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_dp_helper.h>
39 #include <drm/drm_edid.h>
40 #include <drm/drm_fourcc.h>
41 #include <drm/drm_plane_helper.h>
42 #include <drm/drm_probe_helper.h>
43 #include <drm/drm_rect.h>
44 #include <drm/i915_drm.h>
46 #include "display/intel_crt.h"
47 #include "display/intel_ddi.h"
48 #include "display/intel_dp.h"
49 #include "display/intel_dp_mst.h"
50 #include "display/intel_dsi.h"
51 #include "display/intel_dvo.h"
52 #include "display/intel_gmbus.h"
53 #include "display/intel_hdmi.h"
54 #include "display/intel_lvds.h"
55 #include "display/intel_sdvo.h"
56 #include "display/intel_tv.h"
57 #include "display/intel_vdsc.h"
59 #include "gt/intel_rps.h"
62 #include "i915_trace.h"
63 #include "intel_acpi.h"
64 #include "intel_atomic.h"
65 #include "intel_atomic_plane.h"
67 #include "intel_cdclk.h"
68 #include "intel_color.h"
69 #include "intel_display_types.h"
70 #include "intel_dp_link_training.h"
71 #include "intel_fbc.h"
72 #include "intel_fbdev.h"
73 #include "intel_fifo_underrun.h"
74 #include "intel_frontbuffer.h"
75 #include "intel_hdcp.h"
76 #include "intel_hotplug.h"
77 #include "intel_overlay.h"
78 #include "intel_pipe_crc.h"
80 #include "intel_psr.h"
81 #include "intel_quirks.h"
82 #include "intel_sideband.h"
83 #include "intel_sprite.h"
85 #include "intel_vga.h"
87 /* Primary plane formats for gen <= 3 */
88 static const u32 i8xx_primary_formats[] = {
95 /* Primary plane formats for ivb (no fp16 due to hw issue) */
96 static const u32 ivb_primary_formats[] = {
101 DRM_FORMAT_XRGB2101010,
102 DRM_FORMAT_XBGR2101010,
105 /* Primary plane formats for gen >= 4, except ivb */
106 static const u32 i965_primary_formats[] = {
111 DRM_FORMAT_XRGB2101010,
112 DRM_FORMAT_XBGR2101010,
113 DRM_FORMAT_XBGR16161616F,
116 /* Primary plane formats for vlv/chv */
117 static const u32 vlv_primary_formats[] = {
124 DRM_FORMAT_XRGB2101010,
125 DRM_FORMAT_XBGR2101010,
126 DRM_FORMAT_ARGB2101010,
127 DRM_FORMAT_ABGR2101010,
128 DRM_FORMAT_XBGR16161616F,
131 static const u64 i9xx_format_modifiers[] = {
132 I915_FORMAT_MOD_X_TILED,
133 DRM_FORMAT_MOD_LINEAR,
134 DRM_FORMAT_MOD_INVALID
138 static const u32 intel_cursor_formats[] = {
142 static const u64 cursor_format_modifiers[] = {
143 DRM_FORMAT_MOD_LINEAR,
144 DRM_FORMAT_MOD_INVALID
147 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
148 struct intel_crtc_state *pipe_config);
149 static void ilk_pch_clock_get(struct intel_crtc *crtc,
150 struct intel_crtc_state *pipe_config);
152 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
153 struct drm_i915_gem_object *obj,
154 struct drm_mode_fb_cmd2 *mode_cmd);
155 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
156 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
157 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
158 const struct intel_link_m_n *m_n,
159 const struct intel_link_m_n *m2_n2);
160 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
161 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state);
162 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state);
163 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
164 static void vlv_prepare_pll(struct intel_crtc *crtc,
165 const struct intel_crtc_state *pipe_config);
166 static void chv_prepare_pll(struct intel_crtc *crtc,
167 const struct intel_crtc_state *pipe_config);
168 static void skl_pfit_enable(const struct intel_crtc_state *crtc_state);
169 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state);
170 static void intel_modeset_setup_hw_state(struct drm_device *dev,
171 struct drm_modeset_acquire_ctx *ctx);
172 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc);
177 } dot, vco, n, m, m1, m2, p, p1;
181 int p2_slow, p2_fast;
185 /* returns HPLL frequency in kHz */
186 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
188 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
190 /* Obtain SKU information */
191 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
192 CCK_FUSE_HPLL_FREQ_MASK;
194 return vco_freq[hpll_freq] * 1000;
197 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
198 const char *name, u32 reg, int ref_freq)
203 val = vlv_cck_read(dev_priv, reg);
204 divider = val & CCK_FREQUENCY_VALUES;
206 WARN((val & CCK_FREQUENCY_STATUS) !=
207 (divider << CCK_FREQUENCY_STATUS_SHIFT),
208 "%s change in progress\n", name);
210 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
213 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
214 const char *name, u32 reg)
218 vlv_cck_get(dev_priv);
220 if (dev_priv->hpll_freq == 0)
221 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
223 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
225 vlv_cck_put(dev_priv);
230 static void intel_update_czclk(struct drm_i915_private *dev_priv)
232 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
235 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
236 CCK_CZ_CLOCK_CONTROL);
238 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
241 static inline u32 /* units of 100MHz */
242 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
243 const struct intel_crtc_state *pipe_config)
245 if (HAS_DDI(dev_priv))
246 return pipe_config->port_clock; /* SPLL */
248 return dev_priv->fdi_pll_freq;
251 static const struct intel_limit intel_limits_i8xx_dac = {
252 .dot = { .min = 25000, .max = 350000 },
253 .vco = { .min = 908000, .max = 1512000 },
254 .n = { .min = 2, .max = 16 },
255 .m = { .min = 96, .max = 140 },
256 .m1 = { .min = 18, .max = 26 },
257 .m2 = { .min = 6, .max = 16 },
258 .p = { .min = 4, .max = 128 },
259 .p1 = { .min = 2, .max = 33 },
260 .p2 = { .dot_limit = 165000,
261 .p2_slow = 4, .p2_fast = 2 },
264 static const struct intel_limit intel_limits_i8xx_dvo = {
265 .dot = { .min = 25000, .max = 350000 },
266 .vco = { .min = 908000, .max = 1512000 },
267 .n = { .min = 2, .max = 16 },
268 .m = { .min = 96, .max = 140 },
269 .m1 = { .min = 18, .max = 26 },
270 .m2 = { .min = 6, .max = 16 },
271 .p = { .min = 4, .max = 128 },
272 .p1 = { .min = 2, .max = 33 },
273 .p2 = { .dot_limit = 165000,
274 .p2_slow = 4, .p2_fast = 4 },
277 static const struct intel_limit intel_limits_i8xx_lvds = {
278 .dot = { .min = 25000, .max = 350000 },
279 .vco = { .min = 908000, .max = 1512000 },
280 .n = { .min = 2, .max = 16 },
281 .m = { .min = 96, .max = 140 },
282 .m1 = { .min = 18, .max = 26 },
283 .m2 = { .min = 6, .max = 16 },
284 .p = { .min = 4, .max = 128 },
285 .p1 = { .min = 1, .max = 6 },
286 .p2 = { .dot_limit = 165000,
287 .p2_slow = 14, .p2_fast = 7 },
290 static const struct intel_limit intel_limits_i9xx_sdvo = {
291 .dot = { .min = 20000, .max = 400000 },
292 .vco = { .min = 1400000, .max = 2800000 },
293 .n = { .min = 1, .max = 6 },
294 .m = { .min = 70, .max = 120 },
295 .m1 = { .min = 8, .max = 18 },
296 .m2 = { .min = 3, .max = 7 },
297 .p = { .min = 5, .max = 80 },
298 .p1 = { .min = 1, .max = 8 },
299 .p2 = { .dot_limit = 200000,
300 .p2_slow = 10, .p2_fast = 5 },
303 static const struct intel_limit intel_limits_i9xx_lvds = {
304 .dot = { .min = 20000, .max = 400000 },
305 .vco = { .min = 1400000, .max = 2800000 },
306 .n = { .min = 1, .max = 6 },
307 .m = { .min = 70, .max = 120 },
308 .m1 = { .min = 8, .max = 18 },
309 .m2 = { .min = 3, .max = 7 },
310 .p = { .min = 7, .max = 98 },
311 .p1 = { .min = 1, .max = 8 },
312 .p2 = { .dot_limit = 112000,
313 .p2_slow = 14, .p2_fast = 7 },
317 static const struct intel_limit intel_limits_g4x_sdvo = {
318 .dot = { .min = 25000, .max = 270000 },
319 .vco = { .min = 1750000, .max = 3500000},
320 .n = { .min = 1, .max = 4 },
321 .m = { .min = 104, .max = 138 },
322 .m1 = { .min = 17, .max = 23 },
323 .m2 = { .min = 5, .max = 11 },
324 .p = { .min = 10, .max = 30 },
325 .p1 = { .min = 1, .max = 3},
326 .p2 = { .dot_limit = 270000,
332 static const struct intel_limit intel_limits_g4x_hdmi = {
333 .dot = { .min = 22000, .max = 400000 },
334 .vco = { .min = 1750000, .max = 3500000},
335 .n = { .min = 1, .max = 4 },
336 .m = { .min = 104, .max = 138 },
337 .m1 = { .min = 16, .max = 23 },
338 .m2 = { .min = 5, .max = 11 },
339 .p = { .min = 5, .max = 80 },
340 .p1 = { .min = 1, .max = 8},
341 .p2 = { .dot_limit = 165000,
342 .p2_slow = 10, .p2_fast = 5 },
345 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
346 .dot = { .min = 20000, .max = 115000 },
347 .vco = { .min = 1750000, .max = 3500000 },
348 .n = { .min = 1, .max = 3 },
349 .m = { .min = 104, .max = 138 },
350 .m1 = { .min = 17, .max = 23 },
351 .m2 = { .min = 5, .max = 11 },
352 .p = { .min = 28, .max = 112 },
353 .p1 = { .min = 2, .max = 8 },
354 .p2 = { .dot_limit = 0,
355 .p2_slow = 14, .p2_fast = 14
359 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
360 .dot = { .min = 80000, .max = 224000 },
361 .vco = { .min = 1750000, .max = 3500000 },
362 .n = { .min = 1, .max = 3 },
363 .m = { .min = 104, .max = 138 },
364 .m1 = { .min = 17, .max = 23 },
365 .m2 = { .min = 5, .max = 11 },
366 .p = { .min = 14, .max = 42 },
367 .p1 = { .min = 2, .max = 6 },
368 .p2 = { .dot_limit = 0,
369 .p2_slow = 7, .p2_fast = 7
373 static const struct intel_limit pnv_limits_sdvo = {
374 .dot = { .min = 20000, .max = 400000},
375 .vco = { .min = 1700000, .max = 3500000 },
376 /* Pineview's Ncounter is a ring counter */
377 .n = { .min = 3, .max = 6 },
378 .m = { .min = 2, .max = 256 },
379 /* Pineview only has one combined m divider, which we treat as m2. */
380 .m1 = { .min = 0, .max = 0 },
381 .m2 = { .min = 0, .max = 254 },
382 .p = { .min = 5, .max = 80 },
383 .p1 = { .min = 1, .max = 8 },
384 .p2 = { .dot_limit = 200000,
385 .p2_slow = 10, .p2_fast = 5 },
388 static const struct intel_limit pnv_limits_lvds = {
389 .dot = { .min = 20000, .max = 400000 },
390 .vco = { .min = 1700000, .max = 3500000 },
391 .n = { .min = 3, .max = 6 },
392 .m = { .min = 2, .max = 256 },
393 .m1 = { .min = 0, .max = 0 },
394 .m2 = { .min = 0, .max = 254 },
395 .p = { .min = 7, .max = 112 },
396 .p1 = { .min = 1, .max = 8 },
397 .p2 = { .dot_limit = 112000,
398 .p2_slow = 14, .p2_fast = 14 },
401 /* Ironlake / Sandybridge
403 * We calculate clock using (register_value + 2) for N/M1/M2, so here
404 * the range value for them is (actual_value - 2).
406 static const struct intel_limit ilk_limits_dac = {
407 .dot = { .min = 25000, .max = 350000 },
408 .vco = { .min = 1760000, .max = 3510000 },
409 .n = { .min = 1, .max = 5 },
410 .m = { .min = 79, .max = 127 },
411 .m1 = { .min = 12, .max = 22 },
412 .m2 = { .min = 5, .max = 9 },
413 .p = { .min = 5, .max = 80 },
414 .p1 = { .min = 1, .max = 8 },
415 .p2 = { .dot_limit = 225000,
416 .p2_slow = 10, .p2_fast = 5 },
419 static const struct intel_limit ilk_limits_single_lvds = {
420 .dot = { .min = 25000, .max = 350000 },
421 .vco = { .min = 1760000, .max = 3510000 },
422 .n = { .min = 1, .max = 3 },
423 .m = { .min = 79, .max = 118 },
424 .m1 = { .min = 12, .max = 22 },
425 .m2 = { .min = 5, .max = 9 },
426 .p = { .min = 28, .max = 112 },
427 .p1 = { .min = 2, .max = 8 },
428 .p2 = { .dot_limit = 225000,
429 .p2_slow = 14, .p2_fast = 14 },
432 static const struct intel_limit ilk_limits_dual_lvds = {
433 .dot = { .min = 25000, .max = 350000 },
434 .vco = { .min = 1760000, .max = 3510000 },
435 .n = { .min = 1, .max = 3 },
436 .m = { .min = 79, .max = 127 },
437 .m1 = { .min = 12, .max = 22 },
438 .m2 = { .min = 5, .max = 9 },
439 .p = { .min = 14, .max = 56 },
440 .p1 = { .min = 2, .max = 8 },
441 .p2 = { .dot_limit = 225000,
442 .p2_slow = 7, .p2_fast = 7 },
445 /* LVDS 100mhz refclk limits. */
446 static const struct intel_limit ilk_limits_single_lvds_100m = {
447 .dot = { .min = 25000, .max = 350000 },
448 .vco = { .min = 1760000, .max = 3510000 },
449 .n = { .min = 1, .max = 2 },
450 .m = { .min = 79, .max = 126 },
451 .m1 = { .min = 12, .max = 22 },
452 .m2 = { .min = 5, .max = 9 },
453 .p = { .min = 28, .max = 112 },
454 .p1 = { .min = 2, .max = 8 },
455 .p2 = { .dot_limit = 225000,
456 .p2_slow = 14, .p2_fast = 14 },
459 static const struct intel_limit ilk_limits_dual_lvds_100m = {
460 .dot = { .min = 25000, .max = 350000 },
461 .vco = { .min = 1760000, .max = 3510000 },
462 .n = { .min = 1, .max = 3 },
463 .m = { .min = 79, .max = 126 },
464 .m1 = { .min = 12, .max = 22 },
465 .m2 = { .min = 5, .max = 9 },
466 .p = { .min = 14, .max = 42 },
467 .p1 = { .min = 2, .max = 6 },
468 .p2 = { .dot_limit = 225000,
469 .p2_slow = 7, .p2_fast = 7 },
472 static const struct intel_limit intel_limits_vlv = {
474 * These are the data rate limits (measured in fast clocks)
475 * since those are the strictest limits we have. The fast
476 * clock and actual rate limits are more relaxed, so checking
477 * them would make no difference.
479 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
480 .vco = { .min = 4000000, .max = 6000000 },
481 .n = { .min = 1, .max = 7 },
482 .m1 = { .min = 2, .max = 3 },
483 .m2 = { .min = 11, .max = 156 },
484 .p1 = { .min = 2, .max = 3 },
485 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
488 static const struct intel_limit intel_limits_chv = {
490 * These are the data rate limits (measured in fast clocks)
491 * since those are the strictest limits we have. The fast
492 * clock and actual rate limits are more relaxed, so checking
493 * them would make no difference.
495 .dot = { .min = 25000 * 5, .max = 540000 * 5},
496 .vco = { .min = 4800000, .max = 6480000 },
497 .n = { .min = 1, .max = 1 },
498 .m1 = { .min = 2, .max = 2 },
499 .m2 = { .min = 24 << 22, .max = 175 << 22 },
500 .p1 = { .min = 2, .max = 4 },
501 .p2 = { .p2_slow = 1, .p2_fast = 14 },
504 static const struct intel_limit intel_limits_bxt = {
505 /* FIXME: find real dot limits */
506 .dot = { .min = 0, .max = INT_MAX },
507 .vco = { .min = 4800000, .max = 6700000 },
508 .n = { .min = 1, .max = 1 },
509 .m1 = { .min = 2, .max = 2 },
510 /* FIXME: find real m2 limits */
511 .m2 = { .min = 2 << 22, .max = 255 << 22 },
512 .p1 = { .min = 2, .max = 4 },
513 .p2 = { .p2_slow = 1, .p2_fast = 20 },
516 /* WA Display #0827: Gen9:all */
518 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
521 I915_WRITE(CLKGATE_DIS_PSL(pipe),
522 I915_READ(CLKGATE_DIS_PSL(pipe)) |
523 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
525 I915_WRITE(CLKGATE_DIS_PSL(pipe),
526 I915_READ(CLKGATE_DIS_PSL(pipe)) &
527 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
530 /* Wa_2006604312:icl */
532 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
536 I915_WRITE(CLKGATE_DIS_PSL(pipe),
537 I915_READ(CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
539 I915_WRITE(CLKGATE_DIS_PSL(pipe),
540 I915_READ(CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
544 needs_modeset(const struct intel_crtc_state *state)
546 return drm_atomic_crtc_needs_modeset(&state->uapi);
550 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
552 return (crtc_state->master_transcoder != INVALID_TRANSCODER ||
553 crtc_state->sync_mode_slaves_mask);
557 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
559 return (crtc_state->master_transcoder == INVALID_TRANSCODER &&
560 crtc_state->sync_mode_slaves_mask);
564 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
566 return crtc_state->master_transcoder != INVALID_TRANSCODER;
570 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
571 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
572 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
573 * The helpers' return value is the rate of the clock that is fed to the
574 * display engine's pipe which can be the above fast dot clock rate or a
575 * divided-down version of it.
577 /* m1 is reserved as 0 in Pineview, n is a ring counter */
578 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
580 clock->m = clock->m2 + 2;
581 clock->p = clock->p1 * clock->p2;
582 if (WARN_ON(clock->n == 0 || clock->p == 0))
584 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
585 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
590 static u32 i9xx_dpll_compute_m(struct dpll *dpll)
592 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
595 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
597 clock->m = i9xx_dpll_compute_m(clock);
598 clock->p = clock->p1 * clock->p2;
599 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
601 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
602 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
607 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
609 clock->m = clock->m1 * clock->m2;
610 clock->p = clock->p1 * clock->p2;
611 if (WARN_ON(clock->n == 0 || clock->p == 0))
613 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
614 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
616 return clock->dot / 5;
619 int chv_calc_dpll_params(int refclk, struct dpll *clock)
621 clock->m = clock->m1 * clock->m2;
622 clock->p = clock->p1 * clock->p2;
623 if (WARN_ON(clock->n == 0 || clock->p == 0))
625 clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
627 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
629 return clock->dot / 5;
632 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
635 * Returns whether the given set of divisors are valid for a given refclk with
636 * the given connectors.
638 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
639 const struct intel_limit *limit,
640 const struct dpll *clock)
642 if (clock->n < limit->n.min || limit->n.max < clock->n)
643 INTELPllInvalid("n out of range\n");
644 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
645 INTELPllInvalid("p1 out of range\n");
646 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
647 INTELPllInvalid("m2 out of range\n");
648 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
649 INTELPllInvalid("m1 out of range\n");
651 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
652 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
653 if (clock->m1 <= clock->m2)
654 INTELPllInvalid("m1 <= m2\n");
656 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
657 !IS_GEN9_LP(dev_priv)) {
658 if (clock->p < limit->p.min || limit->p.max < clock->p)
659 INTELPllInvalid("p out of range\n");
660 if (clock->m < limit->m.min || limit->m.max < clock->m)
661 INTELPllInvalid("m out of range\n");
664 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
665 INTELPllInvalid("vco out of range\n");
666 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
667 * connector, etc., rather than just a single range.
669 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
670 INTELPllInvalid("dot out of range\n");
676 i9xx_select_p2_div(const struct intel_limit *limit,
677 const struct intel_crtc_state *crtc_state,
680 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
682 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
684 * For LVDS just rely on its current settings for dual-channel.
685 * We haven't figured out how to reliably set up different
686 * single/dual channel state, if we even can.
688 if (intel_is_dual_link_lvds(dev_priv))
689 return limit->p2.p2_fast;
691 return limit->p2.p2_slow;
693 if (target < limit->p2.dot_limit)
694 return limit->p2.p2_slow;
696 return limit->p2.p2_fast;
701 * Returns a set of divisors for the desired target clock with the given
702 * refclk, or FALSE. The returned values represent the clock equation:
703 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
705 * Target and reference clocks are specified in kHz.
707 * If match_clock is provided, then best_clock P divider must match the P
708 * divider from @match_clock used for LVDS downclocking.
711 i9xx_find_best_dpll(const struct intel_limit *limit,
712 struct intel_crtc_state *crtc_state,
713 int target, int refclk, struct dpll *match_clock,
714 struct dpll *best_clock)
716 struct drm_device *dev = crtc_state->uapi.crtc->dev;
720 memset(best_clock, 0, sizeof(*best_clock));
722 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
724 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
726 for (clock.m2 = limit->m2.min;
727 clock.m2 <= limit->m2.max; clock.m2++) {
728 if (clock.m2 >= clock.m1)
730 for (clock.n = limit->n.min;
731 clock.n <= limit->n.max; clock.n++) {
732 for (clock.p1 = limit->p1.min;
733 clock.p1 <= limit->p1.max; clock.p1++) {
736 i9xx_calc_dpll_params(refclk, &clock);
737 if (!intel_PLL_is_valid(to_i915(dev),
742 clock.p != match_clock->p)
745 this_err = abs(clock.dot - target);
746 if (this_err < err) {
755 return (err != target);
759 * Returns a set of divisors for the desired target clock with the given
760 * refclk, or FALSE. The returned values represent the clock equation:
761 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
763 * Target and reference clocks are specified in kHz.
765 * If match_clock is provided, then best_clock P divider must match the P
766 * divider from @match_clock used for LVDS downclocking.
769 pnv_find_best_dpll(const struct intel_limit *limit,
770 struct intel_crtc_state *crtc_state,
771 int target, int refclk, struct dpll *match_clock,
772 struct dpll *best_clock)
774 struct drm_device *dev = crtc_state->uapi.crtc->dev;
778 memset(best_clock, 0, sizeof(*best_clock));
780 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
782 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
784 for (clock.m2 = limit->m2.min;
785 clock.m2 <= limit->m2.max; clock.m2++) {
786 for (clock.n = limit->n.min;
787 clock.n <= limit->n.max; clock.n++) {
788 for (clock.p1 = limit->p1.min;
789 clock.p1 <= limit->p1.max; clock.p1++) {
792 pnv_calc_dpll_params(refclk, &clock);
793 if (!intel_PLL_is_valid(to_i915(dev),
798 clock.p != match_clock->p)
801 this_err = abs(clock.dot - target);
802 if (this_err < err) {
811 return (err != target);
815 * Returns a set of divisors for the desired target clock with the given
816 * refclk, or FALSE. The returned values represent the clock equation:
817 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
819 * Target and reference clocks are specified in kHz.
821 * If match_clock is provided, then best_clock P divider must match the P
822 * divider from @match_clock used for LVDS downclocking.
825 g4x_find_best_dpll(const struct intel_limit *limit,
826 struct intel_crtc_state *crtc_state,
827 int target, int refclk, struct dpll *match_clock,
828 struct dpll *best_clock)
830 struct drm_device *dev = crtc_state->uapi.crtc->dev;
834 /* approximately equals target * 0.00585 */
835 int err_most = (target >> 8) + (target >> 9);
837 memset(best_clock, 0, sizeof(*best_clock));
839 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
841 max_n = limit->n.max;
842 /* based on hardware requirement, prefer smaller n to precision */
843 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
844 /* based on hardware requirement, prefere larger m1,m2 */
845 for (clock.m1 = limit->m1.max;
846 clock.m1 >= limit->m1.min; clock.m1--) {
847 for (clock.m2 = limit->m2.max;
848 clock.m2 >= limit->m2.min; clock.m2--) {
849 for (clock.p1 = limit->p1.max;
850 clock.p1 >= limit->p1.min; clock.p1--) {
853 i9xx_calc_dpll_params(refclk, &clock);
854 if (!intel_PLL_is_valid(to_i915(dev),
859 this_err = abs(clock.dot - target);
860 if (this_err < err_most) {
874 * Check if the calculated PLL configuration is more optimal compared to the
875 * best configuration and error found so far. Return the calculated error.
877 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
878 const struct dpll *calculated_clock,
879 const struct dpll *best_clock,
880 unsigned int best_error_ppm,
881 unsigned int *error_ppm)
884 * For CHV ignore the error and consider only the P value.
885 * Prefer a bigger P value based on HW requirements.
887 if (IS_CHERRYVIEW(to_i915(dev))) {
890 return calculated_clock->p > best_clock->p;
893 if (WARN_ON_ONCE(!target_freq))
896 *error_ppm = div_u64(1000000ULL *
897 abs(target_freq - calculated_clock->dot),
900 * Prefer a better P value over a better (smaller) error if the error
901 * is small. Ensure this preference for future configurations too by
902 * setting the error to 0.
904 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
910 return *error_ppm + 10 < best_error_ppm;
914 * Returns a set of divisors for the desired target clock with the given
915 * refclk, or FALSE. The returned values represent the clock equation:
916 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
919 vlv_find_best_dpll(const struct intel_limit *limit,
920 struct intel_crtc_state *crtc_state,
921 int target, int refclk, struct dpll *match_clock,
922 struct dpll *best_clock)
924 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
925 struct drm_device *dev = crtc->base.dev;
927 unsigned int bestppm = 1000000;
928 /* min update 19.2 MHz */
929 int max_n = min(limit->n.max, refclk / 19200);
932 target *= 5; /* fast clock */
934 memset(best_clock, 0, sizeof(*best_clock));
936 /* based on hardware requirement, prefer smaller n to precision */
937 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
938 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
939 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
940 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
941 clock.p = clock.p1 * clock.p2;
942 /* based on hardware requirement, prefer bigger m1,m2 values */
943 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
946 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
949 vlv_calc_dpll_params(refclk, &clock);
951 if (!intel_PLL_is_valid(to_i915(dev),
956 if (!vlv_PLL_is_optimal(dev, target,
974 * Returns a set of divisors for the desired target clock with the given
975 * refclk, or FALSE. The returned values represent the clock equation:
976 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
979 chv_find_best_dpll(const struct intel_limit *limit,
980 struct intel_crtc_state *crtc_state,
981 int target, int refclk, struct dpll *match_clock,
982 struct dpll *best_clock)
984 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
985 struct drm_device *dev = crtc->base.dev;
986 unsigned int best_error_ppm;
991 memset(best_clock, 0, sizeof(*best_clock));
992 best_error_ppm = 1000000;
995 * Based on hardware doc, the n always set to 1, and m1 always
996 * set to 2. If requires to support 200Mhz refclk, we need to
997 * revisit this because n may not 1 anymore.
999 clock.n = 1, clock.m1 = 2;
1000 target *= 5; /* fast clock */
1002 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
1003 for (clock.p2 = limit->p2.p2_fast;
1004 clock.p2 >= limit->p2.p2_slow;
1005 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
1006 unsigned int error_ppm;
1008 clock.p = clock.p1 * clock.p2;
1010 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
1013 if (m2 > INT_MAX/clock.m1)
1018 chv_calc_dpll_params(refclk, &clock);
1020 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
1023 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
1024 best_error_ppm, &error_ppm))
1027 *best_clock = clock;
1028 best_error_ppm = error_ppm;
1036 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
1037 struct dpll *best_clock)
1039 int refclk = 100000;
1040 const struct intel_limit *limit = &intel_limits_bxt;
1042 return chv_find_best_dpll(limit, crtc_state,
1043 crtc_state->port_clock, refclk,
1047 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1050 i915_reg_t reg = PIPEDSL(pipe);
1054 if (IS_GEN(dev_priv, 2))
1055 line_mask = DSL_LINEMASK_GEN2;
1057 line_mask = DSL_LINEMASK_GEN3;
1059 line1 = I915_READ(reg) & line_mask;
1061 line2 = I915_READ(reg) & line_mask;
1063 return line1 != line2;
1066 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1068 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1069 enum pipe pipe = crtc->pipe;
1071 /* Wait for the display line to settle/start moving */
1072 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1073 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1074 pipe_name(pipe), onoff(state));
1077 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1079 wait_for_pipe_scanline_moving(crtc, false);
1082 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1084 wait_for_pipe_scanline_moving(crtc, true);
1088 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1090 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1091 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1093 if (INTEL_GEN(dev_priv) >= 4) {
1094 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1095 i915_reg_t reg = PIPECONF(cpu_transcoder);
1097 /* Wait for the Pipe State to go off */
1098 if (intel_de_wait_for_clear(dev_priv, reg,
1099 I965_PIPECONF_ACTIVE, 100))
1100 WARN(1, "pipe_off wait timed out\n");
1102 intel_wait_for_pipe_scanline_stopped(crtc);
1106 /* Only for pre-ILK configs */
1107 void assert_pll(struct drm_i915_private *dev_priv,
1108 enum pipe pipe, bool state)
1113 val = I915_READ(DPLL(pipe));
1114 cur_state = !!(val & DPLL_VCO_ENABLE);
1115 I915_STATE_WARN(cur_state != state,
1116 "PLL state assertion failure (expected %s, current %s)\n",
1117 onoff(state), onoff(cur_state));
1120 /* XXX: the dsi pll is shared between MIPI DSI ports */
1121 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1126 vlv_cck_get(dev_priv);
1127 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1128 vlv_cck_put(dev_priv);
1130 cur_state = val & DSI_PLL_VCO_EN;
1131 I915_STATE_WARN(cur_state != state,
1132 "DSI PLL state assertion failure (expected %s, current %s)\n",
1133 onoff(state), onoff(cur_state));
1136 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1137 enum pipe pipe, bool state)
1141 if (HAS_DDI(dev_priv)) {
1143 * DDI does not have a specific FDI_TX register.
1145 * FDI is never fed from EDP transcoder
1146 * so pipe->transcoder cast is fine here.
1148 enum transcoder cpu_transcoder = (enum transcoder)pipe;
1149 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1150 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1152 u32 val = I915_READ(FDI_TX_CTL(pipe));
1153 cur_state = !!(val & FDI_TX_ENABLE);
1155 I915_STATE_WARN(cur_state != state,
1156 "FDI TX state assertion failure (expected %s, current %s)\n",
1157 onoff(state), onoff(cur_state));
1159 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1160 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1162 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1163 enum pipe pipe, bool state)
1168 val = I915_READ(FDI_RX_CTL(pipe));
1169 cur_state = !!(val & FDI_RX_ENABLE);
1170 I915_STATE_WARN(cur_state != state,
1171 "FDI RX state assertion failure (expected %s, current %s)\n",
1172 onoff(state), onoff(cur_state));
1174 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1175 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1177 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1182 /* ILK FDI PLL is always enabled */
1183 if (IS_GEN(dev_priv, 5))
1186 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1187 if (HAS_DDI(dev_priv))
1190 val = I915_READ(FDI_TX_CTL(pipe));
1191 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1194 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1195 enum pipe pipe, bool state)
1200 val = I915_READ(FDI_RX_CTL(pipe));
1201 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1202 I915_STATE_WARN(cur_state != state,
1203 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1204 onoff(state), onoff(cur_state));
1207 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1211 enum pipe panel_pipe = INVALID_PIPE;
1214 if (WARN_ON(HAS_DDI(dev_priv)))
1217 if (HAS_PCH_SPLIT(dev_priv)) {
1220 pp_reg = PP_CONTROL(0);
1221 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1224 case PANEL_PORT_SELECT_LVDS:
1225 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1227 case PANEL_PORT_SELECT_DPA:
1228 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1230 case PANEL_PORT_SELECT_DPC:
1231 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1233 case PANEL_PORT_SELECT_DPD:
1234 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1237 MISSING_CASE(port_sel);
1240 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1241 /* presumably write lock depends on pipe, not port select */
1242 pp_reg = PP_CONTROL(pipe);
1247 pp_reg = PP_CONTROL(0);
1248 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1250 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1251 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1254 val = I915_READ(pp_reg);
1255 if (!(val & PANEL_POWER_ON) ||
1256 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1259 I915_STATE_WARN(panel_pipe == pipe && locked,
1260 "panel assertion failure, pipe %c regs locked\n",
1264 void assert_pipe(struct drm_i915_private *dev_priv,
1265 enum transcoder cpu_transcoder, bool state)
1268 enum intel_display_power_domain power_domain;
1269 intel_wakeref_t wakeref;
1271 /* we keep both pipes enabled on 830 */
1272 if (IS_I830(dev_priv))
1275 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1276 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1278 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1279 cur_state = !!(val & PIPECONF_ENABLE);
1281 intel_display_power_put(dev_priv, power_domain, wakeref);
1286 I915_STATE_WARN(cur_state != state,
1287 "transcoder %s assertion failure (expected %s, current %s)\n",
1288 transcoder_name(cpu_transcoder),
1289 onoff(state), onoff(cur_state));
1292 static void assert_plane(struct intel_plane *plane, bool state)
1297 cur_state = plane->get_hw_state(plane, &pipe);
1299 I915_STATE_WARN(cur_state != state,
1300 "%s assertion failure (expected %s, current %s)\n",
1301 plane->base.name, onoff(state), onoff(cur_state));
1304 #define assert_plane_enabled(p) assert_plane(p, true)
1305 #define assert_plane_disabled(p) assert_plane(p, false)
1307 static void assert_planes_disabled(struct intel_crtc *crtc)
1309 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1310 struct intel_plane *plane;
1312 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1313 assert_plane_disabled(plane);
1316 static void assert_vblank_disabled(struct drm_crtc *crtc)
1318 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1319 drm_crtc_vblank_put(crtc);
1322 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1328 val = I915_READ(PCH_TRANSCONF(pipe));
1329 enabled = !!(val & TRANS_ENABLE);
1330 I915_STATE_WARN(enabled,
1331 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1335 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1336 enum pipe pipe, enum port port,
1339 enum pipe port_pipe;
1342 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1344 I915_STATE_WARN(state && port_pipe == pipe,
1345 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1346 port_name(port), pipe_name(pipe));
1348 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1349 "IBX PCH DP %c still using transcoder B\n",
1353 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1354 enum pipe pipe, enum port port,
1355 i915_reg_t hdmi_reg)
1357 enum pipe port_pipe;
1360 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1362 I915_STATE_WARN(state && port_pipe == pipe,
1363 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1364 port_name(port), pipe_name(pipe));
1366 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1367 "IBX PCH HDMI %c still using transcoder B\n",
1371 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1374 enum pipe port_pipe;
1376 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1377 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1378 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1380 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1382 "PCH VGA enabled on transcoder %c, should be disabled\n",
1385 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1387 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1390 /* PCH SDVOB multiplex with HDMIB */
1391 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1392 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1393 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1396 static void _vlv_enable_pll(struct intel_crtc *crtc,
1397 const struct intel_crtc_state *pipe_config)
1399 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1400 enum pipe pipe = crtc->pipe;
1402 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1403 POSTING_READ(DPLL(pipe));
1406 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1407 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1410 static void vlv_enable_pll(struct intel_crtc *crtc,
1411 const struct intel_crtc_state *pipe_config)
1413 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1414 enum pipe pipe = crtc->pipe;
1416 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1418 /* PLL is protected by panel, make sure we can write it */
1419 assert_panel_unlocked(dev_priv, pipe);
1421 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1422 _vlv_enable_pll(crtc, pipe_config);
1424 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1425 POSTING_READ(DPLL_MD(pipe));
1429 static void _chv_enable_pll(struct intel_crtc *crtc,
1430 const struct intel_crtc_state *pipe_config)
1432 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1433 enum pipe pipe = crtc->pipe;
1434 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1437 vlv_dpio_get(dev_priv);
1439 /* Enable back the 10bit clock to display controller */
1440 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1441 tmp |= DPIO_DCLKP_EN;
1442 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1444 vlv_dpio_put(dev_priv);
1447 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1452 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1454 /* Check PLL is locked */
1455 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1456 DRM_ERROR("PLL %d failed to lock\n", pipe);
1459 static void chv_enable_pll(struct intel_crtc *crtc,
1460 const struct intel_crtc_state *pipe_config)
1462 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1463 enum pipe pipe = crtc->pipe;
1465 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1467 /* PLL is protected by panel, make sure we can write it */
1468 assert_panel_unlocked(dev_priv, pipe);
1470 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1471 _chv_enable_pll(crtc, pipe_config);
1473 if (pipe != PIPE_A) {
1475 * WaPixelRepeatModeFixForC0:chv
1477 * DPLLCMD is AWOL. Use chicken bits to propagate
1478 * the value from DPLLBMD to either pipe B or C.
1480 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1481 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1482 I915_WRITE(CBR4_VLV, 0);
1483 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1486 * DPLLB VGA mode also seems to cause problems.
1487 * We should always have it disabled.
1489 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1491 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1492 POSTING_READ(DPLL_MD(pipe));
1496 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1498 if (IS_I830(dev_priv))
1501 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1504 static void i9xx_enable_pll(struct intel_crtc *crtc,
1505 const struct intel_crtc_state *crtc_state)
1507 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1508 i915_reg_t reg = DPLL(crtc->pipe);
1509 u32 dpll = crtc_state->dpll_hw_state.dpll;
1512 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1514 /* PLL is protected by panel, make sure we can write it */
1515 if (i9xx_has_pps(dev_priv))
1516 assert_panel_unlocked(dev_priv, crtc->pipe);
1519 * Apparently we need to have VGA mode enabled prior to changing
1520 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1521 * dividers, even though the register value does change.
1523 I915_WRITE(reg, dpll & ~DPLL_VGA_MODE_DIS);
1524 I915_WRITE(reg, dpll);
1526 /* Wait for the clocks to stabilize. */
1530 if (INTEL_GEN(dev_priv) >= 4) {
1531 I915_WRITE(DPLL_MD(crtc->pipe),
1532 crtc_state->dpll_hw_state.dpll_md);
1534 /* The pixel multiplier can only be updated once the
1535 * DPLL is enabled and the clocks are stable.
1537 * So write it again.
1539 I915_WRITE(reg, dpll);
1542 /* We do this three times for luck */
1543 for (i = 0; i < 3; i++) {
1544 I915_WRITE(reg, dpll);
1546 udelay(150); /* wait for warmup */
1550 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1552 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1553 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1554 enum pipe pipe = crtc->pipe;
1556 /* Don't disable pipe or pipe PLLs if needed */
1557 if (IS_I830(dev_priv))
1560 /* Make sure the pipe isn't still relying on us */
1561 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1563 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1564 POSTING_READ(DPLL(pipe));
1567 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1571 /* Make sure the pipe isn't still relying on us */
1572 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1574 val = DPLL_INTEGRATED_REF_CLK_VLV |
1575 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1577 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1579 I915_WRITE(DPLL(pipe), val);
1580 POSTING_READ(DPLL(pipe));
1583 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1585 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1588 /* Make sure the pipe isn't still relying on us */
1589 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1591 val = DPLL_SSC_REF_CLK_CHV |
1592 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1594 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1596 I915_WRITE(DPLL(pipe), val);
1597 POSTING_READ(DPLL(pipe));
1599 vlv_dpio_get(dev_priv);
1601 /* Disable 10bit clock to display controller */
1602 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1603 val &= ~DPIO_DCLKP_EN;
1604 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1606 vlv_dpio_put(dev_priv);
1609 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1610 struct intel_digital_port *dport,
1611 unsigned int expected_mask)
1614 i915_reg_t dpll_reg;
1616 switch (dport->base.port) {
1618 port_mask = DPLL_PORTB_READY_MASK;
1622 port_mask = DPLL_PORTC_READY_MASK;
1624 expected_mask <<= 4;
1627 port_mask = DPLL_PORTD_READY_MASK;
1628 dpll_reg = DPIO_PHY_STATUS;
1634 if (intel_de_wait_for_register(dev_priv, dpll_reg,
1635 port_mask, expected_mask, 1000))
1636 WARN(1, "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
1637 dport->base.base.base.id, dport->base.base.name,
1638 I915_READ(dpll_reg) & port_mask, expected_mask);
1641 static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1643 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1644 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1645 enum pipe pipe = crtc->pipe;
1647 u32 val, pipeconf_val;
1649 /* Make sure PCH DPLL is enabled */
1650 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1652 /* FDI must be feeding us bits for PCH ports */
1653 assert_fdi_tx_enabled(dev_priv, pipe);
1654 assert_fdi_rx_enabled(dev_priv, pipe);
1656 if (HAS_PCH_CPT(dev_priv)) {
1657 reg = TRANS_CHICKEN2(pipe);
1658 val = I915_READ(reg);
1660 * Workaround: Set the timing override bit
1661 * before enabling the pch transcoder.
1663 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1664 /* Configure frame start delay to match the CPU */
1665 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1666 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1667 I915_WRITE(reg, val);
1670 reg = PCH_TRANSCONF(pipe);
1671 val = I915_READ(reg);
1672 pipeconf_val = I915_READ(PIPECONF(pipe));
1674 if (HAS_PCH_IBX(dev_priv)) {
1675 /* Configure frame start delay to match the CPU */
1676 val &= ~TRANS_FRAME_START_DELAY_MASK;
1677 val |= TRANS_FRAME_START_DELAY(0);
1680 * Make the BPC in transcoder be consistent with
1681 * that in pipeconf reg. For HDMI we must use 8bpc
1682 * here for both 8bpc and 12bpc.
1684 val &= ~PIPECONF_BPC_MASK;
1685 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1686 val |= PIPECONF_8BPC;
1688 val |= pipeconf_val & PIPECONF_BPC_MASK;
1691 val &= ~TRANS_INTERLACE_MASK;
1692 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
1693 if (HAS_PCH_IBX(dev_priv) &&
1694 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1695 val |= TRANS_LEGACY_INTERLACED_ILK;
1697 val |= TRANS_INTERLACED;
1699 val |= TRANS_PROGRESSIVE;
1702 I915_WRITE(reg, val | TRANS_ENABLE);
1703 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
1704 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1707 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1708 enum transcoder cpu_transcoder)
1710 u32 val, pipeconf_val;
1712 /* FDI must be feeding us bits for PCH ports */
1713 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1714 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1716 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1717 /* Workaround: set timing override bit. */
1718 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1719 /* Configure frame start delay to match the CPU */
1720 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1721 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1722 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1725 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1727 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1728 PIPECONF_INTERLACED_ILK)
1729 val |= TRANS_INTERLACED;
1731 val |= TRANS_PROGRESSIVE;
1733 I915_WRITE(LPT_TRANSCONF, val);
1734 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
1735 TRANS_STATE_ENABLE, 100))
1736 DRM_ERROR("Failed to enable PCH transcoder\n");
1739 static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1745 /* FDI relies on the transcoder */
1746 assert_fdi_tx_disabled(dev_priv, pipe);
1747 assert_fdi_rx_disabled(dev_priv, pipe);
1749 /* Ports must be off as well */
1750 assert_pch_ports_disabled(dev_priv, pipe);
1752 reg = PCH_TRANSCONF(pipe);
1753 val = I915_READ(reg);
1754 val &= ~TRANS_ENABLE;
1755 I915_WRITE(reg, val);
1756 /* wait for PCH transcoder off, transcoder state */
1757 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
1758 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1760 if (HAS_PCH_CPT(dev_priv)) {
1761 /* Workaround: Clear the timing override chicken bit again. */
1762 reg = TRANS_CHICKEN2(pipe);
1763 val = I915_READ(reg);
1764 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1765 I915_WRITE(reg, val);
1769 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1773 val = I915_READ(LPT_TRANSCONF);
1774 val &= ~TRANS_ENABLE;
1775 I915_WRITE(LPT_TRANSCONF, val);
1776 /* wait for PCH transcoder off, transcoder state */
1777 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
1778 TRANS_STATE_ENABLE, 50))
1779 DRM_ERROR("Failed to disable PCH transcoder\n");
1781 /* Workaround: clear timing override bit. */
1782 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1783 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1784 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1787 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1789 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1791 if (HAS_PCH_LPT(dev_priv))
1797 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1799 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1802 * On i965gm the hardware frame counter reads
1803 * zero when the TV encoder is enabled :(
1805 if (IS_I965GM(dev_priv) &&
1806 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1809 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1810 return 0xffffffff; /* full 32 bit counter */
1811 else if (INTEL_GEN(dev_priv) >= 3)
1812 return 0xffffff; /* only 24 bits of frame count */
1814 return 0; /* Gen2 doesn't have a hardware frame counter */
1817 static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1819 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1821 assert_vblank_disabled(&crtc->base);
1822 drm_crtc_set_max_vblank_count(&crtc->base,
1823 intel_crtc_max_vblank_count(crtc_state));
1824 drm_crtc_vblank_on(&crtc->base);
1827 void intel_crtc_vblank_off(const struct intel_crtc_state *crtc_state)
1829 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1831 drm_crtc_vblank_off(&crtc->base);
1832 assert_vblank_disabled(&crtc->base);
1835 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1837 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
1838 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1839 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1840 enum pipe pipe = crtc->pipe;
1844 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1846 assert_planes_disabled(crtc);
1849 * A pipe without a PLL won't actually be able to drive bits from
1850 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1853 if (HAS_GMCH(dev_priv)) {
1854 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1855 assert_dsi_pll_enabled(dev_priv);
1857 assert_pll_enabled(dev_priv, pipe);
1859 if (new_crtc_state->has_pch_encoder) {
1860 /* if driving the PCH, we need FDI enabled */
1861 assert_fdi_rx_pll_enabled(dev_priv,
1862 intel_crtc_pch_transcoder(crtc));
1863 assert_fdi_tx_pll_enabled(dev_priv,
1864 (enum pipe) cpu_transcoder);
1866 /* FIXME: assert CPU port conditions for SNB+ */
1869 trace_intel_pipe_enable(crtc);
1871 reg = PIPECONF(cpu_transcoder);
1872 val = I915_READ(reg);
1873 if (val & PIPECONF_ENABLE) {
1874 /* we keep both pipes enabled on 830 */
1875 WARN_ON(!IS_I830(dev_priv));
1879 I915_WRITE(reg, val | PIPECONF_ENABLE);
1883 * Until the pipe starts PIPEDSL reads will return a stale value,
1884 * which causes an apparent vblank timestamp jump when PIPEDSL
1885 * resets to its proper value. That also messes up the frame count
1886 * when it's derived from the timestamps. So let's wait for the
1887 * pipe to start properly before we call drm_crtc_vblank_on()
1889 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1890 intel_wait_for_pipe_scanline_moving(crtc);
1893 void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1895 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1896 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1897 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1898 enum pipe pipe = crtc->pipe;
1902 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1905 * Make sure planes won't keep trying to pump pixels to us,
1906 * or we might hang the display.
1908 assert_planes_disabled(crtc);
1910 trace_intel_pipe_disable(crtc);
1912 reg = PIPECONF(cpu_transcoder);
1913 val = I915_READ(reg);
1914 if ((val & PIPECONF_ENABLE) == 0)
1918 * Double wide has implications for planes
1919 * so best keep it disabled when not needed.
1921 if (old_crtc_state->double_wide)
1922 val &= ~PIPECONF_DOUBLE_WIDE;
1924 /* Don't disable pipe or pipe PLLs if needed */
1925 if (!IS_I830(dev_priv))
1926 val &= ~PIPECONF_ENABLE;
1928 I915_WRITE(reg, val);
1929 if ((val & PIPECONF_ENABLE) == 0)
1930 intel_wait_for_pipe_off(old_crtc_state);
1933 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1935 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1938 static bool is_ccs_plane(const struct drm_framebuffer *fb, int plane)
1940 if (!is_ccs_modifier(fb->modifier))
1943 return plane >= fb->format->num_planes / 2;
1946 static bool is_gen12_ccs_modifier(u64 modifier)
1948 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS;
1951 static bool is_gen12_ccs_plane(const struct drm_framebuffer *fb, int plane)
1953 return is_gen12_ccs_modifier(fb->modifier) && is_ccs_plane(fb, plane);
1956 static bool is_aux_plane(const struct drm_framebuffer *fb, int plane)
1958 if (is_ccs_modifier(fb->modifier))
1959 return is_ccs_plane(fb, plane);
1964 static int main_to_ccs_plane(const struct drm_framebuffer *fb, int main_plane)
1966 WARN_ON(!is_ccs_modifier(fb->modifier) ||
1967 (main_plane && main_plane >= fb->format->num_planes / 2));
1969 return fb->format->num_planes / 2 + main_plane;
1972 static int ccs_to_main_plane(const struct drm_framebuffer *fb, int ccs_plane)
1974 WARN_ON(!is_ccs_modifier(fb->modifier) ||
1975 ccs_plane < fb->format->num_planes / 2);
1977 return ccs_plane - fb->format->num_planes / 2;
1980 /* Return either the main plane's CCS or - if not a CCS FB - UV plane */
1982 intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane)
1984 if (is_ccs_modifier(fb->modifier))
1985 return main_to_ccs_plane(fb, main_plane);
1991 intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
1994 return info->is_yuv &&
1995 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
1999 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
2001 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2002 unsigned int cpp = fb->format->cpp[color_plane];
2004 switch (fb->modifier) {
2005 case DRM_FORMAT_MOD_LINEAR:
2006 return intel_tile_size(dev_priv);
2007 case I915_FORMAT_MOD_X_TILED:
2008 if (IS_GEN(dev_priv, 2))
2012 case I915_FORMAT_MOD_Y_TILED_CCS:
2013 if (is_ccs_plane(fb, color_plane))
2016 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2017 if (is_ccs_plane(fb, color_plane))
2020 case I915_FORMAT_MOD_Y_TILED:
2021 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
2025 case I915_FORMAT_MOD_Yf_TILED_CCS:
2026 if (is_ccs_plane(fb, color_plane))
2029 case I915_FORMAT_MOD_Yf_TILED:
2045 MISSING_CASE(fb->modifier);
2051 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
2053 if (is_gen12_ccs_plane(fb, color_plane))
2056 return intel_tile_size(to_i915(fb->dev)) /
2057 intel_tile_width_bytes(fb, color_plane);
2060 /* Return the tile dimensions in pixel units */
2061 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
2062 unsigned int *tile_width,
2063 unsigned int *tile_height)
2065 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
2066 unsigned int cpp = fb->format->cpp[color_plane];
2068 *tile_width = tile_width_bytes / cpp;
2069 *tile_height = intel_tile_height(fb, color_plane);
2073 intel_fb_align_height(const struct drm_framebuffer *fb,
2074 int color_plane, unsigned int height)
2076 unsigned int tile_height = intel_tile_height(fb, color_plane);
2078 return ALIGN(height, tile_height);
2081 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2083 unsigned int size = 0;
2086 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2087 size += rot_info->plane[i].width * rot_info->plane[i].height;
2092 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
2094 unsigned int size = 0;
2097 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
2098 size += rem_info->plane[i].width * rem_info->plane[i].height;
2104 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2105 const struct drm_framebuffer *fb,
2106 unsigned int rotation)
2108 view->type = I915_GGTT_VIEW_NORMAL;
2109 if (drm_rotation_90_or_270(rotation)) {
2110 view->type = I915_GGTT_VIEW_ROTATED;
2111 view->rotated = to_intel_framebuffer(fb)->rot_info;
2115 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2117 if (IS_I830(dev_priv))
2119 else if (IS_I85X(dev_priv))
2121 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2127 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2129 if (INTEL_GEN(dev_priv) >= 9)
2131 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2132 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2134 else if (INTEL_GEN(dev_priv) >= 4)
2140 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2143 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2145 /* AUX_DIST needs only 4K alignment */
2146 if (is_aux_plane(fb, color_plane))
2149 switch (fb->modifier) {
2150 case DRM_FORMAT_MOD_LINEAR:
2151 return intel_linear_alignment(dev_priv);
2152 case I915_FORMAT_MOD_X_TILED:
2153 if (INTEL_GEN(dev_priv) >= 9)
2156 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2158 case I915_FORMAT_MOD_Y_TILED_CCS:
2159 case I915_FORMAT_MOD_Yf_TILED_CCS:
2160 case I915_FORMAT_MOD_Y_TILED:
2161 case I915_FORMAT_MOD_Yf_TILED:
2162 return 1 * 1024 * 1024;
2164 MISSING_CASE(fb->modifier);
2169 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2171 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2172 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2174 return INTEL_GEN(dev_priv) < 4 ||
2176 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
2180 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2181 const struct i915_ggtt_view *view,
2183 unsigned long *out_flags)
2185 struct drm_device *dev = fb->dev;
2186 struct drm_i915_private *dev_priv = to_i915(dev);
2187 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2188 intel_wakeref_t wakeref;
2189 struct i915_vma *vma;
2190 unsigned int pinctl;
2193 if (WARN_ON(!i915_gem_object_is_framebuffer(obj)))
2194 return ERR_PTR(-EINVAL);
2196 alignment = intel_surf_alignment(fb, 0);
2198 /* Note that the w/a also requires 64 PTE of padding following the
2199 * bo. We currently fill all unused PTE with the shadow page and so
2200 * we should always have valid PTE following the scanout preventing
2203 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2204 alignment = 256 * 1024;
2207 * Global gtt pte registers are special registers which actually forward
2208 * writes to a chunk of system memory. Which means that there is no risk
2209 * that the register values disappear as soon as we call
2210 * intel_runtime_pm_put(), so it is correct to wrap only the
2211 * pin/unpin/fence and not more.
2213 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
2215 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2218 * Valleyview is definitely limited to scanning out the first
2219 * 512MiB. Lets presume this behaviour was inherited from the
2220 * g4x display engine and that all earlier gen are similarly
2221 * limited. Testing suggests that it is a little more
2222 * complicated than this. For example, Cherryview appears quite
2223 * happy to scanout from anywhere within its global aperture.
2226 if (HAS_GMCH(dev_priv))
2227 pinctl |= PIN_MAPPABLE;
2229 vma = i915_gem_object_pin_to_display_plane(obj,
2230 alignment, view, pinctl);
2234 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2238 * Install a fence for tiled scan-out. Pre-i965 always needs a
2239 * fence, whereas 965+ only requires a fence if using
2240 * framebuffer compression. For simplicity, we always, when
2241 * possible, install a fence as the cost is not that onerous.
2243 * If we fail to fence the tiled scanout, then either the
2244 * modeset will reject the change (which is highly unlikely as
2245 * the affected systems, all but one, do not have unmappable
2246 * space) or we will not be able to enable full powersaving
2247 * techniques (also likely not to apply due to various limits
2248 * FBC and the like impose on the size of the buffer, which
2249 * presumably we violated anyway with this unmappable buffer).
2250 * Anyway, it is presumably better to stumble onwards with
2251 * something and try to run the system in a "less than optimal"
2252 * mode that matches the user configuration.
2254 ret = i915_vma_pin_fence(vma);
2255 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2256 i915_gem_object_unpin_from_display_plane(vma);
2261 if (ret == 0 && vma->fence)
2262 *out_flags |= PLANE_HAS_FENCE;
2267 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2268 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
2272 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2274 i915_gem_object_lock(vma->obj);
2275 if (flags & PLANE_HAS_FENCE)
2276 i915_vma_unpin_fence(vma);
2277 i915_gem_object_unpin_from_display_plane(vma);
2278 i915_gem_object_unlock(vma->obj);
2283 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2284 unsigned int rotation)
2286 if (drm_rotation_90_or_270(rotation))
2287 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2289 return fb->pitches[color_plane];
2293 * Convert the x/y offsets into a linear offset.
2294 * Only valid with 0/180 degree rotation, which is fine since linear
2295 * offset is only used with linear buffers on pre-hsw and tiled buffers
2296 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2298 u32 intel_fb_xy_to_linear(int x, int y,
2299 const struct intel_plane_state *state,
2302 const struct drm_framebuffer *fb = state->hw.fb;
2303 unsigned int cpp = fb->format->cpp[color_plane];
2304 unsigned int pitch = state->color_plane[color_plane].stride;
2306 return y * pitch + x * cpp;
2310 * Add the x/y offsets derived from fb->offsets[] to the user
2311 * specified plane src x/y offsets. The resulting x/y offsets
2312 * specify the start of scanout from the beginning of the gtt mapping.
2314 void intel_add_fb_offsets(int *x, int *y,
2315 const struct intel_plane_state *state,
2319 *x += state->color_plane[color_plane].x;
2320 *y += state->color_plane[color_plane].y;
2323 static u32 intel_adjust_tile_offset(int *x, int *y,
2324 unsigned int tile_width,
2325 unsigned int tile_height,
2326 unsigned int tile_size,
2327 unsigned int pitch_tiles,
2331 unsigned int pitch_pixels = pitch_tiles * tile_width;
2334 WARN_ON(old_offset & (tile_size - 1));
2335 WARN_ON(new_offset & (tile_size - 1));
2336 WARN_ON(new_offset > old_offset);
2338 tiles = (old_offset - new_offset) / tile_size;
2340 *y += tiles / pitch_tiles * tile_height;
2341 *x += tiles % pitch_tiles * tile_width;
2343 /* minimize x in case it got needlessly big */
2344 *y += *x / pitch_pixels * tile_height;
2350 static bool is_surface_linear(const struct drm_framebuffer *fb, int color_plane)
2352 return fb->modifier == DRM_FORMAT_MOD_LINEAR ||
2353 is_gen12_ccs_plane(fb, color_plane);
2356 static u32 intel_adjust_aligned_offset(int *x, int *y,
2357 const struct drm_framebuffer *fb,
2359 unsigned int rotation,
2361 u32 old_offset, u32 new_offset)
2363 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2364 unsigned int cpp = fb->format->cpp[color_plane];
2366 WARN_ON(new_offset > old_offset);
2368 if (!is_surface_linear(fb, color_plane)) {
2369 unsigned int tile_size, tile_width, tile_height;
2370 unsigned int pitch_tiles;
2372 tile_size = intel_tile_size(dev_priv);
2373 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2375 if (drm_rotation_90_or_270(rotation)) {
2376 pitch_tiles = pitch / tile_height;
2377 swap(tile_width, tile_height);
2379 pitch_tiles = pitch / (tile_width * cpp);
2382 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2383 tile_size, pitch_tiles,
2384 old_offset, new_offset);
2386 old_offset += *y * pitch + *x * cpp;
2388 *y = (old_offset - new_offset) / pitch;
2389 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2396 * Adjust the tile offset by moving the difference into
2399 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2400 const struct intel_plane_state *state,
2402 u32 old_offset, u32 new_offset)
2404 return intel_adjust_aligned_offset(x, y, state->hw.fb, color_plane,
2406 state->color_plane[color_plane].stride,
2407 old_offset, new_offset);
2411 * Computes the aligned offset to the base tile and adjusts
2412 * x, y. bytes per pixel is assumed to be a power-of-two.
2414 * In the 90/270 rotated case, x and y are assumed
2415 * to be already rotated to match the rotated GTT view, and
2416 * pitch is the tile_height aligned framebuffer height.
2418 * This function is used when computing the derived information
2419 * under intel_framebuffer, so using any of that information
2420 * here is not allowed. Anything under drm_framebuffer can be
2421 * used. This is why the user has to pass in the pitch since it
2422 * is specified in the rotated orientation.
2424 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2426 const struct drm_framebuffer *fb,
2429 unsigned int rotation,
2432 unsigned int cpp = fb->format->cpp[color_plane];
2433 u32 offset, offset_aligned;
2438 if (!is_surface_linear(fb, color_plane)) {
2439 unsigned int tile_size, tile_width, tile_height;
2440 unsigned int tile_rows, tiles, pitch_tiles;
2442 tile_size = intel_tile_size(dev_priv);
2443 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2445 if (drm_rotation_90_or_270(rotation)) {
2446 pitch_tiles = pitch / tile_height;
2447 swap(tile_width, tile_height);
2449 pitch_tiles = pitch / (tile_width * cpp);
2452 tile_rows = *y / tile_height;
2455 tiles = *x / tile_width;
2458 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2459 offset_aligned = offset & ~alignment;
2461 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2462 tile_size, pitch_tiles,
2463 offset, offset_aligned);
2465 offset = *y * pitch + *x * cpp;
2466 offset_aligned = offset & ~alignment;
2468 *y = (offset & alignment) / pitch;
2469 *x = ((offset & alignment) - *y * pitch) / cpp;
2472 return offset_aligned;
2475 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2476 const struct intel_plane_state *state,
2479 struct intel_plane *intel_plane = to_intel_plane(state->uapi.plane);
2480 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2481 const struct drm_framebuffer *fb = state->hw.fb;
2482 unsigned int rotation = state->hw.rotation;
2483 int pitch = state->color_plane[color_plane].stride;
2486 if (intel_plane->id == PLANE_CURSOR)
2487 alignment = intel_cursor_alignment(dev_priv);
2489 alignment = intel_surf_alignment(fb, color_plane);
2491 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2492 pitch, rotation, alignment);
2495 /* Convert the fb->offset[] into x/y offsets */
2496 static int intel_fb_offset_to_xy(int *x, int *y,
2497 const struct drm_framebuffer *fb,
2500 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2501 unsigned int height;
2503 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2504 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2505 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2506 fb->offsets[color_plane], color_plane);
2510 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2511 height = ALIGN(height, intel_tile_height(fb, color_plane));
2513 /* Catch potential overflows early */
2514 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2515 fb->offsets[color_plane])) {
2516 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2517 fb->offsets[color_plane], fb->pitches[color_plane],
2525 intel_adjust_aligned_offset(x, y,
2526 fb, color_plane, DRM_MODE_ROTATE_0,
2527 fb->pitches[color_plane],
2528 fb->offsets[color_plane], 0);
2533 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2535 switch (fb_modifier) {
2536 case I915_FORMAT_MOD_X_TILED:
2537 return I915_TILING_X;
2538 case I915_FORMAT_MOD_Y_TILED:
2539 case I915_FORMAT_MOD_Y_TILED_CCS:
2540 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2541 return I915_TILING_Y;
2543 return I915_TILING_NONE;
2548 * From the Sky Lake PRM:
2549 * "The Color Control Surface (CCS) contains the compression status of
2550 * the cache-line pairs. The compression state of the cache-line pair
2551 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2552 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2553 * cache-line-pairs. CCS is always Y tiled."
2555 * Since cache line pairs refers to horizontally adjacent cache lines,
2556 * each cache line in the CCS corresponds to an area of 32x16 cache
2557 * lines on the main surface. Since each pixel is 4 bytes, this gives
2558 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2561 static const struct drm_format_info skl_ccs_formats[] = {
2562 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2563 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2564 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2565 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2566 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2567 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2568 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2569 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2573 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
2574 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
2575 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
2576 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
2579 static const struct drm_format_info gen12_ccs_formats[] = {
2580 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2581 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2582 .hsub = 1, .vsub = 1, },
2583 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2584 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2585 .hsub = 1, .vsub = 1, },
2586 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2587 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2588 .hsub = 1, .vsub = 1, .has_alpha = true },
2589 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2590 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2591 .hsub = 1, .vsub = 1, .has_alpha = true },
2594 static const struct drm_format_info *
2595 lookup_format_info(const struct drm_format_info formats[],
2596 int num_formats, u32 format)
2600 for (i = 0; i < num_formats; i++) {
2601 if (formats[i].format == format)
2608 static const struct drm_format_info *
2609 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2611 switch (cmd->modifier[0]) {
2612 case I915_FORMAT_MOD_Y_TILED_CCS:
2613 case I915_FORMAT_MOD_Yf_TILED_CCS:
2614 return lookup_format_info(skl_ccs_formats,
2615 ARRAY_SIZE(skl_ccs_formats),
2617 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2618 return lookup_format_info(gen12_ccs_formats,
2619 ARRAY_SIZE(gen12_ccs_formats),
2626 bool is_ccs_modifier(u64 modifier)
2628 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
2629 modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2630 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2633 static int gen12_ccs_aux_stride(struct drm_framebuffer *fb, int ccs_plane)
2635 return DIV_ROUND_UP(fb->pitches[ccs_to_main_plane(fb, ccs_plane)],
2639 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
2640 u32 pixel_format, u64 modifier)
2642 struct intel_crtc *crtc;
2643 struct intel_plane *plane;
2646 * We assume the primary plane for pipe A has
2647 * the highest stride limits of them all.
2649 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
2653 plane = to_intel_plane(crtc->base.primary);
2655 return plane->max_stride(plane, pixel_format, modifier,
2660 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
2661 u32 pixel_format, u64 modifier)
2664 * Arbitrary limit for gen4+ chosen to match the
2665 * render engine max stride.
2667 * The new CCS hash mode makes remapping impossible
2669 if (!is_ccs_modifier(modifier)) {
2670 if (INTEL_GEN(dev_priv) >= 7)
2672 else if (INTEL_GEN(dev_priv) >= 4)
2676 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
2680 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
2682 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2685 if (is_surface_linear(fb, color_plane)) {
2686 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
2691 * To make remapping with linear generally feasible
2692 * we need the stride to be page aligned.
2694 if (fb->pitches[color_plane] > max_stride &&
2695 !is_ccs_modifier(fb->modifier))
2696 return intel_tile_size(dev_priv);
2701 tile_width = intel_tile_width_bytes(fb, color_plane);
2702 if (is_ccs_modifier(fb->modifier) && color_plane == 0) {
2704 * Display WA #0531: skl,bxt,kbl,glk
2706 * Render decompression and plane width > 3840
2707 * combined with horizontal panning requires the
2708 * plane stride to be a multiple of 4. We'll just
2709 * require the entire fb to accommodate that to avoid
2710 * potential runtime errors at plane configuration time.
2712 if (IS_GEN(dev_priv, 9) && fb->width > 3840)
2715 * The main surface pitch must be padded to a multiple of four
2718 else if (INTEL_GEN(dev_priv) >= 12)
2724 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
2726 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2727 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2728 const struct drm_framebuffer *fb = plane_state->hw.fb;
2731 /* We don't want to deal with remapping with cursors */
2732 if (plane->id == PLANE_CURSOR)
2736 * The display engine limits already match/exceed the
2737 * render engine limits, so not much point in remapping.
2738 * Would also need to deal with the fence POT alignment
2739 * and gen2 2KiB GTT tile size.
2741 if (INTEL_GEN(dev_priv) < 4)
2745 * The new CCS hash mode isn't compatible with remapping as
2746 * the virtual address of the pages affects the compressed data.
2748 if (is_ccs_modifier(fb->modifier))
2751 /* Linear needs a page aligned stride for remapping */
2752 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2753 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2755 for (i = 0; i < fb->format->num_planes; i++) {
2756 if (fb->pitches[i] & alignment)
2764 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2766 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2767 const struct drm_framebuffer *fb = plane_state->hw.fb;
2768 unsigned int rotation = plane_state->hw.rotation;
2769 u32 stride, max_stride;
2772 * No remapping for invisible planes since we don't have
2773 * an actual source viewport to remap.
2775 if (!plane_state->uapi.visible)
2778 if (!intel_plane_can_remap(plane_state))
2782 * FIXME: aux plane limits on gen9+ are
2783 * unclear in Bspec, for now no checking.
2785 stride = intel_fb_pitch(fb, 0, rotation);
2786 max_stride = plane->max_stride(plane, fb->format->format,
2787 fb->modifier, rotation);
2789 return stride > max_stride;
2793 intel_fb_plane_get_subsampling(int *hsub, int *vsub,
2794 const struct drm_framebuffer *fb,
2799 if (color_plane == 0) {
2807 * TODO: Deduct the subsampling from the char block for all CCS
2808 * formats and planes.
2810 if (!is_gen12_ccs_plane(fb, color_plane)) {
2811 *hsub = fb->format->hsub;
2812 *vsub = fb->format->vsub;
2817 main_plane = ccs_to_main_plane(fb, color_plane);
2818 *hsub = drm_format_info_block_width(fb->format, color_plane) /
2819 drm_format_info_block_width(fb->format, main_plane);
2822 * The min stride check in the core framebuffer_check() function
2823 * assumes that format->hsub applies to every plane except for the
2824 * first plane. That's incorrect for the CCS AUX plane of the first
2825 * plane, but for the above check to pass we must define the block
2826 * width with that subsampling applied to it. Adjust the width here
2827 * accordingly, so we can calculate the actual subsampling factor.
2829 if (main_plane == 0)
2830 *hsub *= fb->format->hsub;
2835 intel_fb_check_ccs_xy(struct drm_framebuffer *fb, int ccs_plane, int x, int y)
2837 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2840 int tile_width, tile_height;
2844 if (!is_ccs_plane(fb, ccs_plane))
2847 intel_tile_dims(fb, ccs_plane, &tile_width, &tile_height);
2848 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
2851 tile_height *= vsub;
2853 ccs_x = (x * hsub) % tile_width;
2854 ccs_y = (y * vsub) % tile_height;
2856 main_plane = ccs_to_main_plane(fb, ccs_plane);
2857 main_x = intel_fb->normal[main_plane].x % tile_width;
2858 main_y = intel_fb->normal[main_plane].y % tile_height;
2861 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2862 * x/y offsets must match between CCS and the main surface.
2864 if (main_x != ccs_x || main_y != ccs_y) {
2865 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2868 intel_fb->normal[main_plane].x,
2869 intel_fb->normal[main_plane].y,
2878 intel_fb_plane_dims(int *w, int *h, struct drm_framebuffer *fb, int color_plane)
2882 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, color_plane);
2883 *w = fb->width / hsub;
2884 *h = fb->height / vsub;
2888 * Setup the rotated view for an FB plane and return the size the GTT mapping
2889 * requires for this view.
2892 setup_fb_rotation(int plane, const struct intel_remapped_plane_info *plane_info,
2893 u32 gtt_offset_rotated, int x, int y,
2894 unsigned int width, unsigned int height,
2895 unsigned int tile_size,
2896 unsigned int tile_width, unsigned int tile_height,
2897 struct drm_framebuffer *fb)
2899 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2900 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2901 unsigned int pitch_tiles;
2904 /* Y or Yf modifiers required for 90/270 rotation */
2905 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
2906 fb->modifier != I915_FORMAT_MOD_Yf_TILED)
2909 if (WARN_ON(plane >= ARRAY_SIZE(rot_info->plane)))
2912 rot_info->plane[plane] = *plane_info;
2914 intel_fb->rotated[plane].pitch = plane_info->height * tile_height;
2916 /* rotate the x/y offsets to match the GTT view */
2917 drm_rect_init(&r, x, y, width, height);
2919 plane_info->width * tile_width,
2920 plane_info->height * tile_height,
2921 DRM_MODE_ROTATE_270);
2925 /* rotate the tile dimensions to match the GTT view */
2926 pitch_tiles = intel_fb->rotated[plane].pitch / tile_height;
2927 swap(tile_width, tile_height);
2930 * We only keep the x/y offsets, so push all of the
2931 * gtt offset into the x/y offsets.
2933 intel_adjust_tile_offset(&x, &y,
2934 tile_width, tile_height,
2935 tile_size, pitch_tiles,
2936 gtt_offset_rotated * tile_size, 0);
2939 * First pixel of the framebuffer from
2940 * the start of the rotated gtt mapping.
2942 intel_fb->rotated[plane].x = x;
2943 intel_fb->rotated[plane].y = y;
2945 return plane_info->width * plane_info->height;
2949 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2950 struct drm_framebuffer *fb)
2952 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2953 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2954 u32 gtt_offset_rotated = 0;
2955 unsigned int max_size = 0;
2956 int i, num_planes = fb->format->num_planes;
2957 unsigned int tile_size = intel_tile_size(dev_priv);
2959 for (i = 0; i < num_planes; i++) {
2960 unsigned int width, height;
2961 unsigned int cpp, size;
2966 cpp = fb->format->cpp[i];
2967 intel_fb_plane_dims(&width, &height, fb, i);
2969 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2971 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2976 ret = intel_fb_check_ccs_xy(fb, i, x, y);
2981 * The fence (if used) is aligned to the start of the object
2982 * so having the framebuffer wrap around across the edge of the
2983 * fenced region doesn't really work. We have no API to configure
2984 * the fence start offset within the object (nor could we probably
2985 * on gen2/3). So it's just easier if we just require that the
2986 * fb layout agrees with the fence layout. We already check that the
2987 * fb stride matches the fence stride elsewhere.
2989 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2990 (x + width) * cpp > fb->pitches[i]) {
2991 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2997 * First pixel of the framebuffer from
2998 * the start of the normal gtt mapping.
3000 intel_fb->normal[i].x = x;
3001 intel_fb->normal[i].y = y;
3003 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
3007 offset /= tile_size;
3009 if (!is_surface_linear(fb, i)) {
3010 struct intel_remapped_plane_info plane_info;
3011 unsigned int tile_width, tile_height;
3013 intel_tile_dims(fb, i, &tile_width, &tile_height);
3015 plane_info.offset = offset;
3016 plane_info.stride = DIV_ROUND_UP(fb->pitches[i],
3018 plane_info.width = DIV_ROUND_UP(x + width, tile_width);
3019 plane_info.height = DIV_ROUND_UP(y + height,
3022 /* how many tiles does this plane need */
3023 size = plane_info.stride * plane_info.height;
3025 * If the plane isn't horizontally tile aligned,
3026 * we need one more tile.
3031 gtt_offset_rotated +=
3032 setup_fb_rotation(i, &plane_info,
3034 x, y, width, height,
3036 tile_width, tile_height,
3039 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
3040 x * cpp, tile_size);
3043 /* how many tiles in total needed in the bo */
3044 max_size = max(max_size, offset + size);
3047 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
3048 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
3049 mul_u32_u32(max_size, tile_size), obj->base.size);
3057 intel_plane_remap_gtt(struct intel_plane_state *plane_state)
3059 struct drm_i915_private *dev_priv =
3060 to_i915(plane_state->uapi.plane->dev);
3061 struct drm_framebuffer *fb = plane_state->hw.fb;
3062 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
3063 struct intel_rotation_info *info = &plane_state->view.rotated;
3064 unsigned int rotation = plane_state->hw.rotation;
3065 int i, num_planes = fb->format->num_planes;
3066 unsigned int tile_size = intel_tile_size(dev_priv);
3067 unsigned int src_x, src_y;
3068 unsigned int src_w, src_h;
3071 memset(&plane_state->view, 0, sizeof(plane_state->view));
3072 plane_state->view.type = drm_rotation_90_or_270(rotation) ?
3073 I915_GGTT_VIEW_ROTATED : I915_GGTT_VIEW_REMAPPED;
3075 src_x = plane_state->uapi.src.x1 >> 16;
3076 src_y = plane_state->uapi.src.y1 >> 16;
3077 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
3078 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
3080 WARN_ON(is_ccs_modifier(fb->modifier));
3082 /* Make src coordinates relative to the viewport */
3083 drm_rect_translate(&plane_state->uapi.src,
3084 -(src_x << 16), -(src_y << 16));
3086 /* Rotate src coordinates to match rotated GTT view */
3087 if (drm_rotation_90_or_270(rotation))
3088 drm_rect_rotate(&plane_state->uapi.src,
3089 src_w << 16, src_h << 16,
3090 DRM_MODE_ROTATE_270);
3092 for (i = 0; i < num_planes; i++) {
3093 unsigned int hsub = i ? fb->format->hsub : 1;
3094 unsigned int vsub = i ? fb->format->vsub : 1;
3095 unsigned int cpp = fb->format->cpp[i];
3096 unsigned int tile_width, tile_height;
3097 unsigned int width, height;
3098 unsigned int pitch_tiles;
3102 intel_tile_dims(fb, i, &tile_width, &tile_height);
3106 width = src_w / hsub;
3107 height = src_h / vsub;
3110 * First pixel of the src viewport from the
3111 * start of the normal gtt mapping.
3113 x += intel_fb->normal[i].x;
3114 y += intel_fb->normal[i].y;
3116 offset = intel_compute_aligned_offset(dev_priv, &x, &y,
3117 fb, i, fb->pitches[i],
3118 DRM_MODE_ROTATE_0, tile_size);
3119 offset /= tile_size;
3121 WARN_ON(i >= ARRAY_SIZE(info->plane));
3122 info->plane[i].offset = offset;
3123 info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
3125 info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
3126 info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
3128 if (drm_rotation_90_or_270(rotation)) {
3131 /* rotate the x/y offsets to match the GTT view */
3132 drm_rect_init(&r, x, y, width, height);
3134 info->plane[i].width * tile_width,
3135 info->plane[i].height * tile_height,
3136 DRM_MODE_ROTATE_270);
3140 pitch_tiles = info->plane[i].height;
3141 plane_state->color_plane[i].stride = pitch_tiles * tile_height;
3143 /* rotate the tile dimensions to match the GTT view */
3144 swap(tile_width, tile_height);
3146 pitch_tiles = info->plane[i].width;
3147 plane_state->color_plane[i].stride = pitch_tiles * tile_width * cpp;
3151 * We only keep the x/y offsets, so push all of the
3152 * gtt offset into the x/y offsets.
3154 intel_adjust_tile_offset(&x, &y,
3155 tile_width, tile_height,
3156 tile_size, pitch_tiles,
3157 gtt_offset * tile_size, 0);
3159 gtt_offset += info->plane[i].width * info->plane[i].height;
3161 plane_state->color_plane[i].offset = 0;
3162 plane_state->color_plane[i].x = x;
3163 plane_state->color_plane[i].y = y;
3168 intel_plane_compute_gtt(struct intel_plane_state *plane_state)
3170 const struct intel_framebuffer *fb =
3171 to_intel_framebuffer(plane_state->hw.fb);
3172 unsigned int rotation = plane_state->hw.rotation;
3178 num_planes = fb->base.format->num_planes;
3180 if (intel_plane_needs_remap(plane_state)) {
3181 intel_plane_remap_gtt(plane_state);
3184 * Sometimes even remapping can't overcome
3185 * the stride limitations :( Can happen with
3186 * big plane sizes and suitably misaligned
3189 return intel_plane_check_stride(plane_state);
3192 intel_fill_fb_ggtt_view(&plane_state->view, &fb->base, rotation);
3194 for (i = 0; i < num_planes; i++) {
3195 plane_state->color_plane[i].stride = intel_fb_pitch(&fb->base, i, rotation);
3196 plane_state->color_plane[i].offset = 0;
3198 if (drm_rotation_90_or_270(rotation)) {
3199 plane_state->color_plane[i].x = fb->rotated[i].x;
3200 plane_state->color_plane[i].y = fb->rotated[i].y;
3202 plane_state->color_plane[i].x = fb->normal[i].x;
3203 plane_state->color_plane[i].y = fb->normal[i].y;
3207 /* Rotate src coordinates to match rotated GTT view */
3208 if (drm_rotation_90_or_270(rotation))
3209 drm_rect_rotate(&plane_state->uapi.src,
3210 fb->base.width << 16, fb->base.height << 16,
3211 DRM_MODE_ROTATE_270);
3213 return intel_plane_check_stride(plane_state);
3216 static int i9xx_format_to_fourcc(int format)
3219 case DISPPLANE_8BPP:
3220 return DRM_FORMAT_C8;
3221 case DISPPLANE_BGRA555:
3222 return DRM_FORMAT_ARGB1555;
3223 case DISPPLANE_BGRX555:
3224 return DRM_FORMAT_XRGB1555;
3225 case DISPPLANE_BGRX565:
3226 return DRM_FORMAT_RGB565;
3228 case DISPPLANE_BGRX888:
3229 return DRM_FORMAT_XRGB8888;
3230 case DISPPLANE_RGBX888:
3231 return DRM_FORMAT_XBGR8888;
3232 case DISPPLANE_BGRA888:
3233 return DRM_FORMAT_ARGB8888;
3234 case DISPPLANE_RGBA888:
3235 return DRM_FORMAT_ABGR8888;
3236 case DISPPLANE_BGRX101010:
3237 return DRM_FORMAT_XRGB2101010;
3238 case DISPPLANE_RGBX101010:
3239 return DRM_FORMAT_XBGR2101010;
3240 case DISPPLANE_BGRA101010:
3241 return DRM_FORMAT_ARGB2101010;
3242 case DISPPLANE_RGBA101010:
3243 return DRM_FORMAT_ABGR2101010;
3244 case DISPPLANE_RGBX161616:
3245 return DRM_FORMAT_XBGR16161616F;
3249 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
3252 case PLANE_CTL_FORMAT_RGB_565:
3253 return DRM_FORMAT_RGB565;
3254 case PLANE_CTL_FORMAT_NV12:
3255 return DRM_FORMAT_NV12;
3256 case PLANE_CTL_FORMAT_P010:
3257 return DRM_FORMAT_P010;
3258 case PLANE_CTL_FORMAT_P012:
3259 return DRM_FORMAT_P012;
3260 case PLANE_CTL_FORMAT_P016:
3261 return DRM_FORMAT_P016;
3262 case PLANE_CTL_FORMAT_Y210:
3263 return DRM_FORMAT_Y210;
3264 case PLANE_CTL_FORMAT_Y212:
3265 return DRM_FORMAT_Y212;
3266 case PLANE_CTL_FORMAT_Y216:
3267 return DRM_FORMAT_Y216;
3268 case PLANE_CTL_FORMAT_Y410:
3269 return DRM_FORMAT_XVYU2101010;
3270 case PLANE_CTL_FORMAT_Y412:
3271 return DRM_FORMAT_XVYU12_16161616;
3272 case PLANE_CTL_FORMAT_Y416:
3273 return DRM_FORMAT_XVYU16161616;
3275 case PLANE_CTL_FORMAT_XRGB_8888:
3278 return DRM_FORMAT_ABGR8888;
3280 return DRM_FORMAT_XBGR8888;
3283 return DRM_FORMAT_ARGB8888;
3285 return DRM_FORMAT_XRGB8888;
3287 case PLANE_CTL_FORMAT_XRGB_2101010:
3290 return DRM_FORMAT_ABGR2101010;
3292 return DRM_FORMAT_XBGR2101010;
3295 return DRM_FORMAT_ARGB2101010;
3297 return DRM_FORMAT_XRGB2101010;
3299 case PLANE_CTL_FORMAT_XRGB_16161616F:
3302 return DRM_FORMAT_ABGR16161616F;
3304 return DRM_FORMAT_XBGR16161616F;
3307 return DRM_FORMAT_ARGB16161616F;
3309 return DRM_FORMAT_XRGB16161616F;
3315 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
3316 struct intel_initial_plane_config *plane_config)
3318 struct drm_device *dev = crtc->base.dev;
3319 struct drm_i915_private *dev_priv = to_i915(dev);
3320 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
3321 struct drm_framebuffer *fb = &plane_config->fb->base;
3322 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
3323 u32 size_aligned = round_up(plane_config->base + plane_config->size,
3325 struct drm_i915_gem_object *obj;
3328 size_aligned -= base_aligned;
3330 if (plane_config->size == 0)
3333 /* If the FB is too big, just don't use it since fbdev is not very
3334 * important and we should probably use that space with FBC or other
3336 if (size_aligned * 2 > dev_priv->stolen_usable_size)
3339 switch (fb->modifier) {
3340 case DRM_FORMAT_MOD_LINEAR:
3341 case I915_FORMAT_MOD_X_TILED:
3342 case I915_FORMAT_MOD_Y_TILED:
3345 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
3350 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
3357 switch (plane_config->tiling) {
3358 case I915_TILING_NONE:
3362 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
3365 MISSING_CASE(plane_config->tiling);
3369 mode_cmd.pixel_format = fb->format->format;
3370 mode_cmd.width = fb->width;
3371 mode_cmd.height = fb->height;
3372 mode_cmd.pitches[0] = fb->pitches[0];
3373 mode_cmd.modifier[0] = fb->modifier;
3374 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
3376 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
3377 DRM_DEBUG_KMS("intel fb init failed\n");
3382 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
3385 i915_gem_object_put(obj);
3390 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
3391 struct intel_plane_state *plane_state,
3394 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3396 plane_state->uapi.visible = visible;
3399 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
3401 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
3404 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
3406 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3407 struct drm_plane *plane;
3410 * Active_planes aliases if multiple "primary" or cursor planes
3411 * have been used on the same (or wrong) pipe. plane_mask uses
3412 * unique ids, hence we can use that to reconstruct active_planes.
3414 crtc_state->active_planes = 0;
3416 drm_for_each_plane_mask(plane, &dev_priv->drm,
3417 crtc_state->uapi.plane_mask)
3418 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
3421 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
3422 struct intel_plane *plane)
3424 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3425 struct intel_crtc_state *crtc_state =
3426 to_intel_crtc_state(crtc->base.state);
3427 struct intel_plane_state *plane_state =
3428 to_intel_plane_state(plane->base.state);
3430 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
3431 plane->base.base.id, plane->base.name,
3432 crtc->base.base.id, crtc->base.name);
3434 intel_set_plane_visible(crtc_state, plane_state, false);
3435 fixup_active_planes(crtc_state);
3436 crtc_state->data_rate[plane->id] = 0;
3437 crtc_state->min_cdclk[plane->id] = 0;
3439 if (plane->id == PLANE_PRIMARY)
3440 hsw_disable_ips(crtc_state);
3443 * Vblank time updates from the shadow to live plane control register
3444 * are blocked if the memory self-refresh mode is active at that
3445 * moment. So to make sure the plane gets truly disabled, disable
3446 * first the self-refresh mode. The self-refresh enable bit in turn
3447 * will be checked/applied by the HW only at the next frame start
3448 * event which is after the vblank start event, so we need to have a
3449 * wait-for-vblank between disabling the plane and the pipe.
3451 if (HAS_GMCH(dev_priv) &&
3452 intel_set_memory_cxsr(dev_priv, false))
3453 intel_wait_for_vblank(dev_priv, crtc->pipe);
3456 * Gen2 reports pipe underruns whenever all planes are disabled.
3457 * So disable underrun reporting before all the planes get disabled.
3459 if (IS_GEN(dev_priv, 2) && !crtc_state->active_planes)
3460 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
3462 intel_disable_plane(plane, crtc_state);
3465 static struct intel_frontbuffer *
3466 to_intel_frontbuffer(struct drm_framebuffer *fb)
3468 return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
3472 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
3473 struct intel_initial_plane_config *plane_config)
3475 struct drm_device *dev = intel_crtc->base.dev;
3476 struct drm_i915_private *dev_priv = to_i915(dev);
3478 struct drm_plane *primary = intel_crtc->base.primary;
3479 struct drm_plane_state *plane_state = primary->state;
3480 struct intel_plane *intel_plane = to_intel_plane(primary);
3481 struct intel_plane_state *intel_state =
3482 to_intel_plane_state(plane_state);
3483 struct drm_framebuffer *fb;
3485 if (!plane_config->fb)
3488 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
3489 fb = &plane_config->fb->base;
3493 kfree(plane_config->fb);
3496 * Failed to alloc the obj, check to see if we should share
3497 * an fb with another CRTC instead
3499 for_each_crtc(dev, c) {
3500 struct intel_plane_state *state;
3502 if (c == &intel_crtc->base)
3505 if (!to_intel_crtc(c)->active)
3508 state = to_intel_plane_state(c->primary->state);
3512 if (intel_plane_ggtt_offset(state) == plane_config->base) {
3514 drm_framebuffer_get(fb);
3520 * We've failed to reconstruct the BIOS FB. Current display state
3521 * indicates that the primary plane is visible, but has a NULL FB,
3522 * which will lead to problems later if we don't fix it up. The
3523 * simplest solution is to just disable the primary plane now and
3524 * pretend the BIOS never had it enabled.
3526 intel_plane_disable_noatomic(intel_crtc, intel_plane);
3531 intel_state->hw.rotation = plane_config->rotation;
3532 intel_fill_fb_ggtt_view(&intel_state->view, fb,
3533 intel_state->hw.rotation);
3534 intel_state->color_plane[0].stride =
3535 intel_fb_pitch(fb, 0, intel_state->hw.rotation);
3538 intel_pin_and_fence_fb_obj(fb,
3540 intel_plane_uses_fence(intel_state),
3541 &intel_state->flags);
3542 if (IS_ERR(intel_state->vma)) {
3543 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
3544 intel_crtc->pipe, PTR_ERR(intel_state->vma));
3546 intel_state->vma = NULL;
3547 drm_framebuffer_put(fb);
3551 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
3553 plane_state->src_x = 0;
3554 plane_state->src_y = 0;
3555 plane_state->src_w = fb->width << 16;
3556 plane_state->src_h = fb->height << 16;
3558 plane_state->crtc_x = 0;
3559 plane_state->crtc_y = 0;
3560 plane_state->crtc_w = fb->width;
3561 plane_state->crtc_h = fb->height;
3563 intel_state->uapi.src = drm_plane_state_src(plane_state);
3564 intel_state->uapi.dst = drm_plane_state_dest(plane_state);
3566 if (plane_config->tiling)
3567 dev_priv->preserve_bios_swizzle = true;
3569 plane_state->fb = fb;
3570 plane_state->crtc = &intel_crtc->base;
3571 intel_plane_copy_uapi_to_hw_state(intel_state, intel_state);
3573 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
3574 &to_intel_frontbuffer(fb)->bits);
3577 static int skl_max_plane_width(const struct drm_framebuffer *fb,
3579 unsigned int rotation)
3581 int cpp = fb->format->cpp[color_plane];
3583 switch (fb->modifier) {
3584 case DRM_FORMAT_MOD_LINEAR:
3585 case I915_FORMAT_MOD_X_TILED:
3587 * Validated limit is 4k, but has 5k should
3588 * work apart from the following features:
3589 * - Ytile (already limited to 4k)
3590 * - FP16 (already limited to 4k)
3591 * - render compression (already limited to 4k)
3592 * - KVMR sprite and cursor (don't care)
3593 * - horizontal panning (TODO verify this)
3594 * - pipe and plane scaling (TODO verify this)
3600 case I915_FORMAT_MOD_Y_TILED_CCS:
3601 case I915_FORMAT_MOD_Yf_TILED_CCS:
3602 /* FIXME AUX plane? */
3603 case I915_FORMAT_MOD_Y_TILED:
3604 case I915_FORMAT_MOD_Yf_TILED:
3610 MISSING_CASE(fb->modifier);
3615 static int glk_max_plane_width(const struct drm_framebuffer *fb,
3617 unsigned int rotation)
3619 int cpp = fb->format->cpp[color_plane];
3621 switch (fb->modifier) {
3622 case DRM_FORMAT_MOD_LINEAR:
3623 case I915_FORMAT_MOD_X_TILED:
3628 case I915_FORMAT_MOD_Y_TILED_CCS:
3629 case I915_FORMAT_MOD_Yf_TILED_CCS:
3630 /* FIXME AUX plane? */
3631 case I915_FORMAT_MOD_Y_TILED:
3632 case I915_FORMAT_MOD_Yf_TILED:
3638 MISSING_CASE(fb->modifier);
3643 static int icl_max_plane_width(const struct drm_framebuffer *fb,
3645 unsigned int rotation)
3650 static int skl_max_plane_height(void)
3655 static int icl_max_plane_height(void)
3660 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3661 int main_x, int main_y, u32 main_offset)
3663 const struct drm_framebuffer *fb = plane_state->hw.fb;
3664 int ccs_plane = main_to_ccs_plane(fb, 0);
3665 int aux_x = plane_state->color_plane[ccs_plane].x;
3666 int aux_y = plane_state->color_plane[ccs_plane].y;
3667 u32 aux_offset = plane_state->color_plane[ccs_plane].offset;
3668 u32 alignment = intel_surf_alignment(fb, ccs_plane);
3672 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
3673 while (aux_offset >= main_offset && aux_y <= main_y) {
3676 if (aux_x == main_x && aux_y == main_y)
3679 if (aux_offset == 0)
3684 aux_offset = intel_plane_adjust_aligned_offset(&x, &y,
3690 aux_x = x * hsub + aux_x % hsub;
3691 aux_y = y * vsub + aux_y % vsub;
3694 if (aux_x != main_x || aux_y != main_y)
3697 plane_state->color_plane[ccs_plane].offset = aux_offset;
3698 plane_state->color_plane[ccs_plane].x = aux_x;
3699 plane_state->color_plane[ccs_plane].y = aux_y;
3704 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3706 struct drm_i915_private *dev_priv = to_i915(plane_state->uapi.plane->dev);
3707 const struct drm_framebuffer *fb = plane_state->hw.fb;
3708 unsigned int rotation = plane_state->hw.rotation;
3709 int x = plane_state->uapi.src.x1 >> 16;
3710 int y = plane_state->uapi.src.y1 >> 16;
3711 int w = drm_rect_width(&plane_state->uapi.src) >> 16;
3712 int h = drm_rect_height(&plane_state->uapi.src) >> 16;
3717 int aux_plane = intel_main_to_aux_plane(fb, 0);
3718 u32 aux_offset = plane_state->color_plane[aux_plane].offset;
3720 if (INTEL_GEN(dev_priv) >= 11)
3721 max_width = icl_max_plane_width(fb, 0, rotation);
3722 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3723 max_width = glk_max_plane_width(fb, 0, rotation);
3725 max_width = skl_max_plane_width(fb, 0, rotation);
3727 if (INTEL_GEN(dev_priv) >= 11)
3728 max_height = icl_max_plane_height();
3730 max_height = skl_max_plane_height();
3732 if (w > max_width || h > max_height) {
3733 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3734 w, h, max_width, max_height);
3738 intel_add_fb_offsets(&x, &y, plane_state, 0);
3739 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3740 alignment = intel_surf_alignment(fb, 0);
3743 * AUX surface offset is specified as the distance from the
3744 * main surface offset, and it must be non-negative. Make
3745 * sure that is what we will get.
3747 if (offset > aux_offset)
3748 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3749 offset, aux_offset & ~(alignment - 1));
3752 * When using an X-tiled surface, the plane blows up
3753 * if the x offset + width exceed the stride.
3755 * TODO: linear and Y-tiled seem fine, Yf untested,
3757 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3758 int cpp = fb->format->cpp[0];
3760 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3762 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3766 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3767 offset, offset - alignment);
3772 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3773 * they match with the main surface x/y offsets.
3775 if (is_ccs_modifier(fb->modifier)) {
3776 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3780 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3781 offset, offset - alignment);
3784 if (x != plane_state->color_plane[aux_plane].x ||
3785 y != plane_state->color_plane[aux_plane].y) {
3786 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3791 plane_state->color_plane[0].offset = offset;
3792 plane_state->color_plane[0].x = x;
3793 plane_state->color_plane[0].y = y;
3796 * Put the final coordinates back so that the src
3797 * coordinate checks will see the right values.
3799 drm_rect_translate_to(&plane_state->uapi.src,
3805 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3807 const struct drm_framebuffer *fb = plane_state->hw.fb;
3808 unsigned int rotation = plane_state->hw.rotation;
3809 int max_width = skl_max_plane_width(fb, 1, rotation);
3810 int max_height = 4096;
3811 int x = plane_state->uapi.src.x1 >> 17;
3812 int y = plane_state->uapi.src.y1 >> 17;
3813 int w = drm_rect_width(&plane_state->uapi.src) >> 17;
3814 int h = drm_rect_height(&plane_state->uapi.src) >> 17;
3817 intel_add_fb_offsets(&x, &y, plane_state, 1);
3818 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3820 /* FIXME not quite sure how/if these apply to the chroma plane */
3821 if (w > max_width || h > max_height) {
3822 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3823 w, h, max_width, max_height);
3827 plane_state->color_plane[1].offset = offset;
3828 plane_state->color_plane[1].x = x;
3829 plane_state->color_plane[1].y = y;
3834 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3836 const struct drm_framebuffer *fb = plane_state->hw.fb;
3837 int src_x = plane_state->uapi.src.x1 >> 16;
3838 int src_y = plane_state->uapi.src.y1 >> 16;
3845 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, 1);
3848 intel_add_fb_offsets(&x, &y, plane_state, 1);
3849 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3851 plane_state->color_plane[1].offset = offset;
3852 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3853 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3858 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3860 const struct drm_framebuffer *fb = plane_state->hw.fb;
3863 ret = intel_plane_compute_gtt(plane_state);
3867 if (!plane_state->uapi.visible)
3871 * Handle the AUX surface first since
3872 * the main surface setup depends on it.
3874 if (intel_format_info_is_yuv_semiplanar(fb->format,
3876 ret = skl_check_nv12_aux_surface(plane_state);
3879 } else if (is_ccs_modifier(fb->modifier)) {
3880 ret = skl_check_ccs_aux_surface(plane_state);
3884 plane_state->color_plane[1].offset = ~0xfff;
3885 plane_state->color_plane[1].x = 0;
3886 plane_state->color_plane[1].y = 0;
3889 ret = skl_check_main_surface(plane_state);
3896 static void i9xx_plane_ratio(const struct intel_crtc_state *crtc_state,
3897 const struct intel_plane_state *plane_state,
3898 unsigned int *num, unsigned int *den)
3900 const struct drm_framebuffer *fb = plane_state->hw.fb;
3901 unsigned int cpp = fb->format->cpp[0];
3904 * g4x bspec says 64bpp pixel rate can't exceed 80%
3905 * of cdclk when the sprite plane is enabled on the
3906 * same pipe. ilk/snb bspec says 64bpp pixel rate is
3907 * never allowed to exceed 80% of cdclk. Let's just go
3908 * with the ilk/snb limit always.
3919 static int i9xx_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
3920 const struct intel_plane_state *plane_state)
3922 unsigned int pixel_rate;
3923 unsigned int num, den;
3926 * Note that crtc_state->pixel_rate accounts for both
3927 * horizontal and vertical panel fitter downscaling factors.
3928 * Pre-HSW bspec tells us to only consider the horizontal
3929 * downscaling factor here. We ignore that and just consider
3930 * both for simplicity.
3932 pixel_rate = crtc_state->pixel_rate;
3934 i9xx_plane_ratio(crtc_state, plane_state, &num, &den);
3936 /* two pixels per clock with double wide pipe */
3937 if (crtc_state->double_wide)
3940 return DIV_ROUND_UP(pixel_rate * num, den);
3944 i9xx_plane_max_stride(struct intel_plane *plane,
3945 u32 pixel_format, u64 modifier,
3946 unsigned int rotation)
3948 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3950 if (!HAS_GMCH(dev_priv)) {
3952 } else if (INTEL_GEN(dev_priv) >= 4) {
3953 if (modifier == I915_FORMAT_MOD_X_TILED)
3957 } else if (INTEL_GEN(dev_priv) >= 3) {
3958 if (modifier == I915_FORMAT_MOD_X_TILED)
3963 if (plane->i9xx_plane == PLANE_C)
3970 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3972 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3973 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3976 if (crtc_state->gamma_enable)
3977 dspcntr |= DISPPLANE_GAMMA_ENABLE;
3979 if (crtc_state->csc_enable)
3980 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3982 if (INTEL_GEN(dev_priv) < 5)
3983 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3988 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3989 const struct intel_plane_state *plane_state)
3991 struct drm_i915_private *dev_priv =
3992 to_i915(plane_state->uapi.plane->dev);
3993 const struct drm_framebuffer *fb = plane_state->hw.fb;
3994 unsigned int rotation = plane_state->hw.rotation;
3997 dspcntr = DISPLAY_PLANE_ENABLE;
3999 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
4000 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
4001 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
4003 switch (fb->format->format) {
4005 dspcntr |= DISPPLANE_8BPP;
4007 case DRM_FORMAT_XRGB1555:
4008 dspcntr |= DISPPLANE_BGRX555;
4010 case DRM_FORMAT_ARGB1555:
4011 dspcntr |= DISPPLANE_BGRA555;
4013 case DRM_FORMAT_RGB565:
4014 dspcntr |= DISPPLANE_BGRX565;
4016 case DRM_FORMAT_XRGB8888:
4017 dspcntr |= DISPPLANE_BGRX888;
4019 case DRM_FORMAT_XBGR8888:
4020 dspcntr |= DISPPLANE_RGBX888;
4022 case DRM_FORMAT_ARGB8888:
4023 dspcntr |= DISPPLANE_BGRA888;
4025 case DRM_FORMAT_ABGR8888:
4026 dspcntr |= DISPPLANE_RGBA888;
4028 case DRM_FORMAT_XRGB2101010:
4029 dspcntr |= DISPPLANE_BGRX101010;
4031 case DRM_FORMAT_XBGR2101010:
4032 dspcntr |= DISPPLANE_RGBX101010;
4034 case DRM_FORMAT_ARGB2101010:
4035 dspcntr |= DISPPLANE_BGRA101010;
4037 case DRM_FORMAT_ABGR2101010:
4038 dspcntr |= DISPPLANE_RGBA101010;
4040 case DRM_FORMAT_XBGR16161616F:
4041 dspcntr |= DISPPLANE_RGBX161616;
4044 MISSING_CASE(fb->format->format);
4048 if (INTEL_GEN(dev_priv) >= 4 &&
4049 fb->modifier == I915_FORMAT_MOD_X_TILED)
4050 dspcntr |= DISPPLANE_TILED;
4052 if (rotation & DRM_MODE_ROTATE_180)
4053 dspcntr |= DISPPLANE_ROTATE_180;
4055 if (rotation & DRM_MODE_REFLECT_X)
4056 dspcntr |= DISPPLANE_MIRROR;
4061 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
4063 struct drm_i915_private *dev_priv =
4064 to_i915(plane_state->uapi.plane->dev);
4065 const struct drm_framebuffer *fb = plane_state->hw.fb;
4066 int src_x, src_y, src_w;
4070 ret = intel_plane_compute_gtt(plane_state);
4074 if (!plane_state->uapi.visible)
4077 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
4078 src_x = plane_state->uapi.src.x1 >> 16;
4079 src_y = plane_state->uapi.src.y1 >> 16;
4081 /* Undocumented hardware limit on i965/g4x/vlv/chv */
4082 if (HAS_GMCH(dev_priv) && fb->format->cpp[0] == 8 && src_w > 2048)
4085 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
4087 if (INTEL_GEN(dev_priv) >= 4)
4088 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
4094 * Put the final coordinates back so that the src
4095 * coordinate checks will see the right values.
4097 drm_rect_translate_to(&plane_state->uapi.src,
4098 src_x << 16, src_y << 16);
4100 /* HSW/BDW do this automagically in hardware */
4101 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
4102 unsigned int rotation = plane_state->hw.rotation;
4103 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
4104 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
4106 if (rotation & DRM_MODE_ROTATE_180) {
4109 } else if (rotation & DRM_MODE_REFLECT_X) {
4114 plane_state->color_plane[0].offset = offset;
4115 plane_state->color_plane[0].x = src_x;
4116 plane_state->color_plane[0].y = src_y;
4121 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
4123 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4124 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4126 if (IS_CHERRYVIEW(dev_priv))
4127 return i9xx_plane == PLANE_B;
4128 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
4130 else if (IS_GEN(dev_priv, 4))
4131 return i9xx_plane == PLANE_C;
4133 return i9xx_plane == PLANE_B ||
4134 i9xx_plane == PLANE_C;
4138 i9xx_plane_check(struct intel_crtc_state *crtc_state,
4139 struct intel_plane_state *plane_state)
4141 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
4144 ret = chv_plane_check_rotation(plane_state);
4148 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
4150 DRM_PLANE_HELPER_NO_SCALING,
4151 DRM_PLANE_HELPER_NO_SCALING,
4152 i9xx_plane_has_windowing(plane),
4157 ret = i9xx_check_plane_surface(plane_state);
4161 if (!plane_state->uapi.visible)
4164 ret = intel_plane_check_src_coordinates(plane_state);
4168 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
4173 static void i9xx_update_plane(struct intel_plane *plane,
4174 const struct intel_crtc_state *crtc_state,
4175 const struct intel_plane_state *plane_state)
4177 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4178 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4180 int x = plane_state->color_plane[0].x;
4181 int y = plane_state->color_plane[0].y;
4182 int crtc_x = plane_state->uapi.dst.x1;
4183 int crtc_y = plane_state->uapi.dst.y1;
4184 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
4185 int crtc_h = drm_rect_height(&plane_state->uapi.dst);
4186 unsigned long irqflags;
4190 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
4192 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
4194 if (INTEL_GEN(dev_priv) >= 4)
4195 dspaddr_offset = plane_state->color_plane[0].offset;
4197 dspaddr_offset = linear_offset;
4199 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4201 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
4203 if (INTEL_GEN(dev_priv) < 4) {
4205 * PLANE_A doesn't actually have a full window
4206 * generator but let's assume we still need to
4207 * program whatever is there.
4209 I915_WRITE_FW(DSPPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
4210 I915_WRITE_FW(DSPSIZE(i9xx_plane),
4211 ((crtc_h - 1) << 16) | (crtc_w - 1));
4212 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
4213 I915_WRITE_FW(PRIMPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
4214 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
4215 ((crtc_h - 1) << 16) | (crtc_w - 1));
4216 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
4219 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
4220 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
4221 } else if (INTEL_GEN(dev_priv) >= 4) {
4222 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
4223 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
4227 * The control register self-arms if the plane was previously
4228 * disabled. Try to make the plane enable atomic by writing
4229 * the control register just before the surface register.
4231 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
4232 if (INTEL_GEN(dev_priv) >= 4)
4233 I915_WRITE_FW(DSPSURF(i9xx_plane),
4234 intel_plane_ggtt_offset(plane_state) +
4237 I915_WRITE_FW(DSPADDR(i9xx_plane),
4238 intel_plane_ggtt_offset(plane_state) +
4241 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4244 static void i9xx_disable_plane(struct intel_plane *plane,
4245 const struct intel_crtc_state *crtc_state)
4247 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4248 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4249 unsigned long irqflags;
4253 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
4254 * enable on ilk+ affect the pipe bottom color as
4255 * well, so we must configure them even if the plane
4258 * On pre-g4x there is no way to gamma correct the
4259 * pipe bottom color but we'll keep on doing this
4260 * anyway so that the crtc state readout works correctly.
4262 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
4264 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4266 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
4267 if (INTEL_GEN(dev_priv) >= 4)
4268 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
4270 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
4272 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4275 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
4278 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4279 enum intel_display_power_domain power_domain;
4280 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4281 intel_wakeref_t wakeref;
4286 * Not 100% correct for planes that can move between pipes,
4287 * but that's only the case for gen2-4 which don't have any
4288 * display power wells.
4290 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
4291 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
4295 val = I915_READ(DSPCNTR(i9xx_plane));
4297 ret = val & DISPLAY_PLANE_ENABLE;
4299 if (INTEL_GEN(dev_priv) >= 5)
4300 *pipe = plane->pipe;
4302 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
4303 DISPPLANE_SEL_PIPE_SHIFT;
4305 intel_display_power_put(dev_priv, power_domain, wakeref);
4310 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
4312 struct drm_device *dev = intel_crtc->base.dev;
4313 struct drm_i915_private *dev_priv = to_i915(dev);
4315 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
4316 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
4317 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
4321 * This function detaches (aka. unbinds) unused scalers in hardware
4323 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
4325 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
4326 const struct intel_crtc_scaler_state *scaler_state =
4327 &crtc_state->scaler_state;
4330 /* loop through and disable scalers that aren't in use */
4331 for (i = 0; i < intel_crtc->num_scalers; i++) {
4332 if (!scaler_state->scalers[i].in_use)
4333 skl_detach_scaler(intel_crtc, i);
4337 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
4338 int color_plane, unsigned int rotation)
4341 * The stride is either expressed as a multiple of 64 bytes chunks for
4342 * linear buffers or in number of tiles for tiled buffers.
4344 if (is_surface_linear(fb, color_plane))
4346 else if (drm_rotation_90_or_270(rotation))
4347 return intel_tile_height(fb, color_plane);
4349 return intel_tile_width_bytes(fb, color_plane);
4352 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
4355 const struct drm_framebuffer *fb = plane_state->hw.fb;
4356 unsigned int rotation = plane_state->hw.rotation;
4357 u32 stride = plane_state->color_plane[color_plane].stride;
4359 if (color_plane >= fb->format->num_planes)
4362 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
4365 static u32 skl_plane_ctl_format(u32 pixel_format)
4367 switch (pixel_format) {
4369 return PLANE_CTL_FORMAT_INDEXED;
4370 case DRM_FORMAT_RGB565:
4371 return PLANE_CTL_FORMAT_RGB_565;
4372 case DRM_FORMAT_XBGR8888:
4373 case DRM_FORMAT_ABGR8888:
4374 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
4375 case DRM_FORMAT_XRGB8888:
4376 case DRM_FORMAT_ARGB8888:
4377 return PLANE_CTL_FORMAT_XRGB_8888;
4378 case DRM_FORMAT_XBGR2101010:
4379 case DRM_FORMAT_ABGR2101010:
4380 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
4381 case DRM_FORMAT_XRGB2101010:
4382 case DRM_FORMAT_ARGB2101010:
4383 return PLANE_CTL_FORMAT_XRGB_2101010;
4384 case DRM_FORMAT_XBGR16161616F:
4385 case DRM_FORMAT_ABGR16161616F:
4386 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
4387 case DRM_FORMAT_XRGB16161616F:
4388 case DRM_FORMAT_ARGB16161616F:
4389 return PLANE_CTL_FORMAT_XRGB_16161616F;
4390 case DRM_FORMAT_YUYV:
4391 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
4392 case DRM_FORMAT_YVYU:
4393 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
4394 case DRM_FORMAT_UYVY:
4395 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
4396 case DRM_FORMAT_VYUY:
4397 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
4398 case DRM_FORMAT_NV12:
4399 return PLANE_CTL_FORMAT_NV12;
4400 case DRM_FORMAT_P010:
4401 return PLANE_CTL_FORMAT_P010;
4402 case DRM_FORMAT_P012:
4403 return PLANE_CTL_FORMAT_P012;
4404 case DRM_FORMAT_P016:
4405 return PLANE_CTL_FORMAT_P016;
4406 case DRM_FORMAT_Y210:
4407 return PLANE_CTL_FORMAT_Y210;
4408 case DRM_FORMAT_Y212:
4409 return PLANE_CTL_FORMAT_Y212;
4410 case DRM_FORMAT_Y216:
4411 return PLANE_CTL_FORMAT_Y216;
4412 case DRM_FORMAT_XVYU2101010:
4413 return PLANE_CTL_FORMAT_Y410;
4414 case DRM_FORMAT_XVYU12_16161616:
4415 return PLANE_CTL_FORMAT_Y412;
4416 case DRM_FORMAT_XVYU16161616:
4417 return PLANE_CTL_FORMAT_Y416;
4419 MISSING_CASE(pixel_format);
4425 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
4427 if (!plane_state->hw.fb->format->has_alpha)
4428 return PLANE_CTL_ALPHA_DISABLE;
4430 switch (plane_state->hw.pixel_blend_mode) {
4431 case DRM_MODE_BLEND_PIXEL_NONE:
4432 return PLANE_CTL_ALPHA_DISABLE;
4433 case DRM_MODE_BLEND_PREMULTI:
4434 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
4435 case DRM_MODE_BLEND_COVERAGE:
4436 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
4438 MISSING_CASE(plane_state->hw.pixel_blend_mode);
4439 return PLANE_CTL_ALPHA_DISABLE;
4443 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
4445 if (!plane_state->hw.fb->format->has_alpha)
4446 return PLANE_COLOR_ALPHA_DISABLE;
4448 switch (plane_state->hw.pixel_blend_mode) {
4449 case DRM_MODE_BLEND_PIXEL_NONE:
4450 return PLANE_COLOR_ALPHA_DISABLE;
4451 case DRM_MODE_BLEND_PREMULTI:
4452 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
4453 case DRM_MODE_BLEND_COVERAGE:
4454 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
4456 MISSING_CASE(plane_state->hw.pixel_blend_mode);
4457 return PLANE_COLOR_ALPHA_DISABLE;
4461 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
4463 switch (fb_modifier) {
4464 case DRM_FORMAT_MOD_LINEAR:
4466 case I915_FORMAT_MOD_X_TILED:
4467 return PLANE_CTL_TILED_X;
4468 case I915_FORMAT_MOD_Y_TILED:
4469 return PLANE_CTL_TILED_Y;
4470 case I915_FORMAT_MOD_Y_TILED_CCS:
4471 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4472 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
4473 return PLANE_CTL_TILED_Y |
4474 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
4475 PLANE_CTL_CLEAR_COLOR_DISABLE;
4476 case I915_FORMAT_MOD_Yf_TILED:
4477 return PLANE_CTL_TILED_YF;
4478 case I915_FORMAT_MOD_Yf_TILED_CCS:
4479 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4481 MISSING_CASE(fb_modifier);
4487 static u32 skl_plane_ctl_rotate(unsigned int rotate)
4490 case DRM_MODE_ROTATE_0:
4493 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4494 * while i915 HW rotation is clockwise, thats why this swapping.
4496 case DRM_MODE_ROTATE_90:
4497 return PLANE_CTL_ROTATE_270;
4498 case DRM_MODE_ROTATE_180:
4499 return PLANE_CTL_ROTATE_180;
4500 case DRM_MODE_ROTATE_270:
4501 return PLANE_CTL_ROTATE_90;
4503 MISSING_CASE(rotate);
4509 static u32 cnl_plane_ctl_flip(unsigned int reflect)
4514 case DRM_MODE_REFLECT_X:
4515 return PLANE_CTL_FLIP_HORIZONTAL;
4516 case DRM_MODE_REFLECT_Y:
4518 MISSING_CASE(reflect);
4524 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4526 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4529 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4532 if (crtc_state->gamma_enable)
4533 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
4535 if (crtc_state->csc_enable)
4536 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
4541 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
4542 const struct intel_plane_state *plane_state)
4544 struct drm_i915_private *dev_priv =
4545 to_i915(plane_state->uapi.plane->dev);
4546 const struct drm_framebuffer *fb = plane_state->hw.fb;
4547 unsigned int rotation = plane_state->hw.rotation;
4548 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
4551 plane_ctl = PLANE_CTL_ENABLE;
4553 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
4554 plane_ctl |= skl_plane_ctl_alpha(plane_state);
4555 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
4557 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
4558 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
4560 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4561 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
4564 plane_ctl |= skl_plane_ctl_format(fb->format->format);
4565 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
4566 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
4568 if (INTEL_GEN(dev_priv) >= 10)
4569 plane_ctl |= cnl_plane_ctl_flip(rotation &
4570 DRM_MODE_REFLECT_MASK);
4572 if (key->flags & I915_SET_COLORKEY_DESTINATION)
4573 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
4574 else if (key->flags & I915_SET_COLORKEY_SOURCE)
4575 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
4580 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
4582 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4583 u32 plane_color_ctl = 0;
4585 if (INTEL_GEN(dev_priv) >= 11)
4586 return plane_color_ctl;
4588 if (crtc_state->gamma_enable)
4589 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
4591 if (crtc_state->csc_enable)
4592 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
4594 return plane_color_ctl;
4597 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
4598 const struct intel_plane_state *plane_state)
4600 struct drm_i915_private *dev_priv =
4601 to_i915(plane_state->uapi.plane->dev);
4602 const struct drm_framebuffer *fb = plane_state->hw.fb;
4603 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
4604 u32 plane_color_ctl = 0;
4606 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
4607 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
4609 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
4610 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
4611 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
4613 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
4615 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4616 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
4617 } else if (fb->format->is_yuv) {
4618 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
4621 return plane_color_ctl;
4625 __intel_display_resume(struct drm_device *dev,
4626 struct drm_atomic_state *state,
4627 struct drm_modeset_acquire_ctx *ctx)
4629 struct drm_crtc_state *crtc_state;
4630 struct drm_crtc *crtc;
4633 intel_modeset_setup_hw_state(dev, ctx);
4634 intel_vga_redisable(to_i915(dev));
4640 * We've duplicated the state, pointers to the old state are invalid.
4642 * Don't attempt to use the old state until we commit the duplicated state.
4644 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
4646 * Force recalculation even if we restore
4647 * current state. With fast modeset this may not result
4648 * in a modeset when the state is compatible.
4650 crtc_state->mode_changed = true;
4653 /* ignore any reset values/BIOS leftovers in the WM registers */
4654 if (!HAS_GMCH(to_i915(dev)))
4655 to_intel_atomic_state(state)->skip_intermediate_wm = true;
4657 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4659 WARN_ON(ret == -EDEADLK);
4663 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
4665 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
4666 intel_has_gpu_reset(&dev_priv->gt));
4669 void intel_prepare_reset(struct drm_i915_private *dev_priv)
4671 struct drm_device *dev = &dev_priv->drm;
4672 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4673 struct drm_atomic_state *state;
4676 /* reset doesn't touch the display */
4677 if (!i915_modparams.force_reset_modeset_test &&
4678 !gpu_reset_clobbers_display(dev_priv))
4681 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4682 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4683 smp_mb__after_atomic();
4684 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
4686 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
4687 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
4688 intel_gt_set_wedged(&dev_priv->gt);
4692 * Need mode_config.mutex so that we don't
4693 * trample ongoing ->detect() and whatnot.
4695 mutex_lock(&dev->mode_config.mutex);
4696 drm_modeset_acquire_init(ctx, 0);
4698 ret = drm_modeset_lock_all_ctx(dev, ctx);
4699 if (ret != -EDEADLK)
4702 drm_modeset_backoff(ctx);
4705 * Disabling the crtcs gracefully seems nicer. Also the
4706 * g33 docs say we should at least disable all the planes.
4708 state = drm_atomic_helper_duplicate_state(dev, ctx);
4709 if (IS_ERR(state)) {
4710 ret = PTR_ERR(state);
4711 DRM_ERROR("Duplicating state failed with %i\n", ret);
4715 ret = drm_atomic_helper_disable_all(dev, ctx);
4717 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
4718 drm_atomic_state_put(state);
4722 dev_priv->modeset_restore_state = state;
4723 state->acquire_ctx = ctx;
4726 void intel_finish_reset(struct drm_i915_private *dev_priv)
4728 struct drm_device *dev = &dev_priv->drm;
4729 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4730 struct drm_atomic_state *state;
4733 /* reset doesn't touch the display */
4734 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
4737 state = fetch_and_zero(&dev_priv->modeset_restore_state);
4741 /* reset doesn't touch the display */
4742 if (!gpu_reset_clobbers_display(dev_priv)) {
4743 /* for testing only restore the display */
4744 ret = __intel_display_resume(dev, state, ctx);
4746 DRM_ERROR("Restoring old state failed with %i\n", ret);
4749 * The display has been reset as well,
4750 * so need a full re-initialization.
4752 intel_pps_unlock_regs_wa(dev_priv);
4753 intel_modeset_init_hw(dev_priv);
4754 intel_init_clock_gating(dev_priv);
4756 spin_lock_irq(&dev_priv->irq_lock);
4757 if (dev_priv->display.hpd_irq_setup)
4758 dev_priv->display.hpd_irq_setup(dev_priv);
4759 spin_unlock_irq(&dev_priv->irq_lock);
4761 ret = __intel_display_resume(dev, state, ctx);
4763 DRM_ERROR("Restoring old state failed with %i\n", ret);
4765 intel_hpd_init(dev_priv);
4768 drm_atomic_state_put(state);
4770 drm_modeset_drop_locks(ctx);
4771 drm_modeset_acquire_fini(ctx);
4772 mutex_unlock(&dev->mode_config.mutex);
4774 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4777 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4779 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4780 enum pipe pipe = crtc->pipe;
4783 tmp = I915_READ(PIPE_CHICKEN(pipe));
4786 * Display WA #1153: icl
4787 * enable hardware to bypass the alpha math
4788 * and rounding for per-pixel values 00 and 0xff
4790 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4792 * Display WA # 1605353570: icl
4793 * Set the pixel rounding bit to 1 for allowing
4794 * passthrough of Frame buffer pixels unmodified
4797 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
4798 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4801 static void icl_enable_trans_port_sync(const struct intel_crtc_state *crtc_state)
4803 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4804 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4805 u32 trans_ddi_func_ctl2_val;
4809 * Configure the master select and enable Transcoder Port Sync for
4810 * Slave CRTCs transcoder.
4812 if (crtc_state->master_transcoder == INVALID_TRANSCODER)
4815 if (crtc_state->master_transcoder == TRANSCODER_EDP)
4818 master_select = crtc_state->master_transcoder + 1;
4820 /* Set the master select bits for Tranascoder Port Sync */
4821 trans_ddi_func_ctl2_val = (PORT_SYNC_MODE_MASTER_SELECT(master_select) &
4822 PORT_SYNC_MODE_MASTER_SELECT_MASK) <<
4823 PORT_SYNC_MODE_MASTER_SELECT_SHIFT;
4824 /* Enable Transcoder Port Sync */
4825 trans_ddi_func_ctl2_val |= PORT_SYNC_MODE_ENABLE;
4827 I915_WRITE(TRANS_DDI_FUNC_CTL2(crtc_state->cpu_transcoder),
4828 trans_ddi_func_ctl2_val);
4831 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4833 struct drm_device *dev = crtc->base.dev;
4834 struct drm_i915_private *dev_priv = to_i915(dev);
4835 enum pipe pipe = crtc->pipe;
4839 /* enable normal train */
4840 reg = FDI_TX_CTL(pipe);
4841 temp = I915_READ(reg);
4842 if (IS_IVYBRIDGE(dev_priv)) {
4843 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4844 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4846 temp &= ~FDI_LINK_TRAIN_NONE;
4847 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4849 I915_WRITE(reg, temp);
4851 reg = FDI_RX_CTL(pipe);
4852 temp = I915_READ(reg);
4853 if (HAS_PCH_CPT(dev_priv)) {
4854 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4855 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4857 temp &= ~FDI_LINK_TRAIN_NONE;
4858 temp |= FDI_LINK_TRAIN_NONE;
4860 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4862 /* wait one idle pattern time */
4866 /* IVB wants error correction enabled */
4867 if (IS_IVYBRIDGE(dev_priv))
4868 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4869 FDI_FE_ERRC_ENABLE);
4872 /* The FDI link training functions for ILK/Ibexpeak. */
4873 static void ilk_fdi_link_train(struct intel_crtc *crtc,
4874 const struct intel_crtc_state *crtc_state)
4876 struct drm_device *dev = crtc->base.dev;
4877 struct drm_i915_private *dev_priv = to_i915(dev);
4878 enum pipe pipe = crtc->pipe;
4882 /* FDI needs bits from pipe first */
4883 assert_pipe_enabled(dev_priv, crtc_state->cpu_transcoder);
4885 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4887 reg = FDI_RX_IMR(pipe);
4888 temp = I915_READ(reg);
4889 temp &= ~FDI_RX_SYMBOL_LOCK;
4890 temp &= ~FDI_RX_BIT_LOCK;
4891 I915_WRITE(reg, temp);
4895 /* enable CPU FDI TX and PCH FDI RX */
4896 reg = FDI_TX_CTL(pipe);
4897 temp = I915_READ(reg);
4898 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4899 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4900 temp &= ~FDI_LINK_TRAIN_NONE;
4901 temp |= FDI_LINK_TRAIN_PATTERN_1;
4902 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4904 reg = FDI_RX_CTL(pipe);
4905 temp = I915_READ(reg);
4906 temp &= ~FDI_LINK_TRAIN_NONE;
4907 temp |= FDI_LINK_TRAIN_PATTERN_1;
4908 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4913 /* Ironlake workaround, enable clock pointer after FDI enable*/
4914 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4915 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4916 FDI_RX_PHASE_SYNC_POINTER_EN);
4918 reg = FDI_RX_IIR(pipe);
4919 for (tries = 0; tries < 5; tries++) {
4920 temp = I915_READ(reg);
4921 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4923 if ((temp & FDI_RX_BIT_LOCK)) {
4924 DRM_DEBUG_KMS("FDI train 1 done.\n");
4925 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4930 DRM_ERROR("FDI train 1 fail!\n");
4933 reg = FDI_TX_CTL(pipe);
4934 temp = I915_READ(reg);
4935 temp &= ~FDI_LINK_TRAIN_NONE;
4936 temp |= FDI_LINK_TRAIN_PATTERN_2;
4937 I915_WRITE(reg, temp);
4939 reg = FDI_RX_CTL(pipe);
4940 temp = I915_READ(reg);
4941 temp &= ~FDI_LINK_TRAIN_NONE;
4942 temp |= FDI_LINK_TRAIN_PATTERN_2;
4943 I915_WRITE(reg, temp);
4948 reg = FDI_RX_IIR(pipe);
4949 for (tries = 0; tries < 5; tries++) {
4950 temp = I915_READ(reg);
4951 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4953 if (temp & FDI_RX_SYMBOL_LOCK) {
4954 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4955 DRM_DEBUG_KMS("FDI train 2 done.\n");
4960 DRM_ERROR("FDI train 2 fail!\n");
4962 DRM_DEBUG_KMS("FDI train done\n");
4966 static const int snb_b_fdi_train_param[] = {
4967 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4968 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4969 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4970 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4973 /* The FDI link training functions for SNB/Cougarpoint. */
4974 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4975 const struct intel_crtc_state *crtc_state)
4977 struct drm_device *dev = crtc->base.dev;
4978 struct drm_i915_private *dev_priv = to_i915(dev);
4979 enum pipe pipe = crtc->pipe;
4983 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4985 reg = FDI_RX_IMR(pipe);
4986 temp = I915_READ(reg);
4987 temp &= ~FDI_RX_SYMBOL_LOCK;
4988 temp &= ~FDI_RX_BIT_LOCK;
4989 I915_WRITE(reg, temp);
4994 /* enable CPU FDI TX and PCH FDI RX */
4995 reg = FDI_TX_CTL(pipe);
4996 temp = I915_READ(reg);
4997 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4998 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4999 temp &= ~FDI_LINK_TRAIN_NONE;
5000 temp |= FDI_LINK_TRAIN_PATTERN_1;
5001 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5003 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
5004 I915_WRITE(reg, temp | FDI_TX_ENABLE);
5006 I915_WRITE(FDI_RX_MISC(pipe),
5007 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
5009 reg = FDI_RX_CTL(pipe);
5010 temp = I915_READ(reg);
5011 if (HAS_PCH_CPT(dev_priv)) {
5012 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5013 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5015 temp &= ~FDI_LINK_TRAIN_NONE;
5016 temp |= FDI_LINK_TRAIN_PATTERN_1;
5018 I915_WRITE(reg, temp | FDI_RX_ENABLE);
5023 for (i = 0; i < 4; i++) {
5024 reg = FDI_TX_CTL(pipe);
5025 temp = I915_READ(reg);
5026 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5027 temp |= snb_b_fdi_train_param[i];
5028 I915_WRITE(reg, temp);
5033 for (retry = 0; retry < 5; retry++) {
5034 reg = FDI_RX_IIR(pipe);
5035 temp = I915_READ(reg);
5036 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
5037 if (temp & FDI_RX_BIT_LOCK) {
5038 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
5039 DRM_DEBUG_KMS("FDI train 1 done.\n");
5048 DRM_ERROR("FDI train 1 fail!\n");
5051 reg = FDI_TX_CTL(pipe);
5052 temp = I915_READ(reg);
5053 temp &= ~FDI_LINK_TRAIN_NONE;
5054 temp |= FDI_LINK_TRAIN_PATTERN_2;
5055 if (IS_GEN(dev_priv, 6)) {
5056 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5058 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
5060 I915_WRITE(reg, temp);
5062 reg = FDI_RX_CTL(pipe);
5063 temp = I915_READ(reg);
5064 if (HAS_PCH_CPT(dev_priv)) {
5065 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5066 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
5068 temp &= ~FDI_LINK_TRAIN_NONE;
5069 temp |= FDI_LINK_TRAIN_PATTERN_2;
5071 I915_WRITE(reg, temp);
5076 for (i = 0; i < 4; i++) {
5077 reg = FDI_TX_CTL(pipe);
5078 temp = I915_READ(reg);
5079 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5080 temp |= snb_b_fdi_train_param[i];
5081 I915_WRITE(reg, temp);
5086 for (retry = 0; retry < 5; retry++) {
5087 reg = FDI_RX_IIR(pipe);
5088 temp = I915_READ(reg);
5089 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
5090 if (temp & FDI_RX_SYMBOL_LOCK) {
5091 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
5092 DRM_DEBUG_KMS("FDI train 2 done.\n");
5101 DRM_ERROR("FDI train 2 fail!\n");
5103 DRM_DEBUG_KMS("FDI train done.\n");
5106 /* Manual link training for Ivy Bridge A0 parts */
5107 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
5108 const struct intel_crtc_state *crtc_state)
5110 struct drm_device *dev = crtc->base.dev;
5111 struct drm_i915_private *dev_priv = to_i915(dev);
5112 enum pipe pipe = crtc->pipe;
5116 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5118 reg = FDI_RX_IMR(pipe);
5119 temp = I915_READ(reg);
5120 temp &= ~FDI_RX_SYMBOL_LOCK;
5121 temp &= ~FDI_RX_BIT_LOCK;
5122 I915_WRITE(reg, temp);
5127 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
5128 I915_READ(FDI_RX_IIR(pipe)));
5130 /* Try each vswing and preemphasis setting twice before moving on */
5131 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
5132 /* disable first in case we need to retry */
5133 reg = FDI_TX_CTL(pipe);
5134 temp = I915_READ(reg);
5135 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
5136 temp &= ~FDI_TX_ENABLE;
5137 I915_WRITE(reg, temp);
5139 reg = FDI_RX_CTL(pipe);
5140 temp = I915_READ(reg);
5141 temp &= ~FDI_LINK_TRAIN_AUTO;
5142 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5143 temp &= ~FDI_RX_ENABLE;
5144 I915_WRITE(reg, temp);
5146 /* enable CPU FDI TX and PCH FDI RX */
5147 reg = FDI_TX_CTL(pipe);
5148 temp = I915_READ(reg);
5149 temp &= ~FDI_DP_PORT_WIDTH_MASK;
5150 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5151 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
5152 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5153 temp |= snb_b_fdi_train_param[j/2];
5154 temp |= FDI_COMPOSITE_SYNC;
5155 I915_WRITE(reg, temp | FDI_TX_ENABLE);
5157 I915_WRITE(FDI_RX_MISC(pipe),
5158 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
5160 reg = FDI_RX_CTL(pipe);
5161 temp = I915_READ(reg);
5162 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5163 temp |= FDI_COMPOSITE_SYNC;
5164 I915_WRITE(reg, temp | FDI_RX_ENABLE);
5167 udelay(1); /* should be 0.5us */
5169 for (i = 0; i < 4; i++) {
5170 reg = FDI_RX_IIR(pipe);
5171 temp = I915_READ(reg);
5172 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
5174 if (temp & FDI_RX_BIT_LOCK ||
5175 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
5176 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
5177 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
5181 udelay(1); /* should be 0.5us */
5184 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
5189 reg = FDI_TX_CTL(pipe);
5190 temp = I915_READ(reg);
5191 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
5192 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
5193 I915_WRITE(reg, temp);
5195 reg = FDI_RX_CTL(pipe);
5196 temp = I915_READ(reg);
5197 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5198 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
5199 I915_WRITE(reg, temp);
5202 udelay(2); /* should be 1.5us */
5204 for (i = 0; i < 4; i++) {
5205 reg = FDI_RX_IIR(pipe);
5206 temp = I915_READ(reg);
5207 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
5209 if (temp & FDI_RX_SYMBOL_LOCK ||
5210 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
5211 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
5212 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
5216 udelay(2); /* should be 1.5us */
5219 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
5223 DRM_DEBUG_KMS("FDI train done.\n");
5226 static void ilk_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
5228 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
5229 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5230 enum pipe pipe = intel_crtc->pipe;
5234 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
5235 reg = FDI_RX_CTL(pipe);
5236 temp = I915_READ(reg);
5237 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
5238 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5239 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5240 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
5245 /* Switch from Rawclk to PCDclk */
5246 temp = I915_READ(reg);
5247 I915_WRITE(reg, temp | FDI_PCDCLK);
5252 /* Enable CPU FDI TX PLL, always on for Ironlake */
5253 reg = FDI_TX_CTL(pipe);
5254 temp = I915_READ(reg);
5255 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
5256 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
5263 static void ilk_fdi_pll_disable(struct intel_crtc *intel_crtc)
5265 struct drm_device *dev = intel_crtc->base.dev;
5266 struct drm_i915_private *dev_priv = to_i915(dev);
5267 enum pipe pipe = intel_crtc->pipe;
5271 /* Switch from PCDclk to Rawclk */
5272 reg = FDI_RX_CTL(pipe);
5273 temp = I915_READ(reg);
5274 I915_WRITE(reg, temp & ~FDI_PCDCLK);
5276 /* Disable CPU FDI TX PLL */
5277 reg = FDI_TX_CTL(pipe);
5278 temp = I915_READ(reg);
5279 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
5284 reg = FDI_RX_CTL(pipe);
5285 temp = I915_READ(reg);
5286 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
5288 /* Wait for the clocks to turn off. */
5293 static void ilk_fdi_disable(struct intel_crtc *crtc)
5295 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5296 enum pipe pipe = crtc->pipe;
5300 /* disable CPU FDI tx and PCH FDI rx */
5301 reg = FDI_TX_CTL(pipe);
5302 temp = I915_READ(reg);
5303 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
5306 reg = FDI_RX_CTL(pipe);
5307 temp = I915_READ(reg);
5308 temp &= ~(0x7 << 16);
5309 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5310 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
5315 /* Ironlake workaround, disable clock pointer after downing FDI */
5316 if (HAS_PCH_IBX(dev_priv))
5317 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
5319 /* still set train pattern 1 */
5320 reg = FDI_TX_CTL(pipe);
5321 temp = I915_READ(reg);
5322 temp &= ~FDI_LINK_TRAIN_NONE;
5323 temp |= FDI_LINK_TRAIN_PATTERN_1;
5324 I915_WRITE(reg, temp);
5326 reg = FDI_RX_CTL(pipe);
5327 temp = I915_READ(reg);
5328 if (HAS_PCH_CPT(dev_priv)) {
5329 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5330 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5332 temp &= ~FDI_LINK_TRAIN_NONE;
5333 temp |= FDI_LINK_TRAIN_PATTERN_1;
5335 /* BPC in FDI rx is consistent with that in PIPECONF */
5336 temp &= ~(0x07 << 16);
5337 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5338 I915_WRITE(reg, temp);
5344 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
5346 struct drm_crtc *crtc;
5349 drm_for_each_crtc(crtc, &dev_priv->drm) {
5350 struct drm_crtc_commit *commit;
5351 spin_lock(&crtc->commit_lock);
5352 commit = list_first_entry_or_null(&crtc->commit_list,
5353 struct drm_crtc_commit, commit_entry);
5354 cleanup_done = commit ?
5355 try_wait_for_completion(&commit->cleanup_done) : true;
5356 spin_unlock(&crtc->commit_lock);
5361 drm_crtc_wait_one_vblank(crtc);
5369 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
5373 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
5375 mutex_lock(&dev_priv->sb_lock);
5377 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5378 temp |= SBI_SSCCTL_DISABLE;
5379 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5381 mutex_unlock(&dev_priv->sb_lock);
5384 /* Program iCLKIP clock to the desired frequency */
5385 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
5387 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5388 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5389 int clock = crtc_state->hw.adjusted_mode.crtc_clock;
5390 u32 divsel, phaseinc, auxdiv, phasedir = 0;
5393 lpt_disable_iclkip(dev_priv);
5395 /* The iCLK virtual clock root frequency is in MHz,
5396 * but the adjusted_mode->crtc_clock in in KHz. To get the
5397 * divisors, it is necessary to divide one by another, so we
5398 * convert the virtual clock precision to KHz here for higher
5401 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
5402 u32 iclk_virtual_root_freq = 172800 * 1000;
5403 u32 iclk_pi_range = 64;
5404 u32 desired_divisor;
5406 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5408 divsel = (desired_divisor / iclk_pi_range) - 2;
5409 phaseinc = desired_divisor % iclk_pi_range;
5412 * Near 20MHz is a corner case which is
5413 * out of range for the 7-bit divisor
5419 /* This should not happen with any sane values */
5420 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5421 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5422 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
5423 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5425 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5432 mutex_lock(&dev_priv->sb_lock);
5434 /* Program SSCDIVINTPHASE6 */
5435 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5436 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5437 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5438 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5439 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5440 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5441 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5442 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5444 /* Program SSCAUXDIV */
5445 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5446 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5447 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5448 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5450 /* Enable modulator and associated divider */
5451 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5452 temp &= ~SBI_SSCCTL_DISABLE;
5453 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5455 mutex_unlock(&dev_priv->sb_lock);
5457 /* Wait for initialization time */
5460 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5463 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5465 u32 divsel, phaseinc, auxdiv;
5466 u32 iclk_virtual_root_freq = 172800 * 1000;
5467 u32 iclk_pi_range = 64;
5468 u32 desired_divisor;
5471 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5474 mutex_lock(&dev_priv->sb_lock);
5476 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5477 if (temp & SBI_SSCCTL_DISABLE) {
5478 mutex_unlock(&dev_priv->sb_lock);
5482 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5483 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5484 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5485 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5486 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5488 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5489 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5490 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5492 mutex_unlock(&dev_priv->sb_lock);
5494 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5496 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5497 desired_divisor << auxdiv);
5500 static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5501 enum pipe pch_transcoder)
5503 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5504 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5505 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5507 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
5508 I915_READ(HTOTAL(cpu_transcoder)));
5509 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
5510 I915_READ(HBLANK(cpu_transcoder)));
5511 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
5512 I915_READ(HSYNC(cpu_transcoder)));
5514 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
5515 I915_READ(VTOTAL(cpu_transcoder)));
5516 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
5517 I915_READ(VBLANK(cpu_transcoder)));
5518 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
5519 I915_READ(VSYNC(cpu_transcoder)));
5520 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5521 I915_READ(VSYNCSHIFT(cpu_transcoder)));
5524 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5528 temp = I915_READ(SOUTH_CHICKEN1);
5529 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5532 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5533 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5535 temp &= ~FDI_BC_BIFURCATION_SELECT;
5537 temp |= FDI_BC_BIFURCATION_SELECT;
5539 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
5540 I915_WRITE(SOUTH_CHICKEN1, temp);
5541 POSTING_READ(SOUTH_CHICKEN1);
5544 static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5546 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5547 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5549 switch (crtc->pipe) {
5553 if (crtc_state->fdi_lanes > 2)
5554 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5556 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5560 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5569 * Finds the encoder associated with the given CRTC. This can only be
5570 * used when we know that the CRTC isn't feeding multiple encoders!
5572 static struct intel_encoder *
5573 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5574 const struct intel_crtc_state *crtc_state)
5576 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5577 const struct drm_connector_state *connector_state;
5578 const struct drm_connector *connector;
5579 struct intel_encoder *encoder = NULL;
5580 int num_encoders = 0;
5583 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5584 if (connector_state->crtc != &crtc->base)
5587 encoder = to_intel_encoder(connector_state->best_encoder);
5591 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
5592 num_encoders, pipe_name(crtc->pipe));
5598 * Enable PCH resources required for PCH ports:
5600 * - FDI training & RX/TX
5601 * - update transcoder timings
5602 * - DP transcoding bits
5605 static void ilk_pch_enable(const struct intel_atomic_state *state,
5606 const struct intel_crtc_state *crtc_state)
5608 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5609 struct drm_device *dev = crtc->base.dev;
5610 struct drm_i915_private *dev_priv = to_i915(dev);
5611 enum pipe pipe = crtc->pipe;
5614 assert_pch_transcoder_disabled(dev_priv, pipe);
5616 if (IS_IVYBRIDGE(dev_priv))
5617 ivb_update_fdi_bc_bifurcation(crtc_state);
5619 /* Write the TU size bits before fdi link training, so that error
5620 * detection works. */
5621 I915_WRITE(FDI_RX_TUSIZE1(pipe),
5622 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5624 /* For PCH output, training FDI link */
5625 dev_priv->display.fdi_link_train(crtc, crtc_state);
5627 /* We need to program the right clock selection before writing the pixel
5628 * mutliplier into the DPLL. */
5629 if (HAS_PCH_CPT(dev_priv)) {
5632 temp = I915_READ(PCH_DPLL_SEL);
5633 temp |= TRANS_DPLL_ENABLE(pipe);
5634 sel = TRANS_DPLLB_SEL(pipe);
5635 if (crtc_state->shared_dpll ==
5636 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5640 I915_WRITE(PCH_DPLL_SEL, temp);
5643 /* XXX: pch pll's can be enabled any time before we enable the PCH
5644 * transcoder, and we actually should do this to not upset any PCH
5645 * transcoder that already use the clock when we share it.
5647 * Note that enable_shared_dpll tries to do the right thing, but
5648 * get_shared_dpll unconditionally resets the pll - we need that to have
5649 * the right LVDS enable sequence. */
5650 intel_enable_shared_dpll(crtc_state);
5652 /* set transcoder timing, panel must allow it */
5653 assert_panel_unlocked(dev_priv, pipe);
5654 ilk_pch_transcoder_set_timings(crtc_state, pipe);
5656 intel_fdi_normal_train(crtc);
5658 /* For PCH DP, enable TRANS_DP_CTL */
5659 if (HAS_PCH_CPT(dev_priv) &&
5660 intel_crtc_has_dp_encoder(crtc_state)) {
5661 const struct drm_display_mode *adjusted_mode =
5662 &crtc_state->hw.adjusted_mode;
5663 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5664 i915_reg_t reg = TRANS_DP_CTL(pipe);
5667 temp = I915_READ(reg);
5668 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5669 TRANS_DP_SYNC_MASK |
5671 temp |= TRANS_DP_OUTPUT_ENABLE;
5672 temp |= bpc << 9; /* same format but at 11:9 */
5674 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5675 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5676 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5677 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5679 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5680 WARN_ON(port < PORT_B || port > PORT_D);
5681 temp |= TRANS_DP_PORT_SEL(port);
5683 I915_WRITE(reg, temp);
5686 ilk_enable_pch_transcoder(crtc_state);
5689 static void lpt_pch_enable(const struct intel_atomic_state *state,
5690 const struct intel_crtc_state *crtc_state)
5692 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5693 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5694 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5696 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5698 lpt_program_iclkip(crtc_state);
5700 /* Set transcoder timing. */
5701 ilk_pch_transcoder_set_timings(crtc_state, PIPE_A);
5703 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5706 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
5709 i915_reg_t dslreg = PIPEDSL(pipe);
5712 temp = I915_READ(dslreg);
5714 if (wait_for(I915_READ(dslreg) != temp, 5)) {
5715 if (wait_for(I915_READ(dslreg) != temp, 5))
5716 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
5721 * The hardware phase 0.0 refers to the center of the pixel.
5722 * We want to start from the top/left edge which is phase
5723 * -0.5. That matches how the hardware calculates the scaling
5724 * factors (from top-left of the first pixel to bottom-right
5725 * of the last pixel, as opposed to the pixel centers).
5727 * For 4:2:0 subsampled chroma planes we obviously have to
5728 * adjust that so that the chroma sample position lands in
5731 * Note that for packed YCbCr 4:2:2 formats there is no way to
5732 * control chroma siting. The hardware simply replicates the
5733 * chroma samples for both of the luma samples, and thus we don't
5734 * actually get the expected MPEG2 chroma siting convention :(
5735 * The same behaviour is observed on pre-SKL platforms as well.
5737 * Theory behind the formula (note that we ignore sub-pixel
5738 * source coordinates):
5739 * s = source sample position
5740 * d = destination sample position
5745 * | | 1.5 (initial phase)
5753 * | -0.375 (initial phase)
5760 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5762 int phase = -0x8000;
5766 phase += (sub - 1) * 0x8000 / sub;
5768 phase += scale / (2 * sub);
5771 * Hardware initial phase limited to [-0.5:1.5].
5772 * Since the max hardware scale factor is 3.0, we
5773 * should never actually excdeed 1.0 here.
5775 WARN_ON(phase < -0x8000 || phase > 0x18000);
5778 phase = 0x10000 + phase;
5780 trip = PS_PHASE_TRIP;
5782 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5785 #define SKL_MIN_SRC_W 8
5786 #define SKL_MAX_SRC_W 4096
5787 #define SKL_MIN_SRC_H 8
5788 #define SKL_MAX_SRC_H 4096
5789 #define SKL_MIN_DST_W 8
5790 #define SKL_MAX_DST_W 4096
5791 #define SKL_MIN_DST_H 8
5792 #define SKL_MAX_DST_H 4096
5793 #define ICL_MAX_SRC_W 5120
5794 #define ICL_MAX_SRC_H 4096
5795 #define ICL_MAX_DST_W 5120
5796 #define ICL_MAX_DST_H 4096
5797 #define SKL_MIN_YUV_420_SRC_W 16
5798 #define SKL_MIN_YUV_420_SRC_H 16
5801 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5802 unsigned int scaler_user, int *scaler_id,
5803 int src_w, int src_h, int dst_w, int dst_h,
5804 const struct drm_format_info *format,
5805 u64 modifier, bool need_scaler)
5807 struct intel_crtc_scaler_state *scaler_state =
5808 &crtc_state->scaler_state;
5809 struct intel_crtc *intel_crtc =
5810 to_intel_crtc(crtc_state->uapi.crtc);
5811 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5812 const struct drm_display_mode *adjusted_mode =
5813 &crtc_state->hw.adjusted_mode;
5816 * Src coordinates are already rotated by 270 degrees for
5817 * the 90/270 degree plane rotation cases (to match the
5818 * GTT mapping), hence no need to account for rotation here.
5820 if (src_w != dst_w || src_h != dst_h)
5824 * Scaling/fitting not supported in IF-ID mode in GEN9+
5825 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5826 * Once NV12 is enabled, handle it here while allocating scaler
5829 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->hw.enable &&
5830 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5831 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5836 * if plane is being disabled or scaler is no more required or force detach
5837 * - free scaler binded to this plane/crtc
5838 * - in order to do this, update crtc->scaler_usage
5840 * Here scaler state in crtc_state is set free so that
5841 * scaler can be assigned to other user. Actual register
5842 * update to free the scaler is done in plane/panel-fit programming.
5843 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5845 if (force_detach || !need_scaler) {
5846 if (*scaler_id >= 0) {
5847 scaler_state->scaler_users &= ~(1 << scaler_user);
5848 scaler_state->scalers[*scaler_id].in_use = 0;
5850 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5851 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5852 intel_crtc->pipe, scaler_user, *scaler_id,
5853 scaler_state->scaler_users);
5859 if (format && intel_format_info_is_yuv_semiplanar(format, modifier) &&
5860 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5861 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
5866 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5867 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5868 (INTEL_GEN(dev_priv) >= 11 &&
5869 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5870 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5871 (INTEL_GEN(dev_priv) < 11 &&
5872 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5873 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5874 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
5875 "size is out of scaler range\n",
5876 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
5880 /* mark this plane as a scaler user in crtc_state */
5881 scaler_state->scaler_users |= (1 << scaler_user);
5882 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5883 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5884 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5885 scaler_state->scaler_users);
5891 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5893 * @state: crtc's scaler state
5896 * 0 - scaler_usage updated successfully
5897 * error - requested scaling cannot be supported or other error condition
5899 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5901 const struct drm_display_mode *adjusted_mode = &state->hw.adjusted_mode;
5902 bool need_scaler = false;
5904 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5907 return skl_update_scaler(state, !state->hw.active, SKL_CRTC_INDEX,
5908 &state->scaler_state.scaler_id,
5909 state->pipe_src_w, state->pipe_src_h,
5910 adjusted_mode->crtc_hdisplay,
5911 adjusted_mode->crtc_vdisplay, NULL, 0,
5916 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5917 * @crtc_state: crtc's scaler state
5918 * @plane_state: atomic plane state to update
5921 * 0 - scaler_usage updated successfully
5922 * error - requested scaling cannot be supported or other error condition
5924 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5925 struct intel_plane_state *plane_state)
5927 struct intel_plane *intel_plane =
5928 to_intel_plane(plane_state->uapi.plane);
5929 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5930 struct drm_framebuffer *fb = plane_state->hw.fb;
5932 bool force_detach = !fb || !plane_state->uapi.visible;
5933 bool need_scaler = false;
5935 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5936 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5937 fb && intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
5940 ret = skl_update_scaler(crtc_state, force_detach,
5941 drm_plane_index(&intel_plane->base),
5942 &plane_state->scaler_id,
5943 drm_rect_width(&plane_state->uapi.src) >> 16,
5944 drm_rect_height(&plane_state->uapi.src) >> 16,
5945 drm_rect_width(&plane_state->uapi.dst),
5946 drm_rect_height(&plane_state->uapi.dst),
5947 fb ? fb->format : NULL,
5948 fb ? fb->modifier : 0,
5951 if (ret || plane_state->scaler_id < 0)
5954 /* check colorkey */
5955 if (plane_state->ckey.flags) {
5956 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5957 intel_plane->base.base.id,
5958 intel_plane->base.name);
5962 /* Check src format */
5963 switch (fb->format->format) {
5964 case DRM_FORMAT_RGB565:
5965 case DRM_FORMAT_XBGR8888:
5966 case DRM_FORMAT_XRGB8888:
5967 case DRM_FORMAT_ABGR8888:
5968 case DRM_FORMAT_ARGB8888:
5969 case DRM_FORMAT_XRGB2101010:
5970 case DRM_FORMAT_XBGR2101010:
5971 case DRM_FORMAT_ARGB2101010:
5972 case DRM_FORMAT_ABGR2101010:
5973 case DRM_FORMAT_YUYV:
5974 case DRM_FORMAT_YVYU:
5975 case DRM_FORMAT_UYVY:
5976 case DRM_FORMAT_VYUY:
5977 case DRM_FORMAT_NV12:
5978 case DRM_FORMAT_P010:
5979 case DRM_FORMAT_P012:
5980 case DRM_FORMAT_P016:
5981 case DRM_FORMAT_Y210:
5982 case DRM_FORMAT_Y212:
5983 case DRM_FORMAT_Y216:
5984 case DRM_FORMAT_XVYU2101010:
5985 case DRM_FORMAT_XVYU12_16161616:
5986 case DRM_FORMAT_XVYU16161616:
5988 case DRM_FORMAT_XBGR16161616F:
5989 case DRM_FORMAT_ABGR16161616F:
5990 case DRM_FORMAT_XRGB16161616F:
5991 case DRM_FORMAT_ARGB16161616F:
5992 if (INTEL_GEN(dev_priv) >= 11)
5996 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5997 intel_plane->base.base.id, intel_plane->base.name,
5998 fb->base.id, fb->format->format);
6005 void skl_scaler_disable(const struct intel_crtc_state *old_crtc_state)
6007 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
6010 for (i = 0; i < crtc->num_scalers; i++)
6011 skl_detach_scaler(crtc, i);
6014 static void skl_pfit_enable(const struct intel_crtc_state *crtc_state)
6016 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6017 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6018 enum pipe pipe = crtc->pipe;
6019 const struct intel_crtc_scaler_state *scaler_state =
6020 &crtc_state->scaler_state;
6022 if (crtc_state->pch_pfit.enabled) {
6023 u16 uv_rgb_hphase, uv_rgb_vphase;
6024 int pfit_w, pfit_h, hscale, vscale;
6027 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
6030 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
6031 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
6033 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
6034 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
6036 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
6037 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
6039 id = scaler_state->scaler_id;
6040 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
6041 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
6042 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
6043 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
6044 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
6045 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
6046 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
6047 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
6051 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
6053 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6054 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6055 enum pipe pipe = crtc->pipe;
6057 if (crtc_state->pch_pfit.enabled) {
6058 /* Force use of hard-coded filter coefficients
6059 * as some pre-programmed values are broken,
6062 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
6063 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
6064 PF_PIPE_SEL_IVB(pipe));
6066 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
6067 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
6068 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
6072 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
6074 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6075 struct drm_device *dev = crtc->base.dev;
6076 struct drm_i915_private *dev_priv = to_i915(dev);
6078 if (!crtc_state->ips_enabled)
6082 * We can only enable IPS after we enable a plane and wait for a vblank
6083 * This function is called from post_plane_update, which is run after
6086 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
6088 if (IS_BROADWELL(dev_priv)) {
6089 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
6090 IPS_ENABLE | IPS_PCODE_CONTROL));
6091 /* Quoting Art Runyan: "its not safe to expect any particular
6092 * value in IPS_CTL bit 31 after enabling IPS through the
6093 * mailbox." Moreover, the mailbox may return a bogus state,
6094 * so we need to just enable it and continue on.
6097 I915_WRITE(IPS_CTL, IPS_ENABLE);
6098 /* The bit only becomes 1 in the next vblank, so this wait here
6099 * is essentially intel_wait_for_vblank. If we don't have this
6100 * and don't wait for vblanks until the end of crtc_enable, then
6101 * the HW state readout code will complain that the expected
6102 * IPS_CTL value is not the one we read. */
6103 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
6104 DRM_ERROR("Timed out waiting for IPS enable\n");
6108 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
6110 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6111 struct drm_device *dev = crtc->base.dev;
6112 struct drm_i915_private *dev_priv = to_i915(dev);
6114 if (!crtc_state->ips_enabled)
6117 if (IS_BROADWELL(dev_priv)) {
6118 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
6120 * Wait for PCODE to finish disabling IPS. The BSpec specified
6121 * 42ms timeout value leads to occasional timeouts so use 100ms
6124 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
6125 DRM_ERROR("Timed out waiting for IPS disable\n");
6127 I915_WRITE(IPS_CTL, 0);
6128 POSTING_READ(IPS_CTL);
6131 /* We need to wait for a vblank before we can disable the plane. */
6132 intel_wait_for_vblank(dev_priv, crtc->pipe);
6135 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
6137 if (intel_crtc->overlay)
6138 (void) intel_overlay_switch_off(intel_crtc->overlay);
6140 /* Let userspace switch the overlay on again. In most cases userspace
6141 * has to recompute where to put it anyway.
6145 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
6146 const struct intel_crtc_state *new_crtc_state)
6148 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6149 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6151 if (!old_crtc_state->ips_enabled)
6154 if (needs_modeset(new_crtc_state))
6158 * Workaround : Do not read or write the pipe palette/gamma data while
6159 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6161 * Disable IPS before we program the LUT.
6163 if (IS_HASWELL(dev_priv) &&
6164 (new_crtc_state->uapi.color_mgmt_changed ||
6165 new_crtc_state->update_pipe) &&
6166 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6169 return !new_crtc_state->ips_enabled;
6172 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
6173 const struct intel_crtc_state *new_crtc_state)
6175 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6176 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6178 if (!new_crtc_state->ips_enabled)
6181 if (needs_modeset(new_crtc_state))
6185 * Workaround : Do not read or write the pipe palette/gamma data while
6186 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6188 * Re-enable IPS after the LUT has been programmed.
6190 if (IS_HASWELL(dev_priv) &&
6191 (new_crtc_state->uapi.color_mgmt_changed ||
6192 new_crtc_state->update_pipe) &&
6193 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6197 * We can't read out IPS on broadwell, assume the worst and
6198 * forcibly enable IPS on the first fastset.
6200 if (new_crtc_state->update_pipe &&
6201 old_crtc_state->hw.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
6204 return !old_crtc_state->ips_enabled;
6207 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
6209 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6211 if (!crtc_state->nv12_planes)
6214 /* WA Display #0827: Gen9:all */
6215 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
6221 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
6223 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6225 /* Wa_2006604312:icl */
6226 if (crtc_state->scaler_state.scaler_users > 0 && IS_ICELAKE(dev_priv))
6232 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
6233 const struct intel_crtc_state *new_crtc_state)
6235 return (!old_crtc_state->active_planes || needs_modeset(new_crtc_state)) &&
6236 new_crtc_state->active_planes;
6239 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
6240 const struct intel_crtc_state *new_crtc_state)
6242 return old_crtc_state->active_planes &&
6243 (!new_crtc_state->active_planes || needs_modeset(new_crtc_state));
6246 static void intel_post_plane_update(struct intel_atomic_state *state,
6247 struct intel_crtc *crtc)
6249 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6250 struct intel_plane *primary = to_intel_plane(crtc->base.primary);
6251 const struct intel_crtc_state *old_crtc_state =
6252 intel_atomic_get_old_crtc_state(state, crtc);
6253 const struct intel_crtc_state *new_crtc_state =
6254 intel_atomic_get_new_crtc_state(state, crtc);
6255 const struct intel_plane_state *new_primary_state =
6256 intel_atomic_get_new_plane_state(state, primary);
6257 enum pipe pipe = crtc->pipe;
6259 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
6261 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
6262 intel_update_watermarks(crtc);
6264 if (hsw_post_update_enable_ips(old_crtc_state, new_crtc_state))
6265 hsw_enable_ips(new_crtc_state);
6267 if (new_primary_state)
6268 intel_fbc_post_update(crtc);
6270 if (needs_nv12_wa(old_crtc_state) &&
6271 !needs_nv12_wa(new_crtc_state))
6272 skl_wa_827(dev_priv, pipe, false);
6274 if (needs_scalerclk_wa(old_crtc_state) &&
6275 !needs_scalerclk_wa(new_crtc_state))
6276 icl_wa_scalerclkgating(dev_priv, pipe, false);
6279 static void intel_pre_plane_update(struct intel_atomic_state *state,
6280 struct intel_crtc *crtc)
6282 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6283 struct intel_plane *primary = to_intel_plane(crtc->base.primary);
6284 const struct intel_crtc_state *old_crtc_state =
6285 intel_atomic_get_old_crtc_state(state, crtc);
6286 const struct intel_crtc_state *new_crtc_state =
6287 intel_atomic_get_new_crtc_state(state, crtc);
6288 const struct intel_plane_state *new_primary_state =
6289 intel_atomic_get_new_plane_state(state, primary);
6290 enum pipe pipe = crtc->pipe;
6292 if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
6293 hsw_disable_ips(old_crtc_state);
6295 if (new_primary_state &&
6296 intel_fbc_pre_update(crtc, new_crtc_state, new_primary_state))
6297 intel_wait_for_vblank(dev_priv, pipe);
6299 /* Display WA 827 */
6300 if (!needs_nv12_wa(old_crtc_state) &&
6301 needs_nv12_wa(new_crtc_state))
6302 skl_wa_827(dev_priv, pipe, true);
6304 /* Wa_2006604312:icl */
6305 if (!needs_scalerclk_wa(old_crtc_state) &&
6306 needs_scalerclk_wa(new_crtc_state))
6307 icl_wa_scalerclkgating(dev_priv, pipe, true);
6310 * Vblank time updates from the shadow to live plane control register
6311 * are blocked if the memory self-refresh mode is active at that
6312 * moment. So to make sure the plane gets truly disabled, disable
6313 * first the self-refresh mode. The self-refresh enable bit in turn
6314 * will be checked/applied by the HW only at the next frame start
6315 * event which is after the vblank start event, so we need to have a
6316 * wait-for-vblank between disabling the plane and the pipe.
6318 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
6319 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
6320 intel_wait_for_vblank(dev_priv, pipe);
6323 * IVB workaround: must disable low power watermarks for at least
6324 * one frame before enabling scaling. LP watermarks can be re-enabled
6325 * when scaling is disabled.
6327 * WaCxSRDisabledForSpriteScaling:ivb
6329 if (old_crtc_state->hw.active &&
6330 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
6331 intel_wait_for_vblank(dev_priv, pipe);
6334 * If we're doing a modeset we don't need to do any
6335 * pre-vblank watermark programming here.
6337 if (!needs_modeset(new_crtc_state)) {
6339 * For platforms that support atomic watermarks, program the
6340 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6341 * will be the intermediate values that are safe for both pre- and
6342 * post- vblank; when vblank happens, the 'active' values will be set
6343 * to the final 'target' values and we'll do this again to get the
6344 * optimal watermarks. For gen9+ platforms, the values we program here
6345 * will be the final target values which will get automatically latched
6346 * at vblank time; no further programming will be necessary.
6348 * If a platform hasn't been transitioned to atomic watermarks yet,
6349 * we'll continue to update watermarks the old way, if flags tell
6352 if (dev_priv->display.initial_watermarks)
6353 dev_priv->display.initial_watermarks(state, crtc);
6354 else if (new_crtc_state->update_wm_pre)
6355 intel_update_watermarks(crtc);
6359 * Gen2 reports pipe underruns whenever all planes are disabled.
6360 * So disable underrun reporting before all the planes get disabled.
6362 * We do this after .initial_watermarks() so that we have a
6363 * chance of catching underruns with the intermediate watermarks
6364 * vs. the old plane configuration.
6366 if (IS_GEN(dev_priv, 2) && planes_disabling(old_crtc_state, new_crtc_state))
6367 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6370 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6371 struct intel_crtc *crtc)
6373 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6374 const struct intel_crtc_state *new_crtc_state =
6375 intel_atomic_get_new_crtc_state(state, crtc);
6376 unsigned int update_mask = new_crtc_state->update_planes;
6377 const struct intel_plane_state *old_plane_state;
6378 struct intel_plane *plane;
6379 unsigned fb_bits = 0;
6382 intel_crtc_dpms_overlay_disable(crtc);
6384 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6385 if (crtc->pipe != plane->pipe ||
6386 !(update_mask & BIT(plane->id)))
6389 intel_disable_plane(plane, new_crtc_state);
6391 if (old_plane_state->uapi.visible)
6392 fb_bits |= plane->frontbuffer_bit;
6395 intel_frontbuffer_flip(dev_priv, fb_bits);
6399 * intel_connector_primary_encoder - get the primary encoder for a connector
6400 * @connector: connector for which to return the encoder
6402 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6403 * all connectors to their encoder, except for DP-MST connectors which have
6404 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6405 * pointed to by as many DP-MST connectors as there are pipes.
6407 static struct intel_encoder *
6408 intel_connector_primary_encoder(struct intel_connector *connector)
6410 struct intel_encoder *encoder;
6412 if (connector->mst_port)
6413 return &dp_to_dig_port(connector->mst_port)->base;
6415 encoder = intel_attached_encoder(&connector->base);
6421 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6423 struct drm_connector_state *new_conn_state;
6424 struct drm_connector *connector;
6427 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6429 struct intel_connector *intel_connector;
6430 struct intel_encoder *encoder;
6431 struct intel_crtc *crtc;
6433 if (!intel_connector_needs_modeset(state, connector))
6436 intel_connector = to_intel_connector(connector);
6437 encoder = intel_connector_primary_encoder(intel_connector);
6438 if (!encoder->update_prepare)
6441 crtc = new_conn_state->crtc ?
6442 to_intel_crtc(new_conn_state->crtc) : NULL;
6443 encoder->update_prepare(state, encoder, crtc);
6447 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6449 struct drm_connector_state *new_conn_state;
6450 struct drm_connector *connector;
6453 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6455 struct intel_connector *intel_connector;
6456 struct intel_encoder *encoder;
6457 struct intel_crtc *crtc;
6459 if (!intel_connector_needs_modeset(state, connector))
6462 intel_connector = to_intel_connector(connector);
6463 encoder = intel_connector_primary_encoder(intel_connector);
6464 if (!encoder->update_complete)
6467 crtc = new_conn_state->crtc ?
6468 to_intel_crtc(new_conn_state->crtc) : NULL;
6469 encoder->update_complete(state, encoder, crtc);
6473 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
6474 struct intel_crtc *crtc)
6476 const struct intel_crtc_state *crtc_state =
6477 intel_atomic_get_new_crtc_state(state, crtc);
6478 const struct drm_connector_state *conn_state;
6479 struct drm_connector *conn;
6482 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6483 struct intel_encoder *encoder =
6484 to_intel_encoder(conn_state->best_encoder);
6486 if (conn_state->crtc != &crtc->base)
6489 if (encoder->pre_pll_enable)
6490 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
6494 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
6495 struct intel_crtc *crtc)
6497 const struct intel_crtc_state *crtc_state =
6498 intel_atomic_get_new_crtc_state(state, crtc);
6499 const struct drm_connector_state *conn_state;
6500 struct drm_connector *conn;
6503 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6504 struct intel_encoder *encoder =
6505 to_intel_encoder(conn_state->best_encoder);
6507 if (conn_state->crtc != &crtc->base)
6510 if (encoder->pre_enable)
6511 encoder->pre_enable(encoder, crtc_state, conn_state);
6515 static void intel_encoders_enable(struct intel_atomic_state *state,
6516 struct intel_crtc *crtc)
6518 const struct intel_crtc_state *crtc_state =
6519 intel_atomic_get_new_crtc_state(state, crtc);
6520 const struct drm_connector_state *conn_state;
6521 struct drm_connector *conn;
6524 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6525 struct intel_encoder *encoder =
6526 to_intel_encoder(conn_state->best_encoder);
6528 if (conn_state->crtc != &crtc->base)
6531 if (encoder->enable)
6532 encoder->enable(encoder, crtc_state, conn_state);
6533 intel_opregion_notify_encoder(encoder, true);
6537 static void intel_encoders_disable(struct intel_atomic_state *state,
6538 struct intel_crtc *crtc)
6540 const struct intel_crtc_state *old_crtc_state =
6541 intel_atomic_get_old_crtc_state(state, crtc);
6542 const struct drm_connector_state *old_conn_state;
6543 struct drm_connector *conn;
6546 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6547 struct intel_encoder *encoder =
6548 to_intel_encoder(old_conn_state->best_encoder);
6550 if (old_conn_state->crtc != &crtc->base)
6553 intel_opregion_notify_encoder(encoder, false);
6554 if (encoder->disable)
6555 encoder->disable(encoder, old_crtc_state, old_conn_state);
6559 static void intel_encoders_post_disable(struct intel_atomic_state *state,
6560 struct intel_crtc *crtc)
6562 const struct intel_crtc_state *old_crtc_state =
6563 intel_atomic_get_old_crtc_state(state, crtc);
6564 const struct drm_connector_state *old_conn_state;
6565 struct drm_connector *conn;
6568 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6569 struct intel_encoder *encoder =
6570 to_intel_encoder(old_conn_state->best_encoder);
6572 if (old_conn_state->crtc != &crtc->base)
6575 if (encoder->post_disable)
6576 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
6580 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
6581 struct intel_crtc *crtc)
6583 const struct intel_crtc_state *old_crtc_state =
6584 intel_atomic_get_old_crtc_state(state, crtc);
6585 const struct drm_connector_state *old_conn_state;
6586 struct drm_connector *conn;
6589 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6590 struct intel_encoder *encoder =
6591 to_intel_encoder(old_conn_state->best_encoder);
6593 if (old_conn_state->crtc != &crtc->base)
6596 if (encoder->post_pll_disable)
6597 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
6601 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
6602 struct intel_crtc *crtc)
6604 const struct intel_crtc_state *crtc_state =
6605 intel_atomic_get_new_crtc_state(state, crtc);
6606 const struct drm_connector_state *conn_state;
6607 struct drm_connector *conn;
6610 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6611 struct intel_encoder *encoder =
6612 to_intel_encoder(conn_state->best_encoder);
6614 if (conn_state->crtc != &crtc->base)
6617 if (encoder->update_pipe)
6618 encoder->update_pipe(encoder, crtc_state, conn_state);
6622 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6624 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6625 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6627 plane->disable_plane(plane, crtc_state);
6630 static void ilk_crtc_enable(struct intel_atomic_state *state,
6631 struct intel_crtc *crtc)
6633 const struct intel_crtc_state *new_crtc_state =
6634 intel_atomic_get_new_crtc_state(state, crtc);
6635 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6636 enum pipe pipe = crtc->pipe;
6638 if (WARN_ON(crtc->active))
6642 * Sometimes spurious CPU pipe underruns happen during FDI
6643 * training, at least with VGA+HDMI cloning. Suppress them.
6645 * On ILK we get an occasional spurious CPU pipe underruns
6646 * between eDP port A enable and vdd enable. Also PCH port
6647 * enable seems to result in the occasional CPU pipe underrun.
6649 * Spurious PCH underruns also occur during PCH enabling.
6651 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6652 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6654 if (new_crtc_state->has_pch_encoder)
6655 intel_prepare_shared_dpll(new_crtc_state);
6657 if (intel_crtc_has_dp_encoder(new_crtc_state))
6658 intel_dp_set_m_n(new_crtc_state, M1_N1);
6660 intel_set_pipe_timings(new_crtc_state);
6661 intel_set_pipe_src_size(new_crtc_state);
6663 if (new_crtc_state->has_pch_encoder)
6664 intel_cpu_transcoder_set_m_n(new_crtc_state,
6665 &new_crtc_state->fdi_m_n, NULL);
6667 ilk_set_pipeconf(new_crtc_state);
6669 crtc->active = true;
6671 intel_encoders_pre_enable(state, crtc);
6673 if (new_crtc_state->has_pch_encoder) {
6674 /* Note: FDI PLL enabling _must_ be done before we enable the
6675 * cpu pipes, hence this is separate from all the other fdi/pch
6677 ilk_fdi_pll_enable(new_crtc_state);
6679 assert_fdi_tx_disabled(dev_priv, pipe);
6680 assert_fdi_rx_disabled(dev_priv, pipe);
6683 ilk_pfit_enable(new_crtc_state);
6686 * On ILK+ LUT must be loaded before the pipe is running but with
6689 intel_color_load_luts(new_crtc_state);
6690 intel_color_commit(new_crtc_state);
6691 /* update DSPCNTR to configure gamma for pipe bottom color */
6692 intel_disable_primary_plane(new_crtc_state);
6694 if (dev_priv->display.initial_watermarks)
6695 dev_priv->display.initial_watermarks(state, crtc);
6696 intel_enable_pipe(new_crtc_state);
6698 if (new_crtc_state->has_pch_encoder)
6699 ilk_pch_enable(state, new_crtc_state);
6701 intel_crtc_vblank_on(new_crtc_state);
6703 intel_encoders_enable(state, crtc);
6705 if (HAS_PCH_CPT(dev_priv))
6706 cpt_verify_modeset(dev_priv, pipe);
6709 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6710 * And a second vblank wait is needed at least on ILK with
6711 * some interlaced HDMI modes. Let's do the double wait always
6712 * in case there are more corner cases we don't know about.
6714 if (new_crtc_state->has_pch_encoder) {
6715 intel_wait_for_vblank(dev_priv, pipe);
6716 intel_wait_for_vblank(dev_priv, pipe);
6718 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6719 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6722 /* IPS only exists on ULT machines and is tied to pipe A. */
6723 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6725 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6728 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6729 enum pipe pipe, bool apply)
6731 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
6732 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6739 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
6742 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6744 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6745 enum pipe pipe = crtc->pipe;
6748 val = MBUS_DBOX_A_CREDIT(2);
6750 if (INTEL_GEN(dev_priv) >= 12) {
6751 val |= MBUS_DBOX_BW_CREDIT(2);
6752 val |= MBUS_DBOX_B_CREDIT(12);
6754 val |= MBUS_DBOX_BW_CREDIT(1);
6755 val |= MBUS_DBOX_B_CREDIT(8);
6758 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
6761 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
6763 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6764 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6765 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
6768 val = I915_READ(reg);
6769 val &= ~HSW_FRAME_START_DELAY_MASK;
6770 val |= HSW_FRAME_START_DELAY(0);
6771 I915_WRITE(reg, val);
6774 static void hsw_crtc_enable(struct intel_atomic_state *state,
6775 struct intel_crtc *crtc)
6777 const struct intel_crtc_state *new_crtc_state =
6778 intel_atomic_get_new_crtc_state(state, crtc);
6779 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6780 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
6781 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
6782 bool psl_clkgate_wa;
6784 if (WARN_ON(crtc->active))
6787 intel_encoders_pre_pll_enable(state, crtc);
6789 if (new_crtc_state->shared_dpll)
6790 intel_enable_shared_dpll(new_crtc_state);
6792 intel_encoders_pre_enable(state, crtc);
6794 if (intel_crtc_has_dp_encoder(new_crtc_state))
6795 intel_dp_set_m_n(new_crtc_state, M1_N1);
6797 if (!transcoder_is_dsi(cpu_transcoder))
6798 intel_set_pipe_timings(new_crtc_state);
6800 if (INTEL_GEN(dev_priv) >= 11)
6801 icl_enable_trans_port_sync(new_crtc_state);
6803 intel_set_pipe_src_size(new_crtc_state);
6805 if (cpu_transcoder != TRANSCODER_EDP &&
6806 !transcoder_is_dsi(cpu_transcoder))
6807 I915_WRITE(PIPE_MULT(cpu_transcoder),
6808 new_crtc_state->pixel_multiplier - 1);
6810 if (new_crtc_state->has_pch_encoder)
6811 intel_cpu_transcoder_set_m_n(new_crtc_state,
6812 &new_crtc_state->fdi_m_n, NULL);
6814 if (!transcoder_is_dsi(cpu_transcoder)) {
6815 hsw_set_frame_start_delay(new_crtc_state);
6816 hsw_set_pipeconf(new_crtc_state);
6819 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6820 bdw_set_pipemisc(new_crtc_state);
6822 crtc->active = true;
6824 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6825 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
6826 new_crtc_state->pch_pfit.enabled;
6828 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
6830 if (INTEL_GEN(dev_priv) >= 9)
6831 skl_pfit_enable(new_crtc_state);
6833 ilk_pfit_enable(new_crtc_state);
6836 * On ILK+ LUT must be loaded before the pipe is running but with
6839 intel_color_load_luts(new_crtc_state);
6840 intel_color_commit(new_crtc_state);
6841 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
6842 if (INTEL_GEN(dev_priv) < 9)
6843 intel_disable_primary_plane(new_crtc_state);
6845 if (INTEL_GEN(dev_priv) >= 11)
6846 icl_set_pipe_chicken(crtc);
6848 if (!transcoder_is_dsi(cpu_transcoder))
6849 intel_ddi_enable_transcoder_func(new_crtc_state);
6851 if (dev_priv->display.initial_watermarks)
6852 dev_priv->display.initial_watermarks(state, crtc);
6854 if (INTEL_GEN(dev_priv) >= 11)
6855 icl_pipe_mbus_enable(crtc);
6857 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6858 if (!transcoder_is_dsi(cpu_transcoder))
6859 intel_enable_pipe(new_crtc_state);
6861 if (new_crtc_state->has_pch_encoder)
6862 lpt_pch_enable(state, new_crtc_state);
6864 intel_crtc_vblank_on(new_crtc_state);
6866 intel_encoders_enable(state, crtc);
6868 if (psl_clkgate_wa) {
6869 intel_wait_for_vblank(dev_priv, pipe);
6870 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6873 /* If we change the relative order between pipe/planes enabling, we need
6874 * to change the workaround. */
6875 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
6876 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6877 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6878 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6882 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6884 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
6885 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6886 enum pipe pipe = crtc->pipe;
6888 /* To avoid upsetting the power well on haswell only disable the pfit if
6889 * it's in use. The hw state code will make sure we get this right. */
6890 if (old_crtc_state->pch_pfit.enabled) {
6891 I915_WRITE(PF_CTL(pipe), 0);
6892 I915_WRITE(PF_WIN_POS(pipe), 0);
6893 I915_WRITE(PF_WIN_SZ(pipe), 0);
6897 static void ilk_crtc_disable(struct intel_atomic_state *state,
6898 struct intel_crtc *crtc)
6900 const struct intel_crtc_state *old_crtc_state =
6901 intel_atomic_get_old_crtc_state(state, crtc);
6902 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6903 enum pipe pipe = crtc->pipe;
6906 * Sometimes spurious CPU pipe underruns happen when the
6907 * pipe is already disabled, but FDI RX/TX is still enabled.
6908 * Happens at least with VGA+HDMI cloning. Suppress them.
6910 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6911 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6913 intel_encoders_disable(state, crtc);
6915 intel_crtc_vblank_off(old_crtc_state);
6917 intel_disable_pipe(old_crtc_state);
6919 ilk_pfit_disable(old_crtc_state);
6921 if (old_crtc_state->has_pch_encoder)
6922 ilk_fdi_disable(crtc);
6924 intel_encoders_post_disable(state, crtc);
6926 if (old_crtc_state->has_pch_encoder) {
6927 ilk_disable_pch_transcoder(dev_priv, pipe);
6929 if (HAS_PCH_CPT(dev_priv)) {
6933 /* disable TRANS_DP_CTL */
6934 reg = TRANS_DP_CTL(pipe);
6935 temp = I915_READ(reg);
6936 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6937 TRANS_DP_PORT_SEL_MASK);
6938 temp |= TRANS_DP_PORT_SEL_NONE;
6939 I915_WRITE(reg, temp);
6941 /* disable DPLL_SEL */
6942 temp = I915_READ(PCH_DPLL_SEL);
6943 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6944 I915_WRITE(PCH_DPLL_SEL, temp);
6947 ilk_fdi_pll_disable(crtc);
6950 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6951 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6954 static void hsw_crtc_disable(struct intel_atomic_state *state,
6955 struct intel_crtc *crtc)
6958 * FIXME collapse everything to one hook.
6959 * Need care with mst->ddi interactions.
6961 intel_encoders_disable(state, crtc);
6962 intel_encoders_post_disable(state, crtc);
6965 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6967 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6968 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6970 if (!crtc_state->gmch_pfit.control)
6974 * The panel fitter should only be adjusted whilst the pipe is disabled,
6975 * according to register description and PRM.
6977 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6978 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
6980 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6981 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
6983 /* Border color in case we don't scale up to the full screen. Black by
6984 * default, change to something else for debugging. */
6985 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6988 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
6990 if (phy == PHY_NONE)
6993 if (IS_ELKHARTLAKE(dev_priv))
6994 return phy <= PHY_C;
6996 if (INTEL_GEN(dev_priv) >= 11)
6997 return phy <= PHY_B;
7002 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
7004 if (INTEL_GEN(dev_priv) >= 12)
7005 return phy >= PHY_D && phy <= PHY_I;
7007 if (INTEL_GEN(dev_priv) >= 11 && !IS_ELKHARTLAKE(dev_priv))
7008 return phy >= PHY_C && phy <= PHY_F;
7013 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
7015 if (IS_ELKHARTLAKE(i915) && port == PORT_D)
7018 return (enum phy)port;
7021 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
7023 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
7024 return PORT_TC_NONE;
7026 if (INTEL_GEN(dev_priv) >= 12)
7027 return port - PORT_D;
7029 return port - PORT_C;
7032 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
7036 return POWER_DOMAIN_PORT_DDI_A_LANES;
7038 return POWER_DOMAIN_PORT_DDI_B_LANES;
7040 return POWER_DOMAIN_PORT_DDI_C_LANES;
7042 return POWER_DOMAIN_PORT_DDI_D_LANES;
7044 return POWER_DOMAIN_PORT_DDI_E_LANES;
7046 return POWER_DOMAIN_PORT_DDI_F_LANES;
7048 return POWER_DOMAIN_PORT_DDI_G_LANES;
7051 return POWER_DOMAIN_PORT_OTHER;
7055 enum intel_display_power_domain
7056 intel_aux_power_domain(struct intel_digital_port *dig_port)
7058 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
7059 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
7061 if (intel_phy_is_tc(dev_priv, phy) &&
7062 dig_port->tc_mode == TC_PORT_TBT_ALT) {
7063 switch (dig_port->aux_ch) {
7065 return POWER_DOMAIN_AUX_C_TBT;
7067 return POWER_DOMAIN_AUX_D_TBT;
7069 return POWER_DOMAIN_AUX_E_TBT;
7071 return POWER_DOMAIN_AUX_F_TBT;
7073 return POWER_DOMAIN_AUX_G_TBT;
7075 MISSING_CASE(dig_port->aux_ch);
7076 return POWER_DOMAIN_AUX_C_TBT;
7080 switch (dig_port->aux_ch) {
7082 return POWER_DOMAIN_AUX_A;
7084 return POWER_DOMAIN_AUX_B;
7086 return POWER_DOMAIN_AUX_C;
7088 return POWER_DOMAIN_AUX_D;
7090 return POWER_DOMAIN_AUX_E;
7092 return POWER_DOMAIN_AUX_F;
7094 return POWER_DOMAIN_AUX_G;
7096 MISSING_CASE(dig_port->aux_ch);
7097 return POWER_DOMAIN_AUX_A;
7101 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7103 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7104 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7105 struct drm_encoder *encoder;
7106 enum pipe pipe = crtc->pipe;
7108 enum transcoder transcoder = crtc_state->cpu_transcoder;
7110 if (!crtc_state->hw.active)
7113 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
7114 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
7115 if (crtc_state->pch_pfit.enabled ||
7116 crtc_state->pch_pfit.force_thru)
7117 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
7119 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
7120 crtc_state->uapi.encoder_mask) {
7121 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7123 mask |= BIT_ULL(intel_encoder->power_domain);
7126 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
7127 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
7129 if (crtc_state->shared_dpll)
7130 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
7136 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7138 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7139 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7140 enum intel_display_power_domain domain;
7141 u64 domains, new_domains, old_domains;
7143 old_domains = crtc->enabled_power_domains;
7144 crtc->enabled_power_domains = new_domains =
7145 get_crtc_power_domains(crtc_state);
7147 domains = new_domains & ~old_domains;
7149 for_each_power_domain(domain, domains)
7150 intel_display_power_get(dev_priv, domain);
7152 return old_domains & ~new_domains;
7155 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
7158 enum intel_display_power_domain domain;
7160 for_each_power_domain(domain, domains)
7161 intel_display_power_put_unchecked(dev_priv, domain);
7164 static void valleyview_crtc_enable(struct intel_atomic_state *state,
7165 struct intel_crtc *crtc)
7167 const struct intel_crtc_state *new_crtc_state =
7168 intel_atomic_get_new_crtc_state(state, crtc);
7169 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7170 enum pipe pipe = crtc->pipe;
7172 if (WARN_ON(crtc->active))
7175 if (intel_crtc_has_dp_encoder(new_crtc_state))
7176 intel_dp_set_m_n(new_crtc_state, M1_N1);
7178 intel_set_pipe_timings(new_crtc_state);
7179 intel_set_pipe_src_size(new_crtc_state);
7181 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
7182 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
7183 I915_WRITE(CHV_CANVAS(pipe), 0);
7186 i9xx_set_pipeconf(new_crtc_state);
7188 crtc->active = true;
7190 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7192 intel_encoders_pre_pll_enable(state, crtc);
7194 if (IS_CHERRYVIEW(dev_priv)) {
7195 chv_prepare_pll(crtc, new_crtc_state);
7196 chv_enable_pll(crtc, new_crtc_state);
7198 vlv_prepare_pll(crtc, new_crtc_state);
7199 vlv_enable_pll(crtc, new_crtc_state);
7202 intel_encoders_pre_enable(state, crtc);
7204 i9xx_pfit_enable(new_crtc_state);
7206 intel_color_load_luts(new_crtc_state);
7207 intel_color_commit(new_crtc_state);
7208 /* update DSPCNTR to configure gamma for pipe bottom color */
7209 intel_disable_primary_plane(new_crtc_state);
7211 dev_priv->display.initial_watermarks(state, crtc);
7212 intel_enable_pipe(new_crtc_state);
7214 intel_crtc_vblank_on(new_crtc_state);
7216 intel_encoders_enable(state, crtc);
7219 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
7221 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7222 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7224 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
7225 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
7228 static void i9xx_crtc_enable(struct intel_atomic_state *state,
7229 struct intel_crtc *crtc)
7231 const struct intel_crtc_state *new_crtc_state =
7232 intel_atomic_get_new_crtc_state(state, crtc);
7233 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7234 enum pipe pipe = crtc->pipe;
7236 if (WARN_ON(crtc->active))
7239 i9xx_set_pll_dividers(new_crtc_state);
7241 if (intel_crtc_has_dp_encoder(new_crtc_state))
7242 intel_dp_set_m_n(new_crtc_state, M1_N1);
7244 intel_set_pipe_timings(new_crtc_state);
7245 intel_set_pipe_src_size(new_crtc_state);
7247 i9xx_set_pipeconf(new_crtc_state);
7249 crtc->active = true;
7251 if (!IS_GEN(dev_priv, 2))
7252 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7254 intel_encoders_pre_enable(state, crtc);
7256 i9xx_enable_pll(crtc, new_crtc_state);
7258 i9xx_pfit_enable(new_crtc_state);
7260 intel_color_load_luts(new_crtc_state);
7261 intel_color_commit(new_crtc_state);
7262 /* update DSPCNTR to configure gamma for pipe bottom color */
7263 intel_disable_primary_plane(new_crtc_state);
7265 if (dev_priv->display.initial_watermarks)
7266 dev_priv->display.initial_watermarks(state, crtc);
7268 intel_update_watermarks(crtc);
7269 intel_enable_pipe(new_crtc_state);
7271 intel_crtc_vblank_on(new_crtc_state);
7273 intel_encoders_enable(state, crtc);
7276 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
7278 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
7279 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7281 if (!old_crtc_state->gmch_pfit.control)
7284 assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
7286 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
7287 I915_READ(PFIT_CONTROL));
7288 I915_WRITE(PFIT_CONTROL, 0);
7291 static void i9xx_crtc_disable(struct intel_atomic_state *state,
7292 struct intel_crtc *crtc)
7294 struct intel_crtc_state *old_crtc_state =
7295 intel_atomic_get_old_crtc_state(state, crtc);
7296 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7297 enum pipe pipe = crtc->pipe;
7300 * On gen2 planes are double buffered but the pipe isn't, so we must
7301 * wait for planes to fully turn off before disabling the pipe.
7303 if (IS_GEN(dev_priv, 2))
7304 intel_wait_for_vblank(dev_priv, pipe);
7306 intel_encoders_disable(state, crtc);
7308 intel_crtc_vblank_off(old_crtc_state);
7310 intel_disable_pipe(old_crtc_state);
7312 i9xx_pfit_disable(old_crtc_state);
7314 intel_encoders_post_disable(state, crtc);
7316 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
7317 if (IS_CHERRYVIEW(dev_priv))
7318 chv_disable_pll(dev_priv, pipe);
7319 else if (IS_VALLEYVIEW(dev_priv))
7320 vlv_disable_pll(dev_priv, pipe);
7322 i9xx_disable_pll(old_crtc_state);
7325 intel_encoders_post_pll_disable(state, crtc);
7327 if (!IS_GEN(dev_priv, 2))
7328 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7330 if (!dev_priv->display.initial_watermarks)
7331 intel_update_watermarks(crtc);
7333 /* clock the pipe down to 640x480@60 to potentially save power */
7334 if (IS_I830(dev_priv))
7335 i830_enable_pipe(dev_priv, pipe);
7338 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc,
7339 struct drm_modeset_acquire_ctx *ctx)
7341 struct intel_encoder *encoder;
7342 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7343 struct intel_bw_state *bw_state =
7344 to_intel_bw_state(dev_priv->bw_obj.state);
7345 struct intel_crtc_state *crtc_state =
7346 to_intel_crtc_state(crtc->base.state);
7347 enum intel_display_power_domain domain;
7348 struct intel_plane *plane;
7349 struct drm_atomic_state *state;
7350 struct intel_crtc_state *temp_crtc_state;
7351 enum pipe pipe = crtc->pipe;
7355 if (!crtc_state->hw.active)
7358 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
7359 const struct intel_plane_state *plane_state =
7360 to_intel_plane_state(plane->base.state);
7362 if (plane_state->uapi.visible)
7363 intel_plane_disable_noatomic(crtc, plane);
7366 state = drm_atomic_state_alloc(&dev_priv->drm);
7368 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
7369 crtc->base.base.id, crtc->base.name);
7373 state->acquire_ctx = ctx;
7375 /* Everything's already locked, -EDEADLK can't happen. */
7376 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc);
7377 ret = drm_atomic_add_affected_connectors(state, &crtc->base);
7379 WARN_ON(IS_ERR(temp_crtc_state) || ret);
7381 dev_priv->display.crtc_disable(to_intel_atomic_state(state), crtc);
7383 drm_atomic_state_put(state);
7385 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7386 crtc->base.base.id, crtc->base.name);
7388 crtc->active = false;
7389 crtc->base.enabled = false;
7391 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0);
7392 crtc_state->uapi.active = false;
7393 crtc_state->uapi.connector_mask = 0;
7394 crtc_state->uapi.encoder_mask = 0;
7395 intel_crtc_free_hw_state(crtc_state);
7396 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw));
7398 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder)
7399 encoder->base.crtc = NULL;
7401 intel_fbc_disable(crtc);
7402 intel_update_watermarks(crtc);
7403 intel_disable_shared_dpll(crtc_state);
7405 domains = crtc->enabled_power_domains;
7406 for_each_power_domain(domain, domains)
7407 intel_display_power_put_unchecked(dev_priv, domain);
7408 crtc->enabled_power_domains = 0;
7410 dev_priv->active_pipes &= ~BIT(pipe);
7411 dev_priv->min_cdclk[pipe] = 0;
7412 dev_priv->min_voltage_level[pipe] = 0;
7414 bw_state->data_rate[pipe] = 0;
7415 bw_state->num_active_planes[pipe] = 0;
7419 * turn all crtc's off, but do not adjust state
7420 * This has to be paired with a call to intel_modeset_setup_hw_state.
7422 int intel_display_suspend(struct drm_device *dev)
7424 struct drm_i915_private *dev_priv = to_i915(dev);
7425 struct drm_atomic_state *state;
7428 state = drm_atomic_helper_suspend(dev);
7429 ret = PTR_ERR_OR_ZERO(state);
7431 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
7433 dev_priv->modeset_restore_state = state;
7437 void intel_encoder_destroy(struct drm_encoder *encoder)
7439 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7441 drm_encoder_cleanup(encoder);
7442 kfree(intel_encoder);
7445 /* Cross check the actual hw state with our own modeset state tracking (and it's
7446 * internal consistency). */
7447 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7448 struct drm_connector_state *conn_state)
7450 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7452 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
7453 connector->base.base.id,
7454 connector->base.name);
7456 if (connector->get_hw_state(connector)) {
7457 struct intel_encoder *encoder = connector->encoder;
7459 I915_STATE_WARN(!crtc_state,
7460 "connector enabled without attached crtc\n");
7465 I915_STATE_WARN(!crtc_state->hw.active,
7466 "connector is active, but attached crtc isn't\n");
7468 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7471 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7472 "atomic encoder doesn't match attached encoder\n");
7474 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7475 "attached encoder crtc differs from connector crtc\n");
7477 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
7478 "attached crtc is active, but connector isn't\n");
7479 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7480 "best encoder set without crtc!\n");
7484 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7486 if (crtc_state->hw.enable && crtc_state->has_pch_encoder)
7487 return crtc_state->fdi_lanes;
7492 static int ilk_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7493 struct intel_crtc_state *pipe_config)
7495 struct drm_i915_private *dev_priv = to_i915(dev);
7496 struct drm_atomic_state *state = pipe_config->uapi.state;
7497 struct intel_crtc *other_crtc;
7498 struct intel_crtc_state *other_crtc_state;
7500 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
7501 pipe_name(pipe), pipe_config->fdi_lanes);
7502 if (pipe_config->fdi_lanes > 4) {
7503 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
7504 pipe_name(pipe), pipe_config->fdi_lanes);
7508 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7509 if (pipe_config->fdi_lanes > 2) {
7510 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
7511 pipe_config->fdi_lanes);
7518 if (INTEL_NUM_PIPES(dev_priv) == 2)
7521 /* Ivybridge 3 pipe is really complicated */
7526 if (pipe_config->fdi_lanes <= 2)
7529 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7531 intel_atomic_get_crtc_state(state, other_crtc);
7532 if (IS_ERR(other_crtc_state))
7533 return PTR_ERR(other_crtc_state);
7535 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7536 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
7537 pipe_name(pipe), pipe_config->fdi_lanes);
7542 if (pipe_config->fdi_lanes > 2) {
7543 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
7544 pipe_name(pipe), pipe_config->fdi_lanes);
7548 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7550 intel_atomic_get_crtc_state(state, other_crtc);
7551 if (IS_ERR(other_crtc_state))
7552 return PTR_ERR(other_crtc_state);
7554 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7555 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
7565 static int ilk_fdi_compute_config(struct intel_crtc *intel_crtc,
7566 struct intel_crtc_state *pipe_config)
7568 struct drm_device *dev = intel_crtc->base.dev;
7569 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7570 int lane, link_bw, fdi_dotclock, ret;
7571 bool needs_recompute = false;
7574 /* FDI is a binary signal running at ~2.7GHz, encoding
7575 * each output octet as 10 bits. The actual frequency
7576 * is stored as a divider into a 100MHz clock, and the
7577 * mode pixel clock is stored in units of 1KHz.
7578 * Hence the bw of each lane in terms of the mode signal
7581 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
7583 fdi_dotclock = adjusted_mode->crtc_clock;
7585 lane = ilk_get_lanes_required(fdi_dotclock, link_bw,
7586 pipe_config->pipe_bpp);
7588 pipe_config->fdi_lanes = lane;
7590 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7591 link_bw, &pipe_config->fdi_m_n, false, false);
7593 ret = ilk_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7594 if (ret == -EDEADLK)
7597 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7598 pipe_config->pipe_bpp -= 2*3;
7599 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
7600 pipe_config->pipe_bpp);
7601 needs_recompute = true;
7602 pipe_config->bw_constrained = true;
7607 if (needs_recompute)
7613 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7615 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7616 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7618 /* IPS only exists on ULT machines and is tied to pipe A. */
7619 if (!hsw_crtc_supports_ips(crtc))
7622 if (!i915_modparams.enable_ips)
7625 if (crtc_state->pipe_bpp > 24)
7629 * We compare against max which means we must take
7630 * the increased cdclk requirement into account when
7631 * calculating the new cdclk.
7633 * Should measure whether using a lower cdclk w/o IPS
7635 if (IS_BROADWELL(dev_priv) &&
7636 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7642 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7644 struct drm_i915_private *dev_priv =
7645 to_i915(crtc_state->uapi.crtc->dev);
7646 struct intel_atomic_state *intel_state =
7647 to_intel_atomic_state(crtc_state->uapi.state);
7649 if (!hsw_crtc_state_ips_capable(crtc_state))
7653 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7654 * enabled and disabled dynamically based on package C states,
7655 * user space can't make reliable use of the CRCs, so let's just
7656 * completely disable it.
7658 if (crtc_state->crc_enabled)
7661 /* IPS should be fine as long as at least one plane is enabled. */
7662 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7665 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7666 if (IS_BROADWELL(dev_priv) &&
7667 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
7673 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7675 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7677 /* GDG double wide on either pipe, otherwise pipe A only */
7678 return INTEL_GEN(dev_priv) < 4 &&
7679 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7682 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
7686 pixel_rate = pipe_config->hw.adjusted_mode.crtc_clock;
7689 * We only use IF-ID interlacing. If we ever use
7690 * PF-ID we'll need to adjust the pixel_rate here.
7693 if (pipe_config->pch_pfit.enabled) {
7694 u64 pipe_w, pipe_h, pfit_w, pfit_h;
7695 u32 pfit_size = pipe_config->pch_pfit.size;
7697 pipe_w = pipe_config->pipe_src_w;
7698 pipe_h = pipe_config->pipe_src_h;
7700 pfit_w = (pfit_size >> 16) & 0xFFFF;
7701 pfit_h = pfit_size & 0xFFFF;
7702 if (pipe_w < pfit_w)
7704 if (pipe_h < pfit_h)
7707 if (WARN_ON(!pfit_w || !pfit_h))
7710 pixel_rate = div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7717 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7719 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
7721 if (HAS_GMCH(dev_priv))
7722 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7723 crtc_state->pixel_rate =
7724 crtc_state->hw.adjusted_mode.crtc_clock;
7726 crtc_state->pixel_rate =
7727 ilk_pipe_pixel_rate(crtc_state);
7730 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7731 struct intel_crtc_state *pipe_config)
7733 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7734 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7735 int clock_limit = dev_priv->max_dotclk_freq;
7737 if (INTEL_GEN(dev_priv) < 4) {
7738 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
7741 * Enable double wide mode when the dot clock
7742 * is > 90% of the (display) core speed.
7744 if (intel_crtc_supports_double_wide(crtc) &&
7745 adjusted_mode->crtc_clock > clock_limit) {
7746 clock_limit = dev_priv->max_dotclk_freq;
7747 pipe_config->double_wide = true;
7751 if (adjusted_mode->crtc_clock > clock_limit) {
7752 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7753 adjusted_mode->crtc_clock, clock_limit,
7754 yesno(pipe_config->double_wide));
7758 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
7759 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
7760 pipe_config->hw.ctm) {
7762 * There is only one pipe CSC unit per pipe, and we need that
7763 * for output conversion from RGB->YCBCR. So if CTM is already
7764 * applied we can't support YCBCR420 output.
7766 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
7771 * Pipe horizontal size must be even in:
7773 * - LVDS dual channel mode
7774 * - Double wide pipe
7776 if (pipe_config->pipe_src_w & 1) {
7777 if (pipe_config->double_wide) {
7778 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
7782 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
7783 intel_is_dual_link_lvds(dev_priv)) {
7784 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
7789 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7790 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7792 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7793 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
7796 intel_crtc_compute_pixel_rate(pipe_config);
7798 if (pipe_config->has_pch_encoder)
7799 return ilk_fdi_compute_config(crtc, pipe_config);
7805 intel_reduce_m_n_ratio(u32 *num, u32 *den)
7807 while (*num > DATA_LINK_M_N_MASK ||
7808 *den > DATA_LINK_M_N_MASK) {
7814 static void compute_m_n(unsigned int m, unsigned int n,
7815 u32 *ret_m, u32 *ret_n,
7819 * Several DP dongles in particular seem to be fussy about
7820 * too large link M/N values. Give N value as 0x8000 that
7821 * should be acceptable by specific devices. 0x8000 is the
7822 * specified fixed N value for asynchronous clock mode,
7823 * which the devices expect also in synchronous clock mode.
7828 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
7830 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
7831 intel_reduce_m_n_ratio(ret_m, ret_n);
7835 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
7836 int pixel_clock, int link_clock,
7837 struct intel_link_m_n *m_n,
7838 bool constant_n, bool fec_enable)
7840 u32 data_clock = bits_per_pixel * pixel_clock;
7843 data_clock = intel_dp_mode_to_fec_clock(data_clock);
7846 compute_m_n(data_clock,
7847 link_clock * nlanes * 8,
7848 &m_n->gmch_m, &m_n->gmch_n,
7851 compute_m_n(pixel_clock, link_clock,
7852 &m_n->link_m, &m_n->link_n,
7856 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
7859 * There may be no VBT; and if the BIOS enabled SSC we can
7860 * just keep using it to avoid unnecessary flicker. Whereas if the
7861 * BIOS isn't using it, don't assume it will work even if the VBT
7862 * indicates as much.
7864 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
7865 bool bios_lvds_use_ssc = I915_READ(PCH_DREF_CONTROL) &
7868 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
7869 DRM_DEBUG_KMS("SSC %s by BIOS, overriding VBT which says %s\n",
7870 enableddisabled(bios_lvds_use_ssc),
7871 enableddisabled(dev_priv->vbt.lvds_use_ssc));
7872 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
7877 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7879 if (i915_modparams.panel_use_ssc >= 0)
7880 return i915_modparams.panel_use_ssc != 0;
7881 return dev_priv->vbt.lvds_use_ssc
7882 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7885 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
7887 return (1 << dpll->n) << 16 | dpll->m2;
7890 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7892 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7895 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7896 struct intel_crtc_state *crtc_state,
7897 struct dpll *reduced_clock)
7899 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7902 if (IS_PINEVIEW(dev_priv)) {
7903 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7905 fp2 = pnv_dpll_compute_fp(reduced_clock);
7907 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7909 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7912 crtc_state->dpll_hw_state.fp0 = fp;
7914 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7916 crtc_state->dpll_hw_state.fp1 = fp2;
7918 crtc_state->dpll_hw_state.fp1 = fp;
7922 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7928 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7929 * and set it to a reasonable value instead.
7931 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7932 reg_val &= 0xffffff00;
7933 reg_val |= 0x00000030;
7934 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7936 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7937 reg_val &= 0x00ffffff;
7938 reg_val |= 0x8c000000;
7939 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7941 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7942 reg_val &= 0xffffff00;
7943 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7945 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7946 reg_val &= 0x00ffffff;
7947 reg_val |= 0xb0000000;
7948 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7951 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7952 const struct intel_link_m_n *m_n)
7954 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7955 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7956 enum pipe pipe = crtc->pipe;
7958 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7959 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7960 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7961 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7964 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7965 enum transcoder transcoder)
7967 if (IS_HASWELL(dev_priv))
7968 return transcoder == TRANSCODER_EDP;
7971 * Strictly speaking some registers are available before
7972 * gen7, but we only support DRRS on gen7+
7974 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
7977 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7978 const struct intel_link_m_n *m_n,
7979 const struct intel_link_m_n *m2_n2)
7981 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7982 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7983 enum pipe pipe = crtc->pipe;
7984 enum transcoder transcoder = crtc_state->cpu_transcoder;
7986 if (INTEL_GEN(dev_priv) >= 5) {
7987 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7988 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7989 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7990 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7992 * M2_N2 registers are set only if DRRS is supported
7993 * (to make sure the registers are not unnecessarily accessed).
7995 if (m2_n2 && crtc_state->has_drrs &&
7996 transcoder_has_m2_n2(dev_priv, transcoder)) {
7997 I915_WRITE(PIPE_DATA_M2(transcoder),
7998 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7999 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
8000 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
8001 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
8004 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
8005 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
8006 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
8007 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
8011 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
8013 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
8016 dp_m_n = &crtc_state->dp_m_n;
8017 dp_m2_n2 = &crtc_state->dp_m2_n2;
8018 } else if (m_n == M2_N2) {
8021 * M2_N2 registers are not supported. Hence m2_n2 divider value
8022 * needs to be programmed into M1_N1.
8024 dp_m_n = &crtc_state->dp_m2_n2;
8026 DRM_ERROR("Unsupported divider value\n");
8030 if (crtc_state->has_pch_encoder)
8031 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
8033 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
8036 static void vlv_compute_dpll(struct intel_crtc *crtc,
8037 struct intel_crtc_state *pipe_config)
8039 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
8040 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8041 if (crtc->pipe != PIPE_A)
8042 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8044 /* DPLL not used with DSI, but still need the rest set up */
8045 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8046 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
8047 DPLL_EXT_BUFFER_ENABLE_VLV;
8049 pipe_config->dpll_hw_state.dpll_md =
8050 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8053 static void chv_compute_dpll(struct intel_crtc *crtc,
8054 struct intel_crtc_state *pipe_config)
8056 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
8057 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8058 if (crtc->pipe != PIPE_A)
8059 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8061 /* DPLL not used with DSI, but still need the rest set up */
8062 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8063 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
8065 pipe_config->dpll_hw_state.dpll_md =
8066 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8069 static void vlv_prepare_pll(struct intel_crtc *crtc,
8070 const struct intel_crtc_state *pipe_config)
8072 struct drm_device *dev = crtc->base.dev;
8073 struct drm_i915_private *dev_priv = to_i915(dev);
8074 enum pipe pipe = crtc->pipe;
8076 u32 bestn, bestm1, bestm2, bestp1, bestp2;
8077 u32 coreclk, reg_val;
8080 I915_WRITE(DPLL(pipe),
8081 pipe_config->dpll_hw_state.dpll &
8082 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
8084 /* No need to actually set up the DPLL with DSI */
8085 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8088 vlv_dpio_get(dev_priv);
8090 bestn = pipe_config->dpll.n;
8091 bestm1 = pipe_config->dpll.m1;
8092 bestm2 = pipe_config->dpll.m2;
8093 bestp1 = pipe_config->dpll.p1;
8094 bestp2 = pipe_config->dpll.p2;
8096 /* See eDP HDMI DPIO driver vbios notes doc */
8098 /* PLL B needs special handling */
8100 vlv_pllb_recal_opamp(dev_priv, pipe);
8102 /* Set up Tx target for periodic Rcomp update */
8103 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
8105 /* Disable target IRef on PLL */
8106 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
8107 reg_val &= 0x00ffffff;
8108 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
8110 /* Disable fast lock */
8111 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
8113 /* Set idtafcrecal before PLL is enabled */
8114 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
8115 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
8116 mdiv |= ((bestn << DPIO_N_SHIFT));
8117 mdiv |= (1 << DPIO_K_SHIFT);
8120 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
8121 * but we don't support that).
8122 * Note: don't use the DAC post divider as it seems unstable.
8124 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
8125 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8127 mdiv |= DPIO_ENABLE_CALIBRATION;
8128 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8130 /* Set HBR and RBR LPF coefficients */
8131 if (pipe_config->port_clock == 162000 ||
8132 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
8133 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
8134 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8137 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8140 if (intel_crtc_has_dp_encoder(pipe_config)) {
8141 /* Use SSC source */
8143 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8146 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8148 } else { /* HDMI or VGA */
8149 /* Use bend source */
8151 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8154 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8158 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
8159 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
8160 if (intel_crtc_has_dp_encoder(pipe_config))
8161 coreclk |= 0x01000000;
8162 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
8164 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
8166 vlv_dpio_put(dev_priv);
8169 static void chv_prepare_pll(struct intel_crtc *crtc,
8170 const struct intel_crtc_state *pipe_config)
8172 struct drm_device *dev = crtc->base.dev;
8173 struct drm_i915_private *dev_priv = to_i915(dev);
8174 enum pipe pipe = crtc->pipe;
8175 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8176 u32 loopfilter, tribuf_calcntr;
8177 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
8181 /* Enable Refclk and SSC */
8182 I915_WRITE(DPLL(pipe),
8183 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
8185 /* No need to actually set up the DPLL with DSI */
8186 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8189 bestn = pipe_config->dpll.n;
8190 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
8191 bestm1 = pipe_config->dpll.m1;
8192 bestm2 = pipe_config->dpll.m2 >> 22;
8193 bestp1 = pipe_config->dpll.p1;
8194 bestp2 = pipe_config->dpll.p2;
8195 vco = pipe_config->dpll.vco;
8199 vlv_dpio_get(dev_priv);
8201 /* p1 and p2 divider */
8202 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
8203 5 << DPIO_CHV_S1_DIV_SHIFT |
8204 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
8205 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
8206 1 << DPIO_CHV_K_DIV_SHIFT);
8208 /* Feedback post-divider - m2 */
8209 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
8211 /* Feedback refclk divider - n and m1 */
8212 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
8213 DPIO_CHV_M1_DIV_BY_2 |
8214 1 << DPIO_CHV_N_DIV_SHIFT);
8216 /* M2 fraction division */
8217 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
8219 /* M2 fraction division enable */
8220 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8221 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
8222 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
8224 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
8225 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
8227 /* Program digital lock detect threshold */
8228 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
8229 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
8230 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
8231 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
8233 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
8234 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
8237 if (vco == 5400000) {
8238 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
8239 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
8240 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
8241 tribuf_calcntr = 0x9;
8242 } else if (vco <= 6200000) {
8243 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
8244 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
8245 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8246 tribuf_calcntr = 0x9;
8247 } else if (vco <= 6480000) {
8248 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8249 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8250 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8251 tribuf_calcntr = 0x8;
8253 /* Not supported. Apply the same limits as in the max case */
8254 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8255 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8256 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8259 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
8261 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
8262 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
8263 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
8264 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
8267 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
8268 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
8271 vlv_dpio_put(dev_priv);
8275 * vlv_force_pll_on - forcibly enable just the PLL
8276 * @dev_priv: i915 private structure
8277 * @pipe: pipe PLL to enable
8278 * @dpll: PLL configuration
8280 * Enable the PLL for @pipe using the supplied @dpll config. To be used
8281 * in cases where we need the PLL enabled even when @pipe is not going to
8284 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
8285 const struct dpll *dpll)
8287 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
8288 struct intel_crtc_state *pipe_config;
8290 pipe_config = intel_crtc_state_alloc(crtc);
8294 pipe_config->cpu_transcoder = (enum transcoder)pipe;
8295 pipe_config->pixel_multiplier = 1;
8296 pipe_config->dpll = *dpll;
8298 if (IS_CHERRYVIEW(dev_priv)) {
8299 chv_compute_dpll(crtc, pipe_config);
8300 chv_prepare_pll(crtc, pipe_config);
8301 chv_enable_pll(crtc, pipe_config);
8303 vlv_compute_dpll(crtc, pipe_config);
8304 vlv_prepare_pll(crtc, pipe_config);
8305 vlv_enable_pll(crtc, pipe_config);
8314 * vlv_force_pll_off - forcibly disable just the PLL
8315 * @dev_priv: i915 private structure
8316 * @pipe: pipe PLL to disable
8318 * Disable the PLL for @pipe. To be used in cases where we need
8319 * the PLL enabled even when @pipe is not going to be enabled.
8321 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
8323 if (IS_CHERRYVIEW(dev_priv))
8324 chv_disable_pll(dev_priv, pipe);
8326 vlv_disable_pll(dev_priv, pipe);
8329 static void i9xx_compute_dpll(struct intel_crtc *crtc,
8330 struct intel_crtc_state *crtc_state,
8331 struct dpll *reduced_clock)
8333 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8335 struct dpll *clock = &crtc_state->dpll;
8337 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8339 dpll = DPLL_VGA_MODE_DIS;
8341 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8342 dpll |= DPLLB_MODE_LVDS;
8344 dpll |= DPLLB_MODE_DAC_SERIAL;
8346 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8347 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8348 dpll |= (crtc_state->pixel_multiplier - 1)
8349 << SDVO_MULTIPLIER_SHIFT_HIRES;
8352 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8353 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8354 dpll |= DPLL_SDVO_HIGH_SPEED;
8356 if (intel_crtc_has_dp_encoder(crtc_state))
8357 dpll |= DPLL_SDVO_HIGH_SPEED;
8359 /* compute bitmask from p1 value */
8360 if (IS_PINEVIEW(dev_priv))
8361 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8363 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8364 if (IS_G4X(dev_priv) && reduced_clock)
8365 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8367 switch (clock->p2) {
8369 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8372 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8375 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8378 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8381 if (INTEL_GEN(dev_priv) >= 4)
8382 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8384 if (crtc_state->sdvo_tv_clock)
8385 dpll |= PLL_REF_INPUT_TVCLKINBC;
8386 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8387 intel_panel_use_ssc(dev_priv))
8388 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8390 dpll |= PLL_REF_INPUT_DREFCLK;
8392 dpll |= DPLL_VCO_ENABLE;
8393 crtc_state->dpll_hw_state.dpll = dpll;
8395 if (INTEL_GEN(dev_priv) >= 4) {
8396 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8397 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8398 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8402 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8403 struct intel_crtc_state *crtc_state,
8404 struct dpll *reduced_clock)
8406 struct drm_device *dev = crtc->base.dev;
8407 struct drm_i915_private *dev_priv = to_i915(dev);
8409 struct dpll *clock = &crtc_state->dpll;
8411 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8413 dpll = DPLL_VGA_MODE_DIS;
8415 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8416 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8419 dpll |= PLL_P1_DIVIDE_BY_TWO;
8421 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8423 dpll |= PLL_P2_DIVIDE_BY_4;
8428 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8429 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8430 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8431 * Enable) must be set to “1” in both the DPLL A Control Register
8432 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8434 * For simplicity We simply keep both bits always enabled in
8435 * both DPLLS. The spec says we should disable the DVO 2X clock
8436 * when not needed, but this seems to work fine in practice.
8438 if (IS_I830(dev_priv) ||
8439 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8440 dpll |= DPLL_DVO_2X_MODE;
8442 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8443 intel_panel_use_ssc(dev_priv))
8444 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8446 dpll |= PLL_REF_INPUT_DREFCLK;
8448 dpll |= DPLL_VCO_ENABLE;
8449 crtc_state->dpll_hw_state.dpll = dpll;
8452 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
8454 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8455 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8456 enum pipe pipe = crtc->pipe;
8457 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8458 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
8459 u32 crtc_vtotal, crtc_vblank_end;
8462 /* We need to be careful not to changed the adjusted mode, for otherwise
8463 * the hw state checker will get angry at the mismatch. */
8464 crtc_vtotal = adjusted_mode->crtc_vtotal;
8465 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8467 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8468 /* the chip adds 2 halflines automatically */
8470 crtc_vblank_end -= 1;
8472 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8473 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8475 vsyncshift = adjusted_mode->crtc_hsync_start -
8476 adjusted_mode->crtc_htotal / 2;
8478 vsyncshift += adjusted_mode->crtc_htotal;
8481 if (INTEL_GEN(dev_priv) > 3)
8482 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
8484 I915_WRITE(HTOTAL(cpu_transcoder),
8485 (adjusted_mode->crtc_hdisplay - 1) |
8486 ((adjusted_mode->crtc_htotal - 1) << 16));
8487 I915_WRITE(HBLANK(cpu_transcoder),
8488 (adjusted_mode->crtc_hblank_start - 1) |
8489 ((adjusted_mode->crtc_hblank_end - 1) << 16));
8490 I915_WRITE(HSYNC(cpu_transcoder),
8491 (adjusted_mode->crtc_hsync_start - 1) |
8492 ((adjusted_mode->crtc_hsync_end - 1) << 16));
8494 I915_WRITE(VTOTAL(cpu_transcoder),
8495 (adjusted_mode->crtc_vdisplay - 1) |
8496 ((crtc_vtotal - 1) << 16));
8497 I915_WRITE(VBLANK(cpu_transcoder),
8498 (adjusted_mode->crtc_vblank_start - 1) |
8499 ((crtc_vblank_end - 1) << 16));
8500 I915_WRITE(VSYNC(cpu_transcoder),
8501 (adjusted_mode->crtc_vsync_start - 1) |
8502 ((adjusted_mode->crtc_vsync_end - 1) << 16));
8504 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8505 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8506 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8508 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8509 (pipe == PIPE_B || pipe == PIPE_C))
8510 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
8514 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8516 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8517 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8518 enum pipe pipe = crtc->pipe;
8520 /* pipesrc controls the size that is scaled from, which should
8521 * always be the user's requested size.
8523 I915_WRITE(PIPESRC(pipe),
8524 ((crtc_state->pipe_src_w - 1) << 16) |
8525 (crtc_state->pipe_src_h - 1));
8528 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
8530 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
8531 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8533 if (IS_GEN(dev_priv, 2))
8536 if (INTEL_GEN(dev_priv) >= 9 ||
8537 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
8538 return I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
8540 return I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
8543 static void intel_get_pipe_timings(struct intel_crtc *crtc,
8544 struct intel_crtc_state *pipe_config)
8546 struct drm_device *dev = crtc->base.dev;
8547 struct drm_i915_private *dev_priv = to_i915(dev);
8548 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8551 tmp = I915_READ(HTOTAL(cpu_transcoder));
8552 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8553 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8555 if (!transcoder_is_dsi(cpu_transcoder)) {
8556 tmp = I915_READ(HBLANK(cpu_transcoder));
8557 pipe_config->hw.adjusted_mode.crtc_hblank_start =
8559 pipe_config->hw.adjusted_mode.crtc_hblank_end =
8560 ((tmp >> 16) & 0xffff) + 1;
8562 tmp = I915_READ(HSYNC(cpu_transcoder));
8563 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8564 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8566 tmp = I915_READ(VTOTAL(cpu_transcoder));
8567 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8568 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8570 if (!transcoder_is_dsi(cpu_transcoder)) {
8571 tmp = I915_READ(VBLANK(cpu_transcoder));
8572 pipe_config->hw.adjusted_mode.crtc_vblank_start =
8574 pipe_config->hw.adjusted_mode.crtc_vblank_end =
8575 ((tmp >> 16) & 0xffff) + 1;
8577 tmp = I915_READ(VSYNC(cpu_transcoder));
8578 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8579 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8581 if (intel_pipe_is_interlaced(pipe_config)) {
8582 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8583 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
8584 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
8588 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8589 struct intel_crtc_state *pipe_config)
8591 struct drm_device *dev = crtc->base.dev;
8592 struct drm_i915_private *dev_priv = to_i915(dev);
8595 tmp = I915_READ(PIPESRC(crtc->pipe));
8596 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8597 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8599 pipe_config->hw.mode.vdisplay = pipe_config->pipe_src_h;
8600 pipe_config->hw.mode.hdisplay = pipe_config->pipe_src_w;
8603 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
8604 struct intel_crtc_state *pipe_config)
8606 mode->hdisplay = pipe_config->hw.adjusted_mode.crtc_hdisplay;
8607 mode->htotal = pipe_config->hw.adjusted_mode.crtc_htotal;
8608 mode->hsync_start = pipe_config->hw.adjusted_mode.crtc_hsync_start;
8609 mode->hsync_end = pipe_config->hw.adjusted_mode.crtc_hsync_end;
8611 mode->vdisplay = pipe_config->hw.adjusted_mode.crtc_vdisplay;
8612 mode->vtotal = pipe_config->hw.adjusted_mode.crtc_vtotal;
8613 mode->vsync_start = pipe_config->hw.adjusted_mode.crtc_vsync_start;
8614 mode->vsync_end = pipe_config->hw.adjusted_mode.crtc_vsync_end;
8616 mode->flags = pipe_config->hw.adjusted_mode.flags;
8617 mode->type = DRM_MODE_TYPE_DRIVER;
8619 mode->clock = pipe_config->hw.adjusted_mode.crtc_clock;
8621 mode->hsync = drm_mode_hsync(mode);
8622 mode->vrefresh = drm_mode_vrefresh(mode);
8623 drm_mode_set_name(mode);
8626 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8628 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8629 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8634 /* we keep both pipes enabled on 830 */
8635 if (IS_I830(dev_priv))
8636 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8638 if (crtc_state->double_wide)
8639 pipeconf |= PIPECONF_DOUBLE_WIDE;
8641 /* only g4x and later have fancy bpc/dither controls */
8642 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8643 IS_CHERRYVIEW(dev_priv)) {
8644 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8645 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8646 pipeconf |= PIPECONF_DITHER_EN |
8647 PIPECONF_DITHER_TYPE_SP;
8649 switch (crtc_state->pipe_bpp) {
8651 pipeconf |= PIPECONF_6BPC;
8654 pipeconf |= PIPECONF_8BPC;
8657 pipeconf |= PIPECONF_10BPC;
8660 /* Case prevented by intel_choose_pipe_bpp_dither. */
8665 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8666 if (INTEL_GEN(dev_priv) < 4 ||
8667 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8668 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8670 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8672 pipeconf |= PIPECONF_PROGRESSIVE;
8675 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8676 crtc_state->limited_color_range)
8677 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8679 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8681 pipeconf |= PIPECONF_FRAME_START_DELAY(0);
8683 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
8684 POSTING_READ(PIPECONF(crtc->pipe));
8687 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8688 struct intel_crtc_state *crtc_state)
8690 struct drm_device *dev = crtc->base.dev;
8691 struct drm_i915_private *dev_priv = to_i915(dev);
8692 const struct intel_limit *limit;
8695 memset(&crtc_state->dpll_hw_state, 0,
8696 sizeof(crtc_state->dpll_hw_state));
8698 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8699 if (intel_panel_use_ssc(dev_priv)) {
8700 refclk = dev_priv->vbt.lvds_ssc_freq;
8701 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8704 limit = &intel_limits_i8xx_lvds;
8705 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8706 limit = &intel_limits_i8xx_dvo;
8708 limit = &intel_limits_i8xx_dac;
8711 if (!crtc_state->clock_set &&
8712 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8713 refclk, NULL, &crtc_state->dpll)) {
8714 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8718 i8xx_compute_dpll(crtc, crtc_state, NULL);
8723 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
8724 struct intel_crtc_state *crtc_state)
8726 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8727 const struct intel_limit *limit;
8730 memset(&crtc_state->dpll_hw_state, 0,
8731 sizeof(crtc_state->dpll_hw_state));
8733 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8734 if (intel_panel_use_ssc(dev_priv)) {
8735 refclk = dev_priv->vbt.lvds_ssc_freq;
8736 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8739 if (intel_is_dual_link_lvds(dev_priv))
8740 limit = &intel_limits_g4x_dual_channel_lvds;
8742 limit = &intel_limits_g4x_single_channel_lvds;
8743 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
8744 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
8745 limit = &intel_limits_g4x_hdmi;
8746 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
8747 limit = &intel_limits_g4x_sdvo;
8749 /* The option is for other outputs */
8750 limit = &intel_limits_i9xx_sdvo;
8753 if (!crtc_state->clock_set &&
8754 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8755 refclk, NULL, &crtc_state->dpll)) {
8756 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8760 i9xx_compute_dpll(crtc, crtc_state, NULL);
8765 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
8766 struct intel_crtc_state *crtc_state)
8768 struct drm_device *dev = crtc->base.dev;
8769 struct drm_i915_private *dev_priv = to_i915(dev);
8770 const struct intel_limit *limit;
8773 memset(&crtc_state->dpll_hw_state, 0,
8774 sizeof(crtc_state->dpll_hw_state));
8776 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8777 if (intel_panel_use_ssc(dev_priv)) {
8778 refclk = dev_priv->vbt.lvds_ssc_freq;
8779 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8782 limit = &pnv_limits_lvds;
8784 limit = &pnv_limits_sdvo;
8787 if (!crtc_state->clock_set &&
8788 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8789 refclk, NULL, &crtc_state->dpll)) {
8790 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8794 i9xx_compute_dpll(crtc, crtc_state, NULL);
8799 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
8800 struct intel_crtc_state *crtc_state)
8802 struct drm_device *dev = crtc->base.dev;
8803 struct drm_i915_private *dev_priv = to_i915(dev);
8804 const struct intel_limit *limit;
8807 memset(&crtc_state->dpll_hw_state, 0,
8808 sizeof(crtc_state->dpll_hw_state));
8810 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8811 if (intel_panel_use_ssc(dev_priv)) {
8812 refclk = dev_priv->vbt.lvds_ssc_freq;
8813 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8816 limit = &intel_limits_i9xx_lvds;
8818 limit = &intel_limits_i9xx_sdvo;
8821 if (!crtc_state->clock_set &&
8822 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8823 refclk, NULL, &crtc_state->dpll)) {
8824 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8828 i9xx_compute_dpll(crtc, crtc_state, NULL);
8833 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
8834 struct intel_crtc_state *crtc_state)
8836 int refclk = 100000;
8837 const struct intel_limit *limit = &intel_limits_chv;
8839 memset(&crtc_state->dpll_hw_state, 0,
8840 sizeof(crtc_state->dpll_hw_state));
8842 if (!crtc_state->clock_set &&
8843 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8844 refclk, NULL, &crtc_state->dpll)) {
8845 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8849 chv_compute_dpll(crtc, crtc_state);
8854 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
8855 struct intel_crtc_state *crtc_state)
8857 int refclk = 100000;
8858 const struct intel_limit *limit = &intel_limits_vlv;
8860 memset(&crtc_state->dpll_hw_state, 0,
8861 sizeof(crtc_state->dpll_hw_state));
8863 if (!crtc_state->clock_set &&
8864 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8865 refclk, NULL, &crtc_state->dpll)) {
8866 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8870 vlv_compute_dpll(crtc, crtc_state);
8875 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
8877 if (IS_I830(dev_priv))
8880 return INTEL_GEN(dev_priv) >= 4 ||
8881 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
8884 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
8885 struct intel_crtc_state *pipe_config)
8887 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8890 if (!i9xx_has_pfit(dev_priv))
8893 tmp = I915_READ(PFIT_CONTROL);
8894 if (!(tmp & PFIT_ENABLE))
8897 /* Check whether the pfit is attached to our pipe. */
8898 if (INTEL_GEN(dev_priv) < 4) {
8899 if (crtc->pipe != PIPE_B)
8902 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
8906 pipe_config->gmch_pfit.control = tmp;
8907 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
8910 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
8911 struct intel_crtc_state *pipe_config)
8913 struct drm_device *dev = crtc->base.dev;
8914 struct drm_i915_private *dev_priv = to_i915(dev);
8915 enum pipe pipe = crtc->pipe;
8918 int refclk = 100000;
8920 /* In case of DSI, DPLL will not be used */
8921 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8924 vlv_dpio_get(dev_priv);
8925 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
8926 vlv_dpio_put(dev_priv);
8928 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
8929 clock.m2 = mdiv & DPIO_M2DIV_MASK;
8930 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
8931 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
8932 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
8934 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8938 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8939 struct intel_initial_plane_config *plane_config)
8941 struct drm_device *dev = crtc->base.dev;
8942 struct drm_i915_private *dev_priv = to_i915(dev);
8943 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8944 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8946 u32 val, base, offset;
8947 int fourcc, pixel_format;
8948 unsigned int aligned_height;
8949 struct drm_framebuffer *fb;
8950 struct intel_framebuffer *intel_fb;
8952 if (!plane->get_hw_state(plane, &pipe))
8955 WARN_ON(pipe != crtc->pipe);
8957 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8959 DRM_DEBUG_KMS("failed to alloc fb\n");
8963 fb = &intel_fb->base;
8967 val = I915_READ(DSPCNTR(i9xx_plane));
8969 if (INTEL_GEN(dev_priv) >= 4) {
8970 if (val & DISPPLANE_TILED) {
8971 plane_config->tiling = I915_TILING_X;
8972 fb->modifier = I915_FORMAT_MOD_X_TILED;
8975 if (val & DISPPLANE_ROTATE_180)
8976 plane_config->rotation = DRM_MODE_ROTATE_180;
8979 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8980 val & DISPPLANE_MIRROR)
8981 plane_config->rotation |= DRM_MODE_REFLECT_X;
8983 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8984 fourcc = i9xx_format_to_fourcc(pixel_format);
8985 fb->format = drm_format_info(fourcc);
8987 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8988 offset = I915_READ(DSPOFFSET(i9xx_plane));
8989 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8990 } else if (INTEL_GEN(dev_priv) >= 4) {
8991 if (plane_config->tiling)
8992 offset = I915_READ(DSPTILEOFF(i9xx_plane));
8994 offset = I915_READ(DSPLINOFF(i9xx_plane));
8995 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8997 base = I915_READ(DSPADDR(i9xx_plane));
8999 plane_config->base = base;
9001 val = I915_READ(PIPESRC(pipe));
9002 fb->width = ((val >> 16) & 0xfff) + 1;
9003 fb->height = ((val >> 0) & 0xfff) + 1;
9005 val = I915_READ(DSPSTRIDE(i9xx_plane));
9006 fb->pitches[0] = val & 0xffffffc0;
9008 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9010 plane_config->size = fb->pitches[0] * aligned_height;
9012 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9013 crtc->base.name, plane->base.name, fb->width, fb->height,
9014 fb->format->cpp[0] * 8, base, fb->pitches[0],
9015 plane_config->size);
9017 plane_config->fb = intel_fb;
9020 static void chv_crtc_clock_get(struct intel_crtc *crtc,
9021 struct intel_crtc_state *pipe_config)
9023 struct drm_device *dev = crtc->base.dev;
9024 struct drm_i915_private *dev_priv = to_i915(dev);
9025 enum pipe pipe = crtc->pipe;
9026 enum dpio_channel port = vlv_pipe_to_channel(pipe);
9028 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
9029 int refclk = 100000;
9031 /* In case of DSI, DPLL will not be used */
9032 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
9035 vlv_dpio_get(dev_priv);
9036 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
9037 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
9038 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
9039 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
9040 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
9041 vlv_dpio_put(dev_priv);
9043 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
9044 clock.m2 = (pll_dw0 & 0xff) << 22;
9045 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
9046 clock.m2 |= pll_dw2 & 0x3fffff;
9047 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
9048 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
9049 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
9051 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
9054 static enum intel_output_format
9055 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
9057 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9060 tmp = I915_READ(PIPEMISC(crtc->pipe));
9062 if (tmp & PIPEMISC_YUV420_ENABLE) {
9063 /* We support 4:2:0 in full blend mode only */
9064 WARN_ON((tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
9066 return INTEL_OUTPUT_FORMAT_YCBCR420;
9067 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
9068 return INTEL_OUTPUT_FORMAT_YCBCR444;
9070 return INTEL_OUTPUT_FORMAT_RGB;
9074 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
9076 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9077 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9078 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9079 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
9082 tmp = I915_READ(DSPCNTR(i9xx_plane));
9084 if (tmp & DISPPLANE_GAMMA_ENABLE)
9085 crtc_state->gamma_enable = true;
9087 if (!HAS_GMCH(dev_priv) &&
9088 tmp & DISPPLANE_PIPE_CSC_ENABLE)
9089 crtc_state->csc_enable = true;
9092 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
9093 struct intel_crtc_state *pipe_config)
9095 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9096 enum intel_display_power_domain power_domain;
9097 intel_wakeref_t wakeref;
9101 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9102 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9106 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9107 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9108 pipe_config->shared_dpll = NULL;
9109 pipe_config->master_transcoder = INVALID_TRANSCODER;
9113 tmp = I915_READ(PIPECONF(crtc->pipe));
9114 if (!(tmp & PIPECONF_ENABLE))
9117 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
9118 IS_CHERRYVIEW(dev_priv)) {
9119 switch (tmp & PIPECONF_BPC_MASK) {
9121 pipe_config->pipe_bpp = 18;
9124 pipe_config->pipe_bpp = 24;
9126 case PIPECONF_10BPC:
9127 pipe_config->pipe_bpp = 30;
9134 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
9135 (tmp & PIPECONF_COLOR_RANGE_SELECT))
9136 pipe_config->limited_color_range = true;
9138 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
9139 PIPECONF_GAMMA_MODE_SHIFT;
9141 if (IS_CHERRYVIEW(dev_priv))
9142 pipe_config->cgm_mode = I915_READ(CGM_PIPE_MODE(crtc->pipe));
9144 i9xx_get_pipe_color_config(pipe_config);
9145 intel_color_get_config(pipe_config);
9147 if (INTEL_GEN(dev_priv) < 4)
9148 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
9150 intel_get_pipe_timings(crtc, pipe_config);
9151 intel_get_pipe_src_size(crtc, pipe_config);
9153 i9xx_get_pfit_config(crtc, pipe_config);
9155 if (INTEL_GEN(dev_priv) >= 4) {
9156 /* No way to read it out on pipes B and C */
9157 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
9158 tmp = dev_priv->chv_dpll_md[crtc->pipe];
9160 tmp = I915_READ(DPLL_MD(crtc->pipe));
9161 pipe_config->pixel_multiplier =
9162 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
9163 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
9164 pipe_config->dpll_hw_state.dpll_md = tmp;
9165 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
9166 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
9167 tmp = I915_READ(DPLL(crtc->pipe));
9168 pipe_config->pixel_multiplier =
9169 ((tmp & SDVO_MULTIPLIER_MASK)
9170 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
9172 /* Note that on i915G/GM the pixel multiplier is in the sdvo
9173 * port and will be fixed up in the encoder->get_config
9175 pipe_config->pixel_multiplier = 1;
9177 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
9178 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
9179 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
9180 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
9182 /* Mask out read-only status bits. */
9183 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
9184 DPLL_PORTC_READY_MASK |
9185 DPLL_PORTB_READY_MASK);
9188 if (IS_CHERRYVIEW(dev_priv))
9189 chv_crtc_clock_get(crtc, pipe_config);
9190 else if (IS_VALLEYVIEW(dev_priv))
9191 vlv_crtc_clock_get(crtc, pipe_config);
9193 i9xx_crtc_clock_get(crtc, pipe_config);
9196 * Normally the dotclock is filled in by the encoder .get_config()
9197 * but in case the pipe is enabled w/o any ports we need a sane
9200 pipe_config->hw.adjusted_mode.crtc_clock =
9201 pipe_config->port_clock / pipe_config->pixel_multiplier;
9206 intel_display_power_put(dev_priv, power_domain, wakeref);
9211 static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv)
9213 struct intel_encoder *encoder;
9216 bool has_lvds = false;
9217 bool has_cpu_edp = false;
9218 bool has_panel = false;
9219 bool has_ck505 = false;
9220 bool can_ssc = false;
9221 bool using_ssc_source = false;
9223 /* We need to take the global config into account */
9224 for_each_intel_encoder(&dev_priv->drm, encoder) {
9225 switch (encoder->type) {
9226 case INTEL_OUTPUT_LVDS:
9230 case INTEL_OUTPUT_EDP:
9232 if (encoder->port == PORT_A)
9240 if (HAS_PCH_IBX(dev_priv)) {
9241 has_ck505 = dev_priv->vbt.display_clock_mode;
9242 can_ssc = has_ck505;
9248 /* Check if any DPLLs are using the SSC source */
9249 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
9250 u32 temp = I915_READ(PCH_DPLL(i));
9252 if (!(temp & DPLL_VCO_ENABLE))
9255 if ((temp & PLL_REF_INPUT_MASK) ==
9256 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
9257 using_ssc_source = true;
9262 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
9263 has_panel, has_lvds, has_ck505, using_ssc_source);
9265 /* Ironlake: try to setup display ref clock before DPLL
9266 * enabling. This is only under driver's control after
9267 * PCH B stepping, previous chipset stepping should be
9268 * ignoring this setting.
9270 val = I915_READ(PCH_DREF_CONTROL);
9272 /* As we must carefully and slowly disable/enable each source in turn,
9273 * compute the final state we want first and check if we need to
9274 * make any changes at all.
9277 final &= ~DREF_NONSPREAD_SOURCE_MASK;
9279 final |= DREF_NONSPREAD_CK505_ENABLE;
9281 final |= DREF_NONSPREAD_SOURCE_ENABLE;
9283 final &= ~DREF_SSC_SOURCE_MASK;
9284 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9285 final &= ~DREF_SSC1_ENABLE;
9288 final |= DREF_SSC_SOURCE_ENABLE;
9290 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9291 final |= DREF_SSC1_ENABLE;
9294 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9295 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9297 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9299 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9300 } else if (using_ssc_source) {
9301 final |= DREF_SSC_SOURCE_ENABLE;
9302 final |= DREF_SSC1_ENABLE;
9308 /* Always enable nonspread source */
9309 val &= ~DREF_NONSPREAD_SOURCE_MASK;
9312 val |= DREF_NONSPREAD_CK505_ENABLE;
9314 val |= DREF_NONSPREAD_SOURCE_ENABLE;
9317 val &= ~DREF_SSC_SOURCE_MASK;
9318 val |= DREF_SSC_SOURCE_ENABLE;
9320 /* SSC must be turned on before enabling the CPU output */
9321 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9322 DRM_DEBUG_KMS("Using SSC on panel\n");
9323 val |= DREF_SSC1_ENABLE;
9325 val &= ~DREF_SSC1_ENABLE;
9327 /* Get SSC going before enabling the outputs */
9328 I915_WRITE(PCH_DREF_CONTROL, val);
9329 POSTING_READ(PCH_DREF_CONTROL);
9332 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9334 /* Enable CPU source on CPU attached eDP */
9336 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9337 DRM_DEBUG_KMS("Using SSC on eDP\n");
9338 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9340 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9342 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9344 I915_WRITE(PCH_DREF_CONTROL, val);
9345 POSTING_READ(PCH_DREF_CONTROL);
9348 DRM_DEBUG_KMS("Disabling CPU source output\n");
9350 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9352 /* Turn off CPU output */
9353 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9355 I915_WRITE(PCH_DREF_CONTROL, val);
9356 POSTING_READ(PCH_DREF_CONTROL);
9359 if (!using_ssc_source) {
9360 DRM_DEBUG_KMS("Disabling SSC source\n");
9362 /* Turn off the SSC source */
9363 val &= ~DREF_SSC_SOURCE_MASK;
9364 val |= DREF_SSC_SOURCE_DISABLE;
9367 val &= ~DREF_SSC1_ENABLE;
9369 I915_WRITE(PCH_DREF_CONTROL, val);
9370 POSTING_READ(PCH_DREF_CONTROL);
9375 BUG_ON(val != final);
9378 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9382 tmp = I915_READ(SOUTH_CHICKEN2);
9383 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9384 I915_WRITE(SOUTH_CHICKEN2, tmp);
9386 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
9387 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9388 DRM_ERROR("FDI mPHY reset assert timeout\n");
9390 tmp = I915_READ(SOUTH_CHICKEN2);
9391 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9392 I915_WRITE(SOUTH_CHICKEN2, tmp);
9394 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
9395 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9396 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
9399 /* WaMPhyProgramming:hsw */
9400 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9404 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9405 tmp &= ~(0xFF << 24);
9406 tmp |= (0x12 << 24);
9407 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9409 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9411 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9413 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9415 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9417 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9418 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9419 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9421 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9422 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9423 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9425 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9428 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9430 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9433 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9435 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9438 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9440 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9443 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9445 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9446 tmp &= ~(0xFF << 16);
9447 tmp |= (0x1C << 16);
9448 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9450 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9451 tmp &= ~(0xFF << 16);
9452 tmp |= (0x1C << 16);
9453 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9455 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9457 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9459 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9461 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9463 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9464 tmp &= ~(0xF << 28);
9466 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9468 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9469 tmp &= ~(0xF << 28);
9471 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9474 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9475 * Programming" based on the parameters passed:
9476 * - Sequence to enable CLKOUT_DP
9477 * - Sequence to enable CLKOUT_DP without spread
9478 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9480 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9481 bool with_spread, bool with_fdi)
9485 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
9487 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
9488 with_fdi, "LP PCH doesn't have FDI\n"))
9491 mutex_lock(&dev_priv->sb_lock);
9493 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9494 tmp &= ~SBI_SSCCTL_DISABLE;
9495 tmp |= SBI_SSCCTL_PATHALT;
9496 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9501 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9502 tmp &= ~SBI_SSCCTL_PATHALT;
9503 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9506 lpt_reset_fdi_mphy(dev_priv);
9507 lpt_program_fdi_mphy(dev_priv);
9511 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9512 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9513 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9514 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9516 mutex_unlock(&dev_priv->sb_lock);
9519 /* Sequence to disable CLKOUT_DP */
9520 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9524 mutex_lock(&dev_priv->sb_lock);
9526 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9527 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9528 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9529 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9531 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9532 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9533 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9534 tmp |= SBI_SSCCTL_PATHALT;
9535 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9538 tmp |= SBI_SSCCTL_DISABLE;
9539 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9542 mutex_unlock(&dev_priv->sb_lock);
9545 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9547 static const u16 sscdivintphase[] = {
9548 [BEND_IDX( 50)] = 0x3B23,
9549 [BEND_IDX( 45)] = 0x3B23,
9550 [BEND_IDX( 40)] = 0x3C23,
9551 [BEND_IDX( 35)] = 0x3C23,
9552 [BEND_IDX( 30)] = 0x3D23,
9553 [BEND_IDX( 25)] = 0x3D23,
9554 [BEND_IDX( 20)] = 0x3E23,
9555 [BEND_IDX( 15)] = 0x3E23,
9556 [BEND_IDX( 10)] = 0x3F23,
9557 [BEND_IDX( 5)] = 0x3F23,
9558 [BEND_IDX( 0)] = 0x0025,
9559 [BEND_IDX( -5)] = 0x0025,
9560 [BEND_IDX(-10)] = 0x0125,
9561 [BEND_IDX(-15)] = 0x0125,
9562 [BEND_IDX(-20)] = 0x0225,
9563 [BEND_IDX(-25)] = 0x0225,
9564 [BEND_IDX(-30)] = 0x0325,
9565 [BEND_IDX(-35)] = 0x0325,
9566 [BEND_IDX(-40)] = 0x0425,
9567 [BEND_IDX(-45)] = 0x0425,
9568 [BEND_IDX(-50)] = 0x0525,
9573 * steps -50 to 50 inclusive, in steps of 5
9574 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9575 * change in clock period = -(steps / 10) * 5.787 ps
9577 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9580 int idx = BEND_IDX(steps);
9582 if (WARN_ON(steps % 5 != 0))
9585 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
9588 mutex_lock(&dev_priv->sb_lock);
9590 if (steps % 10 != 0)
9594 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9596 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9598 tmp |= sscdivintphase[idx];
9599 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9601 mutex_unlock(&dev_priv->sb_lock);
9606 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9608 u32 fuse_strap = I915_READ(FUSE_STRAP);
9609 u32 ctl = I915_READ(SPLL_CTL);
9611 if ((ctl & SPLL_PLL_ENABLE) == 0)
9614 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9615 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9618 if (IS_BROADWELL(dev_priv) &&
9619 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9625 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9626 enum intel_dpll_id id)
9628 u32 fuse_strap = I915_READ(FUSE_STRAP);
9629 u32 ctl = I915_READ(WRPLL_CTL(id));
9631 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9634 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9637 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9638 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9639 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9645 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9647 struct intel_encoder *encoder;
9648 bool has_fdi = false;
9650 for_each_intel_encoder(&dev_priv->drm, encoder) {
9651 switch (encoder->type) {
9652 case INTEL_OUTPUT_ANALOG:
9661 * The BIOS may have decided to use the PCH SSC
9662 * reference so we must not disable it until the
9663 * relevant PLLs have stopped relying on it. We'll
9664 * just leave the PCH SSC reference enabled in case
9665 * any active PLL is using it. It will get disabled
9666 * after runtime suspend if we don't have FDI.
9668 * TODO: Move the whole reference clock handling
9669 * to the modeset sequence proper so that we can
9670 * actually enable/disable/reconfigure these things
9671 * safely. To do that we need to introduce a real
9672 * clock hierarchy. That would also allow us to do
9673 * clock bending finally.
9675 dev_priv->pch_ssc_use = 0;
9677 if (spll_uses_pch_ssc(dev_priv)) {
9678 DRM_DEBUG_KMS("SPLL using PCH SSC\n");
9679 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
9682 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9683 DRM_DEBUG_KMS("WRPLL1 using PCH SSC\n");
9684 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
9687 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9688 DRM_DEBUG_KMS("WRPLL2 using PCH SSC\n");
9689 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
9692 if (dev_priv->pch_ssc_use)
9696 lpt_bend_clkout_dp(dev_priv, 0);
9697 lpt_enable_clkout_dp(dev_priv, true, true);
9699 lpt_disable_clkout_dp(dev_priv);
9704 * Initialize reference clocks when the driver loads
9706 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
9708 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
9709 ilk_init_pch_refclk(dev_priv);
9710 else if (HAS_PCH_LPT(dev_priv))
9711 lpt_init_pch_refclk(dev_priv);
9714 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
9716 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9717 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9718 enum pipe pipe = crtc->pipe;
9723 switch (crtc_state->pipe_bpp) {
9725 val |= PIPECONF_6BPC;
9728 val |= PIPECONF_8BPC;
9731 val |= PIPECONF_10BPC;
9734 val |= PIPECONF_12BPC;
9737 /* Case prevented by intel_choose_pipe_bpp_dither. */
9741 if (crtc_state->dither)
9742 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9744 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9745 val |= PIPECONF_INTERLACED_ILK;
9747 val |= PIPECONF_PROGRESSIVE;
9750 * This would end up with an odd purple hue over
9751 * the entire display. Make sure we don't do it.
9753 WARN_ON(crtc_state->limited_color_range &&
9754 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
9756 if (crtc_state->limited_color_range)
9757 val |= PIPECONF_COLOR_RANGE_SELECT;
9759 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
9760 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
9762 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
9764 val |= PIPECONF_FRAME_START_DELAY(0);
9766 I915_WRITE(PIPECONF(pipe), val);
9767 POSTING_READ(PIPECONF(pipe));
9770 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state)
9772 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9773 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9774 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
9777 if (IS_HASWELL(dev_priv) && crtc_state->dither)
9778 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9780 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9781 val |= PIPECONF_INTERLACED_ILK;
9783 val |= PIPECONF_PROGRESSIVE;
9785 if (IS_HASWELL(dev_priv) &&
9786 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
9787 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
9789 I915_WRITE(PIPECONF(cpu_transcoder), val);
9790 POSTING_READ(PIPECONF(cpu_transcoder));
9793 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
9795 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9799 switch (crtc_state->pipe_bpp) {
9801 val |= PIPEMISC_DITHER_6_BPC;
9804 val |= PIPEMISC_DITHER_8_BPC;
9807 val |= PIPEMISC_DITHER_10_BPC;
9810 val |= PIPEMISC_DITHER_12_BPC;
9813 MISSING_CASE(crtc_state->pipe_bpp);
9817 if (crtc_state->dither)
9818 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
9820 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
9821 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
9822 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
9824 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
9825 val |= PIPEMISC_YUV420_ENABLE |
9826 PIPEMISC_YUV420_MODE_FULL_BLEND;
9828 if (INTEL_GEN(dev_priv) >= 11 &&
9829 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
9830 BIT(PLANE_CURSOR))) == 0)
9831 val |= PIPEMISC_HDR_MODE_PRECISION;
9833 I915_WRITE(PIPEMISC(crtc->pipe), val);
9836 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
9838 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9841 tmp = I915_READ(PIPEMISC(crtc->pipe));
9843 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
9844 case PIPEMISC_DITHER_6_BPC:
9846 case PIPEMISC_DITHER_8_BPC:
9848 case PIPEMISC_DITHER_10_BPC:
9850 case PIPEMISC_DITHER_12_BPC:
9858 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
9861 * Account for spread spectrum to avoid
9862 * oversubscribing the link. Max center spread
9863 * is 2.5%; use 5% for safety's sake.
9865 u32 bps = target_clock * bpp * 21 / 20;
9866 return DIV_ROUND_UP(bps, link_bw * 8);
9869 static bool ilk_needs_fb_cb_tune(struct dpll *dpll, int factor)
9871 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
9874 static void ilk_compute_dpll(struct intel_crtc *crtc,
9875 struct intel_crtc_state *crtc_state,
9876 struct dpll *reduced_clock)
9878 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9882 /* Enable autotuning of the PLL clock (if permissible) */
9884 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9885 if ((intel_panel_use_ssc(dev_priv) &&
9886 dev_priv->vbt.lvds_ssc_freq == 100000) ||
9887 (HAS_PCH_IBX(dev_priv) &&
9888 intel_is_dual_link_lvds(dev_priv)))
9890 } else if (crtc_state->sdvo_tv_clock) {
9894 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
9896 if (ilk_needs_fb_cb_tune(&crtc_state->dpll, factor))
9899 if (reduced_clock) {
9900 fp2 = i9xx_dpll_compute_fp(reduced_clock);
9902 if (reduced_clock->m < factor * reduced_clock->n)
9910 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
9911 dpll |= DPLLB_MODE_LVDS;
9913 dpll |= DPLLB_MODE_DAC_SERIAL;
9915 dpll |= (crtc_state->pixel_multiplier - 1)
9916 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
9918 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
9919 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
9920 dpll |= DPLL_SDVO_HIGH_SPEED;
9922 if (intel_crtc_has_dp_encoder(crtc_state))
9923 dpll |= DPLL_SDVO_HIGH_SPEED;
9926 * The high speed IO clock is only really required for
9927 * SDVO/HDMI/DP, but we also enable it for CRT to make it
9928 * possible to share the DPLL between CRT and HDMI. Enabling
9929 * the clock needlessly does no real harm, except use up a
9930 * bit of power potentially.
9932 * We'll limit this to IVB with 3 pipes, since it has only two
9933 * DPLLs and so DPLL sharing is the only way to get three pipes
9934 * driving PCH ports at the same time. On SNB we could do this,
9935 * and potentially avoid enabling the second DPLL, but it's not
9936 * clear if it''s a win or loss power wise. No point in doing
9937 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
9939 if (INTEL_NUM_PIPES(dev_priv) == 3 &&
9940 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
9941 dpll |= DPLL_SDVO_HIGH_SPEED;
9943 /* compute bitmask from p1 value */
9944 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
9946 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
9948 switch (crtc_state->dpll.p2) {
9950 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
9953 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
9956 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
9959 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
9963 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
9964 intel_panel_use_ssc(dev_priv))
9965 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
9967 dpll |= PLL_REF_INPUT_DREFCLK;
9969 dpll |= DPLL_VCO_ENABLE;
9971 crtc_state->dpll_hw_state.dpll = dpll;
9972 crtc_state->dpll_hw_state.fp0 = fp;
9973 crtc_state->dpll_hw_state.fp1 = fp2;
9976 static int ilk_crtc_compute_clock(struct intel_crtc *crtc,
9977 struct intel_crtc_state *crtc_state)
9979 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9980 struct intel_atomic_state *state =
9981 to_intel_atomic_state(crtc_state->uapi.state);
9982 const struct intel_limit *limit;
9983 int refclk = 120000;
9985 memset(&crtc_state->dpll_hw_state, 0,
9986 sizeof(crtc_state->dpll_hw_state));
9988 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
9989 if (!crtc_state->has_pch_encoder)
9992 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9993 if (intel_panel_use_ssc(dev_priv)) {
9994 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
9995 dev_priv->vbt.lvds_ssc_freq);
9996 refclk = dev_priv->vbt.lvds_ssc_freq;
9999 if (intel_is_dual_link_lvds(dev_priv)) {
10000 if (refclk == 100000)
10001 limit = &ilk_limits_dual_lvds_100m;
10003 limit = &ilk_limits_dual_lvds;
10005 if (refclk == 100000)
10006 limit = &ilk_limits_single_lvds_100m;
10008 limit = &ilk_limits_single_lvds;
10011 limit = &ilk_limits_dac;
10014 if (!crtc_state->clock_set &&
10015 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
10016 refclk, NULL, &crtc_state->dpll)) {
10017 DRM_ERROR("Couldn't find PLL settings for mode!\n");
10021 ilk_compute_dpll(crtc, crtc_state, NULL);
10023 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
10024 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10025 pipe_name(crtc->pipe));
10032 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
10033 struct intel_link_m_n *m_n)
10035 struct drm_device *dev = crtc->base.dev;
10036 struct drm_i915_private *dev_priv = to_i915(dev);
10037 enum pipe pipe = crtc->pipe;
10039 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
10040 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
10041 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
10043 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
10044 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
10045 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10048 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
10049 enum transcoder transcoder,
10050 struct intel_link_m_n *m_n,
10051 struct intel_link_m_n *m2_n2)
10053 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10054 enum pipe pipe = crtc->pipe;
10056 if (INTEL_GEN(dev_priv) >= 5) {
10057 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
10058 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
10059 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
10061 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
10062 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
10063 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10065 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
10066 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
10067 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
10068 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
10070 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
10071 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
10072 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10075 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
10076 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
10077 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
10079 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
10080 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
10081 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10085 void intel_dp_get_m_n(struct intel_crtc *crtc,
10086 struct intel_crtc_state *pipe_config)
10088 if (pipe_config->has_pch_encoder)
10089 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
10091 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10092 &pipe_config->dp_m_n,
10093 &pipe_config->dp_m2_n2);
10096 static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc,
10097 struct intel_crtc_state *pipe_config)
10099 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10100 &pipe_config->fdi_m_n, NULL);
10103 static void skl_get_pfit_config(struct intel_crtc *crtc,
10104 struct intel_crtc_state *pipe_config)
10106 struct drm_device *dev = crtc->base.dev;
10107 struct drm_i915_private *dev_priv = to_i915(dev);
10108 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
10113 /* find scaler attached to this pipe */
10114 for (i = 0; i < crtc->num_scalers; i++) {
10115 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
10116 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
10118 pipe_config->pch_pfit.enabled = true;
10119 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
10120 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
10121 scaler_state->scalers[i].in_use = true;
10126 scaler_state->scaler_id = id;
10128 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
10130 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
10135 skl_get_initial_plane_config(struct intel_crtc *crtc,
10136 struct intel_initial_plane_config *plane_config)
10138 struct drm_device *dev = crtc->base.dev;
10139 struct drm_i915_private *dev_priv = to_i915(dev);
10140 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
10141 enum plane_id plane_id = plane->id;
10143 u32 val, base, offset, stride_mult, tiling, alpha;
10144 int fourcc, pixel_format;
10145 unsigned int aligned_height;
10146 struct drm_framebuffer *fb;
10147 struct intel_framebuffer *intel_fb;
10149 if (!plane->get_hw_state(plane, &pipe))
10152 WARN_ON(pipe != crtc->pipe);
10154 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10156 DRM_DEBUG_KMS("failed to alloc fb\n");
10160 fb = &intel_fb->base;
10164 val = I915_READ(PLANE_CTL(pipe, plane_id));
10166 if (INTEL_GEN(dev_priv) >= 11)
10167 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
10169 pixel_format = val & PLANE_CTL_FORMAT_MASK;
10171 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
10172 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
10173 alpha &= PLANE_COLOR_ALPHA_MASK;
10175 alpha = val & PLANE_CTL_ALPHA_MASK;
10178 fourcc = skl_format_to_fourcc(pixel_format,
10179 val & PLANE_CTL_ORDER_RGBX, alpha);
10180 fb->format = drm_format_info(fourcc);
10182 tiling = val & PLANE_CTL_TILED_MASK;
10184 case PLANE_CTL_TILED_LINEAR:
10185 fb->modifier = DRM_FORMAT_MOD_LINEAR;
10187 case PLANE_CTL_TILED_X:
10188 plane_config->tiling = I915_TILING_X;
10189 fb->modifier = I915_FORMAT_MOD_X_TILED;
10191 case PLANE_CTL_TILED_Y:
10192 plane_config->tiling = I915_TILING_Y;
10193 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10194 fb->modifier = INTEL_GEN(dev_priv) >= 12 ?
10195 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS :
10196 I915_FORMAT_MOD_Y_TILED_CCS;
10198 fb->modifier = I915_FORMAT_MOD_Y_TILED;
10200 case PLANE_CTL_TILED_YF:
10201 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10202 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
10204 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
10207 MISSING_CASE(tiling);
10212 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
10213 * while i915 HW rotation is clockwise, thats why this swapping.
10215 switch (val & PLANE_CTL_ROTATE_MASK) {
10216 case PLANE_CTL_ROTATE_0:
10217 plane_config->rotation = DRM_MODE_ROTATE_0;
10219 case PLANE_CTL_ROTATE_90:
10220 plane_config->rotation = DRM_MODE_ROTATE_270;
10222 case PLANE_CTL_ROTATE_180:
10223 plane_config->rotation = DRM_MODE_ROTATE_180;
10225 case PLANE_CTL_ROTATE_270:
10226 plane_config->rotation = DRM_MODE_ROTATE_90;
10230 if (INTEL_GEN(dev_priv) >= 10 &&
10231 val & PLANE_CTL_FLIP_HORIZONTAL)
10232 plane_config->rotation |= DRM_MODE_REFLECT_X;
10234 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
10235 plane_config->base = base;
10237 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
10239 val = I915_READ(PLANE_SIZE(pipe, plane_id));
10240 fb->height = ((val >> 16) & 0xffff) + 1;
10241 fb->width = ((val >> 0) & 0xffff) + 1;
10243 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
10244 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
10245 fb->pitches[0] = (val & 0x3ff) * stride_mult;
10247 aligned_height = intel_fb_align_height(fb, 0, fb->height);
10249 plane_config->size = fb->pitches[0] * aligned_height;
10251 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
10252 crtc->base.name, plane->base.name, fb->width, fb->height,
10253 fb->format->cpp[0] * 8, base, fb->pitches[0],
10254 plane_config->size);
10256 plane_config->fb = intel_fb;
10263 static void ilk_get_pfit_config(struct intel_crtc *crtc,
10264 struct intel_crtc_state *pipe_config)
10266 struct drm_device *dev = crtc->base.dev;
10267 struct drm_i915_private *dev_priv = to_i915(dev);
10270 tmp = I915_READ(PF_CTL(crtc->pipe));
10272 if (tmp & PF_ENABLE) {
10273 pipe_config->pch_pfit.enabled = true;
10274 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
10275 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
10277 /* We currently do not free assignements of panel fitters on
10278 * ivb/hsw (since we don't use the higher upscaling modes which
10279 * differentiates them) so just WARN about this case for now. */
10280 if (IS_GEN(dev_priv, 7)) {
10281 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
10282 PF_PIPE_SEL_IVB(crtc->pipe));
10287 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
10288 struct intel_crtc_state *pipe_config)
10290 struct drm_device *dev = crtc->base.dev;
10291 struct drm_i915_private *dev_priv = to_i915(dev);
10292 enum intel_display_power_domain power_domain;
10293 intel_wakeref_t wakeref;
10297 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10298 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10302 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10303 pipe_config->shared_dpll = NULL;
10304 pipe_config->master_transcoder = INVALID_TRANSCODER;
10307 tmp = I915_READ(PIPECONF(crtc->pipe));
10308 if (!(tmp & PIPECONF_ENABLE))
10311 switch (tmp & PIPECONF_BPC_MASK) {
10312 case PIPECONF_6BPC:
10313 pipe_config->pipe_bpp = 18;
10315 case PIPECONF_8BPC:
10316 pipe_config->pipe_bpp = 24;
10318 case PIPECONF_10BPC:
10319 pipe_config->pipe_bpp = 30;
10321 case PIPECONF_12BPC:
10322 pipe_config->pipe_bpp = 36;
10328 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
10329 pipe_config->limited_color_range = true;
10331 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
10332 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
10333 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
10334 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10337 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10341 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
10342 PIPECONF_GAMMA_MODE_SHIFT;
10344 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
10346 i9xx_get_pipe_color_config(pipe_config);
10347 intel_color_get_config(pipe_config);
10349 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
10350 struct intel_shared_dpll *pll;
10351 enum intel_dpll_id pll_id;
10353 pipe_config->has_pch_encoder = true;
10355 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
10356 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10357 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10359 ilk_get_fdi_m_n_config(crtc, pipe_config);
10361 if (HAS_PCH_IBX(dev_priv)) {
10363 * The pipe->pch transcoder and pch transcoder->pll
10364 * mapping is fixed.
10366 pll_id = (enum intel_dpll_id) crtc->pipe;
10368 tmp = I915_READ(PCH_DPLL_SEL);
10369 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
10370 pll_id = DPLL_ID_PCH_PLL_B;
10372 pll_id= DPLL_ID_PCH_PLL_A;
10375 pipe_config->shared_dpll =
10376 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10377 pll = pipe_config->shared_dpll;
10379 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10380 &pipe_config->dpll_hw_state));
10382 tmp = pipe_config->dpll_hw_state.dpll;
10383 pipe_config->pixel_multiplier =
10384 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10385 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10387 ilk_pch_clock_get(crtc, pipe_config);
10389 pipe_config->pixel_multiplier = 1;
10392 intel_get_pipe_timings(crtc, pipe_config);
10393 intel_get_pipe_src_size(crtc, pipe_config);
10395 ilk_get_pfit_config(crtc, pipe_config);
10400 intel_display_power_put(dev_priv, power_domain, wakeref);
10405 static int hsw_crtc_compute_clock(struct intel_crtc *crtc,
10406 struct intel_crtc_state *crtc_state)
10408 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10409 struct intel_atomic_state *state =
10410 to_intel_atomic_state(crtc_state->uapi.state);
10412 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10413 INTEL_GEN(dev_priv) >= 11) {
10414 struct intel_encoder *encoder =
10415 intel_get_crtc_new_encoder(state, crtc_state);
10417 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10418 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10419 pipe_name(crtc->pipe));
10427 static void cnl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10428 struct intel_crtc_state *pipe_config)
10430 enum intel_dpll_id id;
10433 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10434 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10436 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
10439 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10442 static void icl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10443 struct intel_crtc_state *pipe_config)
10445 enum phy phy = intel_port_to_phy(dev_priv, port);
10446 enum icl_port_dpll_id port_dpll_id;
10447 enum intel_dpll_id id;
10450 if (intel_phy_is_combo(dev_priv, phy)) {
10451 temp = I915_READ(ICL_DPCLKA_CFGCR0) &
10452 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10453 id = temp >> ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10454 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10455 } else if (intel_phy_is_tc(dev_priv, phy)) {
10456 u32 clk_sel = I915_READ(DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
10458 if (clk_sel == DDI_CLK_SEL_MG) {
10459 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
10461 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
10463 WARN_ON(clk_sel < DDI_CLK_SEL_TBT_162);
10464 id = DPLL_ID_ICL_TBTPLL;
10465 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10468 WARN(1, "Invalid port %x\n", port);
10472 pipe_config->icl_port_dplls[port_dpll_id].pll =
10473 intel_get_shared_dpll_by_id(dev_priv, id);
10475 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10478 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
10480 struct intel_crtc_state *pipe_config)
10482 enum intel_dpll_id id;
10486 id = DPLL_ID_SKL_DPLL0;
10489 id = DPLL_ID_SKL_DPLL1;
10492 id = DPLL_ID_SKL_DPLL2;
10495 DRM_ERROR("Incorrect port type\n");
10499 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10502 static void skl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10503 struct intel_crtc_state *pipe_config)
10505 enum intel_dpll_id id;
10508 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10509 id = temp >> (port * 3 + 1);
10511 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
10514 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10517 static void hsw_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10518 struct intel_crtc_state *pipe_config)
10520 enum intel_dpll_id id;
10521 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
10523 switch (ddi_pll_sel) {
10524 case PORT_CLK_SEL_WRPLL1:
10525 id = DPLL_ID_WRPLL1;
10527 case PORT_CLK_SEL_WRPLL2:
10528 id = DPLL_ID_WRPLL2;
10530 case PORT_CLK_SEL_SPLL:
10533 case PORT_CLK_SEL_LCPLL_810:
10534 id = DPLL_ID_LCPLL_810;
10536 case PORT_CLK_SEL_LCPLL_1350:
10537 id = DPLL_ID_LCPLL_1350;
10539 case PORT_CLK_SEL_LCPLL_2700:
10540 id = DPLL_ID_LCPLL_2700;
10543 MISSING_CASE(ddi_pll_sel);
10545 case PORT_CLK_SEL_NONE:
10549 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10552 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10553 struct intel_crtc_state *pipe_config,
10554 u64 *power_domain_mask,
10555 intel_wakeref_t *wakerefs)
10557 struct drm_device *dev = crtc->base.dev;
10558 struct drm_i915_private *dev_priv = to_i915(dev);
10559 enum intel_display_power_domain power_domain;
10560 unsigned long panel_transcoder_mask = 0;
10561 unsigned long enabled_panel_transcoders = 0;
10562 enum transcoder panel_transcoder;
10563 intel_wakeref_t wf;
10566 if (INTEL_GEN(dev_priv) >= 11)
10567 panel_transcoder_mask |=
10568 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10570 if (HAS_TRANSCODER_EDP(dev_priv))
10571 panel_transcoder_mask |= BIT(TRANSCODER_EDP);
10574 * The pipe->transcoder mapping is fixed with the exception of the eDP
10575 * and DSI transcoders handled below.
10577 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10580 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10581 * consistency and less surprising code; it's in always on power).
10583 for_each_set_bit(panel_transcoder,
10584 &panel_transcoder_mask,
10585 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
10586 bool force_thru = false;
10587 enum pipe trans_pipe;
10589 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
10590 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10594 * Log all enabled ones, only use the first one.
10596 * FIXME: This won't work for two separate DSI displays.
10598 enabled_panel_transcoders |= BIT(panel_transcoder);
10599 if (enabled_panel_transcoders != BIT(panel_transcoder))
10602 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10604 WARN(1, "unknown pipe linked to transcoder %s\n",
10605 transcoder_name(panel_transcoder));
10607 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10610 case TRANS_DDI_EDP_INPUT_A_ON:
10611 trans_pipe = PIPE_A;
10613 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10614 trans_pipe = PIPE_B;
10616 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10617 trans_pipe = PIPE_C;
10619 case TRANS_DDI_EDP_INPUT_D_ONOFF:
10620 trans_pipe = PIPE_D;
10624 if (trans_pipe == crtc->pipe) {
10625 pipe_config->cpu_transcoder = panel_transcoder;
10626 pipe_config->pch_pfit.force_thru = force_thru;
10631 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10633 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10634 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10636 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
10637 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10639 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10643 wakerefs[power_domain] = wf;
10644 *power_domain_mask |= BIT_ULL(power_domain);
10646 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10648 return tmp & PIPECONF_ENABLE;
10651 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10652 struct intel_crtc_state *pipe_config,
10653 u64 *power_domain_mask,
10654 intel_wakeref_t *wakerefs)
10656 struct drm_device *dev = crtc->base.dev;
10657 struct drm_i915_private *dev_priv = to_i915(dev);
10658 enum intel_display_power_domain power_domain;
10659 enum transcoder cpu_transcoder;
10660 intel_wakeref_t wf;
10664 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10665 if (port == PORT_A)
10666 cpu_transcoder = TRANSCODER_DSI_A;
10668 cpu_transcoder = TRANSCODER_DSI_C;
10670 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10671 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10673 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10677 wakerefs[power_domain] = wf;
10678 *power_domain_mask |= BIT_ULL(power_domain);
10681 * The PLL needs to be enabled with a valid divider
10682 * configuration, otherwise accessing DSI registers will hang
10683 * the machine. See BSpec North Display Engine
10684 * registers/MIPI[BXT]. We can break out here early, since we
10685 * need the same DSI PLL to be enabled for both DSI ports.
10687 if (!bxt_dsi_pll_is_enabled(dev_priv))
10690 /* XXX: this works for video mode only */
10691 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
10692 if (!(tmp & DPI_ENABLE))
10695 tmp = I915_READ(MIPI_CTRL(port));
10696 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
10699 pipe_config->cpu_transcoder = cpu_transcoder;
10703 return transcoder_is_dsi(pipe_config->cpu_transcoder);
10706 static void hsw_get_ddi_port_state(struct intel_crtc *crtc,
10707 struct intel_crtc_state *pipe_config)
10709 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10710 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
10711 struct intel_shared_dpll *pll;
10715 if (transcoder_is_dsi(cpu_transcoder)) {
10716 port = (cpu_transcoder == TRANSCODER_DSI_A) ?
10719 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
10720 if (INTEL_GEN(dev_priv) >= 12)
10721 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10723 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10726 if (INTEL_GEN(dev_priv) >= 11)
10727 icl_get_ddi_pll(dev_priv, port, pipe_config);
10728 else if (IS_CANNONLAKE(dev_priv))
10729 cnl_get_ddi_pll(dev_priv, port, pipe_config);
10730 else if (IS_GEN9_BC(dev_priv))
10731 skl_get_ddi_pll(dev_priv, port, pipe_config);
10732 else if (IS_GEN9_LP(dev_priv))
10733 bxt_get_ddi_pll(dev_priv, port, pipe_config);
10735 hsw_get_ddi_pll(dev_priv, port, pipe_config);
10737 pll = pipe_config->shared_dpll;
10739 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10740 &pipe_config->dpll_hw_state));
10744 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10745 * DDI E. So just check whether this pipe is wired to DDI E and whether
10746 * the PCH transcoder is on.
10748 if (INTEL_GEN(dev_priv) < 9 &&
10749 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
10750 pipe_config->has_pch_encoder = true;
10752 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
10753 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10754 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10756 ilk_get_fdi_m_n_config(crtc, pipe_config);
10760 static enum transcoder transcoder_master_readout(struct drm_i915_private *dev_priv,
10761 enum transcoder cpu_transcoder)
10763 u32 trans_port_sync, master_select;
10765 trans_port_sync = I915_READ(TRANS_DDI_FUNC_CTL2(cpu_transcoder));
10767 if ((trans_port_sync & PORT_SYNC_MODE_ENABLE) == 0)
10768 return INVALID_TRANSCODER;
10770 master_select = trans_port_sync &
10771 PORT_SYNC_MODE_MASTER_SELECT_MASK;
10772 if (master_select == 0)
10773 return TRANSCODER_EDP;
10775 return master_select - 1;
10778 static void icl_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
10780 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
10782 enum transcoder cpu_transcoder;
10784 crtc_state->master_transcoder = transcoder_master_readout(dev_priv,
10785 crtc_state->cpu_transcoder);
10787 transcoders = BIT(TRANSCODER_A) |
10788 BIT(TRANSCODER_B) |
10789 BIT(TRANSCODER_C) |
10791 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) {
10792 enum intel_display_power_domain power_domain;
10793 intel_wakeref_t trans_wakeref;
10795 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10796 trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
10799 if (!trans_wakeref)
10802 if (transcoder_master_readout(dev_priv, cpu_transcoder) ==
10803 crtc_state->cpu_transcoder)
10804 crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder);
10806 intel_display_power_put(dev_priv, power_domain, trans_wakeref);
10809 WARN_ON(crtc_state->master_transcoder != INVALID_TRANSCODER &&
10810 crtc_state->sync_mode_slaves_mask);
10813 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
10814 struct intel_crtc_state *pipe_config)
10816 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10817 intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf;
10818 enum intel_display_power_domain power_domain;
10819 u64 power_domain_mask;
10822 pipe_config->master_transcoder = INVALID_TRANSCODER;
10824 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10825 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10829 wakerefs[power_domain] = wf;
10830 power_domain_mask = BIT_ULL(power_domain);
10832 pipe_config->shared_dpll = NULL;
10834 active = hsw_get_transcoder_state(crtc, pipe_config,
10835 &power_domain_mask, wakerefs);
10837 if (IS_GEN9_LP(dev_priv) &&
10838 bxt_get_dsi_transcoder_state(crtc, pipe_config,
10839 &power_domain_mask, wakerefs)) {
10847 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
10848 INTEL_GEN(dev_priv) >= 11) {
10849 hsw_get_ddi_port_state(crtc, pipe_config);
10850 intel_get_pipe_timings(crtc, pipe_config);
10853 intel_get_pipe_src_size(crtc, pipe_config);
10855 if (IS_HASWELL(dev_priv)) {
10856 u32 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10858 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
10859 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10861 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10863 pipe_config->output_format =
10864 bdw_get_pipemisc_output_format(crtc);
10867 * Currently there is no interface defined to
10868 * check user preference between RGB/YCBCR444
10869 * or YCBCR420. So the only possible case for
10870 * YCBCR444 usage is driving YCBCR420 output
10871 * with LSPCON, when pipe is configured for
10872 * YCBCR444 output and LSPCON takes care of
10875 pipe_config->lspcon_downsampling =
10876 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444;
10879 pipe_config->gamma_mode = I915_READ(GAMMA_MODE(crtc->pipe));
10881 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
10883 if (INTEL_GEN(dev_priv) >= 9) {
10884 u32 tmp = I915_READ(SKL_BOTTOM_COLOR(crtc->pipe));
10886 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
10887 pipe_config->gamma_enable = true;
10889 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
10890 pipe_config->csc_enable = true;
10892 i9xx_get_pipe_color_config(pipe_config);
10895 intel_color_get_config(pipe_config);
10897 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
10898 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
10900 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10902 wakerefs[power_domain] = wf;
10903 power_domain_mask |= BIT_ULL(power_domain);
10905 if (INTEL_GEN(dev_priv) >= 9)
10906 skl_get_pfit_config(crtc, pipe_config);
10908 ilk_get_pfit_config(crtc, pipe_config);
10911 if (hsw_crtc_supports_ips(crtc)) {
10912 if (IS_HASWELL(dev_priv))
10913 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
10916 * We cannot readout IPS state on broadwell, set to
10917 * true so we can set it to a defined state on first
10920 pipe_config->ips_enabled = true;
10924 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
10925 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
10926 pipe_config->pixel_multiplier =
10927 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
10929 pipe_config->pixel_multiplier = 1;
10932 if (INTEL_GEN(dev_priv) >= 11 &&
10933 !transcoder_is_dsi(pipe_config->cpu_transcoder))
10934 icl_get_trans_port_sync_config(pipe_config);
10937 for_each_power_domain(power_domain, power_domain_mask)
10938 intel_display_power_put(dev_priv,
10939 power_domain, wakerefs[power_domain]);
10944 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
10946 struct drm_i915_private *dev_priv =
10947 to_i915(plane_state->uapi.plane->dev);
10948 const struct drm_framebuffer *fb = plane_state->hw.fb;
10949 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
10952 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
10953 base = obj->phys_handle->busaddr;
10955 base = intel_plane_ggtt_offset(plane_state);
10957 return base + plane_state->color_plane[0].offset;
10960 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
10962 int x = plane_state->uapi.dst.x1;
10963 int y = plane_state->uapi.dst.y1;
10967 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
10970 pos |= x << CURSOR_X_SHIFT;
10973 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
10976 pos |= y << CURSOR_Y_SHIFT;
10981 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
10983 const struct drm_mode_config *config =
10984 &plane_state->uapi.plane->dev->mode_config;
10985 int width = drm_rect_width(&plane_state->uapi.dst);
10986 int height = drm_rect_height(&plane_state->uapi.dst);
10988 return width > 0 && width <= config->cursor_width &&
10989 height > 0 && height <= config->cursor_height;
10992 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
10994 struct drm_i915_private *dev_priv =
10995 to_i915(plane_state->uapi.plane->dev);
10996 unsigned int rotation = plane_state->hw.rotation;
11001 ret = intel_plane_compute_gtt(plane_state);
11005 if (!plane_state->uapi.visible)
11008 src_x = plane_state->uapi.src.x1 >> 16;
11009 src_y = plane_state->uapi.src.y1 >> 16;
11011 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
11012 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
11015 if (src_x != 0 || src_y != 0) {
11016 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
11021 * Put the final coordinates back so that the src
11022 * coordinate checks will see the right values.
11024 drm_rect_translate_to(&plane_state->uapi.src,
11025 src_x << 16, src_y << 16);
11027 /* ILK+ do this automagically in hardware */
11028 if (HAS_GMCH(dev_priv) && rotation & DRM_MODE_ROTATE_180) {
11029 const struct drm_framebuffer *fb = plane_state->hw.fb;
11030 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
11031 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
11033 offset += (src_h * src_w - 1) * fb->format->cpp[0];
11036 plane_state->color_plane[0].offset = offset;
11037 plane_state->color_plane[0].x = src_x;
11038 plane_state->color_plane[0].y = src_y;
11043 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
11044 struct intel_plane_state *plane_state)
11046 const struct drm_framebuffer *fb = plane_state->hw.fb;
11049 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
11050 DRM_DEBUG_KMS("cursor cannot be tiled\n");
11054 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
11056 DRM_PLANE_HELPER_NO_SCALING,
11057 DRM_PLANE_HELPER_NO_SCALING,
11062 /* Use the unclipped src/dst rectangles, which we program to hw */
11063 plane_state->uapi.src = drm_plane_state_src(&plane_state->uapi);
11064 plane_state->uapi.dst = drm_plane_state_dest(&plane_state->uapi);
11066 ret = intel_cursor_check_surface(plane_state);
11070 if (!plane_state->uapi.visible)
11073 ret = intel_plane_check_src_coordinates(plane_state);
11080 static unsigned int
11081 i845_cursor_max_stride(struct intel_plane *plane,
11082 u32 pixel_format, u64 modifier,
11083 unsigned int rotation)
11088 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11092 if (crtc_state->gamma_enable)
11093 cntl |= CURSOR_GAMMA_ENABLE;
11098 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
11099 const struct intel_plane_state *plane_state)
11101 return CURSOR_ENABLE |
11102 CURSOR_FORMAT_ARGB |
11103 CURSOR_STRIDE(plane_state->color_plane[0].stride);
11106 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
11108 int width = drm_rect_width(&plane_state->uapi.dst);
11111 * 845g/865g are only limited by the width of their cursors,
11112 * the height is arbitrary up to the precision of the register.
11114 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
11117 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
11118 struct intel_plane_state *plane_state)
11120 const struct drm_framebuffer *fb = plane_state->hw.fb;
11123 ret = intel_check_cursor(crtc_state, plane_state);
11127 /* if we want to turn off the cursor ignore width and height */
11131 /* Check for which cursor types we support */
11132 if (!i845_cursor_size_ok(plane_state)) {
11133 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
11134 drm_rect_width(&plane_state->uapi.dst),
11135 drm_rect_height(&plane_state->uapi.dst));
11139 WARN_ON(plane_state->uapi.visible &&
11140 plane_state->color_plane[0].stride != fb->pitches[0]);
11142 switch (fb->pitches[0]) {
11149 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
11154 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
11159 static void i845_update_cursor(struct intel_plane *plane,
11160 const struct intel_crtc_state *crtc_state,
11161 const struct intel_plane_state *plane_state)
11163 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11164 u32 cntl = 0, base = 0, pos = 0, size = 0;
11165 unsigned long irqflags;
11167 if (plane_state && plane_state->uapi.visible) {
11168 unsigned int width = drm_rect_width(&plane_state->uapi.dst);
11169 unsigned int height = drm_rect_height(&plane_state->uapi.dst);
11171 cntl = plane_state->ctl |
11172 i845_cursor_ctl_crtc(crtc_state);
11174 size = (height << 12) | width;
11176 base = intel_cursor_base(plane_state);
11177 pos = intel_cursor_position(plane_state);
11180 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11182 /* On these chipsets we can only modify the base/size/stride
11183 * whilst the cursor is disabled.
11185 if (plane->cursor.base != base ||
11186 plane->cursor.size != size ||
11187 plane->cursor.cntl != cntl) {
11188 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
11189 I915_WRITE_FW(CURBASE(PIPE_A), base);
11190 I915_WRITE_FW(CURSIZE, size);
11191 I915_WRITE_FW(CURPOS(PIPE_A), pos);
11192 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
11194 plane->cursor.base = base;
11195 plane->cursor.size = size;
11196 plane->cursor.cntl = cntl;
11198 I915_WRITE_FW(CURPOS(PIPE_A), pos);
11201 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11204 static void i845_disable_cursor(struct intel_plane *plane,
11205 const struct intel_crtc_state *crtc_state)
11207 i845_update_cursor(plane, crtc_state, NULL);
11210 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
11213 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11214 enum intel_display_power_domain power_domain;
11215 intel_wakeref_t wakeref;
11218 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
11219 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11223 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
11227 intel_display_power_put(dev_priv, power_domain, wakeref);
11232 static unsigned int
11233 i9xx_cursor_max_stride(struct intel_plane *plane,
11234 u32 pixel_format, u64 modifier,
11235 unsigned int rotation)
11237 return plane->base.dev->mode_config.cursor_width * 4;
11240 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11242 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11243 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11246 if (INTEL_GEN(dev_priv) >= 11)
11249 if (crtc_state->gamma_enable)
11250 cntl = MCURSOR_GAMMA_ENABLE;
11252 if (crtc_state->csc_enable)
11253 cntl |= MCURSOR_PIPE_CSC_ENABLE;
11255 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11256 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
11261 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
11262 const struct intel_plane_state *plane_state)
11264 struct drm_i915_private *dev_priv =
11265 to_i915(plane_state->uapi.plane->dev);
11268 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
11269 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
11271 switch (drm_rect_width(&plane_state->uapi.dst)) {
11273 cntl |= MCURSOR_MODE_64_ARGB_AX;
11276 cntl |= MCURSOR_MODE_128_ARGB_AX;
11279 cntl |= MCURSOR_MODE_256_ARGB_AX;
11282 MISSING_CASE(drm_rect_width(&plane_state->uapi.dst));
11286 if (plane_state->hw.rotation & DRM_MODE_ROTATE_180)
11287 cntl |= MCURSOR_ROTATE_180;
11292 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
11294 struct drm_i915_private *dev_priv =
11295 to_i915(plane_state->uapi.plane->dev);
11296 int width = drm_rect_width(&plane_state->uapi.dst);
11297 int height = drm_rect_height(&plane_state->uapi.dst);
11299 if (!intel_cursor_size_ok(plane_state))
11302 /* Cursor width is limited to a few power-of-two sizes */
11313 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
11314 * height from 8 lines up to the cursor width, when the
11315 * cursor is not rotated. Everything else requires square
11318 if (HAS_CUR_FBC(dev_priv) &&
11319 plane_state->hw.rotation & DRM_MODE_ROTATE_0) {
11320 if (height < 8 || height > width)
11323 if (height != width)
11330 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
11331 struct intel_plane_state *plane_state)
11333 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
11334 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11335 const struct drm_framebuffer *fb = plane_state->hw.fb;
11336 enum pipe pipe = plane->pipe;
11339 ret = intel_check_cursor(crtc_state, plane_state);
11343 /* if we want to turn off the cursor ignore width and height */
11347 /* Check for which cursor types we support */
11348 if (!i9xx_cursor_size_ok(plane_state)) {
11349 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
11350 drm_rect_width(&plane_state->uapi.dst),
11351 drm_rect_height(&plane_state->uapi.dst));
11355 WARN_ON(plane_state->uapi.visible &&
11356 plane_state->color_plane[0].stride != fb->pitches[0]);
11358 if (fb->pitches[0] !=
11359 drm_rect_width(&plane_state->uapi.dst) * fb->format->cpp[0]) {
11360 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
11362 drm_rect_width(&plane_state->uapi.dst));
11367 * There's something wrong with the cursor on CHV pipe C.
11368 * If it straddles the left edge of the screen then
11369 * moving it away from the edge or disabling it often
11370 * results in a pipe underrun, and often that can lead to
11371 * dead pipe (constant underrun reported, and it scans
11372 * out just a solid color). To recover from that, the
11373 * display power well must be turned off and on again.
11374 * Refuse the put the cursor into that compromised position.
11376 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
11377 plane_state->uapi.visible && plane_state->uapi.dst.x1 < 0) {
11378 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
11382 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
11387 static void i9xx_update_cursor(struct intel_plane *plane,
11388 const struct intel_crtc_state *crtc_state,
11389 const struct intel_plane_state *plane_state)
11391 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11392 enum pipe pipe = plane->pipe;
11393 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
11394 unsigned long irqflags;
11396 if (plane_state && plane_state->uapi.visible) {
11397 unsigned width = drm_rect_width(&plane_state->uapi.dst);
11398 unsigned height = drm_rect_height(&plane_state->uapi.dst);
11400 cntl = plane_state->ctl |
11401 i9xx_cursor_ctl_crtc(crtc_state);
11403 if (width != height)
11404 fbc_ctl = CUR_FBC_CTL_EN | (height - 1);
11406 base = intel_cursor_base(plane_state);
11407 pos = intel_cursor_position(plane_state);
11410 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11413 * On some platforms writing CURCNTR first will also
11414 * cause CURPOS to be armed by the CURBASE write.
11415 * Without the CURCNTR write the CURPOS write would
11416 * arm itself. Thus we always update CURCNTR before
11419 * On other platforms CURPOS always requires the
11420 * CURBASE write to arm the update. Additonally
11421 * a write to any of the cursor register will cancel
11422 * an already armed cursor update. Thus leaving out
11423 * the CURBASE write after CURPOS could lead to a
11424 * cursor that doesn't appear to move, or even change
11425 * shape. Thus we always write CURBASE.
11427 * The other registers are armed by by the CURBASE write
11428 * except when the plane is getting enabled at which time
11429 * the CURCNTR write arms the update.
11432 if (INTEL_GEN(dev_priv) >= 9)
11433 skl_write_cursor_wm(plane, crtc_state);
11435 if (plane->cursor.base != base ||
11436 plane->cursor.size != fbc_ctl ||
11437 plane->cursor.cntl != cntl) {
11438 if (HAS_CUR_FBC(dev_priv))
11439 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
11440 I915_WRITE_FW(CURCNTR(pipe), cntl);
11441 I915_WRITE_FW(CURPOS(pipe), pos);
11442 I915_WRITE_FW(CURBASE(pipe), base);
11444 plane->cursor.base = base;
11445 plane->cursor.size = fbc_ctl;
11446 plane->cursor.cntl = cntl;
11448 I915_WRITE_FW(CURPOS(pipe), pos);
11449 I915_WRITE_FW(CURBASE(pipe), base);
11452 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11455 static void i9xx_disable_cursor(struct intel_plane *plane,
11456 const struct intel_crtc_state *crtc_state)
11458 i9xx_update_cursor(plane, crtc_state, NULL);
11461 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
11464 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11465 enum intel_display_power_domain power_domain;
11466 intel_wakeref_t wakeref;
11471 * Not 100% correct for planes that can move between pipes,
11472 * but that's only the case for gen2-3 which don't have any
11473 * display power wells.
11475 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
11476 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11480 val = I915_READ(CURCNTR(plane->pipe));
11482 ret = val & MCURSOR_MODE;
11484 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
11485 *pipe = plane->pipe;
11487 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
11488 MCURSOR_PIPE_SELECT_SHIFT;
11490 intel_display_power_put(dev_priv, power_domain, wakeref);
11495 /* VESA 640x480x72Hz mode to set on the pipe */
11496 static const struct drm_display_mode load_detect_mode = {
11497 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
11498 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
11501 struct drm_framebuffer *
11502 intel_framebuffer_create(struct drm_i915_gem_object *obj,
11503 struct drm_mode_fb_cmd2 *mode_cmd)
11505 struct intel_framebuffer *intel_fb;
11508 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
11510 return ERR_PTR(-ENOMEM);
11512 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
11516 return &intel_fb->base;
11520 return ERR_PTR(ret);
11523 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
11524 struct drm_crtc *crtc)
11526 struct drm_plane *plane;
11527 struct drm_plane_state *plane_state;
11530 ret = drm_atomic_add_affected_planes(state, crtc);
11534 for_each_new_plane_in_state(state, plane, plane_state, i) {
11535 if (plane_state->crtc != crtc)
11538 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
11542 drm_atomic_set_fb_for_plane(plane_state, NULL);
11548 int intel_get_load_detect_pipe(struct drm_connector *connector,
11549 struct intel_load_detect_pipe *old,
11550 struct drm_modeset_acquire_ctx *ctx)
11552 struct intel_crtc *intel_crtc;
11553 struct intel_encoder *intel_encoder =
11554 intel_attached_encoder(connector);
11555 struct drm_crtc *possible_crtc;
11556 struct drm_encoder *encoder = &intel_encoder->base;
11557 struct drm_crtc *crtc = NULL;
11558 struct drm_device *dev = encoder->dev;
11559 struct drm_i915_private *dev_priv = to_i915(dev);
11560 struct drm_mode_config *config = &dev->mode_config;
11561 struct drm_atomic_state *state = NULL, *restore_state = NULL;
11562 struct drm_connector_state *connector_state;
11563 struct intel_crtc_state *crtc_state;
11566 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11567 connector->base.id, connector->name,
11568 encoder->base.id, encoder->name);
11570 old->restore_state = NULL;
11572 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
11575 * Algorithm gets a little messy:
11577 * - if the connector already has an assigned crtc, use it (but make
11578 * sure it's on first)
11580 * - try to find the first unused crtc that can drive this connector,
11581 * and use that if we find one
11584 /* See if we already have a CRTC for this connector */
11585 if (connector->state->crtc) {
11586 crtc = connector->state->crtc;
11588 ret = drm_modeset_lock(&crtc->mutex, ctx);
11592 /* Make sure the crtc and connector are running */
11596 /* Find an unused one (if possible) */
11597 for_each_crtc(dev, possible_crtc) {
11599 if (!(encoder->possible_crtcs & (1 << i)))
11602 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
11606 if (possible_crtc->state->enable) {
11607 drm_modeset_unlock(&possible_crtc->mutex);
11611 crtc = possible_crtc;
11616 * If we didn't find an unused CRTC, don't use any.
11619 DRM_DEBUG_KMS("no pipe available for load-detect\n");
11625 intel_crtc = to_intel_crtc(crtc);
11627 state = drm_atomic_state_alloc(dev);
11628 restore_state = drm_atomic_state_alloc(dev);
11629 if (!state || !restore_state) {
11634 state->acquire_ctx = ctx;
11635 restore_state->acquire_ctx = ctx;
11637 connector_state = drm_atomic_get_connector_state(state, connector);
11638 if (IS_ERR(connector_state)) {
11639 ret = PTR_ERR(connector_state);
11643 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
11647 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
11648 if (IS_ERR(crtc_state)) {
11649 ret = PTR_ERR(crtc_state);
11653 crtc_state->uapi.active = true;
11655 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
11656 &load_detect_mode);
11660 ret = intel_modeset_disable_planes(state, crtc);
11664 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
11666 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
11668 ret = drm_atomic_add_affected_planes(restore_state, crtc);
11670 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
11674 ret = drm_atomic_commit(state);
11676 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
11680 old->restore_state = restore_state;
11681 drm_atomic_state_put(state);
11683 /* let the connector get through one full cycle before testing */
11684 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
11689 drm_atomic_state_put(state);
11692 if (restore_state) {
11693 drm_atomic_state_put(restore_state);
11694 restore_state = NULL;
11697 if (ret == -EDEADLK)
11703 void intel_release_load_detect_pipe(struct drm_connector *connector,
11704 struct intel_load_detect_pipe *old,
11705 struct drm_modeset_acquire_ctx *ctx)
11707 struct intel_encoder *intel_encoder =
11708 intel_attached_encoder(connector);
11709 struct drm_encoder *encoder = &intel_encoder->base;
11710 struct drm_atomic_state *state = old->restore_state;
11713 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11714 connector->base.id, connector->name,
11715 encoder->base.id, encoder->name);
11720 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
11722 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
11723 drm_atomic_state_put(state);
11726 static int i9xx_pll_refclk(struct drm_device *dev,
11727 const struct intel_crtc_state *pipe_config)
11729 struct drm_i915_private *dev_priv = to_i915(dev);
11730 u32 dpll = pipe_config->dpll_hw_state.dpll;
11732 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
11733 return dev_priv->vbt.lvds_ssc_freq;
11734 else if (HAS_PCH_SPLIT(dev_priv))
11736 else if (!IS_GEN(dev_priv, 2))
11742 /* Returns the clock of the currently programmed mode of the given pipe. */
11743 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
11744 struct intel_crtc_state *pipe_config)
11746 struct drm_device *dev = crtc->base.dev;
11747 struct drm_i915_private *dev_priv = to_i915(dev);
11748 enum pipe pipe = crtc->pipe;
11749 u32 dpll = pipe_config->dpll_hw_state.dpll;
11753 int refclk = i9xx_pll_refclk(dev, pipe_config);
11755 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
11756 fp = pipe_config->dpll_hw_state.fp0;
11758 fp = pipe_config->dpll_hw_state.fp1;
11760 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
11761 if (IS_PINEVIEW(dev_priv)) {
11762 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
11763 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
11765 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
11766 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
11769 if (!IS_GEN(dev_priv, 2)) {
11770 if (IS_PINEVIEW(dev_priv))
11771 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
11772 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
11774 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
11775 DPLL_FPA01_P1_POST_DIV_SHIFT);
11777 switch (dpll & DPLL_MODE_MASK) {
11778 case DPLLB_MODE_DAC_SERIAL:
11779 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
11782 case DPLLB_MODE_LVDS:
11783 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
11787 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
11788 "mode\n", (int)(dpll & DPLL_MODE_MASK));
11792 if (IS_PINEVIEW(dev_priv))
11793 port_clock = pnv_calc_dpll_params(refclk, &clock);
11795 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11797 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
11798 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
11801 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
11802 DPLL_FPA01_P1_POST_DIV_SHIFT);
11804 if (lvds & LVDS_CLKB_POWER_UP)
11809 if (dpll & PLL_P1_DIVIDE_BY_TWO)
11812 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
11813 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
11815 if (dpll & PLL_P2_DIVIDE_BY_4)
11821 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11825 * This value includes pixel_multiplier. We will use
11826 * port_clock to compute adjusted_mode.crtc_clock in the
11827 * encoder's get_config() function.
11829 pipe_config->port_clock = port_clock;
11832 int intel_dotclock_calculate(int link_freq,
11833 const struct intel_link_m_n *m_n)
11836 * The calculation for the data clock is:
11837 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
11838 * But we want to avoid losing precison if possible, so:
11839 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
11841 * and the link clock is simpler:
11842 * link_clock = (m * link_clock) / n
11848 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
11851 static void ilk_pch_clock_get(struct intel_crtc *crtc,
11852 struct intel_crtc_state *pipe_config)
11854 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11856 /* read out port_clock from the DPLL */
11857 i9xx_crtc_clock_get(crtc, pipe_config);
11860 * In case there is an active pipe without active ports,
11861 * we may need some idea for the dotclock anyway.
11862 * Calculate one based on the FDI configuration.
11864 pipe_config->hw.adjusted_mode.crtc_clock =
11865 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11866 &pipe_config->fdi_m_n);
11869 static void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
11870 struct intel_crtc *crtc)
11872 memset(crtc_state, 0, sizeof(*crtc_state));
11874 __drm_atomic_helper_crtc_state_reset(&crtc_state->uapi, &crtc->base);
11876 crtc_state->cpu_transcoder = INVALID_TRANSCODER;
11877 crtc_state->master_transcoder = INVALID_TRANSCODER;
11878 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
11879 crtc_state->output_format = INTEL_OUTPUT_FORMAT_INVALID;
11880 crtc_state->scaler_state.scaler_id = -1;
11881 crtc_state->mst_master_transcoder = INVALID_TRANSCODER;
11884 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc)
11886 struct intel_crtc_state *crtc_state;
11888 crtc_state = kmalloc(sizeof(*crtc_state), GFP_KERNEL);
11891 intel_crtc_state_reset(crtc_state, crtc);
11896 /* Returns the currently programmed mode of the given encoder. */
11897 struct drm_display_mode *
11898 intel_encoder_current_mode(struct intel_encoder *encoder)
11900 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
11901 struct intel_crtc_state *crtc_state;
11902 struct drm_display_mode *mode;
11903 struct intel_crtc *crtc;
11906 if (!encoder->get_hw_state(encoder, &pipe))
11909 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11911 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
11915 crtc_state = intel_crtc_state_alloc(crtc);
11921 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
11927 encoder->get_config(encoder, crtc_state);
11929 intel_mode_from_pipe_config(mode, crtc_state);
11936 static void intel_crtc_destroy(struct drm_crtc *crtc)
11938 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11940 drm_crtc_cleanup(crtc);
11945 * intel_wm_need_update - Check whether watermarks need updating
11946 * @cur: current plane state
11947 * @new: new plane state
11949 * Check current plane state versus the new one to determine whether
11950 * watermarks need to be recalculated.
11952 * Returns true or false.
11954 static bool intel_wm_need_update(const struct intel_plane_state *cur,
11955 struct intel_plane_state *new)
11957 /* Update watermarks on tiling or size changes. */
11958 if (new->uapi.visible != cur->uapi.visible)
11961 if (!cur->hw.fb || !new->hw.fb)
11964 if (cur->hw.fb->modifier != new->hw.fb->modifier ||
11965 cur->hw.rotation != new->hw.rotation ||
11966 drm_rect_width(&new->uapi.src) != drm_rect_width(&cur->uapi.src) ||
11967 drm_rect_height(&new->uapi.src) != drm_rect_height(&cur->uapi.src) ||
11968 drm_rect_width(&new->uapi.dst) != drm_rect_width(&cur->uapi.dst) ||
11969 drm_rect_height(&new->uapi.dst) != drm_rect_height(&cur->uapi.dst))
11975 static bool needs_scaling(const struct intel_plane_state *state)
11977 int src_w = drm_rect_width(&state->uapi.src) >> 16;
11978 int src_h = drm_rect_height(&state->uapi.src) >> 16;
11979 int dst_w = drm_rect_width(&state->uapi.dst);
11980 int dst_h = drm_rect_height(&state->uapi.dst);
11982 return (src_w != dst_w || src_h != dst_h);
11985 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
11986 struct intel_crtc_state *crtc_state,
11987 const struct intel_plane_state *old_plane_state,
11988 struct intel_plane_state *plane_state)
11990 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11991 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
11992 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11993 bool mode_changed = needs_modeset(crtc_state);
11994 bool was_crtc_enabled = old_crtc_state->hw.active;
11995 bool is_crtc_enabled = crtc_state->hw.active;
11996 bool turn_off, turn_on, visible, was_visible;
11999 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
12000 ret = skl_update_scaler_plane(crtc_state, plane_state);
12005 was_visible = old_plane_state->uapi.visible;
12006 visible = plane_state->uapi.visible;
12008 if (!was_crtc_enabled && WARN_ON(was_visible))
12009 was_visible = false;
12012 * Visibility is calculated as if the crtc was on, but
12013 * after scaler setup everything depends on it being off
12014 * when the crtc isn't active.
12016 * FIXME this is wrong for watermarks. Watermarks should also
12017 * be computed as if the pipe would be active. Perhaps move
12018 * per-plane wm computation to the .check_plane() hook, and
12019 * only combine the results from all planes in the current place?
12021 if (!is_crtc_enabled) {
12022 plane_state->uapi.visible = visible = false;
12023 crtc_state->active_planes &= ~BIT(plane->id);
12024 crtc_state->data_rate[plane->id] = 0;
12025 crtc_state->min_cdclk[plane->id] = 0;
12028 if (!was_visible && !visible)
12031 turn_off = was_visible && (!visible || mode_changed);
12032 turn_on = visible && (!was_visible || mode_changed);
12034 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
12035 crtc->base.base.id, crtc->base.name,
12036 plane->base.base.id, plane->base.name,
12037 was_visible, visible,
12038 turn_off, turn_on, mode_changed);
12041 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
12042 crtc_state->update_wm_pre = true;
12044 /* must disable cxsr around plane enable/disable */
12045 if (plane->id != PLANE_CURSOR)
12046 crtc_state->disable_cxsr = true;
12047 } else if (turn_off) {
12048 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
12049 crtc_state->update_wm_post = true;
12051 /* must disable cxsr around plane enable/disable */
12052 if (plane->id != PLANE_CURSOR)
12053 crtc_state->disable_cxsr = true;
12054 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
12055 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
12056 /* FIXME bollocks */
12057 crtc_state->update_wm_pre = true;
12058 crtc_state->update_wm_post = true;
12062 if (visible || was_visible)
12063 crtc_state->fb_bits |= plane->frontbuffer_bit;
12066 * ILK/SNB DVSACNTR/Sprite Enable
12067 * IVB SPR_CTL/Sprite Enable
12068 * "When in Self Refresh Big FIFO mode, a write to enable the
12069 * plane will be internally buffered and delayed while Big FIFO
12070 * mode is exiting."
12072 * Which means that enabling the sprite can take an extra frame
12073 * when we start in big FIFO mode (LP1+). Thus we need to drop
12074 * down to LP0 and wait for vblank in order to make sure the
12075 * sprite gets enabled on the next vblank after the register write.
12076 * Doing otherwise would risk enabling the sprite one frame after
12077 * we've already signalled flip completion. We can resume LP1+
12078 * once the sprite has been enabled.
12081 * WaCxSRDisabledForSpriteScaling:ivb
12082 * IVB SPR_SCALE/Scaling Enable
12083 * "Low Power watermarks must be disabled for at least one
12084 * frame before enabling sprite scaling, and kept disabled
12085 * until sprite scaling is disabled."
12087 * ILK/SNB DVSASCALE/Scaling Enable
12088 * "When in Self Refresh Big FIFO mode, scaling enable will be
12089 * masked off while Big FIFO mode is exiting."
12091 * Despite the w/a only being listed for IVB we assume that
12092 * the ILK/SNB note has similar ramifications, hence we apply
12093 * the w/a on all three platforms.
12095 * With experimental results seems this is needed also for primary
12096 * plane, not only sprite plane.
12098 if (plane->id != PLANE_CURSOR &&
12099 (IS_GEN_RANGE(dev_priv, 5, 6) ||
12100 IS_IVYBRIDGE(dev_priv)) &&
12101 (turn_on || (!needs_scaling(old_plane_state) &&
12102 needs_scaling(plane_state))))
12103 crtc_state->disable_lp_wm = true;
12108 static bool encoders_cloneable(const struct intel_encoder *a,
12109 const struct intel_encoder *b)
12111 /* masks could be asymmetric, so check both ways */
12112 return a == b || (a->cloneable & (1 << b->type) &&
12113 b->cloneable & (1 << a->type));
12116 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
12117 struct intel_crtc *crtc,
12118 struct intel_encoder *encoder)
12120 struct intel_encoder *source_encoder;
12121 struct drm_connector *connector;
12122 struct drm_connector_state *connector_state;
12125 for_each_new_connector_in_state(state, connector, connector_state, i) {
12126 if (connector_state->crtc != &crtc->base)
12130 to_intel_encoder(connector_state->best_encoder);
12131 if (!encoders_cloneable(encoder, source_encoder))
12138 static int icl_add_linked_planes(struct intel_atomic_state *state)
12140 struct intel_plane *plane, *linked;
12141 struct intel_plane_state *plane_state, *linked_plane_state;
12144 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12145 linked = plane_state->planar_linked_plane;
12150 linked_plane_state = intel_atomic_get_plane_state(state, linked);
12151 if (IS_ERR(linked_plane_state))
12152 return PTR_ERR(linked_plane_state);
12154 WARN_ON(linked_plane_state->planar_linked_plane != plane);
12155 WARN_ON(linked_plane_state->planar_slave == plane_state->planar_slave);
12161 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
12163 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12164 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12165 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
12166 struct intel_plane *plane, *linked;
12167 struct intel_plane_state *plane_state;
12170 if (INTEL_GEN(dev_priv) < 11)
12174 * Destroy all old plane links and make the slave plane invisible
12175 * in the crtc_state->active_planes mask.
12177 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12178 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
12181 plane_state->planar_linked_plane = NULL;
12182 if (plane_state->planar_slave && !plane_state->uapi.visible) {
12183 crtc_state->active_planes &= ~BIT(plane->id);
12184 crtc_state->update_planes |= BIT(plane->id);
12187 plane_state->planar_slave = false;
12190 if (!crtc_state->nv12_planes)
12193 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12194 struct intel_plane_state *linked_state = NULL;
12196 if (plane->pipe != crtc->pipe ||
12197 !(crtc_state->nv12_planes & BIT(plane->id)))
12200 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
12201 if (!icl_is_nv12_y_plane(linked->id))
12204 if (crtc_state->active_planes & BIT(linked->id))
12207 linked_state = intel_atomic_get_plane_state(state, linked);
12208 if (IS_ERR(linked_state))
12209 return PTR_ERR(linked_state);
12214 if (!linked_state) {
12215 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
12216 hweight8(crtc_state->nv12_planes));
12221 plane_state->planar_linked_plane = linked;
12223 linked_state->planar_slave = true;
12224 linked_state->planar_linked_plane = plane;
12225 crtc_state->active_planes |= BIT(linked->id);
12226 crtc_state->update_planes |= BIT(linked->id);
12227 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
12229 /* Copy parameters to slave plane */
12230 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
12231 linked_state->color_ctl = plane_state->color_ctl;
12232 memcpy(linked_state->color_plane, plane_state->color_plane,
12233 sizeof(linked_state->color_plane));
12235 intel_plane_copy_uapi_to_hw_state(linked_state, plane_state);
12236 linked_state->uapi.src = plane_state->uapi.src;
12237 linked_state->uapi.dst = plane_state->uapi.dst;
12239 if (icl_is_hdr_plane(dev_priv, plane->id)) {
12240 if (linked->id == PLANE_SPRITE5)
12241 plane_state->cus_ctl |= PLANE_CUS_PLANE_7;
12242 else if (linked->id == PLANE_SPRITE4)
12243 plane_state->cus_ctl |= PLANE_CUS_PLANE_6;
12245 MISSING_CASE(linked->id);
12252 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
12254 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
12255 struct intel_atomic_state *state =
12256 to_intel_atomic_state(new_crtc_state->uapi.state);
12257 const struct intel_crtc_state *old_crtc_state =
12258 intel_atomic_get_old_crtc_state(state, crtc);
12260 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
12263 static int icl_add_sync_mode_crtcs(struct intel_crtc_state *crtc_state)
12265 struct drm_crtc *crtc = crtc_state->uapi.crtc;
12266 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
12267 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
12268 struct drm_connector *master_connector, *connector;
12269 struct drm_connector_state *connector_state;
12270 struct drm_connector_list_iter conn_iter;
12271 struct drm_crtc *master_crtc = NULL;
12272 struct drm_crtc_state *master_crtc_state;
12273 struct intel_crtc_state *master_pipe_config;
12274 int i, tile_group_id;
12276 if (INTEL_GEN(dev_priv) < 11)
12280 * In case of tiled displays there could be one or more slaves but there is
12281 * only one master. Lets make the CRTC used by the connector corresponding
12282 * to the last horizonal and last vertical tile a master/genlock CRTC.
12283 * All the other CRTCs corresponding to other tiles of the same Tile group
12284 * are the slave CRTCs and hold a pointer to their genlock CRTC.
12286 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
12287 if (connector_state->crtc != crtc)
12289 if (!connector->has_tile)
12291 if (crtc_state->hw.mode.hdisplay != connector->tile_h_size ||
12292 crtc_state->hw.mode.vdisplay != connector->tile_v_size)
12294 if (connector->tile_h_loc == connector->num_h_tile - 1 &&
12295 connector->tile_v_loc == connector->num_v_tile - 1)
12297 crtc_state->sync_mode_slaves_mask = 0;
12298 tile_group_id = connector->tile_group->id;
12299 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
12300 drm_for_each_connector_iter(master_connector, &conn_iter) {
12301 struct drm_connector_state *master_conn_state = NULL;
12303 if (!master_connector->has_tile)
12305 if (master_connector->tile_h_loc != master_connector->num_h_tile - 1 ||
12306 master_connector->tile_v_loc != master_connector->num_v_tile - 1)
12308 if (master_connector->tile_group->id != tile_group_id)
12311 master_conn_state = drm_atomic_get_connector_state(&state->base,
12313 if (IS_ERR(master_conn_state)) {
12314 drm_connector_list_iter_end(&conn_iter);
12315 return PTR_ERR(master_conn_state);
12317 if (master_conn_state->crtc) {
12318 master_crtc = master_conn_state->crtc;
12322 drm_connector_list_iter_end(&conn_iter);
12324 if (!master_crtc) {
12325 DRM_DEBUG_KMS("Could not find Master CRTC for Slave CRTC %d\n",
12326 connector_state->crtc->base.id);
12330 master_crtc_state = drm_atomic_get_crtc_state(&state->base,
12332 if (IS_ERR(master_crtc_state))
12333 return PTR_ERR(master_crtc_state);
12335 master_pipe_config = to_intel_crtc_state(master_crtc_state);
12336 crtc_state->master_transcoder = master_pipe_config->cpu_transcoder;
12337 master_pipe_config->sync_mode_slaves_mask |=
12338 BIT(crtc_state->cpu_transcoder);
12339 DRM_DEBUG_KMS("Master Transcoder = %s added for Slave CRTC = %d, slave transcoder bitmask = %d\n",
12340 transcoder_name(crtc_state->master_transcoder),
12341 crtc_state->uapi.crtc->base.id,
12342 master_pipe_config->sync_mode_slaves_mask);
12348 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
12349 struct intel_crtc *crtc)
12351 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12352 struct intel_crtc_state *crtc_state =
12353 intel_atomic_get_new_crtc_state(state, crtc);
12354 bool mode_changed = needs_modeset(crtc_state);
12357 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
12358 mode_changed && !crtc_state->hw.active)
12359 crtc_state->update_wm_post = true;
12361 if (mode_changed && crtc_state->hw.enable &&
12362 dev_priv->display.crtc_compute_clock &&
12363 !WARN_ON(crtc_state->shared_dpll)) {
12364 ret = dev_priv->display.crtc_compute_clock(crtc, crtc_state);
12370 * May need to update pipe gamma enable bits
12371 * when C8 planes are getting enabled/disabled.
12373 if (c8_planes_changed(crtc_state))
12374 crtc_state->uapi.color_mgmt_changed = true;
12376 if (mode_changed || crtc_state->update_pipe ||
12377 crtc_state->uapi.color_mgmt_changed) {
12378 ret = intel_color_check(crtc_state);
12384 if (dev_priv->display.compute_pipe_wm) {
12385 ret = dev_priv->display.compute_pipe_wm(crtc_state);
12387 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
12392 if (dev_priv->display.compute_intermediate_wm) {
12393 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
12397 * Calculate 'intermediate' watermarks that satisfy both the
12398 * old state and the new state. We can program these
12401 ret = dev_priv->display.compute_intermediate_wm(crtc_state);
12403 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
12408 if (INTEL_GEN(dev_priv) >= 9) {
12409 if (mode_changed || crtc_state->update_pipe)
12410 ret = skl_update_scaler_crtc(crtc_state);
12412 ret = intel_atomic_setup_scalers(dev_priv, crtc,
12416 if (HAS_IPS(dev_priv))
12417 crtc_state->ips_enabled = hsw_compute_ips_config(crtc_state);
12422 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
12424 struct intel_connector *connector;
12425 struct drm_connector_list_iter conn_iter;
12427 drm_connector_list_iter_begin(dev, &conn_iter);
12428 for_each_intel_connector_iter(connector, &conn_iter) {
12429 if (connector->base.state->crtc)
12430 drm_connector_put(&connector->base);
12432 if (connector->base.encoder) {
12433 connector->base.state->best_encoder =
12434 connector->base.encoder;
12435 connector->base.state->crtc =
12436 connector->base.encoder->crtc;
12438 drm_connector_get(&connector->base);
12440 connector->base.state->best_encoder = NULL;
12441 connector->base.state->crtc = NULL;
12444 drm_connector_list_iter_end(&conn_iter);
12448 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
12449 struct intel_crtc_state *pipe_config)
12451 struct drm_connector *connector = conn_state->connector;
12452 const struct drm_display_info *info = &connector->display_info;
12455 switch (conn_state->max_bpc) {
12472 if (bpp < pipe_config->pipe_bpp) {
12473 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
12474 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
12475 connector->base.id, connector->name,
12476 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
12477 pipe_config->pipe_bpp);
12479 pipe_config->pipe_bpp = bpp;
12486 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
12487 struct intel_crtc_state *pipe_config)
12489 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12490 struct drm_atomic_state *state = pipe_config->uapi.state;
12491 struct drm_connector *connector;
12492 struct drm_connector_state *connector_state;
12495 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
12496 IS_CHERRYVIEW(dev_priv)))
12498 else if (INTEL_GEN(dev_priv) >= 5)
12503 pipe_config->pipe_bpp = bpp;
12505 /* Clamp display bpp to connector max bpp */
12506 for_each_new_connector_in_state(state, connector, connector_state, i) {
12509 if (connector_state->crtc != &crtc->base)
12512 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
12520 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
12522 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
12523 "type: 0x%x flags: 0x%x\n",
12525 mode->crtc_hdisplay, mode->crtc_hsync_start,
12526 mode->crtc_hsync_end, mode->crtc_htotal,
12527 mode->crtc_vdisplay, mode->crtc_vsync_start,
12528 mode->crtc_vsync_end, mode->crtc_vtotal,
12529 mode->type, mode->flags);
12533 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
12534 const char *id, unsigned int lane_count,
12535 const struct intel_link_m_n *m_n)
12537 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12539 m_n->gmch_m, m_n->gmch_n,
12540 m_n->link_m, m_n->link_n, m_n->tu);
12544 intel_dump_infoframe(struct drm_i915_private *dev_priv,
12545 const union hdmi_infoframe *frame)
12547 if ((drm_debug & DRM_UT_KMS) == 0)
12550 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
12553 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
12555 static const char * const output_type_str[] = {
12556 OUTPUT_TYPE(UNUSED),
12557 OUTPUT_TYPE(ANALOG),
12561 OUTPUT_TYPE(TVOUT),
12567 OUTPUT_TYPE(DP_MST),
12572 static void snprintf_output_types(char *buf, size_t len,
12573 unsigned int output_types)
12580 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
12583 if ((output_types & BIT(i)) == 0)
12586 r = snprintf(str, len, "%s%s",
12587 str != buf ? "," : "", output_type_str[i]);
12593 output_types &= ~BIT(i);
12596 WARN_ON_ONCE(output_types != 0);
12599 static const char * const output_format_str[] = {
12600 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
12601 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
12602 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
12603 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
12606 static const char *output_formats(enum intel_output_format format)
12608 if (format >= ARRAY_SIZE(output_format_str))
12609 format = INTEL_OUTPUT_FORMAT_INVALID;
12610 return output_format_str[format];
12613 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
12615 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
12616 const struct drm_framebuffer *fb = plane_state->hw.fb;
12617 struct drm_format_name_buf format_name;
12620 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12621 plane->base.base.id, plane->base.name,
12622 yesno(plane_state->uapi.visible));
12626 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s, visible: %s\n",
12627 plane->base.base.id, plane->base.name,
12628 fb->base.id, fb->width, fb->height,
12629 drm_get_format_name(fb->format->format, &format_name),
12630 yesno(plane_state->uapi.visible));
12631 DRM_DEBUG_KMS("\trotation: 0x%x, scaler: %d\n",
12632 plane_state->hw.rotation, plane_state->scaler_id);
12633 if (plane_state->uapi.visible)
12634 DRM_DEBUG_KMS("\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
12635 DRM_RECT_FP_ARG(&plane_state->uapi.src),
12636 DRM_RECT_ARG(&plane_state->uapi.dst));
12639 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
12640 struct intel_atomic_state *state,
12641 const char *context)
12643 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
12644 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12645 const struct intel_plane_state *plane_state;
12646 struct intel_plane *plane;
12650 DRM_DEBUG_KMS("[CRTC:%d:%s] enable: %s %s\n",
12651 crtc->base.base.id, crtc->base.name,
12652 yesno(pipe_config->hw.enable), context);
12654 if (!pipe_config->hw.enable)
12657 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
12658 DRM_DEBUG_KMS("active: %s, output_types: %s (0x%x), output format: %s\n",
12659 yesno(pipe_config->hw.active),
12660 buf, pipe_config->output_types,
12661 output_formats(pipe_config->output_format));
12663 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
12664 transcoder_name(pipe_config->cpu_transcoder),
12665 pipe_config->pipe_bpp, pipe_config->dither);
12667 if (pipe_config->has_pch_encoder)
12668 intel_dump_m_n_config(pipe_config, "fdi",
12669 pipe_config->fdi_lanes,
12670 &pipe_config->fdi_m_n);
12672 if (intel_crtc_has_dp_encoder(pipe_config)) {
12673 intel_dump_m_n_config(pipe_config, "dp m_n",
12674 pipe_config->lane_count, &pipe_config->dp_m_n);
12675 if (pipe_config->has_drrs)
12676 intel_dump_m_n_config(pipe_config, "dp m2_n2",
12677 pipe_config->lane_count,
12678 &pipe_config->dp_m2_n2);
12681 DRM_DEBUG_KMS("audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
12682 pipe_config->has_audio, pipe_config->has_infoframe,
12683 pipe_config->infoframes.enable);
12685 if (pipe_config->infoframes.enable &
12686 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
12687 DRM_DEBUG_KMS("GCP: 0x%x\n", pipe_config->infoframes.gcp);
12688 if (pipe_config->infoframes.enable &
12689 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
12690 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
12691 if (pipe_config->infoframes.enable &
12692 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
12693 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
12694 if (pipe_config->infoframes.enable &
12695 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
12696 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
12698 DRM_DEBUG_KMS("requested mode:\n");
12699 drm_mode_debug_printmodeline(&pipe_config->hw.mode);
12700 DRM_DEBUG_KMS("adjusted mode:\n");
12701 drm_mode_debug_printmodeline(&pipe_config->hw.adjusted_mode);
12702 intel_dump_crtc_timings(&pipe_config->hw.adjusted_mode);
12703 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
12704 pipe_config->port_clock,
12705 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
12706 pipe_config->pixel_rate);
12708 if (INTEL_GEN(dev_priv) >= 9)
12709 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12711 pipe_config->scaler_state.scaler_users,
12712 pipe_config->scaler_state.scaler_id);
12714 if (HAS_GMCH(dev_priv))
12715 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12716 pipe_config->gmch_pfit.control,
12717 pipe_config->gmch_pfit.pgm_ratios,
12718 pipe_config->gmch_pfit.lvds_border_bits);
12720 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s, force thru: %s\n",
12721 pipe_config->pch_pfit.pos,
12722 pipe_config->pch_pfit.size,
12723 enableddisabled(pipe_config->pch_pfit.enabled),
12724 yesno(pipe_config->pch_pfit.force_thru));
12726 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
12727 pipe_config->ips_enabled, pipe_config->double_wide);
12729 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
12731 if (IS_CHERRYVIEW(dev_priv))
12732 DRM_DEBUG_KMS("cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12733 pipe_config->cgm_mode, pipe_config->gamma_mode,
12734 pipe_config->gamma_enable, pipe_config->csc_enable);
12736 DRM_DEBUG_KMS("csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12737 pipe_config->csc_mode, pipe_config->gamma_mode,
12738 pipe_config->gamma_enable, pipe_config->csc_enable);
12740 DRM_DEBUG_KMS("MST master transcoder: %s\n",
12741 transcoder_name(pipe_config->mst_master_transcoder));
12747 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12748 if (plane->pipe == crtc->pipe)
12749 intel_dump_plane_state(plane_state);
12753 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
12755 struct drm_device *dev = state->base.dev;
12756 struct drm_connector *connector;
12757 struct drm_connector_list_iter conn_iter;
12758 unsigned int used_ports = 0;
12759 unsigned int used_mst_ports = 0;
12763 * We're going to peek into connector->state,
12764 * hence connection_mutex must be held.
12766 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
12769 * Walk the connector list instead of the encoder
12770 * list to detect the problem on ddi platforms
12771 * where there's just one encoder per digital port.
12773 drm_connector_list_iter_begin(dev, &conn_iter);
12774 drm_for_each_connector_iter(connector, &conn_iter) {
12775 struct drm_connector_state *connector_state;
12776 struct intel_encoder *encoder;
12779 drm_atomic_get_new_connector_state(&state->base,
12781 if (!connector_state)
12782 connector_state = connector->state;
12784 if (!connector_state->best_encoder)
12787 encoder = to_intel_encoder(connector_state->best_encoder);
12789 WARN_ON(!connector_state->crtc);
12791 switch (encoder->type) {
12792 unsigned int port_mask;
12793 case INTEL_OUTPUT_DDI:
12794 if (WARN_ON(!HAS_DDI(to_i915(dev))))
12796 /* else, fall through */
12797 case INTEL_OUTPUT_DP:
12798 case INTEL_OUTPUT_HDMI:
12799 case INTEL_OUTPUT_EDP:
12800 port_mask = 1 << encoder->port;
12802 /* the same port mustn't appear more than once */
12803 if (used_ports & port_mask)
12806 used_ports |= port_mask;
12808 case INTEL_OUTPUT_DP_MST:
12810 1 << encoder->port;
12816 drm_connector_list_iter_end(&conn_iter);
12818 /* can't mix MST and SST/HDMI on the same port */
12819 if (used_ports & used_mst_ports)
12826 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_crtc_state *crtc_state)
12828 intel_crtc_copy_color_blobs(crtc_state);
12832 intel_crtc_copy_uapi_to_hw_state(struct intel_crtc_state *crtc_state)
12834 crtc_state->hw.enable = crtc_state->uapi.enable;
12835 crtc_state->hw.active = crtc_state->uapi.active;
12836 crtc_state->hw.mode = crtc_state->uapi.mode;
12837 crtc_state->hw.adjusted_mode = crtc_state->uapi.adjusted_mode;
12838 intel_crtc_copy_uapi_to_hw_state_nomodeset(crtc_state);
12841 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state)
12843 crtc_state->uapi.enable = crtc_state->hw.enable;
12844 crtc_state->uapi.active = crtc_state->hw.active;
12845 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0);
12847 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode;
12849 /* copy color blobs to uapi */
12850 drm_property_replace_blob(&crtc_state->uapi.degamma_lut,
12851 crtc_state->hw.degamma_lut);
12852 drm_property_replace_blob(&crtc_state->uapi.gamma_lut,
12853 crtc_state->hw.gamma_lut);
12854 drm_property_replace_blob(&crtc_state->uapi.ctm,
12855 crtc_state->hw.ctm);
12859 intel_crtc_prepare_cleared_state(struct intel_crtc_state *crtc_state)
12861 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12862 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12863 struct intel_crtc_state *saved_state;
12865 saved_state = intel_crtc_state_alloc(crtc);
12869 /* free the old crtc_state->hw members */
12870 intel_crtc_free_hw_state(crtc_state);
12872 /* FIXME: before the switch to atomic started, a new pipe_config was
12873 * kzalloc'd. Code that depends on any field being zero should be
12874 * fixed, so that the crtc_state can be safely duplicated. For now,
12875 * only fields that are know to not cause problems are preserved. */
12877 saved_state->uapi = crtc_state->uapi;
12878 saved_state->scaler_state = crtc_state->scaler_state;
12879 saved_state->shared_dpll = crtc_state->shared_dpll;
12880 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
12881 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
12882 sizeof(saved_state->icl_port_dplls));
12883 saved_state->crc_enabled = crtc_state->crc_enabled;
12884 if (IS_G4X(dev_priv) ||
12885 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12886 saved_state->wm = crtc_state->wm;
12888 * Save the slave bitmask which gets filled for master crtc state during
12889 * slave atomic check call.
12891 if (is_trans_port_sync_master(crtc_state))
12892 saved_state->sync_mode_slaves_mask =
12893 crtc_state->sync_mode_slaves_mask;
12895 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
12896 kfree(saved_state);
12898 intel_crtc_copy_uapi_to_hw_state(crtc_state);
12904 intel_modeset_pipe_config(struct intel_crtc_state *pipe_config)
12906 struct drm_crtc *crtc = pipe_config->uapi.crtc;
12907 struct drm_atomic_state *state = pipe_config->uapi.state;
12908 struct intel_encoder *encoder;
12909 struct drm_connector *connector;
12910 struct drm_connector_state *connector_state;
12915 pipe_config->cpu_transcoder =
12916 (enum transcoder) to_intel_crtc(crtc)->pipe;
12919 * Sanitize sync polarity flags based on requested ones. If neither
12920 * positive or negative polarity is requested, treat this as meaning
12921 * negative polarity.
12923 if (!(pipe_config->hw.adjusted_mode.flags &
12924 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
12925 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
12927 if (!(pipe_config->hw.adjusted_mode.flags &
12928 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
12929 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
12931 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
12936 base_bpp = pipe_config->pipe_bpp;
12939 * Determine the real pipe dimensions. Note that stereo modes can
12940 * increase the actual pipe size due to the frame doubling and
12941 * insertion of additional space for blanks between the frame. This
12942 * is stored in the crtc timings. We use the requested mode to do this
12943 * computation to clearly distinguish it from the adjusted mode, which
12944 * can be changed by the connectors in the below retry loop.
12946 drm_mode_get_hv_timing(&pipe_config->hw.mode,
12947 &pipe_config->pipe_src_w,
12948 &pipe_config->pipe_src_h);
12950 for_each_new_connector_in_state(state, connector, connector_state, i) {
12951 if (connector_state->crtc != crtc)
12954 encoder = to_intel_encoder(connector_state->best_encoder);
12956 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
12957 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
12962 * Determine output_types before calling the .compute_config()
12963 * hooks so that the hooks can use this information safely.
12965 if (encoder->compute_output_type)
12966 pipe_config->output_types |=
12967 BIT(encoder->compute_output_type(encoder, pipe_config,
12970 pipe_config->output_types |= BIT(encoder->type);
12974 /* Ensure the port clock defaults are reset when retrying. */
12975 pipe_config->port_clock = 0;
12976 pipe_config->pixel_multiplier = 1;
12978 /* Fill in default crtc timings, allow encoders to overwrite them. */
12979 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
12980 CRTC_STEREO_DOUBLE);
12982 /* Set the crtc_state defaults for trans_port_sync */
12983 pipe_config->master_transcoder = INVALID_TRANSCODER;
12984 ret = icl_add_sync_mode_crtcs(pipe_config);
12986 DRM_DEBUG_KMS("Cannot assign Sync Mode CRTCs: %d\n",
12991 /* Pass our mode to the connectors and the CRTC to give them a chance to
12992 * adjust it according to limitations or connector properties, and also
12993 * a chance to reject the mode entirely.
12995 for_each_new_connector_in_state(state, connector, connector_state, i) {
12996 if (connector_state->crtc != crtc)
12999 encoder = to_intel_encoder(connector_state->best_encoder);
13000 ret = encoder->compute_config(encoder, pipe_config,
13003 if (ret != -EDEADLK)
13004 DRM_DEBUG_KMS("Encoder config failure: %d\n",
13010 /* Set default port clock if not overwritten by the encoder. Needs to be
13011 * done afterwards in case the encoder adjusts the mode. */
13012 if (!pipe_config->port_clock)
13013 pipe_config->port_clock = pipe_config->hw.adjusted_mode.crtc_clock
13014 * pipe_config->pixel_multiplier;
13016 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
13017 if (ret == -EDEADLK)
13020 DRM_DEBUG_KMS("CRTC fixup failed\n");
13024 if (ret == RETRY) {
13025 if (WARN(!retry, "loop in pipe configuration computation\n"))
13028 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
13030 goto encoder_retry;
13033 /* Dithering seems to not pass-through bits correctly when it should, so
13034 * only enable it on 6bpc panels and when its not a compliance
13035 * test requesting 6bpc video pattern.
13037 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
13038 !pipe_config->dither_force_disable;
13039 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
13040 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
13043 * Make drm_calc_timestamping_constants in
13044 * drm_atomic_helper_update_legacy_modeset_state() happy
13046 pipe_config->uapi.adjusted_mode = pipe_config->hw.adjusted_mode;
13051 bool intel_fuzzy_clock_check(int clock1, int clock2)
13055 if (clock1 == clock2)
13058 if (!clock1 || !clock2)
13061 diff = abs(clock1 - clock2);
13063 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
13070 intel_compare_m_n(unsigned int m, unsigned int n,
13071 unsigned int m2, unsigned int n2,
13074 if (m == m2 && n == n2)
13077 if (exact || !m || !n || !m2 || !n2)
13080 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
13087 } else if (n < n2) {
13097 return intel_fuzzy_clock_check(m, m2);
13101 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
13102 const struct intel_link_m_n *m2_n2,
13105 return m_n->tu == m2_n2->tu &&
13106 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
13107 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
13108 intel_compare_m_n(m_n->link_m, m_n->link_n,
13109 m2_n2->link_m, m2_n2->link_n, exact);
13113 intel_compare_infoframe(const union hdmi_infoframe *a,
13114 const union hdmi_infoframe *b)
13116 return memcmp(a, b, sizeof(*a)) == 0;
13120 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
13121 bool fastset, const char *name,
13122 const union hdmi_infoframe *a,
13123 const union hdmi_infoframe *b)
13126 if ((drm_debug & DRM_UT_KMS) == 0)
13129 DRM_DEBUG_KMS("fastset mismatch in %s infoframe\n", name);
13130 DRM_DEBUG_KMS("expected:\n");
13131 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
13132 DRM_DEBUG_KMS("found:\n");
13133 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
13135 DRM_ERROR("mismatch in %s infoframe\n", name);
13136 DRM_ERROR("expected:\n");
13137 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
13138 DRM_ERROR("found:\n");
13139 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
13143 static void __printf(4, 5)
13144 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
13145 const char *name, const char *format, ...)
13147 struct va_format vaf;
13150 va_start(args, format);
13155 DRM_DEBUG_KMS("[CRTC:%d:%s] fastset mismatch in %s %pV\n",
13156 crtc->base.base.id, crtc->base.name, name, &vaf);
13158 DRM_ERROR("[CRTC:%d:%s] mismatch in %s %pV\n",
13159 crtc->base.base.id, crtc->base.name, name, &vaf);
13164 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
13166 if (i915_modparams.fastboot != -1)
13167 return i915_modparams.fastboot;
13169 /* Enable fastboot by default on Skylake and newer */
13170 if (INTEL_GEN(dev_priv) >= 9)
13173 /* Enable fastboot by default on VLV and CHV */
13174 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13177 /* Disabled by default on all others */
13182 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
13183 const struct intel_crtc_state *pipe_config,
13186 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
13187 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
13190 bool fixup_inherited = fastset &&
13191 (current_config->hw.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
13192 !(pipe_config->hw.mode.private_flags & I915_MODE_FLAG_INHERITED);
13194 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
13195 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
13199 #define PIPE_CONF_CHECK_X(name) do { \
13200 if (current_config->name != pipe_config->name) { \
13201 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13202 "(expected 0x%08x, found 0x%08x)", \
13203 current_config->name, \
13204 pipe_config->name); \
13209 #define PIPE_CONF_CHECK_I(name) do { \
13210 if (current_config->name != pipe_config->name) { \
13211 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13212 "(expected %i, found %i)", \
13213 current_config->name, \
13214 pipe_config->name); \
13219 #define PIPE_CONF_CHECK_BOOL(name) do { \
13220 if (current_config->name != pipe_config->name) { \
13221 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13222 "(expected %s, found %s)", \
13223 yesno(current_config->name), \
13224 yesno(pipe_config->name)); \
13230 * Checks state where we only read out the enabling, but not the entire
13231 * state itself (like full infoframes or ELD for audio). These states
13232 * require a full modeset on bootup to fix up.
13234 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
13235 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
13236 PIPE_CONF_CHECK_BOOL(name); \
13238 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13239 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
13240 yesno(current_config->name), \
13241 yesno(pipe_config->name)); \
13246 #define PIPE_CONF_CHECK_P(name) do { \
13247 if (current_config->name != pipe_config->name) { \
13248 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13249 "(expected %p, found %p)", \
13250 current_config->name, \
13251 pipe_config->name); \
13256 #define PIPE_CONF_CHECK_M_N(name) do { \
13257 if (!intel_compare_link_m_n(¤t_config->name, \
13258 &pipe_config->name,\
13260 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13261 "(expected tu %i gmch %i/%i link %i/%i, " \
13262 "found tu %i, gmch %i/%i link %i/%i)", \
13263 current_config->name.tu, \
13264 current_config->name.gmch_m, \
13265 current_config->name.gmch_n, \
13266 current_config->name.link_m, \
13267 current_config->name.link_n, \
13268 pipe_config->name.tu, \
13269 pipe_config->name.gmch_m, \
13270 pipe_config->name.gmch_n, \
13271 pipe_config->name.link_m, \
13272 pipe_config->name.link_n); \
13277 /* This is required for BDW+ where there is only one set of registers for
13278 * switching between high and low RR.
13279 * This macro can be used whenever a comparison has to be made between one
13280 * hw state and multiple sw state variables.
13282 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
13283 if (!intel_compare_link_m_n(¤t_config->name, \
13284 &pipe_config->name, !fastset) && \
13285 !intel_compare_link_m_n(¤t_config->alt_name, \
13286 &pipe_config->name, !fastset)) { \
13287 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13288 "(expected tu %i gmch %i/%i link %i/%i, " \
13289 "or tu %i gmch %i/%i link %i/%i, " \
13290 "found tu %i, gmch %i/%i link %i/%i)", \
13291 current_config->name.tu, \
13292 current_config->name.gmch_m, \
13293 current_config->name.gmch_n, \
13294 current_config->name.link_m, \
13295 current_config->name.link_n, \
13296 current_config->alt_name.tu, \
13297 current_config->alt_name.gmch_m, \
13298 current_config->alt_name.gmch_n, \
13299 current_config->alt_name.link_m, \
13300 current_config->alt_name.link_n, \
13301 pipe_config->name.tu, \
13302 pipe_config->name.gmch_m, \
13303 pipe_config->name.gmch_n, \
13304 pipe_config->name.link_m, \
13305 pipe_config->name.link_n); \
13310 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
13311 if ((current_config->name ^ pipe_config->name) & (mask)) { \
13312 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13313 "(%x) (expected %i, found %i)", \
13315 current_config->name & (mask), \
13316 pipe_config->name & (mask)); \
13321 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
13322 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
13323 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13324 "(expected %i, found %i)", \
13325 current_config->name, \
13326 pipe_config->name); \
13331 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
13332 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
13333 &pipe_config->infoframes.name)) { \
13334 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
13335 ¤t_config->infoframes.name, \
13336 &pipe_config->infoframes.name); \
13341 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
13342 if (current_config->name1 != pipe_config->name1) { \
13343 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
13344 "(expected %i, found %i, won't compare lut values)", \
13345 current_config->name1, \
13346 pipe_config->name1); \
13349 if (!intel_color_lut_equal(current_config->name2, \
13350 pipe_config->name2, pipe_config->name1, \
13351 bit_precision)) { \
13352 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
13353 "hw_state doesn't match sw_state"); \
13359 #define PIPE_CONF_QUIRK(quirk) \
13360 ((current_config->quirks | pipe_config->quirks) & (quirk))
13362 PIPE_CONF_CHECK_I(cpu_transcoder);
13364 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
13365 PIPE_CONF_CHECK_I(fdi_lanes);
13366 PIPE_CONF_CHECK_M_N(fdi_m_n);
13368 PIPE_CONF_CHECK_I(lane_count);
13369 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
13371 if (INTEL_GEN(dev_priv) < 8) {
13372 PIPE_CONF_CHECK_M_N(dp_m_n);
13374 if (current_config->has_drrs)
13375 PIPE_CONF_CHECK_M_N(dp_m2_n2);
13377 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
13379 PIPE_CONF_CHECK_X(output_types);
13381 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hdisplay);
13382 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_htotal);
13383 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_start);
13384 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_end);
13385 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_start);
13386 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_end);
13388 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vdisplay);
13389 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vtotal);
13390 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_start);
13391 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_end);
13392 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_start);
13393 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_end);
13395 PIPE_CONF_CHECK_I(pixel_multiplier);
13396 PIPE_CONF_CHECK_I(output_format);
13397 PIPE_CONF_CHECK_I(dc3co_exitline);
13398 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
13399 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
13400 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13401 PIPE_CONF_CHECK_BOOL(limited_color_range);
13403 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
13404 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
13405 PIPE_CONF_CHECK_BOOL(has_infoframe);
13406 PIPE_CONF_CHECK_BOOL(fec_enable);
13408 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
13410 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13411 DRM_MODE_FLAG_INTERLACE);
13413 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
13414 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13415 DRM_MODE_FLAG_PHSYNC);
13416 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13417 DRM_MODE_FLAG_NHSYNC);
13418 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13419 DRM_MODE_FLAG_PVSYNC);
13420 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13421 DRM_MODE_FLAG_NVSYNC);
13424 PIPE_CONF_CHECK_X(gmch_pfit.control);
13425 /* pfit ratios are autocomputed by the hw on gen4+ */
13426 if (INTEL_GEN(dev_priv) < 4)
13427 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
13428 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
13431 * Changing the EDP transcoder input mux
13432 * (A_ONOFF vs. A_ON) requires a full modeset.
13434 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
13437 PIPE_CONF_CHECK_I(pipe_src_w);
13438 PIPE_CONF_CHECK_I(pipe_src_h);
13440 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
13441 if (current_config->pch_pfit.enabled) {
13442 PIPE_CONF_CHECK_X(pch_pfit.pos);
13443 PIPE_CONF_CHECK_X(pch_pfit.size);
13446 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
13447 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
13449 PIPE_CONF_CHECK_X(gamma_mode);
13450 if (IS_CHERRYVIEW(dev_priv))
13451 PIPE_CONF_CHECK_X(cgm_mode);
13453 PIPE_CONF_CHECK_X(csc_mode);
13454 PIPE_CONF_CHECK_BOOL(gamma_enable);
13455 PIPE_CONF_CHECK_BOOL(csc_enable);
13457 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
13459 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
13463 PIPE_CONF_CHECK_BOOL(double_wide);
13465 PIPE_CONF_CHECK_P(shared_dpll);
13466 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
13467 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
13468 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
13469 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
13470 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
13471 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
13472 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
13473 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
13474 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
13475 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
13476 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
13477 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
13478 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
13479 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
13480 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
13481 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
13482 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
13483 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
13484 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
13485 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
13486 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
13487 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
13488 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
13489 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
13490 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
13491 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
13492 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
13493 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
13494 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
13495 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
13496 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
13498 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
13499 PIPE_CONF_CHECK_X(dsi_pll.div);
13501 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
13502 PIPE_CONF_CHECK_I(pipe_bpp);
13504 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
13505 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
13507 PIPE_CONF_CHECK_I(min_voltage_level);
13509 PIPE_CONF_CHECK_X(infoframes.enable);
13510 PIPE_CONF_CHECK_X(infoframes.gcp);
13511 PIPE_CONF_CHECK_INFOFRAME(avi);
13512 PIPE_CONF_CHECK_INFOFRAME(spd);
13513 PIPE_CONF_CHECK_INFOFRAME(hdmi);
13514 PIPE_CONF_CHECK_INFOFRAME(drm);
13516 PIPE_CONF_CHECK_I(sync_mode_slaves_mask);
13517 PIPE_CONF_CHECK_I(master_transcoder);
13519 PIPE_CONF_CHECK_I(dsc.compression_enable);
13520 PIPE_CONF_CHECK_I(dsc.dsc_split);
13521 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
13523 PIPE_CONF_CHECK_I(mst_master_transcoder);
13525 #undef PIPE_CONF_CHECK_X
13526 #undef PIPE_CONF_CHECK_I
13527 #undef PIPE_CONF_CHECK_BOOL
13528 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
13529 #undef PIPE_CONF_CHECK_P
13530 #undef PIPE_CONF_CHECK_FLAGS
13531 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
13532 #undef PIPE_CONF_CHECK_COLOR_LUT
13533 #undef PIPE_CONF_QUIRK
13538 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
13539 const struct intel_crtc_state *pipe_config)
13541 if (pipe_config->has_pch_encoder) {
13542 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
13543 &pipe_config->fdi_m_n);
13544 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
13547 * FDI already provided one idea for the dotclock.
13548 * Yell if the encoder disagrees.
13550 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
13551 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
13552 fdi_dotclock, dotclock);
13556 static void verify_wm_state(struct intel_crtc *crtc,
13557 struct intel_crtc_state *new_crtc_state)
13559 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13560 struct skl_hw_state {
13561 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
13562 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
13563 struct skl_ddb_allocation ddb;
13564 struct skl_pipe_wm wm;
13566 struct skl_ddb_allocation *sw_ddb;
13567 struct skl_pipe_wm *sw_wm;
13568 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
13569 const enum pipe pipe = crtc->pipe;
13570 int plane, level, max_level = ilk_wm_max_level(dev_priv);
13572 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->hw.active)
13575 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
13579 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
13580 sw_wm = &new_crtc_state->wm.skl.optimal;
13582 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
13584 skl_ddb_get_hw_state(dev_priv, &hw->ddb);
13585 sw_ddb = &dev_priv->wm.skl_hw.ddb;
13587 if (INTEL_GEN(dev_priv) >= 11 &&
13588 hw->ddb.enabled_slices != sw_ddb->enabled_slices)
13589 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
13590 sw_ddb->enabled_slices,
13591 hw->ddb.enabled_slices);
13594 for_each_universal_plane(dev_priv, pipe, plane) {
13595 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13597 hw_plane_wm = &hw->wm.planes[plane];
13598 sw_plane_wm = &sw_wm->planes[plane];
13601 for (level = 0; level <= max_level; level++) {
13602 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13603 &sw_plane_wm->wm[level]))
13606 DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13607 pipe_name(pipe), plane + 1, level,
13608 sw_plane_wm->wm[level].plane_en,
13609 sw_plane_wm->wm[level].plane_res_b,
13610 sw_plane_wm->wm[level].plane_res_l,
13611 hw_plane_wm->wm[level].plane_en,
13612 hw_plane_wm->wm[level].plane_res_b,
13613 hw_plane_wm->wm[level].plane_res_l);
13616 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13617 &sw_plane_wm->trans_wm)) {
13618 DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13619 pipe_name(pipe), plane + 1,
13620 sw_plane_wm->trans_wm.plane_en,
13621 sw_plane_wm->trans_wm.plane_res_b,
13622 sw_plane_wm->trans_wm.plane_res_l,
13623 hw_plane_wm->trans_wm.plane_en,
13624 hw_plane_wm->trans_wm.plane_res_b,
13625 hw_plane_wm->trans_wm.plane_res_l);
13629 hw_ddb_entry = &hw->ddb_y[plane];
13630 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
13632 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13633 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
13634 pipe_name(pipe), plane + 1,
13635 sw_ddb_entry->start, sw_ddb_entry->end,
13636 hw_ddb_entry->start, hw_ddb_entry->end);
13642 * If the cursor plane isn't active, we may not have updated it's ddb
13643 * allocation. In that case since the ddb allocation will be updated
13644 * once the plane becomes visible, we can skip this check
13647 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13649 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
13650 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
13653 for (level = 0; level <= max_level; level++) {
13654 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13655 &sw_plane_wm->wm[level]))
13658 DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13659 pipe_name(pipe), level,
13660 sw_plane_wm->wm[level].plane_en,
13661 sw_plane_wm->wm[level].plane_res_b,
13662 sw_plane_wm->wm[level].plane_res_l,
13663 hw_plane_wm->wm[level].plane_en,
13664 hw_plane_wm->wm[level].plane_res_b,
13665 hw_plane_wm->wm[level].plane_res_l);
13668 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13669 &sw_plane_wm->trans_wm)) {
13670 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13672 sw_plane_wm->trans_wm.plane_en,
13673 sw_plane_wm->trans_wm.plane_res_b,
13674 sw_plane_wm->trans_wm.plane_res_l,
13675 hw_plane_wm->trans_wm.plane_en,
13676 hw_plane_wm->trans_wm.plane_res_b,
13677 hw_plane_wm->trans_wm.plane_res_l);
13681 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
13682 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
13684 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13685 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
13687 sw_ddb_entry->start, sw_ddb_entry->end,
13688 hw_ddb_entry->start, hw_ddb_entry->end);
13696 verify_connector_state(struct intel_atomic_state *state,
13697 struct intel_crtc *crtc)
13699 struct drm_connector *connector;
13700 struct drm_connector_state *new_conn_state;
13703 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
13704 struct drm_encoder *encoder = connector->encoder;
13705 struct intel_crtc_state *crtc_state = NULL;
13707 if (new_conn_state->crtc != &crtc->base)
13711 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13713 intel_connector_verify_state(crtc_state, new_conn_state);
13715 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
13716 "connector's atomic encoder doesn't match legacy encoder\n");
13721 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
13723 struct intel_encoder *encoder;
13724 struct drm_connector *connector;
13725 struct drm_connector_state *old_conn_state, *new_conn_state;
13728 for_each_intel_encoder(&dev_priv->drm, encoder) {
13729 bool enabled = false, found = false;
13732 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
13733 encoder->base.base.id,
13734 encoder->base.name);
13736 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
13737 new_conn_state, i) {
13738 if (old_conn_state->best_encoder == &encoder->base)
13741 if (new_conn_state->best_encoder != &encoder->base)
13743 found = enabled = true;
13745 I915_STATE_WARN(new_conn_state->crtc !=
13746 encoder->base.crtc,
13747 "connector's crtc doesn't match encoder crtc\n");
13753 I915_STATE_WARN(!!encoder->base.crtc != enabled,
13754 "encoder's enabled state mismatch "
13755 "(expected %i, found %i)\n",
13756 !!encoder->base.crtc, enabled);
13758 if (!encoder->base.crtc) {
13761 active = encoder->get_hw_state(encoder, &pipe);
13762 I915_STATE_WARN(active,
13763 "encoder detached but still enabled on pipe %c.\n",
13770 verify_crtc_state(struct intel_crtc *crtc,
13771 struct intel_crtc_state *old_crtc_state,
13772 struct intel_crtc_state *new_crtc_state)
13774 struct drm_device *dev = crtc->base.dev;
13775 struct drm_i915_private *dev_priv = to_i915(dev);
13776 struct intel_encoder *encoder;
13777 struct intel_crtc_state *pipe_config = old_crtc_state;
13778 struct drm_atomic_state *state = old_crtc_state->uapi.state;
13781 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
13782 intel_crtc_free_hw_state(old_crtc_state);
13783 intel_crtc_state_reset(old_crtc_state, crtc);
13784 old_crtc_state->uapi.state = state;
13786 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.base.id, crtc->base.name);
13788 active = dev_priv->display.get_pipe_config(crtc, pipe_config);
13790 /* we keep both pipes enabled on 830 */
13791 if (IS_I830(dev_priv))
13792 active = new_crtc_state->hw.active;
13794 I915_STATE_WARN(new_crtc_state->hw.active != active,
13795 "crtc active state doesn't match with hw state "
13796 "(expected %i, found %i)\n",
13797 new_crtc_state->hw.active, active);
13799 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
13800 "transitional active state does not match atomic hw state "
13801 "(expected %i, found %i)\n",
13802 new_crtc_state->hw.active, crtc->active);
13804 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
13807 active = encoder->get_hw_state(encoder, &pipe);
13808 I915_STATE_WARN(active != new_crtc_state->hw.active,
13809 "[ENCODER:%i] active %i with crtc active %i\n",
13810 encoder->base.base.id, active,
13811 new_crtc_state->hw.active);
13813 I915_STATE_WARN(active && crtc->pipe != pipe,
13814 "Encoder connected to wrong pipe %c\n",
13818 encoder->get_config(encoder, pipe_config);
13821 intel_crtc_compute_pixel_rate(pipe_config);
13823 if (!new_crtc_state->hw.active)
13826 intel_pipe_config_sanity_check(dev_priv, pipe_config);
13828 if (!intel_pipe_config_compare(new_crtc_state,
13829 pipe_config, false)) {
13830 I915_STATE_WARN(1, "pipe state doesn't match!\n");
13831 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
13832 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
13837 intel_verify_planes(struct intel_atomic_state *state)
13839 struct intel_plane *plane;
13840 const struct intel_plane_state *plane_state;
13843 for_each_new_intel_plane_in_state(state, plane,
13845 assert_plane(plane, plane_state->planar_slave ||
13846 plane_state->uapi.visible);
13850 verify_single_dpll_state(struct drm_i915_private *dev_priv,
13851 struct intel_shared_dpll *pll,
13852 struct intel_crtc *crtc,
13853 struct intel_crtc_state *new_crtc_state)
13855 struct intel_dpll_hw_state dpll_hw_state;
13856 unsigned int crtc_mask;
13859 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
13861 DRM_DEBUG_KMS("%s\n", pll->info->name);
13863 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
13865 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
13866 I915_STATE_WARN(!pll->on && pll->active_mask,
13867 "pll in active use but not on in sw tracking\n");
13868 I915_STATE_WARN(pll->on && !pll->active_mask,
13869 "pll is on but not used by any active crtc\n");
13870 I915_STATE_WARN(pll->on != active,
13871 "pll on state mismatch (expected %i, found %i)\n",
13876 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
13877 "more active pll users than references: %x vs %x\n",
13878 pll->active_mask, pll->state.crtc_mask);
13883 crtc_mask = drm_crtc_mask(&crtc->base);
13885 if (new_crtc_state->hw.active)
13886 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
13887 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
13888 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13890 I915_STATE_WARN(pll->active_mask & crtc_mask,
13891 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
13892 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13894 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
13895 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
13896 crtc_mask, pll->state.crtc_mask);
13898 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
13900 sizeof(dpll_hw_state)),
13901 "pll hw state mismatch\n");
13905 verify_shared_dpll_state(struct intel_crtc *crtc,
13906 struct intel_crtc_state *old_crtc_state,
13907 struct intel_crtc_state *new_crtc_state)
13909 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13911 if (new_crtc_state->shared_dpll)
13912 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
13914 if (old_crtc_state->shared_dpll &&
13915 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
13916 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
13917 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
13919 I915_STATE_WARN(pll->active_mask & crtc_mask,
13920 "pll active mismatch (didn't expect pipe %c in active mask)\n",
13921 pipe_name(drm_crtc_index(&crtc->base)));
13922 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
13923 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
13924 pipe_name(drm_crtc_index(&crtc->base)));
13929 intel_modeset_verify_crtc(struct intel_crtc *crtc,
13930 struct intel_atomic_state *state,
13931 struct intel_crtc_state *old_crtc_state,
13932 struct intel_crtc_state *new_crtc_state)
13934 if (!needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
13937 verify_wm_state(crtc, new_crtc_state);
13938 verify_connector_state(state, crtc);
13939 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
13940 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
13944 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
13948 for (i = 0; i < dev_priv->num_shared_dpll; i++)
13949 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
13953 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
13954 struct intel_atomic_state *state)
13956 verify_encoder_state(dev_priv, state);
13957 verify_connector_state(state, NULL);
13958 verify_disabled_dpll_state(dev_priv);
13962 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
13964 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
13965 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13966 const struct drm_display_mode *adjusted_mode =
13967 &crtc_state->hw.adjusted_mode;
13969 drm_calc_timestamping_constants(&crtc->base, adjusted_mode);
13972 * The scanline counter increments at the leading edge of hsync.
13974 * On most platforms it starts counting from vtotal-1 on the
13975 * first active line. That means the scanline counter value is
13976 * always one less than what we would expect. Ie. just after
13977 * start of vblank, which also occurs at start of hsync (on the
13978 * last active line), the scanline counter will read vblank_start-1.
13980 * On gen2 the scanline counter starts counting from 1 instead
13981 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13982 * to keep the value positive), instead of adding one.
13984 * On HSW+ the behaviour of the scanline counter depends on the output
13985 * type. For DP ports it behaves like most other platforms, but on HDMI
13986 * there's an extra 1 line difference. So we need to add two instead of
13987 * one to the value.
13989 * On VLV/CHV DSI the scanline counter would appear to increment
13990 * approx. 1/3 of a scanline before start of vblank. Unfortunately
13991 * that means we can't tell whether we're in vblank or not while
13992 * we're on that particular line. We must still set scanline_offset
13993 * to 1 so that the vblank timestamps come out correct when we query
13994 * the scanline counter from within the vblank interrupt handler.
13995 * However if queried just before the start of vblank we'll get an
13996 * answer that's slightly in the future.
13998 if (IS_GEN(dev_priv, 2)) {
14001 vtotal = adjusted_mode->crtc_vtotal;
14002 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
14005 crtc->scanline_offset = vtotal - 1;
14006 } else if (HAS_DDI(dev_priv) &&
14007 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
14008 crtc->scanline_offset = 2;
14010 crtc->scanline_offset = 1;
14014 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
14016 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14017 struct intel_crtc_state *new_crtc_state;
14018 struct intel_crtc *crtc;
14021 if (!dev_priv->display.crtc_compute_clock)
14024 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14025 if (!needs_modeset(new_crtc_state))
14028 intel_release_shared_dplls(state, crtc);
14033 * This implements the workaround described in the "notes" section of the mode
14034 * set sequence documentation. When going from no pipes or single pipe to
14035 * multiple pipes, and planes are enabled after the pipe, we need to wait at
14036 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
14038 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
14040 struct intel_crtc_state *crtc_state;
14041 struct intel_crtc *crtc;
14042 struct intel_crtc_state *first_crtc_state = NULL;
14043 struct intel_crtc_state *other_crtc_state = NULL;
14044 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
14047 /* look at all crtc's that are going to be enabled in during modeset */
14048 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14049 if (!crtc_state->hw.active ||
14050 !needs_modeset(crtc_state))
14053 if (first_crtc_state) {
14054 other_crtc_state = crtc_state;
14057 first_crtc_state = crtc_state;
14058 first_pipe = crtc->pipe;
14062 /* No workaround needed? */
14063 if (!first_crtc_state)
14066 /* w/a possibly needed, check how many crtc's are already enabled. */
14067 for_each_intel_crtc(state->base.dev, crtc) {
14068 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
14069 if (IS_ERR(crtc_state))
14070 return PTR_ERR(crtc_state);
14072 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
14074 if (!crtc_state->hw.active ||
14075 needs_modeset(crtc_state))
14078 /* 2 or more enabled crtcs means no need for w/a */
14079 if (enabled_pipe != INVALID_PIPE)
14082 enabled_pipe = crtc->pipe;
14085 if (enabled_pipe != INVALID_PIPE)
14086 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
14087 else if (other_crtc_state)
14088 other_crtc_state->hsw_workaround_pipe = first_pipe;
14093 static int intel_modeset_checks(struct intel_atomic_state *state)
14095 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14096 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14097 struct intel_crtc *crtc;
14100 /* keep the current setting */
14101 if (!state->cdclk.force_min_cdclk_changed)
14102 state->cdclk.force_min_cdclk = dev_priv->cdclk.force_min_cdclk;
14104 state->modeset = true;
14105 state->active_pipes = dev_priv->active_pipes;
14106 state->cdclk.logical = dev_priv->cdclk.logical;
14107 state->cdclk.actual = dev_priv->cdclk.actual;
14109 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14110 new_crtc_state, i) {
14111 if (new_crtc_state->hw.active)
14112 state->active_pipes |= BIT(crtc->pipe);
14114 state->active_pipes &= ~BIT(crtc->pipe);
14116 if (old_crtc_state->hw.active != new_crtc_state->hw.active)
14117 state->active_pipe_changes |= BIT(crtc->pipe);
14120 if (state->active_pipe_changes) {
14121 ret = intel_atomic_lock_global_state(state);
14126 ret = intel_modeset_calc_cdclk(state);
14130 intel_modeset_clear_plls(state);
14132 if (IS_HASWELL(dev_priv))
14133 return hsw_mode_set_planes_workaround(state);
14139 * Handle calculation of various watermark data at the end of the atomic check
14140 * phase. The code here should be run after the per-crtc and per-plane 'check'
14141 * handlers to ensure that all derived state has been updated.
14143 static int calc_watermark_data(struct intel_atomic_state *state)
14145 struct drm_device *dev = state->base.dev;
14146 struct drm_i915_private *dev_priv = to_i915(dev);
14148 /* Is there platform-specific watermark information to calculate? */
14149 if (dev_priv->display.compute_global_watermarks)
14150 return dev_priv->display.compute_global_watermarks(state);
14155 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
14156 struct intel_crtc_state *new_crtc_state)
14158 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
14161 new_crtc_state->uapi.mode_changed = false;
14162 new_crtc_state->update_pipe = true;
14165 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
14166 struct intel_crtc_state *new_crtc_state)
14169 * If we're not doing the full modeset we want to
14170 * keep the current M/N values as they may be
14171 * sufficiently different to the computed values
14172 * to cause problems.
14174 * FIXME: should really copy more fuzzy state here
14176 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
14177 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
14178 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
14179 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
14182 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
14183 struct intel_crtc *crtc,
14186 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14187 struct intel_plane *plane;
14189 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
14190 struct intel_plane_state *plane_state;
14192 if ((plane_ids_mask & BIT(plane->id)) == 0)
14195 plane_state = intel_atomic_get_plane_state(state, plane);
14196 if (IS_ERR(plane_state))
14197 return PTR_ERR(plane_state);
14203 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
14205 /* See {hsw,vlv,ivb}_plane_ratio() */
14206 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
14207 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
14208 IS_IVYBRIDGE(dev_priv);
14211 static int intel_atomic_check_planes(struct intel_atomic_state *state,
14212 bool *need_modeset)
14214 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14215 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14216 struct intel_plane_state *plane_state;
14217 struct intel_plane *plane;
14218 struct intel_crtc *crtc;
14221 ret = icl_add_linked_planes(state);
14225 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14226 ret = intel_plane_atomic_check(state, plane);
14228 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic driver check failed\n",
14229 plane->base.base.id, plane->base.name);
14234 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14235 new_crtc_state, i) {
14236 u8 old_active_planes, new_active_planes;
14238 ret = icl_check_nv12_planes(new_crtc_state);
14243 * On some platforms the number of active planes affects
14244 * the planes' minimum cdclk calculation. Add such planes
14245 * to the state before we compute the minimum cdclk.
14247 if (!active_planes_affects_min_cdclk(dev_priv))
14250 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14251 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14253 if (hweight8(old_active_planes) == hweight8(new_active_planes))
14256 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
14262 * active_planes bitmask has been updated, and potentially
14263 * affected planes are part of the state. We can now
14264 * compute the minimum cdclk for each plane.
14266 for_each_new_intel_plane_in_state(state, plane, plane_state, i)
14267 *need_modeset |= intel_plane_calc_min_cdclk(state, plane);
14272 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
14274 struct intel_crtc_state *crtc_state;
14275 struct intel_crtc *crtc;
14278 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14279 int ret = intel_crtc_atomic_check(state, crtc);
14281 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n",
14282 crtc->base.base.id, crtc->base.name);
14290 static bool intel_cpu_transcoder_needs_modeset(struct intel_atomic_state *state,
14291 enum transcoder transcoder)
14293 struct intel_crtc_state *new_crtc_state;
14294 struct intel_crtc *crtc;
14297 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
14298 if (new_crtc_state->cpu_transcoder == transcoder)
14299 return needs_modeset(new_crtc_state);
14305 * intel_atomic_check - validate state object
14307 * @_state: state to validate
14309 static int intel_atomic_check(struct drm_device *dev,
14310 struct drm_atomic_state *_state)
14312 struct drm_i915_private *dev_priv = to_i915(dev);
14313 struct intel_atomic_state *state = to_intel_atomic_state(_state);
14314 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14315 struct intel_crtc *crtc;
14317 bool any_ms = false;
14319 /* Catch I915_MODE_FLAG_INHERITED */
14320 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14321 new_crtc_state, i) {
14322 if (new_crtc_state->hw.mode.private_flags !=
14323 old_crtc_state->hw.mode.private_flags)
14324 new_crtc_state->uapi.mode_changed = true;
14327 ret = drm_atomic_helper_check_modeset(dev, &state->base);
14331 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14332 new_crtc_state, i) {
14333 if (!needs_modeset(new_crtc_state)) {
14335 intel_crtc_copy_uapi_to_hw_state_nomodeset(new_crtc_state);
14340 if (!new_crtc_state->uapi.enable) {
14341 intel_crtc_copy_uapi_to_hw_state(new_crtc_state);
14345 ret = intel_crtc_prepare_cleared_state(new_crtc_state);
14349 ret = intel_modeset_pipe_config(new_crtc_state);
14353 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
14357 * Check if fastset is allowed by external dependencies like other
14358 * pipes and transcoders.
14360 * Right now it only forces a fullmodeset when the MST master
14361 * transcoder did not changed but the pipe of the master transcoder
14362 * needs a fullmodeset so all slaves also needs to do a fullmodeset.
14364 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14365 enum transcoder master = new_crtc_state->mst_master_transcoder;
14367 if (!new_crtc_state->hw.enable ||
14368 needs_modeset(new_crtc_state) ||
14369 !intel_dp_mst_is_slave_trans(new_crtc_state))
14372 if (intel_cpu_transcoder_needs_modeset(state, master)) {
14373 new_crtc_state->uapi.mode_changed = true;
14374 new_crtc_state->update_pipe = false;
14378 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14379 new_crtc_state, i) {
14380 if (needs_modeset(new_crtc_state)) {
14385 if (!new_crtc_state->update_pipe)
14388 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
14391 if (any_ms && !check_digital_port_conflicts(state)) {
14392 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
14397 ret = drm_dp_mst_atomic_check(&state->base);
14401 any_ms |= state->cdclk.force_min_cdclk_changed;
14403 ret = intel_atomic_check_planes(state, &any_ms);
14408 ret = intel_modeset_checks(state);
14412 state->cdclk.logical = dev_priv->cdclk.logical;
14415 ret = intel_atomic_check_crtcs(state);
14419 intel_fbc_choose_crtc(dev_priv, state);
14420 ret = calc_watermark_data(state);
14424 ret = intel_bw_atomic_check(state);
14428 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14429 new_crtc_state, i) {
14430 if (!needs_modeset(new_crtc_state) &&
14431 !new_crtc_state->update_pipe)
14434 intel_dump_pipe_config(new_crtc_state, state,
14435 needs_modeset(new_crtc_state) ?
14436 "[modeset]" : "[fastset]");
14442 if (ret == -EDEADLK)
14446 * FIXME would probably be nice to know which crtc specifically
14447 * caused the failure, in cases where we can pinpoint it.
14449 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14451 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
14456 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
14458 return drm_atomic_helper_prepare_planes(state->base.dev,
14462 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
14464 struct drm_device *dev = crtc->base.dev;
14465 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
14467 if (!vblank->max_vblank_count)
14468 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
14470 return crtc->base.funcs->get_vblank_counter(&crtc->base);
14473 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14474 struct intel_crtc_state *crtc_state)
14476 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14478 if (!IS_GEN(dev_priv, 2) || crtc_state->active_planes)
14479 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14481 if (crtc_state->has_pch_encoder) {
14482 enum pipe pch_transcoder =
14483 intel_crtc_pch_transcoder(crtc);
14485 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14489 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
14490 const struct intel_crtc_state *new_crtc_state)
14492 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
14493 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14496 * Update pipe size and adjust fitter if needed: the reason for this is
14497 * that in compute_mode_changes we check the native mode (not the pfit
14498 * mode) to see if we can flip rather than do a full mode set. In the
14499 * fastboot case, we'll flip, but if we don't update the pipesrc and
14500 * pfit state, we'll end up with a big fb scanned out into the wrong
14503 intel_set_pipe_src_size(new_crtc_state);
14505 /* on skylake this is done by detaching scalers */
14506 if (INTEL_GEN(dev_priv) >= 9) {
14507 skl_detach_scalers(new_crtc_state);
14509 if (new_crtc_state->pch_pfit.enabled)
14510 skl_pfit_enable(new_crtc_state);
14511 } else if (HAS_PCH_SPLIT(dev_priv)) {
14512 if (new_crtc_state->pch_pfit.enabled)
14513 ilk_pfit_enable(new_crtc_state);
14514 else if (old_crtc_state->pch_pfit.enabled)
14515 ilk_pfit_disable(old_crtc_state);
14518 if (INTEL_GEN(dev_priv) >= 11)
14519 icl_set_pipe_chicken(crtc);
14522 static void commit_pipe_config(struct intel_atomic_state *state,
14523 struct intel_crtc_state *old_crtc_state,
14524 struct intel_crtc_state *new_crtc_state)
14526 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
14527 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14528 bool modeset = needs_modeset(new_crtc_state);
14531 * During modesets pipe configuration was programmed as the
14532 * CRTC was enabled.
14535 if (new_crtc_state->uapi.color_mgmt_changed ||
14536 new_crtc_state->update_pipe)
14537 intel_color_commit(new_crtc_state);
14539 if (INTEL_GEN(dev_priv) >= 9)
14540 skl_detach_scalers(new_crtc_state);
14542 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
14543 bdw_set_pipemisc(new_crtc_state);
14545 if (new_crtc_state->update_pipe)
14546 intel_pipe_fastset(old_crtc_state, new_crtc_state);
14549 if (dev_priv->display.atomic_update_watermarks)
14550 dev_priv->display.atomic_update_watermarks(state, crtc);
14553 static void intel_update_crtc(struct intel_crtc *crtc,
14554 struct intel_atomic_state *state,
14555 struct intel_crtc_state *old_crtc_state,
14556 struct intel_crtc_state *new_crtc_state)
14558 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14559 bool modeset = needs_modeset(new_crtc_state);
14560 struct intel_plane_state *new_plane_state =
14561 intel_atomic_get_new_plane_state(state,
14562 to_intel_plane(crtc->base.primary));
14565 intel_crtc_update_active_timings(new_crtc_state);
14567 dev_priv->display.crtc_enable(state, crtc);
14569 /* vblanks work again, re-enable pipe CRC. */
14570 intel_crtc_enable_pipe_crc(crtc);
14572 if (new_crtc_state->preload_luts &&
14573 (new_crtc_state->uapi.color_mgmt_changed ||
14574 new_crtc_state->update_pipe))
14575 intel_color_load_luts(new_crtc_state);
14577 intel_pre_plane_update(state, crtc);
14579 if (new_crtc_state->update_pipe)
14580 intel_encoders_update_pipe(state, crtc);
14583 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
14584 intel_fbc_disable(crtc);
14585 else if (new_plane_state)
14586 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
14588 /* Perform vblank evasion around commit operation */
14589 intel_pipe_update_start(new_crtc_state);
14591 commit_pipe_config(state, old_crtc_state, new_crtc_state);
14593 if (INTEL_GEN(dev_priv) >= 9)
14594 skl_update_planes_on_crtc(state, crtc);
14596 i9xx_update_planes_on_crtc(state, crtc);
14598 intel_pipe_update_end(new_crtc_state);
14601 * We usually enable FIFO underrun interrupts as part of the
14602 * CRTC enable sequence during modesets. But when we inherit a
14603 * valid pipe configuration from the BIOS we need to take care
14604 * of enabling them on the CRTC's first fastset.
14606 if (new_crtc_state->update_pipe && !modeset &&
14607 old_crtc_state->hw.mode.private_flags & I915_MODE_FLAG_INHERITED)
14608 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14611 static struct intel_crtc *intel_get_slave_crtc(const struct intel_crtc_state *new_crtc_state)
14613 struct drm_i915_private *dev_priv = to_i915(new_crtc_state->uapi.crtc->dev);
14614 enum transcoder slave_transcoder;
14616 WARN_ON(!is_power_of_2(new_crtc_state->sync_mode_slaves_mask));
14618 slave_transcoder = ffs(new_crtc_state->sync_mode_slaves_mask) - 1;
14619 return intel_get_crtc_for_pipe(dev_priv,
14620 (enum pipe)slave_transcoder);
14623 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
14624 struct intel_crtc_state *old_crtc_state,
14625 struct intel_crtc_state *new_crtc_state,
14626 struct intel_crtc *crtc)
14628 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14630 intel_crtc_disable_planes(state, crtc);
14633 * We need to disable pipe CRC before disabling the pipe,
14634 * or we race against vblank off.
14636 intel_crtc_disable_pipe_crc(crtc);
14638 dev_priv->display.crtc_disable(state, crtc);
14639 crtc->active = false;
14640 intel_fbc_disable(crtc);
14641 intel_disable_shared_dpll(old_crtc_state);
14643 /* FIXME unify this for all platforms */
14644 if (!new_crtc_state->hw.active &&
14645 !HAS_GMCH(dev_priv) &&
14646 dev_priv->display.initial_watermarks)
14647 dev_priv->display.initial_watermarks(state, crtc);
14650 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
14652 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
14653 struct intel_crtc *crtc;
14657 /* Only disable port sync and MST slaves */
14658 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14659 new_crtc_state, i) {
14660 if (!needs_modeset(new_crtc_state))
14663 if (!old_crtc_state->hw.active)
14666 /* In case of Transcoder port Sync master slave CRTCs can be
14667 * assigned in any order and we need to make sure that
14668 * slave CRTCs are disabled first and then master CRTC since
14669 * Slave vblanks are masked till Master Vblanks.
14671 if (!is_trans_port_sync_slave(old_crtc_state) &&
14672 !intel_dp_mst_is_slave_trans(old_crtc_state))
14675 intel_pre_plane_update(state, crtc);
14676 intel_old_crtc_state_disables(state, old_crtc_state,
14677 new_crtc_state, crtc);
14678 handled |= BIT(crtc->pipe);
14681 /* Disable everything else left on */
14682 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14683 new_crtc_state, i) {
14684 if (!needs_modeset(new_crtc_state) ||
14685 (handled & BIT(crtc->pipe)))
14688 intel_pre_plane_update(state, crtc);
14689 if (old_crtc_state->hw.active)
14690 intel_old_crtc_state_disables(state, old_crtc_state,
14691 new_crtc_state, crtc);
14695 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
14697 struct intel_crtc *crtc;
14698 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14701 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14702 if (!new_crtc_state->hw.active)
14705 intel_update_crtc(crtc, state, old_crtc_state,
14710 static void intel_crtc_enable_trans_port_sync(struct intel_crtc *crtc,
14711 struct intel_atomic_state *state,
14712 struct intel_crtc_state *new_crtc_state)
14714 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14716 intel_crtc_update_active_timings(new_crtc_state);
14717 dev_priv->display.crtc_enable(state, crtc);
14718 intel_crtc_enable_pipe_crc(crtc);
14721 static void intel_set_dp_tp_ctl_normal(struct intel_crtc *crtc,
14722 struct intel_atomic_state *state)
14724 struct drm_connector *uninitialized_var(conn);
14725 struct drm_connector_state *conn_state;
14726 struct intel_dp *intel_dp;
14729 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
14730 if (conn_state->crtc == &crtc->base)
14733 intel_dp = enc_to_intel_dp(&intel_attached_encoder(conn)->base);
14734 intel_dp_stop_link_train(intel_dp);
14738 * TODO: This is only called from port sync and it is identical to what will be
14739 * executed again in intel_update_crtc() over port sync pipes
14741 static void intel_post_crtc_enable_updates(struct intel_crtc *crtc,
14742 struct intel_atomic_state *state)
14744 struct intel_crtc_state *new_crtc_state =
14745 intel_atomic_get_new_crtc_state(state, crtc);
14746 struct intel_crtc_state *old_crtc_state =
14747 intel_atomic_get_old_crtc_state(state, crtc);
14748 struct intel_plane_state *new_plane_state =
14749 intel_atomic_get_new_plane_state(state,
14750 to_intel_plane(crtc->base.primary));
14751 bool modeset = needs_modeset(new_crtc_state);
14753 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
14754 intel_fbc_disable(crtc);
14755 else if (new_plane_state)
14756 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
14758 /* Perform vblank evasion around commit operation */
14759 intel_pipe_update_start(new_crtc_state);
14760 commit_pipe_config(state, old_crtc_state, new_crtc_state);
14761 skl_update_planes_on_crtc(state, crtc);
14762 intel_pipe_update_end(new_crtc_state);
14765 * We usually enable FIFO underrun interrupts as part of the
14766 * CRTC enable sequence during modesets. But when we inherit a
14767 * valid pipe configuration from the BIOS we need to take care
14768 * of enabling them on the CRTC's first fastset.
14770 if (new_crtc_state->update_pipe && !modeset &&
14771 old_crtc_state->hw.mode.private_flags & I915_MODE_FLAG_INHERITED)
14772 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14775 static void intel_update_trans_port_sync_crtcs(struct intel_crtc *crtc,
14776 struct intel_atomic_state *state,
14777 struct intel_crtc_state *old_crtc_state,
14778 struct intel_crtc_state *new_crtc_state)
14780 struct intel_crtc *slave_crtc = intel_get_slave_crtc(new_crtc_state);
14781 struct intel_crtc_state *new_slave_crtc_state =
14782 intel_atomic_get_new_crtc_state(state, slave_crtc);
14783 struct intel_crtc_state *old_slave_crtc_state =
14784 intel_atomic_get_old_crtc_state(state, slave_crtc);
14786 WARN_ON(!slave_crtc || !new_slave_crtc_state ||
14787 !old_slave_crtc_state);
14789 DRM_DEBUG_KMS("Updating Transcoder Port Sync Master CRTC = %d %s and Slave CRTC %d %s\n",
14790 crtc->base.base.id, crtc->base.name, slave_crtc->base.base.id,
14791 slave_crtc->base.name);
14793 /* Enable seq for slave with with DP_TP_CTL left Idle until the
14796 intel_crtc_enable_trans_port_sync(slave_crtc,
14798 new_slave_crtc_state);
14800 /* Enable seq for master with with DP_TP_CTL left Idle */
14801 intel_crtc_enable_trans_port_sync(crtc,
14805 /* Set Slave's DP_TP_CTL to Normal */
14806 intel_set_dp_tp_ctl_normal(slave_crtc,
14809 /* Set Master's DP_TP_CTL To Normal */
14810 usleep_range(200, 400);
14811 intel_set_dp_tp_ctl_normal(crtc,
14814 /* Now do the post crtc enable for all master and slaves */
14815 intel_post_crtc_enable_updates(slave_crtc,
14817 intel_post_crtc_enable_updates(crtc,
14821 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
14823 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14824 struct intel_crtc *crtc;
14825 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14826 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
14827 u8 required_slices = state->wm_results.ddb.enabled_slices;
14828 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
14829 const u8 num_pipes = INTEL_NUM_PIPES(dev_priv);
14830 u8 update_pipes = 0, modeset_pipes = 0;
14833 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14834 if (!new_crtc_state->hw.active)
14837 /* ignore allocations for crtc's that have been turned off. */
14838 if (!needs_modeset(new_crtc_state)) {
14839 entries[i] = old_crtc_state->wm.skl.ddb;
14840 update_pipes |= BIT(crtc->pipe);
14842 modeset_pipes |= BIT(crtc->pipe);
14846 /* If 2nd DBuf slice required, enable it here */
14847 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
14848 icl_dbuf_slices_update(dev_priv, required_slices);
14851 * Whenever the number of active pipes changes, we need to make sure we
14852 * update the pipes in the right order so that their ddb allocations
14853 * never overlap with each other between CRTC updates. Otherwise we'll
14854 * cause pipe underruns and other bad stuff.
14856 * So first lets enable all pipes that do not need a fullmodeset as
14857 * those don't have any external dependency.
14859 while (update_pipes) {
14860 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14861 new_crtc_state, i) {
14862 enum pipe pipe = crtc->pipe;
14864 if ((update_pipes & BIT(pipe)) == 0)
14867 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
14868 entries, num_pipes, i))
14871 entries[i] = new_crtc_state->wm.skl.ddb;
14872 update_pipes &= ~BIT(pipe);
14874 intel_update_crtc(crtc, state, old_crtc_state,
14878 * If this is an already active pipe, it's DDB changed,
14879 * and this isn't the last pipe that needs updating
14880 * then we need to wait for a vblank to pass for the
14881 * new ddb allocation to take effect.
14883 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
14884 &old_crtc_state->wm.skl.ddb) &&
14885 (update_pipes | modeset_pipes))
14886 intel_wait_for_vblank(dev_priv, pipe);
14891 * Enable all pipes that needs a modeset and do not depends on other
14894 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14895 new_crtc_state, i) {
14896 enum pipe pipe = crtc->pipe;
14898 if ((modeset_pipes & BIT(pipe)) == 0)
14901 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
14902 is_trans_port_sync_slave(new_crtc_state))
14905 WARN_ON(skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
14906 entries, num_pipes, i));
14908 entries[i] = new_crtc_state->wm.skl.ddb;
14909 modeset_pipes &= ~BIT(pipe);
14911 if (is_trans_port_sync_mode(new_crtc_state)) {
14912 struct intel_crtc *slave_crtc;
14914 intel_update_trans_port_sync_crtcs(crtc, state,
14918 slave_crtc = intel_get_slave_crtc(new_crtc_state);
14919 /* TODO: update entries[] of slave */
14920 modeset_pipes &= ~BIT(slave_crtc->pipe);
14923 intel_update_crtc(crtc, state, old_crtc_state,
14929 * Finally enable all pipes that needs a modeset and depends on
14930 * other pipes, right now it is only MST slaves as both port sync slave
14931 * and master are enabled together
14933 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14934 new_crtc_state, i) {
14935 enum pipe pipe = crtc->pipe;
14937 if ((modeset_pipes & BIT(pipe)) == 0)
14940 WARN_ON(skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
14941 entries, num_pipes, i));
14943 entries[i] = new_crtc_state->wm.skl.ddb;
14944 modeset_pipes &= ~BIT(pipe);
14946 intel_update_crtc(crtc, state, old_crtc_state, new_crtc_state);
14949 WARN_ON(modeset_pipes);
14951 /* If 2nd DBuf slice is no more required disable it */
14952 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
14953 icl_dbuf_slices_update(dev_priv, required_slices);
14956 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
14958 struct intel_atomic_state *state, *next;
14959 struct llist_node *freed;
14961 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
14962 llist_for_each_entry_safe(state, next, freed, freed)
14963 drm_atomic_state_put(&state->base);
14966 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
14968 struct drm_i915_private *dev_priv =
14969 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
14971 intel_atomic_helper_free_state(dev_priv);
14974 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
14976 struct wait_queue_entry wait_fence, wait_reset;
14977 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
14979 init_wait_entry(&wait_fence, 0);
14980 init_wait_entry(&wait_reset, 0);
14982 prepare_to_wait(&intel_state->commit_ready.wait,
14983 &wait_fence, TASK_UNINTERRUPTIBLE);
14984 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
14985 I915_RESET_MODESET),
14986 &wait_reset, TASK_UNINTERRUPTIBLE);
14989 if (i915_sw_fence_done(&intel_state->commit_ready) ||
14990 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
14995 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
14996 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
14997 I915_RESET_MODESET),
15001 static void intel_atomic_cleanup_work(struct work_struct *work)
15003 struct drm_atomic_state *state =
15004 container_of(work, struct drm_atomic_state, commit_work);
15005 struct drm_i915_private *i915 = to_i915(state->dev);
15007 drm_atomic_helper_cleanup_planes(&i915->drm, state);
15008 drm_atomic_helper_commit_cleanup_done(state);
15009 drm_atomic_state_put(state);
15011 intel_atomic_helper_free_state(i915);
15014 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
15016 struct drm_device *dev = state->base.dev;
15017 struct drm_i915_private *dev_priv = to_i915(dev);
15018 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
15019 struct intel_crtc *crtc;
15020 u64 put_domains[I915_MAX_PIPES] = {};
15021 intel_wakeref_t wakeref = 0;
15024 intel_atomic_commit_fence_wait(state);
15026 drm_atomic_helper_wait_for_dependencies(&state->base);
15028 if (state->modeset)
15029 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
15031 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15032 new_crtc_state, i) {
15033 if (needs_modeset(new_crtc_state) ||
15034 new_crtc_state->update_pipe) {
15036 put_domains[crtc->pipe] =
15037 modeset_get_crtc_power_domains(new_crtc_state);
15041 intel_commit_modeset_disables(state);
15043 /* FIXME: Eventually get rid of our crtc->config pointer */
15044 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15045 crtc->config = new_crtc_state;
15047 if (state->modeset) {
15048 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
15050 intel_set_cdclk_pre_plane_update(dev_priv,
15051 &state->cdclk.actual,
15052 &dev_priv->cdclk.actual,
15053 state->cdclk.pipe);
15056 * SKL workaround: bspec recommends we disable the SAGV when we
15057 * have more then one pipe enabled
15059 if (!intel_can_enable_sagv(state))
15060 intel_disable_sagv(dev_priv);
15062 intel_modeset_verify_disabled(dev_priv, state);
15065 /* Complete the events for pipes that have now been disabled */
15066 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15067 bool modeset = needs_modeset(new_crtc_state);
15069 /* Complete events for now disable pipes here. */
15070 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
15071 spin_lock_irq(&dev->event_lock);
15072 drm_crtc_send_vblank_event(&crtc->base,
15073 new_crtc_state->uapi.event);
15074 spin_unlock_irq(&dev->event_lock);
15076 new_crtc_state->uapi.event = NULL;
15080 if (state->modeset)
15081 intel_encoders_update_prepare(state);
15083 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
15084 dev_priv->display.commit_modeset_enables(state);
15086 if (state->modeset) {
15087 intel_encoders_update_complete(state);
15089 intel_set_cdclk_post_plane_update(dev_priv,
15090 &state->cdclk.actual,
15091 &dev_priv->cdclk.actual,
15092 state->cdclk.pipe);
15095 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
15096 * already, but still need the state for the delayed optimization. To
15098 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
15099 * - schedule that vblank worker _before_ calling hw_done
15100 * - at the start of commit_tail, cancel it _synchrously
15101 * - switch over to the vblank wait helper in the core after that since
15102 * we don't need out special handling any more.
15104 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
15106 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15107 if (new_crtc_state->hw.active &&
15108 !needs_modeset(new_crtc_state) &&
15109 !new_crtc_state->preload_luts &&
15110 (new_crtc_state->uapi.color_mgmt_changed ||
15111 new_crtc_state->update_pipe))
15112 intel_color_load_luts(new_crtc_state);
15116 * Now that the vblank has passed, we can go ahead and program the
15117 * optimal watermarks on platforms that need two-step watermark
15120 * TODO: Move this (and other cleanup) to an async worker eventually.
15122 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15123 new_crtc_state, i) {
15125 * Gen2 reports pipe underruns whenever all planes are disabled.
15126 * So re-enable underrun reporting after some planes get enabled.
15128 * We do this before .optimize_watermarks() so that we have a
15129 * chance of catching underruns with the intermediate watermarks
15130 * vs. the new plane configuration.
15132 if (IS_GEN(dev_priv, 2) && planes_enabling(old_crtc_state, new_crtc_state))
15133 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
15135 if (dev_priv->display.optimize_watermarks)
15136 dev_priv->display.optimize_watermarks(state, crtc);
15139 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15140 intel_post_plane_update(state, crtc);
15142 if (put_domains[i])
15143 modeset_put_power_domains(dev_priv, put_domains[i]);
15145 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
15148 /* Underruns don't always raise interrupts, so check manually */
15149 intel_check_cpu_fifo_underruns(dev_priv);
15150 intel_check_pch_fifo_underruns(dev_priv);
15152 if (state->modeset)
15153 intel_verify_planes(state);
15155 if (state->modeset && intel_can_enable_sagv(state))
15156 intel_enable_sagv(dev_priv);
15158 drm_atomic_helper_commit_hw_done(&state->base);
15160 if (state->modeset) {
15161 /* As one of the primary mmio accessors, KMS has a high
15162 * likelihood of triggering bugs in unclaimed access. After we
15163 * finish modesetting, see if an error has been flagged, and if
15164 * so enable debugging for the next modeset - and hope we catch
15167 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
15168 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
15170 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15173 * Defer the cleanup of the old state to a separate worker to not
15174 * impede the current task (userspace for blocking modesets) that
15175 * are executed inline. For out-of-line asynchronous modesets/flips,
15176 * deferring to a new worker seems overkill, but we would place a
15177 * schedule point (cond_resched()) here anyway to keep latencies
15180 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
15181 queue_work(system_highpri_wq, &state->base.commit_work);
15184 static void intel_atomic_commit_work(struct work_struct *work)
15186 struct intel_atomic_state *state =
15187 container_of(work, struct intel_atomic_state, base.commit_work);
15189 intel_atomic_commit_tail(state);
15192 static int __i915_sw_fence_call
15193 intel_atomic_commit_ready(struct i915_sw_fence *fence,
15194 enum i915_sw_fence_notify notify)
15196 struct intel_atomic_state *state =
15197 container_of(fence, struct intel_atomic_state, commit_ready);
15200 case FENCE_COMPLETE:
15201 /* we do blocking waits in the worker, nothing to do here */
15205 struct intel_atomic_helper *helper =
15206 &to_i915(state->base.dev)->atomic_helper;
15208 if (llist_add(&state->freed, &helper->free_list))
15209 schedule_work(&helper->free_work);
15214 return NOTIFY_DONE;
15217 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
15219 struct intel_plane_state *old_plane_state, *new_plane_state;
15220 struct intel_plane *plane;
15223 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
15224 new_plane_state, i)
15225 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
15226 to_intel_frontbuffer(new_plane_state->hw.fb),
15227 plane->frontbuffer_bit);
15230 static void assert_global_state_locked(struct drm_i915_private *dev_priv)
15232 struct intel_crtc *crtc;
15234 for_each_intel_crtc(&dev_priv->drm, crtc)
15235 drm_modeset_lock_assert_held(&crtc->base.mutex);
15238 static int intel_atomic_commit(struct drm_device *dev,
15239 struct drm_atomic_state *_state,
15242 struct intel_atomic_state *state = to_intel_atomic_state(_state);
15243 struct drm_i915_private *dev_priv = to_i915(dev);
15246 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
15248 drm_atomic_state_get(&state->base);
15249 i915_sw_fence_init(&state->commit_ready,
15250 intel_atomic_commit_ready);
15253 * The intel_legacy_cursor_update() fast path takes care
15254 * of avoiding the vblank waits for simple cursor
15255 * movement and flips. For cursor on/off and size changes,
15256 * we want to perform the vblank waits so that watermark
15257 * updates happen during the correct frames. Gen9+ have
15258 * double buffered watermarks and so shouldn't need this.
15260 * Unset state->legacy_cursor_update before the call to
15261 * drm_atomic_helper_setup_commit() because otherwise
15262 * drm_atomic_helper_wait_for_flip_done() is a noop and
15263 * we get FIFO underruns because we didn't wait
15266 * FIXME doing watermarks and fb cleanup from a vblank worker
15267 * (assuming we had any) would solve these problems.
15269 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
15270 struct intel_crtc_state *new_crtc_state;
15271 struct intel_crtc *crtc;
15274 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15275 if (new_crtc_state->wm.need_postvbl_update ||
15276 new_crtc_state->update_wm_post)
15277 state->base.legacy_cursor_update = false;
15280 ret = intel_atomic_prepare_commit(state);
15282 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
15283 i915_sw_fence_commit(&state->commit_ready);
15284 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15288 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
15290 ret = drm_atomic_helper_swap_state(&state->base, true);
15293 i915_sw_fence_commit(&state->commit_ready);
15295 drm_atomic_helper_cleanup_planes(dev, &state->base);
15296 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15299 dev_priv->wm.distrust_bios_wm = false;
15300 intel_shared_dpll_swap_state(state);
15301 intel_atomic_track_fbs(state);
15303 if (state->global_state_changed) {
15304 assert_global_state_locked(dev_priv);
15306 memcpy(dev_priv->min_cdclk, state->min_cdclk,
15307 sizeof(state->min_cdclk));
15308 memcpy(dev_priv->min_voltage_level, state->min_voltage_level,
15309 sizeof(state->min_voltage_level));
15310 dev_priv->active_pipes = state->active_pipes;
15311 dev_priv->cdclk.force_min_cdclk = state->cdclk.force_min_cdclk;
15313 intel_cdclk_swap_state(state);
15316 drm_atomic_state_get(&state->base);
15317 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
15319 i915_sw_fence_commit(&state->commit_ready);
15320 if (nonblock && state->modeset) {
15321 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
15322 } else if (nonblock) {
15323 queue_work(dev_priv->flip_wq, &state->base.commit_work);
15325 if (state->modeset)
15326 flush_workqueue(dev_priv->modeset_wq);
15327 intel_atomic_commit_tail(state);
15333 struct wait_rps_boost {
15334 struct wait_queue_entry wait;
15336 struct drm_crtc *crtc;
15337 struct i915_request *request;
15340 static int do_rps_boost(struct wait_queue_entry *_wait,
15341 unsigned mode, int sync, void *key)
15343 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
15344 struct i915_request *rq = wait->request;
15347 * If we missed the vblank, but the request is already running it
15348 * is reasonable to assume that it will complete before the next
15349 * vblank without our intervention, so leave RPS alone.
15351 if (!i915_request_started(rq))
15352 intel_rps_boost(rq);
15353 i915_request_put(rq);
15355 drm_crtc_vblank_put(wait->crtc);
15357 list_del(&wait->wait.entry);
15362 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
15363 struct dma_fence *fence)
15365 struct wait_rps_boost *wait;
15367 if (!dma_fence_is_i915(fence))
15370 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
15373 if (drm_crtc_vblank_get(crtc))
15376 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
15378 drm_crtc_vblank_put(crtc);
15382 wait->request = to_request(dma_fence_get(fence));
15385 wait->wait.func = do_rps_boost;
15386 wait->wait.flags = 0;
15388 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
15391 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
15393 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
15394 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
15395 struct drm_framebuffer *fb = plane_state->hw.fb;
15396 struct i915_vma *vma;
15398 if (plane->id == PLANE_CURSOR &&
15399 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
15400 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15401 const int align = intel_cursor_alignment(dev_priv);
15404 err = i915_gem_object_attach_phys(obj, align);
15409 vma = intel_pin_and_fence_fb_obj(fb,
15410 &plane_state->view,
15411 intel_plane_uses_fence(plane_state),
15412 &plane_state->flags);
15414 return PTR_ERR(vma);
15416 plane_state->vma = vma;
15421 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
15423 struct i915_vma *vma;
15425 vma = fetch_and_zero(&old_plane_state->vma);
15427 intel_unpin_fb_vma(vma, old_plane_state->flags);
15430 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
15432 struct i915_sched_attr attr = {
15433 .priority = I915_USER_PRIORITY(I915_PRIORITY_DISPLAY),
15436 i915_gem_object_wait_priority(obj, 0, &attr);
15440 * intel_prepare_plane_fb - Prepare fb for usage on plane
15441 * @plane: drm plane to prepare for
15442 * @_new_plane_state: the plane state being prepared
15444 * Prepares a framebuffer for usage on a display plane. Generally this
15445 * involves pinning the underlying object and updating the frontbuffer tracking
15446 * bits. Some older platforms need special physical address handling for
15449 * Returns 0 on success, negative error code on failure.
15452 intel_prepare_plane_fb(struct drm_plane *plane,
15453 struct drm_plane_state *_new_plane_state)
15455 struct intel_plane_state *new_plane_state =
15456 to_intel_plane_state(_new_plane_state);
15457 struct intel_atomic_state *intel_state =
15458 to_intel_atomic_state(new_plane_state->uapi.state);
15459 struct drm_i915_private *dev_priv = to_i915(plane->dev);
15460 struct drm_framebuffer *fb = new_plane_state->hw.fb;
15461 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15462 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
15466 struct intel_crtc_state *crtc_state =
15467 intel_atomic_get_new_crtc_state(intel_state,
15468 to_intel_crtc(plane->state->crtc));
15470 /* Big Hammer, we also need to ensure that any pending
15471 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
15472 * current scanout is retired before unpinning the old
15473 * framebuffer. Note that we rely on userspace rendering
15474 * into the buffer attached to the pipe they are waiting
15475 * on. If not, userspace generates a GPU hang with IPEHR
15476 * point to the MI_WAIT_FOR_EVENT.
15478 * This should only fail upon a hung GPU, in which case we
15479 * can safely continue.
15481 if (needs_modeset(crtc_state)) {
15482 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
15483 old_obj->base.resv, NULL,
15491 if (new_plane_state->uapi.fence) { /* explicit fencing */
15492 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
15493 new_plane_state->uapi.fence,
15494 I915_FENCE_TIMEOUT,
15503 ret = i915_gem_object_pin_pages(obj);
15507 ret = intel_plane_pin_fb(new_plane_state);
15509 i915_gem_object_unpin_pages(obj);
15513 fb_obj_bump_render_priority(obj);
15514 i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
15516 if (!new_plane_state->uapi.fence) { /* implicit fencing */
15517 struct dma_fence *fence;
15519 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
15520 obj->base.resv, NULL,
15521 false, I915_FENCE_TIMEOUT,
15526 fence = dma_resv_get_excl_rcu(obj->base.resv);
15528 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
15530 dma_fence_put(fence);
15533 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
15534 new_plane_state->uapi.fence);
15538 * We declare pageflips to be interactive and so merit a small bias
15539 * towards upclocking to deliver the frame on time. By only changing
15540 * the RPS thresholds to sample more regularly and aim for higher
15541 * clocks we can hopefully deliver low power workloads (like kodi)
15542 * that are not quite steady state without resorting to forcing
15543 * maximum clocks following a vblank miss (see do_rps_boost()).
15545 if (!intel_state->rps_interactive) {
15546 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
15547 intel_state->rps_interactive = true;
15554 * intel_cleanup_plane_fb - Cleans up an fb after plane use
15555 * @plane: drm plane to clean up for
15556 * @_old_plane_state: the state from the previous modeset
15558 * Cleans up a framebuffer that has just been removed from a plane.
15561 intel_cleanup_plane_fb(struct drm_plane *plane,
15562 struct drm_plane_state *_old_plane_state)
15564 struct intel_plane_state *old_plane_state =
15565 to_intel_plane_state(_old_plane_state);
15566 struct intel_atomic_state *intel_state =
15567 to_intel_atomic_state(old_plane_state->uapi.state);
15568 struct drm_i915_private *dev_priv = to_i915(plane->dev);
15570 if (intel_state->rps_interactive) {
15571 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
15572 intel_state->rps_interactive = false;
15575 /* Should only be called after a successful intel_prepare_plane_fb()! */
15576 intel_plane_unpin_fb(old_plane_state);
15580 * intel_plane_destroy - destroy a plane
15581 * @plane: plane to destroy
15583 * Common destruction function for all types of planes (primary, cursor,
15586 void intel_plane_destroy(struct drm_plane *plane)
15588 drm_plane_cleanup(plane);
15589 kfree(to_intel_plane(plane));
15592 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
15593 u32 format, u64 modifier)
15595 switch (modifier) {
15596 case DRM_FORMAT_MOD_LINEAR:
15597 case I915_FORMAT_MOD_X_TILED:
15604 case DRM_FORMAT_C8:
15605 case DRM_FORMAT_RGB565:
15606 case DRM_FORMAT_XRGB1555:
15607 case DRM_FORMAT_XRGB8888:
15608 return modifier == DRM_FORMAT_MOD_LINEAR ||
15609 modifier == I915_FORMAT_MOD_X_TILED;
15615 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
15616 u32 format, u64 modifier)
15618 switch (modifier) {
15619 case DRM_FORMAT_MOD_LINEAR:
15620 case I915_FORMAT_MOD_X_TILED:
15627 case DRM_FORMAT_C8:
15628 case DRM_FORMAT_RGB565:
15629 case DRM_FORMAT_XRGB8888:
15630 case DRM_FORMAT_XBGR8888:
15631 case DRM_FORMAT_ARGB8888:
15632 case DRM_FORMAT_ABGR8888:
15633 case DRM_FORMAT_XRGB2101010:
15634 case DRM_FORMAT_XBGR2101010:
15635 case DRM_FORMAT_ARGB2101010:
15636 case DRM_FORMAT_ABGR2101010:
15637 case DRM_FORMAT_XBGR16161616F:
15638 return modifier == DRM_FORMAT_MOD_LINEAR ||
15639 modifier == I915_FORMAT_MOD_X_TILED;
15645 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
15646 u32 format, u64 modifier)
15648 return modifier == DRM_FORMAT_MOD_LINEAR &&
15649 format == DRM_FORMAT_ARGB8888;
15652 static const struct drm_plane_funcs i965_plane_funcs = {
15653 .update_plane = drm_atomic_helper_update_plane,
15654 .disable_plane = drm_atomic_helper_disable_plane,
15655 .destroy = intel_plane_destroy,
15656 .atomic_duplicate_state = intel_plane_duplicate_state,
15657 .atomic_destroy_state = intel_plane_destroy_state,
15658 .format_mod_supported = i965_plane_format_mod_supported,
15661 static const struct drm_plane_funcs i8xx_plane_funcs = {
15662 .update_plane = drm_atomic_helper_update_plane,
15663 .disable_plane = drm_atomic_helper_disable_plane,
15664 .destroy = intel_plane_destroy,
15665 .atomic_duplicate_state = intel_plane_duplicate_state,
15666 .atomic_destroy_state = intel_plane_destroy_state,
15667 .format_mod_supported = i8xx_plane_format_mod_supported,
15671 intel_legacy_cursor_update(struct drm_plane *_plane,
15672 struct drm_crtc *_crtc,
15673 struct drm_framebuffer *fb,
15674 int crtc_x, int crtc_y,
15675 unsigned int crtc_w, unsigned int crtc_h,
15676 u32 src_x, u32 src_y,
15677 u32 src_w, u32 src_h,
15678 struct drm_modeset_acquire_ctx *ctx)
15680 struct intel_plane *plane = to_intel_plane(_plane);
15681 struct intel_crtc *crtc = to_intel_crtc(_crtc);
15682 struct intel_plane_state *old_plane_state =
15683 to_intel_plane_state(plane->base.state);
15684 struct intel_plane_state *new_plane_state;
15685 struct intel_crtc_state *crtc_state =
15686 to_intel_crtc_state(crtc->base.state);
15687 struct intel_crtc_state *new_crtc_state;
15691 * When crtc is inactive or there is a modeset pending,
15692 * wait for it to complete in the slowpath
15694 if (!crtc_state->hw.active || needs_modeset(crtc_state) ||
15695 crtc_state->update_pipe)
15699 * Don't do an async update if there is an outstanding commit modifying
15700 * the plane. This prevents our async update's changes from getting
15701 * overridden by a previous synchronous update's state.
15703 if (old_plane_state->uapi.commit &&
15704 !try_wait_for_completion(&old_plane_state->uapi.commit->hw_done))
15708 * If any parameters change that may affect watermarks,
15709 * take the slowpath. Only changing fb or position should be
15712 if (old_plane_state->uapi.crtc != &crtc->base ||
15713 old_plane_state->uapi.src_w != src_w ||
15714 old_plane_state->uapi.src_h != src_h ||
15715 old_plane_state->uapi.crtc_w != crtc_w ||
15716 old_plane_state->uapi.crtc_h != crtc_h ||
15717 !old_plane_state->uapi.fb != !fb)
15720 new_plane_state = to_intel_plane_state(intel_plane_duplicate_state(&plane->base));
15721 if (!new_plane_state)
15724 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(&crtc->base));
15725 if (!new_crtc_state) {
15730 drm_atomic_set_fb_for_plane(&new_plane_state->uapi, fb);
15732 new_plane_state->uapi.src_x = src_x;
15733 new_plane_state->uapi.src_y = src_y;
15734 new_plane_state->uapi.src_w = src_w;
15735 new_plane_state->uapi.src_h = src_h;
15736 new_plane_state->uapi.crtc_x = crtc_x;
15737 new_plane_state->uapi.crtc_y = crtc_y;
15738 new_plane_state->uapi.crtc_w = crtc_w;
15739 new_plane_state->uapi.crtc_h = crtc_h;
15741 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
15742 old_plane_state, new_plane_state);
15746 ret = intel_plane_pin_fb(new_plane_state);
15750 intel_frontbuffer_flush(to_intel_frontbuffer(new_plane_state->hw.fb),
15752 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
15753 to_intel_frontbuffer(new_plane_state->hw.fb),
15754 plane->frontbuffer_bit);
15756 /* Swap plane state */
15757 plane->base.state = &new_plane_state->uapi;
15760 * We cannot swap crtc_state as it may be in use by an atomic commit or
15761 * page flip that's running simultaneously. If we swap crtc_state and
15762 * destroy the old state, we will cause a use-after-free there.
15764 * Only update active_planes, which is needed for our internal
15765 * bookkeeping. Either value will do the right thing when updating
15766 * planes atomically. If the cursor was part of the atomic update then
15767 * we would have taken the slowpath.
15769 crtc_state->active_planes = new_crtc_state->active_planes;
15771 if (new_plane_state->uapi.visible)
15772 intel_update_plane(plane, crtc_state, new_plane_state);
15774 intel_disable_plane(plane, crtc_state);
15776 intel_plane_unpin_fb(old_plane_state);
15779 if (new_crtc_state)
15780 intel_crtc_destroy_state(&crtc->base, &new_crtc_state->uapi);
15782 intel_plane_destroy_state(&plane->base, &new_plane_state->uapi);
15784 intel_plane_destroy_state(&plane->base, &old_plane_state->uapi);
15788 return drm_atomic_helper_update_plane(&plane->base, &crtc->base, fb,
15789 crtc_x, crtc_y, crtc_w, crtc_h,
15790 src_x, src_y, src_w, src_h, ctx);
15793 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
15794 .update_plane = intel_legacy_cursor_update,
15795 .disable_plane = drm_atomic_helper_disable_plane,
15796 .destroy = intel_plane_destroy,
15797 .atomic_duplicate_state = intel_plane_duplicate_state,
15798 .atomic_destroy_state = intel_plane_destroy_state,
15799 .format_mod_supported = intel_cursor_format_mod_supported,
15802 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
15803 enum i9xx_plane_id i9xx_plane)
15805 if (!HAS_FBC(dev_priv))
15808 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
15809 return i9xx_plane == PLANE_A; /* tied to pipe A */
15810 else if (IS_IVYBRIDGE(dev_priv))
15811 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
15812 i9xx_plane == PLANE_C;
15813 else if (INTEL_GEN(dev_priv) >= 4)
15814 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
15816 return i9xx_plane == PLANE_A;
15819 static struct intel_plane *
15820 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
15822 struct intel_plane *plane;
15823 const struct drm_plane_funcs *plane_funcs;
15824 unsigned int supported_rotations;
15825 unsigned int possible_crtcs;
15826 const u32 *formats;
15830 if (INTEL_GEN(dev_priv) >= 9)
15831 return skl_universal_plane_create(dev_priv, pipe,
15834 plane = intel_plane_alloc();
15838 plane->pipe = pipe;
15840 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
15841 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
15843 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
15844 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
15846 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
15847 plane->id = PLANE_PRIMARY;
15848 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
15850 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
15851 if (plane->has_fbc) {
15852 struct intel_fbc *fbc = &dev_priv->fbc;
15854 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
15857 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15858 formats = vlv_primary_formats;
15859 num_formats = ARRAY_SIZE(vlv_primary_formats);
15860 } else if (INTEL_GEN(dev_priv) >= 4) {
15862 * WaFP16GammaEnabling:ivb
15863 * "Workaround : When using the 64-bit format, the plane
15864 * output on each color channel has one quarter amplitude.
15865 * It can be brought up to full amplitude by using pipe
15866 * gamma correction or pipe color space conversion to
15867 * multiply the plane output by four."
15869 * There is no dedicated plane gamma for the primary plane,
15870 * and using the pipe gamma/csc could conflict with other
15871 * planes, so we choose not to expose fp16 on IVB primary
15872 * planes. HSW primary planes no longer have this problem.
15874 if (IS_IVYBRIDGE(dev_priv)) {
15875 formats = ivb_primary_formats;
15876 num_formats = ARRAY_SIZE(ivb_primary_formats);
15878 formats = i965_primary_formats;
15879 num_formats = ARRAY_SIZE(i965_primary_formats);
15882 formats = i8xx_primary_formats;
15883 num_formats = ARRAY_SIZE(i8xx_primary_formats);
15886 if (INTEL_GEN(dev_priv) >= 4)
15887 plane_funcs = &i965_plane_funcs;
15889 plane_funcs = &i8xx_plane_funcs;
15891 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15892 plane->min_cdclk = vlv_plane_min_cdclk;
15893 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
15894 plane->min_cdclk = hsw_plane_min_cdclk;
15895 else if (IS_IVYBRIDGE(dev_priv))
15896 plane->min_cdclk = ivb_plane_min_cdclk;
15898 plane->min_cdclk = i9xx_plane_min_cdclk;
15900 plane->max_stride = i9xx_plane_max_stride;
15901 plane->update_plane = i9xx_update_plane;
15902 plane->disable_plane = i9xx_disable_plane;
15903 plane->get_hw_state = i9xx_plane_get_hw_state;
15904 plane->check_plane = i9xx_plane_check;
15906 possible_crtcs = BIT(pipe);
15908 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
15909 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
15910 possible_crtcs, plane_funcs,
15911 formats, num_formats,
15912 i9xx_format_modifiers,
15913 DRM_PLANE_TYPE_PRIMARY,
15914 "primary %c", pipe_name(pipe));
15916 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
15917 possible_crtcs, plane_funcs,
15918 formats, num_formats,
15919 i9xx_format_modifiers,
15920 DRM_PLANE_TYPE_PRIMARY,
15922 plane_name(plane->i9xx_plane));
15926 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
15927 supported_rotations =
15928 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
15929 DRM_MODE_REFLECT_X;
15930 } else if (INTEL_GEN(dev_priv) >= 4) {
15931 supported_rotations =
15932 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
15934 supported_rotations = DRM_MODE_ROTATE_0;
15937 if (INTEL_GEN(dev_priv) >= 4)
15938 drm_plane_create_rotation_property(&plane->base,
15940 supported_rotations);
15943 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
15945 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
15950 intel_plane_free(plane);
15952 return ERR_PTR(ret);
15955 static struct intel_plane *
15956 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
15959 unsigned int possible_crtcs;
15960 struct intel_plane *cursor;
15963 cursor = intel_plane_alloc();
15964 if (IS_ERR(cursor))
15967 cursor->pipe = pipe;
15968 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
15969 cursor->id = PLANE_CURSOR;
15970 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
15972 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15973 cursor->max_stride = i845_cursor_max_stride;
15974 cursor->update_plane = i845_update_cursor;
15975 cursor->disable_plane = i845_disable_cursor;
15976 cursor->get_hw_state = i845_cursor_get_hw_state;
15977 cursor->check_plane = i845_check_cursor;
15979 cursor->max_stride = i9xx_cursor_max_stride;
15980 cursor->update_plane = i9xx_update_cursor;
15981 cursor->disable_plane = i9xx_disable_cursor;
15982 cursor->get_hw_state = i9xx_cursor_get_hw_state;
15983 cursor->check_plane = i9xx_check_cursor;
15986 cursor->cursor.base = ~0;
15987 cursor->cursor.cntl = ~0;
15989 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
15990 cursor->cursor.size = ~0;
15992 possible_crtcs = BIT(pipe);
15994 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
15995 possible_crtcs, &intel_cursor_plane_funcs,
15996 intel_cursor_formats,
15997 ARRAY_SIZE(intel_cursor_formats),
15998 cursor_format_modifiers,
15999 DRM_PLANE_TYPE_CURSOR,
16000 "cursor %c", pipe_name(pipe));
16004 if (INTEL_GEN(dev_priv) >= 4)
16005 drm_plane_create_rotation_property(&cursor->base,
16007 DRM_MODE_ROTATE_0 |
16008 DRM_MODE_ROTATE_180);
16010 zpos = RUNTIME_INFO(dev_priv)->num_sprites[pipe] + 1;
16011 drm_plane_create_zpos_immutable_property(&cursor->base, zpos);
16013 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
16018 intel_plane_free(cursor);
16020 return ERR_PTR(ret);
16023 #define INTEL_CRTC_FUNCS \
16024 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
16025 .set_config = drm_atomic_helper_set_config, \
16026 .destroy = intel_crtc_destroy, \
16027 .page_flip = drm_atomic_helper_page_flip, \
16028 .atomic_duplicate_state = intel_crtc_duplicate_state, \
16029 .atomic_destroy_state = intel_crtc_destroy_state, \
16030 .set_crc_source = intel_crtc_set_crc_source, \
16031 .verify_crc_source = intel_crtc_verify_crc_source, \
16032 .get_crc_sources = intel_crtc_get_crc_sources
16034 static const struct drm_crtc_funcs bdw_crtc_funcs = {
16037 .get_vblank_counter = g4x_get_vblank_counter,
16038 .enable_vblank = bdw_enable_vblank,
16039 .disable_vblank = bdw_disable_vblank,
16042 static const struct drm_crtc_funcs ilk_crtc_funcs = {
16045 .get_vblank_counter = g4x_get_vblank_counter,
16046 .enable_vblank = ilk_enable_vblank,
16047 .disable_vblank = ilk_disable_vblank,
16050 static const struct drm_crtc_funcs g4x_crtc_funcs = {
16053 .get_vblank_counter = g4x_get_vblank_counter,
16054 .enable_vblank = i965_enable_vblank,
16055 .disable_vblank = i965_disable_vblank,
16058 static const struct drm_crtc_funcs i965_crtc_funcs = {
16061 .get_vblank_counter = i915_get_vblank_counter,
16062 .enable_vblank = i965_enable_vblank,
16063 .disable_vblank = i965_disable_vblank,
16066 static const struct drm_crtc_funcs i915gm_crtc_funcs = {
16069 .get_vblank_counter = i915_get_vblank_counter,
16070 .enable_vblank = i915gm_enable_vblank,
16071 .disable_vblank = i915gm_disable_vblank,
16074 static const struct drm_crtc_funcs i915_crtc_funcs = {
16077 .get_vblank_counter = i915_get_vblank_counter,
16078 .enable_vblank = i8xx_enable_vblank,
16079 .disable_vblank = i8xx_disable_vblank,
16082 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
16085 /* no hw vblank counter */
16086 .enable_vblank = i8xx_enable_vblank,
16087 .disable_vblank = i8xx_disable_vblank,
16090 static struct intel_crtc *intel_crtc_alloc(void)
16092 struct intel_crtc_state *crtc_state;
16093 struct intel_crtc *crtc;
16095 crtc = kzalloc(sizeof(*crtc), GFP_KERNEL);
16097 return ERR_PTR(-ENOMEM);
16099 crtc_state = intel_crtc_state_alloc(crtc);
16102 return ERR_PTR(-ENOMEM);
16105 crtc->base.state = &crtc_state->uapi;
16106 crtc->config = crtc_state;
16111 static void intel_crtc_free(struct intel_crtc *crtc)
16113 intel_crtc_destroy_state(&crtc->base, crtc->base.state);
16117 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
16119 struct intel_plane *primary, *cursor;
16120 const struct drm_crtc_funcs *funcs;
16121 struct intel_crtc *crtc;
16124 crtc = intel_crtc_alloc();
16126 return PTR_ERR(crtc);
16129 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[pipe];
16131 primary = intel_primary_plane_create(dev_priv, pipe);
16132 if (IS_ERR(primary)) {
16133 ret = PTR_ERR(primary);
16136 crtc->plane_ids_mask |= BIT(primary->id);
16138 for_each_sprite(dev_priv, pipe, sprite) {
16139 struct intel_plane *plane;
16141 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
16142 if (IS_ERR(plane)) {
16143 ret = PTR_ERR(plane);
16146 crtc->plane_ids_mask |= BIT(plane->id);
16149 cursor = intel_cursor_plane_create(dev_priv, pipe);
16150 if (IS_ERR(cursor)) {
16151 ret = PTR_ERR(cursor);
16154 crtc->plane_ids_mask |= BIT(cursor->id);
16156 if (HAS_GMCH(dev_priv)) {
16157 if (IS_CHERRYVIEW(dev_priv) ||
16158 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
16159 funcs = &g4x_crtc_funcs;
16160 else if (IS_GEN(dev_priv, 4))
16161 funcs = &i965_crtc_funcs;
16162 else if (IS_I945GM(dev_priv) || IS_I915GM(dev_priv))
16163 funcs = &i915gm_crtc_funcs;
16164 else if (IS_GEN(dev_priv, 3))
16165 funcs = &i915_crtc_funcs;
16167 funcs = &i8xx_crtc_funcs;
16169 if (INTEL_GEN(dev_priv) >= 8)
16170 funcs = &bdw_crtc_funcs;
16172 funcs = &ilk_crtc_funcs;
16175 ret = drm_crtc_init_with_planes(&dev_priv->drm, &crtc->base,
16176 &primary->base, &cursor->base,
16177 funcs, "pipe %c", pipe_name(pipe));
16181 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
16182 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
16183 dev_priv->pipe_to_crtc_mapping[pipe] = crtc;
16185 if (INTEL_GEN(dev_priv) < 9) {
16186 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
16188 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
16189 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
16190 dev_priv->plane_to_crtc_mapping[i9xx_plane] = crtc;
16193 intel_color_init(crtc);
16195 WARN_ON(drm_crtc_index(&crtc->base) != crtc->pipe);
16200 intel_crtc_free(crtc);
16205 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
16206 struct drm_file *file)
16208 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
16209 struct drm_crtc *drmmode_crtc;
16210 struct intel_crtc *crtc;
16212 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
16216 crtc = to_intel_crtc(drmmode_crtc);
16217 pipe_from_crtc_id->pipe = crtc->pipe;
16222 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
16224 struct drm_device *dev = encoder->base.dev;
16225 struct intel_encoder *source_encoder;
16226 u32 possible_clones = 0;
16228 for_each_intel_encoder(dev, source_encoder) {
16229 if (encoders_cloneable(encoder, source_encoder))
16230 possible_clones |= drm_encoder_mask(&source_encoder->base);
16233 return possible_clones;
16236 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
16238 struct drm_device *dev = encoder->base.dev;
16239 struct intel_crtc *crtc;
16240 u32 possible_crtcs = 0;
16242 for_each_intel_crtc(dev, crtc) {
16243 if (encoder->pipe_mask & BIT(crtc->pipe))
16244 possible_crtcs |= drm_crtc_mask(&crtc->base);
16247 return possible_crtcs;
16250 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
16252 if (!IS_MOBILE(dev_priv))
16255 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
16258 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
16264 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
16266 if (INTEL_GEN(dev_priv) >= 9)
16269 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
16272 if (HAS_PCH_LPT_H(dev_priv) &&
16273 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
16276 /* DDI E can't be used if DDI A requires 4 lanes */
16277 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
16280 if (!dev_priv->vbt.int_crt_support)
16286 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
16291 if (HAS_DDI(dev_priv))
16294 * This w/a is needed at least on CPT/PPT, but to be sure apply it
16295 * everywhere where registers can be write protected.
16297 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16302 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
16303 u32 val = I915_READ(PP_CONTROL(pps_idx));
16305 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
16306 I915_WRITE(PP_CONTROL(pps_idx), val);
16310 static void intel_pps_init(struct drm_i915_private *dev_priv)
16312 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
16313 dev_priv->pps_mmio_base = PCH_PPS_BASE;
16314 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16315 dev_priv->pps_mmio_base = VLV_PPS_BASE;
16317 dev_priv->pps_mmio_base = PPS_BASE;
16319 intel_pps_unlock_regs_wa(dev_priv);
16322 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
16324 struct intel_encoder *encoder;
16325 bool dpd_is_edp = false;
16327 intel_pps_init(dev_priv);
16329 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
16332 if (INTEL_GEN(dev_priv) >= 12) {
16333 intel_ddi_init(dev_priv, PORT_A);
16334 intel_ddi_init(dev_priv, PORT_B);
16335 intel_ddi_init(dev_priv, PORT_D);
16336 intel_ddi_init(dev_priv, PORT_E);
16337 intel_ddi_init(dev_priv, PORT_F);
16338 intel_ddi_init(dev_priv, PORT_G);
16339 intel_ddi_init(dev_priv, PORT_H);
16340 intel_ddi_init(dev_priv, PORT_I);
16341 icl_dsi_init(dev_priv);
16342 } else if (IS_ELKHARTLAKE(dev_priv)) {
16343 intel_ddi_init(dev_priv, PORT_A);
16344 intel_ddi_init(dev_priv, PORT_B);
16345 intel_ddi_init(dev_priv, PORT_C);
16346 intel_ddi_init(dev_priv, PORT_D);
16347 icl_dsi_init(dev_priv);
16348 } else if (IS_GEN(dev_priv, 11)) {
16349 intel_ddi_init(dev_priv, PORT_A);
16350 intel_ddi_init(dev_priv, PORT_B);
16351 intel_ddi_init(dev_priv, PORT_C);
16352 intel_ddi_init(dev_priv, PORT_D);
16353 intel_ddi_init(dev_priv, PORT_E);
16355 * On some ICL SKUs port F is not present. No strap bits for
16356 * this, so rely on VBT.
16357 * Work around broken VBTs on SKUs known to have no port F.
16359 if (IS_ICL_WITH_PORT_F(dev_priv) &&
16360 intel_bios_is_port_present(dev_priv, PORT_F))
16361 intel_ddi_init(dev_priv, PORT_F);
16363 icl_dsi_init(dev_priv);
16364 } else if (IS_GEN9_LP(dev_priv)) {
16366 * FIXME: Broxton doesn't support port detection via the
16367 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
16368 * detect the ports.
16370 intel_ddi_init(dev_priv, PORT_A);
16371 intel_ddi_init(dev_priv, PORT_B);
16372 intel_ddi_init(dev_priv, PORT_C);
16374 vlv_dsi_init(dev_priv);
16375 } else if (HAS_DDI(dev_priv)) {
16378 if (intel_ddi_crt_present(dev_priv))
16379 intel_crt_init(dev_priv);
16382 * Haswell uses DDI functions to detect digital outputs.
16383 * On SKL pre-D0 the strap isn't connected, so we assume
16386 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
16387 /* WaIgnoreDDIAStrap: skl */
16388 if (found || IS_GEN9_BC(dev_priv))
16389 intel_ddi_init(dev_priv, PORT_A);
16391 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
16393 found = I915_READ(SFUSE_STRAP);
16395 if (found & SFUSE_STRAP_DDIB_DETECTED)
16396 intel_ddi_init(dev_priv, PORT_B);
16397 if (found & SFUSE_STRAP_DDIC_DETECTED)
16398 intel_ddi_init(dev_priv, PORT_C);
16399 if (found & SFUSE_STRAP_DDID_DETECTED)
16400 intel_ddi_init(dev_priv, PORT_D);
16401 if (found & SFUSE_STRAP_DDIF_DETECTED)
16402 intel_ddi_init(dev_priv, PORT_F);
16404 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
16406 if (IS_GEN9_BC(dev_priv) &&
16407 intel_bios_is_port_present(dev_priv, PORT_E))
16408 intel_ddi_init(dev_priv, PORT_E);
16410 } else if (HAS_PCH_SPLIT(dev_priv)) {
16414 * intel_edp_init_connector() depends on this completing first,
16415 * to prevent the registration of both eDP and LVDS and the
16416 * incorrect sharing of the PPS.
16418 intel_lvds_init(dev_priv);
16419 intel_crt_init(dev_priv);
16421 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
16423 if (ilk_has_edp_a(dev_priv))
16424 intel_dp_init(dev_priv, DP_A, PORT_A);
16426 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
16427 /* PCH SDVOB multiplex with HDMIB */
16428 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
16430 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
16431 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
16432 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
16435 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
16436 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
16438 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
16439 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
16441 if (I915_READ(PCH_DP_C) & DP_DETECTED)
16442 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
16444 if (I915_READ(PCH_DP_D) & DP_DETECTED)
16445 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
16446 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16447 bool has_edp, has_port;
16449 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
16450 intel_crt_init(dev_priv);
16453 * The DP_DETECTED bit is the latched state of the DDC
16454 * SDA pin at boot. However since eDP doesn't require DDC
16455 * (no way to plug in a DP->HDMI dongle) the DDC pins for
16456 * eDP ports may have been muxed to an alternate function.
16457 * Thus we can't rely on the DP_DETECTED bit alone to detect
16458 * eDP ports. Consult the VBT as well as DP_DETECTED to
16459 * detect eDP ports.
16461 * Sadly the straps seem to be missing sometimes even for HDMI
16462 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
16463 * and VBT for the presence of the port. Additionally we can't
16464 * trust the port type the VBT declares as we've seen at least
16465 * HDMI ports that the VBT claim are DP or eDP.
16467 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
16468 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
16469 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
16470 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
16471 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
16472 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
16474 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
16475 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
16476 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
16477 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
16478 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
16479 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
16481 if (IS_CHERRYVIEW(dev_priv)) {
16483 * eDP not supported on port D,
16484 * so no need to worry about it
16486 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
16487 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
16488 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
16489 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
16490 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
16493 vlv_dsi_init(dev_priv);
16494 } else if (IS_PINEVIEW(dev_priv)) {
16495 intel_lvds_init(dev_priv);
16496 intel_crt_init(dev_priv);
16497 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
16498 bool found = false;
16500 if (IS_MOBILE(dev_priv))
16501 intel_lvds_init(dev_priv);
16503 intel_crt_init(dev_priv);
16505 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
16506 DRM_DEBUG_KMS("probing SDVOB\n");
16507 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
16508 if (!found && IS_G4X(dev_priv)) {
16509 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
16510 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
16513 if (!found && IS_G4X(dev_priv))
16514 intel_dp_init(dev_priv, DP_B, PORT_B);
16517 /* Before G4X SDVOC doesn't have its own detect register */
16519 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
16520 DRM_DEBUG_KMS("probing SDVOC\n");
16521 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
16524 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
16526 if (IS_G4X(dev_priv)) {
16527 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
16528 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
16530 if (IS_G4X(dev_priv))
16531 intel_dp_init(dev_priv, DP_C, PORT_C);
16534 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
16535 intel_dp_init(dev_priv, DP_D, PORT_D);
16537 if (SUPPORTS_TV(dev_priv))
16538 intel_tv_init(dev_priv);
16539 } else if (IS_GEN(dev_priv, 2)) {
16540 if (IS_I85X(dev_priv))
16541 intel_lvds_init(dev_priv);
16543 intel_crt_init(dev_priv);
16544 intel_dvo_init(dev_priv);
16547 intel_psr_init(dev_priv);
16549 for_each_intel_encoder(&dev_priv->drm, encoder) {
16550 encoder->base.possible_crtcs =
16551 intel_encoder_possible_crtcs(encoder);
16552 encoder->base.possible_clones =
16553 intel_encoder_possible_clones(encoder);
16556 intel_init_pch_refclk(dev_priv);
16558 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
16561 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
16563 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
16565 drm_framebuffer_cleanup(fb);
16566 intel_frontbuffer_put(intel_fb->frontbuffer);
16571 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
16572 struct drm_file *file,
16573 unsigned int *handle)
16575 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16577 if (obj->userptr.mm) {
16578 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
16582 return drm_gem_handle_create(file, &obj->base, handle);
16585 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
16586 struct drm_file *file,
16587 unsigned flags, unsigned color,
16588 struct drm_clip_rect *clips,
16589 unsigned num_clips)
16591 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16593 i915_gem_object_flush_if_display(obj);
16594 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
16599 static const struct drm_framebuffer_funcs intel_fb_funcs = {
16600 .destroy = intel_user_framebuffer_destroy,
16601 .create_handle = intel_user_framebuffer_create_handle,
16602 .dirty = intel_user_framebuffer_dirty,
16605 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
16606 struct drm_i915_gem_object *obj,
16607 struct drm_mode_fb_cmd2 *mode_cmd)
16609 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
16610 struct drm_framebuffer *fb = &intel_fb->base;
16612 unsigned int tiling, stride;
16616 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
16617 if (!intel_fb->frontbuffer)
16620 i915_gem_object_lock(obj);
16621 tiling = i915_gem_object_get_tiling(obj);
16622 stride = i915_gem_object_get_stride(obj);
16623 i915_gem_object_unlock(obj);
16625 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
16627 * If there's a fence, enforce that
16628 * the fb modifier and tiling mode match.
16630 if (tiling != I915_TILING_NONE &&
16631 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
16632 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
16636 if (tiling == I915_TILING_X) {
16637 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
16638 } else if (tiling == I915_TILING_Y) {
16639 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
16644 if (!drm_any_plane_has_format(&dev_priv->drm,
16645 mode_cmd->pixel_format,
16646 mode_cmd->modifier[0])) {
16647 struct drm_format_name_buf format_name;
16649 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
16650 drm_get_format_name(mode_cmd->pixel_format,
16652 mode_cmd->modifier[0]);
16657 * gen2/3 display engine uses the fence if present,
16658 * so the tiling mode must match the fb modifier exactly.
16660 if (INTEL_GEN(dev_priv) < 4 &&
16661 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
16662 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
16666 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
16667 mode_cmd->modifier[0]);
16668 if (mode_cmd->pitches[0] > max_stride) {
16669 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
16670 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
16671 "tiled" : "linear",
16672 mode_cmd->pitches[0], max_stride);
16677 * If there's a fence, enforce that
16678 * the fb pitch and fence stride match.
16680 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
16681 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
16682 mode_cmd->pitches[0], stride);
16686 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
16687 if (mode_cmd->offsets[0] != 0)
16690 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
16692 for (i = 0; i < fb->format->num_planes; i++) {
16693 u32 stride_alignment;
16695 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
16696 DRM_DEBUG_KMS("bad plane %d handle\n", i);
16700 stride_alignment = intel_fb_stride_alignment(fb, i);
16701 if (fb->pitches[i] & (stride_alignment - 1)) {
16702 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
16703 i, fb->pitches[i], stride_alignment);
16707 if (is_gen12_ccs_plane(fb, i)) {
16708 int ccs_aux_stride = gen12_ccs_aux_stride(fb, i);
16710 if (fb->pitches[i] != ccs_aux_stride) {
16711 DRM_DEBUG_KMS("ccs aux plane %d pitch (%d) must be %d\n",
16713 fb->pitches[i], ccs_aux_stride);
16718 fb->obj[i] = &obj->base;
16721 ret = intel_fill_fb_info(dev_priv, fb);
16725 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
16727 DRM_ERROR("framebuffer init failed %d\n", ret);
16734 intel_frontbuffer_put(intel_fb->frontbuffer);
16738 static struct drm_framebuffer *
16739 intel_user_framebuffer_create(struct drm_device *dev,
16740 struct drm_file *filp,
16741 const struct drm_mode_fb_cmd2 *user_mode_cmd)
16743 struct drm_framebuffer *fb;
16744 struct drm_i915_gem_object *obj;
16745 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
16747 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
16749 return ERR_PTR(-ENOENT);
16751 fb = intel_framebuffer_create(obj, &mode_cmd);
16752 i915_gem_object_put(obj);
16757 static void intel_atomic_state_free(struct drm_atomic_state *state)
16759 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
16761 drm_atomic_state_default_release(state);
16763 i915_sw_fence_fini(&intel_state->commit_ready);
16768 static enum drm_mode_status
16769 intel_mode_valid(struct drm_device *dev,
16770 const struct drm_display_mode *mode)
16772 struct drm_i915_private *dev_priv = to_i915(dev);
16773 int hdisplay_max, htotal_max;
16774 int vdisplay_max, vtotal_max;
16777 * Can't reject DBLSCAN here because Xorg ddxen can add piles
16778 * of DBLSCAN modes to the output's mode list when they detect
16779 * the scaling mode property on the connector. And they don't
16780 * ask the kernel to validate those modes in any way until
16781 * modeset time at which point the client gets a protocol error.
16782 * So in order to not upset those clients we silently ignore the
16783 * DBLSCAN flag on such connectors. For other connectors we will
16784 * reject modes with the DBLSCAN flag in encoder->compute_config().
16785 * And we always reject DBLSCAN modes in connector->mode_valid()
16786 * as we never want such modes on the connector's mode list.
16789 if (mode->vscan > 1)
16790 return MODE_NO_VSCAN;
16792 if (mode->flags & DRM_MODE_FLAG_HSKEW)
16793 return MODE_H_ILLEGAL;
16795 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
16796 DRM_MODE_FLAG_NCSYNC |
16797 DRM_MODE_FLAG_PCSYNC))
16800 if (mode->flags & (DRM_MODE_FLAG_BCAST |
16801 DRM_MODE_FLAG_PIXMUX |
16802 DRM_MODE_FLAG_CLKDIV2))
16805 /* Transcoder timing limits */
16806 if (INTEL_GEN(dev_priv) >= 11) {
16807 hdisplay_max = 16384;
16808 vdisplay_max = 8192;
16809 htotal_max = 16384;
16811 } else if (INTEL_GEN(dev_priv) >= 9 ||
16812 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
16813 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
16814 vdisplay_max = 4096;
16817 } else if (INTEL_GEN(dev_priv) >= 3) {
16818 hdisplay_max = 4096;
16819 vdisplay_max = 4096;
16823 hdisplay_max = 2048;
16824 vdisplay_max = 2048;
16829 if (mode->hdisplay > hdisplay_max ||
16830 mode->hsync_start > htotal_max ||
16831 mode->hsync_end > htotal_max ||
16832 mode->htotal > htotal_max)
16833 return MODE_H_ILLEGAL;
16835 if (mode->vdisplay > vdisplay_max ||
16836 mode->vsync_start > vtotal_max ||
16837 mode->vsync_end > vtotal_max ||
16838 mode->vtotal > vtotal_max)
16839 return MODE_V_ILLEGAL;
16841 if (INTEL_GEN(dev_priv) >= 5) {
16842 if (mode->hdisplay < 64 ||
16843 mode->htotal - mode->hdisplay < 32)
16844 return MODE_H_ILLEGAL;
16846 if (mode->vtotal - mode->vdisplay < 5)
16847 return MODE_V_ILLEGAL;
16849 if (mode->htotal - mode->hdisplay < 32)
16850 return MODE_H_ILLEGAL;
16852 if (mode->vtotal - mode->vdisplay < 3)
16853 return MODE_V_ILLEGAL;
16859 enum drm_mode_status
16860 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
16861 const struct drm_display_mode *mode)
16863 int plane_width_max, plane_height_max;
16866 * intel_mode_valid() should be
16867 * sufficient on older platforms.
16869 if (INTEL_GEN(dev_priv) < 9)
16873 * Most people will probably want a fullscreen
16874 * plane so let's not advertize modes that are
16875 * too big for that.
16877 if (INTEL_GEN(dev_priv) >= 11) {
16878 plane_width_max = 5120;
16879 plane_height_max = 4320;
16881 plane_width_max = 5120;
16882 plane_height_max = 4096;
16885 if (mode->hdisplay > plane_width_max)
16886 return MODE_H_ILLEGAL;
16888 if (mode->vdisplay > plane_height_max)
16889 return MODE_V_ILLEGAL;
16894 static const struct drm_mode_config_funcs intel_mode_funcs = {
16895 .fb_create = intel_user_framebuffer_create,
16896 .get_format_info = intel_get_format_info,
16897 .output_poll_changed = intel_fbdev_output_poll_changed,
16898 .mode_valid = intel_mode_valid,
16899 .atomic_check = intel_atomic_check,
16900 .atomic_commit = intel_atomic_commit,
16901 .atomic_state_alloc = intel_atomic_state_alloc,
16902 .atomic_state_clear = intel_atomic_state_clear,
16903 .atomic_state_free = intel_atomic_state_free,
16907 * intel_init_display_hooks - initialize the display modesetting hooks
16908 * @dev_priv: device private
16910 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
16912 intel_init_cdclk_hooks(dev_priv);
16914 if (INTEL_GEN(dev_priv) >= 9) {
16915 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
16916 dev_priv->display.get_initial_plane_config =
16917 skl_get_initial_plane_config;
16918 dev_priv->display.crtc_compute_clock = hsw_crtc_compute_clock;
16919 dev_priv->display.crtc_enable = hsw_crtc_enable;
16920 dev_priv->display.crtc_disable = hsw_crtc_disable;
16921 } else if (HAS_DDI(dev_priv)) {
16922 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
16923 dev_priv->display.get_initial_plane_config =
16924 i9xx_get_initial_plane_config;
16925 dev_priv->display.crtc_compute_clock =
16926 hsw_crtc_compute_clock;
16927 dev_priv->display.crtc_enable = hsw_crtc_enable;
16928 dev_priv->display.crtc_disable = hsw_crtc_disable;
16929 } else if (HAS_PCH_SPLIT(dev_priv)) {
16930 dev_priv->display.get_pipe_config = ilk_get_pipe_config;
16931 dev_priv->display.get_initial_plane_config =
16932 i9xx_get_initial_plane_config;
16933 dev_priv->display.crtc_compute_clock =
16934 ilk_crtc_compute_clock;
16935 dev_priv->display.crtc_enable = ilk_crtc_enable;
16936 dev_priv->display.crtc_disable = ilk_crtc_disable;
16937 } else if (IS_CHERRYVIEW(dev_priv)) {
16938 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16939 dev_priv->display.get_initial_plane_config =
16940 i9xx_get_initial_plane_config;
16941 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
16942 dev_priv->display.crtc_enable = valleyview_crtc_enable;
16943 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16944 } else if (IS_VALLEYVIEW(dev_priv)) {
16945 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16946 dev_priv->display.get_initial_plane_config =
16947 i9xx_get_initial_plane_config;
16948 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
16949 dev_priv->display.crtc_enable = valleyview_crtc_enable;
16950 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16951 } else if (IS_G4X(dev_priv)) {
16952 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16953 dev_priv->display.get_initial_plane_config =
16954 i9xx_get_initial_plane_config;
16955 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
16956 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16957 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16958 } else if (IS_PINEVIEW(dev_priv)) {
16959 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16960 dev_priv->display.get_initial_plane_config =
16961 i9xx_get_initial_plane_config;
16962 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
16963 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16964 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16965 } else if (!IS_GEN(dev_priv, 2)) {
16966 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16967 dev_priv->display.get_initial_plane_config =
16968 i9xx_get_initial_plane_config;
16969 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
16970 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16971 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16973 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16974 dev_priv->display.get_initial_plane_config =
16975 i9xx_get_initial_plane_config;
16976 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
16977 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16978 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16981 if (IS_GEN(dev_priv, 5)) {
16982 dev_priv->display.fdi_link_train = ilk_fdi_link_train;
16983 } else if (IS_GEN(dev_priv, 6)) {
16984 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
16985 } else if (IS_IVYBRIDGE(dev_priv)) {
16986 /* FIXME: detect B0+ stepping and use auto training */
16987 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
16990 if (INTEL_GEN(dev_priv) >= 9)
16991 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
16993 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
16997 void intel_modeset_init_hw(struct drm_i915_private *i915)
16999 intel_update_cdclk(i915);
17000 intel_dump_cdclk_state(&i915->cdclk.hw, "Current CDCLK");
17001 i915->cdclk.logical = i915->cdclk.actual = i915->cdclk.hw;
17005 * Calculate what we think the watermarks should be for the state we've read
17006 * out of the hardware and then immediately program those watermarks so that
17007 * we ensure the hardware settings match our internal state.
17009 * We can calculate what we think WM's should be by creating a duplicate of the
17010 * current state (which was constructed during hardware readout) and running it
17011 * through the atomic check code to calculate new watermark values in the
17014 static void sanitize_watermarks(struct drm_device *dev)
17016 struct drm_i915_private *dev_priv = to_i915(dev);
17017 struct drm_atomic_state *state;
17018 struct intel_atomic_state *intel_state;
17019 struct intel_crtc *crtc;
17020 struct intel_crtc_state *crtc_state;
17021 struct drm_modeset_acquire_ctx ctx;
17025 /* Only supported on platforms that use atomic watermark design */
17026 if (!dev_priv->display.optimize_watermarks)
17030 * We need to hold connection_mutex before calling duplicate_state so
17031 * that the connector loop is protected.
17033 drm_modeset_acquire_init(&ctx, 0);
17035 ret = drm_modeset_lock_all_ctx(dev, &ctx);
17036 if (ret == -EDEADLK) {
17037 drm_modeset_backoff(&ctx);
17039 } else if (WARN_ON(ret)) {
17043 state = drm_atomic_helper_duplicate_state(dev, &ctx);
17044 if (WARN_ON(IS_ERR(state)))
17047 intel_state = to_intel_atomic_state(state);
17050 * Hardware readout is the only time we don't want to calculate
17051 * intermediate watermarks (since we don't trust the current
17054 if (!HAS_GMCH(dev_priv))
17055 intel_state->skip_intermediate_wm = true;
17057 ret = intel_atomic_check(dev, state);
17060 * If we fail here, it means that the hardware appears to be
17061 * programmed in a way that shouldn't be possible, given our
17062 * understanding of watermark requirements. This might mean a
17063 * mistake in the hardware readout code or a mistake in the
17064 * watermark calculations for a given platform. Raise a WARN
17065 * so that this is noticeable.
17067 * If this actually happens, we'll have to just leave the
17068 * BIOS-programmed watermarks untouched and hope for the best.
17070 WARN(true, "Could not determine valid watermarks for inherited state\n");
17074 /* Write calculated watermark values back */
17075 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
17076 crtc_state->wm.need_postvbl_update = true;
17077 dev_priv->display.optimize_watermarks(intel_state, crtc);
17079 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
17083 drm_atomic_state_put(state);
17085 drm_modeset_drop_locks(&ctx);
17086 drm_modeset_acquire_fini(&ctx);
17089 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
17091 if (IS_GEN(dev_priv, 5)) {
17093 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
17095 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
17096 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
17097 dev_priv->fdi_pll_freq = 270000;
17102 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
17105 static int intel_initial_commit(struct drm_device *dev)
17107 struct drm_atomic_state *state = NULL;
17108 struct drm_modeset_acquire_ctx ctx;
17109 struct intel_crtc *crtc;
17112 state = drm_atomic_state_alloc(dev);
17116 drm_modeset_acquire_init(&ctx, 0);
17119 state->acquire_ctx = &ctx;
17121 for_each_intel_crtc(dev, crtc) {
17122 struct intel_crtc_state *crtc_state =
17123 intel_atomic_get_crtc_state(state, crtc);
17125 if (IS_ERR(crtc_state)) {
17126 ret = PTR_ERR(crtc_state);
17130 if (crtc_state->hw.active) {
17131 ret = drm_atomic_add_affected_planes(state, &crtc->base);
17136 * FIXME hack to force a LUT update to avoid the
17137 * plane update forcing the pipe gamma on without
17138 * having a proper LUT loaded. Remove once we
17139 * have readout for pipe gamma enable.
17141 crtc_state->uapi.color_mgmt_changed = true;
17145 ret = drm_atomic_commit(state);
17148 if (ret == -EDEADLK) {
17149 drm_atomic_state_clear(state);
17150 drm_modeset_backoff(&ctx);
17154 drm_atomic_state_put(state);
17156 drm_modeset_drop_locks(&ctx);
17157 drm_modeset_acquire_fini(&ctx);
17162 static void intel_mode_config_init(struct drm_i915_private *i915)
17164 struct drm_mode_config *mode_config = &i915->drm.mode_config;
17166 drm_mode_config_init(&i915->drm);
17168 mode_config->min_width = 0;
17169 mode_config->min_height = 0;
17171 mode_config->preferred_depth = 24;
17172 mode_config->prefer_shadow = 1;
17174 mode_config->allow_fb_modifiers = true;
17176 mode_config->funcs = &intel_mode_funcs;
17179 * Maximum framebuffer dimensions, chosen to match
17180 * the maximum render engine surface size on gen4+.
17182 if (INTEL_GEN(i915) >= 7) {
17183 mode_config->max_width = 16384;
17184 mode_config->max_height = 16384;
17185 } else if (INTEL_GEN(i915) >= 4) {
17186 mode_config->max_width = 8192;
17187 mode_config->max_height = 8192;
17188 } else if (IS_GEN(i915, 3)) {
17189 mode_config->max_width = 4096;
17190 mode_config->max_height = 4096;
17192 mode_config->max_width = 2048;
17193 mode_config->max_height = 2048;
17196 if (IS_I845G(i915) || IS_I865G(i915)) {
17197 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
17198 mode_config->cursor_height = 1023;
17199 } else if (IS_GEN(i915, 2)) {
17200 mode_config->cursor_width = 64;
17201 mode_config->cursor_height = 64;
17203 mode_config->cursor_width = 256;
17204 mode_config->cursor_height = 256;
17208 int intel_modeset_init(struct drm_i915_private *i915)
17210 struct drm_device *dev = &i915->drm;
17212 struct intel_crtc *crtc;
17215 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
17216 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
17217 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
17219 intel_mode_config_init(i915);
17221 ret = intel_bw_init(i915);
17225 init_llist_head(&i915->atomic_helper.free_list);
17226 INIT_WORK(&i915->atomic_helper.free_work,
17227 intel_atomic_helper_free_state_worker);
17229 intel_init_quirks(i915);
17231 intel_fbc_init(i915);
17233 intel_init_pm(i915);
17235 intel_panel_sanitize_ssc(i915);
17237 intel_gmbus_setup(i915);
17239 DRM_DEBUG_KMS("%d display pipe%s available.\n",
17240 INTEL_NUM_PIPES(i915),
17241 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
17243 if (HAS_DISPLAY(i915) && INTEL_DISPLAY_ENABLED(i915)) {
17244 for_each_pipe(i915, pipe) {
17245 ret = intel_crtc_init(i915, pipe);
17247 drm_mode_config_cleanup(dev);
17253 intel_shared_dpll_init(dev);
17254 intel_update_fdi_pll_freq(i915);
17256 intel_update_czclk(i915);
17257 intel_modeset_init_hw(i915);
17259 intel_hdcp_component_init(i915);
17261 if (i915->max_cdclk_freq == 0)
17262 intel_update_max_cdclk(i915);
17264 /* Just disable it once at startup */
17265 intel_vga_disable(i915);
17266 intel_setup_outputs(i915);
17268 drm_modeset_lock_all(dev);
17269 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
17270 drm_modeset_unlock_all(dev);
17272 for_each_intel_crtc(dev, crtc) {
17273 struct intel_initial_plane_config plane_config = {};
17279 * Note that reserving the BIOS fb up front prevents us
17280 * from stuffing other stolen allocations like the ring
17281 * on top. This prevents some ugliness at boot time, and
17282 * can even allow for smooth boot transitions if the BIOS
17283 * fb is large enough for the active pipe configuration.
17285 i915->display.get_initial_plane_config(crtc, &plane_config);
17288 * If the fb is shared between multiple heads, we'll
17289 * just get the first one.
17291 intel_find_initial_plane_obj(crtc, &plane_config);
17295 * Make sure hardware watermarks really match the state we read out.
17296 * Note that we need to do this after reconstructing the BIOS fb's
17297 * since the watermark calculation done here will use pstate->fb.
17299 if (!HAS_GMCH(i915))
17300 sanitize_watermarks(dev);
17303 * Force all active planes to recompute their states. So that on
17304 * mode_setcrtc after probe, all the intel_plane_state variables
17305 * are already calculated and there is no assert_plane warnings
17308 ret = intel_initial_commit(dev);
17310 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
17315 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17317 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17318 /* 640x480@60Hz, ~25175 kHz */
17319 struct dpll clock = {
17329 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
17331 DRM_DEBUG_KMS("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 I915_WRITE(FP0(pipe), fp);
17343 I915_WRITE(FP1(pipe), fp);
17345 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
17346 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
17347 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
17348 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
17349 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
17350 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
17351 I915_WRITE(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 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
17359 I915_WRITE(DPLL(pipe), dpll);
17361 /* Wait for the clocks to stabilize. */
17362 POSTING_READ(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 I915_WRITE(DPLL(pipe), dpll);
17372 /* We do this three times for luck */
17373 for (i = 0; i < 3 ; i++) {
17374 I915_WRITE(DPLL(pipe), dpll);
17375 POSTING_READ(DPLL(pipe));
17376 udelay(150); /* wait for warmup */
17379 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
17380 POSTING_READ(PIPECONF(pipe));
17382 intel_wait_for_pipe_scanline_moving(crtc);
17385 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17387 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17389 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
17392 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
17393 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
17394 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
17395 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
17396 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
17398 I915_WRITE(PIPECONF(pipe), 0);
17399 POSTING_READ(PIPECONF(pipe));
17401 intel_wait_for_pipe_scanline_stopped(crtc);
17403 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
17404 POSTING_READ(DPLL(pipe));
17408 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
17410 struct intel_crtc *crtc;
17412 if (INTEL_GEN(dev_priv) >= 4)
17415 for_each_intel_crtc(&dev_priv->drm, crtc) {
17416 struct intel_plane *plane =
17417 to_intel_plane(crtc->base.primary);
17418 struct intel_crtc *plane_crtc;
17421 if (!plane->get_hw_state(plane, &pipe))
17424 if (pipe == crtc->pipe)
17427 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
17428 plane->base.base.id, plane->base.name);
17430 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17431 intel_plane_disable_noatomic(plane_crtc, plane);
17435 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
17437 struct drm_device *dev = crtc->base.dev;
17438 struct intel_encoder *encoder;
17440 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
17446 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
17448 struct drm_device *dev = encoder->base.dev;
17449 struct intel_connector *connector;
17451 for_each_connector_on_encoder(dev, &encoder->base, connector)
17457 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
17458 enum pipe pch_transcoder)
17460 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
17461 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
17464 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state *crtc_state)
17466 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
17467 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
17468 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
17470 if (INTEL_GEN(dev_priv) >= 9 ||
17471 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
17472 i915_reg_t reg = CHICKEN_TRANS(cpu_transcoder);
17475 if (transcoder_is_dsi(cpu_transcoder))
17478 val = I915_READ(reg);
17479 val &= ~HSW_FRAME_START_DELAY_MASK;
17480 val |= HSW_FRAME_START_DELAY(0);
17481 I915_WRITE(reg, val);
17483 i915_reg_t reg = PIPECONF(cpu_transcoder);
17486 val = I915_READ(reg);
17487 val &= ~PIPECONF_FRAME_START_DELAY_MASK;
17488 val |= PIPECONF_FRAME_START_DELAY(0);
17489 I915_WRITE(reg, val);
17492 if (!crtc_state->has_pch_encoder)
17495 if (HAS_PCH_IBX(dev_priv)) {
17496 i915_reg_t reg = PCH_TRANSCONF(crtc->pipe);
17499 val = I915_READ(reg);
17500 val &= ~TRANS_FRAME_START_DELAY_MASK;
17501 val |= TRANS_FRAME_START_DELAY(0);
17502 I915_WRITE(reg, val);
17504 enum pipe pch_transcoder = intel_crtc_pch_transcoder(crtc);
17505 i915_reg_t reg = TRANS_CHICKEN2(pch_transcoder);
17508 val = I915_READ(reg);
17509 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
17510 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
17511 I915_WRITE(reg, val);
17515 static void intel_sanitize_crtc(struct intel_crtc *crtc,
17516 struct drm_modeset_acquire_ctx *ctx)
17518 struct drm_device *dev = crtc->base.dev;
17519 struct drm_i915_private *dev_priv = to_i915(dev);
17520 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
17522 if (crtc_state->hw.active) {
17523 struct intel_plane *plane;
17525 /* Clear any frame start delays used for debugging left by the BIOS */
17526 intel_sanitize_frame_start_delay(crtc_state);
17528 /* Disable everything but the primary plane */
17529 for_each_intel_plane_on_crtc(dev, crtc, plane) {
17530 const struct intel_plane_state *plane_state =
17531 to_intel_plane_state(plane->base.state);
17533 if (plane_state->uapi.visible &&
17534 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
17535 intel_plane_disable_noatomic(crtc, plane);
17539 * Disable any background color set by the BIOS, but enable the
17540 * gamma and CSC to match how we program our planes.
17542 if (INTEL_GEN(dev_priv) >= 9)
17543 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
17544 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
17545 SKL_BOTTOM_COLOR_CSC_ENABLE);
17548 /* Adjust the state of the output pipe according to whether we
17549 * have active connectors/encoders. */
17550 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc))
17551 intel_crtc_disable_noatomic(crtc, ctx);
17553 if (crtc_state->hw.active || HAS_GMCH(dev_priv)) {
17555 * We start out with underrun reporting disabled to avoid races.
17556 * For correct bookkeeping mark this on active crtcs.
17558 * Also on gmch platforms we dont have any hardware bits to
17559 * disable the underrun reporting. Which means we need to start
17560 * out with underrun reporting disabled also on inactive pipes,
17561 * since otherwise we'll complain about the garbage we read when
17562 * e.g. coming up after runtime pm.
17564 * No protection against concurrent access is required - at
17565 * worst a fifo underrun happens which also sets this to false.
17567 crtc->cpu_fifo_underrun_disabled = true;
17569 * We track the PCH trancoder underrun reporting state
17570 * within the crtc. With crtc for pipe A housing the underrun
17571 * reporting state for PCH transcoder A, crtc for pipe B housing
17572 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
17573 * and marking underrun reporting as disabled for the non-existing
17574 * PCH transcoders B and C would prevent enabling the south
17575 * error interrupt (see cpt_can_enable_serr_int()).
17577 if (has_pch_trancoder(dev_priv, crtc->pipe))
17578 crtc->pch_fifo_underrun_disabled = true;
17582 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
17584 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
17587 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
17588 * the hardware when a high res displays plugged in. DPLL P
17589 * divider is zero, and the pipe timings are bonkers. We'll
17590 * try to disable everything in that case.
17592 * FIXME would be nice to be able to sanitize this state
17593 * without several WARNs, but for now let's take the easy
17596 return IS_GEN(dev_priv, 6) &&
17597 crtc_state->hw.active &&
17598 crtc_state->shared_dpll &&
17599 crtc_state->port_clock == 0;
17602 static void intel_sanitize_encoder(struct intel_encoder *encoder)
17604 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
17605 struct intel_connector *connector;
17606 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
17607 struct intel_crtc_state *crtc_state = crtc ?
17608 to_intel_crtc_state(crtc->base.state) : NULL;
17610 /* We need to check both for a crtc link (meaning that the
17611 * encoder is active and trying to read from a pipe) and the
17612 * pipe itself being active. */
17613 bool has_active_crtc = crtc_state &&
17614 crtc_state->hw.active;
17616 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
17617 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
17618 pipe_name(crtc->pipe));
17619 has_active_crtc = false;
17622 connector = intel_encoder_find_connector(encoder);
17623 if (connector && !has_active_crtc) {
17624 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
17625 encoder->base.base.id,
17626 encoder->base.name);
17628 /* Connector is active, but has no active pipe. This is
17629 * fallout from our resume register restoring. Disable
17630 * the encoder manually again. */
17632 struct drm_encoder *best_encoder;
17634 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
17635 encoder->base.base.id,
17636 encoder->base.name);
17638 /* avoid oopsing in case the hooks consult best_encoder */
17639 best_encoder = connector->base.state->best_encoder;
17640 connector->base.state->best_encoder = &encoder->base;
17642 if (encoder->disable)
17643 encoder->disable(encoder, crtc_state,
17644 connector->base.state);
17645 if (encoder->post_disable)
17646 encoder->post_disable(encoder, crtc_state,
17647 connector->base.state);
17649 connector->base.state->best_encoder = best_encoder;
17651 encoder->base.crtc = NULL;
17653 /* Inconsistent output/port/pipe state happens presumably due to
17654 * a bug in one of the get_hw_state functions. Or someplace else
17655 * in our code, like the register restore mess on resume. Clamp
17656 * things to off as a safer default. */
17658 connector->base.dpms = DRM_MODE_DPMS_OFF;
17659 connector->base.encoder = NULL;
17662 /* notify opregion of the sanitized encoder state */
17663 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
17665 if (INTEL_GEN(dev_priv) >= 11)
17666 icl_sanitize_encoder_pll_mapping(encoder);
17669 /* FIXME read out full plane state for all planes */
17670 static void readout_plane_state(struct drm_i915_private *dev_priv)
17672 struct intel_plane *plane;
17673 struct intel_crtc *crtc;
17675 for_each_intel_plane(&dev_priv->drm, plane) {
17676 struct intel_plane_state *plane_state =
17677 to_intel_plane_state(plane->base.state);
17678 struct intel_crtc_state *crtc_state;
17679 enum pipe pipe = PIPE_A;
17682 visible = plane->get_hw_state(plane, &pipe);
17684 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17685 crtc_state = to_intel_crtc_state(crtc->base.state);
17687 intel_set_plane_visible(crtc_state, plane_state, visible);
17689 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
17690 plane->base.base.id, plane->base.name,
17691 enableddisabled(visible), pipe_name(pipe));
17694 for_each_intel_crtc(&dev_priv->drm, crtc) {
17695 struct intel_crtc_state *crtc_state =
17696 to_intel_crtc_state(crtc->base.state);
17698 fixup_active_planes(crtc_state);
17702 static void intel_modeset_readout_hw_state(struct drm_device *dev)
17704 struct drm_i915_private *dev_priv = to_i915(dev);
17706 struct intel_crtc *crtc;
17707 struct intel_encoder *encoder;
17708 struct intel_connector *connector;
17709 struct drm_connector_list_iter conn_iter;
17712 dev_priv->active_pipes = 0;
17714 for_each_intel_crtc(dev, crtc) {
17715 struct intel_crtc_state *crtc_state =
17716 to_intel_crtc_state(crtc->base.state);
17718 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
17719 intel_crtc_free_hw_state(crtc_state);
17720 intel_crtc_state_reset(crtc_state, crtc);
17722 crtc_state->hw.active = crtc_state->hw.enable =
17723 dev_priv->display.get_pipe_config(crtc, crtc_state);
17725 crtc->base.enabled = crtc_state->hw.enable;
17726 crtc->active = crtc_state->hw.active;
17728 if (crtc_state->hw.active)
17729 dev_priv->active_pipes |= BIT(crtc->pipe);
17731 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
17732 crtc->base.base.id, crtc->base.name,
17733 enableddisabled(crtc_state->hw.active));
17736 readout_plane_state(dev_priv);
17738 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
17739 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
17741 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
17742 &pll->state.hw_state);
17744 if (IS_ELKHARTLAKE(dev_priv) && pll->on &&
17745 pll->info->id == DPLL_ID_EHL_DPLL4) {
17746 pll->wakeref = intel_display_power_get(dev_priv,
17747 POWER_DOMAIN_DPLL_DC_OFF);
17750 pll->state.crtc_mask = 0;
17751 for_each_intel_crtc(dev, crtc) {
17752 struct intel_crtc_state *crtc_state =
17753 to_intel_crtc_state(crtc->base.state);
17755 if (crtc_state->hw.active &&
17756 crtc_state->shared_dpll == pll)
17757 pll->state.crtc_mask |= 1 << crtc->pipe;
17759 pll->active_mask = pll->state.crtc_mask;
17761 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
17762 pll->info->name, pll->state.crtc_mask, pll->on);
17765 for_each_intel_encoder(dev, encoder) {
17768 if (encoder->get_hw_state(encoder, &pipe)) {
17769 struct intel_crtc_state *crtc_state;
17771 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17772 crtc_state = to_intel_crtc_state(crtc->base.state);
17774 encoder->base.crtc = &crtc->base;
17775 encoder->get_config(encoder, crtc_state);
17777 encoder->base.crtc = NULL;
17780 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
17781 encoder->base.base.id, encoder->base.name,
17782 enableddisabled(encoder->base.crtc),
17786 drm_connector_list_iter_begin(dev, &conn_iter);
17787 for_each_intel_connector_iter(connector, &conn_iter) {
17788 if (connector->get_hw_state(connector)) {
17789 struct intel_crtc_state *crtc_state;
17790 struct intel_crtc *crtc;
17792 connector->base.dpms = DRM_MODE_DPMS_ON;
17794 encoder = connector->encoder;
17795 connector->base.encoder = &encoder->base;
17797 crtc = to_intel_crtc(encoder->base.crtc);
17798 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
17800 if (crtc_state && crtc_state->hw.active) {
17802 * This has to be done during hardware readout
17803 * because anything calling .crtc_disable may
17804 * rely on the connector_mask being accurate.
17806 crtc_state->uapi.connector_mask |=
17807 drm_connector_mask(&connector->base);
17808 crtc_state->uapi.encoder_mask |=
17809 drm_encoder_mask(&encoder->base);
17812 connector->base.dpms = DRM_MODE_DPMS_OFF;
17813 connector->base.encoder = NULL;
17815 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
17816 connector->base.base.id, connector->base.name,
17817 enableddisabled(connector->base.encoder));
17819 drm_connector_list_iter_end(&conn_iter);
17821 for_each_intel_crtc(dev, crtc) {
17822 struct intel_bw_state *bw_state =
17823 to_intel_bw_state(dev_priv->bw_obj.state);
17824 struct intel_crtc_state *crtc_state =
17825 to_intel_crtc_state(crtc->base.state);
17826 struct intel_plane *plane;
17829 if (crtc_state->hw.active) {
17830 struct drm_display_mode *mode = &crtc_state->hw.mode;
17832 intel_mode_from_pipe_config(&crtc_state->hw.adjusted_mode,
17835 *mode = crtc_state->hw.adjusted_mode;
17836 mode->hdisplay = crtc_state->pipe_src_w;
17837 mode->vdisplay = crtc_state->pipe_src_h;
17840 * The initial mode needs to be set in order to keep
17841 * the atomic core happy. It wants a valid mode if the
17842 * crtc's enabled, so we do the above call.
17844 * But we don't set all the derived state fully, hence
17845 * set a flag to indicate that a full recalculation is
17846 * needed on the next commit.
17848 mode->private_flags = I915_MODE_FLAG_INHERITED;
17850 intel_crtc_compute_pixel_rate(crtc_state);
17852 intel_crtc_update_active_timings(crtc_state);
17854 intel_crtc_copy_hw_to_uapi_state(crtc_state);
17857 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
17858 const struct intel_plane_state *plane_state =
17859 to_intel_plane_state(plane->base.state);
17862 * FIXME don't have the fb yet, so can't
17863 * use intel_plane_data_rate() :(
17865 if (plane_state->uapi.visible)
17866 crtc_state->data_rate[plane->id] =
17867 4 * crtc_state->pixel_rate;
17869 * FIXME don't have the fb yet, so can't
17870 * use plane->min_cdclk() :(
17872 if (plane_state->uapi.visible && plane->min_cdclk) {
17873 if (crtc_state->double_wide ||
17874 INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
17875 crtc_state->min_cdclk[plane->id] =
17876 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
17878 crtc_state->min_cdclk[plane->id] =
17879 crtc_state->pixel_rate;
17881 DRM_DEBUG_KMS("[PLANE:%d:%s] min_cdclk %d kHz\n",
17882 plane->base.base.id, plane->base.name,
17883 crtc_state->min_cdclk[plane->id]);
17886 if (crtc_state->hw.active) {
17887 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
17888 if (WARN_ON(min_cdclk < 0))
17892 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
17893 dev_priv->min_voltage_level[crtc->pipe] =
17894 crtc_state->min_voltage_level;
17896 intel_bw_crtc_update(bw_state, crtc_state);
17898 intel_pipe_config_sanity_check(dev_priv, crtc_state);
17903 get_encoder_power_domains(struct drm_i915_private *dev_priv)
17905 struct intel_encoder *encoder;
17907 for_each_intel_encoder(&dev_priv->drm, encoder) {
17908 struct intel_crtc_state *crtc_state;
17910 if (!encoder->get_power_domains)
17914 * MST-primary and inactive encoders don't have a crtc state
17915 * and neither of these require any power domain references.
17917 if (!encoder->base.crtc)
17920 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
17921 encoder->get_power_domains(encoder, crtc_state);
17925 static void intel_early_display_was(struct drm_i915_private *dev_priv)
17928 * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl
17929 * Also known as Wa_14010480278.
17931 if (IS_GEN_RANGE(dev_priv, 10, 12) || IS_GEMINILAKE(dev_priv))
17932 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
17935 if (IS_HASWELL(dev_priv)) {
17937 * WaRsPkgCStateDisplayPMReq:hsw
17938 * System hang if this isn't done before disabling all planes!
17940 I915_WRITE(CHICKEN_PAR1_1,
17941 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
17945 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
17946 enum port port, i915_reg_t hdmi_reg)
17948 u32 val = I915_READ(hdmi_reg);
17950 if (val & SDVO_ENABLE ||
17951 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
17954 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
17957 val &= ~SDVO_PIPE_SEL_MASK;
17958 val |= SDVO_PIPE_SEL(PIPE_A);
17960 I915_WRITE(hdmi_reg, val);
17963 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
17964 enum port port, i915_reg_t dp_reg)
17966 u32 val = I915_READ(dp_reg);
17968 if (val & DP_PORT_EN ||
17969 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
17972 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
17975 val &= ~DP_PIPE_SEL_MASK;
17976 val |= DP_PIPE_SEL(PIPE_A);
17978 I915_WRITE(dp_reg, val);
17981 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
17984 * The BIOS may select transcoder B on some of the PCH
17985 * ports even it doesn't enable the port. This would trip
17986 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
17987 * Sanitize the transcoder select bits to prevent that. We
17988 * assume that the BIOS never actually enabled the port,
17989 * because if it did we'd actually have to toggle the port
17990 * on and back off to make the transcoder A select stick
17991 * (see. intel_dp_link_down(), intel_disable_hdmi(),
17992 * intel_disable_sdvo()).
17994 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
17995 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
17996 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
17998 /* PCH SDVOB multiplex with HDMIB */
17999 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
18000 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
18001 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
18004 /* Scan out the current hw modeset state,
18005 * and sanitizes it to the current state
18008 intel_modeset_setup_hw_state(struct drm_device *dev,
18009 struct drm_modeset_acquire_ctx *ctx)
18011 struct drm_i915_private *dev_priv = to_i915(dev);
18012 struct intel_encoder *encoder;
18013 struct intel_crtc *crtc;
18014 intel_wakeref_t wakeref;
18017 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
18019 intel_early_display_was(dev_priv);
18020 intel_modeset_readout_hw_state(dev);
18022 /* HW state is read out, now we need to sanitize this mess. */
18024 /* Sanitize the TypeC port mode upfront, encoders depend on this */
18025 for_each_intel_encoder(dev, encoder) {
18026 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
18028 /* We need to sanitize only the MST primary port. */
18029 if (encoder->type != INTEL_OUTPUT_DP_MST &&
18030 intel_phy_is_tc(dev_priv, phy))
18031 intel_tc_port_sanitize(enc_to_dig_port(&encoder->base));
18034 get_encoder_power_domains(dev_priv);
18036 if (HAS_PCH_IBX(dev_priv))
18037 ibx_sanitize_pch_ports(dev_priv);
18040 * intel_sanitize_plane_mapping() may need to do vblank
18041 * waits, so we need vblank interrupts restored beforehand.
18043 for_each_intel_crtc(&dev_priv->drm, crtc) {
18044 struct intel_crtc_state *crtc_state =
18045 to_intel_crtc_state(crtc->base.state);
18047 drm_crtc_vblank_reset(&crtc->base);
18049 if (crtc_state->hw.active)
18050 intel_crtc_vblank_on(crtc_state);
18053 intel_sanitize_plane_mapping(dev_priv);
18055 for_each_intel_encoder(dev, encoder)
18056 intel_sanitize_encoder(encoder);
18058 for_each_intel_crtc(&dev_priv->drm, crtc) {
18059 struct intel_crtc_state *crtc_state =
18060 to_intel_crtc_state(crtc->base.state);
18062 intel_sanitize_crtc(crtc, ctx);
18063 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
18066 intel_modeset_update_connector_atomic_state(dev);
18068 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
18069 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
18071 if (!pll->on || pll->active_mask)
18074 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
18077 pll->info->funcs->disable(dev_priv, pll);
18081 if (IS_G4X(dev_priv)) {
18082 g4x_wm_get_hw_state(dev_priv);
18083 g4x_wm_sanitize(dev_priv);
18084 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
18085 vlv_wm_get_hw_state(dev_priv);
18086 vlv_wm_sanitize(dev_priv);
18087 } else if (INTEL_GEN(dev_priv) >= 9) {
18088 skl_wm_get_hw_state(dev_priv);
18089 } else if (HAS_PCH_SPLIT(dev_priv)) {
18090 ilk_wm_get_hw_state(dev_priv);
18093 for_each_intel_crtc(dev, crtc) {
18094 struct intel_crtc_state *crtc_state =
18095 to_intel_crtc_state(crtc->base.state);
18098 put_domains = modeset_get_crtc_power_domains(crtc_state);
18099 if (WARN_ON(put_domains))
18100 modeset_put_power_domains(dev_priv, put_domains);
18103 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
18106 void intel_display_resume(struct drm_device *dev)
18108 struct drm_i915_private *dev_priv = to_i915(dev);
18109 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
18110 struct drm_modeset_acquire_ctx ctx;
18113 dev_priv->modeset_restore_state = NULL;
18115 state->acquire_ctx = &ctx;
18117 drm_modeset_acquire_init(&ctx, 0);
18120 ret = drm_modeset_lock_all_ctx(dev, &ctx);
18121 if (ret != -EDEADLK)
18124 drm_modeset_backoff(&ctx);
18128 ret = __intel_display_resume(dev, state, &ctx);
18130 intel_enable_ipc(dev_priv);
18131 drm_modeset_drop_locks(&ctx);
18132 drm_modeset_acquire_fini(&ctx);
18135 DRM_ERROR("Restoring old state failed with %i\n", ret);
18137 drm_atomic_state_put(state);
18140 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
18142 struct intel_connector *connector;
18143 struct drm_connector_list_iter conn_iter;
18145 /* Kill all the work that may have been queued by hpd. */
18146 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
18147 for_each_intel_connector_iter(connector, &conn_iter) {
18148 if (connector->modeset_retry_work.func)
18149 cancel_work_sync(&connector->modeset_retry_work);
18150 if (connector->hdcp.shim) {
18151 cancel_delayed_work_sync(&connector->hdcp.check_work);
18152 cancel_work_sync(&connector->hdcp.prop_work);
18155 drm_connector_list_iter_end(&conn_iter);
18158 void intel_modeset_driver_remove(struct drm_i915_private *i915)
18160 flush_workqueue(i915->flip_wq);
18161 flush_workqueue(i915->modeset_wq);
18163 flush_work(&i915->atomic_helper.free_work);
18164 WARN_ON(!llist_empty(&i915->atomic_helper.free_list));
18167 * Interrupts and polling as the first thing to avoid creating havoc.
18168 * Too much stuff here (turning of connectors, ...) would
18169 * experience fancy races otherwise.
18171 intel_irq_uninstall(i915);
18174 * Due to the hpd irq storm handling the hotplug work can re-arm the
18175 * poll handlers. Hence disable polling after hpd handling is shut down.
18177 intel_hpd_poll_fini(i915);
18180 * MST topology needs to be suspended so we don't have any calls to
18181 * fbdev after it's finalized. MST will be destroyed later as part of
18182 * drm_mode_config_cleanup()
18184 intel_dp_mst_suspend(i915);
18186 /* poll work can call into fbdev, hence clean that up afterwards */
18187 intel_fbdev_fini(i915);
18189 intel_unregister_dsm_handler();
18191 intel_fbc_global_disable(i915);
18193 /* flush any delayed tasks or pending work */
18194 flush_scheduled_work();
18196 intel_hdcp_component_fini(i915);
18198 drm_mode_config_cleanup(&i915->drm);
18200 intel_overlay_cleanup(i915);
18202 intel_gmbus_teardown(i915);
18204 intel_bw_cleanup(i915);
18206 destroy_workqueue(i915->flip_wq);
18207 destroy_workqueue(i915->modeset_wq);
18209 intel_fbc_cleanup_cfb(i915);
18212 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
18214 struct intel_display_error_state {
18216 u32 power_well_driver;
18218 struct intel_cursor_error_state {
18223 } cursor[I915_MAX_PIPES];
18225 struct intel_pipe_error_state {
18226 bool power_domain_on;
18229 } pipe[I915_MAX_PIPES];
18231 struct intel_plane_error_state {
18239 } plane[I915_MAX_PIPES];
18241 struct intel_transcoder_error_state {
18243 bool power_domain_on;
18244 enum transcoder cpu_transcoder;
18257 struct intel_display_error_state *
18258 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
18260 struct intel_display_error_state *error;
18261 int transcoders[] = {
18270 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
18272 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
18275 error = kzalloc(sizeof(*error), GFP_ATOMIC);
18279 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18280 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
18282 for_each_pipe(dev_priv, i) {
18283 error->pipe[i].power_domain_on =
18284 __intel_display_power_is_enabled(dev_priv,
18285 POWER_DOMAIN_PIPE(i));
18286 if (!error->pipe[i].power_domain_on)
18289 error->cursor[i].control = I915_READ(CURCNTR(i));
18290 error->cursor[i].position = I915_READ(CURPOS(i));
18291 error->cursor[i].base = I915_READ(CURBASE(i));
18293 error->plane[i].control = I915_READ(DSPCNTR(i));
18294 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
18295 if (INTEL_GEN(dev_priv) <= 3) {
18296 error->plane[i].size = I915_READ(DSPSIZE(i));
18297 error->plane[i].pos = I915_READ(DSPPOS(i));
18299 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18300 error->plane[i].addr = I915_READ(DSPADDR(i));
18301 if (INTEL_GEN(dev_priv) >= 4) {
18302 error->plane[i].surface = I915_READ(DSPSURF(i));
18303 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
18306 error->pipe[i].source = I915_READ(PIPESRC(i));
18308 if (HAS_GMCH(dev_priv))
18309 error->pipe[i].stat = I915_READ(PIPESTAT(i));
18312 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18313 enum transcoder cpu_transcoder = transcoders[i];
18315 if (!INTEL_INFO(dev_priv)->trans_offsets[cpu_transcoder])
18318 error->transcoder[i].available = true;
18319 error->transcoder[i].power_domain_on =
18320 __intel_display_power_is_enabled(dev_priv,
18321 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
18322 if (!error->transcoder[i].power_domain_on)
18325 error->transcoder[i].cpu_transcoder = cpu_transcoder;
18327 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
18328 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
18329 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
18330 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
18331 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
18332 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
18333 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
18339 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
18342 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
18343 struct intel_display_error_state *error)
18345 struct drm_i915_private *dev_priv = m->i915;
18351 err_printf(m, "Num Pipes: %d\n", INTEL_NUM_PIPES(dev_priv));
18352 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18353 err_printf(m, "PWR_WELL_CTL2: %08x\n",
18354 error->power_well_driver);
18355 for_each_pipe(dev_priv, i) {
18356 err_printf(m, "Pipe [%d]:\n", i);
18357 err_printf(m, " Power: %s\n",
18358 onoff(error->pipe[i].power_domain_on));
18359 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
18360 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
18362 err_printf(m, "Plane [%d]:\n", i);
18363 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
18364 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
18365 if (INTEL_GEN(dev_priv) <= 3) {
18366 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
18367 err_printf(m, " POS: %08x\n", error->plane[i].pos);
18369 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18370 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
18371 if (INTEL_GEN(dev_priv) >= 4) {
18372 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
18373 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
18376 err_printf(m, "Cursor [%d]:\n", i);
18377 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
18378 err_printf(m, " POS: %08x\n", error->cursor[i].position);
18379 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
18382 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18383 if (!error->transcoder[i].available)
18386 err_printf(m, "CPU transcoder: %s\n",
18387 transcoder_name(error->transcoder[i].cpu_transcoder));
18388 err_printf(m, " Power: %s\n",
18389 onoff(error->transcoder[i].power_domain_on));
18390 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
18391 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
18392 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
18393 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
18394 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
18395 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
18396 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);