blob: 60c1e54285c1e3ed009238a36e92bed0717ae1c9 [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright © 2006-2007 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 */
26
Jesse Barnesc1c7af62009-09-10 15:28:03 -070027#include <linux/module.h>
28#include <linux/input.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080029#include <linux/i2c.h>
Shaohua Li7662c8b2009-06-26 11:23:55 +080030#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Jesse Barnes9cce37f2010-08-13 15:11:26 -070032#include <linux/vgaarb.h>
Wu Fengguange0dac652011-09-05 14:25:34 +080033#include <drm/drm_edid.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080035#include "intel_drv.h"
Chris Wilson5d723d72016-08-04 16:32:35 +010036#include "intel_frontbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "i915_drv.h"
Chris Wilson57822dc2017-02-22 11:40:48 +000039#include "i915_gem_clflush.h"
Imre Deakdb18b6a2016-03-24 12:41:40 +020040#include "intel_dsi.h"
Jesse Barnese5510fa2010-07-01 16:48:37 -070041#include "i915_trace.h"
Xi Ruoyao319c1d42015-03-12 20:16:32 +080042#include <drm/drm_atomic.h>
Matt Roperc196e1d2015-01-21 16:35:48 -080043#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010044#include <drm/drm_dp_helper.h>
45#include <drm/drm_crtc_helper.h>
Matt Roper465c1202014-05-29 08:06:54 -070046#include <drm/drm_plane_helper.h>
47#include <drm/drm_rect.h>
Daniel Vetter72fdb40c2018-09-05 15:57:11 +020048#include <drm/drm_atomic_uapi.h>
Keith Packardc0f372b32011-11-16 22:24:52 -080049#include <linux/dma_remapping.h>
Alex Goinsfd8e0582015-11-25 18:43:38 -080050#include <linux/reservation.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080051
Matt Roper465c1202014-05-29 08:06:54 -070052/* Primary plane formats for gen <= 3 */
Damien Lespiau568db4f2015-05-12 16:13:18 +010053static const uint32_t i8xx_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010054 DRM_FORMAT_C8,
55 DRM_FORMAT_RGB565,
Matt Roper465c1202014-05-29 08:06:54 -070056 DRM_FORMAT_XRGB1555,
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010057 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070058};
59
60/* Primary plane formats for gen >= 4 */
Damien Lespiau568db4f2015-05-12 16:13:18 +010061static const uint32_t i965_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010062 DRM_FORMAT_C8,
63 DRM_FORMAT_RGB565,
64 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070065 DRM_FORMAT_XBGR8888,
Damien Lespiau6c0fd452015-05-19 12:29:16 +010066 DRM_FORMAT_XRGB2101010,
67 DRM_FORMAT_XBGR2101010,
68};
69
Ben Widawsky714244e2017-08-01 09:58:16 -070070static const uint64_t i9xx_format_modifiers[] = {
71 I915_FORMAT_MOD_X_TILED,
72 DRM_FORMAT_MOD_LINEAR,
73 DRM_FORMAT_MOD_INVALID
74};
75
Matt Roper3d7d6512014-06-10 08:28:13 -070076/* Cursor formats */
77static const uint32_t intel_cursor_formats[] = {
78 DRM_FORMAT_ARGB8888,
79};
80
Ben Widawsky714244e2017-08-01 09:58:16 -070081static const uint64_t cursor_format_modifiers[] = {
82 DRM_FORMAT_MOD_LINEAR,
83 DRM_FORMAT_MOD_INVALID
84};
85
Jesse Barnesf1f644d2013-06-27 00:39:25 +030086static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020087 struct intel_crtc_state *pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +030088static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020089 struct intel_crtc_state *pipe_config);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030090
Chris Wilson24dbf512017-02-15 10:59:18 +000091static int intel_framebuffer_init(struct intel_framebuffer *ifb,
92 struct drm_i915_gem_object *obj,
93 struct drm_mode_fb_cmd2 *mode_cmd);
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +020094static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
95static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
Maarten Lankhorst4c354752018-10-11 12:04:49 +020096static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
97 const struct intel_link_m_n *m_n,
98 const struct intel_link_m_n *m2_n2);
Maarten Lankhorstfdf73512018-10-04 11:45:52 +020099static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
100static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
101static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
102static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200103static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200104 const struct intel_crtc_state *pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200105static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200106 const struct intel_crtc_state *pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200107static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
108static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
Nabendu Maiti1c74eea2016-11-29 11:23:14 +0530109static void intel_crtc_init_scalers(struct intel_crtc *crtc,
110 struct intel_crtc_state *crtc_state);
Maarten Lankhorstb2562712018-10-04 11:45:53 +0200111static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
112static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
113static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +0300114static void intel_modeset_setup_hw_state(struct drm_device *dev,
115 struct drm_modeset_acquire_ctx *ctx);
Ville Syrjälä2622a082016-03-09 19:07:26 +0200116static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
Damien Lespiaue7457a92013-08-08 22:28:59 +0100117
Ma Lingd4906092009-03-18 20:13:27 +0800118struct intel_limit {
Ander Conselvan de Oliveira4c5def92016-05-04 12:11:58 +0300119 struct {
120 int min, max;
121 } dot, vco, n, m, m1, m2, p, p1;
122
123 struct {
124 int dot_limit;
125 int p2_slow, p2_fast;
126 } p2;
Ma Lingd4906092009-03-18 20:13:27 +0800127};
Jesse Barnes79e53942008-11-07 14:24:08 -0800128
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300129/* returns HPLL frequency in kHz */
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200130int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300131{
132 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
133
134 /* Obtain SKU information */
135 mutex_lock(&dev_priv->sb_lock);
136 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
137 CCK_FUSE_HPLL_FREQ_MASK;
138 mutex_unlock(&dev_priv->sb_lock);
139
140 return vco_freq[hpll_freq] * 1000;
141}
142
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200143int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
144 const char *name, u32 reg, int ref_freq)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300145{
146 u32 val;
147 int divider;
148
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300149 mutex_lock(&dev_priv->sb_lock);
150 val = vlv_cck_read(dev_priv, reg);
151 mutex_unlock(&dev_priv->sb_lock);
152
153 divider = val & CCK_FREQUENCY_VALUES;
154
155 WARN((val & CCK_FREQUENCY_STATUS) !=
156 (divider << CCK_FREQUENCY_STATUS_SHIFT),
157 "%s change in progress\n", name);
158
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200159 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
160}
161
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +0200162int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
163 const char *name, u32 reg)
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200164{
165 if (dev_priv->hpll_freq == 0)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200166 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200167
168 return vlv_get_cck_clock(dev_priv, name, reg,
169 dev_priv->hpll_freq);
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300170}
171
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300172static void intel_update_czclk(struct drm_i915_private *dev_priv)
173{
Wayne Boyer666a4532015-12-09 12:29:35 -0800174 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300175 return;
176
177 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
178 CCK_CZ_CLOCK_CONTROL);
179
180 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
181}
182
Chris Wilson021357a2010-09-07 20:54:59 +0100183static inline u32 /* units of 100MHz */
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200184intel_fdi_link_freq(struct drm_i915_private *dev_priv,
185 const struct intel_crtc_state *pipe_config)
Chris Wilson021357a2010-09-07 20:54:59 +0100186{
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200187 if (HAS_DDI(dev_priv))
188 return pipe_config->port_clock; /* SPLL */
Ville Syrjäläe3b247d2016-02-17 21:41:09 +0200189 else
Chris Wilson58ecd9d2017-11-05 13:49:05 +0000190 return dev_priv->fdi_pll_freq;
Chris Wilson021357a2010-09-07 20:54:59 +0100191}
192
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300193static const struct intel_limit intel_limits_i8xx_dac = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400194 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200195 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200196 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400197 .m = { .min = 96, .max = 140 },
198 .m1 = { .min = 18, .max = 26 },
199 .m2 = { .min = 6, .max = 16 },
200 .p = { .min = 4, .max = 128 },
201 .p1 = { .min = 2, .max = 33 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700202 .p2 = { .dot_limit = 165000,
203 .p2_slow = 4, .p2_fast = 2 },
Keith Packarde4b36692009-06-05 19:22:17 -0700204};
205
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300206static const struct intel_limit intel_limits_i8xx_dvo = {
Daniel Vetter5d536e22013-07-06 12:52:06 +0200207 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200208 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200209 .n = { .min = 2, .max = 16 },
Daniel Vetter5d536e22013-07-06 12:52:06 +0200210 .m = { .min = 96, .max = 140 },
211 .m1 = { .min = 18, .max = 26 },
212 .m2 = { .min = 6, .max = 16 },
213 .p = { .min = 4, .max = 128 },
214 .p1 = { .min = 2, .max = 33 },
215 .p2 = { .dot_limit = 165000,
216 .p2_slow = 4, .p2_fast = 4 },
217};
218
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300219static const struct intel_limit intel_limits_i8xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400220 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200221 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200222 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400223 .m = { .min = 96, .max = 140 },
224 .m1 = { .min = 18, .max = 26 },
225 .m2 = { .min = 6, .max = 16 },
226 .p = { .min = 4, .max = 128 },
227 .p1 = { .min = 1, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700228 .p2 = { .dot_limit = 165000,
229 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700230};
Eric Anholt273e27c2011-03-30 13:01:10 -0700231
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300232static const struct intel_limit intel_limits_i9xx_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400233 .dot = { .min = 20000, .max = 400000 },
234 .vco = { .min = 1400000, .max = 2800000 },
235 .n = { .min = 1, .max = 6 },
236 .m = { .min = 70, .max = 120 },
Patrik Jakobsson4f7dfb62013-02-13 22:20:22 +0100237 .m1 = { .min = 8, .max = 18 },
238 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400239 .p = { .min = 5, .max = 80 },
240 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700241 .p2 = { .dot_limit = 200000,
242 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700243};
244
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300245static const struct intel_limit intel_limits_i9xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400246 .dot = { .min = 20000, .max = 400000 },
247 .vco = { .min = 1400000, .max = 2800000 },
248 .n = { .min = 1, .max = 6 },
249 .m = { .min = 70, .max = 120 },
Patrik Jakobsson53a7d2d2013-02-13 22:20:21 +0100250 .m1 = { .min = 8, .max = 18 },
251 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400252 .p = { .min = 7, .max = 98 },
253 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700254 .p2 = { .dot_limit = 112000,
255 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700256};
257
Eric Anholt273e27c2011-03-30 13:01:10 -0700258
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300259static const struct intel_limit intel_limits_g4x_sdvo = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700260 .dot = { .min = 25000, .max = 270000 },
261 .vco = { .min = 1750000, .max = 3500000},
262 .n = { .min = 1, .max = 4 },
263 .m = { .min = 104, .max = 138 },
264 .m1 = { .min = 17, .max = 23 },
265 .m2 = { .min = 5, .max = 11 },
266 .p = { .min = 10, .max = 30 },
267 .p1 = { .min = 1, .max = 3},
268 .p2 = { .dot_limit = 270000,
269 .p2_slow = 10,
270 .p2_fast = 10
Ma Ling044c7c42009-03-18 20:13:23 +0800271 },
Keith Packarde4b36692009-06-05 19:22:17 -0700272};
273
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300274static const struct intel_limit intel_limits_g4x_hdmi = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700275 .dot = { .min = 22000, .max = 400000 },
276 .vco = { .min = 1750000, .max = 3500000},
277 .n = { .min = 1, .max = 4 },
278 .m = { .min = 104, .max = 138 },
279 .m1 = { .min = 16, .max = 23 },
280 .m2 = { .min = 5, .max = 11 },
281 .p = { .min = 5, .max = 80 },
282 .p1 = { .min = 1, .max = 8},
283 .p2 = { .dot_limit = 165000,
284 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700285};
286
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300287static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700288 .dot = { .min = 20000, .max = 115000 },
289 .vco = { .min = 1750000, .max = 3500000 },
290 .n = { .min = 1, .max = 3 },
291 .m = { .min = 104, .max = 138 },
292 .m1 = { .min = 17, .max = 23 },
293 .m2 = { .min = 5, .max = 11 },
294 .p = { .min = 28, .max = 112 },
295 .p1 = { .min = 2, .max = 8 },
296 .p2 = { .dot_limit = 0,
297 .p2_slow = 14, .p2_fast = 14
Ma Ling044c7c42009-03-18 20:13:23 +0800298 },
Keith Packarde4b36692009-06-05 19:22:17 -0700299};
300
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300301static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700302 .dot = { .min = 80000, .max = 224000 },
303 .vco = { .min = 1750000, .max = 3500000 },
304 .n = { .min = 1, .max = 3 },
305 .m = { .min = 104, .max = 138 },
306 .m1 = { .min = 17, .max = 23 },
307 .m2 = { .min = 5, .max = 11 },
308 .p = { .min = 14, .max = 42 },
309 .p1 = { .min = 2, .max = 6 },
310 .p2 = { .dot_limit = 0,
311 .p2_slow = 7, .p2_fast = 7
Ma Ling044c7c42009-03-18 20:13:23 +0800312 },
Keith Packarde4b36692009-06-05 19:22:17 -0700313};
314
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300315static const struct intel_limit intel_limits_pineview_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400316 .dot = { .min = 20000, .max = 400000},
317 .vco = { .min = 1700000, .max = 3500000 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700318 /* Pineview's Ncounter is a ring counter */
Akshay Joshi0206e352011-08-16 15:34:10 -0400319 .n = { .min = 3, .max = 6 },
320 .m = { .min = 2, .max = 256 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700321 /* Pineview only has one combined m divider, which we treat as m2. */
Akshay Joshi0206e352011-08-16 15:34:10 -0400322 .m1 = { .min = 0, .max = 0 },
323 .m2 = { .min = 0, .max = 254 },
324 .p = { .min = 5, .max = 80 },
325 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700326 .p2 = { .dot_limit = 200000,
327 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700328};
329
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300330static const struct intel_limit intel_limits_pineview_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400331 .dot = { .min = 20000, .max = 400000 },
332 .vco = { .min = 1700000, .max = 3500000 },
333 .n = { .min = 3, .max = 6 },
334 .m = { .min = 2, .max = 256 },
335 .m1 = { .min = 0, .max = 0 },
336 .m2 = { .min = 0, .max = 254 },
337 .p = { .min = 7, .max = 112 },
338 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700339 .p2 = { .dot_limit = 112000,
340 .p2_slow = 14, .p2_fast = 14 },
Keith Packarde4b36692009-06-05 19:22:17 -0700341};
342
Eric Anholt273e27c2011-03-30 13:01:10 -0700343/* Ironlake / Sandybridge
344 *
345 * We calculate clock using (register_value + 2) for N/M1/M2, so here
346 * the range value for them is (actual_value - 2).
347 */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300348static const struct intel_limit intel_limits_ironlake_dac = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700349 .dot = { .min = 25000, .max = 350000 },
350 .vco = { .min = 1760000, .max = 3510000 },
351 .n = { .min = 1, .max = 5 },
352 .m = { .min = 79, .max = 127 },
353 .m1 = { .min = 12, .max = 22 },
354 .m2 = { .min = 5, .max = 9 },
355 .p = { .min = 5, .max = 80 },
356 .p1 = { .min = 1, .max = 8 },
357 .p2 = { .dot_limit = 225000,
358 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700359};
360
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300361static const struct intel_limit intel_limits_ironlake_single_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700362 .dot = { .min = 25000, .max = 350000 },
363 .vco = { .min = 1760000, .max = 3510000 },
364 .n = { .min = 1, .max = 3 },
365 .m = { .min = 79, .max = 118 },
366 .m1 = { .min = 12, .max = 22 },
367 .m2 = { .min = 5, .max = 9 },
368 .p = { .min = 28, .max = 112 },
369 .p1 = { .min = 2, .max = 8 },
370 .p2 = { .dot_limit = 225000,
371 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800372};
373
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300374static const struct intel_limit intel_limits_ironlake_dual_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700375 .dot = { .min = 25000, .max = 350000 },
376 .vco = { .min = 1760000, .max = 3510000 },
377 .n = { .min = 1, .max = 3 },
378 .m = { .min = 79, .max = 127 },
379 .m1 = { .min = 12, .max = 22 },
380 .m2 = { .min = 5, .max = 9 },
381 .p = { .min = 14, .max = 56 },
382 .p1 = { .min = 2, .max = 8 },
383 .p2 = { .dot_limit = 225000,
384 .p2_slow = 7, .p2_fast = 7 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800385};
386
Eric Anholt273e27c2011-03-30 13:01:10 -0700387/* LVDS 100mhz refclk limits. */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300388static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700389 .dot = { .min = 25000, .max = 350000 },
390 .vco = { .min = 1760000, .max = 3510000 },
391 .n = { .min = 1, .max = 2 },
392 .m = { .min = 79, .max = 126 },
393 .m1 = { .min = 12, .max = 22 },
394 .m2 = { .min = 5, .max = 9 },
395 .p = { .min = 28, .max = 112 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400396 .p1 = { .min = 2, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700397 .p2 = { .dot_limit = 225000,
398 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800399};
400
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300401static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700402 .dot = { .min = 25000, .max = 350000 },
403 .vco = { .min = 1760000, .max = 3510000 },
404 .n = { .min = 1, .max = 3 },
405 .m = { .min = 79, .max = 126 },
406 .m1 = { .min = 12, .max = 22 },
407 .m2 = { .min = 5, .max = 9 },
408 .p = { .min = 14, .max = 42 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400409 .p1 = { .min = 2, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700410 .p2 = { .dot_limit = 225000,
411 .p2_slow = 7, .p2_fast = 7 },
Zhao Yakui45476682009-12-31 16:06:04 +0800412};
413
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300414static const struct intel_limit intel_limits_vlv = {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300415 /*
416 * These are the data rate limits (measured in fast clocks)
417 * since those are the strictest limits we have. The fast
418 * clock and actual rate limits are more relaxed, so checking
419 * them would make no difference.
420 */
421 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
Daniel Vetter75e53982013-04-18 21:10:43 +0200422 .vco = { .min = 4000000, .max = 6000000 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700423 .n = { .min = 1, .max = 7 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700424 .m1 = { .min = 2, .max = 3 },
425 .m2 = { .min = 11, .max = 156 },
Ville Syrjäläb99ab662013-09-24 21:26:26 +0300426 .p1 = { .min = 2, .max = 3 },
Ville Syrjälä5fdc9c492013-09-24 21:26:29 +0300427 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700428};
429
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300430static const struct intel_limit intel_limits_chv = {
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300431 /*
432 * These are the data rate limits (measured in fast clocks)
433 * since those are the strictest limits we have. The fast
434 * clock and actual rate limits are more relaxed, so checking
435 * them would make no difference.
436 */
437 .dot = { .min = 25000 * 5, .max = 540000 * 5},
Ville Syrjälä17fe1022015-02-26 21:01:52 +0200438 .vco = { .min = 4800000, .max = 6480000 },
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300439 .n = { .min = 1, .max = 1 },
440 .m1 = { .min = 2, .max = 2 },
441 .m2 = { .min = 24 << 22, .max = 175 << 22 },
442 .p1 = { .min = 2, .max = 4 },
443 .p2 = { .p2_slow = 1, .p2_fast = 14 },
444};
445
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300446static const struct intel_limit intel_limits_bxt = {
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200447 /* FIXME: find real dot limits */
448 .dot = { .min = 0, .max = INT_MAX },
Vandana Kannane6292552015-07-01 17:02:57 +0530449 .vco = { .min = 4800000, .max = 6700000 },
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200450 .n = { .min = 1, .max = 1 },
451 .m1 = { .min = 2, .max = 2 },
452 /* FIXME: find real m2 limits */
453 .m2 = { .min = 2 << 22, .max = 255 << 22 },
454 .p1 = { .min = 2, .max = 4 },
455 .p2 = { .p2_slow = 1, .p2_fast = 20 },
456};
457
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530458static void
459skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
460{
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530461 if (enable)
462 I915_WRITE(CLKGATE_DIS_PSL(pipe),
463 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
464 else
465 I915_WRITE(CLKGATE_DIS_PSL(pipe),
466 I915_READ(CLKGATE_DIS_PSL(pipe)) &
467 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
468}
469
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200470static bool
Maarten Lankhorst24f28452017-11-22 19:39:01 +0100471needs_modeset(const struct drm_crtc_state *state)
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200472{
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200473 return drm_atomic_crtc_needs_modeset(state);
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200474}
475
Imre Deakdccbea32015-06-22 23:35:51 +0300476/*
477 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
478 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
479 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
480 * The helpers' return value is the rate of the clock that is fed to the
481 * display engine's pipe which can be the above fast dot clock rate or a
482 * divided-down version of it.
483 */
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500484/* m1 is reserved as 0 in Pineview, n is a ring counter */
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300485static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800486{
Shaohua Li21778322009-02-23 15:19:16 +0800487 clock->m = clock->m2 + 2;
488 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200489 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300490 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300491 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
492 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300493
494 return clock->dot;
Shaohua Li21778322009-02-23 15:19:16 +0800495}
496
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200497static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
498{
499 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
500}
501
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300502static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
Shaohua Li21778322009-02-23 15:19:16 +0800503{
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200504 clock->m = i9xx_dpll_compute_m(clock);
Jesse Barnes79e53942008-11-07 14:24:08 -0800505 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200506 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300507 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300508 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
509 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300510
511 return clock->dot;
Jesse Barnes79e53942008-11-07 14:24:08 -0800512}
513
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300514static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
Imre Deak589eca62015-06-22 23:35:50 +0300515{
516 clock->m = clock->m1 * clock->m2;
517 clock->p = clock->p1 * clock->p2;
518 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300519 return 0;
Imre Deak589eca62015-06-22 23:35:50 +0300520 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
521 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300522
523 return clock->dot / 5;
Imre Deak589eca62015-06-22 23:35:50 +0300524}
525
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300526int chv_calc_dpll_params(int refclk, struct dpll *clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300527{
528 clock->m = clock->m1 * clock->m2;
529 clock->p = clock->p1 * clock->p2;
530 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300531 return 0;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300532 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
533 clock->n << 22);
534 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300535
536 return clock->dot / 5;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300537}
538
Jesse Barnes7c04d1d2009-02-23 15:36:40 -0800539#define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
Chris Wilsonc38c1452018-02-14 13:49:22 +0000540
541/*
Jesse Barnes79e53942008-11-07 14:24:08 -0800542 * Returns whether the given set of divisors are valid for a given refclk with
543 * the given connectors.
544 */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100545static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300546 const struct intel_limit *limit,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300547 const struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800548{
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300549 if (clock->n < limit->n.min || limit->n.max < clock->n)
550 INTELPllInvalid("n out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800551 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400552 INTELPllInvalid("p1 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800553 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
Akshay Joshi0206e352011-08-16 15:34:10 -0400554 INTELPllInvalid("m2 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800555 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400556 INTELPllInvalid("m1 out of range\n");
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300557
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100558 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200559 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300560 if (clock->m1 <= clock->m2)
561 INTELPllInvalid("m1 <= m2\n");
562
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100563 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200564 !IS_GEN9_LP(dev_priv)) {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300565 if (clock->p < limit->p.min || limit->p.max < clock->p)
566 INTELPllInvalid("p out of range\n");
567 if (clock->m < limit->m.min || limit->m.max < clock->m)
568 INTELPllInvalid("m out of range\n");
569 }
570
Jesse Barnes79e53942008-11-07 14:24:08 -0800571 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
Akshay Joshi0206e352011-08-16 15:34:10 -0400572 INTELPllInvalid("vco out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800573 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
574 * connector, etc., rather than just a single range.
575 */
576 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
Akshay Joshi0206e352011-08-16 15:34:10 -0400577 INTELPllInvalid("dot out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800578
579 return true;
580}
581
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300582static int
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300583i9xx_select_p2_div(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300584 const struct intel_crtc_state *crtc_state,
585 int target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800586{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300587 struct drm_device *dev = crtc_state->base.crtc->dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800588
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +0300589 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800590 /*
Daniel Vettera210b022012-11-26 17:22:08 +0100591 * For LVDS just rely on its current settings for dual-channel.
592 * We haven't figured out how to reliably set up different
593 * single/dual channel state, if we even can.
Jesse Barnes79e53942008-11-07 14:24:08 -0800594 */
Daniel Vetter1974cad2012-11-26 17:22:09 +0100595 if (intel_is_dual_link_lvds(dev))
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300596 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800597 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300598 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800599 } else {
600 if (target < limit->p2.dot_limit)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300601 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800602 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300603 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800604 }
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300605}
606
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200607/*
608 * Returns a set of divisors for the desired target clock with the given
609 * refclk, or FALSE. The returned values represent the clock equation:
610 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
611 *
612 * Target and reference clocks are specified in kHz.
613 *
614 * If match_clock is provided, then best_clock P divider must match the P
615 * divider from @match_clock used for LVDS downclocking.
616 */
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300617static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300618i9xx_find_best_dpll(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300619 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300620 int target, int refclk, struct dpll *match_clock,
621 struct dpll *best_clock)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300622{
623 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300624 struct dpll clock;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300625 int err = target;
Jesse Barnes79e53942008-11-07 14:24:08 -0800626
Akshay Joshi0206e352011-08-16 15:34:10 -0400627 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnes79e53942008-11-07 14:24:08 -0800628
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300629 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
630
Zhao Yakui42158662009-11-20 11:24:18 +0800631 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
632 clock.m1++) {
633 for (clock.m2 = limit->m2.min;
634 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterc0efc382013-06-03 20:56:24 +0200635 if (clock.m2 >= clock.m1)
Zhao Yakui42158662009-11-20 11:24:18 +0800636 break;
637 for (clock.n = limit->n.min;
638 clock.n <= limit->n.max; clock.n++) {
639 for (clock.p1 = limit->p1.min;
640 clock.p1 <= limit->p1.max; clock.p1++) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800641 int this_err;
642
Imre Deakdccbea32015-06-22 23:35:51 +0300643 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100644 if (!intel_PLL_is_valid(to_i915(dev),
645 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000646 &clock))
Jesse Barnes79e53942008-11-07 14:24:08 -0800647 continue;
Sean Paulcec2f352012-01-10 15:09:36 -0800648 if (match_clock &&
649 clock.p != match_clock->p)
650 continue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800651
652 this_err = abs(clock.dot - target);
653 if (this_err < err) {
654 *best_clock = clock;
655 err = this_err;
656 }
657 }
658 }
659 }
660 }
661
662 return (err != target);
663}
664
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200665/*
666 * Returns a set of divisors for the desired target clock with the given
667 * refclk, or FALSE. The returned values represent the clock equation:
668 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
669 *
670 * Target and reference clocks are specified in kHz.
671 *
672 * If match_clock is provided, then best_clock P divider must match the P
673 * divider from @match_clock used for LVDS downclocking.
674 */
Ma Lingd4906092009-03-18 20:13:27 +0800675static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300676pnv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200677 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300678 int target, int refclk, struct dpll *match_clock,
679 struct dpll *best_clock)
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200680{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300681 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300682 struct dpll clock;
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200683 int err = target;
684
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200685 memset(best_clock, 0, sizeof(*best_clock));
686
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300687 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
688
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200689 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
690 clock.m1++) {
691 for (clock.m2 = limit->m2.min;
692 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200693 for (clock.n = limit->n.min;
694 clock.n <= limit->n.max; clock.n++) {
695 for (clock.p1 = limit->p1.min;
696 clock.p1 <= limit->p1.max; clock.p1++) {
697 int this_err;
698
Imre Deakdccbea32015-06-22 23:35:51 +0300699 pnv_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100700 if (!intel_PLL_is_valid(to_i915(dev),
701 limit,
Jesse Barnes79e53942008-11-07 14:24:08 -0800702 &clock))
703 continue;
704 if (match_clock &&
705 clock.p != match_clock->p)
706 continue;
707
708 this_err = abs(clock.dot - target);
709 if (this_err < err) {
710 *best_clock = clock;
711 err = this_err;
712 }
713 }
714 }
715 }
716 }
717
718 return (err != target);
719}
720
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200721/*
722 * Returns a set of divisors for the desired target clock with the given
723 * refclk, or FALSE. The returned values represent the clock equation:
724 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200725 *
726 * Target and reference clocks are specified in kHz.
727 *
728 * If match_clock is provided, then best_clock P divider must match the P
729 * divider from @match_clock used for LVDS downclocking.
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200730 */
Ma Lingd4906092009-03-18 20:13:27 +0800731static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300732g4x_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200733 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300734 int target, int refclk, struct dpll *match_clock,
735 struct dpll *best_clock)
Ma Lingd4906092009-03-18 20:13:27 +0800736{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300737 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300738 struct dpll clock;
Ma Lingd4906092009-03-18 20:13:27 +0800739 int max_n;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300740 bool found = false;
Adam Jackson6ba770d2010-07-02 16:43:30 -0400741 /* approximately equals target * 0.00585 */
742 int err_most = (target >> 8) + (target >> 9);
Ma Lingd4906092009-03-18 20:13:27 +0800743
744 memset(best_clock, 0, sizeof(*best_clock));
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300745
746 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
747
Ma Lingd4906092009-03-18 20:13:27 +0800748 max_n = limit->n.max;
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200749 /* based on hardware requirement, prefer smaller n to precision */
Ma Lingd4906092009-03-18 20:13:27 +0800750 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200751 /* based on hardware requirement, prefere larger m1,m2 */
Ma Lingd4906092009-03-18 20:13:27 +0800752 for (clock.m1 = limit->m1.max;
753 clock.m1 >= limit->m1.min; clock.m1--) {
754 for (clock.m2 = limit->m2.max;
755 clock.m2 >= limit->m2.min; clock.m2--) {
756 for (clock.p1 = limit->p1.max;
757 clock.p1 >= limit->p1.min; clock.p1--) {
758 int this_err;
759
Imre Deakdccbea32015-06-22 23:35:51 +0300760 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100761 if (!intel_PLL_is_valid(to_i915(dev),
762 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000763 &clock))
Ma Lingd4906092009-03-18 20:13:27 +0800764 continue;
Chris Wilson1b894b52010-12-14 20:04:54 +0000765
766 this_err = abs(clock.dot - target);
Ma Lingd4906092009-03-18 20:13:27 +0800767 if (this_err < err_most) {
768 *best_clock = clock;
769 err_most = this_err;
770 max_n = clock.n;
771 found = true;
772 }
773 }
774 }
775 }
776 }
Zhenyu Wang2c072452009-06-05 15:38:42 +0800777 return found;
778}
Ma Lingd4906092009-03-18 20:13:27 +0800779
Imre Deakd5dd62b2015-03-17 11:40:03 +0200780/*
781 * Check if the calculated PLL configuration is more optimal compared to the
782 * best configuration and error found so far. Return the calculated error.
783 */
784static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300785 const struct dpll *calculated_clock,
786 const struct dpll *best_clock,
Imre Deakd5dd62b2015-03-17 11:40:03 +0200787 unsigned int best_error_ppm,
788 unsigned int *error_ppm)
789{
Imre Deak9ca3ba02015-03-17 11:40:05 +0200790 /*
791 * For CHV ignore the error and consider only the P value.
792 * Prefer a bigger P value based on HW requirements.
793 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100794 if (IS_CHERRYVIEW(to_i915(dev))) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200795 *error_ppm = 0;
796
797 return calculated_clock->p > best_clock->p;
798 }
799
Imre Deak24be4e42015-03-17 11:40:04 +0200800 if (WARN_ON_ONCE(!target_freq))
801 return false;
802
Imre Deakd5dd62b2015-03-17 11:40:03 +0200803 *error_ppm = div_u64(1000000ULL *
804 abs(target_freq - calculated_clock->dot),
805 target_freq);
806 /*
807 * Prefer a better P value over a better (smaller) error if the error
808 * is small. Ensure this preference for future configurations too by
809 * setting the error to 0.
810 */
811 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
812 *error_ppm = 0;
813
814 return true;
815 }
816
817 return *error_ppm + 10 < best_error_ppm;
818}
819
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200820/*
821 * Returns a set of divisors for the desired target clock with the given
822 * refclk, or FALSE. The returned values represent the clock equation:
823 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
824 */
Zhenyu Wang2c072452009-06-05 15:38:42 +0800825static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300826vlv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200827 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300828 int target, int refclk, struct dpll *match_clock,
829 struct dpll *best_clock)
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700830{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200831 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300832 struct drm_device *dev = crtc->base.dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300833 struct dpll clock;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300834 unsigned int bestppm = 1000000;
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300835 /* min update 19.2 MHz */
836 int max_n = min(limit->n.max, refclk / 19200);
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300837 bool found = false;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700838
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300839 target *= 5; /* fast clock */
840
841 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700842
843 /* based on hardware requirement, prefer smaller n to precision */
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300844 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Ville Syrjälä811bbf02013-09-24 21:26:25 +0300845 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
Ville Syrjälä889059d2013-09-24 21:26:27 +0300846 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
Ville Syrjäläc1a9ae42013-09-24 21:26:23 +0300847 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300848 clock.p = clock.p1 * clock.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700849 /* based on hardware requirement, prefer bigger m1,m2 values */
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300850 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
Imre Deakd5dd62b2015-03-17 11:40:03 +0200851 unsigned int ppm;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300852
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300853 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
854 refclk * clock.m1);
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300855
Imre Deakdccbea32015-06-22 23:35:51 +0300856 vlv_calc_dpll_params(refclk, &clock);
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300857
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100858 if (!intel_PLL_is_valid(to_i915(dev),
859 limit,
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300860 &clock))
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300861 continue;
862
Imre Deakd5dd62b2015-03-17 11:40:03 +0200863 if (!vlv_PLL_is_optimal(dev, target,
864 &clock,
865 best_clock,
866 bestppm, &ppm))
867 continue;
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300868
Imre Deakd5dd62b2015-03-17 11:40:03 +0200869 *best_clock = clock;
870 bestppm = ppm;
871 found = true;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700872 }
873 }
874 }
875 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700876
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300877 return found;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700878}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700879
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200880/*
881 * Returns a set of divisors for the desired target clock with the given
882 * refclk, or FALSE. The returned values represent the clock equation:
883 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
884 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300885static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300886chv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200887 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300888 int target, int refclk, struct dpll *match_clock,
889 struct dpll *best_clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300890{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200891 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300892 struct drm_device *dev = crtc->base.dev;
Imre Deak9ca3ba02015-03-17 11:40:05 +0200893 unsigned int best_error_ppm;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300894 struct dpll clock;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300895 uint64_t m2;
896 int found = false;
897
898 memset(best_clock, 0, sizeof(*best_clock));
Imre Deak9ca3ba02015-03-17 11:40:05 +0200899 best_error_ppm = 1000000;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300900
901 /*
902 * Based on hardware doc, the n always set to 1, and m1 always
903 * set to 2. If requires to support 200Mhz refclk, we need to
904 * revisit this because n may not 1 anymore.
905 */
906 clock.n = 1, clock.m1 = 2;
907 target *= 5; /* fast clock */
908
909 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
910 for (clock.p2 = limit->p2.p2_fast;
911 clock.p2 >= limit->p2.p2_slow;
912 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200913 unsigned int error_ppm;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300914
915 clock.p = clock.p1 * clock.p2;
916
917 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
918 clock.n) << 22, refclk * clock.m1);
919
920 if (m2 > INT_MAX/clock.m1)
921 continue;
922
923 clock.m2 = m2;
924
Imre Deakdccbea32015-06-22 23:35:51 +0300925 chv_calc_dpll_params(refclk, &clock);
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300926
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100927 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300928 continue;
929
Imre Deak9ca3ba02015-03-17 11:40:05 +0200930 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
931 best_error_ppm, &error_ppm))
932 continue;
933
934 *best_clock = clock;
935 best_error_ppm = error_ppm;
936 found = true;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300937 }
938 }
939
940 return found;
941}
942
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200943bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300944 struct dpll *best_clock)
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200945{
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200946 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300947 const struct intel_limit *limit = &intel_limits_bxt;
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200948
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200949 return chv_find_best_dpll(limit, crtc_state,
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200950 target_clock, refclk, NULL, best_clock);
951}
952
Ville Syrjälä525b9312016-10-31 22:37:02 +0200953bool intel_crtc_active(struct intel_crtc *crtc)
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300954{
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300955 /* Be paranoid as we can arrive here with only partial
956 * state retrieved from the hardware during setup.
957 *
Damien Lespiau241bfc32013-09-25 16:45:37 +0100958 * We can ditch the adjusted_mode.crtc_clock check as soon
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300959 * as Haswell has gained clock readout/fastboot support.
960 *
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +0300961 * We can ditch the crtc->primary->state->fb check as soon as we can
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300962 * properly reconstruct framebuffers.
Matt Roperc3d1f432015-03-09 10:19:23 -0700963 *
964 * FIXME: The intel_crtc->active here should be switched to
965 * crtc->state->active once we have proper CRTC states wired up
966 * for atomic.
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300967 */
Ville Syrjälä525b9312016-10-31 22:37:02 +0200968 return crtc->active && crtc->base.primary->state->fb &&
969 crtc->config->base.adjusted_mode.crtc_clock;
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300970}
971
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200972enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
973 enum pipe pipe)
974{
Ville Syrjälä98187832016-10-31 22:37:10 +0200975 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200976
Ville Syrjäläe2af48c2016-10-31 22:37:05 +0200977 return crtc->config->cpu_transcoder;
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200978}
979
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200980static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
981 enum pipe pipe)
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300982{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200983 i915_reg_t reg = PIPEDSL(pipe);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300984 u32 line1, line2;
985 u32 line_mask;
986
Tvrtko Ursulin5db94012016-10-13 11:03:10 +0100987 if (IS_GEN2(dev_priv))
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300988 line_mask = DSL_LINEMASK_GEN2;
989 else
990 line_mask = DSL_LINEMASK_GEN3;
991
992 line1 = I915_READ(reg) & line_mask;
Daniel Vetter6adfb1e2015-07-07 09:10:40 +0200993 msleep(5);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300994 line2 = I915_READ(reg) & line_mask;
995
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200996 return line1 != line2;
997}
998
999static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1000{
1001 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1002 enum pipe pipe = crtc->pipe;
1003
1004 /* Wait for the display line to settle/start moving */
1005 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1006 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1007 pipe_name(pipe), onoff(state));
1008}
1009
1010static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1011{
1012 wait_for_pipe_scanline_moving(crtc, false);
1013}
1014
1015static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1016{
1017 wait_for_pipe_scanline_moving(crtc, true);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001018}
1019
Ville Syrjälä4972f702017-11-29 17:37:32 +02001020static void
1021intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001022{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001023 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001024 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001025
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001026 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001027 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001028 i915_reg_t reg = PIPECONF(cpu_transcoder);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001029
Keith Packardab7ad7f2010-10-03 00:33:06 -07001030 /* Wait for the Pipe State to go off */
Chris Wilsonb8511f52016-06-30 15:32:53 +01001031 if (intel_wait_for_register(dev_priv,
1032 reg, I965_PIPECONF_ACTIVE, 0,
1033 100))
Daniel Vetter284637d2012-07-09 09:51:57 +02001034 WARN(1, "pipe_off wait timed out\n");
Keith Packardab7ad7f2010-10-03 00:33:06 -07001035 } else {
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001036 intel_wait_for_pipe_scanline_stopped(crtc);
Keith Packardab7ad7f2010-10-03 00:33:06 -07001037 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001038}
1039
Jesse Barnesb24e7172011-01-04 15:09:30 -08001040/* Only for pre-ILK configs */
Daniel Vetter55607e82013-06-16 21:42:39 +02001041void assert_pll(struct drm_i915_private *dev_priv,
1042 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001043{
Jesse Barnesb24e7172011-01-04 15:09:30 -08001044 u32 val;
1045 bool cur_state;
1046
Ville Syrjälä649636e2015-09-22 19:50:01 +03001047 val = I915_READ(DPLL(pipe));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001048 cur_state = !!(val & DPLL_VCO_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001049 I915_STATE_WARN(cur_state != state,
Jesse Barnesb24e7172011-01-04 15:09:30 -08001050 "PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001051 onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001052}
Jesse Barnesb24e7172011-01-04 15:09:30 -08001053
Jani Nikula23538ef2013-08-27 15:12:22 +03001054/* XXX: the dsi pll is shared between MIPI DSI ports */
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +00001055void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
Jani Nikula23538ef2013-08-27 15:12:22 +03001056{
1057 u32 val;
1058 bool cur_state;
1059
Ville Syrjäläa5805162015-05-26 20:42:30 +03001060 mutex_lock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001061 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001062 mutex_unlock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001063
1064 cur_state = val & DSI_PLL_VCO_EN;
Rob Clarke2c719b2014-12-15 13:56:32 -05001065 I915_STATE_WARN(cur_state != state,
Jani Nikula23538ef2013-08-27 15:12:22 +03001066 "DSI PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001067 onoff(state), onoff(cur_state));
Jani Nikula23538ef2013-08-27 15:12:22 +03001068}
Jani Nikula23538ef2013-08-27 15:12:22 +03001069
Jesse Barnes040484a2011-01-03 12:14:26 -08001070static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1071 enum pipe pipe, bool state)
1072{
Jesse Barnes040484a2011-01-03 12:14:26 -08001073 bool cur_state;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001074 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1075 pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001076
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001077 if (HAS_DDI(dev_priv)) {
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001078 /* DDI does not have a specific FDI_TX register */
Ville Syrjälä649636e2015-09-22 19:50:01 +03001079 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
Paulo Zanoniad80a812012-10-24 16:06:19 -02001080 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001081 } else {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001082 u32 val = I915_READ(FDI_TX_CTL(pipe));
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001083 cur_state = !!(val & FDI_TX_ENABLE);
1084 }
Rob Clarke2c719b2014-12-15 13:56:32 -05001085 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001086 "FDI TX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001087 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001088}
1089#define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1090#define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1091
1092static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1093 enum pipe pipe, bool state)
1094{
Jesse Barnes040484a2011-01-03 12:14:26 -08001095 u32 val;
1096 bool cur_state;
1097
Ville Syrjälä649636e2015-09-22 19:50:01 +03001098 val = I915_READ(FDI_RX_CTL(pipe));
Paulo Zanonid63fa0d2012-11-20 13:27:35 -02001099 cur_state = !!(val & FDI_RX_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001100 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001101 "FDI RX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001102 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001103}
1104#define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1105#define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1106
1107static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1108 enum pipe pipe)
1109{
Jesse Barnes040484a2011-01-03 12:14:26 -08001110 u32 val;
1111
1112 /* ILK FDI PLL is always enabled */
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01001113 if (IS_GEN5(dev_priv))
Jesse Barnes040484a2011-01-03 12:14:26 -08001114 return;
1115
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001116 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001117 if (HAS_DDI(dev_priv))
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001118 return;
1119
Ville Syrjälä649636e2015-09-22 19:50:01 +03001120 val = I915_READ(FDI_TX_CTL(pipe));
Rob Clarke2c719b2014-12-15 13:56:32 -05001121 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
Jesse Barnes040484a2011-01-03 12:14:26 -08001122}
1123
Daniel Vetter55607e82013-06-16 21:42:39 +02001124void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1125 enum pipe pipe, bool state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001126{
Jesse Barnes040484a2011-01-03 12:14:26 -08001127 u32 val;
Daniel Vetter55607e82013-06-16 21:42:39 +02001128 bool cur_state;
Jesse Barnes040484a2011-01-03 12:14:26 -08001129
Ville Syrjälä649636e2015-09-22 19:50:01 +03001130 val = I915_READ(FDI_RX_CTL(pipe));
Daniel Vetter55607e82013-06-16 21:42:39 +02001131 cur_state = !!(val & FDI_RX_PLL_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001132 I915_STATE_WARN(cur_state != state,
Daniel Vetter55607e82013-06-16 21:42:39 +02001133 "FDI RX PLL assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001134 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001135}
1136
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001137void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnesea0760c2011-01-04 15:09:32 -08001138{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001139 i915_reg_t pp_reg;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001140 u32 val;
Ville Syrjälä10ed55e2018-05-23 17:57:18 +03001141 enum pipe panel_pipe = INVALID_PIPE;
Thomas Jarosch0de3b482011-08-25 15:37:45 +02001142 bool locked = true;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001143
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001144 if (WARN_ON(HAS_DDI(dev_priv)))
Jani Nikulabedd4db2014-08-22 15:04:13 +03001145 return;
1146
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001147 if (HAS_PCH_SPLIT(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001148 u32 port_sel;
1149
Imre Deak44cb7342016-08-10 14:07:29 +03001150 pp_reg = PP_CONTROL(0);
1151 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
Jani Nikulabedd4db2014-08-22 15:04:13 +03001152
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001153 switch (port_sel) {
1154 case PANEL_PORT_SELECT_LVDS:
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001155 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001156 break;
1157 case PANEL_PORT_SELECT_DPA:
1158 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1159 break;
1160 case PANEL_PORT_SELECT_DPC:
1161 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1162 break;
1163 case PANEL_PORT_SELECT_DPD:
1164 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1165 break;
1166 default:
1167 MISSING_CASE(port_sel);
1168 break;
1169 }
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001170 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001171 /* presumably write lock depends on pipe, not port select */
Imre Deak44cb7342016-08-10 14:07:29 +03001172 pp_reg = PP_CONTROL(pipe);
Jani Nikulabedd4db2014-08-22 15:04:13 +03001173 panel_pipe = pipe;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001174 } else {
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001175 u32 port_sel;
1176
Imre Deak44cb7342016-08-10 14:07:29 +03001177 pp_reg = PP_CONTROL(0);
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001178 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1179
1180 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001181 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
Jesse Barnesea0760c2011-01-04 15:09:32 -08001182 }
1183
1184 val = I915_READ(pp_reg);
1185 if (!(val & PANEL_POWER_ON) ||
Jani Nikulaec49ba22014-08-21 15:06:25 +03001186 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
Jesse Barnesea0760c2011-01-04 15:09:32 -08001187 locked = false;
1188
Rob Clarke2c719b2014-12-15 13:56:32 -05001189 I915_STATE_WARN(panel_pipe == pipe && locked,
Jesse Barnesea0760c2011-01-04 15:09:32 -08001190 "panel assertion failure, pipe %c regs locked\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001191 pipe_name(pipe));
Jesse Barnesea0760c2011-01-04 15:09:32 -08001192}
1193
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001194void assert_pipe(struct drm_i915_private *dev_priv,
1195 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001196{
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001197 bool cur_state;
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001198 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1199 pipe);
Imre Deak4feed0e2016-02-12 18:55:14 +02001200 enum intel_display_power_domain power_domain;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001201
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001202 /* we keep both pipes enabled on 830 */
1203 if (IS_I830(dev_priv))
Daniel Vetter8e636782012-01-22 01:36:48 +01001204 state = true;
1205
Imre Deak4feed0e2016-02-12 18:55:14 +02001206 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1207 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001208 u32 val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni69310162013-01-29 16:35:19 -02001209 cur_state = !!(val & PIPECONF_ENABLE);
Imre Deak4feed0e2016-02-12 18:55:14 +02001210
1211 intel_display_power_put(dev_priv, power_domain);
1212 } else {
1213 cur_state = false;
Paulo Zanoni69310162013-01-29 16:35:19 -02001214 }
1215
Rob Clarke2c719b2014-12-15 13:56:32 -05001216 I915_STATE_WARN(cur_state != state,
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001217 "pipe %c assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001218 pipe_name(pipe), onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001219}
1220
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001221static void assert_plane(struct intel_plane *plane, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001222{
Ville Syrjäläeade6c82018-01-30 22:38:03 +02001223 enum pipe pipe;
1224 bool cur_state;
1225
1226 cur_state = plane->get_hw_state(plane, &pipe);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001227
Rob Clarke2c719b2014-12-15 13:56:32 -05001228 I915_STATE_WARN(cur_state != state,
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001229 "%s assertion failure (expected %s, current %s)\n",
1230 plane->base.name, onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001231}
1232
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001233#define assert_plane_enabled(p) assert_plane(p, true)
1234#define assert_plane_disabled(p) assert_plane(p, false)
Chris Wilson931872f2012-01-16 23:01:13 +00001235
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001236static void assert_planes_disabled(struct intel_crtc *crtc)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001237{
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001238 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1239 struct intel_plane *plane;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001240
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001241 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1242 assert_plane_disabled(plane);
Jesse Barnes19332d72013-03-28 09:55:38 -07001243}
1244
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001245static void assert_vblank_disabled(struct drm_crtc *crtc)
1246{
Rob Clarke2c719b2014-12-15 13:56:32 -05001247 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001248 drm_crtc_vblank_put(crtc);
1249}
1250
Ander Conselvan de Oliveira7abd4b32016-03-08 17:46:15 +02001251void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1252 enum pipe pipe)
Jesse Barnes92f25842011-01-04 15:09:34 -08001253{
Jesse Barnes92f25842011-01-04 15:09:34 -08001254 u32 val;
1255 bool enabled;
1256
Ville Syrjälä649636e2015-09-22 19:50:01 +03001257 val = I915_READ(PCH_TRANSCONF(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001258 enabled = !!(val & TRANS_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001259 I915_STATE_WARN(enabled,
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001260 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1261 pipe_name(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001262}
1263
Jesse Barnes291906f2011-02-02 12:28:03 -08001264static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001265 enum pipe pipe, enum port port,
1266 i915_reg_t dp_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001267{
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001268 enum pipe port_pipe;
1269 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001270
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001271 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1272
1273 I915_STATE_WARN(state && port_pipe == pipe,
1274 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1275 port_name(port), pipe_name(pipe));
1276
1277 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1278 "IBX PCH DP %c still using transcoder B\n",
1279 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001280}
1281
1282static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä76203462018-05-14 20:24:21 +03001283 enum pipe pipe, enum port port,
1284 i915_reg_t hdmi_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001285{
Ville Syrjälä76203462018-05-14 20:24:21 +03001286 enum pipe port_pipe;
1287 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001288
Ville Syrjälä76203462018-05-14 20:24:21 +03001289 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1290
1291 I915_STATE_WARN(state && port_pipe == pipe,
1292 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1293 port_name(port), pipe_name(pipe));
1294
1295 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1296 "IBX PCH HDMI %c still using transcoder B\n",
1297 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001298}
1299
1300static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1301 enum pipe pipe)
1302{
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001303 enum pipe port_pipe;
Jesse Barnes291906f2011-02-02 12:28:03 -08001304
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001305 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1306 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1307 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
Jesse Barnes291906f2011-02-02 12:28:03 -08001308
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001309 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1310 port_pipe == pipe,
1311 "PCH VGA enabled on transcoder %c, should be disabled\n",
1312 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001313
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001314 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1315 port_pipe == pipe,
1316 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1317 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001318
Ville Syrjälä3aefb672018-11-08 16:36:35 +02001319 /* PCH SDVOB multiplex with HDMIB */
Ville Syrjälä76203462018-05-14 20:24:21 +03001320 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1321 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1322 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
Jesse Barnes291906f2011-02-02 12:28:03 -08001323}
1324
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001325static void _vlv_enable_pll(struct intel_crtc *crtc,
1326 const struct intel_crtc_state *pipe_config)
1327{
1328 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1329 enum pipe pipe = crtc->pipe;
1330
1331 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1332 POSTING_READ(DPLL(pipe));
1333 udelay(150);
1334
Chris Wilson2c30b432016-06-30 15:32:54 +01001335 if (intel_wait_for_register(dev_priv,
1336 DPLL(pipe),
1337 DPLL_LOCK_VLV,
1338 DPLL_LOCK_VLV,
1339 1))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001340 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1341}
1342
Ville Syrjäläd288f652014-10-28 13:20:22 +02001343static void vlv_enable_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001344 const struct intel_crtc_state *pipe_config)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001345{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001346 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001347 enum pipe pipe = crtc->pipe;
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001348
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001349 assert_pipe_disabled(dev_priv, pipe);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001350
Daniel Vetter87442f72013-06-06 00:52:17 +02001351 /* PLL is protected by panel, make sure we can write it */
Ville Syrjälä7d1a83c2016-03-15 16:39:58 +02001352 assert_panel_unlocked(dev_priv, pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001353
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001354 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1355 _vlv_enable_pll(crtc, pipe_config);
Daniel Vetter426115c2013-07-11 22:13:42 +02001356
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001357 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1358 POSTING_READ(DPLL_MD(pipe));
Daniel Vetter87442f72013-06-06 00:52:17 +02001359}
1360
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001361
1362static void _chv_enable_pll(struct intel_crtc *crtc,
1363 const struct intel_crtc_state *pipe_config)
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001364{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001365 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001366 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001367 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001368 u32 tmp;
1369
Ville Syrjäläa5805162015-05-26 20:42:30 +03001370 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001371
1372 /* Enable back the 10bit clock to display controller */
1373 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1374 tmp |= DPIO_DCLKP_EN;
1375 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1376
Ville Syrjälä54433e92015-05-26 20:42:31 +03001377 mutex_unlock(&dev_priv->sb_lock);
1378
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001379 /*
1380 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1381 */
1382 udelay(1);
1383
1384 /* Enable PLL */
Ville Syrjäläd288f652014-10-28 13:20:22 +02001385 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001386
1387 /* Check PLL is locked */
Chris Wilson6b188262016-06-30 15:32:55 +01001388 if (intel_wait_for_register(dev_priv,
1389 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1390 1))
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001391 DRM_ERROR("PLL %d failed to lock\n", pipe);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001392}
1393
1394static void chv_enable_pll(struct intel_crtc *crtc,
1395 const struct intel_crtc_state *pipe_config)
1396{
1397 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1398 enum pipe pipe = crtc->pipe;
1399
1400 assert_pipe_disabled(dev_priv, pipe);
1401
1402 /* PLL is protected by panel, make sure we can write it */
1403 assert_panel_unlocked(dev_priv, pipe);
1404
1405 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1406 _chv_enable_pll(crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001407
Ville Syrjäläc2317752016-03-15 16:39:56 +02001408 if (pipe != PIPE_A) {
1409 /*
1410 * WaPixelRepeatModeFixForC0:chv
1411 *
1412 * DPLLCMD is AWOL. Use chicken bits to propagate
1413 * the value from DPLLBMD to either pipe B or C.
1414 */
Ville Syrjälädfa311f2017-09-13 17:08:54 +03001415 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
Ville Syrjäläc2317752016-03-15 16:39:56 +02001416 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1417 I915_WRITE(CBR4_VLV, 0);
1418 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1419
1420 /*
1421 * DPLLB VGA mode also seems to cause problems.
1422 * We should always have it disabled.
1423 */
1424 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1425 } else {
1426 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1427 POSTING_READ(DPLL_MD(pipe));
1428 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001429}
1430
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001431static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001432{
1433 struct intel_crtc *crtc;
1434 int count = 0;
1435
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001436 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst3538b9d2015-06-01 12:50:10 +02001437 count += crtc->base.state->active &&
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03001438 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1439 }
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001440
1441 return count;
1442}
1443
Ville Syrjälä939994d2017-09-13 17:08:56 +03001444static void i9xx_enable_pll(struct intel_crtc *crtc,
1445 const struct intel_crtc_state *crtc_state)
Daniel Vetter87442f72013-06-06 00:52:17 +02001446{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001447 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001448 i915_reg_t reg = DPLL(crtc->pipe);
Ville Syrjälä939994d2017-09-13 17:08:56 +03001449 u32 dpll = crtc_state->dpll_hw_state.dpll;
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001450 int i;
Daniel Vetter87442f72013-06-06 00:52:17 +02001451
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001452 assert_pipe_disabled(dev_priv, crtc->pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001453
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001454 /* PLL is protected by panel, make sure we can write it */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001455 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001456 assert_panel_unlocked(dev_priv, crtc->pipe);
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001457
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001458 /* Enable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001459 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001460 /*
1461 * It appears to be important that we don't enable this
1462 * for the current pipe before otherwise configuring the
1463 * PLL. No idea how this should be handled if multiple
1464 * DVO outputs are enabled simultaneosly.
1465 */
1466 dpll |= DPLL_DVO_2X_MODE;
1467 I915_WRITE(DPLL(!crtc->pipe),
1468 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1469 }
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001470
Ville Syrjäläc2b63372015-10-07 22:08:25 +03001471 /*
1472 * Apparently we need to have VGA mode enabled prior to changing
1473 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1474 * dividers, even though the register value does change.
1475 */
1476 I915_WRITE(reg, 0);
1477
Ville Syrjälä8e7a65a2015-10-07 22:08:24 +03001478 I915_WRITE(reg, dpll);
1479
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001480 /* Wait for the clocks to stabilize. */
1481 POSTING_READ(reg);
1482 udelay(150);
1483
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001484 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001485 I915_WRITE(DPLL_MD(crtc->pipe),
Ville Syrjälä939994d2017-09-13 17:08:56 +03001486 crtc_state->dpll_hw_state.dpll_md);
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001487 } else {
1488 /* The pixel multiplier can only be updated once the
1489 * DPLL is enabled and the clocks are stable.
1490 *
1491 * So write it again.
1492 */
1493 I915_WRITE(reg, dpll);
1494 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001495
1496 /* We do this three times for luck */
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001497 for (i = 0; i < 3; i++) {
1498 I915_WRITE(reg, dpll);
1499 POSTING_READ(reg);
1500 udelay(150); /* wait for warmup */
1501 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001502}
1503
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001504static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001505{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001506 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001507 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001508 enum pipe pipe = crtc->pipe;
1509
1510 /* Disable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001511 if (IS_I830(dev_priv) &&
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001512 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001513 !intel_num_dvo_pipes(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001514 I915_WRITE(DPLL(PIPE_B),
1515 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1516 I915_WRITE(DPLL(PIPE_A),
1517 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1518 }
1519
Ville Syrjäläb6b5d042014-08-15 01:22:07 +03001520 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001521 if (IS_I830(dev_priv))
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001522 return;
1523
1524 /* Make sure the pipe isn't still relying on us */
1525 assert_pipe_disabled(dev_priv, pipe);
1526
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001527 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
Daniel Vetter50b44a42013-06-05 13:34:33 +02001528 POSTING_READ(DPLL(pipe));
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001529}
1530
Jesse Barnesf6071162013-10-01 10:41:38 -07001531static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1532{
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001533 u32 val;
Jesse Barnesf6071162013-10-01 10:41:38 -07001534
1535 /* Make sure the pipe isn't still relying on us */
1536 assert_pipe_disabled(dev_priv, pipe);
1537
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001538 val = DPLL_INTEGRATED_REF_CLK_VLV |
1539 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1540 if (pipe != PIPE_A)
1541 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1542
Jesse Barnesf6071162013-10-01 10:41:38 -07001543 I915_WRITE(DPLL(pipe), val);
1544 POSTING_READ(DPLL(pipe));
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001545}
1546
1547static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1548{
Ville Syrjäläd7520482014-04-09 13:28:59 +03001549 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001550 u32 val;
1551
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001552 /* Make sure the pipe isn't still relying on us */
1553 assert_pipe_disabled(dev_priv, pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001554
Ville Syrjälä60bfe442015-06-29 15:25:49 +03001555 val = DPLL_SSC_REF_CLK_CHV |
1556 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001557 if (pipe != PIPE_A)
1558 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001559
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001560 I915_WRITE(DPLL(pipe), val);
1561 POSTING_READ(DPLL(pipe));
Ville Syrjäläd7520482014-04-09 13:28:59 +03001562
Ville Syrjäläa5805162015-05-26 20:42:30 +03001563 mutex_lock(&dev_priv->sb_lock);
Ville Syrjäläd7520482014-04-09 13:28:59 +03001564
1565 /* Disable 10bit clock to display controller */
1566 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1567 val &= ~DPIO_DCLKP_EN;
1568 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1569
Ville Syrjäläa5805162015-05-26 20:42:30 +03001570 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesf6071162013-10-01 10:41:38 -07001571}
1572
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001573void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001574 struct intel_digital_port *dport,
1575 unsigned int expected_mask)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001576{
1577 u32 port_mask;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001578 i915_reg_t dpll_reg;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001579
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001580 switch (dport->base.port) {
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001581 case PORT_B:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001582 port_mask = DPLL_PORTB_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001583 dpll_reg = DPLL(0);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001584 break;
1585 case PORT_C:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001586 port_mask = DPLL_PORTC_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001587 dpll_reg = DPLL(0);
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001588 expected_mask <<= 4;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001589 break;
1590 case PORT_D:
1591 port_mask = DPLL_PORTD_READY_MASK;
1592 dpll_reg = DPIO_PHY_STATUS;
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001593 break;
1594 default:
1595 BUG();
1596 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07001597
Chris Wilson370004d2016-06-30 15:32:56 +01001598 if (intel_wait_for_register(dev_priv,
1599 dpll_reg, port_mask, expected_mask,
1600 1000))
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001601 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001602 port_name(dport->base.port),
1603 I915_READ(dpll_reg) & port_mask, expected_mask);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001604}
1605
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001606static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001607{
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001608 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1610 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001611 i915_reg_t reg;
1612 uint32_t val, pipeconf_val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001613
Jesse Barnes040484a2011-01-03 12:14:26 -08001614 /* Make sure PCH DPLL is enabled */
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001615 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
Jesse Barnes040484a2011-01-03 12:14:26 -08001616
1617 /* FDI must be feeding us bits for PCH ports */
1618 assert_fdi_tx_enabled(dev_priv, pipe);
1619 assert_fdi_rx_enabled(dev_priv, pipe);
1620
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001621 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001622 /* Workaround: Set the timing override bit before enabling the
1623 * pch transcoder. */
1624 reg = TRANS_CHICKEN2(pipe);
1625 val = I915_READ(reg);
1626 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1627 I915_WRITE(reg, val);
Eugeni Dodonov59c859d2012-05-09 15:37:19 -03001628 }
Daniel Vetter23670b322012-11-01 09:15:30 +01001629
Daniel Vetterab9412b2013-05-03 11:49:46 +02001630 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001631 val = I915_READ(reg);
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001632 pipeconf_val = I915_READ(PIPECONF(pipe));
Jesse Barnese9bcff52011-06-24 12:19:20 -07001633
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001634 if (HAS_PCH_IBX(dev_priv)) {
Jesse Barnese9bcff52011-06-24 12:19:20 -07001635 /*
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001636 * Make the BPC in transcoder be consistent with
1637 * that in pipeconf reg. For HDMI we must use 8bpc
1638 * here for both 8bpc and 12bpc.
Jesse Barnese9bcff52011-06-24 12:19:20 -07001639 */
Daniel Vetterdfd07d72012-12-17 11:21:38 +01001640 val &= ~PIPECONF_BPC_MASK;
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001641 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001642 val |= PIPECONF_8BPC;
1643 else
1644 val |= pipeconf_val & PIPECONF_BPC_MASK;
Jesse Barnese9bcff52011-06-24 12:19:20 -07001645 }
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001646
1647 val &= ~TRANS_INTERLACE_MASK;
1648 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001649 if (HAS_PCH_IBX(dev_priv) &&
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001650 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Paulo Zanoni7c26e5c2012-02-14 17:07:09 -02001651 val |= TRANS_LEGACY_INTERLACED_ILK;
1652 else
1653 val |= TRANS_INTERLACED;
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001654 else
1655 val |= TRANS_PROGRESSIVE;
1656
Jesse Barnes040484a2011-01-03 12:14:26 -08001657 I915_WRITE(reg, val | TRANS_ENABLE);
Chris Wilson650fbd82016-06-30 15:32:57 +01001658 if (intel_wait_for_register(dev_priv,
1659 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1660 100))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001661 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
Jesse Barnes040484a2011-01-03 12:14:26 -08001662}
1663
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001664static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
Paulo Zanoni937bb612012-10-31 18:12:47 -02001665 enum transcoder cpu_transcoder)
Jesse Barnes040484a2011-01-03 12:14:26 -08001666{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001667 u32 val, pipeconf_val;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001668
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001669 /* FDI must be feeding us bits for PCH ports */
Daniel Vetter1a240d42012-11-29 22:18:51 +01001670 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001671 assert_fdi_rx_enabled(dev_priv, PIPE_A);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001672
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001673 /* Workaround: set timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001674 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001675 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001676 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001677
Paulo Zanoni25f3ef12012-10-31 18:12:49 -02001678 val = TRANS_ENABLE;
Paulo Zanoni937bb612012-10-31 18:12:47 -02001679 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001680
Paulo Zanoni9a76b1c2012-10-31 18:12:48 -02001681 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1682 PIPECONF_INTERLACED_ILK)
Paulo Zanonia35f2672012-10-31 18:12:45 -02001683 val |= TRANS_INTERLACED;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001684 else
1685 val |= TRANS_PROGRESSIVE;
1686
Daniel Vetterab9412b2013-05-03 11:49:46 +02001687 I915_WRITE(LPT_TRANSCONF, val);
Chris Wilsond9f96242016-06-30 15:32:58 +01001688 if (intel_wait_for_register(dev_priv,
1689 LPT_TRANSCONF,
1690 TRANS_STATE_ENABLE,
1691 TRANS_STATE_ENABLE,
1692 100))
Paulo Zanoni937bb612012-10-31 18:12:47 -02001693 DRM_ERROR("Failed to enable PCH transcoder\n");
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001694}
1695
Paulo Zanonib8a4f402012-10-31 18:12:42 -02001696static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1697 enum pipe pipe)
Jesse Barnes040484a2011-01-03 12:14:26 -08001698{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001699 i915_reg_t reg;
1700 uint32_t val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001701
1702 /* FDI relies on the transcoder */
1703 assert_fdi_tx_disabled(dev_priv, pipe);
1704 assert_fdi_rx_disabled(dev_priv, pipe);
1705
Jesse Barnes291906f2011-02-02 12:28:03 -08001706 /* Ports must be off as well */
1707 assert_pch_ports_disabled(dev_priv, pipe);
1708
Daniel Vetterab9412b2013-05-03 11:49:46 +02001709 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001710 val = I915_READ(reg);
1711 val &= ~TRANS_ENABLE;
1712 I915_WRITE(reg, val);
1713 /* wait for PCH transcoder off, transcoder state */
Chris Wilsona7d04662016-06-30 15:32:59 +01001714 if (intel_wait_for_register(dev_priv,
1715 reg, TRANS_STATE_ENABLE, 0,
1716 50))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001717 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
Daniel Vetter23670b322012-11-01 09:15:30 +01001718
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001719 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001720 /* Workaround: Clear the timing override chicken bit again. */
1721 reg = TRANS_CHICKEN2(pipe);
1722 val = I915_READ(reg);
1723 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1724 I915_WRITE(reg, val);
1725 }
Jesse Barnes040484a2011-01-03 12:14:26 -08001726}
1727
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001728void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001729{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001730 u32 val;
1731
Daniel Vetterab9412b2013-05-03 11:49:46 +02001732 val = I915_READ(LPT_TRANSCONF);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001733 val &= ~TRANS_ENABLE;
Daniel Vetterab9412b2013-05-03 11:49:46 +02001734 I915_WRITE(LPT_TRANSCONF, val);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001735 /* wait for PCH transcoder off, transcoder state */
Chris Wilsondfdb4742016-06-30 15:33:00 +01001736 if (intel_wait_for_register(dev_priv,
1737 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1738 50))
Paulo Zanoni8a52fd92012-10-31 18:12:51 -02001739 DRM_ERROR("Failed to disable PCH transcoder\n");
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001740
1741 /* Workaround: clear timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001742 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001743 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001744 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Jesse Barnes92f25842011-01-04 15:09:34 -08001745}
1746
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001747enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
Ville Syrjälä65f21302016-10-14 20:02:53 +03001748{
1749 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1750
Ville Syrjälä65f21302016-10-14 20:02:53 +03001751 if (HAS_PCH_LPT(dev_priv))
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001752 return PIPE_A;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001753 else
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001754 return crtc->pipe;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001755}
1756
Ville Syrjälä4972f702017-11-29 17:37:32 +02001757static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001758{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001759 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1760 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1761 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
Paulo Zanoni03722642014-01-17 13:51:09 -02001762 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001763 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001764 u32 val;
1765
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001766 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1767
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001768 assert_planes_disabled(crtc);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001769
Jesse Barnesb24e7172011-01-04 15:09:30 -08001770 /*
1771 * A pipe without a PLL won't actually be able to drive bits from
1772 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1773 * need the check.
1774 */
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001775 if (HAS_GMCH_DISPLAY(dev_priv)) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001776 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
Jani Nikula23538ef2013-08-27 15:12:22 +03001777 assert_dsi_pll_enabled(dev_priv);
1778 else
1779 assert_pll_enabled(dev_priv, pipe);
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001780 } else {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001781 if (new_crtc_state->has_pch_encoder) {
Jesse Barnes040484a2011-01-03 12:14:26 -08001782 /* if driving the PCH, we need FDI enabled */
Ville Syrjälä65f21302016-10-14 20:02:53 +03001783 assert_fdi_rx_pll_enabled(dev_priv,
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001784 intel_crtc_pch_transcoder(crtc));
Daniel Vetter1a240d42012-11-29 22:18:51 +01001785 assert_fdi_tx_pll_enabled(dev_priv,
1786 (enum pipe) cpu_transcoder);
Jesse Barnes040484a2011-01-03 12:14:26 -08001787 }
1788 /* FIXME: assert CPU port conditions for SNB+ */
1789 }
Jesse Barnesb24e7172011-01-04 15:09:30 -08001790
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001791 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001792 val = I915_READ(reg);
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001793 if (val & PIPECONF_ENABLE) {
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001794 /* we keep both pipes enabled on 830 */
1795 WARN_ON(!IS_I830(dev_priv));
Chris Wilson00d70b12011-03-17 07:18:29 +00001796 return;
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001797 }
Chris Wilson00d70b12011-03-17 07:18:29 +00001798
1799 I915_WRITE(reg, val | PIPECONF_ENABLE);
Paulo Zanoni851855d2013-12-19 19:12:29 -02001800 POSTING_READ(reg);
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001801
1802 /*
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001803 * Until the pipe starts PIPEDSL reads will return a stale value,
1804 * which causes an apparent vblank timestamp jump when PIPEDSL
1805 * resets to its proper value. That also messes up the frame count
1806 * when it's derived from the timestamps. So let's wait for the
1807 * pipe to start properly before we call drm_crtc_vblank_on()
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001808 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001809 if (dev_priv->drm.max_vblank_count == 0)
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001810 intel_wait_for_pipe_scanline_moving(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001811}
1812
Ville Syrjälä4972f702017-11-29 17:37:32 +02001813static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001814{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001815 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001816 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä4972f702017-11-29 17:37:32 +02001817 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjälä575f7ab2014-08-15 01:21:56 +03001818 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001819 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001820 u32 val;
1821
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001822 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1823
Jesse Barnesb24e7172011-01-04 15:09:30 -08001824 /*
1825 * Make sure planes won't keep trying to pump pixels to us,
1826 * or we might hang the display.
1827 */
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001828 assert_planes_disabled(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001829
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001830 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001831 val = I915_READ(reg);
Chris Wilson00d70b12011-03-17 07:18:29 +00001832 if ((val & PIPECONF_ENABLE) == 0)
1833 return;
1834
Ville Syrjälä67adc642014-08-15 01:21:57 +03001835 /*
1836 * Double wide has implications for planes
1837 * so best keep it disabled when not needed.
1838 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001839 if (old_crtc_state->double_wide)
Ville Syrjälä67adc642014-08-15 01:21:57 +03001840 val &= ~PIPECONF_DOUBLE_WIDE;
1841
1842 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001843 if (!IS_I830(dev_priv))
Ville Syrjälä67adc642014-08-15 01:21:57 +03001844 val &= ~PIPECONF_ENABLE;
1845
1846 I915_WRITE(reg, val);
1847 if ((val & PIPECONF_ENABLE) == 0)
Ville Syrjälä4972f702017-11-29 17:37:32 +02001848 intel_wait_for_pipe_off(old_crtc_state);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001849}
1850
Ville Syrjälä832be822016-01-12 21:08:33 +02001851static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1852{
1853 return IS_GEN2(dev_priv) ? 2048 : 4096;
1854}
1855
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001856static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001857intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001858{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001859 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001860 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001861
1862 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001863 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001864 return cpp;
1865 case I915_FORMAT_MOD_X_TILED:
1866 if (IS_GEN2(dev_priv))
1867 return 128;
1868 else
1869 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001870 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001871 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001872 return 128;
1873 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001874 case I915_FORMAT_MOD_Y_TILED:
1875 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1876 return 128;
1877 else
1878 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001879 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001880 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001881 return 128;
1882 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001883 case I915_FORMAT_MOD_Yf_TILED:
1884 switch (cpp) {
1885 case 1:
1886 return 64;
1887 case 2:
1888 case 4:
1889 return 128;
1890 case 8:
1891 case 16:
1892 return 256;
1893 default:
1894 MISSING_CASE(cpp);
1895 return cpp;
1896 }
1897 break;
1898 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001899 MISSING_CASE(fb->modifier);
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001900 return cpp;
1901 }
1902}
1903
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001904static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001905intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001906{
Ben Widawsky2f075562017-03-24 14:29:48 -07001907 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä832be822016-01-12 21:08:33 +02001908 return 1;
1909 else
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001910 return intel_tile_size(to_i915(fb->dev)) /
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001911 intel_tile_width_bytes(fb, color_plane);
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001912}
1913
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001914/* Return the tile dimensions in pixel units */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001915static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001916 unsigned int *tile_width,
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001917 unsigned int *tile_height)
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001918{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001919 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1920 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001921
1922 *tile_width = tile_width_bytes / cpp;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001923 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001924}
1925
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001926unsigned int
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001927intel_fb_align_height(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001928 int color_plane, unsigned int height)
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001929{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001930 unsigned int tile_height = intel_tile_height(fb, color_plane);
Ville Syrjälä832be822016-01-12 21:08:33 +02001931
1932 return ALIGN(height, tile_height);
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001933}
1934
Ville Syrjälä1663b9d2016-02-15 22:54:45 +02001935unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1936{
1937 unsigned int size = 0;
1938 int i;
1939
1940 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1941 size += rot_info->plane[i].width * rot_info->plane[i].height;
1942
1943 return size;
1944}
1945
Daniel Vetter75c82a52015-10-14 16:51:04 +02001946static void
Ville Syrjälä3465c582016-02-15 22:54:43 +02001947intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1948 const struct drm_framebuffer *fb,
1949 unsigned int rotation)
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00001950{
Chris Wilson7b92c042017-01-14 00:28:26 +00001951 view->type = I915_GGTT_VIEW_NORMAL;
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03001952 if (drm_rotation_90_or_270(rotation)) {
Chris Wilson7b92c042017-01-14 00:28:26 +00001953 view->type = I915_GGTT_VIEW_ROTATED;
Chris Wilson8bab11932017-01-14 00:28:25 +00001954 view->rotated = to_intel_framebuffer(fb)->rot_info;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +02001955 }
1956}
1957
Ville Syrjäläfabac482017-03-27 21:55:43 +03001958static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
1959{
1960 if (IS_I830(dev_priv))
1961 return 16 * 1024;
1962 else if (IS_I85X(dev_priv))
1963 return 256;
Ville Syrjäläd9e15512017-03-27 21:55:45 +03001964 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
1965 return 32;
Ville Syrjäläfabac482017-03-27 21:55:43 +03001966 else
1967 return 4 * 1024;
1968}
1969
Ville Syrjälä603525d2016-01-12 21:08:37 +02001970static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001971{
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00001972 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001973 return 256 * 1024;
Jani Nikulac0f86832016-12-07 12:13:04 +02001974 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
Wayne Boyer666a4532015-12-09 12:29:35 -08001975 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001976 return 128 * 1024;
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00001977 else if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001978 return 4 * 1024;
1979 else
Ville Syrjälä44c59052015-06-11 16:31:16 +03001980 return 0;
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001981}
1982
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001983static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001984 int color_plane)
Ville Syrjälä603525d2016-01-12 21:08:37 +02001985{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001986 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1987
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02001988 /* AUX_DIST needs only 4K alignment */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001989 if (color_plane == 1)
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02001990 return 4096;
1991
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001992 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001993 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä603525d2016-01-12 21:08:37 +02001994 return intel_linear_alignment(dev_priv);
1995 case I915_FORMAT_MOD_X_TILED:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001996 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä603525d2016-01-12 21:08:37 +02001997 return 256 * 1024;
1998 return 0;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001999 case I915_FORMAT_MOD_Y_TILED_CCS:
2000 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002001 case I915_FORMAT_MOD_Y_TILED:
2002 case I915_FORMAT_MOD_Yf_TILED:
2003 return 1 * 1024 * 1024;
2004 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002005 MISSING_CASE(fb->modifier);
Ville Syrjälä603525d2016-01-12 21:08:37 +02002006 return 0;
2007 }
2008}
2009
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002010static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2011{
2012 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2013 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2014
Ville Syrjälä32febd92018-02-21 18:02:33 +02002015 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002016}
2017
Chris Wilson058d88c2016-08-15 10:49:06 +01002018struct i915_vma *
Chris Wilson59354852018-02-20 13:42:06 +00002019intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002020 const struct i915_ggtt_view *view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002021 bool uses_fence,
Chris Wilson59354852018-02-20 13:42:06 +00002022 unsigned long *out_flags)
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002023{
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002024 struct drm_device *dev = fb->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002025 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002026 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Chris Wilson058d88c2016-08-15 10:49:06 +01002027 struct i915_vma *vma;
Chris Wilson59354852018-02-20 13:42:06 +00002028 unsigned int pinctl;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002029 u32 alignment;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002030
Matt Roperebcdd392014-07-09 16:22:11 -07002031 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2032
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002033 alignment = intel_surf_alignment(fb, 0);
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002034
Chris Wilson693db182013-03-05 14:52:39 +00002035 /* Note that the w/a also requires 64 PTE of padding following the
2036 * bo. We currently fill all unused PTE with the shadow page and so
2037 * we should always have valid PTE following the scanout preventing
2038 * the VT-d warning.
2039 */
Chris Wilson48f112f2016-06-24 14:07:14 +01002040 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
Chris Wilson693db182013-03-05 14:52:39 +00002041 alignment = 256 * 1024;
2042
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002043 /*
2044 * Global gtt pte registers are special registers which actually forward
2045 * writes to a chunk of system memory. Which means that there is no risk
2046 * that the register values disappear as soon as we call
2047 * intel_runtime_pm_put(), so it is correct to wrap only the
2048 * pin/unpin/fence and not more.
2049 */
2050 intel_runtime_pm_get(dev_priv);
2051
Daniel Vetter9db529a2017-08-08 10:08:28 +02002052 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2053
Chris Wilson59354852018-02-20 13:42:06 +00002054 pinctl = 0;
2055
2056 /* Valleyview is definitely limited to scanning out the first
2057 * 512MiB. Lets presume this behaviour was inherited from the
2058 * g4x display engine and that all earlier gen are similarly
2059 * limited. Testing suggests that it is a little more
2060 * complicated than this. For example, Cherryview appears quite
2061 * happy to scanout from anywhere within its global aperture.
2062 */
2063 if (HAS_GMCH_DISPLAY(dev_priv))
2064 pinctl |= PIN_MAPPABLE;
2065
2066 vma = i915_gem_object_pin_to_display_plane(obj,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002067 alignment, view, pinctl);
Chris Wilson49ef5292016-08-18 17:17:00 +01002068 if (IS_ERR(vma))
2069 goto err;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002070
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002071 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002072 int ret;
2073
Chris Wilson49ef5292016-08-18 17:17:00 +01002074 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2075 * fence, whereas 965+ only requires a fence if using
2076 * framebuffer compression. For simplicity, we always, when
2077 * possible, install a fence as the cost is not that onerous.
2078 *
2079 * If we fail to fence the tiled scanout, then either the
2080 * modeset will reject the change (which is highly unlikely as
2081 * the affected systems, all but one, do not have unmappable
2082 * space) or we will not be able to enable full powersaving
2083 * techniques (also likely not to apply due to various limits
2084 * FBC and the like impose on the size of the buffer, which
2085 * presumably we violated anyway with this unmappable buffer).
2086 * Anyway, it is presumably better to stumble onwards with
2087 * something and try to run the system in a "less than optimal"
2088 * mode that matches the user configuration.
2089 */
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002090 ret = i915_vma_pin_fence(vma);
2091 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
Chris Wilson75097022018-03-05 10:33:12 +00002092 i915_gem_object_unpin_from_display_plane(vma);
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002093 vma = ERR_PTR(ret);
2094 goto err;
2095 }
2096
2097 if (ret == 0 && vma->fence)
Chris Wilson59354852018-02-20 13:42:06 +00002098 *out_flags |= PLANE_HAS_FENCE;
Vivek Kasireddy98072162015-10-29 18:54:38 -07002099 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002100
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002101 i915_vma_get(vma);
Chris Wilson49ef5292016-08-18 17:17:00 +01002102err:
Daniel Vetter9db529a2017-08-08 10:08:28 +02002103 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2104
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002105 intel_runtime_pm_put(dev_priv);
Chris Wilson058d88c2016-08-15 10:49:06 +01002106 return vma;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002107}
2108
Chris Wilson59354852018-02-20 13:42:06 +00002109void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
Chris Wilson1690e1e2011-12-14 13:57:08 +01002110{
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002111 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00002112
Chris Wilson59354852018-02-20 13:42:06 +00002113 if (flags & PLANE_HAS_FENCE)
2114 i915_vma_unpin_fence(vma);
Chris Wilson058d88c2016-08-15 10:49:06 +01002115 i915_gem_object_unpin_from_display_plane(vma);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002116 i915_vma_put(vma);
Chris Wilson1690e1e2011-12-14 13:57:08 +01002117}
2118
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002119static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002120 unsigned int rotation)
2121{
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002122 if (drm_rotation_90_or_270(rotation))
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002123 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002124 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002125 return fb->pitches[color_plane];
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002126}
2127
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002128/*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002129 * Convert the x/y offsets into a linear offset.
2130 * Only valid with 0/180 degree rotation, which is fine since linear
2131 * offset is only used with linear buffers on pre-hsw and tiled buffers
2132 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2133 */
2134u32 intel_fb_xy_to_linear(int x, int y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002135 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002136 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002137{
Ville Syrjälä29490562016-01-20 18:02:50 +02002138 const struct drm_framebuffer *fb = state->base.fb;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002139 unsigned int cpp = fb->format->cpp[color_plane];
2140 unsigned int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002141
2142 return y * pitch + x * cpp;
2143}
2144
2145/*
2146 * Add the x/y offsets derived from fb->offsets[] to the user
2147 * specified plane src x/y offsets. The resulting x/y offsets
2148 * specify the start of scanout from the beginning of the gtt mapping.
2149 */
2150void intel_add_fb_offsets(int *x, int *y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002151 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002152 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002153
2154{
Ville Syrjälä29490562016-01-20 18:02:50 +02002155 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2156 unsigned int rotation = state->base.rotation;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002157
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002158 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002159 *x += intel_fb->rotated[color_plane].x;
2160 *y += intel_fb->rotated[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002161 } else {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002162 *x += intel_fb->normal[color_plane].x;
2163 *y += intel_fb->normal[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002164 }
2165}
2166
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002167static u32 intel_adjust_tile_offset(int *x, int *y,
2168 unsigned int tile_width,
2169 unsigned int tile_height,
2170 unsigned int tile_size,
2171 unsigned int pitch_tiles,
2172 u32 old_offset,
2173 u32 new_offset)
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002174{
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002175 unsigned int pitch_pixels = pitch_tiles * tile_width;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002176 unsigned int tiles;
2177
2178 WARN_ON(old_offset & (tile_size - 1));
2179 WARN_ON(new_offset & (tile_size - 1));
2180 WARN_ON(new_offset > old_offset);
2181
2182 tiles = (old_offset - new_offset) / tile_size;
2183
2184 *y += tiles / pitch_tiles * tile_height;
2185 *x += tiles % pitch_tiles * tile_width;
2186
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002187 /* minimize x in case it got needlessly big */
2188 *y += *x / pitch_pixels * tile_height;
2189 *x %= pitch_pixels;
2190
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002191 return new_offset;
2192}
2193
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002194static bool is_surface_linear(u64 modifier, int color_plane)
2195{
2196 return modifier == DRM_FORMAT_MOD_LINEAR;
2197}
2198
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002199static u32 intel_adjust_aligned_offset(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002200 const struct drm_framebuffer *fb,
2201 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002202 unsigned int rotation,
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002203 unsigned int pitch,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002204 u32 old_offset, u32 new_offset)
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002205{
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002206 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002207 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002208
2209 WARN_ON(new_offset > old_offset);
2210
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002211 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002212 unsigned int tile_size, tile_width, tile_height;
2213 unsigned int pitch_tiles;
2214
2215 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002216 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002217
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002218 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002219 pitch_tiles = pitch / tile_height;
2220 swap(tile_width, tile_height);
2221 } else {
2222 pitch_tiles = pitch / (tile_width * cpp);
2223 }
2224
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002225 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2226 tile_size, pitch_tiles,
2227 old_offset, new_offset);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002228 } else {
2229 old_offset += *y * pitch + *x * cpp;
2230
2231 *y = (old_offset - new_offset) / pitch;
2232 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2233 }
2234
2235 return new_offset;
2236}
2237
2238/*
Ville Syrjälä303ba692017-08-24 22:10:49 +03002239 * Adjust the tile offset by moving the difference into
2240 * the x/y offsets.
2241 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002242static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2243 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002244 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002245 u32 old_offset, u32 new_offset)
Ville Syrjälä303ba692017-08-24 22:10:49 +03002246{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002247 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002248 state->base.rotation,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002249 state->color_plane[color_plane].stride,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002250 old_offset, new_offset);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002251}
2252
2253/*
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002254 * Computes the aligned offset to the base tile and adjusts
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002255 * x, y. bytes per pixel is assumed to be a power-of-two.
2256 *
2257 * In the 90/270 rotated case, x and y are assumed
2258 * to be already rotated to match the rotated GTT view, and
2259 * pitch is the tile_height aligned framebuffer height.
Ville Syrjälä6687c902015-09-15 13:16:41 +03002260 *
2261 * This function is used when computing the derived information
2262 * under intel_framebuffer, so using any of that information
2263 * here is not allowed. Anything under drm_framebuffer can be
2264 * used. This is why the user has to pass in the pitch since it
2265 * is specified in the rotated orientation.
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002266 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002267static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2268 int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002269 const struct drm_framebuffer *fb,
2270 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002271 unsigned int pitch,
2272 unsigned int rotation,
2273 u32 alignment)
Daniel Vetterc2c75132012-07-05 12:17:30 +02002274{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002275 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä6687c902015-09-15 13:16:41 +03002276 u32 offset, offset_aligned;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002277
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002278 if (alignment)
2279 alignment--;
2280
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002281 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002282 unsigned int tile_size, tile_width, tile_height;
2283 unsigned int tile_rows, tiles, pitch_tiles;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002284
Ville Syrjäläd8433102016-01-12 21:08:35 +02002285 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002286 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002287
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002288 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002289 pitch_tiles = pitch / tile_height;
2290 swap(tile_width, tile_height);
2291 } else {
2292 pitch_tiles = pitch / (tile_width * cpp);
2293 }
Daniel Vetterc2c75132012-07-05 12:17:30 +02002294
Ville Syrjäläd8433102016-01-12 21:08:35 +02002295 tile_rows = *y / tile_height;
2296 *y %= tile_height;
Chris Wilsonbc752862013-02-21 20:04:31 +00002297
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002298 tiles = *x / tile_width;
2299 *x %= tile_width;
Ville Syrjäläd8433102016-01-12 21:08:35 +02002300
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002301 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2302 offset_aligned = offset & ~alignment;
Chris Wilsonbc752862013-02-21 20:04:31 +00002303
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002304 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2305 tile_size, pitch_tiles,
2306 offset, offset_aligned);
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002307 } else {
Chris Wilsonbc752862013-02-21 20:04:31 +00002308 offset = *y * pitch + *x * cpp;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002309 offset_aligned = offset & ~alignment;
2310
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002311 *y = (offset & alignment) / pitch;
2312 *x = ((offset & alignment) - *y * pitch) / cpp;
Chris Wilsonbc752862013-02-21 20:04:31 +00002313 }
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002314
2315 return offset_aligned;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002316}
2317
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002318static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2319 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002320 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002321{
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002322 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2323 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
Ville Syrjälä29490562016-01-20 18:02:50 +02002324 const struct drm_framebuffer *fb = state->base.fb;
2325 unsigned int rotation = state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002326 int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002327 u32 alignment;
2328
2329 if (intel_plane->id == PLANE_CURSOR)
2330 alignment = intel_cursor_alignment(dev_priv);
2331 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002332 alignment = intel_surf_alignment(fb, color_plane);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002333
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002334 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002335 pitch, rotation, alignment);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002336}
2337
Ville Syrjälä303ba692017-08-24 22:10:49 +03002338/* Convert the fb->offset[] into x/y offsets */
2339static int intel_fb_offset_to_xy(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002340 const struct drm_framebuffer *fb,
2341 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002342{
Ville Syrjälä303ba692017-08-24 22:10:49 +03002343 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002344
Ville Syrjälä303ba692017-08-24 22:10:49 +03002345 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002346 fb->offsets[color_plane] % intel_tile_size(dev_priv))
Ville Syrjälä303ba692017-08-24 22:10:49 +03002347 return -EINVAL;
2348
2349 *x = 0;
2350 *y = 0;
2351
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002352 intel_adjust_aligned_offset(x, y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002353 fb, color_plane, DRM_MODE_ROTATE_0,
2354 fb->pitches[color_plane],
2355 fb->offsets[color_plane], 0);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002356
2357 return 0;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002358}
2359
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002360static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2361{
2362 switch (fb_modifier) {
2363 case I915_FORMAT_MOD_X_TILED:
2364 return I915_TILING_X;
2365 case I915_FORMAT_MOD_Y_TILED:
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002366 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002367 return I915_TILING_Y;
2368 default:
2369 return I915_TILING_NONE;
2370 }
2371}
2372
Ville Syrjälä16af25f2018-01-19 16:41:52 +02002373/*
2374 * From the Sky Lake PRM:
2375 * "The Color Control Surface (CCS) contains the compression status of
2376 * the cache-line pairs. The compression state of the cache-line pair
2377 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2378 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2379 * cache-line-pairs. CCS is always Y tiled."
2380 *
2381 * Since cache line pairs refers to horizontally adjacent cache lines,
2382 * each cache line in the CCS corresponds to an area of 32x16 cache
2383 * lines on the main surface. Since each pixel is 4 bytes, this gives
2384 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2385 * main surface.
2386 */
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -07002387static const struct drm_format_info ccs_formats[] = {
2388 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2389 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2390 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2391 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2392};
2393
2394static const struct drm_format_info *
2395lookup_format_info(const struct drm_format_info formats[],
2396 int num_formats, u32 format)
2397{
2398 int i;
2399
2400 for (i = 0; i < num_formats; i++) {
2401 if (formats[i].format == format)
2402 return &formats[i];
2403 }
2404
2405 return NULL;
2406}
2407
2408static const struct drm_format_info *
2409intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2410{
2411 switch (cmd->modifier[0]) {
2412 case I915_FORMAT_MOD_Y_TILED_CCS:
2413 case I915_FORMAT_MOD_Yf_TILED_CCS:
2414 return lookup_format_info(ccs_formats,
2415 ARRAY_SIZE(ccs_formats),
2416 cmd->pixel_format);
2417 default:
2418 return NULL;
2419 }
2420}
2421
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002422bool is_ccs_modifier(u64 modifier)
2423{
2424 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2425 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2426}
2427
Ville Syrjälä6687c902015-09-15 13:16:41 +03002428static int
2429intel_fill_fb_info(struct drm_i915_private *dev_priv,
2430 struct drm_framebuffer *fb)
2431{
2432 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2433 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002434 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002435 u32 gtt_offset_rotated = 0;
2436 unsigned int max_size = 0;
Ville Syrjäläbcb0b462016-12-14 23:30:22 +02002437 int i, num_planes = fb->format->num_planes;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002438 unsigned int tile_size = intel_tile_size(dev_priv);
2439
2440 for (i = 0; i < num_planes; i++) {
2441 unsigned int width, height;
2442 unsigned int cpp, size;
2443 u32 offset;
2444 int x, y;
Ville Syrjälä303ba692017-08-24 22:10:49 +03002445 int ret;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002446
Ville Syrjälä353c8592016-12-14 23:30:57 +02002447 cpp = fb->format->cpp[i];
Ville Syrjälä145fcb12016-11-18 21:53:06 +02002448 width = drm_framebuffer_plane_width(fb->width, fb, i);
2449 height = drm_framebuffer_plane_height(fb->height, fb, i);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002450
Ville Syrjälä303ba692017-08-24 22:10:49 +03002451 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2452 if (ret) {
2453 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2454 i, fb->offsets[i]);
2455 return ret;
2456 }
Ville Syrjälä6687c902015-09-15 13:16:41 +03002457
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002458 if (is_ccs_modifier(fb->modifier) && i == 1) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002459 int hsub = fb->format->hsub;
2460 int vsub = fb->format->vsub;
2461 int tile_width, tile_height;
2462 int main_x, main_y;
2463 int ccs_x, ccs_y;
2464
2465 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002466 tile_width *= hsub;
2467 tile_height *= vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002468
Ville Syrjälä303ba692017-08-24 22:10:49 +03002469 ccs_x = (x * hsub) % tile_width;
2470 ccs_y = (y * vsub) % tile_height;
2471 main_x = intel_fb->normal[0].x % tile_width;
2472 main_y = intel_fb->normal[0].y % tile_height;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002473
2474 /*
2475 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2476 * x/y offsets must match between CCS and the main surface.
2477 */
2478 if (main_x != ccs_x || main_y != ccs_y) {
2479 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2480 main_x, main_y,
2481 ccs_x, ccs_y,
2482 intel_fb->normal[0].x,
2483 intel_fb->normal[0].y,
2484 x, y);
2485 return -EINVAL;
2486 }
2487 }
2488
Ville Syrjälä6687c902015-09-15 13:16:41 +03002489 /*
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002490 * The fence (if used) is aligned to the start of the object
2491 * so having the framebuffer wrap around across the edge of the
2492 * fenced region doesn't really work. We have no API to configure
2493 * the fence start offset within the object (nor could we probably
2494 * on gen2/3). So it's just easier if we just require that the
2495 * fb layout agrees with the fence layout. We already check that the
2496 * fb stride matches the fence stride elsewhere.
2497 */
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002498 if (i == 0 && i915_gem_object_is_tiled(obj) &&
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002499 (x + width) * cpp > fb->pitches[i]) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +02002500 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2501 i, fb->offsets[i]);
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002502 return -EINVAL;
2503 }
2504
2505 /*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002506 * First pixel of the framebuffer from
2507 * the start of the normal gtt mapping.
2508 */
2509 intel_fb->normal[i].x = x;
2510 intel_fb->normal[i].y = y;
2511
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002512 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2513 fb->pitches[i],
2514 DRM_MODE_ROTATE_0,
2515 tile_size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002516 offset /= tile_size;
2517
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002518 if (!is_surface_linear(fb->modifier, i)) {
Ville Syrjälä6687c902015-09-15 13:16:41 +03002519 unsigned int tile_width, tile_height;
2520 unsigned int pitch_tiles;
2521 struct drm_rect r;
2522
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002523 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002524
2525 rot_info->plane[i].offset = offset;
2526 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2527 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2528 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2529
2530 intel_fb->rotated[i].pitch =
2531 rot_info->plane[i].height * tile_height;
2532
2533 /* how many tiles does this plane need */
2534 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2535 /*
2536 * If the plane isn't horizontally tile aligned,
2537 * we need one more tile.
2538 */
2539 if (x != 0)
2540 size++;
2541
2542 /* rotate the x/y offsets to match the GTT view */
2543 r.x1 = x;
2544 r.y1 = y;
2545 r.x2 = x + width;
2546 r.y2 = y + height;
2547 drm_rect_rotate(&r,
2548 rot_info->plane[i].width * tile_width,
2549 rot_info->plane[i].height * tile_height,
Robert Fossc2c446a2017-05-19 16:50:17 -04002550 DRM_MODE_ROTATE_270);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002551 x = r.x1;
2552 y = r.y1;
2553
2554 /* rotate the tile dimensions to match the GTT view */
2555 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2556 swap(tile_width, tile_height);
2557
2558 /*
2559 * We only keep the x/y offsets, so push all of the
2560 * gtt offset into the x/y offsets.
2561 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002562 intel_adjust_tile_offset(&x, &y,
2563 tile_width, tile_height,
2564 tile_size, pitch_tiles,
2565 gtt_offset_rotated * tile_size, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002566
2567 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2568
2569 /*
2570 * First pixel of the framebuffer from
2571 * the start of the rotated gtt mapping.
2572 */
2573 intel_fb->rotated[i].x = x;
2574 intel_fb->rotated[i].y = y;
2575 } else {
2576 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2577 x * cpp, tile_size);
2578 }
2579
2580 /* how many tiles in total needed in the bo */
2581 max_size = max(max_size, offset + size);
2582 }
2583
Ville Syrjälä4e050472018-09-12 21:04:43 +03002584 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2585 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2586 mul_u32_u32(max_size, tile_size), obj->base.size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002587 return -EINVAL;
2588 }
2589
2590 return 0;
2591}
2592
Damien Lespiaub35d63f2015-01-20 12:51:50 +00002593static int i9xx_format_to_fourcc(int format)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002594{
2595 switch (format) {
2596 case DISPPLANE_8BPP:
2597 return DRM_FORMAT_C8;
2598 case DISPPLANE_BGRX555:
2599 return DRM_FORMAT_XRGB1555;
2600 case DISPPLANE_BGRX565:
2601 return DRM_FORMAT_RGB565;
2602 default:
2603 case DISPPLANE_BGRX888:
2604 return DRM_FORMAT_XRGB8888;
2605 case DISPPLANE_RGBX888:
2606 return DRM_FORMAT_XBGR8888;
2607 case DISPPLANE_BGRX101010:
2608 return DRM_FORMAT_XRGB2101010;
2609 case DISPPLANE_RGBX101010:
2610 return DRM_FORMAT_XBGR2101010;
2611 }
2612}
2613
Mahesh Kumarddf34312018-04-09 09:11:03 +05302614int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002615{
2616 switch (format) {
2617 case PLANE_CTL_FORMAT_RGB_565:
2618 return DRM_FORMAT_RGB565;
Mahesh Kumarf34a2912018-04-09 09:11:02 +05302619 case PLANE_CTL_FORMAT_NV12:
2620 return DRM_FORMAT_NV12;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002621 default:
2622 case PLANE_CTL_FORMAT_XRGB_8888:
2623 if (rgb_order) {
2624 if (alpha)
2625 return DRM_FORMAT_ABGR8888;
2626 else
2627 return DRM_FORMAT_XBGR8888;
2628 } else {
2629 if (alpha)
2630 return DRM_FORMAT_ARGB8888;
2631 else
2632 return DRM_FORMAT_XRGB8888;
2633 }
2634 case PLANE_CTL_FORMAT_XRGB_2101010:
2635 if (rgb_order)
2636 return DRM_FORMAT_XBGR2101010;
2637 else
2638 return DRM_FORMAT_XRGB2101010;
2639 }
2640}
2641
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002642static bool
Daniel Vetterf6936e22015-03-26 12:17:05 +01002643intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2644 struct intel_initial_plane_config *plane_config)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002645{
2646 struct drm_device *dev = crtc->base.dev;
Paulo Zanoni3badb492015-09-23 12:52:23 -03002647 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002648 struct drm_i915_gem_object *obj = NULL;
2649 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
Damien Lespiau2d140302015-02-05 17:22:18 +00002650 struct drm_framebuffer *fb = &plane_config->fb->base;
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002651 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2652 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2653 PAGE_SIZE);
2654
2655 size_aligned -= base_aligned;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002656
Chris Wilsonff2652e2014-03-10 08:07:02 +00002657 if (plane_config->size == 0)
2658 return false;
2659
Paulo Zanoni3badb492015-09-23 12:52:23 -03002660 /* If the FB is too big, just don't use it since fbdev is not very
2661 * important and we should probably use that space with FBC or other
2662 * features. */
Matthew Auldb1ace602017-12-11 15:18:21 +00002663 if (size_aligned * 2 > dev_priv->stolen_usable_size)
Paulo Zanoni3badb492015-09-23 12:52:23 -03002664 return false;
2665
Imre Deak914a4fd2018-10-16 19:00:11 +03002666 switch (fb->modifier) {
2667 case DRM_FORMAT_MOD_LINEAR:
2668 case I915_FORMAT_MOD_X_TILED:
2669 case I915_FORMAT_MOD_Y_TILED:
2670 break;
2671 default:
2672 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2673 fb->modifier);
2674 return false;
2675 }
2676
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002677 mutex_lock(&dev->struct_mutex);
Tvrtko Ursulin187685c2016-12-01 14:16:36 +00002678 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002679 base_aligned,
2680 base_aligned,
2681 size_aligned);
Chris Wilson24dbf512017-02-15 10:59:18 +00002682 mutex_unlock(&dev->struct_mutex);
2683 if (!obj)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002684 return false;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002685
Imre Deak914a4fd2018-10-16 19:00:11 +03002686 switch (plane_config->tiling) {
2687 case I915_TILING_NONE:
2688 break;
2689 case I915_TILING_X:
2690 case I915_TILING_Y:
2691 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2692 break;
2693 default:
2694 MISSING_CASE(plane_config->tiling);
2695 return false;
2696 }
Jesse Barnes46f297f2014-03-07 08:57:48 -08002697
Ville Syrjälä438b74a2016-12-14 23:32:55 +02002698 mode_cmd.pixel_format = fb->format->format;
Damien Lespiau6bf129d2015-02-05 17:22:16 +00002699 mode_cmd.width = fb->width;
2700 mode_cmd.height = fb->height;
2701 mode_cmd.pitches[0] = fb->pitches[0];
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002702 mode_cmd.modifier[0] = fb->modifier;
Daniel Vetter18c52472015-02-10 17:16:09 +00002703 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002704
Chris Wilson24dbf512017-02-15 10:59:18 +00002705 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
Jesse Barnes46f297f2014-03-07 08:57:48 -08002706 DRM_DEBUG_KMS("intel fb init failed\n");
2707 goto out_unref_obj;
2708 }
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002709
Jesse Barnes484b41d2014-03-07 08:57:55 -08002710
Daniel Vetterf6936e22015-03-26 12:17:05 +01002711 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002712 return true;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002713
2714out_unref_obj:
Chris Wilsonf8c417c2016-07-20 13:31:53 +01002715 i915_gem_object_put(obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002716 return false;
2717}
2718
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002719static void
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002720intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2721 struct intel_plane_state *plane_state,
2722 bool visible)
2723{
2724 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2725
2726 plane_state->base.visible = visible;
2727
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002728 if (visible)
Ville Syrjälä40560e22018-06-26 22:47:11 +03002729 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002730 else
Ville Syrjälä40560e22018-06-26 22:47:11 +03002731 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002732}
2733
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002734static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2735{
2736 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2737 struct drm_plane *plane;
2738
2739 /*
2740 * Active_planes aliases if multiple "primary" or cursor planes
2741 * have been used on the same (or wrong) pipe. plane_mask uses
2742 * unique ids, hence we can use that to reconstruct active_planes.
2743 */
2744 crtc_state->active_planes = 0;
2745
2746 drm_for_each_plane_mask(plane, &dev_priv->drm,
2747 crtc_state->base.plane_mask)
2748 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2749}
2750
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002751static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2752 struct intel_plane *plane)
2753{
2754 struct intel_crtc_state *crtc_state =
2755 to_intel_crtc_state(crtc->base.state);
2756 struct intel_plane_state *plane_state =
2757 to_intel_plane_state(plane->base.state);
2758
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +03002759 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2760 plane->base.base.id, plane->base.name,
2761 crtc->base.base.id, crtc->base.name);
2762
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002763 intel_set_plane_visible(crtc_state, plane_state, false);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002764 fixup_active_planes(crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002765
2766 if (plane->id == PLANE_PRIMARY)
2767 intel_pre_disable_primary_noatomic(&crtc->base);
2768
2769 trace_intel_disable_plane(&plane->base, crtc);
2770 plane->disable_plane(plane, crtc);
2771}
2772
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002773static void
Daniel Vetterf6936e22015-03-26 12:17:05 +01002774intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2775 struct intel_initial_plane_config *plane_config)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002776{
2777 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002778 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002779 struct drm_crtc *c;
Matt Roper2ff8fde2014-07-08 07:50:07 -07002780 struct drm_i915_gem_object *obj;
Daniel Vetter88595ac2015-03-26 12:42:24 +01002781 struct drm_plane *primary = intel_crtc->base.primary;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002782 struct drm_plane_state *plane_state = primary->state;
Matt Roper200757f2015-12-03 11:37:36 -08002783 struct intel_plane *intel_plane = to_intel_plane(primary);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002784 struct intel_plane_state *intel_state =
2785 to_intel_plane_state(plane_state);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002786 struct drm_framebuffer *fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002787
Damien Lespiau2d140302015-02-05 17:22:18 +00002788 if (!plane_config->fb)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002789 return;
2790
Daniel Vetterf6936e22015-03-26 12:17:05 +01002791 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
Daniel Vetter88595ac2015-03-26 12:42:24 +01002792 fb = &plane_config->fb->base;
2793 goto valid_fb;
Damien Lespiauf55548b2015-02-05 18:30:20 +00002794 }
Jesse Barnes484b41d2014-03-07 08:57:55 -08002795
Damien Lespiau2d140302015-02-05 17:22:18 +00002796 kfree(plane_config->fb);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002797
2798 /*
2799 * Failed to alloc the obj, check to see if we should share
2800 * an fb with another CRTC instead
2801 */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +01002802 for_each_crtc(dev, c) {
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002803 struct intel_plane_state *state;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002804
2805 if (c == &intel_crtc->base)
2806 continue;
2807
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002808 if (!to_intel_crtc(c)->active)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002809 continue;
2810
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002811 state = to_intel_plane_state(c->primary->state);
2812 if (!state->vma)
Matt Roper2ff8fde2014-07-08 07:50:07 -07002813 continue;
2814
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002815 if (intel_plane_ggtt_offset(state) == plane_config->base) {
Ville Syrjälä8bc20f62018-03-22 17:22:59 +02002816 fb = state->base.fb;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302817 drm_framebuffer_get(fb);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002818 goto valid_fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002819 }
2820 }
Daniel Vetter88595ac2015-03-26 12:42:24 +01002821
Matt Roper200757f2015-12-03 11:37:36 -08002822 /*
2823 * We've failed to reconstruct the BIOS FB. Current display state
2824 * indicates that the primary plane is visible, but has a NULL FB,
2825 * which will lead to problems later if we don't fix it up. The
2826 * simplest solution is to just disable the primary plane now and
2827 * pretend the BIOS never had it enabled.
2828 */
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002829 intel_plane_disable_noatomic(intel_crtc, intel_plane);
Matt Roper200757f2015-12-03 11:37:36 -08002830
Daniel Vetter88595ac2015-03-26 12:42:24 +01002831 return;
2832
2833valid_fb:
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002834 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2835 intel_state->base.rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002836 intel_state->color_plane[0].stride =
2837 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2838
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002839 mutex_lock(&dev->struct_mutex);
2840 intel_state->vma =
Chris Wilson59354852018-02-20 13:42:06 +00002841 intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002842 &intel_state->view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002843 intel_plane_uses_fence(intel_state),
Chris Wilson59354852018-02-20 13:42:06 +00002844 &intel_state->flags);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002845 mutex_unlock(&dev->struct_mutex);
2846 if (IS_ERR(intel_state->vma)) {
2847 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2848 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2849
2850 intel_state->vma = NULL;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302851 drm_framebuffer_put(fb);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002852 return;
2853 }
2854
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -08002855 obj = intel_fb_obj(fb);
2856 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2857
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002858 plane_state->src_x = 0;
2859 plane_state->src_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002860 plane_state->src_w = fb->width << 16;
2861 plane_state->src_h = fb->height << 16;
2862
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002863 plane_state->crtc_x = 0;
2864 plane_state->crtc_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002865 plane_state->crtc_w = fb->width;
2866 plane_state->crtc_h = fb->height;
2867
Rob Clark1638d302016-11-05 11:08:08 -04002868 intel_state->base.src = drm_plane_state_src(plane_state);
2869 intel_state->base.dst = drm_plane_state_dest(plane_state);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002870
Chris Wilson3e510a82016-08-05 10:14:23 +01002871 if (i915_gem_object_is_tiled(obj))
Daniel Vetter88595ac2015-03-26 12:42:24 +01002872 dev_priv->preserve_bios_swizzle = true;
2873
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +03002874 plane_state->fb = fb;
2875 plane_state->crtc = &intel_crtc->base;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002876
Chris Wilsonfaf5bf02016-08-04 16:32:37 +01002877 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2878 &obj->frontbuffer_bits);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002879}
2880
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002881static int skl_max_plane_width(const struct drm_framebuffer *fb,
2882 int color_plane,
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002883 unsigned int rotation)
2884{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002885 int cpp = fb->format->cpp[color_plane];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002886
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002887 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002888 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002889 case I915_FORMAT_MOD_X_TILED:
2890 switch (cpp) {
2891 case 8:
2892 return 4096;
2893 case 4:
2894 case 2:
2895 case 1:
2896 return 8192;
2897 default:
2898 MISSING_CASE(cpp);
2899 break;
2900 }
2901 break;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002902 case I915_FORMAT_MOD_Y_TILED_CCS:
2903 case I915_FORMAT_MOD_Yf_TILED_CCS:
2904 /* FIXME AUX plane? */
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002905 case I915_FORMAT_MOD_Y_TILED:
2906 case I915_FORMAT_MOD_Yf_TILED:
2907 switch (cpp) {
2908 case 8:
2909 return 2048;
2910 case 4:
2911 return 4096;
2912 case 2:
2913 case 1:
2914 return 8192;
2915 default:
2916 MISSING_CASE(cpp);
2917 break;
2918 }
2919 break;
2920 default:
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002921 MISSING_CASE(fb->modifier);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002922 }
2923
2924 return 2048;
2925}
2926
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002927static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2928 int main_x, int main_y, u32 main_offset)
2929{
2930 const struct drm_framebuffer *fb = plane_state->base.fb;
2931 int hsub = fb->format->hsub;
2932 int vsub = fb->format->vsub;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002933 int aux_x = plane_state->color_plane[1].x;
2934 int aux_y = plane_state->color_plane[1].y;
2935 u32 aux_offset = plane_state->color_plane[1].offset;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002936 u32 alignment = intel_surf_alignment(fb, 1);
2937
2938 while (aux_offset >= main_offset && aux_y <= main_y) {
2939 int x, y;
2940
2941 if (aux_x == main_x && aux_y == main_y)
2942 break;
2943
2944 if (aux_offset == 0)
2945 break;
2946
2947 x = aux_x / hsub;
2948 y = aux_y / vsub;
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002949 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
2950 aux_offset, aux_offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002951 aux_x = x * hsub + aux_x % hsub;
2952 aux_y = y * vsub + aux_y % vsub;
2953 }
2954
2955 if (aux_x != main_x || aux_y != main_y)
2956 return false;
2957
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002958 plane_state->color_plane[1].offset = aux_offset;
2959 plane_state->color_plane[1].x = aux_x;
2960 plane_state->color_plane[1].y = aux_y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002961
2962 return true;
2963}
2964
Ville Syrjälä73266592018-09-07 18:24:11 +03002965static int skl_check_main_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002966{
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002967 const struct drm_framebuffer *fb = plane_state->base.fb;
2968 unsigned int rotation = plane_state->base.rotation;
Daniel Vettercc926382016-08-15 10:41:47 +02002969 int x = plane_state->base.src.x1 >> 16;
2970 int y = plane_state->base.src.y1 >> 16;
2971 int w = drm_rect_width(&plane_state->base.src) >> 16;
2972 int h = drm_rect_height(&plane_state->base.src) >> 16;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002973 int max_width = skl_max_plane_width(fb, 0, rotation);
2974 int max_height = 4096;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002975 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002976
2977 if (w > max_width || h > max_height) {
2978 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2979 w, h, max_width, max_height);
2980 return -EINVAL;
2981 }
2982
2983 intel_add_fb_offsets(&x, &y, plane_state, 0);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002984 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002985 alignment = intel_surf_alignment(fb, 0);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002986
2987 /*
Ville Syrjälä8d970652016-01-28 16:30:28 +02002988 * AUX surface offset is specified as the distance from the
2989 * main surface offset, and it must be non-negative. Make
2990 * sure that is what we will get.
2991 */
2992 if (offset > aux_offset)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002993 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
2994 offset, aux_offset & ~(alignment - 1));
Ville Syrjälä8d970652016-01-28 16:30:28 +02002995
2996 /*
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002997 * When using an X-tiled surface, the plane blows up
2998 * if the x offset + width exceed the stride.
2999 *
3000 * TODO: linear and Y-tiled seem fine, Yf untested,
3001 */
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003002 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
Ville Syrjälä353c8592016-12-14 23:30:57 +02003003 int cpp = fb->format->cpp[0];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003004
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003005 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003006 if (offset == 0) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003007 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003008 return -EINVAL;
3009 }
3010
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003011 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3012 offset, offset - alignment);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003013 }
3014 }
3015
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003016 /*
3017 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3018 * they match with the main surface x/y offsets.
3019 */
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003020 if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003021 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3022 if (offset == 0)
3023 break;
3024
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003025 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3026 offset, offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003027 }
3028
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003029 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003030 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3031 return -EINVAL;
3032 }
3033 }
3034
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003035 plane_state->color_plane[0].offset = offset;
3036 plane_state->color_plane[0].x = x;
3037 plane_state->color_plane[0].y = y;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003038
3039 return 0;
3040}
3041
Ville Syrjälä8d970652016-01-28 16:30:28 +02003042static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3043{
3044 const struct drm_framebuffer *fb = plane_state->base.fb;
3045 unsigned int rotation = plane_state->base.rotation;
3046 int max_width = skl_max_plane_width(fb, 1, rotation);
3047 int max_height = 4096;
Daniel Vettercc926382016-08-15 10:41:47 +02003048 int x = plane_state->base.src.x1 >> 17;
3049 int y = plane_state->base.src.y1 >> 17;
3050 int w = drm_rect_width(&plane_state->base.src) >> 17;
3051 int h = drm_rect_height(&plane_state->base.src) >> 17;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003052 u32 offset;
3053
3054 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003055 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä8d970652016-01-28 16:30:28 +02003056
3057 /* FIXME not quite sure how/if these apply to the chroma plane */
3058 if (w > max_width || h > max_height) {
3059 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3060 w, h, max_width, max_height);
3061 return -EINVAL;
3062 }
3063
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003064 plane_state->color_plane[1].offset = offset;
3065 plane_state->color_plane[1].x = x;
3066 plane_state->color_plane[1].y = y;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003067
3068 return 0;
3069}
3070
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003071static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3072{
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003073 const struct drm_framebuffer *fb = plane_state->base.fb;
3074 int src_x = plane_state->base.src.x1 >> 16;
3075 int src_y = plane_state->base.src.y1 >> 16;
3076 int hsub = fb->format->hsub;
3077 int vsub = fb->format->vsub;
3078 int x = src_x / hsub;
3079 int y = src_y / vsub;
3080 u32 offset;
3081
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003082 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003083 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003084
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003085 plane_state->color_plane[1].offset = offset;
3086 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3087 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003088
3089 return 0;
3090}
3091
Ville Syrjälä73266592018-09-07 18:24:11 +03003092int skl_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003093{
3094 const struct drm_framebuffer *fb = plane_state->base.fb;
3095 unsigned int rotation = plane_state->base.rotation;
3096 int ret;
3097
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003098 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003099 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3100 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3101
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003102 ret = intel_plane_check_stride(plane_state);
3103 if (ret)
3104 return ret;
3105
Ville Syrjäläa5e4c7d2016-11-07 22:20:54 +02003106 if (!plane_state->base.visible)
3107 return 0;
3108
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003109 /* Rotate src coordinates to match rotated GTT view */
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03003110 if (drm_rotation_90_or_270(rotation))
Daniel Vettercc926382016-08-15 10:41:47 +02003111 drm_rect_rotate(&plane_state->base.src,
Ville Syrjäläda064b42016-10-24 19:13:04 +03003112 fb->width << 16, fb->height << 16,
Robert Fossc2c446a2017-05-19 16:50:17 -04003113 DRM_MODE_ROTATE_270);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003114
Ville Syrjälä8d970652016-01-28 16:30:28 +02003115 /*
3116 * Handle the AUX surface first since
3117 * the main surface setup depends on it.
3118 */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003119 if (fb->format->format == DRM_FORMAT_NV12) {
Ville Syrjälä8d970652016-01-28 16:30:28 +02003120 ret = skl_check_nv12_aux_surface(plane_state);
3121 if (ret)
3122 return ret;
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003123 } else if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003124 ret = skl_check_ccs_aux_surface(plane_state);
3125 if (ret)
3126 return ret;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003127 } else {
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003128 plane_state->color_plane[1].offset = ~0xfff;
3129 plane_state->color_plane[1].x = 0;
3130 plane_state->color_plane[1].y = 0;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003131 }
3132
Ville Syrjälä73266592018-09-07 18:24:11 +03003133 ret = skl_check_main_surface(plane_state);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003134 if (ret)
3135 return ret;
3136
3137 return 0;
3138}
3139
Ville Syrjäläddd57132018-09-07 18:24:02 +03003140unsigned int
3141i9xx_plane_max_stride(struct intel_plane *plane,
3142 u32 pixel_format, u64 modifier,
3143 unsigned int rotation)
3144{
3145 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3146
3147 if (!HAS_GMCH_DISPLAY(dev_priv)) {
3148 return 32*1024;
3149 } else if (INTEL_GEN(dev_priv) >= 4) {
3150 if (modifier == I915_FORMAT_MOD_X_TILED)
3151 return 16*1024;
3152 else
3153 return 32*1024;
3154 } else if (INTEL_GEN(dev_priv) >= 3) {
3155 if (modifier == I915_FORMAT_MOD_X_TILED)
3156 return 8*1024;
3157 else
3158 return 16*1024;
3159 } else {
3160 if (plane->i9xx_plane == PLANE_C)
3161 return 4*1024;
3162 else
3163 return 8*1024;
3164 }
3165}
3166
Ville Syrjälä7145f602017-03-23 21:27:07 +02003167static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3168 const struct intel_plane_state *plane_state)
Jesse Barnes81255562010-08-02 12:07:50 -07003169{
Ville Syrjälä7145f602017-03-23 21:27:07 +02003170 struct drm_i915_private *dev_priv =
3171 to_i915(plane_state->base.plane->dev);
3172 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3173 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02003174 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003175 u32 dspcntr;
Ville Syrjäläc9ba6fa2014-08-27 17:48:41 +03003176
Ville Syrjälä7145f602017-03-23 21:27:07 +02003177 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003178
Ville Syrjälä6a4407a2017-03-23 21:27:08 +02003179 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3180 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
Ville Syrjälä7145f602017-03-23 21:27:07 +02003181 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003182
Ville Syrjälä6a4407a2017-03-23 21:27:08 +02003183 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3184 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003185
Ville Syrjäläc154d1e2018-01-30 22:38:02 +02003186 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjäläd509e282017-03-27 21:55:32 +03003187 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003188
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003189 switch (fb->format->format) {
Ville Syrjälä57779d02012-10-31 17:50:14 +02003190 case DRM_FORMAT_C8:
Jesse Barnes81255562010-08-02 12:07:50 -07003191 dspcntr |= DISPPLANE_8BPP;
3192 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003193 case DRM_FORMAT_XRGB1555:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003194 dspcntr |= DISPPLANE_BGRX555;
Jesse Barnes81255562010-08-02 12:07:50 -07003195 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003196 case DRM_FORMAT_RGB565:
3197 dspcntr |= DISPPLANE_BGRX565;
3198 break;
3199 case DRM_FORMAT_XRGB8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003200 dspcntr |= DISPPLANE_BGRX888;
3201 break;
3202 case DRM_FORMAT_XBGR8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003203 dspcntr |= DISPPLANE_RGBX888;
3204 break;
3205 case DRM_FORMAT_XRGB2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003206 dspcntr |= DISPPLANE_BGRX101010;
3207 break;
3208 case DRM_FORMAT_XBGR2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003209 dspcntr |= DISPPLANE_RGBX101010;
Jesse Barnes81255562010-08-02 12:07:50 -07003210 break;
3211 default:
Ville Syrjälä7145f602017-03-23 21:27:07 +02003212 MISSING_CASE(fb->format->format);
3213 return 0;
Jesse Barnes81255562010-08-02 12:07:50 -07003214 }
Ville Syrjälä57779d02012-10-31 17:50:14 +02003215
Ville Syrjälä72618eb2016-02-04 20:38:20 +02003216 if (INTEL_GEN(dev_priv) >= 4 &&
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003217 fb->modifier == I915_FORMAT_MOD_X_TILED)
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003218 dspcntr |= DISPPLANE_TILED;
Jesse Barnes81255562010-08-02 12:07:50 -07003219
Robert Fossc2c446a2017-05-19 16:50:17 -04003220 if (rotation & DRM_MODE_ROTATE_180)
Ville Syrjälädf0cd452016-11-14 18:53:59 +02003221 dspcntr |= DISPPLANE_ROTATE_180;
3222
Robert Fossc2c446a2017-05-19 16:50:17 -04003223 if (rotation & DRM_MODE_REFLECT_X)
Ville Syrjälä4ea7be22016-11-14 18:54:00 +02003224 dspcntr |= DISPPLANE_MIRROR;
3225
Ville Syrjälä7145f602017-03-23 21:27:07 +02003226 return dspcntr;
3227}
Ville Syrjäläde1aa622013-06-07 10:47:01 +03003228
Ville Syrjäläf9407ae2017-03-23 21:27:12 +02003229int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003230{
3231 struct drm_i915_private *dev_priv =
3232 to_i915(plane_state->base.plane->dev);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003233 const struct drm_framebuffer *fb = plane_state->base.fb;
3234 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003235 int src_x = plane_state->base.src.x1 >> 16;
3236 int src_y = plane_state->base.src.y1 >> 16;
3237 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003238 int ret;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003239
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003240 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003241 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3242
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003243 ret = intel_plane_check_stride(plane_state);
3244 if (ret)
3245 return ret;
3246
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003247 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
Jesse Barnes81255562010-08-02 12:07:50 -07003248
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003249 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003250 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3251 plane_state, 0);
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003252 else
3253 offset = 0;
Daniel Vettere506a0c2012-07-05 12:17:29 +02003254
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003255 /* HSW/BDW do this automagically in hardware */
3256 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003257 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3258 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3259
Robert Fossc2c446a2017-05-19 16:50:17 -04003260 if (rotation & DRM_MODE_ROTATE_180) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003261 src_x += src_w - 1;
3262 src_y += src_h - 1;
Robert Fossc2c446a2017-05-19 16:50:17 -04003263 } else if (rotation & DRM_MODE_REFLECT_X) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003264 src_x += src_w - 1;
3265 }
Sonika Jindal48404c12014-08-22 14:06:04 +05303266 }
3267
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003268 plane_state->color_plane[0].offset = offset;
3269 plane_state->color_plane[0].x = src_x;
3270 plane_state->color_plane[0].y = src_y;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003271
3272 return 0;
3273}
3274
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003275static int
3276i9xx_plane_check(struct intel_crtc_state *crtc_state,
3277 struct intel_plane_state *plane_state)
3278{
3279 int ret;
3280
Ville Syrjälä25721f82018-09-07 18:24:12 +03003281 ret = chv_plane_check_rotation(plane_state);
3282 if (ret)
3283 return ret;
3284
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003285 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3286 &crtc_state->base,
3287 DRM_PLANE_HELPER_NO_SCALING,
3288 DRM_PLANE_HELPER_NO_SCALING,
3289 false, true);
3290 if (ret)
3291 return ret;
3292
3293 if (!plane_state->base.visible)
3294 return 0;
3295
3296 ret = intel_plane_check_src_coordinates(plane_state);
3297 if (ret)
3298 return ret;
3299
3300 ret = i9xx_check_plane_surface(plane_state);
3301 if (ret)
3302 return ret;
3303
3304 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3305
3306 return 0;
3307}
3308
Ville Syrjäläed150302017-11-17 21:19:10 +02003309static void i9xx_update_plane(struct intel_plane *plane,
3310 const struct intel_crtc_state *crtc_state,
3311 const struct intel_plane_state *plane_state)
Ville Syrjälä7145f602017-03-23 21:27:07 +02003312{
Ville Syrjäläed150302017-11-17 21:19:10 +02003313 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläed150302017-11-17 21:19:10 +02003314 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003315 u32 linear_offset;
Ville Syrjäläa0864d52017-03-23 21:27:09 +02003316 u32 dspcntr = plane_state->ctl;
Ville Syrjäläed150302017-11-17 21:19:10 +02003317 i915_reg_t reg = DSPCNTR(i9xx_plane);
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003318 int x = plane_state->color_plane[0].x;
3319 int y = plane_state->color_plane[0].y;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003320 unsigned long irqflags;
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003321 u32 dspaddr_offset;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003322
Ville Syrjälä29490562016-01-20 18:02:50 +02003323 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03003324
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003325 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003326 dspaddr_offset = plane_state->color_plane[0].offset;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003327 else
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003328 dspaddr_offset = linear_offset;
Ville Syrjälä6687c902015-09-15 13:16:41 +03003329
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003330 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3331
Ville Syrjälä78587de2017-03-09 17:44:32 +02003332 if (INTEL_GEN(dev_priv) < 4) {
3333 /* pipesrc and dspsize control the size that is scaled from,
3334 * which should always be the user's requested size.
3335 */
Ville Syrjäläed150302017-11-17 21:19:10 +02003336 I915_WRITE_FW(DSPSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003337 ((crtc_state->pipe_src_h - 1) << 16) |
3338 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003339 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3340 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3341 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003342 ((crtc_state->pipe_src_h - 1) << 16) |
3343 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003344 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3345 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
Ville Syrjälä78587de2017-03-09 17:44:32 +02003346 }
3347
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003348 I915_WRITE_FW(reg, dspcntr);
Sonika Jindal48404c12014-08-22 14:06:04 +05303349
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003350 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003351 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjäläed150302017-11-17 21:19:10 +02003352 I915_WRITE_FW(DSPSURF(i9xx_plane),
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003353 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003354 dspaddr_offset);
Ville Syrjäläed150302017-11-17 21:19:10 +02003355 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003356 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjäläed150302017-11-17 21:19:10 +02003357 I915_WRITE_FW(DSPSURF(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003358 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003359 dspaddr_offset);
Ville Syrjäläed150302017-11-17 21:19:10 +02003360 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3361 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
Ville Syrjäläbfb81042016-11-07 22:20:57 +02003362 } else {
Ville Syrjäläed150302017-11-17 21:19:10 +02003363 I915_WRITE_FW(DSPADDR(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003364 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003365 dspaddr_offset);
Ville Syrjäläbfb81042016-11-07 22:20:57 +02003366 }
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003367
3368 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes17638cd2011-06-24 12:19:23 -07003369}
3370
Ville Syrjäläed150302017-11-17 21:19:10 +02003371static void i9xx_disable_plane(struct intel_plane *plane,
3372 struct intel_crtc *crtc)
Jesse Barnes17638cd2011-06-24 12:19:23 -07003373{
Ville Syrjäläed150302017-11-17 21:19:10 +02003374 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3375 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003376 unsigned long irqflags;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003377
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003378 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3379
Ville Syrjäläed150302017-11-17 21:19:10 +02003380 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3381 if (INTEL_GEN(dev_priv) >= 4)
3382 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003383 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003384 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003385
3386 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003387}
3388
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003389static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3390 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003391{
Ville Syrjäläed150302017-11-17 21:19:10 +02003392 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003393 enum intel_display_power_domain power_domain;
Ville Syrjäläed150302017-11-17 21:19:10 +02003394 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003395 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003396 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003397
3398 /*
3399 * Not 100% correct for planes that can move between pipes,
3400 * but that's only the case for gen2-4 which don't have any
3401 * display power wells.
3402 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003403 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003404 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3405 return false;
3406
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003407 val = I915_READ(DSPCNTR(i9xx_plane));
3408
3409 ret = val & DISPLAY_PLANE_ENABLE;
3410
3411 if (INTEL_GEN(dev_priv) >= 5)
3412 *pipe = plane->pipe;
3413 else
3414 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3415 DISPPLANE_SEL_PIPE_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003416
3417 intel_display_power_put(dev_priv, power_domain);
3418
3419 return ret;
3420}
3421
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003422static u32
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003423intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
Damien Lespiaub3218032015-02-27 11:15:18 +00003424{
Ben Widawsky2f075562017-03-24 14:29:48 -07003425 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02003426 return 64;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003427 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003428 return intel_tile_width_bytes(fb, color_plane);
Damien Lespiaub3218032015-02-27 11:15:18 +00003429}
3430
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003431static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3432{
3433 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003434 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003435
3436 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3437 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3438 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003439}
3440
Chandra Kondurua1b22782015-04-07 15:28:45 -07003441/*
3442 * This function detaches (aka. unbinds) unused scalers in hardware
3443 */
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003444static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
Chandra Kondurua1b22782015-04-07 15:28:45 -07003445{
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003446 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3447 const struct intel_crtc_scaler_state *scaler_state =
3448 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07003449 int i;
3450
Chandra Kondurua1b22782015-04-07 15:28:45 -07003451 /* loop through and disable scalers that aren't in use */
3452 for (i = 0; i < intel_crtc->num_scalers; i++) {
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003453 if (!scaler_state->scalers[i].in_use)
3454 skl_detach_scaler(intel_crtc, i);
Chandra Kondurua1b22782015-04-07 15:28:45 -07003455 }
3456}
3457
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003458u32 skl_plane_stride(const struct intel_plane_state *plane_state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003459 int color_plane)
Ville Syrjäläd2196772016-01-28 18:33:11 +02003460{
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003461 const struct drm_framebuffer *fb = plane_state->base.fb;
3462 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003463 u32 stride = plane_state->color_plane[color_plane].stride;
Ville Syrjälä1b500532017-03-07 21:42:08 +02003464
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003465 if (color_plane >= fb->format->num_planes)
Ville Syrjälä1b500532017-03-07 21:42:08 +02003466 return 0;
3467
Ville Syrjäläd2196772016-01-28 18:33:11 +02003468 /*
3469 * The stride is either expressed as a multiple of 64 bytes chunks for
3470 * linear buffers or in number of tiles for tiled buffers.
3471 */
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003472 if (drm_rotation_90_or_270(rotation))
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003473 stride /= intel_tile_height(fb, color_plane);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003474 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003475 stride /= intel_fb_stride_alignment(fb, color_plane);
Ville Syrjäläd2196772016-01-28 18:33:11 +02003476
3477 return stride;
3478}
3479
Ville Syrjälä2e881262017-03-17 23:17:56 +02003480static u32 skl_plane_ctl_format(uint32_t pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -07003481{
Chandra Konduru6156a452015-04-27 13:48:39 -07003482 switch (pixel_format) {
Damien Lespiaud161cf72015-05-12 16:13:17 +01003483 case DRM_FORMAT_C8:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003484 return PLANE_CTL_FORMAT_INDEXED;
Chandra Konduru6156a452015-04-27 13:48:39 -07003485 case DRM_FORMAT_RGB565:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003486 return PLANE_CTL_FORMAT_RGB_565;
Chandra Konduru6156a452015-04-27 13:48:39 -07003487 case DRM_FORMAT_XBGR8888:
James Ausmus4036c782017-11-13 10:11:28 -08003488 case DRM_FORMAT_ABGR8888:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003489 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
Chandra Konduru6156a452015-04-27 13:48:39 -07003490 case DRM_FORMAT_XRGB8888:
Chandra Konduru6156a452015-04-27 13:48:39 -07003491 case DRM_FORMAT_ARGB8888:
James Ausmus4036c782017-11-13 10:11:28 -08003492 return PLANE_CTL_FORMAT_XRGB_8888;
Chandra Konduru6156a452015-04-27 13:48:39 -07003493 case DRM_FORMAT_XRGB2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003494 return PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003495 case DRM_FORMAT_XBGR2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003496 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003497 case DRM_FORMAT_YUYV:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003498 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
Chandra Konduru6156a452015-04-27 13:48:39 -07003499 case DRM_FORMAT_YVYU:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003500 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
Chandra Konduru6156a452015-04-27 13:48:39 -07003501 case DRM_FORMAT_UYVY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003502 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
Chandra Konduru6156a452015-04-27 13:48:39 -07003503 case DRM_FORMAT_VYUY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003504 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
Chandra Konduru77224cd2018-04-09 09:11:13 +05303505 case DRM_FORMAT_NV12:
3506 return PLANE_CTL_FORMAT_NV12;
Chandra Konduru6156a452015-04-27 13:48:39 -07003507 default:
Damien Lespiau4249eee2015-05-12 16:13:16 +01003508 MISSING_CASE(pixel_format);
Chandra Konduru6156a452015-04-27 13:48:39 -07003509 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003510
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003511 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003512}
3513
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003514static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003515{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003516 if (!plane_state->base.fb->format->has_alpha)
3517 return PLANE_CTL_ALPHA_DISABLE;
3518
3519 switch (plane_state->base.pixel_blend_mode) {
3520 case DRM_MODE_BLEND_PIXEL_NONE:
3521 return PLANE_CTL_ALPHA_DISABLE;
3522 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003523 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003524 case DRM_MODE_BLEND_COVERAGE:
3525 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003526 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003527 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003528 return PLANE_CTL_ALPHA_DISABLE;
3529 }
3530}
3531
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003532static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003533{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003534 if (!plane_state->base.fb->format->has_alpha)
3535 return PLANE_COLOR_ALPHA_DISABLE;
3536
3537 switch (plane_state->base.pixel_blend_mode) {
3538 case DRM_MODE_BLEND_PIXEL_NONE:
3539 return PLANE_COLOR_ALPHA_DISABLE;
3540 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003541 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003542 case DRM_MODE_BLEND_COVERAGE:
3543 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003544 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003545 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003546 return PLANE_COLOR_ALPHA_DISABLE;
3547 }
3548}
3549
Ville Syrjälä2e881262017-03-17 23:17:56 +02003550static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
Chandra Konduru6156a452015-04-27 13:48:39 -07003551{
Chandra Konduru6156a452015-04-27 13:48:39 -07003552 switch (fb_modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07003553 case DRM_FORMAT_MOD_LINEAR:
Chandra Konduru6156a452015-04-27 13:48:39 -07003554 break;
3555 case I915_FORMAT_MOD_X_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003556 return PLANE_CTL_TILED_X;
Chandra Konduru6156a452015-04-27 13:48:39 -07003557 case I915_FORMAT_MOD_Y_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003558 return PLANE_CTL_TILED_Y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003559 case I915_FORMAT_MOD_Y_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003560 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003561 case I915_FORMAT_MOD_Yf_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003562 return PLANE_CTL_TILED_YF;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003563 case I915_FORMAT_MOD_Yf_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003564 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003565 default:
3566 MISSING_CASE(fb_modifier);
3567 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003568
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003569 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003570}
3571
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003572static u32 skl_plane_ctl_rotate(unsigned int rotate)
Chandra Konduru6156a452015-04-27 13:48:39 -07003573{
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003574 switch (rotate) {
Robert Fossc2c446a2017-05-19 16:50:17 -04003575 case DRM_MODE_ROTATE_0:
Chandra Konduru6156a452015-04-27 13:48:39 -07003576 break;
Sonika Jindal1e8df162015-05-20 13:40:48 +05303577 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003578 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
Sonika Jindal1e8df162015-05-20 13:40:48 +05303579 * while i915 HW rotation is clockwise, thats why this swapping.
3580 */
Robert Fossc2c446a2017-05-19 16:50:17 -04003581 case DRM_MODE_ROTATE_90:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303582 return PLANE_CTL_ROTATE_270;
Robert Fossc2c446a2017-05-19 16:50:17 -04003583 case DRM_MODE_ROTATE_180:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003584 return PLANE_CTL_ROTATE_180;
Robert Fossc2c446a2017-05-19 16:50:17 -04003585 case DRM_MODE_ROTATE_270:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303586 return PLANE_CTL_ROTATE_90;
Chandra Konduru6156a452015-04-27 13:48:39 -07003587 default:
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003588 MISSING_CASE(rotate);
3589 }
3590
3591 return 0;
3592}
3593
3594static u32 cnl_plane_ctl_flip(unsigned int reflect)
3595{
3596 switch (reflect) {
3597 case 0:
3598 break;
3599 case DRM_MODE_REFLECT_X:
3600 return PLANE_CTL_FLIP_HORIZONTAL;
3601 case DRM_MODE_REFLECT_Y:
3602 default:
3603 MISSING_CASE(reflect);
Chandra Konduru6156a452015-04-27 13:48:39 -07003604 }
3605
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003606 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003607}
3608
Ville Syrjälä2e881262017-03-17 23:17:56 +02003609u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3610 const struct intel_plane_state *plane_state)
Damien Lespiau70d21f02013-07-03 21:06:04 +01003611{
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003612 struct drm_i915_private *dev_priv =
3613 to_i915(plane_state->base.plane->dev);
3614 const struct drm_framebuffer *fb = plane_state->base.fb;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003615 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä2e881262017-03-17 23:17:56 +02003616 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003617 u32 plane_ctl;
Damien Lespiau70d21f02013-07-03 21:06:04 +01003618
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003619 plane_ctl = PLANE_CTL_ENABLE;
3620
James Ausmus4036c782017-11-13 10:11:28 -08003621 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003622 plane_ctl |= skl_plane_ctl_alpha(plane_state);
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003623 plane_ctl |=
3624 PLANE_CTL_PIPE_GAMMA_ENABLE |
3625 PLANE_CTL_PIPE_CSC_ENABLE |
3626 PLANE_CTL_PLANE_GAMMA_DISABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003627
3628 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3629 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003630
3631 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3632 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003633 }
Damien Lespiau70d21f02013-07-03 21:06:04 +01003634
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003635 plane_ctl |= skl_plane_ctl_format(fb->format->format);
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003636 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003637 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3638
3639 if (INTEL_GEN(dev_priv) >= 10)
3640 plane_ctl |= cnl_plane_ctl_flip(rotation &
3641 DRM_MODE_REFLECT_MASK);
Damien Lespiau70d21f02013-07-03 21:06:04 +01003642
Ville Syrjälä2e881262017-03-17 23:17:56 +02003643 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3644 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3645 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3646 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3647
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003648 return plane_ctl;
3649}
3650
James Ausmus4036c782017-11-13 10:11:28 -08003651u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3652 const struct intel_plane_state *plane_state)
3653{
James Ausmus077ef1f2018-03-28 14:57:56 -07003654 struct drm_i915_private *dev_priv =
3655 to_i915(plane_state->base.plane->dev);
James Ausmus4036c782017-11-13 10:11:28 -08003656 const struct drm_framebuffer *fb = plane_state->base.fb;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303657 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
James Ausmus4036c782017-11-13 10:11:28 -08003658 u32 plane_color_ctl = 0;
3659
James Ausmus077ef1f2018-03-28 14:57:56 -07003660 if (INTEL_GEN(dev_priv) < 11) {
3661 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3662 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3663 }
James Ausmus4036c782017-11-13 10:11:28 -08003664 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003665 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
James Ausmus4036c782017-11-13 10:11:28 -08003666
Uma Shankarbfe60a02018-11-02 00:40:20 +05303667 if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) {
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003668 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3669 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3670 else
3671 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003672
3673 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3674 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303675 } else if (fb->format->is_yuv) {
3676 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003677 }
Ville Syrjälä012d79e2018-05-21 21:56:12 +03003678
James Ausmus4036c782017-11-13 10:11:28 -08003679 return plane_color_ctl;
3680}
3681
Maarten Lankhorst73974892016-08-05 23:28:27 +03003682static int
3683__intel_display_resume(struct drm_device *dev,
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003684 struct drm_atomic_state *state,
3685 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorst73974892016-08-05 23:28:27 +03003686{
3687 struct drm_crtc_state *crtc_state;
3688 struct drm_crtc *crtc;
3689 int i, ret;
3690
Ville Syrjäläaecd36b2017-06-01 17:36:13 +03003691 intel_modeset_setup_hw_state(dev, ctx);
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00003692 i915_redisable_vga(to_i915(dev));
Maarten Lankhorst73974892016-08-05 23:28:27 +03003693
3694 if (!state)
3695 return 0;
3696
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01003697 /*
3698 * We've duplicated the state, pointers to the old state are invalid.
3699 *
3700 * Don't attempt to use the old state until we commit the duplicated state.
3701 */
3702 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst73974892016-08-05 23:28:27 +03003703 /*
3704 * Force recalculation even if we restore
3705 * current state. With fast modeset this may not result
3706 * in a modeset when the state is compatible.
3707 */
3708 crtc_state->mode_changed = true;
3709 }
3710
3711 /* ignore any reset values/BIOS leftovers in the WM registers */
Ville Syrjälä602ae832017-03-02 19:15:02 +02003712 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3713 to_intel_atomic_state(state)->skip_intermediate_wm = true;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003714
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003715 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003716
3717 WARN_ON(ret == -EDEADLK);
3718 return ret;
3719}
3720
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003721static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3722{
Ville Syrjäläae981042016-08-05 23:28:30 +03003723 return intel_has_gpu_reset(dev_priv) &&
3724 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003725}
3726
Chris Wilsonc0336662016-05-06 15:40:21 +01003727void intel_prepare_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003728{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003729 struct drm_device *dev = &dev_priv->drm;
3730 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3731 struct drm_atomic_state *state;
3732 int ret;
3733
Daniel Vetterce87ea12017-07-19 14:54:55 +02003734 /* reset doesn't touch the display */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003735 if (!i915_modparams.force_reset_modeset_test &&
Daniel Vetterce87ea12017-07-19 14:54:55 +02003736 !gpu_reset_clobbers_display(dev_priv))
3737 return;
3738
Daniel Vetter9db529a2017-08-08 10:08:28 +02003739 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3740 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3741 wake_up_all(&dev_priv->gpu_error.wait_queue);
3742
3743 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3744 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3745 i915_gem_set_wedged(dev_priv);
3746 }
Daniel Vetter97154ec2017-08-08 10:08:26 +02003747
Maarten Lankhorst73974892016-08-05 23:28:27 +03003748 /*
3749 * Need mode_config.mutex so that we don't
3750 * trample ongoing ->detect() and whatnot.
3751 */
3752 mutex_lock(&dev->mode_config.mutex);
3753 drm_modeset_acquire_init(ctx, 0);
3754 while (1) {
3755 ret = drm_modeset_lock_all_ctx(dev, ctx);
3756 if (ret != -EDEADLK)
3757 break;
3758
3759 drm_modeset_backoff(ctx);
3760 }
Ville Syrjäläf98ce922014-11-21 21:54:30 +02003761 /*
3762 * Disabling the crtcs gracefully seems nicer. Also the
3763 * g33 docs say we should at least disable all the planes.
3764 */
Maarten Lankhorst73974892016-08-05 23:28:27 +03003765 state = drm_atomic_helper_duplicate_state(dev, ctx);
3766 if (IS_ERR(state)) {
3767 ret = PTR_ERR(state);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003768 DRM_ERROR("Duplicating state failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003769 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003770 }
3771
3772 ret = drm_atomic_helper_disable_all(dev, ctx);
3773 if (ret) {
3774 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003775 drm_atomic_state_put(state);
3776 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003777 }
3778
3779 dev_priv->modeset_restore_state = state;
3780 state->acquire_ctx = ctx;
Ville Syrjälä75147472014-11-24 18:28:11 +02003781}
3782
Chris Wilsonc0336662016-05-06 15:40:21 +01003783void intel_finish_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003784{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003785 struct drm_device *dev = &dev_priv->drm;
3786 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
Chris Wilson40da1d32018-04-05 13:37:14 +01003787 struct drm_atomic_state *state;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003788 int ret;
3789
Daniel Vetterce87ea12017-07-19 14:54:55 +02003790 /* reset doesn't touch the display */
Chris Wilson40da1d32018-04-05 13:37:14 +01003791 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
Daniel Vetterce87ea12017-07-19 14:54:55 +02003792 return;
3793
Chris Wilson40da1d32018-04-05 13:37:14 +01003794 state = fetch_and_zero(&dev_priv->modeset_restore_state);
Daniel Vetterce87ea12017-07-19 14:54:55 +02003795 if (!state)
3796 goto unlock;
3797
Ville Syrjälä75147472014-11-24 18:28:11 +02003798 /* reset doesn't touch the display */
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003799 if (!gpu_reset_clobbers_display(dev_priv)) {
Daniel Vetterce87ea12017-07-19 14:54:55 +02003800 /* for testing only restore the display */
3801 ret = __intel_display_resume(dev, state, ctx);
Chris Wilson942d5d02017-08-28 11:46:04 +01003802 if (ret)
3803 DRM_ERROR("Restoring old state failed with %i\n", ret);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003804 } else {
3805 /*
3806 * The display has been reset as well,
3807 * so need a full re-initialization.
3808 */
3809 intel_runtime_pm_disable_interrupts(dev_priv);
3810 intel_runtime_pm_enable_interrupts(dev_priv);
3811
Imre Deak51f59202016-09-14 13:04:13 +03003812 intel_pps_unlock_regs_wa(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003813 intel_modeset_init_hw(dev);
Ville Syrjäläf72b84c2017-11-08 15:35:55 +02003814 intel_init_clock_gating(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003815
3816 spin_lock_irq(&dev_priv->irq_lock);
3817 if (dev_priv->display.hpd_irq_setup)
3818 dev_priv->display.hpd_irq_setup(dev_priv);
3819 spin_unlock_irq(&dev_priv->irq_lock);
3820
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003821 ret = __intel_display_resume(dev, state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003822 if (ret)
3823 DRM_ERROR("Restoring old state failed with %i\n", ret);
3824
3825 intel_hpd_init(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003826 }
3827
Daniel Vetterce87ea12017-07-19 14:54:55 +02003828 drm_atomic_state_put(state);
3829unlock:
Maarten Lankhorst73974892016-08-05 23:28:27 +03003830 drm_modeset_drop_locks(ctx);
3831 drm_modeset_acquire_fini(ctx);
3832 mutex_unlock(&dev->mode_config.mutex);
Daniel Vetter9db529a2017-08-08 10:08:28 +02003833
3834 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
Ville Syrjälä75147472014-11-24 18:28:11 +02003835}
3836
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003837static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3838 const struct intel_crtc_state *new_crtc_state)
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003839{
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003840 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003841 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003842
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003843 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003844 crtc->base.mode = new_crtc_state->base.mode;
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003845
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003846 /*
3847 * Update pipe size and adjust fitter if needed: the reason for this is
3848 * that in compute_mode_changes we check the native mode (not the pfit
3849 * mode) to see if we can flip rather than do a full mode set. In the
3850 * fastboot case, we'll flip, but if we don't update the pipesrc and
3851 * pfit state, we'll end up with a big fb scanned out into the wrong
3852 * sized surface.
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003853 */
3854
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003855 I915_WRITE(PIPESRC(crtc->pipe),
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003856 ((new_crtc_state->pipe_src_w - 1) << 16) |
3857 (new_crtc_state->pipe_src_h - 1));
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003858
3859 /* on skylake this is done by detaching scalers */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003860 if (INTEL_GEN(dev_priv) >= 9) {
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003861 skl_detach_scalers(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003862
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003863 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003864 skylake_pfit_enable(new_crtc_state);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003865 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003866 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003867 ironlake_pfit_enable(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003868 else if (old_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003869 ironlake_pfit_disable(old_crtc_state);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003870 }
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003871}
3872
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003873static void intel_fdi_normal_train(struct intel_crtc *crtc)
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003874{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003875 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003876 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003877 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003878 i915_reg_t reg;
3879 u32 temp;
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003880
3881 /* enable normal train */
3882 reg = FDI_TX_CTL(pipe);
3883 temp = I915_READ(reg);
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003884 if (IS_IVYBRIDGE(dev_priv)) {
Jesse Barnes357555c2011-04-28 15:09:55 -07003885 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3886 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
Keith Packard61e499b2011-05-17 16:13:52 -07003887 } else {
3888 temp &= ~FDI_LINK_TRAIN_NONE;
3889 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
Jesse Barnes357555c2011-04-28 15:09:55 -07003890 }
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003891 I915_WRITE(reg, temp);
3892
3893 reg = FDI_RX_CTL(pipe);
3894 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003895 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003896 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3897 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3898 } else {
3899 temp &= ~FDI_LINK_TRAIN_NONE;
3900 temp |= FDI_LINK_TRAIN_NONE;
3901 }
3902 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3903
3904 /* wait one idle pattern time */
3905 POSTING_READ(reg);
3906 udelay(1000);
Jesse Barnes357555c2011-04-28 15:09:55 -07003907
3908 /* IVB wants error correction enabled */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003909 if (IS_IVYBRIDGE(dev_priv))
Jesse Barnes357555c2011-04-28 15:09:55 -07003910 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3911 FDI_FE_ERRC_ENABLE);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003912}
3913
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003914/* The FDI link training functions for ILK/Ibexpeak. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02003915static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3916 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003917{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003918 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003919 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003920 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003921 i915_reg_t reg;
3922 u32 temp, tries;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003923
Ville Syrjälä1c8562f2014-04-25 22:12:07 +03003924 /* FDI needs bits from pipe first */
Jesse Barnes0fc932b2011-01-04 15:09:37 -08003925 assert_pipe_enabled(dev_priv, pipe);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08003926
Adam Jacksone1a44742010-06-25 15:32:14 -04003927 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3928 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01003929 reg = FDI_RX_IMR(pipe);
3930 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04003931 temp &= ~FDI_RX_SYMBOL_LOCK;
3932 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01003933 I915_WRITE(reg, temp);
3934 I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04003935 udelay(150);
3936
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003937 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01003938 reg = FDI_TX_CTL(pipe);
3939 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02003940 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02003941 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003942 temp &= ~FDI_LINK_TRAIN_NONE;
3943 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01003944 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003945
Chris Wilson5eddb702010-09-11 13:48:45 +01003946 reg = FDI_RX_CTL(pipe);
3947 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003948 temp &= ~FDI_LINK_TRAIN_NONE;
3949 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01003950 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3951
3952 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003953 udelay(150);
3954
Jesse Barnes5b2adf82010-10-07 16:01:15 -07003955 /* Ironlake workaround, enable clock pointer after FDI enable*/
Daniel Vetter8f5718a2012-10-31 22:52:28 +01003956 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3957 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3958 FDI_RX_PHASE_SYNC_POINTER_EN);
Jesse Barnes5b2adf82010-10-07 16:01:15 -07003959
Chris Wilson5eddb702010-09-11 13:48:45 +01003960 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04003961 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01003962 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003963 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3964
3965 if ((temp & FDI_RX_BIT_LOCK)) {
3966 DRM_DEBUG_KMS("FDI train 1 done.\n");
Chris Wilson5eddb702010-09-11 13:48:45 +01003967 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003968 break;
3969 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003970 }
Adam Jacksone1a44742010-06-25 15:32:14 -04003971 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01003972 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003973
3974 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01003975 reg = FDI_TX_CTL(pipe);
3976 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003977 temp &= ~FDI_LINK_TRAIN_NONE;
3978 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01003979 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003980
Chris Wilson5eddb702010-09-11 13:48:45 +01003981 reg = FDI_RX_CTL(pipe);
3982 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003983 temp &= ~FDI_LINK_TRAIN_NONE;
3984 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01003985 I915_WRITE(reg, temp);
3986
3987 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003988 udelay(150);
3989
Chris Wilson5eddb702010-09-11 13:48:45 +01003990 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04003991 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01003992 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003993 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3994
3995 if (temp & FDI_RX_SYMBOL_LOCK) {
Chris Wilson5eddb702010-09-11 13:48:45 +01003996 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003997 DRM_DEBUG_KMS("FDI train 2 done.\n");
3998 break;
3999 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004000 }
Adam Jacksone1a44742010-06-25 15:32:14 -04004001 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01004002 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004003
4004 DRM_DEBUG_KMS("FDI train done\n");
Jesse Barnes5c5313c2010-10-07 16:01:11 -07004005
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004006}
4007
Akshay Joshi0206e352011-08-16 15:34:10 -04004008static const int snb_b_fdi_train_param[] = {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004009 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4010 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4011 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4012 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4013};
4014
4015/* The FDI link training functions for SNB/Cougarpoint. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004016static void gen6_fdi_link_train(struct intel_crtc *crtc,
4017 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004018{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004019 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004020 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004021 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004022 i915_reg_t reg;
4023 u32 temp, i, retry;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004024
Adam Jacksone1a44742010-06-25 15:32:14 -04004025 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4026 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01004027 reg = FDI_RX_IMR(pipe);
4028 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004029 temp &= ~FDI_RX_SYMBOL_LOCK;
4030 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01004031 I915_WRITE(reg, temp);
4032
4033 POSTING_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004034 udelay(150);
4035
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004036 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01004037 reg = FDI_TX_CTL(pipe);
4038 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004039 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004040 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004041 temp &= ~FDI_LINK_TRAIN_NONE;
4042 temp |= FDI_LINK_TRAIN_PATTERN_1;
4043 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4044 /* SNB-B */
4045 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
Chris Wilson5eddb702010-09-11 13:48:45 +01004046 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004047
Daniel Vetterd74cf322012-10-26 10:58:13 +02004048 I915_WRITE(FDI_RX_MISC(pipe),
4049 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4050
Chris Wilson5eddb702010-09-11 13:48:45 +01004051 reg = FDI_RX_CTL(pipe);
4052 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004053 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004054 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4055 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4056 } else {
4057 temp &= ~FDI_LINK_TRAIN_NONE;
4058 temp |= FDI_LINK_TRAIN_PATTERN_1;
4059 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004060 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4061
4062 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004063 udelay(150);
4064
Akshay Joshi0206e352011-08-16 15:34:10 -04004065 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004066 reg = FDI_TX_CTL(pipe);
4067 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004068 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4069 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004070 I915_WRITE(reg, temp);
4071
4072 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004073 udelay(500);
4074
Sean Paulfa37d392012-03-02 12:53:39 -05004075 for (retry = 0; retry < 5; retry++) {
4076 reg = FDI_RX_IIR(pipe);
4077 temp = I915_READ(reg);
4078 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4079 if (temp & FDI_RX_BIT_LOCK) {
4080 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4081 DRM_DEBUG_KMS("FDI train 1 done.\n");
4082 break;
4083 }
4084 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004085 }
Sean Paulfa37d392012-03-02 12:53:39 -05004086 if (retry < 5)
4087 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004088 }
4089 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004090 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004091
4092 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004093 reg = FDI_TX_CTL(pipe);
4094 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004095 temp &= ~FDI_LINK_TRAIN_NONE;
4096 temp |= FDI_LINK_TRAIN_PATTERN_2;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004097 if (IS_GEN6(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004098 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4099 /* SNB-B */
4100 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4101 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004102 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004103
Chris Wilson5eddb702010-09-11 13:48:45 +01004104 reg = FDI_RX_CTL(pipe);
4105 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004106 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004107 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4108 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4109 } else {
4110 temp &= ~FDI_LINK_TRAIN_NONE;
4111 temp |= FDI_LINK_TRAIN_PATTERN_2;
4112 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004113 I915_WRITE(reg, temp);
4114
4115 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004116 udelay(150);
4117
Akshay Joshi0206e352011-08-16 15:34:10 -04004118 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004119 reg = FDI_TX_CTL(pipe);
4120 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004121 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4122 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004123 I915_WRITE(reg, temp);
4124
4125 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004126 udelay(500);
4127
Sean Paulfa37d392012-03-02 12:53:39 -05004128 for (retry = 0; retry < 5; retry++) {
4129 reg = FDI_RX_IIR(pipe);
4130 temp = I915_READ(reg);
4131 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4132 if (temp & FDI_RX_SYMBOL_LOCK) {
4133 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4134 DRM_DEBUG_KMS("FDI train 2 done.\n");
4135 break;
4136 }
4137 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004138 }
Sean Paulfa37d392012-03-02 12:53:39 -05004139 if (retry < 5)
4140 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004141 }
4142 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004143 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004144
4145 DRM_DEBUG_KMS("FDI train done.\n");
4146}
4147
Jesse Barnes357555c2011-04-28 15:09:55 -07004148/* Manual link training for Ivy Bridge A0 parts */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004149static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4150 const struct intel_crtc_state *crtc_state)
Jesse Barnes357555c2011-04-28 15:09:55 -07004151{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004152 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004153 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004154 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004155 i915_reg_t reg;
4156 u32 temp, i, j;
Jesse Barnes357555c2011-04-28 15:09:55 -07004157
4158 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4159 for train result */
4160 reg = FDI_RX_IMR(pipe);
4161 temp = I915_READ(reg);
4162 temp &= ~FDI_RX_SYMBOL_LOCK;
4163 temp &= ~FDI_RX_BIT_LOCK;
4164 I915_WRITE(reg, temp);
4165
4166 POSTING_READ(reg);
4167 udelay(150);
4168
Daniel Vetter01a415f2012-10-27 15:58:40 +02004169 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4170 I915_READ(FDI_RX_IIR(pipe)));
4171
Jesse Barnes139ccd32013-08-19 11:04:55 -07004172 /* Try each vswing and preemphasis setting twice before moving on */
4173 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4174 /* disable first in case we need to retry */
Jesse Barnes357555c2011-04-28 15:09:55 -07004175 reg = FDI_TX_CTL(pipe);
4176 temp = I915_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004177 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4178 temp &= ~FDI_TX_ENABLE;
4179 I915_WRITE(reg, temp);
4180
4181 reg = FDI_RX_CTL(pipe);
4182 temp = I915_READ(reg);
4183 temp &= ~FDI_LINK_TRAIN_AUTO;
4184 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4185 temp &= ~FDI_RX_ENABLE;
4186 I915_WRITE(reg, temp);
4187
4188 /* enable CPU FDI TX and PCH FDI RX */
4189 reg = FDI_TX_CTL(pipe);
4190 temp = I915_READ(reg);
4191 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004192 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004193 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
Jesse Barnes357555c2011-04-28 15:09:55 -07004194 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
Jesse Barnes139ccd32013-08-19 11:04:55 -07004195 temp |= snb_b_fdi_train_param[j/2];
4196 temp |= FDI_COMPOSITE_SYNC;
4197 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4198
4199 I915_WRITE(FDI_RX_MISC(pipe),
4200 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4201
4202 reg = FDI_RX_CTL(pipe);
4203 temp = I915_READ(reg);
4204 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4205 temp |= FDI_COMPOSITE_SYNC;
4206 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4207
4208 POSTING_READ(reg);
4209 udelay(1); /* should be 0.5us */
4210
4211 for (i = 0; i < 4; i++) {
4212 reg = FDI_RX_IIR(pipe);
4213 temp = I915_READ(reg);
4214 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4215
4216 if (temp & FDI_RX_BIT_LOCK ||
4217 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4218 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4219 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4220 i);
4221 break;
4222 }
4223 udelay(1); /* should be 0.5us */
4224 }
4225 if (i == 4) {
4226 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4227 continue;
4228 }
4229
4230 /* Train 2 */
4231 reg = FDI_TX_CTL(pipe);
4232 temp = I915_READ(reg);
4233 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4234 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4235 I915_WRITE(reg, temp);
4236
4237 reg = FDI_RX_CTL(pipe);
4238 temp = I915_READ(reg);
4239 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4240 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
Jesse Barnes357555c2011-04-28 15:09:55 -07004241 I915_WRITE(reg, temp);
4242
4243 POSTING_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004244 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004245
Jesse Barnes139ccd32013-08-19 11:04:55 -07004246 for (i = 0; i < 4; i++) {
4247 reg = FDI_RX_IIR(pipe);
4248 temp = I915_READ(reg);
4249 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
Jesse Barnes357555c2011-04-28 15:09:55 -07004250
Jesse Barnes139ccd32013-08-19 11:04:55 -07004251 if (temp & FDI_RX_SYMBOL_LOCK ||
4252 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4253 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4254 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4255 i);
4256 goto train_done;
4257 }
4258 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004259 }
Jesse Barnes139ccd32013-08-19 11:04:55 -07004260 if (i == 4)
4261 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
Jesse Barnes357555c2011-04-28 15:09:55 -07004262 }
Jesse Barnes357555c2011-04-28 15:09:55 -07004263
Jesse Barnes139ccd32013-08-19 11:04:55 -07004264train_done:
Jesse Barnes357555c2011-04-28 15:09:55 -07004265 DRM_DEBUG_KMS("FDI train done.\n");
4266}
4267
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004268static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes0e23b992010-09-10 11:10:00 -07004269{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004270 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4271 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004272 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004273 i915_reg_t reg;
4274 u32 temp;
Jesse Barnesc64e3112010-09-10 11:27:03 -07004275
Jesse Barnes0e23b992010-09-10 11:10:00 -07004276 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
Chris Wilson5eddb702010-09-11 13:48:45 +01004277 reg = FDI_RX_CTL(pipe);
4278 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004279 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004280 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004281 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Chris Wilson5eddb702010-09-11 13:48:45 +01004282 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4283
4284 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004285 udelay(200);
4286
4287 /* Switch from Rawclk to PCDclk */
Chris Wilson5eddb702010-09-11 13:48:45 +01004288 temp = I915_READ(reg);
4289 I915_WRITE(reg, temp | FDI_PCDCLK);
4290
4291 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004292 udelay(200);
4293
Paulo Zanoni20749732012-11-23 15:30:38 -02004294 /* Enable CPU FDI TX PLL, always on for Ironlake */
4295 reg = FDI_TX_CTL(pipe);
4296 temp = I915_READ(reg);
4297 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4298 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
Chris Wilson5eddb702010-09-11 13:48:45 +01004299
Paulo Zanoni20749732012-11-23 15:30:38 -02004300 POSTING_READ(reg);
4301 udelay(100);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004302 }
4303}
4304
Daniel Vetter88cefb62012-08-12 19:27:14 +02004305static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4306{
4307 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004308 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter88cefb62012-08-12 19:27:14 +02004309 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004310 i915_reg_t reg;
4311 u32 temp;
Daniel Vetter88cefb62012-08-12 19:27:14 +02004312
4313 /* Switch from PCDclk to Rawclk */
4314 reg = FDI_RX_CTL(pipe);
4315 temp = I915_READ(reg);
4316 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4317
4318 /* Disable CPU FDI TX PLL */
4319 reg = FDI_TX_CTL(pipe);
4320 temp = I915_READ(reg);
4321 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4322
4323 POSTING_READ(reg);
4324 udelay(100);
4325
4326 reg = FDI_RX_CTL(pipe);
4327 temp = I915_READ(reg);
4328 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4329
4330 /* Wait for the clocks to turn off. */
4331 POSTING_READ(reg);
4332 udelay(100);
4333}
4334
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004335static void ironlake_fdi_disable(struct drm_crtc *crtc)
4336{
4337 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004338 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004339 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4340 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004341 i915_reg_t reg;
4342 u32 temp;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004343
4344 /* disable CPU FDI tx and PCH FDI rx */
4345 reg = FDI_TX_CTL(pipe);
4346 temp = I915_READ(reg);
4347 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4348 POSTING_READ(reg);
4349
4350 reg = FDI_RX_CTL(pipe);
4351 temp = I915_READ(reg);
4352 temp &= ~(0x7 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004353 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004354 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4355
4356 POSTING_READ(reg);
4357 udelay(100);
4358
4359 /* Ironlake workaround, disable clock pointer after downing FDI */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004360 if (HAS_PCH_IBX(dev_priv))
Jesse Barnes6f06ce12011-01-04 15:09:38 -08004361 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004362
4363 /* still set train pattern 1 */
4364 reg = FDI_TX_CTL(pipe);
4365 temp = I915_READ(reg);
4366 temp &= ~FDI_LINK_TRAIN_NONE;
4367 temp |= FDI_LINK_TRAIN_PATTERN_1;
4368 I915_WRITE(reg, temp);
4369
4370 reg = FDI_RX_CTL(pipe);
4371 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004372 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004373 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4374 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4375 } else {
4376 temp &= ~FDI_LINK_TRAIN_NONE;
4377 temp |= FDI_LINK_TRAIN_PATTERN_1;
4378 }
4379 /* BPC in FDI rx is consistent with that in PIPECONF */
4380 temp &= ~(0x07 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004381 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004382 I915_WRITE(reg, temp);
4383
4384 POSTING_READ(reg);
4385 udelay(100);
4386}
4387
Chris Wilson49d73912016-11-29 09:50:08 +00004388bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004389{
Daniel Vetterfa058872017-07-20 19:57:52 +02004390 struct drm_crtc *crtc;
4391 bool cleanup_done;
Chris Wilson5dce5b932014-01-20 10:17:36 +00004392
Daniel Vetterfa058872017-07-20 19:57:52 +02004393 drm_for_each_crtc(crtc, &dev_priv->drm) {
4394 struct drm_crtc_commit *commit;
4395 spin_lock(&crtc->commit_lock);
4396 commit = list_first_entry_or_null(&crtc->commit_list,
4397 struct drm_crtc_commit, commit_entry);
4398 cleanup_done = commit ?
4399 try_wait_for_completion(&commit->cleanup_done) : true;
4400 spin_unlock(&crtc->commit_lock);
4401
4402 if (cleanup_done)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004403 continue;
4404
Daniel Vetterfa058872017-07-20 19:57:52 +02004405 drm_crtc_wait_one_vblank(crtc);
Chris Wilson5dce5b932014-01-20 10:17:36 +00004406
4407 return true;
4408 }
4409
4410 return false;
4411}
4412
Maarten Lankhorstb7076542016-08-23 16:18:08 +02004413void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004414{
4415 u32 temp;
4416
4417 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4418
4419 mutex_lock(&dev_priv->sb_lock);
4420
4421 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4422 temp |= SBI_SSCCTL_DISABLE;
4423 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4424
4425 mutex_unlock(&dev_priv->sb_lock);
4426}
4427
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004428/* Program iCLKIP clock to the desired frequency */
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004429static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004430{
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004431 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004432 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004433 int clock = crtc_state->base.adjusted_mode.crtc_clock;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004434 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4435 u32 temp;
4436
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004437 lpt_disable_iclkip(dev_priv);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004438
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004439 /* The iCLK virtual clock root frequency is in MHz,
4440 * but the adjusted_mode->crtc_clock in in KHz. To get the
4441 * divisors, it is necessary to divide one by another, so we
4442 * convert the virtual clock precision to KHz here for higher
4443 * precision.
4444 */
4445 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004446 u32 iclk_virtual_root_freq = 172800 * 1000;
4447 u32 iclk_pi_range = 64;
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004448 u32 desired_divisor;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004449
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004450 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4451 clock << auxdiv);
4452 divsel = (desired_divisor / iclk_pi_range) - 2;
4453 phaseinc = desired_divisor % iclk_pi_range;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004454
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004455 /*
4456 * Near 20MHz is a corner case which is
4457 * out of range for the 7-bit divisor
4458 */
4459 if (divsel <= 0x7f)
4460 break;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004461 }
4462
4463 /* This should not happen with any sane values */
4464 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4465 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4466 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4467 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4468
4469 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 +03004470 clock,
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004471 auxdiv,
4472 divsel,
4473 phasedir,
4474 phaseinc);
4475
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004476 mutex_lock(&dev_priv->sb_lock);
4477
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004478 /* Program SSCDIVINTPHASE6 */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004479 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004480 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4481 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4482 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4483 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4484 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4485 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004486 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004487
4488 /* Program SSCAUXDIV */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004489 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004490 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4491 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004492 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004493
4494 /* Enable modulator and associated divider */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004495 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004496 temp &= ~SBI_SSCCTL_DISABLE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004497 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004498
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004499 mutex_unlock(&dev_priv->sb_lock);
4500
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004501 /* Wait for initialization time */
4502 udelay(24);
4503
4504 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4505}
4506
Ville Syrjälä8802e5b2016-02-17 21:41:12 +02004507int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4508{
4509 u32 divsel, phaseinc, auxdiv;
4510 u32 iclk_virtual_root_freq = 172800 * 1000;
4511 u32 iclk_pi_range = 64;
4512 u32 desired_divisor;
4513 u32 temp;
4514
4515 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4516 return 0;
4517
4518 mutex_lock(&dev_priv->sb_lock);
4519
4520 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4521 if (temp & SBI_SSCCTL_DISABLE) {
4522 mutex_unlock(&dev_priv->sb_lock);
4523 return 0;
4524 }
4525
4526 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4527 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4528 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4529 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4530 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4531
4532 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4533 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4534 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4535
4536 mutex_unlock(&dev_priv->sb_lock);
4537
4538 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4539
4540 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4541 desired_divisor << auxdiv);
4542}
4543
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004544static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
Daniel Vetter275f01b22013-05-03 11:49:47 +02004545 enum pipe pch_transcoder)
4546{
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004547 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4548 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4549 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter275f01b22013-05-03 11:49:47 +02004550
4551 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4552 I915_READ(HTOTAL(cpu_transcoder)));
4553 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4554 I915_READ(HBLANK(cpu_transcoder)));
4555 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4556 I915_READ(HSYNC(cpu_transcoder)));
4557
4558 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4559 I915_READ(VTOTAL(cpu_transcoder)));
4560 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4561 I915_READ(VBLANK(cpu_transcoder)));
4562 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4563 I915_READ(VSYNC(cpu_transcoder)));
4564 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4565 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4566}
4567
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004568static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004569{
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004570 uint32_t temp;
4571
4572 temp = I915_READ(SOUTH_CHICKEN1);
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004573 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004574 return;
4575
4576 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4577 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4578
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004579 temp &= ~FDI_BC_BIFURCATION_SELECT;
4580 if (enable)
4581 temp |= FDI_BC_BIFURCATION_SELECT;
4582
4583 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004584 I915_WRITE(SOUTH_CHICKEN1, temp);
4585 POSTING_READ(SOUTH_CHICKEN1);
4586}
4587
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004588static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004589{
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004590 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4591 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004592
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004593 switch (crtc->pipe) {
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004594 case PIPE_A:
4595 break;
4596 case PIPE_B:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004597 if (crtc_state->fdi_lanes > 2)
4598 cpt_set_fdi_bc_bifurcation(dev_priv, false);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004599 else
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004600 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004601
4602 break;
4603 case PIPE_C:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004604 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004605
4606 break;
4607 default:
4608 BUG();
4609 }
4610}
4611
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004612/*
4613 * Finds the encoder associated with the given CRTC. This can only be
4614 * used when we know that the CRTC isn't feeding multiple encoders!
4615 */
4616static struct intel_encoder *
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004617intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4618 const struct intel_crtc_state *crtc_state)
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004619{
4620 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004621 const struct drm_connector_state *connector_state;
4622 const struct drm_connector *connector;
4623 struct intel_encoder *encoder = NULL;
4624 int num_encoders = 0;
4625 int i;
4626
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004627 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004628 if (connector_state->crtc != &crtc->base)
4629 continue;
4630
4631 encoder = to_intel_encoder(connector_state->best_encoder);
4632 num_encoders++;
4633 }
4634
4635 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4636 num_encoders, pipe_name(crtc->pipe));
4637
4638 return encoder;
4639}
4640
Jesse Barnesf67a5592011-01-05 10:31:48 -08004641/*
4642 * Enable PCH resources required for PCH ports:
4643 * - PCH PLLs
4644 * - FDI training & RX/TX
4645 * - update transcoder timings
4646 * - DP transcoding bits
4647 * - transcoder
4648 */
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004649static void ironlake_pch_enable(const struct intel_atomic_state *state,
4650 const struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08004651{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004652 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004653 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004654 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004655 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004656 u32 temp;
Jesse Barnes6be4a602010-09-10 10:26:01 -07004657
Daniel Vetterab9412b2013-05-03 11:49:46 +02004658 assert_pch_transcoder_disabled(dev_priv, pipe);
Chris Wilsone7e164d2012-05-11 09:21:25 +01004659
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004660 if (IS_IVYBRIDGE(dev_priv))
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004661 ivybridge_update_fdi_bc_bifurcation(crtc_state);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004662
Daniel Vettercd986ab2012-10-26 10:58:12 +02004663 /* Write the TU size bits before fdi link training, so that error
4664 * detection works. */
4665 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4666 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4667
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004668 /* For PCH output, training FDI link */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004669 dev_priv->display.fdi_link_train(crtc, crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07004670
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004671 /* We need to program the right clock selection before writing the pixel
4672 * mutliplier into the DPLL. */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004673 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004674 u32 sel;
Jesse Barnes4b645f12011-10-12 09:51:31 -07004675
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004676 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02004677 temp |= TRANS_DPLL_ENABLE(pipe);
4678 sel = TRANS_DPLLB_SEL(pipe);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004679 if (crtc_state->shared_dpll ==
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02004680 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004681 temp |= sel;
4682 else
4683 temp &= ~sel;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004684 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004685 }
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004686
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004687 /* XXX: pch pll's can be enabled any time before we enable the PCH
4688 * transcoder, and we actually should do this to not upset any PCH
4689 * transcoder that already use the clock when we share it.
4690 *
4691 * Note that enable_shared_dpll tries to do the right thing, but
4692 * get_shared_dpll unconditionally resets the pll - we need that to have
4693 * the right LVDS enable sequence. */
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02004694 intel_enable_shared_dpll(crtc_state);
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004695
Jesse Barnesd9b6cb52011-01-04 15:09:35 -08004696 /* set transcoder timing, panel must allow it */
4697 assert_panel_unlocked(dev_priv, pipe);
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004698 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004699
Paulo Zanoni303b81e2012-10-31 18:12:23 -02004700 intel_fdi_normal_train(crtc);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004701
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004702 /* For PCH DP, enable TRANS_DP_CTL */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004703 if (HAS_PCH_CPT(dev_priv) &&
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004704 intel_crtc_has_dp_encoder(crtc_state)) {
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004705 const struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004706 &crtc_state->base.adjusted_mode;
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004707 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004708 i915_reg_t reg = TRANS_DP_CTL(pipe);
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004709 enum port port;
4710
Chris Wilson5eddb702010-09-11 13:48:45 +01004711 temp = I915_READ(reg);
4712 temp &= ~(TRANS_DP_PORT_SEL_MASK |
Eric Anholt220cad32010-11-18 09:32:58 +08004713 TRANS_DP_SYNC_MASK |
4714 TRANS_DP_BPC_MASK);
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03004715 temp |= TRANS_DP_OUTPUT_ENABLE;
Jesse Barnes9325c9f2011-06-24 12:19:21 -07004716 temp |= bpc << 9; /* same format but at 11:9 */
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004717
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004718 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004719 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004720 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004721 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004722
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004723 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004724 WARN_ON(port < PORT_B || port > PORT_D);
4725 temp |= TRANS_DP_PORT_SEL(port);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004726
Chris Wilson5eddb702010-09-11 13:48:45 +01004727 I915_WRITE(reg, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004728 }
4729
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02004730 ironlake_enable_pch_transcoder(crtc_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004731}
4732
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004733static void lpt_pch_enable(const struct intel_atomic_state *state,
4734 const struct intel_crtc_state *crtc_state)
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004735{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004736 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004737 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004738 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004739
Matthias Kaehlckea2196032017-07-17 11:14:03 -07004740 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004741
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004742 lpt_program_iclkip(crtc_state);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004743
Paulo Zanoni0540e482012-10-31 18:12:40 -02004744 /* Set transcoder timing. */
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004745 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004746
Paulo Zanoni937bb612012-10-31 18:12:47 -02004747 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004748}
4749
Daniel Vettera1520312013-05-03 11:49:50 +02004750static void cpt_verify_modeset(struct drm_device *dev, int pipe)
Jesse Barnesd4270e52011-10-11 10:43:02 -07004751{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004752 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004753 i915_reg_t dslreg = PIPEDSL(pipe);
Jesse Barnesd4270e52011-10-11 10:43:02 -07004754 u32 temp;
4755
4756 temp = I915_READ(dslreg);
4757 udelay(500);
4758 if (wait_for(I915_READ(dslreg) != temp, 5)) {
Jesse Barnesd4270e52011-10-11 10:43:02 -07004759 if (wait_for(I915_READ(dslreg) != temp, 5))
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03004760 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
Jesse Barnesd4270e52011-10-11 10:43:02 -07004761 }
4762}
4763
Ville Syrjälä0a599522018-05-21 21:56:13 +03004764/*
4765 * The hardware phase 0.0 refers to the center of the pixel.
4766 * We want to start from the top/left edge which is phase
4767 * -0.5. That matches how the hardware calculates the scaling
4768 * factors (from top-left of the first pixel to bottom-right
4769 * of the last pixel, as opposed to the pixel centers).
4770 *
4771 * For 4:2:0 subsampled chroma planes we obviously have to
4772 * adjust that so that the chroma sample position lands in
4773 * the right spot.
4774 *
4775 * Note that for packed YCbCr 4:2:2 formats there is no way to
4776 * control chroma siting. The hardware simply replicates the
4777 * chroma samples for both of the luma samples, and thus we don't
4778 * actually get the expected MPEG2 chroma siting convention :(
4779 * The same behaviour is observed on pre-SKL platforms as well.
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004780 *
4781 * Theory behind the formula (note that we ignore sub-pixel
4782 * source coordinates):
4783 * s = source sample position
4784 * d = destination sample position
4785 *
4786 * Downscaling 4:1:
4787 * -0.5
4788 * | 0.0
4789 * | | 1.5 (initial phase)
4790 * | | |
4791 * v v v
4792 * | s | s | s | s |
4793 * | d |
4794 *
4795 * Upscaling 1:4:
4796 * -0.5
4797 * | -0.375 (initial phase)
4798 * | | 0.0
4799 * | | |
4800 * v v v
4801 * | s |
4802 * | d | d | d | d |
Ville Syrjälä0a599522018-05-21 21:56:13 +03004803 */
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004804u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
Ville Syrjälä0a599522018-05-21 21:56:13 +03004805{
4806 int phase = -0x8000;
4807 u16 trip = 0;
4808
4809 if (chroma_cosited)
4810 phase += (sub - 1) * 0x8000 / sub;
4811
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004812 phase += scale / (2 * sub);
4813
4814 /*
4815 * Hardware initial phase limited to [-0.5:1.5].
4816 * Since the max hardware scale factor is 3.0, we
4817 * should never actually excdeed 1.0 here.
4818 */
4819 WARN_ON(phase < -0x8000 || phase > 0x18000);
4820
Ville Syrjälä0a599522018-05-21 21:56:13 +03004821 if (phase < 0)
4822 phase = 0x10000 + phase;
4823 else
4824 trip = PS_PHASE_TRIP;
4825
4826 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4827}
4828
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004829static int
4830skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004831 unsigned int scaler_user, int *scaler_id,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304832 int src_w, int src_h, int dst_w, int dst_h,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004833 const struct drm_format_info *format, bool need_scaler)
Chandra Kondurua1b22782015-04-07 15:28:45 -07004834{
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004835 struct intel_crtc_scaler_state *scaler_state =
4836 &crtc_state->scaler_state;
4837 struct intel_crtc *intel_crtc =
4838 to_intel_crtc(crtc_state->base.crtc);
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304839 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4840 const struct drm_display_mode *adjusted_mode =
4841 &crtc_state->base.adjusted_mode;
Chandra Konduru6156a452015-04-27 13:48:39 -07004842
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004843 /*
4844 * Src coordinates are already rotated by 270 degrees for
4845 * the 90/270 degree plane rotation cases (to match the
4846 * GTT mapping), hence no need to account for rotation here.
4847 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004848 if (src_w != dst_w || src_h != dst_h)
4849 need_scaler = true;
Shashank Sharmae5c05932017-07-21 20:55:05 +05304850
Chandra Kondurua1b22782015-04-07 15:28:45 -07004851 /*
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304852 * Scaling/fitting not supported in IF-ID mode in GEN9+
4853 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4854 * Once NV12 is enabled, handle it here while allocating scaler
4855 * for NV12.
4856 */
4857 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004858 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304859 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4860 return -EINVAL;
4861 }
4862
4863 /*
Chandra Kondurua1b22782015-04-07 15:28:45 -07004864 * if plane is being disabled or scaler is no more required or force detach
4865 * - free scaler binded to this plane/crtc
4866 * - in order to do this, update crtc->scaler_usage
4867 *
4868 * Here scaler state in crtc_state is set free so that
4869 * scaler can be assigned to other user. Actual register
4870 * update to free the scaler is done in plane/panel-fit programming.
4871 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4872 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004873 if (force_detach || !need_scaler) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07004874 if (*scaler_id >= 0) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004875 scaler_state->scaler_users &= ~(1 << scaler_user);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004876 scaler_state->scalers[*scaler_id].in_use = 0;
4877
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004878 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4879 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4880 intel_crtc->pipe, scaler_user, *scaler_id,
Chandra Kondurua1b22782015-04-07 15:28:45 -07004881 scaler_state->scaler_users);
4882 *scaler_id = -1;
4883 }
4884 return 0;
4885 }
4886
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004887 if (format && format->format == DRM_FORMAT_NV12 &&
Maarten Lankhorst5d794282018-05-12 03:03:14 +05304888 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
Chandra Konduru77224cd2018-04-09 09:11:13 +05304889 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4890 return -EINVAL;
4891 }
4892
Chandra Kondurua1b22782015-04-07 15:28:45 -07004893 /* range checks */
4894 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
Nabendu Maiti323301a2018-03-23 10:24:18 -07004895 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4896 (IS_GEN11(dev_priv) &&
4897 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4898 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4899 (!IS_GEN11(dev_priv) &&
4900 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4901 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004902 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
Chandra Kondurua1b22782015-04-07 15:28:45 -07004903 "size is out of scaler range\n",
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004904 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004905 return -EINVAL;
4906 }
4907
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004908 /* mark this plane as a scaler user in crtc_state */
4909 scaler_state->scaler_users |= (1 << scaler_user);
4910 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4911 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4912 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4913 scaler_state->scaler_users);
4914
4915 return 0;
4916}
4917
4918/**
4919 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4920 *
4921 * @state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004922 *
4923 * Return
4924 * 0 - scaler_usage updated successfully
4925 * error - requested scaling cannot be supported or other error condition
4926 */
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004927int skl_update_scaler_crtc(struct intel_crtc_state *state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004928{
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03004929 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004930 bool need_scaler = false;
4931
4932 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
4933 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004934
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004935 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304936 &state->scaler_state.scaler_id,
4937 state->pipe_src_w, state->pipe_src_h,
4938 adjusted_mode->crtc_hdisplay,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004939 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004940}
4941
4942/**
4943 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
Chris Wilsonc38c1452018-02-14 13:49:22 +00004944 * @crtc_state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004945 * @plane_state: atomic plane state to update
4946 *
4947 * Return
4948 * 0 - scaler_usage updated successfully
4949 * error - requested scaling cannot be supported or other error condition
4950 */
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02004951static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4952 struct intel_plane_state *plane_state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004953{
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02004954 struct intel_plane *intel_plane =
4955 to_intel_plane(plane_state->base.plane);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004956 struct drm_framebuffer *fb = plane_state->base.fb;
4957 int ret;
Ville Syrjälä936e71e2016-07-26 19:06:59 +03004958 bool force_detach = !fb || !plane_state->base.visible;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004959 bool need_scaler = false;
4960
4961 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
4962 if (!icl_is_hdr_plane(intel_plane) &&
4963 fb && fb->format->format == DRM_FORMAT_NV12)
4964 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004965
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004966 ret = skl_update_scaler(crtc_state, force_detach,
4967 drm_plane_index(&intel_plane->base),
4968 &plane_state->scaler_id,
Ville Syrjälä936e71e2016-07-26 19:06:59 +03004969 drm_rect_width(&plane_state->base.src) >> 16,
4970 drm_rect_height(&plane_state->base.src) >> 16,
4971 drm_rect_width(&plane_state->base.dst),
Chandra Konduru77224cd2018-04-09 09:11:13 +05304972 drm_rect_height(&plane_state->base.dst),
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004973 fb ? fb->format : NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004974
4975 if (ret || plane_state->scaler_id < 0)
4976 return ret;
4977
Chandra Kondurua1b22782015-04-07 15:28:45 -07004978 /* check colorkey */
Ville Syrjälä6ec5bd32018-02-02 22:42:31 +02004979 if (plane_state->ckey.flags) {
Ville Syrjälä72660ce2016-05-27 20:59:20 +03004980 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4981 intel_plane->base.base.id,
4982 intel_plane->base.name);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004983 return -EINVAL;
4984 }
4985
4986 /* Check src format */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02004987 switch (fb->format->format) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004988 case DRM_FORMAT_RGB565:
4989 case DRM_FORMAT_XBGR8888:
4990 case DRM_FORMAT_XRGB8888:
4991 case DRM_FORMAT_ABGR8888:
4992 case DRM_FORMAT_ARGB8888:
4993 case DRM_FORMAT_XRGB2101010:
4994 case DRM_FORMAT_XBGR2101010:
4995 case DRM_FORMAT_YUYV:
4996 case DRM_FORMAT_YVYU:
4997 case DRM_FORMAT_UYVY:
4998 case DRM_FORMAT_VYUY:
Chandra Konduru77224cd2018-04-09 09:11:13 +05304999 case DRM_FORMAT_NV12:
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005000 break;
5001 default:
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005002 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5003 intel_plane->base.base.id, intel_plane->base.name,
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005004 fb->base.id, fb->format->format);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005005 return -EINVAL;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005006 }
5007
Chandra Kondurua1b22782015-04-07 15:28:45 -07005008 return 0;
5009}
5010
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005011static void skylake_scaler_disable(struct intel_crtc *crtc)
5012{
5013 int i;
5014
5015 for (i = 0; i < crtc->num_scalers; i++)
5016 skl_detach_scaler(crtc, i);
5017}
5018
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005019static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005020{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005021 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5022 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5023 enum pipe pipe = crtc->pipe;
5024 const struct intel_crtc_scaler_state *scaler_state =
5025 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005026
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005027 if (crtc_state->pch_pfit.enabled) {
Ville Syrjälä0a599522018-05-21 21:56:13 +03005028 u16 uv_rgb_hphase, uv_rgb_vphase;
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005029 int pfit_w, pfit_h, hscale, vscale;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005030 int id;
5031
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005032 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
Chandra Kondurua1b22782015-04-07 15:28:45 -07005033 return;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005034
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005035 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5036 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5037
5038 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5039 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5040
5041 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5042 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005043
Chandra Kondurua1b22782015-04-07 15:28:45 -07005044 id = scaler_state->scaler_id;
5045 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5046 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005047 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5048 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5049 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5050 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005051 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5052 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005053 }
5054}
5055
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005056static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesb074cec2013-04-25 12:55:02 -07005057{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005058 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5059 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesb074cec2013-04-25 12:55:02 -07005060 int pipe = crtc->pipe;
5061
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005062 if (crtc_state->pch_pfit.enabled) {
Jesse Barnesb074cec2013-04-25 12:55:02 -07005063 /* Force use of hard-coded filter coefficients
5064 * as some pre-programmed values are broken,
5065 * e.g. x201.
5066 */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01005067 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
Jesse Barnesb074cec2013-04-25 12:55:02 -07005068 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5069 PF_PIPE_SEL_IVB(pipe));
5070 else
5071 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005072 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5073 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
Jesse Barnes040484a2011-01-03 12:14:26 -08005074 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005075}
5076
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005077void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005078{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005079 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläcea165c2014-04-15 21:41:35 +03005080 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005081 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005082
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005083 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005084 return;
5085
Maarten Lankhorst307e4492016-03-23 14:33:28 +01005086 /*
5087 * We can only enable IPS after we enable a plane and wait for a vblank
5088 * This function is called from post_plane_update, which is run after
5089 * a vblank wait.
5090 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005091 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02005092
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005093 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005094 mutex_lock(&dev_priv->pcu_lock);
Ville Syrjälä61843f02017-09-12 18:34:11 +03005095 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5096 IPS_ENABLE | IPS_PCODE_CONTROL));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005097 mutex_unlock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005098 /* Quoting Art Runyan: "its not safe to expect any particular
5099 * value in IPS_CTL bit 31 after enabling IPS through the
Jesse Barnese59150d2014-01-07 13:30:45 -08005100 * mailbox." Moreover, the mailbox may return a bogus state,
5101 * so we need to just enable it and continue on.
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005102 */
5103 } else {
5104 I915_WRITE(IPS_CTL, IPS_ENABLE);
5105 /* The bit only becomes 1 in the next vblank, so this wait here
5106 * is essentially intel_wait_for_vblank. If we don't have this
5107 * and don't wait for vblanks until the end of crtc_enable, then
5108 * the HW state readout code will complain that the expected
5109 * IPS_CTL value is not the one we read. */
Chris Wilson2ec9ba32016-06-30 15:33:01 +01005110 if (intel_wait_for_register(dev_priv,
5111 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5112 50))
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005113 DRM_ERROR("Timed out waiting for IPS enable\n");
5114 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005115}
5116
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005117void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005118{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005119 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005120 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005121 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005122
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005123 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005124 return;
5125
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005126 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005127 mutex_lock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005128 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005129 mutex_unlock(&dev_priv->pcu_lock);
Imre Deakacb3ef02018-09-05 13:00:05 +03005130 /*
5131 * Wait for PCODE to finish disabling IPS. The BSpec specified
5132 * 42ms timeout value leads to occasional timeouts so use 100ms
5133 * instead.
5134 */
Chris Wilsonb85c1ec2016-06-30 15:33:02 +01005135 if (intel_wait_for_register(dev_priv,
5136 IPS_CTL, IPS_ENABLE, 0,
Imre Deakacb3ef02018-09-05 13:00:05 +03005137 100))
Ben Widawsky23d0b132014-04-10 14:32:41 -07005138 DRM_ERROR("Timed out waiting for IPS disable\n");
Jesse Barnese59150d2014-01-07 13:30:45 -08005139 } else {
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005140 I915_WRITE(IPS_CTL, 0);
Jesse Barnese59150d2014-01-07 13:30:45 -08005141 POSTING_READ(IPS_CTL);
5142 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005143
5144 /* We need to wait for a vblank before we can disable the plane. */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005145 intel_wait_for_vblank(dev_priv, crtc->pipe);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005146}
5147
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005148static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005149{
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005150 if (intel_crtc->overlay) {
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005151 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005152
5153 mutex_lock(&dev->struct_mutex);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005154 (void) intel_overlay_switch_off(intel_crtc->overlay);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005155 mutex_unlock(&dev->struct_mutex);
5156 }
5157
5158 /* Let userspace switch the overlay on again. In most cases userspace
5159 * has to recompute where to put it anyway.
5160 */
5161}
5162
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005163/**
5164 * intel_post_enable_primary - Perform operations after enabling primary plane
5165 * @crtc: the CRTC whose primary plane was just enabled
Chris Wilsonc38c1452018-02-14 13:49:22 +00005166 * @new_crtc_state: the enabling state
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005167 *
5168 * Performs potentially sleeping operations that must be done after the primary
5169 * plane is enabled, such as updating FBC and IPS. Note that this may be
5170 * called due to an explicit primary plane update, or due to an implicit
5171 * re-enable that is caused when a sprite plane is updated to no longer
5172 * completely hide the primary plane.
5173 */
5174static void
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005175intel_post_enable_primary(struct drm_crtc *crtc,
5176 const struct intel_crtc_state *new_crtc_state)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005177{
5178 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005179 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005180 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5181 int pipe = intel_crtc->pipe;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005182
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005183 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005184 * Gen2 reports pipe underruns whenever all planes are disabled.
5185 * So don't enable underrun reporting before at least some planes
5186 * are enabled.
5187 * FIXME: Need to fix the logic to work when we turn off all planes
5188 * but leave the pipe running.
Daniel Vetterf99d7062014-06-19 16:01:59 +02005189 */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01005190 if (IS_GEN2(dev_priv))
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005191 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5192
Ville Syrjäläaca7b682015-10-30 19:22:21 +02005193 /* Underruns don't always raise interrupts, so check manually. */
5194 intel_check_cpu_fifo_underruns(dev_priv);
5195 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005196}
5197
Ville Syrjälä2622a082016-03-09 19:07:26 +02005198/* FIXME get rid of this and use pre_plane_update */
5199static void
5200intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5201{
5202 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005203 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä2622a082016-03-09 19:07:26 +02005204 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5205 int pipe = intel_crtc->pipe;
5206
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005207 /*
5208 * Gen2 reports pipe underruns whenever all planes are disabled.
5209 * So disable underrun reporting before all the planes get disabled.
5210 */
5211 if (IS_GEN2(dev_priv))
5212 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5213
5214 hsw_disable_ips(to_intel_crtc_state(crtc->state));
Ville Syrjälä2622a082016-03-09 19:07:26 +02005215
5216 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005217 * Vblank time updates from the shadow to live plane control register
5218 * are blocked if the memory self-refresh mode is active at that
5219 * moment. So to make sure the plane gets truly disabled, disable
5220 * first the self-refresh mode. The self-refresh enable bit in turn
5221 * will be checked/applied by the HW only at the next frame start
5222 * event which is after the vblank start event, so we need to have a
5223 * wait-for-vblank between disabling the plane and the pipe.
5224 */
Ville Syrjälä11a85d62016-11-28 19:37:12 +02005225 if (HAS_GMCH_DISPLAY(dev_priv) &&
5226 intel_set_memory_cxsr(dev_priv, false))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005227 intel_wait_for_vblank(dev_priv, pipe);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005228}
5229
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005230static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5231 const struct intel_crtc_state *new_crtc_state)
5232{
5233 if (!old_crtc_state->ips_enabled)
5234 return false;
5235
5236 if (needs_modeset(&new_crtc_state->base))
5237 return true;
5238
5239 return !new_crtc_state->ips_enabled;
5240}
5241
5242static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5243 const struct intel_crtc_state *new_crtc_state)
5244{
5245 if (!new_crtc_state->ips_enabled)
5246 return false;
5247
5248 if (needs_modeset(&new_crtc_state->base))
5249 return true;
5250
5251 /*
5252 * We can't read out IPS on broadwell, assume the worst and
5253 * forcibly enable IPS on the first fastset.
5254 */
5255 if (new_crtc_state->update_pipe &&
5256 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5257 return true;
5258
5259 return !old_crtc_state->ips_enabled;
5260}
5261
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305262static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5263 const struct intel_crtc_state *crtc_state)
5264{
5265 if (!crtc_state->nv12_planes)
5266 return false;
5267
Rodrigo Vivi1347d3c2018-10-31 09:28:45 -07005268 /* WA Display #0827: Gen9:all */
5269 if (IS_GEN9(dev_priv) && !IS_GEMINILAKE(dev_priv))
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305270 return true;
5271
5272 return false;
5273}
5274
Daniel Vetter5a21b662016-05-24 17:13:53 +02005275static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5276{
5277 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +05305278 struct drm_device *dev = crtc->base.dev;
5279 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005280 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5281 struct intel_crtc_state *pipe_config =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005282 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5283 crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005284 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005285 struct drm_plane_state *old_primary_state =
5286 drm_atomic_get_old_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005287
Chris Wilson5748b6a2016-08-04 16:32:38 +01005288 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005289
Daniel Vetter5a21b662016-05-24 17:13:53 +02005290 if (pipe_config->update_wm_post && pipe_config->base.active)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005291 intel_update_watermarks(crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005292
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005293 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5294 hsw_enable_ips(pipe_config);
5295
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005296 if (old_primary_state) {
5297 struct drm_plane_state *new_primary_state =
5298 drm_atomic_get_new_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005299
5300 intel_fbc_post_update(crtc);
5301
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005302 if (new_primary_state->visible &&
Daniel Vetter5a21b662016-05-24 17:13:53 +02005303 (needs_modeset(&pipe_config->base) ||
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005304 !old_primary_state->visible))
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005305 intel_post_enable_primary(&crtc->base, pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005306 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305307
5308 /* Display WA 827 */
5309 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305310 !needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305311 skl_wa_clkgate(dev_priv, crtc->pipe, false);
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305312 }
Daniel Vetter5a21b662016-05-24 17:13:53 +02005313}
5314
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005315static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5316 struct intel_crtc_state *pipe_config)
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005317{
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005318 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005319 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005320 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005321 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5322 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005323 struct drm_plane_state *old_primary_state =
5324 drm_atomic_get_old_plane_state(old_state, primary);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005325 bool modeset = needs_modeset(&pipe_config->base);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005326 struct intel_atomic_state *old_intel_state =
5327 to_intel_atomic_state(old_state);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005328
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005329 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5330 hsw_disable_ips(old_crtc_state);
5331
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005332 if (old_primary_state) {
5333 struct intel_plane_state *new_primary_state =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005334 intel_atomic_get_new_plane_state(old_intel_state,
5335 to_intel_plane(primary));
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005336
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005337 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005338 /*
5339 * Gen2 reports pipe underruns whenever all planes are disabled.
5340 * So disable underrun reporting before all the planes get disabled.
5341 */
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005342 if (IS_GEN2(dev_priv) && old_primary_state->visible &&
5343 (modeset || !new_primary_state->base.visible))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005344 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005345 }
Ville Syrjälä852eb002015-06-24 22:00:07 +03005346
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305347 /* Display WA 827 */
5348 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305349 needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305350 skl_wa_clkgate(dev_priv, crtc->pipe, true);
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305351 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305352
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02005353 /*
5354 * Vblank time updates from the shadow to live plane control register
5355 * are blocked if the memory self-refresh mode is active at that
5356 * moment. So to make sure the plane gets truly disabled, disable
5357 * first the self-refresh mode. The self-refresh enable bit in turn
5358 * will be checked/applied by the HW only at the next frame start
5359 * event which is after the vblank start event, so we need to have a
5360 * wait-for-vblank between disabling the plane and the pipe.
5361 */
5362 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5363 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5364 intel_wait_for_vblank(dev_priv, crtc->pipe);
Maarten Lankhorst92826fc2015-12-03 13:49:13 +01005365
Matt Ropered4a6a72016-02-23 17:20:13 -08005366 /*
5367 * IVB workaround: must disable low power watermarks for at least
5368 * one frame before enabling scaling. LP watermarks can be re-enabled
5369 * when scaling is disabled.
5370 *
5371 * WaCxSRDisabledForSpriteScaling:ivb
5372 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +03005373 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5374 old_crtc_state->base.active)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005375 intel_wait_for_vblank(dev_priv, crtc->pipe);
Matt Ropered4a6a72016-02-23 17:20:13 -08005376
5377 /*
5378 * If we're doing a modeset, we're done. No need to do any pre-vblank
5379 * watermark programming here.
5380 */
5381 if (needs_modeset(&pipe_config->base))
5382 return;
5383
5384 /*
5385 * For platforms that support atomic watermarks, program the
5386 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5387 * will be the intermediate values that are safe for both pre- and
5388 * post- vblank; when vblank happens, the 'active' values will be set
5389 * to the final 'target' values and we'll do this again to get the
5390 * optimal watermarks. For gen9+ platforms, the values we program here
5391 * will be the final target values which will get automatically latched
5392 * at vblank time; no further programming will be necessary.
5393 *
5394 * If a platform hasn't been transitioned to atomic watermarks yet,
5395 * we'll continue to update watermarks the old way, if flags tell
5396 * us to.
5397 */
5398 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005399 dev_priv->display.initial_watermarks(old_intel_state,
5400 pipe_config);
Ville Syrjäläcaed3612016-03-09 19:07:25 +02005401 else if (pipe_config->update_wm_pre)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005402 intel_update_watermarks(crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005403}
5404
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005405static void intel_crtc_disable_planes(struct intel_crtc *crtc, unsigned plane_mask)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005406{
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005407 struct drm_device *dev = crtc->base.dev;
5408 struct intel_plane *plane;
5409 unsigned fb_bits = 0;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005410
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005411 intel_crtc_dpms_overlay_disable(crtc);
Maarten Lankhorst27321ae2015-04-21 17:12:52 +03005412
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005413 for_each_intel_plane_on_crtc(dev, crtc, plane) {
5414 if (plane_mask & BIT(plane->id)) {
5415 plane->disable_plane(plane, crtc);
Ville Syrjäläf98551a2014-05-22 17:48:06 +03005416
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005417 fb_bits |= plane->frontbuffer_bit;
5418 }
5419 }
5420
5421 intel_frontbuffer_flip(to_i915(dev), fb_bits);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005422}
5423
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005424static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005425 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005426 struct drm_atomic_state *old_state)
5427{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005428 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005429 struct drm_connector *conn;
5430 int i;
5431
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005432 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005433 struct intel_encoder *encoder =
5434 to_intel_encoder(conn_state->best_encoder);
5435
5436 if (conn_state->crtc != crtc)
5437 continue;
5438
5439 if (encoder->pre_pll_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005440 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005441 }
5442}
5443
5444static void intel_encoders_pre_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005445 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005446 struct drm_atomic_state *old_state)
5447{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005448 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005449 struct drm_connector *conn;
5450 int i;
5451
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005452 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005453 struct intel_encoder *encoder =
5454 to_intel_encoder(conn_state->best_encoder);
5455
5456 if (conn_state->crtc != crtc)
5457 continue;
5458
5459 if (encoder->pre_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005460 encoder->pre_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005461 }
5462}
5463
5464static void intel_encoders_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005465 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005466 struct drm_atomic_state *old_state)
5467{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005468 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005469 struct drm_connector *conn;
5470 int i;
5471
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005472 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005473 struct intel_encoder *encoder =
5474 to_intel_encoder(conn_state->best_encoder);
5475
5476 if (conn_state->crtc != crtc)
5477 continue;
5478
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005479 if (encoder->enable)
5480 encoder->enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005481 intel_opregion_notify_encoder(encoder, true);
5482 }
5483}
5484
5485static void intel_encoders_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005486 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005487 struct drm_atomic_state *old_state)
5488{
5489 struct drm_connector_state *old_conn_state;
5490 struct drm_connector *conn;
5491 int i;
5492
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005493 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005494 struct intel_encoder *encoder =
5495 to_intel_encoder(old_conn_state->best_encoder);
5496
5497 if (old_conn_state->crtc != crtc)
5498 continue;
5499
5500 intel_opregion_notify_encoder(encoder, false);
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005501 if (encoder->disable)
5502 encoder->disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005503 }
5504}
5505
5506static void intel_encoders_post_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005507 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005508 struct drm_atomic_state *old_state)
5509{
5510 struct drm_connector_state *old_conn_state;
5511 struct drm_connector *conn;
5512 int i;
5513
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005514 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005515 struct intel_encoder *encoder =
5516 to_intel_encoder(old_conn_state->best_encoder);
5517
5518 if (old_conn_state->crtc != crtc)
5519 continue;
5520
5521 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005522 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005523 }
5524}
5525
5526static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005527 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005528 struct drm_atomic_state *old_state)
5529{
5530 struct drm_connector_state *old_conn_state;
5531 struct drm_connector *conn;
5532 int i;
5533
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005534 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005535 struct intel_encoder *encoder =
5536 to_intel_encoder(old_conn_state->best_encoder);
5537
5538 if (old_conn_state->crtc != crtc)
5539 continue;
5540
5541 if (encoder->post_pll_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005542 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005543 }
5544}
5545
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005546static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5547 struct drm_atomic_state *old_state)
Jesse Barnesf67a5592011-01-05 10:31:48 -08005548{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005549 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnesf67a5592011-01-05 10:31:48 -08005550 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005551 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005552 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5553 int pipe = intel_crtc->pipe;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005554 struct intel_atomic_state *old_intel_state =
5555 to_intel_atomic_state(old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005556
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005557 if (WARN_ON(intel_crtc->active))
Jesse Barnesf67a5592011-01-05 10:31:48 -08005558 return;
5559
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005560 /*
5561 * Sometimes spurious CPU pipe underruns happen during FDI
5562 * training, at least with VGA+HDMI cloning. Suppress them.
5563 *
5564 * On ILK we get an occasional spurious CPU pipe underruns
5565 * between eDP port A enable and vdd enable. Also PCH port
5566 * enable seems to result in the occasional CPU pipe underrun.
5567 *
5568 * Spurious PCH underruns also occur during PCH enabling.
5569 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005570 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5571 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005572
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005573 if (pipe_config->has_pch_encoder)
5574 intel_prepare_shared_dpll(pipe_config);
Daniel Vetterb14b1052014-04-24 23:55:13 +02005575
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005576 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005577 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005578
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005579 intel_set_pipe_timings(pipe_config);
5580 intel_set_pipe_src_size(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005581
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005582 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005583 intel_cpu_transcoder_set_m_n(pipe_config,
5584 &pipe_config->fdi_m_n, NULL);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005585 }
5586
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005587 ironlake_set_pipeconf(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005588
Jesse Barnesf67a5592011-01-05 10:31:48 -08005589 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005590
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005591 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005592
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005593 if (pipe_config->has_pch_encoder) {
Daniel Vetterfff367c2012-10-27 15:50:28 +02005594 /* Note: FDI PLL enabling _must_ be done before we enable the
5595 * cpu pipes, hence this is separate from all the other fdi/pch
5596 * enabling. */
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02005597 ironlake_fdi_pll_enable(pipe_config);
Daniel Vetter46b6f812012-09-06 22:08:33 +02005598 } else {
5599 assert_fdi_tx_disabled(dev_priv, pipe);
5600 assert_fdi_rx_disabled(dev_priv, pipe);
5601 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005602
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005603 ironlake_pfit_enable(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005604
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005605 /*
5606 * On ILK+ LUT must be loaded before the pipe is running but with
5607 * clocks enabled
5608 */
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02005609 intel_color_load_luts(&pipe_config->base);
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005610
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005611 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005612 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02005613 intel_enable_pipe(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005614
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005615 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005616 ironlake_pch_enable(old_intel_state, pipe_config);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005617
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005618 assert_vblank_disabled(crtc);
5619 drm_crtc_vblank_on(crtc);
5620
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005621 intel_encoders_enable(crtc, pipe_config, old_state);
Daniel Vetter61b77dd2012-07-02 00:16:19 +02005622
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005623 if (HAS_PCH_CPT(dev_priv))
Daniel Vettera1520312013-05-03 11:49:50 +02005624 cpt_verify_modeset(dev, intel_crtc->pipe);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005625
Ville Syrjäläea80a662018-05-24 22:04:05 +03005626 /*
5627 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5628 * And a second vblank wait is needed at least on ILK with
5629 * some interlaced HDMI modes. Let's do the double wait always
5630 * in case there are more corner cases we don't know about.
5631 */
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005632 if (pipe_config->has_pch_encoder) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005633 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjäläea80a662018-05-24 22:04:05 +03005634 intel_wait_for_vblank(dev_priv, pipe);
5635 }
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005636 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005637 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005638}
5639
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005640/* IPS only exists on ULT machines and is tied to pipe A. */
5641static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5642{
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005643 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005644}
5645
Imre Deaked69cd42017-10-02 10:55:57 +03005646static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5647 enum pipe pipe, bool apply)
5648{
5649 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5650 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5651
5652 if (apply)
5653 val |= mask;
5654 else
5655 val &= ~mask;
5656
5657 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5658}
5659
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005660static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5661{
5662 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5663 enum pipe pipe = crtc->pipe;
5664 uint32_t val;
5665
Rodrigo Vivi443d5e32018-10-04 08:18:14 -07005666 val = MBUS_DBOX_A_CREDIT(2);
5667 val |= MBUS_DBOX_BW_CREDIT(1);
5668 val |= MBUS_DBOX_B_CREDIT(8);
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005669
5670 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5671}
5672
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005673static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5674 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005675{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005676 struct drm_crtc *crtc = pipe_config->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005677 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005678 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005679 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005680 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005681 struct intel_atomic_state *old_intel_state =
5682 to_intel_atomic_state(old_state);
Imre Deaked69cd42017-10-02 10:55:57 +03005683 bool psl_clkgate_wa;
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305684 u32 pipe_chicken;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005685
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005686 if (WARN_ON(intel_crtc->active))
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005687 return;
5688
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005689 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03005690
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005691 if (pipe_config->shared_dpll)
5692 intel_enable_shared_dpll(pipe_config);
Daniel Vetterdf8ad702014-06-25 22:02:03 +03005693
Paulo Zanonic27e9172018-04-27 16:14:36 -07005694 if (INTEL_GEN(dev_priv) >= 11)
5695 icl_map_plls_to_ports(crtc, pipe_config, old_state);
5696
Paulo Zanonic8af5272018-05-02 14:58:51 -07005697 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5698
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005699 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005700 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter229fca92014-04-24 23:55:09 +02005701
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005702 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005703 intel_set_pipe_timings(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005704
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005705 intel_set_pipe_src_size(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005706
Jani Nikula4d1de972016-03-18 17:05:42 +02005707 if (cpu_transcoder != TRANSCODER_EDP &&
5708 !transcoder_is_dsi(cpu_transcoder)) {
5709 I915_WRITE(PIPE_MULT(cpu_transcoder),
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005710 pipe_config->pixel_multiplier - 1);
Clint Taylorebb69c92014-09-30 10:30:22 -07005711 }
5712
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005713 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005714 intel_cpu_transcoder_set_m_n(pipe_config,
5715 &pipe_config->fdi_m_n, NULL);
Daniel Vetter229fca92014-04-24 23:55:09 +02005716 }
5717
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005718 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005719 haswell_set_pipeconf(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005720
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005721 haswell_set_pipemisc(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005722
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02005723 intel_color_set_csc(&pipe_config->base);
Daniel Vetter229fca92014-04-24 23:55:09 +02005724
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005725 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005726
Imre Deaked69cd42017-10-02 10:55:57 +03005727 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5728 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005729 pipe_config->pch_pfit.enabled;
Imre Deaked69cd42017-10-02 10:55:57 +03005730 if (psl_clkgate_wa)
5731 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5732
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005733 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005734 skylake_pfit_enable(pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005735 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005736 ironlake_pfit_enable(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005737
5738 /*
5739 * On ILK+ LUT must be loaded before the pipe is running but with
5740 * clocks enabled
5741 */
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02005742 intel_color_load_luts(&pipe_config->base);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005743
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305744 /*
5745 * Display WA #1153: enable hardware to bypass the alpha math
5746 * and rounding for per-pixel values 00 and 0xff
5747 */
5748 if (INTEL_GEN(dev_priv) >= 11) {
5749 pipe_chicken = I915_READ(PIPE_CHICKEN(pipe));
5750 if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN))
5751 I915_WRITE_FW(PIPE_CHICKEN(pipe),
5752 pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN);
5753 }
5754
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005755 intel_ddi_set_pipe_settings(pipe_config);
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005756 if (!transcoder_is_dsi(cpu_transcoder))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005757 intel_ddi_enable_transcoder_func(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005758
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005759 if (dev_priv->display.initial_watermarks != NULL)
Ville Syrjälä3125d392016-11-28 19:37:03 +02005760 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005761
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005762 if (INTEL_GEN(dev_priv) >= 11)
5763 icl_pipe_mbus_enable(intel_crtc);
5764
Jani Nikula4d1de972016-03-18 17:05:42 +02005765 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005766 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005767 intel_enable_pipe(pipe_config);
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005768
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005769 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005770 lpt_pch_enable(old_intel_state, pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005771
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005772 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005773 intel_ddi_set_vc_payload_alloc(pipe_config, true);
Dave Airlie0e32b392014-05-02 14:02:48 +10005774
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005775 assert_vblank_disabled(crtc);
5776 drm_crtc_vblank_on(crtc);
5777
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005778 intel_encoders_enable(crtc, pipe_config, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005779
Imre Deaked69cd42017-10-02 10:55:57 +03005780 if (psl_clkgate_wa) {
5781 intel_wait_for_vblank(dev_priv, pipe);
5782 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5783 }
5784
Paulo Zanonie4916942013-09-20 16:21:19 -03005785 /* If we change the relative order between pipe/planes enabling, we need
5786 * to change the workaround. */
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005787 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01005788 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005789 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5790 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005791 }
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005792}
5793
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005794static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005795{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005796 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5797 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5798 enum pipe pipe = crtc->pipe;
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005799
5800 /* To avoid upsetting the power well on haswell only disable the pfit if
5801 * it's in use. The hw state code will make sure we get this right. */
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005802 if (old_crtc_state->pch_pfit.enabled) {
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005803 I915_WRITE(PF_CTL(pipe), 0);
5804 I915_WRITE(PF_WIN_POS(pipe), 0);
5805 I915_WRITE(PF_WIN_SZ(pipe), 0);
5806 }
5807}
5808
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005809static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5810 struct drm_atomic_state *old_state)
Jesse Barnes6be4a602010-09-10 10:26:01 -07005811{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005812 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes6be4a602010-09-10 10:26:01 -07005813 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005814 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005815 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5816 int pipe = intel_crtc->pipe;
Jesse Barnes6be4a602010-09-10 10:26:01 -07005817
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005818 /*
5819 * Sometimes spurious CPU pipe underruns happen when the
5820 * pipe is already disabled, but FDI RX/TX is still enabled.
5821 * Happens at least with VGA+HDMI cloning. Suppress them.
5822 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005823 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5824 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005825
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005826 intel_encoders_disable(crtc, old_crtc_state, old_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +02005827
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005828 drm_crtc_vblank_off(crtc);
5829 assert_vblank_disabled(crtc);
5830
Ville Syrjälä4972f702017-11-29 17:37:32 +02005831 intel_disable_pipe(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005832
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005833 ironlake_pfit_disable(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005834
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005835 if (old_crtc_state->has_pch_encoder)
Ville Syrjälä5a74f702015-05-05 17:17:38 +03005836 ironlake_fdi_disable(crtc);
5837
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005838 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005839
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005840 if (old_crtc_state->has_pch_encoder) {
Daniel Vetterd925c592013-06-05 13:34:04 +02005841 ironlake_disable_pch_transcoder(dev_priv, pipe);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005842
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005843 if (HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005844 i915_reg_t reg;
5845 u32 temp;
5846
Daniel Vetterd925c592013-06-05 13:34:04 +02005847 /* disable TRANS_DP_CTL */
5848 reg = TRANS_DP_CTL(pipe);
5849 temp = I915_READ(reg);
5850 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5851 TRANS_DP_PORT_SEL_MASK);
5852 temp |= TRANS_DP_PORT_SEL_NONE;
5853 I915_WRITE(reg, temp);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005854
Daniel Vetterd925c592013-06-05 13:34:04 +02005855 /* disable DPLL_SEL */
5856 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02005857 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
Daniel Vetterd925c592013-06-05 13:34:04 +02005858 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08005859 }
Daniel Vetterd925c592013-06-05 13:34:04 +02005860
Daniel Vetterd925c592013-06-05 13:34:04 +02005861 ironlake_fdi_pll_disable(intel_crtc);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005862 }
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005863
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005864 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005865 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005866}
5867
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005868static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5869 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005870{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005871 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005872 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005873 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Imre Deak24a28172018-06-13 20:07:06 +03005874 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005875
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005876 intel_encoders_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005877
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005878 drm_crtc_vblank_off(crtc);
5879 assert_vblank_disabled(crtc);
5880
Jani Nikula4d1de972016-03-18 17:05:42 +02005881 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005882 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005883 intel_disable_pipe(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005884
Imre Deak24a28172018-06-13 20:07:06 +03005885 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
5886 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
Ville Syrjäläa4bf2142014-08-18 21:27:34 +03005887
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005888 if (!transcoder_is_dsi(cpu_transcoder))
Clint Taylor90c3e212018-07-10 13:02:05 -07005889 intel_ddi_disable_transcoder_func(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005890
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005891 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005892 skylake_scaler_disable(intel_crtc);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005893 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005894 ironlake_pfit_disable(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005895
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005896 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Paulo Zanonic27e9172018-04-27 16:14:36 -07005897
5898 if (INTEL_GEN(dev_priv) >= 11)
5899 icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state);
Imre Deakbdaa29b2018-11-01 16:04:24 +02005900
5901 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005902}
5903
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005904static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes2dd24552013-04-25 12:55:01 -07005905{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005906 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5907 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes2dd24552013-04-25 12:55:01 -07005908
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005909 if (!crtc_state->gmch_pfit.control)
Jesse Barnes2dd24552013-04-25 12:55:01 -07005910 return;
5911
Daniel Vetterc0b03412013-05-28 12:05:54 +02005912 /*
5913 * The panel fitter should only be adjusted whilst the pipe is disabled,
5914 * according to register description and PRM.
5915 */
Jesse Barnes2dd24552013-04-25 12:55:01 -07005916 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5917 assert_pipe_disabled(dev_priv, crtc->pipe);
5918
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005919 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
5920 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
Daniel Vetter5a80c452013-04-25 22:52:18 +02005921
5922 /* Border color in case we don't scale up to the full screen. Black by
5923 * default, change to something else for debugging. */
5924 I915_WRITE(BCLRPAT(crtc->pipe), 0);
Jesse Barnes2dd24552013-04-25 12:55:01 -07005925}
5926
Mahesh Kumar176597a2018-10-04 14:20:43 +05305927bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
5928{
5929 if (port == PORT_NONE)
5930 return false;
5931
5932 if (IS_ICELAKE(dev_priv))
5933 return port <= PORT_B;
5934
5935 return false;
5936}
5937
Paulo Zanoniac213c12018-05-21 17:25:37 -07005938bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
5939{
5940 if (IS_ICELAKE(dev_priv))
5941 return port >= PORT_C && port <= PORT_F;
5942
5943 return false;
5944}
5945
5946enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
5947{
5948 if (!intel_port_is_tc(dev_priv, port))
5949 return PORT_TC_NONE;
5950
5951 return port - PORT_C;
5952}
5953
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02005954enum intel_display_power_domain intel_port_to_power_domain(enum port port)
Dave Airlied05410f2014-06-05 13:22:59 +10005955{
5956 switch (port) {
5957 case PORT_A:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005958 return POWER_DOMAIN_PORT_DDI_A_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005959 case PORT_B:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005960 return POWER_DOMAIN_PORT_DDI_B_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005961 case PORT_C:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005962 return POWER_DOMAIN_PORT_DDI_C_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005963 case PORT_D:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005964 return POWER_DOMAIN_PORT_DDI_D_LANES;
Xiong Zhangd8e19f92015-08-13 18:00:12 +08005965 case PORT_E:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005966 return POWER_DOMAIN_PORT_DDI_E_LANES;
Rodrigo Vivi9787e832018-01-29 15:22:22 -08005967 case PORT_F:
5968 return POWER_DOMAIN_PORT_DDI_F_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005969 default:
Imre Deakb9fec162015-11-18 15:57:25 +02005970 MISSING_CASE(port);
Dave Airlied05410f2014-06-05 13:22:59 +10005971 return POWER_DOMAIN_PORT_OTHER;
5972 }
5973}
5974
Imre Deak337837a2018-11-01 16:04:23 +02005975enum intel_display_power_domain
5976intel_aux_power_domain(struct intel_digital_port *dig_port)
5977{
5978 switch (dig_port->aux_ch) {
5979 case AUX_CH_A:
5980 return POWER_DOMAIN_AUX_A;
5981 case AUX_CH_B:
5982 return POWER_DOMAIN_AUX_B;
5983 case AUX_CH_C:
5984 return POWER_DOMAIN_AUX_C;
5985 case AUX_CH_D:
5986 return POWER_DOMAIN_AUX_D;
5987 case AUX_CH_E:
5988 return POWER_DOMAIN_AUX_E;
5989 case AUX_CH_F:
5990 return POWER_DOMAIN_AUX_F;
5991 default:
5992 MISSING_CASE(dig_port->aux_ch);
5993 return POWER_DOMAIN_AUX_A;
5994 }
5995}
5996
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02005997static u64 get_crtc_power_domains(struct drm_crtc *crtc,
5998 struct intel_crtc_state *crtc_state)
Imre Deak319be8a2014-03-04 19:22:57 +02005999{
6000 struct drm_device *dev = crtc->dev;
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006001 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006002 struct drm_encoder *encoder;
Imre Deak319be8a2014-03-04 19:22:57 +02006003 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6004 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006005 u64 mask;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006006 enum transcoder transcoder = crtc_state->cpu_transcoder;
Imre Deak77d22dc2014-03-05 16:20:52 +02006007
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006008 if (!crtc_state->base.active)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006009 return 0;
6010
Imre Deak17bd6e62018-01-09 14:20:40 +02006011 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6012 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006013 if (crtc_state->pch_pfit.enabled ||
6014 crtc_state->pch_pfit.force_thru)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006015 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
Imre Deak77d22dc2014-03-05 16:20:52 +02006016
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006017 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6018 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6019
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006020 mask |= BIT_ULL(intel_encoder->power_domain);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006021 }
Imre Deak319be8a2014-03-04 19:22:57 +02006022
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006023 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
Imre Deak17bd6e62018-01-09 14:20:40 +02006024 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006025
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006026 if (crtc_state->shared_dpll)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006027 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006028
Imre Deak77d22dc2014-03-05 16:20:52 +02006029 return mask;
6030}
6031
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006032static u64
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006033modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6034 struct intel_crtc_state *crtc_state)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006035{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006036 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006037 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6038 enum intel_display_power_domain domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006039 u64 domains, new_domains, old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006040
6041 old_domains = intel_crtc->enabled_power_domains;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006042 intel_crtc->enabled_power_domains = new_domains =
6043 get_crtc_power_domains(crtc, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006044
Daniel Vetter5a21b662016-05-24 17:13:53 +02006045 domains = new_domains & ~old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006046
6047 for_each_power_domain(domain, domains)
6048 intel_display_power_get(dev_priv, domain);
6049
Daniel Vetter5a21b662016-05-24 17:13:53 +02006050 return old_domains & ~new_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006051}
6052
6053static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006054 u64 domains)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006055{
6056 enum intel_display_power_domain domain;
6057
6058 for_each_power_domain(domain, domains)
6059 intel_display_power_put(dev_priv, domain);
6060}
6061
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006062static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6063 struct drm_atomic_state *old_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006064{
Ville Syrjäläff32c542017-03-02 19:14:57 +02006065 struct intel_atomic_state *old_intel_state =
6066 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006067 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006068 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006069 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006070 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006071 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006072
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006073 if (WARN_ON(intel_crtc->active))
Jesse Barnes89b667f2013-04-18 14:51:36 -07006074 return;
6075
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006076 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006077 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006078
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006079 intel_set_pipe_timings(pipe_config);
6080 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006081
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006082 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjäläc14b0482014-10-16 20:52:34 +03006083 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6084 I915_WRITE(CHV_CANVAS(pipe), 0);
6085 }
6086
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006087 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006088
P Raviraj Sitaramc59d2da2018-09-10 19:57:14 +05306089 intel_color_set_csc(&pipe_config->base);
6090
Jesse Barnes89b667f2013-04-18 14:51:36 -07006091 intel_crtc->active = true;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006092
Daniel Vettera72e4c92014-09-30 10:56:47 +02006093 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006094
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006095 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006096
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006097 if (IS_CHERRYVIEW(dev_priv)) {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006098 chv_prepare_pll(intel_crtc, pipe_config);
6099 chv_enable_pll(intel_crtc, pipe_config);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006100 } else {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006101 vlv_prepare_pll(intel_crtc, pipe_config);
6102 vlv_enable_pll(intel_crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006103 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07006104
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006105 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006106
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006107 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006108
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02006109 intel_color_load_luts(&pipe_config->base);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006110
Ville Syrjäläff32c542017-03-02 19:14:57 +02006111 dev_priv->display.initial_watermarks(old_intel_state,
6112 pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006113 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006114
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006115 assert_vblank_disabled(crtc);
6116 drm_crtc_vblank_on(crtc);
6117
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006118 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006119}
6120
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006121static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006122{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006123 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6124 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006125
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006126 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6127 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006128}
6129
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006130static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6131 struct drm_atomic_state *old_state)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006132{
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006133 struct intel_atomic_state *old_intel_state =
6134 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006135 struct drm_crtc *crtc = pipe_config->base.crtc;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006136 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006137 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -08006138 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006139 enum pipe pipe = intel_crtc->pipe;
Jesse Barnes79e53942008-11-07 14:24:08 -08006140
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006141 if (WARN_ON(intel_crtc->active))
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006142 return;
6143
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006144 i9xx_set_pll_dividers(pipe_config);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006145
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006146 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006147 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006148
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006149 intel_set_pipe_timings(pipe_config);
6150 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006151
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006152 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006153
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006154 intel_crtc->active = true;
Chris Wilson6b383a72010-09-13 13:54:26 +01006155
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01006156 if (!IS_GEN2(dev_priv))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006157 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006158
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006159 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Mika Kuoppala9d6d9f12013-02-08 16:35:38 +02006160
Ville Syrjälä939994d2017-09-13 17:08:56 +03006161 i9xx_enable_pll(intel_crtc, pipe_config);
Daniel Vetterf6736a12013-06-05 13:34:30 +02006162
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006163 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006164
Maarten Lankhorstb95c5322016-03-30 17:16:34 +02006165 intel_color_load_luts(&pipe_config->base);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006166
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006167 if (dev_priv->display.initial_watermarks != NULL)
6168 dev_priv->display.initial_watermarks(old_intel_state,
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006169 pipe_config);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006170 else
6171 intel_update_watermarks(intel_crtc);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006172 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006173
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006174 assert_vblank_disabled(crtc);
6175 drm_crtc_vblank_on(crtc);
6176
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006177 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006178}
6179
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006180static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter87476d62013-04-11 16:29:06 +02006181{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006182 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6183 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter328d8e82013-05-08 10:36:31 +02006184
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006185 if (!old_crtc_state->gmch_pfit.control)
Daniel Vetter328d8e82013-05-08 10:36:31 +02006186 return;
Daniel Vetter87476d62013-04-11 16:29:06 +02006187
6188 assert_pipe_disabled(dev_priv, crtc->pipe);
6189
Chris Wilson43031782018-09-13 14:16:26 +01006190 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6191 I915_READ(PFIT_CONTROL));
Daniel Vetter328d8e82013-05-08 10:36:31 +02006192 I915_WRITE(PFIT_CONTROL, 0);
Daniel Vetter87476d62013-04-11 16:29:06 +02006193}
6194
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006195static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6196 struct drm_atomic_state *old_state)
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006197{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006198 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006199 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006200 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006201 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6202 int pipe = intel_crtc->pipe;
Daniel Vetteref9c3ae2012-06-29 22:40:09 +02006203
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006204 /*
6205 * On gen2 planes are double buffered but the pipe isn't, so we must
6206 * wait for planes to fully turn off before disabling the pipe.
6207 */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01006208 if (IS_GEN2(dev_priv))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02006209 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006210
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006211 intel_encoders_disable(crtc, old_crtc_state, old_state);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006212
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006213 drm_crtc_vblank_off(crtc);
6214 assert_vblank_disabled(crtc);
6215
Ville Syrjälä4972f702017-11-29 17:37:32 +02006216 intel_disable_pipe(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006217
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006218 i9xx_pfit_disable(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006219
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006220 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006221
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006222 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006223 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006224 chv_disable_pll(dev_priv, pipe);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006225 else if (IS_VALLEYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006226 vlv_disable_pll(dev_priv, pipe);
6227 else
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006228 i9xx_disable_pll(old_crtc_state);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006229 }
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006230
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006231 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006232
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01006233 if (!IS_GEN2(dev_priv))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006234 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjäläff32c542017-03-02 19:14:57 +02006235
6236 if (!dev_priv->display.initial_watermarks)
6237 intel_update_watermarks(intel_crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03006238
6239 /* clock the pipe down to 640x480@60 to potentially save power */
6240 if (IS_I830(dev_priv))
6241 i830_enable_pipe(dev_priv, pipe);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006242}
6243
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006244static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6245 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnesee7b9f92012-04-20 17:11:53 +01006246{
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006247 struct intel_encoder *encoder;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006248 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006249 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006250 enum intel_display_power_domain domain;
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006251 struct intel_plane *plane;
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006252 u64 domains;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006253 struct drm_atomic_state *state;
6254 struct intel_crtc_state *crtc_state;
6255 int ret;
Daniel Vetter976f8a22012-07-08 22:34:21 +02006256
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006257 if (!intel_crtc->active)
6258 return;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006259
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006260 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6261 const struct intel_plane_state *plane_state =
6262 to_intel_plane_state(plane->base.state);
Maarten Lankhorst54a419612015-11-23 10:25:28 +01006263
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006264 if (plane_state->base.visible)
6265 intel_plane_disable_noatomic(intel_crtc, plane);
Maarten Lankhorsta5392052015-06-15 12:33:52 +02006266 }
6267
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006268 state = drm_atomic_state_alloc(crtc->dev);
Ander Conselvan de Oliveira31bb2ef2017-01-20 16:28:45 +02006269 if (!state) {
6270 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6271 crtc->base.id, crtc->name);
6272 return;
6273 }
6274
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006275 state->acquire_ctx = ctx;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006276
6277 /* Everything's already locked, -EDEADLK can't happen. */
6278 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6279 ret = drm_atomic_add_affected_connectors(state, crtc);
6280
6281 WARN_ON(IS_ERR(crtc_state) || ret);
6282
6283 dev_priv->display.crtc_disable(crtc_state, state);
6284
Chris Wilson08536952016-10-14 13:18:18 +01006285 drm_atomic_state_put(state);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006286
Ville Syrjälä78108b72016-05-27 20:59:19 +03006287 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6288 crtc->base.id, crtc->name);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006289
6290 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6291 crtc->state->active = false;
Matt Roper37d90782015-09-24 15:53:06 -07006292 intel_crtc->active = false;
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006293 crtc->enabled = false;
6294 crtc->state->connector_mask = 0;
6295 crtc->state->encoder_mask = 0;
6296
6297 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6298 encoder->base.crtc = NULL;
6299
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -02006300 intel_fbc_disable(intel_crtc);
Ville Syrjälä432081b2016-10-31 22:37:03 +02006301 intel_update_watermarks(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02006302 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006303
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006304 domains = intel_crtc->enabled_power_domains;
6305 for_each_power_domain(domain, domains)
6306 intel_display_power_put(dev_priv, domain);
6307 intel_crtc->enabled_power_domains = 0;
Maarten Lankhorst565602d2015-12-10 12:33:57 +01006308
6309 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
Ville Syrjäläd305e062017-08-30 21:57:03 +03006310 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03006311 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006312}
6313
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006314/*
6315 * turn all crtc's off, but do not adjust state
6316 * This has to be paired with a call to intel_modeset_setup_hw_state.
6317 */
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006318int intel_display_suspend(struct drm_device *dev)
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006319{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006320 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006321 struct drm_atomic_state *state;
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006322 int ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006323
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006324 state = drm_atomic_helper_suspend(dev);
6325 ret = PTR_ERR_OR_ZERO(state);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006326 if (ret)
6327 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006328 else
6329 dev_priv->modeset_restore_state = state;
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006330 return ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006331}
6332
Chris Wilsonea5b2132010-08-04 13:50:23 +01006333void intel_encoder_destroy(struct drm_encoder *encoder)
6334{
Chris Wilson4ef69c72010-09-09 15:14:28 +01006335 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
Chris Wilsonea5b2132010-08-04 13:50:23 +01006336
Chris Wilsonea5b2132010-08-04 13:50:23 +01006337 drm_encoder_cleanup(encoder);
6338 kfree(intel_encoder);
6339}
6340
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006341/* Cross check the actual hw state with our own modeset state tracking (and it's
6342 * internal consistency). */
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006343static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6344 struct drm_connector_state *conn_state)
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006345{
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006346 struct intel_connector *connector = to_intel_connector(conn_state->connector);
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006347
6348 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6349 connector->base.base.id,
6350 connector->base.name);
6351
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006352 if (connector->get_hw_state(connector)) {
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006353 struct intel_encoder *encoder = connector->encoder;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006354
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006355 I915_STATE_WARN(!crtc_state,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006356 "connector enabled without attached crtc\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006357
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006358 if (!crtc_state)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006359 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006360
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006361 I915_STATE_WARN(!crtc_state->active,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006362 "connector is active, but attached crtc isn't\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006363
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006364 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006365 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006366
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006367 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006368 "atomic encoder doesn't match attached encoder\n");
Dave Airlie36cd7442014-05-02 13:44:18 +10006369
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006370 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006371 "attached encoder crtc differs from connector crtc\n");
6372 } else {
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006373 I915_STATE_WARN(crtc_state && crtc_state->active,
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02006374 "attached crtc is active, but connector isn't\n");
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006375 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006376 "best encoder set without crtc!\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006377 }
6378}
6379
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006380static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006381{
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006382 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6383 return crtc_state->fdi_lanes;
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006384
6385 return 0;
6386}
6387
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006388static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006389 struct intel_crtc_state *pipe_config)
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006390{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006391 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006392 struct drm_atomic_state *state = pipe_config->base.state;
6393 struct intel_crtc *other_crtc;
6394 struct intel_crtc_state *other_crtc_state;
6395
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006396 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6397 pipe_name(pipe), pipe_config->fdi_lanes);
6398 if (pipe_config->fdi_lanes > 4) {
6399 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6400 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006401 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006402 }
6403
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006404 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006405 if (pipe_config->fdi_lanes > 2) {
6406 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6407 pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006408 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006409 } else {
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006410 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006411 }
6412 }
6413
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +00006414 if (INTEL_INFO(dev_priv)->num_pipes == 2)
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006415 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006416
6417 /* Ivybridge 3 pipe is really complicated */
6418 switch (pipe) {
6419 case PIPE_A:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006420 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006421 case PIPE_B:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006422 if (pipe_config->fdi_lanes <= 2)
6423 return 0;
6424
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006425 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006426 other_crtc_state =
6427 intel_atomic_get_crtc_state(state, other_crtc);
6428 if (IS_ERR(other_crtc_state))
6429 return PTR_ERR(other_crtc_state);
6430
6431 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006432 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6433 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006434 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006435 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006436 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006437 case PIPE_C:
Ville Syrjälä251cc672015-03-11 18:52:30 +02006438 if (pipe_config->fdi_lanes > 2) {
6439 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6440 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006441 return -EINVAL;
Ville Syrjälä251cc672015-03-11 18:52:30 +02006442 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006443
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006444 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006445 other_crtc_state =
6446 intel_atomic_get_crtc_state(state, other_crtc);
6447 if (IS_ERR(other_crtc_state))
6448 return PTR_ERR(other_crtc_state);
6449
6450 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006451 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006452 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006453 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006454 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006455 default:
6456 BUG();
6457 }
6458}
6459
Daniel Vettere29c22c2013-02-21 00:00:16 +01006460#define RETRY 1
6461static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006462 struct intel_crtc_state *pipe_config)
Daniel Vetter877d48d2013-04-19 11:24:43 +02006463{
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006464 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006465 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006466 int lane, link_bw, fdi_dotclock, ret;
6467 bool needs_recompute = false;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006468
Daniel Vettere29c22c2013-02-21 00:00:16 +01006469retry:
Daniel Vetter877d48d2013-04-19 11:24:43 +02006470 /* FDI is a binary signal running at ~2.7GHz, encoding
6471 * each output octet as 10 bits. The actual frequency
6472 * is stored as a divider into a 100MHz clock, and the
6473 * mode pixel clock is stored in units of 1KHz.
6474 * Hence the bw of each lane in terms of the mode signal
6475 * is:
6476 */
Ville Syrjälä21a727b2016-02-17 21:41:10 +02006477 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006478
Damien Lespiau241bfc32013-09-25 16:45:37 +01006479 fdi_dotclock = adjusted_mode->crtc_clock;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006480
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006481 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
Daniel Vetter877d48d2013-04-19 11:24:43 +02006482 pipe_config->pipe_bpp);
6483
6484 pipe_config->fdi_lanes = lane;
6485
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006486 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006487 link_bw, &pipe_config->fdi_m_n, false);
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006488
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02006489 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +02006490 if (ret == -EDEADLK)
6491 return ret;
6492
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006493 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01006494 pipe_config->pipe_bpp -= 2*3;
6495 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6496 pipe_config->pipe_bpp);
6497 needs_recompute = true;
6498 pipe_config->bw_constrained = true;
6499
6500 goto retry;
6501 }
6502
6503 if (needs_recompute)
6504 return RETRY;
6505
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006506 return ret;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006507}
6508
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006509bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006510{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006511 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6512 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6513
6514 /* IPS only exists on ULT machines and is tied to pipe A. */
6515 if (!hsw_crtc_supports_ips(crtc))
Ville Syrjälä6e644622017-08-17 17:55:09 +03006516 return false;
6517
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006518 if (!i915_modparams.enable_ips)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006519 return false;
6520
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006521 if (crtc_state->pipe_bpp > 24)
6522 return false;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006523
6524 /*
Ville Syrjäläb432e5c2015-06-03 15:45:13 +03006525 * We compare against max which means we must take
6526 * the increased cdclk requirement into account when
6527 * calculating the new cdclk.
6528 *
6529 * Should measure whether using a lower cdclk w/o IPS
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006530 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006531 if (IS_BROADWELL(dev_priv) &&
6532 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6533 return false;
6534
6535 return true;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006536}
6537
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006538static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006539{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006540 struct drm_i915_private *dev_priv =
6541 to_i915(crtc_state->base.crtc->dev);
6542 struct intel_atomic_state *intel_state =
6543 to_intel_atomic_state(crtc_state->base.state);
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006544
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006545 if (!hsw_crtc_state_ips_capable(crtc_state))
6546 return false;
6547
6548 if (crtc_state->ips_force_disable)
6549 return false;
6550
Maarten Lankhorstadbe5c52017-11-22 19:39:06 +01006551 /* IPS should be fine as long as at least one plane is enabled. */
6552 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006553 return false;
6554
6555 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6556 if (IS_BROADWELL(dev_priv) &&
6557 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6558 return false;
6559
6560 return true;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006561}
6562
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006563static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6564{
6565 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6566
6567 /* GDG double wide on either pipe, otherwise pipe A only */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00006568 return INTEL_GEN(dev_priv) < 4 &&
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006569 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6570}
6571
Ville Syrjäläceb99322017-01-20 20:22:05 +02006572static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6573{
6574 uint32_t pixel_rate;
6575
6576 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6577
6578 /*
6579 * We only use IF-ID interlacing. If we ever use
6580 * PF-ID we'll need to adjust the pixel_rate here.
6581 */
6582
6583 if (pipe_config->pch_pfit.enabled) {
6584 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6585 uint32_t pfit_size = pipe_config->pch_pfit.size;
6586
6587 pipe_w = pipe_config->pipe_src_w;
6588 pipe_h = pipe_config->pipe_src_h;
6589
6590 pfit_w = (pfit_size >> 16) & 0xFFFF;
6591 pfit_h = pfit_size & 0xFFFF;
6592 if (pipe_w < pfit_w)
6593 pipe_w = pfit_w;
6594 if (pipe_h < pfit_h)
6595 pipe_h = pfit_h;
6596
6597 if (WARN_ON(!pfit_w || !pfit_h))
6598 return pixel_rate;
6599
6600 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6601 pfit_w * pfit_h);
6602 }
6603
6604 return pixel_rate;
6605}
6606
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006607static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6608{
6609 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6610
6611 if (HAS_GMCH_DISPLAY(dev_priv))
6612 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6613 crtc_state->pixel_rate =
6614 crtc_state->base.adjusted_mode.crtc_clock;
6615 else
6616 crtc_state->pixel_rate =
6617 ilk_pipe_pixel_rate(crtc_state);
6618}
6619
Daniel Vettera43f6e02013-06-07 23:10:32 +02006620static int intel_crtc_compute_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006621 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -08006622{
Daniel Vettera43f6e02013-06-07 23:10:32 +02006623 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006624 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006625 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläf3261152016-05-24 21:34:18 +03006626 int clock_limit = dev_priv->max_dotclk_freq;
Chris Wilson89749352010-09-12 18:25:19 +01006627
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006628 if (INTEL_GEN(dev_priv) < 4) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006629 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006630
6631 /*
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006632 * Enable double wide mode when the dot clock
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006633 * is > 90% of the (display) core speed.
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006634 */
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006635 if (intel_crtc_supports_double_wide(crtc) &&
6636 adjusted_mode->crtc_clock > clock_limit) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006637 clock_limit = dev_priv->max_dotclk_freq;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006638 pipe_config->double_wide = true;
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006639 }
Ville Syrjäläf3261152016-05-24 21:34:18 +03006640 }
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006641
Ville Syrjäläf3261152016-05-24 21:34:18 +03006642 if (adjusted_mode->crtc_clock > clock_limit) {
6643 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6644 adjusted_mode->crtc_clock, clock_limit,
6645 yesno(pipe_config->double_wide));
6646 return -EINVAL;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006647 }
Chris Wilson89749352010-09-12 18:25:19 +01006648
Shashank Sharma8c79f842018-10-12 11:53:09 +05306649 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6650 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6651 pipe_config->base.ctm) {
Shashank Sharma25edf912017-07-21 20:55:07 +05306652 /*
6653 * There is only one pipe CSC unit per pipe, and we need that
6654 * for output conversion from RGB->YCBCR. So if CTM is already
6655 * applied we can't support YCBCR420 output.
6656 */
6657 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6658 return -EINVAL;
6659 }
6660
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006661 /*
6662 * Pipe horizontal size must be even in:
6663 * - DVO ganged mode
6664 * - LVDS dual channel mode
6665 * - Double wide pipe
6666 */
Ville Syrjälä0574bd82017-11-23 21:04:48 +02006667 if (pipe_config->pipe_src_w & 1) {
6668 if (pipe_config->double_wide) {
6669 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6670 return -EINVAL;
6671 }
6672
6673 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6674 intel_is_dual_link_lvds(dev)) {
6675 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6676 return -EINVAL;
6677 }
6678 }
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006679
Damien Lespiau8693a822013-05-03 18:48:11 +01006680 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6681 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
Chris Wilson44f46b422012-06-21 13:19:59 +03006682 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01006683 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
Ville Syrjäläaad941d2015-09-25 16:38:56 +03006684 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
Daniel Vettere29c22c2013-02-21 00:00:16 +01006685 return -EINVAL;
Chris Wilson44f46b422012-06-21 13:19:59 +03006686
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006687 intel_crtc_compute_pixel_rate(pipe_config);
6688
Daniel Vetter877d48d2013-04-19 11:24:43 +02006689 if (pipe_config->has_pch_encoder)
Daniel Vettera43f6e02013-06-07 23:10:32 +02006690 return ironlake_fdi_compute_config(crtc, pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006691
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +02006692 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08006693}
6694
Zhenyu Wang2c072452009-06-05 15:38:42 +08006695static void
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006696intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006697{
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006698 while (*num > DATA_LINK_M_N_MASK ||
6699 *den > DATA_LINK_M_N_MASK) {
Zhenyu Wang2c072452009-06-05 15:38:42 +08006700 *num >>= 1;
6701 *den >>= 1;
6702 }
6703}
6704
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006705static void compute_m_n(unsigned int m, unsigned int n,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006706 uint32_t *ret_m, uint32_t *ret_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006707 bool constant_n)
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006708{
Jani Nikula9a86cda2017-03-27 14:33:25 +03006709 /*
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006710 * Several DP dongles in particular seem to be fussy about
6711 * too large link M/N values. Give N value as 0x8000 that
6712 * should be acceptable by specific devices. 0x8000 is the
6713 * specified fixed N value for asynchronous clock mode,
6714 * which the devices expect also in synchronous clock mode.
Jani Nikula9a86cda2017-03-27 14:33:25 +03006715 */
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006716 if (constant_n)
6717 *ret_n = 0x8000;
6718 else
6719 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
Jani Nikula9a86cda2017-03-27 14:33:25 +03006720
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006721 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6722 intel_reduce_m_n_ratio(ret_m, ret_n);
6723}
6724
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006725void
6726intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6727 int pixel_clock, int link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006728 struct intel_link_m_n *m_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006729 bool constant_n)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006730{
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006731 m_n->tu = 64;
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006732
6733 compute_m_n(bits_per_pixel * pixel_clock,
6734 link_clock * nlanes * 8,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006735 &m_n->gmch_m, &m_n->gmch_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006736 constant_n);
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006737
6738 compute_m_n(pixel_clock, link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006739 &m_n->link_m, &m_n->link_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006740 constant_n);
Zhenyu Wang2c072452009-06-05 15:38:42 +08006741}
6742
Chris Wilsona7615032011-01-12 17:04:08 +00006743static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6744{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00006745 if (i915_modparams.panel_use_ssc >= 0)
6746 return i915_modparams.panel_use_ssc != 0;
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03006747 return dev_priv->vbt.lvds_use_ssc
Keith Packard435793d2011-07-12 14:56:22 -07006748 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
Chris Wilsona7615032011-01-12 17:04:08 +00006749}
6750
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006751static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006752{
Daniel Vetter7df00d72013-05-21 21:54:55 +02006753 return (1 << dpll->n) << 16 | dpll->m2;
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006754}
Daniel Vetterf47709a2013-03-28 10:42:02 +01006755
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006756static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6757{
6758 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006759}
6760
Daniel Vetterf47709a2013-03-28 10:42:02 +01006761static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006762 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03006763 struct dpll *reduced_clock)
Jesse Barnesa7516a02011-12-15 12:30:37 -08006764{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006765 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006766 u32 fp, fp2 = 0;
6767
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006768 if (IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006769 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006770 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006771 fp2 = pnv_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006772 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006773 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006774 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006775 fp2 = i9xx_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006776 }
6777
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006778 crtc_state->dpll_hw_state.fp0 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006779
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03006780 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Rodrigo Viviab585de2015-03-24 12:40:09 -07006781 reduced_clock) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006782 crtc_state->dpll_hw_state.fp1 = fp2;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006783 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006784 crtc_state->dpll_hw_state.fp1 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006785 }
6786}
6787
Chon Ming Lee5e69f972013-09-05 20:41:49 +08006788static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6789 pipe)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006790{
6791 u32 reg_val;
6792
6793 /*
6794 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6795 * and set it to a reasonable value instead.
6796 */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006797 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006798 reg_val &= 0xffffff00;
6799 reg_val |= 0x00000030;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006800 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006801
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006802 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Imre Deaked585702017-05-10 12:21:47 +03006803 reg_val &= 0x00ffffff;
6804 reg_val |= 0x8c000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006805 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006806
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006807 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006808 reg_val &= 0xffffff00;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006809 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006810
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006811 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006812 reg_val &= 0x00ffffff;
6813 reg_val |= 0xb0000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006814 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006815}
6816
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006817static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6818 const struct intel_link_m_n *m_n)
Daniel Vetterb5518422013-05-03 11:49:48 +02006819{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006820 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6821 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6822 enum pipe pipe = crtc->pipe;
Daniel Vetterb5518422013-05-03 11:49:48 +02006823
Daniel Vettere3b95f12013-05-03 11:49:49 +02006824 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6825 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6826 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6827 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02006828}
6829
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006830static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
6831 enum transcoder transcoder)
6832{
6833 if (IS_HASWELL(dev_priv))
6834 return transcoder == TRANSCODER_EDP;
6835
6836 /*
6837 * Strictly speaking some registers are available before
6838 * gen7, but we only support DRRS on gen7+
6839 */
6840 return IS_GEN7(dev_priv) || IS_CHERRYVIEW(dev_priv);
6841}
6842
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006843static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6844 const struct intel_link_m_n *m_n,
6845 const struct intel_link_m_n *m2_n2)
Daniel Vetterb5518422013-05-03 11:49:48 +02006846{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006847 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006848 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006849 enum pipe pipe = crtc->pipe;
6850 enum transcoder transcoder = crtc_state->cpu_transcoder;
Daniel Vetterb5518422013-05-03 11:49:48 +02006851
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006852 if (INTEL_GEN(dev_priv) >= 5) {
Daniel Vetterb5518422013-05-03 11:49:48 +02006853 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6854 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6855 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6856 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006857 /*
6858 * M2_N2 registers are set only if DRRS is supported
6859 * (to make sure the registers are not unnecessarily accessed).
Vandana Kannanf769cd22014-08-05 07:51:22 -07006860 */
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006861 if (m2_n2 && crtc_state->has_drrs &&
6862 transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07006863 I915_WRITE(PIPE_DATA_M2(transcoder),
6864 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6865 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6866 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6867 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6868 }
Daniel Vetterb5518422013-05-03 11:49:48 +02006869 } else {
Daniel Vettere3b95f12013-05-03 11:49:49 +02006870 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6871 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6872 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6873 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02006874 }
6875}
6876
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006877void 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 +02006878{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006879 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306880
6881 if (m_n == M1_N1) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006882 dp_m_n = &crtc_state->dp_m_n;
6883 dp_m2_n2 = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306884 } else if (m_n == M2_N2) {
6885
6886 /*
6887 * M2_N2 registers are not supported. Hence m2_n2 divider value
6888 * needs to be programmed into M1_N1.
6889 */
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006890 dp_m_n = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306891 } else {
6892 DRM_ERROR("Unsupported divider value\n");
6893 return;
6894 }
6895
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006896 if (crtc_state->has_pch_encoder)
6897 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006898 else
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006899 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006900}
6901
Daniel Vetter251ac862015-06-18 10:30:24 +02006902static void vlv_compute_dpll(struct intel_crtc *crtc,
6903 struct intel_crtc_state *pipe_config)
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006904{
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006905 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006906 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006907 if (crtc->pipe != PIPE_A)
6908 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006909
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006910 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006911 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006912 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6913 DPLL_EXT_BUFFER_ENABLE_VLV;
6914
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006915 pipe_config->dpll_hw_state.dpll_md =
6916 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6917}
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006918
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006919static void chv_compute_dpll(struct intel_crtc *crtc,
6920 struct intel_crtc_state *pipe_config)
6921{
6922 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006923 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006924 if (crtc->pipe != PIPE_A)
6925 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6926
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006927 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006928 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006929 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6930
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006931 pipe_config->dpll_hw_state.dpll_md =
6932 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006933}
6934
Ville Syrjäläd288f652014-10-28 13:20:22 +02006935static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006936 const struct intel_crtc_state *pipe_config)
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006937{
Daniel Vetterf47709a2013-03-28 10:42:02 +01006938 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006939 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006940 enum pipe pipe = crtc->pipe;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006941 u32 mdiv;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006942 u32 bestn, bestm1, bestm2, bestp1, bestp2;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006943 u32 coreclk, reg_val;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006944
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006945 /* Enable Refclk */
6946 I915_WRITE(DPLL(pipe),
6947 pipe_config->dpll_hw_state.dpll &
6948 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6949
6950 /* No need to actually set up the DPLL with DSI */
6951 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6952 return;
6953
Ville Syrjäläa5805162015-05-26 20:42:30 +03006954 mutex_lock(&dev_priv->sb_lock);
Daniel Vetter09153002012-12-12 14:06:44 +01006955
Ville Syrjäläd288f652014-10-28 13:20:22 +02006956 bestn = pipe_config->dpll.n;
6957 bestm1 = pipe_config->dpll.m1;
6958 bestm2 = pipe_config->dpll.m2;
6959 bestp1 = pipe_config->dpll.p1;
6960 bestp2 = pipe_config->dpll.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006961
Jesse Barnes89b667f2013-04-18 14:51:36 -07006962 /* See eDP HDMI DPIO driver vbios notes doc */
6963
6964 /* PLL B needs special handling */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006965 if (pipe == PIPE_B)
Chon Ming Lee5e69f972013-09-05 20:41:49 +08006966 vlv_pllb_recal_opamp(dev_priv, pipe);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006967
6968 /* Set up Tx target for periodic Rcomp update */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006969 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006970
6971 /* Disable target IRef on PLL */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006972 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006973 reg_val &= 0x00ffffff;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006974 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006975
6976 /* Disable fast lock */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006977 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006978
6979 /* Set idtafcrecal before PLL is enabled */
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006980 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6981 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6982 mdiv |= ((bestn << DPIO_N_SHIFT));
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006983 mdiv |= (1 << DPIO_K_SHIFT);
Jesse Barnes7df50802013-05-02 10:48:09 -07006984
6985 /*
6986 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6987 * but we don't support that).
6988 * Note: don't use the DAC post divider as it seems unstable.
6989 */
6990 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006991 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006992
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006993 mdiv |= DPIO_ENABLE_CALIBRATION;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006994 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006995
Jesse Barnes89b667f2013-04-18 14:51:36 -07006996 /* Set HBR and RBR LPF coefficients */
Ville Syrjäläd288f652014-10-28 13:20:22 +02006997 if (pipe_config->port_clock == 162000 ||
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02006998 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
6999 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007000 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Ville Syrjälä885b01202013-07-05 19:21:38 +03007001 0x009f0003);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007002 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007003 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007004 0x00d0000f);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007005
Ville Syrjälä37a56502016-06-22 21:57:04 +03007006 if (intel_crtc_has_dp_encoder(pipe_config)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07007007 /* Use SSC source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007008 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007009 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007010 0x0df40000);
7011 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007012 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007013 0x0df70000);
7014 } else { /* HDMI or VGA */
7015 /* Use bend source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007016 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007017 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007018 0x0df70000);
7019 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007020 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007021 0x0df40000);
7022 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007023
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007024 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007025 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007026 if (intel_crtc_has_dp_encoder(pipe_config))
Jesse Barnes89b667f2013-04-18 14:51:36 -07007027 coreclk |= 0x01000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007028 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007029
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007030 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
Ville Syrjäläa5805162015-05-26 20:42:30 +03007031 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007032}
7033
Ville Syrjäläd288f652014-10-28 13:20:22 +02007034static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007035 const struct intel_crtc_state *pipe_config)
Ville Syrjälä1ae0d132014-06-28 02:04:00 +03007036{
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007037 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007038 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007039 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007040 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307041 u32 loopfilter, tribuf_calcntr;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007042 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307043 u32 dpio_val;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307044 int vco;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007045
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007046 /* Enable Refclk and SSC */
7047 I915_WRITE(DPLL(pipe),
7048 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7049
7050 /* No need to actually set up the DPLL with DSI */
7051 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7052 return;
7053
Ville Syrjäläd288f652014-10-28 13:20:22 +02007054 bestn = pipe_config->dpll.n;
7055 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7056 bestm1 = pipe_config->dpll.m1;
7057 bestm2 = pipe_config->dpll.m2 >> 22;
7058 bestp1 = pipe_config->dpll.p1;
7059 bestp2 = pipe_config->dpll.p2;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307060 vco = pipe_config->dpll.vco;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307061 dpio_val = 0;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307062 loopfilter = 0;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007063
Ville Syrjäläa5805162015-05-26 20:42:30 +03007064 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007065
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007066 /* p1 and p2 divider */
7067 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7068 5 << DPIO_CHV_S1_DIV_SHIFT |
7069 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7070 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7071 1 << DPIO_CHV_K_DIV_SHIFT);
7072
7073 /* Feedback post-divider - m2 */
7074 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7075
7076 /* Feedback refclk divider - n and m1 */
7077 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7078 DPIO_CHV_M1_DIV_BY_2 |
7079 1 << DPIO_CHV_N_DIV_SHIFT);
7080
7081 /* M2 fraction division */
Ville Syrjälä25a25df2015-07-08 23:45:47 +03007082 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007083
7084 /* M2 fraction division enable */
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307085 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7086 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7087 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7088 if (bestm2_frac)
7089 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7090 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007091
Vijay Purushothamande3a0fd2015-03-05 19:32:06 +05307092 /* Program digital lock detect threshold */
7093 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7094 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7095 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7096 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7097 if (!bestm2_frac)
7098 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7099 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7100
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007101 /* Loop filter */
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307102 if (vco == 5400000) {
7103 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7104 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7105 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7106 tribuf_calcntr = 0x9;
7107 } else if (vco <= 6200000) {
7108 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7109 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7110 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7111 tribuf_calcntr = 0x9;
7112 } else if (vco <= 6480000) {
7113 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7114 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7115 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7116 tribuf_calcntr = 0x8;
7117 } else {
7118 /* Not supported. Apply the same limits as in the max case */
7119 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7120 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7121 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7122 tribuf_calcntr = 0;
7123 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007124 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7125
Ville Syrjälä968040b2015-03-11 22:52:08 +02007126 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307127 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7128 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7129 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7130
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007131 /* AFC Recal */
7132 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7133 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7134 DPIO_AFC_RECAL);
7135
Ville Syrjäläa5805162015-05-26 20:42:30 +03007136 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007137}
7138
Ville Syrjäläd288f652014-10-28 13:20:22 +02007139/**
7140 * vlv_force_pll_on - forcibly enable just the PLL
7141 * @dev_priv: i915 private structure
7142 * @pipe: pipe PLL to enable
7143 * @dpll: PLL configuration
7144 *
7145 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7146 * in cases where we need the PLL enabled even when @pipe is not going to
7147 * be enabled.
7148 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007149int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007150 const struct dpll *dpll)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007151{
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02007152 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007153 struct intel_crtc_state *pipe_config;
7154
7155 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7156 if (!pipe_config)
7157 return -ENOMEM;
7158
7159 pipe_config->base.crtc = &crtc->base;
7160 pipe_config->pixel_multiplier = 1;
7161 pipe_config->dpll = *dpll;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007162
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007163 if (IS_CHERRYVIEW(dev_priv)) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007164 chv_compute_dpll(crtc, pipe_config);
7165 chv_prepare_pll(crtc, pipe_config);
7166 chv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007167 } else {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007168 vlv_compute_dpll(crtc, pipe_config);
7169 vlv_prepare_pll(crtc, pipe_config);
7170 vlv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007171 }
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007172
7173 kfree(pipe_config);
7174
7175 return 0;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007176}
7177
7178/**
7179 * vlv_force_pll_off - forcibly disable just the PLL
7180 * @dev_priv: i915 private structure
7181 * @pipe: pipe PLL to disable
7182 *
7183 * Disable the PLL for @pipe. To be used in cases where we need
7184 * the PLL enabled even when @pipe is not going to be enabled.
7185 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007186void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007187{
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007188 if (IS_CHERRYVIEW(dev_priv))
7189 chv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007190 else
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007191 vlv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007192}
7193
Daniel Vetter251ac862015-06-18 10:30:24 +02007194static void i9xx_compute_dpll(struct intel_crtc *crtc,
7195 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007196 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007197{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007198 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007199 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007200 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007201
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007202 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307203
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007204 dpll = DPLL_VGA_MODE_DIS;
7205
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007206 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007207 dpll |= DPLLB_MODE_LVDS;
7208 else
7209 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter6cc5f342013-03-27 00:44:53 +01007210
Jani Nikula73f67aa2016-12-07 22:48:09 +02007211 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7212 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007213 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetter198a037f2013-04-19 11:14:37 +02007214 << SDVO_MULTIPLIER_SHIFT_HIRES;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007215 }
Daniel Vetter198a037f2013-04-19 11:14:37 +02007216
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03007217 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7218 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007219 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vetter198a037f2013-04-19 11:14:37 +02007220
Ville Syrjälä37a56502016-06-22 21:57:04 +03007221 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007222 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007223
7224 /* compute bitmask from p1 value */
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007225 if (IS_PINEVIEW(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007226 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7227 else {
7228 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007229 if (IS_G4X(dev_priv) && reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007230 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7231 }
7232 switch (clock->p2) {
7233 case 5:
7234 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7235 break;
7236 case 7:
7237 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7238 break;
7239 case 10:
7240 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7241 break;
7242 case 14:
7243 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7244 break;
7245 }
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007246 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007247 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7248
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007249 if (crtc_state->sdvo_tv_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007250 dpll |= PLL_REF_INPUT_TVCLKINBC;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007251 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007252 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007253 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7254 else
7255 dpll |= PLL_REF_INPUT_DREFCLK;
7256
7257 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007258 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007259
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007260 if (INTEL_GEN(dev_priv) >= 4) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007261 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02007262 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007263 crtc_state->dpll_hw_state.dpll_md = dpll_md;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007264 }
7265}
7266
Daniel Vetter251ac862015-06-18 10:30:24 +02007267static void i8xx_compute_dpll(struct intel_crtc *crtc,
7268 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007269 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007270{
Daniel Vetterf47709a2013-03-28 10:42:02 +01007271 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007272 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007273 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007274 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007275
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007276 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307277
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007278 dpll = DPLL_VGA_MODE_DIS;
7279
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007280 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007281 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7282 } else {
7283 if (clock->p1 == 2)
7284 dpll |= PLL_P1_DIVIDE_BY_TWO;
7285 else
7286 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7287 if (clock->p2 == 4)
7288 dpll |= PLL_P2_DIVIDE_BY_4;
7289 }
7290
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007291 if (!IS_I830(dev_priv) &&
7292 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007293 dpll |= DPLL_DVO_2X_MODE;
7294
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007295 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007296 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007297 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7298 else
7299 dpll |= PLL_REF_INPUT_DREFCLK;
7300
7301 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007302 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007303}
7304
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007305static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007306{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007307 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7308 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7309 enum pipe pipe = crtc->pipe;
7310 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7311 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007312 uint32_t crtc_vtotal, crtc_vblank_end;
7313 int vsyncshift = 0;
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007314
7315 /* We need to be careful not to changed the adjusted mode, for otherwise
7316 * the hw state checker will get angry at the mismatch. */
7317 crtc_vtotal = adjusted_mode->crtc_vtotal;
7318 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007319
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007320 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007321 /* the chip adds 2 halflines automatically */
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007322 crtc_vtotal -= 1;
7323 crtc_vblank_end -= 1;
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007324
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007325 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007326 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7327 else
7328 vsyncshift = adjusted_mode->crtc_hsync_start -
7329 adjusted_mode->crtc_htotal / 2;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007330 if (vsyncshift < 0)
7331 vsyncshift += adjusted_mode->crtc_htotal;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007332 }
7333
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007334 if (INTEL_GEN(dev_priv) > 3)
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007335 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007336
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007337 I915_WRITE(HTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007338 (adjusted_mode->crtc_hdisplay - 1) |
7339 ((adjusted_mode->crtc_htotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007340 I915_WRITE(HBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007341 (adjusted_mode->crtc_hblank_start - 1) |
7342 ((adjusted_mode->crtc_hblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007343 I915_WRITE(HSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007344 (adjusted_mode->crtc_hsync_start - 1) |
7345 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7346
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007347 I915_WRITE(VTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007348 (adjusted_mode->crtc_vdisplay - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007349 ((crtc_vtotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007350 I915_WRITE(VBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007351 (adjusted_mode->crtc_vblank_start - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007352 ((crtc_vblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007353 I915_WRITE(VSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007354 (adjusted_mode->crtc_vsync_start - 1) |
7355 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7356
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007357 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7358 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7359 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7360 * bits. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01007361 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007362 (pipe == PIPE_B || pipe == PIPE_C))
7363 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7364
Jani Nikulabc58be62016-03-18 17:05:39 +02007365}
7366
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007367static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
Jani Nikulabc58be62016-03-18 17:05:39 +02007368{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007369 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7370 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7371 enum pipe pipe = crtc->pipe;
Jani Nikulabc58be62016-03-18 17:05:39 +02007372
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007373 /* pipesrc controls the size that is scaled from, which should
7374 * always be the user's requested size.
7375 */
7376 I915_WRITE(PIPESRC(pipe),
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007377 ((crtc_state->pipe_src_w - 1) << 16) |
7378 (crtc_state->pipe_src_h - 1));
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007379}
7380
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007381static void intel_get_pipe_timings(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007382 struct intel_crtc_state *pipe_config)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007383{
7384 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007385 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007386 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7387 uint32_t tmp;
7388
7389 tmp = I915_READ(HTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007390 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7391 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007392 tmp = I915_READ(HBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007393 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7394 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007395 tmp = I915_READ(HSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007396 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7397 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007398
7399 tmp = I915_READ(VTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007400 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7401 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007402 tmp = I915_READ(VBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007403 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7404 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007405 tmp = I915_READ(VSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007406 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7407 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007408
7409 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007410 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7411 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7412 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007413 }
Jani Nikulabc58be62016-03-18 17:05:39 +02007414}
7415
7416static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7417 struct intel_crtc_state *pipe_config)
7418{
7419 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007420 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulabc58be62016-03-18 17:05:39 +02007421 u32 tmp;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007422
7423 tmp = I915_READ(PIPESRC(crtc->pipe));
Ville Syrjälä37327ab2013-09-04 18:25:28 +03007424 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7425 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7426
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007427 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7428 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007429}
7430
Daniel Vetterf6a83282014-02-11 15:28:57 -08007431void intel_mode_from_pipe_config(struct drm_display_mode *mode,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007432 struct intel_crtc_state *pipe_config)
Jesse Barnesbabea612013-06-26 18:57:38 +03007433{
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007434 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7435 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7436 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7437 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007438
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007439 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7440 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7441 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7442 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007443
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007444 mode->flags = pipe_config->base.adjusted_mode.flags;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007445 mode->type = DRM_MODE_TYPE_DRIVER;
Jesse Barnesbabea612013-06-26 18:57:38 +03007446
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007447 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007448
7449 mode->hsync = drm_mode_hsync(mode);
7450 mode->vrefresh = drm_mode_vrefresh(mode);
7451 drm_mode_set_name(mode);
Jesse Barnesbabea612013-06-26 18:57:38 +03007452}
7453
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007454static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
Daniel Vetter84b046f2013-02-19 18:48:54 +01007455{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007456 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7457 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter84b046f2013-02-19 18:48:54 +01007458 uint32_t pipeconf;
7459
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007460 pipeconf = 0;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007461
Ville Syrjäläe56134b2017-06-01 17:36:19 +03007462 /* we keep both pipes enabled on 830 */
7463 if (IS_I830(dev_priv))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007464 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
Daniel Vetter67c72a12013-09-24 11:46:14 +02007465
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007466 if (crtc_state->double_wide)
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03007467 pipeconf |= PIPECONF_DOUBLE_WIDE;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007468
Daniel Vetterff9ce462013-04-24 14:57:17 +02007469 /* only g4x and later have fancy bpc/dither controls */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007470 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7471 IS_CHERRYVIEW(dev_priv)) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007472 /* Bspec claims that we can't use dithering for 30bpp pipes. */
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007473 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
Daniel Vetterff9ce462013-04-24 14:57:17 +02007474 pipeconf |= PIPECONF_DITHER_EN |
7475 PIPECONF_DITHER_TYPE_SP;
7476
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007477 switch (crtc_state->pipe_bpp) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007478 case 18:
7479 pipeconf |= PIPECONF_6BPC;
7480 break;
7481 case 24:
7482 pipeconf |= PIPECONF_8BPC;
7483 break;
7484 case 30:
7485 pipeconf |= PIPECONF_10BPC;
7486 break;
7487 default:
7488 /* Case prevented by intel_choose_pipe_bpp_dither. */
7489 BUG();
Daniel Vetter84b046f2013-02-19 18:48:54 +01007490 }
7491 }
7492
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007493 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007494 if (INTEL_GEN(dev_priv) < 4 ||
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007495 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjäläefc2cff2014-03-28 23:29:31 +02007496 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7497 else
7498 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7499 } else
Daniel Vetter84b046f2013-02-19 18:48:54 +01007500 pipeconf |= PIPECONF_PROGRESSIVE;
7501
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007502 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007503 crtc_state->limited_color_range)
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007504 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä9c8e09b2013-04-02 16:10:09 +03007505
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007506 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7507 POSTING_READ(PIPECONF(crtc->pipe));
Daniel Vetter84b046f2013-02-19 18:48:54 +01007508}
7509
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007510static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7511 struct intel_crtc_state *crtc_state)
7512{
7513 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007514 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007515 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007516 int refclk = 48000;
7517
7518 memset(&crtc_state->dpll_hw_state, 0,
7519 sizeof(crtc_state->dpll_hw_state));
7520
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007521 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007522 if (intel_panel_use_ssc(dev_priv)) {
7523 refclk = dev_priv->vbt.lvds_ssc_freq;
7524 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7525 }
7526
7527 limit = &intel_limits_i8xx_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007528 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007529 limit = &intel_limits_i8xx_dvo;
7530 } else {
7531 limit = &intel_limits_i8xx_dac;
7532 }
7533
7534 if (!crtc_state->clock_set &&
7535 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7536 refclk, NULL, &crtc_state->dpll)) {
7537 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7538 return -EINVAL;
7539 }
7540
7541 i8xx_compute_dpll(crtc, crtc_state, NULL);
7542
7543 return 0;
7544}
7545
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007546static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7547 struct intel_crtc_state *crtc_state)
7548{
7549 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007550 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007551 const struct intel_limit *limit;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007552 int refclk = 96000;
7553
7554 memset(&crtc_state->dpll_hw_state, 0,
7555 sizeof(crtc_state->dpll_hw_state));
7556
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007557 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007558 if (intel_panel_use_ssc(dev_priv)) {
7559 refclk = dev_priv->vbt.lvds_ssc_freq;
7560 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7561 }
7562
7563 if (intel_is_dual_link_lvds(dev))
7564 limit = &intel_limits_g4x_dual_channel_lvds;
7565 else
7566 limit = &intel_limits_g4x_single_channel_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007567 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7568 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007569 limit = &intel_limits_g4x_hdmi;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007570 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007571 limit = &intel_limits_g4x_sdvo;
7572 } else {
7573 /* The option is for other outputs */
7574 limit = &intel_limits_i9xx_sdvo;
7575 }
7576
7577 if (!crtc_state->clock_set &&
7578 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7579 refclk, NULL, &crtc_state->dpll)) {
7580 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7581 return -EINVAL;
7582 }
7583
7584 i9xx_compute_dpll(crtc, crtc_state, NULL);
7585
7586 return 0;
7587}
7588
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007589static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7590 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08007591{
Ander Conselvan de Oliveirac7653192014-10-20 13:46:44 +03007592 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007593 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007594 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007595 int refclk = 96000;
Jesse Barnes79e53942008-11-07 14:24:08 -08007596
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03007597 memset(&crtc_state->dpll_hw_state, 0,
7598 sizeof(crtc_state->dpll_hw_state));
7599
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007600 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007601 if (intel_panel_use_ssc(dev_priv)) {
7602 refclk = dev_priv->vbt.lvds_ssc_freq;
7603 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7604 }
Jesse Barnes79e53942008-11-07 14:24:08 -08007605
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007606 limit = &intel_limits_pineview_lvds;
7607 } else {
7608 limit = &intel_limits_pineview_sdvo;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007609 }
Jani Nikulaf2335332013-09-13 11:03:09 +03007610
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007611 if (!crtc_state->clock_set &&
7612 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7613 refclk, NULL, &crtc_state->dpll)) {
7614 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7615 return -EINVAL;
7616 }
7617
7618 i9xx_compute_dpll(crtc, crtc_state, NULL);
7619
7620 return 0;
7621}
7622
7623static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7624 struct intel_crtc_state *crtc_state)
7625{
7626 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007627 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007628 const struct intel_limit *limit;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007629 int refclk = 96000;
7630
7631 memset(&crtc_state->dpll_hw_state, 0,
7632 sizeof(crtc_state->dpll_hw_state));
7633
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007634 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007635 if (intel_panel_use_ssc(dev_priv)) {
7636 refclk = dev_priv->vbt.lvds_ssc_freq;
7637 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
Jani Nikulae9fd1c02013-08-27 15:12:23 +03007638 }
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007639
7640 limit = &intel_limits_i9xx_lvds;
7641 } else {
7642 limit = &intel_limits_i9xx_sdvo;
7643 }
7644
7645 if (!crtc_state->clock_set &&
7646 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7647 refclk, NULL, &crtc_state->dpll)) {
7648 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7649 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01007650 }
Eric Anholtf564048e2011-03-30 13:01:02 -07007651
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007652 i9xx_compute_dpll(crtc, crtc_state, NULL);
Eric Anholtf564048e2011-03-30 13:01:02 -07007653
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02007654 return 0;
Eric Anholtf564048e2011-03-30 13:01:02 -07007655}
7656
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007657static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7658 struct intel_crtc_state *crtc_state)
7659{
7660 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007661 const struct intel_limit *limit = &intel_limits_chv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007662
7663 memset(&crtc_state->dpll_hw_state, 0,
7664 sizeof(crtc_state->dpll_hw_state));
7665
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007666 if (!crtc_state->clock_set &&
7667 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7668 refclk, NULL, &crtc_state->dpll)) {
7669 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7670 return -EINVAL;
7671 }
7672
7673 chv_compute_dpll(crtc, crtc_state);
7674
7675 return 0;
7676}
7677
7678static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7679 struct intel_crtc_state *crtc_state)
7680{
7681 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007682 const struct intel_limit *limit = &intel_limits_vlv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007683
7684 memset(&crtc_state->dpll_hw_state, 0,
7685 sizeof(crtc_state->dpll_hw_state));
7686
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007687 if (!crtc_state->clock_set &&
7688 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7689 refclk, NULL, &crtc_state->dpll)) {
7690 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7691 return -EINVAL;
7692 }
7693
7694 vlv_compute_dpll(crtc, crtc_state);
7695
7696 return 0;
7697}
7698
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007699static void i9xx_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007700 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007701{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007702 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007703 uint32_t tmp;
7704
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007705 if (INTEL_GEN(dev_priv) <= 3 &&
7706 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
Ville Syrjälädc9e7dec2014-01-10 14:06:45 +02007707 return;
7708
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007709 tmp = I915_READ(PFIT_CONTROL);
Daniel Vetter06922822013-07-11 13:35:40 +02007710 if (!(tmp & PFIT_ENABLE))
7711 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007712
Daniel Vetter06922822013-07-11 13:35:40 +02007713 /* Check whether the pfit is attached to our pipe. */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007714 if (INTEL_GEN(dev_priv) < 4) {
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007715 if (crtc->pipe != PIPE_B)
7716 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007717 } else {
7718 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7719 return;
7720 }
7721
Daniel Vetter06922822013-07-11 13:35:40 +02007722 pipe_config->gmch_pfit.control = tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007723 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007724}
7725
Jesse Barnesacbec812013-09-20 11:29:32 -07007726static void vlv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007727 struct intel_crtc_state *pipe_config)
Jesse Barnesacbec812013-09-20 11:29:32 -07007728{
7729 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007730 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesacbec812013-09-20 11:29:32 -07007731 int pipe = pipe_config->cpu_transcoder;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007732 struct dpll clock;
Jesse Barnesacbec812013-09-20 11:29:32 -07007733 u32 mdiv;
Chris Wilson662c6ec2013-09-25 14:24:01 -07007734 int refclk = 100000;
Jesse Barnesacbec812013-09-20 11:29:32 -07007735
Ville Syrjäläb5219732016-03-15 16:40:01 +02007736 /* In case of DSI, DPLL will not be used */
7737 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
Shobhit Kumarf573de52014-07-30 20:32:37 +05307738 return;
7739
Ville Syrjäläa5805162015-05-26 20:42:30 +03007740 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007741 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007742 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007743
7744 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7745 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7746 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7747 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7748 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7749
Imre Deakdccbea32015-06-22 23:35:51 +03007750 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007751}
7752
Damien Lespiau5724dbd2015-01-20 12:51:52 +00007753static void
7754i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7755 struct intel_initial_plane_config *plane_config)
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007756{
7757 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007758 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007759 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7760 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007761 enum pipe pipe;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007762 u32 val, base, offset;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007763 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00007764 unsigned int aligned_height;
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007765 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00007766 struct intel_framebuffer *intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007767
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007768 if (!plane->get_hw_state(plane, &pipe))
Damien Lespiau42a7b082015-02-05 19:35:13 +00007769 return;
7770
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007771 WARN_ON(pipe != crtc->pipe);
7772
Damien Lespiaud9806c92015-01-21 14:07:19 +00007773 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00007774 if (!intel_fb) {
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007775 DRM_DEBUG_KMS("failed to alloc fb\n");
7776 return;
7777 }
7778
Damien Lespiau1b842c82015-01-21 13:50:54 +00007779 fb = &intel_fb->base;
7780
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02007781 fb->dev = dev;
7782
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02007783 val = I915_READ(DSPCNTR(i9xx_plane));
7784
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007785 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter18c52472015-02-10 17:16:09 +00007786 if (val & DISPPLANE_TILED) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007787 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02007788 fb->modifier = I915_FORMAT_MOD_X_TILED;
Daniel Vetter18c52472015-02-10 17:16:09 +00007789 }
7790 }
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007791
7792 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
Damien Lespiaub35d63f2015-01-20 12:51:50 +00007793 fourcc = i9xx_format_to_fourcc(pixel_format);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02007794 fb->format = drm_format_info(fourcc);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007795
Ville Syrjälä81894b22017-11-17 21:19:13 +02007796 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7797 offset = I915_READ(DSPOFFSET(i9xx_plane));
7798 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7799 } else if (INTEL_GEN(dev_priv) >= 4) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007800 if (plane_config->tiling)
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007801 offset = I915_READ(DSPTILEOFF(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007802 else
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007803 offset = I915_READ(DSPLINOFF(i9xx_plane));
7804 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007805 } else {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007806 base = I915_READ(DSPADDR(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007807 }
7808 plane_config->base = base;
7809
7810 val = I915_READ(PIPESRC(pipe));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007811 fb->width = ((val >> 16) & 0xfff) + 1;
7812 fb->height = ((val >> 0) & 0xfff) + 1;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007813
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007814 val = I915_READ(DSPSTRIDE(i9xx_plane));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007815 fb->pitches[0] = val & 0xffffffc0;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007816
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02007817 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007818
Daniel Vetterf37b5c22015-02-10 23:12:27 +01007819 plane_config->size = fb->pitches[0] * aligned_height;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007820
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007821 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7822 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02007823 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiau2844a922015-01-20 12:51:48 +00007824 plane_config->size);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007825
Damien Lespiau2d140302015-02-05 17:22:18 +00007826 plane_config->fb = intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007827}
7828
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007829static void chv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007830 struct intel_crtc_state *pipe_config)
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007831{
7832 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007833 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007834 int pipe = pipe_config->cpu_transcoder;
7835 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007836 struct dpll clock;
Imre Deak0d7b6b12015-07-02 14:29:58 +03007837 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007838 int refclk = 100000;
7839
Ville Syrjäläb5219732016-03-15 16:40:01 +02007840 /* In case of DSI, DPLL will not be used */
7841 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7842 return;
7843
Ville Syrjäläa5805162015-05-26 20:42:30 +03007844 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007845 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7846 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7847 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7848 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
Imre Deak0d7b6b12015-07-02 14:29:58 +03007849 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007850 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007851
7852 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
Imre Deak0d7b6b12015-07-02 14:29:58 +03007853 clock.m2 = (pll_dw0 & 0xff) << 22;
7854 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7855 clock.m2 |= pll_dw2 & 0x3fffff;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007856 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7857 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7858 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7859
Imre Deakdccbea32015-06-22 23:35:51 +03007860 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007861}
7862
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307863static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
7864 struct intel_crtc_state *pipe_config)
7865{
7866 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7867 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
7868
Shashank Sharma668b6c12018-10-12 11:53:14 +05307869 pipe_config->lspcon_downsampling = false;
7870
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307871 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
7872 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
7873
7874 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
7875 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
7876 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
7877
7878 if (ycbcr420_enabled) {
7879 /* We support 4:2:0 in full blend mode only */
7880 if (!blend)
7881 output = INTEL_OUTPUT_FORMAT_INVALID;
7882 else if (!(IS_GEMINILAKE(dev_priv) ||
7883 INTEL_GEN(dev_priv) >= 10))
7884 output = INTEL_OUTPUT_FORMAT_INVALID;
7885 else
7886 output = INTEL_OUTPUT_FORMAT_YCBCR420;
Shashank Sharma8c79f842018-10-12 11:53:09 +05307887 } else {
Shashank Sharma668b6c12018-10-12 11:53:14 +05307888 /*
7889 * Currently there is no interface defined to
7890 * check user preference between RGB/YCBCR444
7891 * or YCBCR420. So the only possible case for
7892 * YCBCR444 usage is driving YCBCR420 output
7893 * with LSPCON, when pipe is configured for
7894 * YCBCR444 output and LSPCON takes care of
7895 * downsampling it.
7896 */
7897 pipe_config->lspcon_downsampling = true;
Shashank Sharma8c79f842018-10-12 11:53:09 +05307898 output = INTEL_OUTPUT_FORMAT_YCBCR444;
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307899 }
7900 }
7901 }
7902
7903 pipe_config->output_format = output;
7904}
7905
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007906static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007907 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007908{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007909 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02007910 enum intel_display_power_domain power_domain;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007911 uint32_t tmp;
Imre Deak17290502016-02-12 18:55:11 +02007912 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007913
Imre Deak17290502016-02-12 18:55:11 +02007914 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7915 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02007916 return false;
7917
Shashank Sharmad9facae2018-10-12 11:53:07 +05307918 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02007919 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02007920 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02007921
Imre Deak17290502016-02-12 18:55:11 +02007922 ret = false;
7923
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007924 tmp = I915_READ(PIPECONF(crtc->pipe));
7925 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02007926 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007927
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007928 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7929 IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä42571ae2013-09-06 23:29:00 +03007930 switch (tmp & PIPECONF_BPC_MASK) {
7931 case PIPECONF_6BPC:
7932 pipe_config->pipe_bpp = 18;
7933 break;
7934 case PIPECONF_8BPC:
7935 pipe_config->pipe_bpp = 24;
7936 break;
7937 case PIPECONF_10BPC:
7938 pipe_config->pipe_bpp = 30;
7939 break;
7940 default:
7941 break;
7942 }
7943 }
7944
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007945 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08007946 (tmp & PIPECONF_COLOR_RANGE_SELECT))
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02007947 pipe_config->limited_color_range = true;
7948
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007949 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä282740f2013-09-04 18:30:03 +03007950 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7951
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007952 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02007953 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007954
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007955 i9xx_get_pfit_config(crtc, pipe_config);
7956
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007957 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjäläc2317752016-03-15 16:39:56 +02007958 /* No way to read it out on pipes B and C */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007959 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
Ville Syrjäläc2317752016-03-15 16:39:56 +02007960 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7961 else
7962 tmp = I915_READ(DPLL_MD(crtc->pipe));
Daniel Vetter6c49f242013-06-06 12:45:25 +02007963 pipe_config->pixel_multiplier =
7964 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7965 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007966 pipe_config->dpll_hw_state.dpll_md = tmp;
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007967 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
Jani Nikula73f67aa2016-12-07 22:48:09 +02007968 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Daniel Vetter6c49f242013-06-06 12:45:25 +02007969 tmp = I915_READ(DPLL(crtc->pipe));
7970 pipe_config->pixel_multiplier =
7971 ((tmp & SDVO_MULTIPLIER_MASK)
7972 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7973 } else {
7974 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7975 * port and will be fixed up in the encoder->get_config
7976 * function. */
7977 pipe_config->pixel_multiplier = 1;
7978 }
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007979 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007980 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03007981 /*
7982 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7983 * on 830. Filter it out here so that we don't
7984 * report errors due to that.
7985 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007986 if (IS_I830(dev_priv))
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03007987 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
7988
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007989 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
7990 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
Ville Syrjälä165e9012013-06-26 17:44:15 +03007991 } else {
7992 /* Mask out read-only status bits. */
7993 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7994 DPLL_PORTC_READY_MASK |
7995 DPLL_PORTB_READY_MASK);
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007996 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02007997
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007998 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007999 chv_crtc_clock_get(crtc, pipe_config);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01008000 else if (IS_VALLEYVIEW(dev_priv))
Jesse Barnesacbec812013-09-20 11:29:32 -07008001 vlv_crtc_clock_get(crtc, pipe_config);
8002 else
8003 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +03008004
Ville Syrjälä0f646142015-08-26 19:39:18 +03008005 /*
8006 * Normally the dotclock is filled in by the encoder .get_config()
8007 * but in case the pipe is enabled w/o any ports we need a sane
8008 * default.
8009 */
8010 pipe_config->base.adjusted_mode.crtc_clock =
8011 pipe_config->port_clock / pipe_config->pixel_multiplier;
8012
Imre Deak17290502016-02-12 18:55:11 +02008013 ret = true;
8014
8015out:
8016 intel_display_power_put(dev_priv, power_domain);
8017
8018 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008019}
8020
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008021static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
Jesse Barnes13d83a62011-08-03 12:59:20 -07008022{
Jesse Barnes13d83a62011-08-03 12:59:20 -07008023 struct intel_encoder *encoder;
Lyude1c1a24d2016-06-14 11:04:09 -04008024 int i;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008025 u32 val, final;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008026 bool has_lvds = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008027 bool has_cpu_edp = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008028 bool has_panel = false;
Keith Packard99eb6a02011-09-26 14:29:12 -07008029 bool has_ck505 = false;
8030 bool can_ssc = false;
Lyude1c1a24d2016-06-14 11:04:09 -04008031 bool using_ssc_source = false;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008032
8033 /* We need to take the global config into account */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008034 for_each_intel_encoder(&dev_priv->drm, encoder) {
Keith Packard199e5d72011-09-22 12:01:57 -07008035 switch (encoder->type) {
8036 case INTEL_OUTPUT_LVDS:
8037 has_panel = true;
8038 has_lvds = true;
8039 break;
8040 case INTEL_OUTPUT_EDP:
8041 has_panel = true;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02008042 if (encoder->port == PORT_A)
Keith Packard199e5d72011-09-22 12:01:57 -07008043 has_cpu_edp = true;
8044 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008045 default:
8046 break;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008047 }
8048 }
8049
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008050 if (HAS_PCH_IBX(dev_priv)) {
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03008051 has_ck505 = dev_priv->vbt.display_clock_mode;
Keith Packard99eb6a02011-09-26 14:29:12 -07008052 can_ssc = has_ck505;
8053 } else {
8054 has_ck505 = false;
8055 can_ssc = true;
8056 }
8057
Lyude1c1a24d2016-06-14 11:04:09 -04008058 /* Check if any DPLLs are using the SSC source */
8059 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8060 u32 temp = I915_READ(PCH_DPLL(i));
8061
8062 if (!(temp & DPLL_VCO_ENABLE))
8063 continue;
8064
8065 if ((temp & PLL_REF_INPUT_MASK) ==
8066 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8067 using_ssc_source = true;
8068 break;
8069 }
8070 }
8071
8072 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8073 has_panel, has_lvds, has_ck505, using_ssc_source);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008074
8075 /* Ironlake: try to setup display ref clock before DPLL
8076 * enabling. This is only under driver's control after
8077 * PCH B stepping, previous chipset stepping should be
8078 * ignoring this setting.
8079 */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008080 val = I915_READ(PCH_DREF_CONTROL);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008081
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008082 /* As we must carefully and slowly disable/enable each source in turn,
8083 * compute the final state we want first and check if we need to
8084 * make any changes at all.
8085 */
8086 final = val;
8087 final &= ~DREF_NONSPREAD_SOURCE_MASK;
Keith Packard99eb6a02011-09-26 14:29:12 -07008088 if (has_ck505)
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008089 final |= DREF_NONSPREAD_CK505_ENABLE;
Keith Packard99eb6a02011-09-26 14:29:12 -07008090 else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008091 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8092
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008093 final &= ~DREF_SSC_SOURCE_MASK;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008094 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008095 final &= ~DREF_SSC1_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008096
Keith Packard199e5d72011-09-22 12:01:57 -07008097 if (has_panel) {
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008098 final |= DREF_SSC_SOURCE_ENABLE;
8099
8100 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8101 final |= DREF_SSC1_ENABLE;
8102
8103 if (has_cpu_edp) {
8104 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8105 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8106 else
8107 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8108 } else
8109 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Lyude1c1a24d2016-06-14 11:04:09 -04008110 } else if (using_ssc_source) {
8111 final |= DREF_SSC_SOURCE_ENABLE;
8112 final |= DREF_SSC1_ENABLE;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008113 }
8114
8115 if (final == val)
8116 return;
8117
8118 /* Always enable nonspread source */
8119 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8120
8121 if (has_ck505)
8122 val |= DREF_NONSPREAD_CK505_ENABLE;
8123 else
8124 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8125
8126 if (has_panel) {
8127 val &= ~DREF_SSC_SOURCE_MASK;
8128 val |= DREF_SSC_SOURCE_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008129
Keith Packard199e5d72011-09-22 12:01:57 -07008130 /* SSC must be turned on before enabling the CPU output */
Keith Packard99eb6a02011-09-26 14:29:12 -07008131 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008132 DRM_DEBUG_KMS("Using SSC on panel\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008133 val |= DREF_SSC1_ENABLE;
Daniel Vettere77166b2012-03-30 22:14:05 +02008134 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008135 val &= ~DREF_SSC1_ENABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008136
8137 /* Get SSC going before enabling the outputs */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008138 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008139 POSTING_READ(PCH_DREF_CONTROL);
8140 udelay(200);
8141
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008142 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008143
8144 /* Enable CPU source on CPU attached eDP */
Keith Packard199e5d72011-09-22 12:01:57 -07008145 if (has_cpu_edp) {
Keith Packard99eb6a02011-09-26 14:29:12 -07008146 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008147 DRM_DEBUG_KMS("Using SSC on eDP\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008148 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
Robin Schroereba905b2014-05-18 02:24:50 +02008149 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008150 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
Keith Packard199e5d72011-09-22 12:01:57 -07008151 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008152 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008153
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008154 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008155 POSTING_READ(PCH_DREF_CONTROL);
8156 udelay(200);
8157 } else {
Lyude1c1a24d2016-06-14 11:04:09 -04008158 DRM_DEBUG_KMS("Disabling CPU source output\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008159
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008160 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Keith Packard199e5d72011-09-22 12:01:57 -07008161
8162 /* Turn off CPU output */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008163 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008164
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008165 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008166 POSTING_READ(PCH_DREF_CONTROL);
8167 udelay(200);
8168
Lyude1c1a24d2016-06-14 11:04:09 -04008169 if (!using_ssc_source) {
8170 DRM_DEBUG_KMS("Disabling SSC source\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008171
Lyude1c1a24d2016-06-14 11:04:09 -04008172 /* Turn off the SSC source */
8173 val &= ~DREF_SSC_SOURCE_MASK;
8174 val |= DREF_SSC_SOURCE_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008175
Lyude1c1a24d2016-06-14 11:04:09 -04008176 /* Turn off SSC1 */
8177 val &= ~DREF_SSC1_ENABLE;
8178
8179 I915_WRITE(PCH_DREF_CONTROL, val);
8180 POSTING_READ(PCH_DREF_CONTROL);
8181 udelay(200);
8182 }
Jesse Barnes13d83a62011-08-03 12:59:20 -07008183 }
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008184
8185 BUG_ON(val != final);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008186}
8187
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008188static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008189{
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008190 uint32_t tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008191
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008192 tmp = I915_READ(SOUTH_CHICKEN2);
8193 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8194 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008195
Imre Deakcf3598c2016-06-28 13:37:31 +03008196 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8197 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008198 DRM_ERROR("FDI mPHY reset assert timeout\n");
Paulo Zanonidde86e22012-12-01 12:04:25 -02008199
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008200 tmp = I915_READ(SOUTH_CHICKEN2);
8201 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8202 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008203
Imre Deakcf3598c2016-06-28 13:37:31 +03008204 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8205 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008206 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008207}
8208
8209/* WaMPhyProgramming:hsw */
8210static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8211{
8212 uint32_t tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008213
8214 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8215 tmp &= ~(0xFF << 24);
8216 tmp |= (0x12 << 24);
8217 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8218
Paulo Zanonidde86e22012-12-01 12:04:25 -02008219 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8220 tmp |= (1 << 11);
8221 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8222
8223 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8224 tmp |= (1 << 11);
8225 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8226
Paulo Zanonidde86e22012-12-01 12:04:25 -02008227 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8228 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8229 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8230
8231 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8232 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8233 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8234
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008235 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8236 tmp &= ~(7 << 13);
8237 tmp |= (5 << 13);
8238 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008239
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008240 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8241 tmp &= ~(7 << 13);
8242 tmp |= (5 << 13);
8243 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008244
8245 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8246 tmp &= ~0xFF;
8247 tmp |= 0x1C;
8248 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8249
8250 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8251 tmp &= ~0xFF;
8252 tmp |= 0x1C;
8253 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8254
8255 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8256 tmp &= ~(0xFF << 16);
8257 tmp |= (0x1C << 16);
8258 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8259
8260 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8261 tmp &= ~(0xFF << 16);
8262 tmp |= (0x1C << 16);
8263 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8264
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008265 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8266 tmp |= (1 << 27);
8267 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008268
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008269 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8270 tmp |= (1 << 27);
8271 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008272
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008273 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8274 tmp &= ~(0xF << 28);
8275 tmp |= (4 << 28);
8276 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008277
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008278 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8279 tmp &= ~(0xF << 28);
8280 tmp |= (4 << 28);
8281 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008282}
8283
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008284/* Implements 3 different sequences from BSpec chapter "Display iCLK
8285 * Programming" based on the parameters passed:
8286 * - Sequence to enable CLKOUT_DP
8287 * - Sequence to enable CLKOUT_DP without spread
8288 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8289 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008290static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8291 bool with_spread, bool with_fdi)
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008292{
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008293 uint32_t reg, tmp;
8294
8295 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8296 with_spread = true;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008297 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8298 with_fdi, "LP PCH doesn't have FDI\n"))
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008299 with_fdi = false;
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008300
Ville Syrjäläa5805162015-05-26 20:42:30 +03008301 mutex_lock(&dev_priv->sb_lock);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008302
8303 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8304 tmp &= ~SBI_SSCCTL_DISABLE;
8305 tmp |= SBI_SSCCTL_PATHALT;
8306 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8307
8308 udelay(24);
8309
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008310 if (with_spread) {
8311 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8312 tmp &= ~SBI_SSCCTL_PATHALT;
8313 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008314
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008315 if (with_fdi) {
8316 lpt_reset_fdi_mphy(dev_priv);
8317 lpt_program_fdi_mphy(dev_priv);
8318 }
8319 }
Paulo Zanonidde86e22012-12-01 12:04:25 -02008320
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008321 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008322 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8323 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8324 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
Daniel Vetterc00db242013-01-22 15:33:27 +01008325
Ville Syrjäläa5805162015-05-26 20:42:30 +03008326 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008327}
8328
Paulo Zanoni47701c32013-07-23 11:19:25 -03008329/* Sequence to disable CLKOUT_DP */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008330static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
Paulo Zanoni47701c32013-07-23 11:19:25 -03008331{
Paulo Zanoni47701c32013-07-23 11:19:25 -03008332 uint32_t reg, tmp;
8333
Ville Syrjäläa5805162015-05-26 20:42:30 +03008334 mutex_lock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008335
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008336 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni47701c32013-07-23 11:19:25 -03008337 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8338 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8339 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8340
8341 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8342 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8343 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8344 tmp |= SBI_SSCCTL_PATHALT;
8345 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8346 udelay(32);
8347 }
8348 tmp |= SBI_SSCCTL_DISABLE;
8349 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8350 }
8351
Ville Syrjäläa5805162015-05-26 20:42:30 +03008352 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008353}
8354
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008355#define BEND_IDX(steps) ((50 + (steps)) / 5)
8356
8357static const uint16_t sscdivintphase[] = {
8358 [BEND_IDX( 50)] = 0x3B23,
8359 [BEND_IDX( 45)] = 0x3B23,
8360 [BEND_IDX( 40)] = 0x3C23,
8361 [BEND_IDX( 35)] = 0x3C23,
8362 [BEND_IDX( 30)] = 0x3D23,
8363 [BEND_IDX( 25)] = 0x3D23,
8364 [BEND_IDX( 20)] = 0x3E23,
8365 [BEND_IDX( 15)] = 0x3E23,
8366 [BEND_IDX( 10)] = 0x3F23,
8367 [BEND_IDX( 5)] = 0x3F23,
8368 [BEND_IDX( 0)] = 0x0025,
8369 [BEND_IDX( -5)] = 0x0025,
8370 [BEND_IDX(-10)] = 0x0125,
8371 [BEND_IDX(-15)] = 0x0125,
8372 [BEND_IDX(-20)] = 0x0225,
8373 [BEND_IDX(-25)] = 0x0225,
8374 [BEND_IDX(-30)] = 0x0325,
8375 [BEND_IDX(-35)] = 0x0325,
8376 [BEND_IDX(-40)] = 0x0425,
8377 [BEND_IDX(-45)] = 0x0425,
8378 [BEND_IDX(-50)] = 0x0525,
8379};
8380
8381/*
8382 * Bend CLKOUT_DP
8383 * steps -50 to 50 inclusive, in steps of 5
8384 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8385 * change in clock period = -(steps / 10) * 5.787 ps
8386 */
8387static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8388{
8389 uint32_t tmp;
8390 int idx = BEND_IDX(steps);
8391
8392 if (WARN_ON(steps % 5 != 0))
8393 return;
8394
8395 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8396 return;
8397
8398 mutex_lock(&dev_priv->sb_lock);
8399
8400 if (steps % 10 != 0)
8401 tmp = 0xAAAAAAAB;
8402 else
8403 tmp = 0x00000000;
8404 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8405
8406 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8407 tmp &= 0xffff0000;
8408 tmp |= sscdivintphase[idx];
8409 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8410
8411 mutex_unlock(&dev_priv->sb_lock);
8412}
8413
8414#undef BEND_IDX
8415
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008416static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008417{
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008418 struct intel_encoder *encoder;
8419 bool has_vga = false;
8420
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008421 for_each_intel_encoder(&dev_priv->drm, encoder) {
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008422 switch (encoder->type) {
8423 case INTEL_OUTPUT_ANALOG:
8424 has_vga = true;
8425 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008426 default:
8427 break;
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008428 }
8429 }
8430
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008431 if (has_vga) {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008432 lpt_bend_clkout_dp(dev_priv, 0);
8433 lpt_enable_clkout_dp(dev_priv, true, true);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008434 } else {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008435 lpt_disable_clkout_dp(dev_priv);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008436 }
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008437}
8438
Paulo Zanonidde86e22012-12-01 12:04:25 -02008439/*
8440 * Initialize reference clocks when the driver loads
8441 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008442void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008443{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008444 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008445 ironlake_init_pch_refclk(dev_priv);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008446 else if (HAS_PCH_LPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008447 lpt_init_pch_refclk(dev_priv);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008448}
8449
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008450static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanonic8203562012-09-12 10:06:29 -03008451{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008452 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8453 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8454 enum pipe pipe = crtc->pipe;
Paulo Zanonic8203562012-09-12 10:06:29 -03008455 uint32_t val;
8456
Daniel Vetter78114072013-06-13 00:54:57 +02008457 val = 0;
Paulo Zanonic8203562012-09-12 10:06:29 -03008458
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008459 switch (crtc_state->pipe_bpp) {
Paulo Zanonic8203562012-09-12 10:06:29 -03008460 case 18:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008461 val |= PIPECONF_6BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008462 break;
8463 case 24:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008464 val |= PIPECONF_8BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008465 break;
8466 case 30:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008467 val |= PIPECONF_10BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008468 break;
8469 case 36:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008470 val |= PIPECONF_12BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008471 break;
8472 default:
Paulo Zanonicc769b62012-09-20 18:36:03 -03008473 /* Case prevented by intel_choose_pipe_bpp_dither. */
8474 BUG();
Paulo Zanonic8203562012-09-12 10:06:29 -03008475 }
8476
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008477 if (crtc_state->dither)
Paulo Zanonic8203562012-09-12 10:06:29 -03008478 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8479
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008480 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanonic8203562012-09-12 10:06:29 -03008481 val |= PIPECONF_INTERLACED_ILK;
8482 else
8483 val |= PIPECONF_PROGRESSIVE;
8484
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008485 if (crtc_state->limited_color_range)
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008486 val |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008487
Paulo Zanonic8203562012-09-12 10:06:29 -03008488 I915_WRITE(PIPECONF(pipe), val);
8489 POSTING_READ(PIPECONF(pipe));
8490}
8491
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008492static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008493{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008494 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8495 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8496 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Jani Nikula391bf042016-03-18 17:05:40 +02008497 u32 val = 0;
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008498
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008499 if (IS_HASWELL(dev_priv) && crtc_state->dither)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008500 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8501
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008502 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008503 val |= PIPECONF_INTERLACED_ILK;
8504 else
8505 val |= PIPECONF_PROGRESSIVE;
8506
Paulo Zanoni702e7a52012-10-23 18:29:59 -02008507 I915_WRITE(PIPECONF(cpu_transcoder), val);
8508 POSTING_READ(PIPECONF(cpu_transcoder));
Jani Nikula391bf042016-03-18 17:05:40 +02008509}
8510
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008511static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
Jani Nikula391bf042016-03-18 17:05:40 +02008512{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008513 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8514 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jani Nikula391bf042016-03-18 17:05:40 +02008515
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00008516 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
Jani Nikula391bf042016-03-18 17:05:40 +02008517 u32 val = 0;
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008518
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008519 switch (crtc_state->pipe_bpp) {
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008520 case 18:
8521 val |= PIPEMISC_DITHER_6_BPC;
8522 break;
8523 case 24:
8524 val |= PIPEMISC_DITHER_8_BPC;
8525 break;
8526 case 30:
8527 val |= PIPEMISC_DITHER_10_BPC;
8528 break;
8529 case 36:
8530 val |= PIPEMISC_DITHER_12_BPC;
8531 break;
8532 default:
8533 /* Case prevented by pipe_config_set_bpp. */
8534 BUG();
8535 }
8536
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008537 if (crtc_state->dither)
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008538 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8539
Shashank Sharma8c79f842018-10-12 11:53:09 +05308540 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8541 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308542 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308543
8544 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308545 val |= PIPEMISC_YUV420_ENABLE |
Shashank Sharmab22ca992017-07-24 19:19:32 +05308546 PIPEMISC_YUV420_MODE_FULL_BLEND;
Shashank Sharmab22ca992017-07-24 19:19:32 +05308547
Jani Nikula391bf042016-03-18 17:05:40 +02008548 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008549 }
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008550}
8551
Paulo Zanonid4b19312012-11-29 11:29:32 -02008552int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8553{
8554 /*
8555 * Account for spread spectrum to avoid
8556 * oversubscribing the link. Max center spread
8557 * is 2.5%; use 5% for safety's sake.
8558 */
8559 u32 bps = target_clock * bpp * 21 / 20;
Ville Syrjälä619d4d02014-02-27 14:23:14 +02008560 return DIV_ROUND_UP(bps, link_bw * 8);
Paulo Zanonid4b19312012-11-29 11:29:32 -02008561}
8562
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008563static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
Daniel Vetter6cf86a52013-04-02 23:38:10 +02008564{
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008565 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
Paulo Zanonif48d8f22012-09-20 18:36:04 -03008566}
8567
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008568static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8569 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03008570 struct dpll *reduced_clock)
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008571{
8572 struct drm_crtc *crtc = &intel_crtc->base;
8573 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008574 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008575 u32 dpll, fp, fp2;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008576 int factor;
Jesse Barnes79e53942008-11-07 14:24:08 -08008577
Chris Wilsonc1858122010-12-03 21:35:48 +00008578 /* Enable autotuning of the PLL clock (if permissible) */
Eric Anholt8febb292011-03-30 13:01:07 -07008579 factor = 21;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008580 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Eric Anholt8febb292011-03-30 13:01:07 -07008581 if ((intel_panel_use_ssc(dev_priv) &&
Ville Syrjäläe91e9412013-12-09 18:54:16 +02008582 dev_priv->vbt.lvds_ssc_freq == 100000) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008583 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
Eric Anholt8febb292011-03-30 13:01:07 -07008584 factor = 25;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008585 } else if (crtc_state->sdvo_tv_clock)
Eric Anholt8febb292011-03-30 13:01:07 -07008586 factor = 20;
Chris Wilsonc1858122010-12-03 21:35:48 +00008587
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008588 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Chris Wilsonc1858122010-12-03 21:35:48 +00008589
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008590 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8591 fp |= FP_CB_TUNE;
8592
8593 if (reduced_clock) {
8594 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8595
8596 if (reduced_clock->m < factor * reduced_clock->n)
8597 fp2 |= FP_CB_TUNE;
8598 } else {
8599 fp2 = fp;
8600 }
Daniel Vetter9a7c7892013-04-04 22:20:34 +02008601
Chris Wilson5eddb702010-09-11 13:48:45 +01008602 dpll = 0;
Zhenyu Wang2c072452009-06-05 15:38:42 +08008603
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008604 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Eric Anholta07d6782011-03-30 13:01:08 -07008605 dpll |= DPLLB_MODE_LVDS;
8606 else
8607 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008608
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008609 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02008610 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008611
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008612 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8613 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008614 dpll |= DPLL_SDVO_HIGH_SPEED;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008615
Ville Syrjälä37a56502016-06-22 21:57:04 +03008616 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008617 dpll |= DPLL_SDVO_HIGH_SPEED;
Jesse Barnes79e53942008-11-07 14:24:08 -08008618
Ville Syrjälä7d7f8632016-09-26 11:30:46 +03008619 /*
8620 * The high speed IO clock is only really required for
8621 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8622 * possible to share the DPLL between CRT and HDMI. Enabling
8623 * the clock needlessly does no real harm, except use up a
8624 * bit of power potentially.
8625 *
8626 * We'll limit this to IVB with 3 pipes, since it has only two
8627 * DPLLs and so DPLL sharing is the only way to get three pipes
8628 * driving PCH ports at the same time. On SNB we could do this,
8629 * and potentially avoid enabling the second DPLL, but it's not
8630 * clear if it''s a win or loss power wise. No point in doing
8631 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8632 */
8633 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8634 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8635 dpll |= DPLL_SDVO_HIGH_SPEED;
8636
Eric Anholta07d6782011-03-30 13:01:08 -07008637 /* compute bitmask from p1 value */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008638 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008639 /* also FPA1 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008640 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008641
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008642 switch (crtc_state->dpll.p2) {
Eric Anholta07d6782011-03-30 13:01:08 -07008643 case 5:
8644 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8645 break;
8646 case 7:
8647 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8648 break;
8649 case 10:
8650 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8651 break;
8652 case 14:
8653 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8654 break;
Jesse Barnes79e53942008-11-07 14:24:08 -08008655 }
8656
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008657 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8658 intel_panel_use_ssc(dev_priv))
Kristian Høgsberg43565a02009-02-13 20:56:52 -05008659 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
Jesse Barnes79e53942008-11-07 14:24:08 -08008660 else
8661 dpll |= PLL_REF_INPUT_DREFCLK;
8662
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008663 dpll |= DPLL_VCO_ENABLE;
8664
8665 crtc_state->dpll_hw_state.dpll = dpll;
8666 crtc_state->dpll_hw_state.fp0 = fp;
8667 crtc_state->dpll_hw_state.fp1 = fp2;
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008668}
8669
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008670static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8671 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08008672{
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008673 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008674 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03008675 const struct intel_limit *limit;
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008676 int refclk = 120000;
Jesse Barnes79e53942008-11-07 14:24:08 -08008677
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03008678 memset(&crtc_state->dpll_hw_state, 0,
8679 sizeof(crtc_state->dpll_hw_state));
8680
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008681 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8682 if (!crtc_state->has_pch_encoder)
8683 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008684
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03008685 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008686 if (intel_panel_use_ssc(dev_priv)) {
8687 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8688 dev_priv->vbt.lvds_ssc_freq);
8689 refclk = dev_priv->vbt.lvds_ssc_freq;
8690 }
8691
8692 if (intel_is_dual_link_lvds(dev)) {
8693 if (refclk == 100000)
8694 limit = &intel_limits_ironlake_dual_lvds_100m;
8695 else
8696 limit = &intel_limits_ironlake_dual_lvds;
8697 } else {
8698 if (refclk == 100000)
8699 limit = &intel_limits_ironlake_single_lvds_100m;
8700 else
8701 limit = &intel_limits_ironlake_single_lvds;
8702 }
8703 } else {
8704 limit = &intel_limits_ironlake_dac;
8705 }
8706
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008707 if (!crtc_state->clock_set &&
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008708 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8709 refclk, NULL, &crtc_state->dpll)) {
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008710 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8711 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01008712 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008713
Gustavo A. R. Silvacbaa3312017-05-15 16:56:05 -05008714 ironlake_compute_dpll(crtc, crtc_state, NULL);
Daniel Vetter66e985c2013-06-05 13:34:20 +02008715
Gustavo A. R. Silvaefd38b62017-05-15 17:00:28 -05008716 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
Chris Wilson43031782018-09-13 14:16:26 +01008717 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8718 pipe_name(crtc->pipe));
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008719 return -EINVAL;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +02008720 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008721
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02008722 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008723}
8724
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008725static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8726 struct intel_link_m_n *m_n)
Daniel Vetter72419202013-04-04 13:28:53 +02008727{
8728 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008729 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008730 enum pipe pipe = crtc->pipe;
Daniel Vetter72419202013-04-04 13:28:53 +02008731
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008732 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8733 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8734 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8735 & ~TU_SIZE_MASK;
8736 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8737 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8738 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8739}
8740
8741static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8742 enum transcoder transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008743 struct intel_link_m_n *m_n,
8744 struct intel_link_m_n *m2_n2)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008745{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008746 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008747 enum pipe pipe = crtc->pipe;
8748
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008749 if (INTEL_GEN(dev_priv) >= 5) {
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008750 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8751 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8752 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8753 & ~TU_SIZE_MASK;
8754 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8755 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8756 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02008757
8758 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008759 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8760 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8761 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8762 & ~TU_SIZE_MASK;
8763 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8764 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8765 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8766 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008767 } else {
8768 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8769 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8770 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8771 & ~TU_SIZE_MASK;
8772 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8773 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8774 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8775 }
8776}
8777
8778void intel_dp_get_m_n(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008779 struct intel_crtc_state *pipe_config)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008780{
Ander Conselvan de Oliveira681a8502015-01-15 14:55:24 +02008781 if (pipe_config->has_pch_encoder)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008782 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8783 else
8784 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008785 &pipe_config->dp_m_n,
8786 &pipe_config->dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008787}
8788
Daniel Vetter72419202013-04-04 13:28:53 +02008789static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008790 struct intel_crtc_state *pipe_config)
Daniel Vetter72419202013-04-04 13:28:53 +02008791{
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008792 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008793 &pipe_config->fdi_m_n, NULL);
Daniel Vetter72419202013-04-04 13:28:53 +02008794}
8795
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008796static void skylake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008797 struct intel_crtc_state *pipe_config)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008798{
8799 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008800 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Kondurua1b22782015-04-07 15:28:45 -07008801 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8802 uint32_t ps_ctrl = 0;
8803 int id = -1;
8804 int i;
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008805
Chandra Kondurua1b22782015-04-07 15:28:45 -07008806 /* find scaler attached to this pipe */
8807 for (i = 0; i < crtc->num_scalers; i++) {
8808 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8809 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8810 id = i;
8811 pipe_config->pch_pfit.enabled = true;
8812 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8813 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8814 break;
8815 }
8816 }
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008817
Chandra Kondurua1b22782015-04-07 15:28:45 -07008818 scaler_state->scaler_id = id;
8819 if (id >= 0) {
8820 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8821 } else {
8822 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008823 }
8824}
8825
Damien Lespiau5724dbd2015-01-20 12:51:52 +00008826static void
8827skylake_get_initial_plane_config(struct intel_crtc *crtc,
8828 struct intel_initial_plane_config *plane_config)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008829{
8830 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008831 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008832 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8833 enum plane_id plane_id = plane->id;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008834 enum pipe pipe;
James Ausmus4036c782017-11-13 10:11:28 -08008835 u32 val, base, offset, stride_mult, tiling, alpha;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008836 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00008837 unsigned int aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008838 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00008839 struct intel_framebuffer *intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008840
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008841 if (!plane->get_hw_state(plane, &pipe))
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02008842 return;
8843
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008844 WARN_ON(pipe != crtc->pipe);
8845
Damien Lespiaud9806c92015-01-21 14:07:19 +00008846 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00008847 if (!intel_fb) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008848 DRM_DEBUG_KMS("failed to alloc fb\n");
8849 return;
8850 }
8851
Damien Lespiau1b842c82015-01-21 13:50:54 +00008852 fb = &intel_fb->base;
8853
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02008854 fb->dev = dev;
8855
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008856 val = I915_READ(PLANE_CTL(pipe, plane_id));
Damien Lespiau42a7b082015-02-05 19:35:13 +00008857
James Ausmusb5972772018-01-30 11:49:16 -02008858 if (INTEL_GEN(dev_priv) >= 11)
8859 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8860 else
8861 pixel_format = val & PLANE_CTL_FORMAT_MASK;
James Ausmus4036c782017-11-13 10:11:28 -08008862
8863 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008864 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
James Ausmus4036c782017-11-13 10:11:28 -08008865 alpha &= PLANE_COLOR_ALPHA_MASK;
8866 } else {
8867 alpha = val & PLANE_CTL_ALPHA_MASK;
8868 }
8869
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008870 fourcc = skl_format_to_fourcc(pixel_format,
James Ausmus4036c782017-11-13 10:11:28 -08008871 val & PLANE_CTL_ORDER_RGBX, alpha);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02008872 fb->format = drm_format_info(fourcc);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008873
Damien Lespiau40f46282015-02-27 11:15:21 +00008874 tiling = val & PLANE_CTL_TILED_MASK;
8875 switch (tiling) {
8876 case PLANE_CTL_TILED_LINEAR:
Ben Widawsky2f075562017-03-24 14:29:48 -07008877 fb->modifier = DRM_FORMAT_MOD_LINEAR;
Damien Lespiau40f46282015-02-27 11:15:21 +00008878 break;
8879 case PLANE_CTL_TILED_X:
8880 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02008881 fb->modifier = I915_FORMAT_MOD_X_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008882 break;
8883 case PLANE_CTL_TILED_Y:
Imre Deak914a4fd2018-10-16 19:00:11 +03008884 plane_config->tiling = I915_TILING_Y;
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07008885 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07008886 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8887 else
8888 fb->modifier = I915_FORMAT_MOD_Y_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008889 break;
8890 case PLANE_CTL_TILED_YF:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07008891 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07008892 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8893 else
8894 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008895 break;
8896 default:
8897 MISSING_CASE(tiling);
8898 goto error;
8899 }
8900
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008901 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008902 plane_config->base = base;
8903
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008904 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008905
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008906 val = I915_READ(PLANE_SIZE(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008907 fb->height = ((val >> 16) & 0xfff) + 1;
8908 fb->width = ((val >> 0) & 0x1fff) + 1;
8909
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008910 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02008911 stride_mult = intel_fb_stride_alignment(fb, 0);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008912 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8913
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02008914 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008915
Daniel Vetterf37b5c22015-02-10 23:12:27 +01008916 plane_config->size = fb->pitches[0] * aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008917
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008918 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8919 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02008920 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008921 plane_config->size);
8922
Damien Lespiau2d140302015-02-05 17:22:18 +00008923 plane_config->fb = intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008924 return;
8925
8926error:
Matthew Auldd1a3a032016-08-23 16:00:44 +01008927 kfree(intel_fb);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008928}
8929
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008930static void ironlake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008931 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008932{
8933 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008934 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008935 uint32_t tmp;
8936
8937 tmp = I915_READ(PF_CTL(crtc->pipe));
8938
8939 if (tmp & PF_ENABLE) {
Chris Wilsonfd4daa92013-08-27 17:04:17 +01008940 pipe_config->pch_pfit.enabled = true;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008941 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8942 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
Daniel Vettercb8b2a32013-06-01 17:16:23 +02008943
8944 /* We currently do not free assignements of panel fitters on
8945 * ivb/hsw (since we don't use the higher upscaling modes which
8946 * differentiates them) so just WARN about this case for now. */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01008947 if (IS_GEN7(dev_priv)) {
Daniel Vettercb8b2a32013-06-01 17:16:23 +02008948 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
8949 PF_PIPE_SEL_IVB(crtc->pipe));
8950 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008951 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008952}
8953
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008954static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008955 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008956{
8957 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008958 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak17290502016-02-12 18:55:11 +02008959 enum intel_display_power_domain power_domain;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008960 uint32_t tmp;
Imre Deak17290502016-02-12 18:55:11 +02008961 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008962
Imre Deak17290502016-02-12 18:55:11 +02008963 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8964 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Paulo Zanoni930e8c92014-07-04 13:38:34 -03008965 return false;
8966
Shashank Sharmad9facae2018-10-12 11:53:07 +05308967 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02008968 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008969 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02008970
Imre Deak17290502016-02-12 18:55:11 +02008971 ret = false;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008972 tmp = I915_READ(PIPECONF(crtc->pipe));
8973 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02008974 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008975
Ville Syrjälä42571ae2013-09-06 23:29:00 +03008976 switch (tmp & PIPECONF_BPC_MASK) {
8977 case PIPECONF_6BPC:
8978 pipe_config->pipe_bpp = 18;
8979 break;
8980 case PIPECONF_8BPC:
8981 pipe_config->pipe_bpp = 24;
8982 break;
8983 case PIPECONF_10BPC:
8984 pipe_config->pipe_bpp = 30;
8985 break;
8986 case PIPECONF_12BPC:
8987 pipe_config->pipe_bpp = 36;
8988 break;
8989 default:
8990 break;
8991 }
8992
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02008993 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8994 pipe_config->limited_color_range = true;
8995
Daniel Vetterab9412b2013-05-03 11:49:46 +02008996 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
Daniel Vetter66e985c2013-06-05 13:34:20 +02008997 struct intel_shared_dpll *pll;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008998 enum intel_dpll_id pll_id;
Daniel Vetter66e985c2013-06-05 13:34:20 +02008999
Daniel Vetter88adfff2013-03-28 10:42:01 +01009000 pipe_config->has_pch_encoder = true;
9001
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009002 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9003 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9004 FDI_DP_PORT_WIDTH_SHIFT) + 1;
Daniel Vetter72419202013-04-04 13:28:53 +02009005
9006 ironlake_get_fdi_m_n_config(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009007
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03009008 if (HAS_PCH_IBX(dev_priv)) {
Imre Deakd9a7bc62016-05-12 16:18:50 +03009009 /*
9010 * The pipe->pch transcoder and pch transcoder->pll
9011 * mapping is fixed.
9012 */
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009013 pll_id = (enum intel_dpll_id) crtc->pipe;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009014 } else {
9015 tmp = I915_READ(PCH_DPLL_SEL);
9016 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009017 pll_id = DPLL_ID_PCH_PLL_B;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009018 else
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009019 pll_id= DPLL_ID_PCH_PLL_A;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009020 }
Daniel Vetter66e985c2013-06-05 13:34:20 +02009021
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009022 pipe_config->shared_dpll =
9023 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9024 pll = pipe_config->shared_dpll;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009025
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009026 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9027 &pipe_config->dpll_hw_state));
Daniel Vetterc93f54c2013-06-27 19:47:19 +02009028
9029 tmp = pipe_config->dpll_hw_state.dpll;
9030 pipe_config->pixel_multiplier =
9031 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9032 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
Ville Syrjälä18442d02013-09-13 16:00:08 +03009033
9034 ironlake_pch_clock_get(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009035 } else {
9036 pipe_config->pixel_multiplier = 1;
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009037 }
9038
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009039 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02009040 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009041
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009042 ironlake_get_pfit_config(crtc, pipe_config);
9043
Imre Deak17290502016-02-12 18:55:11 +02009044 ret = true;
9045
9046out:
9047 intel_display_power_put(dev_priv, power_domain);
9048
9049 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009050}
9051
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009052static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9053{
Chris Wilson91c8a322016-07-05 10:40:23 +01009054 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009055 struct intel_crtc *crtc;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009056
Damien Lespiaud3fcc802014-05-13 23:32:22 +01009057 for_each_intel_crtc(dev, crtc)
Rob Clarke2c719b2014-12-15 13:56:32 -05009058 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009059 pipe_name(crtc->pipe));
9060
Imre Deak75e39682018-08-06 12:58:39 +03009061 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
Imre Deak9c3a16c2017-08-14 18:15:30 +03009062 "Display power well on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009063 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
Ville Syrjälä01403de2015-09-18 20:03:33 +03009064 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9065 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
Imre Deak44cb7342016-08-10 14:07:29 +03009066 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009067 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009068 "CPU PWM1 enabled\n");
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009069 if (IS_HASWELL(dev_priv))
Rob Clarke2c719b2014-12-15 13:56:32 -05009070 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
Paulo Zanonic5107b82014-07-04 11:50:30 -03009071 "CPU PWM2 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009072 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009073 "PCH PWM1 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009074 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009075 "Utility pin enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009076 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009077
Paulo Zanoni9926ada2014-04-01 19:39:47 -03009078 /*
9079 * In theory we can still leave IRQs enabled, as long as only the HPD
9080 * interrupts remain enabled. We used to check for that, but since it's
9081 * gen-specific and since we only disable LCPLL after we fully disable
9082 * the interrupts, the check below should be enough.
9083 */
Rob Clarke2c719b2014-12-15 13:56:32 -05009084 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009085}
9086
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009087static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9088{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009089 if (IS_HASWELL(dev_priv))
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009090 return I915_READ(D_COMP_HSW);
9091 else
9092 return I915_READ(D_COMP_BDW);
9093}
9094
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009095static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9096{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009097 if (IS_HASWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009098 mutex_lock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009099 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9100 val))
Chris Wilson79cf2192016-08-24 11:16:07 +01009101 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009102 mutex_unlock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009103 } else {
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009104 I915_WRITE(D_COMP_BDW, val);
9105 POSTING_READ(D_COMP_BDW);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009106 }
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009107}
9108
9109/*
9110 * This function implements pieces of two sequences from BSpec:
9111 * - Sequence for display software to disable LCPLL
9112 * - Sequence for display software to allow package C8+
9113 * The steps implemented here are just the steps that actually touch the LCPLL
9114 * register. Callers should take care of disabling all the display engine
9115 * functions, doing the mode unset, fixing interrupts, etc.
9116 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009117static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9118 bool switch_to_fclk, bool allow_power_down)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009119{
9120 uint32_t val;
9121
9122 assert_can_disable_lcpll(dev_priv);
9123
9124 val = I915_READ(LCPLL_CTL);
9125
9126 if (switch_to_fclk) {
9127 val |= LCPLL_CD_SOURCE_FCLK;
9128 I915_WRITE(LCPLL_CTL, val);
9129
Imre Deakf53dd632016-06-28 13:37:32 +03009130 if (wait_for_us(I915_READ(LCPLL_CTL) &
9131 LCPLL_CD_SOURCE_FCLK_DONE, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009132 DRM_ERROR("Switching to FCLK failed\n");
9133
9134 val = I915_READ(LCPLL_CTL);
9135 }
9136
9137 val |= LCPLL_PLL_DISABLE;
9138 I915_WRITE(LCPLL_CTL, val);
9139 POSTING_READ(LCPLL_CTL);
9140
Chris Wilson24d84412016-06-30 15:33:07 +01009141 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009142 DRM_ERROR("LCPLL still locked\n");
9143
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009144 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009145 val |= D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009146 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009147 ndelay(100);
9148
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009149 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9150 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009151 DRM_ERROR("D_COMP RCOMP still in progress\n");
9152
9153 if (allow_power_down) {
9154 val = I915_READ(LCPLL_CTL);
9155 val |= LCPLL_POWER_DOWN_ALLOW;
9156 I915_WRITE(LCPLL_CTL, val);
9157 POSTING_READ(LCPLL_CTL);
9158 }
9159}
9160
9161/*
9162 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9163 * source.
9164 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009165static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009166{
9167 uint32_t val;
9168
9169 val = I915_READ(LCPLL_CTL);
9170
9171 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9172 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9173 return;
9174
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009175 /*
9176 * Make sure we're not on PC8 state before disabling PC8, otherwise
9177 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009178 */
Mika Kuoppala59bad942015-01-16 11:34:40 +02009179 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Paulo Zanoni215733f2013-08-19 13:18:07 -03009180
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009181 if (val & LCPLL_POWER_DOWN_ALLOW) {
9182 val &= ~LCPLL_POWER_DOWN_ALLOW;
9183 I915_WRITE(LCPLL_CTL, val);
Daniel Vetter35d8f2e2013-08-21 23:38:08 +02009184 POSTING_READ(LCPLL_CTL);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009185 }
9186
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009187 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009188 val |= D_COMP_COMP_FORCE;
9189 val &= ~D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009190 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009191
9192 val = I915_READ(LCPLL_CTL);
9193 val &= ~LCPLL_PLL_DISABLE;
9194 I915_WRITE(LCPLL_CTL, val);
9195
Chris Wilson93220c02016-06-30 15:33:08 +01009196 if (intel_wait_for_register(dev_priv,
9197 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9198 5))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009199 DRM_ERROR("LCPLL not locked yet\n");
9200
9201 if (val & LCPLL_CD_SOURCE_FCLK) {
9202 val = I915_READ(LCPLL_CTL);
9203 val &= ~LCPLL_CD_SOURCE_FCLK;
9204 I915_WRITE(LCPLL_CTL, val);
9205
Imre Deakf53dd632016-06-28 13:37:32 +03009206 if (wait_for_us((I915_READ(LCPLL_CTL) &
9207 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009208 DRM_ERROR("Switching back to LCPLL failed\n");
9209 }
Paulo Zanoni215733f2013-08-19 13:18:07 -03009210
Mika Kuoppala59bad942015-01-16 11:34:40 +02009211 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009212
Ville Syrjälä4c75b942016-10-31 22:37:12 +02009213 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009214 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009215}
9216
Paulo Zanoni765dab672014-03-07 20:08:18 -03009217/*
9218 * Package states C8 and deeper are really deep PC states that can only be
9219 * reached when all the devices on the system allow it, so even if the graphics
9220 * device allows PC8+, it doesn't mean the system will actually get to these
9221 * states. Our driver only allows PC8+ when going into runtime PM.
9222 *
9223 * The requirements for PC8+ are that all the outputs are disabled, the power
9224 * well is disabled and most interrupts are disabled, and these are also
9225 * requirements for runtime PM. When these conditions are met, we manually do
9226 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9227 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9228 * hang the machine.
9229 *
9230 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9231 * the state of some registers, so when we come back from PC8+ we need to
9232 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9233 * need to take care of the registers kept by RC6. Notice that this happens even
9234 * if we don't put the device in PCI D3 state (which is what currently happens
9235 * because of the runtime PM support).
9236 *
9237 * For more, read "Display Sequences for Package C8" on the hardware
9238 * documentation.
9239 */
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009240void hsw_enable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009241{
Paulo Zanonic67a4702013-08-19 13:18:09 -03009242 uint32_t val;
9243
Paulo Zanonic67a4702013-08-19 13:18:09 -03009244 DRM_DEBUG_KMS("Enabling package C8+\n");
9245
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009246 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009247 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9248 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9249 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9250 }
9251
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009252 lpt_disable_clkout_dp(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009253 hsw_disable_lcpll(dev_priv, true, true);
9254}
9255
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009256void hsw_disable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009257{
Paulo Zanonic67a4702013-08-19 13:18:09 -03009258 uint32_t val;
9259
Paulo Zanonic67a4702013-08-19 13:18:09 -03009260 DRM_DEBUG_KMS("Disabling package C8+\n");
9261
9262 hsw_restore_lcpll(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009263 lpt_init_pch_refclk(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009264
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009265 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009266 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9267 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9268 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9269 }
Paulo Zanonic67a4702013-08-19 13:18:09 -03009270}
9271
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02009272static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9273 struct intel_crtc_state *crtc_state)
Paulo Zanoni09b4ddf2012-10-05 12:05:55 -03009274{
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009275 struct intel_atomic_state *state =
9276 to_intel_atomic_state(crtc_state->base.state);
9277
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009278 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009279 struct intel_encoder *encoder =
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009280 intel_get_crtc_new_encoder(state, crtc_state);
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009281
9282 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
Chris Wilson43031782018-09-13 14:16:26 +01009283 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9284 pipe_name(crtc->pipe));
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009285 return -EINVAL;
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009286 }
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009287 }
Daniel Vetter716c2e52014-06-25 22:02:02 +03009288
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02009289 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009290}
9291
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009292static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9293 enum port port,
9294 struct intel_crtc_state *pipe_config)
9295{
9296 enum intel_dpll_id id;
9297 u32 temp;
9298
9299 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
Paulo Zanonidfbd4502017-08-25 16:40:04 -03009300 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009301
9302 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9303 return;
9304
9305 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9306}
9307
Paulo Zanoni970888e2018-05-21 17:25:44 -07009308static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9309 enum port port,
9310 struct intel_crtc_state *pipe_config)
9311{
9312 enum intel_dpll_id id;
9313 u32 temp;
9314
9315 /* TODO: TBT pll not implemented. */
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309316 if (intel_port_is_combophy(dev_priv, port)) {
Paulo Zanoni970888e2018-05-21 17:25:44 -07009317 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9318 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9319 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9320
Vandita Kulkarnia54270d2018-10-03 12:52:00 +05309321 if (WARN_ON(!intel_dpll_is_combophy(id)))
Paulo Zanoni970888e2018-05-21 17:25:44 -07009322 return;
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309323 } else if (intel_port_is_tc(dev_priv, port)) {
Vandita Kulkarnicb6caf72018-10-03 12:51:58 +05309324 id = icl_port_to_mg_pll_id(port);
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309325 } else {
9326 WARN(1, "Invalid port %x\n", port);
Paulo Zanoni970888e2018-05-21 17:25:44 -07009327 return;
9328 }
9329
9330 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9331}
9332
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309333static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9334 enum port port,
9335 struct intel_crtc_state *pipe_config)
9336{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009337 enum intel_dpll_id id;
9338
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309339 switch (port) {
9340 case PORT_A:
Imre Deak08250c42016-03-14 19:55:34 +02009341 id = DPLL_ID_SKL_DPLL0;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309342 break;
9343 case PORT_B:
Imre Deak08250c42016-03-14 19:55:34 +02009344 id = DPLL_ID_SKL_DPLL1;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309345 break;
9346 case PORT_C:
Imre Deak08250c42016-03-14 19:55:34 +02009347 id = DPLL_ID_SKL_DPLL2;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309348 break;
9349 default:
9350 DRM_ERROR("Incorrect port type\n");
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009351 return;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309352 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009353
9354 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309355}
9356
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009357static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9358 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009359 struct intel_crtc_state *pipe_config)
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009360{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009361 enum intel_dpll_id id;
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +02009362 u32 temp;
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009363
9364 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009365 id = temp >> (port * 3 + 1);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009366
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009367 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009368 return;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009369
9370 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009371}
9372
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009373static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9374 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009375 struct intel_crtc_state *pipe_config)
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009376{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009377 enum intel_dpll_id id;
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009378 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009379
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009380 switch (ddi_pll_sel) {
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009381 case PORT_CLK_SEL_WRPLL1:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009382 id = DPLL_ID_WRPLL1;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009383 break;
9384 case PORT_CLK_SEL_WRPLL2:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009385 id = DPLL_ID_WRPLL2;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009386 break;
Maarten Lankhorst00490c22015-11-16 14:42:12 +01009387 case PORT_CLK_SEL_SPLL:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009388 id = DPLL_ID_SPLL;
Ville Syrjälä79bd23d2015-12-01 23:32:07 +02009389 break;
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +02009390 case PORT_CLK_SEL_LCPLL_810:
9391 id = DPLL_ID_LCPLL_810;
9392 break;
9393 case PORT_CLK_SEL_LCPLL_1350:
9394 id = DPLL_ID_LCPLL_1350;
9395 break;
9396 case PORT_CLK_SEL_LCPLL_2700:
9397 id = DPLL_ID_LCPLL_2700;
9398 break;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009399 default:
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009400 MISSING_CASE(ddi_pll_sel);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009401 /* fall through */
9402 case PORT_CLK_SEL_NONE:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009403 return;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009404 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009405
9406 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009407}
9408
Jani Nikulacf304292016-03-18 17:05:41 +02009409static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9410 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009411 u64 *power_domain_mask)
Jani Nikulacf304292016-03-18 17:05:41 +02009412{
9413 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009414 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulacf304292016-03-18 17:05:41 +02009415 enum intel_display_power_domain power_domain;
9416 u32 tmp;
9417
Imre Deakd9a7bc62016-05-12 16:18:50 +03009418 /*
9419 * The pipe->transcoder mapping is fixed with the exception of the eDP
9420 * transcoder handled below.
9421 */
Jani Nikulacf304292016-03-18 17:05:41 +02009422 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9423
9424 /*
9425 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9426 * consistency and less surprising code; it's in always on power).
9427 */
9428 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9429 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9430 enum pipe trans_edp_pipe;
9431 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9432 default:
9433 WARN(1, "unknown pipe linked to edp transcoder\n");
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05009434 /* fall through */
Jani Nikulacf304292016-03-18 17:05:41 +02009435 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9436 case TRANS_DDI_EDP_INPUT_A_ON:
9437 trans_edp_pipe = PIPE_A;
9438 break;
9439 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9440 trans_edp_pipe = PIPE_B;
9441 break;
9442 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9443 trans_edp_pipe = PIPE_C;
9444 break;
9445 }
9446
9447 if (trans_edp_pipe == crtc->pipe)
9448 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9449 }
9450
9451 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9452 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9453 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009454 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikulacf304292016-03-18 17:05:41 +02009455
9456 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9457
9458 return tmp & PIPECONF_ENABLE;
9459}
9460
Jani Nikula4d1de972016-03-18 17:05:42 +02009461static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9462 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009463 u64 *power_domain_mask)
Jani Nikula4d1de972016-03-18 17:05:42 +02009464{
9465 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009466 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikula4d1de972016-03-18 17:05:42 +02009467 enum intel_display_power_domain power_domain;
9468 enum port port;
9469 enum transcoder cpu_transcoder;
9470 u32 tmp;
9471
Jani Nikula4d1de972016-03-18 17:05:42 +02009472 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9473 if (port == PORT_A)
9474 cpu_transcoder = TRANSCODER_DSI_A;
9475 else
9476 cpu_transcoder = TRANSCODER_DSI_C;
9477
9478 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9479 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9480 continue;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009481 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikula4d1de972016-03-18 17:05:42 +02009482
Imre Deakdb18b6a2016-03-24 12:41:40 +02009483 /*
9484 * The PLL needs to be enabled with a valid divider
9485 * configuration, otherwise accessing DSI registers will hang
9486 * the machine. See BSpec North Display Engine
9487 * registers/MIPI[BXT]. We can break out here early, since we
9488 * need the same DSI PLL to be enabled for both DSI ports.
9489 */
Jani Nikulae5186342018-07-05 16:25:08 +03009490 if (!bxt_dsi_pll_is_enabled(dev_priv))
Imre Deakdb18b6a2016-03-24 12:41:40 +02009491 break;
9492
Jani Nikula4d1de972016-03-18 17:05:42 +02009493 /* XXX: this works for video mode only */
9494 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9495 if (!(tmp & DPI_ENABLE))
9496 continue;
9497
9498 tmp = I915_READ(MIPI_CTRL(port));
9499 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9500 continue;
9501
9502 pipe_config->cpu_transcoder = cpu_transcoder;
Jani Nikula4d1de972016-03-18 17:05:42 +02009503 break;
9504 }
9505
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009506 return transcoder_is_dsi(pipe_config->cpu_transcoder);
Jani Nikula4d1de972016-03-18 17:05:42 +02009507}
9508
Daniel Vetter26804af2014-06-25 22:01:55 +03009509static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009510 struct intel_crtc_state *pipe_config)
Daniel Vetter26804af2014-06-25 22:01:55 +03009511{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009512 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009513 struct intel_shared_dpll *pll;
Daniel Vetter26804af2014-06-25 22:01:55 +03009514 enum port port;
9515 uint32_t tmp;
9516
9517 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9518
9519 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9520
Paulo Zanoni970888e2018-05-21 17:25:44 -07009521 if (IS_ICELAKE(dev_priv))
9522 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9523 else if (IS_CANNONLAKE(dev_priv))
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009524 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9525 else if (IS_GEN9_BC(dev_priv))
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009526 skylake_get_ddi_pll(dev_priv, port, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009527 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309528 bxt_get_ddi_pll(dev_priv, port, pipe_config);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009529 else
9530 haswell_get_ddi_pll(dev_priv, port, pipe_config);
Daniel Vetter9cd86932014-06-25 22:01:57 +03009531
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009532 pll = pipe_config->shared_dpll;
9533 if (pll) {
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009534 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9535 &pipe_config->dpll_hw_state));
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009536 }
9537
Daniel Vetter26804af2014-06-25 22:01:55 +03009538 /*
9539 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9540 * DDI E. So just check whether this pipe is wired to DDI E and whether
9541 * the PCH transcoder is on.
9542 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009543 if (INTEL_GEN(dev_priv) < 9 &&
Damien Lespiauca370452013-12-03 13:56:24 +00009544 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
Daniel Vetter26804af2014-06-25 22:01:55 +03009545 pipe_config->has_pch_encoder = true;
9546
9547 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9548 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9549 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9550
9551 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9552 }
9553}
9554
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009555static bool haswell_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009556 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009557{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009558 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02009559 enum intel_display_power_domain power_domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009560 u64 power_domain_mask;
Jani Nikulacf304292016-03-18 17:05:41 +02009561 bool active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009562
Imre Deake79dfb52017-07-20 01:50:57 +03009563 intel_crtc_init_scalers(crtc, pipe_config);
Imre Deak5fb9dad2017-07-20 14:28:20 +03009564
Imre Deak17290502016-02-12 18:55:11 +02009565 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9566 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02009567 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009568 power_domain_mask = BIT_ULL(power_domain);
Imre Deak17290502016-02-12 18:55:11 +02009569
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009570 pipe_config->shared_dpll = NULL;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009571
Jani Nikulacf304292016-03-18 17:05:41 +02009572 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
Daniel Vettereccb1402013-05-22 00:50:22 +02009573
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009574 if (IS_GEN9_LP(dev_priv) &&
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009575 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9576 WARN_ON(active);
9577 active = true;
Jani Nikula4d1de972016-03-18 17:05:42 +02009578 }
9579
Jani Nikulacf304292016-03-18 17:05:41 +02009580 if (!active)
Imre Deak17290502016-02-12 18:55:11 +02009581 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009582
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009583 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
Jani Nikula4d1de972016-03-18 17:05:42 +02009584 haswell_get_ddi_port_state(crtc, pipe_config);
9585 intel_get_pipe_timings(crtc, pipe_config);
9586 }
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009587
Jani Nikulabc58be62016-03-18 17:05:39 +02009588 intel_get_pipe_src_size(crtc, pipe_config);
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05309589 intel_get_crtc_ycbcr_config(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009590
Lionel Landwerlin05dc6982016-03-16 10:57:15 +00009591 pipe_config->gamma_mode =
9592 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9593
Imre Deak17290502016-02-12 18:55:11 +02009594 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9595 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009596 power_domain_mask |= BIT_ULL(power_domain);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009597 if (INTEL_GEN(dev_priv) >= 9)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009598 skylake_get_pfit_config(crtc, pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08009599 else
Rodrigo Vivi1c132b42015-09-02 15:19:26 -07009600 ironlake_get_pfit_config(crtc, pipe_config);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009601 }
Daniel Vetter88adfff2013-03-28 10:42:01 +01009602
Maarten Lankhorst24f28452017-11-22 19:39:01 +01009603 if (hsw_crtc_supports_ips(crtc)) {
9604 if (IS_HASWELL(dev_priv))
9605 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9606 else {
9607 /*
9608 * We cannot readout IPS state on broadwell, set to
9609 * true so we can set it to a defined state on first
9610 * commit.
9611 */
9612 pipe_config->ips_enabled = true;
9613 }
9614 }
9615
Jani Nikula4d1de972016-03-18 17:05:42 +02009616 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9617 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
Clint Taylorebb69c92014-09-30 10:30:22 -07009618 pipe_config->pixel_multiplier =
9619 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9620 } else {
9621 pipe_config->pixel_multiplier = 1;
9622 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02009623
Imre Deak17290502016-02-12 18:55:11 +02009624out:
9625 for_each_power_domain(power_domain, power_domain_mask)
9626 intel_display_power_put(dev_priv, power_domain);
9627
Jani Nikulacf304292016-03-18 17:05:41 +02009628 return active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009629}
9630
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009631static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009632{
9633 struct drm_i915_private *dev_priv =
9634 to_i915(plane_state->base.plane->dev);
9635 const struct drm_framebuffer *fb = plane_state->base.fb;
9636 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9637 u32 base;
9638
9639 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9640 base = obj->phys_handle->busaddr;
9641 else
9642 base = intel_plane_ggtt_offset(plane_state);
9643
Ville Syrjäläc11ada02018-09-07 18:24:04 +03009644 base += plane_state->color_plane[0].offset;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009645
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009646 /* ILK+ do this automagically */
9647 if (HAS_GMCH_DISPLAY(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +10009648 plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009649 base += (plane_state->base.crtc_h *
9650 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9651
9652 return base;
9653}
9654
Ville Syrjäläed270222017-03-27 21:55:36 +03009655static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9656{
9657 int x = plane_state->base.crtc_x;
9658 int y = plane_state->base.crtc_y;
9659 u32 pos = 0;
9660
9661 if (x < 0) {
9662 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9663 x = -x;
9664 }
9665 pos |= x << CURSOR_X_SHIFT;
9666
9667 if (y < 0) {
9668 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9669 y = -y;
9670 }
9671 pos |= y << CURSOR_Y_SHIFT;
9672
9673 return pos;
9674}
9675
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009676static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9677{
9678 const struct drm_mode_config *config =
9679 &plane_state->base.plane->dev->mode_config;
9680 int width = plane_state->base.crtc_w;
9681 int height = plane_state->base.crtc_h;
9682
9683 return width > 0 && width <= config->cursor_width &&
9684 height > 0 && height <= config->cursor_height;
9685}
9686
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009687static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009688{
9689 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009690 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009691 int src_x, src_y;
9692 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009693 int ret;
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009694
9695 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
9696 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
9697
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009698 ret = intel_plane_check_stride(plane_state);
9699 if (ret)
9700 return ret;
9701
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009702 src_x = plane_state->base.src_x >> 16;
9703 src_y = plane_state->base.src_y >> 16;
9704
9705 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9706 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
9707 plane_state, 0);
9708
9709 if (src_x != 0 || src_y != 0) {
9710 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9711 return -EINVAL;
9712 }
9713
9714 plane_state->color_plane[0].offset = offset;
9715
9716 return 0;
9717}
9718
9719static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9720 struct intel_plane_state *plane_state)
9721{
9722 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009723 int ret;
9724
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009725 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9726 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9727 return -EINVAL;
9728 }
9729
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009730 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9731 &crtc_state->base,
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009732 DRM_PLANE_HELPER_NO_SCALING,
9733 DRM_PLANE_HELPER_NO_SCALING,
9734 true, true);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009735 if (ret)
9736 return ret;
9737
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009738 if (!plane_state->base.visible)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009739 return 0;
9740
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009741 ret = intel_plane_check_src_coordinates(plane_state);
9742 if (ret)
9743 return ret;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009744
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009745 ret = intel_cursor_check_surface(plane_state);
9746 if (ret)
9747 return ret;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009748
Ville Syrjälä659056f2017-03-27 21:55:39 +03009749 return 0;
9750}
9751
Ville Syrjäläddd57132018-09-07 18:24:02 +03009752static unsigned int
9753i845_cursor_max_stride(struct intel_plane *plane,
9754 u32 pixel_format, u64 modifier,
9755 unsigned int rotation)
9756{
9757 return 2048;
9758}
9759
Ville Syrjälä292889e2017-03-17 23:18:01 +02009760static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9761 const struct intel_plane_state *plane_state)
9762{
Ville Syrjälä292889e2017-03-17 23:18:01 +02009763 return CURSOR_ENABLE |
9764 CURSOR_GAMMA_ENABLE |
9765 CURSOR_FORMAT_ARGB |
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009766 CURSOR_STRIDE(plane_state->color_plane[0].stride);
Ville Syrjälä292889e2017-03-17 23:18:01 +02009767}
9768
Ville Syrjälä659056f2017-03-27 21:55:39 +03009769static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9770{
Ville Syrjälä659056f2017-03-27 21:55:39 +03009771 int width = plane_state->base.crtc_w;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009772
9773 /*
9774 * 845g/865g are only limited by the width of their cursors,
9775 * the height is arbitrary up to the precision of the register.
9776 */
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009777 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009778}
9779
Ville Syrjäläeb0f5042018-08-28 17:27:06 +03009780static int i845_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +03009781 struct intel_plane_state *plane_state)
9782{
9783 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009784 int ret;
9785
9786 ret = intel_check_cursor(crtc_state, plane_state);
9787 if (ret)
9788 return ret;
9789
9790 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009791 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009792 return 0;
9793
9794 /* Check for which cursor types we support */
9795 if (!i845_cursor_size_ok(plane_state)) {
9796 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9797 plane_state->base.crtc_w,
9798 plane_state->base.crtc_h);
9799 return -EINVAL;
9800 }
9801
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009802 WARN_ON(plane_state->base.visible &&
9803 plane_state->color_plane[0].stride != fb->pitches[0]);
9804
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009805 switch (fb->pitches[0]) {
Chris Wilson560b85b2010-08-07 11:01:38 +01009806 case 256:
9807 case 512:
9808 case 1024:
9809 case 2048:
Ville Syrjälädc41c152014-08-13 11:57:05 +03009810 break;
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009811 default:
9812 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9813 fb->pitches[0]);
9814 return -EINVAL;
Chris Wilson560b85b2010-08-07 11:01:38 +01009815 }
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +01009816
Ville Syrjälä659056f2017-03-27 21:55:39 +03009817 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9818
9819 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009820}
9821
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009822static void i845_update_cursor(struct intel_plane *plane,
9823 const struct intel_crtc_state *crtc_state,
Chris Wilson560b85b2010-08-07 11:01:38 +01009824 const struct intel_plane_state *plane_state)
9825{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009826 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009827 u32 cntl = 0, base = 0, pos = 0, size = 0;
9828 unsigned long irqflags;
Chris Wilson560b85b2010-08-07 11:01:38 +01009829
Ville Syrjälä936e71e2016-07-26 19:06:59 +03009830 if (plane_state && plane_state->base.visible) {
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +01009831 unsigned int width = plane_state->base.crtc_w;
9832 unsigned int height = plane_state->base.crtc_h;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009833
Ville Syrjäläa0864d52017-03-23 21:27:09 +02009834 cntl = plane_state->ctl;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009835 size = (height << 12) | width;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009836
9837 base = intel_cursor_base(plane_state);
9838 pos = intel_cursor_position(plane_state);
Chris Wilson4b0e3332014-05-30 16:35:26 +03009839 }
Chris Wilson560b85b2010-08-07 11:01:38 +01009840
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009841 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9842
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +03009843 /* On these chipsets we can only modify the base/size/stride
9844 * whilst the cursor is disabled.
9845 */
9846 if (plane->cursor.base != base ||
9847 plane->cursor.size != size ||
9848 plane->cursor.cntl != cntl) {
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009849 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009850 I915_WRITE_FW(CURBASE(PIPE_A), base);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009851 I915_WRITE_FW(CURSIZE, size);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009852 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009853 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
Ville Syrjälä75343a42017-03-27 21:55:38 +03009854
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +03009855 plane->cursor.base = base;
9856 plane->cursor.size = size;
9857 plane->cursor.cntl = cntl;
9858 } else {
9859 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädc41c152014-08-13 11:57:05 +03009860 }
9861
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009862 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9863}
9864
9865static void i845_disable_cursor(struct intel_plane *plane,
9866 struct intel_crtc *crtc)
9867{
9868 i845_update_cursor(plane, NULL, NULL);
Chris Wilson560b85b2010-08-07 11:01:38 +01009869}
9870
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009871static bool i845_cursor_get_hw_state(struct intel_plane *plane,
9872 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02009873{
9874 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9875 enum intel_display_power_domain power_domain;
9876 bool ret;
9877
9878 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9879 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9880 return false;
9881
9882 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9883
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009884 *pipe = PIPE_A;
9885
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02009886 intel_display_power_put(dev_priv, power_domain);
9887
9888 return ret;
9889}
9890
Ville Syrjäläddd57132018-09-07 18:24:02 +03009891static unsigned int
9892i9xx_cursor_max_stride(struct intel_plane *plane,
9893 u32 pixel_format, u64 modifier,
9894 unsigned int rotation)
9895{
9896 return plane->base.dev->mode_config.cursor_width * 4;
9897}
9898
Ville Syrjälä292889e2017-03-17 23:18:01 +02009899static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9900 const struct intel_plane_state *plane_state)
9901{
9902 struct drm_i915_private *dev_priv =
9903 to_i915(plane_state->base.plane->dev);
9904 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
José Roberto de Souzac894d632018-05-18 13:15:47 -07009905 u32 cntl = 0;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009906
Ville Syrjäläe876b782018-01-30 22:38:05 +02009907 if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
9908 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
9909
José Roberto de Souzac894d632018-05-18 13:15:47 -07009910 if (INTEL_GEN(dev_priv) <= 10) {
9911 cntl |= MCURSOR_GAMMA_ENABLE;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009912
José Roberto de Souzac894d632018-05-18 13:15:47 -07009913 if (HAS_DDI(dev_priv))
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009914 cntl |= MCURSOR_PIPE_CSC_ENABLE;
José Roberto de Souzac894d632018-05-18 13:15:47 -07009915 }
Ville Syrjälä292889e2017-03-17 23:18:01 +02009916
Ville Syrjälä32ea06b2018-01-30 22:38:01 +02009917 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9918 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
Ville Syrjälä292889e2017-03-17 23:18:01 +02009919
9920 switch (plane_state->base.crtc_w) {
9921 case 64:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009922 cntl |= MCURSOR_MODE_64_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009923 break;
9924 case 128:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009925 cntl |= MCURSOR_MODE_128_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009926 break;
9927 case 256:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009928 cntl |= MCURSOR_MODE_256_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009929 break;
9930 default:
9931 MISSING_CASE(plane_state->base.crtc_w);
9932 return 0;
9933 }
9934
Robert Fossc2c446a2017-05-19 16:50:17 -04009935 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +02009936 cntl |= MCURSOR_ROTATE_180;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009937
9938 return cntl;
9939}
9940
Ville Syrjälä659056f2017-03-27 21:55:39 +03009941static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
Chris Wilson560b85b2010-08-07 11:01:38 +01009942{
Ville Syrjälä024faac2017-03-27 21:55:42 +03009943 struct drm_i915_private *dev_priv =
9944 to_i915(plane_state->base.plane->dev);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009945 int width = plane_state->base.crtc_w;
9946 int height = plane_state->base.crtc_h;
Chris Wilson560b85b2010-08-07 11:01:38 +01009947
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009948 if (!intel_cursor_size_ok(plane_state))
Ville Syrjälädc41c152014-08-13 11:57:05 +03009949 return false;
9950
Ville Syrjälä024faac2017-03-27 21:55:42 +03009951 /* Cursor width is limited to a few power-of-two sizes */
9952 switch (width) {
Ville Syrjälä659056f2017-03-27 21:55:39 +03009953 case 256:
9954 case 128:
Ville Syrjälä659056f2017-03-27 21:55:39 +03009955 case 64:
9956 break;
9957 default:
9958 return false;
9959 }
9960
Ville Syrjälädc41c152014-08-13 11:57:05 +03009961 /*
Ville Syrjälä024faac2017-03-27 21:55:42 +03009962 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9963 * height from 8 lines up to the cursor width, when the
9964 * cursor is not rotated. Everything else requires square
9965 * cursors.
Ville Syrjälädc41c152014-08-13 11:57:05 +03009966 */
Ville Syrjälä024faac2017-03-27 21:55:42 +03009967 if (HAS_CUR_FBC(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +10009968 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
Ville Syrjälä024faac2017-03-27 21:55:42 +03009969 if (height < 8 || height > width)
Ville Syrjälädc41c152014-08-13 11:57:05 +03009970 return false;
9971 } else {
Ville Syrjälä024faac2017-03-27 21:55:42 +03009972 if (height != width)
Ville Syrjälädc41c152014-08-13 11:57:05 +03009973 return false;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009974 }
9975
9976 return true;
9977}
9978
Ville Syrjäläeb0f5042018-08-28 17:27:06 +03009979static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +03009980 struct intel_plane_state *plane_state)
9981{
Ville Syrjäläeb0f5042018-08-28 17:27:06 +03009982 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009983 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9984 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009985 enum pipe pipe = plane->pipe;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009986 int ret;
9987
9988 ret = intel_check_cursor(crtc_state, plane_state);
9989 if (ret)
9990 return ret;
9991
9992 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009993 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009994 return 0;
9995
9996 /* Check for which cursor types we support */
9997 if (!i9xx_cursor_size_ok(plane_state)) {
9998 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9999 plane_state->base.crtc_w,
10000 plane_state->base.crtc_h);
10001 return -EINVAL;
10002 }
10003
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010004 WARN_ON(plane_state->base.visible &&
10005 plane_state->color_plane[0].stride != fb->pitches[0]);
10006
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010007 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10008 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10009 fb->pitches[0], plane_state->base.crtc_w);
10010 return -EINVAL;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010011 }
10012
10013 /*
10014 * There's something wrong with the cursor on CHV pipe C.
10015 * If it straddles the left edge of the screen then
10016 * moving it away from the edge or disabling it often
10017 * results in a pipe underrun, and often that can lead to
10018 * dead pipe (constant underrun reported, and it scans
10019 * out just a solid color). To recover from that, the
10020 * display power well must be turned off and on again.
10021 * Refuse the put the cursor into that compromised position.
10022 */
10023 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10024 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10025 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10026 return -EINVAL;
10027 }
10028
10029 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10030
10031 return 0;
10032}
10033
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010034static void i9xx_update_cursor(struct intel_plane *plane,
10035 const struct intel_crtc_state *crtc_state,
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010036 const struct intel_plane_state *plane_state)
10037{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030010038 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10039 enum pipe pipe = plane->pipe;
Ville Syrjälä024faac2017-03-27 21:55:42 +030010040 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010041 unsigned long irqflags;
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010042
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010043 if (plane_state && plane_state->base.visible) {
Ville Syrjäläa0864d52017-03-23 21:27:09 +020010044 cntl = plane_state->ctl;
Chris Wilson4b0e3332014-05-30 16:35:26 +030010045
Ville Syrjälä024faac2017-03-27 21:55:42 +030010046 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10047 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10048
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010049 base = intel_cursor_base(plane_state);
10050 pos = intel_cursor_position(plane_state);
10051 }
10052
10053 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10054
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010055 /*
10056 * On some platforms writing CURCNTR first will also
10057 * cause CURPOS to be armed by the CURBASE write.
10058 * Without the CURCNTR write the CURPOS write would
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010059 * arm itself. Thus we always start the full update
10060 * with a CURCNTR write.
10061 *
10062 * On other platforms CURPOS always requires the
10063 * CURBASE write to arm the update. Additonally
10064 * a write to any of the cursor register will cancel
10065 * an already armed cursor update. Thus leaving out
10066 * the CURBASE write after CURPOS could lead to a
10067 * cursor that doesn't appear to move, or even change
10068 * shape. Thus we always write CURBASE.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010069 *
10070 * CURCNTR and CUR_FBC_CTL are always
10071 * armed by the CURBASE write only.
10072 */
10073 if (plane->cursor.base != base ||
Ville Syrjälä024faac2017-03-27 21:55:42 +030010074 plane->cursor.size != fbc_ctl ||
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010075 plane->cursor.cntl != cntl) {
10076 I915_WRITE_FW(CURCNTR(pipe), cntl);
10077 if (HAS_CUR_FBC(dev_priv))
10078 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
10079 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä75343a42017-03-27 21:55:38 +030010080 I915_WRITE_FW(CURBASE(pipe), base);
10081
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010082 plane->cursor.base = base;
10083 plane->cursor.size = fbc_ctl;
10084 plane->cursor.cntl = cntl;
10085 } else {
10086 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010087 I915_WRITE_FW(CURBASE(pipe), base);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010088 }
10089
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010090 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes65a21cd2011-10-12 11:10:21 -070010091}
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030010092
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010093static void i9xx_disable_cursor(struct intel_plane *plane,
10094 struct intel_crtc *crtc)
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010095{
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010096 i9xx_update_cursor(plane, NULL, NULL);
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010097}
Ville Syrjäläd6e4db12013-09-04 18:25:31 +030010098
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010099static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10100 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010101{
10102 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10103 enum intel_display_power_domain power_domain;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010104 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010105 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010106
10107 /*
10108 * Not 100% correct for planes that can move between pipes,
10109 * but that's only the case for gen2-3 which don't have any
10110 * display power wells.
10111 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010112 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010113 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
10114 return false;
10115
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010116 val = I915_READ(CURCNTR(plane->pipe));
10117
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010118 ret = val & MCURSOR_MODE;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010119
10120 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10121 *pipe = plane->pipe;
10122 else
10123 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10124 MCURSOR_PIPE_SELECT_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010125
10126 intel_display_power_put(dev_priv, power_domain);
10127
10128 return ret;
10129}
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010130
Jesse Barnes79e53942008-11-07 14:24:08 -080010131/* VESA 640x480x72Hz mode to set on the pipe */
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010132static const struct drm_display_mode load_detect_mode = {
Jesse Barnes79e53942008-11-07 14:24:08 -080010133 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10134 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10135};
10136
Daniel Vettera8bb6812014-02-10 18:00:39 +010010137struct drm_framebuffer *
Chris Wilson24dbf512017-02-15 10:59:18 +000010138intel_framebuffer_create(struct drm_i915_gem_object *obj,
10139 struct drm_mode_fb_cmd2 *mode_cmd)
Chris Wilsond2dff872011-04-19 08:36:26 +010010140{
10141 struct intel_framebuffer *intel_fb;
10142 int ret;
10143
10144 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010145 if (!intel_fb)
Chris Wilsond2dff872011-04-19 08:36:26 +010010146 return ERR_PTR(-ENOMEM);
Chris Wilsond2dff872011-04-19 08:36:26 +010010147
Chris Wilson24dbf512017-02-15 10:59:18 +000010148 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010149 if (ret)
10150 goto err;
Chris Wilsond2dff872011-04-19 08:36:26 +010010151
10152 return &intel_fb->base;
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010153
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010154err:
10155 kfree(intel_fb);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010156 return ERR_PTR(ret);
Chris Wilsond2dff872011-04-19 08:36:26 +010010157}
10158
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010159static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10160 struct drm_crtc *crtc)
Chris Wilsond2dff872011-04-19 08:36:26 +010010161{
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010162 struct drm_plane *plane;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010163 struct drm_plane_state *plane_state;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010164 int ret, i;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010165
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010166 ret = drm_atomic_add_affected_planes(state, crtc);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010167 if (ret)
10168 return ret;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010169
10170 for_each_new_plane_in_state(state, plane, plane_state, i) {
10171 if (plane_state->crtc != crtc)
10172 continue;
10173
10174 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10175 if (ret)
10176 return ret;
10177
10178 drm_atomic_set_fb_for_plane(plane_state, NULL);
10179 }
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010180
10181 return 0;
10182}
10183
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010184int intel_get_load_detect_pipe(struct drm_connector *connector,
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010185 const struct drm_display_mode *mode,
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010186 struct intel_load_detect_pipe *old,
10187 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010188{
10189 struct intel_crtc *intel_crtc;
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010190 struct intel_encoder *intel_encoder =
10191 intel_attached_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -080010192 struct drm_crtc *possible_crtc;
Chris Wilson4ef69c72010-09-09 15:14:28 +010010193 struct drm_encoder *encoder = &intel_encoder->base;
Jesse Barnes79e53942008-11-07 14:24:08 -080010194 struct drm_crtc *crtc = NULL;
10195 struct drm_device *dev = encoder->dev;
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010196 struct drm_i915_private *dev_priv = to_i915(dev);
Rob Clark51fd3712013-11-19 12:10:12 -050010197 struct drm_mode_config *config = &dev->mode_config;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010198 struct drm_atomic_state *state = NULL, *restore_state = NULL;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010199 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010200 struct intel_crtc_state *crtc_state;
Rob Clark51fd3712013-11-19 12:10:12 -050010201 int ret, i = -1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010202
Chris Wilsond2dff872011-04-19 08:36:26 +010010203 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010204 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010205 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010206
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010207 old->restore_state = NULL;
10208
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010209 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
Daniel Vetter6e9f7982014-05-29 23:54:47 +020010210
Jesse Barnes79e53942008-11-07 14:24:08 -080010211 /*
10212 * Algorithm gets a little messy:
Chris Wilson7a5e4802011-04-19 23:21:12 +010010213 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010214 * - if the connector already has an assigned crtc, use it (but make
10215 * sure it's on first)
Chris Wilson7a5e4802011-04-19 23:21:12 +010010216 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010217 * - try to find the first unused crtc that can drive this connector,
10218 * and use that if we find one
Jesse Barnes79e53942008-11-07 14:24:08 -080010219 */
10220
10221 /* See if we already have a CRTC for this connector */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010222 if (connector->state->crtc) {
10223 crtc = connector->state->crtc;
Chris Wilson8261b192011-04-19 23:18:09 +010010224
Rob Clark51fd3712013-11-19 12:10:12 -050010225 ret = drm_modeset_lock(&crtc->mutex, ctx);
10226 if (ret)
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010227 goto fail;
Chris Wilson8261b192011-04-19 23:18:09 +010010228
10229 /* Make sure the crtc and connector are running */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010230 goto found;
Jesse Barnes79e53942008-11-07 14:24:08 -080010231 }
10232
10233 /* Find an unused one (if possible) */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +010010234 for_each_crtc(dev, possible_crtc) {
Jesse Barnes79e53942008-11-07 14:24:08 -080010235 i++;
10236 if (!(encoder->possible_crtcs & (1 << i)))
10237 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010238
10239 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10240 if (ret)
10241 goto fail;
10242
10243 if (possible_crtc->state->enable) {
10244 drm_modeset_unlock(&possible_crtc->mutex);
Ville Syrjäläa4592492014-08-11 13:15:36 +030010245 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010246 }
Ville Syrjäläa4592492014-08-11 13:15:36 +030010247
10248 crtc = possible_crtc;
10249 break;
Jesse Barnes79e53942008-11-07 14:24:08 -080010250 }
10251
10252 /*
10253 * If we didn't find an unused CRTC, don't use any.
10254 */
10255 if (!crtc) {
Chris Wilson71731882011-04-19 23:10:58 +010010256 DRM_DEBUG_KMS("no pipe available for load-detect\n");
Dan Carpenterf4bf77b2017-04-14 22:54:25 +030010257 ret = -ENODEV;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010258 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010259 }
10260
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010261found:
10262 intel_crtc = to_intel_crtc(crtc);
10263
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010264 state = drm_atomic_state_alloc(dev);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010265 restore_state = drm_atomic_state_alloc(dev);
10266 if (!state || !restore_state) {
10267 ret = -ENOMEM;
10268 goto fail;
10269 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010270
10271 state->acquire_ctx = ctx;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010272 restore_state->acquire_ctx = ctx;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010273
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010274 connector_state = drm_atomic_get_connector_state(state, connector);
10275 if (IS_ERR(connector_state)) {
10276 ret = PTR_ERR(connector_state);
10277 goto fail;
10278 }
10279
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010280 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10281 if (ret)
10282 goto fail;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010283
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010284 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10285 if (IS_ERR(crtc_state)) {
10286 ret = PTR_ERR(crtc_state);
10287 goto fail;
10288 }
10289
Maarten Lankhorst49d6fa22015-05-11 10:45:15 +020010290 crtc_state->base.active = crtc_state->base.enable = true;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010291
Chris Wilson64927112011-04-20 07:25:26 +010010292 if (!mode)
10293 mode = &load_detect_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -080010294
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010295 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010296 if (ret)
10297 goto fail;
10298
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010299 ret = intel_modeset_disable_planes(state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010300 if (ret)
10301 goto fail;
10302
10303 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10304 if (!ret)
10305 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
Ville Syrjäläbe90cc32018-03-22 17:23:12 +020010306 if (!ret)
10307 ret = drm_atomic_add_affected_planes(restore_state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010308 if (ret) {
10309 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10310 goto fail;
10311 }
Ander Conselvan de Oliveira8c7b5cc2015-04-21 17:13:19 +030010312
Maarten Lankhorst3ba86072016-02-29 09:18:57 +010010313 ret = drm_atomic_commit(state);
10314 if (ret) {
Chris Wilson64927112011-04-20 07:25:26 +010010315 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010316 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010317 }
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010318
10319 old->restore_state = restore_state;
Chris Wilson7abbd112017-01-19 11:37:49 +000010320 drm_atomic_state_put(state);
Chris Wilson71731882011-04-19 23:10:58 +010010321
Jesse Barnes79e53942008-11-07 14:24:08 -080010322 /* let the connector get through one full cycle before testing */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010323 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Chris Wilson71731882011-04-19 23:10:58 +010010324 return true;
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010325
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010326fail:
Chris Wilson7fb71c82016-10-19 12:37:43 +010010327 if (state) {
10328 drm_atomic_state_put(state);
10329 state = NULL;
10330 }
10331 if (restore_state) {
10332 drm_atomic_state_put(restore_state);
10333 restore_state = NULL;
10334 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010335
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010336 if (ret == -EDEADLK)
10337 return ret;
Rob Clark51fd3712013-11-19 12:10:12 -050010338
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010339 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -080010340}
10341
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010342void intel_release_load_detect_pipe(struct drm_connector *connector,
Ander Conselvan de Oliveira49172fe2015-03-20 16:18:02 +020010343 struct intel_load_detect_pipe *old,
10344 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010345{
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010346 struct intel_encoder *intel_encoder =
10347 intel_attached_encoder(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +010010348 struct drm_encoder *encoder = &intel_encoder->base;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010349 struct drm_atomic_state *state = old->restore_state;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010350 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080010351
Chris Wilsond2dff872011-04-19 08:36:26 +010010352 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010353 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010354 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010355
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010356 if (!state)
Chris Wilson0622a532011-04-21 09:32:11 +010010357 return;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010358
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010010359 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Chris Wilson08536952016-10-14 13:18:18 +010010360 if (ret)
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010361 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
Chris Wilson08536952016-10-14 13:18:18 +010010362 drm_atomic_state_put(state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010363}
10364
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010365static int i9xx_pll_refclk(struct drm_device *dev,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010366 const struct intel_crtc_state *pipe_config)
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010367{
Chris Wilsonfac5e232016-07-04 11:34:36 +010010368 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010369 u32 dpll = pipe_config->dpll_hw_state.dpll;
10370
10371 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
Ville Syrjäläe91e9412013-12-09 18:54:16 +020010372 return dev_priv->vbt.lvds_ssc_freq;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010010373 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010374 return 120000;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010010375 else if (!IS_GEN2(dev_priv))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010376 return 96000;
10377 else
10378 return 48000;
10379}
10380
Jesse Barnes79e53942008-11-07 14:24:08 -080010381/* Returns the clock of the currently programmed mode of the given pipe. */
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010382static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010383 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -080010384{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010385 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010010386 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010387 int pipe = pipe_config->cpu_transcoder;
Ville Syrjälä293623f2013-09-13 16:18:46 +030010388 u32 dpll = pipe_config->dpll_hw_state.dpll;
Jesse Barnes79e53942008-11-07 14:24:08 -080010389 u32 fp;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +030010390 struct dpll clock;
Imre Deakdccbea32015-06-22 23:35:51 +030010391 int port_clock;
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010392 int refclk = i9xx_pll_refclk(dev, pipe_config);
Jesse Barnes79e53942008-11-07 14:24:08 -080010393
10394 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
Ville Syrjälä293623f2013-09-13 16:18:46 +030010395 fp = pipe_config->dpll_hw_state.fp0;
Jesse Barnes79e53942008-11-07 14:24:08 -080010396 else
Ville Syrjälä293623f2013-09-13 16:18:46 +030010397 fp = pipe_config->dpll_hw_state.fp1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010398
10399 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010400 if (IS_PINEVIEW(dev_priv)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010401 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10402 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
Shaohua Li21778322009-02-23 15:19:16 +080010403 } else {
10404 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10405 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10406 }
10407
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010010408 if (!IS_GEN2(dev_priv)) {
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010409 if (IS_PINEVIEW(dev_priv))
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010410 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10411 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
Shaohua Li21778322009-02-23 15:19:16 +080010412 else
10413 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
Jesse Barnes79e53942008-11-07 14:24:08 -080010414 DPLL_FPA01_P1_POST_DIV_SHIFT);
10415
10416 switch (dpll & DPLL_MODE_MASK) {
10417 case DPLLB_MODE_DAC_SERIAL:
10418 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10419 5 : 10;
10420 break;
10421 case DPLLB_MODE_LVDS:
10422 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10423 7 : 14;
10424 break;
10425 default:
Zhao Yakui28c97732009-10-09 11:39:41 +080010426 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
Jesse Barnes79e53942008-11-07 14:24:08 -080010427 "mode\n", (int)(dpll & DPLL_MODE_MASK));
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010428 return;
Jesse Barnes79e53942008-11-07 14:24:08 -080010429 }
10430
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010431 if (IS_PINEVIEW(dev_priv))
Imre Deakdccbea32015-06-22 23:35:51 +030010432 port_clock = pnv_calc_dpll_params(refclk, &clock);
Daniel Vetterac58c3f2013-06-01 17:16:17 +020010433 else
Imre Deakdccbea32015-06-22 23:35:51 +030010434 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010435 } else {
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010010436 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010437 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
Jesse Barnes79e53942008-11-07 14:24:08 -080010438
10439 if (is_lvds) {
10440 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10441 DPLL_FPA01_P1_POST_DIV_SHIFT);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010442
10443 if (lvds & LVDS_CLKB_POWER_UP)
10444 clock.p2 = 7;
10445 else
10446 clock.p2 = 14;
Jesse Barnes79e53942008-11-07 14:24:08 -080010447 } else {
10448 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10449 clock.p1 = 2;
10450 else {
10451 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10452 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10453 }
10454 if (dpll & PLL_P2_DIVIDE_BY_4)
10455 clock.p2 = 4;
10456 else
10457 clock.p2 = 2;
Jesse Barnes79e53942008-11-07 14:24:08 -080010458 }
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010459
Imre Deakdccbea32015-06-22 23:35:51 +030010460 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010461 }
10462
Ville Syrjälä18442d02013-09-13 16:00:08 +030010463 /*
10464 * This value includes pixel_multiplier. We will use
Damien Lespiau241bfc32013-09-25 16:45:37 +010010465 * port_clock to compute adjusted_mode.crtc_clock in the
Ville Syrjälä18442d02013-09-13 16:00:08 +030010466 * encoder's get_config() function.
10467 */
Imre Deakdccbea32015-06-22 23:35:51 +030010468 pipe_config->port_clock = port_clock;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010469}
10470
Ville Syrjälä6878da02013-09-13 15:59:11 +030010471int intel_dotclock_calculate(int link_freq,
10472 const struct intel_link_m_n *m_n)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010473{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010474 /*
10475 * The calculation for the data clock is:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010476 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010477 * But we want to avoid losing precison if possible, so:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010478 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010479 *
10480 * and the link clock is simpler:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010481 * link_clock = (m * link_clock) / n
Jesse Barnes79e53942008-11-07 14:24:08 -080010482 */
10483
Ville Syrjälä6878da02013-09-13 15:59:11 +030010484 if (!m_n->link_n)
10485 return 0;
10486
Chris Wilson31236982017-09-13 11:51:53 +010010487 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 +030010488}
10489
Ville Syrjälä18442d02013-09-13 16:00:08 +030010490static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010491 struct intel_crtc_state *pipe_config)
Ville Syrjälä6878da02013-09-13 15:59:11 +030010492{
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010493 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä18442d02013-09-13 16:00:08 +030010494
10495 /* read out port_clock from the DPLL */
10496 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä6878da02013-09-13 15:59:11 +030010497
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010498 /*
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010499 * In case there is an active pipe without active ports,
10500 * we may need some idea for the dotclock anyway.
10501 * Calculate one based on the FDI configuration.
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010502 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020010503 pipe_config->base.adjusted_mode.crtc_clock =
Ville Syrjälä21a727b2016-02-17 21:41:10 +020010504 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjälä18442d02013-09-13 16:00:08 +030010505 &pipe_config->fdi_m_n);
Jesse Barnes79e53942008-11-07 14:24:08 -080010506}
10507
Ville Syrjäläde330812017-10-09 19:19:50 +030010508/* Returns the currently programmed mode of the given encoder. */
10509struct drm_display_mode *
10510intel_encoder_current_mode(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080010511{
Ville Syrjäläde330812017-10-09 19:19:50 +030010512 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10513 struct intel_crtc_state *crtc_state;
Jesse Barnes79e53942008-11-07 14:24:08 -080010514 struct drm_display_mode *mode;
Ville Syrjäläde330812017-10-09 19:19:50 +030010515 struct intel_crtc *crtc;
10516 enum pipe pipe;
10517
10518 if (!encoder->get_hw_state(encoder, &pipe))
10519 return NULL;
10520
10521 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Jesse Barnes79e53942008-11-07 14:24:08 -080010522
10523 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10524 if (!mode)
10525 return NULL;
10526
Ville Syrjäläde330812017-10-09 19:19:50 +030010527 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10528 if (!crtc_state) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010529 kfree(mode);
10530 return NULL;
10531 }
10532
Ville Syrjäläde330812017-10-09 19:19:50 +030010533 crtc_state->base.crtc = &crtc->base;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010534
Ville Syrjäläde330812017-10-09 19:19:50 +030010535 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10536 kfree(crtc_state);
10537 kfree(mode);
10538 return NULL;
10539 }
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010540
Ville Syrjäläde330812017-10-09 19:19:50 +030010541 encoder->get_config(encoder, crtc_state);
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010542
Ville Syrjäläde330812017-10-09 19:19:50 +030010543 intel_mode_from_pipe_config(mode, crtc_state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010544
Ville Syrjäläde330812017-10-09 19:19:50 +030010545 kfree(crtc_state);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010546
Jesse Barnes79e53942008-11-07 14:24:08 -080010547 return mode;
10548}
10549
10550static void intel_crtc_destroy(struct drm_crtc *crtc)
10551{
10552 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10553
10554 drm_crtc_cleanup(crtc);
10555 kfree(intel_crtc);
10556}
10557
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010558/**
10559 * intel_wm_need_update - Check whether watermarks need updating
10560 * @plane: drm plane
10561 * @state: new plane state
10562 *
10563 * Check current plane state versus the new one to determine whether
10564 * watermarks need to be recalculated.
10565 *
10566 * Returns true or false.
10567 */
10568static bool intel_wm_need_update(struct drm_plane *plane,
10569 struct drm_plane_state *state)
10570{
Matt Roperd21fbe82015-09-24 15:53:12 -070010571 struct intel_plane_state *new = to_intel_plane_state(state);
10572 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10573
10574 /* Update watermarks on tiling or size changes. */
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010575 if (new->base.visible != cur->base.visible)
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010576 return true;
10577
10578 if (!cur->base.fb || !new->base.fb)
10579 return false;
10580
Ville Syrjäläbae781b2016-11-16 13:33:16 +020010581 if (cur->base.fb->modifier != new->base.fb->modifier ||
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010582 cur->base.rotation != new->base.rotation ||
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010583 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10584 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10585 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10586 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010587 return true;
10588
10589 return false;
10590}
10591
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010592static bool needs_scaling(const struct intel_plane_state *state)
Matt Roperd21fbe82015-09-24 15:53:12 -070010593{
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010594 int src_w = drm_rect_width(&state->base.src) >> 16;
10595 int src_h = drm_rect_height(&state->base.src) >> 16;
10596 int dst_w = drm_rect_width(&state->base.dst);
10597 int dst_h = drm_rect_height(&state->base.dst);
Matt Roperd21fbe82015-09-24 15:53:12 -070010598
10599 return (src_w != dst_w || src_h != dst_h);
10600}
10601
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010602int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10603 struct drm_crtc_state *crtc_state,
10604 const struct intel_plane_state *old_plane_state,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010605 struct drm_plane_state *plane_state)
10606{
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010607 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010608 struct drm_crtc *crtc = crtc_state->crtc;
10609 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010610 struct intel_plane *plane = to_intel_plane(plane_state->plane);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010611 struct drm_device *dev = crtc->dev;
Matt Ropered4a6a72016-02-23 17:20:13 -080010612 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010613 bool mode_changed = needs_modeset(crtc_state);
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010614 bool was_crtc_enabled = old_crtc_state->base.active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010615 bool is_crtc_enabled = crtc_state->active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010616 bool turn_off, turn_on, visible, was_visible;
10617 struct drm_framebuffer *fb = plane_state->fb;
Ville Syrjälä78108b72016-05-27 20:59:19 +030010618 int ret;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010619
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010620 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010621 ret = skl_update_scaler_plane(
10622 to_intel_crtc_state(crtc_state),
10623 to_intel_plane_state(plane_state));
10624 if (ret)
10625 return ret;
10626 }
10627
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010628 was_visible = old_plane_state->base.visible;
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010629 visible = plane_state->visible;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010630
10631 if (!was_crtc_enabled && WARN_ON(was_visible))
10632 was_visible = false;
10633
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010634 /*
10635 * Visibility is calculated as if the crtc was on, but
10636 * after scaler setup everything depends on it being off
10637 * when the crtc isn't active.
Ville Syrjäläf818ffe2016-04-29 17:31:18 +030010638 *
10639 * FIXME this is wrong for watermarks. Watermarks should also
10640 * be computed as if the pipe would be active. Perhaps move
10641 * per-plane wm computation to the .check_plane() hook, and
10642 * only combine the results from all planes in the current place?
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010643 */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010644 if (!is_crtc_enabled) {
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010645 plane_state->visible = visible = false;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010646 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10647 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010648
10649 if (!was_visible && !visible)
10650 return 0;
10651
Maarten Lankhorste8861672016-02-24 11:24:26 +010010652 if (fb != old_plane_state->base.fb)
10653 pipe_config->fb_changed = true;
10654
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010655 turn_off = was_visible && (!visible || mode_changed);
10656 turn_on = visible && (!was_visible || mode_changed);
10657
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010658 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010659 intel_crtc->base.base.id, intel_crtc->base.name,
10660 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010661 fb ? fb->base.id : -1);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010662
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010663 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 +020010664 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010665 was_visible, visible,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010666 turn_off, turn_on, mode_changed);
10667
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010668 if (turn_on) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010669 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010670 pipe_config->update_wm_pre = true;
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010671
10672 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010673 if (plane->id != PLANE_CURSOR)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010674 pipe_config->disable_cxsr = true;
10675 } else if (turn_off) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010676 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010677 pipe_config->update_wm_post = true;
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010678
Ville Syrjälä852eb002015-06-24 22:00:07 +030010679 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010680 if (plane->id != PLANE_CURSOR)
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010681 pipe_config->disable_cxsr = true;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010682 } else if (intel_wm_need_update(&plane->base, plane_state)) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010683 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010684 /* FIXME bollocks */
10685 pipe_config->update_wm_pre = true;
10686 pipe_config->update_wm_post = true;
10687 }
Ville Syrjälä852eb002015-06-24 22:00:07 +030010688 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010689
Rodrigo Vivi8be6ca82015-08-24 16:38:23 -070010690 if (visible || was_visible)
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010691 pipe_config->fb_bits |= plane->frontbuffer_bit;
Ville Syrjäläa9ff8712015-06-24 21:59:34 +030010692
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010693 /*
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010694 * ILK/SNB DVSACNTR/Sprite Enable
10695 * IVB SPR_CTL/Sprite Enable
10696 * "When in Self Refresh Big FIFO mode, a write to enable the
10697 * plane will be internally buffered and delayed while Big FIFO
10698 * mode is exiting."
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010699 *
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010700 * Which means that enabling the sprite can take an extra frame
10701 * when we start in big FIFO mode (LP1+). Thus we need to drop
10702 * down to LP0 and wait for vblank in order to make sure the
10703 * sprite gets enabled on the next vblank after the register write.
10704 * Doing otherwise would risk enabling the sprite one frame after
10705 * we've already signalled flip completion. We can resume LP1+
10706 * once the sprite has been enabled.
10707 *
10708 *
10709 * WaCxSRDisabledForSpriteScaling:ivb
10710 * IVB SPR_SCALE/Scaling Enable
10711 * "Low Power watermarks must be disabled for at least one
10712 * frame before enabling sprite scaling, and kept disabled
10713 * until sprite scaling is disabled."
10714 *
10715 * ILK/SNB DVSASCALE/Scaling Enable
10716 * "When in Self Refresh Big FIFO mode, scaling enable will be
10717 * masked off while Big FIFO mode is exiting."
10718 *
10719 * Despite the w/a only being listed for IVB we assume that
10720 * the ILK/SNB note has similar ramifications, hence we apply
10721 * the w/a on all three platforms.
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010722 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010723 if (plane->id == PLANE_SPRITE0 &&
10724 (IS_GEN5(dev_priv) || IS_GEN6(dev_priv) ||
10725 IS_IVYBRIDGE(dev_priv)) &&
10726 (turn_on || (!needs_scaling(old_plane_state) &&
10727 needs_scaling(to_intel_plane_state(plane_state)))))
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010728 pipe_config->disable_lp_wm = true;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010729
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010730 return 0;
10731}
10732
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010733static bool encoders_cloneable(const struct intel_encoder *a,
10734 const struct intel_encoder *b)
10735{
10736 /* masks could be asymmetric, so check both ways */
10737 return a == b || (a->cloneable & (1 << b->type) &&
10738 b->cloneable & (1 << a->type));
10739}
10740
10741static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10742 struct intel_crtc *crtc,
10743 struct intel_encoder *encoder)
10744{
10745 struct intel_encoder *source_encoder;
10746 struct drm_connector *connector;
10747 struct drm_connector_state *connector_state;
10748 int i;
10749
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010010750 for_each_new_connector_in_state(state, connector, connector_state, i) {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010751 if (connector_state->crtc != &crtc->base)
10752 continue;
10753
10754 source_encoder =
10755 to_intel_encoder(connector_state->best_encoder);
10756 if (!encoders_cloneable(encoder, source_encoder))
10757 return false;
10758 }
10759
10760 return true;
10761}
10762
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010763static int icl_add_linked_planes(struct intel_atomic_state *state)
10764{
10765 struct intel_plane *plane, *linked;
10766 struct intel_plane_state *plane_state, *linked_plane_state;
10767 int i;
10768
10769 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10770 linked = plane_state->linked_plane;
10771
10772 if (!linked)
10773 continue;
10774
10775 linked_plane_state = intel_atomic_get_plane_state(state, linked);
10776 if (IS_ERR(linked_plane_state))
10777 return PTR_ERR(linked_plane_state);
10778
10779 WARN_ON(linked_plane_state->linked_plane != plane);
10780 WARN_ON(linked_plane_state->slave == plane_state->slave);
10781 }
10782
10783 return 0;
10784}
10785
10786static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
10787{
10788 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10789 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10790 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
10791 struct intel_plane *plane, *linked;
10792 struct intel_plane_state *plane_state;
10793 int i;
10794
10795 if (INTEL_GEN(dev_priv) < 11)
10796 return 0;
10797
10798 /*
10799 * Destroy all old plane links and make the slave plane invisible
10800 * in the crtc_state->active_planes mask.
10801 */
10802 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10803 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
10804 continue;
10805
10806 plane_state->linked_plane = NULL;
10807 if (plane_state->slave && !plane_state->base.visible)
10808 crtc_state->active_planes &= ~BIT(plane->id);
10809
10810 plane_state->slave = false;
10811 }
10812
10813 if (!crtc_state->nv12_planes)
10814 return 0;
10815
10816 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10817 struct intel_plane_state *linked_state = NULL;
10818
10819 if (plane->pipe != crtc->pipe ||
10820 !(crtc_state->nv12_planes & BIT(plane->id)))
10821 continue;
10822
10823 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
10824 if (!icl_is_nv12_y_plane(linked->id))
10825 continue;
10826
10827 if (crtc_state->active_planes & BIT(linked->id))
10828 continue;
10829
10830 linked_state = intel_atomic_get_plane_state(state, linked);
10831 if (IS_ERR(linked_state))
10832 return PTR_ERR(linked_state);
10833
10834 break;
10835 }
10836
10837 if (!linked_state) {
10838 DRM_DEBUG_KMS("Need %d free Y planes for NV12\n",
10839 hweight8(crtc_state->nv12_planes));
10840
10841 return -EINVAL;
10842 }
10843
10844 plane_state->linked_plane = linked;
10845
10846 linked_state->slave = true;
10847 linked_state->linked_plane = plane;
10848 crtc_state->active_planes |= BIT(linked->id);
10849 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
10850 }
10851
10852 return 0;
10853}
10854
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010855static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10856 struct drm_crtc_state *crtc_state)
10857{
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +020010858 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010010859 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010860 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +020010861 struct intel_crtc_state *pipe_config =
10862 to_intel_crtc_state(crtc_state);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020010863 int ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010864 bool mode_changed = needs_modeset(crtc_state);
10865
Ville Syrjälä852eb002015-06-24 22:00:07 +030010866 if (mode_changed && !crtc_state->active)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010867 pipe_config->update_wm_post = true;
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020010868
Maarten Lankhorstad421372015-06-15 12:33:42 +020010869 if (mode_changed && crtc_state->enable &&
10870 dev_priv->display.crtc_compute_clock &&
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020010871 !WARN_ON(pipe_config->shared_dpll)) {
Maarten Lankhorstad421372015-06-15 12:33:42 +020010872 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10873 pipe_config);
10874 if (ret)
10875 return ret;
10876 }
10877
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010878 if (crtc_state->color_mgmt_changed) {
10879 ret = intel_color_check(crtc, crtc_state);
10880 if (ret)
10881 return ret;
Lionel Landwerline7852a42016-05-25 14:30:41 +010010882
10883 /*
10884 * Changing color management on Intel hardware is
10885 * handled as part of planes update.
10886 */
10887 crtc_state->planes_changed = true;
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010888 }
10889
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010890 ret = 0;
Matt Roper86c8bbb2015-09-24 15:53:16 -070010891 if (dev_priv->display.compute_pipe_wm) {
Maarten Lankhorste3bddde2016-03-01 11:07:22 +010010892 ret = dev_priv->display.compute_pipe_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080010893 if (ret) {
10894 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
Matt Roper86c8bbb2015-09-24 15:53:16 -070010895 return ret;
Matt Ropered4a6a72016-02-23 17:20:13 -080010896 }
10897 }
10898
Ville Syrjäläf255c622018-11-08 17:10:13 +020010899 if (dev_priv->display.compute_intermediate_wm) {
Matt Ropered4a6a72016-02-23 17:20:13 -080010900 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10901 return 0;
10902
10903 /*
10904 * Calculate 'intermediate' watermarks that satisfy both the
10905 * old state and the new state. We can program these
10906 * immediately.
10907 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000010908 ret = dev_priv->display.compute_intermediate_wm(dev,
Matt Ropered4a6a72016-02-23 17:20:13 -080010909 intel_crtc,
10910 pipe_config);
10911 if (ret) {
10912 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10913 return ret;
10914 }
Matt Roper86c8bbb2015-09-24 15:53:16 -070010915 }
10916
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000010917 if (INTEL_GEN(dev_priv) >= 9) {
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010918 if (mode_changed)
10919 ret = skl_update_scaler_crtc(pipe_config);
10920
10921 if (!ret)
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010922 ret = icl_check_nv12_planes(pipe_config);
10923 if (!ret)
Mahesh Kumar73b0ca82017-05-26 20:45:46 +053010924 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10925 pipe_config);
10926 if (!ret)
Ander Conselvan de Oliveira6ebc6922017-02-23 09:15:59 +020010927 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010928 pipe_config);
10929 }
10930
Maarten Lankhorst24f28452017-11-22 19:39:01 +010010931 if (HAS_IPS(dev_priv))
10932 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10933
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010934 return ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010935}
10936
Jani Nikula65b38e02015-04-13 11:26:56 +030010937static const struct drm_crtc_helper_funcs intel_helper_funcs = {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010938 .atomic_check = intel_crtc_atomic_check,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010010939};
10940
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010941static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10942{
10943 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010010944 struct drm_connector_list_iter conn_iter;
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010945
Daniel Vetterf9e905c2017-03-01 10:52:25 +010010946 drm_connector_list_iter_begin(dev, &conn_iter);
10947 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter8863dc72016-05-06 15:39:03 +020010948 if (connector->base.state->crtc)
Thomas Zimmermannef196b52018-06-18 13:01:50 +020010949 drm_connector_put(&connector->base);
Daniel Vetter8863dc72016-05-06 15:39:03 +020010950
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010951 if (connector->base.encoder) {
10952 connector->base.state->best_encoder =
10953 connector->base.encoder;
10954 connector->base.state->crtc =
10955 connector->base.encoder->crtc;
Daniel Vetter8863dc72016-05-06 15:39:03 +020010956
Thomas Zimmermannef196b52018-06-18 13:01:50 +020010957 drm_connector_get(&connector->base);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010958 } else {
10959 connector->base.state->best_encoder = NULL;
10960 connector->base.state->crtc = NULL;
10961 }
10962 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010010963 drm_connector_list_iter_end(&conn_iter);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020010964}
10965
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070010966static int
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020010967compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
10968 struct intel_crtc_state *pipe_config)
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010010969{
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020010970 struct drm_connector *connector = conn_state->connector;
10971 const struct drm_display_info *info = &connector->display_info;
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070010972 int bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010973
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070010974 switch (conn_state->max_bpc) {
10975 case 6 ... 7:
10976 bpp = 6 * 3;
10977 break;
10978 case 8 ... 9:
10979 bpp = 8 * 3;
10980 break;
10981 case 10 ... 11:
10982 bpp = 10 * 3;
10983 break;
10984 case 12:
10985 bpp = 12 * 3;
10986 break;
10987 default:
10988 return -EINVAL;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010989 }
10990
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070010991 if (bpp < pipe_config->pipe_bpp) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020010992 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
10993 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
10994 connector->base.id, connector->name,
10995 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070010996 pipe_config->pipe_bpp);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020010997
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070010998 pipe_config->pipe_bpp = bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020010999 }
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011000
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011001 return 0;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011002}
11003
11004static int
11005compute_baseline_pipe_bpp(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011006 struct intel_crtc_state *pipe_config)
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011007{
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011008 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011009 struct drm_atomic_state *state = pipe_config->base.state;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011010 struct drm_connector *connector;
11011 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011012 int bpp, i;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011013
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011014 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11015 IS_CHERRYVIEW(dev_priv)))
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011016 bpp = 10*3;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011017 else if (INTEL_GEN(dev_priv) >= 5)
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011018 bpp = 12*3;
11019 else
11020 bpp = 8*3;
11021
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011022 pipe_config->pipe_bpp = bpp;
11023
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011024 /* Clamp display bpp to connector max bpp */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011025 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011026 int ret;
11027
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011028 if (connector_state->crtc != &crtc->base)
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011029 continue;
11030
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011031 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11032 if (ret)
11033 return ret;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011034 }
11035
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011036 return 0;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011037}
11038
Daniel Vetter644db712013-09-19 14:53:58 +020011039static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11040{
11041 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11042 "type: 0x%x flags: 0x%x\n",
Damien Lespiau13428302013-09-25 16:45:36 +010011043 mode->crtc_clock,
Daniel Vetter644db712013-09-19 14:53:58 +020011044 mode->crtc_hdisplay, mode->crtc_hsync_start,
11045 mode->crtc_hsync_end, mode->crtc_htotal,
11046 mode->crtc_vdisplay, mode->crtc_vsync_start,
11047 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11048}
11049
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011050static inline void
11051intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011052 unsigned int lane_count, struct intel_link_m_n *m_n)
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011053{
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011054 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11055 id, lane_count,
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011056 m_n->gmch_m, m_n->gmch_n,
11057 m_n->link_m, m_n->link_n, m_n->tu);
11058}
11059
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011060#define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11061
11062static const char * const output_type_str[] = {
11063 OUTPUT_TYPE(UNUSED),
11064 OUTPUT_TYPE(ANALOG),
11065 OUTPUT_TYPE(DVO),
11066 OUTPUT_TYPE(SDVO),
11067 OUTPUT_TYPE(LVDS),
11068 OUTPUT_TYPE(TVOUT),
11069 OUTPUT_TYPE(HDMI),
11070 OUTPUT_TYPE(DP),
11071 OUTPUT_TYPE(EDP),
11072 OUTPUT_TYPE(DSI),
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011073 OUTPUT_TYPE(DDI),
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011074 OUTPUT_TYPE(DP_MST),
11075};
11076
11077#undef OUTPUT_TYPE
11078
11079static void snprintf_output_types(char *buf, size_t len,
11080 unsigned int output_types)
11081{
11082 char *str = buf;
11083 int i;
11084
11085 str[0] = '\0';
11086
11087 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11088 int r;
11089
11090 if ((output_types & BIT(i)) == 0)
11091 continue;
11092
11093 r = snprintf(str, len, "%s%s",
11094 str != buf ? "," : "", output_type_str[i]);
11095 if (r >= len)
11096 break;
11097 str += r;
11098 len -= r;
11099
11100 output_types &= ~BIT(i);
11101 }
11102
11103 WARN_ON_ONCE(output_types != 0);
11104}
11105
Shashank Sharmad9facae2018-10-12 11:53:07 +053011106static const char * const output_format_str[] = {
11107 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11108 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011109 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
Shashank Sharma8c79f842018-10-12 11:53:09 +053011110 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
Shashank Sharmad9facae2018-10-12 11:53:07 +053011111};
11112
11113static const char *output_formats(enum intel_output_format format)
11114{
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011115 if (format >= ARRAY_SIZE(output_format_str))
Shashank Sharmad9facae2018-10-12 11:53:07 +053011116 format = INTEL_OUTPUT_FORMAT_INVALID;
11117 return output_format_str[format];
11118}
11119
Daniel Vetterc0b03412013-05-28 12:05:54 +020011120static void intel_dump_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011121 struct intel_crtc_state *pipe_config,
Daniel Vetterc0b03412013-05-28 12:05:54 +020011122 const char *context)
11123{
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011124 struct drm_device *dev = crtc->base.dev;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011125 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011126 struct drm_plane *plane;
11127 struct intel_plane *intel_plane;
11128 struct intel_plane_state *state;
11129 struct drm_framebuffer *fb;
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011130 char buf[64];
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011131
Tvrtko Ursulin66766e42016-11-17 12:30:10 +000011132 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11133 crtc->base.base.id, crtc->base.name, context);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011134
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011135 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11136 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11137 buf, pipe_config->output_types);
11138
Shashank Sharmad9facae2018-10-12 11:53:07 +053011139 DRM_DEBUG_KMS("output format: %s\n",
11140 output_formats(pipe_config->output_format));
11141
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011142 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11143 transcoder_name(pipe_config->cpu_transcoder),
Daniel Vetterc0b03412013-05-28 12:05:54 +020011144 pipe_config->pipe_bpp, pipe_config->dither);
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011145
11146 if (pipe_config->has_pch_encoder)
11147 intel_dump_m_n_config(pipe_config, "fdi",
11148 pipe_config->fdi_lanes,
11149 &pipe_config->fdi_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011150
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011151 if (intel_crtc_has_dp_encoder(pipe_config)) {
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011152 intel_dump_m_n_config(pipe_config, "dp m_n",
11153 pipe_config->lane_count, &pipe_config->dp_m_n);
Tvrtko Ursulind806e682016-11-17 15:44:09 +000011154 if (pipe_config->has_drrs)
11155 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11156 pipe_config->lane_count,
11157 &pipe_config->dp_m2_n2);
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011158 }
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011159
Daniel Vetter55072d12014-11-20 16:10:28 +010011160 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011161 pipe_config->has_audio, pipe_config->has_infoframe);
Daniel Vetter55072d12014-11-20 16:10:28 +010011162
Daniel Vetterc0b03412013-05-28 12:05:54 +020011163 DRM_DEBUG_KMS("requested mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011164 drm_mode_debug_printmodeline(&pipe_config->base.mode);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011165 DRM_DEBUG_KMS("adjusted mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011166 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11167 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011168 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011169 pipe_config->port_clock,
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011170 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11171 pipe_config->pixel_rate);
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011172
11173 if (INTEL_GEN(dev_priv) >= 9)
11174 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11175 crtc->num_scalers,
11176 pipe_config->scaler_state.scaler_users,
11177 pipe_config->scaler_state.scaler_id);
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011178
11179 if (HAS_GMCH_DISPLAY(dev_priv))
11180 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11181 pipe_config->gmch_pfit.control,
11182 pipe_config->gmch_pfit.pgm_ratios,
11183 pipe_config->gmch_pfit.lvds_border_bits);
11184 else
11185 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11186 pipe_config->pch_pfit.pos,
11187 pipe_config->pch_pfit.size,
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000011188 enableddisabled(pipe_config->pch_pfit.enabled));
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011189
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011190 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11191 pipe_config->ips_enabled, pipe_config->double_wide);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011192
Ander Conselvan de Oliveiraf50b79f2016-12-29 17:22:12 +020011193 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
Tvrtko Ursulin415ff0f2015-05-14 13:38:31 +010011194
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011195 DRM_DEBUG_KMS("planes on this crtc\n");
11196 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011197 struct drm_format_name_buf format_name;
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011198 intel_plane = to_intel_plane(plane);
11199 if (intel_plane->pipe != crtc->pipe)
11200 continue;
11201
11202 state = to_intel_plane_state(plane->state);
11203 fb = state->base.fb;
11204 if (!fb) {
Ville Syrjälä1d577e02016-05-27 20:59:25 +030011205 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11206 plane->base.id, plane->name, state->scaler_id);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011207 continue;
11208 }
11209
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011210 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11211 plane->base.id, plane->name,
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011212 fb->base.id, fb->width, fb->height,
Ville Syrjälä438b74a2016-12-14 23:32:55 +020011213 drm_get_format_name(fb->format->format, &format_name));
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011214 if (INTEL_GEN(dev_priv) >= 9)
11215 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11216 state->scaler_id,
11217 state->base.src.x1 >> 16,
11218 state->base.src.y1 >> 16,
11219 drm_rect_width(&state->base.src) >> 16,
11220 drm_rect_height(&state->base.src) >> 16,
11221 state->base.dst.x1, state->base.dst.y1,
11222 drm_rect_width(&state->base.dst),
11223 drm_rect_height(&state->base.dst));
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011224 }
Daniel Vetterc0b03412013-05-28 12:05:54 +020011225}
11226
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011227static bool check_digital_port_conflicts(struct drm_atomic_state *state)
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011228{
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011229 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011230 struct drm_connector *connector;
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011231 struct drm_connector_list_iter conn_iter;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011232 unsigned int used_ports = 0;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011233 unsigned int used_mst_ports = 0;
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011234 bool ret = true;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011235
11236 /*
11237 * Walk the connector list instead of the encoder
11238 * list to detect the problem on ddi platforms
11239 * where there's just one encoder per digital port.
11240 */
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011241 drm_connector_list_iter_begin(dev, &conn_iter);
11242 drm_for_each_connector_iter(connector, &conn_iter) {
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011243 struct drm_connector_state *connector_state;
11244 struct intel_encoder *encoder;
11245
Maarten Lankhorst8b694492018-04-09 14:46:55 +020011246 connector_state = drm_atomic_get_new_connector_state(state, connector);
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011247 if (!connector_state)
11248 connector_state = connector->state;
11249
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011250 if (!connector_state->best_encoder)
11251 continue;
11252
11253 encoder = to_intel_encoder(connector_state->best_encoder);
11254
11255 WARN_ON(!connector_state->crtc);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011256
11257 switch (encoder->type) {
11258 unsigned int port_mask;
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011259 case INTEL_OUTPUT_DDI:
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011260 if (WARN_ON(!HAS_DDI(to_i915(dev))))
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011261 break;
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -050011262 /* else: fall through */
Ville Syrjäläcca05022016-06-22 21:57:06 +030011263 case INTEL_OUTPUT_DP:
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011264 case INTEL_OUTPUT_HDMI:
11265 case INTEL_OUTPUT_EDP:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011266 port_mask = 1 << encoder->port;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011267
11268 /* the same port mustn't appear more than once */
11269 if (used_ports & port_mask)
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011270 ret = false;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011271
11272 used_ports |= port_mask;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011273 break;
11274 case INTEL_OUTPUT_DP_MST:
11275 used_mst_ports |=
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011276 1 << encoder->port;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011277 break;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011278 default:
11279 break;
11280 }
11281 }
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011282 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011283
Ville Syrjälä477321e2016-07-28 17:50:40 +030011284 /* can't mix MST and SST/HDMI on the same port */
11285 if (used_ports & used_mst_ports)
11286 return false;
11287
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011288 return ret;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011289}
11290
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011291static void
11292clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11293{
Ville Syrjäläff32c542017-03-02 19:14:57 +020011294 struct drm_i915_private *dev_priv =
11295 to_i915(crtc_state->base.crtc->dev);
Chandra Konduru663a3642015-04-07 15:28:41 -070011296 struct intel_crtc_scaler_state scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011297 struct intel_dpll_hw_state dpll_hw_state;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011298 struct intel_shared_dpll *shared_dpll;
Ville Syrjäläff32c542017-03-02 19:14:57 +020011299 struct intel_crtc_wm_state wm_state;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011300 bool force_thru, ips_force_disable;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011301
Ander Conselvan de Oliveira7546a382015-05-20 09:03:27 +030011302 /* FIXME: before the switch to atomic started, a new pipe_config was
11303 * kzalloc'd. Code that depends on any field being zero should be
11304 * fixed, so that the crtc_state can be safely duplicated. For now,
11305 * only fields that are know to not cause problems are preserved. */
11306
Chandra Konduru663a3642015-04-07 15:28:41 -070011307 scaler_state = crtc_state->scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011308 shared_dpll = crtc_state->shared_dpll;
11309 dpll_hw_state = crtc_state->dpll_hw_state;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +020011310 force_thru = crtc_state->pch_pfit.force_thru;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011311 ips_force_disable = crtc_state->ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011312 if (IS_G4X(dev_priv) ||
11313 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläff32c542017-03-02 19:14:57 +020011314 wm_state = crtc_state->wm;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011315
Chris Wilsond2fa80a2017-03-03 15:46:44 +000011316 /* Keep base drm_crtc_state intact, only clear our extended struct */
11317 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11318 memset(&crtc_state->base + 1, 0,
11319 sizeof(*crtc_state) - sizeof(crtc_state->base));
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011320
Chandra Konduru663a3642015-04-07 15:28:41 -070011321 crtc_state->scaler_state = scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011322 crtc_state->shared_dpll = shared_dpll;
11323 crtc_state->dpll_hw_state = dpll_hw_state;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +020011324 crtc_state->pch_pfit.force_thru = force_thru;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011325 crtc_state->ips_force_disable = ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011326 if (IS_G4X(dev_priv) ||
11327 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläff32c542017-03-02 19:14:57 +020011328 crtc_state->wm = wm_state;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011329}
11330
Ander Conselvan de Oliveira548ee152015-04-21 17:13:02 +030011331static int
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011332intel_modeset_pipe_config(struct drm_crtc *crtc,
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011333 struct intel_crtc_state *pipe_config)
Daniel Vetter7758a112012-07-08 19:40:39 +020011334{
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011335 struct drm_atomic_state *state = pipe_config->base.state;
Daniel Vetter7758a112012-07-08 19:40:39 +020011336 struct intel_encoder *encoder;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011337 struct drm_connector *connector;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011338 struct drm_connector_state *connector_state;
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011339 int base_bpp, ret;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011340 int i;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011341 bool retry = true;
Daniel Vetter7758a112012-07-08 19:40:39 +020011342
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011343 clear_intel_crtc_state(pipe_config);
Daniel Vetter7758a112012-07-08 19:40:39 +020011344
Daniel Vettere143a212013-07-04 12:01:15 +020011345 pipe_config->cpu_transcoder =
11346 (enum transcoder) to_intel_crtc(crtc)->pipe;
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011347
Imre Deak2960bc92013-07-30 13:36:32 +030011348 /*
11349 * Sanitize sync polarity flags based on requested ones. If neither
11350 * positive or negative polarity is requested, treat this as meaning
11351 * negative polarity.
11352 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011353 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011354 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011355 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011356
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011357 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011358 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011359 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011360
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011361 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11362 pipe_config);
11363 if (ret)
11364 return ret;
11365
11366 base_bpp = pipe_config->pipe_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011367
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011368 /*
11369 * Determine the real pipe dimensions. Note that stereo modes can
11370 * increase the actual pipe size due to the frame doubling and
11371 * insertion of additional space for blanks between the frame. This
11372 * is stored in the crtc timings. We use the requested mode to do this
11373 * computation to clearly distinguish it from the adjusted mode, which
11374 * can be changed by the connectors in the below retry loop.
11375 */
Daniel Vetter196cd5d2017-01-25 07:26:56 +010011376 drm_mode_get_hv_timing(&pipe_config->base.mode,
Gustavo Padovanecb7e162014-12-01 15:40:09 -080011377 &pipe_config->pipe_src_w,
11378 &pipe_config->pipe_src_h);
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011379
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011380 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011381 if (connector_state->crtc != crtc)
11382 continue;
11383
11384 encoder = to_intel_encoder(connector_state->best_encoder);
11385
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011386 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11387 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011388 return -EINVAL;
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011389 }
11390
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011391 /*
11392 * Determine output_types before calling the .compute_config()
11393 * hooks so that the hooks can use this information safely.
11394 */
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011395 if (encoder->compute_output_type)
11396 pipe_config->output_types |=
11397 BIT(encoder->compute_output_type(encoder, pipe_config,
11398 connector_state));
11399 else
11400 pipe_config->output_types |= BIT(encoder->type);
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011401 }
11402
Daniel Vettere29c22c2013-02-21 00:00:16 +010011403encoder_retry:
Daniel Vetteref1b4602013-06-01 17:17:04 +020011404 /* Ensure the port clock defaults are reset when retrying. */
Daniel Vetterff9a6752013-06-01 17:16:21 +020011405 pipe_config->port_clock = 0;
Daniel Vetteref1b4602013-06-01 17:17:04 +020011406 pipe_config->pixel_multiplier = 1;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011407
Daniel Vetter135c81b2013-07-21 21:37:09 +020011408 /* Fill in default crtc timings, allow encoders to overwrite them. */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011409 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11410 CRTC_STEREO_DOUBLE);
Daniel Vetter135c81b2013-07-21 21:37:09 +020011411
Daniel Vetter7758a112012-07-08 19:40:39 +020011412 /* Pass our mode to the connectors and the CRTC to give them a chance to
11413 * adjust it according to limitations or connector properties, and also
11414 * a chance to reject the mode entirely.
11415 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011416 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011417 if (connector_state->crtc != crtc)
11418 continue;
11419
11420 encoder = to_intel_encoder(connector_state->best_encoder);
11421
Maarten Lankhorst0a478c22016-08-09 17:04:05 +020011422 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
Daniel Vetterefea6e82013-07-21 21:36:59 +020011423 DRM_DEBUG_KMS("Encoder config failure\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011424 return -EINVAL;
Daniel Vetter7758a112012-07-08 19:40:39 +020011425 }
11426 }
11427
Daniel Vetterff9a6752013-06-01 17:16:21 +020011428 /* Set default port clock if not overwritten by the encoder. Needs to be
11429 * done afterwards in case the encoder adjusts the mode. */
11430 if (!pipe_config->port_clock)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011431 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
Damien Lespiau241bfc32013-09-25 16:45:37 +010011432 * pipe_config->pixel_multiplier;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011433
Daniel Vettera43f6e02013-06-07 23:10:32 +020011434 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020011435 if (ret == -EDEADLK)
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011436 return ret;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011437 if (ret < 0) {
Daniel Vetter7758a112012-07-08 19:40:39 +020011438 DRM_DEBUG_KMS("CRTC fixup failed\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011439 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011440 }
Daniel Vettere29c22c2013-02-21 00:00:16 +010011441
11442 if (ret == RETRY) {
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011443 if (WARN(!retry, "loop in pipe configuration computation\n"))
11444 return -EINVAL;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011445
11446 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11447 retry = false;
11448 goto encoder_retry;
11449 }
11450
Daniel Vettere8fa4272015-08-12 11:43:34 +020011451 /* Dithering seems to not pass-through bits correctly when it should, so
Manasi Navare611032b2017-01-24 08:21:49 -080011452 * only enable it on 6bpc panels and when its not a compliance
11453 * test requesting 6bpc video pattern.
11454 */
11455 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11456 !pipe_config->dither_force_disable;
Daniel Vetter62f0ace2015-08-26 18:57:26 +020011457 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011458 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011459
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011460 return 0;
Daniel Vetter7758a112012-07-08 19:40:39 +020011461}
11462
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011463static bool intel_fuzzy_clock_check(int clock1, int clock2)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011464{
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011465 int diff;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011466
11467 if (clock1 == clock2)
11468 return true;
11469
11470 if (!clock1 || !clock2)
11471 return false;
11472
11473 diff = abs(clock1 - clock2);
11474
11475 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11476 return true;
11477
11478 return false;
11479}
11480
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011481static bool
11482intel_compare_m_n(unsigned int m, unsigned int n,
11483 unsigned int m2, unsigned int n2,
11484 bool exact)
11485{
11486 if (m == m2 && n == n2)
11487 return true;
11488
11489 if (exact || !m || !n || !m2 || !n2)
11490 return false;
11491
11492 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11493
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011494 if (n > n2) {
11495 while (n > n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011496 m2 <<= 1;
11497 n2 <<= 1;
11498 }
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011499 } else if (n < n2) {
11500 while (n < n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011501 m <<= 1;
11502 n <<= 1;
11503 }
11504 }
11505
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011506 if (n != n2)
11507 return false;
11508
11509 return intel_fuzzy_clock_check(m, m2);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011510}
11511
11512static bool
11513intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11514 struct intel_link_m_n *m2_n2,
11515 bool adjust)
11516{
11517 if (m_n->tu == m2_n2->tu &&
11518 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11519 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11520 intel_compare_m_n(m_n->link_m, m_n->link_n,
11521 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11522 if (adjust)
11523 *m2_n2 = *m_n;
11524
11525 return true;
11526 }
11527
11528 return false;
11529}
11530
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011531static void __printf(3, 4)
11532pipe_config_err(bool adjust, const char *name, const char *format, ...)
11533{
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011534 struct va_format vaf;
11535 va_list args;
11536
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011537 va_start(args, format);
11538 vaf.fmt = format;
11539 vaf.va = &args;
11540
Joe Perches99a95482018-03-13 15:02:15 -070011541 if (adjust)
11542 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11543 else
11544 drm_err("mismatch in %s %pV", name, &vaf);
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011545
11546 va_end(args);
11547}
11548
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011549static bool
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011550intel_pipe_config_compare(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011551 struct intel_crtc_state *current_config,
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011552 struct intel_crtc_state *pipe_config,
11553 bool adjust)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011554{
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011555 bool ret = true;
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011556 bool fixup_inherited = adjust &&
11557 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11558 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011559
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011560#define PIPE_CONF_CHECK_X(name) do { \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011561 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011562 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011563 "(expected 0x%08x, found 0x%08x)\n", \
11564 current_config->name, \
11565 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011566 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011567 } \
11568} while (0)
Daniel Vetter66e985c2013-06-05 13:34:20 +020011569
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011570#define PIPE_CONF_CHECK_I(name) do { \
Daniel Vetter08a24032013-04-19 11:25:34 +020011571 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011572 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter08a24032013-04-19 11:25:34 +020011573 "(expected %i, found %i)\n", \
11574 current_config->name, \
11575 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011576 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011577 } \
11578} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011579
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011580#define PIPE_CONF_CHECK_BOOL(name) do { \
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011581 if (current_config->name != pipe_config->name) { \
11582 pipe_config_err(adjust, __stringify(name), \
11583 "(expected %s, found %s)\n", \
11584 yesno(current_config->name), \
11585 yesno(pipe_config->name)); \
11586 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011587 } \
11588} while (0)
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011589
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011590/*
11591 * Checks state where we only read out the enabling, but not the entire
11592 * state itself (like full infoframes or ELD for audio). These states
11593 * require a full modeset on bootup to fix up.
11594 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011595#define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011596 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11597 PIPE_CONF_CHECK_BOOL(name); \
11598 } else { \
11599 pipe_config_err(adjust, __stringify(name), \
11600 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11601 yesno(current_config->name), \
11602 yesno(pipe_config->name)); \
11603 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011604 } \
11605} while (0)
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011606
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011607#define PIPE_CONF_CHECK_P(name) do { \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011608 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011609 pipe_config_err(adjust, __stringify(name), \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011610 "(expected %p, found %p)\n", \
11611 current_config->name, \
11612 pipe_config->name); \
11613 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011614 } \
11615} while (0)
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011616
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011617#define PIPE_CONF_CHECK_M_N(name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011618 if (!intel_compare_link_m_n(&current_config->name, \
11619 &pipe_config->name,\
11620 adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011621 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011622 "(expected tu %i gmch %i/%i link %i/%i, " \
11623 "found tu %i, gmch %i/%i link %i/%i)\n", \
11624 current_config->name.tu, \
11625 current_config->name.gmch_m, \
11626 current_config->name.gmch_n, \
11627 current_config->name.link_m, \
11628 current_config->name.link_n, \
11629 pipe_config->name.tu, \
11630 pipe_config->name.gmch_m, \
11631 pipe_config->name.gmch_n, \
11632 pipe_config->name.link_m, \
11633 pipe_config->name.link_n); \
11634 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011635 } \
11636} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011637
Daniel Vetter55c561a2016-03-30 11:34:36 +020011638/* This is required for BDW+ where there is only one set of registers for
11639 * switching between high and low RR.
11640 * This macro can be used whenever a comparison has to be made between one
11641 * hw state and multiple sw state variables.
11642 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011643#define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011644 if (!intel_compare_link_m_n(&current_config->name, \
11645 &pipe_config->name, adjust) && \
11646 !intel_compare_link_m_n(&current_config->alt_name, \
11647 &pipe_config->name, adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011648 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011649 "(expected tu %i gmch %i/%i link %i/%i, " \
11650 "or tu %i gmch %i/%i link %i/%i, " \
11651 "found tu %i, gmch %i/%i link %i/%i)\n", \
11652 current_config->name.tu, \
11653 current_config->name.gmch_m, \
11654 current_config->name.gmch_n, \
11655 current_config->name.link_m, \
11656 current_config->name.link_n, \
11657 current_config->alt_name.tu, \
11658 current_config->alt_name.gmch_m, \
11659 current_config->alt_name.gmch_n, \
11660 current_config->alt_name.link_m, \
11661 current_config->alt_name.link_n, \
11662 pipe_config->name.tu, \
11663 pipe_config->name.gmch_m, \
11664 pipe_config->name.gmch_n, \
11665 pipe_config->name.link_m, \
11666 pipe_config->name.link_n); \
11667 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011668 } \
11669} while (0)
Daniel Vetter88adfff2013-03-28 10:42:01 +010011670
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011671#define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011672 if ((current_config->name ^ pipe_config->name) & (mask)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011673 pipe_config_err(adjust, __stringify(name), \
11674 "(%x) (expected %i, found %i)\n", \
11675 (mask), \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011676 current_config->name & (mask), \
11677 pipe_config->name & (mask)); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011678 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011679 } \
11680} while (0)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011681
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011682#define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011683 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011684 pipe_config_err(adjust, __stringify(name), \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011685 "(expected %i, found %i)\n", \
11686 current_config->name, \
11687 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011688 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011689 } \
11690} while (0)
Ville Syrjälä5e550652013-09-06 23:29:07 +030011691
Daniel Vetterbb760062013-06-06 14:55:52 +020011692#define PIPE_CONF_QUIRK(quirk) \
11693 ((current_config->quirks | pipe_config->quirks) & (quirk))
11694
Daniel Vettereccb1402013-05-22 00:50:22 +020011695 PIPE_CONF_CHECK_I(cpu_transcoder);
11696
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011697 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
Daniel Vetter08a24032013-04-19 11:25:34 +020011698 PIPE_CONF_CHECK_I(fdi_lanes);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011699 PIPE_CONF_CHECK_M_N(fdi_m_n);
Daniel Vetter08a24032013-04-19 11:25:34 +020011700
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030011701 PIPE_CONF_CHECK_I(lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +030011702 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011703
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011704 if (INTEL_GEN(dev_priv) < 8) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011705 PIPE_CONF_CHECK_M_N(dp_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011706
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011707 if (current_config->has_drrs)
11708 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11709 } else
11710 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +030011711
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011712 PIPE_CONF_CHECK_X(output_types);
Jani Nikulaa65347b2015-11-27 12:21:46 +020011713
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011714 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11715 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11716 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11717 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11718 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11719 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011720
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011721 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11722 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11723 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11724 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11725 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11726 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011727
Daniel Vetterc93f54c2013-06-27 19:47:19 +020011728 PIPE_CONF_CHECK_I(pixel_multiplier);
Shashank Sharmad9facae2018-10-12 11:53:07 +053011729 PIPE_CONF_CHECK_I(output_format);
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011730 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010011731 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010011732 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011733 PIPE_CONF_CHECK_BOOL(limited_color_range);
Shashank Sharma15953632017-03-13 16:54:03 +053011734
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011735 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11736 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011737 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
Daniel Vetter6c49f242013-06-06 12:45:25 +020011738
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011739 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
Daniel Vetter9ed109a2014-04-24 23:54:52 +020011740
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011741 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011742 DRM_MODE_FLAG_INTERLACE);
11743
Daniel Vetterbb760062013-06-06 14:55:52 +020011744 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011745 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011746 DRM_MODE_FLAG_PHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011747 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011748 DRM_MODE_FLAG_NHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011749 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011750 DRM_MODE_FLAG_PVSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011751 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011752 DRM_MODE_FLAG_NVSYNC);
11753 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -070011754
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030011755 PIPE_CONF_CHECK_X(gmch_pfit.control);
Daniel Vettere2ff2d42015-07-15 14:15:50 +020011756 /* pfit ratios are autocomputed by the hw on gen4+ */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011757 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä7f7d8dd2016-03-15 16:40:07 +020011758 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030011759 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
Daniel Vetter99535992014-04-13 12:00:33 +020011760
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020011761 if (!adjust) {
11762 PIPE_CONF_CHECK_I(pipe_src_w);
11763 PIPE_CONF_CHECK_I(pipe_src_h);
11764
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011765 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020011766 if (current_config->pch_pfit.enabled) {
11767 PIPE_CONF_CHECK_X(pch_pfit.pos);
11768 PIPE_CONF_CHECK_X(pch_pfit.size);
11769 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +020011770
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020011771 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011772 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020011773 }
Chandra Kondurua1b22782015-04-07 15:28:45 -070011774
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011775 PIPE_CONF_CHECK_BOOL(double_wide);
Ville Syrjälä282740f2013-09-04 18:30:03 +030011776
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011777 PIPE_CONF_CHECK_P(shared_dpll);
Daniel Vetter66e985c2013-06-05 13:34:20 +020011778 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
Daniel Vetter8bcc2792013-06-05 13:34:28 +020011779 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
Daniel Vetter66e985c2013-06-05 13:34:20 +020011780 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11781 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -030011782 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
Maarten Lankhorst00490c22015-11-16 14:42:12 +010011783 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
Damien Lespiau3f4cd192014-11-13 14:55:21 +000011784 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11785 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11786 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
Paulo Zanoni2de38132017-09-22 17:53:42 -030011787 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11788 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11789 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11790 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11791 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11792 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11793 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11794 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11795 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11796 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11797 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11798 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
Paulo Zanonic27e9172018-04-27 16:14:36 -070011799 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11800 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11801 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11802 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11803 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11804 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11805 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11806 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11807 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11808 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
Daniel Vetterc0d43d62013-06-07 23:11:08 +020011809
Ville Syrjälä47eacba2016-04-12 22:14:35 +030011810 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11811 PIPE_CONF_CHECK_X(dsi_pll.div);
11812
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011813 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä42571ae2013-09-06 23:29:00 +030011814 PIPE_CONF_CHECK_I(pipe_bpp);
11815
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011816 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
Jesse Barnesa9a7e982014-01-20 14:18:04 -080011817 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
Ville Syrjälä5e550652013-09-06 23:29:07 +030011818
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030011819 PIPE_CONF_CHECK_I(min_voltage_level);
11820
Daniel Vetter66e985c2013-06-05 13:34:20 +020011821#undef PIPE_CONF_CHECK_X
Daniel Vetter08a24032013-04-19 11:25:34 +020011822#undef PIPE_CONF_CHECK_I
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011823#undef PIPE_CONF_CHECK_BOOL
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011824#undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011825#undef PIPE_CONF_CHECK_P
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011826#undef PIPE_CONF_CHECK_FLAGS
Ville Syrjälä5e550652013-09-06 23:29:07 +030011827#undef PIPE_CONF_CHECK_CLOCK_FUZZY
Daniel Vetterbb760062013-06-06 14:55:52 +020011828#undef PIPE_CONF_QUIRK
Daniel Vetter627eb5a2013-04-29 19:33:42 +020011829
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011830 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011831}
11832
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020011833static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11834 const struct intel_crtc_state *pipe_config)
11835{
11836 if (pipe_config->has_pch_encoder) {
Ville Syrjälä21a727b2016-02-17 21:41:10 +020011837 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020011838 &pipe_config->fdi_m_n);
11839 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11840
11841 /*
11842 * FDI already provided one idea for the dotclock.
11843 * Yell if the encoder disagrees.
11844 */
11845 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11846 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11847 fdi_dotclock, dotclock);
11848 }
11849}
11850
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020011851static void verify_wm_state(struct drm_crtc *crtc,
11852 struct drm_crtc_state *new_state)
Damien Lespiau08db6652014-11-04 17:06:52 +000011853{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011854 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Damien Lespiau08db6652014-11-04 17:06:52 +000011855 struct skl_ddb_allocation hw_ddb, *sw_ddb;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011856 struct skl_pipe_wm hw_wm, *sw_wm;
11857 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11858 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011859 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11860 const enum pipe pipe = intel_crtc->pipe;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011861 int plane, level, max_level = ilk_wm_max_level(dev_priv);
Damien Lespiau08db6652014-11-04 17:06:52 +000011862
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011863 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
Damien Lespiau08db6652014-11-04 17:06:52 +000011864 return;
11865
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011866 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
Maarten Lankhorst03af79e2016-10-26 15:41:36 +020011867 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011868
Damien Lespiau08db6652014-11-04 17:06:52 +000011869 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11870 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11871
Mahesh Kumar74bd8002018-04-26 19:55:15 +053011872 if (INTEL_GEN(dev_priv) >= 11)
11873 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11874 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11875 sw_ddb->enabled_slices,
11876 hw_ddb.enabled_slices);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011877 /* planes */
Matt Roper8b364b42016-10-26 15:51:28 -070011878 for_each_universal_plane(dev_priv, pipe, plane) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011879 hw_plane_wm = &hw_wm.planes[plane];
11880 sw_plane_wm = &sw_wm->planes[plane];
Damien Lespiau08db6652014-11-04 17:06:52 +000011881
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011882 /* Watermarks */
11883 for (level = 0; level <= max_level; level++) {
11884 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11885 &sw_plane_wm->wm[level]))
11886 continue;
Damien Lespiau08db6652014-11-04 17:06:52 +000011887
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011888 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",
11889 pipe_name(pipe), plane + 1, level,
11890 sw_plane_wm->wm[level].plane_en,
11891 sw_plane_wm->wm[level].plane_res_b,
11892 sw_plane_wm->wm[level].plane_res_l,
11893 hw_plane_wm->wm[level].plane_en,
11894 hw_plane_wm->wm[level].plane_res_b,
11895 hw_plane_wm->wm[level].plane_res_l);
11896 }
11897
11898 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11899 &sw_plane_wm->trans_wm)) {
11900 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",
11901 pipe_name(pipe), plane + 1,
11902 sw_plane_wm->trans_wm.plane_en,
11903 sw_plane_wm->trans_wm.plane_res_b,
11904 sw_plane_wm->trans_wm.plane_res_l,
11905 hw_plane_wm->trans_wm.plane_en,
11906 hw_plane_wm->trans_wm.plane_res_b,
11907 hw_plane_wm->trans_wm.plane_res_l);
11908 }
11909
11910 /* DDB */
11911 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11912 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11913
11914 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040011915 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 -040011916 pipe_name(pipe), plane + 1,
11917 sw_ddb_entry->start, sw_ddb_entry->end,
11918 hw_ddb_entry->start, hw_ddb_entry->end);
11919 }
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011920 }
11921
Lyude27082492016-08-24 07:48:10 +020011922 /*
11923 * cursor
11924 * If the cursor plane isn't active, we may not have updated it's ddb
11925 * allocation. In that case since the ddb allocation will be updated
11926 * once the plane becomes visible, we can skip this check
11927 */
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030011928 if (1) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011929 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11930 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011931
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011932 /* Watermarks */
11933 for (level = 0; level <= max_level; level++) {
11934 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11935 &sw_plane_wm->wm[level]))
11936 continue;
11937
11938 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",
11939 pipe_name(pipe), level,
11940 sw_plane_wm->wm[level].plane_en,
11941 sw_plane_wm->wm[level].plane_res_b,
11942 sw_plane_wm->wm[level].plane_res_l,
11943 hw_plane_wm->wm[level].plane_en,
11944 hw_plane_wm->wm[level].plane_res_b,
11945 hw_plane_wm->wm[level].plane_res_l);
11946 }
11947
11948 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11949 &sw_plane_wm->trans_wm)) {
11950 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11951 pipe_name(pipe),
11952 sw_plane_wm->trans_wm.plane_en,
11953 sw_plane_wm->trans_wm.plane_res_b,
11954 sw_plane_wm->trans_wm.plane_res_l,
11955 hw_plane_wm->trans_wm.plane_en,
11956 hw_plane_wm->trans_wm.plane_res_b,
11957 hw_plane_wm->trans_wm.plane_res_l);
11958 }
11959
11960 /* DDB */
11961 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11962 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11963
11964 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040011965 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
Lyude27082492016-08-24 07:48:10 +020011966 pipe_name(pipe),
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011967 sw_ddb_entry->start, sw_ddb_entry->end,
11968 hw_ddb_entry->start, hw_ddb_entry->end);
Lyude27082492016-08-24 07:48:10 +020011969 }
Damien Lespiau08db6652014-11-04 17:06:52 +000011970 }
11971}
11972
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020011973static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010011974verify_connector_state(struct drm_device *dev,
11975 struct drm_atomic_state *state,
11976 struct drm_crtc *crtc)
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011977{
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020011978 struct drm_connector *connector;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011979 struct drm_connector_state *new_conn_state;
Maarten Lankhorst677100c2016-11-08 13:55:41 +010011980 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011981
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011982 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020011983 struct drm_encoder *encoder = connector->encoder;
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020011984 struct drm_crtc_state *crtc_state = NULL;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020011985
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011986 if (new_conn_state->crtc != crtc)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011987 continue;
11988
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020011989 if (crtc)
11990 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11991
11992 intel_connector_verify_state(crtc_state, new_conn_state);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011993
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011994 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020011995 "connector's atomic encoder doesn't match legacy encoder\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020011996 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020011997}
11998
11999static void
Daniel Vetter86b04262017-03-01 10:52:26 +010012000verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012001{
12002 struct intel_encoder *encoder;
Daniel Vetter86b04262017-03-01 10:52:26 +010012003 struct drm_connector *connector;
12004 struct drm_connector_state *old_conn_state, *new_conn_state;
12005 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012006
Damien Lespiaub2784e12014-08-05 11:29:37 +010012007 for_each_intel_encoder(dev, encoder) {
Daniel Vetter86b04262017-03-01 10:52:26 +010012008 bool enabled = false, found = false;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012009 enum pipe pipe;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012010
12011 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12012 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030012013 encoder->base.name);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012014
Daniel Vetter86b04262017-03-01 10:52:26 +010012015 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
12016 new_conn_state, i) {
12017 if (old_conn_state->best_encoder == &encoder->base)
12018 found = true;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012019
Daniel Vetter86b04262017-03-01 10:52:26 +010012020 if (new_conn_state->best_encoder != &encoder->base)
12021 continue;
12022 found = enabled = true;
12023
12024 I915_STATE_WARN(new_conn_state->crtc !=
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012025 encoder->base.crtc,
12026 "connector's crtc doesn't match encoder crtc\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012027 }
Daniel Vetter86b04262017-03-01 10:52:26 +010012028
12029 if (!found)
12030 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +100012031
Rob Clarke2c719b2014-12-15 13:56:32 -050012032 I915_STATE_WARN(!!encoder->base.crtc != enabled,
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012033 "encoder's enabled state mismatch "
12034 "(expected %i, found %i)\n",
12035 !!encoder->base.crtc, enabled);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012036
12037 if (!encoder->base.crtc) {
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012038 bool active;
12039
12040 active = encoder->get_hw_state(encoder, &pipe);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012041 I915_STATE_WARN(active,
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012042 "encoder detached but still enabled on pipe %c.\n",
12043 pipe_name(pipe));
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012044 }
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012045 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012046}
12047
12048static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012049verify_crtc_state(struct drm_crtc *crtc,
12050 struct drm_crtc_state *old_crtc_state,
12051 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012052{
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012053 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010012054 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012055 struct intel_encoder *encoder;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012056 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12057 struct intel_crtc_state *pipe_config, *sw_config;
12058 struct drm_atomic_state *old_state;
12059 bool active;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012060
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012061 old_state = old_crtc_state->state;
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020012062 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012063 pipe_config = to_intel_crtc_state(old_crtc_state);
12064 memset(pipe_config, 0, sizeof(*pipe_config));
12065 pipe_config->base.crtc = crtc;
12066 pipe_config->base.state = old_state;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012067
Ville Syrjälä78108b72016-05-27 20:59:19 +030012068 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012069
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012070 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012071
Ville Syrjäläe56134b2017-06-01 17:36:19 +030012072 /* we keep both pipes enabled on 830 */
12073 if (IS_I830(dev_priv))
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012074 active = new_crtc_state->active;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012075
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012076 I915_STATE_WARN(new_crtc_state->active != active,
12077 "crtc active state doesn't match with hw state "
12078 "(expected %i, found %i)\n", new_crtc_state->active, active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012079
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012080 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12081 "transitional active state does not match atomic hw state "
12082 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012083
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012084 for_each_encoder_on_crtc(dev, crtc, encoder) {
12085 enum pipe pipe;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012086
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012087 active = encoder->get_hw_state(encoder, &pipe);
12088 I915_STATE_WARN(active != new_crtc_state->active,
12089 "[ENCODER:%i] active %i with crtc active %i\n",
12090 encoder->base.base.id, active, new_crtc_state->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012091
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012092 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12093 "Encoder connected to wrong pipe %c\n",
12094 pipe_name(pipe));
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012095
Ville Syrjäläe1214b92017-10-27 22:31:23 +030012096 if (active)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012097 encoder->get_config(encoder, pipe_config);
12098 }
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012099
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020012100 intel_crtc_compute_pixel_rate(pipe_config);
12101
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012102 if (!new_crtc_state->active)
12103 return;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012104
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012105 intel_pipe_config_sanity_check(dev_priv, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012106
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012107 sw_config = to_intel_crtc_state(new_crtc_state);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012108 if (!intel_pipe_config_compare(dev_priv, sw_config,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012109 pipe_config, false)) {
12110 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12111 intel_dump_pipe_config(intel_crtc, pipe_config,
12112 "[hw state]");
12113 intel_dump_pipe_config(intel_crtc, sw_config,
12114 "[sw state]");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012115 }
12116}
12117
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012118static void
Ville Syrjäläcff109f2017-11-17 21:19:17 +020012119intel_verify_planes(struct intel_atomic_state *state)
12120{
12121 struct intel_plane *plane;
12122 const struct intel_plane_state *plane_state;
12123 int i;
12124
12125 for_each_new_intel_plane_in_state(state, plane,
12126 plane_state, i)
12127 assert_plane(plane, plane_state->base.visible);
12128}
12129
12130static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012131verify_single_dpll_state(struct drm_i915_private *dev_priv,
12132 struct intel_shared_dpll *pll,
12133 struct drm_crtc *crtc,
12134 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012135{
12136 struct intel_dpll_hw_state dpll_hw_state;
Ville Syrjälä40560e22018-06-26 22:47:11 +030012137 unsigned int crtc_mask;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012138 bool active;
12139
12140 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12141
Lucas De Marchi72f775f2018-03-20 15:06:34 -070012142 DRM_DEBUG_KMS("%s\n", pll->info->name);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012143
Lucas De Marchiee1398b2018-03-20 15:06:33 -070012144 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012145
Lucas De Marchi5cd281f2018-03-20 15:06:36 -070012146 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012147 I915_STATE_WARN(!pll->on && pll->active_mask,
12148 "pll in active use but not on in sw tracking\n");
12149 I915_STATE_WARN(pll->on && !pll->active_mask,
12150 "pll is on but not used by any active crtc\n");
12151 I915_STATE_WARN(pll->on != active,
12152 "pll on state mismatch (expected %i, found %i)\n",
12153 pll->on, active);
12154 }
12155
12156 if (!crtc) {
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012157 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012158 "more active pll users than references: %x vs %x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012159 pll->active_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012160
12161 return;
12162 }
12163
Ville Syrjälä40560e22018-06-26 22:47:11 +030012164 crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012165
12166 if (new_state->active)
12167 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12168 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12169 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12170 else
12171 I915_STATE_WARN(pll->active_mask & crtc_mask,
12172 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12173 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12174
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012175 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012176 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012177 crtc_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012178
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012179 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012180 &dpll_hw_state,
12181 sizeof(dpll_hw_state)),
12182 "pll hw state mismatch\n");
12183}
12184
12185static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012186verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12187 struct drm_crtc_state *old_crtc_state,
12188 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012189{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012190 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012191 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12192 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12193
12194 if (new_state->shared_dpll)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012195 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012196
12197 if (old_state->shared_dpll &&
12198 old_state->shared_dpll != new_state->shared_dpll) {
Ville Syrjälä40560e22018-06-26 22:47:11 +030012199 unsigned int crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012200 struct intel_shared_dpll *pll = old_state->shared_dpll;
12201
12202 I915_STATE_WARN(pll->active_mask & crtc_mask,
12203 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12204 pipe_name(drm_crtc_index(crtc)));
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012205 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012206 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12207 pipe_name(drm_crtc_index(crtc)));
12208 }
12209}
12210
12211static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012212intel_modeset_verify_crtc(struct drm_crtc *crtc,
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012213 struct drm_atomic_state *state,
12214 struct drm_crtc_state *old_state,
12215 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012216{
Daniel Vetter5a21b662016-05-24 17:13:53 +020012217 if (!needs_modeset(new_state) &&
12218 !to_intel_crtc_state(new_state)->update_pipe)
12219 return;
12220
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012221 verify_wm_state(crtc, new_state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012222 verify_connector_state(crtc->dev, state, crtc);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012223 verify_crtc_state(crtc, old_state, new_state);
12224 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012225}
12226
12227static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012228verify_disabled_dpll_state(struct drm_device *dev)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012229{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012230 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012231 int i;
Daniel Vetter53589012013-06-05 13:34:16 +020012232
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012233 for (i = 0; i < dev_priv->num_shared_dpll; i++)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012234 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012235}
Daniel Vetter53589012013-06-05 13:34:16 +020012236
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012237static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012238intel_modeset_verify_disabled(struct drm_device *dev,
12239 struct drm_atomic_state *state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012240{
Daniel Vetter86b04262017-03-01 10:52:26 +010012241 verify_encoder_state(dev, state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012242 verify_connector_state(dev, state, NULL);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012243 verify_disabled_dpll_state(dev);
Daniel Vetter25c5b262012-07-08 22:08:04 +020012244}
12245
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012246static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012247{
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012248 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012249 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä80715b22014-05-15 20:23:23 +030012250
12251 /*
12252 * The scanline counter increments at the leading edge of hsync.
12253 *
12254 * On most platforms it starts counting from vtotal-1 on the
12255 * first active line. That means the scanline counter value is
12256 * always one less than what we would expect. Ie. just after
12257 * start of vblank, which also occurs at start of hsync (on the
12258 * last active line), the scanline counter will read vblank_start-1.
12259 *
12260 * On gen2 the scanline counter starts counting from 1 instead
12261 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12262 * to keep the value positive), instead of adding one.
12263 *
12264 * On HSW+ the behaviour of the scanline counter depends on the output
12265 * type. For DP ports it behaves like most other platforms, but on HDMI
12266 * there's an extra 1 line difference. So we need to add two instead of
12267 * one to the value.
Ville Syrjäläec1b4ee2016-12-15 19:47:34 +020012268 *
12269 * On VLV/CHV DSI the scanline counter would appear to increment
12270 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12271 * that means we can't tell whether we're in vblank or not while
12272 * we're on that particular line. We must still set scanline_offset
12273 * to 1 so that the vblank timestamps come out correct when we query
12274 * the scanline counter from within the vblank interrupt handler.
12275 * However if queried just before the start of vblank we'll get an
12276 * answer that's slightly in the future.
Ville Syrjälä80715b22014-05-15 20:23:23 +030012277 */
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012278 if (IS_GEN2(dev_priv)) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012279 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä80715b22014-05-15 20:23:23 +030012280 int vtotal;
12281
Ville Syrjälä124abe02015-09-08 13:40:45 +030012282 vtotal = adjusted_mode->crtc_vtotal;
12283 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012284 vtotal /= 2;
12285
12286 crtc->scanline_offset = vtotal - 1;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012287 } else if (HAS_DDI(dev_priv) &&
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012288 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
Ville Syrjälä80715b22014-05-15 20:23:23 +030012289 crtc->scanline_offset = 2;
12290 } else
12291 crtc->scanline_offset = 1;
12292}
12293
Maarten Lankhorstad421372015-06-15 12:33:42 +020012294static void intel_modeset_clear_plls(struct drm_atomic_state *state)
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012295{
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012296 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012297 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012298 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012299 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012300 int i;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012301
12302 if (!dev_priv->display.crtc_compute_clock)
Maarten Lankhorstad421372015-06-15 12:33:42 +020012303 return;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012304
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012305 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012306 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012307 struct intel_shared_dpll *old_dpll =
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012308 to_intel_crtc_state(old_crtc_state)->shared_dpll;
Maarten Lankhorstad421372015-06-15 12:33:42 +020012309
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012310 if (!needs_modeset(new_crtc_state))
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012311 continue;
12312
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012313 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012314
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012315 if (!old_dpll)
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012316 continue;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012317
Ander Conselvan de Oliveiraa1c414e2016-12-29 17:22:07 +020012318 intel_release_shared_dpll(old_dpll, intel_crtc, state);
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012319 }
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012320}
12321
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012322/*
12323 * This implements the workaround described in the "notes" section of the mode
12324 * set sequence documentation. When going from no pipes or single pipe to
12325 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12326 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12327 */
12328static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12329{
12330 struct drm_crtc_state *crtc_state;
12331 struct intel_crtc *intel_crtc;
12332 struct drm_crtc *crtc;
12333 struct intel_crtc_state *first_crtc_state = NULL;
12334 struct intel_crtc_state *other_crtc_state = NULL;
12335 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12336 int i;
12337
12338 /* look at all crtc's that are going to be enabled in during modeset */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012339 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012340 intel_crtc = to_intel_crtc(crtc);
12341
12342 if (!crtc_state->active || !needs_modeset(crtc_state))
12343 continue;
12344
12345 if (first_crtc_state) {
12346 other_crtc_state = to_intel_crtc_state(crtc_state);
12347 break;
12348 } else {
12349 first_crtc_state = to_intel_crtc_state(crtc_state);
12350 first_pipe = intel_crtc->pipe;
12351 }
12352 }
12353
12354 /* No workaround needed? */
12355 if (!first_crtc_state)
12356 return 0;
12357
12358 /* w/a possibly needed, check how many crtc's are already enabled. */
12359 for_each_intel_crtc(state->dev, intel_crtc) {
12360 struct intel_crtc_state *pipe_config;
12361
12362 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12363 if (IS_ERR(pipe_config))
12364 return PTR_ERR(pipe_config);
12365
12366 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12367
12368 if (!pipe_config->base.active ||
12369 needs_modeset(&pipe_config->base))
12370 continue;
12371
12372 /* 2 or more enabled crtcs means no need for w/a */
12373 if (enabled_pipe != INVALID_PIPE)
12374 return 0;
12375
12376 enabled_pipe = intel_crtc->pipe;
12377 }
12378
12379 if (enabled_pipe != INVALID_PIPE)
12380 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12381 else if (other_crtc_state)
12382 other_crtc_state->hsw_workaround_pipe = first_pipe;
12383
12384 return 0;
12385}
12386
Ville Syrjälä8d965612016-11-14 18:35:10 +020012387static int intel_lock_all_pipes(struct drm_atomic_state *state)
12388{
12389 struct drm_crtc *crtc;
12390
12391 /* Add all pipes to the state */
12392 for_each_crtc(state->dev, crtc) {
12393 struct drm_crtc_state *crtc_state;
12394
12395 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12396 if (IS_ERR(crtc_state))
12397 return PTR_ERR(crtc_state);
12398 }
12399
12400 return 0;
12401}
12402
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012403static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12404{
12405 struct drm_crtc *crtc;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012406
Ville Syrjälä8d965612016-11-14 18:35:10 +020012407 /*
12408 * Add all pipes to the state, and force
12409 * a modeset on all the active ones.
12410 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012411 for_each_crtc(state->dev, crtc) {
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012412 struct drm_crtc_state *crtc_state;
12413 int ret;
12414
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012415 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12416 if (IS_ERR(crtc_state))
12417 return PTR_ERR(crtc_state);
12418
12419 if (!crtc_state->active || needs_modeset(crtc_state))
12420 continue;
12421
12422 crtc_state->mode_changed = true;
12423
12424 ret = drm_atomic_add_affected_connectors(state, crtc);
12425 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012426 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012427
12428 ret = drm_atomic_add_affected_planes(state, crtc);
12429 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012430 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012431 }
12432
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012433 return 0;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012434}
12435
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012436static int intel_modeset_checks(struct drm_atomic_state *state)
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012437{
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012438 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012439 struct drm_i915_private *dev_priv = to_i915(state->dev);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012440 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012441 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012442 int ret = 0, i;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012443
Maarten Lankhorstb3592832015-06-15 12:33:38 +020012444 if (!check_digital_port_conflicts(state)) {
12445 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12446 return -EINVAL;
12447 }
12448
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012449 intel_state->modeset = true;
12450 intel_state->active_crtcs = dev_priv->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012451 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12452 intel_state->cdclk.actual = dev_priv->cdclk.actual;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012453
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012454 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12455 if (new_crtc_state->active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012456 intel_state->active_crtcs |= 1 << i;
12457 else
12458 intel_state->active_crtcs &= ~(1 << i);
Matt Roper8b4a7d02016-05-12 07:06:00 -070012459
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012460 if (old_crtc_state->active != new_crtc_state->active)
Matt Roper8b4a7d02016-05-12 07:06:00 -070012461 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012462 }
12463
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012464 /*
12465 * See if the config requires any additional preparation, e.g.
12466 * to adjust global state with pipes off. We need to do this
12467 * here so we can get the modeset_pipe updated config for the new
12468 * mode set on this crtc. For other crtcs we need to use the
12469 * adjusted_mode bits in the crtc directly.
12470 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012471 if (dev_priv->display.modeset_calc_cdclk) {
Clint Taylorc89e39f2016-05-13 23:41:21 +030012472 ret = dev_priv->display.modeset_calc_cdclk(state);
12473 if (ret < 0)
12474 return ret;
12475
Ville Syrjälä8d965612016-11-14 18:35:10 +020012476 /*
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012477 * Writes to dev_priv->cdclk.logical must protected by
Ville Syrjälä8d965612016-11-14 18:35:10 +020012478 * holding all the crtc locks, even if we don't end up
12479 * touching the hardware
12480 */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012481 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12482 &intel_state->cdclk.logical)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012483 ret = intel_lock_all_pipes(state);
12484 if (ret < 0)
12485 return ret;
12486 }
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012487
Ville Syrjälä8d965612016-11-14 18:35:10 +020012488 /* All pipes must be switched off while we change the cdclk. */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012489 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12490 &intel_state->cdclk.actual)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012491 ret = intel_modeset_all_pipes(state);
12492 if (ret < 0)
12493 return ret;
12494 }
Maarten Lankhorste8788cb2016-02-16 10:25:11 +010012495
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012496 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12497 intel_state->cdclk.logical.cdclk,
12498 intel_state->cdclk.actual.cdclk);
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030012499 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12500 intel_state->cdclk.logical.voltage_level,
12501 intel_state->cdclk.actual.voltage_level);
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012502 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012503 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012504 }
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012505
Maarten Lankhorstad421372015-06-15 12:33:42 +020012506 intel_modeset_clear_plls(state);
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012507
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012508 if (IS_HASWELL(dev_priv))
Maarten Lankhorstad421372015-06-15 12:33:42 +020012509 return haswell_mode_set_planes_workaround(state);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012510
Maarten Lankhorstad421372015-06-15 12:33:42 +020012511 return 0;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012512}
12513
Matt Roperaa363132015-09-24 15:53:18 -070012514/*
12515 * Handle calculation of various watermark data at the end of the atomic check
12516 * phase. The code here should be run after the per-crtc and per-plane 'check'
12517 * handlers to ensure that all derived state has been updated.
12518 */
Matt Roper55994c22016-05-12 07:06:08 -070012519static int calc_watermark_data(struct drm_atomic_state *state)
Matt Roperaa363132015-09-24 15:53:18 -070012520{
12521 struct drm_device *dev = state->dev;
Matt Roper98d39492016-05-12 07:06:03 -070012522 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roper98d39492016-05-12 07:06:03 -070012523
12524 /* Is there platform-specific watermark information to calculate? */
12525 if (dev_priv->display.compute_global_watermarks)
Matt Roper55994c22016-05-12 07:06:08 -070012526 return dev_priv->display.compute_global_watermarks(state);
12527
12528 return 0;
Matt Roperaa363132015-09-24 15:53:18 -070012529}
12530
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012531/**
12532 * intel_atomic_check - validate state object
12533 * @dev: drm device
12534 * @state: state to validate
12535 */
12536static int intel_atomic_check(struct drm_device *dev,
12537 struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012538{
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012539 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roperaa363132015-09-24 15:53:18 -070012540 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012541 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012542 struct drm_crtc_state *old_crtc_state, *crtc_state;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012543 int ret, i;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012544 bool any_ms = false;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012545
Maarten Lankhorst8c58f732018-02-21 10:28:08 +010012546 /* Catch I915_MODE_FLAG_INHERITED */
12547 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12548 crtc_state, i) {
12549 if (crtc_state->mode.private_flags !=
12550 old_crtc_state->mode.private_flags)
12551 crtc_state->mode_changed = true;
12552 }
12553
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012554 ret = drm_atomic_helper_check_modeset(dev, state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012555 if (ret)
12556 return ret;
12557
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012558 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012559 struct intel_crtc_state *pipe_config =
12560 to_intel_crtc_state(crtc_state);
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012561
Daniel Vetter26495482015-07-15 14:15:52 +020012562 if (!needs_modeset(crtc_state))
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012563 continue;
12564
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012565 if (!crtc_state->enable) {
12566 any_ms = true;
12567 continue;
12568 }
12569
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012570 ret = intel_modeset_pipe_config(crtc, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020012571 if (ret == -EDEADLK)
12572 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012573 if (ret) {
12574 intel_dump_pipe_config(to_intel_crtc(crtc),
12575 pipe_config, "[failed]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012576 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012577 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012578
Michal Wajdeczko4f044a82017-09-19 19:38:44 +000012579 if (i915_modparams.fastboot &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012580 intel_pipe_config_compare(dev_priv,
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012581 to_intel_crtc_state(old_crtc_state),
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012582 pipe_config, true)) {
Daniel Vetter26495482015-07-15 14:15:52 +020012583 crtc_state->mode_changed = false;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012584 pipe_config->update_pipe = true;
Daniel Vetter26495482015-07-15 14:15:52 +020012585 }
12586
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012587 if (needs_modeset(crtc_state))
Daniel Vetter26495482015-07-15 14:15:52 +020012588 any_ms = true;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012589
Daniel Vetter26495482015-07-15 14:15:52 +020012590 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12591 needs_modeset(crtc_state) ?
12592 "[modeset]" : "[fastset]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012593 }
12594
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012595 if (any_ms) {
12596 ret = intel_modeset_checks(state);
12597
12598 if (ret)
12599 return ret;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012600 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012601 intel_state->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012602 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012603
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020012604 ret = icl_add_linked_planes(intel_state);
12605 if (ret)
12606 return ret;
12607
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012608 ret = drm_atomic_helper_check_planes(dev, state);
Matt Roperaa363132015-09-24 15:53:18 -070012609 if (ret)
12610 return ret;
12611
Ville Syrjälädd576022017-11-17 21:19:14 +020012612 intel_fbc_choose_crtc(dev_priv, intel_state);
Matt Roper55994c22016-05-12 07:06:08 -070012613 return calc_watermark_data(state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012614}
12615
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012616static int intel_atomic_prepare_commit(struct drm_device *dev,
Chris Wilsond07f0e52016-10-28 13:58:44 +010012617 struct drm_atomic_state *state)
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012618{
Chris Wilsonfd700752017-07-26 17:00:36 +010012619 return drm_atomic_helper_prepare_planes(dev, state);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012620}
12621
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012622u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12623{
12624 struct drm_device *dev = crtc->base.dev;
12625
12626 if (!dev->max_vblank_count)
Dhinakaran Pandiyan734cbbf2018-02-02 21:12:54 -080012627 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012628
12629 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12630}
12631
Lyude896e5bb2016-08-24 07:48:09 +020012632static void intel_update_crtc(struct drm_crtc *crtc,
12633 struct drm_atomic_state *state,
12634 struct drm_crtc_state *old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012635 struct drm_crtc_state *new_crtc_state)
Lyude896e5bb2016-08-24 07:48:09 +020012636{
12637 struct drm_device *dev = crtc->dev;
12638 struct drm_i915_private *dev_priv = to_i915(dev);
12639 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012640 struct intel_crtc_state *old_intel_cstate = to_intel_crtc_state(old_crtc_state);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012641 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12642 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012643 struct intel_plane_state *new_plane_state =
12644 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12645 to_intel_plane(crtc->primary));
Lyude896e5bb2016-08-24 07:48:09 +020012646
12647 if (modeset) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012648 update_scanline_offset(pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020012649 dev_priv->display.crtc_enable(pipe_config, state);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012650
12651 /* vblanks work again, re-enable pipe CRC. */
12652 intel_crtc_enable_pipe_crc(intel_crtc);
Lyude896e5bb2016-08-24 07:48:09 +020012653 } else {
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012654 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12655 pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020012656 }
12657
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012658 if (new_plane_state)
12659 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
Lyude896e5bb2016-08-24 07:48:09 +020012660
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012661 intel_begin_crtc_commit(crtc, old_crtc_state);
12662
12663 intel_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc,
12664 old_intel_cstate, pipe_config);
12665
12666 intel_finish_crtc_commit(crtc, old_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012667}
12668
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012669static void intel_update_crtcs(struct drm_atomic_state *state)
Lyude896e5bb2016-08-24 07:48:09 +020012670{
12671 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012672 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyude896e5bb2016-08-24 07:48:09 +020012673 int i;
12674
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012675 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12676 if (!new_crtc_state->active)
Lyude896e5bb2016-08-24 07:48:09 +020012677 continue;
12678
12679 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012680 new_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012681 }
12682}
12683
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012684static void skl_update_crtcs(struct drm_atomic_state *state)
Lyude27082492016-08-24 07:48:10 +020012685{
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020012686 struct drm_i915_private *dev_priv = to_i915(state->dev);
Lyude27082492016-08-24 07:48:10 +020012687 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12688 struct drm_crtc *crtc;
Lyudece0ba282016-09-15 10:46:35 -040012689 struct intel_crtc *intel_crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012690 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyudece0ba282016-09-15 10:46:35 -040012691 struct intel_crtc_state *cstate;
Lyude27082492016-08-24 07:48:10 +020012692 unsigned int updated = 0;
12693 bool progress;
12694 enum pipe pipe;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012695 int i;
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012696 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12697 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012698 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012699
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012700 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012701 /* ignore allocations for crtc's that have been turned off. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012702 if (new_crtc_state->active)
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012703 entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020012704
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012705 /* If 2nd DBuf slice required, enable it here */
12706 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12707 icl_dbuf_slices_update(dev_priv, required_slices);
12708
Lyude27082492016-08-24 07:48:10 +020012709 /*
12710 * Whenever the number of active pipes changes, we need to make sure we
12711 * update the pipes in the right order so that their ddb allocations
12712 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12713 * cause pipe underruns and other bad stuff.
12714 */
12715 do {
Lyude27082492016-08-24 07:48:10 +020012716 progress = false;
12717
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012718 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Lyude27082492016-08-24 07:48:10 +020012719 bool vbl_wait = false;
12720 unsigned int cmask = drm_crtc_mask(crtc);
Lyudece0ba282016-09-15 10:46:35 -040012721
12722 intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä21794812017-08-23 18:22:26 +030012723 cstate = to_intel_crtc_state(new_crtc_state);
Lyudece0ba282016-09-15 10:46:35 -040012724 pipe = intel_crtc->pipe;
Lyude27082492016-08-24 07:48:10 +020012725
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012726 if (updated & cmask || !cstate->base.active)
Lyude27082492016-08-24 07:48:10 +020012727 continue;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012728
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012729 if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb,
Mika Kahola2b685042017-10-10 13:17:03 +030012730 entries,
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012731 INTEL_INFO(dev_priv)->num_pipes, i))
Lyude27082492016-08-24 07:48:10 +020012732 continue;
12733
12734 updated |= cmask;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012735 entries[i] = cstate->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020012736
12737 /*
12738 * If this is an already active pipe, it's DDB changed,
12739 * and this isn't the last pipe that needs updating
12740 * then we need to wait for a vblank to pass for the
12741 * new ddb allocation to take effect.
12742 */
Lyudece0ba282016-09-15 10:46:35 -040012743 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
Maarten Lankhorst512b5522016-11-08 13:55:34 +010012744 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012745 !new_crtc_state->active_changed &&
Lyude27082492016-08-24 07:48:10 +020012746 intel_state->wm_results.dirty_pipes != updated)
12747 vbl_wait = true;
12748
12749 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012750 new_crtc_state);
Lyude27082492016-08-24 07:48:10 +020012751
12752 if (vbl_wait)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020012753 intel_wait_for_vblank(dev_priv, pipe);
Lyude27082492016-08-24 07:48:10 +020012754
12755 progress = true;
12756 }
12757 } while (progress);
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012758
12759 /* If 2nd DBuf slice is no more required disable it */
12760 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12761 icl_dbuf_slices_update(dev_priv, required_slices);
Lyude27082492016-08-24 07:48:10 +020012762}
12763
Chris Wilsonba318c62017-02-02 20:47:41 +000012764static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12765{
12766 struct intel_atomic_state *state, *next;
12767 struct llist_node *freed;
12768
12769 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12770 llist_for_each_entry_safe(state, next, freed, freed)
12771 drm_atomic_state_put(&state->base);
12772}
12773
12774static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12775{
12776 struct drm_i915_private *dev_priv =
12777 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12778
12779 intel_atomic_helper_free_state(dev_priv);
12780}
12781
Daniel Vetter9db529a2017-08-08 10:08:28 +020012782static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12783{
12784 struct wait_queue_entry wait_fence, wait_reset;
12785 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12786
12787 init_wait_entry(&wait_fence, 0);
12788 init_wait_entry(&wait_reset, 0);
12789 for (;;) {
12790 prepare_to_wait(&intel_state->commit_ready.wait,
12791 &wait_fence, TASK_UNINTERRUPTIBLE);
12792 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12793 &wait_reset, TASK_UNINTERRUPTIBLE);
12794
12795
12796 if (i915_sw_fence_done(&intel_state->commit_ready)
12797 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12798 break;
12799
12800 schedule();
12801 }
12802 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12803 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12804}
12805
Chris Wilson8d52e442018-06-23 11:39:51 +010012806static void intel_atomic_cleanup_work(struct work_struct *work)
12807{
12808 struct drm_atomic_state *state =
12809 container_of(work, struct drm_atomic_state, commit_work);
12810 struct drm_i915_private *i915 = to_i915(state->dev);
12811
12812 drm_atomic_helper_cleanup_planes(&i915->drm, state);
12813 drm_atomic_helper_commit_cleanup_done(state);
12814 drm_atomic_state_put(state);
12815
12816 intel_atomic_helper_free_state(i915);
12817}
12818
Daniel Vetter94f05022016-06-14 18:01:00 +020012819static void intel_atomic_commit_tail(struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012820{
Daniel Vetter94f05022016-06-14 18:01:00 +020012821 struct drm_device *dev = state->dev;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012822 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012823 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012824 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012825 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
Maarten Lankhorst7580d772015-08-18 13:40:06 +020012826 struct drm_crtc *crtc;
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012827 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020012828 u64 put_domains[I915_MAX_PIPES] = {};
Chris Wilsone95433c2016-10-28 13:58:27 +010012829 int i;
Daniel Vettera6778b32012-07-02 09:56:42 +020012830
Daniel Vetter9db529a2017-08-08 10:08:28 +020012831 intel_atomic_commit_fence_wait(intel_state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020012832
Daniel Vetterea0000f2016-06-13 16:13:46 +020012833 drm_atomic_helper_wait_for_dependencies(state);
12834
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010012835 if (intel_state->modeset)
Daniel Vetter5a21b662016-05-24 17:13:53 +020012836 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012837
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012838 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012839 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
12840 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
12841 intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012842
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012843 if (needs_modeset(new_crtc_state) ||
12844 to_intel_crtc_state(new_crtc_state)->update_pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020012845
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012846 put_domains[intel_crtc->pipe] =
Daniel Vetter5a21b662016-05-24 17:13:53 +020012847 modeset_get_crtc_power_domains(crtc,
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012848 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012849 }
12850
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012851 if (!needs_modeset(new_crtc_state))
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012852 continue;
12853
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012854 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
Daniel Vetter460da9162013-03-27 00:44:51 +010012855
Ville Syrjälä29ceb0e2016-03-09 19:07:27 +020012856 if (old_crtc_state->active) {
Maarten Lankhorstf59e9702018-09-20 12:27:07 +020012857 intel_crtc_disable_planes(intel_crtc, old_intel_crtc_state->active_planes);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012858
12859 /*
12860 * We need to disable pipe CRC before disabling the pipe,
12861 * or we race against vblank off.
12862 */
12863 intel_crtc_disable_pipe_crc(intel_crtc);
12864
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012865 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020012866 intel_crtc->active = false;
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -020012867 intel_fbc_disable(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +020012868 intel_disable_shared_dpll(old_intel_crtc_state);
Ville Syrjälä9bbc8258a2015-11-20 22:09:20 +020012869
12870 /*
12871 * Underruns don't always raise
12872 * interrupts, so check manually.
12873 */
12874 intel_check_cpu_fifo_underruns(dev_priv);
12875 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorstb9001112015-11-19 16:07:16 +010012876
Ville Syrjäläa748fae2018-10-25 16:05:36 +030012877 /* FIXME unify this for all platforms */
12878 if (!new_crtc_state->active &&
12879 !HAS_GMCH_DISPLAY(dev_priv) &&
12880 dev_priv->display.initial_watermarks)
12881 dev_priv->display.initial_watermarks(intel_state,
12882 new_intel_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012883 }
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010012884 }
Daniel Vetter7758a112012-07-08 19:40:39 +020012885
Daniel Vetter7a1530d72017-12-07 15:32:02 +010012886 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12887 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12888 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +020012889
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012890 if (intel_state->modeset) {
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020012891 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
Maarten Lankhorst33c8df892016-02-10 13:49:37 +010012892
Ville Syrjäläb0587e42017-01-26 21:52:01 +020012893 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
Maarten Lankhorstf6d19732016-03-23 14:58:07 +010012894
Lyude656d1b82016-08-17 15:55:54 -040012895 /*
12896 * SKL workaround: bspec recommends we disable the SAGV when we
12897 * have more then one pipe enabled
12898 */
Paulo Zanoni56feca92016-09-22 18:00:28 -030012899 if (!intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030012900 intel_disable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040012901
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012902 intel_modeset_verify_disabled(dev, state);
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020012903 }
Daniel Vetter47fab732012-10-26 10:58:18 +020012904
Lyude896e5bb2016-08-24 07:48:09 +020012905 /* Complete the events for pipes that have now been disabled */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012906 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12907 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012908
Daniel Vetter1f7528c2016-06-13 16:13:45 +020012909 /* Complete events for now disable pipes here. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012910 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
Daniel Vetter1f7528c2016-06-13 16:13:45 +020012911 spin_lock_irq(&dev->event_lock);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012912 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
Daniel Vetter1f7528c2016-06-13 16:13:45 +020012913 spin_unlock_irq(&dev->event_lock);
12914
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012915 new_crtc_state->event = NULL;
Daniel Vetter1f7528c2016-06-13 16:13:45 +020012916 }
Matt Ropered4a6a72016-02-23 17:20:13 -080012917 }
12918
Lyude896e5bb2016-08-24 07:48:09 +020012919 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012920 dev_priv->display.update_crtcs(state);
Lyude896e5bb2016-08-24 07:48:09 +020012921
Daniel Vetter94f05022016-06-14 18:01:00 +020012922 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12923 * already, but still need the state for the delayed optimization. To
12924 * fix this:
12925 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12926 * - schedule that vblank worker _before_ calling hw_done
12927 * - at the start of commit_tail, cancel it _synchrously
12928 * - switch over to the vblank wait helper in the core after that since
12929 * we don't need out special handling any more.
12930 */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012931 drm_atomic_helper_wait_for_flip_done(dev, state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012932
12933 /*
12934 * Now that the vblank has passed, we can go ahead and program the
12935 * optimal watermarks on platforms that need two-step watermark
12936 * programming.
12937 *
12938 * TODO: Move this (and other cleanup) to an async worker eventually.
12939 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012940 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012941 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012942
12943 if (dev_priv->display.optimize_watermarks)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010012944 dev_priv->display.optimize_watermarks(intel_state,
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012945 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012946 }
12947
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012948 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020012949 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12950
12951 if (put_domains[i])
12952 modeset_put_power_domains(dev_priv, put_domains[i]);
12953
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012954 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012955 }
12956
Ville Syrjäläcff109f2017-11-17 21:19:17 +020012957 if (intel_state->modeset)
12958 intel_verify_planes(intel_state);
12959
Paulo Zanoni56feca92016-09-22 18:00:28 -030012960 if (intel_state->modeset && intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030012961 intel_enable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040012962
Daniel Vetter94f05022016-06-14 18:01:00 +020012963 drm_atomic_helper_commit_hw_done(state);
12964
Chris Wilsond5553c02017-05-04 12:55:08 +010012965 if (intel_state->modeset) {
12966 /* As one of the primary mmio accessors, KMS has a high
12967 * likelihood of triggering bugs in unclaimed access. After we
12968 * finish modesetting, see if an error has been flagged, and if
12969 * so enable debugging for the next modeset - and hope we catch
12970 * the culprit.
12971 */
12972 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012973 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
Chris Wilsond5553c02017-05-04 12:55:08 +010012974 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020012975
Chris Wilson8d52e442018-06-23 11:39:51 +010012976 /*
12977 * Defer the cleanup of the old state to a separate worker to not
12978 * impede the current task (userspace for blocking modesets) that
12979 * are executed inline. For out-of-line asynchronous modesets/flips,
12980 * deferring to a new worker seems overkill, but we would place a
12981 * schedule point (cond_resched()) here anyway to keep latencies
12982 * down.
12983 */
12984 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
Chris Wilson41db6452018-07-12 12:57:29 +010012985 queue_work(system_highpri_wq, &state->commit_work);
Daniel Vetter94f05022016-06-14 18:01:00 +020012986}
12987
12988static void intel_atomic_commit_work(struct work_struct *work)
12989{
Chris Wilsonc004a902016-10-28 13:58:45 +010012990 struct drm_atomic_state *state =
12991 container_of(work, struct drm_atomic_state, commit_work);
12992
Daniel Vetter94f05022016-06-14 18:01:00 +020012993 intel_atomic_commit_tail(state);
12994}
12995
Chris Wilsonc004a902016-10-28 13:58:45 +010012996static int __i915_sw_fence_call
12997intel_atomic_commit_ready(struct i915_sw_fence *fence,
12998 enum i915_sw_fence_notify notify)
12999{
13000 struct intel_atomic_state *state =
13001 container_of(fence, struct intel_atomic_state, commit_ready);
13002
13003 switch (notify) {
13004 case FENCE_COMPLETE:
Daniel Vetter42b062b2017-08-08 10:08:27 +020013005 /* we do blocking waits in the worker, nothing to do here */
Chris Wilsonc004a902016-10-28 13:58:45 +010013006 break;
Chris Wilsonc004a902016-10-28 13:58:45 +010013007 case FENCE_FREE:
Chris Wilsoneb955ee2017-01-23 21:29:39 +000013008 {
13009 struct intel_atomic_helper *helper =
13010 &to_i915(state->base.dev)->atomic_helper;
13011
13012 if (llist_add(&state->freed, &helper->free_list))
13013 schedule_work(&helper->free_work);
13014 break;
13015 }
Chris Wilsonc004a902016-10-28 13:58:45 +010013016 }
13017
13018 return NOTIFY_DONE;
13019}
13020
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013021static void intel_atomic_track_fbs(struct drm_atomic_state *state)
13022{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013023 struct drm_plane_state *old_plane_state, *new_plane_state;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013024 struct drm_plane *plane;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013025 int i;
13026
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013027 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013028 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013029 intel_fb_obj(new_plane_state->fb),
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013030 to_intel_plane(plane)->frontbuffer_bit);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013031}
13032
Daniel Vetter94f05022016-06-14 18:01:00 +020013033/**
13034 * intel_atomic_commit - commit validated state object
13035 * @dev: DRM device
13036 * @state: the top-level driver state object
13037 * @nonblock: nonblocking commit
13038 *
13039 * This function commits a top-level state object that has been validated
13040 * with drm_atomic_helper_check().
13041 *
Daniel Vetter94f05022016-06-14 18:01:00 +020013042 * RETURNS
13043 * Zero for success or -errno.
13044 */
13045static int intel_atomic_commit(struct drm_device *dev,
13046 struct drm_atomic_state *state,
13047 bool nonblock)
13048{
13049 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010013050 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter94f05022016-06-14 18:01:00 +020013051 int ret = 0;
13052
Chris Wilsonc004a902016-10-28 13:58:45 +010013053 drm_atomic_state_get(state);
13054 i915_sw_fence_init(&intel_state->commit_ready,
13055 intel_atomic_commit_ready);
Daniel Vetter94f05022016-06-14 18:01:00 +020013056
Ville Syrjälä440df932017-03-29 17:21:23 +030013057 /*
13058 * The intel_legacy_cursor_update() fast path takes care
13059 * of avoiding the vblank waits for simple cursor
13060 * movement and flips. For cursor on/off and size changes,
13061 * we want to perform the vblank waits so that watermark
13062 * updates happen during the correct frames. Gen9+ have
13063 * double buffered watermarks and so shouldn't need this.
13064 *
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013065 * Unset state->legacy_cursor_update before the call to
13066 * drm_atomic_helper_setup_commit() because otherwise
13067 * drm_atomic_helper_wait_for_flip_done() is a noop and
13068 * we get FIFO underruns because we didn't wait
13069 * for vblank.
Ville Syrjälä440df932017-03-29 17:21:23 +030013070 *
13071 * FIXME doing watermarks and fb cleanup from a vblank worker
13072 * (assuming we had any) would solve these problems.
13073 */
Maarten Lankhorst213f1bd2017-09-19 14:14:19 +020013074 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13075 struct intel_crtc_state *new_crtc_state;
13076 struct intel_crtc *crtc;
13077 int i;
13078
13079 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13080 if (new_crtc_state->wm.need_postvbl_update ||
13081 new_crtc_state->update_wm_post)
13082 state->legacy_cursor_update = false;
13083 }
Ville Syrjälä440df932017-03-29 17:21:23 +030013084
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013085 ret = intel_atomic_prepare_commit(dev, state);
13086 if (ret) {
13087 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13088 i915_sw_fence_commit(&intel_state->commit_ready);
13089 return ret;
13090 }
13091
13092 ret = drm_atomic_helper_setup_commit(state, nonblock);
13093 if (!ret)
13094 ret = drm_atomic_helper_swap_state(state, true);
13095
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013096 if (ret) {
13097 i915_sw_fence_commit(&intel_state->commit_ready);
13098
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013099 drm_atomic_helper_cleanup_planes(dev, state);
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013100 return ret;
13101 }
Daniel Vetter94f05022016-06-14 18:01:00 +020013102 dev_priv->wm.distrust_bios_wm = false;
Ander Conselvan de Oliveira3c0fb582016-12-29 17:22:08 +020013103 intel_shared_dpll_swap_state(state);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013104 intel_atomic_track_fbs(state);
Daniel Vetter94f05022016-06-14 18:01:00 +020013105
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013106 if (intel_state->modeset) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030013107 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13108 sizeof(intel_state->min_cdclk));
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030013109 memcpy(dev_priv->min_voltage_level,
13110 intel_state->min_voltage_level,
13111 sizeof(intel_state->min_voltage_level));
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013112 dev_priv->active_crtcs = intel_state->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020013113 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13114 dev_priv->cdclk.actual = intel_state->cdclk.actual;
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013115 }
13116
Chris Wilson08536952016-10-14 13:18:18 +010013117 drm_atomic_state_get(state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020013118 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
Chris Wilsonc004a902016-10-28 13:58:45 +010013119
13120 i915_sw_fence_commit(&intel_state->commit_ready);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013121 if (nonblock && intel_state->modeset) {
13122 queue_work(dev_priv->modeset_wq, &state->commit_work);
13123 } else if (nonblock) {
Daniel Vetter42b062b2017-08-08 10:08:27 +020013124 queue_work(system_unbound_wq, &state->commit_work);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013125 } else {
13126 if (intel_state->modeset)
13127 flush_workqueue(dev_priv->modeset_wq);
Daniel Vetter94f05022016-06-14 18:01:00 +020013128 intel_atomic_commit_tail(state);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013129 }
Mika Kuoppala75714942015-12-16 09:26:48 +020013130
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013131 return 0;
Daniel Vetterf30da182013-04-11 20:22:50 +020013132}
13133
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013134static const struct drm_crtc_funcs intel_crtc_funcs = {
Daniel Vetter3fab2f02017-04-03 10:32:57 +020013135 .gamma_set = drm_atomic_helper_legacy_gamma_set,
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013136 .set_config = drm_atomic_helper_set_config,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013137 .destroy = intel_crtc_destroy,
Maarten Lankhorst4c01ded2016-12-22 11:33:23 +010013138 .page_flip = drm_atomic_helper_page_flip,
Matt Roper13568372015-01-21 16:35:47 -080013139 .atomic_duplicate_state = intel_crtc_duplicate_state,
13140 .atomic_destroy_state = intel_crtc_destroy_state,
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +010013141 .set_crc_source = intel_crtc_set_crc_source,
Mahesh Kumara8c20832018-07-13 19:29:38 +053013142 .verify_crc_source = intel_crtc_verify_crc_source,
Mahesh Kumar260bc552018-07-13 19:29:39 +053013143 .get_crc_sources = intel_crtc_get_crc_sources,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013144};
13145
Chris Wilson74d290f2017-08-17 13:37:06 +010013146struct wait_rps_boost {
13147 struct wait_queue_entry wait;
13148
13149 struct drm_crtc *crtc;
Chris Wilsone61e0f52018-02-21 09:56:36 +000013150 struct i915_request *request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013151};
13152
13153static int do_rps_boost(struct wait_queue_entry *_wait,
13154 unsigned mode, int sync, void *key)
13155{
13156 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013157 struct i915_request *rq = wait->request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013158
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013159 /*
13160 * If we missed the vblank, but the request is already running it
13161 * is reasonable to assume that it will complete before the next
13162 * vblank without our intervention, so leave RPS alone.
13163 */
Chris Wilsone61e0f52018-02-21 09:56:36 +000013164 if (!i915_request_started(rq))
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013165 gen6_rps_boost(rq, NULL);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013166 i915_request_put(rq);
Chris Wilson74d290f2017-08-17 13:37:06 +010013167
13168 drm_crtc_vblank_put(wait->crtc);
13169
13170 list_del(&wait->wait.entry);
13171 kfree(wait);
13172 return 1;
13173}
13174
13175static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13176 struct dma_fence *fence)
13177{
13178 struct wait_rps_boost *wait;
13179
13180 if (!dma_fence_is_i915(fence))
13181 return;
13182
13183 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13184 return;
13185
13186 if (drm_crtc_vblank_get(crtc))
13187 return;
13188
13189 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13190 if (!wait) {
13191 drm_crtc_vblank_put(crtc);
13192 return;
13193 }
13194
13195 wait->request = to_request(dma_fence_get(fence));
13196 wait->crtc = crtc;
13197
13198 wait->wait.func = do_rps_boost;
13199 wait->wait.flags = 0;
13200
13201 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13202}
13203
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013204static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13205{
13206 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13207 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13208 struct drm_framebuffer *fb = plane_state->base.fb;
13209 struct i915_vma *vma;
13210
13211 if (plane->id == PLANE_CURSOR &&
13212 INTEL_INFO(dev_priv)->cursor_needs_physical) {
13213 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13214 const int align = intel_cursor_alignment(dev_priv);
Chris Wilson4a477652018-08-17 09:24:05 +010013215 int err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013216
Chris Wilson4a477652018-08-17 09:24:05 +010013217 err = i915_gem_object_attach_phys(obj, align);
13218 if (err)
13219 return err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013220 }
13221
13222 vma = intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +030013223 &plane_state->view,
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013224 intel_plane_uses_fence(plane_state),
13225 &plane_state->flags);
13226 if (IS_ERR(vma))
13227 return PTR_ERR(vma);
13228
13229 plane_state->vma = vma;
13230
13231 return 0;
13232}
13233
13234static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13235{
13236 struct i915_vma *vma;
13237
13238 vma = fetch_and_zero(&old_plane_state->vma);
13239 if (vma)
13240 intel_unpin_fb_vma(vma, old_plane_state->flags);
13241}
13242
Chris Wilsonb7268c52018-04-18 19:40:52 +010013243static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13244{
13245 struct i915_sched_attr attr = {
13246 .priority = I915_PRIORITY_DISPLAY,
13247 };
13248
13249 i915_gem_object_wait_priority(obj, 0, &attr);
13250}
13251
Matt Roper6beb8c232014-12-01 15:40:14 -080013252/**
13253 * intel_prepare_plane_fb - Prepare fb for usage on plane
13254 * @plane: drm plane to prepare for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013255 * @new_state: the plane state being prepared
Matt Roper6beb8c232014-12-01 15:40:14 -080013256 *
13257 * Prepares a framebuffer for usage on a display plane. Generally this
13258 * involves pinning the underlying object and updating the frontbuffer tracking
13259 * bits. Some older platforms need special physical address handling for
13260 * cursor planes.
13261 *
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013262 * Must be called with struct_mutex held.
13263 *
Matt Roper6beb8c232014-12-01 15:40:14 -080013264 * Returns 0 on success, negative error code on failure.
13265 */
13266int
13267intel_prepare_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013268 struct drm_plane_state *new_state)
Matt Roper465c1202014-05-29 08:06:54 -070013269{
Chris Wilsonc004a902016-10-28 13:58:45 +010013270 struct intel_atomic_state *intel_state =
13271 to_intel_atomic_state(new_state->state);
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000013272 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Maarten Lankhorst844f9112015-09-02 10:42:40 +020013273 struct drm_framebuffer *fb = new_state->fb;
Matt Roper6beb8c232014-12-01 15:40:14 -080013274 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Maarten Lankhorst1ee49392015-09-23 13:27:08 +020013275 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
Chris Wilsonc004a902016-10-28 13:58:45 +010013276 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013277
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013278 if (old_obj) {
13279 struct drm_crtc_state *crtc_state =
Maarten Lankhorst8b694492018-04-09 14:46:55 +020013280 drm_atomic_get_new_crtc_state(new_state->state,
13281 plane->state->crtc);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013282
13283 /* Big Hammer, we also need to ensure that any pending
13284 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13285 * current scanout is retired before unpinning the old
13286 * framebuffer. Note that we rely on userspace rendering
13287 * into the buffer attached to the pipe they are waiting
13288 * on. If not, userspace generates a GPU hang with IPEHR
13289 * point to the MI_WAIT_FOR_EVENT.
13290 *
13291 * This should only fail upon a hung GPU, in which case we
13292 * can safely continue.
13293 */
Chris Wilsonc004a902016-10-28 13:58:45 +010013294 if (needs_modeset(crtc_state)) {
13295 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13296 old_obj->resv, NULL,
13297 false, 0,
13298 GFP_KERNEL);
13299 if (ret < 0)
13300 return ret;
Chris Wilsonf4457ae2016-04-13 17:35:08 +010013301 }
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013302 }
13303
Chris Wilsonc004a902016-10-28 13:58:45 +010013304 if (new_state->fence) { /* explicit fencing */
13305 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13306 new_state->fence,
13307 I915_FENCE_TIMEOUT,
13308 GFP_KERNEL);
13309 if (ret < 0)
13310 return ret;
13311 }
13312
Chris Wilsonc37efb92016-06-17 08:28:47 +010013313 if (!obj)
13314 return 0;
13315
Chris Wilson4d3088c2017-07-26 17:00:38 +010013316 ret = i915_gem_object_pin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013317 if (ret)
13318 return ret;
13319
Chris Wilson4d3088c2017-07-26 17:00:38 +010013320 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13321 if (ret) {
13322 i915_gem_object_unpin_pages(obj);
13323 return ret;
13324 }
13325
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013326 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
Chris Wilsonfd700752017-07-26 17:00:36 +010013327
Chris Wilsonfd700752017-07-26 17:00:36 +010013328 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson4d3088c2017-07-26 17:00:38 +010013329 i915_gem_object_unpin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013330 if (ret)
13331 return ret;
13332
Chris Wilsone2f34962018-10-01 15:47:54 +010013333 fb_obj_bump_render_priority(obj);
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013334 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13335
Chris Wilsonc004a902016-10-28 13:58:45 +010013336 if (!new_state->fence) { /* implicit fencing */
Chris Wilson74d290f2017-08-17 13:37:06 +010013337 struct dma_fence *fence;
13338
Chris Wilsonc004a902016-10-28 13:58:45 +010013339 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13340 obj->resv, NULL,
13341 false, I915_FENCE_TIMEOUT,
13342 GFP_KERNEL);
13343 if (ret < 0)
13344 return ret;
Chris Wilson74d290f2017-08-17 13:37:06 +010013345
13346 fence = reservation_object_get_excl_rcu(obj->resv);
13347 if (fence) {
13348 add_rps_boost_after_vblank(new_state->crtc, fence);
13349 dma_fence_put(fence);
13350 }
13351 } else {
13352 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
Chris Wilsonc004a902016-10-28 13:58:45 +010013353 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013354
Chris Wilson60548c52018-07-31 14:26:29 +010013355 /*
13356 * We declare pageflips to be interactive and so merit a small bias
13357 * towards upclocking to deliver the frame on time. By only changing
13358 * the RPS thresholds to sample more regularly and aim for higher
13359 * clocks we can hopefully deliver low power workloads (like kodi)
13360 * that are not quite steady state without resorting to forcing
13361 * maximum clocks following a vblank miss (see do_rps_boost()).
13362 */
13363 if (!intel_state->rps_interactive) {
13364 intel_rps_mark_interactive(dev_priv, true);
13365 intel_state->rps_interactive = true;
13366 }
13367
Chris Wilsond07f0e52016-10-28 13:58:44 +010013368 return 0;
Matt Roper6beb8c232014-12-01 15:40:14 -080013369}
13370
Matt Roper38f3ce32014-12-02 07:45:25 -080013371/**
13372 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13373 * @plane: drm plane to clean up for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013374 * @old_state: the state from the previous modeset
Matt Roper38f3ce32014-12-02 07:45:25 -080013375 *
13376 * Cleans up a framebuffer that has just been removed from a plane.
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013377 *
13378 * Must be called with struct_mutex held.
Matt Roper38f3ce32014-12-02 07:45:25 -080013379 */
13380void
13381intel_cleanup_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013382 struct drm_plane_state *old_state)
Matt Roper38f3ce32014-12-02 07:45:25 -080013383{
Chris Wilson60548c52018-07-31 14:26:29 +010013384 struct intel_atomic_state *intel_state =
13385 to_intel_atomic_state(old_state->state);
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013386 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Matt Roper38f3ce32014-12-02 07:45:25 -080013387
Chris Wilson60548c52018-07-31 14:26:29 +010013388 if (intel_state->rps_interactive) {
13389 intel_rps_mark_interactive(dev_priv, false);
13390 intel_state->rps_interactive = false;
13391 }
13392
Chris Wilsonbe1e3412017-01-16 15:21:27 +000013393 /* Should only be called after a successful intel_prepare_plane_fb()! */
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013394 mutex_lock(&dev_priv->drm.struct_mutex);
13395 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13396 mutex_unlock(&dev_priv->drm.struct_mutex);
Matt Roper465c1202014-05-29 08:06:54 -070013397}
13398
Chandra Konduru6156a452015-04-27 13:48:39 -070013399int
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013400skl_max_scale(const struct intel_crtc_state *crtc_state,
13401 u32 pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -070013402{
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013403 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru77224cd2018-04-09 09:11:13 +053013405 int max_scale, mult;
13406 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
Chandra Konduru6156a452015-04-27 13:48:39 -070013407
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013408 if (!crtc_state->base.enable)
Chandra Konduru6156a452015-04-27 13:48:39 -070013409 return DRM_PLANE_HELPER_NO_SCALING;
13410
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013411 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13412 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13413
Rodrigo Vivi43037c82017-10-03 15:31:42 -070013414 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013415 max_dotclk *= 2;
13416
13417 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
Chandra Konduru6156a452015-04-27 13:48:39 -070013418 return DRM_PLANE_HELPER_NO_SCALING;
13419
13420 /*
13421 * skl max scale is lower of:
13422 * close to 3 but not 3, -1 is for that purpose
13423 * or
13424 * cdclk/crtc_clock
13425 */
Chandra Konduru77224cd2018-04-09 09:11:13 +053013426 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13427 tmpclk1 = (1 << 16) * mult - 1;
13428 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13429 max_scale = min(tmpclk1, tmpclk2);
Chandra Konduru6156a452015-04-27 13:48:39 -070013430
13431 return max_scale;
13432}
13433
Daniel Vetter5a21b662016-05-24 17:13:53 +020013434static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13435 struct drm_crtc_state *old_crtc_state)
13436{
13437 struct drm_device *dev = crtc->dev;
Lyude62e0fb82016-08-22 12:50:08 -040013438 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013439 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013440 struct intel_crtc_state *old_intel_cstate =
Daniel Vetter5a21b662016-05-24 17:13:53 +020013441 to_intel_crtc_state(old_crtc_state);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013442 struct intel_atomic_state *old_intel_state =
13443 to_intel_atomic_state(old_crtc_state->state);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013444 struct intel_crtc_state *intel_cstate =
13445 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13446 bool modeset = needs_modeset(&intel_cstate->base);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013447
Maarten Lankhorst567f0792017-02-28 15:28:47 +010013448 if (!modeset &&
13449 (intel_cstate->base.color_mgmt_changed ||
13450 intel_cstate->update_pipe)) {
Ville Syrjälä5c857e62017-08-23 18:22:20 +030013451 intel_color_set_csc(&intel_cstate->base);
13452 intel_color_load_luts(&intel_cstate->base);
Maarten Lankhorst567f0792017-02-28 15:28:47 +010013453 }
13454
Daniel Vetter5a21b662016-05-24 17:13:53 +020013455 /* Perform vblank evasion around commit operation */
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013456 intel_pipe_update_start(intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013457
13458 if (modeset)
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013459 goto out;
Daniel Vetter5a21b662016-05-24 17:13:53 +020013460
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013461 if (intel_cstate->update_pipe)
Ville Syrjälä1a15b772017-08-23 18:22:25 +030013462 intel_update_pipe_config(old_intel_cstate, intel_cstate);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013463 else if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +020013464 skl_detach_scalers(intel_cstate);
Lyude62e0fb82016-08-22 12:50:08 -040013465
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013466out:
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013467 if (dev_priv->display.atomic_update_watermarks)
13468 dev_priv->display.atomic_update_watermarks(old_intel_state,
13469 intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013470}
13471
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013472void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13473 struct intel_crtc_state *crtc_state)
13474{
13475 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13476
13477 if (!IS_GEN2(dev_priv))
13478 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13479
13480 if (crtc_state->has_pch_encoder) {
13481 enum pipe pch_transcoder =
13482 intel_crtc_pch_transcoder(crtc);
13483
13484 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13485 }
13486}
13487
Daniel Vetter5a21b662016-05-24 17:13:53 +020013488static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13489 struct drm_crtc_state *old_crtc_state)
13490{
13491 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013492 struct intel_atomic_state *old_intel_state =
13493 to_intel_atomic_state(old_crtc_state->state);
13494 struct intel_crtc_state *new_crtc_state =
13495 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013496
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013497 intel_pipe_update_end(new_crtc_state);
Maarten Lankhorst33a49862017-11-13 15:40:43 +010013498
13499 if (new_crtc_state->update_pipe &&
13500 !needs_modeset(&new_crtc_state->base) &&
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013501 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13502 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013503}
13504
Matt Ropercf4c7c12014-12-04 10:27:42 -080013505/**
Matt Roper4a3b8762014-12-23 10:41:51 -080013506 * intel_plane_destroy - destroy a plane
13507 * @plane: plane to destroy
Matt Ropercf4c7c12014-12-04 10:27:42 -080013508 *
Matt Roper4a3b8762014-12-23 10:41:51 -080013509 * Common destruction function for all types of planes (primary, cursor,
13510 * sprite).
Matt Ropercf4c7c12014-12-04 10:27:42 -080013511 */
Matt Roper4a3b8762014-12-23 10:41:51 -080013512void intel_plane_destroy(struct drm_plane *plane)
Matt Roper465c1202014-05-29 08:06:54 -070013513{
Matt Roper465c1202014-05-29 08:06:54 -070013514 drm_plane_cleanup(plane);
Ville Syrjälä69ae5612016-05-27 20:59:22 +030013515 kfree(to_intel_plane(plane));
Matt Roper465c1202014-05-29 08:06:54 -070013516}
13517
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013518static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13519 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013520{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013521 switch (modifier) {
13522 case DRM_FORMAT_MOD_LINEAR:
13523 case I915_FORMAT_MOD_X_TILED:
13524 break;
13525 default:
13526 return false;
13527 }
13528
Ben Widawsky714244e2017-08-01 09:58:16 -070013529 switch (format) {
13530 case DRM_FORMAT_C8:
13531 case DRM_FORMAT_RGB565:
13532 case DRM_FORMAT_XRGB1555:
13533 case DRM_FORMAT_XRGB8888:
13534 return modifier == DRM_FORMAT_MOD_LINEAR ||
13535 modifier == I915_FORMAT_MOD_X_TILED;
13536 default:
13537 return false;
13538 }
13539}
13540
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013541static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13542 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013543{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013544 switch (modifier) {
13545 case DRM_FORMAT_MOD_LINEAR:
13546 case I915_FORMAT_MOD_X_TILED:
13547 break;
13548 default:
13549 return false;
13550 }
13551
Ben Widawsky714244e2017-08-01 09:58:16 -070013552 switch (format) {
13553 case DRM_FORMAT_C8:
13554 case DRM_FORMAT_RGB565:
13555 case DRM_FORMAT_XRGB8888:
13556 case DRM_FORMAT_XBGR8888:
13557 case DRM_FORMAT_XRGB2101010:
13558 case DRM_FORMAT_XBGR2101010:
13559 return modifier == DRM_FORMAT_MOD_LINEAR ||
13560 modifier == I915_FORMAT_MOD_X_TILED;
13561 default:
13562 return false;
13563 }
13564}
13565
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013566static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13567 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013568{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013569 return modifier == DRM_FORMAT_MOD_LINEAR &&
13570 format == DRM_FORMAT_ARGB8888;
Ben Widawsky714244e2017-08-01 09:58:16 -070013571}
13572
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013573static const struct drm_plane_funcs i965_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013574 .update_plane = drm_atomic_helper_update_plane,
13575 .disable_plane = drm_atomic_helper_disable_plane,
13576 .destroy = intel_plane_destroy,
13577 .atomic_get_property = intel_plane_atomic_get_property,
13578 .atomic_set_property = intel_plane_atomic_set_property,
13579 .atomic_duplicate_state = intel_plane_duplicate_state,
13580 .atomic_destroy_state = intel_plane_destroy_state,
13581 .format_mod_supported = i965_plane_format_mod_supported,
13582};
13583
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013584static const struct drm_plane_funcs i8xx_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013585 .update_plane = drm_atomic_helper_update_plane,
13586 .disable_plane = drm_atomic_helper_disable_plane,
13587 .destroy = intel_plane_destroy,
13588 .atomic_get_property = intel_plane_atomic_get_property,
13589 .atomic_set_property = intel_plane_atomic_set_property,
13590 .atomic_duplicate_state = intel_plane_duplicate_state,
13591 .atomic_destroy_state = intel_plane_destroy_state,
13592 .format_mod_supported = i8xx_plane_format_mod_supported,
Matt Roper465c1202014-05-29 08:06:54 -070013593};
13594
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013595static int
13596intel_legacy_cursor_update(struct drm_plane *plane,
13597 struct drm_crtc *crtc,
13598 struct drm_framebuffer *fb,
13599 int crtc_x, int crtc_y,
13600 unsigned int crtc_w, unsigned int crtc_h,
13601 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013602 uint32_t src_w, uint32_t src_h,
13603 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013604{
13605 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13606 int ret;
13607 struct drm_plane_state *old_plane_state, *new_plane_state;
13608 struct intel_plane *intel_plane = to_intel_plane(plane);
13609 struct drm_framebuffer *old_fb;
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013610 struct intel_crtc_state *crtc_state =
13611 to_intel_crtc_state(crtc->state);
13612 struct intel_crtc_state *new_crtc_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013613
13614 /*
13615 * When crtc is inactive or there is a modeset pending,
13616 * wait for it to complete in the slowpath
13617 */
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013618 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
13619 crtc_state->update_pipe)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013620 goto slow;
13621
13622 old_plane_state = plane->state;
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013623 /*
13624 * Don't do an async update if there is an outstanding commit modifying
13625 * the plane. This prevents our async update's changes from getting
13626 * overridden by a previous synchronous update's state.
13627 */
13628 if (old_plane_state->commit &&
13629 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13630 goto slow;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013631
13632 /*
13633 * If any parameters change that may affect watermarks,
13634 * take the slowpath. Only changing fb or position should be
13635 * in the fastpath.
13636 */
13637 if (old_plane_state->crtc != crtc ||
13638 old_plane_state->src_w != src_w ||
13639 old_plane_state->src_h != src_h ||
13640 old_plane_state->crtc_w != crtc_w ||
13641 old_plane_state->crtc_h != crtc_h ||
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013642 !old_plane_state->fb != !fb)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013643 goto slow;
13644
13645 new_plane_state = intel_plane_duplicate_state(plane);
13646 if (!new_plane_state)
13647 return -ENOMEM;
13648
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013649 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
13650 if (!new_crtc_state) {
13651 ret = -ENOMEM;
13652 goto out_free;
13653 }
13654
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013655 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13656
13657 new_plane_state->src_x = src_x;
13658 new_plane_state->src_y = src_y;
13659 new_plane_state->src_w = src_w;
13660 new_plane_state->src_h = src_h;
13661 new_plane_state->crtc_x = crtc_x;
13662 new_plane_state->crtc_y = crtc_y;
13663 new_plane_state->crtc_w = crtc_w;
13664 new_plane_state->crtc_h = crtc_h;
13665
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013666 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
13667 to_intel_plane_state(old_plane_state),
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013668 to_intel_plane_state(new_plane_state));
13669 if (ret)
13670 goto out_free;
13671
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013672 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13673 if (ret)
13674 goto out_free;
13675
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013676 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13677 if (ret)
13678 goto out_unlock;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013679
Dhinakaran Pandiyana694e222018-03-06 19:34:19 -080013680 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013681
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013682 old_fb = old_plane_state->fb;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013683 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13684 intel_plane->frontbuffer_bit);
13685
13686 /* Swap plane state */
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013687 plane->state = new_plane_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013688
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013689 /*
13690 * We cannot swap crtc_state as it may be in use by an atomic commit or
13691 * page flip that's running simultaneously. If we swap crtc_state and
13692 * destroy the old state, we will cause a use-after-free there.
13693 *
13694 * Only update active_planes, which is needed for our internal
13695 * bookkeeping. Either value will do the right thing when updating
13696 * planes atomically. If the cursor was part of the atomic update then
13697 * we would have taken the slowpath.
13698 */
13699 crtc_state->active_planes = new_crtc_state->active_planes;
13700
Ville Syrjälä72259532017-03-02 19:15:05 +020013701 if (plane->state->visible) {
13702 trace_intel_update_plane(plane, to_intel_crtc(crtc));
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013703 intel_plane->update_plane(intel_plane, crtc_state,
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013704 to_intel_plane_state(plane->state));
Ville Syrjälä72259532017-03-02 19:15:05 +020013705 } else {
13706 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
Ville Syrjälä282dbf92017-03-27 21:55:33 +030013707 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
Ville Syrjälä72259532017-03-02 19:15:05 +020013708 }
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013709
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013710 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013711
13712out_unlock:
13713 mutex_unlock(&dev_priv->drm.struct_mutex);
13714out_free:
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013715 if (new_crtc_state)
13716 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013717 if (ret)
13718 intel_plane_destroy_state(plane, new_plane_state);
13719 else
13720 intel_plane_destroy_state(plane, old_plane_state);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013721 return ret;
13722
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013723slow:
13724 return drm_atomic_helper_update_plane(plane, crtc, fb,
13725 crtc_x, crtc_y, crtc_w, crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013726 src_x, src_y, src_w, src_h, ctx);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013727}
13728
13729static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13730 .update_plane = intel_legacy_cursor_update,
13731 .disable_plane = drm_atomic_helper_disable_plane,
13732 .destroy = intel_plane_destroy,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013733 .atomic_get_property = intel_plane_atomic_get_property,
13734 .atomic_set_property = intel_plane_atomic_set_property,
13735 .atomic_duplicate_state = intel_plane_duplicate_state,
13736 .atomic_destroy_state = intel_plane_destroy_state,
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013737 .format_mod_supported = intel_cursor_format_mod_supported,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013738};
13739
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013740static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13741 enum i9xx_plane_id i9xx_plane)
13742{
13743 if (!HAS_FBC(dev_priv))
13744 return false;
13745
13746 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13747 return i9xx_plane == PLANE_A; /* tied to pipe A */
13748 else if (IS_IVYBRIDGE(dev_priv))
13749 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13750 i9xx_plane == PLANE_C;
13751 else if (INTEL_GEN(dev_priv) >= 4)
13752 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13753 else
13754 return i9xx_plane == PLANE_A;
13755}
13756
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013757static struct intel_plane *
Ville Syrjälä580503c2016-10-31 22:37:00 +020013758intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
Matt Roper465c1202014-05-29 08:06:54 -070013759{
Ville Syrjälä881440a2018-10-05 15:58:17 +030013760 struct intel_plane *plane;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013761 const struct drm_plane_funcs *plane_funcs;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013762 unsigned int supported_rotations;
Ville Syrjälädeb19682018-10-05 15:58:08 +030013763 unsigned int possible_crtcs;
Ville Syrjälä881440a2018-10-05 15:58:17 +030013764 const u64 *modifiers;
13765 const u32 *formats;
13766 int num_formats;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013767 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013768
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013769 if (INTEL_GEN(dev_priv) >= 9)
13770 return skl_universal_plane_create(dev_priv, pipe,
13771 PLANE_PRIMARY);
13772
Ville Syrjälä881440a2018-10-05 15:58:17 +030013773 plane = intel_plane_alloc();
13774 if (IS_ERR(plane))
13775 return plane;
Matt Roperea2c67b2014-12-23 10:41:52 -080013776
Ville Syrjälä881440a2018-10-05 15:58:17 +030013777 plane->pipe = pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020013778 /*
13779 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13780 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13781 */
13782 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030013783 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020013784 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030013785 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
13786 plane->id = PLANE_PRIMARY;
13787 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013788
Ville Syrjälä881440a2018-10-05 15:58:17 +030013789 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
13790 if (plane->has_fbc) {
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013791 struct intel_fbc *fbc = &dev_priv->fbc;
13792
Ville Syrjälä881440a2018-10-05 15:58:17 +030013793 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013794 }
13795
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013796 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä881440a2018-10-05 15:58:17 +030013797 formats = i965_primary_formats;
Damien Lespiau568db4f2015-05-12 16:13:18 +010013798 num_formats = ARRAY_SIZE(i965_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070013799 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010013800
Ville Syrjälä881440a2018-10-05 15:58:17 +030013801 plane->max_stride = i9xx_plane_max_stride;
13802 plane->update_plane = i9xx_update_plane;
13803 plane->disable_plane = i9xx_disable_plane;
13804 plane->get_hw_state = i9xx_plane_get_hw_state;
13805 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013806
13807 plane_funcs = &i965_plane_funcs;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010013808 } else {
Ville Syrjälä881440a2018-10-05 15:58:17 +030013809 formats = i8xx_primary_formats;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010013810 num_formats = ARRAY_SIZE(i8xx_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070013811 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010013812
Ville Syrjälä881440a2018-10-05 15:58:17 +030013813 plane->max_stride = i9xx_plane_max_stride;
13814 plane->update_plane = i9xx_update_plane;
13815 plane->disable_plane = i9xx_disable_plane;
13816 plane->get_hw_state = i9xx_plane_get_hw_state;
13817 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013818
13819 plane_funcs = &i8xx_plane_funcs;
Matt Roper465c1202014-05-29 08:06:54 -070013820 }
13821
Ville Syrjälädeb19682018-10-05 15:58:08 +030013822 possible_crtcs = BIT(pipe);
13823
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013824 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Ville Syrjälä881440a2018-10-05 15:58:17 +030013825 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013826 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030013827 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013828 DRM_PLANE_TYPE_PRIMARY,
13829 "primary %c", pipe_name(pipe));
13830 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030013831 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013832 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030013833 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013834 DRM_PLANE_TYPE_PRIMARY,
Ville Syrjäläed150302017-11-17 21:19:10 +020013835 "plane %c",
Ville Syrjälä881440a2018-10-05 15:58:17 +030013836 plane_name(plane->i9xx_plane));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013837 if (ret)
13838 goto fail;
Sonika Jindal48404c12014-08-22 14:06:04 +053013839
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013840 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjälä4ea7be22016-11-14 18:54:00 +020013841 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040013842 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13843 DRM_MODE_REFLECT_X;
Dave Airlie5481e272016-10-25 16:36:13 +100013844 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013845 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040013846 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013847 } else {
Robert Fossc2c446a2017-05-19 16:50:17 -040013848 supported_rotations = DRM_MODE_ROTATE_0;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013849 }
13850
Dave Airlie5481e272016-10-25 16:36:13 +100013851 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030013852 drm_plane_create_rotation_property(&plane->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040013853 DRM_MODE_ROTATE_0,
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013854 supported_rotations);
Sonika Jindal48404c12014-08-22 14:06:04 +053013855
Ville Syrjälä881440a2018-10-05 15:58:17 +030013856 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
Matt Roperea2c67b2014-12-23 10:41:52 -080013857
Ville Syrjälä881440a2018-10-05 15:58:17 +030013858 return plane;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013859
13860fail:
Ville Syrjälä881440a2018-10-05 15:58:17 +030013861 intel_plane_free(plane);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013862
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013863 return ERR_PTR(ret);
Matt Roper465c1202014-05-29 08:06:54 -070013864}
13865
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013866static struct intel_plane *
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013867intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13868 enum pipe pipe)
Matt Roper3d7d6512014-06-10 08:28:13 -070013869{
Ville Syrjälädeb19682018-10-05 15:58:08 +030013870 unsigned int possible_crtcs;
Ville Syrjäläc539b572018-10-05 15:58:14 +030013871 struct intel_plane *cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013872 int ret;
Matt Roper3d7d6512014-06-10 08:28:13 -070013873
Ville Syrjäläc539b572018-10-05 15:58:14 +030013874 cursor = intel_plane_alloc();
13875 if (IS_ERR(cursor))
13876 return cursor;
Matt Roperea2c67b2014-12-23 10:41:52 -080013877
Matt Roper3d7d6512014-06-10 08:28:13 -070013878 cursor->pipe = pipe;
Ville Syrjäläed150302017-11-17 21:19:10 +020013879 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
Ville Syrjäläb14e5842016-11-22 18:01:56 +020013880 cursor->id = PLANE_CURSOR;
Ville Syrjäläc19e1122018-01-23 20:33:43 +020013881 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013882
13883 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
Ville Syrjäläddd57132018-09-07 18:24:02 +030013884 cursor->max_stride = i845_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013885 cursor->update_plane = i845_update_cursor;
13886 cursor->disable_plane = i845_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020013887 cursor->get_hw_state = i845_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030013888 cursor->check_plane = i845_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013889 } else {
Ville Syrjäläddd57132018-09-07 18:24:02 +030013890 cursor->max_stride = i9xx_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013891 cursor->update_plane = i9xx_update_cursor;
13892 cursor->disable_plane = i9xx_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020013893 cursor->get_hw_state = i9xx_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030013894 cursor->check_plane = i9xx_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013895 }
Matt Roper3d7d6512014-06-10 08:28:13 -070013896
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030013897 cursor->cursor.base = ~0;
13898 cursor->cursor.cntl = ~0;
Ville Syrjälä024faac2017-03-27 21:55:42 +030013899
13900 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13901 cursor->cursor.size = ~0;
Matt Roper3d7d6512014-06-10 08:28:13 -070013902
Ville Syrjälädeb19682018-10-05 15:58:08 +030013903 possible_crtcs = BIT(pipe);
13904
Ville Syrjälä580503c2016-10-31 22:37:00 +020013905 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013906 possible_crtcs, &intel_cursor_plane_funcs,
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013907 intel_cursor_formats,
13908 ARRAY_SIZE(intel_cursor_formats),
Ben Widawsky714244e2017-08-01 09:58:16 -070013909 cursor_format_modifiers,
13910 DRM_PLANE_TYPE_CURSOR,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013911 "cursor %c", pipe_name(pipe));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013912 if (ret)
13913 goto fail;
Ville Syrjälä4398ad42014-10-23 07:41:34 -070013914
Dave Airlie5481e272016-10-25 16:36:13 +100013915 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013916 drm_plane_create_rotation_property(&cursor->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040013917 DRM_MODE_ROTATE_0,
13918 DRM_MODE_ROTATE_0 |
13919 DRM_MODE_ROTATE_180);
Ville Syrjälä4398ad42014-10-23 07:41:34 -070013920
Matt Roperea2c67b2014-12-23 10:41:52 -080013921 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13922
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013923 return cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013924
13925fail:
Ville Syrjäläc539b572018-10-05 15:58:14 +030013926 intel_plane_free(cursor);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013927
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013928 return ERR_PTR(ret);
Matt Roper3d7d6512014-06-10 08:28:13 -070013929}
13930
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053013931static void intel_crtc_init_scalers(struct intel_crtc *crtc,
13932 struct intel_crtc_state *crtc_state)
Chandra Konduru549e2bf2015-04-07 15:28:38 -070013933{
Ville Syrjälä65edccc2016-10-31 22:37:01 +020013934 struct intel_crtc_scaler_state *scaler_state =
13935 &crtc_state->scaler_state;
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053013936 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru549e2bf2015-04-07 15:28:38 -070013937 int i;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070013938
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053013939 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
13940 if (!crtc->num_scalers)
13941 return;
13942
Ville Syrjälä65edccc2016-10-31 22:37:01 +020013943 for (i = 0; i < crtc->num_scalers; i++) {
13944 struct intel_scaler *scaler = &scaler_state->scalers[i];
13945
13946 scaler->in_use = 0;
Maarten Lankhorst0aaf29b2018-09-21 16:44:37 +020013947 scaler->mode = 0;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070013948 }
13949
13950 scaler_state->scaler_id = -1;
13951}
13952
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020013953static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnes79e53942008-11-07 14:24:08 -080013954{
13955 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013956 struct intel_crtc_state *crtc_state = NULL;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013957 struct intel_plane *primary = NULL;
13958 struct intel_plane *cursor = NULL;
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030013959 int sprite, ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080013960
Daniel Vetter955382f2013-09-19 14:05:45 +020013961 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013962 if (!intel_crtc)
13963 return -ENOMEM;
Jesse Barnes79e53942008-11-07 14:24:08 -080013964
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013965 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013966 if (!crtc_state) {
13967 ret = -ENOMEM;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013968 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013969 }
Ander Conselvan de Oliveira550acef2015-04-21 17:13:24 +030013970 intel_crtc->config = crtc_state;
13971 intel_crtc->base.state = &crtc_state->base;
Matt Roper07878242015-02-25 11:43:26 -080013972 crtc_state->base.crtc = &intel_crtc->base;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020013973
Ville Syrjälä580503c2016-10-31 22:37:00 +020013974 primary = intel_primary_plane_create(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013975 if (IS_ERR(primary)) {
13976 ret = PTR_ERR(primary);
Matt Roper3d7d6512014-06-10 08:28:13 -070013977 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013978 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020013979 intel_crtc->plane_ids_mask |= BIT(primary->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070013980
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030013981 for_each_sprite(dev_priv, pipe, sprite) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013982 struct intel_plane *plane;
13983
Ville Syrjälä580503c2016-10-31 22:37:00 +020013984 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020013985 if (IS_ERR(plane)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013986 ret = PTR_ERR(plane);
13987 goto fail;
13988 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020013989 intel_crtc->plane_ids_mask |= BIT(plane->id);
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030013990 }
13991
Ville Syrjälä580503c2016-10-31 22:37:00 +020013992 cursor = intel_cursor_plane_create(dev_priv, pipe);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020013993 if (IS_ERR(cursor)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013994 ret = PTR_ERR(cursor);
Matt Roper3d7d6512014-06-10 08:28:13 -070013995 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013996 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020013997 intel_crtc->plane_ids_mask |= BIT(cursor->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070013998
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020013999 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014000 &primary->base, &cursor->base,
14001 &intel_crtc_funcs,
Ville Syrjälä4d5d72b72016-05-27 20:59:21 +030014002 "pipe %c", pipe_name(pipe));
Matt Roper3d7d6512014-06-10 08:28:13 -070014003 if (ret)
14004 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080014005
Jesse Barnes80824002009-09-10 15:28:06 -070014006 intel_crtc->pipe = pipe;
Jesse Barnes80824002009-09-10 15:28:06 -070014007
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014008 /* initialize shared scalers */
14009 intel_crtc_init_scalers(intel_crtc, crtc_state);
14010
Ville Syrjälä1947fd12018-03-05 19:41:22 +020014011 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14012 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14013 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14014
14015 if (INTEL_GEN(dev_priv) < 9) {
14016 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14017
14018 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14019 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14020 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14021 }
Jesse Barnes22fd0fa2009-12-02 13:42:53 -080014022
Jesse Barnes79e53942008-11-07 14:24:08 -080014023 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
Daniel Vetter87b6b102014-05-15 15:33:46 +020014024
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +000014025 intel_color_init(&intel_crtc->base);
14026
Daniel Vetter87b6b102014-05-15 15:33:46 +020014027 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014028
14029 return 0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014030
14031fail:
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014032 /*
14033 * drm_mode_config_cleanup() will free up any
14034 * crtcs/planes already initialized.
14035 */
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014036 kfree(crtc_state);
Matt Roper3d7d6512014-06-10 08:28:13 -070014037 kfree(intel_crtc);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014038
14039 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014040}
14041
Ville Syrjälä6a20fe72018-02-07 18:48:41 +020014042int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14043 struct drm_file *file)
Carl Worth08d7b3d2009-04-29 14:43:54 -070014044{
Carl Worth08d7b3d2009-04-29 14:43:54 -070014045 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
Rob Clark7707e652014-07-17 23:30:04 -040014046 struct drm_crtc *drmmode_crtc;
Daniel Vetterc05422d2009-08-11 16:05:30 +020014047 struct intel_crtc *crtc;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014048
Keith Packard418da172017-03-14 23:25:07 -070014049 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
Chris Wilson71240ed2016-06-24 14:00:24 +010014050 if (!drmmode_crtc)
Ville Syrjälä3f2c2052013-10-17 13:35:03 +030014051 return -ENOENT;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014052
Rob Clark7707e652014-07-17 23:30:04 -040014053 crtc = to_intel_crtc(drmmode_crtc);
Daniel Vetterc05422d2009-08-11 16:05:30 +020014054 pipe_from_crtc_id->pipe = crtc->pipe;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014055
Daniel Vetterc05422d2009-08-11 16:05:30 +020014056 return 0;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014057}
14058
Daniel Vetter66a92782012-07-12 20:08:18 +020014059static int intel_encoder_clones(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080014060{
Daniel Vetter66a92782012-07-12 20:08:18 +020014061 struct drm_device *dev = encoder->base.dev;
14062 struct intel_encoder *source_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -080014063 int index_mask = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080014064 int entry = 0;
14065
Damien Lespiaub2784e12014-08-05 11:29:37 +010014066 for_each_intel_encoder(dev, source_encoder) {
Ville Syrjäläbc079e82014-03-03 16:15:28 +020014067 if (encoders_cloneable(encoder, source_encoder))
Daniel Vetter66a92782012-07-12 20:08:18 +020014068 index_mask |= (1 << entry);
14069
Jesse Barnes79e53942008-11-07 14:24:08 -080014070 entry++;
14071 }
Chris Wilson4ef69c72010-09-09 15:14:28 +010014072
Jesse Barnes79e53942008-11-07 14:24:08 -080014073 return index_mask;
14074}
14075
Ville Syrjälä646d5772016-10-31 22:37:14 +020014076static bool has_edp_a(struct drm_i915_private *dev_priv)
Chris Wilson4d302442010-12-14 19:21:29 +000014077{
Ville Syrjälä646d5772016-10-31 22:37:14 +020014078 if (!IS_MOBILE(dev_priv))
Chris Wilson4d302442010-12-14 19:21:29 +000014079 return false;
14080
14081 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14082 return false;
14083
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010014084 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
Chris Wilson4d302442010-12-14 19:21:29 +000014085 return false;
14086
14087 return true;
14088}
14089
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014090static bool intel_crt_present(struct drm_i915_private *dev_priv)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014091{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014092 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau884497e2013-12-03 13:56:23 +000014093 return false;
14094
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010014095 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014096 return false;
14097
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014098 if (IS_CHERRYVIEW(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014099 return false;
14100
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014101 if (HAS_PCH_LPT_H(dev_priv) &&
14102 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
Ville Syrjälä65e472e2015-12-01 23:28:55 +020014103 return false;
14104
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014105 /* DDI E can't be used if DDI A requires 4 lanes */
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014106 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 +020014107 return false;
14108
Ville Syrjäläe4abb732015-12-01 23:31:33 +020014109 if (!dev_priv->vbt.int_crt_support)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014110 return false;
14111
14112 return true;
14113}
14114
Imre Deak8090ba82016-08-10 14:07:33 +030014115void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14116{
14117 int pps_num;
14118 int pps_idx;
14119
14120 if (HAS_DDI(dev_priv))
14121 return;
14122 /*
14123 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14124 * everywhere where registers can be write protected.
14125 */
14126 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14127 pps_num = 2;
14128 else
14129 pps_num = 1;
14130
14131 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14132 u32 val = I915_READ(PP_CONTROL(pps_idx));
14133
14134 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14135 I915_WRITE(PP_CONTROL(pps_idx), val);
14136 }
14137}
14138
Imre Deak44cb7342016-08-10 14:07:29 +030014139static void intel_pps_init(struct drm_i915_private *dev_priv)
14140{
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +020014141 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +030014142 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14143 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14144 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14145 else
14146 dev_priv->pps_mmio_base = PPS_BASE;
Imre Deak8090ba82016-08-10 14:07:33 +030014147
14148 intel_pps_unlock_regs_wa(dev_priv);
Imre Deak44cb7342016-08-10 14:07:29 +030014149}
14150
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014151static void intel_setup_outputs(struct drm_i915_private *dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -080014152{
Chris Wilson4ef69c72010-09-09 15:14:28 +010014153 struct intel_encoder *encoder;
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014154 bool dpd_is_edp = false;
Jesse Barnes79e53942008-11-07 14:24:08 -080014155
Imre Deak44cb7342016-08-10 14:07:29 +030014156 intel_pps_init(dev_priv);
14157
Chris Wilsonfc0c5a92018-08-15 21:12:07 +010014158 if (INTEL_INFO(dev_priv)->num_pipes == 0)
14159 return;
14160
Imre Deak97a824e12016-06-21 11:51:47 +030014161 /*
14162 * intel_edp_init_connector() depends on this completing first, to
14163 * prevent the registeration of both eDP and LVDS and the incorrect
14164 * sharing of the PPS.
14165 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014166 intel_lvds_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014167
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014168 if (intel_crt_present(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014169 intel_crt_init(dev_priv);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014170
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014171 if (IS_ICELAKE(dev_priv)) {
14172 intel_ddi_init(dev_priv, PORT_A);
14173 intel_ddi_init(dev_priv, PORT_B);
14174 intel_ddi_init(dev_priv, PORT_C);
14175 intel_ddi_init(dev_priv, PORT_D);
14176 intel_ddi_init(dev_priv, PORT_E);
14177 intel_ddi_init(dev_priv, PORT_F);
Madhav Chauhanbf4d57f2018-10-30 13:56:23 +020014178 icl_dsi_init(dev_priv);
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014179 } else if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanc776eb22014-08-19 12:05:01 +053014180 /*
14181 * FIXME: Broxton doesn't support port detection via the
14182 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14183 * detect the ports.
14184 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014185 intel_ddi_init(dev_priv, PORT_A);
14186 intel_ddi_init(dev_priv, PORT_B);
14187 intel_ddi_init(dev_priv, PORT_C);
Shashank Sharmac6c794a2016-03-22 12:01:50 +020014188
Jani Nikulae5186342018-07-05 16:25:08 +030014189 vlv_dsi_init(dev_priv);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014190 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014191 int found;
14192
Jesse Barnesde31fac2015-03-06 15:53:32 -080014193 /*
14194 * Haswell uses DDI functions to detect digital outputs.
14195 * On SKL pre-D0 the strap isn't connected, so we assume
14196 * it's there.
14197 */
Ville Syrjälä77179402015-09-18 20:03:35 +030014198 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
Jesse Barnesde31fac2015-03-06 15:53:32 -080014199 /* WaIgnoreDDIAStrap: skl */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014200 if (found || IS_GEN9_BC(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014201 intel_ddi_init(dev_priv, PORT_A);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014202
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014203 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014204 * register */
14205 found = I915_READ(SFUSE_STRAP);
14206
14207 if (found & SFUSE_STRAP_DDIB_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014208 intel_ddi_init(dev_priv, PORT_B);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014209 if (found & SFUSE_STRAP_DDIC_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014210 intel_ddi_init(dev_priv, PORT_C);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014211 if (found & SFUSE_STRAP_DDID_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014212 intel_ddi_init(dev_priv, PORT_D);
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014213 if (found & SFUSE_STRAP_DDIF_DETECTED)
14214 intel_ddi_init(dev_priv, PORT_F);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014215 /*
14216 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14217 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014218 if (IS_GEN9_BC(dev_priv) &&
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014219 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14220 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14221 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014222 intel_ddi_init(dev_priv, PORT_E);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014223
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010014224 } else if (HAS_PCH_SPLIT(dev_priv)) {
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014225 int found;
Jani Nikula7b91bf72017-08-18 12:30:19 +030014226 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
Daniel Vetter270b3042012-10-27 15:52:05 +020014227
Ville Syrjälä646d5772016-10-31 22:37:14 +020014228 if (has_edp_a(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014229 intel_dp_init(dev_priv, DP_A, PORT_A);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014230
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014231 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
Zhao Yakui461ed3c2010-03-30 15:11:33 +080014232 /* PCH SDVOB multiplex with HDMIB */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014233 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014234 if (!found)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014235 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014236 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014237 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014238 }
14239
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014240 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014241 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014242
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014243 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014244 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014245
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014246 if (I915_READ(PCH_DP_C) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014247 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014248
Daniel Vetter270b3042012-10-27 15:52:05 +020014249 if (I915_READ(PCH_DP_D) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014250 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014251 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014252 bool has_edp, has_port;
Chris Wilson457c52d2016-06-01 08:27:50 +010014253
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014254 /*
14255 * The DP_DETECTED bit is the latched state of the DDC
14256 * SDA pin at boot. However since eDP doesn't require DDC
14257 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14258 * eDP ports may have been muxed to an alternate function.
14259 * Thus we can't rely on the DP_DETECTED bit alone to detect
14260 * eDP ports. Consult the VBT as well as DP_DETECTED to
14261 * detect eDP ports.
Ville Syrjälä22f350422016-06-03 12:17:43 +030014262 *
14263 * Sadly the straps seem to be missing sometimes even for HDMI
14264 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14265 * and VBT for the presence of the port. Additionally we can't
14266 * trust the port type the VBT declares as we've seen at least
14267 * HDMI ports that the VBT claim are DP or eDP.
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014268 */
Jani Nikula7b91bf72017-08-18 12:30:19 +030014269 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014270 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14271 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014272 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014273 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014274 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
Artem Bityutskiy585a94b2013-10-16 18:10:41 +030014275
Jani Nikula7b91bf72017-08-18 12:30:19 +030014276 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014277 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14278 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014279 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014280 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014281 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
Gajanan Bhat19c03922012-09-27 19:13:07 +053014282
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014283 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014284 /*
14285 * eDP not supported on port D,
14286 * so no need to worry about it
14287 */
14288 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14289 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014290 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014291 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014292 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
Ville Syrjälä9418c1f2014-04-09 13:28:56 +030014293 }
14294
Jani Nikulae5186342018-07-05 16:25:08 +030014295 vlv_dsi_init(dev_priv);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010014296 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014297 bool found = false;
Eric Anholt7d573822009-01-02 13:33:00 -080014298
Paulo Zanonie2debe92013-02-18 19:00:27 -030014299 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014300 DRM_DEBUG_KMS("probing SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014301 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014302 if (!found && IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014303 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014304 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014305 }
Ma Ling27185ae2009-08-24 13:50:23 +080014306
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014307 if (!found && IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014308 intel_dp_init(dev_priv, DP_B, PORT_B);
Eric Anholt725e30a2009-01-22 13:01:02 -080014309 }
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014310
14311 /* Before G4X SDVOC doesn't have its own detect register */
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014312
Paulo Zanonie2debe92013-02-18 19:00:27 -030014313 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014314 DRM_DEBUG_KMS("probing SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014315 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014316 }
Ma Ling27185ae2009-08-24 13:50:23 +080014317
Paulo Zanonie2debe92013-02-18 19:00:27 -030014318 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014319
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014320 if (IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014321 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014322 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014323 }
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014324 if (IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014325 intel_dp_init(dev_priv, DP_C, PORT_C);
Eric Anholt725e30a2009-01-22 13:01:02 -080014326 }
Ma Ling27185ae2009-08-24 13:50:23 +080014327
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014328 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014329 intel_dp_init(dev_priv, DP_D, PORT_D);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010014330 } else if (IS_GEN2(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014331 intel_dvo_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014332
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +000014333 if (SUPPORTS_TV(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014334 intel_tv_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014335
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014336 intel_psr_init(dev_priv);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -070014337
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014338 for_each_intel_encoder(&dev_priv->drm, encoder) {
Chris Wilson4ef69c72010-09-09 15:14:28 +010014339 encoder->base.possible_crtcs = encoder->crtc_mask;
14340 encoder->base.possible_clones =
Daniel Vetter66a92782012-07-12 20:08:18 +020014341 intel_encoder_clones(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -080014342 }
Chris Wilson47356eb2011-01-11 17:06:04 +000014343
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014344 intel_init_pch_refclk(dev_priv);
Daniel Vetter270b3042012-10-27 15:52:05 +020014345
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014346 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
Jesse Barnes79e53942008-11-07 14:24:08 -080014347}
14348
14349static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14350{
14351 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014352 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014353
Daniel Vetteref2d6332014-02-10 18:00:38 +010014354 drm_framebuffer_cleanup(fb);
Chris Wilson70001cd2017-02-16 09:46:21 +000014355
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014356 i915_gem_object_lock(obj);
14357 WARN_ON(!obj->framebuffer_references--);
14358 i915_gem_object_unlock(obj);
Chris Wilsondd689282017-03-01 15:41:28 +000014359
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014360 i915_gem_object_put(obj);
Chris Wilson70001cd2017-02-16 09:46:21 +000014361
Jesse Barnes79e53942008-11-07 14:24:08 -080014362 kfree(intel_fb);
14363}
14364
14365static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
Chris Wilson05394f32010-11-08 19:18:58 +000014366 struct drm_file *file,
Jesse Barnes79e53942008-11-07 14:24:08 -080014367 unsigned int *handle)
14368{
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014369 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014370
Chris Wilsoncc917ab2015-10-13 14:22:26 +010014371 if (obj->userptr.mm) {
14372 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14373 return -EINVAL;
14374 }
14375
Chris Wilson05394f32010-11-08 19:18:58 +000014376 return drm_gem_handle_create(file, &obj->base, handle);
Jesse Barnes79e53942008-11-07 14:24:08 -080014377}
14378
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014379static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14380 struct drm_file *file,
14381 unsigned flags, unsigned color,
14382 struct drm_clip_rect *clips,
14383 unsigned num_clips)
14384{
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014385 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014386
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014387 i915_gem_object_flush_if_display(obj);
Chris Wilsond59b21e2017-02-22 11:40:49 +000014388 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014389
14390 return 0;
14391}
14392
Jesse Barnes79e53942008-11-07 14:24:08 -080014393static const struct drm_framebuffer_funcs intel_fb_funcs = {
14394 .destroy = intel_user_framebuffer_destroy,
14395 .create_handle = intel_user_framebuffer_create_handle,
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014396 .dirty = intel_user_framebuffer_dirty,
Jesse Barnes79e53942008-11-07 14:24:08 -080014397};
14398
Damien Lespiaub3218032015-02-27 11:15:18 +000014399static
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014400u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014401 u32 pixel_format, u64 fb_modifier)
Damien Lespiaub3218032015-02-27 11:15:18 +000014402{
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014403 struct intel_crtc *crtc;
14404 struct intel_plane *plane;
Damien Lespiaub3218032015-02-27 11:15:18 +000014405
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014406 /*
14407 * We assume the primary plane for pipe A has
14408 * the highest stride limits of them all.
14409 */
14410 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14411 plane = to_intel_plane(crtc->base.primary);
Ville Syrjäläac484962016-01-20 21:05:26 +020014412
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014413 return plane->max_stride(plane, pixel_format, fb_modifier,
14414 DRM_MODE_ROTATE_0);
Damien Lespiaub3218032015-02-27 11:15:18 +000014415}
14416
Chris Wilson24dbf512017-02-15 10:59:18 +000014417static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14418 struct drm_i915_gem_object *obj,
14419 struct drm_mode_fb_cmd2 *mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014420{
Chris Wilson24dbf512017-02-15 10:59:18 +000014421 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014422 struct drm_framebuffer *fb = &intel_fb->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +000014423 struct drm_format_name_buf format_name;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014424 u32 pitch_limit;
Chris Wilsondd689282017-03-01 15:41:28 +000014425 unsigned int tiling, stride;
Chris Wilson24dbf512017-02-15 10:59:18 +000014426 int ret = -EINVAL;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014427 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -080014428
Chris Wilsondd689282017-03-01 15:41:28 +000014429 i915_gem_object_lock(obj);
14430 obj->framebuffer_references++;
14431 tiling = i915_gem_object_get_tiling(obj);
14432 stride = i915_gem_object_get_stride(obj);
14433 i915_gem_object_unlock(obj);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020014434
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014435 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014436 /*
14437 * If there's a fence, enforce that
14438 * the fb modifier and tiling mode match.
14439 */
14440 if (tiling != I915_TILING_NONE &&
14441 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014442 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014443 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014444 }
14445 } else {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014446 if (tiling == I915_TILING_X) {
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014447 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014448 } else if (tiling == I915_TILING_Y) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014449 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014450 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014451 }
14452 }
14453
Tvrtko Ursulin9a8f0a12015-02-27 11:15:24 +000014454 /* Passed in modifier sanity checking. */
14455 switch (mode_cmd->modifier[0]) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014456 case I915_FORMAT_MOD_Y_TILED_CCS:
14457 case I915_FORMAT_MOD_Yf_TILED_CCS:
14458 switch (mode_cmd->pixel_format) {
14459 case DRM_FORMAT_XBGR8888:
14460 case DRM_FORMAT_ABGR8888:
14461 case DRM_FORMAT_XRGB8888:
14462 case DRM_FORMAT_ARGB8888:
14463 break;
14464 default:
14465 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
14466 goto err;
14467 }
14468 /* fall through */
Tvrtko Ursulin9a8f0a12015-02-27 11:15:24 +000014469 case I915_FORMAT_MOD_Yf_TILED:
Paulo Zanonief51e0a2018-09-24 17:19:11 -070014470 if (mode_cmd->pixel_format == DRM_FORMAT_C8) {
14471 DRM_DEBUG_KMS("Indexed format does not support Yf tiling\n");
14472 goto err;
14473 }
14474 /* fall through */
14475 case I915_FORMAT_MOD_Y_TILED:
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014476 if (INTEL_GEN(dev_priv) < 9) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014477 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14478 mode_cmd->modifier[0]);
Chris Wilson24dbf512017-02-15 10:59:18 +000014479 goto err;
Tvrtko Ursulin9a8f0a12015-02-27 11:15:24 +000014480 }
Paulo Zanonief51e0a2018-09-24 17:19:11 -070014481 break;
Ben Widawsky2f075562017-03-24 14:29:48 -070014482 case DRM_FORMAT_MOD_LINEAR:
Tvrtko Ursulin9a8f0a12015-02-27 11:15:24 +000014483 case I915_FORMAT_MOD_X_TILED:
14484 break;
14485 default:
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014486 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14487 mode_cmd->modifier[0]);
Chris Wilson24dbf512017-02-15 10:59:18 +000014488 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014489 }
Chris Wilson57cd6502010-08-08 12:34:44 +010014490
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014491 /*
14492 * gen2/3 display engine uses the fence if present,
14493 * so the tiling mode must match the fb modifier exactly.
14494 */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014495 if (INTEL_GEN(dev_priv) < 4 &&
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014496 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014497 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014498 goto err;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014499 }
14500
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014501 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format,
14502 mode_cmd->modifier[0]);
Chris Wilsona35cdaa2013-06-25 17:26:45 +010014503 if (mode_cmd->pitches[0] > pitch_limit) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014504 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
Ben Widawsky2f075562017-03-24 14:29:48 -070014505 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014506 "tiled" : "linear",
14507 mode_cmd->pitches[0], pitch_limit);
Chris Wilson24dbf512017-02-15 10:59:18 +000014508 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014509 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014510
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014511 /*
14512 * If there's a fence, enforce that
14513 * the fb pitch and fence stride match.
14514 */
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014515 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14516 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14517 mode_cmd->pitches[0], stride);
Chris Wilson24dbf512017-02-15 10:59:18 +000014518 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014519 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014520
Ville Syrjälä57779d02012-10-31 17:50:14 +020014521 /* Reject formats not supported by any plane early. */
Jesse Barnes308e5bc2011-11-14 14:51:28 -080014522 switch (mode_cmd->pixel_format) {
Ville Syrjälä57779d02012-10-31 17:50:14 +020014523 case DRM_FORMAT_C8:
Ville Syrjälä04b39242011-11-17 18:05:13 +020014524 case DRM_FORMAT_RGB565:
14525 case DRM_FORMAT_XRGB8888:
14526 case DRM_FORMAT_ARGB8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +020014527 break;
14528 case DRM_FORMAT_XRGB1555:
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014529 if (INTEL_GEN(dev_priv) > 3) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014530 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14531 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014532 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014533 }
Ville Syrjälä57779d02012-10-31 17:50:14 +020014534 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +020014535 case DRM_FORMAT_ABGR8888:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014536 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014537 INTEL_GEN(dev_priv) < 9) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014538 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14539 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014540 goto err;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010014541 }
14542 break;
14543 case DRM_FORMAT_XBGR8888:
Ville Syrjälä04b39242011-11-17 18:05:13 +020014544 case DRM_FORMAT_XRGB2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +020014545 case DRM_FORMAT_XBGR2101010:
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014546 if (INTEL_GEN(dev_priv) < 4) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014547 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14548 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014549 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014550 }
Jesse Barnesb5626742011-06-24 12:19:27 -070014551 break;
Damien Lespiau75312082015-05-15 19:06:01 +010014552 case DRM_FORMAT_ABGR2101010:
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014553 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014554 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14555 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014556 goto err;
Damien Lespiau75312082015-05-15 19:06:01 +010014557 }
14558 break;
Ville Syrjälä04b39242011-11-17 18:05:13 +020014559 case DRM_FORMAT_YUYV:
14560 case DRM_FORMAT_UYVY:
14561 case DRM_FORMAT_YVYU:
14562 case DRM_FORMAT_VYUY:
Ville Syrjäläab330812017-04-21 21:14:32 +030014563 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014564 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14565 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014566 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014567 }
Chris Wilson57cd6502010-08-08 12:34:44 +010014568 break;
Chandra Kondurue44134f2018-05-12 03:03:15 +053014569 case DRM_FORMAT_NV12:
Chandra Kondurue44134f2018-05-12 03:03:15 +053014570 if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) ||
Maarten Lankhorst26ee5bc2018-10-22 15:45:14 +020014571 IS_BROXTON(dev_priv)) {
Chandra Kondurue44134f2018-05-12 03:03:15 +053014572 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14573 drm_get_format_name(mode_cmd->pixel_format,
14574 &format_name));
14575 goto err;
14576 }
14577 break;
Chris Wilson57cd6502010-08-08 12:34:44 +010014578 default:
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014579 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14580 drm_get_format_name(mode_cmd->pixel_format, &format_name));
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014581 goto err;
Chris Wilson57cd6502010-08-08 12:34:44 +010014582 }
14583
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014584 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14585 if (mode_cmd->offsets[0] != 0)
Chris Wilson24dbf512017-02-15 10:59:18 +000014586 goto err;
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014587
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014588 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014589
Chandra Kondurue44134f2018-05-12 03:03:15 +053014590 if (fb->format->format == DRM_FORMAT_NV12 &&
14591 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14592 fb->height < SKL_MIN_YUV_420_SRC_H ||
14593 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14594 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
Ville Syrjälä3b909462018-10-29 16:00:31 +020014595 goto err;
Chandra Kondurue44134f2018-05-12 03:03:15 +053014596 }
14597
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014598 for (i = 0; i < fb->format->num_planes; i++) {
14599 u32 stride_alignment;
14600
14601 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14602 DRM_DEBUG_KMS("bad plane %d handle\n", i);
Christophe JAILLET37875d62017-09-10 10:56:42 +020014603 goto err;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014604 }
14605
14606 stride_alignment = intel_fb_stride_alignment(fb, i);
14607
14608 /*
14609 * Display WA #0531: skl,bxt,kbl,glk
14610 *
14611 * Render decompression and plane width > 3840
14612 * combined with horizontal panning requires the
14613 * plane stride to be a multiple of 4. We'll just
14614 * require the entire fb to accommodate that to avoid
14615 * potential runtime errors at plane configuration time.
14616 */
14617 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -070014618 is_ccs_modifier(fb->modifier))
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014619 stride_alignment *= 4;
14620
14621 if (fb->pitches[i] & (stride_alignment - 1)) {
14622 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14623 i, fb->pitches[i], stride_alignment);
14624 goto err;
14625 }
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014626
Daniel Stonea268bcd2018-05-18 15:30:08 +010014627 fb->obj[i] = &obj->base;
14628 }
Daniel Vetterc7d73f62012-12-13 23:38:38 +010014629
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014630 ret = intel_fill_fb_info(dev_priv, fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +030014631 if (ret)
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014632 goto err;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +020014633
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014634 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -080014635 if (ret) {
14636 DRM_ERROR("framebuffer init failed %d\n", ret);
Chris Wilson24dbf512017-02-15 10:59:18 +000014637 goto err;
Jesse Barnes79e53942008-11-07 14:24:08 -080014638 }
14639
Jesse Barnes79e53942008-11-07 14:24:08 -080014640 return 0;
Chris Wilson24dbf512017-02-15 10:59:18 +000014641
14642err:
Chris Wilsondd689282017-03-01 15:41:28 +000014643 i915_gem_object_lock(obj);
14644 obj->framebuffer_references--;
14645 i915_gem_object_unlock(obj);
Chris Wilson24dbf512017-02-15 10:59:18 +000014646 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014647}
14648
Jesse Barnes79e53942008-11-07 14:24:08 -080014649static struct drm_framebuffer *
14650intel_user_framebuffer_create(struct drm_device *dev,
14651 struct drm_file *filp,
Ville Syrjälä1eb834512015-11-11 19:11:29 +020014652 const struct drm_mode_fb_cmd2 *user_mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014653{
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014654 struct drm_framebuffer *fb;
Chris Wilson05394f32010-11-08 19:18:58 +000014655 struct drm_i915_gem_object *obj;
Ville Syrjälä76dc3762015-11-11 19:11:28 +020014656 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
Jesse Barnes79e53942008-11-07 14:24:08 -080014657
Chris Wilson03ac0642016-07-20 13:31:51 +010014658 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14659 if (!obj)
Chris Wilsoncce13ff2010-08-08 13:36:38 +010014660 return ERR_PTR(-ENOENT);
Jesse Barnes79e53942008-11-07 14:24:08 -080014661
Chris Wilson24dbf512017-02-15 10:59:18 +000014662 fb = intel_framebuffer_create(obj, &mode_cmd);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014663 if (IS_ERR(fb))
Chris Wilsonf0cd5182016-10-28 13:58:43 +010014664 i915_gem_object_put(obj);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014665
14666 return fb;
Jesse Barnes79e53942008-11-07 14:24:08 -080014667}
14668
Chris Wilson778e23a2016-12-05 14:29:39 +000014669static void intel_atomic_state_free(struct drm_atomic_state *state)
14670{
14671 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14672
14673 drm_atomic_state_default_release(state);
14674
14675 i915_sw_fence_fini(&intel_state->commit_ready);
14676
14677 kfree(state);
14678}
14679
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014680static enum drm_mode_status
14681intel_mode_valid(struct drm_device *dev,
14682 const struct drm_display_mode *mode)
14683{
Ville Syrjäläad77c532018-06-15 20:44:05 +030014684 struct drm_i915_private *dev_priv = to_i915(dev);
14685 int hdisplay_max, htotal_max;
14686 int vdisplay_max, vtotal_max;
14687
Ville Syrjäläe4dd27a2018-05-24 15:54:03 +030014688 /*
14689 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14690 * of DBLSCAN modes to the output's mode list when they detect
14691 * the scaling mode property on the connector. And they don't
14692 * ask the kernel to validate those modes in any way until
14693 * modeset time at which point the client gets a protocol error.
14694 * So in order to not upset those clients we silently ignore the
14695 * DBLSCAN flag on such connectors. For other connectors we will
14696 * reject modes with the DBLSCAN flag in encoder->compute_config().
14697 * And we always reject DBLSCAN modes in connector->mode_valid()
14698 * as we never want such modes on the connector's mode list.
14699 */
14700
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014701 if (mode->vscan > 1)
14702 return MODE_NO_VSCAN;
14703
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014704 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14705 return MODE_H_ILLEGAL;
14706
14707 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14708 DRM_MODE_FLAG_NCSYNC |
14709 DRM_MODE_FLAG_PCSYNC))
14710 return MODE_HSYNC;
14711
14712 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14713 DRM_MODE_FLAG_PIXMUX |
14714 DRM_MODE_FLAG_CLKDIV2))
14715 return MODE_BAD;
14716
Ville Syrjäläad77c532018-06-15 20:44:05 +030014717 if (INTEL_GEN(dev_priv) >= 9 ||
14718 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14719 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14720 vdisplay_max = 4096;
14721 htotal_max = 8192;
14722 vtotal_max = 8192;
14723 } else if (INTEL_GEN(dev_priv) >= 3) {
14724 hdisplay_max = 4096;
14725 vdisplay_max = 4096;
14726 htotal_max = 8192;
14727 vtotal_max = 8192;
14728 } else {
14729 hdisplay_max = 2048;
14730 vdisplay_max = 2048;
14731 htotal_max = 4096;
14732 vtotal_max = 4096;
14733 }
14734
14735 if (mode->hdisplay > hdisplay_max ||
14736 mode->hsync_start > htotal_max ||
14737 mode->hsync_end > htotal_max ||
14738 mode->htotal > htotal_max)
14739 return MODE_H_ILLEGAL;
14740
14741 if (mode->vdisplay > vdisplay_max ||
14742 mode->vsync_start > vtotal_max ||
14743 mode->vsync_end > vtotal_max ||
14744 mode->vtotal > vtotal_max)
14745 return MODE_V_ILLEGAL;
14746
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014747 return MODE_OK;
14748}
14749
Jesse Barnes79e53942008-11-07 14:24:08 -080014750static const struct drm_mode_config_funcs intel_mode_funcs = {
Jesse Barnes79e53942008-11-07 14:24:08 -080014751 .fb_create = intel_user_framebuffer_create,
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -070014752 .get_format_info = intel_get_format_info,
Daniel Vetter0632fef2013-10-08 17:44:49 +020014753 .output_poll_changed = intel_fbdev_output_poll_changed,
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014754 .mode_valid = intel_mode_valid,
Matt Roper5ee67f12015-01-21 16:35:44 -080014755 .atomic_check = intel_atomic_check,
14756 .atomic_commit = intel_atomic_commit,
Maarten Lankhorstde419ab2015-06-04 10:21:28 +020014757 .atomic_state_alloc = intel_atomic_state_alloc,
14758 .atomic_state_clear = intel_atomic_state_clear,
Chris Wilson778e23a2016-12-05 14:29:39 +000014759 .atomic_state_free = intel_atomic_state_free,
Jesse Barnes79e53942008-11-07 14:24:08 -080014760};
14761
Imre Deak88212942016-03-16 13:38:53 +020014762/**
14763 * intel_init_display_hooks - initialize the display modesetting hooks
14764 * @dev_priv: device private
14765 */
14766void intel_init_display_hooks(struct drm_i915_private *dev_priv)
Jesse Barnese70236a2009-09-21 10:42:27 -070014767{
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +020014768 intel_init_cdclk_hooks(dev_priv);
14769
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014770 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000014771 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014772 dev_priv->display.get_initial_plane_config =
14773 skylake_get_initial_plane_config;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000014774 dev_priv->display.crtc_compute_clock =
14775 haswell_crtc_compute_clock;
14776 dev_priv->display.crtc_enable = haswell_crtc_enable;
14777 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020014778 } else if (HAS_DDI(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014779 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014780 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020014781 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira797d0252014-10-29 11:32:34 +020014782 dev_priv->display.crtc_compute_clock =
14783 haswell_crtc_compute_clock;
Paulo Zanoni4f771f12012-10-23 18:29:51 -020014784 dev_priv->display.crtc_enable = haswell_crtc_enable;
14785 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020014786 } else if (HAS_PCH_SPLIT(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014787 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014788 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020014789 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +020014790 dev_priv->display.crtc_compute_clock =
14791 ironlake_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020014792 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14793 dev_priv->display.crtc_disable = ironlake_crtc_disable;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020014794 } else if (IS_CHERRYVIEW(dev_priv)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -070014795 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014796 dev_priv->display.get_initial_plane_config =
14797 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020014798 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14799 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14800 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14801 } else if (IS_VALLEYVIEW(dev_priv)) {
14802 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14803 dev_priv->display.get_initial_plane_config =
14804 i9xx_get_initial_plane_config;
14805 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
Jesse Barnes89b667f2013-04-18 14:51:36 -070014806 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14807 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +020014808 } else if (IS_G4X(dev_priv)) {
14809 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14810 dev_priv->display.get_initial_plane_config =
14811 i9xx_get_initial_plane_config;
14812 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14813 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14814 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +020014815 } else if (IS_PINEVIEW(dev_priv)) {
14816 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14817 dev_priv->display.get_initial_plane_config =
14818 i9xx_get_initial_plane_config;
14819 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14820 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14821 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +020014822 } else if (!IS_GEN2(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014823 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014824 dev_priv->display.get_initial_plane_config =
14825 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveirad6dfee72014-10-29 11:32:36 +020014826 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020014827 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14828 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +020014829 } else {
14830 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14831 dev_priv->display.get_initial_plane_config =
14832 i9xx_get_initial_plane_config;
14833 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14834 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14835 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Eric Anholtf564048e2011-03-30 13:01:02 -070014836 }
Jesse Barnese70236a2009-09-21 10:42:27 -070014837
Imre Deak88212942016-03-16 13:38:53 +020014838 if (IS_GEN5(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014839 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014840 } else if (IS_GEN6(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014841 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014842 } else if (IS_IVYBRIDGE(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014843 /* FIXME: detect B0+ stepping and use auto training */
14844 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014845 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014846 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
Ville Syrjälä445e7802016-05-11 22:44:42 +030014847 }
14848
Rodrigo Vivibd30ca22017-09-26 14:13:46 -070014849 if (INTEL_GEN(dev_priv) >= 9)
Lyude27082492016-08-24 07:48:10 +020014850 dev_priv->display.update_crtcs = skl_update_crtcs;
14851 else
14852 dev_priv->display.update_crtcs = intel_update_crtcs;
Jesse Barnese70236a2009-09-21 10:42:27 -070014853}
14854
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014855/* Disable the VGA plane that we never use */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000014856static void i915_disable_vga(struct drm_i915_private *dev_priv)
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014857{
David Weinehall52a05c32016-08-22 13:32:44 +030014858 struct pci_dev *pdev = dev_priv->drm.pdev;
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014859 u8 sr1;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014860 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014861
Ville Syrjälä2b37c612014-01-22 21:32:38 +020014862 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
David Weinehall52a05c32016-08-22 13:32:44 +030014863 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes3fdcf432012-04-06 11:46:27 -070014864 outb(SR01, VGA_SR_INDEX);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014865 sr1 = inb(VGA_SR_DATA);
14866 outb(sr1 | 1<<5, VGA_SR_DATA);
David Weinehall52a05c32016-08-22 13:32:44 +030014867 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014868 udelay(300);
14869
Ville Syrjälä01f5a622014-12-16 18:38:37 +020014870 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014871 POSTING_READ(vga_reg);
14872}
14873
Daniel Vetterf8175862012-04-10 15:50:11 +020014874void intel_modeset_init_hw(struct drm_device *dev)
14875{
Chris Wilsonfac5e232016-07-04 11:34:36 +010014876 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1a617b72015-12-03 14:31:06 +010014877
Ville Syrjälä4c75b942016-10-31 22:37:12 +020014878 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +030014879 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020014880 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
Daniel Vetterf8175862012-04-10 15:50:11 +020014881}
14882
Matt Roperd93c0372015-12-03 11:37:41 -080014883/*
14884 * Calculate what we think the watermarks should be for the state we've read
14885 * out of the hardware and then immediately program those watermarks so that
14886 * we ensure the hardware settings match our internal state.
14887 *
14888 * We can calculate what we think WM's should be by creating a duplicate of the
14889 * current state (which was constructed during hardware readout) and running it
14890 * through the atomic check code to calculate new watermark values in the
14891 * state object.
14892 */
14893static void sanitize_watermarks(struct drm_device *dev)
14894{
14895 struct drm_i915_private *dev_priv = to_i915(dev);
14896 struct drm_atomic_state *state;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014897 struct intel_atomic_state *intel_state;
Matt Roperd93c0372015-12-03 11:37:41 -080014898 struct drm_crtc *crtc;
14899 struct drm_crtc_state *cstate;
14900 struct drm_modeset_acquire_ctx ctx;
14901 int ret;
14902 int i;
14903
14904 /* Only supported on platforms that use atomic watermark design */
Matt Ropered4a6a72016-02-23 17:20:13 -080014905 if (!dev_priv->display.optimize_watermarks)
Matt Roperd93c0372015-12-03 11:37:41 -080014906 return;
14907
14908 /*
14909 * We need to hold connection_mutex before calling duplicate_state so
14910 * that the connector loop is protected.
14911 */
14912 drm_modeset_acquire_init(&ctx, 0);
14913retry:
Matt Roper0cd12622016-01-12 07:13:37 -080014914 ret = drm_modeset_lock_all_ctx(dev, &ctx);
Matt Roperd93c0372015-12-03 11:37:41 -080014915 if (ret == -EDEADLK) {
14916 drm_modeset_backoff(&ctx);
14917 goto retry;
14918 } else if (WARN_ON(ret)) {
Matt Roper0cd12622016-01-12 07:13:37 -080014919 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080014920 }
14921
14922 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14923 if (WARN_ON(IS_ERR(state)))
Matt Roper0cd12622016-01-12 07:13:37 -080014924 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080014925
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014926 intel_state = to_intel_atomic_state(state);
14927
Matt Ropered4a6a72016-02-23 17:20:13 -080014928 /*
14929 * Hardware readout is the only time we don't want to calculate
14930 * intermediate watermarks (since we don't trust the current
14931 * watermarks).
14932 */
Ville Syrjälä602ae832017-03-02 19:15:02 +020014933 if (!HAS_GMCH_DISPLAY(dev_priv))
14934 intel_state->skip_intermediate_wm = true;
Matt Ropered4a6a72016-02-23 17:20:13 -080014935
Matt Roperd93c0372015-12-03 11:37:41 -080014936 ret = intel_atomic_check(dev, state);
14937 if (ret) {
14938 /*
14939 * If we fail here, it means that the hardware appears to be
14940 * programmed in a way that shouldn't be possible, given our
14941 * understanding of watermark requirements. This might mean a
14942 * mistake in the hardware readout code or a mistake in the
14943 * watermark calculations for a given platform. Raise a WARN
14944 * so that this is noticeable.
14945 *
14946 * If this actually happens, we'll have to just leave the
14947 * BIOS-programmed watermarks untouched and hope for the best.
14948 */
14949 WARN(true, "Could not determine valid watermarks for inherited state\n");
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020014950 goto put_state;
Matt Roperd93c0372015-12-03 11:37:41 -080014951 }
14952
14953 /* Write calculated watermark values back */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010014954 for_each_new_crtc_in_state(state, crtc, cstate, i) {
Matt Roperd93c0372015-12-03 11:37:41 -080014955 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14956
Matt Ropered4a6a72016-02-23 17:20:13 -080014957 cs->wm.need_postvbl_update = true;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014958 dev_priv->display.optimize_watermarks(intel_state, cs);
Maarten Lankhorst556fe362017-11-10 12:34:53 +010014959
14960 to_intel_crtc_state(crtc->state)->wm = cs->wm;
Matt Roperd93c0372015-12-03 11:37:41 -080014961 }
14962
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020014963put_state:
Chris Wilson08536952016-10-14 13:18:18 +010014964 drm_atomic_state_put(state);
Matt Roper0cd12622016-01-12 07:13:37 -080014965fail:
Matt Roperd93c0372015-12-03 11:37:41 -080014966 drm_modeset_drop_locks(&ctx);
14967 drm_modeset_acquire_fini(&ctx);
14968}
14969
Chris Wilson58ecd9d2017-11-05 13:49:05 +000014970static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14971{
14972 if (IS_GEN5(dev_priv)) {
14973 u32 fdi_pll_clk =
14974 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14975
14976 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14977 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
14978 dev_priv->fdi_pll_freq = 270000;
14979 } else {
14980 return;
14981 }
14982
14983 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14984}
14985
Azhar Shaikh516a49c2018-07-06 11:37:30 -070014986static int intel_initial_commit(struct drm_device *dev)
14987{
14988 struct drm_atomic_state *state = NULL;
14989 struct drm_modeset_acquire_ctx ctx;
14990 struct drm_crtc *crtc;
14991 struct drm_crtc_state *crtc_state;
14992 int ret = 0;
14993
14994 state = drm_atomic_state_alloc(dev);
14995 if (!state)
14996 return -ENOMEM;
14997
14998 drm_modeset_acquire_init(&ctx, 0);
14999
15000retry:
15001 state->acquire_ctx = &ctx;
15002
15003 drm_for_each_crtc(crtc, dev) {
15004 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15005 if (IS_ERR(crtc_state)) {
15006 ret = PTR_ERR(crtc_state);
15007 goto out;
15008 }
15009
15010 if (crtc_state->active) {
15011 ret = drm_atomic_add_affected_planes(state, crtc);
15012 if (ret)
15013 goto out;
Ville Syrjäläfa6af5142018-11-20 15:54:49 +020015014
15015 /*
15016 * FIXME hack to force a LUT update to avoid the
15017 * plane update forcing the pipe gamma on without
15018 * having a proper LUT loaded. Remove once we
15019 * have readout for pipe gamma enable.
15020 */
15021 crtc_state->color_mgmt_changed = true;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015022 }
15023 }
15024
15025 ret = drm_atomic_commit(state);
15026
15027out:
15028 if (ret == -EDEADLK) {
15029 drm_atomic_state_clear(state);
15030 drm_modeset_backoff(&ctx);
15031 goto retry;
15032 }
15033
15034 drm_atomic_state_put(state);
15035
15036 drm_modeset_drop_locks(&ctx);
15037 drm_modeset_acquire_fini(&ctx);
15038
15039 return ret;
15040}
15041
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015042int intel_modeset_init(struct drm_device *dev)
Jesse Barnes79e53942008-11-07 14:24:08 -080015043{
Joonas Lahtinen72e96d62016-03-30 16:57:10 +030015044 struct drm_i915_private *dev_priv = to_i915(dev);
15045 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Damien Lespiau8cc87b72014-03-03 17:31:44 +000015046 enum pipe pipe;
Jesse Barnes46f297f2014-03-07 08:57:48 -080015047 struct intel_crtc *crtc;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015048 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080015049
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015050 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15051
Jesse Barnes79e53942008-11-07 14:24:08 -080015052 drm_mode_config_init(dev);
15053
15054 dev->mode_config.min_width = 0;
15055 dev->mode_config.min_height = 0;
15056
Dave Airlie019d96c2011-09-29 16:20:42 +010015057 dev->mode_config.preferred_depth = 24;
15058 dev->mode_config.prefer_shadow = 1;
15059
Tvrtko Ursulin25bab382015-02-10 17:16:16 +000015060 dev->mode_config.allow_fb_modifiers = true;
15061
Laurent Pincharte6ecefa2012-05-17 13:27:23 +020015062 dev->mode_config.funcs = &intel_mode_funcs;
Jesse Barnes79e53942008-11-07 14:24:08 -080015063
Andrea Arcangeli400c19d2017-04-07 01:23:45 +020015064 init_llist_head(&dev_priv->atomic_helper.free_list);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015065 INIT_WORK(&dev_priv->atomic_helper.free_work,
Chris Wilsonba318c62017-02-02 20:47:41 +000015066 intel_atomic_helper_free_state_worker);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015067
Jani Nikula27a981b2018-10-17 12:35:39 +030015068 intel_init_quirks(dev_priv);
Jesse Barnesb690e962010-07-19 13:53:12 -070015069
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080015070 intel_fbc_init(dev_priv);
15071
Ville Syrjälä62d75df2016-10-31 22:37:25 +020015072 intel_init_pm(dev_priv);
Eugeni Dodonov1fa61102012-04-18 15:29:26 -030015073
Lukas Wunner69f92f62015-07-15 13:57:35 +020015074 /*
15075 * There may be no VBT; and if the BIOS enabled SSC we can
15076 * just keep using it to avoid unnecessary flicker. Whereas if the
15077 * BIOS isn't using it, don't assume it will work even if the VBT
15078 * indicates as much.
15079 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010015080 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Lukas Wunner69f92f62015-07-15 13:57:35 +020015081 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15082 DREF_SSC1_ENABLE);
15083
15084 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15085 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15086 bios_lvds_use_ssc ? "en" : "dis",
15087 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15088 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15089 }
15090 }
15091
Ville Syrjäläad77c532018-06-15 20:44:05 +030015092 /* maximum framebuffer dimensions */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010015093 if (IS_GEN2(dev_priv)) {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015094 dev->mode_config.max_width = 2048;
15095 dev->mode_config.max_height = 2048;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010015096 } else if (IS_GEN3(dev_priv)) {
Keith Packard5e4d6fa2009-07-12 23:53:17 -070015097 dev->mode_config.max_width = 4096;
15098 dev->mode_config.max_height = 4096;
Jesse Barnes79e53942008-11-07 14:24:08 -080015099 } else {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015100 dev->mode_config.max_width = 8192;
15101 dev->mode_config.max_height = 8192;
Jesse Barnes79e53942008-11-07 14:24:08 -080015102 }
Damien Lespiau068be562014-03-28 14:17:49 +000015103
Jani Nikula2a307c22016-11-30 17:43:04 +020015104 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15105 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
Ville Syrjälädc41c152014-08-13 11:57:05 +030015106 dev->mode_config.cursor_height = 1023;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010015107 } else if (IS_GEN2(dev_priv)) {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015108 dev->mode_config.cursor_width = 64;
15109 dev->mode_config.cursor_height = 64;
Damien Lespiau068be562014-03-28 14:17:49 +000015110 } else {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015111 dev->mode_config.cursor_width = 256;
15112 dev->mode_config.cursor_height = 256;
Damien Lespiau068be562014-03-28 14:17:49 +000015113 }
15114
Matthew Auld73ebd502017-12-11 15:18:20 +000015115 dev->mode_config.fb_base = ggtt->gmadr.start;
Jesse Barnes79e53942008-11-07 14:24:08 -080015116
Zhao Yakui28c97732009-10-09 11:39:41 +080015117 DRM_DEBUG_KMS("%d display pipe%s available.\n",
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000015118 INTEL_INFO(dev_priv)->num_pipes,
15119 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
Jesse Barnes79e53942008-11-07 14:24:08 -080015120
Damien Lespiau055e3932014-08-18 13:49:10 +010015121 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020015122 ret = intel_crtc_init(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015123 if (ret) {
15124 drm_mode_config_cleanup(dev);
15125 return ret;
15126 }
Jesse Barnes79e53942008-11-07 14:24:08 -080015127 }
15128
Daniel Vettere72f9fb2013-06-05 13:34:06 +020015129 intel_shared_dpll_init(dev);
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015130 intel_update_fdi_pll_freq(dev_priv);
Jesse Barnesee7b9f92012-04-20 17:11:53 +010015131
Ville Syrjälä5be6e332017-02-20 16:04:43 +020015132 intel_update_czclk(dev_priv);
15133 intel_modeset_init_hw(dev);
15134
Ville Syrjäläb2045352016-05-13 23:41:27 +030015135 if (dev_priv->max_cdclk_freq == 0)
Ville Syrjälä4c75b942016-10-31 22:37:12 +020015136 intel_update_max_cdclk(dev_priv);
Ville Syrjäläb2045352016-05-13 23:41:27 +030015137
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015138 /* Just disable it once at startup */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015139 i915_disable_vga(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020015140 intel_setup_outputs(dev_priv);
Chris Wilson11be49e2012-11-15 11:32:20 +000015141
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015142 drm_modeset_lock_all(dev);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015143 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015144 drm_modeset_unlock_all(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015145
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015146 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015147 struct intel_initial_plane_config plane_config = {};
15148
Jesse Barnes46f297f2014-03-07 08:57:48 -080015149 if (!crtc->active)
15150 continue;
15151
Jesse Barnes46f297f2014-03-07 08:57:48 -080015152 /*
Jesse Barnes46f297f2014-03-07 08:57:48 -080015153 * Note that reserving the BIOS fb up front prevents us
15154 * from stuffing other stolen allocations like the ring
15155 * on top. This prevents some ugliness at boot time, and
15156 * can even allow for smooth boot transitions if the BIOS
15157 * fb is large enough for the active pipe configuration.
15158 */
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015159 dev_priv->display.get_initial_plane_config(crtc,
15160 &plane_config);
15161
15162 /*
15163 * If the fb is shared between multiple heads, we'll
15164 * just get the first one.
15165 */
15166 intel_find_initial_plane_obj(crtc, &plane_config);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015167 }
Matt Roperd93c0372015-12-03 11:37:41 -080015168
15169 /*
15170 * Make sure hardware watermarks really match the state we read out.
15171 * Note that we need to do this after reconstructing the BIOS fb's
15172 * since the watermark calculation done here will use pstate->fb.
15173 */
Ville Syrjälä602ae832017-03-02 19:15:02 +020015174 if (!HAS_GMCH_DISPLAY(dev_priv))
15175 sanitize_watermarks(dev);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015176
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015177 /*
15178 * Force all active planes to recompute their states. So that on
15179 * mode_setcrtc after probe, all the intel_plane_state variables
15180 * are already calculated and there is no assert_plane warnings
15181 * during bootup.
15182 */
15183 ret = intel_initial_commit(dev);
15184 if (ret)
15185 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15186
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015187 return 0;
Chris Wilson2c7111d2011-03-29 10:40:27 +010015188}
Jesse Barnesd5bb0812011-01-05 12:01:26 -080015189
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015190void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15191{
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015192 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015193 /* 640x480@60Hz, ~25175 kHz */
15194 struct dpll clock = {
15195 .m1 = 18,
15196 .m2 = 7,
15197 .p1 = 13,
15198 .p2 = 4,
15199 .n = 2,
15200 };
15201 u32 dpll, fp;
15202 int i;
15203
15204 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15205
15206 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15207 pipe_name(pipe), clock.vco, clock.dot);
15208
15209 fp = i9xx_dpll_compute_fp(&clock);
15210 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15211 DPLL_VGA_MODE_DIS |
15212 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15213 PLL_P2_DIVIDE_BY_4 |
15214 PLL_REF_INPUT_DREFCLK |
15215 DPLL_VCO_ENABLE;
15216
15217 I915_WRITE(FP0(pipe), fp);
15218 I915_WRITE(FP1(pipe), fp);
15219
15220 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15221 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15222 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15223 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15224 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15225 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15226 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15227
15228 /*
15229 * Apparently we need to have VGA mode enabled prior to changing
15230 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15231 * dividers, even though the register value does change.
15232 */
15233 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15234 I915_WRITE(DPLL(pipe), dpll);
15235
15236 /* Wait for the clocks to stabilize. */
15237 POSTING_READ(DPLL(pipe));
15238 udelay(150);
15239
15240 /* The pixel multiplier can only be updated once the
15241 * DPLL is enabled and the clocks are stable.
15242 *
15243 * So write it again.
15244 */
15245 I915_WRITE(DPLL(pipe), dpll);
15246
15247 /* We do this three times for luck */
15248 for (i = 0; i < 3 ; i++) {
15249 I915_WRITE(DPLL(pipe), dpll);
15250 POSTING_READ(DPLL(pipe));
15251 udelay(150); /* wait for warmup */
15252 }
15253
15254 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15255 POSTING_READ(PIPECONF(pipe));
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015256
15257 intel_wait_for_pipe_scanline_moving(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015258}
15259
15260void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15261{
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015262 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15263
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015264 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15265 pipe_name(pipe));
15266
Ville Syrjälä5816d9c2017-11-29 14:54:11 +020015267 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15268 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15269 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020015270 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15271 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015272
15273 I915_WRITE(PIPECONF(pipe), 0);
15274 POSTING_READ(PIPECONF(pipe));
15275
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015276 intel_wait_for_pipe_scanline_stopped(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015277
15278 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15279 POSTING_READ(DPLL(pipe));
15280}
15281
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015282static void
15283intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15284{
15285 struct intel_crtc *crtc;
Daniel Vetterfa555832012-10-10 23:14:00 +020015286
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015287 if (INTEL_GEN(dev_priv) >= 4)
15288 return;
Daniel Vetterfa555832012-10-10 23:14:00 +020015289
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015290 for_each_intel_crtc(&dev_priv->drm, crtc) {
15291 struct intel_plane *plane =
15292 to_intel_plane(crtc->base.primary);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015293 struct intel_crtc *plane_crtc;
15294 enum pipe pipe;
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015295
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015296 if (!plane->get_hw_state(plane, &pipe))
15297 continue;
15298
15299 if (pipe == crtc->pipe)
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015300 continue;
15301
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015302 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15303 plane->base.base.id, plane->base.name);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015304
15305 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15306 intel_plane_disable_noatomic(plane_crtc, plane);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015307 }
Daniel Vetterfa555832012-10-10 23:14:00 +020015308}
15309
Ville Syrjälä02e93c32015-08-26 19:39:19 +030015310static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15311{
15312 struct drm_device *dev = crtc->base.dev;
15313 struct intel_encoder *encoder;
15314
15315 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15316 return true;
15317
15318 return false;
15319}
15320
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015321static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15322{
15323 struct drm_device *dev = encoder->base.dev;
15324 struct intel_connector *connector;
15325
15326 for_each_connector_on_encoder(dev, &encoder->base, connector)
15327 return connector;
15328
15329 return NULL;
15330}
15331
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015332static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015333 enum pipe pch_transcoder)
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015334{
15335 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015336 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015337}
15338
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015339static void intel_sanitize_crtc(struct intel_crtc *crtc,
15340 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter24929352012-07-02 20:28:59 +020015341{
15342 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010015343 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015344 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15345 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter24929352012-07-02 20:28:59 +020015346
Daniel Vetter24929352012-07-02 20:28:59 +020015347 /* Clear any frame start delays used for debugging left by the BIOS */
Ville Syrjälä738a8142017-11-15 22:04:42 +020015348 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
Jani Nikula4d1de972016-03-18 17:05:42 +020015349 i915_reg_t reg = PIPECONF(cpu_transcoder);
15350
15351 I915_WRITE(reg,
15352 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15353 }
Daniel Vetter24929352012-07-02 20:28:59 +020015354
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015355 if (crtc_state->base.active) {
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015356 struct intel_plane *plane;
15357
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015358 /* Disable everything but the primary plane */
15359 for_each_intel_plane_on_crtc(dev, crtc, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015360 const struct intel_plane_state *plane_state =
15361 to_intel_plane_state(plane->base.state);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015362
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015363 if (plane_state->base.visible &&
15364 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15365 intel_plane_disable_noatomic(crtc, plane);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015366 }
Daniel Vetter96256042015-02-13 21:03:42 +010015367 }
Ville Syrjäläd3eaf882014-05-20 17:20:05 +030015368
Daniel Vetter24929352012-07-02 20:28:59 +020015369 /* Adjust the state of the output pipe according to whether we
15370 * have active connectors/encoders. */
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015371 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
Ville Syrjäläda1d0e22017-06-01 17:36:14 +030015372 intel_crtc_disable_noatomic(&crtc->base, ctx);
Daniel Vetter24929352012-07-02 20:28:59 +020015373
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015374 if (crtc_state->base.active || HAS_GMCH_DISPLAY(dev_priv)) {
Daniel Vetter4cc31482014-03-24 00:01:41 +010015375 /*
15376 * We start out with underrun reporting disabled to avoid races.
15377 * For correct bookkeeping mark this on active crtcs.
15378 *
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +020015379 * Also on gmch platforms we dont have any hardware bits to
15380 * disable the underrun reporting. Which means we need to start
15381 * out with underrun reporting disabled also on inactive pipes,
15382 * since otherwise we'll complain about the garbage we read when
15383 * e.g. coming up after runtime pm.
15384 *
Daniel Vetter4cc31482014-03-24 00:01:41 +010015385 * No protection against concurrent access is required - at
15386 * worst a fifo underrun happens which also sets this to false.
15387 */
15388 crtc->cpu_fifo_underrun_disabled = true;
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015389 /*
15390 * We track the PCH trancoder underrun reporting state
15391 * within the crtc. With crtc for pipe A housing the underrun
15392 * reporting state for PCH transcoder A, crtc for pipe B housing
15393 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15394 * and marking underrun reporting as disabled for the non-existing
15395 * PCH transcoders B and C would prevent enabling the south
15396 * error interrupt (see cpt_can_enable_serr_int()).
15397 */
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015398 if (has_pch_trancoder(dev_priv, crtc->pipe))
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015399 crtc->pch_fifo_underrun_disabled = true;
Daniel Vetter4cc31482014-03-24 00:01:41 +010015400 }
Daniel Vetter24929352012-07-02 20:28:59 +020015401}
15402
15403static void intel_sanitize_encoder(struct intel_encoder *encoder)
15404{
Imre Deak70332ac2018-11-01 16:04:27 +020015405 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015406 struct intel_connector *connector;
Daniel Vetter24929352012-07-02 20:28:59 +020015407
15408 /* We need to check both for a crtc link (meaning that the
15409 * encoder is active and trying to read from a pipe) and the
15410 * pipe itself being active. */
15411 bool has_active_crtc = encoder->base.crtc &&
15412 to_intel_crtc(encoder->base.crtc)->active;
15413
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015414 connector = intel_encoder_find_connector(encoder);
15415 if (connector && !has_active_crtc) {
Daniel Vetter24929352012-07-02 20:28:59 +020015416 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15417 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015418 encoder->base.name);
Daniel Vetter24929352012-07-02 20:28:59 +020015419
15420 /* Connector is active, but has no active pipe. This is
15421 * fallout from our resume register restoring. Disable
15422 * the encoder manually again. */
15423 if (encoder->base.crtc) {
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015424 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15425
Daniel Vetter24929352012-07-02 20:28:59 +020015426 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15427 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015428 encoder->base.name);
Jani Nikulac84c6fe2018-10-16 15:41:34 +030015429 if (encoder->disable)
15430 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
Ville Syrjäläa62d1492014-06-28 02:04:01 +030015431 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015432 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
Daniel Vetter24929352012-07-02 20:28:59 +020015433 }
Egbert Eich7f1950f2014-04-25 10:56:22 +020015434 encoder->base.crtc = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015435
15436 /* Inconsistent output/port/pipe state happens presumably due to
15437 * a bug in one of the get_hw_state functions. Or someplace else
15438 * in our code, like the register restore mess on resume. Clamp
15439 * things to off as a safer default. */
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015440
15441 connector->base.dpms = DRM_MODE_DPMS_OFF;
15442 connector->base.encoder = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015443 }
Maarten Lankhorstd6cae4a2018-05-16 10:50:38 +020015444
15445 /* notify opregion of the sanitized encoder state */
15446 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
Imre Deak70332ac2018-11-01 16:04:27 +020015447
15448 if (INTEL_GEN(dev_priv) >= 11)
15449 icl_sanitize_encoder_pll_mapping(encoder);
Daniel Vetter24929352012-07-02 20:28:59 +020015450}
15451
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015452void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015453{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010015454 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015455
Imre Deak04098752014-02-18 00:02:16 +020015456 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15457 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015458 i915_disable_vga(dev_priv);
Imre Deak04098752014-02-18 00:02:16 +020015459 }
15460}
15461
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015462void i915_redisable_vga(struct drm_i915_private *dev_priv)
Imre Deak04098752014-02-18 00:02:16 +020015463{
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015464 /* This function can be called both from intel_modeset_setup_hw_state or
15465 * at a very early point in our resume sequence, where the power well
15466 * structures are not yet restored. Since this function is at a very
15467 * paranoid "someone might have enabled VGA while we were not looking"
15468 * level, just check if the power well is enabled instead of trying to
15469 * follow the "don't touch the power well if we don't need it" policy
15470 * the rest of the driver uses. */
Imre Deak6392f842016-02-12 18:55:13 +020015471 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015472 return;
15473
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015474 i915_redisable_vga_power_on(dev_priv);
Imre Deak6392f842016-02-12 18:55:13 +020015475
15476 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015477}
15478
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015479/* FIXME read out full plane state for all planes */
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015480static void readout_plane_state(struct drm_i915_private *dev_priv)
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015481{
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015482 struct intel_plane *plane;
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015483 struct intel_crtc *crtc;
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015484
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015485 for_each_intel_plane(&dev_priv->drm, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015486 struct intel_plane_state *plane_state =
15487 to_intel_plane_state(plane->base.state);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015488 struct intel_crtc_state *crtc_state;
15489 enum pipe pipe = PIPE_A;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020015490 bool visible;
15491
15492 visible = plane->get_hw_state(plane, &pipe);
Maarten Lankhorstb26d3ea2015-09-23 16:11:41 +020015493
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015494 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15495 crtc_state = to_intel_crtc_state(crtc->base.state);
15496
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015497 intel_set_plane_visible(crtc_state, plane_state, visible);
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015498
15499 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15500 plane->base.base.id, plane->base.name,
15501 enableddisabled(visible), pipe_name(pipe));
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015502 }
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015503
15504 for_each_intel_crtc(&dev_priv->drm, crtc) {
15505 struct intel_crtc_state *crtc_state =
15506 to_intel_crtc_state(crtc->base.state);
15507
15508 fixup_active_planes(crtc_state);
15509 }
Ville Syrjälä98ec7732014-04-30 17:43:01 +030015510}
15511
Daniel Vetter30e984d2013-06-05 13:34:17 +020015512static void intel_modeset_readout_hw_state(struct drm_device *dev)
Daniel Vetter24929352012-07-02 20:28:59 +020015513{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015514 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015515 enum pipe pipe;
Daniel Vetter24929352012-07-02 20:28:59 +020015516 struct intel_crtc *crtc;
15517 struct intel_encoder *encoder;
15518 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015519 struct drm_connector_list_iter conn_iter;
Daniel Vetter53589012013-06-05 13:34:16 +020015520 int i;
Daniel Vetter24929352012-07-02 20:28:59 +020015521
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015522 dev_priv->active_crtcs = 0;
15523
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015524 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015525 struct intel_crtc_state *crtc_state =
15526 to_intel_crtc_state(crtc->base.state);
Daniel Vetter3b117c82013-04-17 20:15:07 +020015527
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020015528 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015529 memset(crtc_state, 0, sizeof(*crtc_state));
15530 crtc_state->base.crtc = &crtc->base;
Daniel Vetter24929352012-07-02 20:28:59 +020015531
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015532 crtc_state->base.active = crtc_state->base.enable =
15533 dev_priv->display.get_pipe_config(crtc, crtc_state);
15534
15535 crtc->base.enabled = crtc_state->base.enable;
15536 crtc->active = crtc_state->base.active;
15537
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015538 if (crtc_state->base.active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015539 dev_priv->active_crtcs |= 1 << crtc->pipe;
15540
Ville Syrjälä78108b72016-05-27 20:59:19 +030015541 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15542 crtc->base.base.id, crtc->base.name,
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015543 enableddisabled(crtc_state->base.active));
Daniel Vetter24929352012-07-02 20:28:59 +020015544 }
15545
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015546 readout_plane_state(dev_priv);
15547
Daniel Vetter53589012013-06-05 13:34:16 +020015548 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15549 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15550
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015551 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15552 &pll->state.hw_state);
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015553 pll->state.crtc_mask = 0;
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015554 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015555 struct intel_crtc_state *crtc_state =
15556 to_intel_crtc_state(crtc->base.state);
15557
15558 if (crtc_state->base.active &&
15559 crtc_state->shared_dpll == pll)
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015560 pll->state.crtc_mask |= 1 << crtc->pipe;
Daniel Vetter53589012013-06-05 13:34:16 +020015561 }
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015562 pll->active_mask = pll->state.crtc_mask;
Daniel Vetter53589012013-06-05 13:34:16 +020015563
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +020015564 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015565 pll->info->name, pll->state.crtc_mask, pll->on);
Daniel Vetter53589012013-06-05 13:34:16 +020015566 }
15567
Damien Lespiaub2784e12014-08-05 11:29:37 +010015568 for_each_intel_encoder(dev, encoder) {
Daniel Vetter24929352012-07-02 20:28:59 +020015569 pipe = 0;
15570
15571 if (encoder->get_hw_state(encoder, &pipe)) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015572 struct intel_crtc_state *crtc_state;
15573
Ville Syrjälä98187832016-10-31 22:37:10 +020015574 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015575 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015576
Jesse Barnes045ac3b2013-05-14 17:08:26 -070015577 encoder->base.crtc = &crtc->base;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015578 encoder->get_config(encoder, crtc_state);
Daniel Vetter24929352012-07-02 20:28:59 +020015579 } else {
15580 encoder->base.crtc = NULL;
15581 }
15582
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015583 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015584 encoder->base.base.id, encoder->base.name,
15585 enableddisabled(encoder->base.crtc),
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015586 pipe_name(pipe));
Daniel Vetter24929352012-07-02 20:28:59 +020015587 }
15588
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015589 drm_connector_list_iter_begin(dev, &conn_iter);
15590 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter24929352012-07-02 20:28:59 +020015591 if (connector->get_hw_state(connector)) {
15592 connector->base.dpms = DRM_MODE_DPMS_ON;
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015593
15594 encoder = connector->encoder;
15595 connector->base.encoder = &encoder->base;
15596
15597 if (encoder->base.crtc &&
15598 encoder->base.crtc->state->active) {
15599 /*
15600 * This has to be done during hardware readout
15601 * because anything calling .crtc_disable may
15602 * rely on the connector_mask being accurate.
15603 */
15604 encoder->base.crtc->state->connector_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015605 drm_connector_mask(&connector->base);
Maarten Lankhorste87a52b2016-01-28 15:04:58 +010015606 encoder->base.crtc->state->encoder_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015607 drm_encoder_mask(&encoder->base);
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015608 }
15609
Daniel Vetter24929352012-07-02 20:28:59 +020015610 } else {
15611 connector->base.dpms = DRM_MODE_DPMS_OFF;
15612 connector->base.encoder = NULL;
15613 }
15614 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015615 connector->base.base.id, connector->base.name,
15616 enableddisabled(connector->base.encoder));
Daniel Vetter24929352012-07-02 20:28:59 +020015617 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015618 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015619
15620 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015621 struct intel_crtc_state *crtc_state =
15622 to_intel_crtc_state(crtc->base.state);
Ville Syrjäläd305e062017-08-30 21:57:03 +030015623 int min_cdclk = 0;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015624
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015625 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015626 if (crtc_state->base.active) {
15627 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
Ville Syrjäläbd4cd032018-04-26 19:30:15 +030015628 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15629 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015630 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015631 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15632
15633 /*
15634 * The initial mode needs to be set in order to keep
15635 * the atomic core happy. It wants a valid mode if the
15636 * crtc's enabled, so we do the above call.
15637 *
Daniel Vetter7800fb62016-12-19 09:24:23 +010015638 * But we don't set all the derived state fully, hence
15639 * set a flag to indicate that a full recalculation is
15640 * needed on the next commit.
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015641 */
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015642 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
Ville Syrjälä9eca68322015-09-10 18:59:10 +030015643
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020015644 intel_crtc_compute_pixel_rate(crtc_state);
15645
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015646 if (dev_priv->display.modeset_calc_cdclk) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030015647 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015648 if (WARN_ON(min_cdclk < 0))
15649 min_cdclk = 0;
15650 }
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015651
Daniel Vetter5caa0fe2017-05-09 16:03:29 +020015652 drm_calc_timestamping_constants(&crtc->base,
15653 &crtc_state->base.adjusted_mode);
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020015654 update_scanline_offset(crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015655 }
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020015656
Ville Syrjäläd305e062017-08-30 21:57:03 +030015657 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030015658 dev_priv->min_voltage_level[crtc->pipe] =
15659 crtc_state->min_voltage_level;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015660
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015661 intel_pipe_config_sanity_check(dev_priv, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015662 }
Daniel Vetter30e984d2013-06-05 13:34:17 +020015663}
15664
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015665static void
15666get_encoder_power_domains(struct drm_i915_private *dev_priv)
15667{
15668 struct intel_encoder *encoder;
15669
15670 for_each_intel_encoder(&dev_priv->drm, encoder) {
15671 u64 get_domains;
15672 enum intel_display_power_domain domain;
Imre Deak52528052018-06-21 21:44:49 +030015673 struct intel_crtc_state *crtc_state;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015674
15675 if (!encoder->get_power_domains)
15676 continue;
15677
Imre Deak52528052018-06-21 21:44:49 +030015678 /*
Imre Deakb79ebe72018-07-05 15:26:54 +030015679 * MST-primary and inactive encoders don't have a crtc state
15680 * and neither of these require any power domain references.
Imre Deak52528052018-06-21 21:44:49 +030015681 */
Imre Deakb79ebe72018-07-05 15:26:54 +030015682 if (!encoder->base.crtc)
15683 continue;
Imre Deak52528052018-06-21 21:44:49 +030015684
Imre Deakb79ebe72018-07-05 15:26:54 +030015685 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
Imre Deak52528052018-06-21 21:44:49 +030015686 get_domains = encoder->get_power_domains(encoder, crtc_state);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015687 for_each_power_domain(domain, get_domains)
15688 intel_display_power_get(dev_priv, domain);
15689 }
15690}
15691
Rodrigo Vividf49ec82017-11-10 16:03:19 -080015692static void intel_early_display_was(struct drm_i915_private *dev_priv)
15693{
15694 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15695 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15696 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15697 DARBF_GATING_DIS);
15698
15699 if (IS_HASWELL(dev_priv)) {
15700 /*
15701 * WaRsPkgCStateDisplayPMReq:hsw
15702 * System hang if this isn't done before disabling all planes!
15703 */
15704 I915_WRITE(CHICKEN_PAR1_1,
15705 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15706 }
15707}
15708
Ville Syrjälä3aefb672018-11-08 16:36:35 +020015709static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
15710 enum port port, i915_reg_t hdmi_reg)
15711{
15712 u32 val = I915_READ(hdmi_reg);
15713
15714 if (val & SDVO_ENABLE ||
15715 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
15716 return;
15717
15718 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
15719 port_name(port));
15720
15721 val &= ~SDVO_PIPE_SEL_MASK;
15722 val |= SDVO_PIPE_SEL(PIPE_A);
15723
15724 I915_WRITE(hdmi_reg, val);
15725}
15726
15727static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
15728 enum port port, i915_reg_t dp_reg)
15729{
15730 u32 val = I915_READ(dp_reg);
15731
15732 if (val & DP_PORT_EN ||
15733 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
15734 return;
15735
15736 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
15737 port_name(port));
15738
15739 val &= ~DP_PIPE_SEL_MASK;
15740 val |= DP_PIPE_SEL(PIPE_A);
15741
15742 I915_WRITE(dp_reg, val);
15743}
15744
15745static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
15746{
15747 /*
15748 * The BIOS may select transcoder B on some of the PCH
15749 * ports even it doesn't enable the port. This would trip
15750 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
15751 * Sanitize the transcoder select bits to prevent that. We
15752 * assume that the BIOS never actually enabled the port,
15753 * because if it did we'd actually have to toggle the port
15754 * on and back off to make the transcoder A select stick
15755 * (see. intel_dp_link_down(), intel_disable_hdmi(),
15756 * intel_disable_sdvo()).
15757 */
15758 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
15759 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
15760 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
15761
15762 /* PCH SDVOB multiplex with HDMIB */
15763 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
15764 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
15765 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
15766}
15767
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015768/* Scan out the current hw modeset state,
15769 * and sanitizes it to the current state
15770 */
15771static void
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015772intel_modeset_setup_hw_state(struct drm_device *dev,
15773 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter30e984d2013-06-05 13:34:17 +020015774{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015775 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter30e984d2013-06-05 13:34:17 +020015776 struct intel_crtc *crtc;
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015777 struct intel_crtc_state *crtc_state;
Daniel Vetter30e984d2013-06-05 13:34:17 +020015778 struct intel_encoder *encoder;
Daniel Vetter35c95372013-07-17 06:55:04 +020015779 int i;
Daniel Vetter30e984d2013-06-05 13:34:17 +020015780
Imre Deak2cd9a682018-08-16 15:37:57 +030015781 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15782
Rodrigo Vividf49ec82017-11-10 16:03:19 -080015783 intel_early_display_was(dev_priv);
Daniel Vetter30e984d2013-06-05 13:34:17 +020015784 intel_modeset_readout_hw_state(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015785
15786 /* HW state is read out, now we need to sanitize this mess. */
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015787 get_encoder_power_domains(dev_priv);
15788
Ville Syrjälä3aefb672018-11-08 16:36:35 +020015789 if (HAS_PCH_IBX(dev_priv))
15790 ibx_sanitize_pch_ports(dev_priv);
15791
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015792 /*
15793 * intel_sanitize_plane_mapping() may need to do vblank
15794 * waits, so we need vblank interrupts restored beforehand.
15795 */
15796 for_each_intel_crtc(&dev_priv->drm, crtc) {
15797 drm_crtc_vblank_reset(&crtc->base);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015798
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015799 if (crtc->base.state->active)
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015800 drm_crtc_vblank_on(&crtc->base);
Daniel Vetter24929352012-07-02 20:28:59 +020015801 }
15802
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015803 intel_sanitize_plane_mapping(dev_priv);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015804
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015805 for_each_intel_encoder(dev, encoder)
15806 intel_sanitize_encoder(encoder);
15807
15808 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015809 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015810 intel_sanitize_crtc(crtc, ctx);
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015811 intel_dump_pipe_config(crtc, crtc_state,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +020015812 "[setup_hw_state]");
Daniel Vetter24929352012-07-02 20:28:59 +020015813 }
Daniel Vetter9a935852012-07-05 22:34:27 +020015814
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020015815 intel_modeset_update_connector_atomic_state(dev);
15816
Daniel Vetter35c95372013-07-17 06:55:04 +020015817 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15818 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15819
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +010015820 if (!pll->on || pll->active_mask)
Daniel Vetter35c95372013-07-17 06:55:04 +020015821 continue;
15822
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015823 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15824 pll->info->name);
Daniel Vetter35c95372013-07-17 06:55:04 +020015825
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015826 pll->info->funcs->disable(dev_priv, pll);
Daniel Vetter35c95372013-07-17 06:55:04 +020015827 pll->on = false;
15828 }
15829
Ville Syrjälä04548cb2017-04-21 21:14:29 +030015830 if (IS_G4X(dev_priv)) {
15831 g4x_wm_get_hw_state(dev);
15832 g4x_wm_sanitize(dev_priv);
15833 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä6eb1a682015-06-24 22:00:03 +030015834 vlv_wm_get_hw_state(dev);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015835 vlv_wm_sanitize(dev_priv);
Rodrigo Vivia029fa42017-08-09 13:52:48 -070015836 } else if (INTEL_GEN(dev_priv) >= 9) {
Pradeep Bhat30789992014-11-04 17:06:45 +000015837 skl_wm_get_hw_state(dev);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015838 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjälä243e6a42013-10-14 14:55:24 +030015839 ilk_wm_get_hw_state(dev);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015840 }
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015841
15842 for_each_intel_crtc(dev, crtc) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020015843 u64 put_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015844
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015845 crtc_state = to_intel_crtc_state(crtc->base.state);
15846 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015847 if (WARN_ON(put_domains))
15848 modeset_put_power_domains(dev_priv, put_domains);
15849 }
Imre Deak2cd9a682018-08-16 15:37:57 +030015850
15851 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni010cf732016-01-19 11:35:48 -020015852
15853 intel_fbc_init_pipe_state(dev_priv);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015854}
Ville Syrjälä7d0bc1e2013-09-16 17:38:33 +030015855
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015856void intel_display_resume(struct drm_device *dev)
15857{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015858 struct drm_i915_private *dev_priv = to_i915(dev);
15859 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15860 struct drm_modeset_acquire_ctx ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015861 int ret;
Daniel Vetterf30da182013-04-11 20:22:50 +020015862
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015863 dev_priv->modeset_restore_state = NULL;
Maarten Lankhorst73974892016-08-05 23:28:27 +030015864 if (state)
15865 state->acquire_ctx = &ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015866
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015867 drm_modeset_acquire_init(&ctx, 0);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015868
Maarten Lankhorst73974892016-08-05 23:28:27 +030015869 while (1) {
15870 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15871 if (ret != -EDEADLK)
15872 break;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015873
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015874 drm_modeset_backoff(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015875 }
15876
Maarten Lankhorst73974892016-08-05 23:28:27 +030015877 if (!ret)
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010015878 ret = __intel_display_resume(dev, state, &ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +030015879
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +053015880 intel_enable_ipc(dev_priv);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015881 drm_modeset_drop_locks(&ctx);
15882 drm_modeset_acquire_fini(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015883
Chris Wilson08536952016-10-14 13:18:18 +010015884 if (ret)
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015885 DRM_ERROR("Restoring old state failed with %i\n", ret);
Chris Wilson3c5e37f2017-01-15 12:58:25 +000015886 if (state)
15887 drm_atomic_state_put(state);
Chris Wilson2c7111d2011-03-29 10:40:27 +010015888}
15889
Manasi Navare886c6b82017-10-26 14:52:00 -070015890static void intel_hpd_poll_fini(struct drm_device *dev)
15891{
15892 struct intel_connector *connector;
15893 struct drm_connector_list_iter conn_iter;
15894
Chris Wilson448aa912017-11-28 11:01:47 +000015895 /* Kill all the work that may have been queued by hpd. */
Manasi Navare886c6b82017-10-26 14:52:00 -070015896 drm_connector_list_iter_begin(dev, &conn_iter);
15897 for_each_intel_connector_iter(connector, &conn_iter) {
15898 if (connector->modeset_retry_work.func)
15899 cancel_work_sync(&connector->modeset_retry_work);
Ramalingam Cd3dacc72018-10-29 15:15:46 +053015900 if (connector->hdcp.shim) {
15901 cancel_delayed_work_sync(&connector->hdcp.check_work);
15902 cancel_work_sync(&connector->hdcp.prop_work);
Sean Paulee5e5e72018-01-08 14:55:39 -050015903 }
Manasi Navare886c6b82017-10-26 14:52:00 -070015904 }
15905 drm_connector_list_iter_end(&conn_iter);
15906}
15907
Jesse Barnes79e53942008-11-07 14:24:08 -080015908void intel_modeset_cleanup(struct drm_device *dev)
15909{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015910 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes652c3932009-08-17 13:31:43 -070015911
Chris Wilson8bcf9f72018-07-10 10:44:20 +010015912 flush_workqueue(dev_priv->modeset_wq);
15913
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015914 flush_work(&dev_priv->atomic_helper.free_work);
15915 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15916
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015917 /*
15918 * Interrupts and polling as the first thing to avoid creating havoc.
Imre Deak2eb52522014-11-19 15:30:05 +020015919 * Too much stuff here (turning of connectors, ...) would
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015920 * experience fancy races otherwise.
15921 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +020015922 intel_irq_uninstall(dev_priv);
Jesse Barneseb21b922014-06-20 11:57:33 -070015923
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015924 /*
15925 * Due to the hpd irq storm handling the hotplug work can re-arm the
15926 * poll handlers. Hence disable polling after hpd handling is shut down.
15927 */
Manasi Navare886c6b82017-10-26 14:52:00 -070015928 intel_hpd_poll_fini(dev);
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015929
Daniel Vetter4f256d82017-07-15 00:46:55 +020015930 /* poll work can call into fbdev, hence clean that up afterwards */
15931 intel_fbdev_fini(dev_priv);
15932
Jesse Barnes723bfd72010-10-07 16:01:13 -070015933 intel_unregister_dsm_handler();
15934
Paulo Zanonic937ab3e52016-01-19 11:35:46 -020015935 intel_fbc_global_disable(dev_priv);
Kristian Høgsberg69341a52009-11-11 12:19:17 -050015936
Chris Wilson1630fe72011-07-08 12:22:42 +010015937 /* flush any delayed tasks or pending work */
15938 flush_scheduled_work();
15939
Jesse Barnes79e53942008-11-07 14:24:08 -080015940 drm_mode_config_cleanup(dev);
Daniel Vetter4d7bb012012-12-18 15:24:37 +010015941
José Roberto de Souza58db08a72018-11-07 16:16:47 -080015942 intel_overlay_cleanup(dev_priv);
Imre Deakae484342014-03-31 15:10:44 +030015943
Tvrtko Ursulin40196442016-12-01 14:16:42 +000015944 intel_teardown_gmbus(dev_priv);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015945
15946 destroy_workqueue(dev_priv->modeset_wq);
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080015947
15948 intel_fbc_cleanup_cfb(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080015949}
15950
Dave Airlie28d52042009-09-21 14:33:58 +100015951/*
15952 * set vga decode state - true == enable VGA decode
15953 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000015954int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
Dave Airlie28d52042009-09-21 14:33:58 +100015955{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000015956 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
Dave Airlie28d52042009-09-21 14:33:58 +100015957 u16 gmch_ctrl;
15958
Chris Wilson75fa0412014-02-07 18:37:02 -020015959 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15960 DRM_ERROR("failed to read control word\n");
15961 return -EIO;
15962 }
15963
Chris Wilsonc0cc8a52014-02-07 18:37:03 -020015964 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15965 return 0;
15966
Dave Airlie28d52042009-09-21 14:33:58 +100015967 if (state)
15968 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15969 else
15970 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
Chris Wilson75fa0412014-02-07 18:37:02 -020015971
15972 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15973 DRM_ERROR("failed to write control word\n");
15974 return -EIO;
15975 }
15976
Dave Airlie28d52042009-09-21 14:33:58 +100015977 return 0;
15978}
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015979
Chris Wilson98a2f412016-10-12 10:05:18 +010015980#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15981
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015982struct intel_display_error_state {
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030015983
15984 u32 power_well_driver;
15985
Chris Wilson63b66e52013-08-08 15:12:06 +020015986 int num_transcoders;
15987
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015988 struct intel_cursor_error_state {
15989 u32 control;
15990 u32 position;
15991 u32 base;
15992 u32 size;
Damien Lespiau52331302012-08-15 19:23:25 +010015993 } cursor[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015994
15995 struct intel_pipe_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020015996 bool power_domain_on;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015997 u32 source;
Imre Deakf301b1e12014-04-18 15:55:04 +030015998 u32 stat;
Damien Lespiau52331302012-08-15 19:23:25 +010015999 } pipe[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016000
16001 struct intel_plane_error_state {
16002 u32 control;
16003 u32 stride;
16004 u32 size;
16005 u32 pos;
16006 u32 addr;
16007 u32 surface;
16008 u32 tile_offset;
Damien Lespiau52331302012-08-15 19:23:25 +010016009 } plane[I915_MAX_PIPES];
Chris Wilson63b66e52013-08-08 15:12:06 +020016010
16011 struct intel_transcoder_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016012 bool power_domain_on;
Chris Wilson63b66e52013-08-08 15:12:06 +020016013 enum transcoder cpu_transcoder;
16014
16015 u32 conf;
16016
16017 u32 htotal;
16018 u32 hblank;
16019 u32 hsync;
16020 u32 vtotal;
16021 u32 vblank;
16022 u32 vsync;
16023 } transcoder[4];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016024};
16025
16026struct intel_display_error_state *
Chris Wilsonc0336662016-05-06 15:40:21 +010016027intel_display_capture_error_state(struct drm_i915_private *dev_priv)
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016028{
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016029 struct intel_display_error_state *error;
Chris Wilson63b66e52013-08-08 15:12:06 +020016030 int transcoders[] = {
16031 TRANSCODER_A,
16032 TRANSCODER_B,
16033 TRANSCODER_C,
16034 TRANSCODER_EDP,
16035 };
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016036 int i;
16037
Chris Wilsonc0336662016-05-06 15:40:21 +010016038 if (INTEL_INFO(dev_priv)->num_pipes == 0)
Chris Wilson63b66e52013-08-08 15:12:06 +020016039 return NULL;
16040
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016041 error = kzalloc(sizeof(*error), GFP_ATOMIC);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016042 if (error == NULL)
16043 return NULL;
16044
Chris Wilsonc0336662016-05-06 15:40:21 +010016045 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Imre Deak75e39682018-08-06 12:58:39 +030016046 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016047
Damien Lespiau055e3932014-08-18 13:49:10 +010016048 for_each_pipe(dev_priv, i) {
Imre Deakddf9c532013-11-27 22:02:02 +020016049 error->pipe[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016050 __intel_display_power_is_enabled(dev_priv,
16051 POWER_DOMAIN_PIPE(i));
Imre Deakddf9c532013-11-27 22:02:02 +020016052 if (!error->pipe[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016053 continue;
16054
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030016055 error->cursor[i].control = I915_READ(CURCNTR(i));
16056 error->cursor[i].position = I915_READ(CURPOS(i));
16057 error->cursor[i].base = I915_READ(CURBASE(i));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016058
16059 error->plane[i].control = I915_READ(DSPCNTR(i));
16060 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016061 if (INTEL_GEN(dev_priv) <= 3) {
Paulo Zanoni51889b32013-03-06 20:03:13 -030016062 error->plane[i].size = I915_READ(DSPSIZE(i));
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016063 error->plane[i].pos = I915_READ(DSPPOS(i));
16064 }
Chris Wilsonc0336662016-05-06 15:40:21 +010016065 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Paulo Zanonica291362013-03-06 20:03:14 -030016066 error->plane[i].addr = I915_READ(DSPADDR(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016067 if (INTEL_GEN(dev_priv) >= 4) {
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016068 error->plane[i].surface = I915_READ(DSPSURF(i));
16069 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16070 }
16071
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016072 error->pipe[i].source = I915_READ(PIPESRC(i));
Imre Deakf301b1e12014-04-18 15:55:04 +030016073
Chris Wilsonc0336662016-05-06 15:40:21 +010016074 if (HAS_GMCH_DISPLAY(dev_priv))
Imre Deakf301b1e12014-04-18 15:55:04 +030016075 error->pipe[i].stat = I915_READ(PIPESTAT(i));
Chris Wilson63b66e52013-08-08 15:12:06 +020016076 }
16077
Jani Nikula4d1de972016-03-18 17:05:42 +020016078 /* Note: this does not include DSI transcoders. */
Chris Wilsonc0336662016-05-06 15:40:21 +010016079 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +030016080 if (HAS_DDI(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016081 error->num_transcoders++; /* Account for eDP. */
16082
16083 for (i = 0; i < error->num_transcoders; i++) {
16084 enum transcoder cpu_transcoder = transcoders[i];
16085
Imre Deakddf9c532013-11-27 22:02:02 +020016086 error->transcoder[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016087 __intel_display_power_is_enabled(dev_priv,
Paulo Zanoni38cc1da2013-12-20 15:09:41 -020016088 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016089 if (!error->transcoder[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016090 continue;
16091
Chris Wilson63b66e52013-08-08 15:12:06 +020016092 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16093
16094 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16095 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16096 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16097 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16098 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16099 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16100 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016101 }
16102
16103 return error;
16104}
16105
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016106#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16107
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016108void
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016109intel_display_print_error_state(struct drm_i915_error_state_buf *m,
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016110 struct intel_display_error_state *error)
16111{
Chris Wilson5a4c6f12017-02-14 16:46:11 +000016112 struct drm_i915_private *dev_priv = m->i915;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016113 int i;
16114
Chris Wilson63b66e52013-08-08 15:12:06 +020016115 if (!error)
16116 return;
16117
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000016118 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
Tvrtko Ursulin86527442016-10-13 11:03:00 +010016119 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016120 err_printf(m, "PWR_WELL_CTL2: %08x\n",
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016121 error->power_well_driver);
Damien Lespiau055e3932014-08-18 13:49:10 +010016122 for_each_pipe(dev_priv, i) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016123 err_printf(m, "Pipe [%d]:\n", i);
Imre Deakddf9c532013-11-27 22:02:02 +020016124 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016125 onoff(error->pipe[i].power_domain_on));
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016126 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
Imre Deakf301b1e12014-04-18 15:55:04 +030016127 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016128
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016129 err_printf(m, "Plane [%d]:\n", i);
16130 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16131 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016132 if (INTEL_GEN(dev_priv) <= 3) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016133 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16134 err_printf(m, " POS: %08x\n", error->plane[i].pos);
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016135 }
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010016136 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016137 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016138 if (INTEL_GEN(dev_priv) >= 4) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016139 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16140 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016141 }
16142
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016143 err_printf(m, "Cursor [%d]:\n", i);
16144 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16145 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16146 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016147 }
Chris Wilson63b66e52013-08-08 15:12:06 +020016148
16149 for (i = 0; i < error->num_transcoders; i++) {
Jani Nikulada205632016-03-15 21:51:10 +020016150 err_printf(m, "CPU transcoder: %s\n",
Chris Wilson63b66e52013-08-08 15:12:06 +020016151 transcoder_name(error->transcoder[i].cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016152 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016153 onoff(error->transcoder[i].power_domain_on));
Chris Wilson63b66e52013-08-08 15:12:06 +020016154 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16155 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16156 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16157 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16158 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16159 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16160 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
16161 }
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016162}
Chris Wilson98a2f412016-10-12 10:05:18 +010016163
16164#endif