blob: 0224221ee2142cec023cba85e08f43af44e3f236 [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
Vidya Srinivas6deef9b602018-05-12 03:03:13 +0530459skl_wa_528(struct drm_i915_private *dev_priv, int pipe, bool enable)
460{
461 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
462 return;
463
464 if (enable)
465 I915_WRITE(CHICKEN_PIPESL_1(pipe), HSW_FBCQ_DIS);
466 else
467 I915_WRITE(CHICKEN_PIPESL_1(pipe), 0);
468}
469
470static void
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530471skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
472{
Vidya Srinivas6deef9b602018-05-12 03:03:13 +0530473 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530474 return;
475
476 if (enable)
477 I915_WRITE(CLKGATE_DIS_PSL(pipe),
478 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
479 else
480 I915_WRITE(CLKGATE_DIS_PSL(pipe),
481 I915_READ(CLKGATE_DIS_PSL(pipe)) &
482 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
483}
484
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200485static bool
Maarten Lankhorst24f28452017-11-22 19:39:01 +0100486needs_modeset(const struct drm_crtc_state *state)
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200487{
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200488 return drm_atomic_crtc_needs_modeset(state);
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200489}
490
Imre Deakdccbea32015-06-22 23:35:51 +0300491/*
492 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
493 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
494 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
495 * The helpers' return value is the rate of the clock that is fed to the
496 * display engine's pipe which can be the above fast dot clock rate or a
497 * divided-down version of it.
498 */
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500499/* m1 is reserved as 0 in Pineview, n is a ring counter */
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300500static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800501{
Shaohua Li21778322009-02-23 15:19:16 +0800502 clock->m = clock->m2 + 2;
503 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200504 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300505 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300506 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
507 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300508
509 return clock->dot;
Shaohua Li21778322009-02-23 15:19:16 +0800510}
511
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200512static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
513{
514 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
515}
516
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300517static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
Shaohua Li21778322009-02-23 15:19:16 +0800518{
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200519 clock->m = i9xx_dpll_compute_m(clock);
Jesse Barnes79e53942008-11-07 14:24:08 -0800520 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200521 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300522 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300523 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
524 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300525
526 return clock->dot;
Jesse Barnes79e53942008-11-07 14:24:08 -0800527}
528
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300529static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
Imre Deak589eca62015-06-22 23:35:50 +0300530{
531 clock->m = clock->m1 * clock->m2;
532 clock->p = clock->p1 * clock->p2;
533 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300534 return 0;
Imre Deak589eca62015-06-22 23:35:50 +0300535 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
536 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300537
538 return clock->dot / 5;
Imre Deak589eca62015-06-22 23:35:50 +0300539}
540
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300541int chv_calc_dpll_params(int refclk, struct dpll *clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300542{
543 clock->m = clock->m1 * clock->m2;
544 clock->p = clock->p1 * clock->p2;
545 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300546 return 0;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300547 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
548 clock->n << 22);
549 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300550
551 return clock->dot / 5;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300552}
553
Jesse Barnes7c04d1d2009-02-23 15:36:40 -0800554#define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
Chris Wilsonc38c1452018-02-14 13:49:22 +0000555
556/*
Jesse Barnes79e53942008-11-07 14:24:08 -0800557 * Returns whether the given set of divisors are valid for a given refclk with
558 * the given connectors.
559 */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100560static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300561 const struct intel_limit *limit,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300562 const struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800563{
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300564 if (clock->n < limit->n.min || limit->n.max < clock->n)
565 INTELPllInvalid("n out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800566 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400567 INTELPllInvalid("p1 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800568 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
Akshay Joshi0206e352011-08-16 15:34:10 -0400569 INTELPllInvalid("m2 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800570 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400571 INTELPllInvalid("m1 out of range\n");
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300572
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100573 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200574 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300575 if (clock->m1 <= clock->m2)
576 INTELPllInvalid("m1 <= m2\n");
577
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100578 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200579 !IS_GEN9_LP(dev_priv)) {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300580 if (clock->p < limit->p.min || limit->p.max < clock->p)
581 INTELPllInvalid("p out of range\n");
582 if (clock->m < limit->m.min || limit->m.max < clock->m)
583 INTELPllInvalid("m out of range\n");
584 }
585
Jesse Barnes79e53942008-11-07 14:24:08 -0800586 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
Akshay Joshi0206e352011-08-16 15:34:10 -0400587 INTELPllInvalid("vco out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800588 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
589 * connector, etc., rather than just a single range.
590 */
591 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
Akshay Joshi0206e352011-08-16 15:34:10 -0400592 INTELPllInvalid("dot out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800593
594 return true;
595}
596
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300597static int
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300598i9xx_select_p2_div(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300599 const struct intel_crtc_state *crtc_state,
600 int target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800601{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300602 struct drm_device *dev = crtc_state->base.crtc->dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800603
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +0300604 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800605 /*
Daniel Vettera210b022012-11-26 17:22:08 +0100606 * For LVDS just rely on its current settings for dual-channel.
607 * We haven't figured out how to reliably set up different
608 * single/dual channel state, if we even can.
Jesse Barnes79e53942008-11-07 14:24:08 -0800609 */
Daniel Vetter1974cad2012-11-26 17:22:09 +0100610 if (intel_is_dual_link_lvds(dev))
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300611 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800612 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300613 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800614 } else {
615 if (target < limit->p2.dot_limit)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300616 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800617 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300618 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800619 }
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300620}
621
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200622/*
623 * Returns a set of divisors for the desired target clock with the given
624 * refclk, or FALSE. The returned values represent the clock equation:
625 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
626 *
627 * Target and reference clocks are specified in kHz.
628 *
629 * If match_clock is provided, then best_clock P divider must match the P
630 * divider from @match_clock used for LVDS downclocking.
631 */
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300632static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300633i9xx_find_best_dpll(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300634 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300635 int target, int refclk, struct dpll *match_clock,
636 struct dpll *best_clock)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300637{
638 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300639 struct dpll clock;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300640 int err = target;
Jesse Barnes79e53942008-11-07 14:24:08 -0800641
Akshay Joshi0206e352011-08-16 15:34:10 -0400642 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnes79e53942008-11-07 14:24:08 -0800643
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300644 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
645
Zhao Yakui42158662009-11-20 11:24:18 +0800646 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
647 clock.m1++) {
648 for (clock.m2 = limit->m2.min;
649 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterc0efc382013-06-03 20:56:24 +0200650 if (clock.m2 >= clock.m1)
Zhao Yakui42158662009-11-20 11:24:18 +0800651 break;
652 for (clock.n = limit->n.min;
653 clock.n <= limit->n.max; clock.n++) {
654 for (clock.p1 = limit->p1.min;
655 clock.p1 <= limit->p1.max; clock.p1++) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800656 int this_err;
657
Imre Deakdccbea32015-06-22 23:35:51 +0300658 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100659 if (!intel_PLL_is_valid(to_i915(dev),
660 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000661 &clock))
Jesse Barnes79e53942008-11-07 14:24:08 -0800662 continue;
Sean Paulcec2f352012-01-10 15:09:36 -0800663 if (match_clock &&
664 clock.p != match_clock->p)
665 continue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800666
667 this_err = abs(clock.dot - target);
668 if (this_err < err) {
669 *best_clock = clock;
670 err = this_err;
671 }
672 }
673 }
674 }
675 }
676
677 return (err != target);
678}
679
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200680/*
681 * Returns a set of divisors for the desired target clock with the given
682 * refclk, or FALSE. The returned values represent the clock equation:
683 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
684 *
685 * Target and reference clocks are specified in kHz.
686 *
687 * If match_clock is provided, then best_clock P divider must match the P
688 * divider from @match_clock used for LVDS downclocking.
689 */
Ma Lingd4906092009-03-18 20:13:27 +0800690static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300691pnv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200692 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300693 int target, int refclk, struct dpll *match_clock,
694 struct dpll *best_clock)
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200695{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300696 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300697 struct dpll clock;
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200698 int err = target;
699
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200700 memset(best_clock, 0, sizeof(*best_clock));
701
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300702 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
703
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200704 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
705 clock.m1++) {
706 for (clock.m2 = limit->m2.min;
707 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200708 for (clock.n = limit->n.min;
709 clock.n <= limit->n.max; clock.n++) {
710 for (clock.p1 = limit->p1.min;
711 clock.p1 <= limit->p1.max; clock.p1++) {
712 int this_err;
713
Imre Deakdccbea32015-06-22 23:35:51 +0300714 pnv_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100715 if (!intel_PLL_is_valid(to_i915(dev),
716 limit,
Jesse Barnes79e53942008-11-07 14:24:08 -0800717 &clock))
718 continue;
719 if (match_clock &&
720 clock.p != match_clock->p)
721 continue;
722
723 this_err = abs(clock.dot - target);
724 if (this_err < err) {
725 *best_clock = clock;
726 err = this_err;
727 }
728 }
729 }
730 }
731 }
732
733 return (err != target);
734}
735
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200736/*
737 * Returns a set of divisors for the desired target clock with the given
738 * refclk, or FALSE. The returned values represent the clock equation:
739 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200740 *
741 * Target and reference clocks are specified in kHz.
742 *
743 * If match_clock is provided, then best_clock P divider must match the P
744 * divider from @match_clock used for LVDS downclocking.
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200745 */
Ma Lingd4906092009-03-18 20:13:27 +0800746static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300747g4x_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200748 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300749 int target, int refclk, struct dpll *match_clock,
750 struct dpll *best_clock)
Ma Lingd4906092009-03-18 20:13:27 +0800751{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300752 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300753 struct dpll clock;
Ma Lingd4906092009-03-18 20:13:27 +0800754 int max_n;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300755 bool found = false;
Adam Jackson6ba770d2010-07-02 16:43:30 -0400756 /* approximately equals target * 0.00585 */
757 int err_most = (target >> 8) + (target >> 9);
Ma Lingd4906092009-03-18 20:13:27 +0800758
759 memset(best_clock, 0, sizeof(*best_clock));
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300760
761 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
762
Ma Lingd4906092009-03-18 20:13:27 +0800763 max_n = limit->n.max;
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200764 /* based on hardware requirement, prefer smaller n to precision */
Ma Lingd4906092009-03-18 20:13:27 +0800765 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200766 /* based on hardware requirement, prefere larger m1,m2 */
Ma Lingd4906092009-03-18 20:13:27 +0800767 for (clock.m1 = limit->m1.max;
768 clock.m1 >= limit->m1.min; clock.m1--) {
769 for (clock.m2 = limit->m2.max;
770 clock.m2 >= limit->m2.min; clock.m2--) {
771 for (clock.p1 = limit->p1.max;
772 clock.p1 >= limit->p1.min; clock.p1--) {
773 int this_err;
774
Imre Deakdccbea32015-06-22 23:35:51 +0300775 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100776 if (!intel_PLL_is_valid(to_i915(dev),
777 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000778 &clock))
Ma Lingd4906092009-03-18 20:13:27 +0800779 continue;
Chris Wilson1b894b52010-12-14 20:04:54 +0000780
781 this_err = abs(clock.dot - target);
Ma Lingd4906092009-03-18 20:13:27 +0800782 if (this_err < err_most) {
783 *best_clock = clock;
784 err_most = this_err;
785 max_n = clock.n;
786 found = true;
787 }
788 }
789 }
790 }
791 }
Zhenyu Wang2c072452009-06-05 15:38:42 +0800792 return found;
793}
Ma Lingd4906092009-03-18 20:13:27 +0800794
Imre Deakd5dd62b2015-03-17 11:40:03 +0200795/*
796 * Check if the calculated PLL configuration is more optimal compared to the
797 * best configuration and error found so far. Return the calculated error.
798 */
799static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300800 const struct dpll *calculated_clock,
801 const struct dpll *best_clock,
Imre Deakd5dd62b2015-03-17 11:40:03 +0200802 unsigned int best_error_ppm,
803 unsigned int *error_ppm)
804{
Imre Deak9ca3ba02015-03-17 11:40:05 +0200805 /*
806 * For CHV ignore the error and consider only the P value.
807 * Prefer a bigger P value based on HW requirements.
808 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100809 if (IS_CHERRYVIEW(to_i915(dev))) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200810 *error_ppm = 0;
811
812 return calculated_clock->p > best_clock->p;
813 }
814
Imre Deak24be4e42015-03-17 11:40:04 +0200815 if (WARN_ON_ONCE(!target_freq))
816 return false;
817
Imre Deakd5dd62b2015-03-17 11:40:03 +0200818 *error_ppm = div_u64(1000000ULL *
819 abs(target_freq - calculated_clock->dot),
820 target_freq);
821 /*
822 * Prefer a better P value over a better (smaller) error if the error
823 * is small. Ensure this preference for future configurations too by
824 * setting the error to 0.
825 */
826 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
827 *error_ppm = 0;
828
829 return true;
830 }
831
832 return *error_ppm + 10 < best_error_ppm;
833}
834
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200835/*
836 * Returns a set of divisors for the desired target clock with the given
837 * refclk, or FALSE. The returned values represent the clock equation:
838 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
839 */
Zhenyu Wang2c072452009-06-05 15:38:42 +0800840static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300841vlv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200842 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300843 int target, int refclk, struct dpll *match_clock,
844 struct dpll *best_clock)
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700845{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200846 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300847 struct drm_device *dev = crtc->base.dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300848 struct dpll clock;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300849 unsigned int bestppm = 1000000;
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300850 /* min update 19.2 MHz */
851 int max_n = min(limit->n.max, refclk / 19200);
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300852 bool found = false;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700853
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300854 target *= 5; /* fast clock */
855
856 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700857
858 /* based on hardware requirement, prefer smaller n to precision */
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300859 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Ville Syrjälä811bbf02013-09-24 21:26:25 +0300860 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
Ville Syrjälä889059d2013-09-24 21:26:27 +0300861 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
Ville Syrjäläc1a9ae42013-09-24 21:26:23 +0300862 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300863 clock.p = clock.p1 * clock.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700864 /* based on hardware requirement, prefer bigger m1,m2 values */
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300865 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
Imre Deakd5dd62b2015-03-17 11:40:03 +0200866 unsigned int ppm;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300867
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300868 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
869 refclk * clock.m1);
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300870
Imre Deakdccbea32015-06-22 23:35:51 +0300871 vlv_calc_dpll_params(refclk, &clock);
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300872
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100873 if (!intel_PLL_is_valid(to_i915(dev),
874 limit,
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300875 &clock))
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300876 continue;
877
Imre Deakd5dd62b2015-03-17 11:40:03 +0200878 if (!vlv_PLL_is_optimal(dev, target,
879 &clock,
880 best_clock,
881 bestppm, &ppm))
882 continue;
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300883
Imre Deakd5dd62b2015-03-17 11:40:03 +0200884 *best_clock = clock;
885 bestppm = ppm;
886 found = true;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700887 }
888 }
889 }
890 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700891
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300892 return found;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700893}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700894
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200895/*
896 * Returns a set of divisors for the desired target clock with the given
897 * refclk, or FALSE. The returned values represent the clock equation:
898 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
899 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300900static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300901chv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200902 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300903 int target, int refclk, struct dpll *match_clock,
904 struct dpll *best_clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300905{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200906 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300907 struct drm_device *dev = crtc->base.dev;
Imre Deak9ca3ba02015-03-17 11:40:05 +0200908 unsigned int best_error_ppm;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300909 struct dpll clock;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300910 uint64_t m2;
911 int found = false;
912
913 memset(best_clock, 0, sizeof(*best_clock));
Imre Deak9ca3ba02015-03-17 11:40:05 +0200914 best_error_ppm = 1000000;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300915
916 /*
917 * Based on hardware doc, the n always set to 1, and m1 always
918 * set to 2. If requires to support 200Mhz refclk, we need to
919 * revisit this because n may not 1 anymore.
920 */
921 clock.n = 1, clock.m1 = 2;
922 target *= 5; /* fast clock */
923
924 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
925 for (clock.p2 = limit->p2.p2_fast;
926 clock.p2 >= limit->p2.p2_slow;
927 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200928 unsigned int error_ppm;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300929
930 clock.p = clock.p1 * clock.p2;
931
932 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
933 clock.n) << 22, refclk * clock.m1);
934
935 if (m2 > INT_MAX/clock.m1)
936 continue;
937
938 clock.m2 = m2;
939
Imre Deakdccbea32015-06-22 23:35:51 +0300940 chv_calc_dpll_params(refclk, &clock);
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300941
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100942 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300943 continue;
944
Imre Deak9ca3ba02015-03-17 11:40:05 +0200945 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
946 best_error_ppm, &error_ppm))
947 continue;
948
949 *best_clock = clock;
950 best_error_ppm = error_ppm;
951 found = true;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300952 }
953 }
954
955 return found;
956}
957
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200958bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300959 struct dpll *best_clock)
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200960{
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200961 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300962 const struct intel_limit *limit = &intel_limits_bxt;
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200963
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200964 return chv_find_best_dpll(limit, crtc_state,
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200965 target_clock, refclk, NULL, best_clock);
966}
967
Ville Syrjälä525b9312016-10-31 22:37:02 +0200968bool intel_crtc_active(struct intel_crtc *crtc)
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300969{
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300970 /* Be paranoid as we can arrive here with only partial
971 * state retrieved from the hardware during setup.
972 *
Damien Lespiau241bfc32013-09-25 16:45:37 +0100973 * We can ditch the adjusted_mode.crtc_clock check as soon
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300974 * as Haswell has gained clock readout/fastboot support.
975 *
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +0300976 * We can ditch the crtc->primary->state->fb check as soon as we can
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300977 * properly reconstruct framebuffers.
Matt Roperc3d1f432015-03-09 10:19:23 -0700978 *
979 * FIXME: The intel_crtc->active here should be switched to
980 * crtc->state->active once we have proper CRTC states wired up
981 * for atomic.
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300982 */
Ville Syrjälä525b9312016-10-31 22:37:02 +0200983 return crtc->active && crtc->base.primary->state->fb &&
984 crtc->config->base.adjusted_mode.crtc_clock;
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300985}
986
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200987enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
988 enum pipe pipe)
989{
Ville Syrjälä98187832016-10-31 22:37:10 +0200990 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200991
Ville Syrjäläe2af48c2016-10-31 22:37:05 +0200992 return crtc->config->cpu_transcoder;
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200993}
994
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200995static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
996 enum pipe pipe)
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300997{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200998 i915_reg_t reg = PIPEDSL(pipe);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300999 u32 line1, line2;
1000 u32 line_mask;
1001
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001002 if (IS_GEN2(dev_priv))
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001003 line_mask = DSL_LINEMASK_GEN2;
1004 else
1005 line_mask = DSL_LINEMASK_GEN3;
1006
1007 line1 = I915_READ(reg) & line_mask;
Daniel Vetter6adfb1e2015-07-07 09:10:40 +02001008 msleep(5);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001009 line2 = I915_READ(reg) & line_mask;
1010
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001011 return line1 != line2;
1012}
1013
1014static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1015{
1016 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1017 enum pipe pipe = crtc->pipe;
1018
1019 /* Wait for the display line to settle/start moving */
1020 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1021 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1022 pipe_name(pipe), onoff(state));
1023}
1024
1025static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1026{
1027 wait_for_pipe_scanline_moving(crtc, false);
1028}
1029
1030static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1031{
1032 wait_for_pipe_scanline_moving(crtc, true);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001033}
1034
Ville Syrjälä4972f702017-11-29 17:37:32 +02001035static void
1036intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001037{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001038 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001039 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001040
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001041 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001042 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001043 i915_reg_t reg = PIPECONF(cpu_transcoder);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001044
Keith Packardab7ad7f2010-10-03 00:33:06 -07001045 /* Wait for the Pipe State to go off */
Chris Wilsonb8511f52016-06-30 15:32:53 +01001046 if (intel_wait_for_register(dev_priv,
1047 reg, I965_PIPECONF_ACTIVE, 0,
1048 100))
Daniel Vetter284637d2012-07-09 09:51:57 +02001049 WARN(1, "pipe_off wait timed out\n");
Keith Packardab7ad7f2010-10-03 00:33:06 -07001050 } else {
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001051 intel_wait_for_pipe_scanline_stopped(crtc);
Keith Packardab7ad7f2010-10-03 00:33:06 -07001052 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001053}
1054
Jesse Barnesb24e7172011-01-04 15:09:30 -08001055/* Only for pre-ILK configs */
Daniel Vetter55607e82013-06-16 21:42:39 +02001056void assert_pll(struct drm_i915_private *dev_priv,
1057 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001058{
Jesse Barnesb24e7172011-01-04 15:09:30 -08001059 u32 val;
1060 bool cur_state;
1061
Ville Syrjälä649636e2015-09-22 19:50:01 +03001062 val = I915_READ(DPLL(pipe));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001063 cur_state = !!(val & DPLL_VCO_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001064 I915_STATE_WARN(cur_state != state,
Jesse Barnesb24e7172011-01-04 15:09:30 -08001065 "PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001066 onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001067}
Jesse Barnesb24e7172011-01-04 15:09:30 -08001068
Jani Nikula23538ef2013-08-27 15:12:22 +03001069/* XXX: the dsi pll is shared between MIPI DSI ports */
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +00001070void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
Jani Nikula23538ef2013-08-27 15:12:22 +03001071{
1072 u32 val;
1073 bool cur_state;
1074
Ville Syrjäläa5805162015-05-26 20:42:30 +03001075 mutex_lock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001076 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001077 mutex_unlock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001078
1079 cur_state = val & DSI_PLL_VCO_EN;
Rob Clarke2c719b2014-12-15 13:56:32 -05001080 I915_STATE_WARN(cur_state != state,
Jani Nikula23538ef2013-08-27 15:12:22 +03001081 "DSI PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001082 onoff(state), onoff(cur_state));
Jani Nikula23538ef2013-08-27 15:12:22 +03001083}
Jani Nikula23538ef2013-08-27 15:12:22 +03001084
Jesse Barnes040484a2011-01-03 12:14:26 -08001085static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1086 enum pipe pipe, bool state)
1087{
Jesse Barnes040484a2011-01-03 12:14:26 -08001088 bool cur_state;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001089 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1090 pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001091
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001092 if (HAS_DDI(dev_priv)) {
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001093 /* DDI does not have a specific FDI_TX register */
Ville Syrjälä649636e2015-09-22 19:50:01 +03001094 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
Paulo Zanoniad80a812012-10-24 16:06:19 -02001095 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001096 } else {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001097 u32 val = I915_READ(FDI_TX_CTL(pipe));
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001098 cur_state = !!(val & FDI_TX_ENABLE);
1099 }
Rob Clarke2c719b2014-12-15 13:56:32 -05001100 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001101 "FDI TX 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_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1105#define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1106
1107static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1108 enum pipe pipe, bool state)
1109{
Jesse Barnes040484a2011-01-03 12:14:26 -08001110 u32 val;
1111 bool cur_state;
1112
Ville Syrjälä649636e2015-09-22 19:50:01 +03001113 val = I915_READ(FDI_RX_CTL(pipe));
Paulo Zanonid63fa0d2012-11-20 13:27:35 -02001114 cur_state = !!(val & FDI_RX_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001115 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001116 "FDI RX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001117 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001118}
1119#define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1120#define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1121
1122static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1123 enum pipe pipe)
1124{
Jesse Barnes040484a2011-01-03 12:14:26 -08001125 u32 val;
1126
1127 /* ILK FDI PLL is always enabled */
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01001128 if (IS_GEN5(dev_priv))
Jesse Barnes040484a2011-01-03 12:14:26 -08001129 return;
1130
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001131 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001132 if (HAS_DDI(dev_priv))
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001133 return;
1134
Ville Syrjälä649636e2015-09-22 19:50:01 +03001135 val = I915_READ(FDI_TX_CTL(pipe));
Rob Clarke2c719b2014-12-15 13:56:32 -05001136 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 -08001137}
1138
Daniel Vetter55607e82013-06-16 21:42:39 +02001139void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1140 enum pipe pipe, bool state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001141{
Jesse Barnes040484a2011-01-03 12:14:26 -08001142 u32 val;
Daniel Vetter55607e82013-06-16 21:42:39 +02001143 bool cur_state;
Jesse Barnes040484a2011-01-03 12:14:26 -08001144
Ville Syrjälä649636e2015-09-22 19:50:01 +03001145 val = I915_READ(FDI_RX_CTL(pipe));
Daniel Vetter55607e82013-06-16 21:42:39 +02001146 cur_state = !!(val & FDI_RX_PLL_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001147 I915_STATE_WARN(cur_state != state,
Daniel Vetter55607e82013-06-16 21:42:39 +02001148 "FDI RX PLL assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001149 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001150}
1151
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001152void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnesea0760c2011-01-04 15:09:32 -08001153{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001154 i915_reg_t pp_reg;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001155 u32 val;
Ville Syrjälä10ed55e2018-05-23 17:57:18 +03001156 enum pipe panel_pipe = INVALID_PIPE;
Thomas Jarosch0de3b482011-08-25 15:37:45 +02001157 bool locked = true;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001158
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001159 if (WARN_ON(HAS_DDI(dev_priv)))
Jani Nikulabedd4db2014-08-22 15:04:13 +03001160 return;
1161
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001162 if (HAS_PCH_SPLIT(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001163 u32 port_sel;
1164
Imre Deak44cb7342016-08-10 14:07:29 +03001165 pp_reg = PP_CONTROL(0);
1166 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
Jani Nikulabedd4db2014-08-22 15:04:13 +03001167
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001168 switch (port_sel) {
1169 case PANEL_PORT_SELECT_LVDS:
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001170 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001171 break;
1172 case PANEL_PORT_SELECT_DPA:
1173 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1174 break;
1175 case PANEL_PORT_SELECT_DPC:
1176 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1177 break;
1178 case PANEL_PORT_SELECT_DPD:
1179 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1180 break;
1181 default:
1182 MISSING_CASE(port_sel);
1183 break;
1184 }
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001185 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001186 /* presumably write lock depends on pipe, not port select */
Imre Deak44cb7342016-08-10 14:07:29 +03001187 pp_reg = PP_CONTROL(pipe);
Jani Nikulabedd4db2014-08-22 15:04:13 +03001188 panel_pipe = pipe;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001189 } else {
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001190 u32 port_sel;
1191
Imre Deak44cb7342016-08-10 14:07:29 +03001192 pp_reg = PP_CONTROL(0);
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001193 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1194
1195 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001196 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
Jesse Barnesea0760c2011-01-04 15:09:32 -08001197 }
1198
1199 val = I915_READ(pp_reg);
1200 if (!(val & PANEL_POWER_ON) ||
Jani Nikulaec49ba22014-08-21 15:06:25 +03001201 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
Jesse Barnesea0760c2011-01-04 15:09:32 -08001202 locked = false;
1203
Rob Clarke2c719b2014-12-15 13:56:32 -05001204 I915_STATE_WARN(panel_pipe == pipe && locked,
Jesse Barnesea0760c2011-01-04 15:09:32 -08001205 "panel assertion failure, pipe %c regs locked\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001206 pipe_name(pipe));
Jesse Barnesea0760c2011-01-04 15:09:32 -08001207}
1208
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001209void assert_pipe(struct drm_i915_private *dev_priv,
1210 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001211{
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001212 bool cur_state;
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001213 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1214 pipe);
Imre Deak4feed0e2016-02-12 18:55:14 +02001215 enum intel_display_power_domain power_domain;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001216
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001217 /* we keep both pipes enabled on 830 */
1218 if (IS_I830(dev_priv))
Daniel Vetter8e636782012-01-22 01:36:48 +01001219 state = true;
1220
Imre Deak4feed0e2016-02-12 18:55:14 +02001221 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1222 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001223 u32 val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni69310162013-01-29 16:35:19 -02001224 cur_state = !!(val & PIPECONF_ENABLE);
Imre Deak4feed0e2016-02-12 18:55:14 +02001225
1226 intel_display_power_put(dev_priv, power_domain);
1227 } else {
1228 cur_state = false;
Paulo Zanoni69310162013-01-29 16:35:19 -02001229 }
1230
Rob Clarke2c719b2014-12-15 13:56:32 -05001231 I915_STATE_WARN(cur_state != state,
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001232 "pipe %c assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001233 pipe_name(pipe), onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001234}
1235
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001236static void assert_plane(struct intel_plane *plane, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001237{
Ville Syrjäläeade6c82018-01-30 22:38:03 +02001238 enum pipe pipe;
1239 bool cur_state;
1240
1241 cur_state = plane->get_hw_state(plane, &pipe);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001242
Rob Clarke2c719b2014-12-15 13:56:32 -05001243 I915_STATE_WARN(cur_state != state,
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001244 "%s assertion failure (expected %s, current %s)\n",
1245 plane->base.name, onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001246}
1247
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001248#define assert_plane_enabled(p) assert_plane(p, true)
1249#define assert_plane_disabled(p) assert_plane(p, false)
Chris Wilson931872f2012-01-16 23:01:13 +00001250
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001251static void assert_planes_disabled(struct intel_crtc *crtc)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001252{
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001253 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1254 struct intel_plane *plane;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001255
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001256 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1257 assert_plane_disabled(plane);
Jesse Barnes19332d72013-03-28 09:55:38 -07001258}
1259
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001260static void assert_vblank_disabled(struct drm_crtc *crtc)
1261{
Rob Clarke2c719b2014-12-15 13:56:32 -05001262 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001263 drm_crtc_vblank_put(crtc);
1264}
1265
Ander Conselvan de Oliveira7abd4b32016-03-08 17:46:15 +02001266void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1267 enum pipe pipe)
Jesse Barnes92f25842011-01-04 15:09:34 -08001268{
Jesse Barnes92f25842011-01-04 15:09:34 -08001269 u32 val;
1270 bool enabled;
1271
Ville Syrjälä649636e2015-09-22 19:50:01 +03001272 val = I915_READ(PCH_TRANSCONF(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001273 enabled = !!(val & TRANS_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001274 I915_STATE_WARN(enabled,
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001275 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1276 pipe_name(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001277}
1278
Jesse Barnes291906f2011-02-02 12:28:03 -08001279static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001280 enum pipe pipe, enum port port,
1281 i915_reg_t dp_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001282{
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001283 enum pipe port_pipe;
1284 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001285
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001286 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1287
1288 I915_STATE_WARN(state && port_pipe == pipe,
1289 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1290 port_name(port), pipe_name(pipe));
1291
1292 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1293 "IBX PCH DP %c still using transcoder B\n",
1294 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001295}
1296
1297static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä76203462018-05-14 20:24:21 +03001298 enum pipe pipe, enum port port,
1299 i915_reg_t hdmi_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001300{
Ville Syrjälä76203462018-05-14 20:24:21 +03001301 enum pipe port_pipe;
1302 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001303
Ville Syrjälä76203462018-05-14 20:24:21 +03001304 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1305
1306 I915_STATE_WARN(state && port_pipe == pipe,
1307 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1308 port_name(port), pipe_name(pipe));
1309
1310 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1311 "IBX PCH HDMI %c still using transcoder B\n",
1312 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001313}
1314
1315static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1316 enum pipe pipe)
1317{
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001318 enum pipe port_pipe;
Jesse Barnes291906f2011-02-02 12:28:03 -08001319
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001320 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1321 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1322 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
Jesse Barnes291906f2011-02-02 12:28:03 -08001323
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001324 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1325 port_pipe == pipe,
1326 "PCH VGA enabled on transcoder %c, should be disabled\n",
1327 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001328
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001329 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1330 port_pipe == pipe,
1331 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1332 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001333
Ville Syrjälä76203462018-05-14 20:24:21 +03001334 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1335 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1336 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
Jesse Barnes291906f2011-02-02 12:28:03 -08001337}
1338
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001339static void _vlv_enable_pll(struct intel_crtc *crtc,
1340 const struct intel_crtc_state *pipe_config)
1341{
1342 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1343 enum pipe pipe = crtc->pipe;
1344
1345 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1346 POSTING_READ(DPLL(pipe));
1347 udelay(150);
1348
Chris Wilson2c30b432016-06-30 15:32:54 +01001349 if (intel_wait_for_register(dev_priv,
1350 DPLL(pipe),
1351 DPLL_LOCK_VLV,
1352 DPLL_LOCK_VLV,
1353 1))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001354 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1355}
1356
Ville Syrjäläd288f652014-10-28 13:20:22 +02001357static void vlv_enable_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001358 const struct intel_crtc_state *pipe_config)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001359{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001360 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001361 enum pipe pipe = crtc->pipe;
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001362
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001363 assert_pipe_disabled(dev_priv, pipe);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001364
Daniel Vetter87442f72013-06-06 00:52:17 +02001365 /* PLL is protected by panel, make sure we can write it */
Ville Syrjälä7d1a83c2016-03-15 16:39:58 +02001366 assert_panel_unlocked(dev_priv, pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001367
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001368 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1369 _vlv_enable_pll(crtc, pipe_config);
Daniel Vetter426115c2013-07-11 22:13:42 +02001370
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001371 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1372 POSTING_READ(DPLL_MD(pipe));
Daniel Vetter87442f72013-06-06 00:52:17 +02001373}
1374
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001375
1376static void _chv_enable_pll(struct intel_crtc *crtc,
1377 const struct intel_crtc_state *pipe_config)
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001378{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001379 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001380 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001381 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001382 u32 tmp;
1383
Ville Syrjäläa5805162015-05-26 20:42:30 +03001384 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001385
1386 /* Enable back the 10bit clock to display controller */
1387 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1388 tmp |= DPIO_DCLKP_EN;
1389 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1390
Ville Syrjälä54433e92015-05-26 20:42:31 +03001391 mutex_unlock(&dev_priv->sb_lock);
1392
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001393 /*
1394 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1395 */
1396 udelay(1);
1397
1398 /* Enable PLL */
Ville Syrjäläd288f652014-10-28 13:20:22 +02001399 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001400
1401 /* Check PLL is locked */
Chris Wilson6b188262016-06-30 15:32:55 +01001402 if (intel_wait_for_register(dev_priv,
1403 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1404 1))
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001405 DRM_ERROR("PLL %d failed to lock\n", pipe);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001406}
1407
1408static void chv_enable_pll(struct intel_crtc *crtc,
1409 const struct intel_crtc_state *pipe_config)
1410{
1411 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1412 enum pipe pipe = crtc->pipe;
1413
1414 assert_pipe_disabled(dev_priv, pipe);
1415
1416 /* PLL is protected by panel, make sure we can write it */
1417 assert_panel_unlocked(dev_priv, pipe);
1418
1419 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1420 _chv_enable_pll(crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001421
Ville Syrjäläc2317752016-03-15 16:39:56 +02001422 if (pipe != PIPE_A) {
1423 /*
1424 * WaPixelRepeatModeFixForC0:chv
1425 *
1426 * DPLLCMD is AWOL. Use chicken bits to propagate
1427 * the value from DPLLBMD to either pipe B or C.
1428 */
Ville Syrjälädfa311f2017-09-13 17:08:54 +03001429 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
Ville Syrjäläc2317752016-03-15 16:39:56 +02001430 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1431 I915_WRITE(CBR4_VLV, 0);
1432 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1433
1434 /*
1435 * DPLLB VGA mode also seems to cause problems.
1436 * We should always have it disabled.
1437 */
1438 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1439 } else {
1440 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1441 POSTING_READ(DPLL_MD(pipe));
1442 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001443}
1444
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001445static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001446{
1447 struct intel_crtc *crtc;
1448 int count = 0;
1449
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001450 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst3538b9d2015-06-01 12:50:10 +02001451 count += crtc->base.state->active &&
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03001452 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1453 }
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001454
1455 return count;
1456}
1457
Ville Syrjälä939994d2017-09-13 17:08:56 +03001458static void i9xx_enable_pll(struct intel_crtc *crtc,
1459 const struct intel_crtc_state *crtc_state)
Daniel Vetter87442f72013-06-06 00:52:17 +02001460{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001461 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001462 i915_reg_t reg = DPLL(crtc->pipe);
Ville Syrjälä939994d2017-09-13 17:08:56 +03001463 u32 dpll = crtc_state->dpll_hw_state.dpll;
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001464 int i;
Daniel Vetter87442f72013-06-06 00:52:17 +02001465
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001466 assert_pipe_disabled(dev_priv, crtc->pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001467
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001468 /* PLL is protected by panel, make sure we can write it */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001469 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001470 assert_panel_unlocked(dev_priv, crtc->pipe);
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001471
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001472 /* Enable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001473 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001474 /*
1475 * It appears to be important that we don't enable this
1476 * for the current pipe before otherwise configuring the
1477 * PLL. No idea how this should be handled if multiple
1478 * DVO outputs are enabled simultaneosly.
1479 */
1480 dpll |= DPLL_DVO_2X_MODE;
1481 I915_WRITE(DPLL(!crtc->pipe),
1482 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1483 }
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001484
Ville Syrjäläc2b63372015-10-07 22:08:25 +03001485 /*
1486 * Apparently we need to have VGA mode enabled prior to changing
1487 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1488 * dividers, even though the register value does change.
1489 */
1490 I915_WRITE(reg, 0);
1491
Ville Syrjälä8e7a65a2015-10-07 22:08:24 +03001492 I915_WRITE(reg, dpll);
1493
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001494 /* Wait for the clocks to stabilize. */
1495 POSTING_READ(reg);
1496 udelay(150);
1497
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001498 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001499 I915_WRITE(DPLL_MD(crtc->pipe),
Ville Syrjälä939994d2017-09-13 17:08:56 +03001500 crtc_state->dpll_hw_state.dpll_md);
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001501 } else {
1502 /* The pixel multiplier can only be updated once the
1503 * DPLL is enabled and the clocks are stable.
1504 *
1505 * So write it again.
1506 */
1507 I915_WRITE(reg, dpll);
1508 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001509
1510 /* We do this three times for luck */
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001511 for (i = 0; i < 3; i++) {
1512 I915_WRITE(reg, dpll);
1513 POSTING_READ(reg);
1514 udelay(150); /* wait for warmup */
1515 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001516}
1517
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001518static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001519{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001520 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001521 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001522 enum pipe pipe = crtc->pipe;
1523
1524 /* Disable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001525 if (IS_I830(dev_priv) &&
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001526 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001527 !intel_num_dvo_pipes(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001528 I915_WRITE(DPLL(PIPE_B),
1529 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1530 I915_WRITE(DPLL(PIPE_A),
1531 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1532 }
1533
Ville Syrjäläb6b5d042014-08-15 01:22:07 +03001534 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001535 if (IS_I830(dev_priv))
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001536 return;
1537
1538 /* Make sure the pipe isn't still relying on us */
1539 assert_pipe_disabled(dev_priv, pipe);
1540
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001541 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
Daniel Vetter50b44a42013-06-05 13:34:33 +02001542 POSTING_READ(DPLL(pipe));
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001543}
1544
Jesse Barnesf6071162013-10-01 10:41:38 -07001545static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1546{
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001547 u32 val;
Jesse Barnesf6071162013-10-01 10:41:38 -07001548
1549 /* Make sure the pipe isn't still relying on us */
1550 assert_pipe_disabled(dev_priv, pipe);
1551
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001552 val = DPLL_INTEGRATED_REF_CLK_VLV |
1553 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1554 if (pipe != PIPE_A)
1555 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1556
Jesse Barnesf6071162013-10-01 10:41:38 -07001557 I915_WRITE(DPLL(pipe), val);
1558 POSTING_READ(DPLL(pipe));
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001559}
1560
1561static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1562{
Ville Syrjäläd7520482014-04-09 13:28:59 +03001563 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001564 u32 val;
1565
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001566 /* Make sure the pipe isn't still relying on us */
1567 assert_pipe_disabled(dev_priv, pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001568
Ville Syrjälä60bfe442015-06-29 15:25:49 +03001569 val = DPLL_SSC_REF_CLK_CHV |
1570 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001571 if (pipe != PIPE_A)
1572 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001573
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001574 I915_WRITE(DPLL(pipe), val);
1575 POSTING_READ(DPLL(pipe));
Ville Syrjäläd7520482014-04-09 13:28:59 +03001576
Ville Syrjäläa5805162015-05-26 20:42:30 +03001577 mutex_lock(&dev_priv->sb_lock);
Ville Syrjäläd7520482014-04-09 13:28:59 +03001578
1579 /* Disable 10bit clock to display controller */
1580 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1581 val &= ~DPIO_DCLKP_EN;
1582 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1583
Ville Syrjäläa5805162015-05-26 20:42:30 +03001584 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesf6071162013-10-01 10:41:38 -07001585}
1586
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001587void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001588 struct intel_digital_port *dport,
1589 unsigned int expected_mask)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001590{
1591 u32 port_mask;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001592 i915_reg_t dpll_reg;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001593
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001594 switch (dport->base.port) {
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001595 case PORT_B:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001596 port_mask = DPLL_PORTB_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001597 dpll_reg = DPLL(0);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001598 break;
1599 case PORT_C:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001600 port_mask = DPLL_PORTC_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001601 dpll_reg = DPLL(0);
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001602 expected_mask <<= 4;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001603 break;
1604 case PORT_D:
1605 port_mask = DPLL_PORTD_READY_MASK;
1606 dpll_reg = DPIO_PHY_STATUS;
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001607 break;
1608 default:
1609 BUG();
1610 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07001611
Chris Wilson370004d2016-06-30 15:32:56 +01001612 if (intel_wait_for_register(dev_priv,
1613 dpll_reg, port_mask, expected_mask,
1614 1000))
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001615 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 +02001616 port_name(dport->base.port),
1617 I915_READ(dpll_reg) & port_mask, expected_mask);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001618}
1619
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001620static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001621{
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001622 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1623 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1624 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001625 i915_reg_t reg;
1626 uint32_t val, pipeconf_val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001627
Jesse Barnes040484a2011-01-03 12:14:26 -08001628 /* Make sure PCH DPLL is enabled */
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001629 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
Jesse Barnes040484a2011-01-03 12:14:26 -08001630
1631 /* FDI must be feeding us bits for PCH ports */
1632 assert_fdi_tx_enabled(dev_priv, pipe);
1633 assert_fdi_rx_enabled(dev_priv, pipe);
1634
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001635 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001636 /* Workaround: Set the timing override bit before enabling the
1637 * pch transcoder. */
1638 reg = TRANS_CHICKEN2(pipe);
1639 val = I915_READ(reg);
1640 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1641 I915_WRITE(reg, val);
Eugeni Dodonov59c859d2012-05-09 15:37:19 -03001642 }
Daniel Vetter23670b322012-11-01 09:15:30 +01001643
Daniel Vetterab9412b2013-05-03 11:49:46 +02001644 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001645 val = I915_READ(reg);
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001646 pipeconf_val = I915_READ(PIPECONF(pipe));
Jesse Barnese9bcff52011-06-24 12:19:20 -07001647
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001648 if (HAS_PCH_IBX(dev_priv)) {
Jesse Barnese9bcff52011-06-24 12:19:20 -07001649 /*
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001650 * Make the BPC in transcoder be consistent with
1651 * that in pipeconf reg. For HDMI we must use 8bpc
1652 * here for both 8bpc and 12bpc.
Jesse Barnese9bcff52011-06-24 12:19:20 -07001653 */
Daniel Vetterdfd07d72012-12-17 11:21:38 +01001654 val &= ~PIPECONF_BPC_MASK;
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001655 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001656 val |= PIPECONF_8BPC;
1657 else
1658 val |= pipeconf_val & PIPECONF_BPC_MASK;
Jesse Barnese9bcff52011-06-24 12:19:20 -07001659 }
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001660
1661 val &= ~TRANS_INTERLACE_MASK;
1662 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001663 if (HAS_PCH_IBX(dev_priv) &&
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001664 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Paulo Zanoni7c26e5c2012-02-14 17:07:09 -02001665 val |= TRANS_LEGACY_INTERLACED_ILK;
1666 else
1667 val |= TRANS_INTERLACED;
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001668 else
1669 val |= TRANS_PROGRESSIVE;
1670
Jesse Barnes040484a2011-01-03 12:14:26 -08001671 I915_WRITE(reg, val | TRANS_ENABLE);
Chris Wilson650fbd82016-06-30 15:32:57 +01001672 if (intel_wait_for_register(dev_priv,
1673 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1674 100))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001675 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
Jesse Barnes040484a2011-01-03 12:14:26 -08001676}
1677
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001678static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
Paulo Zanoni937bb612012-10-31 18:12:47 -02001679 enum transcoder cpu_transcoder)
Jesse Barnes040484a2011-01-03 12:14:26 -08001680{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001681 u32 val, pipeconf_val;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001682
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001683 /* FDI must be feeding us bits for PCH ports */
Daniel Vetter1a240d42012-11-29 22:18:51 +01001684 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001685 assert_fdi_rx_enabled(dev_priv, PIPE_A);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001686
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001687 /* Workaround: set timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001688 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001689 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001690 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001691
Paulo Zanoni25f3ef12012-10-31 18:12:49 -02001692 val = TRANS_ENABLE;
Paulo Zanoni937bb612012-10-31 18:12:47 -02001693 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001694
Paulo Zanoni9a76b1c2012-10-31 18:12:48 -02001695 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1696 PIPECONF_INTERLACED_ILK)
Paulo Zanonia35f2672012-10-31 18:12:45 -02001697 val |= TRANS_INTERLACED;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001698 else
1699 val |= TRANS_PROGRESSIVE;
1700
Daniel Vetterab9412b2013-05-03 11:49:46 +02001701 I915_WRITE(LPT_TRANSCONF, val);
Chris Wilsond9f96242016-06-30 15:32:58 +01001702 if (intel_wait_for_register(dev_priv,
1703 LPT_TRANSCONF,
1704 TRANS_STATE_ENABLE,
1705 TRANS_STATE_ENABLE,
1706 100))
Paulo Zanoni937bb612012-10-31 18:12:47 -02001707 DRM_ERROR("Failed to enable PCH transcoder\n");
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001708}
1709
Paulo Zanonib8a4f402012-10-31 18:12:42 -02001710static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1711 enum pipe pipe)
Jesse Barnes040484a2011-01-03 12:14:26 -08001712{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001713 i915_reg_t reg;
1714 uint32_t val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001715
1716 /* FDI relies on the transcoder */
1717 assert_fdi_tx_disabled(dev_priv, pipe);
1718 assert_fdi_rx_disabled(dev_priv, pipe);
1719
Jesse Barnes291906f2011-02-02 12:28:03 -08001720 /* Ports must be off as well */
1721 assert_pch_ports_disabled(dev_priv, pipe);
1722
Daniel Vetterab9412b2013-05-03 11:49:46 +02001723 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001724 val = I915_READ(reg);
1725 val &= ~TRANS_ENABLE;
1726 I915_WRITE(reg, val);
1727 /* wait for PCH transcoder off, transcoder state */
Chris Wilsona7d04662016-06-30 15:32:59 +01001728 if (intel_wait_for_register(dev_priv,
1729 reg, TRANS_STATE_ENABLE, 0,
1730 50))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001731 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
Daniel Vetter23670b322012-11-01 09:15:30 +01001732
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001733 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001734 /* Workaround: Clear the timing override chicken bit again. */
1735 reg = TRANS_CHICKEN2(pipe);
1736 val = I915_READ(reg);
1737 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1738 I915_WRITE(reg, val);
1739 }
Jesse Barnes040484a2011-01-03 12:14:26 -08001740}
1741
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001742void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001743{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001744 u32 val;
1745
Daniel Vetterab9412b2013-05-03 11:49:46 +02001746 val = I915_READ(LPT_TRANSCONF);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001747 val &= ~TRANS_ENABLE;
Daniel Vetterab9412b2013-05-03 11:49:46 +02001748 I915_WRITE(LPT_TRANSCONF, val);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001749 /* wait for PCH transcoder off, transcoder state */
Chris Wilsondfdb4742016-06-30 15:33:00 +01001750 if (intel_wait_for_register(dev_priv,
1751 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1752 50))
Paulo Zanoni8a52fd92012-10-31 18:12:51 -02001753 DRM_ERROR("Failed to disable PCH transcoder\n");
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001754
1755 /* Workaround: clear timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001756 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001757 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001758 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Jesse Barnes92f25842011-01-04 15:09:34 -08001759}
1760
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001761enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
Ville Syrjälä65f21302016-10-14 20:02:53 +03001762{
1763 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1764
Ville Syrjälä65f21302016-10-14 20:02:53 +03001765 if (HAS_PCH_LPT(dev_priv))
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001766 return PIPE_A;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001767 else
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001768 return crtc->pipe;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001769}
1770
Ville Syrjälä4972f702017-11-29 17:37:32 +02001771static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001772{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001773 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1774 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1775 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
Paulo Zanoni03722642014-01-17 13:51:09 -02001776 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001777 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001778 u32 val;
1779
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001780 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1781
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001782 assert_planes_disabled(crtc);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001783
Jesse Barnesb24e7172011-01-04 15:09:30 -08001784 /*
1785 * A pipe without a PLL won't actually be able to drive bits from
1786 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1787 * need the check.
1788 */
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001789 if (HAS_GMCH_DISPLAY(dev_priv)) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001790 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
Jani Nikula23538ef2013-08-27 15:12:22 +03001791 assert_dsi_pll_enabled(dev_priv);
1792 else
1793 assert_pll_enabled(dev_priv, pipe);
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001794 } else {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001795 if (new_crtc_state->has_pch_encoder) {
Jesse Barnes040484a2011-01-03 12:14:26 -08001796 /* if driving the PCH, we need FDI enabled */
Ville Syrjälä65f21302016-10-14 20:02:53 +03001797 assert_fdi_rx_pll_enabled(dev_priv,
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001798 intel_crtc_pch_transcoder(crtc));
Daniel Vetter1a240d42012-11-29 22:18:51 +01001799 assert_fdi_tx_pll_enabled(dev_priv,
1800 (enum pipe) cpu_transcoder);
Jesse Barnes040484a2011-01-03 12:14:26 -08001801 }
1802 /* FIXME: assert CPU port conditions for SNB+ */
1803 }
Jesse Barnesb24e7172011-01-04 15:09:30 -08001804
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001805 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001806 val = I915_READ(reg);
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001807 if (val & PIPECONF_ENABLE) {
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001808 /* we keep both pipes enabled on 830 */
1809 WARN_ON(!IS_I830(dev_priv));
Chris Wilson00d70b12011-03-17 07:18:29 +00001810 return;
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001811 }
Chris Wilson00d70b12011-03-17 07:18:29 +00001812
1813 I915_WRITE(reg, val | PIPECONF_ENABLE);
Paulo Zanoni851855d2013-12-19 19:12:29 -02001814 POSTING_READ(reg);
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001815
1816 /*
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001817 * Until the pipe starts PIPEDSL reads will return a stale value,
1818 * which causes an apparent vblank timestamp jump when PIPEDSL
1819 * resets to its proper value. That also messes up the frame count
1820 * when it's derived from the timestamps. So let's wait for the
1821 * pipe to start properly before we call drm_crtc_vblank_on()
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001822 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001823 if (dev_priv->drm.max_vblank_count == 0)
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001824 intel_wait_for_pipe_scanline_moving(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001825}
1826
Ville Syrjälä4972f702017-11-29 17:37:32 +02001827static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001828{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001829 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001830 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä4972f702017-11-29 17:37:32 +02001831 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjälä575f7ab2014-08-15 01:21:56 +03001832 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001833 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001834 u32 val;
1835
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001836 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1837
Jesse Barnesb24e7172011-01-04 15:09:30 -08001838 /*
1839 * Make sure planes won't keep trying to pump pixels to us,
1840 * or we might hang the display.
1841 */
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001842 assert_planes_disabled(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001843
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001844 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001845 val = I915_READ(reg);
Chris Wilson00d70b12011-03-17 07:18:29 +00001846 if ((val & PIPECONF_ENABLE) == 0)
1847 return;
1848
Ville Syrjälä67adc642014-08-15 01:21:57 +03001849 /*
1850 * Double wide has implications for planes
1851 * so best keep it disabled when not needed.
1852 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001853 if (old_crtc_state->double_wide)
Ville Syrjälä67adc642014-08-15 01:21:57 +03001854 val &= ~PIPECONF_DOUBLE_WIDE;
1855
1856 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001857 if (!IS_I830(dev_priv))
Ville Syrjälä67adc642014-08-15 01:21:57 +03001858 val &= ~PIPECONF_ENABLE;
1859
1860 I915_WRITE(reg, val);
1861 if ((val & PIPECONF_ENABLE) == 0)
Ville Syrjälä4972f702017-11-29 17:37:32 +02001862 intel_wait_for_pipe_off(old_crtc_state);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001863}
1864
Ville Syrjälä832be822016-01-12 21:08:33 +02001865static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1866{
1867 return IS_GEN2(dev_priv) ? 2048 : 4096;
1868}
1869
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001870static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001871intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001872{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001873 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001874 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001875
1876 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001877 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001878 return cpp;
1879 case I915_FORMAT_MOD_X_TILED:
1880 if (IS_GEN2(dev_priv))
1881 return 128;
1882 else
1883 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001884 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001885 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001886 return 128;
1887 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001888 case I915_FORMAT_MOD_Y_TILED:
1889 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1890 return 128;
1891 else
1892 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001893 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001894 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001895 return 128;
1896 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001897 case I915_FORMAT_MOD_Yf_TILED:
1898 switch (cpp) {
1899 case 1:
1900 return 64;
1901 case 2:
1902 case 4:
1903 return 128;
1904 case 8:
1905 case 16:
1906 return 256;
1907 default:
1908 MISSING_CASE(cpp);
1909 return cpp;
1910 }
1911 break;
1912 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001913 MISSING_CASE(fb->modifier);
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001914 return cpp;
1915 }
1916}
1917
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001918static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001919intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001920{
Ben Widawsky2f075562017-03-24 14:29:48 -07001921 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä832be822016-01-12 21:08:33 +02001922 return 1;
1923 else
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001924 return intel_tile_size(to_i915(fb->dev)) /
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001925 intel_tile_width_bytes(fb, color_plane);
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001926}
1927
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001928/* Return the tile dimensions in pixel units */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001929static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001930 unsigned int *tile_width,
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001931 unsigned int *tile_height)
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001932{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001933 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1934 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001935
1936 *tile_width = tile_width_bytes / cpp;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001937 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001938}
1939
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001940unsigned int
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001941intel_fb_align_height(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001942 int color_plane, unsigned int height)
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001943{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001944 unsigned int tile_height = intel_tile_height(fb, color_plane);
Ville Syrjälä832be822016-01-12 21:08:33 +02001945
1946 return ALIGN(height, tile_height);
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001947}
1948
Ville Syrjälä1663b9d2016-02-15 22:54:45 +02001949unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1950{
1951 unsigned int size = 0;
1952 int i;
1953
1954 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1955 size += rot_info->plane[i].width * rot_info->plane[i].height;
1956
1957 return size;
1958}
1959
Daniel Vetter75c82a52015-10-14 16:51:04 +02001960static void
Ville Syrjälä3465c582016-02-15 22:54:43 +02001961intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1962 const struct drm_framebuffer *fb,
1963 unsigned int rotation)
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00001964{
Chris Wilson7b92c042017-01-14 00:28:26 +00001965 view->type = I915_GGTT_VIEW_NORMAL;
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03001966 if (drm_rotation_90_or_270(rotation)) {
Chris Wilson7b92c042017-01-14 00:28:26 +00001967 view->type = I915_GGTT_VIEW_ROTATED;
Chris Wilson8bab11932017-01-14 00:28:25 +00001968 view->rotated = to_intel_framebuffer(fb)->rot_info;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +02001969 }
1970}
1971
Ville Syrjäläfabac482017-03-27 21:55:43 +03001972static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
1973{
1974 if (IS_I830(dev_priv))
1975 return 16 * 1024;
1976 else if (IS_I85X(dev_priv))
1977 return 256;
Ville Syrjäläd9e15512017-03-27 21:55:45 +03001978 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
1979 return 32;
Ville Syrjäläfabac482017-03-27 21:55:43 +03001980 else
1981 return 4 * 1024;
1982}
1983
Ville Syrjälä603525d2016-01-12 21:08:37 +02001984static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001985{
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00001986 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001987 return 256 * 1024;
Jani Nikulac0f86832016-12-07 12:13:04 +02001988 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
Wayne Boyer666a4532015-12-09 12:29:35 -08001989 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001990 return 128 * 1024;
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00001991 else if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001992 return 4 * 1024;
1993 else
Ville Syrjälä44c59052015-06-11 16:31:16 +03001994 return 0;
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001995}
1996
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001997static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001998 int color_plane)
Ville Syrjälä603525d2016-01-12 21:08:37 +02001999{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002000 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2001
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02002002 /* AUX_DIST needs only 4K alignment */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002003 if (color_plane == 1)
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02002004 return 4096;
2005
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002006 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002007 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002008 return intel_linear_alignment(dev_priv);
2009 case I915_FORMAT_MOD_X_TILED:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002010 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä603525d2016-01-12 21:08:37 +02002011 return 256 * 1024;
2012 return 0;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002013 case I915_FORMAT_MOD_Y_TILED_CCS:
2014 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002015 case I915_FORMAT_MOD_Y_TILED:
2016 case I915_FORMAT_MOD_Yf_TILED:
2017 return 1 * 1024 * 1024;
2018 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002019 MISSING_CASE(fb->modifier);
Ville Syrjälä603525d2016-01-12 21:08:37 +02002020 return 0;
2021 }
2022}
2023
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002024static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2025{
2026 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2027 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2028
Ville Syrjälä32febd92018-02-21 18:02:33 +02002029 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002030}
2031
Chris Wilson058d88c2016-08-15 10:49:06 +01002032struct i915_vma *
Chris Wilson59354852018-02-20 13:42:06 +00002033intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002034 const struct i915_ggtt_view *view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002035 bool uses_fence,
Chris Wilson59354852018-02-20 13:42:06 +00002036 unsigned long *out_flags)
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002037{
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002038 struct drm_device *dev = fb->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002039 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002040 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Chris Wilson058d88c2016-08-15 10:49:06 +01002041 struct i915_vma *vma;
Chris Wilson59354852018-02-20 13:42:06 +00002042 unsigned int pinctl;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002043 u32 alignment;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002044
Matt Roperebcdd392014-07-09 16:22:11 -07002045 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2046
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002047 alignment = intel_surf_alignment(fb, 0);
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002048
Chris Wilson693db182013-03-05 14:52:39 +00002049 /* Note that the w/a also requires 64 PTE of padding following the
2050 * bo. We currently fill all unused PTE with the shadow page and so
2051 * we should always have valid PTE following the scanout preventing
2052 * the VT-d warning.
2053 */
Chris Wilson48f112f2016-06-24 14:07:14 +01002054 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
Chris Wilson693db182013-03-05 14:52:39 +00002055 alignment = 256 * 1024;
2056
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002057 /*
2058 * Global gtt pte registers are special registers which actually forward
2059 * writes to a chunk of system memory. Which means that there is no risk
2060 * that the register values disappear as soon as we call
2061 * intel_runtime_pm_put(), so it is correct to wrap only the
2062 * pin/unpin/fence and not more.
2063 */
2064 intel_runtime_pm_get(dev_priv);
2065
Daniel Vetter9db529a2017-08-08 10:08:28 +02002066 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2067
Chris Wilson59354852018-02-20 13:42:06 +00002068 pinctl = 0;
2069
2070 /* Valleyview is definitely limited to scanning out the first
2071 * 512MiB. Lets presume this behaviour was inherited from the
2072 * g4x display engine and that all earlier gen are similarly
2073 * limited. Testing suggests that it is a little more
2074 * complicated than this. For example, Cherryview appears quite
2075 * happy to scanout from anywhere within its global aperture.
2076 */
2077 if (HAS_GMCH_DISPLAY(dev_priv))
2078 pinctl |= PIN_MAPPABLE;
2079
2080 vma = i915_gem_object_pin_to_display_plane(obj,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002081 alignment, view, pinctl);
Chris Wilson49ef5292016-08-18 17:17:00 +01002082 if (IS_ERR(vma))
2083 goto err;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002084
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002085 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002086 int ret;
2087
Chris Wilson49ef5292016-08-18 17:17:00 +01002088 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2089 * fence, whereas 965+ only requires a fence if using
2090 * framebuffer compression. For simplicity, we always, when
2091 * possible, install a fence as the cost is not that onerous.
2092 *
2093 * If we fail to fence the tiled scanout, then either the
2094 * modeset will reject the change (which is highly unlikely as
2095 * the affected systems, all but one, do not have unmappable
2096 * space) or we will not be able to enable full powersaving
2097 * techniques (also likely not to apply due to various limits
2098 * FBC and the like impose on the size of the buffer, which
2099 * presumably we violated anyway with this unmappable buffer).
2100 * Anyway, it is presumably better to stumble onwards with
2101 * something and try to run the system in a "less than optimal"
2102 * mode that matches the user configuration.
2103 */
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002104 ret = i915_vma_pin_fence(vma);
2105 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
Chris Wilson75097022018-03-05 10:33:12 +00002106 i915_gem_object_unpin_from_display_plane(vma);
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002107 vma = ERR_PTR(ret);
2108 goto err;
2109 }
2110
2111 if (ret == 0 && vma->fence)
Chris Wilson59354852018-02-20 13:42:06 +00002112 *out_flags |= PLANE_HAS_FENCE;
Vivek Kasireddy98072162015-10-29 18:54:38 -07002113 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002114
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002115 i915_vma_get(vma);
Chris Wilson49ef5292016-08-18 17:17:00 +01002116err:
Daniel Vetter9db529a2017-08-08 10:08:28 +02002117 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2118
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002119 intel_runtime_pm_put(dev_priv);
Chris Wilson058d88c2016-08-15 10:49:06 +01002120 return vma;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002121}
2122
Chris Wilson59354852018-02-20 13:42:06 +00002123void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
Chris Wilson1690e1e2011-12-14 13:57:08 +01002124{
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002125 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00002126
Chris Wilson59354852018-02-20 13:42:06 +00002127 if (flags & PLANE_HAS_FENCE)
2128 i915_vma_unpin_fence(vma);
Chris Wilson058d88c2016-08-15 10:49:06 +01002129 i915_gem_object_unpin_from_display_plane(vma);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002130 i915_vma_put(vma);
Chris Wilson1690e1e2011-12-14 13:57:08 +01002131}
2132
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002133static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002134 unsigned int rotation)
2135{
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002136 if (drm_rotation_90_or_270(rotation))
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002137 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002138 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002139 return fb->pitches[color_plane];
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002140}
2141
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002142/*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002143 * Convert the x/y offsets into a linear offset.
2144 * Only valid with 0/180 degree rotation, which is fine since linear
2145 * offset is only used with linear buffers on pre-hsw and tiled buffers
2146 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2147 */
2148u32 intel_fb_xy_to_linear(int x, int y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002149 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002150 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002151{
Ville Syrjälä29490562016-01-20 18:02:50 +02002152 const struct drm_framebuffer *fb = state->base.fb;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002153 unsigned int cpp = fb->format->cpp[color_plane];
2154 unsigned int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002155
2156 return y * pitch + x * cpp;
2157}
2158
2159/*
2160 * Add the x/y offsets derived from fb->offsets[] to the user
2161 * specified plane src x/y offsets. The resulting x/y offsets
2162 * specify the start of scanout from the beginning of the gtt mapping.
2163 */
2164void intel_add_fb_offsets(int *x, int *y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002165 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002166 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002167
2168{
Ville Syrjälä29490562016-01-20 18:02:50 +02002169 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2170 unsigned int rotation = state->base.rotation;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002171
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002172 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002173 *x += intel_fb->rotated[color_plane].x;
2174 *y += intel_fb->rotated[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002175 } else {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002176 *x += intel_fb->normal[color_plane].x;
2177 *y += intel_fb->normal[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002178 }
2179}
2180
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002181static u32 intel_adjust_tile_offset(int *x, int *y,
2182 unsigned int tile_width,
2183 unsigned int tile_height,
2184 unsigned int tile_size,
2185 unsigned int pitch_tiles,
2186 u32 old_offset,
2187 u32 new_offset)
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002188{
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002189 unsigned int pitch_pixels = pitch_tiles * tile_width;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002190 unsigned int tiles;
2191
2192 WARN_ON(old_offset & (tile_size - 1));
2193 WARN_ON(new_offset & (tile_size - 1));
2194 WARN_ON(new_offset > old_offset);
2195
2196 tiles = (old_offset - new_offset) / tile_size;
2197
2198 *y += tiles / pitch_tiles * tile_height;
2199 *x += tiles % pitch_tiles * tile_width;
2200
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002201 /* minimize x in case it got needlessly big */
2202 *y += *x / pitch_pixels * tile_height;
2203 *x %= pitch_pixels;
2204
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002205 return new_offset;
2206}
2207
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002208static u32 intel_adjust_aligned_offset(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002209 const struct drm_framebuffer *fb,
2210 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002211 unsigned int rotation,
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002212 unsigned int pitch,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002213 u32 old_offset, u32 new_offset)
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002214{
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002215 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002216 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002217
2218 WARN_ON(new_offset > old_offset);
2219
Ben Widawsky2f075562017-03-24 14:29:48 -07002220 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002221 unsigned int tile_size, tile_width, tile_height;
2222 unsigned int pitch_tiles;
2223
2224 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002225 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002226
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002227 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002228 pitch_tiles = pitch / tile_height;
2229 swap(tile_width, tile_height);
2230 } else {
2231 pitch_tiles = pitch / (tile_width * cpp);
2232 }
2233
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002234 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2235 tile_size, pitch_tiles,
2236 old_offset, new_offset);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002237 } else {
2238 old_offset += *y * pitch + *x * cpp;
2239
2240 *y = (old_offset - new_offset) / pitch;
2241 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2242 }
2243
2244 return new_offset;
2245}
2246
2247/*
Ville Syrjälä303ba692017-08-24 22:10:49 +03002248 * Adjust the tile offset by moving the difference into
2249 * the x/y offsets.
2250 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002251static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2252 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002253 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002254 u32 old_offset, u32 new_offset)
Ville Syrjälä303ba692017-08-24 22:10:49 +03002255{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002256 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002257 state->base.rotation,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002258 state->color_plane[color_plane].stride,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002259 old_offset, new_offset);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002260}
2261
2262/*
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002263 * Computes the aligned offset to the base tile and adjusts
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002264 * x, y. bytes per pixel is assumed to be a power-of-two.
2265 *
2266 * In the 90/270 rotated case, x and y are assumed
2267 * to be already rotated to match the rotated GTT view, and
2268 * pitch is the tile_height aligned framebuffer height.
Ville Syrjälä6687c902015-09-15 13:16:41 +03002269 *
2270 * This function is used when computing the derived information
2271 * under intel_framebuffer, so using any of that information
2272 * here is not allowed. Anything under drm_framebuffer can be
2273 * used. This is why the user has to pass in the pitch since it
2274 * is specified in the rotated orientation.
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002275 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002276static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2277 int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002278 const struct drm_framebuffer *fb,
2279 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002280 unsigned int pitch,
2281 unsigned int rotation,
2282 u32 alignment)
Daniel Vetterc2c75132012-07-05 12:17:30 +02002283{
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002284 uint64_t fb_modifier = fb->modifier;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002285 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä6687c902015-09-15 13:16:41 +03002286 u32 offset, offset_aligned;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002287
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002288 if (alignment)
2289 alignment--;
2290
Ben Widawsky2f075562017-03-24 14:29:48 -07002291 if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002292 unsigned int tile_size, tile_width, tile_height;
2293 unsigned int tile_rows, tiles, pitch_tiles;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002294
Ville Syrjäläd8433102016-01-12 21:08:35 +02002295 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002296 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002297
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002298 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002299 pitch_tiles = pitch / tile_height;
2300 swap(tile_width, tile_height);
2301 } else {
2302 pitch_tiles = pitch / (tile_width * cpp);
2303 }
Daniel Vetterc2c75132012-07-05 12:17:30 +02002304
Ville Syrjäläd8433102016-01-12 21:08:35 +02002305 tile_rows = *y / tile_height;
2306 *y %= tile_height;
Chris Wilsonbc752862013-02-21 20:04:31 +00002307
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002308 tiles = *x / tile_width;
2309 *x %= tile_width;
Ville Syrjäläd8433102016-01-12 21:08:35 +02002310
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002311 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2312 offset_aligned = offset & ~alignment;
Chris Wilsonbc752862013-02-21 20:04:31 +00002313
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002314 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2315 tile_size, pitch_tiles,
2316 offset, offset_aligned);
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002317 } else {
Chris Wilsonbc752862013-02-21 20:04:31 +00002318 offset = *y * pitch + *x * cpp;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002319 offset_aligned = offset & ~alignment;
2320
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002321 *y = (offset & alignment) / pitch;
2322 *x = ((offset & alignment) - *y * pitch) / cpp;
Chris Wilsonbc752862013-02-21 20:04:31 +00002323 }
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002324
2325 return offset_aligned;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002326}
2327
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002328static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2329 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002330 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002331{
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002332 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2333 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
Ville Syrjälä29490562016-01-20 18:02:50 +02002334 const struct drm_framebuffer *fb = state->base.fb;
2335 unsigned int rotation = state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002336 int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002337 u32 alignment;
2338
2339 if (intel_plane->id == PLANE_CURSOR)
2340 alignment = intel_cursor_alignment(dev_priv);
2341 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002342 alignment = intel_surf_alignment(fb, color_plane);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002343
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002344 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002345 pitch, rotation, alignment);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002346}
2347
Ville Syrjälä303ba692017-08-24 22:10:49 +03002348/* Convert the fb->offset[] into x/y offsets */
2349static int intel_fb_offset_to_xy(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002350 const struct drm_framebuffer *fb,
2351 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002352{
Ville Syrjälä303ba692017-08-24 22:10:49 +03002353 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002354
Ville Syrjälä303ba692017-08-24 22:10:49 +03002355 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002356 fb->offsets[color_plane] % intel_tile_size(dev_priv))
Ville Syrjälä303ba692017-08-24 22:10:49 +03002357 return -EINVAL;
2358
2359 *x = 0;
2360 *y = 0;
2361
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002362 intel_adjust_aligned_offset(x, y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002363 fb, color_plane, DRM_MODE_ROTATE_0,
2364 fb->pitches[color_plane],
2365 fb->offsets[color_plane], 0);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002366
2367 return 0;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002368}
2369
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002370static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2371{
2372 switch (fb_modifier) {
2373 case I915_FORMAT_MOD_X_TILED:
2374 return I915_TILING_X;
2375 case I915_FORMAT_MOD_Y_TILED:
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002376 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002377 return I915_TILING_Y;
2378 default:
2379 return I915_TILING_NONE;
2380 }
2381}
2382
Ville Syrjälä16af25f2018-01-19 16:41:52 +02002383/*
2384 * From the Sky Lake PRM:
2385 * "The Color Control Surface (CCS) contains the compression status of
2386 * the cache-line pairs. The compression state of the cache-line pair
2387 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2388 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2389 * cache-line-pairs. CCS is always Y tiled."
2390 *
2391 * Since cache line pairs refers to horizontally adjacent cache lines,
2392 * each cache line in the CCS corresponds to an area of 32x16 cache
2393 * lines on the main surface. Since each pixel is 4 bytes, this gives
2394 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2395 * main surface.
2396 */
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -07002397static const struct drm_format_info ccs_formats[] = {
2398 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2399 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2400 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2401 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2402};
2403
2404static const struct drm_format_info *
2405lookup_format_info(const struct drm_format_info formats[],
2406 int num_formats, u32 format)
2407{
2408 int i;
2409
2410 for (i = 0; i < num_formats; i++) {
2411 if (formats[i].format == format)
2412 return &formats[i];
2413 }
2414
2415 return NULL;
2416}
2417
2418static const struct drm_format_info *
2419intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2420{
2421 switch (cmd->modifier[0]) {
2422 case I915_FORMAT_MOD_Y_TILED_CCS:
2423 case I915_FORMAT_MOD_Yf_TILED_CCS:
2424 return lookup_format_info(ccs_formats,
2425 ARRAY_SIZE(ccs_formats),
2426 cmd->pixel_format);
2427 default:
2428 return NULL;
2429 }
2430}
2431
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002432bool is_ccs_modifier(u64 modifier)
2433{
2434 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2435 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2436}
2437
Ville Syrjälä6687c902015-09-15 13:16:41 +03002438static int
2439intel_fill_fb_info(struct drm_i915_private *dev_priv,
2440 struct drm_framebuffer *fb)
2441{
2442 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2443 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002444 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002445 u32 gtt_offset_rotated = 0;
2446 unsigned int max_size = 0;
Ville Syrjäläbcb0b462016-12-14 23:30:22 +02002447 int i, num_planes = fb->format->num_planes;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002448 unsigned int tile_size = intel_tile_size(dev_priv);
2449
2450 for (i = 0; i < num_planes; i++) {
2451 unsigned int width, height;
2452 unsigned int cpp, size;
2453 u32 offset;
2454 int x, y;
Ville Syrjälä303ba692017-08-24 22:10:49 +03002455 int ret;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002456
Ville Syrjälä353c8592016-12-14 23:30:57 +02002457 cpp = fb->format->cpp[i];
Ville Syrjälä145fcb12016-11-18 21:53:06 +02002458 width = drm_framebuffer_plane_width(fb->width, fb, i);
2459 height = drm_framebuffer_plane_height(fb->height, fb, i);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002460
Ville Syrjälä303ba692017-08-24 22:10:49 +03002461 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2462 if (ret) {
2463 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2464 i, fb->offsets[i]);
2465 return ret;
2466 }
Ville Syrjälä6687c902015-09-15 13:16:41 +03002467
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002468 if (is_ccs_modifier(fb->modifier) && i == 1) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002469 int hsub = fb->format->hsub;
2470 int vsub = fb->format->vsub;
2471 int tile_width, tile_height;
2472 int main_x, main_y;
2473 int ccs_x, ccs_y;
2474
2475 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002476 tile_width *= hsub;
2477 tile_height *= vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002478
Ville Syrjälä303ba692017-08-24 22:10:49 +03002479 ccs_x = (x * hsub) % tile_width;
2480 ccs_y = (y * vsub) % tile_height;
2481 main_x = intel_fb->normal[0].x % tile_width;
2482 main_y = intel_fb->normal[0].y % tile_height;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002483
2484 /*
2485 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2486 * x/y offsets must match between CCS and the main surface.
2487 */
2488 if (main_x != ccs_x || main_y != ccs_y) {
2489 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2490 main_x, main_y,
2491 ccs_x, ccs_y,
2492 intel_fb->normal[0].x,
2493 intel_fb->normal[0].y,
2494 x, y);
2495 return -EINVAL;
2496 }
2497 }
2498
Ville Syrjälä6687c902015-09-15 13:16:41 +03002499 /*
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002500 * The fence (if used) is aligned to the start of the object
2501 * so having the framebuffer wrap around across the edge of the
2502 * fenced region doesn't really work. We have no API to configure
2503 * the fence start offset within the object (nor could we probably
2504 * on gen2/3). So it's just easier if we just require that the
2505 * fb layout agrees with the fence layout. We already check that the
2506 * fb stride matches the fence stride elsewhere.
2507 */
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002508 if (i == 0 && i915_gem_object_is_tiled(obj) &&
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002509 (x + width) * cpp > fb->pitches[i]) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +02002510 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2511 i, fb->offsets[i]);
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002512 return -EINVAL;
2513 }
2514
2515 /*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002516 * First pixel of the framebuffer from
2517 * the start of the normal gtt mapping.
2518 */
2519 intel_fb->normal[i].x = x;
2520 intel_fb->normal[i].y = y;
2521
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002522 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2523 fb->pitches[i],
2524 DRM_MODE_ROTATE_0,
2525 tile_size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002526 offset /= tile_size;
2527
Ben Widawsky2f075562017-03-24 14:29:48 -07002528 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
Ville Syrjälä6687c902015-09-15 13:16:41 +03002529 unsigned int tile_width, tile_height;
2530 unsigned int pitch_tiles;
2531 struct drm_rect r;
2532
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002533 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002534
2535 rot_info->plane[i].offset = offset;
2536 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2537 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2538 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2539
2540 intel_fb->rotated[i].pitch =
2541 rot_info->plane[i].height * tile_height;
2542
2543 /* how many tiles does this plane need */
2544 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2545 /*
2546 * If the plane isn't horizontally tile aligned,
2547 * we need one more tile.
2548 */
2549 if (x != 0)
2550 size++;
2551
2552 /* rotate the x/y offsets to match the GTT view */
2553 r.x1 = x;
2554 r.y1 = y;
2555 r.x2 = x + width;
2556 r.y2 = y + height;
2557 drm_rect_rotate(&r,
2558 rot_info->plane[i].width * tile_width,
2559 rot_info->plane[i].height * tile_height,
Robert Fossc2c446a2017-05-19 16:50:17 -04002560 DRM_MODE_ROTATE_270);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002561 x = r.x1;
2562 y = r.y1;
2563
2564 /* rotate the tile dimensions to match the GTT view */
2565 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2566 swap(tile_width, tile_height);
2567
2568 /*
2569 * We only keep the x/y offsets, so push all of the
2570 * gtt offset into the x/y offsets.
2571 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002572 intel_adjust_tile_offset(&x, &y,
2573 tile_width, tile_height,
2574 tile_size, pitch_tiles,
2575 gtt_offset_rotated * tile_size, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002576
2577 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2578
2579 /*
2580 * First pixel of the framebuffer from
2581 * the start of the rotated gtt mapping.
2582 */
2583 intel_fb->rotated[i].x = x;
2584 intel_fb->rotated[i].y = y;
2585 } else {
2586 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2587 x * cpp, tile_size);
2588 }
2589
2590 /* how many tiles in total needed in the bo */
2591 max_size = max(max_size, offset + size);
2592 }
2593
Ville Syrjälä4e050472018-09-12 21:04:43 +03002594 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2595 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2596 mul_u32_u32(max_size, tile_size), obj->base.size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002597 return -EINVAL;
2598 }
2599
2600 return 0;
2601}
2602
Damien Lespiaub35d63f2015-01-20 12:51:50 +00002603static int i9xx_format_to_fourcc(int format)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002604{
2605 switch (format) {
2606 case DISPPLANE_8BPP:
2607 return DRM_FORMAT_C8;
2608 case DISPPLANE_BGRX555:
2609 return DRM_FORMAT_XRGB1555;
2610 case DISPPLANE_BGRX565:
2611 return DRM_FORMAT_RGB565;
2612 default:
2613 case DISPPLANE_BGRX888:
2614 return DRM_FORMAT_XRGB8888;
2615 case DISPPLANE_RGBX888:
2616 return DRM_FORMAT_XBGR8888;
2617 case DISPPLANE_BGRX101010:
2618 return DRM_FORMAT_XRGB2101010;
2619 case DISPPLANE_RGBX101010:
2620 return DRM_FORMAT_XBGR2101010;
2621 }
2622}
2623
Mahesh Kumarddf34312018-04-09 09:11:03 +05302624int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002625{
2626 switch (format) {
2627 case PLANE_CTL_FORMAT_RGB_565:
2628 return DRM_FORMAT_RGB565;
Mahesh Kumarf34a2912018-04-09 09:11:02 +05302629 case PLANE_CTL_FORMAT_NV12:
2630 return DRM_FORMAT_NV12;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002631 default:
2632 case PLANE_CTL_FORMAT_XRGB_8888:
2633 if (rgb_order) {
2634 if (alpha)
2635 return DRM_FORMAT_ABGR8888;
2636 else
2637 return DRM_FORMAT_XBGR8888;
2638 } else {
2639 if (alpha)
2640 return DRM_FORMAT_ARGB8888;
2641 else
2642 return DRM_FORMAT_XRGB8888;
2643 }
2644 case PLANE_CTL_FORMAT_XRGB_2101010:
2645 if (rgb_order)
2646 return DRM_FORMAT_XBGR2101010;
2647 else
2648 return DRM_FORMAT_XRGB2101010;
2649 }
2650}
2651
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002652static bool
Daniel Vetterf6936e22015-03-26 12:17:05 +01002653intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2654 struct intel_initial_plane_config *plane_config)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002655{
2656 struct drm_device *dev = crtc->base.dev;
Paulo Zanoni3badb492015-09-23 12:52:23 -03002657 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002658 struct drm_i915_gem_object *obj = NULL;
2659 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
Damien Lespiau2d140302015-02-05 17:22:18 +00002660 struct drm_framebuffer *fb = &plane_config->fb->base;
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002661 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2662 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2663 PAGE_SIZE);
2664
2665 size_aligned -= base_aligned;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002666
Chris Wilsonff2652e2014-03-10 08:07:02 +00002667 if (plane_config->size == 0)
2668 return false;
2669
Paulo Zanoni3badb492015-09-23 12:52:23 -03002670 /* If the FB is too big, just don't use it since fbdev is not very
2671 * important and we should probably use that space with FBC or other
2672 * features. */
Matthew Auldb1ace602017-12-11 15:18:21 +00002673 if (size_aligned * 2 > dev_priv->stolen_usable_size)
Paulo Zanoni3badb492015-09-23 12:52:23 -03002674 return false;
2675
Imre Deak914a4fd2018-10-16 19:00:11 +03002676 switch (fb->modifier) {
2677 case DRM_FORMAT_MOD_LINEAR:
2678 case I915_FORMAT_MOD_X_TILED:
2679 case I915_FORMAT_MOD_Y_TILED:
2680 break;
2681 default:
2682 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2683 fb->modifier);
2684 return false;
2685 }
2686
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002687 mutex_lock(&dev->struct_mutex);
Tvrtko Ursulin187685c2016-12-01 14:16:36 +00002688 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002689 base_aligned,
2690 base_aligned,
2691 size_aligned);
Chris Wilson24dbf512017-02-15 10:59:18 +00002692 mutex_unlock(&dev->struct_mutex);
2693 if (!obj)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002694 return false;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002695
Imre Deak914a4fd2018-10-16 19:00:11 +03002696 switch (plane_config->tiling) {
2697 case I915_TILING_NONE:
2698 break;
2699 case I915_TILING_X:
2700 case I915_TILING_Y:
2701 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2702 break;
2703 default:
2704 MISSING_CASE(plane_config->tiling);
2705 return false;
2706 }
Jesse Barnes46f297f2014-03-07 08:57:48 -08002707
Ville Syrjälä438b74a2016-12-14 23:32:55 +02002708 mode_cmd.pixel_format = fb->format->format;
Damien Lespiau6bf129d2015-02-05 17:22:16 +00002709 mode_cmd.width = fb->width;
2710 mode_cmd.height = fb->height;
2711 mode_cmd.pitches[0] = fb->pitches[0];
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002712 mode_cmd.modifier[0] = fb->modifier;
Daniel Vetter18c52472015-02-10 17:16:09 +00002713 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002714
Chris Wilson24dbf512017-02-15 10:59:18 +00002715 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
Jesse Barnes46f297f2014-03-07 08:57:48 -08002716 DRM_DEBUG_KMS("intel fb init failed\n");
2717 goto out_unref_obj;
2718 }
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002719
Jesse Barnes484b41d2014-03-07 08:57:55 -08002720
Daniel Vetterf6936e22015-03-26 12:17:05 +01002721 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002722 return true;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002723
2724out_unref_obj:
Chris Wilsonf8c417c2016-07-20 13:31:53 +01002725 i915_gem_object_put(obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002726 return false;
2727}
2728
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002729static void
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002730intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2731 struct intel_plane_state *plane_state,
2732 bool visible)
2733{
2734 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2735
2736 plane_state->base.visible = visible;
2737
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002738 if (visible)
Ville Syrjälä40560e22018-06-26 22:47:11 +03002739 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002740 else
Ville Syrjälä40560e22018-06-26 22:47:11 +03002741 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002742}
2743
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002744static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2745{
2746 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2747 struct drm_plane *plane;
2748
2749 /*
2750 * Active_planes aliases if multiple "primary" or cursor planes
2751 * have been used on the same (or wrong) pipe. plane_mask uses
2752 * unique ids, hence we can use that to reconstruct active_planes.
2753 */
2754 crtc_state->active_planes = 0;
2755
2756 drm_for_each_plane_mask(plane, &dev_priv->drm,
2757 crtc_state->base.plane_mask)
2758 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2759}
2760
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002761static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2762 struct intel_plane *plane)
2763{
2764 struct intel_crtc_state *crtc_state =
2765 to_intel_crtc_state(crtc->base.state);
2766 struct intel_plane_state *plane_state =
2767 to_intel_plane_state(plane->base.state);
2768
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +03002769 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2770 plane->base.base.id, plane->base.name,
2771 crtc->base.base.id, crtc->base.name);
2772
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002773 intel_set_plane_visible(crtc_state, plane_state, false);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002774 fixup_active_planes(crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002775
2776 if (plane->id == PLANE_PRIMARY)
2777 intel_pre_disable_primary_noatomic(&crtc->base);
2778
2779 trace_intel_disable_plane(&plane->base, crtc);
2780 plane->disable_plane(plane, crtc);
2781}
2782
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002783static void
Daniel Vetterf6936e22015-03-26 12:17:05 +01002784intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2785 struct intel_initial_plane_config *plane_config)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002786{
2787 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002788 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002789 struct drm_crtc *c;
Matt Roper2ff8fde2014-07-08 07:50:07 -07002790 struct drm_i915_gem_object *obj;
Daniel Vetter88595ac2015-03-26 12:42:24 +01002791 struct drm_plane *primary = intel_crtc->base.primary;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002792 struct drm_plane_state *plane_state = primary->state;
Matt Roper200757f2015-12-03 11:37:36 -08002793 struct intel_plane *intel_plane = to_intel_plane(primary);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002794 struct intel_plane_state *intel_state =
2795 to_intel_plane_state(plane_state);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002796 struct drm_framebuffer *fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002797
Damien Lespiau2d140302015-02-05 17:22:18 +00002798 if (!plane_config->fb)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002799 return;
2800
Daniel Vetterf6936e22015-03-26 12:17:05 +01002801 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
Daniel Vetter88595ac2015-03-26 12:42:24 +01002802 fb = &plane_config->fb->base;
2803 goto valid_fb;
Damien Lespiauf55548b2015-02-05 18:30:20 +00002804 }
Jesse Barnes484b41d2014-03-07 08:57:55 -08002805
Damien Lespiau2d140302015-02-05 17:22:18 +00002806 kfree(plane_config->fb);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002807
2808 /*
2809 * Failed to alloc the obj, check to see if we should share
2810 * an fb with another CRTC instead
2811 */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +01002812 for_each_crtc(dev, c) {
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002813 struct intel_plane_state *state;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002814
2815 if (c == &intel_crtc->base)
2816 continue;
2817
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002818 if (!to_intel_crtc(c)->active)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002819 continue;
2820
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002821 state = to_intel_plane_state(c->primary->state);
2822 if (!state->vma)
Matt Roper2ff8fde2014-07-08 07:50:07 -07002823 continue;
2824
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002825 if (intel_plane_ggtt_offset(state) == plane_config->base) {
Ville Syrjälä8bc20f62018-03-22 17:22:59 +02002826 fb = state->base.fb;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302827 drm_framebuffer_get(fb);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002828 goto valid_fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002829 }
2830 }
Daniel Vetter88595ac2015-03-26 12:42:24 +01002831
Matt Roper200757f2015-12-03 11:37:36 -08002832 /*
2833 * We've failed to reconstruct the BIOS FB. Current display state
2834 * indicates that the primary plane is visible, but has a NULL FB,
2835 * which will lead to problems later if we don't fix it up. The
2836 * simplest solution is to just disable the primary plane now and
2837 * pretend the BIOS never had it enabled.
2838 */
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002839 intel_plane_disable_noatomic(intel_crtc, intel_plane);
Matt Roper200757f2015-12-03 11:37:36 -08002840
Daniel Vetter88595ac2015-03-26 12:42:24 +01002841 return;
2842
2843valid_fb:
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002844 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2845 intel_state->base.rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002846 intel_state->color_plane[0].stride =
2847 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2848
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002849 mutex_lock(&dev->struct_mutex);
2850 intel_state->vma =
Chris Wilson59354852018-02-20 13:42:06 +00002851 intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002852 &intel_state->view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002853 intel_plane_uses_fence(intel_state),
Chris Wilson59354852018-02-20 13:42:06 +00002854 &intel_state->flags);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002855 mutex_unlock(&dev->struct_mutex);
2856 if (IS_ERR(intel_state->vma)) {
2857 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2858 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2859
2860 intel_state->vma = NULL;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302861 drm_framebuffer_put(fb);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002862 return;
2863 }
2864
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -08002865 obj = intel_fb_obj(fb);
2866 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2867
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002868 plane_state->src_x = 0;
2869 plane_state->src_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002870 plane_state->src_w = fb->width << 16;
2871 plane_state->src_h = fb->height << 16;
2872
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002873 plane_state->crtc_x = 0;
2874 plane_state->crtc_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002875 plane_state->crtc_w = fb->width;
2876 plane_state->crtc_h = fb->height;
2877
Rob Clark1638d302016-11-05 11:08:08 -04002878 intel_state->base.src = drm_plane_state_src(plane_state);
2879 intel_state->base.dst = drm_plane_state_dest(plane_state);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002880
Chris Wilson3e510a82016-08-05 10:14:23 +01002881 if (i915_gem_object_is_tiled(obj))
Daniel Vetter88595ac2015-03-26 12:42:24 +01002882 dev_priv->preserve_bios_swizzle = true;
2883
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +03002884 plane_state->fb = fb;
2885 plane_state->crtc = &intel_crtc->base;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002886
Chris Wilsonfaf5bf02016-08-04 16:32:37 +01002887 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2888 &obj->frontbuffer_bits);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002889}
2890
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002891static int skl_max_plane_width(const struct drm_framebuffer *fb,
2892 int color_plane,
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002893 unsigned int rotation)
2894{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002895 int cpp = fb->format->cpp[color_plane];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002896
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002897 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002898 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002899 case I915_FORMAT_MOD_X_TILED:
2900 switch (cpp) {
2901 case 8:
2902 return 4096;
2903 case 4:
2904 case 2:
2905 case 1:
2906 return 8192;
2907 default:
2908 MISSING_CASE(cpp);
2909 break;
2910 }
2911 break;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002912 case I915_FORMAT_MOD_Y_TILED_CCS:
2913 case I915_FORMAT_MOD_Yf_TILED_CCS:
2914 /* FIXME AUX plane? */
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002915 case I915_FORMAT_MOD_Y_TILED:
2916 case I915_FORMAT_MOD_Yf_TILED:
2917 switch (cpp) {
2918 case 8:
2919 return 2048;
2920 case 4:
2921 return 4096;
2922 case 2:
2923 case 1:
2924 return 8192;
2925 default:
2926 MISSING_CASE(cpp);
2927 break;
2928 }
2929 break;
2930 default:
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002931 MISSING_CASE(fb->modifier);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002932 }
2933
2934 return 2048;
2935}
2936
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002937static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2938 int main_x, int main_y, u32 main_offset)
2939{
2940 const struct drm_framebuffer *fb = plane_state->base.fb;
2941 int hsub = fb->format->hsub;
2942 int vsub = fb->format->vsub;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002943 int aux_x = plane_state->color_plane[1].x;
2944 int aux_y = plane_state->color_plane[1].y;
2945 u32 aux_offset = plane_state->color_plane[1].offset;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002946 u32 alignment = intel_surf_alignment(fb, 1);
2947
2948 while (aux_offset >= main_offset && aux_y <= main_y) {
2949 int x, y;
2950
2951 if (aux_x == main_x && aux_y == main_y)
2952 break;
2953
2954 if (aux_offset == 0)
2955 break;
2956
2957 x = aux_x / hsub;
2958 y = aux_y / vsub;
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002959 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
2960 aux_offset, aux_offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002961 aux_x = x * hsub + aux_x % hsub;
2962 aux_y = y * vsub + aux_y % vsub;
2963 }
2964
2965 if (aux_x != main_x || aux_y != main_y)
2966 return false;
2967
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002968 plane_state->color_plane[1].offset = aux_offset;
2969 plane_state->color_plane[1].x = aux_x;
2970 plane_state->color_plane[1].y = aux_y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002971
2972 return true;
2973}
2974
Ville Syrjälä73266592018-09-07 18:24:11 +03002975static int skl_check_main_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002976{
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002977 const struct drm_framebuffer *fb = plane_state->base.fb;
2978 unsigned int rotation = plane_state->base.rotation;
Daniel Vettercc926382016-08-15 10:41:47 +02002979 int x = plane_state->base.src.x1 >> 16;
2980 int y = plane_state->base.src.y1 >> 16;
2981 int w = drm_rect_width(&plane_state->base.src) >> 16;
2982 int h = drm_rect_height(&plane_state->base.src) >> 16;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002983 int max_width = skl_max_plane_width(fb, 0, rotation);
2984 int max_height = 4096;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002985 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002986
2987 if (w > max_width || h > max_height) {
2988 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2989 w, h, max_width, max_height);
2990 return -EINVAL;
2991 }
2992
2993 intel_add_fb_offsets(&x, &y, plane_state, 0);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002994 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002995 alignment = intel_surf_alignment(fb, 0);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002996
2997 /*
Ville Syrjälä8d970652016-01-28 16:30:28 +02002998 * AUX surface offset is specified as the distance from the
2999 * main surface offset, and it must be non-negative. Make
3000 * sure that is what we will get.
3001 */
3002 if (offset > aux_offset)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003003 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3004 offset, aux_offset & ~(alignment - 1));
Ville Syrjälä8d970652016-01-28 16:30:28 +02003005
3006 /*
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003007 * When using an X-tiled surface, the plane blows up
3008 * if the x offset + width exceed the stride.
3009 *
3010 * TODO: linear and Y-tiled seem fine, Yf untested,
3011 */
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003012 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
Ville Syrjälä353c8592016-12-14 23:30:57 +02003013 int cpp = fb->format->cpp[0];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003014
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003015 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003016 if (offset == 0) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003017 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003018 return -EINVAL;
3019 }
3020
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003021 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3022 offset, offset - alignment);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003023 }
3024 }
3025
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003026 /*
3027 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3028 * they match with the main surface x/y offsets.
3029 */
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003030 if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003031 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3032 if (offset == 0)
3033 break;
3034
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003035 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3036 offset, offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003037 }
3038
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003039 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003040 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3041 return -EINVAL;
3042 }
3043 }
3044
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003045 plane_state->color_plane[0].offset = offset;
3046 plane_state->color_plane[0].x = x;
3047 plane_state->color_plane[0].y = y;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003048
3049 return 0;
3050}
3051
Ville Syrjälä8d970652016-01-28 16:30:28 +02003052static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3053{
3054 const struct drm_framebuffer *fb = plane_state->base.fb;
3055 unsigned int rotation = plane_state->base.rotation;
3056 int max_width = skl_max_plane_width(fb, 1, rotation);
3057 int max_height = 4096;
Daniel Vettercc926382016-08-15 10:41:47 +02003058 int x = plane_state->base.src.x1 >> 17;
3059 int y = plane_state->base.src.y1 >> 17;
3060 int w = drm_rect_width(&plane_state->base.src) >> 17;
3061 int h = drm_rect_height(&plane_state->base.src) >> 17;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003062 u32 offset;
3063
3064 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003065 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä8d970652016-01-28 16:30:28 +02003066
3067 /* FIXME not quite sure how/if these apply to the chroma plane */
3068 if (w > max_width || h > max_height) {
3069 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3070 w, h, max_width, max_height);
3071 return -EINVAL;
3072 }
3073
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003074 plane_state->color_plane[1].offset = offset;
3075 plane_state->color_plane[1].x = x;
3076 plane_state->color_plane[1].y = y;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003077
3078 return 0;
3079}
3080
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003081static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3082{
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003083 const struct drm_framebuffer *fb = plane_state->base.fb;
3084 int src_x = plane_state->base.src.x1 >> 16;
3085 int src_y = plane_state->base.src.y1 >> 16;
3086 int hsub = fb->format->hsub;
3087 int vsub = fb->format->vsub;
3088 int x = src_x / hsub;
3089 int y = src_y / vsub;
3090 u32 offset;
3091
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003092 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003093 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003094
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003095 plane_state->color_plane[1].offset = offset;
3096 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3097 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003098
3099 return 0;
3100}
3101
Ville Syrjälä73266592018-09-07 18:24:11 +03003102int skl_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003103{
3104 const struct drm_framebuffer *fb = plane_state->base.fb;
3105 unsigned int rotation = plane_state->base.rotation;
3106 int ret;
3107
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003108 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003109 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3110 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3111
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003112 ret = intel_plane_check_stride(plane_state);
3113 if (ret)
3114 return ret;
3115
Ville Syrjäläa5e4c7d2016-11-07 22:20:54 +02003116 if (!plane_state->base.visible)
3117 return 0;
3118
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003119 /* Rotate src coordinates to match rotated GTT view */
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03003120 if (drm_rotation_90_or_270(rotation))
Daniel Vettercc926382016-08-15 10:41:47 +02003121 drm_rect_rotate(&plane_state->base.src,
Ville Syrjäläda064b42016-10-24 19:13:04 +03003122 fb->width << 16, fb->height << 16,
Robert Fossc2c446a2017-05-19 16:50:17 -04003123 DRM_MODE_ROTATE_270);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003124
Ville Syrjälä8d970652016-01-28 16:30:28 +02003125 /*
3126 * Handle the AUX surface first since
3127 * the main surface setup depends on it.
3128 */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003129 if (fb->format->format == DRM_FORMAT_NV12) {
Ville Syrjälä8d970652016-01-28 16:30:28 +02003130 ret = skl_check_nv12_aux_surface(plane_state);
3131 if (ret)
3132 return ret;
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003133 } else if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003134 ret = skl_check_ccs_aux_surface(plane_state);
3135 if (ret)
3136 return ret;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003137 } else {
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003138 plane_state->color_plane[1].offset = ~0xfff;
3139 plane_state->color_plane[1].x = 0;
3140 plane_state->color_plane[1].y = 0;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003141 }
3142
Ville Syrjälä73266592018-09-07 18:24:11 +03003143 ret = skl_check_main_surface(plane_state);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003144 if (ret)
3145 return ret;
3146
3147 return 0;
3148}
3149
Ville Syrjäläddd57132018-09-07 18:24:02 +03003150unsigned int
3151i9xx_plane_max_stride(struct intel_plane *plane,
3152 u32 pixel_format, u64 modifier,
3153 unsigned int rotation)
3154{
3155 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3156
3157 if (!HAS_GMCH_DISPLAY(dev_priv)) {
3158 return 32*1024;
3159 } else if (INTEL_GEN(dev_priv) >= 4) {
3160 if (modifier == I915_FORMAT_MOD_X_TILED)
3161 return 16*1024;
3162 else
3163 return 32*1024;
3164 } else if (INTEL_GEN(dev_priv) >= 3) {
3165 if (modifier == I915_FORMAT_MOD_X_TILED)
3166 return 8*1024;
3167 else
3168 return 16*1024;
3169 } else {
3170 if (plane->i9xx_plane == PLANE_C)
3171 return 4*1024;
3172 else
3173 return 8*1024;
3174 }
3175}
3176
Ville Syrjälä7145f602017-03-23 21:27:07 +02003177static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3178 const struct intel_plane_state *plane_state)
Jesse Barnes81255562010-08-02 12:07:50 -07003179{
Ville Syrjälä7145f602017-03-23 21:27:07 +02003180 struct drm_i915_private *dev_priv =
3181 to_i915(plane_state->base.plane->dev);
3182 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3183 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02003184 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003185 u32 dspcntr;
Ville Syrjäläc9ba6fa2014-08-27 17:48:41 +03003186
Ville Syrjälä7145f602017-03-23 21:27:07 +02003187 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003188
Ville Syrjälä6a4407a2017-03-23 21:27:08 +02003189 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3190 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
Ville Syrjälä7145f602017-03-23 21:27:07 +02003191 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003192
Ville Syrjälä6a4407a2017-03-23 21:27:08 +02003193 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3194 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003195
Ville Syrjäläc154d1e2018-01-30 22:38:02 +02003196 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjäläd509e282017-03-27 21:55:32 +03003197 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003198
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003199 switch (fb->format->format) {
Ville Syrjälä57779d02012-10-31 17:50:14 +02003200 case DRM_FORMAT_C8:
Jesse Barnes81255562010-08-02 12:07:50 -07003201 dspcntr |= DISPPLANE_8BPP;
3202 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003203 case DRM_FORMAT_XRGB1555:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003204 dspcntr |= DISPPLANE_BGRX555;
Jesse Barnes81255562010-08-02 12:07:50 -07003205 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003206 case DRM_FORMAT_RGB565:
3207 dspcntr |= DISPPLANE_BGRX565;
3208 break;
3209 case DRM_FORMAT_XRGB8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003210 dspcntr |= DISPPLANE_BGRX888;
3211 break;
3212 case DRM_FORMAT_XBGR8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003213 dspcntr |= DISPPLANE_RGBX888;
3214 break;
3215 case DRM_FORMAT_XRGB2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003216 dspcntr |= DISPPLANE_BGRX101010;
3217 break;
3218 case DRM_FORMAT_XBGR2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003219 dspcntr |= DISPPLANE_RGBX101010;
Jesse Barnes81255562010-08-02 12:07:50 -07003220 break;
3221 default:
Ville Syrjälä7145f602017-03-23 21:27:07 +02003222 MISSING_CASE(fb->format->format);
3223 return 0;
Jesse Barnes81255562010-08-02 12:07:50 -07003224 }
Ville Syrjälä57779d02012-10-31 17:50:14 +02003225
Ville Syrjälä72618eb2016-02-04 20:38:20 +02003226 if (INTEL_GEN(dev_priv) >= 4 &&
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003227 fb->modifier == I915_FORMAT_MOD_X_TILED)
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003228 dspcntr |= DISPPLANE_TILED;
Jesse Barnes81255562010-08-02 12:07:50 -07003229
Robert Fossc2c446a2017-05-19 16:50:17 -04003230 if (rotation & DRM_MODE_ROTATE_180)
Ville Syrjälädf0cd452016-11-14 18:53:59 +02003231 dspcntr |= DISPPLANE_ROTATE_180;
3232
Robert Fossc2c446a2017-05-19 16:50:17 -04003233 if (rotation & DRM_MODE_REFLECT_X)
Ville Syrjälä4ea7be22016-11-14 18:54:00 +02003234 dspcntr |= DISPPLANE_MIRROR;
3235
Ville Syrjälä7145f602017-03-23 21:27:07 +02003236 return dspcntr;
3237}
Ville Syrjäläde1aa622013-06-07 10:47:01 +03003238
Ville Syrjäläf9407ae2017-03-23 21:27:12 +02003239int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003240{
3241 struct drm_i915_private *dev_priv =
3242 to_i915(plane_state->base.plane->dev);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003243 const struct drm_framebuffer *fb = plane_state->base.fb;
3244 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003245 int src_x = plane_state->base.src.x1 >> 16;
3246 int src_y = plane_state->base.src.y1 >> 16;
3247 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003248 int ret;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003249
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003250 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003251 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3252
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003253 ret = intel_plane_check_stride(plane_state);
3254 if (ret)
3255 return ret;
3256
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003257 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
Jesse Barnes81255562010-08-02 12:07:50 -07003258
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003259 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003260 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3261 plane_state, 0);
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003262 else
3263 offset = 0;
Daniel Vettere506a0c2012-07-05 12:17:29 +02003264
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003265 /* HSW/BDW do this automagically in hardware */
3266 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003267 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3268 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3269
Robert Fossc2c446a2017-05-19 16:50:17 -04003270 if (rotation & DRM_MODE_ROTATE_180) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003271 src_x += src_w - 1;
3272 src_y += src_h - 1;
Robert Fossc2c446a2017-05-19 16:50:17 -04003273 } else if (rotation & DRM_MODE_REFLECT_X) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003274 src_x += src_w - 1;
3275 }
Sonika Jindal48404c12014-08-22 14:06:04 +05303276 }
3277
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003278 plane_state->color_plane[0].offset = offset;
3279 plane_state->color_plane[0].x = src_x;
3280 plane_state->color_plane[0].y = src_y;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003281
3282 return 0;
3283}
3284
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003285static int
3286i9xx_plane_check(struct intel_crtc_state *crtc_state,
3287 struct intel_plane_state *plane_state)
3288{
3289 int ret;
3290
Ville Syrjälä25721f82018-09-07 18:24:12 +03003291 ret = chv_plane_check_rotation(plane_state);
3292 if (ret)
3293 return ret;
3294
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003295 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3296 &crtc_state->base,
3297 DRM_PLANE_HELPER_NO_SCALING,
3298 DRM_PLANE_HELPER_NO_SCALING,
3299 false, true);
3300 if (ret)
3301 return ret;
3302
3303 if (!plane_state->base.visible)
3304 return 0;
3305
3306 ret = intel_plane_check_src_coordinates(plane_state);
3307 if (ret)
3308 return ret;
3309
3310 ret = i9xx_check_plane_surface(plane_state);
3311 if (ret)
3312 return ret;
3313
3314 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3315
3316 return 0;
3317}
3318
Ville Syrjäläed150302017-11-17 21:19:10 +02003319static void i9xx_update_plane(struct intel_plane *plane,
3320 const struct intel_crtc_state *crtc_state,
3321 const struct intel_plane_state *plane_state)
Ville Syrjälä7145f602017-03-23 21:27:07 +02003322{
Ville Syrjäläed150302017-11-17 21:19:10 +02003323 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläed150302017-11-17 21:19:10 +02003324 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003325 u32 linear_offset;
Ville Syrjäläa0864d52017-03-23 21:27:09 +02003326 u32 dspcntr = plane_state->ctl;
Ville Syrjäläed150302017-11-17 21:19:10 +02003327 i915_reg_t reg = DSPCNTR(i9xx_plane);
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003328 int x = plane_state->color_plane[0].x;
3329 int y = plane_state->color_plane[0].y;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003330 unsigned long irqflags;
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003331 u32 dspaddr_offset;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003332
Ville Syrjälä29490562016-01-20 18:02:50 +02003333 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03003334
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003335 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003336 dspaddr_offset = plane_state->color_plane[0].offset;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003337 else
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003338 dspaddr_offset = linear_offset;
Ville Syrjälä6687c902015-09-15 13:16:41 +03003339
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003340 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3341
Ville Syrjälä78587de2017-03-09 17:44:32 +02003342 if (INTEL_GEN(dev_priv) < 4) {
3343 /* pipesrc and dspsize control the size that is scaled from,
3344 * which should always be the user's requested size.
3345 */
Ville Syrjäläed150302017-11-17 21:19:10 +02003346 I915_WRITE_FW(DSPSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003347 ((crtc_state->pipe_src_h - 1) << 16) |
3348 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003349 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3350 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3351 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003352 ((crtc_state->pipe_src_h - 1) << 16) |
3353 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003354 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3355 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
Ville Syrjälä78587de2017-03-09 17:44:32 +02003356 }
3357
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003358 I915_WRITE_FW(reg, dspcntr);
Sonika Jindal48404c12014-08-22 14:06:04 +05303359
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003360 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003361 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjäläed150302017-11-17 21:19:10 +02003362 I915_WRITE_FW(DSPSURF(i9xx_plane),
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003363 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003364 dspaddr_offset);
Ville Syrjäläed150302017-11-17 21:19:10 +02003365 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003366 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjäläed150302017-11-17 21:19:10 +02003367 I915_WRITE_FW(DSPSURF(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003368 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003369 dspaddr_offset);
Ville Syrjäläed150302017-11-17 21:19:10 +02003370 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3371 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
Ville Syrjäläbfb81042016-11-07 22:20:57 +02003372 } else {
Ville Syrjäläed150302017-11-17 21:19:10 +02003373 I915_WRITE_FW(DSPADDR(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003374 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003375 dspaddr_offset);
Ville Syrjäläbfb81042016-11-07 22:20:57 +02003376 }
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003377 POSTING_READ_FW(reg);
3378
3379 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes17638cd2011-06-24 12:19:23 -07003380}
3381
Ville Syrjäläed150302017-11-17 21:19:10 +02003382static void i9xx_disable_plane(struct intel_plane *plane,
3383 struct intel_crtc *crtc)
Jesse Barnes17638cd2011-06-24 12:19:23 -07003384{
Ville Syrjäläed150302017-11-17 21:19:10 +02003385 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3386 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003387 unsigned long irqflags;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003388
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003389 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3390
Ville Syrjäläed150302017-11-17 21:19:10 +02003391 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3392 if (INTEL_GEN(dev_priv) >= 4)
3393 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003394 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003395 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3396 POSTING_READ_FW(DSPCNTR(i9xx_plane));
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003397
3398 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003399}
3400
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003401static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3402 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003403{
Ville Syrjäläed150302017-11-17 21:19:10 +02003404 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003405 enum intel_display_power_domain power_domain;
Ville Syrjäläed150302017-11-17 21:19:10 +02003406 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003407 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003408 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003409
3410 /*
3411 * Not 100% correct for planes that can move between pipes,
3412 * but that's only the case for gen2-4 which don't have any
3413 * display power wells.
3414 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003415 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003416 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3417 return false;
3418
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003419 val = I915_READ(DSPCNTR(i9xx_plane));
3420
3421 ret = val & DISPLAY_PLANE_ENABLE;
3422
3423 if (INTEL_GEN(dev_priv) >= 5)
3424 *pipe = plane->pipe;
3425 else
3426 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3427 DISPPLANE_SEL_PIPE_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003428
3429 intel_display_power_put(dev_priv, power_domain);
3430
3431 return ret;
3432}
3433
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003434static u32
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003435intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
Damien Lespiaub3218032015-02-27 11:15:18 +00003436{
Ben Widawsky2f075562017-03-24 14:29:48 -07003437 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02003438 return 64;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003439 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003440 return intel_tile_width_bytes(fb, color_plane);
Damien Lespiaub3218032015-02-27 11:15:18 +00003441}
3442
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003443static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3444{
3445 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003446 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003447
3448 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3449 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3450 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003451}
3452
Chandra Kondurua1b22782015-04-07 15:28:45 -07003453/*
3454 * This function detaches (aka. unbinds) unused scalers in hardware
3455 */
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003456static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
Chandra Kondurua1b22782015-04-07 15:28:45 -07003457{
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003458 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3459 const struct intel_crtc_scaler_state *scaler_state =
3460 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07003461 int i;
3462
Chandra Kondurua1b22782015-04-07 15:28:45 -07003463 /* loop through and disable scalers that aren't in use */
3464 for (i = 0; i < intel_crtc->num_scalers; i++) {
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003465 if (!scaler_state->scalers[i].in_use)
3466 skl_detach_scaler(intel_crtc, i);
Chandra Kondurua1b22782015-04-07 15:28:45 -07003467 }
3468}
3469
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003470u32 skl_plane_stride(const struct intel_plane_state *plane_state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003471 int color_plane)
Ville Syrjäläd2196772016-01-28 18:33:11 +02003472{
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003473 const struct drm_framebuffer *fb = plane_state->base.fb;
3474 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003475 u32 stride = plane_state->color_plane[color_plane].stride;
Ville Syrjälä1b500532017-03-07 21:42:08 +02003476
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003477 if (color_plane >= fb->format->num_planes)
Ville Syrjälä1b500532017-03-07 21:42:08 +02003478 return 0;
3479
Ville Syrjäläd2196772016-01-28 18:33:11 +02003480 /*
3481 * The stride is either expressed as a multiple of 64 bytes chunks for
3482 * linear buffers or in number of tiles for tiled buffers.
3483 */
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003484 if (drm_rotation_90_or_270(rotation))
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003485 stride /= intel_tile_height(fb, color_plane);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003486 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003487 stride /= intel_fb_stride_alignment(fb, color_plane);
Ville Syrjäläd2196772016-01-28 18:33:11 +02003488
3489 return stride;
3490}
3491
Ville Syrjälä2e881262017-03-17 23:17:56 +02003492static u32 skl_plane_ctl_format(uint32_t pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -07003493{
Chandra Konduru6156a452015-04-27 13:48:39 -07003494 switch (pixel_format) {
Damien Lespiaud161cf72015-05-12 16:13:17 +01003495 case DRM_FORMAT_C8:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003496 return PLANE_CTL_FORMAT_INDEXED;
Chandra Konduru6156a452015-04-27 13:48:39 -07003497 case DRM_FORMAT_RGB565:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003498 return PLANE_CTL_FORMAT_RGB_565;
Chandra Konduru6156a452015-04-27 13:48:39 -07003499 case DRM_FORMAT_XBGR8888:
James Ausmus4036c782017-11-13 10:11:28 -08003500 case DRM_FORMAT_ABGR8888:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003501 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
Chandra Konduru6156a452015-04-27 13:48:39 -07003502 case DRM_FORMAT_XRGB8888:
Chandra Konduru6156a452015-04-27 13:48:39 -07003503 case DRM_FORMAT_ARGB8888:
James Ausmus4036c782017-11-13 10:11:28 -08003504 return PLANE_CTL_FORMAT_XRGB_8888;
Chandra Konduru6156a452015-04-27 13:48:39 -07003505 case DRM_FORMAT_XRGB2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003506 return PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003507 case DRM_FORMAT_XBGR2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003508 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003509 case DRM_FORMAT_YUYV:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003510 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
Chandra Konduru6156a452015-04-27 13:48:39 -07003511 case DRM_FORMAT_YVYU:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003512 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
Chandra Konduru6156a452015-04-27 13:48:39 -07003513 case DRM_FORMAT_UYVY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003514 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
Chandra Konduru6156a452015-04-27 13:48:39 -07003515 case DRM_FORMAT_VYUY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003516 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
Chandra Konduru77224cd2018-04-09 09:11:13 +05303517 case DRM_FORMAT_NV12:
3518 return PLANE_CTL_FORMAT_NV12;
Chandra Konduru6156a452015-04-27 13:48:39 -07003519 default:
Damien Lespiau4249eee2015-05-12 16:13:16 +01003520 MISSING_CASE(pixel_format);
Chandra Konduru6156a452015-04-27 13:48:39 -07003521 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003522
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003523 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003524}
3525
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003526static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003527{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003528 if (!plane_state->base.fb->format->has_alpha)
3529 return PLANE_CTL_ALPHA_DISABLE;
3530
3531 switch (plane_state->base.pixel_blend_mode) {
3532 case DRM_MODE_BLEND_PIXEL_NONE:
3533 return PLANE_CTL_ALPHA_DISABLE;
3534 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003535 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003536 case DRM_MODE_BLEND_COVERAGE:
3537 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003538 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003539 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003540 return PLANE_CTL_ALPHA_DISABLE;
3541 }
3542}
3543
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003544static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003545{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003546 if (!plane_state->base.fb->format->has_alpha)
3547 return PLANE_COLOR_ALPHA_DISABLE;
3548
3549 switch (plane_state->base.pixel_blend_mode) {
3550 case DRM_MODE_BLEND_PIXEL_NONE:
3551 return PLANE_COLOR_ALPHA_DISABLE;
3552 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003553 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003554 case DRM_MODE_BLEND_COVERAGE:
3555 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003556 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003557 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003558 return PLANE_COLOR_ALPHA_DISABLE;
3559 }
3560}
3561
Ville Syrjälä2e881262017-03-17 23:17:56 +02003562static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
Chandra Konduru6156a452015-04-27 13:48:39 -07003563{
Chandra Konduru6156a452015-04-27 13:48:39 -07003564 switch (fb_modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07003565 case DRM_FORMAT_MOD_LINEAR:
Chandra Konduru6156a452015-04-27 13:48:39 -07003566 break;
3567 case I915_FORMAT_MOD_X_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003568 return PLANE_CTL_TILED_X;
Chandra Konduru6156a452015-04-27 13:48:39 -07003569 case I915_FORMAT_MOD_Y_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003570 return PLANE_CTL_TILED_Y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003571 case I915_FORMAT_MOD_Y_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003572 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003573 case I915_FORMAT_MOD_Yf_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003574 return PLANE_CTL_TILED_YF;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003575 case I915_FORMAT_MOD_Yf_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003576 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003577 default:
3578 MISSING_CASE(fb_modifier);
3579 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003580
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003581 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003582}
3583
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003584static u32 skl_plane_ctl_rotate(unsigned int rotate)
Chandra Konduru6156a452015-04-27 13:48:39 -07003585{
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003586 switch (rotate) {
Robert Fossc2c446a2017-05-19 16:50:17 -04003587 case DRM_MODE_ROTATE_0:
Chandra Konduru6156a452015-04-27 13:48:39 -07003588 break;
Sonika Jindal1e8df162015-05-20 13:40:48 +05303589 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003590 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
Sonika Jindal1e8df162015-05-20 13:40:48 +05303591 * while i915 HW rotation is clockwise, thats why this swapping.
3592 */
Robert Fossc2c446a2017-05-19 16:50:17 -04003593 case DRM_MODE_ROTATE_90:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303594 return PLANE_CTL_ROTATE_270;
Robert Fossc2c446a2017-05-19 16:50:17 -04003595 case DRM_MODE_ROTATE_180:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003596 return PLANE_CTL_ROTATE_180;
Robert Fossc2c446a2017-05-19 16:50:17 -04003597 case DRM_MODE_ROTATE_270:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303598 return PLANE_CTL_ROTATE_90;
Chandra Konduru6156a452015-04-27 13:48:39 -07003599 default:
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003600 MISSING_CASE(rotate);
3601 }
3602
3603 return 0;
3604}
3605
3606static u32 cnl_plane_ctl_flip(unsigned int reflect)
3607{
3608 switch (reflect) {
3609 case 0:
3610 break;
3611 case DRM_MODE_REFLECT_X:
3612 return PLANE_CTL_FLIP_HORIZONTAL;
3613 case DRM_MODE_REFLECT_Y:
3614 default:
3615 MISSING_CASE(reflect);
Chandra Konduru6156a452015-04-27 13:48:39 -07003616 }
3617
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003618 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003619}
3620
Ville Syrjälä2e881262017-03-17 23:17:56 +02003621u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3622 const struct intel_plane_state *plane_state)
Damien Lespiau70d21f02013-07-03 21:06:04 +01003623{
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003624 struct drm_i915_private *dev_priv =
3625 to_i915(plane_state->base.plane->dev);
3626 const struct drm_framebuffer *fb = plane_state->base.fb;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003627 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä2e881262017-03-17 23:17:56 +02003628 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003629 u32 plane_ctl;
Damien Lespiau70d21f02013-07-03 21:06:04 +01003630
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003631 plane_ctl = PLANE_CTL_ENABLE;
3632
James Ausmus4036c782017-11-13 10:11:28 -08003633 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003634 plane_ctl |= skl_plane_ctl_alpha(plane_state);
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003635 plane_ctl |=
3636 PLANE_CTL_PIPE_GAMMA_ENABLE |
3637 PLANE_CTL_PIPE_CSC_ENABLE |
3638 PLANE_CTL_PLANE_GAMMA_DISABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003639
3640 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3641 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003642
3643 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3644 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003645 }
Damien Lespiau70d21f02013-07-03 21:06:04 +01003646
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003647 plane_ctl |= skl_plane_ctl_format(fb->format->format);
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003648 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003649 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3650
3651 if (INTEL_GEN(dev_priv) >= 10)
3652 plane_ctl |= cnl_plane_ctl_flip(rotation &
3653 DRM_MODE_REFLECT_MASK);
Damien Lespiau70d21f02013-07-03 21:06:04 +01003654
Ville Syrjälä2e881262017-03-17 23:17:56 +02003655 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3656 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3657 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3658 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3659
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003660 return plane_ctl;
3661}
3662
James Ausmus4036c782017-11-13 10:11:28 -08003663u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3664 const struct intel_plane_state *plane_state)
3665{
James Ausmus077ef1f2018-03-28 14:57:56 -07003666 struct drm_i915_private *dev_priv =
3667 to_i915(plane_state->base.plane->dev);
James Ausmus4036c782017-11-13 10:11:28 -08003668 const struct drm_framebuffer *fb = plane_state->base.fb;
3669 u32 plane_color_ctl = 0;
3670
James Ausmus077ef1f2018-03-28 14:57:56 -07003671 if (INTEL_GEN(dev_priv) < 11) {
3672 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3673 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3674 }
James Ausmus4036c782017-11-13 10:11:28 -08003675 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003676 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
James Ausmus4036c782017-11-13 10:11:28 -08003677
Ayan Kumar Halder9bace652018-07-17 18:13:43 +01003678 if (fb->format->is_yuv) {
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003679 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3680 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3681 else
3682 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003683
3684 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3685 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003686 }
Ville Syrjälä012d79e2018-05-21 21:56:12 +03003687
James Ausmus4036c782017-11-13 10:11:28 -08003688 return plane_color_ctl;
3689}
3690
Maarten Lankhorst73974892016-08-05 23:28:27 +03003691static int
3692__intel_display_resume(struct drm_device *dev,
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003693 struct drm_atomic_state *state,
3694 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorst73974892016-08-05 23:28:27 +03003695{
3696 struct drm_crtc_state *crtc_state;
3697 struct drm_crtc *crtc;
3698 int i, ret;
3699
Ville Syrjäläaecd36b2017-06-01 17:36:13 +03003700 intel_modeset_setup_hw_state(dev, ctx);
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00003701 i915_redisable_vga(to_i915(dev));
Maarten Lankhorst73974892016-08-05 23:28:27 +03003702
3703 if (!state)
3704 return 0;
3705
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01003706 /*
3707 * We've duplicated the state, pointers to the old state are invalid.
3708 *
3709 * Don't attempt to use the old state until we commit the duplicated state.
3710 */
3711 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst73974892016-08-05 23:28:27 +03003712 /*
3713 * Force recalculation even if we restore
3714 * current state. With fast modeset this may not result
3715 * in a modeset when the state is compatible.
3716 */
3717 crtc_state->mode_changed = true;
3718 }
3719
3720 /* ignore any reset values/BIOS leftovers in the WM registers */
Ville Syrjälä602ae832017-03-02 19:15:02 +02003721 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3722 to_intel_atomic_state(state)->skip_intermediate_wm = true;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003723
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003724 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003725
3726 WARN_ON(ret == -EDEADLK);
3727 return ret;
3728}
3729
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003730static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3731{
Ville Syrjäläae981042016-08-05 23:28:30 +03003732 return intel_has_gpu_reset(dev_priv) &&
3733 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003734}
3735
Chris Wilsonc0336662016-05-06 15:40:21 +01003736void intel_prepare_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003737{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003738 struct drm_device *dev = &dev_priv->drm;
3739 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3740 struct drm_atomic_state *state;
3741 int ret;
3742
Daniel Vetterce87ea12017-07-19 14:54:55 +02003743 /* reset doesn't touch the display */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003744 if (!i915_modparams.force_reset_modeset_test &&
Daniel Vetterce87ea12017-07-19 14:54:55 +02003745 !gpu_reset_clobbers_display(dev_priv))
3746 return;
3747
Daniel Vetter9db529a2017-08-08 10:08:28 +02003748 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3749 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3750 wake_up_all(&dev_priv->gpu_error.wait_queue);
3751
3752 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3753 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3754 i915_gem_set_wedged(dev_priv);
3755 }
Daniel Vetter97154ec2017-08-08 10:08:26 +02003756
Maarten Lankhorst73974892016-08-05 23:28:27 +03003757 /*
3758 * Need mode_config.mutex so that we don't
3759 * trample ongoing ->detect() and whatnot.
3760 */
3761 mutex_lock(&dev->mode_config.mutex);
3762 drm_modeset_acquire_init(ctx, 0);
3763 while (1) {
3764 ret = drm_modeset_lock_all_ctx(dev, ctx);
3765 if (ret != -EDEADLK)
3766 break;
3767
3768 drm_modeset_backoff(ctx);
3769 }
Ville Syrjäläf98ce922014-11-21 21:54:30 +02003770 /*
3771 * Disabling the crtcs gracefully seems nicer. Also the
3772 * g33 docs say we should at least disable all the planes.
3773 */
Maarten Lankhorst73974892016-08-05 23:28:27 +03003774 state = drm_atomic_helper_duplicate_state(dev, ctx);
3775 if (IS_ERR(state)) {
3776 ret = PTR_ERR(state);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003777 DRM_ERROR("Duplicating state failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003778 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003779 }
3780
3781 ret = drm_atomic_helper_disable_all(dev, ctx);
3782 if (ret) {
3783 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003784 drm_atomic_state_put(state);
3785 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003786 }
3787
3788 dev_priv->modeset_restore_state = state;
3789 state->acquire_ctx = ctx;
Ville Syrjälä75147472014-11-24 18:28:11 +02003790}
3791
Chris Wilsonc0336662016-05-06 15:40:21 +01003792void intel_finish_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003793{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003794 struct drm_device *dev = &dev_priv->drm;
3795 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
Chris Wilson40da1d32018-04-05 13:37:14 +01003796 struct drm_atomic_state *state;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003797 int ret;
3798
Daniel Vetterce87ea12017-07-19 14:54:55 +02003799 /* reset doesn't touch the display */
Chris Wilson40da1d32018-04-05 13:37:14 +01003800 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
Daniel Vetterce87ea12017-07-19 14:54:55 +02003801 return;
3802
Chris Wilson40da1d32018-04-05 13:37:14 +01003803 state = fetch_and_zero(&dev_priv->modeset_restore_state);
Daniel Vetterce87ea12017-07-19 14:54:55 +02003804 if (!state)
3805 goto unlock;
3806
Ville Syrjälä75147472014-11-24 18:28:11 +02003807 /* reset doesn't touch the display */
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003808 if (!gpu_reset_clobbers_display(dev_priv)) {
Daniel Vetterce87ea12017-07-19 14:54:55 +02003809 /* for testing only restore the display */
3810 ret = __intel_display_resume(dev, state, ctx);
Chris Wilson942d5d02017-08-28 11:46:04 +01003811 if (ret)
3812 DRM_ERROR("Restoring old state failed with %i\n", ret);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003813 } else {
3814 /*
3815 * The display has been reset as well,
3816 * so need a full re-initialization.
3817 */
3818 intel_runtime_pm_disable_interrupts(dev_priv);
3819 intel_runtime_pm_enable_interrupts(dev_priv);
3820
Imre Deak51f59202016-09-14 13:04:13 +03003821 intel_pps_unlock_regs_wa(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003822 intel_modeset_init_hw(dev);
Ville Syrjäläf72b84c2017-11-08 15:35:55 +02003823 intel_init_clock_gating(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003824
3825 spin_lock_irq(&dev_priv->irq_lock);
3826 if (dev_priv->display.hpd_irq_setup)
3827 dev_priv->display.hpd_irq_setup(dev_priv);
3828 spin_unlock_irq(&dev_priv->irq_lock);
3829
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003830 ret = __intel_display_resume(dev, state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003831 if (ret)
3832 DRM_ERROR("Restoring old state failed with %i\n", ret);
3833
3834 intel_hpd_init(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003835 }
3836
Daniel Vetterce87ea12017-07-19 14:54:55 +02003837 drm_atomic_state_put(state);
3838unlock:
Maarten Lankhorst73974892016-08-05 23:28:27 +03003839 drm_modeset_drop_locks(ctx);
3840 drm_modeset_acquire_fini(ctx);
3841 mutex_unlock(&dev->mode_config.mutex);
Daniel Vetter9db529a2017-08-08 10:08:28 +02003842
3843 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
Ville Syrjälä75147472014-11-24 18:28:11 +02003844}
3845
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003846static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3847 const struct intel_crtc_state *new_crtc_state)
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003848{
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003849 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003850 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003851
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003852 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003853 crtc->base.mode = new_crtc_state->base.mode;
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003854
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003855 /*
3856 * Update pipe size and adjust fitter if needed: the reason for this is
3857 * that in compute_mode_changes we check the native mode (not the pfit
3858 * mode) to see if we can flip rather than do a full mode set. In the
3859 * fastboot case, we'll flip, but if we don't update the pipesrc and
3860 * pfit state, we'll end up with a big fb scanned out into the wrong
3861 * sized surface.
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003862 */
3863
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003864 I915_WRITE(PIPESRC(crtc->pipe),
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003865 ((new_crtc_state->pipe_src_w - 1) << 16) |
3866 (new_crtc_state->pipe_src_h - 1));
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003867
3868 /* on skylake this is done by detaching scalers */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003869 if (INTEL_GEN(dev_priv) >= 9) {
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003870 skl_detach_scalers(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003871
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003872 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003873 skylake_pfit_enable(new_crtc_state);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003874 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003875 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003876 ironlake_pfit_enable(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003877 else if (old_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003878 ironlake_pfit_disable(old_crtc_state);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003879 }
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003880}
3881
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003882static void intel_fdi_normal_train(struct intel_crtc *crtc)
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003883{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003884 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003885 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003886 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003887 i915_reg_t reg;
3888 u32 temp;
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003889
3890 /* enable normal train */
3891 reg = FDI_TX_CTL(pipe);
3892 temp = I915_READ(reg);
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003893 if (IS_IVYBRIDGE(dev_priv)) {
Jesse Barnes357555c2011-04-28 15:09:55 -07003894 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3895 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
Keith Packard61e499b2011-05-17 16:13:52 -07003896 } else {
3897 temp &= ~FDI_LINK_TRAIN_NONE;
3898 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
Jesse Barnes357555c2011-04-28 15:09:55 -07003899 }
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003900 I915_WRITE(reg, temp);
3901
3902 reg = FDI_RX_CTL(pipe);
3903 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003904 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003905 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3906 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3907 } else {
3908 temp &= ~FDI_LINK_TRAIN_NONE;
3909 temp |= FDI_LINK_TRAIN_NONE;
3910 }
3911 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3912
3913 /* wait one idle pattern time */
3914 POSTING_READ(reg);
3915 udelay(1000);
Jesse Barnes357555c2011-04-28 15:09:55 -07003916
3917 /* IVB wants error correction enabled */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003918 if (IS_IVYBRIDGE(dev_priv))
Jesse Barnes357555c2011-04-28 15:09:55 -07003919 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3920 FDI_FE_ERRC_ENABLE);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003921}
3922
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003923/* The FDI link training functions for ILK/Ibexpeak. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02003924static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3925 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003926{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003927 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003928 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003929 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003930 i915_reg_t reg;
3931 u32 temp, tries;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003932
Ville Syrjälä1c8562f2014-04-25 22:12:07 +03003933 /* FDI needs bits from pipe first */
Jesse Barnes0fc932b2011-01-04 15:09:37 -08003934 assert_pipe_enabled(dev_priv, pipe);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08003935
Adam Jacksone1a44742010-06-25 15:32:14 -04003936 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3937 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01003938 reg = FDI_RX_IMR(pipe);
3939 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04003940 temp &= ~FDI_RX_SYMBOL_LOCK;
3941 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01003942 I915_WRITE(reg, temp);
3943 I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04003944 udelay(150);
3945
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003946 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01003947 reg = FDI_TX_CTL(pipe);
3948 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02003949 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02003950 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003951 temp &= ~FDI_LINK_TRAIN_NONE;
3952 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01003953 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003954
Chris Wilson5eddb702010-09-11 13:48:45 +01003955 reg = FDI_RX_CTL(pipe);
3956 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003957 temp &= ~FDI_LINK_TRAIN_NONE;
3958 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01003959 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3960
3961 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003962 udelay(150);
3963
Jesse Barnes5b2adf82010-10-07 16:01:15 -07003964 /* Ironlake workaround, enable clock pointer after FDI enable*/
Daniel Vetter8f5718a2012-10-31 22:52:28 +01003965 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3966 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3967 FDI_RX_PHASE_SYNC_POINTER_EN);
Jesse Barnes5b2adf82010-10-07 16:01:15 -07003968
Chris Wilson5eddb702010-09-11 13:48:45 +01003969 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04003970 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01003971 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003972 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3973
3974 if ((temp & FDI_RX_BIT_LOCK)) {
3975 DRM_DEBUG_KMS("FDI train 1 done.\n");
Chris Wilson5eddb702010-09-11 13:48:45 +01003976 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003977 break;
3978 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003979 }
Adam Jacksone1a44742010-06-25 15:32:14 -04003980 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01003981 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003982
3983 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01003984 reg = FDI_TX_CTL(pipe);
3985 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003986 temp &= ~FDI_LINK_TRAIN_NONE;
3987 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01003988 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003989
Chris Wilson5eddb702010-09-11 13:48:45 +01003990 reg = FDI_RX_CTL(pipe);
3991 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003992 temp &= ~FDI_LINK_TRAIN_NONE;
3993 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01003994 I915_WRITE(reg, temp);
3995
3996 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003997 udelay(150);
3998
Chris Wilson5eddb702010-09-11 13:48:45 +01003999 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04004000 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004001 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004002 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4003
4004 if (temp & FDI_RX_SYMBOL_LOCK) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004005 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004006 DRM_DEBUG_KMS("FDI train 2 done.\n");
4007 break;
4008 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004009 }
Adam Jacksone1a44742010-06-25 15:32:14 -04004010 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01004011 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004012
4013 DRM_DEBUG_KMS("FDI train done\n");
Jesse Barnes5c5313c2010-10-07 16:01:11 -07004014
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004015}
4016
Akshay Joshi0206e352011-08-16 15:34:10 -04004017static const int snb_b_fdi_train_param[] = {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004018 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4019 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4020 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4021 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4022};
4023
4024/* The FDI link training functions for SNB/Cougarpoint. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004025static void gen6_fdi_link_train(struct intel_crtc *crtc,
4026 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004027{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004028 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004029 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004030 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004031 i915_reg_t reg;
4032 u32 temp, i, retry;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004033
Adam Jacksone1a44742010-06-25 15:32:14 -04004034 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4035 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01004036 reg = FDI_RX_IMR(pipe);
4037 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004038 temp &= ~FDI_RX_SYMBOL_LOCK;
4039 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01004040 I915_WRITE(reg, temp);
4041
4042 POSTING_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004043 udelay(150);
4044
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004045 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01004046 reg = FDI_TX_CTL(pipe);
4047 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004048 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004049 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004050 temp &= ~FDI_LINK_TRAIN_NONE;
4051 temp |= FDI_LINK_TRAIN_PATTERN_1;
4052 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4053 /* SNB-B */
4054 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
Chris Wilson5eddb702010-09-11 13:48:45 +01004055 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004056
Daniel Vetterd74cf322012-10-26 10:58:13 +02004057 I915_WRITE(FDI_RX_MISC(pipe),
4058 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4059
Chris Wilson5eddb702010-09-11 13:48:45 +01004060 reg = FDI_RX_CTL(pipe);
4061 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004062 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004063 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4064 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4065 } else {
4066 temp &= ~FDI_LINK_TRAIN_NONE;
4067 temp |= FDI_LINK_TRAIN_PATTERN_1;
4068 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004069 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4070
4071 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004072 udelay(150);
4073
Akshay Joshi0206e352011-08-16 15:34:10 -04004074 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004075 reg = FDI_TX_CTL(pipe);
4076 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004077 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4078 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004079 I915_WRITE(reg, temp);
4080
4081 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004082 udelay(500);
4083
Sean Paulfa37d392012-03-02 12:53:39 -05004084 for (retry = 0; retry < 5; retry++) {
4085 reg = FDI_RX_IIR(pipe);
4086 temp = I915_READ(reg);
4087 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4088 if (temp & FDI_RX_BIT_LOCK) {
4089 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4090 DRM_DEBUG_KMS("FDI train 1 done.\n");
4091 break;
4092 }
4093 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004094 }
Sean Paulfa37d392012-03-02 12:53:39 -05004095 if (retry < 5)
4096 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004097 }
4098 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004099 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004100
4101 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004102 reg = FDI_TX_CTL(pipe);
4103 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004104 temp &= ~FDI_LINK_TRAIN_NONE;
4105 temp |= FDI_LINK_TRAIN_PATTERN_2;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004106 if (IS_GEN6(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004107 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4108 /* SNB-B */
4109 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4110 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004111 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004112
Chris Wilson5eddb702010-09-11 13:48:45 +01004113 reg = FDI_RX_CTL(pipe);
4114 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004115 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004116 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4117 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4118 } else {
4119 temp &= ~FDI_LINK_TRAIN_NONE;
4120 temp |= FDI_LINK_TRAIN_PATTERN_2;
4121 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004122 I915_WRITE(reg, temp);
4123
4124 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004125 udelay(150);
4126
Akshay Joshi0206e352011-08-16 15:34:10 -04004127 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004128 reg = FDI_TX_CTL(pipe);
4129 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004130 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4131 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004132 I915_WRITE(reg, temp);
4133
4134 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004135 udelay(500);
4136
Sean Paulfa37d392012-03-02 12:53:39 -05004137 for (retry = 0; retry < 5; retry++) {
4138 reg = FDI_RX_IIR(pipe);
4139 temp = I915_READ(reg);
4140 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4141 if (temp & FDI_RX_SYMBOL_LOCK) {
4142 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4143 DRM_DEBUG_KMS("FDI train 2 done.\n");
4144 break;
4145 }
4146 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004147 }
Sean Paulfa37d392012-03-02 12:53:39 -05004148 if (retry < 5)
4149 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004150 }
4151 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004152 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004153
4154 DRM_DEBUG_KMS("FDI train done.\n");
4155}
4156
Jesse Barnes357555c2011-04-28 15:09:55 -07004157/* Manual link training for Ivy Bridge A0 parts */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004158static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4159 const struct intel_crtc_state *crtc_state)
Jesse Barnes357555c2011-04-28 15:09:55 -07004160{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004161 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004162 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004163 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004164 i915_reg_t reg;
4165 u32 temp, i, j;
Jesse Barnes357555c2011-04-28 15:09:55 -07004166
4167 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4168 for train result */
4169 reg = FDI_RX_IMR(pipe);
4170 temp = I915_READ(reg);
4171 temp &= ~FDI_RX_SYMBOL_LOCK;
4172 temp &= ~FDI_RX_BIT_LOCK;
4173 I915_WRITE(reg, temp);
4174
4175 POSTING_READ(reg);
4176 udelay(150);
4177
Daniel Vetter01a415f2012-10-27 15:58:40 +02004178 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4179 I915_READ(FDI_RX_IIR(pipe)));
4180
Jesse Barnes139ccd32013-08-19 11:04:55 -07004181 /* Try each vswing and preemphasis setting twice before moving on */
4182 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4183 /* disable first in case we need to retry */
Jesse Barnes357555c2011-04-28 15:09:55 -07004184 reg = FDI_TX_CTL(pipe);
4185 temp = I915_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004186 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4187 temp &= ~FDI_TX_ENABLE;
4188 I915_WRITE(reg, temp);
4189
4190 reg = FDI_RX_CTL(pipe);
4191 temp = I915_READ(reg);
4192 temp &= ~FDI_LINK_TRAIN_AUTO;
4193 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4194 temp &= ~FDI_RX_ENABLE;
4195 I915_WRITE(reg, temp);
4196
4197 /* enable CPU FDI TX and PCH FDI RX */
4198 reg = FDI_TX_CTL(pipe);
4199 temp = I915_READ(reg);
4200 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004201 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004202 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
Jesse Barnes357555c2011-04-28 15:09:55 -07004203 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
Jesse Barnes139ccd32013-08-19 11:04:55 -07004204 temp |= snb_b_fdi_train_param[j/2];
4205 temp |= FDI_COMPOSITE_SYNC;
4206 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4207
4208 I915_WRITE(FDI_RX_MISC(pipe),
4209 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4210
4211 reg = FDI_RX_CTL(pipe);
4212 temp = I915_READ(reg);
4213 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4214 temp |= FDI_COMPOSITE_SYNC;
4215 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4216
4217 POSTING_READ(reg);
4218 udelay(1); /* should be 0.5us */
4219
4220 for (i = 0; i < 4; i++) {
4221 reg = FDI_RX_IIR(pipe);
4222 temp = I915_READ(reg);
4223 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4224
4225 if (temp & FDI_RX_BIT_LOCK ||
4226 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4227 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4228 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4229 i);
4230 break;
4231 }
4232 udelay(1); /* should be 0.5us */
4233 }
4234 if (i == 4) {
4235 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4236 continue;
4237 }
4238
4239 /* Train 2 */
4240 reg = FDI_TX_CTL(pipe);
4241 temp = I915_READ(reg);
4242 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4243 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4244 I915_WRITE(reg, temp);
4245
4246 reg = FDI_RX_CTL(pipe);
4247 temp = I915_READ(reg);
4248 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4249 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
Jesse Barnes357555c2011-04-28 15:09:55 -07004250 I915_WRITE(reg, temp);
4251
4252 POSTING_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004253 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004254
Jesse Barnes139ccd32013-08-19 11:04:55 -07004255 for (i = 0; i < 4; i++) {
4256 reg = FDI_RX_IIR(pipe);
4257 temp = I915_READ(reg);
4258 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
Jesse Barnes357555c2011-04-28 15:09:55 -07004259
Jesse Barnes139ccd32013-08-19 11:04:55 -07004260 if (temp & FDI_RX_SYMBOL_LOCK ||
4261 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4262 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4263 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4264 i);
4265 goto train_done;
4266 }
4267 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004268 }
Jesse Barnes139ccd32013-08-19 11:04:55 -07004269 if (i == 4)
4270 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
Jesse Barnes357555c2011-04-28 15:09:55 -07004271 }
Jesse Barnes357555c2011-04-28 15:09:55 -07004272
Jesse Barnes139ccd32013-08-19 11:04:55 -07004273train_done:
Jesse Barnes357555c2011-04-28 15:09:55 -07004274 DRM_DEBUG_KMS("FDI train done.\n");
4275}
4276
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004277static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes0e23b992010-09-10 11:10:00 -07004278{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004279 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4280 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004281 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004282 i915_reg_t reg;
4283 u32 temp;
Jesse Barnesc64e3112010-09-10 11:27:03 -07004284
Jesse Barnes0e23b992010-09-10 11:10:00 -07004285 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
Chris Wilson5eddb702010-09-11 13:48:45 +01004286 reg = FDI_RX_CTL(pipe);
4287 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004288 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004289 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004290 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Chris Wilson5eddb702010-09-11 13:48:45 +01004291 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4292
4293 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004294 udelay(200);
4295
4296 /* Switch from Rawclk to PCDclk */
Chris Wilson5eddb702010-09-11 13:48:45 +01004297 temp = I915_READ(reg);
4298 I915_WRITE(reg, temp | FDI_PCDCLK);
4299
4300 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004301 udelay(200);
4302
Paulo Zanoni20749732012-11-23 15:30:38 -02004303 /* Enable CPU FDI TX PLL, always on for Ironlake */
4304 reg = FDI_TX_CTL(pipe);
4305 temp = I915_READ(reg);
4306 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4307 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
Chris Wilson5eddb702010-09-11 13:48:45 +01004308
Paulo Zanoni20749732012-11-23 15:30:38 -02004309 POSTING_READ(reg);
4310 udelay(100);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004311 }
4312}
4313
Daniel Vetter88cefb62012-08-12 19:27:14 +02004314static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4315{
4316 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004317 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter88cefb62012-08-12 19:27:14 +02004318 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004319 i915_reg_t reg;
4320 u32 temp;
Daniel Vetter88cefb62012-08-12 19:27:14 +02004321
4322 /* Switch from PCDclk to Rawclk */
4323 reg = FDI_RX_CTL(pipe);
4324 temp = I915_READ(reg);
4325 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4326
4327 /* Disable CPU FDI TX PLL */
4328 reg = FDI_TX_CTL(pipe);
4329 temp = I915_READ(reg);
4330 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4331
4332 POSTING_READ(reg);
4333 udelay(100);
4334
4335 reg = FDI_RX_CTL(pipe);
4336 temp = I915_READ(reg);
4337 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4338
4339 /* Wait for the clocks to turn off. */
4340 POSTING_READ(reg);
4341 udelay(100);
4342}
4343
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004344static void ironlake_fdi_disable(struct drm_crtc *crtc)
4345{
4346 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004347 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004348 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4349 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004350 i915_reg_t reg;
4351 u32 temp;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004352
4353 /* disable CPU FDI tx and PCH FDI rx */
4354 reg = FDI_TX_CTL(pipe);
4355 temp = I915_READ(reg);
4356 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4357 POSTING_READ(reg);
4358
4359 reg = FDI_RX_CTL(pipe);
4360 temp = I915_READ(reg);
4361 temp &= ~(0x7 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004362 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004363 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4364
4365 POSTING_READ(reg);
4366 udelay(100);
4367
4368 /* Ironlake workaround, disable clock pointer after downing FDI */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004369 if (HAS_PCH_IBX(dev_priv))
Jesse Barnes6f06ce12011-01-04 15:09:38 -08004370 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004371
4372 /* still set train pattern 1 */
4373 reg = FDI_TX_CTL(pipe);
4374 temp = I915_READ(reg);
4375 temp &= ~FDI_LINK_TRAIN_NONE;
4376 temp |= FDI_LINK_TRAIN_PATTERN_1;
4377 I915_WRITE(reg, temp);
4378
4379 reg = FDI_RX_CTL(pipe);
4380 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004381 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004382 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4383 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4384 } else {
4385 temp &= ~FDI_LINK_TRAIN_NONE;
4386 temp |= FDI_LINK_TRAIN_PATTERN_1;
4387 }
4388 /* BPC in FDI rx is consistent with that in PIPECONF */
4389 temp &= ~(0x07 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004390 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004391 I915_WRITE(reg, temp);
4392
4393 POSTING_READ(reg);
4394 udelay(100);
4395}
4396
Chris Wilson49d73912016-11-29 09:50:08 +00004397bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004398{
Daniel Vetterfa058872017-07-20 19:57:52 +02004399 struct drm_crtc *crtc;
4400 bool cleanup_done;
Chris Wilson5dce5b932014-01-20 10:17:36 +00004401
Daniel Vetterfa058872017-07-20 19:57:52 +02004402 drm_for_each_crtc(crtc, &dev_priv->drm) {
4403 struct drm_crtc_commit *commit;
4404 spin_lock(&crtc->commit_lock);
4405 commit = list_first_entry_or_null(&crtc->commit_list,
4406 struct drm_crtc_commit, commit_entry);
4407 cleanup_done = commit ?
4408 try_wait_for_completion(&commit->cleanup_done) : true;
4409 spin_unlock(&crtc->commit_lock);
4410
4411 if (cleanup_done)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004412 continue;
4413
Daniel Vetterfa058872017-07-20 19:57:52 +02004414 drm_crtc_wait_one_vblank(crtc);
Chris Wilson5dce5b932014-01-20 10:17:36 +00004415
4416 return true;
4417 }
4418
4419 return false;
4420}
4421
Maarten Lankhorstb7076542016-08-23 16:18:08 +02004422void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004423{
4424 u32 temp;
4425
4426 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4427
4428 mutex_lock(&dev_priv->sb_lock);
4429
4430 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4431 temp |= SBI_SSCCTL_DISABLE;
4432 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4433
4434 mutex_unlock(&dev_priv->sb_lock);
4435}
4436
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004437/* Program iCLKIP clock to the desired frequency */
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004438static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004439{
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004440 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004441 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004442 int clock = crtc_state->base.adjusted_mode.crtc_clock;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004443 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4444 u32 temp;
4445
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004446 lpt_disable_iclkip(dev_priv);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004447
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004448 /* The iCLK virtual clock root frequency is in MHz,
4449 * but the adjusted_mode->crtc_clock in in KHz. To get the
4450 * divisors, it is necessary to divide one by another, so we
4451 * convert the virtual clock precision to KHz here for higher
4452 * precision.
4453 */
4454 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004455 u32 iclk_virtual_root_freq = 172800 * 1000;
4456 u32 iclk_pi_range = 64;
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004457 u32 desired_divisor;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004458
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004459 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4460 clock << auxdiv);
4461 divsel = (desired_divisor / iclk_pi_range) - 2;
4462 phaseinc = desired_divisor % iclk_pi_range;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004463
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004464 /*
4465 * Near 20MHz is a corner case which is
4466 * out of range for the 7-bit divisor
4467 */
4468 if (divsel <= 0x7f)
4469 break;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004470 }
4471
4472 /* This should not happen with any sane values */
4473 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4474 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4475 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4476 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4477
4478 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 +03004479 clock,
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004480 auxdiv,
4481 divsel,
4482 phasedir,
4483 phaseinc);
4484
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004485 mutex_lock(&dev_priv->sb_lock);
4486
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004487 /* Program SSCDIVINTPHASE6 */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004488 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004489 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4490 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4491 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4492 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4493 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4494 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004495 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004496
4497 /* Program SSCAUXDIV */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004498 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004499 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4500 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004501 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004502
4503 /* Enable modulator and associated divider */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004504 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004505 temp &= ~SBI_SSCCTL_DISABLE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004506 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004507
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004508 mutex_unlock(&dev_priv->sb_lock);
4509
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004510 /* Wait for initialization time */
4511 udelay(24);
4512
4513 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4514}
4515
Ville Syrjälä8802e5b2016-02-17 21:41:12 +02004516int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4517{
4518 u32 divsel, phaseinc, auxdiv;
4519 u32 iclk_virtual_root_freq = 172800 * 1000;
4520 u32 iclk_pi_range = 64;
4521 u32 desired_divisor;
4522 u32 temp;
4523
4524 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4525 return 0;
4526
4527 mutex_lock(&dev_priv->sb_lock);
4528
4529 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4530 if (temp & SBI_SSCCTL_DISABLE) {
4531 mutex_unlock(&dev_priv->sb_lock);
4532 return 0;
4533 }
4534
4535 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4536 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4537 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4538 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4539 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4540
4541 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4542 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4543 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4544
4545 mutex_unlock(&dev_priv->sb_lock);
4546
4547 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4548
4549 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4550 desired_divisor << auxdiv);
4551}
4552
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004553static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
Daniel Vetter275f01b22013-05-03 11:49:47 +02004554 enum pipe pch_transcoder)
4555{
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004556 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4557 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4558 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter275f01b22013-05-03 11:49:47 +02004559
4560 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4561 I915_READ(HTOTAL(cpu_transcoder)));
4562 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4563 I915_READ(HBLANK(cpu_transcoder)));
4564 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4565 I915_READ(HSYNC(cpu_transcoder)));
4566
4567 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4568 I915_READ(VTOTAL(cpu_transcoder)));
4569 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4570 I915_READ(VBLANK(cpu_transcoder)));
4571 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4572 I915_READ(VSYNC(cpu_transcoder)));
4573 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4574 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4575}
4576
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004577static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004578{
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004579 uint32_t temp;
4580
4581 temp = I915_READ(SOUTH_CHICKEN1);
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004582 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004583 return;
4584
4585 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4586 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4587
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004588 temp &= ~FDI_BC_BIFURCATION_SELECT;
4589 if (enable)
4590 temp |= FDI_BC_BIFURCATION_SELECT;
4591
4592 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004593 I915_WRITE(SOUTH_CHICKEN1, temp);
4594 POSTING_READ(SOUTH_CHICKEN1);
4595}
4596
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004597static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004598{
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004599 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4600 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004601
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004602 switch (crtc->pipe) {
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004603 case PIPE_A:
4604 break;
4605 case PIPE_B:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004606 if (crtc_state->fdi_lanes > 2)
4607 cpt_set_fdi_bc_bifurcation(dev_priv, false);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004608 else
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004609 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004610
4611 break;
4612 case PIPE_C:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004613 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004614
4615 break;
4616 default:
4617 BUG();
4618 }
4619}
4620
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004621/*
4622 * Finds the encoder associated with the given CRTC. This can only be
4623 * used when we know that the CRTC isn't feeding multiple encoders!
4624 */
4625static struct intel_encoder *
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004626intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4627 const struct intel_crtc_state *crtc_state)
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004628{
4629 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004630 const struct drm_connector_state *connector_state;
4631 const struct drm_connector *connector;
4632 struct intel_encoder *encoder = NULL;
4633 int num_encoders = 0;
4634 int i;
4635
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004636 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004637 if (connector_state->crtc != &crtc->base)
4638 continue;
4639
4640 encoder = to_intel_encoder(connector_state->best_encoder);
4641 num_encoders++;
4642 }
4643
4644 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4645 num_encoders, pipe_name(crtc->pipe));
4646
4647 return encoder;
4648}
4649
Jesse Barnesf67a5592011-01-05 10:31:48 -08004650/*
4651 * Enable PCH resources required for PCH ports:
4652 * - PCH PLLs
4653 * - FDI training & RX/TX
4654 * - update transcoder timings
4655 * - DP transcoding bits
4656 * - transcoder
4657 */
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004658static void ironlake_pch_enable(const struct intel_atomic_state *state,
4659 const struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08004660{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004661 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004662 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004663 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004664 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004665 u32 temp;
Jesse Barnes6be4a602010-09-10 10:26:01 -07004666
Daniel Vetterab9412b2013-05-03 11:49:46 +02004667 assert_pch_transcoder_disabled(dev_priv, pipe);
Chris Wilsone7e164d2012-05-11 09:21:25 +01004668
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004669 if (IS_IVYBRIDGE(dev_priv))
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004670 ivybridge_update_fdi_bc_bifurcation(crtc_state);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004671
Daniel Vettercd986ab2012-10-26 10:58:12 +02004672 /* Write the TU size bits before fdi link training, so that error
4673 * detection works. */
4674 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4675 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4676
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004677 /* For PCH output, training FDI link */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004678 dev_priv->display.fdi_link_train(crtc, crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07004679
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004680 /* We need to program the right clock selection before writing the pixel
4681 * mutliplier into the DPLL. */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004682 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004683 u32 sel;
Jesse Barnes4b645f12011-10-12 09:51:31 -07004684
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004685 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02004686 temp |= TRANS_DPLL_ENABLE(pipe);
4687 sel = TRANS_DPLLB_SEL(pipe);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004688 if (crtc_state->shared_dpll ==
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02004689 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004690 temp |= sel;
4691 else
4692 temp &= ~sel;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004693 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004694 }
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004695
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004696 /* XXX: pch pll's can be enabled any time before we enable the PCH
4697 * transcoder, and we actually should do this to not upset any PCH
4698 * transcoder that already use the clock when we share it.
4699 *
4700 * Note that enable_shared_dpll tries to do the right thing, but
4701 * get_shared_dpll unconditionally resets the pll - we need that to have
4702 * the right LVDS enable sequence. */
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02004703 intel_enable_shared_dpll(crtc_state);
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004704
Jesse Barnesd9b6cb52011-01-04 15:09:35 -08004705 /* set transcoder timing, panel must allow it */
4706 assert_panel_unlocked(dev_priv, pipe);
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004707 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004708
Paulo Zanoni303b81e2012-10-31 18:12:23 -02004709 intel_fdi_normal_train(crtc);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004710
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004711 /* For PCH DP, enable TRANS_DP_CTL */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004712 if (HAS_PCH_CPT(dev_priv) &&
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004713 intel_crtc_has_dp_encoder(crtc_state)) {
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004714 const struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004715 &crtc_state->base.adjusted_mode;
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004716 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004717 i915_reg_t reg = TRANS_DP_CTL(pipe);
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004718 enum port port;
4719
Chris Wilson5eddb702010-09-11 13:48:45 +01004720 temp = I915_READ(reg);
4721 temp &= ~(TRANS_DP_PORT_SEL_MASK |
Eric Anholt220cad32010-11-18 09:32:58 +08004722 TRANS_DP_SYNC_MASK |
4723 TRANS_DP_BPC_MASK);
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03004724 temp |= TRANS_DP_OUTPUT_ENABLE;
Jesse Barnes9325c9f2011-06-24 12:19:21 -07004725 temp |= bpc << 9; /* same format but at 11:9 */
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004726
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004727 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004728 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004729 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004730 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004731
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004732 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004733 WARN_ON(port < PORT_B || port > PORT_D);
4734 temp |= TRANS_DP_PORT_SEL(port);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004735
Chris Wilson5eddb702010-09-11 13:48:45 +01004736 I915_WRITE(reg, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004737 }
4738
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02004739 ironlake_enable_pch_transcoder(crtc_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004740}
4741
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004742static void lpt_pch_enable(const struct intel_atomic_state *state,
4743 const struct intel_crtc_state *crtc_state)
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004744{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004745 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004746 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004747 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004748
Matthias Kaehlckea2196032017-07-17 11:14:03 -07004749 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004750
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004751 lpt_program_iclkip(crtc_state);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004752
Paulo Zanoni0540e482012-10-31 18:12:40 -02004753 /* Set transcoder timing. */
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004754 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004755
Paulo Zanoni937bb612012-10-31 18:12:47 -02004756 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004757}
4758
Daniel Vettera1520312013-05-03 11:49:50 +02004759static void cpt_verify_modeset(struct drm_device *dev, int pipe)
Jesse Barnesd4270e52011-10-11 10:43:02 -07004760{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004761 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004762 i915_reg_t dslreg = PIPEDSL(pipe);
Jesse Barnesd4270e52011-10-11 10:43:02 -07004763 u32 temp;
4764
4765 temp = I915_READ(dslreg);
4766 udelay(500);
4767 if (wait_for(I915_READ(dslreg) != temp, 5)) {
Jesse Barnesd4270e52011-10-11 10:43:02 -07004768 if (wait_for(I915_READ(dslreg) != temp, 5))
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03004769 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
Jesse Barnesd4270e52011-10-11 10:43:02 -07004770 }
4771}
4772
Ville Syrjälä0a599522018-05-21 21:56:13 +03004773/*
4774 * The hardware phase 0.0 refers to the center of the pixel.
4775 * We want to start from the top/left edge which is phase
4776 * -0.5. That matches how the hardware calculates the scaling
4777 * factors (from top-left of the first pixel to bottom-right
4778 * of the last pixel, as opposed to the pixel centers).
4779 *
4780 * For 4:2:0 subsampled chroma planes we obviously have to
4781 * adjust that so that the chroma sample position lands in
4782 * the right spot.
4783 *
4784 * Note that for packed YCbCr 4:2:2 formats there is no way to
4785 * control chroma siting. The hardware simply replicates the
4786 * chroma samples for both of the luma samples, and thus we don't
4787 * actually get the expected MPEG2 chroma siting convention :(
4788 * The same behaviour is observed on pre-SKL platforms as well.
4789 */
4790u16 skl_scaler_calc_phase(int sub, bool chroma_cosited)
4791{
4792 int phase = -0x8000;
4793 u16 trip = 0;
4794
4795 if (chroma_cosited)
4796 phase += (sub - 1) * 0x8000 / sub;
4797
4798 if (phase < 0)
4799 phase = 0x10000 + phase;
4800 else
4801 trip = PS_PHASE_TRIP;
4802
4803 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4804}
4805
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004806static int
4807skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004808 unsigned int scaler_user, int *scaler_id,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304809 int src_w, int src_h, int dst_w, int dst_h,
4810 bool plane_scaler_check,
4811 uint32_t pixel_format)
Chandra Kondurua1b22782015-04-07 15:28:45 -07004812{
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004813 struct intel_crtc_scaler_state *scaler_state =
4814 &crtc_state->scaler_state;
4815 struct intel_crtc *intel_crtc =
4816 to_intel_crtc(crtc_state->base.crtc);
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304817 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4818 const struct drm_display_mode *adjusted_mode =
4819 &crtc_state->base.adjusted_mode;
Chandra Kondurua1b22782015-04-07 15:28:45 -07004820 int need_scaling;
Chandra Konduru6156a452015-04-27 13:48:39 -07004821
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004822 /*
4823 * Src coordinates are already rotated by 270 degrees for
4824 * the 90/270 degree plane rotation cases (to match the
4825 * GTT mapping), hence no need to account for rotation here.
4826 */
4827 need_scaling = src_w != dst_w || src_h != dst_h;
Chandra Kondurua1b22782015-04-07 15:28:45 -07004828
Chandra Konduru77224cd2018-04-09 09:11:13 +05304829 if (plane_scaler_check)
4830 if (pixel_format == DRM_FORMAT_NV12)
4831 need_scaling = true;
4832
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05304833 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
4834 scaler_user == SKL_CRTC_INDEX)
Shashank Sharmae5c05932017-07-21 20:55:05 +05304835 need_scaling = true;
4836
Chandra Kondurua1b22782015-04-07 15:28:45 -07004837 /*
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304838 * Scaling/fitting not supported in IF-ID mode in GEN9+
4839 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4840 * Once NV12 is enabled, handle it here while allocating scaler
4841 * for NV12.
4842 */
4843 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4844 need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4845 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4846 return -EINVAL;
4847 }
4848
4849 /*
Chandra Kondurua1b22782015-04-07 15:28:45 -07004850 * if plane is being disabled or scaler is no more required or force detach
4851 * - free scaler binded to this plane/crtc
4852 * - in order to do this, update crtc->scaler_usage
4853 *
4854 * Here scaler state in crtc_state is set free so that
4855 * scaler can be assigned to other user. Actual register
4856 * update to free the scaler is done in plane/panel-fit programming.
4857 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4858 */
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004859 if (force_detach || !need_scaling) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07004860 if (*scaler_id >= 0) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004861 scaler_state->scaler_users &= ~(1 << scaler_user);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004862 scaler_state->scalers[*scaler_id].in_use = 0;
4863
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004864 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4865 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4866 intel_crtc->pipe, scaler_user, *scaler_id,
Chandra Kondurua1b22782015-04-07 15:28:45 -07004867 scaler_state->scaler_users);
4868 *scaler_id = -1;
4869 }
4870 return 0;
4871 }
4872
Chandra Konduru77224cd2018-04-09 09:11:13 +05304873 if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 &&
Maarten Lankhorst5d794282018-05-12 03:03:14 +05304874 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
Chandra Konduru77224cd2018-04-09 09:11:13 +05304875 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4876 return -EINVAL;
4877 }
4878
Chandra Kondurua1b22782015-04-07 15:28:45 -07004879 /* range checks */
4880 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
Nabendu Maiti323301a2018-03-23 10:24:18 -07004881 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4882 (IS_GEN11(dev_priv) &&
4883 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4884 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4885 (!IS_GEN11(dev_priv) &&
4886 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4887 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004888 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
Chandra Kondurua1b22782015-04-07 15:28:45 -07004889 "size is out of scaler range\n",
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004890 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004891 return -EINVAL;
4892 }
4893
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004894 /* mark this plane as a scaler user in crtc_state */
4895 scaler_state->scaler_users |= (1 << scaler_user);
4896 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4897 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4898 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4899 scaler_state->scaler_users);
4900
4901 return 0;
4902}
4903
4904/**
4905 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4906 *
4907 * @state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004908 *
4909 * Return
4910 * 0 - scaler_usage updated successfully
4911 * error - requested scaling cannot be supported or other error condition
4912 */
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004913int skl_update_scaler_crtc(struct intel_crtc_state *state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004914{
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03004915 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004916
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004917 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304918 &state->scaler_state.scaler_id,
4919 state->pipe_src_w, state->pipe_src_h,
4920 adjusted_mode->crtc_hdisplay,
4921 adjusted_mode->crtc_vdisplay, false, 0);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004922}
4923
4924/**
4925 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
Chris Wilsonc38c1452018-02-14 13:49:22 +00004926 * @crtc_state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004927 * @plane_state: atomic plane state to update
4928 *
4929 * Return
4930 * 0 - scaler_usage updated successfully
4931 * error - requested scaling cannot be supported or other error condition
4932 */
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02004933static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4934 struct intel_plane_state *plane_state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004935{
4936
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02004937 struct intel_plane *intel_plane =
4938 to_intel_plane(plane_state->base.plane);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004939 struct drm_framebuffer *fb = plane_state->base.fb;
4940 int ret;
4941
Ville Syrjälä936e71e2016-07-26 19:06:59 +03004942 bool force_detach = !fb || !plane_state->base.visible;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004943
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004944 ret = skl_update_scaler(crtc_state, force_detach,
4945 drm_plane_index(&intel_plane->base),
4946 &plane_state->scaler_id,
Ville Syrjälä936e71e2016-07-26 19:06:59 +03004947 drm_rect_width(&plane_state->base.src) >> 16,
4948 drm_rect_height(&plane_state->base.src) >> 16,
4949 drm_rect_width(&plane_state->base.dst),
Chandra Konduru77224cd2018-04-09 09:11:13 +05304950 drm_rect_height(&plane_state->base.dst),
4951 fb ? true : false, fb ? fb->format->format : 0);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004952
4953 if (ret || plane_state->scaler_id < 0)
4954 return ret;
4955
Chandra Kondurua1b22782015-04-07 15:28:45 -07004956 /* check colorkey */
Ville Syrjälä6ec5bd32018-02-02 22:42:31 +02004957 if (plane_state->ckey.flags) {
Ville Syrjälä72660ce2016-05-27 20:59:20 +03004958 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4959 intel_plane->base.base.id,
4960 intel_plane->base.name);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004961 return -EINVAL;
4962 }
4963
4964 /* Check src format */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02004965 switch (fb->format->format) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004966 case DRM_FORMAT_RGB565:
4967 case DRM_FORMAT_XBGR8888:
4968 case DRM_FORMAT_XRGB8888:
4969 case DRM_FORMAT_ABGR8888:
4970 case DRM_FORMAT_ARGB8888:
4971 case DRM_FORMAT_XRGB2101010:
4972 case DRM_FORMAT_XBGR2101010:
4973 case DRM_FORMAT_YUYV:
4974 case DRM_FORMAT_YVYU:
4975 case DRM_FORMAT_UYVY:
4976 case DRM_FORMAT_VYUY:
Chandra Konduru77224cd2018-04-09 09:11:13 +05304977 case DRM_FORMAT_NV12:
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004978 break;
4979 default:
Ville Syrjälä72660ce2016-05-27 20:59:20 +03004980 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4981 intel_plane->base.base.id, intel_plane->base.name,
Ville Syrjälä438b74a2016-12-14 23:32:55 +02004982 fb->base.id, fb->format->format);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004983 return -EINVAL;
Chandra Kondurua1b22782015-04-07 15:28:45 -07004984 }
4985
Chandra Kondurua1b22782015-04-07 15:28:45 -07004986 return 0;
4987}
4988
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004989static void skylake_scaler_disable(struct intel_crtc *crtc)
4990{
4991 int i;
4992
4993 for (i = 0; i < crtc->num_scalers; i++)
4994 skl_detach_scaler(crtc, i);
4995}
4996
Maarten Lankhorstb2562712018-10-04 11:45:53 +02004997static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00004998{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02004999 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5000 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5001 enum pipe pipe = crtc->pipe;
5002 const struct intel_crtc_scaler_state *scaler_state =
5003 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005004
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005005 if (crtc_state->pch_pfit.enabled) {
Ville Syrjälä0a599522018-05-21 21:56:13 +03005006 u16 uv_rgb_hphase, uv_rgb_vphase;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005007 int id;
5008
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005009 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
Chandra Kondurua1b22782015-04-07 15:28:45 -07005010 return;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005011
Ville Syrjälä0a599522018-05-21 21:56:13 +03005012 uv_rgb_hphase = skl_scaler_calc_phase(1, false);
5013 uv_rgb_vphase = skl_scaler_calc_phase(1, false);
5014
Chandra Kondurua1b22782015-04-07 15:28:45 -07005015 id = scaler_state->scaler_id;
5016 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5017 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005018 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5019 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5020 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5021 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005022 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5023 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005024 }
5025}
5026
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005027static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesb074cec2013-04-25 12:55:02 -07005028{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005029 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5030 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesb074cec2013-04-25 12:55:02 -07005031 int pipe = crtc->pipe;
5032
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005033 if (crtc_state->pch_pfit.enabled) {
Jesse Barnesb074cec2013-04-25 12:55:02 -07005034 /* Force use of hard-coded filter coefficients
5035 * as some pre-programmed values are broken,
5036 * e.g. x201.
5037 */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01005038 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
Jesse Barnesb074cec2013-04-25 12:55:02 -07005039 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5040 PF_PIPE_SEL_IVB(pipe));
5041 else
5042 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005043 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5044 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
Jesse Barnes040484a2011-01-03 12:14:26 -08005045 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005046}
5047
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005048void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005049{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005050 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläcea165c2014-04-15 21:41:35 +03005051 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005052 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005053
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005054 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005055 return;
5056
Maarten Lankhorst307e4492016-03-23 14:33:28 +01005057 /*
5058 * We can only enable IPS after we enable a plane and wait for a vblank
5059 * This function is called from post_plane_update, which is run after
5060 * a vblank wait.
5061 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005062 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02005063
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005064 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005065 mutex_lock(&dev_priv->pcu_lock);
Ville Syrjälä61843f02017-09-12 18:34:11 +03005066 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5067 IPS_ENABLE | IPS_PCODE_CONTROL));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005068 mutex_unlock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005069 /* Quoting Art Runyan: "its not safe to expect any particular
5070 * value in IPS_CTL bit 31 after enabling IPS through the
Jesse Barnese59150d2014-01-07 13:30:45 -08005071 * mailbox." Moreover, the mailbox may return a bogus state,
5072 * so we need to just enable it and continue on.
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005073 */
5074 } else {
5075 I915_WRITE(IPS_CTL, IPS_ENABLE);
5076 /* The bit only becomes 1 in the next vblank, so this wait here
5077 * is essentially intel_wait_for_vblank. If we don't have this
5078 * and don't wait for vblanks until the end of crtc_enable, then
5079 * the HW state readout code will complain that the expected
5080 * IPS_CTL value is not the one we read. */
Chris Wilson2ec9ba32016-06-30 15:33:01 +01005081 if (intel_wait_for_register(dev_priv,
5082 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5083 50))
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005084 DRM_ERROR("Timed out waiting for IPS enable\n");
5085 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005086}
5087
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005088void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005089{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005090 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005091 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005092 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005093
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005094 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005095 return;
5096
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005097 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005098 mutex_lock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005099 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005100 mutex_unlock(&dev_priv->pcu_lock);
Imre Deakacb3ef02018-09-05 13:00:05 +03005101 /*
5102 * Wait for PCODE to finish disabling IPS. The BSpec specified
5103 * 42ms timeout value leads to occasional timeouts so use 100ms
5104 * instead.
5105 */
Chris Wilsonb85c1ec2016-06-30 15:33:02 +01005106 if (intel_wait_for_register(dev_priv,
5107 IPS_CTL, IPS_ENABLE, 0,
Imre Deakacb3ef02018-09-05 13:00:05 +03005108 100))
Ben Widawsky23d0b132014-04-10 14:32:41 -07005109 DRM_ERROR("Timed out waiting for IPS disable\n");
Jesse Barnese59150d2014-01-07 13:30:45 -08005110 } else {
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005111 I915_WRITE(IPS_CTL, 0);
Jesse Barnese59150d2014-01-07 13:30:45 -08005112 POSTING_READ(IPS_CTL);
5113 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005114
5115 /* We need to wait for a vblank before we can disable the plane. */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005116 intel_wait_for_vblank(dev_priv, crtc->pipe);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005117}
5118
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005119static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005120{
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005121 if (intel_crtc->overlay) {
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005122 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005123
5124 mutex_lock(&dev->struct_mutex);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005125 (void) intel_overlay_switch_off(intel_crtc->overlay);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005126 mutex_unlock(&dev->struct_mutex);
5127 }
5128
5129 /* Let userspace switch the overlay on again. In most cases userspace
5130 * has to recompute where to put it anyway.
5131 */
5132}
5133
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005134/**
5135 * intel_post_enable_primary - Perform operations after enabling primary plane
5136 * @crtc: the CRTC whose primary plane was just enabled
Chris Wilsonc38c1452018-02-14 13:49:22 +00005137 * @new_crtc_state: the enabling state
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005138 *
5139 * Performs potentially sleeping operations that must be done after the primary
5140 * plane is enabled, such as updating FBC and IPS. Note that this may be
5141 * called due to an explicit primary plane update, or due to an implicit
5142 * re-enable that is caused when a sprite plane is updated to no longer
5143 * completely hide the primary plane.
5144 */
5145static void
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005146intel_post_enable_primary(struct drm_crtc *crtc,
5147 const struct intel_crtc_state *new_crtc_state)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005148{
5149 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005150 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005151 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5152 int pipe = intel_crtc->pipe;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005153
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005154 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005155 * Gen2 reports pipe underruns whenever all planes are disabled.
5156 * So don't enable underrun reporting before at least some planes
5157 * are enabled.
5158 * FIXME: Need to fix the logic to work when we turn off all planes
5159 * but leave the pipe running.
Daniel Vetterf99d7062014-06-19 16:01:59 +02005160 */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01005161 if (IS_GEN2(dev_priv))
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005162 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5163
Ville Syrjäläaca7b682015-10-30 19:22:21 +02005164 /* Underruns don't always raise interrupts, so check manually. */
5165 intel_check_cpu_fifo_underruns(dev_priv);
5166 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005167}
5168
Ville Syrjälä2622a082016-03-09 19:07:26 +02005169/* FIXME get rid of this and use pre_plane_update */
5170static void
5171intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5172{
5173 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005174 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä2622a082016-03-09 19:07:26 +02005175 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5176 int pipe = intel_crtc->pipe;
5177
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005178 /*
5179 * Gen2 reports pipe underruns whenever all planes are disabled.
5180 * So disable underrun reporting before all the planes get disabled.
5181 */
5182 if (IS_GEN2(dev_priv))
5183 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5184
5185 hsw_disable_ips(to_intel_crtc_state(crtc->state));
Ville Syrjälä2622a082016-03-09 19:07:26 +02005186
5187 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005188 * Vblank time updates from the shadow to live plane control register
5189 * are blocked if the memory self-refresh mode is active at that
5190 * moment. So to make sure the plane gets truly disabled, disable
5191 * first the self-refresh mode. The self-refresh enable bit in turn
5192 * will be checked/applied by the HW only at the next frame start
5193 * event which is after the vblank start event, so we need to have a
5194 * wait-for-vblank between disabling the plane and the pipe.
5195 */
Ville Syrjälä11a85d62016-11-28 19:37:12 +02005196 if (HAS_GMCH_DISPLAY(dev_priv) &&
5197 intel_set_memory_cxsr(dev_priv, false))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005198 intel_wait_for_vblank(dev_priv, pipe);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005199}
5200
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005201static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5202 const struct intel_crtc_state *new_crtc_state)
5203{
5204 if (!old_crtc_state->ips_enabled)
5205 return false;
5206
5207 if (needs_modeset(&new_crtc_state->base))
5208 return true;
5209
5210 return !new_crtc_state->ips_enabled;
5211}
5212
5213static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5214 const struct intel_crtc_state *new_crtc_state)
5215{
5216 if (!new_crtc_state->ips_enabled)
5217 return false;
5218
5219 if (needs_modeset(&new_crtc_state->base))
5220 return true;
5221
5222 /*
5223 * We can't read out IPS on broadwell, assume the worst and
5224 * forcibly enable IPS on the first fastset.
5225 */
5226 if (new_crtc_state->update_pipe &&
5227 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5228 return true;
5229
5230 return !old_crtc_state->ips_enabled;
5231}
5232
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305233static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5234 const struct intel_crtc_state *crtc_state)
5235{
5236 if (!crtc_state->nv12_planes)
5237 return false;
5238
5239 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
5240 return false;
5241
5242 if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
5243 IS_CANNONLAKE(dev_priv))
5244 return true;
5245
5246 return false;
5247}
5248
Daniel Vetter5a21b662016-05-24 17:13:53 +02005249static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5250{
5251 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +05305252 struct drm_device *dev = crtc->base.dev;
5253 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005254 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5255 struct intel_crtc_state *pipe_config =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005256 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5257 crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005258 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005259 struct drm_plane_state *old_primary_state =
5260 drm_atomic_get_old_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005261
Chris Wilson5748b6a2016-08-04 16:32:38 +01005262 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005263
Daniel Vetter5a21b662016-05-24 17:13:53 +02005264 if (pipe_config->update_wm_post && pipe_config->base.active)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005265 intel_update_watermarks(crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005266
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005267 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5268 hsw_enable_ips(pipe_config);
5269
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005270 if (old_primary_state) {
5271 struct drm_plane_state *new_primary_state =
5272 drm_atomic_get_new_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005273
5274 intel_fbc_post_update(crtc);
5275
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005276 if (new_primary_state->visible &&
Daniel Vetter5a21b662016-05-24 17:13:53 +02005277 (needs_modeset(&pipe_config->base) ||
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005278 !old_primary_state->visible))
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005279 intel_post_enable_primary(&crtc->base, pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005280 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305281
5282 /* Display WA 827 */
5283 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305284 !needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305285 skl_wa_clkgate(dev_priv, crtc->pipe, false);
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305286 skl_wa_528(dev_priv, crtc->pipe, false);
5287 }
Daniel Vetter5a21b662016-05-24 17:13:53 +02005288}
5289
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005290static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5291 struct intel_crtc_state *pipe_config)
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005292{
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005293 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005294 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005295 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005296 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5297 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005298 struct drm_plane_state *old_primary_state =
5299 drm_atomic_get_old_plane_state(old_state, primary);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005300 bool modeset = needs_modeset(&pipe_config->base);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005301 struct intel_atomic_state *old_intel_state =
5302 to_intel_atomic_state(old_state);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005303
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005304 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5305 hsw_disable_ips(old_crtc_state);
5306
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005307 if (old_primary_state) {
5308 struct intel_plane_state *new_primary_state =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005309 intel_atomic_get_new_plane_state(old_intel_state,
5310 to_intel_plane(primary));
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005311
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005312 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005313 /*
5314 * Gen2 reports pipe underruns whenever all planes are disabled.
5315 * So disable underrun reporting before all the planes get disabled.
5316 */
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005317 if (IS_GEN2(dev_priv) && old_primary_state->visible &&
5318 (modeset || !new_primary_state->base.visible))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005319 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005320 }
Ville Syrjälä852eb002015-06-24 22:00:07 +03005321
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305322 /* Display WA 827 */
5323 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305324 needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305325 skl_wa_clkgate(dev_priv, crtc->pipe, true);
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305326 skl_wa_528(dev_priv, crtc->pipe, true);
5327 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305328
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02005329 /*
5330 * Vblank time updates from the shadow to live plane control register
5331 * are blocked if the memory self-refresh mode is active at that
5332 * moment. So to make sure the plane gets truly disabled, disable
5333 * first the self-refresh mode. The self-refresh enable bit in turn
5334 * will be checked/applied by the HW only at the next frame start
5335 * event which is after the vblank start event, so we need to have a
5336 * wait-for-vblank between disabling the plane and the pipe.
5337 */
5338 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5339 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5340 intel_wait_for_vblank(dev_priv, crtc->pipe);
Maarten Lankhorst92826fc2015-12-03 13:49:13 +01005341
Matt Ropered4a6a72016-02-23 17:20:13 -08005342 /*
5343 * IVB workaround: must disable low power watermarks for at least
5344 * one frame before enabling scaling. LP watermarks can be re-enabled
5345 * when scaling is disabled.
5346 *
5347 * WaCxSRDisabledForSpriteScaling:ivb
5348 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +03005349 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5350 old_crtc_state->base.active)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005351 intel_wait_for_vblank(dev_priv, crtc->pipe);
Matt Ropered4a6a72016-02-23 17:20:13 -08005352
5353 /*
5354 * If we're doing a modeset, we're done. No need to do any pre-vblank
5355 * watermark programming here.
5356 */
5357 if (needs_modeset(&pipe_config->base))
5358 return;
5359
5360 /*
5361 * For platforms that support atomic watermarks, program the
5362 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5363 * will be the intermediate values that are safe for both pre- and
5364 * post- vblank; when vblank happens, the 'active' values will be set
5365 * to the final 'target' values and we'll do this again to get the
5366 * optimal watermarks. For gen9+ platforms, the values we program here
5367 * will be the final target values which will get automatically latched
5368 * at vblank time; no further programming will be necessary.
5369 *
5370 * If a platform hasn't been transitioned to atomic watermarks yet,
5371 * we'll continue to update watermarks the old way, if flags tell
5372 * us to.
5373 */
5374 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005375 dev_priv->display.initial_watermarks(old_intel_state,
5376 pipe_config);
Ville Syrjäläcaed3612016-03-09 19:07:25 +02005377 else if (pipe_config->update_wm_pre)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005378 intel_update_watermarks(crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005379}
5380
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005381static void intel_crtc_disable_planes(struct intel_crtc *crtc, unsigned plane_mask)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005382{
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005383 struct drm_device *dev = crtc->base.dev;
5384 struct intel_plane *plane;
5385 unsigned fb_bits = 0;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005386
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005387 intel_crtc_dpms_overlay_disable(crtc);
Maarten Lankhorst27321ae2015-04-21 17:12:52 +03005388
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005389 for_each_intel_plane_on_crtc(dev, crtc, plane) {
5390 if (plane_mask & BIT(plane->id)) {
5391 plane->disable_plane(plane, crtc);
Ville Syrjäläf98551a2014-05-22 17:48:06 +03005392
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005393 fb_bits |= plane->frontbuffer_bit;
5394 }
5395 }
5396
5397 intel_frontbuffer_flip(to_i915(dev), fb_bits);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005398}
5399
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005400static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005401 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005402 struct drm_atomic_state *old_state)
5403{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005404 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005405 struct drm_connector *conn;
5406 int i;
5407
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005408 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005409 struct intel_encoder *encoder =
5410 to_intel_encoder(conn_state->best_encoder);
5411
5412 if (conn_state->crtc != crtc)
5413 continue;
5414
5415 if (encoder->pre_pll_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005416 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005417 }
5418}
5419
5420static void intel_encoders_pre_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005421 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005422 struct drm_atomic_state *old_state)
5423{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005424 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005425 struct drm_connector *conn;
5426 int i;
5427
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005428 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005429 struct intel_encoder *encoder =
5430 to_intel_encoder(conn_state->best_encoder);
5431
5432 if (conn_state->crtc != crtc)
5433 continue;
5434
5435 if (encoder->pre_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005436 encoder->pre_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005437 }
5438}
5439
5440static void intel_encoders_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005441 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005442 struct drm_atomic_state *old_state)
5443{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005444 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005445 struct drm_connector *conn;
5446 int i;
5447
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005448 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005449 struct intel_encoder *encoder =
5450 to_intel_encoder(conn_state->best_encoder);
5451
5452 if (conn_state->crtc != crtc)
5453 continue;
5454
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005455 if (encoder->enable)
5456 encoder->enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005457 intel_opregion_notify_encoder(encoder, true);
5458 }
5459}
5460
5461static void intel_encoders_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005462 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005463 struct drm_atomic_state *old_state)
5464{
5465 struct drm_connector_state *old_conn_state;
5466 struct drm_connector *conn;
5467 int i;
5468
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005469 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005470 struct intel_encoder *encoder =
5471 to_intel_encoder(old_conn_state->best_encoder);
5472
5473 if (old_conn_state->crtc != crtc)
5474 continue;
5475
5476 intel_opregion_notify_encoder(encoder, false);
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005477 if (encoder->disable)
5478 encoder->disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005479 }
5480}
5481
5482static void intel_encoders_post_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005483 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005484 struct drm_atomic_state *old_state)
5485{
5486 struct drm_connector_state *old_conn_state;
5487 struct drm_connector *conn;
5488 int i;
5489
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005490 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005491 struct intel_encoder *encoder =
5492 to_intel_encoder(old_conn_state->best_encoder);
5493
5494 if (old_conn_state->crtc != crtc)
5495 continue;
5496
5497 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005498 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005499 }
5500}
5501
5502static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005503 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005504 struct drm_atomic_state *old_state)
5505{
5506 struct drm_connector_state *old_conn_state;
5507 struct drm_connector *conn;
5508 int i;
5509
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005510 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005511 struct intel_encoder *encoder =
5512 to_intel_encoder(old_conn_state->best_encoder);
5513
5514 if (old_conn_state->crtc != crtc)
5515 continue;
5516
5517 if (encoder->post_pll_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005518 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005519 }
5520}
5521
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005522static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5523 struct drm_atomic_state *old_state)
Jesse Barnesf67a5592011-01-05 10:31:48 -08005524{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005525 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnesf67a5592011-01-05 10:31:48 -08005526 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005527 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005528 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5529 int pipe = intel_crtc->pipe;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005530 struct intel_atomic_state *old_intel_state =
5531 to_intel_atomic_state(old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005532
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005533 if (WARN_ON(intel_crtc->active))
Jesse Barnesf67a5592011-01-05 10:31:48 -08005534 return;
5535
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005536 /*
5537 * Sometimes spurious CPU pipe underruns happen during FDI
5538 * training, at least with VGA+HDMI cloning. Suppress them.
5539 *
5540 * On ILK we get an occasional spurious CPU pipe underruns
5541 * between eDP port A enable and vdd enable. Also PCH port
5542 * enable seems to result in the occasional CPU pipe underrun.
5543 *
5544 * Spurious PCH underruns also occur during PCH enabling.
5545 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005546 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5547 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005548
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005549 if (pipe_config->has_pch_encoder)
5550 intel_prepare_shared_dpll(pipe_config);
Daniel Vetterb14b1052014-04-24 23:55:13 +02005551
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005552 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005553 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005554
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005555 intel_set_pipe_timings(pipe_config);
5556 intel_set_pipe_src_size(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005557
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005558 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005559 intel_cpu_transcoder_set_m_n(pipe_config,
5560 &pipe_config->fdi_m_n, NULL);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005561 }
5562
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005563 ironlake_set_pipeconf(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005564
Jesse Barnesf67a5592011-01-05 10:31:48 -08005565 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005566
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005567 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005568
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005569 if (pipe_config->has_pch_encoder) {
Daniel Vetterfff367c2012-10-27 15:50:28 +02005570 /* Note: FDI PLL enabling _must_ be done before we enable the
5571 * cpu pipes, hence this is separate from all the other fdi/pch
5572 * enabling. */
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02005573 ironlake_fdi_pll_enable(pipe_config);
Daniel Vetter46b6f812012-09-06 22:08:33 +02005574 } else {
5575 assert_fdi_tx_disabled(dev_priv, pipe);
5576 assert_fdi_rx_disabled(dev_priv, pipe);
5577 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005578
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005579 ironlake_pfit_enable(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005580
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005581 /*
5582 * On ILK+ LUT must be loaded before the pipe is running but with
5583 * clocks enabled
5584 */
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02005585 intel_color_load_luts(&pipe_config->base);
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005586
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005587 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005588 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02005589 intel_enable_pipe(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005590
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005591 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005592 ironlake_pch_enable(old_intel_state, pipe_config);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005593
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005594 assert_vblank_disabled(crtc);
5595 drm_crtc_vblank_on(crtc);
5596
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005597 intel_encoders_enable(crtc, pipe_config, old_state);
Daniel Vetter61b77dd2012-07-02 00:16:19 +02005598
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005599 if (HAS_PCH_CPT(dev_priv))
Daniel Vettera1520312013-05-03 11:49:50 +02005600 cpt_verify_modeset(dev, intel_crtc->pipe);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005601
Ville Syrjäläea80a662018-05-24 22:04:05 +03005602 /*
5603 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5604 * And a second vblank wait is needed at least on ILK with
5605 * some interlaced HDMI modes. Let's do the double wait always
5606 * in case there are more corner cases we don't know about.
5607 */
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005608 if (pipe_config->has_pch_encoder) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005609 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjäläea80a662018-05-24 22:04:05 +03005610 intel_wait_for_vblank(dev_priv, pipe);
5611 }
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005612 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005613 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005614}
5615
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005616/* IPS only exists on ULT machines and is tied to pipe A. */
5617static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5618{
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005619 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005620}
5621
Imre Deaked69cd42017-10-02 10:55:57 +03005622static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5623 enum pipe pipe, bool apply)
5624{
5625 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5626 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5627
5628 if (apply)
5629 val |= mask;
5630 else
5631 val &= ~mask;
5632
5633 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5634}
5635
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005636static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5637{
5638 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5639 enum pipe pipe = crtc->pipe;
5640 uint32_t val;
5641
Rodrigo Vivi443d5e32018-10-04 08:18:14 -07005642 val = MBUS_DBOX_A_CREDIT(2);
5643 val |= MBUS_DBOX_BW_CREDIT(1);
5644 val |= MBUS_DBOX_B_CREDIT(8);
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005645
5646 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5647}
5648
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005649static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5650 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005651{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005652 struct drm_crtc *crtc = pipe_config->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005653 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005654 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005655 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005656 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005657 struct intel_atomic_state *old_intel_state =
5658 to_intel_atomic_state(old_state);
Imre Deaked69cd42017-10-02 10:55:57 +03005659 bool psl_clkgate_wa;
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305660 u32 pipe_chicken;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005661
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005662 if (WARN_ON(intel_crtc->active))
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005663 return;
5664
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005665 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03005666
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005667 if (pipe_config->shared_dpll)
5668 intel_enable_shared_dpll(pipe_config);
Daniel Vetterdf8ad702014-06-25 22:02:03 +03005669
Paulo Zanonic27e9172018-04-27 16:14:36 -07005670 if (INTEL_GEN(dev_priv) >= 11)
5671 icl_map_plls_to_ports(crtc, pipe_config, old_state);
5672
Paulo Zanonic8af5272018-05-02 14:58:51 -07005673 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5674
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005675 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005676 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter229fca92014-04-24 23:55:09 +02005677
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005678 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005679 intel_set_pipe_timings(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005680
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005681 intel_set_pipe_src_size(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005682
Jani Nikula4d1de972016-03-18 17:05:42 +02005683 if (cpu_transcoder != TRANSCODER_EDP &&
5684 !transcoder_is_dsi(cpu_transcoder)) {
5685 I915_WRITE(PIPE_MULT(cpu_transcoder),
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005686 pipe_config->pixel_multiplier - 1);
Clint Taylorebb69c92014-09-30 10:30:22 -07005687 }
5688
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005689 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005690 intel_cpu_transcoder_set_m_n(pipe_config,
5691 &pipe_config->fdi_m_n, NULL);
Daniel Vetter229fca92014-04-24 23:55:09 +02005692 }
5693
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005694 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005695 haswell_set_pipeconf(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005696
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005697 haswell_set_pipemisc(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005698
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02005699 intel_color_set_csc(&pipe_config->base);
Daniel Vetter229fca92014-04-24 23:55:09 +02005700
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005701 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005702
Imre Deaked69cd42017-10-02 10:55:57 +03005703 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5704 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005705 pipe_config->pch_pfit.enabled;
Imre Deaked69cd42017-10-02 10:55:57 +03005706 if (psl_clkgate_wa)
5707 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5708
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005709 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005710 skylake_pfit_enable(pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005711 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005712 ironlake_pfit_enable(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005713
5714 /*
5715 * On ILK+ LUT must be loaded before the pipe is running but with
5716 * clocks enabled
5717 */
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02005718 intel_color_load_luts(&pipe_config->base);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005719
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305720 /*
5721 * Display WA #1153: enable hardware to bypass the alpha math
5722 * and rounding for per-pixel values 00 and 0xff
5723 */
5724 if (INTEL_GEN(dev_priv) >= 11) {
5725 pipe_chicken = I915_READ(PIPE_CHICKEN(pipe));
5726 if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN))
5727 I915_WRITE_FW(PIPE_CHICKEN(pipe),
5728 pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN);
5729 }
5730
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005731 intel_ddi_set_pipe_settings(pipe_config);
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005732 if (!transcoder_is_dsi(cpu_transcoder))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005733 intel_ddi_enable_transcoder_func(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005734
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005735 if (dev_priv->display.initial_watermarks != NULL)
Ville Syrjälä3125d392016-11-28 19:37:03 +02005736 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005737
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005738 if (INTEL_GEN(dev_priv) >= 11)
5739 icl_pipe_mbus_enable(intel_crtc);
5740
Jani Nikula4d1de972016-03-18 17:05:42 +02005741 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005742 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005743 intel_enable_pipe(pipe_config);
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005744
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005745 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005746 lpt_pch_enable(old_intel_state, pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005747
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005748 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005749 intel_ddi_set_vc_payload_alloc(pipe_config, true);
Dave Airlie0e32b392014-05-02 14:02:48 +10005750
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005751 assert_vblank_disabled(crtc);
5752 drm_crtc_vblank_on(crtc);
5753
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005754 intel_encoders_enable(crtc, pipe_config, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005755
Imre Deaked69cd42017-10-02 10:55:57 +03005756 if (psl_clkgate_wa) {
5757 intel_wait_for_vblank(dev_priv, pipe);
5758 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5759 }
5760
Paulo Zanonie4916942013-09-20 16:21:19 -03005761 /* If we change the relative order between pipe/planes enabling, we need
5762 * to change the workaround. */
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005763 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01005764 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005765 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5766 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005767 }
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005768}
5769
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005770static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005771{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005772 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5773 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5774 enum pipe pipe = crtc->pipe;
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005775
5776 /* To avoid upsetting the power well on haswell only disable the pfit if
5777 * it's in use. The hw state code will make sure we get this right. */
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005778 if (old_crtc_state->pch_pfit.enabled) {
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005779 I915_WRITE(PF_CTL(pipe), 0);
5780 I915_WRITE(PF_WIN_POS(pipe), 0);
5781 I915_WRITE(PF_WIN_SZ(pipe), 0);
5782 }
5783}
5784
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005785static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5786 struct drm_atomic_state *old_state)
Jesse Barnes6be4a602010-09-10 10:26:01 -07005787{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005788 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes6be4a602010-09-10 10:26:01 -07005789 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005790 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005791 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5792 int pipe = intel_crtc->pipe;
Jesse Barnes6be4a602010-09-10 10:26:01 -07005793
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005794 /*
5795 * Sometimes spurious CPU pipe underruns happen when the
5796 * pipe is already disabled, but FDI RX/TX is still enabled.
5797 * Happens at least with VGA+HDMI cloning. Suppress them.
5798 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005799 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5800 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005801
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005802 intel_encoders_disable(crtc, old_crtc_state, old_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +02005803
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005804 drm_crtc_vblank_off(crtc);
5805 assert_vblank_disabled(crtc);
5806
Ville Syrjälä4972f702017-11-29 17:37:32 +02005807 intel_disable_pipe(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005808
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005809 ironlake_pfit_disable(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005810
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005811 if (old_crtc_state->has_pch_encoder)
Ville Syrjälä5a74f702015-05-05 17:17:38 +03005812 ironlake_fdi_disable(crtc);
5813
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005814 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005815
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005816 if (old_crtc_state->has_pch_encoder) {
Daniel Vetterd925c592013-06-05 13:34:04 +02005817 ironlake_disable_pch_transcoder(dev_priv, pipe);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005818
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005819 if (HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005820 i915_reg_t reg;
5821 u32 temp;
5822
Daniel Vetterd925c592013-06-05 13:34:04 +02005823 /* disable TRANS_DP_CTL */
5824 reg = TRANS_DP_CTL(pipe);
5825 temp = I915_READ(reg);
5826 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5827 TRANS_DP_PORT_SEL_MASK);
5828 temp |= TRANS_DP_PORT_SEL_NONE;
5829 I915_WRITE(reg, temp);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005830
Daniel Vetterd925c592013-06-05 13:34:04 +02005831 /* disable DPLL_SEL */
5832 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02005833 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
Daniel Vetterd925c592013-06-05 13:34:04 +02005834 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08005835 }
Daniel Vetterd925c592013-06-05 13:34:04 +02005836
Daniel Vetterd925c592013-06-05 13:34:04 +02005837 ironlake_fdi_pll_disable(intel_crtc);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005838 }
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005839
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005840 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005841 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005842}
5843
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005844static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5845 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005846{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005847 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005848 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005849 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Imre Deak24a28172018-06-13 20:07:06 +03005850 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005851
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005852 intel_encoders_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005853
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005854 drm_crtc_vblank_off(crtc);
5855 assert_vblank_disabled(crtc);
5856
Jani Nikula4d1de972016-03-18 17:05:42 +02005857 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005858 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005859 intel_disable_pipe(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005860
Imre Deak24a28172018-06-13 20:07:06 +03005861 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
5862 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
Ville Syrjäläa4bf2142014-08-18 21:27:34 +03005863
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005864 if (!transcoder_is_dsi(cpu_transcoder))
Clint Taylor90c3e212018-07-10 13:02:05 -07005865 intel_ddi_disable_transcoder_func(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005866
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005867 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005868 skylake_scaler_disable(intel_crtc);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005869 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005870 ironlake_pfit_disable(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005871
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005872 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Paulo Zanonic27e9172018-04-27 16:14:36 -07005873
5874 if (INTEL_GEN(dev_priv) >= 11)
5875 icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005876}
5877
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005878static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes2dd24552013-04-25 12:55:01 -07005879{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005880 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5881 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes2dd24552013-04-25 12:55:01 -07005882
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005883 if (!crtc_state->gmch_pfit.control)
Jesse Barnes2dd24552013-04-25 12:55:01 -07005884 return;
5885
Daniel Vetterc0b03412013-05-28 12:05:54 +02005886 /*
5887 * The panel fitter should only be adjusted whilst the pipe is disabled,
5888 * according to register description and PRM.
5889 */
Jesse Barnes2dd24552013-04-25 12:55:01 -07005890 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5891 assert_pipe_disabled(dev_priv, crtc->pipe);
5892
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005893 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
5894 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
Daniel Vetter5a80c452013-04-25 22:52:18 +02005895
5896 /* Border color in case we don't scale up to the full screen. Black by
5897 * default, change to something else for debugging. */
5898 I915_WRITE(BCLRPAT(crtc->pipe), 0);
Jesse Barnes2dd24552013-04-25 12:55:01 -07005899}
5900
Mahesh Kumar176597a2018-10-04 14:20:43 +05305901bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
5902{
5903 if (port == PORT_NONE)
5904 return false;
5905
5906 if (IS_ICELAKE(dev_priv))
5907 return port <= PORT_B;
5908
5909 return false;
5910}
5911
Paulo Zanoniac213c12018-05-21 17:25:37 -07005912bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
5913{
5914 if (IS_ICELAKE(dev_priv))
5915 return port >= PORT_C && port <= PORT_F;
5916
5917 return false;
5918}
5919
5920enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
5921{
5922 if (!intel_port_is_tc(dev_priv, port))
5923 return PORT_TC_NONE;
5924
5925 return port - PORT_C;
5926}
5927
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02005928enum intel_display_power_domain intel_port_to_power_domain(enum port port)
Dave Airlied05410f2014-06-05 13:22:59 +10005929{
5930 switch (port) {
5931 case PORT_A:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005932 return POWER_DOMAIN_PORT_DDI_A_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005933 case PORT_B:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005934 return POWER_DOMAIN_PORT_DDI_B_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005935 case PORT_C:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005936 return POWER_DOMAIN_PORT_DDI_C_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005937 case PORT_D:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005938 return POWER_DOMAIN_PORT_DDI_D_LANES;
Xiong Zhangd8e19f92015-08-13 18:00:12 +08005939 case PORT_E:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005940 return POWER_DOMAIN_PORT_DDI_E_LANES;
Rodrigo Vivi9787e832018-01-29 15:22:22 -08005941 case PORT_F:
5942 return POWER_DOMAIN_PORT_DDI_F_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005943 default:
Imre Deakb9fec162015-11-18 15:57:25 +02005944 MISSING_CASE(port);
Dave Airlied05410f2014-06-05 13:22:59 +10005945 return POWER_DOMAIN_PORT_OTHER;
5946 }
5947}
5948
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02005949static u64 get_crtc_power_domains(struct drm_crtc *crtc,
5950 struct intel_crtc_state *crtc_state)
Imre Deak319be8a2014-03-04 19:22:57 +02005951{
5952 struct drm_device *dev = crtc->dev;
Maarten Lankhorst37255d82016-12-15 15:29:43 +01005953 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01005954 struct drm_encoder *encoder;
Imre Deak319be8a2014-03-04 19:22:57 +02005955 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5956 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02005957 u64 mask;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01005958 enum transcoder transcoder = crtc_state->cpu_transcoder;
Imre Deak77d22dc2014-03-05 16:20:52 +02005959
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01005960 if (!crtc_state->base.active)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02005961 return 0;
5962
Imre Deak17bd6e62018-01-09 14:20:40 +02005963 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
5964 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01005965 if (crtc_state->pch_pfit.enabled ||
5966 crtc_state->pch_pfit.force_thru)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02005967 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
Imre Deak77d22dc2014-03-05 16:20:52 +02005968
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01005969 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
5970 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5971
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02005972 mask |= BIT_ULL(intel_encoder->power_domain);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01005973 }
Imre Deak319be8a2014-03-04 19:22:57 +02005974
Maarten Lankhorst37255d82016-12-15 15:29:43 +01005975 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
Imre Deak17bd6e62018-01-09 14:20:40 +02005976 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
Maarten Lankhorst37255d82016-12-15 15:29:43 +01005977
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01005978 if (crtc_state->shared_dpll)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02005979 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01005980
Imre Deak77d22dc2014-03-05 16:20:52 +02005981 return mask;
5982}
5983
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02005984static u64
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01005985modeset_get_crtc_power_domains(struct drm_crtc *crtc,
5986 struct intel_crtc_state *crtc_state)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02005987{
Chris Wilsonfac5e232016-07-04 11:34:36 +01005988 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02005989 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5990 enum intel_display_power_domain domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02005991 u64 domains, new_domains, old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02005992
5993 old_domains = intel_crtc->enabled_power_domains;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01005994 intel_crtc->enabled_power_domains = new_domains =
5995 get_crtc_power_domains(crtc, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02005996
Daniel Vetter5a21b662016-05-24 17:13:53 +02005997 domains = new_domains & ~old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02005998
5999 for_each_power_domain(domain, domains)
6000 intel_display_power_get(dev_priv, domain);
6001
Daniel Vetter5a21b662016-05-24 17:13:53 +02006002 return old_domains & ~new_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006003}
6004
6005static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006006 u64 domains)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006007{
6008 enum intel_display_power_domain domain;
6009
6010 for_each_power_domain(domain, domains)
6011 intel_display_power_put(dev_priv, domain);
6012}
6013
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006014static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6015 struct drm_atomic_state *old_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006016{
Ville Syrjäläff32c542017-03-02 19:14:57 +02006017 struct intel_atomic_state *old_intel_state =
6018 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006019 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006020 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006021 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006022 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006023 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006024
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006025 if (WARN_ON(intel_crtc->active))
Jesse Barnes89b667f2013-04-18 14:51:36 -07006026 return;
6027
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006028 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006029 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006030
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006031 intel_set_pipe_timings(pipe_config);
6032 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006033
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006034 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjäläc14b0482014-10-16 20:52:34 +03006035 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6036 I915_WRITE(CHV_CANVAS(pipe), 0);
6037 }
6038
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006039 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006040
P Raviraj Sitaramc59d2da2018-09-10 19:57:14 +05306041 intel_color_set_csc(&pipe_config->base);
6042
Jesse Barnes89b667f2013-04-18 14:51:36 -07006043 intel_crtc->active = true;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006044
Daniel Vettera72e4c92014-09-30 10:56:47 +02006045 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006046
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006047 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006048
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006049 if (IS_CHERRYVIEW(dev_priv)) {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006050 chv_prepare_pll(intel_crtc, pipe_config);
6051 chv_enable_pll(intel_crtc, pipe_config);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006052 } else {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006053 vlv_prepare_pll(intel_crtc, pipe_config);
6054 vlv_enable_pll(intel_crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006055 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07006056
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006057 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006058
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006059 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006060
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02006061 intel_color_load_luts(&pipe_config->base);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006062
Ville Syrjäläff32c542017-03-02 19:14:57 +02006063 dev_priv->display.initial_watermarks(old_intel_state,
6064 pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006065 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006066
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006067 assert_vblank_disabled(crtc);
6068 drm_crtc_vblank_on(crtc);
6069
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006070 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006071}
6072
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006073static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006074{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006075 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6076 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006077
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006078 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6079 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006080}
6081
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006082static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6083 struct drm_atomic_state *old_state)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006084{
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006085 struct intel_atomic_state *old_intel_state =
6086 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006087 struct drm_crtc *crtc = pipe_config->base.crtc;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006088 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006089 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -08006090 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006091 enum pipe pipe = intel_crtc->pipe;
Jesse Barnes79e53942008-11-07 14:24:08 -08006092
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006093 if (WARN_ON(intel_crtc->active))
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006094 return;
6095
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006096 i9xx_set_pll_dividers(pipe_config);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006097
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006098 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006099 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006100
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006101 intel_set_pipe_timings(pipe_config);
6102 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006103
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006104 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006105
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006106 intel_crtc->active = true;
Chris Wilson6b383a72010-09-13 13:54:26 +01006107
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01006108 if (!IS_GEN2(dev_priv))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006109 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006110
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006111 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Mika Kuoppala9d6d9f12013-02-08 16:35:38 +02006112
Ville Syrjälä939994d2017-09-13 17:08:56 +03006113 i9xx_enable_pll(intel_crtc, pipe_config);
Daniel Vetterf6736a12013-06-05 13:34:30 +02006114
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006115 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006116
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02006117 intel_color_load_luts(&pipe_config->base);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006118
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006119 if (dev_priv->display.initial_watermarks != NULL)
6120 dev_priv->display.initial_watermarks(old_intel_state,
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006121 pipe_config);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006122 else
6123 intel_update_watermarks(intel_crtc);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006124 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006125
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006126 assert_vblank_disabled(crtc);
6127 drm_crtc_vblank_on(crtc);
6128
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006129 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006130}
6131
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006132static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter87476d62013-04-11 16:29:06 +02006133{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006134 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6135 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter328d8e82013-05-08 10:36:31 +02006136
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006137 if (!old_crtc_state->gmch_pfit.control)
Daniel Vetter328d8e82013-05-08 10:36:31 +02006138 return;
Daniel Vetter87476d62013-04-11 16:29:06 +02006139
6140 assert_pipe_disabled(dev_priv, crtc->pipe);
6141
Chris Wilson43031782018-09-13 14:16:26 +01006142 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6143 I915_READ(PFIT_CONTROL));
Daniel Vetter328d8e82013-05-08 10:36:31 +02006144 I915_WRITE(PFIT_CONTROL, 0);
Daniel Vetter87476d62013-04-11 16:29:06 +02006145}
6146
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006147static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6148 struct drm_atomic_state *old_state)
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006149{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006150 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006151 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006152 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006153 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6154 int pipe = intel_crtc->pipe;
Daniel Vetteref9c3ae2012-06-29 22:40:09 +02006155
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006156 /*
6157 * On gen2 planes are double buffered but the pipe isn't, so we must
6158 * wait for planes to fully turn off before disabling the pipe.
6159 */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01006160 if (IS_GEN2(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02006161 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006162
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006163 intel_encoders_disable(crtc, old_crtc_state, old_state);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006164
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006165 drm_crtc_vblank_off(crtc);
6166 assert_vblank_disabled(crtc);
6167
Ville Syrjälä4972f702017-11-29 17:37:32 +02006168 intel_disable_pipe(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006169
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006170 i9xx_pfit_disable(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006171
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006172 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006173
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006174 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006175 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006176 chv_disable_pll(dev_priv, pipe);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006177 else if (IS_VALLEYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006178 vlv_disable_pll(dev_priv, pipe);
6179 else
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006180 i9xx_disable_pll(old_crtc_state);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006181 }
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006182
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006183 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006184
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01006185 if (!IS_GEN2(dev_priv))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006186 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjäläff32c542017-03-02 19:14:57 +02006187
6188 if (!dev_priv->display.initial_watermarks)
6189 intel_update_watermarks(intel_crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03006190
6191 /* clock the pipe down to 640x480@60 to potentially save power */
6192 if (IS_I830(dev_priv))
6193 i830_enable_pipe(dev_priv, pipe);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006194}
6195
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006196static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6197 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnesee7b9f92012-04-20 17:11:53 +01006198{
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006199 struct intel_encoder *encoder;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006200 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006201 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006202 enum intel_display_power_domain domain;
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006203 struct intel_plane *plane;
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006204 u64 domains;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006205 struct drm_atomic_state *state;
6206 struct intel_crtc_state *crtc_state;
6207 int ret;
Daniel Vetter976f8a22012-07-08 22:34:21 +02006208
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006209 if (!intel_crtc->active)
6210 return;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006211
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006212 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6213 const struct intel_plane_state *plane_state =
6214 to_intel_plane_state(plane->base.state);
Maarten Lankhorst54a419612015-11-23 10:25:28 +01006215
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006216 if (plane_state->base.visible)
6217 intel_plane_disable_noatomic(intel_crtc, plane);
Maarten Lankhorsta5392052015-06-15 12:33:52 +02006218 }
6219
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006220 state = drm_atomic_state_alloc(crtc->dev);
Ander Conselvan de Oliveira31bb2ef2017-01-20 16:28:45 +02006221 if (!state) {
6222 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6223 crtc->base.id, crtc->name);
6224 return;
6225 }
6226
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006227 state->acquire_ctx = ctx;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006228
6229 /* Everything's already locked, -EDEADLK can't happen. */
6230 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6231 ret = drm_atomic_add_affected_connectors(state, crtc);
6232
6233 WARN_ON(IS_ERR(crtc_state) || ret);
6234
6235 dev_priv->display.crtc_disable(crtc_state, state);
6236
Chris Wilson08536952016-10-14 13:18:18 +01006237 drm_atomic_state_put(state);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006238
Ville Syrjälä78108b72016-05-27 20:59:19 +03006239 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6240 crtc->base.id, crtc->name);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006241
6242 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6243 crtc->state->active = false;
Matt Roper37d90782015-09-24 15:53:06 -07006244 intel_crtc->active = false;
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006245 crtc->enabled = false;
6246 crtc->state->connector_mask = 0;
6247 crtc->state->encoder_mask = 0;
6248
6249 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6250 encoder->base.crtc = NULL;
6251
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -02006252 intel_fbc_disable(intel_crtc);
Ville Syrjälä432081b2016-10-31 22:37:03 +02006253 intel_update_watermarks(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02006254 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006255
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006256 domains = intel_crtc->enabled_power_domains;
6257 for_each_power_domain(domain, domains)
6258 intel_display_power_put(dev_priv, domain);
6259 intel_crtc->enabled_power_domains = 0;
Maarten Lankhorst565602d2015-12-10 12:33:57 +01006260
6261 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
Ville Syrjäläd305e062017-08-30 21:57:03 +03006262 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03006263 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006264}
6265
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006266/*
6267 * turn all crtc's off, but do not adjust state
6268 * This has to be paired with a call to intel_modeset_setup_hw_state.
6269 */
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006270int intel_display_suspend(struct drm_device *dev)
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006271{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006272 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006273 struct drm_atomic_state *state;
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006274 int ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006275
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006276 state = drm_atomic_helper_suspend(dev);
6277 ret = PTR_ERR_OR_ZERO(state);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006278 if (ret)
6279 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006280 else
6281 dev_priv->modeset_restore_state = state;
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006282 return ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006283}
6284
Chris Wilsonea5b2132010-08-04 13:50:23 +01006285void intel_encoder_destroy(struct drm_encoder *encoder)
6286{
Chris Wilson4ef69c72010-09-09 15:14:28 +01006287 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
Chris Wilsonea5b2132010-08-04 13:50:23 +01006288
Chris Wilsonea5b2132010-08-04 13:50:23 +01006289 drm_encoder_cleanup(encoder);
6290 kfree(intel_encoder);
6291}
6292
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006293/* Cross check the actual hw state with our own modeset state tracking (and it's
6294 * internal consistency). */
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006295static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6296 struct drm_connector_state *conn_state)
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006297{
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006298 struct intel_connector *connector = to_intel_connector(conn_state->connector);
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006299
6300 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6301 connector->base.base.id,
6302 connector->base.name);
6303
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006304 if (connector->get_hw_state(connector)) {
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006305 struct intel_encoder *encoder = connector->encoder;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006306
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006307 I915_STATE_WARN(!crtc_state,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006308 "connector enabled without attached crtc\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006309
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006310 if (!crtc_state)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006311 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006312
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006313 I915_STATE_WARN(!crtc_state->active,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006314 "connector is active, but attached crtc isn't\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006315
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006316 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006317 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006318
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006319 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006320 "atomic encoder doesn't match attached encoder\n");
Dave Airlie36cd7442014-05-02 13:44:18 +10006321
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006322 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006323 "attached encoder crtc differs from connector crtc\n");
6324 } else {
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006325 I915_STATE_WARN(crtc_state && crtc_state->active,
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02006326 "attached crtc is active, but connector isn't\n");
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006327 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006328 "best encoder set without crtc!\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006329 }
6330}
6331
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006332static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006333{
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006334 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6335 return crtc_state->fdi_lanes;
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006336
6337 return 0;
6338}
6339
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006340static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006341 struct intel_crtc_state *pipe_config)
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006342{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006343 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006344 struct drm_atomic_state *state = pipe_config->base.state;
6345 struct intel_crtc *other_crtc;
6346 struct intel_crtc_state *other_crtc_state;
6347
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006348 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6349 pipe_name(pipe), pipe_config->fdi_lanes);
6350 if (pipe_config->fdi_lanes > 4) {
6351 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6352 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006353 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006354 }
6355
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006356 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006357 if (pipe_config->fdi_lanes > 2) {
6358 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6359 pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006360 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006361 } else {
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006362 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006363 }
6364 }
6365
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +00006366 if (INTEL_INFO(dev_priv)->num_pipes == 2)
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006367 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006368
6369 /* Ivybridge 3 pipe is really complicated */
6370 switch (pipe) {
6371 case PIPE_A:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006372 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006373 case PIPE_B:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006374 if (pipe_config->fdi_lanes <= 2)
6375 return 0;
6376
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006377 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006378 other_crtc_state =
6379 intel_atomic_get_crtc_state(state, other_crtc);
6380 if (IS_ERR(other_crtc_state))
6381 return PTR_ERR(other_crtc_state);
6382
6383 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006384 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6385 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006386 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006387 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006388 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006389 case PIPE_C:
Ville Syrjälä251cc672015-03-11 18:52:30 +02006390 if (pipe_config->fdi_lanes > 2) {
6391 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6392 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006393 return -EINVAL;
Ville Syrjälä251cc672015-03-11 18:52:30 +02006394 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006395
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006396 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006397 other_crtc_state =
6398 intel_atomic_get_crtc_state(state, other_crtc);
6399 if (IS_ERR(other_crtc_state))
6400 return PTR_ERR(other_crtc_state);
6401
6402 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006403 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006404 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006405 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006406 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006407 default:
6408 BUG();
6409 }
6410}
6411
Daniel Vettere29c22c2013-02-21 00:00:16 +01006412#define RETRY 1
6413static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006414 struct intel_crtc_state *pipe_config)
Daniel Vetter877d48d2013-04-19 11:24:43 +02006415{
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006416 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006417 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006418 int lane, link_bw, fdi_dotclock, ret;
6419 bool needs_recompute = false;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006420
Daniel Vettere29c22c2013-02-21 00:00:16 +01006421retry:
Daniel Vetter877d48d2013-04-19 11:24:43 +02006422 /* FDI is a binary signal running at ~2.7GHz, encoding
6423 * each output octet as 10 bits. The actual frequency
6424 * is stored as a divider into a 100MHz clock, and the
6425 * mode pixel clock is stored in units of 1KHz.
6426 * Hence the bw of each lane in terms of the mode signal
6427 * is:
6428 */
Ville Syrjälä21a727b2016-02-17 21:41:10 +02006429 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006430
Damien Lespiau241bfc32013-09-25 16:45:37 +01006431 fdi_dotclock = adjusted_mode->crtc_clock;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006432
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006433 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
Daniel Vetter877d48d2013-04-19 11:24:43 +02006434 pipe_config->pipe_bpp);
6435
6436 pipe_config->fdi_lanes = lane;
6437
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006438 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006439 link_bw, &pipe_config->fdi_m_n, false);
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006440
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02006441 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006442 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01006443 pipe_config->pipe_bpp -= 2*3;
6444 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6445 pipe_config->pipe_bpp);
6446 needs_recompute = true;
6447 pipe_config->bw_constrained = true;
6448
6449 goto retry;
6450 }
6451
6452 if (needs_recompute)
6453 return RETRY;
6454
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006455 return ret;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006456}
6457
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006458bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006459{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006460 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6461 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6462
6463 /* IPS only exists on ULT machines and is tied to pipe A. */
6464 if (!hsw_crtc_supports_ips(crtc))
Ville Syrjälä6e644622017-08-17 17:55:09 +03006465 return false;
6466
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006467 if (!i915_modparams.enable_ips)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006468 return false;
6469
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006470 if (crtc_state->pipe_bpp > 24)
6471 return false;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006472
6473 /*
Ville Syrjäläb432e5c2015-06-03 15:45:13 +03006474 * We compare against max which means we must take
6475 * the increased cdclk requirement into account when
6476 * calculating the new cdclk.
6477 *
6478 * Should measure whether using a lower cdclk w/o IPS
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006479 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006480 if (IS_BROADWELL(dev_priv) &&
6481 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6482 return false;
6483
6484 return true;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006485}
6486
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006487static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006488{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006489 struct drm_i915_private *dev_priv =
6490 to_i915(crtc_state->base.crtc->dev);
6491 struct intel_atomic_state *intel_state =
6492 to_intel_atomic_state(crtc_state->base.state);
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006493
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006494 if (!hsw_crtc_state_ips_capable(crtc_state))
6495 return false;
6496
6497 if (crtc_state->ips_force_disable)
6498 return false;
6499
Maarten Lankhorstadbe5c52017-11-22 19:39:06 +01006500 /* IPS should be fine as long as at least one plane is enabled. */
6501 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006502 return false;
6503
6504 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6505 if (IS_BROADWELL(dev_priv) &&
6506 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6507 return false;
6508
6509 return true;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006510}
6511
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006512static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6513{
6514 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6515
6516 /* GDG double wide on either pipe, otherwise pipe A only */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00006517 return INTEL_GEN(dev_priv) < 4 &&
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006518 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6519}
6520
Ville Syrjäläceb99322017-01-20 20:22:05 +02006521static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6522{
6523 uint32_t pixel_rate;
6524
6525 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6526
6527 /*
6528 * We only use IF-ID interlacing. If we ever use
6529 * PF-ID we'll need to adjust the pixel_rate here.
6530 */
6531
6532 if (pipe_config->pch_pfit.enabled) {
6533 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6534 uint32_t pfit_size = pipe_config->pch_pfit.size;
6535
6536 pipe_w = pipe_config->pipe_src_w;
6537 pipe_h = pipe_config->pipe_src_h;
6538
6539 pfit_w = (pfit_size >> 16) & 0xFFFF;
6540 pfit_h = pfit_size & 0xFFFF;
6541 if (pipe_w < pfit_w)
6542 pipe_w = pfit_w;
6543 if (pipe_h < pfit_h)
6544 pipe_h = pfit_h;
6545
6546 if (WARN_ON(!pfit_w || !pfit_h))
6547 return pixel_rate;
6548
6549 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6550 pfit_w * pfit_h);
6551 }
6552
6553 return pixel_rate;
6554}
6555
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006556static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6557{
6558 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6559
6560 if (HAS_GMCH_DISPLAY(dev_priv))
6561 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6562 crtc_state->pixel_rate =
6563 crtc_state->base.adjusted_mode.crtc_clock;
6564 else
6565 crtc_state->pixel_rate =
6566 ilk_pipe_pixel_rate(crtc_state);
6567}
6568
Daniel Vettera43f6e02013-06-07 23:10:32 +02006569static int intel_crtc_compute_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006570 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -08006571{
Daniel Vettera43f6e02013-06-07 23:10:32 +02006572 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006573 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006574 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläf3261152016-05-24 21:34:18 +03006575 int clock_limit = dev_priv->max_dotclk_freq;
Chris Wilson89749352010-09-12 18:25:19 +01006576
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006577 if (INTEL_GEN(dev_priv) < 4) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006578 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006579
6580 /*
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006581 * Enable double wide mode when the dot clock
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006582 * is > 90% of the (display) core speed.
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006583 */
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006584 if (intel_crtc_supports_double_wide(crtc) &&
6585 adjusted_mode->crtc_clock > clock_limit) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006586 clock_limit = dev_priv->max_dotclk_freq;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006587 pipe_config->double_wide = true;
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006588 }
Ville Syrjäläf3261152016-05-24 21:34:18 +03006589 }
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006590
Ville Syrjäläf3261152016-05-24 21:34:18 +03006591 if (adjusted_mode->crtc_clock > clock_limit) {
6592 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6593 adjusted_mode->crtc_clock, clock_limit,
6594 yesno(pipe_config->double_wide));
6595 return -EINVAL;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006596 }
Chris Wilson89749352010-09-12 18:25:19 +01006597
Shashank Sharma8c79f842018-10-12 11:53:09 +05306598 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6599 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6600 pipe_config->base.ctm) {
Shashank Sharma25edf912017-07-21 20:55:07 +05306601 /*
6602 * There is only one pipe CSC unit per pipe, and we need that
6603 * for output conversion from RGB->YCBCR. So if CTM is already
6604 * applied we can't support YCBCR420 output.
6605 */
6606 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6607 return -EINVAL;
6608 }
6609
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006610 /*
6611 * Pipe horizontal size must be even in:
6612 * - DVO ganged mode
6613 * - LVDS dual channel mode
6614 * - Double wide pipe
6615 */
Ville Syrjälä0574bd82017-11-23 21:04:48 +02006616 if (pipe_config->pipe_src_w & 1) {
6617 if (pipe_config->double_wide) {
6618 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6619 return -EINVAL;
6620 }
6621
6622 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6623 intel_is_dual_link_lvds(dev)) {
6624 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6625 return -EINVAL;
6626 }
6627 }
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006628
Damien Lespiau8693a822013-05-03 18:48:11 +01006629 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6630 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
Chris Wilson44f46b422012-06-21 13:19:59 +03006631 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01006632 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
Ville Syrjäläaad941d2015-09-25 16:38:56 +03006633 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
Daniel Vettere29c22c2013-02-21 00:00:16 +01006634 return -EINVAL;
Chris Wilson44f46b422012-06-21 13:19:59 +03006635
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006636 intel_crtc_compute_pixel_rate(pipe_config);
6637
Daniel Vetter877d48d2013-04-19 11:24:43 +02006638 if (pipe_config->has_pch_encoder)
Daniel Vettera43f6e02013-06-07 23:10:32 +02006639 return ironlake_fdi_compute_config(crtc, pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006640
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +02006641 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08006642}
6643
Zhenyu Wang2c072452009-06-05 15:38:42 +08006644static void
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006645intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006646{
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006647 while (*num > DATA_LINK_M_N_MASK ||
6648 *den > DATA_LINK_M_N_MASK) {
Zhenyu Wang2c072452009-06-05 15:38:42 +08006649 *num >>= 1;
6650 *den >>= 1;
6651 }
6652}
6653
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006654static void compute_m_n(unsigned int m, unsigned int n,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006655 uint32_t *ret_m, uint32_t *ret_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006656 bool constant_n)
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006657{
Jani Nikula9a86cda2017-03-27 14:33:25 +03006658 /*
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006659 * Several DP dongles in particular seem to be fussy about
6660 * too large link M/N values. Give N value as 0x8000 that
6661 * should be acceptable by specific devices. 0x8000 is the
6662 * specified fixed N value for asynchronous clock mode,
6663 * which the devices expect also in synchronous clock mode.
Jani Nikula9a86cda2017-03-27 14:33:25 +03006664 */
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006665 if (constant_n)
6666 *ret_n = 0x8000;
6667 else
6668 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
Jani Nikula9a86cda2017-03-27 14:33:25 +03006669
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006670 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6671 intel_reduce_m_n_ratio(ret_m, ret_n);
6672}
6673
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006674void
6675intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6676 int pixel_clock, int link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006677 struct intel_link_m_n *m_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006678 bool constant_n)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006679{
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006680 m_n->tu = 64;
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006681
6682 compute_m_n(bits_per_pixel * pixel_clock,
6683 link_clock * nlanes * 8,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006684 &m_n->gmch_m, &m_n->gmch_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006685 constant_n);
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006686
6687 compute_m_n(pixel_clock, link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006688 &m_n->link_m, &m_n->link_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006689 constant_n);
Zhenyu Wang2c072452009-06-05 15:38:42 +08006690}
6691
Chris Wilsona7615032011-01-12 17:04:08 +00006692static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6693{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00006694 if (i915_modparams.panel_use_ssc >= 0)
6695 return i915_modparams.panel_use_ssc != 0;
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03006696 return dev_priv->vbt.lvds_use_ssc
Keith Packard435793d2011-07-12 14:56:22 -07006697 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
Chris Wilsona7615032011-01-12 17:04:08 +00006698}
6699
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006700static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006701{
Daniel Vetter7df00d72013-05-21 21:54:55 +02006702 return (1 << dpll->n) << 16 | dpll->m2;
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006703}
Daniel Vetterf47709a2013-03-28 10:42:02 +01006704
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006705static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6706{
6707 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006708}
6709
Daniel Vetterf47709a2013-03-28 10:42:02 +01006710static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006711 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03006712 struct dpll *reduced_clock)
Jesse Barnesa7516a02011-12-15 12:30:37 -08006713{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006714 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006715 u32 fp, fp2 = 0;
6716
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006717 if (IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006718 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006719 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006720 fp2 = pnv_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006721 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006722 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006723 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006724 fp2 = i9xx_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006725 }
6726
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006727 crtc_state->dpll_hw_state.fp0 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006728
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03006729 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Rodrigo Viviab585de2015-03-24 12:40:09 -07006730 reduced_clock) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006731 crtc_state->dpll_hw_state.fp1 = fp2;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006732 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006733 crtc_state->dpll_hw_state.fp1 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006734 }
6735}
6736
Chon Ming Lee5e69f972013-09-05 20:41:49 +08006737static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6738 pipe)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006739{
6740 u32 reg_val;
6741
6742 /*
6743 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6744 * and set it to a reasonable value instead.
6745 */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006746 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006747 reg_val &= 0xffffff00;
6748 reg_val |= 0x00000030;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006749 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006750
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006751 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Imre Deaked585702017-05-10 12:21:47 +03006752 reg_val &= 0x00ffffff;
6753 reg_val |= 0x8c000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006754 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006755
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006756 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006757 reg_val &= 0xffffff00;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006758 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006759
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006760 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006761 reg_val &= 0x00ffffff;
6762 reg_val |= 0xb0000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006763 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006764}
6765
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006766static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6767 const struct intel_link_m_n *m_n)
Daniel Vetterb5518422013-05-03 11:49:48 +02006768{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006769 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6770 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6771 enum pipe pipe = crtc->pipe;
Daniel Vetterb5518422013-05-03 11:49:48 +02006772
Daniel Vettere3b95f12013-05-03 11:49:49 +02006773 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6774 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6775 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6776 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02006777}
6778
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006779static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
6780 enum transcoder transcoder)
6781{
6782 if (IS_HASWELL(dev_priv))
6783 return transcoder == TRANSCODER_EDP;
6784
6785 /*
6786 * Strictly speaking some registers are available before
6787 * gen7, but we only support DRRS on gen7+
6788 */
6789 return IS_GEN7(dev_priv) || IS_CHERRYVIEW(dev_priv);
6790}
6791
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006792static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6793 const struct intel_link_m_n *m_n,
6794 const struct intel_link_m_n *m2_n2)
Daniel Vetterb5518422013-05-03 11:49:48 +02006795{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006796 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006797 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006798 enum pipe pipe = crtc->pipe;
6799 enum transcoder transcoder = crtc_state->cpu_transcoder;
Daniel Vetterb5518422013-05-03 11:49:48 +02006800
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006801 if (INTEL_GEN(dev_priv) >= 5) {
Daniel Vetterb5518422013-05-03 11:49:48 +02006802 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6803 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6804 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6805 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006806 /*
6807 * M2_N2 registers are set only if DRRS is supported
6808 * (to make sure the registers are not unnecessarily accessed).
Vandana Kannanf769cd22014-08-05 07:51:22 -07006809 */
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006810 if (m2_n2 && crtc_state->has_drrs &&
6811 transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07006812 I915_WRITE(PIPE_DATA_M2(transcoder),
6813 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6814 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6815 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6816 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6817 }
Daniel Vetterb5518422013-05-03 11:49:48 +02006818 } else {
Daniel Vettere3b95f12013-05-03 11:49:49 +02006819 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6820 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6821 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6822 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02006823 }
6824}
6825
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006826void 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 +02006827{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006828 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306829
6830 if (m_n == M1_N1) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006831 dp_m_n = &crtc_state->dp_m_n;
6832 dp_m2_n2 = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306833 } else if (m_n == M2_N2) {
6834
6835 /*
6836 * M2_N2 registers are not supported. Hence m2_n2 divider value
6837 * needs to be programmed into M1_N1.
6838 */
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006839 dp_m_n = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306840 } else {
6841 DRM_ERROR("Unsupported divider value\n");
6842 return;
6843 }
6844
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006845 if (crtc_state->has_pch_encoder)
6846 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006847 else
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006848 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006849}
6850
Daniel Vetter251ac862015-06-18 10:30:24 +02006851static void vlv_compute_dpll(struct intel_crtc *crtc,
6852 struct intel_crtc_state *pipe_config)
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006853{
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006854 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006855 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006856 if (crtc->pipe != PIPE_A)
6857 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006858
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006859 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006860 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006861 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6862 DPLL_EXT_BUFFER_ENABLE_VLV;
6863
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006864 pipe_config->dpll_hw_state.dpll_md =
6865 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6866}
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006867
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006868static void chv_compute_dpll(struct intel_crtc *crtc,
6869 struct intel_crtc_state *pipe_config)
6870{
6871 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006872 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006873 if (crtc->pipe != PIPE_A)
6874 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6875
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006876 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006877 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006878 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6879
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006880 pipe_config->dpll_hw_state.dpll_md =
6881 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006882}
6883
Ville Syrjäläd288f652014-10-28 13:20:22 +02006884static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006885 const struct intel_crtc_state *pipe_config)
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006886{
Daniel Vetterf47709a2013-03-28 10:42:02 +01006887 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006888 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006889 enum pipe pipe = crtc->pipe;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006890 u32 mdiv;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006891 u32 bestn, bestm1, bestm2, bestp1, bestp2;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006892 u32 coreclk, reg_val;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006893
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006894 /* Enable Refclk */
6895 I915_WRITE(DPLL(pipe),
6896 pipe_config->dpll_hw_state.dpll &
6897 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6898
6899 /* No need to actually set up the DPLL with DSI */
6900 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6901 return;
6902
Ville Syrjäläa5805162015-05-26 20:42:30 +03006903 mutex_lock(&dev_priv->sb_lock);
Daniel Vetter09153002012-12-12 14:06:44 +01006904
Ville Syrjäläd288f652014-10-28 13:20:22 +02006905 bestn = pipe_config->dpll.n;
6906 bestm1 = pipe_config->dpll.m1;
6907 bestm2 = pipe_config->dpll.m2;
6908 bestp1 = pipe_config->dpll.p1;
6909 bestp2 = pipe_config->dpll.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006910
Jesse Barnes89b667f2013-04-18 14:51:36 -07006911 /* See eDP HDMI DPIO driver vbios notes doc */
6912
6913 /* PLL B needs special handling */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006914 if (pipe == PIPE_B)
Chon Ming Lee5e69f972013-09-05 20:41:49 +08006915 vlv_pllb_recal_opamp(dev_priv, pipe);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006916
6917 /* Set up Tx target for periodic Rcomp update */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006918 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006919
6920 /* Disable target IRef on PLL */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006921 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006922 reg_val &= 0x00ffffff;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006923 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006924
6925 /* Disable fast lock */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006926 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006927
6928 /* Set idtafcrecal before PLL is enabled */
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006929 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6930 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6931 mdiv |= ((bestn << DPIO_N_SHIFT));
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006932 mdiv |= (1 << DPIO_K_SHIFT);
Jesse Barnes7df50802013-05-02 10:48:09 -07006933
6934 /*
6935 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6936 * but we don't support that).
6937 * Note: don't use the DAC post divider as it seems unstable.
6938 */
6939 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006940 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006941
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006942 mdiv |= DPIO_ENABLE_CALIBRATION;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006943 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006944
Jesse Barnes89b667f2013-04-18 14:51:36 -07006945 /* Set HBR and RBR LPF coefficients */
Ville Syrjäläd288f652014-10-28 13:20:22 +02006946 if (pipe_config->port_clock == 162000 ||
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02006947 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
6948 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006949 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Ville Syrjälä885b01202013-07-05 19:21:38 +03006950 0x009f0003);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006951 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006952 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07006953 0x00d0000f);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006954
Ville Syrjälä37a56502016-06-22 21:57:04 +03006955 if (intel_crtc_has_dp_encoder(pipe_config)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07006956 /* Use SSC source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006957 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006958 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07006959 0x0df40000);
6960 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006961 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07006962 0x0df70000);
6963 } else { /* HDMI or VGA */
6964 /* Use bend source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006965 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006966 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07006967 0x0df70000);
6968 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006969 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07006970 0x0df40000);
6971 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006972
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006973 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006974 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02006975 if (intel_crtc_has_dp_encoder(pipe_config))
Jesse Barnes89b667f2013-04-18 14:51:36 -07006976 coreclk |= 0x01000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006977 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006978
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006979 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
Ville Syrjäläa5805162015-05-26 20:42:30 +03006980 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006981}
6982
Ville Syrjäläd288f652014-10-28 13:20:22 +02006983static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006984 const struct intel_crtc_state *pipe_config)
Ville Syrjälä1ae0d132014-06-28 02:04:00 +03006985{
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006986 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006987 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006988 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006989 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05306990 u32 loopfilter, tribuf_calcntr;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006991 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05306992 u32 dpio_val;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05306993 int vco;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006994
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006995 /* Enable Refclk and SSC */
6996 I915_WRITE(DPLL(pipe),
6997 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
6998
6999 /* No need to actually set up the DPLL with DSI */
7000 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7001 return;
7002
Ville Syrjäläd288f652014-10-28 13:20:22 +02007003 bestn = pipe_config->dpll.n;
7004 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7005 bestm1 = pipe_config->dpll.m1;
7006 bestm2 = pipe_config->dpll.m2 >> 22;
7007 bestp1 = pipe_config->dpll.p1;
7008 bestp2 = pipe_config->dpll.p2;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307009 vco = pipe_config->dpll.vco;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307010 dpio_val = 0;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307011 loopfilter = 0;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007012
Ville Syrjäläa5805162015-05-26 20:42:30 +03007013 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007014
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007015 /* p1 and p2 divider */
7016 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7017 5 << DPIO_CHV_S1_DIV_SHIFT |
7018 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7019 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7020 1 << DPIO_CHV_K_DIV_SHIFT);
7021
7022 /* Feedback post-divider - m2 */
7023 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7024
7025 /* Feedback refclk divider - n and m1 */
7026 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7027 DPIO_CHV_M1_DIV_BY_2 |
7028 1 << DPIO_CHV_N_DIV_SHIFT);
7029
7030 /* M2 fraction division */
Ville Syrjälä25a25df2015-07-08 23:45:47 +03007031 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007032
7033 /* M2 fraction division enable */
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307034 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7035 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7036 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7037 if (bestm2_frac)
7038 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7039 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007040
Vijay Purushothamande3a0fd2015-03-05 19:32:06 +05307041 /* Program digital lock detect threshold */
7042 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7043 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7044 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7045 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7046 if (!bestm2_frac)
7047 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7048 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7049
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007050 /* Loop filter */
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307051 if (vco == 5400000) {
7052 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7053 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7054 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7055 tribuf_calcntr = 0x9;
7056 } else if (vco <= 6200000) {
7057 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7058 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7059 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7060 tribuf_calcntr = 0x9;
7061 } else if (vco <= 6480000) {
7062 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7063 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7064 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7065 tribuf_calcntr = 0x8;
7066 } else {
7067 /* Not supported. Apply the same limits as in the max case */
7068 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7069 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7070 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7071 tribuf_calcntr = 0;
7072 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007073 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7074
Ville Syrjälä968040b2015-03-11 22:52:08 +02007075 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307076 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7077 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7078 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7079
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007080 /* AFC Recal */
7081 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7082 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7083 DPIO_AFC_RECAL);
7084
Ville Syrjäläa5805162015-05-26 20:42:30 +03007085 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007086}
7087
Ville Syrjäläd288f652014-10-28 13:20:22 +02007088/**
7089 * vlv_force_pll_on - forcibly enable just the PLL
7090 * @dev_priv: i915 private structure
7091 * @pipe: pipe PLL to enable
7092 * @dpll: PLL configuration
7093 *
7094 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7095 * in cases where we need the PLL enabled even when @pipe is not going to
7096 * be enabled.
7097 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007098int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007099 const struct dpll *dpll)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007100{
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02007101 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007102 struct intel_crtc_state *pipe_config;
7103
7104 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7105 if (!pipe_config)
7106 return -ENOMEM;
7107
7108 pipe_config->base.crtc = &crtc->base;
7109 pipe_config->pixel_multiplier = 1;
7110 pipe_config->dpll = *dpll;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007111
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007112 if (IS_CHERRYVIEW(dev_priv)) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007113 chv_compute_dpll(crtc, pipe_config);
7114 chv_prepare_pll(crtc, pipe_config);
7115 chv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007116 } else {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007117 vlv_compute_dpll(crtc, pipe_config);
7118 vlv_prepare_pll(crtc, pipe_config);
7119 vlv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007120 }
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007121
7122 kfree(pipe_config);
7123
7124 return 0;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007125}
7126
7127/**
7128 * vlv_force_pll_off - forcibly disable just the PLL
7129 * @dev_priv: i915 private structure
7130 * @pipe: pipe PLL to disable
7131 *
7132 * Disable the PLL for @pipe. To be used in cases where we need
7133 * the PLL enabled even when @pipe is not going to be enabled.
7134 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007135void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007136{
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007137 if (IS_CHERRYVIEW(dev_priv))
7138 chv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007139 else
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007140 vlv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007141}
7142
Daniel Vetter251ac862015-06-18 10:30:24 +02007143static void i9xx_compute_dpll(struct intel_crtc *crtc,
7144 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007145 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007146{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007147 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007148 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007149 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007150
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007151 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307152
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007153 dpll = DPLL_VGA_MODE_DIS;
7154
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007155 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007156 dpll |= DPLLB_MODE_LVDS;
7157 else
7158 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter6cc5f342013-03-27 00:44:53 +01007159
Jani Nikula73f67aa2016-12-07 22:48:09 +02007160 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7161 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007162 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetter198a037f2013-04-19 11:14:37 +02007163 << SDVO_MULTIPLIER_SHIFT_HIRES;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007164 }
Daniel Vetter198a037f2013-04-19 11:14:37 +02007165
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03007166 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7167 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007168 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vetter198a037f2013-04-19 11:14:37 +02007169
Ville Syrjälä37a56502016-06-22 21:57:04 +03007170 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007171 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007172
7173 /* compute bitmask from p1 value */
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007174 if (IS_PINEVIEW(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007175 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7176 else {
7177 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007178 if (IS_G4X(dev_priv) && reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007179 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7180 }
7181 switch (clock->p2) {
7182 case 5:
7183 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7184 break;
7185 case 7:
7186 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7187 break;
7188 case 10:
7189 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7190 break;
7191 case 14:
7192 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7193 break;
7194 }
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007195 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007196 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7197
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007198 if (crtc_state->sdvo_tv_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007199 dpll |= PLL_REF_INPUT_TVCLKINBC;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007200 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007201 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007202 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7203 else
7204 dpll |= PLL_REF_INPUT_DREFCLK;
7205
7206 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007207 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007208
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007209 if (INTEL_GEN(dev_priv) >= 4) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007210 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02007211 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007212 crtc_state->dpll_hw_state.dpll_md = dpll_md;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007213 }
7214}
7215
Daniel Vetter251ac862015-06-18 10:30:24 +02007216static void i8xx_compute_dpll(struct intel_crtc *crtc,
7217 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007218 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007219{
Daniel Vetterf47709a2013-03-28 10:42:02 +01007220 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007221 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007222 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007223 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007224
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007225 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307226
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007227 dpll = DPLL_VGA_MODE_DIS;
7228
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007229 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007230 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7231 } else {
7232 if (clock->p1 == 2)
7233 dpll |= PLL_P1_DIVIDE_BY_TWO;
7234 else
7235 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7236 if (clock->p2 == 4)
7237 dpll |= PLL_P2_DIVIDE_BY_4;
7238 }
7239
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007240 if (!IS_I830(dev_priv) &&
7241 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007242 dpll |= DPLL_DVO_2X_MODE;
7243
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007244 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007245 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007246 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7247 else
7248 dpll |= PLL_REF_INPUT_DREFCLK;
7249
7250 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007251 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007252}
7253
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007254static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007255{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007256 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7257 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7258 enum pipe pipe = crtc->pipe;
7259 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7260 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007261 uint32_t crtc_vtotal, crtc_vblank_end;
7262 int vsyncshift = 0;
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007263
7264 /* We need to be careful not to changed the adjusted mode, for otherwise
7265 * the hw state checker will get angry at the mismatch. */
7266 crtc_vtotal = adjusted_mode->crtc_vtotal;
7267 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007268
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007269 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007270 /* the chip adds 2 halflines automatically */
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007271 crtc_vtotal -= 1;
7272 crtc_vblank_end -= 1;
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007273
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007274 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007275 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7276 else
7277 vsyncshift = adjusted_mode->crtc_hsync_start -
7278 adjusted_mode->crtc_htotal / 2;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007279 if (vsyncshift < 0)
7280 vsyncshift += adjusted_mode->crtc_htotal;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007281 }
7282
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007283 if (INTEL_GEN(dev_priv) > 3)
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007284 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007285
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007286 I915_WRITE(HTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007287 (adjusted_mode->crtc_hdisplay - 1) |
7288 ((adjusted_mode->crtc_htotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007289 I915_WRITE(HBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007290 (adjusted_mode->crtc_hblank_start - 1) |
7291 ((adjusted_mode->crtc_hblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007292 I915_WRITE(HSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007293 (adjusted_mode->crtc_hsync_start - 1) |
7294 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7295
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007296 I915_WRITE(VTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007297 (adjusted_mode->crtc_vdisplay - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007298 ((crtc_vtotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007299 I915_WRITE(VBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007300 (adjusted_mode->crtc_vblank_start - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007301 ((crtc_vblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007302 I915_WRITE(VSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007303 (adjusted_mode->crtc_vsync_start - 1) |
7304 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7305
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007306 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7307 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7308 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7309 * bits. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01007310 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007311 (pipe == PIPE_B || pipe == PIPE_C))
7312 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7313
Jani Nikulabc58be62016-03-18 17:05:39 +02007314}
7315
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007316static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
Jani Nikulabc58be62016-03-18 17:05:39 +02007317{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007318 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7319 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7320 enum pipe pipe = crtc->pipe;
Jani Nikulabc58be62016-03-18 17:05:39 +02007321
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007322 /* pipesrc controls the size that is scaled from, which should
7323 * always be the user's requested size.
7324 */
7325 I915_WRITE(PIPESRC(pipe),
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007326 ((crtc_state->pipe_src_w - 1) << 16) |
7327 (crtc_state->pipe_src_h - 1));
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007328}
7329
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007330static void intel_get_pipe_timings(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007331 struct intel_crtc_state *pipe_config)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007332{
7333 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007334 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007335 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7336 uint32_t tmp;
7337
7338 tmp = I915_READ(HTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007339 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7340 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007341 tmp = I915_READ(HBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007342 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7343 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007344 tmp = I915_READ(HSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007345 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7346 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007347
7348 tmp = I915_READ(VTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007349 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7350 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007351 tmp = I915_READ(VBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007352 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7353 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007354 tmp = I915_READ(VSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007355 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7356 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007357
7358 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007359 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7360 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7361 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007362 }
Jani Nikulabc58be62016-03-18 17:05:39 +02007363}
7364
7365static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7366 struct intel_crtc_state *pipe_config)
7367{
7368 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007369 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulabc58be62016-03-18 17:05:39 +02007370 u32 tmp;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007371
7372 tmp = I915_READ(PIPESRC(crtc->pipe));
Ville Syrjälä37327ab2013-09-04 18:25:28 +03007373 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7374 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7375
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007376 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7377 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007378}
7379
Daniel Vetterf6a83282014-02-11 15:28:57 -08007380void intel_mode_from_pipe_config(struct drm_display_mode *mode,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007381 struct intel_crtc_state *pipe_config)
Jesse Barnesbabea612013-06-26 18:57:38 +03007382{
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007383 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7384 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7385 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7386 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007387
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007388 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7389 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7390 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7391 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007392
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007393 mode->flags = pipe_config->base.adjusted_mode.flags;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007394 mode->type = DRM_MODE_TYPE_DRIVER;
Jesse Barnesbabea612013-06-26 18:57:38 +03007395
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007396 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007397
7398 mode->hsync = drm_mode_hsync(mode);
7399 mode->vrefresh = drm_mode_vrefresh(mode);
7400 drm_mode_set_name(mode);
Jesse Barnesbabea612013-06-26 18:57:38 +03007401}
7402
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007403static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
Daniel Vetter84b046f2013-02-19 18:48:54 +01007404{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007405 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7406 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter84b046f2013-02-19 18:48:54 +01007407 uint32_t pipeconf;
7408
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007409 pipeconf = 0;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007410
Ville Syrjäläe56134b2017-06-01 17:36:19 +03007411 /* we keep both pipes enabled on 830 */
7412 if (IS_I830(dev_priv))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007413 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
Daniel Vetter67c72a12013-09-24 11:46:14 +02007414
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007415 if (crtc_state->double_wide)
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03007416 pipeconf |= PIPECONF_DOUBLE_WIDE;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007417
Daniel Vetterff9ce462013-04-24 14:57:17 +02007418 /* only g4x and later have fancy bpc/dither controls */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007419 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7420 IS_CHERRYVIEW(dev_priv)) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007421 /* Bspec claims that we can't use dithering for 30bpp pipes. */
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007422 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
Daniel Vetterff9ce462013-04-24 14:57:17 +02007423 pipeconf |= PIPECONF_DITHER_EN |
7424 PIPECONF_DITHER_TYPE_SP;
7425
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007426 switch (crtc_state->pipe_bpp) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007427 case 18:
7428 pipeconf |= PIPECONF_6BPC;
7429 break;
7430 case 24:
7431 pipeconf |= PIPECONF_8BPC;
7432 break;
7433 case 30:
7434 pipeconf |= PIPECONF_10BPC;
7435 break;
7436 default:
7437 /* Case prevented by intel_choose_pipe_bpp_dither. */
7438 BUG();
Daniel Vetter84b046f2013-02-19 18:48:54 +01007439 }
7440 }
7441
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007442 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007443 if (INTEL_GEN(dev_priv) < 4 ||
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007444 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjäläefc2cff2014-03-28 23:29:31 +02007445 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7446 else
7447 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7448 } else
Daniel Vetter84b046f2013-02-19 18:48:54 +01007449 pipeconf |= PIPECONF_PROGRESSIVE;
7450
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007451 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007452 crtc_state->limited_color_range)
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007453 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä9c8e09b2013-04-02 16:10:09 +03007454
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007455 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7456 POSTING_READ(PIPECONF(crtc->pipe));
Daniel Vetter84b046f2013-02-19 18:48:54 +01007457}
7458
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007459static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7460 struct intel_crtc_state *crtc_state)
7461{
7462 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007463 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007464 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007465 int refclk = 48000;
7466
7467 memset(&crtc_state->dpll_hw_state, 0,
7468 sizeof(crtc_state->dpll_hw_state));
7469
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007470 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007471 if (intel_panel_use_ssc(dev_priv)) {
7472 refclk = dev_priv->vbt.lvds_ssc_freq;
7473 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7474 }
7475
7476 limit = &intel_limits_i8xx_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007477 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007478 limit = &intel_limits_i8xx_dvo;
7479 } else {
7480 limit = &intel_limits_i8xx_dac;
7481 }
7482
7483 if (!crtc_state->clock_set &&
7484 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7485 refclk, NULL, &crtc_state->dpll)) {
7486 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7487 return -EINVAL;
7488 }
7489
7490 i8xx_compute_dpll(crtc, crtc_state, NULL);
7491
7492 return 0;
7493}
7494
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007495static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7496 struct intel_crtc_state *crtc_state)
7497{
7498 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007499 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007500 const struct intel_limit *limit;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007501 int refclk = 96000;
7502
7503 memset(&crtc_state->dpll_hw_state, 0,
7504 sizeof(crtc_state->dpll_hw_state));
7505
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007506 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007507 if (intel_panel_use_ssc(dev_priv)) {
7508 refclk = dev_priv->vbt.lvds_ssc_freq;
7509 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7510 }
7511
7512 if (intel_is_dual_link_lvds(dev))
7513 limit = &intel_limits_g4x_dual_channel_lvds;
7514 else
7515 limit = &intel_limits_g4x_single_channel_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007516 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7517 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007518 limit = &intel_limits_g4x_hdmi;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007519 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007520 limit = &intel_limits_g4x_sdvo;
7521 } else {
7522 /* The option is for other outputs */
7523 limit = &intel_limits_i9xx_sdvo;
7524 }
7525
7526 if (!crtc_state->clock_set &&
7527 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7528 refclk, NULL, &crtc_state->dpll)) {
7529 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7530 return -EINVAL;
7531 }
7532
7533 i9xx_compute_dpll(crtc, crtc_state, NULL);
7534
7535 return 0;
7536}
7537
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007538static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7539 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08007540{
Ander Conselvan de Oliveirac7653192014-10-20 13:46:44 +03007541 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007542 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007543 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007544 int refclk = 96000;
Jesse Barnes79e53942008-11-07 14:24:08 -08007545
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03007546 memset(&crtc_state->dpll_hw_state, 0,
7547 sizeof(crtc_state->dpll_hw_state));
7548
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007549 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007550 if (intel_panel_use_ssc(dev_priv)) {
7551 refclk = dev_priv->vbt.lvds_ssc_freq;
7552 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7553 }
Jesse Barnes79e53942008-11-07 14:24:08 -08007554
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007555 limit = &intel_limits_pineview_lvds;
7556 } else {
7557 limit = &intel_limits_pineview_sdvo;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007558 }
Jani Nikulaf2335332013-09-13 11:03:09 +03007559
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007560 if (!crtc_state->clock_set &&
7561 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7562 refclk, NULL, &crtc_state->dpll)) {
7563 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7564 return -EINVAL;
7565 }
7566
7567 i9xx_compute_dpll(crtc, crtc_state, NULL);
7568
7569 return 0;
7570}
7571
7572static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7573 struct intel_crtc_state *crtc_state)
7574{
7575 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007576 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007577 const struct intel_limit *limit;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007578 int refclk = 96000;
7579
7580 memset(&crtc_state->dpll_hw_state, 0,
7581 sizeof(crtc_state->dpll_hw_state));
7582
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007583 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007584 if (intel_panel_use_ssc(dev_priv)) {
7585 refclk = dev_priv->vbt.lvds_ssc_freq;
7586 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
Jani Nikulae9fd1c02013-08-27 15:12:23 +03007587 }
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007588
7589 limit = &intel_limits_i9xx_lvds;
7590 } else {
7591 limit = &intel_limits_i9xx_sdvo;
7592 }
7593
7594 if (!crtc_state->clock_set &&
7595 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7596 refclk, NULL, &crtc_state->dpll)) {
7597 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7598 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01007599 }
Eric Anholtf564048e2011-03-30 13:01:02 -07007600
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007601 i9xx_compute_dpll(crtc, crtc_state, NULL);
Eric Anholtf564048e2011-03-30 13:01:02 -07007602
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02007603 return 0;
Eric Anholtf564048e2011-03-30 13:01:02 -07007604}
7605
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007606static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7607 struct intel_crtc_state *crtc_state)
7608{
7609 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007610 const struct intel_limit *limit = &intel_limits_chv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007611
7612 memset(&crtc_state->dpll_hw_state, 0,
7613 sizeof(crtc_state->dpll_hw_state));
7614
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007615 if (!crtc_state->clock_set &&
7616 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7617 refclk, NULL, &crtc_state->dpll)) {
7618 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7619 return -EINVAL;
7620 }
7621
7622 chv_compute_dpll(crtc, crtc_state);
7623
7624 return 0;
7625}
7626
7627static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7628 struct intel_crtc_state *crtc_state)
7629{
7630 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007631 const struct intel_limit *limit = &intel_limits_vlv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007632
7633 memset(&crtc_state->dpll_hw_state, 0,
7634 sizeof(crtc_state->dpll_hw_state));
7635
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007636 if (!crtc_state->clock_set &&
7637 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7638 refclk, NULL, &crtc_state->dpll)) {
7639 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7640 return -EINVAL;
7641 }
7642
7643 vlv_compute_dpll(crtc, crtc_state);
7644
7645 return 0;
7646}
7647
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007648static void i9xx_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007649 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007650{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007651 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007652 uint32_t tmp;
7653
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007654 if (INTEL_GEN(dev_priv) <= 3 &&
7655 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
Ville Syrjälädc9e7dec2014-01-10 14:06:45 +02007656 return;
7657
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007658 tmp = I915_READ(PFIT_CONTROL);
Daniel Vetter06922822013-07-11 13:35:40 +02007659 if (!(tmp & PFIT_ENABLE))
7660 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007661
Daniel Vetter06922822013-07-11 13:35:40 +02007662 /* Check whether the pfit is attached to our pipe. */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007663 if (INTEL_GEN(dev_priv) < 4) {
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007664 if (crtc->pipe != PIPE_B)
7665 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007666 } else {
7667 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7668 return;
7669 }
7670
Daniel Vetter06922822013-07-11 13:35:40 +02007671 pipe_config->gmch_pfit.control = tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007672 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007673}
7674
Jesse Barnesacbec812013-09-20 11:29:32 -07007675static void vlv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007676 struct intel_crtc_state *pipe_config)
Jesse Barnesacbec812013-09-20 11:29:32 -07007677{
7678 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007679 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesacbec812013-09-20 11:29:32 -07007680 int pipe = pipe_config->cpu_transcoder;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007681 struct dpll clock;
Jesse Barnesacbec812013-09-20 11:29:32 -07007682 u32 mdiv;
Chris Wilson662c6ec2013-09-25 14:24:01 -07007683 int refclk = 100000;
Jesse Barnesacbec812013-09-20 11:29:32 -07007684
Ville Syrjäläb5219732016-03-15 16:40:01 +02007685 /* In case of DSI, DPLL will not be used */
7686 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
Shobhit Kumarf573de52014-07-30 20:32:37 +05307687 return;
7688
Ville Syrjäläa5805162015-05-26 20:42:30 +03007689 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007690 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007691 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007692
7693 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7694 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7695 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7696 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7697 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7698
Imre Deakdccbea32015-06-22 23:35:51 +03007699 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007700}
7701
Damien Lespiau5724dbd2015-01-20 12:51:52 +00007702static void
7703i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7704 struct intel_initial_plane_config *plane_config)
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007705{
7706 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007707 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007708 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7709 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007710 enum pipe pipe;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007711 u32 val, base, offset;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007712 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00007713 unsigned int aligned_height;
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007714 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00007715 struct intel_framebuffer *intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007716
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007717 if (!plane->get_hw_state(plane, &pipe))
Damien Lespiau42a7b082015-02-05 19:35:13 +00007718 return;
7719
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007720 WARN_ON(pipe != crtc->pipe);
7721
Damien Lespiaud9806c92015-01-21 14:07:19 +00007722 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00007723 if (!intel_fb) {
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007724 DRM_DEBUG_KMS("failed to alloc fb\n");
7725 return;
7726 }
7727
Damien Lespiau1b842c82015-01-21 13:50:54 +00007728 fb = &intel_fb->base;
7729
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02007730 fb->dev = dev;
7731
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02007732 val = I915_READ(DSPCNTR(i9xx_plane));
7733
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007734 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter18c52472015-02-10 17:16:09 +00007735 if (val & DISPPLANE_TILED) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007736 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02007737 fb->modifier = I915_FORMAT_MOD_X_TILED;
Daniel Vetter18c52472015-02-10 17:16:09 +00007738 }
7739 }
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007740
7741 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
Damien Lespiaub35d63f2015-01-20 12:51:50 +00007742 fourcc = i9xx_format_to_fourcc(pixel_format);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02007743 fb->format = drm_format_info(fourcc);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007744
Ville Syrjälä81894b22017-11-17 21:19:13 +02007745 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7746 offset = I915_READ(DSPOFFSET(i9xx_plane));
7747 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7748 } else if (INTEL_GEN(dev_priv) >= 4) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007749 if (plane_config->tiling)
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007750 offset = I915_READ(DSPTILEOFF(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007751 else
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007752 offset = I915_READ(DSPLINOFF(i9xx_plane));
7753 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007754 } else {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007755 base = I915_READ(DSPADDR(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007756 }
7757 plane_config->base = base;
7758
7759 val = I915_READ(PIPESRC(pipe));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007760 fb->width = ((val >> 16) & 0xfff) + 1;
7761 fb->height = ((val >> 0) & 0xfff) + 1;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007762
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007763 val = I915_READ(DSPSTRIDE(i9xx_plane));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007764 fb->pitches[0] = val & 0xffffffc0;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007765
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02007766 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007767
Daniel Vetterf37b5c22015-02-10 23:12:27 +01007768 plane_config->size = fb->pitches[0] * aligned_height;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007769
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007770 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7771 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02007772 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiau2844a922015-01-20 12:51:48 +00007773 plane_config->size);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007774
Damien Lespiau2d140302015-02-05 17:22:18 +00007775 plane_config->fb = intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007776}
7777
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007778static void chv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007779 struct intel_crtc_state *pipe_config)
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007780{
7781 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007782 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007783 int pipe = pipe_config->cpu_transcoder;
7784 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007785 struct dpll clock;
Imre Deak0d7b6b12015-07-02 14:29:58 +03007786 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007787 int refclk = 100000;
7788
Ville Syrjäläb5219732016-03-15 16:40:01 +02007789 /* In case of DSI, DPLL will not be used */
7790 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7791 return;
7792
Ville Syrjäläa5805162015-05-26 20:42:30 +03007793 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007794 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7795 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7796 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7797 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
Imre Deak0d7b6b12015-07-02 14:29:58 +03007798 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007799 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007800
7801 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
Imre Deak0d7b6b12015-07-02 14:29:58 +03007802 clock.m2 = (pll_dw0 & 0xff) << 22;
7803 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7804 clock.m2 |= pll_dw2 & 0x3fffff;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007805 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7806 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7807 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7808
Imre Deakdccbea32015-06-22 23:35:51 +03007809 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007810}
7811
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307812static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
7813 struct intel_crtc_state *pipe_config)
7814{
7815 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7816 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
7817
Shashank Sharma668b6c12018-10-12 11:53:14 +05307818 pipe_config->lspcon_downsampling = false;
7819
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307820 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
7821 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
7822
7823 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
7824 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
7825 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
7826
7827 if (ycbcr420_enabled) {
7828 /* We support 4:2:0 in full blend mode only */
7829 if (!blend)
7830 output = INTEL_OUTPUT_FORMAT_INVALID;
7831 else if (!(IS_GEMINILAKE(dev_priv) ||
7832 INTEL_GEN(dev_priv) >= 10))
7833 output = INTEL_OUTPUT_FORMAT_INVALID;
7834 else
7835 output = INTEL_OUTPUT_FORMAT_YCBCR420;
Shashank Sharma8c79f842018-10-12 11:53:09 +05307836 } else {
Shashank Sharma668b6c12018-10-12 11:53:14 +05307837 /*
7838 * Currently there is no interface defined to
7839 * check user preference between RGB/YCBCR444
7840 * or YCBCR420. So the only possible case for
7841 * YCBCR444 usage is driving YCBCR420 output
7842 * with LSPCON, when pipe is configured for
7843 * YCBCR444 output and LSPCON takes care of
7844 * downsampling it.
7845 */
7846 pipe_config->lspcon_downsampling = true;
Shashank Sharma8c79f842018-10-12 11:53:09 +05307847 output = INTEL_OUTPUT_FORMAT_YCBCR444;
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307848 }
7849 }
7850 }
7851
7852 pipe_config->output_format = output;
7853}
7854
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007855static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007856 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007857{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007858 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02007859 enum intel_display_power_domain power_domain;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007860 uint32_t tmp;
Imre Deak17290502016-02-12 18:55:11 +02007861 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007862
Imre Deak17290502016-02-12 18:55:11 +02007863 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7864 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02007865 return false;
7866
Shashank Sharmad9facae2018-10-12 11:53:07 +05307867 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02007868 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02007869 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02007870
Imre Deak17290502016-02-12 18:55:11 +02007871 ret = false;
7872
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007873 tmp = I915_READ(PIPECONF(crtc->pipe));
7874 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02007875 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007876
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007877 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7878 IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä42571ae2013-09-06 23:29:00 +03007879 switch (tmp & PIPECONF_BPC_MASK) {
7880 case PIPECONF_6BPC:
7881 pipe_config->pipe_bpp = 18;
7882 break;
7883 case PIPECONF_8BPC:
7884 pipe_config->pipe_bpp = 24;
7885 break;
7886 case PIPECONF_10BPC:
7887 pipe_config->pipe_bpp = 30;
7888 break;
7889 default:
7890 break;
7891 }
7892 }
7893
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007894 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08007895 (tmp & PIPECONF_COLOR_RANGE_SELECT))
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02007896 pipe_config->limited_color_range = true;
7897
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007898 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä282740f2013-09-04 18:30:03 +03007899 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7900
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007901 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02007902 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007903
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007904 i9xx_get_pfit_config(crtc, pipe_config);
7905
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007906 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjäläc2317752016-03-15 16:39:56 +02007907 /* No way to read it out on pipes B and C */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007908 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
Ville Syrjäläc2317752016-03-15 16:39:56 +02007909 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7910 else
7911 tmp = I915_READ(DPLL_MD(crtc->pipe));
Daniel Vetter6c49f242013-06-06 12:45:25 +02007912 pipe_config->pixel_multiplier =
7913 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7914 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007915 pipe_config->dpll_hw_state.dpll_md = tmp;
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007916 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
Jani Nikula73f67aa2016-12-07 22:48:09 +02007917 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Daniel Vetter6c49f242013-06-06 12:45:25 +02007918 tmp = I915_READ(DPLL(crtc->pipe));
7919 pipe_config->pixel_multiplier =
7920 ((tmp & SDVO_MULTIPLIER_MASK)
7921 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7922 } else {
7923 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7924 * port and will be fixed up in the encoder->get_config
7925 * function. */
7926 pipe_config->pixel_multiplier = 1;
7927 }
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007928 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007929 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03007930 /*
7931 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7932 * on 830. Filter it out here so that we don't
7933 * report errors due to that.
7934 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007935 if (IS_I830(dev_priv))
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03007936 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
7937
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007938 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
7939 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
Ville Syrjälä165e9012013-06-26 17:44:15 +03007940 } else {
7941 /* Mask out read-only status bits. */
7942 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7943 DPLL_PORTC_READY_MASK |
7944 DPLL_PORTB_READY_MASK);
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007945 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02007946
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007947 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007948 chv_crtc_clock_get(crtc, pipe_config);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01007949 else if (IS_VALLEYVIEW(dev_priv))
Jesse Barnesacbec812013-09-20 11:29:32 -07007950 vlv_crtc_clock_get(crtc, pipe_config);
7951 else
7952 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +03007953
Ville Syrjälä0f646142015-08-26 19:39:18 +03007954 /*
7955 * Normally the dotclock is filled in by the encoder .get_config()
7956 * but in case the pipe is enabled w/o any ports we need a sane
7957 * default.
7958 */
7959 pipe_config->base.adjusted_mode.crtc_clock =
7960 pipe_config->port_clock / pipe_config->pixel_multiplier;
7961
Imre Deak17290502016-02-12 18:55:11 +02007962 ret = true;
7963
7964out:
7965 intel_display_power_put(dev_priv, power_domain);
7966
7967 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007968}
7969
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02007970static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
Jesse Barnes13d83a62011-08-03 12:59:20 -07007971{
Jesse Barnes13d83a62011-08-03 12:59:20 -07007972 struct intel_encoder *encoder;
Lyude1c1a24d2016-06-14 11:04:09 -04007973 int i;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07007974 u32 val, final;
Jesse Barnes13d83a62011-08-03 12:59:20 -07007975 bool has_lvds = false;
Keith Packard199e5d72011-09-22 12:01:57 -07007976 bool has_cpu_edp = false;
Keith Packard199e5d72011-09-22 12:01:57 -07007977 bool has_panel = false;
Keith Packard99eb6a02011-09-26 14:29:12 -07007978 bool has_ck505 = false;
7979 bool can_ssc = false;
Lyude1c1a24d2016-06-14 11:04:09 -04007980 bool using_ssc_source = false;
Jesse Barnes13d83a62011-08-03 12:59:20 -07007981
7982 /* We need to take the global config into account */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02007983 for_each_intel_encoder(&dev_priv->drm, encoder) {
Keith Packard199e5d72011-09-22 12:01:57 -07007984 switch (encoder->type) {
7985 case INTEL_OUTPUT_LVDS:
7986 has_panel = true;
7987 has_lvds = true;
7988 break;
7989 case INTEL_OUTPUT_EDP:
7990 has_panel = true;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02007991 if (encoder->port == PORT_A)
Keith Packard199e5d72011-09-22 12:01:57 -07007992 has_cpu_edp = true;
7993 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02007994 default:
7995 break;
Jesse Barnes13d83a62011-08-03 12:59:20 -07007996 }
7997 }
7998
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01007999 if (HAS_PCH_IBX(dev_priv)) {
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03008000 has_ck505 = dev_priv->vbt.display_clock_mode;
Keith Packard99eb6a02011-09-26 14:29:12 -07008001 can_ssc = has_ck505;
8002 } else {
8003 has_ck505 = false;
8004 can_ssc = true;
8005 }
8006
Lyude1c1a24d2016-06-14 11:04:09 -04008007 /* Check if any DPLLs are using the SSC source */
8008 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8009 u32 temp = I915_READ(PCH_DPLL(i));
8010
8011 if (!(temp & DPLL_VCO_ENABLE))
8012 continue;
8013
8014 if ((temp & PLL_REF_INPUT_MASK) ==
8015 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8016 using_ssc_source = true;
8017 break;
8018 }
8019 }
8020
8021 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8022 has_panel, has_lvds, has_ck505, using_ssc_source);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008023
8024 /* Ironlake: try to setup display ref clock before DPLL
8025 * enabling. This is only under driver's control after
8026 * PCH B stepping, previous chipset stepping should be
8027 * ignoring this setting.
8028 */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008029 val = I915_READ(PCH_DREF_CONTROL);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008030
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008031 /* As we must carefully and slowly disable/enable each source in turn,
8032 * compute the final state we want first and check if we need to
8033 * make any changes at all.
8034 */
8035 final = val;
8036 final &= ~DREF_NONSPREAD_SOURCE_MASK;
Keith Packard99eb6a02011-09-26 14:29:12 -07008037 if (has_ck505)
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008038 final |= DREF_NONSPREAD_CK505_ENABLE;
Keith Packard99eb6a02011-09-26 14:29:12 -07008039 else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008040 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8041
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008042 final &= ~DREF_SSC_SOURCE_MASK;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008043 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008044 final &= ~DREF_SSC1_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008045
Keith Packard199e5d72011-09-22 12:01:57 -07008046 if (has_panel) {
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008047 final |= DREF_SSC_SOURCE_ENABLE;
8048
8049 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8050 final |= DREF_SSC1_ENABLE;
8051
8052 if (has_cpu_edp) {
8053 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8054 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8055 else
8056 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8057 } else
8058 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Lyude1c1a24d2016-06-14 11:04:09 -04008059 } else if (using_ssc_source) {
8060 final |= DREF_SSC_SOURCE_ENABLE;
8061 final |= DREF_SSC1_ENABLE;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008062 }
8063
8064 if (final == val)
8065 return;
8066
8067 /* Always enable nonspread source */
8068 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8069
8070 if (has_ck505)
8071 val |= DREF_NONSPREAD_CK505_ENABLE;
8072 else
8073 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8074
8075 if (has_panel) {
8076 val &= ~DREF_SSC_SOURCE_MASK;
8077 val |= DREF_SSC_SOURCE_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008078
Keith Packard199e5d72011-09-22 12:01:57 -07008079 /* SSC must be turned on before enabling the CPU output */
Keith Packard99eb6a02011-09-26 14:29:12 -07008080 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008081 DRM_DEBUG_KMS("Using SSC on panel\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008082 val |= DREF_SSC1_ENABLE;
Daniel Vettere77166b2012-03-30 22:14:05 +02008083 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008084 val &= ~DREF_SSC1_ENABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008085
8086 /* Get SSC going before enabling the outputs */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008087 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008088 POSTING_READ(PCH_DREF_CONTROL);
8089 udelay(200);
8090
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008091 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008092
8093 /* Enable CPU source on CPU attached eDP */
Keith Packard199e5d72011-09-22 12:01:57 -07008094 if (has_cpu_edp) {
Keith Packard99eb6a02011-09-26 14:29:12 -07008095 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008096 DRM_DEBUG_KMS("Using SSC on eDP\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008097 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
Robin Schroereba905b2014-05-18 02:24:50 +02008098 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008099 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
Keith Packard199e5d72011-09-22 12:01:57 -07008100 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008101 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008102
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008103 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008104 POSTING_READ(PCH_DREF_CONTROL);
8105 udelay(200);
8106 } else {
Lyude1c1a24d2016-06-14 11:04:09 -04008107 DRM_DEBUG_KMS("Disabling CPU source output\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008108
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008109 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Keith Packard199e5d72011-09-22 12:01:57 -07008110
8111 /* Turn off CPU output */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008112 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008113
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008114 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008115 POSTING_READ(PCH_DREF_CONTROL);
8116 udelay(200);
8117
Lyude1c1a24d2016-06-14 11:04:09 -04008118 if (!using_ssc_source) {
8119 DRM_DEBUG_KMS("Disabling SSC source\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008120
Lyude1c1a24d2016-06-14 11:04:09 -04008121 /* Turn off the SSC source */
8122 val &= ~DREF_SSC_SOURCE_MASK;
8123 val |= DREF_SSC_SOURCE_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008124
Lyude1c1a24d2016-06-14 11:04:09 -04008125 /* Turn off SSC1 */
8126 val &= ~DREF_SSC1_ENABLE;
8127
8128 I915_WRITE(PCH_DREF_CONTROL, val);
8129 POSTING_READ(PCH_DREF_CONTROL);
8130 udelay(200);
8131 }
Jesse Barnes13d83a62011-08-03 12:59:20 -07008132 }
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008133
8134 BUG_ON(val != final);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008135}
8136
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008137static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008138{
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008139 uint32_t tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008140
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008141 tmp = I915_READ(SOUTH_CHICKEN2);
8142 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8143 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008144
Imre Deakcf3598c2016-06-28 13:37:31 +03008145 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8146 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008147 DRM_ERROR("FDI mPHY reset assert timeout\n");
Paulo Zanonidde86e22012-12-01 12:04:25 -02008148
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008149 tmp = I915_READ(SOUTH_CHICKEN2);
8150 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8151 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008152
Imre Deakcf3598c2016-06-28 13:37:31 +03008153 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8154 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008155 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008156}
8157
8158/* WaMPhyProgramming:hsw */
8159static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8160{
8161 uint32_t tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008162
8163 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8164 tmp &= ~(0xFF << 24);
8165 tmp |= (0x12 << 24);
8166 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8167
Paulo Zanonidde86e22012-12-01 12:04:25 -02008168 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8169 tmp |= (1 << 11);
8170 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8171
8172 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8173 tmp |= (1 << 11);
8174 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8175
Paulo Zanonidde86e22012-12-01 12:04:25 -02008176 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8177 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8178 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8179
8180 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8181 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8182 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8183
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008184 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8185 tmp &= ~(7 << 13);
8186 tmp |= (5 << 13);
8187 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008188
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008189 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8190 tmp &= ~(7 << 13);
8191 tmp |= (5 << 13);
8192 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008193
8194 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8195 tmp &= ~0xFF;
8196 tmp |= 0x1C;
8197 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8198
8199 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8200 tmp &= ~0xFF;
8201 tmp |= 0x1C;
8202 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8203
8204 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8205 tmp &= ~(0xFF << 16);
8206 tmp |= (0x1C << 16);
8207 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8208
8209 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8210 tmp &= ~(0xFF << 16);
8211 tmp |= (0x1C << 16);
8212 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8213
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008214 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8215 tmp |= (1 << 27);
8216 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008217
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008218 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8219 tmp |= (1 << 27);
8220 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008221
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008222 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8223 tmp &= ~(0xF << 28);
8224 tmp |= (4 << 28);
8225 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008226
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008227 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8228 tmp &= ~(0xF << 28);
8229 tmp |= (4 << 28);
8230 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008231}
8232
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008233/* Implements 3 different sequences from BSpec chapter "Display iCLK
8234 * Programming" based on the parameters passed:
8235 * - Sequence to enable CLKOUT_DP
8236 * - Sequence to enable CLKOUT_DP without spread
8237 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8238 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008239static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8240 bool with_spread, bool with_fdi)
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008241{
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008242 uint32_t reg, tmp;
8243
8244 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8245 with_spread = true;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008246 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8247 with_fdi, "LP PCH doesn't have FDI\n"))
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008248 with_fdi = false;
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008249
Ville Syrjäläa5805162015-05-26 20:42:30 +03008250 mutex_lock(&dev_priv->sb_lock);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008251
8252 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8253 tmp &= ~SBI_SSCCTL_DISABLE;
8254 tmp |= SBI_SSCCTL_PATHALT;
8255 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8256
8257 udelay(24);
8258
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008259 if (with_spread) {
8260 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8261 tmp &= ~SBI_SSCCTL_PATHALT;
8262 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008263
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008264 if (with_fdi) {
8265 lpt_reset_fdi_mphy(dev_priv);
8266 lpt_program_fdi_mphy(dev_priv);
8267 }
8268 }
Paulo Zanonidde86e22012-12-01 12:04:25 -02008269
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008270 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008271 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8272 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8273 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
Daniel Vetterc00db242013-01-22 15:33:27 +01008274
Ville Syrjäläa5805162015-05-26 20:42:30 +03008275 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008276}
8277
Paulo Zanoni47701c32013-07-23 11:19:25 -03008278/* Sequence to disable CLKOUT_DP */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008279static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
Paulo Zanoni47701c32013-07-23 11:19:25 -03008280{
Paulo Zanoni47701c32013-07-23 11:19:25 -03008281 uint32_t reg, tmp;
8282
Ville Syrjäläa5805162015-05-26 20:42:30 +03008283 mutex_lock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008284
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008285 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni47701c32013-07-23 11:19:25 -03008286 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8287 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8288 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8289
8290 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8291 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8292 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8293 tmp |= SBI_SSCCTL_PATHALT;
8294 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8295 udelay(32);
8296 }
8297 tmp |= SBI_SSCCTL_DISABLE;
8298 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8299 }
8300
Ville Syrjäläa5805162015-05-26 20:42:30 +03008301 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008302}
8303
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008304#define BEND_IDX(steps) ((50 + (steps)) / 5)
8305
8306static const uint16_t sscdivintphase[] = {
8307 [BEND_IDX( 50)] = 0x3B23,
8308 [BEND_IDX( 45)] = 0x3B23,
8309 [BEND_IDX( 40)] = 0x3C23,
8310 [BEND_IDX( 35)] = 0x3C23,
8311 [BEND_IDX( 30)] = 0x3D23,
8312 [BEND_IDX( 25)] = 0x3D23,
8313 [BEND_IDX( 20)] = 0x3E23,
8314 [BEND_IDX( 15)] = 0x3E23,
8315 [BEND_IDX( 10)] = 0x3F23,
8316 [BEND_IDX( 5)] = 0x3F23,
8317 [BEND_IDX( 0)] = 0x0025,
8318 [BEND_IDX( -5)] = 0x0025,
8319 [BEND_IDX(-10)] = 0x0125,
8320 [BEND_IDX(-15)] = 0x0125,
8321 [BEND_IDX(-20)] = 0x0225,
8322 [BEND_IDX(-25)] = 0x0225,
8323 [BEND_IDX(-30)] = 0x0325,
8324 [BEND_IDX(-35)] = 0x0325,
8325 [BEND_IDX(-40)] = 0x0425,
8326 [BEND_IDX(-45)] = 0x0425,
8327 [BEND_IDX(-50)] = 0x0525,
8328};
8329
8330/*
8331 * Bend CLKOUT_DP
8332 * steps -50 to 50 inclusive, in steps of 5
8333 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8334 * change in clock period = -(steps / 10) * 5.787 ps
8335 */
8336static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8337{
8338 uint32_t tmp;
8339 int idx = BEND_IDX(steps);
8340
8341 if (WARN_ON(steps % 5 != 0))
8342 return;
8343
8344 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8345 return;
8346
8347 mutex_lock(&dev_priv->sb_lock);
8348
8349 if (steps % 10 != 0)
8350 tmp = 0xAAAAAAAB;
8351 else
8352 tmp = 0x00000000;
8353 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8354
8355 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8356 tmp &= 0xffff0000;
8357 tmp |= sscdivintphase[idx];
8358 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8359
8360 mutex_unlock(&dev_priv->sb_lock);
8361}
8362
8363#undef BEND_IDX
8364
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008365static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008366{
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008367 struct intel_encoder *encoder;
8368 bool has_vga = false;
8369
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008370 for_each_intel_encoder(&dev_priv->drm, encoder) {
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008371 switch (encoder->type) {
8372 case INTEL_OUTPUT_ANALOG:
8373 has_vga = true;
8374 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008375 default:
8376 break;
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008377 }
8378 }
8379
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008380 if (has_vga) {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008381 lpt_bend_clkout_dp(dev_priv, 0);
8382 lpt_enable_clkout_dp(dev_priv, true, true);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008383 } else {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008384 lpt_disable_clkout_dp(dev_priv);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008385 }
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008386}
8387
Paulo Zanonidde86e22012-12-01 12:04:25 -02008388/*
8389 * Initialize reference clocks when the driver loads
8390 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008391void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008392{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008393 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008394 ironlake_init_pch_refclk(dev_priv);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008395 else if (HAS_PCH_LPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008396 lpt_init_pch_refclk(dev_priv);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008397}
8398
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008399static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanonic8203562012-09-12 10:06:29 -03008400{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008401 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8402 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8403 enum pipe pipe = crtc->pipe;
Paulo Zanonic8203562012-09-12 10:06:29 -03008404 uint32_t val;
8405
Daniel Vetter78114072013-06-13 00:54:57 +02008406 val = 0;
Paulo Zanonic8203562012-09-12 10:06:29 -03008407
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008408 switch (crtc_state->pipe_bpp) {
Paulo Zanonic8203562012-09-12 10:06:29 -03008409 case 18:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008410 val |= PIPECONF_6BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008411 break;
8412 case 24:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008413 val |= PIPECONF_8BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008414 break;
8415 case 30:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008416 val |= PIPECONF_10BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008417 break;
8418 case 36:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008419 val |= PIPECONF_12BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008420 break;
8421 default:
Paulo Zanonicc769b62012-09-20 18:36:03 -03008422 /* Case prevented by intel_choose_pipe_bpp_dither. */
8423 BUG();
Paulo Zanonic8203562012-09-12 10:06:29 -03008424 }
8425
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008426 if (crtc_state->dither)
Paulo Zanonic8203562012-09-12 10:06:29 -03008427 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8428
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008429 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanonic8203562012-09-12 10:06:29 -03008430 val |= PIPECONF_INTERLACED_ILK;
8431 else
8432 val |= PIPECONF_PROGRESSIVE;
8433
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008434 if (crtc_state->limited_color_range)
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008435 val |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008436
Paulo Zanonic8203562012-09-12 10:06:29 -03008437 I915_WRITE(PIPECONF(pipe), val);
8438 POSTING_READ(PIPECONF(pipe));
8439}
8440
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008441static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008442{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008443 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8444 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8445 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Jani Nikula391bf042016-03-18 17:05:40 +02008446 u32 val = 0;
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008447
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008448 if (IS_HASWELL(dev_priv) && crtc_state->dither)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008449 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8450
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008451 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008452 val |= PIPECONF_INTERLACED_ILK;
8453 else
8454 val |= PIPECONF_PROGRESSIVE;
8455
Paulo Zanoni702e7a52012-10-23 18:29:59 -02008456 I915_WRITE(PIPECONF(cpu_transcoder), val);
8457 POSTING_READ(PIPECONF(cpu_transcoder));
Jani Nikula391bf042016-03-18 17:05:40 +02008458}
8459
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008460static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
Jani Nikula391bf042016-03-18 17:05:40 +02008461{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008462 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8463 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jani Nikula391bf042016-03-18 17:05:40 +02008464
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00008465 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
Jani Nikula391bf042016-03-18 17:05:40 +02008466 u32 val = 0;
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008467
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008468 switch (crtc_state->pipe_bpp) {
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008469 case 18:
8470 val |= PIPEMISC_DITHER_6_BPC;
8471 break;
8472 case 24:
8473 val |= PIPEMISC_DITHER_8_BPC;
8474 break;
8475 case 30:
8476 val |= PIPEMISC_DITHER_10_BPC;
8477 break;
8478 case 36:
8479 val |= PIPEMISC_DITHER_12_BPC;
8480 break;
8481 default:
8482 /* Case prevented by pipe_config_set_bpp. */
8483 BUG();
8484 }
8485
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008486 if (crtc_state->dither)
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008487 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8488
Shashank Sharma8c79f842018-10-12 11:53:09 +05308489 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8490 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308491 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308492
8493 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308494 val |= PIPEMISC_YUV420_ENABLE |
Shashank Sharmab22ca992017-07-24 19:19:32 +05308495 PIPEMISC_YUV420_MODE_FULL_BLEND;
Shashank Sharmab22ca992017-07-24 19:19:32 +05308496
Jani Nikula391bf042016-03-18 17:05:40 +02008497 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008498 }
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008499}
8500
Paulo Zanonid4b19312012-11-29 11:29:32 -02008501int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8502{
8503 /*
8504 * Account for spread spectrum to avoid
8505 * oversubscribing the link. Max center spread
8506 * is 2.5%; use 5% for safety's sake.
8507 */
8508 u32 bps = target_clock * bpp * 21 / 20;
Ville Syrjälä619d4d02014-02-27 14:23:14 +02008509 return DIV_ROUND_UP(bps, link_bw * 8);
Paulo Zanonid4b19312012-11-29 11:29:32 -02008510}
8511
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008512static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
Daniel Vetter6cf86a52013-04-02 23:38:10 +02008513{
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008514 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
Paulo Zanonif48d8f22012-09-20 18:36:04 -03008515}
8516
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008517static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8518 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03008519 struct dpll *reduced_clock)
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008520{
8521 struct drm_crtc *crtc = &intel_crtc->base;
8522 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008523 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008524 u32 dpll, fp, fp2;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008525 int factor;
Jesse Barnes79e53942008-11-07 14:24:08 -08008526
Chris Wilsonc1858122010-12-03 21:35:48 +00008527 /* Enable autotuning of the PLL clock (if permissible) */
Eric Anholt8febb292011-03-30 13:01:07 -07008528 factor = 21;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008529 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Eric Anholt8febb292011-03-30 13:01:07 -07008530 if ((intel_panel_use_ssc(dev_priv) &&
Ville Syrjäläe91e9412013-12-09 18:54:16 +02008531 dev_priv->vbt.lvds_ssc_freq == 100000) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008532 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
Eric Anholt8febb292011-03-30 13:01:07 -07008533 factor = 25;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008534 } else if (crtc_state->sdvo_tv_clock)
Eric Anholt8febb292011-03-30 13:01:07 -07008535 factor = 20;
Chris Wilsonc1858122010-12-03 21:35:48 +00008536
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008537 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Chris Wilsonc1858122010-12-03 21:35:48 +00008538
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008539 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8540 fp |= FP_CB_TUNE;
8541
8542 if (reduced_clock) {
8543 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8544
8545 if (reduced_clock->m < factor * reduced_clock->n)
8546 fp2 |= FP_CB_TUNE;
8547 } else {
8548 fp2 = fp;
8549 }
Daniel Vetter9a7c7892013-04-04 22:20:34 +02008550
Chris Wilson5eddb702010-09-11 13:48:45 +01008551 dpll = 0;
Zhenyu Wang2c072452009-06-05 15:38:42 +08008552
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008553 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Eric Anholta07d6782011-03-30 13:01:08 -07008554 dpll |= DPLLB_MODE_LVDS;
8555 else
8556 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008557
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008558 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02008559 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008560
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008561 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8562 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008563 dpll |= DPLL_SDVO_HIGH_SPEED;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008564
Ville Syrjälä37a56502016-06-22 21:57:04 +03008565 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008566 dpll |= DPLL_SDVO_HIGH_SPEED;
Jesse Barnes79e53942008-11-07 14:24:08 -08008567
Ville Syrjälä7d7f8632016-09-26 11:30:46 +03008568 /*
8569 * The high speed IO clock is only really required for
8570 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8571 * possible to share the DPLL between CRT and HDMI. Enabling
8572 * the clock needlessly does no real harm, except use up a
8573 * bit of power potentially.
8574 *
8575 * We'll limit this to IVB with 3 pipes, since it has only two
8576 * DPLLs and so DPLL sharing is the only way to get three pipes
8577 * driving PCH ports at the same time. On SNB we could do this,
8578 * and potentially avoid enabling the second DPLL, but it's not
8579 * clear if it''s a win or loss power wise. No point in doing
8580 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8581 */
8582 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8583 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8584 dpll |= DPLL_SDVO_HIGH_SPEED;
8585
Eric Anholta07d6782011-03-30 13:01:08 -07008586 /* compute bitmask from p1 value */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008587 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008588 /* also FPA1 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008589 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008590
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008591 switch (crtc_state->dpll.p2) {
Eric Anholta07d6782011-03-30 13:01:08 -07008592 case 5:
8593 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8594 break;
8595 case 7:
8596 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8597 break;
8598 case 10:
8599 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8600 break;
8601 case 14:
8602 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8603 break;
Jesse Barnes79e53942008-11-07 14:24:08 -08008604 }
8605
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008606 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8607 intel_panel_use_ssc(dev_priv))
Kristian Høgsberg43565a02009-02-13 20:56:52 -05008608 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
Jesse Barnes79e53942008-11-07 14:24:08 -08008609 else
8610 dpll |= PLL_REF_INPUT_DREFCLK;
8611
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008612 dpll |= DPLL_VCO_ENABLE;
8613
8614 crtc_state->dpll_hw_state.dpll = dpll;
8615 crtc_state->dpll_hw_state.fp0 = fp;
8616 crtc_state->dpll_hw_state.fp1 = fp2;
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008617}
8618
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008619static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8620 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08008621{
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008622 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008623 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03008624 const struct intel_limit *limit;
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008625 int refclk = 120000;
Jesse Barnes79e53942008-11-07 14:24:08 -08008626
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03008627 memset(&crtc_state->dpll_hw_state, 0,
8628 sizeof(crtc_state->dpll_hw_state));
8629
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008630 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8631 if (!crtc_state->has_pch_encoder)
8632 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008633
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03008634 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008635 if (intel_panel_use_ssc(dev_priv)) {
8636 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8637 dev_priv->vbt.lvds_ssc_freq);
8638 refclk = dev_priv->vbt.lvds_ssc_freq;
8639 }
8640
8641 if (intel_is_dual_link_lvds(dev)) {
8642 if (refclk == 100000)
8643 limit = &intel_limits_ironlake_dual_lvds_100m;
8644 else
8645 limit = &intel_limits_ironlake_dual_lvds;
8646 } else {
8647 if (refclk == 100000)
8648 limit = &intel_limits_ironlake_single_lvds_100m;
8649 else
8650 limit = &intel_limits_ironlake_single_lvds;
8651 }
8652 } else {
8653 limit = &intel_limits_ironlake_dac;
8654 }
8655
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008656 if (!crtc_state->clock_set &&
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008657 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8658 refclk, NULL, &crtc_state->dpll)) {
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008659 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8660 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01008661 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008662
Gustavo A. R. Silvacbaa3312017-05-15 16:56:05 -05008663 ironlake_compute_dpll(crtc, crtc_state, NULL);
Daniel Vetter66e985c2013-06-05 13:34:20 +02008664
Gustavo A. R. Silvaefd38b62017-05-15 17:00:28 -05008665 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
Chris Wilson43031782018-09-13 14:16:26 +01008666 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8667 pipe_name(crtc->pipe));
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008668 return -EINVAL;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +02008669 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008670
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02008671 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008672}
8673
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008674static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8675 struct intel_link_m_n *m_n)
Daniel Vetter72419202013-04-04 13:28:53 +02008676{
8677 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008678 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008679 enum pipe pipe = crtc->pipe;
Daniel Vetter72419202013-04-04 13:28:53 +02008680
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008681 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8682 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8683 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8684 & ~TU_SIZE_MASK;
8685 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8686 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8687 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8688}
8689
8690static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8691 enum transcoder transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008692 struct intel_link_m_n *m_n,
8693 struct intel_link_m_n *m2_n2)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008694{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008695 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008696 enum pipe pipe = crtc->pipe;
8697
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008698 if (INTEL_GEN(dev_priv) >= 5) {
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008699 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8700 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8701 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8702 & ~TU_SIZE_MASK;
8703 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8704 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8705 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02008706
8707 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008708 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8709 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8710 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8711 & ~TU_SIZE_MASK;
8712 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8713 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8714 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8715 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008716 } else {
8717 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8718 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8719 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8720 & ~TU_SIZE_MASK;
8721 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8722 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8723 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8724 }
8725}
8726
8727void intel_dp_get_m_n(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008728 struct intel_crtc_state *pipe_config)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008729{
Ander Conselvan de Oliveira681a8502015-01-15 14:55:24 +02008730 if (pipe_config->has_pch_encoder)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008731 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8732 else
8733 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008734 &pipe_config->dp_m_n,
8735 &pipe_config->dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008736}
8737
Daniel Vetter72419202013-04-04 13:28:53 +02008738static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008739 struct intel_crtc_state *pipe_config)
Daniel Vetter72419202013-04-04 13:28:53 +02008740{
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008741 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008742 &pipe_config->fdi_m_n, NULL);
Daniel Vetter72419202013-04-04 13:28:53 +02008743}
8744
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008745static void skylake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008746 struct intel_crtc_state *pipe_config)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008747{
8748 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008749 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Kondurua1b22782015-04-07 15:28:45 -07008750 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8751 uint32_t ps_ctrl = 0;
8752 int id = -1;
8753 int i;
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008754
Chandra Kondurua1b22782015-04-07 15:28:45 -07008755 /* find scaler attached to this pipe */
8756 for (i = 0; i < crtc->num_scalers; i++) {
8757 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8758 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8759 id = i;
8760 pipe_config->pch_pfit.enabled = true;
8761 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8762 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8763 break;
8764 }
8765 }
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008766
Chandra Kondurua1b22782015-04-07 15:28:45 -07008767 scaler_state->scaler_id = id;
8768 if (id >= 0) {
8769 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8770 } else {
8771 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008772 }
8773}
8774
Damien Lespiau5724dbd2015-01-20 12:51:52 +00008775static void
8776skylake_get_initial_plane_config(struct intel_crtc *crtc,
8777 struct intel_initial_plane_config *plane_config)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008778{
8779 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008780 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008781 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8782 enum plane_id plane_id = plane->id;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008783 enum pipe pipe;
James Ausmus4036c782017-11-13 10:11:28 -08008784 u32 val, base, offset, stride_mult, tiling, alpha;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008785 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00008786 unsigned int aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008787 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00008788 struct intel_framebuffer *intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008789
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008790 if (!plane->get_hw_state(plane, &pipe))
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02008791 return;
8792
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008793 WARN_ON(pipe != crtc->pipe);
8794
Damien Lespiaud9806c92015-01-21 14:07:19 +00008795 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00008796 if (!intel_fb) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008797 DRM_DEBUG_KMS("failed to alloc fb\n");
8798 return;
8799 }
8800
Damien Lespiau1b842c82015-01-21 13:50:54 +00008801 fb = &intel_fb->base;
8802
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02008803 fb->dev = dev;
8804
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008805 val = I915_READ(PLANE_CTL(pipe, plane_id));
Damien Lespiau42a7b082015-02-05 19:35:13 +00008806
James Ausmusb5972772018-01-30 11:49:16 -02008807 if (INTEL_GEN(dev_priv) >= 11)
8808 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8809 else
8810 pixel_format = val & PLANE_CTL_FORMAT_MASK;
James Ausmus4036c782017-11-13 10:11:28 -08008811
8812 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008813 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
James Ausmus4036c782017-11-13 10:11:28 -08008814 alpha &= PLANE_COLOR_ALPHA_MASK;
8815 } else {
8816 alpha = val & PLANE_CTL_ALPHA_MASK;
8817 }
8818
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008819 fourcc = skl_format_to_fourcc(pixel_format,
James Ausmus4036c782017-11-13 10:11:28 -08008820 val & PLANE_CTL_ORDER_RGBX, alpha);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02008821 fb->format = drm_format_info(fourcc);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008822
Damien Lespiau40f46282015-02-27 11:15:21 +00008823 tiling = val & PLANE_CTL_TILED_MASK;
8824 switch (tiling) {
8825 case PLANE_CTL_TILED_LINEAR:
Ben Widawsky2f075562017-03-24 14:29:48 -07008826 fb->modifier = DRM_FORMAT_MOD_LINEAR;
Damien Lespiau40f46282015-02-27 11:15:21 +00008827 break;
8828 case PLANE_CTL_TILED_X:
8829 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02008830 fb->modifier = I915_FORMAT_MOD_X_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008831 break;
8832 case PLANE_CTL_TILED_Y:
Imre Deak914a4fd2018-10-16 19:00:11 +03008833 plane_config->tiling = I915_TILING_Y;
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07008834 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07008835 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8836 else
8837 fb->modifier = I915_FORMAT_MOD_Y_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008838 break;
8839 case PLANE_CTL_TILED_YF:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07008840 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07008841 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8842 else
8843 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008844 break;
8845 default:
8846 MISSING_CASE(tiling);
8847 goto error;
8848 }
8849
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008850 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008851 plane_config->base = base;
8852
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008853 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008854
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008855 val = I915_READ(PLANE_SIZE(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008856 fb->height = ((val >> 16) & 0xfff) + 1;
8857 fb->width = ((val >> 0) & 0x1fff) + 1;
8858
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008859 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02008860 stride_mult = intel_fb_stride_alignment(fb, 0);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008861 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8862
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02008863 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008864
Daniel Vetterf37b5c22015-02-10 23:12:27 +01008865 plane_config->size = fb->pitches[0] * aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008866
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008867 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8868 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02008869 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008870 plane_config->size);
8871
Damien Lespiau2d140302015-02-05 17:22:18 +00008872 plane_config->fb = intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008873 return;
8874
8875error:
Matthew Auldd1a3a032016-08-23 16:00:44 +01008876 kfree(intel_fb);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008877}
8878
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008879static void ironlake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008880 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008881{
8882 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008883 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008884 uint32_t tmp;
8885
8886 tmp = I915_READ(PF_CTL(crtc->pipe));
8887
8888 if (tmp & PF_ENABLE) {
Chris Wilsonfd4daa92013-08-27 17:04:17 +01008889 pipe_config->pch_pfit.enabled = true;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008890 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8891 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
Daniel Vettercb8b2a32013-06-01 17:16:23 +02008892
8893 /* We currently do not free assignements of panel fitters on
8894 * ivb/hsw (since we don't use the higher upscaling modes which
8895 * differentiates them) so just WARN about this case for now. */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01008896 if (IS_GEN7(dev_priv)) {
Daniel Vettercb8b2a32013-06-01 17:16:23 +02008897 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
8898 PF_PIPE_SEL_IVB(crtc->pipe));
8899 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008900 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008901}
8902
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008903static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008904 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008905{
8906 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008907 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak17290502016-02-12 18:55:11 +02008908 enum intel_display_power_domain power_domain;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008909 uint32_t tmp;
Imre Deak17290502016-02-12 18:55:11 +02008910 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008911
Imre Deak17290502016-02-12 18:55:11 +02008912 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8913 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Paulo Zanoni930e8c92014-07-04 13:38:34 -03008914 return false;
8915
Shashank Sharmad9facae2018-10-12 11:53:07 +05308916 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02008917 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008918 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02008919
Imre Deak17290502016-02-12 18:55:11 +02008920 ret = false;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008921 tmp = I915_READ(PIPECONF(crtc->pipe));
8922 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02008923 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008924
Ville Syrjälä42571ae2013-09-06 23:29:00 +03008925 switch (tmp & PIPECONF_BPC_MASK) {
8926 case PIPECONF_6BPC:
8927 pipe_config->pipe_bpp = 18;
8928 break;
8929 case PIPECONF_8BPC:
8930 pipe_config->pipe_bpp = 24;
8931 break;
8932 case PIPECONF_10BPC:
8933 pipe_config->pipe_bpp = 30;
8934 break;
8935 case PIPECONF_12BPC:
8936 pipe_config->pipe_bpp = 36;
8937 break;
8938 default:
8939 break;
8940 }
8941
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02008942 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8943 pipe_config->limited_color_range = true;
8944
Daniel Vetterab9412b2013-05-03 11:49:46 +02008945 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
Daniel Vetter66e985c2013-06-05 13:34:20 +02008946 struct intel_shared_dpll *pll;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008947 enum intel_dpll_id pll_id;
Daniel Vetter66e985c2013-06-05 13:34:20 +02008948
Daniel Vetter88adfff2013-03-28 10:42:01 +01008949 pipe_config->has_pch_encoder = true;
8950
Daniel Vetter627eb5a2013-04-29 19:33:42 +02008951 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
8952 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8953 FDI_DP_PORT_WIDTH_SHIFT) + 1;
Daniel Vetter72419202013-04-04 13:28:53 +02008954
8955 ironlake_get_fdi_m_n_config(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02008956
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03008957 if (HAS_PCH_IBX(dev_priv)) {
Imre Deakd9a7bc62016-05-12 16:18:50 +03008958 /*
8959 * The pipe->pch transcoder and pch transcoder->pll
8960 * mapping is fixed.
8961 */
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008962 pll_id = (enum intel_dpll_id) crtc->pipe;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02008963 } else {
8964 tmp = I915_READ(PCH_DPLL_SEL);
8965 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008966 pll_id = DPLL_ID_PCH_PLL_B;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02008967 else
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008968 pll_id= DPLL_ID_PCH_PLL_A;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02008969 }
Daniel Vetter66e985c2013-06-05 13:34:20 +02008970
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008971 pipe_config->shared_dpll =
8972 intel_get_shared_dpll_by_id(dev_priv, pll_id);
8973 pll = pipe_config->shared_dpll;
Daniel Vetter66e985c2013-06-05 13:34:20 +02008974
Lucas De Marchiee1398b2018-03-20 15:06:33 -07008975 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
8976 &pipe_config->dpll_hw_state));
Daniel Vetterc93f54c2013-06-27 19:47:19 +02008977
8978 tmp = pipe_config->dpll_hw_state.dpll;
8979 pipe_config->pixel_multiplier =
8980 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
8981 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
Ville Syrjälä18442d02013-09-13 16:00:08 +03008982
8983 ironlake_pch_clock_get(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02008984 } else {
8985 pipe_config->pixel_multiplier = 1;
Daniel Vetter627eb5a2013-04-29 19:33:42 +02008986 }
8987
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02008988 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02008989 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02008990
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008991 ironlake_get_pfit_config(crtc, pipe_config);
8992
Imre Deak17290502016-02-12 18:55:11 +02008993 ret = true;
8994
8995out:
8996 intel_display_power_put(dev_priv, power_domain);
8997
8998 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008999}
9000
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009001static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9002{
Chris Wilson91c8a322016-07-05 10:40:23 +01009003 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009004 struct intel_crtc *crtc;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009005
Damien Lespiaud3fcc802014-05-13 23:32:22 +01009006 for_each_intel_crtc(dev, crtc)
Rob Clarke2c719b2014-12-15 13:56:32 -05009007 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009008 pipe_name(crtc->pipe));
9009
Imre Deak75e39682018-08-06 12:58:39 +03009010 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
Imre Deak9c3a16c2017-08-14 18:15:30 +03009011 "Display power well on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009012 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
Ville Syrjälä01403de2015-09-18 20:03:33 +03009013 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9014 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
Imre Deak44cb7342016-08-10 14:07:29 +03009015 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009016 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009017 "CPU PWM1 enabled\n");
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009018 if (IS_HASWELL(dev_priv))
Rob Clarke2c719b2014-12-15 13:56:32 -05009019 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
Paulo Zanonic5107b82014-07-04 11:50:30 -03009020 "CPU PWM2 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009021 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009022 "PCH PWM1 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009023 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009024 "Utility pin enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009025 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009026
Paulo Zanoni9926ada2014-04-01 19:39:47 -03009027 /*
9028 * In theory we can still leave IRQs enabled, as long as only the HPD
9029 * interrupts remain enabled. We used to check for that, but since it's
9030 * gen-specific and since we only disable LCPLL after we fully disable
9031 * the interrupts, the check below should be enough.
9032 */
Rob Clarke2c719b2014-12-15 13:56:32 -05009033 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009034}
9035
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009036static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9037{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009038 if (IS_HASWELL(dev_priv))
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009039 return I915_READ(D_COMP_HSW);
9040 else
9041 return I915_READ(D_COMP_BDW);
9042}
9043
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009044static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9045{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009046 if (IS_HASWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009047 mutex_lock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009048 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9049 val))
Chris Wilson79cf2192016-08-24 11:16:07 +01009050 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009051 mutex_unlock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009052 } else {
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009053 I915_WRITE(D_COMP_BDW, val);
9054 POSTING_READ(D_COMP_BDW);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009055 }
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009056}
9057
9058/*
9059 * This function implements pieces of two sequences from BSpec:
9060 * - Sequence for display software to disable LCPLL
9061 * - Sequence for display software to allow package C8+
9062 * The steps implemented here are just the steps that actually touch the LCPLL
9063 * register. Callers should take care of disabling all the display engine
9064 * functions, doing the mode unset, fixing interrupts, etc.
9065 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009066static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9067 bool switch_to_fclk, bool allow_power_down)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009068{
9069 uint32_t val;
9070
9071 assert_can_disable_lcpll(dev_priv);
9072
9073 val = I915_READ(LCPLL_CTL);
9074
9075 if (switch_to_fclk) {
9076 val |= LCPLL_CD_SOURCE_FCLK;
9077 I915_WRITE(LCPLL_CTL, val);
9078
Imre Deakf53dd632016-06-28 13:37:32 +03009079 if (wait_for_us(I915_READ(LCPLL_CTL) &
9080 LCPLL_CD_SOURCE_FCLK_DONE, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009081 DRM_ERROR("Switching to FCLK failed\n");
9082
9083 val = I915_READ(LCPLL_CTL);
9084 }
9085
9086 val |= LCPLL_PLL_DISABLE;
9087 I915_WRITE(LCPLL_CTL, val);
9088 POSTING_READ(LCPLL_CTL);
9089
Chris Wilson24d84412016-06-30 15:33:07 +01009090 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009091 DRM_ERROR("LCPLL still locked\n");
9092
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009093 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009094 val |= D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009095 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009096 ndelay(100);
9097
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009098 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9099 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009100 DRM_ERROR("D_COMP RCOMP still in progress\n");
9101
9102 if (allow_power_down) {
9103 val = I915_READ(LCPLL_CTL);
9104 val |= LCPLL_POWER_DOWN_ALLOW;
9105 I915_WRITE(LCPLL_CTL, val);
9106 POSTING_READ(LCPLL_CTL);
9107 }
9108}
9109
9110/*
9111 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9112 * source.
9113 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009114static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009115{
9116 uint32_t val;
9117
9118 val = I915_READ(LCPLL_CTL);
9119
9120 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9121 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9122 return;
9123
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009124 /*
9125 * Make sure we're not on PC8 state before disabling PC8, otherwise
9126 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009127 */
Mika Kuoppala59bad942015-01-16 11:34:40 +02009128 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Paulo Zanoni215733f2013-08-19 13:18:07 -03009129
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009130 if (val & LCPLL_POWER_DOWN_ALLOW) {
9131 val &= ~LCPLL_POWER_DOWN_ALLOW;
9132 I915_WRITE(LCPLL_CTL, val);
Daniel Vetter35d8f2e2013-08-21 23:38:08 +02009133 POSTING_READ(LCPLL_CTL);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009134 }
9135
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009136 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009137 val |= D_COMP_COMP_FORCE;
9138 val &= ~D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009139 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009140
9141 val = I915_READ(LCPLL_CTL);
9142 val &= ~LCPLL_PLL_DISABLE;
9143 I915_WRITE(LCPLL_CTL, val);
9144
Chris Wilson93220c02016-06-30 15:33:08 +01009145 if (intel_wait_for_register(dev_priv,
9146 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9147 5))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009148 DRM_ERROR("LCPLL not locked yet\n");
9149
9150 if (val & LCPLL_CD_SOURCE_FCLK) {
9151 val = I915_READ(LCPLL_CTL);
9152 val &= ~LCPLL_CD_SOURCE_FCLK;
9153 I915_WRITE(LCPLL_CTL, val);
9154
Imre Deakf53dd632016-06-28 13:37:32 +03009155 if (wait_for_us((I915_READ(LCPLL_CTL) &
9156 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009157 DRM_ERROR("Switching back to LCPLL failed\n");
9158 }
Paulo Zanoni215733f2013-08-19 13:18:07 -03009159
Mika Kuoppala59bad942015-01-16 11:34:40 +02009160 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009161
Ville Syrjälä4c75b942016-10-31 22:37:12 +02009162 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009163 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009164}
9165
Paulo Zanoni765dab672014-03-07 20:08:18 -03009166/*
9167 * Package states C8 and deeper are really deep PC states that can only be
9168 * reached when all the devices on the system allow it, so even if the graphics
9169 * device allows PC8+, it doesn't mean the system will actually get to these
9170 * states. Our driver only allows PC8+ when going into runtime PM.
9171 *
9172 * The requirements for PC8+ are that all the outputs are disabled, the power
9173 * well is disabled and most interrupts are disabled, and these are also
9174 * requirements for runtime PM. When these conditions are met, we manually do
9175 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9176 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9177 * hang the machine.
9178 *
9179 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9180 * the state of some registers, so when we come back from PC8+ we need to
9181 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9182 * need to take care of the registers kept by RC6. Notice that this happens even
9183 * if we don't put the device in PCI D3 state (which is what currently happens
9184 * because of the runtime PM support).
9185 *
9186 * For more, read "Display Sequences for Package C8" on the hardware
9187 * documentation.
9188 */
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009189void hsw_enable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009190{
Paulo Zanonic67a4702013-08-19 13:18:09 -03009191 uint32_t val;
9192
Paulo Zanonic67a4702013-08-19 13:18:09 -03009193 DRM_DEBUG_KMS("Enabling package C8+\n");
9194
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009195 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009196 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9197 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9198 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9199 }
9200
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009201 lpt_disable_clkout_dp(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009202 hsw_disable_lcpll(dev_priv, true, true);
9203}
9204
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009205void hsw_disable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009206{
Paulo Zanonic67a4702013-08-19 13:18:09 -03009207 uint32_t val;
9208
Paulo Zanonic67a4702013-08-19 13:18:09 -03009209 DRM_DEBUG_KMS("Disabling package C8+\n");
9210
9211 hsw_restore_lcpll(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009212 lpt_init_pch_refclk(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009213
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009214 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009215 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9216 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9217 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9218 }
Paulo Zanonic67a4702013-08-19 13:18:09 -03009219}
9220
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02009221static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9222 struct intel_crtc_state *crtc_state)
Paulo Zanoni09b4ddf2012-10-05 12:05:55 -03009223{
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009224 struct intel_atomic_state *state =
9225 to_intel_atomic_state(crtc_state->base.state);
9226
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009227 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009228 struct intel_encoder *encoder =
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009229 intel_get_crtc_new_encoder(state, crtc_state);
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009230
9231 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
Chris Wilson43031782018-09-13 14:16:26 +01009232 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9233 pipe_name(crtc->pipe));
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009234 return -EINVAL;
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009235 }
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009236 }
Daniel Vetter716c2e52014-06-25 22:02:02 +03009237
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02009238 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009239}
9240
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009241static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9242 enum port port,
9243 struct intel_crtc_state *pipe_config)
9244{
9245 enum intel_dpll_id id;
9246 u32 temp;
9247
9248 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
Paulo Zanonidfbd4502017-08-25 16:40:04 -03009249 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009250
9251 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9252 return;
9253
9254 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9255}
9256
Paulo Zanoni970888e2018-05-21 17:25:44 -07009257static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9258 enum port port,
9259 struct intel_crtc_state *pipe_config)
9260{
9261 enum intel_dpll_id id;
9262 u32 temp;
9263
9264 /* TODO: TBT pll not implemented. */
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309265 if (intel_port_is_combophy(dev_priv, port)) {
Paulo Zanoni970888e2018-05-21 17:25:44 -07009266 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9267 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9268 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9269
Vandita Kulkarnia54270d2018-10-03 12:52:00 +05309270 if (WARN_ON(!intel_dpll_is_combophy(id)))
Paulo Zanoni970888e2018-05-21 17:25:44 -07009271 return;
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309272 } else if (intel_port_is_tc(dev_priv, port)) {
Vandita Kulkarnicb6caf72018-10-03 12:51:58 +05309273 id = icl_port_to_mg_pll_id(port);
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309274 } else {
9275 WARN(1, "Invalid port %x\n", port);
Paulo Zanoni970888e2018-05-21 17:25:44 -07009276 return;
9277 }
9278
9279 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9280}
9281
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309282static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9283 enum port port,
9284 struct intel_crtc_state *pipe_config)
9285{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009286 enum intel_dpll_id id;
9287
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309288 switch (port) {
9289 case PORT_A:
Imre Deak08250c42016-03-14 19:55:34 +02009290 id = DPLL_ID_SKL_DPLL0;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309291 break;
9292 case PORT_B:
Imre Deak08250c42016-03-14 19:55:34 +02009293 id = DPLL_ID_SKL_DPLL1;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309294 break;
9295 case PORT_C:
Imre Deak08250c42016-03-14 19:55:34 +02009296 id = DPLL_ID_SKL_DPLL2;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309297 break;
9298 default:
9299 DRM_ERROR("Incorrect port type\n");
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009300 return;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309301 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009302
9303 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309304}
9305
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009306static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9307 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009308 struct intel_crtc_state *pipe_config)
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009309{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009310 enum intel_dpll_id id;
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +02009311 u32 temp;
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009312
9313 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009314 id = temp >> (port * 3 + 1);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009315
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009316 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009317 return;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009318
9319 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009320}
9321
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009322static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9323 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009324 struct intel_crtc_state *pipe_config)
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009325{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009326 enum intel_dpll_id id;
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009327 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009328
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009329 switch (ddi_pll_sel) {
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009330 case PORT_CLK_SEL_WRPLL1:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009331 id = DPLL_ID_WRPLL1;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009332 break;
9333 case PORT_CLK_SEL_WRPLL2:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009334 id = DPLL_ID_WRPLL2;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009335 break;
Maarten Lankhorst00490c22015-11-16 14:42:12 +01009336 case PORT_CLK_SEL_SPLL:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009337 id = DPLL_ID_SPLL;
Ville Syrjälä79bd23d2015-12-01 23:32:07 +02009338 break;
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +02009339 case PORT_CLK_SEL_LCPLL_810:
9340 id = DPLL_ID_LCPLL_810;
9341 break;
9342 case PORT_CLK_SEL_LCPLL_1350:
9343 id = DPLL_ID_LCPLL_1350;
9344 break;
9345 case PORT_CLK_SEL_LCPLL_2700:
9346 id = DPLL_ID_LCPLL_2700;
9347 break;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009348 default:
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009349 MISSING_CASE(ddi_pll_sel);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009350 /* fall through */
9351 case PORT_CLK_SEL_NONE:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009352 return;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009353 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009354
9355 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009356}
9357
Jani Nikulacf304292016-03-18 17:05:41 +02009358static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9359 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009360 u64 *power_domain_mask)
Jani Nikulacf304292016-03-18 17:05:41 +02009361{
9362 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009363 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulacf304292016-03-18 17:05:41 +02009364 enum intel_display_power_domain power_domain;
9365 u32 tmp;
9366
Imre Deakd9a7bc62016-05-12 16:18:50 +03009367 /*
9368 * The pipe->transcoder mapping is fixed with the exception of the eDP
9369 * transcoder handled below.
9370 */
Jani Nikulacf304292016-03-18 17:05:41 +02009371 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9372
9373 /*
9374 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9375 * consistency and less surprising code; it's in always on power).
9376 */
9377 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9378 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9379 enum pipe trans_edp_pipe;
9380 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9381 default:
9382 WARN(1, "unknown pipe linked to edp transcoder\n");
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05009383 /* fall through */
Jani Nikulacf304292016-03-18 17:05:41 +02009384 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9385 case TRANS_DDI_EDP_INPUT_A_ON:
9386 trans_edp_pipe = PIPE_A;
9387 break;
9388 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9389 trans_edp_pipe = PIPE_B;
9390 break;
9391 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9392 trans_edp_pipe = PIPE_C;
9393 break;
9394 }
9395
9396 if (trans_edp_pipe == crtc->pipe)
9397 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9398 }
9399
9400 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9401 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9402 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009403 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikulacf304292016-03-18 17:05:41 +02009404
9405 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9406
9407 return tmp & PIPECONF_ENABLE;
9408}
9409
Jani Nikula4d1de972016-03-18 17:05:42 +02009410static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9411 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009412 u64 *power_domain_mask)
Jani Nikula4d1de972016-03-18 17:05:42 +02009413{
9414 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009415 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikula4d1de972016-03-18 17:05:42 +02009416 enum intel_display_power_domain power_domain;
9417 enum port port;
9418 enum transcoder cpu_transcoder;
9419 u32 tmp;
9420
Jani Nikula4d1de972016-03-18 17:05:42 +02009421 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9422 if (port == PORT_A)
9423 cpu_transcoder = TRANSCODER_DSI_A;
9424 else
9425 cpu_transcoder = TRANSCODER_DSI_C;
9426
9427 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9428 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9429 continue;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009430 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikula4d1de972016-03-18 17:05:42 +02009431
Imre Deakdb18b6a2016-03-24 12:41:40 +02009432 /*
9433 * The PLL needs to be enabled with a valid divider
9434 * configuration, otherwise accessing DSI registers will hang
9435 * the machine. See BSpec North Display Engine
9436 * registers/MIPI[BXT]. We can break out here early, since we
9437 * need the same DSI PLL to be enabled for both DSI ports.
9438 */
Jani Nikulae5186342018-07-05 16:25:08 +03009439 if (!bxt_dsi_pll_is_enabled(dev_priv))
Imre Deakdb18b6a2016-03-24 12:41:40 +02009440 break;
9441
Jani Nikula4d1de972016-03-18 17:05:42 +02009442 /* XXX: this works for video mode only */
9443 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9444 if (!(tmp & DPI_ENABLE))
9445 continue;
9446
9447 tmp = I915_READ(MIPI_CTRL(port));
9448 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9449 continue;
9450
9451 pipe_config->cpu_transcoder = cpu_transcoder;
Jani Nikula4d1de972016-03-18 17:05:42 +02009452 break;
9453 }
9454
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009455 return transcoder_is_dsi(pipe_config->cpu_transcoder);
Jani Nikula4d1de972016-03-18 17:05:42 +02009456}
9457
Daniel Vetter26804af2014-06-25 22:01:55 +03009458static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009459 struct intel_crtc_state *pipe_config)
Daniel Vetter26804af2014-06-25 22:01:55 +03009460{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009461 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009462 struct intel_shared_dpll *pll;
Daniel Vetter26804af2014-06-25 22:01:55 +03009463 enum port port;
9464 uint32_t tmp;
9465
9466 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9467
9468 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9469
Paulo Zanoni970888e2018-05-21 17:25:44 -07009470 if (IS_ICELAKE(dev_priv))
9471 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9472 else if (IS_CANNONLAKE(dev_priv))
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009473 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9474 else if (IS_GEN9_BC(dev_priv))
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009475 skylake_get_ddi_pll(dev_priv, port, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009476 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309477 bxt_get_ddi_pll(dev_priv, port, pipe_config);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009478 else
9479 haswell_get_ddi_pll(dev_priv, port, pipe_config);
Daniel Vetter9cd86932014-06-25 22:01:57 +03009480
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009481 pll = pipe_config->shared_dpll;
9482 if (pll) {
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009483 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9484 &pipe_config->dpll_hw_state));
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009485 }
9486
Daniel Vetter26804af2014-06-25 22:01:55 +03009487 /*
9488 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9489 * DDI E. So just check whether this pipe is wired to DDI E and whether
9490 * the PCH transcoder is on.
9491 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009492 if (INTEL_GEN(dev_priv) < 9 &&
Damien Lespiauca370452013-12-03 13:56:24 +00009493 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
Daniel Vetter26804af2014-06-25 22:01:55 +03009494 pipe_config->has_pch_encoder = true;
9495
9496 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9497 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9498 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9499
9500 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9501 }
9502}
9503
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009504static bool haswell_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009505 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009506{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009507 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02009508 enum intel_display_power_domain power_domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009509 u64 power_domain_mask;
Jani Nikulacf304292016-03-18 17:05:41 +02009510 bool active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009511
Imre Deake79dfb52017-07-20 01:50:57 +03009512 intel_crtc_init_scalers(crtc, pipe_config);
Imre Deak5fb9dad2017-07-20 14:28:20 +03009513
Imre Deak17290502016-02-12 18:55:11 +02009514 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9515 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02009516 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009517 power_domain_mask = BIT_ULL(power_domain);
Imre Deak17290502016-02-12 18:55:11 +02009518
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009519 pipe_config->shared_dpll = NULL;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009520
Jani Nikulacf304292016-03-18 17:05:41 +02009521 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
Daniel Vettereccb1402013-05-22 00:50:22 +02009522
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009523 if (IS_GEN9_LP(dev_priv) &&
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009524 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9525 WARN_ON(active);
9526 active = true;
Jani Nikula4d1de972016-03-18 17:05:42 +02009527 }
9528
Jani Nikulacf304292016-03-18 17:05:41 +02009529 if (!active)
Imre Deak17290502016-02-12 18:55:11 +02009530 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009531
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009532 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
Jani Nikula4d1de972016-03-18 17:05:42 +02009533 haswell_get_ddi_port_state(crtc, pipe_config);
9534 intel_get_pipe_timings(crtc, pipe_config);
9535 }
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009536
Jani Nikulabc58be62016-03-18 17:05:39 +02009537 intel_get_pipe_src_size(crtc, pipe_config);
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05309538 intel_get_crtc_ycbcr_config(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009539
Lionel Landwerlin05dc6982016-03-16 10:57:15 +00009540 pipe_config->gamma_mode =
9541 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9542
Imre Deak17290502016-02-12 18:55:11 +02009543 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9544 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009545 power_domain_mask |= BIT_ULL(power_domain);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009546 if (INTEL_GEN(dev_priv) >= 9)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009547 skylake_get_pfit_config(crtc, pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08009548 else
Rodrigo Vivi1c132b42015-09-02 15:19:26 -07009549 ironlake_get_pfit_config(crtc, pipe_config);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009550 }
Daniel Vetter88adfff2013-03-28 10:42:01 +01009551
Maarten Lankhorst24f28452017-11-22 19:39:01 +01009552 if (hsw_crtc_supports_ips(crtc)) {
9553 if (IS_HASWELL(dev_priv))
9554 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9555 else {
9556 /*
9557 * We cannot readout IPS state on broadwell, set to
9558 * true so we can set it to a defined state on first
9559 * commit.
9560 */
9561 pipe_config->ips_enabled = true;
9562 }
9563 }
9564
Jani Nikula4d1de972016-03-18 17:05:42 +02009565 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9566 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
Clint Taylorebb69c92014-09-30 10:30:22 -07009567 pipe_config->pixel_multiplier =
9568 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9569 } else {
9570 pipe_config->pixel_multiplier = 1;
9571 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02009572
Imre Deak17290502016-02-12 18:55:11 +02009573out:
9574 for_each_power_domain(power_domain, power_domain_mask)
9575 intel_display_power_put(dev_priv, power_domain);
9576
Jani Nikulacf304292016-03-18 17:05:41 +02009577 return active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009578}
9579
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009580static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009581{
9582 struct drm_i915_private *dev_priv =
9583 to_i915(plane_state->base.plane->dev);
9584 const struct drm_framebuffer *fb = plane_state->base.fb;
9585 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9586 u32 base;
9587
9588 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9589 base = obj->phys_handle->busaddr;
9590 else
9591 base = intel_plane_ggtt_offset(plane_state);
9592
Ville Syrjäläc11ada02018-09-07 18:24:04 +03009593 base += plane_state->color_plane[0].offset;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009594
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009595 /* ILK+ do this automagically */
9596 if (HAS_GMCH_DISPLAY(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +10009597 plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009598 base += (plane_state->base.crtc_h *
9599 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9600
9601 return base;
9602}
9603
Ville Syrjäläed270222017-03-27 21:55:36 +03009604static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9605{
9606 int x = plane_state->base.crtc_x;
9607 int y = plane_state->base.crtc_y;
9608 u32 pos = 0;
9609
9610 if (x < 0) {
9611 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9612 x = -x;
9613 }
9614 pos |= x << CURSOR_X_SHIFT;
9615
9616 if (y < 0) {
9617 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9618 y = -y;
9619 }
9620 pos |= y << CURSOR_Y_SHIFT;
9621
9622 return pos;
9623}
9624
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009625static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9626{
9627 const struct drm_mode_config *config =
9628 &plane_state->base.plane->dev->mode_config;
9629 int width = plane_state->base.crtc_w;
9630 int height = plane_state->base.crtc_h;
9631
9632 return width > 0 && width <= config->cursor_width &&
9633 height > 0 && height <= config->cursor_height;
9634}
9635
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009636static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009637{
9638 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009639 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009640 int src_x, src_y;
9641 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009642 int ret;
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009643
9644 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
9645 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
9646
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009647 ret = intel_plane_check_stride(plane_state);
9648 if (ret)
9649 return ret;
9650
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009651 src_x = plane_state->base.src_x >> 16;
9652 src_y = plane_state->base.src_y >> 16;
9653
9654 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9655 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
9656 plane_state, 0);
9657
9658 if (src_x != 0 || src_y != 0) {
9659 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9660 return -EINVAL;
9661 }
9662
9663 plane_state->color_plane[0].offset = offset;
9664
9665 return 0;
9666}
9667
9668static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9669 struct intel_plane_state *plane_state)
9670{
9671 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009672 int ret;
9673
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009674 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9675 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9676 return -EINVAL;
9677 }
9678
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009679 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9680 &crtc_state->base,
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009681 DRM_PLANE_HELPER_NO_SCALING,
9682 DRM_PLANE_HELPER_NO_SCALING,
9683 true, true);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009684 if (ret)
9685 return ret;
9686
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009687 if (!plane_state->base.visible)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009688 return 0;
9689
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009690 ret = intel_plane_check_src_coordinates(plane_state);
9691 if (ret)
9692 return ret;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009693
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009694 ret = intel_cursor_check_surface(plane_state);
9695 if (ret)
9696 return ret;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009697
Ville Syrjälä659056f2017-03-27 21:55:39 +03009698 return 0;
9699}
9700
Ville Syrjäläddd57132018-09-07 18:24:02 +03009701static unsigned int
9702i845_cursor_max_stride(struct intel_plane *plane,
9703 u32 pixel_format, u64 modifier,
9704 unsigned int rotation)
9705{
9706 return 2048;
9707}
9708
Ville Syrjälä292889e2017-03-17 23:18:01 +02009709static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9710 const struct intel_plane_state *plane_state)
9711{
Ville Syrjälä292889e2017-03-17 23:18:01 +02009712 return CURSOR_ENABLE |
9713 CURSOR_GAMMA_ENABLE |
9714 CURSOR_FORMAT_ARGB |
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009715 CURSOR_STRIDE(plane_state->color_plane[0].stride);
Ville Syrjälä292889e2017-03-17 23:18:01 +02009716}
9717
Ville Syrjälä659056f2017-03-27 21:55:39 +03009718static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9719{
Ville Syrjälä659056f2017-03-27 21:55:39 +03009720 int width = plane_state->base.crtc_w;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009721
9722 /*
9723 * 845g/865g are only limited by the width of their cursors,
9724 * the height is arbitrary up to the precision of the register.
9725 */
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009726 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009727}
9728
Ville Syrjäläeb0f5042018-08-28 17:27:06 +03009729static int i845_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +03009730 struct intel_plane_state *plane_state)
9731{
9732 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009733 int ret;
9734
9735 ret = intel_check_cursor(crtc_state, plane_state);
9736 if (ret)
9737 return ret;
9738
9739 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009740 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009741 return 0;
9742
9743 /* Check for which cursor types we support */
9744 if (!i845_cursor_size_ok(plane_state)) {
9745 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9746 plane_state->base.crtc_w,
9747 plane_state->base.crtc_h);
9748 return -EINVAL;
9749 }
9750
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009751 WARN_ON(plane_state->base.visible &&
9752 plane_state->color_plane[0].stride != fb->pitches[0]);
9753
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009754 switch (fb->pitches[0]) {
Chris Wilson560b85b2010-08-07 11:01:38 +01009755 case 256:
9756 case 512:
9757 case 1024:
9758 case 2048:
Ville Syrjälädc41c152014-08-13 11:57:05 +03009759 break;
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009760 default:
9761 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9762 fb->pitches[0]);
9763 return -EINVAL;
Chris Wilson560b85b2010-08-07 11:01:38 +01009764 }
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +01009765
Ville Syrjälä659056f2017-03-27 21:55:39 +03009766 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9767
9768 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009769}
9770
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009771static void i845_update_cursor(struct intel_plane *plane,
9772 const struct intel_crtc_state *crtc_state,
Chris Wilson560b85b2010-08-07 11:01:38 +01009773 const struct intel_plane_state *plane_state)
9774{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009775 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009776 u32 cntl = 0, base = 0, pos = 0, size = 0;
9777 unsigned long irqflags;
Chris Wilson560b85b2010-08-07 11:01:38 +01009778
Ville Syrjälä936e71e2016-07-26 19:06:59 +03009779 if (plane_state && plane_state->base.visible) {
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +01009780 unsigned int width = plane_state->base.crtc_w;
9781 unsigned int height = plane_state->base.crtc_h;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009782
Ville Syrjäläa0864d52017-03-23 21:27:09 +02009783 cntl = plane_state->ctl;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009784 size = (height << 12) | width;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009785
9786 base = intel_cursor_base(plane_state);
9787 pos = intel_cursor_position(plane_state);
Chris Wilson4b0e3332014-05-30 16:35:26 +03009788 }
Chris Wilson560b85b2010-08-07 11:01:38 +01009789
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009790 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9791
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +03009792 /* On these chipsets we can only modify the base/size/stride
9793 * whilst the cursor is disabled.
9794 */
9795 if (plane->cursor.base != base ||
9796 plane->cursor.size != size ||
9797 plane->cursor.cntl != cntl) {
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009798 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009799 I915_WRITE_FW(CURBASE(PIPE_A), base);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009800 I915_WRITE_FW(CURSIZE, size);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009801 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009802 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
Ville Syrjälä75343a42017-03-27 21:55:38 +03009803
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +03009804 plane->cursor.base = base;
9805 plane->cursor.size = size;
9806 plane->cursor.cntl = cntl;
9807 } else {
9808 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädc41c152014-08-13 11:57:05 +03009809 }
9810
Ville Syrjälä75343a42017-03-27 21:55:38 +03009811 POSTING_READ_FW(CURCNTR(PIPE_A));
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009812
9813 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9814}
9815
9816static void i845_disable_cursor(struct intel_plane *plane,
9817 struct intel_crtc *crtc)
9818{
9819 i845_update_cursor(plane, NULL, NULL);
Chris Wilson560b85b2010-08-07 11:01:38 +01009820}
9821
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009822static bool i845_cursor_get_hw_state(struct intel_plane *plane,
9823 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02009824{
9825 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9826 enum intel_display_power_domain power_domain;
9827 bool ret;
9828
9829 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9830 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9831 return false;
9832
9833 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9834
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009835 *pipe = PIPE_A;
9836
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02009837 intel_display_power_put(dev_priv, power_domain);
9838
9839 return ret;
9840}
9841
Ville Syrjäläddd57132018-09-07 18:24:02 +03009842static unsigned int
9843i9xx_cursor_max_stride(struct intel_plane *plane,
9844 u32 pixel_format, u64 modifier,
9845 unsigned int rotation)
9846{
9847 return plane->base.dev->mode_config.cursor_width * 4;
9848}
9849
Ville Syrjälä292889e2017-03-17 23:18:01 +02009850static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9851 const struct intel_plane_state *plane_state)
9852{
9853 struct drm_i915_private *dev_priv =
9854 to_i915(plane_state->base.plane->dev);
9855 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
José Roberto de Souzac894d632018-05-18 13:15:47 -07009856 u32 cntl = 0;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009857
Ville Syrjäläe876b782018-01-30 22:38:05 +02009858 if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
9859 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
9860
José Roberto de Souzac894d632018-05-18 13:15:47 -07009861 if (INTEL_GEN(dev_priv) <= 10) {
9862 cntl |= MCURSOR_GAMMA_ENABLE;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009863
José Roberto de Souzac894d632018-05-18 13:15:47 -07009864 if (HAS_DDI(dev_priv))
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009865 cntl |= MCURSOR_PIPE_CSC_ENABLE;
José Roberto de Souzac894d632018-05-18 13:15:47 -07009866 }
Ville Syrjälä292889e2017-03-17 23:18:01 +02009867
Ville Syrjälä32ea06b2018-01-30 22:38:01 +02009868 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9869 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
Ville Syrjälä292889e2017-03-17 23:18:01 +02009870
9871 switch (plane_state->base.crtc_w) {
9872 case 64:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009873 cntl |= MCURSOR_MODE_64_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009874 break;
9875 case 128:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009876 cntl |= MCURSOR_MODE_128_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009877 break;
9878 case 256:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009879 cntl |= MCURSOR_MODE_256_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009880 break;
9881 default:
9882 MISSING_CASE(plane_state->base.crtc_w);
9883 return 0;
9884 }
9885
Robert Fossc2c446a2017-05-19 16:50:17 -04009886 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009887 cntl |= MCURSOR_ROTATE_180;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009888
9889 return cntl;
9890}
9891
Ville Syrjälä659056f2017-03-27 21:55:39 +03009892static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
Chris Wilson560b85b2010-08-07 11:01:38 +01009893{
Ville Syrjälä024faac2017-03-27 21:55:42 +03009894 struct drm_i915_private *dev_priv =
9895 to_i915(plane_state->base.plane->dev);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009896 int width = plane_state->base.crtc_w;
9897 int height = plane_state->base.crtc_h;
Chris Wilson560b85b2010-08-07 11:01:38 +01009898
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009899 if (!intel_cursor_size_ok(plane_state))
Ville Syrjälädc41c152014-08-13 11:57:05 +03009900 return false;
9901
Ville Syrjälä024faac2017-03-27 21:55:42 +03009902 /* Cursor width is limited to a few power-of-two sizes */
9903 switch (width) {
Ville Syrjälä659056f2017-03-27 21:55:39 +03009904 case 256:
9905 case 128:
Ville Syrjälä659056f2017-03-27 21:55:39 +03009906 case 64:
9907 break;
9908 default:
9909 return false;
9910 }
9911
Ville Syrjälädc41c152014-08-13 11:57:05 +03009912 /*
Ville Syrjälä024faac2017-03-27 21:55:42 +03009913 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9914 * height from 8 lines up to the cursor width, when the
9915 * cursor is not rotated. Everything else requires square
9916 * cursors.
Ville Syrjälädc41c152014-08-13 11:57:05 +03009917 */
Ville Syrjälä024faac2017-03-27 21:55:42 +03009918 if (HAS_CUR_FBC(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +10009919 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
Ville Syrjälä024faac2017-03-27 21:55:42 +03009920 if (height < 8 || height > width)
Ville Syrjälädc41c152014-08-13 11:57:05 +03009921 return false;
9922 } else {
Ville Syrjälä024faac2017-03-27 21:55:42 +03009923 if (height != width)
Ville Syrjälädc41c152014-08-13 11:57:05 +03009924 return false;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009925 }
9926
9927 return true;
9928}
9929
Ville Syrjäläeb0f5042018-08-28 17:27:06 +03009930static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +03009931 struct intel_plane_state *plane_state)
9932{
Ville Syrjäläeb0f5042018-08-28 17:27:06 +03009933 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009934 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9935 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009936 enum pipe pipe = plane->pipe;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009937 int ret;
9938
9939 ret = intel_check_cursor(crtc_state, plane_state);
9940 if (ret)
9941 return ret;
9942
9943 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009944 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009945 return 0;
9946
9947 /* Check for which cursor types we support */
9948 if (!i9xx_cursor_size_ok(plane_state)) {
9949 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9950 plane_state->base.crtc_w,
9951 plane_state->base.crtc_h);
9952 return -EINVAL;
9953 }
9954
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009955 WARN_ON(plane_state->base.visible &&
9956 plane_state->color_plane[0].stride != fb->pitches[0]);
9957
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009958 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
9959 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9960 fb->pitches[0], plane_state->base.crtc_w);
9961 return -EINVAL;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009962 }
9963
9964 /*
9965 * There's something wrong with the cursor on CHV pipe C.
9966 * If it straddles the left edge of the screen then
9967 * moving it away from the edge or disabling it often
9968 * results in a pipe underrun, and often that can lead to
9969 * dead pipe (constant underrun reported, and it scans
9970 * out just a solid color). To recover from that, the
9971 * display power well must be turned off and on again.
9972 * Refuse the put the cursor into that compromised position.
9973 */
9974 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
9975 plane_state->base.visible && plane_state->base.crtc_x < 0) {
9976 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9977 return -EINVAL;
9978 }
9979
9980 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
9981
9982 return 0;
9983}
9984
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009985static void i9xx_update_cursor(struct intel_plane *plane,
9986 const struct intel_crtc_state *crtc_state,
Sagar Kamble4726e0b2014-03-10 17:06:23 +05309987 const struct intel_plane_state *plane_state)
9988{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009989 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9990 enum pipe pipe = plane->pipe;
Ville Syrjälä024faac2017-03-27 21:55:42 +03009991 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009992 unsigned long irqflags;
Sagar Kamble4726e0b2014-03-10 17:06:23 +05309993
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009994 if (plane_state && plane_state->base.visible) {
Ville Syrjäläa0864d52017-03-23 21:27:09 +02009995 cntl = plane_state->ctl;
Chris Wilson4b0e3332014-05-30 16:35:26 +03009996
Ville Syrjälä024faac2017-03-27 21:55:42 +03009997 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
9998 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
9999
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010000 base = intel_cursor_base(plane_state);
10001 pos = intel_cursor_position(plane_state);
10002 }
10003
10004 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10005
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010006 /*
10007 * On some platforms writing CURCNTR first will also
10008 * cause CURPOS to be armed by the CURBASE write.
10009 * Without the CURCNTR write the CURPOS write would
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010010 * arm itself. Thus we always start the full update
10011 * with a CURCNTR write.
10012 *
10013 * On other platforms CURPOS always requires the
10014 * CURBASE write to arm the update. Additonally
10015 * a write to any of the cursor register will cancel
10016 * an already armed cursor update. Thus leaving out
10017 * the CURBASE write after CURPOS could lead to a
10018 * cursor that doesn't appear to move, or even change
10019 * shape. Thus we always write CURBASE.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010020 *
10021 * CURCNTR and CUR_FBC_CTL are always
10022 * armed by the CURBASE write only.
10023 */
10024 if (plane->cursor.base != base ||
Ville Syrjälä024faac2017-03-27 21:55:42 +030010025 plane->cursor.size != fbc_ctl ||
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010026 plane->cursor.cntl != cntl) {
10027 I915_WRITE_FW(CURCNTR(pipe), cntl);
10028 if (HAS_CUR_FBC(dev_priv))
10029 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
10030 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä75343a42017-03-27 21:55:38 +030010031 I915_WRITE_FW(CURBASE(pipe), base);
10032
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010033 plane->cursor.base = base;
10034 plane->cursor.size = fbc_ctl;
10035 plane->cursor.cntl = cntl;
10036 } else {
10037 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010038 I915_WRITE_FW(CURBASE(pipe), base);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010039 }
10040
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010041 POSTING_READ_FW(CURBASE(pipe));
10042
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010043 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes65a21cd2011-10-12 11:10:21 -070010044}
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030010045
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010046static void i9xx_disable_cursor(struct intel_plane *plane,
10047 struct intel_crtc *crtc)
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010048{
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010049 i9xx_update_cursor(plane, NULL, NULL);
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010050}
Ville Syrjäläd6e4db12013-09-04 18:25:31 +030010051
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010052static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10053 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010054{
10055 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10056 enum intel_display_power_domain power_domain;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010057 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010058 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010059
10060 /*
10061 * Not 100% correct for planes that can move between pipes,
10062 * but that's only the case for gen2-3 which don't have any
10063 * display power wells.
10064 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010065 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010066 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
10067 return false;
10068
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010069 val = I915_READ(CURCNTR(plane->pipe));
10070
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010071 ret = val & MCURSOR_MODE;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010072
10073 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10074 *pipe = plane->pipe;
10075 else
10076 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10077 MCURSOR_PIPE_SELECT_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010078
10079 intel_display_power_put(dev_priv, power_domain);
10080
10081 return ret;
10082}
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010083
Jesse Barnes79e53942008-11-07 14:24:08 -080010084/* VESA 640x480x72Hz mode to set on the pipe */
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010085static const struct drm_display_mode load_detect_mode = {
Jesse Barnes79e53942008-11-07 14:24:08 -080010086 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10087 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10088};
10089
Daniel Vettera8bb6812014-02-10 18:00:39 +010010090struct drm_framebuffer *
Chris Wilson24dbf512017-02-15 10:59:18 +000010091intel_framebuffer_create(struct drm_i915_gem_object *obj,
10092 struct drm_mode_fb_cmd2 *mode_cmd)
Chris Wilsond2dff872011-04-19 08:36:26 +010010093{
10094 struct intel_framebuffer *intel_fb;
10095 int ret;
10096
10097 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010098 if (!intel_fb)
Chris Wilsond2dff872011-04-19 08:36:26 +010010099 return ERR_PTR(-ENOMEM);
Chris Wilsond2dff872011-04-19 08:36:26 +010010100
Chris Wilson24dbf512017-02-15 10:59:18 +000010101 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010102 if (ret)
10103 goto err;
Chris Wilsond2dff872011-04-19 08:36:26 +010010104
10105 return &intel_fb->base;
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010106
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010107err:
10108 kfree(intel_fb);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010109 return ERR_PTR(ret);
Chris Wilsond2dff872011-04-19 08:36:26 +010010110}
10111
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010112static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10113 struct drm_crtc *crtc)
Chris Wilsond2dff872011-04-19 08:36:26 +010010114{
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010115 struct drm_plane *plane;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010116 struct drm_plane_state *plane_state;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010117 int ret, i;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010118
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010119 ret = drm_atomic_add_affected_planes(state, crtc);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010120 if (ret)
10121 return ret;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010122
10123 for_each_new_plane_in_state(state, plane, plane_state, i) {
10124 if (plane_state->crtc != crtc)
10125 continue;
10126
10127 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10128 if (ret)
10129 return ret;
10130
10131 drm_atomic_set_fb_for_plane(plane_state, NULL);
10132 }
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010133
10134 return 0;
10135}
10136
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010137int intel_get_load_detect_pipe(struct drm_connector *connector,
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010138 const struct drm_display_mode *mode,
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010139 struct intel_load_detect_pipe *old,
10140 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010141{
10142 struct intel_crtc *intel_crtc;
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010143 struct intel_encoder *intel_encoder =
10144 intel_attached_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -080010145 struct drm_crtc *possible_crtc;
Chris Wilson4ef69c72010-09-09 15:14:28 +010010146 struct drm_encoder *encoder = &intel_encoder->base;
Jesse Barnes79e53942008-11-07 14:24:08 -080010147 struct drm_crtc *crtc = NULL;
10148 struct drm_device *dev = encoder->dev;
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010149 struct drm_i915_private *dev_priv = to_i915(dev);
Rob Clark51fd3712013-11-19 12:10:12 -050010150 struct drm_mode_config *config = &dev->mode_config;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010151 struct drm_atomic_state *state = NULL, *restore_state = NULL;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010152 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010153 struct intel_crtc_state *crtc_state;
Rob Clark51fd3712013-11-19 12:10:12 -050010154 int ret, i = -1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010155
Chris Wilsond2dff872011-04-19 08:36:26 +010010156 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010157 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010158 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010159
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010160 old->restore_state = NULL;
10161
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010162 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
Daniel Vetter6e9f7982014-05-29 23:54:47 +020010163
Jesse Barnes79e53942008-11-07 14:24:08 -080010164 /*
10165 * Algorithm gets a little messy:
Chris Wilson7a5e4802011-04-19 23:21:12 +010010166 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010167 * - if the connector already has an assigned crtc, use it (but make
10168 * sure it's on first)
Chris Wilson7a5e4802011-04-19 23:21:12 +010010169 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010170 * - try to find the first unused crtc that can drive this connector,
10171 * and use that if we find one
Jesse Barnes79e53942008-11-07 14:24:08 -080010172 */
10173
10174 /* See if we already have a CRTC for this connector */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010175 if (connector->state->crtc) {
10176 crtc = connector->state->crtc;
Chris Wilson8261b192011-04-19 23:18:09 +010010177
Rob Clark51fd3712013-11-19 12:10:12 -050010178 ret = drm_modeset_lock(&crtc->mutex, ctx);
10179 if (ret)
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010180 goto fail;
Chris Wilson8261b192011-04-19 23:18:09 +010010181
10182 /* Make sure the crtc and connector are running */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010183 goto found;
Jesse Barnes79e53942008-11-07 14:24:08 -080010184 }
10185
10186 /* Find an unused one (if possible) */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +010010187 for_each_crtc(dev, possible_crtc) {
Jesse Barnes79e53942008-11-07 14:24:08 -080010188 i++;
10189 if (!(encoder->possible_crtcs & (1 << i)))
10190 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010191
10192 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10193 if (ret)
10194 goto fail;
10195
10196 if (possible_crtc->state->enable) {
10197 drm_modeset_unlock(&possible_crtc->mutex);
Ville Syrjäläa4592492014-08-11 13:15:36 +030010198 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010199 }
Ville Syrjäläa4592492014-08-11 13:15:36 +030010200
10201 crtc = possible_crtc;
10202 break;
Jesse Barnes79e53942008-11-07 14:24:08 -080010203 }
10204
10205 /*
10206 * If we didn't find an unused CRTC, don't use any.
10207 */
10208 if (!crtc) {
Chris Wilson71731882011-04-19 23:10:58 +010010209 DRM_DEBUG_KMS("no pipe available for load-detect\n");
Dan Carpenterf4bf77b2017-04-14 22:54:25 +030010210 ret = -ENODEV;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010211 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010212 }
10213
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010214found:
10215 intel_crtc = to_intel_crtc(crtc);
10216
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010217 state = drm_atomic_state_alloc(dev);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010218 restore_state = drm_atomic_state_alloc(dev);
10219 if (!state || !restore_state) {
10220 ret = -ENOMEM;
10221 goto fail;
10222 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010223
10224 state->acquire_ctx = ctx;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010225 restore_state->acquire_ctx = ctx;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010226
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010227 connector_state = drm_atomic_get_connector_state(state, connector);
10228 if (IS_ERR(connector_state)) {
10229 ret = PTR_ERR(connector_state);
10230 goto fail;
10231 }
10232
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010233 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10234 if (ret)
10235 goto fail;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010236
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010237 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10238 if (IS_ERR(crtc_state)) {
10239 ret = PTR_ERR(crtc_state);
10240 goto fail;
10241 }
10242
Maarten Lankhorst49d6fa22015-05-11 10:45:15 +020010243 crtc_state->base.active = crtc_state->base.enable = true;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010244
Chris Wilson64927112011-04-20 07:25:26 +010010245 if (!mode)
10246 mode = &load_detect_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -080010247
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010248 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010249 if (ret)
10250 goto fail;
10251
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010252 ret = intel_modeset_disable_planes(state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010253 if (ret)
10254 goto fail;
10255
10256 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10257 if (!ret)
10258 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
Ville Syrjäläbe90cc32018-03-22 17:23:12 +020010259 if (!ret)
10260 ret = drm_atomic_add_affected_planes(restore_state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010261 if (ret) {
10262 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10263 goto fail;
10264 }
Ander Conselvan de Oliveira8c7b5cc2015-04-21 17:13:19 +030010265
Maarten Lankhorst3ba86072016-02-29 09:18:57 +010010266 ret = drm_atomic_commit(state);
10267 if (ret) {
Chris Wilson64927112011-04-20 07:25:26 +010010268 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010269 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010270 }
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010271
10272 old->restore_state = restore_state;
Chris Wilson7abbd112017-01-19 11:37:49 +000010273 drm_atomic_state_put(state);
Chris Wilson71731882011-04-19 23:10:58 +010010274
Jesse Barnes79e53942008-11-07 14:24:08 -080010275 /* let the connector get through one full cycle before testing */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010276 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Chris Wilson71731882011-04-19 23:10:58 +010010277 return true;
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010278
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010279fail:
Chris Wilson7fb71c82016-10-19 12:37:43 +010010280 if (state) {
10281 drm_atomic_state_put(state);
10282 state = NULL;
10283 }
10284 if (restore_state) {
10285 drm_atomic_state_put(restore_state);
10286 restore_state = NULL;
10287 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010288
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010289 if (ret == -EDEADLK)
10290 return ret;
Rob Clark51fd3712013-11-19 12:10:12 -050010291
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010292 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -080010293}
10294
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010295void intel_release_load_detect_pipe(struct drm_connector *connector,
Ander Conselvan de Oliveira49172fe2015-03-20 16:18:02 +020010296 struct intel_load_detect_pipe *old,
10297 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010298{
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010299 struct intel_encoder *intel_encoder =
10300 intel_attached_encoder(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +010010301 struct drm_encoder *encoder = &intel_encoder->base;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010302 struct drm_atomic_state *state = old->restore_state;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010303 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080010304
Chris Wilsond2dff872011-04-19 08:36:26 +010010305 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010306 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010307 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010308
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010309 if (!state)
Chris Wilson0622a532011-04-21 09:32:11 +010010310 return;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010311
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010010312 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Chris Wilson08536952016-10-14 13:18:18 +010010313 if (ret)
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010314 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
Chris Wilson08536952016-10-14 13:18:18 +010010315 drm_atomic_state_put(state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010316}
10317
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010318static int i9xx_pll_refclk(struct drm_device *dev,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010319 const struct intel_crtc_state *pipe_config)
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010320{
Chris Wilsonfac5e232016-07-04 11:34:36 +010010321 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010322 u32 dpll = pipe_config->dpll_hw_state.dpll;
10323
10324 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
Ville Syrjäläe91e9412013-12-09 18:54:16 +020010325 return dev_priv->vbt.lvds_ssc_freq;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010010326 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010327 return 120000;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010010328 else if (!IS_GEN2(dev_priv))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010329 return 96000;
10330 else
10331 return 48000;
10332}
10333
Jesse Barnes79e53942008-11-07 14:24:08 -080010334/* Returns the clock of the currently programmed mode of the given pipe. */
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010335static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010336 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -080010337{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010338 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010010339 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010340 int pipe = pipe_config->cpu_transcoder;
Ville Syrjälä293623f2013-09-13 16:18:46 +030010341 u32 dpll = pipe_config->dpll_hw_state.dpll;
Jesse Barnes79e53942008-11-07 14:24:08 -080010342 u32 fp;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +030010343 struct dpll clock;
Imre Deakdccbea32015-06-22 23:35:51 +030010344 int port_clock;
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010345 int refclk = i9xx_pll_refclk(dev, pipe_config);
Jesse Barnes79e53942008-11-07 14:24:08 -080010346
10347 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
Ville Syrjälä293623f2013-09-13 16:18:46 +030010348 fp = pipe_config->dpll_hw_state.fp0;
Jesse Barnes79e53942008-11-07 14:24:08 -080010349 else
Ville Syrjälä293623f2013-09-13 16:18:46 +030010350 fp = pipe_config->dpll_hw_state.fp1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010351
10352 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010353 if (IS_PINEVIEW(dev_priv)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010354 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10355 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
Shaohua Li21778322009-02-23 15:19:16 +080010356 } else {
10357 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10358 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10359 }
10360
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010010361 if (!IS_GEN2(dev_priv)) {
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010362 if (IS_PINEVIEW(dev_priv))
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010363 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10364 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
Shaohua Li21778322009-02-23 15:19:16 +080010365 else
10366 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
Jesse Barnes79e53942008-11-07 14:24:08 -080010367 DPLL_FPA01_P1_POST_DIV_SHIFT);
10368
10369 switch (dpll & DPLL_MODE_MASK) {
10370 case DPLLB_MODE_DAC_SERIAL:
10371 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10372 5 : 10;
10373 break;
10374 case DPLLB_MODE_LVDS:
10375 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10376 7 : 14;
10377 break;
10378 default:
Zhao Yakui28c97732009-10-09 11:39:41 +080010379 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
Jesse Barnes79e53942008-11-07 14:24:08 -080010380 "mode\n", (int)(dpll & DPLL_MODE_MASK));
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010381 return;
Jesse Barnes79e53942008-11-07 14:24:08 -080010382 }
10383
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010384 if (IS_PINEVIEW(dev_priv))
Imre Deakdccbea32015-06-22 23:35:51 +030010385 port_clock = pnv_calc_dpll_params(refclk, &clock);
Daniel Vetterac58c3f2013-06-01 17:16:17 +020010386 else
Imre Deakdccbea32015-06-22 23:35:51 +030010387 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010388 } else {
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010010389 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010390 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
Jesse Barnes79e53942008-11-07 14:24:08 -080010391
10392 if (is_lvds) {
10393 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10394 DPLL_FPA01_P1_POST_DIV_SHIFT);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010395
10396 if (lvds & LVDS_CLKB_POWER_UP)
10397 clock.p2 = 7;
10398 else
10399 clock.p2 = 14;
Jesse Barnes79e53942008-11-07 14:24:08 -080010400 } else {
10401 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10402 clock.p1 = 2;
10403 else {
10404 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10405 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10406 }
10407 if (dpll & PLL_P2_DIVIDE_BY_4)
10408 clock.p2 = 4;
10409 else
10410 clock.p2 = 2;
Jesse Barnes79e53942008-11-07 14:24:08 -080010411 }
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010412
Imre Deakdccbea32015-06-22 23:35:51 +030010413 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010414 }
10415
Ville Syrjälä18442d02013-09-13 16:00:08 +030010416 /*
10417 * This value includes pixel_multiplier. We will use
Damien Lespiau241bfc32013-09-25 16:45:37 +010010418 * port_clock to compute adjusted_mode.crtc_clock in the
Ville Syrjälä18442d02013-09-13 16:00:08 +030010419 * encoder's get_config() function.
10420 */
Imre Deakdccbea32015-06-22 23:35:51 +030010421 pipe_config->port_clock = port_clock;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010422}
10423
Ville Syrjälä6878da02013-09-13 15:59:11 +030010424int intel_dotclock_calculate(int link_freq,
10425 const struct intel_link_m_n *m_n)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010426{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010427 /*
10428 * The calculation for the data clock is:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010429 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010430 * But we want to avoid losing precison if possible, so:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010431 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010432 *
10433 * and the link clock is simpler:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010434 * link_clock = (m * link_clock) / n
Jesse Barnes79e53942008-11-07 14:24:08 -080010435 */
10436
Ville Syrjälä6878da02013-09-13 15:59:11 +030010437 if (!m_n->link_n)
10438 return 0;
10439
Chris Wilson31236982017-09-13 11:51:53 +010010440 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 +030010441}
10442
Ville Syrjälä18442d02013-09-13 16:00:08 +030010443static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010444 struct intel_crtc_state *pipe_config)
Ville Syrjälä6878da02013-09-13 15:59:11 +030010445{
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010446 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä18442d02013-09-13 16:00:08 +030010447
10448 /* read out port_clock from the DPLL */
10449 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä6878da02013-09-13 15:59:11 +030010450
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010451 /*
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010452 * In case there is an active pipe without active ports,
10453 * we may need some idea for the dotclock anyway.
10454 * Calculate one based on the FDI configuration.
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010455 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020010456 pipe_config->base.adjusted_mode.crtc_clock =
Ville Syrjälä21a727b2016-02-17 21:41:10 +020010457 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjälä18442d02013-09-13 16:00:08 +030010458 &pipe_config->fdi_m_n);
Jesse Barnes79e53942008-11-07 14:24:08 -080010459}
10460
Ville Syrjäläde330812017-10-09 19:19:50 +030010461/* Returns the currently programmed mode of the given encoder. */
10462struct drm_display_mode *
10463intel_encoder_current_mode(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080010464{
Ville Syrjäläde330812017-10-09 19:19:50 +030010465 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10466 struct intel_crtc_state *crtc_state;
Jesse Barnes79e53942008-11-07 14:24:08 -080010467 struct drm_display_mode *mode;
Ville Syrjäläde330812017-10-09 19:19:50 +030010468 struct intel_crtc *crtc;
10469 enum pipe pipe;
10470
10471 if (!encoder->get_hw_state(encoder, &pipe))
10472 return NULL;
10473
10474 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Jesse Barnes79e53942008-11-07 14:24:08 -080010475
10476 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10477 if (!mode)
10478 return NULL;
10479
Ville Syrjäläde330812017-10-09 19:19:50 +030010480 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10481 if (!crtc_state) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010482 kfree(mode);
10483 return NULL;
10484 }
10485
Ville Syrjäläde330812017-10-09 19:19:50 +030010486 crtc_state->base.crtc = &crtc->base;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010487
Ville Syrjäläde330812017-10-09 19:19:50 +030010488 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10489 kfree(crtc_state);
10490 kfree(mode);
10491 return NULL;
10492 }
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010493
Ville Syrjäläde330812017-10-09 19:19:50 +030010494 encoder->get_config(encoder, crtc_state);
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010495
Ville Syrjäläde330812017-10-09 19:19:50 +030010496 intel_mode_from_pipe_config(mode, crtc_state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010497
Ville Syrjäläde330812017-10-09 19:19:50 +030010498 kfree(crtc_state);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010499
Jesse Barnes79e53942008-11-07 14:24:08 -080010500 return mode;
10501}
10502
10503static void intel_crtc_destroy(struct drm_crtc *crtc)
10504{
10505 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10506
10507 drm_crtc_cleanup(crtc);
10508 kfree(intel_crtc);
10509}
10510
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010511/**
10512 * intel_wm_need_update - Check whether watermarks need updating
10513 * @plane: drm plane
10514 * @state: new plane state
10515 *
10516 * Check current plane state versus the new one to determine whether
10517 * watermarks need to be recalculated.
10518 *
10519 * Returns true or false.
10520 */
10521static bool intel_wm_need_update(struct drm_plane *plane,
10522 struct drm_plane_state *state)
10523{
Matt Roperd21fbe82015-09-24 15:53:12 -070010524 struct intel_plane_state *new = to_intel_plane_state(state);
10525 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10526
10527 /* Update watermarks on tiling or size changes. */
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010528 if (new->base.visible != cur->base.visible)
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010529 return true;
10530
10531 if (!cur->base.fb || !new->base.fb)
10532 return false;
10533
Ville Syrjäläbae781b2016-11-16 13:33:16 +020010534 if (cur->base.fb->modifier != new->base.fb->modifier ||
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010535 cur->base.rotation != new->base.rotation ||
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010536 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10537 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10538 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10539 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010540 return true;
10541
10542 return false;
10543}
10544
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010545static bool needs_scaling(const struct intel_plane_state *state)
Matt Roperd21fbe82015-09-24 15:53:12 -070010546{
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010547 int src_w = drm_rect_width(&state->base.src) >> 16;
10548 int src_h = drm_rect_height(&state->base.src) >> 16;
10549 int dst_w = drm_rect_width(&state->base.dst);
10550 int dst_h = drm_rect_height(&state->base.dst);
Matt Roperd21fbe82015-09-24 15:53:12 -070010551
10552 return (src_w != dst_w || src_h != dst_h);
10553}
10554
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010555int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10556 struct drm_crtc_state *crtc_state,
10557 const struct intel_plane_state *old_plane_state,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010558 struct drm_plane_state *plane_state)
10559{
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010560 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010561 struct drm_crtc *crtc = crtc_state->crtc;
10562 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010563 struct intel_plane *plane = to_intel_plane(plane_state->plane);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010564 struct drm_device *dev = crtc->dev;
Matt Ropered4a6a72016-02-23 17:20:13 -080010565 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010566 bool mode_changed = needs_modeset(crtc_state);
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010567 bool was_crtc_enabled = old_crtc_state->base.active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010568 bool is_crtc_enabled = crtc_state->active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010569 bool turn_off, turn_on, visible, was_visible;
10570 struct drm_framebuffer *fb = plane_state->fb;
Ville Syrjälä78108b72016-05-27 20:59:19 +030010571 int ret;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010572
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010573 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010574 ret = skl_update_scaler_plane(
10575 to_intel_crtc_state(crtc_state),
10576 to_intel_plane_state(plane_state));
10577 if (ret)
10578 return ret;
10579 }
10580
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010581 was_visible = old_plane_state->base.visible;
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010582 visible = plane_state->visible;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010583
10584 if (!was_crtc_enabled && WARN_ON(was_visible))
10585 was_visible = false;
10586
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010587 /*
10588 * Visibility is calculated as if the crtc was on, but
10589 * after scaler setup everything depends on it being off
10590 * when the crtc isn't active.
Ville Syrjäläf818ffe2016-04-29 17:31:18 +030010591 *
10592 * FIXME this is wrong for watermarks. Watermarks should also
10593 * be computed as if the pipe would be active. Perhaps move
10594 * per-plane wm computation to the .check_plane() hook, and
10595 * only combine the results from all planes in the current place?
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010596 */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010597 if (!is_crtc_enabled) {
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010598 plane_state->visible = visible = false;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010599 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10600 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010601
10602 if (!was_visible && !visible)
10603 return 0;
10604
Maarten Lankhorste8861672016-02-24 11:24:26 +010010605 if (fb != old_plane_state->base.fb)
10606 pipe_config->fb_changed = true;
10607
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010608 turn_off = was_visible && (!visible || mode_changed);
10609 turn_on = visible && (!was_visible || mode_changed);
10610
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010611 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010612 intel_crtc->base.base.id, intel_crtc->base.name,
10613 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010614 fb ? fb->base.id : -1);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010615
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010616 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 +020010617 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010618 was_visible, visible,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010619 turn_off, turn_on, mode_changed);
10620
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010621 if (turn_on) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010622 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010623 pipe_config->update_wm_pre = true;
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010624
10625 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010626 if (plane->id != PLANE_CURSOR)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010627 pipe_config->disable_cxsr = true;
10628 } else if (turn_off) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010629 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010630 pipe_config->update_wm_post = true;
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010631
Ville Syrjälä852eb002015-06-24 22:00:07 +030010632 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010633 if (plane->id != PLANE_CURSOR)
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010634 pipe_config->disable_cxsr = true;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010635 } else if (intel_wm_need_update(&plane->base, plane_state)) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010636 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010637 /* FIXME bollocks */
10638 pipe_config->update_wm_pre = true;
10639 pipe_config->update_wm_post = true;
10640 }
Ville Syrjälä852eb002015-06-24 22:00:07 +030010641 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010642
Rodrigo Vivi8be6ca82015-08-24 16:38:23 -070010643 if (visible || was_visible)
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010644 pipe_config->fb_bits |= plane->frontbuffer_bit;
Ville Syrjäläa9ff8712015-06-24 21:59:34 +030010645
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010646 /*
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010647 * ILK/SNB DVSACNTR/Sprite Enable
10648 * IVB SPR_CTL/Sprite Enable
10649 * "When in Self Refresh Big FIFO mode, a write to enable the
10650 * plane will be internally buffered and delayed while Big FIFO
10651 * mode is exiting."
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010652 *
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010653 * Which means that enabling the sprite can take an extra frame
10654 * when we start in big FIFO mode (LP1+). Thus we need to drop
10655 * down to LP0 and wait for vblank in order to make sure the
10656 * sprite gets enabled on the next vblank after the register write.
10657 * Doing otherwise would risk enabling the sprite one frame after
10658 * we've already signalled flip completion. We can resume LP1+
10659 * once the sprite has been enabled.
10660 *
10661 *
10662 * WaCxSRDisabledForSpriteScaling:ivb
10663 * IVB SPR_SCALE/Scaling Enable
10664 * "Low Power watermarks must be disabled for at least one
10665 * frame before enabling sprite scaling, and kept disabled
10666 * until sprite scaling is disabled."
10667 *
10668 * ILK/SNB DVSASCALE/Scaling Enable
10669 * "When in Self Refresh Big FIFO mode, scaling enable will be
10670 * masked off while Big FIFO mode is exiting."
10671 *
10672 * Despite the w/a only being listed for IVB we assume that
10673 * the ILK/SNB note has similar ramifications, hence we apply
10674 * the w/a on all three platforms.
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010675 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010676 if (plane->id == PLANE_SPRITE0 &&
10677 (IS_GEN5(dev_priv) || IS_GEN6(dev_priv) ||
10678 IS_IVYBRIDGE(dev_priv)) &&
10679 (turn_on || (!needs_scaling(old_plane_state) &&
10680 needs_scaling(to_intel_plane_state(plane_state)))))
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010681 pipe_config->disable_lp_wm = true;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010682
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010683 return 0;
10684}
10685
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010686static bool encoders_cloneable(const struct intel_encoder *a,
10687 const struct intel_encoder *b)
10688{
10689 /* masks could be asymmetric, so check both ways */
10690 return a == b || (a->cloneable & (1 << b->type) &&
10691 b->cloneable & (1 << a->type));
10692}
10693
10694static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10695 struct intel_crtc *crtc,
10696 struct intel_encoder *encoder)
10697{
10698 struct intel_encoder *source_encoder;
10699 struct drm_connector *connector;
10700 struct drm_connector_state *connector_state;
10701 int i;
10702
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010010703 for_each_new_connector_in_state(state, connector, connector_state, i) {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010704 if (connector_state->crtc != &crtc->base)
10705 continue;
10706
10707 source_encoder =
10708 to_intel_encoder(connector_state->best_encoder);
10709 if (!encoders_cloneable(encoder, source_encoder))
10710 return false;
10711 }
10712
10713 return true;
10714}
10715
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010716static int icl_add_linked_planes(struct intel_atomic_state *state)
10717{
10718 struct intel_plane *plane, *linked;
10719 struct intel_plane_state *plane_state, *linked_plane_state;
10720 int i;
10721
10722 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10723 linked = plane_state->linked_plane;
10724
10725 if (!linked)
10726 continue;
10727
10728 linked_plane_state = intel_atomic_get_plane_state(state, linked);
10729 if (IS_ERR(linked_plane_state))
10730 return PTR_ERR(linked_plane_state);
10731
10732 WARN_ON(linked_plane_state->linked_plane != plane);
10733 WARN_ON(linked_plane_state->slave == plane_state->slave);
10734 }
10735
10736 return 0;
10737}
10738
10739static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
10740{
10741 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10742 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10743 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
10744 struct intel_plane *plane, *linked;
10745 struct intel_plane_state *plane_state;
10746 int i;
10747
10748 if (INTEL_GEN(dev_priv) < 11)
10749 return 0;
10750
10751 /*
10752 * Destroy all old plane links and make the slave plane invisible
10753 * in the crtc_state->active_planes mask.
10754 */
10755 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10756 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
10757 continue;
10758
10759 plane_state->linked_plane = NULL;
10760 if (plane_state->slave && !plane_state->base.visible)
10761 crtc_state->active_planes &= ~BIT(plane->id);
10762
10763 plane_state->slave = false;
10764 }
10765
10766 if (!crtc_state->nv12_planes)
10767 return 0;
10768
10769 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10770 struct intel_plane_state *linked_state = NULL;
10771
10772 if (plane->pipe != crtc->pipe ||
10773 !(crtc_state->nv12_planes & BIT(plane->id)))
10774 continue;
10775
10776 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
10777 if (!icl_is_nv12_y_plane(linked->id))
10778 continue;
10779
10780 if (crtc_state->active_planes & BIT(linked->id))
10781 continue;
10782
10783 linked_state = intel_atomic_get_plane_state(state, linked);
10784 if (IS_ERR(linked_state))
10785 return PTR_ERR(linked_state);
10786
10787 break;
10788 }
10789
10790 if (!linked_state) {
10791 DRM_DEBUG_KMS("Need %d free Y planes for NV12\n",
10792 hweight8(crtc_state->nv12_planes));
10793
10794 return -EINVAL;
10795 }
10796
10797 plane_state->linked_plane = linked;
10798
10799 linked_state->slave = true;
10800 linked_state->linked_plane = plane;
10801 crtc_state->active_planes |= BIT(linked->id);
10802 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
10803 }
10804
10805 return 0;
10806}
10807
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010808static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10809 struct drm_crtc_state *crtc_state)
10810{
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +020010811 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010010812 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010813 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +020010814 struct intel_crtc_state *pipe_config =
10815 to_intel_crtc_state(crtc_state);
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010816 struct drm_atomic_state *state = crtc_state->state;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020010817 int ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010818 bool mode_changed = needs_modeset(crtc_state);
10819
Ville Syrjälä852eb002015-06-24 22:00:07 +030010820 if (mode_changed && !crtc_state->active)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010821 pipe_config->update_wm_post = true;
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020010822
Maarten Lankhorstad421372015-06-15 12:33:42 +020010823 if (mode_changed && crtc_state->enable &&
10824 dev_priv->display.crtc_compute_clock &&
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020010825 !WARN_ON(pipe_config->shared_dpll)) {
Maarten Lankhorstad421372015-06-15 12:33:42 +020010826 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10827 pipe_config);
10828 if (ret)
10829 return ret;
10830 }
10831
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010832 if (crtc_state->color_mgmt_changed) {
10833 ret = intel_color_check(crtc, crtc_state);
10834 if (ret)
10835 return ret;
Lionel Landwerline7852a42016-05-25 14:30:41 +010010836
10837 /*
10838 * Changing color management on Intel hardware is
10839 * handled as part of planes update.
10840 */
10841 crtc_state->planes_changed = true;
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010842 }
10843
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010844 ret = 0;
Matt Roper86c8bbb2015-09-24 15:53:16 -070010845 if (dev_priv->display.compute_pipe_wm) {
Maarten Lankhorste3bddde2016-03-01 11:07:22 +010010846 ret = dev_priv->display.compute_pipe_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080010847 if (ret) {
10848 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
Matt Roper86c8bbb2015-09-24 15:53:16 -070010849 return ret;
Matt Ropered4a6a72016-02-23 17:20:13 -080010850 }
10851 }
10852
10853 if (dev_priv->display.compute_intermediate_wm &&
10854 !to_intel_atomic_state(state)->skip_intermediate_wm) {
10855 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10856 return 0;
10857
10858 /*
10859 * Calculate 'intermediate' watermarks that satisfy both the
10860 * old state and the new state. We can program these
10861 * immediately.
10862 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000010863 ret = dev_priv->display.compute_intermediate_wm(dev,
Matt Ropered4a6a72016-02-23 17:20:13 -080010864 intel_crtc,
10865 pipe_config);
10866 if (ret) {
10867 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10868 return ret;
10869 }
Ville Syrjäläe3d54572016-05-13 10:10:42 -070010870 } else if (dev_priv->display.compute_intermediate_wm) {
10871 if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
10872 pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
Matt Roper86c8bbb2015-09-24 15:53:16 -070010873 }
10874
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000010875 if (INTEL_GEN(dev_priv) >= 9) {
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010876 if (mode_changed)
10877 ret = skl_update_scaler_crtc(pipe_config);
10878
10879 if (!ret)
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010880 ret = icl_check_nv12_planes(pipe_config);
10881 if (!ret)
Mahesh Kumar73b0ca82017-05-26 20:45:46 +053010882 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10883 pipe_config);
10884 if (!ret)
Ander Conselvan de Oliveira6ebc6922017-02-23 09:15:59 +020010885 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010886 pipe_config);
10887 }
10888
Maarten Lankhorst24f28452017-11-22 19:39:01 +010010889 if (HAS_IPS(dev_priv))
10890 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10891
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010892 return ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010893}
10894
Jani Nikula65b38e02015-04-13 11:26:56 +030010895static const struct drm_crtc_helper_funcs intel_helper_funcs = {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010896 .atomic_check = intel_crtc_atomic_check,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010010897};
10898
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010899static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10900{
10901 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010010902 struct drm_connector_list_iter conn_iter;
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010903
Daniel Vetterf9e905c2017-03-01 10:52:25 +010010904 drm_connector_list_iter_begin(dev, &conn_iter);
10905 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter8863dc72016-05-06 15:39:03 +020010906 if (connector->base.state->crtc)
Thomas Zimmermannef196b52018-06-18 13:01:50 +020010907 drm_connector_put(&connector->base);
Daniel Vetter8863dc72016-05-06 15:39:03 +020010908
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010909 if (connector->base.encoder) {
10910 connector->base.state->best_encoder =
10911 connector->base.encoder;
10912 connector->base.state->crtc =
10913 connector->base.encoder->crtc;
Daniel Vetter8863dc72016-05-06 15:39:03 +020010914
Thomas Zimmermannef196b52018-06-18 13:01:50 +020010915 drm_connector_get(&connector->base);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010916 } else {
10917 connector->base.state->best_encoder = NULL;
10918 connector->base.state->crtc = NULL;
10919 }
10920 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010010921 drm_connector_list_iter_end(&conn_iter);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010922}
10923
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010924static void
Robin Schroereba905b2014-05-18 02:24:50 +020010925connected_sink_compute_bpp(struct intel_connector *connector,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010926 struct intel_crtc_state *pipe_config)
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010010927{
Ville Syrjälä6a2a5c52016-09-28 16:51:42 +030010928 const struct drm_display_info *info = &connector->base.display_info;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010929 int bpp = pipe_config->pipe_bpp;
10930
10931 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
Ville Syrjälä6a2a5c52016-09-28 16:51:42 +030010932 connector->base.base.id,
10933 connector->base.name);
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010934
10935 /* Don't use an invalid EDID bpc value */
Ville Syrjälä6a2a5c52016-09-28 16:51:42 +030010936 if (info->bpc != 0 && info->bpc * 3 < bpp) {
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010937 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
Ville Syrjälä6a2a5c52016-09-28 16:51:42 +030010938 bpp, info->bpc * 3);
10939 pipe_config->pipe_bpp = info->bpc * 3;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010940 }
10941
Mario Kleiner196f9542016-07-06 12:05:45 +020010942 /* Clamp bpp to 8 on screens without EDID 1.4 */
Ville Syrjälä6a2a5c52016-09-28 16:51:42 +030010943 if (info->bpc == 0 && bpp > 24) {
Mario Kleiner196f9542016-07-06 12:05:45 +020010944 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10945 bpp);
10946 pipe_config->pipe_bpp = 24;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010947 }
10948}
10949
10950static int
10951compute_baseline_pipe_bpp(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010952 struct intel_crtc_state *pipe_config)
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010953{
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010010954 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020010955 struct drm_atomic_state *state;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030010956 struct drm_connector *connector;
10957 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020010958 int bpp, i;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010010959
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010010960 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10961 IS_CHERRYVIEW(dev_priv)))
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010010962 bpp = 10*3;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010010963 else if (INTEL_GEN(dev_priv) >= 5)
Daniel Vetterd328c9d2015-04-10 16:22:37 +020010964 bpp = 12*3;
10965 else
10966 bpp = 8*3;
10967
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010010968
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010010969 pipe_config->pipe_bpp = bpp;
10970
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020010971 state = pipe_config->base.state;
10972
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010010973 /* Clamp display bpp to EDID value */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010010974 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030010975 if (connector_state->crtc != &crtc->base)
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020010976 continue;
10977
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030010978 connected_sink_compute_bpp(to_intel_connector(connector),
10979 pipe_config);
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010010980 }
10981
10982 return bpp;
10983}
10984
Daniel Vetter644db712013-09-19 14:53:58 +020010985static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
10986{
10987 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10988 "type: 0x%x flags: 0x%x\n",
Damien Lespiau13428302013-09-25 16:45:36 +010010989 mode->crtc_clock,
Daniel Vetter644db712013-09-19 14:53:58 +020010990 mode->crtc_hdisplay, mode->crtc_hsync_start,
10991 mode->crtc_hsync_end, mode->crtc_htotal,
10992 mode->crtc_vdisplay, mode->crtc_vsync_start,
10993 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
10994}
10995
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000010996static inline void
10997intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
Tvrtko Ursulina4309652016-11-17 12:30:09 +000010998 unsigned int lane_count, struct intel_link_m_n *m_n)
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000010999{
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011000 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11001 id, lane_count,
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011002 m_n->gmch_m, m_n->gmch_n,
11003 m_n->link_m, m_n->link_n, m_n->tu);
11004}
11005
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011006#define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11007
11008static const char * const output_type_str[] = {
11009 OUTPUT_TYPE(UNUSED),
11010 OUTPUT_TYPE(ANALOG),
11011 OUTPUT_TYPE(DVO),
11012 OUTPUT_TYPE(SDVO),
11013 OUTPUT_TYPE(LVDS),
11014 OUTPUT_TYPE(TVOUT),
11015 OUTPUT_TYPE(HDMI),
11016 OUTPUT_TYPE(DP),
11017 OUTPUT_TYPE(EDP),
11018 OUTPUT_TYPE(DSI),
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011019 OUTPUT_TYPE(DDI),
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011020 OUTPUT_TYPE(DP_MST),
11021};
11022
11023#undef OUTPUT_TYPE
11024
11025static void snprintf_output_types(char *buf, size_t len,
11026 unsigned int output_types)
11027{
11028 char *str = buf;
11029 int i;
11030
11031 str[0] = '\0';
11032
11033 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11034 int r;
11035
11036 if ((output_types & BIT(i)) == 0)
11037 continue;
11038
11039 r = snprintf(str, len, "%s%s",
11040 str != buf ? "," : "", output_type_str[i]);
11041 if (r >= len)
11042 break;
11043 str += r;
11044 len -= r;
11045
11046 output_types &= ~BIT(i);
11047 }
11048
11049 WARN_ON_ONCE(output_types != 0);
11050}
11051
Shashank Sharmad9facae2018-10-12 11:53:07 +053011052static const char * const output_format_str[] = {
11053 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11054 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011055 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
Shashank Sharma8c79f842018-10-12 11:53:09 +053011056 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
Shashank Sharmad9facae2018-10-12 11:53:07 +053011057};
11058
11059static const char *output_formats(enum intel_output_format format)
11060{
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011061 if (format >= ARRAY_SIZE(output_format_str))
Shashank Sharmad9facae2018-10-12 11:53:07 +053011062 format = INTEL_OUTPUT_FORMAT_INVALID;
11063 return output_format_str[format];
11064}
11065
Daniel Vetterc0b03412013-05-28 12:05:54 +020011066static void intel_dump_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011067 struct intel_crtc_state *pipe_config,
Daniel Vetterc0b03412013-05-28 12:05:54 +020011068 const char *context)
11069{
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011070 struct drm_device *dev = crtc->base.dev;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011071 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011072 struct drm_plane *plane;
11073 struct intel_plane *intel_plane;
11074 struct intel_plane_state *state;
11075 struct drm_framebuffer *fb;
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011076 char buf[64];
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011077
Tvrtko Ursulin66766e42016-11-17 12:30:10 +000011078 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11079 crtc->base.base.id, crtc->base.name, context);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011080
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011081 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11082 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11083 buf, pipe_config->output_types);
11084
Shashank Sharmad9facae2018-10-12 11:53:07 +053011085 DRM_DEBUG_KMS("output format: %s\n",
11086 output_formats(pipe_config->output_format));
11087
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011088 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11089 transcoder_name(pipe_config->cpu_transcoder),
Daniel Vetterc0b03412013-05-28 12:05:54 +020011090 pipe_config->pipe_bpp, pipe_config->dither);
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011091
11092 if (pipe_config->has_pch_encoder)
11093 intel_dump_m_n_config(pipe_config, "fdi",
11094 pipe_config->fdi_lanes,
11095 &pipe_config->fdi_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011096
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011097 if (intel_crtc_has_dp_encoder(pipe_config)) {
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011098 intel_dump_m_n_config(pipe_config, "dp m_n",
11099 pipe_config->lane_count, &pipe_config->dp_m_n);
Tvrtko Ursulind806e682016-11-17 15:44:09 +000011100 if (pipe_config->has_drrs)
11101 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11102 pipe_config->lane_count,
11103 &pipe_config->dp_m2_n2);
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011104 }
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011105
Daniel Vetter55072d12014-11-20 16:10:28 +010011106 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011107 pipe_config->has_audio, pipe_config->has_infoframe);
Daniel Vetter55072d12014-11-20 16:10:28 +010011108
Daniel Vetterc0b03412013-05-28 12:05:54 +020011109 DRM_DEBUG_KMS("requested mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011110 drm_mode_debug_printmodeline(&pipe_config->base.mode);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011111 DRM_DEBUG_KMS("adjusted mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011112 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11113 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011114 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011115 pipe_config->port_clock,
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011116 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11117 pipe_config->pixel_rate);
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011118
11119 if (INTEL_GEN(dev_priv) >= 9)
11120 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11121 crtc->num_scalers,
11122 pipe_config->scaler_state.scaler_users,
11123 pipe_config->scaler_state.scaler_id);
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011124
11125 if (HAS_GMCH_DISPLAY(dev_priv))
11126 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11127 pipe_config->gmch_pfit.control,
11128 pipe_config->gmch_pfit.pgm_ratios,
11129 pipe_config->gmch_pfit.lvds_border_bits);
11130 else
11131 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11132 pipe_config->pch_pfit.pos,
11133 pipe_config->pch_pfit.size,
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000011134 enableddisabled(pipe_config->pch_pfit.enabled));
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011135
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011136 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11137 pipe_config->ips_enabled, pipe_config->double_wide);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011138
Ander Conselvan de Oliveiraf50b79f2016-12-29 17:22:12 +020011139 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
Tvrtko Ursulin415ff0f2015-05-14 13:38:31 +010011140
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011141 DRM_DEBUG_KMS("planes on this crtc\n");
11142 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011143 struct drm_format_name_buf format_name;
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011144 intel_plane = to_intel_plane(plane);
11145 if (intel_plane->pipe != crtc->pipe)
11146 continue;
11147
11148 state = to_intel_plane_state(plane->state);
11149 fb = state->base.fb;
11150 if (!fb) {
Ville Syrjälä1d577e02016-05-27 20:59:25 +030011151 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11152 plane->base.id, plane->name, state->scaler_id);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011153 continue;
11154 }
11155
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011156 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11157 plane->base.id, plane->name,
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011158 fb->base.id, fb->width, fb->height,
Ville Syrjälä438b74a2016-12-14 23:32:55 +020011159 drm_get_format_name(fb->format->format, &format_name));
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011160 if (INTEL_GEN(dev_priv) >= 9)
11161 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11162 state->scaler_id,
11163 state->base.src.x1 >> 16,
11164 state->base.src.y1 >> 16,
11165 drm_rect_width(&state->base.src) >> 16,
11166 drm_rect_height(&state->base.src) >> 16,
11167 state->base.dst.x1, state->base.dst.y1,
11168 drm_rect_width(&state->base.dst),
11169 drm_rect_height(&state->base.dst));
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011170 }
Daniel Vetterc0b03412013-05-28 12:05:54 +020011171}
11172
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011173static bool check_digital_port_conflicts(struct drm_atomic_state *state)
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011174{
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011175 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011176 struct drm_connector *connector;
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011177 struct drm_connector_list_iter conn_iter;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011178 unsigned int used_ports = 0;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011179 unsigned int used_mst_ports = 0;
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011180 bool ret = true;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011181
11182 /*
11183 * Walk the connector list instead of the encoder
11184 * list to detect the problem on ddi platforms
11185 * where there's just one encoder per digital port.
11186 */
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011187 drm_connector_list_iter_begin(dev, &conn_iter);
11188 drm_for_each_connector_iter(connector, &conn_iter) {
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011189 struct drm_connector_state *connector_state;
11190 struct intel_encoder *encoder;
11191
Maarten Lankhorst8b694492018-04-09 14:46:55 +020011192 connector_state = drm_atomic_get_new_connector_state(state, connector);
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011193 if (!connector_state)
11194 connector_state = connector->state;
11195
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011196 if (!connector_state->best_encoder)
11197 continue;
11198
11199 encoder = to_intel_encoder(connector_state->best_encoder);
11200
11201 WARN_ON(!connector_state->crtc);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011202
11203 switch (encoder->type) {
11204 unsigned int port_mask;
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011205 case INTEL_OUTPUT_DDI:
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011206 if (WARN_ON(!HAS_DDI(to_i915(dev))))
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011207 break;
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -050011208 /* else: fall through */
Ville Syrjäläcca05022016-06-22 21:57:06 +030011209 case INTEL_OUTPUT_DP:
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011210 case INTEL_OUTPUT_HDMI:
11211 case INTEL_OUTPUT_EDP:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011212 port_mask = 1 << encoder->port;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011213
11214 /* the same port mustn't appear more than once */
11215 if (used_ports & port_mask)
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011216 ret = false;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011217
11218 used_ports |= port_mask;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011219 break;
11220 case INTEL_OUTPUT_DP_MST:
11221 used_mst_ports |=
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011222 1 << encoder->port;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011223 break;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011224 default:
11225 break;
11226 }
11227 }
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011228 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011229
Ville Syrjälä477321e2016-07-28 17:50:40 +030011230 /* can't mix MST and SST/HDMI on the same port */
11231 if (used_ports & used_mst_ports)
11232 return false;
11233
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011234 return ret;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011235}
11236
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011237static void
11238clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11239{
Ville Syrjäläff32c542017-03-02 19:14:57 +020011240 struct drm_i915_private *dev_priv =
11241 to_i915(crtc_state->base.crtc->dev);
Chandra Konduru663a3642015-04-07 15:28:41 -070011242 struct intel_crtc_scaler_state scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011243 struct intel_dpll_hw_state dpll_hw_state;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011244 struct intel_shared_dpll *shared_dpll;
Ville Syrjäläff32c542017-03-02 19:14:57 +020011245 struct intel_crtc_wm_state wm_state;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011246 bool force_thru, ips_force_disable;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011247
Ander Conselvan de Oliveira7546a382015-05-20 09:03:27 +030011248 /* FIXME: before the switch to atomic started, a new pipe_config was
11249 * kzalloc'd. Code that depends on any field being zero should be
11250 * fixed, so that the crtc_state can be safely duplicated. For now,
11251 * only fields that are know to not cause problems are preserved. */
11252
Chandra Konduru663a3642015-04-07 15:28:41 -070011253 scaler_state = crtc_state->scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011254 shared_dpll = crtc_state->shared_dpll;
11255 dpll_hw_state = crtc_state->dpll_hw_state;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +020011256 force_thru = crtc_state->pch_pfit.force_thru;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011257 ips_force_disable = crtc_state->ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011258 if (IS_G4X(dev_priv) ||
11259 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläff32c542017-03-02 19:14:57 +020011260 wm_state = crtc_state->wm;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011261
Chris Wilsond2fa80a2017-03-03 15:46:44 +000011262 /* Keep base drm_crtc_state intact, only clear our extended struct */
11263 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11264 memset(&crtc_state->base + 1, 0,
11265 sizeof(*crtc_state) - sizeof(crtc_state->base));
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011266
Chandra Konduru663a3642015-04-07 15:28:41 -070011267 crtc_state->scaler_state = scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011268 crtc_state->shared_dpll = shared_dpll;
11269 crtc_state->dpll_hw_state = dpll_hw_state;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +020011270 crtc_state->pch_pfit.force_thru = force_thru;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011271 crtc_state->ips_force_disable = ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011272 if (IS_G4X(dev_priv) ||
11273 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläff32c542017-03-02 19:14:57 +020011274 crtc_state->wm = wm_state;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011275}
11276
Ander Conselvan de Oliveira548ee152015-04-21 17:13:02 +030011277static int
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011278intel_modeset_pipe_config(struct drm_crtc *crtc,
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011279 struct intel_crtc_state *pipe_config)
Daniel Vetter7758a112012-07-08 19:40:39 +020011280{
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011281 struct drm_atomic_state *state = pipe_config->base.state;
Daniel Vetter7758a112012-07-08 19:40:39 +020011282 struct intel_encoder *encoder;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011283 struct drm_connector *connector;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011284 struct drm_connector_state *connector_state;
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011285 int base_bpp, ret = -EINVAL;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011286 int i;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011287 bool retry = true;
Daniel Vetter7758a112012-07-08 19:40:39 +020011288
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011289 clear_intel_crtc_state(pipe_config);
Daniel Vetter7758a112012-07-08 19:40:39 +020011290
Daniel Vettere143a212013-07-04 12:01:15 +020011291 pipe_config->cpu_transcoder =
11292 (enum transcoder) to_intel_crtc(crtc)->pipe;
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011293
Imre Deak2960bc92013-07-30 13:36:32 +030011294 /*
11295 * Sanitize sync polarity flags based on requested ones. If neither
11296 * positive or negative polarity is requested, treat this as meaning
11297 * negative polarity.
11298 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011299 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011300 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011301 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011302
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011303 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011304 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011305 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011306
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011307 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11308 pipe_config);
11309 if (base_bpp < 0)
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011310 goto fail;
11311
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011312 /*
11313 * Determine the real pipe dimensions. Note that stereo modes can
11314 * increase the actual pipe size due to the frame doubling and
11315 * insertion of additional space for blanks between the frame. This
11316 * is stored in the crtc timings. We use the requested mode to do this
11317 * computation to clearly distinguish it from the adjusted mode, which
11318 * can be changed by the connectors in the below retry loop.
11319 */
Daniel Vetter196cd5d2017-01-25 07:26:56 +010011320 drm_mode_get_hv_timing(&pipe_config->base.mode,
Gustavo Padovanecb7e162014-12-01 15:40:09 -080011321 &pipe_config->pipe_src_w,
11322 &pipe_config->pipe_src_h);
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011323
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011324 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011325 if (connector_state->crtc != crtc)
11326 continue;
11327
11328 encoder = to_intel_encoder(connector_state->best_encoder);
11329
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011330 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11331 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11332 goto fail;
11333 }
11334
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011335 /*
11336 * Determine output_types before calling the .compute_config()
11337 * hooks so that the hooks can use this information safely.
11338 */
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011339 if (encoder->compute_output_type)
11340 pipe_config->output_types |=
11341 BIT(encoder->compute_output_type(encoder, pipe_config,
11342 connector_state));
11343 else
11344 pipe_config->output_types |= BIT(encoder->type);
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011345 }
11346
Daniel Vettere29c22c2013-02-21 00:00:16 +010011347encoder_retry:
Daniel Vetteref1b4602013-06-01 17:17:04 +020011348 /* Ensure the port clock defaults are reset when retrying. */
Daniel Vetterff9a6752013-06-01 17:16:21 +020011349 pipe_config->port_clock = 0;
Daniel Vetteref1b4602013-06-01 17:17:04 +020011350 pipe_config->pixel_multiplier = 1;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011351
Daniel Vetter135c81b2013-07-21 21:37:09 +020011352 /* Fill in default crtc timings, allow encoders to overwrite them. */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011353 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11354 CRTC_STEREO_DOUBLE);
Daniel Vetter135c81b2013-07-21 21:37:09 +020011355
Daniel Vetter7758a112012-07-08 19:40:39 +020011356 /* Pass our mode to the connectors and the CRTC to give them a chance to
11357 * adjust it according to limitations or connector properties, and also
11358 * a chance to reject the mode entirely.
11359 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011360 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011361 if (connector_state->crtc != crtc)
11362 continue;
11363
11364 encoder = to_intel_encoder(connector_state->best_encoder);
11365
Maarten Lankhorst0a478c22016-08-09 17:04:05 +020011366 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
Daniel Vetterefea6e82013-07-21 21:36:59 +020011367 DRM_DEBUG_KMS("Encoder config failure\n");
Daniel Vetter7758a112012-07-08 19:40:39 +020011368 goto fail;
11369 }
11370 }
11371
Daniel Vetterff9a6752013-06-01 17:16:21 +020011372 /* Set default port clock if not overwritten by the encoder. Needs to be
11373 * done afterwards in case the encoder adjusts the mode. */
11374 if (!pipe_config->port_clock)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011375 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
Damien Lespiau241bfc32013-09-25 16:45:37 +010011376 * pipe_config->pixel_multiplier;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011377
Daniel Vettera43f6e02013-06-07 23:10:32 +020011378 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
Daniel Vettere29c22c2013-02-21 00:00:16 +010011379 if (ret < 0) {
Daniel Vetter7758a112012-07-08 19:40:39 +020011380 DRM_DEBUG_KMS("CRTC fixup failed\n");
11381 goto fail;
11382 }
Daniel Vettere29c22c2013-02-21 00:00:16 +010011383
11384 if (ret == RETRY) {
11385 if (WARN(!retry, "loop in pipe configuration computation\n")) {
11386 ret = -EINVAL;
11387 goto fail;
11388 }
11389
11390 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11391 retry = false;
11392 goto encoder_retry;
11393 }
11394
Daniel Vettere8fa4272015-08-12 11:43:34 +020011395 /* Dithering seems to not pass-through bits correctly when it should, so
Manasi Navare611032b2017-01-24 08:21:49 -080011396 * only enable it on 6bpc panels and when its not a compliance
11397 * test requesting 6bpc video pattern.
11398 */
11399 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11400 !pipe_config->dither_force_disable;
Daniel Vetter62f0ace2015-08-26 18:57:26 +020011401 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011402 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011403
Daniel Vetter7758a112012-07-08 19:40:39 +020011404fail:
Ander Conselvan de Oliveira548ee152015-04-21 17:13:02 +030011405 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011406}
11407
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011408static bool intel_fuzzy_clock_check(int clock1, int clock2)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011409{
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011410 int diff;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011411
11412 if (clock1 == clock2)
11413 return true;
11414
11415 if (!clock1 || !clock2)
11416 return false;
11417
11418 diff = abs(clock1 - clock2);
11419
11420 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11421 return true;
11422
11423 return false;
11424}
11425
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011426static bool
11427intel_compare_m_n(unsigned int m, unsigned int n,
11428 unsigned int m2, unsigned int n2,
11429 bool exact)
11430{
11431 if (m == m2 && n == n2)
11432 return true;
11433
11434 if (exact || !m || !n || !m2 || !n2)
11435 return false;
11436
11437 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11438
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011439 if (n > n2) {
11440 while (n > n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011441 m2 <<= 1;
11442 n2 <<= 1;
11443 }
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011444 } else if (n < n2) {
11445 while (n < n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011446 m <<= 1;
11447 n <<= 1;
11448 }
11449 }
11450
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011451 if (n != n2)
11452 return false;
11453
11454 return intel_fuzzy_clock_check(m, m2);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011455}
11456
11457static bool
11458intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11459 struct intel_link_m_n *m2_n2,
11460 bool adjust)
11461{
11462 if (m_n->tu == m2_n2->tu &&
11463 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11464 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11465 intel_compare_m_n(m_n->link_m, m_n->link_n,
11466 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11467 if (adjust)
11468 *m2_n2 = *m_n;
11469
11470 return true;
11471 }
11472
11473 return false;
11474}
11475
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011476static void __printf(3, 4)
11477pipe_config_err(bool adjust, const char *name, const char *format, ...)
11478{
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011479 struct va_format vaf;
11480 va_list args;
11481
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011482 va_start(args, format);
11483 vaf.fmt = format;
11484 vaf.va = &args;
11485
Joe Perches99a95482018-03-13 15:02:15 -070011486 if (adjust)
11487 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11488 else
11489 drm_err("mismatch in %s %pV", name, &vaf);
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011490
11491 va_end(args);
11492}
11493
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011494static bool
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011495intel_pipe_config_compare(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011496 struct intel_crtc_state *current_config,
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011497 struct intel_crtc_state *pipe_config,
11498 bool adjust)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011499{
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011500 bool ret = true;
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011501 bool fixup_inherited = adjust &&
11502 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11503 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011504
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011505#define PIPE_CONF_CHECK_X(name) do { \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011506 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011507 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011508 "(expected 0x%08x, found 0x%08x)\n", \
11509 current_config->name, \
11510 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011511 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011512 } \
11513} while (0)
Daniel Vetter66e985c2013-06-05 13:34:20 +020011514
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011515#define PIPE_CONF_CHECK_I(name) do { \
Daniel Vetter08a24032013-04-19 11:25:34 +020011516 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011517 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter08a24032013-04-19 11:25:34 +020011518 "(expected %i, found %i)\n", \
11519 current_config->name, \
11520 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011521 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011522 } \
11523} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011524
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011525#define PIPE_CONF_CHECK_BOOL(name) do { \
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011526 if (current_config->name != pipe_config->name) { \
11527 pipe_config_err(adjust, __stringify(name), \
11528 "(expected %s, found %s)\n", \
11529 yesno(current_config->name), \
11530 yesno(pipe_config->name)); \
11531 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011532 } \
11533} while (0)
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011534
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011535/*
11536 * Checks state where we only read out the enabling, but not the entire
11537 * state itself (like full infoframes or ELD for audio). These states
11538 * require a full modeset on bootup to fix up.
11539 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011540#define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011541 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11542 PIPE_CONF_CHECK_BOOL(name); \
11543 } else { \
11544 pipe_config_err(adjust, __stringify(name), \
11545 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11546 yesno(current_config->name), \
11547 yesno(pipe_config->name)); \
11548 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011549 } \
11550} while (0)
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011551
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011552#define PIPE_CONF_CHECK_P(name) do { \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011553 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011554 pipe_config_err(adjust, __stringify(name), \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011555 "(expected %p, found %p)\n", \
11556 current_config->name, \
11557 pipe_config->name); \
11558 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011559 } \
11560} while (0)
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011561
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011562#define PIPE_CONF_CHECK_M_N(name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011563 if (!intel_compare_link_m_n(&current_config->name, \
11564 &pipe_config->name,\
11565 adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011566 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011567 "(expected tu %i gmch %i/%i link %i/%i, " \
11568 "found tu %i, gmch %i/%i link %i/%i)\n", \
11569 current_config->name.tu, \
11570 current_config->name.gmch_m, \
11571 current_config->name.gmch_n, \
11572 current_config->name.link_m, \
11573 current_config->name.link_n, \
11574 pipe_config->name.tu, \
11575 pipe_config->name.gmch_m, \
11576 pipe_config->name.gmch_n, \
11577 pipe_config->name.link_m, \
11578 pipe_config->name.link_n); \
11579 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011580 } \
11581} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011582
Daniel Vetter55c561a2016-03-30 11:34:36 +020011583/* This is required for BDW+ where there is only one set of registers for
11584 * switching between high and low RR.
11585 * This macro can be used whenever a comparison has to be made between one
11586 * hw state and multiple sw state variables.
11587 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011588#define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011589 if (!intel_compare_link_m_n(&current_config->name, \
11590 &pipe_config->name, adjust) && \
11591 !intel_compare_link_m_n(&current_config->alt_name, \
11592 &pipe_config->name, adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011593 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011594 "(expected tu %i gmch %i/%i link %i/%i, " \
11595 "or tu %i gmch %i/%i link %i/%i, " \
11596 "found tu %i, gmch %i/%i link %i/%i)\n", \
11597 current_config->name.tu, \
11598 current_config->name.gmch_m, \
11599 current_config->name.gmch_n, \
11600 current_config->name.link_m, \
11601 current_config->name.link_n, \
11602 current_config->alt_name.tu, \
11603 current_config->alt_name.gmch_m, \
11604 current_config->alt_name.gmch_n, \
11605 current_config->alt_name.link_m, \
11606 current_config->alt_name.link_n, \
11607 pipe_config->name.tu, \
11608 pipe_config->name.gmch_m, \
11609 pipe_config->name.gmch_n, \
11610 pipe_config->name.link_m, \
11611 pipe_config->name.link_n); \
11612 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011613 } \
11614} while (0)
Daniel Vetter88adfff2013-03-28 10:42:01 +010011615
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011616#define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011617 if ((current_config->name ^ pipe_config->name) & (mask)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011618 pipe_config_err(adjust, __stringify(name), \
11619 "(%x) (expected %i, found %i)\n", \
11620 (mask), \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011621 current_config->name & (mask), \
11622 pipe_config->name & (mask)); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011623 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011624 } \
11625} while (0)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011626
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011627#define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011628 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011629 pipe_config_err(adjust, __stringify(name), \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011630 "(expected %i, found %i)\n", \
11631 current_config->name, \
11632 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011633 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011634 } \
11635} while (0)
Ville Syrjälä5e550652013-09-06 23:29:07 +030011636
Daniel Vetterbb760062013-06-06 14:55:52 +020011637#define PIPE_CONF_QUIRK(quirk) \
11638 ((current_config->quirks | pipe_config->quirks) & (quirk))
11639
Daniel Vettereccb1402013-05-22 00:50:22 +020011640 PIPE_CONF_CHECK_I(cpu_transcoder);
11641
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011642 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
Daniel Vetter08a24032013-04-19 11:25:34 +020011643 PIPE_CONF_CHECK_I(fdi_lanes);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011644 PIPE_CONF_CHECK_M_N(fdi_m_n);
Daniel Vetter08a24032013-04-19 11:25:34 +020011645
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030011646 PIPE_CONF_CHECK_I(lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +030011647 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011648
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011649 if (INTEL_GEN(dev_priv) < 8) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011650 PIPE_CONF_CHECK_M_N(dp_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011651
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011652 if (current_config->has_drrs)
11653 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11654 } else
11655 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +030011656
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011657 PIPE_CONF_CHECK_X(output_types);
Jani Nikulaa65347b2015-11-27 12:21:46 +020011658
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011659 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11660 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11661 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11662 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11663 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11664 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011665
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011666 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11667 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11668 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11669 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11670 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11671 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011672
Daniel Vetterc93f54c2013-06-27 19:47:19 +020011673 PIPE_CONF_CHECK_I(pixel_multiplier);
Shashank Sharmad9facae2018-10-12 11:53:07 +053011674 PIPE_CONF_CHECK_I(output_format);
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011675 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010011676 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010011677 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011678 PIPE_CONF_CHECK_BOOL(limited_color_range);
Shashank Sharma15953632017-03-13 16:54:03 +053011679
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011680 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11681 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011682 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
Daniel Vetter6c49f242013-06-06 12:45:25 +020011683
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011684 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
Daniel Vetter9ed109a2014-04-24 23:54:52 +020011685
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011686 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011687 DRM_MODE_FLAG_INTERLACE);
11688
Daniel Vetterbb760062013-06-06 14:55:52 +020011689 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011690 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011691 DRM_MODE_FLAG_PHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011692 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011693 DRM_MODE_FLAG_NHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011694 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011695 DRM_MODE_FLAG_PVSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011696 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011697 DRM_MODE_FLAG_NVSYNC);
11698 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -070011699
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030011700 PIPE_CONF_CHECK_X(gmch_pfit.control);
Daniel Vettere2ff2d42015-07-15 14:15:50 +020011701 /* pfit ratios are autocomputed by the hw on gen4+ */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011702 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä7f7d8dd2016-03-15 16:40:07 +020011703 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030011704 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
Daniel Vetter99535992014-04-13 12:00:33 +020011705
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020011706 if (!adjust) {
11707 PIPE_CONF_CHECK_I(pipe_src_w);
11708 PIPE_CONF_CHECK_I(pipe_src_h);
11709
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011710 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020011711 if (current_config->pch_pfit.enabled) {
11712 PIPE_CONF_CHECK_X(pch_pfit.pos);
11713 PIPE_CONF_CHECK_X(pch_pfit.size);
11714 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +020011715
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020011716 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011717 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020011718 }
Chandra Kondurua1b22782015-04-07 15:28:45 -070011719
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011720 PIPE_CONF_CHECK_BOOL(double_wide);
Ville Syrjälä282740f2013-09-04 18:30:03 +030011721
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011722 PIPE_CONF_CHECK_P(shared_dpll);
Daniel Vetter66e985c2013-06-05 13:34:20 +020011723 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
Daniel Vetter8bcc2792013-06-05 13:34:28 +020011724 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
Daniel Vetter66e985c2013-06-05 13:34:20 +020011725 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11726 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -030011727 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
Maarten Lankhorst00490c22015-11-16 14:42:12 +010011728 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
Damien Lespiau3f4cd192014-11-13 14:55:21 +000011729 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11730 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11731 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
Paulo Zanoni2de38132017-09-22 17:53:42 -030011732 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11733 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11734 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11735 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11736 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11737 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11738 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11739 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11740 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11741 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11742 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11743 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
Paulo Zanonic27e9172018-04-27 16:14:36 -070011744 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11745 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11746 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11747 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11748 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11749 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11750 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11751 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11752 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11753 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
Daniel Vetterc0d43d62013-06-07 23:11:08 +020011754
Ville Syrjälä47eacba2016-04-12 22:14:35 +030011755 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11756 PIPE_CONF_CHECK_X(dsi_pll.div);
11757
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011758 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä42571ae2013-09-06 23:29:00 +030011759 PIPE_CONF_CHECK_I(pipe_bpp);
11760
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011761 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
Jesse Barnesa9a7e982014-01-20 14:18:04 -080011762 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
Ville Syrjälä5e550652013-09-06 23:29:07 +030011763
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030011764 PIPE_CONF_CHECK_I(min_voltage_level);
11765
Daniel Vetter66e985c2013-06-05 13:34:20 +020011766#undef PIPE_CONF_CHECK_X
Daniel Vetter08a24032013-04-19 11:25:34 +020011767#undef PIPE_CONF_CHECK_I
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011768#undef PIPE_CONF_CHECK_BOOL
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011769#undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011770#undef PIPE_CONF_CHECK_P
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011771#undef PIPE_CONF_CHECK_FLAGS
Ville Syrjälä5e550652013-09-06 23:29:07 +030011772#undef PIPE_CONF_CHECK_CLOCK_FUZZY
Daniel Vetterbb760062013-06-06 14:55:52 +020011773#undef PIPE_CONF_QUIRK
Daniel Vetter627eb5a2013-04-29 19:33:42 +020011774
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011775 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011776}
11777
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020011778static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11779 const struct intel_crtc_state *pipe_config)
11780{
11781 if (pipe_config->has_pch_encoder) {
Ville Syrjälä21a727b2016-02-17 21:41:10 +020011782 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020011783 &pipe_config->fdi_m_n);
11784 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11785
11786 /*
11787 * FDI already provided one idea for the dotclock.
11788 * Yell if the encoder disagrees.
11789 */
11790 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11791 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11792 fdi_dotclock, dotclock);
11793 }
11794}
11795
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020011796static void verify_wm_state(struct drm_crtc *crtc,
11797 struct drm_crtc_state *new_state)
Damien Lespiau08db6652014-11-04 17:06:52 +000011798{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011799 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Damien Lespiau08db6652014-11-04 17:06:52 +000011800 struct skl_ddb_allocation hw_ddb, *sw_ddb;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011801 struct skl_pipe_wm hw_wm, *sw_wm;
11802 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11803 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011804 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11805 const enum pipe pipe = intel_crtc->pipe;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011806 int plane, level, max_level = ilk_wm_max_level(dev_priv);
Damien Lespiau08db6652014-11-04 17:06:52 +000011807
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011808 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
Damien Lespiau08db6652014-11-04 17:06:52 +000011809 return;
11810
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011811 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
Maarten Lankhorst03af79e2016-10-26 15:41:36 +020011812 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011813
Damien Lespiau08db6652014-11-04 17:06:52 +000011814 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11815 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11816
Mahesh Kumar74bd8002018-04-26 19:55:15 +053011817 if (INTEL_GEN(dev_priv) >= 11)
11818 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11819 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11820 sw_ddb->enabled_slices,
11821 hw_ddb.enabled_slices);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011822 /* planes */
Matt Roper8b364b42016-10-26 15:51:28 -070011823 for_each_universal_plane(dev_priv, pipe, plane) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011824 hw_plane_wm = &hw_wm.planes[plane];
11825 sw_plane_wm = &sw_wm->planes[plane];
Damien Lespiau08db6652014-11-04 17:06:52 +000011826
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011827 /* Watermarks */
11828 for (level = 0; level <= max_level; level++) {
11829 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11830 &sw_plane_wm->wm[level]))
11831 continue;
Damien Lespiau08db6652014-11-04 17:06:52 +000011832
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011833 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",
11834 pipe_name(pipe), plane + 1, level,
11835 sw_plane_wm->wm[level].plane_en,
11836 sw_plane_wm->wm[level].plane_res_b,
11837 sw_plane_wm->wm[level].plane_res_l,
11838 hw_plane_wm->wm[level].plane_en,
11839 hw_plane_wm->wm[level].plane_res_b,
11840 hw_plane_wm->wm[level].plane_res_l);
11841 }
11842
11843 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11844 &sw_plane_wm->trans_wm)) {
11845 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",
11846 pipe_name(pipe), plane + 1,
11847 sw_plane_wm->trans_wm.plane_en,
11848 sw_plane_wm->trans_wm.plane_res_b,
11849 sw_plane_wm->trans_wm.plane_res_l,
11850 hw_plane_wm->trans_wm.plane_en,
11851 hw_plane_wm->trans_wm.plane_res_b,
11852 hw_plane_wm->trans_wm.plane_res_l);
11853 }
11854
11855 /* DDB */
11856 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11857 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11858
11859 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040011860 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 -040011861 pipe_name(pipe), plane + 1,
11862 sw_ddb_entry->start, sw_ddb_entry->end,
11863 hw_ddb_entry->start, hw_ddb_entry->end);
11864 }
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011865 }
11866
Lyude27082492016-08-24 07:48:10 +020011867 /*
11868 * cursor
11869 * If the cursor plane isn't active, we may not have updated it's ddb
11870 * allocation. In that case since the ddb allocation will be updated
11871 * once the plane becomes visible, we can skip this check
11872 */
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030011873 if (1) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011874 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11875 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011876
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011877 /* Watermarks */
11878 for (level = 0; level <= max_level; level++) {
11879 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11880 &sw_plane_wm->wm[level]))
11881 continue;
11882
11883 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",
11884 pipe_name(pipe), level,
11885 sw_plane_wm->wm[level].plane_en,
11886 sw_plane_wm->wm[level].plane_res_b,
11887 sw_plane_wm->wm[level].plane_res_l,
11888 hw_plane_wm->wm[level].plane_en,
11889 hw_plane_wm->wm[level].plane_res_b,
11890 hw_plane_wm->wm[level].plane_res_l);
11891 }
11892
11893 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11894 &sw_plane_wm->trans_wm)) {
11895 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11896 pipe_name(pipe),
11897 sw_plane_wm->trans_wm.plane_en,
11898 sw_plane_wm->trans_wm.plane_res_b,
11899 sw_plane_wm->trans_wm.plane_res_l,
11900 hw_plane_wm->trans_wm.plane_en,
11901 hw_plane_wm->trans_wm.plane_res_b,
11902 hw_plane_wm->trans_wm.plane_res_l);
11903 }
11904
11905 /* DDB */
11906 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11907 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11908
11909 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040011910 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
Lyude27082492016-08-24 07:48:10 +020011911 pipe_name(pipe),
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011912 sw_ddb_entry->start, sw_ddb_entry->end,
11913 hw_ddb_entry->start, hw_ddb_entry->end);
Lyude27082492016-08-24 07:48:10 +020011914 }
Damien Lespiau08db6652014-11-04 17:06:52 +000011915 }
11916}
11917
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020011918static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010011919verify_connector_state(struct drm_device *dev,
11920 struct drm_atomic_state *state,
11921 struct drm_crtc *crtc)
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011922{
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020011923 struct drm_connector *connector;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011924 struct drm_connector_state *new_conn_state;
Maarten Lankhorst677100c2016-11-08 13:55:41 +010011925 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011926
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011927 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020011928 struct drm_encoder *encoder = connector->encoder;
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020011929 struct drm_crtc_state *crtc_state = NULL;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020011930
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011931 if (new_conn_state->crtc != crtc)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011932 continue;
11933
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020011934 if (crtc)
11935 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11936
11937 intel_connector_verify_state(crtc_state, new_conn_state);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011938
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011939 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020011940 "connector's atomic encoder doesn't match legacy encoder\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011941 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020011942}
11943
11944static void
Daniel Vetter86b04262017-03-01 10:52:26 +010011945verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020011946{
11947 struct intel_encoder *encoder;
Daniel Vetter86b04262017-03-01 10:52:26 +010011948 struct drm_connector *connector;
11949 struct drm_connector_state *old_conn_state, *new_conn_state;
11950 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011951
Damien Lespiaub2784e12014-08-05 11:29:37 +010011952 for_each_intel_encoder(dev, encoder) {
Daniel Vetter86b04262017-03-01 10:52:26 +010011953 bool enabled = false, found = false;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020011954 enum pipe pipe;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011955
11956 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11957 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030011958 encoder->base.name);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011959
Daniel Vetter86b04262017-03-01 10:52:26 +010011960 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
11961 new_conn_state, i) {
11962 if (old_conn_state->best_encoder == &encoder->base)
11963 found = true;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020011964
Daniel Vetter86b04262017-03-01 10:52:26 +010011965 if (new_conn_state->best_encoder != &encoder->base)
11966 continue;
11967 found = enabled = true;
11968
11969 I915_STATE_WARN(new_conn_state->crtc !=
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020011970 encoder->base.crtc,
11971 "connector's crtc doesn't match encoder crtc\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011972 }
Daniel Vetter86b04262017-03-01 10:52:26 +010011973
11974 if (!found)
11975 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +100011976
Rob Clarke2c719b2014-12-15 13:56:32 -050011977 I915_STATE_WARN(!!encoder->base.crtc != enabled,
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011978 "encoder's enabled state mismatch "
11979 "(expected %i, found %i)\n",
11980 !!encoder->base.crtc, enabled);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020011981
11982 if (!encoder->base.crtc) {
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020011983 bool active;
11984
11985 active = encoder->get_hw_state(encoder, &pipe);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020011986 I915_STATE_WARN(active,
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020011987 "encoder detached but still enabled on pipe %c.\n",
11988 pipe_name(pipe));
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020011989 }
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011990 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020011991}
11992
11993static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020011994verify_crtc_state(struct drm_crtc *crtc,
11995 struct drm_crtc_state *old_crtc_state,
11996 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020011997{
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011998 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010011999 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012000 struct intel_encoder *encoder;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012001 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12002 struct intel_crtc_state *pipe_config, *sw_config;
12003 struct drm_atomic_state *old_state;
12004 bool active;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012005
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012006 old_state = old_crtc_state->state;
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020012007 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012008 pipe_config = to_intel_crtc_state(old_crtc_state);
12009 memset(pipe_config, 0, sizeof(*pipe_config));
12010 pipe_config->base.crtc = crtc;
12011 pipe_config->base.state = old_state;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012012
Ville Syrjälä78108b72016-05-27 20:59:19 +030012013 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012014
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012015 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012016
Ville Syrjäläe56134b2017-06-01 17:36:19 +030012017 /* we keep both pipes enabled on 830 */
12018 if (IS_I830(dev_priv))
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012019 active = new_crtc_state->active;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012020
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012021 I915_STATE_WARN(new_crtc_state->active != active,
12022 "crtc active state doesn't match with hw state "
12023 "(expected %i, found %i)\n", new_crtc_state->active, active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012024
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012025 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12026 "transitional active state does not match atomic hw state "
12027 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012028
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012029 for_each_encoder_on_crtc(dev, crtc, encoder) {
12030 enum pipe pipe;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012031
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012032 active = encoder->get_hw_state(encoder, &pipe);
12033 I915_STATE_WARN(active != new_crtc_state->active,
12034 "[ENCODER:%i] active %i with crtc active %i\n",
12035 encoder->base.base.id, active, new_crtc_state->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012036
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012037 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12038 "Encoder connected to wrong pipe %c\n",
12039 pipe_name(pipe));
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012040
Ville Syrjäläe1214b92017-10-27 22:31:23 +030012041 if (active)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012042 encoder->get_config(encoder, pipe_config);
12043 }
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012044
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020012045 intel_crtc_compute_pixel_rate(pipe_config);
12046
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012047 if (!new_crtc_state->active)
12048 return;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012049
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012050 intel_pipe_config_sanity_check(dev_priv, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012051
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012052 sw_config = to_intel_crtc_state(new_crtc_state);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012053 if (!intel_pipe_config_compare(dev_priv, sw_config,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012054 pipe_config, false)) {
12055 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12056 intel_dump_pipe_config(intel_crtc, pipe_config,
12057 "[hw state]");
12058 intel_dump_pipe_config(intel_crtc, sw_config,
12059 "[sw state]");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012060 }
12061}
12062
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012063static void
Ville Syrjäläcff109f2017-11-17 21:19:17 +020012064intel_verify_planes(struct intel_atomic_state *state)
12065{
12066 struct intel_plane *plane;
12067 const struct intel_plane_state *plane_state;
12068 int i;
12069
12070 for_each_new_intel_plane_in_state(state, plane,
12071 plane_state, i)
12072 assert_plane(plane, plane_state->base.visible);
12073}
12074
12075static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012076verify_single_dpll_state(struct drm_i915_private *dev_priv,
12077 struct intel_shared_dpll *pll,
12078 struct drm_crtc *crtc,
12079 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012080{
12081 struct intel_dpll_hw_state dpll_hw_state;
Ville Syrjälä40560e22018-06-26 22:47:11 +030012082 unsigned int crtc_mask;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012083 bool active;
12084
12085 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12086
Lucas De Marchi72f775f2018-03-20 15:06:34 -070012087 DRM_DEBUG_KMS("%s\n", pll->info->name);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012088
Lucas De Marchiee1398b2018-03-20 15:06:33 -070012089 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012090
Lucas De Marchi5cd281f2018-03-20 15:06:36 -070012091 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012092 I915_STATE_WARN(!pll->on && pll->active_mask,
12093 "pll in active use but not on in sw tracking\n");
12094 I915_STATE_WARN(pll->on && !pll->active_mask,
12095 "pll is on but not used by any active crtc\n");
12096 I915_STATE_WARN(pll->on != active,
12097 "pll on state mismatch (expected %i, found %i)\n",
12098 pll->on, active);
12099 }
12100
12101 if (!crtc) {
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012102 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012103 "more active pll users than references: %x vs %x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012104 pll->active_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012105
12106 return;
12107 }
12108
Ville Syrjälä40560e22018-06-26 22:47:11 +030012109 crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012110
12111 if (new_state->active)
12112 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12113 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12114 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12115 else
12116 I915_STATE_WARN(pll->active_mask & crtc_mask,
12117 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12118 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12119
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012120 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012121 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012122 crtc_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012123
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012124 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012125 &dpll_hw_state,
12126 sizeof(dpll_hw_state)),
12127 "pll hw state mismatch\n");
12128}
12129
12130static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012131verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12132 struct drm_crtc_state *old_crtc_state,
12133 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012134{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012135 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012136 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12137 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12138
12139 if (new_state->shared_dpll)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012140 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012141
12142 if (old_state->shared_dpll &&
12143 old_state->shared_dpll != new_state->shared_dpll) {
Ville Syrjälä40560e22018-06-26 22:47:11 +030012144 unsigned int crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012145 struct intel_shared_dpll *pll = old_state->shared_dpll;
12146
12147 I915_STATE_WARN(pll->active_mask & crtc_mask,
12148 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12149 pipe_name(drm_crtc_index(crtc)));
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012150 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012151 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12152 pipe_name(drm_crtc_index(crtc)));
12153 }
12154}
12155
12156static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012157intel_modeset_verify_crtc(struct drm_crtc *crtc,
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012158 struct drm_atomic_state *state,
12159 struct drm_crtc_state *old_state,
12160 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012161{
Daniel Vetter5a21b662016-05-24 17:13:53 +020012162 if (!needs_modeset(new_state) &&
12163 !to_intel_crtc_state(new_state)->update_pipe)
12164 return;
12165
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012166 verify_wm_state(crtc, new_state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012167 verify_connector_state(crtc->dev, state, crtc);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012168 verify_crtc_state(crtc, old_state, new_state);
12169 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012170}
12171
12172static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012173verify_disabled_dpll_state(struct drm_device *dev)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012174{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012175 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012176 int i;
Daniel Vetter53589012013-06-05 13:34:16 +020012177
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012178 for (i = 0; i < dev_priv->num_shared_dpll; i++)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012179 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012180}
Daniel Vetter53589012013-06-05 13:34:16 +020012181
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012182static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012183intel_modeset_verify_disabled(struct drm_device *dev,
12184 struct drm_atomic_state *state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012185{
Daniel Vetter86b04262017-03-01 10:52:26 +010012186 verify_encoder_state(dev, state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012187 verify_connector_state(dev, state, NULL);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012188 verify_disabled_dpll_state(dev);
Daniel Vetter25c5b262012-07-08 22:08:04 +020012189}
12190
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012191static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012192{
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012193 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012194 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä80715b22014-05-15 20:23:23 +030012195
12196 /*
12197 * The scanline counter increments at the leading edge of hsync.
12198 *
12199 * On most platforms it starts counting from vtotal-1 on the
12200 * first active line. That means the scanline counter value is
12201 * always one less than what we would expect. Ie. just after
12202 * start of vblank, which also occurs at start of hsync (on the
12203 * last active line), the scanline counter will read vblank_start-1.
12204 *
12205 * On gen2 the scanline counter starts counting from 1 instead
12206 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12207 * to keep the value positive), instead of adding one.
12208 *
12209 * On HSW+ the behaviour of the scanline counter depends on the output
12210 * type. For DP ports it behaves like most other platforms, but on HDMI
12211 * there's an extra 1 line difference. So we need to add two instead of
12212 * one to the value.
Ville Syrjäläec1b4ee2016-12-15 19:47:34 +020012213 *
12214 * On VLV/CHV DSI the scanline counter would appear to increment
12215 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12216 * that means we can't tell whether we're in vblank or not while
12217 * we're on that particular line. We must still set scanline_offset
12218 * to 1 so that the vblank timestamps come out correct when we query
12219 * the scanline counter from within the vblank interrupt handler.
12220 * However if queried just before the start of vblank we'll get an
12221 * answer that's slightly in the future.
Ville Syrjälä80715b22014-05-15 20:23:23 +030012222 */
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012223 if (IS_GEN2(dev_priv)) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012224 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä80715b22014-05-15 20:23:23 +030012225 int vtotal;
12226
Ville Syrjälä124abe02015-09-08 13:40:45 +030012227 vtotal = adjusted_mode->crtc_vtotal;
12228 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012229 vtotal /= 2;
12230
12231 crtc->scanline_offset = vtotal - 1;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012232 } else if (HAS_DDI(dev_priv) &&
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012233 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
Ville Syrjälä80715b22014-05-15 20:23:23 +030012234 crtc->scanline_offset = 2;
12235 } else
12236 crtc->scanline_offset = 1;
12237}
12238
Maarten Lankhorstad421372015-06-15 12:33:42 +020012239static void intel_modeset_clear_plls(struct drm_atomic_state *state)
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012240{
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012241 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012242 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012243 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012244 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012245 int i;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012246
12247 if (!dev_priv->display.crtc_compute_clock)
Maarten Lankhorstad421372015-06-15 12:33:42 +020012248 return;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012249
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012250 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012251 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012252 struct intel_shared_dpll *old_dpll =
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012253 to_intel_crtc_state(old_crtc_state)->shared_dpll;
Maarten Lankhorstad421372015-06-15 12:33:42 +020012254
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012255 if (!needs_modeset(new_crtc_state))
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012256 continue;
12257
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012258 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012259
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012260 if (!old_dpll)
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012261 continue;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012262
Ander Conselvan de Oliveiraa1c414e2016-12-29 17:22:07 +020012263 intel_release_shared_dpll(old_dpll, intel_crtc, state);
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012264 }
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012265}
12266
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012267/*
12268 * This implements the workaround described in the "notes" section of the mode
12269 * set sequence documentation. When going from no pipes or single pipe to
12270 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12271 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12272 */
12273static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12274{
12275 struct drm_crtc_state *crtc_state;
12276 struct intel_crtc *intel_crtc;
12277 struct drm_crtc *crtc;
12278 struct intel_crtc_state *first_crtc_state = NULL;
12279 struct intel_crtc_state *other_crtc_state = NULL;
12280 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12281 int i;
12282
12283 /* look at all crtc's that are going to be enabled in during modeset */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012284 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012285 intel_crtc = to_intel_crtc(crtc);
12286
12287 if (!crtc_state->active || !needs_modeset(crtc_state))
12288 continue;
12289
12290 if (first_crtc_state) {
12291 other_crtc_state = to_intel_crtc_state(crtc_state);
12292 break;
12293 } else {
12294 first_crtc_state = to_intel_crtc_state(crtc_state);
12295 first_pipe = intel_crtc->pipe;
12296 }
12297 }
12298
12299 /* No workaround needed? */
12300 if (!first_crtc_state)
12301 return 0;
12302
12303 /* w/a possibly needed, check how many crtc's are already enabled. */
12304 for_each_intel_crtc(state->dev, intel_crtc) {
12305 struct intel_crtc_state *pipe_config;
12306
12307 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12308 if (IS_ERR(pipe_config))
12309 return PTR_ERR(pipe_config);
12310
12311 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12312
12313 if (!pipe_config->base.active ||
12314 needs_modeset(&pipe_config->base))
12315 continue;
12316
12317 /* 2 or more enabled crtcs means no need for w/a */
12318 if (enabled_pipe != INVALID_PIPE)
12319 return 0;
12320
12321 enabled_pipe = intel_crtc->pipe;
12322 }
12323
12324 if (enabled_pipe != INVALID_PIPE)
12325 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12326 else if (other_crtc_state)
12327 other_crtc_state->hsw_workaround_pipe = first_pipe;
12328
12329 return 0;
12330}
12331
Ville Syrjälä8d965612016-11-14 18:35:10 +020012332static int intel_lock_all_pipes(struct drm_atomic_state *state)
12333{
12334 struct drm_crtc *crtc;
12335
12336 /* Add all pipes to the state */
12337 for_each_crtc(state->dev, crtc) {
12338 struct drm_crtc_state *crtc_state;
12339
12340 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12341 if (IS_ERR(crtc_state))
12342 return PTR_ERR(crtc_state);
12343 }
12344
12345 return 0;
12346}
12347
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012348static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12349{
12350 struct drm_crtc *crtc;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012351
Ville Syrjälä8d965612016-11-14 18:35:10 +020012352 /*
12353 * Add all pipes to the state, and force
12354 * a modeset on all the active ones.
12355 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012356 for_each_crtc(state->dev, crtc) {
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012357 struct drm_crtc_state *crtc_state;
12358 int ret;
12359
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012360 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12361 if (IS_ERR(crtc_state))
12362 return PTR_ERR(crtc_state);
12363
12364 if (!crtc_state->active || needs_modeset(crtc_state))
12365 continue;
12366
12367 crtc_state->mode_changed = true;
12368
12369 ret = drm_atomic_add_affected_connectors(state, crtc);
12370 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012371 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012372
12373 ret = drm_atomic_add_affected_planes(state, crtc);
12374 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012375 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012376 }
12377
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012378 return 0;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012379}
12380
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012381static int intel_modeset_checks(struct drm_atomic_state *state)
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012382{
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012383 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012384 struct drm_i915_private *dev_priv = to_i915(state->dev);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012385 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012386 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012387 int ret = 0, i;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012388
Maarten Lankhorstb3592832015-06-15 12:33:38 +020012389 if (!check_digital_port_conflicts(state)) {
12390 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12391 return -EINVAL;
12392 }
12393
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012394 intel_state->modeset = true;
12395 intel_state->active_crtcs = dev_priv->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012396 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12397 intel_state->cdclk.actual = dev_priv->cdclk.actual;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012398
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012399 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12400 if (new_crtc_state->active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012401 intel_state->active_crtcs |= 1 << i;
12402 else
12403 intel_state->active_crtcs &= ~(1 << i);
Matt Roper8b4a7d02016-05-12 07:06:00 -070012404
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012405 if (old_crtc_state->active != new_crtc_state->active)
Matt Roper8b4a7d02016-05-12 07:06:00 -070012406 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012407 }
12408
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012409 /*
12410 * See if the config requires any additional preparation, e.g.
12411 * to adjust global state with pipes off. We need to do this
12412 * here so we can get the modeset_pipe updated config for the new
12413 * mode set on this crtc. For other crtcs we need to use the
12414 * adjusted_mode bits in the crtc directly.
12415 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012416 if (dev_priv->display.modeset_calc_cdclk) {
Clint Taylorc89e39f2016-05-13 23:41:21 +030012417 ret = dev_priv->display.modeset_calc_cdclk(state);
12418 if (ret < 0)
12419 return ret;
12420
Ville Syrjälä8d965612016-11-14 18:35:10 +020012421 /*
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012422 * Writes to dev_priv->cdclk.logical must protected by
Ville Syrjälä8d965612016-11-14 18:35:10 +020012423 * holding all the crtc locks, even if we don't end up
12424 * touching the hardware
12425 */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012426 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12427 &intel_state->cdclk.logical)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012428 ret = intel_lock_all_pipes(state);
12429 if (ret < 0)
12430 return ret;
12431 }
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012432
Ville Syrjälä8d965612016-11-14 18:35:10 +020012433 /* All pipes must be switched off while we change the cdclk. */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012434 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12435 &intel_state->cdclk.actual)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012436 ret = intel_modeset_all_pipes(state);
12437 if (ret < 0)
12438 return ret;
12439 }
Maarten Lankhorste8788cb2016-02-16 10:25:11 +010012440
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012441 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12442 intel_state->cdclk.logical.cdclk,
12443 intel_state->cdclk.actual.cdclk);
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030012444 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12445 intel_state->cdclk.logical.voltage_level,
12446 intel_state->cdclk.actual.voltage_level);
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012447 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012448 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012449 }
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012450
Maarten Lankhorstad421372015-06-15 12:33:42 +020012451 intel_modeset_clear_plls(state);
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012452
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012453 if (IS_HASWELL(dev_priv))
Maarten Lankhorstad421372015-06-15 12:33:42 +020012454 return haswell_mode_set_planes_workaround(state);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012455
Maarten Lankhorstad421372015-06-15 12:33:42 +020012456 return 0;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012457}
12458
Matt Roperaa363132015-09-24 15:53:18 -070012459/*
12460 * Handle calculation of various watermark data at the end of the atomic check
12461 * phase. The code here should be run after the per-crtc and per-plane 'check'
12462 * handlers to ensure that all derived state has been updated.
12463 */
Matt Roper55994c22016-05-12 07:06:08 -070012464static int calc_watermark_data(struct drm_atomic_state *state)
Matt Roperaa363132015-09-24 15:53:18 -070012465{
12466 struct drm_device *dev = state->dev;
Matt Roper98d39492016-05-12 07:06:03 -070012467 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roper98d39492016-05-12 07:06:03 -070012468
12469 /* Is there platform-specific watermark information to calculate? */
12470 if (dev_priv->display.compute_global_watermarks)
Matt Roper55994c22016-05-12 07:06:08 -070012471 return dev_priv->display.compute_global_watermarks(state);
12472
12473 return 0;
Matt Roperaa363132015-09-24 15:53:18 -070012474}
12475
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012476/**
12477 * intel_atomic_check - validate state object
12478 * @dev: drm device
12479 * @state: state to validate
12480 */
12481static int intel_atomic_check(struct drm_device *dev,
12482 struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012483{
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012484 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roperaa363132015-09-24 15:53:18 -070012485 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012486 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012487 struct drm_crtc_state *old_crtc_state, *crtc_state;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012488 int ret, i;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012489 bool any_ms = false;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012490
Maarten Lankhorst8c58f732018-02-21 10:28:08 +010012491 /* Catch I915_MODE_FLAG_INHERITED */
12492 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12493 crtc_state, i) {
12494 if (crtc_state->mode.private_flags !=
12495 old_crtc_state->mode.private_flags)
12496 crtc_state->mode_changed = true;
12497 }
12498
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012499 ret = drm_atomic_helper_check_modeset(dev, state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012500 if (ret)
12501 return ret;
12502
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012503 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012504 struct intel_crtc_state *pipe_config =
12505 to_intel_crtc_state(crtc_state);
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012506
Daniel Vetter26495482015-07-15 14:15:52 +020012507 if (!needs_modeset(crtc_state))
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012508 continue;
12509
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012510 if (!crtc_state->enable) {
12511 any_ms = true;
12512 continue;
12513 }
12514
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012515 ret = intel_modeset_pipe_config(crtc, pipe_config);
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012516 if (ret) {
12517 intel_dump_pipe_config(to_intel_crtc(crtc),
12518 pipe_config, "[failed]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012519 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012520 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012521
Michal Wajdeczko4f044a82017-09-19 19:38:44 +000012522 if (i915_modparams.fastboot &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012523 intel_pipe_config_compare(dev_priv,
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012524 to_intel_crtc_state(old_crtc_state),
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012525 pipe_config, true)) {
Daniel Vetter26495482015-07-15 14:15:52 +020012526 crtc_state->mode_changed = false;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012527 pipe_config->update_pipe = true;
Daniel Vetter26495482015-07-15 14:15:52 +020012528 }
12529
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012530 if (needs_modeset(crtc_state))
Daniel Vetter26495482015-07-15 14:15:52 +020012531 any_ms = true;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012532
Daniel Vetter26495482015-07-15 14:15:52 +020012533 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12534 needs_modeset(crtc_state) ?
12535 "[modeset]" : "[fastset]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012536 }
12537
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012538 if (any_ms) {
12539 ret = intel_modeset_checks(state);
12540
12541 if (ret)
12542 return ret;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012543 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012544 intel_state->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012545 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012546
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020012547 ret = icl_add_linked_planes(intel_state);
12548 if (ret)
12549 return ret;
12550
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012551 ret = drm_atomic_helper_check_planes(dev, state);
Matt Roperaa363132015-09-24 15:53:18 -070012552 if (ret)
12553 return ret;
12554
Ville Syrjälädd576022017-11-17 21:19:14 +020012555 intel_fbc_choose_crtc(dev_priv, intel_state);
Matt Roper55994c22016-05-12 07:06:08 -070012556 return calc_watermark_data(state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012557}
12558
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012559static int intel_atomic_prepare_commit(struct drm_device *dev,
Chris Wilsond07f0e52016-10-28 13:58:44 +010012560 struct drm_atomic_state *state)
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012561{
Chris Wilsonfd700752017-07-26 17:00:36 +010012562 return drm_atomic_helper_prepare_planes(dev, state);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012563}
12564
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012565u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12566{
12567 struct drm_device *dev = crtc->base.dev;
12568
12569 if (!dev->max_vblank_count)
Dhinakaran Pandiyan734cbbf2018-02-02 21:12:54 -080012570 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012571
12572 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12573}
12574
Lyude896e5bb2016-08-24 07:48:09 +020012575static void intel_update_crtc(struct drm_crtc *crtc,
12576 struct drm_atomic_state *state,
12577 struct drm_crtc_state *old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012578 struct drm_crtc_state *new_crtc_state)
Lyude896e5bb2016-08-24 07:48:09 +020012579{
12580 struct drm_device *dev = crtc->dev;
12581 struct drm_i915_private *dev_priv = to_i915(dev);
12582 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012583 struct intel_crtc_state *old_intel_cstate = to_intel_crtc_state(old_crtc_state);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012584 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12585 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012586 struct intel_plane_state *new_plane_state =
12587 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12588 to_intel_plane(crtc->primary));
Lyude896e5bb2016-08-24 07:48:09 +020012589
12590 if (modeset) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012591 update_scanline_offset(pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020012592 dev_priv->display.crtc_enable(pipe_config, state);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012593
12594 /* vblanks work again, re-enable pipe CRC. */
12595 intel_crtc_enable_pipe_crc(intel_crtc);
Lyude896e5bb2016-08-24 07:48:09 +020012596 } else {
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012597 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12598 pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020012599 }
12600
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012601 if (new_plane_state)
12602 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
Lyude896e5bb2016-08-24 07:48:09 +020012603
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012604 intel_begin_crtc_commit(crtc, old_crtc_state);
12605
12606 intel_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc,
12607 old_intel_cstate, pipe_config);
12608
12609 intel_finish_crtc_commit(crtc, old_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012610}
12611
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012612static void intel_update_crtcs(struct drm_atomic_state *state)
Lyude896e5bb2016-08-24 07:48:09 +020012613{
12614 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012615 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyude896e5bb2016-08-24 07:48:09 +020012616 int i;
12617
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012618 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12619 if (!new_crtc_state->active)
Lyude896e5bb2016-08-24 07:48:09 +020012620 continue;
12621
12622 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012623 new_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012624 }
12625}
12626
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012627static void skl_update_crtcs(struct drm_atomic_state *state)
Lyude27082492016-08-24 07:48:10 +020012628{
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020012629 struct drm_i915_private *dev_priv = to_i915(state->dev);
Lyude27082492016-08-24 07:48:10 +020012630 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12631 struct drm_crtc *crtc;
Lyudece0ba282016-09-15 10:46:35 -040012632 struct intel_crtc *intel_crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012633 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyudece0ba282016-09-15 10:46:35 -040012634 struct intel_crtc_state *cstate;
Lyude27082492016-08-24 07:48:10 +020012635 unsigned int updated = 0;
12636 bool progress;
12637 enum pipe pipe;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012638 int i;
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012639 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12640 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012641
12642 const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
12643
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012644 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012645 /* ignore allocations for crtc's that have been turned off. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012646 if (new_crtc_state->active)
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012647 entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020012648
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012649 /* If 2nd DBuf slice required, enable it here */
12650 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12651 icl_dbuf_slices_update(dev_priv, required_slices);
12652
Lyude27082492016-08-24 07:48:10 +020012653 /*
12654 * Whenever the number of active pipes changes, we need to make sure we
12655 * update the pipes in the right order so that their ddb allocations
12656 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12657 * cause pipe underruns and other bad stuff.
12658 */
12659 do {
Lyude27082492016-08-24 07:48:10 +020012660 progress = false;
12661
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012662 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Lyude27082492016-08-24 07:48:10 +020012663 bool vbl_wait = false;
12664 unsigned int cmask = drm_crtc_mask(crtc);
Lyudece0ba282016-09-15 10:46:35 -040012665
12666 intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä21794812017-08-23 18:22:26 +030012667 cstate = to_intel_crtc_state(new_crtc_state);
Lyudece0ba282016-09-15 10:46:35 -040012668 pipe = intel_crtc->pipe;
Lyude27082492016-08-24 07:48:10 +020012669
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012670 if (updated & cmask || !cstate->base.active)
Lyude27082492016-08-24 07:48:10 +020012671 continue;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012672
Mika Kahola2b685042017-10-10 13:17:03 +030012673 if (skl_ddb_allocation_overlaps(dev_priv,
12674 entries,
12675 &cstate->wm.skl.ddb,
12676 i))
Lyude27082492016-08-24 07:48:10 +020012677 continue;
12678
12679 updated |= cmask;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012680 entries[i] = &cstate->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020012681
12682 /*
12683 * If this is an already active pipe, it's DDB changed,
12684 * and this isn't the last pipe that needs updating
12685 * then we need to wait for a vblank to pass for the
12686 * new ddb allocation to take effect.
12687 */
Lyudece0ba282016-09-15 10:46:35 -040012688 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
Maarten Lankhorst512b5522016-11-08 13:55:34 +010012689 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012690 !new_crtc_state->active_changed &&
Lyude27082492016-08-24 07:48:10 +020012691 intel_state->wm_results.dirty_pipes != updated)
12692 vbl_wait = true;
12693
12694 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012695 new_crtc_state);
Lyude27082492016-08-24 07:48:10 +020012696
12697 if (vbl_wait)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020012698 intel_wait_for_vblank(dev_priv, pipe);
Lyude27082492016-08-24 07:48:10 +020012699
12700 progress = true;
12701 }
12702 } while (progress);
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012703
12704 /* If 2nd DBuf slice is no more required disable it */
12705 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12706 icl_dbuf_slices_update(dev_priv, required_slices);
Lyude27082492016-08-24 07:48:10 +020012707}
12708
Chris Wilsonba318c62017-02-02 20:47:41 +000012709static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12710{
12711 struct intel_atomic_state *state, *next;
12712 struct llist_node *freed;
12713
12714 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12715 llist_for_each_entry_safe(state, next, freed, freed)
12716 drm_atomic_state_put(&state->base);
12717}
12718
12719static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12720{
12721 struct drm_i915_private *dev_priv =
12722 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12723
12724 intel_atomic_helper_free_state(dev_priv);
12725}
12726
Daniel Vetter9db529a2017-08-08 10:08:28 +020012727static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12728{
12729 struct wait_queue_entry wait_fence, wait_reset;
12730 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12731
12732 init_wait_entry(&wait_fence, 0);
12733 init_wait_entry(&wait_reset, 0);
12734 for (;;) {
12735 prepare_to_wait(&intel_state->commit_ready.wait,
12736 &wait_fence, TASK_UNINTERRUPTIBLE);
12737 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12738 &wait_reset, TASK_UNINTERRUPTIBLE);
12739
12740
12741 if (i915_sw_fence_done(&intel_state->commit_ready)
12742 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12743 break;
12744
12745 schedule();
12746 }
12747 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12748 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12749}
12750
Chris Wilson8d52e442018-06-23 11:39:51 +010012751static void intel_atomic_cleanup_work(struct work_struct *work)
12752{
12753 struct drm_atomic_state *state =
12754 container_of(work, struct drm_atomic_state, commit_work);
12755 struct drm_i915_private *i915 = to_i915(state->dev);
12756
12757 drm_atomic_helper_cleanup_planes(&i915->drm, state);
12758 drm_atomic_helper_commit_cleanup_done(state);
12759 drm_atomic_state_put(state);
12760
12761 intel_atomic_helper_free_state(i915);
12762}
12763
Daniel Vetter94f05022016-06-14 18:01:00 +020012764static void intel_atomic_commit_tail(struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012765{
Daniel Vetter94f05022016-06-14 18:01:00 +020012766 struct drm_device *dev = state->dev;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012767 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012768 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012769 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012770 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
Maarten Lankhorst7580d772015-08-18 13:40:06 +020012771 struct drm_crtc *crtc;
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012772 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020012773 u64 put_domains[I915_MAX_PIPES] = {};
Chris Wilsone95433c2016-10-28 13:58:27 +010012774 int i;
Daniel Vettera6778b32012-07-02 09:56:42 +020012775
Daniel Vetter9db529a2017-08-08 10:08:28 +020012776 intel_atomic_commit_fence_wait(intel_state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020012777
Daniel Vetterea0000f2016-06-13 16:13:46 +020012778 drm_atomic_helper_wait_for_dependencies(state);
12779
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010012780 if (intel_state->modeset)
Daniel Vetter5a21b662016-05-24 17:13:53 +020012781 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012782
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012783 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012784 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
12785 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
12786 intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012787
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012788 if (needs_modeset(new_crtc_state) ||
12789 to_intel_crtc_state(new_crtc_state)->update_pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020012790
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012791 put_domains[intel_crtc->pipe] =
Daniel Vetter5a21b662016-05-24 17:13:53 +020012792 modeset_get_crtc_power_domains(crtc,
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012793 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012794 }
12795
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012796 if (!needs_modeset(new_crtc_state))
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012797 continue;
12798
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012799 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
Daniel Vetter460da9162013-03-27 00:44:51 +010012800
Ville Syrjälä29ceb0e2016-03-09 19:07:27 +020012801 if (old_crtc_state->active) {
Maarten Lankhorstf59e9702018-09-20 12:27:07 +020012802 intel_crtc_disable_planes(intel_crtc, old_intel_crtc_state->active_planes);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012803
12804 /*
12805 * We need to disable pipe CRC before disabling the pipe,
12806 * or we race against vblank off.
12807 */
12808 intel_crtc_disable_pipe_crc(intel_crtc);
12809
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012810 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020012811 intel_crtc->active = false;
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -020012812 intel_fbc_disable(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +020012813 intel_disable_shared_dpll(old_intel_crtc_state);
Ville Syrjälä9bbc8258a2015-11-20 22:09:20 +020012814
12815 /*
12816 * Underruns don't always raise
12817 * interrupts, so check manually.
12818 */
12819 intel_check_cpu_fifo_underruns(dev_priv);
12820 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorstb9001112015-11-19 16:07:16 +010012821
Ville Syrjälä21794812017-08-23 18:22:26 +030012822 if (!new_crtc_state->active) {
Maarten Lankhorste62929b2016-11-08 13:55:33 +010012823 /*
12824 * Make sure we don't call initial_watermarks
12825 * for ILK-style watermark updates.
Ville Syrjäläff32c542017-03-02 19:14:57 +020012826 *
12827 * No clue what this is supposed to achieve.
Maarten Lankhorste62929b2016-11-08 13:55:33 +010012828 */
Ville Syrjäläff32c542017-03-02 19:14:57 +020012829 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorste62929b2016-11-08 13:55:33 +010012830 dev_priv->display.initial_watermarks(intel_state,
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012831 new_intel_crtc_state);
Maarten Lankhorste62929b2016-11-08 13:55:33 +010012832 }
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012833 }
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010012834 }
Daniel Vetter7758a112012-07-08 19:40:39 +020012835
Daniel Vetter7a1530d72017-12-07 15:32:02 +010012836 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12837 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12838 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +020012839
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012840 if (intel_state->modeset) {
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020012841 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
Maarten Lankhorst33c8df892016-02-10 13:49:37 +010012842
Ville Syrjäläb0587e42017-01-26 21:52:01 +020012843 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
Maarten Lankhorstf6d19732016-03-23 14:58:07 +010012844
Lyude656d1b82016-08-17 15:55:54 -040012845 /*
12846 * SKL workaround: bspec recommends we disable the SAGV when we
12847 * have more then one pipe enabled
12848 */
Paulo Zanoni56feca92016-09-22 18:00:28 -030012849 if (!intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030012850 intel_disable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040012851
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012852 intel_modeset_verify_disabled(dev, state);
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020012853 }
Daniel Vetter47fab732012-10-26 10:58:18 +020012854
Lyude896e5bb2016-08-24 07:48:09 +020012855 /* Complete the events for pipes that have now been disabled */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012856 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12857 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012858
Daniel Vetter1f7528c2016-06-13 16:13:45 +020012859 /* Complete events for now disable pipes here. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012860 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
Daniel Vetter1f7528c2016-06-13 16:13:45 +020012861 spin_lock_irq(&dev->event_lock);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012862 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
Daniel Vetter1f7528c2016-06-13 16:13:45 +020012863 spin_unlock_irq(&dev->event_lock);
12864
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012865 new_crtc_state->event = NULL;
Daniel Vetter1f7528c2016-06-13 16:13:45 +020012866 }
Matt Ropered4a6a72016-02-23 17:20:13 -080012867 }
12868
Lyude896e5bb2016-08-24 07:48:09 +020012869 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012870 dev_priv->display.update_crtcs(state);
Lyude896e5bb2016-08-24 07:48:09 +020012871
Daniel Vetter94f05022016-06-14 18:01:00 +020012872 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12873 * already, but still need the state for the delayed optimization. To
12874 * fix this:
12875 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12876 * - schedule that vblank worker _before_ calling hw_done
12877 * - at the start of commit_tail, cancel it _synchrously
12878 * - switch over to the vblank wait helper in the core after that since
12879 * we don't need out special handling any more.
12880 */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012881 drm_atomic_helper_wait_for_flip_done(dev, state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012882
12883 /*
12884 * Now that the vblank has passed, we can go ahead and program the
12885 * optimal watermarks on platforms that need two-step watermark
12886 * programming.
12887 *
12888 * TODO: Move this (and other cleanup) to an async worker eventually.
12889 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012890 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012891 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012892
12893 if (dev_priv->display.optimize_watermarks)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010012894 dev_priv->display.optimize_watermarks(intel_state,
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012895 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012896 }
12897
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012898 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020012899 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12900
12901 if (put_domains[i])
12902 modeset_put_power_domains(dev_priv, put_domains[i]);
12903
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012904 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012905 }
12906
Ville Syrjäläcff109f2017-11-17 21:19:17 +020012907 if (intel_state->modeset)
12908 intel_verify_planes(intel_state);
12909
Paulo Zanoni56feca92016-09-22 18:00:28 -030012910 if (intel_state->modeset && intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030012911 intel_enable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040012912
Daniel Vetter94f05022016-06-14 18:01:00 +020012913 drm_atomic_helper_commit_hw_done(state);
12914
Chris Wilsond5553c02017-05-04 12:55:08 +010012915 if (intel_state->modeset) {
12916 /* As one of the primary mmio accessors, KMS has a high
12917 * likelihood of triggering bugs in unclaimed access. After we
12918 * finish modesetting, see if an error has been flagged, and if
12919 * so enable debugging for the next modeset - and hope we catch
12920 * the culprit.
12921 */
12922 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012923 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
Chris Wilsond5553c02017-05-04 12:55:08 +010012924 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020012925
Chris Wilson8d52e442018-06-23 11:39:51 +010012926 /*
12927 * Defer the cleanup of the old state to a separate worker to not
12928 * impede the current task (userspace for blocking modesets) that
12929 * are executed inline. For out-of-line asynchronous modesets/flips,
12930 * deferring to a new worker seems overkill, but we would place a
12931 * schedule point (cond_resched()) here anyway to keep latencies
12932 * down.
12933 */
12934 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
Chris Wilson41db6452018-07-12 12:57:29 +010012935 queue_work(system_highpri_wq, &state->commit_work);
Daniel Vetter94f05022016-06-14 18:01:00 +020012936}
12937
12938static void intel_atomic_commit_work(struct work_struct *work)
12939{
Chris Wilsonc004a902016-10-28 13:58:45 +010012940 struct drm_atomic_state *state =
12941 container_of(work, struct drm_atomic_state, commit_work);
12942
Daniel Vetter94f05022016-06-14 18:01:00 +020012943 intel_atomic_commit_tail(state);
12944}
12945
Chris Wilsonc004a902016-10-28 13:58:45 +010012946static int __i915_sw_fence_call
12947intel_atomic_commit_ready(struct i915_sw_fence *fence,
12948 enum i915_sw_fence_notify notify)
12949{
12950 struct intel_atomic_state *state =
12951 container_of(fence, struct intel_atomic_state, commit_ready);
12952
12953 switch (notify) {
12954 case FENCE_COMPLETE:
Daniel Vetter42b062b2017-08-08 10:08:27 +020012955 /* we do blocking waits in the worker, nothing to do here */
Chris Wilsonc004a902016-10-28 13:58:45 +010012956 break;
Chris Wilsonc004a902016-10-28 13:58:45 +010012957 case FENCE_FREE:
Chris Wilsoneb955ee2017-01-23 21:29:39 +000012958 {
12959 struct intel_atomic_helper *helper =
12960 &to_i915(state->base.dev)->atomic_helper;
12961
12962 if (llist_add(&state->freed, &helper->free_list))
12963 schedule_work(&helper->free_work);
12964 break;
12965 }
Chris Wilsonc004a902016-10-28 13:58:45 +010012966 }
12967
12968 return NOTIFY_DONE;
12969}
12970
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020012971static void intel_atomic_track_fbs(struct drm_atomic_state *state)
12972{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012973 struct drm_plane_state *old_plane_state, *new_plane_state;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020012974 struct drm_plane *plane;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020012975 int i;
12976
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012977 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010012978 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012979 intel_fb_obj(new_plane_state->fb),
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010012980 to_intel_plane(plane)->frontbuffer_bit);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020012981}
12982
Daniel Vetter94f05022016-06-14 18:01:00 +020012983/**
12984 * intel_atomic_commit - commit validated state object
12985 * @dev: DRM device
12986 * @state: the top-level driver state object
12987 * @nonblock: nonblocking commit
12988 *
12989 * This function commits a top-level state object that has been validated
12990 * with drm_atomic_helper_check().
12991 *
Daniel Vetter94f05022016-06-14 18:01:00 +020012992 * RETURNS
12993 * Zero for success or -errno.
12994 */
12995static int intel_atomic_commit(struct drm_device *dev,
12996 struct drm_atomic_state *state,
12997 bool nonblock)
12998{
12999 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010013000 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter94f05022016-06-14 18:01:00 +020013001 int ret = 0;
13002
Chris Wilsonc004a902016-10-28 13:58:45 +010013003 drm_atomic_state_get(state);
13004 i915_sw_fence_init(&intel_state->commit_ready,
13005 intel_atomic_commit_ready);
Daniel Vetter94f05022016-06-14 18:01:00 +020013006
Ville Syrjälä440df932017-03-29 17:21:23 +030013007 /*
13008 * The intel_legacy_cursor_update() fast path takes care
13009 * of avoiding the vblank waits for simple cursor
13010 * movement and flips. For cursor on/off and size changes,
13011 * we want to perform the vblank waits so that watermark
13012 * updates happen during the correct frames. Gen9+ have
13013 * double buffered watermarks and so shouldn't need this.
13014 *
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013015 * Unset state->legacy_cursor_update before the call to
13016 * drm_atomic_helper_setup_commit() because otherwise
13017 * drm_atomic_helper_wait_for_flip_done() is a noop and
13018 * we get FIFO underruns because we didn't wait
13019 * for vblank.
Ville Syrjälä440df932017-03-29 17:21:23 +030013020 *
13021 * FIXME doing watermarks and fb cleanup from a vblank worker
13022 * (assuming we had any) would solve these problems.
13023 */
Maarten Lankhorst213f1bd2017-09-19 14:14:19 +020013024 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13025 struct intel_crtc_state *new_crtc_state;
13026 struct intel_crtc *crtc;
13027 int i;
13028
13029 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13030 if (new_crtc_state->wm.need_postvbl_update ||
13031 new_crtc_state->update_wm_post)
13032 state->legacy_cursor_update = false;
13033 }
Ville Syrjälä440df932017-03-29 17:21:23 +030013034
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013035 ret = intel_atomic_prepare_commit(dev, state);
13036 if (ret) {
13037 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13038 i915_sw_fence_commit(&intel_state->commit_ready);
13039 return ret;
13040 }
13041
13042 ret = drm_atomic_helper_setup_commit(state, nonblock);
13043 if (!ret)
13044 ret = drm_atomic_helper_swap_state(state, true);
13045
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013046 if (ret) {
13047 i915_sw_fence_commit(&intel_state->commit_ready);
13048
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013049 drm_atomic_helper_cleanup_planes(dev, state);
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013050 return ret;
13051 }
Daniel Vetter94f05022016-06-14 18:01:00 +020013052 dev_priv->wm.distrust_bios_wm = false;
Ander Conselvan de Oliveira3c0fb582016-12-29 17:22:08 +020013053 intel_shared_dpll_swap_state(state);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013054 intel_atomic_track_fbs(state);
Daniel Vetter94f05022016-06-14 18:01:00 +020013055
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013056 if (intel_state->modeset) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030013057 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13058 sizeof(intel_state->min_cdclk));
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030013059 memcpy(dev_priv->min_voltage_level,
13060 intel_state->min_voltage_level,
13061 sizeof(intel_state->min_voltage_level));
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013062 dev_priv->active_crtcs = intel_state->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020013063 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13064 dev_priv->cdclk.actual = intel_state->cdclk.actual;
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013065 }
13066
Chris Wilson08536952016-10-14 13:18:18 +010013067 drm_atomic_state_get(state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020013068 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
Chris Wilsonc004a902016-10-28 13:58:45 +010013069
13070 i915_sw_fence_commit(&intel_state->commit_ready);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013071 if (nonblock && intel_state->modeset) {
13072 queue_work(dev_priv->modeset_wq, &state->commit_work);
13073 } else if (nonblock) {
Daniel Vetter42b062b2017-08-08 10:08:27 +020013074 queue_work(system_unbound_wq, &state->commit_work);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013075 } else {
13076 if (intel_state->modeset)
13077 flush_workqueue(dev_priv->modeset_wq);
Daniel Vetter94f05022016-06-14 18:01:00 +020013078 intel_atomic_commit_tail(state);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013079 }
Mika Kuoppala75714942015-12-16 09:26:48 +020013080
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013081 return 0;
Daniel Vetterf30da182013-04-11 20:22:50 +020013082}
13083
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013084static const struct drm_crtc_funcs intel_crtc_funcs = {
Daniel Vetter3fab2f02017-04-03 10:32:57 +020013085 .gamma_set = drm_atomic_helper_legacy_gamma_set,
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013086 .set_config = drm_atomic_helper_set_config,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013087 .destroy = intel_crtc_destroy,
Maarten Lankhorst4c01ded2016-12-22 11:33:23 +010013088 .page_flip = drm_atomic_helper_page_flip,
Matt Roper13568372015-01-21 16:35:47 -080013089 .atomic_duplicate_state = intel_crtc_duplicate_state,
13090 .atomic_destroy_state = intel_crtc_destroy_state,
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +010013091 .set_crc_source = intel_crtc_set_crc_source,
Mahesh Kumara8c20832018-07-13 19:29:38 +053013092 .verify_crc_source = intel_crtc_verify_crc_source,
Mahesh Kumar260bc552018-07-13 19:29:39 +053013093 .get_crc_sources = intel_crtc_get_crc_sources,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013094};
13095
Chris Wilson74d290f2017-08-17 13:37:06 +010013096struct wait_rps_boost {
13097 struct wait_queue_entry wait;
13098
13099 struct drm_crtc *crtc;
Chris Wilsone61e0f52018-02-21 09:56:36 +000013100 struct i915_request *request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013101};
13102
13103static int do_rps_boost(struct wait_queue_entry *_wait,
13104 unsigned mode, int sync, void *key)
13105{
13106 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013107 struct i915_request *rq = wait->request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013108
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013109 /*
13110 * If we missed the vblank, but the request is already running it
13111 * is reasonable to assume that it will complete before the next
13112 * vblank without our intervention, so leave RPS alone.
13113 */
Chris Wilsone61e0f52018-02-21 09:56:36 +000013114 if (!i915_request_started(rq))
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013115 gen6_rps_boost(rq, NULL);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013116 i915_request_put(rq);
Chris Wilson74d290f2017-08-17 13:37:06 +010013117
13118 drm_crtc_vblank_put(wait->crtc);
13119
13120 list_del(&wait->wait.entry);
13121 kfree(wait);
13122 return 1;
13123}
13124
13125static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13126 struct dma_fence *fence)
13127{
13128 struct wait_rps_boost *wait;
13129
13130 if (!dma_fence_is_i915(fence))
13131 return;
13132
13133 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13134 return;
13135
13136 if (drm_crtc_vblank_get(crtc))
13137 return;
13138
13139 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13140 if (!wait) {
13141 drm_crtc_vblank_put(crtc);
13142 return;
13143 }
13144
13145 wait->request = to_request(dma_fence_get(fence));
13146 wait->crtc = crtc;
13147
13148 wait->wait.func = do_rps_boost;
13149 wait->wait.flags = 0;
13150
13151 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13152}
13153
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013154static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13155{
13156 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13157 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13158 struct drm_framebuffer *fb = plane_state->base.fb;
13159 struct i915_vma *vma;
13160
13161 if (plane->id == PLANE_CURSOR &&
13162 INTEL_INFO(dev_priv)->cursor_needs_physical) {
13163 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13164 const int align = intel_cursor_alignment(dev_priv);
Chris Wilson4a477652018-08-17 09:24:05 +010013165 int err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013166
Chris Wilson4a477652018-08-17 09:24:05 +010013167 err = i915_gem_object_attach_phys(obj, align);
13168 if (err)
13169 return err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013170 }
13171
13172 vma = intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +030013173 &plane_state->view,
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013174 intel_plane_uses_fence(plane_state),
13175 &plane_state->flags);
13176 if (IS_ERR(vma))
13177 return PTR_ERR(vma);
13178
13179 plane_state->vma = vma;
13180
13181 return 0;
13182}
13183
13184static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13185{
13186 struct i915_vma *vma;
13187
13188 vma = fetch_and_zero(&old_plane_state->vma);
13189 if (vma)
13190 intel_unpin_fb_vma(vma, old_plane_state->flags);
13191}
13192
Chris Wilsonb7268c52018-04-18 19:40:52 +010013193static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13194{
13195 struct i915_sched_attr attr = {
13196 .priority = I915_PRIORITY_DISPLAY,
13197 };
13198
13199 i915_gem_object_wait_priority(obj, 0, &attr);
13200}
13201
Matt Roper6beb8c232014-12-01 15:40:14 -080013202/**
13203 * intel_prepare_plane_fb - Prepare fb for usage on plane
13204 * @plane: drm plane to prepare for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013205 * @new_state: the plane state being prepared
Matt Roper6beb8c232014-12-01 15:40:14 -080013206 *
13207 * Prepares a framebuffer for usage on a display plane. Generally this
13208 * involves pinning the underlying object and updating the frontbuffer tracking
13209 * bits. Some older platforms need special physical address handling for
13210 * cursor planes.
13211 *
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013212 * Must be called with struct_mutex held.
13213 *
Matt Roper6beb8c232014-12-01 15:40:14 -080013214 * Returns 0 on success, negative error code on failure.
13215 */
13216int
13217intel_prepare_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013218 struct drm_plane_state *new_state)
Matt Roper465c1202014-05-29 08:06:54 -070013219{
Chris Wilsonc004a902016-10-28 13:58:45 +010013220 struct intel_atomic_state *intel_state =
13221 to_intel_atomic_state(new_state->state);
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000013222 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Maarten Lankhorst844f9112015-09-02 10:42:40 +020013223 struct drm_framebuffer *fb = new_state->fb;
Matt Roper6beb8c232014-12-01 15:40:14 -080013224 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Maarten Lankhorst1ee49392015-09-23 13:27:08 +020013225 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
Chris Wilsonc004a902016-10-28 13:58:45 +010013226 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013227
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013228 if (old_obj) {
13229 struct drm_crtc_state *crtc_state =
Maarten Lankhorst8b694492018-04-09 14:46:55 +020013230 drm_atomic_get_new_crtc_state(new_state->state,
13231 plane->state->crtc);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013232
13233 /* Big Hammer, we also need to ensure that any pending
13234 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13235 * current scanout is retired before unpinning the old
13236 * framebuffer. Note that we rely on userspace rendering
13237 * into the buffer attached to the pipe they are waiting
13238 * on. If not, userspace generates a GPU hang with IPEHR
13239 * point to the MI_WAIT_FOR_EVENT.
13240 *
13241 * This should only fail upon a hung GPU, in which case we
13242 * can safely continue.
13243 */
Chris Wilsonc004a902016-10-28 13:58:45 +010013244 if (needs_modeset(crtc_state)) {
13245 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13246 old_obj->resv, NULL,
13247 false, 0,
13248 GFP_KERNEL);
13249 if (ret < 0)
13250 return ret;
Chris Wilsonf4457ae2016-04-13 17:35:08 +010013251 }
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013252 }
13253
Chris Wilsonc004a902016-10-28 13:58:45 +010013254 if (new_state->fence) { /* explicit fencing */
13255 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13256 new_state->fence,
13257 I915_FENCE_TIMEOUT,
13258 GFP_KERNEL);
13259 if (ret < 0)
13260 return ret;
13261 }
13262
Chris Wilsonc37efb92016-06-17 08:28:47 +010013263 if (!obj)
13264 return 0;
13265
Chris Wilson4d3088c2017-07-26 17:00:38 +010013266 ret = i915_gem_object_pin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013267 if (ret)
13268 return ret;
13269
Chris Wilson4d3088c2017-07-26 17:00:38 +010013270 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13271 if (ret) {
13272 i915_gem_object_unpin_pages(obj);
13273 return ret;
13274 }
13275
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013276 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
Chris Wilsonfd700752017-07-26 17:00:36 +010013277
Chris Wilsonfd700752017-07-26 17:00:36 +010013278 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson4d3088c2017-07-26 17:00:38 +010013279 i915_gem_object_unpin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013280 if (ret)
13281 return ret;
13282
Chris Wilsone2f34962018-10-01 15:47:54 +010013283 fb_obj_bump_render_priority(obj);
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013284 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13285
Chris Wilsonc004a902016-10-28 13:58:45 +010013286 if (!new_state->fence) { /* implicit fencing */
Chris Wilson74d290f2017-08-17 13:37:06 +010013287 struct dma_fence *fence;
13288
Chris Wilsonc004a902016-10-28 13:58:45 +010013289 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13290 obj->resv, NULL,
13291 false, I915_FENCE_TIMEOUT,
13292 GFP_KERNEL);
13293 if (ret < 0)
13294 return ret;
Chris Wilson74d290f2017-08-17 13:37:06 +010013295
13296 fence = reservation_object_get_excl_rcu(obj->resv);
13297 if (fence) {
13298 add_rps_boost_after_vblank(new_state->crtc, fence);
13299 dma_fence_put(fence);
13300 }
13301 } else {
13302 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
Chris Wilsonc004a902016-10-28 13:58:45 +010013303 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013304
Chris Wilson60548c52018-07-31 14:26:29 +010013305 /*
13306 * We declare pageflips to be interactive and so merit a small bias
13307 * towards upclocking to deliver the frame on time. By only changing
13308 * the RPS thresholds to sample more regularly and aim for higher
13309 * clocks we can hopefully deliver low power workloads (like kodi)
13310 * that are not quite steady state without resorting to forcing
13311 * maximum clocks following a vblank miss (see do_rps_boost()).
13312 */
13313 if (!intel_state->rps_interactive) {
13314 intel_rps_mark_interactive(dev_priv, true);
13315 intel_state->rps_interactive = true;
13316 }
13317
Chris Wilsond07f0e52016-10-28 13:58:44 +010013318 return 0;
Matt Roper6beb8c232014-12-01 15:40:14 -080013319}
13320
Matt Roper38f3ce32014-12-02 07:45:25 -080013321/**
13322 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13323 * @plane: drm plane to clean up for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013324 * @old_state: the state from the previous modeset
Matt Roper38f3ce32014-12-02 07:45:25 -080013325 *
13326 * Cleans up a framebuffer that has just been removed from a plane.
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013327 *
13328 * Must be called with struct_mutex held.
Matt Roper38f3ce32014-12-02 07:45:25 -080013329 */
13330void
13331intel_cleanup_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013332 struct drm_plane_state *old_state)
Matt Roper38f3ce32014-12-02 07:45:25 -080013333{
Chris Wilson60548c52018-07-31 14:26:29 +010013334 struct intel_atomic_state *intel_state =
13335 to_intel_atomic_state(old_state->state);
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013336 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Matt Roper38f3ce32014-12-02 07:45:25 -080013337
Chris Wilson60548c52018-07-31 14:26:29 +010013338 if (intel_state->rps_interactive) {
13339 intel_rps_mark_interactive(dev_priv, false);
13340 intel_state->rps_interactive = false;
13341 }
13342
Chris Wilsonbe1e3412017-01-16 15:21:27 +000013343 /* Should only be called after a successful intel_prepare_plane_fb()! */
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013344 mutex_lock(&dev_priv->drm.struct_mutex);
13345 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13346 mutex_unlock(&dev_priv->drm.struct_mutex);
Matt Roper465c1202014-05-29 08:06:54 -070013347}
13348
Chandra Konduru6156a452015-04-27 13:48:39 -070013349int
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013350skl_max_scale(const struct intel_crtc_state *crtc_state,
13351 u32 pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -070013352{
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013353 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13354 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru77224cd2018-04-09 09:11:13 +053013355 int max_scale, mult;
13356 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
Chandra Konduru6156a452015-04-27 13:48:39 -070013357
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013358 if (!crtc_state->base.enable)
Chandra Konduru6156a452015-04-27 13:48:39 -070013359 return DRM_PLANE_HELPER_NO_SCALING;
13360
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013361 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13362 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13363
Rodrigo Vivi43037c82017-10-03 15:31:42 -070013364 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013365 max_dotclk *= 2;
13366
13367 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
Chandra Konduru6156a452015-04-27 13:48:39 -070013368 return DRM_PLANE_HELPER_NO_SCALING;
13369
13370 /*
13371 * skl max scale is lower of:
13372 * close to 3 but not 3, -1 is for that purpose
13373 * or
13374 * cdclk/crtc_clock
13375 */
Chandra Konduru77224cd2018-04-09 09:11:13 +053013376 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13377 tmpclk1 = (1 << 16) * mult - 1;
13378 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13379 max_scale = min(tmpclk1, tmpclk2);
Chandra Konduru6156a452015-04-27 13:48:39 -070013380
13381 return max_scale;
13382}
13383
Daniel Vetter5a21b662016-05-24 17:13:53 +020013384static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13385 struct drm_crtc_state *old_crtc_state)
13386{
13387 struct drm_device *dev = crtc->dev;
Lyude62e0fb82016-08-22 12:50:08 -040013388 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013389 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013390 struct intel_crtc_state *old_intel_cstate =
Daniel Vetter5a21b662016-05-24 17:13:53 +020013391 to_intel_crtc_state(old_crtc_state);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013392 struct intel_atomic_state *old_intel_state =
13393 to_intel_atomic_state(old_crtc_state->state);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013394 struct intel_crtc_state *intel_cstate =
13395 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13396 bool modeset = needs_modeset(&intel_cstate->base);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013397
Maarten Lankhorst567f0792017-02-28 15:28:47 +010013398 if (!modeset &&
13399 (intel_cstate->base.color_mgmt_changed ||
13400 intel_cstate->update_pipe)) {
Ville Syrjälä5c857e62017-08-23 18:22:20 +030013401 intel_color_set_csc(&intel_cstate->base);
13402 intel_color_load_luts(&intel_cstate->base);
Maarten Lankhorst567f0792017-02-28 15:28:47 +010013403 }
13404
Daniel Vetter5a21b662016-05-24 17:13:53 +020013405 /* Perform vblank evasion around commit operation */
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013406 intel_pipe_update_start(intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013407
13408 if (modeset)
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013409 goto out;
Daniel Vetter5a21b662016-05-24 17:13:53 +020013410
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013411 if (intel_cstate->update_pipe)
Ville Syrjälä1a15b772017-08-23 18:22:25 +030013412 intel_update_pipe_config(old_intel_cstate, intel_cstate);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013413 else if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +020013414 skl_detach_scalers(intel_cstate);
Lyude62e0fb82016-08-22 12:50:08 -040013415
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013416out:
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013417 if (dev_priv->display.atomic_update_watermarks)
13418 dev_priv->display.atomic_update_watermarks(old_intel_state,
13419 intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013420}
13421
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013422void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13423 struct intel_crtc_state *crtc_state)
13424{
13425 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13426
13427 if (!IS_GEN2(dev_priv))
13428 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13429
13430 if (crtc_state->has_pch_encoder) {
13431 enum pipe pch_transcoder =
13432 intel_crtc_pch_transcoder(crtc);
13433
13434 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13435 }
13436}
13437
Daniel Vetter5a21b662016-05-24 17:13:53 +020013438static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13439 struct drm_crtc_state *old_crtc_state)
13440{
13441 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013442 struct intel_atomic_state *old_intel_state =
13443 to_intel_atomic_state(old_crtc_state->state);
13444 struct intel_crtc_state *new_crtc_state =
13445 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013446
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013447 intel_pipe_update_end(new_crtc_state);
Maarten Lankhorst33a49862017-11-13 15:40:43 +010013448
13449 if (new_crtc_state->update_pipe &&
13450 !needs_modeset(&new_crtc_state->base) &&
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013451 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13452 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013453}
13454
Matt Ropercf4c7c12014-12-04 10:27:42 -080013455/**
Matt Roper4a3b8762014-12-23 10:41:51 -080013456 * intel_plane_destroy - destroy a plane
13457 * @plane: plane to destroy
Matt Ropercf4c7c12014-12-04 10:27:42 -080013458 *
Matt Roper4a3b8762014-12-23 10:41:51 -080013459 * Common destruction function for all types of planes (primary, cursor,
13460 * sprite).
Matt Ropercf4c7c12014-12-04 10:27:42 -080013461 */
Matt Roper4a3b8762014-12-23 10:41:51 -080013462void intel_plane_destroy(struct drm_plane *plane)
Matt Roper465c1202014-05-29 08:06:54 -070013463{
Matt Roper465c1202014-05-29 08:06:54 -070013464 drm_plane_cleanup(plane);
Ville Syrjälä69ae5612016-05-27 20:59:22 +030013465 kfree(to_intel_plane(plane));
Matt Roper465c1202014-05-29 08:06:54 -070013466}
13467
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013468static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13469 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013470{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013471 switch (modifier) {
13472 case DRM_FORMAT_MOD_LINEAR:
13473 case I915_FORMAT_MOD_X_TILED:
13474 break;
13475 default:
13476 return false;
13477 }
13478
Ben Widawsky714244e2017-08-01 09:58:16 -070013479 switch (format) {
13480 case DRM_FORMAT_C8:
13481 case DRM_FORMAT_RGB565:
13482 case DRM_FORMAT_XRGB1555:
13483 case DRM_FORMAT_XRGB8888:
13484 return modifier == DRM_FORMAT_MOD_LINEAR ||
13485 modifier == I915_FORMAT_MOD_X_TILED;
13486 default:
13487 return false;
13488 }
13489}
13490
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013491static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13492 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013493{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013494 switch (modifier) {
13495 case DRM_FORMAT_MOD_LINEAR:
13496 case I915_FORMAT_MOD_X_TILED:
13497 break;
13498 default:
13499 return false;
13500 }
13501
Ben Widawsky714244e2017-08-01 09:58:16 -070013502 switch (format) {
13503 case DRM_FORMAT_C8:
13504 case DRM_FORMAT_RGB565:
13505 case DRM_FORMAT_XRGB8888:
13506 case DRM_FORMAT_XBGR8888:
13507 case DRM_FORMAT_XRGB2101010:
13508 case DRM_FORMAT_XBGR2101010:
13509 return modifier == DRM_FORMAT_MOD_LINEAR ||
13510 modifier == I915_FORMAT_MOD_X_TILED;
13511 default:
13512 return false;
13513 }
13514}
13515
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013516static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13517 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013518{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013519 return modifier == DRM_FORMAT_MOD_LINEAR &&
13520 format == DRM_FORMAT_ARGB8888;
Ben Widawsky714244e2017-08-01 09:58:16 -070013521}
13522
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013523static const struct drm_plane_funcs i965_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013524 .update_plane = drm_atomic_helper_update_plane,
13525 .disable_plane = drm_atomic_helper_disable_plane,
13526 .destroy = intel_plane_destroy,
13527 .atomic_get_property = intel_plane_atomic_get_property,
13528 .atomic_set_property = intel_plane_atomic_set_property,
13529 .atomic_duplicate_state = intel_plane_duplicate_state,
13530 .atomic_destroy_state = intel_plane_destroy_state,
13531 .format_mod_supported = i965_plane_format_mod_supported,
13532};
13533
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013534static const struct drm_plane_funcs i8xx_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013535 .update_plane = drm_atomic_helper_update_plane,
13536 .disable_plane = drm_atomic_helper_disable_plane,
13537 .destroy = intel_plane_destroy,
13538 .atomic_get_property = intel_plane_atomic_get_property,
13539 .atomic_set_property = intel_plane_atomic_set_property,
13540 .atomic_duplicate_state = intel_plane_duplicate_state,
13541 .atomic_destroy_state = intel_plane_destroy_state,
13542 .format_mod_supported = i8xx_plane_format_mod_supported,
Matt Roper465c1202014-05-29 08:06:54 -070013543};
13544
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013545static int
13546intel_legacy_cursor_update(struct drm_plane *plane,
13547 struct drm_crtc *crtc,
13548 struct drm_framebuffer *fb,
13549 int crtc_x, int crtc_y,
13550 unsigned int crtc_w, unsigned int crtc_h,
13551 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013552 uint32_t src_w, uint32_t src_h,
13553 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013554{
13555 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13556 int ret;
13557 struct drm_plane_state *old_plane_state, *new_plane_state;
13558 struct intel_plane *intel_plane = to_intel_plane(plane);
13559 struct drm_framebuffer *old_fb;
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013560 struct intel_crtc_state *crtc_state =
13561 to_intel_crtc_state(crtc->state);
13562 struct intel_crtc_state *new_crtc_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013563
13564 /*
13565 * When crtc is inactive or there is a modeset pending,
13566 * wait for it to complete in the slowpath
13567 */
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013568 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
13569 crtc_state->update_pipe)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013570 goto slow;
13571
13572 old_plane_state = plane->state;
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013573 /*
13574 * Don't do an async update if there is an outstanding commit modifying
13575 * the plane. This prevents our async update's changes from getting
13576 * overridden by a previous synchronous update's state.
13577 */
13578 if (old_plane_state->commit &&
13579 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13580 goto slow;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013581
13582 /*
13583 * If any parameters change that may affect watermarks,
13584 * take the slowpath. Only changing fb or position should be
13585 * in the fastpath.
13586 */
13587 if (old_plane_state->crtc != crtc ||
13588 old_plane_state->src_w != src_w ||
13589 old_plane_state->src_h != src_h ||
13590 old_plane_state->crtc_w != crtc_w ||
13591 old_plane_state->crtc_h != crtc_h ||
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013592 !old_plane_state->fb != !fb)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013593 goto slow;
13594
13595 new_plane_state = intel_plane_duplicate_state(plane);
13596 if (!new_plane_state)
13597 return -ENOMEM;
13598
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013599 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
13600 if (!new_crtc_state) {
13601 ret = -ENOMEM;
13602 goto out_free;
13603 }
13604
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013605 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13606
13607 new_plane_state->src_x = src_x;
13608 new_plane_state->src_y = src_y;
13609 new_plane_state->src_w = src_w;
13610 new_plane_state->src_h = src_h;
13611 new_plane_state->crtc_x = crtc_x;
13612 new_plane_state->crtc_y = crtc_y;
13613 new_plane_state->crtc_w = crtc_w;
13614 new_plane_state->crtc_h = crtc_h;
13615
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013616 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
13617 to_intel_plane_state(old_plane_state),
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013618 to_intel_plane_state(new_plane_state));
13619 if (ret)
13620 goto out_free;
13621
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013622 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13623 if (ret)
13624 goto out_free;
13625
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013626 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13627 if (ret)
13628 goto out_unlock;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013629
Dhinakaran Pandiyana694e222018-03-06 19:34:19 -080013630 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013631
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013632 old_fb = old_plane_state->fb;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013633 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13634 intel_plane->frontbuffer_bit);
13635
13636 /* Swap plane state */
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013637 plane->state = new_plane_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013638
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013639 /*
13640 * We cannot swap crtc_state as it may be in use by an atomic commit or
13641 * page flip that's running simultaneously. If we swap crtc_state and
13642 * destroy the old state, we will cause a use-after-free there.
13643 *
13644 * Only update active_planes, which is needed for our internal
13645 * bookkeeping. Either value will do the right thing when updating
13646 * planes atomically. If the cursor was part of the atomic update then
13647 * we would have taken the slowpath.
13648 */
13649 crtc_state->active_planes = new_crtc_state->active_planes;
13650
Ville Syrjälä72259532017-03-02 19:15:05 +020013651 if (plane->state->visible) {
13652 trace_intel_update_plane(plane, to_intel_crtc(crtc));
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013653 intel_plane->update_plane(intel_plane, crtc_state,
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013654 to_intel_plane_state(plane->state));
Ville Syrjälä72259532017-03-02 19:15:05 +020013655 } else {
13656 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
Ville Syrjälä282dbf92017-03-27 21:55:33 +030013657 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
Ville Syrjälä72259532017-03-02 19:15:05 +020013658 }
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013659
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013660 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013661
13662out_unlock:
13663 mutex_unlock(&dev_priv->drm.struct_mutex);
13664out_free:
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013665 if (new_crtc_state)
13666 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013667 if (ret)
13668 intel_plane_destroy_state(plane, new_plane_state);
13669 else
13670 intel_plane_destroy_state(plane, old_plane_state);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013671 return ret;
13672
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013673slow:
13674 return drm_atomic_helper_update_plane(plane, crtc, fb,
13675 crtc_x, crtc_y, crtc_w, crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013676 src_x, src_y, src_w, src_h, ctx);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013677}
13678
13679static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13680 .update_plane = intel_legacy_cursor_update,
13681 .disable_plane = drm_atomic_helper_disable_plane,
13682 .destroy = intel_plane_destroy,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013683 .atomic_get_property = intel_plane_atomic_get_property,
13684 .atomic_set_property = intel_plane_atomic_set_property,
13685 .atomic_duplicate_state = intel_plane_duplicate_state,
13686 .atomic_destroy_state = intel_plane_destroy_state,
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013687 .format_mod_supported = intel_cursor_format_mod_supported,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013688};
13689
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013690static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13691 enum i9xx_plane_id i9xx_plane)
13692{
13693 if (!HAS_FBC(dev_priv))
13694 return false;
13695
13696 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13697 return i9xx_plane == PLANE_A; /* tied to pipe A */
13698 else if (IS_IVYBRIDGE(dev_priv))
13699 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13700 i9xx_plane == PLANE_C;
13701 else if (INTEL_GEN(dev_priv) >= 4)
13702 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13703 else
13704 return i9xx_plane == PLANE_A;
13705}
13706
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013707static struct intel_plane *
Ville Syrjälä580503c2016-10-31 22:37:00 +020013708intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
Matt Roper465c1202014-05-29 08:06:54 -070013709{
Ville Syrjälä881440a2018-10-05 15:58:17 +030013710 struct intel_plane *plane;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013711 const struct drm_plane_funcs *plane_funcs;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013712 unsigned int supported_rotations;
Ville Syrjälädeb19682018-10-05 15:58:08 +030013713 unsigned int possible_crtcs;
Ville Syrjälä881440a2018-10-05 15:58:17 +030013714 const u64 *modifiers;
13715 const u32 *formats;
13716 int num_formats;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013717 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013718
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013719 if (INTEL_GEN(dev_priv) >= 9)
13720 return skl_universal_plane_create(dev_priv, pipe,
13721 PLANE_PRIMARY);
13722
Ville Syrjälä881440a2018-10-05 15:58:17 +030013723 plane = intel_plane_alloc();
13724 if (IS_ERR(plane))
13725 return plane;
Matt Roperea2c67b2014-12-23 10:41:52 -080013726
Ville Syrjälä881440a2018-10-05 15:58:17 +030013727 plane->pipe = pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020013728 /*
13729 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13730 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13731 */
13732 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030013733 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020013734 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030013735 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
13736 plane->id = PLANE_PRIMARY;
13737 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013738
Ville Syrjälä881440a2018-10-05 15:58:17 +030013739 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
13740 if (plane->has_fbc) {
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013741 struct intel_fbc *fbc = &dev_priv->fbc;
13742
Ville Syrjälä881440a2018-10-05 15:58:17 +030013743 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013744 }
13745
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013746 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä881440a2018-10-05 15:58:17 +030013747 formats = i965_primary_formats;
Damien Lespiau568db4f2015-05-12 16:13:18 +010013748 num_formats = ARRAY_SIZE(i965_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070013749 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010013750
Ville Syrjälä881440a2018-10-05 15:58:17 +030013751 plane->max_stride = i9xx_plane_max_stride;
13752 plane->update_plane = i9xx_update_plane;
13753 plane->disable_plane = i9xx_disable_plane;
13754 plane->get_hw_state = i9xx_plane_get_hw_state;
13755 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013756
13757 plane_funcs = &i965_plane_funcs;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010013758 } else {
Ville Syrjälä881440a2018-10-05 15:58:17 +030013759 formats = i8xx_primary_formats;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010013760 num_formats = ARRAY_SIZE(i8xx_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070013761 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010013762
Ville Syrjälä881440a2018-10-05 15:58:17 +030013763 plane->max_stride = i9xx_plane_max_stride;
13764 plane->update_plane = i9xx_update_plane;
13765 plane->disable_plane = i9xx_disable_plane;
13766 plane->get_hw_state = i9xx_plane_get_hw_state;
13767 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013768
13769 plane_funcs = &i8xx_plane_funcs;
Matt Roper465c1202014-05-29 08:06:54 -070013770 }
13771
Ville Syrjälädeb19682018-10-05 15:58:08 +030013772 possible_crtcs = BIT(pipe);
13773
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013774 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Ville Syrjälä881440a2018-10-05 15:58:17 +030013775 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013776 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030013777 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013778 DRM_PLANE_TYPE_PRIMARY,
13779 "primary %c", pipe_name(pipe));
13780 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030013781 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013782 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030013783 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013784 DRM_PLANE_TYPE_PRIMARY,
Ville Syrjäläed150302017-11-17 21:19:10 +020013785 "plane %c",
Ville Syrjälä881440a2018-10-05 15:58:17 +030013786 plane_name(plane->i9xx_plane));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013787 if (ret)
13788 goto fail;
Sonika Jindal48404c12014-08-22 14:06:04 +053013789
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013790 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjälä4ea7be22016-11-14 18:54:00 +020013791 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040013792 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13793 DRM_MODE_REFLECT_X;
Dave Airlie5481e272016-10-25 16:36:13 +100013794 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013795 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040013796 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013797 } else {
Robert Fossc2c446a2017-05-19 16:50:17 -040013798 supported_rotations = DRM_MODE_ROTATE_0;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013799 }
13800
Dave Airlie5481e272016-10-25 16:36:13 +100013801 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030013802 drm_plane_create_rotation_property(&plane->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040013803 DRM_MODE_ROTATE_0,
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013804 supported_rotations);
Sonika Jindal48404c12014-08-22 14:06:04 +053013805
Ville Syrjälä881440a2018-10-05 15:58:17 +030013806 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
Matt Roperea2c67b2014-12-23 10:41:52 -080013807
Ville Syrjälä881440a2018-10-05 15:58:17 +030013808 return plane;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013809
13810fail:
Ville Syrjälä881440a2018-10-05 15:58:17 +030013811 intel_plane_free(plane);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013812
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013813 return ERR_PTR(ret);
Matt Roper465c1202014-05-29 08:06:54 -070013814}
13815
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013816static struct intel_plane *
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013817intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13818 enum pipe pipe)
Matt Roper3d7d6512014-06-10 08:28:13 -070013819{
Ville Syrjälädeb19682018-10-05 15:58:08 +030013820 unsigned int possible_crtcs;
Ville Syrjäläc539b572018-10-05 15:58:14 +030013821 struct intel_plane *cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013822 int ret;
Matt Roper3d7d6512014-06-10 08:28:13 -070013823
Ville Syrjäläc539b572018-10-05 15:58:14 +030013824 cursor = intel_plane_alloc();
13825 if (IS_ERR(cursor))
13826 return cursor;
Matt Roperea2c67b2014-12-23 10:41:52 -080013827
Matt Roper3d7d6512014-06-10 08:28:13 -070013828 cursor->pipe = pipe;
Ville Syrjäläed150302017-11-17 21:19:10 +020013829 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
Ville Syrjäläb14e5842016-11-22 18:01:56 +020013830 cursor->id = PLANE_CURSOR;
Ville Syrjäläc19e1122018-01-23 20:33:43 +020013831 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013832
13833 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
Ville Syrjäläddd57132018-09-07 18:24:02 +030013834 cursor->max_stride = i845_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013835 cursor->update_plane = i845_update_cursor;
13836 cursor->disable_plane = i845_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020013837 cursor->get_hw_state = i845_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030013838 cursor->check_plane = i845_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013839 } else {
Ville Syrjäläddd57132018-09-07 18:24:02 +030013840 cursor->max_stride = i9xx_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013841 cursor->update_plane = i9xx_update_cursor;
13842 cursor->disable_plane = i9xx_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020013843 cursor->get_hw_state = i9xx_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030013844 cursor->check_plane = i9xx_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013845 }
Matt Roper3d7d6512014-06-10 08:28:13 -070013846
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030013847 cursor->cursor.base = ~0;
13848 cursor->cursor.cntl = ~0;
Ville Syrjälä024faac2017-03-27 21:55:42 +030013849
13850 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13851 cursor->cursor.size = ~0;
Matt Roper3d7d6512014-06-10 08:28:13 -070013852
Ville Syrjälädeb19682018-10-05 15:58:08 +030013853 possible_crtcs = BIT(pipe);
13854
Ville Syrjälä580503c2016-10-31 22:37:00 +020013855 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013856 possible_crtcs, &intel_cursor_plane_funcs,
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013857 intel_cursor_formats,
13858 ARRAY_SIZE(intel_cursor_formats),
Ben Widawsky714244e2017-08-01 09:58:16 -070013859 cursor_format_modifiers,
13860 DRM_PLANE_TYPE_CURSOR,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013861 "cursor %c", pipe_name(pipe));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013862 if (ret)
13863 goto fail;
Ville Syrjälä4398ad42014-10-23 07:41:34 -070013864
Dave Airlie5481e272016-10-25 16:36:13 +100013865 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013866 drm_plane_create_rotation_property(&cursor->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040013867 DRM_MODE_ROTATE_0,
13868 DRM_MODE_ROTATE_0 |
13869 DRM_MODE_ROTATE_180);
Ville Syrjälä4398ad42014-10-23 07:41:34 -070013870
Matt Roperea2c67b2014-12-23 10:41:52 -080013871 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13872
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013873 return cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013874
13875fail:
Ville Syrjäläc539b572018-10-05 15:58:14 +030013876 intel_plane_free(cursor);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013877
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013878 return ERR_PTR(ret);
Matt Roper3d7d6512014-06-10 08:28:13 -070013879}
13880
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053013881static void intel_crtc_init_scalers(struct intel_crtc *crtc,
13882 struct intel_crtc_state *crtc_state)
Chandra Konduru549e2bf2015-04-07 15:28:38 -070013883{
Ville Syrjälä65edccc2016-10-31 22:37:01 +020013884 struct intel_crtc_scaler_state *scaler_state =
13885 &crtc_state->scaler_state;
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053013886 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru549e2bf2015-04-07 15:28:38 -070013887 int i;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070013888
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053013889 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
13890 if (!crtc->num_scalers)
13891 return;
13892
Ville Syrjälä65edccc2016-10-31 22:37:01 +020013893 for (i = 0; i < crtc->num_scalers; i++) {
13894 struct intel_scaler *scaler = &scaler_state->scalers[i];
13895
13896 scaler->in_use = 0;
Maarten Lankhorst0aaf29b2018-09-21 16:44:37 +020013897 scaler->mode = 0;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070013898 }
13899
13900 scaler_state->scaler_id = -1;
13901}
13902
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020013903static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnes79e53942008-11-07 14:24:08 -080013904{
13905 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013906 struct intel_crtc_state *crtc_state = NULL;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013907 struct intel_plane *primary = NULL;
13908 struct intel_plane *cursor = NULL;
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030013909 int sprite, ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080013910
Daniel Vetter955382f2013-09-19 14:05:45 +020013911 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013912 if (!intel_crtc)
13913 return -ENOMEM;
Jesse Barnes79e53942008-11-07 14:24:08 -080013914
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013915 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013916 if (!crtc_state) {
13917 ret = -ENOMEM;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013918 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013919 }
Ander Conselvan de Oliveira550acef2015-04-21 17:13:24 +030013920 intel_crtc->config = crtc_state;
13921 intel_crtc->base.state = &crtc_state->base;
Matt Roper07878242015-02-25 11:43:26 -080013922 crtc_state->base.crtc = &intel_crtc->base;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013923
Ville Syrjälä580503c2016-10-31 22:37:00 +020013924 primary = intel_primary_plane_create(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013925 if (IS_ERR(primary)) {
13926 ret = PTR_ERR(primary);
Matt Roper3d7d6512014-06-10 08:28:13 -070013927 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013928 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020013929 intel_crtc->plane_ids_mask |= BIT(primary->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070013930
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030013931 for_each_sprite(dev_priv, pipe, sprite) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013932 struct intel_plane *plane;
13933
Ville Syrjälä580503c2016-10-31 22:37:00 +020013934 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020013935 if (IS_ERR(plane)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013936 ret = PTR_ERR(plane);
13937 goto fail;
13938 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020013939 intel_crtc->plane_ids_mask |= BIT(plane->id);
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030013940 }
13941
Ville Syrjälä580503c2016-10-31 22:37:00 +020013942 cursor = intel_cursor_plane_create(dev_priv, pipe);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020013943 if (IS_ERR(cursor)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013944 ret = PTR_ERR(cursor);
Matt Roper3d7d6512014-06-10 08:28:13 -070013945 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013946 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020013947 intel_crtc->plane_ids_mask |= BIT(cursor->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070013948
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020013949 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013950 &primary->base, &cursor->base,
13951 &intel_crtc_funcs,
Ville Syrjälä4d5d72b72016-05-27 20:59:21 +030013952 "pipe %c", pipe_name(pipe));
Matt Roper3d7d6512014-06-10 08:28:13 -070013953 if (ret)
13954 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080013955
Jesse Barnes80824002009-09-10 15:28:06 -070013956 intel_crtc->pipe = pipe;
Jesse Barnes80824002009-09-10 15:28:06 -070013957
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053013958 /* initialize shared scalers */
13959 intel_crtc_init_scalers(intel_crtc, crtc_state);
13960
Ville Syrjälä1947fd12018-03-05 19:41:22 +020013961 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
13962 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
13963 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
13964
13965 if (INTEL_GEN(dev_priv) < 9) {
13966 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
13967
13968 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
13969 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
13970 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
13971 }
Jesse Barnes22fd0fa2009-12-02 13:42:53 -080013972
Jesse Barnes79e53942008-11-07 14:24:08 -080013973 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
Daniel Vetter87b6b102014-05-15 15:33:46 +020013974
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +000013975 intel_color_init(&intel_crtc->base);
13976
Daniel Vetter87b6b102014-05-15 15:33:46 +020013977 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013978
13979 return 0;
Matt Roper3d7d6512014-06-10 08:28:13 -070013980
13981fail:
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013982 /*
13983 * drm_mode_config_cleanup() will free up any
13984 * crtcs/planes already initialized.
13985 */
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013986 kfree(crtc_state);
Matt Roper3d7d6512014-06-10 08:28:13 -070013987 kfree(intel_crtc);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013988
13989 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080013990}
13991
Ville Syrjälä6a20fe72018-02-07 18:48:41 +020013992int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
13993 struct drm_file *file)
Carl Worth08d7b3d2009-04-29 14:43:54 -070013994{
Carl Worth08d7b3d2009-04-29 14:43:54 -070013995 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
Rob Clark7707e652014-07-17 23:30:04 -040013996 struct drm_crtc *drmmode_crtc;
Daniel Vetterc05422d2009-08-11 16:05:30 +020013997 struct intel_crtc *crtc;
Carl Worth08d7b3d2009-04-29 14:43:54 -070013998
Keith Packard418da172017-03-14 23:25:07 -070013999 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
Chris Wilson71240ed2016-06-24 14:00:24 +010014000 if (!drmmode_crtc)
Ville Syrjälä3f2c2052013-10-17 13:35:03 +030014001 return -ENOENT;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014002
Rob Clark7707e652014-07-17 23:30:04 -040014003 crtc = to_intel_crtc(drmmode_crtc);
Daniel Vetterc05422d2009-08-11 16:05:30 +020014004 pipe_from_crtc_id->pipe = crtc->pipe;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014005
Daniel Vetterc05422d2009-08-11 16:05:30 +020014006 return 0;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014007}
14008
Daniel Vetter66a92782012-07-12 20:08:18 +020014009static int intel_encoder_clones(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080014010{
Daniel Vetter66a92782012-07-12 20:08:18 +020014011 struct drm_device *dev = encoder->base.dev;
14012 struct intel_encoder *source_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -080014013 int index_mask = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080014014 int entry = 0;
14015
Damien Lespiaub2784e12014-08-05 11:29:37 +010014016 for_each_intel_encoder(dev, source_encoder) {
Ville Syrjäläbc079e82014-03-03 16:15:28 +020014017 if (encoders_cloneable(encoder, source_encoder))
Daniel Vetter66a92782012-07-12 20:08:18 +020014018 index_mask |= (1 << entry);
14019
Jesse Barnes79e53942008-11-07 14:24:08 -080014020 entry++;
14021 }
Chris Wilson4ef69c72010-09-09 15:14:28 +010014022
Jesse Barnes79e53942008-11-07 14:24:08 -080014023 return index_mask;
14024}
14025
Ville Syrjälä646d5772016-10-31 22:37:14 +020014026static bool has_edp_a(struct drm_i915_private *dev_priv)
Chris Wilson4d302442010-12-14 19:21:29 +000014027{
Ville Syrjälä646d5772016-10-31 22:37:14 +020014028 if (!IS_MOBILE(dev_priv))
Chris Wilson4d302442010-12-14 19:21:29 +000014029 return false;
14030
14031 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14032 return false;
14033
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010014034 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
Chris Wilson4d302442010-12-14 19:21:29 +000014035 return false;
14036
14037 return true;
14038}
14039
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014040static bool intel_crt_present(struct drm_i915_private *dev_priv)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014041{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014042 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau884497e2013-12-03 13:56:23 +000014043 return false;
14044
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010014045 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014046 return false;
14047
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014048 if (IS_CHERRYVIEW(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014049 return false;
14050
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014051 if (HAS_PCH_LPT_H(dev_priv) &&
14052 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
Ville Syrjälä65e472e2015-12-01 23:28:55 +020014053 return false;
14054
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014055 /* DDI E can't be used if DDI A requires 4 lanes */
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014056 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 +020014057 return false;
14058
Ville Syrjäläe4abb732015-12-01 23:31:33 +020014059 if (!dev_priv->vbt.int_crt_support)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014060 return false;
14061
14062 return true;
14063}
14064
Imre Deak8090ba82016-08-10 14:07:33 +030014065void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14066{
14067 int pps_num;
14068 int pps_idx;
14069
14070 if (HAS_DDI(dev_priv))
14071 return;
14072 /*
14073 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14074 * everywhere where registers can be write protected.
14075 */
14076 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14077 pps_num = 2;
14078 else
14079 pps_num = 1;
14080
14081 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14082 u32 val = I915_READ(PP_CONTROL(pps_idx));
14083
14084 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14085 I915_WRITE(PP_CONTROL(pps_idx), val);
14086 }
14087}
14088
Imre Deak44cb7342016-08-10 14:07:29 +030014089static void intel_pps_init(struct drm_i915_private *dev_priv)
14090{
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +020014091 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +030014092 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14093 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14094 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14095 else
14096 dev_priv->pps_mmio_base = PPS_BASE;
Imre Deak8090ba82016-08-10 14:07:33 +030014097
14098 intel_pps_unlock_regs_wa(dev_priv);
Imre Deak44cb7342016-08-10 14:07:29 +030014099}
14100
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014101static void intel_setup_outputs(struct drm_i915_private *dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -080014102{
Chris Wilson4ef69c72010-09-09 15:14:28 +010014103 struct intel_encoder *encoder;
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014104 bool dpd_is_edp = false;
Jesse Barnes79e53942008-11-07 14:24:08 -080014105
Imre Deak44cb7342016-08-10 14:07:29 +030014106 intel_pps_init(dev_priv);
14107
Chris Wilsonfc0c5a92018-08-15 21:12:07 +010014108 if (INTEL_INFO(dev_priv)->num_pipes == 0)
14109 return;
14110
Imre Deak97a824e12016-06-21 11:51:47 +030014111 /*
14112 * intel_edp_init_connector() depends on this completing first, to
14113 * prevent the registeration of both eDP and LVDS and the incorrect
14114 * sharing of the PPS.
14115 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014116 intel_lvds_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014117
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014118 if (intel_crt_present(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014119 intel_crt_init(dev_priv);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014120
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014121 if (IS_ICELAKE(dev_priv)) {
14122 intel_ddi_init(dev_priv, PORT_A);
14123 intel_ddi_init(dev_priv, PORT_B);
14124 intel_ddi_init(dev_priv, PORT_C);
14125 intel_ddi_init(dev_priv, PORT_D);
14126 intel_ddi_init(dev_priv, PORT_E);
14127 intel_ddi_init(dev_priv, PORT_F);
14128 } else if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanc776eb22014-08-19 12:05:01 +053014129 /*
14130 * FIXME: Broxton doesn't support port detection via the
14131 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14132 * detect the ports.
14133 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014134 intel_ddi_init(dev_priv, PORT_A);
14135 intel_ddi_init(dev_priv, PORT_B);
14136 intel_ddi_init(dev_priv, PORT_C);
Shashank Sharmac6c794a2016-03-22 12:01:50 +020014137
Jani Nikulae5186342018-07-05 16:25:08 +030014138 vlv_dsi_init(dev_priv);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014139 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014140 int found;
14141
Jesse Barnesde31fac2015-03-06 15:53:32 -080014142 /*
14143 * Haswell uses DDI functions to detect digital outputs.
14144 * On SKL pre-D0 the strap isn't connected, so we assume
14145 * it's there.
14146 */
Ville Syrjälä77179402015-09-18 20:03:35 +030014147 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
Jesse Barnesde31fac2015-03-06 15:53:32 -080014148 /* WaIgnoreDDIAStrap: skl */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014149 if (found || IS_GEN9_BC(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014150 intel_ddi_init(dev_priv, PORT_A);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014151
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014152 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014153 * register */
14154 found = I915_READ(SFUSE_STRAP);
14155
14156 if (found & SFUSE_STRAP_DDIB_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014157 intel_ddi_init(dev_priv, PORT_B);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014158 if (found & SFUSE_STRAP_DDIC_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014159 intel_ddi_init(dev_priv, PORT_C);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014160 if (found & SFUSE_STRAP_DDID_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014161 intel_ddi_init(dev_priv, PORT_D);
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014162 if (found & SFUSE_STRAP_DDIF_DETECTED)
14163 intel_ddi_init(dev_priv, PORT_F);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014164 /*
14165 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14166 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014167 if (IS_GEN9_BC(dev_priv) &&
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014168 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14169 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14170 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014171 intel_ddi_init(dev_priv, PORT_E);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014172
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010014173 } else if (HAS_PCH_SPLIT(dev_priv)) {
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014174 int found;
Jani Nikula7b91bf72017-08-18 12:30:19 +030014175 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
Daniel Vetter270b3042012-10-27 15:52:05 +020014176
Ville Syrjälä646d5772016-10-31 22:37:14 +020014177 if (has_edp_a(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014178 intel_dp_init(dev_priv, DP_A, PORT_A);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014179
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014180 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
Zhao Yakui461ed3c2010-03-30 15:11:33 +080014181 /* PCH SDVOB multiplex with HDMIB */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014182 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014183 if (!found)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014184 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014185 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014186 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014187 }
14188
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014189 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014190 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014191
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014192 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014193 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014194
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014195 if (I915_READ(PCH_DP_C) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014196 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014197
Daniel Vetter270b3042012-10-27 15:52:05 +020014198 if (I915_READ(PCH_DP_D) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014199 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014200 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014201 bool has_edp, has_port;
Chris Wilson457c52d2016-06-01 08:27:50 +010014202
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014203 /*
14204 * The DP_DETECTED bit is the latched state of the DDC
14205 * SDA pin at boot. However since eDP doesn't require DDC
14206 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14207 * eDP ports may have been muxed to an alternate function.
14208 * Thus we can't rely on the DP_DETECTED bit alone to detect
14209 * eDP ports. Consult the VBT as well as DP_DETECTED to
14210 * detect eDP ports.
Ville Syrjälä22f350422016-06-03 12:17:43 +030014211 *
14212 * Sadly the straps seem to be missing sometimes even for HDMI
14213 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14214 * and VBT for the presence of the port. Additionally we can't
14215 * trust the port type the VBT declares as we've seen at least
14216 * HDMI ports that the VBT claim are DP or eDP.
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014217 */
Jani Nikula7b91bf72017-08-18 12:30:19 +030014218 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014219 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14220 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014221 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014222 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014223 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
Artem Bityutskiy585a94b2013-10-16 18:10:41 +030014224
Jani Nikula7b91bf72017-08-18 12:30:19 +030014225 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014226 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14227 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014228 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014229 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014230 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
Gajanan Bhat19c03922012-09-27 19:13:07 +053014231
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014232 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014233 /*
14234 * eDP not supported on port D,
14235 * so no need to worry about it
14236 */
14237 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14238 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014239 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014240 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014241 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
Ville Syrjälä9418c1f2014-04-09 13:28:56 +030014242 }
14243
Jani Nikulae5186342018-07-05 16:25:08 +030014244 vlv_dsi_init(dev_priv);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010014245 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014246 bool found = false;
Eric Anholt7d573822009-01-02 13:33:00 -080014247
Paulo Zanonie2debe92013-02-18 19:00:27 -030014248 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014249 DRM_DEBUG_KMS("probing SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014250 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014251 if (!found && IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014252 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014253 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014254 }
Ma Ling27185ae2009-08-24 13:50:23 +080014255
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014256 if (!found && IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014257 intel_dp_init(dev_priv, DP_B, PORT_B);
Eric Anholt725e30a2009-01-22 13:01:02 -080014258 }
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014259
14260 /* Before G4X SDVOC doesn't have its own detect register */
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014261
Paulo Zanonie2debe92013-02-18 19:00:27 -030014262 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014263 DRM_DEBUG_KMS("probing SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014264 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014265 }
Ma Ling27185ae2009-08-24 13:50:23 +080014266
Paulo Zanonie2debe92013-02-18 19:00:27 -030014267 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014268
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014269 if (IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014270 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014271 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014272 }
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014273 if (IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014274 intel_dp_init(dev_priv, DP_C, PORT_C);
Eric Anholt725e30a2009-01-22 13:01:02 -080014275 }
Ma Ling27185ae2009-08-24 13:50:23 +080014276
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014277 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014278 intel_dp_init(dev_priv, DP_D, PORT_D);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010014279 } else if (IS_GEN2(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014280 intel_dvo_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014281
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +000014282 if (SUPPORTS_TV(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014283 intel_tv_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014284
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014285 intel_psr_init(dev_priv);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -070014286
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014287 for_each_intel_encoder(&dev_priv->drm, encoder) {
Chris Wilson4ef69c72010-09-09 15:14:28 +010014288 encoder->base.possible_crtcs = encoder->crtc_mask;
14289 encoder->base.possible_clones =
Daniel Vetter66a92782012-07-12 20:08:18 +020014290 intel_encoder_clones(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -080014291 }
Chris Wilson47356eb2011-01-11 17:06:04 +000014292
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014293 intel_init_pch_refclk(dev_priv);
Daniel Vetter270b3042012-10-27 15:52:05 +020014294
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014295 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
Jesse Barnes79e53942008-11-07 14:24:08 -080014296}
14297
14298static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14299{
14300 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014301 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014302
Daniel Vetteref2d6332014-02-10 18:00:38 +010014303 drm_framebuffer_cleanup(fb);
Chris Wilson70001cd2017-02-16 09:46:21 +000014304
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014305 i915_gem_object_lock(obj);
14306 WARN_ON(!obj->framebuffer_references--);
14307 i915_gem_object_unlock(obj);
Chris Wilsondd689282017-03-01 15:41:28 +000014308
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014309 i915_gem_object_put(obj);
Chris Wilson70001cd2017-02-16 09:46:21 +000014310
Jesse Barnes79e53942008-11-07 14:24:08 -080014311 kfree(intel_fb);
14312}
14313
14314static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
Chris Wilson05394f32010-11-08 19:18:58 +000014315 struct drm_file *file,
Jesse Barnes79e53942008-11-07 14:24:08 -080014316 unsigned int *handle)
14317{
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014318 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014319
Chris Wilsoncc917ab2015-10-13 14:22:26 +010014320 if (obj->userptr.mm) {
14321 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14322 return -EINVAL;
14323 }
14324
Chris Wilson05394f32010-11-08 19:18:58 +000014325 return drm_gem_handle_create(file, &obj->base, handle);
Jesse Barnes79e53942008-11-07 14:24:08 -080014326}
14327
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014328static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14329 struct drm_file *file,
14330 unsigned flags, unsigned color,
14331 struct drm_clip_rect *clips,
14332 unsigned num_clips)
14333{
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014334 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014335
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014336 i915_gem_object_flush_if_display(obj);
Chris Wilsond59b21e2017-02-22 11:40:49 +000014337 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014338
14339 return 0;
14340}
14341
Jesse Barnes79e53942008-11-07 14:24:08 -080014342static const struct drm_framebuffer_funcs intel_fb_funcs = {
14343 .destroy = intel_user_framebuffer_destroy,
14344 .create_handle = intel_user_framebuffer_create_handle,
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014345 .dirty = intel_user_framebuffer_dirty,
Jesse Barnes79e53942008-11-07 14:24:08 -080014346};
14347
Damien Lespiaub3218032015-02-27 11:15:18 +000014348static
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014349u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14350 uint64_t fb_modifier, uint32_t pixel_format)
Damien Lespiaub3218032015-02-27 11:15:18 +000014351{
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014352 struct intel_crtc *crtc;
14353 struct intel_plane *plane;
Damien Lespiaub3218032015-02-27 11:15:18 +000014354
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014355 /*
14356 * We assume the primary plane for pipe A has
14357 * the highest stride limits of them all.
14358 */
14359 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14360 plane = to_intel_plane(crtc->base.primary);
Ville Syrjäläac484962016-01-20 21:05:26 +020014361
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014362 return plane->max_stride(plane, pixel_format, fb_modifier,
14363 DRM_MODE_ROTATE_0);
Damien Lespiaub3218032015-02-27 11:15:18 +000014364}
14365
Chris Wilson24dbf512017-02-15 10:59:18 +000014366static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14367 struct drm_i915_gem_object *obj,
14368 struct drm_mode_fb_cmd2 *mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014369{
Chris Wilson24dbf512017-02-15 10:59:18 +000014370 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014371 struct drm_framebuffer *fb = &intel_fb->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +000014372 struct drm_format_name_buf format_name;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014373 u32 pitch_limit;
Chris Wilsondd689282017-03-01 15:41:28 +000014374 unsigned int tiling, stride;
Chris Wilson24dbf512017-02-15 10:59:18 +000014375 int ret = -EINVAL;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014376 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -080014377
Chris Wilsondd689282017-03-01 15:41:28 +000014378 i915_gem_object_lock(obj);
14379 obj->framebuffer_references++;
14380 tiling = i915_gem_object_get_tiling(obj);
14381 stride = i915_gem_object_get_stride(obj);
14382 i915_gem_object_unlock(obj);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020014383
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014384 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014385 /*
14386 * If there's a fence, enforce that
14387 * the fb modifier and tiling mode match.
14388 */
14389 if (tiling != I915_TILING_NONE &&
14390 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014391 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014392 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014393 }
14394 } else {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014395 if (tiling == I915_TILING_X) {
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014396 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014397 } else if (tiling == I915_TILING_Y) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014398 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014399 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014400 }
14401 }
14402
Tvrtko Ursulin9a8f0a12015-02-27 11:15:24 +000014403 /* Passed in modifier sanity checking. */
14404 switch (mode_cmd->modifier[0]) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014405 case I915_FORMAT_MOD_Y_TILED_CCS:
14406 case I915_FORMAT_MOD_Yf_TILED_CCS:
14407 switch (mode_cmd->pixel_format) {
14408 case DRM_FORMAT_XBGR8888:
14409 case DRM_FORMAT_ABGR8888:
14410 case DRM_FORMAT_XRGB8888:
14411 case DRM_FORMAT_ARGB8888:
14412 break;
14413 default:
14414 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
14415 goto err;
14416 }
14417 /* fall through */
Tvrtko Ursulin9a8f0a12015-02-27 11:15:24 +000014418 case I915_FORMAT_MOD_Yf_TILED:
Paulo Zanonief51e0a2018-09-24 17:19:11 -070014419 if (mode_cmd->pixel_format == DRM_FORMAT_C8) {
14420 DRM_DEBUG_KMS("Indexed format does not support Yf tiling\n");
14421 goto err;
14422 }
14423 /* fall through */
14424 case I915_FORMAT_MOD_Y_TILED:
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014425 if (INTEL_GEN(dev_priv) < 9) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014426 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14427 mode_cmd->modifier[0]);
Chris Wilson24dbf512017-02-15 10:59:18 +000014428 goto err;
Tvrtko Ursulin9a8f0a12015-02-27 11:15:24 +000014429 }
Paulo Zanonief51e0a2018-09-24 17:19:11 -070014430 break;
Ben Widawsky2f075562017-03-24 14:29:48 -070014431 case DRM_FORMAT_MOD_LINEAR:
Tvrtko Ursulin9a8f0a12015-02-27 11:15:24 +000014432 case I915_FORMAT_MOD_X_TILED:
14433 break;
14434 default:
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014435 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14436 mode_cmd->modifier[0]);
Chris Wilson24dbf512017-02-15 10:59:18 +000014437 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014438 }
Chris Wilson57cd6502010-08-08 12:34:44 +010014439
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014440 /*
14441 * gen2/3 display engine uses the fence if present,
14442 * so the tiling mode must match the fb modifier exactly.
14443 */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014444 if (INTEL_GEN(dev_priv) < 4 &&
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014445 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014446 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014447 goto err;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014448 }
14449
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014450 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
Damien Lespiaub3218032015-02-27 11:15:18 +000014451 mode_cmd->pixel_format);
Chris Wilsona35cdaa2013-06-25 17:26:45 +010014452 if (mode_cmd->pitches[0] > pitch_limit) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014453 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
Ben Widawsky2f075562017-03-24 14:29:48 -070014454 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014455 "tiled" : "linear",
14456 mode_cmd->pitches[0], pitch_limit);
Chris Wilson24dbf512017-02-15 10:59:18 +000014457 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014458 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014459
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014460 /*
14461 * If there's a fence, enforce that
14462 * the fb pitch and fence stride match.
14463 */
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014464 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14465 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14466 mode_cmd->pitches[0], stride);
Chris Wilson24dbf512017-02-15 10:59:18 +000014467 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014468 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014469
Ville Syrjälä57779d02012-10-31 17:50:14 +020014470 /* Reject formats not supported by any plane early. */
Jesse Barnes308e5bc2011-11-14 14:51:28 -080014471 switch (mode_cmd->pixel_format) {
Ville Syrjälä57779d02012-10-31 17:50:14 +020014472 case DRM_FORMAT_C8:
Ville Syrjälä04b39242011-11-17 18:05:13 +020014473 case DRM_FORMAT_RGB565:
14474 case DRM_FORMAT_XRGB8888:
14475 case DRM_FORMAT_ARGB8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +020014476 break;
14477 case DRM_FORMAT_XRGB1555:
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014478 if (INTEL_GEN(dev_priv) > 3) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014479 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14480 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014481 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014482 }
Ville Syrjälä57779d02012-10-31 17:50:14 +020014483 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +020014484 case DRM_FORMAT_ABGR8888:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014485 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014486 INTEL_GEN(dev_priv) < 9) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014487 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14488 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014489 goto err;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010014490 }
14491 break;
14492 case DRM_FORMAT_XBGR8888:
Ville Syrjälä04b39242011-11-17 18:05:13 +020014493 case DRM_FORMAT_XRGB2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +020014494 case DRM_FORMAT_XBGR2101010:
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014495 if (INTEL_GEN(dev_priv) < 4) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014496 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14497 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014498 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014499 }
Jesse Barnesb5626742011-06-24 12:19:27 -070014500 break;
Damien Lespiau75312082015-05-15 19:06:01 +010014501 case DRM_FORMAT_ABGR2101010:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014502 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014503 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14504 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014505 goto err;
Damien Lespiau75312082015-05-15 19:06:01 +010014506 }
14507 break;
Ville Syrjälä04b39242011-11-17 18:05:13 +020014508 case DRM_FORMAT_YUYV:
14509 case DRM_FORMAT_UYVY:
14510 case DRM_FORMAT_YVYU:
14511 case DRM_FORMAT_VYUY:
Ville Syrjäläab330812017-04-21 21:14:32 +030014512 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014513 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14514 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014515 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014516 }
Chris Wilson57cd6502010-08-08 12:34:44 +010014517 break;
Chandra Kondurue44134f2018-05-12 03:03:15 +053014518 case DRM_FORMAT_NV12:
Chandra Kondurue44134f2018-05-12 03:03:15 +053014519 if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) ||
Dhinakaran Pandiyanb45649f2018-08-24 13:38:56 -070014520 IS_BROXTON(dev_priv) || INTEL_GEN(dev_priv) >= 11) {
Chandra Kondurue44134f2018-05-12 03:03:15 +053014521 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14522 drm_get_format_name(mode_cmd->pixel_format,
14523 &format_name));
14524 goto err;
14525 }
14526 break;
Chris Wilson57cd6502010-08-08 12:34:44 +010014527 default:
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014528 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14529 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014530 goto err;
Chris Wilson57cd6502010-08-08 12:34:44 +010014531 }
14532
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014533 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14534 if (mode_cmd->offsets[0] != 0)
Chris Wilson24dbf512017-02-15 10:59:18 +000014535 goto err;
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014536
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014537 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014538
Chandra Kondurue44134f2018-05-12 03:03:15 +053014539 if (fb->format->format == DRM_FORMAT_NV12 &&
14540 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14541 fb->height < SKL_MIN_YUV_420_SRC_H ||
14542 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14543 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
14544 return -EINVAL;
14545 }
14546
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014547 for (i = 0; i < fb->format->num_planes; i++) {
14548 u32 stride_alignment;
14549
14550 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14551 DRM_DEBUG_KMS("bad plane %d handle\n", i);
Christophe JAILLET37875d62017-09-10 10:56:42 +020014552 goto err;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014553 }
14554
14555 stride_alignment = intel_fb_stride_alignment(fb, i);
14556
14557 /*
14558 * Display WA #0531: skl,bxt,kbl,glk
14559 *
14560 * Render decompression and plane width > 3840
14561 * combined with horizontal panning requires the
14562 * plane stride to be a multiple of 4. We'll just
14563 * require the entire fb to accommodate that to avoid
14564 * potential runtime errors at plane configuration time.
14565 */
14566 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -070014567 is_ccs_modifier(fb->modifier))
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014568 stride_alignment *= 4;
14569
14570 if (fb->pitches[i] & (stride_alignment - 1)) {
14571 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14572 i, fb->pitches[i], stride_alignment);
14573 goto err;
14574 }
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014575
Daniel Stonea268bcd2018-05-18 15:30:08 +010014576 fb->obj[i] = &obj->base;
14577 }
Daniel Vetterc7d73f62012-12-13 23:38:38 +010014578
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014579 ret = intel_fill_fb_info(dev_priv, fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +030014580 if (ret)
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014581 goto err;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +020014582
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014583 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -080014584 if (ret) {
14585 DRM_ERROR("framebuffer init failed %d\n", ret);
Chris Wilson24dbf512017-02-15 10:59:18 +000014586 goto err;
Jesse Barnes79e53942008-11-07 14:24:08 -080014587 }
14588
Jesse Barnes79e53942008-11-07 14:24:08 -080014589 return 0;
Chris Wilson24dbf512017-02-15 10:59:18 +000014590
14591err:
Chris Wilsondd689282017-03-01 15:41:28 +000014592 i915_gem_object_lock(obj);
14593 obj->framebuffer_references--;
14594 i915_gem_object_unlock(obj);
Chris Wilson24dbf512017-02-15 10:59:18 +000014595 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014596}
14597
Jesse Barnes79e53942008-11-07 14:24:08 -080014598static struct drm_framebuffer *
14599intel_user_framebuffer_create(struct drm_device *dev,
14600 struct drm_file *filp,
Ville Syrjälä1eb834512015-11-11 19:11:29 +020014601 const struct drm_mode_fb_cmd2 *user_mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014602{
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014603 struct drm_framebuffer *fb;
Chris Wilson05394f32010-11-08 19:18:58 +000014604 struct drm_i915_gem_object *obj;
Ville Syrjälä76dc3762015-11-11 19:11:28 +020014605 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
Jesse Barnes79e53942008-11-07 14:24:08 -080014606
Chris Wilson03ac0642016-07-20 13:31:51 +010014607 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14608 if (!obj)
Chris Wilsoncce13ff2010-08-08 13:36:38 +010014609 return ERR_PTR(-ENOENT);
Jesse Barnes79e53942008-11-07 14:24:08 -080014610
Chris Wilson24dbf512017-02-15 10:59:18 +000014611 fb = intel_framebuffer_create(obj, &mode_cmd);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014612 if (IS_ERR(fb))
Chris Wilsonf0cd5182016-10-28 13:58:43 +010014613 i915_gem_object_put(obj);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014614
14615 return fb;
Jesse Barnes79e53942008-11-07 14:24:08 -080014616}
14617
Chris Wilson778e23a2016-12-05 14:29:39 +000014618static void intel_atomic_state_free(struct drm_atomic_state *state)
14619{
14620 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14621
14622 drm_atomic_state_default_release(state);
14623
14624 i915_sw_fence_fini(&intel_state->commit_ready);
14625
14626 kfree(state);
14627}
14628
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014629static enum drm_mode_status
14630intel_mode_valid(struct drm_device *dev,
14631 const struct drm_display_mode *mode)
14632{
Ville Syrjäläad77c532018-06-15 20:44:05 +030014633 struct drm_i915_private *dev_priv = to_i915(dev);
14634 int hdisplay_max, htotal_max;
14635 int vdisplay_max, vtotal_max;
14636
Ville Syrjäläe4dd27a2018-05-24 15:54:03 +030014637 /*
14638 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14639 * of DBLSCAN modes to the output's mode list when they detect
14640 * the scaling mode property on the connector. And they don't
14641 * ask the kernel to validate those modes in any way until
14642 * modeset time at which point the client gets a protocol error.
14643 * So in order to not upset those clients we silently ignore the
14644 * DBLSCAN flag on such connectors. For other connectors we will
14645 * reject modes with the DBLSCAN flag in encoder->compute_config().
14646 * And we always reject DBLSCAN modes in connector->mode_valid()
14647 * as we never want such modes on the connector's mode list.
14648 */
14649
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014650 if (mode->vscan > 1)
14651 return MODE_NO_VSCAN;
14652
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014653 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14654 return MODE_H_ILLEGAL;
14655
14656 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14657 DRM_MODE_FLAG_NCSYNC |
14658 DRM_MODE_FLAG_PCSYNC))
14659 return MODE_HSYNC;
14660
14661 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14662 DRM_MODE_FLAG_PIXMUX |
14663 DRM_MODE_FLAG_CLKDIV2))
14664 return MODE_BAD;
14665
Ville Syrjäläad77c532018-06-15 20:44:05 +030014666 if (INTEL_GEN(dev_priv) >= 9 ||
14667 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14668 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14669 vdisplay_max = 4096;
14670 htotal_max = 8192;
14671 vtotal_max = 8192;
14672 } else if (INTEL_GEN(dev_priv) >= 3) {
14673 hdisplay_max = 4096;
14674 vdisplay_max = 4096;
14675 htotal_max = 8192;
14676 vtotal_max = 8192;
14677 } else {
14678 hdisplay_max = 2048;
14679 vdisplay_max = 2048;
14680 htotal_max = 4096;
14681 vtotal_max = 4096;
14682 }
14683
14684 if (mode->hdisplay > hdisplay_max ||
14685 mode->hsync_start > htotal_max ||
14686 mode->hsync_end > htotal_max ||
14687 mode->htotal > htotal_max)
14688 return MODE_H_ILLEGAL;
14689
14690 if (mode->vdisplay > vdisplay_max ||
14691 mode->vsync_start > vtotal_max ||
14692 mode->vsync_end > vtotal_max ||
14693 mode->vtotal > vtotal_max)
14694 return MODE_V_ILLEGAL;
14695
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014696 return MODE_OK;
14697}
14698
Jesse Barnes79e53942008-11-07 14:24:08 -080014699static const struct drm_mode_config_funcs intel_mode_funcs = {
Jesse Barnes79e53942008-11-07 14:24:08 -080014700 .fb_create = intel_user_framebuffer_create,
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -070014701 .get_format_info = intel_get_format_info,
Daniel Vetter0632fef2013-10-08 17:44:49 +020014702 .output_poll_changed = intel_fbdev_output_poll_changed,
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014703 .mode_valid = intel_mode_valid,
Matt Roper5ee67f12015-01-21 16:35:44 -080014704 .atomic_check = intel_atomic_check,
14705 .atomic_commit = intel_atomic_commit,
Maarten Lankhorstde419ab2015-06-04 10:21:28 +020014706 .atomic_state_alloc = intel_atomic_state_alloc,
14707 .atomic_state_clear = intel_atomic_state_clear,
Chris Wilson778e23a2016-12-05 14:29:39 +000014708 .atomic_state_free = intel_atomic_state_free,
Jesse Barnes79e53942008-11-07 14:24:08 -080014709};
14710
Imre Deak88212942016-03-16 13:38:53 +020014711/**
14712 * intel_init_display_hooks - initialize the display modesetting hooks
14713 * @dev_priv: device private
14714 */
14715void intel_init_display_hooks(struct drm_i915_private *dev_priv)
Jesse Barnese70236a2009-09-21 10:42:27 -070014716{
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +020014717 intel_init_cdclk_hooks(dev_priv);
14718
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014719 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000014720 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014721 dev_priv->display.get_initial_plane_config =
14722 skylake_get_initial_plane_config;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000014723 dev_priv->display.crtc_compute_clock =
14724 haswell_crtc_compute_clock;
14725 dev_priv->display.crtc_enable = haswell_crtc_enable;
14726 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020014727 } else if (HAS_DDI(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014728 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014729 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020014730 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira797d0252014-10-29 11:32:34 +020014731 dev_priv->display.crtc_compute_clock =
14732 haswell_crtc_compute_clock;
Paulo Zanoni4f771f12012-10-23 18:29:51 -020014733 dev_priv->display.crtc_enable = haswell_crtc_enable;
14734 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020014735 } else if (HAS_PCH_SPLIT(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014736 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014737 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020014738 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +020014739 dev_priv->display.crtc_compute_clock =
14740 ironlake_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020014741 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14742 dev_priv->display.crtc_disable = ironlake_crtc_disable;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020014743 } else if (IS_CHERRYVIEW(dev_priv)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -070014744 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014745 dev_priv->display.get_initial_plane_config =
14746 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020014747 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14748 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14749 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14750 } else if (IS_VALLEYVIEW(dev_priv)) {
14751 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14752 dev_priv->display.get_initial_plane_config =
14753 i9xx_get_initial_plane_config;
14754 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
Jesse Barnes89b667f2013-04-18 14:51:36 -070014755 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14756 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +020014757 } else if (IS_G4X(dev_priv)) {
14758 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14759 dev_priv->display.get_initial_plane_config =
14760 i9xx_get_initial_plane_config;
14761 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14762 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14763 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +020014764 } else if (IS_PINEVIEW(dev_priv)) {
14765 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14766 dev_priv->display.get_initial_plane_config =
14767 i9xx_get_initial_plane_config;
14768 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14769 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14770 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +020014771 } else if (!IS_GEN2(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014772 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014773 dev_priv->display.get_initial_plane_config =
14774 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveirad6dfee72014-10-29 11:32:36 +020014775 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020014776 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14777 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +020014778 } else {
14779 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14780 dev_priv->display.get_initial_plane_config =
14781 i9xx_get_initial_plane_config;
14782 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14783 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14784 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Eric Anholtf564048e2011-03-30 13:01:02 -070014785 }
Jesse Barnese70236a2009-09-21 10:42:27 -070014786
Imre Deak88212942016-03-16 13:38:53 +020014787 if (IS_GEN5(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014788 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014789 } else if (IS_GEN6(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014790 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014791 } else if (IS_IVYBRIDGE(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014792 /* FIXME: detect B0+ stepping and use auto training */
14793 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014794 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014795 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
Ville Syrjälä445e7802016-05-11 22:44:42 +030014796 }
14797
Rodrigo Vivibd30ca22017-09-26 14:13:46 -070014798 if (INTEL_GEN(dev_priv) >= 9)
Lyude27082492016-08-24 07:48:10 +020014799 dev_priv->display.update_crtcs = skl_update_crtcs;
14800 else
14801 dev_priv->display.update_crtcs = intel_update_crtcs;
Jesse Barnese70236a2009-09-21 10:42:27 -070014802}
14803
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014804/* Disable the VGA plane that we never use */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000014805static void i915_disable_vga(struct drm_i915_private *dev_priv)
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014806{
David Weinehall52a05c32016-08-22 13:32:44 +030014807 struct pci_dev *pdev = dev_priv->drm.pdev;
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014808 u8 sr1;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014809 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014810
Ville Syrjälä2b37c612014-01-22 21:32:38 +020014811 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
David Weinehall52a05c32016-08-22 13:32:44 +030014812 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes3fdcf432012-04-06 11:46:27 -070014813 outb(SR01, VGA_SR_INDEX);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014814 sr1 = inb(VGA_SR_DATA);
14815 outb(sr1 | 1<<5, VGA_SR_DATA);
David Weinehall52a05c32016-08-22 13:32:44 +030014816 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014817 udelay(300);
14818
Ville Syrjälä01f5a622014-12-16 18:38:37 +020014819 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014820 POSTING_READ(vga_reg);
14821}
14822
Daniel Vetterf8175862012-04-10 15:50:11 +020014823void intel_modeset_init_hw(struct drm_device *dev)
14824{
Chris Wilsonfac5e232016-07-04 11:34:36 +010014825 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1a617b72015-12-03 14:31:06 +010014826
Ville Syrjälä4c75b942016-10-31 22:37:12 +020014827 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +030014828 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020014829 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
Daniel Vetterf8175862012-04-10 15:50:11 +020014830}
14831
Matt Roperd93c0372015-12-03 11:37:41 -080014832/*
14833 * Calculate what we think the watermarks should be for the state we've read
14834 * out of the hardware and then immediately program those watermarks so that
14835 * we ensure the hardware settings match our internal state.
14836 *
14837 * We can calculate what we think WM's should be by creating a duplicate of the
14838 * current state (which was constructed during hardware readout) and running it
14839 * through the atomic check code to calculate new watermark values in the
14840 * state object.
14841 */
14842static void sanitize_watermarks(struct drm_device *dev)
14843{
14844 struct drm_i915_private *dev_priv = to_i915(dev);
14845 struct drm_atomic_state *state;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014846 struct intel_atomic_state *intel_state;
Matt Roperd93c0372015-12-03 11:37:41 -080014847 struct drm_crtc *crtc;
14848 struct drm_crtc_state *cstate;
14849 struct drm_modeset_acquire_ctx ctx;
14850 int ret;
14851 int i;
14852
14853 /* Only supported on platforms that use atomic watermark design */
Matt Ropered4a6a72016-02-23 17:20:13 -080014854 if (!dev_priv->display.optimize_watermarks)
Matt Roperd93c0372015-12-03 11:37:41 -080014855 return;
14856
14857 /*
14858 * We need to hold connection_mutex before calling duplicate_state so
14859 * that the connector loop is protected.
14860 */
14861 drm_modeset_acquire_init(&ctx, 0);
14862retry:
Matt Roper0cd12622016-01-12 07:13:37 -080014863 ret = drm_modeset_lock_all_ctx(dev, &ctx);
Matt Roperd93c0372015-12-03 11:37:41 -080014864 if (ret == -EDEADLK) {
14865 drm_modeset_backoff(&ctx);
14866 goto retry;
14867 } else if (WARN_ON(ret)) {
Matt Roper0cd12622016-01-12 07:13:37 -080014868 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080014869 }
14870
14871 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14872 if (WARN_ON(IS_ERR(state)))
Matt Roper0cd12622016-01-12 07:13:37 -080014873 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080014874
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014875 intel_state = to_intel_atomic_state(state);
14876
Matt Ropered4a6a72016-02-23 17:20:13 -080014877 /*
14878 * Hardware readout is the only time we don't want to calculate
14879 * intermediate watermarks (since we don't trust the current
14880 * watermarks).
14881 */
Ville Syrjälä602ae832017-03-02 19:15:02 +020014882 if (!HAS_GMCH_DISPLAY(dev_priv))
14883 intel_state->skip_intermediate_wm = true;
Matt Ropered4a6a72016-02-23 17:20:13 -080014884
Matt Roperd93c0372015-12-03 11:37:41 -080014885 ret = intel_atomic_check(dev, state);
14886 if (ret) {
14887 /*
14888 * If we fail here, it means that the hardware appears to be
14889 * programmed in a way that shouldn't be possible, given our
14890 * understanding of watermark requirements. This might mean a
14891 * mistake in the hardware readout code or a mistake in the
14892 * watermark calculations for a given platform. Raise a WARN
14893 * so that this is noticeable.
14894 *
14895 * If this actually happens, we'll have to just leave the
14896 * BIOS-programmed watermarks untouched and hope for the best.
14897 */
14898 WARN(true, "Could not determine valid watermarks for inherited state\n");
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020014899 goto put_state;
Matt Roperd93c0372015-12-03 11:37:41 -080014900 }
14901
14902 /* Write calculated watermark values back */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010014903 for_each_new_crtc_in_state(state, crtc, cstate, i) {
Matt Roperd93c0372015-12-03 11:37:41 -080014904 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14905
Matt Ropered4a6a72016-02-23 17:20:13 -080014906 cs->wm.need_postvbl_update = true;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014907 dev_priv->display.optimize_watermarks(intel_state, cs);
Maarten Lankhorst556fe362017-11-10 12:34:53 +010014908
14909 to_intel_crtc_state(crtc->state)->wm = cs->wm;
Matt Roperd93c0372015-12-03 11:37:41 -080014910 }
14911
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020014912put_state:
Chris Wilson08536952016-10-14 13:18:18 +010014913 drm_atomic_state_put(state);
Matt Roper0cd12622016-01-12 07:13:37 -080014914fail:
Matt Roperd93c0372015-12-03 11:37:41 -080014915 drm_modeset_drop_locks(&ctx);
14916 drm_modeset_acquire_fini(&ctx);
14917}
14918
Chris Wilson58ecd9d2017-11-05 13:49:05 +000014919static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14920{
14921 if (IS_GEN5(dev_priv)) {
14922 u32 fdi_pll_clk =
14923 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14924
14925 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14926 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
14927 dev_priv->fdi_pll_freq = 270000;
14928 } else {
14929 return;
14930 }
14931
14932 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14933}
14934
Azhar Shaikh516a49c2018-07-06 11:37:30 -070014935static int intel_initial_commit(struct drm_device *dev)
14936{
14937 struct drm_atomic_state *state = NULL;
14938 struct drm_modeset_acquire_ctx ctx;
14939 struct drm_crtc *crtc;
14940 struct drm_crtc_state *crtc_state;
14941 int ret = 0;
14942
14943 state = drm_atomic_state_alloc(dev);
14944 if (!state)
14945 return -ENOMEM;
14946
14947 drm_modeset_acquire_init(&ctx, 0);
14948
14949retry:
14950 state->acquire_ctx = &ctx;
14951
14952 drm_for_each_crtc(crtc, dev) {
14953 crtc_state = drm_atomic_get_crtc_state(state, crtc);
14954 if (IS_ERR(crtc_state)) {
14955 ret = PTR_ERR(crtc_state);
14956 goto out;
14957 }
14958
14959 if (crtc_state->active) {
14960 ret = drm_atomic_add_affected_planes(state, crtc);
14961 if (ret)
14962 goto out;
14963 }
14964 }
14965
14966 ret = drm_atomic_commit(state);
14967
14968out:
14969 if (ret == -EDEADLK) {
14970 drm_atomic_state_clear(state);
14971 drm_modeset_backoff(&ctx);
14972 goto retry;
14973 }
14974
14975 drm_atomic_state_put(state);
14976
14977 drm_modeset_drop_locks(&ctx);
14978 drm_modeset_acquire_fini(&ctx);
14979
14980 return ret;
14981}
14982
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014983int intel_modeset_init(struct drm_device *dev)
Jesse Barnes79e53942008-11-07 14:24:08 -080014984{
Joonas Lahtinen72e96d62016-03-30 16:57:10 +030014985 struct drm_i915_private *dev_priv = to_i915(dev);
14986 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Damien Lespiau8cc87b72014-03-03 17:31:44 +000014987 enum pipe pipe;
Jesse Barnes46f297f2014-03-07 08:57:48 -080014988 struct intel_crtc *crtc;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070014989 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014990
Ville Syrjälä757fffc2017-11-13 15:36:22 +020014991 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
14992
Jesse Barnes79e53942008-11-07 14:24:08 -080014993 drm_mode_config_init(dev);
14994
14995 dev->mode_config.min_width = 0;
14996 dev->mode_config.min_height = 0;
14997
Dave Airlie019d96c2011-09-29 16:20:42 +010014998 dev->mode_config.preferred_depth = 24;
14999 dev->mode_config.prefer_shadow = 1;
15000
Tvrtko Ursulin25bab382015-02-10 17:16:16 +000015001 dev->mode_config.allow_fb_modifiers = true;
15002
Laurent Pincharte6ecefa2012-05-17 13:27:23 +020015003 dev->mode_config.funcs = &intel_mode_funcs;
Jesse Barnes79e53942008-11-07 14:24:08 -080015004
Andrea Arcangeli400c19d2017-04-07 01:23:45 +020015005 init_llist_head(&dev_priv->atomic_helper.free_list);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015006 INIT_WORK(&dev_priv->atomic_helper.free_work,
Chris Wilsonba318c62017-02-02 20:47:41 +000015007 intel_atomic_helper_free_state_worker);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015008
Jani Nikula27a981b2018-10-17 12:35:39 +030015009 intel_init_quirks(dev_priv);
Jesse Barnesb690e962010-07-19 13:53:12 -070015010
Ville Syrjälä62d75df2016-10-31 22:37:25 +020015011 intel_init_pm(dev_priv);
Eugeni Dodonov1fa61102012-04-18 15:29:26 -030015012
Lukas Wunner69f92f62015-07-15 13:57:35 +020015013 /*
15014 * There may be no VBT; and if the BIOS enabled SSC we can
15015 * just keep using it to avoid unnecessary flicker. Whereas if the
15016 * BIOS isn't using it, don't assume it will work even if the VBT
15017 * indicates as much.
15018 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010015019 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Lukas Wunner69f92f62015-07-15 13:57:35 +020015020 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15021 DREF_SSC1_ENABLE);
15022
15023 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15024 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15025 bios_lvds_use_ssc ? "en" : "dis",
15026 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15027 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15028 }
15029 }
15030
Ville Syrjäläad77c532018-06-15 20:44:05 +030015031 /* maximum framebuffer dimensions */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010015032 if (IS_GEN2(dev_priv)) {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015033 dev->mode_config.max_width = 2048;
15034 dev->mode_config.max_height = 2048;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010015035 } else if (IS_GEN3(dev_priv)) {
Keith Packard5e4d6fa2009-07-12 23:53:17 -070015036 dev->mode_config.max_width = 4096;
15037 dev->mode_config.max_height = 4096;
Jesse Barnes79e53942008-11-07 14:24:08 -080015038 } else {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015039 dev->mode_config.max_width = 8192;
15040 dev->mode_config.max_height = 8192;
Jesse Barnes79e53942008-11-07 14:24:08 -080015041 }
Damien Lespiau068be562014-03-28 14:17:49 +000015042
Jani Nikula2a307c22016-11-30 17:43:04 +020015043 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15044 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
Ville Syrjälädc41c152014-08-13 11:57:05 +030015045 dev->mode_config.cursor_height = 1023;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010015046 } else if (IS_GEN2(dev_priv)) {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015047 dev->mode_config.cursor_width = 64;
15048 dev->mode_config.cursor_height = 64;
Damien Lespiau068be562014-03-28 14:17:49 +000015049 } else {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015050 dev->mode_config.cursor_width = 256;
15051 dev->mode_config.cursor_height = 256;
Damien Lespiau068be562014-03-28 14:17:49 +000015052 }
15053
Matthew Auld73ebd502017-12-11 15:18:20 +000015054 dev->mode_config.fb_base = ggtt->gmadr.start;
Jesse Barnes79e53942008-11-07 14:24:08 -080015055
Zhao Yakui28c97732009-10-09 11:39:41 +080015056 DRM_DEBUG_KMS("%d display pipe%s available.\n",
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000015057 INTEL_INFO(dev_priv)->num_pipes,
15058 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
Jesse Barnes79e53942008-11-07 14:24:08 -080015059
Damien Lespiau055e3932014-08-18 13:49:10 +010015060 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020015061 ret = intel_crtc_init(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015062 if (ret) {
15063 drm_mode_config_cleanup(dev);
15064 return ret;
15065 }
Jesse Barnes79e53942008-11-07 14:24:08 -080015066 }
15067
Daniel Vettere72f9fb2013-06-05 13:34:06 +020015068 intel_shared_dpll_init(dev);
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015069 intel_update_fdi_pll_freq(dev_priv);
Jesse Barnesee7b9f92012-04-20 17:11:53 +010015070
Ville Syrjälä5be6e332017-02-20 16:04:43 +020015071 intel_update_czclk(dev_priv);
15072 intel_modeset_init_hw(dev);
15073
Ville Syrjäläb2045352016-05-13 23:41:27 +030015074 if (dev_priv->max_cdclk_freq == 0)
Ville Syrjälä4c75b942016-10-31 22:37:12 +020015075 intel_update_max_cdclk(dev_priv);
Ville Syrjäläb2045352016-05-13 23:41:27 +030015076
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015077 /* Just disable it once at startup */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015078 i915_disable_vga(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020015079 intel_setup_outputs(dev_priv);
Chris Wilson11be49e2012-11-15 11:32:20 +000015080
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015081 drm_modeset_lock_all(dev);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015082 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015083 drm_modeset_unlock_all(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015084
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015085 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015086 struct intel_initial_plane_config plane_config = {};
15087
Jesse Barnes46f297f2014-03-07 08:57:48 -080015088 if (!crtc->active)
15089 continue;
15090
Jesse Barnes46f297f2014-03-07 08:57:48 -080015091 /*
Jesse Barnes46f297f2014-03-07 08:57:48 -080015092 * Note that reserving the BIOS fb up front prevents us
15093 * from stuffing other stolen allocations like the ring
15094 * on top. This prevents some ugliness at boot time, and
15095 * can even allow for smooth boot transitions if the BIOS
15096 * fb is large enough for the active pipe configuration.
15097 */
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015098 dev_priv->display.get_initial_plane_config(crtc,
15099 &plane_config);
15100
15101 /*
15102 * If the fb is shared between multiple heads, we'll
15103 * just get the first one.
15104 */
15105 intel_find_initial_plane_obj(crtc, &plane_config);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015106 }
Matt Roperd93c0372015-12-03 11:37:41 -080015107
15108 /*
15109 * Make sure hardware watermarks really match the state we read out.
15110 * Note that we need to do this after reconstructing the BIOS fb's
15111 * since the watermark calculation done here will use pstate->fb.
15112 */
Ville Syrjälä602ae832017-03-02 19:15:02 +020015113 if (!HAS_GMCH_DISPLAY(dev_priv))
15114 sanitize_watermarks(dev);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015115
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015116 /*
15117 * Force all active planes to recompute their states. So that on
15118 * mode_setcrtc after probe, all the intel_plane_state variables
15119 * are already calculated and there is no assert_plane warnings
15120 * during bootup.
15121 */
15122 ret = intel_initial_commit(dev);
15123 if (ret)
15124 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15125
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015126 return 0;
Chris Wilson2c7111d2011-03-29 10:40:27 +010015127}
Jesse Barnesd5bb0812011-01-05 12:01:26 -080015128
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015129void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15130{
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015131 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015132 /* 640x480@60Hz, ~25175 kHz */
15133 struct dpll clock = {
15134 .m1 = 18,
15135 .m2 = 7,
15136 .p1 = 13,
15137 .p2 = 4,
15138 .n = 2,
15139 };
15140 u32 dpll, fp;
15141 int i;
15142
15143 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15144
15145 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15146 pipe_name(pipe), clock.vco, clock.dot);
15147
15148 fp = i9xx_dpll_compute_fp(&clock);
15149 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15150 DPLL_VGA_MODE_DIS |
15151 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15152 PLL_P2_DIVIDE_BY_4 |
15153 PLL_REF_INPUT_DREFCLK |
15154 DPLL_VCO_ENABLE;
15155
15156 I915_WRITE(FP0(pipe), fp);
15157 I915_WRITE(FP1(pipe), fp);
15158
15159 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15160 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15161 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15162 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15163 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15164 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15165 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15166
15167 /*
15168 * Apparently we need to have VGA mode enabled prior to changing
15169 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15170 * dividers, even though the register value does change.
15171 */
15172 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15173 I915_WRITE(DPLL(pipe), dpll);
15174
15175 /* Wait for the clocks to stabilize. */
15176 POSTING_READ(DPLL(pipe));
15177 udelay(150);
15178
15179 /* The pixel multiplier can only be updated once the
15180 * DPLL is enabled and the clocks are stable.
15181 *
15182 * So write it again.
15183 */
15184 I915_WRITE(DPLL(pipe), dpll);
15185
15186 /* We do this three times for luck */
15187 for (i = 0; i < 3 ; i++) {
15188 I915_WRITE(DPLL(pipe), dpll);
15189 POSTING_READ(DPLL(pipe));
15190 udelay(150); /* wait for warmup */
15191 }
15192
15193 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15194 POSTING_READ(PIPECONF(pipe));
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015195
15196 intel_wait_for_pipe_scanline_moving(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015197}
15198
15199void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15200{
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015201 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15202
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015203 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15204 pipe_name(pipe));
15205
Ville Syrjälä5816d9c2017-11-29 14:54:11 +020015206 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15207 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15208 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020015209 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15210 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015211
15212 I915_WRITE(PIPECONF(pipe), 0);
15213 POSTING_READ(PIPECONF(pipe));
15214
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015215 intel_wait_for_pipe_scanline_stopped(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015216
15217 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15218 POSTING_READ(DPLL(pipe));
15219}
15220
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015221static void
15222intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15223{
15224 struct intel_crtc *crtc;
Daniel Vetterfa555832012-10-10 23:14:00 +020015225
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015226 if (INTEL_GEN(dev_priv) >= 4)
15227 return;
Daniel Vetterfa555832012-10-10 23:14:00 +020015228
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015229 for_each_intel_crtc(&dev_priv->drm, crtc) {
15230 struct intel_plane *plane =
15231 to_intel_plane(crtc->base.primary);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015232 struct intel_crtc *plane_crtc;
15233 enum pipe pipe;
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015234
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015235 if (!plane->get_hw_state(plane, &pipe))
15236 continue;
15237
15238 if (pipe == crtc->pipe)
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015239 continue;
15240
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015241 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15242 plane->base.base.id, plane->base.name);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015243
15244 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15245 intel_plane_disable_noatomic(plane_crtc, plane);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015246 }
Daniel Vetterfa555832012-10-10 23:14:00 +020015247}
15248
Ville Syrjälä02e93c32015-08-26 19:39:19 +030015249static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15250{
15251 struct drm_device *dev = crtc->base.dev;
15252 struct intel_encoder *encoder;
15253
15254 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15255 return true;
15256
15257 return false;
15258}
15259
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015260static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15261{
15262 struct drm_device *dev = encoder->base.dev;
15263 struct intel_connector *connector;
15264
15265 for_each_connector_on_encoder(dev, &encoder->base, connector)
15266 return connector;
15267
15268 return NULL;
15269}
15270
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015271static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015272 enum pipe pch_transcoder)
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015273{
15274 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015275 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015276}
15277
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015278static void intel_sanitize_crtc(struct intel_crtc *crtc,
15279 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter24929352012-07-02 20:28:59 +020015280{
15281 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010015282 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015283 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15284 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter24929352012-07-02 20:28:59 +020015285
Daniel Vetter24929352012-07-02 20:28:59 +020015286 /* Clear any frame start delays used for debugging left by the BIOS */
Ville Syrjälä738a8142017-11-15 22:04:42 +020015287 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
Jani Nikula4d1de972016-03-18 17:05:42 +020015288 i915_reg_t reg = PIPECONF(cpu_transcoder);
15289
15290 I915_WRITE(reg,
15291 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15292 }
Daniel Vetter24929352012-07-02 20:28:59 +020015293
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015294 if (crtc_state->base.active) {
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015295 struct intel_plane *plane;
15296
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015297 /* Disable everything but the primary plane */
15298 for_each_intel_plane_on_crtc(dev, crtc, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015299 const struct intel_plane_state *plane_state =
15300 to_intel_plane_state(plane->base.state);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015301
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015302 if (plane_state->base.visible &&
15303 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15304 intel_plane_disable_noatomic(crtc, plane);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015305 }
Daniel Vetter96256042015-02-13 21:03:42 +010015306 }
Ville Syrjäläd3eaf882014-05-20 17:20:05 +030015307
Daniel Vetter24929352012-07-02 20:28:59 +020015308 /* Adjust the state of the output pipe according to whether we
15309 * have active connectors/encoders. */
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015310 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
Ville Syrjäläda1d0e22017-06-01 17:36:14 +030015311 intel_crtc_disable_noatomic(&crtc->base, ctx);
Daniel Vetter24929352012-07-02 20:28:59 +020015312
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015313 if (crtc_state->base.active || HAS_GMCH_DISPLAY(dev_priv)) {
Daniel Vetter4cc31482014-03-24 00:01:41 +010015314 /*
15315 * We start out with underrun reporting disabled to avoid races.
15316 * For correct bookkeeping mark this on active crtcs.
15317 *
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +020015318 * Also on gmch platforms we dont have any hardware bits to
15319 * disable the underrun reporting. Which means we need to start
15320 * out with underrun reporting disabled also on inactive pipes,
15321 * since otherwise we'll complain about the garbage we read when
15322 * e.g. coming up after runtime pm.
15323 *
Daniel Vetter4cc31482014-03-24 00:01:41 +010015324 * No protection against concurrent access is required - at
15325 * worst a fifo underrun happens which also sets this to false.
15326 */
15327 crtc->cpu_fifo_underrun_disabled = true;
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015328 /*
15329 * We track the PCH trancoder underrun reporting state
15330 * within the crtc. With crtc for pipe A housing the underrun
15331 * reporting state for PCH transcoder A, crtc for pipe B housing
15332 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15333 * and marking underrun reporting as disabled for the non-existing
15334 * PCH transcoders B and C would prevent enabling the south
15335 * error interrupt (see cpt_can_enable_serr_int()).
15336 */
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015337 if (has_pch_trancoder(dev_priv, crtc->pipe))
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015338 crtc->pch_fifo_underrun_disabled = true;
Daniel Vetter4cc31482014-03-24 00:01:41 +010015339 }
Daniel Vetter24929352012-07-02 20:28:59 +020015340}
15341
15342static void intel_sanitize_encoder(struct intel_encoder *encoder)
15343{
15344 struct intel_connector *connector;
Daniel Vetter24929352012-07-02 20:28:59 +020015345
15346 /* We need to check both for a crtc link (meaning that the
15347 * encoder is active and trying to read from a pipe) and the
15348 * pipe itself being active. */
15349 bool has_active_crtc = encoder->base.crtc &&
15350 to_intel_crtc(encoder->base.crtc)->active;
15351
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015352 connector = intel_encoder_find_connector(encoder);
15353 if (connector && !has_active_crtc) {
Daniel Vetter24929352012-07-02 20:28:59 +020015354 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15355 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015356 encoder->base.name);
Daniel Vetter24929352012-07-02 20:28:59 +020015357
15358 /* Connector is active, but has no active pipe. This is
15359 * fallout from our resume register restoring. Disable
15360 * the encoder manually again. */
15361 if (encoder->base.crtc) {
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015362 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15363
Daniel Vetter24929352012-07-02 20:28:59 +020015364 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15365 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015366 encoder->base.name);
Jani Nikulac84c6fe2018-10-16 15:41:34 +030015367 if (encoder->disable)
15368 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
Ville Syrjäläa62d1492014-06-28 02:04:01 +030015369 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015370 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
Daniel Vetter24929352012-07-02 20:28:59 +020015371 }
Egbert Eich7f1950f2014-04-25 10:56:22 +020015372 encoder->base.crtc = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015373
15374 /* Inconsistent output/port/pipe state happens presumably due to
15375 * a bug in one of the get_hw_state functions. Or someplace else
15376 * in our code, like the register restore mess on resume. Clamp
15377 * things to off as a safer default. */
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015378
15379 connector->base.dpms = DRM_MODE_DPMS_OFF;
15380 connector->base.encoder = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015381 }
Maarten Lankhorstd6cae4a2018-05-16 10:50:38 +020015382
15383 /* notify opregion of the sanitized encoder state */
15384 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
Daniel Vetter24929352012-07-02 20:28:59 +020015385}
15386
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015387void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015388{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010015389 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015390
Imre Deak04098752014-02-18 00:02:16 +020015391 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15392 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015393 i915_disable_vga(dev_priv);
Imre Deak04098752014-02-18 00:02:16 +020015394 }
15395}
15396
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015397void i915_redisable_vga(struct drm_i915_private *dev_priv)
Imre Deak04098752014-02-18 00:02:16 +020015398{
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015399 /* This function can be called both from intel_modeset_setup_hw_state or
15400 * at a very early point in our resume sequence, where the power well
15401 * structures are not yet restored. Since this function is at a very
15402 * paranoid "someone might have enabled VGA while we were not looking"
15403 * level, just check if the power well is enabled instead of trying to
15404 * follow the "don't touch the power well if we don't need it" policy
15405 * the rest of the driver uses. */
Imre Deak6392f842016-02-12 18:55:13 +020015406 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015407 return;
15408
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015409 i915_redisable_vga_power_on(dev_priv);
Imre Deak6392f842016-02-12 18:55:13 +020015410
15411 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015412}
15413
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015414/* FIXME read out full plane state for all planes */
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015415static void readout_plane_state(struct drm_i915_private *dev_priv)
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015416{
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015417 struct intel_plane *plane;
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015418 struct intel_crtc *crtc;
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015419
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015420 for_each_intel_plane(&dev_priv->drm, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015421 struct intel_plane_state *plane_state =
15422 to_intel_plane_state(plane->base.state);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015423 struct intel_crtc_state *crtc_state;
15424 enum pipe pipe = PIPE_A;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020015425 bool visible;
15426
15427 visible = plane->get_hw_state(plane, &pipe);
Maarten Lankhorstb26d3ea2015-09-23 16:11:41 +020015428
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015429 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15430 crtc_state = to_intel_crtc_state(crtc->base.state);
15431
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015432 intel_set_plane_visible(crtc_state, plane_state, visible);
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015433
15434 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15435 plane->base.base.id, plane->base.name,
15436 enableddisabled(visible), pipe_name(pipe));
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015437 }
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015438
15439 for_each_intel_crtc(&dev_priv->drm, crtc) {
15440 struct intel_crtc_state *crtc_state =
15441 to_intel_crtc_state(crtc->base.state);
15442
15443 fixup_active_planes(crtc_state);
15444 }
Ville Syrjälä98ec7732014-04-30 17:43:01 +030015445}
15446
Daniel Vetter30e984d2013-06-05 13:34:17 +020015447static void intel_modeset_readout_hw_state(struct drm_device *dev)
Daniel Vetter24929352012-07-02 20:28:59 +020015448{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015449 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015450 enum pipe pipe;
Daniel Vetter24929352012-07-02 20:28:59 +020015451 struct intel_crtc *crtc;
15452 struct intel_encoder *encoder;
15453 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015454 struct drm_connector_list_iter conn_iter;
Daniel Vetter53589012013-06-05 13:34:16 +020015455 int i;
Daniel Vetter24929352012-07-02 20:28:59 +020015456
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015457 dev_priv->active_crtcs = 0;
15458
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015459 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015460 struct intel_crtc_state *crtc_state =
15461 to_intel_crtc_state(crtc->base.state);
Daniel Vetter3b117c82013-04-17 20:15:07 +020015462
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020015463 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015464 memset(crtc_state, 0, sizeof(*crtc_state));
15465 crtc_state->base.crtc = &crtc->base;
Daniel Vetter24929352012-07-02 20:28:59 +020015466
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015467 crtc_state->base.active = crtc_state->base.enable =
15468 dev_priv->display.get_pipe_config(crtc, crtc_state);
15469
15470 crtc->base.enabled = crtc_state->base.enable;
15471 crtc->active = crtc_state->base.active;
15472
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015473 if (crtc_state->base.active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015474 dev_priv->active_crtcs |= 1 << crtc->pipe;
15475
Ville Syrjälä78108b72016-05-27 20:59:19 +030015476 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15477 crtc->base.base.id, crtc->base.name,
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015478 enableddisabled(crtc_state->base.active));
Daniel Vetter24929352012-07-02 20:28:59 +020015479 }
15480
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015481 readout_plane_state(dev_priv);
15482
Daniel Vetter53589012013-06-05 13:34:16 +020015483 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15484 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15485
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015486 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15487 &pll->state.hw_state);
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015488 pll->state.crtc_mask = 0;
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015489 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015490 struct intel_crtc_state *crtc_state =
15491 to_intel_crtc_state(crtc->base.state);
15492
15493 if (crtc_state->base.active &&
15494 crtc_state->shared_dpll == pll)
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015495 pll->state.crtc_mask |= 1 << crtc->pipe;
Daniel Vetter53589012013-06-05 13:34:16 +020015496 }
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015497 pll->active_mask = pll->state.crtc_mask;
Daniel Vetter53589012013-06-05 13:34:16 +020015498
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +020015499 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015500 pll->info->name, pll->state.crtc_mask, pll->on);
Daniel Vetter53589012013-06-05 13:34:16 +020015501 }
15502
Damien Lespiaub2784e12014-08-05 11:29:37 +010015503 for_each_intel_encoder(dev, encoder) {
Daniel Vetter24929352012-07-02 20:28:59 +020015504 pipe = 0;
15505
15506 if (encoder->get_hw_state(encoder, &pipe)) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015507 struct intel_crtc_state *crtc_state;
15508
Ville Syrjälä98187832016-10-31 22:37:10 +020015509 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015510 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015511
Jesse Barnes045ac3b2013-05-14 17:08:26 -070015512 encoder->base.crtc = &crtc->base;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015513 encoder->get_config(encoder, crtc_state);
Daniel Vetter24929352012-07-02 20:28:59 +020015514 } else {
15515 encoder->base.crtc = NULL;
15516 }
15517
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015518 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015519 encoder->base.base.id, encoder->base.name,
15520 enableddisabled(encoder->base.crtc),
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015521 pipe_name(pipe));
Daniel Vetter24929352012-07-02 20:28:59 +020015522 }
15523
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015524 drm_connector_list_iter_begin(dev, &conn_iter);
15525 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter24929352012-07-02 20:28:59 +020015526 if (connector->get_hw_state(connector)) {
15527 connector->base.dpms = DRM_MODE_DPMS_ON;
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015528
15529 encoder = connector->encoder;
15530 connector->base.encoder = &encoder->base;
15531
15532 if (encoder->base.crtc &&
15533 encoder->base.crtc->state->active) {
15534 /*
15535 * This has to be done during hardware readout
15536 * because anything calling .crtc_disable may
15537 * rely on the connector_mask being accurate.
15538 */
15539 encoder->base.crtc->state->connector_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015540 drm_connector_mask(&connector->base);
Maarten Lankhorste87a52b2016-01-28 15:04:58 +010015541 encoder->base.crtc->state->encoder_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015542 drm_encoder_mask(&encoder->base);
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015543 }
15544
Daniel Vetter24929352012-07-02 20:28:59 +020015545 } else {
15546 connector->base.dpms = DRM_MODE_DPMS_OFF;
15547 connector->base.encoder = NULL;
15548 }
15549 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015550 connector->base.base.id, connector->base.name,
15551 enableddisabled(connector->base.encoder));
Daniel Vetter24929352012-07-02 20:28:59 +020015552 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015553 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015554
15555 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015556 struct intel_crtc_state *crtc_state =
15557 to_intel_crtc_state(crtc->base.state);
Ville Syrjäläd305e062017-08-30 21:57:03 +030015558 int min_cdclk = 0;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015559
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015560 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015561 if (crtc_state->base.active) {
15562 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
Ville Syrjäläbd4cd032018-04-26 19:30:15 +030015563 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15564 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015565 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015566 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15567
15568 /*
15569 * The initial mode needs to be set in order to keep
15570 * the atomic core happy. It wants a valid mode if the
15571 * crtc's enabled, so we do the above call.
15572 *
Daniel Vetter7800fb62016-12-19 09:24:23 +010015573 * But we don't set all the derived state fully, hence
15574 * set a flag to indicate that a full recalculation is
15575 * needed on the next commit.
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015576 */
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015577 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
Ville Syrjälä9eca68322015-09-10 18:59:10 +030015578
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020015579 intel_crtc_compute_pixel_rate(crtc_state);
15580
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015581 if (dev_priv->display.modeset_calc_cdclk) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030015582 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015583 if (WARN_ON(min_cdclk < 0))
15584 min_cdclk = 0;
15585 }
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015586
Daniel Vetter5caa0fe2017-05-09 16:03:29 +020015587 drm_calc_timestamping_constants(&crtc->base,
15588 &crtc_state->base.adjusted_mode);
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020015589 update_scanline_offset(crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015590 }
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020015591
Ville Syrjäläd305e062017-08-30 21:57:03 +030015592 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030015593 dev_priv->min_voltage_level[crtc->pipe] =
15594 crtc_state->min_voltage_level;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015595
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015596 intel_pipe_config_sanity_check(dev_priv, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015597 }
Daniel Vetter30e984d2013-06-05 13:34:17 +020015598}
15599
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015600static void
15601get_encoder_power_domains(struct drm_i915_private *dev_priv)
15602{
15603 struct intel_encoder *encoder;
15604
15605 for_each_intel_encoder(&dev_priv->drm, encoder) {
15606 u64 get_domains;
15607 enum intel_display_power_domain domain;
Imre Deak52528052018-06-21 21:44:49 +030015608 struct intel_crtc_state *crtc_state;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015609
15610 if (!encoder->get_power_domains)
15611 continue;
15612
Imre Deak52528052018-06-21 21:44:49 +030015613 /*
Imre Deakb79ebe72018-07-05 15:26:54 +030015614 * MST-primary and inactive encoders don't have a crtc state
15615 * and neither of these require any power domain references.
Imre Deak52528052018-06-21 21:44:49 +030015616 */
Imre Deakb79ebe72018-07-05 15:26:54 +030015617 if (!encoder->base.crtc)
15618 continue;
Imre Deak52528052018-06-21 21:44:49 +030015619
Imre Deakb79ebe72018-07-05 15:26:54 +030015620 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
Imre Deak52528052018-06-21 21:44:49 +030015621 get_domains = encoder->get_power_domains(encoder, crtc_state);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015622 for_each_power_domain(domain, get_domains)
15623 intel_display_power_get(dev_priv, domain);
15624 }
15625}
15626
Rodrigo Vividf49ec82017-11-10 16:03:19 -080015627static void intel_early_display_was(struct drm_i915_private *dev_priv)
15628{
15629 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15630 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15631 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15632 DARBF_GATING_DIS);
15633
15634 if (IS_HASWELL(dev_priv)) {
15635 /*
15636 * WaRsPkgCStateDisplayPMReq:hsw
15637 * System hang if this isn't done before disabling all planes!
15638 */
15639 I915_WRITE(CHICKEN_PAR1_1,
15640 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15641 }
15642}
15643
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015644/* Scan out the current hw modeset state,
15645 * and sanitizes it to the current state
15646 */
15647static void
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015648intel_modeset_setup_hw_state(struct drm_device *dev,
15649 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter30e984d2013-06-05 13:34:17 +020015650{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015651 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter30e984d2013-06-05 13:34:17 +020015652 struct intel_crtc *crtc;
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015653 struct intel_crtc_state *crtc_state;
Daniel Vetter30e984d2013-06-05 13:34:17 +020015654 struct intel_encoder *encoder;
Daniel Vetter35c95372013-07-17 06:55:04 +020015655 int i;
Daniel Vetter30e984d2013-06-05 13:34:17 +020015656
Imre Deak2cd9a682018-08-16 15:37:57 +030015657 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15658
Rodrigo Vividf49ec82017-11-10 16:03:19 -080015659 intel_early_display_was(dev_priv);
Daniel Vetter30e984d2013-06-05 13:34:17 +020015660 intel_modeset_readout_hw_state(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015661
15662 /* HW state is read out, now we need to sanitize this mess. */
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015663 get_encoder_power_domains(dev_priv);
15664
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015665 /*
15666 * intel_sanitize_plane_mapping() may need to do vblank
15667 * waits, so we need vblank interrupts restored beforehand.
15668 */
15669 for_each_intel_crtc(&dev_priv->drm, crtc) {
15670 drm_crtc_vblank_reset(&crtc->base);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015671
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015672 if (crtc->base.state->active)
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015673 drm_crtc_vblank_on(&crtc->base);
Daniel Vetter24929352012-07-02 20:28:59 +020015674 }
15675
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015676 intel_sanitize_plane_mapping(dev_priv);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015677
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015678 for_each_intel_encoder(dev, encoder)
15679 intel_sanitize_encoder(encoder);
15680
15681 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015682 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015683 intel_sanitize_crtc(crtc, ctx);
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015684 intel_dump_pipe_config(crtc, crtc_state,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +020015685 "[setup_hw_state]");
Daniel Vetter24929352012-07-02 20:28:59 +020015686 }
Daniel Vetter9a935852012-07-05 22:34:27 +020015687
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020015688 intel_modeset_update_connector_atomic_state(dev);
15689
Daniel Vetter35c95372013-07-17 06:55:04 +020015690 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15691 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15692
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +010015693 if (!pll->on || pll->active_mask)
Daniel Vetter35c95372013-07-17 06:55:04 +020015694 continue;
15695
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015696 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15697 pll->info->name);
Daniel Vetter35c95372013-07-17 06:55:04 +020015698
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015699 pll->info->funcs->disable(dev_priv, pll);
Daniel Vetter35c95372013-07-17 06:55:04 +020015700 pll->on = false;
15701 }
15702
Ville Syrjälä04548cb2017-04-21 21:14:29 +030015703 if (IS_G4X(dev_priv)) {
15704 g4x_wm_get_hw_state(dev);
15705 g4x_wm_sanitize(dev_priv);
15706 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä6eb1a682015-06-24 22:00:03 +030015707 vlv_wm_get_hw_state(dev);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015708 vlv_wm_sanitize(dev_priv);
Rodrigo Vivia029fa42017-08-09 13:52:48 -070015709 } else if (INTEL_GEN(dev_priv) >= 9) {
Pradeep Bhat30789992014-11-04 17:06:45 +000015710 skl_wm_get_hw_state(dev);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015711 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjälä243e6a42013-10-14 14:55:24 +030015712 ilk_wm_get_hw_state(dev);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015713 }
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015714
15715 for_each_intel_crtc(dev, crtc) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020015716 u64 put_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015717
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015718 crtc_state = to_intel_crtc_state(crtc->base.state);
15719 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015720 if (WARN_ON(put_domains))
15721 modeset_put_power_domains(dev_priv, put_domains);
15722 }
Imre Deak2cd9a682018-08-16 15:37:57 +030015723
15724 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni010cf732016-01-19 11:35:48 -020015725
15726 intel_fbc_init_pipe_state(dev_priv);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015727}
Ville Syrjälä7d0bc1e2013-09-16 17:38:33 +030015728
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015729void intel_display_resume(struct drm_device *dev)
15730{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015731 struct drm_i915_private *dev_priv = to_i915(dev);
15732 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15733 struct drm_modeset_acquire_ctx ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015734 int ret;
Daniel Vetterf30da182013-04-11 20:22:50 +020015735
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015736 dev_priv->modeset_restore_state = NULL;
Maarten Lankhorst73974892016-08-05 23:28:27 +030015737 if (state)
15738 state->acquire_ctx = &ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015739
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015740 drm_modeset_acquire_init(&ctx, 0);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015741
Maarten Lankhorst73974892016-08-05 23:28:27 +030015742 while (1) {
15743 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15744 if (ret != -EDEADLK)
15745 break;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015746
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015747 drm_modeset_backoff(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015748 }
15749
Maarten Lankhorst73974892016-08-05 23:28:27 +030015750 if (!ret)
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010015751 ret = __intel_display_resume(dev, state, &ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +030015752
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +053015753 intel_enable_ipc(dev_priv);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015754 drm_modeset_drop_locks(&ctx);
15755 drm_modeset_acquire_fini(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015756
Chris Wilson08536952016-10-14 13:18:18 +010015757 if (ret)
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015758 DRM_ERROR("Restoring old state failed with %i\n", ret);
Chris Wilson3c5e37f2017-01-15 12:58:25 +000015759 if (state)
15760 drm_atomic_state_put(state);
Chris Wilson2c7111d2011-03-29 10:40:27 +010015761}
15762
Manasi Navare886c6b82017-10-26 14:52:00 -070015763static void intel_hpd_poll_fini(struct drm_device *dev)
15764{
15765 struct intel_connector *connector;
15766 struct drm_connector_list_iter conn_iter;
15767
Chris Wilson448aa912017-11-28 11:01:47 +000015768 /* Kill all the work that may have been queued by hpd. */
Manasi Navare886c6b82017-10-26 14:52:00 -070015769 drm_connector_list_iter_begin(dev, &conn_iter);
15770 for_each_intel_connector_iter(connector, &conn_iter) {
15771 if (connector->modeset_retry_work.func)
15772 cancel_work_sync(&connector->modeset_retry_work);
Sean Paulee5e5e72018-01-08 14:55:39 -050015773 if (connector->hdcp_shim) {
15774 cancel_delayed_work_sync(&connector->hdcp_check_work);
15775 cancel_work_sync(&connector->hdcp_prop_work);
15776 }
Manasi Navare886c6b82017-10-26 14:52:00 -070015777 }
15778 drm_connector_list_iter_end(&conn_iter);
15779}
15780
Jesse Barnes79e53942008-11-07 14:24:08 -080015781void intel_modeset_cleanup(struct drm_device *dev)
15782{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015783 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes652c3932009-08-17 13:31:43 -070015784
Chris Wilson8bcf9f72018-07-10 10:44:20 +010015785 flush_workqueue(dev_priv->modeset_wq);
15786
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015787 flush_work(&dev_priv->atomic_helper.free_work);
15788 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15789
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015790 /*
15791 * Interrupts and polling as the first thing to avoid creating havoc.
Imre Deak2eb52522014-11-19 15:30:05 +020015792 * Too much stuff here (turning of connectors, ...) would
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015793 * experience fancy races otherwise.
15794 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +020015795 intel_irq_uninstall(dev_priv);
Jesse Barneseb21b922014-06-20 11:57:33 -070015796
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015797 /*
15798 * Due to the hpd irq storm handling the hotplug work can re-arm the
15799 * poll handlers. Hence disable polling after hpd handling is shut down.
15800 */
Manasi Navare886c6b82017-10-26 14:52:00 -070015801 intel_hpd_poll_fini(dev);
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015802
Daniel Vetter4f256d82017-07-15 00:46:55 +020015803 /* poll work can call into fbdev, hence clean that up afterwards */
15804 intel_fbdev_fini(dev_priv);
15805
Jesse Barnes723bfd72010-10-07 16:01:13 -070015806 intel_unregister_dsm_handler();
15807
Paulo Zanonic937ab3e52016-01-19 11:35:46 -020015808 intel_fbc_global_disable(dev_priv);
Kristian Høgsberg69341a52009-11-11 12:19:17 -050015809
Chris Wilson1630fe72011-07-08 12:22:42 +010015810 /* flush any delayed tasks or pending work */
15811 flush_scheduled_work();
15812
Jesse Barnes79e53942008-11-07 14:24:08 -080015813 drm_mode_config_cleanup(dev);
Daniel Vetter4d7bb012012-12-18 15:24:37 +010015814
Chris Wilson1ee8da62016-05-12 12:43:23 +010015815 intel_cleanup_overlay(dev_priv);
Imre Deakae484342014-03-31 15:10:44 +030015816
Tvrtko Ursulin40196442016-12-01 14:16:42 +000015817 intel_teardown_gmbus(dev_priv);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015818
15819 destroy_workqueue(dev_priv->modeset_wq);
Jesse Barnes79e53942008-11-07 14:24:08 -080015820}
15821
Dave Airlie28d52042009-09-21 14:33:58 +100015822/*
15823 * set vga decode state - true == enable VGA decode
15824 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000015825int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
Dave Airlie28d52042009-09-21 14:33:58 +100015826{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000015827 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
Dave Airlie28d52042009-09-21 14:33:58 +100015828 u16 gmch_ctrl;
15829
Chris Wilson75fa0412014-02-07 18:37:02 -020015830 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15831 DRM_ERROR("failed to read control word\n");
15832 return -EIO;
15833 }
15834
Chris Wilsonc0cc8a52014-02-07 18:37:03 -020015835 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15836 return 0;
15837
Dave Airlie28d52042009-09-21 14:33:58 +100015838 if (state)
15839 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15840 else
15841 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
Chris Wilson75fa0412014-02-07 18:37:02 -020015842
15843 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15844 DRM_ERROR("failed to write control word\n");
15845 return -EIO;
15846 }
15847
Dave Airlie28d52042009-09-21 14:33:58 +100015848 return 0;
15849}
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015850
Chris Wilson98a2f412016-10-12 10:05:18 +010015851#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15852
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015853struct intel_display_error_state {
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030015854
15855 u32 power_well_driver;
15856
Chris Wilson63b66e52013-08-08 15:12:06 +020015857 int num_transcoders;
15858
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015859 struct intel_cursor_error_state {
15860 u32 control;
15861 u32 position;
15862 u32 base;
15863 u32 size;
Damien Lespiau52331302012-08-15 19:23:25 +010015864 } cursor[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015865
15866 struct intel_pipe_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020015867 bool power_domain_on;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015868 u32 source;
Imre Deakf301b1e12014-04-18 15:55:04 +030015869 u32 stat;
Damien Lespiau52331302012-08-15 19:23:25 +010015870 } pipe[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015871
15872 struct intel_plane_error_state {
15873 u32 control;
15874 u32 stride;
15875 u32 size;
15876 u32 pos;
15877 u32 addr;
15878 u32 surface;
15879 u32 tile_offset;
Damien Lespiau52331302012-08-15 19:23:25 +010015880 } plane[I915_MAX_PIPES];
Chris Wilson63b66e52013-08-08 15:12:06 +020015881
15882 struct intel_transcoder_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020015883 bool power_domain_on;
Chris Wilson63b66e52013-08-08 15:12:06 +020015884 enum transcoder cpu_transcoder;
15885
15886 u32 conf;
15887
15888 u32 htotal;
15889 u32 hblank;
15890 u32 hsync;
15891 u32 vtotal;
15892 u32 vblank;
15893 u32 vsync;
15894 } transcoder[4];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015895};
15896
15897struct intel_display_error_state *
Chris Wilsonc0336662016-05-06 15:40:21 +010015898intel_display_capture_error_state(struct drm_i915_private *dev_priv)
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015899{
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015900 struct intel_display_error_state *error;
Chris Wilson63b66e52013-08-08 15:12:06 +020015901 int transcoders[] = {
15902 TRANSCODER_A,
15903 TRANSCODER_B,
15904 TRANSCODER_C,
15905 TRANSCODER_EDP,
15906 };
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015907 int i;
15908
Chris Wilsonc0336662016-05-06 15:40:21 +010015909 if (INTEL_INFO(dev_priv)->num_pipes == 0)
Chris Wilson63b66e52013-08-08 15:12:06 +020015910 return NULL;
15911
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020015912 error = kzalloc(sizeof(*error), GFP_ATOMIC);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015913 if (error == NULL)
15914 return NULL;
15915
Chris Wilsonc0336662016-05-06 15:40:21 +010015916 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Imre Deak75e39682018-08-06 12:58:39 +030015917 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030015918
Damien Lespiau055e3932014-08-18 13:49:10 +010015919 for_each_pipe(dev_priv, i) {
Imre Deakddf9c532013-11-27 22:02:02 +020015920 error->pipe[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020015921 __intel_display_power_is_enabled(dev_priv,
15922 POWER_DOMAIN_PIPE(i));
Imre Deakddf9c532013-11-27 22:02:02 +020015923 if (!error->pipe[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020015924 continue;
15925
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030015926 error->cursor[i].control = I915_READ(CURCNTR(i));
15927 error->cursor[i].position = I915_READ(CURPOS(i));
15928 error->cursor[i].base = I915_READ(CURBASE(i));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015929
15930 error->plane[i].control = I915_READ(DSPCNTR(i));
15931 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010015932 if (INTEL_GEN(dev_priv) <= 3) {
Paulo Zanoni51889b32013-03-06 20:03:13 -030015933 error->plane[i].size = I915_READ(DSPSIZE(i));
Paulo Zanoni80ca3782013-03-22 14:20:57 -030015934 error->plane[i].pos = I915_READ(DSPPOS(i));
15935 }
Chris Wilsonc0336662016-05-06 15:40:21 +010015936 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Paulo Zanonica291362013-03-06 20:03:14 -030015937 error->plane[i].addr = I915_READ(DSPADDR(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010015938 if (INTEL_GEN(dev_priv) >= 4) {
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015939 error->plane[i].surface = I915_READ(DSPSURF(i));
15940 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
15941 }
15942
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015943 error->pipe[i].source = I915_READ(PIPESRC(i));
Imre Deakf301b1e12014-04-18 15:55:04 +030015944
Chris Wilsonc0336662016-05-06 15:40:21 +010015945 if (HAS_GMCH_DISPLAY(dev_priv))
Imre Deakf301b1e12014-04-18 15:55:04 +030015946 error->pipe[i].stat = I915_READ(PIPESTAT(i));
Chris Wilson63b66e52013-08-08 15:12:06 +020015947 }
15948
Jani Nikula4d1de972016-03-18 17:05:42 +020015949 /* Note: this does not include DSI transcoders. */
Chris Wilsonc0336662016-05-06 15:40:21 +010015950 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +030015951 if (HAS_DDI(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020015952 error->num_transcoders++; /* Account for eDP. */
15953
15954 for (i = 0; i < error->num_transcoders; i++) {
15955 enum transcoder cpu_transcoder = transcoders[i];
15956
Imre Deakddf9c532013-11-27 22:02:02 +020015957 error->transcoder[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020015958 __intel_display_power_is_enabled(dev_priv,
Paulo Zanoni38cc1da2013-12-20 15:09:41 -020015959 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020015960 if (!error->transcoder[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020015961 continue;
15962
Chris Wilson63b66e52013-08-08 15:12:06 +020015963 error->transcoder[i].cpu_transcoder = cpu_transcoder;
15964
15965 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
15966 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
15967 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
15968 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
15969 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
15970 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
15971 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015972 }
15973
15974 return error;
15975}
15976
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030015977#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15978
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015979void
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030015980intel_display_print_error_state(struct drm_i915_error_state_buf *m,
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015981 struct intel_display_error_state *error)
15982{
Chris Wilson5a4c6f12017-02-14 16:46:11 +000015983 struct drm_i915_private *dev_priv = m->i915;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015984 int i;
15985
Chris Wilson63b66e52013-08-08 15:12:06 +020015986 if (!error)
15987 return;
15988
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000015989 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
Tvrtko Ursulin86527442016-10-13 11:03:00 +010015990 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030015991 err_printf(m, "PWR_WELL_CTL2: %08x\n",
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030015992 error->power_well_driver);
Damien Lespiau055e3932014-08-18 13:49:10 +010015993 for_each_pipe(dev_priv, i) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030015994 err_printf(m, "Pipe [%d]:\n", i);
Imre Deakddf9c532013-11-27 22:02:02 +020015995 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020015996 onoff(error->pipe[i].power_domain_on));
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030015997 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
Imre Deakf301b1e12014-04-18 15:55:04 +030015998 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015999
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016000 err_printf(m, "Plane [%d]:\n", i);
16001 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16002 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016003 if (INTEL_GEN(dev_priv) <= 3) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016004 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16005 err_printf(m, " POS: %08x\n", error->plane[i].pos);
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016006 }
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010016007 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016008 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016009 if (INTEL_GEN(dev_priv) >= 4) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016010 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16011 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016012 }
16013
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016014 err_printf(m, "Cursor [%d]:\n", i);
16015 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16016 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16017 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016018 }
Chris Wilson63b66e52013-08-08 15:12:06 +020016019
16020 for (i = 0; i < error->num_transcoders; i++) {
Jani Nikulada205632016-03-15 21:51:10 +020016021 err_printf(m, "CPU transcoder: %s\n",
Chris Wilson63b66e52013-08-08 15:12:06 +020016022 transcoder_name(error->transcoder[i].cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016023 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016024 onoff(error->transcoder[i].power_domain_on));
Chris Wilson63b66e52013-08-08 15:12:06 +020016025 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16026 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16027 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16028 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16029 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16030 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16031 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
16032 }
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016033}
Chris Wilson98a2f412016-10-12 10:05:18 +010016034
16035#endif