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_dsi.h"
50 #include "display/intel_dvo.h"
51 #include "display/intel_gmbus.h"
52 #include "display/intel_hdmi.h"
53 #include "display/intel_lvds.h"
54 #include "display/intel_sdvo.h"
55 #include "display/intel_tv.h"
56 #include "display/intel_vdsc.h"
58 #include "gt/intel_rps.h"
61 #include "i915_trace.h"
62 #include "intel_acpi.h"
63 #include "intel_atomic.h"
64 #include "intel_atomic_plane.h"
66 #include "intel_cdclk.h"
67 #include "intel_color.h"
68 #include "intel_display_types.h"
69 #include "intel_dp_link_training.h"
70 #include "intel_fbc.h"
71 #include "intel_fbdev.h"
72 #include "intel_fifo_underrun.h"
73 #include "intel_frontbuffer.h"
74 #include "intel_hdcp.h"
75 #include "intel_hotplug.h"
76 #include "intel_overlay.h"
77 #include "intel_pipe_crc.h"
79 #include "intel_psr.h"
80 #include "intel_quirks.h"
81 #include "intel_sideband.h"
82 #include "intel_sprite.h"
84 #include "intel_vga.h"
86 /* Primary plane formats for gen <= 3 */
87 static const u32 i8xx_primary_formats[] = {
94 /* Primary plane formats for ivb (no fp16 due to hw issue) */
95 static const u32 ivb_primary_formats[] = {
100 DRM_FORMAT_XRGB2101010,
101 DRM_FORMAT_XBGR2101010,
104 /* Primary plane formats for gen >= 4, except ivb */
105 static const u32 i965_primary_formats[] = {
110 DRM_FORMAT_XRGB2101010,
111 DRM_FORMAT_XBGR2101010,
112 DRM_FORMAT_XBGR16161616F,
115 /* Primary plane formats for vlv/chv */
116 static const u32 vlv_primary_formats[] = {
123 DRM_FORMAT_XRGB2101010,
124 DRM_FORMAT_XBGR2101010,
125 DRM_FORMAT_ARGB2101010,
126 DRM_FORMAT_ABGR2101010,
127 DRM_FORMAT_XBGR16161616F,
130 static const u64 i9xx_format_modifiers[] = {
131 I915_FORMAT_MOD_X_TILED,
132 DRM_FORMAT_MOD_LINEAR,
133 DRM_FORMAT_MOD_INVALID
137 static const u32 intel_cursor_formats[] = {
141 static const u64 cursor_format_modifiers[] = {
142 DRM_FORMAT_MOD_LINEAR,
143 DRM_FORMAT_MOD_INVALID
146 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
147 struct intel_crtc_state *pipe_config);
148 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
149 struct intel_crtc_state *pipe_config);
151 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
152 struct drm_i915_gem_object *obj,
153 struct drm_mode_fb_cmd2 *mode_cmd);
154 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
155 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
156 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
157 const struct intel_link_m_n *m_n,
158 const struct intel_link_m_n *m2_n2);
159 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
160 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
161 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
162 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
163 static void vlv_prepare_pll(struct intel_crtc *crtc,
164 const struct intel_crtc_state *pipe_config);
165 static void chv_prepare_pll(struct intel_crtc *crtc,
166 const struct intel_crtc_state *pipe_config);
167 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
168 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
169 static void intel_modeset_setup_hw_state(struct drm_device *dev,
170 struct drm_modeset_acquire_ctx *ctx);
171 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc);
176 } dot, vco, n, m, m1, m2, p, p1;
180 int p2_slow, p2_fast;
184 /* returns HPLL frequency in kHz */
185 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
187 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
189 /* Obtain SKU information */
190 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
191 CCK_FUSE_HPLL_FREQ_MASK;
193 return vco_freq[hpll_freq] * 1000;
196 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
197 const char *name, u32 reg, int ref_freq)
202 val = vlv_cck_read(dev_priv, reg);
203 divider = val & CCK_FREQUENCY_VALUES;
205 WARN((val & CCK_FREQUENCY_STATUS) !=
206 (divider << CCK_FREQUENCY_STATUS_SHIFT),
207 "%s change in progress\n", name);
209 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
212 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
213 const char *name, u32 reg)
217 vlv_cck_get(dev_priv);
219 if (dev_priv->hpll_freq == 0)
220 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
222 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
224 vlv_cck_put(dev_priv);
229 static void intel_update_czclk(struct drm_i915_private *dev_priv)
231 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
234 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
235 CCK_CZ_CLOCK_CONTROL);
237 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
240 static inline u32 /* units of 100MHz */
241 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
242 const struct intel_crtc_state *pipe_config)
244 if (HAS_DDI(dev_priv))
245 return pipe_config->port_clock; /* SPLL */
247 return dev_priv->fdi_pll_freq;
250 static const struct intel_limit intel_limits_i8xx_dac = {
251 .dot = { .min = 25000, .max = 350000 },
252 .vco = { .min = 908000, .max = 1512000 },
253 .n = { .min = 2, .max = 16 },
254 .m = { .min = 96, .max = 140 },
255 .m1 = { .min = 18, .max = 26 },
256 .m2 = { .min = 6, .max = 16 },
257 .p = { .min = 4, .max = 128 },
258 .p1 = { .min = 2, .max = 33 },
259 .p2 = { .dot_limit = 165000,
260 .p2_slow = 4, .p2_fast = 2 },
263 static const struct intel_limit intel_limits_i8xx_dvo = {
264 .dot = { .min = 25000, .max = 350000 },
265 .vco = { .min = 908000, .max = 1512000 },
266 .n = { .min = 2, .max = 16 },
267 .m = { .min = 96, .max = 140 },
268 .m1 = { .min = 18, .max = 26 },
269 .m2 = { .min = 6, .max = 16 },
270 .p = { .min = 4, .max = 128 },
271 .p1 = { .min = 2, .max = 33 },
272 .p2 = { .dot_limit = 165000,
273 .p2_slow = 4, .p2_fast = 4 },
276 static const struct intel_limit intel_limits_i8xx_lvds = {
277 .dot = { .min = 25000, .max = 350000 },
278 .vco = { .min = 908000, .max = 1512000 },
279 .n = { .min = 2, .max = 16 },
280 .m = { .min = 96, .max = 140 },
281 .m1 = { .min = 18, .max = 26 },
282 .m2 = { .min = 6, .max = 16 },
283 .p = { .min = 4, .max = 128 },
284 .p1 = { .min = 1, .max = 6 },
285 .p2 = { .dot_limit = 165000,
286 .p2_slow = 14, .p2_fast = 7 },
289 static const struct intel_limit intel_limits_i9xx_sdvo = {
290 .dot = { .min = 20000, .max = 400000 },
291 .vco = { .min = 1400000, .max = 2800000 },
292 .n = { .min = 1, .max = 6 },
293 .m = { .min = 70, .max = 120 },
294 .m1 = { .min = 8, .max = 18 },
295 .m2 = { .min = 3, .max = 7 },
296 .p = { .min = 5, .max = 80 },
297 .p1 = { .min = 1, .max = 8 },
298 .p2 = { .dot_limit = 200000,
299 .p2_slow = 10, .p2_fast = 5 },
302 static const struct intel_limit intel_limits_i9xx_lvds = {
303 .dot = { .min = 20000, .max = 400000 },
304 .vco = { .min = 1400000, .max = 2800000 },
305 .n = { .min = 1, .max = 6 },
306 .m = { .min = 70, .max = 120 },
307 .m1 = { .min = 8, .max = 18 },
308 .m2 = { .min = 3, .max = 7 },
309 .p = { .min = 7, .max = 98 },
310 .p1 = { .min = 1, .max = 8 },
311 .p2 = { .dot_limit = 112000,
312 .p2_slow = 14, .p2_fast = 7 },
316 static const struct intel_limit intel_limits_g4x_sdvo = {
317 .dot = { .min = 25000, .max = 270000 },
318 .vco = { .min = 1750000, .max = 3500000},
319 .n = { .min = 1, .max = 4 },
320 .m = { .min = 104, .max = 138 },
321 .m1 = { .min = 17, .max = 23 },
322 .m2 = { .min = 5, .max = 11 },
323 .p = { .min = 10, .max = 30 },
324 .p1 = { .min = 1, .max = 3},
325 .p2 = { .dot_limit = 270000,
331 static const struct intel_limit intel_limits_g4x_hdmi = {
332 .dot = { .min = 22000, .max = 400000 },
333 .vco = { .min = 1750000, .max = 3500000},
334 .n = { .min = 1, .max = 4 },
335 .m = { .min = 104, .max = 138 },
336 .m1 = { .min = 16, .max = 23 },
337 .m2 = { .min = 5, .max = 11 },
338 .p = { .min = 5, .max = 80 },
339 .p1 = { .min = 1, .max = 8},
340 .p2 = { .dot_limit = 165000,
341 .p2_slow = 10, .p2_fast = 5 },
344 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
345 .dot = { .min = 20000, .max = 115000 },
346 .vco = { .min = 1750000, .max = 3500000 },
347 .n = { .min = 1, .max = 3 },
348 .m = { .min = 104, .max = 138 },
349 .m1 = { .min = 17, .max = 23 },
350 .m2 = { .min = 5, .max = 11 },
351 .p = { .min = 28, .max = 112 },
352 .p1 = { .min = 2, .max = 8 },
353 .p2 = { .dot_limit = 0,
354 .p2_slow = 14, .p2_fast = 14
358 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
359 .dot = { .min = 80000, .max = 224000 },
360 .vco = { .min = 1750000, .max = 3500000 },
361 .n = { .min = 1, .max = 3 },
362 .m = { .min = 104, .max = 138 },
363 .m1 = { .min = 17, .max = 23 },
364 .m2 = { .min = 5, .max = 11 },
365 .p = { .min = 14, .max = 42 },
366 .p1 = { .min = 2, .max = 6 },
367 .p2 = { .dot_limit = 0,
368 .p2_slow = 7, .p2_fast = 7
372 static const struct intel_limit intel_limits_pineview_sdvo = {
373 .dot = { .min = 20000, .max = 400000},
374 .vco = { .min = 1700000, .max = 3500000 },
375 /* Pineview's Ncounter is a ring counter */
376 .n = { .min = 3, .max = 6 },
377 .m = { .min = 2, .max = 256 },
378 /* Pineview only has one combined m divider, which we treat as m2. */
379 .m1 = { .min = 0, .max = 0 },
380 .m2 = { .min = 0, .max = 254 },
381 .p = { .min = 5, .max = 80 },
382 .p1 = { .min = 1, .max = 8 },
383 .p2 = { .dot_limit = 200000,
384 .p2_slow = 10, .p2_fast = 5 },
387 static const struct intel_limit intel_limits_pineview_lvds = {
388 .dot = { .min = 20000, .max = 400000 },
389 .vco = { .min = 1700000, .max = 3500000 },
390 .n = { .min = 3, .max = 6 },
391 .m = { .min = 2, .max = 256 },
392 .m1 = { .min = 0, .max = 0 },
393 .m2 = { .min = 0, .max = 254 },
394 .p = { .min = 7, .max = 112 },
395 .p1 = { .min = 1, .max = 8 },
396 .p2 = { .dot_limit = 112000,
397 .p2_slow = 14, .p2_fast = 14 },
400 /* Ironlake / Sandybridge
402 * We calculate clock using (register_value + 2) for N/M1/M2, so here
403 * the range value for them is (actual_value - 2).
405 static const struct intel_limit intel_limits_ironlake_dac = {
406 .dot = { .min = 25000, .max = 350000 },
407 .vco = { .min = 1760000, .max = 3510000 },
408 .n = { .min = 1, .max = 5 },
409 .m = { .min = 79, .max = 127 },
410 .m1 = { .min = 12, .max = 22 },
411 .m2 = { .min = 5, .max = 9 },
412 .p = { .min = 5, .max = 80 },
413 .p1 = { .min = 1, .max = 8 },
414 .p2 = { .dot_limit = 225000,
415 .p2_slow = 10, .p2_fast = 5 },
418 static const struct intel_limit intel_limits_ironlake_single_lvds = {
419 .dot = { .min = 25000, .max = 350000 },
420 .vco = { .min = 1760000, .max = 3510000 },
421 .n = { .min = 1, .max = 3 },
422 .m = { .min = 79, .max = 118 },
423 .m1 = { .min = 12, .max = 22 },
424 .m2 = { .min = 5, .max = 9 },
425 .p = { .min = 28, .max = 112 },
426 .p1 = { .min = 2, .max = 8 },
427 .p2 = { .dot_limit = 225000,
428 .p2_slow = 14, .p2_fast = 14 },
431 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
432 .dot = { .min = 25000, .max = 350000 },
433 .vco = { .min = 1760000, .max = 3510000 },
434 .n = { .min = 1, .max = 3 },
435 .m = { .min = 79, .max = 127 },
436 .m1 = { .min = 12, .max = 22 },
437 .m2 = { .min = 5, .max = 9 },
438 .p = { .min = 14, .max = 56 },
439 .p1 = { .min = 2, .max = 8 },
440 .p2 = { .dot_limit = 225000,
441 .p2_slow = 7, .p2_fast = 7 },
444 /* LVDS 100mhz refclk limits. */
445 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
446 .dot = { .min = 25000, .max = 350000 },
447 .vco = { .min = 1760000, .max = 3510000 },
448 .n = { .min = 1, .max = 2 },
449 .m = { .min = 79, .max = 126 },
450 .m1 = { .min = 12, .max = 22 },
451 .m2 = { .min = 5, .max = 9 },
452 .p = { .min = 28, .max = 112 },
453 .p1 = { .min = 2, .max = 8 },
454 .p2 = { .dot_limit = 225000,
455 .p2_slow = 14, .p2_fast = 14 },
458 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
459 .dot = { .min = 25000, .max = 350000 },
460 .vco = { .min = 1760000, .max = 3510000 },
461 .n = { .min = 1, .max = 3 },
462 .m = { .min = 79, .max = 126 },
463 .m1 = { .min = 12, .max = 22 },
464 .m2 = { .min = 5, .max = 9 },
465 .p = { .min = 14, .max = 42 },
466 .p1 = { .min = 2, .max = 6 },
467 .p2 = { .dot_limit = 225000,
468 .p2_slow = 7, .p2_fast = 7 },
471 static const struct intel_limit intel_limits_vlv = {
473 * These are the data rate limits (measured in fast clocks)
474 * since those are the strictest limits we have. The fast
475 * clock and actual rate limits are more relaxed, so checking
476 * them would make no difference.
478 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
479 .vco = { .min = 4000000, .max = 6000000 },
480 .n = { .min = 1, .max = 7 },
481 .m1 = { .min = 2, .max = 3 },
482 .m2 = { .min = 11, .max = 156 },
483 .p1 = { .min = 2, .max = 3 },
484 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
487 static const struct intel_limit intel_limits_chv = {
489 * These are the data rate limits (measured in fast clocks)
490 * since those are the strictest limits we have. The fast
491 * clock and actual rate limits are more relaxed, so checking
492 * them would make no difference.
494 .dot = { .min = 25000 * 5, .max = 540000 * 5},
495 .vco = { .min = 4800000, .max = 6480000 },
496 .n = { .min = 1, .max = 1 },
497 .m1 = { .min = 2, .max = 2 },
498 .m2 = { .min = 24 << 22, .max = 175 << 22 },
499 .p1 = { .min = 2, .max = 4 },
500 .p2 = { .p2_slow = 1, .p2_fast = 14 },
503 static const struct intel_limit intel_limits_bxt = {
504 /* FIXME: find real dot limits */
505 .dot = { .min = 0, .max = INT_MAX },
506 .vco = { .min = 4800000, .max = 6700000 },
507 .n = { .min = 1, .max = 1 },
508 .m1 = { .min = 2, .max = 2 },
509 /* FIXME: find real m2 limits */
510 .m2 = { .min = 2 << 22, .max = 255 << 22 },
511 .p1 = { .min = 2, .max = 4 },
512 .p2 = { .p2_slow = 1, .p2_fast = 20 },
515 /* WA Display #0827: Gen9:all */
517 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
520 I915_WRITE(CLKGATE_DIS_PSL(pipe),
521 I915_READ(CLKGATE_DIS_PSL(pipe)) |
522 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
524 I915_WRITE(CLKGATE_DIS_PSL(pipe),
525 I915_READ(CLKGATE_DIS_PSL(pipe)) &
526 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
529 /* Wa_2006604312:icl */
531 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
535 I915_WRITE(CLKGATE_DIS_PSL(pipe),
536 I915_READ(CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
538 I915_WRITE(CLKGATE_DIS_PSL(pipe),
539 I915_READ(CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
543 needs_modeset(const struct intel_crtc_state *state)
545 return drm_atomic_crtc_needs_modeset(&state->uapi);
549 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
551 return (crtc_state->master_transcoder != INVALID_TRANSCODER ||
552 crtc_state->sync_mode_slaves_mask);
556 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
558 return (crtc_state->master_transcoder == INVALID_TRANSCODER &&
559 crtc_state->sync_mode_slaves_mask);
563 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
565 return crtc_state->master_transcoder != INVALID_TRANSCODER;
569 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
570 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
571 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
572 * The helpers' return value is the rate of the clock that is fed to the
573 * display engine's pipe which can be the above fast dot clock rate or a
574 * divided-down version of it.
576 /* m1 is reserved as 0 in Pineview, n is a ring counter */
577 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
579 clock->m = clock->m2 + 2;
580 clock->p = clock->p1 * clock->p2;
581 if (WARN_ON(clock->n == 0 || clock->p == 0))
583 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
584 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
589 static u32 i9xx_dpll_compute_m(struct dpll *dpll)
591 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
594 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
596 clock->m = i9xx_dpll_compute_m(clock);
597 clock->p = clock->p1 * clock->p2;
598 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
600 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
601 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
606 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
608 clock->m = clock->m1 * clock->m2;
609 clock->p = clock->p1 * clock->p2;
610 if (WARN_ON(clock->n == 0 || clock->p == 0))
612 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
613 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
615 return clock->dot / 5;
618 int chv_calc_dpll_params(int refclk, struct dpll *clock)
620 clock->m = clock->m1 * clock->m2;
621 clock->p = clock->p1 * clock->p2;
622 if (WARN_ON(clock->n == 0 || clock->p == 0))
624 clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
626 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
628 return clock->dot / 5;
631 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
634 * Returns whether the given set of divisors are valid for a given refclk with
635 * the given connectors.
637 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
638 const struct intel_limit *limit,
639 const struct dpll *clock)
641 if (clock->n < limit->n.min || limit->n.max < clock->n)
642 INTELPllInvalid("n out of range\n");
643 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
644 INTELPllInvalid("p1 out of range\n");
645 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
646 INTELPllInvalid("m2 out of range\n");
647 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
648 INTELPllInvalid("m1 out of range\n");
650 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
651 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
652 if (clock->m1 <= clock->m2)
653 INTELPllInvalid("m1 <= m2\n");
655 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
656 !IS_GEN9_LP(dev_priv)) {
657 if (clock->p < limit->p.min || limit->p.max < clock->p)
658 INTELPllInvalid("p out of range\n");
659 if (clock->m < limit->m.min || limit->m.max < clock->m)
660 INTELPllInvalid("m out of range\n");
663 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
664 INTELPllInvalid("vco out of range\n");
665 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
666 * connector, etc., rather than just a single range.
668 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
669 INTELPllInvalid("dot out of range\n");
675 i9xx_select_p2_div(const struct intel_limit *limit,
676 const struct intel_crtc_state *crtc_state,
679 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
681 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
683 * For LVDS just rely on its current settings for dual-channel.
684 * We haven't figured out how to reliably set up different
685 * single/dual channel state, if we even can.
687 if (intel_is_dual_link_lvds(dev_priv))
688 return limit->p2.p2_fast;
690 return limit->p2.p2_slow;
692 if (target < limit->p2.dot_limit)
693 return limit->p2.p2_slow;
695 return limit->p2.p2_fast;
700 * Returns a set of divisors for the desired target clock with the given
701 * refclk, or FALSE. The returned values represent the clock equation:
702 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
704 * Target and reference clocks are specified in kHz.
706 * If match_clock is provided, then best_clock P divider must match the P
707 * divider from @match_clock used for LVDS downclocking.
710 i9xx_find_best_dpll(const struct intel_limit *limit,
711 struct intel_crtc_state *crtc_state,
712 int target, int refclk, struct dpll *match_clock,
713 struct dpll *best_clock)
715 struct drm_device *dev = crtc_state->uapi.crtc->dev;
719 memset(best_clock, 0, sizeof(*best_clock));
721 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
723 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
725 for (clock.m2 = limit->m2.min;
726 clock.m2 <= limit->m2.max; clock.m2++) {
727 if (clock.m2 >= clock.m1)
729 for (clock.n = limit->n.min;
730 clock.n <= limit->n.max; clock.n++) {
731 for (clock.p1 = limit->p1.min;
732 clock.p1 <= limit->p1.max; clock.p1++) {
735 i9xx_calc_dpll_params(refclk, &clock);
736 if (!intel_PLL_is_valid(to_i915(dev),
741 clock.p != match_clock->p)
744 this_err = abs(clock.dot - target);
745 if (this_err < err) {
754 return (err != target);
758 * Returns a set of divisors for the desired target clock with the given
759 * refclk, or FALSE. The returned values represent the clock equation:
760 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
762 * Target and reference clocks are specified in kHz.
764 * If match_clock is provided, then best_clock P divider must match the P
765 * divider from @match_clock used for LVDS downclocking.
768 pnv_find_best_dpll(const struct intel_limit *limit,
769 struct intel_crtc_state *crtc_state,
770 int target, int refclk, struct dpll *match_clock,
771 struct dpll *best_clock)
773 struct drm_device *dev = crtc_state->uapi.crtc->dev;
777 memset(best_clock, 0, sizeof(*best_clock));
779 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
781 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
783 for (clock.m2 = limit->m2.min;
784 clock.m2 <= limit->m2.max; clock.m2++) {
785 for (clock.n = limit->n.min;
786 clock.n <= limit->n.max; clock.n++) {
787 for (clock.p1 = limit->p1.min;
788 clock.p1 <= limit->p1.max; clock.p1++) {
791 pnv_calc_dpll_params(refclk, &clock);
792 if (!intel_PLL_is_valid(to_i915(dev),
797 clock.p != match_clock->p)
800 this_err = abs(clock.dot - target);
801 if (this_err < err) {
810 return (err != target);
814 * Returns a set of divisors for the desired target clock with the given
815 * refclk, or FALSE. The returned values represent the clock equation:
816 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
818 * Target and reference clocks are specified in kHz.
820 * If match_clock is provided, then best_clock P divider must match the P
821 * divider from @match_clock used for LVDS downclocking.
824 g4x_find_best_dpll(const struct intel_limit *limit,
825 struct intel_crtc_state *crtc_state,
826 int target, int refclk, struct dpll *match_clock,
827 struct dpll *best_clock)
829 struct drm_device *dev = crtc_state->uapi.crtc->dev;
833 /* approximately equals target * 0.00585 */
834 int err_most = (target >> 8) + (target >> 9);
836 memset(best_clock, 0, sizeof(*best_clock));
838 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
840 max_n = limit->n.max;
841 /* based on hardware requirement, prefer smaller n to precision */
842 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
843 /* based on hardware requirement, prefere larger m1,m2 */
844 for (clock.m1 = limit->m1.max;
845 clock.m1 >= limit->m1.min; clock.m1--) {
846 for (clock.m2 = limit->m2.max;
847 clock.m2 >= limit->m2.min; clock.m2--) {
848 for (clock.p1 = limit->p1.max;
849 clock.p1 >= limit->p1.min; clock.p1--) {
852 i9xx_calc_dpll_params(refclk, &clock);
853 if (!intel_PLL_is_valid(to_i915(dev),
858 this_err = abs(clock.dot - target);
859 if (this_err < err_most) {
873 * Check if the calculated PLL configuration is more optimal compared to the
874 * best configuration and error found so far. Return the calculated error.
876 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
877 const struct dpll *calculated_clock,
878 const struct dpll *best_clock,
879 unsigned int best_error_ppm,
880 unsigned int *error_ppm)
883 * For CHV ignore the error and consider only the P value.
884 * Prefer a bigger P value based on HW requirements.
886 if (IS_CHERRYVIEW(to_i915(dev))) {
889 return calculated_clock->p > best_clock->p;
892 if (WARN_ON_ONCE(!target_freq))
895 *error_ppm = div_u64(1000000ULL *
896 abs(target_freq - calculated_clock->dot),
899 * Prefer a better P value over a better (smaller) error if the error
900 * is small. Ensure this preference for future configurations too by
901 * setting the error to 0.
903 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
909 return *error_ppm + 10 < best_error_ppm;
913 * Returns a set of divisors for the desired target clock with the given
914 * refclk, or FALSE. The returned values represent the clock equation:
915 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
918 vlv_find_best_dpll(const struct intel_limit *limit,
919 struct intel_crtc_state *crtc_state,
920 int target, int refclk, struct dpll *match_clock,
921 struct dpll *best_clock)
923 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
924 struct drm_device *dev = crtc->base.dev;
926 unsigned int bestppm = 1000000;
927 /* min update 19.2 MHz */
928 int max_n = min(limit->n.max, refclk / 19200);
931 target *= 5; /* fast clock */
933 memset(best_clock, 0, sizeof(*best_clock));
935 /* based on hardware requirement, prefer smaller n to precision */
936 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
937 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
938 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
939 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
940 clock.p = clock.p1 * clock.p2;
941 /* based on hardware requirement, prefer bigger m1,m2 values */
942 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
945 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
948 vlv_calc_dpll_params(refclk, &clock);
950 if (!intel_PLL_is_valid(to_i915(dev),
955 if (!vlv_PLL_is_optimal(dev, target,
973 * Returns a set of divisors for the desired target clock with the given
974 * refclk, or FALSE. The returned values represent the clock equation:
975 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
978 chv_find_best_dpll(const struct intel_limit *limit,
979 struct intel_crtc_state *crtc_state,
980 int target, int refclk, struct dpll *match_clock,
981 struct dpll *best_clock)
983 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
984 struct drm_device *dev = crtc->base.dev;
985 unsigned int best_error_ppm;
990 memset(best_clock, 0, sizeof(*best_clock));
991 best_error_ppm = 1000000;
994 * Based on hardware doc, the n always set to 1, and m1 always
995 * set to 2. If requires to support 200Mhz refclk, we need to
996 * revisit this because n may not 1 anymore.
998 clock.n = 1, clock.m1 = 2;
999 target *= 5; /* fast clock */
1001 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
1002 for (clock.p2 = limit->p2.p2_fast;
1003 clock.p2 >= limit->p2.p2_slow;
1004 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
1005 unsigned int error_ppm;
1007 clock.p = clock.p1 * clock.p2;
1009 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
1012 if (m2 > INT_MAX/clock.m1)
1017 chv_calc_dpll_params(refclk, &clock);
1019 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
1022 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
1023 best_error_ppm, &error_ppm))
1026 *best_clock = clock;
1027 best_error_ppm = error_ppm;
1035 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
1036 struct dpll *best_clock)
1038 int refclk = 100000;
1039 const struct intel_limit *limit = &intel_limits_bxt;
1041 return chv_find_best_dpll(limit, crtc_state,
1042 crtc_state->port_clock, refclk,
1046 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1049 i915_reg_t reg = PIPEDSL(pipe);
1053 if (IS_GEN(dev_priv, 2))
1054 line_mask = DSL_LINEMASK_GEN2;
1056 line_mask = DSL_LINEMASK_GEN3;
1058 line1 = I915_READ(reg) & line_mask;
1060 line2 = I915_READ(reg) & line_mask;
1062 return line1 != line2;
1065 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1067 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1068 enum pipe pipe = crtc->pipe;
1070 /* Wait for the display line to settle/start moving */
1071 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1072 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1073 pipe_name(pipe), onoff(state));
1076 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1078 wait_for_pipe_scanline_moving(crtc, false);
1081 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1083 wait_for_pipe_scanline_moving(crtc, true);
1087 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1089 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1090 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1092 if (INTEL_GEN(dev_priv) >= 4) {
1093 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1094 i915_reg_t reg = PIPECONF(cpu_transcoder);
1096 /* Wait for the Pipe State to go off */
1097 if (intel_de_wait_for_clear(dev_priv, reg,
1098 I965_PIPECONF_ACTIVE, 100))
1099 WARN(1, "pipe_off wait timed out\n");
1101 intel_wait_for_pipe_scanline_stopped(crtc);
1105 /* Only for pre-ILK configs */
1106 void assert_pll(struct drm_i915_private *dev_priv,
1107 enum pipe pipe, bool state)
1112 val = I915_READ(DPLL(pipe));
1113 cur_state = !!(val & DPLL_VCO_ENABLE);
1114 I915_STATE_WARN(cur_state != state,
1115 "PLL state assertion failure (expected %s, current %s)\n",
1116 onoff(state), onoff(cur_state));
1119 /* XXX: the dsi pll is shared between MIPI DSI ports */
1120 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1125 vlv_cck_get(dev_priv);
1126 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1127 vlv_cck_put(dev_priv);
1129 cur_state = val & DSI_PLL_VCO_EN;
1130 I915_STATE_WARN(cur_state != state,
1131 "DSI PLL state assertion failure (expected %s, current %s)\n",
1132 onoff(state), onoff(cur_state));
1135 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1136 enum pipe pipe, bool state)
1140 if (HAS_DDI(dev_priv)) {
1142 * DDI does not have a specific FDI_TX register.
1144 * FDI is never fed from EDP transcoder
1145 * so pipe->transcoder cast is fine here.
1147 enum transcoder cpu_transcoder = (enum transcoder)pipe;
1148 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1149 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1151 u32 val = I915_READ(FDI_TX_CTL(pipe));
1152 cur_state = !!(val & FDI_TX_ENABLE);
1154 I915_STATE_WARN(cur_state != state,
1155 "FDI TX state assertion failure (expected %s, current %s)\n",
1156 onoff(state), onoff(cur_state));
1158 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1159 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1161 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1162 enum pipe pipe, bool state)
1167 val = I915_READ(FDI_RX_CTL(pipe));
1168 cur_state = !!(val & FDI_RX_ENABLE);
1169 I915_STATE_WARN(cur_state != state,
1170 "FDI RX state assertion failure (expected %s, current %s)\n",
1171 onoff(state), onoff(cur_state));
1173 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1174 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1176 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1181 /* ILK FDI PLL is always enabled */
1182 if (IS_GEN(dev_priv, 5))
1185 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1186 if (HAS_DDI(dev_priv))
1189 val = I915_READ(FDI_TX_CTL(pipe));
1190 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1193 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1194 enum pipe pipe, bool state)
1199 val = I915_READ(FDI_RX_CTL(pipe));
1200 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1201 I915_STATE_WARN(cur_state != state,
1202 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1203 onoff(state), onoff(cur_state));
1206 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1210 enum pipe panel_pipe = INVALID_PIPE;
1213 if (WARN_ON(HAS_DDI(dev_priv)))
1216 if (HAS_PCH_SPLIT(dev_priv)) {
1219 pp_reg = PP_CONTROL(0);
1220 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1223 case PANEL_PORT_SELECT_LVDS:
1224 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1226 case PANEL_PORT_SELECT_DPA:
1227 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1229 case PANEL_PORT_SELECT_DPC:
1230 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1232 case PANEL_PORT_SELECT_DPD:
1233 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1236 MISSING_CASE(port_sel);
1239 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1240 /* presumably write lock depends on pipe, not port select */
1241 pp_reg = PP_CONTROL(pipe);
1246 pp_reg = PP_CONTROL(0);
1247 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1249 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1250 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1253 val = I915_READ(pp_reg);
1254 if (!(val & PANEL_POWER_ON) ||
1255 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1258 I915_STATE_WARN(panel_pipe == pipe && locked,
1259 "panel assertion failure, pipe %c regs locked\n",
1263 void assert_pipe(struct drm_i915_private *dev_priv,
1264 enum transcoder cpu_transcoder, bool state)
1267 enum intel_display_power_domain power_domain;
1268 intel_wakeref_t wakeref;
1270 /* we keep both pipes enabled on 830 */
1271 if (IS_I830(dev_priv))
1274 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1275 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1277 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1278 cur_state = !!(val & PIPECONF_ENABLE);
1280 intel_display_power_put(dev_priv, power_domain, wakeref);
1285 I915_STATE_WARN(cur_state != state,
1286 "transcoder %s assertion failure (expected %s, current %s)\n",
1287 transcoder_name(cpu_transcoder),
1288 onoff(state), onoff(cur_state));
1291 static void assert_plane(struct intel_plane *plane, bool state)
1296 cur_state = plane->get_hw_state(plane, &pipe);
1298 I915_STATE_WARN(cur_state != state,
1299 "%s assertion failure (expected %s, current %s)\n",
1300 plane->base.name, onoff(state), onoff(cur_state));
1303 #define assert_plane_enabled(p) assert_plane(p, true)
1304 #define assert_plane_disabled(p) assert_plane(p, false)
1306 static void assert_planes_disabled(struct intel_crtc *crtc)
1308 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1309 struct intel_plane *plane;
1311 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1312 assert_plane_disabled(plane);
1315 static void assert_vblank_disabled(struct drm_crtc *crtc)
1317 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1318 drm_crtc_vblank_put(crtc);
1321 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1327 val = I915_READ(PCH_TRANSCONF(pipe));
1328 enabled = !!(val & TRANS_ENABLE);
1329 I915_STATE_WARN(enabled,
1330 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1334 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1335 enum pipe pipe, enum port port,
1338 enum pipe port_pipe;
1341 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1343 I915_STATE_WARN(state && port_pipe == pipe,
1344 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1345 port_name(port), pipe_name(pipe));
1347 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1348 "IBX PCH DP %c still using transcoder B\n",
1352 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1353 enum pipe pipe, enum port port,
1354 i915_reg_t hdmi_reg)
1356 enum pipe port_pipe;
1359 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1361 I915_STATE_WARN(state && port_pipe == pipe,
1362 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1363 port_name(port), pipe_name(pipe));
1365 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1366 "IBX PCH HDMI %c still using transcoder B\n",
1370 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1373 enum pipe port_pipe;
1375 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1376 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1377 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1379 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1381 "PCH VGA enabled on transcoder %c, should be disabled\n",
1384 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1386 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1389 /* PCH SDVOB multiplex with HDMIB */
1390 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1391 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1392 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1395 static void _vlv_enable_pll(struct intel_crtc *crtc,
1396 const struct intel_crtc_state *pipe_config)
1398 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1399 enum pipe pipe = crtc->pipe;
1401 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1402 POSTING_READ(DPLL(pipe));
1405 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1406 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1409 static void vlv_enable_pll(struct intel_crtc *crtc,
1410 const struct intel_crtc_state *pipe_config)
1412 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1413 enum pipe pipe = crtc->pipe;
1415 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1417 /* PLL is protected by panel, make sure we can write it */
1418 assert_panel_unlocked(dev_priv, pipe);
1420 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1421 _vlv_enable_pll(crtc, pipe_config);
1423 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1424 POSTING_READ(DPLL_MD(pipe));
1428 static void _chv_enable_pll(struct intel_crtc *crtc,
1429 const struct intel_crtc_state *pipe_config)
1431 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1432 enum pipe pipe = crtc->pipe;
1433 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1436 vlv_dpio_get(dev_priv);
1438 /* Enable back the 10bit clock to display controller */
1439 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1440 tmp |= DPIO_DCLKP_EN;
1441 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1443 vlv_dpio_put(dev_priv);
1446 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1451 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1453 /* Check PLL is locked */
1454 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1455 DRM_ERROR("PLL %d failed to lock\n", pipe);
1458 static void chv_enable_pll(struct intel_crtc *crtc,
1459 const struct intel_crtc_state *pipe_config)
1461 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1462 enum pipe pipe = crtc->pipe;
1464 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1466 /* PLL is protected by panel, make sure we can write it */
1467 assert_panel_unlocked(dev_priv, pipe);
1469 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1470 _chv_enable_pll(crtc, pipe_config);
1472 if (pipe != PIPE_A) {
1474 * WaPixelRepeatModeFixForC0:chv
1476 * DPLLCMD is AWOL. Use chicken bits to propagate
1477 * the value from DPLLBMD to either pipe B or C.
1479 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1480 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1481 I915_WRITE(CBR4_VLV, 0);
1482 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1485 * DPLLB VGA mode also seems to cause problems.
1486 * We should always have it disabled.
1488 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1490 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1491 POSTING_READ(DPLL_MD(pipe));
1495 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1497 if (IS_I830(dev_priv))
1500 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1503 static void i9xx_enable_pll(struct intel_crtc *crtc,
1504 const struct intel_crtc_state *crtc_state)
1506 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1507 i915_reg_t reg = DPLL(crtc->pipe);
1508 u32 dpll = crtc_state->dpll_hw_state.dpll;
1511 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1513 /* PLL is protected by panel, make sure we can write it */
1514 if (i9xx_has_pps(dev_priv))
1515 assert_panel_unlocked(dev_priv, crtc->pipe);
1518 * Apparently we need to have VGA mode enabled prior to changing
1519 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1520 * dividers, even though the register value does change.
1522 I915_WRITE(reg, dpll & ~DPLL_VGA_MODE_DIS);
1523 I915_WRITE(reg, dpll);
1525 /* Wait for the clocks to stabilize. */
1529 if (INTEL_GEN(dev_priv) >= 4) {
1530 I915_WRITE(DPLL_MD(crtc->pipe),
1531 crtc_state->dpll_hw_state.dpll_md);
1533 /* The pixel multiplier can only be updated once the
1534 * DPLL is enabled and the clocks are stable.
1536 * So write it again.
1538 I915_WRITE(reg, dpll);
1541 /* We do this three times for luck */
1542 for (i = 0; i < 3; i++) {
1543 I915_WRITE(reg, dpll);
1545 udelay(150); /* wait for warmup */
1549 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1551 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1552 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1553 enum pipe pipe = crtc->pipe;
1555 /* Don't disable pipe or pipe PLLs if needed */
1556 if (IS_I830(dev_priv))
1559 /* Make sure the pipe isn't still relying on us */
1560 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1562 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1563 POSTING_READ(DPLL(pipe));
1566 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1570 /* Make sure the pipe isn't still relying on us */
1571 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1573 val = DPLL_INTEGRATED_REF_CLK_VLV |
1574 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1576 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1578 I915_WRITE(DPLL(pipe), val);
1579 POSTING_READ(DPLL(pipe));
1582 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1584 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1587 /* Make sure the pipe isn't still relying on us */
1588 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1590 val = DPLL_SSC_REF_CLK_CHV |
1591 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1593 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1595 I915_WRITE(DPLL(pipe), val);
1596 POSTING_READ(DPLL(pipe));
1598 vlv_dpio_get(dev_priv);
1600 /* Disable 10bit clock to display controller */
1601 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1602 val &= ~DPIO_DCLKP_EN;
1603 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1605 vlv_dpio_put(dev_priv);
1608 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1609 struct intel_digital_port *dport,
1610 unsigned int expected_mask)
1613 i915_reg_t dpll_reg;
1615 switch (dport->base.port) {
1617 port_mask = DPLL_PORTB_READY_MASK;
1621 port_mask = DPLL_PORTC_READY_MASK;
1623 expected_mask <<= 4;
1626 port_mask = DPLL_PORTD_READY_MASK;
1627 dpll_reg = DPIO_PHY_STATUS;
1633 if (intel_de_wait_for_register(dev_priv, dpll_reg,
1634 port_mask, expected_mask, 1000))
1635 WARN(1, "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
1636 dport->base.base.base.id, dport->base.base.name,
1637 I915_READ(dpll_reg) & port_mask, expected_mask);
1640 static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1642 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1643 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1644 enum pipe pipe = crtc->pipe;
1646 u32 val, pipeconf_val;
1648 /* Make sure PCH DPLL is enabled */
1649 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1651 /* FDI must be feeding us bits for PCH ports */
1652 assert_fdi_tx_enabled(dev_priv, pipe);
1653 assert_fdi_rx_enabled(dev_priv, pipe);
1655 if (HAS_PCH_CPT(dev_priv)) {
1656 reg = TRANS_CHICKEN2(pipe);
1657 val = I915_READ(reg);
1659 * Workaround: Set the timing override bit
1660 * before enabling the pch transcoder.
1662 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1663 /* Configure frame start delay to match the CPU */
1664 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1665 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1666 I915_WRITE(reg, val);
1669 reg = PCH_TRANSCONF(pipe);
1670 val = I915_READ(reg);
1671 pipeconf_val = I915_READ(PIPECONF(pipe));
1673 if (HAS_PCH_IBX(dev_priv)) {
1674 /* Configure frame start delay to match the CPU */
1675 val &= ~TRANS_FRAME_START_DELAY_MASK;
1676 val |= TRANS_FRAME_START_DELAY(0);
1679 * Make the BPC in transcoder be consistent with
1680 * that in pipeconf reg. For HDMI we must use 8bpc
1681 * here for both 8bpc and 12bpc.
1683 val &= ~PIPECONF_BPC_MASK;
1684 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1685 val |= PIPECONF_8BPC;
1687 val |= pipeconf_val & PIPECONF_BPC_MASK;
1690 val &= ~TRANS_INTERLACE_MASK;
1691 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
1692 if (HAS_PCH_IBX(dev_priv) &&
1693 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1694 val |= TRANS_LEGACY_INTERLACED_ILK;
1696 val |= TRANS_INTERLACED;
1698 val |= TRANS_PROGRESSIVE;
1701 I915_WRITE(reg, val | TRANS_ENABLE);
1702 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
1703 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1706 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1707 enum transcoder cpu_transcoder)
1709 u32 val, pipeconf_val;
1711 /* FDI must be feeding us bits for PCH ports */
1712 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1713 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1715 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1716 /* Workaround: set timing override bit. */
1717 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1718 /* Configure frame start delay to match the CPU */
1719 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1720 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1721 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1724 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1726 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1727 PIPECONF_INTERLACED_ILK)
1728 val |= TRANS_INTERLACED;
1730 val |= TRANS_PROGRESSIVE;
1732 I915_WRITE(LPT_TRANSCONF, val);
1733 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
1734 TRANS_STATE_ENABLE, 100))
1735 DRM_ERROR("Failed to enable PCH transcoder\n");
1738 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1744 /* FDI relies on the transcoder */
1745 assert_fdi_tx_disabled(dev_priv, pipe);
1746 assert_fdi_rx_disabled(dev_priv, pipe);
1748 /* Ports must be off as well */
1749 assert_pch_ports_disabled(dev_priv, pipe);
1751 reg = PCH_TRANSCONF(pipe);
1752 val = I915_READ(reg);
1753 val &= ~TRANS_ENABLE;
1754 I915_WRITE(reg, val);
1755 /* wait for PCH transcoder off, transcoder state */
1756 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
1757 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1759 if (HAS_PCH_CPT(dev_priv)) {
1760 /* Workaround: Clear the timing override chicken bit again. */
1761 reg = TRANS_CHICKEN2(pipe);
1762 val = I915_READ(reg);
1763 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1764 I915_WRITE(reg, val);
1768 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1772 val = I915_READ(LPT_TRANSCONF);
1773 val &= ~TRANS_ENABLE;
1774 I915_WRITE(LPT_TRANSCONF, val);
1775 /* wait for PCH transcoder off, transcoder state */
1776 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
1777 TRANS_STATE_ENABLE, 50))
1778 DRM_ERROR("Failed to disable PCH transcoder\n");
1780 /* Workaround: clear timing override bit. */
1781 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1782 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1783 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1786 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1788 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1790 if (HAS_PCH_LPT(dev_priv))
1796 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1798 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1801 * On i965gm the hardware frame counter reads
1802 * zero when the TV encoder is enabled :(
1804 if (IS_I965GM(dev_priv) &&
1805 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1808 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1809 return 0xffffffff; /* full 32 bit counter */
1810 else if (INTEL_GEN(dev_priv) >= 3)
1811 return 0xffffff; /* only 24 bits of frame count */
1813 return 0; /* Gen2 doesn't have a hardware frame counter */
1816 static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1818 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1820 assert_vblank_disabled(&crtc->base);
1821 drm_crtc_set_max_vblank_count(&crtc->base,
1822 intel_crtc_max_vblank_count(crtc_state));
1823 drm_crtc_vblank_on(&crtc->base);
1826 void intel_crtc_vblank_off(const struct intel_crtc_state *crtc_state)
1828 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1830 drm_crtc_vblank_off(&crtc->base);
1831 assert_vblank_disabled(&crtc->base);
1834 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1836 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
1837 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1838 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1839 enum pipe pipe = crtc->pipe;
1843 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1845 assert_planes_disabled(crtc);
1848 * A pipe without a PLL won't actually be able to drive bits from
1849 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1852 if (HAS_GMCH(dev_priv)) {
1853 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1854 assert_dsi_pll_enabled(dev_priv);
1856 assert_pll_enabled(dev_priv, pipe);
1858 if (new_crtc_state->has_pch_encoder) {
1859 /* if driving the PCH, we need FDI enabled */
1860 assert_fdi_rx_pll_enabled(dev_priv,
1861 intel_crtc_pch_transcoder(crtc));
1862 assert_fdi_tx_pll_enabled(dev_priv,
1863 (enum pipe) cpu_transcoder);
1865 /* FIXME: assert CPU port conditions for SNB+ */
1868 trace_intel_pipe_enable(crtc);
1870 reg = PIPECONF(cpu_transcoder);
1871 val = I915_READ(reg);
1872 if (val & PIPECONF_ENABLE) {
1873 /* we keep both pipes enabled on 830 */
1874 WARN_ON(!IS_I830(dev_priv));
1878 I915_WRITE(reg, val | PIPECONF_ENABLE);
1882 * Until the pipe starts PIPEDSL reads will return a stale value,
1883 * which causes an apparent vblank timestamp jump when PIPEDSL
1884 * resets to its proper value. That also messes up the frame count
1885 * when it's derived from the timestamps. So let's wait for the
1886 * pipe to start properly before we call drm_crtc_vblank_on()
1888 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1889 intel_wait_for_pipe_scanline_moving(crtc);
1892 void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1894 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1895 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1896 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1897 enum pipe pipe = crtc->pipe;
1901 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1904 * Make sure planes won't keep trying to pump pixels to us,
1905 * or we might hang the display.
1907 assert_planes_disabled(crtc);
1909 trace_intel_pipe_disable(crtc);
1911 reg = PIPECONF(cpu_transcoder);
1912 val = I915_READ(reg);
1913 if ((val & PIPECONF_ENABLE) == 0)
1917 * Double wide has implications for planes
1918 * so best keep it disabled when not needed.
1920 if (old_crtc_state->double_wide)
1921 val &= ~PIPECONF_DOUBLE_WIDE;
1923 /* Don't disable pipe or pipe PLLs if needed */
1924 if (!IS_I830(dev_priv))
1925 val &= ~PIPECONF_ENABLE;
1927 I915_WRITE(reg, val);
1928 if ((val & PIPECONF_ENABLE) == 0)
1929 intel_wait_for_pipe_off(old_crtc_state);
1932 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1934 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1937 static bool is_ccs_plane(const struct drm_framebuffer *fb, int plane)
1939 if (!is_ccs_modifier(fb->modifier))
1942 return plane >= fb->format->num_planes / 2;
1945 static bool is_gen12_ccs_modifier(u64 modifier)
1947 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS;
1950 static bool is_gen12_ccs_plane(const struct drm_framebuffer *fb, int plane)
1952 return is_gen12_ccs_modifier(fb->modifier) && is_ccs_plane(fb, plane);
1955 static bool is_aux_plane(const struct drm_framebuffer *fb, int plane)
1957 if (is_ccs_modifier(fb->modifier))
1958 return is_ccs_plane(fb, plane);
1963 static int main_to_ccs_plane(const struct drm_framebuffer *fb, int main_plane)
1965 WARN_ON(!is_ccs_modifier(fb->modifier) ||
1966 (main_plane && main_plane >= fb->format->num_planes / 2));
1968 return fb->format->num_planes / 2 + main_plane;
1971 static int ccs_to_main_plane(const struct drm_framebuffer *fb, int ccs_plane)
1973 WARN_ON(!is_ccs_modifier(fb->modifier) ||
1974 ccs_plane < fb->format->num_planes / 2);
1976 return ccs_plane - fb->format->num_planes / 2;
1979 /* Return either the main plane's CCS or - if not a CCS FB - UV plane */
1981 intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane)
1983 if (is_ccs_modifier(fb->modifier))
1984 return main_to_ccs_plane(fb, main_plane);
1990 intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
1993 return info->is_yuv &&
1994 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
1998 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
2000 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2001 unsigned int cpp = fb->format->cpp[color_plane];
2003 switch (fb->modifier) {
2004 case DRM_FORMAT_MOD_LINEAR:
2005 return intel_tile_size(dev_priv);
2006 case I915_FORMAT_MOD_X_TILED:
2007 if (IS_GEN(dev_priv, 2))
2011 case I915_FORMAT_MOD_Y_TILED_CCS:
2012 if (is_ccs_plane(fb, color_plane))
2015 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2016 if (is_ccs_plane(fb, color_plane))
2019 case I915_FORMAT_MOD_Y_TILED:
2020 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
2024 case I915_FORMAT_MOD_Yf_TILED_CCS:
2025 if (is_ccs_plane(fb, color_plane))
2028 case I915_FORMAT_MOD_Yf_TILED:
2044 MISSING_CASE(fb->modifier);
2050 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
2052 if (is_gen12_ccs_plane(fb, color_plane))
2055 return intel_tile_size(to_i915(fb->dev)) /
2056 intel_tile_width_bytes(fb, color_plane);
2059 /* Return the tile dimensions in pixel units */
2060 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
2061 unsigned int *tile_width,
2062 unsigned int *tile_height)
2064 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
2065 unsigned int cpp = fb->format->cpp[color_plane];
2067 *tile_width = tile_width_bytes / cpp;
2068 *tile_height = intel_tile_height(fb, color_plane);
2072 intel_fb_align_height(const struct drm_framebuffer *fb,
2073 int color_plane, unsigned int height)
2075 unsigned int tile_height = intel_tile_height(fb, color_plane);
2077 return ALIGN(height, tile_height);
2080 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2082 unsigned int size = 0;
2085 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2086 size += rot_info->plane[i].width * rot_info->plane[i].height;
2091 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
2093 unsigned int size = 0;
2096 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
2097 size += rem_info->plane[i].width * rem_info->plane[i].height;
2103 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2104 const struct drm_framebuffer *fb,
2105 unsigned int rotation)
2107 view->type = I915_GGTT_VIEW_NORMAL;
2108 if (drm_rotation_90_or_270(rotation)) {
2109 view->type = I915_GGTT_VIEW_ROTATED;
2110 view->rotated = to_intel_framebuffer(fb)->rot_info;
2114 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2116 if (IS_I830(dev_priv))
2118 else if (IS_I85X(dev_priv))
2120 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2126 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2128 if (INTEL_GEN(dev_priv) >= 9)
2130 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2131 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2133 else if (INTEL_GEN(dev_priv) >= 4)
2139 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2142 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2144 /* AUX_DIST needs only 4K alignment */
2145 if (is_aux_plane(fb, color_plane))
2148 switch (fb->modifier) {
2149 case DRM_FORMAT_MOD_LINEAR:
2150 return intel_linear_alignment(dev_priv);
2151 case I915_FORMAT_MOD_X_TILED:
2152 if (INTEL_GEN(dev_priv) >= 9)
2155 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2157 case I915_FORMAT_MOD_Y_TILED_CCS:
2158 case I915_FORMAT_MOD_Yf_TILED_CCS:
2159 case I915_FORMAT_MOD_Y_TILED:
2160 case I915_FORMAT_MOD_Yf_TILED:
2161 return 1 * 1024 * 1024;
2163 MISSING_CASE(fb->modifier);
2168 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2170 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2171 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2173 return INTEL_GEN(dev_priv) < 4 ||
2175 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
2179 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2180 const struct i915_ggtt_view *view,
2182 unsigned long *out_flags)
2184 struct drm_device *dev = fb->dev;
2185 struct drm_i915_private *dev_priv = to_i915(dev);
2186 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2187 intel_wakeref_t wakeref;
2188 struct i915_vma *vma;
2189 unsigned int pinctl;
2192 if (WARN_ON(!i915_gem_object_is_framebuffer(obj)))
2193 return ERR_PTR(-EINVAL);
2195 alignment = intel_surf_alignment(fb, 0);
2197 /* Note that the w/a also requires 64 PTE of padding following the
2198 * bo. We currently fill all unused PTE with the shadow page and so
2199 * we should always have valid PTE following the scanout preventing
2202 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2203 alignment = 256 * 1024;
2206 * Global gtt pte registers are special registers which actually forward
2207 * writes to a chunk of system memory. Which means that there is no risk
2208 * that the register values disappear as soon as we call
2209 * intel_runtime_pm_put(), so it is correct to wrap only the
2210 * pin/unpin/fence and not more.
2212 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
2214 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2217 * Valleyview is definitely limited to scanning out the first
2218 * 512MiB. Lets presume this behaviour was inherited from the
2219 * g4x display engine and that all earlier gen are similarly
2220 * limited. Testing suggests that it is a little more
2221 * complicated than this. For example, Cherryview appears quite
2222 * happy to scanout from anywhere within its global aperture.
2225 if (HAS_GMCH(dev_priv))
2226 pinctl |= PIN_MAPPABLE;
2228 vma = i915_gem_object_pin_to_display_plane(obj,
2229 alignment, view, pinctl);
2233 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2237 * Install a fence for tiled scan-out. Pre-i965 always needs a
2238 * fence, whereas 965+ only requires a fence if using
2239 * framebuffer compression. For simplicity, we always, when
2240 * possible, install a fence as the cost is not that onerous.
2242 * If we fail to fence the tiled scanout, then either the
2243 * modeset will reject the change (which is highly unlikely as
2244 * the affected systems, all but one, do not have unmappable
2245 * space) or we will not be able to enable full powersaving
2246 * techniques (also likely not to apply due to various limits
2247 * FBC and the like impose on the size of the buffer, which
2248 * presumably we violated anyway with this unmappable buffer).
2249 * Anyway, it is presumably better to stumble onwards with
2250 * something and try to run the system in a "less than optimal"
2251 * mode that matches the user configuration.
2253 ret = i915_vma_pin_fence(vma);
2254 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2255 i915_gem_object_unpin_from_display_plane(vma);
2260 if (ret == 0 && vma->fence)
2261 *out_flags |= PLANE_HAS_FENCE;
2266 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2267 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
2271 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2273 i915_gem_object_lock(vma->obj);
2274 if (flags & PLANE_HAS_FENCE)
2275 i915_vma_unpin_fence(vma);
2276 i915_gem_object_unpin_from_display_plane(vma);
2277 i915_gem_object_unlock(vma->obj);
2282 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2283 unsigned int rotation)
2285 if (drm_rotation_90_or_270(rotation))
2286 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2288 return fb->pitches[color_plane];
2292 * Convert the x/y offsets into a linear offset.
2293 * Only valid with 0/180 degree rotation, which is fine since linear
2294 * offset is only used with linear buffers on pre-hsw and tiled buffers
2295 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2297 u32 intel_fb_xy_to_linear(int x, int y,
2298 const struct intel_plane_state *state,
2301 const struct drm_framebuffer *fb = state->hw.fb;
2302 unsigned int cpp = fb->format->cpp[color_plane];
2303 unsigned int pitch = state->color_plane[color_plane].stride;
2305 return y * pitch + x * cpp;
2309 * Add the x/y offsets derived from fb->offsets[] to the user
2310 * specified plane src x/y offsets. The resulting x/y offsets
2311 * specify the start of scanout from the beginning of the gtt mapping.
2313 void intel_add_fb_offsets(int *x, int *y,
2314 const struct intel_plane_state *state,
2318 *x += state->color_plane[color_plane].x;
2319 *y += state->color_plane[color_plane].y;
2322 static u32 intel_adjust_tile_offset(int *x, int *y,
2323 unsigned int tile_width,
2324 unsigned int tile_height,
2325 unsigned int tile_size,
2326 unsigned int pitch_tiles,
2330 unsigned int pitch_pixels = pitch_tiles * tile_width;
2333 WARN_ON(old_offset & (tile_size - 1));
2334 WARN_ON(new_offset & (tile_size - 1));
2335 WARN_ON(new_offset > old_offset);
2337 tiles = (old_offset - new_offset) / tile_size;
2339 *y += tiles / pitch_tiles * tile_height;
2340 *x += tiles % pitch_tiles * tile_width;
2342 /* minimize x in case it got needlessly big */
2343 *y += *x / pitch_pixels * tile_height;
2349 static bool is_surface_linear(const struct drm_framebuffer *fb, int color_plane)
2351 return fb->modifier == DRM_FORMAT_MOD_LINEAR ||
2352 is_gen12_ccs_plane(fb, color_plane);
2355 static u32 intel_adjust_aligned_offset(int *x, int *y,
2356 const struct drm_framebuffer *fb,
2358 unsigned int rotation,
2360 u32 old_offset, u32 new_offset)
2362 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2363 unsigned int cpp = fb->format->cpp[color_plane];
2365 WARN_ON(new_offset > old_offset);
2367 if (!is_surface_linear(fb, color_plane)) {
2368 unsigned int tile_size, tile_width, tile_height;
2369 unsigned int pitch_tiles;
2371 tile_size = intel_tile_size(dev_priv);
2372 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2374 if (drm_rotation_90_or_270(rotation)) {
2375 pitch_tiles = pitch / tile_height;
2376 swap(tile_width, tile_height);
2378 pitch_tiles = pitch / (tile_width * cpp);
2381 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2382 tile_size, pitch_tiles,
2383 old_offset, new_offset);
2385 old_offset += *y * pitch + *x * cpp;
2387 *y = (old_offset - new_offset) / pitch;
2388 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2395 * Adjust the tile offset by moving the difference into
2398 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2399 const struct intel_plane_state *state,
2401 u32 old_offset, u32 new_offset)
2403 return intel_adjust_aligned_offset(x, y, state->hw.fb, color_plane,
2405 state->color_plane[color_plane].stride,
2406 old_offset, new_offset);
2410 * Computes the aligned offset to the base tile and adjusts
2411 * x, y. bytes per pixel is assumed to be a power-of-two.
2413 * In the 90/270 rotated case, x and y are assumed
2414 * to be already rotated to match the rotated GTT view, and
2415 * pitch is the tile_height aligned framebuffer height.
2417 * This function is used when computing the derived information
2418 * under intel_framebuffer, so using any of that information
2419 * here is not allowed. Anything under drm_framebuffer can be
2420 * used. This is why the user has to pass in the pitch since it
2421 * is specified in the rotated orientation.
2423 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2425 const struct drm_framebuffer *fb,
2428 unsigned int rotation,
2431 unsigned int cpp = fb->format->cpp[color_plane];
2432 u32 offset, offset_aligned;
2437 if (!is_surface_linear(fb, color_plane)) {
2438 unsigned int tile_size, tile_width, tile_height;
2439 unsigned int tile_rows, tiles, pitch_tiles;
2441 tile_size = intel_tile_size(dev_priv);
2442 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2444 if (drm_rotation_90_or_270(rotation)) {
2445 pitch_tiles = pitch / tile_height;
2446 swap(tile_width, tile_height);
2448 pitch_tiles = pitch / (tile_width * cpp);
2451 tile_rows = *y / tile_height;
2454 tiles = *x / tile_width;
2457 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2458 offset_aligned = offset & ~alignment;
2460 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2461 tile_size, pitch_tiles,
2462 offset, offset_aligned);
2464 offset = *y * pitch + *x * cpp;
2465 offset_aligned = offset & ~alignment;
2467 *y = (offset & alignment) / pitch;
2468 *x = ((offset & alignment) - *y * pitch) / cpp;
2471 return offset_aligned;
2474 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2475 const struct intel_plane_state *state,
2478 struct intel_plane *intel_plane = to_intel_plane(state->uapi.plane);
2479 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2480 const struct drm_framebuffer *fb = state->hw.fb;
2481 unsigned int rotation = state->hw.rotation;
2482 int pitch = state->color_plane[color_plane].stride;
2485 if (intel_plane->id == PLANE_CURSOR)
2486 alignment = intel_cursor_alignment(dev_priv);
2488 alignment = intel_surf_alignment(fb, color_plane);
2490 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2491 pitch, rotation, alignment);
2494 /* Convert the fb->offset[] into x/y offsets */
2495 static int intel_fb_offset_to_xy(int *x, int *y,
2496 const struct drm_framebuffer *fb,
2499 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2500 unsigned int height;
2502 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2503 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2504 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2505 fb->offsets[color_plane], color_plane);
2509 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2510 height = ALIGN(height, intel_tile_height(fb, color_plane));
2512 /* Catch potential overflows early */
2513 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2514 fb->offsets[color_plane])) {
2515 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2516 fb->offsets[color_plane], fb->pitches[color_plane],
2524 intel_adjust_aligned_offset(x, y,
2525 fb, color_plane, DRM_MODE_ROTATE_0,
2526 fb->pitches[color_plane],
2527 fb->offsets[color_plane], 0);
2532 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2534 switch (fb_modifier) {
2535 case I915_FORMAT_MOD_X_TILED:
2536 return I915_TILING_X;
2537 case I915_FORMAT_MOD_Y_TILED:
2538 case I915_FORMAT_MOD_Y_TILED_CCS:
2539 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2540 return I915_TILING_Y;
2542 return I915_TILING_NONE;
2547 * From the Sky Lake PRM:
2548 * "The Color Control Surface (CCS) contains the compression status of
2549 * the cache-line pairs. The compression state of the cache-line pair
2550 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2551 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2552 * cache-line-pairs. CCS is always Y tiled."
2554 * Since cache line pairs refers to horizontally adjacent cache lines,
2555 * each cache line in the CCS corresponds to an area of 32x16 cache
2556 * lines on the main surface. Since each pixel is 4 bytes, this gives
2557 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2560 static const struct drm_format_info skl_ccs_formats[] = {
2561 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2562 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2563 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2564 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2565 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2566 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2567 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2568 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2572 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
2573 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
2574 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
2575 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
2578 static const struct drm_format_info gen12_ccs_formats[] = {
2579 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2580 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2581 .hsub = 1, .vsub = 1, },
2582 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2583 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2584 .hsub = 1, .vsub = 1, },
2585 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2586 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2587 .hsub = 1, .vsub = 1, .has_alpha = true },
2588 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2589 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2590 .hsub = 1, .vsub = 1, .has_alpha = true },
2593 static const struct drm_format_info *
2594 lookup_format_info(const struct drm_format_info formats[],
2595 int num_formats, u32 format)
2599 for (i = 0; i < num_formats; i++) {
2600 if (formats[i].format == format)
2607 static const struct drm_format_info *
2608 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2610 switch (cmd->modifier[0]) {
2611 case I915_FORMAT_MOD_Y_TILED_CCS:
2612 case I915_FORMAT_MOD_Yf_TILED_CCS:
2613 return lookup_format_info(skl_ccs_formats,
2614 ARRAY_SIZE(skl_ccs_formats),
2616 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2617 return lookup_format_info(gen12_ccs_formats,
2618 ARRAY_SIZE(gen12_ccs_formats),
2625 bool is_ccs_modifier(u64 modifier)
2627 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
2628 modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2629 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2632 static int gen12_ccs_aux_stride(struct drm_framebuffer *fb, int ccs_plane)
2634 return DIV_ROUND_UP(fb->pitches[ccs_to_main_plane(fb, ccs_plane)],
2638 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
2639 u32 pixel_format, u64 modifier)
2641 struct intel_crtc *crtc;
2642 struct intel_plane *plane;
2645 * We assume the primary plane for pipe A has
2646 * the highest stride limits of them all.
2648 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
2652 plane = to_intel_plane(crtc->base.primary);
2654 return plane->max_stride(plane, pixel_format, modifier,
2659 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
2660 u32 pixel_format, u64 modifier)
2663 * Arbitrary limit for gen4+ chosen to match the
2664 * render engine max stride.
2666 * The new CCS hash mode makes remapping impossible
2668 if (!is_ccs_modifier(modifier)) {
2669 if (INTEL_GEN(dev_priv) >= 7)
2671 else if (INTEL_GEN(dev_priv) >= 4)
2675 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
2679 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
2681 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2684 if (is_surface_linear(fb, color_plane)) {
2685 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
2690 * To make remapping with linear generally feasible
2691 * we need the stride to be page aligned.
2693 if (fb->pitches[color_plane] > max_stride &&
2694 !is_ccs_modifier(fb->modifier))
2695 return intel_tile_size(dev_priv);
2700 tile_width = intel_tile_width_bytes(fb, color_plane);
2701 if (is_ccs_modifier(fb->modifier) && color_plane == 0) {
2703 * Display WA #0531: skl,bxt,kbl,glk
2705 * Render decompression and plane width > 3840
2706 * combined with horizontal panning requires the
2707 * plane stride to be a multiple of 4. We'll just
2708 * require the entire fb to accommodate that to avoid
2709 * potential runtime errors at plane configuration time.
2711 if (IS_GEN(dev_priv, 9) && fb->width > 3840)
2714 * The main surface pitch must be padded to a multiple of four
2717 else if (INTEL_GEN(dev_priv) >= 12)
2723 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
2725 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2726 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2727 const struct drm_framebuffer *fb = plane_state->hw.fb;
2730 /* We don't want to deal with remapping with cursors */
2731 if (plane->id == PLANE_CURSOR)
2735 * The display engine limits already match/exceed the
2736 * render engine limits, so not much point in remapping.
2737 * Would also need to deal with the fence POT alignment
2738 * and gen2 2KiB GTT tile size.
2740 if (INTEL_GEN(dev_priv) < 4)
2744 * The new CCS hash mode isn't compatible with remapping as
2745 * the virtual address of the pages affects the compressed data.
2747 if (is_ccs_modifier(fb->modifier))
2750 /* Linear needs a page aligned stride for remapping */
2751 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2752 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2754 for (i = 0; i < fb->format->num_planes; i++) {
2755 if (fb->pitches[i] & alignment)
2763 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2765 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2766 const struct drm_framebuffer *fb = plane_state->hw.fb;
2767 unsigned int rotation = plane_state->hw.rotation;
2768 u32 stride, max_stride;
2771 * No remapping for invisible planes since we don't have
2772 * an actual source viewport to remap.
2774 if (!plane_state->uapi.visible)
2777 if (!intel_plane_can_remap(plane_state))
2781 * FIXME: aux plane limits on gen9+ are
2782 * unclear in Bspec, for now no checking.
2784 stride = intel_fb_pitch(fb, 0, rotation);
2785 max_stride = plane->max_stride(plane, fb->format->format,
2786 fb->modifier, rotation);
2788 return stride > max_stride;
2792 intel_fb_plane_get_subsampling(int *hsub, int *vsub,
2793 const struct drm_framebuffer *fb,
2798 if (color_plane == 0) {
2806 * TODO: Deduct the subsampling from the char block for all CCS
2807 * formats and planes.
2809 if (!is_gen12_ccs_plane(fb, color_plane)) {
2810 *hsub = fb->format->hsub;
2811 *vsub = fb->format->vsub;
2816 main_plane = ccs_to_main_plane(fb, color_plane);
2817 *hsub = drm_format_info_block_width(fb->format, color_plane) /
2818 drm_format_info_block_width(fb->format, main_plane);
2821 * The min stride check in the core framebuffer_check() function
2822 * assumes that format->hsub applies to every plane except for the
2823 * first plane. That's incorrect for the CCS AUX plane of the first
2824 * plane, but for the above check to pass we must define the block
2825 * width with that subsampling applied to it. Adjust the width here
2826 * accordingly, so we can calculate the actual subsampling factor.
2828 if (main_plane == 0)
2829 *hsub *= fb->format->hsub;
2834 intel_fb_check_ccs_xy(struct drm_framebuffer *fb, int ccs_plane, int x, int y)
2836 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2839 int tile_width, tile_height;
2843 if (!is_ccs_plane(fb, ccs_plane))
2846 intel_tile_dims(fb, ccs_plane, &tile_width, &tile_height);
2847 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
2850 tile_height *= vsub;
2852 ccs_x = (x * hsub) % tile_width;
2853 ccs_y = (y * vsub) % tile_height;
2855 main_plane = ccs_to_main_plane(fb, ccs_plane);
2856 main_x = intel_fb->normal[main_plane].x % tile_width;
2857 main_y = intel_fb->normal[main_plane].y % tile_height;
2860 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2861 * x/y offsets must match between CCS and the main surface.
2863 if (main_x != ccs_x || main_y != ccs_y) {
2864 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2867 intel_fb->normal[main_plane].x,
2868 intel_fb->normal[main_plane].y,
2877 intel_fb_plane_dims(int *w, int *h, struct drm_framebuffer *fb, int color_plane)
2881 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, color_plane);
2882 *w = fb->width / hsub;
2883 *h = fb->height / vsub;
2887 * Setup the rotated view for an FB plane and return the size the GTT mapping
2888 * requires for this view.
2891 setup_fb_rotation(int plane, const struct intel_remapped_plane_info *plane_info,
2892 u32 gtt_offset_rotated, int x, int y,
2893 unsigned int width, unsigned int height,
2894 unsigned int tile_size,
2895 unsigned int tile_width, unsigned int tile_height,
2896 struct drm_framebuffer *fb)
2898 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2899 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2900 unsigned int pitch_tiles;
2903 /* Y or Yf modifiers required for 90/270 rotation */
2904 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
2905 fb->modifier != I915_FORMAT_MOD_Yf_TILED)
2908 if (WARN_ON(plane >= ARRAY_SIZE(rot_info->plane)))
2911 rot_info->plane[plane] = *plane_info;
2913 intel_fb->rotated[plane].pitch = plane_info->height * tile_height;
2915 /* rotate the x/y offsets to match the GTT view */
2916 drm_rect_init(&r, x, y, width, height);
2918 plane_info->width * tile_width,
2919 plane_info->height * tile_height,
2920 DRM_MODE_ROTATE_270);
2924 /* rotate the tile dimensions to match the GTT view */
2925 pitch_tiles = intel_fb->rotated[plane].pitch / tile_height;
2926 swap(tile_width, tile_height);
2929 * We only keep the x/y offsets, so push all of the
2930 * gtt offset into the x/y offsets.
2932 intel_adjust_tile_offset(&x, &y,
2933 tile_width, tile_height,
2934 tile_size, pitch_tiles,
2935 gtt_offset_rotated * tile_size, 0);
2938 * First pixel of the framebuffer from
2939 * the start of the rotated gtt mapping.
2941 intel_fb->rotated[plane].x = x;
2942 intel_fb->rotated[plane].y = y;
2944 return plane_info->width * plane_info->height;
2948 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2949 struct drm_framebuffer *fb)
2951 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2952 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2953 u32 gtt_offset_rotated = 0;
2954 unsigned int max_size = 0;
2955 int i, num_planes = fb->format->num_planes;
2956 unsigned int tile_size = intel_tile_size(dev_priv);
2958 for (i = 0; i < num_planes; i++) {
2959 unsigned int width, height;
2960 unsigned int cpp, size;
2965 cpp = fb->format->cpp[i];
2966 intel_fb_plane_dims(&width, &height, fb, i);
2968 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2970 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2975 ret = intel_fb_check_ccs_xy(fb, i, x, y);
2980 * The fence (if used) is aligned to the start of the object
2981 * so having the framebuffer wrap around across the edge of the
2982 * fenced region doesn't really work. We have no API to configure
2983 * the fence start offset within the object (nor could we probably
2984 * on gen2/3). So it's just easier if we just require that the
2985 * fb layout agrees with the fence layout. We already check that the
2986 * fb stride matches the fence stride elsewhere.
2988 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2989 (x + width) * cpp > fb->pitches[i]) {
2990 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2996 * First pixel of the framebuffer from
2997 * the start of the normal gtt mapping.
2999 intel_fb->normal[i].x = x;
3000 intel_fb->normal[i].y = y;
3002 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
3006 offset /= tile_size;
3008 if (!is_surface_linear(fb, i)) {
3009 struct intel_remapped_plane_info plane_info;
3010 unsigned int tile_width, tile_height;
3012 intel_tile_dims(fb, i, &tile_width, &tile_height);
3014 plane_info.offset = offset;
3015 plane_info.stride = DIV_ROUND_UP(fb->pitches[i],
3017 plane_info.width = DIV_ROUND_UP(x + width, tile_width);
3018 plane_info.height = DIV_ROUND_UP(y + height,
3021 /* how many tiles does this plane need */
3022 size = plane_info.stride * plane_info.height;
3024 * If the plane isn't horizontally tile aligned,
3025 * we need one more tile.
3030 gtt_offset_rotated +=
3031 setup_fb_rotation(i, &plane_info,
3033 x, y, width, height,
3035 tile_width, tile_height,
3038 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
3039 x * cpp, tile_size);
3042 /* how many tiles in total needed in the bo */
3043 max_size = max(max_size, offset + size);
3046 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
3047 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
3048 mul_u32_u32(max_size, tile_size), obj->base.size);
3056 intel_plane_remap_gtt(struct intel_plane_state *plane_state)
3058 struct drm_i915_private *dev_priv =
3059 to_i915(plane_state->uapi.plane->dev);
3060 struct drm_framebuffer *fb = plane_state->hw.fb;
3061 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
3062 struct intel_rotation_info *info = &plane_state->view.rotated;
3063 unsigned int rotation = plane_state->hw.rotation;
3064 int i, num_planes = fb->format->num_planes;
3065 unsigned int tile_size = intel_tile_size(dev_priv);
3066 unsigned int src_x, src_y;
3067 unsigned int src_w, src_h;
3070 memset(&plane_state->view, 0, sizeof(plane_state->view));
3071 plane_state->view.type = drm_rotation_90_or_270(rotation) ?
3072 I915_GGTT_VIEW_ROTATED : I915_GGTT_VIEW_REMAPPED;
3074 src_x = plane_state->uapi.src.x1 >> 16;
3075 src_y = plane_state->uapi.src.y1 >> 16;
3076 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
3077 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
3079 WARN_ON(is_ccs_modifier(fb->modifier));
3081 /* Make src coordinates relative to the viewport */
3082 drm_rect_translate(&plane_state->uapi.src,
3083 -(src_x << 16), -(src_y << 16));
3085 /* Rotate src coordinates to match rotated GTT view */
3086 if (drm_rotation_90_or_270(rotation))
3087 drm_rect_rotate(&plane_state->uapi.src,
3088 src_w << 16, src_h << 16,
3089 DRM_MODE_ROTATE_270);
3091 for (i = 0; i < num_planes; i++) {
3092 unsigned int hsub = i ? fb->format->hsub : 1;
3093 unsigned int vsub = i ? fb->format->vsub : 1;
3094 unsigned int cpp = fb->format->cpp[i];
3095 unsigned int tile_width, tile_height;
3096 unsigned int width, height;
3097 unsigned int pitch_tiles;
3101 intel_tile_dims(fb, i, &tile_width, &tile_height);
3105 width = src_w / hsub;
3106 height = src_h / vsub;
3109 * First pixel of the src viewport from the
3110 * start of the normal gtt mapping.
3112 x += intel_fb->normal[i].x;
3113 y += intel_fb->normal[i].y;
3115 offset = intel_compute_aligned_offset(dev_priv, &x, &y,
3116 fb, i, fb->pitches[i],
3117 DRM_MODE_ROTATE_0, tile_size);
3118 offset /= tile_size;
3120 WARN_ON(i >= ARRAY_SIZE(info->plane));
3121 info->plane[i].offset = offset;
3122 info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
3124 info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
3125 info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
3127 if (drm_rotation_90_or_270(rotation)) {
3130 /* rotate the x/y offsets to match the GTT view */
3131 drm_rect_init(&r, x, y, width, height);
3133 info->plane[i].width * tile_width,
3134 info->plane[i].height * tile_height,
3135 DRM_MODE_ROTATE_270);
3139 pitch_tiles = info->plane[i].height;
3140 plane_state->color_plane[i].stride = pitch_tiles * tile_height;
3142 /* rotate the tile dimensions to match the GTT view */
3143 swap(tile_width, tile_height);
3145 pitch_tiles = info->plane[i].width;
3146 plane_state->color_plane[i].stride = pitch_tiles * tile_width * cpp;
3150 * We only keep the x/y offsets, so push all of the
3151 * gtt offset into the x/y offsets.
3153 intel_adjust_tile_offset(&x, &y,
3154 tile_width, tile_height,
3155 tile_size, pitch_tiles,
3156 gtt_offset * tile_size, 0);
3158 gtt_offset += info->plane[i].width * info->plane[i].height;
3160 plane_state->color_plane[i].offset = 0;
3161 plane_state->color_plane[i].x = x;
3162 plane_state->color_plane[i].y = y;
3167 intel_plane_compute_gtt(struct intel_plane_state *plane_state)
3169 const struct intel_framebuffer *fb =
3170 to_intel_framebuffer(plane_state->hw.fb);
3171 unsigned int rotation = plane_state->hw.rotation;
3177 num_planes = fb->base.format->num_planes;
3179 if (intel_plane_needs_remap(plane_state)) {
3180 intel_plane_remap_gtt(plane_state);
3183 * Sometimes even remapping can't overcome
3184 * the stride limitations :( Can happen with
3185 * big plane sizes and suitably misaligned
3188 return intel_plane_check_stride(plane_state);
3191 intel_fill_fb_ggtt_view(&plane_state->view, &fb->base, rotation);
3193 for (i = 0; i < num_planes; i++) {
3194 plane_state->color_plane[i].stride = intel_fb_pitch(&fb->base, i, rotation);
3195 plane_state->color_plane[i].offset = 0;
3197 if (drm_rotation_90_or_270(rotation)) {
3198 plane_state->color_plane[i].x = fb->rotated[i].x;
3199 plane_state->color_plane[i].y = fb->rotated[i].y;
3201 plane_state->color_plane[i].x = fb->normal[i].x;
3202 plane_state->color_plane[i].y = fb->normal[i].y;
3206 /* Rotate src coordinates to match rotated GTT view */
3207 if (drm_rotation_90_or_270(rotation))
3208 drm_rect_rotate(&plane_state->uapi.src,
3209 fb->base.width << 16, fb->base.height << 16,
3210 DRM_MODE_ROTATE_270);
3212 return intel_plane_check_stride(plane_state);
3215 static int i9xx_format_to_fourcc(int format)
3218 case DISPPLANE_8BPP:
3219 return DRM_FORMAT_C8;
3220 case DISPPLANE_BGRA555:
3221 return DRM_FORMAT_ARGB1555;
3222 case DISPPLANE_BGRX555:
3223 return DRM_FORMAT_XRGB1555;
3224 case DISPPLANE_BGRX565:
3225 return DRM_FORMAT_RGB565;
3227 case DISPPLANE_BGRX888:
3228 return DRM_FORMAT_XRGB8888;
3229 case DISPPLANE_RGBX888:
3230 return DRM_FORMAT_XBGR8888;
3231 case DISPPLANE_BGRA888:
3232 return DRM_FORMAT_ARGB8888;
3233 case DISPPLANE_RGBA888:
3234 return DRM_FORMAT_ABGR8888;
3235 case DISPPLANE_BGRX101010:
3236 return DRM_FORMAT_XRGB2101010;
3237 case DISPPLANE_RGBX101010:
3238 return DRM_FORMAT_XBGR2101010;
3239 case DISPPLANE_BGRA101010:
3240 return DRM_FORMAT_ARGB2101010;
3241 case DISPPLANE_RGBA101010:
3242 return DRM_FORMAT_ABGR2101010;
3243 case DISPPLANE_RGBX161616:
3244 return DRM_FORMAT_XBGR16161616F;
3248 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
3251 case PLANE_CTL_FORMAT_RGB_565:
3252 return DRM_FORMAT_RGB565;
3253 case PLANE_CTL_FORMAT_NV12:
3254 return DRM_FORMAT_NV12;
3255 case PLANE_CTL_FORMAT_P010:
3256 return DRM_FORMAT_P010;
3257 case PLANE_CTL_FORMAT_P012:
3258 return DRM_FORMAT_P012;
3259 case PLANE_CTL_FORMAT_P016:
3260 return DRM_FORMAT_P016;
3261 case PLANE_CTL_FORMAT_Y210:
3262 return DRM_FORMAT_Y210;
3263 case PLANE_CTL_FORMAT_Y212:
3264 return DRM_FORMAT_Y212;
3265 case PLANE_CTL_FORMAT_Y216:
3266 return DRM_FORMAT_Y216;
3267 case PLANE_CTL_FORMAT_Y410:
3268 return DRM_FORMAT_XVYU2101010;
3269 case PLANE_CTL_FORMAT_Y412:
3270 return DRM_FORMAT_XVYU12_16161616;
3271 case PLANE_CTL_FORMAT_Y416:
3272 return DRM_FORMAT_XVYU16161616;
3274 case PLANE_CTL_FORMAT_XRGB_8888:
3277 return DRM_FORMAT_ABGR8888;
3279 return DRM_FORMAT_XBGR8888;
3282 return DRM_FORMAT_ARGB8888;
3284 return DRM_FORMAT_XRGB8888;
3286 case PLANE_CTL_FORMAT_XRGB_2101010:
3289 return DRM_FORMAT_ABGR2101010;
3291 return DRM_FORMAT_XBGR2101010;
3294 return DRM_FORMAT_ARGB2101010;
3296 return DRM_FORMAT_XRGB2101010;
3298 case PLANE_CTL_FORMAT_XRGB_16161616F:
3301 return DRM_FORMAT_ABGR16161616F;
3303 return DRM_FORMAT_XBGR16161616F;
3306 return DRM_FORMAT_ARGB16161616F;
3308 return DRM_FORMAT_XRGB16161616F;
3314 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
3315 struct intel_initial_plane_config *plane_config)
3317 struct drm_device *dev = crtc->base.dev;
3318 struct drm_i915_private *dev_priv = to_i915(dev);
3319 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
3320 struct drm_framebuffer *fb = &plane_config->fb->base;
3321 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
3322 u32 size_aligned = round_up(plane_config->base + plane_config->size,
3324 struct drm_i915_gem_object *obj;
3327 size_aligned -= base_aligned;
3329 if (plane_config->size == 0)
3332 /* If the FB is too big, just don't use it since fbdev is not very
3333 * important and we should probably use that space with FBC or other
3335 if (size_aligned * 2 > dev_priv->stolen_usable_size)
3338 switch (fb->modifier) {
3339 case DRM_FORMAT_MOD_LINEAR:
3340 case I915_FORMAT_MOD_X_TILED:
3341 case I915_FORMAT_MOD_Y_TILED:
3344 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
3349 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
3356 switch (plane_config->tiling) {
3357 case I915_TILING_NONE:
3361 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
3364 MISSING_CASE(plane_config->tiling);
3368 mode_cmd.pixel_format = fb->format->format;
3369 mode_cmd.width = fb->width;
3370 mode_cmd.height = fb->height;
3371 mode_cmd.pitches[0] = fb->pitches[0];
3372 mode_cmd.modifier[0] = fb->modifier;
3373 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
3375 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
3376 DRM_DEBUG_KMS("intel fb init failed\n");
3381 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
3384 i915_gem_object_put(obj);
3389 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
3390 struct intel_plane_state *plane_state,
3393 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3395 plane_state->uapi.visible = visible;
3398 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
3400 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
3403 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
3405 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3406 struct drm_plane *plane;
3409 * Active_planes aliases if multiple "primary" or cursor planes
3410 * have been used on the same (or wrong) pipe. plane_mask uses
3411 * unique ids, hence we can use that to reconstruct active_planes.
3413 crtc_state->active_planes = 0;
3415 drm_for_each_plane_mask(plane, &dev_priv->drm,
3416 crtc_state->uapi.plane_mask)
3417 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
3420 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
3421 struct intel_plane *plane)
3423 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3424 struct intel_crtc_state *crtc_state =
3425 to_intel_crtc_state(crtc->base.state);
3426 struct intel_plane_state *plane_state =
3427 to_intel_plane_state(plane->base.state);
3429 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
3430 plane->base.base.id, plane->base.name,
3431 crtc->base.base.id, crtc->base.name);
3433 intel_set_plane_visible(crtc_state, plane_state, false);
3434 fixup_active_planes(crtc_state);
3435 crtc_state->data_rate[plane->id] = 0;
3436 crtc_state->min_cdclk[plane->id] = 0;
3438 if (plane->id == PLANE_PRIMARY)
3439 hsw_disable_ips(crtc_state);
3442 * Vblank time updates from the shadow to live plane control register
3443 * are blocked if the memory self-refresh mode is active at that
3444 * moment. So to make sure the plane gets truly disabled, disable
3445 * first the self-refresh mode. The self-refresh enable bit in turn
3446 * will be checked/applied by the HW only at the next frame start
3447 * event which is after the vblank start event, so we need to have a
3448 * wait-for-vblank between disabling the plane and the pipe.
3450 if (HAS_GMCH(dev_priv) &&
3451 intel_set_memory_cxsr(dev_priv, false))
3452 intel_wait_for_vblank(dev_priv, crtc->pipe);
3455 * Gen2 reports pipe underruns whenever all planes are disabled.
3456 * So disable underrun reporting before all the planes get disabled.
3458 if (IS_GEN(dev_priv, 2) && !crtc_state->active_planes)
3459 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
3461 intel_disable_plane(plane, crtc_state);
3464 static struct intel_frontbuffer *
3465 to_intel_frontbuffer(struct drm_framebuffer *fb)
3467 return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
3471 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
3472 struct intel_initial_plane_config *plane_config)
3474 struct drm_device *dev = intel_crtc->base.dev;
3475 struct drm_i915_private *dev_priv = to_i915(dev);
3477 struct drm_plane *primary = intel_crtc->base.primary;
3478 struct drm_plane_state *plane_state = primary->state;
3479 struct intel_plane *intel_plane = to_intel_plane(primary);
3480 struct intel_plane_state *intel_state =
3481 to_intel_plane_state(plane_state);
3482 struct drm_framebuffer *fb;
3484 if (!plane_config->fb)
3487 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
3488 fb = &plane_config->fb->base;
3492 kfree(plane_config->fb);
3495 * Failed to alloc the obj, check to see if we should share
3496 * an fb with another CRTC instead
3498 for_each_crtc(dev, c) {
3499 struct intel_plane_state *state;
3501 if (c == &intel_crtc->base)
3504 if (!to_intel_crtc(c)->active)
3507 state = to_intel_plane_state(c->primary->state);
3511 if (intel_plane_ggtt_offset(state) == plane_config->base) {
3513 drm_framebuffer_get(fb);
3519 * We've failed to reconstruct the BIOS FB. Current display state
3520 * indicates that the primary plane is visible, but has a NULL FB,
3521 * which will lead to problems later if we don't fix it up. The
3522 * simplest solution is to just disable the primary plane now and
3523 * pretend the BIOS never had it enabled.
3525 intel_plane_disable_noatomic(intel_crtc, intel_plane);
3530 intel_state->hw.rotation = plane_config->rotation;
3531 intel_fill_fb_ggtt_view(&intel_state->view, fb,
3532 intel_state->hw.rotation);
3533 intel_state->color_plane[0].stride =
3534 intel_fb_pitch(fb, 0, intel_state->hw.rotation);
3537 intel_pin_and_fence_fb_obj(fb,
3539 intel_plane_uses_fence(intel_state),
3540 &intel_state->flags);
3541 if (IS_ERR(intel_state->vma)) {
3542 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
3543 intel_crtc->pipe, PTR_ERR(intel_state->vma));
3545 intel_state->vma = NULL;
3546 drm_framebuffer_put(fb);
3550 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
3552 plane_state->src_x = 0;
3553 plane_state->src_y = 0;
3554 plane_state->src_w = fb->width << 16;
3555 plane_state->src_h = fb->height << 16;
3557 plane_state->crtc_x = 0;
3558 plane_state->crtc_y = 0;
3559 plane_state->crtc_w = fb->width;
3560 plane_state->crtc_h = fb->height;
3562 intel_state->uapi.src = drm_plane_state_src(plane_state);
3563 intel_state->uapi.dst = drm_plane_state_dest(plane_state);
3565 if (plane_config->tiling)
3566 dev_priv->preserve_bios_swizzle = true;
3568 plane_state->fb = fb;
3569 plane_state->crtc = &intel_crtc->base;
3570 intel_plane_copy_uapi_to_hw_state(intel_state, intel_state);
3572 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
3573 &to_intel_frontbuffer(fb)->bits);
3576 static int skl_max_plane_width(const struct drm_framebuffer *fb,
3578 unsigned int rotation)
3580 int cpp = fb->format->cpp[color_plane];
3582 switch (fb->modifier) {
3583 case DRM_FORMAT_MOD_LINEAR:
3584 case I915_FORMAT_MOD_X_TILED:
3586 * Validated limit is 4k, but has 5k should
3587 * work apart from the following features:
3588 * - Ytile (already limited to 4k)
3589 * - FP16 (already limited to 4k)
3590 * - render compression (already limited to 4k)
3591 * - KVMR sprite and cursor (don't care)
3592 * - horizontal panning (TODO verify this)
3593 * - pipe and plane scaling (TODO verify this)
3599 case I915_FORMAT_MOD_Y_TILED_CCS:
3600 case I915_FORMAT_MOD_Yf_TILED_CCS:
3601 /* FIXME AUX plane? */
3602 case I915_FORMAT_MOD_Y_TILED:
3603 case I915_FORMAT_MOD_Yf_TILED:
3609 MISSING_CASE(fb->modifier);
3614 static int glk_max_plane_width(const struct drm_framebuffer *fb,
3616 unsigned int rotation)
3618 int cpp = fb->format->cpp[color_plane];
3620 switch (fb->modifier) {
3621 case DRM_FORMAT_MOD_LINEAR:
3622 case I915_FORMAT_MOD_X_TILED:
3627 case I915_FORMAT_MOD_Y_TILED_CCS:
3628 case I915_FORMAT_MOD_Yf_TILED_CCS:
3629 /* FIXME AUX plane? */
3630 case I915_FORMAT_MOD_Y_TILED:
3631 case I915_FORMAT_MOD_Yf_TILED:
3637 MISSING_CASE(fb->modifier);
3642 static int icl_max_plane_width(const struct drm_framebuffer *fb,
3644 unsigned int rotation)
3649 static int skl_max_plane_height(void)
3654 static int icl_max_plane_height(void)
3659 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3660 int main_x, int main_y, u32 main_offset)
3662 const struct drm_framebuffer *fb = plane_state->hw.fb;
3663 int ccs_plane = main_to_ccs_plane(fb, 0);
3664 int aux_x = plane_state->color_plane[ccs_plane].x;
3665 int aux_y = plane_state->color_plane[ccs_plane].y;
3666 u32 aux_offset = plane_state->color_plane[ccs_plane].offset;
3667 u32 alignment = intel_surf_alignment(fb, ccs_plane);
3671 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
3672 while (aux_offset >= main_offset && aux_y <= main_y) {
3675 if (aux_x == main_x && aux_y == main_y)
3678 if (aux_offset == 0)
3683 aux_offset = intel_plane_adjust_aligned_offset(&x, &y,
3689 aux_x = x * hsub + aux_x % hsub;
3690 aux_y = y * vsub + aux_y % vsub;
3693 if (aux_x != main_x || aux_y != main_y)
3696 plane_state->color_plane[ccs_plane].offset = aux_offset;
3697 plane_state->color_plane[ccs_plane].x = aux_x;
3698 plane_state->color_plane[ccs_plane].y = aux_y;
3703 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3705 struct drm_i915_private *dev_priv = to_i915(plane_state->uapi.plane->dev);
3706 const struct drm_framebuffer *fb = plane_state->hw.fb;
3707 unsigned int rotation = plane_state->hw.rotation;
3708 int x = plane_state->uapi.src.x1 >> 16;
3709 int y = plane_state->uapi.src.y1 >> 16;
3710 int w = drm_rect_width(&plane_state->uapi.src) >> 16;
3711 int h = drm_rect_height(&plane_state->uapi.src) >> 16;
3716 int aux_plane = intel_main_to_aux_plane(fb, 0);
3717 u32 aux_offset = plane_state->color_plane[aux_plane].offset;
3719 if (INTEL_GEN(dev_priv) >= 11)
3720 max_width = icl_max_plane_width(fb, 0, rotation);
3721 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3722 max_width = glk_max_plane_width(fb, 0, rotation);
3724 max_width = skl_max_plane_width(fb, 0, rotation);
3726 if (INTEL_GEN(dev_priv) >= 11)
3727 max_height = icl_max_plane_height();
3729 max_height = skl_max_plane_height();
3731 if (w > max_width || h > max_height) {
3732 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3733 w, h, max_width, max_height);
3737 intel_add_fb_offsets(&x, &y, plane_state, 0);
3738 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3739 alignment = intel_surf_alignment(fb, 0);
3742 * AUX surface offset is specified as the distance from the
3743 * main surface offset, and it must be non-negative. Make
3744 * sure that is what we will get.
3746 if (offset > aux_offset)
3747 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3748 offset, aux_offset & ~(alignment - 1));
3751 * When using an X-tiled surface, the plane blows up
3752 * if the x offset + width exceed the stride.
3754 * TODO: linear and Y-tiled seem fine, Yf untested,
3756 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3757 int cpp = fb->format->cpp[0];
3759 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3761 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3765 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3766 offset, offset - alignment);
3771 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3772 * they match with the main surface x/y offsets.
3774 if (is_ccs_modifier(fb->modifier)) {
3775 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3779 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3780 offset, offset - alignment);
3783 if (x != plane_state->color_plane[aux_plane].x ||
3784 y != plane_state->color_plane[aux_plane].y) {
3785 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3790 plane_state->color_plane[0].offset = offset;
3791 plane_state->color_plane[0].x = x;
3792 plane_state->color_plane[0].y = y;
3795 * Put the final coordinates back so that the src
3796 * coordinate checks will see the right values.
3798 drm_rect_translate_to(&plane_state->uapi.src,
3804 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3806 const struct drm_framebuffer *fb = plane_state->hw.fb;
3807 unsigned int rotation = plane_state->hw.rotation;
3808 int max_width = skl_max_plane_width(fb, 1, rotation);
3809 int max_height = 4096;
3810 int x = plane_state->uapi.src.x1 >> 17;
3811 int y = plane_state->uapi.src.y1 >> 17;
3812 int w = drm_rect_width(&plane_state->uapi.src) >> 17;
3813 int h = drm_rect_height(&plane_state->uapi.src) >> 17;
3816 intel_add_fb_offsets(&x, &y, plane_state, 1);
3817 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3819 /* FIXME not quite sure how/if these apply to the chroma plane */
3820 if (w > max_width || h > max_height) {
3821 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3822 w, h, max_width, max_height);
3826 plane_state->color_plane[1].offset = offset;
3827 plane_state->color_plane[1].x = x;
3828 plane_state->color_plane[1].y = y;
3833 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3835 const struct drm_framebuffer *fb = plane_state->hw.fb;
3836 int src_x = plane_state->uapi.src.x1 >> 16;
3837 int src_y = plane_state->uapi.src.y1 >> 16;
3844 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, 1);
3847 intel_add_fb_offsets(&x, &y, plane_state, 1);
3848 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3850 plane_state->color_plane[1].offset = offset;
3851 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3852 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3857 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3859 const struct drm_framebuffer *fb = plane_state->hw.fb;
3862 ret = intel_plane_compute_gtt(plane_state);
3866 if (!plane_state->uapi.visible)
3870 * Handle the AUX surface first since
3871 * the main surface setup depends on it.
3873 if (intel_format_info_is_yuv_semiplanar(fb->format,
3875 ret = skl_check_nv12_aux_surface(plane_state);
3878 } else if (is_ccs_modifier(fb->modifier)) {
3879 ret = skl_check_ccs_aux_surface(plane_state);
3883 plane_state->color_plane[1].offset = ~0xfff;
3884 plane_state->color_plane[1].x = 0;
3885 plane_state->color_plane[1].y = 0;
3888 ret = skl_check_main_surface(plane_state);
3895 static void i9xx_plane_ratio(const struct intel_crtc_state *crtc_state,
3896 const struct intel_plane_state *plane_state,
3897 unsigned int *num, unsigned int *den)
3899 const struct drm_framebuffer *fb = plane_state->hw.fb;
3900 unsigned int cpp = fb->format->cpp[0];
3903 * g4x bspec says 64bpp pixel rate can't exceed 80%
3904 * of cdclk when the sprite plane is enabled on the
3905 * same pipe. ilk/snb bspec says 64bpp pixel rate is
3906 * never allowed to exceed 80% of cdclk. Let's just go
3907 * with the ilk/snb limit always.
3918 static int i9xx_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
3919 const struct intel_plane_state *plane_state)
3921 unsigned int pixel_rate;
3922 unsigned int num, den;
3925 * Note that crtc_state->pixel_rate accounts for both
3926 * horizontal and vertical panel fitter downscaling factors.
3927 * Pre-HSW bspec tells us to only consider the horizontal
3928 * downscaling factor here. We ignore that and just consider
3929 * both for simplicity.
3931 pixel_rate = crtc_state->pixel_rate;
3933 i9xx_plane_ratio(crtc_state, plane_state, &num, &den);
3935 /* two pixels per clock with double wide pipe */
3936 if (crtc_state->double_wide)
3939 return DIV_ROUND_UP(pixel_rate * num, den);
3943 i9xx_plane_max_stride(struct intel_plane *plane,
3944 u32 pixel_format, u64 modifier,
3945 unsigned int rotation)
3947 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3949 if (!HAS_GMCH(dev_priv)) {
3951 } else if (INTEL_GEN(dev_priv) >= 4) {
3952 if (modifier == I915_FORMAT_MOD_X_TILED)
3956 } else if (INTEL_GEN(dev_priv) >= 3) {
3957 if (modifier == I915_FORMAT_MOD_X_TILED)
3962 if (plane->i9xx_plane == PLANE_C)
3969 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3971 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3972 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3975 if (crtc_state->gamma_enable)
3976 dspcntr |= DISPPLANE_GAMMA_ENABLE;
3978 if (crtc_state->csc_enable)
3979 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3981 if (INTEL_GEN(dev_priv) < 5)
3982 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3987 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3988 const struct intel_plane_state *plane_state)
3990 struct drm_i915_private *dev_priv =
3991 to_i915(plane_state->uapi.plane->dev);
3992 const struct drm_framebuffer *fb = plane_state->hw.fb;
3993 unsigned int rotation = plane_state->hw.rotation;
3996 dspcntr = DISPLAY_PLANE_ENABLE;
3998 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3999 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
4000 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
4002 switch (fb->format->format) {
4004 dspcntr |= DISPPLANE_8BPP;
4006 case DRM_FORMAT_XRGB1555:
4007 dspcntr |= DISPPLANE_BGRX555;
4009 case DRM_FORMAT_ARGB1555:
4010 dspcntr |= DISPPLANE_BGRA555;
4012 case DRM_FORMAT_RGB565:
4013 dspcntr |= DISPPLANE_BGRX565;
4015 case DRM_FORMAT_XRGB8888:
4016 dspcntr |= DISPPLANE_BGRX888;
4018 case DRM_FORMAT_XBGR8888:
4019 dspcntr |= DISPPLANE_RGBX888;
4021 case DRM_FORMAT_ARGB8888:
4022 dspcntr |= DISPPLANE_BGRA888;
4024 case DRM_FORMAT_ABGR8888:
4025 dspcntr |= DISPPLANE_RGBA888;
4027 case DRM_FORMAT_XRGB2101010:
4028 dspcntr |= DISPPLANE_BGRX101010;
4030 case DRM_FORMAT_XBGR2101010:
4031 dspcntr |= DISPPLANE_RGBX101010;
4033 case DRM_FORMAT_ARGB2101010:
4034 dspcntr |= DISPPLANE_BGRA101010;
4036 case DRM_FORMAT_ABGR2101010:
4037 dspcntr |= DISPPLANE_RGBA101010;
4039 case DRM_FORMAT_XBGR16161616F:
4040 dspcntr |= DISPPLANE_RGBX161616;
4043 MISSING_CASE(fb->format->format);
4047 if (INTEL_GEN(dev_priv) >= 4 &&
4048 fb->modifier == I915_FORMAT_MOD_X_TILED)
4049 dspcntr |= DISPPLANE_TILED;
4051 if (rotation & DRM_MODE_ROTATE_180)
4052 dspcntr |= DISPPLANE_ROTATE_180;
4054 if (rotation & DRM_MODE_REFLECT_X)
4055 dspcntr |= DISPPLANE_MIRROR;
4060 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
4062 struct drm_i915_private *dev_priv =
4063 to_i915(plane_state->uapi.plane->dev);
4064 const struct drm_framebuffer *fb = plane_state->hw.fb;
4065 int src_x, src_y, src_w;
4069 ret = intel_plane_compute_gtt(plane_state);
4073 if (!plane_state->uapi.visible)
4076 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
4077 src_x = plane_state->uapi.src.x1 >> 16;
4078 src_y = plane_state->uapi.src.y1 >> 16;
4080 /* Undocumented hardware limit on i965/g4x/vlv/chv */
4081 if (HAS_GMCH(dev_priv) && fb->format->cpp[0] == 8 && src_w > 2048)
4084 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
4086 if (INTEL_GEN(dev_priv) >= 4)
4087 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
4093 * Put the final coordinates back so that the src
4094 * coordinate checks will see the right values.
4096 drm_rect_translate_to(&plane_state->uapi.src,
4097 src_x << 16, src_y << 16);
4099 /* HSW/BDW do this automagically in hardware */
4100 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
4101 unsigned int rotation = plane_state->hw.rotation;
4102 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
4103 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
4105 if (rotation & DRM_MODE_ROTATE_180) {
4108 } else if (rotation & DRM_MODE_REFLECT_X) {
4113 plane_state->color_plane[0].offset = offset;
4114 plane_state->color_plane[0].x = src_x;
4115 plane_state->color_plane[0].y = src_y;
4120 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
4122 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4123 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4125 if (IS_CHERRYVIEW(dev_priv))
4126 return i9xx_plane == PLANE_B;
4127 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
4129 else if (IS_GEN(dev_priv, 4))
4130 return i9xx_plane == PLANE_C;
4132 return i9xx_plane == PLANE_B ||
4133 i9xx_plane == PLANE_C;
4137 i9xx_plane_check(struct intel_crtc_state *crtc_state,
4138 struct intel_plane_state *plane_state)
4140 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
4143 ret = chv_plane_check_rotation(plane_state);
4147 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
4149 DRM_PLANE_HELPER_NO_SCALING,
4150 DRM_PLANE_HELPER_NO_SCALING,
4151 i9xx_plane_has_windowing(plane),
4156 ret = i9xx_check_plane_surface(plane_state);
4160 if (!plane_state->uapi.visible)
4163 ret = intel_plane_check_src_coordinates(plane_state);
4167 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
4172 static void i9xx_update_plane(struct intel_plane *plane,
4173 const struct intel_crtc_state *crtc_state,
4174 const struct intel_plane_state *plane_state)
4176 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4177 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4179 int x = plane_state->color_plane[0].x;
4180 int y = plane_state->color_plane[0].y;
4181 int crtc_x = plane_state->uapi.dst.x1;
4182 int crtc_y = plane_state->uapi.dst.y1;
4183 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
4184 int crtc_h = drm_rect_height(&plane_state->uapi.dst);
4185 unsigned long irqflags;
4189 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
4191 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
4193 if (INTEL_GEN(dev_priv) >= 4)
4194 dspaddr_offset = plane_state->color_plane[0].offset;
4196 dspaddr_offset = linear_offset;
4198 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4200 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
4202 if (INTEL_GEN(dev_priv) < 4) {
4204 * PLANE_A doesn't actually have a full window
4205 * generator but let's assume we still need to
4206 * program whatever is there.
4208 I915_WRITE_FW(DSPPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
4209 I915_WRITE_FW(DSPSIZE(i9xx_plane),
4210 ((crtc_h - 1) << 16) | (crtc_w - 1));
4211 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
4212 I915_WRITE_FW(PRIMPOS(i9xx_plane), (crtc_y << 16) | crtc_x);
4213 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
4214 ((crtc_h - 1) << 16) | (crtc_w - 1));
4215 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
4218 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
4219 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
4220 } else if (INTEL_GEN(dev_priv) >= 4) {
4221 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
4222 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
4226 * The control register self-arms if the plane was previously
4227 * disabled. Try to make the plane enable atomic by writing
4228 * the control register just before the surface register.
4230 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
4231 if (INTEL_GEN(dev_priv) >= 4)
4232 I915_WRITE_FW(DSPSURF(i9xx_plane),
4233 intel_plane_ggtt_offset(plane_state) +
4236 I915_WRITE_FW(DSPADDR(i9xx_plane),
4237 intel_plane_ggtt_offset(plane_state) +
4240 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4243 static void i9xx_disable_plane(struct intel_plane *plane,
4244 const struct intel_crtc_state *crtc_state)
4246 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4247 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4248 unsigned long irqflags;
4252 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
4253 * enable on ilk+ affect the pipe bottom color as
4254 * well, so we must configure them even if the plane
4257 * On pre-g4x there is no way to gamma correct the
4258 * pipe bottom color but we'll keep on doing this
4259 * anyway so that the crtc state readout works correctly.
4261 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
4263 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4265 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
4266 if (INTEL_GEN(dev_priv) >= 4)
4267 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
4269 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
4271 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4274 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
4277 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4278 enum intel_display_power_domain power_domain;
4279 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4280 intel_wakeref_t wakeref;
4285 * Not 100% correct for planes that can move between pipes,
4286 * but that's only the case for gen2-4 which don't have any
4287 * display power wells.
4289 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
4290 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
4294 val = I915_READ(DSPCNTR(i9xx_plane));
4296 ret = val & DISPLAY_PLANE_ENABLE;
4298 if (INTEL_GEN(dev_priv) >= 5)
4299 *pipe = plane->pipe;
4301 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
4302 DISPPLANE_SEL_PIPE_SHIFT;
4304 intel_display_power_put(dev_priv, power_domain, wakeref);
4309 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
4311 struct drm_device *dev = intel_crtc->base.dev;
4312 struct drm_i915_private *dev_priv = to_i915(dev);
4314 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
4315 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
4316 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
4320 * This function detaches (aka. unbinds) unused scalers in hardware
4322 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
4324 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
4325 const struct intel_crtc_scaler_state *scaler_state =
4326 &crtc_state->scaler_state;
4329 /* loop through and disable scalers that aren't in use */
4330 for (i = 0; i < intel_crtc->num_scalers; i++) {
4331 if (!scaler_state->scalers[i].in_use)
4332 skl_detach_scaler(intel_crtc, i);
4336 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
4337 int color_plane, unsigned int rotation)
4340 * The stride is either expressed as a multiple of 64 bytes chunks for
4341 * linear buffers or in number of tiles for tiled buffers.
4343 if (is_surface_linear(fb, color_plane))
4345 else if (drm_rotation_90_or_270(rotation))
4346 return intel_tile_height(fb, color_plane);
4348 return intel_tile_width_bytes(fb, color_plane);
4351 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
4354 const struct drm_framebuffer *fb = plane_state->hw.fb;
4355 unsigned int rotation = plane_state->hw.rotation;
4356 u32 stride = plane_state->color_plane[color_plane].stride;
4358 if (color_plane >= fb->format->num_planes)
4361 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
4364 static u32 skl_plane_ctl_format(u32 pixel_format)
4366 switch (pixel_format) {
4368 return PLANE_CTL_FORMAT_INDEXED;
4369 case DRM_FORMAT_RGB565:
4370 return PLANE_CTL_FORMAT_RGB_565;
4371 case DRM_FORMAT_XBGR8888:
4372 case DRM_FORMAT_ABGR8888:
4373 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
4374 case DRM_FORMAT_XRGB8888:
4375 case DRM_FORMAT_ARGB8888:
4376 return PLANE_CTL_FORMAT_XRGB_8888;
4377 case DRM_FORMAT_XBGR2101010:
4378 case DRM_FORMAT_ABGR2101010:
4379 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
4380 case DRM_FORMAT_XRGB2101010:
4381 case DRM_FORMAT_ARGB2101010:
4382 return PLANE_CTL_FORMAT_XRGB_2101010;
4383 case DRM_FORMAT_XBGR16161616F:
4384 case DRM_FORMAT_ABGR16161616F:
4385 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
4386 case DRM_FORMAT_XRGB16161616F:
4387 case DRM_FORMAT_ARGB16161616F:
4388 return PLANE_CTL_FORMAT_XRGB_16161616F;
4389 case DRM_FORMAT_YUYV:
4390 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
4391 case DRM_FORMAT_YVYU:
4392 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
4393 case DRM_FORMAT_UYVY:
4394 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
4395 case DRM_FORMAT_VYUY:
4396 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
4397 case DRM_FORMAT_NV12:
4398 return PLANE_CTL_FORMAT_NV12;
4399 case DRM_FORMAT_P010:
4400 return PLANE_CTL_FORMAT_P010;
4401 case DRM_FORMAT_P012:
4402 return PLANE_CTL_FORMAT_P012;
4403 case DRM_FORMAT_P016:
4404 return PLANE_CTL_FORMAT_P016;
4405 case DRM_FORMAT_Y210:
4406 return PLANE_CTL_FORMAT_Y210;
4407 case DRM_FORMAT_Y212:
4408 return PLANE_CTL_FORMAT_Y212;
4409 case DRM_FORMAT_Y216:
4410 return PLANE_CTL_FORMAT_Y216;
4411 case DRM_FORMAT_XVYU2101010:
4412 return PLANE_CTL_FORMAT_Y410;
4413 case DRM_FORMAT_XVYU12_16161616:
4414 return PLANE_CTL_FORMAT_Y412;
4415 case DRM_FORMAT_XVYU16161616:
4416 return PLANE_CTL_FORMAT_Y416;
4418 MISSING_CASE(pixel_format);
4424 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
4426 if (!plane_state->hw.fb->format->has_alpha)
4427 return PLANE_CTL_ALPHA_DISABLE;
4429 switch (plane_state->hw.pixel_blend_mode) {
4430 case DRM_MODE_BLEND_PIXEL_NONE:
4431 return PLANE_CTL_ALPHA_DISABLE;
4432 case DRM_MODE_BLEND_PREMULTI:
4433 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
4434 case DRM_MODE_BLEND_COVERAGE:
4435 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
4437 MISSING_CASE(plane_state->hw.pixel_blend_mode);
4438 return PLANE_CTL_ALPHA_DISABLE;
4442 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
4444 if (!plane_state->hw.fb->format->has_alpha)
4445 return PLANE_COLOR_ALPHA_DISABLE;
4447 switch (plane_state->hw.pixel_blend_mode) {
4448 case DRM_MODE_BLEND_PIXEL_NONE:
4449 return PLANE_COLOR_ALPHA_DISABLE;
4450 case DRM_MODE_BLEND_PREMULTI:
4451 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
4452 case DRM_MODE_BLEND_COVERAGE:
4453 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
4455 MISSING_CASE(plane_state->hw.pixel_blend_mode);
4456 return PLANE_COLOR_ALPHA_DISABLE;
4460 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
4462 switch (fb_modifier) {
4463 case DRM_FORMAT_MOD_LINEAR:
4465 case I915_FORMAT_MOD_X_TILED:
4466 return PLANE_CTL_TILED_X;
4467 case I915_FORMAT_MOD_Y_TILED:
4468 return PLANE_CTL_TILED_Y;
4469 case I915_FORMAT_MOD_Y_TILED_CCS:
4470 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4471 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
4472 return PLANE_CTL_TILED_Y |
4473 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
4474 PLANE_CTL_CLEAR_COLOR_DISABLE;
4475 case I915_FORMAT_MOD_Yf_TILED:
4476 return PLANE_CTL_TILED_YF;
4477 case I915_FORMAT_MOD_Yf_TILED_CCS:
4478 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4480 MISSING_CASE(fb_modifier);
4486 static u32 skl_plane_ctl_rotate(unsigned int rotate)
4489 case DRM_MODE_ROTATE_0:
4492 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4493 * while i915 HW rotation is clockwise, thats why this swapping.
4495 case DRM_MODE_ROTATE_90:
4496 return PLANE_CTL_ROTATE_270;
4497 case DRM_MODE_ROTATE_180:
4498 return PLANE_CTL_ROTATE_180;
4499 case DRM_MODE_ROTATE_270:
4500 return PLANE_CTL_ROTATE_90;
4502 MISSING_CASE(rotate);
4508 static u32 cnl_plane_ctl_flip(unsigned int reflect)
4513 case DRM_MODE_REFLECT_X:
4514 return PLANE_CTL_FLIP_HORIZONTAL;
4515 case DRM_MODE_REFLECT_Y:
4517 MISSING_CASE(reflect);
4523 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4525 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4528 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4531 if (crtc_state->gamma_enable)
4532 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
4534 if (crtc_state->csc_enable)
4535 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
4540 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
4541 const struct intel_plane_state *plane_state)
4543 struct drm_i915_private *dev_priv =
4544 to_i915(plane_state->uapi.plane->dev);
4545 const struct drm_framebuffer *fb = plane_state->hw.fb;
4546 unsigned int rotation = plane_state->hw.rotation;
4547 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
4550 plane_ctl = PLANE_CTL_ENABLE;
4552 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
4553 plane_ctl |= skl_plane_ctl_alpha(plane_state);
4554 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
4556 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
4557 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
4559 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4560 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
4563 plane_ctl |= skl_plane_ctl_format(fb->format->format);
4564 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
4565 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
4567 if (INTEL_GEN(dev_priv) >= 10)
4568 plane_ctl |= cnl_plane_ctl_flip(rotation &
4569 DRM_MODE_REFLECT_MASK);
4571 if (key->flags & I915_SET_COLORKEY_DESTINATION)
4572 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
4573 else if (key->flags & I915_SET_COLORKEY_SOURCE)
4574 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
4579 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
4581 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4582 u32 plane_color_ctl = 0;
4584 if (INTEL_GEN(dev_priv) >= 11)
4585 return plane_color_ctl;
4587 if (crtc_state->gamma_enable)
4588 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
4590 if (crtc_state->csc_enable)
4591 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
4593 return plane_color_ctl;
4596 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
4597 const struct intel_plane_state *plane_state)
4599 struct drm_i915_private *dev_priv =
4600 to_i915(plane_state->uapi.plane->dev);
4601 const struct drm_framebuffer *fb = plane_state->hw.fb;
4602 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
4603 u32 plane_color_ctl = 0;
4605 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
4606 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
4608 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
4609 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
4610 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
4612 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
4614 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4615 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
4616 } else if (fb->format->is_yuv) {
4617 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
4620 return plane_color_ctl;
4624 __intel_display_resume(struct drm_device *dev,
4625 struct drm_atomic_state *state,
4626 struct drm_modeset_acquire_ctx *ctx)
4628 struct drm_crtc_state *crtc_state;
4629 struct drm_crtc *crtc;
4632 intel_modeset_setup_hw_state(dev, ctx);
4633 intel_vga_redisable(to_i915(dev));
4639 * We've duplicated the state, pointers to the old state are invalid.
4641 * Don't attempt to use the old state until we commit the duplicated state.
4643 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
4645 * Force recalculation even if we restore
4646 * current state. With fast modeset this may not result
4647 * in a modeset when the state is compatible.
4649 crtc_state->mode_changed = true;
4652 /* ignore any reset values/BIOS leftovers in the WM registers */
4653 if (!HAS_GMCH(to_i915(dev)))
4654 to_intel_atomic_state(state)->skip_intermediate_wm = true;
4656 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4658 WARN_ON(ret == -EDEADLK);
4662 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
4664 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
4665 intel_has_gpu_reset(&dev_priv->gt));
4668 void intel_prepare_reset(struct drm_i915_private *dev_priv)
4670 struct drm_device *dev = &dev_priv->drm;
4671 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4672 struct drm_atomic_state *state;
4675 /* reset doesn't touch the display */
4676 if (!i915_modparams.force_reset_modeset_test &&
4677 !gpu_reset_clobbers_display(dev_priv))
4680 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4681 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4682 smp_mb__after_atomic();
4683 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
4685 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
4686 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
4687 intel_gt_set_wedged(&dev_priv->gt);
4691 * Need mode_config.mutex so that we don't
4692 * trample ongoing ->detect() and whatnot.
4694 mutex_lock(&dev->mode_config.mutex);
4695 drm_modeset_acquire_init(ctx, 0);
4697 ret = drm_modeset_lock_all_ctx(dev, ctx);
4698 if (ret != -EDEADLK)
4701 drm_modeset_backoff(ctx);
4704 * Disabling the crtcs gracefully seems nicer. Also the
4705 * g33 docs say we should at least disable all the planes.
4707 state = drm_atomic_helper_duplicate_state(dev, ctx);
4708 if (IS_ERR(state)) {
4709 ret = PTR_ERR(state);
4710 DRM_ERROR("Duplicating state failed with %i\n", ret);
4714 ret = drm_atomic_helper_disable_all(dev, ctx);
4716 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
4717 drm_atomic_state_put(state);
4721 dev_priv->modeset_restore_state = state;
4722 state->acquire_ctx = ctx;
4725 void intel_finish_reset(struct drm_i915_private *dev_priv)
4727 struct drm_device *dev = &dev_priv->drm;
4728 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4729 struct drm_atomic_state *state;
4732 /* reset doesn't touch the display */
4733 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
4736 state = fetch_and_zero(&dev_priv->modeset_restore_state);
4740 /* reset doesn't touch the display */
4741 if (!gpu_reset_clobbers_display(dev_priv)) {
4742 /* for testing only restore the display */
4743 ret = __intel_display_resume(dev, state, ctx);
4745 DRM_ERROR("Restoring old state failed with %i\n", ret);
4748 * The display has been reset as well,
4749 * so need a full re-initialization.
4751 intel_pps_unlock_regs_wa(dev_priv);
4752 intel_modeset_init_hw(dev_priv);
4753 intel_init_clock_gating(dev_priv);
4755 spin_lock_irq(&dev_priv->irq_lock);
4756 if (dev_priv->display.hpd_irq_setup)
4757 dev_priv->display.hpd_irq_setup(dev_priv);
4758 spin_unlock_irq(&dev_priv->irq_lock);
4760 ret = __intel_display_resume(dev, state, ctx);
4762 DRM_ERROR("Restoring old state failed with %i\n", ret);
4764 intel_hpd_init(dev_priv);
4767 drm_atomic_state_put(state);
4769 drm_modeset_drop_locks(ctx);
4770 drm_modeset_acquire_fini(ctx);
4771 mutex_unlock(&dev->mode_config.mutex);
4773 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4776 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4778 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4779 enum pipe pipe = crtc->pipe;
4782 tmp = I915_READ(PIPE_CHICKEN(pipe));
4785 * Display WA #1153: icl
4786 * enable hardware to bypass the alpha math
4787 * and rounding for per-pixel values 00 and 0xff
4789 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4791 * Display WA # 1605353570: icl
4792 * Set the pixel rounding bit to 1 for allowing
4793 * passthrough of Frame buffer pixels unmodified
4796 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
4797 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4800 static void icl_enable_trans_port_sync(const struct intel_crtc_state *crtc_state)
4802 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4803 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4804 u32 trans_ddi_func_ctl2_val;
4808 * Configure the master select and enable Transcoder Port Sync for
4809 * Slave CRTCs transcoder.
4811 if (crtc_state->master_transcoder == INVALID_TRANSCODER)
4814 if (crtc_state->master_transcoder == TRANSCODER_EDP)
4817 master_select = crtc_state->master_transcoder + 1;
4819 /* Set the master select bits for Tranascoder Port Sync */
4820 trans_ddi_func_ctl2_val = (PORT_SYNC_MODE_MASTER_SELECT(master_select) &
4821 PORT_SYNC_MODE_MASTER_SELECT_MASK) <<
4822 PORT_SYNC_MODE_MASTER_SELECT_SHIFT;
4823 /* Enable Transcoder Port Sync */
4824 trans_ddi_func_ctl2_val |= PORT_SYNC_MODE_ENABLE;
4826 I915_WRITE(TRANS_DDI_FUNC_CTL2(crtc_state->cpu_transcoder),
4827 trans_ddi_func_ctl2_val);
4830 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4832 struct drm_device *dev = crtc->base.dev;
4833 struct drm_i915_private *dev_priv = to_i915(dev);
4834 enum pipe pipe = crtc->pipe;
4838 /* enable normal train */
4839 reg = FDI_TX_CTL(pipe);
4840 temp = I915_READ(reg);
4841 if (IS_IVYBRIDGE(dev_priv)) {
4842 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4843 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4845 temp &= ~FDI_LINK_TRAIN_NONE;
4846 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4848 I915_WRITE(reg, temp);
4850 reg = FDI_RX_CTL(pipe);
4851 temp = I915_READ(reg);
4852 if (HAS_PCH_CPT(dev_priv)) {
4853 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4854 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4856 temp &= ~FDI_LINK_TRAIN_NONE;
4857 temp |= FDI_LINK_TRAIN_NONE;
4859 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4861 /* wait one idle pattern time */
4865 /* IVB wants error correction enabled */
4866 if (IS_IVYBRIDGE(dev_priv))
4867 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4868 FDI_FE_ERRC_ENABLE);
4871 /* The FDI link training functions for ILK/Ibexpeak. */
4872 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
4873 const struct intel_crtc_state *crtc_state)
4875 struct drm_device *dev = crtc->base.dev;
4876 struct drm_i915_private *dev_priv = to_i915(dev);
4877 enum pipe pipe = crtc->pipe;
4881 /* FDI needs bits from pipe first */
4882 assert_pipe_enabled(dev_priv, crtc_state->cpu_transcoder);
4884 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4886 reg = FDI_RX_IMR(pipe);
4887 temp = I915_READ(reg);
4888 temp &= ~FDI_RX_SYMBOL_LOCK;
4889 temp &= ~FDI_RX_BIT_LOCK;
4890 I915_WRITE(reg, temp);
4894 /* enable CPU FDI TX and PCH FDI RX */
4895 reg = FDI_TX_CTL(pipe);
4896 temp = I915_READ(reg);
4897 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4898 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4899 temp &= ~FDI_LINK_TRAIN_NONE;
4900 temp |= FDI_LINK_TRAIN_PATTERN_1;
4901 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4903 reg = FDI_RX_CTL(pipe);
4904 temp = I915_READ(reg);
4905 temp &= ~FDI_LINK_TRAIN_NONE;
4906 temp |= FDI_LINK_TRAIN_PATTERN_1;
4907 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4912 /* Ironlake workaround, enable clock pointer after FDI enable*/
4913 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4914 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4915 FDI_RX_PHASE_SYNC_POINTER_EN);
4917 reg = FDI_RX_IIR(pipe);
4918 for (tries = 0; tries < 5; tries++) {
4919 temp = I915_READ(reg);
4920 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4922 if ((temp & FDI_RX_BIT_LOCK)) {
4923 DRM_DEBUG_KMS("FDI train 1 done.\n");
4924 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4929 DRM_ERROR("FDI train 1 fail!\n");
4932 reg = FDI_TX_CTL(pipe);
4933 temp = I915_READ(reg);
4934 temp &= ~FDI_LINK_TRAIN_NONE;
4935 temp |= FDI_LINK_TRAIN_PATTERN_2;
4936 I915_WRITE(reg, temp);
4938 reg = FDI_RX_CTL(pipe);
4939 temp = I915_READ(reg);
4940 temp &= ~FDI_LINK_TRAIN_NONE;
4941 temp |= FDI_LINK_TRAIN_PATTERN_2;
4942 I915_WRITE(reg, temp);
4947 reg = FDI_RX_IIR(pipe);
4948 for (tries = 0; tries < 5; tries++) {
4949 temp = I915_READ(reg);
4950 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4952 if (temp & FDI_RX_SYMBOL_LOCK) {
4953 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4954 DRM_DEBUG_KMS("FDI train 2 done.\n");
4959 DRM_ERROR("FDI train 2 fail!\n");
4961 DRM_DEBUG_KMS("FDI train done\n");
4965 static const int snb_b_fdi_train_param[] = {
4966 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4967 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4968 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4969 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4972 /* The FDI link training functions for SNB/Cougarpoint. */
4973 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4974 const struct intel_crtc_state *crtc_state)
4976 struct drm_device *dev = crtc->base.dev;
4977 struct drm_i915_private *dev_priv = to_i915(dev);
4978 enum pipe pipe = crtc->pipe;
4982 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4984 reg = FDI_RX_IMR(pipe);
4985 temp = I915_READ(reg);
4986 temp &= ~FDI_RX_SYMBOL_LOCK;
4987 temp &= ~FDI_RX_BIT_LOCK;
4988 I915_WRITE(reg, temp);
4993 /* enable CPU FDI TX and PCH FDI RX */
4994 reg = FDI_TX_CTL(pipe);
4995 temp = I915_READ(reg);
4996 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4997 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4998 temp &= ~FDI_LINK_TRAIN_NONE;
4999 temp |= FDI_LINK_TRAIN_PATTERN_1;
5000 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5002 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
5003 I915_WRITE(reg, temp | FDI_TX_ENABLE);
5005 I915_WRITE(FDI_RX_MISC(pipe),
5006 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
5008 reg = FDI_RX_CTL(pipe);
5009 temp = I915_READ(reg);
5010 if (HAS_PCH_CPT(dev_priv)) {
5011 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5012 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5014 temp &= ~FDI_LINK_TRAIN_NONE;
5015 temp |= FDI_LINK_TRAIN_PATTERN_1;
5017 I915_WRITE(reg, temp | FDI_RX_ENABLE);
5022 for (i = 0; i < 4; i++) {
5023 reg = FDI_TX_CTL(pipe);
5024 temp = I915_READ(reg);
5025 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5026 temp |= snb_b_fdi_train_param[i];
5027 I915_WRITE(reg, temp);
5032 for (retry = 0; retry < 5; retry++) {
5033 reg = FDI_RX_IIR(pipe);
5034 temp = I915_READ(reg);
5035 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
5036 if (temp & FDI_RX_BIT_LOCK) {
5037 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
5038 DRM_DEBUG_KMS("FDI train 1 done.\n");
5047 DRM_ERROR("FDI train 1 fail!\n");
5050 reg = FDI_TX_CTL(pipe);
5051 temp = I915_READ(reg);
5052 temp &= ~FDI_LINK_TRAIN_NONE;
5053 temp |= FDI_LINK_TRAIN_PATTERN_2;
5054 if (IS_GEN(dev_priv, 6)) {
5055 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5057 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
5059 I915_WRITE(reg, temp);
5061 reg = FDI_RX_CTL(pipe);
5062 temp = I915_READ(reg);
5063 if (HAS_PCH_CPT(dev_priv)) {
5064 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5065 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
5067 temp &= ~FDI_LINK_TRAIN_NONE;
5068 temp |= FDI_LINK_TRAIN_PATTERN_2;
5070 I915_WRITE(reg, temp);
5075 for (i = 0; i < 4; i++) {
5076 reg = FDI_TX_CTL(pipe);
5077 temp = I915_READ(reg);
5078 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5079 temp |= snb_b_fdi_train_param[i];
5080 I915_WRITE(reg, temp);
5085 for (retry = 0; retry < 5; retry++) {
5086 reg = FDI_RX_IIR(pipe);
5087 temp = I915_READ(reg);
5088 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
5089 if (temp & FDI_RX_SYMBOL_LOCK) {
5090 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
5091 DRM_DEBUG_KMS("FDI train 2 done.\n");
5100 DRM_ERROR("FDI train 2 fail!\n");
5102 DRM_DEBUG_KMS("FDI train done.\n");
5105 /* Manual link training for Ivy Bridge A0 parts */
5106 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
5107 const struct intel_crtc_state *crtc_state)
5109 struct drm_device *dev = crtc->base.dev;
5110 struct drm_i915_private *dev_priv = to_i915(dev);
5111 enum pipe pipe = crtc->pipe;
5115 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5117 reg = FDI_RX_IMR(pipe);
5118 temp = I915_READ(reg);
5119 temp &= ~FDI_RX_SYMBOL_LOCK;
5120 temp &= ~FDI_RX_BIT_LOCK;
5121 I915_WRITE(reg, temp);
5126 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
5127 I915_READ(FDI_RX_IIR(pipe)));
5129 /* Try each vswing and preemphasis setting twice before moving on */
5130 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
5131 /* disable first in case we need to retry */
5132 reg = FDI_TX_CTL(pipe);
5133 temp = I915_READ(reg);
5134 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
5135 temp &= ~FDI_TX_ENABLE;
5136 I915_WRITE(reg, temp);
5138 reg = FDI_RX_CTL(pipe);
5139 temp = I915_READ(reg);
5140 temp &= ~FDI_LINK_TRAIN_AUTO;
5141 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5142 temp &= ~FDI_RX_ENABLE;
5143 I915_WRITE(reg, temp);
5145 /* enable CPU FDI TX and PCH FDI RX */
5146 reg = FDI_TX_CTL(pipe);
5147 temp = I915_READ(reg);
5148 temp &= ~FDI_DP_PORT_WIDTH_MASK;
5149 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5150 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
5151 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5152 temp |= snb_b_fdi_train_param[j/2];
5153 temp |= FDI_COMPOSITE_SYNC;
5154 I915_WRITE(reg, temp | FDI_TX_ENABLE);
5156 I915_WRITE(FDI_RX_MISC(pipe),
5157 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
5159 reg = FDI_RX_CTL(pipe);
5160 temp = I915_READ(reg);
5161 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5162 temp |= FDI_COMPOSITE_SYNC;
5163 I915_WRITE(reg, temp | FDI_RX_ENABLE);
5166 udelay(1); /* should be 0.5us */
5168 for (i = 0; i < 4; i++) {
5169 reg = FDI_RX_IIR(pipe);
5170 temp = I915_READ(reg);
5171 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
5173 if (temp & FDI_RX_BIT_LOCK ||
5174 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
5175 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
5176 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
5180 udelay(1); /* should be 0.5us */
5183 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
5188 reg = FDI_TX_CTL(pipe);
5189 temp = I915_READ(reg);
5190 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
5191 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
5192 I915_WRITE(reg, temp);
5194 reg = FDI_RX_CTL(pipe);
5195 temp = I915_READ(reg);
5196 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5197 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
5198 I915_WRITE(reg, temp);
5201 udelay(2); /* should be 1.5us */
5203 for (i = 0; i < 4; i++) {
5204 reg = FDI_RX_IIR(pipe);
5205 temp = I915_READ(reg);
5206 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
5208 if (temp & FDI_RX_SYMBOL_LOCK ||
5209 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
5210 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
5211 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
5215 udelay(2); /* should be 1.5us */
5218 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
5222 DRM_DEBUG_KMS("FDI train done.\n");
5225 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
5227 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
5228 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5229 enum pipe pipe = intel_crtc->pipe;
5233 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
5234 reg = FDI_RX_CTL(pipe);
5235 temp = I915_READ(reg);
5236 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
5237 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5238 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5239 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
5244 /* Switch from Rawclk to PCDclk */
5245 temp = I915_READ(reg);
5246 I915_WRITE(reg, temp | FDI_PCDCLK);
5251 /* Enable CPU FDI TX PLL, always on for Ironlake */
5252 reg = FDI_TX_CTL(pipe);
5253 temp = I915_READ(reg);
5254 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
5255 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
5262 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
5264 struct drm_device *dev = intel_crtc->base.dev;
5265 struct drm_i915_private *dev_priv = to_i915(dev);
5266 enum pipe pipe = intel_crtc->pipe;
5270 /* Switch from PCDclk to Rawclk */
5271 reg = FDI_RX_CTL(pipe);
5272 temp = I915_READ(reg);
5273 I915_WRITE(reg, temp & ~FDI_PCDCLK);
5275 /* Disable CPU FDI TX PLL */
5276 reg = FDI_TX_CTL(pipe);
5277 temp = I915_READ(reg);
5278 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
5283 reg = FDI_RX_CTL(pipe);
5284 temp = I915_READ(reg);
5285 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
5287 /* Wait for the clocks to turn off. */
5292 static void ironlake_fdi_disable(struct intel_crtc *crtc)
5294 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5295 enum pipe pipe = crtc->pipe;
5299 /* disable CPU FDI tx and PCH FDI rx */
5300 reg = FDI_TX_CTL(pipe);
5301 temp = I915_READ(reg);
5302 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
5305 reg = FDI_RX_CTL(pipe);
5306 temp = I915_READ(reg);
5307 temp &= ~(0x7 << 16);
5308 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5309 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
5314 /* Ironlake workaround, disable clock pointer after downing FDI */
5315 if (HAS_PCH_IBX(dev_priv))
5316 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
5318 /* still set train pattern 1 */
5319 reg = FDI_TX_CTL(pipe);
5320 temp = I915_READ(reg);
5321 temp &= ~FDI_LINK_TRAIN_NONE;
5322 temp |= FDI_LINK_TRAIN_PATTERN_1;
5323 I915_WRITE(reg, temp);
5325 reg = FDI_RX_CTL(pipe);
5326 temp = I915_READ(reg);
5327 if (HAS_PCH_CPT(dev_priv)) {
5328 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5329 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5331 temp &= ~FDI_LINK_TRAIN_NONE;
5332 temp |= FDI_LINK_TRAIN_PATTERN_1;
5334 /* BPC in FDI rx is consistent with that in PIPECONF */
5335 temp &= ~(0x07 << 16);
5336 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5337 I915_WRITE(reg, temp);
5343 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
5345 struct drm_crtc *crtc;
5348 drm_for_each_crtc(crtc, &dev_priv->drm) {
5349 struct drm_crtc_commit *commit;
5350 spin_lock(&crtc->commit_lock);
5351 commit = list_first_entry_or_null(&crtc->commit_list,
5352 struct drm_crtc_commit, commit_entry);
5353 cleanup_done = commit ?
5354 try_wait_for_completion(&commit->cleanup_done) : true;
5355 spin_unlock(&crtc->commit_lock);
5360 drm_crtc_wait_one_vblank(crtc);
5368 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
5372 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
5374 mutex_lock(&dev_priv->sb_lock);
5376 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5377 temp |= SBI_SSCCTL_DISABLE;
5378 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5380 mutex_unlock(&dev_priv->sb_lock);
5383 /* Program iCLKIP clock to the desired frequency */
5384 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
5386 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5387 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5388 int clock = crtc_state->hw.adjusted_mode.crtc_clock;
5389 u32 divsel, phaseinc, auxdiv, phasedir = 0;
5392 lpt_disable_iclkip(dev_priv);
5394 /* The iCLK virtual clock root frequency is in MHz,
5395 * but the adjusted_mode->crtc_clock in in KHz. To get the
5396 * divisors, it is necessary to divide one by another, so we
5397 * convert the virtual clock precision to KHz here for higher
5400 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
5401 u32 iclk_virtual_root_freq = 172800 * 1000;
5402 u32 iclk_pi_range = 64;
5403 u32 desired_divisor;
5405 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5407 divsel = (desired_divisor / iclk_pi_range) - 2;
5408 phaseinc = desired_divisor % iclk_pi_range;
5411 * Near 20MHz is a corner case which is
5412 * out of range for the 7-bit divisor
5418 /* This should not happen with any sane values */
5419 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5420 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5421 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
5422 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5424 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5431 mutex_lock(&dev_priv->sb_lock);
5433 /* Program SSCDIVINTPHASE6 */
5434 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5435 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5436 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5437 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5438 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5439 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5440 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5441 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5443 /* Program SSCAUXDIV */
5444 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5445 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5446 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5447 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5449 /* Enable modulator and associated divider */
5450 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5451 temp &= ~SBI_SSCCTL_DISABLE;
5452 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5454 mutex_unlock(&dev_priv->sb_lock);
5456 /* Wait for initialization time */
5459 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5462 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5464 u32 divsel, phaseinc, auxdiv;
5465 u32 iclk_virtual_root_freq = 172800 * 1000;
5466 u32 iclk_pi_range = 64;
5467 u32 desired_divisor;
5470 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5473 mutex_lock(&dev_priv->sb_lock);
5475 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5476 if (temp & SBI_SSCCTL_DISABLE) {
5477 mutex_unlock(&dev_priv->sb_lock);
5481 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5482 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5483 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5484 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5485 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5487 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5488 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5489 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5491 mutex_unlock(&dev_priv->sb_lock);
5493 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5495 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5496 desired_divisor << auxdiv);
5499 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5500 enum pipe pch_transcoder)
5502 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5503 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5504 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5506 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
5507 I915_READ(HTOTAL(cpu_transcoder)));
5508 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
5509 I915_READ(HBLANK(cpu_transcoder)));
5510 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
5511 I915_READ(HSYNC(cpu_transcoder)));
5513 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
5514 I915_READ(VTOTAL(cpu_transcoder)));
5515 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
5516 I915_READ(VBLANK(cpu_transcoder)));
5517 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
5518 I915_READ(VSYNC(cpu_transcoder)));
5519 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5520 I915_READ(VSYNCSHIFT(cpu_transcoder)));
5523 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5527 temp = I915_READ(SOUTH_CHICKEN1);
5528 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5531 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5532 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5534 temp &= ~FDI_BC_BIFURCATION_SELECT;
5536 temp |= FDI_BC_BIFURCATION_SELECT;
5538 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
5539 I915_WRITE(SOUTH_CHICKEN1, temp);
5540 POSTING_READ(SOUTH_CHICKEN1);
5543 static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5545 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5546 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5548 switch (crtc->pipe) {
5552 if (crtc_state->fdi_lanes > 2)
5553 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5555 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5559 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5568 * Finds the encoder associated with the given CRTC. This can only be
5569 * used when we know that the CRTC isn't feeding multiple encoders!
5571 static struct intel_encoder *
5572 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5573 const struct intel_crtc_state *crtc_state)
5575 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5576 const struct drm_connector_state *connector_state;
5577 const struct drm_connector *connector;
5578 struct intel_encoder *encoder = NULL;
5579 int num_encoders = 0;
5582 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5583 if (connector_state->crtc != &crtc->base)
5586 encoder = to_intel_encoder(connector_state->best_encoder);
5590 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
5591 num_encoders, pipe_name(crtc->pipe));
5597 * Enable PCH resources required for PCH ports:
5599 * - FDI training & RX/TX
5600 * - update transcoder timings
5601 * - DP transcoding bits
5604 static void ironlake_pch_enable(const struct intel_atomic_state *state,
5605 const struct intel_crtc_state *crtc_state)
5607 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5608 struct drm_device *dev = crtc->base.dev;
5609 struct drm_i915_private *dev_priv = to_i915(dev);
5610 enum pipe pipe = crtc->pipe;
5613 assert_pch_transcoder_disabled(dev_priv, pipe);
5615 if (IS_IVYBRIDGE(dev_priv))
5616 ivybridge_update_fdi_bc_bifurcation(crtc_state);
5618 /* Write the TU size bits before fdi link training, so that error
5619 * detection works. */
5620 I915_WRITE(FDI_RX_TUSIZE1(pipe),
5621 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5623 /* For PCH output, training FDI link */
5624 dev_priv->display.fdi_link_train(crtc, crtc_state);
5626 /* We need to program the right clock selection before writing the pixel
5627 * mutliplier into the DPLL. */
5628 if (HAS_PCH_CPT(dev_priv)) {
5631 temp = I915_READ(PCH_DPLL_SEL);
5632 temp |= TRANS_DPLL_ENABLE(pipe);
5633 sel = TRANS_DPLLB_SEL(pipe);
5634 if (crtc_state->shared_dpll ==
5635 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5639 I915_WRITE(PCH_DPLL_SEL, temp);
5642 /* XXX: pch pll's can be enabled any time before we enable the PCH
5643 * transcoder, and we actually should do this to not upset any PCH
5644 * transcoder that already use the clock when we share it.
5646 * Note that enable_shared_dpll tries to do the right thing, but
5647 * get_shared_dpll unconditionally resets the pll - we need that to have
5648 * the right LVDS enable sequence. */
5649 intel_enable_shared_dpll(crtc_state);
5651 /* set transcoder timing, panel must allow it */
5652 assert_panel_unlocked(dev_priv, pipe);
5653 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
5655 intel_fdi_normal_train(crtc);
5657 /* For PCH DP, enable TRANS_DP_CTL */
5658 if (HAS_PCH_CPT(dev_priv) &&
5659 intel_crtc_has_dp_encoder(crtc_state)) {
5660 const struct drm_display_mode *adjusted_mode =
5661 &crtc_state->hw.adjusted_mode;
5662 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5663 i915_reg_t reg = TRANS_DP_CTL(pipe);
5666 temp = I915_READ(reg);
5667 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5668 TRANS_DP_SYNC_MASK |
5670 temp |= TRANS_DP_OUTPUT_ENABLE;
5671 temp |= bpc << 9; /* same format but at 11:9 */
5673 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5674 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5675 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5676 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5678 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5679 WARN_ON(port < PORT_B || port > PORT_D);
5680 temp |= TRANS_DP_PORT_SEL(port);
5682 I915_WRITE(reg, temp);
5685 ironlake_enable_pch_transcoder(crtc_state);
5688 static void lpt_pch_enable(const struct intel_atomic_state *state,
5689 const struct intel_crtc_state *crtc_state)
5691 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5692 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5693 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5695 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5697 lpt_program_iclkip(crtc_state);
5699 /* Set transcoder timing. */
5700 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
5702 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5705 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
5708 i915_reg_t dslreg = PIPEDSL(pipe);
5711 temp = I915_READ(dslreg);
5713 if (wait_for(I915_READ(dslreg) != temp, 5)) {
5714 if (wait_for(I915_READ(dslreg) != temp, 5))
5715 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
5720 * The hardware phase 0.0 refers to the center of the pixel.
5721 * We want to start from the top/left edge which is phase
5722 * -0.5. That matches how the hardware calculates the scaling
5723 * factors (from top-left of the first pixel to bottom-right
5724 * of the last pixel, as opposed to the pixel centers).
5726 * For 4:2:0 subsampled chroma planes we obviously have to
5727 * adjust that so that the chroma sample position lands in
5730 * Note that for packed YCbCr 4:2:2 formats there is no way to
5731 * control chroma siting. The hardware simply replicates the
5732 * chroma samples for both of the luma samples, and thus we don't
5733 * actually get the expected MPEG2 chroma siting convention :(
5734 * The same behaviour is observed on pre-SKL platforms as well.
5736 * Theory behind the formula (note that we ignore sub-pixel
5737 * source coordinates):
5738 * s = source sample position
5739 * d = destination sample position
5744 * | | 1.5 (initial phase)
5752 * | -0.375 (initial phase)
5759 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5761 int phase = -0x8000;
5765 phase += (sub - 1) * 0x8000 / sub;
5767 phase += scale / (2 * sub);
5770 * Hardware initial phase limited to [-0.5:1.5].
5771 * Since the max hardware scale factor is 3.0, we
5772 * should never actually excdeed 1.0 here.
5774 WARN_ON(phase < -0x8000 || phase > 0x18000);
5777 phase = 0x10000 + phase;
5779 trip = PS_PHASE_TRIP;
5781 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5784 #define SKL_MIN_SRC_W 8
5785 #define SKL_MAX_SRC_W 4096
5786 #define SKL_MIN_SRC_H 8
5787 #define SKL_MAX_SRC_H 4096
5788 #define SKL_MIN_DST_W 8
5789 #define SKL_MAX_DST_W 4096
5790 #define SKL_MIN_DST_H 8
5791 #define SKL_MAX_DST_H 4096
5792 #define ICL_MAX_SRC_W 5120
5793 #define ICL_MAX_SRC_H 4096
5794 #define ICL_MAX_DST_W 5120
5795 #define ICL_MAX_DST_H 4096
5796 #define SKL_MIN_YUV_420_SRC_W 16
5797 #define SKL_MIN_YUV_420_SRC_H 16
5800 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5801 unsigned int scaler_user, int *scaler_id,
5802 int src_w, int src_h, int dst_w, int dst_h,
5803 const struct drm_format_info *format,
5804 u64 modifier, bool need_scaler)
5806 struct intel_crtc_scaler_state *scaler_state =
5807 &crtc_state->scaler_state;
5808 struct intel_crtc *intel_crtc =
5809 to_intel_crtc(crtc_state->uapi.crtc);
5810 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5811 const struct drm_display_mode *adjusted_mode =
5812 &crtc_state->hw.adjusted_mode;
5815 * Src coordinates are already rotated by 270 degrees for
5816 * the 90/270 degree plane rotation cases (to match the
5817 * GTT mapping), hence no need to account for rotation here.
5819 if (src_w != dst_w || src_h != dst_h)
5823 * Scaling/fitting not supported in IF-ID mode in GEN9+
5824 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5825 * Once NV12 is enabled, handle it here while allocating scaler
5828 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->hw.enable &&
5829 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5830 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5835 * if plane is being disabled or scaler is no more required or force detach
5836 * - free scaler binded to this plane/crtc
5837 * - in order to do this, update crtc->scaler_usage
5839 * Here scaler state in crtc_state is set free so that
5840 * scaler can be assigned to other user. Actual register
5841 * update to free the scaler is done in plane/panel-fit programming.
5842 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5844 if (force_detach || !need_scaler) {
5845 if (*scaler_id >= 0) {
5846 scaler_state->scaler_users &= ~(1 << scaler_user);
5847 scaler_state->scalers[*scaler_id].in_use = 0;
5849 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5850 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5851 intel_crtc->pipe, scaler_user, *scaler_id,
5852 scaler_state->scaler_users);
5858 if (format && intel_format_info_is_yuv_semiplanar(format, modifier) &&
5859 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5860 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
5865 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5866 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5867 (INTEL_GEN(dev_priv) >= 11 &&
5868 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5869 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5870 (INTEL_GEN(dev_priv) < 11 &&
5871 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5872 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5873 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
5874 "size is out of scaler range\n",
5875 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
5879 /* mark this plane as a scaler user in crtc_state */
5880 scaler_state->scaler_users |= (1 << scaler_user);
5881 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5882 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5883 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5884 scaler_state->scaler_users);
5890 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5892 * @state: crtc's scaler state
5895 * 0 - scaler_usage updated successfully
5896 * error - requested scaling cannot be supported or other error condition
5898 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5900 const struct drm_display_mode *adjusted_mode = &state->hw.adjusted_mode;
5901 bool need_scaler = false;
5903 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5906 return skl_update_scaler(state, !state->hw.active, SKL_CRTC_INDEX,
5907 &state->scaler_state.scaler_id,
5908 state->pipe_src_w, state->pipe_src_h,
5909 adjusted_mode->crtc_hdisplay,
5910 adjusted_mode->crtc_vdisplay, NULL, 0,
5915 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5916 * @crtc_state: crtc's scaler state
5917 * @plane_state: atomic plane state to update
5920 * 0 - scaler_usage updated successfully
5921 * error - requested scaling cannot be supported or other error condition
5923 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5924 struct intel_plane_state *plane_state)
5926 struct intel_plane *intel_plane =
5927 to_intel_plane(plane_state->uapi.plane);
5928 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5929 struct drm_framebuffer *fb = plane_state->hw.fb;
5931 bool force_detach = !fb || !plane_state->uapi.visible;
5932 bool need_scaler = false;
5934 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5935 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5936 fb && intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
5939 ret = skl_update_scaler(crtc_state, force_detach,
5940 drm_plane_index(&intel_plane->base),
5941 &plane_state->scaler_id,
5942 drm_rect_width(&plane_state->uapi.src) >> 16,
5943 drm_rect_height(&plane_state->uapi.src) >> 16,
5944 drm_rect_width(&plane_state->uapi.dst),
5945 drm_rect_height(&plane_state->uapi.dst),
5946 fb ? fb->format : NULL,
5947 fb ? fb->modifier : 0,
5950 if (ret || plane_state->scaler_id < 0)
5953 /* check colorkey */
5954 if (plane_state->ckey.flags) {
5955 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5956 intel_plane->base.base.id,
5957 intel_plane->base.name);
5961 /* Check src format */
5962 switch (fb->format->format) {
5963 case DRM_FORMAT_RGB565:
5964 case DRM_FORMAT_XBGR8888:
5965 case DRM_FORMAT_XRGB8888:
5966 case DRM_FORMAT_ABGR8888:
5967 case DRM_FORMAT_ARGB8888:
5968 case DRM_FORMAT_XRGB2101010:
5969 case DRM_FORMAT_XBGR2101010:
5970 case DRM_FORMAT_ARGB2101010:
5971 case DRM_FORMAT_ABGR2101010:
5972 case DRM_FORMAT_YUYV:
5973 case DRM_FORMAT_YVYU:
5974 case DRM_FORMAT_UYVY:
5975 case DRM_FORMAT_VYUY:
5976 case DRM_FORMAT_NV12:
5977 case DRM_FORMAT_P010:
5978 case DRM_FORMAT_P012:
5979 case DRM_FORMAT_P016:
5980 case DRM_FORMAT_Y210:
5981 case DRM_FORMAT_Y212:
5982 case DRM_FORMAT_Y216:
5983 case DRM_FORMAT_XVYU2101010:
5984 case DRM_FORMAT_XVYU12_16161616:
5985 case DRM_FORMAT_XVYU16161616:
5987 case DRM_FORMAT_XBGR16161616F:
5988 case DRM_FORMAT_ABGR16161616F:
5989 case DRM_FORMAT_XRGB16161616F:
5990 case DRM_FORMAT_ARGB16161616F:
5991 if (INTEL_GEN(dev_priv) >= 11)
5995 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5996 intel_plane->base.base.id, intel_plane->base.name,
5997 fb->base.id, fb->format->format);
6004 void skylake_scaler_disable(const struct intel_crtc_state *old_crtc_state)
6006 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
6009 for (i = 0; i < crtc->num_scalers; i++)
6010 skl_detach_scaler(crtc, i);
6013 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
6015 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6016 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6017 enum pipe pipe = crtc->pipe;
6018 const struct intel_crtc_scaler_state *scaler_state =
6019 &crtc_state->scaler_state;
6021 if (crtc_state->pch_pfit.enabled) {
6022 u16 uv_rgb_hphase, uv_rgb_vphase;
6023 int pfit_w, pfit_h, hscale, vscale;
6026 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
6029 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
6030 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
6032 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
6033 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
6035 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
6036 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
6038 id = scaler_state->scaler_id;
6039 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
6040 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
6041 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
6042 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
6043 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
6044 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
6045 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
6046 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
6050 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
6052 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6053 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6054 enum pipe pipe = crtc->pipe;
6056 if (crtc_state->pch_pfit.enabled) {
6057 /* Force use of hard-coded filter coefficients
6058 * as some pre-programmed values are broken,
6061 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
6062 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
6063 PF_PIPE_SEL_IVB(pipe));
6065 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
6066 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
6067 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
6071 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
6073 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6074 struct drm_device *dev = crtc->base.dev;
6075 struct drm_i915_private *dev_priv = to_i915(dev);
6077 if (!crtc_state->ips_enabled)
6081 * We can only enable IPS after we enable a plane and wait for a vblank
6082 * This function is called from post_plane_update, which is run after
6085 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
6087 if (IS_BROADWELL(dev_priv)) {
6088 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
6089 IPS_ENABLE | IPS_PCODE_CONTROL));
6090 /* Quoting Art Runyan: "its not safe to expect any particular
6091 * value in IPS_CTL bit 31 after enabling IPS through the
6092 * mailbox." Moreover, the mailbox may return a bogus state,
6093 * so we need to just enable it and continue on.
6096 I915_WRITE(IPS_CTL, IPS_ENABLE);
6097 /* The bit only becomes 1 in the next vblank, so this wait here
6098 * is essentially intel_wait_for_vblank. If we don't have this
6099 * and don't wait for vblanks until the end of crtc_enable, then
6100 * the HW state readout code will complain that the expected
6101 * IPS_CTL value is not the one we read. */
6102 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
6103 DRM_ERROR("Timed out waiting for IPS enable\n");
6107 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
6109 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6110 struct drm_device *dev = crtc->base.dev;
6111 struct drm_i915_private *dev_priv = to_i915(dev);
6113 if (!crtc_state->ips_enabled)
6116 if (IS_BROADWELL(dev_priv)) {
6117 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
6119 * Wait for PCODE to finish disabling IPS. The BSpec specified
6120 * 42ms timeout value leads to occasional timeouts so use 100ms
6123 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
6124 DRM_ERROR("Timed out waiting for IPS disable\n");
6126 I915_WRITE(IPS_CTL, 0);
6127 POSTING_READ(IPS_CTL);
6130 /* We need to wait for a vblank before we can disable the plane. */
6131 intel_wait_for_vblank(dev_priv, crtc->pipe);
6134 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
6136 if (intel_crtc->overlay)
6137 (void) intel_overlay_switch_off(intel_crtc->overlay);
6139 /* Let userspace switch the overlay on again. In most cases userspace
6140 * has to recompute where to put it anyway.
6144 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
6145 const struct intel_crtc_state *new_crtc_state)
6147 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6148 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6150 if (!old_crtc_state->ips_enabled)
6153 if (needs_modeset(new_crtc_state))
6157 * Workaround : Do not read or write the pipe palette/gamma data while
6158 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6160 * Disable IPS before we program the LUT.
6162 if (IS_HASWELL(dev_priv) &&
6163 (new_crtc_state->uapi.color_mgmt_changed ||
6164 new_crtc_state->update_pipe) &&
6165 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6168 return !new_crtc_state->ips_enabled;
6171 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
6172 const struct intel_crtc_state *new_crtc_state)
6174 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6175 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6177 if (!new_crtc_state->ips_enabled)
6180 if (needs_modeset(new_crtc_state))
6184 * Workaround : Do not read or write the pipe palette/gamma data while
6185 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6187 * Re-enable IPS after the LUT has been programmed.
6189 if (IS_HASWELL(dev_priv) &&
6190 (new_crtc_state->uapi.color_mgmt_changed ||
6191 new_crtc_state->update_pipe) &&
6192 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6196 * We can't read out IPS on broadwell, assume the worst and
6197 * forcibly enable IPS on the first fastset.
6199 if (new_crtc_state->update_pipe &&
6200 old_crtc_state->hw.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
6203 return !old_crtc_state->ips_enabled;
6206 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
6208 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6210 if (!crtc_state->nv12_planes)
6213 /* WA Display #0827: Gen9:all */
6214 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
6220 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
6222 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6224 /* Wa_2006604312:icl */
6225 if (crtc_state->scaler_state.scaler_users > 0 && IS_ICELAKE(dev_priv))
6231 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
6232 const struct intel_crtc_state *new_crtc_state)
6234 return (!old_crtc_state->active_planes || needs_modeset(new_crtc_state)) &&
6235 new_crtc_state->active_planes;
6238 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
6239 const struct intel_crtc_state *new_crtc_state)
6241 return old_crtc_state->active_planes &&
6242 (!new_crtc_state->active_planes || needs_modeset(new_crtc_state));
6245 static void intel_post_plane_update(struct intel_atomic_state *state,
6246 struct intel_crtc *crtc)
6248 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6249 struct intel_plane *primary = to_intel_plane(crtc->base.primary);
6250 const struct intel_crtc_state *old_crtc_state =
6251 intel_atomic_get_old_crtc_state(state, crtc);
6252 const struct intel_crtc_state *new_crtc_state =
6253 intel_atomic_get_new_crtc_state(state, crtc);
6254 const struct intel_plane_state *new_primary_state =
6255 intel_atomic_get_new_plane_state(state, primary);
6256 enum pipe pipe = crtc->pipe;
6258 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
6260 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
6261 intel_update_watermarks(crtc);
6263 if (hsw_post_update_enable_ips(old_crtc_state, new_crtc_state))
6264 hsw_enable_ips(new_crtc_state);
6266 if (new_primary_state)
6267 intel_fbc_post_update(crtc);
6269 if (needs_nv12_wa(old_crtc_state) &&
6270 !needs_nv12_wa(new_crtc_state))
6271 skl_wa_827(dev_priv, pipe, false);
6273 if (needs_scalerclk_wa(old_crtc_state) &&
6274 !needs_scalerclk_wa(new_crtc_state))
6275 icl_wa_scalerclkgating(dev_priv, pipe, false);
6278 static void intel_pre_plane_update(struct intel_atomic_state *state,
6279 struct intel_crtc *crtc)
6281 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6282 struct intel_plane *primary = to_intel_plane(crtc->base.primary);
6283 const struct intel_crtc_state *old_crtc_state =
6284 intel_atomic_get_old_crtc_state(state, crtc);
6285 const struct intel_crtc_state *new_crtc_state =
6286 intel_atomic_get_new_crtc_state(state, crtc);
6287 const struct intel_plane_state *new_primary_state =
6288 intel_atomic_get_new_plane_state(state, primary);
6289 enum pipe pipe = crtc->pipe;
6291 if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
6292 hsw_disable_ips(old_crtc_state);
6294 if (new_primary_state &&
6295 intel_fbc_pre_update(crtc, new_crtc_state, new_primary_state))
6296 intel_wait_for_vblank(dev_priv, pipe);
6298 /* Display WA 827 */
6299 if (!needs_nv12_wa(old_crtc_state) &&
6300 needs_nv12_wa(new_crtc_state))
6301 skl_wa_827(dev_priv, pipe, true);
6303 /* Wa_2006604312:icl */
6304 if (!needs_scalerclk_wa(old_crtc_state) &&
6305 needs_scalerclk_wa(new_crtc_state))
6306 icl_wa_scalerclkgating(dev_priv, pipe, true);
6309 * Vblank time updates from the shadow to live plane control register
6310 * are blocked if the memory self-refresh mode is active at that
6311 * moment. So to make sure the plane gets truly disabled, disable
6312 * first the self-refresh mode. The self-refresh enable bit in turn
6313 * will be checked/applied by the HW only at the next frame start
6314 * event which is after the vblank start event, so we need to have a
6315 * wait-for-vblank between disabling the plane and the pipe.
6317 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
6318 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
6319 intel_wait_for_vblank(dev_priv, pipe);
6322 * IVB workaround: must disable low power watermarks for at least
6323 * one frame before enabling scaling. LP watermarks can be re-enabled
6324 * when scaling is disabled.
6326 * WaCxSRDisabledForSpriteScaling:ivb
6328 if (old_crtc_state->hw.active &&
6329 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
6330 intel_wait_for_vblank(dev_priv, pipe);
6333 * If we're doing a modeset we don't need to do any
6334 * pre-vblank watermark programming here.
6336 if (!needs_modeset(new_crtc_state)) {
6338 * For platforms that support atomic watermarks, program the
6339 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6340 * will be the intermediate values that are safe for both pre- and
6341 * post- vblank; when vblank happens, the 'active' values will be set
6342 * to the final 'target' values and we'll do this again to get the
6343 * optimal watermarks. For gen9+ platforms, the values we program here
6344 * will be the final target values which will get automatically latched
6345 * at vblank time; no further programming will be necessary.
6347 * If a platform hasn't been transitioned to atomic watermarks yet,
6348 * we'll continue to update watermarks the old way, if flags tell
6351 if (dev_priv->display.initial_watermarks)
6352 dev_priv->display.initial_watermarks(state, crtc);
6353 else if (new_crtc_state->update_wm_pre)
6354 intel_update_watermarks(crtc);
6358 * Gen2 reports pipe underruns whenever all planes are disabled.
6359 * So disable underrun reporting before all the planes get disabled.
6361 * We do this after .initial_watermarks() so that we have a
6362 * chance of catching underruns with the intermediate watermarks
6363 * vs. the old plane configuration.
6365 if (IS_GEN(dev_priv, 2) && planes_disabling(old_crtc_state, new_crtc_state))
6366 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6369 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6370 struct intel_crtc *crtc)
6372 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6373 const struct intel_crtc_state *new_crtc_state =
6374 intel_atomic_get_new_crtc_state(state, crtc);
6375 unsigned int update_mask = new_crtc_state->update_planes;
6376 const struct intel_plane_state *old_plane_state;
6377 struct intel_plane *plane;
6378 unsigned fb_bits = 0;
6381 intel_crtc_dpms_overlay_disable(crtc);
6383 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6384 if (crtc->pipe != plane->pipe ||
6385 !(update_mask & BIT(plane->id)))
6388 intel_disable_plane(plane, new_crtc_state);
6390 if (old_plane_state->uapi.visible)
6391 fb_bits |= plane->frontbuffer_bit;
6394 intel_frontbuffer_flip(dev_priv, fb_bits);
6398 * intel_connector_primary_encoder - get the primary encoder for a connector
6399 * @connector: connector for which to return the encoder
6401 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6402 * all connectors to their encoder, except for DP-MST connectors which have
6403 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6404 * pointed to by as many DP-MST connectors as there are pipes.
6406 static struct intel_encoder *
6407 intel_connector_primary_encoder(struct intel_connector *connector)
6409 struct intel_encoder *encoder;
6411 if (connector->mst_port)
6412 return &dp_to_dig_port(connector->mst_port)->base;
6414 encoder = intel_attached_encoder(&connector->base);
6420 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6422 struct drm_connector_state *new_conn_state;
6423 struct drm_connector *connector;
6426 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6428 struct intel_connector *intel_connector;
6429 struct intel_encoder *encoder;
6430 struct intel_crtc *crtc;
6432 if (!intel_connector_needs_modeset(state, connector))
6435 intel_connector = to_intel_connector(connector);
6436 encoder = intel_connector_primary_encoder(intel_connector);
6437 if (!encoder->update_prepare)
6440 crtc = new_conn_state->crtc ?
6441 to_intel_crtc(new_conn_state->crtc) : NULL;
6442 encoder->update_prepare(state, encoder, crtc);
6446 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6448 struct drm_connector_state *new_conn_state;
6449 struct drm_connector *connector;
6452 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6454 struct intel_connector *intel_connector;
6455 struct intel_encoder *encoder;
6456 struct intel_crtc *crtc;
6458 if (!intel_connector_needs_modeset(state, connector))
6461 intel_connector = to_intel_connector(connector);
6462 encoder = intel_connector_primary_encoder(intel_connector);
6463 if (!encoder->update_complete)
6466 crtc = new_conn_state->crtc ?
6467 to_intel_crtc(new_conn_state->crtc) : NULL;
6468 encoder->update_complete(state, encoder, crtc);
6472 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
6473 struct intel_crtc *crtc)
6475 const struct intel_crtc_state *crtc_state =
6476 intel_atomic_get_new_crtc_state(state, crtc);
6477 const struct drm_connector_state *conn_state;
6478 struct drm_connector *conn;
6481 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6482 struct intel_encoder *encoder =
6483 to_intel_encoder(conn_state->best_encoder);
6485 if (conn_state->crtc != &crtc->base)
6488 if (encoder->pre_pll_enable)
6489 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
6493 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
6494 struct intel_crtc *crtc)
6496 const struct intel_crtc_state *crtc_state =
6497 intel_atomic_get_new_crtc_state(state, crtc);
6498 const struct drm_connector_state *conn_state;
6499 struct drm_connector *conn;
6502 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6503 struct intel_encoder *encoder =
6504 to_intel_encoder(conn_state->best_encoder);
6506 if (conn_state->crtc != &crtc->base)
6509 if (encoder->pre_enable)
6510 encoder->pre_enable(encoder, crtc_state, conn_state);
6514 static void intel_encoders_enable(struct intel_atomic_state *state,
6515 struct intel_crtc *crtc)
6517 const struct intel_crtc_state *crtc_state =
6518 intel_atomic_get_new_crtc_state(state, crtc);
6519 const struct drm_connector_state *conn_state;
6520 struct drm_connector *conn;
6523 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6524 struct intel_encoder *encoder =
6525 to_intel_encoder(conn_state->best_encoder);
6527 if (conn_state->crtc != &crtc->base)
6530 if (encoder->enable)
6531 encoder->enable(encoder, crtc_state, conn_state);
6532 intel_opregion_notify_encoder(encoder, true);
6536 static void intel_encoders_disable(struct intel_atomic_state *state,
6537 struct intel_crtc *crtc)
6539 const struct intel_crtc_state *old_crtc_state =
6540 intel_atomic_get_old_crtc_state(state, crtc);
6541 const struct drm_connector_state *old_conn_state;
6542 struct drm_connector *conn;
6545 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6546 struct intel_encoder *encoder =
6547 to_intel_encoder(old_conn_state->best_encoder);
6549 if (old_conn_state->crtc != &crtc->base)
6552 intel_opregion_notify_encoder(encoder, false);
6553 if (encoder->disable)
6554 encoder->disable(encoder, old_crtc_state, old_conn_state);
6558 static void intel_encoders_post_disable(struct intel_atomic_state *state,
6559 struct intel_crtc *crtc)
6561 const struct intel_crtc_state *old_crtc_state =
6562 intel_atomic_get_old_crtc_state(state, crtc);
6563 const struct drm_connector_state *old_conn_state;
6564 struct drm_connector *conn;
6567 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6568 struct intel_encoder *encoder =
6569 to_intel_encoder(old_conn_state->best_encoder);
6571 if (old_conn_state->crtc != &crtc->base)
6574 if (encoder->post_disable)
6575 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
6579 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
6580 struct intel_crtc *crtc)
6582 const struct intel_crtc_state *old_crtc_state =
6583 intel_atomic_get_old_crtc_state(state, crtc);
6584 const struct drm_connector_state *old_conn_state;
6585 struct drm_connector *conn;
6588 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6589 struct intel_encoder *encoder =
6590 to_intel_encoder(old_conn_state->best_encoder);
6592 if (old_conn_state->crtc != &crtc->base)
6595 if (encoder->post_pll_disable)
6596 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
6600 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
6601 struct intel_crtc *crtc)
6603 const struct intel_crtc_state *crtc_state =
6604 intel_atomic_get_new_crtc_state(state, crtc);
6605 const struct drm_connector_state *conn_state;
6606 struct drm_connector *conn;
6609 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6610 struct intel_encoder *encoder =
6611 to_intel_encoder(conn_state->best_encoder);
6613 if (conn_state->crtc != &crtc->base)
6616 if (encoder->update_pipe)
6617 encoder->update_pipe(encoder, crtc_state, conn_state);
6621 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6623 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6624 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6626 plane->disable_plane(plane, crtc_state);
6629 static void ironlake_crtc_enable(struct intel_atomic_state *state,
6630 struct intel_crtc *crtc)
6632 const struct intel_crtc_state *new_crtc_state =
6633 intel_atomic_get_new_crtc_state(state, crtc);
6634 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6635 enum pipe pipe = crtc->pipe;
6637 if (WARN_ON(crtc->active))
6641 * Sometimes spurious CPU pipe underruns happen during FDI
6642 * training, at least with VGA+HDMI cloning. Suppress them.
6644 * On ILK we get an occasional spurious CPU pipe underruns
6645 * between eDP port A enable and vdd enable. Also PCH port
6646 * enable seems to result in the occasional CPU pipe underrun.
6648 * Spurious PCH underruns also occur during PCH enabling.
6650 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6651 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6653 if (new_crtc_state->has_pch_encoder)
6654 intel_prepare_shared_dpll(new_crtc_state);
6656 if (intel_crtc_has_dp_encoder(new_crtc_state))
6657 intel_dp_set_m_n(new_crtc_state, M1_N1);
6659 intel_set_pipe_timings(new_crtc_state);
6660 intel_set_pipe_src_size(new_crtc_state);
6662 if (new_crtc_state->has_pch_encoder)
6663 intel_cpu_transcoder_set_m_n(new_crtc_state,
6664 &new_crtc_state->fdi_m_n, NULL);
6666 ironlake_set_pipeconf(new_crtc_state);
6668 crtc->active = true;
6670 intel_encoders_pre_enable(state, crtc);
6672 if (new_crtc_state->has_pch_encoder) {
6673 /* Note: FDI PLL enabling _must_ be done before we enable the
6674 * cpu pipes, hence this is separate from all the other fdi/pch
6676 ironlake_fdi_pll_enable(new_crtc_state);
6678 assert_fdi_tx_disabled(dev_priv, pipe);
6679 assert_fdi_rx_disabled(dev_priv, pipe);
6682 ironlake_pfit_enable(new_crtc_state);
6685 * On ILK+ LUT must be loaded before the pipe is running but with
6688 intel_color_load_luts(new_crtc_state);
6689 intel_color_commit(new_crtc_state);
6690 /* update DSPCNTR to configure gamma for pipe bottom color */
6691 intel_disable_primary_plane(new_crtc_state);
6693 if (dev_priv->display.initial_watermarks)
6694 dev_priv->display.initial_watermarks(state, crtc);
6695 intel_enable_pipe(new_crtc_state);
6697 if (new_crtc_state->has_pch_encoder)
6698 ironlake_pch_enable(state, new_crtc_state);
6700 intel_crtc_vblank_on(new_crtc_state);
6702 intel_encoders_enable(state, crtc);
6704 if (HAS_PCH_CPT(dev_priv))
6705 cpt_verify_modeset(dev_priv, pipe);
6708 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6709 * And a second vblank wait is needed at least on ILK with
6710 * some interlaced HDMI modes. Let's do the double wait always
6711 * in case there are more corner cases we don't know about.
6713 if (new_crtc_state->has_pch_encoder) {
6714 intel_wait_for_vblank(dev_priv, pipe);
6715 intel_wait_for_vblank(dev_priv, pipe);
6717 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6718 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6721 /* IPS only exists on ULT machines and is tied to pipe A. */
6722 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6724 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6727 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6728 enum pipe pipe, bool apply)
6730 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
6731 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6738 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
6741 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6743 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6744 enum pipe pipe = crtc->pipe;
6747 val = MBUS_DBOX_A_CREDIT(2);
6749 if (INTEL_GEN(dev_priv) >= 12) {
6750 val |= MBUS_DBOX_BW_CREDIT(2);
6751 val |= MBUS_DBOX_B_CREDIT(12);
6753 val |= MBUS_DBOX_BW_CREDIT(1);
6754 val |= MBUS_DBOX_B_CREDIT(8);
6757 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
6760 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
6762 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6763 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6764 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
6767 val = I915_READ(reg);
6768 val &= ~HSW_FRAME_START_DELAY_MASK;
6769 val |= HSW_FRAME_START_DELAY(0);
6770 I915_WRITE(reg, val);
6773 static void haswell_crtc_enable(struct intel_atomic_state *state,
6774 struct intel_crtc *crtc)
6776 const struct intel_crtc_state *new_crtc_state =
6777 intel_atomic_get_new_crtc_state(state, crtc);
6778 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6779 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
6780 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
6781 bool psl_clkgate_wa;
6783 if (WARN_ON(crtc->active))
6786 intel_encoders_pre_pll_enable(state, crtc);
6788 if (new_crtc_state->shared_dpll)
6789 intel_enable_shared_dpll(new_crtc_state);
6791 intel_encoders_pre_enable(state, crtc);
6793 if (intel_crtc_has_dp_encoder(new_crtc_state))
6794 intel_dp_set_m_n(new_crtc_state, M1_N1);
6796 if (!transcoder_is_dsi(cpu_transcoder))
6797 intel_set_pipe_timings(new_crtc_state);
6799 if (INTEL_GEN(dev_priv) >= 11)
6800 icl_enable_trans_port_sync(new_crtc_state);
6802 intel_set_pipe_src_size(new_crtc_state);
6804 if (cpu_transcoder != TRANSCODER_EDP &&
6805 !transcoder_is_dsi(cpu_transcoder))
6806 I915_WRITE(PIPE_MULT(cpu_transcoder),
6807 new_crtc_state->pixel_multiplier - 1);
6809 if (new_crtc_state->has_pch_encoder)
6810 intel_cpu_transcoder_set_m_n(new_crtc_state,
6811 &new_crtc_state->fdi_m_n, NULL);
6813 if (!transcoder_is_dsi(cpu_transcoder)) {
6814 hsw_set_frame_start_delay(new_crtc_state);
6815 haswell_set_pipeconf(new_crtc_state);
6818 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6819 bdw_set_pipemisc(new_crtc_state);
6821 crtc->active = true;
6823 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6824 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
6825 new_crtc_state->pch_pfit.enabled;
6827 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
6829 if (INTEL_GEN(dev_priv) >= 9)
6830 skylake_pfit_enable(new_crtc_state);
6832 ironlake_pfit_enable(new_crtc_state);
6835 * On ILK+ LUT must be loaded before the pipe is running but with
6838 intel_color_load_luts(new_crtc_state);
6839 intel_color_commit(new_crtc_state);
6840 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
6841 if (INTEL_GEN(dev_priv) < 9)
6842 intel_disable_primary_plane(new_crtc_state);
6844 if (INTEL_GEN(dev_priv) >= 11)
6845 icl_set_pipe_chicken(crtc);
6847 if (!transcoder_is_dsi(cpu_transcoder))
6848 intel_ddi_enable_transcoder_func(new_crtc_state);
6850 if (dev_priv->display.initial_watermarks)
6851 dev_priv->display.initial_watermarks(state, crtc);
6853 if (INTEL_GEN(dev_priv) >= 11)
6854 icl_pipe_mbus_enable(crtc);
6856 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6857 if (!transcoder_is_dsi(cpu_transcoder))
6858 intel_enable_pipe(new_crtc_state);
6860 if (new_crtc_state->has_pch_encoder)
6861 lpt_pch_enable(state, new_crtc_state);
6863 intel_crtc_vblank_on(new_crtc_state);
6865 intel_encoders_enable(state, crtc);
6867 if (psl_clkgate_wa) {
6868 intel_wait_for_vblank(dev_priv, pipe);
6869 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6872 /* If we change the relative order between pipe/planes enabling, we need
6873 * to change the workaround. */
6874 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
6875 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6876 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6877 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6881 void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6883 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
6884 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6885 enum pipe pipe = crtc->pipe;
6887 /* To avoid upsetting the power well on haswell only disable the pfit if
6888 * it's in use. The hw state code will make sure we get this right. */
6889 if (old_crtc_state->pch_pfit.enabled) {
6890 I915_WRITE(PF_CTL(pipe), 0);
6891 I915_WRITE(PF_WIN_POS(pipe), 0);
6892 I915_WRITE(PF_WIN_SZ(pipe), 0);
6896 static void ironlake_crtc_disable(struct intel_atomic_state *state,
6897 struct intel_crtc *crtc)
6899 const struct intel_crtc_state *old_crtc_state =
6900 intel_atomic_get_old_crtc_state(state, crtc);
6901 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6902 enum pipe pipe = crtc->pipe;
6905 * Sometimes spurious CPU pipe underruns happen when the
6906 * pipe is already disabled, but FDI RX/TX is still enabled.
6907 * Happens at least with VGA+HDMI cloning. Suppress them.
6909 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6910 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6912 intel_encoders_disable(state, crtc);
6914 intel_crtc_vblank_off(old_crtc_state);
6916 intel_disable_pipe(old_crtc_state);
6918 ironlake_pfit_disable(old_crtc_state);
6920 if (old_crtc_state->has_pch_encoder)
6921 ironlake_fdi_disable(crtc);
6923 intel_encoders_post_disable(state, crtc);
6925 if (old_crtc_state->has_pch_encoder) {
6926 ironlake_disable_pch_transcoder(dev_priv, pipe);
6928 if (HAS_PCH_CPT(dev_priv)) {
6932 /* disable TRANS_DP_CTL */
6933 reg = TRANS_DP_CTL(pipe);
6934 temp = I915_READ(reg);
6935 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6936 TRANS_DP_PORT_SEL_MASK);
6937 temp |= TRANS_DP_PORT_SEL_NONE;
6938 I915_WRITE(reg, temp);
6940 /* disable DPLL_SEL */
6941 temp = I915_READ(PCH_DPLL_SEL);
6942 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6943 I915_WRITE(PCH_DPLL_SEL, temp);
6946 ironlake_fdi_pll_disable(crtc);
6949 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6950 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6953 static void haswell_crtc_disable(struct intel_atomic_state *state,
6954 struct intel_crtc *crtc)
6957 * FIXME collapse everything to one hook.
6958 * Need care with mst->ddi interactions.
6960 intel_encoders_disable(state, crtc);
6961 intel_encoders_post_disable(state, crtc);
6964 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6966 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6967 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6969 if (!crtc_state->gmch_pfit.control)
6973 * The panel fitter should only be adjusted whilst the pipe is disabled,
6974 * according to register description and PRM.
6976 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6977 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
6979 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6980 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
6982 /* Border color in case we don't scale up to the full screen. Black by
6983 * default, change to something else for debugging. */
6984 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6987 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
6989 if (phy == PHY_NONE)
6992 if (IS_ELKHARTLAKE(dev_priv))
6993 return phy <= PHY_C;
6995 if (INTEL_GEN(dev_priv) >= 11)
6996 return phy <= PHY_B;
7001 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
7003 if (INTEL_GEN(dev_priv) >= 12)
7004 return phy >= PHY_D && phy <= PHY_I;
7006 if (INTEL_GEN(dev_priv) >= 11 && !IS_ELKHARTLAKE(dev_priv))
7007 return phy >= PHY_C && phy <= PHY_F;
7012 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
7014 if (IS_ELKHARTLAKE(i915) && port == PORT_D)
7017 return (enum phy)port;
7020 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
7022 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
7023 return PORT_TC_NONE;
7025 if (INTEL_GEN(dev_priv) >= 12)
7026 return port - PORT_D;
7028 return port - PORT_C;
7031 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
7035 return POWER_DOMAIN_PORT_DDI_A_LANES;
7037 return POWER_DOMAIN_PORT_DDI_B_LANES;
7039 return POWER_DOMAIN_PORT_DDI_C_LANES;
7041 return POWER_DOMAIN_PORT_DDI_D_LANES;
7043 return POWER_DOMAIN_PORT_DDI_E_LANES;
7045 return POWER_DOMAIN_PORT_DDI_F_LANES;
7047 return POWER_DOMAIN_PORT_DDI_G_LANES;
7050 return POWER_DOMAIN_PORT_OTHER;
7054 enum intel_display_power_domain
7055 intel_aux_power_domain(struct intel_digital_port *dig_port)
7057 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
7058 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
7060 if (intel_phy_is_tc(dev_priv, phy) &&
7061 dig_port->tc_mode == TC_PORT_TBT_ALT) {
7062 switch (dig_port->aux_ch) {
7064 return POWER_DOMAIN_AUX_C_TBT;
7066 return POWER_DOMAIN_AUX_D_TBT;
7068 return POWER_DOMAIN_AUX_E_TBT;
7070 return POWER_DOMAIN_AUX_F_TBT;
7072 return POWER_DOMAIN_AUX_G_TBT;
7074 MISSING_CASE(dig_port->aux_ch);
7075 return POWER_DOMAIN_AUX_C_TBT;
7079 switch (dig_port->aux_ch) {
7081 return POWER_DOMAIN_AUX_A;
7083 return POWER_DOMAIN_AUX_B;
7085 return POWER_DOMAIN_AUX_C;
7087 return POWER_DOMAIN_AUX_D;
7089 return POWER_DOMAIN_AUX_E;
7091 return POWER_DOMAIN_AUX_F;
7093 return POWER_DOMAIN_AUX_G;
7095 MISSING_CASE(dig_port->aux_ch);
7096 return POWER_DOMAIN_AUX_A;
7100 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7102 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7103 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7104 struct drm_encoder *encoder;
7105 enum pipe pipe = crtc->pipe;
7107 enum transcoder transcoder = crtc_state->cpu_transcoder;
7109 if (!crtc_state->hw.active)
7112 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
7113 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
7114 if (crtc_state->pch_pfit.enabled ||
7115 crtc_state->pch_pfit.force_thru)
7116 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
7118 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
7119 crtc_state->uapi.encoder_mask) {
7120 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7122 mask |= BIT_ULL(intel_encoder->power_domain);
7125 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
7126 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
7128 if (crtc_state->shared_dpll)
7129 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
7135 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7137 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7138 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7139 enum intel_display_power_domain domain;
7140 u64 domains, new_domains, old_domains;
7142 old_domains = crtc->enabled_power_domains;
7143 crtc->enabled_power_domains = new_domains =
7144 get_crtc_power_domains(crtc_state);
7146 domains = new_domains & ~old_domains;
7148 for_each_power_domain(domain, domains)
7149 intel_display_power_get(dev_priv, domain);
7151 return old_domains & ~new_domains;
7154 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
7157 enum intel_display_power_domain domain;
7159 for_each_power_domain(domain, domains)
7160 intel_display_power_put_unchecked(dev_priv, domain);
7163 static void valleyview_crtc_enable(struct intel_atomic_state *state,
7164 struct intel_crtc *crtc)
7166 const struct intel_crtc_state *new_crtc_state =
7167 intel_atomic_get_new_crtc_state(state, crtc);
7168 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7169 enum pipe pipe = crtc->pipe;
7171 if (WARN_ON(crtc->active))
7174 if (intel_crtc_has_dp_encoder(new_crtc_state))
7175 intel_dp_set_m_n(new_crtc_state, M1_N1);
7177 intel_set_pipe_timings(new_crtc_state);
7178 intel_set_pipe_src_size(new_crtc_state);
7180 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
7181 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
7182 I915_WRITE(CHV_CANVAS(pipe), 0);
7185 i9xx_set_pipeconf(new_crtc_state);
7187 crtc->active = true;
7189 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7191 intel_encoders_pre_pll_enable(state, crtc);
7193 if (IS_CHERRYVIEW(dev_priv)) {
7194 chv_prepare_pll(crtc, new_crtc_state);
7195 chv_enable_pll(crtc, new_crtc_state);
7197 vlv_prepare_pll(crtc, new_crtc_state);
7198 vlv_enable_pll(crtc, new_crtc_state);
7201 intel_encoders_pre_enable(state, crtc);
7203 i9xx_pfit_enable(new_crtc_state);
7205 intel_color_load_luts(new_crtc_state);
7206 intel_color_commit(new_crtc_state);
7207 /* update DSPCNTR to configure gamma for pipe bottom color */
7208 intel_disable_primary_plane(new_crtc_state);
7210 dev_priv->display.initial_watermarks(state, crtc);
7211 intel_enable_pipe(new_crtc_state);
7213 intel_crtc_vblank_on(new_crtc_state);
7215 intel_encoders_enable(state, crtc);
7218 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
7220 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7221 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7223 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
7224 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
7227 static void i9xx_crtc_enable(struct intel_atomic_state *state,
7228 struct intel_crtc *crtc)
7230 const struct intel_crtc_state *new_crtc_state =
7231 intel_atomic_get_new_crtc_state(state, crtc);
7232 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7233 enum pipe pipe = crtc->pipe;
7235 if (WARN_ON(crtc->active))
7238 i9xx_set_pll_dividers(new_crtc_state);
7240 if (intel_crtc_has_dp_encoder(new_crtc_state))
7241 intel_dp_set_m_n(new_crtc_state, M1_N1);
7243 intel_set_pipe_timings(new_crtc_state);
7244 intel_set_pipe_src_size(new_crtc_state);
7246 i9xx_set_pipeconf(new_crtc_state);
7248 crtc->active = true;
7250 if (!IS_GEN(dev_priv, 2))
7251 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7253 intel_encoders_pre_enable(state, crtc);
7255 i9xx_enable_pll(crtc, new_crtc_state);
7257 i9xx_pfit_enable(new_crtc_state);
7259 intel_color_load_luts(new_crtc_state);
7260 intel_color_commit(new_crtc_state);
7261 /* update DSPCNTR to configure gamma for pipe bottom color */
7262 intel_disable_primary_plane(new_crtc_state);
7264 if (dev_priv->display.initial_watermarks)
7265 dev_priv->display.initial_watermarks(state, crtc);
7267 intel_update_watermarks(crtc);
7268 intel_enable_pipe(new_crtc_state);
7270 intel_crtc_vblank_on(new_crtc_state);
7272 intel_encoders_enable(state, crtc);
7275 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
7277 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
7278 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7280 if (!old_crtc_state->gmch_pfit.control)
7283 assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
7285 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
7286 I915_READ(PFIT_CONTROL));
7287 I915_WRITE(PFIT_CONTROL, 0);
7290 static void i9xx_crtc_disable(struct intel_atomic_state *state,
7291 struct intel_crtc *crtc)
7293 struct intel_crtc_state *old_crtc_state =
7294 intel_atomic_get_old_crtc_state(state, crtc);
7295 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7296 enum pipe pipe = crtc->pipe;
7299 * On gen2 planes are double buffered but the pipe isn't, so we must
7300 * wait for planes to fully turn off before disabling the pipe.
7302 if (IS_GEN(dev_priv, 2))
7303 intel_wait_for_vblank(dev_priv, pipe);
7305 intel_encoders_disable(state, crtc);
7307 intel_crtc_vblank_off(old_crtc_state);
7309 intel_disable_pipe(old_crtc_state);
7311 i9xx_pfit_disable(old_crtc_state);
7313 intel_encoders_post_disable(state, crtc);
7315 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
7316 if (IS_CHERRYVIEW(dev_priv))
7317 chv_disable_pll(dev_priv, pipe);
7318 else if (IS_VALLEYVIEW(dev_priv))
7319 vlv_disable_pll(dev_priv, pipe);
7321 i9xx_disable_pll(old_crtc_state);
7324 intel_encoders_post_pll_disable(state, crtc);
7326 if (!IS_GEN(dev_priv, 2))
7327 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7329 if (!dev_priv->display.initial_watermarks)
7330 intel_update_watermarks(crtc);
7332 /* clock the pipe down to 640x480@60 to potentially save power */
7333 if (IS_I830(dev_priv))
7334 i830_enable_pipe(dev_priv, pipe);
7337 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc,
7338 struct drm_modeset_acquire_ctx *ctx)
7340 struct intel_encoder *encoder;
7341 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7342 struct intel_bw_state *bw_state =
7343 to_intel_bw_state(dev_priv->bw_obj.state);
7344 struct intel_crtc_state *crtc_state =
7345 to_intel_crtc_state(crtc->base.state);
7346 enum intel_display_power_domain domain;
7347 struct intel_plane *plane;
7348 struct drm_atomic_state *state;
7349 struct intel_crtc_state *temp_crtc_state;
7350 enum pipe pipe = crtc->pipe;
7354 if (!crtc_state->hw.active)
7357 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
7358 const struct intel_plane_state *plane_state =
7359 to_intel_plane_state(plane->base.state);
7361 if (plane_state->uapi.visible)
7362 intel_plane_disable_noatomic(crtc, plane);
7365 state = drm_atomic_state_alloc(&dev_priv->drm);
7367 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
7368 crtc->base.base.id, crtc->base.name);
7372 state->acquire_ctx = ctx;
7374 /* Everything's already locked, -EDEADLK can't happen. */
7375 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc);
7376 ret = drm_atomic_add_affected_connectors(state, &crtc->base);
7378 WARN_ON(IS_ERR(temp_crtc_state) || ret);
7380 dev_priv->display.crtc_disable(to_intel_atomic_state(state), crtc);
7382 drm_atomic_state_put(state);
7384 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7385 crtc->base.base.id, crtc->base.name);
7387 crtc->active = false;
7388 crtc->base.enabled = false;
7390 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0);
7391 crtc_state->uapi.active = false;
7392 crtc_state->uapi.connector_mask = 0;
7393 crtc_state->uapi.encoder_mask = 0;
7394 intel_crtc_free_hw_state(crtc_state);
7395 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw));
7397 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder)
7398 encoder->base.crtc = NULL;
7400 intel_fbc_disable(crtc);
7401 intel_update_watermarks(crtc);
7402 intel_disable_shared_dpll(crtc_state);
7404 domains = crtc->enabled_power_domains;
7405 for_each_power_domain(domain, domains)
7406 intel_display_power_put_unchecked(dev_priv, domain);
7407 crtc->enabled_power_domains = 0;
7409 dev_priv->active_pipes &= ~BIT(pipe);
7410 dev_priv->min_cdclk[pipe] = 0;
7411 dev_priv->min_voltage_level[pipe] = 0;
7413 bw_state->data_rate[pipe] = 0;
7414 bw_state->num_active_planes[pipe] = 0;
7418 * turn all crtc's off, but do not adjust state
7419 * This has to be paired with a call to intel_modeset_setup_hw_state.
7421 int intel_display_suspend(struct drm_device *dev)
7423 struct drm_i915_private *dev_priv = to_i915(dev);
7424 struct drm_atomic_state *state;
7427 state = drm_atomic_helper_suspend(dev);
7428 ret = PTR_ERR_OR_ZERO(state);
7430 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
7432 dev_priv->modeset_restore_state = state;
7436 void intel_encoder_destroy(struct drm_encoder *encoder)
7438 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7440 drm_encoder_cleanup(encoder);
7441 kfree(intel_encoder);
7444 /* Cross check the actual hw state with our own modeset state tracking (and it's
7445 * internal consistency). */
7446 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7447 struct drm_connector_state *conn_state)
7449 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7451 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
7452 connector->base.base.id,
7453 connector->base.name);
7455 if (connector->get_hw_state(connector)) {
7456 struct intel_encoder *encoder = connector->encoder;
7458 I915_STATE_WARN(!crtc_state,
7459 "connector enabled without attached crtc\n");
7464 I915_STATE_WARN(!crtc_state->hw.active,
7465 "connector is active, but attached crtc isn't\n");
7467 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7470 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7471 "atomic encoder doesn't match attached encoder\n");
7473 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7474 "attached encoder crtc differs from connector crtc\n");
7476 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
7477 "attached crtc is active, but connector isn't\n");
7478 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7479 "best encoder set without crtc!\n");
7483 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7485 if (crtc_state->hw.enable && crtc_state->has_pch_encoder)
7486 return crtc_state->fdi_lanes;
7491 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7492 struct intel_crtc_state *pipe_config)
7494 struct drm_i915_private *dev_priv = to_i915(dev);
7495 struct drm_atomic_state *state = pipe_config->uapi.state;
7496 struct intel_crtc *other_crtc;
7497 struct intel_crtc_state *other_crtc_state;
7499 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
7500 pipe_name(pipe), pipe_config->fdi_lanes);
7501 if (pipe_config->fdi_lanes > 4) {
7502 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
7503 pipe_name(pipe), pipe_config->fdi_lanes);
7507 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7508 if (pipe_config->fdi_lanes > 2) {
7509 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
7510 pipe_config->fdi_lanes);
7517 if (INTEL_NUM_PIPES(dev_priv) == 2)
7520 /* Ivybridge 3 pipe is really complicated */
7525 if (pipe_config->fdi_lanes <= 2)
7528 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7530 intel_atomic_get_crtc_state(state, other_crtc);
7531 if (IS_ERR(other_crtc_state))
7532 return PTR_ERR(other_crtc_state);
7534 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7535 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
7536 pipe_name(pipe), pipe_config->fdi_lanes);
7541 if (pipe_config->fdi_lanes > 2) {
7542 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
7543 pipe_name(pipe), pipe_config->fdi_lanes);
7547 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7549 intel_atomic_get_crtc_state(state, other_crtc);
7550 if (IS_ERR(other_crtc_state))
7551 return PTR_ERR(other_crtc_state);
7553 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7554 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
7564 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
7565 struct intel_crtc_state *pipe_config)
7567 struct drm_device *dev = intel_crtc->base.dev;
7568 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7569 int lane, link_bw, fdi_dotclock, ret;
7570 bool needs_recompute = false;
7573 /* FDI is a binary signal running at ~2.7GHz, encoding
7574 * each output octet as 10 bits. The actual frequency
7575 * is stored as a divider into a 100MHz clock, and the
7576 * mode pixel clock is stored in units of 1KHz.
7577 * Hence the bw of each lane in terms of the mode signal
7580 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
7582 fdi_dotclock = adjusted_mode->crtc_clock;
7584 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
7585 pipe_config->pipe_bpp);
7587 pipe_config->fdi_lanes = lane;
7589 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7590 link_bw, &pipe_config->fdi_m_n, false, false);
7592 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7593 if (ret == -EDEADLK)
7596 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7597 pipe_config->pipe_bpp -= 2*3;
7598 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
7599 pipe_config->pipe_bpp);
7600 needs_recompute = true;
7601 pipe_config->bw_constrained = true;
7606 if (needs_recompute)
7612 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7614 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7615 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7617 /* IPS only exists on ULT machines and is tied to pipe A. */
7618 if (!hsw_crtc_supports_ips(crtc))
7621 if (!i915_modparams.enable_ips)
7624 if (crtc_state->pipe_bpp > 24)
7628 * We compare against max which means we must take
7629 * the increased cdclk requirement into account when
7630 * calculating the new cdclk.
7632 * Should measure whether using a lower cdclk w/o IPS
7634 if (IS_BROADWELL(dev_priv) &&
7635 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7641 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7643 struct drm_i915_private *dev_priv =
7644 to_i915(crtc_state->uapi.crtc->dev);
7645 struct intel_atomic_state *intel_state =
7646 to_intel_atomic_state(crtc_state->uapi.state);
7648 if (!hsw_crtc_state_ips_capable(crtc_state))
7652 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7653 * enabled and disabled dynamically based on package C states,
7654 * user space can't make reliable use of the CRCs, so let's just
7655 * completely disable it.
7657 if (crtc_state->crc_enabled)
7660 /* IPS should be fine as long as at least one plane is enabled. */
7661 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7664 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7665 if (IS_BROADWELL(dev_priv) &&
7666 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
7672 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7674 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7676 /* GDG double wide on either pipe, otherwise pipe A only */
7677 return INTEL_GEN(dev_priv) < 4 &&
7678 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7681 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
7685 pixel_rate = pipe_config->hw.adjusted_mode.crtc_clock;
7688 * We only use IF-ID interlacing. If we ever use
7689 * PF-ID we'll need to adjust the pixel_rate here.
7692 if (pipe_config->pch_pfit.enabled) {
7693 u64 pipe_w, pipe_h, pfit_w, pfit_h;
7694 u32 pfit_size = pipe_config->pch_pfit.size;
7696 pipe_w = pipe_config->pipe_src_w;
7697 pipe_h = pipe_config->pipe_src_h;
7699 pfit_w = (pfit_size >> 16) & 0xFFFF;
7700 pfit_h = pfit_size & 0xFFFF;
7701 if (pipe_w < pfit_w)
7703 if (pipe_h < pfit_h)
7706 if (WARN_ON(!pfit_w || !pfit_h))
7709 pixel_rate = div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7716 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7718 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
7720 if (HAS_GMCH(dev_priv))
7721 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7722 crtc_state->pixel_rate =
7723 crtc_state->hw.adjusted_mode.crtc_clock;
7725 crtc_state->pixel_rate =
7726 ilk_pipe_pixel_rate(crtc_state);
7729 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7730 struct intel_crtc_state *pipe_config)
7732 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7733 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7734 int clock_limit = dev_priv->max_dotclk_freq;
7736 if (INTEL_GEN(dev_priv) < 4) {
7737 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
7740 * Enable double wide mode when the dot clock
7741 * is > 90% of the (display) core speed.
7743 if (intel_crtc_supports_double_wide(crtc) &&
7744 adjusted_mode->crtc_clock > clock_limit) {
7745 clock_limit = dev_priv->max_dotclk_freq;
7746 pipe_config->double_wide = true;
7750 if (adjusted_mode->crtc_clock > clock_limit) {
7751 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7752 adjusted_mode->crtc_clock, clock_limit,
7753 yesno(pipe_config->double_wide));
7757 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
7758 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
7759 pipe_config->hw.ctm) {
7761 * There is only one pipe CSC unit per pipe, and we need that
7762 * for output conversion from RGB->YCBCR. So if CTM is already
7763 * applied we can't support YCBCR420 output.
7765 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
7770 * Pipe horizontal size must be even in:
7772 * - LVDS dual channel mode
7773 * - Double wide pipe
7775 if (pipe_config->pipe_src_w & 1) {
7776 if (pipe_config->double_wide) {
7777 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
7781 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
7782 intel_is_dual_link_lvds(dev_priv)) {
7783 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
7788 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
7789 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7791 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7792 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
7795 intel_crtc_compute_pixel_rate(pipe_config);
7797 if (pipe_config->has_pch_encoder)
7798 return ironlake_fdi_compute_config(crtc, pipe_config);
7804 intel_reduce_m_n_ratio(u32 *num, u32 *den)
7806 while (*num > DATA_LINK_M_N_MASK ||
7807 *den > DATA_LINK_M_N_MASK) {
7813 static void compute_m_n(unsigned int m, unsigned int n,
7814 u32 *ret_m, u32 *ret_n,
7818 * Several DP dongles in particular seem to be fussy about
7819 * too large link M/N values. Give N value as 0x8000 that
7820 * should be acceptable by specific devices. 0x8000 is the
7821 * specified fixed N value for asynchronous clock mode,
7822 * which the devices expect also in synchronous clock mode.
7827 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
7829 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
7830 intel_reduce_m_n_ratio(ret_m, ret_n);
7834 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
7835 int pixel_clock, int link_clock,
7836 struct intel_link_m_n *m_n,
7837 bool constant_n, bool fec_enable)
7839 u32 data_clock = bits_per_pixel * pixel_clock;
7842 data_clock = intel_dp_mode_to_fec_clock(data_clock);
7845 compute_m_n(data_clock,
7846 link_clock * nlanes * 8,
7847 &m_n->gmch_m, &m_n->gmch_n,
7850 compute_m_n(pixel_clock, link_clock,
7851 &m_n->link_m, &m_n->link_n,
7855 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
7858 * There may be no VBT; and if the BIOS enabled SSC we can
7859 * just keep using it to avoid unnecessary flicker. Whereas if the
7860 * BIOS isn't using it, don't assume it will work even if the VBT
7861 * indicates as much.
7863 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
7864 bool bios_lvds_use_ssc = I915_READ(PCH_DREF_CONTROL) &
7867 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
7868 DRM_DEBUG_KMS("SSC %s by BIOS, overriding VBT which says %s\n",
7869 enableddisabled(bios_lvds_use_ssc),
7870 enableddisabled(dev_priv->vbt.lvds_use_ssc));
7871 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
7876 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7878 if (i915_modparams.panel_use_ssc >= 0)
7879 return i915_modparams.panel_use_ssc != 0;
7880 return dev_priv->vbt.lvds_use_ssc
7881 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7884 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
7886 return (1 << dpll->n) << 16 | dpll->m2;
7889 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7891 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7894 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7895 struct intel_crtc_state *crtc_state,
7896 struct dpll *reduced_clock)
7898 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7901 if (IS_PINEVIEW(dev_priv)) {
7902 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7904 fp2 = pnv_dpll_compute_fp(reduced_clock);
7906 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7908 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7911 crtc_state->dpll_hw_state.fp0 = fp;
7913 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7915 crtc_state->dpll_hw_state.fp1 = fp2;
7917 crtc_state->dpll_hw_state.fp1 = fp;
7921 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7927 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7928 * and set it to a reasonable value instead.
7930 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7931 reg_val &= 0xffffff00;
7932 reg_val |= 0x00000030;
7933 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7935 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7936 reg_val &= 0x00ffffff;
7937 reg_val |= 0x8c000000;
7938 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7940 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7941 reg_val &= 0xffffff00;
7942 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7944 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7945 reg_val &= 0x00ffffff;
7946 reg_val |= 0xb0000000;
7947 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7950 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7951 const struct intel_link_m_n *m_n)
7953 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7954 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7955 enum pipe pipe = crtc->pipe;
7957 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7958 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7959 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7960 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7963 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7964 enum transcoder transcoder)
7966 if (IS_HASWELL(dev_priv))
7967 return transcoder == TRANSCODER_EDP;
7970 * Strictly speaking some registers are available before
7971 * gen7, but we only support DRRS on gen7+
7973 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
7976 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7977 const struct intel_link_m_n *m_n,
7978 const struct intel_link_m_n *m2_n2)
7980 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7981 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7982 enum pipe pipe = crtc->pipe;
7983 enum transcoder transcoder = crtc_state->cpu_transcoder;
7985 if (INTEL_GEN(dev_priv) >= 5) {
7986 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7987 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7988 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7989 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7991 * M2_N2 registers are set only if DRRS is supported
7992 * (to make sure the registers are not unnecessarily accessed).
7994 if (m2_n2 && crtc_state->has_drrs &&
7995 transcoder_has_m2_n2(dev_priv, transcoder)) {
7996 I915_WRITE(PIPE_DATA_M2(transcoder),
7997 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7998 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7999 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
8000 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
8003 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
8004 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
8005 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
8006 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
8010 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
8012 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
8015 dp_m_n = &crtc_state->dp_m_n;
8016 dp_m2_n2 = &crtc_state->dp_m2_n2;
8017 } else if (m_n == M2_N2) {
8020 * M2_N2 registers are not supported. Hence m2_n2 divider value
8021 * needs to be programmed into M1_N1.
8023 dp_m_n = &crtc_state->dp_m2_n2;
8025 DRM_ERROR("Unsupported divider value\n");
8029 if (crtc_state->has_pch_encoder)
8030 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
8032 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
8035 static void vlv_compute_dpll(struct intel_crtc *crtc,
8036 struct intel_crtc_state *pipe_config)
8038 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
8039 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8040 if (crtc->pipe != PIPE_A)
8041 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8043 /* DPLL not used with DSI, but still need the rest set up */
8044 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8045 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
8046 DPLL_EXT_BUFFER_ENABLE_VLV;
8048 pipe_config->dpll_hw_state.dpll_md =
8049 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8052 static void chv_compute_dpll(struct intel_crtc *crtc,
8053 struct intel_crtc_state *pipe_config)
8055 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
8056 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8057 if (crtc->pipe != PIPE_A)
8058 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8060 /* DPLL not used with DSI, but still need the rest set up */
8061 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8062 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
8064 pipe_config->dpll_hw_state.dpll_md =
8065 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8068 static void vlv_prepare_pll(struct intel_crtc *crtc,
8069 const struct intel_crtc_state *pipe_config)
8071 struct drm_device *dev = crtc->base.dev;
8072 struct drm_i915_private *dev_priv = to_i915(dev);
8073 enum pipe pipe = crtc->pipe;
8075 u32 bestn, bestm1, bestm2, bestp1, bestp2;
8076 u32 coreclk, reg_val;
8079 I915_WRITE(DPLL(pipe),
8080 pipe_config->dpll_hw_state.dpll &
8081 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
8083 /* No need to actually set up the DPLL with DSI */
8084 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8087 vlv_dpio_get(dev_priv);
8089 bestn = pipe_config->dpll.n;
8090 bestm1 = pipe_config->dpll.m1;
8091 bestm2 = pipe_config->dpll.m2;
8092 bestp1 = pipe_config->dpll.p1;
8093 bestp2 = pipe_config->dpll.p2;
8095 /* See eDP HDMI DPIO driver vbios notes doc */
8097 /* PLL B needs special handling */
8099 vlv_pllb_recal_opamp(dev_priv, pipe);
8101 /* Set up Tx target for periodic Rcomp update */
8102 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
8104 /* Disable target IRef on PLL */
8105 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
8106 reg_val &= 0x00ffffff;
8107 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
8109 /* Disable fast lock */
8110 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
8112 /* Set idtafcrecal before PLL is enabled */
8113 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
8114 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
8115 mdiv |= ((bestn << DPIO_N_SHIFT));
8116 mdiv |= (1 << DPIO_K_SHIFT);
8119 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
8120 * but we don't support that).
8121 * Note: don't use the DAC post divider as it seems unstable.
8123 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
8124 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8126 mdiv |= DPIO_ENABLE_CALIBRATION;
8127 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8129 /* Set HBR and RBR LPF coefficients */
8130 if (pipe_config->port_clock == 162000 ||
8131 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
8132 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
8133 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8136 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8139 if (intel_crtc_has_dp_encoder(pipe_config)) {
8140 /* Use SSC source */
8142 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8145 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8147 } else { /* HDMI or VGA */
8148 /* Use bend source */
8150 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8153 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8157 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
8158 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
8159 if (intel_crtc_has_dp_encoder(pipe_config))
8160 coreclk |= 0x01000000;
8161 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
8163 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
8165 vlv_dpio_put(dev_priv);
8168 static void chv_prepare_pll(struct intel_crtc *crtc,
8169 const struct intel_crtc_state *pipe_config)
8171 struct drm_device *dev = crtc->base.dev;
8172 struct drm_i915_private *dev_priv = to_i915(dev);
8173 enum pipe pipe = crtc->pipe;
8174 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8175 u32 loopfilter, tribuf_calcntr;
8176 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
8180 /* Enable Refclk and SSC */
8181 I915_WRITE(DPLL(pipe),
8182 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
8184 /* No need to actually set up the DPLL with DSI */
8185 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8188 bestn = pipe_config->dpll.n;
8189 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
8190 bestm1 = pipe_config->dpll.m1;
8191 bestm2 = pipe_config->dpll.m2 >> 22;
8192 bestp1 = pipe_config->dpll.p1;
8193 bestp2 = pipe_config->dpll.p2;
8194 vco = pipe_config->dpll.vco;
8198 vlv_dpio_get(dev_priv);
8200 /* p1 and p2 divider */
8201 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
8202 5 << DPIO_CHV_S1_DIV_SHIFT |
8203 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
8204 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
8205 1 << DPIO_CHV_K_DIV_SHIFT);
8207 /* Feedback post-divider - m2 */
8208 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
8210 /* Feedback refclk divider - n and m1 */
8211 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
8212 DPIO_CHV_M1_DIV_BY_2 |
8213 1 << DPIO_CHV_N_DIV_SHIFT);
8215 /* M2 fraction division */
8216 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
8218 /* M2 fraction division enable */
8219 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8220 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
8221 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
8223 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
8224 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
8226 /* Program digital lock detect threshold */
8227 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
8228 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
8229 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
8230 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
8232 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
8233 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
8236 if (vco == 5400000) {
8237 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
8238 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
8239 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
8240 tribuf_calcntr = 0x9;
8241 } else if (vco <= 6200000) {
8242 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
8243 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
8244 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8245 tribuf_calcntr = 0x9;
8246 } else if (vco <= 6480000) {
8247 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8248 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8249 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8250 tribuf_calcntr = 0x8;
8252 /* Not supported. Apply the same limits as in the max case */
8253 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8254 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8255 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8258 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
8260 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
8261 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
8262 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
8263 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
8266 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
8267 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
8270 vlv_dpio_put(dev_priv);
8274 * vlv_force_pll_on - forcibly enable just the PLL
8275 * @dev_priv: i915 private structure
8276 * @pipe: pipe PLL to enable
8277 * @dpll: PLL configuration
8279 * Enable the PLL for @pipe using the supplied @dpll config. To be used
8280 * in cases where we need the PLL enabled even when @pipe is not going to
8283 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
8284 const struct dpll *dpll)
8286 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
8287 struct intel_crtc_state *pipe_config;
8289 pipe_config = intel_crtc_state_alloc(crtc);
8293 pipe_config->cpu_transcoder = (enum transcoder)pipe;
8294 pipe_config->pixel_multiplier = 1;
8295 pipe_config->dpll = *dpll;
8297 if (IS_CHERRYVIEW(dev_priv)) {
8298 chv_compute_dpll(crtc, pipe_config);
8299 chv_prepare_pll(crtc, pipe_config);
8300 chv_enable_pll(crtc, pipe_config);
8302 vlv_compute_dpll(crtc, pipe_config);
8303 vlv_prepare_pll(crtc, pipe_config);
8304 vlv_enable_pll(crtc, pipe_config);
8313 * vlv_force_pll_off - forcibly disable just the PLL
8314 * @dev_priv: i915 private structure
8315 * @pipe: pipe PLL to disable
8317 * Disable the PLL for @pipe. To be used in cases where we need
8318 * the PLL enabled even when @pipe is not going to be enabled.
8320 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
8322 if (IS_CHERRYVIEW(dev_priv))
8323 chv_disable_pll(dev_priv, pipe);
8325 vlv_disable_pll(dev_priv, pipe);
8328 static void i9xx_compute_dpll(struct intel_crtc *crtc,
8329 struct intel_crtc_state *crtc_state,
8330 struct dpll *reduced_clock)
8332 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8334 struct dpll *clock = &crtc_state->dpll;
8336 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8338 dpll = DPLL_VGA_MODE_DIS;
8340 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8341 dpll |= DPLLB_MODE_LVDS;
8343 dpll |= DPLLB_MODE_DAC_SERIAL;
8345 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8346 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8347 dpll |= (crtc_state->pixel_multiplier - 1)
8348 << SDVO_MULTIPLIER_SHIFT_HIRES;
8351 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8352 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8353 dpll |= DPLL_SDVO_HIGH_SPEED;
8355 if (intel_crtc_has_dp_encoder(crtc_state))
8356 dpll |= DPLL_SDVO_HIGH_SPEED;
8358 /* compute bitmask from p1 value */
8359 if (IS_PINEVIEW(dev_priv))
8360 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8362 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8363 if (IS_G4X(dev_priv) && reduced_clock)
8364 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8366 switch (clock->p2) {
8368 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8371 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8374 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8377 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8380 if (INTEL_GEN(dev_priv) >= 4)
8381 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8383 if (crtc_state->sdvo_tv_clock)
8384 dpll |= PLL_REF_INPUT_TVCLKINBC;
8385 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8386 intel_panel_use_ssc(dev_priv))
8387 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8389 dpll |= PLL_REF_INPUT_DREFCLK;
8391 dpll |= DPLL_VCO_ENABLE;
8392 crtc_state->dpll_hw_state.dpll = dpll;
8394 if (INTEL_GEN(dev_priv) >= 4) {
8395 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8396 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8397 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8401 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8402 struct intel_crtc_state *crtc_state,
8403 struct dpll *reduced_clock)
8405 struct drm_device *dev = crtc->base.dev;
8406 struct drm_i915_private *dev_priv = to_i915(dev);
8408 struct dpll *clock = &crtc_state->dpll;
8410 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8412 dpll = DPLL_VGA_MODE_DIS;
8414 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8415 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8418 dpll |= PLL_P1_DIVIDE_BY_TWO;
8420 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8422 dpll |= PLL_P2_DIVIDE_BY_4;
8427 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8428 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8429 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8430 * Enable) must be set to “1” in both the DPLL A Control Register
8431 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8433 * For simplicity We simply keep both bits always enabled in
8434 * both DPLLS. The spec says we should disable the DVO 2X clock
8435 * when not needed, but this seems to work fine in practice.
8437 if (IS_I830(dev_priv) ||
8438 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8439 dpll |= DPLL_DVO_2X_MODE;
8441 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8442 intel_panel_use_ssc(dev_priv))
8443 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8445 dpll |= PLL_REF_INPUT_DREFCLK;
8447 dpll |= DPLL_VCO_ENABLE;
8448 crtc_state->dpll_hw_state.dpll = dpll;
8451 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
8453 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8454 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8455 enum pipe pipe = crtc->pipe;
8456 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8457 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
8458 u32 crtc_vtotal, crtc_vblank_end;
8461 /* We need to be careful not to changed the adjusted mode, for otherwise
8462 * the hw state checker will get angry at the mismatch. */
8463 crtc_vtotal = adjusted_mode->crtc_vtotal;
8464 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8466 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8467 /* the chip adds 2 halflines automatically */
8469 crtc_vblank_end -= 1;
8471 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8472 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8474 vsyncshift = adjusted_mode->crtc_hsync_start -
8475 adjusted_mode->crtc_htotal / 2;
8477 vsyncshift += adjusted_mode->crtc_htotal;
8480 if (INTEL_GEN(dev_priv) > 3)
8481 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
8483 I915_WRITE(HTOTAL(cpu_transcoder),
8484 (adjusted_mode->crtc_hdisplay - 1) |
8485 ((adjusted_mode->crtc_htotal - 1) << 16));
8486 I915_WRITE(HBLANK(cpu_transcoder),
8487 (adjusted_mode->crtc_hblank_start - 1) |
8488 ((adjusted_mode->crtc_hblank_end - 1) << 16));
8489 I915_WRITE(HSYNC(cpu_transcoder),
8490 (adjusted_mode->crtc_hsync_start - 1) |
8491 ((adjusted_mode->crtc_hsync_end - 1) << 16));
8493 I915_WRITE(VTOTAL(cpu_transcoder),
8494 (adjusted_mode->crtc_vdisplay - 1) |
8495 ((crtc_vtotal - 1) << 16));
8496 I915_WRITE(VBLANK(cpu_transcoder),
8497 (adjusted_mode->crtc_vblank_start - 1) |
8498 ((crtc_vblank_end - 1) << 16));
8499 I915_WRITE(VSYNC(cpu_transcoder),
8500 (adjusted_mode->crtc_vsync_start - 1) |
8501 ((adjusted_mode->crtc_vsync_end - 1) << 16));
8503 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8504 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8505 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8507 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8508 (pipe == PIPE_B || pipe == PIPE_C))
8509 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
8513 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8515 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8516 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8517 enum pipe pipe = crtc->pipe;
8519 /* pipesrc controls the size that is scaled from, which should
8520 * always be the user's requested size.
8522 I915_WRITE(PIPESRC(pipe),
8523 ((crtc_state->pipe_src_w - 1) << 16) |
8524 (crtc_state->pipe_src_h - 1));
8527 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
8529 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
8530 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8532 if (IS_GEN(dev_priv, 2))
8535 if (INTEL_GEN(dev_priv) >= 9 ||
8536 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
8537 return I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
8539 return I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
8542 static void intel_get_pipe_timings(struct intel_crtc *crtc,
8543 struct intel_crtc_state *pipe_config)
8545 struct drm_device *dev = crtc->base.dev;
8546 struct drm_i915_private *dev_priv = to_i915(dev);
8547 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8550 tmp = I915_READ(HTOTAL(cpu_transcoder));
8551 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8552 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8554 if (!transcoder_is_dsi(cpu_transcoder)) {
8555 tmp = I915_READ(HBLANK(cpu_transcoder));
8556 pipe_config->hw.adjusted_mode.crtc_hblank_start =
8558 pipe_config->hw.adjusted_mode.crtc_hblank_end =
8559 ((tmp >> 16) & 0xffff) + 1;
8561 tmp = I915_READ(HSYNC(cpu_transcoder));
8562 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8563 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8565 tmp = I915_READ(VTOTAL(cpu_transcoder));
8566 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8567 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8569 if (!transcoder_is_dsi(cpu_transcoder)) {
8570 tmp = I915_READ(VBLANK(cpu_transcoder));
8571 pipe_config->hw.adjusted_mode.crtc_vblank_start =
8573 pipe_config->hw.adjusted_mode.crtc_vblank_end =
8574 ((tmp >> 16) & 0xffff) + 1;
8576 tmp = I915_READ(VSYNC(cpu_transcoder));
8577 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8578 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8580 if (intel_pipe_is_interlaced(pipe_config)) {
8581 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8582 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
8583 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
8587 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8588 struct intel_crtc_state *pipe_config)
8590 struct drm_device *dev = crtc->base.dev;
8591 struct drm_i915_private *dev_priv = to_i915(dev);
8594 tmp = I915_READ(PIPESRC(crtc->pipe));
8595 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8596 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8598 pipe_config->hw.mode.vdisplay = pipe_config->pipe_src_h;
8599 pipe_config->hw.mode.hdisplay = pipe_config->pipe_src_w;
8602 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
8603 struct intel_crtc_state *pipe_config)
8605 mode->hdisplay = pipe_config->hw.adjusted_mode.crtc_hdisplay;
8606 mode->htotal = pipe_config->hw.adjusted_mode.crtc_htotal;
8607 mode->hsync_start = pipe_config->hw.adjusted_mode.crtc_hsync_start;
8608 mode->hsync_end = pipe_config->hw.adjusted_mode.crtc_hsync_end;
8610 mode->vdisplay = pipe_config->hw.adjusted_mode.crtc_vdisplay;
8611 mode->vtotal = pipe_config->hw.adjusted_mode.crtc_vtotal;
8612 mode->vsync_start = pipe_config->hw.adjusted_mode.crtc_vsync_start;
8613 mode->vsync_end = pipe_config->hw.adjusted_mode.crtc_vsync_end;
8615 mode->flags = pipe_config->hw.adjusted_mode.flags;
8616 mode->type = DRM_MODE_TYPE_DRIVER;
8618 mode->clock = pipe_config->hw.adjusted_mode.crtc_clock;
8620 mode->hsync = drm_mode_hsync(mode);
8621 mode->vrefresh = drm_mode_vrefresh(mode);
8622 drm_mode_set_name(mode);
8625 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8627 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8628 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8633 /* we keep both pipes enabled on 830 */
8634 if (IS_I830(dev_priv))
8635 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8637 if (crtc_state->double_wide)
8638 pipeconf |= PIPECONF_DOUBLE_WIDE;
8640 /* only g4x and later have fancy bpc/dither controls */
8641 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8642 IS_CHERRYVIEW(dev_priv)) {
8643 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8644 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8645 pipeconf |= PIPECONF_DITHER_EN |
8646 PIPECONF_DITHER_TYPE_SP;
8648 switch (crtc_state->pipe_bpp) {
8650 pipeconf |= PIPECONF_6BPC;
8653 pipeconf |= PIPECONF_8BPC;
8656 pipeconf |= PIPECONF_10BPC;
8659 /* Case prevented by intel_choose_pipe_bpp_dither. */
8664 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8665 if (INTEL_GEN(dev_priv) < 4 ||
8666 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8667 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8669 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8671 pipeconf |= PIPECONF_PROGRESSIVE;
8674 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8675 crtc_state->limited_color_range)
8676 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8678 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8680 pipeconf |= PIPECONF_FRAME_START_DELAY(0);
8682 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
8683 POSTING_READ(PIPECONF(crtc->pipe));
8686 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8687 struct intel_crtc_state *crtc_state)
8689 struct drm_device *dev = crtc->base.dev;
8690 struct drm_i915_private *dev_priv = to_i915(dev);
8691 const struct intel_limit *limit;
8694 memset(&crtc_state->dpll_hw_state, 0,
8695 sizeof(crtc_state->dpll_hw_state));
8697 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8698 if (intel_panel_use_ssc(dev_priv)) {
8699 refclk = dev_priv->vbt.lvds_ssc_freq;
8700 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8703 limit = &intel_limits_i8xx_lvds;
8704 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8705 limit = &intel_limits_i8xx_dvo;
8707 limit = &intel_limits_i8xx_dac;
8710 if (!crtc_state->clock_set &&
8711 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8712 refclk, NULL, &crtc_state->dpll)) {
8713 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8717 i8xx_compute_dpll(crtc, crtc_state, NULL);
8722 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
8723 struct intel_crtc_state *crtc_state)
8725 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8726 const struct intel_limit *limit;
8729 memset(&crtc_state->dpll_hw_state, 0,
8730 sizeof(crtc_state->dpll_hw_state));
8732 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8733 if (intel_panel_use_ssc(dev_priv)) {
8734 refclk = dev_priv->vbt.lvds_ssc_freq;
8735 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8738 if (intel_is_dual_link_lvds(dev_priv))
8739 limit = &intel_limits_g4x_dual_channel_lvds;
8741 limit = &intel_limits_g4x_single_channel_lvds;
8742 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
8743 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
8744 limit = &intel_limits_g4x_hdmi;
8745 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
8746 limit = &intel_limits_g4x_sdvo;
8748 /* The option is for other outputs */
8749 limit = &intel_limits_i9xx_sdvo;
8752 if (!crtc_state->clock_set &&
8753 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8754 refclk, NULL, &crtc_state->dpll)) {
8755 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8759 i9xx_compute_dpll(crtc, crtc_state, NULL);
8764 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
8765 struct intel_crtc_state *crtc_state)
8767 struct drm_device *dev = crtc->base.dev;
8768 struct drm_i915_private *dev_priv = to_i915(dev);
8769 const struct intel_limit *limit;
8772 memset(&crtc_state->dpll_hw_state, 0,
8773 sizeof(crtc_state->dpll_hw_state));
8775 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8776 if (intel_panel_use_ssc(dev_priv)) {
8777 refclk = dev_priv->vbt.lvds_ssc_freq;
8778 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8781 limit = &intel_limits_pineview_lvds;
8783 limit = &intel_limits_pineview_sdvo;
8786 if (!crtc_state->clock_set &&
8787 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8788 refclk, NULL, &crtc_state->dpll)) {
8789 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8793 i9xx_compute_dpll(crtc, crtc_state, NULL);
8798 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
8799 struct intel_crtc_state *crtc_state)
8801 struct drm_device *dev = crtc->base.dev;
8802 struct drm_i915_private *dev_priv = to_i915(dev);
8803 const struct intel_limit *limit;
8806 memset(&crtc_state->dpll_hw_state, 0,
8807 sizeof(crtc_state->dpll_hw_state));
8809 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8810 if (intel_panel_use_ssc(dev_priv)) {
8811 refclk = dev_priv->vbt.lvds_ssc_freq;
8812 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
8815 limit = &intel_limits_i9xx_lvds;
8817 limit = &intel_limits_i9xx_sdvo;
8820 if (!crtc_state->clock_set &&
8821 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8822 refclk, NULL, &crtc_state->dpll)) {
8823 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8827 i9xx_compute_dpll(crtc, crtc_state, NULL);
8832 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
8833 struct intel_crtc_state *crtc_state)
8835 int refclk = 100000;
8836 const struct intel_limit *limit = &intel_limits_chv;
8838 memset(&crtc_state->dpll_hw_state, 0,
8839 sizeof(crtc_state->dpll_hw_state));
8841 if (!crtc_state->clock_set &&
8842 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8843 refclk, NULL, &crtc_state->dpll)) {
8844 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8848 chv_compute_dpll(crtc, crtc_state);
8853 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
8854 struct intel_crtc_state *crtc_state)
8856 int refclk = 100000;
8857 const struct intel_limit *limit = &intel_limits_vlv;
8859 memset(&crtc_state->dpll_hw_state, 0,
8860 sizeof(crtc_state->dpll_hw_state));
8862 if (!crtc_state->clock_set &&
8863 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8864 refclk, NULL, &crtc_state->dpll)) {
8865 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8869 vlv_compute_dpll(crtc, crtc_state);
8874 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
8876 if (IS_I830(dev_priv))
8879 return INTEL_GEN(dev_priv) >= 4 ||
8880 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
8883 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
8884 struct intel_crtc_state *pipe_config)
8886 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8889 if (!i9xx_has_pfit(dev_priv))
8892 tmp = I915_READ(PFIT_CONTROL);
8893 if (!(tmp & PFIT_ENABLE))
8896 /* Check whether the pfit is attached to our pipe. */
8897 if (INTEL_GEN(dev_priv) < 4) {
8898 if (crtc->pipe != PIPE_B)
8901 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
8905 pipe_config->gmch_pfit.control = tmp;
8906 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
8909 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
8910 struct intel_crtc_state *pipe_config)
8912 struct drm_device *dev = crtc->base.dev;
8913 struct drm_i915_private *dev_priv = to_i915(dev);
8914 enum pipe pipe = crtc->pipe;
8917 int refclk = 100000;
8919 /* In case of DSI, DPLL will not be used */
8920 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8923 vlv_dpio_get(dev_priv);
8924 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
8925 vlv_dpio_put(dev_priv);
8927 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
8928 clock.m2 = mdiv & DPIO_M2DIV_MASK;
8929 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
8930 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
8931 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
8933 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8937 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8938 struct intel_initial_plane_config *plane_config)
8940 struct drm_device *dev = crtc->base.dev;
8941 struct drm_i915_private *dev_priv = to_i915(dev);
8942 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8943 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8945 u32 val, base, offset;
8946 int fourcc, pixel_format;
8947 unsigned int aligned_height;
8948 struct drm_framebuffer *fb;
8949 struct intel_framebuffer *intel_fb;
8951 if (!plane->get_hw_state(plane, &pipe))
8954 WARN_ON(pipe != crtc->pipe);
8956 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8958 DRM_DEBUG_KMS("failed to alloc fb\n");
8962 fb = &intel_fb->base;
8966 val = I915_READ(DSPCNTR(i9xx_plane));
8968 if (INTEL_GEN(dev_priv) >= 4) {
8969 if (val & DISPPLANE_TILED) {
8970 plane_config->tiling = I915_TILING_X;
8971 fb->modifier = I915_FORMAT_MOD_X_TILED;
8974 if (val & DISPPLANE_ROTATE_180)
8975 plane_config->rotation = DRM_MODE_ROTATE_180;
8978 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8979 val & DISPPLANE_MIRROR)
8980 plane_config->rotation |= DRM_MODE_REFLECT_X;
8982 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8983 fourcc = i9xx_format_to_fourcc(pixel_format);
8984 fb->format = drm_format_info(fourcc);
8986 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8987 offset = I915_READ(DSPOFFSET(i9xx_plane));
8988 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8989 } else if (INTEL_GEN(dev_priv) >= 4) {
8990 if (plane_config->tiling)
8991 offset = I915_READ(DSPTILEOFF(i9xx_plane));
8993 offset = I915_READ(DSPLINOFF(i9xx_plane));
8994 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8996 base = I915_READ(DSPADDR(i9xx_plane));
8998 plane_config->base = base;
9000 val = I915_READ(PIPESRC(pipe));
9001 fb->width = ((val >> 16) & 0xfff) + 1;
9002 fb->height = ((val >> 0) & 0xfff) + 1;
9004 val = I915_READ(DSPSTRIDE(i9xx_plane));
9005 fb->pitches[0] = val & 0xffffffc0;
9007 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9009 plane_config->size = fb->pitches[0] * aligned_height;
9011 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9012 crtc->base.name, plane->base.name, fb->width, fb->height,
9013 fb->format->cpp[0] * 8, base, fb->pitches[0],
9014 plane_config->size);
9016 plane_config->fb = intel_fb;
9019 static void chv_crtc_clock_get(struct intel_crtc *crtc,
9020 struct intel_crtc_state *pipe_config)
9022 struct drm_device *dev = crtc->base.dev;
9023 struct drm_i915_private *dev_priv = to_i915(dev);
9024 enum pipe pipe = crtc->pipe;
9025 enum dpio_channel port = vlv_pipe_to_channel(pipe);
9027 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
9028 int refclk = 100000;
9030 /* In case of DSI, DPLL will not be used */
9031 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
9034 vlv_dpio_get(dev_priv);
9035 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
9036 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
9037 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
9038 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
9039 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
9040 vlv_dpio_put(dev_priv);
9042 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
9043 clock.m2 = (pll_dw0 & 0xff) << 22;
9044 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
9045 clock.m2 |= pll_dw2 & 0x3fffff;
9046 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
9047 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
9048 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
9050 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
9053 static enum intel_output_format
9054 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
9056 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9059 tmp = I915_READ(PIPEMISC(crtc->pipe));
9061 if (tmp & PIPEMISC_YUV420_ENABLE) {
9062 /* We support 4:2:0 in full blend mode only */
9063 WARN_ON((tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
9065 return INTEL_OUTPUT_FORMAT_YCBCR420;
9066 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
9067 return INTEL_OUTPUT_FORMAT_YCBCR444;
9069 return INTEL_OUTPUT_FORMAT_RGB;
9073 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
9075 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9076 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9077 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9078 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
9081 tmp = I915_READ(DSPCNTR(i9xx_plane));
9083 if (tmp & DISPPLANE_GAMMA_ENABLE)
9084 crtc_state->gamma_enable = true;
9086 if (!HAS_GMCH(dev_priv) &&
9087 tmp & DISPPLANE_PIPE_CSC_ENABLE)
9088 crtc_state->csc_enable = true;
9091 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
9092 struct intel_crtc_state *pipe_config)
9094 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9095 enum intel_display_power_domain power_domain;
9096 intel_wakeref_t wakeref;
9100 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9101 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9105 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9106 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9107 pipe_config->shared_dpll = NULL;
9108 pipe_config->master_transcoder = INVALID_TRANSCODER;
9112 tmp = I915_READ(PIPECONF(crtc->pipe));
9113 if (!(tmp & PIPECONF_ENABLE))
9116 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
9117 IS_CHERRYVIEW(dev_priv)) {
9118 switch (tmp & PIPECONF_BPC_MASK) {
9120 pipe_config->pipe_bpp = 18;
9123 pipe_config->pipe_bpp = 24;
9125 case PIPECONF_10BPC:
9126 pipe_config->pipe_bpp = 30;
9133 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
9134 (tmp & PIPECONF_COLOR_RANGE_SELECT))
9135 pipe_config->limited_color_range = true;
9137 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
9138 PIPECONF_GAMMA_MODE_SHIFT;
9140 if (IS_CHERRYVIEW(dev_priv))
9141 pipe_config->cgm_mode = I915_READ(CGM_PIPE_MODE(crtc->pipe));
9143 i9xx_get_pipe_color_config(pipe_config);
9144 intel_color_get_config(pipe_config);
9146 if (INTEL_GEN(dev_priv) < 4)
9147 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
9149 intel_get_pipe_timings(crtc, pipe_config);
9150 intel_get_pipe_src_size(crtc, pipe_config);
9152 i9xx_get_pfit_config(crtc, pipe_config);
9154 if (INTEL_GEN(dev_priv) >= 4) {
9155 /* No way to read it out on pipes B and C */
9156 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
9157 tmp = dev_priv->chv_dpll_md[crtc->pipe];
9159 tmp = I915_READ(DPLL_MD(crtc->pipe));
9160 pipe_config->pixel_multiplier =
9161 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
9162 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
9163 pipe_config->dpll_hw_state.dpll_md = tmp;
9164 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
9165 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
9166 tmp = I915_READ(DPLL(crtc->pipe));
9167 pipe_config->pixel_multiplier =
9168 ((tmp & SDVO_MULTIPLIER_MASK)
9169 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
9171 /* Note that on i915G/GM the pixel multiplier is in the sdvo
9172 * port and will be fixed up in the encoder->get_config
9174 pipe_config->pixel_multiplier = 1;
9176 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
9177 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
9178 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
9179 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
9181 /* Mask out read-only status bits. */
9182 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
9183 DPLL_PORTC_READY_MASK |
9184 DPLL_PORTB_READY_MASK);
9187 if (IS_CHERRYVIEW(dev_priv))
9188 chv_crtc_clock_get(crtc, pipe_config);
9189 else if (IS_VALLEYVIEW(dev_priv))
9190 vlv_crtc_clock_get(crtc, pipe_config);
9192 i9xx_crtc_clock_get(crtc, pipe_config);
9195 * Normally the dotclock is filled in by the encoder .get_config()
9196 * but in case the pipe is enabled w/o any ports we need a sane
9199 pipe_config->hw.adjusted_mode.crtc_clock =
9200 pipe_config->port_clock / pipe_config->pixel_multiplier;
9205 intel_display_power_put(dev_priv, power_domain, wakeref);
9210 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
9212 struct intel_encoder *encoder;
9215 bool has_lvds = false;
9216 bool has_cpu_edp = false;
9217 bool has_panel = false;
9218 bool has_ck505 = false;
9219 bool can_ssc = false;
9220 bool using_ssc_source = false;
9222 /* We need to take the global config into account */
9223 for_each_intel_encoder(&dev_priv->drm, encoder) {
9224 switch (encoder->type) {
9225 case INTEL_OUTPUT_LVDS:
9229 case INTEL_OUTPUT_EDP:
9231 if (encoder->port == PORT_A)
9239 if (HAS_PCH_IBX(dev_priv)) {
9240 has_ck505 = dev_priv->vbt.display_clock_mode;
9241 can_ssc = has_ck505;
9247 /* Check if any DPLLs are using the SSC source */
9248 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
9249 u32 temp = I915_READ(PCH_DPLL(i));
9251 if (!(temp & DPLL_VCO_ENABLE))
9254 if ((temp & PLL_REF_INPUT_MASK) ==
9255 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
9256 using_ssc_source = true;
9261 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
9262 has_panel, has_lvds, has_ck505, using_ssc_source);
9264 /* Ironlake: try to setup display ref clock before DPLL
9265 * enabling. This is only under driver's control after
9266 * PCH B stepping, previous chipset stepping should be
9267 * ignoring this setting.
9269 val = I915_READ(PCH_DREF_CONTROL);
9271 /* As we must carefully and slowly disable/enable each source in turn,
9272 * compute the final state we want first and check if we need to
9273 * make any changes at all.
9276 final &= ~DREF_NONSPREAD_SOURCE_MASK;
9278 final |= DREF_NONSPREAD_CK505_ENABLE;
9280 final |= DREF_NONSPREAD_SOURCE_ENABLE;
9282 final &= ~DREF_SSC_SOURCE_MASK;
9283 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9284 final &= ~DREF_SSC1_ENABLE;
9287 final |= DREF_SSC_SOURCE_ENABLE;
9289 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9290 final |= DREF_SSC1_ENABLE;
9293 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9294 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9296 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9298 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9299 } else if (using_ssc_source) {
9300 final |= DREF_SSC_SOURCE_ENABLE;
9301 final |= DREF_SSC1_ENABLE;
9307 /* Always enable nonspread source */
9308 val &= ~DREF_NONSPREAD_SOURCE_MASK;
9311 val |= DREF_NONSPREAD_CK505_ENABLE;
9313 val |= DREF_NONSPREAD_SOURCE_ENABLE;
9316 val &= ~DREF_SSC_SOURCE_MASK;
9317 val |= DREF_SSC_SOURCE_ENABLE;
9319 /* SSC must be turned on before enabling the CPU output */
9320 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9321 DRM_DEBUG_KMS("Using SSC on panel\n");
9322 val |= DREF_SSC1_ENABLE;
9324 val &= ~DREF_SSC1_ENABLE;
9326 /* Get SSC going before enabling the outputs */
9327 I915_WRITE(PCH_DREF_CONTROL, val);
9328 POSTING_READ(PCH_DREF_CONTROL);
9331 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9333 /* Enable CPU source on CPU attached eDP */
9335 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9336 DRM_DEBUG_KMS("Using SSC on eDP\n");
9337 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9339 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9341 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9343 I915_WRITE(PCH_DREF_CONTROL, val);
9344 POSTING_READ(PCH_DREF_CONTROL);
9347 DRM_DEBUG_KMS("Disabling CPU source output\n");
9349 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9351 /* Turn off CPU output */
9352 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9354 I915_WRITE(PCH_DREF_CONTROL, val);
9355 POSTING_READ(PCH_DREF_CONTROL);
9358 if (!using_ssc_source) {
9359 DRM_DEBUG_KMS("Disabling SSC source\n");
9361 /* Turn off the SSC source */
9362 val &= ~DREF_SSC_SOURCE_MASK;
9363 val |= DREF_SSC_SOURCE_DISABLE;
9366 val &= ~DREF_SSC1_ENABLE;
9368 I915_WRITE(PCH_DREF_CONTROL, val);
9369 POSTING_READ(PCH_DREF_CONTROL);
9374 BUG_ON(val != final);
9377 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9381 tmp = I915_READ(SOUTH_CHICKEN2);
9382 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9383 I915_WRITE(SOUTH_CHICKEN2, tmp);
9385 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
9386 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9387 DRM_ERROR("FDI mPHY reset assert timeout\n");
9389 tmp = I915_READ(SOUTH_CHICKEN2);
9390 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9391 I915_WRITE(SOUTH_CHICKEN2, tmp);
9393 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
9394 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9395 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
9398 /* WaMPhyProgramming:hsw */
9399 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9403 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9404 tmp &= ~(0xFF << 24);
9405 tmp |= (0x12 << 24);
9406 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9408 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9410 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9412 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9414 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9416 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9417 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9418 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9420 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9421 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9422 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9424 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9427 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9429 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9432 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9434 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9437 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9439 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9442 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9444 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9445 tmp &= ~(0xFF << 16);
9446 tmp |= (0x1C << 16);
9447 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9449 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9450 tmp &= ~(0xFF << 16);
9451 tmp |= (0x1C << 16);
9452 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9454 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9456 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9458 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9460 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9462 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9463 tmp &= ~(0xF << 28);
9465 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9467 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9468 tmp &= ~(0xF << 28);
9470 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9473 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9474 * Programming" based on the parameters passed:
9475 * - Sequence to enable CLKOUT_DP
9476 * - Sequence to enable CLKOUT_DP without spread
9477 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9479 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9480 bool with_spread, bool with_fdi)
9484 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
9486 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
9487 with_fdi, "LP PCH doesn't have FDI\n"))
9490 mutex_lock(&dev_priv->sb_lock);
9492 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9493 tmp &= ~SBI_SSCCTL_DISABLE;
9494 tmp |= SBI_SSCCTL_PATHALT;
9495 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9500 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9501 tmp &= ~SBI_SSCCTL_PATHALT;
9502 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9505 lpt_reset_fdi_mphy(dev_priv);
9506 lpt_program_fdi_mphy(dev_priv);
9510 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9511 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9512 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9513 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9515 mutex_unlock(&dev_priv->sb_lock);
9518 /* Sequence to disable CLKOUT_DP */
9519 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9523 mutex_lock(&dev_priv->sb_lock);
9525 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9526 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9527 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9528 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9530 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9531 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9532 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9533 tmp |= SBI_SSCCTL_PATHALT;
9534 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9537 tmp |= SBI_SSCCTL_DISABLE;
9538 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9541 mutex_unlock(&dev_priv->sb_lock);
9544 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9546 static const u16 sscdivintphase[] = {
9547 [BEND_IDX( 50)] = 0x3B23,
9548 [BEND_IDX( 45)] = 0x3B23,
9549 [BEND_IDX( 40)] = 0x3C23,
9550 [BEND_IDX( 35)] = 0x3C23,
9551 [BEND_IDX( 30)] = 0x3D23,
9552 [BEND_IDX( 25)] = 0x3D23,
9553 [BEND_IDX( 20)] = 0x3E23,
9554 [BEND_IDX( 15)] = 0x3E23,
9555 [BEND_IDX( 10)] = 0x3F23,
9556 [BEND_IDX( 5)] = 0x3F23,
9557 [BEND_IDX( 0)] = 0x0025,
9558 [BEND_IDX( -5)] = 0x0025,
9559 [BEND_IDX(-10)] = 0x0125,
9560 [BEND_IDX(-15)] = 0x0125,
9561 [BEND_IDX(-20)] = 0x0225,
9562 [BEND_IDX(-25)] = 0x0225,
9563 [BEND_IDX(-30)] = 0x0325,
9564 [BEND_IDX(-35)] = 0x0325,
9565 [BEND_IDX(-40)] = 0x0425,
9566 [BEND_IDX(-45)] = 0x0425,
9567 [BEND_IDX(-50)] = 0x0525,
9572 * steps -50 to 50 inclusive, in steps of 5
9573 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9574 * change in clock period = -(steps / 10) * 5.787 ps
9576 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9579 int idx = BEND_IDX(steps);
9581 if (WARN_ON(steps % 5 != 0))
9584 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
9587 mutex_lock(&dev_priv->sb_lock);
9589 if (steps % 10 != 0)
9593 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9595 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9597 tmp |= sscdivintphase[idx];
9598 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9600 mutex_unlock(&dev_priv->sb_lock);
9605 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9607 u32 fuse_strap = I915_READ(FUSE_STRAP);
9608 u32 ctl = I915_READ(SPLL_CTL);
9610 if ((ctl & SPLL_PLL_ENABLE) == 0)
9613 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9614 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9617 if (IS_BROADWELL(dev_priv) &&
9618 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9624 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9625 enum intel_dpll_id id)
9627 u32 fuse_strap = I915_READ(FUSE_STRAP);
9628 u32 ctl = I915_READ(WRPLL_CTL(id));
9630 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9633 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9636 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9637 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9638 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9644 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9646 struct intel_encoder *encoder;
9647 bool has_fdi = false;
9649 for_each_intel_encoder(&dev_priv->drm, encoder) {
9650 switch (encoder->type) {
9651 case INTEL_OUTPUT_ANALOG:
9660 * The BIOS may have decided to use the PCH SSC
9661 * reference so we must not disable it until the
9662 * relevant PLLs have stopped relying on it. We'll
9663 * just leave the PCH SSC reference enabled in case
9664 * any active PLL is using it. It will get disabled
9665 * after runtime suspend if we don't have FDI.
9667 * TODO: Move the whole reference clock handling
9668 * to the modeset sequence proper so that we can
9669 * actually enable/disable/reconfigure these things
9670 * safely. To do that we need to introduce a real
9671 * clock hierarchy. That would also allow us to do
9672 * clock bending finally.
9674 dev_priv->pch_ssc_use = 0;
9676 if (spll_uses_pch_ssc(dev_priv)) {
9677 DRM_DEBUG_KMS("SPLL using PCH SSC\n");
9678 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
9681 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9682 DRM_DEBUG_KMS("WRPLL1 using PCH SSC\n");
9683 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
9686 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9687 DRM_DEBUG_KMS("WRPLL2 using PCH SSC\n");
9688 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
9691 if (dev_priv->pch_ssc_use)
9695 lpt_bend_clkout_dp(dev_priv, 0);
9696 lpt_enable_clkout_dp(dev_priv, true, true);
9698 lpt_disable_clkout_dp(dev_priv);
9703 * Initialize reference clocks when the driver loads
9705 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
9707 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
9708 ironlake_init_pch_refclk(dev_priv);
9709 else if (HAS_PCH_LPT(dev_priv))
9710 lpt_init_pch_refclk(dev_priv);
9713 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
9715 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9716 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9717 enum pipe pipe = crtc->pipe;
9722 switch (crtc_state->pipe_bpp) {
9724 val |= PIPECONF_6BPC;
9727 val |= PIPECONF_8BPC;
9730 val |= PIPECONF_10BPC;
9733 val |= PIPECONF_12BPC;
9736 /* Case prevented by intel_choose_pipe_bpp_dither. */
9740 if (crtc_state->dither)
9741 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9743 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9744 val |= PIPECONF_INTERLACED_ILK;
9746 val |= PIPECONF_PROGRESSIVE;
9749 * This would end up with an odd purple hue over
9750 * the entire display. Make sure we don't do it.
9752 WARN_ON(crtc_state->limited_color_range &&
9753 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
9755 if (crtc_state->limited_color_range)
9756 val |= PIPECONF_COLOR_RANGE_SELECT;
9758 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
9759 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
9761 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
9763 val |= PIPECONF_FRAME_START_DELAY(0);
9765 I915_WRITE(PIPECONF(pipe), val);
9766 POSTING_READ(PIPECONF(pipe));
9769 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
9771 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9772 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9773 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
9776 if (IS_HASWELL(dev_priv) && crtc_state->dither)
9777 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
9779 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9780 val |= PIPECONF_INTERLACED_ILK;
9782 val |= PIPECONF_PROGRESSIVE;
9784 if (IS_HASWELL(dev_priv) &&
9785 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
9786 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
9788 I915_WRITE(PIPECONF(cpu_transcoder), val);
9789 POSTING_READ(PIPECONF(cpu_transcoder));
9792 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
9794 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9795 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9798 switch (crtc_state->pipe_bpp) {
9800 val |= PIPEMISC_DITHER_6_BPC;
9803 val |= PIPEMISC_DITHER_8_BPC;
9806 val |= PIPEMISC_DITHER_10_BPC;
9809 val |= PIPEMISC_DITHER_12_BPC;
9812 MISSING_CASE(crtc_state->pipe_bpp);
9816 if (crtc_state->dither)
9817 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
9819 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
9820 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
9821 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
9823 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
9824 val |= PIPEMISC_YUV420_ENABLE |
9825 PIPEMISC_YUV420_MODE_FULL_BLEND;
9827 if (INTEL_GEN(dev_priv) >= 11 &&
9828 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
9829 BIT(PLANE_CURSOR))) == 0)
9830 val |= PIPEMISC_HDR_MODE_PRECISION;
9832 I915_WRITE(PIPEMISC(crtc->pipe), val);
9835 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
9837 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9840 tmp = I915_READ(PIPEMISC(crtc->pipe));
9842 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
9843 case PIPEMISC_DITHER_6_BPC:
9845 case PIPEMISC_DITHER_8_BPC:
9847 case PIPEMISC_DITHER_10_BPC:
9849 case PIPEMISC_DITHER_12_BPC:
9857 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
9860 * Account for spread spectrum to avoid
9861 * oversubscribing the link. Max center spread
9862 * is 2.5%; use 5% for safety's sake.
9864 u32 bps = target_clock * bpp * 21 / 20;
9865 return DIV_ROUND_UP(bps, link_bw * 8);
9868 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
9870 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
9873 static void ironlake_compute_dpll(struct intel_crtc *crtc,
9874 struct intel_crtc_state *crtc_state,
9875 struct dpll *reduced_clock)
9877 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9881 /* Enable autotuning of the PLL clock (if permissible) */
9883 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9884 if ((intel_panel_use_ssc(dev_priv) &&
9885 dev_priv->vbt.lvds_ssc_freq == 100000) ||
9886 (HAS_PCH_IBX(dev_priv) &&
9887 intel_is_dual_link_lvds(dev_priv)))
9889 } else if (crtc_state->sdvo_tv_clock) {
9893 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
9895 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
9898 if (reduced_clock) {
9899 fp2 = i9xx_dpll_compute_fp(reduced_clock);
9901 if (reduced_clock->m < factor * reduced_clock->n)
9909 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
9910 dpll |= DPLLB_MODE_LVDS;
9912 dpll |= DPLLB_MODE_DAC_SERIAL;
9914 dpll |= (crtc_state->pixel_multiplier - 1)
9915 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
9917 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
9918 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
9919 dpll |= DPLL_SDVO_HIGH_SPEED;
9921 if (intel_crtc_has_dp_encoder(crtc_state))
9922 dpll |= DPLL_SDVO_HIGH_SPEED;
9925 * The high speed IO clock is only really required for
9926 * SDVO/HDMI/DP, but we also enable it for CRT to make it
9927 * possible to share the DPLL between CRT and HDMI. Enabling
9928 * the clock needlessly does no real harm, except use up a
9929 * bit of power potentially.
9931 * We'll limit this to IVB with 3 pipes, since it has only two
9932 * DPLLs and so DPLL sharing is the only way to get three pipes
9933 * driving PCH ports at the same time. On SNB we could do this,
9934 * and potentially avoid enabling the second DPLL, but it's not
9935 * clear if it''s a win or loss power wise. No point in doing
9936 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
9938 if (INTEL_NUM_PIPES(dev_priv) == 3 &&
9939 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
9940 dpll |= DPLL_SDVO_HIGH_SPEED;
9942 /* compute bitmask from p1 value */
9943 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
9945 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
9947 switch (crtc_state->dpll.p2) {
9949 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
9952 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
9955 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
9958 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
9962 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
9963 intel_panel_use_ssc(dev_priv))
9964 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
9966 dpll |= PLL_REF_INPUT_DREFCLK;
9968 dpll |= DPLL_VCO_ENABLE;
9970 crtc_state->dpll_hw_state.dpll = dpll;
9971 crtc_state->dpll_hw_state.fp0 = fp;
9972 crtc_state->dpll_hw_state.fp1 = fp2;
9975 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
9976 struct intel_crtc_state *crtc_state)
9978 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9979 struct intel_atomic_state *state =
9980 to_intel_atomic_state(crtc_state->uapi.state);
9981 const struct intel_limit *limit;
9982 int refclk = 120000;
9984 memset(&crtc_state->dpll_hw_state, 0,
9985 sizeof(crtc_state->dpll_hw_state));
9987 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
9988 if (!crtc_state->has_pch_encoder)
9991 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9992 if (intel_panel_use_ssc(dev_priv)) {
9993 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
9994 dev_priv->vbt.lvds_ssc_freq);
9995 refclk = dev_priv->vbt.lvds_ssc_freq;
9998 if (intel_is_dual_link_lvds(dev_priv)) {
9999 if (refclk == 100000)
10000 limit = &intel_limits_ironlake_dual_lvds_100m;
10002 limit = &intel_limits_ironlake_dual_lvds;
10004 if (refclk == 100000)
10005 limit = &intel_limits_ironlake_single_lvds_100m;
10007 limit = &intel_limits_ironlake_single_lvds;
10010 limit = &intel_limits_ironlake_dac;
10013 if (!crtc_state->clock_set &&
10014 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
10015 refclk, NULL, &crtc_state->dpll)) {
10016 DRM_ERROR("Couldn't find PLL settings for mode!\n");
10020 ironlake_compute_dpll(crtc, crtc_state, NULL);
10022 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
10023 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10024 pipe_name(crtc->pipe));
10031 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
10032 struct intel_link_m_n *m_n)
10034 struct drm_device *dev = crtc->base.dev;
10035 struct drm_i915_private *dev_priv = to_i915(dev);
10036 enum pipe pipe = crtc->pipe;
10038 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
10039 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
10040 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
10042 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
10043 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
10044 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10047 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
10048 enum transcoder transcoder,
10049 struct intel_link_m_n *m_n,
10050 struct intel_link_m_n *m2_n2)
10052 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10053 enum pipe pipe = crtc->pipe;
10055 if (INTEL_GEN(dev_priv) >= 5) {
10056 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
10057 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
10058 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
10060 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
10061 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
10062 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10064 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
10065 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
10066 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
10067 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
10069 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
10070 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
10071 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10074 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
10075 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
10076 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
10078 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
10079 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
10080 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10084 void intel_dp_get_m_n(struct intel_crtc *crtc,
10085 struct intel_crtc_state *pipe_config)
10087 if (pipe_config->has_pch_encoder)
10088 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
10090 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10091 &pipe_config->dp_m_n,
10092 &pipe_config->dp_m2_n2);
10095 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
10096 struct intel_crtc_state *pipe_config)
10098 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10099 &pipe_config->fdi_m_n, NULL);
10102 static void skylake_get_pfit_config(struct intel_crtc *crtc,
10103 struct intel_crtc_state *pipe_config)
10105 struct drm_device *dev = crtc->base.dev;
10106 struct drm_i915_private *dev_priv = to_i915(dev);
10107 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
10112 /* find scaler attached to this pipe */
10113 for (i = 0; i < crtc->num_scalers; i++) {
10114 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
10115 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
10117 pipe_config->pch_pfit.enabled = true;
10118 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
10119 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
10120 scaler_state->scalers[i].in_use = true;
10125 scaler_state->scaler_id = id;
10127 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
10129 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
10134 skylake_get_initial_plane_config(struct intel_crtc *crtc,
10135 struct intel_initial_plane_config *plane_config)
10137 struct drm_device *dev = crtc->base.dev;
10138 struct drm_i915_private *dev_priv = to_i915(dev);
10139 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
10140 enum plane_id plane_id = plane->id;
10142 u32 val, base, offset, stride_mult, tiling, alpha;
10143 int fourcc, pixel_format;
10144 unsigned int aligned_height;
10145 struct drm_framebuffer *fb;
10146 struct intel_framebuffer *intel_fb;
10148 if (!plane->get_hw_state(plane, &pipe))
10151 WARN_ON(pipe != crtc->pipe);
10153 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10155 DRM_DEBUG_KMS("failed to alloc fb\n");
10159 fb = &intel_fb->base;
10163 val = I915_READ(PLANE_CTL(pipe, plane_id));
10165 if (INTEL_GEN(dev_priv) >= 11)
10166 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
10168 pixel_format = val & PLANE_CTL_FORMAT_MASK;
10170 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
10171 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
10172 alpha &= PLANE_COLOR_ALPHA_MASK;
10174 alpha = val & PLANE_CTL_ALPHA_MASK;
10177 fourcc = skl_format_to_fourcc(pixel_format,
10178 val & PLANE_CTL_ORDER_RGBX, alpha);
10179 fb->format = drm_format_info(fourcc);
10181 tiling = val & PLANE_CTL_TILED_MASK;
10183 case PLANE_CTL_TILED_LINEAR:
10184 fb->modifier = DRM_FORMAT_MOD_LINEAR;
10186 case PLANE_CTL_TILED_X:
10187 plane_config->tiling = I915_TILING_X;
10188 fb->modifier = I915_FORMAT_MOD_X_TILED;
10190 case PLANE_CTL_TILED_Y:
10191 plane_config->tiling = I915_TILING_Y;
10192 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10193 fb->modifier = INTEL_GEN(dev_priv) >= 12 ?
10194 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS :
10195 I915_FORMAT_MOD_Y_TILED_CCS;
10197 fb->modifier = I915_FORMAT_MOD_Y_TILED;
10199 case PLANE_CTL_TILED_YF:
10200 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10201 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
10203 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
10206 MISSING_CASE(tiling);
10211 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
10212 * while i915 HW rotation is clockwise, thats why this swapping.
10214 switch (val & PLANE_CTL_ROTATE_MASK) {
10215 case PLANE_CTL_ROTATE_0:
10216 plane_config->rotation = DRM_MODE_ROTATE_0;
10218 case PLANE_CTL_ROTATE_90:
10219 plane_config->rotation = DRM_MODE_ROTATE_270;
10221 case PLANE_CTL_ROTATE_180:
10222 plane_config->rotation = DRM_MODE_ROTATE_180;
10224 case PLANE_CTL_ROTATE_270:
10225 plane_config->rotation = DRM_MODE_ROTATE_90;
10229 if (INTEL_GEN(dev_priv) >= 10 &&
10230 val & PLANE_CTL_FLIP_HORIZONTAL)
10231 plane_config->rotation |= DRM_MODE_REFLECT_X;
10233 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
10234 plane_config->base = base;
10236 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
10238 val = I915_READ(PLANE_SIZE(pipe, plane_id));
10239 fb->height = ((val >> 16) & 0xffff) + 1;
10240 fb->width = ((val >> 0) & 0xffff) + 1;
10242 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
10243 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
10244 fb->pitches[0] = (val & 0x3ff) * stride_mult;
10246 aligned_height = intel_fb_align_height(fb, 0, fb->height);
10248 plane_config->size = fb->pitches[0] * aligned_height;
10250 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
10251 crtc->base.name, plane->base.name, fb->width, fb->height,
10252 fb->format->cpp[0] * 8, base, fb->pitches[0],
10253 plane_config->size);
10255 plane_config->fb = intel_fb;
10262 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
10263 struct intel_crtc_state *pipe_config)
10265 struct drm_device *dev = crtc->base.dev;
10266 struct drm_i915_private *dev_priv = to_i915(dev);
10269 tmp = I915_READ(PF_CTL(crtc->pipe));
10271 if (tmp & PF_ENABLE) {
10272 pipe_config->pch_pfit.enabled = true;
10273 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
10274 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
10276 /* We currently do not free assignements of panel fitters on
10277 * ivb/hsw (since we don't use the higher upscaling modes which
10278 * differentiates them) so just WARN about this case for now. */
10279 if (IS_GEN(dev_priv, 7)) {
10280 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
10281 PF_PIPE_SEL_IVB(crtc->pipe));
10286 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
10287 struct intel_crtc_state *pipe_config)
10289 struct drm_device *dev = crtc->base.dev;
10290 struct drm_i915_private *dev_priv = to_i915(dev);
10291 enum intel_display_power_domain power_domain;
10292 intel_wakeref_t wakeref;
10296 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10297 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10301 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10302 pipe_config->shared_dpll = NULL;
10303 pipe_config->master_transcoder = INVALID_TRANSCODER;
10306 tmp = I915_READ(PIPECONF(crtc->pipe));
10307 if (!(tmp & PIPECONF_ENABLE))
10310 switch (tmp & PIPECONF_BPC_MASK) {
10311 case PIPECONF_6BPC:
10312 pipe_config->pipe_bpp = 18;
10314 case PIPECONF_8BPC:
10315 pipe_config->pipe_bpp = 24;
10317 case PIPECONF_10BPC:
10318 pipe_config->pipe_bpp = 30;
10320 case PIPECONF_12BPC:
10321 pipe_config->pipe_bpp = 36;
10327 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
10328 pipe_config->limited_color_range = true;
10330 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
10331 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
10332 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
10333 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10336 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10340 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
10341 PIPECONF_GAMMA_MODE_SHIFT;
10343 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
10345 i9xx_get_pipe_color_config(pipe_config);
10346 intel_color_get_config(pipe_config);
10348 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
10349 struct intel_shared_dpll *pll;
10350 enum intel_dpll_id pll_id;
10352 pipe_config->has_pch_encoder = true;
10354 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
10355 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10356 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10358 ironlake_get_fdi_m_n_config(crtc, pipe_config);
10360 if (HAS_PCH_IBX(dev_priv)) {
10362 * The pipe->pch transcoder and pch transcoder->pll
10363 * mapping is fixed.
10365 pll_id = (enum intel_dpll_id) crtc->pipe;
10367 tmp = I915_READ(PCH_DPLL_SEL);
10368 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
10369 pll_id = DPLL_ID_PCH_PLL_B;
10371 pll_id= DPLL_ID_PCH_PLL_A;
10374 pipe_config->shared_dpll =
10375 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10376 pll = pipe_config->shared_dpll;
10378 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10379 &pipe_config->dpll_hw_state));
10381 tmp = pipe_config->dpll_hw_state.dpll;
10382 pipe_config->pixel_multiplier =
10383 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10384 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10386 ironlake_pch_clock_get(crtc, pipe_config);
10388 pipe_config->pixel_multiplier = 1;
10391 intel_get_pipe_timings(crtc, pipe_config);
10392 intel_get_pipe_src_size(crtc, pipe_config);
10394 ironlake_get_pfit_config(crtc, pipe_config);
10399 intel_display_power_put(dev_priv, power_domain, wakeref);
10403 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
10404 struct intel_crtc_state *crtc_state)
10406 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10407 struct intel_atomic_state *state =
10408 to_intel_atomic_state(crtc_state->uapi.state);
10410 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10411 INTEL_GEN(dev_priv) >= 11) {
10412 struct intel_encoder *encoder =
10413 intel_get_crtc_new_encoder(state, crtc_state);
10415 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10416 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
10417 pipe_name(crtc->pipe));
10425 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
10427 struct intel_crtc_state *pipe_config)
10429 enum intel_dpll_id id;
10432 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10433 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10435 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
10438 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10441 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
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 skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
10504 struct intel_crtc_state *pipe_config)
10506 enum intel_dpll_id id;
10509 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10510 id = temp >> (port * 3 + 1);
10512 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
10515 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10518 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
10520 struct intel_crtc_state *pipe_config)
10522 enum intel_dpll_id id;
10523 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
10525 switch (ddi_pll_sel) {
10526 case PORT_CLK_SEL_WRPLL1:
10527 id = DPLL_ID_WRPLL1;
10529 case PORT_CLK_SEL_WRPLL2:
10530 id = DPLL_ID_WRPLL2;
10532 case PORT_CLK_SEL_SPLL:
10535 case PORT_CLK_SEL_LCPLL_810:
10536 id = DPLL_ID_LCPLL_810;
10538 case PORT_CLK_SEL_LCPLL_1350:
10539 id = DPLL_ID_LCPLL_1350;
10541 case PORT_CLK_SEL_LCPLL_2700:
10542 id = DPLL_ID_LCPLL_2700;
10545 MISSING_CASE(ddi_pll_sel);
10547 case PORT_CLK_SEL_NONE:
10551 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10554 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10555 struct intel_crtc_state *pipe_config,
10556 u64 *power_domain_mask,
10557 intel_wakeref_t *wakerefs)
10559 struct drm_device *dev = crtc->base.dev;
10560 struct drm_i915_private *dev_priv = to_i915(dev);
10561 enum intel_display_power_domain power_domain;
10562 unsigned long panel_transcoder_mask = 0;
10563 unsigned long enabled_panel_transcoders = 0;
10564 enum transcoder panel_transcoder;
10565 intel_wakeref_t wf;
10568 if (INTEL_GEN(dev_priv) >= 11)
10569 panel_transcoder_mask |=
10570 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10572 if (HAS_TRANSCODER_EDP(dev_priv))
10573 panel_transcoder_mask |= BIT(TRANSCODER_EDP);
10576 * The pipe->transcoder mapping is fixed with the exception of the eDP
10577 * and DSI transcoders handled below.
10579 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10582 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10583 * consistency and less surprising code; it's in always on power).
10585 for_each_set_bit(panel_transcoder,
10586 &panel_transcoder_mask,
10587 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
10588 bool force_thru = false;
10589 enum pipe trans_pipe;
10591 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
10592 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10596 * Log all enabled ones, only use the first one.
10598 * FIXME: This won't work for two separate DSI displays.
10600 enabled_panel_transcoders |= BIT(panel_transcoder);
10601 if (enabled_panel_transcoders != BIT(panel_transcoder))
10604 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10606 WARN(1, "unknown pipe linked to transcoder %s\n",
10607 transcoder_name(panel_transcoder));
10609 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10612 case TRANS_DDI_EDP_INPUT_A_ON:
10613 trans_pipe = PIPE_A;
10615 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10616 trans_pipe = PIPE_B;
10618 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10619 trans_pipe = PIPE_C;
10621 case TRANS_DDI_EDP_INPUT_D_ONOFF:
10622 trans_pipe = PIPE_D;
10626 if (trans_pipe == crtc->pipe) {
10627 pipe_config->cpu_transcoder = panel_transcoder;
10628 pipe_config->pch_pfit.force_thru = force_thru;
10633 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10635 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10636 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10638 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
10639 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10641 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10645 wakerefs[power_domain] = wf;
10646 *power_domain_mask |= BIT_ULL(power_domain);
10648 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10650 return tmp & PIPECONF_ENABLE;
10653 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10654 struct intel_crtc_state *pipe_config,
10655 u64 *power_domain_mask,
10656 intel_wakeref_t *wakerefs)
10658 struct drm_device *dev = crtc->base.dev;
10659 struct drm_i915_private *dev_priv = to_i915(dev);
10660 enum intel_display_power_domain power_domain;
10661 enum transcoder cpu_transcoder;
10662 intel_wakeref_t wf;
10666 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10667 if (port == PORT_A)
10668 cpu_transcoder = TRANSCODER_DSI_A;
10670 cpu_transcoder = TRANSCODER_DSI_C;
10672 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10673 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
10675 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10679 wakerefs[power_domain] = wf;
10680 *power_domain_mask |= BIT_ULL(power_domain);
10683 * The PLL needs to be enabled with a valid divider
10684 * configuration, otherwise accessing DSI registers will hang
10685 * the machine. See BSpec North Display Engine
10686 * registers/MIPI[BXT]. We can break out here early, since we
10687 * need the same DSI PLL to be enabled for both DSI ports.
10689 if (!bxt_dsi_pll_is_enabled(dev_priv))
10692 /* XXX: this works for video mode only */
10693 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
10694 if (!(tmp & DPI_ENABLE))
10697 tmp = I915_READ(MIPI_CTRL(port));
10698 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
10701 pipe_config->cpu_transcoder = cpu_transcoder;
10705 return transcoder_is_dsi(pipe_config->cpu_transcoder);
10708 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
10709 struct intel_crtc_state *pipe_config)
10711 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10712 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
10713 struct intel_shared_dpll *pll;
10717 if (transcoder_is_dsi(cpu_transcoder)) {
10718 port = (cpu_transcoder == TRANSCODER_DSI_A) ?
10721 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
10722 if (INTEL_GEN(dev_priv) >= 12)
10723 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10725 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
10728 if (INTEL_GEN(dev_priv) >= 11)
10729 icelake_get_ddi_pll(dev_priv, port, pipe_config);
10730 else if (IS_CANNONLAKE(dev_priv))
10731 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
10732 else if (IS_GEN9_BC(dev_priv))
10733 skylake_get_ddi_pll(dev_priv, port, pipe_config);
10734 else if (IS_GEN9_LP(dev_priv))
10735 bxt_get_ddi_pll(dev_priv, port, pipe_config);
10737 haswell_get_ddi_pll(dev_priv, port, pipe_config);
10739 pll = pipe_config->shared_dpll;
10741 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
10742 &pipe_config->dpll_hw_state));
10746 * Haswell has only FDI/PCH transcoder A. It is which is connected to
10747 * DDI E. So just check whether this pipe is wired to DDI E and whether
10748 * the PCH transcoder is on.
10750 if (INTEL_GEN(dev_priv) < 9 &&
10751 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
10752 pipe_config->has_pch_encoder = true;
10754 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
10755 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10756 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10758 ironlake_get_fdi_m_n_config(crtc, pipe_config);
10762 static enum transcoder transcoder_master_readout(struct drm_i915_private *dev_priv,
10763 enum transcoder cpu_transcoder)
10765 u32 trans_port_sync, master_select;
10767 trans_port_sync = I915_READ(TRANS_DDI_FUNC_CTL2(cpu_transcoder));
10769 if ((trans_port_sync & PORT_SYNC_MODE_ENABLE) == 0)
10770 return INVALID_TRANSCODER;
10772 master_select = trans_port_sync &
10773 PORT_SYNC_MODE_MASTER_SELECT_MASK;
10774 if (master_select == 0)
10775 return TRANSCODER_EDP;
10777 return master_select - 1;
10780 static void icelake_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
10782 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
10784 enum transcoder cpu_transcoder;
10786 crtc_state->master_transcoder = transcoder_master_readout(dev_priv,
10787 crtc_state->cpu_transcoder);
10789 transcoders = BIT(TRANSCODER_A) |
10790 BIT(TRANSCODER_B) |
10791 BIT(TRANSCODER_C) |
10793 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) {
10794 enum intel_display_power_domain power_domain;
10795 intel_wakeref_t trans_wakeref;
10797 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10798 trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
10801 if (!trans_wakeref)
10804 if (transcoder_master_readout(dev_priv, cpu_transcoder) ==
10805 crtc_state->cpu_transcoder)
10806 crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder);
10808 intel_display_power_put(dev_priv, power_domain, trans_wakeref);
10811 WARN_ON(crtc_state->master_transcoder != INVALID_TRANSCODER &&
10812 crtc_state->sync_mode_slaves_mask);
10815 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
10816 struct intel_crtc_state *pipe_config)
10818 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10819 intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf;
10820 enum intel_display_power_domain power_domain;
10821 u64 power_domain_mask;
10824 pipe_config->master_transcoder = INVALID_TRANSCODER;
10826 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10827 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10831 wakerefs[power_domain] = wf;
10832 power_domain_mask = BIT_ULL(power_domain);
10834 pipe_config->shared_dpll = NULL;
10836 active = hsw_get_transcoder_state(crtc, pipe_config,
10837 &power_domain_mask, wakerefs);
10839 if (IS_GEN9_LP(dev_priv) &&
10840 bxt_get_dsi_transcoder_state(crtc, pipe_config,
10841 &power_domain_mask, wakerefs)) {
10849 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
10850 INTEL_GEN(dev_priv) >= 11) {
10851 haswell_get_ddi_port_state(crtc, pipe_config);
10852 intel_get_pipe_timings(crtc, pipe_config);
10855 intel_get_pipe_src_size(crtc, pipe_config);
10857 if (IS_HASWELL(dev_priv)) {
10858 u32 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
10860 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
10861 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10863 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10865 pipe_config->output_format =
10866 bdw_get_pipemisc_output_format(crtc);
10869 * Currently there is no interface defined to
10870 * check user preference between RGB/YCBCR444
10871 * or YCBCR420. So the only possible case for
10872 * YCBCR444 usage is driving YCBCR420 output
10873 * with LSPCON, when pipe is configured for
10874 * YCBCR444 output and LSPCON takes care of
10877 pipe_config->lspcon_downsampling =
10878 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444;
10881 pipe_config->gamma_mode = I915_READ(GAMMA_MODE(crtc->pipe));
10883 pipe_config->csc_mode = I915_READ(PIPE_CSC_MODE(crtc->pipe));
10885 if (INTEL_GEN(dev_priv) >= 9) {
10886 u32 tmp = I915_READ(SKL_BOTTOM_COLOR(crtc->pipe));
10888 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
10889 pipe_config->gamma_enable = true;
10891 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
10892 pipe_config->csc_enable = true;
10894 i9xx_get_pipe_color_config(pipe_config);
10897 intel_color_get_config(pipe_config);
10899 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
10900 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
10902 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10904 wakerefs[power_domain] = wf;
10905 power_domain_mask |= BIT_ULL(power_domain);
10907 if (INTEL_GEN(dev_priv) >= 9)
10908 skylake_get_pfit_config(crtc, pipe_config);
10910 ironlake_get_pfit_config(crtc, pipe_config);
10913 if (hsw_crtc_supports_ips(crtc)) {
10914 if (IS_HASWELL(dev_priv))
10915 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
10918 * We cannot readout IPS state on broadwell, set to
10919 * true so we can set it to a defined state on first
10922 pipe_config->ips_enabled = true;
10926 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
10927 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
10928 pipe_config->pixel_multiplier =
10929 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
10931 pipe_config->pixel_multiplier = 1;
10934 if (INTEL_GEN(dev_priv) >= 11 &&
10935 !transcoder_is_dsi(pipe_config->cpu_transcoder))
10936 icelake_get_trans_port_sync_config(pipe_config);
10939 for_each_power_domain(power_domain, power_domain_mask)
10940 intel_display_power_put(dev_priv,
10941 power_domain, wakerefs[power_domain]);
10946 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
10948 struct drm_i915_private *dev_priv =
10949 to_i915(plane_state->uapi.plane->dev);
10950 const struct drm_framebuffer *fb = plane_state->hw.fb;
10951 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
10954 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
10955 base = obj->phys_handle->busaddr;
10957 base = intel_plane_ggtt_offset(plane_state);
10959 return base + plane_state->color_plane[0].offset;
10962 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
10964 int x = plane_state->uapi.dst.x1;
10965 int y = plane_state->uapi.dst.y1;
10969 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
10972 pos |= x << CURSOR_X_SHIFT;
10975 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
10978 pos |= y << CURSOR_Y_SHIFT;
10983 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
10985 const struct drm_mode_config *config =
10986 &plane_state->uapi.plane->dev->mode_config;
10987 int width = drm_rect_width(&plane_state->uapi.dst);
10988 int height = drm_rect_height(&plane_state->uapi.dst);
10990 return width > 0 && width <= config->cursor_width &&
10991 height > 0 && height <= config->cursor_height;
10994 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
10996 struct drm_i915_private *dev_priv =
10997 to_i915(plane_state->uapi.plane->dev);
10998 unsigned int rotation = plane_state->hw.rotation;
11003 ret = intel_plane_compute_gtt(plane_state);
11007 if (!plane_state->uapi.visible)
11010 src_x = plane_state->uapi.src.x1 >> 16;
11011 src_y = plane_state->uapi.src.y1 >> 16;
11013 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
11014 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
11017 if (src_x != 0 || src_y != 0) {
11018 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
11023 * Put the final coordinates back so that the src
11024 * coordinate checks will see the right values.
11026 drm_rect_translate_to(&plane_state->uapi.src,
11027 src_x << 16, src_y << 16);
11029 /* ILK+ do this automagically in hardware */
11030 if (HAS_GMCH(dev_priv) && rotation & DRM_MODE_ROTATE_180) {
11031 const struct drm_framebuffer *fb = plane_state->hw.fb;
11032 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
11033 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
11035 offset += (src_h * src_w - 1) * fb->format->cpp[0];
11038 plane_state->color_plane[0].offset = offset;
11039 plane_state->color_plane[0].x = src_x;
11040 plane_state->color_plane[0].y = src_y;
11045 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
11046 struct intel_plane_state *plane_state)
11048 const struct drm_framebuffer *fb = plane_state->hw.fb;
11051 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
11052 DRM_DEBUG_KMS("cursor cannot be tiled\n");
11056 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
11058 DRM_PLANE_HELPER_NO_SCALING,
11059 DRM_PLANE_HELPER_NO_SCALING,
11064 /* Use the unclipped src/dst rectangles, which we program to hw */
11065 plane_state->uapi.src = drm_plane_state_src(&plane_state->uapi);
11066 plane_state->uapi.dst = drm_plane_state_dest(&plane_state->uapi);
11068 ret = intel_cursor_check_surface(plane_state);
11072 if (!plane_state->uapi.visible)
11075 ret = intel_plane_check_src_coordinates(plane_state);
11082 static unsigned int
11083 i845_cursor_max_stride(struct intel_plane *plane,
11084 u32 pixel_format, u64 modifier,
11085 unsigned int rotation)
11090 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11094 if (crtc_state->gamma_enable)
11095 cntl |= CURSOR_GAMMA_ENABLE;
11100 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
11101 const struct intel_plane_state *plane_state)
11103 return CURSOR_ENABLE |
11104 CURSOR_FORMAT_ARGB |
11105 CURSOR_STRIDE(plane_state->color_plane[0].stride);
11108 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
11110 int width = drm_rect_width(&plane_state->uapi.dst);
11113 * 845g/865g are only limited by the width of their cursors,
11114 * the height is arbitrary up to the precision of the register.
11116 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
11119 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
11120 struct intel_plane_state *plane_state)
11122 const struct drm_framebuffer *fb = plane_state->hw.fb;
11125 ret = intel_check_cursor(crtc_state, plane_state);
11129 /* if we want to turn off the cursor ignore width and height */
11133 /* Check for which cursor types we support */
11134 if (!i845_cursor_size_ok(plane_state)) {
11135 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
11136 drm_rect_width(&plane_state->uapi.dst),
11137 drm_rect_height(&plane_state->uapi.dst));
11141 WARN_ON(plane_state->uapi.visible &&
11142 plane_state->color_plane[0].stride != fb->pitches[0]);
11144 switch (fb->pitches[0]) {
11151 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
11156 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
11161 static void i845_update_cursor(struct intel_plane *plane,
11162 const struct intel_crtc_state *crtc_state,
11163 const struct intel_plane_state *plane_state)
11165 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11166 u32 cntl = 0, base = 0, pos = 0, size = 0;
11167 unsigned long irqflags;
11169 if (plane_state && plane_state->uapi.visible) {
11170 unsigned int width = drm_rect_width(&plane_state->uapi.dst);
11171 unsigned int height = drm_rect_height(&plane_state->uapi.dst);
11173 cntl = plane_state->ctl |
11174 i845_cursor_ctl_crtc(crtc_state);
11176 size = (height << 12) | width;
11178 base = intel_cursor_base(plane_state);
11179 pos = intel_cursor_position(plane_state);
11182 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11184 /* On these chipsets we can only modify the base/size/stride
11185 * whilst the cursor is disabled.
11187 if (plane->cursor.base != base ||
11188 plane->cursor.size != size ||
11189 plane->cursor.cntl != cntl) {
11190 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
11191 I915_WRITE_FW(CURBASE(PIPE_A), base);
11192 I915_WRITE_FW(CURSIZE, size);
11193 I915_WRITE_FW(CURPOS(PIPE_A), pos);
11194 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
11196 plane->cursor.base = base;
11197 plane->cursor.size = size;
11198 plane->cursor.cntl = cntl;
11200 I915_WRITE_FW(CURPOS(PIPE_A), pos);
11203 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11206 static void i845_disable_cursor(struct intel_plane *plane,
11207 const struct intel_crtc_state *crtc_state)
11209 i845_update_cursor(plane, crtc_state, NULL);
11212 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
11215 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11216 enum intel_display_power_domain power_domain;
11217 intel_wakeref_t wakeref;
11220 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
11221 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11225 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
11229 intel_display_power_put(dev_priv, power_domain, wakeref);
11234 static unsigned int
11235 i9xx_cursor_max_stride(struct intel_plane *plane,
11236 u32 pixel_format, u64 modifier,
11237 unsigned int rotation)
11239 return plane->base.dev->mode_config.cursor_width * 4;
11242 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11244 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11245 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11248 if (INTEL_GEN(dev_priv) >= 11)
11251 if (crtc_state->gamma_enable)
11252 cntl = MCURSOR_GAMMA_ENABLE;
11254 if (crtc_state->csc_enable)
11255 cntl |= MCURSOR_PIPE_CSC_ENABLE;
11257 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11258 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
11263 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
11264 const struct intel_plane_state *plane_state)
11266 struct drm_i915_private *dev_priv =
11267 to_i915(plane_state->uapi.plane->dev);
11270 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
11271 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
11273 switch (drm_rect_width(&plane_state->uapi.dst)) {
11275 cntl |= MCURSOR_MODE_64_ARGB_AX;
11278 cntl |= MCURSOR_MODE_128_ARGB_AX;
11281 cntl |= MCURSOR_MODE_256_ARGB_AX;
11284 MISSING_CASE(drm_rect_width(&plane_state->uapi.dst));
11288 if (plane_state->hw.rotation & DRM_MODE_ROTATE_180)
11289 cntl |= MCURSOR_ROTATE_180;
11294 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
11296 struct drm_i915_private *dev_priv =
11297 to_i915(plane_state->uapi.plane->dev);
11298 int width = drm_rect_width(&plane_state->uapi.dst);
11299 int height = drm_rect_height(&plane_state->uapi.dst);
11301 if (!intel_cursor_size_ok(plane_state))
11304 /* Cursor width is limited to a few power-of-two sizes */
11315 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
11316 * height from 8 lines up to the cursor width, when the
11317 * cursor is not rotated. Everything else requires square
11320 if (HAS_CUR_FBC(dev_priv) &&
11321 plane_state->hw.rotation & DRM_MODE_ROTATE_0) {
11322 if (height < 8 || height > width)
11325 if (height != width)
11332 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
11333 struct intel_plane_state *plane_state)
11335 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
11336 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11337 const struct drm_framebuffer *fb = plane_state->hw.fb;
11338 enum pipe pipe = plane->pipe;
11341 ret = intel_check_cursor(crtc_state, plane_state);
11345 /* if we want to turn off the cursor ignore width and height */
11349 /* Check for which cursor types we support */
11350 if (!i9xx_cursor_size_ok(plane_state)) {
11351 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
11352 drm_rect_width(&plane_state->uapi.dst),
11353 drm_rect_height(&plane_state->uapi.dst));
11357 WARN_ON(plane_state->uapi.visible &&
11358 plane_state->color_plane[0].stride != fb->pitches[0]);
11360 if (fb->pitches[0] !=
11361 drm_rect_width(&plane_state->uapi.dst) * fb->format->cpp[0]) {
11362 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
11364 drm_rect_width(&plane_state->uapi.dst));
11369 * There's something wrong with the cursor on CHV pipe C.
11370 * If it straddles the left edge of the screen then
11371 * moving it away from the edge or disabling it often
11372 * results in a pipe underrun, and often that can lead to
11373 * dead pipe (constant underrun reported, and it scans
11374 * out just a solid color). To recover from that, the
11375 * display power well must be turned off and on again.
11376 * Refuse the put the cursor into that compromised position.
11378 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
11379 plane_state->uapi.visible && plane_state->uapi.dst.x1 < 0) {
11380 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
11384 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
11389 static void i9xx_update_cursor(struct intel_plane *plane,
11390 const struct intel_crtc_state *crtc_state,
11391 const struct intel_plane_state *plane_state)
11393 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11394 enum pipe pipe = plane->pipe;
11395 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
11396 unsigned long irqflags;
11398 if (plane_state && plane_state->uapi.visible) {
11399 unsigned width = drm_rect_width(&plane_state->uapi.dst);
11400 unsigned height = drm_rect_height(&plane_state->uapi.dst);
11402 cntl = plane_state->ctl |
11403 i9xx_cursor_ctl_crtc(crtc_state);
11405 if (width != height)
11406 fbc_ctl = CUR_FBC_CTL_EN | (height - 1);
11408 base = intel_cursor_base(plane_state);
11409 pos = intel_cursor_position(plane_state);
11412 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11415 * On some platforms writing CURCNTR first will also
11416 * cause CURPOS to be armed by the CURBASE write.
11417 * Without the CURCNTR write the CURPOS write would
11418 * arm itself. Thus we always update CURCNTR before
11421 * On other platforms CURPOS always requires the
11422 * CURBASE write to arm the update. Additonally
11423 * a write to any of the cursor register will cancel
11424 * an already armed cursor update. Thus leaving out
11425 * the CURBASE write after CURPOS could lead to a
11426 * cursor that doesn't appear to move, or even change
11427 * shape. Thus we always write CURBASE.
11429 * The other registers are armed by by the CURBASE write
11430 * except when the plane is getting enabled at which time
11431 * the CURCNTR write arms the update.
11434 if (INTEL_GEN(dev_priv) >= 9)
11435 skl_write_cursor_wm(plane, crtc_state);
11437 if (plane->cursor.base != base ||
11438 plane->cursor.size != fbc_ctl ||
11439 plane->cursor.cntl != cntl) {
11440 if (HAS_CUR_FBC(dev_priv))
11441 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
11442 I915_WRITE_FW(CURCNTR(pipe), cntl);
11443 I915_WRITE_FW(CURPOS(pipe), pos);
11444 I915_WRITE_FW(CURBASE(pipe), base);
11446 plane->cursor.base = base;
11447 plane->cursor.size = fbc_ctl;
11448 plane->cursor.cntl = cntl;
11450 I915_WRITE_FW(CURPOS(pipe), pos);
11451 I915_WRITE_FW(CURBASE(pipe), base);
11454 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11457 static void i9xx_disable_cursor(struct intel_plane *plane,
11458 const struct intel_crtc_state *crtc_state)
11460 i9xx_update_cursor(plane, crtc_state, NULL);
11463 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
11466 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11467 enum intel_display_power_domain power_domain;
11468 intel_wakeref_t wakeref;
11473 * Not 100% correct for planes that can move between pipes,
11474 * but that's only the case for gen2-3 which don't have any
11475 * display power wells.
11477 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
11478 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11482 val = I915_READ(CURCNTR(plane->pipe));
11484 ret = val & MCURSOR_MODE;
11486 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
11487 *pipe = plane->pipe;
11489 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
11490 MCURSOR_PIPE_SELECT_SHIFT;
11492 intel_display_power_put(dev_priv, power_domain, wakeref);
11497 /* VESA 640x480x72Hz mode to set on the pipe */
11498 static const struct drm_display_mode load_detect_mode = {
11499 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
11500 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
11503 struct drm_framebuffer *
11504 intel_framebuffer_create(struct drm_i915_gem_object *obj,
11505 struct drm_mode_fb_cmd2 *mode_cmd)
11507 struct intel_framebuffer *intel_fb;
11510 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
11512 return ERR_PTR(-ENOMEM);
11514 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
11518 return &intel_fb->base;
11522 return ERR_PTR(ret);
11525 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
11526 struct drm_crtc *crtc)
11528 struct drm_plane *plane;
11529 struct drm_plane_state *plane_state;
11532 ret = drm_atomic_add_affected_planes(state, crtc);
11536 for_each_new_plane_in_state(state, plane, plane_state, i) {
11537 if (plane_state->crtc != crtc)
11540 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
11544 drm_atomic_set_fb_for_plane(plane_state, NULL);
11550 int intel_get_load_detect_pipe(struct drm_connector *connector,
11551 struct intel_load_detect_pipe *old,
11552 struct drm_modeset_acquire_ctx *ctx)
11554 struct intel_crtc *intel_crtc;
11555 struct intel_encoder *intel_encoder =
11556 intel_attached_encoder(connector);
11557 struct drm_crtc *possible_crtc;
11558 struct drm_encoder *encoder = &intel_encoder->base;
11559 struct drm_crtc *crtc = NULL;
11560 struct drm_device *dev = encoder->dev;
11561 struct drm_i915_private *dev_priv = to_i915(dev);
11562 struct drm_mode_config *config = &dev->mode_config;
11563 struct drm_atomic_state *state = NULL, *restore_state = NULL;
11564 struct drm_connector_state *connector_state;
11565 struct intel_crtc_state *crtc_state;
11568 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11569 connector->base.id, connector->name,
11570 encoder->base.id, encoder->name);
11572 old->restore_state = NULL;
11574 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
11577 * Algorithm gets a little messy:
11579 * - if the connector already has an assigned crtc, use it (but make
11580 * sure it's on first)
11582 * - try to find the first unused crtc that can drive this connector,
11583 * and use that if we find one
11586 /* See if we already have a CRTC for this connector */
11587 if (connector->state->crtc) {
11588 crtc = connector->state->crtc;
11590 ret = drm_modeset_lock(&crtc->mutex, ctx);
11594 /* Make sure the crtc and connector are running */
11598 /* Find an unused one (if possible) */
11599 for_each_crtc(dev, possible_crtc) {
11601 if (!(encoder->possible_crtcs & (1 << i)))
11604 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
11608 if (possible_crtc->state->enable) {
11609 drm_modeset_unlock(&possible_crtc->mutex);
11613 crtc = possible_crtc;
11618 * If we didn't find an unused CRTC, don't use any.
11621 DRM_DEBUG_KMS("no pipe available for load-detect\n");
11627 intel_crtc = to_intel_crtc(crtc);
11629 state = drm_atomic_state_alloc(dev);
11630 restore_state = drm_atomic_state_alloc(dev);
11631 if (!state || !restore_state) {
11636 state->acquire_ctx = ctx;
11637 restore_state->acquire_ctx = ctx;
11639 connector_state = drm_atomic_get_connector_state(state, connector);
11640 if (IS_ERR(connector_state)) {
11641 ret = PTR_ERR(connector_state);
11645 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
11649 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
11650 if (IS_ERR(crtc_state)) {
11651 ret = PTR_ERR(crtc_state);
11655 crtc_state->uapi.active = true;
11657 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
11658 &load_detect_mode);
11662 ret = intel_modeset_disable_planes(state, crtc);
11666 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
11668 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
11670 ret = drm_atomic_add_affected_planes(restore_state, crtc);
11672 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
11676 ret = drm_atomic_commit(state);
11678 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
11682 old->restore_state = restore_state;
11683 drm_atomic_state_put(state);
11685 /* let the connector get through one full cycle before testing */
11686 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
11691 drm_atomic_state_put(state);
11694 if (restore_state) {
11695 drm_atomic_state_put(restore_state);
11696 restore_state = NULL;
11699 if (ret == -EDEADLK)
11705 void intel_release_load_detect_pipe(struct drm_connector *connector,
11706 struct intel_load_detect_pipe *old,
11707 struct drm_modeset_acquire_ctx *ctx)
11709 struct intel_encoder *intel_encoder =
11710 intel_attached_encoder(connector);
11711 struct drm_encoder *encoder = &intel_encoder->base;
11712 struct drm_atomic_state *state = old->restore_state;
11715 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11716 connector->base.id, connector->name,
11717 encoder->base.id, encoder->name);
11722 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
11724 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
11725 drm_atomic_state_put(state);
11728 static int i9xx_pll_refclk(struct drm_device *dev,
11729 const struct intel_crtc_state *pipe_config)
11731 struct drm_i915_private *dev_priv = to_i915(dev);
11732 u32 dpll = pipe_config->dpll_hw_state.dpll;
11734 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
11735 return dev_priv->vbt.lvds_ssc_freq;
11736 else if (HAS_PCH_SPLIT(dev_priv))
11738 else if (!IS_GEN(dev_priv, 2))
11744 /* Returns the clock of the currently programmed mode of the given pipe. */
11745 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
11746 struct intel_crtc_state *pipe_config)
11748 struct drm_device *dev = crtc->base.dev;
11749 struct drm_i915_private *dev_priv = to_i915(dev);
11750 enum pipe pipe = crtc->pipe;
11751 u32 dpll = pipe_config->dpll_hw_state.dpll;
11755 int refclk = i9xx_pll_refclk(dev, pipe_config);
11757 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
11758 fp = pipe_config->dpll_hw_state.fp0;
11760 fp = pipe_config->dpll_hw_state.fp1;
11762 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
11763 if (IS_PINEVIEW(dev_priv)) {
11764 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
11765 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
11767 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
11768 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
11771 if (!IS_GEN(dev_priv, 2)) {
11772 if (IS_PINEVIEW(dev_priv))
11773 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
11774 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
11776 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
11777 DPLL_FPA01_P1_POST_DIV_SHIFT);
11779 switch (dpll & DPLL_MODE_MASK) {
11780 case DPLLB_MODE_DAC_SERIAL:
11781 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
11784 case DPLLB_MODE_LVDS:
11785 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
11789 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
11790 "mode\n", (int)(dpll & DPLL_MODE_MASK));
11794 if (IS_PINEVIEW(dev_priv))
11795 port_clock = pnv_calc_dpll_params(refclk, &clock);
11797 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11799 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
11800 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
11803 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
11804 DPLL_FPA01_P1_POST_DIV_SHIFT);
11806 if (lvds & LVDS_CLKB_POWER_UP)
11811 if (dpll & PLL_P1_DIVIDE_BY_TWO)
11814 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
11815 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
11817 if (dpll & PLL_P2_DIVIDE_BY_4)
11823 port_clock = i9xx_calc_dpll_params(refclk, &clock);
11827 * This value includes pixel_multiplier. We will use
11828 * port_clock to compute adjusted_mode.crtc_clock in the
11829 * encoder's get_config() function.
11831 pipe_config->port_clock = port_clock;
11834 int intel_dotclock_calculate(int link_freq,
11835 const struct intel_link_m_n *m_n)
11838 * The calculation for the data clock is:
11839 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
11840 * But we want to avoid losing precison if possible, so:
11841 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
11843 * and the link clock is simpler:
11844 * link_clock = (m * link_clock) / n
11850 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
11853 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
11854 struct intel_crtc_state *pipe_config)
11856 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11858 /* read out port_clock from the DPLL */
11859 i9xx_crtc_clock_get(crtc, pipe_config);
11862 * In case there is an active pipe without active ports,
11863 * we may need some idea for the dotclock anyway.
11864 * Calculate one based on the FDI configuration.
11866 pipe_config->hw.adjusted_mode.crtc_clock =
11867 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11868 &pipe_config->fdi_m_n);
11871 static void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
11872 struct intel_crtc *crtc)
11874 memset(crtc_state, 0, sizeof(*crtc_state));
11876 __drm_atomic_helper_crtc_state_reset(&crtc_state->uapi, &crtc->base);
11878 crtc_state->cpu_transcoder = INVALID_TRANSCODER;
11879 crtc_state->master_transcoder = INVALID_TRANSCODER;
11880 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
11881 crtc_state->output_format = INTEL_OUTPUT_FORMAT_INVALID;
11882 crtc_state->scaler_state.scaler_id = -1;
11885 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc)
11887 struct intel_crtc_state *crtc_state;
11889 crtc_state = kmalloc(sizeof(*crtc_state), GFP_KERNEL);
11892 intel_crtc_state_reset(crtc_state, crtc);
11897 /* Returns the currently programmed mode of the given encoder. */
11898 struct drm_display_mode *
11899 intel_encoder_current_mode(struct intel_encoder *encoder)
11901 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
11902 struct intel_crtc_state *crtc_state;
11903 struct drm_display_mode *mode;
11904 struct intel_crtc *crtc;
11907 if (!encoder->get_hw_state(encoder, &pipe))
11910 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11912 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
11916 crtc_state = intel_crtc_state_alloc(crtc);
11922 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
11928 encoder->get_config(encoder, crtc_state);
11930 intel_mode_from_pipe_config(mode, crtc_state);
11937 static void intel_crtc_destroy(struct drm_crtc *crtc)
11939 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11941 drm_crtc_cleanup(crtc);
11946 * intel_wm_need_update - Check whether watermarks need updating
11947 * @cur: current plane state
11948 * @new: new plane state
11950 * Check current plane state versus the new one to determine whether
11951 * watermarks need to be recalculated.
11953 * Returns true or false.
11955 static bool intel_wm_need_update(const struct intel_plane_state *cur,
11956 struct intel_plane_state *new)
11958 /* Update watermarks on tiling or size changes. */
11959 if (new->uapi.visible != cur->uapi.visible)
11962 if (!cur->hw.fb || !new->hw.fb)
11965 if (cur->hw.fb->modifier != new->hw.fb->modifier ||
11966 cur->hw.rotation != new->hw.rotation ||
11967 drm_rect_width(&new->uapi.src) != drm_rect_width(&cur->uapi.src) ||
11968 drm_rect_height(&new->uapi.src) != drm_rect_height(&cur->uapi.src) ||
11969 drm_rect_width(&new->uapi.dst) != drm_rect_width(&cur->uapi.dst) ||
11970 drm_rect_height(&new->uapi.dst) != drm_rect_height(&cur->uapi.dst))
11976 static bool needs_scaling(const struct intel_plane_state *state)
11978 int src_w = drm_rect_width(&state->uapi.src) >> 16;
11979 int src_h = drm_rect_height(&state->uapi.src) >> 16;
11980 int dst_w = drm_rect_width(&state->uapi.dst);
11981 int dst_h = drm_rect_height(&state->uapi.dst);
11983 return (src_w != dst_w || src_h != dst_h);
11986 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
11987 struct intel_crtc_state *crtc_state,
11988 const struct intel_plane_state *old_plane_state,
11989 struct intel_plane_state *plane_state)
11991 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11992 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
11993 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11994 bool mode_changed = needs_modeset(crtc_state);
11995 bool was_crtc_enabled = old_crtc_state->hw.active;
11996 bool is_crtc_enabled = crtc_state->hw.active;
11997 bool turn_off, turn_on, visible, was_visible;
12000 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
12001 ret = skl_update_scaler_plane(crtc_state, plane_state);
12006 was_visible = old_plane_state->uapi.visible;
12007 visible = plane_state->uapi.visible;
12009 if (!was_crtc_enabled && WARN_ON(was_visible))
12010 was_visible = false;
12013 * Visibility is calculated as if the crtc was on, but
12014 * after scaler setup everything depends on it being off
12015 * when the crtc isn't active.
12017 * FIXME this is wrong for watermarks. Watermarks should also
12018 * be computed as if the pipe would be active. Perhaps move
12019 * per-plane wm computation to the .check_plane() hook, and
12020 * only combine the results from all planes in the current place?
12022 if (!is_crtc_enabled) {
12023 plane_state->uapi.visible = visible = false;
12024 crtc_state->active_planes &= ~BIT(plane->id);
12025 crtc_state->data_rate[plane->id] = 0;
12026 crtc_state->min_cdclk[plane->id] = 0;
12029 if (!was_visible && !visible)
12032 turn_off = was_visible && (!visible || mode_changed);
12033 turn_on = visible && (!was_visible || mode_changed);
12035 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
12036 crtc->base.base.id, crtc->base.name,
12037 plane->base.base.id, plane->base.name,
12038 was_visible, visible,
12039 turn_off, turn_on, mode_changed);
12042 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
12043 crtc_state->update_wm_pre = true;
12045 /* must disable cxsr around plane enable/disable */
12046 if (plane->id != PLANE_CURSOR)
12047 crtc_state->disable_cxsr = true;
12048 } else if (turn_off) {
12049 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
12050 crtc_state->update_wm_post = true;
12052 /* must disable cxsr around plane enable/disable */
12053 if (plane->id != PLANE_CURSOR)
12054 crtc_state->disable_cxsr = true;
12055 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
12056 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
12057 /* FIXME bollocks */
12058 crtc_state->update_wm_pre = true;
12059 crtc_state->update_wm_post = true;
12063 if (visible || was_visible)
12064 crtc_state->fb_bits |= plane->frontbuffer_bit;
12067 * ILK/SNB DVSACNTR/Sprite Enable
12068 * IVB SPR_CTL/Sprite Enable
12069 * "When in Self Refresh Big FIFO mode, a write to enable the
12070 * plane will be internally buffered and delayed while Big FIFO
12071 * mode is exiting."
12073 * Which means that enabling the sprite can take an extra frame
12074 * when we start in big FIFO mode (LP1+). Thus we need to drop
12075 * down to LP0 and wait for vblank in order to make sure the
12076 * sprite gets enabled on the next vblank after the register write.
12077 * Doing otherwise would risk enabling the sprite one frame after
12078 * we've already signalled flip completion. We can resume LP1+
12079 * once the sprite has been enabled.
12082 * WaCxSRDisabledForSpriteScaling:ivb
12083 * IVB SPR_SCALE/Scaling Enable
12084 * "Low Power watermarks must be disabled for at least one
12085 * frame before enabling sprite scaling, and kept disabled
12086 * until sprite scaling is disabled."
12088 * ILK/SNB DVSASCALE/Scaling Enable
12089 * "When in Self Refresh Big FIFO mode, scaling enable will be
12090 * masked off while Big FIFO mode is exiting."
12092 * Despite the w/a only being listed for IVB we assume that
12093 * the ILK/SNB note has similar ramifications, hence we apply
12094 * the w/a on all three platforms.
12096 * With experimental results seems this is needed also for primary
12097 * plane, not only sprite plane.
12099 if (plane->id != PLANE_CURSOR &&
12100 (IS_GEN_RANGE(dev_priv, 5, 6) ||
12101 IS_IVYBRIDGE(dev_priv)) &&
12102 (turn_on || (!needs_scaling(old_plane_state) &&
12103 needs_scaling(plane_state))))
12104 crtc_state->disable_lp_wm = true;
12109 static bool encoders_cloneable(const struct intel_encoder *a,
12110 const struct intel_encoder *b)
12112 /* masks could be asymmetric, so check both ways */
12113 return a == b || (a->cloneable & (1 << b->type) &&
12114 b->cloneable & (1 << a->type));
12117 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
12118 struct intel_crtc *crtc,
12119 struct intel_encoder *encoder)
12121 struct intel_encoder *source_encoder;
12122 struct drm_connector *connector;
12123 struct drm_connector_state *connector_state;
12126 for_each_new_connector_in_state(state, connector, connector_state, i) {
12127 if (connector_state->crtc != &crtc->base)
12131 to_intel_encoder(connector_state->best_encoder);
12132 if (!encoders_cloneable(encoder, source_encoder))
12139 static int icl_add_linked_planes(struct intel_atomic_state *state)
12141 struct intel_plane *plane, *linked;
12142 struct intel_plane_state *plane_state, *linked_plane_state;
12145 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12146 linked = plane_state->planar_linked_plane;
12151 linked_plane_state = intel_atomic_get_plane_state(state, linked);
12152 if (IS_ERR(linked_plane_state))
12153 return PTR_ERR(linked_plane_state);
12155 WARN_ON(linked_plane_state->planar_linked_plane != plane);
12156 WARN_ON(linked_plane_state->planar_slave == plane_state->planar_slave);
12162 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
12164 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12165 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12166 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
12167 struct intel_plane *plane, *linked;
12168 struct intel_plane_state *plane_state;
12171 if (INTEL_GEN(dev_priv) < 11)
12175 * Destroy all old plane links and make the slave plane invisible
12176 * in the crtc_state->active_planes mask.
12178 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12179 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
12182 plane_state->planar_linked_plane = NULL;
12183 if (plane_state->planar_slave && !plane_state->uapi.visible) {
12184 crtc_state->active_planes &= ~BIT(plane->id);
12185 crtc_state->update_planes |= BIT(plane->id);
12188 plane_state->planar_slave = false;
12191 if (!crtc_state->nv12_planes)
12194 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12195 struct intel_plane_state *linked_state = NULL;
12197 if (plane->pipe != crtc->pipe ||
12198 !(crtc_state->nv12_planes & BIT(plane->id)))
12201 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
12202 if (!icl_is_nv12_y_plane(linked->id))
12205 if (crtc_state->active_planes & BIT(linked->id))
12208 linked_state = intel_atomic_get_plane_state(state, linked);
12209 if (IS_ERR(linked_state))
12210 return PTR_ERR(linked_state);
12215 if (!linked_state) {
12216 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
12217 hweight8(crtc_state->nv12_planes));
12222 plane_state->planar_linked_plane = linked;
12224 linked_state->planar_slave = true;
12225 linked_state->planar_linked_plane = plane;
12226 crtc_state->active_planes |= BIT(linked->id);
12227 crtc_state->update_planes |= BIT(linked->id);
12228 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
12230 /* Copy parameters to slave plane */
12231 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
12232 linked_state->color_ctl = plane_state->color_ctl;
12233 memcpy(linked_state->color_plane, plane_state->color_plane,
12234 sizeof(linked_state->color_plane));
12236 intel_plane_copy_uapi_to_hw_state(linked_state, plane_state);
12237 linked_state->uapi.src = plane_state->uapi.src;
12238 linked_state->uapi.dst = plane_state->uapi.dst;
12240 if (icl_is_hdr_plane(dev_priv, plane->id)) {
12241 if (linked->id == PLANE_SPRITE5)
12242 plane_state->cus_ctl |= PLANE_CUS_PLANE_7;
12243 else if (linked->id == PLANE_SPRITE4)
12244 plane_state->cus_ctl |= PLANE_CUS_PLANE_6;
12246 MISSING_CASE(linked->id);
12253 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
12255 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
12256 struct intel_atomic_state *state =
12257 to_intel_atomic_state(new_crtc_state->uapi.state);
12258 const struct intel_crtc_state *old_crtc_state =
12259 intel_atomic_get_old_crtc_state(state, crtc);
12261 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
12264 static int icl_add_sync_mode_crtcs(struct intel_crtc_state *crtc_state)
12266 struct drm_crtc *crtc = crtc_state->uapi.crtc;
12267 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
12268 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
12269 struct drm_connector *master_connector, *connector;
12270 struct drm_connector_state *connector_state;
12271 struct drm_connector_list_iter conn_iter;
12272 struct drm_crtc *master_crtc = NULL;
12273 struct drm_crtc_state *master_crtc_state;
12274 struct intel_crtc_state *master_pipe_config;
12275 int i, tile_group_id;
12277 if (INTEL_GEN(dev_priv) < 11)
12281 * In case of tiled displays there could be one or more slaves but there is
12282 * only one master. Lets make the CRTC used by the connector corresponding
12283 * to the last horizonal and last vertical tile a master/genlock CRTC.
12284 * All the other CRTCs corresponding to other tiles of the same Tile group
12285 * are the slave CRTCs and hold a pointer to their genlock CRTC.
12287 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
12288 if (connector_state->crtc != crtc)
12290 if (!connector->has_tile)
12292 if (crtc_state->hw.mode.hdisplay != connector->tile_h_size ||
12293 crtc_state->hw.mode.vdisplay != connector->tile_v_size)
12295 if (connector->tile_h_loc == connector->num_h_tile - 1 &&
12296 connector->tile_v_loc == connector->num_v_tile - 1)
12298 crtc_state->sync_mode_slaves_mask = 0;
12299 tile_group_id = connector->tile_group->id;
12300 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
12301 drm_for_each_connector_iter(master_connector, &conn_iter) {
12302 struct drm_connector_state *master_conn_state = NULL;
12304 if (!master_connector->has_tile)
12306 if (master_connector->tile_h_loc != master_connector->num_h_tile - 1 ||
12307 master_connector->tile_v_loc != master_connector->num_v_tile - 1)
12309 if (master_connector->tile_group->id != tile_group_id)
12312 master_conn_state = drm_atomic_get_connector_state(&state->base,
12314 if (IS_ERR(master_conn_state)) {
12315 drm_connector_list_iter_end(&conn_iter);
12316 return PTR_ERR(master_conn_state);
12318 if (master_conn_state->crtc) {
12319 master_crtc = master_conn_state->crtc;
12323 drm_connector_list_iter_end(&conn_iter);
12325 if (!master_crtc) {
12326 DRM_DEBUG_KMS("Could not find Master CRTC for Slave CRTC %d\n",
12327 connector_state->crtc->base.id);
12331 master_crtc_state = drm_atomic_get_crtc_state(&state->base,
12333 if (IS_ERR(master_crtc_state))
12334 return PTR_ERR(master_crtc_state);
12336 master_pipe_config = to_intel_crtc_state(master_crtc_state);
12337 crtc_state->master_transcoder = master_pipe_config->cpu_transcoder;
12338 master_pipe_config->sync_mode_slaves_mask |=
12339 BIT(crtc_state->cpu_transcoder);
12340 DRM_DEBUG_KMS("Master Transcoder = %s added for Slave CRTC = %d, slave transcoder bitmask = %d\n",
12341 transcoder_name(crtc_state->master_transcoder),
12342 crtc_state->uapi.crtc->base.id,
12343 master_pipe_config->sync_mode_slaves_mask);
12349 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
12350 struct intel_crtc *crtc)
12352 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12353 struct intel_crtc_state *crtc_state =
12354 intel_atomic_get_new_crtc_state(state, crtc);
12355 bool mode_changed = needs_modeset(crtc_state);
12358 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
12359 mode_changed && !crtc_state->hw.active)
12360 crtc_state->update_wm_post = true;
12362 if (mode_changed && crtc_state->hw.enable &&
12363 dev_priv->display.crtc_compute_clock &&
12364 !WARN_ON(crtc_state->shared_dpll)) {
12365 ret = dev_priv->display.crtc_compute_clock(crtc, crtc_state);
12371 * May need to update pipe gamma enable bits
12372 * when C8 planes are getting enabled/disabled.
12374 if (c8_planes_changed(crtc_state))
12375 crtc_state->uapi.color_mgmt_changed = true;
12377 if (mode_changed || crtc_state->update_pipe ||
12378 crtc_state->uapi.color_mgmt_changed) {
12379 ret = intel_color_check(crtc_state);
12385 if (dev_priv->display.compute_pipe_wm) {
12386 ret = dev_priv->display.compute_pipe_wm(crtc_state);
12388 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
12393 if (dev_priv->display.compute_intermediate_wm) {
12394 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
12398 * Calculate 'intermediate' watermarks that satisfy both the
12399 * old state and the new state. We can program these
12402 ret = dev_priv->display.compute_intermediate_wm(crtc_state);
12404 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
12409 if (INTEL_GEN(dev_priv) >= 9) {
12410 if (mode_changed || crtc_state->update_pipe)
12411 ret = skl_update_scaler_crtc(crtc_state);
12413 ret = intel_atomic_setup_scalers(dev_priv, crtc,
12417 if (HAS_IPS(dev_priv))
12418 crtc_state->ips_enabled = hsw_compute_ips_config(crtc_state);
12423 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
12425 struct intel_connector *connector;
12426 struct drm_connector_list_iter conn_iter;
12428 drm_connector_list_iter_begin(dev, &conn_iter);
12429 for_each_intel_connector_iter(connector, &conn_iter) {
12430 if (connector->base.state->crtc)
12431 drm_connector_put(&connector->base);
12433 if (connector->base.encoder) {
12434 connector->base.state->best_encoder =
12435 connector->base.encoder;
12436 connector->base.state->crtc =
12437 connector->base.encoder->crtc;
12439 drm_connector_get(&connector->base);
12441 connector->base.state->best_encoder = NULL;
12442 connector->base.state->crtc = NULL;
12445 drm_connector_list_iter_end(&conn_iter);
12449 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
12450 struct intel_crtc_state *pipe_config)
12452 struct drm_connector *connector = conn_state->connector;
12453 const struct drm_display_info *info = &connector->display_info;
12456 switch (conn_state->max_bpc) {
12473 if (bpp < pipe_config->pipe_bpp) {
12474 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
12475 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
12476 connector->base.id, connector->name,
12477 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
12478 pipe_config->pipe_bpp);
12480 pipe_config->pipe_bpp = bpp;
12487 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
12488 struct intel_crtc_state *pipe_config)
12490 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12491 struct drm_atomic_state *state = pipe_config->uapi.state;
12492 struct drm_connector *connector;
12493 struct drm_connector_state *connector_state;
12496 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
12497 IS_CHERRYVIEW(dev_priv)))
12499 else if (INTEL_GEN(dev_priv) >= 5)
12504 pipe_config->pipe_bpp = bpp;
12506 /* Clamp display bpp to connector max bpp */
12507 for_each_new_connector_in_state(state, connector, connector_state, i) {
12510 if (connector_state->crtc != &crtc->base)
12513 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
12521 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
12523 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
12524 "type: 0x%x flags: 0x%x\n",
12526 mode->crtc_hdisplay, mode->crtc_hsync_start,
12527 mode->crtc_hsync_end, mode->crtc_htotal,
12528 mode->crtc_vdisplay, mode->crtc_vsync_start,
12529 mode->crtc_vsync_end, mode->crtc_vtotal,
12530 mode->type, mode->flags);
12534 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
12535 const char *id, unsigned int lane_count,
12536 const struct intel_link_m_n *m_n)
12538 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12540 m_n->gmch_m, m_n->gmch_n,
12541 m_n->link_m, m_n->link_n, m_n->tu);
12545 intel_dump_infoframe(struct drm_i915_private *dev_priv,
12546 const union hdmi_infoframe *frame)
12548 if ((drm_debug & DRM_UT_KMS) == 0)
12551 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
12554 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
12556 static const char * const output_type_str[] = {
12557 OUTPUT_TYPE(UNUSED),
12558 OUTPUT_TYPE(ANALOG),
12562 OUTPUT_TYPE(TVOUT),
12568 OUTPUT_TYPE(DP_MST),
12573 static void snprintf_output_types(char *buf, size_t len,
12574 unsigned int output_types)
12581 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
12584 if ((output_types & BIT(i)) == 0)
12587 r = snprintf(str, len, "%s%s",
12588 str != buf ? "," : "", output_type_str[i]);
12594 output_types &= ~BIT(i);
12597 WARN_ON_ONCE(output_types != 0);
12600 static const char * const output_format_str[] = {
12601 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
12602 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
12603 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
12604 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
12607 static const char *output_formats(enum intel_output_format format)
12609 if (format >= ARRAY_SIZE(output_format_str))
12610 format = INTEL_OUTPUT_FORMAT_INVALID;
12611 return output_format_str[format];
12614 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
12616 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
12617 const struct drm_framebuffer *fb = plane_state->hw.fb;
12618 struct drm_format_name_buf format_name;
12621 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12622 plane->base.base.id, plane->base.name,
12623 yesno(plane_state->uapi.visible));
12627 DRM_DEBUG_KMS("[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s, visible: %s\n",
12628 plane->base.base.id, plane->base.name,
12629 fb->base.id, fb->width, fb->height,
12630 drm_get_format_name(fb->format->format, &format_name),
12631 yesno(plane_state->uapi.visible));
12632 DRM_DEBUG_KMS("\trotation: 0x%x, scaler: %d\n",
12633 plane_state->hw.rotation, plane_state->scaler_id);
12634 if (plane_state->uapi.visible)
12635 DRM_DEBUG_KMS("\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
12636 DRM_RECT_FP_ARG(&plane_state->uapi.src),
12637 DRM_RECT_ARG(&plane_state->uapi.dst));
12640 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
12641 struct intel_atomic_state *state,
12642 const char *context)
12644 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
12645 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12646 const struct intel_plane_state *plane_state;
12647 struct intel_plane *plane;
12651 DRM_DEBUG_KMS("[CRTC:%d:%s] enable: %s %s\n",
12652 crtc->base.base.id, crtc->base.name,
12653 yesno(pipe_config->hw.enable), context);
12655 if (!pipe_config->hw.enable)
12658 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
12659 DRM_DEBUG_KMS("active: %s, output_types: %s (0x%x), output format: %s\n",
12660 yesno(pipe_config->hw.active),
12661 buf, pipe_config->output_types,
12662 output_formats(pipe_config->output_format));
12664 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
12665 transcoder_name(pipe_config->cpu_transcoder),
12666 pipe_config->pipe_bpp, pipe_config->dither);
12668 if (pipe_config->has_pch_encoder)
12669 intel_dump_m_n_config(pipe_config, "fdi",
12670 pipe_config->fdi_lanes,
12671 &pipe_config->fdi_m_n);
12673 if (intel_crtc_has_dp_encoder(pipe_config)) {
12674 intel_dump_m_n_config(pipe_config, "dp m_n",
12675 pipe_config->lane_count, &pipe_config->dp_m_n);
12676 if (pipe_config->has_drrs)
12677 intel_dump_m_n_config(pipe_config, "dp m2_n2",
12678 pipe_config->lane_count,
12679 &pipe_config->dp_m2_n2);
12682 DRM_DEBUG_KMS("audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
12683 pipe_config->has_audio, pipe_config->has_infoframe,
12684 pipe_config->infoframes.enable);
12686 if (pipe_config->infoframes.enable &
12687 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
12688 DRM_DEBUG_KMS("GCP: 0x%x\n", pipe_config->infoframes.gcp);
12689 if (pipe_config->infoframes.enable &
12690 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
12691 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
12692 if (pipe_config->infoframes.enable &
12693 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
12694 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
12695 if (pipe_config->infoframes.enable &
12696 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
12697 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
12699 DRM_DEBUG_KMS("requested mode:\n");
12700 drm_mode_debug_printmodeline(&pipe_config->hw.mode);
12701 DRM_DEBUG_KMS("adjusted mode:\n");
12702 drm_mode_debug_printmodeline(&pipe_config->hw.adjusted_mode);
12703 intel_dump_crtc_timings(&pipe_config->hw.adjusted_mode);
12704 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
12705 pipe_config->port_clock,
12706 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
12707 pipe_config->pixel_rate);
12709 if (INTEL_GEN(dev_priv) >= 9)
12710 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
12712 pipe_config->scaler_state.scaler_users,
12713 pipe_config->scaler_state.scaler_id);
12715 if (HAS_GMCH(dev_priv))
12716 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
12717 pipe_config->gmch_pfit.control,
12718 pipe_config->gmch_pfit.pgm_ratios,
12719 pipe_config->gmch_pfit.lvds_border_bits);
12721 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s, force thru: %s\n",
12722 pipe_config->pch_pfit.pos,
12723 pipe_config->pch_pfit.size,
12724 enableddisabled(pipe_config->pch_pfit.enabled),
12725 yesno(pipe_config->pch_pfit.force_thru));
12727 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
12728 pipe_config->ips_enabled, pipe_config->double_wide);
12730 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
12732 if (IS_CHERRYVIEW(dev_priv))
12733 DRM_DEBUG_KMS("cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12734 pipe_config->cgm_mode, pipe_config->gamma_mode,
12735 pipe_config->gamma_enable, pipe_config->csc_enable);
12737 DRM_DEBUG_KMS("csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
12738 pipe_config->csc_mode, pipe_config->gamma_mode,
12739 pipe_config->gamma_enable, pipe_config->csc_enable);
12745 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12746 if (plane->pipe == crtc->pipe)
12747 intel_dump_plane_state(plane_state);
12751 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
12753 struct drm_device *dev = state->base.dev;
12754 struct drm_connector *connector;
12755 struct drm_connector_list_iter conn_iter;
12756 unsigned int used_ports = 0;
12757 unsigned int used_mst_ports = 0;
12761 * We're going to peek into connector->state,
12762 * hence connection_mutex must be held.
12764 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
12767 * Walk the connector list instead of the encoder
12768 * list to detect the problem on ddi platforms
12769 * where there's just one encoder per digital port.
12771 drm_connector_list_iter_begin(dev, &conn_iter);
12772 drm_for_each_connector_iter(connector, &conn_iter) {
12773 struct drm_connector_state *connector_state;
12774 struct intel_encoder *encoder;
12777 drm_atomic_get_new_connector_state(&state->base,
12779 if (!connector_state)
12780 connector_state = connector->state;
12782 if (!connector_state->best_encoder)
12785 encoder = to_intel_encoder(connector_state->best_encoder);
12787 WARN_ON(!connector_state->crtc);
12789 switch (encoder->type) {
12790 unsigned int port_mask;
12791 case INTEL_OUTPUT_DDI:
12792 if (WARN_ON(!HAS_DDI(to_i915(dev))))
12794 /* else, fall through */
12795 case INTEL_OUTPUT_DP:
12796 case INTEL_OUTPUT_HDMI:
12797 case INTEL_OUTPUT_EDP:
12798 port_mask = 1 << encoder->port;
12800 /* the same port mustn't appear more than once */
12801 if (used_ports & port_mask)
12804 used_ports |= port_mask;
12806 case INTEL_OUTPUT_DP_MST:
12808 1 << encoder->port;
12814 drm_connector_list_iter_end(&conn_iter);
12816 /* can't mix MST and SST/HDMI on the same port */
12817 if (used_ports & used_mst_ports)
12824 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_crtc_state *crtc_state)
12826 intel_crtc_copy_color_blobs(crtc_state);
12830 intel_crtc_copy_uapi_to_hw_state(struct intel_crtc_state *crtc_state)
12832 crtc_state->hw.enable = crtc_state->uapi.enable;
12833 crtc_state->hw.active = crtc_state->uapi.active;
12834 crtc_state->hw.mode = crtc_state->uapi.mode;
12835 crtc_state->hw.adjusted_mode = crtc_state->uapi.adjusted_mode;
12836 intel_crtc_copy_uapi_to_hw_state_nomodeset(crtc_state);
12839 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state)
12841 crtc_state->uapi.enable = crtc_state->hw.enable;
12842 crtc_state->uapi.active = crtc_state->hw.active;
12843 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0);
12845 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode;
12847 /* copy color blobs to uapi */
12848 drm_property_replace_blob(&crtc_state->uapi.degamma_lut,
12849 crtc_state->hw.degamma_lut);
12850 drm_property_replace_blob(&crtc_state->uapi.gamma_lut,
12851 crtc_state->hw.gamma_lut);
12852 drm_property_replace_blob(&crtc_state->uapi.ctm,
12853 crtc_state->hw.ctm);
12857 intel_crtc_prepare_cleared_state(struct intel_crtc_state *crtc_state)
12859 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12860 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12861 struct intel_crtc_state *saved_state;
12863 saved_state = intel_crtc_state_alloc(crtc);
12867 /* free the old crtc_state->hw members */
12868 intel_crtc_free_hw_state(crtc_state);
12870 /* FIXME: before the switch to atomic started, a new pipe_config was
12871 * kzalloc'd. Code that depends on any field being zero should be
12872 * fixed, so that the crtc_state can be safely duplicated. For now,
12873 * only fields that are know to not cause problems are preserved. */
12875 saved_state->uapi = crtc_state->uapi;
12876 saved_state->scaler_state = crtc_state->scaler_state;
12877 saved_state->shared_dpll = crtc_state->shared_dpll;
12878 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
12879 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
12880 sizeof(saved_state->icl_port_dplls));
12881 saved_state->crc_enabled = crtc_state->crc_enabled;
12882 if (IS_G4X(dev_priv) ||
12883 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12884 saved_state->wm = crtc_state->wm;
12886 * Save the slave bitmask which gets filled for master crtc state during
12887 * slave atomic check call.
12889 if (is_trans_port_sync_master(crtc_state))
12890 saved_state->sync_mode_slaves_mask =
12891 crtc_state->sync_mode_slaves_mask;
12893 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
12894 kfree(saved_state);
12896 intel_crtc_copy_uapi_to_hw_state(crtc_state);
12902 intel_modeset_pipe_config(struct intel_crtc_state *pipe_config)
12904 struct drm_crtc *crtc = pipe_config->uapi.crtc;
12905 struct drm_atomic_state *state = pipe_config->uapi.state;
12906 struct intel_encoder *encoder;
12907 struct drm_connector *connector;
12908 struct drm_connector_state *connector_state;
12913 pipe_config->cpu_transcoder =
12914 (enum transcoder) to_intel_crtc(crtc)->pipe;
12917 * Sanitize sync polarity flags based on requested ones. If neither
12918 * positive or negative polarity is requested, treat this as meaning
12919 * negative polarity.
12921 if (!(pipe_config->hw.adjusted_mode.flags &
12922 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
12923 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
12925 if (!(pipe_config->hw.adjusted_mode.flags &
12926 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
12927 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
12929 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
12934 base_bpp = pipe_config->pipe_bpp;
12937 * Determine the real pipe dimensions. Note that stereo modes can
12938 * increase the actual pipe size due to the frame doubling and
12939 * insertion of additional space for blanks between the frame. This
12940 * is stored in the crtc timings. We use the requested mode to do this
12941 * computation to clearly distinguish it from the adjusted mode, which
12942 * can be changed by the connectors in the below retry loop.
12944 drm_mode_get_hv_timing(&pipe_config->hw.mode,
12945 &pipe_config->pipe_src_w,
12946 &pipe_config->pipe_src_h);
12948 for_each_new_connector_in_state(state, connector, connector_state, i) {
12949 if (connector_state->crtc != crtc)
12952 encoder = to_intel_encoder(connector_state->best_encoder);
12954 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
12955 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
12960 * Determine output_types before calling the .compute_config()
12961 * hooks so that the hooks can use this information safely.
12963 if (encoder->compute_output_type)
12964 pipe_config->output_types |=
12965 BIT(encoder->compute_output_type(encoder, pipe_config,
12968 pipe_config->output_types |= BIT(encoder->type);
12972 /* Ensure the port clock defaults are reset when retrying. */
12973 pipe_config->port_clock = 0;
12974 pipe_config->pixel_multiplier = 1;
12976 /* Fill in default crtc timings, allow encoders to overwrite them. */
12977 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
12978 CRTC_STEREO_DOUBLE);
12980 /* Set the crtc_state defaults for trans_port_sync */
12981 pipe_config->master_transcoder = INVALID_TRANSCODER;
12982 ret = icl_add_sync_mode_crtcs(pipe_config);
12984 DRM_DEBUG_KMS("Cannot assign Sync Mode CRTCs: %d\n",
12989 /* Pass our mode to the connectors and the CRTC to give them a chance to
12990 * adjust it according to limitations or connector properties, and also
12991 * a chance to reject the mode entirely.
12993 for_each_new_connector_in_state(state, connector, connector_state, i) {
12994 if (connector_state->crtc != crtc)
12997 encoder = to_intel_encoder(connector_state->best_encoder);
12998 ret = encoder->compute_config(encoder, pipe_config,
13001 if (ret != -EDEADLK)
13002 DRM_DEBUG_KMS("Encoder config failure: %d\n",
13008 /* Set default port clock if not overwritten by the encoder. Needs to be
13009 * done afterwards in case the encoder adjusts the mode. */
13010 if (!pipe_config->port_clock)
13011 pipe_config->port_clock = pipe_config->hw.adjusted_mode.crtc_clock
13012 * pipe_config->pixel_multiplier;
13014 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
13015 if (ret == -EDEADLK)
13018 DRM_DEBUG_KMS("CRTC fixup failed\n");
13022 if (ret == RETRY) {
13023 if (WARN(!retry, "loop in pipe configuration computation\n"))
13026 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
13028 goto encoder_retry;
13031 /* Dithering seems to not pass-through bits correctly when it should, so
13032 * only enable it on 6bpc panels and when its not a compliance
13033 * test requesting 6bpc video pattern.
13035 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
13036 !pipe_config->dither_force_disable;
13037 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
13038 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
13041 * Make drm_calc_timestamping_constants in
13042 * drm_atomic_helper_update_legacy_modeset_state() happy
13044 pipe_config->uapi.adjusted_mode = pipe_config->hw.adjusted_mode;
13049 bool intel_fuzzy_clock_check(int clock1, int clock2)
13053 if (clock1 == clock2)
13056 if (!clock1 || !clock2)
13059 diff = abs(clock1 - clock2);
13061 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
13068 intel_compare_m_n(unsigned int m, unsigned int n,
13069 unsigned int m2, unsigned int n2,
13072 if (m == m2 && n == n2)
13075 if (exact || !m || !n || !m2 || !n2)
13078 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
13085 } else if (n < n2) {
13095 return intel_fuzzy_clock_check(m, m2);
13099 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
13100 const struct intel_link_m_n *m2_n2,
13103 return m_n->tu == m2_n2->tu &&
13104 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
13105 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
13106 intel_compare_m_n(m_n->link_m, m_n->link_n,
13107 m2_n2->link_m, m2_n2->link_n, exact);
13111 intel_compare_infoframe(const union hdmi_infoframe *a,
13112 const union hdmi_infoframe *b)
13114 return memcmp(a, b, sizeof(*a)) == 0;
13118 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
13119 bool fastset, const char *name,
13120 const union hdmi_infoframe *a,
13121 const union hdmi_infoframe *b)
13124 if ((drm_debug & DRM_UT_KMS) == 0)
13127 DRM_DEBUG_KMS("fastset mismatch in %s infoframe\n", name);
13128 DRM_DEBUG_KMS("expected:\n");
13129 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
13130 DRM_DEBUG_KMS("found:\n");
13131 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
13133 DRM_ERROR("mismatch in %s infoframe\n", name);
13134 DRM_ERROR("expected:\n");
13135 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
13136 DRM_ERROR("found:\n");
13137 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
13141 static void __printf(4, 5)
13142 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
13143 const char *name, const char *format, ...)
13145 struct va_format vaf;
13148 va_start(args, format);
13153 DRM_DEBUG_KMS("[CRTC:%d:%s] fastset mismatch in %s %pV\n",
13154 crtc->base.base.id, crtc->base.name, name, &vaf);
13156 DRM_ERROR("[CRTC:%d:%s] mismatch in %s %pV\n",
13157 crtc->base.base.id, crtc->base.name, name, &vaf);
13162 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
13164 if (i915_modparams.fastboot != -1)
13165 return i915_modparams.fastboot;
13167 /* Enable fastboot by default on Skylake and newer */
13168 if (INTEL_GEN(dev_priv) >= 9)
13171 /* Enable fastboot by default on VLV and CHV */
13172 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13175 /* Disabled by default on all others */
13180 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
13181 const struct intel_crtc_state *pipe_config,
13184 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
13185 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
13188 bool fixup_inherited = fastset &&
13189 (current_config->hw.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
13190 !(pipe_config->hw.mode.private_flags & I915_MODE_FLAG_INHERITED);
13192 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
13193 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
13197 #define PIPE_CONF_CHECK_X(name) do { \
13198 if (current_config->name != pipe_config->name) { \
13199 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13200 "(expected 0x%08x, found 0x%08x)", \
13201 current_config->name, \
13202 pipe_config->name); \
13207 #define PIPE_CONF_CHECK_I(name) do { \
13208 if (current_config->name != pipe_config->name) { \
13209 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13210 "(expected %i, found %i)", \
13211 current_config->name, \
13212 pipe_config->name); \
13217 #define PIPE_CONF_CHECK_BOOL(name) do { \
13218 if (current_config->name != pipe_config->name) { \
13219 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13220 "(expected %s, found %s)", \
13221 yesno(current_config->name), \
13222 yesno(pipe_config->name)); \
13228 * Checks state where we only read out the enabling, but not the entire
13229 * state itself (like full infoframes or ELD for audio). These states
13230 * require a full modeset on bootup to fix up.
13232 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
13233 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
13234 PIPE_CONF_CHECK_BOOL(name); \
13236 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13237 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
13238 yesno(current_config->name), \
13239 yesno(pipe_config->name)); \
13244 #define PIPE_CONF_CHECK_P(name) do { \
13245 if (current_config->name != pipe_config->name) { \
13246 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13247 "(expected %p, found %p)", \
13248 current_config->name, \
13249 pipe_config->name); \
13254 #define PIPE_CONF_CHECK_M_N(name) do { \
13255 if (!intel_compare_link_m_n(¤t_config->name, \
13256 &pipe_config->name,\
13258 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13259 "(expected tu %i gmch %i/%i link %i/%i, " \
13260 "found tu %i, gmch %i/%i link %i/%i)", \
13261 current_config->name.tu, \
13262 current_config->name.gmch_m, \
13263 current_config->name.gmch_n, \
13264 current_config->name.link_m, \
13265 current_config->name.link_n, \
13266 pipe_config->name.tu, \
13267 pipe_config->name.gmch_m, \
13268 pipe_config->name.gmch_n, \
13269 pipe_config->name.link_m, \
13270 pipe_config->name.link_n); \
13275 /* This is required for BDW+ where there is only one set of registers for
13276 * switching between high and low RR.
13277 * This macro can be used whenever a comparison has to be made between one
13278 * hw state and multiple sw state variables.
13280 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
13281 if (!intel_compare_link_m_n(¤t_config->name, \
13282 &pipe_config->name, !fastset) && \
13283 !intel_compare_link_m_n(¤t_config->alt_name, \
13284 &pipe_config->name, !fastset)) { \
13285 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13286 "(expected tu %i gmch %i/%i link %i/%i, " \
13287 "or tu %i gmch %i/%i link %i/%i, " \
13288 "found tu %i, gmch %i/%i link %i/%i)", \
13289 current_config->name.tu, \
13290 current_config->name.gmch_m, \
13291 current_config->name.gmch_n, \
13292 current_config->name.link_m, \
13293 current_config->name.link_n, \
13294 current_config->alt_name.tu, \
13295 current_config->alt_name.gmch_m, \
13296 current_config->alt_name.gmch_n, \
13297 current_config->alt_name.link_m, \
13298 current_config->alt_name.link_n, \
13299 pipe_config->name.tu, \
13300 pipe_config->name.gmch_m, \
13301 pipe_config->name.gmch_n, \
13302 pipe_config->name.link_m, \
13303 pipe_config->name.link_n); \
13308 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
13309 if ((current_config->name ^ pipe_config->name) & (mask)) { \
13310 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13311 "(%x) (expected %i, found %i)", \
13313 current_config->name & (mask), \
13314 pipe_config->name & (mask)); \
13319 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
13320 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
13321 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13322 "(expected %i, found %i)", \
13323 current_config->name, \
13324 pipe_config->name); \
13329 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
13330 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
13331 &pipe_config->infoframes.name)) { \
13332 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
13333 ¤t_config->infoframes.name, \
13334 &pipe_config->infoframes.name); \
13339 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
13340 if (current_config->name1 != pipe_config->name1) { \
13341 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
13342 "(expected %i, found %i, won't compare lut values)", \
13343 current_config->name1, \
13344 pipe_config->name1); \
13347 if (!intel_color_lut_equal(current_config->name2, \
13348 pipe_config->name2, pipe_config->name1, \
13349 bit_precision)) { \
13350 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
13351 "hw_state doesn't match sw_state"); \
13357 #define PIPE_CONF_QUIRK(quirk) \
13358 ((current_config->quirks | pipe_config->quirks) & (quirk))
13360 PIPE_CONF_CHECK_I(cpu_transcoder);
13362 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
13363 PIPE_CONF_CHECK_I(fdi_lanes);
13364 PIPE_CONF_CHECK_M_N(fdi_m_n);
13366 PIPE_CONF_CHECK_I(lane_count);
13367 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
13369 if (INTEL_GEN(dev_priv) < 8) {
13370 PIPE_CONF_CHECK_M_N(dp_m_n);
13372 if (current_config->has_drrs)
13373 PIPE_CONF_CHECK_M_N(dp_m2_n2);
13375 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
13377 PIPE_CONF_CHECK_X(output_types);
13379 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hdisplay);
13380 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_htotal);
13381 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_start);
13382 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_end);
13383 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_start);
13384 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_end);
13386 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vdisplay);
13387 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vtotal);
13388 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_start);
13389 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_end);
13390 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_start);
13391 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_end);
13393 PIPE_CONF_CHECK_I(pixel_multiplier);
13394 PIPE_CONF_CHECK_I(output_format);
13395 PIPE_CONF_CHECK_I(dc3co_exitline);
13396 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
13397 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
13398 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13399 PIPE_CONF_CHECK_BOOL(limited_color_range);
13401 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
13402 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
13403 PIPE_CONF_CHECK_BOOL(has_infoframe);
13404 PIPE_CONF_CHECK_BOOL(fec_enable);
13406 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
13408 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13409 DRM_MODE_FLAG_INTERLACE);
13411 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
13412 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13413 DRM_MODE_FLAG_PHSYNC);
13414 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13415 DRM_MODE_FLAG_NHSYNC);
13416 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13417 DRM_MODE_FLAG_PVSYNC);
13418 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13419 DRM_MODE_FLAG_NVSYNC);
13422 PIPE_CONF_CHECK_X(gmch_pfit.control);
13423 /* pfit ratios are autocomputed by the hw on gen4+ */
13424 if (INTEL_GEN(dev_priv) < 4)
13425 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
13426 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
13429 * Changing the EDP transcoder input mux
13430 * (A_ONOFF vs. A_ON) requires a full modeset.
13432 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
13435 PIPE_CONF_CHECK_I(pipe_src_w);
13436 PIPE_CONF_CHECK_I(pipe_src_h);
13438 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
13439 if (current_config->pch_pfit.enabled) {
13440 PIPE_CONF_CHECK_X(pch_pfit.pos);
13441 PIPE_CONF_CHECK_X(pch_pfit.size);
13444 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
13445 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
13447 PIPE_CONF_CHECK_X(gamma_mode);
13448 if (IS_CHERRYVIEW(dev_priv))
13449 PIPE_CONF_CHECK_X(cgm_mode);
13451 PIPE_CONF_CHECK_X(csc_mode);
13452 PIPE_CONF_CHECK_BOOL(gamma_enable);
13453 PIPE_CONF_CHECK_BOOL(csc_enable);
13455 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
13457 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
13461 PIPE_CONF_CHECK_BOOL(double_wide);
13463 PIPE_CONF_CHECK_P(shared_dpll);
13464 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
13465 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
13466 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
13467 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
13468 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
13469 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
13470 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
13471 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
13472 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
13473 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
13474 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
13475 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
13476 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
13477 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
13478 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
13479 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
13480 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
13481 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
13482 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
13483 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
13484 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
13485 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
13486 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
13487 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
13488 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
13489 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
13490 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
13491 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
13492 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
13493 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
13494 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
13496 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
13497 PIPE_CONF_CHECK_X(dsi_pll.div);
13499 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
13500 PIPE_CONF_CHECK_I(pipe_bpp);
13502 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
13503 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
13505 PIPE_CONF_CHECK_I(min_voltage_level);
13507 PIPE_CONF_CHECK_X(infoframes.enable);
13508 PIPE_CONF_CHECK_X(infoframes.gcp);
13509 PIPE_CONF_CHECK_INFOFRAME(avi);
13510 PIPE_CONF_CHECK_INFOFRAME(spd);
13511 PIPE_CONF_CHECK_INFOFRAME(hdmi);
13512 PIPE_CONF_CHECK_INFOFRAME(drm);
13514 PIPE_CONF_CHECK_I(sync_mode_slaves_mask);
13515 PIPE_CONF_CHECK_I(master_transcoder);
13517 PIPE_CONF_CHECK_I(dsc.compression_enable);
13518 PIPE_CONF_CHECK_I(dsc.dsc_split);
13519 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
13521 #undef PIPE_CONF_CHECK_X
13522 #undef PIPE_CONF_CHECK_I
13523 #undef PIPE_CONF_CHECK_BOOL
13524 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
13525 #undef PIPE_CONF_CHECK_P
13526 #undef PIPE_CONF_CHECK_FLAGS
13527 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
13528 #undef PIPE_CONF_CHECK_COLOR_LUT
13529 #undef PIPE_CONF_QUIRK
13534 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
13535 const struct intel_crtc_state *pipe_config)
13537 if (pipe_config->has_pch_encoder) {
13538 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
13539 &pipe_config->fdi_m_n);
13540 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
13543 * FDI already provided one idea for the dotclock.
13544 * Yell if the encoder disagrees.
13546 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
13547 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
13548 fdi_dotclock, dotclock);
13552 static void verify_wm_state(struct intel_crtc *crtc,
13553 struct intel_crtc_state *new_crtc_state)
13555 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13556 struct skl_hw_state {
13557 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
13558 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
13559 struct skl_ddb_allocation ddb;
13560 struct skl_pipe_wm wm;
13562 struct skl_ddb_allocation *sw_ddb;
13563 struct skl_pipe_wm *sw_wm;
13564 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
13565 const enum pipe pipe = crtc->pipe;
13566 int plane, level, max_level = ilk_wm_max_level(dev_priv);
13568 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->hw.active)
13571 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
13575 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
13576 sw_wm = &new_crtc_state->wm.skl.optimal;
13578 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
13580 skl_ddb_get_hw_state(dev_priv, &hw->ddb);
13581 sw_ddb = &dev_priv->wm.skl_hw.ddb;
13583 if (INTEL_GEN(dev_priv) >= 11 &&
13584 hw->ddb.enabled_slices != sw_ddb->enabled_slices)
13585 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
13586 sw_ddb->enabled_slices,
13587 hw->ddb.enabled_slices);
13590 for_each_universal_plane(dev_priv, pipe, plane) {
13591 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13593 hw_plane_wm = &hw->wm.planes[plane];
13594 sw_plane_wm = &sw_wm->planes[plane];
13597 for (level = 0; level <= max_level; level++) {
13598 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13599 &sw_plane_wm->wm[level]))
13602 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",
13603 pipe_name(pipe), plane + 1, level,
13604 sw_plane_wm->wm[level].plane_en,
13605 sw_plane_wm->wm[level].plane_res_b,
13606 sw_plane_wm->wm[level].plane_res_l,
13607 hw_plane_wm->wm[level].plane_en,
13608 hw_plane_wm->wm[level].plane_res_b,
13609 hw_plane_wm->wm[level].plane_res_l);
13612 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13613 &sw_plane_wm->trans_wm)) {
13614 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",
13615 pipe_name(pipe), plane + 1,
13616 sw_plane_wm->trans_wm.plane_en,
13617 sw_plane_wm->trans_wm.plane_res_b,
13618 sw_plane_wm->trans_wm.plane_res_l,
13619 hw_plane_wm->trans_wm.plane_en,
13620 hw_plane_wm->trans_wm.plane_res_b,
13621 hw_plane_wm->trans_wm.plane_res_l);
13625 hw_ddb_entry = &hw->ddb_y[plane];
13626 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
13628 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13629 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
13630 pipe_name(pipe), plane + 1,
13631 sw_ddb_entry->start, sw_ddb_entry->end,
13632 hw_ddb_entry->start, hw_ddb_entry->end);
13638 * If the cursor plane isn't active, we may not have updated it's ddb
13639 * allocation. In that case since the ddb allocation will be updated
13640 * once the plane becomes visible, we can skip this check
13643 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13645 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
13646 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
13649 for (level = 0; level <= max_level; level++) {
13650 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13651 &sw_plane_wm->wm[level]))
13654 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",
13655 pipe_name(pipe), level,
13656 sw_plane_wm->wm[level].plane_en,
13657 sw_plane_wm->wm[level].plane_res_b,
13658 sw_plane_wm->wm[level].plane_res_l,
13659 hw_plane_wm->wm[level].plane_en,
13660 hw_plane_wm->wm[level].plane_res_b,
13661 hw_plane_wm->wm[level].plane_res_l);
13664 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13665 &sw_plane_wm->trans_wm)) {
13666 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13668 sw_plane_wm->trans_wm.plane_en,
13669 sw_plane_wm->trans_wm.plane_res_b,
13670 sw_plane_wm->trans_wm.plane_res_l,
13671 hw_plane_wm->trans_wm.plane_en,
13672 hw_plane_wm->trans_wm.plane_res_b,
13673 hw_plane_wm->trans_wm.plane_res_l);
13677 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
13678 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
13680 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13681 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
13683 sw_ddb_entry->start, sw_ddb_entry->end,
13684 hw_ddb_entry->start, hw_ddb_entry->end);
13692 verify_connector_state(struct intel_atomic_state *state,
13693 struct intel_crtc *crtc)
13695 struct drm_connector *connector;
13696 struct drm_connector_state *new_conn_state;
13699 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
13700 struct drm_encoder *encoder = connector->encoder;
13701 struct intel_crtc_state *crtc_state = NULL;
13703 if (new_conn_state->crtc != &crtc->base)
13707 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
13709 intel_connector_verify_state(crtc_state, new_conn_state);
13711 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
13712 "connector's atomic encoder doesn't match legacy encoder\n");
13717 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
13719 struct intel_encoder *encoder;
13720 struct drm_connector *connector;
13721 struct drm_connector_state *old_conn_state, *new_conn_state;
13724 for_each_intel_encoder(&dev_priv->drm, encoder) {
13725 bool enabled = false, found = false;
13728 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
13729 encoder->base.base.id,
13730 encoder->base.name);
13732 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
13733 new_conn_state, i) {
13734 if (old_conn_state->best_encoder == &encoder->base)
13737 if (new_conn_state->best_encoder != &encoder->base)
13739 found = enabled = true;
13741 I915_STATE_WARN(new_conn_state->crtc !=
13742 encoder->base.crtc,
13743 "connector's crtc doesn't match encoder crtc\n");
13749 I915_STATE_WARN(!!encoder->base.crtc != enabled,
13750 "encoder's enabled state mismatch "
13751 "(expected %i, found %i)\n",
13752 !!encoder->base.crtc, enabled);
13754 if (!encoder->base.crtc) {
13757 active = encoder->get_hw_state(encoder, &pipe);
13758 I915_STATE_WARN(active,
13759 "encoder detached but still enabled on pipe %c.\n",
13766 verify_crtc_state(struct intel_crtc *crtc,
13767 struct intel_crtc_state *old_crtc_state,
13768 struct intel_crtc_state *new_crtc_state)
13770 struct drm_device *dev = crtc->base.dev;
13771 struct drm_i915_private *dev_priv = to_i915(dev);
13772 struct intel_encoder *encoder;
13773 struct intel_crtc_state *pipe_config = old_crtc_state;
13774 struct drm_atomic_state *state = old_crtc_state->uapi.state;
13777 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
13778 intel_crtc_free_hw_state(old_crtc_state);
13779 intel_crtc_state_reset(old_crtc_state, crtc);
13780 old_crtc_state->uapi.state = state;
13782 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.base.id, crtc->base.name);
13784 active = dev_priv->display.get_pipe_config(crtc, pipe_config);
13786 /* we keep both pipes enabled on 830 */
13787 if (IS_I830(dev_priv))
13788 active = new_crtc_state->hw.active;
13790 I915_STATE_WARN(new_crtc_state->hw.active != active,
13791 "crtc active state doesn't match with hw state "
13792 "(expected %i, found %i)\n",
13793 new_crtc_state->hw.active, active);
13795 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
13796 "transitional active state does not match atomic hw state "
13797 "(expected %i, found %i)\n",
13798 new_crtc_state->hw.active, crtc->active);
13800 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
13803 active = encoder->get_hw_state(encoder, &pipe);
13804 I915_STATE_WARN(active != new_crtc_state->hw.active,
13805 "[ENCODER:%i] active %i with crtc active %i\n",
13806 encoder->base.base.id, active,
13807 new_crtc_state->hw.active);
13809 I915_STATE_WARN(active && crtc->pipe != pipe,
13810 "Encoder connected to wrong pipe %c\n",
13814 encoder->get_config(encoder, pipe_config);
13817 intel_crtc_compute_pixel_rate(pipe_config);
13819 if (!new_crtc_state->hw.active)
13822 intel_pipe_config_sanity_check(dev_priv, pipe_config);
13824 if (!intel_pipe_config_compare(new_crtc_state,
13825 pipe_config, false)) {
13826 I915_STATE_WARN(1, "pipe state doesn't match!\n");
13827 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
13828 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
13833 intel_verify_planes(struct intel_atomic_state *state)
13835 struct intel_plane *plane;
13836 const struct intel_plane_state *plane_state;
13839 for_each_new_intel_plane_in_state(state, plane,
13841 assert_plane(plane, plane_state->planar_slave ||
13842 plane_state->uapi.visible);
13846 verify_single_dpll_state(struct drm_i915_private *dev_priv,
13847 struct intel_shared_dpll *pll,
13848 struct intel_crtc *crtc,
13849 struct intel_crtc_state *new_crtc_state)
13851 struct intel_dpll_hw_state dpll_hw_state;
13852 unsigned int crtc_mask;
13855 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
13857 DRM_DEBUG_KMS("%s\n", pll->info->name);
13859 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
13861 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
13862 I915_STATE_WARN(!pll->on && pll->active_mask,
13863 "pll in active use but not on in sw tracking\n");
13864 I915_STATE_WARN(pll->on && !pll->active_mask,
13865 "pll is on but not used by any active crtc\n");
13866 I915_STATE_WARN(pll->on != active,
13867 "pll on state mismatch (expected %i, found %i)\n",
13872 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
13873 "more active pll users than references: %x vs %x\n",
13874 pll->active_mask, pll->state.crtc_mask);
13879 crtc_mask = drm_crtc_mask(&crtc->base);
13881 if (new_crtc_state->hw.active)
13882 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
13883 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
13884 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13886 I915_STATE_WARN(pll->active_mask & crtc_mask,
13887 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
13888 pipe_name(drm_crtc_index(&crtc->base)), pll->active_mask);
13890 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
13891 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
13892 crtc_mask, pll->state.crtc_mask);
13894 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
13896 sizeof(dpll_hw_state)),
13897 "pll hw state mismatch\n");
13901 verify_shared_dpll_state(struct intel_crtc *crtc,
13902 struct intel_crtc_state *old_crtc_state,
13903 struct intel_crtc_state *new_crtc_state)
13905 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13907 if (new_crtc_state->shared_dpll)
13908 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
13910 if (old_crtc_state->shared_dpll &&
13911 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
13912 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
13913 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
13915 I915_STATE_WARN(pll->active_mask & crtc_mask,
13916 "pll active mismatch (didn't expect pipe %c in active mask)\n",
13917 pipe_name(drm_crtc_index(&crtc->base)));
13918 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
13919 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
13920 pipe_name(drm_crtc_index(&crtc->base)));
13925 intel_modeset_verify_crtc(struct intel_crtc *crtc,
13926 struct intel_atomic_state *state,
13927 struct intel_crtc_state *old_crtc_state,
13928 struct intel_crtc_state *new_crtc_state)
13930 if (!needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
13933 verify_wm_state(crtc, new_crtc_state);
13934 verify_connector_state(state, crtc);
13935 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
13936 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
13940 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
13944 for (i = 0; i < dev_priv->num_shared_dpll; i++)
13945 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
13949 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
13950 struct intel_atomic_state *state)
13952 verify_encoder_state(dev_priv, state);
13953 verify_connector_state(state, NULL);
13954 verify_disabled_dpll_state(dev_priv);
13958 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
13960 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
13961 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13962 const struct drm_display_mode *adjusted_mode =
13963 &crtc_state->hw.adjusted_mode;
13965 drm_calc_timestamping_constants(&crtc->base, adjusted_mode);
13968 * The scanline counter increments at the leading edge of hsync.
13970 * On most platforms it starts counting from vtotal-1 on the
13971 * first active line. That means the scanline counter value is
13972 * always one less than what we would expect. Ie. just after
13973 * start of vblank, which also occurs at start of hsync (on the
13974 * last active line), the scanline counter will read vblank_start-1.
13976 * On gen2 the scanline counter starts counting from 1 instead
13977 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
13978 * to keep the value positive), instead of adding one.
13980 * On HSW+ the behaviour of the scanline counter depends on the output
13981 * type. For DP ports it behaves like most other platforms, but on HDMI
13982 * there's an extra 1 line difference. So we need to add two instead of
13983 * one to the value.
13985 * On VLV/CHV DSI the scanline counter would appear to increment
13986 * approx. 1/3 of a scanline before start of vblank. Unfortunately
13987 * that means we can't tell whether we're in vblank or not while
13988 * we're on that particular line. We must still set scanline_offset
13989 * to 1 so that the vblank timestamps come out correct when we query
13990 * the scanline counter from within the vblank interrupt handler.
13991 * However if queried just before the start of vblank we'll get an
13992 * answer that's slightly in the future.
13994 if (IS_GEN(dev_priv, 2)) {
13997 vtotal = adjusted_mode->crtc_vtotal;
13998 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
14001 crtc->scanline_offset = vtotal - 1;
14002 } else if (HAS_DDI(dev_priv) &&
14003 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
14004 crtc->scanline_offset = 2;
14006 crtc->scanline_offset = 1;
14010 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
14012 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14013 struct intel_crtc_state *new_crtc_state;
14014 struct intel_crtc *crtc;
14017 if (!dev_priv->display.crtc_compute_clock)
14020 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14021 if (!needs_modeset(new_crtc_state))
14024 intel_release_shared_dplls(state, crtc);
14029 * This implements the workaround described in the "notes" section of the mode
14030 * set sequence documentation. When going from no pipes or single pipe to
14031 * multiple pipes, and planes are enabled after the pipe, we need to wait at
14032 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
14034 static int haswell_mode_set_planes_workaround(struct intel_atomic_state *state)
14036 struct intel_crtc_state *crtc_state;
14037 struct intel_crtc *crtc;
14038 struct intel_crtc_state *first_crtc_state = NULL;
14039 struct intel_crtc_state *other_crtc_state = NULL;
14040 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
14043 /* look at all crtc's that are going to be enabled in during modeset */
14044 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14045 if (!crtc_state->hw.active ||
14046 !needs_modeset(crtc_state))
14049 if (first_crtc_state) {
14050 other_crtc_state = crtc_state;
14053 first_crtc_state = crtc_state;
14054 first_pipe = crtc->pipe;
14058 /* No workaround needed? */
14059 if (!first_crtc_state)
14062 /* w/a possibly needed, check how many crtc's are already enabled. */
14063 for_each_intel_crtc(state->base.dev, crtc) {
14064 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
14065 if (IS_ERR(crtc_state))
14066 return PTR_ERR(crtc_state);
14068 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
14070 if (!crtc_state->hw.active ||
14071 needs_modeset(crtc_state))
14074 /* 2 or more enabled crtcs means no need for w/a */
14075 if (enabled_pipe != INVALID_PIPE)
14078 enabled_pipe = crtc->pipe;
14081 if (enabled_pipe != INVALID_PIPE)
14082 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
14083 else if (other_crtc_state)
14084 other_crtc_state->hsw_workaround_pipe = first_pipe;
14089 static int intel_modeset_checks(struct intel_atomic_state *state)
14091 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14092 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14093 struct intel_crtc *crtc;
14096 /* keep the current setting */
14097 if (!state->cdclk.force_min_cdclk_changed)
14098 state->cdclk.force_min_cdclk = dev_priv->cdclk.force_min_cdclk;
14100 state->modeset = true;
14101 state->active_pipes = dev_priv->active_pipes;
14102 state->cdclk.logical = dev_priv->cdclk.logical;
14103 state->cdclk.actual = dev_priv->cdclk.actual;
14105 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14106 new_crtc_state, i) {
14107 if (new_crtc_state->hw.active)
14108 state->active_pipes |= BIT(crtc->pipe);
14110 state->active_pipes &= ~BIT(crtc->pipe);
14112 if (old_crtc_state->hw.active != new_crtc_state->hw.active)
14113 state->active_pipe_changes |= BIT(crtc->pipe);
14116 if (state->active_pipe_changes) {
14117 ret = intel_atomic_lock_global_state(state);
14122 ret = intel_modeset_calc_cdclk(state);
14126 intel_modeset_clear_plls(state);
14128 if (IS_HASWELL(dev_priv))
14129 return haswell_mode_set_planes_workaround(state);
14135 * Handle calculation of various watermark data at the end of the atomic check
14136 * phase. The code here should be run after the per-crtc and per-plane 'check'
14137 * handlers to ensure that all derived state has been updated.
14139 static int calc_watermark_data(struct intel_atomic_state *state)
14141 struct drm_device *dev = state->base.dev;
14142 struct drm_i915_private *dev_priv = to_i915(dev);
14144 /* Is there platform-specific watermark information to calculate? */
14145 if (dev_priv->display.compute_global_watermarks)
14146 return dev_priv->display.compute_global_watermarks(state);
14151 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
14152 struct intel_crtc_state *new_crtc_state)
14154 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
14157 new_crtc_state->uapi.mode_changed = false;
14158 new_crtc_state->update_pipe = true;
14161 * If we're not doing the full modeset we want to
14162 * keep the current M/N values as they may be
14163 * sufficiently different to the computed values
14164 * to cause problems.
14166 * FIXME: should really copy more fuzzy state here
14168 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
14169 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
14170 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
14171 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
14174 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
14175 struct intel_crtc *crtc,
14178 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14179 struct intel_plane *plane;
14181 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
14182 struct intel_plane_state *plane_state;
14184 if ((plane_ids_mask & BIT(plane->id)) == 0)
14187 plane_state = intel_atomic_get_plane_state(state, plane);
14188 if (IS_ERR(plane_state))
14189 return PTR_ERR(plane_state);
14195 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
14197 /* See {hsw,vlv,ivb}_plane_ratio() */
14198 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
14199 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
14200 IS_IVYBRIDGE(dev_priv);
14203 static int intel_atomic_check_planes(struct intel_atomic_state *state,
14204 bool *need_modeset)
14206 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14207 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14208 struct intel_plane_state *plane_state;
14209 struct intel_plane *plane;
14210 struct intel_crtc *crtc;
14213 ret = icl_add_linked_planes(state);
14217 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14218 ret = intel_plane_atomic_check(state, plane);
14220 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic driver check failed\n",
14221 plane->base.base.id, plane->base.name);
14226 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14227 new_crtc_state, i) {
14228 u8 old_active_planes, new_active_planes;
14230 ret = icl_check_nv12_planes(new_crtc_state);
14235 * On some platforms the number of active planes affects
14236 * the planes' minimum cdclk calculation. Add such planes
14237 * to the state before we compute the minimum cdclk.
14239 if (!active_planes_affects_min_cdclk(dev_priv))
14242 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14243 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14245 if (hweight8(old_active_planes) == hweight8(new_active_planes))
14248 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
14254 * active_planes bitmask has been updated, and potentially
14255 * affected planes are part of the state. We can now
14256 * compute the minimum cdclk for each plane.
14258 for_each_new_intel_plane_in_state(state, plane, plane_state, i)
14259 *need_modeset |= intel_plane_calc_min_cdclk(state, plane);
14264 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
14266 struct intel_crtc_state *crtc_state;
14267 struct intel_crtc *crtc;
14270 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14271 int ret = intel_crtc_atomic_check(state, crtc);
14273 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n",
14274 crtc->base.base.id, crtc->base.name);
14283 * intel_atomic_check - validate state object
14285 * @_state: state to validate
14287 static int intel_atomic_check(struct drm_device *dev,
14288 struct drm_atomic_state *_state)
14290 struct drm_i915_private *dev_priv = to_i915(dev);
14291 struct intel_atomic_state *state = to_intel_atomic_state(_state);
14292 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14293 struct intel_crtc *crtc;
14295 bool any_ms = false;
14297 /* Catch I915_MODE_FLAG_INHERITED */
14298 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14299 new_crtc_state, i) {
14300 if (new_crtc_state->hw.mode.private_flags !=
14301 old_crtc_state->hw.mode.private_flags)
14302 new_crtc_state->uapi.mode_changed = true;
14305 ret = drm_atomic_helper_check_modeset(dev, &state->base);
14309 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14310 new_crtc_state, i) {
14311 if (!needs_modeset(new_crtc_state)) {
14313 intel_crtc_copy_uapi_to_hw_state_nomodeset(new_crtc_state);
14318 if (!new_crtc_state->uapi.enable) {
14319 intel_crtc_copy_uapi_to_hw_state(new_crtc_state);
14325 ret = intel_crtc_prepare_cleared_state(new_crtc_state);
14329 ret = intel_modeset_pipe_config(new_crtc_state);
14333 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
14335 if (needs_modeset(new_crtc_state))
14339 if (any_ms && !check_digital_port_conflicts(state)) {
14340 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
14345 ret = drm_dp_mst_atomic_check(&state->base);
14349 any_ms |= state->cdclk.force_min_cdclk_changed;
14351 ret = intel_atomic_check_planes(state, &any_ms);
14356 ret = intel_modeset_checks(state);
14360 state->cdclk.logical = dev_priv->cdclk.logical;
14363 ret = intel_atomic_check_crtcs(state);
14367 intel_fbc_choose_crtc(dev_priv, state);
14368 ret = calc_watermark_data(state);
14372 ret = intel_bw_atomic_check(state);
14376 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14377 new_crtc_state, i) {
14378 if (!needs_modeset(new_crtc_state) &&
14379 !new_crtc_state->update_pipe)
14382 intel_dump_pipe_config(new_crtc_state, state,
14383 needs_modeset(new_crtc_state) ?
14384 "[modeset]" : "[fastset]");
14390 if (ret == -EDEADLK)
14394 * FIXME would probably be nice to know which crtc specifically
14395 * caused the failure, in cases where we can pinpoint it.
14397 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14399 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
14404 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
14406 return drm_atomic_helper_prepare_planes(state->base.dev,
14410 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
14412 struct drm_device *dev = crtc->base.dev;
14413 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
14415 if (!vblank->max_vblank_count)
14416 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
14418 return crtc->base.funcs->get_vblank_counter(&crtc->base);
14421 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14422 struct intel_crtc_state *crtc_state)
14424 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14426 if (!IS_GEN(dev_priv, 2) || crtc_state->active_planes)
14427 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14429 if (crtc_state->has_pch_encoder) {
14430 enum pipe pch_transcoder =
14431 intel_crtc_pch_transcoder(crtc);
14433 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14437 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
14438 const struct intel_crtc_state *new_crtc_state)
14440 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
14441 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14444 * Update pipe size and adjust fitter if needed: the reason for this is
14445 * that in compute_mode_changes we check the native mode (not the pfit
14446 * mode) to see if we can flip rather than do a full mode set. In the
14447 * fastboot case, we'll flip, but if we don't update the pipesrc and
14448 * pfit state, we'll end up with a big fb scanned out into the wrong
14451 intel_set_pipe_src_size(new_crtc_state);
14453 /* on skylake this is done by detaching scalers */
14454 if (INTEL_GEN(dev_priv) >= 9) {
14455 skl_detach_scalers(new_crtc_state);
14457 if (new_crtc_state->pch_pfit.enabled)
14458 skylake_pfit_enable(new_crtc_state);
14459 } else if (HAS_PCH_SPLIT(dev_priv)) {
14460 if (new_crtc_state->pch_pfit.enabled)
14461 ironlake_pfit_enable(new_crtc_state);
14462 else if (old_crtc_state->pch_pfit.enabled)
14463 ironlake_pfit_disable(old_crtc_state);
14466 if (INTEL_GEN(dev_priv) >= 11)
14467 icl_set_pipe_chicken(crtc);
14470 static void commit_pipe_config(struct intel_atomic_state *state,
14471 struct intel_crtc_state *old_crtc_state,
14472 struct intel_crtc_state *new_crtc_state)
14474 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
14475 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14476 bool modeset = needs_modeset(new_crtc_state);
14479 * During modesets pipe configuration was programmed as the
14480 * CRTC was enabled.
14483 if (new_crtc_state->uapi.color_mgmt_changed ||
14484 new_crtc_state->update_pipe)
14485 intel_color_commit(new_crtc_state);
14487 if (INTEL_GEN(dev_priv) >= 9)
14488 skl_detach_scalers(new_crtc_state);
14490 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
14491 bdw_set_pipemisc(new_crtc_state);
14493 if (new_crtc_state->update_pipe)
14494 intel_pipe_fastset(old_crtc_state, new_crtc_state);
14497 if (dev_priv->display.atomic_update_watermarks)
14498 dev_priv->display.atomic_update_watermarks(state, crtc);
14501 static void intel_update_crtc(struct intel_crtc *crtc,
14502 struct intel_atomic_state *state,
14503 struct intel_crtc_state *old_crtc_state,
14504 struct intel_crtc_state *new_crtc_state)
14506 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14507 bool modeset = needs_modeset(new_crtc_state);
14508 struct intel_plane_state *new_plane_state =
14509 intel_atomic_get_new_plane_state(state,
14510 to_intel_plane(crtc->base.primary));
14513 intel_crtc_update_active_timings(new_crtc_state);
14515 dev_priv->display.crtc_enable(state, crtc);
14517 /* vblanks work again, re-enable pipe CRC. */
14518 intel_crtc_enable_pipe_crc(crtc);
14520 if (new_crtc_state->preload_luts &&
14521 (new_crtc_state->uapi.color_mgmt_changed ||
14522 new_crtc_state->update_pipe))
14523 intel_color_load_luts(new_crtc_state);
14525 intel_pre_plane_update(state, crtc);
14527 if (new_crtc_state->update_pipe)
14528 intel_encoders_update_pipe(state, crtc);
14531 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
14532 intel_fbc_disable(crtc);
14533 else if (new_plane_state)
14534 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
14536 /* Perform vblank evasion around commit operation */
14537 intel_pipe_update_start(new_crtc_state);
14539 commit_pipe_config(state, old_crtc_state, new_crtc_state);
14541 if (INTEL_GEN(dev_priv) >= 9)
14542 skl_update_planes_on_crtc(state, crtc);
14544 i9xx_update_planes_on_crtc(state, crtc);
14546 intel_pipe_update_end(new_crtc_state);
14549 * We usually enable FIFO underrun interrupts as part of the
14550 * CRTC enable sequence during modesets. But when we inherit a
14551 * valid pipe configuration from the BIOS we need to take care
14552 * of enabling them on the CRTC's first fastset.
14554 if (new_crtc_state->update_pipe && !modeset &&
14555 old_crtc_state->hw.mode.private_flags & I915_MODE_FLAG_INHERITED)
14556 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14559 static struct intel_crtc *intel_get_slave_crtc(const struct intel_crtc_state *new_crtc_state)
14561 struct drm_i915_private *dev_priv = to_i915(new_crtc_state->uapi.crtc->dev);
14562 enum transcoder slave_transcoder;
14564 WARN_ON(!is_power_of_2(new_crtc_state->sync_mode_slaves_mask));
14566 slave_transcoder = ffs(new_crtc_state->sync_mode_slaves_mask) - 1;
14567 return intel_get_crtc_for_pipe(dev_priv,
14568 (enum pipe)slave_transcoder);
14571 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
14572 struct intel_crtc_state *old_crtc_state,
14573 struct intel_crtc_state *new_crtc_state,
14574 struct intel_crtc *crtc)
14576 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14578 intel_crtc_disable_planes(state, crtc);
14581 * We need to disable pipe CRC before disabling the pipe,
14582 * or we race against vblank off.
14584 intel_crtc_disable_pipe_crc(crtc);
14586 dev_priv->display.crtc_disable(state, crtc);
14587 crtc->active = false;
14588 intel_fbc_disable(crtc);
14589 intel_disable_shared_dpll(old_crtc_state);
14591 /* FIXME unify this for all platforms */
14592 if (!new_crtc_state->hw.active &&
14593 !HAS_GMCH(dev_priv) &&
14594 dev_priv->display.initial_watermarks)
14595 dev_priv->display.initial_watermarks(state, crtc);
14598 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
14600 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
14601 struct intel_crtc *crtc;
14605 /* Only disable port sync slaves */
14606 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14607 new_crtc_state, i) {
14608 if (!needs_modeset(new_crtc_state))
14611 if (!old_crtc_state->hw.active)
14614 /* In case of Transcoder port Sync master slave CRTCs can be
14615 * assigned in any order and we need to make sure that
14616 * slave CRTCs are disabled first and then master CRTC since
14617 * Slave vblanks are masked till Master Vblanks.
14619 if (!is_trans_port_sync_slave(old_crtc_state))
14622 intel_pre_plane_update(state, crtc);
14623 intel_old_crtc_state_disables(state, old_crtc_state,
14624 new_crtc_state, crtc);
14625 handled |= BIT(crtc->pipe);
14628 /* Disable everything else left on */
14629 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14630 new_crtc_state, i) {
14631 if (!needs_modeset(new_crtc_state) ||
14632 (handled & BIT(crtc->pipe)))
14635 intel_pre_plane_update(state, crtc);
14636 if (old_crtc_state->hw.active)
14637 intel_old_crtc_state_disables(state, old_crtc_state,
14638 new_crtc_state, crtc);
14642 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
14644 struct intel_crtc *crtc;
14645 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14648 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14649 if (!new_crtc_state->hw.active)
14652 intel_update_crtc(crtc, state, old_crtc_state,
14657 static void intel_crtc_enable_trans_port_sync(struct intel_crtc *crtc,
14658 struct intel_atomic_state *state,
14659 struct intel_crtc_state *new_crtc_state)
14661 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14663 intel_crtc_update_active_timings(new_crtc_state);
14664 dev_priv->display.crtc_enable(state, crtc);
14665 intel_crtc_enable_pipe_crc(crtc);
14668 static void intel_set_dp_tp_ctl_normal(struct intel_crtc *crtc,
14669 struct intel_atomic_state *state)
14671 struct drm_connector *uninitialized_var(conn);
14672 struct drm_connector_state *conn_state;
14673 struct intel_dp *intel_dp;
14676 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
14677 if (conn_state->crtc == &crtc->base)
14680 intel_dp = enc_to_intel_dp(&intel_attached_encoder(conn)->base);
14681 intel_dp_stop_link_train(intel_dp);
14684 static void intel_post_crtc_enable_updates(struct intel_crtc *crtc,
14685 struct intel_atomic_state *state)
14687 struct intel_crtc_state *new_crtc_state =
14688 intel_atomic_get_new_crtc_state(state, crtc);
14689 struct intel_crtc_state *old_crtc_state =
14690 intel_atomic_get_old_crtc_state(state, crtc);
14691 struct intel_plane_state *new_plane_state =
14692 intel_atomic_get_new_plane_state(state,
14693 to_intel_plane(crtc->base.primary));
14694 bool modeset = needs_modeset(new_crtc_state);
14696 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
14697 intel_fbc_disable(crtc);
14698 else if (new_plane_state)
14699 intel_fbc_enable(crtc, new_crtc_state, new_plane_state);
14701 /* Perform vblank evasion around commit operation */
14702 intel_pipe_update_start(new_crtc_state);
14703 commit_pipe_config(state, old_crtc_state, new_crtc_state);
14704 skl_update_planes_on_crtc(state, crtc);
14705 intel_pipe_update_end(new_crtc_state);
14708 * We usually enable FIFO underrun interrupts as part of the
14709 * CRTC enable sequence during modesets. But when we inherit a
14710 * valid pipe configuration from the BIOS we need to take care
14711 * of enabling them on the CRTC's first fastset.
14713 if (new_crtc_state->update_pipe && !modeset &&
14714 old_crtc_state->hw.mode.private_flags & I915_MODE_FLAG_INHERITED)
14715 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
14718 static void intel_update_trans_port_sync_crtcs(struct intel_crtc *crtc,
14719 struct intel_atomic_state *state,
14720 struct intel_crtc_state *old_crtc_state,
14721 struct intel_crtc_state *new_crtc_state)
14723 struct intel_crtc *slave_crtc = intel_get_slave_crtc(new_crtc_state);
14724 struct intel_crtc_state *new_slave_crtc_state =
14725 intel_atomic_get_new_crtc_state(state, slave_crtc);
14726 struct intel_crtc_state *old_slave_crtc_state =
14727 intel_atomic_get_old_crtc_state(state, slave_crtc);
14729 WARN_ON(!slave_crtc || !new_slave_crtc_state ||
14730 !old_slave_crtc_state);
14732 DRM_DEBUG_KMS("Updating Transcoder Port Sync Master CRTC = %d %s and Slave CRTC %d %s\n",
14733 crtc->base.base.id, crtc->base.name, slave_crtc->base.base.id,
14734 slave_crtc->base.name);
14736 /* Enable seq for slave with with DP_TP_CTL left Idle until the
14739 intel_crtc_enable_trans_port_sync(slave_crtc,
14741 new_slave_crtc_state);
14743 /* Enable seq for master with with DP_TP_CTL left Idle */
14744 intel_crtc_enable_trans_port_sync(crtc,
14748 /* Set Slave's DP_TP_CTL to Normal */
14749 intel_set_dp_tp_ctl_normal(slave_crtc,
14752 /* Set Master's DP_TP_CTL To Normal */
14753 usleep_range(200, 400);
14754 intel_set_dp_tp_ctl_normal(crtc,
14757 /* Now do the post crtc enable for all master and slaves */
14758 intel_post_crtc_enable_updates(slave_crtc,
14760 intel_post_crtc_enable_updates(crtc,
14764 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
14766 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14767 struct intel_crtc *crtc;
14768 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14769 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
14770 u8 required_slices = state->wm_results.ddb.enabled_slices;
14771 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
14772 u8 dirty_pipes = 0;
14775 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
14776 /* ignore allocations for crtc's that have been turned off. */
14777 if (!needs_modeset(new_crtc_state) && new_crtc_state->hw.active)
14778 entries[i] = old_crtc_state->wm.skl.ddb;
14779 if (new_crtc_state->hw.active)
14780 dirty_pipes |= BIT(crtc->pipe);
14783 /* If 2nd DBuf slice required, enable it here */
14784 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
14785 icl_dbuf_slices_update(dev_priv, required_slices);
14788 * Whenever the number of active pipes changes, we need to make sure we
14789 * update the pipes in the right order so that their ddb allocations
14790 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
14791 * cause pipe underruns and other bad stuff.
14793 while (dirty_pipes) {
14794 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14795 new_crtc_state, i) {
14796 enum pipe pipe = crtc->pipe;
14797 bool modeset = needs_modeset(new_crtc_state);
14799 if ((dirty_pipes & BIT(pipe)) == 0)
14802 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
14804 INTEL_NUM_PIPES(dev_priv), i))
14807 entries[i] = new_crtc_state->wm.skl.ddb;
14808 dirty_pipes &= ~BIT(pipe);
14810 if (modeset && is_trans_port_sync_mode(new_crtc_state)) {
14811 if (is_trans_port_sync_master(new_crtc_state))
14812 intel_update_trans_port_sync_crtcs(crtc,
14819 intel_update_crtc(crtc, state, old_crtc_state,
14824 * If this is an already active pipe, it's DDB changed,
14825 * and this isn't the last pipe that needs updating
14826 * then we need to wait for a vblank to pass for the
14827 * new ddb allocation to take effect.
14829 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
14830 &old_crtc_state->wm.skl.ddb) &&
14831 !modeset && dirty_pipes)
14832 intel_wait_for_vblank(dev_priv, pipe);
14836 /* If 2nd DBuf slice is no more required disable it */
14837 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
14838 icl_dbuf_slices_update(dev_priv, required_slices);
14841 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
14843 struct intel_atomic_state *state, *next;
14844 struct llist_node *freed;
14846 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
14847 llist_for_each_entry_safe(state, next, freed, freed)
14848 drm_atomic_state_put(&state->base);
14851 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
14853 struct drm_i915_private *dev_priv =
14854 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
14856 intel_atomic_helper_free_state(dev_priv);
14859 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
14861 struct wait_queue_entry wait_fence, wait_reset;
14862 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
14864 init_wait_entry(&wait_fence, 0);
14865 init_wait_entry(&wait_reset, 0);
14867 prepare_to_wait(&intel_state->commit_ready.wait,
14868 &wait_fence, TASK_UNINTERRUPTIBLE);
14869 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
14870 I915_RESET_MODESET),
14871 &wait_reset, TASK_UNINTERRUPTIBLE);
14874 if (i915_sw_fence_done(&intel_state->commit_ready) ||
14875 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
14880 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
14881 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
14882 I915_RESET_MODESET),
14886 static void intel_atomic_cleanup_work(struct work_struct *work)
14888 struct drm_atomic_state *state =
14889 container_of(work, struct drm_atomic_state, commit_work);
14890 struct drm_i915_private *i915 = to_i915(state->dev);
14892 drm_atomic_helper_cleanup_planes(&i915->drm, state);
14893 drm_atomic_helper_commit_cleanup_done(state);
14894 drm_atomic_state_put(state);
14896 intel_atomic_helper_free_state(i915);
14899 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
14901 struct drm_device *dev = state->base.dev;
14902 struct drm_i915_private *dev_priv = to_i915(dev);
14903 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
14904 struct intel_crtc *crtc;
14905 u64 put_domains[I915_MAX_PIPES] = {};
14906 intel_wakeref_t wakeref = 0;
14909 intel_atomic_commit_fence_wait(state);
14911 drm_atomic_helper_wait_for_dependencies(&state->base);
14913 if (state->modeset)
14914 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
14916 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14917 new_crtc_state, i) {
14918 if (needs_modeset(new_crtc_state) ||
14919 new_crtc_state->update_pipe) {
14921 put_domains[crtc->pipe] =
14922 modeset_get_crtc_power_domains(new_crtc_state);
14926 intel_commit_modeset_disables(state);
14928 /* FIXME: Eventually get rid of our crtc->config pointer */
14929 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
14930 crtc->config = new_crtc_state;
14932 if (state->modeset) {
14933 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
14935 intel_set_cdclk_pre_plane_update(dev_priv,
14936 &state->cdclk.actual,
14937 &dev_priv->cdclk.actual,
14938 state->cdclk.pipe);
14941 * SKL workaround: bspec recommends we disable the SAGV when we
14942 * have more then one pipe enabled
14944 if (!intel_can_enable_sagv(state))
14945 intel_disable_sagv(dev_priv);
14947 intel_modeset_verify_disabled(dev_priv, state);
14950 /* Complete the events for pipes that have now been disabled */
14951 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14952 bool modeset = needs_modeset(new_crtc_state);
14954 /* Complete events for now disable pipes here. */
14955 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
14956 spin_lock_irq(&dev->event_lock);
14957 drm_crtc_send_vblank_event(&crtc->base,
14958 new_crtc_state->uapi.event);
14959 spin_unlock_irq(&dev->event_lock);
14961 new_crtc_state->uapi.event = NULL;
14965 if (state->modeset)
14966 intel_encoders_update_prepare(state);
14968 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
14969 dev_priv->display.commit_modeset_enables(state);
14971 if (state->modeset) {
14972 intel_encoders_update_complete(state);
14974 intel_set_cdclk_post_plane_update(dev_priv,
14975 &state->cdclk.actual,
14976 &dev_priv->cdclk.actual,
14977 state->cdclk.pipe);
14980 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
14981 * already, but still need the state for the delayed optimization. To
14983 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
14984 * - schedule that vblank worker _before_ calling hw_done
14985 * - at the start of commit_tail, cancel it _synchrously
14986 * - switch over to the vblank wait helper in the core after that since
14987 * we don't need out special handling any more.
14989 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
14991 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14992 if (new_crtc_state->hw.active &&
14993 !needs_modeset(new_crtc_state) &&
14994 !new_crtc_state->preload_luts &&
14995 (new_crtc_state->uapi.color_mgmt_changed ||
14996 new_crtc_state->update_pipe))
14997 intel_color_load_luts(new_crtc_state);
15001 * Now that the vblank has passed, we can go ahead and program the
15002 * optimal watermarks on platforms that need two-step watermark
15005 * TODO: Move this (and other cleanup) to an async worker eventually.
15007 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15008 new_crtc_state, i) {
15010 * Gen2 reports pipe underruns whenever all planes are disabled.
15011 * So re-enable underrun reporting after some planes get enabled.
15013 * We do this before .optimize_watermarks() so that we have a
15014 * chance of catching underruns with the intermediate watermarks
15015 * vs. the new plane configuration.
15017 if (IS_GEN(dev_priv, 2) && planes_enabling(old_crtc_state, new_crtc_state))
15018 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
15020 if (dev_priv->display.optimize_watermarks)
15021 dev_priv->display.optimize_watermarks(state, crtc);
15024 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15025 intel_post_plane_update(state, crtc);
15027 if (put_domains[i])
15028 modeset_put_power_domains(dev_priv, put_domains[i]);
15030 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
15033 /* Underruns don't always raise interrupts, so check manually */
15034 intel_check_cpu_fifo_underruns(dev_priv);
15035 intel_check_pch_fifo_underruns(dev_priv);
15037 if (state->modeset)
15038 intel_verify_planes(state);
15040 if (state->modeset && intel_can_enable_sagv(state))
15041 intel_enable_sagv(dev_priv);
15043 drm_atomic_helper_commit_hw_done(&state->base);
15045 if (state->modeset) {
15046 /* As one of the primary mmio accessors, KMS has a high
15047 * likelihood of triggering bugs in unclaimed access. After we
15048 * finish modesetting, see if an error has been flagged, and if
15049 * so enable debugging for the next modeset - and hope we catch
15052 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
15053 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
15055 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15058 * Defer the cleanup of the old state to a separate worker to not
15059 * impede the current task (userspace for blocking modesets) that
15060 * are executed inline. For out-of-line asynchronous modesets/flips,
15061 * deferring to a new worker seems overkill, but we would place a
15062 * schedule point (cond_resched()) here anyway to keep latencies
15065 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
15066 queue_work(system_highpri_wq, &state->base.commit_work);
15069 static void intel_atomic_commit_work(struct work_struct *work)
15071 struct intel_atomic_state *state =
15072 container_of(work, struct intel_atomic_state, base.commit_work);
15074 intel_atomic_commit_tail(state);
15077 static int __i915_sw_fence_call
15078 intel_atomic_commit_ready(struct i915_sw_fence *fence,
15079 enum i915_sw_fence_notify notify)
15081 struct intel_atomic_state *state =
15082 container_of(fence, struct intel_atomic_state, commit_ready);
15085 case FENCE_COMPLETE:
15086 /* we do blocking waits in the worker, nothing to do here */
15090 struct intel_atomic_helper *helper =
15091 &to_i915(state->base.dev)->atomic_helper;
15093 if (llist_add(&state->freed, &helper->free_list))
15094 schedule_work(&helper->free_work);
15099 return NOTIFY_DONE;
15102 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
15104 struct intel_plane_state *old_plane_state, *new_plane_state;
15105 struct intel_plane *plane;
15108 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
15109 new_plane_state, i)
15110 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
15111 to_intel_frontbuffer(new_plane_state->hw.fb),
15112 plane->frontbuffer_bit);
15115 static void assert_global_state_locked(struct drm_i915_private *dev_priv)
15117 struct intel_crtc *crtc;
15119 for_each_intel_crtc(&dev_priv->drm, crtc)
15120 drm_modeset_lock_assert_held(&crtc->base.mutex);
15123 static int intel_atomic_commit(struct drm_device *dev,
15124 struct drm_atomic_state *_state,
15127 struct intel_atomic_state *state = to_intel_atomic_state(_state);
15128 struct drm_i915_private *dev_priv = to_i915(dev);
15131 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
15133 drm_atomic_state_get(&state->base);
15134 i915_sw_fence_init(&state->commit_ready,
15135 intel_atomic_commit_ready);
15138 * The intel_legacy_cursor_update() fast path takes care
15139 * of avoiding the vblank waits for simple cursor
15140 * movement and flips. For cursor on/off and size changes,
15141 * we want to perform the vblank waits so that watermark
15142 * updates happen during the correct frames. Gen9+ have
15143 * double buffered watermarks and so shouldn't need this.
15145 * Unset state->legacy_cursor_update before the call to
15146 * drm_atomic_helper_setup_commit() because otherwise
15147 * drm_atomic_helper_wait_for_flip_done() is a noop and
15148 * we get FIFO underruns because we didn't wait
15151 * FIXME doing watermarks and fb cleanup from a vblank worker
15152 * (assuming we had any) would solve these problems.
15154 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
15155 struct intel_crtc_state *new_crtc_state;
15156 struct intel_crtc *crtc;
15159 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15160 if (new_crtc_state->wm.need_postvbl_update ||
15161 new_crtc_state->update_wm_post)
15162 state->base.legacy_cursor_update = false;
15165 ret = intel_atomic_prepare_commit(state);
15167 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
15168 i915_sw_fence_commit(&state->commit_ready);
15169 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15173 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
15175 ret = drm_atomic_helper_swap_state(&state->base, true);
15178 i915_sw_fence_commit(&state->commit_ready);
15180 drm_atomic_helper_cleanup_planes(dev, &state->base);
15181 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15184 dev_priv->wm.distrust_bios_wm = false;
15185 intel_shared_dpll_swap_state(state);
15186 intel_atomic_track_fbs(state);
15188 if (state->global_state_changed) {
15189 assert_global_state_locked(dev_priv);
15191 memcpy(dev_priv->min_cdclk, state->min_cdclk,
15192 sizeof(state->min_cdclk));
15193 memcpy(dev_priv->min_voltage_level, state->min_voltage_level,
15194 sizeof(state->min_voltage_level));
15195 dev_priv->active_pipes = state->active_pipes;
15196 dev_priv->cdclk.force_min_cdclk = state->cdclk.force_min_cdclk;
15198 intel_cdclk_swap_state(state);
15201 drm_atomic_state_get(&state->base);
15202 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
15204 i915_sw_fence_commit(&state->commit_ready);
15205 if (nonblock && state->modeset) {
15206 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
15207 } else if (nonblock) {
15208 queue_work(dev_priv->flip_wq, &state->base.commit_work);
15210 if (state->modeset)
15211 flush_workqueue(dev_priv->modeset_wq);
15212 intel_atomic_commit_tail(state);
15218 struct wait_rps_boost {
15219 struct wait_queue_entry wait;
15221 struct drm_crtc *crtc;
15222 struct i915_request *request;
15225 static int do_rps_boost(struct wait_queue_entry *_wait,
15226 unsigned mode, int sync, void *key)
15228 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
15229 struct i915_request *rq = wait->request;
15232 * If we missed the vblank, but the request is already running it
15233 * is reasonable to assume that it will complete before the next
15234 * vblank without our intervention, so leave RPS alone.
15236 if (!i915_request_started(rq))
15237 intel_rps_boost(rq);
15238 i915_request_put(rq);
15240 drm_crtc_vblank_put(wait->crtc);
15242 list_del(&wait->wait.entry);
15247 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
15248 struct dma_fence *fence)
15250 struct wait_rps_boost *wait;
15252 if (!dma_fence_is_i915(fence))
15255 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
15258 if (drm_crtc_vblank_get(crtc))
15261 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
15263 drm_crtc_vblank_put(crtc);
15267 wait->request = to_request(dma_fence_get(fence));
15270 wait->wait.func = do_rps_boost;
15271 wait->wait.flags = 0;
15273 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
15276 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
15278 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
15279 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
15280 struct drm_framebuffer *fb = plane_state->hw.fb;
15281 struct i915_vma *vma;
15283 if (plane->id == PLANE_CURSOR &&
15284 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
15285 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15286 const int align = intel_cursor_alignment(dev_priv);
15289 err = i915_gem_object_attach_phys(obj, align);
15294 vma = intel_pin_and_fence_fb_obj(fb,
15295 &plane_state->view,
15296 intel_plane_uses_fence(plane_state),
15297 &plane_state->flags);
15299 return PTR_ERR(vma);
15301 plane_state->vma = vma;
15306 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
15308 struct i915_vma *vma;
15310 vma = fetch_and_zero(&old_plane_state->vma);
15312 intel_unpin_fb_vma(vma, old_plane_state->flags);
15315 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
15317 struct i915_sched_attr attr = {
15318 .priority = I915_USER_PRIORITY(I915_PRIORITY_DISPLAY),
15321 i915_gem_object_wait_priority(obj, 0, &attr);
15325 * intel_prepare_plane_fb - Prepare fb for usage on plane
15326 * @plane: drm plane to prepare for
15327 * @_new_plane_state: the plane state being prepared
15329 * Prepares a framebuffer for usage on a display plane. Generally this
15330 * involves pinning the underlying object and updating the frontbuffer tracking
15331 * bits. Some older platforms need special physical address handling for
15334 * Returns 0 on success, negative error code on failure.
15337 intel_prepare_plane_fb(struct drm_plane *plane,
15338 struct drm_plane_state *_new_plane_state)
15340 struct intel_plane_state *new_plane_state =
15341 to_intel_plane_state(_new_plane_state);
15342 struct intel_atomic_state *intel_state =
15343 to_intel_atomic_state(new_plane_state->uapi.state);
15344 struct drm_i915_private *dev_priv = to_i915(plane->dev);
15345 struct drm_framebuffer *fb = new_plane_state->hw.fb;
15346 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15347 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
15351 struct intel_crtc_state *crtc_state =
15352 intel_atomic_get_new_crtc_state(intel_state,
15353 to_intel_crtc(plane->state->crtc));
15355 /* Big Hammer, we also need to ensure that any pending
15356 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
15357 * current scanout is retired before unpinning the old
15358 * framebuffer. Note that we rely on userspace rendering
15359 * into the buffer attached to the pipe they are waiting
15360 * on. If not, userspace generates a GPU hang with IPEHR
15361 * point to the MI_WAIT_FOR_EVENT.
15363 * This should only fail upon a hung GPU, in which case we
15364 * can safely continue.
15366 if (needs_modeset(crtc_state)) {
15367 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
15368 old_obj->base.resv, NULL,
15376 if (new_plane_state->uapi.fence) { /* explicit fencing */
15377 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
15378 new_plane_state->uapi.fence,
15379 I915_FENCE_TIMEOUT,
15388 ret = i915_gem_object_pin_pages(obj);
15392 ret = intel_plane_pin_fb(new_plane_state);
15394 i915_gem_object_unpin_pages(obj);
15398 fb_obj_bump_render_priority(obj);
15399 i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
15401 if (!new_plane_state->uapi.fence) { /* implicit fencing */
15402 struct dma_fence *fence;
15404 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
15405 obj->base.resv, NULL,
15406 false, I915_FENCE_TIMEOUT,
15411 fence = dma_resv_get_excl_rcu(obj->base.resv);
15413 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
15415 dma_fence_put(fence);
15418 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
15419 new_plane_state->uapi.fence);
15423 * We declare pageflips to be interactive and so merit a small bias
15424 * towards upclocking to deliver the frame on time. By only changing
15425 * the RPS thresholds to sample more regularly and aim for higher
15426 * clocks we can hopefully deliver low power workloads (like kodi)
15427 * that are not quite steady state without resorting to forcing
15428 * maximum clocks following a vblank miss (see do_rps_boost()).
15430 if (!intel_state->rps_interactive) {
15431 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
15432 intel_state->rps_interactive = true;
15439 * intel_cleanup_plane_fb - Cleans up an fb after plane use
15440 * @plane: drm plane to clean up for
15441 * @_old_plane_state: the state from the previous modeset
15443 * Cleans up a framebuffer that has just been removed from a plane.
15446 intel_cleanup_plane_fb(struct drm_plane *plane,
15447 struct drm_plane_state *_old_plane_state)
15449 struct intel_plane_state *old_plane_state =
15450 to_intel_plane_state(_old_plane_state);
15451 struct intel_atomic_state *intel_state =
15452 to_intel_atomic_state(old_plane_state->uapi.state);
15453 struct drm_i915_private *dev_priv = to_i915(plane->dev);
15455 if (intel_state->rps_interactive) {
15456 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
15457 intel_state->rps_interactive = false;
15460 /* Should only be called after a successful intel_prepare_plane_fb()! */
15461 intel_plane_unpin_fb(old_plane_state);
15465 * intel_plane_destroy - destroy a plane
15466 * @plane: plane to destroy
15468 * Common destruction function for all types of planes (primary, cursor,
15471 void intel_plane_destroy(struct drm_plane *plane)
15473 drm_plane_cleanup(plane);
15474 kfree(to_intel_plane(plane));
15477 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
15478 u32 format, u64 modifier)
15480 switch (modifier) {
15481 case DRM_FORMAT_MOD_LINEAR:
15482 case I915_FORMAT_MOD_X_TILED:
15489 case DRM_FORMAT_C8:
15490 case DRM_FORMAT_RGB565:
15491 case DRM_FORMAT_XRGB1555:
15492 case DRM_FORMAT_XRGB8888:
15493 return modifier == DRM_FORMAT_MOD_LINEAR ||
15494 modifier == I915_FORMAT_MOD_X_TILED;
15500 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
15501 u32 format, u64 modifier)
15503 switch (modifier) {
15504 case DRM_FORMAT_MOD_LINEAR:
15505 case I915_FORMAT_MOD_X_TILED:
15512 case DRM_FORMAT_C8:
15513 case DRM_FORMAT_RGB565:
15514 case DRM_FORMAT_XRGB8888:
15515 case DRM_FORMAT_XBGR8888:
15516 case DRM_FORMAT_ARGB8888:
15517 case DRM_FORMAT_ABGR8888:
15518 case DRM_FORMAT_XRGB2101010:
15519 case DRM_FORMAT_XBGR2101010:
15520 case DRM_FORMAT_ARGB2101010:
15521 case DRM_FORMAT_ABGR2101010:
15522 case DRM_FORMAT_XBGR16161616F:
15523 return modifier == DRM_FORMAT_MOD_LINEAR ||
15524 modifier == I915_FORMAT_MOD_X_TILED;
15530 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
15531 u32 format, u64 modifier)
15533 return modifier == DRM_FORMAT_MOD_LINEAR &&
15534 format == DRM_FORMAT_ARGB8888;
15537 static const struct drm_plane_funcs i965_plane_funcs = {
15538 .update_plane = drm_atomic_helper_update_plane,
15539 .disable_plane = drm_atomic_helper_disable_plane,
15540 .destroy = intel_plane_destroy,
15541 .atomic_duplicate_state = intel_plane_duplicate_state,
15542 .atomic_destroy_state = intel_plane_destroy_state,
15543 .format_mod_supported = i965_plane_format_mod_supported,
15546 static const struct drm_plane_funcs i8xx_plane_funcs = {
15547 .update_plane = drm_atomic_helper_update_plane,
15548 .disable_plane = drm_atomic_helper_disable_plane,
15549 .destroy = intel_plane_destroy,
15550 .atomic_duplicate_state = intel_plane_duplicate_state,
15551 .atomic_destroy_state = intel_plane_destroy_state,
15552 .format_mod_supported = i8xx_plane_format_mod_supported,
15556 intel_legacy_cursor_update(struct drm_plane *_plane,
15557 struct drm_crtc *_crtc,
15558 struct drm_framebuffer *fb,
15559 int crtc_x, int crtc_y,
15560 unsigned int crtc_w, unsigned int crtc_h,
15561 u32 src_x, u32 src_y,
15562 u32 src_w, u32 src_h,
15563 struct drm_modeset_acquire_ctx *ctx)
15565 struct intel_plane *plane = to_intel_plane(_plane);
15566 struct intel_crtc *crtc = to_intel_crtc(_crtc);
15567 struct intel_plane_state *old_plane_state =
15568 to_intel_plane_state(plane->base.state);
15569 struct intel_plane_state *new_plane_state;
15570 struct intel_crtc_state *crtc_state =
15571 to_intel_crtc_state(crtc->base.state);
15572 struct intel_crtc_state *new_crtc_state;
15576 * When crtc is inactive or there is a modeset pending,
15577 * wait for it to complete in the slowpath
15579 if (!crtc_state->hw.active || needs_modeset(crtc_state) ||
15580 crtc_state->update_pipe)
15584 * Don't do an async update if there is an outstanding commit modifying
15585 * the plane. This prevents our async update's changes from getting
15586 * overridden by a previous synchronous update's state.
15588 if (old_plane_state->uapi.commit &&
15589 !try_wait_for_completion(&old_plane_state->uapi.commit->hw_done))
15593 * If any parameters change that may affect watermarks,
15594 * take the slowpath. Only changing fb or position should be
15597 if (old_plane_state->uapi.crtc != &crtc->base ||
15598 old_plane_state->uapi.src_w != src_w ||
15599 old_plane_state->uapi.src_h != src_h ||
15600 old_plane_state->uapi.crtc_w != crtc_w ||
15601 old_plane_state->uapi.crtc_h != crtc_h ||
15602 !old_plane_state->uapi.fb != !fb)
15605 new_plane_state = to_intel_plane_state(intel_plane_duplicate_state(&plane->base));
15606 if (!new_plane_state)
15609 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(&crtc->base));
15610 if (!new_crtc_state) {
15615 drm_atomic_set_fb_for_plane(&new_plane_state->uapi, fb);
15617 new_plane_state->uapi.src_x = src_x;
15618 new_plane_state->uapi.src_y = src_y;
15619 new_plane_state->uapi.src_w = src_w;
15620 new_plane_state->uapi.src_h = src_h;
15621 new_plane_state->uapi.crtc_x = crtc_x;
15622 new_plane_state->uapi.crtc_y = crtc_y;
15623 new_plane_state->uapi.crtc_w = crtc_w;
15624 new_plane_state->uapi.crtc_h = crtc_h;
15626 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
15627 old_plane_state, new_plane_state);
15631 ret = intel_plane_pin_fb(new_plane_state);
15635 intel_frontbuffer_flush(to_intel_frontbuffer(new_plane_state->hw.fb),
15637 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
15638 to_intel_frontbuffer(new_plane_state->hw.fb),
15639 plane->frontbuffer_bit);
15641 /* Swap plane state */
15642 plane->base.state = &new_plane_state->uapi;
15645 * We cannot swap crtc_state as it may be in use by an atomic commit or
15646 * page flip that's running simultaneously. If we swap crtc_state and
15647 * destroy the old state, we will cause a use-after-free there.
15649 * Only update active_planes, which is needed for our internal
15650 * bookkeeping. Either value will do the right thing when updating
15651 * planes atomically. If the cursor was part of the atomic update then
15652 * we would have taken the slowpath.
15654 crtc_state->active_planes = new_crtc_state->active_planes;
15656 if (new_plane_state->uapi.visible)
15657 intel_update_plane(plane, crtc_state, new_plane_state);
15659 intel_disable_plane(plane, crtc_state);
15661 intel_plane_unpin_fb(old_plane_state);
15664 if (new_crtc_state)
15665 intel_crtc_destroy_state(&crtc->base, &new_crtc_state->uapi);
15667 intel_plane_destroy_state(&plane->base, &new_plane_state->uapi);
15669 intel_plane_destroy_state(&plane->base, &old_plane_state->uapi);
15673 return drm_atomic_helper_update_plane(&plane->base, &crtc->base, fb,
15674 crtc_x, crtc_y, crtc_w, crtc_h,
15675 src_x, src_y, src_w, src_h, ctx);
15678 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
15679 .update_plane = intel_legacy_cursor_update,
15680 .disable_plane = drm_atomic_helper_disable_plane,
15681 .destroy = intel_plane_destroy,
15682 .atomic_duplicate_state = intel_plane_duplicate_state,
15683 .atomic_destroy_state = intel_plane_destroy_state,
15684 .format_mod_supported = intel_cursor_format_mod_supported,
15687 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
15688 enum i9xx_plane_id i9xx_plane)
15690 if (!HAS_FBC(dev_priv))
15693 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
15694 return i9xx_plane == PLANE_A; /* tied to pipe A */
15695 else if (IS_IVYBRIDGE(dev_priv))
15696 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
15697 i9xx_plane == PLANE_C;
15698 else if (INTEL_GEN(dev_priv) >= 4)
15699 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
15701 return i9xx_plane == PLANE_A;
15704 static struct intel_plane *
15705 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
15707 struct intel_plane *plane;
15708 const struct drm_plane_funcs *plane_funcs;
15709 unsigned int supported_rotations;
15710 unsigned int possible_crtcs;
15711 const u32 *formats;
15715 if (INTEL_GEN(dev_priv) >= 9)
15716 return skl_universal_plane_create(dev_priv, pipe,
15719 plane = intel_plane_alloc();
15723 plane->pipe = pipe;
15725 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
15726 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
15728 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
15729 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
15731 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
15732 plane->id = PLANE_PRIMARY;
15733 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
15735 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
15736 if (plane->has_fbc) {
15737 struct intel_fbc *fbc = &dev_priv->fbc;
15739 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
15742 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15743 formats = vlv_primary_formats;
15744 num_formats = ARRAY_SIZE(vlv_primary_formats);
15745 } else if (INTEL_GEN(dev_priv) >= 4) {
15747 * WaFP16GammaEnabling:ivb
15748 * "Workaround : When using the 64-bit format, the plane
15749 * output on each color channel has one quarter amplitude.
15750 * It can be brought up to full amplitude by using pipe
15751 * gamma correction or pipe color space conversion to
15752 * multiply the plane output by four."
15754 * There is no dedicated plane gamma for the primary plane,
15755 * and using the pipe gamma/csc could conflict with other
15756 * planes, so we choose not to expose fp16 on IVB primary
15757 * planes. HSW primary planes no longer have this problem.
15759 if (IS_IVYBRIDGE(dev_priv)) {
15760 formats = ivb_primary_formats;
15761 num_formats = ARRAY_SIZE(ivb_primary_formats);
15763 formats = i965_primary_formats;
15764 num_formats = ARRAY_SIZE(i965_primary_formats);
15767 formats = i8xx_primary_formats;
15768 num_formats = ARRAY_SIZE(i8xx_primary_formats);
15771 if (INTEL_GEN(dev_priv) >= 4)
15772 plane_funcs = &i965_plane_funcs;
15774 plane_funcs = &i8xx_plane_funcs;
15776 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
15777 plane->min_cdclk = vlv_plane_min_cdclk;
15778 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
15779 plane->min_cdclk = hsw_plane_min_cdclk;
15780 else if (IS_IVYBRIDGE(dev_priv))
15781 plane->min_cdclk = ivb_plane_min_cdclk;
15783 plane->min_cdclk = i9xx_plane_min_cdclk;
15785 plane->max_stride = i9xx_plane_max_stride;
15786 plane->update_plane = i9xx_update_plane;
15787 plane->disable_plane = i9xx_disable_plane;
15788 plane->get_hw_state = i9xx_plane_get_hw_state;
15789 plane->check_plane = i9xx_plane_check;
15791 possible_crtcs = BIT(pipe);
15793 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
15794 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
15795 possible_crtcs, plane_funcs,
15796 formats, num_formats,
15797 i9xx_format_modifiers,
15798 DRM_PLANE_TYPE_PRIMARY,
15799 "primary %c", pipe_name(pipe));
15801 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
15802 possible_crtcs, plane_funcs,
15803 formats, num_formats,
15804 i9xx_format_modifiers,
15805 DRM_PLANE_TYPE_PRIMARY,
15807 plane_name(plane->i9xx_plane));
15811 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
15812 supported_rotations =
15813 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
15814 DRM_MODE_REFLECT_X;
15815 } else if (INTEL_GEN(dev_priv) >= 4) {
15816 supported_rotations =
15817 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
15819 supported_rotations = DRM_MODE_ROTATE_0;
15822 if (INTEL_GEN(dev_priv) >= 4)
15823 drm_plane_create_rotation_property(&plane->base,
15825 supported_rotations);
15828 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
15830 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
15835 intel_plane_free(plane);
15837 return ERR_PTR(ret);
15840 static struct intel_plane *
15841 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
15844 unsigned int possible_crtcs;
15845 struct intel_plane *cursor;
15848 cursor = intel_plane_alloc();
15849 if (IS_ERR(cursor))
15852 cursor->pipe = pipe;
15853 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
15854 cursor->id = PLANE_CURSOR;
15855 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
15857 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15858 cursor->max_stride = i845_cursor_max_stride;
15859 cursor->update_plane = i845_update_cursor;
15860 cursor->disable_plane = i845_disable_cursor;
15861 cursor->get_hw_state = i845_cursor_get_hw_state;
15862 cursor->check_plane = i845_check_cursor;
15864 cursor->max_stride = i9xx_cursor_max_stride;
15865 cursor->update_plane = i9xx_update_cursor;
15866 cursor->disable_plane = i9xx_disable_cursor;
15867 cursor->get_hw_state = i9xx_cursor_get_hw_state;
15868 cursor->check_plane = i9xx_check_cursor;
15871 cursor->cursor.base = ~0;
15872 cursor->cursor.cntl = ~0;
15874 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
15875 cursor->cursor.size = ~0;
15877 possible_crtcs = BIT(pipe);
15879 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
15880 possible_crtcs, &intel_cursor_plane_funcs,
15881 intel_cursor_formats,
15882 ARRAY_SIZE(intel_cursor_formats),
15883 cursor_format_modifiers,
15884 DRM_PLANE_TYPE_CURSOR,
15885 "cursor %c", pipe_name(pipe));
15889 if (INTEL_GEN(dev_priv) >= 4)
15890 drm_plane_create_rotation_property(&cursor->base,
15892 DRM_MODE_ROTATE_0 |
15893 DRM_MODE_ROTATE_180);
15895 zpos = RUNTIME_INFO(dev_priv)->num_sprites[pipe] + 1;
15896 drm_plane_create_zpos_immutable_property(&cursor->base, zpos);
15898 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
15903 intel_plane_free(cursor);
15905 return ERR_PTR(ret);
15908 #define INTEL_CRTC_FUNCS \
15909 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
15910 .set_config = drm_atomic_helper_set_config, \
15911 .destroy = intel_crtc_destroy, \
15912 .page_flip = drm_atomic_helper_page_flip, \
15913 .atomic_duplicate_state = intel_crtc_duplicate_state, \
15914 .atomic_destroy_state = intel_crtc_destroy_state, \
15915 .set_crc_source = intel_crtc_set_crc_source, \
15916 .verify_crc_source = intel_crtc_verify_crc_source, \
15917 .get_crc_sources = intel_crtc_get_crc_sources
15919 static const struct drm_crtc_funcs bdw_crtc_funcs = {
15922 .get_vblank_counter = g4x_get_vblank_counter,
15923 .enable_vblank = bdw_enable_vblank,
15924 .disable_vblank = bdw_disable_vblank,
15927 static const struct drm_crtc_funcs ilk_crtc_funcs = {
15930 .get_vblank_counter = g4x_get_vblank_counter,
15931 .enable_vblank = ilk_enable_vblank,
15932 .disable_vblank = ilk_disable_vblank,
15935 static const struct drm_crtc_funcs g4x_crtc_funcs = {
15938 .get_vblank_counter = g4x_get_vblank_counter,
15939 .enable_vblank = i965_enable_vblank,
15940 .disable_vblank = i965_disable_vblank,
15943 static const struct drm_crtc_funcs i965_crtc_funcs = {
15946 .get_vblank_counter = i915_get_vblank_counter,
15947 .enable_vblank = i965_enable_vblank,
15948 .disable_vblank = i965_disable_vblank,
15951 static const struct drm_crtc_funcs i915gm_crtc_funcs = {
15954 .get_vblank_counter = i915_get_vblank_counter,
15955 .enable_vblank = i915gm_enable_vblank,
15956 .disable_vblank = i915gm_disable_vblank,
15959 static const struct drm_crtc_funcs i915_crtc_funcs = {
15962 .get_vblank_counter = i915_get_vblank_counter,
15963 .enable_vblank = i8xx_enable_vblank,
15964 .disable_vblank = i8xx_disable_vblank,
15967 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
15970 /* no hw vblank counter */
15971 .enable_vblank = i8xx_enable_vblank,
15972 .disable_vblank = i8xx_disable_vblank,
15975 static struct intel_crtc *intel_crtc_alloc(void)
15977 struct intel_crtc_state *crtc_state;
15978 struct intel_crtc *crtc;
15980 crtc = kzalloc(sizeof(*crtc), GFP_KERNEL);
15982 return ERR_PTR(-ENOMEM);
15984 crtc_state = intel_crtc_state_alloc(crtc);
15987 return ERR_PTR(-ENOMEM);
15990 crtc->base.state = &crtc_state->uapi;
15991 crtc->config = crtc_state;
15996 static void intel_crtc_free(struct intel_crtc *crtc)
15998 intel_crtc_destroy_state(&crtc->base, crtc->base.state);
16002 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
16004 struct intel_plane *primary, *cursor;
16005 const struct drm_crtc_funcs *funcs;
16006 struct intel_crtc *crtc;
16009 crtc = intel_crtc_alloc();
16011 return PTR_ERR(crtc);
16014 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[pipe];
16016 primary = intel_primary_plane_create(dev_priv, pipe);
16017 if (IS_ERR(primary)) {
16018 ret = PTR_ERR(primary);
16021 crtc->plane_ids_mask |= BIT(primary->id);
16023 for_each_sprite(dev_priv, pipe, sprite) {
16024 struct intel_plane *plane;
16026 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
16027 if (IS_ERR(plane)) {
16028 ret = PTR_ERR(plane);
16031 crtc->plane_ids_mask |= BIT(plane->id);
16034 cursor = intel_cursor_plane_create(dev_priv, pipe);
16035 if (IS_ERR(cursor)) {
16036 ret = PTR_ERR(cursor);
16039 crtc->plane_ids_mask |= BIT(cursor->id);
16041 if (HAS_GMCH(dev_priv)) {
16042 if (IS_CHERRYVIEW(dev_priv) ||
16043 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
16044 funcs = &g4x_crtc_funcs;
16045 else if (IS_GEN(dev_priv, 4))
16046 funcs = &i965_crtc_funcs;
16047 else if (IS_I945GM(dev_priv) || IS_I915GM(dev_priv))
16048 funcs = &i915gm_crtc_funcs;
16049 else if (IS_GEN(dev_priv, 3))
16050 funcs = &i915_crtc_funcs;
16052 funcs = &i8xx_crtc_funcs;
16054 if (INTEL_GEN(dev_priv) >= 8)
16055 funcs = &bdw_crtc_funcs;
16057 funcs = &ilk_crtc_funcs;
16060 ret = drm_crtc_init_with_planes(&dev_priv->drm, &crtc->base,
16061 &primary->base, &cursor->base,
16062 funcs, "pipe %c", pipe_name(pipe));
16066 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
16067 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
16068 dev_priv->pipe_to_crtc_mapping[pipe] = crtc;
16070 if (INTEL_GEN(dev_priv) < 9) {
16071 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
16073 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
16074 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
16075 dev_priv->plane_to_crtc_mapping[i9xx_plane] = crtc;
16078 intel_color_init(crtc);
16080 WARN_ON(drm_crtc_index(&crtc->base) != crtc->pipe);
16085 intel_crtc_free(crtc);
16090 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
16091 struct drm_file *file)
16093 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
16094 struct drm_crtc *drmmode_crtc;
16095 struct intel_crtc *crtc;
16097 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
16101 crtc = to_intel_crtc(drmmode_crtc);
16102 pipe_from_crtc_id->pipe = crtc->pipe;
16107 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
16109 struct drm_device *dev = encoder->base.dev;
16110 struct intel_encoder *source_encoder;
16111 u32 possible_clones = 0;
16113 for_each_intel_encoder(dev, source_encoder) {
16114 if (encoders_cloneable(encoder, source_encoder))
16115 possible_clones |= drm_encoder_mask(&source_encoder->base);
16118 return possible_clones;
16121 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
16123 struct drm_device *dev = encoder->base.dev;
16124 struct intel_crtc *crtc;
16125 u32 possible_crtcs = 0;
16127 for_each_intel_crtc(dev, crtc) {
16128 if (encoder->pipe_mask & BIT(crtc->pipe))
16129 possible_crtcs |= drm_crtc_mask(&crtc->base);
16132 return possible_crtcs;
16135 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
16137 if (!IS_MOBILE(dev_priv))
16140 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
16143 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
16149 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
16151 if (INTEL_GEN(dev_priv) >= 9)
16154 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
16157 if (HAS_PCH_LPT_H(dev_priv) &&
16158 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
16161 /* DDI E can't be used if DDI A requires 4 lanes */
16162 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
16165 if (!dev_priv->vbt.int_crt_support)
16171 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
16176 if (HAS_DDI(dev_priv))
16179 * This w/a is needed at least on CPT/PPT, but to be sure apply it
16180 * everywhere where registers can be write protected.
16182 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16187 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
16188 u32 val = I915_READ(PP_CONTROL(pps_idx));
16190 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
16191 I915_WRITE(PP_CONTROL(pps_idx), val);
16195 static void intel_pps_init(struct drm_i915_private *dev_priv)
16197 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
16198 dev_priv->pps_mmio_base = PCH_PPS_BASE;
16199 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16200 dev_priv->pps_mmio_base = VLV_PPS_BASE;
16202 dev_priv->pps_mmio_base = PPS_BASE;
16204 intel_pps_unlock_regs_wa(dev_priv);
16207 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
16209 struct intel_encoder *encoder;
16210 bool dpd_is_edp = false;
16212 intel_pps_init(dev_priv);
16214 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
16217 if (INTEL_GEN(dev_priv) >= 12) {
16218 intel_ddi_init(dev_priv, PORT_A);
16219 intel_ddi_init(dev_priv, PORT_B);
16220 intel_ddi_init(dev_priv, PORT_D);
16221 intel_ddi_init(dev_priv, PORT_E);
16222 intel_ddi_init(dev_priv, PORT_F);
16223 intel_ddi_init(dev_priv, PORT_G);
16224 intel_ddi_init(dev_priv, PORT_H);
16225 intel_ddi_init(dev_priv, PORT_I);
16226 icl_dsi_init(dev_priv);
16227 } else if (IS_ELKHARTLAKE(dev_priv)) {
16228 intel_ddi_init(dev_priv, PORT_A);
16229 intel_ddi_init(dev_priv, PORT_B);
16230 intel_ddi_init(dev_priv, PORT_C);
16231 intel_ddi_init(dev_priv, PORT_D);
16232 icl_dsi_init(dev_priv);
16233 } else if (IS_GEN(dev_priv, 11)) {
16234 intel_ddi_init(dev_priv, PORT_A);
16235 intel_ddi_init(dev_priv, PORT_B);
16236 intel_ddi_init(dev_priv, PORT_C);
16237 intel_ddi_init(dev_priv, PORT_D);
16238 intel_ddi_init(dev_priv, PORT_E);
16240 * On some ICL SKUs port F is not present. No strap bits for
16241 * this, so rely on VBT.
16242 * Work around broken VBTs on SKUs known to have no port F.
16244 if (IS_ICL_WITH_PORT_F(dev_priv) &&
16245 intel_bios_is_port_present(dev_priv, PORT_F))
16246 intel_ddi_init(dev_priv, PORT_F);
16248 icl_dsi_init(dev_priv);
16249 } else if (IS_GEN9_LP(dev_priv)) {
16251 * FIXME: Broxton doesn't support port detection via the
16252 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
16253 * detect the ports.
16255 intel_ddi_init(dev_priv, PORT_A);
16256 intel_ddi_init(dev_priv, PORT_B);
16257 intel_ddi_init(dev_priv, PORT_C);
16259 vlv_dsi_init(dev_priv);
16260 } else if (HAS_DDI(dev_priv)) {
16263 if (intel_ddi_crt_present(dev_priv))
16264 intel_crt_init(dev_priv);
16267 * Haswell uses DDI functions to detect digital outputs.
16268 * On SKL pre-D0 the strap isn't connected, so we assume
16271 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
16272 /* WaIgnoreDDIAStrap: skl */
16273 if (found || IS_GEN9_BC(dev_priv))
16274 intel_ddi_init(dev_priv, PORT_A);
16276 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
16278 found = I915_READ(SFUSE_STRAP);
16280 if (found & SFUSE_STRAP_DDIB_DETECTED)
16281 intel_ddi_init(dev_priv, PORT_B);
16282 if (found & SFUSE_STRAP_DDIC_DETECTED)
16283 intel_ddi_init(dev_priv, PORT_C);
16284 if (found & SFUSE_STRAP_DDID_DETECTED)
16285 intel_ddi_init(dev_priv, PORT_D);
16286 if (found & SFUSE_STRAP_DDIF_DETECTED)
16287 intel_ddi_init(dev_priv, PORT_F);
16289 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
16291 if (IS_GEN9_BC(dev_priv) &&
16292 intel_bios_is_port_present(dev_priv, PORT_E))
16293 intel_ddi_init(dev_priv, PORT_E);
16295 } else if (HAS_PCH_SPLIT(dev_priv)) {
16299 * intel_edp_init_connector() depends on this completing first,
16300 * to prevent the registration of both eDP and LVDS and the
16301 * incorrect sharing of the PPS.
16303 intel_lvds_init(dev_priv);
16304 intel_crt_init(dev_priv);
16306 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
16308 if (ilk_has_edp_a(dev_priv))
16309 intel_dp_init(dev_priv, DP_A, PORT_A);
16311 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
16312 /* PCH SDVOB multiplex with HDMIB */
16313 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
16315 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
16316 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
16317 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
16320 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
16321 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
16323 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
16324 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
16326 if (I915_READ(PCH_DP_C) & DP_DETECTED)
16327 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
16329 if (I915_READ(PCH_DP_D) & DP_DETECTED)
16330 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
16331 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16332 bool has_edp, has_port;
16334 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
16335 intel_crt_init(dev_priv);
16338 * The DP_DETECTED bit is the latched state of the DDC
16339 * SDA pin at boot. However since eDP doesn't require DDC
16340 * (no way to plug in a DP->HDMI dongle) the DDC pins for
16341 * eDP ports may have been muxed to an alternate function.
16342 * Thus we can't rely on the DP_DETECTED bit alone to detect
16343 * eDP ports. Consult the VBT as well as DP_DETECTED to
16344 * detect eDP ports.
16346 * Sadly the straps seem to be missing sometimes even for HDMI
16347 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
16348 * and VBT for the presence of the port. Additionally we can't
16349 * trust the port type the VBT declares as we've seen at least
16350 * HDMI ports that the VBT claim are DP or eDP.
16352 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
16353 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
16354 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
16355 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
16356 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
16357 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
16359 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
16360 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
16361 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
16362 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
16363 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
16364 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
16366 if (IS_CHERRYVIEW(dev_priv)) {
16368 * eDP not supported on port D,
16369 * so no need to worry about it
16371 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
16372 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
16373 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
16374 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
16375 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
16378 vlv_dsi_init(dev_priv);
16379 } else if (IS_PINEVIEW(dev_priv)) {
16380 intel_lvds_init(dev_priv);
16381 intel_crt_init(dev_priv);
16382 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
16383 bool found = false;
16385 if (IS_MOBILE(dev_priv))
16386 intel_lvds_init(dev_priv);
16388 intel_crt_init(dev_priv);
16390 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
16391 DRM_DEBUG_KMS("probing SDVOB\n");
16392 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
16393 if (!found && IS_G4X(dev_priv)) {
16394 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
16395 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
16398 if (!found && IS_G4X(dev_priv))
16399 intel_dp_init(dev_priv, DP_B, PORT_B);
16402 /* Before G4X SDVOC doesn't have its own detect register */
16404 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
16405 DRM_DEBUG_KMS("probing SDVOC\n");
16406 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
16409 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
16411 if (IS_G4X(dev_priv)) {
16412 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
16413 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
16415 if (IS_G4X(dev_priv))
16416 intel_dp_init(dev_priv, DP_C, PORT_C);
16419 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
16420 intel_dp_init(dev_priv, DP_D, PORT_D);
16422 if (SUPPORTS_TV(dev_priv))
16423 intel_tv_init(dev_priv);
16424 } else if (IS_GEN(dev_priv, 2)) {
16425 if (IS_I85X(dev_priv))
16426 intel_lvds_init(dev_priv);
16428 intel_crt_init(dev_priv);
16429 intel_dvo_init(dev_priv);
16432 intel_psr_init(dev_priv);
16434 for_each_intel_encoder(&dev_priv->drm, encoder) {
16435 encoder->base.possible_crtcs =
16436 intel_encoder_possible_crtcs(encoder);
16437 encoder->base.possible_clones =
16438 intel_encoder_possible_clones(encoder);
16441 intel_init_pch_refclk(dev_priv);
16443 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
16446 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
16448 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
16450 drm_framebuffer_cleanup(fb);
16451 intel_frontbuffer_put(intel_fb->frontbuffer);
16456 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
16457 struct drm_file *file,
16458 unsigned int *handle)
16460 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16462 if (obj->userptr.mm) {
16463 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
16467 return drm_gem_handle_create(file, &obj->base, handle);
16470 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
16471 struct drm_file *file,
16472 unsigned flags, unsigned color,
16473 struct drm_clip_rect *clips,
16474 unsigned num_clips)
16476 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16478 i915_gem_object_flush_if_display(obj);
16479 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
16484 static const struct drm_framebuffer_funcs intel_fb_funcs = {
16485 .destroy = intel_user_framebuffer_destroy,
16486 .create_handle = intel_user_framebuffer_create_handle,
16487 .dirty = intel_user_framebuffer_dirty,
16490 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
16491 struct drm_i915_gem_object *obj,
16492 struct drm_mode_fb_cmd2 *mode_cmd)
16494 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
16495 struct drm_framebuffer *fb = &intel_fb->base;
16497 unsigned int tiling, stride;
16501 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
16502 if (!intel_fb->frontbuffer)
16505 i915_gem_object_lock(obj);
16506 tiling = i915_gem_object_get_tiling(obj);
16507 stride = i915_gem_object_get_stride(obj);
16508 i915_gem_object_unlock(obj);
16510 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
16512 * If there's a fence, enforce that
16513 * the fb modifier and tiling mode match.
16515 if (tiling != I915_TILING_NONE &&
16516 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
16517 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
16521 if (tiling == I915_TILING_X) {
16522 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
16523 } else if (tiling == I915_TILING_Y) {
16524 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
16529 if (!drm_any_plane_has_format(&dev_priv->drm,
16530 mode_cmd->pixel_format,
16531 mode_cmd->modifier[0])) {
16532 struct drm_format_name_buf format_name;
16534 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
16535 drm_get_format_name(mode_cmd->pixel_format,
16537 mode_cmd->modifier[0]);
16542 * gen2/3 display engine uses the fence if present,
16543 * so the tiling mode must match the fb modifier exactly.
16545 if (INTEL_GEN(dev_priv) < 4 &&
16546 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
16547 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
16551 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
16552 mode_cmd->modifier[0]);
16553 if (mode_cmd->pitches[0] > max_stride) {
16554 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
16555 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
16556 "tiled" : "linear",
16557 mode_cmd->pitches[0], max_stride);
16562 * If there's a fence, enforce that
16563 * the fb pitch and fence stride match.
16565 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
16566 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
16567 mode_cmd->pitches[0], stride);
16571 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
16572 if (mode_cmd->offsets[0] != 0)
16575 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
16577 for (i = 0; i < fb->format->num_planes; i++) {
16578 u32 stride_alignment;
16580 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
16581 DRM_DEBUG_KMS("bad plane %d handle\n", i);
16585 stride_alignment = intel_fb_stride_alignment(fb, i);
16586 if (fb->pitches[i] & (stride_alignment - 1)) {
16587 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
16588 i, fb->pitches[i], stride_alignment);
16592 if (is_gen12_ccs_plane(fb, i)) {
16593 int ccs_aux_stride = gen12_ccs_aux_stride(fb, i);
16595 if (fb->pitches[i] != ccs_aux_stride) {
16596 DRM_DEBUG_KMS("ccs aux plane %d pitch (%d) must be %d\n",
16598 fb->pitches[i], ccs_aux_stride);
16603 fb->obj[i] = &obj->base;
16606 ret = intel_fill_fb_info(dev_priv, fb);
16610 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
16612 DRM_ERROR("framebuffer init failed %d\n", ret);
16619 intel_frontbuffer_put(intel_fb->frontbuffer);
16623 static struct drm_framebuffer *
16624 intel_user_framebuffer_create(struct drm_device *dev,
16625 struct drm_file *filp,
16626 const struct drm_mode_fb_cmd2 *user_mode_cmd)
16628 struct drm_framebuffer *fb;
16629 struct drm_i915_gem_object *obj;
16630 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
16632 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
16634 return ERR_PTR(-ENOENT);
16636 fb = intel_framebuffer_create(obj, &mode_cmd);
16637 i915_gem_object_put(obj);
16642 static void intel_atomic_state_free(struct drm_atomic_state *state)
16644 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
16646 drm_atomic_state_default_release(state);
16648 i915_sw_fence_fini(&intel_state->commit_ready);
16653 static enum drm_mode_status
16654 intel_mode_valid(struct drm_device *dev,
16655 const struct drm_display_mode *mode)
16657 struct drm_i915_private *dev_priv = to_i915(dev);
16658 int hdisplay_max, htotal_max;
16659 int vdisplay_max, vtotal_max;
16662 * Can't reject DBLSCAN here because Xorg ddxen can add piles
16663 * of DBLSCAN modes to the output's mode list when they detect
16664 * the scaling mode property on the connector. And they don't
16665 * ask the kernel to validate those modes in any way until
16666 * modeset time at which point the client gets a protocol error.
16667 * So in order to not upset those clients we silently ignore the
16668 * DBLSCAN flag on such connectors. For other connectors we will
16669 * reject modes with the DBLSCAN flag in encoder->compute_config().
16670 * And we always reject DBLSCAN modes in connector->mode_valid()
16671 * as we never want such modes on the connector's mode list.
16674 if (mode->vscan > 1)
16675 return MODE_NO_VSCAN;
16677 if (mode->flags & DRM_MODE_FLAG_HSKEW)
16678 return MODE_H_ILLEGAL;
16680 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
16681 DRM_MODE_FLAG_NCSYNC |
16682 DRM_MODE_FLAG_PCSYNC))
16685 if (mode->flags & (DRM_MODE_FLAG_BCAST |
16686 DRM_MODE_FLAG_PIXMUX |
16687 DRM_MODE_FLAG_CLKDIV2))
16690 /* Transcoder timing limits */
16691 if (INTEL_GEN(dev_priv) >= 11) {
16692 hdisplay_max = 16384;
16693 vdisplay_max = 8192;
16694 htotal_max = 16384;
16696 } else if (INTEL_GEN(dev_priv) >= 9 ||
16697 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
16698 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
16699 vdisplay_max = 4096;
16702 } else if (INTEL_GEN(dev_priv) >= 3) {
16703 hdisplay_max = 4096;
16704 vdisplay_max = 4096;
16708 hdisplay_max = 2048;
16709 vdisplay_max = 2048;
16714 if (mode->hdisplay > hdisplay_max ||
16715 mode->hsync_start > htotal_max ||
16716 mode->hsync_end > htotal_max ||
16717 mode->htotal > htotal_max)
16718 return MODE_H_ILLEGAL;
16720 if (mode->vdisplay > vdisplay_max ||
16721 mode->vsync_start > vtotal_max ||
16722 mode->vsync_end > vtotal_max ||
16723 mode->vtotal > vtotal_max)
16724 return MODE_V_ILLEGAL;
16726 if (INTEL_GEN(dev_priv) >= 5) {
16727 if (mode->hdisplay < 64 ||
16728 mode->htotal - mode->hdisplay < 32)
16729 return MODE_H_ILLEGAL;
16731 if (mode->vtotal - mode->vdisplay < 5)
16732 return MODE_V_ILLEGAL;
16734 if (mode->htotal - mode->hdisplay < 32)
16735 return MODE_H_ILLEGAL;
16737 if (mode->vtotal - mode->vdisplay < 3)
16738 return MODE_V_ILLEGAL;
16744 enum drm_mode_status
16745 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
16746 const struct drm_display_mode *mode)
16748 int plane_width_max, plane_height_max;
16751 * intel_mode_valid() should be
16752 * sufficient on older platforms.
16754 if (INTEL_GEN(dev_priv) < 9)
16758 * Most people will probably want a fullscreen
16759 * plane so let's not advertize modes that are
16760 * too big for that.
16762 if (INTEL_GEN(dev_priv) >= 11) {
16763 plane_width_max = 5120;
16764 plane_height_max = 4320;
16766 plane_width_max = 5120;
16767 plane_height_max = 4096;
16770 if (mode->hdisplay > plane_width_max)
16771 return MODE_H_ILLEGAL;
16773 if (mode->vdisplay > plane_height_max)
16774 return MODE_V_ILLEGAL;
16779 static const struct drm_mode_config_funcs intel_mode_funcs = {
16780 .fb_create = intel_user_framebuffer_create,
16781 .get_format_info = intel_get_format_info,
16782 .output_poll_changed = intel_fbdev_output_poll_changed,
16783 .mode_valid = intel_mode_valid,
16784 .atomic_check = intel_atomic_check,
16785 .atomic_commit = intel_atomic_commit,
16786 .atomic_state_alloc = intel_atomic_state_alloc,
16787 .atomic_state_clear = intel_atomic_state_clear,
16788 .atomic_state_free = intel_atomic_state_free,
16792 * intel_init_display_hooks - initialize the display modesetting hooks
16793 * @dev_priv: device private
16795 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
16797 intel_init_cdclk_hooks(dev_priv);
16799 if (INTEL_GEN(dev_priv) >= 9) {
16800 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
16801 dev_priv->display.get_initial_plane_config =
16802 skylake_get_initial_plane_config;
16803 dev_priv->display.crtc_compute_clock =
16804 haswell_crtc_compute_clock;
16805 dev_priv->display.crtc_enable = haswell_crtc_enable;
16806 dev_priv->display.crtc_disable = haswell_crtc_disable;
16807 } else if (HAS_DDI(dev_priv)) {
16808 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
16809 dev_priv->display.get_initial_plane_config =
16810 i9xx_get_initial_plane_config;
16811 dev_priv->display.crtc_compute_clock =
16812 haswell_crtc_compute_clock;
16813 dev_priv->display.crtc_enable = haswell_crtc_enable;
16814 dev_priv->display.crtc_disable = haswell_crtc_disable;
16815 } else if (HAS_PCH_SPLIT(dev_priv)) {
16816 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
16817 dev_priv->display.get_initial_plane_config =
16818 i9xx_get_initial_plane_config;
16819 dev_priv->display.crtc_compute_clock =
16820 ironlake_crtc_compute_clock;
16821 dev_priv->display.crtc_enable = ironlake_crtc_enable;
16822 dev_priv->display.crtc_disable = ironlake_crtc_disable;
16823 } else if (IS_CHERRYVIEW(dev_priv)) {
16824 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16825 dev_priv->display.get_initial_plane_config =
16826 i9xx_get_initial_plane_config;
16827 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
16828 dev_priv->display.crtc_enable = valleyview_crtc_enable;
16829 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16830 } else if (IS_VALLEYVIEW(dev_priv)) {
16831 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16832 dev_priv->display.get_initial_plane_config =
16833 i9xx_get_initial_plane_config;
16834 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
16835 dev_priv->display.crtc_enable = valleyview_crtc_enable;
16836 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16837 } else if (IS_G4X(dev_priv)) {
16838 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16839 dev_priv->display.get_initial_plane_config =
16840 i9xx_get_initial_plane_config;
16841 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
16842 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16843 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16844 } else if (IS_PINEVIEW(dev_priv)) {
16845 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16846 dev_priv->display.get_initial_plane_config =
16847 i9xx_get_initial_plane_config;
16848 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
16849 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16850 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16851 } else if (!IS_GEN(dev_priv, 2)) {
16852 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16853 dev_priv->display.get_initial_plane_config =
16854 i9xx_get_initial_plane_config;
16855 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
16856 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16857 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16859 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
16860 dev_priv->display.get_initial_plane_config =
16861 i9xx_get_initial_plane_config;
16862 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
16863 dev_priv->display.crtc_enable = i9xx_crtc_enable;
16864 dev_priv->display.crtc_disable = i9xx_crtc_disable;
16867 if (IS_GEN(dev_priv, 5)) {
16868 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
16869 } else if (IS_GEN(dev_priv, 6)) {
16870 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
16871 } else if (IS_IVYBRIDGE(dev_priv)) {
16872 /* FIXME: detect B0+ stepping and use auto training */
16873 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
16876 if (INTEL_GEN(dev_priv) >= 9)
16877 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
16879 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
16883 void intel_modeset_init_hw(struct drm_i915_private *i915)
16885 intel_update_cdclk(i915);
16886 intel_dump_cdclk_state(&i915->cdclk.hw, "Current CDCLK");
16887 i915->cdclk.logical = i915->cdclk.actual = i915->cdclk.hw;
16891 * Calculate what we think the watermarks should be for the state we've read
16892 * out of the hardware and then immediately program those watermarks so that
16893 * we ensure the hardware settings match our internal state.
16895 * We can calculate what we think WM's should be by creating a duplicate of the
16896 * current state (which was constructed during hardware readout) and running it
16897 * through the atomic check code to calculate new watermark values in the
16900 static void sanitize_watermarks(struct drm_device *dev)
16902 struct drm_i915_private *dev_priv = to_i915(dev);
16903 struct drm_atomic_state *state;
16904 struct intel_atomic_state *intel_state;
16905 struct intel_crtc *crtc;
16906 struct intel_crtc_state *crtc_state;
16907 struct drm_modeset_acquire_ctx ctx;
16911 /* Only supported on platforms that use atomic watermark design */
16912 if (!dev_priv->display.optimize_watermarks)
16916 * We need to hold connection_mutex before calling duplicate_state so
16917 * that the connector loop is protected.
16919 drm_modeset_acquire_init(&ctx, 0);
16921 ret = drm_modeset_lock_all_ctx(dev, &ctx);
16922 if (ret == -EDEADLK) {
16923 drm_modeset_backoff(&ctx);
16925 } else if (WARN_ON(ret)) {
16929 state = drm_atomic_helper_duplicate_state(dev, &ctx);
16930 if (WARN_ON(IS_ERR(state)))
16933 intel_state = to_intel_atomic_state(state);
16936 * Hardware readout is the only time we don't want to calculate
16937 * intermediate watermarks (since we don't trust the current
16940 if (!HAS_GMCH(dev_priv))
16941 intel_state->skip_intermediate_wm = true;
16943 ret = intel_atomic_check(dev, state);
16946 * If we fail here, it means that the hardware appears to be
16947 * programmed in a way that shouldn't be possible, given our
16948 * understanding of watermark requirements. This might mean a
16949 * mistake in the hardware readout code or a mistake in the
16950 * watermark calculations for a given platform. Raise a WARN
16951 * so that this is noticeable.
16953 * If this actually happens, we'll have to just leave the
16954 * BIOS-programmed watermarks untouched and hope for the best.
16956 WARN(true, "Could not determine valid watermarks for inherited state\n");
16960 /* Write calculated watermark values back */
16961 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
16962 crtc_state->wm.need_postvbl_update = true;
16963 dev_priv->display.optimize_watermarks(intel_state, crtc);
16965 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
16969 drm_atomic_state_put(state);
16971 drm_modeset_drop_locks(&ctx);
16972 drm_modeset_acquire_fini(&ctx);
16975 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
16977 if (IS_GEN(dev_priv, 5)) {
16979 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
16981 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
16982 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
16983 dev_priv->fdi_pll_freq = 270000;
16988 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
16991 static int intel_initial_commit(struct drm_device *dev)
16993 struct drm_atomic_state *state = NULL;
16994 struct drm_modeset_acquire_ctx ctx;
16995 struct intel_crtc *crtc;
16998 state = drm_atomic_state_alloc(dev);
17002 drm_modeset_acquire_init(&ctx, 0);
17005 state->acquire_ctx = &ctx;
17007 for_each_intel_crtc(dev, crtc) {
17008 struct intel_crtc_state *crtc_state =
17009 intel_atomic_get_crtc_state(state, crtc);
17011 if (IS_ERR(crtc_state)) {
17012 ret = PTR_ERR(crtc_state);
17016 if (crtc_state->hw.active) {
17017 ret = drm_atomic_add_affected_planes(state, &crtc->base);
17022 * FIXME hack to force a LUT update to avoid the
17023 * plane update forcing the pipe gamma on without
17024 * having a proper LUT loaded. Remove once we
17025 * have readout for pipe gamma enable.
17027 crtc_state->uapi.color_mgmt_changed = true;
17031 ret = drm_atomic_commit(state);
17034 if (ret == -EDEADLK) {
17035 drm_atomic_state_clear(state);
17036 drm_modeset_backoff(&ctx);
17040 drm_atomic_state_put(state);
17042 drm_modeset_drop_locks(&ctx);
17043 drm_modeset_acquire_fini(&ctx);
17048 static void intel_mode_config_init(struct drm_i915_private *i915)
17050 struct drm_mode_config *mode_config = &i915->drm.mode_config;
17052 drm_mode_config_init(&i915->drm);
17054 mode_config->min_width = 0;
17055 mode_config->min_height = 0;
17057 mode_config->preferred_depth = 24;
17058 mode_config->prefer_shadow = 1;
17060 mode_config->allow_fb_modifiers = true;
17062 mode_config->funcs = &intel_mode_funcs;
17065 * Maximum framebuffer dimensions, chosen to match
17066 * the maximum render engine surface size on gen4+.
17068 if (INTEL_GEN(i915) >= 7) {
17069 mode_config->max_width = 16384;
17070 mode_config->max_height = 16384;
17071 } else if (INTEL_GEN(i915) >= 4) {
17072 mode_config->max_width = 8192;
17073 mode_config->max_height = 8192;
17074 } else if (IS_GEN(i915, 3)) {
17075 mode_config->max_width = 4096;
17076 mode_config->max_height = 4096;
17078 mode_config->max_width = 2048;
17079 mode_config->max_height = 2048;
17082 if (IS_I845G(i915) || IS_I865G(i915)) {
17083 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
17084 mode_config->cursor_height = 1023;
17085 } else if (IS_GEN(i915, 2)) {
17086 mode_config->cursor_width = 64;
17087 mode_config->cursor_height = 64;
17089 mode_config->cursor_width = 256;
17090 mode_config->cursor_height = 256;
17094 int intel_modeset_init(struct drm_i915_private *i915)
17096 struct drm_device *dev = &i915->drm;
17098 struct intel_crtc *crtc;
17101 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
17102 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
17103 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
17105 intel_mode_config_init(i915);
17107 ret = intel_bw_init(i915);
17111 init_llist_head(&i915->atomic_helper.free_list);
17112 INIT_WORK(&i915->atomic_helper.free_work,
17113 intel_atomic_helper_free_state_worker);
17115 intel_init_quirks(i915);
17117 intel_fbc_init(i915);
17119 intel_init_pm(i915);
17121 intel_panel_sanitize_ssc(i915);
17123 intel_gmbus_setup(i915);
17125 DRM_DEBUG_KMS("%d display pipe%s available.\n",
17126 INTEL_NUM_PIPES(i915),
17127 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
17129 if (HAS_DISPLAY(i915) && INTEL_DISPLAY_ENABLED(i915)) {
17130 for_each_pipe(i915, pipe) {
17131 ret = intel_crtc_init(i915, pipe);
17133 drm_mode_config_cleanup(dev);
17139 intel_shared_dpll_init(dev);
17140 intel_update_fdi_pll_freq(i915);
17142 intel_update_czclk(i915);
17143 intel_modeset_init_hw(i915);
17145 intel_hdcp_component_init(i915);
17147 if (i915->max_cdclk_freq == 0)
17148 intel_update_max_cdclk(i915);
17150 /* Just disable it once at startup */
17151 intel_vga_disable(i915);
17152 intel_setup_outputs(i915);
17154 drm_modeset_lock_all(dev);
17155 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
17156 drm_modeset_unlock_all(dev);
17158 for_each_intel_crtc(dev, crtc) {
17159 struct intel_initial_plane_config plane_config = {};
17165 * Note that reserving the BIOS fb up front prevents us
17166 * from stuffing other stolen allocations like the ring
17167 * on top. This prevents some ugliness at boot time, and
17168 * can even allow for smooth boot transitions if the BIOS
17169 * fb is large enough for the active pipe configuration.
17171 i915->display.get_initial_plane_config(crtc, &plane_config);
17174 * If the fb is shared between multiple heads, we'll
17175 * just get the first one.
17177 intel_find_initial_plane_obj(crtc, &plane_config);
17181 * Make sure hardware watermarks really match the state we read out.
17182 * Note that we need to do this after reconstructing the BIOS fb's
17183 * since the watermark calculation done here will use pstate->fb.
17185 if (!HAS_GMCH(i915))
17186 sanitize_watermarks(dev);
17189 * Force all active planes to recompute their states. So that on
17190 * mode_setcrtc after probe, all the intel_plane_state variables
17191 * are already calculated and there is no assert_plane warnings
17194 ret = intel_initial_commit(dev);
17196 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
17201 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17203 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17204 /* 640x480@60Hz, ~25175 kHz */
17205 struct dpll clock = {
17215 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
17217 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
17218 pipe_name(pipe), clock.vco, clock.dot);
17220 fp = i9xx_dpll_compute_fp(&clock);
17221 dpll = DPLL_DVO_2X_MODE |
17222 DPLL_VGA_MODE_DIS |
17223 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
17224 PLL_P2_DIVIDE_BY_4 |
17225 PLL_REF_INPUT_DREFCLK |
17228 I915_WRITE(FP0(pipe), fp);
17229 I915_WRITE(FP1(pipe), fp);
17231 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
17232 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
17233 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
17234 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
17235 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
17236 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
17237 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
17240 * Apparently we need to have VGA mode enabled prior to changing
17241 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
17242 * dividers, even though the register value does change.
17244 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
17245 I915_WRITE(DPLL(pipe), dpll);
17247 /* Wait for the clocks to stabilize. */
17248 POSTING_READ(DPLL(pipe));
17251 /* The pixel multiplier can only be updated once the
17252 * DPLL is enabled and the clocks are stable.
17254 * So write it again.
17256 I915_WRITE(DPLL(pipe), dpll);
17258 /* We do this three times for luck */
17259 for (i = 0; i < 3 ; i++) {
17260 I915_WRITE(DPLL(pipe), dpll);
17261 POSTING_READ(DPLL(pipe));
17262 udelay(150); /* wait for warmup */
17265 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
17266 POSTING_READ(PIPECONF(pipe));
17268 intel_wait_for_pipe_scanline_moving(crtc);
17271 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17273 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17275 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
17278 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
17279 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
17280 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
17281 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
17282 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
17284 I915_WRITE(PIPECONF(pipe), 0);
17285 POSTING_READ(PIPECONF(pipe));
17287 intel_wait_for_pipe_scanline_stopped(crtc);
17289 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
17290 POSTING_READ(DPLL(pipe));
17294 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
17296 struct intel_crtc *crtc;
17298 if (INTEL_GEN(dev_priv) >= 4)
17301 for_each_intel_crtc(&dev_priv->drm, crtc) {
17302 struct intel_plane *plane =
17303 to_intel_plane(crtc->base.primary);
17304 struct intel_crtc *plane_crtc;
17307 if (!plane->get_hw_state(plane, &pipe))
17310 if (pipe == crtc->pipe)
17313 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
17314 plane->base.base.id, plane->base.name);
17316 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17317 intel_plane_disable_noatomic(plane_crtc, plane);
17321 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
17323 struct drm_device *dev = crtc->base.dev;
17324 struct intel_encoder *encoder;
17326 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
17332 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
17334 struct drm_device *dev = encoder->base.dev;
17335 struct intel_connector *connector;
17337 for_each_connector_on_encoder(dev, &encoder->base, connector)
17343 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
17344 enum pipe pch_transcoder)
17346 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
17347 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
17350 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state *crtc_state)
17352 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
17353 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
17354 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
17356 if (INTEL_GEN(dev_priv) >= 9 ||
17357 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
17358 i915_reg_t reg = CHICKEN_TRANS(cpu_transcoder);
17361 if (transcoder_is_dsi(cpu_transcoder))
17364 val = I915_READ(reg);
17365 val &= ~HSW_FRAME_START_DELAY_MASK;
17366 val |= HSW_FRAME_START_DELAY(0);
17367 I915_WRITE(reg, val);
17369 i915_reg_t reg = PIPECONF(cpu_transcoder);
17372 val = I915_READ(reg);
17373 val &= ~PIPECONF_FRAME_START_DELAY_MASK;
17374 val |= PIPECONF_FRAME_START_DELAY(0);
17375 I915_WRITE(reg, val);
17378 if (!crtc_state->has_pch_encoder)
17381 if (HAS_PCH_IBX(dev_priv)) {
17382 i915_reg_t reg = PCH_TRANSCONF(crtc->pipe);
17385 val = I915_READ(reg);
17386 val &= ~TRANS_FRAME_START_DELAY_MASK;
17387 val |= TRANS_FRAME_START_DELAY(0);
17388 I915_WRITE(reg, val);
17390 enum pipe pch_transcoder = intel_crtc_pch_transcoder(crtc);
17391 i915_reg_t reg = TRANS_CHICKEN2(pch_transcoder);
17394 val = I915_READ(reg);
17395 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
17396 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
17397 I915_WRITE(reg, val);
17401 static void intel_sanitize_crtc(struct intel_crtc *crtc,
17402 struct drm_modeset_acquire_ctx *ctx)
17404 struct drm_device *dev = crtc->base.dev;
17405 struct drm_i915_private *dev_priv = to_i915(dev);
17406 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
17408 if (crtc_state->hw.active) {
17409 struct intel_plane *plane;
17411 /* Clear any frame start delays used for debugging left by the BIOS */
17412 intel_sanitize_frame_start_delay(crtc_state);
17414 /* Disable everything but the primary plane */
17415 for_each_intel_plane_on_crtc(dev, crtc, plane) {
17416 const struct intel_plane_state *plane_state =
17417 to_intel_plane_state(plane->base.state);
17419 if (plane_state->uapi.visible &&
17420 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
17421 intel_plane_disable_noatomic(crtc, plane);
17425 * Disable any background color set by the BIOS, but enable the
17426 * gamma and CSC to match how we program our planes.
17428 if (INTEL_GEN(dev_priv) >= 9)
17429 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
17430 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
17431 SKL_BOTTOM_COLOR_CSC_ENABLE);
17434 /* Adjust the state of the output pipe according to whether we
17435 * have active connectors/encoders. */
17436 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc))
17437 intel_crtc_disable_noatomic(crtc, ctx);
17439 if (crtc_state->hw.active || HAS_GMCH(dev_priv)) {
17441 * We start out with underrun reporting disabled to avoid races.
17442 * For correct bookkeeping mark this on active crtcs.
17444 * Also on gmch platforms we dont have any hardware bits to
17445 * disable the underrun reporting. Which means we need to start
17446 * out with underrun reporting disabled also on inactive pipes,
17447 * since otherwise we'll complain about the garbage we read when
17448 * e.g. coming up after runtime pm.
17450 * No protection against concurrent access is required - at
17451 * worst a fifo underrun happens which also sets this to false.
17453 crtc->cpu_fifo_underrun_disabled = true;
17455 * We track the PCH trancoder underrun reporting state
17456 * within the crtc. With crtc for pipe A housing the underrun
17457 * reporting state for PCH transcoder A, crtc for pipe B housing
17458 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
17459 * and marking underrun reporting as disabled for the non-existing
17460 * PCH transcoders B and C would prevent enabling the south
17461 * error interrupt (see cpt_can_enable_serr_int()).
17463 if (has_pch_trancoder(dev_priv, crtc->pipe))
17464 crtc->pch_fifo_underrun_disabled = true;
17468 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
17470 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
17473 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
17474 * the hardware when a high res displays plugged in. DPLL P
17475 * divider is zero, and the pipe timings are bonkers. We'll
17476 * try to disable everything in that case.
17478 * FIXME would be nice to be able to sanitize this state
17479 * without several WARNs, but for now let's take the easy
17482 return IS_GEN(dev_priv, 6) &&
17483 crtc_state->hw.active &&
17484 crtc_state->shared_dpll &&
17485 crtc_state->port_clock == 0;
17488 static void intel_sanitize_encoder(struct intel_encoder *encoder)
17490 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
17491 struct intel_connector *connector;
17492 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
17493 struct intel_crtc_state *crtc_state = crtc ?
17494 to_intel_crtc_state(crtc->base.state) : NULL;
17496 /* We need to check both for a crtc link (meaning that the
17497 * encoder is active and trying to read from a pipe) and the
17498 * pipe itself being active. */
17499 bool has_active_crtc = crtc_state &&
17500 crtc_state->hw.active;
17502 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
17503 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
17504 pipe_name(crtc->pipe));
17505 has_active_crtc = false;
17508 connector = intel_encoder_find_connector(encoder);
17509 if (connector && !has_active_crtc) {
17510 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
17511 encoder->base.base.id,
17512 encoder->base.name);
17514 /* Connector is active, but has no active pipe. This is
17515 * fallout from our resume register restoring. Disable
17516 * the encoder manually again. */
17518 struct drm_encoder *best_encoder;
17520 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
17521 encoder->base.base.id,
17522 encoder->base.name);
17524 /* avoid oopsing in case the hooks consult best_encoder */
17525 best_encoder = connector->base.state->best_encoder;
17526 connector->base.state->best_encoder = &encoder->base;
17528 if (encoder->disable)
17529 encoder->disable(encoder, crtc_state,
17530 connector->base.state);
17531 if (encoder->post_disable)
17532 encoder->post_disable(encoder, crtc_state,
17533 connector->base.state);
17535 connector->base.state->best_encoder = best_encoder;
17537 encoder->base.crtc = NULL;
17539 /* Inconsistent output/port/pipe state happens presumably due to
17540 * a bug in one of the get_hw_state functions. Or someplace else
17541 * in our code, like the register restore mess on resume. Clamp
17542 * things to off as a safer default. */
17544 connector->base.dpms = DRM_MODE_DPMS_OFF;
17545 connector->base.encoder = NULL;
17548 /* notify opregion of the sanitized encoder state */
17549 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
17551 if (INTEL_GEN(dev_priv) >= 11)
17552 icl_sanitize_encoder_pll_mapping(encoder);
17555 /* FIXME read out full plane state for all planes */
17556 static void readout_plane_state(struct drm_i915_private *dev_priv)
17558 struct intel_plane *plane;
17559 struct intel_crtc *crtc;
17561 for_each_intel_plane(&dev_priv->drm, plane) {
17562 struct intel_plane_state *plane_state =
17563 to_intel_plane_state(plane->base.state);
17564 struct intel_crtc_state *crtc_state;
17565 enum pipe pipe = PIPE_A;
17568 visible = plane->get_hw_state(plane, &pipe);
17570 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17571 crtc_state = to_intel_crtc_state(crtc->base.state);
17573 intel_set_plane_visible(crtc_state, plane_state, visible);
17575 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
17576 plane->base.base.id, plane->base.name,
17577 enableddisabled(visible), pipe_name(pipe));
17580 for_each_intel_crtc(&dev_priv->drm, crtc) {
17581 struct intel_crtc_state *crtc_state =
17582 to_intel_crtc_state(crtc->base.state);
17584 fixup_active_planes(crtc_state);
17588 static void intel_modeset_readout_hw_state(struct drm_device *dev)
17590 struct drm_i915_private *dev_priv = to_i915(dev);
17592 struct intel_crtc *crtc;
17593 struct intel_encoder *encoder;
17594 struct intel_connector *connector;
17595 struct drm_connector_list_iter conn_iter;
17598 dev_priv->active_pipes = 0;
17600 for_each_intel_crtc(dev, crtc) {
17601 struct intel_crtc_state *crtc_state =
17602 to_intel_crtc_state(crtc->base.state);
17604 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
17605 intel_crtc_free_hw_state(crtc_state);
17606 intel_crtc_state_reset(crtc_state, crtc);
17608 crtc_state->hw.active = crtc_state->hw.enable =
17609 dev_priv->display.get_pipe_config(crtc, crtc_state);
17611 crtc->base.enabled = crtc_state->hw.enable;
17612 crtc->active = crtc_state->hw.active;
17614 if (crtc_state->hw.active)
17615 dev_priv->active_pipes |= BIT(crtc->pipe);
17617 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
17618 crtc->base.base.id, crtc->base.name,
17619 enableddisabled(crtc_state->hw.active));
17622 readout_plane_state(dev_priv);
17624 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
17625 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
17627 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
17628 &pll->state.hw_state);
17630 if (IS_ELKHARTLAKE(dev_priv) && pll->on &&
17631 pll->info->id == DPLL_ID_EHL_DPLL4) {
17632 pll->wakeref = intel_display_power_get(dev_priv,
17633 POWER_DOMAIN_DPLL_DC_OFF);
17636 pll->state.crtc_mask = 0;
17637 for_each_intel_crtc(dev, crtc) {
17638 struct intel_crtc_state *crtc_state =
17639 to_intel_crtc_state(crtc->base.state);
17641 if (crtc_state->hw.active &&
17642 crtc_state->shared_dpll == pll)
17643 pll->state.crtc_mask |= 1 << crtc->pipe;
17645 pll->active_mask = pll->state.crtc_mask;
17647 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
17648 pll->info->name, pll->state.crtc_mask, pll->on);
17651 for_each_intel_encoder(dev, encoder) {
17654 if (encoder->get_hw_state(encoder, &pipe)) {
17655 struct intel_crtc_state *crtc_state;
17657 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17658 crtc_state = to_intel_crtc_state(crtc->base.state);
17660 encoder->base.crtc = &crtc->base;
17661 encoder->get_config(encoder, crtc_state);
17663 encoder->base.crtc = NULL;
17666 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
17667 encoder->base.base.id, encoder->base.name,
17668 enableddisabled(encoder->base.crtc),
17672 drm_connector_list_iter_begin(dev, &conn_iter);
17673 for_each_intel_connector_iter(connector, &conn_iter) {
17674 if (connector->get_hw_state(connector)) {
17675 struct intel_crtc_state *crtc_state;
17676 struct intel_crtc *crtc;
17678 connector->base.dpms = DRM_MODE_DPMS_ON;
17680 encoder = connector->encoder;
17681 connector->base.encoder = &encoder->base;
17683 crtc = to_intel_crtc(encoder->base.crtc);
17684 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
17686 if (crtc_state && crtc_state->hw.active) {
17688 * This has to be done during hardware readout
17689 * because anything calling .crtc_disable may
17690 * rely on the connector_mask being accurate.
17692 crtc_state->uapi.connector_mask |=
17693 drm_connector_mask(&connector->base);
17694 crtc_state->uapi.encoder_mask |=
17695 drm_encoder_mask(&encoder->base);
17698 connector->base.dpms = DRM_MODE_DPMS_OFF;
17699 connector->base.encoder = NULL;
17701 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
17702 connector->base.base.id, connector->base.name,
17703 enableddisabled(connector->base.encoder));
17705 drm_connector_list_iter_end(&conn_iter);
17707 for_each_intel_crtc(dev, crtc) {
17708 struct intel_bw_state *bw_state =
17709 to_intel_bw_state(dev_priv->bw_obj.state);
17710 struct intel_crtc_state *crtc_state =
17711 to_intel_crtc_state(crtc->base.state);
17712 struct intel_plane *plane;
17715 if (crtc_state->hw.active) {
17716 struct drm_display_mode *mode = &crtc_state->hw.mode;
17718 intel_mode_from_pipe_config(&crtc_state->hw.adjusted_mode,
17721 *mode = crtc_state->hw.adjusted_mode;
17722 mode->hdisplay = crtc_state->pipe_src_w;
17723 mode->vdisplay = crtc_state->pipe_src_h;
17726 * The initial mode needs to be set in order to keep
17727 * the atomic core happy. It wants a valid mode if the
17728 * crtc's enabled, so we do the above call.
17730 * But we don't set all the derived state fully, hence
17731 * set a flag to indicate that a full recalculation is
17732 * needed on the next commit.
17734 mode->private_flags = I915_MODE_FLAG_INHERITED;
17736 intel_crtc_compute_pixel_rate(crtc_state);
17738 intel_crtc_update_active_timings(crtc_state);
17740 intel_crtc_copy_hw_to_uapi_state(crtc_state);
17743 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
17744 const struct intel_plane_state *plane_state =
17745 to_intel_plane_state(plane->base.state);
17748 * FIXME don't have the fb yet, so can't
17749 * use intel_plane_data_rate() :(
17751 if (plane_state->uapi.visible)
17752 crtc_state->data_rate[plane->id] =
17753 4 * crtc_state->pixel_rate;
17755 * FIXME don't have the fb yet, so can't
17756 * use plane->min_cdclk() :(
17758 if (plane_state->uapi.visible && plane->min_cdclk) {
17759 if (crtc_state->double_wide ||
17760 INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
17761 crtc_state->min_cdclk[plane->id] =
17762 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
17764 crtc_state->min_cdclk[plane->id] =
17765 crtc_state->pixel_rate;
17767 DRM_DEBUG_KMS("[PLANE:%d:%s] min_cdclk %d kHz\n",
17768 plane->base.base.id, plane->base.name,
17769 crtc_state->min_cdclk[plane->id]);
17772 if (crtc_state->hw.active) {
17773 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
17774 if (WARN_ON(min_cdclk < 0))
17778 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
17779 dev_priv->min_voltage_level[crtc->pipe] =
17780 crtc_state->min_voltage_level;
17782 intel_bw_crtc_update(bw_state, crtc_state);
17784 intel_pipe_config_sanity_check(dev_priv, crtc_state);
17789 get_encoder_power_domains(struct drm_i915_private *dev_priv)
17791 struct intel_encoder *encoder;
17793 for_each_intel_encoder(&dev_priv->drm, encoder) {
17794 struct intel_crtc_state *crtc_state;
17796 if (!encoder->get_power_domains)
17800 * MST-primary and inactive encoders don't have a crtc state
17801 * and neither of these require any power domain references.
17803 if (!encoder->base.crtc)
17806 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
17807 encoder->get_power_domains(encoder, crtc_state);
17811 static void intel_early_display_was(struct drm_i915_private *dev_priv)
17813 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
17814 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
17815 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
17818 if (IS_HASWELL(dev_priv)) {
17820 * WaRsPkgCStateDisplayPMReq:hsw
17821 * System hang if this isn't done before disabling all planes!
17823 I915_WRITE(CHICKEN_PAR1_1,
17824 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
17828 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
17829 enum port port, i915_reg_t hdmi_reg)
17831 u32 val = I915_READ(hdmi_reg);
17833 if (val & SDVO_ENABLE ||
17834 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
17837 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
17840 val &= ~SDVO_PIPE_SEL_MASK;
17841 val |= SDVO_PIPE_SEL(PIPE_A);
17843 I915_WRITE(hdmi_reg, val);
17846 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
17847 enum port port, i915_reg_t dp_reg)
17849 u32 val = I915_READ(dp_reg);
17851 if (val & DP_PORT_EN ||
17852 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
17855 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
17858 val &= ~DP_PIPE_SEL_MASK;
17859 val |= DP_PIPE_SEL(PIPE_A);
17861 I915_WRITE(dp_reg, val);
17864 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
17867 * The BIOS may select transcoder B on some of the PCH
17868 * ports even it doesn't enable the port. This would trip
17869 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
17870 * Sanitize the transcoder select bits to prevent that. We
17871 * assume that the BIOS never actually enabled the port,
17872 * because if it did we'd actually have to toggle the port
17873 * on and back off to make the transcoder A select stick
17874 * (see. intel_dp_link_down(), intel_disable_hdmi(),
17875 * intel_disable_sdvo()).
17877 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
17878 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
17879 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
17881 /* PCH SDVOB multiplex with HDMIB */
17882 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
17883 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
17884 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
17887 /* Scan out the current hw modeset state,
17888 * and sanitizes it to the current state
17891 intel_modeset_setup_hw_state(struct drm_device *dev,
17892 struct drm_modeset_acquire_ctx *ctx)
17894 struct drm_i915_private *dev_priv = to_i915(dev);
17895 struct intel_encoder *encoder;
17896 struct intel_crtc *crtc;
17897 intel_wakeref_t wakeref;
17900 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
17902 intel_early_display_was(dev_priv);
17903 intel_modeset_readout_hw_state(dev);
17905 /* HW state is read out, now we need to sanitize this mess. */
17907 /* Sanitize the TypeC port mode upfront, encoders depend on this */
17908 for_each_intel_encoder(dev, encoder) {
17909 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
17911 /* We need to sanitize only the MST primary port. */
17912 if (encoder->type != INTEL_OUTPUT_DP_MST &&
17913 intel_phy_is_tc(dev_priv, phy))
17914 intel_tc_port_sanitize(enc_to_dig_port(&encoder->base));
17917 get_encoder_power_domains(dev_priv);
17919 if (HAS_PCH_IBX(dev_priv))
17920 ibx_sanitize_pch_ports(dev_priv);
17923 * intel_sanitize_plane_mapping() may need to do vblank
17924 * waits, so we need vblank interrupts restored beforehand.
17926 for_each_intel_crtc(&dev_priv->drm, crtc) {
17927 struct intel_crtc_state *crtc_state =
17928 to_intel_crtc_state(crtc->base.state);
17930 drm_crtc_vblank_reset(&crtc->base);
17932 if (crtc_state->hw.active)
17933 intel_crtc_vblank_on(crtc_state);
17936 intel_sanitize_plane_mapping(dev_priv);
17938 for_each_intel_encoder(dev, encoder)
17939 intel_sanitize_encoder(encoder);
17941 for_each_intel_crtc(&dev_priv->drm, crtc) {
17942 struct intel_crtc_state *crtc_state =
17943 to_intel_crtc_state(crtc->base.state);
17945 intel_sanitize_crtc(crtc, ctx);
17946 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
17949 intel_modeset_update_connector_atomic_state(dev);
17951 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
17952 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
17954 if (!pll->on || pll->active_mask)
17957 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
17960 pll->info->funcs->disable(dev_priv, pll);
17964 if (IS_G4X(dev_priv)) {
17965 g4x_wm_get_hw_state(dev_priv);
17966 g4x_wm_sanitize(dev_priv);
17967 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
17968 vlv_wm_get_hw_state(dev_priv);
17969 vlv_wm_sanitize(dev_priv);
17970 } else if (INTEL_GEN(dev_priv) >= 9) {
17971 skl_wm_get_hw_state(dev_priv);
17972 } else if (HAS_PCH_SPLIT(dev_priv)) {
17973 ilk_wm_get_hw_state(dev_priv);
17976 for_each_intel_crtc(dev, crtc) {
17977 struct intel_crtc_state *crtc_state =
17978 to_intel_crtc_state(crtc->base.state);
17981 put_domains = modeset_get_crtc_power_domains(crtc_state);
17982 if (WARN_ON(put_domains))
17983 modeset_put_power_domains(dev_priv, put_domains);
17986 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
17989 void intel_display_resume(struct drm_device *dev)
17991 struct drm_i915_private *dev_priv = to_i915(dev);
17992 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
17993 struct drm_modeset_acquire_ctx ctx;
17996 dev_priv->modeset_restore_state = NULL;
17998 state->acquire_ctx = &ctx;
18000 drm_modeset_acquire_init(&ctx, 0);
18003 ret = drm_modeset_lock_all_ctx(dev, &ctx);
18004 if (ret != -EDEADLK)
18007 drm_modeset_backoff(&ctx);
18011 ret = __intel_display_resume(dev, state, &ctx);
18013 intel_enable_ipc(dev_priv);
18014 drm_modeset_drop_locks(&ctx);
18015 drm_modeset_acquire_fini(&ctx);
18018 DRM_ERROR("Restoring old state failed with %i\n", ret);
18020 drm_atomic_state_put(state);
18023 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
18025 struct intel_connector *connector;
18026 struct drm_connector_list_iter conn_iter;
18028 /* Kill all the work that may have been queued by hpd. */
18029 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
18030 for_each_intel_connector_iter(connector, &conn_iter) {
18031 if (connector->modeset_retry_work.func)
18032 cancel_work_sync(&connector->modeset_retry_work);
18033 if (connector->hdcp.shim) {
18034 cancel_delayed_work_sync(&connector->hdcp.check_work);
18035 cancel_work_sync(&connector->hdcp.prop_work);
18038 drm_connector_list_iter_end(&conn_iter);
18041 void intel_modeset_driver_remove(struct drm_i915_private *i915)
18043 flush_workqueue(i915->flip_wq);
18044 flush_workqueue(i915->modeset_wq);
18046 flush_work(&i915->atomic_helper.free_work);
18047 WARN_ON(!llist_empty(&i915->atomic_helper.free_list));
18050 * Interrupts and polling as the first thing to avoid creating havoc.
18051 * Too much stuff here (turning of connectors, ...) would
18052 * experience fancy races otherwise.
18054 intel_irq_uninstall(i915);
18057 * Due to the hpd irq storm handling the hotplug work can re-arm the
18058 * poll handlers. Hence disable polling after hpd handling is shut down.
18060 intel_hpd_poll_fini(i915);
18063 * MST topology needs to be suspended so we don't have any calls to
18064 * fbdev after it's finalized. MST will be destroyed later as part of
18065 * drm_mode_config_cleanup()
18067 intel_dp_mst_suspend(i915);
18069 /* poll work can call into fbdev, hence clean that up afterwards */
18070 intel_fbdev_fini(i915);
18072 intel_unregister_dsm_handler();
18074 intel_fbc_global_disable(i915);
18076 /* flush any delayed tasks or pending work */
18077 flush_scheduled_work();
18079 intel_hdcp_component_fini(i915);
18081 drm_mode_config_cleanup(&i915->drm);
18083 intel_overlay_cleanup(i915);
18085 intel_gmbus_teardown(i915);
18087 destroy_workqueue(i915->flip_wq);
18088 destroy_workqueue(i915->modeset_wq);
18090 intel_fbc_cleanup_cfb(i915);
18093 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
18095 struct intel_display_error_state {
18097 u32 power_well_driver;
18099 struct intel_cursor_error_state {
18104 } cursor[I915_MAX_PIPES];
18106 struct intel_pipe_error_state {
18107 bool power_domain_on;
18110 } pipe[I915_MAX_PIPES];
18112 struct intel_plane_error_state {
18120 } plane[I915_MAX_PIPES];
18122 struct intel_transcoder_error_state {
18124 bool power_domain_on;
18125 enum transcoder cpu_transcoder;
18138 struct intel_display_error_state *
18139 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
18141 struct intel_display_error_state *error;
18142 int transcoders[] = {
18151 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
18153 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
18156 error = kzalloc(sizeof(*error), GFP_ATOMIC);
18160 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18161 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
18163 for_each_pipe(dev_priv, i) {
18164 error->pipe[i].power_domain_on =
18165 __intel_display_power_is_enabled(dev_priv,
18166 POWER_DOMAIN_PIPE(i));
18167 if (!error->pipe[i].power_domain_on)
18170 error->cursor[i].control = I915_READ(CURCNTR(i));
18171 error->cursor[i].position = I915_READ(CURPOS(i));
18172 error->cursor[i].base = I915_READ(CURBASE(i));
18174 error->plane[i].control = I915_READ(DSPCNTR(i));
18175 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
18176 if (INTEL_GEN(dev_priv) <= 3) {
18177 error->plane[i].size = I915_READ(DSPSIZE(i));
18178 error->plane[i].pos = I915_READ(DSPPOS(i));
18180 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18181 error->plane[i].addr = I915_READ(DSPADDR(i));
18182 if (INTEL_GEN(dev_priv) >= 4) {
18183 error->plane[i].surface = I915_READ(DSPSURF(i));
18184 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
18187 error->pipe[i].source = I915_READ(PIPESRC(i));
18189 if (HAS_GMCH(dev_priv))
18190 error->pipe[i].stat = I915_READ(PIPESTAT(i));
18193 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18194 enum transcoder cpu_transcoder = transcoders[i];
18196 if (!INTEL_INFO(dev_priv)->trans_offsets[cpu_transcoder])
18199 error->transcoder[i].available = true;
18200 error->transcoder[i].power_domain_on =
18201 __intel_display_power_is_enabled(dev_priv,
18202 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
18203 if (!error->transcoder[i].power_domain_on)
18206 error->transcoder[i].cpu_transcoder = cpu_transcoder;
18208 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
18209 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
18210 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
18211 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
18212 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
18213 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
18214 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
18220 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
18223 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
18224 struct intel_display_error_state *error)
18226 struct drm_i915_private *dev_priv = m->i915;
18232 err_printf(m, "Num Pipes: %d\n", INTEL_NUM_PIPES(dev_priv));
18233 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18234 err_printf(m, "PWR_WELL_CTL2: %08x\n",
18235 error->power_well_driver);
18236 for_each_pipe(dev_priv, i) {
18237 err_printf(m, "Pipe [%d]:\n", i);
18238 err_printf(m, " Power: %s\n",
18239 onoff(error->pipe[i].power_domain_on));
18240 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
18241 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
18243 err_printf(m, "Plane [%d]:\n", i);
18244 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
18245 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
18246 if (INTEL_GEN(dev_priv) <= 3) {
18247 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
18248 err_printf(m, " POS: %08x\n", error->plane[i].pos);
18250 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18251 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
18252 if (INTEL_GEN(dev_priv) >= 4) {
18253 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
18254 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
18257 err_printf(m, "Cursor [%d]:\n", i);
18258 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
18259 err_printf(m, " POS: %08x\n", error->cursor[i].position);
18260 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
18263 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18264 if (!error->transcoder[i].available)
18267 err_printf(m, "CPU transcoder: %s\n",
18268 transcoder_name(error->transcoder[i].cpu_transcoder));
18269 err_printf(m, " Power: %s\n",
18270 onoff(error->transcoder[i].power_domain_on));
18271 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
18272 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
18273 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
18274 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
18275 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
18276 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
18277 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);