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>
45 #include "display/intel_crt.h"
46 #include "display/intel_ddi.h"
47 #include "display/intel_dp.h"
48 #include "display/intel_dp_mst.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 ilk_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 ilk_set_pipeconf(const struct intel_crtc_state *crtc_state);
161 static void hsw_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 skl_pfit_enable(const struct intel_crtc_state *crtc_state);
168 static void ilk_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 drm_WARN(&dev_priv->drm, (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_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
238 dev_priv->czclk_freq);
241 static inline u32 /* units of 100MHz */
242 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
243 const struct intel_crtc_state *pipe_config)
245 if (HAS_DDI(dev_priv))
246 return pipe_config->port_clock; /* SPLL */
248 return dev_priv->fdi_pll_freq;
251 static const struct intel_limit intel_limits_i8xx_dac = {
252 .dot = { .min = 25000, .max = 350000 },
253 .vco = { .min = 908000, .max = 1512000 },
254 .n = { .min = 2, .max = 16 },
255 .m = { .min = 96, .max = 140 },
256 .m1 = { .min = 18, .max = 26 },
257 .m2 = { .min = 6, .max = 16 },
258 .p = { .min = 4, .max = 128 },
259 .p1 = { .min = 2, .max = 33 },
260 .p2 = { .dot_limit = 165000,
261 .p2_slow = 4, .p2_fast = 2 },
264 static const struct intel_limit intel_limits_i8xx_dvo = {
265 .dot = { .min = 25000, .max = 350000 },
266 .vco = { .min = 908000, .max = 1512000 },
267 .n = { .min = 2, .max = 16 },
268 .m = { .min = 96, .max = 140 },
269 .m1 = { .min = 18, .max = 26 },
270 .m2 = { .min = 6, .max = 16 },
271 .p = { .min = 4, .max = 128 },
272 .p1 = { .min = 2, .max = 33 },
273 .p2 = { .dot_limit = 165000,
274 .p2_slow = 4, .p2_fast = 4 },
277 static const struct intel_limit intel_limits_i8xx_lvds = {
278 .dot = { .min = 25000, .max = 350000 },
279 .vco = { .min = 908000, .max = 1512000 },
280 .n = { .min = 2, .max = 16 },
281 .m = { .min = 96, .max = 140 },
282 .m1 = { .min = 18, .max = 26 },
283 .m2 = { .min = 6, .max = 16 },
284 .p = { .min = 4, .max = 128 },
285 .p1 = { .min = 1, .max = 6 },
286 .p2 = { .dot_limit = 165000,
287 .p2_slow = 14, .p2_fast = 7 },
290 static const struct intel_limit intel_limits_i9xx_sdvo = {
291 .dot = { .min = 20000, .max = 400000 },
292 .vco = { .min = 1400000, .max = 2800000 },
293 .n = { .min = 1, .max = 6 },
294 .m = { .min = 70, .max = 120 },
295 .m1 = { .min = 8, .max = 18 },
296 .m2 = { .min = 3, .max = 7 },
297 .p = { .min = 5, .max = 80 },
298 .p1 = { .min = 1, .max = 8 },
299 .p2 = { .dot_limit = 200000,
300 .p2_slow = 10, .p2_fast = 5 },
303 static const struct intel_limit intel_limits_i9xx_lvds = {
304 .dot = { .min = 20000, .max = 400000 },
305 .vco = { .min = 1400000, .max = 2800000 },
306 .n = { .min = 1, .max = 6 },
307 .m = { .min = 70, .max = 120 },
308 .m1 = { .min = 8, .max = 18 },
309 .m2 = { .min = 3, .max = 7 },
310 .p = { .min = 7, .max = 98 },
311 .p1 = { .min = 1, .max = 8 },
312 .p2 = { .dot_limit = 112000,
313 .p2_slow = 14, .p2_fast = 7 },
317 static const struct intel_limit intel_limits_g4x_sdvo = {
318 .dot = { .min = 25000, .max = 270000 },
319 .vco = { .min = 1750000, .max = 3500000},
320 .n = { .min = 1, .max = 4 },
321 .m = { .min = 104, .max = 138 },
322 .m1 = { .min = 17, .max = 23 },
323 .m2 = { .min = 5, .max = 11 },
324 .p = { .min = 10, .max = 30 },
325 .p1 = { .min = 1, .max = 3},
326 .p2 = { .dot_limit = 270000,
332 static const struct intel_limit intel_limits_g4x_hdmi = {
333 .dot = { .min = 22000, .max = 400000 },
334 .vco = { .min = 1750000, .max = 3500000},
335 .n = { .min = 1, .max = 4 },
336 .m = { .min = 104, .max = 138 },
337 .m1 = { .min = 16, .max = 23 },
338 .m2 = { .min = 5, .max = 11 },
339 .p = { .min = 5, .max = 80 },
340 .p1 = { .min = 1, .max = 8},
341 .p2 = { .dot_limit = 165000,
342 .p2_slow = 10, .p2_fast = 5 },
345 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
346 .dot = { .min = 20000, .max = 115000 },
347 .vco = { .min = 1750000, .max = 3500000 },
348 .n = { .min = 1, .max = 3 },
349 .m = { .min = 104, .max = 138 },
350 .m1 = { .min = 17, .max = 23 },
351 .m2 = { .min = 5, .max = 11 },
352 .p = { .min = 28, .max = 112 },
353 .p1 = { .min = 2, .max = 8 },
354 .p2 = { .dot_limit = 0,
355 .p2_slow = 14, .p2_fast = 14
359 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
360 .dot = { .min = 80000, .max = 224000 },
361 .vco = { .min = 1750000, .max = 3500000 },
362 .n = { .min = 1, .max = 3 },
363 .m = { .min = 104, .max = 138 },
364 .m1 = { .min = 17, .max = 23 },
365 .m2 = { .min = 5, .max = 11 },
366 .p = { .min = 14, .max = 42 },
367 .p1 = { .min = 2, .max = 6 },
368 .p2 = { .dot_limit = 0,
369 .p2_slow = 7, .p2_fast = 7
373 static const struct intel_limit pnv_limits_sdvo = {
374 .dot = { .min = 20000, .max = 400000},
375 .vco = { .min = 1700000, .max = 3500000 },
376 /* Pineview's Ncounter is a ring counter */
377 .n = { .min = 3, .max = 6 },
378 .m = { .min = 2, .max = 256 },
379 /* Pineview only has one combined m divider, which we treat as m2. */
380 .m1 = { .min = 0, .max = 0 },
381 .m2 = { .min = 0, .max = 254 },
382 .p = { .min = 5, .max = 80 },
383 .p1 = { .min = 1, .max = 8 },
384 .p2 = { .dot_limit = 200000,
385 .p2_slow = 10, .p2_fast = 5 },
388 static const struct intel_limit pnv_limits_lvds = {
389 .dot = { .min = 20000, .max = 400000 },
390 .vco = { .min = 1700000, .max = 3500000 },
391 .n = { .min = 3, .max = 6 },
392 .m = { .min = 2, .max = 256 },
393 .m1 = { .min = 0, .max = 0 },
394 .m2 = { .min = 0, .max = 254 },
395 .p = { .min = 7, .max = 112 },
396 .p1 = { .min = 1, .max = 8 },
397 .p2 = { .dot_limit = 112000,
398 .p2_slow = 14, .p2_fast = 14 },
401 /* Ironlake / Sandybridge
403 * We calculate clock using (register_value + 2) for N/M1/M2, so here
404 * the range value for them is (actual_value - 2).
406 static const struct intel_limit ilk_limits_dac = {
407 .dot = { .min = 25000, .max = 350000 },
408 .vco = { .min = 1760000, .max = 3510000 },
409 .n = { .min = 1, .max = 5 },
410 .m = { .min = 79, .max = 127 },
411 .m1 = { .min = 12, .max = 22 },
412 .m2 = { .min = 5, .max = 9 },
413 .p = { .min = 5, .max = 80 },
414 .p1 = { .min = 1, .max = 8 },
415 .p2 = { .dot_limit = 225000,
416 .p2_slow = 10, .p2_fast = 5 },
419 static const struct intel_limit ilk_limits_single_lvds = {
420 .dot = { .min = 25000, .max = 350000 },
421 .vco = { .min = 1760000, .max = 3510000 },
422 .n = { .min = 1, .max = 3 },
423 .m = { .min = 79, .max = 118 },
424 .m1 = { .min = 12, .max = 22 },
425 .m2 = { .min = 5, .max = 9 },
426 .p = { .min = 28, .max = 112 },
427 .p1 = { .min = 2, .max = 8 },
428 .p2 = { .dot_limit = 225000,
429 .p2_slow = 14, .p2_fast = 14 },
432 static const struct intel_limit ilk_limits_dual_lvds = {
433 .dot = { .min = 25000, .max = 350000 },
434 .vco = { .min = 1760000, .max = 3510000 },
435 .n = { .min = 1, .max = 3 },
436 .m = { .min = 79, .max = 127 },
437 .m1 = { .min = 12, .max = 22 },
438 .m2 = { .min = 5, .max = 9 },
439 .p = { .min = 14, .max = 56 },
440 .p1 = { .min = 2, .max = 8 },
441 .p2 = { .dot_limit = 225000,
442 .p2_slow = 7, .p2_fast = 7 },
445 /* LVDS 100mhz refclk limits. */
446 static const struct intel_limit ilk_limits_single_lvds_100m = {
447 .dot = { .min = 25000, .max = 350000 },
448 .vco = { .min = 1760000, .max = 3510000 },
449 .n = { .min = 1, .max = 2 },
450 .m = { .min = 79, .max = 126 },
451 .m1 = { .min = 12, .max = 22 },
452 .m2 = { .min = 5, .max = 9 },
453 .p = { .min = 28, .max = 112 },
454 .p1 = { .min = 2, .max = 8 },
455 .p2 = { .dot_limit = 225000,
456 .p2_slow = 14, .p2_fast = 14 },
459 static const struct intel_limit ilk_limits_dual_lvds_100m = {
460 .dot = { .min = 25000, .max = 350000 },
461 .vco = { .min = 1760000, .max = 3510000 },
462 .n = { .min = 1, .max = 3 },
463 .m = { .min = 79, .max = 126 },
464 .m1 = { .min = 12, .max = 22 },
465 .m2 = { .min = 5, .max = 9 },
466 .p = { .min = 14, .max = 42 },
467 .p1 = { .min = 2, .max = 6 },
468 .p2 = { .dot_limit = 225000,
469 .p2_slow = 7, .p2_fast = 7 },
472 static const struct intel_limit intel_limits_vlv = {
474 * These are the data rate limits (measured in fast clocks)
475 * since those are the strictest limits we have. The fast
476 * clock and actual rate limits are more relaxed, so checking
477 * them would make no difference.
479 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
480 .vco = { .min = 4000000, .max = 6000000 },
481 .n = { .min = 1, .max = 7 },
482 .m1 = { .min = 2, .max = 3 },
483 .m2 = { .min = 11, .max = 156 },
484 .p1 = { .min = 2, .max = 3 },
485 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
488 static const struct intel_limit intel_limits_chv = {
490 * These are the data rate limits (measured in fast clocks)
491 * since those are the strictest limits we have. The fast
492 * clock and actual rate limits are more relaxed, so checking
493 * them would make no difference.
495 .dot = { .min = 25000 * 5, .max = 540000 * 5},
496 .vco = { .min = 4800000, .max = 6480000 },
497 .n = { .min = 1, .max = 1 },
498 .m1 = { .min = 2, .max = 2 },
499 .m2 = { .min = 24 << 22, .max = 175 << 22 },
500 .p1 = { .min = 2, .max = 4 },
501 .p2 = { .p2_slow = 1, .p2_fast = 14 },
504 static const struct intel_limit intel_limits_bxt = {
505 /* FIXME: find real dot limits */
506 .dot = { .min = 0, .max = INT_MAX },
507 .vco = { .min = 4800000, .max = 6700000 },
508 .n = { .min = 1, .max = 1 },
509 .m1 = { .min = 2, .max = 2 },
510 /* FIXME: find real m2 limits */
511 .m2 = { .min = 2 << 22, .max = 255 << 22 },
512 .p1 = { .min = 2, .max = 4 },
513 .p2 = { .p2_slow = 1, .p2_fast = 20 },
516 /* WA Display #0827: Gen9:all */
518 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
521 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
522 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DUPS1_GATING_DIS | DUPS2_GATING_DIS);
524 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
525 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
528 /* Wa_2006604312:icl */
530 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
534 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
535 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
537 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
538 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
542 needs_modeset(const struct intel_crtc_state *state)
544 return drm_atomic_crtc_needs_modeset(&state->uapi);
548 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
550 return (crtc_state->master_transcoder != INVALID_TRANSCODER ||
551 crtc_state->sync_mode_slaves_mask);
555 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
557 return crtc_state->master_transcoder != INVALID_TRANSCODER;
561 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
562 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
563 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
564 * The helpers' return value is the rate of the clock that is fed to the
565 * display engine's pipe which can be the above fast dot clock rate or a
566 * divided-down version of it.
568 /* m1 is reserved as 0 in Pineview, n is a ring counter */
569 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
571 clock->m = clock->m2 + 2;
572 clock->p = clock->p1 * clock->p2;
573 if (WARN_ON(clock->n == 0 || clock->p == 0))
575 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
576 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
581 static u32 i9xx_dpll_compute_m(struct dpll *dpll)
583 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
586 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
588 clock->m = i9xx_dpll_compute_m(clock);
589 clock->p = clock->p1 * clock->p2;
590 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
592 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
593 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
598 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
600 clock->m = clock->m1 * clock->m2;
601 clock->p = clock->p1 * clock->p2;
602 if (WARN_ON(clock->n == 0 || clock->p == 0))
604 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
605 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
607 return clock->dot / 5;
610 int chv_calc_dpll_params(int refclk, struct dpll *clock)
612 clock->m = clock->m1 * clock->m2;
613 clock->p = clock->p1 * clock->p2;
614 if (WARN_ON(clock->n == 0 || clock->p == 0))
616 clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
618 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
620 return clock->dot / 5;
624 * Returns whether the given set of divisors are valid for a given refclk with
625 * the given connectors.
627 static bool intel_pll_is_valid(struct drm_i915_private *dev_priv,
628 const struct intel_limit *limit,
629 const struct dpll *clock)
631 if (clock->n < limit->n.min || limit->n.max < clock->n)
633 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
635 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
637 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
640 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
641 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
642 if (clock->m1 <= clock->m2)
645 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
646 !IS_GEN9_LP(dev_priv)) {
647 if (clock->p < limit->p.min || limit->p.max < clock->p)
649 if (clock->m < limit->m.min || limit->m.max < clock->m)
653 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
655 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
656 * connector, etc., rather than just a single range.
658 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
665 i9xx_select_p2_div(const struct intel_limit *limit,
666 const struct intel_crtc_state *crtc_state,
669 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
671 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
673 * For LVDS just rely on its current settings for dual-channel.
674 * We haven't figured out how to reliably set up different
675 * single/dual channel state, if we even can.
677 if (intel_is_dual_link_lvds(dev_priv))
678 return limit->p2.p2_fast;
680 return limit->p2.p2_slow;
682 if (target < limit->p2.dot_limit)
683 return limit->p2.p2_slow;
685 return limit->p2.p2_fast;
690 * Returns a set of divisors for the desired target clock with the given
691 * refclk, or FALSE. The returned values represent the clock equation:
692 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
694 * Target and reference clocks are specified in kHz.
696 * If match_clock is provided, then best_clock P divider must match the P
697 * divider from @match_clock used for LVDS downclocking.
700 i9xx_find_best_dpll(const struct intel_limit *limit,
701 struct intel_crtc_state *crtc_state,
702 int target, int refclk, struct dpll *match_clock,
703 struct dpll *best_clock)
705 struct drm_device *dev = crtc_state->uapi.crtc->dev;
709 memset(best_clock, 0, sizeof(*best_clock));
711 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
713 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
715 for (clock.m2 = limit->m2.min;
716 clock.m2 <= limit->m2.max; clock.m2++) {
717 if (clock.m2 >= clock.m1)
719 for (clock.n = limit->n.min;
720 clock.n <= limit->n.max; clock.n++) {
721 for (clock.p1 = limit->p1.min;
722 clock.p1 <= limit->p1.max; clock.p1++) {
725 i9xx_calc_dpll_params(refclk, &clock);
726 if (!intel_pll_is_valid(to_i915(dev),
731 clock.p != match_clock->p)
734 this_err = abs(clock.dot - target);
735 if (this_err < err) {
744 return (err != target);
748 * Returns a set of divisors for the desired target clock with the given
749 * refclk, or FALSE. The returned values represent the clock equation:
750 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
752 * Target and reference clocks are specified in kHz.
754 * If match_clock is provided, then best_clock P divider must match the P
755 * divider from @match_clock used for LVDS downclocking.
758 pnv_find_best_dpll(const struct intel_limit *limit,
759 struct intel_crtc_state *crtc_state,
760 int target, int refclk, struct dpll *match_clock,
761 struct dpll *best_clock)
763 struct drm_device *dev = crtc_state->uapi.crtc->dev;
767 memset(best_clock, 0, sizeof(*best_clock));
769 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
771 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
773 for (clock.m2 = limit->m2.min;
774 clock.m2 <= limit->m2.max; clock.m2++) {
775 for (clock.n = limit->n.min;
776 clock.n <= limit->n.max; clock.n++) {
777 for (clock.p1 = limit->p1.min;
778 clock.p1 <= limit->p1.max; clock.p1++) {
781 pnv_calc_dpll_params(refclk, &clock);
782 if (!intel_pll_is_valid(to_i915(dev),
787 clock.p != match_clock->p)
790 this_err = abs(clock.dot - target);
791 if (this_err < err) {
800 return (err != target);
804 * Returns a set of divisors for the desired target clock with the given
805 * refclk, or FALSE. The returned values represent the clock equation:
806 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
808 * Target and reference clocks are specified in kHz.
810 * If match_clock is provided, then best_clock P divider must match the P
811 * divider from @match_clock used for LVDS downclocking.
814 g4x_find_best_dpll(const struct intel_limit *limit,
815 struct intel_crtc_state *crtc_state,
816 int target, int refclk, struct dpll *match_clock,
817 struct dpll *best_clock)
819 struct drm_device *dev = crtc_state->uapi.crtc->dev;
823 /* approximately equals target * 0.00585 */
824 int err_most = (target >> 8) + (target >> 9);
826 memset(best_clock, 0, sizeof(*best_clock));
828 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
830 max_n = limit->n.max;
831 /* based on hardware requirement, prefer smaller n to precision */
832 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
833 /* based on hardware requirement, prefere larger m1,m2 */
834 for (clock.m1 = limit->m1.max;
835 clock.m1 >= limit->m1.min; clock.m1--) {
836 for (clock.m2 = limit->m2.max;
837 clock.m2 >= limit->m2.min; clock.m2--) {
838 for (clock.p1 = limit->p1.max;
839 clock.p1 >= limit->p1.min; clock.p1--) {
842 i9xx_calc_dpll_params(refclk, &clock);
843 if (!intel_pll_is_valid(to_i915(dev),
848 this_err = abs(clock.dot - target);
849 if (this_err < err_most) {
863 * Check if the calculated PLL configuration is more optimal compared to the
864 * best configuration and error found so far. Return the calculated error.
866 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
867 const struct dpll *calculated_clock,
868 const struct dpll *best_clock,
869 unsigned int best_error_ppm,
870 unsigned int *error_ppm)
873 * For CHV ignore the error and consider only the P value.
874 * Prefer a bigger P value based on HW requirements.
876 if (IS_CHERRYVIEW(to_i915(dev))) {
879 return calculated_clock->p > best_clock->p;
882 if (drm_WARN_ON_ONCE(dev, !target_freq))
885 *error_ppm = div_u64(1000000ULL *
886 abs(target_freq - calculated_clock->dot),
889 * Prefer a better P value over a better (smaller) error if the error
890 * is small. Ensure this preference for future configurations too by
891 * setting the error to 0.
893 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
899 return *error_ppm + 10 < best_error_ppm;
903 * Returns a set of divisors for the desired target clock with the given
904 * refclk, or FALSE. The returned values represent the clock equation:
905 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
908 vlv_find_best_dpll(const struct intel_limit *limit,
909 struct intel_crtc_state *crtc_state,
910 int target, int refclk, struct dpll *match_clock,
911 struct dpll *best_clock)
913 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
914 struct drm_device *dev = crtc->base.dev;
916 unsigned int bestppm = 1000000;
917 /* min update 19.2 MHz */
918 int max_n = min(limit->n.max, refclk / 19200);
921 target *= 5; /* fast clock */
923 memset(best_clock, 0, sizeof(*best_clock));
925 /* based on hardware requirement, prefer smaller n to precision */
926 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
927 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
928 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
929 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
930 clock.p = clock.p1 * clock.p2;
931 /* based on hardware requirement, prefer bigger m1,m2 values */
932 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
935 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
938 vlv_calc_dpll_params(refclk, &clock);
940 if (!intel_pll_is_valid(to_i915(dev),
945 if (!vlv_PLL_is_optimal(dev, target,
963 * Returns a set of divisors for the desired target clock with the given
964 * refclk, or FALSE. The returned values represent the clock equation:
965 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
968 chv_find_best_dpll(const struct intel_limit *limit,
969 struct intel_crtc_state *crtc_state,
970 int target, int refclk, struct dpll *match_clock,
971 struct dpll *best_clock)
973 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
974 struct drm_device *dev = crtc->base.dev;
975 unsigned int best_error_ppm;
980 memset(best_clock, 0, sizeof(*best_clock));
981 best_error_ppm = 1000000;
984 * Based on hardware doc, the n always set to 1, and m1 always
985 * set to 2. If requires to support 200Mhz refclk, we need to
986 * revisit this because n may not 1 anymore.
988 clock.n = 1, clock.m1 = 2;
989 target *= 5; /* fast clock */
991 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
992 for (clock.p2 = limit->p2.p2_fast;
993 clock.p2 >= limit->p2.p2_slow;
994 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
995 unsigned int error_ppm;
997 clock.p = clock.p1 * clock.p2;
999 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
1002 if (m2 > INT_MAX/clock.m1)
1007 chv_calc_dpll_params(refclk, &clock);
1009 if (!intel_pll_is_valid(to_i915(dev), limit, &clock))
1012 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
1013 best_error_ppm, &error_ppm))
1016 *best_clock = clock;
1017 best_error_ppm = error_ppm;
1025 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
1026 struct dpll *best_clock)
1028 int refclk = 100000;
1029 const struct intel_limit *limit = &intel_limits_bxt;
1031 return chv_find_best_dpll(limit, crtc_state,
1032 crtc_state->port_clock, refclk,
1036 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1039 i915_reg_t reg = PIPEDSL(pipe);
1043 if (IS_GEN(dev_priv, 2))
1044 line_mask = DSL_LINEMASK_GEN2;
1046 line_mask = DSL_LINEMASK_GEN3;
1048 line1 = intel_de_read(dev_priv, reg) & line_mask;
1050 line2 = intel_de_read(dev_priv, reg) & line_mask;
1052 return line1 != line2;
1055 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1057 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1058 enum pipe pipe = crtc->pipe;
1060 /* Wait for the display line to settle/start moving */
1061 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1062 drm_err(&dev_priv->drm,
1063 "pipe %c scanline %s wait timed out\n",
1064 pipe_name(pipe), onoff(state));
1067 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1069 wait_for_pipe_scanline_moving(crtc, false);
1072 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1074 wait_for_pipe_scanline_moving(crtc, true);
1078 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1080 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1081 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1083 if (INTEL_GEN(dev_priv) >= 4) {
1084 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1085 i915_reg_t reg = PIPECONF(cpu_transcoder);
1087 /* Wait for the Pipe State to go off */
1088 if (intel_de_wait_for_clear(dev_priv, reg,
1089 I965_PIPECONF_ACTIVE, 100))
1090 drm_WARN(&dev_priv->drm, 1,
1091 "pipe_off wait timed out\n");
1093 intel_wait_for_pipe_scanline_stopped(crtc);
1097 /* Only for pre-ILK configs */
1098 void assert_pll(struct drm_i915_private *dev_priv,
1099 enum pipe pipe, bool state)
1104 val = intel_de_read(dev_priv, DPLL(pipe));
1105 cur_state = !!(val & DPLL_VCO_ENABLE);
1106 I915_STATE_WARN(cur_state != state,
1107 "PLL state assertion failure (expected %s, current %s)\n",
1108 onoff(state), onoff(cur_state));
1111 /* XXX: the dsi pll is shared between MIPI DSI ports */
1112 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1117 vlv_cck_get(dev_priv);
1118 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1119 vlv_cck_put(dev_priv);
1121 cur_state = val & DSI_PLL_VCO_EN;
1122 I915_STATE_WARN(cur_state != state,
1123 "DSI PLL state assertion failure (expected %s, current %s)\n",
1124 onoff(state), onoff(cur_state));
1127 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1128 enum pipe pipe, bool state)
1132 if (HAS_DDI(dev_priv)) {
1134 * DDI does not have a specific FDI_TX register.
1136 * FDI is never fed from EDP transcoder
1137 * so pipe->transcoder cast is fine here.
1139 enum transcoder cpu_transcoder = (enum transcoder)pipe;
1140 u32 val = intel_de_read(dev_priv,
1141 TRANS_DDI_FUNC_CTL(cpu_transcoder));
1142 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1144 u32 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
1145 cur_state = !!(val & FDI_TX_ENABLE);
1147 I915_STATE_WARN(cur_state != state,
1148 "FDI TX state assertion failure (expected %s, current %s)\n",
1149 onoff(state), onoff(cur_state));
1151 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1152 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1154 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1155 enum pipe pipe, bool state)
1160 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
1161 cur_state = !!(val & FDI_RX_ENABLE);
1162 I915_STATE_WARN(cur_state != state,
1163 "FDI RX state assertion failure (expected %s, current %s)\n",
1164 onoff(state), onoff(cur_state));
1166 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1167 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1169 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1174 /* ILK FDI PLL is always enabled */
1175 if (IS_GEN(dev_priv, 5))
1178 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1179 if (HAS_DDI(dev_priv))
1182 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
1183 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1186 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1187 enum pipe pipe, bool state)
1192 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
1193 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1194 I915_STATE_WARN(cur_state != state,
1195 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1196 onoff(state), onoff(cur_state));
1199 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1203 enum pipe panel_pipe = INVALID_PIPE;
1206 if (drm_WARN_ON(&dev_priv->drm, HAS_DDI(dev_priv)))
1209 if (HAS_PCH_SPLIT(dev_priv)) {
1212 pp_reg = PP_CONTROL(0);
1213 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1216 case PANEL_PORT_SELECT_LVDS:
1217 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1219 case PANEL_PORT_SELECT_DPA:
1220 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1222 case PANEL_PORT_SELECT_DPC:
1223 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1225 case PANEL_PORT_SELECT_DPD:
1226 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1229 MISSING_CASE(port_sel);
1232 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1233 /* presumably write lock depends on pipe, not port select */
1234 pp_reg = PP_CONTROL(pipe);
1239 pp_reg = PP_CONTROL(0);
1240 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1242 drm_WARN_ON(&dev_priv->drm,
1243 port_sel != PANEL_PORT_SELECT_LVDS);
1244 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1247 val = intel_de_read(dev_priv, pp_reg);
1248 if (!(val & PANEL_POWER_ON) ||
1249 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1252 I915_STATE_WARN(panel_pipe == pipe && locked,
1253 "panel assertion failure, pipe %c regs locked\n",
1257 void assert_pipe(struct drm_i915_private *dev_priv,
1258 enum transcoder cpu_transcoder, bool state)
1261 enum intel_display_power_domain power_domain;
1262 intel_wakeref_t wakeref;
1264 /* we keep both pipes enabled on 830 */
1265 if (IS_I830(dev_priv))
1268 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1269 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1271 u32 val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
1272 cur_state = !!(val & PIPECONF_ENABLE);
1274 intel_display_power_put(dev_priv, power_domain, wakeref);
1279 I915_STATE_WARN(cur_state != state,
1280 "transcoder %s assertion failure (expected %s, current %s)\n",
1281 transcoder_name(cpu_transcoder),
1282 onoff(state), onoff(cur_state));
1285 static void assert_plane(struct intel_plane *plane, bool state)
1290 cur_state = plane->get_hw_state(plane, &pipe);
1292 I915_STATE_WARN(cur_state != state,
1293 "%s assertion failure (expected %s, current %s)\n",
1294 plane->base.name, onoff(state), onoff(cur_state));
1297 #define assert_plane_enabled(p) assert_plane(p, true)
1298 #define assert_plane_disabled(p) assert_plane(p, false)
1300 static void assert_planes_disabled(struct intel_crtc *crtc)
1302 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1303 struct intel_plane *plane;
1305 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1306 assert_plane_disabled(plane);
1309 static void assert_vblank_disabled(struct drm_crtc *crtc)
1311 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1312 drm_crtc_vblank_put(crtc);
1315 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1321 val = intel_de_read(dev_priv, PCH_TRANSCONF(pipe));
1322 enabled = !!(val & TRANS_ENABLE);
1323 I915_STATE_WARN(enabled,
1324 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1328 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1329 enum pipe pipe, enum port port,
1332 enum pipe port_pipe;
1335 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1337 I915_STATE_WARN(state && port_pipe == pipe,
1338 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1339 port_name(port), pipe_name(pipe));
1341 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1342 "IBX PCH DP %c still using transcoder B\n",
1346 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1347 enum pipe pipe, enum port port,
1348 i915_reg_t hdmi_reg)
1350 enum pipe port_pipe;
1353 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1355 I915_STATE_WARN(state && port_pipe == pipe,
1356 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1357 port_name(port), pipe_name(pipe));
1359 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1360 "IBX PCH HDMI %c still using transcoder B\n",
1364 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1367 enum pipe port_pipe;
1369 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1370 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1371 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1373 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1375 "PCH VGA enabled on transcoder %c, should be disabled\n",
1378 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1380 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1383 /* PCH SDVOB multiplex with HDMIB */
1384 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1385 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1386 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1389 static void _vlv_enable_pll(struct intel_crtc *crtc,
1390 const struct intel_crtc_state *pipe_config)
1392 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1393 enum pipe pipe = crtc->pipe;
1395 intel_de_write(dev_priv, DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1396 intel_de_posting_read(dev_priv, DPLL(pipe));
1399 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1400 drm_err(&dev_priv->drm, "DPLL %d failed to lock\n", pipe);
1403 static void vlv_enable_pll(struct intel_crtc *crtc,
1404 const struct intel_crtc_state *pipe_config)
1406 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1407 enum pipe pipe = crtc->pipe;
1409 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1411 /* PLL is protected by panel, make sure we can write it */
1412 assert_panel_unlocked(dev_priv, pipe);
1414 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1415 _vlv_enable_pll(crtc, pipe_config);
1417 intel_de_write(dev_priv, DPLL_MD(pipe),
1418 pipe_config->dpll_hw_state.dpll_md);
1419 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
1423 static void _chv_enable_pll(struct intel_crtc *crtc,
1424 const struct intel_crtc_state *pipe_config)
1426 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1427 enum pipe pipe = crtc->pipe;
1428 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1431 vlv_dpio_get(dev_priv);
1433 /* Enable back the 10bit clock to display controller */
1434 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1435 tmp |= DPIO_DCLKP_EN;
1436 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1438 vlv_dpio_put(dev_priv);
1441 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1446 intel_de_write(dev_priv, DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1448 /* Check PLL is locked */
1449 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1450 drm_err(&dev_priv->drm, "PLL %d failed to lock\n", pipe);
1453 static void chv_enable_pll(struct intel_crtc *crtc,
1454 const struct intel_crtc_state *pipe_config)
1456 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1457 enum pipe pipe = crtc->pipe;
1459 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1461 /* PLL is protected by panel, make sure we can write it */
1462 assert_panel_unlocked(dev_priv, pipe);
1464 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1465 _chv_enable_pll(crtc, pipe_config);
1467 if (pipe != PIPE_A) {
1469 * WaPixelRepeatModeFixForC0:chv
1471 * DPLLCMD is AWOL. Use chicken bits to propagate
1472 * the value from DPLLBMD to either pipe B or C.
1474 intel_de_write(dev_priv, CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1475 intel_de_write(dev_priv, DPLL_MD(PIPE_B),
1476 pipe_config->dpll_hw_state.dpll_md);
1477 intel_de_write(dev_priv, CBR4_VLV, 0);
1478 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1481 * DPLLB VGA mode also seems to cause problems.
1482 * We should always have it disabled.
1484 drm_WARN_ON(&dev_priv->drm,
1485 (intel_de_read(dev_priv, DPLL(PIPE_B)) &
1486 DPLL_VGA_MODE_DIS) == 0);
1488 intel_de_write(dev_priv, DPLL_MD(pipe),
1489 pipe_config->dpll_hw_state.dpll_md);
1490 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
1494 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1496 if (IS_I830(dev_priv))
1499 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1502 static void i9xx_enable_pll(struct intel_crtc *crtc,
1503 const struct intel_crtc_state *crtc_state)
1505 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1506 i915_reg_t reg = DPLL(crtc->pipe);
1507 u32 dpll = crtc_state->dpll_hw_state.dpll;
1510 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1512 /* PLL is protected by panel, make sure we can write it */
1513 if (i9xx_has_pps(dev_priv))
1514 assert_panel_unlocked(dev_priv, crtc->pipe);
1517 * Apparently we need to have VGA mode enabled prior to changing
1518 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1519 * dividers, even though the register value does change.
1521 intel_de_write(dev_priv, reg, dpll & ~DPLL_VGA_MODE_DIS);
1522 intel_de_write(dev_priv, reg, dpll);
1524 /* Wait for the clocks to stabilize. */
1525 intel_de_posting_read(dev_priv, reg);
1528 if (INTEL_GEN(dev_priv) >= 4) {
1529 intel_de_write(dev_priv, DPLL_MD(crtc->pipe),
1530 crtc_state->dpll_hw_state.dpll_md);
1532 /* The pixel multiplier can only be updated once the
1533 * DPLL is enabled and the clocks are stable.
1535 * So write it again.
1537 intel_de_write(dev_priv, reg, dpll);
1540 /* We do this three times for luck */
1541 for (i = 0; i < 3; i++) {
1542 intel_de_write(dev_priv, reg, dpll);
1543 intel_de_posting_read(dev_priv, reg);
1544 udelay(150); /* wait for warmup */
1548 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1550 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1551 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1552 enum pipe pipe = crtc->pipe;
1554 /* Don't disable pipe or pipe PLLs if needed */
1555 if (IS_I830(dev_priv))
1558 /* Make sure the pipe isn't still relying on us */
1559 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1561 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
1562 intel_de_posting_read(dev_priv, DPLL(pipe));
1565 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1569 /* Make sure the pipe isn't still relying on us */
1570 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1572 val = DPLL_INTEGRATED_REF_CLK_VLV |
1573 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1575 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1577 intel_de_write(dev_priv, DPLL(pipe), val);
1578 intel_de_posting_read(dev_priv, DPLL(pipe));
1581 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1583 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1586 /* Make sure the pipe isn't still relying on us */
1587 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1589 val = DPLL_SSC_REF_CLK_CHV |
1590 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1592 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1594 intel_de_write(dev_priv, DPLL(pipe), val);
1595 intel_de_posting_read(dev_priv, DPLL(pipe));
1597 vlv_dpio_get(dev_priv);
1599 /* Disable 10bit clock to display controller */
1600 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1601 val &= ~DPIO_DCLKP_EN;
1602 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1604 vlv_dpio_put(dev_priv);
1607 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1608 struct intel_digital_port *dport,
1609 unsigned int expected_mask)
1612 i915_reg_t dpll_reg;
1614 switch (dport->base.port) {
1616 port_mask = DPLL_PORTB_READY_MASK;
1620 port_mask = DPLL_PORTC_READY_MASK;
1622 expected_mask <<= 4;
1625 port_mask = DPLL_PORTD_READY_MASK;
1626 dpll_reg = DPIO_PHY_STATUS;
1632 if (intel_de_wait_for_register(dev_priv, dpll_reg,
1633 port_mask, expected_mask, 1000))
1634 drm_WARN(&dev_priv->drm, 1,
1635 "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 intel_de_read(dev_priv, dpll_reg) & port_mask,
1641 static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1643 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1644 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1645 enum pipe pipe = crtc->pipe;
1647 u32 val, pipeconf_val;
1649 /* Make sure PCH DPLL is enabled */
1650 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1652 /* FDI must be feeding us bits for PCH ports */
1653 assert_fdi_tx_enabled(dev_priv, pipe);
1654 assert_fdi_rx_enabled(dev_priv, pipe);
1656 if (HAS_PCH_CPT(dev_priv)) {
1657 reg = TRANS_CHICKEN2(pipe);
1658 val = intel_de_read(dev_priv, reg);
1660 * Workaround: Set the timing override bit
1661 * before enabling the pch transcoder.
1663 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1664 /* Configure frame start delay to match the CPU */
1665 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1666 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1667 intel_de_write(dev_priv, reg, val);
1670 reg = PCH_TRANSCONF(pipe);
1671 val = intel_de_read(dev_priv, reg);
1672 pipeconf_val = intel_de_read(dev_priv, PIPECONF(pipe));
1674 if (HAS_PCH_IBX(dev_priv)) {
1675 /* Configure frame start delay to match the CPU */
1676 val &= ~TRANS_FRAME_START_DELAY_MASK;
1677 val |= TRANS_FRAME_START_DELAY(0);
1680 * Make the BPC in transcoder be consistent with
1681 * that in pipeconf reg. For HDMI we must use 8bpc
1682 * here for both 8bpc and 12bpc.
1684 val &= ~PIPECONF_BPC_MASK;
1685 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1686 val |= PIPECONF_8BPC;
1688 val |= pipeconf_val & PIPECONF_BPC_MASK;
1691 val &= ~TRANS_INTERLACE_MASK;
1692 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
1693 if (HAS_PCH_IBX(dev_priv) &&
1694 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1695 val |= TRANS_LEGACY_INTERLACED_ILK;
1697 val |= TRANS_INTERLACED;
1699 val |= TRANS_PROGRESSIVE;
1702 intel_de_write(dev_priv, reg, val | TRANS_ENABLE);
1703 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
1704 drm_err(&dev_priv->drm, "failed to enable transcoder %c\n",
1708 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1709 enum transcoder cpu_transcoder)
1711 u32 val, pipeconf_val;
1713 /* FDI must be feeding us bits for PCH ports */
1714 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1715 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1717 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
1718 /* Workaround: set timing override bit. */
1719 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1720 /* Configure frame start delay to match the CPU */
1721 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1722 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1723 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
1726 pipeconf_val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
1728 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1729 PIPECONF_INTERLACED_ILK)
1730 val |= TRANS_INTERLACED;
1732 val |= TRANS_PROGRESSIVE;
1734 intel_de_write(dev_priv, LPT_TRANSCONF, val);
1735 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
1736 TRANS_STATE_ENABLE, 100))
1737 drm_err(&dev_priv->drm, "Failed to enable PCH transcoder\n");
1740 static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1746 /* FDI relies on the transcoder */
1747 assert_fdi_tx_disabled(dev_priv, pipe);
1748 assert_fdi_rx_disabled(dev_priv, pipe);
1750 /* Ports must be off as well */
1751 assert_pch_ports_disabled(dev_priv, pipe);
1753 reg = PCH_TRANSCONF(pipe);
1754 val = intel_de_read(dev_priv, reg);
1755 val &= ~TRANS_ENABLE;
1756 intel_de_write(dev_priv, reg, val);
1757 /* wait for PCH transcoder off, transcoder state */
1758 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
1759 drm_err(&dev_priv->drm, "failed to disable transcoder %c\n",
1762 if (HAS_PCH_CPT(dev_priv)) {
1763 /* Workaround: Clear the timing override chicken bit again. */
1764 reg = TRANS_CHICKEN2(pipe);
1765 val = intel_de_read(dev_priv, reg);
1766 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1767 intel_de_write(dev_priv, reg, val);
1771 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1775 val = intel_de_read(dev_priv, LPT_TRANSCONF);
1776 val &= ~TRANS_ENABLE;
1777 intel_de_write(dev_priv, LPT_TRANSCONF, val);
1778 /* wait for PCH transcoder off, transcoder state */
1779 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
1780 TRANS_STATE_ENABLE, 50))
1781 drm_err(&dev_priv->drm, "Failed to disable PCH transcoder\n");
1783 /* Workaround: clear timing override bit. */
1784 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
1785 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1786 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
1789 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1791 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1793 if (HAS_PCH_LPT(dev_priv))
1799 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1801 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1804 * On i965gm the hardware frame counter reads
1805 * zero when the TV encoder is enabled :(
1807 if (IS_I965GM(dev_priv) &&
1808 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1811 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1812 return 0xffffffff; /* full 32 bit counter */
1813 else if (INTEL_GEN(dev_priv) >= 3)
1814 return 0xffffff; /* only 24 bits of frame count */
1816 return 0; /* Gen2 doesn't have a hardware frame counter */
1819 void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1821 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1823 assert_vblank_disabled(&crtc->base);
1824 drm_crtc_set_max_vblank_count(&crtc->base,
1825 intel_crtc_max_vblank_count(crtc_state));
1826 drm_crtc_vblank_on(&crtc->base);
1829 void intel_crtc_vblank_off(const struct intel_crtc_state *crtc_state)
1831 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1833 drm_crtc_vblank_off(&crtc->base);
1834 assert_vblank_disabled(&crtc->base);
1837 void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1839 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
1840 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1841 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1842 enum pipe pipe = crtc->pipe;
1846 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
1848 assert_planes_disabled(crtc);
1851 * A pipe without a PLL won't actually be able to drive bits from
1852 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1855 if (HAS_GMCH(dev_priv)) {
1856 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1857 assert_dsi_pll_enabled(dev_priv);
1859 assert_pll_enabled(dev_priv, pipe);
1861 if (new_crtc_state->has_pch_encoder) {
1862 /* if driving the PCH, we need FDI enabled */
1863 assert_fdi_rx_pll_enabled(dev_priv,
1864 intel_crtc_pch_transcoder(crtc));
1865 assert_fdi_tx_pll_enabled(dev_priv,
1866 (enum pipe) cpu_transcoder);
1868 /* FIXME: assert CPU port conditions for SNB+ */
1871 trace_intel_pipe_enable(crtc);
1873 reg = PIPECONF(cpu_transcoder);
1874 val = intel_de_read(dev_priv, reg);
1875 if (val & PIPECONF_ENABLE) {
1876 /* we keep both pipes enabled on 830 */
1877 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
1881 intel_de_write(dev_priv, reg, val | PIPECONF_ENABLE);
1882 intel_de_posting_read(dev_priv, reg);
1885 * Until the pipe starts PIPEDSL reads will return a stale value,
1886 * which causes an apparent vblank timestamp jump when PIPEDSL
1887 * resets to its proper value. That also messes up the frame count
1888 * when it's derived from the timestamps. So let's wait for the
1889 * pipe to start properly before we call drm_crtc_vblank_on()
1891 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1892 intel_wait_for_pipe_scanline_moving(crtc);
1895 void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1897 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1898 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1899 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1900 enum pipe pipe = crtc->pipe;
1904 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
1907 * Make sure planes won't keep trying to pump pixels to us,
1908 * or we might hang the display.
1910 assert_planes_disabled(crtc);
1912 trace_intel_pipe_disable(crtc);
1914 reg = PIPECONF(cpu_transcoder);
1915 val = intel_de_read(dev_priv, reg);
1916 if ((val & PIPECONF_ENABLE) == 0)
1920 * Double wide has implications for planes
1921 * so best keep it disabled when not needed.
1923 if (old_crtc_state->double_wide)
1924 val &= ~PIPECONF_DOUBLE_WIDE;
1926 /* Don't disable pipe or pipe PLLs if needed */
1927 if (!IS_I830(dev_priv))
1928 val &= ~PIPECONF_ENABLE;
1930 intel_de_write(dev_priv, reg, val);
1931 if ((val & PIPECONF_ENABLE) == 0)
1932 intel_wait_for_pipe_off(old_crtc_state);
1935 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1937 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1940 static bool is_ccs_plane(const struct drm_framebuffer *fb, int plane)
1942 if (!is_ccs_modifier(fb->modifier))
1945 return plane >= fb->format->num_planes / 2;
1948 static bool is_gen12_ccs_modifier(u64 modifier)
1950 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
1951 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
1955 static bool is_gen12_ccs_plane(const struct drm_framebuffer *fb, int plane)
1957 return is_gen12_ccs_modifier(fb->modifier) && is_ccs_plane(fb, plane);
1960 static bool is_aux_plane(const struct drm_framebuffer *fb, int plane)
1962 if (is_ccs_modifier(fb->modifier))
1963 return is_ccs_plane(fb, plane);
1968 static int main_to_ccs_plane(const struct drm_framebuffer *fb, int main_plane)
1970 WARN_ON(!is_ccs_modifier(fb->modifier) ||
1971 (main_plane && main_plane >= fb->format->num_planes / 2));
1973 return fb->format->num_planes / 2 + main_plane;
1976 static int ccs_to_main_plane(const struct drm_framebuffer *fb, int ccs_plane)
1978 WARN_ON(!is_ccs_modifier(fb->modifier) ||
1979 ccs_plane < fb->format->num_planes / 2);
1981 return ccs_plane - fb->format->num_planes / 2;
1984 /* Return either the main plane's CCS or - if not a CCS FB - UV plane */
1985 int intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane)
1987 if (is_ccs_modifier(fb->modifier))
1988 return main_to_ccs_plane(fb, main_plane);
1994 intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
1997 return info->is_yuv &&
1998 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
2001 static bool is_semiplanar_uv_plane(const struct drm_framebuffer *fb,
2004 return intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
2009 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
2011 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2012 unsigned int cpp = fb->format->cpp[color_plane];
2014 switch (fb->modifier) {
2015 case DRM_FORMAT_MOD_LINEAR:
2016 return intel_tile_size(dev_priv);
2017 case I915_FORMAT_MOD_X_TILED:
2018 if (IS_GEN(dev_priv, 2))
2022 case I915_FORMAT_MOD_Y_TILED_CCS:
2023 if (is_ccs_plane(fb, color_plane))
2026 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2027 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2028 if (is_ccs_plane(fb, color_plane))
2031 case I915_FORMAT_MOD_Y_TILED:
2032 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
2036 case I915_FORMAT_MOD_Yf_TILED_CCS:
2037 if (is_ccs_plane(fb, color_plane))
2040 case I915_FORMAT_MOD_Yf_TILED:
2056 MISSING_CASE(fb->modifier);
2062 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
2064 if (is_gen12_ccs_plane(fb, color_plane))
2067 return intel_tile_size(to_i915(fb->dev)) /
2068 intel_tile_width_bytes(fb, color_plane);
2071 /* Return the tile dimensions in pixel units */
2072 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
2073 unsigned int *tile_width,
2074 unsigned int *tile_height)
2076 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
2077 unsigned int cpp = fb->format->cpp[color_plane];
2079 *tile_width = tile_width_bytes / cpp;
2080 *tile_height = intel_tile_height(fb, color_plane);
2083 static unsigned int intel_tile_row_size(const struct drm_framebuffer *fb,
2086 unsigned int tile_width, tile_height;
2088 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2090 return fb->pitches[color_plane] * tile_height;
2094 intel_fb_align_height(const struct drm_framebuffer *fb,
2095 int color_plane, unsigned int height)
2097 unsigned int tile_height = intel_tile_height(fb, color_plane);
2099 return ALIGN(height, tile_height);
2102 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2104 unsigned int size = 0;
2107 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2108 size += rot_info->plane[i].width * rot_info->plane[i].height;
2113 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
2115 unsigned int size = 0;
2118 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
2119 size += rem_info->plane[i].width * rem_info->plane[i].height;
2125 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2126 const struct drm_framebuffer *fb,
2127 unsigned int rotation)
2129 view->type = I915_GGTT_VIEW_NORMAL;
2130 if (drm_rotation_90_or_270(rotation)) {
2131 view->type = I915_GGTT_VIEW_ROTATED;
2132 view->rotated = to_intel_framebuffer(fb)->rot_info;
2136 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2138 if (IS_I830(dev_priv))
2140 else if (IS_I85X(dev_priv))
2142 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2148 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2150 if (INTEL_GEN(dev_priv) >= 9)
2152 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2153 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2155 else if (INTEL_GEN(dev_priv) >= 4)
2161 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2164 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2166 /* AUX_DIST needs only 4K alignment */
2167 if ((INTEL_GEN(dev_priv) < 12 && is_aux_plane(fb, color_plane)) ||
2168 is_ccs_plane(fb, color_plane))
2171 switch (fb->modifier) {
2172 case DRM_FORMAT_MOD_LINEAR:
2173 return intel_linear_alignment(dev_priv);
2174 case I915_FORMAT_MOD_X_TILED:
2175 if (INTEL_GEN(dev_priv) >= 9)
2178 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2179 if (is_semiplanar_uv_plane(fb, color_plane))
2180 return intel_tile_row_size(fb, color_plane);
2182 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2184 case I915_FORMAT_MOD_Y_TILED_CCS:
2185 case I915_FORMAT_MOD_Yf_TILED_CCS:
2186 case I915_FORMAT_MOD_Y_TILED:
2187 if (INTEL_GEN(dev_priv) >= 12 &&
2188 is_semiplanar_uv_plane(fb, color_plane))
2189 return intel_tile_row_size(fb, color_plane);
2191 case I915_FORMAT_MOD_Yf_TILED:
2192 return 1 * 1024 * 1024;
2194 MISSING_CASE(fb->modifier);
2199 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2201 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2202 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2204 return INTEL_GEN(dev_priv) < 4 ||
2206 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
2210 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2211 const struct i915_ggtt_view *view,
2213 unsigned long *out_flags)
2215 struct drm_device *dev = fb->dev;
2216 struct drm_i915_private *dev_priv = to_i915(dev);
2217 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2218 intel_wakeref_t wakeref;
2219 struct i915_vma *vma;
2220 unsigned int pinctl;
2223 if (drm_WARN_ON(dev, !i915_gem_object_is_framebuffer(obj)))
2224 return ERR_PTR(-EINVAL);
2226 alignment = intel_surf_alignment(fb, 0);
2227 if (drm_WARN_ON(dev, alignment && !is_power_of_2(alignment)))
2228 return ERR_PTR(-EINVAL);
2230 /* Note that the w/a also requires 64 PTE of padding following the
2231 * bo. We currently fill all unused PTE with the shadow page and so
2232 * we should always have valid PTE following the scanout preventing
2235 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2236 alignment = 256 * 1024;
2239 * Global gtt pte registers are special registers which actually forward
2240 * writes to a chunk of system memory. Which means that there is no risk
2241 * that the register values disappear as soon as we call
2242 * intel_runtime_pm_put(), so it is correct to wrap only the
2243 * pin/unpin/fence and not more.
2245 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
2247 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2250 * Valleyview is definitely limited to scanning out the first
2251 * 512MiB. Lets presume this behaviour was inherited from the
2252 * g4x display engine and that all earlier gen are similarly
2253 * limited. Testing suggests that it is a little more
2254 * complicated than this. For example, Cherryview appears quite
2255 * happy to scanout from anywhere within its global aperture.
2258 if (HAS_GMCH(dev_priv))
2259 pinctl |= PIN_MAPPABLE;
2261 vma = i915_gem_object_pin_to_display_plane(obj,
2262 alignment, view, pinctl);
2266 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2270 * Install a fence for tiled scan-out. Pre-i965 always needs a
2271 * fence, whereas 965+ only requires a fence if using
2272 * framebuffer compression. For simplicity, we always, when
2273 * possible, install a fence as the cost is not that onerous.
2275 * If we fail to fence the tiled scanout, then either the
2276 * modeset will reject the change (which is highly unlikely as
2277 * the affected systems, all but one, do not have unmappable
2278 * space) or we will not be able to enable full powersaving
2279 * techniques (also likely not to apply due to various limits
2280 * FBC and the like impose on the size of the buffer, which
2281 * presumably we violated anyway with this unmappable buffer).
2282 * Anyway, it is presumably better to stumble onwards with
2283 * something and try to run the system in a "less than optimal"
2284 * mode that matches the user configuration.
2286 ret = i915_vma_pin_fence(vma);
2287 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2288 i915_gem_object_unpin_from_display_plane(vma);
2293 if (ret == 0 && vma->fence)
2294 *out_flags |= PLANE_HAS_FENCE;
2299 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2300 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
2304 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2306 i915_gem_object_lock(vma->obj);
2307 if (flags & PLANE_HAS_FENCE)
2308 i915_vma_unpin_fence(vma);
2309 i915_gem_object_unpin_from_display_plane(vma);
2310 i915_gem_object_unlock(vma->obj);
2315 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2316 unsigned int rotation)
2318 if (drm_rotation_90_or_270(rotation))
2319 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2321 return fb->pitches[color_plane];
2325 * Convert the x/y offsets into a linear offset.
2326 * Only valid with 0/180 degree rotation, which is fine since linear
2327 * offset is only used with linear buffers on pre-hsw and tiled buffers
2328 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2330 u32 intel_fb_xy_to_linear(int x, int y,
2331 const struct intel_plane_state *state,
2334 const struct drm_framebuffer *fb = state->hw.fb;
2335 unsigned int cpp = fb->format->cpp[color_plane];
2336 unsigned int pitch = state->color_plane[color_plane].stride;
2338 return y * pitch + x * cpp;
2342 * Add the x/y offsets derived from fb->offsets[] to the user
2343 * specified plane src x/y offsets. The resulting x/y offsets
2344 * specify the start of scanout from the beginning of the gtt mapping.
2346 void intel_add_fb_offsets(int *x, int *y,
2347 const struct intel_plane_state *state,
2351 *x += state->color_plane[color_plane].x;
2352 *y += state->color_plane[color_plane].y;
2355 static u32 intel_adjust_tile_offset(int *x, int *y,
2356 unsigned int tile_width,
2357 unsigned int tile_height,
2358 unsigned int tile_size,
2359 unsigned int pitch_tiles,
2363 unsigned int pitch_pixels = pitch_tiles * tile_width;
2366 WARN_ON(old_offset & (tile_size - 1));
2367 WARN_ON(new_offset & (tile_size - 1));
2368 WARN_ON(new_offset > old_offset);
2370 tiles = (old_offset - new_offset) / tile_size;
2372 *y += tiles / pitch_tiles * tile_height;
2373 *x += tiles % pitch_tiles * tile_width;
2375 /* minimize x in case it got needlessly big */
2376 *y += *x / pitch_pixels * tile_height;
2382 static bool is_surface_linear(const struct drm_framebuffer *fb, int color_plane)
2384 return fb->modifier == DRM_FORMAT_MOD_LINEAR ||
2385 is_gen12_ccs_plane(fb, color_plane);
2388 static u32 intel_adjust_aligned_offset(int *x, int *y,
2389 const struct drm_framebuffer *fb,
2391 unsigned int rotation,
2393 u32 old_offset, u32 new_offset)
2395 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2396 unsigned int cpp = fb->format->cpp[color_plane];
2398 drm_WARN_ON(&dev_priv->drm, new_offset > old_offset);
2400 if (!is_surface_linear(fb, color_plane)) {
2401 unsigned int tile_size, tile_width, tile_height;
2402 unsigned int pitch_tiles;
2404 tile_size = intel_tile_size(dev_priv);
2405 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2407 if (drm_rotation_90_or_270(rotation)) {
2408 pitch_tiles = pitch / tile_height;
2409 swap(tile_width, tile_height);
2411 pitch_tiles = pitch / (tile_width * cpp);
2414 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2415 tile_size, pitch_tiles,
2416 old_offset, new_offset);
2418 old_offset += *y * pitch + *x * cpp;
2420 *y = (old_offset - new_offset) / pitch;
2421 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2428 * Adjust the tile offset by moving the difference into
2431 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2432 const struct intel_plane_state *state,
2434 u32 old_offset, u32 new_offset)
2436 return intel_adjust_aligned_offset(x, y, state->hw.fb, color_plane,
2438 state->color_plane[color_plane].stride,
2439 old_offset, new_offset);
2443 * Computes the aligned offset to the base tile and adjusts
2444 * x, y. bytes per pixel is assumed to be a power-of-two.
2446 * In the 90/270 rotated case, x and y are assumed
2447 * to be already rotated to match the rotated GTT view, and
2448 * pitch is the tile_height aligned framebuffer height.
2450 * This function is used when computing the derived information
2451 * under intel_framebuffer, so using any of that information
2452 * here is not allowed. Anything under drm_framebuffer can be
2453 * used. This is why the user has to pass in the pitch since it
2454 * is specified in the rotated orientation.
2456 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2458 const struct drm_framebuffer *fb,
2461 unsigned int rotation,
2464 unsigned int cpp = fb->format->cpp[color_plane];
2465 u32 offset, offset_aligned;
2467 if (!is_surface_linear(fb, color_plane)) {
2468 unsigned int tile_size, tile_width, tile_height;
2469 unsigned int tile_rows, tiles, pitch_tiles;
2471 tile_size = intel_tile_size(dev_priv);
2472 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2474 if (drm_rotation_90_or_270(rotation)) {
2475 pitch_tiles = pitch / tile_height;
2476 swap(tile_width, tile_height);
2478 pitch_tiles = pitch / (tile_width * cpp);
2481 tile_rows = *y / tile_height;
2484 tiles = *x / tile_width;
2487 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2489 offset_aligned = offset;
2491 offset_aligned = rounddown(offset_aligned, alignment);
2493 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2494 tile_size, pitch_tiles,
2495 offset, offset_aligned);
2497 offset = *y * pitch + *x * cpp;
2498 offset_aligned = offset;
2500 offset_aligned = rounddown(offset_aligned, alignment);
2501 *y = (offset % alignment) / pitch;
2502 *x = ((offset % alignment) - *y * pitch) / cpp;
2508 return offset_aligned;
2511 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2512 const struct intel_plane_state *state,
2515 struct intel_plane *intel_plane = to_intel_plane(state->uapi.plane);
2516 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2517 const struct drm_framebuffer *fb = state->hw.fb;
2518 unsigned int rotation = state->hw.rotation;
2519 int pitch = state->color_plane[color_plane].stride;
2522 if (intel_plane->id == PLANE_CURSOR)
2523 alignment = intel_cursor_alignment(dev_priv);
2525 alignment = intel_surf_alignment(fb, color_plane);
2527 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2528 pitch, rotation, alignment);
2531 /* Convert the fb->offset[] into x/y offsets */
2532 static int intel_fb_offset_to_xy(int *x, int *y,
2533 const struct drm_framebuffer *fb,
2536 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2537 unsigned int height;
2540 if (INTEL_GEN(dev_priv) >= 12 &&
2541 is_semiplanar_uv_plane(fb, color_plane))
2542 alignment = intel_tile_row_size(fb, color_plane);
2543 else if (fb->modifier != DRM_FORMAT_MOD_LINEAR)
2544 alignment = intel_tile_size(dev_priv);
2548 if (alignment != 0 && fb->offsets[color_plane] % alignment) {
2549 drm_dbg_kms(&dev_priv->drm,
2550 "Misaligned offset 0x%08x for color plane %d\n",
2551 fb->offsets[color_plane], color_plane);
2555 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2556 height = ALIGN(height, intel_tile_height(fb, color_plane));
2558 /* Catch potential overflows early */
2559 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2560 fb->offsets[color_plane])) {
2561 drm_dbg_kms(&dev_priv->drm,
2562 "Bad offset 0x%08x or pitch %d for color plane %d\n",
2563 fb->offsets[color_plane], fb->pitches[color_plane],
2571 intel_adjust_aligned_offset(x, y,
2572 fb, color_plane, DRM_MODE_ROTATE_0,
2573 fb->pitches[color_plane],
2574 fb->offsets[color_plane], 0);
2579 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2581 switch (fb_modifier) {
2582 case I915_FORMAT_MOD_X_TILED:
2583 return I915_TILING_X;
2584 case I915_FORMAT_MOD_Y_TILED:
2585 case I915_FORMAT_MOD_Y_TILED_CCS:
2586 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2587 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2588 return I915_TILING_Y;
2590 return I915_TILING_NONE;
2595 * From the Sky Lake PRM:
2596 * "The Color Control Surface (CCS) contains the compression status of
2597 * the cache-line pairs. The compression state of the cache-line pair
2598 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2599 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2600 * cache-line-pairs. CCS is always Y tiled."
2602 * Since cache line pairs refers to horizontally adjacent cache lines,
2603 * each cache line in the CCS corresponds to an area of 32x16 cache
2604 * lines on the main surface. Since each pixel is 4 bytes, this gives
2605 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2608 static const struct drm_format_info skl_ccs_formats[] = {
2609 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2610 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2611 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2612 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2613 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2614 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2615 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2616 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2620 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
2621 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
2622 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
2623 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
2626 static const struct drm_format_info gen12_ccs_formats[] = {
2627 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2628 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2629 .hsub = 1, .vsub = 1, },
2630 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2631 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2632 .hsub = 1, .vsub = 1, },
2633 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2634 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2635 .hsub = 1, .vsub = 1, .has_alpha = true },
2636 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2637 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2638 .hsub = 1, .vsub = 1, .has_alpha = true },
2639 { .format = DRM_FORMAT_YUYV, .num_planes = 2,
2640 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2641 .hsub = 2, .vsub = 1, .is_yuv = true },
2642 { .format = DRM_FORMAT_YVYU, .num_planes = 2,
2643 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2644 .hsub = 2, .vsub = 1, .is_yuv = true },
2645 { .format = DRM_FORMAT_UYVY, .num_planes = 2,
2646 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2647 .hsub = 2, .vsub = 1, .is_yuv = true },
2648 { .format = DRM_FORMAT_VYUY, .num_planes = 2,
2649 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2650 .hsub = 2, .vsub = 1, .is_yuv = true },
2651 { .format = DRM_FORMAT_NV12, .num_planes = 4,
2652 .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 },
2653 .hsub = 2, .vsub = 2, .is_yuv = true },
2654 { .format = DRM_FORMAT_P010, .num_planes = 4,
2655 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2656 .hsub = 2, .vsub = 2, .is_yuv = true },
2657 { .format = DRM_FORMAT_P012, .num_planes = 4,
2658 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2659 .hsub = 2, .vsub = 2, .is_yuv = true },
2660 { .format = DRM_FORMAT_P016, .num_planes = 4,
2661 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2662 .hsub = 2, .vsub = 2, .is_yuv = true },
2665 static const struct drm_format_info *
2666 lookup_format_info(const struct drm_format_info formats[],
2667 int num_formats, u32 format)
2671 for (i = 0; i < num_formats; i++) {
2672 if (formats[i].format == format)
2679 static const struct drm_format_info *
2680 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2682 switch (cmd->modifier[0]) {
2683 case I915_FORMAT_MOD_Y_TILED_CCS:
2684 case I915_FORMAT_MOD_Yf_TILED_CCS:
2685 return lookup_format_info(skl_ccs_formats,
2686 ARRAY_SIZE(skl_ccs_formats),
2688 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2689 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2690 return lookup_format_info(gen12_ccs_formats,
2691 ARRAY_SIZE(gen12_ccs_formats),
2698 bool is_ccs_modifier(u64 modifier)
2700 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
2701 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS ||
2702 modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2703 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2706 static int gen12_ccs_aux_stride(struct drm_framebuffer *fb, int ccs_plane)
2708 return DIV_ROUND_UP(fb->pitches[ccs_to_main_plane(fb, ccs_plane)],
2712 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
2713 u32 pixel_format, u64 modifier)
2715 struct intel_crtc *crtc;
2716 struct intel_plane *plane;
2719 * We assume the primary plane for pipe A has
2720 * the highest stride limits of them all,
2721 * if in case pipe A is disabled, use the first pipe from pipe_mask.
2723 crtc = intel_get_first_crtc(dev_priv);
2727 plane = to_intel_plane(crtc->base.primary);
2729 return plane->max_stride(plane, pixel_format, modifier,
2734 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
2735 u32 pixel_format, u64 modifier)
2738 * Arbitrary limit for gen4+ chosen to match the
2739 * render engine max stride.
2741 * The new CCS hash mode makes remapping impossible
2743 if (!is_ccs_modifier(modifier)) {
2744 if (INTEL_GEN(dev_priv) >= 7)
2746 else if (INTEL_GEN(dev_priv) >= 4)
2750 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
2754 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
2756 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2759 if (is_surface_linear(fb, color_plane)) {
2760 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
2765 * To make remapping with linear generally feasible
2766 * we need the stride to be page aligned.
2768 if (fb->pitches[color_plane] > max_stride &&
2769 !is_ccs_modifier(fb->modifier))
2770 return intel_tile_size(dev_priv);
2775 tile_width = intel_tile_width_bytes(fb, color_plane);
2776 if (is_ccs_modifier(fb->modifier)) {
2778 * Display WA #0531: skl,bxt,kbl,glk
2780 * Render decompression and plane width > 3840
2781 * combined with horizontal panning requires the
2782 * plane stride to be a multiple of 4. We'll just
2783 * require the entire fb to accommodate that to avoid
2784 * potential runtime errors at plane configuration time.
2786 if (IS_GEN(dev_priv, 9) && color_plane == 0 && fb->width > 3840)
2789 * The main surface pitch must be padded to a multiple of four
2792 else if (INTEL_GEN(dev_priv) >= 12)
2798 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
2800 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2801 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2802 const struct drm_framebuffer *fb = plane_state->hw.fb;
2805 /* We don't want to deal with remapping with cursors */
2806 if (plane->id == PLANE_CURSOR)
2810 * The display engine limits already match/exceed the
2811 * render engine limits, so not much point in remapping.
2812 * Would also need to deal with the fence POT alignment
2813 * and gen2 2KiB GTT tile size.
2815 if (INTEL_GEN(dev_priv) < 4)
2819 * The new CCS hash mode isn't compatible with remapping as
2820 * the virtual address of the pages affects the compressed data.
2822 if (is_ccs_modifier(fb->modifier))
2825 /* Linear needs a page aligned stride for remapping */
2826 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2827 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2829 for (i = 0; i < fb->format->num_planes; i++) {
2830 if (fb->pitches[i] & alignment)
2838 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2840 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2841 const struct drm_framebuffer *fb = plane_state->hw.fb;
2842 unsigned int rotation = plane_state->hw.rotation;
2843 u32 stride, max_stride;
2846 * No remapping for invisible planes since we don't have
2847 * an actual source viewport to remap.
2849 if (!plane_state->uapi.visible)
2852 if (!intel_plane_can_remap(plane_state))
2856 * FIXME: aux plane limits on gen9+ are
2857 * unclear in Bspec, for now no checking.
2859 stride = intel_fb_pitch(fb, 0, rotation);
2860 max_stride = plane->max_stride(plane, fb->format->format,
2861 fb->modifier, rotation);
2863 return stride > max_stride;
2867 intel_fb_plane_get_subsampling(int *hsub, int *vsub,
2868 const struct drm_framebuffer *fb,
2873 if (color_plane == 0) {
2881 * TODO: Deduct the subsampling from the char block for all CCS
2882 * formats and planes.
2884 if (!is_gen12_ccs_plane(fb, color_plane)) {
2885 *hsub = fb->format->hsub;
2886 *vsub = fb->format->vsub;
2891 main_plane = ccs_to_main_plane(fb, color_plane);
2892 *hsub = drm_format_info_block_width(fb->format, color_plane) /
2893 drm_format_info_block_width(fb->format, main_plane);
2896 * The min stride check in the core framebuffer_check() function
2897 * assumes that format->hsub applies to every plane except for the
2898 * first plane. That's incorrect for the CCS AUX plane of the first
2899 * plane, but for the above check to pass we must define the block
2900 * width with that subsampling applied to it. Adjust the width here
2901 * accordingly, so we can calculate the actual subsampling factor.
2903 if (main_plane == 0)
2904 *hsub *= fb->format->hsub;
2909 intel_fb_check_ccs_xy(struct drm_framebuffer *fb, int ccs_plane, int x, int y)
2911 struct drm_i915_private *i915 = to_i915(fb->dev);
2912 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2915 int tile_width, tile_height;
2919 if (!is_ccs_plane(fb, ccs_plane))
2922 intel_tile_dims(fb, ccs_plane, &tile_width, &tile_height);
2923 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
2926 tile_height *= vsub;
2928 ccs_x = (x * hsub) % tile_width;
2929 ccs_y = (y * vsub) % tile_height;
2931 main_plane = ccs_to_main_plane(fb, ccs_plane);
2932 main_x = intel_fb->normal[main_plane].x % tile_width;
2933 main_y = intel_fb->normal[main_plane].y % tile_height;
2936 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2937 * x/y offsets must match between CCS and the main surface.
2939 if (main_x != ccs_x || main_y != ccs_y) {
2940 drm_dbg_kms(&i915->drm,
2941 "Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2944 intel_fb->normal[main_plane].x,
2945 intel_fb->normal[main_plane].y,
2954 intel_fb_plane_dims(int *w, int *h, struct drm_framebuffer *fb, int color_plane)
2956 int main_plane = is_ccs_plane(fb, color_plane) ?
2957 ccs_to_main_plane(fb, color_plane) : 0;
2958 int main_hsub, main_vsub;
2961 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb, main_plane);
2962 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, color_plane);
2963 *w = fb->width / main_hsub / hsub;
2964 *h = fb->height / main_vsub / vsub;
2968 * Setup the rotated view for an FB plane and return the size the GTT mapping
2969 * requires for this view.
2972 setup_fb_rotation(int plane, const struct intel_remapped_plane_info *plane_info,
2973 u32 gtt_offset_rotated, int x, int y,
2974 unsigned int width, unsigned int height,
2975 unsigned int tile_size,
2976 unsigned int tile_width, unsigned int tile_height,
2977 struct drm_framebuffer *fb)
2979 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2980 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2981 unsigned int pitch_tiles;
2984 /* Y or Yf modifiers required for 90/270 rotation */
2985 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
2986 fb->modifier != I915_FORMAT_MOD_Yf_TILED)
2989 if (WARN_ON(plane >= ARRAY_SIZE(rot_info->plane)))
2992 rot_info->plane[plane] = *plane_info;
2994 intel_fb->rotated[plane].pitch = plane_info->height * tile_height;
2996 /* rotate the x/y offsets to match the GTT view */
2997 drm_rect_init(&r, x, y, width, height);
2999 plane_info->width * tile_width,
3000 plane_info->height * tile_height,
3001 DRM_MODE_ROTATE_270);
3005 /* rotate the tile dimensions to match the GTT view */
3006 pitch_tiles = intel_fb->rotated[plane].pitch / tile_height;
3007 swap(tile_width, tile_height);
3010 * We only keep the x/y offsets, so push all of the
3011 * gtt offset into the x/y offsets.
3013 intel_adjust_tile_offset(&x, &y,
3014 tile_width, tile_height,
3015 tile_size, pitch_tiles,
3016 gtt_offset_rotated * tile_size, 0);
3019 * First pixel of the framebuffer from
3020 * the start of the rotated gtt mapping.
3022 intel_fb->rotated[plane].x = x;
3023 intel_fb->rotated[plane].y = y;
3025 return plane_info->width * plane_info->height;
3029 intel_fill_fb_info(struct drm_i915_private *dev_priv,
3030 struct drm_framebuffer *fb)
3032 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
3033 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
3034 u32 gtt_offset_rotated = 0;
3035 unsigned int max_size = 0;
3036 int i, num_planes = fb->format->num_planes;
3037 unsigned int tile_size = intel_tile_size(dev_priv);
3039 for (i = 0; i < num_planes; i++) {
3040 unsigned int width, height;
3041 unsigned int cpp, size;
3046 cpp = fb->format->cpp[i];
3047 intel_fb_plane_dims(&width, &height, fb, i);
3049 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
3051 drm_dbg_kms(&dev_priv->drm,
3052 "bad fb plane %d offset: 0x%x\n",
3057 ret = intel_fb_check_ccs_xy(fb, i, x, y);
3062 * The fence (if used) is aligned to the start of the object
3063 * so having the framebuffer wrap around across the edge of the
3064 * fenced region doesn't really work. We have no API to configure
3065 * the fence start offset within the object (nor could we probably
3066 * on gen2/3). So it's just easier if we just require that the
3067 * fb layout agrees with the fence layout. We already check that the
3068 * fb stride matches the fence stride elsewhere.
3070 if (i == 0 && i915_gem_object_is_tiled(obj) &&
3071 (x + width) * cpp > fb->pitches[i]) {
3072 drm_dbg_kms(&dev_priv->drm,
3073 "bad fb plane %d offset: 0x%x\n",
3079 * First pixel of the framebuffer from
3080 * the start of the normal gtt mapping.
3082 intel_fb->normal[i].x = x;
3083 intel_fb->normal[i].y = y;
3085 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
3089 offset /= tile_size;
3091 if (!is_surface_linear(fb, i)) {
3092 struct intel_remapped_plane_info plane_info;
3093 unsigned int tile_width, tile_height;
3095 intel_tile_dims(fb, i, &tile_width, &tile_height);
3097 plane_info.offset = offset;
3098 plane_info.stride = DIV_ROUND_UP(fb->pitches[i],
3100 plane_info.width = DIV_ROUND_UP(x + width, tile_width);
3101 plane_info.height = DIV_ROUND_UP(y + height,
3104 /* how many tiles does this plane need */
3105 size = plane_info.stride * plane_info.height;
3107 * If the plane isn't horizontally tile aligned,
3108 * we need one more tile.
3113 gtt_offset_rotated +=
3114 setup_fb_rotation(i, &plane_info,
3116 x, y, width, height,
3118 tile_width, tile_height,
3121 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
3122 x * cpp, tile_size);
3125 /* how many tiles in total needed in the bo */
3126 max_size = max(max_size, offset + size);
3129 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
3130 drm_dbg_kms(&dev_priv->drm,
3131 "fb too big for bo (need %llu bytes, have %zu bytes)\n",
3132 mul_u32_u32(max_size, tile_size), obj->base.size);
3140 intel_plane_remap_gtt(struct intel_plane_state *plane_state)
3142 struct drm_i915_private *dev_priv =
3143 to_i915(plane_state->uapi.plane->dev);
3144 struct drm_framebuffer *fb = plane_state->hw.fb;
3145 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
3146 struct intel_rotation_info *info = &plane_state->view.rotated;
3147 unsigned int rotation = plane_state->hw.rotation;
3148 int i, num_planes = fb->format->num_planes;
3149 unsigned int tile_size = intel_tile_size(dev_priv);
3150 unsigned int src_x, src_y;
3151 unsigned int src_w, src_h;
3154 memset(&plane_state->view, 0, sizeof(plane_state->view));
3155 plane_state->view.type = drm_rotation_90_or_270(rotation) ?
3156 I915_GGTT_VIEW_ROTATED : I915_GGTT_VIEW_REMAPPED;
3158 src_x = plane_state->uapi.src.x1 >> 16;
3159 src_y = plane_state->uapi.src.y1 >> 16;
3160 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
3161 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
3163 drm_WARN_ON(&dev_priv->drm, is_ccs_modifier(fb->modifier));
3165 /* Make src coordinates relative to the viewport */
3166 drm_rect_translate(&plane_state->uapi.src,
3167 -(src_x << 16), -(src_y << 16));
3169 /* Rotate src coordinates to match rotated GTT view */
3170 if (drm_rotation_90_or_270(rotation))
3171 drm_rect_rotate(&plane_state->uapi.src,
3172 src_w << 16, src_h << 16,
3173 DRM_MODE_ROTATE_270);
3175 for (i = 0; i < num_planes; i++) {
3176 unsigned int hsub = i ? fb->format->hsub : 1;
3177 unsigned int vsub = i ? fb->format->vsub : 1;
3178 unsigned int cpp = fb->format->cpp[i];
3179 unsigned int tile_width, tile_height;
3180 unsigned int width, height;
3181 unsigned int pitch_tiles;
3185 intel_tile_dims(fb, i, &tile_width, &tile_height);
3189 width = src_w / hsub;
3190 height = src_h / vsub;
3193 * First pixel of the src viewport from the
3194 * start of the normal gtt mapping.
3196 x += intel_fb->normal[i].x;
3197 y += intel_fb->normal[i].y;
3199 offset = intel_compute_aligned_offset(dev_priv, &x, &y,
3200 fb, i, fb->pitches[i],
3201 DRM_MODE_ROTATE_0, tile_size);
3202 offset /= tile_size;
3204 drm_WARN_ON(&dev_priv->drm, i >= ARRAY_SIZE(info->plane));
3205 info->plane[i].offset = offset;
3206 info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
3208 info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
3209 info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
3211 if (drm_rotation_90_or_270(rotation)) {
3214 /* rotate the x/y offsets to match the GTT view */
3215 drm_rect_init(&r, x, y, width, height);
3217 info->plane[i].width * tile_width,
3218 info->plane[i].height * tile_height,
3219 DRM_MODE_ROTATE_270);
3223 pitch_tiles = info->plane[i].height;
3224 plane_state->color_plane[i].stride = pitch_tiles * tile_height;
3226 /* rotate the tile dimensions to match the GTT view */
3227 swap(tile_width, tile_height);
3229 pitch_tiles = info->plane[i].width;
3230 plane_state->color_plane[i].stride = pitch_tiles * tile_width * cpp;
3234 * We only keep the x/y offsets, so push all of the
3235 * gtt offset into the x/y offsets.
3237 intel_adjust_tile_offset(&x, &y,
3238 tile_width, tile_height,
3239 tile_size, pitch_tiles,
3240 gtt_offset * tile_size, 0);
3242 gtt_offset += info->plane[i].width * info->plane[i].height;
3244 plane_state->color_plane[i].offset = 0;
3245 plane_state->color_plane[i].x = x;
3246 plane_state->color_plane[i].y = y;
3251 intel_plane_compute_gtt(struct intel_plane_state *plane_state)
3253 const struct intel_framebuffer *fb =
3254 to_intel_framebuffer(plane_state->hw.fb);
3255 unsigned int rotation = plane_state->hw.rotation;
3261 num_planes = fb->base.format->num_planes;
3263 if (intel_plane_needs_remap(plane_state)) {
3264 intel_plane_remap_gtt(plane_state);
3267 * Sometimes even remapping can't overcome
3268 * the stride limitations :( Can happen with
3269 * big plane sizes and suitably misaligned
3272 return intel_plane_check_stride(plane_state);
3275 intel_fill_fb_ggtt_view(&plane_state->view, &fb->base, rotation);
3277 for (i = 0; i < num_planes; i++) {
3278 plane_state->color_plane[i].stride = intel_fb_pitch(&fb->base, i, rotation);
3279 plane_state->color_plane[i].offset = 0;
3281 if (drm_rotation_90_or_270(rotation)) {
3282 plane_state->color_plane[i].x = fb->rotated[i].x;
3283 plane_state->color_plane[i].y = fb->rotated[i].y;
3285 plane_state->color_plane[i].x = fb->normal[i].x;
3286 plane_state->color_plane[i].y = fb->normal[i].y;
3290 /* Rotate src coordinates to match rotated GTT view */
3291 if (drm_rotation_90_or_270(rotation))
3292 drm_rect_rotate(&plane_state->uapi.src,
3293 fb->base.width << 16, fb->base.height << 16,
3294 DRM_MODE_ROTATE_270);
3296 return intel_plane_check_stride(plane_state);
3299 static int i9xx_format_to_fourcc(int format)
3302 case DISPPLANE_8BPP:
3303 return DRM_FORMAT_C8;
3304 case DISPPLANE_BGRA555:
3305 return DRM_FORMAT_ARGB1555;
3306 case DISPPLANE_BGRX555:
3307 return DRM_FORMAT_XRGB1555;
3308 case DISPPLANE_BGRX565:
3309 return DRM_FORMAT_RGB565;
3311 case DISPPLANE_BGRX888:
3312 return DRM_FORMAT_XRGB8888;
3313 case DISPPLANE_RGBX888:
3314 return DRM_FORMAT_XBGR8888;
3315 case DISPPLANE_BGRA888:
3316 return DRM_FORMAT_ARGB8888;
3317 case DISPPLANE_RGBA888:
3318 return DRM_FORMAT_ABGR8888;
3319 case DISPPLANE_BGRX101010:
3320 return DRM_FORMAT_XRGB2101010;
3321 case DISPPLANE_RGBX101010:
3322 return DRM_FORMAT_XBGR2101010;
3323 case DISPPLANE_BGRA101010:
3324 return DRM_FORMAT_ARGB2101010;
3325 case DISPPLANE_RGBA101010:
3326 return DRM_FORMAT_ABGR2101010;
3327 case DISPPLANE_RGBX161616:
3328 return DRM_FORMAT_XBGR16161616F;
3332 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
3335 case PLANE_CTL_FORMAT_RGB_565:
3336 return DRM_FORMAT_RGB565;
3337 case PLANE_CTL_FORMAT_NV12:
3338 return DRM_FORMAT_NV12;
3339 case PLANE_CTL_FORMAT_P010:
3340 return DRM_FORMAT_P010;
3341 case PLANE_CTL_FORMAT_P012:
3342 return DRM_FORMAT_P012;
3343 case PLANE_CTL_FORMAT_P016:
3344 return DRM_FORMAT_P016;
3345 case PLANE_CTL_FORMAT_Y210:
3346 return DRM_FORMAT_Y210;
3347 case PLANE_CTL_FORMAT_Y212:
3348 return DRM_FORMAT_Y212;
3349 case PLANE_CTL_FORMAT_Y216:
3350 return DRM_FORMAT_Y216;
3351 case PLANE_CTL_FORMAT_Y410:
3352 return DRM_FORMAT_XVYU2101010;
3353 case PLANE_CTL_FORMAT_Y412:
3354 return DRM_FORMAT_XVYU12_16161616;
3355 case PLANE_CTL_FORMAT_Y416:
3356 return DRM_FORMAT_XVYU16161616;
3358 case PLANE_CTL_FORMAT_XRGB_8888:
3361 return DRM_FORMAT_ABGR8888;
3363 return DRM_FORMAT_XBGR8888;
3366 return DRM_FORMAT_ARGB8888;
3368 return DRM_FORMAT_XRGB8888;
3370 case PLANE_CTL_FORMAT_XRGB_2101010:
3373 return DRM_FORMAT_ABGR2101010;
3375 return DRM_FORMAT_XBGR2101010;
3378 return DRM_FORMAT_ARGB2101010;
3380 return DRM_FORMAT_XRGB2101010;
3382 case PLANE_CTL_FORMAT_XRGB_16161616F:
3385 return DRM_FORMAT_ABGR16161616F;
3387 return DRM_FORMAT_XBGR16161616F;
3390 return DRM_FORMAT_ARGB16161616F;
3392 return DRM_FORMAT_XRGB16161616F;
3397 static struct i915_vma *
3398 initial_plane_vma(struct drm_i915_private *i915,
3399 struct intel_initial_plane_config *plane_config)
3401 struct drm_i915_gem_object *obj;
3402 struct i915_vma *vma;
3405 if (plane_config->size == 0)
3408 base = round_down(plane_config->base,
3409 I915_GTT_MIN_ALIGNMENT);
3410 size = round_up(plane_config->base + plane_config->size,
3411 I915_GTT_MIN_ALIGNMENT);
3415 * If the FB is too big, just don't use it since fbdev is not very
3416 * important and we should probably use that space with FBC or other
3419 if (size * 2 > i915->stolen_usable_size)
3422 obj = i915_gem_object_create_stolen_for_preallocated(i915, base, size);
3426 switch (plane_config->tiling) {
3427 case I915_TILING_NONE:
3431 obj->tiling_and_stride =
3432 plane_config->fb->base.pitches[0] |
3433 plane_config->tiling;
3436 MISSING_CASE(plane_config->tiling);
3440 vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL);
3444 if (i915_ggtt_pin(vma, 0, PIN_MAPPABLE | PIN_OFFSET_FIXED | base))
3447 if (i915_gem_object_is_tiled(obj) &&
3448 !i915_vma_is_map_and_fenceable(vma))
3454 i915_gem_object_put(obj);
3459 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
3460 struct intel_initial_plane_config *plane_config)
3462 struct drm_device *dev = crtc->base.dev;
3463 struct drm_i915_private *dev_priv = to_i915(dev);
3464 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
3465 struct drm_framebuffer *fb = &plane_config->fb->base;
3466 struct i915_vma *vma;
3468 switch (fb->modifier) {
3469 case DRM_FORMAT_MOD_LINEAR:
3470 case I915_FORMAT_MOD_X_TILED:
3471 case I915_FORMAT_MOD_Y_TILED:
3474 drm_dbg(&dev_priv->drm,
3475 "Unsupported modifier for initial FB: 0x%llx\n",
3480 vma = initial_plane_vma(dev_priv, plane_config);
3484 mode_cmd.pixel_format = fb->format->format;
3485 mode_cmd.width = fb->width;
3486 mode_cmd.height = fb->height;
3487 mode_cmd.pitches[0] = fb->pitches[0];
3488 mode_cmd.modifier[0] = fb->modifier;
3489 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
3491 if (intel_framebuffer_init(to_intel_framebuffer(fb),
3492 vma->obj, &mode_cmd)) {
3493 drm_dbg_kms(&dev_priv->drm, "intel fb init failed\n");
3497 plane_config->vma = vma;
3506 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
3507 struct intel_plane_state *plane_state,
3510 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3512 plane_state->uapi.visible = visible;
3515 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
3517 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
3520 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
3522 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3523 struct drm_plane *plane;
3526 * Active_planes aliases if multiple "primary" or cursor planes
3527 * have been used on the same (or wrong) pipe. plane_mask uses
3528 * unique ids, hence we can use that to reconstruct active_planes.
3530 crtc_state->active_planes = 0;
3532 drm_for_each_plane_mask(plane, &dev_priv->drm,
3533 crtc_state->uapi.plane_mask)
3534 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
3537 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
3538 struct intel_plane *plane)
3540 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3541 struct intel_crtc_state *crtc_state =
3542 to_intel_crtc_state(crtc->base.state);
3543 struct intel_plane_state *plane_state =
3544 to_intel_plane_state(plane->base.state);
3546 drm_dbg_kms(&dev_priv->drm,
3547 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
3548 plane->base.base.id, plane->base.name,
3549 crtc->base.base.id, crtc->base.name);
3551 intel_set_plane_visible(crtc_state, plane_state, false);
3552 fixup_active_planes(crtc_state);
3553 crtc_state->data_rate[plane->id] = 0;
3554 crtc_state->min_cdclk[plane->id] = 0;
3556 if (plane->id == PLANE_PRIMARY)
3557 hsw_disable_ips(crtc_state);
3560 * Vblank time updates from the shadow to live plane control register
3561 * are blocked if the memory self-refresh mode is active at that
3562 * moment. So to make sure the plane gets truly disabled, disable
3563 * first the self-refresh mode. The self-refresh enable bit in turn
3564 * will be checked/applied by the HW only at the next frame start
3565 * event which is after the vblank start event, so we need to have a
3566 * wait-for-vblank between disabling the plane and the pipe.
3568 if (HAS_GMCH(dev_priv) &&
3569 intel_set_memory_cxsr(dev_priv, false))
3570 intel_wait_for_vblank(dev_priv, crtc->pipe);
3573 * Gen2 reports pipe underruns whenever all planes are disabled.
3574 * So disable underrun reporting before all the planes get disabled.
3576 if (IS_GEN(dev_priv, 2) && !crtc_state->active_planes)
3577 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
3579 intel_disable_plane(plane, crtc_state);
3582 static struct intel_frontbuffer *
3583 to_intel_frontbuffer(struct drm_framebuffer *fb)
3585 return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
3589 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
3590 struct intel_initial_plane_config *plane_config)
3592 struct drm_device *dev = intel_crtc->base.dev;
3593 struct drm_i915_private *dev_priv = to_i915(dev);
3595 struct drm_plane *primary = intel_crtc->base.primary;
3596 struct drm_plane_state *plane_state = primary->state;
3597 struct intel_plane *intel_plane = to_intel_plane(primary);
3598 struct intel_plane_state *intel_state =
3599 to_intel_plane_state(plane_state);
3600 struct drm_framebuffer *fb;
3601 struct i915_vma *vma;
3603 if (!plane_config->fb)
3606 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
3607 fb = &plane_config->fb->base;
3608 vma = plane_config->vma;
3613 * Failed to alloc the obj, check to see if we should share
3614 * an fb with another CRTC instead
3616 for_each_crtc(dev, c) {
3617 struct intel_plane_state *state;
3619 if (c == &intel_crtc->base)
3622 if (!to_intel_crtc(c)->active)
3625 state = to_intel_plane_state(c->primary->state);
3629 if (intel_plane_ggtt_offset(state) == plane_config->base) {
3637 * We've failed to reconstruct the BIOS FB. Current display state
3638 * indicates that the primary plane is visible, but has a NULL FB,
3639 * which will lead to problems later if we don't fix it up. The
3640 * simplest solution is to just disable the primary plane now and
3641 * pretend the BIOS never had it enabled.
3643 intel_plane_disable_noatomic(intel_crtc, intel_plane);
3648 intel_state->hw.rotation = plane_config->rotation;
3649 intel_fill_fb_ggtt_view(&intel_state->view, fb,
3650 intel_state->hw.rotation);
3651 intel_state->color_plane[0].stride =
3652 intel_fb_pitch(fb, 0, intel_state->hw.rotation);
3654 __i915_vma_pin(vma);
3655 intel_state->vma = i915_vma_get(vma);
3656 if (intel_plane_uses_fence(intel_state) && i915_vma_pin_fence(vma) == 0)
3658 intel_state->flags |= PLANE_HAS_FENCE;
3660 plane_state->src_x = 0;
3661 plane_state->src_y = 0;
3662 plane_state->src_w = fb->width << 16;
3663 plane_state->src_h = fb->height << 16;
3665 plane_state->crtc_x = 0;
3666 plane_state->crtc_y = 0;
3667 plane_state->crtc_w = fb->width;
3668 plane_state->crtc_h = fb->height;
3670 intel_state->uapi.src = drm_plane_state_src(plane_state);
3671 intel_state->uapi.dst = drm_plane_state_dest(plane_state);
3673 if (plane_config->tiling)
3674 dev_priv->preserve_bios_swizzle = true;
3676 plane_state->fb = fb;
3677 drm_framebuffer_get(fb);
3679 plane_state->crtc = &intel_crtc->base;
3680 intel_plane_copy_uapi_to_hw_state(intel_state, intel_state);
3682 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
3684 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
3685 &to_intel_frontbuffer(fb)->bits);
3688 static int skl_max_plane_width(const struct drm_framebuffer *fb,
3690 unsigned int rotation)
3692 int cpp = fb->format->cpp[color_plane];
3694 switch (fb->modifier) {
3695 case DRM_FORMAT_MOD_LINEAR:
3696 case I915_FORMAT_MOD_X_TILED:
3698 * Validated limit is 4k, but has 5k should
3699 * work apart from the following features:
3700 * - Ytile (already limited to 4k)
3701 * - FP16 (already limited to 4k)
3702 * - render compression (already limited to 4k)
3703 * - KVMR sprite and cursor (don't care)
3704 * - horizontal panning (TODO verify this)
3705 * - pipe and plane scaling (TODO verify this)
3711 case I915_FORMAT_MOD_Y_TILED_CCS:
3712 case I915_FORMAT_MOD_Yf_TILED_CCS:
3713 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
3714 /* FIXME AUX plane? */
3715 case I915_FORMAT_MOD_Y_TILED:
3716 case I915_FORMAT_MOD_Yf_TILED:
3722 MISSING_CASE(fb->modifier);
3727 static int glk_max_plane_width(const struct drm_framebuffer *fb,
3729 unsigned int rotation)
3731 int cpp = fb->format->cpp[color_plane];
3733 switch (fb->modifier) {
3734 case DRM_FORMAT_MOD_LINEAR:
3735 case I915_FORMAT_MOD_X_TILED:
3740 case I915_FORMAT_MOD_Y_TILED_CCS:
3741 case I915_FORMAT_MOD_Yf_TILED_CCS:
3742 /* FIXME AUX plane? */
3743 case I915_FORMAT_MOD_Y_TILED:
3744 case I915_FORMAT_MOD_Yf_TILED:
3750 MISSING_CASE(fb->modifier);
3755 static int icl_max_plane_width(const struct drm_framebuffer *fb,
3757 unsigned int rotation)
3762 static int skl_max_plane_height(void)
3767 static int icl_max_plane_height(void)
3773 skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3774 int main_x, int main_y, u32 main_offset,
3777 const struct drm_framebuffer *fb = plane_state->hw.fb;
3778 int aux_x = plane_state->color_plane[ccs_plane].x;
3779 int aux_y = plane_state->color_plane[ccs_plane].y;
3780 u32 aux_offset = plane_state->color_plane[ccs_plane].offset;
3781 u32 alignment = intel_surf_alignment(fb, ccs_plane);
3785 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
3786 while (aux_offset >= main_offset && aux_y <= main_y) {
3789 if (aux_x == main_x && aux_y == main_y)
3792 if (aux_offset == 0)
3797 aux_offset = intel_plane_adjust_aligned_offset(&x, &y,
3803 aux_x = x * hsub + aux_x % hsub;
3804 aux_y = y * vsub + aux_y % vsub;
3807 if (aux_x != main_x || aux_y != main_y)
3810 plane_state->color_plane[ccs_plane].offset = aux_offset;
3811 plane_state->color_plane[ccs_plane].x = aux_x;
3812 plane_state->color_plane[ccs_plane].y = aux_y;
3817 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3819 struct drm_i915_private *dev_priv = to_i915(plane_state->uapi.plane->dev);
3820 const struct drm_framebuffer *fb = plane_state->hw.fb;
3821 unsigned int rotation = plane_state->hw.rotation;
3822 int x = plane_state->uapi.src.x1 >> 16;
3823 int y = plane_state->uapi.src.y1 >> 16;
3824 int w = drm_rect_width(&plane_state->uapi.src) >> 16;
3825 int h = drm_rect_height(&plane_state->uapi.src) >> 16;
3830 int aux_plane = intel_main_to_aux_plane(fb, 0);
3831 u32 aux_offset = plane_state->color_plane[aux_plane].offset;
3833 if (INTEL_GEN(dev_priv) >= 11)
3834 max_width = icl_max_plane_width(fb, 0, rotation);
3835 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3836 max_width = glk_max_plane_width(fb, 0, rotation);
3838 max_width = skl_max_plane_width(fb, 0, rotation);
3840 if (INTEL_GEN(dev_priv) >= 11)
3841 max_height = icl_max_plane_height();
3843 max_height = skl_max_plane_height();
3845 if (w > max_width || h > max_height) {
3846 drm_dbg_kms(&dev_priv->drm,
3847 "requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3848 w, h, max_width, max_height);
3852 intel_add_fb_offsets(&x, &y, plane_state, 0);
3853 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3854 alignment = intel_surf_alignment(fb, 0);
3855 if (drm_WARN_ON(&dev_priv->drm, alignment && !is_power_of_2(alignment)))
3859 * AUX surface offset is specified as the distance from the
3860 * main surface offset, and it must be non-negative. Make
3861 * sure that is what we will get.
3863 if (offset > aux_offset)
3864 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3865 offset, aux_offset & ~(alignment - 1));
3868 * When using an X-tiled surface, the plane blows up
3869 * if the x offset + width exceed the stride.
3871 * TODO: linear and Y-tiled seem fine, Yf untested,
3873 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3874 int cpp = fb->format->cpp[0];
3876 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3878 drm_dbg_kms(&dev_priv->drm,
3879 "Unable to find suitable display surface offset due to X-tiling\n");
3883 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3884 offset, offset - alignment);
3889 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3890 * they match with the main surface x/y offsets.
3892 if (is_ccs_modifier(fb->modifier)) {
3893 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
3894 offset, aux_plane)) {
3898 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3899 offset, offset - alignment);
3902 if (x != plane_state->color_plane[aux_plane].x ||
3903 y != plane_state->color_plane[aux_plane].y) {
3904 drm_dbg_kms(&dev_priv->drm,
3905 "Unable to find suitable display surface offset due to CCS\n");
3910 plane_state->color_plane[0].offset = offset;
3911 plane_state->color_plane[0].x = x;
3912 plane_state->color_plane[0].y = y;
3915 * Put the final coordinates back so that the src
3916 * coordinate checks will see the right values.
3918 drm_rect_translate_to(&plane_state->uapi.src,
3924 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3926 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
3927 const struct drm_framebuffer *fb = plane_state->hw.fb;
3928 unsigned int rotation = plane_state->hw.rotation;
3930 int max_width = skl_max_plane_width(fb, uv_plane, rotation);
3931 int max_height = 4096;
3932 int x = plane_state->uapi.src.x1 >> 17;
3933 int y = plane_state->uapi.src.y1 >> 17;
3934 int w = drm_rect_width(&plane_state->uapi.src) >> 17;
3935 int h = drm_rect_height(&plane_state->uapi.src) >> 17;
3938 intel_add_fb_offsets(&x, &y, plane_state, uv_plane);
3939 offset = intel_plane_compute_aligned_offset(&x, &y,
3940 plane_state, uv_plane);
3942 /* FIXME not quite sure how/if these apply to the chroma plane */
3943 if (w > max_width || h > max_height) {
3944 drm_dbg_kms(&i915->drm,
3945 "CbCr source size %dx%d too big (limit %dx%d)\n",
3946 w, h, max_width, max_height);
3950 if (is_ccs_modifier(fb->modifier)) {
3951 int ccs_plane = main_to_ccs_plane(fb, uv_plane);
3952 int aux_offset = plane_state->color_plane[ccs_plane].offset;
3953 int alignment = intel_surf_alignment(fb, uv_plane);
3955 if (offset > aux_offset)
3956 offset = intel_plane_adjust_aligned_offset(&x, &y,
3960 aux_offset & ~(alignment - 1));
3962 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
3963 offset, ccs_plane)) {
3967 offset = intel_plane_adjust_aligned_offset(&x, &y,
3970 offset, offset - alignment);
3973 if (x != plane_state->color_plane[ccs_plane].x ||
3974 y != plane_state->color_plane[ccs_plane].y) {
3975 drm_dbg_kms(&i915->drm,
3976 "Unable to find suitable display surface offset due to CCS\n");
3981 plane_state->color_plane[uv_plane].offset = offset;
3982 plane_state->color_plane[uv_plane].x = x;
3983 plane_state->color_plane[uv_plane].y = y;
3988 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3990 const struct drm_framebuffer *fb = plane_state->hw.fb;
3991 int src_x = plane_state->uapi.src.x1 >> 16;
3992 int src_y = plane_state->uapi.src.y1 >> 16;
3996 for (ccs_plane = 0; ccs_plane < fb->format->num_planes; ccs_plane++) {
3997 int main_hsub, main_vsub;
4001 if (!is_ccs_plane(fb, ccs_plane))
4004 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb,
4005 ccs_to_main_plane(fb, ccs_plane));
4006 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
4013 intel_add_fb_offsets(&x, &y, plane_state, ccs_plane);
4015 offset = intel_plane_compute_aligned_offset(&x, &y,
4019 plane_state->color_plane[ccs_plane].offset = offset;
4020 plane_state->color_plane[ccs_plane].x = (x * hsub +
4023 plane_state->color_plane[ccs_plane].y = (y * vsub +
4031 int skl_check_plane_surface(struct intel_plane_state *plane_state)
4033 const struct drm_framebuffer *fb = plane_state->hw.fb;
4035 bool needs_aux = false;
4037 ret = intel_plane_compute_gtt(plane_state);
4041 if (!plane_state->uapi.visible)
4045 * Handle the AUX surface first since the main surface setup depends on
4048 if (is_ccs_modifier(fb->modifier)) {
4050 ret = skl_check_ccs_aux_surface(plane_state);
4055 if (intel_format_info_is_yuv_semiplanar(fb->format,
4058 ret = skl_check_nv12_aux_surface(plane_state);
4066 for (i = 1; i < fb->format->num_planes; i++) {
4067 plane_state->color_plane[i].offset = ~0xfff;
4068 plane_state->color_plane[i].x = 0;
4069 plane_state->color_plane[i].y = 0;
4073 ret = skl_check_main_surface(plane_state);
4080 static void i9xx_plane_ratio(const struct intel_crtc_state *crtc_state,
4081 const struct intel_plane_state *plane_state,
4082 unsigned int *num, unsigned int *den)
4084 const struct drm_framebuffer *fb = plane_state->hw.fb;
4085 unsigned int cpp = fb->format->cpp[0];
4088 * g4x bspec says 64bpp pixel rate can't exceed 80%
4089 * of cdclk when the sprite plane is enabled on the
4090 * same pipe. ilk/snb bspec says 64bpp pixel rate is
4091 * never allowed to exceed 80% of cdclk. Let's just go
4092 * with the ilk/snb limit always.
4103 static int i9xx_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
4104 const struct intel_plane_state *plane_state)
4106 unsigned int pixel_rate;
4107 unsigned int num, den;
4110 * Note that crtc_state->pixel_rate accounts for both
4111 * horizontal and vertical panel fitter downscaling factors.
4112 * Pre-HSW bspec tells us to only consider the horizontal
4113 * downscaling factor here. We ignore that and just consider
4114 * both for simplicity.
4116 pixel_rate = crtc_state->pixel_rate;
4118 i9xx_plane_ratio(crtc_state, plane_state, &num, &den);
4120 /* two pixels per clock with double wide pipe */
4121 if (crtc_state->double_wide)
4124 return DIV_ROUND_UP(pixel_rate * num, den);
4128 i9xx_plane_max_stride(struct intel_plane *plane,
4129 u32 pixel_format, u64 modifier,
4130 unsigned int rotation)
4132 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4134 if (!HAS_GMCH(dev_priv)) {
4136 } else if (INTEL_GEN(dev_priv) >= 4) {
4137 if (modifier == I915_FORMAT_MOD_X_TILED)
4141 } else if (INTEL_GEN(dev_priv) >= 3) {
4142 if (modifier == I915_FORMAT_MOD_X_TILED)
4147 if (plane->i9xx_plane == PLANE_C)
4154 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4156 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4157 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4160 if (crtc_state->gamma_enable)
4161 dspcntr |= DISPPLANE_GAMMA_ENABLE;
4163 if (crtc_state->csc_enable)
4164 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
4166 if (INTEL_GEN(dev_priv) < 5)
4167 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
4172 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
4173 const struct intel_plane_state *plane_state)
4175 struct drm_i915_private *dev_priv =
4176 to_i915(plane_state->uapi.plane->dev);
4177 const struct drm_framebuffer *fb = plane_state->hw.fb;
4178 unsigned int rotation = plane_state->hw.rotation;
4181 dspcntr = DISPLAY_PLANE_ENABLE;
4183 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
4184 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
4185 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
4187 switch (fb->format->format) {
4189 dspcntr |= DISPPLANE_8BPP;
4191 case DRM_FORMAT_XRGB1555:
4192 dspcntr |= DISPPLANE_BGRX555;
4194 case DRM_FORMAT_ARGB1555:
4195 dspcntr |= DISPPLANE_BGRA555;
4197 case DRM_FORMAT_RGB565:
4198 dspcntr |= DISPPLANE_BGRX565;
4200 case DRM_FORMAT_XRGB8888:
4201 dspcntr |= DISPPLANE_BGRX888;
4203 case DRM_FORMAT_XBGR8888:
4204 dspcntr |= DISPPLANE_RGBX888;
4206 case DRM_FORMAT_ARGB8888:
4207 dspcntr |= DISPPLANE_BGRA888;
4209 case DRM_FORMAT_ABGR8888:
4210 dspcntr |= DISPPLANE_RGBA888;
4212 case DRM_FORMAT_XRGB2101010:
4213 dspcntr |= DISPPLANE_BGRX101010;
4215 case DRM_FORMAT_XBGR2101010:
4216 dspcntr |= DISPPLANE_RGBX101010;
4218 case DRM_FORMAT_ARGB2101010:
4219 dspcntr |= DISPPLANE_BGRA101010;
4221 case DRM_FORMAT_ABGR2101010:
4222 dspcntr |= DISPPLANE_RGBA101010;
4224 case DRM_FORMAT_XBGR16161616F:
4225 dspcntr |= DISPPLANE_RGBX161616;
4228 MISSING_CASE(fb->format->format);
4232 if (INTEL_GEN(dev_priv) >= 4 &&
4233 fb->modifier == I915_FORMAT_MOD_X_TILED)
4234 dspcntr |= DISPPLANE_TILED;
4236 if (rotation & DRM_MODE_ROTATE_180)
4237 dspcntr |= DISPPLANE_ROTATE_180;
4239 if (rotation & DRM_MODE_REFLECT_X)
4240 dspcntr |= DISPPLANE_MIRROR;
4245 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
4247 struct drm_i915_private *dev_priv =
4248 to_i915(plane_state->uapi.plane->dev);
4249 const struct drm_framebuffer *fb = plane_state->hw.fb;
4250 int src_x, src_y, src_w;
4254 ret = intel_plane_compute_gtt(plane_state);
4258 if (!plane_state->uapi.visible)
4261 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
4262 src_x = plane_state->uapi.src.x1 >> 16;
4263 src_y = plane_state->uapi.src.y1 >> 16;
4265 /* Undocumented hardware limit on i965/g4x/vlv/chv */
4266 if (HAS_GMCH(dev_priv) && fb->format->cpp[0] == 8 && src_w > 2048)
4269 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
4271 if (INTEL_GEN(dev_priv) >= 4)
4272 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
4278 * Put the final coordinates back so that the src
4279 * coordinate checks will see the right values.
4281 drm_rect_translate_to(&plane_state->uapi.src,
4282 src_x << 16, src_y << 16);
4284 /* HSW/BDW do this automagically in hardware */
4285 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
4286 unsigned int rotation = plane_state->hw.rotation;
4287 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
4288 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
4290 if (rotation & DRM_MODE_ROTATE_180) {
4293 } else if (rotation & DRM_MODE_REFLECT_X) {
4298 plane_state->color_plane[0].offset = offset;
4299 plane_state->color_plane[0].x = src_x;
4300 plane_state->color_plane[0].y = src_y;
4305 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
4307 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4308 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4310 if (IS_CHERRYVIEW(dev_priv))
4311 return i9xx_plane == PLANE_B;
4312 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
4314 else if (IS_GEN(dev_priv, 4))
4315 return i9xx_plane == PLANE_C;
4317 return i9xx_plane == PLANE_B ||
4318 i9xx_plane == PLANE_C;
4322 i9xx_plane_check(struct intel_crtc_state *crtc_state,
4323 struct intel_plane_state *plane_state)
4325 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
4328 ret = chv_plane_check_rotation(plane_state);
4332 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
4334 DRM_PLANE_HELPER_NO_SCALING,
4335 DRM_PLANE_HELPER_NO_SCALING,
4336 i9xx_plane_has_windowing(plane),
4341 ret = i9xx_check_plane_surface(plane_state);
4345 if (!plane_state->uapi.visible)
4348 ret = intel_plane_check_src_coordinates(plane_state);
4352 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
4357 static void i9xx_update_plane(struct intel_plane *plane,
4358 const struct intel_crtc_state *crtc_state,
4359 const struct intel_plane_state *plane_state)
4361 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4362 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4364 int x = plane_state->color_plane[0].x;
4365 int y = plane_state->color_plane[0].y;
4366 int crtc_x = plane_state->uapi.dst.x1;
4367 int crtc_y = plane_state->uapi.dst.y1;
4368 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
4369 int crtc_h = drm_rect_height(&plane_state->uapi.dst);
4370 unsigned long irqflags;
4374 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
4376 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
4378 if (INTEL_GEN(dev_priv) >= 4)
4379 dspaddr_offset = plane_state->color_plane[0].offset;
4381 dspaddr_offset = linear_offset;
4383 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4385 intel_de_write_fw(dev_priv, DSPSTRIDE(i9xx_plane),
4386 plane_state->color_plane[0].stride);
4388 if (INTEL_GEN(dev_priv) < 4) {
4390 * PLANE_A doesn't actually have a full window
4391 * generator but let's assume we still need to
4392 * program whatever is there.
4394 intel_de_write_fw(dev_priv, DSPPOS(i9xx_plane),
4395 (crtc_y << 16) | crtc_x);
4396 intel_de_write_fw(dev_priv, DSPSIZE(i9xx_plane),
4397 ((crtc_h - 1) << 16) | (crtc_w - 1));
4398 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
4399 intel_de_write_fw(dev_priv, PRIMPOS(i9xx_plane),
4400 (crtc_y << 16) | crtc_x);
4401 intel_de_write_fw(dev_priv, PRIMSIZE(i9xx_plane),
4402 ((crtc_h - 1) << 16) | (crtc_w - 1));
4403 intel_de_write_fw(dev_priv, PRIMCNSTALPHA(i9xx_plane), 0);
4406 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
4407 intel_de_write_fw(dev_priv, DSPOFFSET(i9xx_plane),
4409 } else if (INTEL_GEN(dev_priv) >= 4) {
4410 intel_de_write_fw(dev_priv, DSPLINOFF(i9xx_plane),
4412 intel_de_write_fw(dev_priv, DSPTILEOFF(i9xx_plane),
4417 * The control register self-arms if the plane was previously
4418 * disabled. Try to make the plane enable atomic by writing
4419 * the control register just before the surface register.
4421 intel_de_write_fw(dev_priv, DSPCNTR(i9xx_plane), dspcntr);
4422 if (INTEL_GEN(dev_priv) >= 4)
4423 intel_de_write_fw(dev_priv, DSPSURF(i9xx_plane),
4424 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
4426 intel_de_write_fw(dev_priv, DSPADDR(i9xx_plane),
4427 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
4429 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4432 static void i9xx_disable_plane(struct intel_plane *plane,
4433 const struct intel_crtc_state *crtc_state)
4435 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4436 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4437 unsigned long irqflags;
4441 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
4442 * enable on ilk+ affect the pipe bottom color as
4443 * well, so we must configure them even if the plane
4446 * On pre-g4x there is no way to gamma correct the
4447 * pipe bottom color but we'll keep on doing this
4448 * anyway so that the crtc state readout works correctly.
4450 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
4452 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4454 intel_de_write_fw(dev_priv, DSPCNTR(i9xx_plane), dspcntr);
4455 if (INTEL_GEN(dev_priv) >= 4)
4456 intel_de_write_fw(dev_priv, DSPSURF(i9xx_plane), 0);
4458 intel_de_write_fw(dev_priv, DSPADDR(i9xx_plane), 0);
4460 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4463 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
4466 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
4467 enum intel_display_power_domain power_domain;
4468 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4469 intel_wakeref_t wakeref;
4474 * Not 100% correct for planes that can move between pipes,
4475 * but that's only the case for gen2-4 which don't have any
4476 * display power wells.
4478 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
4479 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
4483 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
4485 ret = val & DISPLAY_PLANE_ENABLE;
4487 if (INTEL_GEN(dev_priv) >= 5)
4488 *pipe = plane->pipe;
4490 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
4491 DISPPLANE_SEL_PIPE_SHIFT;
4493 intel_display_power_put(dev_priv, power_domain, wakeref);
4498 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
4500 struct drm_device *dev = intel_crtc->base.dev;
4501 struct drm_i915_private *dev_priv = to_i915(dev);
4502 unsigned long irqflags;
4504 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4506 intel_de_write_fw(dev_priv, SKL_PS_CTRL(intel_crtc->pipe, id), 0);
4507 intel_de_write_fw(dev_priv, SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
4508 intel_de_write_fw(dev_priv, SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
4510 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4514 * This function detaches (aka. unbinds) unused scalers in hardware
4516 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
4518 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
4519 const struct intel_crtc_scaler_state *scaler_state =
4520 &crtc_state->scaler_state;
4523 /* loop through and disable scalers that aren't in use */
4524 for (i = 0; i < intel_crtc->num_scalers; i++) {
4525 if (!scaler_state->scalers[i].in_use)
4526 skl_detach_scaler(intel_crtc, i);
4530 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
4531 int color_plane, unsigned int rotation)
4534 * The stride is either expressed as a multiple of 64 bytes chunks for
4535 * linear buffers or in number of tiles for tiled buffers.
4537 if (is_surface_linear(fb, color_plane))
4539 else if (drm_rotation_90_or_270(rotation))
4540 return intel_tile_height(fb, color_plane);
4542 return intel_tile_width_bytes(fb, color_plane);
4545 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
4548 const struct drm_framebuffer *fb = plane_state->hw.fb;
4549 unsigned int rotation = plane_state->hw.rotation;
4550 u32 stride = plane_state->color_plane[color_plane].stride;
4552 if (color_plane >= fb->format->num_planes)
4555 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
4558 static u32 skl_plane_ctl_format(u32 pixel_format)
4560 switch (pixel_format) {
4562 return PLANE_CTL_FORMAT_INDEXED;
4563 case DRM_FORMAT_RGB565:
4564 return PLANE_CTL_FORMAT_RGB_565;
4565 case DRM_FORMAT_XBGR8888:
4566 case DRM_FORMAT_ABGR8888:
4567 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
4568 case DRM_FORMAT_XRGB8888:
4569 case DRM_FORMAT_ARGB8888:
4570 return PLANE_CTL_FORMAT_XRGB_8888;
4571 case DRM_FORMAT_XBGR2101010:
4572 case DRM_FORMAT_ABGR2101010:
4573 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
4574 case DRM_FORMAT_XRGB2101010:
4575 case DRM_FORMAT_ARGB2101010:
4576 return PLANE_CTL_FORMAT_XRGB_2101010;
4577 case DRM_FORMAT_XBGR16161616F:
4578 case DRM_FORMAT_ABGR16161616F:
4579 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
4580 case DRM_FORMAT_XRGB16161616F:
4581 case DRM_FORMAT_ARGB16161616F:
4582 return PLANE_CTL_FORMAT_XRGB_16161616F;
4583 case DRM_FORMAT_YUYV:
4584 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
4585 case DRM_FORMAT_YVYU:
4586 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
4587 case DRM_FORMAT_UYVY:
4588 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
4589 case DRM_FORMAT_VYUY:
4590 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
4591 case DRM_FORMAT_NV12:
4592 return PLANE_CTL_FORMAT_NV12;
4593 case DRM_FORMAT_P010:
4594 return PLANE_CTL_FORMAT_P010;
4595 case DRM_FORMAT_P012:
4596 return PLANE_CTL_FORMAT_P012;
4597 case DRM_FORMAT_P016:
4598 return PLANE_CTL_FORMAT_P016;
4599 case DRM_FORMAT_Y210:
4600 return PLANE_CTL_FORMAT_Y210;
4601 case DRM_FORMAT_Y212:
4602 return PLANE_CTL_FORMAT_Y212;
4603 case DRM_FORMAT_Y216:
4604 return PLANE_CTL_FORMAT_Y216;
4605 case DRM_FORMAT_XVYU2101010:
4606 return PLANE_CTL_FORMAT_Y410;
4607 case DRM_FORMAT_XVYU12_16161616:
4608 return PLANE_CTL_FORMAT_Y412;
4609 case DRM_FORMAT_XVYU16161616:
4610 return PLANE_CTL_FORMAT_Y416;
4612 MISSING_CASE(pixel_format);
4618 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
4620 if (!plane_state->hw.fb->format->has_alpha)
4621 return PLANE_CTL_ALPHA_DISABLE;
4623 switch (plane_state->hw.pixel_blend_mode) {
4624 case DRM_MODE_BLEND_PIXEL_NONE:
4625 return PLANE_CTL_ALPHA_DISABLE;
4626 case DRM_MODE_BLEND_PREMULTI:
4627 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
4628 case DRM_MODE_BLEND_COVERAGE:
4629 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
4631 MISSING_CASE(plane_state->hw.pixel_blend_mode);
4632 return PLANE_CTL_ALPHA_DISABLE;
4636 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
4638 if (!plane_state->hw.fb->format->has_alpha)
4639 return PLANE_COLOR_ALPHA_DISABLE;
4641 switch (plane_state->hw.pixel_blend_mode) {
4642 case DRM_MODE_BLEND_PIXEL_NONE:
4643 return PLANE_COLOR_ALPHA_DISABLE;
4644 case DRM_MODE_BLEND_PREMULTI:
4645 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
4646 case DRM_MODE_BLEND_COVERAGE:
4647 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
4649 MISSING_CASE(plane_state->hw.pixel_blend_mode);
4650 return PLANE_COLOR_ALPHA_DISABLE;
4654 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
4656 switch (fb_modifier) {
4657 case DRM_FORMAT_MOD_LINEAR:
4659 case I915_FORMAT_MOD_X_TILED:
4660 return PLANE_CTL_TILED_X;
4661 case I915_FORMAT_MOD_Y_TILED:
4662 return PLANE_CTL_TILED_Y;
4663 case I915_FORMAT_MOD_Y_TILED_CCS:
4664 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4665 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
4666 return PLANE_CTL_TILED_Y |
4667 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
4668 PLANE_CTL_CLEAR_COLOR_DISABLE;
4669 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
4670 return PLANE_CTL_TILED_Y | PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE;
4671 case I915_FORMAT_MOD_Yf_TILED:
4672 return PLANE_CTL_TILED_YF;
4673 case I915_FORMAT_MOD_Yf_TILED_CCS:
4674 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
4676 MISSING_CASE(fb_modifier);
4682 static u32 skl_plane_ctl_rotate(unsigned int rotate)
4685 case DRM_MODE_ROTATE_0:
4688 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
4689 * while i915 HW rotation is clockwise, thats why this swapping.
4691 case DRM_MODE_ROTATE_90:
4692 return PLANE_CTL_ROTATE_270;
4693 case DRM_MODE_ROTATE_180:
4694 return PLANE_CTL_ROTATE_180;
4695 case DRM_MODE_ROTATE_270:
4696 return PLANE_CTL_ROTATE_90;
4698 MISSING_CASE(rotate);
4704 static u32 cnl_plane_ctl_flip(unsigned int reflect)
4709 case DRM_MODE_REFLECT_X:
4710 return PLANE_CTL_FLIP_HORIZONTAL;
4711 case DRM_MODE_REFLECT_Y:
4713 MISSING_CASE(reflect);
4719 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
4721 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4724 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4727 if (crtc_state->gamma_enable)
4728 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
4730 if (crtc_state->csc_enable)
4731 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
4736 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
4737 const struct intel_plane_state *plane_state)
4739 struct drm_i915_private *dev_priv =
4740 to_i915(plane_state->uapi.plane->dev);
4741 const struct drm_framebuffer *fb = plane_state->hw.fb;
4742 unsigned int rotation = plane_state->hw.rotation;
4743 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
4746 plane_ctl = PLANE_CTL_ENABLE;
4748 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
4749 plane_ctl |= skl_plane_ctl_alpha(plane_state);
4750 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
4752 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
4753 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
4755 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4756 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
4759 plane_ctl |= skl_plane_ctl_format(fb->format->format);
4760 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
4761 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
4763 if (INTEL_GEN(dev_priv) >= 10)
4764 plane_ctl |= cnl_plane_ctl_flip(rotation &
4765 DRM_MODE_REFLECT_MASK);
4767 if (key->flags & I915_SET_COLORKEY_DESTINATION)
4768 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
4769 else if (key->flags & I915_SET_COLORKEY_SOURCE)
4770 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
4775 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
4777 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4778 u32 plane_color_ctl = 0;
4780 if (INTEL_GEN(dev_priv) >= 11)
4781 return plane_color_ctl;
4783 if (crtc_state->gamma_enable)
4784 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
4786 if (crtc_state->csc_enable)
4787 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
4789 return plane_color_ctl;
4792 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
4793 const struct intel_plane_state *plane_state)
4795 struct drm_i915_private *dev_priv =
4796 to_i915(plane_state->uapi.plane->dev);
4797 const struct drm_framebuffer *fb = plane_state->hw.fb;
4798 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
4799 u32 plane_color_ctl = 0;
4801 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
4802 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
4804 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
4805 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
4806 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
4808 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
4810 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
4811 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
4812 } else if (fb->format->is_yuv) {
4813 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
4816 return plane_color_ctl;
4820 __intel_display_resume(struct drm_device *dev,
4821 struct drm_atomic_state *state,
4822 struct drm_modeset_acquire_ctx *ctx)
4824 struct drm_crtc_state *crtc_state;
4825 struct drm_crtc *crtc;
4828 intel_modeset_setup_hw_state(dev, ctx);
4829 intel_vga_redisable(to_i915(dev));
4835 * We've duplicated the state, pointers to the old state are invalid.
4837 * Don't attempt to use the old state until we commit the duplicated state.
4839 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
4841 * Force recalculation even if we restore
4842 * current state. With fast modeset this may not result
4843 * in a modeset when the state is compatible.
4845 crtc_state->mode_changed = true;
4848 /* ignore any reset values/BIOS leftovers in the WM registers */
4849 if (!HAS_GMCH(to_i915(dev)))
4850 to_intel_atomic_state(state)->skip_intermediate_wm = true;
4852 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4854 drm_WARN_ON(dev, ret == -EDEADLK);
4858 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
4860 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
4861 intel_has_gpu_reset(&dev_priv->gt));
4864 void intel_prepare_reset(struct drm_i915_private *dev_priv)
4866 struct drm_device *dev = &dev_priv->drm;
4867 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4868 struct drm_atomic_state *state;
4871 /* reset doesn't touch the display */
4872 if (!i915_modparams.force_reset_modeset_test &&
4873 !gpu_reset_clobbers_display(dev_priv))
4876 /* We have a modeset vs reset deadlock, defensively unbreak it. */
4877 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4878 smp_mb__after_atomic();
4879 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
4881 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
4882 drm_dbg_kms(&dev_priv->drm,
4883 "Modeset potentially stuck, unbreaking through wedging\n");
4884 intel_gt_set_wedged(&dev_priv->gt);
4888 * Need mode_config.mutex so that we don't
4889 * trample ongoing ->detect() and whatnot.
4891 mutex_lock(&dev->mode_config.mutex);
4892 drm_modeset_acquire_init(ctx, 0);
4894 ret = drm_modeset_lock_all_ctx(dev, ctx);
4895 if (ret != -EDEADLK)
4898 drm_modeset_backoff(ctx);
4901 * Disabling the crtcs gracefully seems nicer. Also the
4902 * g33 docs say we should at least disable all the planes.
4904 state = drm_atomic_helper_duplicate_state(dev, ctx);
4905 if (IS_ERR(state)) {
4906 ret = PTR_ERR(state);
4907 drm_err(&dev_priv->drm, "Duplicating state failed with %i\n",
4912 ret = drm_atomic_helper_disable_all(dev, ctx);
4914 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
4916 drm_atomic_state_put(state);
4920 dev_priv->modeset_restore_state = state;
4921 state->acquire_ctx = ctx;
4924 void intel_finish_reset(struct drm_i915_private *dev_priv)
4926 struct drm_device *dev = &dev_priv->drm;
4927 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
4928 struct drm_atomic_state *state;
4931 /* reset doesn't touch the display */
4932 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
4935 state = fetch_and_zero(&dev_priv->modeset_restore_state);
4939 /* reset doesn't touch the display */
4940 if (!gpu_reset_clobbers_display(dev_priv)) {
4941 /* for testing only restore the display */
4942 ret = __intel_display_resume(dev, state, ctx);
4944 drm_err(&dev_priv->drm,
4945 "Restoring old state failed with %i\n", ret);
4948 * The display has been reset as well,
4949 * so need a full re-initialization.
4951 intel_pps_unlock_regs_wa(dev_priv);
4952 intel_modeset_init_hw(dev_priv);
4953 intel_init_clock_gating(dev_priv);
4955 spin_lock_irq(&dev_priv->irq_lock);
4956 if (dev_priv->display.hpd_irq_setup)
4957 dev_priv->display.hpd_irq_setup(dev_priv);
4958 spin_unlock_irq(&dev_priv->irq_lock);
4960 ret = __intel_display_resume(dev, state, ctx);
4962 drm_err(&dev_priv->drm,
4963 "Restoring old state failed with %i\n", ret);
4965 intel_hpd_init(dev_priv);
4968 drm_atomic_state_put(state);
4970 drm_modeset_drop_locks(ctx);
4971 drm_modeset_acquire_fini(ctx);
4972 mutex_unlock(&dev->mode_config.mutex);
4974 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
4977 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4979 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4980 enum pipe pipe = crtc->pipe;
4983 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
4986 * Display WA #1153: icl
4987 * enable hardware to bypass the alpha math
4988 * and rounding for per-pixel values 00 and 0xff
4990 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4992 * Display WA # 1605353570: icl
4993 * Set the pixel rounding bit to 1 for allowing
4994 * passthrough of Frame buffer pixels unmodified
4997 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
4998 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
5001 static void intel_fdi_normal_train(struct intel_crtc *crtc)
5003 struct drm_device *dev = crtc->base.dev;
5004 struct drm_i915_private *dev_priv = to_i915(dev);
5005 enum pipe pipe = crtc->pipe;
5009 /* enable normal train */
5010 reg = FDI_TX_CTL(pipe);
5011 temp = intel_de_read(dev_priv, reg);
5012 if (IS_IVYBRIDGE(dev_priv)) {
5013 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
5014 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
5016 temp &= ~FDI_LINK_TRAIN_NONE;
5017 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
5019 intel_de_write(dev_priv, reg, temp);
5021 reg = FDI_RX_CTL(pipe);
5022 temp = intel_de_read(dev_priv, reg);
5023 if (HAS_PCH_CPT(dev_priv)) {
5024 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5025 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
5027 temp &= ~FDI_LINK_TRAIN_NONE;
5028 temp |= FDI_LINK_TRAIN_NONE;
5030 intel_de_write(dev_priv, reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
5032 /* wait one idle pattern time */
5033 intel_de_posting_read(dev_priv, reg);
5036 /* IVB wants error correction enabled */
5037 if (IS_IVYBRIDGE(dev_priv))
5038 intel_de_write(dev_priv, reg,
5039 intel_de_read(dev_priv, reg) | FDI_FS_ERRC_ENABLE | FDI_FE_ERRC_ENABLE);
5042 /* The FDI link training functions for ILK/Ibexpeak. */
5043 static void ilk_fdi_link_train(struct intel_crtc *crtc,
5044 const struct intel_crtc_state *crtc_state)
5046 struct drm_device *dev = crtc->base.dev;
5047 struct drm_i915_private *dev_priv = to_i915(dev);
5048 enum pipe pipe = crtc->pipe;
5052 /* FDI needs bits from pipe first */
5053 assert_pipe_enabled(dev_priv, crtc_state->cpu_transcoder);
5055 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5057 reg = FDI_RX_IMR(pipe);
5058 temp = intel_de_read(dev_priv, reg);
5059 temp &= ~FDI_RX_SYMBOL_LOCK;
5060 temp &= ~FDI_RX_BIT_LOCK;
5061 intel_de_write(dev_priv, reg, temp);
5062 intel_de_read(dev_priv, reg);
5065 /* enable CPU FDI TX and PCH FDI RX */
5066 reg = FDI_TX_CTL(pipe);
5067 temp = intel_de_read(dev_priv, reg);
5068 temp &= ~FDI_DP_PORT_WIDTH_MASK;
5069 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5070 temp &= ~FDI_LINK_TRAIN_NONE;
5071 temp |= FDI_LINK_TRAIN_PATTERN_1;
5072 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
5074 reg = FDI_RX_CTL(pipe);
5075 temp = intel_de_read(dev_priv, reg);
5076 temp &= ~FDI_LINK_TRAIN_NONE;
5077 temp |= FDI_LINK_TRAIN_PATTERN_1;
5078 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
5080 intel_de_posting_read(dev_priv, reg);
5083 /* Ironlake workaround, enable clock pointer after FDI enable*/
5084 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
5085 FDI_RX_PHASE_SYNC_POINTER_OVR);
5086 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
5087 FDI_RX_PHASE_SYNC_POINTER_OVR | FDI_RX_PHASE_SYNC_POINTER_EN);
5089 reg = FDI_RX_IIR(pipe);
5090 for (tries = 0; tries < 5; tries++) {
5091 temp = intel_de_read(dev_priv, reg);
5092 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5094 if ((temp & FDI_RX_BIT_LOCK)) {
5095 drm_dbg_kms(&dev_priv->drm, "FDI train 1 done.\n");
5096 intel_de_write(dev_priv, reg, temp | FDI_RX_BIT_LOCK);
5101 drm_err(&dev_priv->drm, "FDI train 1 fail!\n");
5104 reg = FDI_TX_CTL(pipe);
5105 temp = intel_de_read(dev_priv, reg);
5106 temp &= ~FDI_LINK_TRAIN_NONE;
5107 temp |= FDI_LINK_TRAIN_PATTERN_2;
5108 intel_de_write(dev_priv, reg, temp);
5110 reg = FDI_RX_CTL(pipe);
5111 temp = intel_de_read(dev_priv, reg);
5112 temp &= ~FDI_LINK_TRAIN_NONE;
5113 temp |= FDI_LINK_TRAIN_PATTERN_2;
5114 intel_de_write(dev_priv, reg, temp);
5116 intel_de_posting_read(dev_priv, reg);
5119 reg = FDI_RX_IIR(pipe);
5120 for (tries = 0; tries < 5; tries++) {
5121 temp = intel_de_read(dev_priv, reg);
5122 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5124 if (temp & FDI_RX_SYMBOL_LOCK) {
5125 intel_de_write(dev_priv, reg,
5126 temp | FDI_RX_SYMBOL_LOCK);
5127 drm_dbg_kms(&dev_priv->drm, "FDI train 2 done.\n");
5132 drm_err(&dev_priv->drm, "FDI train 2 fail!\n");
5134 drm_dbg_kms(&dev_priv->drm, "FDI train done\n");
5138 static const int snb_b_fdi_train_param[] = {
5139 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
5140 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
5141 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
5142 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
5145 /* The FDI link training functions for SNB/Cougarpoint. */
5146 static void gen6_fdi_link_train(struct intel_crtc *crtc,
5147 const struct intel_crtc_state *crtc_state)
5149 struct drm_device *dev = crtc->base.dev;
5150 struct drm_i915_private *dev_priv = to_i915(dev);
5151 enum pipe pipe = crtc->pipe;
5155 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5157 reg = FDI_RX_IMR(pipe);
5158 temp = intel_de_read(dev_priv, reg);
5159 temp &= ~FDI_RX_SYMBOL_LOCK;
5160 temp &= ~FDI_RX_BIT_LOCK;
5161 intel_de_write(dev_priv, reg, temp);
5163 intel_de_posting_read(dev_priv, reg);
5166 /* enable CPU FDI TX and PCH FDI RX */
5167 reg = FDI_TX_CTL(pipe);
5168 temp = intel_de_read(dev_priv, reg);
5169 temp &= ~FDI_DP_PORT_WIDTH_MASK;
5170 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5171 temp &= ~FDI_LINK_TRAIN_NONE;
5172 temp |= FDI_LINK_TRAIN_PATTERN_1;
5173 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5175 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
5176 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
5178 intel_de_write(dev_priv, FDI_RX_MISC(pipe),
5179 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
5181 reg = FDI_RX_CTL(pipe);
5182 temp = intel_de_read(dev_priv, reg);
5183 if (HAS_PCH_CPT(dev_priv)) {
5184 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5185 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5187 temp &= ~FDI_LINK_TRAIN_NONE;
5188 temp |= FDI_LINK_TRAIN_PATTERN_1;
5190 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
5192 intel_de_posting_read(dev_priv, reg);
5195 for (i = 0; i < 4; i++) {
5196 reg = FDI_TX_CTL(pipe);
5197 temp = intel_de_read(dev_priv, reg);
5198 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5199 temp |= snb_b_fdi_train_param[i];
5200 intel_de_write(dev_priv, reg, temp);
5202 intel_de_posting_read(dev_priv, reg);
5205 for (retry = 0; retry < 5; retry++) {
5206 reg = FDI_RX_IIR(pipe);
5207 temp = intel_de_read(dev_priv, reg);
5208 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5209 if (temp & FDI_RX_BIT_LOCK) {
5210 intel_de_write(dev_priv, reg,
5211 temp | FDI_RX_BIT_LOCK);
5212 drm_dbg_kms(&dev_priv->drm,
5213 "FDI train 1 done.\n");
5222 drm_err(&dev_priv->drm, "FDI train 1 fail!\n");
5225 reg = FDI_TX_CTL(pipe);
5226 temp = intel_de_read(dev_priv, reg);
5227 temp &= ~FDI_LINK_TRAIN_NONE;
5228 temp |= FDI_LINK_TRAIN_PATTERN_2;
5229 if (IS_GEN(dev_priv, 6)) {
5230 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5232 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
5234 intel_de_write(dev_priv, reg, temp);
5236 reg = FDI_RX_CTL(pipe);
5237 temp = intel_de_read(dev_priv, reg);
5238 if (HAS_PCH_CPT(dev_priv)) {
5239 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5240 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
5242 temp &= ~FDI_LINK_TRAIN_NONE;
5243 temp |= FDI_LINK_TRAIN_PATTERN_2;
5245 intel_de_write(dev_priv, reg, temp);
5247 intel_de_posting_read(dev_priv, reg);
5250 for (i = 0; i < 4; i++) {
5251 reg = FDI_TX_CTL(pipe);
5252 temp = intel_de_read(dev_priv, reg);
5253 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5254 temp |= snb_b_fdi_train_param[i];
5255 intel_de_write(dev_priv, reg, temp);
5257 intel_de_posting_read(dev_priv, reg);
5260 for (retry = 0; retry < 5; retry++) {
5261 reg = FDI_RX_IIR(pipe);
5262 temp = intel_de_read(dev_priv, reg);
5263 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5264 if (temp & FDI_RX_SYMBOL_LOCK) {
5265 intel_de_write(dev_priv, reg,
5266 temp | FDI_RX_SYMBOL_LOCK);
5267 drm_dbg_kms(&dev_priv->drm,
5268 "FDI train 2 done.\n");
5277 drm_err(&dev_priv->drm, "FDI train 2 fail!\n");
5279 drm_dbg_kms(&dev_priv->drm, "FDI train done.\n");
5282 /* Manual link training for Ivy Bridge A0 parts */
5283 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
5284 const struct intel_crtc_state *crtc_state)
5286 struct drm_device *dev = crtc->base.dev;
5287 struct drm_i915_private *dev_priv = to_i915(dev);
5288 enum pipe pipe = crtc->pipe;
5292 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5294 reg = FDI_RX_IMR(pipe);
5295 temp = intel_de_read(dev_priv, reg);
5296 temp &= ~FDI_RX_SYMBOL_LOCK;
5297 temp &= ~FDI_RX_BIT_LOCK;
5298 intel_de_write(dev_priv, reg, temp);
5300 intel_de_posting_read(dev_priv, reg);
5303 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR before link train 0x%x\n",
5304 intel_de_read(dev_priv, FDI_RX_IIR(pipe)));
5306 /* Try each vswing and preemphasis setting twice before moving on */
5307 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
5308 /* disable first in case we need to retry */
5309 reg = FDI_TX_CTL(pipe);
5310 temp = intel_de_read(dev_priv, reg);
5311 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
5312 temp &= ~FDI_TX_ENABLE;
5313 intel_de_write(dev_priv, reg, temp);
5315 reg = FDI_RX_CTL(pipe);
5316 temp = intel_de_read(dev_priv, reg);
5317 temp &= ~FDI_LINK_TRAIN_AUTO;
5318 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5319 temp &= ~FDI_RX_ENABLE;
5320 intel_de_write(dev_priv, reg, temp);
5322 /* enable CPU FDI TX and PCH FDI RX */
5323 reg = FDI_TX_CTL(pipe);
5324 temp = intel_de_read(dev_priv, reg);
5325 temp &= ~FDI_DP_PORT_WIDTH_MASK;
5326 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5327 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
5328 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5329 temp |= snb_b_fdi_train_param[j/2];
5330 temp |= FDI_COMPOSITE_SYNC;
5331 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
5333 intel_de_write(dev_priv, FDI_RX_MISC(pipe),
5334 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
5336 reg = FDI_RX_CTL(pipe);
5337 temp = intel_de_read(dev_priv, reg);
5338 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5339 temp |= FDI_COMPOSITE_SYNC;
5340 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
5342 intel_de_posting_read(dev_priv, reg);
5343 udelay(1); /* should be 0.5us */
5345 for (i = 0; i < 4; i++) {
5346 reg = FDI_RX_IIR(pipe);
5347 temp = intel_de_read(dev_priv, reg);
5348 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5350 if (temp & FDI_RX_BIT_LOCK ||
5351 (intel_de_read(dev_priv, reg) & FDI_RX_BIT_LOCK)) {
5352 intel_de_write(dev_priv, reg,
5353 temp | FDI_RX_BIT_LOCK);
5354 drm_dbg_kms(&dev_priv->drm,
5355 "FDI train 1 done, level %i.\n",
5359 udelay(1); /* should be 0.5us */
5362 drm_dbg_kms(&dev_priv->drm,
5363 "FDI train 1 fail on vswing %d\n", j / 2);
5368 reg = FDI_TX_CTL(pipe);
5369 temp = intel_de_read(dev_priv, reg);
5370 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
5371 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
5372 intel_de_write(dev_priv, reg, temp);
5374 reg = FDI_RX_CTL(pipe);
5375 temp = intel_de_read(dev_priv, reg);
5376 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5377 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
5378 intel_de_write(dev_priv, reg, temp);
5380 intel_de_posting_read(dev_priv, reg);
5381 udelay(2); /* should be 1.5us */
5383 for (i = 0; i < 4; i++) {
5384 reg = FDI_RX_IIR(pipe);
5385 temp = intel_de_read(dev_priv, reg);
5386 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5388 if (temp & FDI_RX_SYMBOL_LOCK ||
5389 (intel_de_read(dev_priv, reg) & FDI_RX_SYMBOL_LOCK)) {
5390 intel_de_write(dev_priv, reg,
5391 temp | FDI_RX_SYMBOL_LOCK);
5392 drm_dbg_kms(&dev_priv->drm,
5393 "FDI train 2 done, level %i.\n",
5397 udelay(2); /* should be 1.5us */
5400 drm_dbg_kms(&dev_priv->drm,
5401 "FDI train 2 fail on vswing %d\n", j / 2);
5405 drm_dbg_kms(&dev_priv->drm, "FDI train done.\n");
5408 static void ilk_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
5410 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
5411 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5412 enum pipe pipe = intel_crtc->pipe;
5416 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
5417 reg = FDI_RX_CTL(pipe);
5418 temp = intel_de_read(dev_priv, reg);
5419 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
5420 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5421 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5422 intel_de_write(dev_priv, reg, temp | FDI_RX_PLL_ENABLE);
5424 intel_de_posting_read(dev_priv, reg);
5427 /* Switch from Rawclk to PCDclk */
5428 temp = intel_de_read(dev_priv, reg);
5429 intel_de_write(dev_priv, reg, temp | FDI_PCDCLK);
5431 intel_de_posting_read(dev_priv, reg);
5434 /* Enable CPU FDI TX PLL, always on for Ironlake */
5435 reg = FDI_TX_CTL(pipe);
5436 temp = intel_de_read(dev_priv, reg);
5437 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
5438 intel_de_write(dev_priv, reg, temp | FDI_TX_PLL_ENABLE);
5440 intel_de_posting_read(dev_priv, reg);
5445 static void ilk_fdi_pll_disable(struct intel_crtc *intel_crtc)
5447 struct drm_device *dev = intel_crtc->base.dev;
5448 struct drm_i915_private *dev_priv = to_i915(dev);
5449 enum pipe pipe = intel_crtc->pipe;
5453 /* Switch from PCDclk to Rawclk */
5454 reg = FDI_RX_CTL(pipe);
5455 temp = intel_de_read(dev_priv, reg);
5456 intel_de_write(dev_priv, reg, temp & ~FDI_PCDCLK);
5458 /* Disable CPU FDI TX PLL */
5459 reg = FDI_TX_CTL(pipe);
5460 temp = intel_de_read(dev_priv, reg);
5461 intel_de_write(dev_priv, reg, temp & ~FDI_TX_PLL_ENABLE);
5463 intel_de_posting_read(dev_priv, reg);
5466 reg = FDI_RX_CTL(pipe);
5467 temp = intel_de_read(dev_priv, reg);
5468 intel_de_write(dev_priv, reg, temp & ~FDI_RX_PLL_ENABLE);
5470 /* Wait for the clocks to turn off. */
5471 intel_de_posting_read(dev_priv, reg);
5475 static void ilk_fdi_disable(struct intel_crtc *crtc)
5477 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5478 enum pipe pipe = crtc->pipe;
5482 /* disable CPU FDI tx and PCH FDI rx */
5483 reg = FDI_TX_CTL(pipe);
5484 temp = intel_de_read(dev_priv, reg);
5485 intel_de_write(dev_priv, reg, temp & ~FDI_TX_ENABLE);
5486 intel_de_posting_read(dev_priv, reg);
5488 reg = FDI_RX_CTL(pipe);
5489 temp = intel_de_read(dev_priv, reg);
5490 temp &= ~(0x7 << 16);
5491 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5492 intel_de_write(dev_priv, reg, temp & ~FDI_RX_ENABLE);
5494 intel_de_posting_read(dev_priv, reg);
5497 /* Ironlake workaround, disable clock pointer after downing FDI */
5498 if (HAS_PCH_IBX(dev_priv))
5499 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
5500 FDI_RX_PHASE_SYNC_POINTER_OVR);
5502 /* still set train pattern 1 */
5503 reg = FDI_TX_CTL(pipe);
5504 temp = intel_de_read(dev_priv, reg);
5505 temp &= ~FDI_LINK_TRAIN_NONE;
5506 temp |= FDI_LINK_TRAIN_PATTERN_1;
5507 intel_de_write(dev_priv, reg, temp);
5509 reg = FDI_RX_CTL(pipe);
5510 temp = intel_de_read(dev_priv, reg);
5511 if (HAS_PCH_CPT(dev_priv)) {
5512 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5513 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5515 temp &= ~FDI_LINK_TRAIN_NONE;
5516 temp |= FDI_LINK_TRAIN_PATTERN_1;
5518 /* BPC in FDI rx is consistent with that in PIPECONF */
5519 temp &= ~(0x07 << 16);
5520 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5521 intel_de_write(dev_priv, reg, temp);
5523 intel_de_posting_read(dev_priv, reg);
5527 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
5529 struct drm_crtc *crtc;
5532 drm_for_each_crtc(crtc, &dev_priv->drm) {
5533 struct drm_crtc_commit *commit;
5534 spin_lock(&crtc->commit_lock);
5535 commit = list_first_entry_or_null(&crtc->commit_list,
5536 struct drm_crtc_commit, commit_entry);
5537 cleanup_done = commit ?
5538 try_wait_for_completion(&commit->cleanup_done) : true;
5539 spin_unlock(&crtc->commit_lock);
5544 drm_crtc_wait_one_vblank(crtc);
5552 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
5556 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_GATE);
5558 mutex_lock(&dev_priv->sb_lock);
5560 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5561 temp |= SBI_SSCCTL_DISABLE;
5562 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5564 mutex_unlock(&dev_priv->sb_lock);
5567 /* Program iCLKIP clock to the desired frequency */
5568 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
5570 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5571 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5572 int clock = crtc_state->hw.adjusted_mode.crtc_clock;
5573 u32 divsel, phaseinc, auxdiv, phasedir = 0;
5576 lpt_disable_iclkip(dev_priv);
5578 /* The iCLK virtual clock root frequency is in MHz,
5579 * but the adjusted_mode->crtc_clock in in KHz. To get the
5580 * divisors, it is necessary to divide one by another, so we
5581 * convert the virtual clock precision to KHz here for higher
5584 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
5585 u32 iclk_virtual_root_freq = 172800 * 1000;
5586 u32 iclk_pi_range = 64;
5587 u32 desired_divisor;
5589 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5591 divsel = (desired_divisor / iclk_pi_range) - 2;
5592 phaseinc = desired_divisor % iclk_pi_range;
5595 * Near 20MHz is a corner case which is
5596 * out of range for the 7-bit divisor
5602 /* This should not happen with any sane values */
5603 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5604 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5605 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIR(phasedir) &
5606 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5608 drm_dbg_kms(&dev_priv->drm,
5609 "iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5610 clock, auxdiv, divsel, phasedir, phaseinc);
5612 mutex_lock(&dev_priv->sb_lock);
5614 /* Program SSCDIVINTPHASE6 */
5615 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5616 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5617 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5618 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5619 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5620 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5621 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5622 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5624 /* Program SSCAUXDIV */
5625 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5626 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5627 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5628 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5630 /* Enable modulator and associated divider */
5631 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5632 temp &= ~SBI_SSCCTL_DISABLE;
5633 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5635 mutex_unlock(&dev_priv->sb_lock);
5637 /* Wait for initialization time */
5640 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5643 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5645 u32 divsel, phaseinc, auxdiv;
5646 u32 iclk_virtual_root_freq = 172800 * 1000;
5647 u32 iclk_pi_range = 64;
5648 u32 desired_divisor;
5651 if ((intel_de_read(dev_priv, PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5654 mutex_lock(&dev_priv->sb_lock);
5656 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5657 if (temp & SBI_SSCCTL_DISABLE) {
5658 mutex_unlock(&dev_priv->sb_lock);
5662 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5663 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5664 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5665 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5666 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5668 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5669 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5670 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5672 mutex_unlock(&dev_priv->sb_lock);
5674 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5676 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5677 desired_divisor << auxdiv);
5680 static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5681 enum pipe pch_transcoder)
5683 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5684 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5685 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5687 intel_de_write(dev_priv, PCH_TRANS_HTOTAL(pch_transcoder),
5688 intel_de_read(dev_priv, HTOTAL(cpu_transcoder)));
5689 intel_de_write(dev_priv, PCH_TRANS_HBLANK(pch_transcoder),
5690 intel_de_read(dev_priv, HBLANK(cpu_transcoder)));
5691 intel_de_write(dev_priv, PCH_TRANS_HSYNC(pch_transcoder),
5692 intel_de_read(dev_priv, HSYNC(cpu_transcoder)));
5694 intel_de_write(dev_priv, PCH_TRANS_VTOTAL(pch_transcoder),
5695 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
5696 intel_de_write(dev_priv, PCH_TRANS_VBLANK(pch_transcoder),
5697 intel_de_read(dev_priv, VBLANK(cpu_transcoder)));
5698 intel_de_write(dev_priv, PCH_TRANS_VSYNC(pch_transcoder),
5699 intel_de_read(dev_priv, VSYNC(cpu_transcoder)));
5700 intel_de_write(dev_priv, PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5701 intel_de_read(dev_priv, VSYNCSHIFT(cpu_transcoder)));
5704 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5708 temp = intel_de_read(dev_priv, SOUTH_CHICKEN1);
5709 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5712 drm_WARN_ON(&dev_priv->drm,
5713 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_B)) &
5715 drm_WARN_ON(&dev_priv->drm,
5716 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_C)) &
5719 temp &= ~FDI_BC_BIFURCATION_SELECT;
5721 temp |= FDI_BC_BIFURCATION_SELECT;
5723 drm_dbg_kms(&dev_priv->drm, "%sabling fdi C rx\n",
5724 enable ? "en" : "dis");
5725 intel_de_write(dev_priv, SOUTH_CHICKEN1, temp);
5726 intel_de_posting_read(dev_priv, SOUTH_CHICKEN1);
5729 static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5731 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5732 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5734 switch (crtc->pipe) {
5738 if (crtc_state->fdi_lanes > 2)
5739 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5741 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5745 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5754 * Finds the encoder associated with the given CRTC. This can only be
5755 * used when we know that the CRTC isn't feeding multiple encoders!
5757 static struct intel_encoder *
5758 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5759 const struct intel_crtc_state *crtc_state)
5761 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5762 const struct drm_connector_state *connector_state;
5763 const struct drm_connector *connector;
5764 struct intel_encoder *encoder = NULL;
5765 int num_encoders = 0;
5768 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5769 if (connector_state->crtc != &crtc->base)
5772 encoder = to_intel_encoder(connector_state->best_encoder);
5776 drm_WARN(encoder->base.dev, num_encoders != 1,
5777 "%d encoders for pipe %c\n",
5778 num_encoders, pipe_name(crtc->pipe));
5784 * Enable PCH resources required for PCH ports:
5786 * - FDI training & RX/TX
5787 * - update transcoder timings
5788 * - DP transcoding bits
5791 static void ilk_pch_enable(const struct intel_atomic_state *state,
5792 const struct intel_crtc_state *crtc_state)
5794 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5795 struct drm_device *dev = crtc->base.dev;
5796 struct drm_i915_private *dev_priv = to_i915(dev);
5797 enum pipe pipe = crtc->pipe;
5800 assert_pch_transcoder_disabled(dev_priv, pipe);
5802 if (IS_IVYBRIDGE(dev_priv))
5803 ivb_update_fdi_bc_bifurcation(crtc_state);
5805 /* Write the TU size bits before fdi link training, so that error
5806 * detection works. */
5807 intel_de_write(dev_priv, FDI_RX_TUSIZE1(pipe),
5808 intel_de_read(dev_priv, PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5810 /* For PCH output, training FDI link */
5811 dev_priv->display.fdi_link_train(crtc, crtc_state);
5813 /* We need to program the right clock selection before writing the pixel
5814 * mutliplier into the DPLL. */
5815 if (HAS_PCH_CPT(dev_priv)) {
5818 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
5819 temp |= TRANS_DPLL_ENABLE(pipe);
5820 sel = TRANS_DPLLB_SEL(pipe);
5821 if (crtc_state->shared_dpll ==
5822 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5826 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
5829 /* XXX: pch pll's can be enabled any time before we enable the PCH
5830 * transcoder, and we actually should do this to not upset any PCH
5831 * transcoder that already use the clock when we share it.
5833 * Note that enable_shared_dpll tries to do the right thing, but
5834 * get_shared_dpll unconditionally resets the pll - we need that to have
5835 * the right LVDS enable sequence. */
5836 intel_enable_shared_dpll(crtc_state);
5838 /* set transcoder timing, panel must allow it */
5839 assert_panel_unlocked(dev_priv, pipe);
5840 ilk_pch_transcoder_set_timings(crtc_state, pipe);
5842 intel_fdi_normal_train(crtc);
5844 /* For PCH DP, enable TRANS_DP_CTL */
5845 if (HAS_PCH_CPT(dev_priv) &&
5846 intel_crtc_has_dp_encoder(crtc_state)) {
5847 const struct drm_display_mode *adjusted_mode =
5848 &crtc_state->hw.adjusted_mode;
5849 u32 bpc = (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5850 i915_reg_t reg = TRANS_DP_CTL(pipe);
5853 temp = intel_de_read(dev_priv, reg);
5854 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5855 TRANS_DP_SYNC_MASK |
5857 temp |= TRANS_DP_OUTPUT_ENABLE;
5858 temp |= bpc << 9; /* same format but at 11:9 */
5860 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5861 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5862 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5863 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5865 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5866 drm_WARN_ON(dev, port < PORT_B || port > PORT_D);
5867 temp |= TRANS_DP_PORT_SEL(port);
5869 intel_de_write(dev_priv, reg, temp);
5872 ilk_enable_pch_transcoder(crtc_state);
5875 void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
5877 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5878 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5879 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5881 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5883 lpt_program_iclkip(crtc_state);
5885 /* Set transcoder timing. */
5886 ilk_pch_transcoder_set_timings(crtc_state, PIPE_A);
5888 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5891 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
5894 i915_reg_t dslreg = PIPEDSL(pipe);
5897 temp = intel_de_read(dev_priv, dslreg);
5899 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) {
5900 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5))
5901 drm_err(&dev_priv->drm,
5902 "mode set failed: pipe %c stuck\n",
5908 * The hardware phase 0.0 refers to the center of the pixel.
5909 * We want to start from the top/left edge which is phase
5910 * -0.5. That matches how the hardware calculates the scaling
5911 * factors (from top-left of the first pixel to bottom-right
5912 * of the last pixel, as opposed to the pixel centers).
5914 * For 4:2:0 subsampled chroma planes we obviously have to
5915 * adjust that so that the chroma sample position lands in
5918 * Note that for packed YCbCr 4:2:2 formats there is no way to
5919 * control chroma siting. The hardware simply replicates the
5920 * chroma samples for both of the luma samples, and thus we don't
5921 * actually get the expected MPEG2 chroma siting convention :(
5922 * The same behaviour is observed on pre-SKL platforms as well.
5924 * Theory behind the formula (note that we ignore sub-pixel
5925 * source coordinates):
5926 * s = source sample position
5927 * d = destination sample position
5932 * | | 1.5 (initial phase)
5940 * | -0.375 (initial phase)
5947 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5949 int phase = -0x8000;
5953 phase += (sub - 1) * 0x8000 / sub;
5955 phase += scale / (2 * sub);
5958 * Hardware initial phase limited to [-0.5:1.5].
5959 * Since the max hardware scale factor is 3.0, we
5960 * should never actually excdeed 1.0 here.
5962 WARN_ON(phase < -0x8000 || phase > 0x18000);
5965 phase = 0x10000 + phase;
5967 trip = PS_PHASE_TRIP;
5969 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5972 #define SKL_MIN_SRC_W 8
5973 #define SKL_MAX_SRC_W 4096
5974 #define SKL_MIN_SRC_H 8
5975 #define SKL_MAX_SRC_H 4096
5976 #define SKL_MIN_DST_W 8
5977 #define SKL_MAX_DST_W 4096
5978 #define SKL_MIN_DST_H 8
5979 #define SKL_MAX_DST_H 4096
5980 #define ICL_MAX_SRC_W 5120
5981 #define ICL_MAX_SRC_H 4096
5982 #define ICL_MAX_DST_W 5120
5983 #define ICL_MAX_DST_H 4096
5984 #define SKL_MIN_YUV_420_SRC_W 16
5985 #define SKL_MIN_YUV_420_SRC_H 16
5988 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5989 unsigned int scaler_user, int *scaler_id,
5990 int src_w, int src_h, int dst_w, int dst_h,
5991 const struct drm_format_info *format,
5992 u64 modifier, bool need_scaler)
5994 struct intel_crtc_scaler_state *scaler_state =
5995 &crtc_state->scaler_state;
5996 struct intel_crtc *intel_crtc =
5997 to_intel_crtc(crtc_state->uapi.crtc);
5998 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5999 const struct drm_display_mode *adjusted_mode =
6000 &crtc_state->hw.adjusted_mode;
6003 * Src coordinates are already rotated by 270 degrees for
6004 * the 90/270 degree plane rotation cases (to match the
6005 * GTT mapping), hence no need to account for rotation here.
6007 if (src_w != dst_w || src_h != dst_h)
6011 * Scaling/fitting not supported in IF-ID mode in GEN9+
6012 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
6013 * Once NV12 is enabled, handle it here while allocating scaler
6016 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->hw.enable &&
6017 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
6018 drm_dbg_kms(&dev_priv->drm,
6019 "Pipe/Plane scaling not supported with IF-ID mode\n");
6024 * if plane is being disabled or scaler is no more required or force detach
6025 * - free scaler binded to this plane/crtc
6026 * - in order to do this, update crtc->scaler_usage
6028 * Here scaler state in crtc_state is set free so that
6029 * scaler can be assigned to other user. Actual register
6030 * update to free the scaler is done in plane/panel-fit programming.
6031 * For this purpose crtc/plane_state->scaler_id isn't reset here.
6033 if (force_detach || !need_scaler) {
6034 if (*scaler_id >= 0) {
6035 scaler_state->scaler_users &= ~(1 << scaler_user);
6036 scaler_state->scalers[*scaler_id].in_use = 0;
6038 drm_dbg_kms(&dev_priv->drm,
6039 "scaler_user index %u.%u: "
6040 "Staged freeing scaler id %d scaler_users = 0x%x\n",
6041 intel_crtc->pipe, scaler_user, *scaler_id,
6042 scaler_state->scaler_users);
6048 if (format && intel_format_info_is_yuv_semiplanar(format, modifier) &&
6049 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
6050 drm_dbg_kms(&dev_priv->drm,
6051 "Planar YUV: src dimensions not met\n");
6056 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
6057 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
6058 (INTEL_GEN(dev_priv) >= 11 &&
6059 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
6060 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
6061 (INTEL_GEN(dev_priv) < 11 &&
6062 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
6063 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
6064 drm_dbg_kms(&dev_priv->drm,
6065 "scaler_user index %u.%u: src %ux%u dst %ux%u "
6066 "size is out of scaler range\n",
6067 intel_crtc->pipe, scaler_user, src_w, src_h,
6072 /* mark this plane as a scaler user in crtc_state */
6073 scaler_state->scaler_users |= (1 << scaler_user);
6074 drm_dbg_kms(&dev_priv->drm, "scaler_user index %u.%u: "
6075 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
6076 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
6077 scaler_state->scaler_users);
6083 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
6085 * @state: crtc's scaler state
6088 * 0 - scaler_usage updated successfully
6089 * error - requested scaling cannot be supported or other error condition
6091 int skl_update_scaler_crtc(struct intel_crtc_state *state)
6093 const struct drm_display_mode *adjusted_mode = &state->hw.adjusted_mode;
6094 bool need_scaler = false;
6096 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6097 state->pch_pfit.enabled)
6100 return skl_update_scaler(state, !state->hw.active, SKL_CRTC_INDEX,
6101 &state->scaler_state.scaler_id,
6102 state->pipe_src_w, state->pipe_src_h,
6103 adjusted_mode->crtc_hdisplay,
6104 adjusted_mode->crtc_vdisplay, NULL, 0,
6109 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
6110 * @crtc_state: crtc's scaler state
6111 * @plane_state: atomic plane state to update
6114 * 0 - scaler_usage updated successfully
6115 * error - requested scaling cannot be supported or other error condition
6117 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
6118 struct intel_plane_state *plane_state)
6120 struct intel_plane *intel_plane =
6121 to_intel_plane(plane_state->uapi.plane);
6122 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
6123 struct drm_framebuffer *fb = plane_state->hw.fb;
6125 bool force_detach = !fb || !plane_state->uapi.visible;
6126 bool need_scaler = false;
6128 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
6129 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
6130 fb && intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
6133 ret = skl_update_scaler(crtc_state, force_detach,
6134 drm_plane_index(&intel_plane->base),
6135 &plane_state->scaler_id,
6136 drm_rect_width(&plane_state->uapi.src) >> 16,
6137 drm_rect_height(&plane_state->uapi.src) >> 16,
6138 drm_rect_width(&plane_state->uapi.dst),
6139 drm_rect_height(&plane_state->uapi.dst),
6140 fb ? fb->format : NULL,
6141 fb ? fb->modifier : 0,
6144 if (ret || plane_state->scaler_id < 0)
6147 /* check colorkey */
6148 if (plane_state->ckey.flags) {
6149 drm_dbg_kms(&dev_priv->drm,
6150 "[PLANE:%d:%s] scaling with color key not allowed",
6151 intel_plane->base.base.id,
6152 intel_plane->base.name);
6156 /* Check src format */
6157 switch (fb->format->format) {
6158 case DRM_FORMAT_RGB565:
6159 case DRM_FORMAT_XBGR8888:
6160 case DRM_FORMAT_XRGB8888:
6161 case DRM_FORMAT_ABGR8888:
6162 case DRM_FORMAT_ARGB8888:
6163 case DRM_FORMAT_XRGB2101010:
6164 case DRM_FORMAT_XBGR2101010:
6165 case DRM_FORMAT_ARGB2101010:
6166 case DRM_FORMAT_ABGR2101010:
6167 case DRM_FORMAT_YUYV:
6168 case DRM_FORMAT_YVYU:
6169 case DRM_FORMAT_UYVY:
6170 case DRM_FORMAT_VYUY:
6171 case DRM_FORMAT_NV12:
6172 case DRM_FORMAT_P010:
6173 case DRM_FORMAT_P012:
6174 case DRM_FORMAT_P016:
6175 case DRM_FORMAT_Y210:
6176 case DRM_FORMAT_Y212:
6177 case DRM_FORMAT_Y216:
6178 case DRM_FORMAT_XVYU2101010:
6179 case DRM_FORMAT_XVYU12_16161616:
6180 case DRM_FORMAT_XVYU16161616:
6182 case DRM_FORMAT_XBGR16161616F:
6183 case DRM_FORMAT_ABGR16161616F:
6184 case DRM_FORMAT_XRGB16161616F:
6185 case DRM_FORMAT_ARGB16161616F:
6186 if (INTEL_GEN(dev_priv) >= 11)
6190 drm_dbg_kms(&dev_priv->drm,
6191 "[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
6192 intel_plane->base.base.id, intel_plane->base.name,
6193 fb->base.id, fb->format->format);
6200 void skl_scaler_disable(const struct intel_crtc_state *old_crtc_state)
6202 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
6205 for (i = 0; i < crtc->num_scalers; i++)
6206 skl_detach_scaler(crtc, i);
6209 static void skl_pfit_enable(const struct intel_crtc_state *crtc_state)
6211 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6212 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6213 enum pipe pipe = crtc->pipe;
6214 const struct intel_crtc_scaler_state *scaler_state =
6215 &crtc_state->scaler_state;
6217 if (crtc_state->pch_pfit.enabled) {
6218 u16 uv_rgb_hphase, uv_rgb_vphase;
6219 int pfit_w, pfit_h, hscale, vscale;
6220 unsigned long irqflags;
6223 if (drm_WARN_ON(&dev_priv->drm,
6224 crtc_state->scaler_state.scaler_id < 0))
6227 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
6228 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
6230 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
6231 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
6233 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
6234 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
6236 id = scaler_state->scaler_id;
6238 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
6240 intel_de_write_fw(dev_priv, SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
6241 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
6242 intel_de_write_fw(dev_priv, SKL_PS_VPHASE(pipe, id),
6243 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
6244 intel_de_write_fw(dev_priv, SKL_PS_HPHASE(pipe, id),
6245 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
6246 intel_de_write_fw(dev_priv, SKL_PS_WIN_POS(pipe, id),
6247 crtc_state->pch_pfit.pos);
6248 intel_de_write_fw(dev_priv, SKL_PS_WIN_SZ(pipe, id),
6249 crtc_state->pch_pfit.size);
6251 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
6255 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
6257 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6258 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6259 enum pipe pipe = crtc->pipe;
6261 if (crtc_state->pch_pfit.enabled) {
6262 /* Force use of hard-coded filter coefficients
6263 * as some pre-programmed values are broken,
6266 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
6267 intel_de_write(dev_priv, PF_CTL(pipe),
6268 PF_ENABLE | PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
6270 intel_de_write(dev_priv, PF_CTL(pipe),
6271 PF_ENABLE | PF_FILTER_MED_3x3);
6272 intel_de_write(dev_priv, PF_WIN_POS(pipe),
6273 crtc_state->pch_pfit.pos);
6274 intel_de_write(dev_priv, PF_WIN_SZ(pipe),
6275 crtc_state->pch_pfit.size);
6279 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
6281 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6282 struct drm_device *dev = crtc->base.dev;
6283 struct drm_i915_private *dev_priv = to_i915(dev);
6285 if (!crtc_state->ips_enabled)
6289 * We can only enable IPS after we enable a plane and wait for a vblank
6290 * This function is called from post_plane_update, which is run after
6293 drm_WARN_ON(dev, !(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
6295 if (IS_BROADWELL(dev_priv)) {
6296 drm_WARN_ON(dev, sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
6297 IPS_ENABLE | IPS_PCODE_CONTROL));
6298 /* Quoting Art Runyan: "its not safe to expect any particular
6299 * value in IPS_CTL bit 31 after enabling IPS through the
6300 * mailbox." Moreover, the mailbox may return a bogus state,
6301 * so we need to just enable it and continue on.
6304 intel_de_write(dev_priv, IPS_CTL, IPS_ENABLE);
6305 /* The bit only becomes 1 in the next vblank, so this wait here
6306 * is essentially intel_wait_for_vblank. If we don't have this
6307 * and don't wait for vblanks until the end of crtc_enable, then
6308 * the HW state readout code will complain that the expected
6309 * IPS_CTL value is not the one we read. */
6310 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
6311 drm_err(&dev_priv->drm,
6312 "Timed out waiting for IPS enable\n");
6316 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
6318 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6319 struct drm_device *dev = crtc->base.dev;
6320 struct drm_i915_private *dev_priv = to_i915(dev);
6322 if (!crtc_state->ips_enabled)
6325 if (IS_BROADWELL(dev_priv)) {
6327 sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
6329 * Wait for PCODE to finish disabling IPS. The BSpec specified
6330 * 42ms timeout value leads to occasional timeouts so use 100ms
6333 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
6334 drm_err(&dev_priv->drm,
6335 "Timed out waiting for IPS disable\n");
6337 intel_de_write(dev_priv, IPS_CTL, 0);
6338 intel_de_posting_read(dev_priv, IPS_CTL);
6341 /* We need to wait for a vblank before we can disable the plane. */
6342 intel_wait_for_vblank(dev_priv, crtc->pipe);
6345 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
6347 if (intel_crtc->overlay)
6348 (void) intel_overlay_switch_off(intel_crtc->overlay);
6350 /* Let userspace switch the overlay on again. In most cases userspace
6351 * has to recompute where to put it anyway.
6355 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
6356 const struct intel_crtc_state *new_crtc_state)
6358 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6359 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6361 if (!old_crtc_state->ips_enabled)
6364 if (needs_modeset(new_crtc_state))
6368 * Workaround : Do not read or write the pipe palette/gamma data while
6369 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6371 * Disable IPS before we program the LUT.
6373 if (IS_HASWELL(dev_priv) &&
6374 (new_crtc_state->uapi.color_mgmt_changed ||
6375 new_crtc_state->update_pipe) &&
6376 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6379 return !new_crtc_state->ips_enabled;
6382 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
6383 const struct intel_crtc_state *new_crtc_state)
6385 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6386 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6388 if (!new_crtc_state->ips_enabled)
6391 if (needs_modeset(new_crtc_state))
6395 * Workaround : Do not read or write the pipe palette/gamma data while
6396 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6398 * Re-enable IPS after the LUT has been programmed.
6400 if (IS_HASWELL(dev_priv) &&
6401 (new_crtc_state->uapi.color_mgmt_changed ||
6402 new_crtc_state->update_pipe) &&
6403 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6407 * We can't read out IPS on broadwell, assume the worst and
6408 * forcibly enable IPS on the first fastset.
6410 if (new_crtc_state->update_pipe &&
6411 old_crtc_state->hw.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
6414 return !old_crtc_state->ips_enabled;
6417 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
6419 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6421 if (!crtc_state->nv12_planes)
6424 /* WA Display #0827: Gen9:all */
6425 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
6431 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
6433 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6435 /* Wa_2006604312:icl */
6436 if (crtc_state->scaler_state.scaler_users > 0 && IS_ICELAKE(dev_priv))
6442 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
6443 const struct intel_crtc_state *new_crtc_state)
6445 return (!old_crtc_state->active_planes || needs_modeset(new_crtc_state)) &&
6446 new_crtc_state->active_planes;
6449 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
6450 const struct intel_crtc_state *new_crtc_state)
6452 return old_crtc_state->active_planes &&
6453 (!new_crtc_state->active_planes || needs_modeset(new_crtc_state));
6456 static void intel_post_plane_update(struct intel_atomic_state *state,
6457 struct intel_crtc *crtc)
6459 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6460 const struct intel_crtc_state *old_crtc_state =
6461 intel_atomic_get_old_crtc_state(state, crtc);
6462 const struct intel_crtc_state *new_crtc_state =
6463 intel_atomic_get_new_crtc_state(state, crtc);
6464 enum pipe pipe = crtc->pipe;
6466 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
6468 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
6469 intel_update_watermarks(crtc);
6471 if (hsw_post_update_enable_ips(old_crtc_state, new_crtc_state))
6472 hsw_enable_ips(new_crtc_state);
6474 intel_fbc_post_update(state, crtc);
6476 if (needs_nv12_wa(old_crtc_state) &&
6477 !needs_nv12_wa(new_crtc_state))
6478 skl_wa_827(dev_priv, pipe, false);
6480 if (needs_scalerclk_wa(old_crtc_state) &&
6481 !needs_scalerclk_wa(new_crtc_state))
6482 icl_wa_scalerclkgating(dev_priv, pipe, false);
6485 static void intel_pre_plane_update(struct intel_atomic_state *state,
6486 struct intel_crtc *crtc)
6488 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6489 const struct intel_crtc_state *old_crtc_state =
6490 intel_atomic_get_old_crtc_state(state, crtc);
6491 const struct intel_crtc_state *new_crtc_state =
6492 intel_atomic_get_new_crtc_state(state, crtc);
6493 enum pipe pipe = crtc->pipe;
6495 if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
6496 hsw_disable_ips(old_crtc_state);
6498 if (intel_fbc_pre_update(state, crtc))
6499 intel_wait_for_vblank(dev_priv, pipe);
6501 /* Display WA 827 */
6502 if (!needs_nv12_wa(old_crtc_state) &&
6503 needs_nv12_wa(new_crtc_state))
6504 skl_wa_827(dev_priv, pipe, true);
6506 /* Wa_2006604312:icl */
6507 if (!needs_scalerclk_wa(old_crtc_state) &&
6508 needs_scalerclk_wa(new_crtc_state))
6509 icl_wa_scalerclkgating(dev_priv, pipe, true);
6512 * Vblank time updates from the shadow to live plane control register
6513 * are blocked if the memory self-refresh mode is active at that
6514 * moment. So to make sure the plane gets truly disabled, disable
6515 * first the self-refresh mode. The self-refresh enable bit in turn
6516 * will be checked/applied by the HW only at the next frame start
6517 * event which is after the vblank start event, so we need to have a
6518 * wait-for-vblank between disabling the plane and the pipe.
6520 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
6521 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
6522 intel_wait_for_vblank(dev_priv, pipe);
6525 * IVB workaround: must disable low power watermarks for at least
6526 * one frame before enabling scaling. LP watermarks can be re-enabled
6527 * when scaling is disabled.
6529 * WaCxSRDisabledForSpriteScaling:ivb
6531 if (old_crtc_state->hw.active &&
6532 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
6533 intel_wait_for_vblank(dev_priv, pipe);
6536 * If we're doing a modeset we don't need to do any
6537 * pre-vblank watermark programming here.
6539 if (!needs_modeset(new_crtc_state)) {
6541 * For platforms that support atomic watermarks, program the
6542 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6543 * will be the intermediate values that are safe for both pre- and
6544 * post- vblank; when vblank happens, the 'active' values will be set
6545 * to the final 'target' values and we'll do this again to get the
6546 * optimal watermarks. For gen9+ platforms, the values we program here
6547 * will be the final target values which will get automatically latched
6548 * at vblank time; no further programming will be necessary.
6550 * If a platform hasn't been transitioned to atomic watermarks yet,
6551 * we'll continue to update watermarks the old way, if flags tell
6554 if (dev_priv->display.initial_watermarks)
6555 dev_priv->display.initial_watermarks(state, crtc);
6556 else if (new_crtc_state->update_wm_pre)
6557 intel_update_watermarks(crtc);
6561 * Gen2 reports pipe underruns whenever all planes are disabled.
6562 * So disable underrun reporting before all the planes get disabled.
6564 * We do this after .initial_watermarks() so that we have a
6565 * chance of catching underruns with the intermediate watermarks
6566 * vs. the old plane configuration.
6568 if (IS_GEN(dev_priv, 2) && planes_disabling(old_crtc_state, new_crtc_state))
6569 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6572 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6573 struct intel_crtc *crtc)
6575 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6576 const struct intel_crtc_state *new_crtc_state =
6577 intel_atomic_get_new_crtc_state(state, crtc);
6578 unsigned int update_mask = new_crtc_state->update_planes;
6579 const struct intel_plane_state *old_plane_state;
6580 struct intel_plane *plane;
6581 unsigned fb_bits = 0;
6584 intel_crtc_dpms_overlay_disable(crtc);
6586 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6587 if (crtc->pipe != plane->pipe ||
6588 !(update_mask & BIT(plane->id)))
6591 intel_disable_plane(plane, new_crtc_state);
6593 if (old_plane_state->uapi.visible)
6594 fb_bits |= plane->frontbuffer_bit;
6597 intel_frontbuffer_flip(dev_priv, fb_bits);
6601 * intel_connector_primary_encoder - get the primary encoder for a connector
6602 * @connector: connector for which to return the encoder
6604 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6605 * all connectors to their encoder, except for DP-MST connectors which have
6606 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6607 * pointed to by as many DP-MST connectors as there are pipes.
6609 static struct intel_encoder *
6610 intel_connector_primary_encoder(struct intel_connector *connector)
6612 struct intel_encoder *encoder;
6614 if (connector->mst_port)
6615 return &dp_to_dig_port(connector->mst_port)->base;
6617 encoder = intel_attached_encoder(connector);
6623 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6625 struct drm_connector_state *new_conn_state;
6626 struct drm_connector *connector;
6629 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6631 struct intel_connector *intel_connector;
6632 struct intel_encoder *encoder;
6633 struct intel_crtc *crtc;
6635 if (!intel_connector_needs_modeset(state, connector))
6638 intel_connector = to_intel_connector(connector);
6639 encoder = intel_connector_primary_encoder(intel_connector);
6640 if (!encoder->update_prepare)
6643 crtc = new_conn_state->crtc ?
6644 to_intel_crtc(new_conn_state->crtc) : NULL;
6645 encoder->update_prepare(state, encoder, crtc);
6649 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6651 struct drm_connector_state *new_conn_state;
6652 struct drm_connector *connector;
6655 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6657 struct intel_connector *intel_connector;
6658 struct intel_encoder *encoder;
6659 struct intel_crtc *crtc;
6661 if (!intel_connector_needs_modeset(state, connector))
6664 intel_connector = to_intel_connector(connector);
6665 encoder = intel_connector_primary_encoder(intel_connector);
6666 if (!encoder->update_complete)
6669 crtc = new_conn_state->crtc ?
6670 to_intel_crtc(new_conn_state->crtc) : NULL;
6671 encoder->update_complete(state, encoder, crtc);
6675 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
6676 struct intel_crtc *crtc)
6678 const struct intel_crtc_state *crtc_state =
6679 intel_atomic_get_new_crtc_state(state, crtc);
6680 const struct drm_connector_state *conn_state;
6681 struct drm_connector *conn;
6684 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6685 struct intel_encoder *encoder =
6686 to_intel_encoder(conn_state->best_encoder);
6688 if (conn_state->crtc != &crtc->base)
6691 if (encoder->pre_pll_enable)
6692 encoder->pre_pll_enable(state, encoder,
6693 crtc_state, conn_state);
6697 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
6698 struct intel_crtc *crtc)
6700 const struct intel_crtc_state *crtc_state =
6701 intel_atomic_get_new_crtc_state(state, crtc);
6702 const struct drm_connector_state *conn_state;
6703 struct drm_connector *conn;
6706 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6707 struct intel_encoder *encoder =
6708 to_intel_encoder(conn_state->best_encoder);
6710 if (conn_state->crtc != &crtc->base)
6713 if (encoder->pre_enable)
6714 encoder->pre_enable(state, encoder,
6715 crtc_state, conn_state);
6719 static void intel_encoders_enable(struct intel_atomic_state *state,
6720 struct intel_crtc *crtc)
6722 const struct intel_crtc_state *crtc_state =
6723 intel_atomic_get_new_crtc_state(state, crtc);
6724 const struct drm_connector_state *conn_state;
6725 struct drm_connector *conn;
6728 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6729 struct intel_encoder *encoder =
6730 to_intel_encoder(conn_state->best_encoder);
6732 if (conn_state->crtc != &crtc->base)
6735 if (encoder->enable)
6736 encoder->enable(state, encoder,
6737 crtc_state, conn_state);
6738 intel_opregion_notify_encoder(encoder, true);
6742 static void intel_encoders_disable(struct intel_atomic_state *state,
6743 struct intel_crtc *crtc)
6745 const struct intel_crtc_state *old_crtc_state =
6746 intel_atomic_get_old_crtc_state(state, crtc);
6747 const struct drm_connector_state *old_conn_state;
6748 struct drm_connector *conn;
6751 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6752 struct intel_encoder *encoder =
6753 to_intel_encoder(old_conn_state->best_encoder);
6755 if (old_conn_state->crtc != &crtc->base)
6758 intel_opregion_notify_encoder(encoder, false);
6759 if (encoder->disable)
6760 encoder->disable(state, encoder,
6761 old_crtc_state, old_conn_state);
6765 static void intel_encoders_post_disable(struct intel_atomic_state *state,
6766 struct intel_crtc *crtc)
6768 const struct intel_crtc_state *old_crtc_state =
6769 intel_atomic_get_old_crtc_state(state, crtc);
6770 const struct drm_connector_state *old_conn_state;
6771 struct drm_connector *conn;
6774 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6775 struct intel_encoder *encoder =
6776 to_intel_encoder(old_conn_state->best_encoder);
6778 if (old_conn_state->crtc != &crtc->base)
6781 if (encoder->post_disable)
6782 encoder->post_disable(state, encoder,
6783 old_crtc_state, old_conn_state);
6787 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
6788 struct intel_crtc *crtc)
6790 const struct intel_crtc_state *old_crtc_state =
6791 intel_atomic_get_old_crtc_state(state, crtc);
6792 const struct drm_connector_state *old_conn_state;
6793 struct drm_connector *conn;
6796 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6797 struct intel_encoder *encoder =
6798 to_intel_encoder(old_conn_state->best_encoder);
6800 if (old_conn_state->crtc != &crtc->base)
6803 if (encoder->post_pll_disable)
6804 encoder->post_pll_disable(state, encoder,
6805 old_crtc_state, old_conn_state);
6809 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
6810 struct intel_crtc *crtc)
6812 const struct intel_crtc_state *crtc_state =
6813 intel_atomic_get_new_crtc_state(state, crtc);
6814 const struct drm_connector_state *conn_state;
6815 struct drm_connector *conn;
6818 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6819 struct intel_encoder *encoder =
6820 to_intel_encoder(conn_state->best_encoder);
6822 if (conn_state->crtc != &crtc->base)
6825 if (encoder->update_pipe)
6826 encoder->update_pipe(state, encoder,
6827 crtc_state, conn_state);
6831 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6833 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6834 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6836 plane->disable_plane(plane, crtc_state);
6839 static void ilk_crtc_enable(struct intel_atomic_state *state,
6840 struct intel_crtc *crtc)
6842 const struct intel_crtc_state *new_crtc_state =
6843 intel_atomic_get_new_crtc_state(state, crtc);
6844 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6845 enum pipe pipe = crtc->pipe;
6847 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
6851 * Sometimes spurious CPU pipe underruns happen during FDI
6852 * training, at least with VGA+HDMI cloning. Suppress them.
6854 * On ILK we get an occasional spurious CPU pipe underruns
6855 * between eDP port A enable and vdd enable. Also PCH port
6856 * enable seems to result in the occasional CPU pipe underrun.
6858 * Spurious PCH underruns also occur during PCH enabling.
6860 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6861 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6863 if (new_crtc_state->has_pch_encoder)
6864 intel_prepare_shared_dpll(new_crtc_state);
6866 if (intel_crtc_has_dp_encoder(new_crtc_state))
6867 intel_dp_set_m_n(new_crtc_state, M1_N1);
6869 intel_set_pipe_timings(new_crtc_state);
6870 intel_set_pipe_src_size(new_crtc_state);
6872 if (new_crtc_state->has_pch_encoder)
6873 intel_cpu_transcoder_set_m_n(new_crtc_state,
6874 &new_crtc_state->fdi_m_n, NULL);
6876 ilk_set_pipeconf(new_crtc_state);
6878 crtc->active = true;
6880 intel_encoders_pre_enable(state, crtc);
6882 if (new_crtc_state->has_pch_encoder) {
6883 /* Note: FDI PLL enabling _must_ be done before we enable the
6884 * cpu pipes, hence this is separate from all the other fdi/pch
6886 ilk_fdi_pll_enable(new_crtc_state);
6888 assert_fdi_tx_disabled(dev_priv, pipe);
6889 assert_fdi_rx_disabled(dev_priv, pipe);
6892 ilk_pfit_enable(new_crtc_state);
6895 * On ILK+ LUT must be loaded before the pipe is running but with
6898 intel_color_load_luts(new_crtc_state);
6899 intel_color_commit(new_crtc_state);
6900 /* update DSPCNTR to configure gamma for pipe bottom color */
6901 intel_disable_primary_plane(new_crtc_state);
6903 if (dev_priv->display.initial_watermarks)
6904 dev_priv->display.initial_watermarks(state, crtc);
6905 intel_enable_pipe(new_crtc_state);
6907 if (new_crtc_state->has_pch_encoder)
6908 ilk_pch_enable(state, new_crtc_state);
6910 intel_crtc_vblank_on(new_crtc_state);
6912 intel_encoders_enable(state, crtc);
6914 if (HAS_PCH_CPT(dev_priv))
6915 cpt_verify_modeset(dev_priv, pipe);
6918 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6919 * And a second vblank wait is needed at least on ILK with
6920 * some interlaced HDMI modes. Let's do the double wait always
6921 * in case there are more corner cases we don't know about.
6923 if (new_crtc_state->has_pch_encoder) {
6924 intel_wait_for_vblank(dev_priv, pipe);
6925 intel_wait_for_vblank(dev_priv, pipe);
6927 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6928 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6931 /* IPS only exists on ULT machines and is tied to pipe A. */
6932 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6934 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6937 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6938 enum pipe pipe, bool apply)
6940 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
6941 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6948 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
6951 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6953 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6954 enum pipe pipe = crtc->pipe;
6957 val = MBUS_DBOX_A_CREDIT(2);
6959 if (INTEL_GEN(dev_priv) >= 12) {
6960 val |= MBUS_DBOX_BW_CREDIT(2);
6961 val |= MBUS_DBOX_B_CREDIT(12);
6963 val |= MBUS_DBOX_BW_CREDIT(1);
6964 val |= MBUS_DBOX_B_CREDIT(8);
6967 intel_de_write(dev_priv, PIPE_MBUS_DBOX_CTL(pipe), val);
6970 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
6972 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6973 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6975 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
6976 HSW_LINETIME(crtc_state->linetime) |
6977 HSW_IPS_LINETIME(crtc_state->ips_linetime));
6980 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
6982 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6983 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6984 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
6987 val = intel_de_read(dev_priv, reg);
6988 val &= ~HSW_FRAME_START_DELAY_MASK;
6989 val |= HSW_FRAME_START_DELAY(0);
6990 intel_de_write(dev_priv, reg, val);
6993 static void hsw_crtc_enable(struct intel_atomic_state *state,
6994 struct intel_crtc *crtc)
6996 const struct intel_crtc_state *new_crtc_state =
6997 intel_atomic_get_new_crtc_state(state, crtc);
6998 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6999 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
7000 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
7001 bool psl_clkgate_wa;
7003 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
7006 intel_encoders_pre_pll_enable(state, crtc);
7008 if (new_crtc_state->shared_dpll)
7009 intel_enable_shared_dpll(new_crtc_state);
7011 intel_encoders_pre_enable(state, crtc);
7013 if (!transcoder_is_dsi(cpu_transcoder))
7014 intel_set_pipe_timings(new_crtc_state);
7016 intel_set_pipe_src_size(new_crtc_state);
7018 if (cpu_transcoder != TRANSCODER_EDP &&
7019 !transcoder_is_dsi(cpu_transcoder))
7020 intel_de_write(dev_priv, PIPE_MULT(cpu_transcoder),
7021 new_crtc_state->pixel_multiplier - 1);
7023 if (new_crtc_state->has_pch_encoder)
7024 intel_cpu_transcoder_set_m_n(new_crtc_state,
7025 &new_crtc_state->fdi_m_n, NULL);
7027 if (!transcoder_is_dsi(cpu_transcoder)) {
7028 hsw_set_frame_start_delay(new_crtc_state);
7029 hsw_set_pipeconf(new_crtc_state);
7032 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
7033 bdw_set_pipemisc(new_crtc_state);
7035 crtc->active = true;
7037 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
7038 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
7039 new_crtc_state->pch_pfit.enabled;
7041 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
7043 if (INTEL_GEN(dev_priv) >= 9)
7044 skl_pfit_enable(new_crtc_state);
7046 ilk_pfit_enable(new_crtc_state);
7049 * On ILK+ LUT must be loaded before the pipe is running but with
7052 intel_color_load_luts(new_crtc_state);
7053 intel_color_commit(new_crtc_state);
7054 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
7055 if (INTEL_GEN(dev_priv) < 9)
7056 intel_disable_primary_plane(new_crtc_state);
7058 hsw_set_linetime_wm(new_crtc_state);
7060 if (INTEL_GEN(dev_priv) >= 11)
7061 icl_set_pipe_chicken(crtc);
7063 if (!transcoder_is_dsi(cpu_transcoder))
7064 intel_ddi_enable_transcoder_func(new_crtc_state);
7066 if (dev_priv->display.initial_watermarks)
7067 dev_priv->display.initial_watermarks(state, crtc);
7069 if (INTEL_GEN(dev_priv) >= 11)
7070 icl_pipe_mbus_enable(crtc);
7072 intel_encoders_enable(state, crtc);
7074 if (psl_clkgate_wa) {
7075 intel_wait_for_vblank(dev_priv, pipe);
7076 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
7079 /* If we change the relative order between pipe/planes enabling, we need
7080 * to change the workaround. */
7081 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
7082 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
7083 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
7084 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
7088 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
7090 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
7091 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7092 enum pipe pipe = crtc->pipe;
7094 /* To avoid upsetting the power well on haswell only disable the pfit if
7095 * it's in use. The hw state code will make sure we get this right. */
7096 if (old_crtc_state->pch_pfit.enabled) {
7097 intel_de_write(dev_priv, PF_CTL(pipe), 0);
7098 intel_de_write(dev_priv, PF_WIN_POS(pipe), 0);
7099 intel_de_write(dev_priv, PF_WIN_SZ(pipe), 0);
7103 static void ilk_crtc_disable(struct intel_atomic_state *state,
7104 struct intel_crtc *crtc)
7106 const struct intel_crtc_state *old_crtc_state =
7107 intel_atomic_get_old_crtc_state(state, crtc);
7108 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7109 enum pipe pipe = crtc->pipe;
7112 * Sometimes spurious CPU pipe underruns happen when the
7113 * pipe is already disabled, but FDI RX/TX is still enabled.
7114 * Happens at least with VGA+HDMI cloning. Suppress them.
7116 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7117 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
7119 intel_encoders_disable(state, crtc);
7121 intel_crtc_vblank_off(old_crtc_state);
7123 intel_disable_pipe(old_crtc_state);
7125 ilk_pfit_disable(old_crtc_state);
7127 if (old_crtc_state->has_pch_encoder)
7128 ilk_fdi_disable(crtc);
7130 intel_encoders_post_disable(state, crtc);
7132 if (old_crtc_state->has_pch_encoder) {
7133 ilk_disable_pch_transcoder(dev_priv, pipe);
7135 if (HAS_PCH_CPT(dev_priv)) {
7139 /* disable TRANS_DP_CTL */
7140 reg = TRANS_DP_CTL(pipe);
7141 temp = intel_de_read(dev_priv, reg);
7142 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
7143 TRANS_DP_PORT_SEL_MASK);
7144 temp |= TRANS_DP_PORT_SEL_NONE;
7145 intel_de_write(dev_priv, reg, temp);
7147 /* disable DPLL_SEL */
7148 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
7149 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
7150 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
7153 ilk_fdi_pll_disable(crtc);
7156 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7157 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
7160 static void hsw_crtc_disable(struct intel_atomic_state *state,
7161 struct intel_crtc *crtc)
7164 * FIXME collapse everything to one hook.
7165 * Need care with mst->ddi interactions.
7167 intel_encoders_disable(state, crtc);
7168 intel_encoders_post_disable(state, crtc);
7171 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
7173 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7174 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7176 if (!crtc_state->gmch_pfit.control)
7180 * The panel fitter should only be adjusted whilst the pipe is disabled,
7181 * according to register description and PRM.
7183 drm_WARN_ON(&dev_priv->drm,
7184 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
7185 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
7187 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
7188 crtc_state->gmch_pfit.pgm_ratios);
7189 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
7191 /* Border color in case we don't scale up to the full screen. Black by
7192 * default, change to something else for debugging. */
7193 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
7196 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
7198 if (phy == PHY_NONE)
7201 if (IS_ELKHARTLAKE(dev_priv))
7202 return phy <= PHY_C;
7204 if (INTEL_GEN(dev_priv) >= 11)
7205 return phy <= PHY_B;
7210 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
7212 if (INTEL_GEN(dev_priv) >= 12)
7213 return phy >= PHY_D && phy <= PHY_I;
7215 if (INTEL_GEN(dev_priv) >= 11 && !IS_ELKHARTLAKE(dev_priv))
7216 return phy >= PHY_C && phy <= PHY_F;
7221 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
7223 if (IS_ELKHARTLAKE(i915) && port == PORT_D)
7226 return (enum phy)port;
7229 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
7231 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
7232 return PORT_TC_NONE;
7234 if (INTEL_GEN(dev_priv) >= 12)
7235 return port - PORT_D;
7237 return port - PORT_C;
7240 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
7244 return POWER_DOMAIN_PORT_DDI_A_LANES;
7246 return POWER_DOMAIN_PORT_DDI_B_LANES;
7248 return POWER_DOMAIN_PORT_DDI_C_LANES;
7250 return POWER_DOMAIN_PORT_DDI_D_LANES;
7252 return POWER_DOMAIN_PORT_DDI_E_LANES;
7254 return POWER_DOMAIN_PORT_DDI_F_LANES;
7256 return POWER_DOMAIN_PORT_DDI_G_LANES;
7259 return POWER_DOMAIN_PORT_OTHER;
7263 enum intel_display_power_domain
7264 intel_aux_power_domain(struct intel_digital_port *dig_port)
7266 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
7267 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
7269 if (intel_phy_is_tc(dev_priv, phy) &&
7270 dig_port->tc_mode == TC_PORT_TBT_ALT) {
7271 switch (dig_port->aux_ch) {
7273 return POWER_DOMAIN_AUX_C_TBT;
7275 return POWER_DOMAIN_AUX_D_TBT;
7277 return POWER_DOMAIN_AUX_E_TBT;
7279 return POWER_DOMAIN_AUX_F_TBT;
7281 return POWER_DOMAIN_AUX_G_TBT;
7283 MISSING_CASE(dig_port->aux_ch);
7284 return POWER_DOMAIN_AUX_C_TBT;
7288 switch (dig_port->aux_ch) {
7290 return POWER_DOMAIN_AUX_A;
7292 return POWER_DOMAIN_AUX_B;
7294 return POWER_DOMAIN_AUX_C;
7296 return POWER_DOMAIN_AUX_D;
7298 return POWER_DOMAIN_AUX_E;
7300 return POWER_DOMAIN_AUX_F;
7302 return POWER_DOMAIN_AUX_G;
7304 MISSING_CASE(dig_port->aux_ch);
7305 return POWER_DOMAIN_AUX_A;
7309 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7311 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7312 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7313 struct drm_encoder *encoder;
7314 enum pipe pipe = crtc->pipe;
7316 enum transcoder transcoder = crtc_state->cpu_transcoder;
7318 if (!crtc_state->hw.active)
7321 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
7322 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
7323 if (crtc_state->pch_pfit.enabled ||
7324 crtc_state->pch_pfit.force_thru)
7325 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
7327 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
7328 crtc_state->uapi.encoder_mask) {
7329 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7331 mask |= BIT_ULL(intel_encoder->power_domain);
7334 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
7335 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
7337 if (crtc_state->shared_dpll)
7338 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
7344 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7346 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7347 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7348 enum intel_display_power_domain domain;
7349 u64 domains, new_domains, old_domains;
7351 old_domains = crtc->enabled_power_domains;
7352 crtc->enabled_power_domains = new_domains =
7353 get_crtc_power_domains(crtc_state);
7355 domains = new_domains & ~old_domains;
7357 for_each_power_domain(domain, domains)
7358 intel_display_power_get(dev_priv, domain);
7360 return old_domains & ~new_domains;
7363 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
7366 enum intel_display_power_domain domain;
7368 for_each_power_domain(domain, domains)
7369 intel_display_power_put_unchecked(dev_priv, domain);
7372 static void valleyview_crtc_enable(struct intel_atomic_state *state,
7373 struct intel_crtc *crtc)
7375 const struct intel_crtc_state *new_crtc_state =
7376 intel_atomic_get_new_crtc_state(state, crtc);
7377 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7378 enum pipe pipe = crtc->pipe;
7380 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
7383 if (intel_crtc_has_dp_encoder(new_crtc_state))
7384 intel_dp_set_m_n(new_crtc_state, M1_N1);
7386 intel_set_pipe_timings(new_crtc_state);
7387 intel_set_pipe_src_size(new_crtc_state);
7389 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
7390 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
7391 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
7394 i9xx_set_pipeconf(new_crtc_state);
7396 crtc->active = true;
7398 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7400 intel_encoders_pre_pll_enable(state, crtc);
7402 if (IS_CHERRYVIEW(dev_priv)) {
7403 chv_prepare_pll(crtc, new_crtc_state);
7404 chv_enable_pll(crtc, new_crtc_state);
7406 vlv_prepare_pll(crtc, new_crtc_state);
7407 vlv_enable_pll(crtc, new_crtc_state);
7410 intel_encoders_pre_enable(state, crtc);
7412 i9xx_pfit_enable(new_crtc_state);
7414 intel_color_load_luts(new_crtc_state);
7415 intel_color_commit(new_crtc_state);
7416 /* update DSPCNTR to configure gamma for pipe bottom color */
7417 intel_disable_primary_plane(new_crtc_state);
7419 dev_priv->display.initial_watermarks(state, crtc);
7420 intel_enable_pipe(new_crtc_state);
7422 intel_crtc_vblank_on(new_crtc_state);
7424 intel_encoders_enable(state, crtc);
7427 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
7429 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7430 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7432 intel_de_write(dev_priv, FP0(crtc->pipe),
7433 crtc_state->dpll_hw_state.fp0);
7434 intel_de_write(dev_priv, FP1(crtc->pipe),
7435 crtc_state->dpll_hw_state.fp1);
7438 static void i9xx_crtc_enable(struct intel_atomic_state *state,
7439 struct intel_crtc *crtc)
7441 const struct intel_crtc_state *new_crtc_state =
7442 intel_atomic_get_new_crtc_state(state, crtc);
7443 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7444 enum pipe pipe = crtc->pipe;
7446 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
7449 i9xx_set_pll_dividers(new_crtc_state);
7451 if (intel_crtc_has_dp_encoder(new_crtc_state))
7452 intel_dp_set_m_n(new_crtc_state, M1_N1);
7454 intel_set_pipe_timings(new_crtc_state);
7455 intel_set_pipe_src_size(new_crtc_state);
7457 i9xx_set_pipeconf(new_crtc_state);
7459 crtc->active = true;
7461 if (!IS_GEN(dev_priv, 2))
7462 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7464 intel_encoders_pre_enable(state, crtc);
7466 i9xx_enable_pll(crtc, new_crtc_state);
7468 i9xx_pfit_enable(new_crtc_state);
7470 intel_color_load_luts(new_crtc_state);
7471 intel_color_commit(new_crtc_state);
7472 /* update DSPCNTR to configure gamma for pipe bottom color */
7473 intel_disable_primary_plane(new_crtc_state);
7475 if (dev_priv->display.initial_watermarks)
7476 dev_priv->display.initial_watermarks(state, crtc);
7478 intel_update_watermarks(crtc);
7479 intel_enable_pipe(new_crtc_state);
7481 intel_crtc_vblank_on(new_crtc_state);
7483 intel_encoders_enable(state, crtc);
7486 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
7488 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
7489 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7491 if (!old_crtc_state->gmch_pfit.control)
7494 assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
7496 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
7497 intel_de_read(dev_priv, PFIT_CONTROL));
7498 intel_de_write(dev_priv, PFIT_CONTROL, 0);
7501 static void i9xx_crtc_disable(struct intel_atomic_state *state,
7502 struct intel_crtc *crtc)
7504 struct intel_crtc_state *old_crtc_state =
7505 intel_atomic_get_old_crtc_state(state, crtc);
7506 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7507 enum pipe pipe = crtc->pipe;
7510 * On gen2 planes are double buffered but the pipe isn't, so we must
7511 * wait for planes to fully turn off before disabling the pipe.
7513 if (IS_GEN(dev_priv, 2))
7514 intel_wait_for_vblank(dev_priv, pipe);
7516 intel_encoders_disable(state, crtc);
7518 intel_crtc_vblank_off(old_crtc_state);
7520 intel_disable_pipe(old_crtc_state);
7522 i9xx_pfit_disable(old_crtc_state);
7524 intel_encoders_post_disable(state, crtc);
7526 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
7527 if (IS_CHERRYVIEW(dev_priv))
7528 chv_disable_pll(dev_priv, pipe);
7529 else if (IS_VALLEYVIEW(dev_priv))
7530 vlv_disable_pll(dev_priv, pipe);
7532 i9xx_disable_pll(old_crtc_state);
7535 intel_encoders_post_pll_disable(state, crtc);
7537 if (!IS_GEN(dev_priv, 2))
7538 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7540 if (!dev_priv->display.initial_watermarks)
7541 intel_update_watermarks(crtc);
7543 /* clock the pipe down to 640x480@60 to potentially save power */
7544 if (IS_I830(dev_priv))
7545 i830_enable_pipe(dev_priv, pipe);
7548 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc,
7549 struct drm_modeset_acquire_ctx *ctx)
7551 struct intel_encoder *encoder;
7552 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7553 struct intel_bw_state *bw_state =
7554 to_intel_bw_state(dev_priv->bw_obj.state);
7555 struct intel_cdclk_state *cdclk_state =
7556 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
7557 struct intel_crtc_state *crtc_state =
7558 to_intel_crtc_state(crtc->base.state);
7559 enum intel_display_power_domain domain;
7560 struct intel_plane *plane;
7561 struct drm_atomic_state *state;
7562 struct intel_crtc_state *temp_crtc_state;
7563 enum pipe pipe = crtc->pipe;
7567 if (!crtc_state->hw.active)
7570 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
7571 const struct intel_plane_state *plane_state =
7572 to_intel_plane_state(plane->base.state);
7574 if (plane_state->uapi.visible)
7575 intel_plane_disable_noatomic(crtc, plane);
7578 state = drm_atomic_state_alloc(&dev_priv->drm);
7580 drm_dbg_kms(&dev_priv->drm,
7581 "failed to disable [CRTC:%d:%s], out of memory",
7582 crtc->base.base.id, crtc->base.name);
7586 state->acquire_ctx = ctx;
7588 /* Everything's already locked, -EDEADLK can't happen. */
7589 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc);
7590 ret = drm_atomic_add_affected_connectors(state, &crtc->base);
7592 drm_WARN_ON(&dev_priv->drm, IS_ERR(temp_crtc_state) || ret);
7594 dev_priv->display.crtc_disable(to_intel_atomic_state(state), crtc);
7596 drm_atomic_state_put(state);
7598 drm_dbg_kms(&dev_priv->drm,
7599 "[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7600 crtc->base.base.id, crtc->base.name);
7602 crtc->active = false;
7603 crtc->base.enabled = false;
7605 drm_WARN_ON(&dev_priv->drm,
7606 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0);
7607 crtc_state->uapi.active = false;
7608 crtc_state->uapi.connector_mask = 0;
7609 crtc_state->uapi.encoder_mask = 0;
7610 intel_crtc_free_hw_state(crtc_state);
7611 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw));
7613 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder)
7614 encoder->base.crtc = NULL;
7616 intel_fbc_disable(crtc);
7617 intel_update_watermarks(crtc);
7618 intel_disable_shared_dpll(crtc_state);
7620 domains = crtc->enabled_power_domains;
7621 for_each_power_domain(domain, domains)
7622 intel_display_power_put_unchecked(dev_priv, domain);
7623 crtc->enabled_power_domains = 0;
7625 dev_priv->active_pipes &= ~BIT(pipe);
7626 cdclk_state->min_cdclk[pipe] = 0;
7627 cdclk_state->min_voltage_level[pipe] = 0;
7628 cdclk_state->active_pipes &= ~BIT(pipe);
7630 bw_state->data_rate[pipe] = 0;
7631 bw_state->num_active_planes[pipe] = 0;
7635 * turn all crtc's off, but do not adjust state
7636 * This has to be paired with a call to intel_modeset_setup_hw_state.
7638 int intel_display_suspend(struct drm_device *dev)
7640 struct drm_i915_private *dev_priv = to_i915(dev);
7641 struct drm_atomic_state *state;
7644 state = drm_atomic_helper_suspend(dev);
7645 ret = PTR_ERR_OR_ZERO(state);
7647 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
7650 dev_priv->modeset_restore_state = state;
7654 void intel_encoder_destroy(struct drm_encoder *encoder)
7656 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7658 drm_encoder_cleanup(encoder);
7659 kfree(intel_encoder);
7662 /* Cross check the actual hw state with our own modeset state tracking (and it's
7663 * internal consistency). */
7664 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7665 struct drm_connector_state *conn_state)
7667 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7668 struct drm_i915_private *i915 = to_i915(connector->base.dev);
7670 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n",
7671 connector->base.base.id, connector->base.name);
7673 if (connector->get_hw_state(connector)) {
7674 struct intel_encoder *encoder = intel_attached_encoder(connector);
7676 I915_STATE_WARN(!crtc_state,
7677 "connector enabled without attached crtc\n");
7682 I915_STATE_WARN(!crtc_state->hw.active,
7683 "connector is active, but attached crtc isn't\n");
7685 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7688 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7689 "atomic encoder doesn't match attached encoder\n");
7691 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7692 "attached encoder crtc differs from connector crtc\n");
7694 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
7695 "attached crtc is active, but connector isn't\n");
7696 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7697 "best encoder set without crtc!\n");
7701 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7703 if (crtc_state->hw.enable && crtc_state->has_pch_encoder)
7704 return crtc_state->fdi_lanes;
7709 static int ilk_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7710 struct intel_crtc_state *pipe_config)
7712 struct drm_i915_private *dev_priv = to_i915(dev);
7713 struct drm_atomic_state *state = pipe_config->uapi.state;
7714 struct intel_crtc *other_crtc;
7715 struct intel_crtc_state *other_crtc_state;
7717 drm_dbg_kms(&dev_priv->drm,
7718 "checking fdi config on pipe %c, lanes %i\n",
7719 pipe_name(pipe), pipe_config->fdi_lanes);
7720 if (pipe_config->fdi_lanes > 4) {
7721 drm_dbg_kms(&dev_priv->drm,
7722 "invalid fdi lane config on pipe %c: %i lanes\n",
7723 pipe_name(pipe), pipe_config->fdi_lanes);
7727 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7728 if (pipe_config->fdi_lanes > 2) {
7729 drm_dbg_kms(&dev_priv->drm,
7730 "only 2 lanes on haswell, required: %i lanes\n",
7731 pipe_config->fdi_lanes);
7738 if (INTEL_NUM_PIPES(dev_priv) == 2)
7741 /* Ivybridge 3 pipe is really complicated */
7746 if (pipe_config->fdi_lanes <= 2)
7749 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7751 intel_atomic_get_crtc_state(state, other_crtc);
7752 if (IS_ERR(other_crtc_state))
7753 return PTR_ERR(other_crtc_state);
7755 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7756 drm_dbg_kms(&dev_priv->drm,
7757 "invalid shared fdi lane config on pipe %c: %i lanes\n",
7758 pipe_name(pipe), pipe_config->fdi_lanes);
7763 if (pipe_config->fdi_lanes > 2) {
7764 drm_dbg_kms(&dev_priv->drm,
7765 "only 2 lanes on pipe %c: required %i lanes\n",
7766 pipe_name(pipe), pipe_config->fdi_lanes);
7770 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7772 intel_atomic_get_crtc_state(state, other_crtc);
7773 if (IS_ERR(other_crtc_state))
7774 return PTR_ERR(other_crtc_state);
7776 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7777 drm_dbg_kms(&dev_priv->drm,
7778 "fdi link B uses too many lanes to enable link C\n");
7788 static int ilk_fdi_compute_config(struct intel_crtc *intel_crtc,
7789 struct intel_crtc_state *pipe_config)
7791 struct drm_device *dev = intel_crtc->base.dev;
7792 struct drm_i915_private *i915 = to_i915(dev);
7793 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7794 int lane, link_bw, fdi_dotclock, ret;
7795 bool needs_recompute = false;
7798 /* FDI is a binary signal running at ~2.7GHz, encoding
7799 * each output octet as 10 bits. The actual frequency
7800 * is stored as a divider into a 100MHz clock, and the
7801 * mode pixel clock is stored in units of 1KHz.
7802 * Hence the bw of each lane in terms of the mode signal
7805 link_bw = intel_fdi_link_freq(i915, pipe_config);
7807 fdi_dotclock = adjusted_mode->crtc_clock;
7809 lane = ilk_get_lanes_required(fdi_dotclock, link_bw,
7810 pipe_config->pipe_bpp);
7812 pipe_config->fdi_lanes = lane;
7814 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7815 link_bw, &pipe_config->fdi_m_n, false, false);
7817 ret = ilk_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7818 if (ret == -EDEADLK)
7821 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7822 pipe_config->pipe_bpp -= 2*3;
7823 drm_dbg_kms(&i915->drm,
7824 "fdi link bw constraint, reducing pipe bpp to %i\n",
7825 pipe_config->pipe_bpp);
7826 needs_recompute = true;
7827 pipe_config->bw_constrained = true;
7832 if (needs_recompute)
7838 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7840 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7841 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7843 /* IPS only exists on ULT machines and is tied to pipe A. */
7844 if (!hsw_crtc_supports_ips(crtc))
7847 if (!i915_modparams.enable_ips)
7850 if (crtc_state->pipe_bpp > 24)
7854 * We compare against max which means we must take
7855 * the increased cdclk requirement into account when
7856 * calculating the new cdclk.
7858 * Should measure whether using a lower cdclk w/o IPS
7860 if (IS_BROADWELL(dev_priv) &&
7861 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7867 static int hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7869 struct drm_i915_private *dev_priv =
7870 to_i915(crtc_state->uapi.crtc->dev);
7871 struct intel_atomic_state *state =
7872 to_intel_atomic_state(crtc_state->uapi.state);
7874 crtc_state->ips_enabled = false;
7876 if (!hsw_crtc_state_ips_capable(crtc_state))
7880 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7881 * enabled and disabled dynamically based on package C states,
7882 * user space can't make reliable use of the CRCs, so let's just
7883 * completely disable it.
7885 if (crtc_state->crc_enabled)
7888 /* IPS should be fine as long as at least one plane is enabled. */
7889 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7892 if (IS_BROADWELL(dev_priv)) {
7893 const struct intel_cdclk_state *cdclk_state;
7895 cdclk_state = intel_atomic_get_cdclk_state(state);
7896 if (IS_ERR(cdclk_state))
7897 return PTR_ERR(cdclk_state);
7899 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7900 if (crtc_state->pixel_rate > cdclk_state->logical.cdclk * 95 / 100)
7904 crtc_state->ips_enabled = true;
7909 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7911 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7913 /* GDG double wide on either pipe, otherwise pipe A only */
7914 return INTEL_GEN(dev_priv) < 4 &&
7915 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7918 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
7922 pixel_rate = pipe_config->hw.adjusted_mode.crtc_clock;
7925 * We only use IF-ID interlacing. If we ever use
7926 * PF-ID we'll need to adjust the pixel_rate here.
7929 if (pipe_config->pch_pfit.enabled) {
7930 u64 pipe_w, pipe_h, pfit_w, pfit_h;
7931 u32 pfit_size = pipe_config->pch_pfit.size;
7933 pipe_w = pipe_config->pipe_src_w;
7934 pipe_h = pipe_config->pipe_src_h;
7936 pfit_w = (pfit_size >> 16) & 0xFFFF;
7937 pfit_h = pfit_size & 0xFFFF;
7938 if (pipe_w < pfit_w)
7940 if (pipe_h < pfit_h)
7943 if (WARN_ON(!pfit_w || !pfit_h))
7946 pixel_rate = div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7953 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7955 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
7957 if (HAS_GMCH(dev_priv))
7958 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7959 crtc_state->pixel_rate =
7960 crtc_state->hw.adjusted_mode.crtc_clock;
7962 crtc_state->pixel_rate =
7963 ilk_pipe_pixel_rate(crtc_state);
7966 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7967 struct intel_crtc_state *pipe_config)
7969 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7970 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7971 int clock_limit = dev_priv->max_dotclk_freq;
7973 if (INTEL_GEN(dev_priv) < 4) {
7974 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
7977 * Enable double wide mode when the dot clock
7978 * is > 90% of the (display) core speed.
7980 if (intel_crtc_supports_double_wide(crtc) &&
7981 adjusted_mode->crtc_clock > clock_limit) {
7982 clock_limit = dev_priv->max_dotclk_freq;
7983 pipe_config->double_wide = true;
7987 if (adjusted_mode->crtc_clock > clock_limit) {
7988 drm_dbg_kms(&dev_priv->drm,
7989 "requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
7990 adjusted_mode->crtc_clock, clock_limit,
7991 yesno(pipe_config->double_wide));
7995 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
7996 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
7997 pipe_config->hw.ctm) {
7999 * There is only one pipe CSC unit per pipe, and we need that
8000 * for output conversion from RGB->YCBCR. So if CTM is already
8001 * applied we can't support YCBCR420 output.
8003 drm_dbg_kms(&dev_priv->drm,
8004 "YCBCR420 and CTM together are not possible\n");
8009 * Pipe horizontal size must be even in:
8011 * - LVDS dual channel mode
8012 * - Double wide pipe
8014 if (pipe_config->pipe_src_w & 1) {
8015 if (pipe_config->double_wide) {
8016 drm_dbg_kms(&dev_priv->drm,
8017 "Odd pipe source width not supported with double wide pipe\n");
8021 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
8022 intel_is_dual_link_lvds(dev_priv)) {
8023 drm_dbg_kms(&dev_priv->drm,
8024 "Odd pipe source width not supported with dual link LVDS\n");
8029 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
8030 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
8032 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
8033 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
8036 intel_crtc_compute_pixel_rate(pipe_config);
8038 if (pipe_config->has_pch_encoder)
8039 return ilk_fdi_compute_config(crtc, pipe_config);
8045 intel_reduce_m_n_ratio(u32 *num, u32 *den)
8047 while (*num > DATA_LINK_M_N_MASK ||
8048 *den > DATA_LINK_M_N_MASK) {
8054 static void compute_m_n(unsigned int m, unsigned int n,
8055 u32 *ret_m, u32 *ret_n,
8059 * Several DP dongles in particular seem to be fussy about
8060 * too large link M/N values. Give N value as 0x8000 that
8061 * should be acceptable by specific devices. 0x8000 is the
8062 * specified fixed N value for asynchronous clock mode,
8063 * which the devices expect also in synchronous clock mode.
8068 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
8070 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
8071 intel_reduce_m_n_ratio(ret_m, ret_n);
8075 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
8076 int pixel_clock, int link_clock,
8077 struct intel_link_m_n *m_n,
8078 bool constant_n, bool fec_enable)
8080 u32 data_clock = bits_per_pixel * pixel_clock;
8083 data_clock = intel_dp_mode_to_fec_clock(data_clock);
8086 compute_m_n(data_clock,
8087 link_clock * nlanes * 8,
8088 &m_n->gmch_m, &m_n->gmch_n,
8091 compute_m_n(pixel_clock, link_clock,
8092 &m_n->link_m, &m_n->link_n,
8096 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
8099 * There may be no VBT; and if the BIOS enabled SSC we can
8100 * just keep using it to avoid unnecessary flicker. Whereas if the
8101 * BIOS isn't using it, don't assume it will work even if the VBT
8102 * indicates as much.
8104 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
8105 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
8109 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
8110 drm_dbg_kms(&dev_priv->drm,
8111 "SSC %s by BIOS, overriding VBT which says %s\n",
8112 enableddisabled(bios_lvds_use_ssc),
8113 enableddisabled(dev_priv->vbt.lvds_use_ssc));
8114 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
8119 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
8121 if (i915_modparams.panel_use_ssc >= 0)
8122 return i915_modparams.panel_use_ssc != 0;
8123 return dev_priv->vbt.lvds_use_ssc
8124 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
8127 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
8129 return (1 << dpll->n) << 16 | dpll->m2;
8132 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
8134 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
8137 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
8138 struct intel_crtc_state *crtc_state,
8139 struct dpll *reduced_clock)
8141 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8144 if (IS_PINEVIEW(dev_priv)) {
8145 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
8147 fp2 = pnv_dpll_compute_fp(reduced_clock);
8149 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8151 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8154 crtc_state->dpll_hw_state.fp0 = fp;
8156 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8158 crtc_state->dpll_hw_state.fp1 = fp2;
8160 crtc_state->dpll_hw_state.fp1 = fp;
8164 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
8170 * PLLB opamp always calibrates to max value of 0x3f, force enable it
8171 * and set it to a reasonable value instead.
8173 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
8174 reg_val &= 0xffffff00;
8175 reg_val |= 0x00000030;
8176 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
8178 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
8179 reg_val &= 0x00ffffff;
8180 reg_val |= 0x8c000000;
8181 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
8183 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
8184 reg_val &= 0xffffff00;
8185 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
8187 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
8188 reg_val &= 0x00ffffff;
8189 reg_val |= 0xb0000000;
8190 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
8193 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
8194 const struct intel_link_m_n *m_n)
8196 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8197 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8198 enum pipe pipe = crtc->pipe;
8200 intel_de_write(dev_priv, PCH_TRANS_DATA_M1(pipe),
8201 TU_SIZE(m_n->tu) | m_n->gmch_m);
8202 intel_de_write(dev_priv, PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
8203 intel_de_write(dev_priv, PCH_TRANS_LINK_M1(pipe), m_n->link_m);
8204 intel_de_write(dev_priv, PCH_TRANS_LINK_N1(pipe), m_n->link_n);
8207 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
8208 enum transcoder transcoder)
8210 if (IS_HASWELL(dev_priv))
8211 return transcoder == TRANSCODER_EDP;
8214 * Strictly speaking some registers are available before
8215 * gen7, but we only support DRRS on gen7+
8217 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
8220 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
8221 const struct intel_link_m_n *m_n,
8222 const struct intel_link_m_n *m2_n2)
8224 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8225 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8226 enum pipe pipe = crtc->pipe;
8227 enum transcoder transcoder = crtc_state->cpu_transcoder;
8229 if (INTEL_GEN(dev_priv) >= 5) {
8230 intel_de_write(dev_priv, PIPE_DATA_M1(transcoder),
8231 TU_SIZE(m_n->tu) | m_n->gmch_m);
8232 intel_de_write(dev_priv, PIPE_DATA_N1(transcoder),
8234 intel_de_write(dev_priv, PIPE_LINK_M1(transcoder),
8236 intel_de_write(dev_priv, PIPE_LINK_N1(transcoder),
8239 * M2_N2 registers are set only if DRRS is supported
8240 * (to make sure the registers are not unnecessarily accessed).
8242 if (m2_n2 && crtc_state->has_drrs &&
8243 transcoder_has_m2_n2(dev_priv, transcoder)) {
8244 intel_de_write(dev_priv, PIPE_DATA_M2(transcoder),
8245 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
8246 intel_de_write(dev_priv, PIPE_DATA_N2(transcoder),
8248 intel_de_write(dev_priv, PIPE_LINK_M2(transcoder),
8250 intel_de_write(dev_priv, PIPE_LINK_N2(transcoder),
8254 intel_de_write(dev_priv, PIPE_DATA_M_G4X(pipe),
8255 TU_SIZE(m_n->tu) | m_n->gmch_m);
8256 intel_de_write(dev_priv, PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
8257 intel_de_write(dev_priv, PIPE_LINK_M_G4X(pipe), m_n->link_m);
8258 intel_de_write(dev_priv, PIPE_LINK_N_G4X(pipe), m_n->link_n);
8262 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
8264 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
8265 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
8268 dp_m_n = &crtc_state->dp_m_n;
8269 dp_m2_n2 = &crtc_state->dp_m2_n2;
8270 } else if (m_n == M2_N2) {
8273 * M2_N2 registers are not supported. Hence m2_n2 divider value
8274 * needs to be programmed into M1_N1.
8276 dp_m_n = &crtc_state->dp_m2_n2;
8278 drm_err(&i915->drm, "Unsupported divider value\n");
8282 if (crtc_state->has_pch_encoder)
8283 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
8285 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
8288 static void vlv_compute_dpll(struct intel_crtc *crtc,
8289 struct intel_crtc_state *pipe_config)
8291 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
8292 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8293 if (crtc->pipe != PIPE_A)
8294 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8296 /* DPLL not used with DSI, but still need the rest set up */
8297 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8298 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
8299 DPLL_EXT_BUFFER_ENABLE_VLV;
8301 pipe_config->dpll_hw_state.dpll_md =
8302 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8305 static void chv_compute_dpll(struct intel_crtc *crtc,
8306 struct intel_crtc_state *pipe_config)
8308 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
8309 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8310 if (crtc->pipe != PIPE_A)
8311 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8313 /* DPLL not used with DSI, but still need the rest set up */
8314 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8315 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
8317 pipe_config->dpll_hw_state.dpll_md =
8318 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8321 static void vlv_prepare_pll(struct intel_crtc *crtc,
8322 const struct intel_crtc_state *pipe_config)
8324 struct drm_device *dev = crtc->base.dev;
8325 struct drm_i915_private *dev_priv = to_i915(dev);
8326 enum pipe pipe = crtc->pipe;
8328 u32 bestn, bestm1, bestm2, bestp1, bestp2;
8329 u32 coreclk, reg_val;
8332 intel_de_write(dev_priv, DPLL(pipe),
8333 pipe_config->dpll_hw_state.dpll & ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
8335 /* No need to actually set up the DPLL with DSI */
8336 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8339 vlv_dpio_get(dev_priv);
8341 bestn = pipe_config->dpll.n;
8342 bestm1 = pipe_config->dpll.m1;
8343 bestm2 = pipe_config->dpll.m2;
8344 bestp1 = pipe_config->dpll.p1;
8345 bestp2 = pipe_config->dpll.p2;
8347 /* See eDP HDMI DPIO driver vbios notes doc */
8349 /* PLL B needs special handling */
8351 vlv_pllb_recal_opamp(dev_priv, pipe);
8353 /* Set up Tx target for periodic Rcomp update */
8354 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
8356 /* Disable target IRef on PLL */
8357 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
8358 reg_val &= 0x00ffffff;
8359 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
8361 /* Disable fast lock */
8362 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
8364 /* Set idtafcrecal before PLL is enabled */
8365 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
8366 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
8367 mdiv |= ((bestn << DPIO_N_SHIFT));
8368 mdiv |= (1 << DPIO_K_SHIFT);
8371 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
8372 * but we don't support that).
8373 * Note: don't use the DAC post divider as it seems unstable.
8375 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
8376 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8378 mdiv |= DPIO_ENABLE_CALIBRATION;
8379 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8381 /* Set HBR and RBR LPF coefficients */
8382 if (pipe_config->port_clock == 162000 ||
8383 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
8384 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
8385 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8388 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8391 if (intel_crtc_has_dp_encoder(pipe_config)) {
8392 /* Use SSC source */
8394 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8397 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8399 } else { /* HDMI or VGA */
8400 /* Use bend source */
8402 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8405 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8409 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
8410 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
8411 if (intel_crtc_has_dp_encoder(pipe_config))
8412 coreclk |= 0x01000000;
8413 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
8415 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
8417 vlv_dpio_put(dev_priv);
8420 static void chv_prepare_pll(struct intel_crtc *crtc,
8421 const struct intel_crtc_state *pipe_config)
8423 struct drm_device *dev = crtc->base.dev;
8424 struct drm_i915_private *dev_priv = to_i915(dev);
8425 enum pipe pipe = crtc->pipe;
8426 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8427 u32 loopfilter, tribuf_calcntr;
8428 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
8432 /* Enable Refclk and SSC */
8433 intel_de_write(dev_priv, DPLL(pipe),
8434 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
8436 /* No need to actually set up the DPLL with DSI */
8437 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8440 bestn = pipe_config->dpll.n;
8441 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
8442 bestm1 = pipe_config->dpll.m1;
8443 bestm2 = pipe_config->dpll.m2 >> 22;
8444 bestp1 = pipe_config->dpll.p1;
8445 bestp2 = pipe_config->dpll.p2;
8446 vco = pipe_config->dpll.vco;
8450 vlv_dpio_get(dev_priv);
8452 /* p1 and p2 divider */
8453 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
8454 5 << DPIO_CHV_S1_DIV_SHIFT |
8455 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
8456 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
8457 1 << DPIO_CHV_K_DIV_SHIFT);
8459 /* Feedback post-divider - m2 */
8460 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
8462 /* Feedback refclk divider - n and m1 */
8463 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
8464 DPIO_CHV_M1_DIV_BY_2 |
8465 1 << DPIO_CHV_N_DIV_SHIFT);
8467 /* M2 fraction division */
8468 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
8470 /* M2 fraction division enable */
8471 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8472 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
8473 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
8475 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
8476 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
8478 /* Program digital lock detect threshold */
8479 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
8480 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
8481 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
8482 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
8484 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
8485 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
8488 if (vco == 5400000) {
8489 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
8490 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
8491 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
8492 tribuf_calcntr = 0x9;
8493 } else if (vco <= 6200000) {
8494 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
8495 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
8496 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8497 tribuf_calcntr = 0x9;
8498 } else if (vco <= 6480000) {
8499 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8500 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8501 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8502 tribuf_calcntr = 0x8;
8504 /* Not supported. Apply the same limits as in the max case */
8505 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8506 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8507 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8510 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
8512 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
8513 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
8514 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
8515 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
8518 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
8519 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
8522 vlv_dpio_put(dev_priv);
8526 * vlv_force_pll_on - forcibly enable just the PLL
8527 * @dev_priv: i915 private structure
8528 * @pipe: pipe PLL to enable
8529 * @dpll: PLL configuration
8531 * Enable the PLL for @pipe using the supplied @dpll config. To be used
8532 * in cases where we need the PLL enabled even when @pipe is not going to
8535 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
8536 const struct dpll *dpll)
8538 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
8539 struct intel_crtc_state *pipe_config;
8541 pipe_config = intel_crtc_state_alloc(crtc);
8545 pipe_config->cpu_transcoder = (enum transcoder)pipe;
8546 pipe_config->pixel_multiplier = 1;
8547 pipe_config->dpll = *dpll;
8549 if (IS_CHERRYVIEW(dev_priv)) {
8550 chv_compute_dpll(crtc, pipe_config);
8551 chv_prepare_pll(crtc, pipe_config);
8552 chv_enable_pll(crtc, pipe_config);
8554 vlv_compute_dpll(crtc, pipe_config);
8555 vlv_prepare_pll(crtc, pipe_config);
8556 vlv_enable_pll(crtc, pipe_config);
8565 * vlv_force_pll_off - forcibly disable just the PLL
8566 * @dev_priv: i915 private structure
8567 * @pipe: pipe PLL to disable
8569 * Disable the PLL for @pipe. To be used in cases where we need
8570 * the PLL enabled even when @pipe is not going to be enabled.
8572 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
8574 if (IS_CHERRYVIEW(dev_priv))
8575 chv_disable_pll(dev_priv, pipe);
8577 vlv_disable_pll(dev_priv, pipe);
8580 static void i9xx_compute_dpll(struct intel_crtc *crtc,
8581 struct intel_crtc_state *crtc_state,
8582 struct dpll *reduced_clock)
8584 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8586 struct dpll *clock = &crtc_state->dpll;
8588 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8590 dpll = DPLL_VGA_MODE_DIS;
8592 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8593 dpll |= DPLLB_MODE_LVDS;
8595 dpll |= DPLLB_MODE_DAC_SERIAL;
8597 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8598 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8599 dpll |= (crtc_state->pixel_multiplier - 1)
8600 << SDVO_MULTIPLIER_SHIFT_HIRES;
8603 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8604 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8605 dpll |= DPLL_SDVO_HIGH_SPEED;
8607 if (intel_crtc_has_dp_encoder(crtc_state))
8608 dpll |= DPLL_SDVO_HIGH_SPEED;
8610 /* compute bitmask from p1 value */
8611 if (IS_PINEVIEW(dev_priv))
8612 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8614 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8615 if (IS_G4X(dev_priv) && reduced_clock)
8616 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8618 switch (clock->p2) {
8620 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8623 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8626 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8629 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8632 if (INTEL_GEN(dev_priv) >= 4)
8633 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8635 if (crtc_state->sdvo_tv_clock)
8636 dpll |= PLL_REF_INPUT_TVCLKINBC;
8637 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8638 intel_panel_use_ssc(dev_priv))
8639 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8641 dpll |= PLL_REF_INPUT_DREFCLK;
8643 dpll |= DPLL_VCO_ENABLE;
8644 crtc_state->dpll_hw_state.dpll = dpll;
8646 if (INTEL_GEN(dev_priv) >= 4) {
8647 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8648 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8649 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8653 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8654 struct intel_crtc_state *crtc_state,
8655 struct dpll *reduced_clock)
8657 struct drm_device *dev = crtc->base.dev;
8658 struct drm_i915_private *dev_priv = to_i915(dev);
8660 struct dpll *clock = &crtc_state->dpll;
8662 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8664 dpll = DPLL_VGA_MODE_DIS;
8666 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8667 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8670 dpll |= PLL_P1_DIVIDE_BY_TWO;
8672 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8674 dpll |= PLL_P2_DIVIDE_BY_4;
8679 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8680 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8681 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8682 * Enable) must be set to “1” in both the DPLL A Control Register
8683 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8685 * For simplicity We simply keep both bits always enabled in
8686 * both DPLLS. The spec says we should disable the DVO 2X clock
8687 * when not needed, but this seems to work fine in practice.
8689 if (IS_I830(dev_priv) ||
8690 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8691 dpll |= DPLL_DVO_2X_MODE;
8693 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8694 intel_panel_use_ssc(dev_priv))
8695 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8697 dpll |= PLL_REF_INPUT_DREFCLK;
8699 dpll |= DPLL_VCO_ENABLE;
8700 crtc_state->dpll_hw_state.dpll = dpll;
8703 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
8705 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8706 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8707 enum pipe pipe = crtc->pipe;
8708 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8709 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
8710 u32 crtc_vtotal, crtc_vblank_end;
8713 /* We need to be careful not to changed the adjusted mode, for otherwise
8714 * the hw state checker will get angry at the mismatch. */
8715 crtc_vtotal = adjusted_mode->crtc_vtotal;
8716 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8718 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8719 /* the chip adds 2 halflines automatically */
8721 crtc_vblank_end -= 1;
8723 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8724 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8726 vsyncshift = adjusted_mode->crtc_hsync_start -
8727 adjusted_mode->crtc_htotal / 2;
8729 vsyncshift += adjusted_mode->crtc_htotal;
8732 if (INTEL_GEN(dev_priv) > 3)
8733 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder),
8736 intel_de_write(dev_priv, HTOTAL(cpu_transcoder),
8737 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
8738 intel_de_write(dev_priv, HBLANK(cpu_transcoder),
8739 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
8740 intel_de_write(dev_priv, HSYNC(cpu_transcoder),
8741 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
8743 intel_de_write(dev_priv, VTOTAL(cpu_transcoder),
8744 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16));
8745 intel_de_write(dev_priv, VBLANK(cpu_transcoder),
8746 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16));
8747 intel_de_write(dev_priv, VSYNC(cpu_transcoder),
8748 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
8750 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8751 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8752 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8754 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8755 (pipe == PIPE_B || pipe == PIPE_C))
8756 intel_de_write(dev_priv, VTOTAL(pipe),
8757 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
8761 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8763 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8764 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8765 enum pipe pipe = crtc->pipe;
8767 /* pipesrc controls the size that is scaled from, which should
8768 * always be the user's requested size.
8770 intel_de_write(dev_priv, PIPESRC(pipe),
8771 ((crtc_state->pipe_src_w - 1) << 16) | (crtc_state->pipe_src_h - 1));
8774 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
8776 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
8777 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8779 if (IS_GEN(dev_priv, 2))
8782 if (INTEL_GEN(dev_priv) >= 9 ||
8783 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
8784 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
8786 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
8789 static void intel_get_pipe_timings(struct intel_crtc *crtc,
8790 struct intel_crtc_state *pipe_config)
8792 struct drm_device *dev = crtc->base.dev;
8793 struct drm_i915_private *dev_priv = to_i915(dev);
8794 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8797 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder));
8798 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8799 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8801 if (!transcoder_is_dsi(cpu_transcoder)) {
8802 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder));
8803 pipe_config->hw.adjusted_mode.crtc_hblank_start =
8805 pipe_config->hw.adjusted_mode.crtc_hblank_end =
8806 ((tmp >> 16) & 0xffff) + 1;
8808 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder));
8809 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8810 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8812 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder));
8813 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8814 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8816 if (!transcoder_is_dsi(cpu_transcoder)) {
8817 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder));
8818 pipe_config->hw.adjusted_mode.crtc_vblank_start =
8820 pipe_config->hw.adjusted_mode.crtc_vblank_end =
8821 ((tmp >> 16) & 0xffff) + 1;
8823 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder));
8824 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8825 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8827 if (intel_pipe_is_interlaced(pipe_config)) {
8828 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8829 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
8830 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
8834 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8835 struct intel_crtc_state *pipe_config)
8837 struct drm_device *dev = crtc->base.dev;
8838 struct drm_i915_private *dev_priv = to_i915(dev);
8841 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
8842 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8843 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8845 pipe_config->hw.mode.vdisplay = pipe_config->pipe_src_h;
8846 pipe_config->hw.mode.hdisplay = pipe_config->pipe_src_w;
8849 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
8850 struct intel_crtc_state *pipe_config)
8852 mode->hdisplay = pipe_config->hw.adjusted_mode.crtc_hdisplay;
8853 mode->htotal = pipe_config->hw.adjusted_mode.crtc_htotal;
8854 mode->hsync_start = pipe_config->hw.adjusted_mode.crtc_hsync_start;
8855 mode->hsync_end = pipe_config->hw.adjusted_mode.crtc_hsync_end;
8857 mode->vdisplay = pipe_config->hw.adjusted_mode.crtc_vdisplay;
8858 mode->vtotal = pipe_config->hw.adjusted_mode.crtc_vtotal;
8859 mode->vsync_start = pipe_config->hw.adjusted_mode.crtc_vsync_start;
8860 mode->vsync_end = pipe_config->hw.adjusted_mode.crtc_vsync_end;
8862 mode->flags = pipe_config->hw.adjusted_mode.flags;
8863 mode->type = DRM_MODE_TYPE_DRIVER;
8865 mode->clock = pipe_config->hw.adjusted_mode.crtc_clock;
8867 mode->hsync = drm_mode_hsync(mode);
8868 mode->vrefresh = drm_mode_vrefresh(mode);
8869 drm_mode_set_name(mode);
8872 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8874 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8875 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8880 /* we keep both pipes enabled on 830 */
8881 if (IS_I830(dev_priv))
8882 pipeconf |= intel_de_read(dev_priv, PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8884 if (crtc_state->double_wide)
8885 pipeconf |= PIPECONF_DOUBLE_WIDE;
8887 /* only g4x and later have fancy bpc/dither controls */
8888 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8889 IS_CHERRYVIEW(dev_priv)) {
8890 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8891 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8892 pipeconf |= PIPECONF_DITHER_EN |
8893 PIPECONF_DITHER_TYPE_SP;
8895 switch (crtc_state->pipe_bpp) {
8897 pipeconf |= PIPECONF_6BPC;
8900 pipeconf |= PIPECONF_8BPC;
8903 pipeconf |= PIPECONF_10BPC;
8906 /* Case prevented by intel_choose_pipe_bpp_dither. */
8911 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8912 if (INTEL_GEN(dev_priv) < 4 ||
8913 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8914 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8916 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8918 pipeconf |= PIPECONF_PROGRESSIVE;
8921 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8922 crtc_state->limited_color_range)
8923 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8925 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8927 pipeconf |= PIPECONF_FRAME_START_DELAY(0);
8929 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf);
8930 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe));
8933 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8934 struct intel_crtc_state *crtc_state)
8936 struct drm_device *dev = crtc->base.dev;
8937 struct drm_i915_private *dev_priv = to_i915(dev);
8938 const struct intel_limit *limit;
8941 memset(&crtc_state->dpll_hw_state, 0,
8942 sizeof(crtc_state->dpll_hw_state));
8944 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8945 if (intel_panel_use_ssc(dev_priv)) {
8946 refclk = dev_priv->vbt.lvds_ssc_freq;
8947 drm_dbg_kms(&dev_priv->drm,
8948 "using SSC reference clock of %d kHz\n",
8952 limit = &intel_limits_i8xx_lvds;
8953 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8954 limit = &intel_limits_i8xx_dvo;
8956 limit = &intel_limits_i8xx_dac;
8959 if (!crtc_state->clock_set &&
8960 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8961 refclk, NULL, &crtc_state->dpll)) {
8962 drm_err(&dev_priv->drm,
8963 "Couldn't find PLL settings for mode!\n");
8967 i8xx_compute_dpll(crtc, crtc_state, NULL);
8972 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
8973 struct intel_crtc_state *crtc_state)
8975 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8976 const struct intel_limit *limit;
8979 memset(&crtc_state->dpll_hw_state, 0,
8980 sizeof(crtc_state->dpll_hw_state));
8982 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8983 if (intel_panel_use_ssc(dev_priv)) {
8984 refclk = dev_priv->vbt.lvds_ssc_freq;
8985 drm_dbg_kms(&dev_priv->drm,
8986 "using SSC reference clock of %d kHz\n",
8990 if (intel_is_dual_link_lvds(dev_priv))
8991 limit = &intel_limits_g4x_dual_channel_lvds;
8993 limit = &intel_limits_g4x_single_channel_lvds;
8994 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
8995 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
8996 limit = &intel_limits_g4x_hdmi;
8997 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
8998 limit = &intel_limits_g4x_sdvo;
9000 /* The option is for other outputs */
9001 limit = &intel_limits_i9xx_sdvo;
9004 if (!crtc_state->clock_set &&
9005 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9006 refclk, NULL, &crtc_state->dpll)) {
9007 drm_err(&dev_priv->drm,
9008 "Couldn't find PLL settings for mode!\n");
9012 i9xx_compute_dpll(crtc, crtc_state, NULL);
9017 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
9018 struct intel_crtc_state *crtc_state)
9020 struct drm_device *dev = crtc->base.dev;
9021 struct drm_i915_private *dev_priv = to_i915(dev);
9022 const struct intel_limit *limit;
9025 memset(&crtc_state->dpll_hw_state, 0,
9026 sizeof(crtc_state->dpll_hw_state));
9028 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9029 if (intel_panel_use_ssc(dev_priv)) {
9030 refclk = dev_priv->vbt.lvds_ssc_freq;
9031 drm_dbg_kms(&dev_priv->drm,
9032 "using SSC reference clock of %d kHz\n",
9036 limit = &pnv_limits_lvds;
9038 limit = &pnv_limits_sdvo;
9041 if (!crtc_state->clock_set &&
9042 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9043 refclk, NULL, &crtc_state->dpll)) {
9044 drm_err(&dev_priv->drm,
9045 "Couldn't find PLL settings for mode!\n");
9049 i9xx_compute_dpll(crtc, crtc_state, NULL);
9054 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
9055 struct intel_crtc_state *crtc_state)
9057 struct drm_device *dev = crtc->base.dev;
9058 struct drm_i915_private *dev_priv = to_i915(dev);
9059 const struct intel_limit *limit;
9062 memset(&crtc_state->dpll_hw_state, 0,
9063 sizeof(crtc_state->dpll_hw_state));
9065 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9066 if (intel_panel_use_ssc(dev_priv)) {
9067 refclk = dev_priv->vbt.lvds_ssc_freq;
9068 drm_dbg_kms(&dev_priv->drm,
9069 "using SSC reference clock of %d kHz\n",
9073 limit = &intel_limits_i9xx_lvds;
9075 limit = &intel_limits_i9xx_sdvo;
9078 if (!crtc_state->clock_set &&
9079 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9080 refclk, NULL, &crtc_state->dpll)) {
9081 drm_err(&dev_priv->drm,
9082 "Couldn't find PLL settings for mode!\n");
9086 i9xx_compute_dpll(crtc, crtc_state, NULL);
9091 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
9092 struct intel_crtc_state *crtc_state)
9094 int refclk = 100000;
9095 const struct intel_limit *limit = &intel_limits_chv;
9096 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
9098 memset(&crtc_state->dpll_hw_state, 0,
9099 sizeof(crtc_state->dpll_hw_state));
9101 if (!crtc_state->clock_set &&
9102 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9103 refclk, NULL, &crtc_state->dpll)) {
9104 drm_err(&i915->drm, "Couldn't find PLL settings for mode!\n");
9108 chv_compute_dpll(crtc, crtc_state);
9113 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
9114 struct intel_crtc_state *crtc_state)
9116 int refclk = 100000;
9117 const struct intel_limit *limit = &intel_limits_vlv;
9118 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
9120 memset(&crtc_state->dpll_hw_state, 0,
9121 sizeof(crtc_state->dpll_hw_state));
9123 if (!crtc_state->clock_set &&
9124 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9125 refclk, NULL, &crtc_state->dpll)) {
9126 drm_err(&i915->drm, "Couldn't find PLL settings for mode!\n");
9130 vlv_compute_dpll(crtc, crtc_state);
9135 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
9137 if (IS_I830(dev_priv))
9140 return INTEL_GEN(dev_priv) >= 4 ||
9141 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
9144 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
9145 struct intel_crtc_state *pipe_config)
9147 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9150 if (!i9xx_has_pfit(dev_priv))
9153 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
9154 if (!(tmp & PFIT_ENABLE))
9157 /* Check whether the pfit is attached to our pipe. */
9158 if (INTEL_GEN(dev_priv) < 4) {
9159 if (crtc->pipe != PIPE_B)
9162 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
9166 pipe_config->gmch_pfit.control = tmp;
9167 pipe_config->gmch_pfit.pgm_ratios = intel_de_read(dev_priv,
9171 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
9172 struct intel_crtc_state *pipe_config)
9174 struct drm_device *dev = crtc->base.dev;
9175 struct drm_i915_private *dev_priv = to_i915(dev);
9176 enum pipe pipe = crtc->pipe;
9179 int refclk = 100000;
9181 /* In case of DSI, DPLL will not be used */
9182 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
9185 vlv_dpio_get(dev_priv);
9186 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
9187 vlv_dpio_put(dev_priv);
9189 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
9190 clock.m2 = mdiv & DPIO_M2DIV_MASK;
9191 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
9192 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
9193 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
9195 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
9199 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
9200 struct intel_initial_plane_config *plane_config)
9202 struct drm_device *dev = crtc->base.dev;
9203 struct drm_i915_private *dev_priv = to_i915(dev);
9204 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9205 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
9207 u32 val, base, offset;
9208 int fourcc, pixel_format;
9209 unsigned int aligned_height;
9210 struct drm_framebuffer *fb;
9211 struct intel_framebuffer *intel_fb;
9213 if (!plane->get_hw_state(plane, &pipe))
9216 drm_WARN_ON(dev, pipe != crtc->pipe);
9218 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9220 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
9224 fb = &intel_fb->base;
9228 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
9230 if (INTEL_GEN(dev_priv) >= 4) {
9231 if (val & DISPPLANE_TILED) {
9232 plane_config->tiling = I915_TILING_X;
9233 fb->modifier = I915_FORMAT_MOD_X_TILED;
9236 if (val & DISPPLANE_ROTATE_180)
9237 plane_config->rotation = DRM_MODE_ROTATE_180;
9240 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
9241 val & DISPPLANE_MIRROR)
9242 plane_config->rotation |= DRM_MODE_REFLECT_X;
9244 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
9245 fourcc = i9xx_format_to_fourcc(pixel_format);
9246 fb->format = drm_format_info(fourcc);
9248 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
9249 offset = intel_de_read(dev_priv, DSPOFFSET(i9xx_plane));
9250 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
9251 } else if (INTEL_GEN(dev_priv) >= 4) {
9252 if (plane_config->tiling)
9253 offset = intel_de_read(dev_priv,
9254 DSPTILEOFF(i9xx_plane));
9256 offset = intel_de_read(dev_priv,
9257 DSPLINOFF(i9xx_plane));
9258 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
9260 base = intel_de_read(dev_priv, DSPADDR(i9xx_plane));
9262 plane_config->base = base;
9264 val = intel_de_read(dev_priv, PIPESRC(pipe));
9265 fb->width = ((val >> 16) & 0xfff) + 1;
9266 fb->height = ((val >> 0) & 0xfff) + 1;
9268 val = intel_de_read(dev_priv, DSPSTRIDE(i9xx_plane));
9269 fb->pitches[0] = val & 0xffffffc0;
9271 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9273 plane_config->size = fb->pitches[0] * aligned_height;
9275 drm_dbg_kms(&dev_priv->drm,
9276 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9277 crtc->base.name, plane->base.name, fb->width, fb->height,
9278 fb->format->cpp[0] * 8, base, fb->pitches[0],
9279 plane_config->size);
9281 plane_config->fb = intel_fb;
9284 static void chv_crtc_clock_get(struct intel_crtc *crtc,
9285 struct intel_crtc_state *pipe_config)
9287 struct drm_device *dev = crtc->base.dev;
9288 struct drm_i915_private *dev_priv = to_i915(dev);
9289 enum pipe pipe = crtc->pipe;
9290 enum dpio_channel port = vlv_pipe_to_channel(pipe);
9292 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
9293 int refclk = 100000;
9295 /* In case of DSI, DPLL will not be used */
9296 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
9299 vlv_dpio_get(dev_priv);
9300 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
9301 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
9302 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
9303 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
9304 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
9305 vlv_dpio_put(dev_priv);
9307 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
9308 clock.m2 = (pll_dw0 & 0xff) << 22;
9309 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
9310 clock.m2 |= pll_dw2 & 0x3fffff;
9311 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
9312 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
9313 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
9315 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
9318 static enum intel_output_format
9319 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
9321 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9324 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
9326 if (tmp & PIPEMISC_YUV420_ENABLE) {
9327 /* We support 4:2:0 in full blend mode only */
9328 drm_WARN_ON(&dev_priv->drm,
9329 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
9331 return INTEL_OUTPUT_FORMAT_YCBCR420;
9332 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
9333 return INTEL_OUTPUT_FORMAT_YCBCR444;
9335 return INTEL_OUTPUT_FORMAT_RGB;
9339 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
9341 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9342 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9343 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9344 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
9347 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
9349 if (tmp & DISPPLANE_GAMMA_ENABLE)
9350 crtc_state->gamma_enable = true;
9352 if (!HAS_GMCH(dev_priv) &&
9353 tmp & DISPPLANE_PIPE_CSC_ENABLE)
9354 crtc_state->csc_enable = true;
9357 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
9358 struct intel_crtc_state *pipe_config)
9360 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9361 enum intel_display_power_domain power_domain;
9362 intel_wakeref_t wakeref;
9366 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9367 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9371 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9372 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9373 pipe_config->shared_dpll = NULL;
9377 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
9378 if (!(tmp & PIPECONF_ENABLE))
9381 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
9382 IS_CHERRYVIEW(dev_priv)) {
9383 switch (tmp & PIPECONF_BPC_MASK) {
9385 pipe_config->pipe_bpp = 18;
9388 pipe_config->pipe_bpp = 24;
9390 case PIPECONF_10BPC:
9391 pipe_config->pipe_bpp = 30;
9398 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
9399 (tmp & PIPECONF_COLOR_RANGE_SELECT))
9400 pipe_config->limited_color_range = true;
9402 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
9403 PIPECONF_GAMMA_MODE_SHIFT;
9405 if (IS_CHERRYVIEW(dev_priv))
9406 pipe_config->cgm_mode = intel_de_read(dev_priv,
9407 CGM_PIPE_MODE(crtc->pipe));
9409 i9xx_get_pipe_color_config(pipe_config);
9410 intel_color_get_config(pipe_config);
9412 if (INTEL_GEN(dev_priv) < 4)
9413 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
9415 intel_get_pipe_timings(crtc, pipe_config);
9416 intel_get_pipe_src_size(crtc, pipe_config);
9418 i9xx_get_pfit_config(crtc, pipe_config);
9420 if (INTEL_GEN(dev_priv) >= 4) {
9421 /* No way to read it out on pipes B and C */
9422 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
9423 tmp = dev_priv->chv_dpll_md[crtc->pipe];
9425 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
9426 pipe_config->pixel_multiplier =
9427 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
9428 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
9429 pipe_config->dpll_hw_state.dpll_md = tmp;
9430 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
9431 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
9432 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
9433 pipe_config->pixel_multiplier =
9434 ((tmp & SDVO_MULTIPLIER_MASK)
9435 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
9437 /* Note that on i915G/GM the pixel multiplier is in the sdvo
9438 * port and will be fixed up in the encoder->get_config
9440 pipe_config->pixel_multiplier = 1;
9442 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
9444 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
9445 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
9447 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
9450 /* Mask out read-only status bits. */
9451 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
9452 DPLL_PORTC_READY_MASK |
9453 DPLL_PORTB_READY_MASK);
9456 if (IS_CHERRYVIEW(dev_priv))
9457 chv_crtc_clock_get(crtc, pipe_config);
9458 else if (IS_VALLEYVIEW(dev_priv))
9459 vlv_crtc_clock_get(crtc, pipe_config);
9461 i9xx_crtc_clock_get(crtc, pipe_config);
9464 * Normally the dotclock is filled in by the encoder .get_config()
9465 * but in case the pipe is enabled w/o any ports we need a sane
9468 pipe_config->hw.adjusted_mode.crtc_clock =
9469 pipe_config->port_clock / pipe_config->pixel_multiplier;
9474 intel_display_power_put(dev_priv, power_domain, wakeref);
9479 static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv)
9481 struct intel_encoder *encoder;
9484 bool has_lvds = false;
9485 bool has_cpu_edp = false;
9486 bool has_panel = false;
9487 bool has_ck505 = false;
9488 bool can_ssc = false;
9489 bool using_ssc_source = false;
9491 /* We need to take the global config into account */
9492 for_each_intel_encoder(&dev_priv->drm, encoder) {
9493 switch (encoder->type) {
9494 case INTEL_OUTPUT_LVDS:
9498 case INTEL_OUTPUT_EDP:
9500 if (encoder->port == PORT_A)
9508 if (HAS_PCH_IBX(dev_priv)) {
9509 has_ck505 = dev_priv->vbt.display_clock_mode;
9510 can_ssc = has_ck505;
9516 /* Check if any DPLLs are using the SSC source */
9517 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++) {
9518 u32 temp = intel_de_read(dev_priv, PCH_DPLL(i));
9520 if (!(temp & DPLL_VCO_ENABLE))
9523 if ((temp & PLL_REF_INPUT_MASK) ==
9524 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
9525 using_ssc_source = true;
9530 drm_dbg_kms(&dev_priv->drm,
9531 "has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
9532 has_panel, has_lvds, has_ck505, using_ssc_source);
9534 /* Ironlake: try to setup display ref clock before DPLL
9535 * enabling. This is only under driver's control after
9536 * PCH B stepping, previous chipset stepping should be
9537 * ignoring this setting.
9539 val = intel_de_read(dev_priv, PCH_DREF_CONTROL);
9541 /* As we must carefully and slowly disable/enable each source in turn,
9542 * compute the final state we want first and check if we need to
9543 * make any changes at all.
9546 final &= ~DREF_NONSPREAD_SOURCE_MASK;
9548 final |= DREF_NONSPREAD_CK505_ENABLE;
9550 final |= DREF_NONSPREAD_SOURCE_ENABLE;
9552 final &= ~DREF_SSC_SOURCE_MASK;
9553 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9554 final &= ~DREF_SSC1_ENABLE;
9557 final |= DREF_SSC_SOURCE_ENABLE;
9559 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9560 final |= DREF_SSC1_ENABLE;
9563 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9564 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9566 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9568 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9569 } else if (using_ssc_source) {
9570 final |= DREF_SSC_SOURCE_ENABLE;
9571 final |= DREF_SSC1_ENABLE;
9577 /* Always enable nonspread source */
9578 val &= ~DREF_NONSPREAD_SOURCE_MASK;
9581 val |= DREF_NONSPREAD_CK505_ENABLE;
9583 val |= DREF_NONSPREAD_SOURCE_ENABLE;
9586 val &= ~DREF_SSC_SOURCE_MASK;
9587 val |= DREF_SSC_SOURCE_ENABLE;
9589 /* SSC must be turned on before enabling the CPU output */
9590 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9591 drm_dbg_kms(&dev_priv->drm, "Using SSC on panel\n");
9592 val |= DREF_SSC1_ENABLE;
9594 val &= ~DREF_SSC1_ENABLE;
9596 /* Get SSC going before enabling the outputs */
9597 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9598 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9601 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9603 /* Enable CPU source on CPU attached eDP */
9605 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9606 drm_dbg_kms(&dev_priv->drm,
9607 "Using SSC on eDP\n");
9608 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9610 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9612 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9614 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9615 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9618 drm_dbg_kms(&dev_priv->drm, "Disabling CPU source output\n");
9620 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9622 /* Turn off CPU output */
9623 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9625 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9626 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9629 if (!using_ssc_source) {
9630 drm_dbg_kms(&dev_priv->drm, "Disabling SSC source\n");
9632 /* Turn off the SSC source */
9633 val &= ~DREF_SSC_SOURCE_MASK;
9634 val |= DREF_SSC_SOURCE_DISABLE;
9637 val &= ~DREF_SSC1_ENABLE;
9639 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9640 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9645 BUG_ON(val != final);
9648 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9652 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
9653 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9654 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
9656 if (wait_for_us(intel_de_read(dev_priv, SOUTH_CHICKEN2) &
9657 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9658 drm_err(&dev_priv->drm, "FDI mPHY reset assert timeout\n");
9660 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
9661 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9662 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
9664 if (wait_for_us((intel_de_read(dev_priv, SOUTH_CHICKEN2) &
9665 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9666 drm_err(&dev_priv->drm, "FDI mPHY reset de-assert timeout\n");
9669 /* WaMPhyProgramming:hsw */
9670 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9674 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9675 tmp &= ~(0xFF << 24);
9676 tmp |= (0x12 << 24);
9677 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9679 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9681 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9683 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9685 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9687 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9688 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9689 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9691 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9692 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9693 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9695 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9698 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9700 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9703 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9705 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9708 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9710 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9713 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9715 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9716 tmp &= ~(0xFF << 16);
9717 tmp |= (0x1C << 16);
9718 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9720 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9721 tmp &= ~(0xFF << 16);
9722 tmp |= (0x1C << 16);
9723 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9725 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9727 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9729 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9731 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9733 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9734 tmp &= ~(0xF << 28);
9736 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9738 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9739 tmp &= ~(0xF << 28);
9741 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9744 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9745 * Programming" based on the parameters passed:
9746 * - Sequence to enable CLKOUT_DP
9747 * - Sequence to enable CLKOUT_DP without spread
9748 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9750 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9751 bool with_spread, bool with_fdi)
9755 if (drm_WARN(&dev_priv->drm, with_fdi && !with_spread,
9756 "FDI requires downspread\n"))
9758 if (drm_WARN(&dev_priv->drm, HAS_PCH_LPT_LP(dev_priv) &&
9759 with_fdi, "LP PCH doesn't have FDI\n"))
9762 mutex_lock(&dev_priv->sb_lock);
9764 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9765 tmp &= ~SBI_SSCCTL_DISABLE;
9766 tmp |= SBI_SSCCTL_PATHALT;
9767 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9772 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9773 tmp &= ~SBI_SSCCTL_PATHALT;
9774 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9777 lpt_reset_fdi_mphy(dev_priv);
9778 lpt_program_fdi_mphy(dev_priv);
9782 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9783 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9784 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9785 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9787 mutex_unlock(&dev_priv->sb_lock);
9790 /* Sequence to disable CLKOUT_DP */
9791 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9795 mutex_lock(&dev_priv->sb_lock);
9797 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9798 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9799 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9800 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9802 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9803 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9804 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9805 tmp |= SBI_SSCCTL_PATHALT;
9806 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9809 tmp |= SBI_SSCCTL_DISABLE;
9810 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9813 mutex_unlock(&dev_priv->sb_lock);
9816 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9818 static const u16 sscdivintphase[] = {
9819 [BEND_IDX( 50)] = 0x3B23,
9820 [BEND_IDX( 45)] = 0x3B23,
9821 [BEND_IDX( 40)] = 0x3C23,
9822 [BEND_IDX( 35)] = 0x3C23,
9823 [BEND_IDX( 30)] = 0x3D23,
9824 [BEND_IDX( 25)] = 0x3D23,
9825 [BEND_IDX( 20)] = 0x3E23,
9826 [BEND_IDX( 15)] = 0x3E23,
9827 [BEND_IDX( 10)] = 0x3F23,
9828 [BEND_IDX( 5)] = 0x3F23,
9829 [BEND_IDX( 0)] = 0x0025,
9830 [BEND_IDX( -5)] = 0x0025,
9831 [BEND_IDX(-10)] = 0x0125,
9832 [BEND_IDX(-15)] = 0x0125,
9833 [BEND_IDX(-20)] = 0x0225,
9834 [BEND_IDX(-25)] = 0x0225,
9835 [BEND_IDX(-30)] = 0x0325,
9836 [BEND_IDX(-35)] = 0x0325,
9837 [BEND_IDX(-40)] = 0x0425,
9838 [BEND_IDX(-45)] = 0x0425,
9839 [BEND_IDX(-50)] = 0x0525,
9844 * steps -50 to 50 inclusive, in steps of 5
9845 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9846 * change in clock period = -(steps / 10) * 5.787 ps
9848 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9851 int idx = BEND_IDX(steps);
9853 if (drm_WARN_ON(&dev_priv->drm, steps % 5 != 0))
9856 if (drm_WARN_ON(&dev_priv->drm, idx >= ARRAY_SIZE(sscdivintphase)))
9859 mutex_lock(&dev_priv->sb_lock);
9861 if (steps % 10 != 0)
9865 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9867 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9869 tmp |= sscdivintphase[idx];
9870 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9872 mutex_unlock(&dev_priv->sb_lock);
9877 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9879 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
9880 u32 ctl = intel_de_read(dev_priv, SPLL_CTL);
9882 if ((ctl & SPLL_PLL_ENABLE) == 0)
9885 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9886 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9889 if (IS_BROADWELL(dev_priv) &&
9890 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9896 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9897 enum intel_dpll_id id)
9899 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
9900 u32 ctl = intel_de_read(dev_priv, WRPLL_CTL(id));
9902 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9905 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9908 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9909 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9910 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9916 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9918 struct intel_encoder *encoder;
9919 bool has_fdi = false;
9921 for_each_intel_encoder(&dev_priv->drm, encoder) {
9922 switch (encoder->type) {
9923 case INTEL_OUTPUT_ANALOG:
9932 * The BIOS may have decided to use the PCH SSC
9933 * reference so we must not disable it until the
9934 * relevant PLLs have stopped relying on it. We'll
9935 * just leave the PCH SSC reference enabled in case
9936 * any active PLL is using it. It will get disabled
9937 * after runtime suspend if we don't have FDI.
9939 * TODO: Move the whole reference clock handling
9940 * to the modeset sequence proper so that we can
9941 * actually enable/disable/reconfigure these things
9942 * safely. To do that we need to introduce a real
9943 * clock hierarchy. That would also allow us to do
9944 * clock bending finally.
9946 dev_priv->pch_ssc_use = 0;
9948 if (spll_uses_pch_ssc(dev_priv)) {
9949 drm_dbg_kms(&dev_priv->drm, "SPLL using PCH SSC\n");
9950 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
9953 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9954 drm_dbg_kms(&dev_priv->drm, "WRPLL1 using PCH SSC\n");
9955 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
9958 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9959 drm_dbg_kms(&dev_priv->drm, "WRPLL2 using PCH SSC\n");
9960 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
9963 if (dev_priv->pch_ssc_use)
9967 lpt_bend_clkout_dp(dev_priv, 0);
9968 lpt_enable_clkout_dp(dev_priv, true, true);
9970 lpt_disable_clkout_dp(dev_priv);
9975 * Initialize reference clocks when the driver loads
9977 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
9979 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
9980 ilk_init_pch_refclk(dev_priv);
9981 else if (HAS_PCH_LPT(dev_priv))
9982 lpt_init_pch_refclk(dev_priv);
9985 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
9987 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9988 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9989 enum pipe pipe = crtc->pipe;
9994 switch (crtc_state->pipe_bpp) {
9996 val |= PIPECONF_6BPC;
9999 val |= PIPECONF_8BPC;
10002 val |= PIPECONF_10BPC;
10005 val |= PIPECONF_12BPC;
10008 /* Case prevented by intel_choose_pipe_bpp_dither. */
10012 if (crtc_state->dither)
10013 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
10015 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
10016 val |= PIPECONF_INTERLACED_ILK;
10018 val |= PIPECONF_PROGRESSIVE;
10021 * This would end up with an odd purple hue over
10022 * the entire display. Make sure we don't do it.
10024 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
10025 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
10027 if (crtc_state->limited_color_range)
10028 val |= PIPECONF_COLOR_RANGE_SELECT;
10030 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
10031 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
10033 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
10035 val |= PIPECONF_FRAME_START_DELAY(0);
10037 intel_de_write(dev_priv, PIPECONF(pipe), val);
10038 intel_de_posting_read(dev_priv, PIPECONF(pipe));
10041 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state)
10043 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10044 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10045 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
10048 if (IS_HASWELL(dev_priv) && crtc_state->dither)
10049 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
10051 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
10052 val |= PIPECONF_INTERLACED_ILK;
10054 val |= PIPECONF_PROGRESSIVE;
10056 if (IS_HASWELL(dev_priv) &&
10057 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
10058 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
10060 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val);
10061 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder));
10064 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
10066 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10067 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10070 switch (crtc_state->pipe_bpp) {
10072 val |= PIPEMISC_DITHER_6_BPC;
10075 val |= PIPEMISC_DITHER_8_BPC;
10078 val |= PIPEMISC_DITHER_10_BPC;
10081 val |= PIPEMISC_DITHER_12_BPC;
10084 MISSING_CASE(crtc_state->pipe_bpp);
10088 if (crtc_state->dither)
10089 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
10091 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
10092 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
10093 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
10095 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
10096 val |= PIPEMISC_YUV420_ENABLE |
10097 PIPEMISC_YUV420_MODE_FULL_BLEND;
10099 if (INTEL_GEN(dev_priv) >= 11 &&
10100 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
10101 BIT(PLANE_CURSOR))) == 0)
10102 val |= PIPEMISC_HDR_MODE_PRECISION;
10104 if (INTEL_GEN(dev_priv) >= 12)
10105 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC;
10107 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val);
10110 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
10112 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10115 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
10117 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
10118 case PIPEMISC_DITHER_6_BPC:
10120 case PIPEMISC_DITHER_8_BPC:
10122 case PIPEMISC_DITHER_10_BPC:
10124 case PIPEMISC_DITHER_12_BPC:
10132 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
10135 * Account for spread spectrum to avoid
10136 * oversubscribing the link. Max center spread
10137 * is 2.5%; use 5% for safety's sake.
10139 u32 bps = target_clock * bpp * 21 / 20;
10140 return DIV_ROUND_UP(bps, link_bw * 8);
10143 static bool ilk_needs_fb_cb_tune(struct dpll *dpll, int factor)
10145 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
10148 static void ilk_compute_dpll(struct intel_crtc *crtc,
10149 struct intel_crtc_state *crtc_state,
10150 struct dpll *reduced_clock)
10152 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10156 /* Enable autotuning of the PLL clock (if permissible) */
10158 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
10159 if ((intel_panel_use_ssc(dev_priv) &&
10160 dev_priv->vbt.lvds_ssc_freq == 100000) ||
10161 (HAS_PCH_IBX(dev_priv) &&
10162 intel_is_dual_link_lvds(dev_priv)))
10164 } else if (crtc_state->sdvo_tv_clock) {
10168 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
10170 if (ilk_needs_fb_cb_tune(&crtc_state->dpll, factor))
10173 if (reduced_clock) {
10174 fp2 = i9xx_dpll_compute_fp(reduced_clock);
10176 if (reduced_clock->m < factor * reduced_clock->n)
10184 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
10185 dpll |= DPLLB_MODE_LVDS;
10187 dpll |= DPLLB_MODE_DAC_SERIAL;
10189 dpll |= (crtc_state->pixel_multiplier - 1)
10190 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
10192 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
10193 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
10194 dpll |= DPLL_SDVO_HIGH_SPEED;
10196 if (intel_crtc_has_dp_encoder(crtc_state))
10197 dpll |= DPLL_SDVO_HIGH_SPEED;
10200 * The high speed IO clock is only really required for
10201 * SDVO/HDMI/DP, but we also enable it for CRT to make it
10202 * possible to share the DPLL between CRT and HDMI. Enabling
10203 * the clock needlessly does no real harm, except use up a
10204 * bit of power potentially.
10206 * We'll limit this to IVB with 3 pipes, since it has only two
10207 * DPLLs and so DPLL sharing is the only way to get three pipes
10208 * driving PCH ports at the same time. On SNB we could do this,
10209 * and potentially avoid enabling the second DPLL, but it's not
10210 * clear if it''s a win or loss power wise. No point in doing
10211 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
10213 if (INTEL_NUM_PIPES(dev_priv) == 3 &&
10214 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
10215 dpll |= DPLL_SDVO_HIGH_SPEED;
10217 /* compute bitmask from p1 value */
10218 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
10220 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
10222 switch (crtc_state->dpll.p2) {
10224 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
10227 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
10230 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
10233 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
10237 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
10238 intel_panel_use_ssc(dev_priv))
10239 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
10241 dpll |= PLL_REF_INPUT_DREFCLK;
10243 dpll |= DPLL_VCO_ENABLE;
10245 crtc_state->dpll_hw_state.dpll = dpll;
10246 crtc_state->dpll_hw_state.fp0 = fp;
10247 crtc_state->dpll_hw_state.fp1 = fp2;
10250 static int ilk_crtc_compute_clock(struct intel_crtc *crtc,
10251 struct intel_crtc_state *crtc_state)
10253 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10254 struct intel_atomic_state *state =
10255 to_intel_atomic_state(crtc_state->uapi.state);
10256 const struct intel_limit *limit;
10257 int refclk = 120000;
10259 memset(&crtc_state->dpll_hw_state, 0,
10260 sizeof(crtc_state->dpll_hw_state));
10262 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
10263 if (!crtc_state->has_pch_encoder)
10266 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
10267 if (intel_panel_use_ssc(dev_priv)) {
10268 drm_dbg_kms(&dev_priv->drm,
10269 "using SSC reference clock of %d kHz\n",
10270 dev_priv->vbt.lvds_ssc_freq);
10271 refclk = dev_priv->vbt.lvds_ssc_freq;
10274 if (intel_is_dual_link_lvds(dev_priv)) {
10275 if (refclk == 100000)
10276 limit = &ilk_limits_dual_lvds_100m;
10278 limit = &ilk_limits_dual_lvds;
10280 if (refclk == 100000)
10281 limit = &ilk_limits_single_lvds_100m;
10283 limit = &ilk_limits_single_lvds;
10286 limit = &ilk_limits_dac;
10289 if (!crtc_state->clock_set &&
10290 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
10291 refclk, NULL, &crtc_state->dpll)) {
10292 drm_err(&dev_priv->drm,
10293 "Couldn't find PLL settings for mode!\n");
10297 ilk_compute_dpll(crtc, crtc_state, NULL);
10299 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
10300 drm_dbg_kms(&dev_priv->drm,
10301 "failed to find PLL for pipe %c\n",
10302 pipe_name(crtc->pipe));
10309 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
10310 struct intel_link_m_n *m_n)
10312 struct drm_device *dev = crtc->base.dev;
10313 struct drm_i915_private *dev_priv = to_i915(dev);
10314 enum pipe pipe = crtc->pipe;
10316 m_n->link_m = intel_de_read(dev_priv, PCH_TRANS_LINK_M1(pipe));
10317 m_n->link_n = intel_de_read(dev_priv, PCH_TRANS_LINK_N1(pipe));
10318 m_n->gmch_m = intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
10320 m_n->gmch_n = intel_de_read(dev_priv, PCH_TRANS_DATA_N1(pipe));
10321 m_n->tu = ((intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
10322 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10325 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
10326 enum transcoder transcoder,
10327 struct intel_link_m_n *m_n,
10328 struct intel_link_m_n *m2_n2)
10330 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10331 enum pipe pipe = crtc->pipe;
10333 if (INTEL_GEN(dev_priv) >= 5) {
10334 m_n->link_m = intel_de_read(dev_priv,
10335 PIPE_LINK_M1(transcoder));
10336 m_n->link_n = intel_de_read(dev_priv,
10337 PIPE_LINK_N1(transcoder));
10338 m_n->gmch_m = intel_de_read(dev_priv,
10339 PIPE_DATA_M1(transcoder))
10341 m_n->gmch_n = intel_de_read(dev_priv,
10342 PIPE_DATA_N1(transcoder));
10343 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M1(transcoder))
10344 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10346 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
10347 m2_n2->link_m = intel_de_read(dev_priv,
10348 PIPE_LINK_M2(transcoder));
10349 m2_n2->link_n = intel_de_read(dev_priv,
10350 PIPE_LINK_N2(transcoder));
10351 m2_n2->gmch_m = intel_de_read(dev_priv,
10352 PIPE_DATA_M2(transcoder))
10354 m2_n2->gmch_n = intel_de_read(dev_priv,
10355 PIPE_DATA_N2(transcoder));
10356 m2_n2->tu = ((intel_de_read(dev_priv, PIPE_DATA_M2(transcoder))
10357 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10360 m_n->link_m = intel_de_read(dev_priv, PIPE_LINK_M_G4X(pipe));
10361 m_n->link_n = intel_de_read(dev_priv, PIPE_LINK_N_G4X(pipe));
10362 m_n->gmch_m = intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
10364 m_n->gmch_n = intel_de_read(dev_priv, PIPE_DATA_N_G4X(pipe));
10365 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
10366 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10370 void intel_dp_get_m_n(struct intel_crtc *crtc,
10371 struct intel_crtc_state *pipe_config)
10373 if (pipe_config->has_pch_encoder)
10374 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
10376 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10377 &pipe_config->dp_m_n,
10378 &pipe_config->dp_m2_n2);
10381 static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc,
10382 struct intel_crtc_state *pipe_config)
10384 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10385 &pipe_config->fdi_m_n, NULL);
10388 static void skl_get_pfit_config(struct intel_crtc *crtc,
10389 struct intel_crtc_state *pipe_config)
10391 struct drm_device *dev = crtc->base.dev;
10392 struct drm_i915_private *dev_priv = to_i915(dev);
10393 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
10398 /* find scaler attached to this pipe */
10399 for (i = 0; i < crtc->num_scalers; i++) {
10400 ps_ctrl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i));
10401 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
10403 pipe_config->pch_pfit.enabled = true;
10404 pipe_config->pch_pfit.pos = intel_de_read(dev_priv,
10405 SKL_PS_WIN_POS(crtc->pipe, i));
10406 pipe_config->pch_pfit.size = intel_de_read(dev_priv,
10407 SKL_PS_WIN_SZ(crtc->pipe, i));
10408 scaler_state->scalers[i].in_use = true;
10413 scaler_state->scaler_id = id;
10415 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
10417 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
10422 skl_get_initial_plane_config(struct intel_crtc *crtc,
10423 struct intel_initial_plane_config *plane_config)
10425 struct drm_device *dev = crtc->base.dev;
10426 struct drm_i915_private *dev_priv = to_i915(dev);
10427 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
10428 enum plane_id plane_id = plane->id;
10430 u32 val, base, offset, stride_mult, tiling, alpha;
10431 int fourcc, pixel_format;
10432 unsigned int aligned_height;
10433 struct drm_framebuffer *fb;
10434 struct intel_framebuffer *intel_fb;
10436 if (!plane->get_hw_state(plane, &pipe))
10439 drm_WARN_ON(dev, pipe != crtc->pipe);
10441 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10443 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
10447 fb = &intel_fb->base;
10451 val = intel_de_read(dev_priv, PLANE_CTL(pipe, plane_id));
10453 if (INTEL_GEN(dev_priv) >= 11)
10454 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
10456 pixel_format = val & PLANE_CTL_FORMAT_MASK;
10458 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
10459 alpha = intel_de_read(dev_priv,
10460 PLANE_COLOR_CTL(pipe, plane_id));
10461 alpha &= PLANE_COLOR_ALPHA_MASK;
10463 alpha = val & PLANE_CTL_ALPHA_MASK;
10466 fourcc = skl_format_to_fourcc(pixel_format,
10467 val & PLANE_CTL_ORDER_RGBX, alpha);
10468 fb->format = drm_format_info(fourcc);
10470 tiling = val & PLANE_CTL_TILED_MASK;
10472 case PLANE_CTL_TILED_LINEAR:
10473 fb->modifier = DRM_FORMAT_MOD_LINEAR;
10475 case PLANE_CTL_TILED_X:
10476 plane_config->tiling = I915_TILING_X;
10477 fb->modifier = I915_FORMAT_MOD_X_TILED;
10479 case PLANE_CTL_TILED_Y:
10480 plane_config->tiling = I915_TILING_Y;
10481 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10482 fb->modifier = INTEL_GEN(dev_priv) >= 12 ?
10483 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS :
10484 I915_FORMAT_MOD_Y_TILED_CCS;
10485 else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE)
10486 fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
10488 fb->modifier = I915_FORMAT_MOD_Y_TILED;
10490 case PLANE_CTL_TILED_YF:
10491 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10492 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
10494 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
10497 MISSING_CASE(tiling);
10502 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
10503 * while i915 HW rotation is clockwise, thats why this swapping.
10505 switch (val & PLANE_CTL_ROTATE_MASK) {
10506 case PLANE_CTL_ROTATE_0:
10507 plane_config->rotation = DRM_MODE_ROTATE_0;
10509 case PLANE_CTL_ROTATE_90:
10510 plane_config->rotation = DRM_MODE_ROTATE_270;
10512 case PLANE_CTL_ROTATE_180:
10513 plane_config->rotation = DRM_MODE_ROTATE_180;
10515 case PLANE_CTL_ROTATE_270:
10516 plane_config->rotation = DRM_MODE_ROTATE_90;
10520 if (INTEL_GEN(dev_priv) >= 10 &&
10521 val & PLANE_CTL_FLIP_HORIZONTAL)
10522 plane_config->rotation |= DRM_MODE_REFLECT_X;
10524 base = intel_de_read(dev_priv, PLANE_SURF(pipe, plane_id)) & 0xfffff000;
10525 plane_config->base = base;
10527 offset = intel_de_read(dev_priv, PLANE_OFFSET(pipe, plane_id));
10529 val = intel_de_read(dev_priv, PLANE_SIZE(pipe, plane_id));
10530 fb->height = ((val >> 16) & 0xffff) + 1;
10531 fb->width = ((val >> 0) & 0xffff) + 1;
10533 val = intel_de_read(dev_priv, PLANE_STRIDE(pipe, plane_id));
10534 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
10535 fb->pitches[0] = (val & 0x3ff) * stride_mult;
10537 aligned_height = intel_fb_align_height(fb, 0, fb->height);
10539 plane_config->size = fb->pitches[0] * aligned_height;
10541 drm_dbg_kms(&dev_priv->drm,
10542 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
10543 crtc->base.name, plane->base.name, fb->width, fb->height,
10544 fb->format->cpp[0] * 8, base, fb->pitches[0],
10545 plane_config->size);
10547 plane_config->fb = intel_fb;
10554 static void ilk_get_pfit_config(struct intel_crtc *crtc,
10555 struct intel_crtc_state *pipe_config)
10557 struct drm_device *dev = crtc->base.dev;
10558 struct drm_i915_private *dev_priv = to_i915(dev);
10561 tmp = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
10563 if (tmp & PF_ENABLE) {
10564 pipe_config->pch_pfit.enabled = true;
10565 pipe_config->pch_pfit.pos = intel_de_read(dev_priv,
10566 PF_WIN_POS(crtc->pipe));
10567 pipe_config->pch_pfit.size = intel_de_read(dev_priv,
10568 PF_WIN_SZ(crtc->pipe));
10570 /* We currently do not free assignements of panel fitters on
10571 * ivb/hsw (since we don't use the higher upscaling modes which
10572 * differentiates them) so just WARN about this case for now. */
10573 if (IS_GEN(dev_priv, 7)) {
10574 drm_WARN_ON(dev, (tmp & PF_PIPE_SEL_MASK_IVB) !=
10575 PF_PIPE_SEL_IVB(crtc->pipe));
10580 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
10581 struct intel_crtc_state *pipe_config)
10583 struct drm_device *dev = crtc->base.dev;
10584 struct drm_i915_private *dev_priv = to_i915(dev);
10585 enum intel_display_power_domain power_domain;
10586 intel_wakeref_t wakeref;
10590 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10591 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10595 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10596 pipe_config->shared_dpll = NULL;
10599 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
10600 if (!(tmp & PIPECONF_ENABLE))
10603 switch (tmp & PIPECONF_BPC_MASK) {
10604 case PIPECONF_6BPC:
10605 pipe_config->pipe_bpp = 18;
10607 case PIPECONF_8BPC:
10608 pipe_config->pipe_bpp = 24;
10610 case PIPECONF_10BPC:
10611 pipe_config->pipe_bpp = 30;
10613 case PIPECONF_12BPC:
10614 pipe_config->pipe_bpp = 36;
10620 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
10621 pipe_config->limited_color_range = true;
10623 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
10624 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
10625 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
10626 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10629 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10633 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
10634 PIPECONF_GAMMA_MODE_SHIFT;
10636 pipe_config->csc_mode = intel_de_read(dev_priv,
10637 PIPE_CSC_MODE(crtc->pipe));
10639 i9xx_get_pipe_color_config(pipe_config);
10640 intel_color_get_config(pipe_config);
10642 if (intel_de_read(dev_priv, PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
10643 struct intel_shared_dpll *pll;
10644 enum intel_dpll_id pll_id;
10646 pipe_config->has_pch_encoder = true;
10648 tmp = intel_de_read(dev_priv, FDI_RX_CTL(crtc->pipe));
10649 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10650 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10652 ilk_get_fdi_m_n_config(crtc, pipe_config);
10654 if (HAS_PCH_IBX(dev_priv)) {
10656 * The pipe->pch transcoder and pch transcoder->pll
10657 * mapping is fixed.
10659 pll_id = (enum intel_dpll_id) crtc->pipe;
10661 tmp = intel_de_read(dev_priv, PCH_DPLL_SEL);
10662 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
10663 pll_id = DPLL_ID_PCH_PLL_B;
10665 pll_id= DPLL_ID_PCH_PLL_A;
10668 pipe_config->shared_dpll =
10669 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10670 pll = pipe_config->shared_dpll;
10672 drm_WARN_ON(dev, !pll->info->funcs->get_hw_state(dev_priv, pll,
10673 &pipe_config->dpll_hw_state));
10675 tmp = pipe_config->dpll_hw_state.dpll;
10676 pipe_config->pixel_multiplier =
10677 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10678 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10680 ilk_pch_clock_get(crtc, pipe_config);
10682 pipe_config->pixel_multiplier = 1;
10685 intel_get_pipe_timings(crtc, pipe_config);
10686 intel_get_pipe_src_size(crtc, pipe_config);
10688 ilk_get_pfit_config(crtc, pipe_config);
10693 intel_display_power_put(dev_priv, power_domain, wakeref);
10698 static int hsw_crtc_compute_clock(struct intel_crtc *crtc,
10699 struct intel_crtc_state *crtc_state)
10701 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10702 struct intel_atomic_state *state =
10703 to_intel_atomic_state(crtc_state->uapi.state);
10705 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10706 INTEL_GEN(dev_priv) >= 11) {
10707 struct intel_encoder *encoder =
10708 intel_get_crtc_new_encoder(state, crtc_state);
10710 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10711 drm_dbg_kms(&dev_priv->drm,
10712 "failed to find PLL for pipe %c\n",
10713 pipe_name(crtc->pipe));
10721 static void cnl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10722 struct intel_crtc_state *pipe_config)
10724 enum intel_dpll_id id;
10727 temp = intel_de_read(dev_priv, DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10728 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10730 if (drm_WARN_ON(&dev_priv->drm, id < SKL_DPLL0 || id > SKL_DPLL2))
10733 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10736 static void icl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10737 struct intel_crtc_state *pipe_config)
10739 enum phy phy = intel_port_to_phy(dev_priv, port);
10740 enum icl_port_dpll_id port_dpll_id;
10741 enum intel_dpll_id id;
10744 if (intel_phy_is_combo(dev_priv, phy)) {
10745 temp = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0) &
10746 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10747 id = temp >> ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10748 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10749 } else if (intel_phy_is_tc(dev_priv, phy)) {
10750 u32 clk_sel = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
10752 if (clk_sel == DDI_CLK_SEL_MG) {
10753 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
10755 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
10757 drm_WARN_ON(&dev_priv->drm,
10758 clk_sel < DDI_CLK_SEL_TBT_162);
10759 id = DPLL_ID_ICL_TBTPLL;
10760 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10763 drm_WARN(&dev_priv->drm, 1, "Invalid port %x\n", port);
10767 pipe_config->icl_port_dplls[port_dpll_id].pll =
10768 intel_get_shared_dpll_by_id(dev_priv, id);
10770 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10773 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
10775 struct intel_crtc_state *pipe_config)
10777 enum intel_dpll_id id;
10781 id = DPLL_ID_SKL_DPLL0;
10784 id = DPLL_ID_SKL_DPLL1;
10787 id = DPLL_ID_SKL_DPLL2;
10790 drm_err(&dev_priv->drm, "Incorrect port type\n");
10794 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10797 static void skl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10798 struct intel_crtc_state *pipe_config)
10800 enum intel_dpll_id id;
10803 temp = intel_de_read(dev_priv, DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10804 id = temp >> (port * 3 + 1);
10806 if (drm_WARN_ON(&dev_priv->drm, id < SKL_DPLL0 || id > SKL_DPLL3))
10809 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10812 static void hsw_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10813 struct intel_crtc_state *pipe_config)
10815 enum intel_dpll_id id;
10816 u32 ddi_pll_sel = intel_de_read(dev_priv, PORT_CLK_SEL(port));
10818 switch (ddi_pll_sel) {
10819 case PORT_CLK_SEL_WRPLL1:
10820 id = DPLL_ID_WRPLL1;
10822 case PORT_CLK_SEL_WRPLL2:
10823 id = DPLL_ID_WRPLL2;
10825 case PORT_CLK_SEL_SPLL:
10828 case PORT_CLK_SEL_LCPLL_810:
10829 id = DPLL_ID_LCPLL_810;
10831 case PORT_CLK_SEL_LCPLL_1350:
10832 id = DPLL_ID_LCPLL_1350;
10834 case PORT_CLK_SEL_LCPLL_2700:
10835 id = DPLL_ID_LCPLL_2700;
10838 MISSING_CASE(ddi_pll_sel);
10840 case PORT_CLK_SEL_NONE:
10844 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10847 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10848 struct intel_crtc_state *pipe_config,
10849 u64 *power_domain_mask,
10850 intel_wakeref_t *wakerefs)
10852 struct drm_device *dev = crtc->base.dev;
10853 struct drm_i915_private *dev_priv = to_i915(dev);
10854 enum intel_display_power_domain power_domain;
10855 unsigned long panel_transcoder_mask = 0;
10856 unsigned long enabled_panel_transcoders = 0;
10857 enum transcoder panel_transcoder;
10858 intel_wakeref_t wf;
10861 if (INTEL_GEN(dev_priv) >= 11)
10862 panel_transcoder_mask |=
10863 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10865 if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP))
10866 panel_transcoder_mask |= BIT(TRANSCODER_EDP);
10869 * The pipe->transcoder mapping is fixed with the exception of the eDP
10870 * and DSI transcoders handled below.
10872 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10875 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10876 * consistency and less surprising code; it's in always on power).
10878 for_each_set_bit(panel_transcoder,
10879 &panel_transcoder_mask,
10880 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
10881 bool force_thru = false;
10882 enum pipe trans_pipe;
10884 tmp = intel_de_read(dev_priv,
10885 TRANS_DDI_FUNC_CTL(panel_transcoder));
10886 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10890 * Log all enabled ones, only use the first one.
10892 * FIXME: This won't work for two separate DSI displays.
10894 enabled_panel_transcoders |= BIT(panel_transcoder);
10895 if (enabled_panel_transcoders != BIT(panel_transcoder))
10898 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10901 "unknown pipe linked to transcoder %s\n",
10902 transcoder_name(panel_transcoder));
10904 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10907 case TRANS_DDI_EDP_INPUT_A_ON:
10908 trans_pipe = PIPE_A;
10910 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10911 trans_pipe = PIPE_B;
10913 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10914 trans_pipe = PIPE_C;
10916 case TRANS_DDI_EDP_INPUT_D_ONOFF:
10917 trans_pipe = PIPE_D;
10921 if (trans_pipe == crtc->pipe) {
10922 pipe_config->cpu_transcoder = panel_transcoder;
10923 pipe_config->pch_pfit.force_thru = force_thru;
10928 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10930 drm_WARN_ON(dev, (enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10931 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10933 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
10934 drm_WARN_ON(dev, *power_domain_mask & BIT_ULL(power_domain));
10936 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10940 wakerefs[power_domain] = wf;
10941 *power_domain_mask |= BIT_ULL(power_domain);
10943 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder));
10945 return tmp & PIPECONF_ENABLE;
10948 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10949 struct intel_crtc_state *pipe_config,
10950 u64 *power_domain_mask,
10951 intel_wakeref_t *wakerefs)
10953 struct drm_device *dev = crtc->base.dev;
10954 struct drm_i915_private *dev_priv = to_i915(dev);
10955 enum intel_display_power_domain power_domain;
10956 enum transcoder cpu_transcoder;
10957 intel_wakeref_t wf;
10961 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10962 if (port == PORT_A)
10963 cpu_transcoder = TRANSCODER_DSI_A;
10965 cpu_transcoder = TRANSCODER_DSI_C;
10967 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10968 drm_WARN_ON(dev, *power_domain_mask & BIT_ULL(power_domain));
10970 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10974 wakerefs[power_domain] = wf;
10975 *power_domain_mask |= BIT_ULL(power_domain);
10978 * The PLL needs to be enabled with a valid divider
10979 * configuration, otherwise accessing DSI registers will hang
10980 * the machine. See BSpec North Display Engine
10981 * registers/MIPI[BXT]. We can break out here early, since we
10982 * need the same DSI PLL to be enabled for both DSI ports.
10984 if (!bxt_dsi_pll_is_enabled(dev_priv))
10987 /* XXX: this works for video mode only */
10988 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
10989 if (!(tmp & DPI_ENABLE))
10992 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
10993 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
10996 pipe_config->cpu_transcoder = cpu_transcoder;
11000 return transcoder_is_dsi(pipe_config->cpu_transcoder);
11003 static void hsw_get_ddi_port_state(struct intel_crtc *crtc,
11004 struct intel_crtc_state *pipe_config)
11006 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11007 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
11008 struct intel_shared_dpll *pll;
11012 if (transcoder_is_dsi(cpu_transcoder)) {
11013 port = (cpu_transcoder == TRANSCODER_DSI_A) ?
11016 tmp = intel_de_read(dev_priv,
11017 TRANS_DDI_FUNC_CTL(cpu_transcoder));
11018 if (INTEL_GEN(dev_priv) >= 12)
11019 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
11021 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
11024 if (INTEL_GEN(dev_priv) >= 11)
11025 icl_get_ddi_pll(dev_priv, port, pipe_config);
11026 else if (IS_CANNONLAKE(dev_priv))
11027 cnl_get_ddi_pll(dev_priv, port, pipe_config);
11028 else if (IS_GEN9_BC(dev_priv))
11029 skl_get_ddi_pll(dev_priv, port, pipe_config);
11030 else if (IS_GEN9_LP(dev_priv))
11031 bxt_get_ddi_pll(dev_priv, port, pipe_config);
11033 hsw_get_ddi_pll(dev_priv, port, pipe_config);
11035 pll = pipe_config->shared_dpll;
11037 drm_WARN_ON(&dev_priv->drm,
11038 !pll->info->funcs->get_hw_state(dev_priv, pll,
11039 &pipe_config->dpll_hw_state));
11043 * Haswell has only FDI/PCH transcoder A. It is which is connected to
11044 * DDI E. So just check whether this pipe is wired to DDI E and whether
11045 * the PCH transcoder is on.
11047 if (INTEL_GEN(dev_priv) < 9 &&
11048 (port == PORT_E) && intel_de_read(dev_priv, LPT_TRANSCONF) & TRANS_ENABLE) {
11049 pipe_config->has_pch_encoder = true;
11051 tmp = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
11052 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
11053 FDI_DP_PORT_WIDTH_SHIFT) + 1;
11055 ilk_get_fdi_m_n_config(crtc, pipe_config);
11059 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
11060 struct intel_crtc_state *pipe_config)
11062 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11063 intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf;
11064 enum intel_display_power_domain power_domain;
11065 u64 power_domain_mask;
11069 pipe_config->master_transcoder = INVALID_TRANSCODER;
11071 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
11072 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
11076 wakerefs[power_domain] = wf;
11077 power_domain_mask = BIT_ULL(power_domain);
11079 pipe_config->shared_dpll = NULL;
11081 active = hsw_get_transcoder_state(crtc, pipe_config,
11082 &power_domain_mask, wakerefs);
11084 if (IS_GEN9_LP(dev_priv) &&
11085 bxt_get_dsi_transcoder_state(crtc, pipe_config,
11086 &power_domain_mask, wakerefs)) {
11087 drm_WARN_ON(&dev_priv->drm, active);
11094 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
11095 INTEL_GEN(dev_priv) >= 11) {
11096 hsw_get_ddi_port_state(crtc, pipe_config);
11097 intel_get_pipe_timings(crtc, pipe_config);
11100 intel_get_pipe_src_size(crtc, pipe_config);
11102 if (IS_HASWELL(dev_priv)) {
11103 u32 tmp = intel_de_read(dev_priv,
11104 PIPECONF(pipe_config->cpu_transcoder));
11106 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
11107 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
11109 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
11111 pipe_config->output_format =
11112 bdw_get_pipemisc_output_format(crtc);
11115 * Currently there is no interface defined to
11116 * check user preference between RGB/YCBCR444
11117 * or YCBCR420. So the only possible case for
11118 * YCBCR444 usage is driving YCBCR420 output
11119 * with LSPCON, when pipe is configured for
11120 * YCBCR444 output and LSPCON takes care of
11123 pipe_config->lspcon_downsampling =
11124 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444;
11127 pipe_config->gamma_mode = intel_de_read(dev_priv,
11128 GAMMA_MODE(crtc->pipe));
11130 pipe_config->csc_mode = intel_de_read(dev_priv,
11131 PIPE_CSC_MODE(crtc->pipe));
11133 if (INTEL_GEN(dev_priv) >= 9) {
11134 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
11136 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
11137 pipe_config->gamma_enable = true;
11139 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
11140 pipe_config->csc_enable = true;
11142 i9xx_get_pipe_color_config(pipe_config);
11145 intel_color_get_config(pipe_config);
11147 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
11148 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
11149 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
11150 pipe_config->ips_linetime =
11151 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
11153 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
11154 drm_WARN_ON(&dev_priv->drm, power_domain_mask & BIT_ULL(power_domain));
11156 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
11158 wakerefs[power_domain] = wf;
11159 power_domain_mask |= BIT_ULL(power_domain);
11161 if (INTEL_GEN(dev_priv) >= 9)
11162 skl_get_pfit_config(crtc, pipe_config);
11164 ilk_get_pfit_config(crtc, pipe_config);
11167 if (hsw_crtc_supports_ips(crtc)) {
11168 if (IS_HASWELL(dev_priv))
11169 pipe_config->ips_enabled = intel_de_read(dev_priv,
11170 IPS_CTL) & IPS_ENABLE;
11173 * We cannot readout IPS state on broadwell, set to
11174 * true so we can set it to a defined state on first
11177 pipe_config->ips_enabled = true;
11181 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
11182 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
11183 pipe_config->pixel_multiplier =
11184 intel_de_read(dev_priv,
11185 PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
11187 pipe_config->pixel_multiplier = 1;
11191 for_each_power_domain(power_domain, power_domain_mask)
11192 intel_display_power_put(dev_priv,
11193 power_domain, wakerefs[power_domain]);
11198 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
11200 struct drm_i915_private *dev_priv =
11201 to_i915(plane_state->uapi.plane->dev);
11202 const struct drm_framebuffer *fb = plane_state->hw.fb;
11203 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11206 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
11207 base = sg_dma_address(obj->mm.pages->sgl);
11209 base = intel_plane_ggtt_offset(plane_state);
11211 return base + plane_state->color_plane[0].offset;
11214 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
11216 int x = plane_state->uapi.dst.x1;
11217 int y = plane_state->uapi.dst.y1;
11221 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
11224 pos |= x << CURSOR_X_SHIFT;
11227 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
11230 pos |= y << CURSOR_Y_SHIFT;
11235 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
11237 const struct drm_mode_config *config =
11238 &plane_state->uapi.plane->dev->mode_config;
11239 int width = drm_rect_width(&plane_state->uapi.dst);
11240 int height = drm_rect_height(&plane_state->uapi.dst);
11242 return width > 0 && width <= config->cursor_width &&
11243 height > 0 && height <= config->cursor_height;
11246 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
11248 struct drm_i915_private *dev_priv =
11249 to_i915(plane_state->uapi.plane->dev);
11250 unsigned int rotation = plane_state->hw.rotation;
11255 ret = intel_plane_compute_gtt(plane_state);
11259 if (!plane_state->uapi.visible)
11262 src_x = plane_state->uapi.src.x1 >> 16;
11263 src_y = plane_state->uapi.src.y1 >> 16;
11265 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
11266 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
11269 if (src_x != 0 || src_y != 0) {
11270 drm_dbg_kms(&dev_priv->drm,
11271 "Arbitrary cursor panning not supported\n");
11276 * Put the final coordinates back so that the src
11277 * coordinate checks will see the right values.
11279 drm_rect_translate_to(&plane_state->uapi.src,
11280 src_x << 16, src_y << 16);
11282 /* ILK+ do this automagically in hardware */
11283 if (HAS_GMCH(dev_priv) && rotation & DRM_MODE_ROTATE_180) {
11284 const struct drm_framebuffer *fb = plane_state->hw.fb;
11285 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
11286 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
11288 offset += (src_h * src_w - 1) * fb->format->cpp[0];
11291 plane_state->color_plane[0].offset = offset;
11292 plane_state->color_plane[0].x = src_x;
11293 plane_state->color_plane[0].y = src_y;
11298 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
11299 struct intel_plane_state *plane_state)
11301 const struct drm_framebuffer *fb = plane_state->hw.fb;
11302 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
11305 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
11306 drm_dbg_kms(&i915->drm, "cursor cannot be tiled\n");
11310 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
11312 DRM_PLANE_HELPER_NO_SCALING,
11313 DRM_PLANE_HELPER_NO_SCALING,
11318 /* Use the unclipped src/dst rectangles, which we program to hw */
11319 plane_state->uapi.src = drm_plane_state_src(&plane_state->uapi);
11320 plane_state->uapi.dst = drm_plane_state_dest(&plane_state->uapi);
11322 ret = intel_cursor_check_surface(plane_state);
11326 if (!plane_state->uapi.visible)
11329 ret = intel_plane_check_src_coordinates(plane_state);
11336 static unsigned int
11337 i845_cursor_max_stride(struct intel_plane *plane,
11338 u32 pixel_format, u64 modifier,
11339 unsigned int rotation)
11344 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11348 if (crtc_state->gamma_enable)
11349 cntl |= CURSOR_GAMMA_ENABLE;
11354 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
11355 const struct intel_plane_state *plane_state)
11357 return CURSOR_ENABLE |
11358 CURSOR_FORMAT_ARGB |
11359 CURSOR_STRIDE(plane_state->color_plane[0].stride);
11362 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
11364 int width = drm_rect_width(&plane_state->uapi.dst);
11367 * 845g/865g are only limited by the width of their cursors,
11368 * the height is arbitrary up to the precision of the register.
11370 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
11373 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
11374 struct intel_plane_state *plane_state)
11376 const struct drm_framebuffer *fb = plane_state->hw.fb;
11377 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
11380 ret = intel_check_cursor(crtc_state, plane_state);
11384 /* if we want to turn off the cursor ignore width and height */
11388 /* Check for which cursor types we support */
11389 if (!i845_cursor_size_ok(plane_state)) {
11390 drm_dbg_kms(&i915->drm,
11391 "Cursor dimension %dx%d not supported\n",
11392 drm_rect_width(&plane_state->uapi.dst),
11393 drm_rect_height(&plane_state->uapi.dst));
11397 drm_WARN_ON(&i915->drm, plane_state->uapi.visible &&
11398 plane_state->color_plane[0].stride != fb->pitches[0]);
11400 switch (fb->pitches[0]) {
11407 drm_dbg_kms(&i915->drm, "Invalid cursor stride (%u)\n",
11412 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
11417 static void i845_update_cursor(struct intel_plane *plane,
11418 const struct intel_crtc_state *crtc_state,
11419 const struct intel_plane_state *plane_state)
11421 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11422 u32 cntl = 0, base = 0, pos = 0, size = 0;
11423 unsigned long irqflags;
11425 if (plane_state && plane_state->uapi.visible) {
11426 unsigned int width = drm_rect_width(&plane_state->uapi.dst);
11427 unsigned int height = drm_rect_height(&plane_state->uapi.dst);
11429 cntl = plane_state->ctl |
11430 i845_cursor_ctl_crtc(crtc_state);
11432 size = (height << 12) | width;
11434 base = intel_cursor_base(plane_state);
11435 pos = intel_cursor_position(plane_state);
11438 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11440 /* On these chipsets we can only modify the base/size/stride
11441 * whilst the cursor is disabled.
11443 if (plane->cursor.base != base ||
11444 plane->cursor.size != size ||
11445 plane->cursor.cntl != cntl) {
11446 intel_de_write_fw(dev_priv, CURCNTR(PIPE_A), 0);
11447 intel_de_write_fw(dev_priv, CURBASE(PIPE_A), base);
11448 intel_de_write_fw(dev_priv, CURSIZE, size);
11449 intel_de_write_fw(dev_priv, CURPOS(PIPE_A), pos);
11450 intel_de_write_fw(dev_priv, CURCNTR(PIPE_A), cntl);
11452 plane->cursor.base = base;
11453 plane->cursor.size = size;
11454 plane->cursor.cntl = cntl;
11456 intel_de_write_fw(dev_priv, CURPOS(PIPE_A), pos);
11459 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11462 static void i845_disable_cursor(struct intel_plane *plane,
11463 const struct intel_crtc_state *crtc_state)
11465 i845_update_cursor(plane, crtc_state, NULL);
11468 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
11471 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11472 enum intel_display_power_domain power_domain;
11473 intel_wakeref_t wakeref;
11476 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
11477 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11481 ret = intel_de_read(dev_priv, CURCNTR(PIPE_A)) & CURSOR_ENABLE;
11485 intel_display_power_put(dev_priv, power_domain, wakeref);
11490 static unsigned int
11491 i9xx_cursor_max_stride(struct intel_plane *plane,
11492 u32 pixel_format, u64 modifier,
11493 unsigned int rotation)
11495 return plane->base.dev->mode_config.cursor_width * 4;
11498 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11500 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11501 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11504 if (INTEL_GEN(dev_priv) >= 11)
11507 if (crtc_state->gamma_enable)
11508 cntl = MCURSOR_GAMMA_ENABLE;
11510 if (crtc_state->csc_enable)
11511 cntl |= MCURSOR_PIPE_CSC_ENABLE;
11513 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11514 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
11519 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
11520 const struct intel_plane_state *plane_state)
11522 struct drm_i915_private *dev_priv =
11523 to_i915(plane_state->uapi.plane->dev);
11526 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
11527 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
11529 switch (drm_rect_width(&plane_state->uapi.dst)) {
11531 cntl |= MCURSOR_MODE_64_ARGB_AX;
11534 cntl |= MCURSOR_MODE_128_ARGB_AX;
11537 cntl |= MCURSOR_MODE_256_ARGB_AX;
11540 MISSING_CASE(drm_rect_width(&plane_state->uapi.dst));
11544 if (plane_state->hw.rotation & DRM_MODE_ROTATE_180)
11545 cntl |= MCURSOR_ROTATE_180;
11550 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
11552 struct drm_i915_private *dev_priv =
11553 to_i915(plane_state->uapi.plane->dev);
11554 int width = drm_rect_width(&plane_state->uapi.dst);
11555 int height = drm_rect_height(&plane_state->uapi.dst);
11557 if (!intel_cursor_size_ok(plane_state))
11560 /* Cursor width is limited to a few power-of-two sizes */
11571 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
11572 * height from 8 lines up to the cursor width, when the
11573 * cursor is not rotated. Everything else requires square
11576 if (HAS_CUR_FBC(dev_priv) &&
11577 plane_state->hw.rotation & DRM_MODE_ROTATE_0) {
11578 if (height < 8 || height > width)
11581 if (height != width)
11588 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
11589 struct intel_plane_state *plane_state)
11591 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
11592 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11593 const struct drm_framebuffer *fb = plane_state->hw.fb;
11594 enum pipe pipe = plane->pipe;
11597 ret = intel_check_cursor(crtc_state, plane_state);
11601 /* if we want to turn off the cursor ignore width and height */
11605 /* Check for which cursor types we support */
11606 if (!i9xx_cursor_size_ok(plane_state)) {
11607 drm_dbg(&dev_priv->drm,
11608 "Cursor dimension %dx%d not supported\n",
11609 drm_rect_width(&plane_state->uapi.dst),
11610 drm_rect_height(&plane_state->uapi.dst));
11614 drm_WARN_ON(&dev_priv->drm, plane_state->uapi.visible &&
11615 plane_state->color_plane[0].stride != fb->pitches[0]);
11617 if (fb->pitches[0] !=
11618 drm_rect_width(&plane_state->uapi.dst) * fb->format->cpp[0]) {
11619 drm_dbg_kms(&dev_priv->drm,
11620 "Invalid cursor stride (%u) (cursor width %d)\n",
11622 drm_rect_width(&plane_state->uapi.dst));
11627 * There's something wrong with the cursor on CHV pipe C.
11628 * If it straddles the left edge of the screen then
11629 * moving it away from the edge or disabling it often
11630 * results in a pipe underrun, and often that can lead to
11631 * dead pipe (constant underrun reported, and it scans
11632 * out just a solid color). To recover from that, the
11633 * display power well must be turned off and on again.
11634 * Refuse the put the cursor into that compromised position.
11636 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
11637 plane_state->uapi.visible && plane_state->uapi.dst.x1 < 0) {
11638 drm_dbg_kms(&dev_priv->drm,
11639 "CHV cursor C not allowed to straddle the left screen edge\n");
11643 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
11648 static void i9xx_update_cursor(struct intel_plane *plane,
11649 const struct intel_crtc_state *crtc_state,
11650 const struct intel_plane_state *plane_state)
11652 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11653 enum pipe pipe = plane->pipe;
11654 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
11655 unsigned long irqflags;
11657 if (plane_state && plane_state->uapi.visible) {
11658 unsigned width = drm_rect_width(&plane_state->uapi.dst);
11659 unsigned height = drm_rect_height(&plane_state->uapi.dst);
11661 cntl = plane_state->ctl |
11662 i9xx_cursor_ctl_crtc(crtc_state);
11664 if (width != height)
11665 fbc_ctl = CUR_FBC_CTL_EN | (height - 1);
11667 base = intel_cursor_base(plane_state);
11668 pos = intel_cursor_position(plane_state);
11671 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11674 * On some platforms writing CURCNTR first will also
11675 * cause CURPOS to be armed by the CURBASE write.
11676 * Without the CURCNTR write the CURPOS write would
11677 * arm itself. Thus we always update CURCNTR before
11680 * On other platforms CURPOS always requires the
11681 * CURBASE write to arm the update. Additonally
11682 * a write to any of the cursor register will cancel
11683 * an already armed cursor update. Thus leaving out
11684 * the CURBASE write after CURPOS could lead to a
11685 * cursor that doesn't appear to move, or even change
11686 * shape. Thus we always write CURBASE.
11688 * The other registers are armed by by the CURBASE write
11689 * except when the plane is getting enabled at which time
11690 * the CURCNTR write arms the update.
11693 if (INTEL_GEN(dev_priv) >= 9)
11694 skl_write_cursor_wm(plane, crtc_state);
11696 if (plane->cursor.base != base ||
11697 plane->cursor.size != fbc_ctl ||
11698 plane->cursor.cntl != cntl) {
11699 if (HAS_CUR_FBC(dev_priv))
11700 intel_de_write_fw(dev_priv, CUR_FBC_CTL(pipe),
11702 intel_de_write_fw(dev_priv, CURCNTR(pipe), cntl);
11703 intel_de_write_fw(dev_priv, CURPOS(pipe), pos);
11704 intel_de_write_fw(dev_priv, CURBASE(pipe), base);
11706 plane->cursor.base = base;
11707 plane->cursor.size = fbc_ctl;
11708 plane->cursor.cntl = cntl;
11710 intel_de_write_fw(dev_priv, CURPOS(pipe), pos);
11711 intel_de_write_fw(dev_priv, CURBASE(pipe), base);
11714 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11717 static void i9xx_disable_cursor(struct intel_plane *plane,
11718 const struct intel_crtc_state *crtc_state)
11720 i9xx_update_cursor(plane, crtc_state, NULL);
11723 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
11726 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11727 enum intel_display_power_domain power_domain;
11728 intel_wakeref_t wakeref;
11733 * Not 100% correct for planes that can move between pipes,
11734 * but that's only the case for gen2-3 which don't have any
11735 * display power wells.
11737 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
11738 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11742 val = intel_de_read(dev_priv, CURCNTR(plane->pipe));
11744 ret = val & MCURSOR_MODE;
11746 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
11747 *pipe = plane->pipe;
11749 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
11750 MCURSOR_PIPE_SELECT_SHIFT;
11752 intel_display_power_put(dev_priv, power_domain, wakeref);
11757 /* VESA 640x480x72Hz mode to set on the pipe */
11758 static const struct drm_display_mode load_detect_mode = {
11759 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
11760 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
11763 struct drm_framebuffer *
11764 intel_framebuffer_create(struct drm_i915_gem_object *obj,
11765 struct drm_mode_fb_cmd2 *mode_cmd)
11767 struct intel_framebuffer *intel_fb;
11770 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
11772 return ERR_PTR(-ENOMEM);
11774 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
11778 return &intel_fb->base;
11782 return ERR_PTR(ret);
11785 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
11786 struct drm_crtc *crtc)
11788 struct drm_plane *plane;
11789 struct drm_plane_state *plane_state;
11792 ret = drm_atomic_add_affected_planes(state, crtc);
11796 for_each_new_plane_in_state(state, plane, plane_state, i) {
11797 if (plane_state->crtc != crtc)
11800 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
11804 drm_atomic_set_fb_for_plane(plane_state, NULL);
11810 int intel_get_load_detect_pipe(struct drm_connector *connector,
11811 struct intel_load_detect_pipe *old,
11812 struct drm_modeset_acquire_ctx *ctx)
11814 struct intel_crtc *intel_crtc;
11815 struct intel_encoder *intel_encoder =
11816 intel_attached_encoder(to_intel_connector(connector));
11817 struct drm_crtc *possible_crtc;
11818 struct drm_encoder *encoder = &intel_encoder->base;
11819 struct drm_crtc *crtc = NULL;
11820 struct drm_device *dev = encoder->dev;
11821 struct drm_i915_private *dev_priv = to_i915(dev);
11822 struct drm_mode_config *config = &dev->mode_config;
11823 struct drm_atomic_state *state = NULL, *restore_state = NULL;
11824 struct drm_connector_state *connector_state;
11825 struct intel_crtc_state *crtc_state;
11828 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11829 connector->base.id, connector->name,
11830 encoder->base.id, encoder->name);
11832 old->restore_state = NULL;
11834 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex));
11837 * Algorithm gets a little messy:
11839 * - if the connector already has an assigned crtc, use it (but make
11840 * sure it's on first)
11842 * - try to find the first unused crtc that can drive this connector,
11843 * and use that if we find one
11846 /* See if we already have a CRTC for this connector */
11847 if (connector->state->crtc) {
11848 crtc = connector->state->crtc;
11850 ret = drm_modeset_lock(&crtc->mutex, ctx);
11854 /* Make sure the crtc and connector are running */
11858 /* Find an unused one (if possible) */
11859 for_each_crtc(dev, possible_crtc) {
11861 if (!(encoder->possible_crtcs & (1 << i)))
11864 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
11868 if (possible_crtc->state->enable) {
11869 drm_modeset_unlock(&possible_crtc->mutex);
11873 crtc = possible_crtc;
11878 * If we didn't find an unused CRTC, don't use any.
11881 drm_dbg_kms(&dev_priv->drm,
11882 "no pipe available for load-detect\n");
11888 intel_crtc = to_intel_crtc(crtc);
11890 state = drm_atomic_state_alloc(dev);
11891 restore_state = drm_atomic_state_alloc(dev);
11892 if (!state || !restore_state) {
11897 state->acquire_ctx = ctx;
11898 restore_state->acquire_ctx = ctx;
11900 connector_state = drm_atomic_get_connector_state(state, connector);
11901 if (IS_ERR(connector_state)) {
11902 ret = PTR_ERR(connector_state);
11906 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
11910 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
11911 if (IS_ERR(crtc_state)) {
11912 ret = PTR_ERR(crtc_state);
11916 crtc_state->uapi.active = true;
11918 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
11919 &load_detect_mode);
11923 ret = intel_modeset_disable_planes(state, crtc);
11927 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
11929 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
11931 ret = drm_atomic_add_affected_planes(restore_state, crtc);
11933 drm_dbg_kms(&dev_priv->drm,
11934 "Failed to create a copy of old state to restore: %i\n",
11939 ret = drm_atomic_commit(state);
11941 drm_dbg_kms(&dev_priv->drm,
11942 "failed to set mode on load-detect pipe\n");
11946 old->restore_state = restore_state;
11947 drm_atomic_state_put(state);
11949 /* let the connector get through one full cycle before testing */
11950 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
11955 drm_atomic_state_put(state);
11958 if (restore_state) {
11959 drm_atomic_state_put(restore_state);
11960 restore_state = NULL;
11963 if (ret == -EDEADLK)
11969 void intel_release_load_detect_pipe(struct drm_connector *connector,
11970 struct intel_load_detect_pipe *old,
11971 struct drm_modeset_acquire_ctx *ctx)
11973 struct intel_encoder *intel_encoder =
11974 intel_attached_encoder(to_intel_connector(connector));
11975 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev);
11976 struct drm_encoder *encoder = &intel_encoder->base;
11977 struct drm_atomic_state *state = old->restore_state;
11980 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11981 connector->base.id, connector->name,
11982 encoder->base.id, encoder->name);
11987 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
11989 drm_dbg_kms(&i915->drm,
11990 "Couldn't release load detect pipe: %i\n", ret);
11991 drm_atomic_state_put(state);
11994 static int i9xx_pll_refclk(struct drm_device *dev,
11995 const struct intel_crtc_state *pipe_config)
11997 struct drm_i915_private *dev_priv = to_i915(dev);
11998 u32 dpll = pipe_config->dpll_hw_state.dpll;
12000 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
12001 return dev_priv->vbt.lvds_ssc_freq;
12002 else if (HAS_PCH_SPLIT(dev_priv))
12004 else if (!IS_GEN(dev_priv, 2))
12010 /* Returns the clock of the currently programmed mode of the given pipe. */
12011 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
12012 struct intel_crtc_state *pipe_config)
12014 struct drm_device *dev = crtc->base.dev;
12015 struct drm_i915_private *dev_priv = to_i915(dev);
12016 enum pipe pipe = crtc->pipe;
12017 u32 dpll = pipe_config->dpll_hw_state.dpll;
12021 int refclk = i9xx_pll_refclk(dev, pipe_config);
12023 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
12024 fp = pipe_config->dpll_hw_state.fp0;
12026 fp = pipe_config->dpll_hw_state.fp1;
12028 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
12029 if (IS_PINEVIEW(dev_priv)) {
12030 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
12031 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
12033 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
12034 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
12037 if (!IS_GEN(dev_priv, 2)) {
12038 if (IS_PINEVIEW(dev_priv))
12039 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
12040 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
12042 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
12043 DPLL_FPA01_P1_POST_DIV_SHIFT);
12045 switch (dpll & DPLL_MODE_MASK) {
12046 case DPLLB_MODE_DAC_SERIAL:
12047 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
12050 case DPLLB_MODE_LVDS:
12051 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
12055 drm_dbg_kms(&dev_priv->drm,
12056 "Unknown DPLL mode %08x in programmed "
12057 "mode\n", (int)(dpll & DPLL_MODE_MASK));
12061 if (IS_PINEVIEW(dev_priv))
12062 port_clock = pnv_calc_dpll_params(refclk, &clock);
12064 port_clock = i9xx_calc_dpll_params(refclk, &clock);
12066 u32 lvds = IS_I830(dev_priv) ? 0 : intel_de_read(dev_priv,
12068 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
12071 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
12072 DPLL_FPA01_P1_POST_DIV_SHIFT);
12074 if (lvds & LVDS_CLKB_POWER_UP)
12079 if (dpll & PLL_P1_DIVIDE_BY_TWO)
12082 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
12083 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
12085 if (dpll & PLL_P2_DIVIDE_BY_4)
12091 port_clock = i9xx_calc_dpll_params(refclk, &clock);
12095 * This value includes pixel_multiplier. We will use
12096 * port_clock to compute adjusted_mode.crtc_clock in the
12097 * encoder's get_config() function.
12099 pipe_config->port_clock = port_clock;
12102 int intel_dotclock_calculate(int link_freq,
12103 const struct intel_link_m_n *m_n)
12106 * The calculation for the data clock is:
12107 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
12108 * But we want to avoid losing precison if possible, so:
12109 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
12111 * and the link clock is simpler:
12112 * link_clock = (m * link_clock) / n
12118 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
12121 static void ilk_pch_clock_get(struct intel_crtc *crtc,
12122 struct intel_crtc_state *pipe_config)
12124 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12126 /* read out port_clock from the DPLL */
12127 i9xx_crtc_clock_get(crtc, pipe_config);
12130 * In case there is an active pipe without active ports,
12131 * we may need some idea for the dotclock anyway.
12132 * Calculate one based on the FDI configuration.
12134 pipe_config->hw.adjusted_mode.crtc_clock =
12135 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
12136 &pipe_config->fdi_m_n);
12139 static void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
12140 struct intel_crtc *crtc)
12142 memset(crtc_state, 0, sizeof(*crtc_state));
12144 __drm_atomic_helper_crtc_state_reset(&crtc_state->uapi, &crtc->base);
12146 crtc_state->cpu_transcoder = INVALID_TRANSCODER;
12147 crtc_state->master_transcoder = INVALID_TRANSCODER;
12148 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
12149 crtc_state->output_format = INTEL_OUTPUT_FORMAT_INVALID;
12150 crtc_state->scaler_state.scaler_id = -1;
12151 crtc_state->mst_master_transcoder = INVALID_TRANSCODER;
12154 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc)
12156 struct intel_crtc_state *crtc_state;
12158 crtc_state = kmalloc(sizeof(*crtc_state), GFP_KERNEL);
12161 intel_crtc_state_reset(crtc_state, crtc);
12166 /* Returns the currently programmed mode of the given encoder. */
12167 struct drm_display_mode *
12168 intel_encoder_current_mode(struct intel_encoder *encoder)
12170 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
12171 struct intel_crtc_state *crtc_state;
12172 struct drm_display_mode *mode;
12173 struct intel_crtc *crtc;
12176 if (!encoder->get_hw_state(encoder, &pipe))
12179 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12181 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
12185 crtc_state = intel_crtc_state_alloc(crtc);
12191 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
12197 encoder->get_config(encoder, crtc_state);
12199 intel_mode_from_pipe_config(mode, crtc_state);
12206 static void intel_crtc_destroy(struct drm_crtc *crtc)
12208 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12210 drm_crtc_cleanup(crtc);
12215 * intel_wm_need_update - Check whether watermarks need updating
12216 * @cur: current plane state
12217 * @new: new plane state
12219 * Check current plane state versus the new one to determine whether
12220 * watermarks need to be recalculated.
12222 * Returns true or false.
12224 static bool intel_wm_need_update(const struct intel_plane_state *cur,
12225 struct intel_plane_state *new)
12227 /* Update watermarks on tiling or size changes. */
12228 if (new->uapi.visible != cur->uapi.visible)
12231 if (!cur->hw.fb || !new->hw.fb)
12234 if (cur->hw.fb->modifier != new->hw.fb->modifier ||
12235 cur->hw.rotation != new->hw.rotation ||
12236 drm_rect_width(&new->uapi.src) != drm_rect_width(&cur->uapi.src) ||
12237 drm_rect_height(&new->uapi.src) != drm_rect_height(&cur->uapi.src) ||
12238 drm_rect_width(&new->uapi.dst) != drm_rect_width(&cur->uapi.dst) ||
12239 drm_rect_height(&new->uapi.dst) != drm_rect_height(&cur->uapi.dst))
12245 static bool needs_scaling(const struct intel_plane_state *state)
12247 int src_w = drm_rect_width(&state->uapi.src) >> 16;
12248 int src_h = drm_rect_height(&state->uapi.src) >> 16;
12249 int dst_w = drm_rect_width(&state->uapi.dst);
12250 int dst_h = drm_rect_height(&state->uapi.dst);
12252 return (src_w != dst_w || src_h != dst_h);
12255 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
12256 struct intel_crtc_state *crtc_state,
12257 const struct intel_plane_state *old_plane_state,
12258 struct intel_plane_state *plane_state)
12260 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12261 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
12262 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12263 bool mode_changed = needs_modeset(crtc_state);
12264 bool was_crtc_enabled = old_crtc_state->hw.active;
12265 bool is_crtc_enabled = crtc_state->hw.active;
12266 bool turn_off, turn_on, visible, was_visible;
12269 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
12270 ret = skl_update_scaler_plane(crtc_state, plane_state);
12275 was_visible = old_plane_state->uapi.visible;
12276 visible = plane_state->uapi.visible;
12278 if (!was_crtc_enabled && drm_WARN_ON(&dev_priv->drm, was_visible))
12279 was_visible = false;
12282 * Visibility is calculated as if the crtc was on, but
12283 * after scaler setup everything depends on it being off
12284 * when the crtc isn't active.
12286 * FIXME this is wrong for watermarks. Watermarks should also
12287 * be computed as if the pipe would be active. Perhaps move
12288 * per-plane wm computation to the .check_plane() hook, and
12289 * only combine the results from all planes in the current place?
12291 if (!is_crtc_enabled) {
12292 intel_plane_set_invisible(crtc_state, plane_state);
12296 if (!was_visible && !visible)
12299 turn_off = was_visible && (!visible || mode_changed);
12300 turn_on = visible && (!was_visible || mode_changed);
12302 drm_dbg_atomic(&dev_priv->drm,
12303 "[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
12304 crtc->base.base.id, crtc->base.name,
12305 plane->base.base.id, plane->base.name,
12306 was_visible, visible,
12307 turn_off, turn_on, mode_changed);
12310 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
12311 crtc_state->update_wm_pre = true;
12313 /* must disable cxsr around plane enable/disable */
12314 if (plane->id != PLANE_CURSOR)
12315 crtc_state->disable_cxsr = true;
12316 } else if (turn_off) {
12317 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
12318 crtc_state->update_wm_post = true;
12320 /* must disable cxsr around plane enable/disable */
12321 if (plane->id != PLANE_CURSOR)
12322 crtc_state->disable_cxsr = true;
12323 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
12324 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
12325 /* FIXME bollocks */
12326 crtc_state->update_wm_pre = true;
12327 crtc_state->update_wm_post = true;
12331 if (visible || was_visible)
12332 crtc_state->fb_bits |= plane->frontbuffer_bit;
12335 * ILK/SNB DVSACNTR/Sprite Enable
12336 * IVB SPR_CTL/Sprite Enable
12337 * "When in Self Refresh Big FIFO mode, a write to enable the
12338 * plane will be internally buffered and delayed while Big FIFO
12339 * mode is exiting."
12341 * Which means that enabling the sprite can take an extra frame
12342 * when we start in big FIFO mode (LP1+). Thus we need to drop
12343 * down to LP0 and wait for vblank in order to make sure the
12344 * sprite gets enabled on the next vblank after the register write.
12345 * Doing otherwise would risk enabling the sprite one frame after
12346 * we've already signalled flip completion. We can resume LP1+
12347 * once the sprite has been enabled.
12350 * WaCxSRDisabledForSpriteScaling:ivb
12351 * IVB SPR_SCALE/Scaling Enable
12352 * "Low Power watermarks must be disabled for at least one
12353 * frame before enabling sprite scaling, and kept disabled
12354 * until sprite scaling is disabled."
12356 * ILK/SNB DVSASCALE/Scaling Enable
12357 * "When in Self Refresh Big FIFO mode, scaling enable will be
12358 * masked off while Big FIFO mode is exiting."
12360 * Despite the w/a only being listed for IVB we assume that
12361 * the ILK/SNB note has similar ramifications, hence we apply
12362 * the w/a on all three platforms.
12364 * With experimental results seems this is needed also for primary
12365 * plane, not only sprite plane.
12367 if (plane->id != PLANE_CURSOR &&
12368 (IS_GEN_RANGE(dev_priv, 5, 6) ||
12369 IS_IVYBRIDGE(dev_priv)) &&
12370 (turn_on || (!needs_scaling(old_plane_state) &&
12371 needs_scaling(plane_state))))
12372 crtc_state->disable_lp_wm = true;
12377 static bool encoders_cloneable(const struct intel_encoder *a,
12378 const struct intel_encoder *b)
12380 /* masks could be asymmetric, so check both ways */
12381 return a == b || (a->cloneable & (1 << b->type) &&
12382 b->cloneable & (1 << a->type));
12385 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
12386 struct intel_crtc *crtc,
12387 struct intel_encoder *encoder)
12389 struct intel_encoder *source_encoder;
12390 struct drm_connector *connector;
12391 struct drm_connector_state *connector_state;
12394 for_each_new_connector_in_state(state, connector, connector_state, i) {
12395 if (connector_state->crtc != &crtc->base)
12399 to_intel_encoder(connector_state->best_encoder);
12400 if (!encoders_cloneable(encoder, source_encoder))
12407 static int icl_add_linked_planes(struct intel_atomic_state *state)
12409 struct intel_plane *plane, *linked;
12410 struct intel_plane_state *plane_state, *linked_plane_state;
12413 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12414 linked = plane_state->planar_linked_plane;
12419 linked_plane_state = intel_atomic_get_plane_state(state, linked);
12420 if (IS_ERR(linked_plane_state))
12421 return PTR_ERR(linked_plane_state);
12423 WARN_ON(linked_plane_state->planar_linked_plane != plane);
12424 WARN_ON(linked_plane_state->planar_slave == plane_state->planar_slave);
12430 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
12432 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12433 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12434 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
12435 struct intel_plane *plane, *linked;
12436 struct intel_plane_state *plane_state;
12439 if (INTEL_GEN(dev_priv) < 11)
12443 * Destroy all old plane links and make the slave plane invisible
12444 * in the crtc_state->active_planes mask.
12446 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12447 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
12450 plane_state->planar_linked_plane = NULL;
12451 if (plane_state->planar_slave && !plane_state->uapi.visible) {
12452 crtc_state->active_planes &= ~BIT(plane->id);
12453 crtc_state->update_planes |= BIT(plane->id);
12456 plane_state->planar_slave = false;
12459 if (!crtc_state->nv12_planes)
12462 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12463 struct intel_plane_state *linked_state = NULL;
12465 if (plane->pipe != crtc->pipe ||
12466 !(crtc_state->nv12_planes & BIT(plane->id)))
12469 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
12470 if (!icl_is_nv12_y_plane(linked->id))
12473 if (crtc_state->active_planes & BIT(linked->id))
12476 linked_state = intel_atomic_get_plane_state(state, linked);
12477 if (IS_ERR(linked_state))
12478 return PTR_ERR(linked_state);
12483 if (!linked_state) {
12484 drm_dbg_kms(&dev_priv->drm,
12485 "Need %d free Y planes for planar YUV\n",
12486 hweight8(crtc_state->nv12_planes));
12491 plane_state->planar_linked_plane = linked;
12493 linked_state->planar_slave = true;
12494 linked_state->planar_linked_plane = plane;
12495 crtc_state->active_planes |= BIT(linked->id);
12496 crtc_state->update_planes |= BIT(linked->id);
12497 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
12498 linked->base.name, plane->base.name);
12500 /* Copy parameters to slave plane */
12501 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
12502 linked_state->color_ctl = plane_state->color_ctl;
12503 linked_state->view = plane_state->view;
12504 memcpy(linked_state->color_plane, plane_state->color_plane,
12505 sizeof(linked_state->color_plane));
12507 intel_plane_copy_uapi_to_hw_state(linked_state, plane_state);
12508 linked_state->uapi.src = plane_state->uapi.src;
12509 linked_state->uapi.dst = plane_state->uapi.dst;
12511 if (icl_is_hdr_plane(dev_priv, plane->id)) {
12512 if (linked->id == PLANE_SPRITE5)
12513 plane_state->cus_ctl |= PLANE_CUS_PLANE_7;
12514 else if (linked->id == PLANE_SPRITE4)
12515 plane_state->cus_ctl |= PLANE_CUS_PLANE_6;
12517 MISSING_CASE(linked->id);
12524 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
12526 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
12527 struct intel_atomic_state *state =
12528 to_intel_atomic_state(new_crtc_state->uapi.state);
12529 const struct intel_crtc_state *old_crtc_state =
12530 intel_atomic_get_old_crtc_state(state, crtc);
12532 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
12535 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
12537 const struct drm_display_mode *adjusted_mode =
12538 &crtc_state->hw.adjusted_mode;
12540 if (!crtc_state->hw.enable)
12543 return DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8,
12544 adjusted_mode->crtc_clock);
12547 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
12548 const struct intel_cdclk_state *cdclk_state)
12550 const struct drm_display_mode *adjusted_mode =
12551 &crtc_state->hw.adjusted_mode;
12553 if (!crtc_state->hw.enable)
12556 return DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8,
12557 cdclk_state->logical.cdclk);
12560 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
12562 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12563 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12564 const struct drm_display_mode *adjusted_mode =
12565 &crtc_state->hw.adjusted_mode;
12568 if (!crtc_state->hw.enable)
12571 linetime_wm = DIV_ROUND_UP(adjusted_mode->crtc_htotal * 1000 * 8,
12572 crtc_state->pixel_rate);
12574 /* Display WA #1135: BXT:ALL GLK:ALL */
12575 if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled)
12578 return linetime_wm;
12581 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
12582 struct intel_crtc *crtc)
12584 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12585 struct intel_crtc_state *crtc_state =
12586 intel_atomic_get_new_crtc_state(state, crtc);
12587 const struct intel_cdclk_state *cdclk_state;
12589 if (INTEL_GEN(dev_priv) >= 9)
12590 crtc_state->linetime = skl_linetime_wm(crtc_state);
12592 crtc_state->linetime = hsw_linetime_wm(crtc_state);
12594 if (!hsw_crtc_supports_ips(crtc))
12597 cdclk_state = intel_atomic_get_cdclk_state(state);
12598 if (IS_ERR(cdclk_state))
12599 return PTR_ERR(cdclk_state);
12601 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
12607 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
12608 struct intel_crtc *crtc)
12610 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12611 struct intel_crtc_state *crtc_state =
12612 intel_atomic_get_new_crtc_state(state, crtc);
12613 bool mode_changed = needs_modeset(crtc_state);
12616 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
12617 mode_changed && !crtc_state->hw.active)
12618 crtc_state->update_wm_post = true;
12620 if (mode_changed && crtc_state->hw.enable &&
12621 dev_priv->display.crtc_compute_clock &&
12622 !drm_WARN_ON(&dev_priv->drm, crtc_state->shared_dpll)) {
12623 ret = dev_priv->display.crtc_compute_clock(crtc, crtc_state);
12629 * May need to update pipe gamma enable bits
12630 * when C8 planes are getting enabled/disabled.
12632 if (c8_planes_changed(crtc_state))
12633 crtc_state->uapi.color_mgmt_changed = true;
12635 if (mode_changed || crtc_state->update_pipe ||
12636 crtc_state->uapi.color_mgmt_changed) {
12637 ret = intel_color_check(crtc_state);
12642 if (dev_priv->display.compute_pipe_wm) {
12643 ret = dev_priv->display.compute_pipe_wm(crtc_state);
12645 drm_dbg_kms(&dev_priv->drm,
12646 "Target pipe watermarks are invalid\n");
12651 if (dev_priv->display.compute_intermediate_wm) {
12652 if (drm_WARN_ON(&dev_priv->drm,
12653 !dev_priv->display.compute_pipe_wm))
12657 * Calculate 'intermediate' watermarks that satisfy both the
12658 * old state and the new state. We can program these
12661 ret = dev_priv->display.compute_intermediate_wm(crtc_state);
12663 drm_dbg_kms(&dev_priv->drm,
12664 "No valid intermediate pipe watermarks are possible\n");
12669 if (INTEL_GEN(dev_priv) >= 9) {
12670 if (mode_changed || crtc_state->update_pipe) {
12671 ret = skl_update_scaler_crtc(crtc_state);
12676 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
12681 if (HAS_IPS(dev_priv)) {
12682 ret = hsw_compute_ips_config(crtc_state);
12687 if (INTEL_GEN(dev_priv) >= 9 ||
12688 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
12689 ret = hsw_compute_linetime_wm(state, crtc);
12698 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
12700 struct intel_connector *connector;
12701 struct drm_connector_list_iter conn_iter;
12703 drm_connector_list_iter_begin(dev, &conn_iter);
12704 for_each_intel_connector_iter(connector, &conn_iter) {
12705 if (connector->base.state->crtc)
12706 drm_connector_put(&connector->base);
12708 if (connector->base.encoder) {
12709 connector->base.state->best_encoder =
12710 connector->base.encoder;
12711 connector->base.state->crtc =
12712 connector->base.encoder->crtc;
12714 drm_connector_get(&connector->base);
12716 connector->base.state->best_encoder = NULL;
12717 connector->base.state->crtc = NULL;
12720 drm_connector_list_iter_end(&conn_iter);
12724 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
12725 struct intel_crtc_state *pipe_config)
12727 struct drm_connector *connector = conn_state->connector;
12728 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
12729 const struct drm_display_info *info = &connector->display_info;
12732 switch (conn_state->max_bpc) {
12749 if (bpp < pipe_config->pipe_bpp) {
12750 drm_dbg_kms(&i915->drm,
12751 "[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
12752 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
12753 connector->base.id, connector->name,
12754 bpp, 3 * info->bpc,
12755 3 * conn_state->max_requested_bpc,
12756 pipe_config->pipe_bpp);
12758 pipe_config->pipe_bpp = bpp;
12765 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
12766 struct intel_crtc_state *pipe_config)
12768 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12769 struct drm_atomic_state *state = pipe_config->uapi.state;
12770 struct drm_connector *connector;
12771 struct drm_connector_state *connector_state;
12774 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
12775 IS_CHERRYVIEW(dev_priv)))
12777 else if (INTEL_GEN(dev_priv) >= 5)
12782 pipe_config->pipe_bpp = bpp;
12784 /* Clamp display bpp to connector max bpp */
12785 for_each_new_connector_in_state(state, connector, connector_state, i) {
12788 if (connector_state->crtc != &crtc->base)
12791 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
12799 static void intel_dump_crtc_timings(struct drm_i915_private *i915,
12800 const struct drm_display_mode *mode)
12802 drm_dbg_kms(&i915->drm, "crtc timings: %d %d %d %d %d %d %d %d %d, "
12803 "type: 0x%x flags: 0x%x\n",
12805 mode->crtc_hdisplay, mode->crtc_hsync_start,
12806 mode->crtc_hsync_end, mode->crtc_htotal,
12807 mode->crtc_vdisplay, mode->crtc_vsync_start,
12808 mode->crtc_vsync_end, mode->crtc_vtotal,
12809 mode->type, mode->flags);
12813 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
12814 const char *id, unsigned int lane_count,
12815 const struct intel_link_m_n *m_n)
12817 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
12819 drm_dbg_kms(&i915->drm,
12820 "%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12822 m_n->gmch_m, m_n->gmch_n,
12823 m_n->link_m, m_n->link_n, m_n->tu);
12827 intel_dump_infoframe(struct drm_i915_private *dev_priv,
12828 const union hdmi_infoframe *frame)
12830 if (!drm_debug_enabled(DRM_UT_KMS))
12833 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
12836 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
12838 static const char * const output_type_str[] = {
12839 OUTPUT_TYPE(UNUSED),
12840 OUTPUT_TYPE(ANALOG),
12844 OUTPUT_TYPE(TVOUT),
12850 OUTPUT_TYPE(DP_MST),
12855 static void snprintf_output_types(char *buf, size_t len,
12856 unsigned int output_types)
12863 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
12866 if ((output_types & BIT(i)) == 0)
12869 r = snprintf(str, len, "%s%s",
12870 str != buf ? "," : "", output_type_str[i]);
12876 output_types &= ~BIT(i);
12879 WARN_ON_ONCE(output_types != 0);
12882 static const char * const output_format_str[] = {
12883 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
12884 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
12885 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
12886 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
12889 static const char *output_formats(enum intel_output_format format)
12891 if (format >= ARRAY_SIZE(output_format_str))
12892 format = INTEL_OUTPUT_FORMAT_INVALID;
12893 return output_format_str[format];
12896 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
12898 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
12899 struct drm_i915_private *i915 = to_i915(plane->base.dev);
12900 const struct drm_framebuffer *fb = plane_state->hw.fb;
12901 struct drm_format_name_buf format_name;
12904 drm_dbg_kms(&i915->drm,
12905 "[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12906 plane->base.base.id, plane->base.name,
12907 yesno(plane_state->uapi.visible));
12911 drm_dbg_kms(&i915->drm,
12912 "[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s, visible: %s\n",
12913 plane->base.base.id, plane->base.name,
12914 fb->base.id, fb->width, fb->height,
12915 drm_get_format_name(fb->format->format, &format_name),
12916 yesno(plane_state->uapi.visible));
12917 drm_dbg_kms(&i915->drm, "\trotation: 0x%x, scaler: %d\n",
12918 plane_state->hw.rotation, plane_state->scaler_id);
12919 if (plane_state->uapi.visible)
12920 drm_dbg_kms(&i915->drm,
12921 "\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
12922 DRM_RECT_FP_ARG(&plane_state->uapi.src),
12923 DRM_RECT_ARG(&plane_state->uapi.dst));
12926 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
12927 struct intel_atomic_state *state,
12928 const char *context)
12930 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
12931 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12932 const struct intel_plane_state *plane_state;
12933 struct intel_plane *plane;
12937 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s] enable: %s %s\n",
12938 crtc->base.base.id, crtc->base.name,
12939 yesno(pipe_config->hw.enable), context);
12941 if (!pipe_config->hw.enable)
12944 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
12945 drm_dbg_kms(&dev_priv->drm,
12946 "active: %s, output_types: %s (0x%x), output format: %s\n",
12947 yesno(pipe_config->hw.active),
12948 buf, pipe_config->output_types,
12949 output_formats(pipe_config->output_format));
12951 drm_dbg_kms(&dev_priv->drm,
12952 "cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
12953 transcoder_name(pipe_config->cpu_transcoder),
12954 pipe_config->pipe_bpp, pipe_config->dither);
12956 drm_dbg_kms(&dev_priv->drm,
12957 "port sync: master transcoder: %s, slave transcoder bitmask = 0x%x\n",
12958 transcoder_name(pipe_config->master_transcoder),
12959 pipe_config->sync_mode_slaves_mask);
12961 if (pipe_config->has_pch_encoder)
12962 intel_dump_m_n_config(pipe_config, "fdi",
12963 pipe_config->fdi_lanes,
12964 &pipe_config->fdi_m_n);
12966 if (intel_crtc_has_dp_encoder(pipe_config)) {
12967 intel_dump_m_n_config(pipe_config, "dp m_n",
12968 pipe_config->lane_count, &pipe_config->dp_m_n);
12969 if (pipe_config->has_drrs)
12970 intel_dump_m_n_config(pipe_config, "dp m2_n2",
12971 pipe_config->lane_count,
12972 &pipe_config->dp_m2_n2);
12975 drm_dbg_kms(&dev_priv->drm,
12976 "audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
12977 pipe_config->has_audio, pipe_config->has_infoframe,
12978 pipe_config->infoframes.enable);
12980 if (pipe_config->infoframes.enable &
12981 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
12982 drm_dbg_kms(&dev_priv->drm, "GCP: 0x%x\n",
12983 pipe_config->infoframes.gcp);
12984 if (pipe_config->infoframes.enable &
12985 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
12986 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
12987 if (pipe_config->infoframes.enable &
12988 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
12989 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
12990 if (pipe_config->infoframes.enable &
12991 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
12992 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
12994 drm_dbg_kms(&dev_priv->drm, "requested mode:\n");
12995 drm_mode_debug_printmodeline(&pipe_config->hw.mode);
12996 drm_dbg_kms(&dev_priv->drm, "adjusted mode:\n");
12997 drm_mode_debug_printmodeline(&pipe_config->hw.adjusted_mode);
12998 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.adjusted_mode);
12999 drm_dbg_kms(&dev_priv->drm,
13000 "port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
13001 pipe_config->port_clock,
13002 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
13003 pipe_config->pixel_rate);
13005 drm_dbg_kms(&dev_priv->drm, "linetime: %d, ips linetime: %d\n",
13006 pipe_config->linetime, pipe_config->ips_linetime);
13008 if (INTEL_GEN(dev_priv) >= 9)
13009 drm_dbg_kms(&dev_priv->drm,
13010 "num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
13012 pipe_config->scaler_state.scaler_users,
13013 pipe_config->scaler_state.scaler_id);
13015 if (HAS_GMCH(dev_priv))
13016 drm_dbg_kms(&dev_priv->drm,
13017 "gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
13018 pipe_config->gmch_pfit.control,
13019 pipe_config->gmch_pfit.pgm_ratios,
13020 pipe_config->gmch_pfit.lvds_border_bits);
13022 drm_dbg_kms(&dev_priv->drm,
13023 "pch pfit: pos: 0x%08x, size: 0x%08x, %s, force thru: %s\n",
13024 pipe_config->pch_pfit.pos,
13025 pipe_config->pch_pfit.size,
13026 enableddisabled(pipe_config->pch_pfit.enabled),
13027 yesno(pipe_config->pch_pfit.force_thru));
13029 drm_dbg_kms(&dev_priv->drm, "ips: %i, double wide: %i\n",
13030 pipe_config->ips_enabled, pipe_config->double_wide);
13032 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
13034 if (IS_CHERRYVIEW(dev_priv))
13035 drm_dbg_kms(&dev_priv->drm,
13036 "cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
13037 pipe_config->cgm_mode, pipe_config->gamma_mode,
13038 pipe_config->gamma_enable, pipe_config->csc_enable);
13040 drm_dbg_kms(&dev_priv->drm,
13041 "csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
13042 pipe_config->csc_mode, pipe_config->gamma_mode,
13043 pipe_config->gamma_enable, pipe_config->csc_enable);
13045 drm_dbg_kms(&dev_priv->drm, "MST master transcoder: %s\n",
13046 transcoder_name(pipe_config->mst_master_transcoder));
13052 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
13053 if (plane->pipe == crtc->pipe)
13054 intel_dump_plane_state(plane_state);
13058 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
13060 struct drm_device *dev = state->base.dev;
13061 struct drm_connector *connector;
13062 struct drm_connector_list_iter conn_iter;
13063 unsigned int used_ports = 0;
13064 unsigned int used_mst_ports = 0;
13068 * We're going to peek into connector->state,
13069 * hence connection_mutex must be held.
13071 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
13074 * Walk the connector list instead of the encoder
13075 * list to detect the problem on ddi platforms
13076 * where there's just one encoder per digital port.
13078 drm_connector_list_iter_begin(dev, &conn_iter);
13079 drm_for_each_connector_iter(connector, &conn_iter) {
13080 struct drm_connector_state *connector_state;
13081 struct intel_encoder *encoder;
13084 drm_atomic_get_new_connector_state(&state->base,
13086 if (!connector_state)
13087 connector_state = connector->state;
13089 if (!connector_state->best_encoder)
13092 encoder = to_intel_encoder(connector_state->best_encoder);
13094 drm_WARN_ON(dev, !connector_state->crtc);
13096 switch (encoder->type) {
13097 case INTEL_OUTPUT_DDI:
13098 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
13100 /* else, fall through */
13101 case INTEL_OUTPUT_DP:
13102 case INTEL_OUTPUT_HDMI:
13103 case INTEL_OUTPUT_EDP:
13104 /* the same port mustn't appear more than once */
13105 if (used_ports & BIT(encoder->port))
13108 used_ports |= BIT(encoder->port);
13110 case INTEL_OUTPUT_DP_MST:
13112 1 << encoder->port;
13118 drm_connector_list_iter_end(&conn_iter);
13120 /* can't mix MST and SST/HDMI on the same port */
13121 if (used_ports & used_mst_ports)
13128 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_crtc_state *crtc_state)
13130 intel_crtc_copy_color_blobs(crtc_state);
13134 intel_crtc_copy_uapi_to_hw_state(struct intel_crtc_state *crtc_state)
13136 crtc_state->hw.enable = crtc_state->uapi.enable;
13137 crtc_state->hw.active = crtc_state->uapi.active;
13138 crtc_state->hw.mode = crtc_state->uapi.mode;
13139 crtc_state->hw.adjusted_mode = crtc_state->uapi.adjusted_mode;
13140 intel_crtc_copy_uapi_to_hw_state_nomodeset(crtc_state);
13143 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state)
13145 crtc_state->uapi.enable = crtc_state->hw.enable;
13146 crtc_state->uapi.active = crtc_state->hw.active;
13147 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0);
13149 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode;
13151 /* copy color blobs to uapi */
13152 drm_property_replace_blob(&crtc_state->uapi.degamma_lut,
13153 crtc_state->hw.degamma_lut);
13154 drm_property_replace_blob(&crtc_state->uapi.gamma_lut,
13155 crtc_state->hw.gamma_lut);
13156 drm_property_replace_blob(&crtc_state->uapi.ctm,
13157 crtc_state->hw.ctm);
13161 intel_crtc_prepare_cleared_state(struct intel_crtc_state *crtc_state)
13163 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
13164 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13165 struct intel_crtc_state *saved_state;
13167 saved_state = intel_crtc_state_alloc(crtc);
13171 /* free the old crtc_state->hw members */
13172 intel_crtc_free_hw_state(crtc_state);
13174 /* FIXME: before the switch to atomic started, a new pipe_config was
13175 * kzalloc'd. Code that depends on any field being zero should be
13176 * fixed, so that the crtc_state can be safely duplicated. For now,
13177 * only fields that are know to not cause problems are preserved. */
13179 saved_state->uapi = crtc_state->uapi;
13180 saved_state->scaler_state = crtc_state->scaler_state;
13181 saved_state->shared_dpll = crtc_state->shared_dpll;
13182 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
13183 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
13184 sizeof(saved_state->icl_port_dplls));
13185 saved_state->crc_enabled = crtc_state->crc_enabled;
13186 if (IS_G4X(dev_priv) ||
13187 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13188 saved_state->wm = crtc_state->wm;
13190 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
13191 kfree(saved_state);
13193 intel_crtc_copy_uapi_to_hw_state(crtc_state);
13199 intel_modeset_pipe_config(struct intel_crtc_state *pipe_config)
13201 struct drm_crtc *crtc = pipe_config->uapi.crtc;
13202 struct drm_atomic_state *state = pipe_config->uapi.state;
13203 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
13204 struct drm_connector *connector;
13205 struct drm_connector_state *connector_state;
13206 int base_bpp, ret, i;
13209 pipe_config->cpu_transcoder =
13210 (enum transcoder) to_intel_crtc(crtc)->pipe;
13213 * Sanitize sync polarity flags based on requested ones. If neither
13214 * positive or negative polarity is requested, treat this as meaning
13215 * negative polarity.
13217 if (!(pipe_config->hw.adjusted_mode.flags &
13218 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
13219 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
13221 if (!(pipe_config->hw.adjusted_mode.flags &
13222 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
13223 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
13225 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
13230 base_bpp = pipe_config->pipe_bpp;
13233 * Determine the real pipe dimensions. Note that stereo modes can
13234 * increase the actual pipe size due to the frame doubling and
13235 * insertion of additional space for blanks between the frame. This
13236 * is stored in the crtc timings. We use the requested mode to do this
13237 * computation to clearly distinguish it from the adjusted mode, which
13238 * can be changed by the connectors in the below retry loop.
13240 drm_mode_get_hv_timing(&pipe_config->hw.mode,
13241 &pipe_config->pipe_src_w,
13242 &pipe_config->pipe_src_h);
13244 for_each_new_connector_in_state(state, connector, connector_state, i) {
13245 struct intel_encoder *encoder =
13246 to_intel_encoder(connector_state->best_encoder);
13248 if (connector_state->crtc != crtc)
13251 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
13252 drm_dbg_kms(&i915->drm,
13253 "rejecting invalid cloning configuration\n");
13258 * Determine output_types before calling the .compute_config()
13259 * hooks so that the hooks can use this information safely.
13261 if (encoder->compute_output_type)
13262 pipe_config->output_types |=
13263 BIT(encoder->compute_output_type(encoder, pipe_config,
13266 pipe_config->output_types |= BIT(encoder->type);
13270 /* Ensure the port clock defaults are reset when retrying. */
13271 pipe_config->port_clock = 0;
13272 pipe_config->pixel_multiplier = 1;
13274 /* Fill in default crtc timings, allow encoders to overwrite them. */
13275 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
13276 CRTC_STEREO_DOUBLE);
13278 /* Pass our mode to the connectors and the CRTC to give them a chance to
13279 * adjust it according to limitations or connector properties, and also
13280 * a chance to reject the mode entirely.
13282 for_each_new_connector_in_state(state, connector, connector_state, i) {
13283 struct intel_encoder *encoder =
13284 to_intel_encoder(connector_state->best_encoder);
13286 if (connector_state->crtc != crtc)
13289 ret = encoder->compute_config(encoder, pipe_config,
13292 if (ret != -EDEADLK)
13293 drm_dbg_kms(&i915->drm,
13294 "Encoder config failure: %d\n",
13300 /* Set default port clock if not overwritten by the encoder. Needs to be
13301 * done afterwards in case the encoder adjusts the mode. */
13302 if (!pipe_config->port_clock)
13303 pipe_config->port_clock = pipe_config->hw.adjusted_mode.crtc_clock
13304 * pipe_config->pixel_multiplier;
13306 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
13307 if (ret == -EDEADLK)
13310 drm_dbg_kms(&i915->drm, "CRTC fixup failed\n");
13314 if (ret == RETRY) {
13315 if (drm_WARN(&i915->drm, !retry,
13316 "loop in pipe configuration computation\n"))
13319 drm_dbg_kms(&i915->drm, "CRTC bw constrained, retrying\n");
13321 goto encoder_retry;
13324 /* Dithering seems to not pass-through bits correctly when it should, so
13325 * only enable it on 6bpc panels and when its not a compliance
13326 * test requesting 6bpc video pattern.
13328 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
13329 !pipe_config->dither_force_disable;
13330 drm_dbg_kms(&i915->drm,
13331 "hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
13332 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
13335 * Make drm_calc_timestamping_constants in
13336 * drm_atomic_helper_update_legacy_modeset_state() happy
13338 pipe_config->uapi.adjusted_mode = pipe_config->hw.adjusted_mode;
13344 intel_modeset_pipe_config_late(struct intel_crtc_state *crtc_state)
13346 struct intel_atomic_state *state =
13347 to_intel_atomic_state(crtc_state->uapi.state);
13348 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
13349 struct drm_connector_state *conn_state;
13350 struct drm_connector *connector;
13353 for_each_new_connector_in_state(&state->base, connector,
13355 struct intel_encoder *encoder =
13356 to_intel_encoder(conn_state->best_encoder);
13359 if (conn_state->crtc != &crtc->base ||
13360 !encoder->compute_config_late)
13363 ret = encoder->compute_config_late(encoder, crtc_state,
13372 bool intel_fuzzy_clock_check(int clock1, int clock2)
13376 if (clock1 == clock2)
13379 if (!clock1 || !clock2)
13382 diff = abs(clock1 - clock2);
13384 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
13391 intel_compare_m_n(unsigned int m, unsigned int n,
13392 unsigned int m2, unsigned int n2,
13395 if (m == m2 && n == n2)
13398 if (exact || !m || !n || !m2 || !n2)
13401 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
13408 } else if (n < n2) {
13418 return intel_fuzzy_clock_check(m, m2);
13422 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
13423 const struct intel_link_m_n *m2_n2,
13426 return m_n->tu == m2_n2->tu &&
13427 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
13428 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
13429 intel_compare_m_n(m_n->link_m, m_n->link_n,
13430 m2_n2->link_m, m2_n2->link_n, exact);
13434 intel_compare_infoframe(const union hdmi_infoframe *a,
13435 const union hdmi_infoframe *b)
13437 return memcmp(a, b, sizeof(*a)) == 0;
13441 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
13442 bool fastset, const char *name,
13443 const union hdmi_infoframe *a,
13444 const union hdmi_infoframe *b)
13447 if (!drm_debug_enabled(DRM_UT_KMS))
13450 drm_dbg_kms(&dev_priv->drm,
13451 "fastset mismatch in %s infoframe\n", name);
13452 drm_dbg_kms(&dev_priv->drm, "expected:\n");
13453 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
13454 drm_dbg_kms(&dev_priv->drm, "found:\n");
13455 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
13457 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
13458 drm_err(&dev_priv->drm, "expected:\n");
13459 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
13460 drm_err(&dev_priv->drm, "found:\n");
13461 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
13465 static void __printf(4, 5)
13466 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
13467 const char *name, const char *format, ...)
13469 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
13470 struct va_format vaf;
13473 va_start(args, format);
13478 drm_dbg_kms(&i915->drm,
13479 "[CRTC:%d:%s] fastset mismatch in %s %pV\n",
13480 crtc->base.base.id, crtc->base.name, name, &vaf);
13482 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
13483 crtc->base.base.id, crtc->base.name, name, &vaf);
13488 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
13490 if (i915_modparams.fastboot != -1)
13491 return i915_modparams.fastboot;
13493 /* Enable fastboot by default on Skylake and newer */
13494 if (INTEL_GEN(dev_priv) >= 9)
13497 /* Enable fastboot by default on VLV and CHV */
13498 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13501 /* Disabled by default on all others */
13506 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
13507 const struct intel_crtc_state *pipe_config,
13510 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
13511 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
13514 bool fixup_inherited = fastset &&
13515 (current_config->hw.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
13516 !(pipe_config->hw.mode.private_flags & I915_MODE_FLAG_INHERITED);
13518 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
13519 drm_dbg_kms(&dev_priv->drm,
13520 "initial modeset and fastboot not set\n");
13524 #define PIPE_CONF_CHECK_X(name) do { \
13525 if (current_config->name != pipe_config->name) { \
13526 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13527 "(expected 0x%08x, found 0x%08x)", \
13528 current_config->name, \
13529 pipe_config->name); \
13534 #define PIPE_CONF_CHECK_I(name) do { \
13535 if (current_config->name != pipe_config->name) { \
13536 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13537 "(expected %i, found %i)", \
13538 current_config->name, \
13539 pipe_config->name); \
13544 #define PIPE_CONF_CHECK_BOOL(name) do { \
13545 if (current_config->name != pipe_config->name) { \
13546 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13547 "(expected %s, found %s)", \
13548 yesno(current_config->name), \
13549 yesno(pipe_config->name)); \
13555 * Checks state where we only read out the enabling, but not the entire
13556 * state itself (like full infoframes or ELD for audio). These states
13557 * require a full modeset on bootup to fix up.
13559 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
13560 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
13561 PIPE_CONF_CHECK_BOOL(name); \
13563 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13564 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
13565 yesno(current_config->name), \
13566 yesno(pipe_config->name)); \
13571 #define PIPE_CONF_CHECK_P(name) do { \
13572 if (current_config->name != pipe_config->name) { \
13573 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13574 "(expected %p, found %p)", \
13575 current_config->name, \
13576 pipe_config->name); \
13581 #define PIPE_CONF_CHECK_M_N(name) do { \
13582 if (!intel_compare_link_m_n(¤t_config->name, \
13583 &pipe_config->name,\
13585 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13586 "(expected tu %i gmch %i/%i link %i/%i, " \
13587 "found tu %i, gmch %i/%i link %i/%i)", \
13588 current_config->name.tu, \
13589 current_config->name.gmch_m, \
13590 current_config->name.gmch_n, \
13591 current_config->name.link_m, \
13592 current_config->name.link_n, \
13593 pipe_config->name.tu, \
13594 pipe_config->name.gmch_m, \
13595 pipe_config->name.gmch_n, \
13596 pipe_config->name.link_m, \
13597 pipe_config->name.link_n); \
13602 /* This is required for BDW+ where there is only one set of registers for
13603 * switching between high and low RR.
13604 * This macro can be used whenever a comparison has to be made between one
13605 * hw state and multiple sw state variables.
13607 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
13608 if (!intel_compare_link_m_n(¤t_config->name, \
13609 &pipe_config->name, !fastset) && \
13610 !intel_compare_link_m_n(¤t_config->alt_name, \
13611 &pipe_config->name, !fastset)) { \
13612 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13613 "(expected tu %i gmch %i/%i link %i/%i, " \
13614 "or tu %i gmch %i/%i link %i/%i, " \
13615 "found tu %i, gmch %i/%i link %i/%i)", \
13616 current_config->name.tu, \
13617 current_config->name.gmch_m, \
13618 current_config->name.gmch_n, \
13619 current_config->name.link_m, \
13620 current_config->name.link_n, \
13621 current_config->alt_name.tu, \
13622 current_config->alt_name.gmch_m, \
13623 current_config->alt_name.gmch_n, \
13624 current_config->alt_name.link_m, \
13625 current_config->alt_name.link_n, \
13626 pipe_config->name.tu, \
13627 pipe_config->name.gmch_m, \
13628 pipe_config->name.gmch_n, \
13629 pipe_config->name.link_m, \
13630 pipe_config->name.link_n); \
13635 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
13636 if ((current_config->name ^ pipe_config->name) & (mask)) { \
13637 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13638 "(%x) (expected %i, found %i)", \
13640 current_config->name & (mask), \
13641 pipe_config->name & (mask)); \
13646 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
13647 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
13648 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13649 "(expected %i, found %i)", \
13650 current_config->name, \
13651 pipe_config->name); \
13656 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
13657 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
13658 &pipe_config->infoframes.name)) { \
13659 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
13660 ¤t_config->infoframes.name, \
13661 &pipe_config->infoframes.name); \
13666 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
13667 if (current_config->name1 != pipe_config->name1) { \
13668 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
13669 "(expected %i, found %i, won't compare lut values)", \
13670 current_config->name1, \
13671 pipe_config->name1); \
13674 if (!intel_color_lut_equal(current_config->name2, \
13675 pipe_config->name2, pipe_config->name1, \
13676 bit_precision)) { \
13677 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
13678 "hw_state doesn't match sw_state"); \
13684 #define PIPE_CONF_QUIRK(quirk) \
13685 ((current_config->quirks | pipe_config->quirks) & (quirk))
13687 PIPE_CONF_CHECK_I(cpu_transcoder);
13689 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
13690 PIPE_CONF_CHECK_I(fdi_lanes);
13691 PIPE_CONF_CHECK_M_N(fdi_m_n);
13693 PIPE_CONF_CHECK_I(lane_count);
13694 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
13696 if (INTEL_GEN(dev_priv) < 8) {
13697 PIPE_CONF_CHECK_M_N(dp_m_n);
13699 if (current_config->has_drrs)
13700 PIPE_CONF_CHECK_M_N(dp_m2_n2);
13702 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
13704 PIPE_CONF_CHECK_X(output_types);
13706 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hdisplay);
13707 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_htotal);
13708 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_start);
13709 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_end);
13710 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_start);
13711 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_end);
13713 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vdisplay);
13714 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vtotal);
13715 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_start);
13716 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_end);
13717 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_start);
13718 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_end);
13720 PIPE_CONF_CHECK_I(pixel_multiplier);
13721 PIPE_CONF_CHECK_I(output_format);
13722 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
13723 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
13724 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13725 PIPE_CONF_CHECK_BOOL(limited_color_range);
13727 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
13728 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
13729 PIPE_CONF_CHECK_BOOL(has_infoframe);
13730 PIPE_CONF_CHECK_BOOL(fec_enable);
13732 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
13734 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13735 DRM_MODE_FLAG_INTERLACE);
13737 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
13738 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13739 DRM_MODE_FLAG_PHSYNC);
13740 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13741 DRM_MODE_FLAG_NHSYNC);
13742 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13743 DRM_MODE_FLAG_PVSYNC);
13744 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13745 DRM_MODE_FLAG_NVSYNC);
13748 PIPE_CONF_CHECK_X(gmch_pfit.control);
13749 /* pfit ratios are autocomputed by the hw on gen4+ */
13750 if (INTEL_GEN(dev_priv) < 4)
13751 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
13752 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
13755 * Changing the EDP transcoder input mux
13756 * (A_ONOFF vs. A_ON) requires a full modeset.
13758 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
13761 PIPE_CONF_CHECK_I(pipe_src_w);
13762 PIPE_CONF_CHECK_I(pipe_src_h);
13764 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
13765 if (current_config->pch_pfit.enabled) {
13766 PIPE_CONF_CHECK_X(pch_pfit.pos);
13767 PIPE_CONF_CHECK_X(pch_pfit.size);
13770 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
13771 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
13773 PIPE_CONF_CHECK_X(gamma_mode);
13774 if (IS_CHERRYVIEW(dev_priv))
13775 PIPE_CONF_CHECK_X(cgm_mode);
13777 PIPE_CONF_CHECK_X(csc_mode);
13778 PIPE_CONF_CHECK_BOOL(gamma_enable);
13779 PIPE_CONF_CHECK_BOOL(csc_enable);
13781 PIPE_CONF_CHECK_I(linetime);
13782 PIPE_CONF_CHECK_I(ips_linetime);
13784 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
13786 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
13789 PIPE_CONF_CHECK_BOOL(double_wide);
13791 PIPE_CONF_CHECK_P(shared_dpll);
13792 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
13793 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
13794 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
13795 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
13796 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
13797 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
13798 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
13799 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
13800 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
13801 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
13802 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
13803 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
13804 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
13805 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
13806 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
13807 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
13808 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
13809 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
13810 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
13811 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
13812 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
13813 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
13814 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
13815 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
13816 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
13817 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
13818 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
13819 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
13820 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
13821 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
13822 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
13824 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
13825 PIPE_CONF_CHECK_X(dsi_pll.div);
13827 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
13828 PIPE_CONF_CHECK_I(pipe_bpp);
13830 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
13831 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
13833 PIPE_CONF_CHECK_I(min_voltage_level);
13835 PIPE_CONF_CHECK_X(infoframes.enable);
13836 PIPE_CONF_CHECK_X(infoframes.gcp);
13837 PIPE_CONF_CHECK_INFOFRAME(avi);
13838 PIPE_CONF_CHECK_INFOFRAME(spd);
13839 PIPE_CONF_CHECK_INFOFRAME(hdmi);
13840 PIPE_CONF_CHECK_INFOFRAME(drm);
13842 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
13843 PIPE_CONF_CHECK_I(master_transcoder);
13845 PIPE_CONF_CHECK_I(dsc.compression_enable);
13846 PIPE_CONF_CHECK_I(dsc.dsc_split);
13847 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
13849 PIPE_CONF_CHECK_I(mst_master_transcoder);
13851 #undef PIPE_CONF_CHECK_X
13852 #undef PIPE_CONF_CHECK_I
13853 #undef PIPE_CONF_CHECK_BOOL
13854 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
13855 #undef PIPE_CONF_CHECK_P
13856 #undef PIPE_CONF_CHECK_FLAGS
13857 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
13858 #undef PIPE_CONF_CHECK_COLOR_LUT
13859 #undef PIPE_CONF_QUIRK
13864 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
13865 const struct intel_crtc_state *pipe_config)
13867 if (pipe_config->has_pch_encoder) {
13868 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
13869 &pipe_config->fdi_m_n);
13870 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
13873 * FDI already provided one idea for the dotclock.
13874 * Yell if the encoder disagrees.
13876 drm_WARN(&dev_priv->drm,
13877 !intel_fuzzy_clock_check(fdi_dotclock, dotclock),
13878 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
13879 fdi_dotclock, dotclock);
13883 static void verify_wm_state(struct intel_crtc *crtc,
13884 struct intel_crtc_state *new_crtc_state)
13886 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13887 struct skl_hw_state {
13888 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
13889 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
13890 struct skl_pipe_wm wm;
13892 struct skl_pipe_wm *sw_wm;
13893 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
13894 u8 hw_enabled_slices;
13895 const enum pipe pipe = crtc->pipe;
13896 int plane, level, max_level = ilk_wm_max_level(dev_priv);
13898 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->hw.active)
13901 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
13905 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
13906 sw_wm = &new_crtc_state->wm.skl.optimal;
13908 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
13910 hw_enabled_slices = intel_enabled_dbuf_slices_mask(dev_priv);
13912 if (INTEL_GEN(dev_priv) >= 11 &&
13913 hw_enabled_slices != dev_priv->enabled_dbuf_slices_mask)
13914 drm_err(&dev_priv->drm,
13915 "mismatch in DBUF Slices (expected 0x%x, got 0x%x)\n",
13916 dev_priv->enabled_dbuf_slices_mask,
13917 hw_enabled_slices);
13920 for_each_universal_plane(dev_priv, pipe, plane) {
13921 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13923 hw_plane_wm = &hw->wm.planes[plane];
13924 sw_plane_wm = &sw_wm->planes[plane];
13927 for (level = 0; level <= max_level; level++) {
13928 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13929 &sw_plane_wm->wm[level]))
13932 drm_err(&dev_priv->drm,
13933 "mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13934 pipe_name(pipe), plane + 1, level,
13935 sw_plane_wm->wm[level].plane_en,
13936 sw_plane_wm->wm[level].plane_res_b,
13937 sw_plane_wm->wm[level].plane_res_l,
13938 hw_plane_wm->wm[level].plane_en,
13939 hw_plane_wm->wm[level].plane_res_b,
13940 hw_plane_wm->wm[level].plane_res_l);
13943 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13944 &sw_plane_wm->trans_wm)) {
13945 drm_err(&dev_priv->drm,
13946 "mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13947 pipe_name(pipe), plane + 1,
13948 sw_plane_wm->trans_wm.plane_en,
13949 sw_plane_wm->trans_wm.plane_res_b,
13950 sw_plane_wm->trans_wm.plane_res_l,
13951 hw_plane_wm->trans_wm.plane_en,
13952 hw_plane_wm->trans_wm.plane_res_b,
13953 hw_plane_wm->trans_wm.plane_res_l);
13957 hw_ddb_entry = &hw->ddb_y[plane];
13958 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
13960 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
13961 drm_err(&dev_priv->drm,
13962 "mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
13963 pipe_name(pipe), plane + 1,
13964 sw_ddb_entry->start, sw_ddb_entry->end,
13965 hw_ddb_entry->start, hw_ddb_entry->end);
13971 * If the cursor plane isn't active, we may not have updated it's ddb
13972 * allocation. In that case since the ddb allocation will be updated
13973 * once the plane becomes visible, we can skip this check
13976 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
13978 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
13979 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
13982 for (level = 0; level <= max_level; level++) {
13983 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
13984 &sw_plane_wm->wm[level]))
13987 drm_err(&dev_priv->drm,
13988 "mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
13989 pipe_name(pipe), level,
13990 sw_plane_wm->wm[level].plane_en,
13991 sw_plane_wm->wm[level].plane_res_b,
13992 sw_plane_wm->wm[level].plane_res_l,
13993 hw_plane_wm->wm[level].plane_en,
13994 hw_plane_wm->wm[level].plane_res_b,
13995 hw_plane_wm->wm[level].plane_res_l);
13998 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
13999 &sw_plane_wm->trans_wm)) {
14000 drm_err(&dev_priv->drm,
14001 "mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
14003 sw_plane_wm->trans_wm.plane_en,
14004 sw_plane_wm->trans_wm.plane_res_b,
14005 sw_plane_wm->trans_wm.plane_res_l,
14006 hw_plane_wm->trans_wm.plane_en,
14007 hw_plane_wm->trans_wm.plane_res_b,
14008 hw_plane_wm->trans_wm.plane_res_l);
14012 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
14013 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
14015 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
14016 drm_err(&dev_priv->drm,
14017 "mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
14019 sw_ddb_entry->start, sw_ddb_entry->end,
14020 hw_ddb_entry->start, hw_ddb_entry->end);
14028 verify_connector_state(struct intel_atomic_state *state,
14029 struct intel_crtc *crtc)
14031 struct drm_connector *connector;
14032 struct drm_connector_state *new_conn_state;
14035 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
14036 struct drm_encoder *encoder = connector->encoder;
14037 struct intel_crtc_state *crtc_state = NULL;
14039 if (new_conn_state->crtc != &crtc->base)
14043 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
14045 intel_connector_verify_state(crtc_state, new_conn_state);
14047 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
14048 "connector's atomic encoder doesn't match legacy encoder\n");
14053 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
14055 struct intel_encoder *encoder;
14056 struct drm_connector *connector;
14057 struct drm_connector_state *old_conn_state, *new_conn_state;
14060 for_each_intel_encoder(&dev_priv->drm, encoder) {
14061 bool enabled = false, found = false;
14064 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s]\n",
14065 encoder->base.base.id,
14066 encoder->base.name);
14068 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
14069 new_conn_state, i) {
14070 if (old_conn_state->best_encoder == &encoder->base)
14073 if (new_conn_state->best_encoder != &encoder->base)
14075 found = enabled = true;
14077 I915_STATE_WARN(new_conn_state->crtc !=
14078 encoder->base.crtc,
14079 "connector's crtc doesn't match encoder crtc\n");
14085 I915_STATE_WARN(!!encoder->base.crtc != enabled,
14086 "encoder's enabled state mismatch "
14087 "(expected %i, found %i)\n",
14088 !!encoder->base.crtc, enabled);
14090 if (!encoder->base.crtc) {
14093 active = encoder->get_hw_state(encoder, &pipe);
14094 I915_STATE_WARN(active,
14095 "encoder detached but still enabled on pipe %c.\n",
14102 verify_crtc_state(struct intel_crtc *crtc,
14103 struct intel_crtc_state *old_crtc_state,
14104 struct intel_crtc_state *new_crtc_state)
14106 struct drm_device *dev = crtc->base.dev;
14107 struct drm_i915_private *dev_priv = to_i915(dev);
14108 struct intel_encoder *encoder;
14109 struct intel_crtc_state *pipe_config = old_crtc_state;
14110 struct drm_atomic_state *state = old_crtc_state->uapi.state;
14113 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
14114 intel_crtc_free_hw_state(old_crtc_state);
14115 intel_crtc_state_reset(old_crtc_state, crtc);
14116 old_crtc_state->uapi.state = state;
14118 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s]\n", crtc->base.base.id,
14121 active = dev_priv->display.get_pipe_config(crtc, pipe_config);
14123 /* we keep both pipes enabled on 830 */
14124 if (IS_I830(dev_priv))
14125 active = new_crtc_state->hw.active;
14127 I915_STATE_WARN(new_crtc_state->hw.active != active,
14128 "crtc active state doesn't match with hw state "
14129 "(expected %i, found %i)\n",
14130 new_crtc_state->hw.active, active);
14132 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
14133 "transitional active state does not match atomic hw state "
14134 "(expected %i, found %i)\n",
14135 new_crtc_state->hw.active, crtc->active);
14137 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
14140 active = encoder->get_hw_state(encoder, &pipe);
14141 I915_STATE_WARN(active != new_crtc_state->hw.active,
14142 "[ENCODER:%i] active %i with crtc active %i\n",
14143 encoder->base.base.id, active,
14144 new_crtc_state->hw.active);
14146 I915_STATE_WARN(active && crtc->pipe != pipe,
14147 "Encoder connected to wrong pipe %c\n",
14151 encoder->get_config(encoder, pipe_config);
14154 intel_crtc_compute_pixel_rate(pipe_config);
14156 if (!new_crtc_state->hw.active)
14159 intel_pipe_config_sanity_check(dev_priv, pipe_config);
14161 if (!intel_pipe_config_compare(new_crtc_state,
14162 pipe_config, false)) {
14163 I915_STATE_WARN(1, "pipe state doesn't match!\n");
14164 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
14165 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
14170 intel_verify_planes(struct intel_atomic_state *state)
14172 struct intel_plane *plane;
14173 const struct intel_plane_state *plane_state;
14176 for_each_new_intel_plane_in_state(state, plane,
14178 assert_plane(plane, plane_state->planar_slave ||
14179 plane_state->uapi.visible);
14183 verify_single_dpll_state(struct drm_i915_private *dev_priv,
14184 struct intel_shared_dpll *pll,
14185 struct intel_crtc *crtc,
14186 struct intel_crtc_state *new_crtc_state)
14188 struct intel_dpll_hw_state dpll_hw_state;
14189 unsigned int crtc_mask;
14192 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
14194 drm_dbg_kms(&dev_priv->drm, "%s\n", pll->info->name);
14196 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
14198 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
14199 I915_STATE_WARN(!pll->on && pll->active_mask,
14200 "pll in active use but not on in sw tracking\n");
14201 I915_STATE_WARN(pll->on && !pll->active_mask,
14202 "pll is on but not used by any active crtc\n");
14203 I915_STATE_WARN(pll->on != active,
14204 "pll on state mismatch (expected %i, found %i)\n",
14209 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
14210 "more active pll users than references: %x vs %x\n",
14211 pll->active_mask, pll->state.crtc_mask);
14216 crtc_mask = drm_crtc_mask(&crtc->base);
14218 if (new_crtc_state->hw.active)
14219 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
14220 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
14221 pipe_name(crtc->pipe), pll->active_mask);
14223 I915_STATE_WARN(pll->active_mask & crtc_mask,
14224 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
14225 pipe_name(crtc->pipe), pll->active_mask);
14227 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
14228 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
14229 crtc_mask, pll->state.crtc_mask);
14231 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
14233 sizeof(dpll_hw_state)),
14234 "pll hw state mismatch\n");
14238 verify_shared_dpll_state(struct intel_crtc *crtc,
14239 struct intel_crtc_state *old_crtc_state,
14240 struct intel_crtc_state *new_crtc_state)
14242 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14244 if (new_crtc_state->shared_dpll)
14245 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
14247 if (old_crtc_state->shared_dpll &&
14248 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
14249 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
14250 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
14252 I915_STATE_WARN(pll->active_mask & crtc_mask,
14253 "pll active mismatch (didn't expect pipe %c in active mask)\n",
14254 pipe_name(crtc->pipe));
14255 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
14256 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
14257 pipe_name(crtc->pipe));
14262 intel_modeset_verify_crtc(struct intel_crtc *crtc,
14263 struct intel_atomic_state *state,
14264 struct intel_crtc_state *old_crtc_state,
14265 struct intel_crtc_state *new_crtc_state)
14267 if (!needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
14270 verify_wm_state(crtc, new_crtc_state);
14271 verify_connector_state(state, crtc);
14272 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
14273 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
14277 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
14281 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++)
14282 verify_single_dpll_state(dev_priv,
14283 &dev_priv->dpll.shared_dplls[i],
14288 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
14289 struct intel_atomic_state *state)
14291 verify_encoder_state(dev_priv, state);
14292 verify_connector_state(state, NULL);
14293 verify_disabled_dpll_state(dev_priv);
14297 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
14299 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
14300 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14301 const struct drm_display_mode *adjusted_mode =
14302 &crtc_state->hw.adjusted_mode;
14304 drm_calc_timestamping_constants(&crtc->base, adjusted_mode);
14307 * The scanline counter increments at the leading edge of hsync.
14309 * On most platforms it starts counting from vtotal-1 on the
14310 * first active line. That means the scanline counter value is
14311 * always one less than what we would expect. Ie. just after
14312 * start of vblank, which also occurs at start of hsync (on the
14313 * last active line), the scanline counter will read vblank_start-1.
14315 * On gen2 the scanline counter starts counting from 1 instead
14316 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
14317 * to keep the value positive), instead of adding one.
14319 * On HSW+ the behaviour of the scanline counter depends on the output
14320 * type. For DP ports it behaves like most other platforms, but on HDMI
14321 * there's an extra 1 line difference. So we need to add two instead of
14322 * one to the value.
14324 * On VLV/CHV DSI the scanline counter would appear to increment
14325 * approx. 1/3 of a scanline before start of vblank. Unfortunately
14326 * that means we can't tell whether we're in vblank or not while
14327 * we're on that particular line. We must still set scanline_offset
14328 * to 1 so that the vblank timestamps come out correct when we query
14329 * the scanline counter from within the vblank interrupt handler.
14330 * However if queried just before the start of vblank we'll get an
14331 * answer that's slightly in the future.
14333 if (IS_GEN(dev_priv, 2)) {
14336 vtotal = adjusted_mode->crtc_vtotal;
14337 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
14340 crtc->scanline_offset = vtotal - 1;
14341 } else if (HAS_DDI(dev_priv) &&
14342 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
14343 crtc->scanline_offset = 2;
14345 crtc->scanline_offset = 1;
14349 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
14351 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14352 struct intel_crtc_state *new_crtc_state;
14353 struct intel_crtc *crtc;
14356 if (!dev_priv->display.crtc_compute_clock)
14359 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14360 if (!needs_modeset(new_crtc_state))
14363 intel_release_shared_dplls(state, crtc);
14368 * This implements the workaround described in the "notes" section of the mode
14369 * set sequence documentation. When going from no pipes or single pipe to
14370 * multiple pipes, and planes are enabled after the pipe, we need to wait at
14371 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
14373 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
14375 struct intel_crtc_state *crtc_state;
14376 struct intel_crtc *crtc;
14377 struct intel_crtc_state *first_crtc_state = NULL;
14378 struct intel_crtc_state *other_crtc_state = NULL;
14379 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
14382 /* look at all crtc's that are going to be enabled in during modeset */
14383 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14384 if (!crtc_state->hw.active ||
14385 !needs_modeset(crtc_state))
14388 if (first_crtc_state) {
14389 other_crtc_state = crtc_state;
14392 first_crtc_state = crtc_state;
14393 first_pipe = crtc->pipe;
14397 /* No workaround needed? */
14398 if (!first_crtc_state)
14401 /* w/a possibly needed, check how many crtc's are already enabled. */
14402 for_each_intel_crtc(state->base.dev, crtc) {
14403 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
14404 if (IS_ERR(crtc_state))
14405 return PTR_ERR(crtc_state);
14407 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
14409 if (!crtc_state->hw.active ||
14410 needs_modeset(crtc_state))
14413 /* 2 or more enabled crtcs means no need for w/a */
14414 if (enabled_pipe != INVALID_PIPE)
14417 enabled_pipe = crtc->pipe;
14420 if (enabled_pipe != INVALID_PIPE)
14421 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
14422 else if (other_crtc_state)
14423 other_crtc_state->hsw_workaround_pipe = first_pipe;
14428 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
14431 const struct intel_crtc_state *crtc_state;
14432 struct intel_crtc *crtc;
14435 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14436 if (crtc_state->hw.active)
14437 active_pipes |= BIT(crtc->pipe);
14439 active_pipes &= ~BIT(crtc->pipe);
14442 return active_pipes;
14445 static int intel_modeset_checks(struct intel_atomic_state *state)
14447 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14450 state->modeset = true;
14451 state->active_pipes = intel_calc_active_pipes(state, dev_priv->active_pipes);
14453 state->active_pipe_changes = state->active_pipes ^ dev_priv->active_pipes;
14455 if (state->active_pipe_changes) {
14456 ret = _intel_atomic_lock_global_state(state);
14461 ret = intel_modeset_calc_cdclk(state);
14465 intel_modeset_clear_plls(state);
14467 if (IS_HASWELL(dev_priv))
14468 return hsw_mode_set_planes_workaround(state);
14474 * Handle calculation of various watermark data at the end of the atomic check
14475 * phase. The code here should be run after the per-crtc and per-plane 'check'
14476 * handlers to ensure that all derived state has been updated.
14478 static int calc_watermark_data(struct intel_atomic_state *state)
14480 struct drm_device *dev = state->base.dev;
14481 struct drm_i915_private *dev_priv = to_i915(dev);
14483 /* Is there platform-specific watermark information to calculate? */
14484 if (dev_priv->display.compute_global_watermarks)
14485 return dev_priv->display.compute_global_watermarks(state);
14490 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
14491 struct intel_crtc_state *new_crtc_state)
14493 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
14496 new_crtc_state->uapi.mode_changed = false;
14497 new_crtc_state->update_pipe = true;
14500 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
14501 struct intel_crtc_state *new_crtc_state)
14504 * If we're not doing the full modeset we want to
14505 * keep the current M/N values as they may be
14506 * sufficiently different to the computed values
14507 * to cause problems.
14509 * FIXME: should really copy more fuzzy state here
14511 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
14512 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
14513 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
14514 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
14517 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
14518 struct intel_crtc *crtc,
14521 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14522 struct intel_plane *plane;
14524 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
14525 struct intel_plane_state *plane_state;
14527 if ((plane_ids_mask & BIT(plane->id)) == 0)
14530 plane_state = intel_atomic_get_plane_state(state, plane);
14531 if (IS_ERR(plane_state))
14532 return PTR_ERR(plane_state);
14538 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
14540 /* See {hsw,vlv,ivb}_plane_ratio() */
14541 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
14542 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
14543 IS_IVYBRIDGE(dev_priv);
14546 static int intel_atomic_check_planes(struct intel_atomic_state *state,
14547 bool *need_cdclk_calc)
14549 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14550 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14551 struct intel_plane_state *plane_state;
14552 struct intel_plane *plane;
14553 struct intel_crtc *crtc;
14556 ret = icl_add_linked_planes(state);
14560 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14561 ret = intel_plane_atomic_check(state, plane);
14563 drm_dbg_atomic(&dev_priv->drm,
14564 "[PLANE:%d:%s] atomic driver check failed\n",
14565 plane->base.base.id, plane->base.name);
14570 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14571 new_crtc_state, i) {
14572 u8 old_active_planes, new_active_planes;
14574 ret = icl_check_nv12_planes(new_crtc_state);
14579 * On some platforms the number of active planes affects
14580 * the planes' minimum cdclk calculation. Add such planes
14581 * to the state before we compute the minimum cdclk.
14583 if (!active_planes_affects_min_cdclk(dev_priv))
14586 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14587 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14589 if (hweight8(old_active_planes) == hweight8(new_active_planes))
14592 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
14598 * active_planes bitmask has been updated, and potentially
14599 * affected planes are part of the state. We can now
14600 * compute the minimum cdclk for each plane.
14602 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14603 ret = intel_plane_calc_min_cdclk(state, plane, need_cdclk_calc);
14611 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
14613 struct intel_crtc_state *crtc_state;
14614 struct intel_crtc *crtc;
14617 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14618 int ret = intel_crtc_atomic_check(state, crtc);
14619 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
14621 drm_dbg_atomic(&i915->drm,
14622 "[CRTC:%d:%s] atomic driver check failed\n",
14623 crtc->base.base.id, crtc->base.name);
14631 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
14634 const struct intel_crtc_state *new_crtc_state;
14635 struct intel_crtc *crtc;
14638 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14639 if (new_crtc_state->hw.enable &&
14640 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
14641 needs_modeset(new_crtc_state))
14649 * intel_atomic_check - validate state object
14651 * @_state: state to validate
14653 static int intel_atomic_check(struct drm_device *dev,
14654 struct drm_atomic_state *_state)
14656 struct drm_i915_private *dev_priv = to_i915(dev);
14657 struct intel_atomic_state *state = to_intel_atomic_state(_state);
14658 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14659 struct intel_cdclk_state *new_cdclk_state;
14660 struct intel_crtc *crtc;
14662 bool any_ms = false;
14664 /* Catch I915_MODE_FLAG_INHERITED */
14665 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14666 new_crtc_state, i) {
14667 if (new_crtc_state->uapi.mode.private_flags !=
14668 old_crtc_state->uapi.mode.private_flags)
14669 new_crtc_state->uapi.mode_changed = true;
14672 ret = drm_atomic_helper_check_modeset(dev, &state->base);
14676 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14677 new_crtc_state, i) {
14678 if (!needs_modeset(new_crtc_state)) {
14680 intel_crtc_copy_uapi_to_hw_state_nomodeset(new_crtc_state);
14685 ret = intel_crtc_prepare_cleared_state(new_crtc_state);
14689 if (!new_crtc_state->hw.enable)
14692 ret = intel_modeset_pipe_config(new_crtc_state);
14697 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14698 new_crtc_state, i) {
14699 if (!needs_modeset(new_crtc_state))
14702 ret = intel_modeset_pipe_config_late(new_crtc_state);
14706 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
14710 * Check if fastset is allowed by external dependencies like other
14711 * pipes and transcoders.
14713 * Right now it only forces a fullmodeset when the MST master
14714 * transcoder did not changed but the pipe of the master transcoder
14715 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
14716 * in case of port synced crtcs, if one of the synced crtcs
14717 * needs a full modeset, all other synced crtcs should be
14718 * forced a full modeset.
14720 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14721 if (!new_crtc_state->hw.enable || needs_modeset(new_crtc_state))
14724 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
14725 enum transcoder master = new_crtc_state->mst_master_transcoder;
14727 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
14728 new_crtc_state->uapi.mode_changed = true;
14729 new_crtc_state->update_pipe = false;
14733 if (is_trans_port_sync_mode(new_crtc_state)) {
14734 u8 trans = new_crtc_state->sync_mode_slaves_mask;
14736 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
14737 trans |= BIT(new_crtc_state->master_transcoder);
14739 if (intel_cpu_transcoders_need_modeset(state, trans)) {
14740 new_crtc_state->uapi.mode_changed = true;
14741 new_crtc_state->update_pipe = false;
14746 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14747 new_crtc_state, i) {
14748 if (needs_modeset(new_crtc_state)) {
14753 if (!new_crtc_state->update_pipe)
14756 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
14759 if (any_ms && !check_digital_port_conflicts(state)) {
14760 drm_dbg_kms(&dev_priv->drm,
14761 "rejecting conflicting digital port configuration\n");
14766 ret = drm_dp_mst_atomic_check(&state->base);
14770 ret = intel_atomic_check_planes(state, &any_ms);
14774 new_cdclk_state = intel_atomic_get_new_cdclk_state(state);
14775 if (new_cdclk_state && new_cdclk_state->force_min_cdclk_changed)
14779 * distrust_bios_wm will force a full dbuf recomputation
14780 * but the hardware state will only get updated accordingly
14781 * if state->modeset==true. Hence distrust_bios_wm==true &&
14782 * state->modeset==false is an invalid combination which
14783 * would cause the hardware and software dbuf state to get
14784 * out of sync. We must prevent that.
14786 * FIXME clean up this mess and introduce better
14787 * state tracking for dbuf.
14789 if (dev_priv->wm.distrust_bios_wm)
14793 ret = intel_modeset_checks(state);
14798 ret = intel_atomic_check_crtcs(state);
14802 intel_fbc_choose_crtc(dev_priv, state);
14803 ret = calc_watermark_data(state);
14807 ret = intel_bw_atomic_check(state);
14811 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14812 new_crtc_state, i) {
14813 if (!needs_modeset(new_crtc_state) &&
14814 !new_crtc_state->update_pipe)
14817 intel_dump_pipe_config(new_crtc_state, state,
14818 needs_modeset(new_crtc_state) ?
14819 "[modeset]" : "[fastset]");
14825 if (ret == -EDEADLK)
14829 * FIXME would probably be nice to know which crtc specifically
14830 * caused the failure, in cases where we can pinpoint it.
14832 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14834 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
14839 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
14841 return drm_atomic_helper_prepare_planes(state->base.dev,
14845 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
14847 struct drm_device *dev = crtc->base.dev;
14848 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
14850 if (!vblank->max_vblank_count)
14851 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
14853 return crtc->base.funcs->get_vblank_counter(&crtc->base);
14856 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14857 struct intel_crtc_state *crtc_state)
14859 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14861 if (!IS_GEN(dev_priv, 2) || crtc_state->active_planes)
14862 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14864 if (crtc_state->has_pch_encoder) {
14865 enum pipe pch_transcoder =
14866 intel_crtc_pch_transcoder(crtc);
14868 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14872 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
14873 const struct intel_crtc_state *new_crtc_state)
14875 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
14876 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14879 * Update pipe size and adjust fitter if needed: the reason for this is
14880 * that in compute_mode_changes we check the native mode (not the pfit
14881 * mode) to see if we can flip rather than do a full mode set. In the
14882 * fastboot case, we'll flip, but if we don't update the pipesrc and
14883 * pfit state, we'll end up with a big fb scanned out into the wrong
14886 intel_set_pipe_src_size(new_crtc_state);
14888 /* on skylake this is done by detaching scalers */
14889 if (INTEL_GEN(dev_priv) >= 9) {
14890 skl_detach_scalers(new_crtc_state);
14892 if (new_crtc_state->pch_pfit.enabled)
14893 skl_pfit_enable(new_crtc_state);
14894 } else if (HAS_PCH_SPLIT(dev_priv)) {
14895 if (new_crtc_state->pch_pfit.enabled)
14896 ilk_pfit_enable(new_crtc_state);
14897 else if (old_crtc_state->pch_pfit.enabled)
14898 ilk_pfit_disable(old_crtc_state);
14902 * The register is supposedly single buffered so perhaps
14903 * not 100% correct to do this here. But SKL+ calculate
14904 * this based on the adjust pixel rate so pfit changes do
14905 * affect it and so it must be updated for fastsets.
14906 * HSW/BDW only really need this here for fastboot, after
14907 * that the value should not change without a full modeset.
14909 if (INTEL_GEN(dev_priv) >= 9 ||
14910 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14911 hsw_set_linetime_wm(new_crtc_state);
14913 if (INTEL_GEN(dev_priv) >= 11)
14914 icl_set_pipe_chicken(crtc);
14917 static void commit_pipe_config(struct intel_atomic_state *state,
14918 struct intel_crtc *crtc)
14920 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14921 const struct intel_crtc_state *old_crtc_state =
14922 intel_atomic_get_old_crtc_state(state, crtc);
14923 const struct intel_crtc_state *new_crtc_state =
14924 intel_atomic_get_new_crtc_state(state, crtc);
14925 bool modeset = needs_modeset(new_crtc_state);
14928 * During modesets pipe configuration was programmed as the
14929 * CRTC was enabled.
14932 if (new_crtc_state->uapi.color_mgmt_changed ||
14933 new_crtc_state->update_pipe)
14934 intel_color_commit(new_crtc_state);
14936 if (INTEL_GEN(dev_priv) >= 9)
14937 skl_detach_scalers(new_crtc_state);
14939 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
14940 bdw_set_pipemisc(new_crtc_state);
14942 if (new_crtc_state->update_pipe)
14943 intel_pipe_fastset(old_crtc_state, new_crtc_state);
14946 if (dev_priv->display.atomic_update_watermarks)
14947 dev_priv->display.atomic_update_watermarks(state, crtc);
14950 static void intel_enable_crtc(struct intel_atomic_state *state,
14951 struct intel_crtc *crtc)
14953 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14954 const struct intel_crtc_state *new_crtc_state =
14955 intel_atomic_get_new_crtc_state(state, crtc);
14957 if (!needs_modeset(new_crtc_state))
14960 intel_crtc_update_active_timings(new_crtc_state);
14962 dev_priv->display.crtc_enable(state, crtc);
14964 /* vblanks work again, re-enable pipe CRC. */
14965 intel_crtc_enable_pipe_crc(crtc);
14968 static void intel_update_crtc(struct intel_atomic_state *state,
14969 struct intel_crtc *crtc)
14971 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14972 const struct intel_crtc_state *old_crtc_state =
14973 intel_atomic_get_old_crtc_state(state, crtc);
14974 struct intel_crtc_state *new_crtc_state =
14975 intel_atomic_get_new_crtc_state(state, crtc);
14976 bool modeset = needs_modeset(new_crtc_state);
14979 if (new_crtc_state->preload_luts &&
14980 (new_crtc_state->uapi.color_mgmt_changed ||
14981 new_crtc_state->update_pipe))
14982 intel_color_load_luts(new_crtc_state);
14984 intel_pre_plane_update(state, crtc);
14986 if (new_crtc_state->update_pipe)
14987 intel_encoders_update_pipe(state, crtc);
14990 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
14991 intel_fbc_disable(crtc);
14993 intel_fbc_enable(state, crtc);
14995 /* Perform vblank evasion around commit operation */
14996 intel_pipe_update_start(new_crtc_state);
14998 commit_pipe_config(state, crtc);
15000 if (INTEL_GEN(dev_priv) >= 9)
15001 skl_update_planes_on_crtc(state, crtc);
15003 i9xx_update_planes_on_crtc(state, crtc);
15005 intel_pipe_update_end(new_crtc_state);
15008 * We usually enable FIFO underrun interrupts as part of the
15009 * CRTC enable sequence during modesets. But when we inherit a
15010 * valid pipe configuration from the BIOS we need to take care
15011 * of enabling them on the CRTC's first fastset.
15013 if (new_crtc_state->update_pipe && !modeset &&
15014 old_crtc_state->hw.mode.private_flags & I915_MODE_FLAG_INHERITED)
15015 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
15019 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
15020 struct intel_crtc_state *old_crtc_state,
15021 struct intel_crtc_state *new_crtc_state,
15022 struct intel_crtc *crtc)
15024 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15026 intel_crtc_disable_planes(state, crtc);
15029 * We need to disable pipe CRC before disabling the pipe,
15030 * or we race against vblank off.
15032 intel_crtc_disable_pipe_crc(crtc);
15034 dev_priv->display.crtc_disable(state, crtc);
15035 crtc->active = false;
15036 intel_fbc_disable(crtc);
15037 intel_disable_shared_dpll(old_crtc_state);
15039 /* FIXME unify this for all platforms */
15040 if (!new_crtc_state->hw.active &&
15041 !HAS_GMCH(dev_priv) &&
15042 dev_priv->display.initial_watermarks)
15043 dev_priv->display.initial_watermarks(state, crtc);
15046 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
15048 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
15049 struct intel_crtc *crtc;
15053 /* Only disable port sync and MST slaves */
15054 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15055 new_crtc_state, i) {
15056 if (!needs_modeset(new_crtc_state))
15059 if (!old_crtc_state->hw.active)
15062 /* In case of Transcoder port Sync master slave CRTCs can be
15063 * assigned in any order and we need to make sure that
15064 * slave CRTCs are disabled first and then master CRTC since
15065 * Slave vblanks are masked till Master Vblanks.
15067 if (!is_trans_port_sync_slave(old_crtc_state) &&
15068 !intel_dp_mst_is_slave_trans(old_crtc_state))
15071 intel_pre_plane_update(state, crtc);
15072 intel_old_crtc_state_disables(state, old_crtc_state,
15073 new_crtc_state, crtc);
15074 handled |= BIT(crtc->pipe);
15077 /* Disable everything else left on */
15078 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15079 new_crtc_state, i) {
15080 if (!needs_modeset(new_crtc_state) ||
15081 (handled & BIT(crtc->pipe)))
15084 intel_pre_plane_update(state, crtc);
15085 if (old_crtc_state->hw.active)
15086 intel_old_crtc_state_disables(state, old_crtc_state,
15087 new_crtc_state, crtc);
15091 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
15093 struct intel_crtc_state *new_crtc_state;
15094 struct intel_crtc *crtc;
15097 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15098 if (!new_crtc_state->hw.active)
15101 intel_enable_crtc(state, crtc);
15102 intel_update_crtc(state, crtc);
15106 static void intel_set_dp_tp_ctl_normal(struct intel_atomic_state *state,
15107 struct intel_crtc *crtc)
15109 struct drm_connector *uninitialized_var(conn);
15110 struct drm_connector_state *conn_state;
15111 struct intel_dp *intel_dp;
15114 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
15115 if (conn_state->crtc == &crtc->base)
15118 intel_dp = intel_attached_dp(to_intel_connector(conn));
15119 intel_dp_stop_link_train(intel_dp);
15122 static void intel_update_trans_port_sync_crtcs(struct intel_atomic_state *state,
15123 struct intel_crtc *crtc)
15125 struct drm_i915_private *i915 = to_i915(state->base.dev);
15126 const struct intel_crtc_state *new_slave_crtc_state;
15127 const struct intel_crtc_state *new_crtc_state =
15128 intel_atomic_get_new_crtc_state(state, crtc);
15129 struct intel_crtc *slave_crtc;
15132 for_each_new_intel_crtc_in_state(state, slave_crtc,
15133 new_slave_crtc_state, i) {
15134 if (new_slave_crtc_state->master_transcoder !=
15135 new_crtc_state->cpu_transcoder)
15138 drm_dbg_kms(&i915->drm,
15139 "Updating transcoder port sync slave [CRTC:%d:%s]\n",
15140 slave_crtc->base.base.id, slave_crtc->base.name);
15142 intel_enable_crtc(state, slave_crtc);
15145 drm_dbg_kms(&i915->drm,
15146 "Updating transcoder port sync master [CRTC:%d:%s]\n",
15147 crtc->base.base.id, crtc->base.name);
15149 intel_enable_crtc(state, crtc);
15151 for_each_new_intel_crtc_in_state(state, slave_crtc,
15152 new_slave_crtc_state, i) {
15153 if (new_slave_crtc_state->master_transcoder !=
15154 new_crtc_state->cpu_transcoder)
15157 intel_set_dp_tp_ctl_normal(state, slave_crtc);
15160 usleep_range(200, 400);
15161 intel_set_dp_tp_ctl_normal(state, crtc);
15164 static void icl_dbuf_slice_pre_update(struct intel_atomic_state *state)
15166 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15167 u8 hw_enabled_slices = dev_priv->enabled_dbuf_slices_mask;
15168 u8 required_slices = state->enabled_dbuf_slices_mask;
15169 u8 slices_union = hw_enabled_slices | required_slices;
15171 /* If 2nd DBuf slice required, enable it here */
15172 if (INTEL_GEN(dev_priv) >= 11 && slices_union != hw_enabled_slices)
15173 icl_dbuf_slices_update(dev_priv, slices_union);
15176 static void icl_dbuf_slice_post_update(struct intel_atomic_state *state)
15178 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15179 u8 hw_enabled_slices = dev_priv->enabled_dbuf_slices_mask;
15180 u8 required_slices = state->enabled_dbuf_slices_mask;
15182 /* If 2nd DBuf slice is no more required disable it */
15183 if (INTEL_GEN(dev_priv) >= 11 && required_slices != hw_enabled_slices)
15184 icl_dbuf_slices_update(dev_priv, required_slices);
15187 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
15189 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15190 struct intel_crtc *crtc;
15191 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
15192 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
15193 u8 update_pipes = 0, modeset_pipes = 0;
15196 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15197 enum pipe pipe = crtc->pipe;
15199 if (!new_crtc_state->hw.active)
15202 /* ignore allocations for crtc's that have been turned off. */
15203 if (!needs_modeset(new_crtc_state)) {
15204 entries[pipe] = old_crtc_state->wm.skl.ddb;
15205 update_pipes |= BIT(pipe);
15207 modeset_pipes |= BIT(pipe);
15212 * Whenever the number of active pipes changes, we need to make sure we
15213 * update the pipes in the right order so that their ddb allocations
15214 * never overlap with each other between CRTC updates. Otherwise we'll
15215 * cause pipe underruns and other bad stuff.
15217 * So first lets enable all pipes that do not need a fullmodeset as
15218 * those don't have any external dependency.
15220 while (update_pipes) {
15221 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15222 new_crtc_state, i) {
15223 enum pipe pipe = crtc->pipe;
15225 if ((update_pipes & BIT(pipe)) == 0)
15228 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
15229 entries, I915_MAX_PIPES, pipe))
15232 entries[pipe] = new_crtc_state->wm.skl.ddb;
15233 update_pipes &= ~BIT(pipe);
15235 intel_update_crtc(state, crtc);
15238 * If this is an already active pipe, it's DDB changed,
15239 * and this isn't the last pipe that needs updating
15240 * then we need to wait for a vblank to pass for the
15241 * new ddb allocation to take effect.
15243 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
15244 &old_crtc_state->wm.skl.ddb) &&
15245 (update_pipes | modeset_pipes))
15246 intel_wait_for_vblank(dev_priv, pipe);
15250 update_pipes = modeset_pipes;
15253 * Enable all pipes that needs a modeset and do not depends on other
15256 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15257 enum pipe pipe = crtc->pipe;
15259 if ((modeset_pipes & BIT(pipe)) == 0)
15262 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
15263 is_trans_port_sync_slave(new_crtc_state))
15266 modeset_pipes &= ~BIT(pipe);
15268 if (is_trans_port_sync_mode(new_crtc_state)) {
15269 const struct intel_crtc_state *new_slave_crtc_state;
15270 struct intel_crtc *slave_crtc;
15273 intel_update_trans_port_sync_crtcs(state, crtc);
15275 for_each_new_intel_crtc_in_state(state, slave_crtc,
15276 new_slave_crtc_state, i) {
15277 if (new_slave_crtc_state->master_transcoder !=
15278 new_crtc_state->cpu_transcoder)
15281 modeset_pipes &= ~BIT(slave_crtc->pipe);
15284 intel_enable_crtc(state, crtc);
15289 * Then we enable all remaining pipes that depend on other
15290 * pipes, right now it is only MST slaves as both port sync
15291 * slave and master are enabled together
15293 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15294 enum pipe pipe = crtc->pipe;
15296 if ((modeset_pipes & BIT(pipe)) == 0)
15299 modeset_pipes &= ~BIT(pipe);
15301 intel_enable_crtc(state, crtc);
15305 * Finally we do the plane updates/etc. for all pipes that got enabled.
15307 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15308 enum pipe pipe = crtc->pipe;
15310 if ((update_pipes & BIT(pipe)) == 0)
15313 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
15314 entries, I915_MAX_PIPES, pipe));
15316 entries[pipe] = new_crtc_state->wm.skl.ddb;
15317 update_pipes &= ~BIT(pipe);
15319 intel_update_crtc(state, crtc);
15322 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
15323 drm_WARN_ON(&dev_priv->drm, update_pipes);
15326 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
15328 struct intel_atomic_state *state, *next;
15329 struct llist_node *freed;
15331 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
15332 llist_for_each_entry_safe(state, next, freed, freed)
15333 drm_atomic_state_put(&state->base);
15336 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
15338 struct drm_i915_private *dev_priv =
15339 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
15341 intel_atomic_helper_free_state(dev_priv);
15344 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
15346 struct wait_queue_entry wait_fence, wait_reset;
15347 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
15349 init_wait_entry(&wait_fence, 0);
15350 init_wait_entry(&wait_reset, 0);
15352 prepare_to_wait(&intel_state->commit_ready.wait,
15353 &wait_fence, TASK_UNINTERRUPTIBLE);
15354 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
15355 I915_RESET_MODESET),
15356 &wait_reset, TASK_UNINTERRUPTIBLE);
15359 if (i915_sw_fence_done(&intel_state->commit_ready) ||
15360 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
15365 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
15366 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
15367 I915_RESET_MODESET),
15371 static void intel_atomic_cleanup_work(struct work_struct *work)
15373 struct drm_atomic_state *state =
15374 container_of(work, struct drm_atomic_state, commit_work);
15375 struct drm_i915_private *i915 = to_i915(state->dev);
15377 drm_atomic_helper_cleanup_planes(&i915->drm, state);
15378 drm_atomic_helper_commit_cleanup_done(state);
15379 drm_atomic_state_put(state);
15381 intel_atomic_helper_free_state(i915);
15384 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
15386 struct drm_device *dev = state->base.dev;
15387 struct drm_i915_private *dev_priv = to_i915(dev);
15388 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
15389 struct intel_crtc *crtc;
15390 u64 put_domains[I915_MAX_PIPES] = {};
15391 intel_wakeref_t wakeref = 0;
15394 intel_atomic_commit_fence_wait(state);
15396 drm_atomic_helper_wait_for_dependencies(&state->base);
15398 if (state->modeset)
15399 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
15401 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15402 new_crtc_state, i) {
15403 if (needs_modeset(new_crtc_state) ||
15404 new_crtc_state->update_pipe) {
15406 put_domains[crtc->pipe] =
15407 modeset_get_crtc_power_domains(new_crtc_state);
15411 intel_commit_modeset_disables(state);
15413 /* FIXME: Eventually get rid of our crtc->config pointer */
15414 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15415 crtc->config = new_crtc_state;
15417 if (state->modeset) {
15418 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
15420 intel_set_cdclk_pre_plane_update(state);
15423 * SKL workaround: bspec recommends we disable the SAGV when we
15424 * have more then one pipe enabled
15426 if (!intel_can_enable_sagv(state))
15427 intel_disable_sagv(dev_priv);
15429 intel_modeset_verify_disabled(dev_priv, state);
15432 /* Complete the events for pipes that have now been disabled */
15433 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15434 bool modeset = needs_modeset(new_crtc_state);
15436 /* Complete events for now disable pipes here. */
15437 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
15438 spin_lock_irq(&dev->event_lock);
15439 drm_crtc_send_vblank_event(&crtc->base,
15440 new_crtc_state->uapi.event);
15441 spin_unlock_irq(&dev->event_lock);
15443 new_crtc_state->uapi.event = NULL;
15447 if (state->modeset)
15448 intel_encoders_update_prepare(state);
15450 /* Enable all new slices, we might need */
15451 if (state->modeset)
15452 icl_dbuf_slice_pre_update(state);
15454 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
15455 dev_priv->display.commit_modeset_enables(state);
15457 if (state->modeset) {
15458 intel_encoders_update_complete(state);
15460 intel_set_cdclk_post_plane_update(state);
15463 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
15464 * already, but still need the state for the delayed optimization. To
15466 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
15467 * - schedule that vblank worker _before_ calling hw_done
15468 * - at the start of commit_tail, cancel it _synchrously
15469 * - switch over to the vblank wait helper in the core after that since
15470 * we don't need out special handling any more.
15472 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
15474 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15475 if (new_crtc_state->hw.active &&
15476 !needs_modeset(new_crtc_state) &&
15477 !new_crtc_state->preload_luts &&
15478 (new_crtc_state->uapi.color_mgmt_changed ||
15479 new_crtc_state->update_pipe))
15480 intel_color_load_luts(new_crtc_state);
15484 * Now that the vblank has passed, we can go ahead and program the
15485 * optimal watermarks on platforms that need two-step watermark
15488 * TODO: Move this (and other cleanup) to an async worker eventually.
15490 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15491 new_crtc_state, i) {
15493 * Gen2 reports pipe underruns whenever all planes are disabled.
15494 * So re-enable underrun reporting after some planes get enabled.
15496 * We do this before .optimize_watermarks() so that we have a
15497 * chance of catching underruns with the intermediate watermarks
15498 * vs. the new plane configuration.
15500 if (IS_GEN(dev_priv, 2) && planes_enabling(old_crtc_state, new_crtc_state))
15501 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
15503 if (dev_priv->display.optimize_watermarks)
15504 dev_priv->display.optimize_watermarks(state, crtc);
15507 /* Disable all slices, we don't need */
15508 if (state->modeset)
15509 icl_dbuf_slice_post_update(state);
15511 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15512 intel_post_plane_update(state, crtc);
15514 if (put_domains[i])
15515 modeset_put_power_domains(dev_priv, put_domains[i]);
15517 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
15520 /* Underruns don't always raise interrupts, so check manually */
15521 intel_check_cpu_fifo_underruns(dev_priv);
15522 intel_check_pch_fifo_underruns(dev_priv);
15524 if (state->modeset)
15525 intel_verify_planes(state);
15527 if (state->modeset && intel_can_enable_sagv(state))
15528 intel_enable_sagv(dev_priv);
15530 drm_atomic_helper_commit_hw_done(&state->base);
15532 if (state->modeset) {
15533 /* As one of the primary mmio accessors, KMS has a high
15534 * likelihood of triggering bugs in unclaimed access. After we
15535 * finish modesetting, see if an error has been flagged, and if
15536 * so enable debugging for the next modeset - and hope we catch
15539 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
15540 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
15542 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15545 * Defer the cleanup of the old state to a separate worker to not
15546 * impede the current task (userspace for blocking modesets) that
15547 * are executed inline. For out-of-line asynchronous modesets/flips,
15548 * deferring to a new worker seems overkill, but we would place a
15549 * schedule point (cond_resched()) here anyway to keep latencies
15552 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
15553 queue_work(system_highpri_wq, &state->base.commit_work);
15556 static void intel_atomic_commit_work(struct work_struct *work)
15558 struct intel_atomic_state *state =
15559 container_of(work, struct intel_atomic_state, base.commit_work);
15561 intel_atomic_commit_tail(state);
15564 static int __i915_sw_fence_call
15565 intel_atomic_commit_ready(struct i915_sw_fence *fence,
15566 enum i915_sw_fence_notify notify)
15568 struct intel_atomic_state *state =
15569 container_of(fence, struct intel_atomic_state, commit_ready);
15572 case FENCE_COMPLETE:
15573 /* we do blocking waits in the worker, nothing to do here */
15577 struct intel_atomic_helper *helper =
15578 &to_i915(state->base.dev)->atomic_helper;
15580 if (llist_add(&state->freed, &helper->free_list))
15581 schedule_work(&helper->free_work);
15586 return NOTIFY_DONE;
15589 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
15591 struct intel_plane_state *old_plane_state, *new_plane_state;
15592 struct intel_plane *plane;
15595 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
15596 new_plane_state, i)
15597 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
15598 to_intel_frontbuffer(new_plane_state->hw.fb),
15599 plane->frontbuffer_bit);
15602 static void assert_global_state_locked(struct drm_i915_private *dev_priv)
15604 struct intel_crtc *crtc;
15606 for_each_intel_crtc(&dev_priv->drm, crtc)
15607 drm_modeset_lock_assert_held(&crtc->base.mutex);
15610 static int intel_atomic_commit(struct drm_device *dev,
15611 struct drm_atomic_state *_state,
15614 struct intel_atomic_state *state = to_intel_atomic_state(_state);
15615 struct drm_i915_private *dev_priv = to_i915(dev);
15618 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
15620 drm_atomic_state_get(&state->base);
15621 i915_sw_fence_init(&state->commit_ready,
15622 intel_atomic_commit_ready);
15625 * The intel_legacy_cursor_update() fast path takes care
15626 * of avoiding the vblank waits for simple cursor
15627 * movement and flips. For cursor on/off and size changes,
15628 * we want to perform the vblank waits so that watermark
15629 * updates happen during the correct frames. Gen9+ have
15630 * double buffered watermarks and so shouldn't need this.
15632 * Unset state->legacy_cursor_update before the call to
15633 * drm_atomic_helper_setup_commit() because otherwise
15634 * drm_atomic_helper_wait_for_flip_done() is a noop and
15635 * we get FIFO underruns because we didn't wait
15638 * FIXME doing watermarks and fb cleanup from a vblank worker
15639 * (assuming we had any) would solve these problems.
15641 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
15642 struct intel_crtc_state *new_crtc_state;
15643 struct intel_crtc *crtc;
15646 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15647 if (new_crtc_state->wm.need_postvbl_update ||
15648 new_crtc_state->update_wm_post)
15649 state->base.legacy_cursor_update = false;
15652 ret = intel_atomic_prepare_commit(state);
15654 drm_dbg_atomic(&dev_priv->drm,
15655 "Preparing state failed with %i\n", ret);
15656 i915_sw_fence_commit(&state->commit_ready);
15657 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15661 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
15663 ret = drm_atomic_helper_swap_state(&state->base, true);
15665 intel_atomic_swap_global_state(state);
15668 i915_sw_fence_commit(&state->commit_ready);
15670 drm_atomic_helper_cleanup_planes(dev, &state->base);
15671 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15674 dev_priv->wm.distrust_bios_wm = false;
15675 intel_shared_dpll_swap_state(state);
15676 intel_atomic_track_fbs(state);
15678 if (state->global_state_changed) {
15679 assert_global_state_locked(dev_priv);
15681 dev_priv->active_pipes = state->active_pipes;
15684 drm_atomic_state_get(&state->base);
15685 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
15687 i915_sw_fence_commit(&state->commit_ready);
15688 if (nonblock && state->modeset) {
15689 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
15690 } else if (nonblock) {
15691 queue_work(dev_priv->flip_wq, &state->base.commit_work);
15693 if (state->modeset)
15694 flush_workqueue(dev_priv->modeset_wq);
15695 intel_atomic_commit_tail(state);
15701 struct wait_rps_boost {
15702 struct wait_queue_entry wait;
15704 struct drm_crtc *crtc;
15705 struct i915_request *request;
15708 static int do_rps_boost(struct wait_queue_entry *_wait,
15709 unsigned mode, int sync, void *key)
15711 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
15712 struct i915_request *rq = wait->request;
15715 * If we missed the vblank, but the request is already running it
15716 * is reasonable to assume that it will complete before the next
15717 * vblank without our intervention, so leave RPS alone.
15719 if (!i915_request_started(rq))
15720 intel_rps_boost(rq);
15721 i915_request_put(rq);
15723 drm_crtc_vblank_put(wait->crtc);
15725 list_del(&wait->wait.entry);
15730 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
15731 struct dma_fence *fence)
15733 struct wait_rps_boost *wait;
15735 if (!dma_fence_is_i915(fence))
15738 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
15741 if (drm_crtc_vblank_get(crtc))
15744 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
15746 drm_crtc_vblank_put(crtc);
15750 wait->request = to_request(dma_fence_get(fence));
15753 wait->wait.func = do_rps_boost;
15754 wait->wait.flags = 0;
15756 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
15759 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
15761 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
15762 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
15763 struct drm_framebuffer *fb = plane_state->hw.fb;
15764 struct i915_vma *vma;
15766 if (plane->id == PLANE_CURSOR &&
15767 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
15768 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15769 const int align = intel_cursor_alignment(dev_priv);
15772 err = i915_gem_object_attach_phys(obj, align);
15777 vma = intel_pin_and_fence_fb_obj(fb,
15778 &plane_state->view,
15779 intel_plane_uses_fence(plane_state),
15780 &plane_state->flags);
15782 return PTR_ERR(vma);
15784 plane_state->vma = vma;
15789 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
15791 struct i915_vma *vma;
15793 vma = fetch_and_zero(&old_plane_state->vma);
15795 intel_unpin_fb_vma(vma, old_plane_state->flags);
15798 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
15800 struct i915_sched_attr attr = {
15801 .priority = I915_USER_PRIORITY(I915_PRIORITY_DISPLAY),
15804 i915_gem_object_wait_priority(obj, 0, &attr);
15808 * intel_prepare_plane_fb - Prepare fb for usage on plane
15809 * @_plane: drm plane to prepare for
15810 * @_new_plane_state: the plane state being prepared
15812 * Prepares a framebuffer for usage on a display plane. Generally this
15813 * involves pinning the underlying object and updating the frontbuffer tracking
15814 * bits. Some older platforms need special physical address handling for
15817 * Returns 0 on success, negative error code on failure.
15820 intel_prepare_plane_fb(struct drm_plane *_plane,
15821 struct drm_plane_state *_new_plane_state)
15823 struct intel_plane *plane = to_intel_plane(_plane);
15824 struct intel_plane_state *new_plane_state =
15825 to_intel_plane_state(_new_plane_state);
15826 struct intel_atomic_state *state =
15827 to_intel_atomic_state(new_plane_state->uapi.state);
15828 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
15829 const struct intel_plane_state *old_plane_state =
15830 intel_atomic_get_old_plane_state(state, plane);
15831 struct drm_i915_gem_object *obj = intel_fb_obj(new_plane_state->hw.fb);
15832 struct drm_i915_gem_object *old_obj = intel_fb_obj(old_plane_state->hw.fb);
15836 const struct intel_crtc_state *crtc_state =
15837 intel_atomic_get_new_crtc_state(state,
15838 to_intel_crtc(old_plane_state->hw.crtc));
15840 /* Big Hammer, we also need to ensure that any pending
15841 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
15842 * current scanout is retired before unpinning the old
15843 * framebuffer. Note that we rely on userspace rendering
15844 * into the buffer attached to the pipe they are waiting
15845 * on. If not, userspace generates a GPU hang with IPEHR
15846 * point to the MI_WAIT_FOR_EVENT.
15848 * This should only fail upon a hung GPU, in which case we
15849 * can safely continue.
15851 if (needs_modeset(crtc_state)) {
15852 ret = i915_sw_fence_await_reservation(&state->commit_ready,
15853 old_obj->base.resv, NULL,
15861 if (new_plane_state->uapi.fence) { /* explicit fencing */
15862 ret = i915_sw_fence_await_dma_fence(&state->commit_ready,
15863 new_plane_state->uapi.fence,
15864 I915_FENCE_TIMEOUT,
15873 ret = i915_gem_object_pin_pages(obj);
15877 ret = intel_plane_pin_fb(new_plane_state);
15879 i915_gem_object_unpin_pages(obj);
15883 fb_obj_bump_render_priority(obj);
15884 i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
15886 if (!new_plane_state->uapi.fence) { /* implicit fencing */
15887 struct dma_fence *fence;
15889 ret = i915_sw_fence_await_reservation(&state->commit_ready,
15890 obj->base.resv, NULL,
15891 false, I915_FENCE_TIMEOUT,
15896 fence = dma_resv_get_excl_rcu(obj->base.resv);
15898 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
15900 dma_fence_put(fence);
15903 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
15904 new_plane_state->uapi.fence);
15908 * We declare pageflips to be interactive and so merit a small bias
15909 * towards upclocking to deliver the frame on time. By only changing
15910 * the RPS thresholds to sample more regularly and aim for higher
15911 * clocks we can hopefully deliver low power workloads (like kodi)
15912 * that are not quite steady state without resorting to forcing
15913 * maximum clocks following a vblank miss (see do_rps_boost()).
15915 if (!state->rps_interactive) {
15916 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
15917 state->rps_interactive = true;
15923 intel_plane_unpin_fb(new_plane_state);
15929 * intel_cleanup_plane_fb - Cleans up an fb after plane use
15930 * @plane: drm plane to clean up for
15931 * @_old_plane_state: the state from the previous modeset
15933 * Cleans up a framebuffer that has just been removed from a plane.
15936 intel_cleanup_plane_fb(struct drm_plane *plane,
15937 struct drm_plane_state *_old_plane_state)
15939 struct intel_plane_state *old_plane_state =
15940 to_intel_plane_state(_old_plane_state);
15941 struct intel_atomic_state *state =
15942 to_intel_atomic_state(old_plane_state->uapi.state);
15943 struct drm_i915_private *dev_priv = to_i915(plane->dev);
15944 struct drm_i915_gem_object *obj = intel_fb_obj(old_plane_state->hw.fb);
15949 if (state->rps_interactive) {
15950 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
15951 state->rps_interactive = false;
15954 /* Should only be called after a successful intel_prepare_plane_fb()! */
15955 intel_plane_unpin_fb(old_plane_state);
15959 * intel_plane_destroy - destroy a plane
15960 * @plane: plane to destroy
15962 * Common destruction function for all types of planes (primary, cursor,
15965 void intel_plane_destroy(struct drm_plane *plane)
15967 drm_plane_cleanup(plane);
15968 kfree(to_intel_plane(plane));
15971 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
15972 u32 format, u64 modifier)
15974 switch (modifier) {
15975 case DRM_FORMAT_MOD_LINEAR:
15976 case I915_FORMAT_MOD_X_TILED:
15983 case DRM_FORMAT_C8:
15984 case DRM_FORMAT_RGB565:
15985 case DRM_FORMAT_XRGB1555:
15986 case DRM_FORMAT_XRGB8888:
15987 return modifier == DRM_FORMAT_MOD_LINEAR ||
15988 modifier == I915_FORMAT_MOD_X_TILED;
15994 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
15995 u32 format, u64 modifier)
15997 switch (modifier) {
15998 case DRM_FORMAT_MOD_LINEAR:
15999 case I915_FORMAT_MOD_X_TILED:
16006 case DRM_FORMAT_C8:
16007 case DRM_FORMAT_RGB565:
16008 case DRM_FORMAT_XRGB8888:
16009 case DRM_FORMAT_XBGR8888:
16010 case DRM_FORMAT_ARGB8888:
16011 case DRM_FORMAT_ABGR8888:
16012 case DRM_FORMAT_XRGB2101010:
16013 case DRM_FORMAT_XBGR2101010:
16014 case DRM_FORMAT_ARGB2101010:
16015 case DRM_FORMAT_ABGR2101010:
16016 case DRM_FORMAT_XBGR16161616F:
16017 return modifier == DRM_FORMAT_MOD_LINEAR ||
16018 modifier == I915_FORMAT_MOD_X_TILED;
16024 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
16025 u32 format, u64 modifier)
16027 return modifier == DRM_FORMAT_MOD_LINEAR &&
16028 format == DRM_FORMAT_ARGB8888;
16031 static const struct drm_plane_funcs i965_plane_funcs = {
16032 .update_plane = drm_atomic_helper_update_plane,
16033 .disable_plane = drm_atomic_helper_disable_plane,
16034 .destroy = intel_plane_destroy,
16035 .atomic_duplicate_state = intel_plane_duplicate_state,
16036 .atomic_destroy_state = intel_plane_destroy_state,
16037 .format_mod_supported = i965_plane_format_mod_supported,
16040 static const struct drm_plane_funcs i8xx_plane_funcs = {
16041 .update_plane = drm_atomic_helper_update_plane,
16042 .disable_plane = drm_atomic_helper_disable_plane,
16043 .destroy = intel_plane_destroy,
16044 .atomic_duplicate_state = intel_plane_duplicate_state,
16045 .atomic_destroy_state = intel_plane_destroy_state,
16046 .format_mod_supported = i8xx_plane_format_mod_supported,
16050 intel_legacy_cursor_update(struct drm_plane *_plane,
16051 struct drm_crtc *_crtc,
16052 struct drm_framebuffer *fb,
16053 int crtc_x, int crtc_y,
16054 unsigned int crtc_w, unsigned int crtc_h,
16055 u32 src_x, u32 src_y,
16056 u32 src_w, u32 src_h,
16057 struct drm_modeset_acquire_ctx *ctx)
16059 struct intel_plane *plane = to_intel_plane(_plane);
16060 struct intel_crtc *crtc = to_intel_crtc(_crtc);
16061 struct intel_plane_state *old_plane_state =
16062 to_intel_plane_state(plane->base.state);
16063 struct intel_plane_state *new_plane_state;
16064 struct intel_crtc_state *crtc_state =
16065 to_intel_crtc_state(crtc->base.state);
16066 struct intel_crtc_state *new_crtc_state;
16070 * When crtc is inactive or there is a modeset pending,
16071 * wait for it to complete in the slowpath
16073 if (!crtc_state->hw.active || needs_modeset(crtc_state) ||
16074 crtc_state->update_pipe)
16078 * Don't do an async update if there is an outstanding commit modifying
16079 * the plane. This prevents our async update's changes from getting
16080 * overridden by a previous synchronous update's state.
16082 if (old_plane_state->uapi.commit &&
16083 !try_wait_for_completion(&old_plane_state->uapi.commit->hw_done))
16087 * If any parameters change that may affect watermarks,
16088 * take the slowpath. Only changing fb or position should be
16091 if (old_plane_state->uapi.crtc != &crtc->base ||
16092 old_plane_state->uapi.src_w != src_w ||
16093 old_plane_state->uapi.src_h != src_h ||
16094 old_plane_state->uapi.crtc_w != crtc_w ||
16095 old_plane_state->uapi.crtc_h != crtc_h ||
16096 !old_plane_state->uapi.fb != !fb)
16099 new_plane_state = to_intel_plane_state(intel_plane_duplicate_state(&plane->base));
16100 if (!new_plane_state)
16103 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(&crtc->base));
16104 if (!new_crtc_state) {
16109 drm_atomic_set_fb_for_plane(&new_plane_state->uapi, fb);
16111 new_plane_state->uapi.src_x = src_x;
16112 new_plane_state->uapi.src_y = src_y;
16113 new_plane_state->uapi.src_w = src_w;
16114 new_plane_state->uapi.src_h = src_h;
16115 new_plane_state->uapi.crtc_x = crtc_x;
16116 new_plane_state->uapi.crtc_y = crtc_y;
16117 new_plane_state->uapi.crtc_w = crtc_w;
16118 new_plane_state->uapi.crtc_h = crtc_h;
16120 intel_plane_copy_uapi_to_hw_state(new_plane_state, new_plane_state);
16122 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
16123 old_plane_state, new_plane_state);
16127 ret = intel_plane_pin_fb(new_plane_state);
16131 intel_frontbuffer_flush(to_intel_frontbuffer(new_plane_state->hw.fb),
16133 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
16134 to_intel_frontbuffer(new_plane_state->hw.fb),
16135 plane->frontbuffer_bit);
16137 /* Swap plane state */
16138 plane->base.state = &new_plane_state->uapi;
16141 * We cannot swap crtc_state as it may be in use by an atomic commit or
16142 * page flip that's running simultaneously. If we swap crtc_state and
16143 * destroy the old state, we will cause a use-after-free there.
16145 * Only update active_planes, which is needed for our internal
16146 * bookkeeping. Either value will do the right thing when updating
16147 * planes atomically. If the cursor was part of the atomic update then
16148 * we would have taken the slowpath.
16150 crtc_state->active_planes = new_crtc_state->active_planes;
16152 if (new_plane_state->uapi.visible)
16153 intel_update_plane(plane, crtc_state, new_plane_state);
16155 intel_disable_plane(plane, crtc_state);
16157 intel_plane_unpin_fb(old_plane_state);
16160 if (new_crtc_state)
16161 intel_crtc_destroy_state(&crtc->base, &new_crtc_state->uapi);
16163 intel_plane_destroy_state(&plane->base, &new_plane_state->uapi);
16165 intel_plane_destroy_state(&plane->base, &old_plane_state->uapi);
16169 return drm_atomic_helper_update_plane(&plane->base, &crtc->base, fb,
16170 crtc_x, crtc_y, crtc_w, crtc_h,
16171 src_x, src_y, src_w, src_h, ctx);
16174 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
16175 .update_plane = intel_legacy_cursor_update,
16176 .disable_plane = drm_atomic_helper_disable_plane,
16177 .destroy = intel_plane_destroy,
16178 .atomic_duplicate_state = intel_plane_duplicate_state,
16179 .atomic_destroy_state = intel_plane_destroy_state,
16180 .format_mod_supported = intel_cursor_format_mod_supported,
16183 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
16184 enum i9xx_plane_id i9xx_plane)
16186 if (!HAS_FBC(dev_priv))
16189 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
16190 return i9xx_plane == PLANE_A; /* tied to pipe A */
16191 else if (IS_IVYBRIDGE(dev_priv))
16192 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
16193 i9xx_plane == PLANE_C;
16194 else if (INTEL_GEN(dev_priv) >= 4)
16195 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
16197 return i9xx_plane == PLANE_A;
16200 static struct intel_plane *
16201 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
16203 struct intel_plane *plane;
16204 const struct drm_plane_funcs *plane_funcs;
16205 unsigned int supported_rotations;
16206 const u32 *formats;
16210 if (INTEL_GEN(dev_priv) >= 9)
16211 return skl_universal_plane_create(dev_priv, pipe,
16214 plane = intel_plane_alloc();
16218 plane->pipe = pipe;
16220 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
16221 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
16223 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
16224 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
16226 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
16227 plane->id = PLANE_PRIMARY;
16228 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
16230 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
16231 if (plane->has_fbc) {
16232 struct intel_fbc *fbc = &dev_priv->fbc;
16234 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
16237 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16238 formats = vlv_primary_formats;
16239 num_formats = ARRAY_SIZE(vlv_primary_formats);
16240 } else if (INTEL_GEN(dev_priv) >= 4) {
16242 * WaFP16GammaEnabling:ivb
16243 * "Workaround : When using the 64-bit format, the plane
16244 * output on each color channel has one quarter amplitude.
16245 * It can be brought up to full amplitude by using pipe
16246 * gamma correction or pipe color space conversion to
16247 * multiply the plane output by four."
16249 * There is no dedicated plane gamma for the primary plane,
16250 * and using the pipe gamma/csc could conflict with other
16251 * planes, so we choose not to expose fp16 on IVB primary
16252 * planes. HSW primary planes no longer have this problem.
16254 if (IS_IVYBRIDGE(dev_priv)) {
16255 formats = ivb_primary_formats;
16256 num_formats = ARRAY_SIZE(ivb_primary_formats);
16258 formats = i965_primary_formats;
16259 num_formats = ARRAY_SIZE(i965_primary_formats);
16262 formats = i8xx_primary_formats;
16263 num_formats = ARRAY_SIZE(i8xx_primary_formats);
16266 if (INTEL_GEN(dev_priv) >= 4)
16267 plane_funcs = &i965_plane_funcs;
16269 plane_funcs = &i8xx_plane_funcs;
16271 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16272 plane->min_cdclk = vlv_plane_min_cdclk;
16273 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
16274 plane->min_cdclk = hsw_plane_min_cdclk;
16275 else if (IS_IVYBRIDGE(dev_priv))
16276 plane->min_cdclk = ivb_plane_min_cdclk;
16278 plane->min_cdclk = i9xx_plane_min_cdclk;
16280 plane->max_stride = i9xx_plane_max_stride;
16281 plane->update_plane = i9xx_update_plane;
16282 plane->disable_plane = i9xx_disable_plane;
16283 plane->get_hw_state = i9xx_plane_get_hw_state;
16284 plane->check_plane = i9xx_plane_check;
16286 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
16287 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
16289 formats, num_formats,
16290 i9xx_format_modifiers,
16291 DRM_PLANE_TYPE_PRIMARY,
16292 "primary %c", pipe_name(pipe));
16294 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
16296 formats, num_formats,
16297 i9xx_format_modifiers,
16298 DRM_PLANE_TYPE_PRIMARY,
16300 plane_name(plane->i9xx_plane));
16304 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
16305 supported_rotations =
16306 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
16307 DRM_MODE_REFLECT_X;
16308 } else if (INTEL_GEN(dev_priv) >= 4) {
16309 supported_rotations =
16310 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
16312 supported_rotations = DRM_MODE_ROTATE_0;
16315 if (INTEL_GEN(dev_priv) >= 4)
16316 drm_plane_create_rotation_property(&plane->base,
16318 supported_rotations);
16321 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
16323 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
16328 intel_plane_free(plane);
16330 return ERR_PTR(ret);
16333 static struct intel_plane *
16334 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
16337 struct intel_plane *cursor;
16340 cursor = intel_plane_alloc();
16341 if (IS_ERR(cursor))
16344 cursor->pipe = pipe;
16345 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
16346 cursor->id = PLANE_CURSOR;
16347 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
16349 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
16350 cursor->max_stride = i845_cursor_max_stride;
16351 cursor->update_plane = i845_update_cursor;
16352 cursor->disable_plane = i845_disable_cursor;
16353 cursor->get_hw_state = i845_cursor_get_hw_state;
16354 cursor->check_plane = i845_check_cursor;
16356 cursor->max_stride = i9xx_cursor_max_stride;
16357 cursor->update_plane = i9xx_update_cursor;
16358 cursor->disable_plane = i9xx_disable_cursor;
16359 cursor->get_hw_state = i9xx_cursor_get_hw_state;
16360 cursor->check_plane = i9xx_check_cursor;
16363 cursor->cursor.base = ~0;
16364 cursor->cursor.cntl = ~0;
16366 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
16367 cursor->cursor.size = ~0;
16369 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
16370 0, &intel_cursor_plane_funcs,
16371 intel_cursor_formats,
16372 ARRAY_SIZE(intel_cursor_formats),
16373 cursor_format_modifiers,
16374 DRM_PLANE_TYPE_CURSOR,
16375 "cursor %c", pipe_name(pipe));
16379 if (INTEL_GEN(dev_priv) >= 4)
16380 drm_plane_create_rotation_property(&cursor->base,
16382 DRM_MODE_ROTATE_0 |
16383 DRM_MODE_ROTATE_180);
16385 zpos = RUNTIME_INFO(dev_priv)->num_sprites[pipe] + 1;
16386 drm_plane_create_zpos_immutable_property(&cursor->base, zpos);
16388 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
16393 intel_plane_free(cursor);
16395 return ERR_PTR(ret);
16398 #define INTEL_CRTC_FUNCS \
16399 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
16400 .set_config = drm_atomic_helper_set_config, \
16401 .destroy = intel_crtc_destroy, \
16402 .page_flip = drm_atomic_helper_page_flip, \
16403 .atomic_duplicate_state = intel_crtc_duplicate_state, \
16404 .atomic_destroy_state = intel_crtc_destroy_state, \
16405 .set_crc_source = intel_crtc_set_crc_source, \
16406 .verify_crc_source = intel_crtc_verify_crc_source, \
16407 .get_crc_sources = intel_crtc_get_crc_sources
16409 static const struct drm_crtc_funcs bdw_crtc_funcs = {
16412 .get_vblank_counter = g4x_get_vblank_counter,
16413 .enable_vblank = bdw_enable_vblank,
16414 .disable_vblank = bdw_disable_vblank,
16417 static const struct drm_crtc_funcs ilk_crtc_funcs = {
16420 .get_vblank_counter = g4x_get_vblank_counter,
16421 .enable_vblank = ilk_enable_vblank,
16422 .disable_vblank = ilk_disable_vblank,
16425 static const struct drm_crtc_funcs g4x_crtc_funcs = {
16428 .get_vblank_counter = g4x_get_vblank_counter,
16429 .enable_vblank = i965_enable_vblank,
16430 .disable_vblank = i965_disable_vblank,
16433 static const struct drm_crtc_funcs i965_crtc_funcs = {
16436 .get_vblank_counter = i915_get_vblank_counter,
16437 .enable_vblank = i965_enable_vblank,
16438 .disable_vblank = i965_disable_vblank,
16441 static const struct drm_crtc_funcs i915gm_crtc_funcs = {
16444 .get_vblank_counter = i915_get_vblank_counter,
16445 .enable_vblank = i915gm_enable_vblank,
16446 .disable_vblank = i915gm_disable_vblank,
16449 static const struct drm_crtc_funcs i915_crtc_funcs = {
16452 .get_vblank_counter = i915_get_vblank_counter,
16453 .enable_vblank = i8xx_enable_vblank,
16454 .disable_vblank = i8xx_disable_vblank,
16457 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
16460 /* no hw vblank counter */
16461 .enable_vblank = i8xx_enable_vblank,
16462 .disable_vblank = i8xx_disable_vblank,
16465 static struct intel_crtc *intel_crtc_alloc(void)
16467 struct intel_crtc_state *crtc_state;
16468 struct intel_crtc *crtc;
16470 crtc = kzalloc(sizeof(*crtc), GFP_KERNEL);
16472 return ERR_PTR(-ENOMEM);
16474 crtc_state = intel_crtc_state_alloc(crtc);
16477 return ERR_PTR(-ENOMEM);
16480 crtc->base.state = &crtc_state->uapi;
16481 crtc->config = crtc_state;
16486 static void intel_crtc_free(struct intel_crtc *crtc)
16488 intel_crtc_destroy_state(&crtc->base, crtc->base.state);
16492 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv)
16494 struct intel_plane *plane;
16496 for_each_intel_plane(&dev_priv->drm, plane) {
16497 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
16500 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
16504 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
16506 struct intel_plane *primary, *cursor;
16507 const struct drm_crtc_funcs *funcs;
16508 struct intel_crtc *crtc;
16511 crtc = intel_crtc_alloc();
16513 return PTR_ERR(crtc);
16516 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[pipe];
16518 primary = intel_primary_plane_create(dev_priv, pipe);
16519 if (IS_ERR(primary)) {
16520 ret = PTR_ERR(primary);
16523 crtc->plane_ids_mask |= BIT(primary->id);
16525 for_each_sprite(dev_priv, pipe, sprite) {
16526 struct intel_plane *plane;
16528 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
16529 if (IS_ERR(plane)) {
16530 ret = PTR_ERR(plane);
16533 crtc->plane_ids_mask |= BIT(plane->id);
16536 cursor = intel_cursor_plane_create(dev_priv, pipe);
16537 if (IS_ERR(cursor)) {
16538 ret = PTR_ERR(cursor);
16541 crtc->plane_ids_mask |= BIT(cursor->id);
16543 if (HAS_GMCH(dev_priv)) {
16544 if (IS_CHERRYVIEW(dev_priv) ||
16545 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
16546 funcs = &g4x_crtc_funcs;
16547 else if (IS_GEN(dev_priv, 4))
16548 funcs = &i965_crtc_funcs;
16549 else if (IS_I945GM(dev_priv) || IS_I915GM(dev_priv))
16550 funcs = &i915gm_crtc_funcs;
16551 else if (IS_GEN(dev_priv, 3))
16552 funcs = &i915_crtc_funcs;
16554 funcs = &i8xx_crtc_funcs;
16556 if (INTEL_GEN(dev_priv) >= 8)
16557 funcs = &bdw_crtc_funcs;
16559 funcs = &ilk_crtc_funcs;
16562 ret = drm_crtc_init_with_planes(&dev_priv->drm, &crtc->base,
16563 &primary->base, &cursor->base,
16564 funcs, "pipe %c", pipe_name(pipe));
16568 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
16569 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
16570 dev_priv->pipe_to_crtc_mapping[pipe] = crtc;
16572 if (INTEL_GEN(dev_priv) < 9) {
16573 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
16575 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
16576 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
16577 dev_priv->plane_to_crtc_mapping[i9xx_plane] = crtc;
16580 intel_color_init(crtc);
16582 intel_crtc_crc_init(crtc);
16584 drm_WARN_ON(&dev_priv->drm, drm_crtc_index(&crtc->base) != crtc->pipe);
16589 intel_crtc_free(crtc);
16594 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
16595 struct drm_file *file)
16597 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
16598 struct drm_crtc *drmmode_crtc;
16599 struct intel_crtc *crtc;
16601 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
16605 crtc = to_intel_crtc(drmmode_crtc);
16606 pipe_from_crtc_id->pipe = crtc->pipe;
16611 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
16613 struct drm_device *dev = encoder->base.dev;
16614 struct intel_encoder *source_encoder;
16615 u32 possible_clones = 0;
16617 for_each_intel_encoder(dev, source_encoder) {
16618 if (encoders_cloneable(encoder, source_encoder))
16619 possible_clones |= drm_encoder_mask(&source_encoder->base);
16622 return possible_clones;
16625 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
16627 struct drm_device *dev = encoder->base.dev;
16628 struct intel_crtc *crtc;
16629 u32 possible_crtcs = 0;
16631 for_each_intel_crtc(dev, crtc) {
16632 if (encoder->pipe_mask & BIT(crtc->pipe))
16633 possible_crtcs |= drm_crtc_mask(&crtc->base);
16636 return possible_crtcs;
16639 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
16641 if (!IS_MOBILE(dev_priv))
16644 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
16647 if (IS_GEN(dev_priv, 5) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
16653 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
16655 if (INTEL_GEN(dev_priv) >= 9)
16658 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
16661 if (HAS_PCH_LPT_H(dev_priv) &&
16662 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
16665 /* DDI E can't be used if DDI A requires 4 lanes */
16666 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
16669 if (!dev_priv->vbt.int_crt_support)
16675 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
16680 if (HAS_DDI(dev_priv))
16683 * This w/a is needed at least on CPT/PPT, but to be sure apply it
16684 * everywhere where registers can be write protected.
16686 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16691 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
16692 u32 val = intel_de_read(dev_priv, PP_CONTROL(pps_idx));
16694 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
16695 intel_de_write(dev_priv, PP_CONTROL(pps_idx), val);
16699 static void intel_pps_init(struct drm_i915_private *dev_priv)
16701 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
16702 dev_priv->pps_mmio_base = PCH_PPS_BASE;
16703 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16704 dev_priv->pps_mmio_base = VLV_PPS_BASE;
16706 dev_priv->pps_mmio_base = PPS_BASE;
16708 intel_pps_unlock_regs_wa(dev_priv);
16711 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
16713 struct intel_encoder *encoder;
16714 bool dpd_is_edp = false;
16716 intel_pps_init(dev_priv);
16718 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
16721 if (INTEL_GEN(dev_priv) >= 12) {
16722 intel_ddi_init(dev_priv, PORT_A);
16723 intel_ddi_init(dev_priv, PORT_B);
16724 intel_ddi_init(dev_priv, PORT_D);
16725 intel_ddi_init(dev_priv, PORT_E);
16726 intel_ddi_init(dev_priv, PORT_F);
16727 intel_ddi_init(dev_priv, PORT_G);
16728 intel_ddi_init(dev_priv, PORT_H);
16729 intel_ddi_init(dev_priv, PORT_I);
16730 icl_dsi_init(dev_priv);
16731 } else if (IS_ELKHARTLAKE(dev_priv)) {
16732 intel_ddi_init(dev_priv, PORT_A);
16733 intel_ddi_init(dev_priv, PORT_B);
16734 intel_ddi_init(dev_priv, PORT_C);
16735 intel_ddi_init(dev_priv, PORT_D);
16736 icl_dsi_init(dev_priv);
16737 } else if (IS_GEN(dev_priv, 11)) {
16738 intel_ddi_init(dev_priv, PORT_A);
16739 intel_ddi_init(dev_priv, PORT_B);
16740 intel_ddi_init(dev_priv, PORT_C);
16741 intel_ddi_init(dev_priv, PORT_D);
16742 intel_ddi_init(dev_priv, PORT_E);
16744 * On some ICL SKUs port F is not present. No strap bits for
16745 * this, so rely on VBT.
16746 * Work around broken VBTs on SKUs known to have no port F.
16748 if (IS_ICL_WITH_PORT_F(dev_priv) &&
16749 intel_bios_is_port_present(dev_priv, PORT_F))
16750 intel_ddi_init(dev_priv, PORT_F);
16752 icl_dsi_init(dev_priv);
16753 } else if (IS_GEN9_LP(dev_priv)) {
16755 * FIXME: Broxton doesn't support port detection via the
16756 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
16757 * detect the ports.
16759 intel_ddi_init(dev_priv, PORT_A);
16760 intel_ddi_init(dev_priv, PORT_B);
16761 intel_ddi_init(dev_priv, PORT_C);
16763 vlv_dsi_init(dev_priv);
16764 } else if (HAS_DDI(dev_priv)) {
16767 if (intel_ddi_crt_present(dev_priv))
16768 intel_crt_init(dev_priv);
16771 * Haswell uses DDI functions to detect digital outputs.
16772 * On SKL pre-D0 the strap isn't connected, so we assume
16775 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
16776 /* WaIgnoreDDIAStrap: skl */
16777 if (found || IS_GEN9_BC(dev_priv))
16778 intel_ddi_init(dev_priv, PORT_A);
16780 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
16782 found = intel_de_read(dev_priv, SFUSE_STRAP);
16784 if (found & SFUSE_STRAP_DDIB_DETECTED)
16785 intel_ddi_init(dev_priv, PORT_B);
16786 if (found & SFUSE_STRAP_DDIC_DETECTED)
16787 intel_ddi_init(dev_priv, PORT_C);
16788 if (found & SFUSE_STRAP_DDID_DETECTED)
16789 intel_ddi_init(dev_priv, PORT_D);
16790 if (found & SFUSE_STRAP_DDIF_DETECTED)
16791 intel_ddi_init(dev_priv, PORT_F);
16793 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
16795 if (IS_GEN9_BC(dev_priv) &&
16796 intel_bios_is_port_present(dev_priv, PORT_E))
16797 intel_ddi_init(dev_priv, PORT_E);
16799 } else if (HAS_PCH_SPLIT(dev_priv)) {
16803 * intel_edp_init_connector() depends on this completing first,
16804 * to prevent the registration of both eDP and LVDS and the
16805 * incorrect sharing of the PPS.
16807 intel_lvds_init(dev_priv);
16808 intel_crt_init(dev_priv);
16810 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
16812 if (ilk_has_edp_a(dev_priv))
16813 intel_dp_init(dev_priv, DP_A, PORT_A);
16815 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
16816 /* PCH SDVOB multiplex with HDMIB */
16817 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
16819 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
16820 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
16821 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
16824 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
16825 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
16827 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
16828 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
16830 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
16831 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
16833 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
16834 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
16835 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16836 bool has_edp, has_port;
16838 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
16839 intel_crt_init(dev_priv);
16842 * The DP_DETECTED bit is the latched state of the DDC
16843 * SDA pin at boot. However since eDP doesn't require DDC
16844 * (no way to plug in a DP->HDMI dongle) the DDC pins for
16845 * eDP ports may have been muxed to an alternate function.
16846 * Thus we can't rely on the DP_DETECTED bit alone to detect
16847 * eDP ports. Consult the VBT as well as DP_DETECTED to
16848 * detect eDP ports.
16850 * Sadly the straps seem to be missing sometimes even for HDMI
16851 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
16852 * and VBT for the presence of the port. Additionally we can't
16853 * trust the port type the VBT declares as we've seen at least
16854 * HDMI ports that the VBT claim are DP or eDP.
16856 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
16857 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
16858 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
16859 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
16860 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
16861 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
16863 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
16864 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
16865 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
16866 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
16867 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
16868 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
16870 if (IS_CHERRYVIEW(dev_priv)) {
16872 * eDP not supported on port D,
16873 * so no need to worry about it
16875 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
16876 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
16877 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
16878 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
16879 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
16882 vlv_dsi_init(dev_priv);
16883 } else if (IS_PINEVIEW(dev_priv)) {
16884 intel_lvds_init(dev_priv);
16885 intel_crt_init(dev_priv);
16886 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
16887 bool found = false;
16889 if (IS_MOBILE(dev_priv))
16890 intel_lvds_init(dev_priv);
16892 intel_crt_init(dev_priv);
16894 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
16895 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
16896 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
16897 if (!found && IS_G4X(dev_priv)) {
16898 drm_dbg_kms(&dev_priv->drm,
16899 "probing HDMI on SDVOB\n");
16900 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
16903 if (!found && IS_G4X(dev_priv))
16904 intel_dp_init(dev_priv, DP_B, PORT_B);
16907 /* Before G4X SDVOC doesn't have its own detect register */
16909 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
16910 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
16911 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
16914 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
16916 if (IS_G4X(dev_priv)) {
16917 drm_dbg_kms(&dev_priv->drm,
16918 "probing HDMI on SDVOC\n");
16919 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
16921 if (IS_G4X(dev_priv))
16922 intel_dp_init(dev_priv, DP_C, PORT_C);
16925 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
16926 intel_dp_init(dev_priv, DP_D, PORT_D);
16928 if (SUPPORTS_TV(dev_priv))
16929 intel_tv_init(dev_priv);
16930 } else if (IS_GEN(dev_priv, 2)) {
16931 if (IS_I85X(dev_priv))
16932 intel_lvds_init(dev_priv);
16934 intel_crt_init(dev_priv);
16935 intel_dvo_init(dev_priv);
16938 intel_psr_init(dev_priv);
16940 for_each_intel_encoder(&dev_priv->drm, encoder) {
16941 encoder->base.possible_crtcs =
16942 intel_encoder_possible_crtcs(encoder);
16943 encoder->base.possible_clones =
16944 intel_encoder_possible_clones(encoder);
16947 intel_init_pch_refclk(dev_priv);
16949 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
16952 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
16954 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
16956 drm_framebuffer_cleanup(fb);
16957 intel_frontbuffer_put(intel_fb->frontbuffer);
16962 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
16963 struct drm_file *file,
16964 unsigned int *handle)
16966 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16967 struct drm_i915_private *i915 = to_i915(obj->base.dev);
16969 if (obj->userptr.mm) {
16970 drm_dbg(&i915->drm,
16971 "attempting to use a userptr for a framebuffer, denied\n");
16975 return drm_gem_handle_create(file, &obj->base, handle);
16978 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
16979 struct drm_file *file,
16980 unsigned flags, unsigned color,
16981 struct drm_clip_rect *clips,
16982 unsigned num_clips)
16984 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
16986 i915_gem_object_flush_if_display(obj);
16987 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
16992 static const struct drm_framebuffer_funcs intel_fb_funcs = {
16993 .destroy = intel_user_framebuffer_destroy,
16994 .create_handle = intel_user_framebuffer_create_handle,
16995 .dirty = intel_user_framebuffer_dirty,
16998 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
16999 struct drm_i915_gem_object *obj,
17000 struct drm_mode_fb_cmd2 *mode_cmd)
17002 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
17003 struct drm_framebuffer *fb = &intel_fb->base;
17005 unsigned int tiling, stride;
17009 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
17010 if (!intel_fb->frontbuffer)
17013 i915_gem_object_lock(obj);
17014 tiling = i915_gem_object_get_tiling(obj);
17015 stride = i915_gem_object_get_stride(obj);
17016 i915_gem_object_unlock(obj);
17018 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
17020 * If there's a fence, enforce that
17021 * the fb modifier and tiling mode match.
17023 if (tiling != I915_TILING_NONE &&
17024 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
17025 drm_dbg_kms(&dev_priv->drm,
17026 "tiling_mode doesn't match fb modifier\n");
17030 if (tiling == I915_TILING_X) {
17031 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
17032 } else if (tiling == I915_TILING_Y) {
17033 drm_dbg_kms(&dev_priv->drm,
17034 "No Y tiling for legacy addfb\n");
17039 if (!drm_any_plane_has_format(&dev_priv->drm,
17040 mode_cmd->pixel_format,
17041 mode_cmd->modifier[0])) {
17042 struct drm_format_name_buf format_name;
17044 drm_dbg_kms(&dev_priv->drm,
17045 "unsupported pixel format %s / modifier 0x%llx\n",
17046 drm_get_format_name(mode_cmd->pixel_format,
17048 mode_cmd->modifier[0]);
17053 * gen2/3 display engine uses the fence if present,
17054 * so the tiling mode must match the fb modifier exactly.
17056 if (INTEL_GEN(dev_priv) < 4 &&
17057 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
17058 drm_dbg_kms(&dev_priv->drm,
17059 "tiling_mode must match fb modifier exactly on gen2/3\n");
17063 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
17064 mode_cmd->modifier[0]);
17065 if (mode_cmd->pitches[0] > max_stride) {
17066 drm_dbg_kms(&dev_priv->drm,
17067 "%s pitch (%u) must be at most %d\n",
17068 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
17069 "tiled" : "linear",
17070 mode_cmd->pitches[0], max_stride);
17075 * If there's a fence, enforce that
17076 * the fb pitch and fence stride match.
17078 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
17079 drm_dbg_kms(&dev_priv->drm,
17080 "pitch (%d) must match tiling stride (%d)\n",
17081 mode_cmd->pitches[0], stride);
17085 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
17086 if (mode_cmd->offsets[0] != 0) {
17087 drm_dbg_kms(&dev_priv->drm,
17088 "plane 0 offset (0x%08x) must be 0\n",
17089 mode_cmd->offsets[0]);
17093 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
17095 for (i = 0; i < fb->format->num_planes; i++) {
17096 u32 stride_alignment;
17098 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
17099 drm_dbg_kms(&dev_priv->drm, "bad plane %d handle\n",
17104 stride_alignment = intel_fb_stride_alignment(fb, i);
17105 if (fb->pitches[i] & (stride_alignment - 1)) {
17106 drm_dbg_kms(&dev_priv->drm,
17107 "plane %d pitch (%d) must be at least %u byte aligned\n",
17108 i, fb->pitches[i], stride_alignment);
17112 if (is_gen12_ccs_plane(fb, i)) {
17113 int ccs_aux_stride = gen12_ccs_aux_stride(fb, i);
17115 if (fb->pitches[i] != ccs_aux_stride) {
17116 drm_dbg_kms(&dev_priv->drm,
17117 "ccs aux plane %d pitch (%d) must be %d\n",
17119 fb->pitches[i], ccs_aux_stride);
17124 fb->obj[i] = &obj->base;
17127 ret = intel_fill_fb_info(dev_priv, fb);
17131 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
17133 drm_err(&dev_priv->drm, "framebuffer init failed %d\n", ret);
17140 intel_frontbuffer_put(intel_fb->frontbuffer);
17144 static struct drm_framebuffer *
17145 intel_user_framebuffer_create(struct drm_device *dev,
17146 struct drm_file *filp,
17147 const struct drm_mode_fb_cmd2 *user_mode_cmd)
17149 struct drm_framebuffer *fb;
17150 struct drm_i915_gem_object *obj;
17151 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
17153 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
17155 return ERR_PTR(-ENOENT);
17157 fb = intel_framebuffer_create(obj, &mode_cmd);
17158 i915_gem_object_put(obj);
17163 static enum drm_mode_status
17164 intel_mode_valid(struct drm_device *dev,
17165 const struct drm_display_mode *mode)
17167 struct drm_i915_private *dev_priv = to_i915(dev);
17168 int hdisplay_max, htotal_max;
17169 int vdisplay_max, vtotal_max;
17172 * Can't reject DBLSCAN here because Xorg ddxen can add piles
17173 * of DBLSCAN modes to the output's mode list when they detect
17174 * the scaling mode property on the connector. And they don't
17175 * ask the kernel to validate those modes in any way until
17176 * modeset time at which point the client gets a protocol error.
17177 * So in order to not upset those clients we silently ignore the
17178 * DBLSCAN flag on such connectors. For other connectors we will
17179 * reject modes with the DBLSCAN flag in encoder->compute_config().
17180 * And we always reject DBLSCAN modes in connector->mode_valid()
17181 * as we never want such modes on the connector's mode list.
17184 if (mode->vscan > 1)
17185 return MODE_NO_VSCAN;
17187 if (mode->flags & DRM_MODE_FLAG_HSKEW)
17188 return MODE_H_ILLEGAL;
17190 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
17191 DRM_MODE_FLAG_NCSYNC |
17192 DRM_MODE_FLAG_PCSYNC))
17195 if (mode->flags & (DRM_MODE_FLAG_BCAST |
17196 DRM_MODE_FLAG_PIXMUX |
17197 DRM_MODE_FLAG_CLKDIV2))
17200 /* Transcoder timing limits */
17201 if (INTEL_GEN(dev_priv) >= 11) {
17202 hdisplay_max = 16384;
17203 vdisplay_max = 8192;
17204 htotal_max = 16384;
17206 } else if (INTEL_GEN(dev_priv) >= 9 ||
17207 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
17208 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
17209 vdisplay_max = 4096;
17212 } else if (INTEL_GEN(dev_priv) >= 3) {
17213 hdisplay_max = 4096;
17214 vdisplay_max = 4096;
17218 hdisplay_max = 2048;
17219 vdisplay_max = 2048;
17224 if (mode->hdisplay > hdisplay_max ||
17225 mode->hsync_start > htotal_max ||
17226 mode->hsync_end > htotal_max ||
17227 mode->htotal > htotal_max)
17228 return MODE_H_ILLEGAL;
17230 if (mode->vdisplay > vdisplay_max ||
17231 mode->vsync_start > vtotal_max ||
17232 mode->vsync_end > vtotal_max ||
17233 mode->vtotal > vtotal_max)
17234 return MODE_V_ILLEGAL;
17236 if (INTEL_GEN(dev_priv) >= 5) {
17237 if (mode->hdisplay < 64 ||
17238 mode->htotal - mode->hdisplay < 32)
17239 return MODE_H_ILLEGAL;
17241 if (mode->vtotal - mode->vdisplay < 5)
17242 return MODE_V_ILLEGAL;
17244 if (mode->htotal - mode->hdisplay < 32)
17245 return MODE_H_ILLEGAL;
17247 if (mode->vtotal - mode->vdisplay < 3)
17248 return MODE_V_ILLEGAL;
17254 enum drm_mode_status
17255 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
17256 const struct drm_display_mode *mode)
17258 int plane_width_max, plane_height_max;
17261 * intel_mode_valid() should be
17262 * sufficient on older platforms.
17264 if (INTEL_GEN(dev_priv) < 9)
17268 * Most people will probably want a fullscreen
17269 * plane so let's not advertize modes that are
17270 * too big for that.
17272 if (INTEL_GEN(dev_priv) >= 11) {
17273 plane_width_max = 5120;
17274 plane_height_max = 4320;
17276 plane_width_max = 5120;
17277 plane_height_max = 4096;
17280 if (mode->hdisplay > plane_width_max)
17281 return MODE_H_ILLEGAL;
17283 if (mode->vdisplay > plane_height_max)
17284 return MODE_V_ILLEGAL;
17289 static const struct drm_mode_config_funcs intel_mode_funcs = {
17290 .fb_create = intel_user_framebuffer_create,
17291 .get_format_info = intel_get_format_info,
17292 .output_poll_changed = intel_fbdev_output_poll_changed,
17293 .mode_valid = intel_mode_valid,
17294 .atomic_check = intel_atomic_check,
17295 .atomic_commit = intel_atomic_commit,
17296 .atomic_state_alloc = intel_atomic_state_alloc,
17297 .atomic_state_clear = intel_atomic_state_clear,
17298 .atomic_state_free = intel_atomic_state_free,
17302 * intel_init_display_hooks - initialize the display modesetting hooks
17303 * @dev_priv: device private
17305 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
17307 intel_init_cdclk_hooks(dev_priv);
17309 if (INTEL_GEN(dev_priv) >= 9) {
17310 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
17311 dev_priv->display.get_initial_plane_config =
17312 skl_get_initial_plane_config;
17313 dev_priv->display.crtc_compute_clock = hsw_crtc_compute_clock;
17314 dev_priv->display.crtc_enable = hsw_crtc_enable;
17315 dev_priv->display.crtc_disable = hsw_crtc_disable;
17316 } else if (HAS_DDI(dev_priv)) {
17317 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
17318 dev_priv->display.get_initial_plane_config =
17319 i9xx_get_initial_plane_config;
17320 dev_priv->display.crtc_compute_clock =
17321 hsw_crtc_compute_clock;
17322 dev_priv->display.crtc_enable = hsw_crtc_enable;
17323 dev_priv->display.crtc_disable = hsw_crtc_disable;
17324 } else if (HAS_PCH_SPLIT(dev_priv)) {
17325 dev_priv->display.get_pipe_config = ilk_get_pipe_config;
17326 dev_priv->display.get_initial_plane_config =
17327 i9xx_get_initial_plane_config;
17328 dev_priv->display.crtc_compute_clock =
17329 ilk_crtc_compute_clock;
17330 dev_priv->display.crtc_enable = ilk_crtc_enable;
17331 dev_priv->display.crtc_disable = ilk_crtc_disable;
17332 } else if (IS_CHERRYVIEW(dev_priv)) {
17333 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17334 dev_priv->display.get_initial_plane_config =
17335 i9xx_get_initial_plane_config;
17336 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
17337 dev_priv->display.crtc_enable = valleyview_crtc_enable;
17338 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17339 } else if (IS_VALLEYVIEW(dev_priv)) {
17340 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17341 dev_priv->display.get_initial_plane_config =
17342 i9xx_get_initial_plane_config;
17343 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
17344 dev_priv->display.crtc_enable = valleyview_crtc_enable;
17345 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17346 } else if (IS_G4X(dev_priv)) {
17347 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17348 dev_priv->display.get_initial_plane_config =
17349 i9xx_get_initial_plane_config;
17350 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
17351 dev_priv->display.crtc_enable = i9xx_crtc_enable;
17352 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17353 } else if (IS_PINEVIEW(dev_priv)) {
17354 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17355 dev_priv->display.get_initial_plane_config =
17356 i9xx_get_initial_plane_config;
17357 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
17358 dev_priv->display.crtc_enable = i9xx_crtc_enable;
17359 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17360 } else if (!IS_GEN(dev_priv, 2)) {
17361 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17362 dev_priv->display.get_initial_plane_config =
17363 i9xx_get_initial_plane_config;
17364 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
17365 dev_priv->display.crtc_enable = i9xx_crtc_enable;
17366 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17368 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17369 dev_priv->display.get_initial_plane_config =
17370 i9xx_get_initial_plane_config;
17371 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
17372 dev_priv->display.crtc_enable = i9xx_crtc_enable;
17373 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17376 if (IS_GEN(dev_priv, 5)) {
17377 dev_priv->display.fdi_link_train = ilk_fdi_link_train;
17378 } else if (IS_GEN(dev_priv, 6)) {
17379 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
17380 } else if (IS_IVYBRIDGE(dev_priv)) {
17381 /* FIXME: detect B0+ stepping and use auto training */
17382 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
17385 if (INTEL_GEN(dev_priv) >= 9)
17386 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
17388 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
17392 void intel_modeset_init_hw(struct drm_i915_private *i915)
17394 struct intel_cdclk_state *cdclk_state =
17395 to_intel_cdclk_state(i915->cdclk.obj.state);
17397 intel_update_cdclk(i915);
17398 intel_dump_cdclk_config(&i915->cdclk.hw, "Current CDCLK");
17399 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw;
17402 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state)
17404 struct drm_plane *plane;
17405 struct drm_crtc *crtc;
17407 drm_for_each_crtc(crtc, state->dev) {
17408 struct drm_crtc_state *crtc_state;
17410 crtc_state = drm_atomic_get_crtc_state(state, crtc);
17411 if (IS_ERR(crtc_state))
17412 return PTR_ERR(crtc_state);
17415 drm_for_each_plane(plane, state->dev) {
17416 struct drm_plane_state *plane_state;
17418 plane_state = drm_atomic_get_plane_state(state, plane);
17419 if (IS_ERR(plane_state))
17420 return PTR_ERR(plane_state);
17427 * Calculate what we think the watermarks should be for the state we've read
17428 * out of the hardware and then immediately program those watermarks so that
17429 * we ensure the hardware settings match our internal state.
17431 * We can calculate what we think WM's should be by creating a duplicate of the
17432 * current state (which was constructed during hardware readout) and running it
17433 * through the atomic check code to calculate new watermark values in the
17436 static void sanitize_watermarks(struct drm_i915_private *dev_priv)
17438 struct drm_atomic_state *state;
17439 struct intel_atomic_state *intel_state;
17440 struct intel_crtc *crtc;
17441 struct intel_crtc_state *crtc_state;
17442 struct drm_modeset_acquire_ctx ctx;
17446 /* Only supported on platforms that use atomic watermark design */
17447 if (!dev_priv->display.optimize_watermarks)
17450 state = drm_atomic_state_alloc(&dev_priv->drm);
17451 if (drm_WARN_ON(&dev_priv->drm, !state))
17454 intel_state = to_intel_atomic_state(state);
17456 drm_modeset_acquire_init(&ctx, 0);
17459 state->acquire_ctx = &ctx;
17462 * Hardware readout is the only time we don't want to calculate
17463 * intermediate watermarks (since we don't trust the current
17466 if (!HAS_GMCH(dev_priv))
17467 intel_state->skip_intermediate_wm = true;
17469 ret = sanitize_watermarks_add_affected(state);
17473 ret = intel_atomic_check(&dev_priv->drm, state);
17477 /* Write calculated watermark values back */
17478 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
17479 crtc_state->wm.need_postvbl_update = true;
17480 dev_priv->display.optimize_watermarks(intel_state, crtc);
17482 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
17486 if (ret == -EDEADLK) {
17487 drm_atomic_state_clear(state);
17488 drm_modeset_backoff(&ctx);
17493 * If we fail here, it means that the hardware appears to be
17494 * programmed in a way that shouldn't be possible, given our
17495 * understanding of watermark requirements. This might mean a
17496 * mistake in the hardware readout code or a mistake in the
17497 * watermark calculations for a given platform. Raise a WARN
17498 * so that this is noticeable.
17500 * If this actually happens, we'll have to just leave the
17501 * BIOS-programmed watermarks untouched and hope for the best.
17503 drm_WARN(&dev_priv->drm, ret,
17504 "Could not determine valid watermarks for inherited state\n");
17506 drm_atomic_state_put(state);
17508 drm_modeset_drop_locks(&ctx);
17509 drm_modeset_acquire_fini(&ctx);
17512 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
17514 if (IS_GEN(dev_priv, 5)) {
17516 intel_de_read(dev_priv, FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
17518 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
17519 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
17520 dev_priv->fdi_pll_freq = 270000;
17525 drm_dbg(&dev_priv->drm, "FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
17528 static int intel_initial_commit(struct drm_device *dev)
17530 struct drm_atomic_state *state = NULL;
17531 struct drm_modeset_acquire_ctx ctx;
17532 struct intel_crtc *crtc;
17535 state = drm_atomic_state_alloc(dev);
17539 drm_modeset_acquire_init(&ctx, 0);
17542 state->acquire_ctx = &ctx;
17544 for_each_intel_crtc(dev, crtc) {
17545 struct intel_crtc_state *crtc_state =
17546 intel_atomic_get_crtc_state(state, crtc);
17548 if (IS_ERR(crtc_state)) {
17549 ret = PTR_ERR(crtc_state);
17553 if (crtc_state->hw.active) {
17554 ret = drm_atomic_add_affected_planes(state, &crtc->base);
17559 * FIXME hack to force a LUT update to avoid the
17560 * plane update forcing the pipe gamma on without
17561 * having a proper LUT loaded. Remove once we
17562 * have readout for pipe gamma enable.
17564 crtc_state->uapi.color_mgmt_changed = true;
17567 * FIXME hack to force full modeset when DSC is being
17570 * As long as we do not have full state readout and
17571 * config comparison of crtc_state->dsc, we have no way
17572 * to ensure reliable fastset. Remove once we have
17575 if (crtc_state->dsc.compression_enable) {
17576 ret = drm_atomic_add_affected_connectors(state,
17580 crtc_state->uapi.mode_changed = true;
17581 drm_dbg_kms(dev, "Force full modeset for DSC\n");
17586 ret = drm_atomic_commit(state);
17589 if (ret == -EDEADLK) {
17590 drm_atomic_state_clear(state);
17591 drm_modeset_backoff(&ctx);
17595 drm_atomic_state_put(state);
17597 drm_modeset_drop_locks(&ctx);
17598 drm_modeset_acquire_fini(&ctx);
17603 static void intel_mode_config_init(struct drm_i915_private *i915)
17605 struct drm_mode_config *mode_config = &i915->drm.mode_config;
17607 drm_mode_config_init(&i915->drm);
17608 INIT_LIST_HEAD(&i915->global_obj_list);
17610 mode_config->min_width = 0;
17611 mode_config->min_height = 0;
17613 mode_config->preferred_depth = 24;
17614 mode_config->prefer_shadow = 1;
17616 mode_config->allow_fb_modifiers = true;
17618 mode_config->funcs = &intel_mode_funcs;
17621 * Maximum framebuffer dimensions, chosen to match
17622 * the maximum render engine surface size on gen4+.
17624 if (INTEL_GEN(i915) >= 7) {
17625 mode_config->max_width = 16384;
17626 mode_config->max_height = 16384;
17627 } else if (INTEL_GEN(i915) >= 4) {
17628 mode_config->max_width = 8192;
17629 mode_config->max_height = 8192;
17630 } else if (IS_GEN(i915, 3)) {
17631 mode_config->max_width = 4096;
17632 mode_config->max_height = 4096;
17634 mode_config->max_width = 2048;
17635 mode_config->max_height = 2048;
17638 if (IS_I845G(i915) || IS_I865G(i915)) {
17639 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
17640 mode_config->cursor_height = 1023;
17641 } else if (IS_GEN(i915, 2)) {
17642 mode_config->cursor_width = 64;
17643 mode_config->cursor_height = 64;
17645 mode_config->cursor_width = 256;
17646 mode_config->cursor_height = 256;
17650 static void intel_mode_config_cleanup(struct drm_i915_private *i915)
17652 intel_atomic_global_obj_cleanup(i915);
17653 drm_mode_config_cleanup(&i915->drm);
17656 static void plane_config_fini(struct intel_initial_plane_config *plane_config)
17658 if (plane_config->fb) {
17659 struct drm_framebuffer *fb = &plane_config->fb->base;
17661 /* We may only have the stub and not a full framebuffer */
17662 if (drm_framebuffer_read_refcount(fb))
17663 drm_framebuffer_put(fb);
17668 if (plane_config->vma)
17669 i915_vma_put(plane_config->vma);
17672 /* part #1: call before irq install */
17673 int intel_modeset_init_noirq(struct drm_i915_private *i915)
17677 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
17678 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
17679 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
17681 intel_mode_config_init(i915);
17683 ret = intel_cdclk_init(i915);
17687 ret = intel_bw_init(i915);
17691 init_llist_head(&i915->atomic_helper.free_list);
17692 INIT_WORK(&i915->atomic_helper.free_work,
17693 intel_atomic_helper_free_state_worker);
17695 intel_init_quirks(i915);
17697 intel_fbc_init(i915);
17702 /* part #2: call after irq install */
17703 int intel_modeset_init(struct drm_i915_private *i915)
17705 struct drm_device *dev = &i915->drm;
17707 struct intel_crtc *crtc;
17710 intel_init_pm(i915);
17712 intel_panel_sanitize_ssc(i915);
17714 intel_gmbus_setup(i915);
17716 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n",
17717 INTEL_NUM_PIPES(i915),
17718 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
17720 if (HAS_DISPLAY(i915) && INTEL_DISPLAY_ENABLED(i915)) {
17721 for_each_pipe(i915, pipe) {
17722 ret = intel_crtc_init(i915, pipe);
17724 intel_mode_config_cleanup(i915);
17730 intel_plane_possible_crtcs_init(i915);
17731 intel_shared_dpll_init(dev);
17732 intel_update_fdi_pll_freq(i915);
17734 intel_update_czclk(i915);
17735 intel_modeset_init_hw(i915);
17737 intel_hdcp_component_init(i915);
17739 if (i915->max_cdclk_freq == 0)
17740 intel_update_max_cdclk(i915);
17742 /* Just disable it once at startup */
17743 intel_vga_disable(i915);
17744 intel_setup_outputs(i915);
17746 drm_modeset_lock_all(dev);
17747 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
17748 drm_modeset_unlock_all(dev);
17750 for_each_intel_crtc(dev, crtc) {
17751 struct intel_initial_plane_config plane_config = {};
17757 * Note that reserving the BIOS fb up front prevents us
17758 * from stuffing other stolen allocations like the ring
17759 * on top. This prevents some ugliness at boot time, and
17760 * can even allow for smooth boot transitions if the BIOS
17761 * fb is large enough for the active pipe configuration.
17763 i915->display.get_initial_plane_config(crtc, &plane_config);
17766 * If the fb is shared between multiple heads, we'll
17767 * just get the first one.
17769 intel_find_initial_plane_obj(crtc, &plane_config);
17771 plane_config_fini(&plane_config);
17775 * Make sure hardware watermarks really match the state we read out.
17776 * Note that we need to do this after reconstructing the BIOS fb's
17777 * since the watermark calculation done here will use pstate->fb.
17779 if (!HAS_GMCH(i915))
17780 sanitize_watermarks(i915);
17783 * Force all active planes to recompute their states. So that on
17784 * mode_setcrtc after probe, all the intel_plane_state variables
17785 * are already calculated and there is no assert_plane warnings
17788 ret = intel_initial_commit(dev);
17790 drm_dbg_kms(&i915->drm, "Initial commit in probe failed.\n");
17795 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17797 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17798 /* 640x480@60Hz, ~25175 kHz */
17799 struct dpll clock = {
17809 drm_WARN_ON(&dev_priv->drm,
17810 i9xx_calc_dpll_params(48000, &clock) != 25154);
17812 drm_dbg_kms(&dev_priv->drm,
17813 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
17814 pipe_name(pipe), clock.vco, clock.dot);
17816 fp = i9xx_dpll_compute_fp(&clock);
17817 dpll = DPLL_DVO_2X_MODE |
17818 DPLL_VGA_MODE_DIS |
17819 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
17820 PLL_P2_DIVIDE_BY_4 |
17821 PLL_REF_INPUT_DREFCLK |
17824 intel_de_write(dev_priv, FP0(pipe), fp);
17825 intel_de_write(dev_priv, FP1(pipe), fp);
17827 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
17828 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
17829 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
17830 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
17831 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
17832 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
17833 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
17836 * Apparently we need to have VGA mode enabled prior to changing
17837 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
17838 * dividers, even though the register value does change.
17840 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
17841 intel_de_write(dev_priv, DPLL(pipe), dpll);
17843 /* Wait for the clocks to stabilize. */
17844 intel_de_posting_read(dev_priv, DPLL(pipe));
17847 /* The pixel multiplier can only be updated once the
17848 * DPLL is enabled and the clocks are stable.
17850 * So write it again.
17852 intel_de_write(dev_priv, DPLL(pipe), dpll);
17854 /* We do this three times for luck */
17855 for (i = 0; i < 3 ; i++) {
17856 intel_de_write(dev_priv, DPLL(pipe), dpll);
17857 intel_de_posting_read(dev_priv, DPLL(pipe));
17858 udelay(150); /* wait for warmup */
17861 intel_de_write(dev_priv, PIPECONF(pipe),
17862 PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
17863 intel_de_posting_read(dev_priv, PIPECONF(pipe));
17865 intel_wait_for_pipe_scanline_moving(crtc);
17868 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17870 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17872 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
17875 drm_WARN_ON(&dev_priv->drm,
17876 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) &
17877 DISPLAY_PLANE_ENABLE);
17878 drm_WARN_ON(&dev_priv->drm,
17879 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) &
17880 DISPLAY_PLANE_ENABLE);
17881 drm_WARN_ON(&dev_priv->drm,
17882 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) &
17883 DISPLAY_PLANE_ENABLE);
17884 drm_WARN_ON(&dev_priv->drm,
17885 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE);
17886 drm_WARN_ON(&dev_priv->drm,
17887 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE);
17889 intel_de_write(dev_priv, PIPECONF(pipe), 0);
17890 intel_de_posting_read(dev_priv, PIPECONF(pipe));
17892 intel_wait_for_pipe_scanline_stopped(crtc);
17894 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
17895 intel_de_posting_read(dev_priv, DPLL(pipe));
17899 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
17901 struct intel_crtc *crtc;
17903 if (INTEL_GEN(dev_priv) >= 4)
17906 for_each_intel_crtc(&dev_priv->drm, crtc) {
17907 struct intel_plane *plane =
17908 to_intel_plane(crtc->base.primary);
17909 struct intel_crtc *plane_crtc;
17912 if (!plane->get_hw_state(plane, &pipe))
17915 if (pipe == crtc->pipe)
17918 drm_dbg_kms(&dev_priv->drm,
17919 "[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
17920 plane->base.base.id, plane->base.name);
17922 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17923 intel_plane_disable_noatomic(plane_crtc, plane);
17927 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
17929 struct drm_device *dev = crtc->base.dev;
17930 struct intel_encoder *encoder;
17932 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
17938 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
17940 struct drm_device *dev = encoder->base.dev;
17941 struct intel_connector *connector;
17943 for_each_connector_on_encoder(dev, &encoder->base, connector)
17949 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
17950 enum pipe pch_transcoder)
17952 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
17953 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
17956 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state *crtc_state)
17958 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
17959 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
17960 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
17962 if (INTEL_GEN(dev_priv) >= 9 ||
17963 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
17964 i915_reg_t reg = CHICKEN_TRANS(cpu_transcoder);
17967 if (transcoder_is_dsi(cpu_transcoder))
17970 val = intel_de_read(dev_priv, reg);
17971 val &= ~HSW_FRAME_START_DELAY_MASK;
17972 val |= HSW_FRAME_START_DELAY(0);
17973 intel_de_write(dev_priv, reg, val);
17975 i915_reg_t reg = PIPECONF(cpu_transcoder);
17978 val = intel_de_read(dev_priv, reg);
17979 val &= ~PIPECONF_FRAME_START_DELAY_MASK;
17980 val |= PIPECONF_FRAME_START_DELAY(0);
17981 intel_de_write(dev_priv, reg, val);
17984 if (!crtc_state->has_pch_encoder)
17987 if (HAS_PCH_IBX(dev_priv)) {
17988 i915_reg_t reg = PCH_TRANSCONF(crtc->pipe);
17991 val = intel_de_read(dev_priv, reg);
17992 val &= ~TRANS_FRAME_START_DELAY_MASK;
17993 val |= TRANS_FRAME_START_DELAY(0);
17994 intel_de_write(dev_priv, reg, val);
17996 enum pipe pch_transcoder = intel_crtc_pch_transcoder(crtc);
17997 i915_reg_t reg = TRANS_CHICKEN2(pch_transcoder);
18000 val = intel_de_read(dev_priv, reg);
18001 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
18002 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
18003 intel_de_write(dev_priv, reg, val);
18007 static void intel_sanitize_crtc(struct intel_crtc *crtc,
18008 struct drm_modeset_acquire_ctx *ctx)
18010 struct drm_device *dev = crtc->base.dev;
18011 struct drm_i915_private *dev_priv = to_i915(dev);
18012 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
18014 if (crtc_state->hw.active) {
18015 struct intel_plane *plane;
18017 /* Clear any frame start delays used for debugging left by the BIOS */
18018 intel_sanitize_frame_start_delay(crtc_state);
18020 /* Disable everything but the primary plane */
18021 for_each_intel_plane_on_crtc(dev, crtc, plane) {
18022 const struct intel_plane_state *plane_state =
18023 to_intel_plane_state(plane->base.state);
18025 if (plane_state->uapi.visible &&
18026 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
18027 intel_plane_disable_noatomic(crtc, plane);
18031 * Disable any background color set by the BIOS, but enable the
18032 * gamma and CSC to match how we program our planes.
18034 if (INTEL_GEN(dev_priv) >= 9)
18035 intel_de_write(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe),
18036 SKL_BOTTOM_COLOR_GAMMA_ENABLE | SKL_BOTTOM_COLOR_CSC_ENABLE);
18039 /* Adjust the state of the output pipe according to whether we
18040 * have active connectors/encoders. */
18041 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc))
18042 intel_crtc_disable_noatomic(crtc, ctx);
18044 if (crtc_state->hw.active || HAS_GMCH(dev_priv)) {
18046 * We start out with underrun reporting disabled to avoid races.
18047 * For correct bookkeeping mark this on active crtcs.
18049 * Also on gmch platforms we dont have any hardware bits to
18050 * disable the underrun reporting. Which means we need to start
18051 * out with underrun reporting disabled also on inactive pipes,
18052 * since otherwise we'll complain about the garbage we read when
18053 * e.g. coming up after runtime pm.
18055 * No protection against concurrent access is required - at
18056 * worst a fifo underrun happens which also sets this to false.
18058 crtc->cpu_fifo_underrun_disabled = true;
18060 * We track the PCH trancoder underrun reporting state
18061 * within the crtc. With crtc for pipe A housing the underrun
18062 * reporting state for PCH transcoder A, crtc for pipe B housing
18063 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
18064 * and marking underrun reporting as disabled for the non-existing
18065 * PCH transcoders B and C would prevent enabling the south
18066 * error interrupt (see cpt_can_enable_serr_int()).
18068 if (has_pch_trancoder(dev_priv, crtc->pipe))
18069 crtc->pch_fifo_underrun_disabled = true;
18073 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
18075 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
18078 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
18079 * the hardware when a high res displays plugged in. DPLL P
18080 * divider is zero, and the pipe timings are bonkers. We'll
18081 * try to disable everything in that case.
18083 * FIXME would be nice to be able to sanitize this state
18084 * without several WARNs, but for now let's take the easy
18087 return IS_GEN(dev_priv, 6) &&
18088 crtc_state->hw.active &&
18089 crtc_state->shared_dpll &&
18090 crtc_state->port_clock == 0;
18093 static void intel_sanitize_encoder(struct intel_encoder *encoder)
18095 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
18096 struct intel_connector *connector;
18097 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
18098 struct intel_crtc_state *crtc_state = crtc ?
18099 to_intel_crtc_state(crtc->base.state) : NULL;
18101 /* We need to check both for a crtc link (meaning that the
18102 * encoder is active and trying to read from a pipe) and the
18103 * pipe itself being active. */
18104 bool has_active_crtc = crtc_state &&
18105 crtc_state->hw.active;
18107 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
18108 drm_dbg_kms(&dev_priv->drm,
18109 "BIOS has misprogrammed the hardware. Disabling pipe %c\n",
18110 pipe_name(crtc->pipe));
18111 has_active_crtc = false;
18114 connector = intel_encoder_find_connector(encoder);
18115 if (connector && !has_active_crtc) {
18116 drm_dbg_kms(&dev_priv->drm,
18117 "[ENCODER:%d:%s] has active connectors but no active pipe!\n",
18118 encoder->base.base.id,
18119 encoder->base.name);
18121 /* Connector is active, but has no active pipe. This is
18122 * fallout from our resume register restoring. Disable
18123 * the encoder manually again. */
18125 struct drm_encoder *best_encoder;
18127 drm_dbg_kms(&dev_priv->drm,
18128 "[ENCODER:%d:%s] manually disabled\n",
18129 encoder->base.base.id,
18130 encoder->base.name);
18132 /* avoid oopsing in case the hooks consult best_encoder */
18133 best_encoder = connector->base.state->best_encoder;
18134 connector->base.state->best_encoder = &encoder->base;
18136 /* FIXME NULL atomic state passed! */
18137 if (encoder->disable)
18138 encoder->disable(NULL, encoder, crtc_state,
18139 connector->base.state);
18140 if (encoder->post_disable)
18141 encoder->post_disable(NULL, encoder, crtc_state,
18142 connector->base.state);
18144 connector->base.state->best_encoder = best_encoder;
18146 encoder->base.crtc = NULL;
18148 /* Inconsistent output/port/pipe state happens presumably due to
18149 * a bug in one of the get_hw_state functions. Or someplace else
18150 * in our code, like the register restore mess on resume. Clamp
18151 * things to off as a safer default. */
18153 connector->base.dpms = DRM_MODE_DPMS_OFF;
18154 connector->base.encoder = NULL;
18157 /* notify opregion of the sanitized encoder state */
18158 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
18160 if (INTEL_GEN(dev_priv) >= 11)
18161 icl_sanitize_encoder_pll_mapping(encoder);
18164 /* FIXME read out full plane state for all planes */
18165 static void readout_plane_state(struct drm_i915_private *dev_priv)
18167 struct intel_plane *plane;
18168 struct intel_crtc *crtc;
18170 for_each_intel_plane(&dev_priv->drm, plane) {
18171 struct intel_plane_state *plane_state =
18172 to_intel_plane_state(plane->base.state);
18173 struct intel_crtc_state *crtc_state;
18174 enum pipe pipe = PIPE_A;
18177 visible = plane->get_hw_state(plane, &pipe);
18179 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
18180 crtc_state = to_intel_crtc_state(crtc->base.state);
18182 intel_set_plane_visible(crtc_state, plane_state, visible);
18184 drm_dbg_kms(&dev_priv->drm,
18185 "[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
18186 plane->base.base.id, plane->base.name,
18187 enableddisabled(visible), pipe_name(pipe));
18190 for_each_intel_crtc(&dev_priv->drm, crtc) {
18191 struct intel_crtc_state *crtc_state =
18192 to_intel_crtc_state(crtc->base.state);
18194 fixup_active_planes(crtc_state);
18198 static void intel_modeset_readout_hw_state(struct drm_device *dev)
18200 struct drm_i915_private *dev_priv = to_i915(dev);
18201 struct intel_cdclk_state *cdclk_state =
18202 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
18204 struct intel_crtc *crtc;
18205 struct intel_encoder *encoder;
18206 struct intel_connector *connector;
18207 struct drm_connector_list_iter conn_iter;
18208 u8 active_pipes = 0;
18210 for_each_intel_crtc(dev, crtc) {
18211 struct intel_crtc_state *crtc_state =
18212 to_intel_crtc_state(crtc->base.state);
18214 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
18215 intel_crtc_free_hw_state(crtc_state);
18216 intel_crtc_state_reset(crtc_state, crtc);
18218 crtc_state->hw.active = crtc_state->hw.enable =
18219 dev_priv->display.get_pipe_config(crtc, crtc_state);
18221 crtc->base.enabled = crtc_state->hw.enable;
18222 crtc->active = crtc_state->hw.active;
18224 if (crtc_state->hw.active)
18225 active_pipes |= BIT(crtc->pipe);
18227 drm_dbg_kms(&dev_priv->drm,
18228 "[CRTC:%d:%s] hw state readout: %s\n",
18229 crtc->base.base.id, crtc->base.name,
18230 enableddisabled(crtc_state->hw.active));
18233 dev_priv->active_pipes = cdclk_state->active_pipes = active_pipes;
18235 readout_plane_state(dev_priv);
18237 intel_dpll_readout_hw_state(dev_priv);
18239 for_each_intel_encoder(dev, encoder) {
18242 if (encoder->get_hw_state(encoder, &pipe)) {
18243 struct intel_crtc_state *crtc_state;
18245 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
18246 crtc_state = to_intel_crtc_state(crtc->base.state);
18248 encoder->base.crtc = &crtc->base;
18249 encoder->get_config(encoder, crtc_state);
18251 encoder->base.crtc = NULL;
18254 drm_dbg_kms(&dev_priv->drm,
18255 "[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
18256 encoder->base.base.id, encoder->base.name,
18257 enableddisabled(encoder->base.crtc),
18261 drm_connector_list_iter_begin(dev, &conn_iter);
18262 for_each_intel_connector_iter(connector, &conn_iter) {
18263 if (connector->get_hw_state(connector)) {
18264 struct intel_crtc_state *crtc_state;
18265 struct intel_crtc *crtc;
18267 connector->base.dpms = DRM_MODE_DPMS_ON;
18269 encoder = intel_attached_encoder(connector);
18270 connector->base.encoder = &encoder->base;
18272 crtc = to_intel_crtc(encoder->base.crtc);
18273 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
18275 if (crtc_state && crtc_state->hw.active) {
18277 * This has to be done during hardware readout
18278 * because anything calling .crtc_disable may
18279 * rely on the connector_mask being accurate.
18281 crtc_state->uapi.connector_mask |=
18282 drm_connector_mask(&connector->base);
18283 crtc_state->uapi.encoder_mask |=
18284 drm_encoder_mask(&encoder->base);
18287 connector->base.dpms = DRM_MODE_DPMS_OFF;
18288 connector->base.encoder = NULL;
18290 drm_dbg_kms(&dev_priv->drm,
18291 "[CONNECTOR:%d:%s] hw state readout: %s\n",
18292 connector->base.base.id, connector->base.name,
18293 enableddisabled(connector->base.encoder));
18295 drm_connector_list_iter_end(&conn_iter);
18297 for_each_intel_crtc(dev, crtc) {
18298 struct intel_bw_state *bw_state =
18299 to_intel_bw_state(dev_priv->bw_obj.state);
18300 struct intel_crtc_state *crtc_state =
18301 to_intel_crtc_state(crtc->base.state);
18302 struct intel_plane *plane;
18305 if (crtc_state->hw.active) {
18306 struct drm_display_mode *mode = &crtc_state->hw.mode;
18308 intel_mode_from_pipe_config(&crtc_state->hw.adjusted_mode,
18311 *mode = crtc_state->hw.adjusted_mode;
18312 mode->hdisplay = crtc_state->pipe_src_w;
18313 mode->vdisplay = crtc_state->pipe_src_h;
18316 * The initial mode needs to be set in order to keep
18317 * the atomic core happy. It wants a valid mode if the
18318 * crtc's enabled, so we do the above call.
18320 * But we don't set all the derived state fully, hence
18321 * set a flag to indicate that a full recalculation is
18322 * needed on the next commit.
18324 mode->private_flags = I915_MODE_FLAG_INHERITED;
18326 intel_crtc_compute_pixel_rate(crtc_state);
18328 intel_crtc_update_active_timings(crtc_state);
18330 intel_crtc_copy_hw_to_uapi_state(crtc_state);
18333 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
18334 const struct intel_plane_state *plane_state =
18335 to_intel_plane_state(plane->base.state);
18338 * FIXME don't have the fb yet, so can't
18339 * use intel_plane_data_rate() :(
18341 if (plane_state->uapi.visible)
18342 crtc_state->data_rate[plane->id] =
18343 4 * crtc_state->pixel_rate;
18345 * FIXME don't have the fb yet, so can't
18346 * use plane->min_cdclk() :(
18348 if (plane_state->uapi.visible && plane->min_cdclk) {
18349 if (crtc_state->double_wide ||
18350 INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
18351 crtc_state->min_cdclk[plane->id] =
18352 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
18354 crtc_state->min_cdclk[plane->id] =
18355 crtc_state->pixel_rate;
18357 drm_dbg_kms(&dev_priv->drm,
18358 "[PLANE:%d:%s] min_cdclk %d kHz\n",
18359 plane->base.base.id, plane->base.name,
18360 crtc_state->min_cdclk[plane->id]);
18363 if (crtc_state->hw.active) {
18364 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
18365 if (drm_WARN_ON(dev, min_cdclk < 0))
18369 cdclk_state->min_cdclk[crtc->pipe] = min_cdclk;
18370 cdclk_state->min_voltage_level[crtc->pipe] =
18371 crtc_state->min_voltage_level;
18373 intel_bw_crtc_update(bw_state, crtc_state);
18375 intel_pipe_config_sanity_check(dev_priv, crtc_state);
18380 get_encoder_power_domains(struct drm_i915_private *dev_priv)
18382 struct intel_encoder *encoder;
18384 for_each_intel_encoder(&dev_priv->drm, encoder) {
18385 struct intel_crtc_state *crtc_state;
18387 if (!encoder->get_power_domains)
18391 * MST-primary and inactive encoders don't have a crtc state
18392 * and neither of these require any power domain references.
18394 if (!encoder->base.crtc)
18397 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
18398 encoder->get_power_domains(encoder, crtc_state);
18402 static void intel_early_display_was(struct drm_i915_private *dev_priv)
18405 * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl
18406 * Also known as Wa_14010480278.
18408 if (IS_GEN_RANGE(dev_priv, 10, 12) || IS_GEMINILAKE(dev_priv))
18409 intel_de_write(dev_priv, GEN9_CLKGATE_DIS_0,
18410 intel_de_read(dev_priv, GEN9_CLKGATE_DIS_0) | DARBF_GATING_DIS);
18412 if (IS_HASWELL(dev_priv)) {
18414 * WaRsPkgCStateDisplayPMReq:hsw
18415 * System hang if this isn't done before disabling all planes!
18417 intel_de_write(dev_priv, CHICKEN_PAR1_1,
18418 intel_de_read(dev_priv, CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
18422 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
18423 enum port port, i915_reg_t hdmi_reg)
18425 u32 val = intel_de_read(dev_priv, hdmi_reg);
18427 if (val & SDVO_ENABLE ||
18428 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
18431 drm_dbg_kms(&dev_priv->drm,
18432 "Sanitizing transcoder select for HDMI %c\n",
18435 val &= ~SDVO_PIPE_SEL_MASK;
18436 val |= SDVO_PIPE_SEL(PIPE_A);
18438 intel_de_write(dev_priv, hdmi_reg, val);
18441 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
18442 enum port port, i915_reg_t dp_reg)
18444 u32 val = intel_de_read(dev_priv, dp_reg);
18446 if (val & DP_PORT_EN ||
18447 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
18450 drm_dbg_kms(&dev_priv->drm,
18451 "Sanitizing transcoder select for DP %c\n",
18454 val &= ~DP_PIPE_SEL_MASK;
18455 val |= DP_PIPE_SEL(PIPE_A);
18457 intel_de_write(dev_priv, dp_reg, val);
18460 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
18463 * The BIOS may select transcoder B on some of the PCH
18464 * ports even it doesn't enable the port. This would trip
18465 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
18466 * Sanitize the transcoder select bits to prevent that. We
18467 * assume that the BIOS never actually enabled the port,
18468 * because if it did we'd actually have to toggle the port
18469 * on and back off to make the transcoder A select stick
18470 * (see. intel_dp_link_down(), intel_disable_hdmi(),
18471 * intel_disable_sdvo()).
18473 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
18474 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
18475 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
18477 /* PCH SDVOB multiplex with HDMIB */
18478 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
18479 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
18480 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
18483 /* Scan out the current hw modeset state,
18484 * and sanitizes it to the current state
18487 intel_modeset_setup_hw_state(struct drm_device *dev,
18488 struct drm_modeset_acquire_ctx *ctx)
18490 struct drm_i915_private *dev_priv = to_i915(dev);
18491 struct intel_encoder *encoder;
18492 struct intel_crtc *crtc;
18493 intel_wakeref_t wakeref;
18495 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
18497 intel_early_display_was(dev_priv);
18498 intel_modeset_readout_hw_state(dev);
18500 /* HW state is read out, now we need to sanitize this mess. */
18502 /* Sanitize the TypeC port mode upfront, encoders depend on this */
18503 for_each_intel_encoder(dev, encoder) {
18504 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
18506 /* We need to sanitize only the MST primary port. */
18507 if (encoder->type != INTEL_OUTPUT_DP_MST &&
18508 intel_phy_is_tc(dev_priv, phy))
18509 intel_tc_port_sanitize(enc_to_dig_port(encoder));
18512 get_encoder_power_domains(dev_priv);
18514 if (HAS_PCH_IBX(dev_priv))
18515 ibx_sanitize_pch_ports(dev_priv);
18518 * intel_sanitize_plane_mapping() may need to do vblank
18519 * waits, so we need vblank interrupts restored beforehand.
18521 for_each_intel_crtc(&dev_priv->drm, crtc) {
18522 struct intel_crtc_state *crtc_state =
18523 to_intel_crtc_state(crtc->base.state);
18525 drm_crtc_vblank_reset(&crtc->base);
18527 if (crtc_state->hw.active)
18528 intel_crtc_vblank_on(crtc_state);
18531 intel_sanitize_plane_mapping(dev_priv);
18533 for_each_intel_encoder(dev, encoder)
18534 intel_sanitize_encoder(encoder);
18536 for_each_intel_crtc(&dev_priv->drm, crtc) {
18537 struct intel_crtc_state *crtc_state =
18538 to_intel_crtc_state(crtc->base.state);
18540 intel_sanitize_crtc(crtc, ctx);
18541 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
18544 intel_modeset_update_connector_atomic_state(dev);
18546 intel_dpll_sanitize_state(dev_priv);
18548 if (IS_G4X(dev_priv)) {
18549 g4x_wm_get_hw_state(dev_priv);
18550 g4x_wm_sanitize(dev_priv);
18551 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
18552 vlv_wm_get_hw_state(dev_priv);
18553 vlv_wm_sanitize(dev_priv);
18554 } else if (INTEL_GEN(dev_priv) >= 9) {
18555 skl_wm_get_hw_state(dev_priv);
18556 } else if (HAS_PCH_SPLIT(dev_priv)) {
18557 ilk_wm_get_hw_state(dev_priv);
18560 for_each_intel_crtc(dev, crtc) {
18561 struct intel_crtc_state *crtc_state =
18562 to_intel_crtc_state(crtc->base.state);
18565 put_domains = modeset_get_crtc_power_domains(crtc_state);
18566 if (drm_WARN_ON(dev, put_domains))
18567 modeset_put_power_domains(dev_priv, put_domains);
18570 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
18573 void intel_display_resume(struct drm_device *dev)
18575 struct drm_i915_private *dev_priv = to_i915(dev);
18576 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
18577 struct drm_modeset_acquire_ctx ctx;
18580 dev_priv->modeset_restore_state = NULL;
18582 state->acquire_ctx = &ctx;
18584 drm_modeset_acquire_init(&ctx, 0);
18587 ret = drm_modeset_lock_all_ctx(dev, &ctx);
18588 if (ret != -EDEADLK)
18591 drm_modeset_backoff(&ctx);
18595 ret = __intel_display_resume(dev, state, &ctx);
18597 intel_enable_ipc(dev_priv);
18598 drm_modeset_drop_locks(&ctx);
18599 drm_modeset_acquire_fini(&ctx);
18602 drm_err(&dev_priv->drm,
18603 "Restoring old state failed with %i\n", ret);
18605 drm_atomic_state_put(state);
18608 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
18610 struct intel_connector *connector;
18611 struct drm_connector_list_iter conn_iter;
18613 /* Kill all the work that may have been queued by hpd. */
18614 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
18615 for_each_intel_connector_iter(connector, &conn_iter) {
18616 if (connector->modeset_retry_work.func)
18617 cancel_work_sync(&connector->modeset_retry_work);
18618 if (connector->hdcp.shim) {
18619 cancel_delayed_work_sync(&connector->hdcp.check_work);
18620 cancel_work_sync(&connector->hdcp.prop_work);
18623 drm_connector_list_iter_end(&conn_iter);
18626 /* part #1: call before irq uninstall */
18627 void intel_modeset_driver_remove(struct drm_i915_private *i915)
18629 flush_workqueue(i915->flip_wq);
18630 flush_workqueue(i915->modeset_wq);
18632 flush_work(&i915->atomic_helper.free_work);
18633 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list));
18636 /* part #2: call after irq uninstall */
18637 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915)
18640 * Due to the hpd irq storm handling the hotplug work can re-arm the
18641 * poll handlers. Hence disable polling after hpd handling is shut down.
18643 intel_hpd_poll_fini(i915);
18646 * MST topology needs to be suspended so we don't have any calls to
18647 * fbdev after it's finalized. MST will be destroyed later as part of
18648 * drm_mode_config_cleanup()
18650 intel_dp_mst_suspend(i915);
18652 /* poll work can call into fbdev, hence clean that up afterwards */
18653 intel_fbdev_fini(i915);
18655 intel_unregister_dsm_handler();
18657 intel_fbc_global_disable(i915);
18659 /* flush any delayed tasks or pending work */
18660 flush_scheduled_work();
18662 intel_hdcp_component_fini(i915);
18664 intel_mode_config_cleanup(i915);
18666 intel_overlay_cleanup(i915);
18668 intel_gmbus_teardown(i915);
18670 destroy_workqueue(i915->flip_wq);
18671 destroy_workqueue(i915->modeset_wq);
18673 intel_fbc_cleanup_cfb(i915);
18676 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
18678 struct intel_display_error_state {
18680 u32 power_well_driver;
18682 struct intel_cursor_error_state {
18687 } cursor[I915_MAX_PIPES];
18689 struct intel_pipe_error_state {
18690 bool power_domain_on;
18693 } pipe[I915_MAX_PIPES];
18695 struct intel_plane_error_state {
18703 } plane[I915_MAX_PIPES];
18705 struct intel_transcoder_error_state {
18707 bool power_domain_on;
18708 enum transcoder cpu_transcoder;
18721 struct intel_display_error_state *
18722 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
18724 struct intel_display_error_state *error;
18725 int transcoders[] = {
18734 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
18736 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
18739 error = kzalloc(sizeof(*error), GFP_ATOMIC);
18743 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18744 error->power_well_driver = intel_de_read(dev_priv,
18745 HSW_PWR_WELL_CTL2);
18747 for_each_pipe(dev_priv, i) {
18748 error->pipe[i].power_domain_on =
18749 __intel_display_power_is_enabled(dev_priv,
18750 POWER_DOMAIN_PIPE(i));
18751 if (!error->pipe[i].power_domain_on)
18754 error->cursor[i].control = intel_de_read(dev_priv, CURCNTR(i));
18755 error->cursor[i].position = intel_de_read(dev_priv, CURPOS(i));
18756 error->cursor[i].base = intel_de_read(dev_priv, CURBASE(i));
18758 error->plane[i].control = intel_de_read(dev_priv, DSPCNTR(i));
18759 error->plane[i].stride = intel_de_read(dev_priv, DSPSTRIDE(i));
18760 if (INTEL_GEN(dev_priv) <= 3) {
18761 error->plane[i].size = intel_de_read(dev_priv,
18763 error->plane[i].pos = intel_de_read(dev_priv,
18766 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18767 error->plane[i].addr = intel_de_read(dev_priv,
18769 if (INTEL_GEN(dev_priv) >= 4) {
18770 error->plane[i].surface = intel_de_read(dev_priv,
18772 error->plane[i].tile_offset = intel_de_read(dev_priv,
18776 error->pipe[i].source = intel_de_read(dev_priv, PIPESRC(i));
18778 if (HAS_GMCH(dev_priv))
18779 error->pipe[i].stat = intel_de_read(dev_priv,
18783 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18784 enum transcoder cpu_transcoder = transcoders[i];
18786 if (!HAS_TRANSCODER(dev_priv, cpu_transcoder))
18789 error->transcoder[i].available = true;
18790 error->transcoder[i].power_domain_on =
18791 __intel_display_power_is_enabled(dev_priv,
18792 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
18793 if (!error->transcoder[i].power_domain_on)
18796 error->transcoder[i].cpu_transcoder = cpu_transcoder;
18798 error->transcoder[i].conf = intel_de_read(dev_priv,
18799 PIPECONF(cpu_transcoder));
18800 error->transcoder[i].htotal = intel_de_read(dev_priv,
18801 HTOTAL(cpu_transcoder));
18802 error->transcoder[i].hblank = intel_de_read(dev_priv,
18803 HBLANK(cpu_transcoder));
18804 error->transcoder[i].hsync = intel_de_read(dev_priv,
18805 HSYNC(cpu_transcoder));
18806 error->transcoder[i].vtotal = intel_de_read(dev_priv,
18807 VTOTAL(cpu_transcoder));
18808 error->transcoder[i].vblank = intel_de_read(dev_priv,
18809 VBLANK(cpu_transcoder));
18810 error->transcoder[i].vsync = intel_de_read(dev_priv,
18811 VSYNC(cpu_transcoder));
18817 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
18820 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
18821 struct intel_display_error_state *error)
18823 struct drm_i915_private *dev_priv = m->i915;
18829 err_printf(m, "Num Pipes: %d\n", INTEL_NUM_PIPES(dev_priv));
18830 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18831 err_printf(m, "PWR_WELL_CTL2: %08x\n",
18832 error->power_well_driver);
18833 for_each_pipe(dev_priv, i) {
18834 err_printf(m, "Pipe [%d]:\n", i);
18835 err_printf(m, " Power: %s\n",
18836 onoff(error->pipe[i].power_domain_on));
18837 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
18838 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
18840 err_printf(m, "Plane [%d]:\n", i);
18841 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
18842 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
18843 if (INTEL_GEN(dev_priv) <= 3) {
18844 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
18845 err_printf(m, " POS: %08x\n", error->plane[i].pos);
18847 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18848 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
18849 if (INTEL_GEN(dev_priv) >= 4) {
18850 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
18851 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
18854 err_printf(m, "Cursor [%d]:\n", i);
18855 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
18856 err_printf(m, " POS: %08x\n", error->cursor[i].position);
18857 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
18860 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18861 if (!error->transcoder[i].available)
18864 err_printf(m, "CPU transcoder: %s\n",
18865 transcoder_name(error->transcoder[i].cpu_transcoder));
18866 err_printf(m, " Power: %s\n",
18867 onoff(error->transcoder[i].power_domain_on));
18868 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
18869 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
18870 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
18871 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
18872 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
18873 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
18874 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);