2 * Copyright © 2006-2007 Intel Corporation
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:
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
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.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/i2c.h>
28 #include <linux/input.h>
29 #include <linux/intel-iommu.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/dma-resv.h>
33 #include <linux/slab.h>
35 #include <drm/drm_atomic.h>
36 #include <drm/drm_atomic_helper.h>
37 #include <drm/drm_atomic_uapi.h>
38 #include <drm/drm_damage_helper.h>
39 #include <drm/drm_dp_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_fourcc.h>
42 #include <drm/drm_plane_helper.h>
43 #include <drm/drm_probe_helper.h>
44 #include <drm/drm_rect.h>
46 #include "display/intel_crt.h"
47 #include "display/intel_ddi.h"
48 #include "display/intel_display_debugfs.h"
49 #include "display/intel_dp.h"
50 #include "display/intel_dp_mst.h"
51 #include "display/intel_dpll_mgr.h"
52 #include "display/intel_dsi.h"
53 #include "display/intel_dvo.h"
54 #include "display/intel_gmbus.h"
55 #include "display/intel_hdmi.h"
56 #include "display/intel_lvds.h"
57 #include "display/intel_sdvo.h"
58 #include "display/intel_tv.h"
59 #include "display/intel_vdsc.h"
61 #include "gt/intel_rps.h"
64 #include "i915_trace.h"
65 #include "intel_acpi.h"
66 #include "intel_atomic.h"
67 #include "intel_atomic_plane.h"
69 #include "intel_cdclk.h"
70 #include "intel_color.h"
71 #include "intel_csr.h"
72 #include "intel_cursor.h"
73 #include "intel_display_types.h"
74 #include "intel_dp_link_training.h"
75 #include "intel_fbc.h"
76 #include "intel_fbdev.h"
77 #include "intel_fifo_underrun.h"
78 #include "intel_frontbuffer.h"
79 #include "intel_hdcp.h"
80 #include "intel_hotplug.h"
81 #include "intel_overlay.h"
82 #include "intel_pipe_crc.h"
84 #include "intel_psr.h"
85 #include "intel_quirks.h"
86 #include "intel_sideband.h"
87 #include "intel_sprite.h"
89 #include "intel_vga.h"
90 #include "i9xx_plane.h"
92 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
93 struct intel_crtc_state *pipe_config);
94 static void ilk_pch_clock_get(struct intel_crtc *crtc,
95 struct intel_crtc_state *pipe_config);
97 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
98 struct drm_i915_gem_object *obj,
99 struct drm_mode_fb_cmd2 *mode_cmd);
100 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
101 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
102 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
103 const struct intel_link_m_n *m_n,
104 const struct intel_link_m_n *m2_n2);
105 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
106 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state);
107 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state);
108 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
109 static void vlv_prepare_pll(struct intel_crtc *crtc,
110 const struct intel_crtc_state *pipe_config);
111 static void chv_prepare_pll(struct intel_crtc *crtc,
112 const struct intel_crtc_state *pipe_config);
113 static void skl_pfit_enable(const struct intel_crtc_state *crtc_state);
114 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state);
115 static void intel_modeset_setup_hw_state(struct drm_device *dev,
116 struct drm_modeset_acquire_ctx *ctx);
117 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc);
122 } dot, vco, n, m, m1, m2, p, p1;
126 int p2_slow, p2_fast;
130 /* returns HPLL frequency in kHz */
131 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
133 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
135 /* Obtain SKU information */
136 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
137 CCK_FUSE_HPLL_FREQ_MASK;
139 return vco_freq[hpll_freq] * 1000;
142 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
143 const char *name, u32 reg, int ref_freq)
148 val = vlv_cck_read(dev_priv, reg);
149 divider = val & CCK_FREQUENCY_VALUES;
151 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
152 (divider << CCK_FREQUENCY_STATUS_SHIFT),
153 "%s change in progress\n", name);
155 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
158 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
159 const char *name, u32 reg)
163 vlv_cck_get(dev_priv);
165 if (dev_priv->hpll_freq == 0)
166 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
168 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
170 vlv_cck_put(dev_priv);
175 static void intel_update_czclk(struct drm_i915_private *dev_priv)
177 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
180 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
181 CCK_CZ_CLOCK_CONTROL);
183 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
184 dev_priv->czclk_freq);
187 /* units of 100MHz */
188 static u32 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
189 const struct intel_crtc_state *pipe_config)
191 if (HAS_DDI(dev_priv))
192 return pipe_config->port_clock; /* SPLL */
194 return dev_priv->fdi_pll_freq;
197 static const struct intel_limit intel_limits_i8xx_dac = {
198 .dot = { .min = 25000, .max = 350000 },
199 .vco = { .min = 908000, .max = 1512000 },
200 .n = { .min = 2, .max = 16 },
201 .m = { .min = 96, .max = 140 },
202 .m1 = { .min = 18, .max = 26 },
203 .m2 = { .min = 6, .max = 16 },
204 .p = { .min = 4, .max = 128 },
205 .p1 = { .min = 2, .max = 33 },
206 .p2 = { .dot_limit = 165000,
207 .p2_slow = 4, .p2_fast = 2 },
210 static const struct intel_limit intel_limits_i8xx_dvo = {
211 .dot = { .min = 25000, .max = 350000 },
212 .vco = { .min = 908000, .max = 1512000 },
213 .n = { .min = 2, .max = 16 },
214 .m = { .min = 96, .max = 140 },
215 .m1 = { .min = 18, .max = 26 },
216 .m2 = { .min = 6, .max = 16 },
217 .p = { .min = 4, .max = 128 },
218 .p1 = { .min = 2, .max = 33 },
219 .p2 = { .dot_limit = 165000,
220 .p2_slow = 4, .p2_fast = 4 },
223 static const struct intel_limit intel_limits_i8xx_lvds = {
224 .dot = { .min = 25000, .max = 350000 },
225 .vco = { .min = 908000, .max = 1512000 },
226 .n = { .min = 2, .max = 16 },
227 .m = { .min = 96, .max = 140 },
228 .m1 = { .min = 18, .max = 26 },
229 .m2 = { .min = 6, .max = 16 },
230 .p = { .min = 4, .max = 128 },
231 .p1 = { .min = 1, .max = 6 },
232 .p2 = { .dot_limit = 165000,
233 .p2_slow = 14, .p2_fast = 7 },
236 static const struct intel_limit intel_limits_i9xx_sdvo = {
237 .dot = { .min = 20000, .max = 400000 },
238 .vco = { .min = 1400000, .max = 2800000 },
239 .n = { .min = 1, .max = 6 },
240 .m = { .min = 70, .max = 120 },
241 .m1 = { .min = 8, .max = 18 },
242 .m2 = { .min = 3, .max = 7 },
243 .p = { .min = 5, .max = 80 },
244 .p1 = { .min = 1, .max = 8 },
245 .p2 = { .dot_limit = 200000,
246 .p2_slow = 10, .p2_fast = 5 },
249 static const struct intel_limit intel_limits_i9xx_lvds = {
250 .dot = { .min = 20000, .max = 400000 },
251 .vco = { .min = 1400000, .max = 2800000 },
252 .n = { .min = 1, .max = 6 },
253 .m = { .min = 70, .max = 120 },
254 .m1 = { .min = 8, .max = 18 },
255 .m2 = { .min = 3, .max = 7 },
256 .p = { .min = 7, .max = 98 },
257 .p1 = { .min = 1, .max = 8 },
258 .p2 = { .dot_limit = 112000,
259 .p2_slow = 14, .p2_fast = 7 },
263 static const struct intel_limit intel_limits_g4x_sdvo = {
264 .dot = { .min = 25000, .max = 270000 },
265 .vco = { .min = 1750000, .max = 3500000},
266 .n = { .min = 1, .max = 4 },
267 .m = { .min = 104, .max = 138 },
268 .m1 = { .min = 17, .max = 23 },
269 .m2 = { .min = 5, .max = 11 },
270 .p = { .min = 10, .max = 30 },
271 .p1 = { .min = 1, .max = 3},
272 .p2 = { .dot_limit = 270000,
278 static const struct intel_limit intel_limits_g4x_hdmi = {
279 .dot = { .min = 22000, .max = 400000 },
280 .vco = { .min = 1750000, .max = 3500000},
281 .n = { .min = 1, .max = 4 },
282 .m = { .min = 104, .max = 138 },
283 .m1 = { .min = 16, .max = 23 },
284 .m2 = { .min = 5, .max = 11 },
285 .p = { .min = 5, .max = 80 },
286 .p1 = { .min = 1, .max = 8},
287 .p2 = { .dot_limit = 165000,
288 .p2_slow = 10, .p2_fast = 5 },
291 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
292 .dot = { .min = 20000, .max = 115000 },
293 .vco = { .min = 1750000, .max = 3500000 },
294 .n = { .min = 1, .max = 3 },
295 .m = { .min = 104, .max = 138 },
296 .m1 = { .min = 17, .max = 23 },
297 .m2 = { .min = 5, .max = 11 },
298 .p = { .min = 28, .max = 112 },
299 .p1 = { .min = 2, .max = 8 },
300 .p2 = { .dot_limit = 0,
301 .p2_slow = 14, .p2_fast = 14
305 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
306 .dot = { .min = 80000, .max = 224000 },
307 .vco = { .min = 1750000, .max = 3500000 },
308 .n = { .min = 1, .max = 3 },
309 .m = { .min = 104, .max = 138 },
310 .m1 = { .min = 17, .max = 23 },
311 .m2 = { .min = 5, .max = 11 },
312 .p = { .min = 14, .max = 42 },
313 .p1 = { .min = 2, .max = 6 },
314 .p2 = { .dot_limit = 0,
315 .p2_slow = 7, .p2_fast = 7
319 static const struct intel_limit pnv_limits_sdvo = {
320 .dot = { .min = 20000, .max = 400000},
321 .vco = { .min = 1700000, .max = 3500000 },
322 /* Pineview's Ncounter is a ring counter */
323 .n = { .min = 3, .max = 6 },
324 .m = { .min = 2, .max = 256 },
325 /* Pineview only has one combined m divider, which we treat as m2. */
326 .m1 = { .min = 0, .max = 0 },
327 .m2 = { .min = 0, .max = 254 },
328 .p = { .min = 5, .max = 80 },
329 .p1 = { .min = 1, .max = 8 },
330 .p2 = { .dot_limit = 200000,
331 .p2_slow = 10, .p2_fast = 5 },
334 static const struct intel_limit pnv_limits_lvds = {
335 .dot = { .min = 20000, .max = 400000 },
336 .vco = { .min = 1700000, .max = 3500000 },
337 .n = { .min = 3, .max = 6 },
338 .m = { .min = 2, .max = 256 },
339 .m1 = { .min = 0, .max = 0 },
340 .m2 = { .min = 0, .max = 254 },
341 .p = { .min = 7, .max = 112 },
342 .p1 = { .min = 1, .max = 8 },
343 .p2 = { .dot_limit = 112000,
344 .p2_slow = 14, .p2_fast = 14 },
347 /* Ironlake / Sandybridge
349 * We calculate clock using (register_value + 2) for N/M1/M2, so here
350 * the range value for them is (actual_value - 2).
352 static const struct intel_limit ilk_limits_dac = {
353 .dot = { .min = 25000, .max = 350000 },
354 .vco = { .min = 1760000, .max = 3510000 },
355 .n = { .min = 1, .max = 5 },
356 .m = { .min = 79, .max = 127 },
357 .m1 = { .min = 12, .max = 22 },
358 .m2 = { .min = 5, .max = 9 },
359 .p = { .min = 5, .max = 80 },
360 .p1 = { .min = 1, .max = 8 },
361 .p2 = { .dot_limit = 225000,
362 .p2_slow = 10, .p2_fast = 5 },
365 static const struct intel_limit ilk_limits_single_lvds = {
366 .dot = { .min = 25000, .max = 350000 },
367 .vco = { .min = 1760000, .max = 3510000 },
368 .n = { .min = 1, .max = 3 },
369 .m = { .min = 79, .max = 118 },
370 .m1 = { .min = 12, .max = 22 },
371 .m2 = { .min = 5, .max = 9 },
372 .p = { .min = 28, .max = 112 },
373 .p1 = { .min = 2, .max = 8 },
374 .p2 = { .dot_limit = 225000,
375 .p2_slow = 14, .p2_fast = 14 },
378 static const struct intel_limit ilk_limits_dual_lvds = {
379 .dot = { .min = 25000, .max = 350000 },
380 .vco = { .min = 1760000, .max = 3510000 },
381 .n = { .min = 1, .max = 3 },
382 .m = { .min = 79, .max = 127 },
383 .m1 = { .min = 12, .max = 22 },
384 .m2 = { .min = 5, .max = 9 },
385 .p = { .min = 14, .max = 56 },
386 .p1 = { .min = 2, .max = 8 },
387 .p2 = { .dot_limit = 225000,
388 .p2_slow = 7, .p2_fast = 7 },
391 /* LVDS 100mhz refclk limits. */
392 static const struct intel_limit ilk_limits_single_lvds_100m = {
393 .dot = { .min = 25000, .max = 350000 },
394 .vco = { .min = 1760000, .max = 3510000 },
395 .n = { .min = 1, .max = 2 },
396 .m = { .min = 79, .max = 126 },
397 .m1 = { .min = 12, .max = 22 },
398 .m2 = { .min = 5, .max = 9 },
399 .p = { .min = 28, .max = 112 },
400 .p1 = { .min = 2, .max = 8 },
401 .p2 = { .dot_limit = 225000,
402 .p2_slow = 14, .p2_fast = 14 },
405 static const struct intel_limit ilk_limits_dual_lvds_100m = {
406 .dot = { .min = 25000, .max = 350000 },
407 .vco = { .min = 1760000, .max = 3510000 },
408 .n = { .min = 1, .max = 3 },
409 .m = { .min = 79, .max = 126 },
410 .m1 = { .min = 12, .max = 22 },
411 .m2 = { .min = 5, .max = 9 },
412 .p = { .min = 14, .max = 42 },
413 .p1 = { .min = 2, .max = 6 },
414 .p2 = { .dot_limit = 225000,
415 .p2_slow = 7, .p2_fast = 7 },
418 static const struct intel_limit intel_limits_vlv = {
420 * These are the data rate limits (measured in fast clocks)
421 * since those are the strictest limits we have. The fast
422 * clock and actual rate limits are more relaxed, so checking
423 * them would make no difference.
425 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
426 .vco = { .min = 4000000, .max = 6000000 },
427 .n = { .min = 1, .max = 7 },
428 .m1 = { .min = 2, .max = 3 },
429 .m2 = { .min = 11, .max = 156 },
430 .p1 = { .min = 2, .max = 3 },
431 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
434 static const struct intel_limit intel_limits_chv = {
436 * These are the data rate limits (measured in fast clocks)
437 * since those are the strictest limits we have. The fast
438 * clock and actual rate limits are more relaxed, so checking
439 * them would make no difference.
441 .dot = { .min = 25000 * 5, .max = 540000 * 5},
442 .vco = { .min = 4800000, .max = 6480000 },
443 .n = { .min = 1, .max = 1 },
444 .m1 = { .min = 2, .max = 2 },
445 .m2 = { .min = 24 << 22, .max = 175 << 22 },
446 .p1 = { .min = 2, .max = 4 },
447 .p2 = { .p2_slow = 1, .p2_fast = 14 },
450 static const struct intel_limit intel_limits_bxt = {
451 /* FIXME: find real dot limits */
452 .dot = { .min = 0, .max = INT_MAX },
453 .vco = { .min = 4800000, .max = 6700000 },
454 .n = { .min = 1, .max = 1 },
455 .m1 = { .min = 2, .max = 2 },
456 /* FIXME: find real m2 limits */
457 .m2 = { .min = 2 << 22, .max = 255 << 22 },
458 .p1 = { .min = 2, .max = 4 },
459 .p2 = { .p2_slow = 1, .p2_fast = 20 },
462 /* WA Display #0827: Gen9:all */
464 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
467 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
468 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DUPS1_GATING_DIS | DUPS2_GATING_DIS);
470 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
471 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
474 /* Wa_2006604312:icl,ehl */
476 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
480 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
481 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
483 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
484 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
488 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
490 return crtc_state->master_transcoder != INVALID_TRANSCODER;
494 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
496 return crtc_state->sync_mode_slaves_mask != 0;
500 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
502 return is_trans_port_sync_master(crtc_state) ||
503 is_trans_port_sync_slave(crtc_state);
507 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
508 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
509 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
510 * The helpers' return value is the rate of the clock that is fed to the
511 * display engine's pipe which can be the above fast dot clock rate or a
512 * divided-down version of it.
514 /* m1 is reserved as 0 in Pineview, n is a ring counter */
515 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
517 clock->m = clock->m2 + 2;
518 clock->p = clock->p1 * clock->p2;
519 if (WARN_ON(clock->n == 0 || clock->p == 0))
521 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
522 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
527 static u32 i9xx_dpll_compute_m(struct dpll *dpll)
529 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
532 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
534 clock->m = i9xx_dpll_compute_m(clock);
535 clock->p = clock->p1 * clock->p2;
536 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
538 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
539 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
544 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
546 clock->m = clock->m1 * clock->m2;
547 clock->p = clock->p1 * clock->p2;
548 if (WARN_ON(clock->n == 0 || clock->p == 0))
550 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
551 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
553 return clock->dot / 5;
556 int chv_calc_dpll_params(int refclk, struct dpll *clock)
558 clock->m = clock->m1 * clock->m2;
559 clock->p = clock->p1 * clock->p2;
560 if (WARN_ON(clock->n == 0 || clock->p == 0))
562 clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
564 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
566 return clock->dot / 5;
570 * Returns whether the given set of divisors are valid for a given refclk with
571 * the given connectors.
573 static bool intel_pll_is_valid(struct drm_i915_private *dev_priv,
574 const struct intel_limit *limit,
575 const struct dpll *clock)
577 if (clock->n < limit->n.min || limit->n.max < clock->n)
579 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
581 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
583 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
586 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
587 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
588 if (clock->m1 <= clock->m2)
591 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
592 !IS_GEN9_LP(dev_priv)) {
593 if (clock->p < limit->p.min || limit->p.max < clock->p)
595 if (clock->m < limit->m.min || limit->m.max < clock->m)
599 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
601 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
602 * connector, etc., rather than just a single range.
604 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
611 i9xx_select_p2_div(const struct intel_limit *limit,
612 const struct intel_crtc_state *crtc_state,
615 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
617 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
619 * For LVDS just rely on its current settings for dual-channel.
620 * We haven't figured out how to reliably set up different
621 * single/dual channel state, if we even can.
623 if (intel_is_dual_link_lvds(dev_priv))
624 return limit->p2.p2_fast;
626 return limit->p2.p2_slow;
628 if (target < limit->p2.dot_limit)
629 return limit->p2.p2_slow;
631 return limit->p2.p2_fast;
636 * Returns a set of divisors for the desired target clock with the given
637 * refclk, or FALSE. The returned values represent the clock equation:
638 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
640 * Target and reference clocks are specified in kHz.
642 * If match_clock is provided, then best_clock P divider must match the P
643 * divider from @match_clock used for LVDS downclocking.
646 i9xx_find_best_dpll(const struct intel_limit *limit,
647 struct intel_crtc_state *crtc_state,
648 int target, int refclk, struct dpll *match_clock,
649 struct dpll *best_clock)
651 struct drm_device *dev = crtc_state->uapi.crtc->dev;
655 memset(best_clock, 0, sizeof(*best_clock));
657 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
659 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
661 for (clock.m2 = limit->m2.min;
662 clock.m2 <= limit->m2.max; clock.m2++) {
663 if (clock.m2 >= clock.m1)
665 for (clock.n = limit->n.min;
666 clock.n <= limit->n.max; clock.n++) {
667 for (clock.p1 = limit->p1.min;
668 clock.p1 <= limit->p1.max; clock.p1++) {
671 i9xx_calc_dpll_params(refclk, &clock);
672 if (!intel_pll_is_valid(to_i915(dev),
677 clock.p != match_clock->p)
680 this_err = abs(clock.dot - target);
681 if (this_err < err) {
690 return (err != target);
694 * Returns a set of divisors for the desired target clock with the given
695 * refclk, or FALSE. The returned values represent the clock equation:
696 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
698 * Target and reference clocks are specified in kHz.
700 * If match_clock is provided, then best_clock P divider must match the P
701 * divider from @match_clock used for LVDS downclocking.
704 pnv_find_best_dpll(const struct intel_limit *limit,
705 struct intel_crtc_state *crtc_state,
706 int target, int refclk, struct dpll *match_clock,
707 struct dpll *best_clock)
709 struct drm_device *dev = crtc_state->uapi.crtc->dev;
713 memset(best_clock, 0, sizeof(*best_clock));
715 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
717 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
719 for (clock.m2 = limit->m2.min;
720 clock.m2 <= limit->m2.max; clock.m2++) {
721 for (clock.n = limit->n.min;
722 clock.n <= limit->n.max; clock.n++) {
723 for (clock.p1 = limit->p1.min;
724 clock.p1 <= limit->p1.max; clock.p1++) {
727 pnv_calc_dpll_params(refclk, &clock);
728 if (!intel_pll_is_valid(to_i915(dev),
733 clock.p != match_clock->p)
736 this_err = abs(clock.dot - target);
737 if (this_err < err) {
746 return (err != target);
750 * Returns a set of divisors for the desired target clock with the given
751 * refclk, or FALSE. The returned values represent the clock equation:
752 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
754 * Target and reference clocks are specified in kHz.
756 * If match_clock is provided, then best_clock P divider must match the P
757 * divider from @match_clock used for LVDS downclocking.
760 g4x_find_best_dpll(const struct intel_limit *limit,
761 struct intel_crtc_state *crtc_state,
762 int target, int refclk, struct dpll *match_clock,
763 struct dpll *best_clock)
765 struct drm_device *dev = crtc_state->uapi.crtc->dev;
769 /* approximately equals target * 0.00585 */
770 int err_most = (target >> 8) + (target >> 9);
772 memset(best_clock, 0, sizeof(*best_clock));
774 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
776 max_n = limit->n.max;
777 /* based on hardware requirement, prefer smaller n to precision */
778 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
779 /* based on hardware requirement, prefere larger m1,m2 */
780 for (clock.m1 = limit->m1.max;
781 clock.m1 >= limit->m1.min; clock.m1--) {
782 for (clock.m2 = limit->m2.max;
783 clock.m2 >= limit->m2.min; clock.m2--) {
784 for (clock.p1 = limit->p1.max;
785 clock.p1 >= limit->p1.min; clock.p1--) {
788 i9xx_calc_dpll_params(refclk, &clock);
789 if (!intel_pll_is_valid(to_i915(dev),
794 this_err = abs(clock.dot - target);
795 if (this_err < err_most) {
809 * Check if the calculated PLL configuration is more optimal compared to the
810 * best configuration and error found so far. Return the calculated error.
812 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
813 const struct dpll *calculated_clock,
814 const struct dpll *best_clock,
815 unsigned int best_error_ppm,
816 unsigned int *error_ppm)
819 * For CHV ignore the error and consider only the P value.
820 * Prefer a bigger P value based on HW requirements.
822 if (IS_CHERRYVIEW(to_i915(dev))) {
825 return calculated_clock->p > best_clock->p;
828 if (drm_WARN_ON_ONCE(dev, !target_freq))
831 *error_ppm = div_u64(1000000ULL *
832 abs(target_freq - calculated_clock->dot),
835 * Prefer a better P value over a better (smaller) error if the error
836 * is small. Ensure this preference for future configurations too by
837 * setting the error to 0.
839 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
845 return *error_ppm + 10 < best_error_ppm;
849 * Returns a set of divisors for the desired target clock with the given
850 * refclk, or FALSE. The returned values represent the clock equation:
851 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
854 vlv_find_best_dpll(const struct intel_limit *limit,
855 struct intel_crtc_state *crtc_state,
856 int target, int refclk, struct dpll *match_clock,
857 struct dpll *best_clock)
859 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
860 struct drm_device *dev = crtc->base.dev;
862 unsigned int bestppm = 1000000;
863 /* min update 19.2 MHz */
864 int max_n = min(limit->n.max, refclk / 19200);
867 target *= 5; /* fast clock */
869 memset(best_clock, 0, sizeof(*best_clock));
871 /* based on hardware requirement, prefer smaller n to precision */
872 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
873 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
874 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
875 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
876 clock.p = clock.p1 * clock.p2;
877 /* based on hardware requirement, prefer bigger m1,m2 values */
878 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
881 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
884 vlv_calc_dpll_params(refclk, &clock);
886 if (!intel_pll_is_valid(to_i915(dev),
891 if (!vlv_PLL_is_optimal(dev, target,
909 * Returns a set of divisors for the desired target clock with the given
910 * refclk, or FALSE. The returned values represent the clock equation:
911 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
914 chv_find_best_dpll(const struct intel_limit *limit,
915 struct intel_crtc_state *crtc_state,
916 int target, int refclk, struct dpll *match_clock,
917 struct dpll *best_clock)
919 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
920 struct drm_device *dev = crtc->base.dev;
921 unsigned int best_error_ppm;
926 memset(best_clock, 0, sizeof(*best_clock));
927 best_error_ppm = 1000000;
930 * Based on hardware doc, the n always set to 1, and m1 always
931 * set to 2. If requires to support 200Mhz refclk, we need to
932 * revisit this because n may not 1 anymore.
936 target *= 5; /* fast clock */
938 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
939 for (clock.p2 = limit->p2.p2_fast;
940 clock.p2 >= limit->p2.p2_slow;
941 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
942 unsigned int error_ppm;
944 clock.p = clock.p1 * clock.p2;
946 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
949 if (m2 > INT_MAX/clock.m1)
954 chv_calc_dpll_params(refclk, &clock);
956 if (!intel_pll_is_valid(to_i915(dev), limit, &clock))
959 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
960 best_error_ppm, &error_ppm))
964 best_error_ppm = error_ppm;
972 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
973 struct dpll *best_clock)
976 const struct intel_limit *limit = &intel_limits_bxt;
978 return chv_find_best_dpll(limit, crtc_state,
979 crtc_state->port_clock, refclk,
983 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
986 i915_reg_t reg = PIPEDSL(pipe);
990 if (IS_GEN(dev_priv, 2))
991 line_mask = DSL_LINEMASK_GEN2;
993 line_mask = DSL_LINEMASK_GEN3;
995 line1 = intel_de_read(dev_priv, reg) & line_mask;
997 line2 = intel_de_read(dev_priv, reg) & line_mask;
999 return line1 != line2;
1002 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1004 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1005 enum pipe pipe = crtc->pipe;
1007 /* Wait for the display line to settle/start moving */
1008 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1009 drm_err(&dev_priv->drm,
1010 "pipe %c scanline %s wait timed out\n",
1011 pipe_name(pipe), onoff(state));
1014 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1016 wait_for_pipe_scanline_moving(crtc, false);
1019 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1021 wait_for_pipe_scanline_moving(crtc, true);
1025 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1027 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1028 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1030 if (INTEL_GEN(dev_priv) >= 4) {
1031 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1032 i915_reg_t reg = PIPECONF(cpu_transcoder);
1034 /* Wait for the Pipe State to go off */
1035 if (intel_de_wait_for_clear(dev_priv, reg,
1036 I965_PIPECONF_ACTIVE, 100))
1037 drm_WARN(&dev_priv->drm, 1,
1038 "pipe_off wait timed out\n");
1040 intel_wait_for_pipe_scanline_stopped(crtc);
1044 /* Only for pre-ILK configs */
1045 void assert_pll(struct drm_i915_private *dev_priv,
1046 enum pipe pipe, bool state)
1051 val = intel_de_read(dev_priv, DPLL(pipe));
1052 cur_state = !!(val & DPLL_VCO_ENABLE);
1053 I915_STATE_WARN(cur_state != state,
1054 "PLL state assertion failure (expected %s, current %s)\n",
1055 onoff(state), onoff(cur_state));
1058 /* XXX: the dsi pll is shared between MIPI DSI ports */
1059 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1064 vlv_cck_get(dev_priv);
1065 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1066 vlv_cck_put(dev_priv);
1068 cur_state = val & DSI_PLL_VCO_EN;
1069 I915_STATE_WARN(cur_state != state,
1070 "DSI PLL state assertion failure (expected %s, current %s)\n",
1071 onoff(state), onoff(cur_state));
1074 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1075 enum pipe pipe, bool state)
1079 if (HAS_DDI(dev_priv)) {
1081 * DDI does not have a specific FDI_TX register.
1083 * FDI is never fed from EDP transcoder
1084 * so pipe->transcoder cast is fine here.
1086 enum transcoder cpu_transcoder = (enum transcoder)pipe;
1087 u32 val = intel_de_read(dev_priv,
1088 TRANS_DDI_FUNC_CTL(cpu_transcoder));
1089 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1091 u32 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
1092 cur_state = !!(val & FDI_TX_ENABLE);
1094 I915_STATE_WARN(cur_state != state,
1095 "FDI TX state assertion failure (expected %s, current %s)\n",
1096 onoff(state), onoff(cur_state));
1098 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1099 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1101 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1102 enum pipe pipe, bool state)
1107 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
1108 cur_state = !!(val & FDI_RX_ENABLE);
1109 I915_STATE_WARN(cur_state != state,
1110 "FDI RX state assertion failure (expected %s, current %s)\n",
1111 onoff(state), onoff(cur_state));
1113 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1114 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1116 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1121 /* ILK FDI PLL is always enabled */
1122 if (IS_GEN(dev_priv, 5))
1125 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1126 if (HAS_DDI(dev_priv))
1129 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
1130 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1133 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1134 enum pipe pipe, bool state)
1139 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
1140 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1141 I915_STATE_WARN(cur_state != state,
1142 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1143 onoff(state), onoff(cur_state));
1146 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1150 enum pipe panel_pipe = INVALID_PIPE;
1153 if (drm_WARN_ON(&dev_priv->drm, HAS_DDI(dev_priv)))
1156 if (HAS_PCH_SPLIT(dev_priv)) {
1159 pp_reg = PP_CONTROL(0);
1160 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1163 case PANEL_PORT_SELECT_LVDS:
1164 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1166 case PANEL_PORT_SELECT_DPA:
1167 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1169 case PANEL_PORT_SELECT_DPC:
1170 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1172 case PANEL_PORT_SELECT_DPD:
1173 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1176 MISSING_CASE(port_sel);
1179 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1180 /* presumably write lock depends on pipe, not port select */
1181 pp_reg = PP_CONTROL(pipe);
1186 pp_reg = PP_CONTROL(0);
1187 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1189 drm_WARN_ON(&dev_priv->drm,
1190 port_sel != PANEL_PORT_SELECT_LVDS);
1191 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1194 val = intel_de_read(dev_priv, pp_reg);
1195 if (!(val & PANEL_POWER_ON) ||
1196 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1199 I915_STATE_WARN(panel_pipe == pipe && locked,
1200 "panel assertion failure, pipe %c regs locked\n",
1204 void assert_pipe(struct drm_i915_private *dev_priv,
1205 enum transcoder cpu_transcoder, bool state)
1208 enum intel_display_power_domain power_domain;
1209 intel_wakeref_t wakeref;
1211 /* we keep both pipes enabled on 830 */
1212 if (IS_I830(dev_priv))
1215 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1216 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1218 u32 val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
1219 cur_state = !!(val & PIPECONF_ENABLE);
1221 intel_display_power_put(dev_priv, power_domain, wakeref);
1226 I915_STATE_WARN(cur_state != state,
1227 "transcoder %s assertion failure (expected %s, current %s)\n",
1228 transcoder_name(cpu_transcoder),
1229 onoff(state), onoff(cur_state));
1232 static void assert_plane(struct intel_plane *plane, bool state)
1237 cur_state = plane->get_hw_state(plane, &pipe);
1239 I915_STATE_WARN(cur_state != state,
1240 "%s assertion failure (expected %s, current %s)\n",
1241 plane->base.name, onoff(state), onoff(cur_state));
1244 #define assert_plane_enabled(p) assert_plane(p, true)
1245 #define assert_plane_disabled(p) assert_plane(p, false)
1247 static void assert_planes_disabled(struct intel_crtc *crtc)
1249 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1250 struct intel_plane *plane;
1252 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1253 assert_plane_disabled(plane);
1256 static void assert_vblank_disabled(struct drm_crtc *crtc)
1258 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1259 drm_crtc_vblank_put(crtc);
1262 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1268 val = intel_de_read(dev_priv, PCH_TRANSCONF(pipe));
1269 enabled = !!(val & TRANS_ENABLE);
1270 I915_STATE_WARN(enabled,
1271 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1275 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1276 enum pipe pipe, enum port port,
1279 enum pipe port_pipe;
1282 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1284 I915_STATE_WARN(state && port_pipe == pipe,
1285 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1286 port_name(port), pipe_name(pipe));
1288 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1289 "IBX PCH DP %c still using transcoder B\n",
1293 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1294 enum pipe pipe, enum port port,
1295 i915_reg_t hdmi_reg)
1297 enum pipe port_pipe;
1300 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1302 I915_STATE_WARN(state && port_pipe == pipe,
1303 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1304 port_name(port), pipe_name(pipe));
1306 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1307 "IBX PCH HDMI %c still using transcoder B\n",
1311 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1314 enum pipe port_pipe;
1316 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1317 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1318 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1320 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1322 "PCH VGA enabled on transcoder %c, should be disabled\n",
1325 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1327 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1330 /* PCH SDVOB multiplex with HDMIB */
1331 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1332 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1333 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1336 static void _vlv_enable_pll(struct intel_crtc *crtc,
1337 const struct intel_crtc_state *pipe_config)
1339 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1340 enum pipe pipe = crtc->pipe;
1342 intel_de_write(dev_priv, DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1343 intel_de_posting_read(dev_priv, DPLL(pipe));
1346 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1347 drm_err(&dev_priv->drm, "DPLL %d failed to lock\n", pipe);
1350 static void vlv_enable_pll(struct intel_crtc *crtc,
1351 const struct intel_crtc_state *pipe_config)
1353 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1354 enum pipe pipe = crtc->pipe;
1356 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1358 /* PLL is protected by panel, make sure we can write it */
1359 assert_panel_unlocked(dev_priv, pipe);
1361 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1362 _vlv_enable_pll(crtc, pipe_config);
1364 intel_de_write(dev_priv, DPLL_MD(pipe),
1365 pipe_config->dpll_hw_state.dpll_md);
1366 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
1370 static void _chv_enable_pll(struct intel_crtc *crtc,
1371 const struct intel_crtc_state *pipe_config)
1373 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1374 enum pipe pipe = crtc->pipe;
1375 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1378 vlv_dpio_get(dev_priv);
1380 /* Enable back the 10bit clock to display controller */
1381 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1382 tmp |= DPIO_DCLKP_EN;
1383 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1385 vlv_dpio_put(dev_priv);
1388 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1393 intel_de_write(dev_priv, DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1395 /* Check PLL is locked */
1396 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1397 drm_err(&dev_priv->drm, "PLL %d failed to lock\n", pipe);
1400 static void chv_enable_pll(struct intel_crtc *crtc,
1401 const struct intel_crtc_state *pipe_config)
1403 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1404 enum pipe pipe = crtc->pipe;
1406 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1408 /* PLL is protected by panel, make sure we can write it */
1409 assert_panel_unlocked(dev_priv, pipe);
1411 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1412 _chv_enable_pll(crtc, pipe_config);
1414 if (pipe != PIPE_A) {
1416 * WaPixelRepeatModeFixForC0:chv
1418 * DPLLCMD is AWOL. Use chicken bits to propagate
1419 * the value from DPLLBMD to either pipe B or C.
1421 intel_de_write(dev_priv, CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1422 intel_de_write(dev_priv, DPLL_MD(PIPE_B),
1423 pipe_config->dpll_hw_state.dpll_md);
1424 intel_de_write(dev_priv, CBR4_VLV, 0);
1425 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1428 * DPLLB VGA mode also seems to cause problems.
1429 * We should always have it disabled.
1431 drm_WARN_ON(&dev_priv->drm,
1432 (intel_de_read(dev_priv, DPLL(PIPE_B)) &
1433 DPLL_VGA_MODE_DIS) == 0);
1435 intel_de_write(dev_priv, DPLL_MD(pipe),
1436 pipe_config->dpll_hw_state.dpll_md);
1437 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
1441 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1443 if (IS_I830(dev_priv))
1446 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1449 static void i9xx_enable_pll(struct intel_crtc *crtc,
1450 const struct intel_crtc_state *crtc_state)
1452 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1453 i915_reg_t reg = DPLL(crtc->pipe);
1454 u32 dpll = crtc_state->dpll_hw_state.dpll;
1457 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1459 /* PLL is protected by panel, make sure we can write it */
1460 if (i9xx_has_pps(dev_priv))
1461 assert_panel_unlocked(dev_priv, crtc->pipe);
1464 * Apparently we need to have VGA mode enabled prior to changing
1465 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1466 * dividers, even though the register value does change.
1468 intel_de_write(dev_priv, reg, dpll & ~DPLL_VGA_MODE_DIS);
1469 intel_de_write(dev_priv, reg, dpll);
1471 /* Wait for the clocks to stabilize. */
1472 intel_de_posting_read(dev_priv, reg);
1475 if (INTEL_GEN(dev_priv) >= 4) {
1476 intel_de_write(dev_priv, DPLL_MD(crtc->pipe),
1477 crtc_state->dpll_hw_state.dpll_md);
1479 /* The pixel multiplier can only be updated once the
1480 * DPLL is enabled and the clocks are stable.
1482 * So write it again.
1484 intel_de_write(dev_priv, reg, dpll);
1487 /* We do this three times for luck */
1488 for (i = 0; i < 3; i++) {
1489 intel_de_write(dev_priv, reg, dpll);
1490 intel_de_posting_read(dev_priv, reg);
1491 udelay(150); /* wait for warmup */
1495 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1497 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1498 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1499 enum pipe pipe = crtc->pipe;
1501 /* Don't disable pipe or pipe PLLs if needed */
1502 if (IS_I830(dev_priv))
1505 /* Make sure the pipe isn't still relying on us */
1506 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1508 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
1509 intel_de_posting_read(dev_priv, DPLL(pipe));
1512 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1516 /* Make sure the pipe isn't still relying on us */
1517 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1519 val = DPLL_INTEGRATED_REF_CLK_VLV |
1520 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1522 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1524 intel_de_write(dev_priv, DPLL(pipe), val);
1525 intel_de_posting_read(dev_priv, DPLL(pipe));
1528 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1530 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1533 /* Make sure the pipe isn't still relying on us */
1534 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1536 val = DPLL_SSC_REF_CLK_CHV |
1537 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1539 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1541 intel_de_write(dev_priv, DPLL(pipe), val);
1542 intel_de_posting_read(dev_priv, DPLL(pipe));
1544 vlv_dpio_get(dev_priv);
1546 /* Disable 10bit clock to display controller */
1547 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1548 val &= ~DPIO_DCLKP_EN;
1549 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1551 vlv_dpio_put(dev_priv);
1554 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1555 struct intel_digital_port *dig_port,
1556 unsigned int expected_mask)
1559 i915_reg_t dpll_reg;
1561 switch (dig_port->base.port) {
1563 port_mask = DPLL_PORTB_READY_MASK;
1567 port_mask = DPLL_PORTC_READY_MASK;
1569 expected_mask <<= 4;
1572 port_mask = DPLL_PORTD_READY_MASK;
1573 dpll_reg = DPIO_PHY_STATUS;
1579 if (intel_de_wait_for_register(dev_priv, dpll_reg,
1580 port_mask, expected_mask, 1000))
1581 drm_WARN(&dev_priv->drm, 1,
1582 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
1583 dig_port->base.base.base.id, dig_port->base.base.name,
1584 intel_de_read(dev_priv, dpll_reg) & port_mask,
1588 static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1590 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1591 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1592 enum pipe pipe = crtc->pipe;
1594 u32 val, pipeconf_val;
1596 /* Make sure PCH DPLL is enabled */
1597 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1599 /* FDI must be feeding us bits for PCH ports */
1600 assert_fdi_tx_enabled(dev_priv, pipe);
1601 assert_fdi_rx_enabled(dev_priv, pipe);
1603 if (HAS_PCH_CPT(dev_priv)) {
1604 reg = TRANS_CHICKEN2(pipe);
1605 val = intel_de_read(dev_priv, reg);
1607 * Workaround: Set the timing override bit
1608 * before enabling the pch transcoder.
1610 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1611 /* Configure frame start delay to match the CPU */
1612 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1613 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1614 intel_de_write(dev_priv, reg, val);
1617 reg = PCH_TRANSCONF(pipe);
1618 val = intel_de_read(dev_priv, reg);
1619 pipeconf_val = intel_de_read(dev_priv, PIPECONF(pipe));
1621 if (HAS_PCH_IBX(dev_priv)) {
1622 /* Configure frame start delay to match the CPU */
1623 val &= ~TRANS_FRAME_START_DELAY_MASK;
1624 val |= TRANS_FRAME_START_DELAY(0);
1627 * Make the BPC in transcoder be consistent with
1628 * that in pipeconf reg. For HDMI we must use 8bpc
1629 * here for both 8bpc and 12bpc.
1631 val &= ~PIPECONF_BPC_MASK;
1632 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1633 val |= PIPECONF_8BPC;
1635 val |= pipeconf_val & PIPECONF_BPC_MASK;
1638 val &= ~TRANS_INTERLACE_MASK;
1639 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
1640 if (HAS_PCH_IBX(dev_priv) &&
1641 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1642 val |= TRANS_LEGACY_INTERLACED_ILK;
1644 val |= TRANS_INTERLACED;
1646 val |= TRANS_PROGRESSIVE;
1649 intel_de_write(dev_priv, reg, val | TRANS_ENABLE);
1650 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
1651 drm_err(&dev_priv->drm, "failed to enable transcoder %c\n",
1655 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1656 enum transcoder cpu_transcoder)
1658 u32 val, pipeconf_val;
1660 /* FDI must be feeding us bits for PCH ports */
1661 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1662 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1664 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
1665 /* Workaround: set timing override bit. */
1666 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1667 /* Configure frame start delay to match the CPU */
1668 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1669 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1670 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
1673 pipeconf_val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
1675 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1676 PIPECONF_INTERLACED_ILK)
1677 val |= TRANS_INTERLACED;
1679 val |= TRANS_PROGRESSIVE;
1681 intel_de_write(dev_priv, LPT_TRANSCONF, val);
1682 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
1683 TRANS_STATE_ENABLE, 100))
1684 drm_err(&dev_priv->drm, "Failed to enable PCH transcoder\n");
1687 static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1693 /* FDI relies on the transcoder */
1694 assert_fdi_tx_disabled(dev_priv, pipe);
1695 assert_fdi_rx_disabled(dev_priv, pipe);
1697 /* Ports must be off as well */
1698 assert_pch_ports_disabled(dev_priv, pipe);
1700 reg = PCH_TRANSCONF(pipe);
1701 val = intel_de_read(dev_priv, reg);
1702 val &= ~TRANS_ENABLE;
1703 intel_de_write(dev_priv, reg, val);
1704 /* wait for PCH transcoder off, transcoder state */
1705 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
1706 drm_err(&dev_priv->drm, "failed to disable transcoder %c\n",
1709 if (HAS_PCH_CPT(dev_priv)) {
1710 /* Workaround: Clear the timing override chicken bit again. */
1711 reg = TRANS_CHICKEN2(pipe);
1712 val = intel_de_read(dev_priv, reg);
1713 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1714 intel_de_write(dev_priv, reg, val);
1718 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1722 val = intel_de_read(dev_priv, LPT_TRANSCONF);
1723 val &= ~TRANS_ENABLE;
1724 intel_de_write(dev_priv, LPT_TRANSCONF, val);
1725 /* wait for PCH transcoder off, transcoder state */
1726 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
1727 TRANS_STATE_ENABLE, 50))
1728 drm_err(&dev_priv->drm, "Failed to disable PCH transcoder\n");
1730 /* Workaround: clear timing override bit. */
1731 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
1732 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1733 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
1736 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1738 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1740 if (HAS_PCH_LPT(dev_priv))
1746 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1748 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1749 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1750 u32 mode_flags = crtc->mode_flags;
1753 * From Gen 11, In case of dsi cmd mode, frame counter wouldnt
1754 * have updated at the beginning of TE, if we want to use
1755 * the hw counter, then we would find it updated in only
1756 * the next TE, hence switching to sw counter.
1758 if (mode_flags & (I915_MODE_FLAG_DSI_USE_TE0 | I915_MODE_FLAG_DSI_USE_TE1))
1762 * On i965gm the hardware frame counter reads
1763 * zero when the TV encoder is enabled :(
1765 if (IS_I965GM(dev_priv) &&
1766 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1769 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1770 return 0xffffffff; /* full 32 bit counter */
1771 else if (INTEL_GEN(dev_priv) >= 3)
1772 return 0xffffff; /* only 24 bits of frame count */
1774 return 0; /* Gen2 doesn't have a hardware frame counter */
1777 void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1779 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1781 assert_vblank_disabled(&crtc->base);
1782 drm_crtc_set_max_vblank_count(&crtc->base,
1783 intel_crtc_max_vblank_count(crtc_state));
1784 drm_crtc_vblank_on(&crtc->base);
1787 void intel_crtc_vblank_off(const struct intel_crtc_state *crtc_state)
1789 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1791 drm_crtc_vblank_off(&crtc->base);
1792 assert_vblank_disabled(&crtc->base);
1795 void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1797 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
1798 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1799 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1800 enum pipe pipe = crtc->pipe;
1804 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
1806 assert_planes_disabled(crtc);
1809 * A pipe without a PLL won't actually be able to drive bits from
1810 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1813 if (HAS_GMCH(dev_priv)) {
1814 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1815 assert_dsi_pll_enabled(dev_priv);
1817 assert_pll_enabled(dev_priv, pipe);
1819 if (new_crtc_state->has_pch_encoder) {
1820 /* if driving the PCH, we need FDI enabled */
1821 assert_fdi_rx_pll_enabled(dev_priv,
1822 intel_crtc_pch_transcoder(crtc));
1823 assert_fdi_tx_pll_enabled(dev_priv,
1824 (enum pipe) cpu_transcoder);
1826 /* FIXME: assert CPU port conditions for SNB+ */
1829 trace_intel_pipe_enable(crtc);
1831 reg = PIPECONF(cpu_transcoder);
1832 val = intel_de_read(dev_priv, reg);
1833 if (val & PIPECONF_ENABLE) {
1834 /* we keep both pipes enabled on 830 */
1835 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
1839 intel_de_write(dev_priv, reg, val | PIPECONF_ENABLE);
1840 intel_de_posting_read(dev_priv, reg);
1843 * Until the pipe starts PIPEDSL reads will return a stale value,
1844 * which causes an apparent vblank timestamp jump when PIPEDSL
1845 * resets to its proper value. That also messes up the frame count
1846 * when it's derived from the timestamps. So let's wait for the
1847 * pipe to start properly before we call drm_crtc_vblank_on()
1849 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1850 intel_wait_for_pipe_scanline_moving(crtc);
1853 void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1855 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1856 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1857 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1858 enum pipe pipe = crtc->pipe;
1862 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
1865 * Make sure planes won't keep trying to pump pixels to us,
1866 * or we might hang the display.
1868 assert_planes_disabled(crtc);
1870 trace_intel_pipe_disable(crtc);
1872 reg = PIPECONF(cpu_transcoder);
1873 val = intel_de_read(dev_priv, reg);
1874 if ((val & PIPECONF_ENABLE) == 0)
1878 * Double wide has implications for planes
1879 * so best keep it disabled when not needed.
1881 if (old_crtc_state->double_wide)
1882 val &= ~PIPECONF_DOUBLE_WIDE;
1884 /* Don't disable pipe or pipe PLLs if needed */
1885 if (!IS_I830(dev_priv))
1886 val &= ~PIPECONF_ENABLE;
1888 intel_de_write(dev_priv, reg, val);
1889 if ((val & PIPECONF_ENABLE) == 0)
1890 intel_wait_for_pipe_off(old_crtc_state);
1893 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1895 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1898 static bool is_ccs_plane(const struct drm_framebuffer *fb, int plane)
1900 if (!is_ccs_modifier(fb->modifier))
1903 return plane >= fb->format->num_planes / 2;
1906 static bool is_gen12_ccs_modifier(u64 modifier)
1908 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
1909 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
1913 static bool is_gen12_ccs_plane(const struct drm_framebuffer *fb, int plane)
1915 return is_gen12_ccs_modifier(fb->modifier) && is_ccs_plane(fb, plane);
1918 static bool is_aux_plane(const struct drm_framebuffer *fb, int plane)
1920 if (is_ccs_modifier(fb->modifier))
1921 return is_ccs_plane(fb, plane);
1926 static int main_to_ccs_plane(const struct drm_framebuffer *fb, int main_plane)
1928 drm_WARN_ON(fb->dev, !is_ccs_modifier(fb->modifier) ||
1929 (main_plane && main_plane >= fb->format->num_planes / 2));
1931 return fb->format->num_planes / 2 + main_plane;
1934 static int ccs_to_main_plane(const struct drm_framebuffer *fb, int ccs_plane)
1936 drm_WARN_ON(fb->dev, !is_ccs_modifier(fb->modifier) ||
1937 ccs_plane < fb->format->num_planes / 2);
1939 return ccs_plane - fb->format->num_planes / 2;
1942 int intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane)
1944 struct drm_i915_private *i915 = to_i915(fb->dev);
1946 if (is_ccs_modifier(fb->modifier))
1947 return main_to_ccs_plane(fb, main_plane);
1948 else if (INTEL_GEN(i915) < 11 &&
1949 intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
1956 intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
1959 return info->is_yuv &&
1960 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
1963 static bool is_semiplanar_uv_plane(const struct drm_framebuffer *fb,
1966 return intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
1971 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1973 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1974 unsigned int cpp = fb->format->cpp[color_plane];
1976 switch (fb->modifier) {
1977 case DRM_FORMAT_MOD_LINEAR:
1978 return intel_tile_size(dev_priv);
1979 case I915_FORMAT_MOD_X_TILED:
1980 if (IS_GEN(dev_priv, 2))
1984 case I915_FORMAT_MOD_Y_TILED_CCS:
1985 if (is_ccs_plane(fb, color_plane))
1988 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1989 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1990 if (is_ccs_plane(fb, color_plane))
1993 case I915_FORMAT_MOD_Y_TILED:
1994 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
1998 case I915_FORMAT_MOD_Yf_TILED_CCS:
1999 if (is_ccs_plane(fb, color_plane))
2002 case I915_FORMAT_MOD_Yf_TILED:
2018 MISSING_CASE(fb->modifier);
2024 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
2026 if (is_gen12_ccs_plane(fb, color_plane))
2029 return intel_tile_size(to_i915(fb->dev)) /
2030 intel_tile_width_bytes(fb, color_plane);
2033 /* Return the tile dimensions in pixel units */
2034 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
2035 unsigned int *tile_width,
2036 unsigned int *tile_height)
2038 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
2039 unsigned int cpp = fb->format->cpp[color_plane];
2041 *tile_width = tile_width_bytes / cpp;
2042 *tile_height = intel_tile_height(fb, color_plane);
2045 static unsigned int intel_tile_row_size(const struct drm_framebuffer *fb,
2048 unsigned int tile_width, tile_height;
2050 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2052 return fb->pitches[color_plane] * tile_height;
2056 intel_fb_align_height(const struct drm_framebuffer *fb,
2057 int color_plane, unsigned int height)
2059 unsigned int tile_height = intel_tile_height(fb, color_plane);
2061 return ALIGN(height, tile_height);
2064 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2066 unsigned int size = 0;
2069 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2070 size += rot_info->plane[i].width * rot_info->plane[i].height;
2075 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
2077 unsigned int size = 0;
2080 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
2081 size += rem_info->plane[i].width * rem_info->plane[i].height;
2087 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2088 const struct drm_framebuffer *fb,
2089 unsigned int rotation)
2091 view->type = I915_GGTT_VIEW_NORMAL;
2092 if (drm_rotation_90_or_270(rotation)) {
2093 view->type = I915_GGTT_VIEW_ROTATED;
2094 view->rotated = to_intel_framebuffer(fb)->rot_info;
2098 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2100 if (IS_I830(dev_priv))
2102 else if (IS_I85X(dev_priv))
2104 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2110 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2112 if (INTEL_GEN(dev_priv) >= 9)
2114 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2115 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2117 else if (INTEL_GEN(dev_priv) >= 4)
2123 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2126 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2128 /* AUX_DIST needs only 4K alignment */
2129 if ((INTEL_GEN(dev_priv) < 12 && is_aux_plane(fb, color_plane)) ||
2130 is_ccs_plane(fb, color_plane))
2133 switch (fb->modifier) {
2134 case DRM_FORMAT_MOD_LINEAR:
2135 return intel_linear_alignment(dev_priv);
2136 case I915_FORMAT_MOD_X_TILED:
2137 if (INTEL_GEN(dev_priv) >= 9)
2140 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2141 if (is_semiplanar_uv_plane(fb, color_plane))
2142 return intel_tile_row_size(fb, color_plane);
2144 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2146 case I915_FORMAT_MOD_Y_TILED_CCS:
2147 case I915_FORMAT_MOD_Yf_TILED_CCS:
2148 case I915_FORMAT_MOD_Y_TILED:
2149 if (INTEL_GEN(dev_priv) >= 12 &&
2150 is_semiplanar_uv_plane(fb, color_plane))
2151 return intel_tile_row_size(fb, color_plane);
2153 case I915_FORMAT_MOD_Yf_TILED:
2154 return 1 * 1024 * 1024;
2156 MISSING_CASE(fb->modifier);
2161 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2163 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2164 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2166 return INTEL_GEN(dev_priv) < 4 ||
2168 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
2172 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2173 const struct i915_ggtt_view *view,
2175 unsigned long *out_flags)
2177 struct drm_device *dev = fb->dev;
2178 struct drm_i915_private *dev_priv = to_i915(dev);
2179 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2180 intel_wakeref_t wakeref;
2181 struct i915_vma *vma;
2182 unsigned int pinctl;
2185 if (drm_WARN_ON(dev, !i915_gem_object_is_framebuffer(obj)))
2186 return ERR_PTR(-EINVAL);
2188 alignment = intel_surf_alignment(fb, 0);
2189 if (drm_WARN_ON(dev, alignment && !is_power_of_2(alignment)))
2190 return ERR_PTR(-EINVAL);
2192 /* Note that the w/a also requires 64 PTE of padding following the
2193 * bo. We currently fill all unused PTE with the shadow page and so
2194 * we should always have valid PTE following the scanout preventing
2197 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2198 alignment = 256 * 1024;
2201 * Global gtt pte registers are special registers which actually forward
2202 * writes to a chunk of system memory. Which means that there is no risk
2203 * that the register values disappear as soon as we call
2204 * intel_runtime_pm_put(), so it is correct to wrap only the
2205 * pin/unpin/fence and not more.
2207 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
2209 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2212 * Valleyview is definitely limited to scanning out the first
2213 * 512MiB. Lets presume this behaviour was inherited from the
2214 * g4x display engine and that all earlier gen are similarly
2215 * limited. Testing suggests that it is a little more
2216 * complicated than this. For example, Cherryview appears quite
2217 * happy to scanout from anywhere within its global aperture.
2220 if (HAS_GMCH(dev_priv))
2221 pinctl |= PIN_MAPPABLE;
2223 vma = i915_gem_object_pin_to_display_plane(obj,
2224 alignment, view, pinctl);
2228 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2232 * Install a fence for tiled scan-out. Pre-i965 always needs a
2233 * fence, whereas 965+ only requires a fence if using
2234 * framebuffer compression. For simplicity, we always, when
2235 * possible, install a fence as the cost is not that onerous.
2237 * If we fail to fence the tiled scanout, then either the
2238 * modeset will reject the change (which is highly unlikely as
2239 * the affected systems, all but one, do not have unmappable
2240 * space) or we will not be able to enable full powersaving
2241 * techniques (also likely not to apply due to various limits
2242 * FBC and the like impose on the size of the buffer, which
2243 * presumably we violated anyway with this unmappable buffer).
2244 * Anyway, it is presumably better to stumble onwards with
2245 * something and try to run the system in a "less than optimal"
2246 * mode that matches the user configuration.
2248 ret = i915_vma_pin_fence(vma);
2249 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2250 i915_gem_object_unpin_from_display_plane(vma);
2255 if (ret == 0 && vma->fence)
2256 *out_flags |= PLANE_HAS_FENCE;
2261 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2262 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
2266 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2268 i915_gem_object_lock(vma->obj, NULL);
2269 if (flags & PLANE_HAS_FENCE)
2270 i915_vma_unpin_fence(vma);
2271 i915_gem_object_unpin_from_display_plane(vma);
2272 i915_gem_object_unlock(vma->obj);
2277 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2278 unsigned int rotation)
2280 if (drm_rotation_90_or_270(rotation))
2281 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2283 return fb->pitches[color_plane];
2287 * Convert the x/y offsets into a linear offset.
2288 * Only valid with 0/180 degree rotation, which is fine since linear
2289 * offset is only used with linear buffers on pre-hsw and tiled buffers
2290 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2292 u32 intel_fb_xy_to_linear(int x, int y,
2293 const struct intel_plane_state *state,
2296 const struct drm_framebuffer *fb = state->hw.fb;
2297 unsigned int cpp = fb->format->cpp[color_plane];
2298 unsigned int pitch = state->color_plane[color_plane].stride;
2300 return y * pitch + x * cpp;
2304 * Add the x/y offsets derived from fb->offsets[] to the user
2305 * specified plane src x/y offsets. The resulting x/y offsets
2306 * specify the start of scanout from the beginning of the gtt mapping.
2308 void intel_add_fb_offsets(int *x, int *y,
2309 const struct intel_plane_state *state,
2313 *x += state->color_plane[color_plane].x;
2314 *y += state->color_plane[color_plane].y;
2317 static u32 intel_adjust_tile_offset(int *x, int *y,
2318 unsigned int tile_width,
2319 unsigned int tile_height,
2320 unsigned int tile_size,
2321 unsigned int pitch_tiles,
2325 unsigned int pitch_pixels = pitch_tiles * tile_width;
2328 WARN_ON(old_offset & (tile_size - 1));
2329 WARN_ON(new_offset & (tile_size - 1));
2330 WARN_ON(new_offset > old_offset);
2332 tiles = (old_offset - new_offset) / tile_size;
2334 *y += tiles / pitch_tiles * tile_height;
2335 *x += tiles % pitch_tiles * tile_width;
2337 /* minimize x in case it got needlessly big */
2338 *y += *x / pitch_pixels * tile_height;
2344 static bool is_surface_linear(const struct drm_framebuffer *fb, int color_plane)
2346 return fb->modifier == DRM_FORMAT_MOD_LINEAR ||
2347 is_gen12_ccs_plane(fb, color_plane);
2350 static u32 intel_adjust_aligned_offset(int *x, int *y,
2351 const struct drm_framebuffer *fb,
2353 unsigned int rotation,
2355 u32 old_offset, u32 new_offset)
2357 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2358 unsigned int cpp = fb->format->cpp[color_plane];
2360 drm_WARN_ON(&dev_priv->drm, new_offset > old_offset);
2362 if (!is_surface_linear(fb, color_plane)) {
2363 unsigned int tile_size, tile_width, tile_height;
2364 unsigned int pitch_tiles;
2366 tile_size = intel_tile_size(dev_priv);
2367 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2369 if (drm_rotation_90_or_270(rotation)) {
2370 pitch_tiles = pitch / tile_height;
2371 swap(tile_width, tile_height);
2373 pitch_tiles = pitch / (tile_width * cpp);
2376 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2377 tile_size, pitch_tiles,
2378 old_offset, new_offset);
2380 old_offset += *y * pitch + *x * cpp;
2382 *y = (old_offset - new_offset) / pitch;
2383 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2390 * Adjust the tile offset by moving the difference into
2393 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2394 const struct intel_plane_state *state,
2396 u32 old_offset, u32 new_offset)
2398 return intel_adjust_aligned_offset(x, y, state->hw.fb, color_plane,
2400 state->color_plane[color_plane].stride,
2401 old_offset, new_offset);
2405 * Computes the aligned offset to the base tile and adjusts
2406 * x, y. bytes per pixel is assumed to be a power-of-two.
2408 * In the 90/270 rotated case, x and y are assumed
2409 * to be already rotated to match the rotated GTT view, and
2410 * pitch is the tile_height aligned framebuffer height.
2412 * This function is used when computing the derived information
2413 * under intel_framebuffer, so using any of that information
2414 * here is not allowed. Anything under drm_framebuffer can be
2415 * used. This is why the user has to pass in the pitch since it
2416 * is specified in the rotated orientation.
2418 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2420 const struct drm_framebuffer *fb,
2423 unsigned int rotation,
2426 unsigned int cpp = fb->format->cpp[color_plane];
2427 u32 offset, offset_aligned;
2429 if (!is_surface_linear(fb, color_plane)) {
2430 unsigned int tile_size, tile_width, tile_height;
2431 unsigned int tile_rows, tiles, pitch_tiles;
2433 tile_size = intel_tile_size(dev_priv);
2434 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2436 if (drm_rotation_90_or_270(rotation)) {
2437 pitch_tiles = pitch / tile_height;
2438 swap(tile_width, tile_height);
2440 pitch_tiles = pitch / (tile_width * cpp);
2443 tile_rows = *y / tile_height;
2446 tiles = *x / tile_width;
2449 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2451 offset_aligned = offset;
2453 offset_aligned = rounddown(offset_aligned, alignment);
2455 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2456 tile_size, pitch_tiles,
2457 offset, offset_aligned);
2459 offset = *y * pitch + *x * cpp;
2460 offset_aligned = offset;
2462 offset_aligned = rounddown(offset_aligned, alignment);
2463 *y = (offset % alignment) / pitch;
2464 *x = ((offset % alignment) - *y * pitch) / cpp;
2470 return offset_aligned;
2473 u32 intel_plane_compute_aligned_offset(int *x, int *y,
2474 const struct intel_plane_state *state,
2477 struct intel_plane *intel_plane = to_intel_plane(state->uapi.plane);
2478 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2479 const struct drm_framebuffer *fb = state->hw.fb;
2480 unsigned int rotation = state->hw.rotation;
2481 int pitch = state->color_plane[color_plane].stride;
2484 if (intel_plane->id == PLANE_CURSOR)
2485 alignment = intel_cursor_alignment(dev_priv);
2487 alignment = intel_surf_alignment(fb, color_plane);
2489 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2490 pitch, rotation, alignment);
2493 /* Convert the fb->offset[] into x/y offsets */
2494 static int intel_fb_offset_to_xy(int *x, int *y,
2495 const struct drm_framebuffer *fb,
2498 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2499 unsigned int height;
2502 if (INTEL_GEN(dev_priv) >= 12 &&
2503 is_semiplanar_uv_plane(fb, color_plane))
2504 alignment = intel_tile_row_size(fb, color_plane);
2505 else if (fb->modifier != DRM_FORMAT_MOD_LINEAR)
2506 alignment = intel_tile_size(dev_priv);
2510 if (alignment != 0 && fb->offsets[color_plane] % alignment) {
2511 drm_dbg_kms(&dev_priv->drm,
2512 "Misaligned offset 0x%08x for color plane %d\n",
2513 fb->offsets[color_plane], color_plane);
2517 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2518 height = ALIGN(height, intel_tile_height(fb, color_plane));
2520 /* Catch potential overflows early */
2521 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2522 fb->offsets[color_plane])) {
2523 drm_dbg_kms(&dev_priv->drm,
2524 "Bad offset 0x%08x or pitch %d for color plane %d\n",
2525 fb->offsets[color_plane], fb->pitches[color_plane],
2533 intel_adjust_aligned_offset(x, y,
2534 fb, color_plane, DRM_MODE_ROTATE_0,
2535 fb->pitches[color_plane],
2536 fb->offsets[color_plane], 0);
2541 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2543 switch (fb_modifier) {
2544 case I915_FORMAT_MOD_X_TILED:
2545 return I915_TILING_X;
2546 case I915_FORMAT_MOD_Y_TILED:
2547 case I915_FORMAT_MOD_Y_TILED_CCS:
2548 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2549 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2550 return I915_TILING_Y;
2552 return I915_TILING_NONE;
2557 * From the Sky Lake PRM:
2558 * "The Color Control Surface (CCS) contains the compression status of
2559 * the cache-line pairs. The compression state of the cache-line pair
2560 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2561 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2562 * cache-line-pairs. CCS is always Y tiled."
2564 * Since cache line pairs refers to horizontally adjacent cache lines,
2565 * each cache line in the CCS corresponds to an area of 32x16 cache
2566 * lines on the main surface. Since each pixel is 4 bytes, this gives
2567 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2570 static const struct drm_format_info skl_ccs_formats[] = {
2571 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2572 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2573 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2574 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2575 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2576 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2577 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2578 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2582 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
2583 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
2584 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
2585 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
2588 static const struct drm_format_info gen12_ccs_formats[] = {
2589 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2590 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2591 .hsub = 1, .vsub = 1, },
2592 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2593 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2594 .hsub = 1, .vsub = 1, },
2595 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2596 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2597 .hsub = 1, .vsub = 1, .has_alpha = true },
2598 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2599 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2600 .hsub = 1, .vsub = 1, .has_alpha = true },
2601 { .format = DRM_FORMAT_YUYV, .num_planes = 2,
2602 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2603 .hsub = 2, .vsub = 1, .is_yuv = true },
2604 { .format = DRM_FORMAT_YVYU, .num_planes = 2,
2605 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2606 .hsub = 2, .vsub = 1, .is_yuv = true },
2607 { .format = DRM_FORMAT_UYVY, .num_planes = 2,
2608 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2609 .hsub = 2, .vsub = 1, .is_yuv = true },
2610 { .format = DRM_FORMAT_VYUY, .num_planes = 2,
2611 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2612 .hsub = 2, .vsub = 1, .is_yuv = true },
2613 { .format = DRM_FORMAT_NV12, .num_planes = 4,
2614 .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 },
2615 .hsub = 2, .vsub = 2, .is_yuv = true },
2616 { .format = DRM_FORMAT_P010, .num_planes = 4,
2617 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2618 .hsub = 2, .vsub = 2, .is_yuv = true },
2619 { .format = DRM_FORMAT_P012, .num_planes = 4,
2620 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2621 .hsub = 2, .vsub = 2, .is_yuv = true },
2622 { .format = DRM_FORMAT_P016, .num_planes = 4,
2623 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2624 .hsub = 2, .vsub = 2, .is_yuv = true },
2627 static const struct drm_format_info *
2628 lookup_format_info(const struct drm_format_info formats[],
2629 int num_formats, u32 format)
2633 for (i = 0; i < num_formats; i++) {
2634 if (formats[i].format == format)
2641 static const struct drm_format_info *
2642 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2644 switch (cmd->modifier[0]) {
2645 case I915_FORMAT_MOD_Y_TILED_CCS:
2646 case I915_FORMAT_MOD_Yf_TILED_CCS:
2647 return lookup_format_info(skl_ccs_formats,
2648 ARRAY_SIZE(skl_ccs_formats),
2650 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2651 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2652 return lookup_format_info(gen12_ccs_formats,
2653 ARRAY_SIZE(gen12_ccs_formats),
2660 bool is_ccs_modifier(u64 modifier)
2662 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
2663 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS ||
2664 modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2665 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2668 static int gen12_ccs_aux_stride(struct drm_framebuffer *fb, int ccs_plane)
2670 return DIV_ROUND_UP(fb->pitches[ccs_to_main_plane(fb, ccs_plane)],
2674 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
2675 u32 pixel_format, u64 modifier)
2677 struct intel_crtc *crtc;
2678 struct intel_plane *plane;
2681 * We assume the primary plane for pipe A has
2682 * the highest stride limits of them all,
2683 * if in case pipe A is disabled, use the first pipe from pipe_mask.
2685 crtc = intel_get_first_crtc(dev_priv);
2689 plane = to_intel_plane(crtc->base.primary);
2691 return plane->max_stride(plane, pixel_format, modifier,
2696 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
2697 u32 pixel_format, u64 modifier)
2700 * Arbitrary limit for gen4+ chosen to match the
2701 * render engine max stride.
2703 * The new CCS hash mode makes remapping impossible
2705 if (!is_ccs_modifier(modifier)) {
2706 if (INTEL_GEN(dev_priv) >= 7)
2708 else if (INTEL_GEN(dev_priv) >= 4)
2712 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
2716 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
2718 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2721 if (is_surface_linear(fb, color_plane)) {
2722 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
2727 * To make remapping with linear generally feasible
2728 * we need the stride to be page aligned.
2730 if (fb->pitches[color_plane] > max_stride &&
2731 !is_ccs_modifier(fb->modifier))
2732 return intel_tile_size(dev_priv);
2737 tile_width = intel_tile_width_bytes(fb, color_plane);
2738 if (is_ccs_modifier(fb->modifier)) {
2740 * Display WA #0531: skl,bxt,kbl,glk
2742 * Render decompression and plane width > 3840
2743 * combined with horizontal panning requires the
2744 * plane stride to be a multiple of 4. We'll just
2745 * require the entire fb to accommodate that to avoid
2746 * potential runtime errors at plane configuration time.
2748 if (IS_GEN(dev_priv, 9) && color_plane == 0 && fb->width > 3840)
2751 * The main surface pitch must be padded to a multiple of four
2754 else if (INTEL_GEN(dev_priv) >= 12)
2760 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
2762 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2763 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2764 const struct drm_framebuffer *fb = plane_state->hw.fb;
2767 /* We don't want to deal with remapping with cursors */
2768 if (plane->id == PLANE_CURSOR)
2772 * The display engine limits already match/exceed the
2773 * render engine limits, so not much point in remapping.
2774 * Would also need to deal with the fence POT alignment
2775 * and gen2 2KiB GTT tile size.
2777 if (INTEL_GEN(dev_priv) < 4)
2781 * The new CCS hash mode isn't compatible with remapping as
2782 * the virtual address of the pages affects the compressed data.
2784 if (is_ccs_modifier(fb->modifier))
2787 /* Linear needs a page aligned stride for remapping */
2788 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2789 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2791 for (i = 0; i < fb->format->num_planes; i++) {
2792 if (fb->pitches[i] & alignment)
2800 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2802 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2803 const struct drm_framebuffer *fb = plane_state->hw.fb;
2804 unsigned int rotation = plane_state->hw.rotation;
2805 u32 stride, max_stride;
2808 * No remapping for invisible planes since we don't have
2809 * an actual source viewport to remap.
2811 if (!plane_state->uapi.visible)
2814 if (!intel_plane_can_remap(plane_state))
2818 * FIXME: aux plane limits on gen9+ are
2819 * unclear in Bspec, for now no checking.
2821 stride = intel_fb_pitch(fb, 0, rotation);
2822 max_stride = plane->max_stride(plane, fb->format->format,
2823 fb->modifier, rotation);
2825 return stride > max_stride;
2829 intel_fb_plane_get_subsampling(int *hsub, int *vsub,
2830 const struct drm_framebuffer *fb,
2835 if (color_plane == 0) {
2843 * TODO: Deduct the subsampling from the char block for all CCS
2844 * formats and planes.
2846 if (!is_gen12_ccs_plane(fb, color_plane)) {
2847 *hsub = fb->format->hsub;
2848 *vsub = fb->format->vsub;
2853 main_plane = ccs_to_main_plane(fb, color_plane);
2854 *hsub = drm_format_info_block_width(fb->format, color_plane) /
2855 drm_format_info_block_width(fb->format, main_plane);
2858 * The min stride check in the core framebuffer_check() function
2859 * assumes that format->hsub applies to every plane except for the
2860 * first plane. That's incorrect for the CCS AUX plane of the first
2861 * plane, but for the above check to pass we must define the block
2862 * width with that subsampling applied to it. Adjust the width here
2863 * accordingly, so we can calculate the actual subsampling factor.
2865 if (main_plane == 0)
2866 *hsub *= fb->format->hsub;
2871 intel_fb_check_ccs_xy(struct drm_framebuffer *fb, int ccs_plane, int x, int y)
2873 struct drm_i915_private *i915 = to_i915(fb->dev);
2874 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2877 int tile_width, tile_height;
2881 if (!is_ccs_plane(fb, ccs_plane))
2884 intel_tile_dims(fb, ccs_plane, &tile_width, &tile_height);
2885 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
2888 tile_height *= vsub;
2890 ccs_x = (x * hsub) % tile_width;
2891 ccs_y = (y * vsub) % tile_height;
2893 main_plane = ccs_to_main_plane(fb, ccs_plane);
2894 main_x = intel_fb->normal[main_plane].x % tile_width;
2895 main_y = intel_fb->normal[main_plane].y % tile_height;
2898 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2899 * x/y offsets must match between CCS and the main surface.
2901 if (main_x != ccs_x || main_y != ccs_y) {
2902 drm_dbg_kms(&i915->drm,
2903 "Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2906 intel_fb->normal[main_plane].x,
2907 intel_fb->normal[main_plane].y,
2916 intel_fb_plane_dims(int *w, int *h, struct drm_framebuffer *fb, int color_plane)
2918 int main_plane = is_ccs_plane(fb, color_plane) ?
2919 ccs_to_main_plane(fb, color_plane) : 0;
2920 int main_hsub, main_vsub;
2923 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb, main_plane);
2924 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, color_plane);
2925 *w = fb->width / main_hsub / hsub;
2926 *h = fb->height / main_vsub / vsub;
2930 * Setup the rotated view for an FB plane and return the size the GTT mapping
2931 * requires for this view.
2934 setup_fb_rotation(int plane, const struct intel_remapped_plane_info *plane_info,
2935 u32 gtt_offset_rotated, int x, int y,
2936 unsigned int width, unsigned int height,
2937 unsigned int tile_size,
2938 unsigned int tile_width, unsigned int tile_height,
2939 struct drm_framebuffer *fb)
2941 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2942 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2943 unsigned int pitch_tiles;
2946 /* Y or Yf modifiers required for 90/270 rotation */
2947 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
2948 fb->modifier != I915_FORMAT_MOD_Yf_TILED)
2951 if (drm_WARN_ON(fb->dev, plane >= ARRAY_SIZE(rot_info->plane)))
2954 rot_info->plane[plane] = *plane_info;
2956 intel_fb->rotated[plane].pitch = plane_info->height * tile_height;
2958 /* rotate the x/y offsets to match the GTT view */
2959 drm_rect_init(&r, x, y, width, height);
2961 plane_info->width * tile_width,
2962 plane_info->height * tile_height,
2963 DRM_MODE_ROTATE_270);
2967 /* rotate the tile dimensions to match the GTT view */
2968 pitch_tiles = intel_fb->rotated[plane].pitch / tile_height;
2969 swap(tile_width, tile_height);
2972 * We only keep the x/y offsets, so push all of the
2973 * gtt offset into the x/y offsets.
2975 intel_adjust_tile_offset(&x, &y,
2976 tile_width, tile_height,
2977 tile_size, pitch_tiles,
2978 gtt_offset_rotated * tile_size, 0);
2981 * First pixel of the framebuffer from
2982 * the start of the rotated gtt mapping.
2984 intel_fb->rotated[plane].x = x;
2985 intel_fb->rotated[plane].y = y;
2987 return plane_info->width * plane_info->height;
2991 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2992 struct drm_framebuffer *fb)
2994 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2995 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2996 u32 gtt_offset_rotated = 0;
2997 unsigned int max_size = 0;
2998 int i, num_planes = fb->format->num_planes;
2999 unsigned int tile_size = intel_tile_size(dev_priv);
3001 for (i = 0; i < num_planes; i++) {
3002 unsigned int width, height;
3003 unsigned int cpp, size;
3008 cpp = fb->format->cpp[i];
3009 intel_fb_plane_dims(&width, &height, fb, i);
3011 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
3013 drm_dbg_kms(&dev_priv->drm,
3014 "bad fb plane %d offset: 0x%x\n",
3019 ret = intel_fb_check_ccs_xy(fb, i, x, y);
3024 * The fence (if used) is aligned to the start of the object
3025 * so having the framebuffer wrap around across the edge of the
3026 * fenced region doesn't really work. We have no API to configure
3027 * the fence start offset within the object (nor could we probably
3028 * on gen2/3). So it's just easier if we just require that the
3029 * fb layout agrees with the fence layout. We already check that the
3030 * fb stride matches the fence stride elsewhere.
3032 if (i == 0 && i915_gem_object_is_tiled(obj) &&
3033 (x + width) * cpp > fb->pitches[i]) {
3034 drm_dbg_kms(&dev_priv->drm,
3035 "bad fb plane %d offset: 0x%x\n",
3041 * First pixel of the framebuffer from
3042 * the start of the normal gtt mapping.
3044 intel_fb->normal[i].x = x;
3045 intel_fb->normal[i].y = y;
3047 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
3051 offset /= tile_size;
3053 if (!is_surface_linear(fb, i)) {
3054 struct intel_remapped_plane_info plane_info;
3055 unsigned int tile_width, tile_height;
3057 intel_tile_dims(fb, i, &tile_width, &tile_height);
3059 plane_info.offset = offset;
3060 plane_info.stride = DIV_ROUND_UP(fb->pitches[i],
3062 plane_info.width = DIV_ROUND_UP(x + width, tile_width);
3063 plane_info.height = DIV_ROUND_UP(y + height,
3066 /* how many tiles does this plane need */
3067 size = plane_info.stride * plane_info.height;
3069 * If the plane isn't horizontally tile aligned,
3070 * we need one more tile.
3075 gtt_offset_rotated +=
3076 setup_fb_rotation(i, &plane_info,
3078 x, y, width, height,
3080 tile_width, tile_height,
3083 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
3084 x * cpp, tile_size);
3087 /* how many tiles in total needed in the bo */
3088 max_size = max(max_size, offset + size);
3091 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
3092 drm_dbg_kms(&dev_priv->drm,
3093 "fb too big for bo (need %llu bytes, have %zu bytes)\n",
3094 mul_u32_u32(max_size, tile_size), obj->base.size);
3102 intel_plane_remap_gtt(struct intel_plane_state *plane_state)
3104 struct drm_i915_private *dev_priv =
3105 to_i915(plane_state->uapi.plane->dev);
3106 struct drm_framebuffer *fb = plane_state->hw.fb;
3107 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
3108 struct intel_rotation_info *info = &plane_state->view.rotated;
3109 unsigned int rotation = plane_state->hw.rotation;
3110 int i, num_planes = fb->format->num_planes;
3111 unsigned int tile_size = intel_tile_size(dev_priv);
3112 unsigned int src_x, src_y;
3113 unsigned int src_w, src_h;
3116 memset(&plane_state->view, 0, sizeof(plane_state->view));
3117 plane_state->view.type = drm_rotation_90_or_270(rotation) ?
3118 I915_GGTT_VIEW_ROTATED : I915_GGTT_VIEW_REMAPPED;
3120 src_x = plane_state->uapi.src.x1 >> 16;
3121 src_y = plane_state->uapi.src.y1 >> 16;
3122 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
3123 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
3125 drm_WARN_ON(&dev_priv->drm, is_ccs_modifier(fb->modifier));
3127 /* Make src coordinates relative to the viewport */
3128 drm_rect_translate(&plane_state->uapi.src,
3129 -(src_x << 16), -(src_y << 16));
3131 /* Rotate src coordinates to match rotated GTT view */
3132 if (drm_rotation_90_or_270(rotation))
3133 drm_rect_rotate(&plane_state->uapi.src,
3134 src_w << 16, src_h << 16,
3135 DRM_MODE_ROTATE_270);
3137 for (i = 0; i < num_planes; i++) {
3138 unsigned int hsub = i ? fb->format->hsub : 1;
3139 unsigned int vsub = i ? fb->format->vsub : 1;
3140 unsigned int cpp = fb->format->cpp[i];
3141 unsigned int tile_width, tile_height;
3142 unsigned int width, height;
3143 unsigned int pitch_tiles;
3147 intel_tile_dims(fb, i, &tile_width, &tile_height);
3151 width = src_w / hsub;
3152 height = src_h / vsub;
3155 * First pixel of the src viewport from the
3156 * start of the normal gtt mapping.
3158 x += intel_fb->normal[i].x;
3159 y += intel_fb->normal[i].y;
3161 offset = intel_compute_aligned_offset(dev_priv, &x, &y,
3162 fb, i, fb->pitches[i],
3163 DRM_MODE_ROTATE_0, tile_size);
3164 offset /= tile_size;
3166 drm_WARN_ON(&dev_priv->drm, i >= ARRAY_SIZE(info->plane));
3167 info->plane[i].offset = offset;
3168 info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
3170 info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
3171 info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
3173 if (drm_rotation_90_or_270(rotation)) {
3176 /* rotate the x/y offsets to match the GTT view */
3177 drm_rect_init(&r, x, y, width, height);
3179 info->plane[i].width * tile_width,
3180 info->plane[i].height * tile_height,
3181 DRM_MODE_ROTATE_270);
3185 pitch_tiles = info->plane[i].height;
3186 plane_state->color_plane[i].stride = pitch_tiles * tile_height;
3188 /* rotate the tile dimensions to match the GTT view */
3189 swap(tile_width, tile_height);
3191 pitch_tiles = info->plane[i].width;
3192 plane_state->color_plane[i].stride = pitch_tiles * tile_width * cpp;
3196 * We only keep the x/y offsets, so push all of the
3197 * gtt offset into the x/y offsets.
3199 intel_adjust_tile_offset(&x, &y,
3200 tile_width, tile_height,
3201 tile_size, pitch_tiles,
3202 gtt_offset * tile_size, 0);
3204 gtt_offset += info->plane[i].width * info->plane[i].height;
3206 plane_state->color_plane[i].offset = 0;
3207 plane_state->color_plane[i].x = x;
3208 plane_state->color_plane[i].y = y;
3213 intel_plane_compute_gtt(struct intel_plane_state *plane_state)
3215 const struct intel_framebuffer *fb =
3216 to_intel_framebuffer(plane_state->hw.fb);
3217 unsigned int rotation = plane_state->hw.rotation;
3223 num_planes = fb->base.format->num_planes;
3225 if (intel_plane_needs_remap(plane_state)) {
3226 intel_plane_remap_gtt(plane_state);
3229 * Sometimes even remapping can't overcome
3230 * the stride limitations :( Can happen with
3231 * big plane sizes and suitably misaligned
3234 return intel_plane_check_stride(plane_state);
3237 intel_fill_fb_ggtt_view(&plane_state->view, &fb->base, rotation);
3239 for (i = 0; i < num_planes; i++) {
3240 plane_state->color_plane[i].stride = intel_fb_pitch(&fb->base, i, rotation);
3241 plane_state->color_plane[i].offset = 0;
3243 if (drm_rotation_90_or_270(rotation)) {
3244 plane_state->color_plane[i].x = fb->rotated[i].x;
3245 plane_state->color_plane[i].y = fb->rotated[i].y;
3247 plane_state->color_plane[i].x = fb->normal[i].x;
3248 plane_state->color_plane[i].y = fb->normal[i].y;
3252 /* Rotate src coordinates to match rotated GTT view */
3253 if (drm_rotation_90_or_270(rotation))
3254 drm_rect_rotate(&plane_state->uapi.src,
3255 fb->base.width << 16, fb->base.height << 16,
3256 DRM_MODE_ROTATE_270);
3258 return intel_plane_check_stride(plane_state);
3261 static int i9xx_format_to_fourcc(int format)
3264 case DISPPLANE_8BPP:
3265 return DRM_FORMAT_C8;
3266 case DISPPLANE_BGRA555:
3267 return DRM_FORMAT_ARGB1555;
3268 case DISPPLANE_BGRX555:
3269 return DRM_FORMAT_XRGB1555;
3270 case DISPPLANE_BGRX565:
3271 return DRM_FORMAT_RGB565;
3273 case DISPPLANE_BGRX888:
3274 return DRM_FORMAT_XRGB8888;
3275 case DISPPLANE_RGBX888:
3276 return DRM_FORMAT_XBGR8888;
3277 case DISPPLANE_BGRA888:
3278 return DRM_FORMAT_ARGB8888;
3279 case DISPPLANE_RGBA888:
3280 return DRM_FORMAT_ABGR8888;
3281 case DISPPLANE_BGRX101010:
3282 return DRM_FORMAT_XRGB2101010;
3283 case DISPPLANE_RGBX101010:
3284 return DRM_FORMAT_XBGR2101010;
3285 case DISPPLANE_BGRA101010:
3286 return DRM_FORMAT_ARGB2101010;
3287 case DISPPLANE_RGBA101010:
3288 return DRM_FORMAT_ABGR2101010;
3289 case DISPPLANE_RGBX161616:
3290 return DRM_FORMAT_XBGR16161616F;
3294 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
3297 case PLANE_CTL_FORMAT_RGB_565:
3298 return DRM_FORMAT_RGB565;
3299 case PLANE_CTL_FORMAT_NV12:
3300 return DRM_FORMAT_NV12;
3301 case PLANE_CTL_FORMAT_XYUV:
3302 return DRM_FORMAT_XYUV8888;
3303 case PLANE_CTL_FORMAT_P010:
3304 return DRM_FORMAT_P010;
3305 case PLANE_CTL_FORMAT_P012:
3306 return DRM_FORMAT_P012;
3307 case PLANE_CTL_FORMAT_P016:
3308 return DRM_FORMAT_P016;
3309 case PLANE_CTL_FORMAT_Y210:
3310 return DRM_FORMAT_Y210;
3311 case PLANE_CTL_FORMAT_Y212:
3312 return DRM_FORMAT_Y212;
3313 case PLANE_CTL_FORMAT_Y216:
3314 return DRM_FORMAT_Y216;
3315 case PLANE_CTL_FORMAT_Y410:
3316 return DRM_FORMAT_XVYU2101010;
3317 case PLANE_CTL_FORMAT_Y412:
3318 return DRM_FORMAT_XVYU12_16161616;
3319 case PLANE_CTL_FORMAT_Y416:
3320 return DRM_FORMAT_XVYU16161616;
3322 case PLANE_CTL_FORMAT_XRGB_8888:
3325 return DRM_FORMAT_ABGR8888;
3327 return DRM_FORMAT_XBGR8888;
3330 return DRM_FORMAT_ARGB8888;
3332 return DRM_FORMAT_XRGB8888;
3334 case PLANE_CTL_FORMAT_XRGB_2101010:
3337 return DRM_FORMAT_ABGR2101010;
3339 return DRM_FORMAT_XBGR2101010;
3342 return DRM_FORMAT_ARGB2101010;
3344 return DRM_FORMAT_XRGB2101010;
3346 case PLANE_CTL_FORMAT_XRGB_16161616F:
3349 return DRM_FORMAT_ABGR16161616F;
3351 return DRM_FORMAT_XBGR16161616F;
3354 return DRM_FORMAT_ARGB16161616F;
3356 return DRM_FORMAT_XRGB16161616F;
3361 static struct i915_vma *
3362 initial_plane_vma(struct drm_i915_private *i915,
3363 struct intel_initial_plane_config *plane_config)
3365 struct drm_i915_gem_object *obj;
3366 struct i915_vma *vma;
3369 if (plane_config->size == 0)
3372 base = round_down(plane_config->base,
3373 I915_GTT_MIN_ALIGNMENT);
3374 size = round_up(plane_config->base + plane_config->size,
3375 I915_GTT_MIN_ALIGNMENT);
3379 * If the FB is too big, just don't use it since fbdev is not very
3380 * important and we should probably use that space with FBC or other
3383 if (size * 2 > i915->stolen_usable_size)
3386 obj = i915_gem_object_create_stolen_for_preallocated(i915, base, size);
3391 * Mark it WT ahead of time to avoid changing the
3392 * cache_level during fbdev initialization. The
3393 * unbind there would get stuck waiting for rcu.
3395 i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
3396 I915_CACHE_WT : I915_CACHE_NONE);
3398 switch (plane_config->tiling) {
3399 case I915_TILING_NONE:
3403 obj->tiling_and_stride =
3404 plane_config->fb->base.pitches[0] |
3405 plane_config->tiling;
3408 MISSING_CASE(plane_config->tiling);
3412 vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL);
3416 if (i915_ggtt_pin(vma, NULL, 0, PIN_MAPPABLE | PIN_OFFSET_FIXED | base))
3419 if (i915_gem_object_is_tiled(obj) &&
3420 !i915_vma_is_map_and_fenceable(vma))
3426 i915_gem_object_put(obj);
3431 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
3432 struct intel_initial_plane_config *plane_config)
3434 struct drm_device *dev = crtc->base.dev;
3435 struct drm_i915_private *dev_priv = to_i915(dev);
3436 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
3437 struct drm_framebuffer *fb = &plane_config->fb->base;
3438 struct i915_vma *vma;
3440 switch (fb->modifier) {
3441 case DRM_FORMAT_MOD_LINEAR:
3442 case I915_FORMAT_MOD_X_TILED:
3443 case I915_FORMAT_MOD_Y_TILED:
3446 drm_dbg(&dev_priv->drm,
3447 "Unsupported modifier for initial FB: 0x%llx\n",
3452 vma = initial_plane_vma(dev_priv, plane_config);
3456 mode_cmd.pixel_format = fb->format->format;
3457 mode_cmd.width = fb->width;
3458 mode_cmd.height = fb->height;
3459 mode_cmd.pitches[0] = fb->pitches[0];
3460 mode_cmd.modifier[0] = fb->modifier;
3461 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
3463 if (intel_framebuffer_init(to_intel_framebuffer(fb),
3464 vma->obj, &mode_cmd)) {
3465 drm_dbg_kms(&dev_priv->drm, "intel fb init failed\n");
3469 plane_config->vma = vma;
3478 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
3479 struct intel_plane_state *plane_state,
3482 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3484 plane_state->uapi.visible = visible;
3487 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
3489 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
3492 static void fixup_plane_bitmasks(struct intel_crtc_state *crtc_state)
3494 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3495 struct drm_plane *plane;
3498 * Active_planes aliases if multiple "primary" or cursor planes
3499 * have been used on the same (or wrong) pipe. plane_mask uses
3500 * unique ids, hence we can use that to reconstruct active_planes.
3502 crtc_state->enabled_planes = 0;
3503 crtc_state->active_planes = 0;
3505 drm_for_each_plane_mask(plane, &dev_priv->drm,
3506 crtc_state->uapi.plane_mask) {
3507 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
3508 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
3512 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
3513 struct intel_plane *plane)
3515 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3516 struct intel_crtc_state *crtc_state =
3517 to_intel_crtc_state(crtc->base.state);
3518 struct intel_plane_state *plane_state =
3519 to_intel_plane_state(plane->base.state);
3521 drm_dbg_kms(&dev_priv->drm,
3522 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
3523 plane->base.base.id, plane->base.name,
3524 crtc->base.base.id, crtc->base.name);
3526 intel_set_plane_visible(crtc_state, plane_state, false);
3527 fixup_plane_bitmasks(crtc_state);
3528 crtc_state->data_rate[plane->id] = 0;
3529 crtc_state->min_cdclk[plane->id] = 0;
3531 if (plane->id == PLANE_PRIMARY)
3532 hsw_disable_ips(crtc_state);
3535 * Vblank time updates from the shadow to live plane control register
3536 * are blocked if the memory self-refresh mode is active at that
3537 * moment. So to make sure the plane gets truly disabled, disable
3538 * first the self-refresh mode. The self-refresh enable bit in turn
3539 * will be checked/applied by the HW only at the next frame start
3540 * event which is after the vblank start event, so we need to have a
3541 * wait-for-vblank between disabling the plane and the pipe.
3543 if (HAS_GMCH(dev_priv) &&
3544 intel_set_memory_cxsr(dev_priv, false))
3545 intel_wait_for_vblank(dev_priv, crtc->pipe);
3548 * Gen2 reports pipe underruns whenever all planes are disabled.
3549 * So disable underrun reporting before all the planes get disabled.
3551 if (IS_GEN(dev_priv, 2) && !crtc_state->active_planes)
3552 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
3554 intel_disable_plane(plane, crtc_state);
3558 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
3559 struct intel_initial_plane_config *plane_config)
3561 struct drm_device *dev = intel_crtc->base.dev;
3562 struct drm_i915_private *dev_priv = to_i915(dev);
3564 struct drm_plane *primary = intel_crtc->base.primary;
3565 struct drm_plane_state *plane_state = primary->state;
3566 struct intel_plane *intel_plane = to_intel_plane(primary);
3567 struct intel_plane_state *intel_state =
3568 to_intel_plane_state(plane_state);
3569 struct intel_crtc_state *crtc_state =
3570 to_intel_crtc_state(intel_crtc->base.state);
3571 struct drm_framebuffer *fb;
3572 struct i915_vma *vma;
3574 if (!plane_config->fb)
3577 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
3578 fb = &plane_config->fb->base;
3579 vma = plane_config->vma;
3584 * Failed to alloc the obj, check to see if we should share
3585 * an fb with another CRTC instead
3587 for_each_crtc(dev, c) {
3588 struct intel_plane_state *state;
3590 if (c == &intel_crtc->base)
3593 if (!to_intel_crtc_state(c->state)->uapi.active)
3596 state = to_intel_plane_state(c->primary->state);
3600 if (intel_plane_ggtt_offset(state) == plane_config->base) {
3608 * We've failed to reconstruct the BIOS FB. Current display state
3609 * indicates that the primary plane is visible, but has a NULL FB,
3610 * which will lead to problems later if we don't fix it up. The
3611 * simplest solution is to just disable the primary plane now and
3612 * pretend the BIOS never had it enabled.
3614 intel_plane_disable_noatomic(intel_crtc, intel_plane);
3615 if (crtc_state->bigjoiner) {
3616 struct intel_crtc *slave =
3617 crtc_state->bigjoiner_linked_crtc;
3618 intel_plane_disable_noatomic(slave, to_intel_plane(slave->base.primary));
3624 intel_state->hw.rotation = plane_config->rotation;
3625 intel_fill_fb_ggtt_view(&intel_state->view, fb,
3626 intel_state->hw.rotation);
3627 intel_state->color_plane[0].stride =
3628 intel_fb_pitch(fb, 0, intel_state->hw.rotation);
3630 __i915_vma_pin(vma);
3631 intel_state->vma = i915_vma_get(vma);
3632 if (intel_plane_uses_fence(intel_state) && i915_vma_pin_fence(vma) == 0)
3634 intel_state->flags |= PLANE_HAS_FENCE;
3636 plane_state->src_x = 0;
3637 plane_state->src_y = 0;
3638 plane_state->src_w = fb->width << 16;
3639 plane_state->src_h = fb->height << 16;
3641 plane_state->crtc_x = 0;
3642 plane_state->crtc_y = 0;
3643 plane_state->crtc_w = fb->width;
3644 plane_state->crtc_h = fb->height;
3646 intel_state->uapi.src = drm_plane_state_src(plane_state);
3647 intel_state->uapi.dst = drm_plane_state_dest(plane_state);
3649 if (plane_config->tiling)
3650 dev_priv->preserve_bios_swizzle = true;
3652 plane_state->fb = fb;
3653 drm_framebuffer_get(fb);
3655 plane_state->crtc = &intel_crtc->base;
3656 intel_plane_copy_uapi_to_hw_state(intel_state, intel_state,
3659 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
3661 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
3662 &to_intel_frontbuffer(fb)->bits);
3667 skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3668 int main_x, int main_y, u32 main_offset,
3671 const struct drm_framebuffer *fb = plane_state->hw.fb;
3672 int aux_x = plane_state->color_plane[ccs_plane].x;
3673 int aux_y = plane_state->color_plane[ccs_plane].y;
3674 u32 aux_offset = plane_state->color_plane[ccs_plane].offset;
3675 u32 alignment = intel_surf_alignment(fb, ccs_plane);
3679 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
3680 while (aux_offset >= main_offset && aux_y <= main_y) {
3683 if (aux_x == main_x && aux_y == main_y)
3686 if (aux_offset == 0)
3691 aux_offset = intel_plane_adjust_aligned_offset(&x, &y,
3697 aux_x = x * hsub + aux_x % hsub;
3698 aux_y = y * vsub + aux_y % vsub;
3701 if (aux_x != main_x || aux_y != main_y)
3704 plane_state->color_plane[ccs_plane].offset = aux_offset;
3705 plane_state->color_plane[ccs_plane].x = aux_x;
3706 plane_state->color_plane[ccs_plane].y = aux_y;
3712 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
3716 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3717 plane_state->color_plane[0].offset, 0);
3722 static int intel_plane_min_width(struct intel_plane *plane,
3723 const struct drm_framebuffer *fb,
3725 unsigned int rotation)
3727 if (plane->min_width)
3728 return plane->min_width(fb, color_plane, rotation);
3733 static int intel_plane_max_width(struct intel_plane *plane,
3734 const struct drm_framebuffer *fb,
3736 unsigned int rotation)
3738 if (plane->max_width)
3739 return plane->max_width(fb, color_plane, rotation);
3744 static int intel_plane_max_height(struct intel_plane *plane,
3745 const struct drm_framebuffer *fb,
3747 unsigned int rotation)
3749 if (plane->max_height)
3750 return plane->max_height(fb, color_plane, rotation);
3755 int skl_calc_main_surface_offset(const struct intel_plane_state *plane_state,
3756 int *x, int *y, u32 *offset)
3758 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3759 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3760 const struct drm_framebuffer *fb = plane_state->hw.fb;
3761 const int aux_plane = intel_main_to_aux_plane(fb, 0);
3762 const u32 aux_offset = plane_state->color_plane[aux_plane].offset;
3763 const u32 alignment = intel_surf_alignment(fb, 0);
3764 const int w = drm_rect_width(&plane_state->uapi.src) >> 16;
3766 intel_add_fb_offsets(x, y, plane_state, 0);
3767 *offset = intel_plane_compute_aligned_offset(x, y, plane_state, 0);
3768 if (drm_WARN_ON(&dev_priv->drm, alignment && !is_power_of_2(alignment)))
3772 * AUX surface offset is specified as the distance from the
3773 * main surface offset, and it must be non-negative. Make
3774 * sure that is what we will get.
3776 if (aux_plane && *offset > aux_offset)
3777 *offset = intel_plane_adjust_aligned_offset(x, y, plane_state, 0,
3779 aux_offset & ~(alignment - 1));
3782 * When using an X-tiled surface, the plane blows up
3783 * if the x offset + width exceed the stride.
3785 * TODO: linear and Y-tiled seem fine, Yf untested,
3787 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3788 int cpp = fb->format->cpp[0];
3790 while ((*x + w) * cpp > plane_state->color_plane[0].stride) {
3792 drm_dbg_kms(&dev_priv->drm,
3793 "Unable to find suitable display surface offset due to X-tiling\n");
3797 *offset = intel_plane_adjust_aligned_offset(x, y, plane_state, 0,
3799 *offset - alignment);
3806 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3808 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3809 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3810 const struct drm_framebuffer *fb = plane_state->hw.fb;
3811 const unsigned int rotation = plane_state->hw.rotation;
3812 int x = plane_state->uapi.src.x1 >> 16;
3813 int y = plane_state->uapi.src.y1 >> 16;
3814 const int w = drm_rect_width(&plane_state->uapi.src) >> 16;
3815 const int h = drm_rect_height(&plane_state->uapi.src) >> 16;
3816 const int min_width = intel_plane_min_width(plane, fb, 0, rotation);
3817 const int max_width = intel_plane_max_width(plane, fb, 0, rotation);
3818 const int max_height = intel_plane_max_height(plane, fb, 0, rotation);
3819 const int aux_plane = intel_main_to_aux_plane(fb, 0);
3820 const u32 alignment = intel_surf_alignment(fb, 0);
3824 if (w > max_width || w < min_width || h > max_height) {
3825 drm_dbg_kms(&dev_priv->drm,
3826 "requested Y/RGB source size %dx%d outside limits (min: %dx1 max: %dx%d)\n",
3827 w, h, min_width, max_width, max_height);
3831 ret = skl_calc_main_surface_offset(plane_state, &x, &y, &offset);
3836 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3837 * they match with the main surface x/y offsets.
3839 if (is_ccs_modifier(fb->modifier)) {
3840 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
3841 offset, aux_plane)) {
3845 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3846 offset, offset - alignment);
3849 if (x != plane_state->color_plane[aux_plane].x ||
3850 y != plane_state->color_plane[aux_plane].y) {
3851 drm_dbg_kms(&dev_priv->drm,
3852 "Unable to find suitable display surface offset due to CCS\n");
3857 plane_state->color_plane[0].offset = offset;
3858 plane_state->color_plane[0].x = x;
3859 plane_state->color_plane[0].y = y;
3862 * Put the final coordinates back so that the src
3863 * coordinate checks will see the right values.
3865 drm_rect_translate_to(&plane_state->uapi.src,
3871 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3873 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3874 struct drm_i915_private *i915 = to_i915(plane->base.dev);
3875 const struct drm_framebuffer *fb = plane_state->hw.fb;
3876 unsigned int rotation = plane_state->hw.rotation;
3878 int max_width = intel_plane_max_width(plane, fb, uv_plane, rotation);
3879 int max_height = intel_plane_max_height(plane, fb, uv_plane, rotation);
3880 int x = plane_state->uapi.src.x1 >> 17;
3881 int y = plane_state->uapi.src.y1 >> 17;
3882 int w = drm_rect_width(&plane_state->uapi.src) >> 17;
3883 int h = drm_rect_height(&plane_state->uapi.src) >> 17;
3886 /* FIXME not quite sure how/if these apply to the chroma plane */
3887 if (w > max_width || h > max_height) {
3888 drm_dbg_kms(&i915->drm,
3889 "CbCr source size %dx%d too big (limit %dx%d)\n",
3890 w, h, max_width, max_height);
3894 intel_add_fb_offsets(&x, &y, plane_state, uv_plane);
3895 offset = intel_plane_compute_aligned_offset(&x, &y,
3896 plane_state, uv_plane);
3898 if (is_ccs_modifier(fb->modifier)) {
3899 int ccs_plane = main_to_ccs_plane(fb, uv_plane);
3900 u32 aux_offset = plane_state->color_plane[ccs_plane].offset;
3901 u32 alignment = intel_surf_alignment(fb, uv_plane);
3903 if (offset > aux_offset)
3904 offset = intel_plane_adjust_aligned_offset(&x, &y,
3908 aux_offset & ~(alignment - 1));
3910 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
3911 offset, ccs_plane)) {
3915 offset = intel_plane_adjust_aligned_offset(&x, &y,
3918 offset, offset - alignment);
3921 if (x != plane_state->color_plane[ccs_plane].x ||
3922 y != plane_state->color_plane[ccs_plane].y) {
3923 drm_dbg_kms(&i915->drm,
3924 "Unable to find suitable display surface offset due to CCS\n");
3929 plane_state->color_plane[uv_plane].offset = offset;
3930 plane_state->color_plane[uv_plane].x = x;
3931 plane_state->color_plane[uv_plane].y = y;
3936 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3938 const struct drm_framebuffer *fb = plane_state->hw.fb;
3939 int src_x = plane_state->uapi.src.x1 >> 16;
3940 int src_y = plane_state->uapi.src.y1 >> 16;
3944 for (ccs_plane = 0; ccs_plane < fb->format->num_planes; ccs_plane++) {
3945 int main_hsub, main_vsub;
3949 if (!is_ccs_plane(fb, ccs_plane))
3952 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb,
3953 ccs_to_main_plane(fb, ccs_plane));
3954 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
3961 intel_add_fb_offsets(&x, &y, plane_state, ccs_plane);
3963 offset = intel_plane_compute_aligned_offset(&x, &y,
3967 plane_state->color_plane[ccs_plane].offset = offset;
3968 plane_state->color_plane[ccs_plane].x = (x * hsub +
3971 plane_state->color_plane[ccs_plane].y = (y * vsub +
3979 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3981 const struct drm_framebuffer *fb = plane_state->hw.fb;
3984 ret = intel_plane_compute_gtt(plane_state);
3988 if (!plane_state->uapi.visible)
3992 * Handle the AUX surface first since the main surface setup depends on
3995 if (is_ccs_modifier(fb->modifier)) {
3996 ret = skl_check_ccs_aux_surface(plane_state);
4001 if (intel_format_info_is_yuv_semiplanar(fb->format,
4003 ret = skl_check_nv12_aux_surface(plane_state);
4008 for (i = fb->format->num_planes; i < ARRAY_SIZE(plane_state->color_plane); i++) {
4009 plane_state->color_plane[i].offset = 0;
4010 plane_state->color_plane[i].x = 0;
4011 plane_state->color_plane[i].y = 0;
4014 ret = skl_check_main_surface(plane_state);
4021 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
4023 struct drm_device *dev = intel_crtc->base.dev;
4024 struct drm_i915_private *dev_priv = to_i915(dev);
4025 unsigned long irqflags;
4027 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4029 intel_de_write_fw(dev_priv, SKL_PS_CTRL(intel_crtc->pipe, id), 0);
4030 intel_de_write_fw(dev_priv, SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
4031 intel_de_write_fw(dev_priv, SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
4033 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4037 * This function detaches (aka. unbinds) unused scalers in hardware
4039 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
4041 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
4042 const struct intel_crtc_scaler_state *scaler_state =
4043 &crtc_state->scaler_state;
4046 /* loop through and disable scalers that aren't in use */
4047 for (i = 0; i < intel_crtc->num_scalers; i++) {
4048 if (!scaler_state->scalers[i].in_use)
4049 skl_detach_scaler(intel_crtc, i);
4053 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
4054 int color_plane, unsigned int rotation)
4057 * The stride is either expressed as a multiple of 64 bytes chunks for
4058 * linear buffers or in number of tiles for tiled buffers.
4060 if (is_surface_linear(fb, color_plane))
4062 else if (drm_rotation_90_or_270(rotation))
4063 return intel_tile_height(fb, color_plane);
4065 return intel_tile_width_bytes(fb, color_plane);
4068 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
4071 const struct drm_framebuffer *fb = plane_state->hw.fb;
4072 unsigned int rotation = plane_state->hw.rotation;
4073 u32 stride = plane_state->color_plane[color_plane].stride;
4075 if (color_plane >= fb->format->num_planes)
4078 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
4081 static u32 skl_plane_ctl_format(u32 pixel_format)
4083 switch (pixel_format) {
4085 return PLANE_CTL_FORMAT_INDEXED;
4086 case DRM_FORMAT_RGB565:
4087 return PLANE_CTL_FORMAT_RGB_565;
4088 case DRM_FORMAT_XBGR8888:
4089 case DRM_FORMAT_ABGR8888:
4090 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
4091 case DRM_FORMAT_XRGB8888:
4092 case DRM_FORMAT_ARGB8888:
4093 return PLANE_CTL_FORMAT_XRGB_8888;
4094 case DRM_FORMAT_XBGR2101010:
4095 case DRM_FORMAT_ABGR2101010:
4096 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
4097 case DRM_FORMAT_XRGB2101010:
4098 case DRM_FORMAT_ARGB2101010:
4099 return PLANE_CTL_FORMAT_XRGB_2101010;
4100 case DRM_FORMAT_XBGR16161616F:
4101 case DRM_FORMAT_ABGR16161616F:
4102 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
4103 case DRM_FORMAT_XRGB16161616F:
4104 case DRM_FORMAT_ARGB16161616F:
4105 return PLANE_CTL_FORMAT_XRGB_16161616F;
4106 case DRM_FORMAT_XYUV8888:
4107 return PLANE_CTL_FORMAT_XYUV;
4108 case DRM_FORMAT_YUYV:
4109 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
4110 case DRM_FORMAT_YVYU:
4111 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
4112 case DRM_FORMAT_UYVY:
4113 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
4114 case DRM_FORMAT_VYUY:
4115 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
4116 case DRM_FORMAT_NV12:
4117 return PLANE_CTL_FORMAT_NV12;
4118 case DRM_FORMAT_P010:
4119 return PLANE_CTL_FORMAT_P010;
4120 case DRM_FORMAT_P012:
4121 return PLANE_CTL_FORMAT_P012;
4122 case DRM_FORMAT_P016:
4123 return PLANE_CTL_FORMAT_P016;
4124 case DRM_FORMAT_Y210:
4125 return PLANE_CTL_FORMAT_Y210;
4126 case DRM_FORMAT_Y212:
4127 return PLANE_CTL_FORMAT_Y212;
4128 case DRM_FORMAT_Y216:
4129 return PLANE_CTL_FORMAT_Y216;
4130 case DRM_FORMAT_XVYU2101010:
4131 return PLANE_CTL_FORMAT_Y410;
4132 case DRM_FORMAT_XVYU12_16161616:
4133 return PLANE_CTL_FORMAT_Y412;
4134 case DRM_FORMAT_XVYU16161616:
4135 return PLANE_CTL_FORMAT_Y416;
4137 MISSING_CASE(pixel_format);
4143 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
4145 if (!plane_state->hw.fb->format->has_alpha)
4146 return PLANE_CTL_ALPHA_DISABLE;
4148 switch (plane_state->hw.pixel_blend_mode) {
4149 case DRM_MODE_BLEND_PIXEL_NONE:
4150 return PLANE_CTL_ALPHA_DISABLE;
4151 case DRM_MODE_BLEND_PREMULTI:
4152 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
4153 case DRM_MODE_BLEND_COVERAGE:
4154 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
4156 MISSING_CASE(plane_state->hw.pixel_blend_mode);
4157 return PLANE_CTL_ALPHA_DISABLE;
4161 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
4163 if (!plane_state->hw.fb->format->has_alpha)
4164 return PLANE_COLOR_ALPHA_DISABLE;
4166 switch (plane_state->hw.pixel_blend_mode) {
4167 case DRM_MODE_BLEND_PIXEL_NONE:
4168 return PLANE_COLOR_ALPHA_DISABLE;
4169 case DRM_MODE_BLEND_PREMULTI:
4170 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
4171 case DRM_MODE_BLEND_COVERAGE:
4172 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
4174 MISSING_CASE(plane_state->hw.pixel_blend_mode);
4175 return PLANE_COLOR_ALPHA_DISABLE;
4179 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
4181 switch (fb_modifier) {
4182 case DRM_FORMAT_MOD_LINEAR:
4184 case I915_FORMAT_MOD_X_TILED:
4185 return PLANE_CTL_TILED_X;
4186 case I915_FORMAT_MOD_Y_TILED:
4187 return PLANE_CTL_TILED_Y;
4188 case I915_FORMAT_MOD_Y_TILED_CCS:
4189 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4190 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
4191 return PLANE_CTL_TILED_Y |
4192 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
4193 PLANE_CTL_CLEAR_COLOR_DISABLE;
4194 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
4195 return PLANE_CTL_TILED_Y | PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE;
4196 case I915_FORMAT_MOD_Yf_TILED:
4197 return PLANE_CTL_TILED_YF;
4198 case I915_FORMAT_MOD_Yf_TILED_CCS:
4199 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4201 MISSING_CASE(fb_modifier);
4207 static u32 skl_plane_ctl_rotate(unsigned int rotate)
4210 case DRM_MODE_ROTATE_0:
4213 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4214 * while i915 HW rotation is clockwise, thats why this swapping.
4216 case DRM_MODE_ROTATE_90:
4217 return PLANE_CTL_ROTATE_270;
4218 case DRM_MODE_ROTATE_180:
4219 return PLANE_CTL_ROTATE_180;
4220 case DRM_MODE_ROTATE_270:
4221 return PLANE_CTL_ROTATE_90;
4223 MISSING_CASE(rotate);
4229 static u32 cnl_plane_ctl_flip(unsigned int reflect)
4234 case DRM_MODE_REFLECT_X:
4235 return PLANE_CTL_FLIP_HORIZONTAL;
4236 case DRM_MODE_REFLECT_Y:
4238 MISSING_CASE(reflect);
4244 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4246 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4249 if (crtc_state->uapi.async_flip)
4250 plane_ctl |= PLANE_CTL_ASYNC_FLIP;
4252 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4255 if (crtc_state->gamma_enable)
4256 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
4258 if (crtc_state->csc_enable)
4259 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
4264 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
4265 const struct intel_plane_state *plane_state)
4267 struct drm_i915_private *dev_priv =
4268 to_i915(plane_state->uapi.plane->dev);
4269 const struct drm_framebuffer *fb = plane_state->hw.fb;
4270 unsigned int rotation = plane_state->hw.rotation;
4271 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
4274 plane_ctl = PLANE_CTL_ENABLE;
4276 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
4277 plane_ctl |= skl_plane_ctl_alpha(plane_state);
4278 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
4280 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
4281 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
4283 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4284 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
4287 plane_ctl |= skl_plane_ctl_format(fb->format->format);
4288 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
4289 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
4291 if (INTEL_GEN(dev_priv) >= 10)
4292 plane_ctl |= cnl_plane_ctl_flip(rotation &
4293 DRM_MODE_REFLECT_MASK);
4295 if (key->flags & I915_SET_COLORKEY_DESTINATION)
4296 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
4297 else if (key->flags & I915_SET_COLORKEY_SOURCE)
4298 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
4303 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
4305 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4306 u32 plane_color_ctl = 0;
4308 if (INTEL_GEN(dev_priv) >= 11)
4309 return plane_color_ctl;
4311 if (crtc_state->gamma_enable)
4312 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
4314 if (crtc_state->csc_enable)
4315 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
4317 return plane_color_ctl;
4320 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
4321 const struct intel_plane_state *plane_state)
4323 struct drm_i915_private *dev_priv =
4324 to_i915(plane_state->uapi.plane->dev);
4325 const struct drm_framebuffer *fb = plane_state->hw.fb;
4326 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
4327 u32 plane_color_ctl = 0;
4329 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
4330 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
4332 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
4333 switch (plane_state->hw.color_encoding) {
4334 case DRM_COLOR_YCBCR_BT709:
4335 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
4337 case DRM_COLOR_YCBCR_BT2020:
4339 PLANE_COLOR_CSC_MODE_YUV2020_TO_RGB2020;
4343 PLANE_COLOR_CSC_MODE_YUV601_TO_RGB601;
4345 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4346 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
4347 } else if (fb->format->is_yuv) {
4348 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
4351 return plane_color_ctl;
4355 __intel_display_resume(struct drm_device *dev,
4356 struct drm_atomic_state *state,
4357 struct drm_modeset_acquire_ctx *ctx)
4359 struct drm_crtc_state *crtc_state;
4360 struct drm_crtc *crtc;
4363 intel_modeset_setup_hw_state(dev, ctx);
4364 intel_vga_redisable(to_i915(dev));
4370 * We've duplicated the state, pointers to the old state are invalid.
4372 * Don't attempt to use the old state until we commit the duplicated state.
4374 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
4376 * Force recalculation even if we restore
4377 * current state. With fast modeset this may not result
4378 * in a modeset when the state is compatible.
4380 crtc_state->mode_changed = true;
4383 /* ignore any reset values/BIOS leftovers in the WM registers */
4384 if (!HAS_GMCH(to_i915(dev)))
4385 to_intel_atomic_state(state)->skip_intermediate_wm = true;
4387 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4389 drm_WARN_ON(dev, ret == -EDEADLK);
4393 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
4395 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
4396 intel_has_gpu_reset(&dev_priv->gt));
4399 void intel_display_prepare_reset(struct drm_i915_private *dev_priv)
4401 struct drm_device *dev = &dev_priv->drm;
4402 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4403 struct drm_atomic_state *state;
4406 if (!HAS_DISPLAY(dev_priv))
4409 /* reset doesn't touch the display */
4410 if (!dev_priv->params.force_reset_modeset_test &&
4411 !gpu_reset_clobbers_display(dev_priv))
4414 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4415 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4416 smp_mb__after_atomic();
4417 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
4419 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
4420 drm_dbg_kms(&dev_priv->drm,
4421 "Modeset potentially stuck, unbreaking through wedging\n");
4422 intel_gt_set_wedged(&dev_priv->gt);
4426 * Need mode_config.mutex so that we don't
4427 * trample ongoing ->detect() and whatnot.
4429 mutex_lock(&dev->mode_config.mutex);
4430 drm_modeset_acquire_init(ctx, 0);
4432 ret = drm_modeset_lock_all_ctx(dev, ctx);
4433 if (ret != -EDEADLK)
4436 drm_modeset_backoff(ctx);
4439 * Disabling the crtcs gracefully seems nicer. Also the
4440 * g33 docs say we should at least disable all the planes.
4442 state = drm_atomic_helper_duplicate_state(dev, ctx);
4443 if (IS_ERR(state)) {
4444 ret = PTR_ERR(state);
4445 drm_err(&dev_priv->drm, "Duplicating state failed with %i\n",
4450 ret = drm_atomic_helper_disable_all(dev, ctx);
4452 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
4454 drm_atomic_state_put(state);
4458 dev_priv->modeset_restore_state = state;
4459 state->acquire_ctx = ctx;
4462 void intel_display_finish_reset(struct drm_i915_private *dev_priv)
4464 struct drm_device *dev = &dev_priv->drm;
4465 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4466 struct drm_atomic_state *state;
4469 if (!HAS_DISPLAY(dev_priv))
4472 /* reset doesn't touch the display */
4473 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
4476 state = fetch_and_zero(&dev_priv->modeset_restore_state);
4480 /* reset doesn't touch the display */
4481 if (!gpu_reset_clobbers_display(dev_priv)) {
4482 /* for testing only restore the display */
4483 ret = __intel_display_resume(dev, state, ctx);
4485 drm_err(&dev_priv->drm,
4486 "Restoring old state failed with %i\n", ret);
4489 * The display has been reset as well,
4490 * so need a full re-initialization.
4492 intel_pps_unlock_regs_wa(dev_priv);
4493 intel_modeset_init_hw(dev_priv);
4494 intel_init_clock_gating(dev_priv);
4495 intel_hpd_init(dev_priv);
4497 ret = __intel_display_resume(dev, state, ctx);
4499 drm_err(&dev_priv->drm,
4500 "Restoring old state failed with %i\n", ret);
4502 intel_hpd_poll_disable(dev_priv);
4505 drm_atomic_state_put(state);
4507 drm_modeset_drop_locks(ctx);
4508 drm_modeset_acquire_fini(ctx);
4509 mutex_unlock(&dev->mode_config.mutex);
4511 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4514 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4516 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4517 enum pipe pipe = crtc->pipe;
4520 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
4523 * Display WA #1153: icl
4524 * enable hardware to bypass the alpha math
4525 * and rounding for per-pixel values 00 and 0xff
4527 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4529 * Display WA # 1605353570: icl
4530 * Set the pixel rounding bit to 1 for allowing
4531 * passthrough of Frame buffer pixels unmodified
4534 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
4535 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
4538 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4540 struct drm_device *dev = crtc->base.dev;
4541 struct drm_i915_private *dev_priv = to_i915(dev);
4542 enum pipe pipe = crtc->pipe;
4546 /* enable normal train */
4547 reg = FDI_TX_CTL(pipe);
4548 temp = intel_de_read(dev_priv, reg);
4549 if (IS_IVYBRIDGE(dev_priv)) {
4550 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4551 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4553 temp &= ~FDI_LINK_TRAIN_NONE;
4554 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4556 intel_de_write(dev_priv, reg, temp);
4558 reg = FDI_RX_CTL(pipe);
4559 temp = intel_de_read(dev_priv, reg);
4560 if (HAS_PCH_CPT(dev_priv)) {
4561 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4562 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4564 temp &= ~FDI_LINK_TRAIN_NONE;
4565 temp |= FDI_LINK_TRAIN_NONE;
4567 intel_de_write(dev_priv, reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4569 /* wait one idle pattern time */
4570 intel_de_posting_read(dev_priv, reg);
4573 /* IVB wants error correction enabled */
4574 if (IS_IVYBRIDGE(dev_priv))
4575 intel_de_write(dev_priv, reg,
4576 intel_de_read(dev_priv, reg) | FDI_FS_ERRC_ENABLE | FDI_FE_ERRC_ENABLE);
4579 /* The FDI link training functions for ILK/Ibexpeak. */
4580 static void ilk_fdi_link_train(struct intel_crtc *crtc,
4581 const struct intel_crtc_state *crtc_state)
4583 struct drm_device *dev = crtc->base.dev;
4584 struct drm_i915_private *dev_priv = to_i915(dev);
4585 enum pipe pipe = crtc->pipe;
4589 /* FDI needs bits from pipe first */
4590 assert_pipe_enabled(dev_priv, crtc_state->cpu_transcoder);
4592 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4594 reg = FDI_RX_IMR(pipe);
4595 temp = intel_de_read(dev_priv, reg);
4596 temp &= ~FDI_RX_SYMBOL_LOCK;
4597 temp &= ~FDI_RX_BIT_LOCK;
4598 intel_de_write(dev_priv, reg, temp);
4599 intel_de_read(dev_priv, reg);
4602 /* enable CPU FDI TX and PCH FDI RX */
4603 reg = FDI_TX_CTL(pipe);
4604 temp = intel_de_read(dev_priv, reg);
4605 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4606 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4607 temp &= ~FDI_LINK_TRAIN_NONE;
4608 temp |= FDI_LINK_TRAIN_PATTERN_1;
4609 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
4611 reg = FDI_RX_CTL(pipe);
4612 temp = intel_de_read(dev_priv, reg);
4613 temp &= ~FDI_LINK_TRAIN_NONE;
4614 temp |= FDI_LINK_TRAIN_PATTERN_1;
4615 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
4617 intel_de_posting_read(dev_priv, reg);
4620 /* Ironlake workaround, enable clock pointer after FDI enable*/
4621 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
4622 FDI_RX_PHASE_SYNC_POINTER_OVR);
4623 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
4624 FDI_RX_PHASE_SYNC_POINTER_OVR | FDI_RX_PHASE_SYNC_POINTER_EN);
4626 reg = FDI_RX_IIR(pipe);
4627 for (tries = 0; tries < 5; tries++) {
4628 temp = intel_de_read(dev_priv, reg);
4629 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
4631 if ((temp & FDI_RX_BIT_LOCK)) {
4632 drm_dbg_kms(&dev_priv->drm, "FDI train 1 done.\n");
4633 intel_de_write(dev_priv, reg, temp | FDI_RX_BIT_LOCK);
4638 drm_err(&dev_priv->drm, "FDI train 1 fail!\n");
4641 reg = FDI_TX_CTL(pipe);
4642 temp = intel_de_read(dev_priv, reg);
4643 temp &= ~FDI_LINK_TRAIN_NONE;
4644 temp |= FDI_LINK_TRAIN_PATTERN_2;
4645 intel_de_write(dev_priv, reg, temp);
4647 reg = FDI_RX_CTL(pipe);
4648 temp = intel_de_read(dev_priv, reg);
4649 temp &= ~FDI_LINK_TRAIN_NONE;
4650 temp |= FDI_LINK_TRAIN_PATTERN_2;
4651 intel_de_write(dev_priv, reg, temp);
4653 intel_de_posting_read(dev_priv, reg);
4656 reg = FDI_RX_IIR(pipe);
4657 for (tries = 0; tries < 5; tries++) {
4658 temp = intel_de_read(dev_priv, reg);
4659 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
4661 if (temp & FDI_RX_SYMBOL_LOCK) {
4662 intel_de_write(dev_priv, reg,
4663 temp | FDI_RX_SYMBOL_LOCK);
4664 drm_dbg_kms(&dev_priv->drm, "FDI train 2 done.\n");
4669 drm_err(&dev_priv->drm, "FDI train 2 fail!\n");
4671 drm_dbg_kms(&dev_priv->drm, "FDI train done\n");
4675 static const int snb_b_fdi_train_param[] = {
4676 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4677 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4678 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4679 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4682 /* The FDI link training functions for SNB/Cougarpoint. */
4683 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4684 const struct intel_crtc_state *crtc_state)
4686 struct drm_device *dev = crtc->base.dev;
4687 struct drm_i915_private *dev_priv = to_i915(dev);
4688 enum pipe pipe = crtc->pipe;
4692 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4694 reg = FDI_RX_IMR(pipe);
4695 temp = intel_de_read(dev_priv, reg);
4696 temp &= ~FDI_RX_SYMBOL_LOCK;
4697 temp &= ~FDI_RX_BIT_LOCK;
4698 intel_de_write(dev_priv, reg, temp);
4700 intel_de_posting_read(dev_priv, reg);
4703 /* enable CPU FDI TX and PCH FDI RX */
4704 reg = FDI_TX_CTL(pipe);
4705 temp = intel_de_read(dev_priv, reg);
4706 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4707 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4708 temp &= ~FDI_LINK_TRAIN_NONE;
4709 temp |= FDI_LINK_TRAIN_PATTERN_1;
4710 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4712 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4713 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
4715 intel_de_write(dev_priv, FDI_RX_MISC(pipe),
4716 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4718 reg = FDI_RX_CTL(pipe);
4719 temp = intel_de_read(dev_priv, reg);
4720 if (HAS_PCH_CPT(dev_priv)) {
4721 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4722 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4724 temp &= ~FDI_LINK_TRAIN_NONE;
4725 temp |= FDI_LINK_TRAIN_PATTERN_1;
4727 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
4729 intel_de_posting_read(dev_priv, reg);
4732 for (i = 0; i < 4; i++) {
4733 reg = FDI_TX_CTL(pipe);
4734 temp = intel_de_read(dev_priv, reg);
4735 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4736 temp |= snb_b_fdi_train_param[i];
4737 intel_de_write(dev_priv, reg, temp);
4739 intel_de_posting_read(dev_priv, reg);
4742 for (retry = 0; retry < 5; retry++) {
4743 reg = FDI_RX_IIR(pipe);
4744 temp = intel_de_read(dev_priv, reg);
4745 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
4746 if (temp & FDI_RX_BIT_LOCK) {
4747 intel_de_write(dev_priv, reg,
4748 temp | FDI_RX_BIT_LOCK);
4749 drm_dbg_kms(&dev_priv->drm,
4750 "FDI train 1 done.\n");
4759 drm_err(&dev_priv->drm, "FDI train 1 fail!\n");
4762 reg = FDI_TX_CTL(pipe);
4763 temp = intel_de_read(dev_priv, reg);
4764 temp &= ~FDI_LINK_TRAIN_NONE;
4765 temp |= FDI_LINK_TRAIN_PATTERN_2;
4766 if (IS_GEN(dev_priv, 6)) {
4767 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4769 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4771 intel_de_write(dev_priv, reg, temp);
4773 reg = FDI_RX_CTL(pipe);
4774 temp = intel_de_read(dev_priv, reg);
4775 if (HAS_PCH_CPT(dev_priv)) {
4776 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4777 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4779 temp &= ~FDI_LINK_TRAIN_NONE;
4780 temp |= FDI_LINK_TRAIN_PATTERN_2;
4782 intel_de_write(dev_priv, reg, temp);
4784 intel_de_posting_read(dev_priv, reg);
4787 for (i = 0; i < 4; i++) {
4788 reg = FDI_TX_CTL(pipe);
4789 temp = intel_de_read(dev_priv, reg);
4790 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4791 temp |= snb_b_fdi_train_param[i];
4792 intel_de_write(dev_priv, reg, temp);
4794 intel_de_posting_read(dev_priv, reg);
4797 for (retry = 0; retry < 5; retry++) {
4798 reg = FDI_RX_IIR(pipe);
4799 temp = intel_de_read(dev_priv, reg);
4800 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
4801 if (temp & FDI_RX_SYMBOL_LOCK) {
4802 intel_de_write(dev_priv, reg,
4803 temp | FDI_RX_SYMBOL_LOCK);
4804 drm_dbg_kms(&dev_priv->drm,
4805 "FDI train 2 done.\n");
4814 drm_err(&dev_priv->drm, "FDI train 2 fail!\n");
4816 drm_dbg_kms(&dev_priv->drm, "FDI train done.\n");
4819 /* Manual link training for Ivy Bridge A0 parts */
4820 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4821 const struct intel_crtc_state *crtc_state)
4823 struct drm_device *dev = crtc->base.dev;
4824 struct drm_i915_private *dev_priv = to_i915(dev);
4825 enum pipe pipe = crtc->pipe;
4829 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4831 reg = FDI_RX_IMR(pipe);
4832 temp = intel_de_read(dev_priv, reg);
4833 temp &= ~FDI_RX_SYMBOL_LOCK;
4834 temp &= ~FDI_RX_BIT_LOCK;
4835 intel_de_write(dev_priv, reg, temp);
4837 intel_de_posting_read(dev_priv, reg);
4840 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR before link train 0x%x\n",
4841 intel_de_read(dev_priv, FDI_RX_IIR(pipe)));
4843 /* Try each vswing and preemphasis setting twice before moving on */
4844 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4845 /* disable first in case we need to retry */
4846 reg = FDI_TX_CTL(pipe);
4847 temp = intel_de_read(dev_priv, reg);
4848 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4849 temp &= ~FDI_TX_ENABLE;
4850 intel_de_write(dev_priv, reg, temp);
4852 reg = FDI_RX_CTL(pipe);
4853 temp = intel_de_read(dev_priv, reg);
4854 temp &= ~FDI_LINK_TRAIN_AUTO;
4855 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4856 temp &= ~FDI_RX_ENABLE;
4857 intel_de_write(dev_priv, reg, temp);
4859 /* enable CPU FDI TX and PCH FDI RX */
4860 reg = FDI_TX_CTL(pipe);
4861 temp = intel_de_read(dev_priv, reg);
4862 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4863 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4864 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4865 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4866 temp |= snb_b_fdi_train_param[j/2];
4867 temp |= FDI_COMPOSITE_SYNC;
4868 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
4870 intel_de_write(dev_priv, FDI_RX_MISC(pipe),
4871 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4873 reg = FDI_RX_CTL(pipe);
4874 temp = intel_de_read(dev_priv, reg);
4875 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4876 temp |= FDI_COMPOSITE_SYNC;
4877 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
4879 intel_de_posting_read(dev_priv, reg);
4880 udelay(1); /* should be 0.5us */
4882 for (i = 0; i < 4; i++) {
4883 reg = FDI_RX_IIR(pipe);
4884 temp = intel_de_read(dev_priv, reg);
4885 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
4887 if (temp & FDI_RX_BIT_LOCK ||
4888 (intel_de_read(dev_priv, reg) & FDI_RX_BIT_LOCK)) {
4889 intel_de_write(dev_priv, reg,
4890 temp | FDI_RX_BIT_LOCK);
4891 drm_dbg_kms(&dev_priv->drm,
4892 "FDI train 1 done, level %i.\n",
4896 udelay(1); /* should be 0.5us */
4899 drm_dbg_kms(&dev_priv->drm,
4900 "FDI train 1 fail on vswing %d\n", j / 2);
4905 reg = FDI_TX_CTL(pipe);
4906 temp = intel_de_read(dev_priv, reg);
4907 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4908 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4909 intel_de_write(dev_priv, reg, temp);
4911 reg = FDI_RX_CTL(pipe);
4912 temp = intel_de_read(dev_priv, reg);
4913 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4914 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4915 intel_de_write(dev_priv, reg, temp);
4917 intel_de_posting_read(dev_priv, reg);
4918 udelay(2); /* should be 1.5us */
4920 for (i = 0; i < 4; i++) {
4921 reg = FDI_RX_IIR(pipe);
4922 temp = intel_de_read(dev_priv, reg);
4923 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
4925 if (temp & FDI_RX_SYMBOL_LOCK ||
4926 (intel_de_read(dev_priv, reg) & FDI_RX_SYMBOL_LOCK)) {
4927 intel_de_write(dev_priv, reg,
4928 temp | FDI_RX_SYMBOL_LOCK);
4929 drm_dbg_kms(&dev_priv->drm,
4930 "FDI train 2 done, level %i.\n",
4934 udelay(2); /* should be 1.5us */
4937 drm_dbg_kms(&dev_priv->drm,
4938 "FDI train 2 fail on vswing %d\n", j / 2);
4942 drm_dbg_kms(&dev_priv->drm, "FDI train done.\n");
4945 static void ilk_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4947 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
4948 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4949 enum pipe pipe = intel_crtc->pipe;
4953 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4954 reg = FDI_RX_CTL(pipe);
4955 temp = intel_de_read(dev_priv, reg);
4956 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4957 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4958 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4959 intel_de_write(dev_priv, reg, temp | FDI_RX_PLL_ENABLE);
4961 intel_de_posting_read(dev_priv, reg);
4964 /* Switch from Rawclk to PCDclk */
4965 temp = intel_de_read(dev_priv, reg);
4966 intel_de_write(dev_priv, reg, temp | FDI_PCDCLK);
4968 intel_de_posting_read(dev_priv, reg);
4971 /* Enable CPU FDI TX PLL, always on for Ironlake */
4972 reg = FDI_TX_CTL(pipe);
4973 temp = intel_de_read(dev_priv, reg);
4974 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4975 intel_de_write(dev_priv, reg, temp | FDI_TX_PLL_ENABLE);
4977 intel_de_posting_read(dev_priv, reg);
4982 static void ilk_fdi_pll_disable(struct intel_crtc *intel_crtc)
4984 struct drm_device *dev = intel_crtc->base.dev;
4985 struct drm_i915_private *dev_priv = to_i915(dev);
4986 enum pipe pipe = intel_crtc->pipe;
4990 /* Switch from PCDclk to Rawclk */
4991 reg = FDI_RX_CTL(pipe);
4992 temp = intel_de_read(dev_priv, reg);
4993 intel_de_write(dev_priv, reg, temp & ~FDI_PCDCLK);
4995 /* Disable CPU FDI TX PLL */
4996 reg = FDI_TX_CTL(pipe);
4997 temp = intel_de_read(dev_priv, reg);
4998 intel_de_write(dev_priv, reg, temp & ~FDI_TX_PLL_ENABLE);
5000 intel_de_posting_read(dev_priv, reg);
5003 reg = FDI_RX_CTL(pipe);
5004 temp = intel_de_read(dev_priv, reg);
5005 intel_de_write(dev_priv, reg, temp & ~FDI_RX_PLL_ENABLE);
5007 /* Wait for the clocks to turn off. */
5008 intel_de_posting_read(dev_priv, reg);
5012 static void ilk_fdi_disable(struct intel_crtc *crtc)
5014 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5015 enum pipe pipe = crtc->pipe;
5019 /* disable CPU FDI tx and PCH FDI rx */
5020 reg = FDI_TX_CTL(pipe);
5021 temp = intel_de_read(dev_priv, reg);
5022 intel_de_write(dev_priv, reg, temp & ~FDI_TX_ENABLE);
5023 intel_de_posting_read(dev_priv, reg);
5025 reg = FDI_RX_CTL(pipe);
5026 temp = intel_de_read(dev_priv, reg);
5027 temp &= ~(0x7 << 16);
5028 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5029 intel_de_write(dev_priv, reg, temp & ~FDI_RX_ENABLE);
5031 intel_de_posting_read(dev_priv, reg);
5034 /* Ironlake workaround, disable clock pointer after downing FDI */
5035 if (HAS_PCH_IBX(dev_priv))
5036 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
5037 FDI_RX_PHASE_SYNC_POINTER_OVR);
5039 /* still set train pattern 1 */
5040 reg = FDI_TX_CTL(pipe);
5041 temp = intel_de_read(dev_priv, reg);
5042 temp &= ~FDI_LINK_TRAIN_NONE;
5043 temp |= FDI_LINK_TRAIN_PATTERN_1;
5044 intel_de_write(dev_priv, reg, temp);
5046 reg = FDI_RX_CTL(pipe);
5047 temp = intel_de_read(dev_priv, reg);
5048 if (HAS_PCH_CPT(dev_priv)) {
5049 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5050 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5052 temp &= ~FDI_LINK_TRAIN_NONE;
5053 temp |= FDI_LINK_TRAIN_PATTERN_1;
5055 /* BPC in FDI rx is consistent with that in PIPECONF */
5056 temp &= ~(0x07 << 16);
5057 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5058 intel_de_write(dev_priv, reg, temp);
5060 intel_de_posting_read(dev_priv, reg);
5064 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
5066 struct drm_crtc *crtc;
5069 drm_for_each_crtc(crtc, &dev_priv->drm) {
5070 struct drm_crtc_commit *commit;
5071 spin_lock(&crtc->commit_lock);
5072 commit = list_first_entry_or_null(&crtc->commit_list,
5073 struct drm_crtc_commit, commit_entry);
5074 cleanup_done = commit ?
5075 try_wait_for_completion(&commit->cleanup_done) : true;
5076 spin_unlock(&crtc->commit_lock);
5081 drm_crtc_wait_one_vblank(crtc);
5089 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
5093 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_GATE);
5095 mutex_lock(&dev_priv->sb_lock);
5097 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5098 temp |= SBI_SSCCTL_DISABLE;
5099 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5101 mutex_unlock(&dev_priv->sb_lock);
5104 /* Program iCLKIP clock to the desired frequency */
5105 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
5107 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5108 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5109 int clock = crtc_state->hw.adjusted_mode.crtc_clock;
5110 u32 divsel, phaseinc, auxdiv, phasedir = 0;
5113 lpt_disable_iclkip(dev_priv);
5115 /* The iCLK virtual clock root frequency is in MHz,
5116 * but the adjusted_mode->crtc_clock in in KHz. To get the
5117 * divisors, it is necessary to divide one by another, so we
5118 * convert the virtual clock precision to KHz here for higher
5121 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
5122 u32 iclk_virtual_root_freq = 172800 * 1000;
5123 u32 iclk_pi_range = 64;
5124 u32 desired_divisor;
5126 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5128 divsel = (desired_divisor / iclk_pi_range) - 2;
5129 phaseinc = desired_divisor % iclk_pi_range;
5132 * Near 20MHz is a corner case which is
5133 * out of range for the 7-bit divisor
5139 /* This should not happen with any sane values */
5140 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5141 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5142 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIR(phasedir) &
5143 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5145 drm_dbg_kms(&dev_priv->drm,
5146 "iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5147 clock, auxdiv, divsel, phasedir, phaseinc);
5149 mutex_lock(&dev_priv->sb_lock);
5151 /* Program SSCDIVINTPHASE6 */
5152 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5153 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5154 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5155 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5156 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5157 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5158 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5159 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5161 /* Program SSCAUXDIV */
5162 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5163 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5164 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5165 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5167 /* Enable modulator and associated divider */
5168 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5169 temp &= ~SBI_SSCCTL_DISABLE;
5170 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5172 mutex_unlock(&dev_priv->sb_lock);
5174 /* Wait for initialization time */
5177 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5180 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5182 u32 divsel, phaseinc, auxdiv;
5183 u32 iclk_virtual_root_freq = 172800 * 1000;
5184 u32 iclk_pi_range = 64;
5185 u32 desired_divisor;
5188 if ((intel_de_read(dev_priv, PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5191 mutex_lock(&dev_priv->sb_lock);
5193 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5194 if (temp & SBI_SSCCTL_DISABLE) {
5195 mutex_unlock(&dev_priv->sb_lock);
5199 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5200 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5201 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5202 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5203 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5205 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5206 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5207 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5209 mutex_unlock(&dev_priv->sb_lock);
5211 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5213 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5214 desired_divisor << auxdiv);
5217 static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5218 enum pipe pch_transcoder)
5220 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5221 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5222 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5224 intel_de_write(dev_priv, PCH_TRANS_HTOTAL(pch_transcoder),
5225 intel_de_read(dev_priv, HTOTAL(cpu_transcoder)));
5226 intel_de_write(dev_priv, PCH_TRANS_HBLANK(pch_transcoder),
5227 intel_de_read(dev_priv, HBLANK(cpu_transcoder)));
5228 intel_de_write(dev_priv, PCH_TRANS_HSYNC(pch_transcoder),
5229 intel_de_read(dev_priv, HSYNC(cpu_transcoder)));
5231 intel_de_write(dev_priv, PCH_TRANS_VTOTAL(pch_transcoder),
5232 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
5233 intel_de_write(dev_priv, PCH_TRANS_VBLANK(pch_transcoder),
5234 intel_de_read(dev_priv, VBLANK(cpu_transcoder)));
5235 intel_de_write(dev_priv, PCH_TRANS_VSYNC(pch_transcoder),
5236 intel_de_read(dev_priv, VSYNC(cpu_transcoder)));
5237 intel_de_write(dev_priv, PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5238 intel_de_read(dev_priv, VSYNCSHIFT(cpu_transcoder)));
5241 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5245 temp = intel_de_read(dev_priv, SOUTH_CHICKEN1);
5246 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5249 drm_WARN_ON(&dev_priv->drm,
5250 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_B)) &
5252 drm_WARN_ON(&dev_priv->drm,
5253 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_C)) &
5256 temp &= ~FDI_BC_BIFURCATION_SELECT;
5258 temp |= FDI_BC_BIFURCATION_SELECT;
5260 drm_dbg_kms(&dev_priv->drm, "%sabling fdi C rx\n",
5261 enable ? "en" : "dis");
5262 intel_de_write(dev_priv, SOUTH_CHICKEN1, temp);
5263 intel_de_posting_read(dev_priv, SOUTH_CHICKEN1);
5266 static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5268 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5269 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5271 switch (crtc->pipe) {
5275 if (crtc_state->fdi_lanes > 2)
5276 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5278 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5282 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5291 * Finds the encoder associated with the given CRTC. This can only be
5292 * used when we know that the CRTC isn't feeding multiple encoders!
5294 static struct intel_encoder *
5295 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5296 const struct intel_crtc_state *crtc_state)
5298 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5299 const struct drm_connector_state *connector_state;
5300 const struct drm_connector *connector;
5301 struct intel_encoder *encoder = NULL;
5302 int num_encoders = 0;
5305 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5306 if (connector_state->crtc != &crtc->base)
5309 encoder = to_intel_encoder(connector_state->best_encoder);
5313 drm_WARN(encoder->base.dev, num_encoders != 1,
5314 "%d encoders for pipe %c\n",
5315 num_encoders, pipe_name(crtc->pipe));
5321 * Enable PCH resources required for PCH ports:
5323 * - FDI training & RX/TX
5324 * - update transcoder timings
5325 * - DP transcoding bits
5328 static void ilk_pch_enable(const struct intel_atomic_state *state,
5329 const struct intel_crtc_state *crtc_state)
5331 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5332 struct drm_device *dev = crtc->base.dev;
5333 struct drm_i915_private *dev_priv = to_i915(dev);
5334 enum pipe pipe = crtc->pipe;
5337 assert_pch_transcoder_disabled(dev_priv, pipe);
5339 if (IS_IVYBRIDGE(dev_priv))
5340 ivb_update_fdi_bc_bifurcation(crtc_state);
5342 /* Write the TU size bits before fdi link training, so that error
5343 * detection works. */
5344 intel_de_write(dev_priv, FDI_RX_TUSIZE1(pipe),
5345 intel_de_read(dev_priv, PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5347 /* For PCH output, training FDI link */
5348 dev_priv->display.fdi_link_train(crtc, crtc_state);
5350 /* We need to program the right clock selection before writing the pixel
5351 * mutliplier into the DPLL. */
5352 if (HAS_PCH_CPT(dev_priv)) {
5355 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
5356 temp |= TRANS_DPLL_ENABLE(pipe);
5357 sel = TRANS_DPLLB_SEL(pipe);
5358 if (crtc_state->shared_dpll ==
5359 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5363 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
5366 /* XXX: pch pll's can be enabled any time before we enable the PCH
5367 * transcoder, and we actually should do this to not upset any PCH
5368 * transcoder that already use the clock when we share it.
5370 * Note that enable_shared_dpll tries to do the right thing, but
5371 * get_shared_dpll unconditionally resets the pll - we need that to have
5372 * the right LVDS enable sequence. */
5373 intel_enable_shared_dpll(crtc_state);
5375 /* set transcoder timing, panel must allow it */
5376 assert_panel_unlocked(dev_priv, pipe);
5377 ilk_pch_transcoder_set_timings(crtc_state, pipe);
5379 intel_fdi_normal_train(crtc);
5381 /* For PCH DP, enable TRANS_DP_CTL */
5382 if (HAS_PCH_CPT(dev_priv) &&
5383 intel_crtc_has_dp_encoder(crtc_state)) {
5384 const struct drm_display_mode *adjusted_mode =
5385 &crtc_state->hw.adjusted_mode;
5386 u32 bpc = (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5387 i915_reg_t reg = TRANS_DP_CTL(pipe);
5390 temp = intel_de_read(dev_priv, reg);
5391 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5392 TRANS_DP_SYNC_MASK |
5394 temp |= TRANS_DP_OUTPUT_ENABLE;
5395 temp |= bpc << 9; /* same format but at 11:9 */
5397 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5398 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5399 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5400 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5402 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5403 drm_WARN_ON(dev, port < PORT_B || port > PORT_D);
5404 temp |= TRANS_DP_PORT_SEL(port);
5406 intel_de_write(dev_priv, reg, temp);
5409 ilk_enable_pch_transcoder(crtc_state);
5412 void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
5414 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5415 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5416 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5418 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5420 lpt_program_iclkip(crtc_state);
5422 /* Set transcoder timing. */
5423 ilk_pch_transcoder_set_timings(crtc_state, PIPE_A);
5425 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5428 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
5431 i915_reg_t dslreg = PIPEDSL(pipe);
5434 temp = intel_de_read(dev_priv, dslreg);
5436 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) {
5437 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5))
5438 drm_err(&dev_priv->drm,
5439 "mode set failed: pipe %c stuck\n",
5445 * The hardware phase 0.0 refers to the center of the pixel.
5446 * We want to start from the top/left edge which is phase
5447 * -0.5. That matches how the hardware calculates the scaling
5448 * factors (from top-left of the first pixel to bottom-right
5449 * of the last pixel, as opposed to the pixel centers).
5451 * For 4:2:0 subsampled chroma planes we obviously have to
5452 * adjust that so that the chroma sample position lands in
5455 * Note that for packed YCbCr 4:2:2 formats there is no way to
5456 * control chroma siting. The hardware simply replicates the
5457 * chroma samples for both of the luma samples, and thus we don't
5458 * actually get the expected MPEG2 chroma siting convention :(
5459 * The same behaviour is observed on pre-SKL platforms as well.
5461 * Theory behind the formula (note that we ignore sub-pixel
5462 * source coordinates):
5463 * s = source sample position
5464 * d = destination sample position
5469 * | | 1.5 (initial phase)
5477 * | -0.375 (initial phase)
5484 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5486 int phase = -0x8000;
5490 phase += (sub - 1) * 0x8000 / sub;
5492 phase += scale / (2 * sub);
5495 * Hardware initial phase limited to [-0.5:1.5].
5496 * Since the max hardware scale factor is 3.0, we
5497 * should never actually excdeed 1.0 here.
5499 WARN_ON(phase < -0x8000 || phase > 0x18000);
5502 phase = 0x10000 + phase;
5504 trip = PS_PHASE_TRIP;
5506 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5509 #define SKL_MIN_SRC_W 8
5510 #define SKL_MAX_SRC_W 4096
5511 #define SKL_MIN_SRC_H 8
5512 #define SKL_MAX_SRC_H 4096
5513 #define SKL_MIN_DST_W 8
5514 #define SKL_MAX_DST_W 4096
5515 #define SKL_MIN_DST_H 8
5516 #define SKL_MAX_DST_H 4096
5517 #define ICL_MAX_SRC_W 5120
5518 #define ICL_MAX_SRC_H 4096
5519 #define ICL_MAX_DST_W 5120
5520 #define ICL_MAX_DST_H 4096
5521 #define SKL_MIN_YUV_420_SRC_W 16
5522 #define SKL_MIN_YUV_420_SRC_H 16
5525 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5526 unsigned int scaler_user, int *scaler_id,
5527 int src_w, int src_h, int dst_w, int dst_h,
5528 const struct drm_format_info *format,
5529 u64 modifier, bool need_scaler)
5531 struct intel_crtc_scaler_state *scaler_state =
5532 &crtc_state->scaler_state;
5533 struct intel_crtc *intel_crtc =
5534 to_intel_crtc(crtc_state->uapi.crtc);
5535 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5536 const struct drm_display_mode *adjusted_mode =
5537 &crtc_state->hw.adjusted_mode;
5540 * Src coordinates are already rotated by 270 degrees for
5541 * the 90/270 degree plane rotation cases (to match the
5542 * GTT mapping), hence no need to account for rotation here.
5544 if (src_w != dst_w || src_h != dst_h)
5548 * Scaling/fitting not supported in IF-ID mode in GEN9+
5549 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5550 * Once NV12 is enabled, handle it here while allocating scaler
5553 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->hw.enable &&
5554 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5555 drm_dbg_kms(&dev_priv->drm,
5556 "Pipe/Plane scaling not supported with IF-ID mode\n");
5561 * if plane is being disabled or scaler is no more required or force detach
5562 * - free scaler binded to this plane/crtc
5563 * - in order to do this, update crtc->scaler_usage
5565 * Here scaler state in crtc_state is set free so that
5566 * scaler can be assigned to other user. Actual register
5567 * update to free the scaler is done in plane/panel-fit programming.
5568 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5570 if (force_detach || !need_scaler) {
5571 if (*scaler_id >= 0) {
5572 scaler_state->scaler_users &= ~(1 << scaler_user);
5573 scaler_state->scalers[*scaler_id].in_use = 0;
5575 drm_dbg_kms(&dev_priv->drm,
5576 "scaler_user index %u.%u: "
5577 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5578 intel_crtc->pipe, scaler_user, *scaler_id,
5579 scaler_state->scaler_users);
5585 if (format && intel_format_info_is_yuv_semiplanar(format, modifier) &&
5586 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5587 drm_dbg_kms(&dev_priv->drm,
5588 "Planar YUV: src dimensions not met\n");
5593 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5594 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5595 (INTEL_GEN(dev_priv) >= 11 &&
5596 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5597 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5598 (INTEL_GEN(dev_priv) < 11 &&
5599 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5600 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5601 drm_dbg_kms(&dev_priv->drm,
5602 "scaler_user index %u.%u: src %ux%u dst %ux%u "
5603 "size is out of scaler range\n",
5604 intel_crtc->pipe, scaler_user, src_w, src_h,
5609 /* mark this plane as a scaler user in crtc_state */
5610 scaler_state->scaler_users |= (1 << scaler_user);
5611 drm_dbg_kms(&dev_priv->drm, "scaler_user index %u.%u: "
5612 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5613 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5614 scaler_state->scaler_users);
5619 static int skl_update_scaler_crtc(struct intel_crtc_state *crtc_state)
5621 const struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
5624 if (crtc_state->pch_pfit.enabled) {
5625 width = drm_rect_width(&crtc_state->pch_pfit.dst);
5626 height = drm_rect_height(&crtc_state->pch_pfit.dst);
5628 width = pipe_mode->crtc_hdisplay;
5629 height = pipe_mode->crtc_vdisplay;
5631 return skl_update_scaler(crtc_state, !crtc_state->hw.active,
5633 &crtc_state->scaler_state.scaler_id,
5634 crtc_state->pipe_src_w, crtc_state->pipe_src_h,
5635 width, height, NULL, 0,
5636 crtc_state->pch_pfit.enabled);
5640 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5641 * @crtc_state: crtc's scaler state
5642 * @plane_state: atomic plane state to update
5645 * 0 - scaler_usage updated successfully
5646 * error - requested scaling cannot be supported or other error condition
5648 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5649 struct intel_plane_state *plane_state)
5651 struct intel_plane *intel_plane =
5652 to_intel_plane(plane_state->uapi.plane);
5653 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5654 struct drm_framebuffer *fb = plane_state->hw.fb;
5656 bool force_detach = !fb || !plane_state->uapi.visible;
5657 bool need_scaler = false;
5659 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5660 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5661 fb && intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
5664 ret = skl_update_scaler(crtc_state, force_detach,
5665 drm_plane_index(&intel_plane->base),
5666 &plane_state->scaler_id,
5667 drm_rect_width(&plane_state->uapi.src) >> 16,
5668 drm_rect_height(&plane_state->uapi.src) >> 16,
5669 drm_rect_width(&plane_state->uapi.dst),
5670 drm_rect_height(&plane_state->uapi.dst),
5671 fb ? fb->format : NULL,
5672 fb ? fb->modifier : 0,
5675 if (ret || plane_state->scaler_id < 0)
5678 /* check colorkey */
5679 if (plane_state->ckey.flags) {
5680 drm_dbg_kms(&dev_priv->drm,
5681 "[PLANE:%d:%s] scaling with color key not allowed",
5682 intel_plane->base.base.id,
5683 intel_plane->base.name);
5687 /* Check src format */
5688 switch (fb->format->format) {
5689 case DRM_FORMAT_RGB565:
5690 case DRM_FORMAT_XBGR8888:
5691 case DRM_FORMAT_XRGB8888:
5692 case DRM_FORMAT_ABGR8888:
5693 case DRM_FORMAT_ARGB8888:
5694 case DRM_FORMAT_XRGB2101010:
5695 case DRM_FORMAT_XBGR2101010:
5696 case DRM_FORMAT_ARGB2101010:
5697 case DRM_FORMAT_ABGR2101010:
5698 case DRM_FORMAT_YUYV:
5699 case DRM_FORMAT_YVYU:
5700 case DRM_FORMAT_UYVY:
5701 case DRM_FORMAT_VYUY:
5702 case DRM_FORMAT_NV12:
5703 case DRM_FORMAT_XYUV8888:
5704 case DRM_FORMAT_P010:
5705 case DRM_FORMAT_P012:
5706 case DRM_FORMAT_P016:
5707 case DRM_FORMAT_Y210:
5708 case DRM_FORMAT_Y212:
5709 case DRM_FORMAT_Y216:
5710 case DRM_FORMAT_XVYU2101010:
5711 case DRM_FORMAT_XVYU12_16161616:
5712 case DRM_FORMAT_XVYU16161616:
5714 case DRM_FORMAT_XBGR16161616F:
5715 case DRM_FORMAT_ABGR16161616F:
5716 case DRM_FORMAT_XRGB16161616F:
5717 case DRM_FORMAT_ARGB16161616F:
5718 if (INTEL_GEN(dev_priv) >= 11)
5722 drm_dbg_kms(&dev_priv->drm,
5723 "[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5724 intel_plane->base.base.id, intel_plane->base.name,
5725 fb->base.id, fb->format->format);
5732 void skl_scaler_disable(const struct intel_crtc_state *old_crtc_state)
5734 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
5737 for (i = 0; i < crtc->num_scalers; i++)
5738 skl_detach_scaler(crtc, i);
5741 static int cnl_coef_tap(int i)
5746 static u16 cnl_nearest_filter_coef(int t)
5748 return t == 3 ? 0x0800 : 0x3000;
5752 * Theory behind setting nearest-neighbor integer scaling:
5754 * 17 phase of 7 taps requires 119 coefficients in 60 dwords per set.
5755 * The letter represents the filter tap (D is the center tap) and the number
5756 * represents the coefficient set for a phase (0-16).
5758 * +------------+------------------------+------------------------+
5759 * |Index value | Data value coeffient 1 | Data value coeffient 2 |
5760 * +------------+------------------------+------------------------+
5762 * +------------+------------------------+------------------------+
5764 * +------------+------------------------+------------------------+
5766 * +------------+------------------------+------------------------+
5768 * +------------+------------------------+------------------------+
5770 * +------------+------------------------+------------------------+
5771 * | ... | ... | ... |
5772 * +------------+------------------------+------------------------+
5773 * | 38h | B16 | A16 |
5774 * +------------+------------------------+------------------------+
5775 * | 39h | D16 | C16 |
5776 * +------------+------------------------+------------------------+
5777 * | 3Ah | F16 | C16 |
5778 * +------------+------------------------+------------------------+
5779 * | 3Bh | Reserved | G16 |
5780 * +------------+------------------------+------------------------+
5782 * To enable nearest-neighbor scaling: program scaler coefficents with
5783 * the center tap (Dxx) values set to 1 and all other values set to 0 as per
5784 * SCALER_COEFFICIENT_FORMAT
5788 static void cnl_program_nearest_filter_coefs(struct drm_i915_private *dev_priv,
5789 enum pipe pipe, int id, int set)
5793 intel_de_write_fw(dev_priv, CNL_PS_COEF_INDEX_SET(pipe, id, set),
5794 PS_COEE_INDEX_AUTO_INC);
5796 for (i = 0; i < 17 * 7; i += 2) {
5800 t = cnl_coef_tap(i);
5801 tmp = cnl_nearest_filter_coef(t);
5803 t = cnl_coef_tap(i + 1);
5804 tmp |= cnl_nearest_filter_coef(t) << 16;
5806 intel_de_write_fw(dev_priv, CNL_PS_COEF_DATA_SET(pipe, id, set),
5810 intel_de_write_fw(dev_priv, CNL_PS_COEF_INDEX_SET(pipe, id, set), 0);
5813 u32 skl_scaler_get_filter_select(enum drm_scaling_filter filter, int set)
5815 if (filter == DRM_SCALING_FILTER_NEAREST_NEIGHBOR) {
5816 return (PS_FILTER_PROGRAMMED |
5817 PS_Y_VERT_FILTER_SELECT(set) |
5818 PS_Y_HORZ_FILTER_SELECT(set) |
5819 PS_UV_VERT_FILTER_SELECT(set) |
5820 PS_UV_HORZ_FILTER_SELECT(set));
5823 return PS_FILTER_MEDIUM;
5826 void skl_scaler_setup_filter(struct drm_i915_private *dev_priv, enum pipe pipe,
5827 int id, int set, enum drm_scaling_filter filter)
5830 case DRM_SCALING_FILTER_DEFAULT:
5832 case DRM_SCALING_FILTER_NEAREST_NEIGHBOR:
5833 cnl_program_nearest_filter_coefs(dev_priv, pipe, id, set);
5836 MISSING_CASE(filter);
5840 static void skl_pfit_enable(const struct intel_crtc_state *crtc_state)
5842 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5843 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5844 const struct intel_crtc_scaler_state *scaler_state =
5845 &crtc_state->scaler_state;
5846 struct drm_rect src = {
5847 .x2 = crtc_state->pipe_src_w << 16,
5848 .y2 = crtc_state->pipe_src_h << 16,
5850 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
5851 u16 uv_rgb_hphase, uv_rgb_vphase;
5852 enum pipe pipe = crtc->pipe;
5853 int width = drm_rect_width(dst);
5854 int height = drm_rect_height(dst);
5858 unsigned long irqflags;
5862 if (!crtc_state->pch_pfit.enabled)
5865 if (drm_WARN_ON(&dev_priv->drm,
5866 crtc_state->scaler_state.scaler_id < 0))
5869 hscale = drm_rect_calc_hscale(&src, dst, 0, INT_MAX);
5870 vscale = drm_rect_calc_vscale(&src, dst, 0, INT_MAX);
5872 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5873 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5875 id = scaler_state->scaler_id;
5877 ps_ctrl = skl_scaler_get_filter_select(crtc_state->hw.scaling_filter, 0);
5878 ps_ctrl |= PS_SCALER_EN | scaler_state->scalers[id].mode;
5880 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
5882 skl_scaler_setup_filter(dev_priv, pipe, id, 0,
5883 crtc_state->hw.scaling_filter);
5885 intel_de_write_fw(dev_priv, SKL_PS_CTRL(pipe, id), ps_ctrl);
5887 intel_de_write_fw(dev_priv, SKL_PS_VPHASE(pipe, id),
5888 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5889 intel_de_write_fw(dev_priv, SKL_PS_HPHASE(pipe, id),
5890 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5891 intel_de_write_fw(dev_priv, SKL_PS_WIN_POS(pipe, id),
5893 intel_de_write_fw(dev_priv, SKL_PS_WIN_SZ(pipe, id),
5894 width << 16 | height);
5896 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
5899 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
5901 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5902 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5903 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
5904 enum pipe pipe = crtc->pipe;
5905 int width = drm_rect_width(dst);
5906 int height = drm_rect_height(dst);
5910 if (!crtc_state->pch_pfit.enabled)
5913 /* Force use of hard-coded filter coefficients
5914 * as some pre-programmed values are broken,
5917 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5918 intel_de_write(dev_priv, PF_CTL(pipe), PF_ENABLE |
5919 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
5921 intel_de_write(dev_priv, PF_CTL(pipe), PF_ENABLE |
5923 intel_de_write(dev_priv, PF_WIN_POS(pipe), x << 16 | y);
5924 intel_de_write(dev_priv, PF_WIN_SZ(pipe), width << 16 | height);
5927 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5929 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5930 struct drm_device *dev = crtc->base.dev;
5931 struct drm_i915_private *dev_priv = to_i915(dev);
5933 if (!crtc_state->ips_enabled)
5937 * We can only enable IPS after we enable a plane and wait for a vblank
5938 * This function is called from post_plane_update, which is run after
5941 drm_WARN_ON(dev, !(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5943 if (IS_BROADWELL(dev_priv)) {
5944 drm_WARN_ON(dev, sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5945 IPS_ENABLE | IPS_PCODE_CONTROL));
5946 /* Quoting Art Runyan: "its not safe to expect any particular
5947 * value in IPS_CTL bit 31 after enabling IPS through the
5948 * mailbox." Moreover, the mailbox may return a bogus state,
5949 * so we need to just enable it and continue on.
5952 intel_de_write(dev_priv, IPS_CTL, IPS_ENABLE);
5953 /* The bit only becomes 1 in the next vblank, so this wait here
5954 * is essentially intel_wait_for_vblank. If we don't have this
5955 * and don't wait for vblanks until the end of crtc_enable, then
5956 * the HW state readout code will complain that the expected
5957 * IPS_CTL value is not the one we read. */
5958 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
5959 drm_err(&dev_priv->drm,
5960 "Timed out waiting for IPS enable\n");
5964 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5966 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5967 struct drm_device *dev = crtc->base.dev;
5968 struct drm_i915_private *dev_priv = to_i915(dev);
5970 if (!crtc_state->ips_enabled)
5973 if (IS_BROADWELL(dev_priv)) {
5975 sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5977 * Wait for PCODE to finish disabling IPS. The BSpec specified
5978 * 42ms timeout value leads to occasional timeouts so use 100ms
5981 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
5982 drm_err(&dev_priv->drm,
5983 "Timed out waiting for IPS disable\n");
5985 intel_de_write(dev_priv, IPS_CTL, 0);
5986 intel_de_posting_read(dev_priv, IPS_CTL);
5989 /* We need to wait for a vblank before we can disable the plane. */
5990 intel_wait_for_vblank(dev_priv, crtc->pipe);
5993 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5995 if (intel_crtc->overlay)
5996 (void) intel_overlay_switch_off(intel_crtc->overlay);
5998 /* Let userspace switch the overlay on again. In most cases userspace
5999 * has to recompute where to put it anyway.
6003 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
6004 const struct intel_crtc_state *new_crtc_state)
6006 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6007 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6009 if (!old_crtc_state->ips_enabled)
6012 if (intel_crtc_needs_modeset(new_crtc_state))
6016 * Workaround : Do not read or write the pipe palette/gamma data while
6017 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6019 * Disable IPS before we program the LUT.
6021 if (IS_HASWELL(dev_priv) &&
6022 (new_crtc_state->uapi.color_mgmt_changed ||
6023 new_crtc_state->update_pipe) &&
6024 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6027 return !new_crtc_state->ips_enabled;
6030 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
6031 const struct intel_crtc_state *new_crtc_state)
6033 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6034 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6036 if (!new_crtc_state->ips_enabled)
6039 if (intel_crtc_needs_modeset(new_crtc_state))
6043 * Workaround : Do not read or write the pipe palette/gamma data while
6044 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6046 * Re-enable IPS after the LUT has been programmed.
6048 if (IS_HASWELL(dev_priv) &&
6049 (new_crtc_state->uapi.color_mgmt_changed ||
6050 new_crtc_state->update_pipe) &&
6051 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6055 * We can't read out IPS on broadwell, assume the worst and
6056 * forcibly enable IPS on the first fastset.
6058 if (new_crtc_state->update_pipe && old_crtc_state->inherited)
6061 return !old_crtc_state->ips_enabled;
6064 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
6066 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6068 if (!crtc_state->nv12_planes)
6071 /* WA Display #0827: Gen9:all */
6072 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
6078 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
6080 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6082 /* Wa_2006604312:icl,ehl */
6083 if (crtc_state->scaler_state.scaler_users > 0 && IS_GEN(dev_priv, 11))
6089 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
6090 const struct intel_crtc_state *new_crtc_state)
6092 return (!old_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state)) &&
6093 new_crtc_state->active_planes;
6096 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
6097 const struct intel_crtc_state *new_crtc_state)
6099 return old_crtc_state->active_planes &&
6100 (!new_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state));
6103 static void intel_post_plane_update(struct intel_atomic_state *state,
6104 struct intel_crtc *crtc)
6106 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6107 const struct intel_crtc_state *old_crtc_state =
6108 intel_atomic_get_old_crtc_state(state, crtc);
6109 const struct intel_crtc_state *new_crtc_state =
6110 intel_atomic_get_new_crtc_state(state, crtc);
6111 enum pipe pipe = crtc->pipe;
6113 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
6115 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
6116 intel_update_watermarks(crtc);
6118 if (hsw_post_update_enable_ips(old_crtc_state, new_crtc_state))
6119 hsw_enable_ips(new_crtc_state);
6121 intel_fbc_post_update(state, crtc);
6123 if (needs_nv12_wa(old_crtc_state) &&
6124 !needs_nv12_wa(new_crtc_state))
6125 skl_wa_827(dev_priv, pipe, false);
6127 if (needs_scalerclk_wa(old_crtc_state) &&
6128 !needs_scalerclk_wa(new_crtc_state))
6129 icl_wa_scalerclkgating(dev_priv, pipe, false);
6132 static void skl_disable_async_flip_wa(struct intel_atomic_state *state,
6133 struct intel_crtc *crtc,
6134 const struct intel_crtc_state *new_crtc_state)
6136 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6137 struct intel_plane *plane;
6138 struct intel_plane_state *new_plane_state;
6141 for_each_new_intel_plane_in_state(state, plane, new_plane_state, i) {
6142 u32 update_mask = new_crtc_state->update_planes;
6143 u32 plane_ctl, surf_addr;
6144 enum plane_id plane_id;
6145 unsigned long irqflags;
6148 if (crtc->pipe != plane->pipe ||
6149 !(update_mask & BIT(plane->id)))
6152 plane_id = plane->id;
6155 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
6156 plane_ctl = intel_de_read_fw(dev_priv, PLANE_CTL(pipe, plane_id));
6157 surf_addr = intel_de_read_fw(dev_priv, PLANE_SURF(pipe, plane_id));
6159 plane_ctl &= ~PLANE_CTL_ASYNC_FLIP;
6161 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), plane_ctl);
6162 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id), surf_addr);
6163 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
6166 intel_wait_for_vblank(dev_priv, crtc->pipe);
6169 static void intel_pre_plane_update(struct intel_atomic_state *state,
6170 struct intel_crtc *crtc)
6172 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6173 const struct intel_crtc_state *old_crtc_state =
6174 intel_atomic_get_old_crtc_state(state, crtc);
6175 const struct intel_crtc_state *new_crtc_state =
6176 intel_atomic_get_new_crtc_state(state, crtc);
6177 enum pipe pipe = crtc->pipe;
6179 if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
6180 hsw_disable_ips(old_crtc_state);
6182 if (intel_fbc_pre_update(state, crtc))
6183 intel_wait_for_vblank(dev_priv, pipe);
6185 /* Display WA 827 */
6186 if (!needs_nv12_wa(old_crtc_state) &&
6187 needs_nv12_wa(new_crtc_state))
6188 skl_wa_827(dev_priv, pipe, true);
6190 /* Wa_2006604312:icl,ehl */
6191 if (!needs_scalerclk_wa(old_crtc_state) &&
6192 needs_scalerclk_wa(new_crtc_state))
6193 icl_wa_scalerclkgating(dev_priv, pipe, true);
6196 * Vblank time updates from the shadow to live plane control register
6197 * are blocked if the memory self-refresh mode is active at that
6198 * moment. So to make sure the plane gets truly disabled, disable
6199 * first the self-refresh mode. The self-refresh enable bit in turn
6200 * will be checked/applied by the HW only at the next frame start
6201 * event which is after the vblank start event, so we need to have a
6202 * wait-for-vblank between disabling the plane and the pipe.
6204 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
6205 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
6206 intel_wait_for_vblank(dev_priv, pipe);
6209 * IVB workaround: must disable low power watermarks for at least
6210 * one frame before enabling scaling. LP watermarks can be re-enabled
6211 * when scaling is disabled.
6213 * WaCxSRDisabledForSpriteScaling:ivb
6215 if (old_crtc_state->hw.active &&
6216 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
6217 intel_wait_for_vblank(dev_priv, pipe);
6220 * If we're doing a modeset we don't need to do any
6221 * pre-vblank watermark programming here.
6223 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6225 * For platforms that support atomic watermarks, program the
6226 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6227 * will be the intermediate values that are safe for both pre- and
6228 * post- vblank; when vblank happens, the 'active' values will be set
6229 * to the final 'target' values and we'll do this again to get the
6230 * optimal watermarks. For gen9+ platforms, the values we program here
6231 * will be the final target values which will get automatically latched
6232 * at vblank time; no further programming will be necessary.
6234 * If a platform hasn't been transitioned to atomic watermarks yet,
6235 * we'll continue to update watermarks the old way, if flags tell
6238 if (dev_priv->display.initial_watermarks)
6239 dev_priv->display.initial_watermarks(state, crtc);
6240 else if (new_crtc_state->update_wm_pre)
6241 intel_update_watermarks(crtc);
6245 * Gen2 reports pipe underruns whenever all planes are disabled.
6246 * So disable underrun reporting before all the planes get disabled.
6248 * We do this after .initial_watermarks() so that we have a
6249 * chance of catching underruns with the intermediate watermarks
6250 * vs. the old plane configuration.
6252 if (IS_GEN(dev_priv, 2) && planes_disabling(old_crtc_state, new_crtc_state))
6253 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6256 * WA for platforms where async address update enable bit
6257 * is double buffered and only latched at start of vblank.
6259 if (old_crtc_state->uapi.async_flip &&
6260 !new_crtc_state->uapi.async_flip &&
6261 IS_GEN_RANGE(dev_priv, 9, 10))
6262 skl_disable_async_flip_wa(state, crtc, new_crtc_state);
6265 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6266 struct intel_crtc *crtc)
6268 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6269 const struct intel_crtc_state *new_crtc_state =
6270 intel_atomic_get_new_crtc_state(state, crtc);
6271 unsigned int update_mask = new_crtc_state->update_planes;
6272 const struct intel_plane_state *old_plane_state;
6273 struct intel_plane *plane;
6274 unsigned fb_bits = 0;
6277 intel_crtc_dpms_overlay_disable(crtc);
6279 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6280 if (crtc->pipe != plane->pipe ||
6281 !(update_mask & BIT(plane->id)))
6284 intel_disable_plane(plane, new_crtc_state);
6286 if (old_plane_state->uapi.visible)
6287 fb_bits |= plane->frontbuffer_bit;
6290 intel_frontbuffer_flip(dev_priv, fb_bits);
6294 * intel_connector_primary_encoder - get the primary encoder for a connector
6295 * @connector: connector for which to return the encoder
6297 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6298 * all connectors to their encoder, except for DP-MST connectors which have
6299 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6300 * pointed to by as many DP-MST connectors as there are pipes.
6302 static struct intel_encoder *
6303 intel_connector_primary_encoder(struct intel_connector *connector)
6305 struct intel_encoder *encoder;
6307 if (connector->mst_port)
6308 return &dp_to_dig_port(connector->mst_port)->base;
6310 encoder = intel_attached_encoder(connector);
6311 drm_WARN_ON(connector->base.dev, !encoder);
6316 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6318 struct drm_connector_state *new_conn_state;
6319 struct drm_connector *connector;
6322 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6324 struct intel_connector *intel_connector;
6325 struct intel_encoder *encoder;
6326 struct intel_crtc *crtc;
6328 if (!intel_connector_needs_modeset(state, connector))
6331 intel_connector = to_intel_connector(connector);
6332 encoder = intel_connector_primary_encoder(intel_connector);
6333 if (!encoder->update_prepare)
6336 crtc = new_conn_state->crtc ?
6337 to_intel_crtc(new_conn_state->crtc) : NULL;
6338 encoder->update_prepare(state, encoder, crtc);
6342 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6344 struct drm_connector_state *new_conn_state;
6345 struct drm_connector *connector;
6348 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6350 struct intel_connector *intel_connector;
6351 struct intel_encoder *encoder;
6352 struct intel_crtc *crtc;
6354 if (!intel_connector_needs_modeset(state, connector))
6357 intel_connector = to_intel_connector(connector);
6358 encoder = intel_connector_primary_encoder(intel_connector);
6359 if (!encoder->update_complete)
6362 crtc = new_conn_state->crtc ?
6363 to_intel_crtc(new_conn_state->crtc) : NULL;
6364 encoder->update_complete(state, encoder, crtc);
6368 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
6369 struct intel_crtc *crtc)
6371 const struct intel_crtc_state *crtc_state =
6372 intel_atomic_get_new_crtc_state(state, crtc);
6373 const struct drm_connector_state *conn_state;
6374 struct drm_connector *conn;
6377 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6378 struct intel_encoder *encoder =
6379 to_intel_encoder(conn_state->best_encoder);
6381 if (conn_state->crtc != &crtc->base)
6384 if (encoder->pre_pll_enable)
6385 encoder->pre_pll_enable(state, encoder,
6386 crtc_state, conn_state);
6390 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
6391 struct intel_crtc *crtc)
6393 const struct intel_crtc_state *crtc_state =
6394 intel_atomic_get_new_crtc_state(state, crtc);
6395 const struct drm_connector_state *conn_state;
6396 struct drm_connector *conn;
6399 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6400 struct intel_encoder *encoder =
6401 to_intel_encoder(conn_state->best_encoder);
6403 if (conn_state->crtc != &crtc->base)
6406 if (encoder->pre_enable)
6407 encoder->pre_enable(state, encoder,
6408 crtc_state, conn_state);
6412 static void intel_encoders_enable(struct intel_atomic_state *state,
6413 struct intel_crtc *crtc)
6415 const struct intel_crtc_state *crtc_state =
6416 intel_atomic_get_new_crtc_state(state, crtc);
6417 const struct drm_connector_state *conn_state;
6418 struct drm_connector *conn;
6421 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6422 struct intel_encoder *encoder =
6423 to_intel_encoder(conn_state->best_encoder);
6425 if (conn_state->crtc != &crtc->base)
6428 if (encoder->enable)
6429 encoder->enable(state, encoder,
6430 crtc_state, conn_state);
6431 intel_opregion_notify_encoder(encoder, true);
6435 static void intel_encoders_disable(struct intel_atomic_state *state,
6436 struct intel_crtc *crtc)
6438 const struct intel_crtc_state *old_crtc_state =
6439 intel_atomic_get_old_crtc_state(state, crtc);
6440 const struct drm_connector_state *old_conn_state;
6441 struct drm_connector *conn;
6444 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6445 struct intel_encoder *encoder =
6446 to_intel_encoder(old_conn_state->best_encoder);
6448 if (old_conn_state->crtc != &crtc->base)
6451 intel_opregion_notify_encoder(encoder, false);
6452 if (encoder->disable)
6453 encoder->disable(state, encoder,
6454 old_crtc_state, old_conn_state);
6458 static void intel_encoders_post_disable(struct intel_atomic_state *state,
6459 struct intel_crtc *crtc)
6461 const struct intel_crtc_state *old_crtc_state =
6462 intel_atomic_get_old_crtc_state(state, crtc);
6463 const struct drm_connector_state *old_conn_state;
6464 struct drm_connector *conn;
6467 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6468 struct intel_encoder *encoder =
6469 to_intel_encoder(old_conn_state->best_encoder);
6471 if (old_conn_state->crtc != &crtc->base)
6474 if (encoder->post_disable)
6475 encoder->post_disable(state, encoder,
6476 old_crtc_state, old_conn_state);
6480 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
6481 struct intel_crtc *crtc)
6483 const struct intel_crtc_state *old_crtc_state =
6484 intel_atomic_get_old_crtc_state(state, crtc);
6485 const struct drm_connector_state *old_conn_state;
6486 struct drm_connector *conn;
6489 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6490 struct intel_encoder *encoder =
6491 to_intel_encoder(old_conn_state->best_encoder);
6493 if (old_conn_state->crtc != &crtc->base)
6496 if (encoder->post_pll_disable)
6497 encoder->post_pll_disable(state, encoder,
6498 old_crtc_state, old_conn_state);
6502 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
6503 struct intel_crtc *crtc)
6505 const struct intel_crtc_state *crtc_state =
6506 intel_atomic_get_new_crtc_state(state, crtc);
6507 const struct drm_connector_state *conn_state;
6508 struct drm_connector *conn;
6511 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6512 struct intel_encoder *encoder =
6513 to_intel_encoder(conn_state->best_encoder);
6515 if (conn_state->crtc != &crtc->base)
6518 if (encoder->update_pipe)
6519 encoder->update_pipe(state, encoder,
6520 crtc_state, conn_state);
6524 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6526 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6527 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6529 plane->disable_plane(plane, crtc_state);
6532 static void ilk_crtc_enable(struct intel_atomic_state *state,
6533 struct intel_crtc *crtc)
6535 const struct intel_crtc_state *new_crtc_state =
6536 intel_atomic_get_new_crtc_state(state, crtc);
6537 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6538 enum pipe pipe = crtc->pipe;
6540 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
6544 * Sometimes spurious CPU pipe underruns happen during FDI
6545 * training, at least with VGA+HDMI cloning. Suppress them.
6547 * On ILK we get an occasional spurious CPU pipe underruns
6548 * between eDP port A enable and vdd enable. Also PCH port
6549 * enable seems to result in the occasional CPU pipe underrun.
6551 * Spurious PCH underruns also occur during PCH enabling.
6553 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6554 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6556 if (new_crtc_state->has_pch_encoder)
6557 intel_prepare_shared_dpll(new_crtc_state);
6559 if (intel_crtc_has_dp_encoder(new_crtc_state))
6560 intel_dp_set_m_n(new_crtc_state, M1_N1);
6562 intel_set_transcoder_timings(new_crtc_state);
6563 intel_set_pipe_src_size(new_crtc_state);
6565 if (new_crtc_state->has_pch_encoder)
6566 intel_cpu_transcoder_set_m_n(new_crtc_state,
6567 &new_crtc_state->fdi_m_n, NULL);
6569 ilk_set_pipeconf(new_crtc_state);
6571 crtc->active = true;
6573 intel_encoders_pre_enable(state, crtc);
6575 if (new_crtc_state->has_pch_encoder) {
6576 /* Note: FDI PLL enabling _must_ be done before we enable the
6577 * cpu pipes, hence this is separate from all the other fdi/pch
6579 ilk_fdi_pll_enable(new_crtc_state);
6581 assert_fdi_tx_disabled(dev_priv, pipe);
6582 assert_fdi_rx_disabled(dev_priv, pipe);
6585 ilk_pfit_enable(new_crtc_state);
6588 * On ILK+ LUT must be loaded before the pipe is running but with
6591 intel_color_load_luts(new_crtc_state);
6592 intel_color_commit(new_crtc_state);
6593 /* update DSPCNTR to configure gamma for pipe bottom color */
6594 intel_disable_primary_plane(new_crtc_state);
6596 if (dev_priv->display.initial_watermarks)
6597 dev_priv->display.initial_watermarks(state, crtc);
6598 intel_enable_pipe(new_crtc_state);
6600 if (new_crtc_state->has_pch_encoder)
6601 ilk_pch_enable(state, new_crtc_state);
6603 intel_crtc_vblank_on(new_crtc_state);
6605 intel_encoders_enable(state, crtc);
6607 if (HAS_PCH_CPT(dev_priv))
6608 cpt_verify_modeset(dev_priv, pipe);
6611 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6612 * And a second vblank wait is needed at least on ILK with
6613 * some interlaced HDMI modes. Let's do the double wait always
6614 * in case there are more corner cases we don't know about.
6616 if (new_crtc_state->has_pch_encoder) {
6617 intel_wait_for_vblank(dev_priv, pipe);
6618 intel_wait_for_vblank(dev_priv, pipe);
6620 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6621 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6624 /* IPS only exists on ULT machines and is tied to pipe A. */
6625 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6627 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6630 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6631 enum pipe pipe, bool apply)
6633 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
6634 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6641 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
6644 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6646 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6647 enum pipe pipe = crtc->pipe;
6650 val = MBUS_DBOX_A_CREDIT(2);
6652 if (INTEL_GEN(dev_priv) >= 12) {
6653 val |= MBUS_DBOX_BW_CREDIT(2);
6654 val |= MBUS_DBOX_B_CREDIT(12);
6656 val |= MBUS_DBOX_BW_CREDIT(1);
6657 val |= MBUS_DBOX_B_CREDIT(8);
6660 intel_de_write(dev_priv, PIPE_MBUS_DBOX_CTL(pipe), val);
6663 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
6665 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6666 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6668 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
6669 HSW_LINETIME(crtc_state->linetime) |
6670 HSW_IPS_LINETIME(crtc_state->ips_linetime));
6673 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
6675 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6676 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6677 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
6680 val = intel_de_read(dev_priv, reg);
6681 val &= ~HSW_FRAME_START_DELAY_MASK;
6682 val |= HSW_FRAME_START_DELAY(0);
6683 intel_de_write(dev_priv, reg, val);
6686 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
6687 const struct intel_crtc_state *crtc_state)
6689 struct intel_crtc *master = to_intel_crtc(crtc_state->uapi.crtc);
6690 struct intel_crtc_state *master_crtc_state;
6691 struct drm_connector_state *conn_state;
6692 struct drm_connector *conn;
6693 struct intel_encoder *encoder = NULL;
6696 if (crtc_state->bigjoiner_slave)
6697 master = crtc_state->bigjoiner_linked_crtc;
6699 master_crtc_state = intel_atomic_get_new_crtc_state(state, master);
6701 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6702 if (conn_state->crtc != &master->base)
6705 encoder = to_intel_encoder(conn_state->best_encoder);
6709 if (!crtc_state->bigjoiner_slave) {
6710 /* need to enable VDSC, which we skipped in pre-enable */
6711 intel_dsc_enable(encoder, crtc_state);
6714 * Enable sequence steps 1-7 on bigjoiner master
6716 intel_encoders_pre_pll_enable(state, master);
6717 intel_enable_shared_dpll(master_crtc_state);
6718 intel_encoders_pre_enable(state, master);
6720 /* and DSC on slave */
6721 intel_dsc_enable(NULL, crtc_state);
6725 static void hsw_crtc_enable(struct intel_atomic_state *state,
6726 struct intel_crtc *crtc)
6728 const struct intel_crtc_state *new_crtc_state =
6729 intel_atomic_get_new_crtc_state(state, crtc);
6730 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6731 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
6732 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
6733 bool psl_clkgate_wa;
6735 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
6738 if (!new_crtc_state->bigjoiner) {
6739 intel_encoders_pre_pll_enable(state, crtc);
6741 if (new_crtc_state->shared_dpll)
6742 intel_enable_shared_dpll(new_crtc_state);
6744 intel_encoders_pre_enable(state, crtc);
6746 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
6749 intel_set_pipe_src_size(new_crtc_state);
6750 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6751 bdw_set_pipemisc(new_crtc_state);
6753 if (!new_crtc_state->bigjoiner_slave && !transcoder_is_dsi(cpu_transcoder)) {
6754 intel_set_transcoder_timings(new_crtc_state);
6756 if (cpu_transcoder != TRANSCODER_EDP)
6757 intel_de_write(dev_priv, PIPE_MULT(cpu_transcoder),
6758 new_crtc_state->pixel_multiplier - 1);
6760 if (new_crtc_state->has_pch_encoder)
6761 intel_cpu_transcoder_set_m_n(new_crtc_state,
6762 &new_crtc_state->fdi_m_n, NULL);
6764 hsw_set_frame_start_delay(new_crtc_state);
6767 if (!transcoder_is_dsi(cpu_transcoder))
6768 hsw_set_pipeconf(new_crtc_state);
6770 crtc->active = true;
6772 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6773 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
6774 new_crtc_state->pch_pfit.enabled;
6776 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
6778 if (INTEL_GEN(dev_priv) >= 9)
6779 skl_pfit_enable(new_crtc_state);
6781 ilk_pfit_enable(new_crtc_state);
6784 * On ILK+ LUT must be loaded before the pipe is running but with
6787 intel_color_load_luts(new_crtc_state);
6788 intel_color_commit(new_crtc_state);
6789 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
6790 if (INTEL_GEN(dev_priv) < 9)
6791 intel_disable_primary_plane(new_crtc_state);
6793 hsw_set_linetime_wm(new_crtc_state);
6795 if (INTEL_GEN(dev_priv) >= 11)
6796 icl_set_pipe_chicken(crtc);
6798 if (dev_priv->display.initial_watermarks)
6799 dev_priv->display.initial_watermarks(state, crtc);
6801 if (INTEL_GEN(dev_priv) >= 11)
6802 icl_pipe_mbus_enable(crtc);
6804 if (new_crtc_state->bigjoiner_slave) {
6805 trace_intel_pipe_enable(crtc);
6806 intel_crtc_vblank_on(new_crtc_state);
6809 intel_encoders_enable(state, crtc);
6811 if (psl_clkgate_wa) {
6812 intel_wait_for_vblank(dev_priv, pipe);
6813 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6816 /* If we change the relative order between pipe/planes enabling, we need
6817 * to change the workaround. */
6818 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
6819 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6820 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6821 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6825 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6827 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
6828 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6829 enum pipe pipe = crtc->pipe;
6831 /* To avoid upsetting the power well on haswell only disable the pfit if
6832 * it's in use. The hw state code will make sure we get this right. */
6833 if (!old_crtc_state->pch_pfit.enabled)
6836 intel_de_write(dev_priv, PF_CTL(pipe), 0);
6837 intel_de_write(dev_priv, PF_WIN_POS(pipe), 0);
6838 intel_de_write(dev_priv, PF_WIN_SZ(pipe), 0);
6841 static void ilk_crtc_disable(struct intel_atomic_state *state,
6842 struct intel_crtc *crtc)
6844 const struct intel_crtc_state *old_crtc_state =
6845 intel_atomic_get_old_crtc_state(state, crtc);
6846 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6847 enum pipe pipe = crtc->pipe;
6850 * Sometimes spurious CPU pipe underruns happen when the
6851 * pipe is already disabled, but FDI RX/TX is still enabled.
6852 * Happens at least with VGA+HDMI cloning. Suppress them.
6854 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6855 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6857 intel_encoders_disable(state, crtc);
6859 intel_crtc_vblank_off(old_crtc_state);
6861 intel_disable_pipe(old_crtc_state);
6863 ilk_pfit_disable(old_crtc_state);
6865 if (old_crtc_state->has_pch_encoder)
6866 ilk_fdi_disable(crtc);
6868 intel_encoders_post_disable(state, crtc);
6870 if (old_crtc_state->has_pch_encoder) {
6871 ilk_disable_pch_transcoder(dev_priv, pipe);
6873 if (HAS_PCH_CPT(dev_priv)) {
6877 /* disable TRANS_DP_CTL */
6878 reg = TRANS_DP_CTL(pipe);
6879 temp = intel_de_read(dev_priv, reg);
6880 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6881 TRANS_DP_PORT_SEL_MASK);
6882 temp |= TRANS_DP_PORT_SEL_NONE;
6883 intel_de_write(dev_priv, reg, temp);
6885 /* disable DPLL_SEL */
6886 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
6887 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6888 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
6891 ilk_fdi_pll_disable(crtc);
6894 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6895 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6898 static void hsw_crtc_disable(struct intel_atomic_state *state,
6899 struct intel_crtc *crtc)
6902 * FIXME collapse everything to one hook.
6903 * Need care with mst->ddi interactions.
6905 intel_encoders_disable(state, crtc);
6906 intel_encoders_post_disable(state, crtc);
6909 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6911 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6912 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6914 if (!crtc_state->gmch_pfit.control)
6918 * The panel fitter should only be adjusted whilst the pipe is disabled,
6919 * according to register description and PRM.
6921 drm_WARN_ON(&dev_priv->drm,
6922 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
6923 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
6925 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
6926 crtc_state->gmch_pfit.pgm_ratios);
6927 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
6929 /* Border color in case we don't scale up to the full screen. Black by
6930 * default, change to something else for debugging. */
6931 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
6934 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
6936 if (phy == PHY_NONE)
6938 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
6939 return phy <= PHY_D;
6940 else if (IS_JSL_EHL(dev_priv))
6941 return phy <= PHY_C;
6942 else if (INTEL_GEN(dev_priv) >= 11)
6943 return phy <= PHY_B;
6948 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
6950 if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
6952 else if (INTEL_GEN(dev_priv) >= 12)
6953 return phy >= PHY_D && phy <= PHY_I;
6954 else if (INTEL_GEN(dev_priv) >= 11 && !IS_JSL_EHL(dev_priv))
6955 return phy >= PHY_C && phy <= PHY_F;
6960 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
6962 if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
6963 return PHY_C + port - PORT_TC1;
6964 else if (IS_JSL_EHL(i915) && port == PORT_D)
6967 return PHY_A + port - PORT_A;
6970 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6972 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
6973 return TC_PORT_NONE;
6975 if (INTEL_GEN(dev_priv) >= 12)
6976 return TC_PORT_1 + port - PORT_TC1;
6978 return TC_PORT_1 + port - PORT_C;
6981 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
6985 return POWER_DOMAIN_PORT_DDI_A_LANES;
6987 return POWER_DOMAIN_PORT_DDI_B_LANES;
6989 return POWER_DOMAIN_PORT_DDI_C_LANES;
6991 return POWER_DOMAIN_PORT_DDI_D_LANES;
6993 return POWER_DOMAIN_PORT_DDI_E_LANES;
6995 return POWER_DOMAIN_PORT_DDI_F_LANES;
6997 return POWER_DOMAIN_PORT_DDI_G_LANES;
6999 return POWER_DOMAIN_PORT_DDI_H_LANES;
7001 return POWER_DOMAIN_PORT_DDI_I_LANES;
7004 return POWER_DOMAIN_PORT_OTHER;
7008 enum intel_display_power_domain
7009 intel_aux_power_domain(struct intel_digital_port *dig_port)
7011 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
7012 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
7014 if (intel_phy_is_tc(dev_priv, phy) &&
7015 dig_port->tc_mode == TC_PORT_TBT_ALT) {
7016 switch (dig_port->aux_ch) {
7018 return POWER_DOMAIN_AUX_C_TBT;
7020 return POWER_DOMAIN_AUX_D_TBT;
7022 return POWER_DOMAIN_AUX_E_TBT;
7024 return POWER_DOMAIN_AUX_F_TBT;
7026 return POWER_DOMAIN_AUX_G_TBT;
7028 return POWER_DOMAIN_AUX_H_TBT;
7030 return POWER_DOMAIN_AUX_I_TBT;
7032 MISSING_CASE(dig_port->aux_ch);
7033 return POWER_DOMAIN_AUX_C_TBT;
7037 return intel_legacy_aux_to_power_domain(dig_port->aux_ch);
7041 * Converts aux_ch to power_domain without caring about TBT ports for that use
7042 * intel_aux_power_domain()
7044 enum intel_display_power_domain
7045 intel_legacy_aux_to_power_domain(enum aux_ch aux_ch)
7049 return POWER_DOMAIN_AUX_A;
7051 return POWER_DOMAIN_AUX_B;
7053 return POWER_DOMAIN_AUX_C;
7055 return POWER_DOMAIN_AUX_D;
7057 return POWER_DOMAIN_AUX_E;
7059 return POWER_DOMAIN_AUX_F;
7061 return POWER_DOMAIN_AUX_G;
7063 return POWER_DOMAIN_AUX_H;
7065 return POWER_DOMAIN_AUX_I;
7067 MISSING_CASE(aux_ch);
7068 return POWER_DOMAIN_AUX_A;
7072 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7074 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7075 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7076 struct drm_encoder *encoder;
7077 enum pipe pipe = crtc->pipe;
7079 enum transcoder transcoder = crtc_state->cpu_transcoder;
7081 if (!crtc_state->hw.active)
7084 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
7085 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
7086 if (crtc_state->pch_pfit.enabled ||
7087 crtc_state->pch_pfit.force_thru)
7088 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
7090 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
7091 crtc_state->uapi.encoder_mask) {
7092 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7094 mask |= BIT_ULL(intel_encoder->power_domain);
7097 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
7098 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
7100 if (crtc_state->shared_dpll)
7101 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
7103 if (crtc_state->dsc.compression_enable)
7104 mask |= BIT_ULL(intel_dsc_power_domain(crtc_state));
7110 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7112 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7113 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7114 enum intel_display_power_domain domain;
7115 u64 domains, new_domains, old_domains;
7117 domains = get_crtc_power_domains(crtc_state);
7119 new_domains = domains & ~crtc->enabled_power_domains.mask;
7120 old_domains = crtc->enabled_power_domains.mask & ~domains;
7122 for_each_power_domain(domain, new_domains)
7123 intel_display_power_get_in_set(dev_priv,
7124 &crtc->enabled_power_domains,
7130 static void modeset_put_crtc_power_domains(struct intel_crtc *crtc,
7133 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
7134 &crtc->enabled_power_domains,
7138 static void valleyview_crtc_enable(struct intel_atomic_state *state,
7139 struct intel_crtc *crtc)
7141 const struct intel_crtc_state *new_crtc_state =
7142 intel_atomic_get_new_crtc_state(state, crtc);
7143 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7144 enum pipe pipe = crtc->pipe;
7146 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
7149 if (intel_crtc_has_dp_encoder(new_crtc_state))
7150 intel_dp_set_m_n(new_crtc_state, M1_N1);
7152 intel_set_transcoder_timings(new_crtc_state);
7153 intel_set_pipe_src_size(new_crtc_state);
7155 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
7156 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
7157 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
7160 i9xx_set_pipeconf(new_crtc_state);
7162 crtc->active = true;
7164 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7166 intel_encoders_pre_pll_enable(state, crtc);
7168 if (IS_CHERRYVIEW(dev_priv)) {
7169 chv_prepare_pll(crtc, new_crtc_state);
7170 chv_enable_pll(crtc, new_crtc_state);
7172 vlv_prepare_pll(crtc, new_crtc_state);
7173 vlv_enable_pll(crtc, new_crtc_state);
7176 intel_encoders_pre_enable(state, crtc);
7178 i9xx_pfit_enable(new_crtc_state);
7180 intel_color_load_luts(new_crtc_state);
7181 intel_color_commit(new_crtc_state);
7182 /* update DSPCNTR to configure gamma for pipe bottom color */
7183 intel_disable_primary_plane(new_crtc_state);
7185 dev_priv->display.initial_watermarks(state, crtc);
7186 intel_enable_pipe(new_crtc_state);
7188 intel_crtc_vblank_on(new_crtc_state);
7190 intel_encoders_enable(state, crtc);
7193 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
7195 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7196 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7198 intel_de_write(dev_priv, FP0(crtc->pipe),
7199 crtc_state->dpll_hw_state.fp0);
7200 intel_de_write(dev_priv, FP1(crtc->pipe),
7201 crtc_state->dpll_hw_state.fp1);
7204 static void i9xx_crtc_enable(struct intel_atomic_state *state,
7205 struct intel_crtc *crtc)
7207 const struct intel_crtc_state *new_crtc_state =
7208 intel_atomic_get_new_crtc_state(state, crtc);
7209 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7210 enum pipe pipe = crtc->pipe;
7212 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
7215 i9xx_set_pll_dividers(new_crtc_state);
7217 if (intel_crtc_has_dp_encoder(new_crtc_state))
7218 intel_dp_set_m_n(new_crtc_state, M1_N1);
7220 intel_set_transcoder_timings(new_crtc_state);
7221 intel_set_pipe_src_size(new_crtc_state);
7223 i9xx_set_pipeconf(new_crtc_state);
7225 crtc->active = true;
7227 if (!IS_GEN(dev_priv, 2))
7228 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7230 intel_encoders_pre_enable(state, crtc);
7232 i9xx_enable_pll(crtc, new_crtc_state);
7234 i9xx_pfit_enable(new_crtc_state);
7236 intel_color_load_luts(new_crtc_state);
7237 intel_color_commit(new_crtc_state);
7238 /* update DSPCNTR to configure gamma for pipe bottom color */
7239 intel_disable_primary_plane(new_crtc_state);
7241 if (dev_priv->display.initial_watermarks)
7242 dev_priv->display.initial_watermarks(state, crtc);
7244 intel_update_watermarks(crtc);
7245 intel_enable_pipe(new_crtc_state);
7247 intel_crtc_vblank_on(new_crtc_state);
7249 intel_encoders_enable(state, crtc);
7251 /* prevents spurious underruns */
7252 if (IS_GEN(dev_priv, 2))
7253 intel_wait_for_vblank(dev_priv, pipe);
7256 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
7258 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
7259 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7261 if (!old_crtc_state->gmch_pfit.control)
7264 assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
7266 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
7267 intel_de_read(dev_priv, PFIT_CONTROL));
7268 intel_de_write(dev_priv, PFIT_CONTROL, 0);
7271 static void i9xx_crtc_disable(struct intel_atomic_state *state,
7272 struct intel_crtc *crtc)
7274 struct intel_crtc_state *old_crtc_state =
7275 intel_atomic_get_old_crtc_state(state, crtc);
7276 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7277 enum pipe pipe = crtc->pipe;
7280 * On gen2 planes are double buffered but the pipe isn't, so we must
7281 * wait for planes to fully turn off before disabling the pipe.
7283 if (IS_GEN(dev_priv, 2))
7284 intel_wait_for_vblank(dev_priv, pipe);
7286 intel_encoders_disable(state, crtc);
7288 intel_crtc_vblank_off(old_crtc_state);
7290 intel_disable_pipe(old_crtc_state);
7292 i9xx_pfit_disable(old_crtc_state);
7294 intel_encoders_post_disable(state, crtc);
7296 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
7297 if (IS_CHERRYVIEW(dev_priv))
7298 chv_disable_pll(dev_priv, pipe);
7299 else if (IS_VALLEYVIEW(dev_priv))
7300 vlv_disable_pll(dev_priv, pipe);
7302 i9xx_disable_pll(old_crtc_state);
7305 intel_encoders_post_pll_disable(state, crtc);
7307 if (!IS_GEN(dev_priv, 2))
7308 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7310 if (!dev_priv->display.initial_watermarks)
7311 intel_update_watermarks(crtc);
7313 /* clock the pipe down to 640x480@60 to potentially save power */
7314 if (IS_I830(dev_priv))
7315 i830_enable_pipe(dev_priv, pipe);
7318 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc,
7319 struct drm_modeset_acquire_ctx *ctx)
7321 struct intel_encoder *encoder;
7322 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7323 struct intel_bw_state *bw_state =
7324 to_intel_bw_state(dev_priv->bw_obj.state);
7325 struct intel_cdclk_state *cdclk_state =
7326 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
7327 struct intel_dbuf_state *dbuf_state =
7328 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
7329 struct intel_crtc_state *crtc_state =
7330 to_intel_crtc_state(crtc->base.state);
7331 struct intel_plane *plane;
7332 struct drm_atomic_state *state;
7333 struct intel_crtc_state *temp_crtc_state;
7334 enum pipe pipe = crtc->pipe;
7337 if (!crtc_state->hw.active)
7340 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
7341 const struct intel_plane_state *plane_state =
7342 to_intel_plane_state(plane->base.state);
7344 if (plane_state->uapi.visible)
7345 intel_plane_disable_noatomic(crtc, plane);
7348 state = drm_atomic_state_alloc(&dev_priv->drm);
7350 drm_dbg_kms(&dev_priv->drm,
7351 "failed to disable [CRTC:%d:%s], out of memory",
7352 crtc->base.base.id, crtc->base.name);
7356 state->acquire_ctx = ctx;
7358 /* Everything's already locked, -EDEADLK can't happen. */
7359 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc);
7360 ret = drm_atomic_add_affected_connectors(state, &crtc->base);
7362 drm_WARN_ON(&dev_priv->drm, IS_ERR(temp_crtc_state) || ret);
7364 dev_priv->display.crtc_disable(to_intel_atomic_state(state), crtc);
7366 drm_atomic_state_put(state);
7368 drm_dbg_kms(&dev_priv->drm,
7369 "[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7370 crtc->base.base.id, crtc->base.name);
7372 crtc->active = false;
7373 crtc->base.enabled = false;
7375 drm_WARN_ON(&dev_priv->drm,
7376 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0);
7377 crtc_state->uapi.active = false;
7378 crtc_state->uapi.connector_mask = 0;
7379 crtc_state->uapi.encoder_mask = 0;
7380 intel_crtc_free_hw_state(crtc_state);
7381 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw));
7383 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder)
7384 encoder->base.crtc = NULL;
7386 intel_fbc_disable(crtc);
7387 intel_update_watermarks(crtc);
7388 intel_disable_shared_dpll(crtc_state);
7390 intel_display_power_put_all_in_set(dev_priv, &crtc->enabled_power_domains);
7392 dev_priv->active_pipes &= ~BIT(pipe);
7393 cdclk_state->min_cdclk[pipe] = 0;
7394 cdclk_state->min_voltage_level[pipe] = 0;
7395 cdclk_state->active_pipes &= ~BIT(pipe);
7397 dbuf_state->active_pipes &= ~BIT(pipe);
7399 bw_state->data_rate[pipe] = 0;
7400 bw_state->num_active_planes[pipe] = 0;
7404 * turn all crtc's off, but do not adjust state
7405 * This has to be paired with a call to intel_modeset_setup_hw_state.
7407 int intel_display_suspend(struct drm_device *dev)
7409 struct drm_i915_private *dev_priv = to_i915(dev);
7410 struct drm_atomic_state *state;
7413 state = drm_atomic_helper_suspend(dev);
7414 ret = PTR_ERR_OR_ZERO(state);
7416 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
7419 dev_priv->modeset_restore_state = state;
7423 void intel_encoder_destroy(struct drm_encoder *encoder)
7425 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7427 drm_encoder_cleanup(encoder);
7428 kfree(intel_encoder);
7431 /* Cross check the actual hw state with our own modeset state tracking (and it's
7432 * internal consistency). */
7433 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7434 struct drm_connector_state *conn_state)
7436 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7437 struct drm_i915_private *i915 = to_i915(connector->base.dev);
7439 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n",
7440 connector->base.base.id, connector->base.name);
7442 if (connector->get_hw_state(connector)) {
7443 struct intel_encoder *encoder = intel_attached_encoder(connector);
7445 I915_STATE_WARN(!crtc_state,
7446 "connector enabled without attached crtc\n");
7451 I915_STATE_WARN(!crtc_state->hw.active,
7452 "connector is active, but attached crtc isn't\n");
7454 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7457 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7458 "atomic encoder doesn't match attached encoder\n");
7460 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7461 "attached encoder crtc differs from connector crtc\n");
7463 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
7464 "attached crtc is active, but connector isn't\n");
7465 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7466 "best encoder set without crtc!\n");
7470 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7472 if (crtc_state->hw.enable && crtc_state->has_pch_encoder)
7473 return crtc_state->fdi_lanes;
7478 static int ilk_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7479 struct intel_crtc_state *pipe_config)
7481 struct drm_i915_private *dev_priv = to_i915(dev);
7482 struct drm_atomic_state *state = pipe_config->uapi.state;
7483 struct intel_crtc *other_crtc;
7484 struct intel_crtc_state *other_crtc_state;
7486 drm_dbg_kms(&dev_priv->drm,
7487 "checking fdi config on pipe %c, lanes %i\n",
7488 pipe_name(pipe), pipe_config->fdi_lanes);
7489 if (pipe_config->fdi_lanes > 4) {
7490 drm_dbg_kms(&dev_priv->drm,
7491 "invalid fdi lane config on pipe %c: %i lanes\n",
7492 pipe_name(pipe), pipe_config->fdi_lanes);
7496 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7497 if (pipe_config->fdi_lanes > 2) {
7498 drm_dbg_kms(&dev_priv->drm,
7499 "only 2 lanes on haswell, required: %i lanes\n",
7500 pipe_config->fdi_lanes);
7507 if (INTEL_NUM_PIPES(dev_priv) == 2)
7510 /* Ivybridge 3 pipe is really complicated */
7515 if (pipe_config->fdi_lanes <= 2)
7518 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7520 intel_atomic_get_crtc_state(state, other_crtc);
7521 if (IS_ERR(other_crtc_state))
7522 return PTR_ERR(other_crtc_state);
7524 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7525 drm_dbg_kms(&dev_priv->drm,
7526 "invalid shared fdi lane config on pipe %c: %i lanes\n",
7527 pipe_name(pipe), pipe_config->fdi_lanes);
7532 if (pipe_config->fdi_lanes > 2) {
7533 drm_dbg_kms(&dev_priv->drm,
7534 "only 2 lanes on pipe %c: required %i lanes\n",
7535 pipe_name(pipe), pipe_config->fdi_lanes);
7539 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7541 intel_atomic_get_crtc_state(state, other_crtc);
7542 if (IS_ERR(other_crtc_state))
7543 return PTR_ERR(other_crtc_state);
7545 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7546 drm_dbg_kms(&dev_priv->drm,
7547 "fdi link B uses too many lanes to enable link C\n");
7557 static int ilk_fdi_compute_config(struct intel_crtc *intel_crtc,
7558 struct intel_crtc_state *pipe_config)
7560 struct drm_device *dev = intel_crtc->base.dev;
7561 struct drm_i915_private *i915 = to_i915(dev);
7562 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7563 int lane, link_bw, fdi_dotclock, ret;
7564 bool needs_recompute = false;
7567 /* FDI is a binary signal running at ~2.7GHz, encoding
7568 * each output octet as 10 bits. The actual frequency
7569 * is stored as a divider into a 100MHz clock, and the
7570 * mode pixel clock is stored in units of 1KHz.
7571 * Hence the bw of each lane in terms of the mode signal
7574 link_bw = intel_fdi_link_freq(i915, pipe_config);
7576 fdi_dotclock = adjusted_mode->crtc_clock;
7578 lane = ilk_get_lanes_required(fdi_dotclock, link_bw,
7579 pipe_config->pipe_bpp);
7581 pipe_config->fdi_lanes = lane;
7583 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7584 link_bw, &pipe_config->fdi_m_n, false, false);
7586 ret = ilk_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7587 if (ret == -EDEADLK)
7590 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7591 pipe_config->pipe_bpp -= 2*3;
7592 drm_dbg_kms(&i915->drm,
7593 "fdi link bw constraint, reducing pipe bpp to %i\n",
7594 pipe_config->pipe_bpp);
7595 needs_recompute = true;
7596 pipe_config->bw_constrained = true;
7601 if (needs_recompute)
7607 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7609 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7610 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7612 /* IPS only exists on ULT machines and is tied to pipe A. */
7613 if (!hsw_crtc_supports_ips(crtc))
7616 if (!dev_priv->params.enable_ips)
7619 if (crtc_state->pipe_bpp > 24)
7623 * We compare against max which means we must take
7624 * the increased cdclk requirement into account when
7625 * calculating the new cdclk.
7627 * Should measure whether using a lower cdclk w/o IPS
7629 if (IS_BROADWELL(dev_priv) &&
7630 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7636 static int hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7638 struct drm_i915_private *dev_priv =
7639 to_i915(crtc_state->uapi.crtc->dev);
7640 struct intel_atomic_state *state =
7641 to_intel_atomic_state(crtc_state->uapi.state);
7643 crtc_state->ips_enabled = false;
7645 if (!hsw_crtc_state_ips_capable(crtc_state))
7649 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7650 * enabled and disabled dynamically based on package C states,
7651 * user space can't make reliable use of the CRCs, so let's just
7652 * completely disable it.
7654 if (crtc_state->crc_enabled)
7657 /* IPS should be fine as long as at least one plane is enabled. */
7658 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7661 if (IS_BROADWELL(dev_priv)) {
7662 const struct intel_cdclk_state *cdclk_state;
7664 cdclk_state = intel_atomic_get_cdclk_state(state);
7665 if (IS_ERR(cdclk_state))
7666 return PTR_ERR(cdclk_state);
7668 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7669 if (crtc_state->pixel_rate > cdclk_state->logical.cdclk * 95 / 100)
7673 crtc_state->ips_enabled = true;
7678 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7680 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7682 /* GDG double wide on either pipe, otherwise pipe A only */
7683 return INTEL_GEN(dev_priv) < 4 &&
7684 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7687 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
7689 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
7690 unsigned int pipe_w, pipe_h, pfit_w, pfit_h;
7693 * We only use IF-ID interlacing. If we ever use
7694 * PF-ID we'll need to adjust the pixel_rate here.
7697 if (!crtc_state->pch_pfit.enabled)
7700 pipe_w = crtc_state->pipe_src_w;
7701 pipe_h = crtc_state->pipe_src_h;
7703 pfit_w = drm_rect_width(&crtc_state->pch_pfit.dst);
7704 pfit_h = drm_rect_height(&crtc_state->pch_pfit.dst);
7706 if (pipe_w < pfit_w)
7708 if (pipe_h < pfit_h)
7711 if (drm_WARN_ON(crtc_state->uapi.crtc->dev,
7712 !pfit_w || !pfit_h))
7715 return div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7719 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
7720 const struct drm_display_mode *timings)
7722 mode->hdisplay = timings->crtc_hdisplay;
7723 mode->htotal = timings->crtc_htotal;
7724 mode->hsync_start = timings->crtc_hsync_start;
7725 mode->hsync_end = timings->crtc_hsync_end;
7727 mode->vdisplay = timings->crtc_vdisplay;
7728 mode->vtotal = timings->crtc_vtotal;
7729 mode->vsync_start = timings->crtc_vsync_start;
7730 mode->vsync_end = timings->crtc_vsync_end;
7732 mode->flags = timings->flags;
7733 mode->type = DRM_MODE_TYPE_DRIVER;
7735 mode->clock = timings->crtc_clock;
7737 drm_mode_set_name(mode);
7740 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7742 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
7744 if (HAS_GMCH(dev_priv))
7745 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7746 crtc_state->pixel_rate =
7747 crtc_state->hw.pipe_mode.crtc_clock;
7749 crtc_state->pixel_rate =
7750 ilk_pipe_pixel_rate(crtc_state);
7753 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
7755 struct drm_display_mode *mode = &crtc_state->hw.mode;
7756 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
7757 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
7759 drm_mode_copy(pipe_mode, adjusted_mode);
7761 if (crtc_state->bigjoiner) {
7763 * transcoder is programmed to the full mode,
7764 * but pipe timings are half of the transcoder mode
7766 pipe_mode->crtc_hdisplay /= 2;
7767 pipe_mode->crtc_hblank_start /= 2;
7768 pipe_mode->crtc_hblank_end /= 2;
7769 pipe_mode->crtc_hsync_start /= 2;
7770 pipe_mode->crtc_hsync_end /= 2;
7771 pipe_mode->crtc_htotal /= 2;
7772 pipe_mode->crtc_clock /= 2;
7775 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
7776 intel_mode_from_crtc_timings(adjusted_mode, adjusted_mode);
7778 intel_crtc_compute_pixel_rate(crtc_state);
7780 drm_mode_copy(mode, adjusted_mode);
7781 mode->hdisplay = crtc_state->pipe_src_w << crtc_state->bigjoiner;
7782 mode->vdisplay = crtc_state->pipe_src_h;
7785 static void intel_encoder_get_config(struct intel_encoder *encoder,
7786 struct intel_crtc_state *crtc_state)
7788 encoder->get_config(encoder, crtc_state);
7790 intel_crtc_readout_derived_state(crtc_state);
7793 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7794 struct intel_crtc_state *pipe_config)
7796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7797 struct drm_display_mode *pipe_mode = &pipe_config->hw.pipe_mode;
7798 int clock_limit = dev_priv->max_dotclk_freq;
7800 drm_mode_copy(pipe_mode, &pipe_config->hw.adjusted_mode);
7802 /* Adjust pipe_mode for bigjoiner, with half the horizontal mode */
7803 if (pipe_config->bigjoiner) {
7804 pipe_mode->crtc_clock /= 2;
7805 pipe_mode->crtc_hdisplay /= 2;
7806 pipe_mode->crtc_hblank_start /= 2;
7807 pipe_mode->crtc_hblank_end /= 2;
7808 pipe_mode->crtc_hsync_start /= 2;
7809 pipe_mode->crtc_hsync_end /= 2;
7810 pipe_mode->crtc_htotal /= 2;
7811 pipe_config->pipe_src_w /= 2;
7814 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
7816 if (INTEL_GEN(dev_priv) < 4) {
7817 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
7820 * Enable double wide mode when the dot clock
7821 * is > 90% of the (display) core speed.
7823 if (intel_crtc_supports_double_wide(crtc) &&
7824 pipe_mode->crtc_clock > clock_limit) {
7825 clock_limit = dev_priv->max_dotclk_freq;
7826 pipe_config->double_wide = true;
7830 if (pipe_mode->crtc_clock > clock_limit) {
7831 drm_dbg_kms(&dev_priv->drm,
7832 "requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7833 pipe_mode->crtc_clock, clock_limit,
7834 yesno(pipe_config->double_wide));
7838 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
7839 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
7840 pipe_config->hw.ctm) {
7842 * There is only one pipe CSC unit per pipe, and we need that
7843 * for output conversion from RGB->YCBCR. So if CTM is already
7844 * applied we can't support YCBCR420 output.
7846 drm_dbg_kms(&dev_priv->drm,
7847 "YCBCR420 and CTM together are not possible\n");
7852 * Pipe horizontal size must be even in:
7854 * - LVDS dual channel mode
7855 * - Double wide pipe
7857 if (pipe_config->pipe_src_w & 1) {
7858 if (pipe_config->double_wide) {
7859 drm_dbg_kms(&dev_priv->drm,
7860 "Odd pipe source width not supported with double wide pipe\n");
7864 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
7865 intel_is_dual_link_lvds(dev_priv)) {
7866 drm_dbg_kms(&dev_priv->drm,
7867 "Odd pipe source width not supported with dual link LVDS\n");
7872 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7873 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7875 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7876 pipe_mode->crtc_hsync_start == pipe_mode->crtc_hdisplay)
7879 intel_crtc_compute_pixel_rate(pipe_config);
7881 if (pipe_config->has_pch_encoder)
7882 return ilk_fdi_compute_config(crtc, pipe_config);
7888 intel_reduce_m_n_ratio(u32 *num, u32 *den)
7890 while (*num > DATA_LINK_M_N_MASK ||
7891 *den > DATA_LINK_M_N_MASK) {
7897 static void compute_m_n(unsigned int m, unsigned int n,
7898 u32 *ret_m, u32 *ret_n,
7902 * Several DP dongles in particular seem to be fussy about
7903 * too large link M/N values. Give N value as 0x8000 that
7904 * should be acceptable by specific devices. 0x8000 is the
7905 * specified fixed N value for asynchronous clock mode,
7906 * which the devices expect also in synchronous clock mode.
7909 *ret_n = DP_LINK_CONSTANT_N_VALUE;
7911 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
7913 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
7914 intel_reduce_m_n_ratio(ret_m, ret_n);
7918 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
7919 int pixel_clock, int link_clock,
7920 struct intel_link_m_n *m_n,
7921 bool constant_n, bool fec_enable)
7923 u32 data_clock = bits_per_pixel * pixel_clock;
7926 data_clock = intel_dp_mode_to_fec_clock(data_clock);
7929 compute_m_n(data_clock,
7930 link_clock * nlanes * 8,
7931 &m_n->gmch_m, &m_n->gmch_n,
7934 compute_m_n(pixel_clock, link_clock,
7935 &m_n->link_m, &m_n->link_n,
7939 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
7942 * There may be no VBT; and if the BIOS enabled SSC we can
7943 * just keep using it to avoid unnecessary flicker. Whereas if the
7944 * BIOS isn't using it, don't assume it will work even if the VBT
7945 * indicates as much.
7947 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
7948 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
7952 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
7953 drm_dbg_kms(&dev_priv->drm,
7954 "SSC %s by BIOS, overriding VBT which says %s\n",
7955 enableddisabled(bios_lvds_use_ssc),
7956 enableddisabled(dev_priv->vbt.lvds_use_ssc));
7957 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
7962 static bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7964 if (dev_priv->params.panel_use_ssc >= 0)
7965 return dev_priv->params.panel_use_ssc != 0;
7966 return dev_priv->vbt.lvds_use_ssc
7967 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7970 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
7972 return (1 << dpll->n) << 16 | dpll->m2;
7975 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7977 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7980 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7981 struct intel_crtc_state *crtc_state,
7982 struct dpll *reduced_clock)
7984 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7987 if (IS_PINEVIEW(dev_priv)) {
7988 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7990 fp2 = pnv_dpll_compute_fp(reduced_clock);
7992 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7994 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7997 crtc_state->dpll_hw_state.fp0 = fp;
7999 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8001 crtc_state->dpll_hw_state.fp1 = fp2;
8003 crtc_state->dpll_hw_state.fp1 = fp;
8007 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
8013 * PLLB opamp always calibrates to max value of 0x3f, force enable it
8014 * and set it to a reasonable value instead.
8016 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
8017 reg_val &= 0xffffff00;
8018 reg_val |= 0x00000030;
8019 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
8021 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
8022 reg_val &= 0x00ffffff;
8023 reg_val |= 0x8c000000;
8024 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
8026 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
8027 reg_val &= 0xffffff00;
8028 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
8030 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
8031 reg_val &= 0x00ffffff;
8032 reg_val |= 0xb0000000;
8033 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
8036 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
8037 const struct intel_link_m_n *m_n)
8039 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8040 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8041 enum pipe pipe = crtc->pipe;
8043 intel_de_write(dev_priv, PCH_TRANS_DATA_M1(pipe),
8044 TU_SIZE(m_n->tu) | m_n->gmch_m);
8045 intel_de_write(dev_priv, PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
8046 intel_de_write(dev_priv, PCH_TRANS_LINK_M1(pipe), m_n->link_m);
8047 intel_de_write(dev_priv, PCH_TRANS_LINK_N1(pipe), m_n->link_n);
8050 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
8051 enum transcoder transcoder)
8053 if (IS_HASWELL(dev_priv))
8054 return transcoder == TRANSCODER_EDP;
8057 * Strictly speaking some registers are available before
8058 * gen7, but we only support DRRS on gen7+
8060 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
8063 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
8064 const struct intel_link_m_n *m_n,
8065 const struct intel_link_m_n *m2_n2)
8067 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8068 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8069 enum pipe pipe = crtc->pipe;
8070 enum transcoder transcoder = crtc_state->cpu_transcoder;
8072 if (INTEL_GEN(dev_priv) >= 5) {
8073 intel_de_write(dev_priv, PIPE_DATA_M1(transcoder),
8074 TU_SIZE(m_n->tu) | m_n->gmch_m);
8075 intel_de_write(dev_priv, PIPE_DATA_N1(transcoder),
8077 intel_de_write(dev_priv, PIPE_LINK_M1(transcoder),
8079 intel_de_write(dev_priv, PIPE_LINK_N1(transcoder),
8082 * M2_N2 registers are set only if DRRS is supported
8083 * (to make sure the registers are not unnecessarily accessed).
8085 if (m2_n2 && crtc_state->has_drrs &&
8086 transcoder_has_m2_n2(dev_priv, transcoder)) {
8087 intel_de_write(dev_priv, PIPE_DATA_M2(transcoder),
8088 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
8089 intel_de_write(dev_priv, PIPE_DATA_N2(transcoder),
8091 intel_de_write(dev_priv, PIPE_LINK_M2(transcoder),
8093 intel_de_write(dev_priv, PIPE_LINK_N2(transcoder),
8097 intel_de_write(dev_priv, PIPE_DATA_M_G4X(pipe),
8098 TU_SIZE(m_n->tu) | m_n->gmch_m);
8099 intel_de_write(dev_priv, PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
8100 intel_de_write(dev_priv, PIPE_LINK_M_G4X(pipe), m_n->link_m);
8101 intel_de_write(dev_priv, PIPE_LINK_N_G4X(pipe), m_n->link_n);
8105 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
8107 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
8108 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
8111 dp_m_n = &crtc_state->dp_m_n;
8112 dp_m2_n2 = &crtc_state->dp_m2_n2;
8113 } else if (m_n == M2_N2) {
8116 * M2_N2 registers are not supported. Hence m2_n2 divider value
8117 * needs to be programmed into M1_N1.
8119 dp_m_n = &crtc_state->dp_m2_n2;
8121 drm_err(&i915->drm, "Unsupported divider value\n");
8125 if (crtc_state->has_pch_encoder)
8126 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
8128 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
8131 static void vlv_compute_dpll(struct intel_crtc *crtc,
8132 struct intel_crtc_state *pipe_config)
8134 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
8135 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8136 if (crtc->pipe != PIPE_A)
8137 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8139 /* DPLL not used with DSI, but still need the rest set up */
8140 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8141 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
8142 DPLL_EXT_BUFFER_ENABLE_VLV;
8144 pipe_config->dpll_hw_state.dpll_md =
8145 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8148 static void chv_compute_dpll(struct intel_crtc *crtc,
8149 struct intel_crtc_state *pipe_config)
8151 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
8152 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8153 if (crtc->pipe != PIPE_A)
8154 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8156 /* DPLL not used with DSI, but still need the rest set up */
8157 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8158 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
8160 pipe_config->dpll_hw_state.dpll_md =
8161 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8164 static void vlv_prepare_pll(struct intel_crtc *crtc,
8165 const struct intel_crtc_state *pipe_config)
8167 struct drm_device *dev = crtc->base.dev;
8168 struct drm_i915_private *dev_priv = to_i915(dev);
8169 enum pipe pipe = crtc->pipe;
8171 u32 bestn, bestm1, bestm2, bestp1, bestp2;
8172 u32 coreclk, reg_val;
8175 intel_de_write(dev_priv, DPLL(pipe),
8176 pipe_config->dpll_hw_state.dpll & ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
8178 /* No need to actually set up the DPLL with DSI */
8179 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8182 vlv_dpio_get(dev_priv);
8184 bestn = pipe_config->dpll.n;
8185 bestm1 = pipe_config->dpll.m1;
8186 bestm2 = pipe_config->dpll.m2;
8187 bestp1 = pipe_config->dpll.p1;
8188 bestp2 = pipe_config->dpll.p2;
8190 /* See eDP HDMI DPIO driver vbios notes doc */
8192 /* PLL B needs special handling */
8194 vlv_pllb_recal_opamp(dev_priv, pipe);
8196 /* Set up Tx target for periodic Rcomp update */
8197 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
8199 /* Disable target IRef on PLL */
8200 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
8201 reg_val &= 0x00ffffff;
8202 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
8204 /* Disable fast lock */
8205 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
8207 /* Set idtafcrecal before PLL is enabled */
8208 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
8209 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
8210 mdiv |= ((bestn << DPIO_N_SHIFT));
8211 mdiv |= (1 << DPIO_K_SHIFT);
8214 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
8215 * but we don't support that).
8216 * Note: don't use the DAC post divider as it seems unstable.
8218 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
8219 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8221 mdiv |= DPIO_ENABLE_CALIBRATION;
8222 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8224 /* Set HBR and RBR LPF coefficients */
8225 if (pipe_config->port_clock == 162000 ||
8226 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
8227 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
8228 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8231 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8234 if (intel_crtc_has_dp_encoder(pipe_config)) {
8235 /* Use SSC source */
8237 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8240 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8242 } else { /* HDMI or VGA */
8243 /* Use bend source */
8245 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8248 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8252 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
8253 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
8254 if (intel_crtc_has_dp_encoder(pipe_config))
8255 coreclk |= 0x01000000;
8256 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
8258 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
8260 vlv_dpio_put(dev_priv);
8263 static void chv_prepare_pll(struct intel_crtc *crtc,
8264 const struct intel_crtc_state *pipe_config)
8266 struct drm_device *dev = crtc->base.dev;
8267 struct drm_i915_private *dev_priv = to_i915(dev);
8268 enum pipe pipe = crtc->pipe;
8269 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8270 u32 loopfilter, tribuf_calcntr;
8271 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
8275 /* Enable Refclk and SSC */
8276 intel_de_write(dev_priv, DPLL(pipe),
8277 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
8279 /* No need to actually set up the DPLL with DSI */
8280 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8283 bestn = pipe_config->dpll.n;
8284 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
8285 bestm1 = pipe_config->dpll.m1;
8286 bestm2 = pipe_config->dpll.m2 >> 22;
8287 bestp1 = pipe_config->dpll.p1;
8288 bestp2 = pipe_config->dpll.p2;
8289 vco = pipe_config->dpll.vco;
8293 vlv_dpio_get(dev_priv);
8295 /* p1 and p2 divider */
8296 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
8297 5 << DPIO_CHV_S1_DIV_SHIFT |
8298 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
8299 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
8300 1 << DPIO_CHV_K_DIV_SHIFT);
8302 /* Feedback post-divider - m2 */
8303 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
8305 /* Feedback refclk divider - n and m1 */
8306 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
8307 DPIO_CHV_M1_DIV_BY_2 |
8308 1 << DPIO_CHV_N_DIV_SHIFT);
8310 /* M2 fraction division */
8311 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
8313 /* M2 fraction division enable */
8314 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8315 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
8316 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
8318 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
8319 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
8321 /* Program digital lock detect threshold */
8322 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
8323 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
8324 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
8325 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
8327 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
8328 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
8331 if (vco == 5400000) {
8332 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
8333 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
8334 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
8335 tribuf_calcntr = 0x9;
8336 } else if (vco <= 6200000) {
8337 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
8338 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
8339 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8340 tribuf_calcntr = 0x9;
8341 } else if (vco <= 6480000) {
8342 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8343 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8344 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8345 tribuf_calcntr = 0x8;
8347 /* Not supported. Apply the same limits as in the max case */
8348 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8349 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8350 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8353 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
8355 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
8356 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
8357 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
8358 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
8361 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
8362 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
8365 vlv_dpio_put(dev_priv);
8369 * vlv_force_pll_on - forcibly enable just the PLL
8370 * @dev_priv: i915 private structure
8371 * @pipe: pipe PLL to enable
8372 * @dpll: PLL configuration
8374 * Enable the PLL for @pipe using the supplied @dpll config. To be used
8375 * in cases where we need the PLL enabled even when @pipe is not going to
8378 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
8379 const struct dpll *dpll)
8381 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
8382 struct intel_crtc_state *pipe_config;
8384 pipe_config = intel_crtc_state_alloc(crtc);
8388 pipe_config->cpu_transcoder = (enum transcoder)pipe;
8389 pipe_config->pixel_multiplier = 1;
8390 pipe_config->dpll = *dpll;
8392 if (IS_CHERRYVIEW(dev_priv)) {
8393 chv_compute_dpll(crtc, pipe_config);
8394 chv_prepare_pll(crtc, pipe_config);
8395 chv_enable_pll(crtc, pipe_config);
8397 vlv_compute_dpll(crtc, pipe_config);
8398 vlv_prepare_pll(crtc, pipe_config);
8399 vlv_enable_pll(crtc, pipe_config);
8408 * vlv_force_pll_off - forcibly disable just the PLL
8409 * @dev_priv: i915 private structure
8410 * @pipe: pipe PLL to disable
8412 * Disable the PLL for @pipe. To be used in cases where we need
8413 * the PLL enabled even when @pipe is not going to be enabled.
8415 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
8417 if (IS_CHERRYVIEW(dev_priv))
8418 chv_disable_pll(dev_priv, pipe);
8420 vlv_disable_pll(dev_priv, pipe);
8423 static void i9xx_compute_dpll(struct intel_crtc *crtc,
8424 struct intel_crtc_state *crtc_state,
8425 struct dpll *reduced_clock)
8427 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8429 struct dpll *clock = &crtc_state->dpll;
8431 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8433 dpll = DPLL_VGA_MODE_DIS;
8435 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8436 dpll |= DPLLB_MODE_LVDS;
8438 dpll |= DPLLB_MODE_DAC_SERIAL;
8440 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8441 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8442 dpll |= (crtc_state->pixel_multiplier - 1)
8443 << SDVO_MULTIPLIER_SHIFT_HIRES;
8446 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8447 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8448 dpll |= DPLL_SDVO_HIGH_SPEED;
8450 if (intel_crtc_has_dp_encoder(crtc_state))
8451 dpll |= DPLL_SDVO_HIGH_SPEED;
8453 /* compute bitmask from p1 value */
8454 if (IS_PINEVIEW(dev_priv))
8455 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8457 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8458 if (IS_G4X(dev_priv) && reduced_clock)
8459 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8461 switch (clock->p2) {
8463 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8466 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8469 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8472 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8475 if (INTEL_GEN(dev_priv) >= 4)
8476 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8478 if (crtc_state->sdvo_tv_clock)
8479 dpll |= PLL_REF_INPUT_TVCLKINBC;
8480 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8481 intel_panel_use_ssc(dev_priv))
8482 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8484 dpll |= PLL_REF_INPUT_DREFCLK;
8486 dpll |= DPLL_VCO_ENABLE;
8487 crtc_state->dpll_hw_state.dpll = dpll;
8489 if (INTEL_GEN(dev_priv) >= 4) {
8490 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8491 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8492 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8496 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8497 struct intel_crtc_state *crtc_state,
8498 struct dpll *reduced_clock)
8500 struct drm_device *dev = crtc->base.dev;
8501 struct drm_i915_private *dev_priv = to_i915(dev);
8503 struct dpll *clock = &crtc_state->dpll;
8505 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8507 dpll = DPLL_VGA_MODE_DIS;
8509 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8510 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8513 dpll |= PLL_P1_DIVIDE_BY_TWO;
8515 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8517 dpll |= PLL_P2_DIVIDE_BY_4;
8522 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8523 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8524 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8525 * Enable) must be set to “1” in both the DPLL A Control Register
8526 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8528 * For simplicity We simply keep both bits always enabled in
8529 * both DPLLS. The spec says we should disable the DVO 2X clock
8530 * when not needed, but this seems to work fine in practice.
8532 if (IS_I830(dev_priv) ||
8533 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8534 dpll |= DPLL_DVO_2X_MODE;
8536 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8537 intel_panel_use_ssc(dev_priv))
8538 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8540 dpll |= PLL_REF_INPUT_DREFCLK;
8542 dpll |= DPLL_VCO_ENABLE;
8543 crtc_state->dpll_hw_state.dpll = dpll;
8546 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
8548 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8549 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8550 enum pipe pipe = crtc->pipe;
8551 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8552 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
8553 u32 crtc_vtotal, crtc_vblank_end;
8556 /* We need to be careful not to changed the adjusted mode, for otherwise
8557 * the hw state checker will get angry at the mismatch. */
8558 crtc_vtotal = adjusted_mode->crtc_vtotal;
8559 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8561 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8562 /* the chip adds 2 halflines automatically */
8564 crtc_vblank_end -= 1;
8566 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8567 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8569 vsyncshift = adjusted_mode->crtc_hsync_start -
8570 adjusted_mode->crtc_htotal / 2;
8572 vsyncshift += adjusted_mode->crtc_htotal;
8575 if (INTEL_GEN(dev_priv) > 3)
8576 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder),
8579 intel_de_write(dev_priv, HTOTAL(cpu_transcoder),
8580 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
8581 intel_de_write(dev_priv, HBLANK(cpu_transcoder),
8582 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
8583 intel_de_write(dev_priv, HSYNC(cpu_transcoder),
8584 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
8586 intel_de_write(dev_priv, VTOTAL(cpu_transcoder),
8587 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16));
8588 intel_de_write(dev_priv, VBLANK(cpu_transcoder),
8589 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16));
8590 intel_de_write(dev_priv, VSYNC(cpu_transcoder),
8591 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
8593 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8594 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8595 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8597 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8598 (pipe == PIPE_B || pipe == PIPE_C))
8599 intel_de_write(dev_priv, VTOTAL(pipe),
8600 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
8604 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8606 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8607 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8608 enum pipe pipe = crtc->pipe;
8610 /* pipesrc controls the size that is scaled from, which should
8611 * always be the user's requested size.
8613 intel_de_write(dev_priv, PIPESRC(pipe),
8614 ((crtc_state->pipe_src_w - 1) << 16) | (crtc_state->pipe_src_h - 1));
8617 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
8619 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
8620 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8622 if (IS_GEN(dev_priv, 2))
8625 if (INTEL_GEN(dev_priv) >= 9 ||
8626 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
8627 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
8629 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
8632 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
8633 struct intel_crtc_state *pipe_config)
8635 struct drm_device *dev = crtc->base.dev;
8636 struct drm_i915_private *dev_priv = to_i915(dev);
8637 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8640 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder));
8641 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8642 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8644 if (!transcoder_is_dsi(cpu_transcoder)) {
8645 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder));
8646 pipe_config->hw.adjusted_mode.crtc_hblank_start =
8648 pipe_config->hw.adjusted_mode.crtc_hblank_end =
8649 ((tmp >> 16) & 0xffff) + 1;
8651 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder));
8652 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8653 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8655 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder));
8656 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8657 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8659 if (!transcoder_is_dsi(cpu_transcoder)) {
8660 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder));
8661 pipe_config->hw.adjusted_mode.crtc_vblank_start =
8663 pipe_config->hw.adjusted_mode.crtc_vblank_end =
8664 ((tmp >> 16) & 0xffff) + 1;
8666 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder));
8667 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8668 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8670 if (intel_pipe_is_interlaced(pipe_config)) {
8671 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8672 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
8673 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
8677 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8678 struct intel_crtc_state *pipe_config)
8680 struct drm_device *dev = crtc->base.dev;
8681 struct drm_i915_private *dev_priv = to_i915(dev);
8684 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
8685 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8686 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8689 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8691 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8692 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8697 /* we keep both pipes enabled on 830 */
8698 if (IS_I830(dev_priv))
8699 pipeconf |= intel_de_read(dev_priv, PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8701 if (crtc_state->double_wide)
8702 pipeconf |= PIPECONF_DOUBLE_WIDE;
8704 /* only g4x and later have fancy bpc/dither controls */
8705 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8706 IS_CHERRYVIEW(dev_priv)) {
8707 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8708 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8709 pipeconf |= PIPECONF_DITHER_EN |
8710 PIPECONF_DITHER_TYPE_SP;
8712 switch (crtc_state->pipe_bpp) {
8714 pipeconf |= PIPECONF_6BPC;
8717 pipeconf |= PIPECONF_8BPC;
8720 pipeconf |= PIPECONF_10BPC;
8723 /* Case prevented by intel_choose_pipe_bpp_dither. */
8728 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8729 if (INTEL_GEN(dev_priv) < 4 ||
8730 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8731 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8733 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8735 pipeconf |= PIPECONF_PROGRESSIVE;
8738 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8739 crtc_state->limited_color_range)
8740 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8742 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8744 pipeconf |= PIPECONF_FRAME_START_DELAY(0);
8746 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf);
8747 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe));
8750 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8751 struct intel_crtc_state *crtc_state)
8753 struct drm_device *dev = crtc->base.dev;
8754 struct drm_i915_private *dev_priv = to_i915(dev);
8755 const struct intel_limit *limit;
8758 memset(&crtc_state->dpll_hw_state, 0,
8759 sizeof(crtc_state->dpll_hw_state));
8761 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8762 if (intel_panel_use_ssc(dev_priv)) {
8763 refclk = dev_priv->vbt.lvds_ssc_freq;
8764 drm_dbg_kms(&dev_priv->drm,
8765 "using SSC reference clock of %d kHz\n",
8769 limit = &intel_limits_i8xx_lvds;
8770 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8771 limit = &intel_limits_i8xx_dvo;
8773 limit = &intel_limits_i8xx_dac;
8776 if (!crtc_state->clock_set &&
8777 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8778 refclk, NULL, &crtc_state->dpll)) {
8779 drm_err(&dev_priv->drm,
8780 "Couldn't find PLL settings for mode!\n");
8784 i8xx_compute_dpll(crtc, crtc_state, NULL);
8789 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
8790 struct intel_crtc_state *crtc_state)
8792 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8793 const struct intel_limit *limit;
8796 memset(&crtc_state->dpll_hw_state, 0,
8797 sizeof(crtc_state->dpll_hw_state));
8799 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8800 if (intel_panel_use_ssc(dev_priv)) {
8801 refclk = dev_priv->vbt.lvds_ssc_freq;
8802 drm_dbg_kms(&dev_priv->drm,
8803 "using SSC reference clock of %d kHz\n",
8807 if (intel_is_dual_link_lvds(dev_priv))
8808 limit = &intel_limits_g4x_dual_channel_lvds;
8810 limit = &intel_limits_g4x_single_channel_lvds;
8811 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
8812 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
8813 limit = &intel_limits_g4x_hdmi;
8814 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
8815 limit = &intel_limits_g4x_sdvo;
8817 /* The option is for other outputs */
8818 limit = &intel_limits_i9xx_sdvo;
8821 if (!crtc_state->clock_set &&
8822 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8823 refclk, NULL, &crtc_state->dpll)) {
8824 drm_err(&dev_priv->drm,
8825 "Couldn't find PLL settings for mode!\n");
8829 i9xx_compute_dpll(crtc, crtc_state, NULL);
8834 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
8835 struct intel_crtc_state *crtc_state)
8837 struct drm_device *dev = crtc->base.dev;
8838 struct drm_i915_private *dev_priv = to_i915(dev);
8839 const struct intel_limit *limit;
8842 memset(&crtc_state->dpll_hw_state, 0,
8843 sizeof(crtc_state->dpll_hw_state));
8845 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8846 if (intel_panel_use_ssc(dev_priv)) {
8847 refclk = dev_priv->vbt.lvds_ssc_freq;
8848 drm_dbg_kms(&dev_priv->drm,
8849 "using SSC reference clock of %d kHz\n",
8853 limit = &pnv_limits_lvds;
8855 limit = &pnv_limits_sdvo;
8858 if (!crtc_state->clock_set &&
8859 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8860 refclk, NULL, &crtc_state->dpll)) {
8861 drm_err(&dev_priv->drm,
8862 "Couldn't find PLL settings for mode!\n");
8866 i9xx_compute_dpll(crtc, crtc_state, NULL);
8871 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
8872 struct intel_crtc_state *crtc_state)
8874 struct drm_device *dev = crtc->base.dev;
8875 struct drm_i915_private *dev_priv = to_i915(dev);
8876 const struct intel_limit *limit;
8879 memset(&crtc_state->dpll_hw_state, 0,
8880 sizeof(crtc_state->dpll_hw_state));
8882 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8883 if (intel_panel_use_ssc(dev_priv)) {
8884 refclk = dev_priv->vbt.lvds_ssc_freq;
8885 drm_dbg_kms(&dev_priv->drm,
8886 "using SSC reference clock of %d kHz\n",
8890 limit = &intel_limits_i9xx_lvds;
8892 limit = &intel_limits_i9xx_sdvo;
8895 if (!crtc_state->clock_set &&
8896 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8897 refclk, NULL, &crtc_state->dpll)) {
8898 drm_err(&dev_priv->drm,
8899 "Couldn't find PLL settings for mode!\n");
8903 i9xx_compute_dpll(crtc, crtc_state, NULL);
8908 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
8909 struct intel_crtc_state *crtc_state)
8911 int refclk = 100000;
8912 const struct intel_limit *limit = &intel_limits_chv;
8913 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
8915 memset(&crtc_state->dpll_hw_state, 0,
8916 sizeof(crtc_state->dpll_hw_state));
8918 if (!crtc_state->clock_set &&
8919 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8920 refclk, NULL, &crtc_state->dpll)) {
8921 drm_err(&i915->drm, "Couldn't find PLL settings for mode!\n");
8925 chv_compute_dpll(crtc, crtc_state);
8930 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
8931 struct intel_crtc_state *crtc_state)
8933 int refclk = 100000;
8934 const struct intel_limit *limit = &intel_limits_vlv;
8935 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
8937 memset(&crtc_state->dpll_hw_state, 0,
8938 sizeof(crtc_state->dpll_hw_state));
8940 if (!crtc_state->clock_set &&
8941 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8942 refclk, NULL, &crtc_state->dpll)) {
8943 drm_err(&i915->drm, "Couldn't find PLL settings for mode!\n");
8947 vlv_compute_dpll(crtc, crtc_state);
8952 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
8954 if (IS_I830(dev_priv))
8957 return INTEL_GEN(dev_priv) >= 4 ||
8958 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
8961 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
8963 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8964 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8967 if (!i9xx_has_pfit(dev_priv))
8970 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
8971 if (!(tmp & PFIT_ENABLE))
8974 /* Check whether the pfit is attached to our pipe. */
8975 if (INTEL_GEN(dev_priv) < 4) {
8976 if (crtc->pipe != PIPE_B)
8979 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
8983 crtc_state->gmch_pfit.control = tmp;
8984 crtc_state->gmch_pfit.pgm_ratios =
8985 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
8988 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
8989 struct intel_crtc_state *pipe_config)
8991 struct drm_device *dev = crtc->base.dev;
8992 struct drm_i915_private *dev_priv = to_i915(dev);
8993 enum pipe pipe = crtc->pipe;
8996 int refclk = 100000;
8998 /* In case of DSI, DPLL will not be used */
8999 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
9002 vlv_dpio_get(dev_priv);
9003 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
9004 vlv_dpio_put(dev_priv);
9006 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
9007 clock.m2 = mdiv & DPIO_M2DIV_MASK;
9008 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
9009 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
9010 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
9012 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
9016 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
9017 struct intel_initial_plane_config *plane_config)
9019 struct drm_device *dev = crtc->base.dev;
9020 struct drm_i915_private *dev_priv = to_i915(dev);
9021 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9022 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
9024 u32 val, base, offset;
9025 int fourcc, pixel_format;
9026 unsigned int aligned_height;
9027 struct drm_framebuffer *fb;
9028 struct intel_framebuffer *intel_fb;
9030 if (!plane->get_hw_state(plane, &pipe))
9033 drm_WARN_ON(dev, pipe != crtc->pipe);
9035 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9037 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
9041 fb = &intel_fb->base;
9045 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
9047 if (INTEL_GEN(dev_priv) >= 4) {
9048 if (val & DISPPLANE_TILED) {
9049 plane_config->tiling = I915_TILING_X;
9050 fb->modifier = I915_FORMAT_MOD_X_TILED;
9053 if (val & DISPPLANE_ROTATE_180)
9054 plane_config->rotation = DRM_MODE_ROTATE_180;
9057 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
9058 val & DISPPLANE_MIRROR)
9059 plane_config->rotation |= DRM_MODE_REFLECT_X;
9061 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
9062 fourcc = i9xx_format_to_fourcc(pixel_format);
9063 fb->format = drm_format_info(fourcc);
9065 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
9066 offset = intel_de_read(dev_priv, DSPOFFSET(i9xx_plane));
9067 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
9068 } else if (INTEL_GEN(dev_priv) >= 4) {
9069 if (plane_config->tiling)
9070 offset = intel_de_read(dev_priv,
9071 DSPTILEOFF(i9xx_plane));
9073 offset = intel_de_read(dev_priv,
9074 DSPLINOFF(i9xx_plane));
9075 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
9077 base = intel_de_read(dev_priv, DSPADDR(i9xx_plane));
9079 plane_config->base = base;
9081 val = intel_de_read(dev_priv, PIPESRC(pipe));
9082 fb->width = ((val >> 16) & 0xfff) + 1;
9083 fb->height = ((val >> 0) & 0xfff) + 1;
9085 val = intel_de_read(dev_priv, DSPSTRIDE(i9xx_plane));
9086 fb->pitches[0] = val & 0xffffffc0;
9088 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9090 plane_config->size = fb->pitches[0] * aligned_height;
9092 drm_dbg_kms(&dev_priv->drm,
9093 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9094 crtc->base.name, plane->base.name, fb->width, fb->height,
9095 fb->format->cpp[0] * 8, base, fb->pitches[0],
9096 plane_config->size);
9098 plane_config->fb = intel_fb;
9101 static void chv_crtc_clock_get(struct intel_crtc *crtc,
9102 struct intel_crtc_state *pipe_config)
9104 struct drm_device *dev = crtc->base.dev;
9105 struct drm_i915_private *dev_priv = to_i915(dev);
9106 enum pipe pipe = crtc->pipe;
9107 enum dpio_channel port = vlv_pipe_to_channel(pipe);
9109 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
9110 int refclk = 100000;
9112 /* In case of DSI, DPLL will not be used */
9113 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
9116 vlv_dpio_get(dev_priv);
9117 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
9118 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
9119 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
9120 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
9121 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
9122 vlv_dpio_put(dev_priv);
9124 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
9125 clock.m2 = (pll_dw0 & 0xff) << 22;
9126 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
9127 clock.m2 |= pll_dw2 & 0x3fffff;
9128 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
9129 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
9130 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
9132 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
9135 static enum intel_output_format
9136 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
9138 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9141 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
9143 if (tmp & PIPEMISC_YUV420_ENABLE) {
9144 /* We support 4:2:0 in full blend mode only */
9145 drm_WARN_ON(&dev_priv->drm,
9146 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
9148 return INTEL_OUTPUT_FORMAT_YCBCR420;
9149 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
9150 return INTEL_OUTPUT_FORMAT_YCBCR444;
9152 return INTEL_OUTPUT_FORMAT_RGB;
9156 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
9158 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9159 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9160 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9161 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
9164 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
9166 if (tmp & DISPPLANE_GAMMA_ENABLE)
9167 crtc_state->gamma_enable = true;
9169 if (!HAS_GMCH(dev_priv) &&
9170 tmp & DISPPLANE_PIPE_CSC_ENABLE)
9171 crtc_state->csc_enable = true;
9174 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
9175 struct intel_crtc_state *pipe_config)
9177 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9178 enum intel_display_power_domain power_domain;
9179 intel_wakeref_t wakeref;
9183 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9184 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9188 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9189 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9190 pipe_config->shared_dpll = NULL;
9194 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
9195 if (!(tmp & PIPECONF_ENABLE))
9198 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
9199 IS_CHERRYVIEW(dev_priv)) {
9200 switch (tmp & PIPECONF_BPC_MASK) {
9202 pipe_config->pipe_bpp = 18;
9205 pipe_config->pipe_bpp = 24;
9207 case PIPECONF_10BPC:
9208 pipe_config->pipe_bpp = 30;
9215 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
9216 (tmp & PIPECONF_COLOR_RANGE_SELECT))
9217 pipe_config->limited_color_range = true;
9219 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
9220 PIPECONF_GAMMA_MODE_SHIFT;
9222 if (IS_CHERRYVIEW(dev_priv))
9223 pipe_config->cgm_mode = intel_de_read(dev_priv,
9224 CGM_PIPE_MODE(crtc->pipe));
9226 i9xx_get_pipe_color_config(pipe_config);
9227 intel_color_get_config(pipe_config);
9229 if (INTEL_GEN(dev_priv) < 4)
9230 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
9232 intel_get_transcoder_timings(crtc, pipe_config);
9233 intel_get_pipe_src_size(crtc, pipe_config);
9235 i9xx_get_pfit_config(pipe_config);
9237 if (INTEL_GEN(dev_priv) >= 4) {
9238 /* No way to read it out on pipes B and C */
9239 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
9240 tmp = dev_priv->chv_dpll_md[crtc->pipe];
9242 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
9243 pipe_config->pixel_multiplier =
9244 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
9245 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
9246 pipe_config->dpll_hw_state.dpll_md = tmp;
9247 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
9248 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
9249 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
9250 pipe_config->pixel_multiplier =
9251 ((tmp & SDVO_MULTIPLIER_MASK)
9252 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
9254 /* Note that on i915G/GM the pixel multiplier is in the sdvo
9255 * port and will be fixed up in the encoder->get_config
9257 pipe_config->pixel_multiplier = 1;
9259 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
9261 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
9262 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
9264 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
9267 /* Mask out read-only status bits. */
9268 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
9269 DPLL_PORTC_READY_MASK |
9270 DPLL_PORTB_READY_MASK);
9273 if (IS_CHERRYVIEW(dev_priv))
9274 chv_crtc_clock_get(crtc, pipe_config);
9275 else if (IS_VALLEYVIEW(dev_priv))
9276 vlv_crtc_clock_get(crtc, pipe_config);
9278 i9xx_crtc_clock_get(crtc, pipe_config);
9281 * Normally the dotclock is filled in by the encoder .get_config()
9282 * but in case the pipe is enabled w/o any ports we need a sane
9285 pipe_config->hw.adjusted_mode.crtc_clock =
9286 pipe_config->port_clock / pipe_config->pixel_multiplier;
9291 intel_display_power_put(dev_priv, power_domain, wakeref);
9296 static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv)
9298 struct intel_encoder *encoder;
9301 bool has_lvds = false;
9302 bool has_cpu_edp = false;
9303 bool has_panel = false;
9304 bool has_ck505 = false;
9305 bool can_ssc = false;
9306 bool using_ssc_source = false;
9308 /* We need to take the global config into account */
9309 for_each_intel_encoder(&dev_priv->drm, encoder) {
9310 switch (encoder->type) {
9311 case INTEL_OUTPUT_LVDS:
9315 case INTEL_OUTPUT_EDP:
9317 if (encoder->port == PORT_A)
9325 if (HAS_PCH_IBX(dev_priv)) {
9326 has_ck505 = dev_priv->vbt.display_clock_mode;
9327 can_ssc = has_ck505;
9333 /* Check if any DPLLs are using the SSC source */
9334 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++) {
9335 u32 temp = intel_de_read(dev_priv, PCH_DPLL(i));
9337 if (!(temp & DPLL_VCO_ENABLE))
9340 if ((temp & PLL_REF_INPUT_MASK) ==
9341 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
9342 using_ssc_source = true;
9347 drm_dbg_kms(&dev_priv->drm,
9348 "has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
9349 has_panel, has_lvds, has_ck505, using_ssc_source);
9351 /* Ironlake: try to setup display ref clock before DPLL
9352 * enabling. This is only under driver's control after
9353 * PCH B stepping, previous chipset stepping should be
9354 * ignoring this setting.
9356 val = intel_de_read(dev_priv, PCH_DREF_CONTROL);
9358 /* As we must carefully and slowly disable/enable each source in turn,
9359 * compute the final state we want first and check if we need to
9360 * make any changes at all.
9363 final &= ~DREF_NONSPREAD_SOURCE_MASK;
9365 final |= DREF_NONSPREAD_CK505_ENABLE;
9367 final |= DREF_NONSPREAD_SOURCE_ENABLE;
9369 final &= ~DREF_SSC_SOURCE_MASK;
9370 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9371 final &= ~DREF_SSC1_ENABLE;
9374 final |= DREF_SSC_SOURCE_ENABLE;
9376 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9377 final |= DREF_SSC1_ENABLE;
9380 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9381 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9383 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9385 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9386 } else if (using_ssc_source) {
9387 final |= DREF_SSC_SOURCE_ENABLE;
9388 final |= DREF_SSC1_ENABLE;
9394 /* Always enable nonspread source */
9395 val &= ~DREF_NONSPREAD_SOURCE_MASK;
9398 val |= DREF_NONSPREAD_CK505_ENABLE;
9400 val |= DREF_NONSPREAD_SOURCE_ENABLE;
9403 val &= ~DREF_SSC_SOURCE_MASK;
9404 val |= DREF_SSC_SOURCE_ENABLE;
9406 /* SSC must be turned on before enabling the CPU output */
9407 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9408 drm_dbg_kms(&dev_priv->drm, "Using SSC on panel\n");
9409 val |= DREF_SSC1_ENABLE;
9411 val &= ~DREF_SSC1_ENABLE;
9413 /* Get SSC going before enabling the outputs */
9414 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9415 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9418 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9420 /* Enable CPU source on CPU attached eDP */
9422 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9423 drm_dbg_kms(&dev_priv->drm,
9424 "Using SSC on eDP\n");
9425 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9427 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9429 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9431 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9432 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9435 drm_dbg_kms(&dev_priv->drm, "Disabling CPU source output\n");
9437 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9439 /* Turn off CPU output */
9440 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9442 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9443 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9446 if (!using_ssc_source) {
9447 drm_dbg_kms(&dev_priv->drm, "Disabling SSC source\n");
9449 /* Turn off the SSC source */
9450 val &= ~DREF_SSC_SOURCE_MASK;
9451 val |= DREF_SSC_SOURCE_DISABLE;
9454 val &= ~DREF_SSC1_ENABLE;
9456 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9457 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9462 BUG_ON(val != final);
9465 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9469 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
9470 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9471 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
9473 if (wait_for_us(intel_de_read(dev_priv, SOUTH_CHICKEN2) &
9474 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9475 drm_err(&dev_priv->drm, "FDI mPHY reset assert timeout\n");
9477 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
9478 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9479 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
9481 if (wait_for_us((intel_de_read(dev_priv, SOUTH_CHICKEN2) &
9482 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9483 drm_err(&dev_priv->drm, "FDI mPHY reset de-assert timeout\n");
9486 /* WaMPhyProgramming:hsw */
9487 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9491 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9492 tmp &= ~(0xFF << 24);
9493 tmp |= (0x12 << 24);
9494 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9496 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9498 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9500 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9502 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9504 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9505 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9506 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9508 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9509 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9510 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9512 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9515 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9517 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9520 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9522 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9525 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9527 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9530 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9532 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9533 tmp &= ~(0xFF << 16);
9534 tmp |= (0x1C << 16);
9535 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9537 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9538 tmp &= ~(0xFF << 16);
9539 tmp |= (0x1C << 16);
9540 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9542 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9544 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9546 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9548 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9550 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9551 tmp &= ~(0xF << 28);
9553 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9555 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9556 tmp &= ~(0xF << 28);
9558 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9561 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9562 * Programming" based on the parameters passed:
9563 * - Sequence to enable CLKOUT_DP
9564 * - Sequence to enable CLKOUT_DP without spread
9565 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9567 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9568 bool with_spread, bool with_fdi)
9572 if (drm_WARN(&dev_priv->drm, with_fdi && !with_spread,
9573 "FDI requires downspread\n"))
9575 if (drm_WARN(&dev_priv->drm, HAS_PCH_LPT_LP(dev_priv) &&
9576 with_fdi, "LP PCH doesn't have FDI\n"))
9579 mutex_lock(&dev_priv->sb_lock);
9581 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9582 tmp &= ~SBI_SSCCTL_DISABLE;
9583 tmp |= SBI_SSCCTL_PATHALT;
9584 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9589 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9590 tmp &= ~SBI_SSCCTL_PATHALT;
9591 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9594 lpt_reset_fdi_mphy(dev_priv);
9595 lpt_program_fdi_mphy(dev_priv);
9599 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9600 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9601 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9602 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9604 mutex_unlock(&dev_priv->sb_lock);
9607 /* Sequence to disable CLKOUT_DP */
9608 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9612 mutex_lock(&dev_priv->sb_lock);
9614 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9615 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9616 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9617 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9619 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9620 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9621 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9622 tmp |= SBI_SSCCTL_PATHALT;
9623 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9626 tmp |= SBI_SSCCTL_DISABLE;
9627 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9630 mutex_unlock(&dev_priv->sb_lock);
9633 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9635 static const u16 sscdivintphase[] = {
9636 [BEND_IDX( 50)] = 0x3B23,
9637 [BEND_IDX( 45)] = 0x3B23,
9638 [BEND_IDX( 40)] = 0x3C23,
9639 [BEND_IDX( 35)] = 0x3C23,
9640 [BEND_IDX( 30)] = 0x3D23,
9641 [BEND_IDX( 25)] = 0x3D23,
9642 [BEND_IDX( 20)] = 0x3E23,
9643 [BEND_IDX( 15)] = 0x3E23,
9644 [BEND_IDX( 10)] = 0x3F23,
9645 [BEND_IDX( 5)] = 0x3F23,
9646 [BEND_IDX( 0)] = 0x0025,
9647 [BEND_IDX( -5)] = 0x0025,
9648 [BEND_IDX(-10)] = 0x0125,
9649 [BEND_IDX(-15)] = 0x0125,
9650 [BEND_IDX(-20)] = 0x0225,
9651 [BEND_IDX(-25)] = 0x0225,
9652 [BEND_IDX(-30)] = 0x0325,
9653 [BEND_IDX(-35)] = 0x0325,
9654 [BEND_IDX(-40)] = 0x0425,
9655 [BEND_IDX(-45)] = 0x0425,
9656 [BEND_IDX(-50)] = 0x0525,
9661 * steps -50 to 50 inclusive, in steps of 5
9662 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9663 * change in clock period = -(steps / 10) * 5.787 ps
9665 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9668 int idx = BEND_IDX(steps);
9670 if (drm_WARN_ON(&dev_priv->drm, steps % 5 != 0))
9673 if (drm_WARN_ON(&dev_priv->drm, idx >= ARRAY_SIZE(sscdivintphase)))
9676 mutex_lock(&dev_priv->sb_lock);
9678 if (steps % 10 != 0)
9682 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9684 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9686 tmp |= sscdivintphase[idx];
9687 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9689 mutex_unlock(&dev_priv->sb_lock);
9694 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9696 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
9697 u32 ctl = intel_de_read(dev_priv, SPLL_CTL);
9699 if ((ctl & SPLL_PLL_ENABLE) == 0)
9702 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9703 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9706 if (IS_BROADWELL(dev_priv) &&
9707 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9713 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9714 enum intel_dpll_id id)
9716 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
9717 u32 ctl = intel_de_read(dev_priv, WRPLL_CTL(id));
9719 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9722 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9725 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9726 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9727 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9733 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9735 struct intel_encoder *encoder;
9736 bool has_fdi = false;
9738 for_each_intel_encoder(&dev_priv->drm, encoder) {
9739 switch (encoder->type) {
9740 case INTEL_OUTPUT_ANALOG:
9749 * The BIOS may have decided to use the PCH SSC
9750 * reference so we must not disable it until the
9751 * relevant PLLs have stopped relying on it. We'll
9752 * just leave the PCH SSC reference enabled in case
9753 * any active PLL is using it. It will get disabled
9754 * after runtime suspend if we don't have FDI.
9756 * TODO: Move the whole reference clock handling
9757 * to the modeset sequence proper so that we can
9758 * actually enable/disable/reconfigure these things
9759 * safely. To do that we need to introduce a real
9760 * clock hierarchy. That would also allow us to do
9761 * clock bending finally.
9763 dev_priv->pch_ssc_use = 0;
9765 if (spll_uses_pch_ssc(dev_priv)) {
9766 drm_dbg_kms(&dev_priv->drm, "SPLL using PCH SSC\n");
9767 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
9770 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9771 drm_dbg_kms(&dev_priv->drm, "WRPLL1 using PCH SSC\n");
9772 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
9775 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9776 drm_dbg_kms(&dev_priv->drm, "WRPLL2 using PCH SSC\n");
9777 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
9780 if (dev_priv->pch_ssc_use)
9784 lpt_bend_clkout_dp(dev_priv, 0);
9785 lpt_enable_clkout_dp(dev_priv, true, true);
9787 lpt_disable_clkout_dp(dev_priv);
9792 * Initialize reference clocks when the driver loads
9794 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
9796 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
9797 ilk_init_pch_refclk(dev_priv);
9798 else if (HAS_PCH_LPT(dev_priv))
9799 lpt_init_pch_refclk(dev_priv);
9802 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
9804 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9805 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9806 enum pipe pipe = crtc->pipe;
9811 switch (crtc_state->pipe_bpp) {
9813 val |= PIPECONF_6BPC;
9816 val |= PIPECONF_8BPC;
9819 val |= PIPECONF_10BPC;
9822 val |= PIPECONF_12BPC;
9825 /* Case prevented by intel_choose_pipe_bpp_dither. */
9829 if (crtc_state->dither)
9830 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9832 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9833 val |= PIPECONF_INTERLACED_ILK;
9835 val |= PIPECONF_PROGRESSIVE;
9838 * This would end up with an odd purple hue over
9839 * the entire display. Make sure we don't do it.
9841 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
9842 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
9844 if (crtc_state->limited_color_range &&
9845 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
9846 val |= PIPECONF_COLOR_RANGE_SELECT;
9848 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
9849 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
9851 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
9853 val |= PIPECONF_FRAME_START_DELAY(0);
9855 intel_de_write(dev_priv, PIPECONF(pipe), val);
9856 intel_de_posting_read(dev_priv, PIPECONF(pipe));
9859 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state)
9861 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9862 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9863 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
9866 if (IS_HASWELL(dev_priv) && crtc_state->dither)
9867 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9869 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9870 val |= PIPECONF_INTERLACED_ILK;
9872 val |= PIPECONF_PROGRESSIVE;
9874 if (IS_HASWELL(dev_priv) &&
9875 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
9876 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
9878 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val);
9879 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder));
9882 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
9884 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9885 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9888 switch (crtc_state->pipe_bpp) {
9890 val |= PIPEMISC_DITHER_6_BPC;
9893 val |= PIPEMISC_DITHER_8_BPC;
9896 val |= PIPEMISC_DITHER_10_BPC;
9899 val |= PIPEMISC_DITHER_12_BPC;
9902 MISSING_CASE(crtc_state->pipe_bpp);
9906 if (crtc_state->dither)
9907 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
9909 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
9910 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
9911 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
9913 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
9914 val |= PIPEMISC_YUV420_ENABLE |
9915 PIPEMISC_YUV420_MODE_FULL_BLEND;
9917 if (INTEL_GEN(dev_priv) >= 11 &&
9918 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
9919 BIT(PLANE_CURSOR))) == 0)
9920 val |= PIPEMISC_HDR_MODE_PRECISION;
9922 if (INTEL_GEN(dev_priv) >= 12)
9923 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC;
9925 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val);
9928 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
9930 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9933 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
9935 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
9936 case PIPEMISC_DITHER_6_BPC:
9938 case PIPEMISC_DITHER_8_BPC:
9940 case PIPEMISC_DITHER_10_BPC:
9942 case PIPEMISC_DITHER_12_BPC:
9950 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
9953 * Account for spread spectrum to avoid
9954 * oversubscribing the link. Max center spread
9955 * is 2.5%; use 5% for safety's sake.
9957 u32 bps = target_clock * bpp * 21 / 20;
9958 return DIV_ROUND_UP(bps, link_bw * 8);
9961 static bool ilk_needs_fb_cb_tune(struct dpll *dpll, int factor)
9963 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
9966 static void ilk_compute_dpll(struct intel_crtc *crtc,
9967 struct intel_crtc_state *crtc_state,
9968 struct dpll *reduced_clock)
9970 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9974 /* Enable autotuning of the PLL clock (if permissible) */
9976 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9977 if ((intel_panel_use_ssc(dev_priv) &&
9978 dev_priv->vbt.lvds_ssc_freq == 100000) ||
9979 (HAS_PCH_IBX(dev_priv) &&
9980 intel_is_dual_link_lvds(dev_priv)))
9982 } else if (crtc_state->sdvo_tv_clock) {
9986 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
9988 if (ilk_needs_fb_cb_tune(&crtc_state->dpll, factor))
9991 if (reduced_clock) {
9992 fp2 = i9xx_dpll_compute_fp(reduced_clock);
9994 if (reduced_clock->m < factor * reduced_clock->n)
10002 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
10003 dpll |= DPLLB_MODE_LVDS;
10005 dpll |= DPLLB_MODE_DAC_SERIAL;
10007 dpll |= (crtc_state->pixel_multiplier - 1)
10008 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
10010 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
10011 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
10012 dpll |= DPLL_SDVO_HIGH_SPEED;
10014 if (intel_crtc_has_dp_encoder(crtc_state))
10015 dpll |= DPLL_SDVO_HIGH_SPEED;
10018 * The high speed IO clock is only really required for
10019 * SDVO/HDMI/DP, but we also enable it for CRT to make it
10020 * possible to share the DPLL between CRT and HDMI. Enabling
10021 * the clock needlessly does no real harm, except use up a
10022 * bit of power potentially.
10024 * We'll limit this to IVB with 3 pipes, since it has only two
10025 * DPLLs and so DPLL sharing is the only way to get three pipes
10026 * driving PCH ports at the same time. On SNB we could do this,
10027 * and potentially avoid enabling the second DPLL, but it's not
10028 * clear if it''s a win or loss power wise. No point in doing
10029 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
10031 if (INTEL_NUM_PIPES(dev_priv) == 3 &&
10032 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
10033 dpll |= DPLL_SDVO_HIGH_SPEED;
10035 /* compute bitmask from p1 value */
10036 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
10038 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
10040 switch (crtc_state->dpll.p2) {
10042 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
10045 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
10048 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
10051 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
10055 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
10056 intel_panel_use_ssc(dev_priv))
10057 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
10059 dpll |= PLL_REF_INPUT_DREFCLK;
10061 dpll |= DPLL_VCO_ENABLE;
10063 crtc_state->dpll_hw_state.dpll = dpll;
10064 crtc_state->dpll_hw_state.fp0 = fp;
10065 crtc_state->dpll_hw_state.fp1 = fp2;
10068 static int ilk_crtc_compute_clock(struct intel_crtc *crtc,
10069 struct intel_crtc_state *crtc_state)
10071 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10072 struct intel_atomic_state *state =
10073 to_intel_atomic_state(crtc_state->uapi.state);
10074 const struct intel_limit *limit;
10075 int refclk = 120000;
10077 memset(&crtc_state->dpll_hw_state, 0,
10078 sizeof(crtc_state->dpll_hw_state));
10080 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
10081 if (!crtc_state->has_pch_encoder)
10084 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
10085 if (intel_panel_use_ssc(dev_priv)) {
10086 drm_dbg_kms(&dev_priv->drm,
10087 "using SSC reference clock of %d kHz\n",
10088 dev_priv->vbt.lvds_ssc_freq);
10089 refclk = dev_priv->vbt.lvds_ssc_freq;
10092 if (intel_is_dual_link_lvds(dev_priv)) {
10093 if (refclk == 100000)
10094 limit = &ilk_limits_dual_lvds_100m;
10096 limit = &ilk_limits_dual_lvds;
10098 if (refclk == 100000)
10099 limit = &ilk_limits_single_lvds_100m;
10101 limit = &ilk_limits_single_lvds;
10104 limit = &ilk_limits_dac;
10107 if (!crtc_state->clock_set &&
10108 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
10109 refclk, NULL, &crtc_state->dpll)) {
10110 drm_err(&dev_priv->drm,
10111 "Couldn't find PLL settings for mode!\n");
10115 ilk_compute_dpll(crtc, crtc_state, NULL);
10117 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
10118 drm_dbg_kms(&dev_priv->drm,
10119 "failed to find PLL for pipe %c\n",
10120 pipe_name(crtc->pipe));
10127 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
10128 struct intel_link_m_n *m_n)
10130 struct drm_device *dev = crtc->base.dev;
10131 struct drm_i915_private *dev_priv = to_i915(dev);
10132 enum pipe pipe = crtc->pipe;
10134 m_n->link_m = intel_de_read(dev_priv, PCH_TRANS_LINK_M1(pipe));
10135 m_n->link_n = intel_de_read(dev_priv, PCH_TRANS_LINK_N1(pipe));
10136 m_n->gmch_m = intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
10138 m_n->gmch_n = intel_de_read(dev_priv, PCH_TRANS_DATA_N1(pipe));
10139 m_n->tu = ((intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
10140 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10143 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
10144 enum transcoder transcoder,
10145 struct intel_link_m_n *m_n,
10146 struct intel_link_m_n *m2_n2)
10148 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10149 enum pipe pipe = crtc->pipe;
10151 if (INTEL_GEN(dev_priv) >= 5) {
10152 m_n->link_m = intel_de_read(dev_priv,
10153 PIPE_LINK_M1(transcoder));
10154 m_n->link_n = intel_de_read(dev_priv,
10155 PIPE_LINK_N1(transcoder));
10156 m_n->gmch_m = intel_de_read(dev_priv,
10157 PIPE_DATA_M1(transcoder))
10159 m_n->gmch_n = intel_de_read(dev_priv,
10160 PIPE_DATA_N1(transcoder));
10161 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M1(transcoder))
10162 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10164 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
10165 m2_n2->link_m = intel_de_read(dev_priv,
10166 PIPE_LINK_M2(transcoder));
10167 m2_n2->link_n = intel_de_read(dev_priv,
10168 PIPE_LINK_N2(transcoder));
10169 m2_n2->gmch_m = intel_de_read(dev_priv,
10170 PIPE_DATA_M2(transcoder))
10172 m2_n2->gmch_n = intel_de_read(dev_priv,
10173 PIPE_DATA_N2(transcoder));
10174 m2_n2->tu = ((intel_de_read(dev_priv, PIPE_DATA_M2(transcoder))
10175 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10178 m_n->link_m = intel_de_read(dev_priv, PIPE_LINK_M_G4X(pipe));
10179 m_n->link_n = intel_de_read(dev_priv, PIPE_LINK_N_G4X(pipe));
10180 m_n->gmch_m = intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
10182 m_n->gmch_n = intel_de_read(dev_priv, PIPE_DATA_N_G4X(pipe));
10183 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
10184 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10188 void intel_dp_get_m_n(struct intel_crtc *crtc,
10189 struct intel_crtc_state *pipe_config)
10191 if (pipe_config->has_pch_encoder)
10192 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
10194 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10195 &pipe_config->dp_m_n,
10196 &pipe_config->dp_m2_n2);
10199 static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc,
10200 struct intel_crtc_state *pipe_config)
10202 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10203 &pipe_config->fdi_m_n, NULL);
10206 static void ilk_get_pfit_pos_size(struct intel_crtc_state *crtc_state,
10209 drm_rect_init(&crtc_state->pch_pfit.dst,
10210 pos >> 16, pos & 0xffff,
10211 size >> 16, size & 0xffff);
10214 static void skl_get_pfit_config(struct intel_crtc_state *crtc_state)
10216 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10217 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10218 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
10222 /* find scaler attached to this pipe */
10223 for (i = 0; i < crtc->num_scalers; i++) {
10224 u32 ctl, pos, size;
10226 ctl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i));
10227 if ((ctl & (PS_SCALER_EN | PS_PLANE_SEL_MASK)) != PS_SCALER_EN)
10231 crtc_state->pch_pfit.enabled = true;
10233 pos = intel_de_read(dev_priv, SKL_PS_WIN_POS(crtc->pipe, i));
10234 size = intel_de_read(dev_priv, SKL_PS_WIN_SZ(crtc->pipe, i));
10236 ilk_get_pfit_pos_size(crtc_state, pos, size);
10238 scaler_state->scalers[i].in_use = true;
10242 scaler_state->scaler_id = id;
10244 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
10246 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
10250 skl_get_initial_plane_config(struct intel_crtc *crtc,
10251 struct intel_initial_plane_config *plane_config)
10253 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
10254 struct drm_device *dev = crtc->base.dev;
10255 struct drm_i915_private *dev_priv = to_i915(dev);
10256 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
10257 enum plane_id plane_id = plane->id;
10259 u32 val, base, offset, stride_mult, tiling, alpha;
10260 int fourcc, pixel_format;
10261 unsigned int aligned_height;
10262 struct drm_framebuffer *fb;
10263 struct intel_framebuffer *intel_fb;
10265 if (!plane->get_hw_state(plane, &pipe))
10268 drm_WARN_ON(dev, pipe != crtc->pipe);
10270 if (crtc_state->bigjoiner) {
10271 drm_dbg_kms(&dev_priv->drm,
10272 "Unsupported bigjoiner configuration for initial FB\n");
10276 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10278 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
10282 fb = &intel_fb->base;
10286 val = intel_de_read(dev_priv, PLANE_CTL(pipe, plane_id));
10288 if (INTEL_GEN(dev_priv) >= 11)
10289 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
10291 pixel_format = val & PLANE_CTL_FORMAT_MASK;
10293 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
10294 alpha = intel_de_read(dev_priv,
10295 PLANE_COLOR_CTL(pipe, plane_id));
10296 alpha &= PLANE_COLOR_ALPHA_MASK;
10298 alpha = val & PLANE_CTL_ALPHA_MASK;
10301 fourcc = skl_format_to_fourcc(pixel_format,
10302 val & PLANE_CTL_ORDER_RGBX, alpha);
10303 fb->format = drm_format_info(fourcc);
10305 tiling = val & PLANE_CTL_TILED_MASK;
10307 case PLANE_CTL_TILED_LINEAR:
10308 fb->modifier = DRM_FORMAT_MOD_LINEAR;
10310 case PLANE_CTL_TILED_X:
10311 plane_config->tiling = I915_TILING_X;
10312 fb->modifier = I915_FORMAT_MOD_X_TILED;
10314 case PLANE_CTL_TILED_Y:
10315 plane_config->tiling = I915_TILING_Y;
10316 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10317 fb->modifier = INTEL_GEN(dev_priv) >= 12 ?
10318 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS :
10319 I915_FORMAT_MOD_Y_TILED_CCS;
10320 else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE)
10321 fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
10323 fb->modifier = I915_FORMAT_MOD_Y_TILED;
10325 case PLANE_CTL_TILED_YF:
10326 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10327 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
10329 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
10332 MISSING_CASE(tiling);
10337 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
10338 * while i915 HW rotation is clockwise, thats why this swapping.
10340 switch (val & PLANE_CTL_ROTATE_MASK) {
10341 case PLANE_CTL_ROTATE_0:
10342 plane_config->rotation = DRM_MODE_ROTATE_0;
10344 case PLANE_CTL_ROTATE_90:
10345 plane_config->rotation = DRM_MODE_ROTATE_270;
10347 case PLANE_CTL_ROTATE_180:
10348 plane_config->rotation = DRM_MODE_ROTATE_180;
10350 case PLANE_CTL_ROTATE_270:
10351 plane_config->rotation = DRM_MODE_ROTATE_90;
10355 if (INTEL_GEN(dev_priv) >= 10 &&
10356 val & PLANE_CTL_FLIP_HORIZONTAL)
10357 plane_config->rotation |= DRM_MODE_REFLECT_X;
10359 /* 90/270 degree rotation would require extra work */
10360 if (drm_rotation_90_or_270(plane_config->rotation))
10363 base = intel_de_read(dev_priv, PLANE_SURF(pipe, plane_id)) & 0xfffff000;
10364 plane_config->base = base;
10366 offset = intel_de_read(dev_priv, PLANE_OFFSET(pipe, plane_id));
10368 val = intel_de_read(dev_priv, PLANE_SIZE(pipe, plane_id));
10369 fb->height = ((val >> 16) & 0xffff) + 1;
10370 fb->width = ((val >> 0) & 0xffff) + 1;
10372 val = intel_de_read(dev_priv, PLANE_STRIDE(pipe, plane_id));
10373 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
10374 fb->pitches[0] = (val & 0x3ff) * stride_mult;
10376 aligned_height = intel_fb_align_height(fb, 0, fb->height);
10378 plane_config->size = fb->pitches[0] * aligned_height;
10380 drm_dbg_kms(&dev_priv->drm,
10381 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
10382 crtc->base.name, plane->base.name, fb->width, fb->height,
10383 fb->format->cpp[0] * 8, base, fb->pitches[0],
10384 plane_config->size);
10386 plane_config->fb = intel_fb;
10393 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
10395 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10396 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10397 u32 ctl, pos, size;
10399 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
10400 if ((ctl & PF_ENABLE) == 0)
10403 crtc_state->pch_pfit.enabled = true;
10405 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
10406 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
10408 ilk_get_pfit_pos_size(crtc_state, pos, size);
10411 * We currently do not free assignements of panel fitters on
10412 * ivb/hsw (since we don't use the higher upscaling modes which
10413 * differentiates them) so just WARN about this case for now.
10415 drm_WARN_ON(&dev_priv->drm, IS_GEN(dev_priv, 7) &&
10416 (ctl & PF_PIPE_SEL_MASK_IVB) != PF_PIPE_SEL_IVB(crtc->pipe));
10419 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
10420 struct intel_crtc_state *pipe_config)
10422 struct drm_device *dev = crtc->base.dev;
10423 struct drm_i915_private *dev_priv = to_i915(dev);
10424 enum intel_display_power_domain power_domain;
10425 intel_wakeref_t wakeref;
10429 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10430 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10434 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10435 pipe_config->shared_dpll = NULL;
10438 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
10439 if (!(tmp & PIPECONF_ENABLE))
10442 switch (tmp & PIPECONF_BPC_MASK) {
10443 case PIPECONF_6BPC:
10444 pipe_config->pipe_bpp = 18;
10446 case PIPECONF_8BPC:
10447 pipe_config->pipe_bpp = 24;
10449 case PIPECONF_10BPC:
10450 pipe_config->pipe_bpp = 30;
10452 case PIPECONF_12BPC:
10453 pipe_config->pipe_bpp = 36;
10459 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
10460 pipe_config->limited_color_range = true;
10462 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
10463 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
10464 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
10465 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10468 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10472 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
10473 PIPECONF_GAMMA_MODE_SHIFT;
10475 pipe_config->csc_mode = intel_de_read(dev_priv,
10476 PIPE_CSC_MODE(crtc->pipe));
10478 i9xx_get_pipe_color_config(pipe_config);
10479 intel_color_get_config(pipe_config);
10481 if (intel_de_read(dev_priv, PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
10482 struct intel_shared_dpll *pll;
10483 enum intel_dpll_id pll_id;
10486 pipe_config->has_pch_encoder = true;
10488 tmp = intel_de_read(dev_priv, FDI_RX_CTL(crtc->pipe));
10489 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10490 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10492 ilk_get_fdi_m_n_config(crtc, pipe_config);
10494 if (HAS_PCH_IBX(dev_priv)) {
10496 * The pipe->pch transcoder and pch transcoder->pll
10497 * mapping is fixed.
10499 pll_id = (enum intel_dpll_id) crtc->pipe;
10501 tmp = intel_de_read(dev_priv, PCH_DPLL_SEL);
10502 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
10503 pll_id = DPLL_ID_PCH_PLL_B;
10505 pll_id= DPLL_ID_PCH_PLL_A;
10508 pipe_config->shared_dpll =
10509 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10510 pll = pipe_config->shared_dpll;
10512 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
10513 &pipe_config->dpll_hw_state);
10514 drm_WARN_ON(dev, !pll_active);
10516 tmp = pipe_config->dpll_hw_state.dpll;
10517 pipe_config->pixel_multiplier =
10518 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10519 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10521 ilk_pch_clock_get(crtc, pipe_config);
10523 pipe_config->pixel_multiplier = 1;
10526 intel_get_transcoder_timings(crtc, pipe_config);
10527 intel_get_pipe_src_size(crtc, pipe_config);
10529 ilk_get_pfit_config(pipe_config);
10534 intel_display_power_put(dev_priv, power_domain, wakeref);
10539 static int hsw_crtc_compute_clock(struct intel_crtc *crtc,
10540 struct intel_crtc_state *crtc_state)
10542 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10543 struct intel_atomic_state *state =
10544 to_intel_atomic_state(crtc_state->uapi.state);
10546 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10547 INTEL_GEN(dev_priv) >= 11) {
10548 struct intel_encoder *encoder =
10549 intel_get_crtc_new_encoder(state, crtc_state);
10551 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10552 drm_dbg_kms(&dev_priv->drm,
10553 "failed to find PLL for pipe %c\n",
10554 pipe_name(crtc->pipe));
10562 static void dg1_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10563 struct intel_crtc_state *pipe_config)
10565 enum icl_port_dpll_id port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10566 enum phy phy = intel_port_to_phy(dev_priv, port);
10567 struct icl_port_dpll *port_dpll;
10568 struct intel_shared_dpll *pll;
10569 enum intel_dpll_id id;
10573 clk_sel = intel_de_read(dev_priv, DG1_DPCLKA_CFGCR0(phy)) & DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10574 id = DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_DPLL_MAP(clk_sel, phy);
10576 if (WARN_ON(id > DPLL_ID_DG1_DPLL3))
10579 pll = intel_get_shared_dpll_by_id(dev_priv, id);
10580 port_dpll = &pipe_config->icl_port_dplls[port_dpll_id];
10582 port_dpll->pll = pll;
10583 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
10584 &port_dpll->hw_state);
10585 drm_WARN_ON(&dev_priv->drm, !pll_active);
10587 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10590 static void icl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10591 struct intel_crtc_state *pipe_config)
10593 enum phy phy = intel_port_to_phy(dev_priv, port);
10594 enum icl_port_dpll_id port_dpll_id;
10595 struct icl_port_dpll *port_dpll;
10596 struct intel_shared_dpll *pll;
10597 enum intel_dpll_id id;
10601 if (intel_phy_is_combo(dev_priv, phy)) {
10604 if (IS_ROCKETLAKE(dev_priv)) {
10605 mask = RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10606 shift = RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10608 mask = ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10609 shift = ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10612 temp = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0) & mask;
10613 id = temp >> shift;
10614 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10615 } else if (intel_phy_is_tc(dev_priv, phy)) {
10616 u32 clk_sel = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
10618 if (clk_sel == DDI_CLK_SEL_MG) {
10619 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
10621 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
10623 drm_WARN_ON(&dev_priv->drm,
10624 clk_sel < DDI_CLK_SEL_TBT_162);
10625 id = DPLL_ID_ICL_TBTPLL;
10626 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10629 drm_WARN(&dev_priv->drm, 1, "Invalid port %x\n", port);
10633 pll = intel_get_shared_dpll_by_id(dev_priv, id);
10634 port_dpll = &pipe_config->icl_port_dplls[port_dpll_id];
10636 port_dpll->pll = pll;
10637 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
10638 &port_dpll->hw_state);
10639 drm_WARN_ON(&dev_priv->drm, !pll_active);
10641 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10644 static void cnl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10645 struct intel_crtc_state *pipe_config)
10647 struct intel_shared_dpll *pll;
10648 enum intel_dpll_id id;
10652 temp = intel_de_read(dev_priv, DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10653 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10655 if (drm_WARN_ON(&dev_priv->drm, id < SKL_DPLL0 || id > SKL_DPLL2))
10658 pll = intel_get_shared_dpll_by_id(dev_priv, id);
10660 pipe_config->shared_dpll = pll;
10661 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
10662 &pipe_config->dpll_hw_state);
10663 drm_WARN_ON(&dev_priv->drm, !pll_active);
10666 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
10668 struct intel_crtc_state *pipe_config)
10670 struct intel_shared_dpll *pll;
10671 enum intel_dpll_id id;
10676 id = DPLL_ID_SKL_DPLL0;
10679 id = DPLL_ID_SKL_DPLL1;
10682 id = DPLL_ID_SKL_DPLL2;
10685 drm_err(&dev_priv->drm, "Incorrect port type\n");
10689 pll = intel_get_shared_dpll_by_id(dev_priv, id);
10691 pipe_config->shared_dpll = pll;
10692 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
10693 &pipe_config->dpll_hw_state);
10694 drm_WARN_ON(&dev_priv->drm, !pll_active);
10697 static void skl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10698 struct intel_crtc_state *pipe_config)
10700 struct intel_shared_dpll *pll;
10701 enum intel_dpll_id id;
10705 temp = intel_de_read(dev_priv, DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10706 id = temp >> (port * 3 + 1);
10708 if (drm_WARN_ON(&dev_priv->drm, id < SKL_DPLL0 || id > SKL_DPLL3))
10711 pll = intel_get_shared_dpll_by_id(dev_priv, id);
10713 pipe_config->shared_dpll = pll;
10714 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
10715 &pipe_config->dpll_hw_state);
10716 drm_WARN_ON(&dev_priv->drm, !pll_active);
10719 static void hsw_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10720 struct intel_crtc_state *pipe_config)
10722 struct intel_shared_dpll *pll;
10723 enum intel_dpll_id id;
10724 u32 ddi_pll_sel = intel_de_read(dev_priv, PORT_CLK_SEL(port));
10727 switch (ddi_pll_sel) {
10728 case PORT_CLK_SEL_WRPLL1:
10729 id = DPLL_ID_WRPLL1;
10731 case PORT_CLK_SEL_WRPLL2:
10732 id = DPLL_ID_WRPLL2;
10734 case PORT_CLK_SEL_SPLL:
10737 case PORT_CLK_SEL_LCPLL_810:
10738 id = DPLL_ID_LCPLL_810;
10740 case PORT_CLK_SEL_LCPLL_1350:
10741 id = DPLL_ID_LCPLL_1350;
10743 case PORT_CLK_SEL_LCPLL_2700:
10744 id = DPLL_ID_LCPLL_2700;
10747 MISSING_CASE(ddi_pll_sel);
10749 case PORT_CLK_SEL_NONE:
10753 pll = intel_get_shared_dpll_by_id(dev_priv, id);
10755 pipe_config->shared_dpll = pll;
10756 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
10757 &pipe_config->dpll_hw_state);
10758 drm_WARN_ON(&dev_priv->drm, !pll_active);
10761 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10762 struct intel_crtc_state *pipe_config,
10763 struct intel_display_power_domain_set *power_domain_set)
10765 struct drm_device *dev = crtc->base.dev;
10766 struct drm_i915_private *dev_priv = to_i915(dev);
10767 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
10768 unsigned long enabled_panel_transcoders = 0;
10769 enum transcoder panel_transcoder;
10772 if (INTEL_GEN(dev_priv) >= 11)
10773 panel_transcoder_mask |=
10774 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10777 * The pipe->transcoder mapping is fixed with the exception of the eDP
10778 * and DSI transcoders handled below.
10780 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10783 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10784 * consistency and less surprising code; it's in always on power).
10786 for_each_cpu_transcoder_masked(dev_priv, panel_transcoder,
10787 panel_transcoder_mask) {
10788 bool force_thru = false;
10789 enum pipe trans_pipe;
10791 tmp = intel_de_read(dev_priv,
10792 TRANS_DDI_FUNC_CTL(panel_transcoder));
10793 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10797 * Log all enabled ones, only use the first one.
10799 * FIXME: This won't work for two separate DSI displays.
10801 enabled_panel_transcoders |= BIT(panel_transcoder);
10802 if (enabled_panel_transcoders != BIT(panel_transcoder))
10805 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10808 "unknown pipe linked to transcoder %s\n",
10809 transcoder_name(panel_transcoder));
10811 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10814 case TRANS_DDI_EDP_INPUT_A_ON:
10815 trans_pipe = PIPE_A;
10817 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10818 trans_pipe = PIPE_B;
10820 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10821 trans_pipe = PIPE_C;
10823 case TRANS_DDI_EDP_INPUT_D_ONOFF:
10824 trans_pipe = PIPE_D;
10828 if (trans_pipe == crtc->pipe) {
10829 pipe_config->cpu_transcoder = panel_transcoder;
10830 pipe_config->pch_pfit.force_thru = force_thru;
10835 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10837 drm_WARN_ON(dev, (enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10838 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10840 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
10841 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
10844 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder));
10846 return tmp & PIPECONF_ENABLE;
10849 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10850 struct intel_crtc_state *pipe_config,
10851 struct intel_display_power_domain_set *power_domain_set)
10853 struct drm_device *dev = crtc->base.dev;
10854 struct drm_i915_private *dev_priv = to_i915(dev);
10855 enum transcoder cpu_transcoder;
10859 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10860 if (port == PORT_A)
10861 cpu_transcoder = TRANSCODER_DSI_A;
10863 cpu_transcoder = TRANSCODER_DSI_C;
10865 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
10866 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
10870 * The PLL needs to be enabled with a valid divider
10871 * configuration, otherwise accessing DSI registers will hang
10872 * the machine. See BSpec North Display Engine
10873 * registers/MIPI[BXT]. We can break out here early, since we
10874 * need the same DSI PLL to be enabled for both DSI ports.
10876 if (!bxt_dsi_pll_is_enabled(dev_priv))
10879 /* XXX: this works for video mode only */
10880 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
10881 if (!(tmp & DPI_ENABLE))
10884 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
10885 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
10888 pipe_config->cpu_transcoder = cpu_transcoder;
10892 return transcoder_is_dsi(pipe_config->cpu_transcoder);
10895 static void hsw_get_ddi_port_state(struct intel_crtc *crtc,
10896 struct intel_crtc_state *pipe_config)
10898 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10899 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
10903 if (transcoder_is_dsi(cpu_transcoder)) {
10904 port = (cpu_transcoder == TRANSCODER_DSI_A) ?
10907 tmp = intel_de_read(dev_priv,
10908 TRANS_DDI_FUNC_CTL(cpu_transcoder));
10909 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10911 if (INTEL_GEN(dev_priv) >= 12)
10912 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10914 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10917 if (IS_DG1(dev_priv))
10918 dg1_get_ddi_pll(dev_priv, port, pipe_config);
10919 else if (INTEL_GEN(dev_priv) >= 11)
10920 icl_get_ddi_pll(dev_priv, port, pipe_config);
10921 else if (IS_CANNONLAKE(dev_priv))
10922 cnl_get_ddi_pll(dev_priv, port, pipe_config);
10923 else if (IS_GEN9_LP(dev_priv))
10924 bxt_get_ddi_pll(dev_priv, port, pipe_config);
10925 else if (IS_GEN9_BC(dev_priv))
10926 skl_get_ddi_pll(dev_priv, port, pipe_config);
10928 hsw_get_ddi_pll(dev_priv, port, pipe_config);
10931 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10932 * DDI E. So just check whether this pipe is wired to DDI E and whether
10933 * the PCH transcoder is on.
10935 if (INTEL_GEN(dev_priv) < 9 &&
10936 (port == PORT_E) && intel_de_read(dev_priv, LPT_TRANSCONF) & TRANS_ENABLE) {
10937 pipe_config->has_pch_encoder = true;
10939 tmp = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
10940 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10941 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10943 ilk_get_fdi_m_n_config(crtc, pipe_config);
10947 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
10948 struct intel_crtc_state *pipe_config)
10950 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10951 struct intel_display_power_domain_set power_domain_set = { };
10955 pipe_config->master_transcoder = INVALID_TRANSCODER;
10957 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
10958 POWER_DOMAIN_PIPE(crtc->pipe)))
10961 pipe_config->shared_dpll = NULL;
10963 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_set);
10965 if (IS_GEN9_LP(dev_priv) &&
10966 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_set)) {
10967 drm_WARN_ON(&dev_priv->drm, active);
10971 intel_dsc_get_config(pipe_config);
10974 /* bigjoiner slave doesn't enable transcoder */
10975 if (!pipe_config->bigjoiner_slave)
10979 pipe_config->pixel_multiplier = 1;
10981 /* we cannot read out most state, so don't bother.. */
10982 pipe_config->quirks |= PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE;
10983 } else if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
10984 INTEL_GEN(dev_priv) >= 11) {
10985 hsw_get_ddi_port_state(crtc, pipe_config);
10986 intel_get_transcoder_timings(crtc, pipe_config);
10989 intel_get_pipe_src_size(crtc, pipe_config);
10991 if (IS_HASWELL(dev_priv)) {
10992 u32 tmp = intel_de_read(dev_priv,
10993 PIPECONF(pipe_config->cpu_transcoder));
10995 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
10996 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10998 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
11000 pipe_config->output_format =
11001 bdw_get_pipemisc_output_format(crtc);
11004 pipe_config->gamma_mode = intel_de_read(dev_priv,
11005 GAMMA_MODE(crtc->pipe));
11007 pipe_config->csc_mode = intel_de_read(dev_priv,
11008 PIPE_CSC_MODE(crtc->pipe));
11010 if (INTEL_GEN(dev_priv) >= 9) {
11011 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
11013 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
11014 pipe_config->gamma_enable = true;
11016 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
11017 pipe_config->csc_enable = true;
11019 i9xx_get_pipe_color_config(pipe_config);
11022 intel_color_get_config(pipe_config);
11024 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
11025 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
11026 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
11027 pipe_config->ips_linetime =
11028 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
11030 if (intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
11031 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
11032 if (INTEL_GEN(dev_priv) >= 9)
11033 skl_get_pfit_config(pipe_config);
11035 ilk_get_pfit_config(pipe_config);
11038 if (hsw_crtc_supports_ips(crtc)) {
11039 if (IS_HASWELL(dev_priv))
11040 pipe_config->ips_enabled = intel_de_read(dev_priv,
11041 IPS_CTL) & IPS_ENABLE;
11044 * We cannot readout IPS state on broadwell, set to
11045 * true so we can set it to a defined state on first
11048 pipe_config->ips_enabled = true;
11052 if (pipe_config->bigjoiner_slave) {
11053 /* Cannot be read out as a slave, set to 0. */
11054 pipe_config->pixel_multiplier = 0;
11055 } else if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
11056 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
11057 pipe_config->pixel_multiplier =
11058 intel_de_read(dev_priv,
11059 PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
11061 pipe_config->pixel_multiplier = 1;
11065 intel_display_power_put_all_in_set(dev_priv, &power_domain_set);
11070 static bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
11072 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11073 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
11075 if (!i915->display.get_pipe_config(crtc, crtc_state))
11078 crtc_state->hw.active = true;
11080 intel_crtc_readout_derived_state(crtc_state);
11085 /* VESA 640x480x72Hz mode to set on the pipe */
11086 static const struct drm_display_mode load_detect_mode = {
11087 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
11088 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
11091 struct drm_framebuffer *
11092 intel_framebuffer_create(struct drm_i915_gem_object *obj,
11093 struct drm_mode_fb_cmd2 *mode_cmd)
11095 struct intel_framebuffer *intel_fb;
11098 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
11100 return ERR_PTR(-ENOMEM);
11102 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
11106 return &intel_fb->base;
11110 return ERR_PTR(ret);
11113 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
11114 struct drm_crtc *crtc)
11116 struct drm_plane *plane;
11117 struct drm_plane_state *plane_state;
11120 ret = drm_atomic_add_affected_planes(state, crtc);
11124 for_each_new_plane_in_state(state, plane, plane_state, i) {
11125 if (plane_state->crtc != crtc)
11128 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
11132 drm_atomic_set_fb_for_plane(plane_state, NULL);
11138 int intel_get_load_detect_pipe(struct drm_connector *connector,
11139 struct intel_load_detect_pipe *old,
11140 struct drm_modeset_acquire_ctx *ctx)
11142 struct intel_crtc *intel_crtc;
11143 struct intel_encoder *intel_encoder =
11144 intel_attached_encoder(to_intel_connector(connector));
11145 struct drm_crtc *possible_crtc;
11146 struct drm_encoder *encoder = &intel_encoder->base;
11147 struct drm_crtc *crtc = NULL;
11148 struct drm_device *dev = encoder->dev;
11149 struct drm_i915_private *dev_priv = to_i915(dev);
11150 struct drm_mode_config *config = &dev->mode_config;
11151 struct drm_atomic_state *state = NULL, *restore_state = NULL;
11152 struct drm_connector_state *connector_state;
11153 struct intel_crtc_state *crtc_state;
11156 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11157 connector->base.id, connector->name,
11158 encoder->base.id, encoder->name);
11160 old->restore_state = NULL;
11162 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex));
11165 * Algorithm gets a little messy:
11167 * - if the connector already has an assigned crtc, use it (but make
11168 * sure it's on first)
11170 * - try to find the first unused crtc that can drive this connector,
11171 * and use that if we find one
11174 /* See if we already have a CRTC for this connector */
11175 if (connector->state->crtc) {
11176 crtc = connector->state->crtc;
11178 ret = drm_modeset_lock(&crtc->mutex, ctx);
11182 /* Make sure the crtc and connector are running */
11186 /* Find an unused one (if possible) */
11187 for_each_crtc(dev, possible_crtc) {
11189 if (!(encoder->possible_crtcs & (1 << i)))
11192 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
11196 if (possible_crtc->state->enable) {
11197 drm_modeset_unlock(&possible_crtc->mutex);
11201 crtc = possible_crtc;
11206 * If we didn't find an unused CRTC, don't use any.
11209 drm_dbg_kms(&dev_priv->drm,
11210 "no pipe available for load-detect\n");
11216 intel_crtc = to_intel_crtc(crtc);
11218 state = drm_atomic_state_alloc(dev);
11219 restore_state = drm_atomic_state_alloc(dev);
11220 if (!state || !restore_state) {
11225 state->acquire_ctx = ctx;
11226 restore_state->acquire_ctx = ctx;
11228 connector_state = drm_atomic_get_connector_state(state, connector);
11229 if (IS_ERR(connector_state)) {
11230 ret = PTR_ERR(connector_state);
11234 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
11238 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
11239 if (IS_ERR(crtc_state)) {
11240 ret = PTR_ERR(crtc_state);
11244 crtc_state->uapi.active = true;
11246 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
11247 &load_detect_mode);
11251 ret = intel_modeset_disable_planes(state, crtc);
11255 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
11257 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
11259 ret = drm_atomic_add_affected_planes(restore_state, crtc);
11261 drm_dbg_kms(&dev_priv->drm,
11262 "Failed to create a copy of old state to restore: %i\n",
11267 ret = drm_atomic_commit(state);
11269 drm_dbg_kms(&dev_priv->drm,
11270 "failed to set mode on load-detect pipe\n");
11274 old->restore_state = restore_state;
11275 drm_atomic_state_put(state);
11277 /* let the connector get through one full cycle before testing */
11278 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
11283 drm_atomic_state_put(state);
11286 if (restore_state) {
11287 drm_atomic_state_put(restore_state);
11288 restore_state = NULL;
11291 if (ret == -EDEADLK)
11297 void intel_release_load_detect_pipe(struct drm_connector *connector,
11298 struct intel_load_detect_pipe *old,
11299 struct drm_modeset_acquire_ctx *ctx)
11301 struct intel_encoder *intel_encoder =
11302 intel_attached_encoder(to_intel_connector(connector));
11303 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev);
11304 struct drm_encoder *encoder = &intel_encoder->base;
11305 struct drm_atomic_state *state = old->restore_state;
11308 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11309 connector->base.id, connector->name,
11310 encoder->base.id, encoder->name);
11315 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
11317 drm_dbg_kms(&i915->drm,
11318 "Couldn't release load detect pipe: %i\n", ret);
11319 drm_atomic_state_put(state);
11322 static int i9xx_pll_refclk(struct drm_device *dev,
11323 const struct intel_crtc_state *pipe_config)
11325 struct drm_i915_private *dev_priv = to_i915(dev);
11326 u32 dpll = pipe_config->dpll_hw_state.dpll;
11328 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
11329 return dev_priv->vbt.lvds_ssc_freq;
11330 else if (HAS_PCH_SPLIT(dev_priv))
11332 else if (!IS_GEN(dev_priv, 2))
11338 /* Returns the clock of the currently programmed mode of the given pipe. */
11339 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
11340 struct intel_crtc_state *pipe_config)
11342 struct drm_device *dev = crtc->base.dev;
11343 struct drm_i915_private *dev_priv = to_i915(dev);
11344 enum pipe pipe = crtc->pipe;
11345 u32 dpll = pipe_config->dpll_hw_state.dpll;
11349 int refclk = i9xx_pll_refclk(dev, pipe_config);
11351 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
11352 fp = pipe_config->dpll_hw_state.fp0;
11354 fp = pipe_config->dpll_hw_state.fp1;
11356 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
11357 if (IS_PINEVIEW(dev_priv)) {
11358 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
11359 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
11361 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
11362 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
11365 if (!IS_GEN(dev_priv, 2)) {
11366 if (IS_PINEVIEW(dev_priv))
11367 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
11368 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
11370 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
11371 DPLL_FPA01_P1_POST_DIV_SHIFT);
11373 switch (dpll & DPLL_MODE_MASK) {
11374 case DPLLB_MODE_DAC_SERIAL:
11375 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
11378 case DPLLB_MODE_LVDS:
11379 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
11383 drm_dbg_kms(&dev_priv->drm,
11384 "Unknown DPLL mode %08x in programmed "
11385 "mode\n", (int)(dpll & DPLL_MODE_MASK));
11389 if (IS_PINEVIEW(dev_priv))
11390 port_clock = pnv_calc_dpll_params(refclk, &clock);
11392 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11394 u32 lvds = IS_I830(dev_priv) ? 0 : intel_de_read(dev_priv,
11396 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
11399 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
11400 DPLL_FPA01_P1_POST_DIV_SHIFT);
11402 if (lvds & LVDS_CLKB_POWER_UP)
11407 if (dpll & PLL_P1_DIVIDE_BY_TWO)
11410 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
11411 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
11413 if (dpll & PLL_P2_DIVIDE_BY_4)
11419 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11423 * This value includes pixel_multiplier. We will use
11424 * port_clock to compute adjusted_mode.crtc_clock in the
11425 * encoder's get_config() function.
11427 pipe_config->port_clock = port_clock;
11430 int intel_dotclock_calculate(int link_freq,
11431 const struct intel_link_m_n *m_n)
11434 * The calculation for the data clock is:
11435 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
11436 * But we want to avoid losing precison if possible, so:
11437 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
11439 * and the link clock is simpler:
11440 * link_clock = (m * link_clock) / n
11446 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
11449 static void ilk_pch_clock_get(struct intel_crtc *crtc,
11450 struct intel_crtc_state *pipe_config)
11452 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11454 /* read out port_clock from the DPLL */
11455 i9xx_crtc_clock_get(crtc, pipe_config);
11458 * In case there is an active pipe without active ports,
11459 * we may need some idea for the dotclock anyway.
11460 * Calculate one based on the FDI configuration.
11462 pipe_config->hw.adjusted_mode.crtc_clock =
11463 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11464 &pipe_config->fdi_m_n);
11467 static void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
11468 struct intel_crtc *crtc)
11470 memset(crtc_state, 0, sizeof(*crtc_state));
11472 __drm_atomic_helper_crtc_state_reset(&crtc_state->uapi, &crtc->base);
11474 crtc_state->cpu_transcoder = INVALID_TRANSCODER;
11475 crtc_state->master_transcoder = INVALID_TRANSCODER;
11476 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
11477 crtc_state->output_format = INTEL_OUTPUT_FORMAT_INVALID;
11478 crtc_state->scaler_state.scaler_id = -1;
11479 crtc_state->mst_master_transcoder = INVALID_TRANSCODER;
11482 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc)
11484 struct intel_crtc_state *crtc_state;
11486 crtc_state = kmalloc(sizeof(*crtc_state), GFP_KERNEL);
11489 intel_crtc_state_reset(crtc_state, crtc);
11494 /* Returns the currently programmed mode of the given encoder. */
11495 struct drm_display_mode *
11496 intel_encoder_current_mode(struct intel_encoder *encoder)
11498 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
11499 struct intel_crtc_state *crtc_state;
11500 struct drm_display_mode *mode;
11501 struct intel_crtc *crtc;
11504 if (!encoder->get_hw_state(encoder, &pipe))
11507 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11509 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
11513 crtc_state = intel_crtc_state_alloc(crtc);
11519 if (!intel_crtc_get_pipe_config(crtc_state)) {
11525 intel_encoder_get_config(encoder, crtc_state);
11527 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
11534 static void intel_crtc_destroy(struct drm_crtc *crtc)
11536 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11538 drm_crtc_cleanup(crtc);
11543 * intel_wm_need_update - Check whether watermarks need updating
11544 * @cur: current plane state
11545 * @new: new plane state
11547 * Check current plane state versus the new one to determine whether
11548 * watermarks need to be recalculated.
11550 * Returns true or false.
11552 static bool intel_wm_need_update(const struct intel_plane_state *cur,
11553 struct intel_plane_state *new)
11555 /* Update watermarks on tiling or size changes. */
11556 if (new->uapi.visible != cur->uapi.visible)
11559 if (!cur->hw.fb || !new->hw.fb)
11562 if (cur->hw.fb->modifier != new->hw.fb->modifier ||
11563 cur->hw.rotation != new->hw.rotation ||
11564 drm_rect_width(&new->uapi.src) != drm_rect_width(&cur->uapi.src) ||
11565 drm_rect_height(&new->uapi.src) != drm_rect_height(&cur->uapi.src) ||
11566 drm_rect_width(&new->uapi.dst) != drm_rect_width(&cur->uapi.dst) ||
11567 drm_rect_height(&new->uapi.dst) != drm_rect_height(&cur->uapi.dst))
11573 static bool needs_scaling(const struct intel_plane_state *state)
11575 int src_w = drm_rect_width(&state->uapi.src) >> 16;
11576 int src_h = drm_rect_height(&state->uapi.src) >> 16;
11577 int dst_w = drm_rect_width(&state->uapi.dst);
11578 int dst_h = drm_rect_height(&state->uapi.dst);
11580 return (src_w != dst_w || src_h != dst_h);
11583 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
11584 struct intel_crtc_state *crtc_state,
11585 const struct intel_plane_state *old_plane_state,
11586 struct intel_plane_state *plane_state)
11588 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11589 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
11590 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11591 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
11592 bool was_crtc_enabled = old_crtc_state->hw.active;
11593 bool is_crtc_enabled = crtc_state->hw.active;
11594 bool turn_off, turn_on, visible, was_visible;
11597 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
11598 ret = skl_update_scaler_plane(crtc_state, plane_state);
11603 was_visible = old_plane_state->uapi.visible;
11604 visible = plane_state->uapi.visible;
11606 if (!was_crtc_enabled && drm_WARN_ON(&dev_priv->drm, was_visible))
11607 was_visible = false;
11610 * Visibility is calculated as if the crtc was on, but
11611 * after scaler setup everything depends on it being off
11612 * when the crtc isn't active.
11614 * FIXME this is wrong for watermarks. Watermarks should also
11615 * be computed as if the pipe would be active. Perhaps move
11616 * per-plane wm computation to the .check_plane() hook, and
11617 * only combine the results from all planes in the current place?
11619 if (!is_crtc_enabled) {
11620 intel_plane_set_invisible(crtc_state, plane_state);
11624 if (!was_visible && !visible)
11627 turn_off = was_visible && (!visible || mode_changed);
11628 turn_on = visible && (!was_visible || mode_changed);
11630 drm_dbg_atomic(&dev_priv->drm,
11631 "[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
11632 crtc->base.base.id, crtc->base.name,
11633 plane->base.base.id, plane->base.name,
11634 was_visible, visible,
11635 turn_off, turn_on, mode_changed);
11638 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11639 crtc_state->update_wm_pre = true;
11641 /* must disable cxsr around plane enable/disable */
11642 if (plane->id != PLANE_CURSOR)
11643 crtc_state->disable_cxsr = true;
11644 } else if (turn_off) {
11645 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11646 crtc_state->update_wm_post = true;
11648 /* must disable cxsr around plane enable/disable */
11649 if (plane->id != PLANE_CURSOR)
11650 crtc_state->disable_cxsr = true;
11651 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
11652 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
11653 /* FIXME bollocks */
11654 crtc_state->update_wm_pre = true;
11655 crtc_state->update_wm_post = true;
11659 if (visible || was_visible)
11660 crtc_state->fb_bits |= plane->frontbuffer_bit;
11663 * ILK/SNB DVSACNTR/Sprite Enable
11664 * IVB SPR_CTL/Sprite Enable
11665 * "When in Self Refresh Big FIFO mode, a write to enable the
11666 * plane will be internally buffered and delayed while Big FIFO
11667 * mode is exiting."
11669 * Which means that enabling the sprite can take an extra frame
11670 * when we start in big FIFO mode (LP1+). Thus we need to drop
11671 * down to LP0 and wait for vblank in order to make sure the
11672 * sprite gets enabled on the next vblank after the register write.
11673 * Doing otherwise would risk enabling the sprite one frame after
11674 * we've already signalled flip completion. We can resume LP1+
11675 * once the sprite has been enabled.
11678 * WaCxSRDisabledForSpriteScaling:ivb
11679 * IVB SPR_SCALE/Scaling Enable
11680 * "Low Power watermarks must be disabled for at least one
11681 * frame before enabling sprite scaling, and kept disabled
11682 * until sprite scaling is disabled."
11684 * ILK/SNB DVSASCALE/Scaling Enable
11685 * "When in Self Refresh Big FIFO mode, scaling enable will be
11686 * masked off while Big FIFO mode is exiting."
11688 * Despite the w/a only being listed for IVB we assume that
11689 * the ILK/SNB note has similar ramifications, hence we apply
11690 * the w/a on all three platforms.
11692 * With experimental results seems this is needed also for primary
11693 * plane, not only sprite plane.
11695 if (plane->id != PLANE_CURSOR &&
11696 (IS_GEN_RANGE(dev_priv, 5, 6) ||
11697 IS_IVYBRIDGE(dev_priv)) &&
11698 (turn_on || (!needs_scaling(old_plane_state) &&
11699 needs_scaling(plane_state))))
11700 crtc_state->disable_lp_wm = true;
11705 static bool encoders_cloneable(const struct intel_encoder *a,
11706 const struct intel_encoder *b)
11708 /* masks could be asymmetric, so check both ways */
11709 return a == b || (a->cloneable & (1 << b->type) &&
11710 b->cloneable & (1 << a->type));
11713 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
11714 struct intel_crtc *crtc,
11715 struct intel_encoder *encoder)
11717 struct intel_encoder *source_encoder;
11718 struct drm_connector *connector;
11719 struct drm_connector_state *connector_state;
11722 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
11723 if (connector_state->crtc != &crtc->base)
11727 to_intel_encoder(connector_state->best_encoder);
11728 if (!encoders_cloneable(encoder, source_encoder))
11735 static int icl_add_linked_planes(struct intel_atomic_state *state)
11737 struct intel_plane *plane, *linked;
11738 struct intel_plane_state *plane_state, *linked_plane_state;
11741 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11742 linked = plane_state->planar_linked_plane;
11747 linked_plane_state = intel_atomic_get_plane_state(state, linked);
11748 if (IS_ERR(linked_plane_state))
11749 return PTR_ERR(linked_plane_state);
11751 drm_WARN_ON(state->base.dev,
11752 linked_plane_state->planar_linked_plane != plane);
11753 drm_WARN_ON(state->base.dev,
11754 linked_plane_state->planar_slave == plane_state->planar_slave);
11760 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
11762 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11763 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11764 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
11765 struct intel_plane *plane, *linked;
11766 struct intel_plane_state *plane_state;
11769 if (INTEL_GEN(dev_priv) < 11)
11773 * Destroy all old plane links and make the slave plane invisible
11774 * in the crtc_state->active_planes mask.
11776 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11777 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
11780 plane_state->planar_linked_plane = NULL;
11781 if (plane_state->planar_slave && !plane_state->uapi.visible) {
11782 crtc_state->enabled_planes &= ~BIT(plane->id);
11783 crtc_state->active_planes &= ~BIT(plane->id);
11784 crtc_state->update_planes |= BIT(plane->id);
11787 plane_state->planar_slave = false;
11790 if (!crtc_state->nv12_planes)
11793 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11794 struct intel_plane_state *linked_state = NULL;
11796 if (plane->pipe != crtc->pipe ||
11797 !(crtc_state->nv12_planes & BIT(plane->id)))
11800 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
11801 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
11804 if (crtc_state->active_planes & BIT(linked->id))
11807 linked_state = intel_atomic_get_plane_state(state, linked);
11808 if (IS_ERR(linked_state))
11809 return PTR_ERR(linked_state);
11814 if (!linked_state) {
11815 drm_dbg_kms(&dev_priv->drm,
11816 "Need %d free Y planes for planar YUV\n",
11817 hweight8(crtc_state->nv12_planes));
11822 plane_state->planar_linked_plane = linked;
11824 linked_state->planar_slave = true;
11825 linked_state->planar_linked_plane = plane;
11826 crtc_state->enabled_planes |= BIT(linked->id);
11827 crtc_state->active_planes |= BIT(linked->id);
11828 crtc_state->update_planes |= BIT(linked->id);
11829 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
11830 linked->base.name, plane->base.name);
11832 /* Copy parameters to slave plane */
11833 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
11834 linked_state->color_ctl = plane_state->color_ctl;
11835 linked_state->view = plane_state->view;
11836 memcpy(linked_state->color_plane, plane_state->color_plane,
11837 sizeof(linked_state->color_plane));
11839 intel_plane_copy_hw_state(linked_state, plane_state);
11840 linked_state->uapi.src = plane_state->uapi.src;
11841 linked_state->uapi.dst = plane_state->uapi.dst;
11843 if (icl_is_hdr_plane(dev_priv, plane->id)) {
11844 if (linked->id == PLANE_SPRITE5)
11845 plane_state->cus_ctl |= PLANE_CUS_PLANE_7;
11846 else if (linked->id == PLANE_SPRITE4)
11847 plane_state->cus_ctl |= PLANE_CUS_PLANE_6;
11848 else if (linked->id == PLANE_SPRITE3)
11849 plane_state->cus_ctl |= PLANE_CUS_PLANE_5_RKL;
11850 else if (linked->id == PLANE_SPRITE2)
11851 plane_state->cus_ctl |= PLANE_CUS_PLANE_4_RKL;
11853 MISSING_CASE(linked->id);
11860 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
11862 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
11863 struct intel_atomic_state *state =
11864 to_intel_atomic_state(new_crtc_state->uapi.state);
11865 const struct intel_crtc_state *old_crtc_state =
11866 intel_atomic_get_old_crtc_state(state, crtc);
11868 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
11871 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
11873 const struct drm_display_mode *pipe_mode =
11874 &crtc_state->hw.pipe_mode;
11877 if (!crtc_state->hw.enable)
11880 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
11881 pipe_mode->crtc_clock);
11883 return min(linetime_wm, 0x1ff);
11886 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
11887 const struct intel_cdclk_state *cdclk_state)
11889 const struct drm_display_mode *pipe_mode =
11890 &crtc_state->hw.pipe_mode;
11893 if (!crtc_state->hw.enable)
11896 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
11897 cdclk_state->logical.cdclk);
11899 return min(linetime_wm, 0x1ff);
11902 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
11904 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11905 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11906 const struct drm_display_mode *pipe_mode =
11907 &crtc_state->hw.pipe_mode;
11910 if (!crtc_state->hw.enable)
11913 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
11914 crtc_state->pixel_rate);
11916 /* Display WA #1135: BXT:ALL GLK:ALL */
11917 if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled)
11920 return min(linetime_wm, 0x1ff);
11923 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
11924 struct intel_crtc *crtc)
11926 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11927 struct intel_crtc_state *crtc_state =
11928 intel_atomic_get_new_crtc_state(state, crtc);
11929 const struct intel_cdclk_state *cdclk_state;
11931 if (INTEL_GEN(dev_priv) >= 9)
11932 crtc_state->linetime = skl_linetime_wm(crtc_state);
11934 crtc_state->linetime = hsw_linetime_wm(crtc_state);
11936 if (!hsw_crtc_supports_ips(crtc))
11939 cdclk_state = intel_atomic_get_cdclk_state(state);
11940 if (IS_ERR(cdclk_state))
11941 return PTR_ERR(cdclk_state);
11943 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
11949 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
11950 struct intel_crtc *crtc)
11952 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11953 struct intel_crtc_state *crtc_state =
11954 intel_atomic_get_new_crtc_state(state, crtc);
11955 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
11958 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
11959 mode_changed && !crtc_state->hw.active)
11960 crtc_state->update_wm_post = true;
11962 if (mode_changed && crtc_state->hw.enable &&
11963 dev_priv->display.crtc_compute_clock &&
11964 !crtc_state->bigjoiner_slave &&
11965 !drm_WARN_ON(&dev_priv->drm, crtc_state->shared_dpll)) {
11966 ret = dev_priv->display.crtc_compute_clock(crtc, crtc_state);
11972 * May need to update pipe gamma enable bits
11973 * when C8 planes are getting enabled/disabled.
11975 if (c8_planes_changed(crtc_state))
11976 crtc_state->uapi.color_mgmt_changed = true;
11978 if (mode_changed || crtc_state->update_pipe ||
11979 crtc_state->uapi.color_mgmt_changed) {
11980 ret = intel_color_check(crtc_state);
11985 if (dev_priv->display.compute_pipe_wm) {
11986 ret = dev_priv->display.compute_pipe_wm(crtc_state);
11988 drm_dbg_kms(&dev_priv->drm,
11989 "Target pipe watermarks are invalid\n");
11994 if (dev_priv->display.compute_intermediate_wm) {
11995 if (drm_WARN_ON(&dev_priv->drm,
11996 !dev_priv->display.compute_pipe_wm))
12000 * Calculate 'intermediate' watermarks that satisfy both the
12001 * old state and the new state. We can program these
12004 ret = dev_priv->display.compute_intermediate_wm(crtc_state);
12006 drm_dbg_kms(&dev_priv->drm,
12007 "No valid intermediate pipe watermarks are possible\n");
12012 if (INTEL_GEN(dev_priv) >= 9) {
12013 if (mode_changed || crtc_state->update_pipe) {
12014 ret = skl_update_scaler_crtc(crtc_state);
12019 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
12024 if (HAS_IPS(dev_priv)) {
12025 ret = hsw_compute_ips_config(crtc_state);
12030 if (INTEL_GEN(dev_priv) >= 9 ||
12031 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
12032 ret = hsw_compute_linetime_wm(state, crtc);
12038 if (!mode_changed) {
12039 ret = intel_psr2_sel_fetch_update(state, crtc);
12047 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
12049 struct intel_connector *connector;
12050 struct drm_connector_list_iter conn_iter;
12052 drm_connector_list_iter_begin(dev, &conn_iter);
12053 for_each_intel_connector_iter(connector, &conn_iter) {
12054 if (connector->base.state->crtc)
12055 drm_connector_put(&connector->base);
12057 if (connector->base.encoder) {
12058 connector->base.state->best_encoder =
12059 connector->base.encoder;
12060 connector->base.state->crtc =
12061 connector->base.encoder->crtc;
12063 drm_connector_get(&connector->base);
12065 connector->base.state->best_encoder = NULL;
12066 connector->base.state->crtc = NULL;
12069 drm_connector_list_iter_end(&conn_iter);
12073 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
12074 struct intel_crtc_state *pipe_config)
12076 struct drm_connector *connector = conn_state->connector;
12077 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
12078 const struct drm_display_info *info = &connector->display_info;
12081 switch (conn_state->max_bpc) {
12095 MISSING_CASE(conn_state->max_bpc);
12099 if (bpp < pipe_config->pipe_bpp) {
12100 drm_dbg_kms(&i915->drm,
12101 "[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
12102 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
12103 connector->base.id, connector->name,
12104 bpp, 3 * info->bpc,
12105 3 * conn_state->max_requested_bpc,
12106 pipe_config->pipe_bpp);
12108 pipe_config->pipe_bpp = bpp;
12115 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
12116 struct intel_crtc_state *pipe_config)
12118 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12119 struct drm_atomic_state *state = pipe_config->uapi.state;
12120 struct drm_connector *connector;
12121 struct drm_connector_state *connector_state;
12124 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
12125 IS_CHERRYVIEW(dev_priv)))
12127 else if (INTEL_GEN(dev_priv) >= 5)
12132 pipe_config->pipe_bpp = bpp;
12134 /* Clamp display bpp to connector max bpp */
12135 for_each_new_connector_in_state(state, connector, connector_state, i) {
12138 if (connector_state->crtc != &crtc->base)
12141 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
12149 static void intel_dump_crtc_timings(struct drm_i915_private *i915,
12150 const struct drm_display_mode *mode)
12152 drm_dbg_kms(&i915->drm, "crtc timings: %d %d %d %d %d %d %d %d %d, "
12153 "type: 0x%x flags: 0x%x\n",
12155 mode->crtc_hdisplay, mode->crtc_hsync_start,
12156 mode->crtc_hsync_end, mode->crtc_htotal,
12157 mode->crtc_vdisplay, mode->crtc_vsync_start,
12158 mode->crtc_vsync_end, mode->crtc_vtotal,
12159 mode->type, mode->flags);
12163 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
12164 const char *id, unsigned int lane_count,
12165 const struct intel_link_m_n *m_n)
12167 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
12169 drm_dbg_kms(&i915->drm,
12170 "%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12172 m_n->gmch_m, m_n->gmch_n,
12173 m_n->link_m, m_n->link_n, m_n->tu);
12177 intel_dump_infoframe(struct drm_i915_private *dev_priv,
12178 const union hdmi_infoframe *frame)
12180 if (!drm_debug_enabled(DRM_UT_KMS))
12183 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
12187 intel_dump_dp_vsc_sdp(struct drm_i915_private *dev_priv,
12188 const struct drm_dp_vsc_sdp *vsc)
12190 if (!drm_debug_enabled(DRM_UT_KMS))
12193 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, vsc);
12196 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
12198 static const char * const output_type_str[] = {
12199 OUTPUT_TYPE(UNUSED),
12200 OUTPUT_TYPE(ANALOG),
12204 OUTPUT_TYPE(TVOUT),
12210 OUTPUT_TYPE(DP_MST),
12215 static void snprintf_output_types(char *buf, size_t len,
12216 unsigned int output_types)
12223 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
12226 if ((output_types & BIT(i)) == 0)
12229 r = snprintf(str, len, "%s%s",
12230 str != buf ? "," : "", output_type_str[i]);
12236 output_types &= ~BIT(i);
12239 WARN_ON_ONCE(output_types != 0);
12242 static const char * const output_format_str[] = {
12243 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
12244 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
12245 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
12246 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
12249 static const char *output_formats(enum intel_output_format format)
12251 if (format >= ARRAY_SIZE(output_format_str))
12252 format = INTEL_OUTPUT_FORMAT_INVALID;
12253 return output_format_str[format];
12256 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
12258 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
12259 struct drm_i915_private *i915 = to_i915(plane->base.dev);
12260 const struct drm_framebuffer *fb = plane_state->hw.fb;
12261 struct drm_format_name_buf format_name;
12264 drm_dbg_kms(&i915->drm,
12265 "[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12266 plane->base.base.id, plane->base.name,
12267 yesno(plane_state->uapi.visible));
12271 drm_dbg_kms(&i915->drm,
12272 "[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s modifier = 0x%llx, visible: %s\n",
12273 plane->base.base.id, plane->base.name,
12274 fb->base.id, fb->width, fb->height,
12275 drm_get_format_name(fb->format->format, &format_name),
12276 fb->modifier, yesno(plane_state->uapi.visible));
12277 drm_dbg_kms(&i915->drm, "\trotation: 0x%x, scaler: %d\n",
12278 plane_state->hw.rotation, plane_state->scaler_id);
12279 if (plane_state->uapi.visible)
12280 drm_dbg_kms(&i915->drm,
12281 "\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
12282 DRM_RECT_FP_ARG(&plane_state->uapi.src),
12283 DRM_RECT_ARG(&plane_state->uapi.dst));
12286 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
12287 struct intel_atomic_state *state,
12288 const char *context)
12290 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
12291 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12292 const struct intel_plane_state *plane_state;
12293 struct intel_plane *plane;
12297 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s] enable: %s %s\n",
12298 crtc->base.base.id, crtc->base.name,
12299 yesno(pipe_config->hw.enable), context);
12301 if (!pipe_config->hw.enable)
12304 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
12305 drm_dbg_kms(&dev_priv->drm,
12306 "active: %s, output_types: %s (0x%x), output format: %s\n",
12307 yesno(pipe_config->hw.active),
12308 buf, pipe_config->output_types,
12309 output_formats(pipe_config->output_format));
12311 drm_dbg_kms(&dev_priv->drm,
12312 "cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
12313 transcoder_name(pipe_config->cpu_transcoder),
12314 pipe_config->pipe_bpp, pipe_config->dither);
12316 drm_dbg_kms(&dev_priv->drm, "MST master transcoder: %s\n",
12317 transcoder_name(pipe_config->mst_master_transcoder));
12319 drm_dbg_kms(&dev_priv->drm,
12320 "port sync: master transcoder: %s, slave transcoder bitmask = 0x%x\n",
12321 transcoder_name(pipe_config->master_transcoder),
12322 pipe_config->sync_mode_slaves_mask);
12324 drm_dbg_kms(&dev_priv->drm, "bigjoiner: %s\n",
12325 pipe_config->bigjoiner_slave ? "slave" :
12326 pipe_config->bigjoiner ? "master" : "no");
12328 if (pipe_config->has_pch_encoder)
12329 intel_dump_m_n_config(pipe_config, "fdi",
12330 pipe_config->fdi_lanes,
12331 &pipe_config->fdi_m_n);
12333 if (intel_crtc_has_dp_encoder(pipe_config)) {
12334 intel_dump_m_n_config(pipe_config, "dp m_n",
12335 pipe_config->lane_count, &pipe_config->dp_m_n);
12336 if (pipe_config->has_drrs)
12337 intel_dump_m_n_config(pipe_config, "dp m2_n2",
12338 pipe_config->lane_count,
12339 &pipe_config->dp_m2_n2);
12342 drm_dbg_kms(&dev_priv->drm,
12343 "audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
12344 pipe_config->has_audio, pipe_config->has_infoframe,
12345 pipe_config->infoframes.enable);
12347 if (pipe_config->infoframes.enable &
12348 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
12349 drm_dbg_kms(&dev_priv->drm, "GCP: 0x%x\n",
12350 pipe_config->infoframes.gcp);
12351 if (pipe_config->infoframes.enable &
12352 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
12353 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
12354 if (pipe_config->infoframes.enable &
12355 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
12356 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
12357 if (pipe_config->infoframes.enable &
12358 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
12359 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
12360 if (pipe_config->infoframes.enable &
12361 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_DRM))
12362 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm);
12363 if (pipe_config->infoframes.enable &
12364 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA))
12365 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm);
12366 if (pipe_config->infoframes.enable &
12367 intel_hdmi_infoframe_enable(DP_SDP_VSC))
12368 intel_dump_dp_vsc_sdp(dev_priv, &pipe_config->infoframes.vsc);
12370 drm_dbg_kms(&dev_priv->drm, "requested mode:\n");
12371 drm_mode_debug_printmodeline(&pipe_config->hw.mode);
12372 drm_dbg_kms(&dev_priv->drm, "adjusted mode:\n");
12373 drm_mode_debug_printmodeline(&pipe_config->hw.adjusted_mode);
12374 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.adjusted_mode);
12375 drm_dbg_kms(&dev_priv->drm, "pipe mode:\n");
12376 drm_mode_debug_printmodeline(&pipe_config->hw.pipe_mode);
12377 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.pipe_mode);
12378 drm_dbg_kms(&dev_priv->drm,
12379 "port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
12380 pipe_config->port_clock,
12381 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
12382 pipe_config->pixel_rate);
12384 drm_dbg_kms(&dev_priv->drm, "linetime: %d, ips linetime: %d\n",
12385 pipe_config->linetime, pipe_config->ips_linetime);
12387 if (INTEL_GEN(dev_priv) >= 9)
12388 drm_dbg_kms(&dev_priv->drm,
12389 "num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12391 pipe_config->scaler_state.scaler_users,
12392 pipe_config->scaler_state.scaler_id);
12394 if (HAS_GMCH(dev_priv))
12395 drm_dbg_kms(&dev_priv->drm,
12396 "gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12397 pipe_config->gmch_pfit.control,
12398 pipe_config->gmch_pfit.pgm_ratios,
12399 pipe_config->gmch_pfit.lvds_border_bits);
12401 drm_dbg_kms(&dev_priv->drm,
12402 "pch pfit: " DRM_RECT_FMT ", %s, force thru: %s\n",
12403 DRM_RECT_ARG(&pipe_config->pch_pfit.dst),
12404 enableddisabled(pipe_config->pch_pfit.enabled),
12405 yesno(pipe_config->pch_pfit.force_thru));
12407 drm_dbg_kms(&dev_priv->drm, "ips: %i, double wide: %i\n",
12408 pipe_config->ips_enabled, pipe_config->double_wide);
12410 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
12412 if (IS_CHERRYVIEW(dev_priv))
12413 drm_dbg_kms(&dev_priv->drm,
12414 "cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12415 pipe_config->cgm_mode, pipe_config->gamma_mode,
12416 pipe_config->gamma_enable, pipe_config->csc_enable);
12418 drm_dbg_kms(&dev_priv->drm,
12419 "csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12420 pipe_config->csc_mode, pipe_config->gamma_mode,
12421 pipe_config->gamma_enable, pipe_config->csc_enable);
12423 drm_dbg_kms(&dev_priv->drm, "degamma lut: %d entries, gamma lut: %d entries\n",
12424 pipe_config->hw.degamma_lut ?
12425 drm_color_lut_size(pipe_config->hw.degamma_lut) : 0,
12426 pipe_config->hw.gamma_lut ?
12427 drm_color_lut_size(pipe_config->hw.gamma_lut) : 0);
12433 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12434 if (plane->pipe == crtc->pipe)
12435 intel_dump_plane_state(plane_state);
12439 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
12441 struct drm_device *dev = state->base.dev;
12442 struct drm_connector *connector;
12443 struct drm_connector_list_iter conn_iter;
12444 unsigned int used_ports = 0;
12445 unsigned int used_mst_ports = 0;
12449 * We're going to peek into connector->state,
12450 * hence connection_mutex must be held.
12452 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
12455 * Walk the connector list instead of the encoder
12456 * list to detect the problem on ddi platforms
12457 * where there's just one encoder per digital port.
12459 drm_connector_list_iter_begin(dev, &conn_iter);
12460 drm_for_each_connector_iter(connector, &conn_iter) {
12461 struct drm_connector_state *connector_state;
12462 struct intel_encoder *encoder;
12465 drm_atomic_get_new_connector_state(&state->base,
12467 if (!connector_state)
12468 connector_state = connector->state;
12470 if (!connector_state->best_encoder)
12473 encoder = to_intel_encoder(connector_state->best_encoder);
12475 drm_WARN_ON(dev, !connector_state->crtc);
12477 switch (encoder->type) {
12478 case INTEL_OUTPUT_DDI:
12479 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
12482 case INTEL_OUTPUT_DP:
12483 case INTEL_OUTPUT_HDMI:
12484 case INTEL_OUTPUT_EDP:
12485 /* the same port mustn't appear more than once */
12486 if (used_ports & BIT(encoder->port))
12489 used_ports |= BIT(encoder->port);
12491 case INTEL_OUTPUT_DP_MST:
12493 1 << encoder->port;
12499 drm_connector_list_iter_end(&conn_iter);
12501 /* can't mix MST and SST/HDMI on the same port */
12502 if (used_ports & used_mst_ports)
12509 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
12510 struct intel_crtc_state *crtc_state)
12512 const struct intel_crtc_state *from_crtc_state = crtc_state;
12514 if (crtc_state->bigjoiner_slave) {
12515 from_crtc_state = intel_atomic_get_new_crtc_state(state,
12516 crtc_state->bigjoiner_linked_crtc);
12518 /* No need to copy state if the master state is unchanged */
12519 if (!from_crtc_state)
12523 intel_crtc_copy_color_blobs(crtc_state, from_crtc_state);
12527 intel_crtc_copy_uapi_to_hw_state(struct intel_atomic_state *state,
12528 struct intel_crtc_state *crtc_state)
12530 crtc_state->hw.enable = crtc_state->uapi.enable;
12531 crtc_state->hw.active = crtc_state->uapi.active;
12532 crtc_state->hw.mode = crtc_state->uapi.mode;
12533 crtc_state->hw.adjusted_mode = crtc_state->uapi.adjusted_mode;
12534 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
12536 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc_state);
12539 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state)
12541 if (crtc_state->bigjoiner_slave)
12544 crtc_state->uapi.enable = crtc_state->hw.enable;
12545 crtc_state->uapi.active = crtc_state->hw.active;
12546 drm_WARN_ON(crtc_state->uapi.crtc->dev,
12547 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0);
12549 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode;
12550 crtc_state->uapi.scaling_filter = crtc_state->hw.scaling_filter;
12552 /* copy color blobs to uapi */
12553 drm_property_replace_blob(&crtc_state->uapi.degamma_lut,
12554 crtc_state->hw.degamma_lut);
12555 drm_property_replace_blob(&crtc_state->uapi.gamma_lut,
12556 crtc_state->hw.gamma_lut);
12557 drm_property_replace_blob(&crtc_state->uapi.ctm,
12558 crtc_state->hw.ctm);
12562 copy_bigjoiner_crtc_state(struct intel_crtc_state *crtc_state,
12563 const struct intel_crtc_state *from_crtc_state)
12565 struct intel_crtc_state *saved_state;
12566 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12568 saved_state = kmemdup(from_crtc_state, sizeof(*saved_state), GFP_KERNEL);
12572 saved_state->uapi = crtc_state->uapi;
12573 saved_state->scaler_state = crtc_state->scaler_state;
12574 saved_state->shared_dpll = crtc_state->shared_dpll;
12575 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
12576 saved_state->crc_enabled = crtc_state->crc_enabled;
12578 intel_crtc_free_hw_state(crtc_state);
12579 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
12580 kfree(saved_state);
12582 /* Re-init hw state */
12583 memset(&crtc_state->hw, 0, sizeof(saved_state->hw));
12584 crtc_state->hw.enable = from_crtc_state->hw.enable;
12585 crtc_state->hw.active = from_crtc_state->hw.active;
12586 crtc_state->hw.pipe_mode = from_crtc_state->hw.pipe_mode;
12587 crtc_state->hw.adjusted_mode = from_crtc_state->hw.adjusted_mode;
12590 crtc_state->uapi.mode_changed = from_crtc_state->uapi.mode_changed;
12591 crtc_state->uapi.connectors_changed = from_crtc_state->uapi.connectors_changed;
12592 crtc_state->uapi.active_changed = from_crtc_state->uapi.active_changed;
12593 crtc_state->nv12_planes = crtc_state->c8_planes = crtc_state->update_planes = 0;
12594 crtc_state->bigjoiner_linked_crtc = to_intel_crtc(from_crtc_state->uapi.crtc);
12595 crtc_state->bigjoiner_slave = true;
12596 crtc_state->cpu_transcoder = (enum transcoder)crtc->pipe;
12597 crtc_state->has_audio = false;
12603 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
12604 struct intel_crtc_state *crtc_state)
12606 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12607 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12608 struct intel_crtc_state *saved_state;
12610 saved_state = intel_crtc_state_alloc(crtc);
12614 /* free the old crtc_state->hw members */
12615 intel_crtc_free_hw_state(crtc_state);
12617 /* FIXME: before the switch to atomic started, a new pipe_config was
12618 * kzalloc'd. Code that depends on any field being zero should be
12619 * fixed, so that the crtc_state can be safely duplicated. For now,
12620 * only fields that are know to not cause problems are preserved. */
12622 saved_state->uapi = crtc_state->uapi;
12623 saved_state->scaler_state = crtc_state->scaler_state;
12624 saved_state->shared_dpll = crtc_state->shared_dpll;
12625 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
12626 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
12627 sizeof(saved_state->icl_port_dplls));
12628 saved_state->crc_enabled = crtc_state->crc_enabled;
12629 if (IS_G4X(dev_priv) ||
12630 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12631 saved_state->wm = crtc_state->wm;
12633 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
12634 kfree(saved_state);
12636 intel_crtc_copy_uapi_to_hw_state(state, crtc_state);
12642 intel_modeset_pipe_config(struct intel_atomic_state *state,
12643 struct intel_crtc_state *pipe_config)
12645 struct drm_crtc *crtc = pipe_config->uapi.crtc;
12646 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
12647 struct drm_connector *connector;
12648 struct drm_connector_state *connector_state;
12649 int base_bpp, ret, i;
12652 pipe_config->cpu_transcoder =
12653 (enum transcoder) to_intel_crtc(crtc)->pipe;
12656 * Sanitize sync polarity flags based on requested ones. If neither
12657 * positive or negative polarity is requested, treat this as meaning
12658 * negative polarity.
12660 if (!(pipe_config->hw.adjusted_mode.flags &
12661 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
12662 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
12664 if (!(pipe_config->hw.adjusted_mode.flags &
12665 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
12666 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
12668 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
12673 base_bpp = pipe_config->pipe_bpp;
12676 * Determine the real pipe dimensions. Note that stereo modes can
12677 * increase the actual pipe size due to the frame doubling and
12678 * insertion of additional space for blanks between the frame. This
12679 * is stored in the crtc timings. We use the requested mode to do this
12680 * computation to clearly distinguish it from the adjusted mode, which
12681 * can be changed by the connectors in the below retry loop.
12683 drm_mode_get_hv_timing(&pipe_config->hw.mode,
12684 &pipe_config->pipe_src_w,
12685 &pipe_config->pipe_src_h);
12687 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
12688 struct intel_encoder *encoder =
12689 to_intel_encoder(connector_state->best_encoder);
12691 if (connector_state->crtc != crtc)
12694 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
12695 drm_dbg_kms(&i915->drm,
12696 "rejecting invalid cloning configuration\n");
12701 * Determine output_types before calling the .compute_config()
12702 * hooks so that the hooks can use this information safely.
12704 if (encoder->compute_output_type)
12705 pipe_config->output_types |=
12706 BIT(encoder->compute_output_type(encoder, pipe_config,
12709 pipe_config->output_types |= BIT(encoder->type);
12713 /* Ensure the port clock defaults are reset when retrying. */
12714 pipe_config->port_clock = 0;
12715 pipe_config->pixel_multiplier = 1;
12717 /* Fill in default crtc timings, allow encoders to overwrite them. */
12718 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
12719 CRTC_STEREO_DOUBLE);
12721 /* Pass our mode to the connectors and the CRTC to give them a chance to
12722 * adjust it according to limitations or connector properties, and also
12723 * a chance to reject the mode entirely.
12725 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
12726 struct intel_encoder *encoder =
12727 to_intel_encoder(connector_state->best_encoder);
12729 if (connector_state->crtc != crtc)
12732 ret = encoder->compute_config(encoder, pipe_config,
12735 if (ret != -EDEADLK)
12736 drm_dbg_kms(&i915->drm,
12737 "Encoder config failure: %d\n",
12743 /* Set default port clock if not overwritten by the encoder. Needs to be
12744 * done afterwards in case the encoder adjusts the mode. */
12745 if (!pipe_config->port_clock)
12746 pipe_config->port_clock = pipe_config->hw.adjusted_mode.crtc_clock
12747 * pipe_config->pixel_multiplier;
12749 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
12750 if (ret == -EDEADLK)
12753 drm_dbg_kms(&i915->drm, "CRTC fixup failed\n");
12757 if (ret == RETRY) {
12758 if (drm_WARN(&i915->drm, !retry,
12759 "loop in pipe configuration computation\n"))
12762 drm_dbg_kms(&i915->drm, "CRTC bw constrained, retrying\n");
12764 goto encoder_retry;
12767 /* Dithering seems to not pass-through bits correctly when it should, so
12768 * only enable it on 6bpc panels and when its not a compliance
12769 * test requesting 6bpc video pattern.
12771 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
12772 !pipe_config->dither_force_disable;
12773 drm_dbg_kms(&i915->drm,
12774 "hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
12775 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
12781 intel_modeset_pipe_config_late(struct intel_crtc_state *crtc_state)
12783 struct intel_atomic_state *state =
12784 to_intel_atomic_state(crtc_state->uapi.state);
12785 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12786 struct drm_connector_state *conn_state;
12787 struct drm_connector *connector;
12790 for_each_new_connector_in_state(&state->base, connector,
12792 struct intel_encoder *encoder =
12793 to_intel_encoder(conn_state->best_encoder);
12796 if (conn_state->crtc != &crtc->base ||
12797 !encoder->compute_config_late)
12800 ret = encoder->compute_config_late(encoder, crtc_state,
12809 bool intel_fuzzy_clock_check(int clock1, int clock2)
12813 if (clock1 == clock2)
12816 if (!clock1 || !clock2)
12819 diff = abs(clock1 - clock2);
12821 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
12828 intel_compare_m_n(unsigned int m, unsigned int n,
12829 unsigned int m2, unsigned int n2,
12832 if (m == m2 && n == n2)
12835 if (exact || !m || !n || !m2 || !n2)
12838 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
12845 } else if (n < n2) {
12855 return intel_fuzzy_clock_check(m, m2);
12859 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
12860 const struct intel_link_m_n *m2_n2,
12863 return m_n->tu == m2_n2->tu &&
12864 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
12865 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
12866 intel_compare_m_n(m_n->link_m, m_n->link_n,
12867 m2_n2->link_m, m2_n2->link_n, exact);
12871 intel_compare_infoframe(const union hdmi_infoframe *a,
12872 const union hdmi_infoframe *b)
12874 return memcmp(a, b, sizeof(*a)) == 0;
12878 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
12879 const struct drm_dp_vsc_sdp *b)
12881 return memcmp(a, b, sizeof(*a)) == 0;
12885 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
12886 bool fastset, const char *name,
12887 const union hdmi_infoframe *a,
12888 const union hdmi_infoframe *b)
12891 if (!drm_debug_enabled(DRM_UT_KMS))
12894 drm_dbg_kms(&dev_priv->drm,
12895 "fastset mismatch in %s infoframe\n", name);
12896 drm_dbg_kms(&dev_priv->drm, "expected:\n");
12897 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
12898 drm_dbg_kms(&dev_priv->drm, "found:\n");
12899 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
12901 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
12902 drm_err(&dev_priv->drm, "expected:\n");
12903 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
12904 drm_err(&dev_priv->drm, "found:\n");
12905 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
12910 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
12911 bool fastset, const char *name,
12912 const struct drm_dp_vsc_sdp *a,
12913 const struct drm_dp_vsc_sdp *b)
12916 if (!drm_debug_enabled(DRM_UT_KMS))
12919 drm_dbg_kms(&dev_priv->drm,
12920 "fastset mismatch in %s dp sdp\n", name);
12921 drm_dbg_kms(&dev_priv->drm, "expected:\n");
12922 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
12923 drm_dbg_kms(&dev_priv->drm, "found:\n");
12924 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
12926 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
12927 drm_err(&dev_priv->drm, "expected:\n");
12928 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
12929 drm_err(&dev_priv->drm, "found:\n");
12930 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
12934 static void __printf(4, 5)
12935 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
12936 const char *name, const char *format, ...)
12938 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
12939 struct va_format vaf;
12942 va_start(args, format);
12947 drm_dbg_kms(&i915->drm,
12948 "[CRTC:%d:%s] fastset mismatch in %s %pV\n",
12949 crtc->base.base.id, crtc->base.name, name, &vaf);
12951 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
12952 crtc->base.base.id, crtc->base.name, name, &vaf);
12957 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
12959 if (dev_priv->params.fastboot != -1)
12960 return dev_priv->params.fastboot;
12962 /* Enable fastboot by default on Skylake and newer */
12963 if (INTEL_GEN(dev_priv) >= 9)
12966 /* Enable fastboot by default on VLV and CHV */
12967 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12970 /* Disabled by default on all others */
12975 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
12976 const struct intel_crtc_state *pipe_config,
12979 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
12980 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
12983 bool fixup_inherited = fastset &&
12984 current_config->inherited && !pipe_config->inherited;
12986 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
12987 drm_dbg_kms(&dev_priv->drm,
12988 "initial modeset and fastboot not set\n");
12992 #define PIPE_CONF_CHECK_X(name) do { \
12993 if (current_config->name != pipe_config->name) { \
12994 pipe_config_mismatch(fastset, crtc, __stringify(name), \
12995 "(expected 0x%08x, found 0x%08x)", \
12996 current_config->name, \
12997 pipe_config->name); \
13002 #define PIPE_CONF_CHECK_I(name) do { \
13003 if (current_config->name != pipe_config->name) { \
13004 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13005 "(expected %i, found %i)", \
13006 current_config->name, \
13007 pipe_config->name); \
13012 #define PIPE_CONF_CHECK_BOOL(name) do { \
13013 if (current_config->name != pipe_config->name) { \
13014 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13015 "(expected %s, found %s)", \
13016 yesno(current_config->name), \
13017 yesno(pipe_config->name)); \
13023 * Checks state where we only read out the enabling, but not the entire
13024 * state itself (like full infoframes or ELD for audio). These states
13025 * require a full modeset on bootup to fix up.
13027 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
13028 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
13029 PIPE_CONF_CHECK_BOOL(name); \
13031 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13032 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
13033 yesno(current_config->name), \
13034 yesno(pipe_config->name)); \
13039 #define PIPE_CONF_CHECK_P(name) do { \
13040 if (current_config->name != pipe_config->name) { \
13041 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13042 "(expected %p, found %p)", \
13043 current_config->name, \
13044 pipe_config->name); \
13049 #define PIPE_CONF_CHECK_M_N(name) do { \
13050 if (!intel_compare_link_m_n(¤t_config->name, \
13051 &pipe_config->name,\
13053 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13054 "(expected tu %i gmch %i/%i link %i/%i, " \
13055 "found tu %i, gmch %i/%i link %i/%i)", \
13056 current_config->name.tu, \
13057 current_config->name.gmch_m, \
13058 current_config->name.gmch_n, \
13059 current_config->name.link_m, \
13060 current_config->name.link_n, \
13061 pipe_config->name.tu, \
13062 pipe_config->name.gmch_m, \
13063 pipe_config->name.gmch_n, \
13064 pipe_config->name.link_m, \
13065 pipe_config->name.link_n); \
13070 /* This is required for BDW+ where there is only one set of registers for
13071 * switching between high and low RR.
13072 * This macro can be used whenever a comparison has to be made between one
13073 * hw state and multiple sw state variables.
13075 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
13076 if (!intel_compare_link_m_n(¤t_config->name, \
13077 &pipe_config->name, !fastset) && \
13078 !intel_compare_link_m_n(¤t_config->alt_name, \
13079 &pipe_config->name, !fastset)) { \
13080 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13081 "(expected tu %i gmch %i/%i link %i/%i, " \
13082 "or tu %i gmch %i/%i link %i/%i, " \
13083 "found tu %i, gmch %i/%i link %i/%i)", \
13084 current_config->name.tu, \
13085 current_config->name.gmch_m, \
13086 current_config->name.gmch_n, \
13087 current_config->name.link_m, \
13088 current_config->name.link_n, \
13089 current_config->alt_name.tu, \
13090 current_config->alt_name.gmch_m, \
13091 current_config->alt_name.gmch_n, \
13092 current_config->alt_name.link_m, \
13093 current_config->alt_name.link_n, \
13094 pipe_config->name.tu, \
13095 pipe_config->name.gmch_m, \
13096 pipe_config->name.gmch_n, \
13097 pipe_config->name.link_m, \
13098 pipe_config->name.link_n); \
13103 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
13104 if ((current_config->name ^ pipe_config->name) & (mask)) { \
13105 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13106 "(%x) (expected %i, found %i)", \
13108 current_config->name & (mask), \
13109 pipe_config->name & (mask)); \
13114 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
13115 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
13116 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13117 "(expected %i, found %i)", \
13118 current_config->name, \
13119 pipe_config->name); \
13124 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
13125 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
13126 &pipe_config->infoframes.name)) { \
13127 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
13128 ¤t_config->infoframes.name, \
13129 &pipe_config->infoframes.name); \
13134 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
13135 if (!current_config->has_psr && !pipe_config->has_psr && \
13136 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
13137 &pipe_config->infoframes.name)) { \
13138 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
13139 ¤t_config->infoframes.name, \
13140 &pipe_config->infoframes.name); \
13145 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
13146 if (current_config->name1 != pipe_config->name1) { \
13147 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
13148 "(expected %i, found %i, won't compare lut values)", \
13149 current_config->name1, \
13150 pipe_config->name1); \
13153 if (!intel_color_lut_equal(current_config->name2, \
13154 pipe_config->name2, pipe_config->name1, \
13155 bit_precision)) { \
13156 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
13157 "hw_state doesn't match sw_state"); \
13163 #define PIPE_CONF_QUIRK(quirk) \
13164 ((current_config->quirks | pipe_config->quirks) & (quirk))
13166 PIPE_CONF_CHECK_I(cpu_transcoder);
13168 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
13169 PIPE_CONF_CHECK_I(fdi_lanes);
13170 PIPE_CONF_CHECK_M_N(fdi_m_n);
13172 PIPE_CONF_CHECK_I(lane_count);
13173 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
13175 if (INTEL_GEN(dev_priv) < 8) {
13176 PIPE_CONF_CHECK_M_N(dp_m_n);
13178 if (current_config->has_drrs)
13179 PIPE_CONF_CHECK_M_N(dp_m2_n2);
13181 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
13183 PIPE_CONF_CHECK_X(output_types);
13185 /* FIXME do the readout properly and get rid of this quirk */
13186 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
13187 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hdisplay);
13188 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_htotal);
13189 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hblank_start);
13190 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hblank_end);
13191 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hsync_start);
13192 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hsync_end);
13194 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vdisplay);
13195 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vtotal);
13196 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vblank_start);
13197 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vblank_end);
13198 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vsync_start);
13199 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vsync_end);
13201 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hdisplay);
13202 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_htotal);
13203 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_start);
13204 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_end);
13205 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_start);
13206 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_end);
13208 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vdisplay);
13209 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vtotal);
13210 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_start);
13211 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_end);
13212 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_start);
13213 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_end);
13215 PIPE_CONF_CHECK_I(pixel_multiplier);
13217 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13218 DRM_MODE_FLAG_INTERLACE);
13220 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
13221 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13222 DRM_MODE_FLAG_PHSYNC);
13223 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13224 DRM_MODE_FLAG_NHSYNC);
13225 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13226 DRM_MODE_FLAG_PVSYNC);
13227 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13228 DRM_MODE_FLAG_NVSYNC);
13232 PIPE_CONF_CHECK_I(output_format);
13233 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
13234 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
13235 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13236 PIPE_CONF_CHECK_BOOL(limited_color_range);
13238 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
13239 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
13240 PIPE_CONF_CHECK_BOOL(has_infoframe);
13241 /* FIXME do the readout properly and get rid of this quirk */
13242 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE))
13243 PIPE_CONF_CHECK_BOOL(fec_enable);
13245 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
13247 PIPE_CONF_CHECK_X(gmch_pfit.control);
13248 /* pfit ratios are autocomputed by the hw on gen4+ */
13249 if (INTEL_GEN(dev_priv) < 4)
13250 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
13251 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
13254 * Changing the EDP transcoder input mux
13255 * (A_ONOFF vs. A_ON) requires a full modeset.
13257 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
13260 PIPE_CONF_CHECK_I(pipe_src_w);
13261 PIPE_CONF_CHECK_I(pipe_src_h);
13263 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
13264 if (current_config->pch_pfit.enabled) {
13265 PIPE_CONF_CHECK_I(pch_pfit.dst.x1);
13266 PIPE_CONF_CHECK_I(pch_pfit.dst.y1);
13267 PIPE_CONF_CHECK_I(pch_pfit.dst.x2);
13268 PIPE_CONF_CHECK_I(pch_pfit.dst.y2);
13271 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
13272 /* FIXME do the readout properly and get rid of this quirk */
13273 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE))
13274 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
13276 PIPE_CONF_CHECK_X(gamma_mode);
13277 if (IS_CHERRYVIEW(dev_priv))
13278 PIPE_CONF_CHECK_X(cgm_mode);
13280 PIPE_CONF_CHECK_X(csc_mode);
13281 PIPE_CONF_CHECK_BOOL(gamma_enable);
13282 PIPE_CONF_CHECK_BOOL(csc_enable);
13284 PIPE_CONF_CHECK_I(linetime);
13285 PIPE_CONF_CHECK_I(ips_linetime);
13287 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
13289 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
13292 PIPE_CONF_CHECK_BOOL(double_wide);
13294 PIPE_CONF_CHECK_P(shared_dpll);
13296 /* FIXME do the readout properly and get rid of this quirk */
13297 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
13298 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
13299 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
13300 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
13301 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
13302 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
13303 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
13304 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
13305 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
13306 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
13307 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
13308 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
13309 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
13310 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
13311 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
13312 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
13313 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
13314 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
13315 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
13316 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
13317 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
13318 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
13319 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
13320 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
13321 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
13322 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
13323 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
13324 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
13325 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
13326 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
13327 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
13328 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
13330 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
13331 PIPE_CONF_CHECK_X(dsi_pll.div);
13333 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
13334 PIPE_CONF_CHECK_I(pipe_bpp);
13336 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.pipe_mode.crtc_clock);
13337 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
13338 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
13340 PIPE_CONF_CHECK_I(min_voltage_level);
13343 PIPE_CONF_CHECK_X(infoframes.enable);
13344 PIPE_CONF_CHECK_X(infoframes.gcp);
13345 PIPE_CONF_CHECK_INFOFRAME(avi);
13346 PIPE_CONF_CHECK_INFOFRAME(spd);
13347 PIPE_CONF_CHECK_INFOFRAME(hdmi);
13348 PIPE_CONF_CHECK_INFOFRAME(drm);
13349 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
13351 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
13352 PIPE_CONF_CHECK_I(master_transcoder);
13353 PIPE_CONF_CHECK_BOOL(bigjoiner);
13354 PIPE_CONF_CHECK_BOOL(bigjoiner_slave);
13355 PIPE_CONF_CHECK_P(bigjoiner_linked_crtc);
13357 PIPE_CONF_CHECK_I(dsc.compression_enable);
13358 PIPE_CONF_CHECK_I(dsc.dsc_split);
13359 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
13361 PIPE_CONF_CHECK_I(mst_master_transcoder);
13363 #undef PIPE_CONF_CHECK_X
13364 #undef PIPE_CONF_CHECK_I
13365 #undef PIPE_CONF_CHECK_BOOL
13366 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
13367 #undef PIPE_CONF_CHECK_P
13368 #undef PIPE_CONF_CHECK_FLAGS
13369 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
13370 #undef PIPE_CONF_CHECK_COLOR_LUT
13371 #undef PIPE_CONF_QUIRK
13376 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
13377 const struct intel_crtc_state *pipe_config)
13379 if (pipe_config->has_pch_encoder) {
13380 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
13381 &pipe_config->fdi_m_n);
13382 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
13385 * FDI already provided one idea for the dotclock.
13386 * Yell if the encoder disagrees.
13388 drm_WARN(&dev_priv->drm,
13389 !intel_fuzzy_clock_check(fdi_dotclock, dotclock),
13390 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
13391 fdi_dotclock, dotclock);
13395 static void verify_wm_state(struct intel_crtc *crtc,
13396 struct intel_crtc_state *new_crtc_state)
13398 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13399 struct skl_hw_state {
13400 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
13401 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
13402 struct skl_pipe_wm wm;
13404 struct skl_pipe_wm *sw_wm;
13405 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
13406 u8 hw_enabled_slices;
13407 const enum pipe pipe = crtc->pipe;
13408 int plane, level, max_level = ilk_wm_max_level(dev_priv);
13410 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->hw.active)
13413 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
13417 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
13418 sw_wm = &new_crtc_state->wm.skl.optimal;
13420 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
13422 hw_enabled_slices = intel_enabled_dbuf_slices_mask(dev_priv);
13424 if (INTEL_GEN(dev_priv) >= 11 &&
13425 hw_enabled_slices != dev_priv->dbuf.enabled_slices)
13426 drm_err(&dev_priv->drm,
13427 "mismatch in DBUF Slices (expected 0x%x, got 0x%x)\n",
13428 dev_priv->dbuf.enabled_slices,
13429 hw_enabled_slices);
13432 for_each_universal_plane(dev_priv, pipe, plane) {
13433 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13435 hw_plane_wm = &hw->wm.planes[plane];
13436 sw_plane_wm = &sw_wm->planes[plane];
13439 for (level = 0; level <= max_level; level++) {
13440 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13441 &sw_plane_wm->wm[level]) ||
13442 (level == 0 && skl_wm_level_equals(&hw_plane_wm->wm[level],
13443 &sw_plane_wm->sagv_wm0)))
13446 drm_err(&dev_priv->drm,
13447 "mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13448 pipe_name(pipe), plane + 1, level,
13449 sw_plane_wm->wm[level].plane_en,
13450 sw_plane_wm->wm[level].plane_res_b,
13451 sw_plane_wm->wm[level].plane_res_l,
13452 hw_plane_wm->wm[level].plane_en,
13453 hw_plane_wm->wm[level].plane_res_b,
13454 hw_plane_wm->wm[level].plane_res_l);
13457 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13458 &sw_plane_wm->trans_wm)) {
13459 drm_err(&dev_priv->drm,
13460 "mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13461 pipe_name(pipe), plane + 1,
13462 sw_plane_wm->trans_wm.plane_en,
13463 sw_plane_wm->trans_wm.plane_res_b,
13464 sw_plane_wm->trans_wm.plane_res_l,
13465 hw_plane_wm->trans_wm.plane_en,
13466 hw_plane_wm->trans_wm.plane_res_b,
13467 hw_plane_wm->trans_wm.plane_res_l);
13471 hw_ddb_entry = &hw->ddb_y[plane];
13472 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
13474 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13475 drm_err(&dev_priv->drm,
13476 "mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
13477 pipe_name(pipe), plane + 1,
13478 sw_ddb_entry->start, sw_ddb_entry->end,
13479 hw_ddb_entry->start, hw_ddb_entry->end);
13485 * If the cursor plane isn't active, we may not have updated it's ddb
13486 * allocation. In that case since the ddb allocation will be updated
13487 * once the plane becomes visible, we can skip this check
13490 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13492 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
13493 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
13496 for (level = 0; level <= max_level; level++) {
13497 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13498 &sw_plane_wm->wm[level]) ||
13499 (level == 0 && skl_wm_level_equals(&hw_plane_wm->wm[level],
13500 &sw_plane_wm->sagv_wm0)))
13503 drm_err(&dev_priv->drm,
13504 "mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13505 pipe_name(pipe), level,
13506 sw_plane_wm->wm[level].plane_en,
13507 sw_plane_wm->wm[level].plane_res_b,
13508 sw_plane_wm->wm[level].plane_res_l,
13509 hw_plane_wm->wm[level].plane_en,
13510 hw_plane_wm->wm[level].plane_res_b,
13511 hw_plane_wm->wm[level].plane_res_l);
13514 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13515 &sw_plane_wm->trans_wm)) {
13516 drm_err(&dev_priv->drm,
13517 "mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13519 sw_plane_wm->trans_wm.plane_en,
13520 sw_plane_wm->trans_wm.plane_res_b,
13521 sw_plane_wm->trans_wm.plane_res_l,
13522 hw_plane_wm->trans_wm.plane_en,
13523 hw_plane_wm->trans_wm.plane_res_b,
13524 hw_plane_wm->trans_wm.plane_res_l);
13528 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
13529 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
13531 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13532 drm_err(&dev_priv->drm,
13533 "mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
13535 sw_ddb_entry->start, sw_ddb_entry->end,
13536 hw_ddb_entry->start, hw_ddb_entry->end);
13544 verify_connector_state(struct intel_atomic_state *state,
13545 struct intel_crtc *crtc)
13547 struct drm_connector *connector;
13548 struct drm_connector_state *new_conn_state;
13551 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
13552 struct drm_encoder *encoder = connector->encoder;
13553 struct intel_crtc_state *crtc_state = NULL;
13555 if (new_conn_state->crtc != &crtc->base)
13559 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13561 intel_connector_verify_state(crtc_state, new_conn_state);
13563 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
13564 "connector's atomic encoder doesn't match legacy encoder\n");
13569 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
13571 struct intel_encoder *encoder;
13572 struct drm_connector *connector;
13573 struct drm_connector_state *old_conn_state, *new_conn_state;
13576 for_each_intel_encoder(&dev_priv->drm, encoder) {
13577 bool enabled = false, found = false;
13580 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s]\n",
13581 encoder->base.base.id,
13582 encoder->base.name);
13584 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
13585 new_conn_state, i) {
13586 if (old_conn_state->best_encoder == &encoder->base)
13589 if (new_conn_state->best_encoder != &encoder->base)
13591 found = enabled = true;
13593 I915_STATE_WARN(new_conn_state->crtc !=
13594 encoder->base.crtc,
13595 "connector's crtc doesn't match encoder crtc\n");
13601 I915_STATE_WARN(!!encoder->base.crtc != enabled,
13602 "encoder's enabled state mismatch "
13603 "(expected %i, found %i)\n",
13604 !!encoder->base.crtc, enabled);
13606 if (!encoder->base.crtc) {
13609 active = encoder->get_hw_state(encoder, &pipe);
13610 I915_STATE_WARN(active,
13611 "encoder detached but still enabled on pipe %c.\n",
13618 verify_crtc_state(struct intel_crtc *crtc,
13619 struct intel_crtc_state *old_crtc_state,
13620 struct intel_crtc_state *new_crtc_state)
13622 struct drm_device *dev = crtc->base.dev;
13623 struct drm_i915_private *dev_priv = to_i915(dev);
13624 struct intel_encoder *encoder;
13625 struct intel_crtc_state *pipe_config = old_crtc_state;
13626 struct drm_atomic_state *state = old_crtc_state->uapi.state;
13627 struct intel_crtc *master = crtc;
13629 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
13630 intel_crtc_free_hw_state(old_crtc_state);
13631 intel_crtc_state_reset(old_crtc_state, crtc);
13632 old_crtc_state->uapi.state = state;
13634 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s]\n", crtc->base.base.id,
13637 pipe_config->hw.enable = new_crtc_state->hw.enable;
13639 intel_crtc_get_pipe_config(pipe_config);
13641 /* we keep both pipes enabled on 830 */
13642 if (IS_I830(dev_priv) && pipe_config->hw.active)
13643 pipe_config->hw.active = new_crtc_state->hw.active;
13645 I915_STATE_WARN(new_crtc_state->hw.active != pipe_config->hw.active,
13646 "crtc active state doesn't match with hw state "
13647 "(expected %i, found %i)\n",
13648 new_crtc_state->hw.active, pipe_config->hw.active);
13650 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
13651 "transitional active state does not match atomic hw state "
13652 "(expected %i, found %i)\n",
13653 new_crtc_state->hw.active, crtc->active);
13655 if (new_crtc_state->bigjoiner_slave)
13656 master = new_crtc_state->bigjoiner_linked_crtc;
13658 for_each_encoder_on_crtc(dev, &master->base, encoder) {
13662 active = encoder->get_hw_state(encoder, &pipe);
13663 I915_STATE_WARN(active != new_crtc_state->hw.active,
13664 "[ENCODER:%i] active %i with crtc active %i\n",
13665 encoder->base.base.id, active,
13666 new_crtc_state->hw.active);
13668 I915_STATE_WARN(active && master->pipe != pipe,
13669 "Encoder connected to wrong pipe %c\n",
13673 intel_encoder_get_config(encoder, pipe_config);
13676 if (!new_crtc_state->hw.active)
13679 intel_pipe_config_sanity_check(dev_priv, pipe_config);
13681 if (!intel_pipe_config_compare(new_crtc_state,
13682 pipe_config, false)) {
13683 I915_STATE_WARN(1, "pipe state doesn't match!\n");
13684 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
13685 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
13690 intel_verify_planes(struct intel_atomic_state *state)
13692 struct intel_plane *plane;
13693 const struct intel_plane_state *plane_state;
13696 for_each_new_intel_plane_in_state(state, plane,
13698 assert_plane(plane, plane_state->planar_slave ||
13699 plane_state->uapi.visible);
13703 verify_single_dpll_state(struct drm_i915_private *dev_priv,
13704 struct intel_shared_dpll *pll,
13705 struct intel_crtc *crtc,
13706 struct intel_crtc_state *new_crtc_state)
13708 struct intel_dpll_hw_state dpll_hw_state;
13709 unsigned int crtc_mask;
13712 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
13714 drm_dbg_kms(&dev_priv->drm, "%s\n", pll->info->name);
13716 active = intel_dpll_get_hw_state(dev_priv, pll, &dpll_hw_state);
13718 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
13719 I915_STATE_WARN(!pll->on && pll->active_mask,
13720 "pll in active use but not on in sw tracking\n");
13721 I915_STATE_WARN(pll->on && !pll->active_mask,
13722 "pll is on but not used by any active crtc\n");
13723 I915_STATE_WARN(pll->on != active,
13724 "pll on state mismatch (expected %i, found %i)\n",
13729 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
13730 "more active pll users than references: %x vs %x\n",
13731 pll->active_mask, pll->state.crtc_mask);
13736 crtc_mask = drm_crtc_mask(&crtc->base);
13738 if (new_crtc_state->hw.active)
13739 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
13740 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
13741 pipe_name(crtc->pipe), pll->active_mask);
13743 I915_STATE_WARN(pll->active_mask & crtc_mask,
13744 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
13745 pipe_name(crtc->pipe), pll->active_mask);
13747 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
13748 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
13749 crtc_mask, pll->state.crtc_mask);
13751 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
13753 sizeof(dpll_hw_state)),
13754 "pll hw state mismatch\n");
13758 verify_shared_dpll_state(struct intel_crtc *crtc,
13759 struct intel_crtc_state *old_crtc_state,
13760 struct intel_crtc_state *new_crtc_state)
13762 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13764 if (new_crtc_state->shared_dpll)
13765 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
13767 if (old_crtc_state->shared_dpll &&
13768 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
13769 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
13770 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
13772 I915_STATE_WARN(pll->active_mask & crtc_mask,
13773 "pll active mismatch (didn't expect pipe %c in active mask)\n",
13774 pipe_name(crtc->pipe));
13775 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
13776 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
13777 pipe_name(crtc->pipe));
13782 intel_modeset_verify_crtc(struct intel_crtc *crtc,
13783 struct intel_atomic_state *state,
13784 struct intel_crtc_state *old_crtc_state,
13785 struct intel_crtc_state *new_crtc_state)
13787 if (!intel_crtc_needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
13790 verify_wm_state(crtc, new_crtc_state);
13791 verify_connector_state(state, crtc);
13792 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
13793 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
13797 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
13801 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++)
13802 verify_single_dpll_state(dev_priv,
13803 &dev_priv->dpll.shared_dplls[i],
13808 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
13809 struct intel_atomic_state *state)
13811 verify_encoder_state(dev_priv, state);
13812 verify_connector_state(state, NULL);
13813 verify_disabled_dpll_state(dev_priv);
13817 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
13819 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
13820 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13821 const struct drm_display_mode *adjusted_mode =
13822 &crtc_state->hw.adjusted_mode;
13824 drm_calc_timestamping_constants(&crtc->base, adjusted_mode);
13826 crtc->mode_flags = crtc_state->mode_flags;
13829 * The scanline counter increments at the leading edge of hsync.
13831 * On most platforms it starts counting from vtotal-1 on the
13832 * first active line. That means the scanline counter value is
13833 * always one less than what we would expect. Ie. just after
13834 * start of vblank, which also occurs at start of hsync (on the
13835 * last active line), the scanline counter will read vblank_start-1.
13837 * On gen2 the scanline counter starts counting from 1 instead
13838 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13839 * to keep the value positive), instead of adding one.
13841 * On HSW+ the behaviour of the scanline counter depends on the output
13842 * type. For DP ports it behaves like most other platforms, but on HDMI
13843 * there's an extra 1 line difference. So we need to add two instead of
13844 * one to the value.
13846 * On VLV/CHV DSI the scanline counter would appear to increment
13847 * approx. 1/3 of a scanline before start of vblank. Unfortunately
13848 * that means we can't tell whether we're in vblank or not while
13849 * we're on that particular line. We must still set scanline_offset
13850 * to 1 so that the vblank timestamps come out correct when we query
13851 * the scanline counter from within the vblank interrupt handler.
13852 * However if queried just before the start of vblank we'll get an
13853 * answer that's slightly in the future.
13855 if (IS_GEN(dev_priv, 2)) {
13858 vtotal = adjusted_mode->crtc_vtotal;
13859 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
13862 crtc->scanline_offset = vtotal - 1;
13863 } else if (HAS_DDI(dev_priv) &&
13864 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
13865 crtc->scanline_offset = 2;
13867 crtc->scanline_offset = 1;
13871 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
13873 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13874 struct intel_crtc_state *new_crtc_state;
13875 struct intel_crtc *crtc;
13878 if (!dev_priv->display.crtc_compute_clock)
13881 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13882 if (!intel_crtc_needs_modeset(new_crtc_state))
13885 intel_release_shared_dplls(state, crtc);
13890 * This implements the workaround described in the "notes" section of the mode
13891 * set sequence documentation. When going from no pipes or single pipe to
13892 * multiple pipes, and planes are enabled after the pipe, we need to wait at
13893 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
13895 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
13897 struct intel_crtc_state *crtc_state;
13898 struct intel_crtc *crtc;
13899 struct intel_crtc_state *first_crtc_state = NULL;
13900 struct intel_crtc_state *other_crtc_state = NULL;
13901 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
13904 /* look at all crtc's that are going to be enabled in during modeset */
13905 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
13906 if (!crtc_state->hw.active ||
13907 !intel_crtc_needs_modeset(crtc_state))
13910 if (first_crtc_state) {
13911 other_crtc_state = crtc_state;
13914 first_crtc_state = crtc_state;
13915 first_pipe = crtc->pipe;
13919 /* No workaround needed? */
13920 if (!first_crtc_state)
13923 /* w/a possibly needed, check how many crtc's are already enabled. */
13924 for_each_intel_crtc(state->base.dev, crtc) {
13925 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
13926 if (IS_ERR(crtc_state))
13927 return PTR_ERR(crtc_state);
13929 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
13931 if (!crtc_state->hw.active ||
13932 intel_crtc_needs_modeset(crtc_state))
13935 /* 2 or more enabled crtcs means no need for w/a */
13936 if (enabled_pipe != INVALID_PIPE)
13939 enabled_pipe = crtc->pipe;
13942 if (enabled_pipe != INVALID_PIPE)
13943 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
13944 else if (other_crtc_state)
13945 other_crtc_state->hsw_workaround_pipe = first_pipe;
13950 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
13953 const struct intel_crtc_state *crtc_state;
13954 struct intel_crtc *crtc;
13957 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
13958 if (crtc_state->hw.active)
13959 active_pipes |= BIT(crtc->pipe);
13961 active_pipes &= ~BIT(crtc->pipe);
13964 return active_pipes;
13967 static int intel_modeset_checks(struct intel_atomic_state *state)
13969 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13971 state->modeset = true;
13973 if (IS_HASWELL(dev_priv))
13974 return hsw_mode_set_planes_workaround(state);
13980 * Handle calculation of various watermark data at the end of the atomic check
13981 * phase. The code here should be run after the per-crtc and per-plane 'check'
13982 * handlers to ensure that all derived state has been updated.
13984 static int calc_watermark_data(struct intel_atomic_state *state)
13986 struct drm_device *dev = state->base.dev;
13987 struct drm_i915_private *dev_priv = to_i915(dev);
13989 /* Is there platform-specific watermark information to calculate? */
13990 if (dev_priv->display.compute_global_watermarks)
13991 return dev_priv->display.compute_global_watermarks(state);
13996 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
13997 struct intel_crtc_state *new_crtc_state)
13999 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
14002 new_crtc_state->uapi.mode_changed = false;
14003 new_crtc_state->update_pipe = true;
14006 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
14007 struct intel_crtc_state *new_crtc_state)
14010 * If we're not doing the full modeset we want to
14011 * keep the current M/N values as they may be
14012 * sufficiently different to the computed values
14013 * to cause problems.
14015 * FIXME: should really copy more fuzzy state here
14017 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
14018 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
14019 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
14020 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
14023 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
14024 struct intel_crtc *crtc,
14027 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14028 struct intel_plane *plane;
14030 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
14031 struct intel_plane_state *plane_state;
14033 if ((plane_ids_mask & BIT(plane->id)) == 0)
14036 plane_state = intel_atomic_get_plane_state(state, plane);
14037 if (IS_ERR(plane_state))
14038 return PTR_ERR(plane_state);
14044 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
14045 struct intel_crtc *crtc)
14047 const struct intel_crtc_state *old_crtc_state =
14048 intel_atomic_get_old_crtc_state(state, crtc);
14049 const struct intel_crtc_state *new_crtc_state =
14050 intel_atomic_get_new_crtc_state(state, crtc);
14052 return intel_crtc_add_planes_to_state(state, crtc,
14053 old_crtc_state->enabled_planes |
14054 new_crtc_state->enabled_planes);
14057 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
14059 /* See {hsw,vlv,ivb}_plane_ratio() */
14060 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
14061 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
14062 IS_IVYBRIDGE(dev_priv) || (INTEL_GEN(dev_priv) >= 11);
14065 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
14066 struct intel_crtc *crtc,
14067 struct intel_crtc *other)
14069 const struct intel_plane_state *plane_state;
14070 struct intel_plane *plane;
14074 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14075 if (plane->pipe == crtc->pipe)
14076 plane_ids |= BIT(plane->id);
14079 return intel_crtc_add_planes_to_state(state, other, plane_ids);
14082 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
14084 const struct intel_crtc_state *crtc_state;
14085 struct intel_crtc *crtc;
14088 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14091 if (!crtc_state->bigjoiner)
14094 ret = intel_crtc_add_bigjoiner_planes(state, crtc,
14095 crtc_state->bigjoiner_linked_crtc);
14103 static int intel_atomic_check_planes(struct intel_atomic_state *state)
14105 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14106 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14107 struct intel_plane_state *plane_state;
14108 struct intel_plane *plane;
14109 struct intel_crtc *crtc;
14112 ret = icl_add_linked_planes(state);
14116 ret = intel_bigjoiner_add_affected_planes(state);
14120 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14121 ret = intel_plane_atomic_check(state, plane);
14123 drm_dbg_atomic(&dev_priv->drm,
14124 "[PLANE:%d:%s] atomic driver check failed\n",
14125 plane->base.base.id, plane->base.name);
14130 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14131 new_crtc_state, i) {
14132 u8 old_active_planes, new_active_planes;
14134 ret = icl_check_nv12_planes(new_crtc_state);
14139 * On some platforms the number of active planes affects
14140 * the planes' minimum cdclk calculation. Add such planes
14141 * to the state before we compute the minimum cdclk.
14143 if (!active_planes_affects_min_cdclk(dev_priv))
14146 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14147 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14150 * Not only the number of planes, but if the plane configuration had
14151 * changed might already mean we need to recompute min CDCLK,
14152 * because different planes might consume different amount of Dbuf bandwidth
14153 * according to formula: Bw per plane = Pixel rate * bpp * pipe/plane scale factor
14155 if (old_active_planes == new_active_planes)
14158 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
14166 static int intel_atomic_check_cdclk(struct intel_atomic_state *state,
14167 bool *need_cdclk_calc)
14169 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14170 const struct intel_cdclk_state *old_cdclk_state;
14171 const struct intel_cdclk_state *new_cdclk_state;
14172 struct intel_plane_state *plane_state;
14173 struct intel_bw_state *new_bw_state;
14174 struct intel_plane *plane;
14180 * active_planes bitmask has been updated, and potentially
14181 * affected planes are part of the state. We can now
14182 * compute the minimum cdclk for each plane.
14184 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14185 ret = intel_plane_calc_min_cdclk(state, plane, need_cdclk_calc);
14190 old_cdclk_state = intel_atomic_get_old_cdclk_state(state);
14191 new_cdclk_state = intel_atomic_get_new_cdclk_state(state);
14193 if (new_cdclk_state &&
14194 old_cdclk_state->force_min_cdclk != new_cdclk_state->force_min_cdclk)
14195 *need_cdclk_calc = true;
14197 ret = dev_priv->display.bw_calc_min_cdclk(state);
14201 new_bw_state = intel_atomic_get_new_bw_state(state);
14203 if (!new_cdclk_state || !new_bw_state)
14206 for_each_pipe(dev_priv, pipe) {
14207 min_cdclk = max(new_cdclk_state->min_cdclk[pipe], min_cdclk);
14210 * Currently do this change only if we need to increase
14212 if (new_bw_state->min_cdclk > min_cdclk)
14213 *need_cdclk_calc = true;
14219 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
14221 struct intel_crtc_state *crtc_state;
14222 struct intel_crtc *crtc;
14225 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14226 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
14229 ret = intel_crtc_atomic_check(state, crtc);
14231 drm_dbg_atomic(&i915->drm,
14232 "[CRTC:%d:%s] atomic driver check failed\n",
14233 crtc->base.base.id, crtc->base.name);
14241 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
14244 const struct intel_crtc_state *new_crtc_state;
14245 struct intel_crtc *crtc;
14248 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14249 if (new_crtc_state->hw.enable &&
14250 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
14251 intel_crtc_needs_modeset(new_crtc_state))
14258 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
14259 struct intel_crtc *crtc,
14260 struct intel_crtc_state *old_crtc_state,
14261 struct intel_crtc_state *new_crtc_state)
14263 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14264 struct intel_crtc_state *slave_crtc_state, *master_crtc_state;
14265 struct intel_crtc *slave, *master;
14267 /* slave being enabled, is master is still claiming this crtc? */
14268 if (old_crtc_state->bigjoiner_slave) {
14270 master = old_crtc_state->bigjoiner_linked_crtc;
14271 master_crtc_state = intel_atomic_get_new_crtc_state(state, master);
14272 if (!master_crtc_state || !intel_crtc_needs_modeset(master_crtc_state))
14276 if (!new_crtc_state->bigjoiner)
14279 if (1 + crtc->pipe >= INTEL_NUM_PIPES(dev_priv)) {
14280 DRM_DEBUG_KMS("[CRTC:%d:%s] Big joiner configuration requires "
14281 "CRTC + 1 to be used, doesn't exist\n",
14282 crtc->base.base.id, crtc->base.name);
14286 slave = new_crtc_state->bigjoiner_linked_crtc =
14287 intel_get_crtc_for_pipe(dev_priv, crtc->pipe + 1);
14288 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave);
14290 if (IS_ERR(slave_crtc_state))
14291 return PTR_ERR(slave_crtc_state);
14293 /* master being enabled, slave was already configured? */
14294 if (slave_crtc_state->uapi.enable)
14297 DRM_DEBUG_KMS("[CRTC:%d:%s] Used as slave for big joiner\n",
14298 slave->base.base.id, slave->base.name);
14300 return copy_bigjoiner_crtc_state(slave_crtc_state, new_crtc_state);
14303 DRM_DEBUG_KMS("[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
14304 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
14305 slave->base.base.id, slave->base.name,
14306 master->base.base.id, master->base.name);
14310 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
14311 struct intel_crtc_state *master_crtc_state)
14313 struct intel_crtc_state *slave_crtc_state =
14314 intel_atomic_get_new_crtc_state(state, master_crtc_state->bigjoiner_linked_crtc);
14316 slave_crtc_state->bigjoiner = master_crtc_state->bigjoiner = false;
14317 slave_crtc_state->bigjoiner_slave = master_crtc_state->bigjoiner_slave = false;
14318 slave_crtc_state->bigjoiner_linked_crtc = master_crtc_state->bigjoiner_linked_crtc = NULL;
14319 intel_crtc_copy_uapi_to_hw_state(state, slave_crtc_state);
14323 * DOC: asynchronous flip implementation
14325 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
14326 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
14327 * Correspondingly, support is currently added for primary plane only.
14329 * Async flip can only change the plane surface address, so anything else
14330 * changing is rejected from the intel_atomic_check_async() function.
14331 * Once this check is cleared, flip done interrupt is enabled using
14332 * the skl_enable_flip_done() function.
14334 * As soon as the surface address register is written, flip done interrupt is
14335 * generated and the requested events are sent to the usersapce in the interrupt
14336 * handler itself. The timestamp and sequence sent during the flip done event
14337 * correspond to the last vblank and have no relation to the actual time when
14338 * the flip done event was sent.
14340 static int intel_atomic_check_async(struct intel_atomic_state *state)
14342 struct drm_i915_private *i915 = to_i915(state->base.dev);
14343 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14344 const struct intel_plane_state *new_plane_state, *old_plane_state;
14345 struct intel_crtc *crtc;
14346 struct intel_plane *plane;
14349 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14350 new_crtc_state, i) {
14351 if (intel_crtc_needs_modeset(new_crtc_state)) {
14352 drm_dbg_kms(&i915->drm, "Modeset Required. Async flip not supported\n");
14356 if (!new_crtc_state->hw.active) {
14357 drm_dbg_kms(&i915->drm, "CRTC inactive\n");
14360 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
14361 drm_dbg_kms(&i915->drm,
14362 "Active planes cannot be changed during async flip\n");
14367 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
14368 new_plane_state, i) {
14370 * TODO: Async flip is only supported through the page flip IOCTL
14371 * as of now. So support currently added for primary plane only.
14372 * Support for other planes on platforms on which supports
14373 * this(vlv/chv and icl+) should be added when async flip is
14374 * enabled in the atomic IOCTL path.
14376 if (plane->id != PLANE_PRIMARY)
14380 * FIXME: This check is kept generic for all platforms.
14381 * Need to verify this for all gen9 and gen10 platforms to enable
14382 * this selectively if required.
14384 switch (new_plane_state->hw.fb->modifier) {
14385 case I915_FORMAT_MOD_X_TILED:
14386 case I915_FORMAT_MOD_Y_TILED:
14387 case I915_FORMAT_MOD_Yf_TILED:
14390 drm_dbg_kms(&i915->drm,
14391 "Linear memory/CCS does not support async flips\n");
14395 if (old_plane_state->color_plane[0].stride !=
14396 new_plane_state->color_plane[0].stride) {
14397 drm_dbg_kms(&i915->drm, "Stride cannot be changed in async flip\n");
14401 if (old_plane_state->hw.fb->modifier !=
14402 new_plane_state->hw.fb->modifier) {
14403 drm_dbg_kms(&i915->drm,
14404 "Framebuffer modifiers cannot be changed in async flip\n");
14408 if (old_plane_state->hw.fb->format !=
14409 new_plane_state->hw.fb->format) {
14410 drm_dbg_kms(&i915->drm,
14411 "Framebuffer format cannot be changed in async flip\n");
14415 if (old_plane_state->hw.rotation !=
14416 new_plane_state->hw.rotation) {
14417 drm_dbg_kms(&i915->drm, "Rotation cannot be changed in async flip\n");
14421 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
14422 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
14423 drm_dbg_kms(&i915->drm,
14424 "Plane size/co-ordinates cannot be changed in async flip\n");
14428 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
14429 drm_dbg_kms(&i915->drm, "Alpha value cannot be changed in async flip\n");
14433 if (old_plane_state->hw.pixel_blend_mode !=
14434 new_plane_state->hw.pixel_blend_mode) {
14435 drm_dbg_kms(&i915->drm,
14436 "Pixel blend mode cannot be changed in async flip\n");
14440 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
14441 drm_dbg_kms(&i915->drm,
14442 "Color encoding cannot be changed in async flip\n");
14446 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
14447 drm_dbg_kms(&i915->drm, "Color range cannot be changed in async flip\n");
14455 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
14457 struct intel_crtc_state *crtc_state;
14458 struct intel_crtc *crtc;
14461 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14462 struct intel_crtc_state *linked_crtc_state;
14463 struct intel_crtc *linked_crtc;
14466 if (!crtc_state->bigjoiner)
14469 linked_crtc = crtc_state->bigjoiner_linked_crtc;
14470 linked_crtc_state = intel_atomic_get_crtc_state(&state->base, linked_crtc);
14471 if (IS_ERR(linked_crtc_state))
14472 return PTR_ERR(linked_crtc_state);
14474 if (!intel_crtc_needs_modeset(crtc_state))
14477 linked_crtc_state->uapi.mode_changed = true;
14479 ret = drm_atomic_add_affected_connectors(&state->base,
14480 &linked_crtc->base);
14484 ret = intel_atomic_add_affected_planes(state, linked_crtc);
14489 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14490 /* Kill old bigjoiner link, we may re-establish afterwards */
14491 if (intel_crtc_needs_modeset(crtc_state) &&
14492 crtc_state->bigjoiner && !crtc_state->bigjoiner_slave)
14493 kill_bigjoiner_slave(state, crtc_state);
14500 * intel_atomic_check - validate state object
14502 * @_state: state to validate
14504 static int intel_atomic_check(struct drm_device *dev,
14505 struct drm_atomic_state *_state)
14507 struct drm_i915_private *dev_priv = to_i915(dev);
14508 struct intel_atomic_state *state = to_intel_atomic_state(_state);
14509 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14510 struct intel_crtc *crtc;
14512 bool any_ms = false;
14514 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14515 new_crtc_state, i) {
14516 if (new_crtc_state->inherited != old_crtc_state->inherited)
14517 new_crtc_state->uapi.mode_changed = true;
14520 ret = drm_atomic_helper_check_modeset(dev, &state->base);
14524 ret = intel_bigjoiner_add_affected_crtcs(state);
14528 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14529 new_crtc_state, i) {
14530 if (!intel_crtc_needs_modeset(new_crtc_state)) {
14532 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, new_crtc_state);
14537 if (!new_crtc_state->uapi.enable) {
14538 if (!new_crtc_state->bigjoiner_slave) {
14539 intel_crtc_copy_uapi_to_hw_state(state, new_crtc_state);
14545 ret = intel_crtc_prepare_cleared_state(state, new_crtc_state);
14549 ret = intel_modeset_pipe_config(state, new_crtc_state);
14553 ret = intel_atomic_check_bigjoiner(state, crtc, old_crtc_state,
14559 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14560 new_crtc_state, i) {
14561 if (!intel_crtc_needs_modeset(new_crtc_state))
14564 ret = intel_modeset_pipe_config_late(new_crtc_state);
14568 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
14572 * Check if fastset is allowed by external dependencies like other
14573 * pipes and transcoders.
14575 * Right now it only forces a fullmodeset when the MST master
14576 * transcoder did not changed but the pipe of the master transcoder
14577 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
14578 * in case of port synced crtcs, if one of the synced crtcs
14579 * needs a full modeset, all other synced crtcs should be
14580 * forced a full modeset.
14582 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14583 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
14586 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
14587 enum transcoder master = new_crtc_state->mst_master_transcoder;
14589 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
14590 new_crtc_state->uapi.mode_changed = true;
14591 new_crtc_state->update_pipe = false;
14595 if (is_trans_port_sync_mode(new_crtc_state)) {
14596 u8 trans = new_crtc_state->sync_mode_slaves_mask;
14598 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
14599 trans |= BIT(new_crtc_state->master_transcoder);
14601 if (intel_cpu_transcoders_need_modeset(state, trans)) {
14602 new_crtc_state->uapi.mode_changed = true;
14603 new_crtc_state->update_pipe = false;
14607 if (new_crtc_state->bigjoiner) {
14608 struct intel_crtc_state *linked_crtc_state =
14609 intel_atomic_get_new_crtc_state(state, new_crtc_state->bigjoiner_linked_crtc);
14611 if (intel_crtc_needs_modeset(linked_crtc_state)) {
14612 new_crtc_state->uapi.mode_changed = true;
14613 new_crtc_state->update_pipe = false;
14618 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14619 new_crtc_state, i) {
14620 if (intel_crtc_needs_modeset(new_crtc_state)) {
14625 if (!new_crtc_state->update_pipe)
14628 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
14631 if (any_ms && !check_digital_port_conflicts(state)) {
14632 drm_dbg_kms(&dev_priv->drm,
14633 "rejecting conflicting digital port configuration\n");
14638 ret = drm_dp_mst_atomic_check(&state->base);
14642 ret = intel_atomic_check_planes(state);
14647 * distrust_bios_wm will force a full dbuf recomputation
14648 * but the hardware state will only get updated accordingly
14649 * if state->modeset==true. Hence distrust_bios_wm==true &&
14650 * state->modeset==false is an invalid combination which
14651 * would cause the hardware and software dbuf state to get
14652 * out of sync. We must prevent that.
14654 * FIXME clean up this mess and introduce better
14655 * state tracking for dbuf.
14657 if (dev_priv->wm.distrust_bios_wm)
14660 intel_fbc_choose_crtc(dev_priv, state);
14661 ret = calc_watermark_data(state);
14665 ret = intel_bw_atomic_check(state);
14669 ret = intel_atomic_check_cdclk(state, &any_ms);
14674 ret = intel_modeset_checks(state);
14678 ret = intel_modeset_calc_cdclk(state);
14682 intel_modeset_clear_plls(state);
14685 ret = intel_atomic_check_crtcs(state);
14689 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14690 new_crtc_state, i) {
14691 if (new_crtc_state->uapi.async_flip) {
14692 ret = intel_atomic_check_async(state);
14697 if (!intel_crtc_needs_modeset(new_crtc_state) &&
14698 !new_crtc_state->update_pipe)
14701 intel_dump_pipe_config(new_crtc_state, state,
14702 intel_crtc_needs_modeset(new_crtc_state) ?
14703 "[modeset]" : "[fastset]");
14709 if (ret == -EDEADLK)
14713 * FIXME would probably be nice to know which crtc specifically
14714 * caused the failure, in cases where we can pinpoint it.
14716 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14718 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
14723 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
14725 struct intel_crtc_state *crtc_state;
14726 struct intel_crtc *crtc;
14729 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
14733 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14734 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
14736 if (mode_changed || crtc_state->update_pipe ||
14737 crtc_state->uapi.color_mgmt_changed) {
14738 intel_dsb_prepare(crtc_state);
14745 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
14747 struct drm_device *dev = crtc->base.dev;
14748 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
14750 if (!vblank->max_vblank_count)
14751 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
14753 return crtc->base.funcs->get_vblank_counter(&crtc->base);
14756 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14757 struct intel_crtc_state *crtc_state)
14759 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14761 if (!IS_GEN(dev_priv, 2) || crtc_state->active_planes)
14762 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14764 if (crtc_state->has_pch_encoder) {
14765 enum pipe pch_transcoder =
14766 intel_crtc_pch_transcoder(crtc);
14768 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14772 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
14773 const struct intel_crtc_state *new_crtc_state)
14775 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
14776 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14779 * Update pipe size and adjust fitter if needed: the reason for this is
14780 * that in compute_mode_changes we check the native mode (not the pfit
14781 * mode) to see if we can flip rather than do a full mode set. In the
14782 * fastboot case, we'll flip, but if we don't update the pipesrc and
14783 * pfit state, we'll end up with a big fb scanned out into the wrong
14786 intel_set_pipe_src_size(new_crtc_state);
14788 /* on skylake this is done by detaching scalers */
14789 if (INTEL_GEN(dev_priv) >= 9) {
14790 skl_detach_scalers(new_crtc_state);
14792 if (new_crtc_state->pch_pfit.enabled)
14793 skl_pfit_enable(new_crtc_state);
14794 } else if (HAS_PCH_SPLIT(dev_priv)) {
14795 if (new_crtc_state->pch_pfit.enabled)
14796 ilk_pfit_enable(new_crtc_state);
14797 else if (old_crtc_state->pch_pfit.enabled)
14798 ilk_pfit_disable(old_crtc_state);
14802 * The register is supposedly single buffered so perhaps
14803 * not 100% correct to do this here. But SKL+ calculate
14804 * this based on the adjust pixel rate so pfit changes do
14805 * affect it and so it must be updated for fastsets.
14806 * HSW/BDW only really need this here for fastboot, after
14807 * that the value should not change without a full modeset.
14809 if (INTEL_GEN(dev_priv) >= 9 ||
14810 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14811 hsw_set_linetime_wm(new_crtc_state);
14813 if (INTEL_GEN(dev_priv) >= 11)
14814 icl_set_pipe_chicken(crtc);
14817 static void commit_pipe_config(struct intel_atomic_state *state,
14818 struct intel_crtc *crtc)
14820 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14821 const struct intel_crtc_state *old_crtc_state =
14822 intel_atomic_get_old_crtc_state(state, crtc);
14823 const struct intel_crtc_state *new_crtc_state =
14824 intel_atomic_get_new_crtc_state(state, crtc);
14825 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
14828 * During modesets pipe configuration was programmed as the
14829 * CRTC was enabled.
14832 if (new_crtc_state->uapi.color_mgmt_changed ||
14833 new_crtc_state->update_pipe)
14834 intel_color_commit(new_crtc_state);
14836 if (INTEL_GEN(dev_priv) >= 9)
14837 skl_detach_scalers(new_crtc_state);
14839 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
14840 bdw_set_pipemisc(new_crtc_state);
14842 if (new_crtc_state->update_pipe)
14843 intel_pipe_fastset(old_crtc_state, new_crtc_state);
14845 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
14848 if (dev_priv->display.atomic_update_watermarks)
14849 dev_priv->display.atomic_update_watermarks(state, crtc);
14852 static void intel_enable_crtc(struct intel_atomic_state *state,
14853 struct intel_crtc *crtc)
14855 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14856 const struct intel_crtc_state *new_crtc_state =
14857 intel_atomic_get_new_crtc_state(state, crtc);
14859 if (!intel_crtc_needs_modeset(new_crtc_state))
14862 intel_crtc_update_active_timings(new_crtc_state);
14864 dev_priv->display.crtc_enable(state, crtc);
14866 if (new_crtc_state->bigjoiner_slave)
14869 /* vblanks work again, re-enable pipe CRC. */
14870 intel_crtc_enable_pipe_crc(crtc);
14873 static void intel_update_crtc(struct intel_atomic_state *state,
14874 struct intel_crtc *crtc)
14876 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14877 const struct intel_crtc_state *old_crtc_state =
14878 intel_atomic_get_old_crtc_state(state, crtc);
14879 struct intel_crtc_state *new_crtc_state =
14880 intel_atomic_get_new_crtc_state(state, crtc);
14881 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
14884 if (new_crtc_state->preload_luts &&
14885 (new_crtc_state->uapi.color_mgmt_changed ||
14886 new_crtc_state->update_pipe))
14887 intel_color_load_luts(new_crtc_state);
14889 intel_pre_plane_update(state, crtc);
14891 if (new_crtc_state->update_pipe)
14892 intel_encoders_update_pipe(state, crtc);
14895 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
14896 intel_fbc_disable(crtc);
14898 intel_fbc_enable(state, crtc);
14900 /* Perform vblank evasion around commit operation */
14901 intel_pipe_update_start(new_crtc_state);
14903 commit_pipe_config(state, crtc);
14905 if (INTEL_GEN(dev_priv) >= 9)
14906 skl_update_planes_on_crtc(state, crtc);
14908 i9xx_update_planes_on_crtc(state, crtc);
14910 intel_pipe_update_end(new_crtc_state);
14913 * We usually enable FIFO underrun interrupts as part of the
14914 * CRTC enable sequence during modesets. But when we inherit a
14915 * valid pipe configuration from the BIOS we need to take care
14916 * of enabling them on the CRTC's first fastset.
14918 if (new_crtc_state->update_pipe && !modeset &&
14919 old_crtc_state->inherited)
14920 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14923 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
14924 struct intel_crtc_state *old_crtc_state,
14925 struct intel_crtc_state *new_crtc_state,
14926 struct intel_crtc *crtc)
14928 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14930 drm_WARN_ON(&dev_priv->drm, old_crtc_state->bigjoiner_slave);
14932 intel_crtc_disable_planes(state, crtc);
14935 * We still need special handling for disabling bigjoiner master
14936 * and slaves since for slave we do not have encoder or plls
14937 * so we dont need to disable those.
14939 if (old_crtc_state->bigjoiner) {
14940 intel_crtc_disable_planes(state,
14941 old_crtc_state->bigjoiner_linked_crtc);
14942 old_crtc_state->bigjoiner_linked_crtc->active = false;
14946 * We need to disable pipe CRC before disabling the pipe,
14947 * or we race against vblank off.
14949 intel_crtc_disable_pipe_crc(crtc);
14951 dev_priv->display.crtc_disable(state, crtc);
14952 crtc->active = false;
14953 intel_fbc_disable(crtc);
14954 intel_disable_shared_dpll(old_crtc_state);
14956 /* FIXME unify this for all platforms */
14957 if (!new_crtc_state->hw.active &&
14958 !HAS_GMCH(dev_priv) &&
14959 dev_priv->display.initial_watermarks)
14960 dev_priv->display.initial_watermarks(state, crtc);
14963 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
14965 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
14966 struct intel_crtc *crtc;
14970 /* Only disable port sync and MST slaves */
14971 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14972 new_crtc_state, i) {
14973 if (!intel_crtc_needs_modeset(new_crtc_state) || old_crtc_state->bigjoiner)
14976 if (!old_crtc_state->hw.active)
14979 /* In case of Transcoder port Sync master slave CRTCs can be
14980 * assigned in any order and we need to make sure that
14981 * slave CRTCs are disabled first and then master CRTC since
14982 * Slave vblanks are masked till Master Vblanks.
14984 if (!is_trans_port_sync_slave(old_crtc_state) &&
14985 !intel_dp_mst_is_slave_trans(old_crtc_state))
14988 intel_pre_plane_update(state, crtc);
14989 intel_old_crtc_state_disables(state, old_crtc_state,
14990 new_crtc_state, crtc);
14991 handled |= BIT(crtc->pipe);
14994 /* Disable everything else left on */
14995 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14996 new_crtc_state, i) {
14997 if (!intel_crtc_needs_modeset(new_crtc_state) ||
14998 (handled & BIT(crtc->pipe)) ||
14999 old_crtc_state->bigjoiner_slave)
15002 intel_pre_plane_update(state, crtc);
15003 if (old_crtc_state->bigjoiner) {
15004 struct intel_crtc *slave =
15005 old_crtc_state->bigjoiner_linked_crtc;
15007 intel_pre_plane_update(state, slave);
15010 if (old_crtc_state->hw.active)
15011 intel_old_crtc_state_disables(state, old_crtc_state,
15012 new_crtc_state, crtc);
15016 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
15018 struct intel_crtc_state *new_crtc_state;
15019 struct intel_crtc *crtc;
15022 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15023 if (!new_crtc_state->hw.active)
15026 intel_enable_crtc(state, crtc);
15027 intel_update_crtc(state, crtc);
15031 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
15033 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15034 struct intel_crtc *crtc;
15035 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
15036 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
15037 u8 update_pipes = 0, modeset_pipes = 0;
15040 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15041 enum pipe pipe = crtc->pipe;
15043 if (!new_crtc_state->hw.active)
15046 /* ignore allocations for crtc's that have been turned off. */
15047 if (!intel_crtc_needs_modeset(new_crtc_state)) {
15048 entries[pipe] = old_crtc_state->wm.skl.ddb;
15049 update_pipes |= BIT(pipe);
15051 modeset_pipes |= BIT(pipe);
15056 * Whenever the number of active pipes changes, we need to make sure we
15057 * update the pipes in the right order so that their ddb allocations
15058 * never overlap with each other between CRTC updates. Otherwise we'll
15059 * cause pipe underruns and other bad stuff.
15061 * So first lets enable all pipes that do not need a fullmodeset as
15062 * those don't have any external dependency.
15064 while (update_pipes) {
15065 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15066 new_crtc_state, i) {
15067 enum pipe pipe = crtc->pipe;
15069 if ((update_pipes & BIT(pipe)) == 0)
15072 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
15073 entries, I915_MAX_PIPES, pipe))
15076 entries[pipe] = new_crtc_state->wm.skl.ddb;
15077 update_pipes &= ~BIT(pipe);
15079 intel_update_crtc(state, crtc);
15082 * If this is an already active pipe, it's DDB changed,
15083 * and this isn't the last pipe that needs updating
15084 * then we need to wait for a vblank to pass for the
15085 * new ddb allocation to take effect.
15087 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
15088 &old_crtc_state->wm.skl.ddb) &&
15089 (update_pipes | modeset_pipes))
15090 intel_wait_for_vblank(dev_priv, pipe);
15094 update_pipes = modeset_pipes;
15097 * Enable all pipes that needs a modeset and do not depends on other
15100 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15101 enum pipe pipe = crtc->pipe;
15103 if ((modeset_pipes & BIT(pipe)) == 0)
15106 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
15107 is_trans_port_sync_master(new_crtc_state) ||
15108 (new_crtc_state->bigjoiner && !new_crtc_state->bigjoiner_slave))
15111 modeset_pipes &= ~BIT(pipe);
15113 intel_enable_crtc(state, crtc);
15117 * Then we enable all remaining pipes that depend on other
15118 * pipes: MST slaves and port sync masters, big joiner master
15120 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15121 enum pipe pipe = crtc->pipe;
15123 if ((modeset_pipes & BIT(pipe)) == 0)
15126 modeset_pipes &= ~BIT(pipe);
15128 intel_enable_crtc(state, crtc);
15132 * Finally we do the plane updates/etc. for all pipes that got enabled.
15134 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15135 enum pipe pipe = crtc->pipe;
15137 if ((update_pipes & BIT(pipe)) == 0)
15140 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
15141 entries, I915_MAX_PIPES, pipe));
15143 entries[pipe] = new_crtc_state->wm.skl.ddb;
15144 update_pipes &= ~BIT(pipe);
15146 intel_update_crtc(state, crtc);
15149 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
15150 drm_WARN_ON(&dev_priv->drm, update_pipes);
15153 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
15155 struct intel_atomic_state *state, *next;
15156 struct llist_node *freed;
15158 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
15159 llist_for_each_entry_safe(state, next, freed, freed)
15160 drm_atomic_state_put(&state->base);
15163 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
15165 struct drm_i915_private *dev_priv =
15166 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
15168 intel_atomic_helper_free_state(dev_priv);
15171 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
15173 struct wait_queue_entry wait_fence, wait_reset;
15174 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
15176 init_wait_entry(&wait_fence, 0);
15177 init_wait_entry(&wait_reset, 0);
15179 prepare_to_wait(&intel_state->commit_ready.wait,
15180 &wait_fence, TASK_UNINTERRUPTIBLE);
15181 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
15182 I915_RESET_MODESET),
15183 &wait_reset, TASK_UNINTERRUPTIBLE);
15186 if (i915_sw_fence_done(&intel_state->commit_ready) ||
15187 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
15192 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
15193 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
15194 I915_RESET_MODESET),
15198 static void intel_cleanup_dsbs(struct intel_atomic_state *state)
15200 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
15201 struct intel_crtc *crtc;
15204 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15206 intel_dsb_cleanup(old_crtc_state);
15209 static void intel_atomic_cleanup_work(struct work_struct *work)
15211 struct intel_atomic_state *state =
15212 container_of(work, struct intel_atomic_state, base.commit_work);
15213 struct drm_i915_private *i915 = to_i915(state->base.dev);
15215 intel_cleanup_dsbs(state);
15216 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
15217 drm_atomic_helper_commit_cleanup_done(&state->base);
15218 drm_atomic_state_put(&state->base);
15220 intel_atomic_helper_free_state(i915);
15223 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
15225 struct drm_device *dev = state->base.dev;
15226 struct drm_i915_private *dev_priv = to_i915(dev);
15227 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
15228 struct intel_crtc *crtc;
15229 u64 put_domains[I915_MAX_PIPES] = {};
15230 intel_wakeref_t wakeref = 0;
15233 intel_atomic_commit_fence_wait(state);
15235 drm_atomic_helper_wait_for_dependencies(&state->base);
15237 if (state->modeset)
15238 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
15240 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15241 new_crtc_state, i) {
15242 if (intel_crtc_needs_modeset(new_crtc_state) ||
15243 new_crtc_state->update_pipe) {
15245 put_domains[crtc->pipe] =
15246 modeset_get_crtc_power_domains(new_crtc_state);
15250 intel_commit_modeset_disables(state);
15252 /* FIXME: Eventually get rid of our crtc->config pointer */
15253 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15254 crtc->config = new_crtc_state;
15256 if (state->modeset) {
15257 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
15259 intel_set_cdclk_pre_plane_update(state);
15261 intel_modeset_verify_disabled(dev_priv, state);
15264 intel_sagv_pre_plane_update(state);
15266 /* Complete the events for pipes that have now been disabled */
15267 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15268 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
15270 /* Complete events for now disable pipes here. */
15271 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
15272 spin_lock_irq(&dev->event_lock);
15273 drm_crtc_send_vblank_event(&crtc->base,
15274 new_crtc_state->uapi.event);
15275 spin_unlock_irq(&dev->event_lock);
15277 new_crtc_state->uapi.event = NULL;
15281 if (state->modeset)
15282 intel_encoders_update_prepare(state);
15284 intel_dbuf_pre_plane_update(state);
15286 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15287 if (new_crtc_state->uapi.async_flip)
15288 skl_enable_flip_done(crtc);
15291 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
15292 dev_priv->display.commit_modeset_enables(state);
15294 if (state->modeset) {
15295 intel_encoders_update_complete(state);
15297 intel_set_cdclk_post_plane_update(state);
15300 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
15301 * already, but still need the state for the delayed optimization. To
15303 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
15304 * - schedule that vblank worker _before_ calling hw_done
15305 * - at the start of commit_tail, cancel it _synchrously
15306 * - switch over to the vblank wait helper in the core after that since
15307 * we don't need out special handling any more.
15309 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
15311 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15312 if (new_crtc_state->uapi.async_flip)
15313 skl_disable_flip_done(crtc);
15315 if (new_crtc_state->hw.active &&
15316 !intel_crtc_needs_modeset(new_crtc_state) &&
15317 !new_crtc_state->preload_luts &&
15318 (new_crtc_state->uapi.color_mgmt_changed ||
15319 new_crtc_state->update_pipe))
15320 intel_color_load_luts(new_crtc_state);
15324 * Now that the vblank has passed, we can go ahead and program the
15325 * optimal watermarks on platforms that need two-step watermark
15328 * TODO: Move this (and other cleanup) to an async worker eventually.
15330 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15331 new_crtc_state, i) {
15333 * Gen2 reports pipe underruns whenever all planes are disabled.
15334 * So re-enable underrun reporting after some planes get enabled.
15336 * We do this before .optimize_watermarks() so that we have a
15337 * chance of catching underruns with the intermediate watermarks
15338 * vs. the new plane configuration.
15340 if (IS_GEN(dev_priv, 2) && planes_enabling(old_crtc_state, new_crtc_state))
15341 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
15343 if (dev_priv->display.optimize_watermarks)
15344 dev_priv->display.optimize_watermarks(state, crtc);
15347 intel_dbuf_post_plane_update(state);
15349 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15350 intel_post_plane_update(state, crtc);
15352 modeset_put_crtc_power_domains(crtc, put_domains[crtc->pipe]);
15354 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
15357 * DSB cleanup is done in cleanup_work aligning with framebuffer
15358 * cleanup. So copy and reset the dsb structure to sync with
15359 * commit_done and later do dsb cleanup in cleanup_work.
15361 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
15364 /* Underruns don't always raise interrupts, so check manually */
15365 intel_check_cpu_fifo_underruns(dev_priv);
15366 intel_check_pch_fifo_underruns(dev_priv);
15368 if (state->modeset)
15369 intel_verify_planes(state);
15371 intel_sagv_post_plane_update(state);
15373 drm_atomic_helper_commit_hw_done(&state->base);
15375 if (state->modeset) {
15376 /* As one of the primary mmio accessors, KMS has a high
15377 * likelihood of triggering bugs in unclaimed access. After we
15378 * finish modesetting, see if an error has been flagged, and if
15379 * so enable debugging for the next modeset - and hope we catch
15382 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
15383 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
15385 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15388 * Defer the cleanup of the old state to a separate worker to not
15389 * impede the current task (userspace for blocking modesets) that
15390 * are executed inline. For out-of-line asynchronous modesets/flips,
15391 * deferring to a new worker seems overkill, but we would place a
15392 * schedule point (cond_resched()) here anyway to keep latencies
15395 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
15396 queue_work(system_highpri_wq, &state->base.commit_work);
15399 static void intel_atomic_commit_work(struct work_struct *work)
15401 struct intel_atomic_state *state =
15402 container_of(work, struct intel_atomic_state, base.commit_work);
15404 intel_atomic_commit_tail(state);
15407 static int __i915_sw_fence_call
15408 intel_atomic_commit_ready(struct i915_sw_fence *fence,
15409 enum i915_sw_fence_notify notify)
15411 struct intel_atomic_state *state =
15412 container_of(fence, struct intel_atomic_state, commit_ready);
15415 case FENCE_COMPLETE:
15416 /* we do blocking waits in the worker, nothing to do here */
15420 struct intel_atomic_helper *helper =
15421 &to_i915(state->base.dev)->atomic_helper;
15423 if (llist_add(&state->freed, &helper->free_list))
15424 schedule_work(&helper->free_work);
15429 return NOTIFY_DONE;
15432 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
15434 struct intel_plane_state *old_plane_state, *new_plane_state;
15435 struct intel_plane *plane;
15438 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
15439 new_plane_state, i)
15440 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
15441 to_intel_frontbuffer(new_plane_state->hw.fb),
15442 plane->frontbuffer_bit);
15445 static int intel_atomic_commit(struct drm_device *dev,
15446 struct drm_atomic_state *_state,
15449 struct intel_atomic_state *state = to_intel_atomic_state(_state);
15450 struct drm_i915_private *dev_priv = to_i915(dev);
15453 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
15455 drm_atomic_state_get(&state->base);
15456 i915_sw_fence_init(&state->commit_ready,
15457 intel_atomic_commit_ready);
15460 * The intel_legacy_cursor_update() fast path takes care
15461 * of avoiding the vblank waits for simple cursor
15462 * movement and flips. For cursor on/off and size changes,
15463 * we want to perform the vblank waits so that watermark
15464 * updates happen during the correct frames. Gen9+ have
15465 * double buffered watermarks and so shouldn't need this.
15467 * Unset state->legacy_cursor_update before the call to
15468 * drm_atomic_helper_setup_commit() because otherwise
15469 * drm_atomic_helper_wait_for_flip_done() is a noop and
15470 * we get FIFO underruns because we didn't wait
15473 * FIXME doing watermarks and fb cleanup from a vblank worker
15474 * (assuming we had any) would solve these problems.
15476 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
15477 struct intel_crtc_state *new_crtc_state;
15478 struct intel_crtc *crtc;
15481 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15482 if (new_crtc_state->wm.need_postvbl_update ||
15483 new_crtc_state->update_wm_post)
15484 state->base.legacy_cursor_update = false;
15487 ret = intel_atomic_prepare_commit(state);
15489 drm_dbg_atomic(&dev_priv->drm,
15490 "Preparing state failed with %i\n", ret);
15491 i915_sw_fence_commit(&state->commit_ready);
15492 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15496 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
15498 ret = drm_atomic_helper_swap_state(&state->base, true);
15500 intel_atomic_swap_global_state(state);
15503 struct intel_crtc_state *new_crtc_state;
15504 struct intel_crtc *crtc;
15507 i915_sw_fence_commit(&state->commit_ready);
15509 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15510 intel_dsb_cleanup(new_crtc_state);
15512 drm_atomic_helper_cleanup_planes(dev, &state->base);
15513 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15516 dev_priv->wm.distrust_bios_wm = false;
15517 intel_shared_dpll_swap_state(state);
15518 intel_atomic_track_fbs(state);
15520 drm_atomic_state_get(&state->base);
15521 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
15523 i915_sw_fence_commit(&state->commit_ready);
15524 if (nonblock && state->modeset) {
15525 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
15526 } else if (nonblock) {
15527 queue_work(dev_priv->flip_wq, &state->base.commit_work);
15529 if (state->modeset)
15530 flush_workqueue(dev_priv->modeset_wq);
15531 intel_atomic_commit_tail(state);
15537 struct wait_rps_boost {
15538 struct wait_queue_entry wait;
15540 struct drm_crtc *crtc;
15541 struct i915_request *request;
15544 static int do_rps_boost(struct wait_queue_entry *_wait,
15545 unsigned mode, int sync, void *key)
15547 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
15548 struct i915_request *rq = wait->request;
15551 * If we missed the vblank, but the request is already running it
15552 * is reasonable to assume that it will complete before the next
15553 * vblank without our intervention, so leave RPS alone.
15555 if (!i915_request_started(rq))
15556 intel_rps_boost(rq);
15557 i915_request_put(rq);
15559 drm_crtc_vblank_put(wait->crtc);
15561 list_del(&wait->wait.entry);
15566 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
15567 struct dma_fence *fence)
15569 struct wait_rps_boost *wait;
15571 if (!dma_fence_is_i915(fence))
15574 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
15577 if (drm_crtc_vblank_get(crtc))
15580 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
15582 drm_crtc_vblank_put(crtc);
15586 wait->request = to_request(dma_fence_get(fence));
15589 wait->wait.func = do_rps_boost;
15590 wait->wait.flags = 0;
15592 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
15595 int intel_plane_pin_fb(struct intel_plane_state *plane_state)
15597 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
15598 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
15599 struct drm_framebuffer *fb = plane_state->hw.fb;
15600 struct i915_vma *vma;
15602 if (plane->id == PLANE_CURSOR &&
15603 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
15604 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15605 const int align = intel_cursor_alignment(dev_priv);
15608 err = i915_gem_object_attach_phys(obj, align);
15613 vma = intel_pin_and_fence_fb_obj(fb,
15614 &plane_state->view,
15615 intel_plane_uses_fence(plane_state),
15616 &plane_state->flags);
15618 return PTR_ERR(vma);
15620 plane_state->vma = vma;
15625 void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
15627 struct i915_vma *vma;
15629 vma = fetch_and_zero(&old_plane_state->vma);
15631 intel_unpin_fb_vma(vma, old_plane_state->flags);
15634 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
15636 struct i915_sched_attr attr = {
15637 .priority = I915_USER_PRIORITY(I915_PRIORITY_DISPLAY),
15640 i915_gem_object_wait_priority(obj, 0, &attr);
15644 * intel_prepare_plane_fb - Prepare fb for usage on plane
15645 * @_plane: drm plane to prepare for
15646 * @_new_plane_state: the plane state being prepared
15648 * Prepares a framebuffer for usage on a display plane. Generally this
15649 * involves pinning the underlying object and updating the frontbuffer tracking
15650 * bits. Some older platforms need special physical address handling for
15653 * Returns 0 on success, negative error code on failure.
15656 intel_prepare_plane_fb(struct drm_plane *_plane,
15657 struct drm_plane_state *_new_plane_state)
15659 struct intel_plane *plane = to_intel_plane(_plane);
15660 struct intel_plane_state *new_plane_state =
15661 to_intel_plane_state(_new_plane_state);
15662 struct intel_atomic_state *state =
15663 to_intel_atomic_state(new_plane_state->uapi.state);
15664 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
15665 const struct intel_plane_state *old_plane_state =
15666 intel_atomic_get_old_plane_state(state, plane);
15667 struct drm_i915_gem_object *obj = intel_fb_obj(new_plane_state->hw.fb);
15668 struct drm_i915_gem_object *old_obj = intel_fb_obj(old_plane_state->hw.fb);
15672 const struct intel_crtc_state *crtc_state =
15673 intel_atomic_get_new_crtc_state(state,
15674 to_intel_crtc(old_plane_state->hw.crtc));
15676 /* Big Hammer, we also need to ensure that any pending
15677 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
15678 * current scanout is retired before unpinning the old
15679 * framebuffer. Note that we rely on userspace rendering
15680 * into the buffer attached to the pipe they are waiting
15681 * on. If not, userspace generates a GPU hang with IPEHR
15682 * point to the MI_WAIT_FOR_EVENT.
15684 * This should only fail upon a hung GPU, in which case we
15685 * can safely continue.
15687 if (intel_crtc_needs_modeset(crtc_state)) {
15688 ret = i915_sw_fence_await_reservation(&state->commit_ready,
15689 old_obj->base.resv, NULL,
15697 if (new_plane_state->uapi.fence) { /* explicit fencing */
15698 ret = i915_sw_fence_await_dma_fence(&state->commit_ready,
15699 new_plane_state->uapi.fence,
15700 i915_fence_timeout(dev_priv),
15709 ret = i915_gem_object_pin_pages(obj);
15713 ret = intel_plane_pin_fb(new_plane_state);
15715 i915_gem_object_unpin_pages(obj);
15719 fb_obj_bump_render_priority(obj);
15720 i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
15722 if (!new_plane_state->uapi.fence) { /* implicit fencing */
15723 struct dma_fence *fence;
15725 ret = i915_sw_fence_await_reservation(&state->commit_ready,
15726 obj->base.resv, NULL,
15728 i915_fence_timeout(dev_priv),
15733 fence = dma_resv_get_excl_rcu(obj->base.resv);
15735 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
15737 dma_fence_put(fence);
15740 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
15741 new_plane_state->uapi.fence);
15745 * We declare pageflips to be interactive and so merit a small bias
15746 * towards upclocking to deliver the frame on time. By only changing
15747 * the RPS thresholds to sample more regularly and aim for higher
15748 * clocks we can hopefully deliver low power workloads (like kodi)
15749 * that are not quite steady state without resorting to forcing
15750 * maximum clocks following a vblank miss (see do_rps_boost()).
15752 if (!state->rps_interactive) {
15753 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
15754 state->rps_interactive = true;
15760 intel_plane_unpin_fb(new_plane_state);
15766 * intel_cleanup_plane_fb - Cleans up an fb after plane use
15767 * @plane: drm plane to clean up for
15768 * @_old_plane_state: the state from the previous modeset
15770 * Cleans up a framebuffer that has just been removed from a plane.
15773 intel_cleanup_plane_fb(struct drm_plane *plane,
15774 struct drm_plane_state *_old_plane_state)
15776 struct intel_plane_state *old_plane_state =
15777 to_intel_plane_state(_old_plane_state);
15778 struct intel_atomic_state *state =
15779 to_intel_atomic_state(old_plane_state->uapi.state);
15780 struct drm_i915_private *dev_priv = to_i915(plane->dev);
15781 struct drm_i915_gem_object *obj = intel_fb_obj(old_plane_state->hw.fb);
15786 if (state->rps_interactive) {
15787 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
15788 state->rps_interactive = false;
15791 /* Should only be called after a successful intel_prepare_plane_fb()! */
15792 intel_plane_unpin_fb(old_plane_state);
15796 * intel_plane_destroy - destroy a plane
15797 * @plane: plane to destroy
15799 * Common destruction function for all types of planes (primary, cursor,
15802 void intel_plane_destroy(struct drm_plane *plane)
15804 drm_plane_cleanup(plane);
15805 kfree(to_intel_plane(plane));
15808 static int intel_crtc_late_register(struct drm_crtc *crtc)
15810 intel_crtc_debugfs_add(crtc);
15814 #define INTEL_CRTC_FUNCS \
15815 .set_config = drm_atomic_helper_set_config, \
15816 .destroy = intel_crtc_destroy, \
15817 .page_flip = drm_atomic_helper_page_flip, \
15818 .atomic_duplicate_state = intel_crtc_duplicate_state, \
15819 .atomic_destroy_state = intel_crtc_destroy_state, \
15820 .set_crc_source = intel_crtc_set_crc_source, \
15821 .verify_crc_source = intel_crtc_verify_crc_source, \
15822 .get_crc_sources = intel_crtc_get_crc_sources, \
15823 .late_register = intel_crtc_late_register
15825 static const struct drm_crtc_funcs bdw_crtc_funcs = {
15828 .get_vblank_counter = g4x_get_vblank_counter,
15829 .enable_vblank = bdw_enable_vblank,
15830 .disable_vblank = bdw_disable_vblank,
15831 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
15834 static const struct drm_crtc_funcs ilk_crtc_funcs = {
15837 .get_vblank_counter = g4x_get_vblank_counter,
15838 .enable_vblank = ilk_enable_vblank,
15839 .disable_vblank = ilk_disable_vblank,
15840 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
15843 static const struct drm_crtc_funcs g4x_crtc_funcs = {
15846 .get_vblank_counter = g4x_get_vblank_counter,
15847 .enable_vblank = i965_enable_vblank,
15848 .disable_vblank = i965_disable_vblank,
15849 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
15852 static const struct drm_crtc_funcs i965_crtc_funcs = {
15855 .get_vblank_counter = i915_get_vblank_counter,
15856 .enable_vblank = i965_enable_vblank,
15857 .disable_vblank = i965_disable_vblank,
15858 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
15861 static const struct drm_crtc_funcs i915gm_crtc_funcs = {
15864 .get_vblank_counter = i915_get_vblank_counter,
15865 .enable_vblank = i915gm_enable_vblank,
15866 .disable_vblank = i915gm_disable_vblank,
15867 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
15870 static const struct drm_crtc_funcs i915_crtc_funcs = {
15873 .get_vblank_counter = i915_get_vblank_counter,
15874 .enable_vblank = i8xx_enable_vblank,
15875 .disable_vblank = i8xx_disable_vblank,
15876 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
15879 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
15882 /* no hw vblank counter */
15883 .enable_vblank = i8xx_enable_vblank,
15884 .disable_vblank = i8xx_disable_vblank,
15885 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
15888 static struct intel_crtc *intel_crtc_alloc(void)
15890 struct intel_crtc_state *crtc_state;
15891 struct intel_crtc *crtc;
15893 crtc = kzalloc(sizeof(*crtc), GFP_KERNEL);
15895 return ERR_PTR(-ENOMEM);
15897 crtc_state = intel_crtc_state_alloc(crtc);
15900 return ERR_PTR(-ENOMEM);
15903 crtc->base.state = &crtc_state->uapi;
15904 crtc->config = crtc_state;
15909 static void intel_crtc_free(struct intel_crtc *crtc)
15911 intel_crtc_destroy_state(&crtc->base, crtc->base.state);
15915 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv)
15917 struct intel_plane *plane;
15919 for_each_intel_plane(&dev_priv->drm, plane) {
15920 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
15923 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
15927 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
15929 struct intel_plane *primary, *cursor;
15930 const struct drm_crtc_funcs *funcs;
15931 struct intel_crtc *crtc;
15934 crtc = intel_crtc_alloc();
15936 return PTR_ERR(crtc);
15939 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[pipe];
15941 primary = intel_primary_plane_create(dev_priv, pipe);
15942 if (IS_ERR(primary)) {
15943 ret = PTR_ERR(primary);
15946 crtc->plane_ids_mask |= BIT(primary->id);
15948 for_each_sprite(dev_priv, pipe, sprite) {
15949 struct intel_plane *plane;
15951 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
15952 if (IS_ERR(plane)) {
15953 ret = PTR_ERR(plane);
15956 crtc->plane_ids_mask |= BIT(plane->id);
15959 cursor = intel_cursor_plane_create(dev_priv, pipe);
15960 if (IS_ERR(cursor)) {
15961 ret = PTR_ERR(cursor);
15964 crtc->plane_ids_mask |= BIT(cursor->id);
15966 if (HAS_GMCH(dev_priv)) {
15967 if (IS_CHERRYVIEW(dev_priv) ||
15968 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
15969 funcs = &g4x_crtc_funcs;
15970 else if (IS_GEN(dev_priv, 4))
15971 funcs = &i965_crtc_funcs;
15972 else if (IS_I945GM(dev_priv) || IS_I915GM(dev_priv))
15973 funcs = &i915gm_crtc_funcs;
15974 else if (IS_GEN(dev_priv, 3))
15975 funcs = &i915_crtc_funcs;
15977 funcs = &i8xx_crtc_funcs;
15979 if (INTEL_GEN(dev_priv) >= 8)
15980 funcs = &bdw_crtc_funcs;
15982 funcs = &ilk_crtc_funcs;
15985 ret = drm_crtc_init_with_planes(&dev_priv->drm, &crtc->base,
15986 &primary->base, &cursor->base,
15987 funcs, "pipe %c", pipe_name(pipe));
15991 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
15992 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
15993 dev_priv->pipe_to_crtc_mapping[pipe] = crtc;
15995 if (INTEL_GEN(dev_priv) < 9) {
15996 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
15998 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
15999 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
16000 dev_priv->plane_to_crtc_mapping[i9xx_plane] = crtc;
16003 if (INTEL_GEN(dev_priv) >= 10)
16004 drm_crtc_create_scaling_filter_property(&crtc->base,
16005 BIT(DRM_SCALING_FILTER_DEFAULT) |
16006 BIT(DRM_SCALING_FILTER_NEAREST_NEIGHBOR));
16008 intel_color_init(crtc);
16010 intel_crtc_crc_init(crtc);
16012 drm_WARN_ON(&dev_priv->drm, drm_crtc_index(&crtc->base) != crtc->pipe);
16017 intel_crtc_free(crtc);
16022 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
16023 struct drm_file *file)
16025 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
16026 struct drm_crtc *drmmode_crtc;
16027 struct intel_crtc *crtc;
16029 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
16033 crtc = to_intel_crtc(drmmode_crtc);
16034 pipe_from_crtc_id->pipe = crtc->pipe;
16039 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
16041 struct drm_device *dev = encoder->base.dev;
16042 struct intel_encoder *source_encoder;
16043 u32 possible_clones = 0;
16045 for_each_intel_encoder(dev, source_encoder) {
16046 if (encoders_cloneable(encoder, source_encoder))
16047 possible_clones |= drm_encoder_mask(&source_encoder->base);
16050 return possible_clones;
16053 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
16055 struct drm_device *dev = encoder->base.dev;
16056 struct intel_crtc *crtc;
16057 u32 possible_crtcs = 0;
16059 for_each_intel_crtc(dev, crtc) {
16060 if (encoder->pipe_mask & BIT(crtc->pipe))
16061 possible_crtcs |= drm_crtc_mask(&crtc->base);
16064 return possible_crtcs;
16067 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
16069 if (!IS_MOBILE(dev_priv))
16072 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
16075 if (IS_GEN(dev_priv, 5) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
16081 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
16083 if (INTEL_GEN(dev_priv) >= 9)
16086 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
16089 if (HAS_PCH_LPT_H(dev_priv) &&
16090 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
16093 /* DDI E can't be used if DDI A requires 4 lanes */
16094 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
16097 if (!dev_priv->vbt.int_crt_support)
16103 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
16108 if (HAS_DDI(dev_priv))
16111 * This w/a is needed at least on CPT/PPT, but to be sure apply it
16112 * everywhere where registers can be write protected.
16114 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16119 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
16120 u32 val = intel_de_read(dev_priv, PP_CONTROL(pps_idx));
16122 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
16123 intel_de_write(dev_priv, PP_CONTROL(pps_idx), val);
16127 static void intel_pps_init(struct drm_i915_private *dev_priv)
16129 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
16130 dev_priv->pps_mmio_base = PCH_PPS_BASE;
16131 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16132 dev_priv->pps_mmio_base = VLV_PPS_BASE;
16134 dev_priv->pps_mmio_base = PPS_BASE;
16136 intel_pps_unlock_regs_wa(dev_priv);
16139 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
16141 struct intel_encoder *encoder;
16142 bool dpd_is_edp = false;
16144 intel_pps_init(dev_priv);
16146 if (!HAS_DISPLAY(dev_priv))
16149 if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) {
16150 intel_ddi_init(dev_priv, PORT_A);
16151 intel_ddi_init(dev_priv, PORT_B);
16152 intel_ddi_init(dev_priv, PORT_TC1);
16153 intel_ddi_init(dev_priv, PORT_TC2);
16154 } else if (INTEL_GEN(dev_priv) >= 12) {
16155 intel_ddi_init(dev_priv, PORT_A);
16156 intel_ddi_init(dev_priv, PORT_B);
16157 intel_ddi_init(dev_priv, PORT_TC1);
16158 intel_ddi_init(dev_priv, PORT_TC2);
16159 intel_ddi_init(dev_priv, PORT_TC3);
16160 intel_ddi_init(dev_priv, PORT_TC4);
16161 intel_ddi_init(dev_priv, PORT_TC5);
16162 intel_ddi_init(dev_priv, PORT_TC6);
16163 icl_dsi_init(dev_priv);
16164 } else if (IS_JSL_EHL(dev_priv)) {
16165 intel_ddi_init(dev_priv, PORT_A);
16166 intel_ddi_init(dev_priv, PORT_B);
16167 intel_ddi_init(dev_priv, PORT_C);
16168 intel_ddi_init(dev_priv, PORT_D);
16169 icl_dsi_init(dev_priv);
16170 } else if (IS_GEN(dev_priv, 11)) {
16171 intel_ddi_init(dev_priv, PORT_A);
16172 intel_ddi_init(dev_priv, PORT_B);
16173 intel_ddi_init(dev_priv, PORT_C);
16174 intel_ddi_init(dev_priv, PORT_D);
16175 intel_ddi_init(dev_priv, PORT_E);
16177 * On some ICL SKUs port F is not present. No strap bits for
16178 * this, so rely on VBT.
16179 * Work around broken VBTs on SKUs known to have no port F.
16181 if (IS_ICL_WITH_PORT_F(dev_priv) &&
16182 intel_bios_is_port_present(dev_priv, PORT_F))
16183 intel_ddi_init(dev_priv, PORT_F);
16185 icl_dsi_init(dev_priv);
16186 } else if (IS_GEN9_LP(dev_priv)) {
16188 * FIXME: Broxton doesn't support port detection via the
16189 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
16190 * detect the ports.
16192 intel_ddi_init(dev_priv, PORT_A);
16193 intel_ddi_init(dev_priv, PORT_B);
16194 intel_ddi_init(dev_priv, PORT_C);
16196 vlv_dsi_init(dev_priv);
16197 } else if (HAS_DDI(dev_priv)) {
16200 if (intel_ddi_crt_present(dev_priv))
16201 intel_crt_init(dev_priv);
16204 * Haswell uses DDI functions to detect digital outputs.
16205 * On SKL pre-D0 the strap isn't connected, so we assume
16208 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
16209 /* WaIgnoreDDIAStrap: skl */
16210 if (found || IS_GEN9_BC(dev_priv))
16211 intel_ddi_init(dev_priv, PORT_A);
16213 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
16215 found = intel_de_read(dev_priv, SFUSE_STRAP);
16217 if (found & SFUSE_STRAP_DDIB_DETECTED)
16218 intel_ddi_init(dev_priv, PORT_B);
16219 if (found & SFUSE_STRAP_DDIC_DETECTED)
16220 intel_ddi_init(dev_priv, PORT_C);
16221 if (found & SFUSE_STRAP_DDID_DETECTED)
16222 intel_ddi_init(dev_priv, PORT_D);
16223 if (found & SFUSE_STRAP_DDIF_DETECTED)
16224 intel_ddi_init(dev_priv, PORT_F);
16226 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
16228 if (IS_GEN9_BC(dev_priv) &&
16229 intel_bios_is_port_present(dev_priv, PORT_E))
16230 intel_ddi_init(dev_priv, PORT_E);
16232 } else if (HAS_PCH_SPLIT(dev_priv)) {
16236 * intel_edp_init_connector() depends on this completing first,
16237 * to prevent the registration of both eDP and LVDS and the
16238 * incorrect sharing of the PPS.
16240 intel_lvds_init(dev_priv);
16241 intel_crt_init(dev_priv);
16243 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
16245 if (ilk_has_edp_a(dev_priv))
16246 intel_dp_init(dev_priv, DP_A, PORT_A);
16248 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
16249 /* PCH SDVOB multiplex with HDMIB */
16250 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
16252 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
16253 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
16254 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
16257 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
16258 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
16260 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
16261 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
16263 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
16264 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
16266 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
16267 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
16268 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16269 bool has_edp, has_port;
16271 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
16272 intel_crt_init(dev_priv);
16275 * The DP_DETECTED bit is the latched state of the DDC
16276 * SDA pin at boot. However since eDP doesn't require DDC
16277 * (no way to plug in a DP->HDMI dongle) the DDC pins for
16278 * eDP ports may have been muxed to an alternate function.
16279 * Thus we can't rely on the DP_DETECTED bit alone to detect
16280 * eDP ports. Consult the VBT as well as DP_DETECTED to
16281 * detect eDP ports.
16283 * Sadly the straps seem to be missing sometimes even for HDMI
16284 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
16285 * and VBT for the presence of the port. Additionally we can't
16286 * trust the port type the VBT declares as we've seen at least
16287 * HDMI ports that the VBT claim are DP or eDP.
16289 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
16290 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
16291 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
16292 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
16293 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
16294 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
16296 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
16297 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
16298 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
16299 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
16300 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
16301 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
16303 if (IS_CHERRYVIEW(dev_priv)) {
16305 * eDP not supported on port D,
16306 * so no need to worry about it
16308 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
16309 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
16310 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
16311 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
16312 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
16315 vlv_dsi_init(dev_priv);
16316 } else if (IS_PINEVIEW(dev_priv)) {
16317 intel_lvds_init(dev_priv);
16318 intel_crt_init(dev_priv);
16319 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
16320 bool found = false;
16322 if (IS_MOBILE(dev_priv))
16323 intel_lvds_init(dev_priv);
16325 intel_crt_init(dev_priv);
16327 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
16328 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
16329 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
16330 if (!found && IS_G4X(dev_priv)) {
16331 drm_dbg_kms(&dev_priv->drm,
16332 "probing HDMI on SDVOB\n");
16333 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
16336 if (!found && IS_G4X(dev_priv))
16337 intel_dp_init(dev_priv, DP_B, PORT_B);
16340 /* Before G4X SDVOC doesn't have its own detect register */
16342 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
16343 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
16344 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
16347 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
16349 if (IS_G4X(dev_priv)) {
16350 drm_dbg_kms(&dev_priv->drm,
16351 "probing HDMI on SDVOC\n");
16352 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
16354 if (IS_G4X(dev_priv))
16355 intel_dp_init(dev_priv, DP_C, PORT_C);
16358 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
16359 intel_dp_init(dev_priv, DP_D, PORT_D);
16361 if (SUPPORTS_TV(dev_priv))
16362 intel_tv_init(dev_priv);
16363 } else if (IS_GEN(dev_priv, 2)) {
16364 if (IS_I85X(dev_priv))
16365 intel_lvds_init(dev_priv);
16367 intel_crt_init(dev_priv);
16368 intel_dvo_init(dev_priv);
16371 intel_psr_init(dev_priv);
16373 for_each_intel_encoder(&dev_priv->drm, encoder) {
16374 encoder->base.possible_crtcs =
16375 intel_encoder_possible_crtcs(encoder);
16376 encoder->base.possible_clones =
16377 intel_encoder_possible_clones(encoder);
16380 intel_init_pch_refclk(dev_priv);
16382 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
16385 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
16387 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
16389 drm_framebuffer_cleanup(fb);
16390 intel_frontbuffer_put(intel_fb->frontbuffer);
16395 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
16396 struct drm_file *file,
16397 unsigned int *handle)
16399 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16400 struct drm_i915_private *i915 = to_i915(obj->base.dev);
16402 if (obj->userptr.mm) {
16403 drm_dbg(&i915->drm,
16404 "attempting to use a userptr for a framebuffer, denied\n");
16408 return drm_gem_handle_create(file, &obj->base, handle);
16411 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
16412 struct drm_file *file,
16413 unsigned flags, unsigned color,
16414 struct drm_clip_rect *clips,
16415 unsigned num_clips)
16417 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16419 i915_gem_object_flush_if_display(obj);
16420 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
16425 static const struct drm_framebuffer_funcs intel_fb_funcs = {
16426 .destroy = intel_user_framebuffer_destroy,
16427 .create_handle = intel_user_framebuffer_create_handle,
16428 .dirty = intel_user_framebuffer_dirty,
16431 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
16432 struct drm_i915_gem_object *obj,
16433 struct drm_mode_fb_cmd2 *mode_cmd)
16435 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
16436 struct drm_framebuffer *fb = &intel_fb->base;
16438 unsigned int tiling, stride;
16442 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
16443 if (!intel_fb->frontbuffer)
16446 i915_gem_object_lock(obj, NULL);
16447 tiling = i915_gem_object_get_tiling(obj);
16448 stride = i915_gem_object_get_stride(obj);
16449 i915_gem_object_unlock(obj);
16451 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
16453 * If there's a fence, enforce that
16454 * the fb modifier and tiling mode match.
16456 if (tiling != I915_TILING_NONE &&
16457 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
16458 drm_dbg_kms(&dev_priv->drm,
16459 "tiling_mode doesn't match fb modifier\n");
16463 if (tiling == I915_TILING_X) {
16464 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
16465 } else if (tiling == I915_TILING_Y) {
16466 drm_dbg_kms(&dev_priv->drm,
16467 "No Y tiling for legacy addfb\n");
16472 if (!drm_any_plane_has_format(&dev_priv->drm,
16473 mode_cmd->pixel_format,
16474 mode_cmd->modifier[0])) {
16475 struct drm_format_name_buf format_name;
16477 drm_dbg_kms(&dev_priv->drm,
16478 "unsupported pixel format %s / modifier 0x%llx\n",
16479 drm_get_format_name(mode_cmd->pixel_format,
16481 mode_cmd->modifier[0]);
16486 * gen2/3 display engine uses the fence if present,
16487 * so the tiling mode must match the fb modifier exactly.
16489 if (INTEL_GEN(dev_priv) < 4 &&
16490 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
16491 drm_dbg_kms(&dev_priv->drm,
16492 "tiling_mode must match fb modifier exactly on gen2/3\n");
16496 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
16497 mode_cmd->modifier[0]);
16498 if (mode_cmd->pitches[0] > max_stride) {
16499 drm_dbg_kms(&dev_priv->drm,
16500 "%s pitch (%u) must be at most %d\n",
16501 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
16502 "tiled" : "linear",
16503 mode_cmd->pitches[0], max_stride);
16508 * If there's a fence, enforce that
16509 * the fb pitch and fence stride match.
16511 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
16512 drm_dbg_kms(&dev_priv->drm,
16513 "pitch (%d) must match tiling stride (%d)\n",
16514 mode_cmd->pitches[0], stride);
16518 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
16519 if (mode_cmd->offsets[0] != 0) {
16520 drm_dbg_kms(&dev_priv->drm,
16521 "plane 0 offset (0x%08x) must be 0\n",
16522 mode_cmd->offsets[0]);
16526 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
16528 for (i = 0; i < fb->format->num_planes; i++) {
16529 u32 stride_alignment;
16531 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
16532 drm_dbg_kms(&dev_priv->drm, "bad plane %d handle\n",
16537 stride_alignment = intel_fb_stride_alignment(fb, i);
16538 if (fb->pitches[i] & (stride_alignment - 1)) {
16539 drm_dbg_kms(&dev_priv->drm,
16540 "plane %d pitch (%d) must be at least %u byte aligned\n",
16541 i, fb->pitches[i], stride_alignment);
16545 if (is_gen12_ccs_plane(fb, i)) {
16546 int ccs_aux_stride = gen12_ccs_aux_stride(fb, i);
16548 if (fb->pitches[i] != ccs_aux_stride) {
16549 drm_dbg_kms(&dev_priv->drm,
16550 "ccs aux plane %d pitch (%d) must be %d\n",
16552 fb->pitches[i], ccs_aux_stride);
16557 fb->obj[i] = &obj->base;
16560 ret = intel_fill_fb_info(dev_priv, fb);
16564 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
16566 drm_err(&dev_priv->drm, "framebuffer init failed %d\n", ret);
16573 intel_frontbuffer_put(intel_fb->frontbuffer);
16577 static struct drm_framebuffer *
16578 intel_user_framebuffer_create(struct drm_device *dev,
16579 struct drm_file *filp,
16580 const struct drm_mode_fb_cmd2 *user_mode_cmd)
16582 struct drm_framebuffer *fb;
16583 struct drm_i915_gem_object *obj;
16584 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
16586 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
16588 return ERR_PTR(-ENOENT);
16590 fb = intel_framebuffer_create(obj, &mode_cmd);
16591 i915_gem_object_put(obj);
16596 static enum drm_mode_status
16597 intel_mode_valid(struct drm_device *dev,
16598 const struct drm_display_mode *mode)
16600 struct drm_i915_private *dev_priv = to_i915(dev);
16601 int hdisplay_max, htotal_max;
16602 int vdisplay_max, vtotal_max;
16605 * Can't reject DBLSCAN here because Xorg ddxen can add piles
16606 * of DBLSCAN modes to the output's mode list when they detect
16607 * the scaling mode property on the connector. And they don't
16608 * ask the kernel to validate those modes in any way until
16609 * modeset time at which point the client gets a protocol error.
16610 * So in order to not upset those clients we silently ignore the
16611 * DBLSCAN flag on such connectors. For other connectors we will
16612 * reject modes with the DBLSCAN flag in encoder->compute_config().
16613 * And we always reject DBLSCAN modes in connector->mode_valid()
16614 * as we never want such modes on the connector's mode list.
16617 if (mode->vscan > 1)
16618 return MODE_NO_VSCAN;
16620 if (mode->flags & DRM_MODE_FLAG_HSKEW)
16621 return MODE_H_ILLEGAL;
16623 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
16624 DRM_MODE_FLAG_NCSYNC |
16625 DRM_MODE_FLAG_PCSYNC))
16628 if (mode->flags & (DRM_MODE_FLAG_BCAST |
16629 DRM_MODE_FLAG_PIXMUX |
16630 DRM_MODE_FLAG_CLKDIV2))
16633 /* Transcoder timing limits */
16634 if (INTEL_GEN(dev_priv) >= 11) {
16635 hdisplay_max = 16384;
16636 vdisplay_max = 8192;
16637 htotal_max = 16384;
16639 } else if (INTEL_GEN(dev_priv) >= 9 ||
16640 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
16641 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
16642 vdisplay_max = 4096;
16645 } else if (INTEL_GEN(dev_priv) >= 3) {
16646 hdisplay_max = 4096;
16647 vdisplay_max = 4096;
16651 hdisplay_max = 2048;
16652 vdisplay_max = 2048;
16657 if (mode->hdisplay > hdisplay_max ||
16658 mode->hsync_start > htotal_max ||
16659 mode->hsync_end > htotal_max ||
16660 mode->htotal > htotal_max)
16661 return MODE_H_ILLEGAL;
16663 if (mode->vdisplay > vdisplay_max ||
16664 mode->vsync_start > vtotal_max ||
16665 mode->vsync_end > vtotal_max ||
16666 mode->vtotal > vtotal_max)
16667 return MODE_V_ILLEGAL;
16669 if (INTEL_GEN(dev_priv) >= 5) {
16670 if (mode->hdisplay < 64 ||
16671 mode->htotal - mode->hdisplay < 32)
16672 return MODE_H_ILLEGAL;
16674 if (mode->vtotal - mode->vdisplay < 5)
16675 return MODE_V_ILLEGAL;
16677 if (mode->htotal - mode->hdisplay < 32)
16678 return MODE_H_ILLEGAL;
16680 if (mode->vtotal - mode->vdisplay < 3)
16681 return MODE_V_ILLEGAL;
16687 enum drm_mode_status
16688 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
16689 const struct drm_display_mode *mode,
16692 int plane_width_max, plane_height_max;
16695 * intel_mode_valid() should be
16696 * sufficient on older platforms.
16698 if (INTEL_GEN(dev_priv) < 9)
16702 * Most people will probably want a fullscreen
16703 * plane so let's not advertize modes that are
16704 * too big for that.
16706 if (INTEL_GEN(dev_priv) >= 11) {
16707 plane_width_max = 5120 << bigjoiner;
16708 plane_height_max = 4320;
16710 plane_width_max = 5120;
16711 plane_height_max = 4096;
16714 if (mode->hdisplay > plane_width_max)
16715 return MODE_H_ILLEGAL;
16717 if (mode->vdisplay > plane_height_max)
16718 return MODE_V_ILLEGAL;
16723 static const struct drm_mode_config_funcs intel_mode_funcs = {
16724 .fb_create = intel_user_framebuffer_create,
16725 .get_format_info = intel_get_format_info,
16726 .output_poll_changed = intel_fbdev_output_poll_changed,
16727 .mode_valid = intel_mode_valid,
16728 .atomic_check = intel_atomic_check,
16729 .atomic_commit = intel_atomic_commit,
16730 .atomic_state_alloc = intel_atomic_state_alloc,
16731 .atomic_state_clear = intel_atomic_state_clear,
16732 .atomic_state_free = intel_atomic_state_free,
16736 * intel_init_display_hooks - initialize the display modesetting hooks
16737 * @dev_priv: device private
16739 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
16741 intel_init_cdclk_hooks(dev_priv);
16743 if (INTEL_GEN(dev_priv) >= 9) {
16744 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
16745 dev_priv->display.get_initial_plane_config =
16746 skl_get_initial_plane_config;
16747 dev_priv->display.crtc_compute_clock = hsw_crtc_compute_clock;
16748 dev_priv->display.crtc_enable = hsw_crtc_enable;
16749 dev_priv->display.crtc_disable = hsw_crtc_disable;
16750 } else if (HAS_DDI(dev_priv)) {
16751 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
16752 dev_priv->display.get_initial_plane_config =
16753 i9xx_get_initial_plane_config;
16754 dev_priv->display.crtc_compute_clock =
16755 hsw_crtc_compute_clock;
16756 dev_priv->display.crtc_enable = hsw_crtc_enable;
16757 dev_priv->display.crtc_disable = hsw_crtc_disable;
16758 } else if (HAS_PCH_SPLIT(dev_priv)) {
16759 dev_priv->display.get_pipe_config = ilk_get_pipe_config;
16760 dev_priv->display.get_initial_plane_config =
16761 i9xx_get_initial_plane_config;
16762 dev_priv->display.crtc_compute_clock =
16763 ilk_crtc_compute_clock;
16764 dev_priv->display.crtc_enable = ilk_crtc_enable;
16765 dev_priv->display.crtc_disable = ilk_crtc_disable;
16766 } else if (IS_CHERRYVIEW(dev_priv)) {
16767 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16768 dev_priv->display.get_initial_plane_config =
16769 i9xx_get_initial_plane_config;
16770 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
16771 dev_priv->display.crtc_enable = valleyview_crtc_enable;
16772 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16773 } else if (IS_VALLEYVIEW(dev_priv)) {
16774 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16775 dev_priv->display.get_initial_plane_config =
16776 i9xx_get_initial_plane_config;
16777 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
16778 dev_priv->display.crtc_enable = valleyview_crtc_enable;
16779 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16780 } else if (IS_G4X(dev_priv)) {
16781 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16782 dev_priv->display.get_initial_plane_config =
16783 i9xx_get_initial_plane_config;
16784 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
16785 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16786 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16787 } else if (IS_PINEVIEW(dev_priv)) {
16788 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16789 dev_priv->display.get_initial_plane_config =
16790 i9xx_get_initial_plane_config;
16791 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
16792 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16793 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16794 } else if (!IS_GEN(dev_priv, 2)) {
16795 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16796 dev_priv->display.get_initial_plane_config =
16797 i9xx_get_initial_plane_config;
16798 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
16799 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16800 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16802 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16803 dev_priv->display.get_initial_plane_config =
16804 i9xx_get_initial_plane_config;
16805 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
16806 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16807 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16810 if (IS_GEN(dev_priv, 5)) {
16811 dev_priv->display.fdi_link_train = ilk_fdi_link_train;
16812 } else if (IS_GEN(dev_priv, 6)) {
16813 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
16814 } else if (IS_IVYBRIDGE(dev_priv)) {
16815 /* FIXME: detect B0+ stepping and use auto training */
16816 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
16819 if (INTEL_GEN(dev_priv) >= 9)
16820 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
16822 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
16826 void intel_modeset_init_hw(struct drm_i915_private *i915)
16828 struct intel_cdclk_state *cdclk_state =
16829 to_intel_cdclk_state(i915->cdclk.obj.state);
16830 struct intel_dbuf_state *dbuf_state =
16831 to_intel_dbuf_state(i915->dbuf.obj.state);
16833 intel_update_cdclk(i915);
16834 intel_dump_cdclk_config(&i915->cdclk.hw, "Current CDCLK");
16835 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw;
16837 dbuf_state->enabled_slices = i915->dbuf.enabled_slices;
16840 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state)
16842 struct drm_plane *plane;
16843 struct intel_crtc *crtc;
16845 for_each_intel_crtc(state->dev, crtc) {
16846 struct intel_crtc_state *crtc_state;
16848 crtc_state = intel_atomic_get_crtc_state(state, crtc);
16849 if (IS_ERR(crtc_state))
16850 return PTR_ERR(crtc_state);
16852 if (crtc_state->hw.active) {
16854 * Preserve the inherited flag to avoid
16855 * taking the full modeset path.
16857 crtc_state->inherited = true;
16861 drm_for_each_plane(plane, state->dev) {
16862 struct drm_plane_state *plane_state;
16864 plane_state = drm_atomic_get_plane_state(state, plane);
16865 if (IS_ERR(plane_state))
16866 return PTR_ERR(plane_state);
16873 * Calculate what we think the watermarks should be for the state we've read
16874 * out of the hardware and then immediately program those watermarks so that
16875 * we ensure the hardware settings match our internal state.
16877 * We can calculate what we think WM's should be by creating a duplicate of the
16878 * current state (which was constructed during hardware readout) and running it
16879 * through the atomic check code to calculate new watermark values in the
16882 static void sanitize_watermarks(struct drm_i915_private *dev_priv)
16884 struct drm_atomic_state *state;
16885 struct intel_atomic_state *intel_state;
16886 struct intel_crtc *crtc;
16887 struct intel_crtc_state *crtc_state;
16888 struct drm_modeset_acquire_ctx ctx;
16892 /* Only supported on platforms that use atomic watermark design */
16893 if (!dev_priv->display.optimize_watermarks)
16896 state = drm_atomic_state_alloc(&dev_priv->drm);
16897 if (drm_WARN_ON(&dev_priv->drm, !state))
16900 intel_state = to_intel_atomic_state(state);
16902 drm_modeset_acquire_init(&ctx, 0);
16905 state->acquire_ctx = &ctx;
16908 * Hardware readout is the only time we don't want to calculate
16909 * intermediate watermarks (since we don't trust the current
16912 if (!HAS_GMCH(dev_priv))
16913 intel_state->skip_intermediate_wm = true;
16915 ret = sanitize_watermarks_add_affected(state);
16919 ret = intel_atomic_check(&dev_priv->drm, state);
16923 /* Write calculated watermark values back */
16924 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
16925 crtc_state->wm.need_postvbl_update = true;
16926 dev_priv->display.optimize_watermarks(intel_state, crtc);
16928 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
16932 if (ret == -EDEADLK) {
16933 drm_atomic_state_clear(state);
16934 drm_modeset_backoff(&ctx);
16939 * If we fail here, it means that the hardware appears to be
16940 * programmed in a way that shouldn't be possible, given our
16941 * understanding of watermark requirements. This might mean a
16942 * mistake in the hardware readout code or a mistake in the
16943 * watermark calculations for a given platform. Raise a WARN
16944 * so that this is noticeable.
16946 * If this actually happens, we'll have to just leave the
16947 * BIOS-programmed watermarks untouched and hope for the best.
16949 drm_WARN(&dev_priv->drm, ret,
16950 "Could not determine valid watermarks for inherited state\n");
16952 drm_atomic_state_put(state);
16954 drm_modeset_drop_locks(&ctx);
16955 drm_modeset_acquire_fini(&ctx);
16958 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
16960 if (IS_GEN(dev_priv, 5)) {
16962 intel_de_read(dev_priv, FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
16964 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
16965 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
16966 dev_priv->fdi_pll_freq = 270000;
16971 drm_dbg(&dev_priv->drm, "FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
16974 static int intel_initial_commit(struct drm_device *dev)
16976 struct drm_atomic_state *state = NULL;
16977 struct drm_modeset_acquire_ctx ctx;
16978 struct intel_crtc *crtc;
16981 state = drm_atomic_state_alloc(dev);
16985 drm_modeset_acquire_init(&ctx, 0);
16988 state->acquire_ctx = &ctx;
16990 for_each_intel_crtc(dev, crtc) {
16991 struct intel_crtc_state *crtc_state =
16992 intel_atomic_get_crtc_state(state, crtc);
16994 if (IS_ERR(crtc_state)) {
16995 ret = PTR_ERR(crtc_state);
16999 if (crtc_state->hw.active) {
17000 struct intel_encoder *encoder;
17003 * We've not yet detected sink capabilities
17004 * (audio,infoframes,etc.) and thus we don't want to
17005 * force a full state recomputation yet. We want that to
17006 * happen only for the first real commit from userspace.
17007 * So preserve the inherited flag for the time being.
17009 crtc_state->inherited = true;
17011 ret = drm_atomic_add_affected_planes(state, &crtc->base);
17016 * FIXME hack to force a LUT update to avoid the
17017 * plane update forcing the pipe gamma on without
17018 * having a proper LUT loaded. Remove once we
17019 * have readout for pipe gamma enable.
17021 crtc_state->uapi.color_mgmt_changed = true;
17023 for_each_intel_encoder_mask(dev, encoder,
17024 crtc_state->uapi.encoder_mask) {
17025 if (encoder->initial_fastset_check &&
17026 !encoder->initial_fastset_check(encoder, crtc_state)) {
17027 ret = drm_atomic_add_affected_connectors(state,
17036 ret = drm_atomic_commit(state);
17039 if (ret == -EDEADLK) {
17040 drm_atomic_state_clear(state);
17041 drm_modeset_backoff(&ctx);
17045 drm_atomic_state_put(state);
17047 drm_modeset_drop_locks(&ctx);
17048 drm_modeset_acquire_fini(&ctx);
17053 static void intel_mode_config_init(struct drm_i915_private *i915)
17055 struct drm_mode_config *mode_config = &i915->drm.mode_config;
17057 drm_mode_config_init(&i915->drm);
17058 INIT_LIST_HEAD(&i915->global_obj_list);
17060 mode_config->min_width = 0;
17061 mode_config->min_height = 0;
17063 mode_config->preferred_depth = 24;
17064 mode_config->prefer_shadow = 1;
17066 mode_config->allow_fb_modifiers = true;
17068 mode_config->funcs = &intel_mode_funcs;
17070 if (INTEL_GEN(i915) >= 9)
17071 mode_config->async_page_flip = true;
17074 * Maximum framebuffer dimensions, chosen to match
17075 * the maximum render engine surface size on gen4+.
17077 if (INTEL_GEN(i915) >= 7) {
17078 mode_config->max_width = 16384;
17079 mode_config->max_height = 16384;
17080 } else if (INTEL_GEN(i915) >= 4) {
17081 mode_config->max_width = 8192;
17082 mode_config->max_height = 8192;
17083 } else if (IS_GEN(i915, 3)) {
17084 mode_config->max_width = 4096;
17085 mode_config->max_height = 4096;
17087 mode_config->max_width = 2048;
17088 mode_config->max_height = 2048;
17091 if (IS_I845G(i915) || IS_I865G(i915)) {
17092 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
17093 mode_config->cursor_height = 1023;
17094 } else if (IS_I830(i915) || IS_I85X(i915) ||
17095 IS_I915G(i915) || IS_I915GM(i915)) {
17096 mode_config->cursor_width = 64;
17097 mode_config->cursor_height = 64;
17099 mode_config->cursor_width = 256;
17100 mode_config->cursor_height = 256;
17104 static void intel_mode_config_cleanup(struct drm_i915_private *i915)
17106 intel_atomic_global_obj_cleanup(i915);
17107 drm_mode_config_cleanup(&i915->drm);
17110 static void plane_config_fini(struct intel_initial_plane_config *plane_config)
17112 if (plane_config->fb) {
17113 struct drm_framebuffer *fb = &plane_config->fb->base;
17115 /* We may only have the stub and not a full framebuffer */
17116 if (drm_framebuffer_read_refcount(fb))
17117 drm_framebuffer_put(fb);
17122 if (plane_config->vma)
17123 i915_vma_put(plane_config->vma);
17126 /* part #1: call before irq install */
17127 int intel_modeset_init_noirq(struct drm_i915_private *i915)
17131 if (i915_inject_probe_failure(i915))
17134 if (HAS_DISPLAY(i915)) {
17135 ret = drm_vblank_init(&i915->drm,
17136 INTEL_NUM_PIPES(i915));
17141 intel_bios_init(i915);
17143 ret = intel_vga_register(i915);
17147 /* FIXME: completely on the wrong abstraction layer */
17148 intel_power_domains_init_hw(i915, false);
17150 intel_csr_ucode_init(i915);
17152 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
17153 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
17154 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
17156 intel_mode_config_init(i915);
17158 ret = intel_cdclk_init(i915);
17160 goto cleanup_vga_client_pw_domain_csr;
17162 ret = intel_dbuf_init(i915);
17164 goto cleanup_vga_client_pw_domain_csr;
17166 ret = intel_bw_init(i915);
17168 goto cleanup_vga_client_pw_domain_csr;
17170 init_llist_head(&i915->atomic_helper.free_list);
17171 INIT_WORK(&i915->atomic_helper.free_work,
17172 intel_atomic_helper_free_state_worker);
17174 intel_init_quirks(i915);
17176 intel_fbc_init(i915);
17180 cleanup_vga_client_pw_domain_csr:
17181 intel_csr_ucode_fini(i915);
17182 intel_power_domains_driver_remove(i915);
17183 intel_vga_unregister(i915);
17185 intel_bios_driver_remove(i915);
17190 /* part #2: call after irq install, but before gem init */
17191 int intel_modeset_init_nogem(struct drm_i915_private *i915)
17193 struct drm_device *dev = &i915->drm;
17195 struct intel_crtc *crtc;
17198 intel_init_pm(i915);
17200 intel_panel_sanitize_ssc(i915);
17202 intel_gmbus_setup(i915);
17204 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n",
17205 INTEL_NUM_PIPES(i915),
17206 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
17208 if (HAS_DISPLAY(i915)) {
17209 for_each_pipe(i915, pipe) {
17210 ret = intel_crtc_init(i915, pipe);
17212 intel_mode_config_cleanup(i915);
17218 intel_plane_possible_crtcs_init(i915);
17219 intel_shared_dpll_init(dev);
17220 intel_update_fdi_pll_freq(i915);
17222 intel_update_czclk(i915);
17223 intel_modeset_init_hw(i915);
17225 intel_hdcp_component_init(i915);
17227 if (i915->max_cdclk_freq == 0)
17228 intel_update_max_cdclk(i915);
17231 * If the platform has HTI, we need to find out whether it has reserved
17232 * any display resources before we create our display outputs.
17234 if (INTEL_INFO(i915)->display.has_hti)
17235 i915->hti_state = intel_de_read(i915, HDPORT_STATE);
17237 /* Just disable it once at startup */
17238 intel_vga_disable(i915);
17239 intel_setup_outputs(i915);
17241 drm_modeset_lock_all(dev);
17242 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
17243 drm_modeset_unlock_all(dev);
17245 for_each_intel_crtc(dev, crtc) {
17246 struct intel_initial_plane_config plane_config = {};
17248 if (!to_intel_crtc_state(crtc->base.state)->uapi.active)
17252 * Note that reserving the BIOS fb up front prevents us
17253 * from stuffing other stolen allocations like the ring
17254 * on top. This prevents some ugliness at boot time, and
17255 * can even allow for smooth boot transitions if the BIOS
17256 * fb is large enough for the active pipe configuration.
17258 i915->display.get_initial_plane_config(crtc, &plane_config);
17261 * If the fb is shared between multiple heads, we'll
17262 * just get the first one.
17264 intel_find_initial_plane_obj(crtc, &plane_config);
17266 plane_config_fini(&plane_config);
17270 * Make sure hardware watermarks really match the state we read out.
17271 * Note that we need to do this after reconstructing the BIOS fb's
17272 * since the watermark calculation done here will use pstate->fb.
17274 if (!HAS_GMCH(i915))
17275 sanitize_watermarks(i915);
17280 /* part #3: call after gem init */
17281 int intel_modeset_init(struct drm_i915_private *i915)
17285 if (!HAS_DISPLAY(i915))
17289 * Force all active planes to recompute their states. So that on
17290 * mode_setcrtc after probe, all the intel_plane_state variables
17291 * are already calculated and there is no assert_plane warnings
17294 ret = intel_initial_commit(&i915->drm);
17296 drm_dbg_kms(&i915->drm, "Initial modeset failed, %d\n", ret);
17298 intel_overlay_setup(i915);
17300 ret = intel_fbdev_init(&i915->drm);
17304 /* Only enable hotplug handling once the fbdev is fully set up. */
17305 intel_hpd_init(i915);
17306 intel_hpd_poll_disable(i915);
17308 intel_init_ipc(i915);
17313 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17315 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17316 /* 640x480@60Hz, ~25175 kHz */
17317 struct dpll clock = {
17327 drm_WARN_ON(&dev_priv->drm,
17328 i9xx_calc_dpll_params(48000, &clock) != 25154);
17330 drm_dbg_kms(&dev_priv->drm,
17331 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
17332 pipe_name(pipe), clock.vco, clock.dot);
17334 fp = i9xx_dpll_compute_fp(&clock);
17335 dpll = DPLL_DVO_2X_MODE |
17336 DPLL_VGA_MODE_DIS |
17337 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
17338 PLL_P2_DIVIDE_BY_4 |
17339 PLL_REF_INPUT_DREFCLK |
17342 intel_de_write(dev_priv, FP0(pipe), fp);
17343 intel_de_write(dev_priv, FP1(pipe), fp);
17345 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
17346 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
17347 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
17348 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
17349 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
17350 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
17351 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
17354 * Apparently we need to have VGA mode enabled prior to changing
17355 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
17356 * dividers, even though the register value does change.
17358 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
17359 intel_de_write(dev_priv, DPLL(pipe), dpll);
17361 /* Wait for the clocks to stabilize. */
17362 intel_de_posting_read(dev_priv, DPLL(pipe));
17365 /* The pixel multiplier can only be updated once the
17366 * DPLL is enabled and the clocks are stable.
17368 * So write it again.
17370 intel_de_write(dev_priv, DPLL(pipe), dpll);
17372 /* We do this three times for luck */
17373 for (i = 0; i < 3 ; i++) {
17374 intel_de_write(dev_priv, DPLL(pipe), dpll);
17375 intel_de_posting_read(dev_priv, DPLL(pipe));
17376 udelay(150); /* wait for warmup */
17379 intel_de_write(dev_priv, PIPECONF(pipe),
17380 PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
17381 intel_de_posting_read(dev_priv, PIPECONF(pipe));
17383 intel_wait_for_pipe_scanline_moving(crtc);
17386 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17388 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17390 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
17393 drm_WARN_ON(&dev_priv->drm,
17394 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) &
17395 DISPLAY_PLANE_ENABLE);
17396 drm_WARN_ON(&dev_priv->drm,
17397 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) &
17398 DISPLAY_PLANE_ENABLE);
17399 drm_WARN_ON(&dev_priv->drm,
17400 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) &
17401 DISPLAY_PLANE_ENABLE);
17402 drm_WARN_ON(&dev_priv->drm,
17403 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE);
17404 drm_WARN_ON(&dev_priv->drm,
17405 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE);
17407 intel_de_write(dev_priv, PIPECONF(pipe), 0);
17408 intel_de_posting_read(dev_priv, PIPECONF(pipe));
17410 intel_wait_for_pipe_scanline_stopped(crtc);
17412 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
17413 intel_de_posting_read(dev_priv, DPLL(pipe));
17417 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
17419 struct intel_crtc *crtc;
17421 if (INTEL_GEN(dev_priv) >= 4)
17424 for_each_intel_crtc(&dev_priv->drm, crtc) {
17425 struct intel_plane *plane =
17426 to_intel_plane(crtc->base.primary);
17427 struct intel_crtc *plane_crtc;
17430 if (!plane->get_hw_state(plane, &pipe))
17433 if (pipe == crtc->pipe)
17436 drm_dbg_kms(&dev_priv->drm,
17437 "[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
17438 plane->base.base.id, plane->base.name);
17440 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17441 intel_plane_disable_noatomic(plane_crtc, plane);
17445 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
17447 struct drm_device *dev = crtc->base.dev;
17448 struct intel_encoder *encoder;
17450 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
17456 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
17458 struct drm_device *dev = encoder->base.dev;
17459 struct intel_connector *connector;
17461 for_each_connector_on_encoder(dev, &encoder->base, connector)
17467 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
17468 enum pipe pch_transcoder)
17470 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
17471 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
17474 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state *crtc_state)
17476 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
17477 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
17478 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
17480 if (INTEL_GEN(dev_priv) >= 9 ||
17481 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
17482 i915_reg_t reg = CHICKEN_TRANS(cpu_transcoder);
17485 if (transcoder_is_dsi(cpu_transcoder))
17488 val = intel_de_read(dev_priv, reg);
17489 val &= ~HSW_FRAME_START_DELAY_MASK;
17490 val |= HSW_FRAME_START_DELAY(0);
17491 intel_de_write(dev_priv, reg, val);
17493 i915_reg_t reg = PIPECONF(cpu_transcoder);
17496 val = intel_de_read(dev_priv, reg);
17497 val &= ~PIPECONF_FRAME_START_DELAY_MASK;
17498 val |= PIPECONF_FRAME_START_DELAY(0);
17499 intel_de_write(dev_priv, reg, val);
17502 if (!crtc_state->has_pch_encoder)
17505 if (HAS_PCH_IBX(dev_priv)) {
17506 i915_reg_t reg = PCH_TRANSCONF(crtc->pipe);
17509 val = intel_de_read(dev_priv, reg);
17510 val &= ~TRANS_FRAME_START_DELAY_MASK;
17511 val |= TRANS_FRAME_START_DELAY(0);
17512 intel_de_write(dev_priv, reg, val);
17514 enum pipe pch_transcoder = intel_crtc_pch_transcoder(crtc);
17515 i915_reg_t reg = TRANS_CHICKEN2(pch_transcoder);
17518 val = intel_de_read(dev_priv, reg);
17519 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
17520 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
17521 intel_de_write(dev_priv, reg, val);
17525 static void intel_sanitize_crtc(struct intel_crtc *crtc,
17526 struct drm_modeset_acquire_ctx *ctx)
17528 struct drm_device *dev = crtc->base.dev;
17529 struct drm_i915_private *dev_priv = to_i915(dev);
17530 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
17532 if (crtc_state->hw.active) {
17533 struct intel_plane *plane;
17535 /* Clear any frame start delays used for debugging left by the BIOS */
17536 intel_sanitize_frame_start_delay(crtc_state);
17538 /* Disable everything but the primary plane */
17539 for_each_intel_plane_on_crtc(dev, crtc, plane) {
17540 const struct intel_plane_state *plane_state =
17541 to_intel_plane_state(plane->base.state);
17543 if (plane_state->uapi.visible &&
17544 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
17545 intel_plane_disable_noatomic(crtc, plane);
17549 * Disable any background color set by the BIOS, but enable the
17550 * gamma and CSC to match how we program our planes.
17552 if (INTEL_GEN(dev_priv) >= 9)
17553 intel_de_write(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe),
17554 SKL_BOTTOM_COLOR_GAMMA_ENABLE | SKL_BOTTOM_COLOR_CSC_ENABLE);
17557 /* Adjust the state of the output pipe according to whether we
17558 * have active connectors/encoders. */
17559 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc) &&
17560 !crtc_state->bigjoiner_slave)
17561 intel_crtc_disable_noatomic(crtc, ctx);
17563 if (crtc_state->hw.active || HAS_GMCH(dev_priv)) {
17565 * We start out with underrun reporting disabled to avoid races.
17566 * For correct bookkeeping mark this on active crtcs.
17568 * Also on gmch platforms we dont have any hardware bits to
17569 * disable the underrun reporting. Which means we need to start
17570 * out with underrun reporting disabled also on inactive pipes,
17571 * since otherwise we'll complain about the garbage we read when
17572 * e.g. coming up after runtime pm.
17574 * No protection against concurrent access is required - at
17575 * worst a fifo underrun happens which also sets this to false.
17577 crtc->cpu_fifo_underrun_disabled = true;
17579 * We track the PCH trancoder underrun reporting state
17580 * within the crtc. With crtc for pipe A housing the underrun
17581 * reporting state for PCH transcoder A, crtc for pipe B housing
17582 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
17583 * and marking underrun reporting as disabled for the non-existing
17584 * PCH transcoders B and C would prevent enabling the south
17585 * error interrupt (see cpt_can_enable_serr_int()).
17587 if (has_pch_trancoder(dev_priv, crtc->pipe))
17588 crtc->pch_fifo_underrun_disabled = true;
17592 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
17594 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
17597 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
17598 * the hardware when a high res displays plugged in. DPLL P
17599 * divider is zero, and the pipe timings are bonkers. We'll
17600 * try to disable everything in that case.
17602 * FIXME would be nice to be able to sanitize this state
17603 * without several WARNs, but for now let's take the easy
17606 return IS_GEN(dev_priv, 6) &&
17607 crtc_state->hw.active &&
17608 crtc_state->shared_dpll &&
17609 crtc_state->port_clock == 0;
17612 static void intel_sanitize_encoder(struct intel_encoder *encoder)
17614 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
17615 struct intel_connector *connector;
17616 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
17617 struct intel_crtc_state *crtc_state = crtc ?
17618 to_intel_crtc_state(crtc->base.state) : NULL;
17620 /* We need to check both for a crtc link (meaning that the
17621 * encoder is active and trying to read from a pipe) and the
17622 * pipe itself being active. */
17623 bool has_active_crtc = crtc_state &&
17624 crtc_state->hw.active;
17626 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
17627 drm_dbg_kms(&dev_priv->drm,
17628 "BIOS has misprogrammed the hardware. Disabling pipe %c\n",
17629 pipe_name(crtc->pipe));
17630 has_active_crtc = false;
17633 connector = intel_encoder_find_connector(encoder);
17634 if (connector && !has_active_crtc) {
17635 drm_dbg_kms(&dev_priv->drm,
17636 "[ENCODER:%d:%s] has active connectors but no active pipe!\n",
17637 encoder->base.base.id,
17638 encoder->base.name);
17640 /* Connector is active, but has no active pipe. This is
17641 * fallout from our resume register restoring. Disable
17642 * the encoder manually again. */
17644 struct drm_encoder *best_encoder;
17646 drm_dbg_kms(&dev_priv->drm,
17647 "[ENCODER:%d:%s] manually disabled\n",
17648 encoder->base.base.id,
17649 encoder->base.name);
17651 /* avoid oopsing in case the hooks consult best_encoder */
17652 best_encoder = connector->base.state->best_encoder;
17653 connector->base.state->best_encoder = &encoder->base;
17655 /* FIXME NULL atomic state passed! */
17656 if (encoder->disable)
17657 encoder->disable(NULL, encoder, crtc_state,
17658 connector->base.state);
17659 if (encoder->post_disable)
17660 encoder->post_disable(NULL, encoder, crtc_state,
17661 connector->base.state);
17663 connector->base.state->best_encoder = best_encoder;
17665 encoder->base.crtc = NULL;
17667 /* Inconsistent output/port/pipe state happens presumably due to
17668 * a bug in one of the get_hw_state functions. Or someplace else
17669 * in our code, like the register restore mess on resume. Clamp
17670 * things to off as a safer default. */
17672 connector->base.dpms = DRM_MODE_DPMS_OFF;
17673 connector->base.encoder = NULL;
17676 /* notify opregion of the sanitized encoder state */
17677 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
17679 if (INTEL_GEN(dev_priv) >= 11)
17680 icl_sanitize_encoder_pll_mapping(encoder);
17683 /* FIXME read out full plane state for all planes */
17684 static void readout_plane_state(struct drm_i915_private *dev_priv)
17686 struct intel_plane *plane;
17687 struct intel_crtc *crtc;
17689 for_each_intel_plane(&dev_priv->drm, plane) {
17690 struct intel_plane_state *plane_state =
17691 to_intel_plane_state(plane->base.state);
17692 struct intel_crtc_state *crtc_state;
17693 enum pipe pipe = PIPE_A;
17696 visible = plane->get_hw_state(plane, &pipe);
17698 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17699 crtc_state = to_intel_crtc_state(crtc->base.state);
17701 intel_set_plane_visible(crtc_state, plane_state, visible);
17703 drm_dbg_kms(&dev_priv->drm,
17704 "[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
17705 plane->base.base.id, plane->base.name,
17706 enableddisabled(visible), pipe_name(pipe));
17709 for_each_intel_crtc(&dev_priv->drm, crtc) {
17710 struct intel_crtc_state *crtc_state =
17711 to_intel_crtc_state(crtc->base.state);
17713 fixup_plane_bitmasks(crtc_state);
17717 static void intel_modeset_readout_hw_state(struct drm_device *dev)
17719 struct drm_i915_private *dev_priv = to_i915(dev);
17720 struct intel_cdclk_state *cdclk_state =
17721 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
17722 struct intel_dbuf_state *dbuf_state =
17723 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
17725 struct intel_crtc *crtc;
17726 struct intel_encoder *encoder;
17727 struct intel_connector *connector;
17728 struct drm_connector_list_iter conn_iter;
17729 u8 active_pipes = 0;
17731 for_each_intel_crtc(dev, crtc) {
17732 struct intel_crtc_state *crtc_state =
17733 to_intel_crtc_state(crtc->base.state);
17735 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
17736 intel_crtc_free_hw_state(crtc_state);
17737 intel_crtc_state_reset(crtc_state, crtc);
17739 intel_crtc_get_pipe_config(crtc_state);
17741 crtc_state->hw.enable = crtc_state->hw.active;
17743 crtc->base.enabled = crtc_state->hw.enable;
17744 crtc->active = crtc_state->hw.active;
17746 if (crtc_state->hw.active)
17747 active_pipes |= BIT(crtc->pipe);
17749 drm_dbg_kms(&dev_priv->drm,
17750 "[CRTC:%d:%s] hw state readout: %s\n",
17751 crtc->base.base.id, crtc->base.name,
17752 enableddisabled(crtc_state->hw.active));
17755 dev_priv->active_pipes = cdclk_state->active_pipes =
17756 dbuf_state->active_pipes = active_pipes;
17758 readout_plane_state(dev_priv);
17760 intel_dpll_readout_hw_state(dev_priv);
17762 for_each_intel_encoder(dev, encoder) {
17765 if (encoder->get_hw_state(encoder, &pipe)) {
17766 struct intel_crtc_state *crtc_state;
17768 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17769 crtc_state = to_intel_crtc_state(crtc->base.state);
17771 encoder->base.crtc = &crtc->base;
17772 intel_encoder_get_config(encoder, crtc_state);
17773 if (encoder->sync_state)
17774 encoder->sync_state(encoder, crtc_state);
17776 /* read out to slave crtc as well for bigjoiner */
17777 if (crtc_state->bigjoiner) {
17778 /* encoder should read be linked to bigjoiner master */
17779 WARN_ON(crtc_state->bigjoiner_slave);
17781 crtc = crtc_state->bigjoiner_linked_crtc;
17782 crtc_state = to_intel_crtc_state(crtc->base.state);
17783 intel_encoder_get_config(encoder, crtc_state);
17786 encoder->base.crtc = NULL;
17789 drm_dbg_kms(&dev_priv->drm,
17790 "[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
17791 encoder->base.base.id, encoder->base.name,
17792 enableddisabled(encoder->base.crtc),
17796 drm_connector_list_iter_begin(dev, &conn_iter);
17797 for_each_intel_connector_iter(connector, &conn_iter) {
17798 if (connector->get_hw_state(connector)) {
17799 struct intel_crtc_state *crtc_state;
17800 struct intel_crtc *crtc;
17802 connector->base.dpms = DRM_MODE_DPMS_ON;
17804 encoder = intel_attached_encoder(connector);
17805 connector->base.encoder = &encoder->base;
17807 crtc = to_intel_crtc(encoder->base.crtc);
17808 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
17810 if (crtc_state && crtc_state->hw.active) {
17812 * This has to be done during hardware readout
17813 * because anything calling .crtc_disable may
17814 * rely on the connector_mask being accurate.
17816 crtc_state->uapi.connector_mask |=
17817 drm_connector_mask(&connector->base);
17818 crtc_state->uapi.encoder_mask |=
17819 drm_encoder_mask(&encoder->base);
17822 connector->base.dpms = DRM_MODE_DPMS_OFF;
17823 connector->base.encoder = NULL;
17825 drm_dbg_kms(&dev_priv->drm,
17826 "[CONNECTOR:%d:%s] hw state readout: %s\n",
17827 connector->base.base.id, connector->base.name,
17828 enableddisabled(connector->base.encoder));
17830 drm_connector_list_iter_end(&conn_iter);
17832 for_each_intel_crtc(dev, crtc) {
17833 struct intel_bw_state *bw_state =
17834 to_intel_bw_state(dev_priv->bw_obj.state);
17835 struct intel_crtc_state *crtc_state =
17836 to_intel_crtc_state(crtc->base.state);
17837 struct intel_plane *plane;
17840 if (crtc_state->bigjoiner_slave)
17843 if (crtc_state->hw.active) {
17845 * The initial mode needs to be set in order to keep
17846 * the atomic core happy. It wants a valid mode if the
17847 * crtc's enabled, so we do the above call.
17849 * But we don't set all the derived state fully, hence
17850 * set a flag to indicate that a full recalculation is
17851 * needed on the next commit.
17853 crtc_state->inherited = true;
17855 intel_crtc_update_active_timings(crtc_state);
17857 intel_crtc_copy_hw_to_uapi_state(crtc_state);
17860 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
17861 const struct intel_plane_state *plane_state =
17862 to_intel_plane_state(plane->base.state);
17865 * FIXME don't have the fb yet, so can't
17866 * use intel_plane_data_rate() :(
17868 if (plane_state->uapi.visible)
17869 crtc_state->data_rate[plane->id] =
17870 4 * crtc_state->pixel_rate;
17872 * FIXME don't have the fb yet, so can't
17873 * use plane->min_cdclk() :(
17875 if (plane_state->uapi.visible && plane->min_cdclk) {
17876 if (crtc_state->double_wide ||
17877 INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
17878 crtc_state->min_cdclk[plane->id] =
17879 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
17881 crtc_state->min_cdclk[plane->id] =
17882 crtc_state->pixel_rate;
17884 drm_dbg_kms(&dev_priv->drm,
17885 "[PLANE:%d:%s] min_cdclk %d kHz\n",
17886 plane->base.base.id, plane->base.name,
17887 crtc_state->min_cdclk[plane->id]);
17890 if (crtc_state->hw.active) {
17891 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
17892 if (drm_WARN_ON(dev, min_cdclk < 0))
17896 cdclk_state->min_cdclk[crtc->pipe] = min_cdclk;
17897 cdclk_state->min_voltage_level[crtc->pipe] =
17898 crtc_state->min_voltage_level;
17900 intel_bw_crtc_update(bw_state, crtc_state);
17902 intel_pipe_config_sanity_check(dev_priv, crtc_state);
17904 /* discard our incomplete slave state, copy it from master */
17905 if (crtc_state->bigjoiner && crtc_state->hw.active) {
17906 struct intel_crtc *slave = crtc_state->bigjoiner_linked_crtc;
17907 struct intel_crtc_state *slave_crtc_state =
17908 to_intel_crtc_state(slave->base.state);
17910 copy_bigjoiner_crtc_state(slave_crtc_state, crtc_state);
17911 slave->base.mode = crtc->base.mode;
17913 cdclk_state->min_cdclk[slave->pipe] = min_cdclk;
17914 cdclk_state->min_voltage_level[slave->pipe] =
17915 crtc_state->min_voltage_level;
17917 for_each_intel_plane_on_crtc(&dev_priv->drm, slave, plane) {
17918 const struct intel_plane_state *plane_state =
17919 to_intel_plane_state(plane->base.state);
17922 * FIXME don't have the fb yet, so can't
17923 * use intel_plane_data_rate() :(
17925 if (plane_state->uapi.visible)
17926 crtc_state->data_rate[plane->id] =
17927 4 * crtc_state->pixel_rate;
17929 crtc_state->data_rate[plane->id] = 0;
17932 intel_bw_crtc_update(bw_state, slave_crtc_state);
17933 drm_calc_timestamping_constants(&slave->base,
17934 &slave_crtc_state->hw.adjusted_mode);
17940 get_encoder_power_domains(struct drm_i915_private *dev_priv)
17942 struct intel_encoder *encoder;
17944 for_each_intel_encoder(&dev_priv->drm, encoder) {
17945 struct intel_crtc_state *crtc_state;
17947 if (!encoder->get_power_domains)
17951 * MST-primary and inactive encoders don't have a crtc state
17952 * and neither of these require any power domain references.
17954 if (!encoder->base.crtc)
17957 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
17958 encoder->get_power_domains(encoder, crtc_state);
17962 static void intel_early_display_was(struct drm_i915_private *dev_priv)
17965 * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl
17966 * Also known as Wa_14010480278.
17968 if (IS_GEN_RANGE(dev_priv, 10, 12) || IS_GEMINILAKE(dev_priv))
17969 intel_de_write(dev_priv, GEN9_CLKGATE_DIS_0,
17970 intel_de_read(dev_priv, GEN9_CLKGATE_DIS_0) | DARBF_GATING_DIS);
17972 if (IS_HASWELL(dev_priv)) {
17974 * WaRsPkgCStateDisplayPMReq:hsw
17975 * System hang if this isn't done before disabling all planes!
17977 intel_de_write(dev_priv, CHICKEN_PAR1_1,
17978 intel_de_read(dev_priv, CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
17981 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) {
17982 /* Display WA #1142:kbl,cfl,cml */
17983 intel_de_rmw(dev_priv, CHICKEN_PAR1_1,
17984 KBL_ARB_FILL_SPARE_22, KBL_ARB_FILL_SPARE_22);
17985 intel_de_rmw(dev_priv, CHICKEN_MISC_2,
17986 KBL_ARB_FILL_SPARE_13 | KBL_ARB_FILL_SPARE_14,
17987 KBL_ARB_FILL_SPARE_14);
17991 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
17992 enum port port, i915_reg_t hdmi_reg)
17994 u32 val = intel_de_read(dev_priv, hdmi_reg);
17996 if (val & SDVO_ENABLE ||
17997 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
18000 drm_dbg_kms(&dev_priv->drm,
18001 "Sanitizing transcoder select for HDMI %c\n",
18004 val &= ~SDVO_PIPE_SEL_MASK;
18005 val |= SDVO_PIPE_SEL(PIPE_A);
18007 intel_de_write(dev_priv, hdmi_reg, val);
18010 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
18011 enum port port, i915_reg_t dp_reg)
18013 u32 val = intel_de_read(dev_priv, dp_reg);
18015 if (val & DP_PORT_EN ||
18016 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
18019 drm_dbg_kms(&dev_priv->drm,
18020 "Sanitizing transcoder select for DP %c\n",
18023 val &= ~DP_PIPE_SEL_MASK;
18024 val |= DP_PIPE_SEL(PIPE_A);
18026 intel_de_write(dev_priv, dp_reg, val);
18029 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
18032 * The BIOS may select transcoder B on some of the PCH
18033 * ports even it doesn't enable the port. This would trip
18034 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
18035 * Sanitize the transcoder select bits to prevent that. We
18036 * assume that the BIOS never actually enabled the port,
18037 * because if it did we'd actually have to toggle the port
18038 * on and back off to make the transcoder A select stick
18039 * (see. intel_dp_link_down(), intel_disable_hdmi(),
18040 * intel_disable_sdvo()).
18042 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
18043 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
18044 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
18046 /* PCH SDVOB multiplex with HDMIB */
18047 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
18048 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
18049 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
18052 /* Scan out the current hw modeset state,
18053 * and sanitizes it to the current state
18056 intel_modeset_setup_hw_state(struct drm_device *dev,
18057 struct drm_modeset_acquire_ctx *ctx)
18059 struct drm_i915_private *dev_priv = to_i915(dev);
18060 struct intel_encoder *encoder;
18061 struct intel_crtc *crtc;
18062 intel_wakeref_t wakeref;
18064 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
18066 intel_early_display_was(dev_priv);
18067 intel_modeset_readout_hw_state(dev);
18069 /* HW state is read out, now we need to sanitize this mess. */
18071 /* Sanitize the TypeC port mode upfront, encoders depend on this */
18072 for_each_intel_encoder(dev, encoder) {
18073 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
18075 /* We need to sanitize only the MST primary port. */
18076 if (encoder->type != INTEL_OUTPUT_DP_MST &&
18077 intel_phy_is_tc(dev_priv, phy))
18078 intel_tc_port_sanitize(enc_to_dig_port(encoder));
18081 get_encoder_power_domains(dev_priv);
18083 if (HAS_PCH_IBX(dev_priv))
18084 ibx_sanitize_pch_ports(dev_priv);
18087 * intel_sanitize_plane_mapping() may need to do vblank
18088 * waits, so we need vblank interrupts restored beforehand.
18090 for_each_intel_crtc(&dev_priv->drm, crtc) {
18091 struct intel_crtc_state *crtc_state =
18092 to_intel_crtc_state(crtc->base.state);
18094 drm_crtc_vblank_reset(&crtc->base);
18096 if (crtc_state->hw.active)
18097 intel_crtc_vblank_on(crtc_state);
18100 intel_sanitize_plane_mapping(dev_priv);
18102 for_each_intel_encoder(dev, encoder)
18103 intel_sanitize_encoder(encoder);
18105 for_each_intel_crtc(&dev_priv->drm, crtc) {
18106 struct intel_crtc_state *crtc_state =
18107 to_intel_crtc_state(crtc->base.state);
18109 intel_sanitize_crtc(crtc, ctx);
18110 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
18113 intel_modeset_update_connector_atomic_state(dev);
18115 intel_dpll_sanitize_state(dev_priv);
18117 if (IS_G4X(dev_priv)) {
18118 g4x_wm_get_hw_state(dev_priv);
18119 g4x_wm_sanitize(dev_priv);
18120 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
18121 vlv_wm_get_hw_state(dev_priv);
18122 vlv_wm_sanitize(dev_priv);
18123 } else if (INTEL_GEN(dev_priv) >= 9) {
18124 skl_wm_get_hw_state(dev_priv);
18125 } else if (HAS_PCH_SPLIT(dev_priv)) {
18126 ilk_wm_get_hw_state(dev_priv);
18129 for_each_intel_crtc(dev, crtc) {
18130 struct intel_crtc_state *crtc_state =
18131 to_intel_crtc_state(crtc->base.state);
18134 put_domains = modeset_get_crtc_power_domains(crtc_state);
18135 if (drm_WARN_ON(dev, put_domains))
18136 modeset_put_crtc_power_domains(crtc, put_domains);
18139 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
18142 void intel_display_resume(struct drm_device *dev)
18144 struct drm_i915_private *dev_priv = to_i915(dev);
18145 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
18146 struct drm_modeset_acquire_ctx ctx;
18149 dev_priv->modeset_restore_state = NULL;
18151 state->acquire_ctx = &ctx;
18153 drm_modeset_acquire_init(&ctx, 0);
18156 ret = drm_modeset_lock_all_ctx(dev, &ctx);
18157 if (ret != -EDEADLK)
18160 drm_modeset_backoff(&ctx);
18164 ret = __intel_display_resume(dev, state, &ctx);
18166 intel_enable_ipc(dev_priv);
18167 drm_modeset_drop_locks(&ctx);
18168 drm_modeset_acquire_fini(&ctx);
18171 drm_err(&dev_priv->drm,
18172 "Restoring old state failed with %i\n", ret);
18174 drm_atomic_state_put(state);
18177 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
18179 struct intel_connector *connector;
18180 struct drm_connector_list_iter conn_iter;
18182 /* Kill all the work that may have been queued by hpd. */
18183 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
18184 for_each_intel_connector_iter(connector, &conn_iter) {
18185 if (connector->modeset_retry_work.func)
18186 cancel_work_sync(&connector->modeset_retry_work);
18187 if (connector->hdcp.shim) {
18188 cancel_delayed_work_sync(&connector->hdcp.check_work);
18189 cancel_work_sync(&connector->hdcp.prop_work);
18192 drm_connector_list_iter_end(&conn_iter);
18195 /* part #1: call before irq uninstall */
18196 void intel_modeset_driver_remove(struct drm_i915_private *i915)
18198 flush_workqueue(i915->flip_wq);
18199 flush_workqueue(i915->modeset_wq);
18201 flush_work(&i915->atomic_helper.free_work);
18202 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list));
18205 /* part #2: call after irq uninstall */
18206 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915)
18209 * Due to the hpd irq storm handling the hotplug work can re-arm the
18210 * poll handlers. Hence disable polling after hpd handling is shut down.
18212 intel_hpd_poll_fini(i915);
18215 * MST topology needs to be suspended so we don't have any calls to
18216 * fbdev after it's finalized. MST will be destroyed later as part of
18217 * drm_mode_config_cleanup()
18219 intel_dp_mst_suspend(i915);
18221 /* poll work can call into fbdev, hence clean that up afterwards */
18222 intel_fbdev_fini(i915);
18224 intel_unregister_dsm_handler();
18226 intel_fbc_global_disable(i915);
18228 /* flush any delayed tasks or pending work */
18229 flush_scheduled_work();
18231 intel_hdcp_component_fini(i915);
18233 intel_mode_config_cleanup(i915);
18235 intel_overlay_cleanup(i915);
18237 intel_gmbus_teardown(i915);
18239 destroy_workqueue(i915->flip_wq);
18240 destroy_workqueue(i915->modeset_wq);
18242 intel_fbc_cleanup_cfb(i915);
18245 /* part #3: call after gem init */
18246 void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
18248 intel_csr_ucode_fini(i915);
18250 intel_power_domains_driver_remove(i915);
18252 intel_vga_unregister(i915);
18254 intel_bios_driver_remove(i915);
18257 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
18259 struct intel_display_error_state {
18261 u32 power_well_driver;
18263 struct intel_cursor_error_state {
18268 } cursor[I915_MAX_PIPES];
18270 struct intel_pipe_error_state {
18271 bool power_domain_on;
18274 } pipe[I915_MAX_PIPES];
18276 struct intel_plane_error_state {
18284 } plane[I915_MAX_PIPES];
18286 struct intel_transcoder_error_state {
18288 bool power_domain_on;
18289 enum transcoder cpu_transcoder;
18302 struct intel_display_error_state *
18303 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
18305 struct intel_display_error_state *error;
18306 int transcoders[] = {
18315 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
18317 if (!HAS_DISPLAY(dev_priv))
18320 error = kzalloc(sizeof(*error), GFP_ATOMIC);
18324 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18325 error->power_well_driver = intel_de_read(dev_priv,
18326 HSW_PWR_WELL_CTL2);
18328 for_each_pipe(dev_priv, i) {
18329 error->pipe[i].power_domain_on =
18330 __intel_display_power_is_enabled(dev_priv,
18331 POWER_DOMAIN_PIPE(i));
18332 if (!error->pipe[i].power_domain_on)
18335 error->cursor[i].control = intel_de_read(dev_priv, CURCNTR(i));
18336 error->cursor[i].position = intel_de_read(dev_priv, CURPOS(i));
18337 error->cursor[i].base = intel_de_read(dev_priv, CURBASE(i));
18339 error->plane[i].control = intel_de_read(dev_priv, DSPCNTR(i));
18340 error->plane[i].stride = intel_de_read(dev_priv, DSPSTRIDE(i));
18341 if (INTEL_GEN(dev_priv) <= 3) {
18342 error->plane[i].size = intel_de_read(dev_priv,
18344 error->plane[i].pos = intel_de_read(dev_priv,
18347 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18348 error->plane[i].addr = intel_de_read(dev_priv,
18350 if (INTEL_GEN(dev_priv) >= 4) {
18351 error->plane[i].surface = intel_de_read(dev_priv,
18353 error->plane[i].tile_offset = intel_de_read(dev_priv,
18357 error->pipe[i].source = intel_de_read(dev_priv, PIPESRC(i));
18359 if (HAS_GMCH(dev_priv))
18360 error->pipe[i].stat = intel_de_read(dev_priv,
18364 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18365 enum transcoder cpu_transcoder = transcoders[i];
18367 if (!HAS_TRANSCODER(dev_priv, cpu_transcoder))
18370 error->transcoder[i].available = true;
18371 error->transcoder[i].power_domain_on =
18372 __intel_display_power_is_enabled(dev_priv,
18373 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
18374 if (!error->transcoder[i].power_domain_on)
18377 error->transcoder[i].cpu_transcoder = cpu_transcoder;
18379 error->transcoder[i].conf = intel_de_read(dev_priv,
18380 PIPECONF(cpu_transcoder));
18381 error->transcoder[i].htotal = intel_de_read(dev_priv,
18382 HTOTAL(cpu_transcoder));
18383 error->transcoder[i].hblank = intel_de_read(dev_priv,
18384 HBLANK(cpu_transcoder));
18385 error->transcoder[i].hsync = intel_de_read(dev_priv,
18386 HSYNC(cpu_transcoder));
18387 error->transcoder[i].vtotal = intel_de_read(dev_priv,
18388 VTOTAL(cpu_transcoder));
18389 error->transcoder[i].vblank = intel_de_read(dev_priv,
18390 VBLANK(cpu_transcoder));
18391 error->transcoder[i].vsync = intel_de_read(dev_priv,
18392 VSYNC(cpu_transcoder));
18398 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
18401 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
18402 struct intel_display_error_state *error)
18404 struct drm_i915_private *dev_priv = m->i915;
18410 err_printf(m, "Num Pipes: %d\n", INTEL_NUM_PIPES(dev_priv));
18411 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18412 err_printf(m, "PWR_WELL_CTL2: %08x\n",
18413 error->power_well_driver);
18414 for_each_pipe(dev_priv, i) {
18415 err_printf(m, "Pipe [%d]:\n", i);
18416 err_printf(m, " Power: %s\n",
18417 onoff(error->pipe[i].power_domain_on));
18418 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
18419 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
18421 err_printf(m, "Plane [%d]:\n", i);
18422 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
18423 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
18424 if (INTEL_GEN(dev_priv) <= 3) {
18425 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
18426 err_printf(m, " POS: %08x\n", error->plane[i].pos);
18428 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18429 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
18430 if (INTEL_GEN(dev_priv) >= 4) {
18431 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
18432 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
18435 err_printf(m, "Cursor [%d]:\n", i);
18436 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
18437 err_printf(m, " POS: %08x\n", error->cursor[i].position);
18438 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
18441 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18442 if (!error->transcoder[i].available)
18445 err_printf(m, "CPU transcoder: %s\n",
18446 transcoder_name(error->transcoder[i].cpu_transcoder));
18447 err_printf(m, " Power: %s\n",
18448 onoff(error->transcoder[i].power_domain_on));
18449 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
18450 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
18451 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
18452 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
18453 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
18454 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
18455 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);