blob: 2802674c94efdc25060776a1cb330130814a95fb [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/i915_drm.h>
Xi Ruoyao319c1d42015-03-12 20:16:32 +080035#include <drm/drm_atomic.h>
Matt Roperc196e1d2015-01-21 16:35:48 -080036#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drm_dp_helper.h>
38#include <drm/drm_crtc_helper.h>
Matt Roper465c1202014-05-29 08:06:54 -070039#include <drm/drm_plane_helper.h>
40#include <drm/drm_rect.h>
Daniel Vetter72fdb402018-09-05 15:57:11 +020041#include <drm/drm_atomic_uapi.h>
Lu Baoludaedaa32018-11-12 14:40:08 +080042#include <linux/intel-iommu.h>
Alex Goinsfd8e0582015-11-25 18:43:38 -080043#include <linux/reservation.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080044
Chris Wilson9f588922019-01-16 15:33:04 +000045#include "intel_drv.h"
46#include "intel_dsi.h"
47#include "intel_frontbuffer.h"
48
49#include "i915_drv.h"
50#include "i915_gem_clflush.h"
51#include "i915_reset.h"
52#include "i915_trace.h"
53
Matt Roper465c1202014-05-29 08:06:54 -070054/* Primary plane formats for gen <= 3 */
Jani Nikulaba3f4d02019-01-18 14:01:23 +020055static const u32 i8xx_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010056 DRM_FORMAT_C8,
57 DRM_FORMAT_RGB565,
Matt Roper465c1202014-05-29 08:06:54 -070058 DRM_FORMAT_XRGB1555,
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010059 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070060};
61
62/* Primary plane formats for gen >= 4 */
Jani Nikulaba3f4d02019-01-18 14:01:23 +020063static const u32 i965_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010064 DRM_FORMAT_C8,
65 DRM_FORMAT_RGB565,
66 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070067 DRM_FORMAT_XBGR8888,
Damien Lespiau6c0fd452015-05-19 12:29:16 +010068 DRM_FORMAT_XRGB2101010,
69 DRM_FORMAT_XBGR2101010,
70};
71
Jani Nikulaba3f4d02019-01-18 14:01:23 +020072static const u64 i9xx_format_modifiers[] = {
Ben Widawsky714244e2017-08-01 09:58:16 -070073 I915_FORMAT_MOD_X_TILED,
74 DRM_FORMAT_MOD_LINEAR,
75 DRM_FORMAT_MOD_INVALID
76};
77
Matt Roper3d7d6512014-06-10 08:28:13 -070078/* Cursor formats */
Jani Nikulaba3f4d02019-01-18 14:01:23 +020079static const u32 intel_cursor_formats[] = {
Matt Roper3d7d6512014-06-10 08:28:13 -070080 DRM_FORMAT_ARGB8888,
81};
82
Jani Nikulaba3f4d02019-01-18 14:01:23 +020083static const u64 cursor_format_modifiers[] = {
Ben Widawsky714244e2017-08-01 09:58:16 -070084 DRM_FORMAT_MOD_LINEAR,
85 DRM_FORMAT_MOD_INVALID
86};
87
Jesse Barnesf1f644d2013-06-27 00:39:25 +030088static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020089 struct intel_crtc_state *pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +030090static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020091 struct intel_crtc_state *pipe_config);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030092
Chris Wilson24dbf512017-02-15 10:59:18 +000093static int intel_framebuffer_init(struct intel_framebuffer *ifb,
94 struct drm_i915_gem_object *obj,
95 struct drm_mode_fb_cmd2 *mode_cmd);
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +020096static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
97static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
Maarten Lankhorst4c354752018-10-11 12:04:49 +020098static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
99 const struct intel_link_m_n *m_n,
100 const struct intel_link_m_n *m2_n2);
Maarten Lankhorstfdf73512018-10-04 11:45:52 +0200101static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
102static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
103static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
104static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200105static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200106 const struct intel_crtc_state *pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200107static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200108 const struct intel_crtc_state *pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200109static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
110static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
Nabendu Maiti1c74eea2016-11-29 11:23:14 +0530111static void intel_crtc_init_scalers(struct intel_crtc *crtc,
112 struct intel_crtc_state *crtc_state);
Maarten Lankhorstb2562712018-10-04 11:45:53 +0200113static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
114static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
115static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +0300116static void intel_modeset_setup_hw_state(struct drm_device *dev,
117 struct drm_modeset_acquire_ctx *ctx);
Ville Syrjälä2622a082016-03-09 19:07:26 +0200118static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
Damien Lespiaue7457a92013-08-08 22:28:59 +0100119
Ma Lingd4906092009-03-18 20:13:27 +0800120struct intel_limit {
Ander Conselvan de Oliveira4c5def92016-05-04 12:11:58 +0300121 struct {
122 int min, max;
123 } dot, vco, n, m, m1, m2, p, p1;
124
125 struct {
126 int dot_limit;
127 int p2_slow, p2_fast;
128 } p2;
Ma Lingd4906092009-03-18 20:13:27 +0800129};
Jesse Barnes79e53942008-11-07 14:24:08 -0800130
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300131/* returns HPLL frequency in kHz */
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200132int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300133{
134 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
135
136 /* Obtain SKU information */
137 mutex_lock(&dev_priv->sb_lock);
138 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
139 CCK_FUSE_HPLL_FREQ_MASK;
140 mutex_unlock(&dev_priv->sb_lock);
141
142 return vco_freq[hpll_freq] * 1000;
143}
144
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200145int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
146 const char *name, u32 reg, int ref_freq)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300147{
148 u32 val;
149 int divider;
150
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300151 mutex_lock(&dev_priv->sb_lock);
152 val = vlv_cck_read(dev_priv, reg);
153 mutex_unlock(&dev_priv->sb_lock);
154
155 divider = val & CCK_FREQUENCY_VALUES;
156
157 WARN((val & CCK_FREQUENCY_STATUS) !=
158 (divider << CCK_FREQUENCY_STATUS_SHIFT),
159 "%s change in progress\n", name);
160
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200161 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
162}
163
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +0200164int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
165 const char *name, u32 reg)
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200166{
167 if (dev_priv->hpll_freq == 0)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200168 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200169
170 return vlv_get_cck_clock(dev_priv, name, reg,
171 dev_priv->hpll_freq);
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300172}
173
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300174static void intel_update_czclk(struct drm_i915_private *dev_priv)
175{
Wayne Boyer666a4532015-12-09 12:29:35 -0800176 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300177 return;
178
179 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
180 CCK_CZ_CLOCK_CONTROL);
181
182 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
183}
184
Chris Wilson021357a2010-09-07 20:54:59 +0100185static inline u32 /* units of 100MHz */
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200186intel_fdi_link_freq(struct drm_i915_private *dev_priv,
187 const struct intel_crtc_state *pipe_config)
Chris Wilson021357a2010-09-07 20:54:59 +0100188{
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200189 if (HAS_DDI(dev_priv))
190 return pipe_config->port_clock; /* SPLL */
Ville Syrjäläe3b247d2016-02-17 21:41:09 +0200191 else
Chris Wilson58ecd9d2017-11-05 13:49:05 +0000192 return dev_priv->fdi_pll_freq;
Chris Wilson021357a2010-09-07 20:54:59 +0100193}
194
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300195static const struct intel_limit intel_limits_i8xx_dac = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400196 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200197 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200198 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400199 .m = { .min = 96, .max = 140 },
200 .m1 = { .min = 18, .max = 26 },
201 .m2 = { .min = 6, .max = 16 },
202 .p = { .min = 4, .max = 128 },
203 .p1 = { .min = 2, .max = 33 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700204 .p2 = { .dot_limit = 165000,
205 .p2_slow = 4, .p2_fast = 2 },
Keith Packarde4b36692009-06-05 19:22:17 -0700206};
207
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300208static const struct intel_limit intel_limits_i8xx_dvo = {
Daniel Vetter5d536e22013-07-06 12:52:06 +0200209 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200210 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200211 .n = { .min = 2, .max = 16 },
Daniel Vetter5d536e22013-07-06 12:52:06 +0200212 .m = { .min = 96, .max = 140 },
213 .m1 = { .min = 18, .max = 26 },
214 .m2 = { .min = 6, .max = 16 },
215 .p = { .min = 4, .max = 128 },
216 .p1 = { .min = 2, .max = 33 },
217 .p2 = { .dot_limit = 165000,
218 .p2_slow = 4, .p2_fast = 4 },
219};
220
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300221static const struct intel_limit intel_limits_i8xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400222 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200223 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200224 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400225 .m = { .min = 96, .max = 140 },
226 .m1 = { .min = 18, .max = 26 },
227 .m2 = { .min = 6, .max = 16 },
228 .p = { .min = 4, .max = 128 },
229 .p1 = { .min = 1, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700230 .p2 = { .dot_limit = 165000,
231 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700232};
Eric Anholt273e27c2011-03-30 13:01:10 -0700233
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300234static const struct intel_limit intel_limits_i9xx_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400235 .dot = { .min = 20000, .max = 400000 },
236 .vco = { .min = 1400000, .max = 2800000 },
237 .n = { .min = 1, .max = 6 },
238 .m = { .min = 70, .max = 120 },
Patrik Jakobsson4f7dfb62013-02-13 22:20:22 +0100239 .m1 = { .min = 8, .max = 18 },
240 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400241 .p = { .min = 5, .max = 80 },
242 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700243 .p2 = { .dot_limit = 200000,
244 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700245};
246
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300247static const struct intel_limit intel_limits_i9xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400248 .dot = { .min = 20000, .max = 400000 },
249 .vco = { .min = 1400000, .max = 2800000 },
250 .n = { .min = 1, .max = 6 },
251 .m = { .min = 70, .max = 120 },
Patrik Jakobsson53a7d2d2013-02-13 22:20:21 +0100252 .m1 = { .min = 8, .max = 18 },
253 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400254 .p = { .min = 7, .max = 98 },
255 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700256 .p2 = { .dot_limit = 112000,
257 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700258};
259
Eric Anholt273e27c2011-03-30 13:01:10 -0700260
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300261static const struct intel_limit intel_limits_g4x_sdvo = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700262 .dot = { .min = 25000, .max = 270000 },
263 .vco = { .min = 1750000, .max = 3500000},
264 .n = { .min = 1, .max = 4 },
265 .m = { .min = 104, .max = 138 },
266 .m1 = { .min = 17, .max = 23 },
267 .m2 = { .min = 5, .max = 11 },
268 .p = { .min = 10, .max = 30 },
269 .p1 = { .min = 1, .max = 3},
270 .p2 = { .dot_limit = 270000,
271 .p2_slow = 10,
272 .p2_fast = 10
Ma Ling044c7c42009-03-18 20:13:23 +0800273 },
Keith Packarde4b36692009-06-05 19:22:17 -0700274};
275
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300276static const struct intel_limit intel_limits_g4x_hdmi = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700277 .dot = { .min = 22000, .max = 400000 },
278 .vco = { .min = 1750000, .max = 3500000},
279 .n = { .min = 1, .max = 4 },
280 .m = { .min = 104, .max = 138 },
281 .m1 = { .min = 16, .max = 23 },
282 .m2 = { .min = 5, .max = 11 },
283 .p = { .min = 5, .max = 80 },
284 .p1 = { .min = 1, .max = 8},
285 .p2 = { .dot_limit = 165000,
286 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700287};
288
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300289static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700290 .dot = { .min = 20000, .max = 115000 },
291 .vco = { .min = 1750000, .max = 3500000 },
292 .n = { .min = 1, .max = 3 },
293 .m = { .min = 104, .max = 138 },
294 .m1 = { .min = 17, .max = 23 },
295 .m2 = { .min = 5, .max = 11 },
296 .p = { .min = 28, .max = 112 },
297 .p1 = { .min = 2, .max = 8 },
298 .p2 = { .dot_limit = 0,
299 .p2_slow = 14, .p2_fast = 14
Ma Ling044c7c42009-03-18 20:13:23 +0800300 },
Keith Packarde4b36692009-06-05 19:22:17 -0700301};
302
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300303static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700304 .dot = { .min = 80000, .max = 224000 },
305 .vco = { .min = 1750000, .max = 3500000 },
306 .n = { .min = 1, .max = 3 },
307 .m = { .min = 104, .max = 138 },
308 .m1 = { .min = 17, .max = 23 },
309 .m2 = { .min = 5, .max = 11 },
310 .p = { .min = 14, .max = 42 },
311 .p1 = { .min = 2, .max = 6 },
312 .p2 = { .dot_limit = 0,
313 .p2_slow = 7, .p2_fast = 7
Ma Ling044c7c42009-03-18 20:13:23 +0800314 },
Keith Packarde4b36692009-06-05 19:22:17 -0700315};
316
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300317static const struct intel_limit intel_limits_pineview_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400318 .dot = { .min = 20000, .max = 400000},
319 .vco = { .min = 1700000, .max = 3500000 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700320 /* Pineview's Ncounter is a ring counter */
Akshay Joshi0206e352011-08-16 15:34:10 -0400321 .n = { .min = 3, .max = 6 },
322 .m = { .min = 2, .max = 256 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700323 /* Pineview only has one combined m divider, which we treat as m2. */
Akshay Joshi0206e352011-08-16 15:34:10 -0400324 .m1 = { .min = 0, .max = 0 },
325 .m2 = { .min = 0, .max = 254 },
326 .p = { .min = 5, .max = 80 },
327 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700328 .p2 = { .dot_limit = 200000,
329 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700330};
331
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300332static const struct intel_limit intel_limits_pineview_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400333 .dot = { .min = 20000, .max = 400000 },
334 .vco = { .min = 1700000, .max = 3500000 },
335 .n = { .min = 3, .max = 6 },
336 .m = { .min = 2, .max = 256 },
337 .m1 = { .min = 0, .max = 0 },
338 .m2 = { .min = 0, .max = 254 },
339 .p = { .min = 7, .max = 112 },
340 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700341 .p2 = { .dot_limit = 112000,
342 .p2_slow = 14, .p2_fast = 14 },
Keith Packarde4b36692009-06-05 19:22:17 -0700343};
344
Eric Anholt273e27c2011-03-30 13:01:10 -0700345/* Ironlake / Sandybridge
346 *
347 * We calculate clock using (register_value + 2) for N/M1/M2, so here
348 * the range value for them is (actual_value - 2).
349 */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300350static const struct intel_limit intel_limits_ironlake_dac = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700351 .dot = { .min = 25000, .max = 350000 },
352 .vco = { .min = 1760000, .max = 3510000 },
353 .n = { .min = 1, .max = 5 },
354 .m = { .min = 79, .max = 127 },
355 .m1 = { .min = 12, .max = 22 },
356 .m2 = { .min = 5, .max = 9 },
357 .p = { .min = 5, .max = 80 },
358 .p1 = { .min = 1, .max = 8 },
359 .p2 = { .dot_limit = 225000,
360 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700361};
362
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300363static const struct intel_limit intel_limits_ironlake_single_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700364 .dot = { .min = 25000, .max = 350000 },
365 .vco = { .min = 1760000, .max = 3510000 },
366 .n = { .min = 1, .max = 3 },
367 .m = { .min = 79, .max = 118 },
368 .m1 = { .min = 12, .max = 22 },
369 .m2 = { .min = 5, .max = 9 },
370 .p = { .min = 28, .max = 112 },
371 .p1 = { .min = 2, .max = 8 },
372 .p2 = { .dot_limit = 225000,
373 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800374};
375
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300376static const struct intel_limit intel_limits_ironlake_dual_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700377 .dot = { .min = 25000, .max = 350000 },
378 .vco = { .min = 1760000, .max = 3510000 },
379 .n = { .min = 1, .max = 3 },
380 .m = { .min = 79, .max = 127 },
381 .m1 = { .min = 12, .max = 22 },
382 .m2 = { .min = 5, .max = 9 },
383 .p = { .min = 14, .max = 56 },
384 .p1 = { .min = 2, .max = 8 },
385 .p2 = { .dot_limit = 225000,
386 .p2_slow = 7, .p2_fast = 7 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800387};
388
Eric Anholt273e27c2011-03-30 13:01:10 -0700389/* LVDS 100mhz refclk limits. */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300390static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700391 .dot = { .min = 25000, .max = 350000 },
392 .vco = { .min = 1760000, .max = 3510000 },
393 .n = { .min = 1, .max = 2 },
394 .m = { .min = 79, .max = 126 },
395 .m1 = { .min = 12, .max = 22 },
396 .m2 = { .min = 5, .max = 9 },
397 .p = { .min = 28, .max = 112 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400398 .p1 = { .min = 2, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700399 .p2 = { .dot_limit = 225000,
400 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800401};
402
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300403static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700404 .dot = { .min = 25000, .max = 350000 },
405 .vco = { .min = 1760000, .max = 3510000 },
406 .n = { .min = 1, .max = 3 },
407 .m = { .min = 79, .max = 126 },
408 .m1 = { .min = 12, .max = 22 },
409 .m2 = { .min = 5, .max = 9 },
410 .p = { .min = 14, .max = 42 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400411 .p1 = { .min = 2, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700412 .p2 = { .dot_limit = 225000,
413 .p2_slow = 7, .p2_fast = 7 },
Zhao Yakui45476682009-12-31 16:06:04 +0800414};
415
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300416static const struct intel_limit intel_limits_vlv = {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300417 /*
418 * These are the data rate limits (measured in fast clocks)
419 * since those are the strictest limits we have. The fast
420 * clock and actual rate limits are more relaxed, so checking
421 * them would make no difference.
422 */
423 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
Daniel Vetter75e53982013-04-18 21:10:43 +0200424 .vco = { .min = 4000000, .max = 6000000 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700425 .n = { .min = 1, .max = 7 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700426 .m1 = { .min = 2, .max = 3 },
427 .m2 = { .min = 11, .max = 156 },
Ville Syrjäläb99ab662013-09-24 21:26:26 +0300428 .p1 = { .min = 2, .max = 3 },
Ville Syrjälä5fdc9c492013-09-24 21:26:29 +0300429 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700430};
431
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300432static const struct intel_limit intel_limits_chv = {
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300433 /*
434 * These are the data rate limits (measured in fast clocks)
435 * since those are the strictest limits we have. The fast
436 * clock and actual rate limits are more relaxed, so checking
437 * them would make no difference.
438 */
439 .dot = { .min = 25000 * 5, .max = 540000 * 5},
Ville Syrjälä17fe1022015-02-26 21:01:52 +0200440 .vco = { .min = 4800000, .max = 6480000 },
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300441 .n = { .min = 1, .max = 1 },
442 .m1 = { .min = 2, .max = 2 },
443 .m2 = { .min = 24 << 22, .max = 175 << 22 },
444 .p1 = { .min = 2, .max = 4 },
445 .p2 = { .p2_slow = 1, .p2_fast = 14 },
446};
447
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300448static const struct intel_limit intel_limits_bxt = {
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200449 /* FIXME: find real dot limits */
450 .dot = { .min = 0, .max = INT_MAX },
Vandana Kannane6292552015-07-01 17:02:57 +0530451 .vco = { .min = 4800000, .max = 6700000 },
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200452 .n = { .min = 1, .max = 1 },
453 .m1 = { .min = 2, .max = 2 },
454 /* FIXME: find real m2 limits */
455 .m2 = { .min = 2 << 22, .max = 255 << 22 },
456 .p1 = { .min = 2, .max = 4 },
457 .p2 = { .p2_slow = 1, .p2_fast = 20 },
458};
459
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530460static void
461skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
462{
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530463 if (enable)
464 I915_WRITE(CLKGATE_DIS_PSL(pipe),
465 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
466 else
467 I915_WRITE(CLKGATE_DIS_PSL(pipe),
468 I915_READ(CLKGATE_DIS_PSL(pipe)) &
469 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
470}
471
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200472static bool
Maarten Lankhorst24f28452017-11-22 19:39:01 +0100473needs_modeset(const struct drm_crtc_state *state)
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200474{
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200475 return drm_atomic_crtc_needs_modeset(state);
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200476}
477
Imre Deakdccbea32015-06-22 23:35:51 +0300478/*
479 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
480 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
481 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
482 * The helpers' return value is the rate of the clock that is fed to the
483 * display engine's pipe which can be the above fast dot clock rate or a
484 * divided-down version of it.
485 */
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500486/* m1 is reserved as 0 in Pineview, n is a ring counter */
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300487static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800488{
Shaohua Li21778322009-02-23 15:19:16 +0800489 clock->m = clock->m2 + 2;
490 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200491 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300492 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300493 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
494 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300495
496 return clock->dot;
Shaohua Li21778322009-02-23 15:19:16 +0800497}
498
Jani Nikulaba3f4d02019-01-18 14:01:23 +0200499static u32 i9xx_dpll_compute_m(struct dpll *dpll)
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200500{
501 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
502}
503
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300504static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
Shaohua Li21778322009-02-23 15:19:16 +0800505{
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200506 clock->m = i9xx_dpll_compute_m(clock);
Jesse Barnes79e53942008-11-07 14:24:08 -0800507 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200508 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300509 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300510 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
511 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300512
513 return clock->dot;
Jesse Barnes79e53942008-11-07 14:24:08 -0800514}
515
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300516static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
Imre Deak589eca62015-06-22 23:35:50 +0300517{
518 clock->m = clock->m1 * clock->m2;
519 clock->p = clock->p1 * clock->p2;
520 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300521 return 0;
Imre Deak589eca62015-06-22 23:35:50 +0300522 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
523 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300524
525 return clock->dot / 5;
Imre Deak589eca62015-06-22 23:35:50 +0300526}
527
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300528int chv_calc_dpll_params(int refclk, struct dpll *clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300529{
530 clock->m = clock->m1 * clock->m2;
531 clock->p = clock->p1 * clock->p2;
532 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300533 return 0;
Jani Nikulaba3f4d02019-01-18 14:01:23 +0200534 clock->vco = DIV_ROUND_CLOSEST_ULL((u64)refclk * clock->m,
535 clock->n << 22);
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300536 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300537
538 return clock->dot / 5;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300539}
540
Jesse Barnes7c04d1d2009-02-23 15:36:40 -0800541#define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
Chris Wilsonc38c1452018-02-14 13:49:22 +0000542
543/*
Jesse Barnes79e53942008-11-07 14:24:08 -0800544 * Returns whether the given set of divisors are valid for a given refclk with
545 * the given connectors.
546 */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100547static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300548 const struct intel_limit *limit,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300549 const struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800550{
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300551 if (clock->n < limit->n.min || limit->n.max < clock->n)
552 INTELPllInvalid("n out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800553 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400554 INTELPllInvalid("p1 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800555 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
Akshay Joshi0206e352011-08-16 15:34:10 -0400556 INTELPllInvalid("m2 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800557 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400558 INTELPllInvalid("m1 out of range\n");
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300559
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100560 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200561 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300562 if (clock->m1 <= clock->m2)
563 INTELPllInvalid("m1 <= m2\n");
564
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100565 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200566 !IS_GEN9_LP(dev_priv)) {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300567 if (clock->p < limit->p.min || limit->p.max < clock->p)
568 INTELPllInvalid("p out of range\n");
569 if (clock->m < limit->m.min || limit->m.max < clock->m)
570 INTELPllInvalid("m out of range\n");
571 }
572
Jesse Barnes79e53942008-11-07 14:24:08 -0800573 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
Akshay Joshi0206e352011-08-16 15:34:10 -0400574 INTELPllInvalid("vco out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800575 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
576 * connector, etc., rather than just a single range.
577 */
578 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
Akshay Joshi0206e352011-08-16 15:34:10 -0400579 INTELPllInvalid("dot out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800580
581 return true;
582}
583
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300584static int
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300585i9xx_select_p2_div(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300586 const struct intel_crtc_state *crtc_state,
587 int target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800588{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300589 struct drm_device *dev = crtc_state->base.crtc->dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800590
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +0300591 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800592 /*
Daniel Vettera210b022012-11-26 17:22:08 +0100593 * For LVDS just rely on its current settings for dual-channel.
594 * We haven't figured out how to reliably set up different
595 * single/dual channel state, if we even can.
Jesse Barnes79e53942008-11-07 14:24:08 -0800596 */
Daniel Vetter1974cad2012-11-26 17:22:09 +0100597 if (intel_is_dual_link_lvds(dev))
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300598 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800599 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300600 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800601 } else {
602 if (target < limit->p2.dot_limit)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300603 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800604 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300605 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800606 }
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300607}
608
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200609/*
610 * Returns a set of divisors for the desired target clock with the given
611 * refclk, or FALSE. The returned values represent the clock equation:
612 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
613 *
614 * Target and reference clocks are specified in kHz.
615 *
616 * If match_clock is provided, then best_clock P divider must match the P
617 * divider from @match_clock used for LVDS downclocking.
618 */
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300619static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300620i9xx_find_best_dpll(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300621 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300622 int target, int refclk, struct dpll *match_clock,
623 struct dpll *best_clock)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300624{
625 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300626 struct dpll clock;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300627 int err = target;
Jesse Barnes79e53942008-11-07 14:24:08 -0800628
Akshay Joshi0206e352011-08-16 15:34:10 -0400629 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnes79e53942008-11-07 14:24:08 -0800630
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300631 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
632
Zhao Yakui42158662009-11-20 11:24:18 +0800633 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
634 clock.m1++) {
635 for (clock.m2 = limit->m2.min;
636 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterc0efc382013-06-03 20:56:24 +0200637 if (clock.m2 >= clock.m1)
Zhao Yakui42158662009-11-20 11:24:18 +0800638 break;
639 for (clock.n = limit->n.min;
640 clock.n <= limit->n.max; clock.n++) {
641 for (clock.p1 = limit->p1.min;
642 clock.p1 <= limit->p1.max; clock.p1++) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800643 int this_err;
644
Imre Deakdccbea32015-06-22 23:35:51 +0300645 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100646 if (!intel_PLL_is_valid(to_i915(dev),
647 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000648 &clock))
Jesse Barnes79e53942008-11-07 14:24:08 -0800649 continue;
Sean Paulcec2f352012-01-10 15:09:36 -0800650 if (match_clock &&
651 clock.p != match_clock->p)
652 continue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800653
654 this_err = abs(clock.dot - target);
655 if (this_err < err) {
656 *best_clock = clock;
657 err = this_err;
658 }
659 }
660 }
661 }
662 }
663
664 return (err != target);
665}
666
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200667/*
668 * Returns a set of divisors for the desired target clock with the given
669 * refclk, or FALSE. The returned values represent the clock equation:
670 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
671 *
672 * Target and reference clocks are specified in kHz.
673 *
674 * If match_clock is provided, then best_clock P divider must match the P
675 * divider from @match_clock used for LVDS downclocking.
676 */
Ma Lingd4906092009-03-18 20:13:27 +0800677static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300678pnv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200679 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300680 int target, int refclk, struct dpll *match_clock,
681 struct dpll *best_clock)
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200682{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300683 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300684 struct dpll clock;
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200685 int err = target;
686
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200687 memset(best_clock, 0, sizeof(*best_clock));
688
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300689 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
690
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200691 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
692 clock.m1++) {
693 for (clock.m2 = limit->m2.min;
694 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200695 for (clock.n = limit->n.min;
696 clock.n <= limit->n.max; clock.n++) {
697 for (clock.p1 = limit->p1.min;
698 clock.p1 <= limit->p1.max; clock.p1++) {
699 int this_err;
700
Imre Deakdccbea32015-06-22 23:35:51 +0300701 pnv_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100702 if (!intel_PLL_is_valid(to_i915(dev),
703 limit,
Jesse Barnes79e53942008-11-07 14:24:08 -0800704 &clock))
705 continue;
706 if (match_clock &&
707 clock.p != match_clock->p)
708 continue;
709
710 this_err = abs(clock.dot - target);
711 if (this_err < err) {
712 *best_clock = clock;
713 err = this_err;
714 }
715 }
716 }
717 }
718 }
719
720 return (err != target);
721}
722
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200723/*
724 * Returns a set of divisors for the desired target clock with the given
725 * refclk, or FALSE. The returned values represent the clock equation:
726 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200727 *
728 * Target and reference clocks are specified in kHz.
729 *
730 * If match_clock is provided, then best_clock P divider must match the P
731 * divider from @match_clock used for LVDS downclocking.
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200732 */
Ma Lingd4906092009-03-18 20:13:27 +0800733static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300734g4x_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200735 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300736 int target, int refclk, struct dpll *match_clock,
737 struct dpll *best_clock)
Ma Lingd4906092009-03-18 20:13:27 +0800738{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300739 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300740 struct dpll clock;
Ma Lingd4906092009-03-18 20:13:27 +0800741 int max_n;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300742 bool found = false;
Adam Jackson6ba770d2010-07-02 16:43:30 -0400743 /* approximately equals target * 0.00585 */
744 int err_most = (target >> 8) + (target >> 9);
Ma Lingd4906092009-03-18 20:13:27 +0800745
746 memset(best_clock, 0, sizeof(*best_clock));
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300747
748 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
749
Ma Lingd4906092009-03-18 20:13:27 +0800750 max_n = limit->n.max;
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200751 /* based on hardware requirement, prefer smaller n to precision */
Ma Lingd4906092009-03-18 20:13:27 +0800752 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200753 /* based on hardware requirement, prefere larger m1,m2 */
Ma Lingd4906092009-03-18 20:13:27 +0800754 for (clock.m1 = limit->m1.max;
755 clock.m1 >= limit->m1.min; clock.m1--) {
756 for (clock.m2 = limit->m2.max;
757 clock.m2 >= limit->m2.min; clock.m2--) {
758 for (clock.p1 = limit->p1.max;
759 clock.p1 >= limit->p1.min; clock.p1--) {
760 int this_err;
761
Imre Deakdccbea32015-06-22 23:35:51 +0300762 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100763 if (!intel_PLL_is_valid(to_i915(dev),
764 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000765 &clock))
Ma Lingd4906092009-03-18 20:13:27 +0800766 continue;
Chris Wilson1b894b52010-12-14 20:04:54 +0000767
768 this_err = abs(clock.dot - target);
Ma Lingd4906092009-03-18 20:13:27 +0800769 if (this_err < err_most) {
770 *best_clock = clock;
771 err_most = this_err;
772 max_n = clock.n;
773 found = true;
774 }
775 }
776 }
777 }
778 }
Zhenyu Wang2c072452009-06-05 15:38:42 +0800779 return found;
780}
Ma Lingd4906092009-03-18 20:13:27 +0800781
Imre Deakd5dd62b2015-03-17 11:40:03 +0200782/*
783 * Check if the calculated PLL configuration is more optimal compared to the
784 * best configuration and error found so far. Return the calculated error.
785 */
786static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300787 const struct dpll *calculated_clock,
788 const struct dpll *best_clock,
Imre Deakd5dd62b2015-03-17 11:40:03 +0200789 unsigned int best_error_ppm,
790 unsigned int *error_ppm)
791{
Imre Deak9ca3ba02015-03-17 11:40:05 +0200792 /*
793 * For CHV ignore the error and consider only the P value.
794 * Prefer a bigger P value based on HW requirements.
795 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100796 if (IS_CHERRYVIEW(to_i915(dev))) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200797 *error_ppm = 0;
798
799 return calculated_clock->p > best_clock->p;
800 }
801
Imre Deak24be4e42015-03-17 11:40:04 +0200802 if (WARN_ON_ONCE(!target_freq))
803 return false;
804
Imre Deakd5dd62b2015-03-17 11:40:03 +0200805 *error_ppm = div_u64(1000000ULL *
806 abs(target_freq - calculated_clock->dot),
807 target_freq);
808 /*
809 * Prefer a better P value over a better (smaller) error if the error
810 * is small. Ensure this preference for future configurations too by
811 * setting the error to 0.
812 */
813 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
814 *error_ppm = 0;
815
816 return true;
817 }
818
819 return *error_ppm + 10 < best_error_ppm;
820}
821
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200822/*
823 * Returns a set of divisors for the desired target clock with the given
824 * refclk, or FALSE. The returned values represent the clock equation:
825 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
826 */
Zhenyu Wang2c072452009-06-05 15:38:42 +0800827static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300828vlv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200829 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300830 int target, int refclk, struct dpll *match_clock,
831 struct dpll *best_clock)
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700832{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200833 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300834 struct drm_device *dev = crtc->base.dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300835 struct dpll clock;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300836 unsigned int bestppm = 1000000;
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300837 /* min update 19.2 MHz */
838 int max_n = min(limit->n.max, refclk / 19200);
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300839 bool found = false;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700840
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300841 target *= 5; /* fast clock */
842
843 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700844
845 /* based on hardware requirement, prefer smaller n to precision */
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300846 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Ville Syrjälä811bbf02013-09-24 21:26:25 +0300847 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
Ville Syrjälä889059d2013-09-24 21:26:27 +0300848 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
Ville Syrjäläc1a9ae42013-09-24 21:26:23 +0300849 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300850 clock.p = clock.p1 * clock.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700851 /* based on hardware requirement, prefer bigger m1,m2 values */
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300852 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
Imre Deakd5dd62b2015-03-17 11:40:03 +0200853 unsigned int ppm;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300854
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300855 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
856 refclk * clock.m1);
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300857
Imre Deakdccbea32015-06-22 23:35:51 +0300858 vlv_calc_dpll_params(refclk, &clock);
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300859
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100860 if (!intel_PLL_is_valid(to_i915(dev),
861 limit,
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300862 &clock))
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300863 continue;
864
Imre Deakd5dd62b2015-03-17 11:40:03 +0200865 if (!vlv_PLL_is_optimal(dev, target,
866 &clock,
867 best_clock,
868 bestppm, &ppm))
869 continue;
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300870
Imre Deakd5dd62b2015-03-17 11:40:03 +0200871 *best_clock = clock;
872 bestppm = ppm;
873 found = true;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700874 }
875 }
876 }
877 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700878
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300879 return found;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700880}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700881
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200882/*
883 * Returns a set of divisors for the desired target clock with the given
884 * refclk, or FALSE. The returned values represent the clock equation:
885 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
886 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300887static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300888chv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200889 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300890 int target, int refclk, struct dpll *match_clock,
891 struct dpll *best_clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300892{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200893 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300894 struct drm_device *dev = crtc->base.dev;
Imre Deak9ca3ba02015-03-17 11:40:05 +0200895 unsigned int best_error_ppm;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300896 struct dpll clock;
Jani Nikulaba3f4d02019-01-18 14:01:23 +0200897 u64 m2;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300898 int found = false;
899
900 memset(best_clock, 0, sizeof(*best_clock));
Imre Deak9ca3ba02015-03-17 11:40:05 +0200901 best_error_ppm = 1000000;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300902
903 /*
904 * Based on hardware doc, the n always set to 1, and m1 always
905 * set to 2. If requires to support 200Mhz refclk, we need to
906 * revisit this because n may not 1 anymore.
907 */
908 clock.n = 1, clock.m1 = 2;
909 target *= 5; /* fast clock */
910
911 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
912 for (clock.p2 = limit->p2.p2_fast;
913 clock.p2 >= limit->p2.p2_slow;
914 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200915 unsigned int error_ppm;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300916
917 clock.p = clock.p1 * clock.p2;
918
Jani Nikulaba3f4d02019-01-18 14:01:23 +0200919 m2 = DIV_ROUND_CLOSEST_ULL(((u64)target * clock.p *
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300920 clock.n) << 22, refclk * clock.m1);
921
922 if (m2 > INT_MAX/clock.m1)
923 continue;
924
925 clock.m2 = m2;
926
Imre Deakdccbea32015-06-22 23:35:51 +0300927 chv_calc_dpll_params(refclk, &clock);
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300928
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100929 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300930 continue;
931
Imre Deak9ca3ba02015-03-17 11:40:05 +0200932 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
933 best_error_ppm, &error_ppm))
934 continue;
935
936 *best_clock = clock;
937 best_error_ppm = error_ppm;
938 found = true;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300939 }
940 }
941
942 return found;
943}
944
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200945bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300946 struct dpll *best_clock)
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200947{
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200948 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300949 const struct intel_limit *limit = &intel_limits_bxt;
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200950
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200951 return chv_find_best_dpll(limit, crtc_state,
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200952 target_clock, refclk, NULL, best_clock);
953}
954
Ville Syrjälä525b9312016-10-31 22:37:02 +0200955bool intel_crtc_active(struct intel_crtc *crtc)
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300956{
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300957 /* Be paranoid as we can arrive here with only partial
958 * state retrieved from the hardware during setup.
959 *
Damien Lespiau241bfc32013-09-25 16:45:37 +0100960 * We can ditch the adjusted_mode.crtc_clock check as soon
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300961 * as Haswell has gained clock readout/fastboot support.
962 *
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +0300963 * We can ditch the crtc->primary->state->fb check as soon as we can
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300964 * properly reconstruct framebuffers.
Matt Roperc3d1f432015-03-09 10:19:23 -0700965 *
966 * FIXME: The intel_crtc->active here should be switched to
967 * crtc->state->active once we have proper CRTC states wired up
968 * for atomic.
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300969 */
Ville Syrjälä525b9312016-10-31 22:37:02 +0200970 return crtc->active && crtc->base.primary->state->fb &&
971 crtc->config->base.adjusted_mode.crtc_clock;
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300972}
973
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200974enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
975 enum pipe pipe)
976{
Ville Syrjälä98187832016-10-31 22:37:10 +0200977 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200978
Ville Syrjäläe2af48c2016-10-31 22:37:05 +0200979 return crtc->config->cpu_transcoder;
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200980}
981
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200982static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
983 enum pipe pipe)
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300984{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200985 i915_reg_t reg = PIPEDSL(pipe);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300986 u32 line1, line2;
987 u32 line_mask;
988
Lucas De Marchicf819ef2018-12-12 10:10:43 -0800989 if (IS_GEN(dev_priv, 2))
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300990 line_mask = DSL_LINEMASK_GEN2;
991 else
992 line_mask = DSL_LINEMASK_GEN3;
993
994 line1 = I915_READ(reg) & line_mask;
Daniel Vetter6adfb1e2015-07-07 09:10:40 +0200995 msleep(5);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300996 line2 = I915_READ(reg) & line_mask;
997
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200998 return line1 != line2;
999}
1000
1001static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1002{
1003 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1004 enum pipe pipe = crtc->pipe;
1005
1006 /* Wait for the display line to settle/start moving */
1007 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1008 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1009 pipe_name(pipe), onoff(state));
1010}
1011
1012static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1013{
1014 wait_for_pipe_scanline_moving(crtc, false);
1015}
1016
1017static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1018{
1019 wait_for_pipe_scanline_moving(crtc, true);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001020}
1021
Ville Syrjälä4972f702017-11-29 17:37:32 +02001022static void
1023intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001024{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001025 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001026 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001027
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001028 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001029 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001030 i915_reg_t reg = PIPECONF(cpu_transcoder);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001031
Keith Packardab7ad7f2010-10-03 00:33:06 -07001032 /* Wait for the Pipe State to go off */
Chris Wilsonb8511f52016-06-30 15:32:53 +01001033 if (intel_wait_for_register(dev_priv,
1034 reg, I965_PIPECONF_ACTIVE, 0,
1035 100))
Daniel Vetter284637d2012-07-09 09:51:57 +02001036 WARN(1, "pipe_off wait timed out\n");
Keith Packardab7ad7f2010-10-03 00:33:06 -07001037 } else {
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001038 intel_wait_for_pipe_scanline_stopped(crtc);
Keith Packardab7ad7f2010-10-03 00:33:06 -07001039 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001040}
1041
Jesse Barnesb24e7172011-01-04 15:09:30 -08001042/* Only for pre-ILK configs */
Daniel Vetter55607e82013-06-16 21:42:39 +02001043void assert_pll(struct drm_i915_private *dev_priv,
1044 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001045{
Jesse Barnesb24e7172011-01-04 15:09:30 -08001046 u32 val;
1047 bool cur_state;
1048
Ville Syrjälä649636e2015-09-22 19:50:01 +03001049 val = I915_READ(DPLL(pipe));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001050 cur_state = !!(val & DPLL_VCO_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001051 I915_STATE_WARN(cur_state != state,
Jesse Barnesb24e7172011-01-04 15:09:30 -08001052 "PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001053 onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001054}
Jesse Barnesb24e7172011-01-04 15:09:30 -08001055
Jani Nikula23538ef2013-08-27 15:12:22 +03001056/* XXX: the dsi pll is shared between MIPI DSI ports */
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +00001057void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
Jani Nikula23538ef2013-08-27 15:12:22 +03001058{
1059 u32 val;
1060 bool cur_state;
1061
Ville Syrjäläa5805162015-05-26 20:42:30 +03001062 mutex_lock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001063 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001064 mutex_unlock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001065
1066 cur_state = val & DSI_PLL_VCO_EN;
Rob Clarke2c719b2014-12-15 13:56:32 -05001067 I915_STATE_WARN(cur_state != state,
Jani Nikula23538ef2013-08-27 15:12:22 +03001068 "DSI PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001069 onoff(state), onoff(cur_state));
Jani Nikula23538ef2013-08-27 15:12:22 +03001070}
Jani Nikula23538ef2013-08-27 15:12:22 +03001071
Jesse Barnes040484a2011-01-03 12:14:26 -08001072static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1073 enum pipe pipe, bool state)
1074{
Jesse Barnes040484a2011-01-03 12:14:26 -08001075 bool cur_state;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001076 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1077 pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001078
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001079 if (HAS_DDI(dev_priv)) {
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001080 /* DDI does not have a specific FDI_TX register */
Ville Syrjälä649636e2015-09-22 19:50:01 +03001081 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
Paulo Zanoniad80a812012-10-24 16:06:19 -02001082 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001083 } else {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001084 u32 val = I915_READ(FDI_TX_CTL(pipe));
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001085 cur_state = !!(val & FDI_TX_ENABLE);
1086 }
Rob Clarke2c719b2014-12-15 13:56:32 -05001087 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001088 "FDI TX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001089 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001090}
1091#define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1092#define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1093
1094static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1095 enum pipe pipe, bool state)
1096{
Jesse Barnes040484a2011-01-03 12:14:26 -08001097 u32 val;
1098 bool cur_state;
1099
Ville Syrjälä649636e2015-09-22 19:50:01 +03001100 val = I915_READ(FDI_RX_CTL(pipe));
Paulo Zanonid63fa0d2012-11-20 13:27:35 -02001101 cur_state = !!(val & FDI_RX_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001102 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001103 "FDI RX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001104 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001105}
1106#define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1107#define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1108
1109static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1110 enum pipe pipe)
1111{
Jesse Barnes040484a2011-01-03 12:14:26 -08001112 u32 val;
1113
1114 /* ILK FDI PLL is always enabled */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001115 if (IS_GEN(dev_priv, 5))
Jesse Barnes040484a2011-01-03 12:14:26 -08001116 return;
1117
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001118 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001119 if (HAS_DDI(dev_priv))
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001120 return;
1121
Ville Syrjälä649636e2015-09-22 19:50:01 +03001122 val = I915_READ(FDI_TX_CTL(pipe));
Rob Clarke2c719b2014-12-15 13:56:32 -05001123 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 -08001124}
1125
Daniel Vetter55607e82013-06-16 21:42:39 +02001126void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1127 enum pipe pipe, bool state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001128{
Jesse Barnes040484a2011-01-03 12:14:26 -08001129 u32 val;
Daniel Vetter55607e82013-06-16 21:42:39 +02001130 bool cur_state;
Jesse Barnes040484a2011-01-03 12:14:26 -08001131
Ville Syrjälä649636e2015-09-22 19:50:01 +03001132 val = I915_READ(FDI_RX_CTL(pipe));
Daniel Vetter55607e82013-06-16 21:42:39 +02001133 cur_state = !!(val & FDI_RX_PLL_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001134 I915_STATE_WARN(cur_state != state,
Daniel Vetter55607e82013-06-16 21:42:39 +02001135 "FDI RX PLL assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001136 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001137}
1138
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001139void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnesea0760c2011-01-04 15:09:32 -08001140{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001141 i915_reg_t pp_reg;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001142 u32 val;
Ville Syrjälä10ed55e2018-05-23 17:57:18 +03001143 enum pipe panel_pipe = INVALID_PIPE;
Thomas Jarosch0de3b482011-08-25 15:37:45 +02001144 bool locked = true;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001145
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001146 if (WARN_ON(HAS_DDI(dev_priv)))
Jani Nikulabedd4db2014-08-22 15:04:13 +03001147 return;
1148
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001149 if (HAS_PCH_SPLIT(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001150 u32 port_sel;
1151
Imre Deak44cb7342016-08-10 14:07:29 +03001152 pp_reg = PP_CONTROL(0);
1153 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
Jani Nikulabedd4db2014-08-22 15:04:13 +03001154
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001155 switch (port_sel) {
1156 case PANEL_PORT_SELECT_LVDS:
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001157 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001158 break;
1159 case PANEL_PORT_SELECT_DPA:
1160 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1161 break;
1162 case PANEL_PORT_SELECT_DPC:
1163 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1164 break;
1165 case PANEL_PORT_SELECT_DPD:
1166 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1167 break;
1168 default:
1169 MISSING_CASE(port_sel);
1170 break;
1171 }
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001172 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001173 /* presumably write lock depends on pipe, not port select */
Imre Deak44cb7342016-08-10 14:07:29 +03001174 pp_reg = PP_CONTROL(pipe);
Jani Nikulabedd4db2014-08-22 15:04:13 +03001175 panel_pipe = pipe;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001176 } else {
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001177 u32 port_sel;
1178
Imre Deak44cb7342016-08-10 14:07:29 +03001179 pp_reg = PP_CONTROL(0);
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001180 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1181
1182 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001183 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
Jesse Barnesea0760c2011-01-04 15:09:32 -08001184 }
1185
1186 val = I915_READ(pp_reg);
1187 if (!(val & PANEL_POWER_ON) ||
Jani Nikulaec49ba22014-08-21 15:06:25 +03001188 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
Jesse Barnesea0760c2011-01-04 15:09:32 -08001189 locked = false;
1190
Rob Clarke2c719b2014-12-15 13:56:32 -05001191 I915_STATE_WARN(panel_pipe == pipe && locked,
Jesse Barnesea0760c2011-01-04 15:09:32 -08001192 "panel assertion failure, pipe %c regs locked\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001193 pipe_name(pipe));
Jesse Barnesea0760c2011-01-04 15:09:32 -08001194}
1195
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001196void assert_pipe(struct drm_i915_private *dev_priv,
1197 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001198{
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001199 bool cur_state;
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001200 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1201 pipe);
Imre Deak4feed0e2016-02-12 18:55:14 +02001202 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00001203 intel_wakeref_t wakeref;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001204
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001205 /* we keep both pipes enabled on 830 */
1206 if (IS_I830(dev_priv))
Daniel Vetter8e636782012-01-22 01:36:48 +01001207 state = true;
1208
Imre Deak4feed0e2016-02-12 18:55:14 +02001209 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00001210 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1211 if (wakeref) {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001212 u32 val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni69310162013-01-29 16:35:19 -02001213 cur_state = !!(val & PIPECONF_ENABLE);
Imre Deak4feed0e2016-02-12 18:55:14 +02001214
Chris Wilson0e6e0be2019-01-14 14:21:24 +00001215 intel_display_power_put(dev_priv, power_domain, wakeref);
Imre Deak4feed0e2016-02-12 18:55:14 +02001216 } else {
1217 cur_state = false;
Paulo Zanoni69310162013-01-29 16:35:19 -02001218 }
1219
Rob Clarke2c719b2014-12-15 13:56:32 -05001220 I915_STATE_WARN(cur_state != state,
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001221 "pipe %c assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001222 pipe_name(pipe), onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001223}
1224
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001225static void assert_plane(struct intel_plane *plane, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001226{
Ville Syrjäläeade6c82018-01-30 22:38:03 +02001227 enum pipe pipe;
1228 bool cur_state;
1229
1230 cur_state = plane->get_hw_state(plane, &pipe);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001231
Rob Clarke2c719b2014-12-15 13:56:32 -05001232 I915_STATE_WARN(cur_state != state,
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001233 "%s assertion failure (expected %s, current %s)\n",
1234 plane->base.name, onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001235}
1236
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001237#define assert_plane_enabled(p) assert_plane(p, true)
1238#define assert_plane_disabled(p) assert_plane(p, false)
Chris Wilson931872f2012-01-16 23:01:13 +00001239
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001240static void assert_planes_disabled(struct intel_crtc *crtc)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001241{
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001242 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1243 struct intel_plane *plane;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001244
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001245 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1246 assert_plane_disabled(plane);
Jesse Barnes19332d72013-03-28 09:55:38 -07001247}
1248
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001249static void assert_vblank_disabled(struct drm_crtc *crtc)
1250{
Rob Clarke2c719b2014-12-15 13:56:32 -05001251 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001252 drm_crtc_vblank_put(crtc);
1253}
1254
Ander Conselvan de Oliveira7abd4b32016-03-08 17:46:15 +02001255void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1256 enum pipe pipe)
Jesse Barnes92f25842011-01-04 15:09:34 -08001257{
Jesse Barnes92f25842011-01-04 15:09:34 -08001258 u32 val;
1259 bool enabled;
1260
Ville Syrjälä649636e2015-09-22 19:50:01 +03001261 val = I915_READ(PCH_TRANSCONF(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001262 enabled = !!(val & TRANS_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001263 I915_STATE_WARN(enabled,
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001264 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1265 pipe_name(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001266}
1267
Jesse Barnes291906f2011-02-02 12:28:03 -08001268static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001269 enum pipe pipe, enum port port,
1270 i915_reg_t dp_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001271{
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001272 enum pipe port_pipe;
1273 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001274
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001275 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1276
1277 I915_STATE_WARN(state && port_pipe == pipe,
1278 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1279 port_name(port), pipe_name(pipe));
1280
1281 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1282 "IBX PCH DP %c still using transcoder B\n",
1283 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001284}
1285
1286static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä76203462018-05-14 20:24:21 +03001287 enum pipe pipe, enum port port,
1288 i915_reg_t hdmi_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001289{
Ville Syrjälä76203462018-05-14 20:24:21 +03001290 enum pipe port_pipe;
1291 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001292
Ville Syrjälä76203462018-05-14 20:24:21 +03001293 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1294
1295 I915_STATE_WARN(state && port_pipe == pipe,
1296 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1297 port_name(port), pipe_name(pipe));
1298
1299 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1300 "IBX PCH HDMI %c still using transcoder B\n",
1301 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001302}
1303
1304static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1305 enum pipe pipe)
1306{
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001307 enum pipe port_pipe;
Jesse Barnes291906f2011-02-02 12:28:03 -08001308
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001309 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1310 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1311 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
Jesse Barnes291906f2011-02-02 12:28:03 -08001312
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001313 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1314 port_pipe == pipe,
1315 "PCH VGA enabled on transcoder %c, should be disabled\n",
1316 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001317
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001318 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1319 port_pipe == pipe,
1320 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1321 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001322
Ville Syrjälä3aefb672018-11-08 16:36:35 +02001323 /* PCH SDVOB multiplex with HDMIB */
Ville Syrjälä76203462018-05-14 20:24:21 +03001324 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1325 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1326 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
Jesse Barnes291906f2011-02-02 12:28:03 -08001327}
1328
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001329static void _vlv_enable_pll(struct intel_crtc *crtc,
1330 const struct intel_crtc_state *pipe_config)
1331{
1332 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1333 enum pipe pipe = crtc->pipe;
1334
1335 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1336 POSTING_READ(DPLL(pipe));
1337 udelay(150);
1338
Chris Wilson2c30b432016-06-30 15:32:54 +01001339 if (intel_wait_for_register(dev_priv,
1340 DPLL(pipe),
1341 DPLL_LOCK_VLV,
1342 DPLL_LOCK_VLV,
1343 1))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001344 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1345}
1346
Ville Syrjäläd288f652014-10-28 13:20:22 +02001347static void vlv_enable_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001348 const struct intel_crtc_state *pipe_config)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001349{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001350 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001351 enum pipe pipe = crtc->pipe;
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001352
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001353 assert_pipe_disabled(dev_priv, pipe);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001354
Daniel Vetter87442f72013-06-06 00:52:17 +02001355 /* PLL is protected by panel, make sure we can write it */
Ville Syrjälä7d1a83c2016-03-15 16:39:58 +02001356 assert_panel_unlocked(dev_priv, pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001357
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001358 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1359 _vlv_enable_pll(crtc, pipe_config);
Daniel Vetter426115c2013-07-11 22:13:42 +02001360
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001361 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1362 POSTING_READ(DPLL_MD(pipe));
Daniel Vetter87442f72013-06-06 00:52:17 +02001363}
1364
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001365
1366static void _chv_enable_pll(struct intel_crtc *crtc,
1367 const struct intel_crtc_state *pipe_config)
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001368{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001369 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001370 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001371 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001372 u32 tmp;
1373
Ville Syrjäläa5805162015-05-26 20:42:30 +03001374 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001375
1376 /* Enable back the 10bit clock to display controller */
1377 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1378 tmp |= DPIO_DCLKP_EN;
1379 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1380
Ville Syrjälä54433e92015-05-26 20:42:31 +03001381 mutex_unlock(&dev_priv->sb_lock);
1382
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001383 /*
1384 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1385 */
1386 udelay(1);
1387
1388 /* Enable PLL */
Ville Syrjäläd288f652014-10-28 13:20:22 +02001389 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001390
1391 /* Check PLL is locked */
Chris Wilson6b188262016-06-30 15:32:55 +01001392 if (intel_wait_for_register(dev_priv,
1393 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1394 1))
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001395 DRM_ERROR("PLL %d failed to lock\n", pipe);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001396}
1397
1398static void chv_enable_pll(struct intel_crtc *crtc,
1399 const struct intel_crtc_state *pipe_config)
1400{
1401 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1402 enum pipe pipe = crtc->pipe;
1403
1404 assert_pipe_disabled(dev_priv, pipe);
1405
1406 /* PLL is protected by panel, make sure we can write it */
1407 assert_panel_unlocked(dev_priv, pipe);
1408
1409 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1410 _chv_enable_pll(crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001411
Ville Syrjäläc2317752016-03-15 16:39:56 +02001412 if (pipe != PIPE_A) {
1413 /*
1414 * WaPixelRepeatModeFixForC0:chv
1415 *
1416 * DPLLCMD is AWOL. Use chicken bits to propagate
1417 * the value from DPLLBMD to either pipe B or C.
1418 */
Ville Syrjälädfa311f2017-09-13 17:08:54 +03001419 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
Ville Syrjäläc2317752016-03-15 16:39:56 +02001420 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1421 I915_WRITE(CBR4_VLV, 0);
1422 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1423
1424 /*
1425 * DPLLB VGA mode also seems to cause problems.
1426 * We should always have it disabled.
1427 */
1428 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1429 } else {
1430 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1431 POSTING_READ(DPLL_MD(pipe));
1432 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001433}
1434
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001435static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001436{
1437 struct intel_crtc *crtc;
1438 int count = 0;
1439
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001440 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst3538b9d2015-06-01 12:50:10 +02001441 count += crtc->base.state->active &&
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03001442 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1443 }
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001444
1445 return count;
1446}
1447
Ville Syrjälä939994d2017-09-13 17:08:56 +03001448static void i9xx_enable_pll(struct intel_crtc *crtc,
1449 const struct intel_crtc_state *crtc_state)
Daniel Vetter87442f72013-06-06 00:52:17 +02001450{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001451 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001452 i915_reg_t reg = DPLL(crtc->pipe);
Ville Syrjälä939994d2017-09-13 17:08:56 +03001453 u32 dpll = crtc_state->dpll_hw_state.dpll;
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001454 int i;
Daniel Vetter87442f72013-06-06 00:52:17 +02001455
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001456 assert_pipe_disabled(dev_priv, crtc->pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001457
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001458 /* PLL is protected by panel, make sure we can write it */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001459 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001460 assert_panel_unlocked(dev_priv, crtc->pipe);
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001461
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001462 /* Enable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001463 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001464 /*
1465 * It appears to be important that we don't enable this
1466 * for the current pipe before otherwise configuring the
1467 * PLL. No idea how this should be handled if multiple
1468 * DVO outputs are enabled simultaneosly.
1469 */
1470 dpll |= DPLL_DVO_2X_MODE;
1471 I915_WRITE(DPLL(!crtc->pipe),
1472 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1473 }
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001474
Ville Syrjäläc2b63372015-10-07 22:08:25 +03001475 /*
1476 * Apparently we need to have VGA mode enabled prior to changing
1477 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1478 * dividers, even though the register value does change.
1479 */
1480 I915_WRITE(reg, 0);
1481
Ville Syrjälä8e7a65a2015-10-07 22:08:24 +03001482 I915_WRITE(reg, dpll);
1483
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001484 /* Wait for the clocks to stabilize. */
1485 POSTING_READ(reg);
1486 udelay(150);
1487
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001488 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001489 I915_WRITE(DPLL_MD(crtc->pipe),
Ville Syrjälä939994d2017-09-13 17:08:56 +03001490 crtc_state->dpll_hw_state.dpll_md);
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001491 } else {
1492 /* The pixel multiplier can only be updated once the
1493 * DPLL is enabled and the clocks are stable.
1494 *
1495 * So write it again.
1496 */
1497 I915_WRITE(reg, dpll);
1498 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001499
1500 /* We do this three times for luck */
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001501 for (i = 0; i < 3; i++) {
1502 I915_WRITE(reg, dpll);
1503 POSTING_READ(reg);
1504 udelay(150); /* wait for warmup */
1505 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001506}
1507
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001508static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001509{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001510 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001511 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001512 enum pipe pipe = crtc->pipe;
1513
1514 /* Disable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001515 if (IS_I830(dev_priv) &&
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001516 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001517 !intel_num_dvo_pipes(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001518 I915_WRITE(DPLL(PIPE_B),
1519 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1520 I915_WRITE(DPLL(PIPE_A),
1521 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1522 }
1523
Ville Syrjäläb6b5d042014-08-15 01:22:07 +03001524 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001525 if (IS_I830(dev_priv))
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001526 return;
1527
1528 /* Make sure the pipe isn't still relying on us */
1529 assert_pipe_disabled(dev_priv, pipe);
1530
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001531 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
Daniel Vetter50b44a42013-06-05 13:34:33 +02001532 POSTING_READ(DPLL(pipe));
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001533}
1534
Jesse Barnesf6071162013-10-01 10:41:38 -07001535static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1536{
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001537 u32 val;
Jesse Barnesf6071162013-10-01 10:41:38 -07001538
1539 /* Make sure the pipe isn't still relying on us */
1540 assert_pipe_disabled(dev_priv, pipe);
1541
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001542 val = DPLL_INTEGRATED_REF_CLK_VLV |
1543 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1544 if (pipe != PIPE_A)
1545 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1546
Jesse Barnesf6071162013-10-01 10:41:38 -07001547 I915_WRITE(DPLL(pipe), val);
1548 POSTING_READ(DPLL(pipe));
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001549}
1550
1551static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1552{
Ville Syrjäläd7520482014-04-09 13:28:59 +03001553 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001554 u32 val;
1555
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001556 /* Make sure the pipe isn't still relying on us */
1557 assert_pipe_disabled(dev_priv, pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001558
Ville Syrjälä60bfe442015-06-29 15:25:49 +03001559 val = DPLL_SSC_REF_CLK_CHV |
1560 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001561 if (pipe != PIPE_A)
1562 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001563
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001564 I915_WRITE(DPLL(pipe), val);
1565 POSTING_READ(DPLL(pipe));
Ville Syrjäläd7520482014-04-09 13:28:59 +03001566
Ville Syrjäläa5805162015-05-26 20:42:30 +03001567 mutex_lock(&dev_priv->sb_lock);
Ville Syrjäläd7520482014-04-09 13:28:59 +03001568
1569 /* Disable 10bit clock to display controller */
1570 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1571 val &= ~DPIO_DCLKP_EN;
1572 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1573
Ville Syrjäläa5805162015-05-26 20:42:30 +03001574 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesf6071162013-10-01 10:41:38 -07001575}
1576
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001577void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001578 struct intel_digital_port *dport,
1579 unsigned int expected_mask)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001580{
1581 u32 port_mask;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001582 i915_reg_t dpll_reg;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001583
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001584 switch (dport->base.port) {
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001585 case PORT_B:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001586 port_mask = DPLL_PORTB_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001587 dpll_reg = DPLL(0);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001588 break;
1589 case PORT_C:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001590 port_mask = DPLL_PORTC_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001591 dpll_reg = DPLL(0);
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001592 expected_mask <<= 4;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001593 break;
1594 case PORT_D:
1595 port_mask = DPLL_PORTD_READY_MASK;
1596 dpll_reg = DPIO_PHY_STATUS;
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001597 break;
1598 default:
1599 BUG();
1600 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07001601
Chris Wilson370004d2016-06-30 15:32:56 +01001602 if (intel_wait_for_register(dev_priv,
1603 dpll_reg, port_mask, expected_mask,
1604 1000))
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001605 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 +02001606 port_name(dport->base.port),
1607 I915_READ(dpll_reg) & port_mask, expected_mask);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001608}
1609
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001610static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001611{
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001612 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1613 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1614 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001615 i915_reg_t reg;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02001616 u32 val, pipeconf_val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001617
Jesse Barnes040484a2011-01-03 12:14:26 -08001618 /* Make sure PCH DPLL is enabled */
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001619 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
Jesse Barnes040484a2011-01-03 12:14:26 -08001620
1621 /* FDI must be feeding us bits for PCH ports */
1622 assert_fdi_tx_enabled(dev_priv, pipe);
1623 assert_fdi_rx_enabled(dev_priv, pipe);
1624
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001625 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001626 /* Workaround: Set the timing override bit before enabling the
1627 * pch transcoder. */
1628 reg = TRANS_CHICKEN2(pipe);
1629 val = I915_READ(reg);
1630 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1631 I915_WRITE(reg, val);
Eugeni Dodonov59c859d2012-05-09 15:37:19 -03001632 }
Daniel Vetter23670b322012-11-01 09:15:30 +01001633
Daniel Vetterab9412b2013-05-03 11:49:46 +02001634 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001635 val = I915_READ(reg);
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001636 pipeconf_val = I915_READ(PIPECONF(pipe));
Jesse Barnese9bcff52011-06-24 12:19:20 -07001637
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001638 if (HAS_PCH_IBX(dev_priv)) {
Jesse Barnese9bcff52011-06-24 12:19:20 -07001639 /*
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001640 * Make the BPC in transcoder be consistent with
1641 * that in pipeconf reg. For HDMI we must use 8bpc
1642 * here for both 8bpc and 12bpc.
Jesse Barnese9bcff52011-06-24 12:19:20 -07001643 */
Daniel Vetterdfd07d72012-12-17 11:21:38 +01001644 val &= ~PIPECONF_BPC_MASK;
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001645 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001646 val |= PIPECONF_8BPC;
1647 else
1648 val |= pipeconf_val & PIPECONF_BPC_MASK;
Jesse Barnese9bcff52011-06-24 12:19:20 -07001649 }
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001650
1651 val &= ~TRANS_INTERLACE_MASK;
1652 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001653 if (HAS_PCH_IBX(dev_priv) &&
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001654 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Paulo Zanoni7c26e5c2012-02-14 17:07:09 -02001655 val |= TRANS_LEGACY_INTERLACED_ILK;
1656 else
1657 val |= TRANS_INTERLACED;
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001658 else
1659 val |= TRANS_PROGRESSIVE;
1660
Jesse Barnes040484a2011-01-03 12:14:26 -08001661 I915_WRITE(reg, val | TRANS_ENABLE);
Chris Wilson650fbd82016-06-30 15:32:57 +01001662 if (intel_wait_for_register(dev_priv,
1663 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1664 100))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001665 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
Jesse Barnes040484a2011-01-03 12:14:26 -08001666}
1667
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001668static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
Paulo Zanoni937bb612012-10-31 18:12:47 -02001669 enum transcoder cpu_transcoder)
Jesse Barnes040484a2011-01-03 12:14:26 -08001670{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001671 u32 val, pipeconf_val;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001672
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001673 /* FDI must be feeding us bits for PCH ports */
Daniel Vetter1a240d42012-11-29 22:18:51 +01001674 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001675 assert_fdi_rx_enabled(dev_priv, PIPE_A);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001676
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001677 /* Workaround: set timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001678 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001679 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001680 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001681
Paulo Zanoni25f3ef12012-10-31 18:12:49 -02001682 val = TRANS_ENABLE;
Paulo Zanoni937bb612012-10-31 18:12:47 -02001683 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001684
Paulo Zanoni9a76b1c2012-10-31 18:12:48 -02001685 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1686 PIPECONF_INTERLACED_ILK)
Paulo Zanonia35f2672012-10-31 18:12:45 -02001687 val |= TRANS_INTERLACED;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001688 else
1689 val |= TRANS_PROGRESSIVE;
1690
Daniel Vetterab9412b2013-05-03 11:49:46 +02001691 I915_WRITE(LPT_TRANSCONF, val);
Chris Wilsond9f96242016-06-30 15:32:58 +01001692 if (intel_wait_for_register(dev_priv,
1693 LPT_TRANSCONF,
1694 TRANS_STATE_ENABLE,
1695 TRANS_STATE_ENABLE,
1696 100))
Paulo Zanoni937bb612012-10-31 18:12:47 -02001697 DRM_ERROR("Failed to enable PCH transcoder\n");
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001698}
1699
Paulo Zanonib8a4f402012-10-31 18:12:42 -02001700static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1701 enum pipe pipe)
Jesse Barnes040484a2011-01-03 12:14:26 -08001702{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001703 i915_reg_t reg;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02001704 u32 val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001705
1706 /* FDI relies on the transcoder */
1707 assert_fdi_tx_disabled(dev_priv, pipe);
1708 assert_fdi_rx_disabled(dev_priv, pipe);
1709
Jesse Barnes291906f2011-02-02 12:28:03 -08001710 /* Ports must be off as well */
1711 assert_pch_ports_disabled(dev_priv, pipe);
1712
Daniel Vetterab9412b2013-05-03 11:49:46 +02001713 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001714 val = I915_READ(reg);
1715 val &= ~TRANS_ENABLE;
1716 I915_WRITE(reg, val);
1717 /* wait for PCH transcoder off, transcoder state */
Chris Wilsona7d04662016-06-30 15:32:59 +01001718 if (intel_wait_for_register(dev_priv,
1719 reg, TRANS_STATE_ENABLE, 0,
1720 50))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001721 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
Daniel Vetter23670b322012-11-01 09:15:30 +01001722
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001723 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001724 /* Workaround: Clear the timing override chicken bit again. */
1725 reg = TRANS_CHICKEN2(pipe);
1726 val = I915_READ(reg);
1727 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1728 I915_WRITE(reg, val);
1729 }
Jesse Barnes040484a2011-01-03 12:14:26 -08001730}
1731
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001732void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001733{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001734 u32 val;
1735
Daniel Vetterab9412b2013-05-03 11:49:46 +02001736 val = I915_READ(LPT_TRANSCONF);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001737 val &= ~TRANS_ENABLE;
Daniel Vetterab9412b2013-05-03 11:49:46 +02001738 I915_WRITE(LPT_TRANSCONF, val);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001739 /* wait for PCH transcoder off, transcoder state */
Chris Wilsondfdb4742016-06-30 15:33:00 +01001740 if (intel_wait_for_register(dev_priv,
1741 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1742 50))
Paulo Zanoni8a52fd92012-10-31 18:12:51 -02001743 DRM_ERROR("Failed to disable PCH transcoder\n");
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001744
1745 /* Workaround: clear timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001746 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001747 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001748 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Jesse Barnes92f25842011-01-04 15:09:34 -08001749}
1750
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001751enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
Ville Syrjälä65f21302016-10-14 20:02:53 +03001752{
1753 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1754
Ville Syrjälä65f21302016-10-14 20:02:53 +03001755 if (HAS_PCH_LPT(dev_priv))
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001756 return PIPE_A;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001757 else
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001758 return crtc->pipe;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001759}
1760
Ville Syrjälä32db0b62018-11-27 22:05:50 +02001761static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1762{
1763 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1764
1765 /*
1766 * On i965gm the hardware frame counter reads
1767 * zero when the TV encoder is enabled :(
1768 */
1769 if (IS_I965GM(dev_priv) &&
1770 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1771 return 0;
1772
1773 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1774 return 0xffffffff; /* full 32 bit counter */
1775 else if (INTEL_GEN(dev_priv) >= 3)
1776 return 0xffffff; /* only 24 bits of frame count */
1777 else
1778 return 0; /* Gen2 doesn't have a hardware frame counter */
1779}
1780
1781static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1782{
1783 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1784
1785 drm_crtc_set_max_vblank_count(&crtc->base,
1786 intel_crtc_max_vblank_count(crtc_state));
1787 drm_crtc_vblank_on(&crtc->base);
1788}
1789
Ville Syrjälä4972f702017-11-29 17:37:32 +02001790static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001791{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001792 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1793 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1794 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
Paulo Zanoni03722642014-01-17 13:51:09 -02001795 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001796 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001797 u32 val;
1798
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001799 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1800
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001801 assert_planes_disabled(crtc);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001802
Jesse Barnesb24e7172011-01-04 15:09:30 -08001803 /*
1804 * A pipe without a PLL won't actually be able to drive bits from
1805 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1806 * need the check.
1807 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08001808 if (HAS_GMCH(dev_priv)) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001809 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
Jani Nikula23538ef2013-08-27 15:12:22 +03001810 assert_dsi_pll_enabled(dev_priv);
1811 else
1812 assert_pll_enabled(dev_priv, pipe);
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001813 } else {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001814 if (new_crtc_state->has_pch_encoder) {
Jesse Barnes040484a2011-01-03 12:14:26 -08001815 /* if driving the PCH, we need FDI enabled */
Ville Syrjälä65f21302016-10-14 20:02:53 +03001816 assert_fdi_rx_pll_enabled(dev_priv,
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001817 intel_crtc_pch_transcoder(crtc));
Daniel Vetter1a240d42012-11-29 22:18:51 +01001818 assert_fdi_tx_pll_enabled(dev_priv,
1819 (enum pipe) cpu_transcoder);
Jesse Barnes040484a2011-01-03 12:14:26 -08001820 }
1821 /* FIXME: assert CPU port conditions for SNB+ */
1822 }
Jesse Barnesb24e7172011-01-04 15:09:30 -08001823
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001824 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001825 val = I915_READ(reg);
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001826 if (val & PIPECONF_ENABLE) {
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001827 /* we keep both pipes enabled on 830 */
1828 WARN_ON(!IS_I830(dev_priv));
Chris Wilson00d70b12011-03-17 07:18:29 +00001829 return;
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001830 }
Chris Wilson00d70b12011-03-17 07:18:29 +00001831
1832 I915_WRITE(reg, val | PIPECONF_ENABLE);
Paulo Zanoni851855d2013-12-19 19:12:29 -02001833 POSTING_READ(reg);
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001834
1835 /*
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001836 * Until the pipe starts PIPEDSL reads will return a stale value,
1837 * which causes an apparent vblank timestamp jump when PIPEDSL
1838 * resets to its proper value. That also messes up the frame count
1839 * when it's derived from the timestamps. So let's wait for the
1840 * pipe to start properly before we call drm_crtc_vblank_on()
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001841 */
Ville Syrjälä32db0b62018-11-27 22:05:50 +02001842 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001843 intel_wait_for_pipe_scanline_moving(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001844}
1845
Ville Syrjälä4972f702017-11-29 17:37:32 +02001846static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001847{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001848 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001849 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä4972f702017-11-29 17:37:32 +02001850 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjälä575f7ab2014-08-15 01:21:56 +03001851 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001852 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001853 u32 val;
1854
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001855 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1856
Jesse Barnesb24e7172011-01-04 15:09:30 -08001857 /*
1858 * Make sure planes won't keep trying to pump pixels to us,
1859 * or we might hang the display.
1860 */
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001861 assert_planes_disabled(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001862
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001863 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001864 val = I915_READ(reg);
Chris Wilson00d70b12011-03-17 07:18:29 +00001865 if ((val & PIPECONF_ENABLE) == 0)
1866 return;
1867
Ville Syrjälä67adc642014-08-15 01:21:57 +03001868 /*
1869 * Double wide has implications for planes
1870 * so best keep it disabled when not needed.
1871 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001872 if (old_crtc_state->double_wide)
Ville Syrjälä67adc642014-08-15 01:21:57 +03001873 val &= ~PIPECONF_DOUBLE_WIDE;
1874
1875 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001876 if (!IS_I830(dev_priv))
Ville Syrjälä67adc642014-08-15 01:21:57 +03001877 val &= ~PIPECONF_ENABLE;
1878
1879 I915_WRITE(reg, val);
1880 if ((val & PIPECONF_ENABLE) == 0)
Ville Syrjälä4972f702017-11-29 17:37:32 +02001881 intel_wait_for_pipe_off(old_crtc_state);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001882}
1883
Ville Syrjälä832be822016-01-12 21:08:33 +02001884static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1885{
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001886 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
Ville Syrjälä832be822016-01-12 21:08:33 +02001887}
1888
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001889static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001890intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001891{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001892 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001893 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001894
1895 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001896 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001897 return cpp;
1898 case I915_FORMAT_MOD_X_TILED:
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001899 if (IS_GEN(dev_priv, 2))
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001900 return 128;
1901 else
1902 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001903 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001904 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001905 return 128;
1906 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001907 case I915_FORMAT_MOD_Y_TILED:
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001908 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001909 return 128;
1910 else
1911 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001912 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001913 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001914 return 128;
1915 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001916 case I915_FORMAT_MOD_Yf_TILED:
1917 switch (cpp) {
1918 case 1:
1919 return 64;
1920 case 2:
1921 case 4:
1922 return 128;
1923 case 8:
1924 case 16:
1925 return 256;
1926 default:
1927 MISSING_CASE(cpp);
1928 return cpp;
1929 }
1930 break;
1931 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001932 MISSING_CASE(fb->modifier);
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001933 return cpp;
1934 }
1935}
1936
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001937static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001938intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001939{
Ben Widawsky2f075562017-03-24 14:29:48 -07001940 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä832be822016-01-12 21:08:33 +02001941 return 1;
1942 else
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001943 return intel_tile_size(to_i915(fb->dev)) /
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001944 intel_tile_width_bytes(fb, color_plane);
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001945}
1946
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001947/* Return the tile dimensions in pixel units */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001948static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001949 unsigned int *tile_width,
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001950 unsigned int *tile_height)
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001951{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001952 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1953 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001954
1955 *tile_width = tile_width_bytes / cpp;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001956 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001957}
1958
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001959unsigned int
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001960intel_fb_align_height(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001961 int color_plane, unsigned int height)
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001962{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001963 unsigned int tile_height = intel_tile_height(fb, color_plane);
Ville Syrjälä832be822016-01-12 21:08:33 +02001964
1965 return ALIGN(height, tile_height);
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001966}
1967
Ville Syrjälä1663b9d2016-02-15 22:54:45 +02001968unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1969{
1970 unsigned int size = 0;
1971 int i;
1972
1973 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1974 size += rot_info->plane[i].width * rot_info->plane[i].height;
1975
1976 return size;
1977}
1978
Daniel Vetter75c82a52015-10-14 16:51:04 +02001979static void
Ville Syrjälä3465c582016-02-15 22:54:43 +02001980intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1981 const struct drm_framebuffer *fb,
1982 unsigned int rotation)
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00001983{
Chris Wilson7b92c042017-01-14 00:28:26 +00001984 view->type = I915_GGTT_VIEW_NORMAL;
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03001985 if (drm_rotation_90_or_270(rotation)) {
Chris Wilson7b92c042017-01-14 00:28:26 +00001986 view->type = I915_GGTT_VIEW_ROTATED;
Chris Wilson8bab11932017-01-14 00:28:25 +00001987 view->rotated = to_intel_framebuffer(fb)->rot_info;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +02001988 }
1989}
1990
Ville Syrjäläfabac482017-03-27 21:55:43 +03001991static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
1992{
1993 if (IS_I830(dev_priv))
1994 return 16 * 1024;
1995 else if (IS_I85X(dev_priv))
1996 return 256;
Ville Syrjäläd9e15512017-03-27 21:55:45 +03001997 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
1998 return 32;
Ville Syrjäläfabac482017-03-27 21:55:43 +03001999 else
2000 return 4 * 1024;
2001}
2002
Ville Syrjälä603525d2016-01-12 21:08:37 +02002003static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002004{
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00002005 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002006 return 256 * 1024;
Jani Nikulac0f86832016-12-07 12:13:04 +02002007 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
Wayne Boyer666a4532015-12-09 12:29:35 -08002008 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002009 return 128 * 1024;
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00002010 else if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002011 return 4 * 1024;
2012 else
Ville Syrjälä44c59052015-06-11 16:31:16 +03002013 return 0;
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002014}
2015
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002016static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002017 int color_plane)
Ville Syrjälä603525d2016-01-12 21:08:37 +02002018{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002019 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2020
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02002021 /* AUX_DIST needs only 4K alignment */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002022 if (color_plane == 1)
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02002023 return 4096;
2024
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002025 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002026 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002027 return intel_linear_alignment(dev_priv);
2028 case I915_FORMAT_MOD_X_TILED:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002029 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä603525d2016-01-12 21:08:37 +02002030 return 256 * 1024;
2031 return 0;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002032 case I915_FORMAT_MOD_Y_TILED_CCS:
2033 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002034 case I915_FORMAT_MOD_Y_TILED:
2035 case I915_FORMAT_MOD_Yf_TILED:
2036 return 1 * 1024 * 1024;
2037 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002038 MISSING_CASE(fb->modifier);
Ville Syrjälä603525d2016-01-12 21:08:37 +02002039 return 0;
2040 }
2041}
2042
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002043static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2044{
2045 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2046 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2047
Ville Syrjälä32febd92018-02-21 18:02:33 +02002048 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002049}
2050
Chris Wilson058d88c2016-08-15 10:49:06 +01002051struct i915_vma *
Chris Wilson59354852018-02-20 13:42:06 +00002052intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002053 const struct i915_ggtt_view *view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002054 bool uses_fence,
Chris Wilson59354852018-02-20 13:42:06 +00002055 unsigned long *out_flags)
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002056{
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002057 struct drm_device *dev = fb->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002058 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002059 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Chris Wilson1d264d92019-01-14 14:21:19 +00002060 intel_wakeref_t wakeref;
Chris Wilson058d88c2016-08-15 10:49:06 +01002061 struct i915_vma *vma;
Chris Wilson59354852018-02-20 13:42:06 +00002062 unsigned int pinctl;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002063 u32 alignment;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002064
Matt Roperebcdd392014-07-09 16:22:11 -07002065 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2066
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002067 alignment = intel_surf_alignment(fb, 0);
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002068
Chris Wilson693db182013-03-05 14:52:39 +00002069 /* Note that the w/a also requires 64 PTE of padding following the
2070 * bo. We currently fill all unused PTE with the shadow page and so
2071 * we should always have valid PTE following the scanout preventing
2072 * the VT-d warning.
2073 */
Chris Wilson48f112f2016-06-24 14:07:14 +01002074 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
Chris Wilson693db182013-03-05 14:52:39 +00002075 alignment = 256 * 1024;
2076
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002077 /*
2078 * Global gtt pte registers are special registers which actually forward
2079 * writes to a chunk of system memory. Which means that there is no risk
2080 * that the register values disappear as soon as we call
2081 * intel_runtime_pm_put(), so it is correct to wrap only the
2082 * pin/unpin/fence and not more.
2083 */
Chris Wilson1d264d92019-01-14 14:21:19 +00002084 wakeref = intel_runtime_pm_get(dev_priv);
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002085
Daniel Vetter9db529a2017-08-08 10:08:28 +02002086 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2087
Chris Wilson59354852018-02-20 13:42:06 +00002088 pinctl = 0;
2089
2090 /* Valleyview is definitely limited to scanning out the first
2091 * 512MiB. Lets presume this behaviour was inherited from the
2092 * g4x display engine and that all earlier gen are similarly
2093 * limited. Testing suggests that it is a little more
2094 * complicated than this. For example, Cherryview appears quite
2095 * happy to scanout from anywhere within its global aperture.
2096 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08002097 if (HAS_GMCH(dev_priv))
Chris Wilson59354852018-02-20 13:42:06 +00002098 pinctl |= PIN_MAPPABLE;
2099
2100 vma = i915_gem_object_pin_to_display_plane(obj,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002101 alignment, view, pinctl);
Chris Wilson49ef5292016-08-18 17:17:00 +01002102 if (IS_ERR(vma))
2103 goto err;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002104
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002105 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002106 int ret;
2107
Chris Wilson49ef5292016-08-18 17:17:00 +01002108 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2109 * fence, whereas 965+ only requires a fence if using
2110 * framebuffer compression. For simplicity, we always, when
2111 * possible, install a fence as the cost is not that onerous.
2112 *
2113 * If we fail to fence the tiled scanout, then either the
2114 * modeset will reject the change (which is highly unlikely as
2115 * the affected systems, all but one, do not have unmappable
2116 * space) or we will not be able to enable full powersaving
2117 * techniques (also likely not to apply due to various limits
2118 * FBC and the like impose on the size of the buffer, which
2119 * presumably we violated anyway with this unmappable buffer).
2120 * Anyway, it is presumably better to stumble onwards with
2121 * something and try to run the system in a "less than optimal"
2122 * mode that matches the user configuration.
2123 */
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002124 ret = i915_vma_pin_fence(vma);
2125 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
Chris Wilson75097022018-03-05 10:33:12 +00002126 i915_gem_object_unpin_from_display_plane(vma);
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002127 vma = ERR_PTR(ret);
2128 goto err;
2129 }
2130
2131 if (ret == 0 && vma->fence)
Chris Wilson59354852018-02-20 13:42:06 +00002132 *out_flags |= PLANE_HAS_FENCE;
Vivek Kasireddy98072162015-10-29 18:54:38 -07002133 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002134
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002135 i915_vma_get(vma);
Chris Wilson49ef5292016-08-18 17:17:00 +01002136err:
Daniel Vetter9db529a2017-08-08 10:08:28 +02002137 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2138
Chris Wilson1d264d92019-01-14 14:21:19 +00002139 intel_runtime_pm_put(dev_priv, wakeref);
Chris Wilson058d88c2016-08-15 10:49:06 +01002140 return vma;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002141}
2142
Chris Wilson59354852018-02-20 13:42:06 +00002143void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
Chris Wilson1690e1e2011-12-14 13:57:08 +01002144{
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002145 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00002146
Chris Wilson59354852018-02-20 13:42:06 +00002147 if (flags & PLANE_HAS_FENCE)
2148 i915_vma_unpin_fence(vma);
Chris Wilson058d88c2016-08-15 10:49:06 +01002149 i915_gem_object_unpin_from_display_plane(vma);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002150 i915_vma_put(vma);
Chris Wilson1690e1e2011-12-14 13:57:08 +01002151}
2152
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002153static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002154 unsigned int rotation)
2155{
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002156 if (drm_rotation_90_or_270(rotation))
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002157 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002158 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002159 return fb->pitches[color_plane];
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002160}
2161
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002162/*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002163 * Convert the x/y offsets into a linear offset.
2164 * Only valid with 0/180 degree rotation, which is fine since linear
2165 * offset is only used with linear buffers on pre-hsw and tiled buffers
2166 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2167 */
2168u32 intel_fb_xy_to_linear(int x, int y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002169 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002170 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002171{
Ville Syrjälä29490562016-01-20 18:02:50 +02002172 const struct drm_framebuffer *fb = state->base.fb;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002173 unsigned int cpp = fb->format->cpp[color_plane];
2174 unsigned int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002175
2176 return y * pitch + x * cpp;
2177}
2178
2179/*
2180 * Add the x/y offsets derived from fb->offsets[] to the user
2181 * specified plane src x/y offsets. The resulting x/y offsets
2182 * specify the start of scanout from the beginning of the gtt mapping.
2183 */
2184void intel_add_fb_offsets(int *x, int *y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002185 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002186 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002187
2188{
Ville Syrjälä29490562016-01-20 18:02:50 +02002189 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2190 unsigned int rotation = state->base.rotation;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002191
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002192 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002193 *x += intel_fb->rotated[color_plane].x;
2194 *y += intel_fb->rotated[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002195 } else {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002196 *x += intel_fb->normal[color_plane].x;
2197 *y += intel_fb->normal[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002198 }
2199}
2200
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002201static u32 intel_adjust_tile_offset(int *x, int *y,
2202 unsigned int tile_width,
2203 unsigned int tile_height,
2204 unsigned int tile_size,
2205 unsigned int pitch_tiles,
2206 u32 old_offset,
2207 u32 new_offset)
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002208{
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002209 unsigned int pitch_pixels = pitch_tiles * tile_width;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002210 unsigned int tiles;
2211
2212 WARN_ON(old_offset & (tile_size - 1));
2213 WARN_ON(new_offset & (tile_size - 1));
2214 WARN_ON(new_offset > old_offset);
2215
2216 tiles = (old_offset - new_offset) / tile_size;
2217
2218 *y += tiles / pitch_tiles * tile_height;
2219 *x += tiles % pitch_tiles * tile_width;
2220
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002221 /* minimize x in case it got needlessly big */
2222 *y += *x / pitch_pixels * tile_height;
2223 *x %= pitch_pixels;
2224
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002225 return new_offset;
2226}
2227
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002228static bool is_surface_linear(u64 modifier, int color_plane)
2229{
2230 return modifier == DRM_FORMAT_MOD_LINEAR;
2231}
2232
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002233static u32 intel_adjust_aligned_offset(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002234 const struct drm_framebuffer *fb,
2235 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002236 unsigned int rotation,
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002237 unsigned int pitch,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002238 u32 old_offset, u32 new_offset)
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002239{
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002240 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002241 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002242
2243 WARN_ON(new_offset > old_offset);
2244
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002245 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002246 unsigned int tile_size, tile_width, tile_height;
2247 unsigned int pitch_tiles;
2248
2249 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002250 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002251
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002252 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002253 pitch_tiles = pitch / tile_height;
2254 swap(tile_width, tile_height);
2255 } else {
2256 pitch_tiles = pitch / (tile_width * cpp);
2257 }
2258
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002259 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2260 tile_size, pitch_tiles,
2261 old_offset, new_offset);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002262 } else {
2263 old_offset += *y * pitch + *x * cpp;
2264
2265 *y = (old_offset - new_offset) / pitch;
2266 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2267 }
2268
2269 return new_offset;
2270}
2271
2272/*
Ville Syrjälä303ba692017-08-24 22:10:49 +03002273 * Adjust the tile offset by moving the difference into
2274 * the x/y offsets.
2275 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002276static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2277 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002278 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002279 u32 old_offset, u32 new_offset)
Ville Syrjälä303ba692017-08-24 22:10:49 +03002280{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002281 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002282 state->base.rotation,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002283 state->color_plane[color_plane].stride,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002284 old_offset, new_offset);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002285}
2286
2287/*
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002288 * Computes the aligned offset to the base tile and adjusts
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002289 * x, y. bytes per pixel is assumed to be a power-of-two.
2290 *
2291 * In the 90/270 rotated case, x and y are assumed
2292 * to be already rotated to match the rotated GTT view, and
2293 * pitch is the tile_height aligned framebuffer height.
Ville Syrjälä6687c902015-09-15 13:16:41 +03002294 *
2295 * This function is used when computing the derived information
2296 * under intel_framebuffer, so using any of that information
2297 * here is not allowed. Anything under drm_framebuffer can be
2298 * used. This is why the user has to pass in the pitch since it
2299 * is specified in the rotated orientation.
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002300 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002301static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2302 int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002303 const struct drm_framebuffer *fb,
2304 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002305 unsigned int pitch,
2306 unsigned int rotation,
2307 u32 alignment)
Daniel Vetterc2c75132012-07-05 12:17:30 +02002308{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002309 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä6687c902015-09-15 13:16:41 +03002310 u32 offset, offset_aligned;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002311
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002312 if (alignment)
2313 alignment--;
2314
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002315 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002316 unsigned int tile_size, tile_width, tile_height;
2317 unsigned int tile_rows, tiles, pitch_tiles;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002318
Ville Syrjäläd8433102016-01-12 21:08:35 +02002319 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002320 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002321
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002322 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002323 pitch_tiles = pitch / tile_height;
2324 swap(tile_width, tile_height);
2325 } else {
2326 pitch_tiles = pitch / (tile_width * cpp);
2327 }
Daniel Vetterc2c75132012-07-05 12:17:30 +02002328
Ville Syrjäläd8433102016-01-12 21:08:35 +02002329 tile_rows = *y / tile_height;
2330 *y %= tile_height;
Chris Wilsonbc752862013-02-21 20:04:31 +00002331
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002332 tiles = *x / tile_width;
2333 *x %= tile_width;
Ville Syrjäläd8433102016-01-12 21:08:35 +02002334
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002335 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2336 offset_aligned = offset & ~alignment;
Chris Wilsonbc752862013-02-21 20:04:31 +00002337
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002338 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2339 tile_size, pitch_tiles,
2340 offset, offset_aligned);
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002341 } else {
Chris Wilsonbc752862013-02-21 20:04:31 +00002342 offset = *y * pitch + *x * cpp;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002343 offset_aligned = offset & ~alignment;
2344
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002345 *y = (offset & alignment) / pitch;
2346 *x = ((offset & alignment) - *y * pitch) / cpp;
Chris Wilsonbc752862013-02-21 20:04:31 +00002347 }
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002348
2349 return offset_aligned;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002350}
2351
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002352static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2353 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002354 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002355{
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002356 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2357 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
Ville Syrjälä29490562016-01-20 18:02:50 +02002358 const struct drm_framebuffer *fb = state->base.fb;
2359 unsigned int rotation = state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002360 int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002361 u32 alignment;
2362
2363 if (intel_plane->id == PLANE_CURSOR)
2364 alignment = intel_cursor_alignment(dev_priv);
2365 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002366 alignment = intel_surf_alignment(fb, color_plane);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002367
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002368 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002369 pitch, rotation, alignment);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002370}
2371
Ville Syrjälä303ba692017-08-24 22:10:49 +03002372/* Convert the fb->offset[] into x/y offsets */
2373static int intel_fb_offset_to_xy(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002374 const struct drm_framebuffer *fb,
2375 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002376{
Ville Syrjälä303ba692017-08-24 22:10:49 +03002377 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002378 unsigned int height;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002379
Ville Syrjälä303ba692017-08-24 22:10:49 +03002380 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002381 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2382 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2383 fb->offsets[color_plane], color_plane);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002384 return -EINVAL;
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002385 }
2386
2387 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2388 height = ALIGN(height, intel_tile_height(fb, color_plane));
2389
2390 /* Catch potential overflows early */
2391 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2392 fb->offsets[color_plane])) {
2393 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2394 fb->offsets[color_plane], fb->pitches[color_plane],
2395 color_plane);
2396 return -ERANGE;
2397 }
Ville Syrjälä303ba692017-08-24 22:10:49 +03002398
2399 *x = 0;
2400 *y = 0;
2401
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002402 intel_adjust_aligned_offset(x, y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002403 fb, color_plane, DRM_MODE_ROTATE_0,
2404 fb->pitches[color_plane],
2405 fb->offsets[color_plane], 0);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002406
2407 return 0;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002408}
2409
Jani Nikulaba3f4d02019-01-18 14:01:23 +02002410static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002411{
2412 switch (fb_modifier) {
2413 case I915_FORMAT_MOD_X_TILED:
2414 return I915_TILING_X;
2415 case I915_FORMAT_MOD_Y_TILED:
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002416 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002417 return I915_TILING_Y;
2418 default:
2419 return I915_TILING_NONE;
2420 }
2421}
2422
Ville Syrjälä16af25f2018-01-19 16:41:52 +02002423/*
2424 * From the Sky Lake PRM:
2425 * "The Color Control Surface (CCS) contains the compression status of
2426 * the cache-line pairs. The compression state of the cache-line pair
2427 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2428 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2429 * cache-line-pairs. CCS is always Y tiled."
2430 *
2431 * Since cache line pairs refers to horizontally adjacent cache lines,
2432 * each cache line in the CCS corresponds to an area of 32x16 cache
2433 * lines on the main surface. Since each pixel is 4 bytes, this gives
2434 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2435 * main surface.
2436 */
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -07002437static const struct drm_format_info ccs_formats[] = {
2438 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2439 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2440 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2441 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2442};
2443
2444static const struct drm_format_info *
2445lookup_format_info(const struct drm_format_info formats[],
2446 int num_formats, u32 format)
2447{
2448 int i;
2449
2450 for (i = 0; i < num_formats; i++) {
2451 if (formats[i].format == format)
2452 return &formats[i];
2453 }
2454
2455 return NULL;
2456}
2457
2458static const struct drm_format_info *
2459intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2460{
2461 switch (cmd->modifier[0]) {
2462 case I915_FORMAT_MOD_Y_TILED_CCS:
2463 case I915_FORMAT_MOD_Yf_TILED_CCS:
2464 return lookup_format_info(ccs_formats,
2465 ARRAY_SIZE(ccs_formats),
2466 cmd->pixel_format);
2467 default:
2468 return NULL;
2469 }
2470}
2471
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002472bool is_ccs_modifier(u64 modifier)
2473{
2474 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2475 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2476}
2477
Ville Syrjälä6687c902015-09-15 13:16:41 +03002478static int
2479intel_fill_fb_info(struct drm_i915_private *dev_priv,
2480 struct drm_framebuffer *fb)
2481{
2482 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2483 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002484 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002485 u32 gtt_offset_rotated = 0;
2486 unsigned int max_size = 0;
Ville Syrjäläbcb0b462016-12-14 23:30:22 +02002487 int i, num_planes = fb->format->num_planes;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002488 unsigned int tile_size = intel_tile_size(dev_priv);
2489
2490 for (i = 0; i < num_planes; i++) {
2491 unsigned int width, height;
2492 unsigned int cpp, size;
2493 u32 offset;
2494 int x, y;
Ville Syrjälä303ba692017-08-24 22:10:49 +03002495 int ret;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002496
Ville Syrjälä353c8592016-12-14 23:30:57 +02002497 cpp = fb->format->cpp[i];
Ville Syrjälä145fcb12016-11-18 21:53:06 +02002498 width = drm_framebuffer_plane_width(fb->width, fb, i);
2499 height = drm_framebuffer_plane_height(fb->height, fb, i);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002500
Ville Syrjälä303ba692017-08-24 22:10:49 +03002501 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2502 if (ret) {
2503 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2504 i, fb->offsets[i]);
2505 return ret;
2506 }
Ville Syrjälä6687c902015-09-15 13:16:41 +03002507
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002508 if (is_ccs_modifier(fb->modifier) && i == 1) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002509 int hsub = fb->format->hsub;
2510 int vsub = fb->format->vsub;
2511 int tile_width, tile_height;
2512 int main_x, main_y;
2513 int ccs_x, ccs_y;
2514
2515 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002516 tile_width *= hsub;
2517 tile_height *= vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002518
Ville Syrjälä303ba692017-08-24 22:10:49 +03002519 ccs_x = (x * hsub) % tile_width;
2520 ccs_y = (y * vsub) % tile_height;
2521 main_x = intel_fb->normal[0].x % tile_width;
2522 main_y = intel_fb->normal[0].y % tile_height;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002523
2524 /*
2525 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2526 * x/y offsets must match between CCS and the main surface.
2527 */
2528 if (main_x != ccs_x || main_y != ccs_y) {
2529 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2530 main_x, main_y,
2531 ccs_x, ccs_y,
2532 intel_fb->normal[0].x,
2533 intel_fb->normal[0].y,
2534 x, y);
2535 return -EINVAL;
2536 }
2537 }
2538
Ville Syrjälä6687c902015-09-15 13:16:41 +03002539 /*
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002540 * The fence (if used) is aligned to the start of the object
2541 * so having the framebuffer wrap around across the edge of the
2542 * fenced region doesn't really work. We have no API to configure
2543 * the fence start offset within the object (nor could we probably
2544 * on gen2/3). So it's just easier if we just require that the
2545 * fb layout agrees with the fence layout. We already check that the
2546 * fb stride matches the fence stride elsewhere.
2547 */
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002548 if (i == 0 && i915_gem_object_is_tiled(obj) &&
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002549 (x + width) * cpp > fb->pitches[i]) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +02002550 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2551 i, fb->offsets[i]);
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002552 return -EINVAL;
2553 }
2554
2555 /*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002556 * First pixel of the framebuffer from
2557 * the start of the normal gtt mapping.
2558 */
2559 intel_fb->normal[i].x = x;
2560 intel_fb->normal[i].y = y;
2561
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002562 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2563 fb->pitches[i],
2564 DRM_MODE_ROTATE_0,
2565 tile_size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002566 offset /= tile_size;
2567
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002568 if (!is_surface_linear(fb->modifier, i)) {
Ville Syrjälä6687c902015-09-15 13:16:41 +03002569 unsigned int tile_width, tile_height;
2570 unsigned int pitch_tiles;
2571 struct drm_rect r;
2572
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002573 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002574
2575 rot_info->plane[i].offset = offset;
2576 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2577 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2578 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2579
2580 intel_fb->rotated[i].pitch =
2581 rot_info->plane[i].height * tile_height;
2582
2583 /* how many tiles does this plane need */
2584 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2585 /*
2586 * If the plane isn't horizontally tile aligned,
2587 * we need one more tile.
2588 */
2589 if (x != 0)
2590 size++;
2591
2592 /* rotate the x/y offsets to match the GTT view */
2593 r.x1 = x;
2594 r.y1 = y;
2595 r.x2 = x + width;
2596 r.y2 = y + height;
2597 drm_rect_rotate(&r,
2598 rot_info->plane[i].width * tile_width,
2599 rot_info->plane[i].height * tile_height,
Robert Fossc2c446a2017-05-19 16:50:17 -04002600 DRM_MODE_ROTATE_270);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002601 x = r.x1;
2602 y = r.y1;
2603
2604 /* rotate the tile dimensions to match the GTT view */
2605 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2606 swap(tile_width, tile_height);
2607
2608 /*
2609 * We only keep the x/y offsets, so push all of the
2610 * gtt offset into the x/y offsets.
2611 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002612 intel_adjust_tile_offset(&x, &y,
2613 tile_width, tile_height,
2614 tile_size, pitch_tiles,
2615 gtt_offset_rotated * tile_size, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002616
2617 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2618
2619 /*
2620 * First pixel of the framebuffer from
2621 * the start of the rotated gtt mapping.
2622 */
2623 intel_fb->rotated[i].x = x;
2624 intel_fb->rotated[i].y = y;
2625 } else {
2626 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2627 x * cpp, tile_size);
2628 }
2629
2630 /* how many tiles in total needed in the bo */
2631 max_size = max(max_size, offset + size);
2632 }
2633
Ville Syrjälä4e050472018-09-12 21:04:43 +03002634 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2635 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2636 mul_u32_u32(max_size, tile_size), obj->base.size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002637 return -EINVAL;
2638 }
2639
2640 return 0;
2641}
2642
Damien Lespiaub35d63f2015-01-20 12:51:50 +00002643static int i9xx_format_to_fourcc(int format)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002644{
2645 switch (format) {
2646 case DISPPLANE_8BPP:
2647 return DRM_FORMAT_C8;
2648 case DISPPLANE_BGRX555:
2649 return DRM_FORMAT_XRGB1555;
2650 case DISPPLANE_BGRX565:
2651 return DRM_FORMAT_RGB565;
2652 default:
2653 case DISPPLANE_BGRX888:
2654 return DRM_FORMAT_XRGB8888;
2655 case DISPPLANE_RGBX888:
2656 return DRM_FORMAT_XBGR8888;
2657 case DISPPLANE_BGRX101010:
2658 return DRM_FORMAT_XRGB2101010;
2659 case DISPPLANE_RGBX101010:
2660 return DRM_FORMAT_XBGR2101010;
2661 }
2662}
2663
Mahesh Kumarddf34312018-04-09 09:11:03 +05302664int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002665{
2666 switch (format) {
2667 case PLANE_CTL_FORMAT_RGB_565:
2668 return DRM_FORMAT_RGB565;
Mahesh Kumarf34a2912018-04-09 09:11:02 +05302669 case PLANE_CTL_FORMAT_NV12:
2670 return DRM_FORMAT_NV12;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002671 default:
2672 case PLANE_CTL_FORMAT_XRGB_8888:
2673 if (rgb_order) {
2674 if (alpha)
2675 return DRM_FORMAT_ABGR8888;
2676 else
2677 return DRM_FORMAT_XBGR8888;
2678 } else {
2679 if (alpha)
2680 return DRM_FORMAT_ARGB8888;
2681 else
2682 return DRM_FORMAT_XRGB8888;
2683 }
2684 case PLANE_CTL_FORMAT_XRGB_2101010:
2685 if (rgb_order)
2686 return DRM_FORMAT_XBGR2101010;
2687 else
2688 return DRM_FORMAT_XRGB2101010;
2689 }
2690}
2691
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002692static bool
Daniel Vetterf6936e22015-03-26 12:17:05 +01002693intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2694 struct intel_initial_plane_config *plane_config)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002695{
2696 struct drm_device *dev = crtc->base.dev;
Paulo Zanoni3badb492015-09-23 12:52:23 -03002697 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002698 struct drm_i915_gem_object *obj = NULL;
2699 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
Damien Lespiau2d140302015-02-05 17:22:18 +00002700 struct drm_framebuffer *fb = &plane_config->fb->base;
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002701 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2702 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2703 PAGE_SIZE);
2704
2705 size_aligned -= base_aligned;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002706
Chris Wilsonff2652e2014-03-10 08:07:02 +00002707 if (plane_config->size == 0)
2708 return false;
2709
Paulo Zanoni3badb492015-09-23 12:52:23 -03002710 /* If the FB is too big, just don't use it since fbdev is not very
2711 * important and we should probably use that space with FBC or other
2712 * features. */
Matthew Auldb1ace602017-12-11 15:18:21 +00002713 if (size_aligned * 2 > dev_priv->stolen_usable_size)
Paulo Zanoni3badb492015-09-23 12:52:23 -03002714 return false;
2715
Imre Deak914a4fd2018-10-16 19:00:11 +03002716 switch (fb->modifier) {
2717 case DRM_FORMAT_MOD_LINEAR:
2718 case I915_FORMAT_MOD_X_TILED:
2719 case I915_FORMAT_MOD_Y_TILED:
2720 break;
2721 default:
2722 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2723 fb->modifier);
2724 return false;
2725 }
2726
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002727 mutex_lock(&dev->struct_mutex);
Tvrtko Ursulin187685c2016-12-01 14:16:36 +00002728 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002729 base_aligned,
2730 base_aligned,
2731 size_aligned);
Chris Wilson24dbf512017-02-15 10:59:18 +00002732 mutex_unlock(&dev->struct_mutex);
2733 if (!obj)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002734 return false;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002735
Imre Deak914a4fd2018-10-16 19:00:11 +03002736 switch (plane_config->tiling) {
2737 case I915_TILING_NONE:
2738 break;
2739 case I915_TILING_X:
2740 case I915_TILING_Y:
2741 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2742 break;
2743 default:
2744 MISSING_CASE(plane_config->tiling);
2745 return false;
2746 }
Jesse Barnes46f297f2014-03-07 08:57:48 -08002747
Ville Syrjälä438b74a2016-12-14 23:32:55 +02002748 mode_cmd.pixel_format = fb->format->format;
Damien Lespiau6bf129d2015-02-05 17:22:16 +00002749 mode_cmd.width = fb->width;
2750 mode_cmd.height = fb->height;
2751 mode_cmd.pitches[0] = fb->pitches[0];
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002752 mode_cmd.modifier[0] = fb->modifier;
Daniel Vetter18c52472015-02-10 17:16:09 +00002753 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002754
Chris Wilson24dbf512017-02-15 10:59:18 +00002755 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
Jesse Barnes46f297f2014-03-07 08:57:48 -08002756 DRM_DEBUG_KMS("intel fb init failed\n");
2757 goto out_unref_obj;
2758 }
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002759
Jesse Barnes484b41d2014-03-07 08:57:55 -08002760
Daniel Vetterf6936e22015-03-26 12:17:05 +01002761 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002762 return true;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002763
2764out_unref_obj:
Chris Wilsonf8c417c2016-07-20 13:31:53 +01002765 i915_gem_object_put(obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002766 return false;
2767}
2768
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002769static void
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002770intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2771 struct intel_plane_state *plane_state,
2772 bool visible)
2773{
2774 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2775
2776 plane_state->base.visible = visible;
2777
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002778 if (visible)
Ville Syrjälä40560e22018-06-26 22:47:11 +03002779 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002780 else
Ville Syrjälä40560e22018-06-26 22:47:11 +03002781 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002782}
2783
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002784static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2785{
2786 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2787 struct drm_plane *plane;
2788
2789 /*
2790 * Active_planes aliases if multiple "primary" or cursor planes
2791 * have been used on the same (or wrong) pipe. plane_mask uses
2792 * unique ids, hence we can use that to reconstruct active_planes.
2793 */
2794 crtc_state->active_planes = 0;
2795
2796 drm_for_each_plane_mask(plane, &dev_priv->drm,
2797 crtc_state->base.plane_mask)
2798 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2799}
2800
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002801static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2802 struct intel_plane *plane)
2803{
2804 struct intel_crtc_state *crtc_state =
2805 to_intel_crtc_state(crtc->base.state);
2806 struct intel_plane_state *plane_state =
2807 to_intel_plane_state(plane->base.state);
2808
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +03002809 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2810 plane->base.base.id, plane->base.name,
2811 crtc->base.base.id, crtc->base.name);
2812
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002813 intel_set_plane_visible(crtc_state, plane_state, false);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002814 fixup_active_planes(crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002815
2816 if (plane->id == PLANE_PRIMARY)
2817 intel_pre_disable_primary_noatomic(&crtc->base);
2818
2819 trace_intel_disable_plane(&plane->base, crtc);
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02002820 plane->disable_plane(plane, crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002821}
2822
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002823static void
Daniel Vetterf6936e22015-03-26 12:17:05 +01002824intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2825 struct intel_initial_plane_config *plane_config)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002826{
2827 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002828 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002829 struct drm_crtc *c;
Matt Roper2ff8fde2014-07-08 07:50:07 -07002830 struct drm_i915_gem_object *obj;
Daniel Vetter88595ac2015-03-26 12:42:24 +01002831 struct drm_plane *primary = intel_crtc->base.primary;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002832 struct drm_plane_state *plane_state = primary->state;
Matt Roper200757f2015-12-03 11:37:36 -08002833 struct intel_plane *intel_plane = to_intel_plane(primary);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002834 struct intel_plane_state *intel_state =
2835 to_intel_plane_state(plane_state);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002836 struct drm_framebuffer *fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002837
Damien Lespiau2d140302015-02-05 17:22:18 +00002838 if (!plane_config->fb)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002839 return;
2840
Daniel Vetterf6936e22015-03-26 12:17:05 +01002841 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
Daniel Vetter88595ac2015-03-26 12:42:24 +01002842 fb = &plane_config->fb->base;
2843 goto valid_fb;
Damien Lespiauf55548b2015-02-05 18:30:20 +00002844 }
Jesse Barnes484b41d2014-03-07 08:57:55 -08002845
Damien Lespiau2d140302015-02-05 17:22:18 +00002846 kfree(plane_config->fb);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002847
2848 /*
2849 * Failed to alloc the obj, check to see if we should share
2850 * an fb with another CRTC instead
2851 */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +01002852 for_each_crtc(dev, c) {
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002853 struct intel_plane_state *state;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002854
2855 if (c == &intel_crtc->base)
2856 continue;
2857
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002858 if (!to_intel_crtc(c)->active)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002859 continue;
2860
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002861 state = to_intel_plane_state(c->primary->state);
2862 if (!state->vma)
Matt Roper2ff8fde2014-07-08 07:50:07 -07002863 continue;
2864
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002865 if (intel_plane_ggtt_offset(state) == plane_config->base) {
Ville Syrjälä8bc20f62018-03-22 17:22:59 +02002866 fb = state->base.fb;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302867 drm_framebuffer_get(fb);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002868 goto valid_fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002869 }
2870 }
Daniel Vetter88595ac2015-03-26 12:42:24 +01002871
Matt Roper200757f2015-12-03 11:37:36 -08002872 /*
2873 * We've failed to reconstruct the BIOS FB. Current display state
2874 * indicates that the primary plane is visible, but has a NULL FB,
2875 * which will lead to problems later if we don't fix it up. The
2876 * simplest solution is to just disable the primary plane now and
2877 * pretend the BIOS never had it enabled.
2878 */
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002879 intel_plane_disable_noatomic(intel_crtc, intel_plane);
Matt Roper200757f2015-12-03 11:37:36 -08002880
Daniel Vetter88595ac2015-03-26 12:42:24 +01002881 return;
2882
2883valid_fb:
Ville Syrjäläf43348a2018-11-20 15:54:50 +02002884 intel_state->base.rotation = plane_config->rotation;
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002885 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2886 intel_state->base.rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002887 intel_state->color_plane[0].stride =
2888 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2889
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002890 mutex_lock(&dev->struct_mutex);
2891 intel_state->vma =
Chris Wilson59354852018-02-20 13:42:06 +00002892 intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002893 &intel_state->view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002894 intel_plane_uses_fence(intel_state),
Chris Wilson59354852018-02-20 13:42:06 +00002895 &intel_state->flags);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002896 mutex_unlock(&dev->struct_mutex);
2897 if (IS_ERR(intel_state->vma)) {
2898 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2899 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2900
2901 intel_state->vma = NULL;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302902 drm_framebuffer_put(fb);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002903 return;
2904 }
2905
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -08002906 obj = intel_fb_obj(fb);
2907 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2908
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002909 plane_state->src_x = 0;
2910 plane_state->src_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002911 plane_state->src_w = fb->width << 16;
2912 plane_state->src_h = fb->height << 16;
2913
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002914 plane_state->crtc_x = 0;
2915 plane_state->crtc_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002916 plane_state->crtc_w = fb->width;
2917 plane_state->crtc_h = fb->height;
2918
Rob Clark1638d302016-11-05 11:08:08 -04002919 intel_state->base.src = drm_plane_state_src(plane_state);
2920 intel_state->base.dst = drm_plane_state_dest(plane_state);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002921
Chris Wilson3e510a82016-08-05 10:14:23 +01002922 if (i915_gem_object_is_tiled(obj))
Daniel Vetter88595ac2015-03-26 12:42:24 +01002923 dev_priv->preserve_bios_swizzle = true;
2924
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +03002925 plane_state->fb = fb;
2926 plane_state->crtc = &intel_crtc->base;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002927
Chris Wilsonfaf5bf02016-08-04 16:32:37 +01002928 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2929 &obj->frontbuffer_bits);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002930}
2931
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002932static int skl_max_plane_width(const struct drm_framebuffer *fb,
2933 int color_plane,
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002934 unsigned int rotation)
2935{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002936 int cpp = fb->format->cpp[color_plane];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002937
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002938 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002939 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002940 case I915_FORMAT_MOD_X_TILED:
2941 switch (cpp) {
2942 case 8:
2943 return 4096;
2944 case 4:
2945 case 2:
2946 case 1:
2947 return 8192;
2948 default:
2949 MISSING_CASE(cpp);
2950 break;
2951 }
2952 break;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002953 case I915_FORMAT_MOD_Y_TILED_CCS:
2954 case I915_FORMAT_MOD_Yf_TILED_CCS:
2955 /* FIXME AUX plane? */
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002956 case I915_FORMAT_MOD_Y_TILED:
2957 case I915_FORMAT_MOD_Yf_TILED:
2958 switch (cpp) {
2959 case 8:
2960 return 2048;
2961 case 4:
2962 return 4096;
2963 case 2:
2964 case 1:
2965 return 8192;
2966 default:
2967 MISSING_CASE(cpp);
2968 break;
2969 }
2970 break;
2971 default:
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002972 MISSING_CASE(fb->modifier);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002973 }
2974
2975 return 2048;
2976}
2977
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002978static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2979 int main_x, int main_y, u32 main_offset)
2980{
2981 const struct drm_framebuffer *fb = plane_state->base.fb;
2982 int hsub = fb->format->hsub;
2983 int vsub = fb->format->vsub;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002984 int aux_x = plane_state->color_plane[1].x;
2985 int aux_y = plane_state->color_plane[1].y;
2986 u32 aux_offset = plane_state->color_plane[1].offset;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002987 u32 alignment = intel_surf_alignment(fb, 1);
2988
2989 while (aux_offset >= main_offset && aux_y <= main_y) {
2990 int x, y;
2991
2992 if (aux_x == main_x && aux_y == main_y)
2993 break;
2994
2995 if (aux_offset == 0)
2996 break;
2997
2998 x = aux_x / hsub;
2999 y = aux_y / vsub;
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003000 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3001 aux_offset, aux_offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003002 aux_x = x * hsub + aux_x % hsub;
3003 aux_y = y * vsub + aux_y % vsub;
3004 }
3005
3006 if (aux_x != main_x || aux_y != main_y)
3007 return false;
3008
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003009 plane_state->color_plane[1].offset = aux_offset;
3010 plane_state->color_plane[1].x = aux_x;
3011 plane_state->color_plane[1].y = aux_y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003012
3013 return true;
3014}
3015
Ville Syrjälä73266592018-09-07 18:24:11 +03003016static int skl_check_main_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003017{
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003018 const struct drm_framebuffer *fb = plane_state->base.fb;
3019 unsigned int rotation = plane_state->base.rotation;
Daniel Vettercc926382016-08-15 10:41:47 +02003020 int x = plane_state->base.src.x1 >> 16;
3021 int y = plane_state->base.src.y1 >> 16;
3022 int w = drm_rect_width(&plane_state->base.src) >> 16;
3023 int h = drm_rect_height(&plane_state->base.src) >> 16;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003024 int max_width = skl_max_plane_width(fb, 0, rotation);
3025 int max_height = 4096;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003026 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003027
3028 if (w > max_width || h > max_height) {
3029 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3030 w, h, max_width, max_height);
3031 return -EINVAL;
3032 }
3033
3034 intel_add_fb_offsets(&x, &y, plane_state, 0);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003035 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003036 alignment = intel_surf_alignment(fb, 0);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003037
3038 /*
Ville Syrjälä8d970652016-01-28 16:30:28 +02003039 * AUX surface offset is specified as the distance from the
3040 * main surface offset, and it must be non-negative. Make
3041 * sure that is what we will get.
3042 */
3043 if (offset > aux_offset)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003044 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3045 offset, aux_offset & ~(alignment - 1));
Ville Syrjälä8d970652016-01-28 16:30:28 +02003046
3047 /*
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003048 * When using an X-tiled surface, the plane blows up
3049 * if the x offset + width exceed the stride.
3050 *
3051 * TODO: linear and Y-tiled seem fine, Yf untested,
3052 */
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003053 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
Ville Syrjälä353c8592016-12-14 23:30:57 +02003054 int cpp = fb->format->cpp[0];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003055
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003056 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003057 if (offset == 0) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003058 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003059 return -EINVAL;
3060 }
3061
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003062 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3063 offset, offset - alignment);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003064 }
3065 }
3066
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003067 /*
3068 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3069 * they match with the main surface x/y offsets.
3070 */
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003071 if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003072 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3073 if (offset == 0)
3074 break;
3075
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003076 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3077 offset, offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003078 }
3079
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003080 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003081 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3082 return -EINVAL;
3083 }
3084 }
3085
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003086 plane_state->color_plane[0].offset = offset;
3087 plane_state->color_plane[0].x = x;
3088 plane_state->color_plane[0].y = y;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003089
3090 return 0;
3091}
3092
Ville Syrjälä8d970652016-01-28 16:30:28 +02003093static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3094{
3095 const struct drm_framebuffer *fb = plane_state->base.fb;
3096 unsigned int rotation = plane_state->base.rotation;
3097 int max_width = skl_max_plane_width(fb, 1, rotation);
3098 int max_height = 4096;
Daniel Vettercc926382016-08-15 10:41:47 +02003099 int x = plane_state->base.src.x1 >> 17;
3100 int y = plane_state->base.src.y1 >> 17;
3101 int w = drm_rect_width(&plane_state->base.src) >> 17;
3102 int h = drm_rect_height(&plane_state->base.src) >> 17;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003103 u32 offset;
3104
3105 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003106 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä8d970652016-01-28 16:30:28 +02003107
3108 /* FIXME not quite sure how/if these apply to the chroma plane */
3109 if (w > max_width || h > max_height) {
3110 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3111 w, h, max_width, max_height);
3112 return -EINVAL;
3113 }
3114
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003115 plane_state->color_plane[1].offset = offset;
3116 plane_state->color_plane[1].x = x;
3117 plane_state->color_plane[1].y = y;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003118
3119 return 0;
3120}
3121
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003122static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3123{
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003124 const struct drm_framebuffer *fb = plane_state->base.fb;
3125 int src_x = plane_state->base.src.x1 >> 16;
3126 int src_y = plane_state->base.src.y1 >> 16;
3127 int hsub = fb->format->hsub;
3128 int vsub = fb->format->vsub;
3129 int x = src_x / hsub;
3130 int y = src_y / vsub;
3131 u32 offset;
3132
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003133 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003134 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003135
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003136 plane_state->color_plane[1].offset = offset;
3137 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3138 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003139
3140 return 0;
3141}
3142
Ville Syrjälä73266592018-09-07 18:24:11 +03003143int skl_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003144{
3145 const struct drm_framebuffer *fb = plane_state->base.fb;
3146 unsigned int rotation = plane_state->base.rotation;
3147 int ret;
3148
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003149 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003150 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3151 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3152
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003153 ret = intel_plane_check_stride(plane_state);
3154 if (ret)
3155 return ret;
3156
Ville Syrjäläa5e4c7d2016-11-07 22:20:54 +02003157 if (!plane_state->base.visible)
3158 return 0;
3159
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003160 /* Rotate src coordinates to match rotated GTT view */
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03003161 if (drm_rotation_90_or_270(rotation))
Daniel Vettercc926382016-08-15 10:41:47 +02003162 drm_rect_rotate(&plane_state->base.src,
Ville Syrjäläda064b42016-10-24 19:13:04 +03003163 fb->width << 16, fb->height << 16,
Robert Fossc2c446a2017-05-19 16:50:17 -04003164 DRM_MODE_ROTATE_270);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003165
Ville Syrjälä8d970652016-01-28 16:30:28 +02003166 /*
3167 * Handle the AUX surface first since
3168 * the main surface setup depends on it.
3169 */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003170 if (fb->format->format == DRM_FORMAT_NV12) {
Ville Syrjälä8d970652016-01-28 16:30:28 +02003171 ret = skl_check_nv12_aux_surface(plane_state);
3172 if (ret)
3173 return ret;
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003174 } else if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003175 ret = skl_check_ccs_aux_surface(plane_state);
3176 if (ret)
3177 return ret;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003178 } else {
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003179 plane_state->color_plane[1].offset = ~0xfff;
3180 plane_state->color_plane[1].x = 0;
3181 plane_state->color_plane[1].y = 0;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003182 }
3183
Ville Syrjälä73266592018-09-07 18:24:11 +03003184 ret = skl_check_main_surface(plane_state);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003185 if (ret)
3186 return ret;
3187
3188 return 0;
3189}
3190
Ville Syrjäläddd57132018-09-07 18:24:02 +03003191unsigned int
3192i9xx_plane_max_stride(struct intel_plane *plane,
3193 u32 pixel_format, u64 modifier,
3194 unsigned int rotation)
3195{
3196 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3197
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08003198 if (!HAS_GMCH(dev_priv)) {
Ville Syrjäläddd57132018-09-07 18:24:02 +03003199 return 32*1024;
3200 } else if (INTEL_GEN(dev_priv) >= 4) {
3201 if (modifier == I915_FORMAT_MOD_X_TILED)
3202 return 16*1024;
3203 else
3204 return 32*1024;
3205 } else if (INTEL_GEN(dev_priv) >= 3) {
3206 if (modifier == I915_FORMAT_MOD_X_TILED)
3207 return 8*1024;
3208 else
3209 return 16*1024;
3210 } else {
3211 if (plane->i9xx_plane == PLANE_C)
3212 return 4*1024;
3213 else
3214 return 8*1024;
3215 }
3216}
3217
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003218static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
Jesse Barnes81255562010-08-02 12:07:50 -07003219{
Ville Syrjälä7145f602017-03-23 21:27:07 +02003220 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003221 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3222 u32 dspcntr = 0;
Ville Syrjäläc9ba6fa2014-08-27 17:48:41 +03003223
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003224 dspcntr |= DISPPLANE_GAMMA_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003225
Ville Syrjälä6a4407a2017-03-23 21:27:08 +02003226 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3227 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003228
Ville Syrjäläc154d1e2018-01-30 22:38:02 +02003229 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjäläd509e282017-03-27 21:55:32 +03003230 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003231
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003232 return dspcntr;
3233}
3234
3235static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3236 const struct intel_plane_state *plane_state)
3237{
3238 struct drm_i915_private *dev_priv =
3239 to_i915(plane_state->base.plane->dev);
3240 const struct drm_framebuffer *fb = plane_state->base.fb;
3241 unsigned int rotation = plane_state->base.rotation;
3242 u32 dspcntr;
3243
3244 dspcntr = DISPLAY_PLANE_ENABLE;
3245
3246 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3247 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
3248 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3249
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003250 switch (fb->format->format) {
Ville Syrjälä57779d02012-10-31 17:50:14 +02003251 case DRM_FORMAT_C8:
Jesse Barnes81255562010-08-02 12:07:50 -07003252 dspcntr |= DISPPLANE_8BPP;
3253 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003254 case DRM_FORMAT_XRGB1555:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003255 dspcntr |= DISPPLANE_BGRX555;
Jesse Barnes81255562010-08-02 12:07:50 -07003256 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003257 case DRM_FORMAT_RGB565:
3258 dspcntr |= DISPPLANE_BGRX565;
3259 break;
3260 case DRM_FORMAT_XRGB8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003261 dspcntr |= DISPPLANE_BGRX888;
3262 break;
3263 case DRM_FORMAT_XBGR8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003264 dspcntr |= DISPPLANE_RGBX888;
3265 break;
3266 case DRM_FORMAT_XRGB2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003267 dspcntr |= DISPPLANE_BGRX101010;
3268 break;
3269 case DRM_FORMAT_XBGR2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003270 dspcntr |= DISPPLANE_RGBX101010;
Jesse Barnes81255562010-08-02 12:07:50 -07003271 break;
3272 default:
Ville Syrjälä7145f602017-03-23 21:27:07 +02003273 MISSING_CASE(fb->format->format);
3274 return 0;
Jesse Barnes81255562010-08-02 12:07:50 -07003275 }
Ville Syrjälä57779d02012-10-31 17:50:14 +02003276
Ville Syrjälä72618eb2016-02-04 20:38:20 +02003277 if (INTEL_GEN(dev_priv) >= 4 &&
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003278 fb->modifier == I915_FORMAT_MOD_X_TILED)
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003279 dspcntr |= DISPPLANE_TILED;
Jesse Barnes81255562010-08-02 12:07:50 -07003280
Robert Fossc2c446a2017-05-19 16:50:17 -04003281 if (rotation & DRM_MODE_ROTATE_180)
Ville Syrjälädf0cd452016-11-14 18:53:59 +02003282 dspcntr |= DISPPLANE_ROTATE_180;
3283
Robert Fossc2c446a2017-05-19 16:50:17 -04003284 if (rotation & DRM_MODE_REFLECT_X)
Ville Syrjälä4ea7be22016-11-14 18:54:00 +02003285 dspcntr |= DISPPLANE_MIRROR;
3286
Ville Syrjälä7145f602017-03-23 21:27:07 +02003287 return dspcntr;
3288}
Ville Syrjäläde1aa622013-06-07 10:47:01 +03003289
Ville Syrjäläf9407ae2017-03-23 21:27:12 +02003290int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003291{
3292 struct drm_i915_private *dev_priv =
3293 to_i915(plane_state->base.plane->dev);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003294 const struct drm_framebuffer *fb = plane_state->base.fb;
3295 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003296 int src_x = plane_state->base.src.x1 >> 16;
3297 int src_y = plane_state->base.src.y1 >> 16;
3298 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003299 int ret;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003300
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003301 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003302 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3303
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003304 ret = intel_plane_check_stride(plane_state);
3305 if (ret)
3306 return ret;
3307
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003308 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
Jesse Barnes81255562010-08-02 12:07:50 -07003309
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003310 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003311 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3312 plane_state, 0);
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003313 else
3314 offset = 0;
Daniel Vettere506a0c2012-07-05 12:17:29 +02003315
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003316 /* HSW/BDW do this automagically in hardware */
3317 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003318 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3319 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3320
Robert Fossc2c446a2017-05-19 16:50:17 -04003321 if (rotation & DRM_MODE_ROTATE_180) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003322 src_x += src_w - 1;
3323 src_y += src_h - 1;
Robert Fossc2c446a2017-05-19 16:50:17 -04003324 } else if (rotation & DRM_MODE_REFLECT_X) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003325 src_x += src_w - 1;
3326 }
Sonika Jindal48404c12014-08-22 14:06:04 +05303327 }
3328
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003329 plane_state->color_plane[0].offset = offset;
3330 plane_state->color_plane[0].x = src_x;
3331 plane_state->color_plane[0].y = src_y;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003332
3333 return 0;
3334}
3335
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003336static int
3337i9xx_plane_check(struct intel_crtc_state *crtc_state,
3338 struct intel_plane_state *plane_state)
3339{
3340 int ret;
3341
Ville Syrjälä25721f82018-09-07 18:24:12 +03003342 ret = chv_plane_check_rotation(plane_state);
3343 if (ret)
3344 return ret;
3345
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003346 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3347 &crtc_state->base,
3348 DRM_PLANE_HELPER_NO_SCALING,
3349 DRM_PLANE_HELPER_NO_SCALING,
3350 false, true);
3351 if (ret)
3352 return ret;
3353
3354 if (!plane_state->base.visible)
3355 return 0;
3356
3357 ret = intel_plane_check_src_coordinates(plane_state);
3358 if (ret)
3359 return ret;
3360
3361 ret = i9xx_check_plane_surface(plane_state);
3362 if (ret)
3363 return ret;
3364
3365 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3366
3367 return 0;
3368}
3369
Ville Syrjäläed150302017-11-17 21:19:10 +02003370static void i9xx_update_plane(struct intel_plane *plane,
3371 const struct intel_crtc_state *crtc_state,
3372 const struct intel_plane_state *plane_state)
Ville Syrjälä7145f602017-03-23 21:27:07 +02003373{
Ville Syrjäläed150302017-11-17 21:19:10 +02003374 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläed150302017-11-17 21:19:10 +02003375 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003376 u32 linear_offset;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003377 int x = plane_state->color_plane[0].x;
3378 int y = plane_state->color_plane[0].y;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003379 unsigned long irqflags;
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003380 u32 dspaddr_offset;
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003381 u32 dspcntr;
3382
3383 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
Ville Syrjälä7145f602017-03-23 21:27:07 +02003384
Ville Syrjälä29490562016-01-20 18:02:50 +02003385 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03003386
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003387 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003388 dspaddr_offset = plane_state->color_plane[0].offset;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003389 else
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003390 dspaddr_offset = linear_offset;
Ville Syrjälä6687c902015-09-15 13:16:41 +03003391
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003392 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3393
Ville Syrjälä83234d12018-11-14 23:07:17 +02003394 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3395
Ville Syrjälä78587de2017-03-09 17:44:32 +02003396 if (INTEL_GEN(dev_priv) < 4) {
3397 /* pipesrc and dspsize control the size that is scaled from,
3398 * which should always be the user's requested size.
3399 */
Ville Syrjälä83234d12018-11-14 23:07:17 +02003400 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
Ville Syrjäläed150302017-11-17 21:19:10 +02003401 I915_WRITE_FW(DSPSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003402 ((crtc_state->pipe_src_h - 1) << 16) |
3403 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003404 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
Ville Syrjälä83234d12018-11-14 23:07:17 +02003405 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
Ville Syrjäläed150302017-11-17 21:19:10 +02003406 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003407 ((crtc_state->pipe_src_h - 1) << 16) |
3408 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003409 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
Ville Syrjälä78587de2017-03-09 17:44:32 +02003410 }
3411
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003412 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjäläed150302017-11-17 21:19:10 +02003413 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003414 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä83234d12018-11-14 23:07:17 +02003415 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3416 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3417 }
3418
3419 /*
3420 * The control register self-arms if the plane was previously
3421 * disabled. Try to make the plane enable atomic by writing
3422 * the control register just before the surface register.
3423 */
3424 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3425 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläed150302017-11-17 21:19:10 +02003426 I915_WRITE_FW(DSPSURF(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003427 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003428 dspaddr_offset);
Ville Syrjälä83234d12018-11-14 23:07:17 +02003429 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003430 I915_WRITE_FW(DSPADDR(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003431 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003432 dspaddr_offset);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003433
3434 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes17638cd2011-06-24 12:19:23 -07003435}
3436
Ville Syrjäläed150302017-11-17 21:19:10 +02003437static void i9xx_disable_plane(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02003438 const struct intel_crtc_state *crtc_state)
Jesse Barnes17638cd2011-06-24 12:19:23 -07003439{
Ville Syrjäläed150302017-11-17 21:19:10 +02003440 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3441 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003442 unsigned long irqflags;
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003443 u32 dspcntr;
3444
3445 /*
3446 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
3447 * enable on ilk+ affect the pipe bottom color as
3448 * well, so we must configure them even if the plane
3449 * is disabled.
3450 *
3451 * On pre-g4x there is no way to gamma correct the
3452 * pipe bottom color but we'll keep on doing this
3453 * anyway.
3454 */
3455 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003456
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003457 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3458
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003459 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
Ville Syrjäläed150302017-11-17 21:19:10 +02003460 if (INTEL_GEN(dev_priv) >= 4)
3461 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003462 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003463 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003464
3465 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003466}
3467
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003468static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3469 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003470{
Ville Syrjäläed150302017-11-17 21:19:10 +02003471 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003472 enum intel_display_power_domain power_domain;
Ville Syrjäläed150302017-11-17 21:19:10 +02003473 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00003474 intel_wakeref_t wakeref;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003475 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003476 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003477
3478 /*
3479 * Not 100% correct for planes that can move between pipes,
3480 * but that's only the case for gen2-4 which don't have any
3481 * display power wells.
3482 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003483 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00003484 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3485 if (!wakeref)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003486 return false;
3487
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003488 val = I915_READ(DSPCNTR(i9xx_plane));
3489
3490 ret = val & DISPLAY_PLANE_ENABLE;
3491
3492 if (INTEL_GEN(dev_priv) >= 5)
3493 *pipe = plane->pipe;
3494 else
3495 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3496 DISPPLANE_SEL_PIPE_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003497
Chris Wilson0e6e0be2019-01-14 14:21:24 +00003498 intel_display_power_put(dev_priv, power_domain, wakeref);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003499
3500 return ret;
3501}
3502
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003503static u32
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003504intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
Damien Lespiaub3218032015-02-27 11:15:18 +00003505{
Ben Widawsky2f075562017-03-24 14:29:48 -07003506 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02003507 return 64;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003508 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003509 return intel_tile_width_bytes(fb, color_plane);
Damien Lespiaub3218032015-02-27 11:15:18 +00003510}
3511
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003512static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3513{
3514 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003515 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003516
3517 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3518 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3519 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003520}
3521
Chandra Kondurua1b22782015-04-07 15:28:45 -07003522/*
3523 * This function detaches (aka. unbinds) unused scalers in hardware
3524 */
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003525static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
Chandra Kondurua1b22782015-04-07 15:28:45 -07003526{
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003527 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3528 const struct intel_crtc_scaler_state *scaler_state =
3529 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07003530 int i;
3531
Chandra Kondurua1b22782015-04-07 15:28:45 -07003532 /* loop through and disable scalers that aren't in use */
3533 for (i = 0; i < intel_crtc->num_scalers; i++) {
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003534 if (!scaler_state->scalers[i].in_use)
3535 skl_detach_scaler(intel_crtc, i);
Chandra Kondurua1b22782015-04-07 15:28:45 -07003536 }
3537}
3538
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03003539static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3540 int color_plane, unsigned int rotation)
3541{
3542 /*
3543 * The stride is either expressed as a multiple of 64 bytes chunks for
3544 * linear buffers or in number of tiles for tiled buffers.
3545 */
3546 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3547 return 64;
3548 else if (drm_rotation_90_or_270(rotation))
3549 return intel_tile_height(fb, color_plane);
3550 else
3551 return intel_tile_width_bytes(fb, color_plane);
3552}
3553
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003554u32 skl_plane_stride(const struct intel_plane_state *plane_state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003555 int color_plane)
Ville Syrjäläd2196772016-01-28 18:33:11 +02003556{
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003557 const struct drm_framebuffer *fb = plane_state->base.fb;
3558 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003559 u32 stride = plane_state->color_plane[color_plane].stride;
Ville Syrjälä1b500532017-03-07 21:42:08 +02003560
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003561 if (color_plane >= fb->format->num_planes)
Ville Syrjälä1b500532017-03-07 21:42:08 +02003562 return 0;
3563
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03003564 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
Ville Syrjäläd2196772016-01-28 18:33:11 +02003565}
3566
Jani Nikulaba3f4d02019-01-18 14:01:23 +02003567static u32 skl_plane_ctl_format(u32 pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -07003568{
Chandra Konduru6156a452015-04-27 13:48:39 -07003569 switch (pixel_format) {
Damien Lespiaud161cf72015-05-12 16:13:17 +01003570 case DRM_FORMAT_C8:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003571 return PLANE_CTL_FORMAT_INDEXED;
Chandra Konduru6156a452015-04-27 13:48:39 -07003572 case DRM_FORMAT_RGB565:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003573 return PLANE_CTL_FORMAT_RGB_565;
Chandra Konduru6156a452015-04-27 13:48:39 -07003574 case DRM_FORMAT_XBGR8888:
James Ausmus4036c782017-11-13 10:11:28 -08003575 case DRM_FORMAT_ABGR8888:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003576 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
Chandra Konduru6156a452015-04-27 13:48:39 -07003577 case DRM_FORMAT_XRGB8888:
Chandra Konduru6156a452015-04-27 13:48:39 -07003578 case DRM_FORMAT_ARGB8888:
James Ausmus4036c782017-11-13 10:11:28 -08003579 return PLANE_CTL_FORMAT_XRGB_8888;
Chandra Konduru6156a452015-04-27 13:48:39 -07003580 case DRM_FORMAT_XRGB2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003581 return PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003582 case DRM_FORMAT_XBGR2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003583 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003584 case DRM_FORMAT_YUYV:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003585 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
Chandra Konduru6156a452015-04-27 13:48:39 -07003586 case DRM_FORMAT_YVYU:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003587 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
Chandra Konduru6156a452015-04-27 13:48:39 -07003588 case DRM_FORMAT_UYVY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003589 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
Chandra Konduru6156a452015-04-27 13:48:39 -07003590 case DRM_FORMAT_VYUY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003591 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
Chandra Konduru77224cd2018-04-09 09:11:13 +05303592 case DRM_FORMAT_NV12:
3593 return PLANE_CTL_FORMAT_NV12;
Chandra Konduru6156a452015-04-27 13:48:39 -07003594 default:
Damien Lespiau4249eee2015-05-12 16:13:16 +01003595 MISSING_CASE(pixel_format);
Chandra Konduru6156a452015-04-27 13:48:39 -07003596 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003597
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003598 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003599}
3600
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003601static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003602{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003603 if (!plane_state->base.fb->format->has_alpha)
3604 return PLANE_CTL_ALPHA_DISABLE;
3605
3606 switch (plane_state->base.pixel_blend_mode) {
3607 case DRM_MODE_BLEND_PIXEL_NONE:
3608 return PLANE_CTL_ALPHA_DISABLE;
3609 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003610 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003611 case DRM_MODE_BLEND_COVERAGE:
3612 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003613 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003614 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003615 return PLANE_CTL_ALPHA_DISABLE;
3616 }
3617}
3618
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003619static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003620{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003621 if (!plane_state->base.fb->format->has_alpha)
3622 return PLANE_COLOR_ALPHA_DISABLE;
3623
3624 switch (plane_state->base.pixel_blend_mode) {
3625 case DRM_MODE_BLEND_PIXEL_NONE:
3626 return PLANE_COLOR_ALPHA_DISABLE;
3627 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003628 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003629 case DRM_MODE_BLEND_COVERAGE:
3630 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003631 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003632 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003633 return PLANE_COLOR_ALPHA_DISABLE;
3634 }
3635}
3636
Jani Nikulaba3f4d02019-01-18 14:01:23 +02003637static u32 skl_plane_ctl_tiling(u64 fb_modifier)
Chandra Konduru6156a452015-04-27 13:48:39 -07003638{
Chandra Konduru6156a452015-04-27 13:48:39 -07003639 switch (fb_modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07003640 case DRM_FORMAT_MOD_LINEAR:
Chandra Konduru6156a452015-04-27 13:48:39 -07003641 break;
3642 case I915_FORMAT_MOD_X_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003643 return PLANE_CTL_TILED_X;
Chandra Konduru6156a452015-04-27 13:48:39 -07003644 case I915_FORMAT_MOD_Y_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003645 return PLANE_CTL_TILED_Y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003646 case I915_FORMAT_MOD_Y_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003647 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003648 case I915_FORMAT_MOD_Yf_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003649 return PLANE_CTL_TILED_YF;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003650 case I915_FORMAT_MOD_Yf_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003651 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003652 default:
3653 MISSING_CASE(fb_modifier);
3654 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003655
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003656 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003657}
3658
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003659static u32 skl_plane_ctl_rotate(unsigned int rotate)
Chandra Konduru6156a452015-04-27 13:48:39 -07003660{
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003661 switch (rotate) {
Robert Fossc2c446a2017-05-19 16:50:17 -04003662 case DRM_MODE_ROTATE_0:
Chandra Konduru6156a452015-04-27 13:48:39 -07003663 break;
Sonika Jindal1e8df162015-05-20 13:40:48 +05303664 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003665 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
Sonika Jindal1e8df162015-05-20 13:40:48 +05303666 * while i915 HW rotation is clockwise, thats why this swapping.
3667 */
Robert Fossc2c446a2017-05-19 16:50:17 -04003668 case DRM_MODE_ROTATE_90:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303669 return PLANE_CTL_ROTATE_270;
Robert Fossc2c446a2017-05-19 16:50:17 -04003670 case DRM_MODE_ROTATE_180:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003671 return PLANE_CTL_ROTATE_180;
Robert Fossc2c446a2017-05-19 16:50:17 -04003672 case DRM_MODE_ROTATE_270:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303673 return PLANE_CTL_ROTATE_90;
Chandra Konduru6156a452015-04-27 13:48:39 -07003674 default:
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003675 MISSING_CASE(rotate);
3676 }
3677
3678 return 0;
3679}
3680
3681static u32 cnl_plane_ctl_flip(unsigned int reflect)
3682{
3683 switch (reflect) {
3684 case 0:
3685 break;
3686 case DRM_MODE_REFLECT_X:
3687 return PLANE_CTL_FLIP_HORIZONTAL;
3688 case DRM_MODE_REFLECT_Y:
3689 default:
3690 MISSING_CASE(reflect);
Chandra Konduru6156a452015-04-27 13:48:39 -07003691 }
3692
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003693 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003694}
3695
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003696u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3697{
3698 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3699 u32 plane_ctl = 0;
3700
3701 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3702 return plane_ctl;
3703
3704 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
3705 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
3706
3707 return plane_ctl;
3708}
3709
Ville Syrjälä2e881262017-03-17 23:17:56 +02003710u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3711 const struct intel_plane_state *plane_state)
Damien Lespiau70d21f02013-07-03 21:06:04 +01003712{
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003713 struct drm_i915_private *dev_priv =
3714 to_i915(plane_state->base.plane->dev);
3715 const struct drm_framebuffer *fb = plane_state->base.fb;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003716 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä2e881262017-03-17 23:17:56 +02003717 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003718 u32 plane_ctl;
Damien Lespiau70d21f02013-07-03 21:06:04 +01003719
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003720 plane_ctl = PLANE_CTL_ENABLE;
3721
James Ausmus4036c782017-11-13 10:11:28 -08003722 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003723 plane_ctl |= skl_plane_ctl_alpha(plane_state);
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003724 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003725
3726 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3727 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003728
3729 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3730 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003731 }
Damien Lespiau70d21f02013-07-03 21:06:04 +01003732
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003733 plane_ctl |= skl_plane_ctl_format(fb->format->format);
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003734 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003735 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3736
3737 if (INTEL_GEN(dev_priv) >= 10)
3738 plane_ctl |= cnl_plane_ctl_flip(rotation &
3739 DRM_MODE_REFLECT_MASK);
Damien Lespiau70d21f02013-07-03 21:06:04 +01003740
Ville Syrjälä2e881262017-03-17 23:17:56 +02003741 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3742 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3743 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3744 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3745
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003746 return plane_ctl;
3747}
3748
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003749u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
3750{
3751 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3752 u32 plane_color_ctl = 0;
3753
3754 if (INTEL_GEN(dev_priv) >= 11)
3755 return plane_color_ctl;
3756
3757 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3758 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3759
3760 return plane_color_ctl;
3761}
3762
James Ausmus4036c782017-11-13 10:11:28 -08003763u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3764 const struct intel_plane_state *plane_state)
3765{
3766 const struct drm_framebuffer *fb = plane_state->base.fb;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303767 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
James Ausmus4036c782017-11-13 10:11:28 -08003768 u32 plane_color_ctl = 0;
3769
James Ausmus4036c782017-11-13 10:11:28 -08003770 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003771 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
James Ausmus4036c782017-11-13 10:11:28 -08003772
Uma Shankarbfe60a02018-11-02 00:40:20 +05303773 if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) {
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003774 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3775 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3776 else
3777 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003778
3779 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3780 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303781 } else if (fb->format->is_yuv) {
3782 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003783 }
Ville Syrjälä012d79e2018-05-21 21:56:12 +03003784
James Ausmus4036c782017-11-13 10:11:28 -08003785 return plane_color_ctl;
3786}
3787
Maarten Lankhorst73974892016-08-05 23:28:27 +03003788static int
3789__intel_display_resume(struct drm_device *dev,
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003790 struct drm_atomic_state *state,
3791 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorst73974892016-08-05 23:28:27 +03003792{
3793 struct drm_crtc_state *crtc_state;
3794 struct drm_crtc *crtc;
3795 int i, ret;
3796
Ville Syrjäläaecd36b2017-06-01 17:36:13 +03003797 intel_modeset_setup_hw_state(dev, ctx);
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00003798 i915_redisable_vga(to_i915(dev));
Maarten Lankhorst73974892016-08-05 23:28:27 +03003799
3800 if (!state)
3801 return 0;
3802
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01003803 /*
3804 * We've duplicated the state, pointers to the old state are invalid.
3805 *
3806 * Don't attempt to use the old state until we commit the duplicated state.
3807 */
3808 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst73974892016-08-05 23:28:27 +03003809 /*
3810 * Force recalculation even if we restore
3811 * current state. With fast modeset this may not result
3812 * in a modeset when the state is compatible.
3813 */
3814 crtc_state->mode_changed = true;
3815 }
3816
3817 /* ignore any reset values/BIOS leftovers in the WM registers */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08003818 if (!HAS_GMCH(to_i915(dev)))
Ville Syrjälä602ae832017-03-02 19:15:02 +02003819 to_intel_atomic_state(state)->skip_intermediate_wm = true;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003820
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003821 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003822
3823 WARN_ON(ret == -EDEADLK);
3824 return ret;
3825}
3826
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003827static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3828{
Chris Wilson55277e12019-01-03 11:21:04 +00003829 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
3830 intel_has_gpu_reset(dev_priv));
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003831}
3832
Chris Wilsonc0336662016-05-06 15:40:21 +01003833void intel_prepare_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003834{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003835 struct drm_device *dev = &dev_priv->drm;
3836 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3837 struct drm_atomic_state *state;
3838 int ret;
3839
Daniel Vetterce87ea12017-07-19 14:54:55 +02003840 /* reset doesn't touch the display */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003841 if (!i915_modparams.force_reset_modeset_test &&
Daniel Vetterce87ea12017-07-19 14:54:55 +02003842 !gpu_reset_clobbers_display(dev_priv))
3843 return;
3844
Daniel Vetter9db529a2017-08-08 10:08:28 +02003845 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3846 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3847 wake_up_all(&dev_priv->gpu_error.wait_queue);
3848
3849 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3850 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3851 i915_gem_set_wedged(dev_priv);
3852 }
Daniel Vetter97154ec2017-08-08 10:08:26 +02003853
Maarten Lankhorst73974892016-08-05 23:28:27 +03003854 /*
3855 * Need mode_config.mutex so that we don't
3856 * trample ongoing ->detect() and whatnot.
3857 */
3858 mutex_lock(&dev->mode_config.mutex);
3859 drm_modeset_acquire_init(ctx, 0);
3860 while (1) {
3861 ret = drm_modeset_lock_all_ctx(dev, ctx);
3862 if (ret != -EDEADLK)
3863 break;
3864
3865 drm_modeset_backoff(ctx);
3866 }
Ville Syrjäläf98ce922014-11-21 21:54:30 +02003867 /*
3868 * Disabling the crtcs gracefully seems nicer. Also the
3869 * g33 docs say we should at least disable all the planes.
3870 */
Maarten Lankhorst73974892016-08-05 23:28:27 +03003871 state = drm_atomic_helper_duplicate_state(dev, ctx);
3872 if (IS_ERR(state)) {
3873 ret = PTR_ERR(state);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003874 DRM_ERROR("Duplicating state failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003875 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003876 }
3877
3878 ret = drm_atomic_helper_disable_all(dev, ctx);
3879 if (ret) {
3880 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003881 drm_atomic_state_put(state);
3882 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003883 }
3884
3885 dev_priv->modeset_restore_state = state;
3886 state->acquire_ctx = ctx;
Ville Syrjälä75147472014-11-24 18:28:11 +02003887}
3888
Chris Wilsonc0336662016-05-06 15:40:21 +01003889void intel_finish_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003890{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003891 struct drm_device *dev = &dev_priv->drm;
3892 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
Chris Wilson40da1d32018-04-05 13:37:14 +01003893 struct drm_atomic_state *state;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003894 int ret;
3895
Daniel Vetterce87ea12017-07-19 14:54:55 +02003896 /* reset doesn't touch the display */
Chris Wilson40da1d32018-04-05 13:37:14 +01003897 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
Daniel Vetterce87ea12017-07-19 14:54:55 +02003898 return;
3899
Chris Wilson40da1d32018-04-05 13:37:14 +01003900 state = fetch_and_zero(&dev_priv->modeset_restore_state);
Daniel Vetterce87ea12017-07-19 14:54:55 +02003901 if (!state)
3902 goto unlock;
3903
Ville Syrjälä75147472014-11-24 18:28:11 +02003904 /* reset doesn't touch the display */
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003905 if (!gpu_reset_clobbers_display(dev_priv)) {
Daniel Vetterce87ea12017-07-19 14:54:55 +02003906 /* for testing only restore the display */
3907 ret = __intel_display_resume(dev, state, ctx);
Chris Wilson942d5d02017-08-28 11:46:04 +01003908 if (ret)
3909 DRM_ERROR("Restoring old state failed with %i\n", ret);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003910 } else {
3911 /*
3912 * The display has been reset as well,
3913 * so need a full re-initialization.
3914 */
3915 intel_runtime_pm_disable_interrupts(dev_priv);
3916 intel_runtime_pm_enable_interrupts(dev_priv);
3917
Imre Deak51f59202016-09-14 13:04:13 +03003918 intel_pps_unlock_regs_wa(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003919 intel_modeset_init_hw(dev);
Ville Syrjäläf72b84c2017-11-08 15:35:55 +02003920 intel_init_clock_gating(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003921
3922 spin_lock_irq(&dev_priv->irq_lock);
3923 if (dev_priv->display.hpd_irq_setup)
3924 dev_priv->display.hpd_irq_setup(dev_priv);
3925 spin_unlock_irq(&dev_priv->irq_lock);
3926
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003927 ret = __intel_display_resume(dev, state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003928 if (ret)
3929 DRM_ERROR("Restoring old state failed with %i\n", ret);
3930
3931 intel_hpd_init(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003932 }
3933
Daniel Vetterce87ea12017-07-19 14:54:55 +02003934 drm_atomic_state_put(state);
3935unlock:
Maarten Lankhorst73974892016-08-05 23:28:27 +03003936 drm_modeset_drop_locks(ctx);
3937 drm_modeset_acquire_fini(ctx);
3938 mutex_unlock(&dev->mode_config.mutex);
Daniel Vetter9db529a2017-08-08 10:08:28 +02003939
3940 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
Ville Syrjälä75147472014-11-24 18:28:11 +02003941}
3942
Ville Syrjäläd1622112019-02-04 22:21:39 +02003943static void icl_set_pipe_chicken(struct intel_crtc *crtc)
3944{
3945 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3946 enum pipe pipe = crtc->pipe;
3947 u32 tmp;
3948
3949 tmp = I915_READ(PIPE_CHICKEN(pipe));
3950
3951 /*
3952 * Display WA #1153: icl
3953 * enable hardware to bypass the alpha math
3954 * and rounding for per-pixel values 00 and 0xff
3955 */
3956 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
3957
Ville Syrjäläbf002c12019-02-04 22:22:32 +02003958 /*
3959 * W/A for underruns with linear/X-tiled with
3960 * WM1+ disabled.
3961 */
3962 tmp |= PM_FILL_MAINTAIN_DBUF_FULLNESS;
3963
Ville Syrjäläd1622112019-02-04 22:21:39 +02003964 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
3965}
3966
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003967static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3968 const struct intel_crtc_state *new_crtc_state)
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003969{
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003970 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003971 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003972
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003973 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003974 crtc->base.mode = new_crtc_state->base.mode;
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003975
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003976 /*
3977 * Update pipe size and adjust fitter if needed: the reason for this is
3978 * that in compute_mode_changes we check the native mode (not the pfit
3979 * mode) to see if we can flip rather than do a full mode set. In the
3980 * fastboot case, we'll flip, but if we don't update the pipesrc and
3981 * pfit state, we'll end up with a big fb scanned out into the wrong
3982 * sized surface.
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003983 */
3984
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003985 I915_WRITE(PIPESRC(crtc->pipe),
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003986 ((new_crtc_state->pipe_src_w - 1) << 16) |
3987 (new_crtc_state->pipe_src_h - 1));
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003988
3989 /* on skylake this is done by detaching scalers */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003990 if (INTEL_GEN(dev_priv) >= 9) {
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003991 skl_detach_scalers(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003992
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003993 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003994 skylake_pfit_enable(new_crtc_state);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003995 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003996 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003997 ironlake_pfit_enable(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003998 else if (old_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003999 ironlake_pfit_disable(old_crtc_state);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004000 }
Matt Roperc0550302019-01-30 10:51:20 -08004001
4002 /*
4003 * We don't (yet) allow userspace to control the pipe background color,
4004 * so force it to black, but apply pipe gamma and CSC so that its
4005 * handling will match how we program our planes.
4006 */
4007 if (INTEL_GEN(dev_priv) >= 9)
4008 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
4009 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
4010 SKL_BOTTOM_COLOR_CSC_ENABLE);
Ville Syrjälä108d14b2019-02-04 22:22:14 +02004011
4012 if (INTEL_GEN(dev_priv) >= 11)
4013 icl_set_pipe_chicken(crtc);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004014}
4015
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004016static void intel_fdi_normal_train(struct intel_crtc *crtc)
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004017{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004018 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004019 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004020 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004021 i915_reg_t reg;
4022 u32 temp;
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004023
4024 /* enable normal train */
4025 reg = FDI_TX_CTL(pipe);
4026 temp = I915_READ(reg);
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004027 if (IS_IVYBRIDGE(dev_priv)) {
Jesse Barnes357555c2011-04-28 15:09:55 -07004028 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4029 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
Keith Packard61e499b2011-05-17 16:13:52 -07004030 } else {
4031 temp &= ~FDI_LINK_TRAIN_NONE;
4032 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
Jesse Barnes357555c2011-04-28 15:09:55 -07004033 }
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004034 I915_WRITE(reg, temp);
4035
4036 reg = FDI_RX_CTL(pipe);
4037 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004038 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004039 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4040 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4041 } else {
4042 temp &= ~FDI_LINK_TRAIN_NONE;
4043 temp |= FDI_LINK_TRAIN_NONE;
4044 }
4045 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4046
4047 /* wait one idle pattern time */
4048 POSTING_READ(reg);
4049 udelay(1000);
Jesse Barnes357555c2011-04-28 15:09:55 -07004050
4051 /* IVB wants error correction enabled */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004052 if (IS_IVYBRIDGE(dev_priv))
Jesse Barnes357555c2011-04-28 15:09:55 -07004053 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4054 FDI_FE_ERRC_ENABLE);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004055}
4056
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004057/* The FDI link training functions for ILK/Ibexpeak. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004058static void ironlake_fdi_link_train(struct intel_crtc *crtc,
4059 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004060{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004061 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004062 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004063 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004064 i915_reg_t reg;
4065 u32 temp, tries;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004066
Ville Syrjälä1c8562f2014-04-25 22:12:07 +03004067 /* FDI needs bits from pipe first */
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004068 assert_pipe_enabled(dev_priv, pipe);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004069
Adam Jacksone1a44742010-06-25 15:32:14 -04004070 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4071 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01004072 reg = FDI_RX_IMR(pipe);
4073 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004074 temp &= ~FDI_RX_SYMBOL_LOCK;
4075 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01004076 I915_WRITE(reg, temp);
4077 I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004078 udelay(150);
4079
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004080 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01004081 reg = FDI_TX_CTL(pipe);
4082 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004083 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004084 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004085 temp &= ~FDI_LINK_TRAIN_NONE;
4086 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01004087 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004088
Chris Wilson5eddb702010-09-11 13:48:45 +01004089 reg = FDI_RX_CTL(pipe);
4090 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004091 temp &= ~FDI_LINK_TRAIN_NONE;
4092 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01004093 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4094
4095 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004096 udelay(150);
4097
Jesse Barnes5b2adf82010-10-07 16:01:15 -07004098 /* Ironlake workaround, enable clock pointer after FDI enable*/
Daniel Vetter8f5718a2012-10-31 22:52:28 +01004099 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4100 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4101 FDI_RX_PHASE_SYNC_POINTER_EN);
Jesse Barnes5b2adf82010-10-07 16:01:15 -07004102
Chris Wilson5eddb702010-09-11 13:48:45 +01004103 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04004104 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004105 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004106 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4107
4108 if ((temp & FDI_RX_BIT_LOCK)) {
4109 DRM_DEBUG_KMS("FDI train 1 done.\n");
Chris Wilson5eddb702010-09-11 13:48:45 +01004110 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004111 break;
4112 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004113 }
Adam Jacksone1a44742010-06-25 15:32:14 -04004114 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01004115 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004116
4117 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004118 reg = FDI_TX_CTL(pipe);
4119 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004120 temp &= ~FDI_LINK_TRAIN_NONE;
4121 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01004122 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004123
Chris Wilson5eddb702010-09-11 13:48:45 +01004124 reg = FDI_RX_CTL(pipe);
4125 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004126 temp &= ~FDI_LINK_TRAIN_NONE;
4127 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01004128 I915_WRITE(reg, temp);
4129
4130 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004131 udelay(150);
4132
Chris Wilson5eddb702010-09-11 13:48:45 +01004133 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04004134 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004135 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004136 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4137
4138 if (temp & FDI_RX_SYMBOL_LOCK) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004139 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004140 DRM_DEBUG_KMS("FDI train 2 done.\n");
4141 break;
4142 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004143 }
Adam Jacksone1a44742010-06-25 15:32:14 -04004144 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01004145 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004146
4147 DRM_DEBUG_KMS("FDI train done\n");
Jesse Barnes5c5313c2010-10-07 16:01:11 -07004148
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004149}
4150
Akshay Joshi0206e352011-08-16 15:34:10 -04004151static const int snb_b_fdi_train_param[] = {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004152 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4153 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4154 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4155 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4156};
4157
4158/* The FDI link training functions for SNB/Cougarpoint. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004159static void gen6_fdi_link_train(struct intel_crtc *crtc,
4160 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004161{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004162 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004163 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004164 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004165 i915_reg_t reg;
4166 u32 temp, i, retry;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004167
Adam Jacksone1a44742010-06-25 15:32:14 -04004168 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4169 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01004170 reg = FDI_RX_IMR(pipe);
4171 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004172 temp &= ~FDI_RX_SYMBOL_LOCK;
4173 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01004174 I915_WRITE(reg, temp);
4175
4176 POSTING_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004177 udelay(150);
4178
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004179 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01004180 reg = FDI_TX_CTL(pipe);
4181 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004182 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004183 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004184 temp &= ~FDI_LINK_TRAIN_NONE;
4185 temp |= FDI_LINK_TRAIN_PATTERN_1;
4186 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4187 /* SNB-B */
4188 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
Chris Wilson5eddb702010-09-11 13:48:45 +01004189 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004190
Daniel Vetterd74cf322012-10-26 10:58:13 +02004191 I915_WRITE(FDI_RX_MISC(pipe),
4192 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4193
Chris Wilson5eddb702010-09-11 13:48:45 +01004194 reg = FDI_RX_CTL(pipe);
4195 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004196 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004197 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4198 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4199 } else {
4200 temp &= ~FDI_LINK_TRAIN_NONE;
4201 temp |= FDI_LINK_TRAIN_PATTERN_1;
4202 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004203 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4204
4205 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004206 udelay(150);
4207
Akshay Joshi0206e352011-08-16 15:34:10 -04004208 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004209 reg = FDI_TX_CTL(pipe);
4210 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004211 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4212 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004213 I915_WRITE(reg, temp);
4214
4215 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004216 udelay(500);
4217
Sean Paulfa37d392012-03-02 12:53:39 -05004218 for (retry = 0; retry < 5; retry++) {
4219 reg = FDI_RX_IIR(pipe);
4220 temp = I915_READ(reg);
4221 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4222 if (temp & FDI_RX_BIT_LOCK) {
4223 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4224 DRM_DEBUG_KMS("FDI train 1 done.\n");
4225 break;
4226 }
4227 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004228 }
Sean Paulfa37d392012-03-02 12:53:39 -05004229 if (retry < 5)
4230 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004231 }
4232 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004233 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004234
4235 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004236 reg = FDI_TX_CTL(pipe);
4237 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004238 temp &= ~FDI_LINK_TRAIN_NONE;
4239 temp |= FDI_LINK_TRAIN_PATTERN_2;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004240 if (IS_GEN(dev_priv, 6)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004241 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4242 /* SNB-B */
4243 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4244 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004245 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004246
Chris Wilson5eddb702010-09-11 13:48:45 +01004247 reg = FDI_RX_CTL(pipe);
4248 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004249 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004250 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4251 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4252 } else {
4253 temp &= ~FDI_LINK_TRAIN_NONE;
4254 temp |= FDI_LINK_TRAIN_PATTERN_2;
4255 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004256 I915_WRITE(reg, temp);
4257
4258 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004259 udelay(150);
4260
Akshay Joshi0206e352011-08-16 15:34:10 -04004261 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004262 reg = FDI_TX_CTL(pipe);
4263 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004264 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4265 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004266 I915_WRITE(reg, temp);
4267
4268 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004269 udelay(500);
4270
Sean Paulfa37d392012-03-02 12:53:39 -05004271 for (retry = 0; retry < 5; retry++) {
4272 reg = FDI_RX_IIR(pipe);
4273 temp = I915_READ(reg);
4274 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4275 if (temp & FDI_RX_SYMBOL_LOCK) {
4276 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4277 DRM_DEBUG_KMS("FDI train 2 done.\n");
4278 break;
4279 }
4280 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004281 }
Sean Paulfa37d392012-03-02 12:53:39 -05004282 if (retry < 5)
4283 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004284 }
4285 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004286 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004287
4288 DRM_DEBUG_KMS("FDI train done.\n");
4289}
4290
Jesse Barnes357555c2011-04-28 15:09:55 -07004291/* Manual link training for Ivy Bridge A0 parts */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004292static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4293 const struct intel_crtc_state *crtc_state)
Jesse Barnes357555c2011-04-28 15:09:55 -07004294{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004295 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004296 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004297 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004298 i915_reg_t reg;
4299 u32 temp, i, j;
Jesse Barnes357555c2011-04-28 15:09:55 -07004300
4301 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4302 for train result */
4303 reg = FDI_RX_IMR(pipe);
4304 temp = I915_READ(reg);
4305 temp &= ~FDI_RX_SYMBOL_LOCK;
4306 temp &= ~FDI_RX_BIT_LOCK;
4307 I915_WRITE(reg, temp);
4308
4309 POSTING_READ(reg);
4310 udelay(150);
4311
Daniel Vetter01a415f2012-10-27 15:58:40 +02004312 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4313 I915_READ(FDI_RX_IIR(pipe)));
4314
Jesse Barnes139ccd32013-08-19 11:04:55 -07004315 /* Try each vswing and preemphasis setting twice before moving on */
4316 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4317 /* disable first in case we need to retry */
Jesse Barnes357555c2011-04-28 15:09:55 -07004318 reg = FDI_TX_CTL(pipe);
4319 temp = I915_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004320 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4321 temp &= ~FDI_TX_ENABLE;
4322 I915_WRITE(reg, temp);
4323
4324 reg = FDI_RX_CTL(pipe);
4325 temp = I915_READ(reg);
4326 temp &= ~FDI_LINK_TRAIN_AUTO;
4327 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4328 temp &= ~FDI_RX_ENABLE;
4329 I915_WRITE(reg, temp);
4330
4331 /* enable CPU FDI TX and PCH FDI RX */
4332 reg = FDI_TX_CTL(pipe);
4333 temp = I915_READ(reg);
4334 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004335 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004336 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
Jesse Barnes357555c2011-04-28 15:09:55 -07004337 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
Jesse Barnes139ccd32013-08-19 11:04:55 -07004338 temp |= snb_b_fdi_train_param[j/2];
4339 temp |= FDI_COMPOSITE_SYNC;
4340 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4341
4342 I915_WRITE(FDI_RX_MISC(pipe),
4343 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4344
4345 reg = FDI_RX_CTL(pipe);
4346 temp = I915_READ(reg);
4347 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4348 temp |= FDI_COMPOSITE_SYNC;
4349 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4350
4351 POSTING_READ(reg);
4352 udelay(1); /* should be 0.5us */
4353
4354 for (i = 0; i < 4; i++) {
4355 reg = FDI_RX_IIR(pipe);
4356 temp = I915_READ(reg);
4357 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4358
4359 if (temp & FDI_RX_BIT_LOCK ||
4360 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4361 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4362 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4363 i);
4364 break;
4365 }
4366 udelay(1); /* should be 0.5us */
4367 }
4368 if (i == 4) {
4369 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4370 continue;
4371 }
4372
4373 /* Train 2 */
4374 reg = FDI_TX_CTL(pipe);
4375 temp = I915_READ(reg);
4376 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4377 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4378 I915_WRITE(reg, temp);
4379
4380 reg = FDI_RX_CTL(pipe);
4381 temp = I915_READ(reg);
4382 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4383 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
Jesse Barnes357555c2011-04-28 15:09:55 -07004384 I915_WRITE(reg, temp);
4385
4386 POSTING_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004387 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004388
Jesse Barnes139ccd32013-08-19 11:04:55 -07004389 for (i = 0; i < 4; i++) {
4390 reg = FDI_RX_IIR(pipe);
4391 temp = I915_READ(reg);
4392 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
Jesse Barnes357555c2011-04-28 15:09:55 -07004393
Jesse Barnes139ccd32013-08-19 11:04:55 -07004394 if (temp & FDI_RX_SYMBOL_LOCK ||
4395 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4396 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4397 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4398 i);
4399 goto train_done;
4400 }
4401 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004402 }
Jesse Barnes139ccd32013-08-19 11:04:55 -07004403 if (i == 4)
4404 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
Jesse Barnes357555c2011-04-28 15:09:55 -07004405 }
Jesse Barnes357555c2011-04-28 15:09:55 -07004406
Jesse Barnes139ccd32013-08-19 11:04:55 -07004407train_done:
Jesse Barnes357555c2011-04-28 15:09:55 -07004408 DRM_DEBUG_KMS("FDI train done.\n");
4409}
4410
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004411static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes0e23b992010-09-10 11:10:00 -07004412{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004413 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4414 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004415 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004416 i915_reg_t reg;
4417 u32 temp;
Jesse Barnesc64e3112010-09-10 11:27:03 -07004418
Jesse Barnes0e23b992010-09-10 11:10:00 -07004419 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
Chris Wilson5eddb702010-09-11 13:48:45 +01004420 reg = FDI_RX_CTL(pipe);
4421 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004422 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004423 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004424 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Chris Wilson5eddb702010-09-11 13:48:45 +01004425 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4426
4427 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004428 udelay(200);
4429
4430 /* Switch from Rawclk to PCDclk */
Chris Wilson5eddb702010-09-11 13:48:45 +01004431 temp = I915_READ(reg);
4432 I915_WRITE(reg, temp | FDI_PCDCLK);
4433
4434 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004435 udelay(200);
4436
Paulo Zanoni20749732012-11-23 15:30:38 -02004437 /* Enable CPU FDI TX PLL, always on for Ironlake */
4438 reg = FDI_TX_CTL(pipe);
4439 temp = I915_READ(reg);
4440 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4441 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
Chris Wilson5eddb702010-09-11 13:48:45 +01004442
Paulo Zanoni20749732012-11-23 15:30:38 -02004443 POSTING_READ(reg);
4444 udelay(100);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004445 }
4446}
4447
Daniel Vetter88cefb62012-08-12 19:27:14 +02004448static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4449{
4450 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004451 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter88cefb62012-08-12 19:27:14 +02004452 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004453 i915_reg_t reg;
4454 u32 temp;
Daniel Vetter88cefb62012-08-12 19:27:14 +02004455
4456 /* Switch from PCDclk to Rawclk */
4457 reg = FDI_RX_CTL(pipe);
4458 temp = I915_READ(reg);
4459 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4460
4461 /* Disable CPU FDI TX PLL */
4462 reg = FDI_TX_CTL(pipe);
4463 temp = I915_READ(reg);
4464 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4465
4466 POSTING_READ(reg);
4467 udelay(100);
4468
4469 reg = FDI_RX_CTL(pipe);
4470 temp = I915_READ(reg);
4471 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4472
4473 /* Wait for the clocks to turn off. */
4474 POSTING_READ(reg);
4475 udelay(100);
4476}
4477
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004478static void ironlake_fdi_disable(struct drm_crtc *crtc)
4479{
4480 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004481 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004482 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4483 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004484 i915_reg_t reg;
4485 u32 temp;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004486
4487 /* disable CPU FDI tx and PCH FDI rx */
4488 reg = FDI_TX_CTL(pipe);
4489 temp = I915_READ(reg);
4490 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4491 POSTING_READ(reg);
4492
4493 reg = FDI_RX_CTL(pipe);
4494 temp = I915_READ(reg);
4495 temp &= ~(0x7 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004496 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004497 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4498
4499 POSTING_READ(reg);
4500 udelay(100);
4501
4502 /* Ironlake workaround, disable clock pointer after downing FDI */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004503 if (HAS_PCH_IBX(dev_priv))
Jesse Barnes6f06ce12011-01-04 15:09:38 -08004504 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004505
4506 /* still set train pattern 1 */
4507 reg = FDI_TX_CTL(pipe);
4508 temp = I915_READ(reg);
4509 temp &= ~FDI_LINK_TRAIN_NONE;
4510 temp |= FDI_LINK_TRAIN_PATTERN_1;
4511 I915_WRITE(reg, temp);
4512
4513 reg = FDI_RX_CTL(pipe);
4514 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004515 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004516 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4517 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4518 } else {
4519 temp &= ~FDI_LINK_TRAIN_NONE;
4520 temp |= FDI_LINK_TRAIN_PATTERN_1;
4521 }
4522 /* BPC in FDI rx is consistent with that in PIPECONF */
4523 temp &= ~(0x07 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004524 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004525 I915_WRITE(reg, temp);
4526
4527 POSTING_READ(reg);
4528 udelay(100);
4529}
4530
Chris Wilson49d73912016-11-29 09:50:08 +00004531bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004532{
Daniel Vetterfa058872017-07-20 19:57:52 +02004533 struct drm_crtc *crtc;
4534 bool cleanup_done;
Chris Wilson5dce5b932014-01-20 10:17:36 +00004535
Daniel Vetterfa058872017-07-20 19:57:52 +02004536 drm_for_each_crtc(crtc, &dev_priv->drm) {
4537 struct drm_crtc_commit *commit;
4538 spin_lock(&crtc->commit_lock);
4539 commit = list_first_entry_or_null(&crtc->commit_list,
4540 struct drm_crtc_commit, commit_entry);
4541 cleanup_done = commit ?
4542 try_wait_for_completion(&commit->cleanup_done) : true;
4543 spin_unlock(&crtc->commit_lock);
4544
4545 if (cleanup_done)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004546 continue;
4547
Daniel Vetterfa058872017-07-20 19:57:52 +02004548 drm_crtc_wait_one_vblank(crtc);
Chris Wilson5dce5b932014-01-20 10:17:36 +00004549
4550 return true;
4551 }
4552
4553 return false;
4554}
4555
Maarten Lankhorstb7076542016-08-23 16:18:08 +02004556void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004557{
4558 u32 temp;
4559
4560 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4561
4562 mutex_lock(&dev_priv->sb_lock);
4563
4564 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4565 temp |= SBI_SSCCTL_DISABLE;
4566 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4567
4568 mutex_unlock(&dev_priv->sb_lock);
4569}
4570
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004571/* Program iCLKIP clock to the desired frequency */
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004572static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004573{
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004574 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004575 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004576 int clock = crtc_state->base.adjusted_mode.crtc_clock;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004577 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4578 u32 temp;
4579
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004580 lpt_disable_iclkip(dev_priv);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004581
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004582 /* The iCLK virtual clock root frequency is in MHz,
4583 * but the adjusted_mode->crtc_clock in in KHz. To get the
4584 * divisors, it is necessary to divide one by another, so we
4585 * convert the virtual clock precision to KHz here for higher
4586 * precision.
4587 */
4588 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004589 u32 iclk_virtual_root_freq = 172800 * 1000;
4590 u32 iclk_pi_range = 64;
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004591 u32 desired_divisor;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004592
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004593 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4594 clock << auxdiv);
4595 divsel = (desired_divisor / iclk_pi_range) - 2;
4596 phaseinc = desired_divisor % iclk_pi_range;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004597
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004598 /*
4599 * Near 20MHz is a corner case which is
4600 * out of range for the 7-bit divisor
4601 */
4602 if (divsel <= 0x7f)
4603 break;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004604 }
4605
4606 /* This should not happen with any sane values */
4607 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4608 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4609 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4610 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4611
4612 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 +03004613 clock,
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004614 auxdiv,
4615 divsel,
4616 phasedir,
4617 phaseinc);
4618
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004619 mutex_lock(&dev_priv->sb_lock);
4620
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004621 /* Program SSCDIVINTPHASE6 */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004622 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004623 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4624 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4625 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4626 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4627 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4628 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004629 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004630
4631 /* Program SSCAUXDIV */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004632 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004633 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4634 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004635 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004636
4637 /* Enable modulator and associated divider */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004638 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004639 temp &= ~SBI_SSCCTL_DISABLE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004640 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004641
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004642 mutex_unlock(&dev_priv->sb_lock);
4643
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004644 /* Wait for initialization time */
4645 udelay(24);
4646
4647 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4648}
4649
Ville Syrjälä8802e5b2016-02-17 21:41:12 +02004650int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4651{
4652 u32 divsel, phaseinc, auxdiv;
4653 u32 iclk_virtual_root_freq = 172800 * 1000;
4654 u32 iclk_pi_range = 64;
4655 u32 desired_divisor;
4656 u32 temp;
4657
4658 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4659 return 0;
4660
4661 mutex_lock(&dev_priv->sb_lock);
4662
4663 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4664 if (temp & SBI_SSCCTL_DISABLE) {
4665 mutex_unlock(&dev_priv->sb_lock);
4666 return 0;
4667 }
4668
4669 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4670 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4671 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4672 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4673 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4674
4675 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4676 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4677 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4678
4679 mutex_unlock(&dev_priv->sb_lock);
4680
4681 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4682
4683 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4684 desired_divisor << auxdiv);
4685}
4686
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004687static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
Daniel Vetter275f01b22013-05-03 11:49:47 +02004688 enum pipe pch_transcoder)
4689{
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004690 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4691 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4692 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter275f01b22013-05-03 11:49:47 +02004693
4694 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4695 I915_READ(HTOTAL(cpu_transcoder)));
4696 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4697 I915_READ(HBLANK(cpu_transcoder)));
4698 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4699 I915_READ(HSYNC(cpu_transcoder)));
4700
4701 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4702 I915_READ(VTOTAL(cpu_transcoder)));
4703 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4704 I915_READ(VBLANK(cpu_transcoder)));
4705 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4706 I915_READ(VSYNC(cpu_transcoder)));
4707 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4708 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4709}
4710
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004711static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004712{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02004713 u32 temp;
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004714
4715 temp = I915_READ(SOUTH_CHICKEN1);
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004716 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004717 return;
4718
4719 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4720 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4721
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004722 temp &= ~FDI_BC_BIFURCATION_SELECT;
4723 if (enable)
4724 temp |= FDI_BC_BIFURCATION_SELECT;
4725
4726 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004727 I915_WRITE(SOUTH_CHICKEN1, temp);
4728 POSTING_READ(SOUTH_CHICKEN1);
4729}
4730
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004731static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004732{
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004733 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4734 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004735
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004736 switch (crtc->pipe) {
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004737 case PIPE_A:
4738 break;
4739 case PIPE_B:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004740 if (crtc_state->fdi_lanes > 2)
4741 cpt_set_fdi_bc_bifurcation(dev_priv, false);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004742 else
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004743 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004744
4745 break;
4746 case PIPE_C:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004747 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004748
4749 break;
4750 default:
4751 BUG();
4752 }
4753}
4754
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004755/*
4756 * Finds the encoder associated with the given CRTC. This can only be
4757 * used when we know that the CRTC isn't feeding multiple encoders!
4758 */
4759static struct intel_encoder *
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004760intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4761 const struct intel_crtc_state *crtc_state)
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004762{
4763 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004764 const struct drm_connector_state *connector_state;
4765 const struct drm_connector *connector;
4766 struct intel_encoder *encoder = NULL;
4767 int num_encoders = 0;
4768 int i;
4769
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004770 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004771 if (connector_state->crtc != &crtc->base)
4772 continue;
4773
4774 encoder = to_intel_encoder(connector_state->best_encoder);
4775 num_encoders++;
4776 }
4777
4778 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4779 num_encoders, pipe_name(crtc->pipe));
4780
4781 return encoder;
4782}
4783
Jesse Barnesf67a5592011-01-05 10:31:48 -08004784/*
4785 * Enable PCH resources required for PCH ports:
4786 * - PCH PLLs
4787 * - FDI training & RX/TX
4788 * - update transcoder timings
4789 * - DP transcoding bits
4790 * - transcoder
4791 */
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004792static void ironlake_pch_enable(const struct intel_atomic_state *state,
4793 const struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08004794{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004795 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004796 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004797 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004798 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004799 u32 temp;
Jesse Barnes6be4a602010-09-10 10:26:01 -07004800
Daniel Vetterab9412b2013-05-03 11:49:46 +02004801 assert_pch_transcoder_disabled(dev_priv, pipe);
Chris Wilsone7e164d2012-05-11 09:21:25 +01004802
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004803 if (IS_IVYBRIDGE(dev_priv))
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004804 ivybridge_update_fdi_bc_bifurcation(crtc_state);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004805
Daniel Vettercd986ab2012-10-26 10:58:12 +02004806 /* Write the TU size bits before fdi link training, so that error
4807 * detection works. */
4808 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4809 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4810
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004811 /* For PCH output, training FDI link */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004812 dev_priv->display.fdi_link_train(crtc, crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07004813
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004814 /* We need to program the right clock selection before writing the pixel
4815 * mutliplier into the DPLL. */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004816 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004817 u32 sel;
Jesse Barnes4b645f12011-10-12 09:51:31 -07004818
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004819 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02004820 temp |= TRANS_DPLL_ENABLE(pipe);
4821 sel = TRANS_DPLLB_SEL(pipe);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004822 if (crtc_state->shared_dpll ==
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02004823 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004824 temp |= sel;
4825 else
4826 temp &= ~sel;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004827 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004828 }
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004829
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004830 /* XXX: pch pll's can be enabled any time before we enable the PCH
4831 * transcoder, and we actually should do this to not upset any PCH
4832 * transcoder that already use the clock when we share it.
4833 *
4834 * Note that enable_shared_dpll tries to do the right thing, but
4835 * get_shared_dpll unconditionally resets the pll - we need that to have
4836 * the right LVDS enable sequence. */
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02004837 intel_enable_shared_dpll(crtc_state);
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004838
Jesse Barnesd9b6cb52011-01-04 15:09:35 -08004839 /* set transcoder timing, panel must allow it */
4840 assert_panel_unlocked(dev_priv, pipe);
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004841 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004842
Paulo Zanoni303b81e2012-10-31 18:12:23 -02004843 intel_fdi_normal_train(crtc);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004844
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004845 /* For PCH DP, enable TRANS_DP_CTL */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004846 if (HAS_PCH_CPT(dev_priv) &&
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004847 intel_crtc_has_dp_encoder(crtc_state)) {
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004848 const struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004849 &crtc_state->base.adjusted_mode;
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004850 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004851 i915_reg_t reg = TRANS_DP_CTL(pipe);
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004852 enum port port;
4853
Chris Wilson5eddb702010-09-11 13:48:45 +01004854 temp = I915_READ(reg);
4855 temp &= ~(TRANS_DP_PORT_SEL_MASK |
Eric Anholt220cad32010-11-18 09:32:58 +08004856 TRANS_DP_SYNC_MASK |
4857 TRANS_DP_BPC_MASK);
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03004858 temp |= TRANS_DP_OUTPUT_ENABLE;
Jesse Barnes9325c9f2011-06-24 12:19:21 -07004859 temp |= bpc << 9; /* same format but at 11:9 */
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004860
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004861 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004862 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004863 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004864 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004865
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004866 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004867 WARN_ON(port < PORT_B || port > PORT_D);
4868 temp |= TRANS_DP_PORT_SEL(port);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004869
Chris Wilson5eddb702010-09-11 13:48:45 +01004870 I915_WRITE(reg, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004871 }
4872
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02004873 ironlake_enable_pch_transcoder(crtc_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004874}
4875
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004876static void lpt_pch_enable(const struct intel_atomic_state *state,
4877 const struct intel_crtc_state *crtc_state)
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004878{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004879 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004880 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004881 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004882
Matthias Kaehlckea2196032017-07-17 11:14:03 -07004883 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004884
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004885 lpt_program_iclkip(crtc_state);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004886
Paulo Zanoni0540e482012-10-31 18:12:40 -02004887 /* Set transcoder timing. */
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004888 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004889
Paulo Zanoni937bb612012-10-31 18:12:47 -02004890 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004891}
4892
Daniel Vettera1520312013-05-03 11:49:50 +02004893static void cpt_verify_modeset(struct drm_device *dev, int pipe)
Jesse Barnesd4270e52011-10-11 10:43:02 -07004894{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004895 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004896 i915_reg_t dslreg = PIPEDSL(pipe);
Jesse Barnesd4270e52011-10-11 10:43:02 -07004897 u32 temp;
4898
4899 temp = I915_READ(dslreg);
4900 udelay(500);
4901 if (wait_for(I915_READ(dslreg) != temp, 5)) {
Jesse Barnesd4270e52011-10-11 10:43:02 -07004902 if (wait_for(I915_READ(dslreg) != temp, 5))
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03004903 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
Jesse Barnesd4270e52011-10-11 10:43:02 -07004904 }
4905}
4906
Ville Syrjälä0a599522018-05-21 21:56:13 +03004907/*
4908 * The hardware phase 0.0 refers to the center of the pixel.
4909 * We want to start from the top/left edge which is phase
4910 * -0.5. That matches how the hardware calculates the scaling
4911 * factors (from top-left of the first pixel to bottom-right
4912 * of the last pixel, as opposed to the pixel centers).
4913 *
4914 * For 4:2:0 subsampled chroma planes we obviously have to
4915 * adjust that so that the chroma sample position lands in
4916 * the right spot.
4917 *
4918 * Note that for packed YCbCr 4:2:2 formats there is no way to
4919 * control chroma siting. The hardware simply replicates the
4920 * chroma samples for both of the luma samples, and thus we don't
4921 * actually get the expected MPEG2 chroma siting convention :(
4922 * The same behaviour is observed on pre-SKL platforms as well.
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004923 *
4924 * Theory behind the formula (note that we ignore sub-pixel
4925 * source coordinates):
4926 * s = source sample position
4927 * d = destination sample position
4928 *
4929 * Downscaling 4:1:
4930 * -0.5
4931 * | 0.0
4932 * | | 1.5 (initial phase)
4933 * | | |
4934 * v v v
4935 * | s | s | s | s |
4936 * | d |
4937 *
4938 * Upscaling 1:4:
4939 * -0.5
4940 * | -0.375 (initial phase)
4941 * | | 0.0
4942 * | | |
4943 * v v v
4944 * | s |
4945 * | d | d | d | d |
Ville Syrjälä0a599522018-05-21 21:56:13 +03004946 */
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004947u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
Ville Syrjälä0a599522018-05-21 21:56:13 +03004948{
4949 int phase = -0x8000;
4950 u16 trip = 0;
4951
4952 if (chroma_cosited)
4953 phase += (sub - 1) * 0x8000 / sub;
4954
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004955 phase += scale / (2 * sub);
4956
4957 /*
4958 * Hardware initial phase limited to [-0.5:1.5].
4959 * Since the max hardware scale factor is 3.0, we
4960 * should never actually excdeed 1.0 here.
4961 */
4962 WARN_ON(phase < -0x8000 || phase > 0x18000);
4963
Ville Syrjälä0a599522018-05-21 21:56:13 +03004964 if (phase < 0)
4965 phase = 0x10000 + phase;
4966 else
4967 trip = PS_PHASE_TRIP;
4968
4969 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4970}
4971
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004972static int
4973skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004974 unsigned int scaler_user, int *scaler_id,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304975 int src_w, int src_h, int dst_w, int dst_h,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004976 const struct drm_format_info *format, bool need_scaler)
Chandra Kondurua1b22782015-04-07 15:28:45 -07004977{
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004978 struct intel_crtc_scaler_state *scaler_state =
4979 &crtc_state->scaler_state;
4980 struct intel_crtc *intel_crtc =
4981 to_intel_crtc(crtc_state->base.crtc);
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304982 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4983 const struct drm_display_mode *adjusted_mode =
4984 &crtc_state->base.adjusted_mode;
Chandra Konduru6156a452015-04-27 13:48:39 -07004985
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004986 /*
4987 * Src coordinates are already rotated by 270 degrees for
4988 * the 90/270 degree plane rotation cases (to match the
4989 * GTT mapping), hence no need to account for rotation here.
4990 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004991 if (src_w != dst_w || src_h != dst_h)
4992 need_scaler = true;
Shashank Sharmae5c05932017-07-21 20:55:05 +05304993
Chandra Kondurua1b22782015-04-07 15:28:45 -07004994 /*
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304995 * Scaling/fitting not supported in IF-ID mode in GEN9+
4996 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4997 * Once NV12 is enabled, handle it here while allocating scaler
4998 * for NV12.
4999 */
5000 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005001 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05305002 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5003 return -EINVAL;
5004 }
5005
5006 /*
Chandra Kondurua1b22782015-04-07 15:28:45 -07005007 * if plane is being disabled or scaler is no more required or force detach
5008 * - free scaler binded to this plane/crtc
5009 * - in order to do this, update crtc->scaler_usage
5010 *
5011 * Here scaler state in crtc_state is set free so that
5012 * scaler can be assigned to other user. Actual register
5013 * update to free the scaler is done in plane/panel-fit programming.
5014 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5015 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005016 if (force_detach || !need_scaler) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07005017 if (*scaler_id >= 0) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005018 scaler_state->scaler_users &= ~(1 << scaler_user);
Chandra Kondurua1b22782015-04-07 15:28:45 -07005019 scaler_state->scalers[*scaler_id].in_use = 0;
5020
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005021 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5022 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5023 intel_crtc->pipe, scaler_user, *scaler_id,
Chandra Kondurua1b22782015-04-07 15:28:45 -07005024 scaler_state->scaler_users);
5025 *scaler_id = -1;
5026 }
5027 return 0;
5028 }
5029
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005030 if (format && format->format == DRM_FORMAT_NV12 &&
Maarten Lankhorst5d794282018-05-12 03:03:14 +05305031 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
Chandra Konduru77224cd2018-04-09 09:11:13 +05305032 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
5033 return -EINVAL;
5034 }
5035
Chandra Kondurua1b22782015-04-07 15:28:45 -07005036 /* range checks */
5037 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
Nabendu Maiti323301a2018-03-23 10:24:18 -07005038 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005039 (IS_GEN(dev_priv, 11) &&
Nabendu Maiti323301a2018-03-23 10:24:18 -07005040 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5041 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005042 (!IS_GEN(dev_priv, 11) &&
Nabendu Maiti323301a2018-03-23 10:24:18 -07005043 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5044 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005045 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
Chandra Kondurua1b22782015-04-07 15:28:45 -07005046 "size is out of scaler range\n",
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005047 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
Chandra Kondurua1b22782015-04-07 15:28:45 -07005048 return -EINVAL;
5049 }
5050
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005051 /* mark this plane as a scaler user in crtc_state */
5052 scaler_state->scaler_users |= (1 << scaler_user);
5053 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5054 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5055 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5056 scaler_state->scaler_users);
5057
5058 return 0;
5059}
5060
5061/**
5062 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5063 *
5064 * @state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005065 *
5066 * Return
5067 * 0 - scaler_usage updated successfully
5068 * error - requested scaling cannot be supported or other error condition
5069 */
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005070int skl_update_scaler_crtc(struct intel_crtc_state *state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005071{
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03005072 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005073 bool need_scaler = false;
5074
5075 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5076 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005077
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005078 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
Chandra Konduru77224cd2018-04-09 09:11:13 +05305079 &state->scaler_state.scaler_id,
5080 state->pipe_src_w, state->pipe_src_h,
5081 adjusted_mode->crtc_hdisplay,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005082 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005083}
5084
5085/**
5086 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
Chris Wilsonc38c1452018-02-14 13:49:22 +00005087 * @crtc_state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005088 * @plane_state: atomic plane state to update
5089 *
5090 * Return
5091 * 0 - scaler_usage updated successfully
5092 * error - requested scaling cannot be supported or other error condition
5093 */
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02005094static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5095 struct intel_plane_state *plane_state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005096{
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02005097 struct intel_plane *intel_plane =
5098 to_intel_plane(plane_state->base.plane);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005099 struct drm_framebuffer *fb = plane_state->base.fb;
5100 int ret;
Ville Syrjälä936e71e2016-07-26 19:06:59 +03005101 bool force_detach = !fb || !plane_state->base.visible;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005102 bool need_scaler = false;
5103
5104 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5105 if (!icl_is_hdr_plane(intel_plane) &&
5106 fb && fb->format->format == DRM_FORMAT_NV12)
5107 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005108
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005109 ret = skl_update_scaler(crtc_state, force_detach,
5110 drm_plane_index(&intel_plane->base),
5111 &plane_state->scaler_id,
Ville Syrjälä936e71e2016-07-26 19:06:59 +03005112 drm_rect_width(&plane_state->base.src) >> 16,
5113 drm_rect_height(&plane_state->base.src) >> 16,
5114 drm_rect_width(&plane_state->base.dst),
Chandra Konduru77224cd2018-04-09 09:11:13 +05305115 drm_rect_height(&plane_state->base.dst),
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005116 fb ? fb->format : NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005117
5118 if (ret || plane_state->scaler_id < 0)
5119 return ret;
5120
Chandra Kondurua1b22782015-04-07 15:28:45 -07005121 /* check colorkey */
Ville Syrjälä6ec5bd32018-02-02 22:42:31 +02005122 if (plane_state->ckey.flags) {
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005123 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5124 intel_plane->base.base.id,
5125 intel_plane->base.name);
Chandra Kondurua1b22782015-04-07 15:28:45 -07005126 return -EINVAL;
5127 }
5128
5129 /* Check src format */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005130 switch (fb->format->format) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005131 case DRM_FORMAT_RGB565:
5132 case DRM_FORMAT_XBGR8888:
5133 case DRM_FORMAT_XRGB8888:
5134 case DRM_FORMAT_ABGR8888:
5135 case DRM_FORMAT_ARGB8888:
5136 case DRM_FORMAT_XRGB2101010:
5137 case DRM_FORMAT_XBGR2101010:
5138 case DRM_FORMAT_YUYV:
5139 case DRM_FORMAT_YVYU:
5140 case DRM_FORMAT_UYVY:
5141 case DRM_FORMAT_VYUY:
Chandra Konduru77224cd2018-04-09 09:11:13 +05305142 case DRM_FORMAT_NV12:
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005143 break;
5144 default:
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005145 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5146 intel_plane->base.base.id, intel_plane->base.name,
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005147 fb->base.id, fb->format->format);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005148 return -EINVAL;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005149 }
5150
Chandra Kondurua1b22782015-04-07 15:28:45 -07005151 return 0;
5152}
5153
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005154static void skylake_scaler_disable(struct intel_crtc *crtc)
5155{
5156 int i;
5157
5158 for (i = 0; i < crtc->num_scalers; i++)
5159 skl_detach_scaler(crtc, i);
5160}
5161
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005162static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005163{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005164 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5165 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5166 enum pipe pipe = crtc->pipe;
5167 const struct intel_crtc_scaler_state *scaler_state =
5168 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005169
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005170 if (crtc_state->pch_pfit.enabled) {
Ville Syrjälä0a599522018-05-21 21:56:13 +03005171 u16 uv_rgb_hphase, uv_rgb_vphase;
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005172 int pfit_w, pfit_h, hscale, vscale;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005173 int id;
5174
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005175 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
Chandra Kondurua1b22782015-04-07 15:28:45 -07005176 return;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005177
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005178 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5179 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5180
5181 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5182 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5183
5184 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5185 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005186
Chandra Kondurua1b22782015-04-07 15:28:45 -07005187 id = scaler_state->scaler_id;
5188 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5189 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005190 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5191 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5192 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5193 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005194 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5195 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005196 }
5197}
5198
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005199static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesb074cec2013-04-25 12:55:02 -07005200{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005201 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5202 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesb074cec2013-04-25 12:55:02 -07005203 int pipe = crtc->pipe;
5204
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005205 if (crtc_state->pch_pfit.enabled) {
Jesse Barnesb074cec2013-04-25 12:55:02 -07005206 /* Force use of hard-coded filter coefficients
5207 * as some pre-programmed values are broken,
5208 * e.g. x201.
5209 */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01005210 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
Jesse Barnesb074cec2013-04-25 12:55:02 -07005211 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5212 PF_PIPE_SEL_IVB(pipe));
5213 else
5214 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005215 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5216 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
Jesse Barnes040484a2011-01-03 12:14:26 -08005217 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005218}
5219
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005220void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005221{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005222 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläcea165c2014-04-15 21:41:35 +03005223 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005224 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005225
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005226 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005227 return;
5228
Maarten Lankhorst307e4492016-03-23 14:33:28 +01005229 /*
5230 * We can only enable IPS after we enable a plane and wait for a vblank
5231 * This function is called from post_plane_update, which is run after
5232 * a vblank wait.
5233 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005234 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02005235
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005236 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005237 mutex_lock(&dev_priv->pcu_lock);
Ville Syrjälä61843f02017-09-12 18:34:11 +03005238 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5239 IPS_ENABLE | IPS_PCODE_CONTROL));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005240 mutex_unlock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005241 /* Quoting Art Runyan: "its not safe to expect any particular
5242 * value in IPS_CTL bit 31 after enabling IPS through the
Jesse Barnese59150d2014-01-07 13:30:45 -08005243 * mailbox." Moreover, the mailbox may return a bogus state,
5244 * so we need to just enable it and continue on.
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005245 */
5246 } else {
5247 I915_WRITE(IPS_CTL, IPS_ENABLE);
5248 /* The bit only becomes 1 in the next vblank, so this wait here
5249 * is essentially intel_wait_for_vblank. If we don't have this
5250 * and don't wait for vblanks until the end of crtc_enable, then
5251 * the HW state readout code will complain that the expected
5252 * IPS_CTL value is not the one we read. */
Chris Wilson2ec9ba32016-06-30 15:33:01 +01005253 if (intel_wait_for_register(dev_priv,
5254 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5255 50))
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005256 DRM_ERROR("Timed out waiting for IPS enable\n");
5257 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005258}
5259
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005260void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005261{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005262 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005263 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005264 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005265
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005266 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005267 return;
5268
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005269 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005270 mutex_lock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005271 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005272 mutex_unlock(&dev_priv->pcu_lock);
Imre Deakacb3ef02018-09-05 13:00:05 +03005273 /*
5274 * Wait for PCODE to finish disabling IPS. The BSpec specified
5275 * 42ms timeout value leads to occasional timeouts so use 100ms
5276 * instead.
5277 */
Chris Wilsonb85c1ec2016-06-30 15:33:02 +01005278 if (intel_wait_for_register(dev_priv,
5279 IPS_CTL, IPS_ENABLE, 0,
Imre Deakacb3ef02018-09-05 13:00:05 +03005280 100))
Ben Widawsky23d0b132014-04-10 14:32:41 -07005281 DRM_ERROR("Timed out waiting for IPS disable\n");
Jesse Barnese59150d2014-01-07 13:30:45 -08005282 } else {
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005283 I915_WRITE(IPS_CTL, 0);
Jesse Barnese59150d2014-01-07 13:30:45 -08005284 POSTING_READ(IPS_CTL);
5285 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005286
5287 /* We need to wait for a vblank before we can disable the plane. */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005288 intel_wait_for_vblank(dev_priv, crtc->pipe);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005289}
5290
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005291static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005292{
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005293 if (intel_crtc->overlay) {
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005294 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005295
5296 mutex_lock(&dev->struct_mutex);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005297 (void) intel_overlay_switch_off(intel_crtc->overlay);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005298 mutex_unlock(&dev->struct_mutex);
5299 }
5300
5301 /* Let userspace switch the overlay on again. In most cases userspace
5302 * has to recompute where to put it anyway.
5303 */
5304}
5305
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005306/**
5307 * intel_post_enable_primary - Perform operations after enabling primary plane
5308 * @crtc: the CRTC whose primary plane was just enabled
Chris Wilsonc38c1452018-02-14 13:49:22 +00005309 * @new_crtc_state: the enabling state
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005310 *
5311 * Performs potentially sleeping operations that must be done after the primary
5312 * plane is enabled, such as updating FBC and IPS. Note that this may be
5313 * called due to an explicit primary plane update, or due to an implicit
5314 * re-enable that is caused when a sprite plane is updated to no longer
5315 * completely hide the primary plane.
5316 */
5317static void
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005318intel_post_enable_primary(struct drm_crtc *crtc,
5319 const struct intel_crtc_state *new_crtc_state)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005320{
5321 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005322 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005323 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5324 int pipe = intel_crtc->pipe;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005325
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005326 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005327 * Gen2 reports pipe underruns whenever all planes are disabled.
5328 * So don't enable underrun reporting before at least some planes
5329 * are enabled.
5330 * FIXME: Need to fix the logic to work when we turn off all planes
5331 * but leave the pipe running.
Daniel Vetterf99d7062014-06-19 16:01:59 +02005332 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005333 if (IS_GEN(dev_priv, 2))
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005334 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5335
Ville Syrjäläaca7b682015-10-30 19:22:21 +02005336 /* Underruns don't always raise interrupts, so check manually. */
5337 intel_check_cpu_fifo_underruns(dev_priv);
5338 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005339}
5340
Ville Syrjälä2622a082016-03-09 19:07:26 +02005341/* FIXME get rid of this and use pre_plane_update */
5342static void
5343intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5344{
5345 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005346 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä2622a082016-03-09 19:07:26 +02005347 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5348 int pipe = intel_crtc->pipe;
5349
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005350 /*
5351 * Gen2 reports pipe underruns whenever all planes are disabled.
5352 * So disable underrun reporting before all the planes get disabled.
5353 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005354 if (IS_GEN(dev_priv, 2))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005355 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5356
5357 hsw_disable_ips(to_intel_crtc_state(crtc->state));
Ville Syrjälä2622a082016-03-09 19:07:26 +02005358
5359 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005360 * Vblank time updates from the shadow to live plane control register
5361 * are blocked if the memory self-refresh mode is active at that
5362 * moment. So to make sure the plane gets truly disabled, disable
5363 * first the self-refresh mode. The self-refresh enable bit in turn
5364 * will be checked/applied by the HW only at the next frame start
5365 * event which is after the vblank start event, so we need to have a
5366 * wait-for-vblank between disabling the plane and the pipe.
5367 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08005368 if (HAS_GMCH(dev_priv) &&
Ville Syrjälä11a85d62016-11-28 19:37:12 +02005369 intel_set_memory_cxsr(dev_priv, false))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005370 intel_wait_for_vblank(dev_priv, pipe);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005371}
5372
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005373static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5374 const struct intel_crtc_state *new_crtc_state)
5375{
Ville Syrjälä051a6d82019-02-05 18:08:41 +02005376 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5377 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5378
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005379 if (!old_crtc_state->ips_enabled)
5380 return false;
5381
5382 if (needs_modeset(&new_crtc_state->base))
5383 return true;
5384
Ville Syrjälä051a6d82019-02-05 18:08:41 +02005385 /*
5386 * Workaround : Do not read or write the pipe palette/gamma data while
5387 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5388 *
5389 * Disable IPS before we program the LUT.
5390 */
5391 if (IS_HASWELL(dev_priv) &&
5392 (new_crtc_state->base.color_mgmt_changed ||
5393 new_crtc_state->update_pipe) &&
5394 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5395 return true;
5396
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005397 return !new_crtc_state->ips_enabled;
5398}
5399
5400static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5401 const struct intel_crtc_state *new_crtc_state)
5402{
Ville Syrjälä051a6d82019-02-05 18:08:41 +02005403 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5405
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005406 if (!new_crtc_state->ips_enabled)
5407 return false;
5408
5409 if (needs_modeset(&new_crtc_state->base))
5410 return true;
5411
5412 /*
Ville Syrjälä051a6d82019-02-05 18:08:41 +02005413 * Workaround : Do not read or write the pipe palette/gamma data while
5414 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5415 *
5416 * Re-enable IPS after the LUT has been programmed.
5417 */
5418 if (IS_HASWELL(dev_priv) &&
5419 (new_crtc_state->base.color_mgmt_changed ||
5420 new_crtc_state->update_pipe) &&
5421 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5422 return true;
5423
5424 /*
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005425 * We can't read out IPS on broadwell, assume the worst and
5426 * forcibly enable IPS on the first fastset.
5427 */
5428 if (new_crtc_state->update_pipe &&
5429 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5430 return true;
5431
5432 return !old_crtc_state->ips_enabled;
5433}
5434
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305435static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5436 const struct intel_crtc_state *crtc_state)
5437{
5438 if (!crtc_state->nv12_planes)
5439 return false;
5440
Rodrigo Vivi1347d3c2018-10-31 09:28:45 -07005441 /* WA Display #0827: Gen9:all */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005442 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305443 return true;
5444
5445 return false;
5446}
5447
Daniel Vetter5a21b662016-05-24 17:13:53 +02005448static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5449{
5450 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +05305451 struct drm_device *dev = crtc->base.dev;
5452 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005453 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5454 struct intel_crtc_state *pipe_config =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005455 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5456 crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005457 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005458 struct drm_plane_state *old_primary_state =
5459 drm_atomic_get_old_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005460
Chris Wilson5748b6a2016-08-04 16:32:38 +01005461 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005462
Daniel Vetter5a21b662016-05-24 17:13:53 +02005463 if (pipe_config->update_wm_post && pipe_config->base.active)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005464 intel_update_watermarks(crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005465
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005466 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5467 hsw_enable_ips(pipe_config);
5468
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005469 if (old_primary_state) {
5470 struct drm_plane_state *new_primary_state =
5471 drm_atomic_get_new_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005472
5473 intel_fbc_post_update(crtc);
5474
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005475 if (new_primary_state->visible &&
Daniel Vetter5a21b662016-05-24 17:13:53 +02005476 (needs_modeset(&pipe_config->base) ||
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005477 !old_primary_state->visible))
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005478 intel_post_enable_primary(&crtc->base, pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005479 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305480
5481 /* Display WA 827 */
5482 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305483 !needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305484 skl_wa_clkgate(dev_priv, crtc->pipe, false);
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305485 }
Daniel Vetter5a21b662016-05-24 17:13:53 +02005486}
5487
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005488static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5489 struct intel_crtc_state *pipe_config)
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005490{
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005491 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005492 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005493 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005494 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5495 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005496 struct drm_plane_state *old_primary_state =
5497 drm_atomic_get_old_plane_state(old_state, primary);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005498 bool modeset = needs_modeset(&pipe_config->base);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005499 struct intel_atomic_state *old_intel_state =
5500 to_intel_atomic_state(old_state);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005501
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005502 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5503 hsw_disable_ips(old_crtc_state);
5504
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005505 if (old_primary_state) {
5506 struct intel_plane_state *new_primary_state =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005507 intel_atomic_get_new_plane_state(old_intel_state,
5508 to_intel_plane(primary));
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005509
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005510 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005511 /*
5512 * Gen2 reports pipe underruns whenever all planes are disabled.
5513 * So disable underrun reporting before all the planes get disabled.
5514 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005515 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005516 (modeset || !new_primary_state->base.visible))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005517 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005518 }
Ville Syrjälä852eb002015-06-24 22:00:07 +03005519
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305520 /* Display WA 827 */
5521 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305522 needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305523 skl_wa_clkgate(dev_priv, crtc->pipe, true);
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305524 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305525
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02005526 /*
5527 * Vblank time updates from the shadow to live plane control register
5528 * are blocked if the memory self-refresh mode is active at that
5529 * moment. So to make sure the plane gets truly disabled, disable
5530 * first the self-refresh mode. The self-refresh enable bit in turn
5531 * will be checked/applied by the HW only at the next frame start
5532 * event which is after the vblank start event, so we need to have a
5533 * wait-for-vblank between disabling the plane and the pipe.
5534 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08005535 if (HAS_GMCH(dev_priv) && old_crtc_state->base.active &&
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02005536 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5537 intel_wait_for_vblank(dev_priv, crtc->pipe);
Maarten Lankhorst92826fc2015-12-03 13:49:13 +01005538
Matt Ropered4a6a72016-02-23 17:20:13 -08005539 /*
5540 * IVB workaround: must disable low power watermarks for at least
5541 * one frame before enabling scaling. LP watermarks can be re-enabled
5542 * when scaling is disabled.
5543 *
5544 * WaCxSRDisabledForSpriteScaling:ivb
5545 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +03005546 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5547 old_crtc_state->base.active)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005548 intel_wait_for_vblank(dev_priv, crtc->pipe);
Matt Ropered4a6a72016-02-23 17:20:13 -08005549
5550 /*
5551 * If we're doing a modeset, we're done. No need to do any pre-vblank
5552 * watermark programming here.
5553 */
5554 if (needs_modeset(&pipe_config->base))
5555 return;
5556
5557 /*
5558 * For platforms that support atomic watermarks, program the
5559 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5560 * will be the intermediate values that are safe for both pre- and
5561 * post- vblank; when vblank happens, the 'active' values will be set
5562 * to the final 'target' values and we'll do this again to get the
5563 * optimal watermarks. For gen9+ platforms, the values we program here
5564 * will be the final target values which will get automatically latched
5565 * at vblank time; no further programming will be necessary.
5566 *
5567 * If a platform hasn't been transitioned to atomic watermarks yet,
5568 * we'll continue to update watermarks the old way, if flags tell
5569 * us to.
5570 */
5571 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005572 dev_priv->display.initial_watermarks(old_intel_state,
5573 pipe_config);
Ville Syrjäläcaed3612016-03-09 19:07:25 +02005574 else if (pipe_config->update_wm_pre)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005575 intel_update_watermarks(crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005576}
5577
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005578static void intel_crtc_disable_planes(struct intel_atomic_state *state,
5579 struct intel_crtc *crtc)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005580{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005581 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5582 const struct intel_crtc_state *new_crtc_state =
5583 intel_atomic_get_new_crtc_state(state, crtc);
5584 unsigned int update_mask = new_crtc_state->update_planes;
5585 const struct intel_plane_state *old_plane_state;
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005586 struct intel_plane *plane;
5587 unsigned fb_bits = 0;
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005588 int i;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005589
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005590 intel_crtc_dpms_overlay_disable(crtc);
Maarten Lankhorst27321ae2015-04-21 17:12:52 +03005591
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005592 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
5593 if (crtc->pipe != plane->pipe ||
5594 !(update_mask & BIT(plane->id)))
5595 continue;
Ville Syrjäläf98551a2014-05-22 17:48:06 +03005596
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005597 plane->disable_plane(plane, new_crtc_state);
5598
5599 if (old_plane_state->base.visible)
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005600 fb_bits |= plane->frontbuffer_bit;
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005601 }
5602
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005603 intel_frontbuffer_flip(dev_priv, fb_bits);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005604}
5605
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005606static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005607 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005608 struct drm_atomic_state *old_state)
5609{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005610 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005611 struct drm_connector *conn;
5612 int i;
5613
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005614 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005615 struct intel_encoder *encoder =
5616 to_intel_encoder(conn_state->best_encoder);
5617
5618 if (conn_state->crtc != crtc)
5619 continue;
5620
5621 if (encoder->pre_pll_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005622 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005623 }
5624}
5625
5626static void intel_encoders_pre_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005627 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005628 struct drm_atomic_state *old_state)
5629{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005630 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005631 struct drm_connector *conn;
5632 int i;
5633
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005634 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005635 struct intel_encoder *encoder =
5636 to_intel_encoder(conn_state->best_encoder);
5637
5638 if (conn_state->crtc != crtc)
5639 continue;
5640
5641 if (encoder->pre_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005642 encoder->pre_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005643 }
5644}
5645
5646static void intel_encoders_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005647 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005648 struct drm_atomic_state *old_state)
5649{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005650 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005651 struct drm_connector *conn;
5652 int i;
5653
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005654 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005655 struct intel_encoder *encoder =
5656 to_intel_encoder(conn_state->best_encoder);
5657
5658 if (conn_state->crtc != crtc)
5659 continue;
5660
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005661 if (encoder->enable)
5662 encoder->enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005663 intel_opregion_notify_encoder(encoder, true);
5664 }
5665}
5666
5667static void intel_encoders_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005668 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005669 struct drm_atomic_state *old_state)
5670{
5671 struct drm_connector_state *old_conn_state;
5672 struct drm_connector *conn;
5673 int i;
5674
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005675 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005676 struct intel_encoder *encoder =
5677 to_intel_encoder(old_conn_state->best_encoder);
5678
5679 if (old_conn_state->crtc != crtc)
5680 continue;
5681
5682 intel_opregion_notify_encoder(encoder, false);
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005683 if (encoder->disable)
5684 encoder->disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005685 }
5686}
5687
5688static void intel_encoders_post_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005689 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005690 struct drm_atomic_state *old_state)
5691{
5692 struct drm_connector_state *old_conn_state;
5693 struct drm_connector *conn;
5694 int i;
5695
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005696 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005697 struct intel_encoder *encoder =
5698 to_intel_encoder(old_conn_state->best_encoder);
5699
5700 if (old_conn_state->crtc != crtc)
5701 continue;
5702
5703 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005704 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005705 }
5706}
5707
5708static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005709 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005710 struct drm_atomic_state *old_state)
5711{
5712 struct drm_connector_state *old_conn_state;
5713 struct drm_connector *conn;
5714 int i;
5715
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005716 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005717 struct intel_encoder *encoder =
5718 to_intel_encoder(old_conn_state->best_encoder);
5719
5720 if (old_conn_state->crtc != crtc)
5721 continue;
5722
5723 if (encoder->post_pll_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005724 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005725 }
5726}
5727
Hans de Goede608ed4a2018-12-20 14:21:18 +01005728static void intel_encoders_update_pipe(struct drm_crtc *crtc,
5729 struct intel_crtc_state *crtc_state,
5730 struct drm_atomic_state *old_state)
5731{
5732 struct drm_connector_state *conn_state;
5733 struct drm_connector *conn;
5734 int i;
5735
5736 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5737 struct intel_encoder *encoder =
5738 to_intel_encoder(conn_state->best_encoder);
5739
5740 if (conn_state->crtc != crtc)
5741 continue;
5742
5743 if (encoder->update_pipe)
5744 encoder->update_pipe(encoder, crtc_state, conn_state);
5745 }
5746}
5747
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005748static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5749 struct drm_atomic_state *old_state)
Jesse Barnesf67a5592011-01-05 10:31:48 -08005750{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005751 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnesf67a5592011-01-05 10:31:48 -08005752 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005753 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005754 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5755 int pipe = intel_crtc->pipe;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005756 struct intel_atomic_state *old_intel_state =
5757 to_intel_atomic_state(old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005758
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005759 if (WARN_ON(intel_crtc->active))
Jesse Barnesf67a5592011-01-05 10:31:48 -08005760 return;
5761
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005762 /*
5763 * Sometimes spurious CPU pipe underruns happen during FDI
5764 * training, at least with VGA+HDMI cloning. Suppress them.
5765 *
5766 * On ILK we get an occasional spurious CPU pipe underruns
5767 * between eDP port A enable and vdd enable. Also PCH port
5768 * enable seems to result in the occasional CPU pipe underrun.
5769 *
5770 * Spurious PCH underruns also occur during PCH enabling.
5771 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005772 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5773 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005774
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005775 if (pipe_config->has_pch_encoder)
5776 intel_prepare_shared_dpll(pipe_config);
Daniel Vetterb14b1052014-04-24 23:55:13 +02005777
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005778 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005779 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005780
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005781 intel_set_pipe_timings(pipe_config);
5782 intel_set_pipe_src_size(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005783
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005784 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005785 intel_cpu_transcoder_set_m_n(pipe_config,
5786 &pipe_config->fdi_m_n, NULL);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005787 }
5788
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005789 ironlake_set_pipeconf(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005790
Jesse Barnesf67a5592011-01-05 10:31:48 -08005791 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005792
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005793 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005794
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005795 if (pipe_config->has_pch_encoder) {
Daniel Vetterfff367c2012-10-27 15:50:28 +02005796 /* Note: FDI PLL enabling _must_ be done before we enable the
5797 * cpu pipes, hence this is separate from all the other fdi/pch
5798 * enabling. */
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02005799 ironlake_fdi_pll_enable(pipe_config);
Daniel Vetter46b6f812012-09-06 22:08:33 +02005800 } else {
5801 assert_fdi_tx_disabled(dev_priv, pipe);
5802 assert_fdi_rx_disabled(dev_priv, pipe);
5803 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005804
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005805 ironlake_pfit_enable(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005806
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005807 /*
5808 * On ILK+ LUT must be loaded before the pipe is running but with
5809 * clocks enabled
5810 */
Matt Roper302da0c2018-12-10 13:54:15 -08005811 intel_color_load_luts(pipe_config);
Ville Syrjälä4d8ed542019-02-05 18:08:40 +02005812 intel_color_commit(pipe_config);
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005813
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005814 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005815 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02005816 intel_enable_pipe(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005817
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005818 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005819 ironlake_pch_enable(old_intel_state, pipe_config);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005820
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005821 assert_vblank_disabled(crtc);
Ville Syrjälä32db0b62018-11-27 22:05:50 +02005822 intel_crtc_vblank_on(pipe_config);
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005823
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005824 intel_encoders_enable(crtc, pipe_config, old_state);
Daniel Vetter61b77dd2012-07-02 00:16:19 +02005825
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005826 if (HAS_PCH_CPT(dev_priv))
Daniel Vettera1520312013-05-03 11:49:50 +02005827 cpt_verify_modeset(dev, intel_crtc->pipe);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005828
Ville Syrjäläea80a662018-05-24 22:04:05 +03005829 /*
5830 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5831 * And a second vblank wait is needed at least on ILK with
5832 * some interlaced HDMI modes. Let's do the double wait always
5833 * in case there are more corner cases we don't know about.
5834 */
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005835 if (pipe_config->has_pch_encoder) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005836 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjäläea80a662018-05-24 22:04:05 +03005837 intel_wait_for_vblank(dev_priv, pipe);
5838 }
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005839 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005840 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005841}
5842
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005843/* IPS only exists on ULT machines and is tied to pipe A. */
5844static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5845{
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005846 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005847}
5848
Imre Deaked69cd42017-10-02 10:55:57 +03005849static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5850 enum pipe pipe, bool apply)
5851{
5852 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5853 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5854
5855 if (apply)
5856 val |= mask;
5857 else
5858 val &= ~mask;
5859
5860 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5861}
5862
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005863static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5864{
5865 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5866 enum pipe pipe = crtc->pipe;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02005867 u32 val;
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005868
Rodrigo Vivi443d5e32018-10-04 08:18:14 -07005869 val = MBUS_DBOX_A_CREDIT(2);
5870 val |= MBUS_DBOX_BW_CREDIT(1);
5871 val |= MBUS_DBOX_B_CREDIT(8);
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005872
5873 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5874}
5875
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005876static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5877 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005878{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005879 struct drm_crtc *crtc = pipe_config->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005880 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005881 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005882 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005883 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005884 struct intel_atomic_state *old_intel_state =
5885 to_intel_atomic_state(old_state);
Imre Deaked69cd42017-10-02 10:55:57 +03005886 bool psl_clkgate_wa;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005887
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005888 if (WARN_ON(intel_crtc->active))
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005889 return;
5890
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005891 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03005892
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005893 if (pipe_config->shared_dpll)
5894 intel_enable_shared_dpll(pipe_config);
Daniel Vetterdf8ad702014-06-25 22:02:03 +03005895
Paulo Zanonic8af5272018-05-02 14:58:51 -07005896 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5897
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005898 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005899 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter229fca92014-04-24 23:55:09 +02005900
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005901 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005902 intel_set_pipe_timings(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005903
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005904 intel_set_pipe_src_size(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005905
Jani Nikula4d1de972016-03-18 17:05:42 +02005906 if (cpu_transcoder != TRANSCODER_EDP &&
5907 !transcoder_is_dsi(cpu_transcoder)) {
5908 I915_WRITE(PIPE_MULT(cpu_transcoder),
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005909 pipe_config->pixel_multiplier - 1);
Clint Taylorebb69c92014-09-30 10:30:22 -07005910 }
5911
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005912 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005913 intel_cpu_transcoder_set_m_n(pipe_config,
5914 &pipe_config->fdi_m_n, NULL);
Daniel Vetter229fca92014-04-24 23:55:09 +02005915 }
5916
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005917 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005918 haswell_set_pipeconf(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005919
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005920 haswell_set_pipemisc(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005921
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005922 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005923
Imre Deaked69cd42017-10-02 10:55:57 +03005924 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5925 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005926 pipe_config->pch_pfit.enabled;
Imre Deaked69cd42017-10-02 10:55:57 +03005927 if (psl_clkgate_wa)
5928 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5929
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005930 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005931 skylake_pfit_enable(pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005932 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005933 ironlake_pfit_enable(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005934
5935 /*
5936 * On ILK+ LUT must be loaded before the pipe is running but with
5937 * clocks enabled
5938 */
Matt Roper302da0c2018-12-10 13:54:15 -08005939 intel_color_load_luts(pipe_config);
Ville Syrjälä4d8ed542019-02-05 18:08:40 +02005940 intel_color_commit(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005941
Ville Syrjäläd1622112019-02-04 22:21:39 +02005942 if (INTEL_GEN(dev_priv) >= 11)
5943 icl_set_pipe_chicken(intel_crtc);
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305944
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005945 intel_ddi_set_pipe_settings(pipe_config);
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005946 if (!transcoder_is_dsi(cpu_transcoder))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005947 intel_ddi_enable_transcoder_func(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005948
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005949 if (dev_priv->display.initial_watermarks != NULL)
Ville Syrjälä3125d392016-11-28 19:37:03 +02005950 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005951
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005952 if (INTEL_GEN(dev_priv) >= 11)
5953 icl_pipe_mbus_enable(intel_crtc);
5954
Jani Nikula4d1de972016-03-18 17:05:42 +02005955 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005956 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005957 intel_enable_pipe(pipe_config);
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005958
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005959 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005960 lpt_pch_enable(old_intel_state, pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005961
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005962 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005963 intel_ddi_set_vc_payload_alloc(pipe_config, true);
Dave Airlie0e32b392014-05-02 14:02:48 +10005964
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005965 assert_vblank_disabled(crtc);
Ville Syrjälä32db0b62018-11-27 22:05:50 +02005966 intel_crtc_vblank_on(pipe_config);
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005967
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005968 intel_encoders_enable(crtc, pipe_config, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005969
Imre Deaked69cd42017-10-02 10:55:57 +03005970 if (psl_clkgate_wa) {
5971 intel_wait_for_vblank(dev_priv, pipe);
5972 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5973 }
5974
Paulo Zanonie4916942013-09-20 16:21:19 -03005975 /* If we change the relative order between pipe/planes enabling, we need
5976 * to change the workaround. */
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005977 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01005978 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005979 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5980 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005981 }
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005982}
5983
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005984static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005985{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005986 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5987 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5988 enum pipe pipe = crtc->pipe;
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005989
5990 /* To avoid upsetting the power well on haswell only disable the pfit if
5991 * it's in use. The hw state code will make sure we get this right. */
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005992 if (old_crtc_state->pch_pfit.enabled) {
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005993 I915_WRITE(PF_CTL(pipe), 0);
5994 I915_WRITE(PF_WIN_POS(pipe), 0);
5995 I915_WRITE(PF_WIN_SZ(pipe), 0);
5996 }
5997}
5998
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005999static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
6000 struct drm_atomic_state *old_state)
Jesse Barnes6be4a602010-09-10 10:26:01 -07006001{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006002 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes6be4a602010-09-10 10:26:01 -07006003 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006004 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006005 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6006 int pipe = intel_crtc->pipe;
Jesse Barnes6be4a602010-09-10 10:26:01 -07006007
Ville Syrjäläb2c05932016-04-01 21:53:17 +03006008 /*
6009 * Sometimes spurious CPU pipe underruns happen when the
6010 * pipe is already disabled, but FDI RX/TX is still enabled.
6011 * Happens at least with VGA+HDMI cloning. Suppress them.
6012 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03006013 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6014 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02006015
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006016 intel_encoders_disable(crtc, old_crtc_state, old_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +02006017
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006018 drm_crtc_vblank_off(crtc);
6019 assert_vblank_disabled(crtc);
6020
Ville Syrjälä4972f702017-11-29 17:37:32 +02006021 intel_disable_pipe(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006022
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006023 ironlake_pfit_disable(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006024
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006025 if (old_crtc_state->has_pch_encoder)
Ville Syrjälä5a74f702015-05-05 17:17:38 +03006026 ironlake_fdi_disable(crtc);
6027
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006028 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006029
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006030 if (old_crtc_state->has_pch_encoder) {
Daniel Vetterd925c592013-06-05 13:34:04 +02006031 ironlake_disable_pch_transcoder(dev_priv, pipe);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006032
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006033 if (HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02006034 i915_reg_t reg;
6035 u32 temp;
6036
Daniel Vetterd925c592013-06-05 13:34:04 +02006037 /* disable TRANS_DP_CTL */
6038 reg = TRANS_DP_CTL(pipe);
6039 temp = I915_READ(reg);
6040 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6041 TRANS_DP_PORT_SEL_MASK);
6042 temp |= TRANS_DP_PORT_SEL_NONE;
6043 I915_WRITE(reg, temp);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006044
Daniel Vetterd925c592013-06-05 13:34:04 +02006045 /* disable DPLL_SEL */
6046 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02006047 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
Daniel Vetterd925c592013-06-05 13:34:04 +02006048 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08006049 }
Daniel Vetterd925c592013-06-05 13:34:04 +02006050
Daniel Vetterd925c592013-06-05 13:34:04 +02006051 ironlake_fdi_pll_disable(intel_crtc);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006052 }
Ville Syrjälä81b088c2015-10-30 19:21:31 +02006053
Ville Syrjäläb2c05932016-04-01 21:53:17 +03006054 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02006055 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006056}
6057
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006058static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
6059 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006060{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006061 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006062 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006063 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Imre Deak24a28172018-06-13 20:07:06 +03006064 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006065
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006066 intel_encoders_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006067
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006068 drm_crtc_vblank_off(crtc);
6069 assert_vblank_disabled(crtc);
6070
Jani Nikula4d1de972016-03-18 17:05:42 +02006071 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006072 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02006073 intel_disable_pipe(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006074
Imre Deak24a28172018-06-13 20:07:06 +03006075 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
6076 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
Ville Syrjäläa4bf2142014-08-18 21:27:34 +03006077
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006078 if (!transcoder_is_dsi(cpu_transcoder))
Clint Taylor90c3e212018-07-10 13:02:05 -07006079 intel_ddi_disable_transcoder_func(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006080
Manasi Navarea6006222018-11-28 12:26:23 -08006081 intel_dsc_disable(old_crtc_state);
6082
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006083 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02006084 skylake_scaler_disable(intel_crtc);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08006085 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006086 ironlake_pfit_disable(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006087
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006088 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Paulo Zanonic27e9172018-04-27 16:14:36 -07006089
Imre Deakbdaa29b2018-11-01 16:04:24 +02006090 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006091}
6092
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006093static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes2dd24552013-04-25 12:55:01 -07006094{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006095 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6096 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006097
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006098 if (!crtc_state->gmch_pfit.control)
Jesse Barnes2dd24552013-04-25 12:55:01 -07006099 return;
6100
Daniel Vetterc0b03412013-05-28 12:05:54 +02006101 /*
6102 * The panel fitter should only be adjusted whilst the pipe is disabled,
6103 * according to register description and PRM.
6104 */
Jesse Barnes2dd24552013-04-25 12:55:01 -07006105 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6106 assert_pipe_disabled(dev_priv, crtc->pipe);
6107
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006108 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6109 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
Daniel Vetter5a80c452013-04-25 22:52:18 +02006110
6111 /* Border color in case we don't scale up to the full screen. Black by
6112 * default, change to something else for debugging. */
6113 I915_WRITE(BCLRPAT(crtc->pipe), 0);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006114}
6115
Mahesh Kumar176597a2018-10-04 14:20:43 +05306116bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
6117{
6118 if (port == PORT_NONE)
6119 return false;
6120
6121 if (IS_ICELAKE(dev_priv))
6122 return port <= PORT_B;
6123
6124 return false;
6125}
6126
Paulo Zanoniac213c12018-05-21 17:25:37 -07006127bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
6128{
6129 if (IS_ICELAKE(dev_priv))
6130 return port >= PORT_C && port <= PORT_F;
6131
6132 return false;
6133}
6134
6135enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6136{
6137 if (!intel_port_is_tc(dev_priv, port))
6138 return PORT_TC_NONE;
6139
6140 return port - PORT_C;
6141}
6142
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006143enum intel_display_power_domain intel_port_to_power_domain(enum port port)
Dave Airlied05410f2014-06-05 13:22:59 +10006144{
6145 switch (port) {
6146 case PORT_A:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006147 return POWER_DOMAIN_PORT_DDI_A_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006148 case PORT_B:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006149 return POWER_DOMAIN_PORT_DDI_B_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006150 case PORT_C:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006151 return POWER_DOMAIN_PORT_DDI_C_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006152 case PORT_D:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006153 return POWER_DOMAIN_PORT_DDI_D_LANES;
Xiong Zhangd8e19f92015-08-13 18:00:12 +08006154 case PORT_E:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006155 return POWER_DOMAIN_PORT_DDI_E_LANES;
Rodrigo Vivi9787e832018-01-29 15:22:22 -08006156 case PORT_F:
6157 return POWER_DOMAIN_PORT_DDI_F_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006158 default:
Imre Deakb9fec162015-11-18 15:57:25 +02006159 MISSING_CASE(port);
Dave Airlied05410f2014-06-05 13:22:59 +10006160 return POWER_DOMAIN_PORT_OTHER;
6161 }
6162}
6163
Imre Deak337837a2018-11-01 16:04:23 +02006164enum intel_display_power_domain
6165intel_aux_power_domain(struct intel_digital_port *dig_port)
6166{
6167 switch (dig_port->aux_ch) {
6168 case AUX_CH_A:
6169 return POWER_DOMAIN_AUX_A;
6170 case AUX_CH_B:
6171 return POWER_DOMAIN_AUX_B;
6172 case AUX_CH_C:
6173 return POWER_DOMAIN_AUX_C;
6174 case AUX_CH_D:
6175 return POWER_DOMAIN_AUX_D;
6176 case AUX_CH_E:
6177 return POWER_DOMAIN_AUX_E;
6178 case AUX_CH_F:
6179 return POWER_DOMAIN_AUX_F;
6180 default:
6181 MISSING_CASE(dig_port->aux_ch);
6182 return POWER_DOMAIN_AUX_A;
6183 }
6184}
6185
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006186static u64 get_crtc_power_domains(struct drm_crtc *crtc,
6187 struct intel_crtc_state *crtc_state)
Imre Deak319be8a2014-03-04 19:22:57 +02006188{
6189 struct drm_device *dev = crtc->dev;
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006190 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006191 struct drm_encoder *encoder;
Imre Deak319be8a2014-03-04 19:22:57 +02006192 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6193 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006194 u64 mask;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006195 enum transcoder transcoder = crtc_state->cpu_transcoder;
Imre Deak77d22dc2014-03-05 16:20:52 +02006196
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006197 if (!crtc_state->base.active)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006198 return 0;
6199
Imre Deak17bd6e62018-01-09 14:20:40 +02006200 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6201 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006202 if (crtc_state->pch_pfit.enabled ||
6203 crtc_state->pch_pfit.force_thru)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006204 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
Imre Deak77d22dc2014-03-05 16:20:52 +02006205
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006206 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6207 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6208
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006209 mask |= BIT_ULL(intel_encoder->power_domain);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006210 }
Imre Deak319be8a2014-03-04 19:22:57 +02006211
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006212 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
Imre Deak17bd6e62018-01-09 14:20:40 +02006213 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006214
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006215 if (crtc_state->shared_dpll)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006216 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006217
Imre Deak77d22dc2014-03-05 16:20:52 +02006218 return mask;
6219}
6220
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006221static u64
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006222modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6223 struct intel_crtc_state *crtc_state)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006224{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006225 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006226 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6227 enum intel_display_power_domain domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006228 u64 domains, new_domains, old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006229
6230 old_domains = intel_crtc->enabled_power_domains;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006231 intel_crtc->enabled_power_domains = new_domains =
6232 get_crtc_power_domains(crtc, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006233
Daniel Vetter5a21b662016-05-24 17:13:53 +02006234 domains = new_domains & ~old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006235
6236 for_each_power_domain(domain, domains)
6237 intel_display_power_get(dev_priv, domain);
6238
Daniel Vetter5a21b662016-05-24 17:13:53 +02006239 return old_domains & ~new_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006240}
6241
6242static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006243 u64 domains)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006244{
6245 enum intel_display_power_domain domain;
6246
6247 for_each_power_domain(domain, domains)
Chris Wilson0e6e0be2019-01-14 14:21:24 +00006248 intel_display_power_put_unchecked(dev_priv, domain);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006249}
6250
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006251static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6252 struct drm_atomic_state *old_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006253{
Ville Syrjäläff32c542017-03-02 19:14:57 +02006254 struct intel_atomic_state *old_intel_state =
6255 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006256 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006257 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006258 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006259 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006260 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006261
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006262 if (WARN_ON(intel_crtc->active))
Jesse Barnes89b667f2013-04-18 14:51:36 -07006263 return;
6264
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006265 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006266 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006267
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006268 intel_set_pipe_timings(pipe_config);
6269 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006270
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006271 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjäläc14b0482014-10-16 20:52:34 +03006272 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6273 I915_WRITE(CHV_CANVAS(pipe), 0);
6274 }
6275
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006276 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006277
Jesse Barnes89b667f2013-04-18 14:51:36 -07006278 intel_crtc->active = true;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006279
Daniel Vettera72e4c92014-09-30 10:56:47 +02006280 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006281
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006282 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006283
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006284 if (IS_CHERRYVIEW(dev_priv)) {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006285 chv_prepare_pll(intel_crtc, pipe_config);
6286 chv_enable_pll(intel_crtc, pipe_config);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006287 } else {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006288 vlv_prepare_pll(intel_crtc, pipe_config);
6289 vlv_enable_pll(intel_crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006290 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07006291
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006292 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006293
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006294 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006295
Matt Roper302da0c2018-12-10 13:54:15 -08006296 intel_color_load_luts(pipe_config);
Ville Syrjälä4d8ed542019-02-05 18:08:40 +02006297 intel_color_commit(pipe_config);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006298
Ville Syrjäläff32c542017-03-02 19:14:57 +02006299 dev_priv->display.initial_watermarks(old_intel_state,
6300 pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006301 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006302
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006303 assert_vblank_disabled(crtc);
Ville Syrjälä32db0b62018-11-27 22:05:50 +02006304 intel_crtc_vblank_on(pipe_config);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006305
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006306 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006307}
6308
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006309static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006310{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006311 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6312 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006313
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006314 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6315 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006316}
6317
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006318static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6319 struct drm_atomic_state *old_state)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006320{
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006321 struct intel_atomic_state *old_intel_state =
6322 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006323 struct drm_crtc *crtc = pipe_config->base.crtc;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006324 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006325 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -08006326 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006327 enum pipe pipe = intel_crtc->pipe;
Jesse Barnes79e53942008-11-07 14:24:08 -08006328
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006329 if (WARN_ON(intel_crtc->active))
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006330 return;
6331
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006332 i9xx_set_pll_dividers(pipe_config);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006333
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006334 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006335 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006336
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006337 intel_set_pipe_timings(pipe_config);
6338 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006339
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006340 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006341
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006342 intel_crtc->active = true;
Chris Wilson6b383a72010-09-13 13:54:26 +01006343
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006344 if (!IS_GEN(dev_priv, 2))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006345 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006346
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006347 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Mika Kuoppala9d6d9f12013-02-08 16:35:38 +02006348
Ville Syrjälä939994d2017-09-13 17:08:56 +03006349 i9xx_enable_pll(intel_crtc, pipe_config);
Daniel Vetterf6736a12013-06-05 13:34:30 +02006350
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006351 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006352
Matt Roper302da0c2018-12-10 13:54:15 -08006353 intel_color_load_luts(pipe_config);
Ville Syrjälä4d8ed542019-02-05 18:08:40 +02006354 intel_color_commit(pipe_config);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006355
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006356 if (dev_priv->display.initial_watermarks != NULL)
6357 dev_priv->display.initial_watermarks(old_intel_state,
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006358 pipe_config);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006359 else
6360 intel_update_watermarks(intel_crtc);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006361 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006362
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006363 assert_vblank_disabled(crtc);
Ville Syrjälä32db0b62018-11-27 22:05:50 +02006364 intel_crtc_vblank_on(pipe_config);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006365
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006366 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006367}
6368
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006369static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter87476d62013-04-11 16:29:06 +02006370{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006371 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6372 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter328d8e82013-05-08 10:36:31 +02006373
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006374 if (!old_crtc_state->gmch_pfit.control)
Daniel Vetter328d8e82013-05-08 10:36:31 +02006375 return;
Daniel Vetter87476d62013-04-11 16:29:06 +02006376
6377 assert_pipe_disabled(dev_priv, crtc->pipe);
6378
Chris Wilson43031782018-09-13 14:16:26 +01006379 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6380 I915_READ(PFIT_CONTROL));
Daniel Vetter328d8e82013-05-08 10:36:31 +02006381 I915_WRITE(PFIT_CONTROL, 0);
Daniel Vetter87476d62013-04-11 16:29:06 +02006382}
6383
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006384static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6385 struct drm_atomic_state *old_state)
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006386{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006387 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006388 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006389 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006390 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6391 int pipe = intel_crtc->pipe;
Daniel Vetteref9c3ae2012-06-29 22:40:09 +02006392
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006393 /*
6394 * On gen2 planes are double buffered but the pipe isn't, so we must
6395 * wait for planes to fully turn off before disabling the pipe.
6396 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006397 if (IS_GEN(dev_priv, 2))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02006398 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006399
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006400 intel_encoders_disable(crtc, old_crtc_state, old_state);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006401
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006402 drm_crtc_vblank_off(crtc);
6403 assert_vblank_disabled(crtc);
6404
Ville Syrjälä4972f702017-11-29 17:37:32 +02006405 intel_disable_pipe(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006406
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006407 i9xx_pfit_disable(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006408
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006409 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006410
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006411 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006412 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006413 chv_disable_pll(dev_priv, pipe);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006414 else if (IS_VALLEYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006415 vlv_disable_pll(dev_priv, pipe);
6416 else
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006417 i9xx_disable_pll(old_crtc_state);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006418 }
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006419
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006420 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006421
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006422 if (!IS_GEN(dev_priv, 2))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006423 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjäläff32c542017-03-02 19:14:57 +02006424
6425 if (!dev_priv->display.initial_watermarks)
6426 intel_update_watermarks(intel_crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03006427
6428 /* clock the pipe down to 640x480@60 to potentially save power */
6429 if (IS_I830(dev_priv))
6430 i830_enable_pipe(dev_priv, pipe);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006431}
6432
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006433static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6434 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnesee7b9f92012-04-20 17:11:53 +01006435{
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006436 struct intel_encoder *encoder;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006437 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006438 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006439 enum intel_display_power_domain domain;
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006440 struct intel_plane *plane;
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006441 u64 domains;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006442 struct drm_atomic_state *state;
6443 struct intel_crtc_state *crtc_state;
6444 int ret;
Daniel Vetter976f8a22012-07-08 22:34:21 +02006445
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006446 if (!intel_crtc->active)
6447 return;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006448
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006449 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6450 const struct intel_plane_state *plane_state =
6451 to_intel_plane_state(plane->base.state);
Maarten Lankhorst54a419612015-11-23 10:25:28 +01006452
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006453 if (plane_state->base.visible)
6454 intel_plane_disable_noatomic(intel_crtc, plane);
Maarten Lankhorsta5392052015-06-15 12:33:52 +02006455 }
6456
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006457 state = drm_atomic_state_alloc(crtc->dev);
Ander Conselvan de Oliveira31bb2ef2017-01-20 16:28:45 +02006458 if (!state) {
6459 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6460 crtc->base.id, crtc->name);
6461 return;
6462 }
6463
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006464 state->acquire_ctx = ctx;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006465
6466 /* Everything's already locked, -EDEADLK can't happen. */
6467 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6468 ret = drm_atomic_add_affected_connectors(state, crtc);
6469
6470 WARN_ON(IS_ERR(crtc_state) || ret);
6471
6472 dev_priv->display.crtc_disable(crtc_state, state);
6473
Chris Wilson08536952016-10-14 13:18:18 +01006474 drm_atomic_state_put(state);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006475
Ville Syrjälä78108b72016-05-27 20:59:19 +03006476 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6477 crtc->base.id, crtc->name);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006478
6479 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6480 crtc->state->active = false;
Matt Roper37d90782015-09-24 15:53:06 -07006481 intel_crtc->active = false;
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006482 crtc->enabled = false;
6483 crtc->state->connector_mask = 0;
6484 crtc->state->encoder_mask = 0;
6485
6486 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6487 encoder->base.crtc = NULL;
6488
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -02006489 intel_fbc_disable(intel_crtc);
Ville Syrjälä432081b2016-10-31 22:37:03 +02006490 intel_update_watermarks(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02006491 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006492
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006493 domains = intel_crtc->enabled_power_domains;
6494 for_each_power_domain(domain, domains)
Chris Wilson0e6e0be2019-01-14 14:21:24 +00006495 intel_display_power_put_unchecked(dev_priv, domain);
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006496 intel_crtc->enabled_power_domains = 0;
Maarten Lankhorst565602d2015-12-10 12:33:57 +01006497
6498 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
Ville Syrjäläd305e062017-08-30 21:57:03 +03006499 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03006500 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006501}
6502
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006503/*
6504 * turn all crtc's off, but do not adjust state
6505 * This has to be paired with a call to intel_modeset_setup_hw_state.
6506 */
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006507int intel_display_suspend(struct drm_device *dev)
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006508{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006509 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006510 struct drm_atomic_state *state;
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006511 int ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006512
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006513 state = drm_atomic_helper_suspend(dev);
6514 ret = PTR_ERR_OR_ZERO(state);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006515 if (ret)
6516 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006517 else
6518 dev_priv->modeset_restore_state = state;
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006519 return ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006520}
6521
Chris Wilsonea5b2132010-08-04 13:50:23 +01006522void intel_encoder_destroy(struct drm_encoder *encoder)
6523{
Chris Wilson4ef69c72010-09-09 15:14:28 +01006524 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
Chris Wilsonea5b2132010-08-04 13:50:23 +01006525
Chris Wilsonea5b2132010-08-04 13:50:23 +01006526 drm_encoder_cleanup(encoder);
6527 kfree(intel_encoder);
6528}
6529
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006530/* Cross check the actual hw state with our own modeset state tracking (and it's
6531 * internal consistency). */
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006532static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6533 struct drm_connector_state *conn_state)
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006534{
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006535 struct intel_connector *connector = to_intel_connector(conn_state->connector);
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006536
6537 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6538 connector->base.base.id,
6539 connector->base.name);
6540
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006541 if (connector->get_hw_state(connector)) {
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006542 struct intel_encoder *encoder = connector->encoder;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006543
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006544 I915_STATE_WARN(!crtc_state,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006545 "connector enabled without attached crtc\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006546
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006547 if (!crtc_state)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006548 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006549
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006550 I915_STATE_WARN(!crtc_state->active,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006551 "connector is active, but attached crtc isn't\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006552
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006553 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006554 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006555
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006556 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006557 "atomic encoder doesn't match attached encoder\n");
Dave Airlie36cd7442014-05-02 13:44:18 +10006558
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006559 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006560 "attached encoder crtc differs from connector crtc\n");
6561 } else {
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006562 I915_STATE_WARN(crtc_state && crtc_state->active,
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02006563 "attached crtc is active, but connector isn't\n");
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006564 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006565 "best encoder set without crtc!\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006566 }
6567}
6568
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006569static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006570{
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006571 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6572 return crtc_state->fdi_lanes;
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006573
6574 return 0;
6575}
6576
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006577static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006578 struct intel_crtc_state *pipe_config)
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006579{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006580 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006581 struct drm_atomic_state *state = pipe_config->base.state;
6582 struct intel_crtc *other_crtc;
6583 struct intel_crtc_state *other_crtc_state;
6584
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006585 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6586 pipe_name(pipe), pipe_config->fdi_lanes);
6587 if (pipe_config->fdi_lanes > 4) {
6588 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6589 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006590 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006591 }
6592
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006593 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006594 if (pipe_config->fdi_lanes > 2) {
6595 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6596 pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006597 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006598 } else {
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006599 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006600 }
6601 }
6602
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +00006603 if (INTEL_INFO(dev_priv)->num_pipes == 2)
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006604 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006605
6606 /* Ivybridge 3 pipe is really complicated */
6607 switch (pipe) {
6608 case PIPE_A:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006609 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006610 case PIPE_B:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006611 if (pipe_config->fdi_lanes <= 2)
6612 return 0;
6613
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006614 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006615 other_crtc_state =
6616 intel_atomic_get_crtc_state(state, other_crtc);
6617 if (IS_ERR(other_crtc_state))
6618 return PTR_ERR(other_crtc_state);
6619
6620 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006621 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6622 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006623 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006624 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006625 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006626 case PIPE_C:
Ville Syrjälä251cc672015-03-11 18:52:30 +02006627 if (pipe_config->fdi_lanes > 2) {
6628 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6629 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006630 return -EINVAL;
Ville Syrjälä251cc672015-03-11 18:52:30 +02006631 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006632
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006633 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006634 other_crtc_state =
6635 intel_atomic_get_crtc_state(state, other_crtc);
6636 if (IS_ERR(other_crtc_state))
6637 return PTR_ERR(other_crtc_state);
6638
6639 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006640 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006641 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006642 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006643 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006644 default:
6645 BUG();
6646 }
6647}
6648
Daniel Vettere29c22c2013-02-21 00:00:16 +01006649#define RETRY 1
6650static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006651 struct intel_crtc_state *pipe_config)
Daniel Vetter877d48d2013-04-19 11:24:43 +02006652{
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006653 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006654 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006655 int lane, link_bw, fdi_dotclock, ret;
6656 bool needs_recompute = false;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006657
Daniel Vettere29c22c2013-02-21 00:00:16 +01006658retry:
Daniel Vetter877d48d2013-04-19 11:24:43 +02006659 /* FDI is a binary signal running at ~2.7GHz, encoding
6660 * each output octet as 10 bits. The actual frequency
6661 * is stored as a divider into a 100MHz clock, and the
6662 * mode pixel clock is stored in units of 1KHz.
6663 * Hence the bw of each lane in terms of the mode signal
6664 * is:
6665 */
Ville Syrjälä21a727b2016-02-17 21:41:10 +02006666 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006667
Damien Lespiau241bfc32013-09-25 16:45:37 +01006668 fdi_dotclock = adjusted_mode->crtc_clock;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006669
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006670 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
Daniel Vetter877d48d2013-04-19 11:24:43 +02006671 pipe_config->pipe_bpp);
6672
6673 pipe_config->fdi_lanes = lane;
6674
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006675 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006676 link_bw, &pipe_config->fdi_m_n, false);
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006677
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02006678 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +02006679 if (ret == -EDEADLK)
6680 return ret;
6681
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006682 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01006683 pipe_config->pipe_bpp -= 2*3;
6684 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6685 pipe_config->pipe_bpp);
6686 needs_recompute = true;
6687 pipe_config->bw_constrained = true;
6688
6689 goto retry;
6690 }
6691
6692 if (needs_recompute)
6693 return RETRY;
6694
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006695 return ret;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006696}
6697
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006698bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006699{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006700 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6701 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6702
6703 /* IPS only exists on ULT machines and is tied to pipe A. */
6704 if (!hsw_crtc_supports_ips(crtc))
Ville Syrjälä6e644622017-08-17 17:55:09 +03006705 return false;
6706
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006707 if (!i915_modparams.enable_ips)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006708 return false;
6709
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006710 if (crtc_state->pipe_bpp > 24)
6711 return false;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006712
6713 /*
Ville Syrjäläb432e5c2015-06-03 15:45:13 +03006714 * We compare against max which means we must take
6715 * the increased cdclk requirement into account when
6716 * calculating the new cdclk.
6717 *
6718 * Should measure whether using a lower cdclk w/o IPS
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006719 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006720 if (IS_BROADWELL(dev_priv) &&
6721 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6722 return false;
6723
6724 return true;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006725}
6726
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006727static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006728{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006729 struct drm_i915_private *dev_priv =
6730 to_i915(crtc_state->base.crtc->dev);
6731 struct intel_atomic_state *intel_state =
6732 to_intel_atomic_state(crtc_state->base.state);
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006733
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006734 if (!hsw_crtc_state_ips_capable(crtc_state))
6735 return false;
6736
6737 if (crtc_state->ips_force_disable)
6738 return false;
6739
Maarten Lankhorstadbe5c52017-11-22 19:39:06 +01006740 /* IPS should be fine as long as at least one plane is enabled. */
6741 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006742 return false;
6743
6744 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6745 if (IS_BROADWELL(dev_priv) &&
6746 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6747 return false;
6748
6749 return true;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006750}
6751
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006752static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6753{
6754 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6755
6756 /* GDG double wide on either pipe, otherwise pipe A only */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00006757 return INTEL_GEN(dev_priv) < 4 &&
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006758 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6759}
6760
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006761static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
Ville Syrjäläceb99322017-01-20 20:22:05 +02006762{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006763 u32 pixel_rate;
Ville Syrjäläceb99322017-01-20 20:22:05 +02006764
6765 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6766
6767 /*
6768 * We only use IF-ID interlacing. If we ever use
6769 * PF-ID we'll need to adjust the pixel_rate here.
6770 */
6771
6772 if (pipe_config->pch_pfit.enabled) {
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006773 u64 pipe_w, pipe_h, pfit_w, pfit_h;
6774 u32 pfit_size = pipe_config->pch_pfit.size;
Ville Syrjäläceb99322017-01-20 20:22:05 +02006775
6776 pipe_w = pipe_config->pipe_src_w;
6777 pipe_h = pipe_config->pipe_src_h;
6778
6779 pfit_w = (pfit_size >> 16) & 0xFFFF;
6780 pfit_h = pfit_size & 0xFFFF;
6781 if (pipe_w < pfit_w)
6782 pipe_w = pfit_w;
6783 if (pipe_h < pfit_h)
6784 pipe_h = pfit_h;
6785
6786 if (WARN_ON(!pfit_w || !pfit_h))
6787 return pixel_rate;
6788
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006789 pixel_rate = div_u64((u64)pixel_rate * pipe_w * pipe_h,
Ville Syrjäläceb99322017-01-20 20:22:05 +02006790 pfit_w * pfit_h);
6791 }
6792
6793 return pixel_rate;
6794}
6795
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006796static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6797{
6798 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6799
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08006800 if (HAS_GMCH(dev_priv))
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006801 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6802 crtc_state->pixel_rate =
6803 crtc_state->base.adjusted_mode.crtc_clock;
6804 else
6805 crtc_state->pixel_rate =
6806 ilk_pipe_pixel_rate(crtc_state);
6807}
6808
Daniel Vettera43f6e02013-06-07 23:10:32 +02006809static int intel_crtc_compute_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006810 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -08006811{
Daniel Vettera43f6e02013-06-07 23:10:32 +02006812 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006813 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006814 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläf3261152016-05-24 21:34:18 +03006815 int clock_limit = dev_priv->max_dotclk_freq;
Chris Wilson89749352010-09-12 18:25:19 +01006816
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006817 if (INTEL_GEN(dev_priv) < 4) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006818 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006819
6820 /*
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006821 * Enable double wide mode when the dot clock
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006822 * is > 90% of the (display) core speed.
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006823 */
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006824 if (intel_crtc_supports_double_wide(crtc) &&
6825 adjusted_mode->crtc_clock > clock_limit) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006826 clock_limit = dev_priv->max_dotclk_freq;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006827 pipe_config->double_wide = true;
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006828 }
Ville Syrjäläf3261152016-05-24 21:34:18 +03006829 }
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006830
Ville Syrjäläf3261152016-05-24 21:34:18 +03006831 if (adjusted_mode->crtc_clock > clock_limit) {
6832 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6833 adjusted_mode->crtc_clock, clock_limit,
6834 yesno(pipe_config->double_wide));
6835 return -EINVAL;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006836 }
Chris Wilson89749352010-09-12 18:25:19 +01006837
Shashank Sharma8c79f842018-10-12 11:53:09 +05306838 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6839 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6840 pipe_config->base.ctm) {
Shashank Sharma25edf912017-07-21 20:55:07 +05306841 /*
6842 * There is only one pipe CSC unit per pipe, and we need that
6843 * for output conversion from RGB->YCBCR. So if CTM is already
6844 * applied we can't support YCBCR420 output.
6845 */
6846 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6847 return -EINVAL;
6848 }
6849
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006850 /*
6851 * Pipe horizontal size must be even in:
6852 * - DVO ganged mode
6853 * - LVDS dual channel mode
6854 * - Double wide pipe
6855 */
Ville Syrjälä0574bd82017-11-23 21:04:48 +02006856 if (pipe_config->pipe_src_w & 1) {
6857 if (pipe_config->double_wide) {
6858 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6859 return -EINVAL;
6860 }
6861
6862 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6863 intel_is_dual_link_lvds(dev)) {
6864 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6865 return -EINVAL;
6866 }
6867 }
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006868
Damien Lespiau8693a822013-05-03 18:48:11 +01006869 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6870 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
Chris Wilson44f46b422012-06-21 13:19:59 +03006871 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01006872 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
Ville Syrjäläaad941d2015-09-25 16:38:56 +03006873 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
Daniel Vettere29c22c2013-02-21 00:00:16 +01006874 return -EINVAL;
Chris Wilson44f46b422012-06-21 13:19:59 +03006875
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006876 intel_crtc_compute_pixel_rate(pipe_config);
6877
Daniel Vetter877d48d2013-04-19 11:24:43 +02006878 if (pipe_config->has_pch_encoder)
Daniel Vettera43f6e02013-06-07 23:10:32 +02006879 return ironlake_fdi_compute_config(crtc, pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006880
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +02006881 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08006882}
6883
Zhenyu Wang2c072452009-06-05 15:38:42 +08006884static void
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006885intel_reduce_m_n_ratio(u32 *num, u32 *den)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006886{
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006887 while (*num > DATA_LINK_M_N_MASK ||
6888 *den > DATA_LINK_M_N_MASK) {
Zhenyu Wang2c072452009-06-05 15:38:42 +08006889 *num >>= 1;
6890 *den >>= 1;
6891 }
6892}
6893
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006894static void compute_m_n(unsigned int m, unsigned int n,
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006895 u32 *ret_m, u32 *ret_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006896 bool constant_n)
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006897{
Jani Nikula9a86cda2017-03-27 14:33:25 +03006898 /*
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006899 * Several DP dongles in particular seem to be fussy about
6900 * too large link M/N values. Give N value as 0x8000 that
6901 * should be acceptable by specific devices. 0x8000 is the
6902 * specified fixed N value for asynchronous clock mode,
6903 * which the devices expect also in synchronous clock mode.
Jani Nikula9a86cda2017-03-27 14:33:25 +03006904 */
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006905 if (constant_n)
6906 *ret_n = 0x8000;
6907 else
6908 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
Jani Nikula9a86cda2017-03-27 14:33:25 +03006909
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006910 *ret_m = div_u64((u64)m * *ret_n, n);
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006911 intel_reduce_m_n_ratio(ret_m, ret_n);
6912}
6913
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006914void
Manasi Navarea4a15772018-11-28 13:36:21 -08006915intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006916 int pixel_clock, int link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006917 struct intel_link_m_n *m_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006918 bool constant_n)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006919{
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006920 m_n->tu = 64;
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006921
6922 compute_m_n(bits_per_pixel * pixel_clock,
6923 link_clock * nlanes * 8,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006924 &m_n->gmch_m, &m_n->gmch_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006925 constant_n);
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006926
6927 compute_m_n(pixel_clock, link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006928 &m_n->link_m, &m_n->link_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006929 constant_n);
Zhenyu Wang2c072452009-06-05 15:38:42 +08006930}
6931
Chris Wilsona7615032011-01-12 17:04:08 +00006932static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6933{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00006934 if (i915_modparams.panel_use_ssc >= 0)
6935 return i915_modparams.panel_use_ssc != 0;
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03006936 return dev_priv->vbt.lvds_use_ssc
Keith Packard435793d2011-07-12 14:56:22 -07006937 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
Chris Wilsona7615032011-01-12 17:04:08 +00006938}
6939
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006940static u32 pnv_dpll_compute_fp(struct dpll *dpll)
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006941{
Daniel Vetter7df00d72013-05-21 21:54:55 +02006942 return (1 << dpll->n) << 16 | dpll->m2;
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006943}
Daniel Vetterf47709a2013-03-28 10:42:02 +01006944
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006945static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006946{
6947 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006948}
6949
Daniel Vetterf47709a2013-03-28 10:42:02 +01006950static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006951 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03006952 struct dpll *reduced_clock)
Jesse Barnesa7516a02011-12-15 12:30:37 -08006953{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006954 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006955 u32 fp, fp2 = 0;
6956
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006957 if (IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006958 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006959 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006960 fp2 = pnv_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006961 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006962 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006963 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006964 fp2 = i9xx_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006965 }
6966
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006967 crtc_state->dpll_hw_state.fp0 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006968
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03006969 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Rodrigo Viviab585de2015-03-24 12:40:09 -07006970 reduced_clock) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006971 crtc_state->dpll_hw_state.fp1 = fp2;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006972 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006973 crtc_state->dpll_hw_state.fp1 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006974 }
6975}
6976
Chon Ming Lee5e69f972013-09-05 20:41:49 +08006977static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6978 pipe)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006979{
6980 u32 reg_val;
6981
6982 /*
6983 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6984 * and set it to a reasonable value instead.
6985 */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006986 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006987 reg_val &= 0xffffff00;
6988 reg_val |= 0x00000030;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006989 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006990
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006991 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Imre Deaked585702017-05-10 12:21:47 +03006992 reg_val &= 0x00ffffff;
6993 reg_val |= 0x8c000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006994 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006995
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006996 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006997 reg_val &= 0xffffff00;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006998 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006999
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007000 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007001 reg_val &= 0x00ffffff;
7002 reg_val |= 0xb0000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007003 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007004}
7005
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007006static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7007 const struct intel_link_m_n *m_n)
Daniel Vetterb5518422013-05-03 11:49:48 +02007008{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007009 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7010 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7011 enum pipe pipe = crtc->pipe;
Daniel Vetterb5518422013-05-03 11:49:48 +02007012
Daniel Vettere3b95f12013-05-03 11:49:49 +02007013 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7014 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7015 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7016 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02007017}
7018
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02007019static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7020 enum transcoder transcoder)
7021{
7022 if (IS_HASWELL(dev_priv))
7023 return transcoder == TRANSCODER_EDP;
7024
7025 /*
7026 * Strictly speaking some registers are available before
7027 * gen7, but we only support DRRS on gen7+
7028 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007029 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02007030}
7031
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007032static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7033 const struct intel_link_m_n *m_n,
7034 const struct intel_link_m_n *m2_n2)
Daniel Vetterb5518422013-05-03 11:49:48 +02007035{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007036 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007037 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007038 enum pipe pipe = crtc->pipe;
7039 enum transcoder transcoder = crtc_state->cpu_transcoder;
Daniel Vetterb5518422013-05-03 11:49:48 +02007040
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007041 if (INTEL_GEN(dev_priv) >= 5) {
Daniel Vetterb5518422013-05-03 11:49:48 +02007042 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7043 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7044 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7045 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02007046 /*
7047 * M2_N2 registers are set only if DRRS is supported
7048 * (to make sure the registers are not unnecessarily accessed).
Vandana Kannanf769cd22014-08-05 07:51:22 -07007049 */
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02007050 if (m2_n2 && crtc_state->has_drrs &&
7051 transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07007052 I915_WRITE(PIPE_DATA_M2(transcoder),
7053 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7054 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7055 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7056 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7057 }
Daniel Vetterb5518422013-05-03 11:49:48 +02007058 } else {
Daniel Vettere3b95f12013-05-03 11:49:49 +02007059 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7060 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7061 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7062 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02007063 }
7064}
7065
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007066void 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 +02007067{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007068 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05307069
7070 if (m_n == M1_N1) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007071 dp_m_n = &crtc_state->dp_m_n;
7072 dp_m2_n2 = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05307073 } else if (m_n == M2_N2) {
7074
7075 /*
7076 * M2_N2 registers are not supported. Hence m2_n2 divider value
7077 * needs to be programmed into M1_N1.
7078 */
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007079 dp_m_n = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05307080 } else {
7081 DRM_ERROR("Unsupported divider value\n");
7082 return;
7083 }
7084
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007085 if (crtc_state->has_pch_encoder)
7086 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02007087 else
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007088 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02007089}
7090
Daniel Vetter251ac862015-06-18 10:30:24 +02007091static void vlv_compute_dpll(struct intel_crtc *crtc,
7092 struct intel_crtc_state *pipe_config)
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007093{
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007094 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007095 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007096 if (crtc->pipe != PIPE_A)
7097 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007098
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007099 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03007100 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007101 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7102 DPLL_EXT_BUFFER_ENABLE_VLV;
7103
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007104 pipe_config->dpll_hw_state.dpll_md =
7105 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7106}
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007107
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007108static void chv_compute_dpll(struct intel_crtc *crtc,
7109 struct intel_crtc_state *pipe_config)
7110{
7111 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007112 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007113 if (crtc->pipe != PIPE_A)
7114 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7115
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007116 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03007117 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007118 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
7119
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007120 pipe_config->dpll_hw_state.dpll_md =
7121 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007122}
7123
Ville Syrjäläd288f652014-10-28 13:20:22 +02007124static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007125 const struct intel_crtc_state *pipe_config)
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007126{
Daniel Vetterf47709a2013-03-28 10:42:02 +01007127 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007128 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007129 enum pipe pipe = crtc->pipe;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007130 u32 mdiv;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007131 u32 bestn, bestm1, bestm2, bestp1, bestp2;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007132 u32 coreclk, reg_val;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007133
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007134 /* Enable Refclk */
7135 I915_WRITE(DPLL(pipe),
7136 pipe_config->dpll_hw_state.dpll &
7137 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7138
7139 /* No need to actually set up the DPLL with DSI */
7140 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7141 return;
7142
Ville Syrjäläa5805162015-05-26 20:42:30 +03007143 mutex_lock(&dev_priv->sb_lock);
Daniel Vetter09153002012-12-12 14:06:44 +01007144
Ville Syrjäläd288f652014-10-28 13:20:22 +02007145 bestn = pipe_config->dpll.n;
7146 bestm1 = pipe_config->dpll.m1;
7147 bestm2 = pipe_config->dpll.m2;
7148 bestp1 = pipe_config->dpll.p1;
7149 bestp2 = pipe_config->dpll.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007150
Jesse Barnes89b667f2013-04-18 14:51:36 -07007151 /* See eDP HDMI DPIO driver vbios notes doc */
7152
7153 /* PLL B needs special handling */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007154 if (pipe == PIPE_B)
Chon Ming Lee5e69f972013-09-05 20:41:49 +08007155 vlv_pllb_recal_opamp(dev_priv, pipe);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007156
7157 /* Set up Tx target for periodic Rcomp update */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007158 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007159
7160 /* Disable target IRef on PLL */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007161 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007162 reg_val &= 0x00ffffff;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007163 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007164
7165 /* Disable fast lock */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007166 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007167
7168 /* Set idtafcrecal before PLL is enabled */
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007169 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7170 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7171 mdiv |= ((bestn << DPIO_N_SHIFT));
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007172 mdiv |= (1 << DPIO_K_SHIFT);
Jesse Barnes7df50802013-05-02 10:48:09 -07007173
7174 /*
7175 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7176 * but we don't support that).
7177 * Note: don't use the DAC post divider as it seems unstable.
7178 */
7179 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007180 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007181
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007182 mdiv |= DPIO_ENABLE_CALIBRATION;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007183 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007184
Jesse Barnes89b667f2013-04-18 14:51:36 -07007185 /* Set HBR and RBR LPF coefficients */
Ville Syrjäläd288f652014-10-28 13:20:22 +02007186 if (pipe_config->port_clock == 162000 ||
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007187 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7188 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007189 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Ville Syrjälä885b01202013-07-05 19:21:38 +03007190 0x009f0003);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007191 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007192 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007193 0x00d0000f);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007194
Ville Syrjälä37a56502016-06-22 21:57:04 +03007195 if (intel_crtc_has_dp_encoder(pipe_config)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07007196 /* Use SSC source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007197 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007198 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007199 0x0df40000);
7200 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007201 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007202 0x0df70000);
7203 } else { /* HDMI or VGA */
7204 /* Use bend source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007205 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007206 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007207 0x0df70000);
7208 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007209 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007210 0x0df40000);
7211 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007212
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007213 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007214 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007215 if (intel_crtc_has_dp_encoder(pipe_config))
Jesse Barnes89b667f2013-04-18 14:51:36 -07007216 coreclk |= 0x01000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007217 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007218
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007219 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
Ville Syrjäläa5805162015-05-26 20:42:30 +03007220 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007221}
7222
Ville Syrjäläd288f652014-10-28 13:20:22 +02007223static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007224 const struct intel_crtc_state *pipe_config)
Ville Syrjälä1ae0d132014-06-28 02:04:00 +03007225{
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007226 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007227 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007228 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007229 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307230 u32 loopfilter, tribuf_calcntr;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007231 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307232 u32 dpio_val;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307233 int vco;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007234
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007235 /* Enable Refclk and SSC */
7236 I915_WRITE(DPLL(pipe),
7237 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7238
7239 /* No need to actually set up the DPLL with DSI */
7240 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7241 return;
7242
Ville Syrjäläd288f652014-10-28 13:20:22 +02007243 bestn = pipe_config->dpll.n;
7244 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7245 bestm1 = pipe_config->dpll.m1;
7246 bestm2 = pipe_config->dpll.m2 >> 22;
7247 bestp1 = pipe_config->dpll.p1;
7248 bestp2 = pipe_config->dpll.p2;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307249 vco = pipe_config->dpll.vco;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307250 dpio_val = 0;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307251 loopfilter = 0;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007252
Ville Syrjäläa5805162015-05-26 20:42:30 +03007253 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007254
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007255 /* p1 and p2 divider */
7256 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7257 5 << DPIO_CHV_S1_DIV_SHIFT |
7258 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7259 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7260 1 << DPIO_CHV_K_DIV_SHIFT);
7261
7262 /* Feedback post-divider - m2 */
7263 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7264
7265 /* Feedback refclk divider - n and m1 */
7266 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7267 DPIO_CHV_M1_DIV_BY_2 |
7268 1 << DPIO_CHV_N_DIV_SHIFT);
7269
7270 /* M2 fraction division */
Ville Syrjälä25a25df2015-07-08 23:45:47 +03007271 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007272
7273 /* M2 fraction division enable */
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307274 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7275 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7276 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7277 if (bestm2_frac)
7278 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7279 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007280
Vijay Purushothamande3a0fd2015-03-05 19:32:06 +05307281 /* Program digital lock detect threshold */
7282 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7283 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7284 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7285 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7286 if (!bestm2_frac)
7287 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7288 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7289
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007290 /* Loop filter */
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307291 if (vco == 5400000) {
7292 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7293 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7294 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7295 tribuf_calcntr = 0x9;
7296 } else if (vco <= 6200000) {
7297 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7298 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7299 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7300 tribuf_calcntr = 0x9;
7301 } else if (vco <= 6480000) {
7302 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7303 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7304 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7305 tribuf_calcntr = 0x8;
7306 } else {
7307 /* Not supported. Apply the same limits as in the max case */
7308 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7309 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7310 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7311 tribuf_calcntr = 0;
7312 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007313 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7314
Ville Syrjälä968040b2015-03-11 22:52:08 +02007315 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307316 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7317 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7318 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7319
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007320 /* AFC Recal */
7321 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7322 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7323 DPIO_AFC_RECAL);
7324
Ville Syrjäläa5805162015-05-26 20:42:30 +03007325 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007326}
7327
Ville Syrjäläd288f652014-10-28 13:20:22 +02007328/**
7329 * vlv_force_pll_on - forcibly enable just the PLL
7330 * @dev_priv: i915 private structure
7331 * @pipe: pipe PLL to enable
7332 * @dpll: PLL configuration
7333 *
7334 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7335 * in cases where we need the PLL enabled even when @pipe is not going to
7336 * be enabled.
7337 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007338int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007339 const struct dpll *dpll)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007340{
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02007341 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007342 struct intel_crtc_state *pipe_config;
7343
7344 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7345 if (!pipe_config)
7346 return -ENOMEM;
7347
7348 pipe_config->base.crtc = &crtc->base;
7349 pipe_config->pixel_multiplier = 1;
7350 pipe_config->dpll = *dpll;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007351
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007352 if (IS_CHERRYVIEW(dev_priv)) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007353 chv_compute_dpll(crtc, pipe_config);
7354 chv_prepare_pll(crtc, pipe_config);
7355 chv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007356 } else {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007357 vlv_compute_dpll(crtc, pipe_config);
7358 vlv_prepare_pll(crtc, pipe_config);
7359 vlv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007360 }
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007361
7362 kfree(pipe_config);
7363
7364 return 0;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007365}
7366
7367/**
7368 * vlv_force_pll_off - forcibly disable just the PLL
7369 * @dev_priv: i915 private structure
7370 * @pipe: pipe PLL to disable
7371 *
7372 * Disable the PLL for @pipe. To be used in cases where we need
7373 * the PLL enabled even when @pipe is not going to be enabled.
7374 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007375void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007376{
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007377 if (IS_CHERRYVIEW(dev_priv))
7378 chv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007379 else
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007380 vlv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007381}
7382
Daniel Vetter251ac862015-06-18 10:30:24 +02007383static void i9xx_compute_dpll(struct intel_crtc *crtc,
7384 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007385 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007386{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007387 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007388 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007389 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007390
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007391 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307392
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007393 dpll = DPLL_VGA_MODE_DIS;
7394
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007395 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007396 dpll |= DPLLB_MODE_LVDS;
7397 else
7398 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter6cc5f342013-03-27 00:44:53 +01007399
Jani Nikula73f67aa2016-12-07 22:48:09 +02007400 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7401 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007402 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetter198a037f2013-04-19 11:14:37 +02007403 << SDVO_MULTIPLIER_SHIFT_HIRES;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007404 }
Daniel Vetter198a037f2013-04-19 11:14:37 +02007405
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03007406 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7407 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007408 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vetter198a037f2013-04-19 11:14:37 +02007409
Ville Syrjälä37a56502016-06-22 21:57:04 +03007410 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007411 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007412
7413 /* compute bitmask from p1 value */
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007414 if (IS_PINEVIEW(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007415 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7416 else {
7417 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007418 if (IS_G4X(dev_priv) && reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007419 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7420 }
7421 switch (clock->p2) {
7422 case 5:
7423 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7424 break;
7425 case 7:
7426 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7427 break;
7428 case 10:
7429 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7430 break;
7431 case 14:
7432 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7433 break;
7434 }
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007435 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007436 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7437
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007438 if (crtc_state->sdvo_tv_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007439 dpll |= PLL_REF_INPUT_TVCLKINBC;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007440 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007441 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007442 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7443 else
7444 dpll |= PLL_REF_INPUT_DREFCLK;
7445
7446 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007447 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007448
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007449 if (INTEL_GEN(dev_priv) >= 4) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007450 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02007451 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007452 crtc_state->dpll_hw_state.dpll_md = dpll_md;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007453 }
7454}
7455
Daniel Vetter251ac862015-06-18 10:30:24 +02007456static void i8xx_compute_dpll(struct intel_crtc *crtc,
7457 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007458 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007459{
Daniel Vetterf47709a2013-03-28 10:42:02 +01007460 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007461 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007462 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007463 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007464
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007465 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307466
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007467 dpll = DPLL_VGA_MODE_DIS;
7468
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007469 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007470 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7471 } else {
7472 if (clock->p1 == 2)
7473 dpll |= PLL_P1_DIVIDE_BY_TWO;
7474 else
7475 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7476 if (clock->p2 == 4)
7477 dpll |= PLL_P2_DIVIDE_BY_4;
7478 }
7479
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007480 if (!IS_I830(dev_priv) &&
7481 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007482 dpll |= DPLL_DVO_2X_MODE;
7483
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007484 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007485 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007486 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7487 else
7488 dpll |= PLL_REF_INPUT_DREFCLK;
7489
7490 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007491 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007492}
7493
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007494static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007495{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007496 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7497 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7498 enum pipe pipe = crtc->pipe;
7499 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7500 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007501 u32 crtc_vtotal, crtc_vblank_end;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007502 int vsyncshift = 0;
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007503
7504 /* We need to be careful not to changed the adjusted mode, for otherwise
7505 * the hw state checker will get angry at the mismatch. */
7506 crtc_vtotal = adjusted_mode->crtc_vtotal;
7507 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007508
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007509 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007510 /* the chip adds 2 halflines automatically */
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007511 crtc_vtotal -= 1;
7512 crtc_vblank_end -= 1;
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007513
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007514 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007515 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7516 else
7517 vsyncshift = adjusted_mode->crtc_hsync_start -
7518 adjusted_mode->crtc_htotal / 2;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007519 if (vsyncshift < 0)
7520 vsyncshift += adjusted_mode->crtc_htotal;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007521 }
7522
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007523 if (INTEL_GEN(dev_priv) > 3)
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007524 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007525
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007526 I915_WRITE(HTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007527 (adjusted_mode->crtc_hdisplay - 1) |
7528 ((adjusted_mode->crtc_htotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007529 I915_WRITE(HBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007530 (adjusted_mode->crtc_hblank_start - 1) |
7531 ((adjusted_mode->crtc_hblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007532 I915_WRITE(HSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007533 (adjusted_mode->crtc_hsync_start - 1) |
7534 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7535
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007536 I915_WRITE(VTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007537 (adjusted_mode->crtc_vdisplay - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007538 ((crtc_vtotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007539 I915_WRITE(VBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007540 (adjusted_mode->crtc_vblank_start - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007541 ((crtc_vblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007542 I915_WRITE(VSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007543 (adjusted_mode->crtc_vsync_start - 1) |
7544 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7545
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007546 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7547 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7548 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7549 * bits. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01007550 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007551 (pipe == PIPE_B || pipe == PIPE_C))
7552 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7553
Jani Nikulabc58be62016-03-18 17:05:39 +02007554}
7555
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007556static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
Jani Nikulabc58be62016-03-18 17:05:39 +02007557{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007558 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7559 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7560 enum pipe pipe = crtc->pipe;
Jani Nikulabc58be62016-03-18 17:05:39 +02007561
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007562 /* pipesrc controls the size that is scaled from, which should
7563 * always be the user's requested size.
7564 */
7565 I915_WRITE(PIPESRC(pipe),
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007566 ((crtc_state->pipe_src_w - 1) << 16) |
7567 (crtc_state->pipe_src_h - 1));
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007568}
7569
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007570static void intel_get_pipe_timings(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007571 struct intel_crtc_state *pipe_config)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007572{
7573 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007574 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007575 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007576 u32 tmp;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007577
7578 tmp = I915_READ(HTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007579 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7580 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007581 tmp = I915_READ(HBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007582 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7583 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007584 tmp = I915_READ(HSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007585 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7586 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007587
7588 tmp = I915_READ(VTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007589 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7590 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007591 tmp = I915_READ(VBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007592 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7593 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007594 tmp = I915_READ(VSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007595 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7596 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007597
7598 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007599 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7600 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7601 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007602 }
Jani Nikulabc58be62016-03-18 17:05:39 +02007603}
7604
7605static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7606 struct intel_crtc_state *pipe_config)
7607{
7608 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007609 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulabc58be62016-03-18 17:05:39 +02007610 u32 tmp;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007611
7612 tmp = I915_READ(PIPESRC(crtc->pipe));
Ville Syrjälä37327ab2013-09-04 18:25:28 +03007613 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7614 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7615
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007616 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7617 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007618}
7619
Daniel Vetterf6a83282014-02-11 15:28:57 -08007620void intel_mode_from_pipe_config(struct drm_display_mode *mode,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007621 struct intel_crtc_state *pipe_config)
Jesse Barnesbabea612013-06-26 18:57:38 +03007622{
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007623 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7624 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7625 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7626 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007627
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007628 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7629 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7630 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7631 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007632
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007633 mode->flags = pipe_config->base.adjusted_mode.flags;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007634 mode->type = DRM_MODE_TYPE_DRIVER;
Jesse Barnesbabea612013-06-26 18:57:38 +03007635
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007636 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007637
7638 mode->hsync = drm_mode_hsync(mode);
7639 mode->vrefresh = drm_mode_vrefresh(mode);
7640 drm_mode_set_name(mode);
Jesse Barnesbabea612013-06-26 18:57:38 +03007641}
7642
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007643static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
Daniel Vetter84b046f2013-02-19 18:48:54 +01007644{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007645 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7646 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007647 u32 pipeconf;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007648
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007649 pipeconf = 0;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007650
Ville Syrjäläe56134b2017-06-01 17:36:19 +03007651 /* we keep both pipes enabled on 830 */
7652 if (IS_I830(dev_priv))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007653 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
Daniel Vetter67c72a12013-09-24 11:46:14 +02007654
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007655 if (crtc_state->double_wide)
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03007656 pipeconf |= PIPECONF_DOUBLE_WIDE;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007657
Daniel Vetterff9ce462013-04-24 14:57:17 +02007658 /* only g4x and later have fancy bpc/dither controls */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007659 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7660 IS_CHERRYVIEW(dev_priv)) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007661 /* Bspec claims that we can't use dithering for 30bpp pipes. */
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007662 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
Daniel Vetterff9ce462013-04-24 14:57:17 +02007663 pipeconf |= PIPECONF_DITHER_EN |
7664 PIPECONF_DITHER_TYPE_SP;
7665
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007666 switch (crtc_state->pipe_bpp) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007667 case 18:
7668 pipeconf |= PIPECONF_6BPC;
7669 break;
7670 case 24:
7671 pipeconf |= PIPECONF_8BPC;
7672 break;
7673 case 30:
7674 pipeconf |= PIPECONF_10BPC;
7675 break;
7676 default:
7677 /* Case prevented by intel_choose_pipe_bpp_dither. */
7678 BUG();
Daniel Vetter84b046f2013-02-19 18:48:54 +01007679 }
7680 }
7681
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007682 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007683 if (INTEL_GEN(dev_priv) < 4 ||
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007684 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjäläefc2cff2014-03-28 23:29:31 +02007685 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7686 else
7687 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7688 } else
Daniel Vetter84b046f2013-02-19 18:48:54 +01007689 pipeconf |= PIPECONF_PROGRESSIVE;
7690
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007691 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007692 crtc_state->limited_color_range)
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007693 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä9c8e09b2013-04-02 16:10:09 +03007694
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007695 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7696 POSTING_READ(PIPECONF(crtc->pipe));
Daniel Vetter84b046f2013-02-19 18:48:54 +01007697}
7698
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007699static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7700 struct intel_crtc_state *crtc_state)
7701{
7702 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007703 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007704 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007705 int refclk = 48000;
7706
7707 memset(&crtc_state->dpll_hw_state, 0,
7708 sizeof(crtc_state->dpll_hw_state));
7709
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007710 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007711 if (intel_panel_use_ssc(dev_priv)) {
7712 refclk = dev_priv->vbt.lvds_ssc_freq;
7713 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7714 }
7715
7716 limit = &intel_limits_i8xx_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007717 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007718 limit = &intel_limits_i8xx_dvo;
7719 } else {
7720 limit = &intel_limits_i8xx_dac;
7721 }
7722
7723 if (!crtc_state->clock_set &&
7724 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7725 refclk, NULL, &crtc_state->dpll)) {
7726 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7727 return -EINVAL;
7728 }
7729
7730 i8xx_compute_dpll(crtc, crtc_state, NULL);
7731
7732 return 0;
7733}
7734
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007735static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7736 struct intel_crtc_state *crtc_state)
7737{
7738 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007739 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007740 const struct intel_limit *limit;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007741 int refclk = 96000;
7742
7743 memset(&crtc_state->dpll_hw_state, 0,
7744 sizeof(crtc_state->dpll_hw_state));
7745
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007746 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007747 if (intel_panel_use_ssc(dev_priv)) {
7748 refclk = dev_priv->vbt.lvds_ssc_freq;
7749 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7750 }
7751
7752 if (intel_is_dual_link_lvds(dev))
7753 limit = &intel_limits_g4x_dual_channel_lvds;
7754 else
7755 limit = &intel_limits_g4x_single_channel_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007756 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7757 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007758 limit = &intel_limits_g4x_hdmi;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007759 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007760 limit = &intel_limits_g4x_sdvo;
7761 } else {
7762 /* The option is for other outputs */
7763 limit = &intel_limits_i9xx_sdvo;
7764 }
7765
7766 if (!crtc_state->clock_set &&
7767 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7768 refclk, NULL, &crtc_state->dpll)) {
7769 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7770 return -EINVAL;
7771 }
7772
7773 i9xx_compute_dpll(crtc, crtc_state, NULL);
7774
7775 return 0;
7776}
7777
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007778static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7779 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08007780{
Ander Conselvan de Oliveirac7653192014-10-20 13:46:44 +03007781 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007782 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007783 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007784 int refclk = 96000;
Jesse Barnes79e53942008-11-07 14:24:08 -08007785
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03007786 memset(&crtc_state->dpll_hw_state, 0,
7787 sizeof(crtc_state->dpll_hw_state));
7788
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007789 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007790 if (intel_panel_use_ssc(dev_priv)) {
7791 refclk = dev_priv->vbt.lvds_ssc_freq;
7792 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7793 }
Jesse Barnes79e53942008-11-07 14:24:08 -08007794
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007795 limit = &intel_limits_pineview_lvds;
7796 } else {
7797 limit = &intel_limits_pineview_sdvo;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007798 }
Jani Nikulaf2335332013-09-13 11:03:09 +03007799
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007800 if (!crtc_state->clock_set &&
7801 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7802 refclk, NULL, &crtc_state->dpll)) {
7803 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7804 return -EINVAL;
7805 }
7806
7807 i9xx_compute_dpll(crtc, crtc_state, NULL);
7808
7809 return 0;
7810}
7811
7812static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7813 struct intel_crtc_state *crtc_state)
7814{
7815 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007816 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007817 const struct intel_limit *limit;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007818 int refclk = 96000;
7819
7820 memset(&crtc_state->dpll_hw_state, 0,
7821 sizeof(crtc_state->dpll_hw_state));
7822
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007823 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007824 if (intel_panel_use_ssc(dev_priv)) {
7825 refclk = dev_priv->vbt.lvds_ssc_freq;
7826 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
Jani Nikulae9fd1c02013-08-27 15:12:23 +03007827 }
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007828
7829 limit = &intel_limits_i9xx_lvds;
7830 } else {
7831 limit = &intel_limits_i9xx_sdvo;
7832 }
7833
7834 if (!crtc_state->clock_set &&
7835 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7836 refclk, NULL, &crtc_state->dpll)) {
7837 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7838 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01007839 }
Eric Anholtf564048e2011-03-30 13:01:02 -07007840
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007841 i9xx_compute_dpll(crtc, crtc_state, NULL);
Eric Anholtf564048e2011-03-30 13:01:02 -07007842
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02007843 return 0;
Eric Anholtf564048e2011-03-30 13:01:02 -07007844}
7845
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007846static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7847 struct intel_crtc_state *crtc_state)
7848{
7849 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007850 const struct intel_limit *limit = &intel_limits_chv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007851
7852 memset(&crtc_state->dpll_hw_state, 0,
7853 sizeof(crtc_state->dpll_hw_state));
7854
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007855 if (!crtc_state->clock_set &&
7856 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7857 refclk, NULL, &crtc_state->dpll)) {
7858 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7859 return -EINVAL;
7860 }
7861
7862 chv_compute_dpll(crtc, crtc_state);
7863
7864 return 0;
7865}
7866
7867static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7868 struct intel_crtc_state *crtc_state)
7869{
7870 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007871 const struct intel_limit *limit = &intel_limits_vlv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007872
7873 memset(&crtc_state->dpll_hw_state, 0,
7874 sizeof(crtc_state->dpll_hw_state));
7875
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007876 if (!crtc_state->clock_set &&
7877 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7878 refclk, NULL, &crtc_state->dpll)) {
7879 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7880 return -EINVAL;
7881 }
7882
7883 vlv_compute_dpll(crtc, crtc_state);
7884
7885 return 0;
7886}
7887
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007888static void i9xx_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007889 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007890{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007891 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007892 u32 tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007893
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007894 if (INTEL_GEN(dev_priv) <= 3 &&
7895 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
Ville Syrjälädc9e7dec2014-01-10 14:06:45 +02007896 return;
7897
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007898 tmp = I915_READ(PFIT_CONTROL);
Daniel Vetter06922822013-07-11 13:35:40 +02007899 if (!(tmp & PFIT_ENABLE))
7900 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007901
Daniel Vetter06922822013-07-11 13:35:40 +02007902 /* Check whether the pfit is attached to our pipe. */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007903 if (INTEL_GEN(dev_priv) < 4) {
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007904 if (crtc->pipe != PIPE_B)
7905 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007906 } else {
7907 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7908 return;
7909 }
7910
Daniel Vetter06922822013-07-11 13:35:40 +02007911 pipe_config->gmch_pfit.control = tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007912 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007913}
7914
Jesse Barnesacbec812013-09-20 11:29:32 -07007915static void vlv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007916 struct intel_crtc_state *pipe_config)
Jesse Barnesacbec812013-09-20 11:29:32 -07007917{
7918 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007919 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesacbec812013-09-20 11:29:32 -07007920 int pipe = pipe_config->cpu_transcoder;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007921 struct dpll clock;
Jesse Barnesacbec812013-09-20 11:29:32 -07007922 u32 mdiv;
Chris Wilson662c6ec2013-09-25 14:24:01 -07007923 int refclk = 100000;
Jesse Barnesacbec812013-09-20 11:29:32 -07007924
Ville Syrjäläb5219732016-03-15 16:40:01 +02007925 /* In case of DSI, DPLL will not be used */
7926 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
Shobhit Kumarf573de52014-07-30 20:32:37 +05307927 return;
7928
Ville Syrjäläa5805162015-05-26 20:42:30 +03007929 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007930 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007931 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007932
7933 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7934 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7935 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7936 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7937 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7938
Imre Deakdccbea32015-06-22 23:35:51 +03007939 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007940}
7941
Damien Lespiau5724dbd2015-01-20 12:51:52 +00007942static void
7943i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7944 struct intel_initial_plane_config *plane_config)
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007945{
7946 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007947 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007948 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7949 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007950 enum pipe pipe;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007951 u32 val, base, offset;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007952 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00007953 unsigned int aligned_height;
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007954 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00007955 struct intel_framebuffer *intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007956
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007957 if (!plane->get_hw_state(plane, &pipe))
Damien Lespiau42a7b082015-02-05 19:35:13 +00007958 return;
7959
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007960 WARN_ON(pipe != crtc->pipe);
7961
Damien Lespiaud9806c92015-01-21 14:07:19 +00007962 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00007963 if (!intel_fb) {
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007964 DRM_DEBUG_KMS("failed to alloc fb\n");
7965 return;
7966 }
7967
Damien Lespiau1b842c82015-01-21 13:50:54 +00007968 fb = &intel_fb->base;
7969
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02007970 fb->dev = dev;
7971
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02007972 val = I915_READ(DSPCNTR(i9xx_plane));
7973
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007974 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter18c52472015-02-10 17:16:09 +00007975 if (val & DISPPLANE_TILED) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007976 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02007977 fb->modifier = I915_FORMAT_MOD_X_TILED;
Daniel Vetter18c52472015-02-10 17:16:09 +00007978 }
Ville Syrjäläf43348a2018-11-20 15:54:50 +02007979
7980 if (val & DISPPLANE_ROTATE_180)
7981 plane_config->rotation = DRM_MODE_ROTATE_180;
Daniel Vetter18c52472015-02-10 17:16:09 +00007982 }
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007983
Ville Syrjäläf43348a2018-11-20 15:54:50 +02007984 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
7985 val & DISPPLANE_MIRROR)
7986 plane_config->rotation |= DRM_MODE_REFLECT_X;
7987
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007988 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
Damien Lespiaub35d63f2015-01-20 12:51:50 +00007989 fourcc = i9xx_format_to_fourcc(pixel_format);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02007990 fb->format = drm_format_info(fourcc);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007991
Ville Syrjälä81894b22017-11-17 21:19:13 +02007992 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7993 offset = I915_READ(DSPOFFSET(i9xx_plane));
7994 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7995 } else if (INTEL_GEN(dev_priv) >= 4) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007996 if (plane_config->tiling)
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007997 offset = I915_READ(DSPTILEOFF(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007998 else
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007999 offset = I915_READ(DSPLINOFF(i9xx_plane));
8000 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008001 } else {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008002 base = I915_READ(DSPADDR(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008003 }
8004 plane_config->base = base;
8005
8006 val = I915_READ(PIPESRC(pipe));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00008007 fb->width = ((val >> 16) & 0xfff) + 1;
8008 fb->height = ((val >> 0) & 0xfff) + 1;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008009
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008010 val = I915_READ(DSPSTRIDE(i9xx_plane));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00008011 fb->pitches[0] = val & 0xffffffc0;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008012
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02008013 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008014
Daniel Vetterf37b5c22015-02-10 23:12:27 +01008015 plane_config->size = fb->pitches[0] * aligned_height;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008016
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008017 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8018 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02008019 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiau2844a922015-01-20 12:51:48 +00008020 plane_config->size);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008021
Damien Lespiau2d140302015-02-05 17:22:18 +00008022 plane_config->fb = intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008023}
8024
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008025static void chv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008026 struct intel_crtc_state *pipe_config)
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008027{
8028 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008029 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008030 int pipe = pipe_config->cpu_transcoder;
8031 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03008032 struct dpll clock;
Imre Deak0d7b6b12015-07-02 14:29:58 +03008033 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008034 int refclk = 100000;
8035
Ville Syrjäläb5219732016-03-15 16:40:01 +02008036 /* In case of DSI, DPLL will not be used */
8037 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8038 return;
8039
Ville Syrjäläa5805162015-05-26 20:42:30 +03008040 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008041 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8042 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8043 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8044 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
Imre Deak0d7b6b12015-07-02 14:29:58 +03008045 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
Ville Syrjäläa5805162015-05-26 20:42:30 +03008046 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008047
8048 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
Imre Deak0d7b6b12015-07-02 14:29:58 +03008049 clock.m2 = (pll_dw0 & 0xff) << 22;
8050 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
8051 clock.m2 |= pll_dw2 & 0x3fffff;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008052 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8053 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8054 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8055
Imre Deakdccbea32015-06-22 23:35:51 +03008056 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008057}
8058
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308059static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
8060 struct intel_crtc_state *pipe_config)
8061{
8062 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8063 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
8064
Shashank Sharma668b6c12018-10-12 11:53:14 +05308065 pipe_config->lspcon_downsampling = false;
8066
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308067 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8068 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
8069
8070 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
8071 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
8072 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
8073
8074 if (ycbcr420_enabled) {
8075 /* We support 4:2:0 in full blend mode only */
8076 if (!blend)
8077 output = INTEL_OUTPUT_FORMAT_INVALID;
8078 else if (!(IS_GEMINILAKE(dev_priv) ||
8079 INTEL_GEN(dev_priv) >= 10))
8080 output = INTEL_OUTPUT_FORMAT_INVALID;
8081 else
8082 output = INTEL_OUTPUT_FORMAT_YCBCR420;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308083 } else {
Shashank Sharma668b6c12018-10-12 11:53:14 +05308084 /*
8085 * Currently there is no interface defined to
8086 * check user preference between RGB/YCBCR444
8087 * or YCBCR420. So the only possible case for
8088 * YCBCR444 usage is driving YCBCR420 output
8089 * with LSPCON, when pipe is configured for
8090 * YCBCR444 output and LSPCON takes care of
8091 * downsampling it.
8092 */
8093 pipe_config->lspcon_downsampling = true;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308094 output = INTEL_OUTPUT_FORMAT_YCBCR444;
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308095 }
8096 }
8097 }
8098
8099 pipe_config->output_format = output;
8100}
8101
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008102static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008103 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008104{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008105 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02008106 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00008107 intel_wakeref_t wakeref;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008108 u32 tmp;
Imre Deak17290502016-02-12 18:55:11 +02008109 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008110
Imre Deak17290502016-02-12 18:55:11 +02008111 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00008112 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8113 if (!wakeref)
Imre Deakb5482bd2014-03-05 16:20:55 +02008114 return false;
8115
Shashank Sharmad9facae2018-10-12 11:53:07 +05308116 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02008117 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008118 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02008119
Imre Deak17290502016-02-12 18:55:11 +02008120 ret = false;
8121
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008122 tmp = I915_READ(PIPECONF(crtc->pipe));
8123 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02008124 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008125
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01008126 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8127 IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä42571ae2013-09-06 23:29:00 +03008128 switch (tmp & PIPECONF_BPC_MASK) {
8129 case PIPECONF_6BPC:
8130 pipe_config->pipe_bpp = 18;
8131 break;
8132 case PIPECONF_8BPC:
8133 pipe_config->pipe_bpp = 24;
8134 break;
8135 case PIPECONF_10BPC:
8136 pipe_config->pipe_bpp = 30;
8137 break;
8138 default:
8139 break;
8140 }
8141 }
8142
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008143 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08008144 (tmp & PIPECONF_COLOR_RANGE_SELECT))
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02008145 pipe_config->limited_color_range = true;
8146
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008147 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä282740f2013-09-04 18:30:03 +03008148 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8149
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02008150 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02008151 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02008152
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008153 i9xx_get_pfit_config(crtc, pipe_config);
8154
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008155 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjäläc2317752016-03-15 16:39:56 +02008156 /* No way to read it out on pipes B and C */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008157 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
Ville Syrjäläc2317752016-03-15 16:39:56 +02008158 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8159 else
8160 tmp = I915_READ(DPLL_MD(crtc->pipe));
Daniel Vetter6c49f242013-06-06 12:45:25 +02008161 pipe_config->pixel_multiplier =
8162 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8163 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008164 pipe_config->dpll_hw_state.dpll_md = tmp;
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01008165 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
Jani Nikula73f67aa2016-12-07 22:48:09 +02008166 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Daniel Vetter6c49f242013-06-06 12:45:25 +02008167 tmp = I915_READ(DPLL(crtc->pipe));
8168 pipe_config->pixel_multiplier =
8169 ((tmp & SDVO_MULTIPLIER_MASK)
8170 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8171 } else {
8172 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8173 * port and will be fixed up in the encoder->get_config
8174 * function. */
8175 pipe_config->pixel_multiplier = 1;
8176 }
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008177 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008178 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03008179 /*
8180 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8181 * on 830. Filter it out here so that we don't
8182 * report errors due to that.
8183 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01008184 if (IS_I830(dev_priv))
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03008185 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8186
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008187 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8188 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
Ville Syrjälä165e9012013-06-26 17:44:15 +03008189 } else {
8190 /* Mask out read-only status bits. */
8191 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8192 DPLL_PORTC_READY_MASK |
8193 DPLL_PORTB_READY_MASK);
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008194 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02008195
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008196 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008197 chv_crtc_clock_get(crtc, pipe_config);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01008198 else if (IS_VALLEYVIEW(dev_priv))
Jesse Barnesacbec812013-09-20 11:29:32 -07008199 vlv_crtc_clock_get(crtc, pipe_config);
8200 else
8201 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +03008202
Ville Syrjälä0f646142015-08-26 19:39:18 +03008203 /*
8204 * Normally the dotclock is filled in by the encoder .get_config()
8205 * but in case the pipe is enabled w/o any ports we need a sane
8206 * default.
8207 */
8208 pipe_config->base.adjusted_mode.crtc_clock =
8209 pipe_config->port_clock / pipe_config->pixel_multiplier;
8210
Imre Deak17290502016-02-12 18:55:11 +02008211 ret = true;
8212
8213out:
Chris Wilson0e6e0be2019-01-14 14:21:24 +00008214 intel_display_power_put(dev_priv, power_domain, wakeref);
Imre Deak17290502016-02-12 18:55:11 +02008215
8216 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008217}
8218
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008219static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
Jesse Barnes13d83a62011-08-03 12:59:20 -07008220{
Jesse Barnes13d83a62011-08-03 12:59:20 -07008221 struct intel_encoder *encoder;
Lyude1c1a24d2016-06-14 11:04:09 -04008222 int i;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008223 u32 val, final;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008224 bool has_lvds = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008225 bool has_cpu_edp = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008226 bool has_panel = false;
Keith Packard99eb6a02011-09-26 14:29:12 -07008227 bool has_ck505 = false;
8228 bool can_ssc = false;
Lyude1c1a24d2016-06-14 11:04:09 -04008229 bool using_ssc_source = false;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008230
8231 /* We need to take the global config into account */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008232 for_each_intel_encoder(&dev_priv->drm, encoder) {
Keith Packard199e5d72011-09-22 12:01:57 -07008233 switch (encoder->type) {
8234 case INTEL_OUTPUT_LVDS:
8235 has_panel = true;
8236 has_lvds = true;
8237 break;
8238 case INTEL_OUTPUT_EDP:
8239 has_panel = true;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02008240 if (encoder->port == PORT_A)
Keith Packard199e5d72011-09-22 12:01:57 -07008241 has_cpu_edp = true;
8242 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008243 default:
8244 break;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008245 }
8246 }
8247
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008248 if (HAS_PCH_IBX(dev_priv)) {
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03008249 has_ck505 = dev_priv->vbt.display_clock_mode;
Keith Packard99eb6a02011-09-26 14:29:12 -07008250 can_ssc = has_ck505;
8251 } else {
8252 has_ck505 = false;
8253 can_ssc = true;
8254 }
8255
Lyude1c1a24d2016-06-14 11:04:09 -04008256 /* Check if any DPLLs are using the SSC source */
8257 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8258 u32 temp = I915_READ(PCH_DPLL(i));
8259
8260 if (!(temp & DPLL_VCO_ENABLE))
8261 continue;
8262
8263 if ((temp & PLL_REF_INPUT_MASK) ==
8264 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8265 using_ssc_source = true;
8266 break;
8267 }
8268 }
8269
8270 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8271 has_panel, has_lvds, has_ck505, using_ssc_source);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008272
8273 /* Ironlake: try to setup display ref clock before DPLL
8274 * enabling. This is only under driver's control after
8275 * PCH B stepping, previous chipset stepping should be
8276 * ignoring this setting.
8277 */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008278 val = I915_READ(PCH_DREF_CONTROL);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008279
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008280 /* As we must carefully and slowly disable/enable each source in turn,
8281 * compute the final state we want first and check if we need to
8282 * make any changes at all.
8283 */
8284 final = val;
8285 final &= ~DREF_NONSPREAD_SOURCE_MASK;
Keith Packard99eb6a02011-09-26 14:29:12 -07008286 if (has_ck505)
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008287 final |= DREF_NONSPREAD_CK505_ENABLE;
Keith Packard99eb6a02011-09-26 14:29:12 -07008288 else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008289 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8290
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008291 final &= ~DREF_SSC_SOURCE_MASK;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008292 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008293 final &= ~DREF_SSC1_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008294
Keith Packard199e5d72011-09-22 12:01:57 -07008295 if (has_panel) {
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008296 final |= DREF_SSC_SOURCE_ENABLE;
8297
8298 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8299 final |= DREF_SSC1_ENABLE;
8300
8301 if (has_cpu_edp) {
8302 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8303 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8304 else
8305 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8306 } else
8307 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Lyude1c1a24d2016-06-14 11:04:09 -04008308 } else if (using_ssc_source) {
8309 final |= DREF_SSC_SOURCE_ENABLE;
8310 final |= DREF_SSC1_ENABLE;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008311 }
8312
8313 if (final == val)
8314 return;
8315
8316 /* Always enable nonspread source */
8317 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8318
8319 if (has_ck505)
8320 val |= DREF_NONSPREAD_CK505_ENABLE;
8321 else
8322 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8323
8324 if (has_panel) {
8325 val &= ~DREF_SSC_SOURCE_MASK;
8326 val |= DREF_SSC_SOURCE_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008327
Keith Packard199e5d72011-09-22 12:01:57 -07008328 /* SSC must be turned on before enabling the CPU output */
Keith Packard99eb6a02011-09-26 14:29:12 -07008329 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008330 DRM_DEBUG_KMS("Using SSC on panel\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008331 val |= DREF_SSC1_ENABLE;
Daniel Vettere77166b2012-03-30 22:14:05 +02008332 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008333 val &= ~DREF_SSC1_ENABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008334
8335 /* Get SSC going before enabling the outputs */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008336 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008337 POSTING_READ(PCH_DREF_CONTROL);
8338 udelay(200);
8339
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008340 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008341
8342 /* Enable CPU source on CPU attached eDP */
Keith Packard199e5d72011-09-22 12:01:57 -07008343 if (has_cpu_edp) {
Keith Packard99eb6a02011-09-26 14:29:12 -07008344 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008345 DRM_DEBUG_KMS("Using SSC on eDP\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008346 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
Robin Schroereba905b2014-05-18 02:24:50 +02008347 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008348 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
Keith Packard199e5d72011-09-22 12:01:57 -07008349 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008350 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008351
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008352 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008353 POSTING_READ(PCH_DREF_CONTROL);
8354 udelay(200);
8355 } else {
Lyude1c1a24d2016-06-14 11:04:09 -04008356 DRM_DEBUG_KMS("Disabling CPU source output\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008357
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008358 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Keith Packard199e5d72011-09-22 12:01:57 -07008359
8360 /* Turn off CPU output */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008361 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008362
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008363 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008364 POSTING_READ(PCH_DREF_CONTROL);
8365 udelay(200);
8366
Lyude1c1a24d2016-06-14 11:04:09 -04008367 if (!using_ssc_source) {
8368 DRM_DEBUG_KMS("Disabling SSC source\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008369
Lyude1c1a24d2016-06-14 11:04:09 -04008370 /* Turn off the SSC source */
8371 val &= ~DREF_SSC_SOURCE_MASK;
8372 val |= DREF_SSC_SOURCE_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008373
Lyude1c1a24d2016-06-14 11:04:09 -04008374 /* Turn off SSC1 */
8375 val &= ~DREF_SSC1_ENABLE;
8376
8377 I915_WRITE(PCH_DREF_CONTROL, val);
8378 POSTING_READ(PCH_DREF_CONTROL);
8379 udelay(200);
8380 }
Jesse Barnes13d83a62011-08-03 12:59:20 -07008381 }
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008382
8383 BUG_ON(val != final);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008384}
8385
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008386static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008387{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008388 u32 tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008389
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008390 tmp = I915_READ(SOUTH_CHICKEN2);
8391 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8392 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008393
Imre Deakcf3598c2016-06-28 13:37:31 +03008394 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8395 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008396 DRM_ERROR("FDI mPHY reset assert timeout\n");
Paulo Zanonidde86e22012-12-01 12:04:25 -02008397
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008398 tmp = I915_READ(SOUTH_CHICKEN2);
8399 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8400 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008401
Imre Deakcf3598c2016-06-28 13:37:31 +03008402 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8403 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008404 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008405}
8406
8407/* WaMPhyProgramming:hsw */
8408static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8409{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008410 u32 tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008411
8412 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8413 tmp &= ~(0xFF << 24);
8414 tmp |= (0x12 << 24);
8415 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8416
Paulo Zanonidde86e22012-12-01 12:04:25 -02008417 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8418 tmp |= (1 << 11);
8419 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8420
8421 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8422 tmp |= (1 << 11);
8423 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8424
Paulo Zanonidde86e22012-12-01 12:04:25 -02008425 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8426 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8427 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8428
8429 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8430 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8431 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8432
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008433 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8434 tmp &= ~(7 << 13);
8435 tmp |= (5 << 13);
8436 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008437
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008438 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8439 tmp &= ~(7 << 13);
8440 tmp |= (5 << 13);
8441 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008442
8443 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8444 tmp &= ~0xFF;
8445 tmp |= 0x1C;
8446 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8447
8448 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8449 tmp &= ~0xFF;
8450 tmp |= 0x1C;
8451 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8452
8453 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8454 tmp &= ~(0xFF << 16);
8455 tmp |= (0x1C << 16);
8456 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8457
8458 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8459 tmp &= ~(0xFF << 16);
8460 tmp |= (0x1C << 16);
8461 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8462
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008463 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8464 tmp |= (1 << 27);
8465 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008466
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008467 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8468 tmp |= (1 << 27);
8469 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008470
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008471 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8472 tmp &= ~(0xF << 28);
8473 tmp |= (4 << 28);
8474 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008475
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008476 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8477 tmp &= ~(0xF << 28);
8478 tmp |= (4 << 28);
8479 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008480}
8481
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008482/* Implements 3 different sequences from BSpec chapter "Display iCLK
8483 * Programming" based on the parameters passed:
8484 * - Sequence to enable CLKOUT_DP
8485 * - Sequence to enable CLKOUT_DP without spread
8486 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8487 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008488static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8489 bool with_spread, bool with_fdi)
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008490{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008491 u32 reg, tmp;
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008492
8493 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8494 with_spread = true;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008495 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8496 with_fdi, "LP PCH doesn't have FDI\n"))
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008497 with_fdi = false;
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008498
Ville Syrjäläa5805162015-05-26 20:42:30 +03008499 mutex_lock(&dev_priv->sb_lock);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008500
8501 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8502 tmp &= ~SBI_SSCCTL_DISABLE;
8503 tmp |= SBI_SSCCTL_PATHALT;
8504 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8505
8506 udelay(24);
8507
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008508 if (with_spread) {
8509 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8510 tmp &= ~SBI_SSCCTL_PATHALT;
8511 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008512
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008513 if (with_fdi) {
8514 lpt_reset_fdi_mphy(dev_priv);
8515 lpt_program_fdi_mphy(dev_priv);
8516 }
8517 }
Paulo Zanonidde86e22012-12-01 12:04:25 -02008518
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008519 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008520 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8521 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8522 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
Daniel Vetterc00db242013-01-22 15:33:27 +01008523
Ville Syrjäläa5805162015-05-26 20:42:30 +03008524 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008525}
8526
Paulo Zanoni47701c32013-07-23 11:19:25 -03008527/* Sequence to disable CLKOUT_DP */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008528static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
Paulo Zanoni47701c32013-07-23 11:19:25 -03008529{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008530 u32 reg, tmp;
Paulo Zanoni47701c32013-07-23 11:19:25 -03008531
Ville Syrjäläa5805162015-05-26 20:42:30 +03008532 mutex_lock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008533
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008534 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni47701c32013-07-23 11:19:25 -03008535 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8536 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8537 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8538
8539 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8540 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8541 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8542 tmp |= SBI_SSCCTL_PATHALT;
8543 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8544 udelay(32);
8545 }
8546 tmp |= SBI_SSCCTL_DISABLE;
8547 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8548 }
8549
Ville Syrjäläa5805162015-05-26 20:42:30 +03008550 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008551}
8552
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008553#define BEND_IDX(steps) ((50 + (steps)) / 5)
8554
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008555static const u16 sscdivintphase[] = {
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008556 [BEND_IDX( 50)] = 0x3B23,
8557 [BEND_IDX( 45)] = 0x3B23,
8558 [BEND_IDX( 40)] = 0x3C23,
8559 [BEND_IDX( 35)] = 0x3C23,
8560 [BEND_IDX( 30)] = 0x3D23,
8561 [BEND_IDX( 25)] = 0x3D23,
8562 [BEND_IDX( 20)] = 0x3E23,
8563 [BEND_IDX( 15)] = 0x3E23,
8564 [BEND_IDX( 10)] = 0x3F23,
8565 [BEND_IDX( 5)] = 0x3F23,
8566 [BEND_IDX( 0)] = 0x0025,
8567 [BEND_IDX( -5)] = 0x0025,
8568 [BEND_IDX(-10)] = 0x0125,
8569 [BEND_IDX(-15)] = 0x0125,
8570 [BEND_IDX(-20)] = 0x0225,
8571 [BEND_IDX(-25)] = 0x0225,
8572 [BEND_IDX(-30)] = 0x0325,
8573 [BEND_IDX(-35)] = 0x0325,
8574 [BEND_IDX(-40)] = 0x0425,
8575 [BEND_IDX(-45)] = 0x0425,
8576 [BEND_IDX(-50)] = 0x0525,
8577};
8578
8579/*
8580 * Bend CLKOUT_DP
8581 * steps -50 to 50 inclusive, in steps of 5
8582 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8583 * change in clock period = -(steps / 10) * 5.787 ps
8584 */
8585static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8586{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008587 u32 tmp;
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008588 int idx = BEND_IDX(steps);
8589
8590 if (WARN_ON(steps % 5 != 0))
8591 return;
8592
8593 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8594 return;
8595
8596 mutex_lock(&dev_priv->sb_lock);
8597
8598 if (steps % 10 != 0)
8599 tmp = 0xAAAAAAAB;
8600 else
8601 tmp = 0x00000000;
8602 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8603
8604 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8605 tmp &= 0xffff0000;
8606 tmp |= sscdivintphase[idx];
8607 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8608
8609 mutex_unlock(&dev_priv->sb_lock);
8610}
8611
8612#undef BEND_IDX
8613
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008614static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008615{
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008616 struct intel_encoder *encoder;
8617 bool has_vga = false;
8618
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008619 for_each_intel_encoder(&dev_priv->drm, encoder) {
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008620 switch (encoder->type) {
8621 case INTEL_OUTPUT_ANALOG:
8622 has_vga = true;
8623 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008624 default:
8625 break;
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008626 }
8627 }
8628
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008629 if (has_vga) {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008630 lpt_bend_clkout_dp(dev_priv, 0);
8631 lpt_enable_clkout_dp(dev_priv, true, true);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008632 } else {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008633 lpt_disable_clkout_dp(dev_priv);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008634 }
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008635}
8636
Paulo Zanonidde86e22012-12-01 12:04:25 -02008637/*
8638 * Initialize reference clocks when the driver loads
8639 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008640void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008641{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008642 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008643 ironlake_init_pch_refclk(dev_priv);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008644 else if (HAS_PCH_LPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008645 lpt_init_pch_refclk(dev_priv);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008646}
8647
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008648static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanonic8203562012-09-12 10:06:29 -03008649{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008650 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8651 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8652 enum pipe pipe = crtc->pipe;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008653 u32 val;
Paulo Zanonic8203562012-09-12 10:06:29 -03008654
Daniel Vetter78114072013-06-13 00:54:57 +02008655 val = 0;
Paulo Zanonic8203562012-09-12 10:06:29 -03008656
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008657 switch (crtc_state->pipe_bpp) {
Paulo Zanonic8203562012-09-12 10:06:29 -03008658 case 18:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008659 val |= PIPECONF_6BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008660 break;
8661 case 24:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008662 val |= PIPECONF_8BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008663 break;
8664 case 30:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008665 val |= PIPECONF_10BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008666 break;
8667 case 36:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008668 val |= PIPECONF_12BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008669 break;
8670 default:
Paulo Zanonicc769b62012-09-20 18:36:03 -03008671 /* Case prevented by intel_choose_pipe_bpp_dither. */
8672 BUG();
Paulo Zanonic8203562012-09-12 10:06:29 -03008673 }
8674
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008675 if (crtc_state->dither)
Paulo Zanonic8203562012-09-12 10:06:29 -03008676 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8677
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008678 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanonic8203562012-09-12 10:06:29 -03008679 val |= PIPECONF_INTERLACED_ILK;
8680 else
8681 val |= PIPECONF_PROGRESSIVE;
8682
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008683 if (crtc_state->limited_color_range)
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008684 val |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008685
Paulo Zanonic8203562012-09-12 10:06:29 -03008686 I915_WRITE(PIPECONF(pipe), val);
8687 POSTING_READ(PIPECONF(pipe));
8688}
8689
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008690static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008691{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008692 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8693 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8694 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Jani Nikula391bf042016-03-18 17:05:40 +02008695 u32 val = 0;
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008696
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008697 if (IS_HASWELL(dev_priv) && crtc_state->dither)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008698 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8699
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008700 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008701 val |= PIPECONF_INTERLACED_ILK;
8702 else
8703 val |= PIPECONF_PROGRESSIVE;
8704
Paulo Zanoni702e7a52012-10-23 18:29:59 -02008705 I915_WRITE(PIPECONF(cpu_transcoder), val);
8706 POSTING_READ(PIPECONF(cpu_transcoder));
Jani Nikula391bf042016-03-18 17:05:40 +02008707}
8708
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008709static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
Jani Nikula391bf042016-03-18 17:05:40 +02008710{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008711 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8712 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jani Nikula391bf042016-03-18 17:05:40 +02008713
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00008714 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
Jani Nikula391bf042016-03-18 17:05:40 +02008715 u32 val = 0;
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008716
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008717 switch (crtc_state->pipe_bpp) {
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008718 case 18:
8719 val |= PIPEMISC_DITHER_6_BPC;
8720 break;
8721 case 24:
8722 val |= PIPEMISC_DITHER_8_BPC;
8723 break;
8724 case 30:
8725 val |= PIPEMISC_DITHER_10_BPC;
8726 break;
8727 case 36:
8728 val |= PIPEMISC_DITHER_12_BPC;
8729 break;
8730 default:
8731 /* Case prevented by pipe_config_set_bpp. */
8732 BUG();
8733 }
8734
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008735 if (crtc_state->dither)
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008736 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8737
Shashank Sharma8c79f842018-10-12 11:53:09 +05308738 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8739 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308740 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308741
8742 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308743 val |= PIPEMISC_YUV420_ENABLE |
Shashank Sharmab22ca992017-07-24 19:19:32 +05308744 PIPEMISC_YUV420_MODE_FULL_BLEND;
Shashank Sharmab22ca992017-07-24 19:19:32 +05308745
Jani Nikula391bf042016-03-18 17:05:40 +02008746 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008747 }
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008748}
8749
Paulo Zanonid4b19312012-11-29 11:29:32 -02008750int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8751{
8752 /*
8753 * Account for spread spectrum to avoid
8754 * oversubscribing the link. Max center spread
8755 * is 2.5%; use 5% for safety's sake.
8756 */
8757 u32 bps = target_clock * bpp * 21 / 20;
Ville Syrjälä619d4d02014-02-27 14:23:14 +02008758 return DIV_ROUND_UP(bps, link_bw * 8);
Paulo Zanonid4b19312012-11-29 11:29:32 -02008759}
8760
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008761static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
Daniel Vetter6cf86a52013-04-02 23:38:10 +02008762{
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008763 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
Paulo Zanonif48d8f22012-09-20 18:36:04 -03008764}
8765
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008766static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8767 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03008768 struct dpll *reduced_clock)
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008769{
8770 struct drm_crtc *crtc = &intel_crtc->base;
8771 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008772 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008773 u32 dpll, fp, fp2;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008774 int factor;
Jesse Barnes79e53942008-11-07 14:24:08 -08008775
Chris Wilsonc1858122010-12-03 21:35:48 +00008776 /* Enable autotuning of the PLL clock (if permissible) */
Eric Anholt8febb292011-03-30 13:01:07 -07008777 factor = 21;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008778 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Eric Anholt8febb292011-03-30 13:01:07 -07008779 if ((intel_panel_use_ssc(dev_priv) &&
Ville Syrjäläe91e9412013-12-09 18:54:16 +02008780 dev_priv->vbt.lvds_ssc_freq == 100000) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008781 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
Eric Anholt8febb292011-03-30 13:01:07 -07008782 factor = 25;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008783 } else if (crtc_state->sdvo_tv_clock)
Eric Anholt8febb292011-03-30 13:01:07 -07008784 factor = 20;
Chris Wilsonc1858122010-12-03 21:35:48 +00008785
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008786 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Chris Wilsonc1858122010-12-03 21:35:48 +00008787
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008788 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8789 fp |= FP_CB_TUNE;
8790
8791 if (reduced_clock) {
8792 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8793
8794 if (reduced_clock->m < factor * reduced_clock->n)
8795 fp2 |= FP_CB_TUNE;
8796 } else {
8797 fp2 = fp;
8798 }
Daniel Vetter9a7c7892013-04-04 22:20:34 +02008799
Chris Wilson5eddb702010-09-11 13:48:45 +01008800 dpll = 0;
Zhenyu Wang2c072452009-06-05 15:38:42 +08008801
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008802 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Eric Anholta07d6782011-03-30 13:01:08 -07008803 dpll |= DPLLB_MODE_LVDS;
8804 else
8805 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008806
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008807 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02008808 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008809
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008810 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8811 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008812 dpll |= DPLL_SDVO_HIGH_SPEED;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008813
Ville Syrjälä37a56502016-06-22 21:57:04 +03008814 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008815 dpll |= DPLL_SDVO_HIGH_SPEED;
Jesse Barnes79e53942008-11-07 14:24:08 -08008816
Ville Syrjälä7d7f8632016-09-26 11:30:46 +03008817 /*
8818 * The high speed IO clock is only really required for
8819 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8820 * possible to share the DPLL between CRT and HDMI. Enabling
8821 * the clock needlessly does no real harm, except use up a
8822 * bit of power potentially.
8823 *
8824 * We'll limit this to IVB with 3 pipes, since it has only two
8825 * DPLLs and so DPLL sharing is the only way to get three pipes
8826 * driving PCH ports at the same time. On SNB we could do this,
8827 * and potentially avoid enabling the second DPLL, but it's not
8828 * clear if it''s a win or loss power wise. No point in doing
8829 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8830 */
8831 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8832 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8833 dpll |= DPLL_SDVO_HIGH_SPEED;
8834
Eric Anholta07d6782011-03-30 13:01:08 -07008835 /* compute bitmask from p1 value */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008836 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008837 /* also FPA1 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008838 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008839
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008840 switch (crtc_state->dpll.p2) {
Eric Anholta07d6782011-03-30 13:01:08 -07008841 case 5:
8842 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8843 break;
8844 case 7:
8845 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8846 break;
8847 case 10:
8848 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8849 break;
8850 case 14:
8851 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8852 break;
Jesse Barnes79e53942008-11-07 14:24:08 -08008853 }
8854
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008855 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8856 intel_panel_use_ssc(dev_priv))
Kristian Høgsberg43565a02009-02-13 20:56:52 -05008857 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
Jesse Barnes79e53942008-11-07 14:24:08 -08008858 else
8859 dpll |= PLL_REF_INPUT_DREFCLK;
8860
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008861 dpll |= DPLL_VCO_ENABLE;
8862
8863 crtc_state->dpll_hw_state.dpll = dpll;
8864 crtc_state->dpll_hw_state.fp0 = fp;
8865 crtc_state->dpll_hw_state.fp1 = fp2;
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008866}
8867
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008868static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8869 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08008870{
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008871 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008872 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03008873 const struct intel_limit *limit;
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008874 int refclk = 120000;
Jesse Barnes79e53942008-11-07 14:24:08 -08008875
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03008876 memset(&crtc_state->dpll_hw_state, 0,
8877 sizeof(crtc_state->dpll_hw_state));
8878
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008879 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8880 if (!crtc_state->has_pch_encoder)
8881 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008882
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03008883 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008884 if (intel_panel_use_ssc(dev_priv)) {
8885 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8886 dev_priv->vbt.lvds_ssc_freq);
8887 refclk = dev_priv->vbt.lvds_ssc_freq;
8888 }
8889
8890 if (intel_is_dual_link_lvds(dev)) {
8891 if (refclk == 100000)
8892 limit = &intel_limits_ironlake_dual_lvds_100m;
8893 else
8894 limit = &intel_limits_ironlake_dual_lvds;
8895 } else {
8896 if (refclk == 100000)
8897 limit = &intel_limits_ironlake_single_lvds_100m;
8898 else
8899 limit = &intel_limits_ironlake_single_lvds;
8900 }
8901 } else {
8902 limit = &intel_limits_ironlake_dac;
8903 }
8904
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008905 if (!crtc_state->clock_set &&
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008906 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8907 refclk, NULL, &crtc_state->dpll)) {
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008908 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8909 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01008910 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008911
Gustavo A. R. Silvacbaa3312017-05-15 16:56:05 -05008912 ironlake_compute_dpll(crtc, crtc_state, NULL);
Daniel Vetter66e985c2013-06-05 13:34:20 +02008913
Gustavo A. R. Silvaefd38b62017-05-15 17:00:28 -05008914 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
Chris Wilson43031782018-09-13 14:16:26 +01008915 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8916 pipe_name(crtc->pipe));
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008917 return -EINVAL;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +02008918 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008919
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02008920 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008921}
8922
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008923static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8924 struct intel_link_m_n *m_n)
Daniel Vetter72419202013-04-04 13:28:53 +02008925{
8926 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008927 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008928 enum pipe pipe = crtc->pipe;
Daniel Vetter72419202013-04-04 13:28:53 +02008929
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008930 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8931 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8932 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8933 & ~TU_SIZE_MASK;
8934 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8935 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8936 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8937}
8938
8939static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8940 enum transcoder transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008941 struct intel_link_m_n *m_n,
8942 struct intel_link_m_n *m2_n2)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008943{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008944 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008945 enum pipe pipe = crtc->pipe;
8946
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008947 if (INTEL_GEN(dev_priv) >= 5) {
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008948 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8949 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8950 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8951 & ~TU_SIZE_MASK;
8952 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8953 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8954 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02008955
8956 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008957 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8958 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8959 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8960 & ~TU_SIZE_MASK;
8961 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8962 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8963 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8964 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008965 } else {
8966 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8967 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8968 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8969 & ~TU_SIZE_MASK;
8970 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8971 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8972 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8973 }
8974}
8975
8976void intel_dp_get_m_n(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008977 struct intel_crtc_state *pipe_config)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008978{
Ander Conselvan de Oliveira681a8502015-01-15 14:55:24 +02008979 if (pipe_config->has_pch_encoder)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008980 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8981 else
8982 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008983 &pipe_config->dp_m_n,
8984 &pipe_config->dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008985}
8986
Daniel Vetter72419202013-04-04 13:28:53 +02008987static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008988 struct intel_crtc_state *pipe_config)
Daniel Vetter72419202013-04-04 13:28:53 +02008989{
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008990 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008991 &pipe_config->fdi_m_n, NULL);
Daniel Vetter72419202013-04-04 13:28:53 +02008992}
8993
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008994static void skylake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008995 struct intel_crtc_state *pipe_config)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008996{
8997 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008998 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Kondurua1b22782015-04-07 15:28:45 -07008999 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009000 u32 ps_ctrl = 0;
Chandra Kondurua1b22782015-04-07 15:28:45 -07009001 int id = -1;
9002 int i;
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009003
Chandra Kondurua1b22782015-04-07 15:28:45 -07009004 /* find scaler attached to this pipe */
9005 for (i = 0; i < crtc->num_scalers; i++) {
9006 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9007 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9008 id = i;
9009 pipe_config->pch_pfit.enabled = true;
9010 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9011 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
Maarten Lankhorst0cdc1d02019-01-08 17:08:41 +01009012 scaler_state->scalers[i].in_use = true;
Chandra Kondurua1b22782015-04-07 15:28:45 -07009013 break;
9014 }
9015 }
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009016
Chandra Kondurua1b22782015-04-07 15:28:45 -07009017 scaler_state->scaler_id = id;
9018 if (id >= 0) {
9019 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9020 } else {
9021 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009022 }
9023}
9024
Damien Lespiau5724dbd2015-01-20 12:51:52 +00009025static void
9026skylake_get_initial_plane_config(struct intel_crtc *crtc,
9027 struct intel_initial_plane_config *plane_config)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009028{
9029 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009030 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009031 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9032 enum plane_id plane_id = plane->id;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009033 enum pipe pipe;
James Ausmus4036c782017-11-13 10:11:28 -08009034 u32 val, base, offset, stride_mult, tiling, alpha;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009035 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00009036 unsigned int aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009037 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00009038 struct intel_framebuffer *intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009039
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009040 if (!plane->get_hw_state(plane, &pipe))
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02009041 return;
9042
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009043 WARN_ON(pipe != crtc->pipe);
9044
Damien Lespiaud9806c92015-01-21 14:07:19 +00009045 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00009046 if (!intel_fb) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009047 DRM_DEBUG_KMS("failed to alloc fb\n");
9048 return;
9049 }
9050
Damien Lespiau1b842c82015-01-21 13:50:54 +00009051 fb = &intel_fb->base;
9052
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02009053 fb->dev = dev;
9054
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009055 val = I915_READ(PLANE_CTL(pipe, plane_id));
Damien Lespiau42a7b082015-02-05 19:35:13 +00009056
James Ausmusb5972772018-01-30 11:49:16 -02009057 if (INTEL_GEN(dev_priv) >= 11)
9058 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
9059 else
9060 pixel_format = val & PLANE_CTL_FORMAT_MASK;
James Ausmus4036c782017-11-13 10:11:28 -08009061
9062 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009063 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
James Ausmus4036c782017-11-13 10:11:28 -08009064 alpha &= PLANE_COLOR_ALPHA_MASK;
9065 } else {
9066 alpha = val & PLANE_CTL_ALPHA_MASK;
9067 }
9068
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009069 fourcc = skl_format_to_fourcc(pixel_format,
James Ausmus4036c782017-11-13 10:11:28 -08009070 val & PLANE_CTL_ORDER_RGBX, alpha);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02009071 fb->format = drm_format_info(fourcc);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009072
Damien Lespiau40f46282015-02-27 11:15:21 +00009073 tiling = val & PLANE_CTL_TILED_MASK;
9074 switch (tiling) {
9075 case PLANE_CTL_TILED_LINEAR:
Ben Widawsky2f075562017-03-24 14:29:48 -07009076 fb->modifier = DRM_FORMAT_MOD_LINEAR;
Damien Lespiau40f46282015-02-27 11:15:21 +00009077 break;
9078 case PLANE_CTL_TILED_X:
9079 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02009080 fb->modifier = I915_FORMAT_MOD_X_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00009081 break;
9082 case PLANE_CTL_TILED_Y:
Imre Deak914a4fd2018-10-16 19:00:11 +03009083 plane_config->tiling = I915_TILING_Y;
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07009084 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07009085 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
9086 else
9087 fb->modifier = I915_FORMAT_MOD_Y_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00009088 break;
9089 case PLANE_CTL_TILED_YF:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07009090 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07009091 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
9092 else
9093 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00009094 break;
9095 default:
9096 MISSING_CASE(tiling);
9097 goto error;
9098 }
9099
Ville Syrjäläf43348a2018-11-20 15:54:50 +02009100 /*
9101 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
9102 * while i915 HW rotation is clockwise, thats why this swapping.
9103 */
9104 switch (val & PLANE_CTL_ROTATE_MASK) {
9105 case PLANE_CTL_ROTATE_0:
9106 plane_config->rotation = DRM_MODE_ROTATE_0;
9107 break;
9108 case PLANE_CTL_ROTATE_90:
9109 plane_config->rotation = DRM_MODE_ROTATE_270;
9110 break;
9111 case PLANE_CTL_ROTATE_180:
9112 plane_config->rotation = DRM_MODE_ROTATE_180;
9113 break;
9114 case PLANE_CTL_ROTATE_270:
9115 plane_config->rotation = DRM_MODE_ROTATE_90;
9116 break;
9117 }
9118
9119 if (INTEL_GEN(dev_priv) >= 10 &&
9120 val & PLANE_CTL_FLIP_HORIZONTAL)
9121 plane_config->rotation |= DRM_MODE_REFLECT_X;
9122
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009123 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009124 plane_config->base = base;
9125
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009126 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009127
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009128 val = I915_READ(PLANE_SIZE(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009129 fb->height = ((val >> 16) & 0xfff) + 1;
9130 fb->width = ((val >> 0) & 0x1fff) + 1;
9131
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009132 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03009133 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009134 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9135
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02009136 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009137
Daniel Vetterf37b5c22015-02-10 23:12:27 +01009138 plane_config->size = fb->pitches[0] * aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009139
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009140 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9141 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02009142 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009143 plane_config->size);
9144
Damien Lespiau2d140302015-02-05 17:22:18 +00009145 plane_config->fb = intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009146 return;
9147
9148error:
Matthew Auldd1a3a032016-08-23 16:00:44 +01009149 kfree(intel_fb);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009150}
9151
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009152static void ironlake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009153 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009154{
9155 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009156 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009157 u32 tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009158
9159 tmp = I915_READ(PF_CTL(crtc->pipe));
9160
9161 if (tmp & PF_ENABLE) {
Chris Wilsonfd4daa92013-08-27 17:04:17 +01009162 pipe_config->pch_pfit.enabled = true;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009163 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9164 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
Daniel Vettercb8b2a32013-06-01 17:16:23 +02009165
9166 /* We currently do not free assignements of panel fitters on
9167 * ivb/hsw (since we don't use the higher upscaling modes which
9168 * differentiates them) so just WARN about this case for now. */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08009169 if (IS_GEN(dev_priv, 7)) {
Daniel Vettercb8b2a32013-06-01 17:16:23 +02009170 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9171 PF_PIPE_SEL_IVB(crtc->pipe));
9172 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009173 }
Jesse Barnes79e53942008-11-07 14:24:08 -08009174}
9175
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009176static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009177 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009178{
9179 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009180 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak17290502016-02-12 18:55:11 +02009181 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00009182 intel_wakeref_t wakeref;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009183 u32 tmp;
Imre Deak17290502016-02-12 18:55:11 +02009184 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009185
Imre Deak17290502016-02-12 18:55:11 +02009186 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00009187 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9188 if (!wakeref)
Paulo Zanoni930e8c92014-07-04 13:38:34 -03009189 return false;
9190
Shashank Sharmad9facae2018-10-12 11:53:07 +05309191 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02009192 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009193 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02009194
Imre Deak17290502016-02-12 18:55:11 +02009195 ret = false;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009196 tmp = I915_READ(PIPECONF(crtc->pipe));
9197 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02009198 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009199
Ville Syrjälä42571ae2013-09-06 23:29:00 +03009200 switch (tmp & PIPECONF_BPC_MASK) {
9201 case PIPECONF_6BPC:
9202 pipe_config->pipe_bpp = 18;
9203 break;
9204 case PIPECONF_8BPC:
9205 pipe_config->pipe_bpp = 24;
9206 break;
9207 case PIPECONF_10BPC:
9208 pipe_config->pipe_bpp = 30;
9209 break;
9210 case PIPECONF_12BPC:
9211 pipe_config->pipe_bpp = 36;
9212 break;
9213 default:
9214 break;
9215 }
9216
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02009217 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9218 pipe_config->limited_color_range = true;
9219
Daniel Vetterab9412b2013-05-03 11:49:46 +02009220 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
Daniel Vetter66e985c2013-06-05 13:34:20 +02009221 struct intel_shared_dpll *pll;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009222 enum intel_dpll_id pll_id;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009223
Daniel Vetter88adfff2013-03-28 10:42:01 +01009224 pipe_config->has_pch_encoder = true;
9225
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009226 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9227 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9228 FDI_DP_PORT_WIDTH_SHIFT) + 1;
Daniel Vetter72419202013-04-04 13:28:53 +02009229
9230 ironlake_get_fdi_m_n_config(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009231
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03009232 if (HAS_PCH_IBX(dev_priv)) {
Imre Deakd9a7bc62016-05-12 16:18:50 +03009233 /*
9234 * The pipe->pch transcoder and pch transcoder->pll
9235 * mapping is fixed.
9236 */
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009237 pll_id = (enum intel_dpll_id) crtc->pipe;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009238 } else {
9239 tmp = I915_READ(PCH_DPLL_SEL);
9240 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009241 pll_id = DPLL_ID_PCH_PLL_B;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009242 else
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009243 pll_id= DPLL_ID_PCH_PLL_A;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009244 }
Daniel Vetter66e985c2013-06-05 13:34:20 +02009245
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009246 pipe_config->shared_dpll =
9247 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9248 pll = pipe_config->shared_dpll;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009249
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009250 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9251 &pipe_config->dpll_hw_state));
Daniel Vetterc93f54c2013-06-27 19:47:19 +02009252
9253 tmp = pipe_config->dpll_hw_state.dpll;
9254 pipe_config->pixel_multiplier =
9255 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9256 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
Ville Syrjälä18442d02013-09-13 16:00:08 +03009257
9258 ironlake_pch_clock_get(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009259 } else {
9260 pipe_config->pixel_multiplier = 1;
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009261 }
9262
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009263 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02009264 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009265
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009266 ironlake_get_pfit_config(crtc, pipe_config);
9267
Imre Deak17290502016-02-12 18:55:11 +02009268 ret = true;
9269
9270out:
Chris Wilson0e6e0be2019-01-14 14:21:24 +00009271 intel_display_power_put(dev_priv, power_domain, wakeref);
Imre Deak17290502016-02-12 18:55:11 +02009272
9273 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009274}
9275
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009276static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9277{
Chris Wilson91c8a322016-07-05 10:40:23 +01009278 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009279 struct intel_crtc *crtc;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009280
Damien Lespiaud3fcc802014-05-13 23:32:22 +01009281 for_each_intel_crtc(dev, crtc)
Rob Clarke2c719b2014-12-15 13:56:32 -05009282 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009283 pipe_name(crtc->pipe));
9284
Imre Deak75e39682018-08-06 12:58:39 +03009285 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
Imre Deak9c3a16c2017-08-14 18:15:30 +03009286 "Display power well on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009287 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
Ville Syrjälä01403de2015-09-18 20:03:33 +03009288 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9289 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
Imre Deak44cb7342016-08-10 14:07:29 +03009290 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009291 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009292 "CPU PWM1 enabled\n");
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009293 if (IS_HASWELL(dev_priv))
Rob Clarke2c719b2014-12-15 13:56:32 -05009294 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
Paulo Zanonic5107b82014-07-04 11:50:30 -03009295 "CPU PWM2 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009296 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009297 "PCH PWM1 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009298 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009299 "Utility pin enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009300 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009301
Paulo Zanoni9926ada2014-04-01 19:39:47 -03009302 /*
9303 * In theory we can still leave IRQs enabled, as long as only the HPD
9304 * interrupts remain enabled. We used to check for that, but since it's
9305 * gen-specific and since we only disable LCPLL after we fully disable
9306 * the interrupts, the check below should be enough.
9307 */
Rob Clarke2c719b2014-12-15 13:56:32 -05009308 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009309}
9310
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009311static u32 hsw_read_dcomp(struct drm_i915_private *dev_priv)
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009312{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009313 if (IS_HASWELL(dev_priv))
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009314 return I915_READ(D_COMP_HSW);
9315 else
9316 return I915_READ(D_COMP_BDW);
9317}
9318
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009319static void hsw_write_dcomp(struct drm_i915_private *dev_priv, u32 val)
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009320{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009321 if (IS_HASWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009322 mutex_lock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009323 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9324 val))
Chris Wilson79cf2192016-08-24 11:16:07 +01009325 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009326 mutex_unlock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009327 } else {
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009328 I915_WRITE(D_COMP_BDW, val);
9329 POSTING_READ(D_COMP_BDW);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009330 }
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009331}
9332
9333/*
9334 * This function implements pieces of two sequences from BSpec:
9335 * - Sequence for display software to disable LCPLL
9336 * - Sequence for display software to allow package C8+
9337 * The steps implemented here are just the steps that actually touch the LCPLL
9338 * register. Callers should take care of disabling all the display engine
9339 * functions, doing the mode unset, fixing interrupts, etc.
9340 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009341static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9342 bool switch_to_fclk, bool allow_power_down)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009343{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009344 u32 val;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009345
9346 assert_can_disable_lcpll(dev_priv);
9347
9348 val = I915_READ(LCPLL_CTL);
9349
9350 if (switch_to_fclk) {
9351 val |= LCPLL_CD_SOURCE_FCLK;
9352 I915_WRITE(LCPLL_CTL, val);
9353
Imre Deakf53dd632016-06-28 13:37:32 +03009354 if (wait_for_us(I915_READ(LCPLL_CTL) &
9355 LCPLL_CD_SOURCE_FCLK_DONE, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009356 DRM_ERROR("Switching to FCLK failed\n");
9357
9358 val = I915_READ(LCPLL_CTL);
9359 }
9360
9361 val |= LCPLL_PLL_DISABLE;
9362 I915_WRITE(LCPLL_CTL, val);
9363 POSTING_READ(LCPLL_CTL);
9364
Chris Wilson24d84412016-06-30 15:33:07 +01009365 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009366 DRM_ERROR("LCPLL still locked\n");
9367
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009368 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009369 val |= D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009370 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009371 ndelay(100);
9372
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009373 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9374 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009375 DRM_ERROR("D_COMP RCOMP still in progress\n");
9376
9377 if (allow_power_down) {
9378 val = I915_READ(LCPLL_CTL);
9379 val |= LCPLL_POWER_DOWN_ALLOW;
9380 I915_WRITE(LCPLL_CTL, val);
9381 POSTING_READ(LCPLL_CTL);
9382 }
9383}
9384
9385/*
9386 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9387 * source.
9388 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009389static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009390{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009391 u32 val;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009392
9393 val = I915_READ(LCPLL_CTL);
9394
9395 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9396 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9397 return;
9398
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009399 /*
9400 * Make sure we're not on PC8 state before disabling PC8, otherwise
9401 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009402 */
Mika Kuoppala59bad942015-01-16 11:34:40 +02009403 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Paulo Zanoni215733f2013-08-19 13:18:07 -03009404
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009405 if (val & LCPLL_POWER_DOWN_ALLOW) {
9406 val &= ~LCPLL_POWER_DOWN_ALLOW;
9407 I915_WRITE(LCPLL_CTL, val);
Daniel Vetter35d8f2e2013-08-21 23:38:08 +02009408 POSTING_READ(LCPLL_CTL);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009409 }
9410
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009411 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009412 val |= D_COMP_COMP_FORCE;
9413 val &= ~D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009414 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009415
9416 val = I915_READ(LCPLL_CTL);
9417 val &= ~LCPLL_PLL_DISABLE;
9418 I915_WRITE(LCPLL_CTL, val);
9419
Chris Wilson93220c02016-06-30 15:33:08 +01009420 if (intel_wait_for_register(dev_priv,
9421 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9422 5))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009423 DRM_ERROR("LCPLL not locked yet\n");
9424
9425 if (val & LCPLL_CD_SOURCE_FCLK) {
9426 val = I915_READ(LCPLL_CTL);
9427 val &= ~LCPLL_CD_SOURCE_FCLK;
9428 I915_WRITE(LCPLL_CTL, val);
9429
Imre Deakf53dd632016-06-28 13:37:32 +03009430 if (wait_for_us((I915_READ(LCPLL_CTL) &
9431 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009432 DRM_ERROR("Switching back to LCPLL failed\n");
9433 }
Paulo Zanoni215733f2013-08-19 13:18:07 -03009434
Mika Kuoppala59bad942015-01-16 11:34:40 +02009435 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009436
Ville Syrjälä4c75b942016-10-31 22:37:12 +02009437 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009438 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009439}
9440
Paulo Zanoni765dab672014-03-07 20:08:18 -03009441/*
9442 * Package states C8 and deeper are really deep PC states that can only be
9443 * reached when all the devices on the system allow it, so even if the graphics
9444 * device allows PC8+, it doesn't mean the system will actually get to these
9445 * states. Our driver only allows PC8+ when going into runtime PM.
9446 *
9447 * The requirements for PC8+ are that all the outputs are disabled, the power
9448 * well is disabled and most interrupts are disabled, and these are also
9449 * requirements for runtime PM. When these conditions are met, we manually do
9450 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9451 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9452 * hang the machine.
9453 *
9454 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9455 * the state of some registers, so when we come back from PC8+ we need to
9456 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9457 * need to take care of the registers kept by RC6. Notice that this happens even
9458 * if we don't put the device in PCI D3 state (which is what currently happens
9459 * because of the runtime PM support).
9460 *
9461 * For more, read "Display Sequences for Package C8" on the hardware
9462 * documentation.
9463 */
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009464void hsw_enable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009465{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009466 u32 val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03009467
Paulo Zanonic67a4702013-08-19 13:18:09 -03009468 DRM_DEBUG_KMS("Enabling package C8+\n");
9469
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009470 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009471 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9472 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9473 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9474 }
9475
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009476 lpt_disable_clkout_dp(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009477 hsw_disable_lcpll(dev_priv, true, true);
9478}
9479
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009480void hsw_disable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009481{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009482 u32 val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03009483
Paulo Zanonic67a4702013-08-19 13:18:09 -03009484 DRM_DEBUG_KMS("Disabling package C8+\n");
9485
9486 hsw_restore_lcpll(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009487 lpt_init_pch_refclk(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009488
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009489 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009490 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9491 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9492 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9493 }
Paulo Zanonic67a4702013-08-19 13:18:09 -03009494}
9495
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02009496static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9497 struct intel_crtc_state *crtc_state)
Paulo Zanoni09b4ddf2012-10-05 12:05:55 -03009498{
Madhav Chauhan70a057b2018-11-29 16:12:18 +02009499 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009500 struct intel_atomic_state *state =
9501 to_intel_atomic_state(crtc_state->base.state);
9502
Madhav Chauhan70a057b2018-11-29 16:12:18 +02009503 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
9504 IS_ICELAKE(dev_priv)) {
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009505 struct intel_encoder *encoder =
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009506 intel_get_crtc_new_encoder(state, crtc_state);
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009507
9508 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
Chris Wilson43031782018-09-13 14:16:26 +01009509 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9510 pipe_name(crtc->pipe));
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009511 return -EINVAL;
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009512 }
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009513 }
Daniel Vetter716c2e52014-06-25 22:02:02 +03009514
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02009515 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009516}
9517
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009518static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9519 enum port port,
9520 struct intel_crtc_state *pipe_config)
9521{
9522 enum intel_dpll_id id;
9523 u32 temp;
9524
9525 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
Paulo Zanonidfbd4502017-08-25 16:40:04 -03009526 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009527
9528 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9529 return;
9530
9531 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9532}
9533
Paulo Zanoni970888e2018-05-21 17:25:44 -07009534static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9535 enum port port,
9536 struct intel_crtc_state *pipe_config)
9537{
9538 enum intel_dpll_id id;
9539 u32 temp;
9540
9541 /* TODO: TBT pll not implemented. */
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309542 if (intel_port_is_combophy(dev_priv, port)) {
Paulo Zanoni970888e2018-05-21 17:25:44 -07009543 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9544 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9545 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9546
Vandita Kulkarnia54270d2018-10-03 12:52:00 +05309547 if (WARN_ON(!intel_dpll_is_combophy(id)))
Paulo Zanoni970888e2018-05-21 17:25:44 -07009548 return;
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309549 } else if (intel_port_is_tc(dev_priv, port)) {
Lucas De Marchi584fca12019-01-25 14:24:41 -08009550 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv, port));
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309551 } else {
9552 WARN(1, "Invalid port %x\n", port);
Paulo Zanoni970888e2018-05-21 17:25:44 -07009553 return;
9554 }
9555
9556 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9557}
9558
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309559static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9560 enum port port,
9561 struct intel_crtc_state *pipe_config)
9562{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009563 enum intel_dpll_id id;
9564
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309565 switch (port) {
9566 case PORT_A:
Imre Deak08250c42016-03-14 19:55:34 +02009567 id = DPLL_ID_SKL_DPLL0;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309568 break;
9569 case PORT_B:
Imre Deak08250c42016-03-14 19:55:34 +02009570 id = DPLL_ID_SKL_DPLL1;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309571 break;
9572 case PORT_C:
Imre Deak08250c42016-03-14 19:55:34 +02009573 id = DPLL_ID_SKL_DPLL2;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309574 break;
9575 default:
9576 DRM_ERROR("Incorrect port type\n");
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009577 return;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309578 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009579
9580 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309581}
9582
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009583static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9584 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009585 struct intel_crtc_state *pipe_config)
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009586{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009587 enum intel_dpll_id id;
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +02009588 u32 temp;
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009589
9590 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009591 id = temp >> (port * 3 + 1);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009592
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009593 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009594 return;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009595
9596 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009597}
9598
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009599static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9600 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009601 struct intel_crtc_state *pipe_config)
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009602{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009603 enum intel_dpll_id id;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009604 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009605
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009606 switch (ddi_pll_sel) {
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009607 case PORT_CLK_SEL_WRPLL1:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009608 id = DPLL_ID_WRPLL1;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009609 break;
9610 case PORT_CLK_SEL_WRPLL2:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009611 id = DPLL_ID_WRPLL2;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009612 break;
Maarten Lankhorst00490c22015-11-16 14:42:12 +01009613 case PORT_CLK_SEL_SPLL:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009614 id = DPLL_ID_SPLL;
Ville Syrjälä79bd23d2015-12-01 23:32:07 +02009615 break;
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +02009616 case PORT_CLK_SEL_LCPLL_810:
9617 id = DPLL_ID_LCPLL_810;
9618 break;
9619 case PORT_CLK_SEL_LCPLL_1350:
9620 id = DPLL_ID_LCPLL_1350;
9621 break;
9622 case PORT_CLK_SEL_LCPLL_2700:
9623 id = DPLL_ID_LCPLL_2700;
9624 break;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009625 default:
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009626 MISSING_CASE(ddi_pll_sel);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009627 /* fall through */
9628 case PORT_CLK_SEL_NONE:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009629 return;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009630 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009631
9632 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009633}
9634
Jani Nikulacf304292016-03-18 17:05:41 +02009635static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9636 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009637 u64 *power_domain_mask)
Jani Nikulacf304292016-03-18 17:05:41 +02009638{
9639 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009640 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulacf304292016-03-18 17:05:41 +02009641 enum intel_display_power_domain power_domain;
Jani Nikula07169312018-12-04 12:19:26 +02009642 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
9643 unsigned long enabled_panel_transcoders = 0;
9644 enum transcoder panel_transcoder;
Jani Nikulacf304292016-03-18 17:05:41 +02009645 u32 tmp;
Jani Nikula07169312018-12-04 12:19:26 +02009646
9647 if (IS_ICELAKE(dev_priv))
9648 panel_transcoder_mask |=
9649 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
Jani Nikulacf304292016-03-18 17:05:41 +02009650
Imre Deakd9a7bc62016-05-12 16:18:50 +03009651 /*
9652 * The pipe->transcoder mapping is fixed with the exception of the eDP
Jani Nikula07169312018-12-04 12:19:26 +02009653 * and DSI transcoders handled below.
Imre Deakd9a7bc62016-05-12 16:18:50 +03009654 */
Jani Nikulacf304292016-03-18 17:05:41 +02009655 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9656
9657 /*
9658 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9659 * consistency and less surprising code; it's in always on power).
9660 */
Chris Wilson1b4bd5c2019-01-16 15:54:21 +00009661 for_each_set_bit(panel_transcoder,
9662 &panel_transcoder_mask,
9663 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009664 enum pipe trans_pipe;
Jani Nikula07169312018-12-04 12:19:26 +02009665
9666 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
9667 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
9668 continue;
9669
9670 /*
9671 * Log all enabled ones, only use the first one.
9672 *
9673 * FIXME: This won't work for two separate DSI displays.
9674 */
9675 enabled_panel_transcoders |= BIT(panel_transcoder);
9676 if (enabled_panel_transcoders != BIT(panel_transcoder))
9677 continue;
9678
Jani Nikulacf304292016-03-18 17:05:41 +02009679 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9680 default:
Jani Nikula07169312018-12-04 12:19:26 +02009681 WARN(1, "unknown pipe linked to transcoder %s\n",
9682 transcoder_name(panel_transcoder));
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05009683 /* fall through */
Jani Nikulacf304292016-03-18 17:05:41 +02009684 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9685 case TRANS_DDI_EDP_INPUT_A_ON:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009686 trans_pipe = PIPE_A;
Jani Nikulacf304292016-03-18 17:05:41 +02009687 break;
9688 case TRANS_DDI_EDP_INPUT_B_ONOFF:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009689 trans_pipe = PIPE_B;
Jani Nikulacf304292016-03-18 17:05:41 +02009690 break;
9691 case TRANS_DDI_EDP_INPUT_C_ONOFF:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009692 trans_pipe = PIPE_C;
Jani Nikulacf304292016-03-18 17:05:41 +02009693 break;
9694 }
9695
Jani Nikula07169312018-12-04 12:19:26 +02009696 if (trans_pipe == crtc->pipe)
9697 pipe_config->cpu_transcoder = panel_transcoder;
Jani Nikulacf304292016-03-18 17:05:41 +02009698 }
9699
Jani Nikula07169312018-12-04 12:19:26 +02009700 /*
9701 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
9702 */
9703 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
9704 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
9705
Jani Nikulacf304292016-03-18 17:05:41 +02009706 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9707 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9708 return false;
Chris Wilson04161d62019-01-14 14:21:27 +00009709
9710 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009711 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikulacf304292016-03-18 17:05:41 +02009712
9713 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9714
9715 return tmp & PIPECONF_ENABLE;
9716}
9717
Jani Nikula4d1de972016-03-18 17:05:42 +02009718static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9719 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009720 u64 *power_domain_mask)
Jani Nikula4d1de972016-03-18 17:05:42 +02009721{
9722 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009723 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikula4d1de972016-03-18 17:05:42 +02009724 enum intel_display_power_domain power_domain;
9725 enum port port;
9726 enum transcoder cpu_transcoder;
9727 u32 tmp;
9728
Jani Nikula4d1de972016-03-18 17:05:42 +02009729 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9730 if (port == PORT_A)
9731 cpu_transcoder = TRANSCODER_DSI_A;
9732 else
9733 cpu_transcoder = TRANSCODER_DSI_C;
9734
9735 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9736 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9737 continue;
Chris Wilson04161d62019-01-14 14:21:27 +00009738
9739 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009740 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikula4d1de972016-03-18 17:05:42 +02009741
Imre Deakdb18b6a2016-03-24 12:41:40 +02009742 /*
9743 * The PLL needs to be enabled with a valid divider
9744 * configuration, otherwise accessing DSI registers will hang
9745 * the machine. See BSpec North Display Engine
9746 * registers/MIPI[BXT]. We can break out here early, since we
9747 * need the same DSI PLL to be enabled for both DSI ports.
9748 */
Jani Nikulae5186342018-07-05 16:25:08 +03009749 if (!bxt_dsi_pll_is_enabled(dev_priv))
Imre Deakdb18b6a2016-03-24 12:41:40 +02009750 break;
9751
Jani Nikula4d1de972016-03-18 17:05:42 +02009752 /* XXX: this works for video mode only */
9753 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9754 if (!(tmp & DPI_ENABLE))
9755 continue;
9756
9757 tmp = I915_READ(MIPI_CTRL(port));
9758 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9759 continue;
9760
9761 pipe_config->cpu_transcoder = cpu_transcoder;
Jani Nikula4d1de972016-03-18 17:05:42 +02009762 break;
9763 }
9764
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009765 return transcoder_is_dsi(pipe_config->cpu_transcoder);
Jani Nikula4d1de972016-03-18 17:05:42 +02009766}
9767
Daniel Vetter26804af2014-06-25 22:01:55 +03009768static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009769 struct intel_crtc_state *pipe_config)
Daniel Vetter26804af2014-06-25 22:01:55 +03009770{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009771 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009772 struct intel_shared_dpll *pll;
Daniel Vetter26804af2014-06-25 22:01:55 +03009773 enum port port;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009774 u32 tmp;
Daniel Vetter26804af2014-06-25 22:01:55 +03009775
9776 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9777
9778 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9779
Paulo Zanoni970888e2018-05-21 17:25:44 -07009780 if (IS_ICELAKE(dev_priv))
9781 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9782 else if (IS_CANNONLAKE(dev_priv))
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009783 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9784 else if (IS_GEN9_BC(dev_priv))
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009785 skylake_get_ddi_pll(dev_priv, port, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009786 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309787 bxt_get_ddi_pll(dev_priv, port, pipe_config);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009788 else
9789 haswell_get_ddi_pll(dev_priv, port, pipe_config);
Daniel Vetter9cd86932014-06-25 22:01:57 +03009790
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009791 pll = pipe_config->shared_dpll;
9792 if (pll) {
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009793 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9794 &pipe_config->dpll_hw_state));
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009795 }
9796
Daniel Vetter26804af2014-06-25 22:01:55 +03009797 /*
9798 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9799 * DDI E. So just check whether this pipe is wired to DDI E and whether
9800 * the PCH transcoder is on.
9801 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009802 if (INTEL_GEN(dev_priv) < 9 &&
Damien Lespiauca370452013-12-03 13:56:24 +00009803 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
Daniel Vetter26804af2014-06-25 22:01:55 +03009804 pipe_config->has_pch_encoder = true;
9805
9806 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9807 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9808 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9809
9810 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9811 }
9812}
9813
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009814static bool haswell_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009815 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009816{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009817 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02009818 enum intel_display_power_domain power_domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009819 u64 power_domain_mask;
Jani Nikulacf304292016-03-18 17:05:41 +02009820 bool active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009821
Imre Deake79dfb52017-07-20 01:50:57 +03009822 intel_crtc_init_scalers(crtc, pipe_config);
Imre Deak5fb9dad2017-07-20 14:28:20 +03009823
Imre Deak17290502016-02-12 18:55:11 +02009824 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9825 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02009826 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009827 power_domain_mask = BIT_ULL(power_domain);
Imre Deak17290502016-02-12 18:55:11 +02009828
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009829 pipe_config->shared_dpll = NULL;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009830
Jani Nikulacf304292016-03-18 17:05:41 +02009831 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
Daniel Vettereccb1402013-05-22 00:50:22 +02009832
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009833 if (IS_GEN9_LP(dev_priv) &&
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009834 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9835 WARN_ON(active);
9836 active = true;
Jani Nikula4d1de972016-03-18 17:05:42 +02009837 }
9838
Jani Nikulacf304292016-03-18 17:05:41 +02009839 if (!active)
Imre Deak17290502016-02-12 18:55:11 +02009840 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009841
Madhav Chauhan2eae5d62018-11-29 16:12:28 +02009842 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
9843 IS_ICELAKE(dev_priv)) {
Jani Nikula4d1de972016-03-18 17:05:42 +02009844 haswell_get_ddi_port_state(crtc, pipe_config);
9845 intel_get_pipe_timings(crtc, pipe_config);
9846 }
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009847
Jani Nikulabc58be62016-03-18 17:05:39 +02009848 intel_get_pipe_src_size(crtc, pipe_config);
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05309849 intel_get_crtc_ycbcr_config(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009850
Lionel Landwerlin05dc6982016-03-16 10:57:15 +00009851 pipe_config->gamma_mode =
9852 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9853
Imre Deak17290502016-02-12 18:55:11 +02009854 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9855 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Chris Wilson04161d62019-01-14 14:21:27 +00009856 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009857 power_domain_mask |= BIT_ULL(power_domain);
Chris Wilson04161d62019-01-14 14:21:27 +00009858
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009859 if (INTEL_GEN(dev_priv) >= 9)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009860 skylake_get_pfit_config(crtc, pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08009861 else
Rodrigo Vivi1c132b42015-09-02 15:19:26 -07009862 ironlake_get_pfit_config(crtc, pipe_config);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009863 }
Daniel Vetter88adfff2013-03-28 10:42:01 +01009864
Maarten Lankhorst24f28452017-11-22 19:39:01 +01009865 if (hsw_crtc_supports_ips(crtc)) {
9866 if (IS_HASWELL(dev_priv))
9867 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9868 else {
9869 /*
9870 * We cannot readout IPS state on broadwell, set to
9871 * true so we can set it to a defined state on first
9872 * commit.
9873 */
9874 pipe_config->ips_enabled = true;
9875 }
9876 }
9877
Jani Nikula4d1de972016-03-18 17:05:42 +02009878 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9879 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
Clint Taylorebb69c92014-09-30 10:30:22 -07009880 pipe_config->pixel_multiplier =
9881 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9882 } else {
9883 pipe_config->pixel_multiplier = 1;
9884 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02009885
Imre Deak17290502016-02-12 18:55:11 +02009886out:
9887 for_each_power_domain(power_domain, power_domain_mask)
Chris Wilson0e6e0be2019-01-14 14:21:24 +00009888 intel_display_power_put_unchecked(dev_priv, power_domain);
Imre Deak17290502016-02-12 18:55:11 +02009889
Jani Nikulacf304292016-03-18 17:05:41 +02009890 return active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009891}
9892
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009893static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009894{
9895 struct drm_i915_private *dev_priv =
9896 to_i915(plane_state->base.plane->dev);
9897 const struct drm_framebuffer *fb = plane_state->base.fb;
9898 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9899 u32 base;
9900
José Roberto de Souzad53db442018-11-30 15:20:48 -08009901 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009902 base = obj->phys_handle->busaddr;
9903 else
9904 base = intel_plane_ggtt_offset(plane_state);
9905
Ville Syrjäläc11ada02018-09-07 18:24:04 +03009906 base += plane_state->color_plane[0].offset;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009907
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009908 /* ILK+ do this automagically */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08009909 if (HAS_GMCH(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +10009910 plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009911 base += (plane_state->base.crtc_h *
9912 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9913
9914 return base;
9915}
9916
Ville Syrjäläed270222017-03-27 21:55:36 +03009917static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9918{
9919 int x = plane_state->base.crtc_x;
9920 int y = plane_state->base.crtc_y;
9921 u32 pos = 0;
9922
9923 if (x < 0) {
9924 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9925 x = -x;
9926 }
9927 pos |= x << CURSOR_X_SHIFT;
9928
9929 if (y < 0) {
9930 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9931 y = -y;
9932 }
9933 pos |= y << CURSOR_Y_SHIFT;
9934
9935 return pos;
9936}
9937
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009938static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9939{
9940 const struct drm_mode_config *config =
9941 &plane_state->base.plane->dev->mode_config;
9942 int width = plane_state->base.crtc_w;
9943 int height = plane_state->base.crtc_h;
9944
9945 return width > 0 && width <= config->cursor_width &&
9946 height > 0 && height <= config->cursor_height;
9947}
9948
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009949static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009950{
9951 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009952 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009953 int src_x, src_y;
9954 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009955 int ret;
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009956
9957 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
9958 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
9959
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009960 ret = intel_plane_check_stride(plane_state);
9961 if (ret)
9962 return ret;
9963
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009964 src_x = plane_state->base.src_x >> 16;
9965 src_y = plane_state->base.src_y >> 16;
9966
9967 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9968 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
9969 plane_state, 0);
9970
9971 if (src_x != 0 || src_y != 0) {
9972 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9973 return -EINVAL;
9974 }
9975
9976 plane_state->color_plane[0].offset = offset;
9977
9978 return 0;
9979}
9980
9981static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9982 struct intel_plane_state *plane_state)
9983{
9984 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009985 int ret;
9986
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009987 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9988 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9989 return -EINVAL;
9990 }
9991
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009992 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9993 &crtc_state->base,
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009994 DRM_PLANE_HELPER_NO_SCALING,
9995 DRM_PLANE_HELPER_NO_SCALING,
9996 true, true);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009997 if (ret)
9998 return ret;
9999
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030010000 if (!plane_state->base.visible)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010001 return 0;
10002
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030010003 ret = intel_plane_check_src_coordinates(plane_state);
10004 if (ret)
10005 return ret;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010006
Ville Syrjäläfce8d232018-09-07 18:24:13 +030010007 ret = intel_cursor_check_surface(plane_state);
10008 if (ret)
10009 return ret;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +030010010
Ville Syrjälä659056f2017-03-27 21:55:39 +030010011 return 0;
10012}
10013
Ville Syrjäläddd57132018-09-07 18:24:02 +030010014static unsigned int
10015i845_cursor_max_stride(struct intel_plane *plane,
10016 u32 pixel_format, u64 modifier,
10017 unsigned int rotation)
10018{
10019 return 2048;
10020}
10021
Ville Syrjälä7eb31a02019-02-05 18:08:36 +020010022static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10023{
10024 return CURSOR_GAMMA_ENABLE;
10025}
10026
Ville Syrjälä292889e2017-03-17 23:18:01 +020010027static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
10028 const struct intel_plane_state *plane_state)
10029{
Ville Syrjälä292889e2017-03-17 23:18:01 +020010030 return CURSOR_ENABLE |
Ville Syrjälä292889e2017-03-17 23:18:01 +020010031 CURSOR_FORMAT_ARGB |
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010032 CURSOR_STRIDE(plane_state->color_plane[0].stride);
Ville Syrjälä292889e2017-03-17 23:18:01 +020010033}
10034
Ville Syrjälä659056f2017-03-27 21:55:39 +030010035static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
10036{
Ville Syrjälä659056f2017-03-27 21:55:39 +030010037 int width = plane_state->base.crtc_w;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010038
10039 /*
10040 * 845g/865g are only limited by the width of their cursors,
10041 * the height is arbitrary up to the precision of the register.
10042 */
Ville Syrjälä3637ecf2017-03-27 21:55:40 +030010043 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010044}
10045
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010046static int i845_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +030010047 struct intel_plane_state *plane_state)
10048{
10049 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010050 int ret;
10051
10052 ret = intel_check_cursor(crtc_state, plane_state);
10053 if (ret)
10054 return ret;
10055
10056 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010057 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010058 return 0;
10059
10060 /* Check for which cursor types we support */
10061 if (!i845_cursor_size_ok(plane_state)) {
10062 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10063 plane_state->base.crtc_w,
10064 plane_state->base.crtc_h);
10065 return -EINVAL;
10066 }
10067
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010068 WARN_ON(plane_state->base.visible &&
10069 plane_state->color_plane[0].stride != fb->pitches[0]);
10070
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010071 switch (fb->pitches[0]) {
Chris Wilson560b85b2010-08-07 11:01:38 +010010072 case 256:
10073 case 512:
10074 case 1024:
10075 case 2048:
Ville Syrjälädc41c152014-08-13 11:57:05 +030010076 break;
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010077 default:
10078 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
10079 fb->pitches[0]);
10080 return -EINVAL;
Chris Wilson560b85b2010-08-07 11:01:38 +010010081 }
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +010010082
Ville Syrjälä659056f2017-03-27 21:55:39 +030010083 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
10084
10085 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080010086}
10087
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010088static void i845_update_cursor(struct intel_plane *plane,
10089 const struct intel_crtc_state *crtc_state,
Chris Wilson560b85b2010-08-07 11:01:38 +010010090 const struct intel_plane_state *plane_state)
10091{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030010092 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010093 u32 cntl = 0, base = 0, pos = 0, size = 0;
10094 unsigned long irqflags;
Chris Wilson560b85b2010-08-07 11:01:38 +010010095
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010096 if (plane_state && plane_state->base.visible) {
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +010010097 unsigned int width = plane_state->base.crtc_w;
10098 unsigned int height = plane_state->base.crtc_h;
Ville Syrjälädc41c152014-08-13 11:57:05 +030010099
Ville Syrjälä7eb31a02019-02-05 18:08:36 +020010100 cntl = plane_state->ctl |
10101 i845_cursor_ctl_crtc(crtc_state);
10102
Ville Syrjälädc41c152014-08-13 11:57:05 +030010103 size = (height << 12) | width;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010104
10105 base = intel_cursor_base(plane_state);
10106 pos = intel_cursor_position(plane_state);
Chris Wilson4b0e3332014-05-30 16:35:26 +030010107 }
Chris Wilson560b85b2010-08-07 11:01:38 +010010108
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010109 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10110
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010111 /* On these chipsets we can only modify the base/size/stride
10112 * whilst the cursor is disabled.
10113 */
10114 if (plane->cursor.base != base ||
10115 plane->cursor.size != size ||
10116 plane->cursor.cntl != cntl) {
Ville Syrjälädd584fc2017-03-09 17:44:33 +020010117 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +020010118 I915_WRITE_FW(CURBASE(PIPE_A), base);
Ville Syrjälädd584fc2017-03-09 17:44:33 +020010119 I915_WRITE_FW(CURSIZE, size);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010120 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädd584fc2017-03-09 17:44:33 +020010121 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
Ville Syrjälä75343a42017-03-27 21:55:38 +030010122
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010123 plane->cursor.base = base;
10124 plane->cursor.size = size;
10125 plane->cursor.cntl = cntl;
10126 } else {
10127 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädc41c152014-08-13 11:57:05 +030010128 }
10129
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010130 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10131}
10132
10133static void i845_disable_cursor(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010134 const struct intel_crtc_state *crtc_state)
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010135{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010136 i845_update_cursor(plane, crtc_state, NULL);
Chris Wilson560b85b2010-08-07 11:01:38 +010010137}
10138
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010139static bool i845_cursor_get_hw_state(struct intel_plane *plane,
10140 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010141{
10142 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10143 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010144 intel_wakeref_t wakeref;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010145 bool ret;
10146
10147 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010148 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10149 if (!wakeref)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010150 return false;
10151
10152 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
10153
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010154 *pipe = PIPE_A;
10155
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010156 intel_display_power_put(dev_priv, power_domain, wakeref);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010157
10158 return ret;
10159}
10160
Ville Syrjäläddd57132018-09-07 18:24:02 +030010161static unsigned int
10162i9xx_cursor_max_stride(struct intel_plane *plane,
10163 u32 pixel_format, u64 modifier,
10164 unsigned int rotation)
10165{
10166 return plane->base.dev->mode_config.cursor_width * 4;
10167}
10168
Ville Syrjälä7eb31a02019-02-05 18:08:36 +020010169static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10170{
10171 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10172 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10173 u32 cntl = 0;
10174
10175 if (INTEL_GEN(dev_priv) >= 11)
10176 return cntl;
10177
10178 cntl |= MCURSOR_GAMMA_ENABLE;
10179
10180 if (HAS_DDI(dev_priv))
10181 cntl |= MCURSOR_PIPE_CSC_ENABLE;
10182
10183 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10184 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
10185
10186 return cntl;
10187}
10188
Ville Syrjälä292889e2017-03-17 23:18:01 +020010189static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
10190 const struct intel_plane_state *plane_state)
10191{
10192 struct drm_i915_private *dev_priv =
10193 to_i915(plane_state->base.plane->dev);
José Roberto de Souzac894d632018-05-18 13:15:47 -070010194 u32 cntl = 0;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010195
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010196 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
Ville Syrjäläe876b782018-01-30 22:38:05 +020010197 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10198
Ville Syrjälä292889e2017-03-17 23:18:01 +020010199 switch (plane_state->base.crtc_w) {
10200 case 64:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010201 cntl |= MCURSOR_MODE_64_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010202 break;
10203 case 128:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010204 cntl |= MCURSOR_MODE_128_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010205 break;
10206 case 256:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010207 cntl |= MCURSOR_MODE_256_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010208 break;
10209 default:
10210 MISSING_CASE(plane_state->base.crtc_w);
10211 return 0;
10212 }
10213
Robert Fossc2c446a2017-05-19 16:50:17 -040010214 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010215 cntl |= MCURSOR_ROTATE_180;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010216
10217 return cntl;
10218}
10219
Ville Syrjälä659056f2017-03-27 21:55:39 +030010220static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
Chris Wilson560b85b2010-08-07 11:01:38 +010010221{
Ville Syrjälä024faac2017-03-27 21:55:42 +030010222 struct drm_i915_private *dev_priv =
10223 to_i915(plane_state->base.plane->dev);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010224 int width = plane_state->base.crtc_w;
10225 int height = plane_state->base.crtc_h;
Chris Wilson560b85b2010-08-07 11:01:38 +010010226
Ville Syrjälä3637ecf2017-03-27 21:55:40 +030010227 if (!intel_cursor_size_ok(plane_state))
Ville Syrjälädc41c152014-08-13 11:57:05 +030010228 return false;
10229
Ville Syrjälä024faac2017-03-27 21:55:42 +030010230 /* Cursor width is limited to a few power-of-two sizes */
10231 switch (width) {
Ville Syrjälä659056f2017-03-27 21:55:39 +030010232 case 256:
10233 case 128:
Ville Syrjälä659056f2017-03-27 21:55:39 +030010234 case 64:
10235 break;
10236 default:
10237 return false;
10238 }
10239
Ville Syrjälädc41c152014-08-13 11:57:05 +030010240 /*
Ville Syrjälä024faac2017-03-27 21:55:42 +030010241 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10242 * height from 8 lines up to the cursor width, when the
10243 * cursor is not rotated. Everything else requires square
10244 * cursors.
Ville Syrjälädc41c152014-08-13 11:57:05 +030010245 */
Ville Syrjälä024faac2017-03-27 21:55:42 +030010246 if (HAS_CUR_FBC(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +100010247 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
Ville Syrjälä024faac2017-03-27 21:55:42 +030010248 if (height < 8 || height > width)
Ville Syrjälädc41c152014-08-13 11:57:05 +030010249 return false;
10250 } else {
Ville Syrjälä024faac2017-03-27 21:55:42 +030010251 if (height != width)
Ville Syrjälädc41c152014-08-13 11:57:05 +030010252 return false;
Ville Syrjälädc41c152014-08-13 11:57:05 +030010253 }
10254
10255 return true;
10256}
10257
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010258static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +030010259 struct intel_plane_state *plane_state)
10260{
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010261 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010262 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10263 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010264 enum pipe pipe = plane->pipe;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010265 int ret;
10266
10267 ret = intel_check_cursor(crtc_state, plane_state);
10268 if (ret)
10269 return ret;
10270
10271 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010272 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010273 return 0;
10274
10275 /* Check for which cursor types we support */
10276 if (!i9xx_cursor_size_ok(plane_state)) {
10277 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10278 plane_state->base.crtc_w,
10279 plane_state->base.crtc_h);
10280 return -EINVAL;
10281 }
10282
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010283 WARN_ON(plane_state->base.visible &&
10284 plane_state->color_plane[0].stride != fb->pitches[0]);
10285
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010286 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10287 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10288 fb->pitches[0], plane_state->base.crtc_w);
10289 return -EINVAL;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010290 }
10291
10292 /*
10293 * There's something wrong with the cursor on CHV pipe C.
10294 * If it straddles the left edge of the screen then
10295 * moving it away from the edge or disabling it often
10296 * results in a pipe underrun, and often that can lead to
10297 * dead pipe (constant underrun reported, and it scans
10298 * out just a solid color). To recover from that, the
10299 * display power well must be turned off and on again.
10300 * Refuse the put the cursor into that compromised position.
10301 */
10302 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10303 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10304 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10305 return -EINVAL;
10306 }
10307
10308 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10309
10310 return 0;
10311}
10312
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010313static void i9xx_update_cursor(struct intel_plane *plane,
10314 const struct intel_crtc_state *crtc_state,
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010315 const struct intel_plane_state *plane_state)
10316{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030010317 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10318 enum pipe pipe = plane->pipe;
Ville Syrjälä024faac2017-03-27 21:55:42 +030010319 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010320 unsigned long irqflags;
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010321
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010322 if (plane_state && plane_state->base.visible) {
Ville Syrjälä7eb31a02019-02-05 18:08:36 +020010323 cntl = plane_state->ctl |
10324 i9xx_cursor_ctl_crtc(crtc_state);
Chris Wilson4b0e3332014-05-30 16:35:26 +030010325
Ville Syrjälä024faac2017-03-27 21:55:42 +030010326 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10327 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10328
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010329 base = intel_cursor_base(plane_state);
10330 pos = intel_cursor_position(plane_state);
10331 }
10332
10333 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10334
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010335 /*
10336 * On some platforms writing CURCNTR first will also
10337 * cause CURPOS to be armed by the CURBASE write.
10338 * Without the CURCNTR write the CURPOS write would
Ville Syrjälä83234d12018-11-14 23:07:17 +020010339 * arm itself. Thus we always update CURCNTR before
10340 * CURPOS.
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010341 *
10342 * On other platforms CURPOS always requires the
10343 * CURBASE write to arm the update. Additonally
10344 * a write to any of the cursor register will cancel
10345 * an already armed cursor update. Thus leaving out
10346 * the CURBASE write after CURPOS could lead to a
10347 * cursor that doesn't appear to move, or even change
10348 * shape. Thus we always write CURBASE.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010349 *
Ville Syrjälä83234d12018-11-14 23:07:17 +020010350 * The other registers are armed by by the CURBASE write
10351 * except when the plane is getting enabled at which time
10352 * the CURCNTR write arms the update.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010353 */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020010354
10355 if (INTEL_GEN(dev_priv) >= 9)
10356 skl_write_cursor_wm(plane, crtc_state);
10357
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010358 if (plane->cursor.base != base ||
Ville Syrjälä024faac2017-03-27 21:55:42 +030010359 plane->cursor.size != fbc_ctl ||
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010360 plane->cursor.cntl != cntl) {
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010361 if (HAS_CUR_FBC(dev_priv))
10362 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
Ville Syrjälä83234d12018-11-14 23:07:17 +020010363 I915_WRITE_FW(CURCNTR(pipe), cntl);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010364 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä75343a42017-03-27 21:55:38 +030010365 I915_WRITE_FW(CURBASE(pipe), base);
10366
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010367 plane->cursor.base = base;
10368 plane->cursor.size = fbc_ctl;
10369 plane->cursor.cntl = cntl;
10370 } else {
10371 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010372 I915_WRITE_FW(CURBASE(pipe), base);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010373 }
10374
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010375 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes65a21cd2011-10-12 11:10:21 -070010376}
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030010377
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010378static void i9xx_disable_cursor(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010379 const struct intel_crtc_state *crtc_state)
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010380{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010381 i9xx_update_cursor(plane, crtc_state, NULL);
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010382}
Ville Syrjäläd6e4db12013-09-04 18:25:31 +030010383
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010384static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10385 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010386{
10387 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10388 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010389 intel_wakeref_t wakeref;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010390 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010391 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010392
10393 /*
10394 * Not 100% correct for planes that can move between pipes,
10395 * but that's only the case for gen2-3 which don't have any
10396 * display power wells.
10397 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010398 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010399 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10400 if (!wakeref)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010401 return false;
10402
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010403 val = I915_READ(CURCNTR(plane->pipe));
10404
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010405 ret = val & MCURSOR_MODE;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010406
10407 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10408 *pipe = plane->pipe;
10409 else
10410 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10411 MCURSOR_PIPE_SELECT_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010412
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010413 intel_display_power_put(dev_priv, power_domain, wakeref);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010414
10415 return ret;
10416}
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010417
Jesse Barnes79e53942008-11-07 14:24:08 -080010418/* VESA 640x480x72Hz mode to set on the pipe */
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010419static const struct drm_display_mode load_detect_mode = {
Jesse Barnes79e53942008-11-07 14:24:08 -080010420 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10421 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10422};
10423
Daniel Vettera8bb6812014-02-10 18:00:39 +010010424struct drm_framebuffer *
Chris Wilson24dbf512017-02-15 10:59:18 +000010425intel_framebuffer_create(struct drm_i915_gem_object *obj,
10426 struct drm_mode_fb_cmd2 *mode_cmd)
Chris Wilsond2dff872011-04-19 08:36:26 +010010427{
10428 struct intel_framebuffer *intel_fb;
10429 int ret;
10430
10431 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010432 if (!intel_fb)
Chris Wilsond2dff872011-04-19 08:36:26 +010010433 return ERR_PTR(-ENOMEM);
Chris Wilsond2dff872011-04-19 08:36:26 +010010434
Chris Wilson24dbf512017-02-15 10:59:18 +000010435 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010436 if (ret)
10437 goto err;
Chris Wilsond2dff872011-04-19 08:36:26 +010010438
10439 return &intel_fb->base;
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010440
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010441err:
10442 kfree(intel_fb);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010443 return ERR_PTR(ret);
Chris Wilsond2dff872011-04-19 08:36:26 +010010444}
10445
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010446static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10447 struct drm_crtc *crtc)
Chris Wilsond2dff872011-04-19 08:36:26 +010010448{
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010449 struct drm_plane *plane;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010450 struct drm_plane_state *plane_state;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010451 int ret, i;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010452
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010453 ret = drm_atomic_add_affected_planes(state, crtc);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010454 if (ret)
10455 return ret;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010456
10457 for_each_new_plane_in_state(state, plane, plane_state, i) {
10458 if (plane_state->crtc != crtc)
10459 continue;
10460
10461 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10462 if (ret)
10463 return ret;
10464
10465 drm_atomic_set_fb_for_plane(plane_state, NULL);
10466 }
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010467
10468 return 0;
10469}
10470
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010471int intel_get_load_detect_pipe(struct drm_connector *connector,
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010472 const struct drm_display_mode *mode,
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010473 struct intel_load_detect_pipe *old,
10474 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010475{
10476 struct intel_crtc *intel_crtc;
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010477 struct intel_encoder *intel_encoder =
10478 intel_attached_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -080010479 struct drm_crtc *possible_crtc;
Chris Wilson4ef69c72010-09-09 15:14:28 +010010480 struct drm_encoder *encoder = &intel_encoder->base;
Jesse Barnes79e53942008-11-07 14:24:08 -080010481 struct drm_crtc *crtc = NULL;
10482 struct drm_device *dev = encoder->dev;
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010483 struct drm_i915_private *dev_priv = to_i915(dev);
Rob Clark51fd3712013-11-19 12:10:12 -050010484 struct drm_mode_config *config = &dev->mode_config;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010485 struct drm_atomic_state *state = NULL, *restore_state = NULL;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010486 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010487 struct intel_crtc_state *crtc_state;
Rob Clark51fd3712013-11-19 12:10:12 -050010488 int ret, i = -1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010489
Chris Wilsond2dff872011-04-19 08:36:26 +010010490 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010491 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010492 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010493
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010494 old->restore_state = NULL;
10495
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010496 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
Daniel Vetter6e9f7982014-05-29 23:54:47 +020010497
Jesse Barnes79e53942008-11-07 14:24:08 -080010498 /*
10499 * Algorithm gets a little messy:
Chris Wilson7a5e4802011-04-19 23:21:12 +010010500 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010501 * - if the connector already has an assigned crtc, use it (but make
10502 * sure it's on first)
Chris Wilson7a5e4802011-04-19 23:21:12 +010010503 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010504 * - try to find the first unused crtc that can drive this connector,
10505 * and use that if we find one
Jesse Barnes79e53942008-11-07 14:24:08 -080010506 */
10507
10508 /* See if we already have a CRTC for this connector */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010509 if (connector->state->crtc) {
10510 crtc = connector->state->crtc;
Chris Wilson8261b192011-04-19 23:18:09 +010010511
Rob Clark51fd3712013-11-19 12:10:12 -050010512 ret = drm_modeset_lock(&crtc->mutex, ctx);
10513 if (ret)
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010514 goto fail;
Chris Wilson8261b192011-04-19 23:18:09 +010010515
10516 /* Make sure the crtc and connector are running */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010517 goto found;
Jesse Barnes79e53942008-11-07 14:24:08 -080010518 }
10519
10520 /* Find an unused one (if possible) */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +010010521 for_each_crtc(dev, possible_crtc) {
Jesse Barnes79e53942008-11-07 14:24:08 -080010522 i++;
10523 if (!(encoder->possible_crtcs & (1 << i)))
10524 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010525
10526 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10527 if (ret)
10528 goto fail;
10529
10530 if (possible_crtc->state->enable) {
10531 drm_modeset_unlock(&possible_crtc->mutex);
Ville Syrjäläa4592492014-08-11 13:15:36 +030010532 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010533 }
Ville Syrjäläa4592492014-08-11 13:15:36 +030010534
10535 crtc = possible_crtc;
10536 break;
Jesse Barnes79e53942008-11-07 14:24:08 -080010537 }
10538
10539 /*
10540 * If we didn't find an unused CRTC, don't use any.
10541 */
10542 if (!crtc) {
Chris Wilson71731882011-04-19 23:10:58 +010010543 DRM_DEBUG_KMS("no pipe available for load-detect\n");
Dan Carpenterf4bf77b2017-04-14 22:54:25 +030010544 ret = -ENODEV;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010545 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010546 }
10547
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010548found:
10549 intel_crtc = to_intel_crtc(crtc);
10550
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010551 state = drm_atomic_state_alloc(dev);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010552 restore_state = drm_atomic_state_alloc(dev);
10553 if (!state || !restore_state) {
10554 ret = -ENOMEM;
10555 goto fail;
10556 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010557
10558 state->acquire_ctx = ctx;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010559 restore_state->acquire_ctx = ctx;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010560
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010561 connector_state = drm_atomic_get_connector_state(state, connector);
10562 if (IS_ERR(connector_state)) {
10563 ret = PTR_ERR(connector_state);
10564 goto fail;
10565 }
10566
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010567 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10568 if (ret)
10569 goto fail;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010570
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010571 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10572 if (IS_ERR(crtc_state)) {
10573 ret = PTR_ERR(crtc_state);
10574 goto fail;
10575 }
10576
Maarten Lankhorst49d6fa22015-05-11 10:45:15 +020010577 crtc_state->base.active = crtc_state->base.enable = true;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010578
Chris Wilson64927112011-04-20 07:25:26 +010010579 if (!mode)
10580 mode = &load_detect_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -080010581
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010582 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010583 if (ret)
10584 goto fail;
10585
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010586 ret = intel_modeset_disable_planes(state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010587 if (ret)
10588 goto fail;
10589
10590 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10591 if (!ret)
10592 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
Ville Syrjäläbe90cc32018-03-22 17:23:12 +020010593 if (!ret)
10594 ret = drm_atomic_add_affected_planes(restore_state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010595 if (ret) {
10596 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10597 goto fail;
10598 }
Ander Conselvan de Oliveira8c7b5cc2015-04-21 17:13:19 +030010599
Maarten Lankhorst3ba86072016-02-29 09:18:57 +010010600 ret = drm_atomic_commit(state);
10601 if (ret) {
Chris Wilson64927112011-04-20 07:25:26 +010010602 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010603 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010604 }
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010605
10606 old->restore_state = restore_state;
Chris Wilson7abbd112017-01-19 11:37:49 +000010607 drm_atomic_state_put(state);
Chris Wilson71731882011-04-19 23:10:58 +010010608
Jesse Barnes79e53942008-11-07 14:24:08 -080010609 /* let the connector get through one full cycle before testing */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010610 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Chris Wilson71731882011-04-19 23:10:58 +010010611 return true;
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010612
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010613fail:
Chris Wilson7fb71c82016-10-19 12:37:43 +010010614 if (state) {
10615 drm_atomic_state_put(state);
10616 state = NULL;
10617 }
10618 if (restore_state) {
10619 drm_atomic_state_put(restore_state);
10620 restore_state = NULL;
10621 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010622
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010623 if (ret == -EDEADLK)
10624 return ret;
Rob Clark51fd3712013-11-19 12:10:12 -050010625
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010626 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -080010627}
10628
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010629void intel_release_load_detect_pipe(struct drm_connector *connector,
Ander Conselvan de Oliveira49172fe2015-03-20 16:18:02 +020010630 struct intel_load_detect_pipe *old,
10631 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010632{
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010633 struct intel_encoder *intel_encoder =
10634 intel_attached_encoder(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +010010635 struct drm_encoder *encoder = &intel_encoder->base;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010636 struct drm_atomic_state *state = old->restore_state;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010637 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080010638
Chris Wilsond2dff872011-04-19 08:36:26 +010010639 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010640 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010641 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010642
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010643 if (!state)
Chris Wilson0622a532011-04-21 09:32:11 +010010644 return;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010645
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010010646 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Chris Wilson08536952016-10-14 13:18:18 +010010647 if (ret)
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010648 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
Chris Wilson08536952016-10-14 13:18:18 +010010649 drm_atomic_state_put(state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010650}
10651
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010652static int i9xx_pll_refclk(struct drm_device *dev,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010653 const struct intel_crtc_state *pipe_config)
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010654{
Chris Wilsonfac5e232016-07-04 11:34:36 +010010655 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010656 u32 dpll = pipe_config->dpll_hw_state.dpll;
10657
10658 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
Ville Syrjäläe91e9412013-12-09 18:54:16 +020010659 return dev_priv->vbt.lvds_ssc_freq;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010010660 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010661 return 120000;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010662 else if (!IS_GEN(dev_priv, 2))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010663 return 96000;
10664 else
10665 return 48000;
10666}
10667
Jesse Barnes79e53942008-11-07 14:24:08 -080010668/* Returns the clock of the currently programmed mode of the given pipe. */
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010669static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010670 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -080010671{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010672 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010010673 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010674 int pipe = pipe_config->cpu_transcoder;
Ville Syrjälä293623f2013-09-13 16:18:46 +030010675 u32 dpll = pipe_config->dpll_hw_state.dpll;
Jesse Barnes79e53942008-11-07 14:24:08 -080010676 u32 fp;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +030010677 struct dpll clock;
Imre Deakdccbea32015-06-22 23:35:51 +030010678 int port_clock;
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010679 int refclk = i9xx_pll_refclk(dev, pipe_config);
Jesse Barnes79e53942008-11-07 14:24:08 -080010680
10681 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
Ville Syrjälä293623f2013-09-13 16:18:46 +030010682 fp = pipe_config->dpll_hw_state.fp0;
Jesse Barnes79e53942008-11-07 14:24:08 -080010683 else
Ville Syrjälä293623f2013-09-13 16:18:46 +030010684 fp = pipe_config->dpll_hw_state.fp1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010685
10686 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010687 if (IS_PINEVIEW(dev_priv)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010688 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10689 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
Shaohua Li21778322009-02-23 15:19:16 +080010690 } else {
10691 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10692 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10693 }
10694
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010695 if (!IS_GEN(dev_priv, 2)) {
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010696 if (IS_PINEVIEW(dev_priv))
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010697 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10698 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
Shaohua Li21778322009-02-23 15:19:16 +080010699 else
10700 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
Jesse Barnes79e53942008-11-07 14:24:08 -080010701 DPLL_FPA01_P1_POST_DIV_SHIFT);
10702
10703 switch (dpll & DPLL_MODE_MASK) {
10704 case DPLLB_MODE_DAC_SERIAL:
10705 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10706 5 : 10;
10707 break;
10708 case DPLLB_MODE_LVDS:
10709 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10710 7 : 14;
10711 break;
10712 default:
Zhao Yakui28c97732009-10-09 11:39:41 +080010713 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
Jesse Barnes79e53942008-11-07 14:24:08 -080010714 "mode\n", (int)(dpll & DPLL_MODE_MASK));
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010715 return;
Jesse Barnes79e53942008-11-07 14:24:08 -080010716 }
10717
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010718 if (IS_PINEVIEW(dev_priv))
Imre Deakdccbea32015-06-22 23:35:51 +030010719 port_clock = pnv_calc_dpll_params(refclk, &clock);
Daniel Vetterac58c3f2013-06-01 17:16:17 +020010720 else
Imre Deakdccbea32015-06-22 23:35:51 +030010721 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010722 } else {
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010010723 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010724 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
Jesse Barnes79e53942008-11-07 14:24:08 -080010725
10726 if (is_lvds) {
10727 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10728 DPLL_FPA01_P1_POST_DIV_SHIFT);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010729
10730 if (lvds & LVDS_CLKB_POWER_UP)
10731 clock.p2 = 7;
10732 else
10733 clock.p2 = 14;
Jesse Barnes79e53942008-11-07 14:24:08 -080010734 } else {
10735 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10736 clock.p1 = 2;
10737 else {
10738 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10739 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10740 }
10741 if (dpll & PLL_P2_DIVIDE_BY_4)
10742 clock.p2 = 4;
10743 else
10744 clock.p2 = 2;
Jesse Barnes79e53942008-11-07 14:24:08 -080010745 }
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010746
Imre Deakdccbea32015-06-22 23:35:51 +030010747 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010748 }
10749
Ville Syrjälä18442d02013-09-13 16:00:08 +030010750 /*
10751 * This value includes pixel_multiplier. We will use
Damien Lespiau241bfc32013-09-25 16:45:37 +010010752 * port_clock to compute adjusted_mode.crtc_clock in the
Ville Syrjälä18442d02013-09-13 16:00:08 +030010753 * encoder's get_config() function.
10754 */
Imre Deakdccbea32015-06-22 23:35:51 +030010755 pipe_config->port_clock = port_clock;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010756}
10757
Ville Syrjälä6878da02013-09-13 15:59:11 +030010758int intel_dotclock_calculate(int link_freq,
10759 const struct intel_link_m_n *m_n)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010760{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010761 /*
10762 * The calculation for the data clock is:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010763 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010764 * But we want to avoid losing precison if possible, so:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010765 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010766 *
10767 * and the link clock is simpler:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010768 * link_clock = (m * link_clock) / n
Jesse Barnes79e53942008-11-07 14:24:08 -080010769 */
10770
Ville Syrjälä6878da02013-09-13 15:59:11 +030010771 if (!m_n->link_n)
10772 return 0;
10773
Chris Wilson31236982017-09-13 11:51:53 +010010774 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 +030010775}
10776
Ville Syrjälä18442d02013-09-13 16:00:08 +030010777static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010778 struct intel_crtc_state *pipe_config)
Ville Syrjälä6878da02013-09-13 15:59:11 +030010779{
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010780 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä18442d02013-09-13 16:00:08 +030010781
10782 /* read out port_clock from the DPLL */
10783 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä6878da02013-09-13 15:59:11 +030010784
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010785 /*
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010786 * In case there is an active pipe without active ports,
10787 * we may need some idea for the dotclock anyway.
10788 * Calculate one based on the FDI configuration.
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010789 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020010790 pipe_config->base.adjusted_mode.crtc_clock =
Ville Syrjälä21a727b2016-02-17 21:41:10 +020010791 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjälä18442d02013-09-13 16:00:08 +030010792 &pipe_config->fdi_m_n);
Jesse Barnes79e53942008-11-07 14:24:08 -080010793}
10794
Ville Syrjäläde330812017-10-09 19:19:50 +030010795/* Returns the currently programmed mode of the given encoder. */
10796struct drm_display_mode *
10797intel_encoder_current_mode(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080010798{
Ville Syrjäläde330812017-10-09 19:19:50 +030010799 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10800 struct intel_crtc_state *crtc_state;
Jesse Barnes79e53942008-11-07 14:24:08 -080010801 struct drm_display_mode *mode;
Ville Syrjäläde330812017-10-09 19:19:50 +030010802 struct intel_crtc *crtc;
10803 enum pipe pipe;
10804
10805 if (!encoder->get_hw_state(encoder, &pipe))
10806 return NULL;
10807
10808 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Jesse Barnes79e53942008-11-07 14:24:08 -080010809
10810 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10811 if (!mode)
10812 return NULL;
10813
Ville Syrjäläde330812017-10-09 19:19:50 +030010814 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10815 if (!crtc_state) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010816 kfree(mode);
10817 return NULL;
10818 }
10819
Ville Syrjäläde330812017-10-09 19:19:50 +030010820 crtc_state->base.crtc = &crtc->base;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010821
Ville Syrjäläde330812017-10-09 19:19:50 +030010822 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10823 kfree(crtc_state);
10824 kfree(mode);
10825 return NULL;
10826 }
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010827
Ville Syrjäläde330812017-10-09 19:19:50 +030010828 encoder->get_config(encoder, crtc_state);
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010829
Ville Syrjäläde330812017-10-09 19:19:50 +030010830 intel_mode_from_pipe_config(mode, crtc_state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010831
Ville Syrjäläde330812017-10-09 19:19:50 +030010832 kfree(crtc_state);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010833
Jesse Barnes79e53942008-11-07 14:24:08 -080010834 return mode;
10835}
10836
10837static void intel_crtc_destroy(struct drm_crtc *crtc)
10838{
10839 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10840
10841 drm_crtc_cleanup(crtc);
10842 kfree(intel_crtc);
10843}
10844
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010845/**
10846 * intel_wm_need_update - Check whether watermarks need updating
Chris Wilson6bf19812018-12-31 14:35:05 +000010847 * @cur: current plane state
10848 * @new: new plane state
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010849 *
10850 * Check current plane state versus the new one to determine whether
10851 * watermarks need to be recalculated.
10852 *
10853 * Returns true or false.
10854 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010855static bool intel_wm_need_update(struct intel_plane_state *cur,
10856 struct intel_plane_state *new)
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010857{
Matt Roperd21fbe82015-09-24 15:53:12 -070010858 /* Update watermarks on tiling or size changes. */
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010859 if (new->base.visible != cur->base.visible)
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010860 return true;
10861
10862 if (!cur->base.fb || !new->base.fb)
10863 return false;
10864
Ville Syrjäläbae781b2016-11-16 13:33:16 +020010865 if (cur->base.fb->modifier != new->base.fb->modifier ||
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010866 cur->base.rotation != new->base.rotation ||
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010867 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10868 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10869 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10870 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010871 return true;
10872
10873 return false;
10874}
10875
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010876static bool needs_scaling(const struct intel_plane_state *state)
Matt Roperd21fbe82015-09-24 15:53:12 -070010877{
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010878 int src_w = drm_rect_width(&state->base.src) >> 16;
10879 int src_h = drm_rect_height(&state->base.src) >> 16;
10880 int dst_w = drm_rect_width(&state->base.dst);
10881 int dst_h = drm_rect_height(&state->base.dst);
Matt Roperd21fbe82015-09-24 15:53:12 -070010882
10883 return (src_w != dst_w || src_h != dst_h);
10884}
10885
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010886int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10887 struct drm_crtc_state *crtc_state,
10888 const struct intel_plane_state *old_plane_state,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010889 struct drm_plane_state *plane_state)
10890{
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010891 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010892 struct drm_crtc *crtc = crtc_state->crtc;
10893 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010894 struct intel_plane *plane = to_intel_plane(plane_state->plane);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010895 struct drm_device *dev = crtc->dev;
Matt Ropered4a6a72016-02-23 17:20:13 -080010896 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010897 bool mode_changed = needs_modeset(crtc_state);
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010898 bool was_crtc_enabled = old_crtc_state->base.active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010899 bool is_crtc_enabled = crtc_state->active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010900 bool turn_off, turn_on, visible, was_visible;
10901 struct drm_framebuffer *fb = plane_state->fb;
Ville Syrjälä78108b72016-05-27 20:59:19 +030010902 int ret;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010903
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010904 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010905 ret = skl_update_scaler_plane(
10906 to_intel_crtc_state(crtc_state),
10907 to_intel_plane_state(plane_state));
10908 if (ret)
10909 return ret;
10910 }
10911
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010912 was_visible = old_plane_state->base.visible;
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010913 visible = plane_state->visible;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010914
10915 if (!was_crtc_enabled && WARN_ON(was_visible))
10916 was_visible = false;
10917
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010918 /*
10919 * Visibility is calculated as if the crtc was on, but
10920 * after scaler setup everything depends on it being off
10921 * when the crtc isn't active.
Ville Syrjäläf818ffe2016-04-29 17:31:18 +030010922 *
10923 * FIXME this is wrong for watermarks. Watermarks should also
10924 * be computed as if the pipe would be active. Perhaps move
10925 * per-plane wm computation to the .check_plane() hook, and
10926 * only combine the results from all planes in the current place?
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010927 */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010928 if (!is_crtc_enabled) {
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010929 plane_state->visible = visible = false;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010930 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10931 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010932
10933 if (!was_visible && !visible)
10934 return 0;
10935
Maarten Lankhorste8861672016-02-24 11:24:26 +010010936 if (fb != old_plane_state->base.fb)
10937 pipe_config->fb_changed = true;
10938
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010939 turn_off = was_visible && (!visible || mode_changed);
10940 turn_on = visible && (!was_visible || mode_changed);
10941
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010942 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010943 intel_crtc->base.base.id, intel_crtc->base.name,
10944 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010945 fb ? fb->base.id : -1);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010946
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010947 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 +020010948 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010949 was_visible, visible,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010950 turn_off, turn_on, mode_changed);
10951
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010952 if (turn_on) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010953 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010954 pipe_config->update_wm_pre = true;
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010955
10956 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010957 if (plane->id != PLANE_CURSOR)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010958 pipe_config->disable_cxsr = true;
10959 } else if (turn_off) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010960 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010961 pipe_config->update_wm_post = true;
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010962
Ville Syrjälä852eb002015-06-24 22:00:07 +030010963 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010964 if (plane->id != PLANE_CURSOR)
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010965 pipe_config->disable_cxsr = true;
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010966 } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state),
10967 to_intel_plane_state(plane_state))) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010968 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010969 /* FIXME bollocks */
10970 pipe_config->update_wm_pre = true;
10971 pipe_config->update_wm_post = true;
10972 }
Ville Syrjälä852eb002015-06-24 22:00:07 +030010973 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010974
Rodrigo Vivi8be6ca82015-08-24 16:38:23 -070010975 if (visible || was_visible)
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010976 pipe_config->fb_bits |= plane->frontbuffer_bit;
Ville Syrjäläa9ff8712015-06-24 21:59:34 +030010977
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010978 /*
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010979 * ILK/SNB DVSACNTR/Sprite Enable
10980 * IVB SPR_CTL/Sprite Enable
10981 * "When in Self Refresh Big FIFO mode, a write to enable the
10982 * plane will be internally buffered and delayed while Big FIFO
10983 * mode is exiting."
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010984 *
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010985 * Which means that enabling the sprite can take an extra frame
10986 * when we start in big FIFO mode (LP1+). Thus we need to drop
10987 * down to LP0 and wait for vblank in order to make sure the
10988 * sprite gets enabled on the next vblank after the register write.
10989 * Doing otherwise would risk enabling the sprite one frame after
10990 * we've already signalled flip completion. We can resume LP1+
10991 * once the sprite has been enabled.
10992 *
10993 *
10994 * WaCxSRDisabledForSpriteScaling:ivb
10995 * IVB SPR_SCALE/Scaling Enable
10996 * "Low Power watermarks must be disabled for at least one
10997 * frame before enabling sprite scaling, and kept disabled
10998 * until sprite scaling is disabled."
10999 *
11000 * ILK/SNB DVSASCALE/Scaling Enable
11001 * "When in Self Refresh Big FIFO mode, scaling enable will be
11002 * masked off while Big FIFO mode is exiting."
11003 *
11004 * Despite the w/a only being listed for IVB we assume that
11005 * the ILK/SNB note has similar ramifications, hence we apply
11006 * the w/a on all three platforms.
Juha-Pekka Heikkilad8af3272018-12-20 13:26:08 +020011007 *
11008 * With experimental results seems this is needed also for primary
11009 * plane, not only sprite plane.
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010011010 */
Juha-Pekka Heikkilad8af3272018-12-20 13:26:08 +020011011 if (plane->id != PLANE_CURSOR &&
Lucas De Marchif3ce44a2018-12-12 10:10:44 -080011012 (IS_GEN_RANGE(dev_priv, 5, 6) ||
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030011013 IS_IVYBRIDGE(dev_priv)) &&
11014 (turn_on || (!needs_scaling(old_plane_state) &&
11015 needs_scaling(to_intel_plane_state(plane_state)))))
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010011016 pipe_config->disable_lp_wm = true;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020011017
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020011018 return 0;
11019}
11020
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011021static bool encoders_cloneable(const struct intel_encoder *a,
11022 const struct intel_encoder *b)
11023{
11024 /* masks could be asymmetric, so check both ways */
11025 return a == b || (a->cloneable & (1 << b->type) &&
11026 b->cloneable & (1 << a->type));
11027}
11028
11029static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11030 struct intel_crtc *crtc,
11031 struct intel_encoder *encoder)
11032{
11033 struct intel_encoder *source_encoder;
11034 struct drm_connector *connector;
11035 struct drm_connector_state *connector_state;
11036 int i;
11037
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011038 for_each_new_connector_in_state(state, connector, connector_state, i) {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011039 if (connector_state->crtc != &crtc->base)
11040 continue;
11041
11042 source_encoder =
11043 to_intel_encoder(connector_state->best_encoder);
11044 if (!encoders_cloneable(encoder, source_encoder))
11045 return false;
11046 }
11047
11048 return true;
11049}
11050
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011051static int icl_add_linked_planes(struct intel_atomic_state *state)
11052{
11053 struct intel_plane *plane, *linked;
11054 struct intel_plane_state *plane_state, *linked_plane_state;
11055 int i;
11056
11057 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11058 linked = plane_state->linked_plane;
11059
11060 if (!linked)
11061 continue;
11062
11063 linked_plane_state = intel_atomic_get_plane_state(state, linked);
11064 if (IS_ERR(linked_plane_state))
11065 return PTR_ERR(linked_plane_state);
11066
11067 WARN_ON(linked_plane_state->linked_plane != plane);
11068 WARN_ON(linked_plane_state->slave == plane_state->slave);
11069 }
11070
11071 return 0;
11072}
11073
11074static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
11075{
11076 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11077 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11078 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
11079 struct intel_plane *plane, *linked;
11080 struct intel_plane_state *plane_state;
11081 int i;
11082
11083 if (INTEL_GEN(dev_priv) < 11)
11084 return 0;
11085
11086 /*
11087 * Destroy all old plane links and make the slave plane invisible
11088 * in the crtc_state->active_planes mask.
11089 */
11090 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11091 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
11092 continue;
11093
11094 plane_state->linked_plane = NULL;
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020011095 if (plane_state->slave && !plane_state->base.visible) {
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011096 crtc_state->active_planes &= ~BIT(plane->id);
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020011097 crtc_state->update_planes |= BIT(plane->id);
11098 }
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011099
11100 plane_state->slave = false;
11101 }
11102
11103 if (!crtc_state->nv12_planes)
11104 return 0;
11105
11106 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11107 struct intel_plane_state *linked_state = NULL;
11108
11109 if (plane->pipe != crtc->pipe ||
11110 !(crtc_state->nv12_planes & BIT(plane->id)))
11111 continue;
11112
11113 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
11114 if (!icl_is_nv12_y_plane(linked->id))
11115 continue;
11116
11117 if (crtc_state->active_planes & BIT(linked->id))
11118 continue;
11119
11120 linked_state = intel_atomic_get_plane_state(state, linked);
11121 if (IS_ERR(linked_state))
11122 return PTR_ERR(linked_state);
11123
11124 break;
11125 }
11126
11127 if (!linked_state) {
11128 DRM_DEBUG_KMS("Need %d free Y planes for NV12\n",
11129 hweight8(crtc_state->nv12_planes));
11130
11131 return -EINVAL;
11132 }
11133
11134 plane_state->linked_plane = linked;
11135
11136 linked_state->slave = true;
11137 linked_state->linked_plane = plane;
11138 crtc_state->active_planes |= BIT(linked->id);
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020011139 crtc_state->update_planes |= BIT(linked->id);
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011140 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
11141 }
11142
11143 return 0;
11144}
11145
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011146static int intel_crtc_atomic_check(struct drm_crtc *crtc,
11147 struct drm_crtc_state *crtc_state)
11148{
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011149 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011150 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +020011151 struct intel_crtc_state *pipe_config =
11152 to_intel_crtc_state(crtc_state);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020011153 int ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011154 bool mode_changed = needs_modeset(crtc_state);
11155
Ville Syrjälä440e84a2019-02-06 20:54:33 +020011156 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
11157 mode_changed && !crtc_state->active)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020011158 pipe_config->update_wm_post = true;
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020011159
Maarten Lankhorstad421372015-06-15 12:33:42 +020011160 if (mode_changed && crtc_state->enable &&
11161 dev_priv->display.crtc_compute_clock &&
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011162 !WARN_ON(pipe_config->shared_dpll)) {
Maarten Lankhorstad421372015-06-15 12:33:42 +020011163 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
11164 pipe_config);
11165 if (ret)
11166 return ret;
11167 }
11168
Ville Syrjälä051a6d82019-02-05 18:08:41 +020011169 if (mode_changed || crtc_state->color_mgmt_changed) {
Matt Roper302da0c2018-12-10 13:54:15 -080011170 ret = intel_color_check(pipe_config);
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000011171 if (ret)
11172 return ret;
Lionel Landwerline7852a42016-05-25 14:30:41 +010011173
11174 /*
11175 * Changing color management on Intel hardware is
11176 * handled as part of planes update.
11177 */
11178 crtc_state->planes_changed = true;
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000011179 }
11180
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011181 ret = 0;
Matt Roper86c8bbb2015-09-24 15:53:16 -070011182 if (dev_priv->display.compute_pipe_wm) {
Maarten Lankhorste3bddde2016-03-01 11:07:22 +010011183 ret = dev_priv->display.compute_pipe_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080011184 if (ret) {
11185 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
Matt Roper86c8bbb2015-09-24 15:53:16 -070011186 return ret;
Matt Ropered4a6a72016-02-23 17:20:13 -080011187 }
11188 }
11189
Ville Syrjäläf255c622018-11-08 17:10:13 +020011190 if (dev_priv->display.compute_intermediate_wm) {
Matt Ropered4a6a72016-02-23 17:20:13 -080011191 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
11192 return 0;
11193
11194 /*
11195 * Calculate 'intermediate' watermarks that satisfy both the
11196 * old state and the new state. We can program these
11197 * immediately.
11198 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011199 ret = dev_priv->display.compute_intermediate_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080011200 if (ret) {
11201 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11202 return ret;
11203 }
Matt Roper86c8bbb2015-09-24 15:53:16 -070011204 }
11205
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011206 if (INTEL_GEN(dev_priv) >= 9) {
Hans de Goede2c5c4152018-12-17 15:19:03 +010011207 if (mode_changed || pipe_config->update_pipe)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011208 ret = skl_update_scaler_crtc(pipe_config);
11209
11210 if (!ret)
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011211 ret = icl_check_nv12_planes(pipe_config);
11212 if (!ret)
Mahesh Kumar73b0ca82017-05-26 20:45:46 +053011213 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11214 pipe_config);
11215 if (!ret)
Ander Conselvan de Oliveira6ebc6922017-02-23 09:15:59 +020011216 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011217 pipe_config);
11218 }
11219
Maarten Lankhorst24f28452017-11-22 19:39:01 +010011220 if (HAS_IPS(dev_priv))
11221 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11222
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011223 return ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011224}
11225
Jani Nikula65b38e02015-04-13 11:26:56 +030011226static const struct drm_crtc_helper_funcs intel_helper_funcs = {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011227 .atomic_check = intel_crtc_atomic_check,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010011228};
11229
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011230static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11231{
11232 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011233 struct drm_connector_list_iter conn_iter;
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011234
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011235 drm_connector_list_iter_begin(dev, &conn_iter);
11236 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter8863dc72016-05-06 15:39:03 +020011237 if (connector->base.state->crtc)
Thomas Zimmermannef196b52018-06-18 13:01:50 +020011238 drm_connector_put(&connector->base);
Daniel Vetter8863dc72016-05-06 15:39:03 +020011239
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011240 if (connector->base.encoder) {
11241 connector->base.state->best_encoder =
11242 connector->base.encoder;
11243 connector->base.state->crtc =
11244 connector->base.encoder->crtc;
Daniel Vetter8863dc72016-05-06 15:39:03 +020011245
Thomas Zimmermannef196b52018-06-18 13:01:50 +020011246 drm_connector_get(&connector->base);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011247 } else {
11248 connector->base.state->best_encoder = NULL;
11249 connector->base.state->crtc = NULL;
11250 }
11251 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011252 drm_connector_list_iter_end(&conn_iter);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011253}
11254
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011255static int
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011256compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11257 struct intel_crtc_state *pipe_config)
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011258{
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011259 struct drm_connector *connector = conn_state->connector;
11260 const struct drm_display_info *info = &connector->display_info;
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011261 int bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011262
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011263 switch (conn_state->max_bpc) {
11264 case 6 ... 7:
11265 bpp = 6 * 3;
11266 break;
11267 case 8 ... 9:
11268 bpp = 8 * 3;
11269 break;
11270 case 10 ... 11:
11271 bpp = 10 * 3;
11272 break;
11273 case 12:
11274 bpp = 12 * 3;
11275 break;
11276 default:
11277 return -EINVAL;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011278 }
11279
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011280 if (bpp < pipe_config->pipe_bpp) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011281 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11282 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11283 connector->base.id, connector->name,
11284 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011285 pipe_config->pipe_bpp);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011286
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011287 pipe_config->pipe_bpp = bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011288 }
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011289
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011290 return 0;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011291}
11292
11293static int
11294compute_baseline_pipe_bpp(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011295 struct intel_crtc_state *pipe_config)
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011296{
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011297 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011298 struct drm_atomic_state *state = pipe_config->base.state;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011299 struct drm_connector *connector;
11300 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011301 int bpp, i;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011302
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011303 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11304 IS_CHERRYVIEW(dev_priv)))
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011305 bpp = 10*3;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011306 else if (INTEL_GEN(dev_priv) >= 5)
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011307 bpp = 12*3;
11308 else
11309 bpp = 8*3;
11310
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011311 pipe_config->pipe_bpp = bpp;
11312
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011313 /* Clamp display bpp to connector max bpp */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011314 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011315 int ret;
11316
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011317 if (connector_state->crtc != &crtc->base)
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011318 continue;
11319
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011320 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11321 if (ret)
11322 return ret;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011323 }
11324
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011325 return 0;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011326}
11327
Daniel Vetter644db712013-09-19 14:53:58 +020011328static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11329{
11330 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11331 "type: 0x%x flags: 0x%x\n",
Damien Lespiau13428302013-09-25 16:45:36 +010011332 mode->crtc_clock,
Daniel Vetter644db712013-09-19 14:53:58 +020011333 mode->crtc_hdisplay, mode->crtc_hsync_start,
11334 mode->crtc_hsync_end, mode->crtc_htotal,
11335 mode->crtc_vdisplay, mode->crtc_vsync_start,
11336 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11337}
11338
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011339static inline void
11340intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011341 unsigned int lane_count, struct intel_link_m_n *m_n)
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011342{
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011343 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11344 id, lane_count,
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011345 m_n->gmch_m, m_n->gmch_n,
11346 m_n->link_m, m_n->link_n, m_n->tu);
11347}
11348
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011349#define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11350
11351static const char * const output_type_str[] = {
11352 OUTPUT_TYPE(UNUSED),
11353 OUTPUT_TYPE(ANALOG),
11354 OUTPUT_TYPE(DVO),
11355 OUTPUT_TYPE(SDVO),
11356 OUTPUT_TYPE(LVDS),
11357 OUTPUT_TYPE(TVOUT),
11358 OUTPUT_TYPE(HDMI),
11359 OUTPUT_TYPE(DP),
11360 OUTPUT_TYPE(EDP),
11361 OUTPUT_TYPE(DSI),
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011362 OUTPUT_TYPE(DDI),
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011363 OUTPUT_TYPE(DP_MST),
11364};
11365
11366#undef OUTPUT_TYPE
11367
11368static void snprintf_output_types(char *buf, size_t len,
11369 unsigned int output_types)
11370{
11371 char *str = buf;
11372 int i;
11373
11374 str[0] = '\0';
11375
11376 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11377 int r;
11378
11379 if ((output_types & BIT(i)) == 0)
11380 continue;
11381
11382 r = snprintf(str, len, "%s%s",
11383 str != buf ? "," : "", output_type_str[i]);
11384 if (r >= len)
11385 break;
11386 str += r;
11387 len -= r;
11388
11389 output_types &= ~BIT(i);
11390 }
11391
11392 WARN_ON_ONCE(output_types != 0);
11393}
11394
Shashank Sharmad9facae2018-10-12 11:53:07 +053011395static const char * const output_format_str[] = {
11396 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11397 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011398 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
Shashank Sharma8c79f842018-10-12 11:53:09 +053011399 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
Shashank Sharmad9facae2018-10-12 11:53:07 +053011400};
11401
11402static const char *output_formats(enum intel_output_format format)
11403{
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011404 if (format >= ARRAY_SIZE(output_format_str))
Shashank Sharmad9facae2018-10-12 11:53:07 +053011405 format = INTEL_OUTPUT_FORMAT_INVALID;
11406 return output_format_str[format];
11407}
11408
Daniel Vetterc0b03412013-05-28 12:05:54 +020011409static void intel_dump_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011410 struct intel_crtc_state *pipe_config,
Daniel Vetterc0b03412013-05-28 12:05:54 +020011411 const char *context)
11412{
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011413 struct drm_device *dev = crtc->base.dev;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011414 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011415 struct drm_plane *plane;
11416 struct intel_plane *intel_plane;
11417 struct intel_plane_state *state;
11418 struct drm_framebuffer *fb;
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011419 char buf[64];
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011420
Tvrtko Ursulin66766e42016-11-17 12:30:10 +000011421 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11422 crtc->base.base.id, crtc->base.name, context);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011423
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011424 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11425 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11426 buf, pipe_config->output_types);
11427
Shashank Sharmad9facae2018-10-12 11:53:07 +053011428 DRM_DEBUG_KMS("output format: %s\n",
11429 output_formats(pipe_config->output_format));
11430
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011431 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11432 transcoder_name(pipe_config->cpu_transcoder),
Daniel Vetterc0b03412013-05-28 12:05:54 +020011433 pipe_config->pipe_bpp, pipe_config->dither);
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011434
11435 if (pipe_config->has_pch_encoder)
11436 intel_dump_m_n_config(pipe_config, "fdi",
11437 pipe_config->fdi_lanes,
11438 &pipe_config->fdi_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011439
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011440 if (intel_crtc_has_dp_encoder(pipe_config)) {
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011441 intel_dump_m_n_config(pipe_config, "dp m_n",
11442 pipe_config->lane_count, &pipe_config->dp_m_n);
Tvrtko Ursulind806e682016-11-17 15:44:09 +000011443 if (pipe_config->has_drrs)
11444 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11445 pipe_config->lane_count,
11446 &pipe_config->dp_m2_n2);
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011447 }
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011448
Daniel Vetter55072d12014-11-20 16:10:28 +010011449 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011450 pipe_config->has_audio, pipe_config->has_infoframe);
Daniel Vetter55072d12014-11-20 16:10:28 +010011451
Daniel Vetterc0b03412013-05-28 12:05:54 +020011452 DRM_DEBUG_KMS("requested mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011453 drm_mode_debug_printmodeline(&pipe_config->base.mode);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011454 DRM_DEBUG_KMS("adjusted mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011455 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11456 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011457 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011458 pipe_config->port_clock,
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011459 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11460 pipe_config->pixel_rate);
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011461
11462 if (INTEL_GEN(dev_priv) >= 9)
11463 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11464 crtc->num_scalers,
11465 pipe_config->scaler_state.scaler_users,
11466 pipe_config->scaler_state.scaler_id);
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011467
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080011468 if (HAS_GMCH(dev_priv))
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011469 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11470 pipe_config->gmch_pfit.control,
11471 pipe_config->gmch_pfit.pgm_ratios,
11472 pipe_config->gmch_pfit.lvds_border_bits);
11473 else
11474 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11475 pipe_config->pch_pfit.pos,
11476 pipe_config->pch_pfit.size,
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000011477 enableddisabled(pipe_config->pch_pfit.enabled));
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011478
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011479 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11480 pipe_config->ips_enabled, pipe_config->double_wide);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011481
Ander Conselvan de Oliveiraf50b79f2016-12-29 17:22:12 +020011482 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
Tvrtko Ursulin415ff0f2015-05-14 13:38:31 +010011483
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011484 DRM_DEBUG_KMS("planes on this crtc\n");
11485 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011486 struct drm_format_name_buf format_name;
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011487 intel_plane = to_intel_plane(plane);
11488 if (intel_plane->pipe != crtc->pipe)
11489 continue;
11490
11491 state = to_intel_plane_state(plane->state);
11492 fb = state->base.fb;
11493 if (!fb) {
Ville Syrjälä1d577e02016-05-27 20:59:25 +030011494 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11495 plane->base.id, plane->name, state->scaler_id);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011496 continue;
11497 }
11498
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011499 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11500 plane->base.id, plane->name,
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011501 fb->base.id, fb->width, fb->height,
Ville Syrjälä438b74a2016-12-14 23:32:55 +020011502 drm_get_format_name(fb->format->format, &format_name));
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011503 if (INTEL_GEN(dev_priv) >= 9)
11504 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11505 state->scaler_id,
11506 state->base.src.x1 >> 16,
11507 state->base.src.y1 >> 16,
11508 drm_rect_width(&state->base.src) >> 16,
11509 drm_rect_height(&state->base.src) >> 16,
11510 state->base.dst.x1, state->base.dst.y1,
11511 drm_rect_width(&state->base.dst),
11512 drm_rect_height(&state->base.dst));
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011513 }
Daniel Vetterc0b03412013-05-28 12:05:54 +020011514}
11515
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011516static bool check_digital_port_conflicts(struct drm_atomic_state *state)
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011517{
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011518 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011519 struct drm_connector *connector;
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011520 struct drm_connector_list_iter conn_iter;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011521 unsigned int used_ports = 0;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011522 unsigned int used_mst_ports = 0;
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011523 bool ret = true;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011524
11525 /*
11526 * Walk the connector list instead of the encoder
11527 * list to detect the problem on ddi platforms
11528 * where there's just one encoder per digital port.
11529 */
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011530 drm_connector_list_iter_begin(dev, &conn_iter);
11531 drm_for_each_connector_iter(connector, &conn_iter) {
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011532 struct drm_connector_state *connector_state;
11533 struct intel_encoder *encoder;
11534
Maarten Lankhorst8b694492018-04-09 14:46:55 +020011535 connector_state = drm_atomic_get_new_connector_state(state, connector);
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011536 if (!connector_state)
11537 connector_state = connector->state;
11538
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011539 if (!connector_state->best_encoder)
11540 continue;
11541
11542 encoder = to_intel_encoder(connector_state->best_encoder);
11543
11544 WARN_ON(!connector_state->crtc);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011545
11546 switch (encoder->type) {
11547 unsigned int port_mask;
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011548 case INTEL_OUTPUT_DDI:
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011549 if (WARN_ON(!HAS_DDI(to_i915(dev))))
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011550 break;
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -050011551 /* else: fall through */
Ville Syrjäläcca05022016-06-22 21:57:06 +030011552 case INTEL_OUTPUT_DP:
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011553 case INTEL_OUTPUT_HDMI:
11554 case INTEL_OUTPUT_EDP:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011555 port_mask = 1 << encoder->port;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011556
11557 /* the same port mustn't appear more than once */
11558 if (used_ports & port_mask)
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011559 ret = false;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011560
11561 used_ports |= port_mask;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011562 break;
11563 case INTEL_OUTPUT_DP_MST:
11564 used_mst_ports |=
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011565 1 << encoder->port;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011566 break;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011567 default:
11568 break;
11569 }
11570 }
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011571 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011572
Ville Syrjälä477321e2016-07-28 17:50:40 +030011573 /* can't mix MST and SST/HDMI on the same port */
11574 if (used_ports & used_mst_ports)
11575 return false;
11576
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011577 return ret;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011578}
11579
Chris Wilsonf81b8452019-02-05 09:27:59 +000011580static int
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011581clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11582{
Ville Syrjäläff32c542017-03-02 19:14:57 +020011583 struct drm_i915_private *dev_priv =
11584 to_i915(crtc_state->base.crtc->dev);
Chris Wilsonf81b8452019-02-05 09:27:59 +000011585 struct intel_crtc_state *saved_state;
11586
11587 saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL);
11588 if (!saved_state)
11589 return -ENOMEM;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011590
Ander Conselvan de Oliveira7546a382015-05-20 09:03:27 +030011591 /* FIXME: before the switch to atomic started, a new pipe_config was
11592 * kzalloc'd. Code that depends on any field being zero should be
11593 * fixed, so that the crtc_state can be safely duplicated. For now,
11594 * only fields that are know to not cause problems are preserved. */
11595
Chris Wilsonf81b8452019-02-05 09:27:59 +000011596 saved_state->scaler_state = crtc_state->scaler_state;
11597 saved_state->shared_dpll = crtc_state->shared_dpll;
11598 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
11599 saved_state->pch_pfit.force_thru = crtc_state->pch_pfit.force_thru;
11600 saved_state->ips_force_disable = crtc_state->ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011601 if (IS_G4X(dev_priv) ||
11602 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsonf81b8452019-02-05 09:27:59 +000011603 saved_state->wm = crtc_state->wm;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011604
Chris Wilsond2fa80a2017-03-03 15:46:44 +000011605 /* Keep base drm_crtc_state intact, only clear our extended struct */
11606 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
Chris Wilsonf81b8452019-02-05 09:27:59 +000011607 memcpy(&crtc_state->base + 1, &saved_state->base + 1,
Chris Wilsond2fa80a2017-03-03 15:46:44 +000011608 sizeof(*crtc_state) - sizeof(crtc_state->base));
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011609
Chris Wilsonf81b8452019-02-05 09:27:59 +000011610 kfree(saved_state);
11611 return 0;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011612}
11613
Ander Conselvan de Oliveira548ee152015-04-21 17:13:02 +030011614static int
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011615intel_modeset_pipe_config(struct drm_crtc *crtc,
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011616 struct intel_crtc_state *pipe_config)
Daniel Vetter7758a112012-07-08 19:40:39 +020011617{
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011618 struct drm_atomic_state *state = pipe_config->base.state;
Daniel Vetter7758a112012-07-08 19:40:39 +020011619 struct intel_encoder *encoder;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011620 struct drm_connector *connector;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011621 struct drm_connector_state *connector_state;
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011622 int base_bpp, ret;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011623 int i;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011624 bool retry = true;
Daniel Vetter7758a112012-07-08 19:40:39 +020011625
Chris Wilsonf81b8452019-02-05 09:27:59 +000011626 ret = clear_intel_crtc_state(pipe_config);
11627 if (ret)
11628 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011629
Daniel Vettere143a212013-07-04 12:01:15 +020011630 pipe_config->cpu_transcoder =
11631 (enum transcoder) to_intel_crtc(crtc)->pipe;
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011632
Imre Deak2960bc92013-07-30 13:36:32 +030011633 /*
11634 * Sanitize sync polarity flags based on requested ones. If neither
11635 * positive or negative polarity is requested, treat this as meaning
11636 * negative polarity.
11637 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011638 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011639 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011640 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011641
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011642 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011643 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011644 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011645
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011646 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11647 pipe_config);
11648 if (ret)
11649 return ret;
11650
11651 base_bpp = pipe_config->pipe_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011652
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011653 /*
11654 * Determine the real pipe dimensions. Note that stereo modes can
11655 * increase the actual pipe size due to the frame doubling and
11656 * insertion of additional space for blanks between the frame. This
11657 * is stored in the crtc timings. We use the requested mode to do this
11658 * computation to clearly distinguish it from the adjusted mode, which
11659 * can be changed by the connectors in the below retry loop.
11660 */
Daniel Vetter196cd5d2017-01-25 07:26:56 +010011661 drm_mode_get_hv_timing(&pipe_config->base.mode,
Gustavo Padovanecb7e162014-12-01 15:40:09 -080011662 &pipe_config->pipe_src_w,
11663 &pipe_config->pipe_src_h);
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011664
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011665 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011666 if (connector_state->crtc != crtc)
11667 continue;
11668
11669 encoder = to_intel_encoder(connector_state->best_encoder);
11670
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011671 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11672 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011673 return -EINVAL;
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011674 }
11675
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011676 /*
11677 * Determine output_types before calling the .compute_config()
11678 * hooks so that the hooks can use this information safely.
11679 */
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011680 if (encoder->compute_output_type)
11681 pipe_config->output_types |=
11682 BIT(encoder->compute_output_type(encoder, pipe_config,
11683 connector_state));
11684 else
11685 pipe_config->output_types |= BIT(encoder->type);
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011686 }
11687
Daniel Vettere29c22c2013-02-21 00:00:16 +010011688encoder_retry:
Daniel Vetteref1b4602013-06-01 17:17:04 +020011689 /* Ensure the port clock defaults are reset when retrying. */
Daniel Vetterff9a6752013-06-01 17:16:21 +020011690 pipe_config->port_clock = 0;
Daniel Vetteref1b4602013-06-01 17:17:04 +020011691 pipe_config->pixel_multiplier = 1;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011692
Daniel Vetter135c81b2013-07-21 21:37:09 +020011693 /* Fill in default crtc timings, allow encoders to overwrite them. */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011694 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11695 CRTC_STEREO_DOUBLE);
Daniel Vetter135c81b2013-07-21 21:37:09 +020011696
Daniel Vetter7758a112012-07-08 19:40:39 +020011697 /* Pass our mode to the connectors and the CRTC to give them a chance to
11698 * adjust it according to limitations or connector properties, and also
11699 * a chance to reject the mode entirely.
11700 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011701 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011702 if (connector_state->crtc != crtc)
11703 continue;
11704
11705 encoder = to_intel_encoder(connector_state->best_encoder);
Lyude Paul204474a2019-01-15 15:08:00 -050011706 ret = encoder->compute_config(encoder, pipe_config,
11707 connector_state);
11708 if (ret < 0) {
11709 if (ret != -EDEADLK)
11710 DRM_DEBUG_KMS("Encoder config failure: %d\n",
11711 ret);
11712 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011713 }
11714 }
11715
Daniel Vetterff9a6752013-06-01 17:16:21 +020011716 /* Set default port clock if not overwritten by the encoder. Needs to be
11717 * done afterwards in case the encoder adjusts the mode. */
11718 if (!pipe_config->port_clock)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011719 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
Damien Lespiau241bfc32013-09-25 16:45:37 +010011720 * pipe_config->pixel_multiplier;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011721
Daniel Vettera43f6e02013-06-07 23:10:32 +020011722 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020011723 if (ret == -EDEADLK)
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011724 return ret;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011725 if (ret < 0) {
Daniel Vetter7758a112012-07-08 19:40:39 +020011726 DRM_DEBUG_KMS("CRTC fixup failed\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011727 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011728 }
Daniel Vettere29c22c2013-02-21 00:00:16 +010011729
11730 if (ret == RETRY) {
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011731 if (WARN(!retry, "loop in pipe configuration computation\n"))
11732 return -EINVAL;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011733
11734 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11735 retry = false;
11736 goto encoder_retry;
11737 }
11738
Daniel Vettere8fa4272015-08-12 11:43:34 +020011739 /* Dithering seems to not pass-through bits correctly when it should, so
Manasi Navare611032b2017-01-24 08:21:49 -080011740 * only enable it on 6bpc panels and when its not a compliance
11741 * test requesting 6bpc video pattern.
11742 */
11743 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11744 !pipe_config->dither_force_disable;
Daniel Vetter62f0ace2015-08-26 18:57:26 +020011745 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011746 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011747
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011748 return 0;
Daniel Vetter7758a112012-07-08 19:40:39 +020011749}
11750
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011751static bool intel_fuzzy_clock_check(int clock1, int clock2)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011752{
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011753 int diff;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011754
11755 if (clock1 == clock2)
11756 return true;
11757
11758 if (!clock1 || !clock2)
11759 return false;
11760
11761 diff = abs(clock1 - clock2);
11762
11763 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11764 return true;
11765
11766 return false;
11767}
11768
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011769static bool
11770intel_compare_m_n(unsigned int m, unsigned int n,
11771 unsigned int m2, unsigned int n2,
11772 bool exact)
11773{
11774 if (m == m2 && n == n2)
11775 return true;
11776
11777 if (exact || !m || !n || !m2 || !n2)
11778 return false;
11779
11780 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11781
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011782 if (n > n2) {
11783 while (n > n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011784 m2 <<= 1;
11785 n2 <<= 1;
11786 }
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011787 } else if (n < n2) {
11788 while (n < n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011789 m <<= 1;
11790 n <<= 1;
11791 }
11792 }
11793
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011794 if (n != n2)
11795 return false;
11796
11797 return intel_fuzzy_clock_check(m, m2);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011798}
11799
11800static bool
11801intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11802 struct intel_link_m_n *m2_n2,
11803 bool adjust)
11804{
11805 if (m_n->tu == m2_n2->tu &&
11806 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11807 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11808 intel_compare_m_n(m_n->link_m, m_n->link_n,
11809 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11810 if (adjust)
11811 *m2_n2 = *m_n;
11812
11813 return true;
11814 }
11815
11816 return false;
11817}
11818
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011819static void __printf(3, 4)
11820pipe_config_err(bool adjust, const char *name, const char *format, ...)
11821{
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011822 struct va_format vaf;
11823 va_list args;
11824
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011825 va_start(args, format);
11826 vaf.fmt = format;
11827 vaf.va = &args;
11828
Joe Perches99a95482018-03-13 15:02:15 -070011829 if (adjust)
11830 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11831 else
11832 drm_err("mismatch in %s %pV", name, &vaf);
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011833
11834 va_end(args);
11835}
11836
Hans de Goede3d6535c2019-01-24 14:01:14 +010011837static bool fastboot_enabled(struct drm_i915_private *dev_priv)
11838{
11839 if (i915_modparams.fastboot != -1)
11840 return i915_modparams.fastboot;
11841
11842 /* Enable fastboot by default on Skylake and newer */
Hans de Goede7360c9f2019-01-29 15:22:37 +010011843 if (INTEL_GEN(dev_priv) >= 9)
11844 return true;
11845
11846 /* Enable fastboot by default on VLV and CHV */
11847 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11848 return true;
11849
11850 /* Disabled by default on all others */
11851 return false;
Hans de Goede3d6535c2019-01-24 14:01:14 +010011852}
11853
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011854static bool
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011855intel_pipe_config_compare(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011856 struct intel_crtc_state *current_config,
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011857 struct intel_crtc_state *pipe_config,
11858 bool adjust)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011859{
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011860 bool ret = true;
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011861 bool fixup_inherited = adjust &&
11862 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11863 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011864
Hans de Goede3d6535c2019-01-24 14:01:14 +010011865 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
Maarten Lankhorstd19f9582019-01-08 17:08:40 +010011866 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
11867 ret = false;
11868 }
11869
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011870#define PIPE_CONF_CHECK_X(name) do { \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011871 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011872 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011873 "(expected 0x%08x, found 0x%08x)\n", \
11874 current_config->name, \
11875 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011876 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011877 } \
11878} while (0)
Daniel Vetter66e985c2013-06-05 13:34:20 +020011879
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011880#define PIPE_CONF_CHECK_I(name) do { \
Daniel Vetter08a24032013-04-19 11:25:34 +020011881 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011882 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter08a24032013-04-19 11:25:34 +020011883 "(expected %i, found %i)\n", \
11884 current_config->name, \
11885 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011886 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011887 } \
11888} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011889
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011890#define PIPE_CONF_CHECK_BOOL(name) do { \
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011891 if (current_config->name != pipe_config->name) { \
11892 pipe_config_err(adjust, __stringify(name), \
11893 "(expected %s, found %s)\n", \
11894 yesno(current_config->name), \
11895 yesno(pipe_config->name)); \
11896 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011897 } \
11898} while (0)
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011899
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011900/*
11901 * Checks state where we only read out the enabling, but not the entire
11902 * state itself (like full infoframes or ELD for audio). These states
11903 * require a full modeset on bootup to fix up.
11904 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011905#define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011906 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11907 PIPE_CONF_CHECK_BOOL(name); \
11908 } else { \
11909 pipe_config_err(adjust, __stringify(name), \
11910 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11911 yesno(current_config->name), \
11912 yesno(pipe_config->name)); \
11913 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011914 } \
11915} while (0)
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011916
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011917#define PIPE_CONF_CHECK_P(name) do { \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011918 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011919 pipe_config_err(adjust, __stringify(name), \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011920 "(expected %p, found %p)\n", \
11921 current_config->name, \
11922 pipe_config->name); \
11923 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011924 } \
11925} while (0)
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011926
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011927#define PIPE_CONF_CHECK_M_N(name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011928 if (!intel_compare_link_m_n(&current_config->name, \
11929 &pipe_config->name,\
11930 adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011931 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011932 "(expected tu %i gmch %i/%i link %i/%i, " \
11933 "found tu %i, gmch %i/%i link %i/%i)\n", \
11934 current_config->name.tu, \
11935 current_config->name.gmch_m, \
11936 current_config->name.gmch_n, \
11937 current_config->name.link_m, \
11938 current_config->name.link_n, \
11939 pipe_config->name.tu, \
11940 pipe_config->name.gmch_m, \
11941 pipe_config->name.gmch_n, \
11942 pipe_config->name.link_m, \
11943 pipe_config->name.link_n); \
11944 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011945 } \
11946} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011947
Daniel Vetter55c561a2016-03-30 11:34:36 +020011948/* This is required for BDW+ where there is only one set of registers for
11949 * switching between high and low RR.
11950 * This macro can be used whenever a comparison has to be made between one
11951 * hw state and multiple sw state variables.
11952 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011953#define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011954 if (!intel_compare_link_m_n(&current_config->name, \
11955 &pipe_config->name, adjust) && \
11956 !intel_compare_link_m_n(&current_config->alt_name, \
11957 &pipe_config->name, adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011958 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011959 "(expected tu %i gmch %i/%i link %i/%i, " \
11960 "or tu %i gmch %i/%i link %i/%i, " \
11961 "found tu %i, gmch %i/%i link %i/%i)\n", \
11962 current_config->name.tu, \
11963 current_config->name.gmch_m, \
11964 current_config->name.gmch_n, \
11965 current_config->name.link_m, \
11966 current_config->name.link_n, \
11967 current_config->alt_name.tu, \
11968 current_config->alt_name.gmch_m, \
11969 current_config->alt_name.gmch_n, \
11970 current_config->alt_name.link_m, \
11971 current_config->alt_name.link_n, \
11972 pipe_config->name.tu, \
11973 pipe_config->name.gmch_m, \
11974 pipe_config->name.gmch_n, \
11975 pipe_config->name.link_m, \
11976 pipe_config->name.link_n); \
11977 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011978 } \
11979} while (0)
Daniel Vetter88adfff2013-03-28 10:42:01 +010011980
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011981#define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011982 if ((current_config->name ^ pipe_config->name) & (mask)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011983 pipe_config_err(adjust, __stringify(name), \
11984 "(%x) (expected %i, found %i)\n", \
11985 (mask), \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011986 current_config->name & (mask), \
11987 pipe_config->name & (mask)); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011988 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011989 } \
11990} while (0)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011991
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011992#define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011993 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011994 pipe_config_err(adjust, __stringify(name), \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011995 "(expected %i, found %i)\n", \
11996 current_config->name, \
11997 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011998 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011999 } \
12000} while (0)
Ville Syrjälä5e550652013-09-06 23:29:07 +030012001
Daniel Vetterbb760062013-06-06 14:55:52 +020012002#define PIPE_CONF_QUIRK(quirk) \
12003 ((current_config->quirks | pipe_config->quirks) & (quirk))
12004
Daniel Vettereccb1402013-05-22 00:50:22 +020012005 PIPE_CONF_CHECK_I(cpu_transcoder);
12006
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012007 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
Daniel Vetter08a24032013-04-19 11:25:34 +020012008 PIPE_CONF_CHECK_I(fdi_lanes);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012009 PIPE_CONF_CHECK_M_N(fdi_m_n);
Daniel Vetter08a24032013-04-19 11:25:34 +020012010
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030012011 PIPE_CONF_CHECK_I(lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +030012012 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070012013
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012014 if (INTEL_GEN(dev_priv) < 8) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012015 PIPE_CONF_CHECK_M_N(dp_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070012016
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012017 if (current_config->has_drrs)
12018 PIPE_CONF_CHECK_M_N(dp_m2_n2);
12019 } else
12020 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +030012021
Ville Syrjälä253c84c2016-06-22 21:57:01 +030012022 PIPE_CONF_CHECK_X(output_types);
Jani Nikulaa65347b2015-11-27 12:21:46 +020012023
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012024 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
12025 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
12026 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
12027 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
12028 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
12029 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012030
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012031 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
12032 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
12033 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
12034 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
12035 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
12036 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012037
Daniel Vetterc93f54c2013-06-27 19:47:19 +020012038 PIPE_CONF_CHECK_I(pixel_multiplier);
Shashank Sharmad9facae2018-10-12 11:53:07 +053012039 PIPE_CONF_CHECK_I(output_format);
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012040 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010012041 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010012042 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012043 PIPE_CONF_CHECK_BOOL(limited_color_range);
Shashank Sharma15953632017-03-13 16:54:03 +053012044
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012045 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
12046 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
Maarten Lankhorst4493e092017-11-10 12:34:56 +010012047 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
Daniel Vetter6c49f242013-06-06 12:45:25 +020012048
Maarten Lankhorst4493e092017-11-10 12:34:56 +010012049 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
Daniel Vetter9ed109a2014-04-24 23:54:52 +020012050
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012051 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012052 DRM_MODE_FLAG_INTERLACE);
12053
Daniel Vetterbb760062013-06-06 14:55:52 +020012054 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012055 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020012056 DRM_MODE_FLAG_PHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012057 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020012058 DRM_MODE_FLAG_NHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012059 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020012060 DRM_MODE_FLAG_PVSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012061 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020012062 DRM_MODE_FLAG_NVSYNC);
12063 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -070012064
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030012065 PIPE_CONF_CHECK_X(gmch_pfit.control);
Daniel Vettere2ff2d42015-07-15 14:15:50 +020012066 /* pfit ratios are autocomputed by the hw on gen4+ */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012067 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä7f7d8dd2016-03-15 16:40:07 +020012068 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030012069 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
Daniel Vetter99535992014-04-13 12:00:33 +020012070
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020012071 if (!adjust) {
12072 PIPE_CONF_CHECK_I(pipe_src_w);
12073 PIPE_CONF_CHECK_I(pipe_src_h);
12074
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012075 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020012076 if (current_config->pch_pfit.enabled) {
12077 PIPE_CONF_CHECK_X(pch_pfit.pos);
12078 PIPE_CONF_CHECK_X(pch_pfit.size);
12079 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +020012080
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020012081 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020012082 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020012083 }
Chandra Kondurua1b22782015-04-07 15:28:45 -070012084
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012085 PIPE_CONF_CHECK_BOOL(double_wide);
Ville Syrjälä282740f2013-09-04 18:30:03 +030012086
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012087 PIPE_CONF_CHECK_P(shared_dpll);
Daniel Vetter66e985c2013-06-05 13:34:20 +020012088 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
Daniel Vetter8bcc2792013-06-05 13:34:28 +020012089 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
Daniel Vetter66e985c2013-06-05 13:34:20 +020012090 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
12091 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -030012092 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
Maarten Lankhorst00490c22015-11-16 14:42:12 +010012093 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
Damien Lespiau3f4cd192014-11-13 14:55:21 +000012094 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
12095 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
12096 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
Paulo Zanoni2de38132017-09-22 17:53:42 -030012097 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
12098 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
12099 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
12100 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
12101 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
12102 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
12103 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
12104 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
12105 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
12106 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
12107 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
12108 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
Paulo Zanonic27e9172018-04-27 16:14:36 -070012109 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
12110 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
12111 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
12112 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
12113 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
12114 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
12115 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
12116 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
12117 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
12118 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
Daniel Vetterc0d43d62013-06-07 23:11:08 +020012119
Ville Syrjälä47eacba2016-04-12 22:14:35 +030012120 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
12121 PIPE_CONF_CHECK_X(dsi_pll.div);
12122
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010012123 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä42571ae2013-09-06 23:29:00 +030012124 PIPE_CONF_CHECK_I(pipe_bpp);
12125
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012126 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
Jesse Barnesa9a7e982014-01-20 14:18:04 -080012127 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
Ville Syrjälä5e550652013-09-06 23:29:07 +030012128
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030012129 PIPE_CONF_CHECK_I(min_voltage_level);
12130
Daniel Vetter66e985c2013-06-05 13:34:20 +020012131#undef PIPE_CONF_CHECK_X
Daniel Vetter08a24032013-04-19 11:25:34 +020012132#undef PIPE_CONF_CHECK_I
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012133#undef PIPE_CONF_CHECK_BOOL
Maarten Lankhorst4493e092017-11-10 12:34:56 +010012134#undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012135#undef PIPE_CONF_CHECK_P
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012136#undef PIPE_CONF_CHECK_FLAGS
Ville Syrjälä5e550652013-09-06 23:29:07 +030012137#undef PIPE_CONF_CHECK_CLOCK_FUZZY
Daniel Vetterbb760062013-06-06 14:55:52 +020012138#undef PIPE_CONF_QUIRK
Daniel Vetter627eb5a2013-04-29 19:33:42 +020012139
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012140 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010012141}
12142
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020012143static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
12144 const struct intel_crtc_state *pipe_config)
12145{
12146 if (pipe_config->has_pch_encoder) {
Ville Syrjälä21a727b2016-02-17 21:41:10 +020012147 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020012148 &pipe_config->fdi_m_n);
12149 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
12150
12151 /*
12152 * FDI already provided one idea for the dotclock.
12153 * Yell if the encoder disagrees.
12154 */
12155 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
12156 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12157 fdi_dotclock, dotclock);
12158 }
12159}
12160
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012161static void verify_wm_state(struct drm_crtc *crtc,
12162 struct drm_crtc_state *new_state)
Damien Lespiau08db6652014-11-04 17:06:52 +000012163{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012164 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Damien Lespiau08db6652014-11-04 17:06:52 +000012165 struct skl_ddb_allocation hw_ddb, *sw_ddb;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012166 struct skl_pipe_wm hw_wm, *sw_wm;
12167 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
12168 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012169 struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES];
12170 struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012171 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12172 const enum pipe pipe = intel_crtc->pipe;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012173 int plane, level, max_level = ilk_wm_max_level(dev_priv);
Damien Lespiau08db6652014-11-04 17:06:52 +000012174
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012175 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
Damien Lespiau08db6652014-11-04 17:06:52 +000012176 return;
12177
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012178 skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm);
Maarten Lankhorst03af79e2016-10-26 15:41:36 +020012179 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012180
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012181 skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv);
12182
Damien Lespiau08db6652014-11-04 17:06:52 +000012183 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
12184 sw_ddb = &dev_priv->wm.skl_hw.ddb;
12185
Mahesh Kumar74bd8002018-04-26 19:55:15 +053012186 if (INTEL_GEN(dev_priv) >= 11)
12187 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
12188 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
12189 sw_ddb->enabled_slices,
12190 hw_ddb.enabled_slices);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012191 /* planes */
Matt Roper8b364b42016-10-26 15:51:28 -070012192 for_each_universal_plane(dev_priv, pipe, plane) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012193 hw_plane_wm = &hw_wm.planes[plane];
12194 sw_plane_wm = &sw_wm->planes[plane];
Damien Lespiau08db6652014-11-04 17:06:52 +000012195
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012196 /* Watermarks */
12197 for (level = 0; level <= max_level; level++) {
12198 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12199 &sw_plane_wm->wm[level]))
12200 continue;
Damien Lespiau08db6652014-11-04 17:06:52 +000012201
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012202 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",
12203 pipe_name(pipe), plane + 1, level,
12204 sw_plane_wm->wm[level].plane_en,
12205 sw_plane_wm->wm[level].plane_res_b,
12206 sw_plane_wm->wm[level].plane_res_l,
12207 hw_plane_wm->wm[level].plane_en,
12208 hw_plane_wm->wm[level].plane_res_b,
12209 hw_plane_wm->wm[level].plane_res_l);
12210 }
12211
12212 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12213 &sw_plane_wm->trans_wm)) {
12214 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",
12215 pipe_name(pipe), plane + 1,
12216 sw_plane_wm->trans_wm.plane_en,
12217 sw_plane_wm->trans_wm.plane_res_b,
12218 sw_plane_wm->trans_wm.plane_res_l,
12219 hw_plane_wm->trans_wm.plane_en,
12220 hw_plane_wm->trans_wm.plane_res_b,
12221 hw_plane_wm->trans_wm.plane_res_l);
12222 }
12223
12224 /* DDB */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012225 hw_ddb_entry = &hw_ddb_y[plane];
12226 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane];
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012227
12228 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040012229 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 -040012230 pipe_name(pipe), plane + 1,
12231 sw_ddb_entry->start, sw_ddb_entry->end,
12232 hw_ddb_entry->start, hw_ddb_entry->end);
12233 }
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012234 }
12235
Lyude27082492016-08-24 07:48:10 +020012236 /*
12237 * cursor
12238 * If the cursor plane isn't active, we may not have updated it's ddb
12239 * allocation. In that case since the ddb allocation will be updated
12240 * once the plane becomes visible, we can skip this check
12241 */
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030012242 if (1) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012243 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
12244 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012245
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012246 /* Watermarks */
12247 for (level = 0; level <= max_level; level++) {
12248 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12249 &sw_plane_wm->wm[level]))
12250 continue;
12251
12252 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",
12253 pipe_name(pipe), level,
12254 sw_plane_wm->wm[level].plane_en,
12255 sw_plane_wm->wm[level].plane_res_b,
12256 sw_plane_wm->wm[level].plane_res_l,
12257 hw_plane_wm->wm[level].plane_en,
12258 hw_plane_wm->wm[level].plane_res_b,
12259 hw_plane_wm->wm[level].plane_res_l);
12260 }
12261
12262 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12263 &sw_plane_wm->trans_wm)) {
12264 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12265 pipe_name(pipe),
12266 sw_plane_wm->trans_wm.plane_en,
12267 sw_plane_wm->trans_wm.plane_res_b,
12268 sw_plane_wm->trans_wm.plane_res_l,
12269 hw_plane_wm->trans_wm.plane_en,
12270 hw_plane_wm->trans_wm.plane_res_b,
12271 hw_plane_wm->trans_wm.plane_res_l);
12272 }
12273
12274 /* DDB */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012275 hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR];
12276 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR];
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012277
12278 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040012279 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
Lyude27082492016-08-24 07:48:10 +020012280 pipe_name(pipe),
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012281 sw_ddb_entry->start, sw_ddb_entry->end,
12282 hw_ddb_entry->start, hw_ddb_entry->end);
Lyude27082492016-08-24 07:48:10 +020012283 }
Damien Lespiau08db6652014-11-04 17:06:52 +000012284 }
12285}
12286
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012287static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012288verify_connector_state(struct drm_device *dev,
12289 struct drm_atomic_state *state,
12290 struct drm_crtc *crtc)
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012291{
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012292 struct drm_connector *connector;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012293 struct drm_connector_state *new_conn_state;
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012294 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012295
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012296 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012297 struct drm_encoder *encoder = connector->encoder;
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012298 struct drm_crtc_state *crtc_state = NULL;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012299
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012300 if (new_conn_state->crtc != crtc)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012301 continue;
12302
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012303 if (crtc)
12304 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
12305
12306 intel_connector_verify_state(crtc_state, new_conn_state);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012307
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012308 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012309 "connector's atomic encoder doesn't match legacy encoder\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012310 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012311}
12312
12313static void
Daniel Vetter86b04262017-03-01 10:52:26 +010012314verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012315{
12316 struct intel_encoder *encoder;
Daniel Vetter86b04262017-03-01 10:52:26 +010012317 struct drm_connector *connector;
12318 struct drm_connector_state *old_conn_state, *new_conn_state;
12319 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012320
Damien Lespiaub2784e12014-08-05 11:29:37 +010012321 for_each_intel_encoder(dev, encoder) {
Daniel Vetter86b04262017-03-01 10:52:26 +010012322 bool enabled = false, found = false;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012323 enum pipe pipe;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012324
12325 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12326 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030012327 encoder->base.name);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012328
Daniel Vetter86b04262017-03-01 10:52:26 +010012329 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
12330 new_conn_state, i) {
12331 if (old_conn_state->best_encoder == &encoder->base)
12332 found = true;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012333
Daniel Vetter86b04262017-03-01 10:52:26 +010012334 if (new_conn_state->best_encoder != &encoder->base)
12335 continue;
12336 found = enabled = true;
12337
12338 I915_STATE_WARN(new_conn_state->crtc !=
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012339 encoder->base.crtc,
12340 "connector's crtc doesn't match encoder crtc\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012341 }
Daniel Vetter86b04262017-03-01 10:52:26 +010012342
12343 if (!found)
12344 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +100012345
Rob Clarke2c719b2014-12-15 13:56:32 -050012346 I915_STATE_WARN(!!encoder->base.crtc != enabled,
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012347 "encoder's enabled state mismatch "
12348 "(expected %i, found %i)\n",
12349 !!encoder->base.crtc, enabled);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012350
12351 if (!encoder->base.crtc) {
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012352 bool active;
12353
12354 active = encoder->get_hw_state(encoder, &pipe);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012355 I915_STATE_WARN(active,
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012356 "encoder detached but still enabled on pipe %c.\n",
12357 pipe_name(pipe));
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012358 }
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012359 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012360}
12361
12362static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012363verify_crtc_state(struct drm_crtc *crtc,
12364 struct drm_crtc_state *old_crtc_state,
12365 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012366{
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012367 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010012368 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012369 struct intel_encoder *encoder;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012370 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12371 struct intel_crtc_state *pipe_config, *sw_config;
12372 struct drm_atomic_state *old_state;
12373 bool active;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012374
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012375 old_state = old_crtc_state->state;
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020012376 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012377 pipe_config = to_intel_crtc_state(old_crtc_state);
12378 memset(pipe_config, 0, sizeof(*pipe_config));
12379 pipe_config->base.crtc = crtc;
12380 pipe_config->base.state = old_state;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012381
Ville Syrjälä78108b72016-05-27 20:59:19 +030012382 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012383
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012384 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012385
Ville Syrjäläe56134b2017-06-01 17:36:19 +030012386 /* we keep both pipes enabled on 830 */
12387 if (IS_I830(dev_priv))
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012388 active = new_crtc_state->active;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012389
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012390 I915_STATE_WARN(new_crtc_state->active != active,
12391 "crtc active state doesn't match with hw state "
12392 "(expected %i, found %i)\n", new_crtc_state->active, active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012393
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012394 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12395 "transitional active state does not match atomic hw state "
12396 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012397
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012398 for_each_encoder_on_crtc(dev, crtc, encoder) {
12399 enum pipe pipe;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012400
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012401 active = encoder->get_hw_state(encoder, &pipe);
12402 I915_STATE_WARN(active != new_crtc_state->active,
12403 "[ENCODER:%i] active %i with crtc active %i\n",
12404 encoder->base.base.id, active, new_crtc_state->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012405
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012406 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12407 "Encoder connected to wrong pipe %c\n",
12408 pipe_name(pipe));
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012409
Ville Syrjäläe1214b92017-10-27 22:31:23 +030012410 if (active)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012411 encoder->get_config(encoder, pipe_config);
12412 }
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012413
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020012414 intel_crtc_compute_pixel_rate(pipe_config);
12415
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012416 if (!new_crtc_state->active)
12417 return;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012418
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012419 intel_pipe_config_sanity_check(dev_priv, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012420
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012421 sw_config = to_intel_crtc_state(new_crtc_state);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012422 if (!intel_pipe_config_compare(dev_priv, sw_config,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012423 pipe_config, false)) {
12424 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12425 intel_dump_pipe_config(intel_crtc, pipe_config,
12426 "[hw state]");
12427 intel_dump_pipe_config(intel_crtc, sw_config,
12428 "[sw state]");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012429 }
12430}
12431
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012432static void
Ville Syrjäläcff109f2017-11-17 21:19:17 +020012433intel_verify_planes(struct intel_atomic_state *state)
12434{
12435 struct intel_plane *plane;
12436 const struct intel_plane_state *plane_state;
12437 int i;
12438
12439 for_each_new_intel_plane_in_state(state, plane,
12440 plane_state, i)
12441 assert_plane(plane, plane_state->base.visible);
12442}
12443
12444static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012445verify_single_dpll_state(struct drm_i915_private *dev_priv,
12446 struct intel_shared_dpll *pll,
12447 struct drm_crtc *crtc,
12448 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012449{
12450 struct intel_dpll_hw_state dpll_hw_state;
Ville Syrjälä40560e22018-06-26 22:47:11 +030012451 unsigned int crtc_mask;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012452 bool active;
12453
12454 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12455
Lucas De Marchi72f775f2018-03-20 15:06:34 -070012456 DRM_DEBUG_KMS("%s\n", pll->info->name);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012457
Lucas De Marchiee1398b2018-03-20 15:06:33 -070012458 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012459
Lucas De Marchi5cd281f2018-03-20 15:06:36 -070012460 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012461 I915_STATE_WARN(!pll->on && pll->active_mask,
12462 "pll in active use but not on in sw tracking\n");
12463 I915_STATE_WARN(pll->on && !pll->active_mask,
12464 "pll is on but not used by any active crtc\n");
12465 I915_STATE_WARN(pll->on != active,
12466 "pll on state mismatch (expected %i, found %i)\n",
12467 pll->on, active);
12468 }
12469
12470 if (!crtc) {
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012471 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012472 "more active pll users than references: %x vs %x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012473 pll->active_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012474
12475 return;
12476 }
12477
Ville Syrjälä40560e22018-06-26 22:47:11 +030012478 crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012479
12480 if (new_state->active)
12481 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12482 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12483 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12484 else
12485 I915_STATE_WARN(pll->active_mask & crtc_mask,
12486 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12487 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12488
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012489 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012490 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012491 crtc_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012492
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012493 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012494 &dpll_hw_state,
12495 sizeof(dpll_hw_state)),
12496 "pll hw state mismatch\n");
12497}
12498
12499static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012500verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12501 struct drm_crtc_state *old_crtc_state,
12502 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012503{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012504 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012505 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12506 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12507
12508 if (new_state->shared_dpll)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012509 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012510
12511 if (old_state->shared_dpll &&
12512 old_state->shared_dpll != new_state->shared_dpll) {
Ville Syrjälä40560e22018-06-26 22:47:11 +030012513 unsigned int crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012514 struct intel_shared_dpll *pll = old_state->shared_dpll;
12515
12516 I915_STATE_WARN(pll->active_mask & crtc_mask,
12517 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12518 pipe_name(drm_crtc_index(crtc)));
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012519 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012520 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12521 pipe_name(drm_crtc_index(crtc)));
12522 }
12523}
12524
12525static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012526intel_modeset_verify_crtc(struct drm_crtc *crtc,
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012527 struct drm_atomic_state *state,
12528 struct drm_crtc_state *old_state,
12529 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012530{
Daniel Vetter5a21b662016-05-24 17:13:53 +020012531 if (!needs_modeset(new_state) &&
12532 !to_intel_crtc_state(new_state)->update_pipe)
12533 return;
12534
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012535 verify_wm_state(crtc, new_state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012536 verify_connector_state(crtc->dev, state, crtc);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012537 verify_crtc_state(crtc, old_state, new_state);
12538 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012539}
12540
12541static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012542verify_disabled_dpll_state(struct drm_device *dev)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012543{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012544 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012545 int i;
Daniel Vetter53589012013-06-05 13:34:16 +020012546
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012547 for (i = 0; i < dev_priv->num_shared_dpll; i++)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012548 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012549}
Daniel Vetter53589012013-06-05 13:34:16 +020012550
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012551static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012552intel_modeset_verify_disabled(struct drm_device *dev,
12553 struct drm_atomic_state *state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012554{
Daniel Vetter86b04262017-03-01 10:52:26 +010012555 verify_encoder_state(dev, state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012556 verify_connector_state(dev, state, NULL);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012557 verify_disabled_dpll_state(dev);
Daniel Vetter25c5b262012-07-08 22:08:04 +020012558}
12559
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012560static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012561{
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012562 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012563 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä80715b22014-05-15 20:23:23 +030012564
12565 /*
12566 * The scanline counter increments at the leading edge of hsync.
12567 *
12568 * On most platforms it starts counting from vtotal-1 on the
12569 * first active line. That means the scanline counter value is
12570 * always one less than what we would expect. Ie. just after
12571 * start of vblank, which also occurs at start of hsync (on the
12572 * last active line), the scanline counter will read vblank_start-1.
12573 *
12574 * On gen2 the scanline counter starts counting from 1 instead
12575 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12576 * to keep the value positive), instead of adding one.
12577 *
12578 * On HSW+ the behaviour of the scanline counter depends on the output
12579 * type. For DP ports it behaves like most other platforms, but on HDMI
12580 * there's an extra 1 line difference. So we need to add two instead of
12581 * one to the value.
Ville Syrjäläec1b4ee2016-12-15 19:47:34 +020012582 *
12583 * On VLV/CHV DSI the scanline counter would appear to increment
12584 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12585 * that means we can't tell whether we're in vblank or not while
12586 * we're on that particular line. We must still set scanline_offset
12587 * to 1 so that the vblank timestamps come out correct when we query
12588 * the scanline counter from within the vblank interrupt handler.
12589 * However if queried just before the start of vblank we'll get an
12590 * answer that's slightly in the future.
Ville Syrjälä80715b22014-05-15 20:23:23 +030012591 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080012592 if (IS_GEN(dev_priv, 2)) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012593 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä80715b22014-05-15 20:23:23 +030012594 int vtotal;
12595
Ville Syrjälä124abe02015-09-08 13:40:45 +030012596 vtotal = adjusted_mode->crtc_vtotal;
12597 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012598 vtotal /= 2;
12599
12600 crtc->scanline_offset = vtotal - 1;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012601 } else if (HAS_DDI(dev_priv) &&
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012602 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
Ville Syrjälä80715b22014-05-15 20:23:23 +030012603 crtc->scanline_offset = 2;
12604 } else
12605 crtc->scanline_offset = 1;
12606}
12607
Maarten Lankhorstad421372015-06-15 12:33:42 +020012608static void intel_modeset_clear_plls(struct drm_atomic_state *state)
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012609{
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012610 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012611 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012612 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012613 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012614 int i;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012615
12616 if (!dev_priv->display.crtc_compute_clock)
Maarten Lankhorstad421372015-06-15 12:33:42 +020012617 return;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012618
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012619 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012620 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012621 struct intel_shared_dpll *old_dpll =
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012622 to_intel_crtc_state(old_crtc_state)->shared_dpll;
Maarten Lankhorstad421372015-06-15 12:33:42 +020012623
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012624 if (!needs_modeset(new_crtc_state))
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012625 continue;
12626
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012627 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012628
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012629 if (!old_dpll)
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012630 continue;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012631
Ander Conselvan de Oliveiraa1c414e2016-12-29 17:22:07 +020012632 intel_release_shared_dpll(old_dpll, intel_crtc, state);
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012633 }
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012634}
12635
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012636/*
12637 * This implements the workaround described in the "notes" section of the mode
12638 * set sequence documentation. When going from no pipes or single pipe to
12639 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12640 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12641 */
12642static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12643{
12644 struct drm_crtc_state *crtc_state;
12645 struct intel_crtc *intel_crtc;
12646 struct drm_crtc *crtc;
12647 struct intel_crtc_state *first_crtc_state = NULL;
12648 struct intel_crtc_state *other_crtc_state = NULL;
12649 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12650 int i;
12651
12652 /* look at all crtc's that are going to be enabled in during modeset */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012653 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012654 intel_crtc = to_intel_crtc(crtc);
12655
12656 if (!crtc_state->active || !needs_modeset(crtc_state))
12657 continue;
12658
12659 if (first_crtc_state) {
12660 other_crtc_state = to_intel_crtc_state(crtc_state);
12661 break;
12662 } else {
12663 first_crtc_state = to_intel_crtc_state(crtc_state);
12664 first_pipe = intel_crtc->pipe;
12665 }
12666 }
12667
12668 /* No workaround needed? */
12669 if (!first_crtc_state)
12670 return 0;
12671
12672 /* w/a possibly needed, check how many crtc's are already enabled. */
12673 for_each_intel_crtc(state->dev, intel_crtc) {
12674 struct intel_crtc_state *pipe_config;
12675
12676 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12677 if (IS_ERR(pipe_config))
12678 return PTR_ERR(pipe_config);
12679
12680 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12681
12682 if (!pipe_config->base.active ||
12683 needs_modeset(&pipe_config->base))
12684 continue;
12685
12686 /* 2 or more enabled crtcs means no need for w/a */
12687 if (enabled_pipe != INVALID_PIPE)
12688 return 0;
12689
12690 enabled_pipe = intel_crtc->pipe;
12691 }
12692
12693 if (enabled_pipe != INVALID_PIPE)
12694 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12695 else if (other_crtc_state)
12696 other_crtc_state->hsw_workaround_pipe = first_pipe;
12697
12698 return 0;
12699}
12700
Ville Syrjälä8d965612016-11-14 18:35:10 +020012701static int intel_lock_all_pipes(struct drm_atomic_state *state)
12702{
12703 struct drm_crtc *crtc;
12704
12705 /* Add all pipes to the state */
12706 for_each_crtc(state->dev, crtc) {
12707 struct drm_crtc_state *crtc_state;
12708
12709 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12710 if (IS_ERR(crtc_state))
12711 return PTR_ERR(crtc_state);
12712 }
12713
12714 return 0;
12715}
12716
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012717static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12718{
12719 struct drm_crtc *crtc;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012720
Ville Syrjälä8d965612016-11-14 18:35:10 +020012721 /*
12722 * Add all pipes to the state, and force
12723 * a modeset on all the active ones.
12724 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012725 for_each_crtc(state->dev, crtc) {
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012726 struct drm_crtc_state *crtc_state;
12727 int ret;
12728
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012729 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12730 if (IS_ERR(crtc_state))
12731 return PTR_ERR(crtc_state);
12732
12733 if (!crtc_state->active || needs_modeset(crtc_state))
12734 continue;
12735
12736 crtc_state->mode_changed = true;
12737
12738 ret = drm_atomic_add_affected_connectors(state, crtc);
12739 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012740 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012741
12742 ret = drm_atomic_add_affected_planes(state, crtc);
12743 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012744 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012745 }
12746
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012747 return 0;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012748}
12749
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012750static int intel_modeset_checks(struct drm_atomic_state *state)
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012751{
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012752 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012753 struct drm_i915_private *dev_priv = to_i915(state->dev);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012754 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012755 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012756 int ret = 0, i;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012757
Maarten Lankhorstb3592832015-06-15 12:33:38 +020012758 if (!check_digital_port_conflicts(state)) {
12759 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12760 return -EINVAL;
12761 }
12762
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012763 intel_state->modeset = true;
12764 intel_state->active_crtcs = dev_priv->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012765 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12766 intel_state->cdclk.actual = dev_priv->cdclk.actual;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012767
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012768 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12769 if (new_crtc_state->active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012770 intel_state->active_crtcs |= 1 << i;
12771 else
12772 intel_state->active_crtcs &= ~(1 << i);
Matt Roper8b4a7d02016-05-12 07:06:00 -070012773
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012774 if (old_crtc_state->active != new_crtc_state->active)
Matt Roper8b4a7d02016-05-12 07:06:00 -070012775 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012776 }
12777
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012778 /*
12779 * See if the config requires any additional preparation, e.g.
12780 * to adjust global state with pipes off. We need to do this
12781 * here so we can get the modeset_pipe updated config for the new
12782 * mode set on this crtc. For other crtcs we need to use the
12783 * adjusted_mode bits in the crtc directly.
12784 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012785 if (dev_priv->display.modeset_calc_cdclk) {
Clint Taylorc89e39f2016-05-13 23:41:21 +030012786 ret = dev_priv->display.modeset_calc_cdclk(state);
12787 if (ret < 0)
12788 return ret;
12789
Ville Syrjälä8d965612016-11-14 18:35:10 +020012790 /*
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012791 * Writes to dev_priv->cdclk.logical must protected by
Ville Syrjälä8d965612016-11-14 18:35:10 +020012792 * holding all the crtc locks, even if we don't end up
12793 * touching the hardware
12794 */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012795 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12796 &intel_state->cdclk.logical)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012797 ret = intel_lock_all_pipes(state);
12798 if (ret < 0)
12799 return ret;
12800 }
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012801
Ville Syrjälä8d965612016-11-14 18:35:10 +020012802 /* All pipes must be switched off while we change the cdclk. */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012803 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12804 &intel_state->cdclk.actual)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012805 ret = intel_modeset_all_pipes(state);
12806 if (ret < 0)
12807 return ret;
12808 }
Maarten Lankhorste8788cb2016-02-16 10:25:11 +010012809
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012810 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12811 intel_state->cdclk.logical.cdclk,
12812 intel_state->cdclk.actual.cdclk);
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030012813 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12814 intel_state->cdclk.logical.voltage_level,
12815 intel_state->cdclk.actual.voltage_level);
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012816 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012817 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012818 }
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012819
Maarten Lankhorstad421372015-06-15 12:33:42 +020012820 intel_modeset_clear_plls(state);
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012821
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012822 if (IS_HASWELL(dev_priv))
Maarten Lankhorstad421372015-06-15 12:33:42 +020012823 return haswell_mode_set_planes_workaround(state);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012824
Maarten Lankhorstad421372015-06-15 12:33:42 +020012825 return 0;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012826}
12827
Matt Roperaa363132015-09-24 15:53:18 -070012828/*
12829 * Handle calculation of various watermark data at the end of the atomic check
12830 * phase. The code here should be run after the per-crtc and per-plane 'check'
12831 * handlers to ensure that all derived state has been updated.
12832 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012833static int calc_watermark_data(struct intel_atomic_state *state)
Matt Roperaa363132015-09-24 15:53:18 -070012834{
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012835 struct drm_device *dev = state->base.dev;
Matt Roper98d39492016-05-12 07:06:03 -070012836 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roper98d39492016-05-12 07:06:03 -070012837
12838 /* Is there platform-specific watermark information to calculate? */
12839 if (dev_priv->display.compute_global_watermarks)
Matt Roper55994c22016-05-12 07:06:08 -070012840 return dev_priv->display.compute_global_watermarks(state);
12841
12842 return 0;
Matt Roperaa363132015-09-24 15:53:18 -070012843}
12844
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012845/**
12846 * intel_atomic_check - validate state object
12847 * @dev: drm device
12848 * @state: state to validate
12849 */
12850static int intel_atomic_check(struct drm_device *dev,
12851 struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012852{
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012853 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roperaa363132015-09-24 15:53:18 -070012854 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012855 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012856 struct drm_crtc_state *old_crtc_state, *crtc_state;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012857 int ret, i;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012858 bool any_ms = false;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012859
Maarten Lankhorst8c58f732018-02-21 10:28:08 +010012860 /* Catch I915_MODE_FLAG_INHERITED */
12861 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12862 crtc_state, i) {
12863 if (crtc_state->mode.private_flags !=
12864 old_crtc_state->mode.private_flags)
12865 crtc_state->mode_changed = true;
12866 }
12867
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012868 ret = drm_atomic_helper_check_modeset(dev, state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012869 if (ret)
12870 return ret;
12871
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012872 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012873 struct intel_crtc_state *pipe_config =
12874 to_intel_crtc_state(crtc_state);
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012875
Daniel Vetter26495482015-07-15 14:15:52 +020012876 if (!needs_modeset(crtc_state))
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012877 continue;
12878
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012879 if (!crtc_state->enable) {
12880 any_ms = true;
12881 continue;
12882 }
12883
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012884 ret = intel_modeset_pipe_config(crtc, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020012885 if (ret == -EDEADLK)
12886 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012887 if (ret) {
12888 intel_dump_pipe_config(to_intel_crtc(crtc),
12889 pipe_config, "[failed]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012890 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012891 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012892
Maarten Lankhorstd19f9582019-01-08 17:08:40 +010012893 if (intel_pipe_config_compare(dev_priv,
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012894 to_intel_crtc_state(old_crtc_state),
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012895 pipe_config, true)) {
Daniel Vetter26495482015-07-15 14:15:52 +020012896 crtc_state->mode_changed = false;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012897 pipe_config->update_pipe = true;
Daniel Vetter26495482015-07-15 14:15:52 +020012898 }
12899
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012900 if (needs_modeset(crtc_state))
Daniel Vetter26495482015-07-15 14:15:52 +020012901 any_ms = true;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012902
Daniel Vetter26495482015-07-15 14:15:52 +020012903 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12904 needs_modeset(crtc_state) ?
12905 "[modeset]" : "[fastset]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012906 }
12907
Lyude Pauleceae142019-01-10 19:53:41 -050012908 ret = drm_dp_mst_atomic_check(state);
12909 if (ret)
12910 return ret;
12911
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012912 if (any_ms) {
12913 ret = intel_modeset_checks(state);
12914
12915 if (ret)
12916 return ret;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012917 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012918 intel_state->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012919 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012920
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020012921 ret = icl_add_linked_planes(intel_state);
12922 if (ret)
12923 return ret;
12924
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012925 ret = drm_atomic_helper_check_planes(dev, state);
Matt Roperaa363132015-09-24 15:53:18 -070012926 if (ret)
12927 return ret;
12928
Ville Syrjälädd576022017-11-17 21:19:14 +020012929 intel_fbc_choose_crtc(dev_priv, intel_state);
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012930 return calc_watermark_data(intel_state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012931}
12932
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012933static int intel_atomic_prepare_commit(struct drm_device *dev,
Chris Wilsond07f0e52016-10-28 13:58:44 +010012934 struct drm_atomic_state *state)
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012935{
Chris Wilsonfd700752017-07-26 17:00:36 +010012936 return drm_atomic_helper_prepare_planes(dev, state);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012937}
12938
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012939u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12940{
12941 struct drm_device *dev = crtc->base.dev;
Ville Syrjälä32db0b62018-11-27 22:05:50 +020012942 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012943
Ville Syrjälä32db0b62018-11-27 22:05:50 +020012944 if (!vblank->max_vblank_count)
Dhinakaran Pandiyan734cbbf2018-02-02 21:12:54 -080012945 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012946
12947 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12948}
12949
Lyude896e5bb2016-08-24 07:48:09 +020012950static void intel_update_crtc(struct drm_crtc *crtc,
12951 struct drm_atomic_state *state,
12952 struct drm_crtc_state *old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012953 struct drm_crtc_state *new_crtc_state)
Lyude896e5bb2016-08-24 07:48:09 +020012954{
12955 struct drm_device *dev = crtc->dev;
12956 struct drm_i915_private *dev_priv = to_i915(dev);
12957 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012958 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12959 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012960 struct intel_plane_state *new_plane_state =
12961 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12962 to_intel_plane(crtc->primary));
Lyude896e5bb2016-08-24 07:48:09 +020012963
12964 if (modeset) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012965 update_scanline_offset(pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020012966 dev_priv->display.crtc_enable(pipe_config, state);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012967
12968 /* vblanks work again, re-enable pipe CRC. */
12969 intel_crtc_enable_pipe_crc(intel_crtc);
Lyude896e5bb2016-08-24 07:48:09 +020012970 } else {
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012971 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12972 pipe_config);
Hans de Goede608ed4a2018-12-20 14:21:18 +010012973
12974 if (pipe_config->update_pipe)
12975 intel_encoders_update_pipe(crtc, pipe_config, state);
Lyude896e5bb2016-08-24 07:48:09 +020012976 }
12977
Maarten Lankhorst50c42fc2018-12-20 16:17:19 +010012978 if (pipe_config->update_pipe && !pipe_config->enable_fbc)
12979 intel_fbc_disable(intel_crtc);
12980 else if (new_plane_state)
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012981 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
Lyude896e5bb2016-08-24 07:48:09 +020012982
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012983 intel_begin_crtc_commit(crtc, old_crtc_state);
12984
Ville Syrjälä5f2e5112018-11-14 23:07:27 +020012985 if (INTEL_GEN(dev_priv) >= 9)
12986 skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
12987 else
12988 i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012989
12990 intel_finish_crtc_commit(crtc, old_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012991}
12992
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012993static void intel_update_crtcs(struct drm_atomic_state *state)
Lyude896e5bb2016-08-24 07:48:09 +020012994{
12995 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012996 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyude896e5bb2016-08-24 07:48:09 +020012997 int i;
12998
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012999 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13000 if (!new_crtc_state->active)
Lyude896e5bb2016-08-24 07:48:09 +020013001 continue;
13002
13003 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013004 new_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020013005 }
13006}
13007
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013008static void skl_update_crtcs(struct drm_atomic_state *state)
Lyude27082492016-08-24 07:48:10 +020013009{
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020013010 struct drm_i915_private *dev_priv = to_i915(state->dev);
Lyude27082492016-08-24 07:48:10 +020013011 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13012 struct drm_crtc *crtc;
Lyudece0ba282016-09-15 10:46:35 -040013013 struct intel_crtc *intel_crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013014 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyudece0ba282016-09-15 10:46:35 -040013015 struct intel_crtc_state *cstate;
Lyude27082492016-08-24 07:48:10 +020013016 unsigned int updated = 0;
13017 bool progress;
13018 enum pipe pipe;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013019 int i;
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053013020 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
13021 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013022 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013023
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013024 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013025 /* ignore allocations for crtc's that have been turned off. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013026 if (new_crtc_state->active)
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013027 entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020013028
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053013029 /* If 2nd DBuf slice required, enable it here */
13030 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
13031 icl_dbuf_slices_update(dev_priv, required_slices);
13032
Lyude27082492016-08-24 07:48:10 +020013033 /*
13034 * Whenever the number of active pipes changes, we need to make sure we
13035 * update the pipes in the right order so that their ddb allocations
13036 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
13037 * cause pipe underruns and other bad stuff.
13038 */
13039 do {
Lyude27082492016-08-24 07:48:10 +020013040 progress = false;
13041
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013042 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Lyude27082492016-08-24 07:48:10 +020013043 bool vbl_wait = false;
13044 unsigned int cmask = drm_crtc_mask(crtc);
Lyudece0ba282016-09-15 10:46:35 -040013045
13046 intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä21794812017-08-23 18:22:26 +030013047 cstate = to_intel_crtc_state(new_crtc_state);
Lyudece0ba282016-09-15 10:46:35 -040013048 pipe = intel_crtc->pipe;
Lyude27082492016-08-24 07:48:10 +020013049
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013050 if (updated & cmask || !cstate->base.active)
Lyude27082492016-08-24 07:48:10 +020013051 continue;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013052
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013053 if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb,
Mika Kahola2b685042017-10-10 13:17:03 +030013054 entries,
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013055 INTEL_INFO(dev_priv)->num_pipes, i))
Lyude27082492016-08-24 07:48:10 +020013056 continue;
13057
13058 updated |= cmask;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013059 entries[i] = cstate->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020013060
13061 /*
13062 * If this is an already active pipe, it's DDB changed,
13063 * and this isn't the last pipe that needs updating
13064 * then we need to wait for a vblank to pass for the
13065 * new ddb allocation to take effect.
13066 */
Lyudece0ba282016-09-15 10:46:35 -040013067 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
Maarten Lankhorst512b5522016-11-08 13:55:34 +010013068 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013069 !new_crtc_state->active_changed &&
Lyude27082492016-08-24 07:48:10 +020013070 intel_state->wm_results.dirty_pipes != updated)
13071 vbl_wait = true;
13072
13073 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013074 new_crtc_state);
Lyude27082492016-08-24 07:48:10 +020013075
13076 if (vbl_wait)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020013077 intel_wait_for_vblank(dev_priv, pipe);
Lyude27082492016-08-24 07:48:10 +020013078
13079 progress = true;
13080 }
13081 } while (progress);
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053013082
13083 /* If 2nd DBuf slice is no more required disable it */
13084 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
13085 icl_dbuf_slices_update(dev_priv, required_slices);
Lyude27082492016-08-24 07:48:10 +020013086}
13087
Chris Wilsonba318c62017-02-02 20:47:41 +000013088static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
13089{
13090 struct intel_atomic_state *state, *next;
13091 struct llist_node *freed;
13092
13093 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
13094 llist_for_each_entry_safe(state, next, freed, freed)
13095 drm_atomic_state_put(&state->base);
13096}
13097
13098static void intel_atomic_helper_free_state_worker(struct work_struct *work)
13099{
13100 struct drm_i915_private *dev_priv =
13101 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
13102
13103 intel_atomic_helper_free_state(dev_priv);
13104}
13105
Daniel Vetter9db529a2017-08-08 10:08:28 +020013106static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
13107{
13108 struct wait_queue_entry wait_fence, wait_reset;
13109 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
13110
13111 init_wait_entry(&wait_fence, 0);
13112 init_wait_entry(&wait_reset, 0);
13113 for (;;) {
13114 prepare_to_wait(&intel_state->commit_ready.wait,
13115 &wait_fence, TASK_UNINTERRUPTIBLE);
13116 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
13117 &wait_reset, TASK_UNINTERRUPTIBLE);
13118
13119
13120 if (i915_sw_fence_done(&intel_state->commit_ready)
13121 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
13122 break;
13123
13124 schedule();
13125 }
13126 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
13127 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
13128}
13129
Chris Wilson8d52e442018-06-23 11:39:51 +010013130static void intel_atomic_cleanup_work(struct work_struct *work)
13131{
13132 struct drm_atomic_state *state =
13133 container_of(work, struct drm_atomic_state, commit_work);
13134 struct drm_i915_private *i915 = to_i915(state->dev);
13135
13136 drm_atomic_helper_cleanup_planes(&i915->drm, state);
13137 drm_atomic_helper_commit_cleanup_done(state);
13138 drm_atomic_state_put(state);
13139
13140 intel_atomic_helper_free_state(i915);
13141}
13142
Daniel Vetter94f05022016-06-14 18:01:00 +020013143static void intel_atomic_commit_tail(struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020013144{
Daniel Vetter94f05022016-06-14 18:01:00 +020013145 struct drm_device *dev = state->dev;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010013146 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010013147 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013148 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013149 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
Maarten Lankhorst7580d772015-08-18 13:40:06 +020013150 struct drm_crtc *crtc;
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013151 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020013152 u64 put_domains[I915_MAX_PIPES] = {};
Chris Wilson0e6e0be2019-01-14 14:21:24 +000013153 intel_wakeref_t wakeref = 0;
Chris Wilsone95433c2016-10-28 13:58:27 +010013154 int i;
Daniel Vettera6778b32012-07-02 09:56:42 +020013155
Daniel Vetter9db529a2017-08-08 10:08:28 +020013156 intel_atomic_commit_fence_wait(intel_state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020013157
Daniel Vetterea0000f2016-06-13 16:13:46 +020013158 drm_atomic_helper_wait_for_dependencies(state);
13159
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013160 if (intel_state->modeset)
Chris Wilson0e6e0be2019-01-14 14:21:24 +000013161 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010013162
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013163 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013164 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
13165 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13166 intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013167
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013168 if (needs_modeset(new_crtc_state) ||
13169 to_intel_crtc_state(new_crtc_state)->update_pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020013170
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013171 put_domains[intel_crtc->pipe] =
Daniel Vetter5a21b662016-05-24 17:13:53 +020013172 modeset_get_crtc_power_domains(crtc,
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013173 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013174 }
13175
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013176 if (!needs_modeset(new_crtc_state))
Maarten Lankhorst61333b62015-06-15 12:33:50 +020013177 continue;
13178
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013179 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
Daniel Vetter460da9162013-03-27 00:44:51 +010013180
Ville Syrjälä29ceb0e2016-03-09 19:07:27 +020013181 if (old_crtc_state->active) {
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020013182 intel_crtc_disable_planes(intel_state, intel_crtc);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010013183
13184 /*
13185 * We need to disable pipe CRC before disabling the pipe,
13186 * or we race against vblank off.
13187 */
13188 intel_crtc_disable_pipe_crc(intel_crtc);
13189
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013190 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020013191 intel_crtc->active = false;
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -020013192 intel_fbc_disable(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +020013193 intel_disable_shared_dpll(old_intel_crtc_state);
Ville Syrjälä9bbc8258a2015-11-20 22:09:20 +020013194
13195 /*
13196 * Underruns don't always raise
13197 * interrupts, so check manually.
13198 */
13199 intel_check_cpu_fifo_underruns(dev_priv);
13200 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorstb9001112015-11-19 16:07:16 +010013201
Ville Syrjäläa748fae2018-10-25 16:05:36 +030013202 /* FIXME unify this for all platforms */
13203 if (!new_crtc_state->active &&
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080013204 !HAS_GMCH(dev_priv) &&
Ville Syrjäläa748fae2018-10-25 16:05:36 +030013205 dev_priv->display.initial_watermarks)
13206 dev_priv->display.initial_watermarks(intel_state,
13207 new_intel_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013208 }
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010013209 }
Daniel Vetter7758a112012-07-08 19:40:39 +020013210
Daniel Vetter7a1530d72017-12-07 15:32:02 +010013211 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
13212 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
13213 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +020013214
Maarten Lankhorst565602d2015-12-10 12:33:57 +010013215 if (intel_state->modeset) {
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020013216 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
Maarten Lankhorst33c8df892016-02-10 13:49:37 +010013217
Ville Syrjäläb0587e42017-01-26 21:52:01 +020013218 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
Maarten Lankhorstf6d19732016-03-23 14:58:07 +010013219
Lyude656d1b82016-08-17 15:55:54 -040013220 /*
13221 * SKL workaround: bspec recommends we disable the SAGV when we
13222 * have more then one pipe enabled
13223 */
Paulo Zanoni56feca92016-09-22 18:00:28 -030013224 if (!intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030013225 intel_disable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040013226
Maarten Lankhorst677100c2016-11-08 13:55:41 +010013227 intel_modeset_verify_disabled(dev, state);
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020013228 }
Daniel Vetter47fab732012-10-26 10:58:18 +020013229
Lyude896e5bb2016-08-24 07:48:09 +020013230 /* Complete the events for pipes that have now been disabled */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013231 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13232 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013233
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013234 /* Complete events for now disable pipes here. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013235 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013236 spin_lock_irq(&dev->event_lock);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013237 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013238 spin_unlock_irq(&dev->event_lock);
13239
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013240 new_crtc_state->event = NULL;
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013241 }
Matt Ropered4a6a72016-02-23 17:20:13 -080013242 }
13243
Lyude896e5bb2016-08-24 07:48:09 +020013244 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013245 dev_priv->display.update_crtcs(state);
Lyude896e5bb2016-08-24 07:48:09 +020013246
Daniel Vetter94f05022016-06-14 18:01:00 +020013247 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13248 * already, but still need the state for the delayed optimization. To
13249 * fix this:
13250 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13251 * - schedule that vblank worker _before_ calling hw_done
13252 * - at the start of commit_tail, cancel it _synchrously
13253 * - switch over to the vblank wait helper in the core after that since
13254 * we don't need out special handling any more.
13255 */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013256 drm_atomic_helper_wait_for_flip_done(dev, state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013257
Ville Syrjälä051a6d82019-02-05 18:08:41 +020013258 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13259 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13260
13261 if (new_crtc_state->active &&
13262 !needs_modeset(new_crtc_state) &&
13263 (new_intel_crtc_state->base.color_mgmt_changed ||
13264 new_intel_crtc_state->update_pipe))
13265 intel_color_load_luts(new_intel_crtc_state);
13266 }
13267
Daniel Vetter5a21b662016-05-24 17:13:53 +020013268 /*
13269 * Now that the vblank has passed, we can go ahead and program the
13270 * optimal watermarks on platforms that need two-step watermark
13271 * programming.
13272 *
13273 * TODO: Move this (and other cleanup) to an async worker eventually.
13274 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013275 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013276 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013277
13278 if (dev_priv->display.optimize_watermarks)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013279 dev_priv->display.optimize_watermarks(intel_state,
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013280 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013281 }
13282
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013283 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020013284 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
13285
13286 if (put_domains[i])
13287 modeset_put_power_domains(dev_priv, put_domains[i]);
13288
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013289 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013290 }
13291
Ville Syrjäläcff109f2017-11-17 21:19:17 +020013292 if (intel_state->modeset)
13293 intel_verify_planes(intel_state);
13294
Paulo Zanoni56feca92016-09-22 18:00:28 -030013295 if (intel_state->modeset && intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030013296 intel_enable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040013297
Daniel Vetter94f05022016-06-14 18:01:00 +020013298 drm_atomic_helper_commit_hw_done(state);
13299
Chris Wilsond5553c02017-05-04 12:55:08 +010013300 if (intel_state->modeset) {
13301 /* As one of the primary mmio accessors, KMS has a high
13302 * likelihood of triggering bugs in unclaimed access. After we
13303 * finish modesetting, see if an error has been flagged, and if
13304 * so enable debugging for the next modeset - and hope we catch
13305 * the culprit.
13306 */
13307 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
Chris Wilson0e6e0be2019-01-14 14:21:24 +000013308 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
Chris Wilsond5553c02017-05-04 12:55:08 +010013309 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013310
Chris Wilson8d52e442018-06-23 11:39:51 +010013311 /*
13312 * Defer the cleanup of the old state to a separate worker to not
13313 * impede the current task (userspace for blocking modesets) that
13314 * are executed inline. For out-of-line asynchronous modesets/flips,
13315 * deferring to a new worker seems overkill, but we would place a
13316 * schedule point (cond_resched()) here anyway to keep latencies
13317 * down.
13318 */
13319 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
Chris Wilson41db6452018-07-12 12:57:29 +010013320 queue_work(system_highpri_wq, &state->commit_work);
Daniel Vetter94f05022016-06-14 18:01:00 +020013321}
13322
13323static void intel_atomic_commit_work(struct work_struct *work)
13324{
Chris Wilsonc004a902016-10-28 13:58:45 +010013325 struct drm_atomic_state *state =
13326 container_of(work, struct drm_atomic_state, commit_work);
13327
Daniel Vetter94f05022016-06-14 18:01:00 +020013328 intel_atomic_commit_tail(state);
13329}
13330
Chris Wilsonc004a902016-10-28 13:58:45 +010013331static int __i915_sw_fence_call
13332intel_atomic_commit_ready(struct i915_sw_fence *fence,
13333 enum i915_sw_fence_notify notify)
13334{
13335 struct intel_atomic_state *state =
13336 container_of(fence, struct intel_atomic_state, commit_ready);
13337
13338 switch (notify) {
13339 case FENCE_COMPLETE:
Daniel Vetter42b062b2017-08-08 10:08:27 +020013340 /* we do blocking waits in the worker, nothing to do here */
Chris Wilsonc004a902016-10-28 13:58:45 +010013341 break;
Chris Wilsonc004a902016-10-28 13:58:45 +010013342 case FENCE_FREE:
Chris Wilsoneb955ee2017-01-23 21:29:39 +000013343 {
13344 struct intel_atomic_helper *helper =
13345 &to_i915(state->base.dev)->atomic_helper;
13346
13347 if (llist_add(&state->freed, &helper->free_list))
13348 schedule_work(&helper->free_work);
13349 break;
13350 }
Chris Wilsonc004a902016-10-28 13:58:45 +010013351 }
13352
13353 return NOTIFY_DONE;
13354}
13355
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013356static void intel_atomic_track_fbs(struct drm_atomic_state *state)
13357{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013358 struct drm_plane_state *old_plane_state, *new_plane_state;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013359 struct drm_plane *plane;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013360 int i;
13361
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013362 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013363 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013364 intel_fb_obj(new_plane_state->fb),
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013365 to_intel_plane(plane)->frontbuffer_bit);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013366}
13367
Daniel Vetter94f05022016-06-14 18:01:00 +020013368/**
13369 * intel_atomic_commit - commit validated state object
13370 * @dev: DRM device
13371 * @state: the top-level driver state object
13372 * @nonblock: nonblocking commit
13373 *
13374 * This function commits a top-level state object that has been validated
13375 * with drm_atomic_helper_check().
13376 *
Daniel Vetter94f05022016-06-14 18:01:00 +020013377 * RETURNS
13378 * Zero for success or -errno.
13379 */
13380static int intel_atomic_commit(struct drm_device *dev,
13381 struct drm_atomic_state *state,
13382 bool nonblock)
13383{
13384 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010013385 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter94f05022016-06-14 18:01:00 +020013386 int ret = 0;
13387
Chris Wilsonc004a902016-10-28 13:58:45 +010013388 drm_atomic_state_get(state);
13389 i915_sw_fence_init(&intel_state->commit_ready,
13390 intel_atomic_commit_ready);
Daniel Vetter94f05022016-06-14 18:01:00 +020013391
Ville Syrjälä440df932017-03-29 17:21:23 +030013392 /*
13393 * The intel_legacy_cursor_update() fast path takes care
13394 * of avoiding the vblank waits for simple cursor
13395 * movement and flips. For cursor on/off and size changes,
13396 * we want to perform the vblank waits so that watermark
13397 * updates happen during the correct frames. Gen9+ have
13398 * double buffered watermarks and so shouldn't need this.
13399 *
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013400 * Unset state->legacy_cursor_update before the call to
13401 * drm_atomic_helper_setup_commit() because otherwise
13402 * drm_atomic_helper_wait_for_flip_done() is a noop and
13403 * we get FIFO underruns because we didn't wait
13404 * for vblank.
Ville Syrjälä440df932017-03-29 17:21:23 +030013405 *
13406 * FIXME doing watermarks and fb cleanup from a vblank worker
13407 * (assuming we had any) would solve these problems.
13408 */
Maarten Lankhorst213f1bd2017-09-19 14:14:19 +020013409 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13410 struct intel_crtc_state *new_crtc_state;
13411 struct intel_crtc *crtc;
13412 int i;
13413
13414 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13415 if (new_crtc_state->wm.need_postvbl_update ||
13416 new_crtc_state->update_wm_post)
13417 state->legacy_cursor_update = false;
13418 }
Ville Syrjälä440df932017-03-29 17:21:23 +030013419
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013420 ret = intel_atomic_prepare_commit(dev, state);
13421 if (ret) {
13422 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13423 i915_sw_fence_commit(&intel_state->commit_ready);
13424 return ret;
13425 }
13426
13427 ret = drm_atomic_helper_setup_commit(state, nonblock);
13428 if (!ret)
13429 ret = drm_atomic_helper_swap_state(state, true);
13430
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013431 if (ret) {
13432 i915_sw_fence_commit(&intel_state->commit_ready);
13433
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013434 drm_atomic_helper_cleanup_planes(dev, state);
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013435 return ret;
13436 }
Daniel Vetter94f05022016-06-14 18:01:00 +020013437 dev_priv->wm.distrust_bios_wm = false;
Ander Conselvan de Oliveira3c0fb582016-12-29 17:22:08 +020013438 intel_shared_dpll_swap_state(state);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013439 intel_atomic_track_fbs(state);
Daniel Vetter94f05022016-06-14 18:01:00 +020013440
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013441 if (intel_state->modeset) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030013442 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13443 sizeof(intel_state->min_cdclk));
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030013444 memcpy(dev_priv->min_voltage_level,
13445 intel_state->min_voltage_level,
13446 sizeof(intel_state->min_voltage_level));
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013447 dev_priv->active_crtcs = intel_state->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020013448 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13449 dev_priv->cdclk.actual = intel_state->cdclk.actual;
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013450 }
13451
Chris Wilson08536952016-10-14 13:18:18 +010013452 drm_atomic_state_get(state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020013453 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
Chris Wilsonc004a902016-10-28 13:58:45 +010013454
13455 i915_sw_fence_commit(&intel_state->commit_ready);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013456 if (nonblock && intel_state->modeset) {
13457 queue_work(dev_priv->modeset_wq, &state->commit_work);
13458 } else if (nonblock) {
Daniel Vetter42b062b2017-08-08 10:08:27 +020013459 queue_work(system_unbound_wq, &state->commit_work);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013460 } else {
13461 if (intel_state->modeset)
13462 flush_workqueue(dev_priv->modeset_wq);
Daniel Vetter94f05022016-06-14 18:01:00 +020013463 intel_atomic_commit_tail(state);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013464 }
Mika Kuoppala75714942015-12-16 09:26:48 +020013465
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013466 return 0;
Daniel Vetterf30da182013-04-11 20:22:50 +020013467}
13468
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013469static const struct drm_crtc_funcs intel_crtc_funcs = {
Daniel Vetter3fab2f02017-04-03 10:32:57 +020013470 .gamma_set = drm_atomic_helper_legacy_gamma_set,
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013471 .set_config = drm_atomic_helper_set_config,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013472 .destroy = intel_crtc_destroy,
Maarten Lankhorst4c01ded2016-12-22 11:33:23 +010013473 .page_flip = drm_atomic_helper_page_flip,
Matt Roper13568372015-01-21 16:35:47 -080013474 .atomic_duplicate_state = intel_crtc_duplicate_state,
13475 .atomic_destroy_state = intel_crtc_destroy_state,
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +010013476 .set_crc_source = intel_crtc_set_crc_source,
Mahesh Kumara8c20832018-07-13 19:29:38 +053013477 .verify_crc_source = intel_crtc_verify_crc_source,
Mahesh Kumar260bc552018-07-13 19:29:39 +053013478 .get_crc_sources = intel_crtc_get_crc_sources,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013479};
13480
Chris Wilson74d290f2017-08-17 13:37:06 +010013481struct wait_rps_boost {
13482 struct wait_queue_entry wait;
13483
13484 struct drm_crtc *crtc;
Chris Wilsone61e0f52018-02-21 09:56:36 +000013485 struct i915_request *request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013486};
13487
13488static int do_rps_boost(struct wait_queue_entry *_wait,
13489 unsigned mode, int sync, void *key)
13490{
13491 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013492 struct i915_request *rq = wait->request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013493
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013494 /*
13495 * If we missed the vblank, but the request is already running it
13496 * is reasonable to assume that it will complete before the next
13497 * vblank without our intervention, so leave RPS alone.
13498 */
Chris Wilsone61e0f52018-02-21 09:56:36 +000013499 if (!i915_request_started(rq))
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013500 gen6_rps_boost(rq, NULL);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013501 i915_request_put(rq);
Chris Wilson74d290f2017-08-17 13:37:06 +010013502
13503 drm_crtc_vblank_put(wait->crtc);
13504
13505 list_del(&wait->wait.entry);
13506 kfree(wait);
13507 return 1;
13508}
13509
13510static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13511 struct dma_fence *fence)
13512{
13513 struct wait_rps_boost *wait;
13514
13515 if (!dma_fence_is_i915(fence))
13516 return;
13517
13518 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13519 return;
13520
13521 if (drm_crtc_vblank_get(crtc))
13522 return;
13523
13524 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13525 if (!wait) {
13526 drm_crtc_vblank_put(crtc);
13527 return;
13528 }
13529
13530 wait->request = to_request(dma_fence_get(fence));
13531 wait->crtc = crtc;
13532
13533 wait->wait.func = do_rps_boost;
13534 wait->wait.flags = 0;
13535
13536 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13537}
13538
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013539static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13540{
13541 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13542 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13543 struct drm_framebuffer *fb = plane_state->base.fb;
13544 struct i915_vma *vma;
13545
13546 if (plane->id == PLANE_CURSOR &&
José Roberto de Souzad53db442018-11-30 15:20:48 -080013547 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013548 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13549 const int align = intel_cursor_alignment(dev_priv);
Chris Wilson4a477652018-08-17 09:24:05 +010013550 int err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013551
Chris Wilson4a477652018-08-17 09:24:05 +010013552 err = i915_gem_object_attach_phys(obj, align);
13553 if (err)
13554 return err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013555 }
13556
13557 vma = intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +030013558 &plane_state->view,
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013559 intel_plane_uses_fence(plane_state),
13560 &plane_state->flags);
13561 if (IS_ERR(vma))
13562 return PTR_ERR(vma);
13563
13564 plane_state->vma = vma;
13565
13566 return 0;
13567}
13568
13569static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13570{
13571 struct i915_vma *vma;
13572
13573 vma = fetch_and_zero(&old_plane_state->vma);
13574 if (vma)
13575 intel_unpin_fb_vma(vma, old_plane_state->flags);
13576}
13577
Chris Wilsonb7268c52018-04-18 19:40:52 +010013578static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13579{
13580 struct i915_sched_attr attr = {
13581 .priority = I915_PRIORITY_DISPLAY,
13582 };
13583
13584 i915_gem_object_wait_priority(obj, 0, &attr);
13585}
13586
Matt Roper6beb8c232014-12-01 15:40:14 -080013587/**
13588 * intel_prepare_plane_fb - Prepare fb for usage on plane
13589 * @plane: drm plane to prepare for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013590 * @new_state: the plane state being prepared
Matt Roper6beb8c232014-12-01 15:40:14 -080013591 *
13592 * Prepares a framebuffer for usage on a display plane. Generally this
13593 * involves pinning the underlying object and updating the frontbuffer tracking
13594 * bits. Some older platforms need special physical address handling for
13595 * cursor planes.
13596 *
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013597 * Must be called with struct_mutex held.
13598 *
Matt Roper6beb8c232014-12-01 15:40:14 -080013599 * Returns 0 on success, negative error code on failure.
13600 */
13601int
13602intel_prepare_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013603 struct drm_plane_state *new_state)
Matt Roper465c1202014-05-29 08:06:54 -070013604{
Chris Wilsonc004a902016-10-28 13:58:45 +010013605 struct intel_atomic_state *intel_state =
13606 to_intel_atomic_state(new_state->state);
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000013607 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Maarten Lankhorst844f9112015-09-02 10:42:40 +020013608 struct drm_framebuffer *fb = new_state->fb;
Matt Roper6beb8c232014-12-01 15:40:14 -080013609 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Maarten Lankhorst1ee49392015-09-23 13:27:08 +020013610 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
Chris Wilsonc004a902016-10-28 13:58:45 +010013611 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013612
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013613 if (old_obj) {
13614 struct drm_crtc_state *crtc_state =
Maarten Lankhorst8b694492018-04-09 14:46:55 +020013615 drm_atomic_get_new_crtc_state(new_state->state,
13616 plane->state->crtc);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013617
13618 /* Big Hammer, we also need to ensure that any pending
13619 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13620 * current scanout is retired before unpinning the old
13621 * framebuffer. Note that we rely on userspace rendering
13622 * into the buffer attached to the pipe they are waiting
13623 * on. If not, userspace generates a GPU hang with IPEHR
13624 * point to the MI_WAIT_FOR_EVENT.
13625 *
13626 * This should only fail upon a hung GPU, in which case we
13627 * can safely continue.
13628 */
Chris Wilsonc004a902016-10-28 13:58:45 +010013629 if (needs_modeset(crtc_state)) {
13630 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13631 old_obj->resv, NULL,
13632 false, 0,
13633 GFP_KERNEL);
13634 if (ret < 0)
13635 return ret;
Chris Wilsonf4457ae2016-04-13 17:35:08 +010013636 }
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013637 }
13638
Chris Wilsonc004a902016-10-28 13:58:45 +010013639 if (new_state->fence) { /* explicit fencing */
13640 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13641 new_state->fence,
13642 I915_FENCE_TIMEOUT,
13643 GFP_KERNEL);
13644 if (ret < 0)
13645 return ret;
13646 }
13647
Chris Wilsonc37efb92016-06-17 08:28:47 +010013648 if (!obj)
13649 return 0;
13650
Chris Wilson4d3088c2017-07-26 17:00:38 +010013651 ret = i915_gem_object_pin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013652 if (ret)
13653 return ret;
13654
Chris Wilson4d3088c2017-07-26 17:00:38 +010013655 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13656 if (ret) {
13657 i915_gem_object_unpin_pages(obj);
13658 return ret;
13659 }
13660
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013661 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
Chris Wilsonfd700752017-07-26 17:00:36 +010013662
Chris Wilsonfd700752017-07-26 17:00:36 +010013663 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson4d3088c2017-07-26 17:00:38 +010013664 i915_gem_object_unpin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013665 if (ret)
13666 return ret;
13667
Chris Wilsone2f34962018-10-01 15:47:54 +010013668 fb_obj_bump_render_priority(obj);
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013669 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13670
Chris Wilsonc004a902016-10-28 13:58:45 +010013671 if (!new_state->fence) { /* implicit fencing */
Chris Wilson74d290f2017-08-17 13:37:06 +010013672 struct dma_fence *fence;
13673
Chris Wilsonc004a902016-10-28 13:58:45 +010013674 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13675 obj->resv, NULL,
13676 false, I915_FENCE_TIMEOUT,
13677 GFP_KERNEL);
13678 if (ret < 0)
13679 return ret;
Chris Wilson74d290f2017-08-17 13:37:06 +010013680
13681 fence = reservation_object_get_excl_rcu(obj->resv);
13682 if (fence) {
13683 add_rps_boost_after_vblank(new_state->crtc, fence);
13684 dma_fence_put(fence);
13685 }
13686 } else {
13687 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
Chris Wilsonc004a902016-10-28 13:58:45 +010013688 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013689
Chris Wilson60548c52018-07-31 14:26:29 +010013690 /*
13691 * We declare pageflips to be interactive and so merit a small bias
13692 * towards upclocking to deliver the frame on time. By only changing
13693 * the RPS thresholds to sample more regularly and aim for higher
13694 * clocks we can hopefully deliver low power workloads (like kodi)
13695 * that are not quite steady state without resorting to forcing
13696 * maximum clocks following a vblank miss (see do_rps_boost()).
13697 */
13698 if (!intel_state->rps_interactive) {
13699 intel_rps_mark_interactive(dev_priv, true);
13700 intel_state->rps_interactive = true;
13701 }
13702
Chris Wilsond07f0e52016-10-28 13:58:44 +010013703 return 0;
Matt Roper6beb8c232014-12-01 15:40:14 -080013704}
13705
Matt Roper38f3ce32014-12-02 07:45:25 -080013706/**
13707 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13708 * @plane: drm plane to clean up for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013709 * @old_state: the state from the previous modeset
Matt Roper38f3ce32014-12-02 07:45:25 -080013710 *
13711 * Cleans up a framebuffer that has just been removed from a plane.
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013712 *
13713 * Must be called with struct_mutex held.
Matt Roper38f3ce32014-12-02 07:45:25 -080013714 */
13715void
13716intel_cleanup_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013717 struct drm_plane_state *old_state)
Matt Roper38f3ce32014-12-02 07:45:25 -080013718{
Chris Wilson60548c52018-07-31 14:26:29 +010013719 struct intel_atomic_state *intel_state =
13720 to_intel_atomic_state(old_state->state);
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013721 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Matt Roper38f3ce32014-12-02 07:45:25 -080013722
Chris Wilson60548c52018-07-31 14:26:29 +010013723 if (intel_state->rps_interactive) {
13724 intel_rps_mark_interactive(dev_priv, false);
13725 intel_state->rps_interactive = false;
13726 }
13727
Chris Wilsonbe1e3412017-01-16 15:21:27 +000013728 /* Should only be called after a successful intel_prepare_plane_fb()! */
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013729 mutex_lock(&dev_priv->drm.struct_mutex);
13730 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13731 mutex_unlock(&dev_priv->drm.struct_mutex);
Matt Roper465c1202014-05-29 08:06:54 -070013732}
13733
Chandra Konduru6156a452015-04-27 13:48:39 -070013734int
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013735skl_max_scale(const struct intel_crtc_state *crtc_state,
13736 u32 pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -070013737{
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013738 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13739 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru77224cd2018-04-09 09:11:13 +053013740 int max_scale, mult;
13741 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
Chandra Konduru6156a452015-04-27 13:48:39 -070013742
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013743 if (!crtc_state->base.enable)
Chandra Konduru6156a452015-04-27 13:48:39 -070013744 return DRM_PLANE_HELPER_NO_SCALING;
13745
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013746 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13747 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13748
Rodrigo Vivi43037c82017-10-03 15:31:42 -070013749 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013750 max_dotclk *= 2;
13751
13752 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
Chandra Konduru6156a452015-04-27 13:48:39 -070013753 return DRM_PLANE_HELPER_NO_SCALING;
13754
13755 /*
13756 * skl max scale is lower of:
13757 * close to 3 but not 3, -1 is for that purpose
13758 * or
13759 * cdclk/crtc_clock
13760 */
Chandra Konduru77224cd2018-04-09 09:11:13 +053013761 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13762 tmpclk1 = (1 << 16) * mult - 1;
13763 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13764 max_scale = min(tmpclk1, tmpclk2);
Chandra Konduru6156a452015-04-27 13:48:39 -070013765
13766 return max_scale;
13767}
13768
Daniel Vetter5a21b662016-05-24 17:13:53 +020013769static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13770 struct drm_crtc_state *old_crtc_state)
13771{
13772 struct drm_device *dev = crtc->dev;
Lyude62e0fb82016-08-22 12:50:08 -040013773 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013774 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013775 struct intel_crtc_state *old_intel_cstate =
Daniel Vetter5a21b662016-05-24 17:13:53 +020013776 to_intel_crtc_state(old_crtc_state);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013777 struct intel_atomic_state *old_intel_state =
13778 to_intel_atomic_state(old_crtc_state->state);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013779 struct intel_crtc_state *intel_cstate =
13780 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13781 bool modeset = needs_modeset(&intel_cstate->base);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013782
13783 /* Perform vblank evasion around commit operation */
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013784 intel_pipe_update_start(intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013785
13786 if (modeset)
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013787 goto out;
Daniel Vetter5a21b662016-05-24 17:13:53 +020013788
Ville Syrjälä4d8ed542019-02-05 18:08:40 +020013789 if (intel_cstate->base.color_mgmt_changed ||
13790 intel_cstate->update_pipe)
13791 intel_color_commit(intel_cstate);
13792
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013793 if (intel_cstate->update_pipe)
Ville Syrjälä1a15b772017-08-23 18:22:25 +030013794 intel_update_pipe_config(old_intel_cstate, intel_cstate);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013795 else if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +020013796 skl_detach_scalers(intel_cstate);
Lyude62e0fb82016-08-22 12:50:08 -040013797
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013798out:
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013799 if (dev_priv->display.atomic_update_watermarks)
13800 dev_priv->display.atomic_update_watermarks(old_intel_state,
13801 intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013802}
13803
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013804void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13805 struct intel_crtc_state *crtc_state)
13806{
13807 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13808
Lucas De Marchicf819ef2018-12-12 10:10:43 -080013809 if (!IS_GEN(dev_priv, 2))
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013810 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13811
13812 if (crtc_state->has_pch_encoder) {
13813 enum pipe pch_transcoder =
13814 intel_crtc_pch_transcoder(crtc);
13815
13816 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13817 }
13818}
13819
Daniel Vetter5a21b662016-05-24 17:13:53 +020013820static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13821 struct drm_crtc_state *old_crtc_state)
13822{
13823 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013824 struct intel_atomic_state *old_intel_state =
13825 to_intel_atomic_state(old_crtc_state->state);
13826 struct intel_crtc_state *new_crtc_state =
13827 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013828
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013829 intel_pipe_update_end(new_crtc_state);
Maarten Lankhorst33a49862017-11-13 15:40:43 +010013830
13831 if (new_crtc_state->update_pipe &&
13832 !needs_modeset(&new_crtc_state->base) &&
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013833 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13834 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013835}
13836
Matt Ropercf4c7c12014-12-04 10:27:42 -080013837/**
Matt Roper4a3b8762014-12-23 10:41:51 -080013838 * intel_plane_destroy - destroy a plane
13839 * @plane: plane to destroy
Matt Ropercf4c7c12014-12-04 10:27:42 -080013840 *
Matt Roper4a3b8762014-12-23 10:41:51 -080013841 * Common destruction function for all types of planes (primary, cursor,
13842 * sprite).
Matt Ropercf4c7c12014-12-04 10:27:42 -080013843 */
Matt Roper4a3b8762014-12-23 10:41:51 -080013844void intel_plane_destroy(struct drm_plane *plane)
Matt Roper465c1202014-05-29 08:06:54 -070013845{
Matt Roper465c1202014-05-29 08:06:54 -070013846 drm_plane_cleanup(plane);
Ville Syrjälä69ae5612016-05-27 20:59:22 +030013847 kfree(to_intel_plane(plane));
Matt Roper465c1202014-05-29 08:06:54 -070013848}
13849
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013850static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13851 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013852{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013853 switch (modifier) {
13854 case DRM_FORMAT_MOD_LINEAR:
13855 case I915_FORMAT_MOD_X_TILED:
13856 break;
13857 default:
13858 return false;
13859 }
13860
Ben Widawsky714244e2017-08-01 09:58:16 -070013861 switch (format) {
13862 case DRM_FORMAT_C8:
13863 case DRM_FORMAT_RGB565:
13864 case DRM_FORMAT_XRGB1555:
13865 case DRM_FORMAT_XRGB8888:
13866 return modifier == DRM_FORMAT_MOD_LINEAR ||
13867 modifier == I915_FORMAT_MOD_X_TILED;
13868 default:
13869 return false;
13870 }
13871}
13872
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013873static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13874 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013875{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013876 switch (modifier) {
13877 case DRM_FORMAT_MOD_LINEAR:
13878 case I915_FORMAT_MOD_X_TILED:
13879 break;
13880 default:
13881 return false;
13882 }
13883
Ben Widawsky714244e2017-08-01 09:58:16 -070013884 switch (format) {
13885 case DRM_FORMAT_C8:
13886 case DRM_FORMAT_RGB565:
13887 case DRM_FORMAT_XRGB8888:
13888 case DRM_FORMAT_XBGR8888:
13889 case DRM_FORMAT_XRGB2101010:
13890 case DRM_FORMAT_XBGR2101010:
13891 return modifier == DRM_FORMAT_MOD_LINEAR ||
13892 modifier == I915_FORMAT_MOD_X_TILED;
13893 default:
13894 return false;
13895 }
13896}
13897
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013898static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13899 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013900{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013901 return modifier == DRM_FORMAT_MOD_LINEAR &&
13902 format == DRM_FORMAT_ARGB8888;
Ben Widawsky714244e2017-08-01 09:58:16 -070013903}
13904
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013905static const struct drm_plane_funcs i965_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013906 .update_plane = drm_atomic_helper_update_plane,
13907 .disable_plane = drm_atomic_helper_disable_plane,
13908 .destroy = intel_plane_destroy,
13909 .atomic_get_property = intel_plane_atomic_get_property,
13910 .atomic_set_property = intel_plane_atomic_set_property,
13911 .atomic_duplicate_state = intel_plane_duplicate_state,
13912 .atomic_destroy_state = intel_plane_destroy_state,
13913 .format_mod_supported = i965_plane_format_mod_supported,
13914};
13915
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013916static const struct drm_plane_funcs i8xx_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013917 .update_plane = drm_atomic_helper_update_plane,
13918 .disable_plane = drm_atomic_helper_disable_plane,
13919 .destroy = intel_plane_destroy,
13920 .atomic_get_property = intel_plane_atomic_get_property,
13921 .atomic_set_property = intel_plane_atomic_set_property,
13922 .atomic_duplicate_state = intel_plane_duplicate_state,
13923 .atomic_destroy_state = intel_plane_destroy_state,
13924 .format_mod_supported = i8xx_plane_format_mod_supported,
Matt Roper465c1202014-05-29 08:06:54 -070013925};
13926
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013927static int
13928intel_legacy_cursor_update(struct drm_plane *plane,
13929 struct drm_crtc *crtc,
13930 struct drm_framebuffer *fb,
13931 int crtc_x, int crtc_y,
13932 unsigned int crtc_w, unsigned int crtc_h,
Jani Nikulaba3f4d02019-01-18 14:01:23 +020013933 u32 src_x, u32 src_y,
13934 u32 src_w, u32 src_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013935 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013936{
13937 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13938 int ret;
13939 struct drm_plane_state *old_plane_state, *new_plane_state;
13940 struct intel_plane *intel_plane = to_intel_plane(plane);
13941 struct drm_framebuffer *old_fb;
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013942 struct intel_crtc_state *crtc_state =
13943 to_intel_crtc_state(crtc->state);
13944 struct intel_crtc_state *new_crtc_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013945
13946 /*
13947 * When crtc is inactive or there is a modeset pending,
13948 * wait for it to complete in the slowpath
13949 */
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013950 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
13951 crtc_state->update_pipe)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013952 goto slow;
13953
13954 old_plane_state = plane->state;
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013955 /*
13956 * Don't do an async update if there is an outstanding commit modifying
13957 * the plane. This prevents our async update's changes from getting
13958 * overridden by a previous synchronous update's state.
13959 */
13960 if (old_plane_state->commit &&
13961 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13962 goto slow;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013963
13964 /*
13965 * If any parameters change that may affect watermarks,
13966 * take the slowpath. Only changing fb or position should be
13967 * in the fastpath.
13968 */
13969 if (old_plane_state->crtc != crtc ||
13970 old_plane_state->src_w != src_w ||
13971 old_plane_state->src_h != src_h ||
13972 old_plane_state->crtc_w != crtc_w ||
13973 old_plane_state->crtc_h != crtc_h ||
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013974 !old_plane_state->fb != !fb)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013975 goto slow;
13976
13977 new_plane_state = intel_plane_duplicate_state(plane);
13978 if (!new_plane_state)
13979 return -ENOMEM;
13980
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013981 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
13982 if (!new_crtc_state) {
13983 ret = -ENOMEM;
13984 goto out_free;
13985 }
13986
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013987 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13988
13989 new_plane_state->src_x = src_x;
13990 new_plane_state->src_y = src_y;
13991 new_plane_state->src_w = src_w;
13992 new_plane_state->src_h = src_h;
13993 new_plane_state->crtc_x = crtc_x;
13994 new_plane_state->crtc_y = crtc_y;
13995 new_plane_state->crtc_w = crtc_w;
13996 new_plane_state->crtc_h = crtc_h;
13997
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013998 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
13999 to_intel_plane_state(old_plane_state),
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014000 to_intel_plane_state(new_plane_state));
14001 if (ret)
14002 goto out_free;
14003
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014004 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14005 if (ret)
14006 goto out_free;
14007
Ville Syrjäläef1a1912018-02-21 18:02:34 +020014008 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
14009 if (ret)
14010 goto out_unlock;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014011
Dhinakaran Pandiyana694e222018-03-06 19:34:19 -080014012 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014013
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080014014 old_fb = old_plane_state->fb;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014015 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
14016 intel_plane->frontbuffer_bit);
14017
14018 /* Swap plane state */
Maarten Lankhorst669c9212017-09-04 12:48:38 +020014019 plane->state = new_plane_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014020
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014021 /*
14022 * We cannot swap crtc_state as it may be in use by an atomic commit or
14023 * page flip that's running simultaneously. If we swap crtc_state and
14024 * destroy the old state, we will cause a use-after-free there.
14025 *
14026 * Only update active_planes, which is needed for our internal
14027 * bookkeeping. Either value will do the right thing when updating
14028 * planes atomically. If the cursor was part of the atomic update then
14029 * we would have taken the slowpath.
14030 */
14031 crtc_state->active_planes = new_crtc_state->active_planes;
14032
Ville Syrjälä72259532017-03-02 19:15:05 +020014033 if (plane->state->visible) {
14034 trace_intel_update_plane(plane, to_intel_crtc(crtc));
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014035 intel_plane->update_plane(intel_plane, crtc_state,
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020014036 to_intel_plane_state(plane->state));
Ville Syrjälä72259532017-03-02 19:15:05 +020014037 } else {
14038 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020014039 intel_plane->disable_plane(intel_plane, crtc_state);
Ville Syrjälä72259532017-03-02 19:15:05 +020014040 }
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014041
Ville Syrjäläef1a1912018-02-21 18:02:34 +020014042 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014043
14044out_unlock:
14045 mutex_unlock(&dev_priv->drm.struct_mutex);
14046out_free:
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014047 if (new_crtc_state)
14048 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
Maarten Lankhorst669c9212017-09-04 12:48:38 +020014049 if (ret)
14050 intel_plane_destroy_state(plane, new_plane_state);
14051 else
14052 intel_plane_destroy_state(plane, old_plane_state);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014053 return ret;
14054
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014055slow:
14056 return drm_atomic_helper_update_plane(plane, crtc, fb,
14057 crtc_x, crtc_y, crtc_w, crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010014058 src_x, src_y, src_w, src_h, ctx);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014059}
14060
14061static const struct drm_plane_funcs intel_cursor_plane_funcs = {
14062 .update_plane = intel_legacy_cursor_update,
14063 .disable_plane = drm_atomic_helper_disable_plane,
14064 .destroy = intel_plane_destroy,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014065 .atomic_get_property = intel_plane_atomic_get_property,
14066 .atomic_set_property = intel_plane_atomic_set_property,
14067 .atomic_duplicate_state = intel_plane_duplicate_state,
14068 .atomic_destroy_state = intel_plane_destroy_state,
Ville Syrjäläa38189c2018-05-18 19:21:59 +030014069 .format_mod_supported = intel_cursor_format_mod_supported,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014070};
14071
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020014072static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
14073 enum i9xx_plane_id i9xx_plane)
14074{
14075 if (!HAS_FBC(dev_priv))
14076 return false;
14077
14078 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14079 return i9xx_plane == PLANE_A; /* tied to pipe A */
14080 else if (IS_IVYBRIDGE(dev_priv))
14081 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
14082 i9xx_plane == PLANE_C;
14083 else if (INTEL_GEN(dev_priv) >= 4)
14084 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
14085 else
14086 return i9xx_plane == PLANE_A;
14087}
14088
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014089static struct intel_plane *
Ville Syrjälä580503c2016-10-31 22:37:00 +020014090intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
Matt Roper465c1202014-05-29 08:06:54 -070014091{
Ville Syrjälä881440a2018-10-05 15:58:17 +030014092 struct intel_plane *plane;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030014093 const struct drm_plane_funcs *plane_funcs;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014094 unsigned int supported_rotations;
Ville Syrjälädeb19682018-10-05 15:58:08 +030014095 unsigned int possible_crtcs;
Ville Syrjälä881440a2018-10-05 15:58:17 +030014096 const u64 *modifiers;
14097 const u32 *formats;
14098 int num_formats;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014099 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070014100
Ville Syrjäläb7c80602018-10-05 15:58:15 +030014101 if (INTEL_GEN(dev_priv) >= 9)
14102 return skl_universal_plane_create(dev_priv, pipe,
14103 PLANE_PRIMARY);
14104
Ville Syrjälä881440a2018-10-05 15:58:17 +030014105 plane = intel_plane_alloc();
14106 if (IS_ERR(plane))
14107 return plane;
Matt Roperea2c67b2014-12-23 10:41:52 -080014108
Ville Syrjälä881440a2018-10-05 15:58:17 +030014109 plane->pipe = pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020014110 /*
14111 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
14112 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
14113 */
14114 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030014115 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020014116 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030014117 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
14118 plane->id = PLANE_PRIMARY;
14119 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020014120
Ville Syrjälä881440a2018-10-05 15:58:17 +030014121 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
14122 if (plane->has_fbc) {
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020014123 struct intel_fbc *fbc = &dev_priv->fbc;
14124
Ville Syrjälä881440a2018-10-05 15:58:17 +030014125 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020014126 }
14127
Ville Syrjäläb7c80602018-10-05 15:58:15 +030014128 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä881440a2018-10-05 15:58:17 +030014129 formats = i965_primary_formats;
Damien Lespiau568db4f2015-05-12 16:13:18 +010014130 num_formats = ARRAY_SIZE(i965_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070014131 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010014132
Ville Syrjälä881440a2018-10-05 15:58:17 +030014133 plane->max_stride = i9xx_plane_max_stride;
14134 plane->update_plane = i9xx_update_plane;
14135 plane->disable_plane = i9xx_disable_plane;
14136 plane->get_hw_state = i9xx_plane_get_hw_state;
14137 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030014138
14139 plane_funcs = &i965_plane_funcs;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010014140 } else {
Ville Syrjälä881440a2018-10-05 15:58:17 +030014141 formats = i8xx_primary_formats;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010014142 num_formats = ARRAY_SIZE(i8xx_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070014143 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010014144
Ville Syrjälä881440a2018-10-05 15:58:17 +030014145 plane->max_stride = i9xx_plane_max_stride;
14146 plane->update_plane = i9xx_update_plane;
14147 plane->disable_plane = i9xx_disable_plane;
14148 plane->get_hw_state = i9xx_plane_get_hw_state;
14149 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030014150
14151 plane_funcs = &i8xx_plane_funcs;
Matt Roper465c1202014-05-29 08:06:54 -070014152 }
14153
Ville Syrjälädeb19682018-10-05 15:58:08 +030014154 possible_crtcs = BIT(pipe);
14155
Ville Syrjäläb7c80602018-10-05 15:58:15 +030014156 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Ville Syrjälä881440a2018-10-05 15:58:17 +030014157 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030014158 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030014159 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030014160 DRM_PLANE_TYPE_PRIMARY,
14161 "primary %c", pipe_name(pipe));
14162 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030014163 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030014164 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030014165 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030014166 DRM_PLANE_TYPE_PRIMARY,
Ville Syrjäläed150302017-11-17 21:19:10 +020014167 "plane %c",
Ville Syrjälä881440a2018-10-05 15:58:17 +030014168 plane_name(plane->i9xx_plane));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014169 if (ret)
14170 goto fail;
Sonika Jindal48404c12014-08-22 14:06:04 +053014171
Ville Syrjäläb7c80602018-10-05 15:58:15 +030014172 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjälä4ea7be22016-11-14 18:54:00 +020014173 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040014174 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
14175 DRM_MODE_REFLECT_X;
Dave Airlie5481e272016-10-25 16:36:13 +100014176 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014177 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040014178 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014179 } else {
Robert Fossc2c446a2017-05-19 16:50:17 -040014180 supported_rotations = DRM_MODE_ROTATE_0;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014181 }
14182
Dave Airlie5481e272016-10-25 16:36:13 +100014183 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030014184 drm_plane_create_rotation_property(&plane->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040014185 DRM_MODE_ROTATE_0,
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014186 supported_rotations);
Sonika Jindal48404c12014-08-22 14:06:04 +053014187
Ville Syrjälä881440a2018-10-05 15:58:17 +030014188 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
Matt Roperea2c67b2014-12-23 10:41:52 -080014189
Ville Syrjälä881440a2018-10-05 15:58:17 +030014190 return plane;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014191
14192fail:
Ville Syrjälä881440a2018-10-05 15:58:17 +030014193 intel_plane_free(plane);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014194
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014195 return ERR_PTR(ret);
Matt Roper465c1202014-05-29 08:06:54 -070014196}
14197
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014198static struct intel_plane *
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014199intel_cursor_plane_create(struct drm_i915_private *dev_priv,
14200 enum pipe pipe)
Matt Roper3d7d6512014-06-10 08:28:13 -070014201{
Ville Syrjälädeb19682018-10-05 15:58:08 +030014202 unsigned int possible_crtcs;
Ville Syrjäläc539b572018-10-05 15:58:14 +030014203 struct intel_plane *cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014204 int ret;
Matt Roper3d7d6512014-06-10 08:28:13 -070014205
Ville Syrjäläc539b572018-10-05 15:58:14 +030014206 cursor = intel_plane_alloc();
14207 if (IS_ERR(cursor))
14208 return cursor;
Matt Roperea2c67b2014-12-23 10:41:52 -080014209
Matt Roper3d7d6512014-06-10 08:28:13 -070014210 cursor->pipe = pipe;
Ville Syrjäläed150302017-11-17 21:19:10 +020014211 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
Ville Syrjäläb14e5842016-11-22 18:01:56 +020014212 cursor->id = PLANE_CURSOR;
Ville Syrjäläc19e1122018-01-23 20:33:43 +020014213 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014214
14215 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
Ville Syrjäläddd57132018-09-07 18:24:02 +030014216 cursor->max_stride = i845_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014217 cursor->update_plane = i845_update_cursor;
14218 cursor->disable_plane = i845_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020014219 cursor->get_hw_state = i845_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030014220 cursor->check_plane = i845_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014221 } else {
Ville Syrjäläddd57132018-09-07 18:24:02 +030014222 cursor->max_stride = i9xx_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014223 cursor->update_plane = i9xx_update_cursor;
14224 cursor->disable_plane = i9xx_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020014225 cursor->get_hw_state = i9xx_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030014226 cursor->check_plane = i9xx_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014227 }
Matt Roper3d7d6512014-06-10 08:28:13 -070014228
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030014229 cursor->cursor.base = ~0;
14230 cursor->cursor.cntl = ~0;
Ville Syrjälä024faac2017-03-27 21:55:42 +030014231
14232 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14233 cursor->cursor.size = ~0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014234
Ville Syrjälädeb19682018-10-05 15:58:08 +030014235 possible_crtcs = BIT(pipe);
14236
Ville Syrjälä580503c2016-10-31 22:37:00 +020014237 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030014238 possible_crtcs, &intel_cursor_plane_funcs,
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014239 intel_cursor_formats,
14240 ARRAY_SIZE(intel_cursor_formats),
Ben Widawsky714244e2017-08-01 09:58:16 -070014241 cursor_format_modifiers,
14242 DRM_PLANE_TYPE_CURSOR,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030014243 "cursor %c", pipe_name(pipe));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014244 if (ret)
14245 goto fail;
Ville Syrjälä4398ad42014-10-23 07:41:34 -070014246
Dave Airlie5481e272016-10-25 16:36:13 +100014247 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014248 drm_plane_create_rotation_property(&cursor->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040014249 DRM_MODE_ROTATE_0,
14250 DRM_MODE_ROTATE_0 |
14251 DRM_MODE_ROTATE_180);
Ville Syrjälä4398ad42014-10-23 07:41:34 -070014252
Matt Roperea2c67b2014-12-23 10:41:52 -080014253 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14254
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014255 return cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014256
14257fail:
Ville Syrjäläc539b572018-10-05 15:58:14 +030014258 intel_plane_free(cursor);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014259
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014260 return ERR_PTR(ret);
Matt Roper3d7d6512014-06-10 08:28:13 -070014261}
14262
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014263static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14264 struct intel_crtc_state *crtc_state)
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014265{
Ville Syrjälä65edccc2016-10-31 22:37:01 +020014266 struct intel_crtc_scaler_state *scaler_state =
14267 &crtc_state->scaler_state;
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014268 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014269 int i;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014270
Jani Nikula02584042018-12-31 16:56:41 +020014271 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014272 if (!crtc->num_scalers)
14273 return;
14274
Ville Syrjälä65edccc2016-10-31 22:37:01 +020014275 for (i = 0; i < crtc->num_scalers; i++) {
14276 struct intel_scaler *scaler = &scaler_state->scalers[i];
14277
14278 scaler->in_use = 0;
Maarten Lankhorst0aaf29b2018-09-21 16:44:37 +020014279 scaler->mode = 0;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014280 }
14281
14282 scaler_state->scaler_id = -1;
14283}
14284
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020014285static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnes79e53942008-11-07 14:24:08 -080014286{
14287 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014288 struct intel_crtc_state *crtc_state = NULL;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014289 struct intel_plane *primary = NULL;
14290 struct intel_plane *cursor = NULL;
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014291 int sprite, ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014292
Daniel Vetter955382f2013-09-19 14:05:45 +020014293 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014294 if (!intel_crtc)
14295 return -ENOMEM;
Jesse Barnes79e53942008-11-07 14:24:08 -080014296
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014297 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014298 if (!crtc_state) {
14299 ret = -ENOMEM;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014300 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014301 }
Ander Conselvan de Oliveira550acef2015-04-21 17:13:24 +030014302 intel_crtc->config = crtc_state;
14303 intel_crtc->base.state = &crtc_state->base;
Matt Roper07878242015-02-25 11:43:26 -080014304 crtc_state->base.crtc = &intel_crtc->base;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014305
Ville Syrjälä580503c2016-10-31 22:37:00 +020014306 primary = intel_primary_plane_create(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014307 if (IS_ERR(primary)) {
14308 ret = PTR_ERR(primary);
Matt Roper3d7d6512014-06-10 08:28:13 -070014309 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014310 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014311 intel_crtc->plane_ids_mask |= BIT(primary->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070014312
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014313 for_each_sprite(dev_priv, pipe, sprite) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014314 struct intel_plane *plane;
14315
Ville Syrjälä580503c2016-10-31 22:37:00 +020014316 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020014317 if (IS_ERR(plane)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014318 ret = PTR_ERR(plane);
14319 goto fail;
14320 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014321 intel_crtc->plane_ids_mask |= BIT(plane->id);
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014322 }
14323
Ville Syrjälä580503c2016-10-31 22:37:00 +020014324 cursor = intel_cursor_plane_create(dev_priv, pipe);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020014325 if (IS_ERR(cursor)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014326 ret = PTR_ERR(cursor);
Matt Roper3d7d6512014-06-10 08:28:13 -070014327 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014328 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014329 intel_crtc->plane_ids_mask |= BIT(cursor->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070014330
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020014331 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014332 &primary->base, &cursor->base,
14333 &intel_crtc_funcs,
Ville Syrjälä4d5d72b72016-05-27 20:59:21 +030014334 "pipe %c", pipe_name(pipe));
Matt Roper3d7d6512014-06-10 08:28:13 -070014335 if (ret)
14336 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080014337
Jesse Barnes80824002009-09-10 15:28:06 -070014338 intel_crtc->pipe = pipe;
Jesse Barnes80824002009-09-10 15:28:06 -070014339
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014340 /* initialize shared scalers */
14341 intel_crtc_init_scalers(intel_crtc, crtc_state);
14342
Ville Syrjälä1947fd12018-03-05 19:41:22 +020014343 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14344 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14345 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14346
14347 if (INTEL_GEN(dev_priv) < 9) {
14348 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14349
14350 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14351 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14352 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14353 }
Jesse Barnes22fd0fa2009-12-02 13:42:53 -080014354
Jesse Barnes79e53942008-11-07 14:24:08 -080014355 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
Daniel Vetter87b6b102014-05-15 15:33:46 +020014356
Matt Roper302da0c2018-12-10 13:54:15 -080014357 intel_color_init(intel_crtc);
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +000014358
Daniel Vetter87b6b102014-05-15 15:33:46 +020014359 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014360
14361 return 0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014362
14363fail:
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014364 /*
14365 * drm_mode_config_cleanup() will free up any
14366 * crtcs/planes already initialized.
14367 */
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014368 kfree(crtc_state);
Matt Roper3d7d6512014-06-10 08:28:13 -070014369 kfree(intel_crtc);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014370
14371 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014372}
14373
Ville Syrjälä6a20fe72018-02-07 18:48:41 +020014374int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14375 struct drm_file *file)
Carl Worth08d7b3d2009-04-29 14:43:54 -070014376{
Carl Worth08d7b3d2009-04-29 14:43:54 -070014377 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
Rob Clark7707e652014-07-17 23:30:04 -040014378 struct drm_crtc *drmmode_crtc;
Daniel Vetterc05422d2009-08-11 16:05:30 +020014379 struct intel_crtc *crtc;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014380
Keith Packard418da172017-03-14 23:25:07 -070014381 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
Chris Wilson71240ed2016-06-24 14:00:24 +010014382 if (!drmmode_crtc)
Ville Syrjälä3f2c2052013-10-17 13:35:03 +030014383 return -ENOENT;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014384
Rob Clark7707e652014-07-17 23:30:04 -040014385 crtc = to_intel_crtc(drmmode_crtc);
Daniel Vetterc05422d2009-08-11 16:05:30 +020014386 pipe_from_crtc_id->pipe = crtc->pipe;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014387
Daniel Vetterc05422d2009-08-11 16:05:30 +020014388 return 0;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014389}
14390
Daniel Vetter66a92782012-07-12 20:08:18 +020014391static int intel_encoder_clones(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080014392{
Daniel Vetter66a92782012-07-12 20:08:18 +020014393 struct drm_device *dev = encoder->base.dev;
14394 struct intel_encoder *source_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -080014395 int index_mask = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080014396 int entry = 0;
14397
Damien Lespiaub2784e12014-08-05 11:29:37 +010014398 for_each_intel_encoder(dev, source_encoder) {
Ville Syrjäläbc079e82014-03-03 16:15:28 +020014399 if (encoders_cloneable(encoder, source_encoder))
Daniel Vetter66a92782012-07-12 20:08:18 +020014400 index_mask |= (1 << entry);
14401
Jesse Barnes79e53942008-11-07 14:24:08 -080014402 entry++;
14403 }
Chris Wilson4ef69c72010-09-09 15:14:28 +010014404
Jesse Barnes79e53942008-11-07 14:24:08 -080014405 return index_mask;
14406}
14407
Jani Nikulaa5916fd2019-01-22 10:23:05 +020014408static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
Chris Wilson4d302442010-12-14 19:21:29 +000014409{
Ville Syrjälä646d5772016-10-31 22:37:14 +020014410 if (!IS_MOBILE(dev_priv))
Chris Wilson4d302442010-12-14 19:21:29 +000014411 return false;
14412
14413 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14414 return false;
14415
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014416 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
Chris Wilson4d302442010-12-14 19:21:29 +000014417 return false;
14418
14419 return true;
14420}
14421
Jani Nikula63cb4e62019-01-22 10:23:01 +020014422static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014423{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014424 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau884497e2013-12-03 13:56:23 +000014425 return false;
14426
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010014427 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014428 return false;
14429
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014430 if (HAS_PCH_LPT_H(dev_priv) &&
14431 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
Ville Syrjälä65e472e2015-12-01 23:28:55 +020014432 return false;
14433
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014434 /* DDI E can't be used if DDI A requires 4 lanes */
Jani Nikula63cb4e62019-01-22 10:23:01 +020014435 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014436 return false;
14437
Ville Syrjäläe4abb732015-12-01 23:31:33 +020014438 if (!dev_priv->vbt.int_crt_support)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014439 return false;
14440
14441 return true;
14442}
14443
Imre Deak8090ba82016-08-10 14:07:33 +030014444void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14445{
14446 int pps_num;
14447 int pps_idx;
14448
14449 if (HAS_DDI(dev_priv))
14450 return;
14451 /*
14452 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14453 * everywhere where registers can be write protected.
14454 */
14455 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14456 pps_num = 2;
14457 else
14458 pps_num = 1;
14459
14460 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14461 u32 val = I915_READ(PP_CONTROL(pps_idx));
14462
14463 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14464 I915_WRITE(PP_CONTROL(pps_idx), val);
14465 }
14466}
14467
Imre Deak44cb7342016-08-10 14:07:29 +030014468static void intel_pps_init(struct drm_i915_private *dev_priv)
14469{
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +020014470 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +030014471 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14472 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14473 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14474 else
14475 dev_priv->pps_mmio_base = PPS_BASE;
Imre Deak8090ba82016-08-10 14:07:33 +030014476
14477 intel_pps_unlock_regs_wa(dev_priv);
Imre Deak44cb7342016-08-10 14:07:29 +030014478}
14479
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014480static void intel_setup_outputs(struct drm_i915_private *dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -080014481{
Chris Wilson4ef69c72010-09-09 15:14:28 +010014482 struct intel_encoder *encoder;
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014483 bool dpd_is_edp = false;
Jesse Barnes79e53942008-11-07 14:24:08 -080014484
Imre Deak44cb7342016-08-10 14:07:29 +030014485 intel_pps_init(dev_priv);
14486
José Roberto de Souzae1bf0942018-11-30 15:20:47 -080014487 if (!HAS_DISPLAY(dev_priv))
Chris Wilsonfc0c5a92018-08-15 21:12:07 +010014488 return;
14489
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014490 if (IS_ICELAKE(dev_priv)) {
14491 intel_ddi_init(dev_priv, PORT_A);
14492 intel_ddi_init(dev_priv, PORT_B);
14493 intel_ddi_init(dev_priv, PORT_C);
14494 intel_ddi_init(dev_priv, PORT_D);
14495 intel_ddi_init(dev_priv, PORT_E);
Imre Deak3f2e9ed2018-12-20 15:26:03 +020014496 /*
14497 * On some ICL SKUs port F is not present. No strap bits for
14498 * this, so rely on VBT.
Imre Deak2b34e5622018-12-20 17:52:11 +020014499 * Work around broken VBTs on SKUs known to have no port F.
Imre Deak3f2e9ed2018-12-20 15:26:03 +020014500 */
Imre Deak2b34e5622018-12-20 17:52:11 +020014501 if (IS_ICL_WITH_PORT_F(dev_priv) &&
14502 intel_bios_is_port_present(dev_priv, PORT_F))
Imre Deak3f2e9ed2018-12-20 15:26:03 +020014503 intel_ddi_init(dev_priv, PORT_F);
14504
Madhav Chauhanbf4d57f2018-10-30 13:56:23 +020014505 icl_dsi_init(dev_priv);
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014506 } else if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanc776eb22014-08-19 12:05:01 +053014507 /*
14508 * FIXME: Broxton doesn't support port detection via the
14509 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14510 * detect the ports.
14511 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014512 intel_ddi_init(dev_priv, PORT_A);
14513 intel_ddi_init(dev_priv, PORT_B);
14514 intel_ddi_init(dev_priv, PORT_C);
Shashank Sharmac6c794a2016-03-22 12:01:50 +020014515
Jani Nikulae5186342018-07-05 16:25:08 +030014516 vlv_dsi_init(dev_priv);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014517 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014518 int found;
14519
Jani Nikula63cb4e62019-01-22 10:23:01 +020014520 if (intel_ddi_crt_present(dev_priv))
14521 intel_crt_init(dev_priv);
14522
Jesse Barnesde31fac2015-03-06 15:53:32 -080014523 /*
14524 * Haswell uses DDI functions to detect digital outputs.
14525 * On SKL pre-D0 the strap isn't connected, so we assume
14526 * it's there.
14527 */
Ville Syrjälä77179402015-09-18 20:03:35 +030014528 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
Jesse Barnesde31fac2015-03-06 15:53:32 -080014529 /* WaIgnoreDDIAStrap: skl */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014530 if (found || IS_GEN9_BC(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014531 intel_ddi_init(dev_priv, PORT_A);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014532
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014533 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014534 * register */
14535 found = I915_READ(SFUSE_STRAP);
14536
14537 if (found & SFUSE_STRAP_DDIB_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014538 intel_ddi_init(dev_priv, PORT_B);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014539 if (found & SFUSE_STRAP_DDIC_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014540 intel_ddi_init(dev_priv, PORT_C);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014541 if (found & SFUSE_STRAP_DDID_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014542 intel_ddi_init(dev_priv, PORT_D);
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014543 if (found & SFUSE_STRAP_DDIF_DETECTED)
14544 intel_ddi_init(dev_priv, PORT_F);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014545 /*
14546 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14547 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014548 if (IS_GEN9_BC(dev_priv) &&
Imre Deake9d49bb2018-12-20 15:26:02 +020014549 intel_bios_is_port_present(dev_priv, PORT_E))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014550 intel_ddi_init(dev_priv, PORT_E);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014551
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010014552 } else if (HAS_PCH_SPLIT(dev_priv)) {
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014553 int found;
Jani Nikula63cb4e62019-01-22 10:23:01 +020014554
Jani Nikula0fafa222019-01-22 10:23:02 +020014555 /*
14556 * intel_edp_init_connector() depends on this completing first,
14557 * to prevent the registration of both eDP and LVDS and the
14558 * incorrect sharing of the PPS.
14559 */
14560 intel_lvds_init(dev_priv);
Jani Nikula74d021e2019-01-22 10:23:07 +020014561 intel_crt_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014562
Jani Nikula7b91bf72017-08-18 12:30:19 +030014563 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
Daniel Vetter270b3042012-10-27 15:52:05 +020014564
Jani Nikulaa5916fd2019-01-22 10:23:05 +020014565 if (ilk_has_edp_a(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014566 intel_dp_init(dev_priv, DP_A, PORT_A);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014567
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014568 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
Zhao Yakui461ed3c2010-03-30 15:11:33 +080014569 /* PCH SDVOB multiplex with HDMIB */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014570 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014571 if (!found)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014572 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014573 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014574 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014575 }
14576
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014577 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014578 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014579
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014580 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014581 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014582
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014583 if (I915_READ(PCH_DP_C) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014584 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014585
Daniel Vetter270b3042012-10-27 15:52:05 +020014586 if (I915_READ(PCH_DP_D) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014587 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014588 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014589 bool has_edp, has_port;
Chris Wilson457c52d2016-06-01 08:27:50 +010014590
Jani Nikula63cb4e62019-01-22 10:23:01 +020014591 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
14592 intel_crt_init(dev_priv);
14593
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014594 /*
14595 * The DP_DETECTED bit is the latched state of the DDC
14596 * SDA pin at boot. However since eDP doesn't require DDC
14597 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14598 * eDP ports may have been muxed to an alternate function.
14599 * Thus we can't rely on the DP_DETECTED bit alone to detect
14600 * eDP ports. Consult the VBT as well as DP_DETECTED to
14601 * detect eDP ports.
Ville Syrjälä22f350422016-06-03 12:17:43 +030014602 *
14603 * Sadly the straps seem to be missing sometimes even for HDMI
14604 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14605 * and VBT for the presence of the port. Additionally we can't
14606 * trust the port type the VBT declares as we've seen at least
14607 * HDMI ports that the VBT claim are DP or eDP.
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014608 */
Jani Nikula7b91bf72017-08-18 12:30:19 +030014609 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014610 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14611 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014612 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014613 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014614 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
Artem Bityutskiy585a94b2013-10-16 18:10:41 +030014615
Jani Nikula7b91bf72017-08-18 12:30:19 +030014616 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014617 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14618 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014619 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014620 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014621 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
Gajanan Bhat19c03922012-09-27 19:13:07 +053014622
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014623 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014624 /*
14625 * eDP not supported on port D,
14626 * so no need to worry about it
14627 */
14628 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14629 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014630 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014631 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014632 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
Ville Syrjälä9418c1f2014-04-09 13:28:56 +030014633 }
14634
Jani Nikulae5186342018-07-05 16:25:08 +030014635 vlv_dsi_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014636 } else if (IS_PINEVIEW(dev_priv)) {
Jani Nikula0fafa222019-01-22 10:23:02 +020014637 intel_lvds_init(dev_priv);
Jani Nikula74d021e2019-01-22 10:23:07 +020014638 intel_crt_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014639 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014640 bool found = false;
Eric Anholt7d573822009-01-02 13:33:00 -080014641
Jani Nikula9bedc7e2019-01-22 10:23:03 +020014642 if (IS_MOBILE(dev_priv))
14643 intel_lvds_init(dev_priv);
Jani Nikula0fafa222019-01-22 10:23:02 +020014644
Jani Nikula74d021e2019-01-22 10:23:07 +020014645 intel_crt_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014646
Paulo Zanonie2debe92013-02-18 19:00:27 -030014647 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014648 DRM_DEBUG_KMS("probing SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014649 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014650 if (!found && IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014651 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014652 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014653 }
Ma Ling27185ae2009-08-24 13:50:23 +080014654
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014655 if (!found && IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014656 intel_dp_init(dev_priv, DP_B, PORT_B);
Eric Anholt725e30a2009-01-22 13:01:02 -080014657 }
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014658
14659 /* Before G4X SDVOC doesn't have its own detect register */
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014660
Paulo Zanonie2debe92013-02-18 19:00:27 -030014661 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014662 DRM_DEBUG_KMS("probing SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014663 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014664 }
Ma Ling27185ae2009-08-24 13:50:23 +080014665
Paulo Zanonie2debe92013-02-18 19:00:27 -030014666 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014667
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014668 if (IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014669 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014670 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014671 }
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014672 if (IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014673 intel_dp_init(dev_priv, DP_C, PORT_C);
Eric Anholt725e30a2009-01-22 13:01:02 -080014674 }
Ma Ling27185ae2009-08-24 13:50:23 +080014675
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014676 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014677 intel_dp_init(dev_priv, DP_D, PORT_D);
Jani Nikulad6521462019-01-22 10:23:04 +020014678
14679 if (SUPPORTS_TV(dev_priv))
14680 intel_tv_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014681 } else if (IS_GEN(dev_priv, 2)) {
Jani Nikula346073c2019-01-22 10:23:06 +020014682 if (IS_I85X(dev_priv))
Jani Nikula9bedc7e2019-01-22 10:23:03 +020014683 intel_lvds_init(dev_priv);
Jani Nikula0fafa222019-01-22 10:23:02 +020014684
Jani Nikula74d021e2019-01-22 10:23:07 +020014685 intel_crt_init(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014686 intel_dvo_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014687 }
Jesse Barnes79e53942008-11-07 14:24:08 -080014688
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014689 intel_psr_init(dev_priv);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -070014690
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014691 for_each_intel_encoder(&dev_priv->drm, encoder) {
Chris Wilson4ef69c72010-09-09 15:14:28 +010014692 encoder->base.possible_crtcs = encoder->crtc_mask;
14693 encoder->base.possible_clones =
Daniel Vetter66a92782012-07-12 20:08:18 +020014694 intel_encoder_clones(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -080014695 }
Chris Wilson47356eb2011-01-11 17:06:04 +000014696
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014697 intel_init_pch_refclk(dev_priv);
Daniel Vetter270b3042012-10-27 15:52:05 +020014698
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014699 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
Jesse Barnes79e53942008-11-07 14:24:08 -080014700}
14701
14702static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14703{
14704 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014705 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014706
Daniel Vetteref2d6332014-02-10 18:00:38 +010014707 drm_framebuffer_cleanup(fb);
Chris Wilson70001cd2017-02-16 09:46:21 +000014708
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014709 i915_gem_object_lock(obj);
14710 WARN_ON(!obj->framebuffer_references--);
14711 i915_gem_object_unlock(obj);
Chris Wilsondd689282017-03-01 15:41:28 +000014712
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014713 i915_gem_object_put(obj);
Chris Wilson70001cd2017-02-16 09:46:21 +000014714
Jesse Barnes79e53942008-11-07 14:24:08 -080014715 kfree(intel_fb);
14716}
14717
14718static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
Chris Wilson05394f32010-11-08 19:18:58 +000014719 struct drm_file *file,
Jesse Barnes79e53942008-11-07 14:24:08 -080014720 unsigned int *handle)
14721{
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014722 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014723
Chris Wilsoncc917ab2015-10-13 14:22:26 +010014724 if (obj->userptr.mm) {
14725 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14726 return -EINVAL;
14727 }
14728
Chris Wilson05394f32010-11-08 19:18:58 +000014729 return drm_gem_handle_create(file, &obj->base, handle);
Jesse Barnes79e53942008-11-07 14:24:08 -080014730}
14731
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014732static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14733 struct drm_file *file,
14734 unsigned flags, unsigned color,
14735 struct drm_clip_rect *clips,
14736 unsigned num_clips)
14737{
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014738 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014739
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014740 i915_gem_object_flush_if_display(obj);
Chris Wilsond59b21e2017-02-22 11:40:49 +000014741 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014742
14743 return 0;
14744}
14745
Jesse Barnes79e53942008-11-07 14:24:08 -080014746static const struct drm_framebuffer_funcs intel_fb_funcs = {
14747 .destroy = intel_user_framebuffer_destroy,
14748 .create_handle = intel_user_framebuffer_create_handle,
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014749 .dirty = intel_user_framebuffer_dirty,
Jesse Barnes79e53942008-11-07 14:24:08 -080014750};
14751
Damien Lespiaub3218032015-02-27 11:15:18 +000014752static
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014753u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014754 u32 pixel_format, u64 fb_modifier)
Damien Lespiaub3218032015-02-27 11:15:18 +000014755{
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014756 struct intel_crtc *crtc;
14757 struct intel_plane *plane;
Damien Lespiaub3218032015-02-27 11:15:18 +000014758
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014759 /*
14760 * We assume the primary plane for pipe A has
14761 * the highest stride limits of them all.
14762 */
14763 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14764 plane = to_intel_plane(crtc->base.primary);
Ville Syrjäläac484962016-01-20 21:05:26 +020014765
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014766 return plane->max_stride(plane, pixel_format, fb_modifier,
14767 DRM_MODE_ROTATE_0);
Damien Lespiaub3218032015-02-27 11:15:18 +000014768}
14769
Chris Wilson24dbf512017-02-15 10:59:18 +000014770static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14771 struct drm_i915_gem_object *obj,
14772 struct drm_mode_fb_cmd2 *mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014773{
Chris Wilson24dbf512017-02-15 10:59:18 +000014774 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014775 struct drm_framebuffer *fb = &intel_fb->base;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014776 u32 pitch_limit;
Chris Wilsondd689282017-03-01 15:41:28 +000014777 unsigned int tiling, stride;
Chris Wilson24dbf512017-02-15 10:59:18 +000014778 int ret = -EINVAL;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014779 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -080014780
Chris Wilsondd689282017-03-01 15:41:28 +000014781 i915_gem_object_lock(obj);
14782 obj->framebuffer_references++;
14783 tiling = i915_gem_object_get_tiling(obj);
14784 stride = i915_gem_object_get_stride(obj);
14785 i915_gem_object_unlock(obj);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020014786
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014787 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014788 /*
14789 * If there's a fence, enforce that
14790 * the fb modifier and tiling mode match.
14791 */
14792 if (tiling != I915_TILING_NONE &&
14793 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014794 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014795 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014796 }
14797 } else {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014798 if (tiling == I915_TILING_X) {
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014799 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014800 } else if (tiling == I915_TILING_Y) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014801 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014802 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014803 }
14804 }
14805
Ville Syrjälä17e8fd12018-10-29 20:34:53 +020014806 if (!drm_any_plane_has_format(&dev_priv->drm,
14807 mode_cmd->pixel_format,
14808 mode_cmd->modifier[0])) {
14809 struct drm_format_name_buf format_name;
14810
14811 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
14812 drm_get_format_name(mode_cmd->pixel_format,
14813 &format_name),
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014814 mode_cmd->modifier[0]);
Chris Wilson24dbf512017-02-15 10:59:18 +000014815 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014816 }
Chris Wilson57cd6502010-08-08 12:34:44 +010014817
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014818 /*
14819 * gen2/3 display engine uses the fence if present,
14820 * so the tiling mode must match the fb modifier exactly.
14821 */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014822 if (INTEL_GEN(dev_priv) < 4 &&
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014823 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014824 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014825 goto err;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014826 }
14827
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014828 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format,
14829 mode_cmd->modifier[0]);
Chris Wilsona35cdaa2013-06-25 17:26:45 +010014830 if (mode_cmd->pitches[0] > pitch_limit) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014831 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
Ben Widawsky2f075562017-03-24 14:29:48 -070014832 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014833 "tiled" : "linear",
14834 mode_cmd->pitches[0], pitch_limit);
Chris Wilson24dbf512017-02-15 10:59:18 +000014835 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014836 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014837
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014838 /*
14839 * If there's a fence, enforce that
14840 * the fb pitch and fence stride match.
14841 */
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014842 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14843 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14844 mode_cmd->pitches[0], stride);
Chris Wilson24dbf512017-02-15 10:59:18 +000014845 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014846 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014847
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014848 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14849 if (mode_cmd->offsets[0] != 0)
Chris Wilson24dbf512017-02-15 10:59:18 +000014850 goto err;
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014851
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014852 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014853
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014854 for (i = 0; i < fb->format->num_planes; i++) {
14855 u32 stride_alignment;
14856
14857 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14858 DRM_DEBUG_KMS("bad plane %d handle\n", i);
Christophe JAILLET37875d62017-09-10 10:56:42 +020014859 goto err;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014860 }
14861
14862 stride_alignment = intel_fb_stride_alignment(fb, i);
14863
14864 /*
14865 * Display WA #0531: skl,bxt,kbl,glk
14866 *
14867 * Render decompression and plane width > 3840
14868 * combined with horizontal panning requires the
14869 * plane stride to be a multiple of 4. We'll just
14870 * require the entire fb to accommodate that to avoid
14871 * potential runtime errors at plane configuration time.
14872 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014873 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -070014874 is_ccs_modifier(fb->modifier))
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014875 stride_alignment *= 4;
14876
14877 if (fb->pitches[i] & (stride_alignment - 1)) {
14878 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14879 i, fb->pitches[i], stride_alignment);
14880 goto err;
14881 }
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014882
Daniel Stonea268bcd2018-05-18 15:30:08 +010014883 fb->obj[i] = &obj->base;
14884 }
Daniel Vetterc7d73f62012-12-13 23:38:38 +010014885
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014886 ret = intel_fill_fb_info(dev_priv, fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +030014887 if (ret)
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014888 goto err;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +020014889
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014890 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -080014891 if (ret) {
14892 DRM_ERROR("framebuffer init failed %d\n", ret);
Chris Wilson24dbf512017-02-15 10:59:18 +000014893 goto err;
Jesse Barnes79e53942008-11-07 14:24:08 -080014894 }
14895
Jesse Barnes79e53942008-11-07 14:24:08 -080014896 return 0;
Chris Wilson24dbf512017-02-15 10:59:18 +000014897
14898err:
Chris Wilsondd689282017-03-01 15:41:28 +000014899 i915_gem_object_lock(obj);
14900 obj->framebuffer_references--;
14901 i915_gem_object_unlock(obj);
Chris Wilson24dbf512017-02-15 10:59:18 +000014902 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014903}
14904
Jesse Barnes79e53942008-11-07 14:24:08 -080014905static struct drm_framebuffer *
14906intel_user_framebuffer_create(struct drm_device *dev,
14907 struct drm_file *filp,
Ville Syrjälä1eb83452015-11-11 19:11:29 +020014908 const struct drm_mode_fb_cmd2 *user_mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014909{
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014910 struct drm_framebuffer *fb;
Chris Wilson05394f32010-11-08 19:18:58 +000014911 struct drm_i915_gem_object *obj;
Ville Syrjälä76dc3762015-11-11 19:11:28 +020014912 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
Jesse Barnes79e53942008-11-07 14:24:08 -080014913
Chris Wilson03ac0642016-07-20 13:31:51 +010014914 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14915 if (!obj)
Chris Wilsoncce13ff2010-08-08 13:36:38 +010014916 return ERR_PTR(-ENOENT);
Jesse Barnes79e53942008-11-07 14:24:08 -080014917
Chris Wilson24dbf512017-02-15 10:59:18 +000014918 fb = intel_framebuffer_create(obj, &mode_cmd);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014919 if (IS_ERR(fb))
Chris Wilsonf0cd5182016-10-28 13:58:43 +010014920 i915_gem_object_put(obj);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014921
14922 return fb;
Jesse Barnes79e53942008-11-07 14:24:08 -080014923}
14924
Chris Wilson778e23a2016-12-05 14:29:39 +000014925static void intel_atomic_state_free(struct drm_atomic_state *state)
14926{
14927 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14928
14929 drm_atomic_state_default_release(state);
14930
14931 i915_sw_fence_fini(&intel_state->commit_ready);
14932
14933 kfree(state);
14934}
14935
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014936static enum drm_mode_status
14937intel_mode_valid(struct drm_device *dev,
14938 const struct drm_display_mode *mode)
14939{
Ville Syrjäläad77c532018-06-15 20:44:05 +030014940 struct drm_i915_private *dev_priv = to_i915(dev);
14941 int hdisplay_max, htotal_max;
14942 int vdisplay_max, vtotal_max;
14943
Ville Syrjäläe4dd27a2018-05-24 15:54:03 +030014944 /*
14945 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14946 * of DBLSCAN modes to the output's mode list when they detect
14947 * the scaling mode property on the connector. And they don't
14948 * ask the kernel to validate those modes in any way until
14949 * modeset time at which point the client gets a protocol error.
14950 * So in order to not upset those clients we silently ignore the
14951 * DBLSCAN flag on such connectors. For other connectors we will
14952 * reject modes with the DBLSCAN flag in encoder->compute_config().
14953 * And we always reject DBLSCAN modes in connector->mode_valid()
14954 * as we never want such modes on the connector's mode list.
14955 */
14956
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014957 if (mode->vscan > 1)
14958 return MODE_NO_VSCAN;
14959
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014960 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14961 return MODE_H_ILLEGAL;
14962
14963 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14964 DRM_MODE_FLAG_NCSYNC |
14965 DRM_MODE_FLAG_PCSYNC))
14966 return MODE_HSYNC;
14967
14968 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14969 DRM_MODE_FLAG_PIXMUX |
14970 DRM_MODE_FLAG_CLKDIV2))
14971 return MODE_BAD;
14972
Ville Syrjäläad77c532018-06-15 20:44:05 +030014973 if (INTEL_GEN(dev_priv) >= 9 ||
14974 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14975 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14976 vdisplay_max = 4096;
14977 htotal_max = 8192;
14978 vtotal_max = 8192;
14979 } else if (INTEL_GEN(dev_priv) >= 3) {
14980 hdisplay_max = 4096;
14981 vdisplay_max = 4096;
14982 htotal_max = 8192;
14983 vtotal_max = 8192;
14984 } else {
14985 hdisplay_max = 2048;
14986 vdisplay_max = 2048;
14987 htotal_max = 4096;
14988 vtotal_max = 4096;
14989 }
14990
14991 if (mode->hdisplay > hdisplay_max ||
14992 mode->hsync_start > htotal_max ||
14993 mode->hsync_end > htotal_max ||
14994 mode->htotal > htotal_max)
14995 return MODE_H_ILLEGAL;
14996
14997 if (mode->vdisplay > vdisplay_max ||
14998 mode->vsync_start > vtotal_max ||
14999 mode->vsync_end > vtotal_max ||
15000 mode->vtotal > vtotal_max)
15001 return MODE_V_ILLEGAL;
15002
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020015003 return MODE_OK;
15004}
15005
Jesse Barnes79e53942008-11-07 14:24:08 -080015006static const struct drm_mode_config_funcs intel_mode_funcs = {
Jesse Barnes79e53942008-11-07 14:24:08 -080015007 .fb_create = intel_user_framebuffer_create,
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -070015008 .get_format_info = intel_get_format_info,
Daniel Vetter0632fef2013-10-08 17:44:49 +020015009 .output_poll_changed = intel_fbdev_output_poll_changed,
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020015010 .mode_valid = intel_mode_valid,
Matt Roper5ee67f12015-01-21 16:35:44 -080015011 .atomic_check = intel_atomic_check,
15012 .atomic_commit = intel_atomic_commit,
Maarten Lankhorstde419ab2015-06-04 10:21:28 +020015013 .atomic_state_alloc = intel_atomic_state_alloc,
15014 .atomic_state_clear = intel_atomic_state_clear,
Chris Wilson778e23a2016-12-05 14:29:39 +000015015 .atomic_state_free = intel_atomic_state_free,
Jesse Barnes79e53942008-11-07 14:24:08 -080015016};
15017
Imre Deak88212942016-03-16 13:38:53 +020015018/**
15019 * intel_init_display_hooks - initialize the display modesetting hooks
15020 * @dev_priv: device private
15021 */
15022void intel_init_display_hooks(struct drm_i915_private *dev_priv)
Jesse Barnese70236a2009-09-21 10:42:27 -070015023{
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +020015024 intel_init_cdclk_hooks(dev_priv);
15025
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000015026 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000015027 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015028 dev_priv->display.get_initial_plane_config =
15029 skylake_get_initial_plane_config;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000015030 dev_priv->display.crtc_compute_clock =
15031 haswell_crtc_compute_clock;
15032 dev_priv->display.crtc_enable = haswell_crtc_enable;
15033 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020015034 } else if (HAS_DDI(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010015035 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015036 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020015037 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira797d0252014-10-29 11:32:34 +020015038 dev_priv->display.crtc_compute_clock =
15039 haswell_crtc_compute_clock;
Paulo Zanoni4f771f12012-10-23 18:29:51 -020015040 dev_priv->display.crtc_enable = haswell_crtc_enable;
15041 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020015042 } else if (HAS_PCH_SPLIT(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010015043 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015044 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020015045 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +020015046 dev_priv->display.crtc_compute_clock =
15047 ironlake_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020015048 dev_priv->display.crtc_enable = ironlake_crtc_enable;
15049 dev_priv->display.crtc_disable = ironlake_crtc_disable;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020015050 } else if (IS_CHERRYVIEW(dev_priv)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -070015051 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015052 dev_priv->display.get_initial_plane_config =
15053 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020015054 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
15055 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15056 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15057 } else if (IS_VALLEYVIEW(dev_priv)) {
15058 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15059 dev_priv->display.get_initial_plane_config =
15060 i9xx_get_initial_plane_config;
15061 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
Jesse Barnes89b667f2013-04-18 14:51:36 -070015062 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15063 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +020015064 } else if (IS_G4X(dev_priv)) {
15065 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15066 dev_priv->display.get_initial_plane_config =
15067 i9xx_get_initial_plane_config;
15068 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
15069 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15070 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +020015071 } else if (IS_PINEVIEW(dev_priv)) {
15072 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15073 dev_priv->display.get_initial_plane_config =
15074 i9xx_get_initial_plane_config;
15075 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
15076 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15077 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015078 } else if (!IS_GEN(dev_priv, 2)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010015079 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015080 dev_priv->display.get_initial_plane_config =
15081 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveirad6dfee72014-10-29 11:32:36 +020015082 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020015083 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15084 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +020015085 } else {
15086 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15087 dev_priv->display.get_initial_plane_config =
15088 i9xx_get_initial_plane_config;
15089 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
15090 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15091 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Eric Anholtf564048e2011-03-30 13:01:02 -070015092 }
Jesse Barnese70236a2009-09-21 10:42:27 -070015093
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015094 if (IS_GEN(dev_priv, 5)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053015095 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015096 } else if (IS_GEN(dev_priv, 6)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053015097 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020015098 } else if (IS_IVYBRIDGE(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053015099 /* FIXME: detect B0+ stepping and use auto training */
15100 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020015101 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053015102 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
Ville Syrjälä445e7802016-05-11 22:44:42 +030015103 }
15104
Rodrigo Vivibd30ca22017-09-26 14:13:46 -070015105 if (INTEL_GEN(dev_priv) >= 9)
Lyude27082492016-08-24 07:48:10 +020015106 dev_priv->display.update_crtcs = skl_update_crtcs;
15107 else
15108 dev_priv->display.update_crtcs = intel_update_crtcs;
Jesse Barnese70236a2009-09-21 10:42:27 -070015109}
15110
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015111/* Disable the VGA plane that we never use */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015112static void i915_disable_vga(struct drm_i915_private *dev_priv)
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015113{
David Weinehall52a05c32016-08-22 13:32:44 +030015114 struct pci_dev *pdev = dev_priv->drm.pdev;
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015115 u8 sr1;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010015116 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015117
Ville Syrjälä2b37c612014-01-22 21:32:38 +020015118 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
David Weinehall52a05c32016-08-22 13:32:44 +030015119 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes3fdcf432012-04-06 11:46:27 -070015120 outb(SR01, VGA_SR_INDEX);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015121 sr1 = inb(VGA_SR_DATA);
15122 outb(sr1 | 1<<5, VGA_SR_DATA);
David Weinehall52a05c32016-08-22 13:32:44 +030015123 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015124 udelay(300);
15125
Ville Syrjälä01f5a622014-12-16 18:38:37 +020015126 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015127 POSTING_READ(vga_reg);
15128}
15129
Daniel Vetterf8175862012-04-10 15:50:11 +020015130void intel_modeset_init_hw(struct drm_device *dev)
15131{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015132 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1a617b72015-12-03 14:31:06 +010015133
Ville Syrjälä4c75b942016-10-31 22:37:12 +020015134 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +030015135 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020015136 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
Daniel Vetterf8175862012-04-10 15:50:11 +020015137}
15138
Matt Roperd93c0372015-12-03 11:37:41 -080015139/*
15140 * Calculate what we think the watermarks should be for the state we've read
15141 * out of the hardware and then immediately program those watermarks so that
15142 * we ensure the hardware settings match our internal state.
15143 *
15144 * We can calculate what we think WM's should be by creating a duplicate of the
15145 * current state (which was constructed during hardware readout) and running it
15146 * through the atomic check code to calculate new watermark values in the
15147 * state object.
15148 */
15149static void sanitize_watermarks(struct drm_device *dev)
15150{
15151 struct drm_i915_private *dev_priv = to_i915(dev);
15152 struct drm_atomic_state *state;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010015153 struct intel_atomic_state *intel_state;
Matt Roperd93c0372015-12-03 11:37:41 -080015154 struct drm_crtc *crtc;
15155 struct drm_crtc_state *cstate;
15156 struct drm_modeset_acquire_ctx ctx;
15157 int ret;
15158 int i;
15159
15160 /* Only supported on platforms that use atomic watermark design */
Matt Ropered4a6a72016-02-23 17:20:13 -080015161 if (!dev_priv->display.optimize_watermarks)
Matt Roperd93c0372015-12-03 11:37:41 -080015162 return;
15163
15164 /*
15165 * We need to hold connection_mutex before calling duplicate_state so
15166 * that the connector loop is protected.
15167 */
15168 drm_modeset_acquire_init(&ctx, 0);
15169retry:
Matt Roper0cd12622016-01-12 07:13:37 -080015170 ret = drm_modeset_lock_all_ctx(dev, &ctx);
Matt Roperd93c0372015-12-03 11:37:41 -080015171 if (ret == -EDEADLK) {
15172 drm_modeset_backoff(&ctx);
15173 goto retry;
15174 } else if (WARN_ON(ret)) {
Matt Roper0cd12622016-01-12 07:13:37 -080015175 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080015176 }
15177
15178 state = drm_atomic_helper_duplicate_state(dev, &ctx);
15179 if (WARN_ON(IS_ERR(state)))
Matt Roper0cd12622016-01-12 07:13:37 -080015180 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080015181
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010015182 intel_state = to_intel_atomic_state(state);
15183
Matt Ropered4a6a72016-02-23 17:20:13 -080015184 /*
15185 * Hardware readout is the only time we don't want to calculate
15186 * intermediate watermarks (since we don't trust the current
15187 * watermarks).
15188 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080015189 if (!HAS_GMCH(dev_priv))
Ville Syrjälä602ae832017-03-02 19:15:02 +020015190 intel_state->skip_intermediate_wm = true;
Matt Ropered4a6a72016-02-23 17:20:13 -080015191
Matt Roperd93c0372015-12-03 11:37:41 -080015192 ret = intel_atomic_check(dev, state);
15193 if (ret) {
15194 /*
15195 * If we fail here, it means that the hardware appears to be
15196 * programmed in a way that shouldn't be possible, given our
15197 * understanding of watermark requirements. This might mean a
15198 * mistake in the hardware readout code or a mistake in the
15199 * watermark calculations for a given platform. Raise a WARN
15200 * so that this is noticeable.
15201 *
15202 * If this actually happens, we'll have to just leave the
15203 * BIOS-programmed watermarks untouched and hope for the best.
15204 */
15205 WARN(true, "Could not determine valid watermarks for inherited state\n");
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020015206 goto put_state;
Matt Roperd93c0372015-12-03 11:37:41 -080015207 }
15208
15209 /* Write calculated watermark values back */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010015210 for_each_new_crtc_in_state(state, crtc, cstate, i) {
Matt Roperd93c0372015-12-03 11:37:41 -080015211 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
15212
Matt Ropered4a6a72016-02-23 17:20:13 -080015213 cs->wm.need_postvbl_update = true;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010015214 dev_priv->display.optimize_watermarks(intel_state, cs);
Maarten Lankhorst556fe362017-11-10 12:34:53 +010015215
15216 to_intel_crtc_state(crtc->state)->wm = cs->wm;
Matt Roperd93c0372015-12-03 11:37:41 -080015217 }
15218
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020015219put_state:
Chris Wilson08536952016-10-14 13:18:18 +010015220 drm_atomic_state_put(state);
Matt Roper0cd12622016-01-12 07:13:37 -080015221fail:
Matt Roperd93c0372015-12-03 11:37:41 -080015222 drm_modeset_drop_locks(&ctx);
15223 drm_modeset_acquire_fini(&ctx);
15224}
15225
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015226static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
15227{
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015228 if (IS_GEN(dev_priv, 5)) {
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015229 u32 fdi_pll_clk =
15230 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
15231
15232 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015233 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015234 dev_priv->fdi_pll_freq = 270000;
15235 } else {
15236 return;
15237 }
15238
15239 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
15240}
15241
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015242static int intel_initial_commit(struct drm_device *dev)
15243{
15244 struct drm_atomic_state *state = NULL;
15245 struct drm_modeset_acquire_ctx ctx;
15246 struct drm_crtc *crtc;
15247 struct drm_crtc_state *crtc_state;
15248 int ret = 0;
15249
15250 state = drm_atomic_state_alloc(dev);
15251 if (!state)
15252 return -ENOMEM;
15253
15254 drm_modeset_acquire_init(&ctx, 0);
15255
15256retry:
15257 state->acquire_ctx = &ctx;
15258
15259 drm_for_each_crtc(crtc, dev) {
15260 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15261 if (IS_ERR(crtc_state)) {
15262 ret = PTR_ERR(crtc_state);
15263 goto out;
15264 }
15265
15266 if (crtc_state->active) {
15267 ret = drm_atomic_add_affected_planes(state, crtc);
15268 if (ret)
15269 goto out;
Ville Syrjäläfa6af5142018-11-20 15:54:49 +020015270
15271 /*
15272 * FIXME hack to force a LUT update to avoid the
15273 * plane update forcing the pipe gamma on without
15274 * having a proper LUT loaded. Remove once we
15275 * have readout for pipe gamma enable.
15276 */
15277 crtc_state->color_mgmt_changed = true;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015278 }
15279 }
15280
15281 ret = drm_atomic_commit(state);
15282
15283out:
15284 if (ret == -EDEADLK) {
15285 drm_atomic_state_clear(state);
15286 drm_modeset_backoff(&ctx);
15287 goto retry;
15288 }
15289
15290 drm_atomic_state_put(state);
15291
15292 drm_modeset_drop_locks(&ctx);
15293 drm_modeset_acquire_fini(&ctx);
15294
15295 return ret;
15296}
15297
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015298int intel_modeset_init(struct drm_device *dev)
Jesse Barnes79e53942008-11-07 14:24:08 -080015299{
Joonas Lahtinen72e96d62016-03-30 16:57:10 +030015300 struct drm_i915_private *dev_priv = to_i915(dev);
15301 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Damien Lespiau8cc87b72014-03-03 17:31:44 +000015302 enum pipe pipe;
Jesse Barnes46f297f2014-03-07 08:57:48 -080015303 struct intel_crtc *crtc;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015304 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080015305
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015306 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15307
Jesse Barnes79e53942008-11-07 14:24:08 -080015308 drm_mode_config_init(dev);
15309
15310 dev->mode_config.min_width = 0;
15311 dev->mode_config.min_height = 0;
15312
Dave Airlie019d96c2011-09-29 16:20:42 +010015313 dev->mode_config.preferred_depth = 24;
15314 dev->mode_config.prefer_shadow = 1;
15315
Tvrtko Ursulin25bab382015-02-10 17:16:16 +000015316 dev->mode_config.allow_fb_modifiers = true;
15317
Laurent Pincharte6ecefa2012-05-17 13:27:23 +020015318 dev->mode_config.funcs = &intel_mode_funcs;
Jesse Barnes79e53942008-11-07 14:24:08 -080015319
Andrea Arcangeli400c19d2017-04-07 01:23:45 +020015320 init_llist_head(&dev_priv->atomic_helper.free_list);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015321 INIT_WORK(&dev_priv->atomic_helper.free_work,
Chris Wilsonba318c62017-02-02 20:47:41 +000015322 intel_atomic_helper_free_state_worker);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015323
Jani Nikula27a981b2018-10-17 12:35:39 +030015324 intel_init_quirks(dev_priv);
Jesse Barnesb690e962010-07-19 13:53:12 -070015325
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080015326 intel_fbc_init(dev_priv);
15327
Ville Syrjälä62d75df2016-10-31 22:37:25 +020015328 intel_init_pm(dev_priv);
Eugeni Dodonov1fa61102012-04-18 15:29:26 -030015329
Lukas Wunner69f92f62015-07-15 13:57:35 +020015330 /*
15331 * There may be no VBT; and if the BIOS enabled SSC we can
15332 * just keep using it to avoid unnecessary flicker. Whereas if the
15333 * BIOS isn't using it, don't assume it will work even if the VBT
15334 * indicates as much.
15335 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010015336 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Lukas Wunner69f92f62015-07-15 13:57:35 +020015337 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15338 DREF_SSC1_ENABLE);
15339
15340 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15341 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15342 bios_lvds_use_ssc ? "en" : "dis",
15343 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15344 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15345 }
15346 }
15347
Ville Syrjäläad77c532018-06-15 20:44:05 +030015348 /* maximum framebuffer dimensions */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015349 if (IS_GEN(dev_priv, 2)) {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015350 dev->mode_config.max_width = 2048;
15351 dev->mode_config.max_height = 2048;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015352 } else if (IS_GEN(dev_priv, 3)) {
Keith Packard5e4d6fa2009-07-12 23:53:17 -070015353 dev->mode_config.max_width = 4096;
15354 dev->mode_config.max_height = 4096;
Jesse Barnes79e53942008-11-07 14:24:08 -080015355 } else {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015356 dev->mode_config.max_width = 8192;
15357 dev->mode_config.max_height = 8192;
Jesse Barnes79e53942008-11-07 14:24:08 -080015358 }
Damien Lespiau068be562014-03-28 14:17:49 +000015359
Jani Nikula2a307c22016-11-30 17:43:04 +020015360 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15361 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
Ville Syrjälädc41c152014-08-13 11:57:05 +030015362 dev->mode_config.cursor_height = 1023;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015363 } else if (IS_GEN(dev_priv, 2)) {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015364 dev->mode_config.cursor_width = 64;
15365 dev->mode_config.cursor_height = 64;
Damien Lespiau068be562014-03-28 14:17:49 +000015366 } else {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015367 dev->mode_config.cursor_width = 256;
15368 dev->mode_config.cursor_height = 256;
Damien Lespiau068be562014-03-28 14:17:49 +000015369 }
15370
Matthew Auld73ebd502017-12-11 15:18:20 +000015371 dev->mode_config.fb_base = ggtt->gmadr.start;
Jesse Barnes79e53942008-11-07 14:24:08 -080015372
Zhao Yakui28c97732009-10-09 11:39:41 +080015373 DRM_DEBUG_KMS("%d display pipe%s available.\n",
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000015374 INTEL_INFO(dev_priv)->num_pipes,
15375 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
Jesse Barnes79e53942008-11-07 14:24:08 -080015376
Damien Lespiau055e3932014-08-18 13:49:10 +010015377 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020015378 ret = intel_crtc_init(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015379 if (ret) {
15380 drm_mode_config_cleanup(dev);
15381 return ret;
15382 }
Jesse Barnes79e53942008-11-07 14:24:08 -080015383 }
15384
Daniel Vettere72f9fb2013-06-05 13:34:06 +020015385 intel_shared_dpll_init(dev);
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015386 intel_update_fdi_pll_freq(dev_priv);
Jesse Barnesee7b9f92012-04-20 17:11:53 +010015387
Ville Syrjälä5be6e332017-02-20 16:04:43 +020015388 intel_update_czclk(dev_priv);
15389 intel_modeset_init_hw(dev);
15390
Ville Syrjäläb2045352016-05-13 23:41:27 +030015391 if (dev_priv->max_cdclk_freq == 0)
Ville Syrjälä4c75b942016-10-31 22:37:12 +020015392 intel_update_max_cdclk(dev_priv);
Ville Syrjäläb2045352016-05-13 23:41:27 +030015393
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015394 /* Just disable it once at startup */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015395 i915_disable_vga(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020015396 intel_setup_outputs(dev_priv);
Chris Wilson11be49e2012-11-15 11:32:20 +000015397
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015398 drm_modeset_lock_all(dev);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015399 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015400 drm_modeset_unlock_all(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015401
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015402 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015403 struct intel_initial_plane_config plane_config = {};
15404
Jesse Barnes46f297f2014-03-07 08:57:48 -080015405 if (!crtc->active)
15406 continue;
15407
Jesse Barnes46f297f2014-03-07 08:57:48 -080015408 /*
Jesse Barnes46f297f2014-03-07 08:57:48 -080015409 * Note that reserving the BIOS fb up front prevents us
15410 * from stuffing other stolen allocations like the ring
15411 * on top. This prevents some ugliness at boot time, and
15412 * can even allow for smooth boot transitions if the BIOS
15413 * fb is large enough for the active pipe configuration.
15414 */
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015415 dev_priv->display.get_initial_plane_config(crtc,
15416 &plane_config);
15417
15418 /*
15419 * If the fb is shared between multiple heads, we'll
15420 * just get the first one.
15421 */
15422 intel_find_initial_plane_obj(crtc, &plane_config);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015423 }
Matt Roperd93c0372015-12-03 11:37:41 -080015424
15425 /*
15426 * Make sure hardware watermarks really match the state we read out.
15427 * Note that we need to do this after reconstructing the BIOS fb's
15428 * since the watermark calculation done here will use pstate->fb.
15429 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080015430 if (!HAS_GMCH(dev_priv))
Ville Syrjälä602ae832017-03-02 19:15:02 +020015431 sanitize_watermarks(dev);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015432
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015433 /*
15434 * Force all active planes to recompute their states. So that on
15435 * mode_setcrtc after probe, all the intel_plane_state variables
15436 * are already calculated and there is no assert_plane warnings
15437 * during bootup.
15438 */
15439 ret = intel_initial_commit(dev);
15440 if (ret)
15441 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15442
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015443 return 0;
Chris Wilson2c7111d2011-03-29 10:40:27 +010015444}
Jesse Barnesd5bb0812011-01-05 12:01:26 -080015445
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015446void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15447{
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015448 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015449 /* 640x480@60Hz, ~25175 kHz */
15450 struct dpll clock = {
15451 .m1 = 18,
15452 .m2 = 7,
15453 .p1 = 13,
15454 .p2 = 4,
15455 .n = 2,
15456 };
15457 u32 dpll, fp;
15458 int i;
15459
15460 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15461
15462 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15463 pipe_name(pipe), clock.vco, clock.dot);
15464
15465 fp = i9xx_dpll_compute_fp(&clock);
15466 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15467 DPLL_VGA_MODE_DIS |
15468 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15469 PLL_P2_DIVIDE_BY_4 |
15470 PLL_REF_INPUT_DREFCLK |
15471 DPLL_VCO_ENABLE;
15472
15473 I915_WRITE(FP0(pipe), fp);
15474 I915_WRITE(FP1(pipe), fp);
15475
15476 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15477 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15478 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15479 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15480 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15481 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15482 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15483
15484 /*
15485 * Apparently we need to have VGA mode enabled prior to changing
15486 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15487 * dividers, even though the register value does change.
15488 */
15489 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15490 I915_WRITE(DPLL(pipe), dpll);
15491
15492 /* Wait for the clocks to stabilize. */
15493 POSTING_READ(DPLL(pipe));
15494 udelay(150);
15495
15496 /* The pixel multiplier can only be updated once the
15497 * DPLL is enabled and the clocks are stable.
15498 *
15499 * So write it again.
15500 */
15501 I915_WRITE(DPLL(pipe), dpll);
15502
15503 /* We do this three times for luck */
15504 for (i = 0; i < 3 ; i++) {
15505 I915_WRITE(DPLL(pipe), dpll);
15506 POSTING_READ(DPLL(pipe));
15507 udelay(150); /* wait for warmup */
15508 }
15509
15510 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15511 POSTING_READ(PIPECONF(pipe));
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015512
15513 intel_wait_for_pipe_scanline_moving(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015514}
15515
15516void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15517{
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015518 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15519
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015520 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15521 pipe_name(pipe));
15522
Ville Syrjälä5816d9c2017-11-29 14:54:11 +020015523 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15524 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15525 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020015526 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15527 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015528
15529 I915_WRITE(PIPECONF(pipe), 0);
15530 POSTING_READ(PIPECONF(pipe));
15531
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015532 intel_wait_for_pipe_scanline_stopped(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015533
15534 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15535 POSTING_READ(DPLL(pipe));
15536}
15537
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015538static void
15539intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15540{
15541 struct intel_crtc *crtc;
Daniel Vetterfa555832012-10-10 23:14:00 +020015542
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015543 if (INTEL_GEN(dev_priv) >= 4)
15544 return;
Daniel Vetterfa555832012-10-10 23:14:00 +020015545
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015546 for_each_intel_crtc(&dev_priv->drm, crtc) {
15547 struct intel_plane *plane =
15548 to_intel_plane(crtc->base.primary);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015549 struct intel_crtc *plane_crtc;
15550 enum pipe pipe;
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015551
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015552 if (!plane->get_hw_state(plane, &pipe))
15553 continue;
15554
15555 if (pipe == crtc->pipe)
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015556 continue;
15557
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015558 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15559 plane->base.base.id, plane->base.name);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015560
15561 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15562 intel_plane_disable_noatomic(plane_crtc, plane);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015563 }
Daniel Vetterfa555832012-10-10 23:14:00 +020015564}
15565
Ville Syrjälä02e93c32015-08-26 19:39:19 +030015566static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15567{
15568 struct drm_device *dev = crtc->base.dev;
15569 struct intel_encoder *encoder;
15570
15571 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15572 return true;
15573
15574 return false;
15575}
15576
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015577static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15578{
15579 struct drm_device *dev = encoder->base.dev;
15580 struct intel_connector *connector;
15581
15582 for_each_connector_on_encoder(dev, &encoder->base, connector)
15583 return connector;
15584
15585 return NULL;
15586}
15587
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015588static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015589 enum pipe pch_transcoder)
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015590{
15591 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015592 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015593}
15594
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015595static void intel_sanitize_crtc(struct intel_crtc *crtc,
15596 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter24929352012-07-02 20:28:59 +020015597{
15598 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010015599 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015600 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15601 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter24929352012-07-02 20:28:59 +020015602
Daniel Vetter24929352012-07-02 20:28:59 +020015603 /* Clear any frame start delays used for debugging left by the BIOS */
Ville Syrjälä738a8142017-11-15 22:04:42 +020015604 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
Jani Nikula4d1de972016-03-18 17:05:42 +020015605 i915_reg_t reg = PIPECONF(cpu_transcoder);
15606
15607 I915_WRITE(reg,
15608 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15609 }
Daniel Vetter24929352012-07-02 20:28:59 +020015610
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015611 if (crtc_state->base.active) {
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015612 struct intel_plane *plane;
15613
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015614 /* Disable everything but the primary plane */
15615 for_each_intel_plane_on_crtc(dev, crtc, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015616 const struct intel_plane_state *plane_state =
15617 to_intel_plane_state(plane->base.state);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015618
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015619 if (plane_state->base.visible &&
15620 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15621 intel_plane_disable_noatomic(crtc, plane);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015622 }
Matt Roperc0550302019-01-30 10:51:20 -080015623
15624 /*
15625 * Disable any background color set by the BIOS, but enable the
15626 * gamma and CSC to match how we program our planes.
15627 */
15628 if (INTEL_GEN(dev_priv) >= 9)
15629 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
15630 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
15631 SKL_BOTTOM_COLOR_CSC_ENABLE);
Daniel Vetter96256042015-02-13 21:03:42 +010015632 }
Ville Syrjäläd3eaf882014-05-20 17:20:05 +030015633
Daniel Vetter24929352012-07-02 20:28:59 +020015634 /* Adjust the state of the output pipe according to whether we
15635 * have active connectors/encoders. */
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015636 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
Ville Syrjäläda1d0e22017-06-01 17:36:14 +030015637 intel_crtc_disable_noatomic(&crtc->base, ctx);
Daniel Vetter24929352012-07-02 20:28:59 +020015638
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080015639 if (crtc_state->base.active || HAS_GMCH(dev_priv)) {
Daniel Vetter4cc31482014-03-24 00:01:41 +010015640 /*
15641 * We start out with underrun reporting disabled to avoid races.
15642 * For correct bookkeeping mark this on active crtcs.
15643 *
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +020015644 * Also on gmch platforms we dont have any hardware bits to
15645 * disable the underrun reporting. Which means we need to start
15646 * out with underrun reporting disabled also on inactive pipes,
15647 * since otherwise we'll complain about the garbage we read when
15648 * e.g. coming up after runtime pm.
15649 *
Daniel Vetter4cc31482014-03-24 00:01:41 +010015650 * No protection against concurrent access is required - at
15651 * worst a fifo underrun happens which also sets this to false.
15652 */
15653 crtc->cpu_fifo_underrun_disabled = true;
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015654 /*
15655 * We track the PCH trancoder underrun reporting state
15656 * within the crtc. With crtc for pipe A housing the underrun
15657 * reporting state for PCH transcoder A, crtc for pipe B housing
15658 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15659 * and marking underrun reporting as disabled for the non-existing
15660 * PCH transcoders B and C would prevent enabling the south
15661 * error interrupt (see cpt_can_enable_serr_int()).
15662 */
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015663 if (has_pch_trancoder(dev_priv, crtc->pipe))
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015664 crtc->pch_fifo_underrun_disabled = true;
Daniel Vetter4cc31482014-03-24 00:01:41 +010015665 }
Daniel Vetter24929352012-07-02 20:28:59 +020015666}
15667
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015668static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
15669{
15670 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
15671
15672 /*
15673 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
15674 * the hardware when a high res displays plugged in. DPLL P
15675 * divider is zero, and the pipe timings are bonkers. We'll
15676 * try to disable everything in that case.
15677 *
15678 * FIXME would be nice to be able to sanitize this state
15679 * without several WARNs, but for now let's take the easy
15680 * road.
15681 */
15682 return IS_GEN(dev_priv, 6) &&
15683 crtc_state->base.active &&
15684 crtc_state->shared_dpll &&
15685 crtc_state->port_clock == 0;
15686}
15687
Daniel Vetter24929352012-07-02 20:28:59 +020015688static void intel_sanitize_encoder(struct intel_encoder *encoder)
15689{
Imre Deak70332ac2018-11-01 16:04:27 +020015690 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015691 struct intel_connector *connector;
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015692 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
15693 struct intel_crtc_state *crtc_state = crtc ?
15694 to_intel_crtc_state(crtc->base.state) : NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015695
15696 /* We need to check both for a crtc link (meaning that the
15697 * encoder is active and trying to read from a pipe) and the
15698 * pipe itself being active. */
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015699 bool has_active_crtc = crtc_state &&
15700 crtc_state->base.active;
15701
15702 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
15703 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
15704 pipe_name(crtc->pipe));
15705 has_active_crtc = false;
15706 }
Daniel Vetter24929352012-07-02 20:28:59 +020015707
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015708 connector = intel_encoder_find_connector(encoder);
15709 if (connector && !has_active_crtc) {
Daniel Vetter24929352012-07-02 20:28:59 +020015710 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15711 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015712 encoder->base.name);
Daniel Vetter24929352012-07-02 20:28:59 +020015713
15714 /* Connector is active, but has no active pipe. This is
15715 * fallout from our resume register restoring. Disable
15716 * the encoder manually again. */
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015717 if (crtc_state) {
15718 struct drm_encoder *best_encoder;
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015719
Daniel Vetter24929352012-07-02 20:28:59 +020015720 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15721 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015722 encoder->base.name);
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015723
15724 /* avoid oopsing in case the hooks consult best_encoder */
15725 best_encoder = connector->base.state->best_encoder;
15726 connector->base.state->best_encoder = &encoder->base;
15727
Jani Nikulac84c6fe2018-10-16 15:41:34 +030015728 if (encoder->disable)
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015729 encoder->disable(encoder, crtc_state,
15730 connector->base.state);
Ville Syrjäläa62d1492014-06-28 02:04:01 +030015731 if (encoder->post_disable)
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015732 encoder->post_disable(encoder, crtc_state,
15733 connector->base.state);
15734
15735 connector->base.state->best_encoder = best_encoder;
Daniel Vetter24929352012-07-02 20:28:59 +020015736 }
Egbert Eich7f1950f2014-04-25 10:56:22 +020015737 encoder->base.crtc = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015738
15739 /* Inconsistent output/port/pipe state happens presumably due to
15740 * a bug in one of the get_hw_state functions. Or someplace else
15741 * in our code, like the register restore mess on resume. Clamp
15742 * things to off as a safer default. */
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015743
15744 connector->base.dpms = DRM_MODE_DPMS_OFF;
15745 connector->base.encoder = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015746 }
Maarten Lankhorstd6cae4a2018-05-16 10:50:38 +020015747
15748 /* notify opregion of the sanitized encoder state */
15749 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
Imre Deak70332ac2018-11-01 16:04:27 +020015750
15751 if (INTEL_GEN(dev_priv) >= 11)
15752 icl_sanitize_encoder_pll_mapping(encoder);
Daniel Vetter24929352012-07-02 20:28:59 +020015753}
15754
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015755void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015756{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010015757 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015758
Imre Deak04098752014-02-18 00:02:16 +020015759 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15760 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015761 i915_disable_vga(dev_priv);
Imre Deak04098752014-02-18 00:02:16 +020015762 }
15763}
15764
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015765void i915_redisable_vga(struct drm_i915_private *dev_priv)
Imre Deak04098752014-02-18 00:02:16 +020015766{
Chris Wilson0e6e0be2019-01-14 14:21:24 +000015767 intel_wakeref_t wakeref;
15768
15769 /*
15770 * This function can be called both from intel_modeset_setup_hw_state or
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015771 * at a very early point in our resume sequence, where the power well
15772 * structures are not yet restored. Since this function is at a very
15773 * paranoid "someone might have enabled VGA while we were not looking"
15774 * level, just check if the power well is enabled instead of trying to
15775 * follow the "don't touch the power well if we don't need it" policy
Chris Wilson0e6e0be2019-01-14 14:21:24 +000015776 * the rest of the driver uses.
15777 */
15778 wakeref = intel_display_power_get_if_enabled(dev_priv,
15779 POWER_DOMAIN_VGA);
15780 if (!wakeref)
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015781 return;
15782
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015783 i915_redisable_vga_power_on(dev_priv);
Imre Deak6392f842016-02-12 18:55:13 +020015784
Chris Wilson0e6e0be2019-01-14 14:21:24 +000015785 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015786}
15787
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015788/* FIXME read out full plane state for all planes */
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015789static void readout_plane_state(struct drm_i915_private *dev_priv)
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015790{
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015791 struct intel_plane *plane;
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015792 struct intel_crtc *crtc;
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015793
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015794 for_each_intel_plane(&dev_priv->drm, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015795 struct intel_plane_state *plane_state =
15796 to_intel_plane_state(plane->base.state);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015797 struct intel_crtc_state *crtc_state;
15798 enum pipe pipe = PIPE_A;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020015799 bool visible;
15800
15801 visible = plane->get_hw_state(plane, &pipe);
Maarten Lankhorstb26d3ea2015-09-23 16:11:41 +020015802
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015803 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15804 crtc_state = to_intel_crtc_state(crtc->base.state);
15805
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015806 intel_set_plane_visible(crtc_state, plane_state, visible);
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015807
15808 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15809 plane->base.base.id, plane->base.name,
15810 enableddisabled(visible), pipe_name(pipe));
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015811 }
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015812
15813 for_each_intel_crtc(&dev_priv->drm, crtc) {
15814 struct intel_crtc_state *crtc_state =
15815 to_intel_crtc_state(crtc->base.state);
15816
15817 fixup_active_planes(crtc_state);
15818 }
Ville Syrjälä98ec7732014-04-30 17:43:01 +030015819}
15820
Daniel Vetter30e984d2013-06-05 13:34:17 +020015821static void intel_modeset_readout_hw_state(struct drm_device *dev)
Daniel Vetter24929352012-07-02 20:28:59 +020015822{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015823 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015824 enum pipe pipe;
Daniel Vetter24929352012-07-02 20:28:59 +020015825 struct intel_crtc *crtc;
15826 struct intel_encoder *encoder;
15827 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015828 struct drm_connector_list_iter conn_iter;
Daniel Vetter53589012013-06-05 13:34:16 +020015829 int i;
Daniel Vetter24929352012-07-02 20:28:59 +020015830
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015831 dev_priv->active_crtcs = 0;
15832
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015833 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015834 struct intel_crtc_state *crtc_state =
15835 to_intel_crtc_state(crtc->base.state);
Daniel Vetter3b117c82013-04-17 20:15:07 +020015836
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020015837 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015838 memset(crtc_state, 0, sizeof(*crtc_state));
15839 crtc_state->base.crtc = &crtc->base;
Daniel Vetter24929352012-07-02 20:28:59 +020015840
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015841 crtc_state->base.active = crtc_state->base.enable =
15842 dev_priv->display.get_pipe_config(crtc, crtc_state);
15843
15844 crtc->base.enabled = crtc_state->base.enable;
15845 crtc->active = crtc_state->base.active;
15846
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015847 if (crtc_state->base.active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015848 dev_priv->active_crtcs |= 1 << crtc->pipe;
15849
Ville Syrjälä78108b72016-05-27 20:59:19 +030015850 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15851 crtc->base.base.id, crtc->base.name,
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015852 enableddisabled(crtc_state->base.active));
Daniel Vetter24929352012-07-02 20:28:59 +020015853 }
15854
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015855 readout_plane_state(dev_priv);
15856
Daniel Vetter53589012013-06-05 13:34:16 +020015857 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15858 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15859
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015860 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15861 &pll->state.hw_state);
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015862 pll->state.crtc_mask = 0;
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015863 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015864 struct intel_crtc_state *crtc_state =
15865 to_intel_crtc_state(crtc->base.state);
15866
15867 if (crtc_state->base.active &&
15868 crtc_state->shared_dpll == pll)
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015869 pll->state.crtc_mask |= 1 << crtc->pipe;
Daniel Vetter53589012013-06-05 13:34:16 +020015870 }
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015871 pll->active_mask = pll->state.crtc_mask;
Daniel Vetter53589012013-06-05 13:34:16 +020015872
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +020015873 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015874 pll->info->name, pll->state.crtc_mask, pll->on);
Daniel Vetter53589012013-06-05 13:34:16 +020015875 }
15876
Damien Lespiaub2784e12014-08-05 11:29:37 +010015877 for_each_intel_encoder(dev, encoder) {
Daniel Vetter24929352012-07-02 20:28:59 +020015878 pipe = 0;
15879
15880 if (encoder->get_hw_state(encoder, &pipe)) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015881 struct intel_crtc_state *crtc_state;
15882
Ville Syrjälä98187832016-10-31 22:37:10 +020015883 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015884 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015885
Jesse Barnes045ac3b2013-05-14 17:08:26 -070015886 encoder->base.crtc = &crtc->base;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015887 encoder->get_config(encoder, crtc_state);
Daniel Vetter24929352012-07-02 20:28:59 +020015888 } else {
15889 encoder->base.crtc = NULL;
15890 }
15891
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015892 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015893 encoder->base.base.id, encoder->base.name,
15894 enableddisabled(encoder->base.crtc),
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015895 pipe_name(pipe));
Daniel Vetter24929352012-07-02 20:28:59 +020015896 }
15897
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015898 drm_connector_list_iter_begin(dev, &conn_iter);
15899 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter24929352012-07-02 20:28:59 +020015900 if (connector->get_hw_state(connector)) {
15901 connector->base.dpms = DRM_MODE_DPMS_ON;
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015902
15903 encoder = connector->encoder;
15904 connector->base.encoder = &encoder->base;
15905
15906 if (encoder->base.crtc &&
15907 encoder->base.crtc->state->active) {
15908 /*
15909 * This has to be done during hardware readout
15910 * because anything calling .crtc_disable may
15911 * rely on the connector_mask being accurate.
15912 */
15913 encoder->base.crtc->state->connector_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015914 drm_connector_mask(&connector->base);
Maarten Lankhorste87a52b2016-01-28 15:04:58 +010015915 encoder->base.crtc->state->encoder_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015916 drm_encoder_mask(&encoder->base);
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015917 }
15918
Daniel Vetter24929352012-07-02 20:28:59 +020015919 } else {
15920 connector->base.dpms = DRM_MODE_DPMS_OFF;
15921 connector->base.encoder = NULL;
15922 }
15923 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015924 connector->base.base.id, connector->base.name,
15925 enableddisabled(connector->base.encoder));
Daniel Vetter24929352012-07-02 20:28:59 +020015926 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015927 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015928
15929 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015930 struct intel_crtc_state *crtc_state =
15931 to_intel_crtc_state(crtc->base.state);
Ville Syrjäläd305e062017-08-30 21:57:03 +030015932 int min_cdclk = 0;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015933
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015934 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015935 if (crtc_state->base.active) {
15936 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
Ville Syrjäläbd4cd032018-04-26 19:30:15 +030015937 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15938 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015939 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015940 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15941
15942 /*
15943 * The initial mode needs to be set in order to keep
15944 * the atomic core happy. It wants a valid mode if the
15945 * crtc's enabled, so we do the above call.
15946 *
Daniel Vetter7800fb62016-12-19 09:24:23 +010015947 * But we don't set all the derived state fully, hence
15948 * set a flag to indicate that a full recalculation is
15949 * needed on the next commit.
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015950 */
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015951 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
Ville Syrjälä9eca68322015-09-10 18:59:10 +030015952
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020015953 intel_crtc_compute_pixel_rate(crtc_state);
15954
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015955 if (dev_priv->display.modeset_calc_cdclk) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030015956 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015957 if (WARN_ON(min_cdclk < 0))
15958 min_cdclk = 0;
15959 }
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015960
Daniel Vetter5caa0fe2017-05-09 16:03:29 +020015961 drm_calc_timestamping_constants(&crtc->base,
15962 &crtc_state->base.adjusted_mode);
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020015963 update_scanline_offset(crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015964 }
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020015965
Ville Syrjäläd305e062017-08-30 21:57:03 +030015966 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030015967 dev_priv->min_voltage_level[crtc->pipe] =
15968 crtc_state->min_voltage_level;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015969
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015970 intel_pipe_config_sanity_check(dev_priv, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015971 }
Daniel Vetter30e984d2013-06-05 13:34:17 +020015972}
15973
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015974static void
15975get_encoder_power_domains(struct drm_i915_private *dev_priv)
15976{
15977 struct intel_encoder *encoder;
15978
15979 for_each_intel_encoder(&dev_priv->drm, encoder) {
15980 u64 get_domains;
15981 enum intel_display_power_domain domain;
Imre Deak52528052018-06-21 21:44:49 +030015982 struct intel_crtc_state *crtc_state;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015983
15984 if (!encoder->get_power_domains)
15985 continue;
15986
Imre Deak52528052018-06-21 21:44:49 +030015987 /*
Imre Deakb79ebe72018-07-05 15:26:54 +030015988 * MST-primary and inactive encoders don't have a crtc state
15989 * and neither of these require any power domain references.
Imre Deak52528052018-06-21 21:44:49 +030015990 */
Imre Deakb79ebe72018-07-05 15:26:54 +030015991 if (!encoder->base.crtc)
15992 continue;
Imre Deak52528052018-06-21 21:44:49 +030015993
Imre Deakb79ebe72018-07-05 15:26:54 +030015994 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
Imre Deak52528052018-06-21 21:44:49 +030015995 get_domains = encoder->get_power_domains(encoder, crtc_state);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015996 for_each_power_domain(domain, get_domains)
15997 intel_display_power_get(dev_priv, domain);
15998 }
15999}
16000
Rodrigo Vividf49ec82017-11-10 16:03:19 -080016001static void intel_early_display_was(struct drm_i915_private *dev_priv)
16002{
16003 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
16004 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
16005 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
16006 DARBF_GATING_DIS);
16007
16008 if (IS_HASWELL(dev_priv)) {
16009 /*
16010 * WaRsPkgCStateDisplayPMReq:hsw
16011 * System hang if this isn't done before disabling all planes!
16012 */
16013 I915_WRITE(CHICKEN_PAR1_1,
16014 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
16015 }
16016}
16017
Ville Syrjälä3aefb672018-11-08 16:36:35 +020016018static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
16019 enum port port, i915_reg_t hdmi_reg)
16020{
16021 u32 val = I915_READ(hdmi_reg);
16022
16023 if (val & SDVO_ENABLE ||
16024 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
16025 return;
16026
16027 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
16028 port_name(port));
16029
16030 val &= ~SDVO_PIPE_SEL_MASK;
16031 val |= SDVO_PIPE_SEL(PIPE_A);
16032
16033 I915_WRITE(hdmi_reg, val);
16034}
16035
16036static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
16037 enum port port, i915_reg_t dp_reg)
16038{
16039 u32 val = I915_READ(dp_reg);
16040
16041 if (val & DP_PORT_EN ||
16042 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
16043 return;
16044
16045 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
16046 port_name(port));
16047
16048 val &= ~DP_PIPE_SEL_MASK;
16049 val |= DP_PIPE_SEL(PIPE_A);
16050
16051 I915_WRITE(dp_reg, val);
16052}
16053
16054static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
16055{
16056 /*
16057 * The BIOS may select transcoder B on some of the PCH
16058 * ports even it doesn't enable the port. This would trip
16059 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
16060 * Sanitize the transcoder select bits to prevent that. We
16061 * assume that the BIOS never actually enabled the port,
16062 * because if it did we'd actually have to toggle the port
16063 * on and back off to make the transcoder A select stick
16064 * (see. intel_dp_link_down(), intel_disable_hdmi(),
16065 * intel_disable_sdvo()).
16066 */
16067 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
16068 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
16069 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
16070
16071 /* PCH SDVOB multiplex with HDMIB */
16072 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
16073 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
16074 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
16075}
16076
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016077/* Scan out the current hw modeset state,
16078 * and sanitizes it to the current state
16079 */
16080static void
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030016081intel_modeset_setup_hw_state(struct drm_device *dev,
16082 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter30e984d2013-06-05 13:34:17 +020016083{
Chris Wilsonfac5e232016-07-04 11:34:36 +010016084 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst91d78192018-10-11 12:04:54 +020016085 struct intel_crtc_state *crtc_state;
Daniel Vetter30e984d2013-06-05 13:34:17 +020016086 struct intel_encoder *encoder;
Chris Wilson0e6e0be2019-01-14 14:21:24 +000016087 struct intel_crtc *crtc;
16088 intel_wakeref_t wakeref;
Daniel Vetter35c95372013-07-17 06:55:04 +020016089 int i;
Daniel Vetter30e984d2013-06-05 13:34:17 +020016090
Chris Wilson0e6e0be2019-01-14 14:21:24 +000016091 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2cd9a682018-08-16 15:37:57 +030016092
Rodrigo Vividf49ec82017-11-10 16:03:19 -080016093 intel_early_display_was(dev_priv);
Daniel Vetter30e984d2013-06-05 13:34:17 +020016094 intel_modeset_readout_hw_state(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020016095
16096 /* HW state is read out, now we need to sanitize this mess. */
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020016097 get_encoder_power_domains(dev_priv);
16098
Ville Syrjälä3aefb672018-11-08 16:36:35 +020016099 if (HAS_PCH_IBX(dev_priv))
16100 ibx_sanitize_pch_ports(dev_priv);
16101
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030016102 /*
16103 * intel_sanitize_plane_mapping() may need to do vblank
16104 * waits, so we need vblank interrupts restored beforehand.
16105 */
16106 for_each_intel_crtc(&dev_priv->drm, crtc) {
Ville Syrjälä32db0b62018-11-27 22:05:50 +020016107 crtc_state = to_intel_crtc_state(crtc->base.state);
16108
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030016109 drm_crtc_vblank_reset(&crtc->base);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020016110
Ville Syrjälä32db0b62018-11-27 22:05:50 +020016111 if (crtc_state->base.active)
16112 intel_crtc_vblank_on(crtc_state);
Daniel Vetter24929352012-07-02 20:28:59 +020016113 }
16114
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030016115 intel_sanitize_plane_mapping(dev_priv);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020016116
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030016117 for_each_intel_encoder(dev, encoder)
16118 intel_sanitize_encoder(encoder);
16119
16120 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst91d78192018-10-11 12:04:54 +020016121 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030016122 intel_sanitize_crtc(crtc, ctx);
Maarten Lankhorst91d78192018-10-11 12:04:54 +020016123 intel_dump_pipe_config(crtc, crtc_state,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +020016124 "[setup_hw_state]");
Daniel Vetter24929352012-07-02 20:28:59 +020016125 }
Daniel Vetter9a935852012-07-05 22:34:27 +020016126
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020016127 intel_modeset_update_connector_atomic_state(dev);
16128
Daniel Vetter35c95372013-07-17 06:55:04 +020016129 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16130 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16131
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +010016132 if (!pll->on || pll->active_mask)
Daniel Vetter35c95372013-07-17 06:55:04 +020016133 continue;
16134
Lucas De Marchi72f775f2018-03-20 15:06:34 -070016135 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
16136 pll->info->name);
Daniel Vetter35c95372013-07-17 06:55:04 +020016137
Lucas De Marchiee1398b2018-03-20 15:06:33 -070016138 pll->info->funcs->disable(dev_priv, pll);
Daniel Vetter35c95372013-07-17 06:55:04 +020016139 pll->on = false;
16140 }
16141
Ville Syrjälä04548cb2017-04-21 21:14:29 +030016142 if (IS_G4X(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080016143 g4x_wm_get_hw_state(dev_priv);
Ville Syrjälä04548cb2017-04-21 21:14:29 +030016144 g4x_wm_sanitize(dev_priv);
16145 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080016146 vlv_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020016147 vlv_wm_sanitize(dev_priv);
Rodrigo Vivia029fa42017-08-09 13:52:48 -070016148 } else if (INTEL_GEN(dev_priv) >= 9) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080016149 skl_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020016150 } else if (HAS_PCH_SPLIT(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080016151 ilk_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020016152 }
Maarten Lankhorst292b9902015-07-13 16:30:27 +020016153
16154 for_each_intel_crtc(dev, crtc) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020016155 u64 put_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +020016156
Maarten Lankhorst91d78192018-10-11 12:04:54 +020016157 crtc_state = to_intel_crtc_state(crtc->base.state);
16158 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +020016159 if (WARN_ON(put_domains))
16160 modeset_put_power_domains(dev_priv, put_domains);
16161 }
Imre Deak2cd9a682018-08-16 15:37:57 +030016162
Chris Wilson0e6e0be2019-01-14 14:21:24 +000016163 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
Paulo Zanoni010cf732016-01-19 11:35:48 -020016164
16165 intel_fbc_init_pipe_state(dev_priv);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016166}
Ville Syrjälä7d0bc1e2013-09-16 17:38:33 +030016167
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016168void intel_display_resume(struct drm_device *dev)
16169{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016170 struct drm_i915_private *dev_priv = to_i915(dev);
16171 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
16172 struct drm_modeset_acquire_ctx ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016173 int ret;
Daniel Vetterf30da182013-04-11 20:22:50 +020016174
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016175 dev_priv->modeset_restore_state = NULL;
Maarten Lankhorst73974892016-08-05 23:28:27 +030016176 if (state)
16177 state->acquire_ctx = &ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016178
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016179 drm_modeset_acquire_init(&ctx, 0);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016180
Maarten Lankhorst73974892016-08-05 23:28:27 +030016181 while (1) {
16182 ret = drm_modeset_lock_all_ctx(dev, &ctx);
16183 if (ret != -EDEADLK)
16184 break;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016185
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016186 drm_modeset_backoff(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016187 }
16188
Maarten Lankhorst73974892016-08-05 23:28:27 +030016189 if (!ret)
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010016190 ret = __intel_display_resume(dev, state, &ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +030016191
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +053016192 intel_enable_ipc(dev_priv);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016193 drm_modeset_drop_locks(&ctx);
16194 drm_modeset_acquire_fini(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016195
Chris Wilson08536952016-10-14 13:18:18 +010016196 if (ret)
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016197 DRM_ERROR("Restoring old state failed with %i\n", ret);
Chris Wilson3c5e37f2017-01-15 12:58:25 +000016198 if (state)
16199 drm_atomic_state_put(state);
Chris Wilson2c7111d2011-03-29 10:40:27 +010016200}
16201
Manasi Navare886c6b82017-10-26 14:52:00 -070016202static void intel_hpd_poll_fini(struct drm_device *dev)
16203{
16204 struct intel_connector *connector;
16205 struct drm_connector_list_iter conn_iter;
16206
Chris Wilson448aa912017-11-28 11:01:47 +000016207 /* Kill all the work that may have been queued by hpd. */
Manasi Navare886c6b82017-10-26 14:52:00 -070016208 drm_connector_list_iter_begin(dev, &conn_iter);
16209 for_each_intel_connector_iter(connector, &conn_iter) {
16210 if (connector->modeset_retry_work.func)
16211 cancel_work_sync(&connector->modeset_retry_work);
Ramalingam Cd3dacc72018-10-29 15:15:46 +053016212 if (connector->hdcp.shim) {
16213 cancel_delayed_work_sync(&connector->hdcp.check_work);
16214 cancel_work_sync(&connector->hdcp.prop_work);
Sean Paulee5e5e72018-01-08 14:55:39 -050016215 }
Manasi Navare886c6b82017-10-26 14:52:00 -070016216 }
16217 drm_connector_list_iter_end(&conn_iter);
16218}
16219
Jesse Barnes79e53942008-11-07 14:24:08 -080016220void intel_modeset_cleanup(struct drm_device *dev)
16221{
Chris Wilsonfac5e232016-07-04 11:34:36 +010016222 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes652c3932009-08-17 13:31:43 -070016223
Chris Wilson8bcf9f72018-07-10 10:44:20 +010016224 flush_workqueue(dev_priv->modeset_wq);
16225
Chris Wilsoneb955ee2017-01-23 21:29:39 +000016226 flush_work(&dev_priv->atomic_helper.free_work);
16227 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
16228
Daniel Vetterfd0c0642013-04-24 11:13:35 +020016229 /*
16230 * Interrupts and polling as the first thing to avoid creating havoc.
Imre Deak2eb52522014-11-19 15:30:05 +020016231 * Too much stuff here (turning of connectors, ...) would
Daniel Vetterfd0c0642013-04-24 11:13:35 +020016232 * experience fancy races otherwise.
16233 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +020016234 intel_irq_uninstall(dev_priv);
Jesse Barneseb21b922014-06-20 11:57:33 -070016235
Daniel Vetterfd0c0642013-04-24 11:13:35 +020016236 /*
16237 * Due to the hpd irq storm handling the hotplug work can re-arm the
16238 * poll handlers. Hence disable polling after hpd handling is shut down.
16239 */
Manasi Navare886c6b82017-10-26 14:52:00 -070016240 intel_hpd_poll_fini(dev);
Daniel Vetterfd0c0642013-04-24 11:13:35 +020016241
Daniel Vetter4f256d82017-07-15 00:46:55 +020016242 /* poll work can call into fbdev, hence clean that up afterwards */
16243 intel_fbdev_fini(dev_priv);
16244
Jesse Barnes723bfd72010-10-07 16:01:13 -070016245 intel_unregister_dsm_handler();
16246
Paulo Zanonic937ab3e52016-01-19 11:35:46 -020016247 intel_fbc_global_disable(dev_priv);
Kristian Høgsberg69341a52009-11-11 12:19:17 -050016248
Chris Wilson1630fe72011-07-08 12:22:42 +010016249 /* flush any delayed tasks or pending work */
16250 flush_scheduled_work();
16251
Jesse Barnes79e53942008-11-07 14:24:08 -080016252 drm_mode_config_cleanup(dev);
Daniel Vetter4d7bb012012-12-18 15:24:37 +010016253
José Roberto de Souza58db08a72018-11-07 16:16:47 -080016254 intel_overlay_cleanup(dev_priv);
Imre Deakae484342014-03-31 15:10:44 +030016255
Tvrtko Ursulin40196442016-12-01 14:16:42 +000016256 intel_teardown_gmbus(dev_priv);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020016257
16258 destroy_workqueue(dev_priv->modeset_wq);
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080016259
16260 intel_fbc_cleanup_cfb(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080016261}
16262
Dave Airlie28d52042009-09-21 14:33:58 +100016263/*
16264 * set vga decode state - true == enable VGA decode
16265 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000016266int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
Dave Airlie28d52042009-09-21 14:33:58 +100016267{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000016268 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
Dave Airlie28d52042009-09-21 14:33:58 +100016269 u16 gmch_ctrl;
16270
Chris Wilson75fa0412014-02-07 18:37:02 -020016271 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
16272 DRM_ERROR("failed to read control word\n");
16273 return -EIO;
16274 }
16275
Chris Wilsonc0cc8a52014-02-07 18:37:03 -020016276 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
16277 return 0;
16278
Dave Airlie28d52042009-09-21 14:33:58 +100016279 if (state)
16280 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
16281 else
16282 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
Chris Wilson75fa0412014-02-07 18:37:02 -020016283
16284 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
16285 DRM_ERROR("failed to write control word\n");
16286 return -EIO;
16287 }
16288
Dave Airlie28d52042009-09-21 14:33:58 +100016289 return 0;
16290}
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016291
Chris Wilson98a2f412016-10-12 10:05:18 +010016292#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
16293
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016294struct intel_display_error_state {
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016295
16296 u32 power_well_driver;
16297
Chris Wilson63b66e52013-08-08 15:12:06 +020016298 int num_transcoders;
16299
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016300 struct intel_cursor_error_state {
16301 u32 control;
16302 u32 position;
16303 u32 base;
16304 u32 size;
Damien Lespiau52331302012-08-15 19:23:25 +010016305 } cursor[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016306
16307 struct intel_pipe_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016308 bool power_domain_on;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016309 u32 source;
Imre Deakf301b1e2014-04-18 15:55:04 +030016310 u32 stat;
Damien Lespiau52331302012-08-15 19:23:25 +010016311 } pipe[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016312
16313 struct intel_plane_error_state {
16314 u32 control;
16315 u32 stride;
16316 u32 size;
16317 u32 pos;
16318 u32 addr;
16319 u32 surface;
16320 u32 tile_offset;
Damien Lespiau52331302012-08-15 19:23:25 +010016321 } plane[I915_MAX_PIPES];
Chris Wilson63b66e52013-08-08 15:12:06 +020016322
16323 struct intel_transcoder_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016324 bool power_domain_on;
Chris Wilson63b66e52013-08-08 15:12:06 +020016325 enum transcoder cpu_transcoder;
16326
16327 u32 conf;
16328
16329 u32 htotal;
16330 u32 hblank;
16331 u32 hsync;
16332 u32 vtotal;
16333 u32 vblank;
16334 u32 vsync;
16335 } transcoder[4];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016336};
16337
16338struct intel_display_error_state *
Chris Wilsonc0336662016-05-06 15:40:21 +010016339intel_display_capture_error_state(struct drm_i915_private *dev_priv)
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016340{
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016341 struct intel_display_error_state *error;
Chris Wilson63b66e52013-08-08 15:12:06 +020016342 int transcoders[] = {
16343 TRANSCODER_A,
16344 TRANSCODER_B,
16345 TRANSCODER_C,
16346 TRANSCODER_EDP,
16347 };
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016348 int i;
16349
José Roberto de Souzae1bf0942018-11-30 15:20:47 -080016350 if (!HAS_DISPLAY(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016351 return NULL;
16352
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016353 error = kzalloc(sizeof(*error), GFP_ATOMIC);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016354 if (error == NULL)
16355 return NULL;
16356
Chris Wilsonc0336662016-05-06 15:40:21 +010016357 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Imre Deak75e39682018-08-06 12:58:39 +030016358 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016359
Damien Lespiau055e3932014-08-18 13:49:10 +010016360 for_each_pipe(dev_priv, i) {
Imre Deakddf9c532013-11-27 22:02:02 +020016361 error->pipe[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016362 __intel_display_power_is_enabled(dev_priv,
16363 POWER_DOMAIN_PIPE(i));
Imre Deakddf9c532013-11-27 22:02:02 +020016364 if (!error->pipe[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016365 continue;
16366
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030016367 error->cursor[i].control = I915_READ(CURCNTR(i));
16368 error->cursor[i].position = I915_READ(CURPOS(i));
16369 error->cursor[i].base = I915_READ(CURBASE(i));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016370
16371 error->plane[i].control = I915_READ(DSPCNTR(i));
16372 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016373 if (INTEL_GEN(dev_priv) <= 3) {
Paulo Zanoni51889b32013-03-06 20:03:13 -030016374 error->plane[i].size = I915_READ(DSPSIZE(i));
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016375 error->plane[i].pos = I915_READ(DSPPOS(i));
16376 }
Chris Wilsonc0336662016-05-06 15:40:21 +010016377 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Paulo Zanonica291362013-03-06 20:03:14 -030016378 error->plane[i].addr = I915_READ(DSPADDR(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016379 if (INTEL_GEN(dev_priv) >= 4) {
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016380 error->plane[i].surface = I915_READ(DSPSURF(i));
16381 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16382 }
16383
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016384 error->pipe[i].source = I915_READ(PIPESRC(i));
Imre Deakf301b1e2014-04-18 15:55:04 +030016385
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080016386 if (HAS_GMCH(dev_priv))
Imre Deakf301b1e2014-04-18 15:55:04 +030016387 error->pipe[i].stat = I915_READ(PIPESTAT(i));
Chris Wilson63b66e52013-08-08 15:12:06 +020016388 }
16389
Jani Nikula4d1de972016-03-18 17:05:42 +020016390 /* Note: this does not include DSI transcoders. */
Chris Wilsonc0336662016-05-06 15:40:21 +010016391 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +030016392 if (HAS_DDI(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016393 error->num_transcoders++; /* Account for eDP. */
16394
16395 for (i = 0; i < error->num_transcoders; i++) {
16396 enum transcoder cpu_transcoder = transcoders[i];
16397
Imre Deakddf9c532013-11-27 22:02:02 +020016398 error->transcoder[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016399 __intel_display_power_is_enabled(dev_priv,
Paulo Zanoni38cc1da2013-12-20 15:09:41 -020016400 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016401 if (!error->transcoder[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016402 continue;
16403
Chris Wilson63b66e52013-08-08 15:12:06 +020016404 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16405
16406 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16407 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16408 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16409 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16410 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16411 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16412 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016413 }
16414
16415 return error;
16416}
16417
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016418#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16419
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016420void
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016421intel_display_print_error_state(struct drm_i915_error_state_buf *m,
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016422 struct intel_display_error_state *error)
16423{
Chris Wilson5a4c6f12017-02-14 16:46:11 +000016424 struct drm_i915_private *dev_priv = m->i915;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016425 int i;
16426
Chris Wilson63b66e52013-08-08 15:12:06 +020016427 if (!error)
16428 return;
16429
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000016430 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
Tvrtko Ursulin86527442016-10-13 11:03:00 +010016431 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016432 err_printf(m, "PWR_WELL_CTL2: %08x\n",
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016433 error->power_well_driver);
Damien Lespiau055e3932014-08-18 13:49:10 +010016434 for_each_pipe(dev_priv, i) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016435 err_printf(m, "Pipe [%d]:\n", i);
Imre Deakddf9c532013-11-27 22:02:02 +020016436 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016437 onoff(error->pipe[i].power_domain_on));
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016438 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
Imre Deakf301b1e2014-04-18 15:55:04 +030016439 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016440
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016441 err_printf(m, "Plane [%d]:\n", i);
16442 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16443 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016444 if (INTEL_GEN(dev_priv) <= 3) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016445 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16446 err_printf(m, " POS: %08x\n", error->plane[i].pos);
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016447 }
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010016448 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016449 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016450 if (INTEL_GEN(dev_priv) >= 4) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016451 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16452 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016453 }
16454
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016455 err_printf(m, "Cursor [%d]:\n", i);
16456 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16457 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16458 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016459 }
Chris Wilson63b66e52013-08-08 15:12:06 +020016460
16461 for (i = 0; i < error->num_transcoders; i++) {
Jani Nikulada205632016-03-15 21:51:10 +020016462 err_printf(m, "CPU transcoder: %s\n",
Chris Wilson63b66e52013-08-08 15:12:06 +020016463 transcoder_name(error->transcoder[i].cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016464 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016465 onoff(error->transcoder[i].power_domain_on));
Chris Wilson63b66e52013-08-08 15:12:06 +020016466 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16467 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16468 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16469 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16470 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16471 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16472 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
16473 }
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016474}
Chris Wilson98a2f412016-10-12 10:05:18 +010016475
16476#endif