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;
623 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
626 * Returns whether the given set of divisors are valid for a given refclk with
627 * the given connectors.
629 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
630 const struct intel_limit *limit,
631 const struct dpll *clock)
633 if (clock->n < limit->n.min || limit->n.max < clock->n)
634 INTELPllInvalid("n out of range\n");
635 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
636 INTELPllInvalid("p1 out of range\n");
637 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
638 INTELPllInvalid("m2 out of range\n");
639 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
640 INTELPllInvalid("m1 out of range\n");
642 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
643 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
644 if (clock->m1 <= clock->m2)
645 INTELPllInvalid("m1 <= m2\n");
647 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
648 !IS_GEN9_LP(dev_priv)) {
649 if (clock->p < limit->p.min || limit->p.max < clock->p)
650 INTELPllInvalid("p out of range\n");
651 if (clock->m < limit->m.min || limit->m.max < clock->m)
652 INTELPllInvalid("m out of range\n");
655 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
656 INTELPllInvalid("vco out of range\n");
657 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
658 * connector, etc., rather than just a single range.
660 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
661 INTELPllInvalid("dot out of range\n");
667 i9xx_select_p2_div(const struct intel_limit *limit,
668 const struct intel_crtc_state *crtc_state,
671 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
673 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
675 * For LVDS just rely on its current settings for dual-channel.
676 * We haven't figured out how to reliably set up different
677 * single/dual channel state, if we even can.
679 if (intel_is_dual_link_lvds(dev_priv))
680 return limit->p2.p2_fast;
682 return limit->p2.p2_slow;
684 if (target < limit->p2.dot_limit)
685 return limit->p2.p2_slow;
687 return limit->p2.p2_fast;
692 * Returns a set of divisors for the desired target clock with the given
693 * refclk, or FALSE. The returned values represent the clock equation:
694 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
696 * Target and reference clocks are specified in kHz.
698 * If match_clock is provided, then best_clock P divider must match the P
699 * divider from @match_clock used for LVDS downclocking.
702 i9xx_find_best_dpll(const struct intel_limit *limit,
703 struct intel_crtc_state *crtc_state,
704 int target, int refclk, struct dpll *match_clock,
705 struct dpll *best_clock)
707 struct drm_device *dev = crtc_state->uapi.crtc->dev;
711 memset(best_clock, 0, sizeof(*best_clock));
713 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
715 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
717 for (clock.m2 = limit->m2.min;
718 clock.m2 <= limit->m2.max; clock.m2++) {
719 if (clock.m2 >= clock.m1)
721 for (clock.n = limit->n.min;
722 clock.n <= limit->n.max; clock.n++) {
723 for (clock.p1 = limit->p1.min;
724 clock.p1 <= limit->p1.max; clock.p1++) {
727 i9xx_calc_dpll_params(refclk, &clock);
728 if (!intel_PLL_is_valid(to_i915(dev),
733 clock.p != match_clock->p)
736 this_err = abs(clock.dot - target);
737 if (this_err < err) {
746 return (err != target);
750 * Returns a set of divisors for the desired target clock with the given
751 * refclk, or FALSE. The returned values represent the clock equation:
752 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
754 * Target and reference clocks are specified in kHz.
756 * If match_clock is provided, then best_clock P divider must match the P
757 * divider from @match_clock used for LVDS downclocking.
760 pnv_find_best_dpll(const struct intel_limit *limit,
761 struct intel_crtc_state *crtc_state,
762 int target, int refclk, struct dpll *match_clock,
763 struct dpll *best_clock)
765 struct drm_device *dev = crtc_state->uapi.crtc->dev;
769 memset(best_clock, 0, sizeof(*best_clock));
771 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
773 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
775 for (clock.m2 = limit->m2.min;
776 clock.m2 <= limit->m2.max; clock.m2++) {
777 for (clock.n = limit->n.min;
778 clock.n <= limit->n.max; clock.n++) {
779 for (clock.p1 = limit->p1.min;
780 clock.p1 <= limit->p1.max; clock.p1++) {
783 pnv_calc_dpll_params(refclk, &clock);
784 if (!intel_PLL_is_valid(to_i915(dev),
789 clock.p != match_clock->p)
792 this_err = abs(clock.dot - target);
793 if (this_err < err) {
802 return (err != target);
806 * Returns a set of divisors for the desired target clock with the given
807 * refclk, or FALSE. The returned values represent the clock equation:
808 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
810 * Target and reference clocks are specified in kHz.
812 * If match_clock is provided, then best_clock P divider must match the P
813 * divider from @match_clock used for LVDS downclocking.
816 g4x_find_best_dpll(const struct intel_limit *limit,
817 struct intel_crtc_state *crtc_state,
818 int target, int refclk, struct dpll *match_clock,
819 struct dpll *best_clock)
821 struct drm_device *dev = crtc_state->uapi.crtc->dev;
825 /* approximately equals target * 0.00585 */
826 int err_most = (target >> 8) + (target >> 9);
828 memset(best_clock, 0, sizeof(*best_clock));
830 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
832 max_n = limit->n.max;
833 /* based on hardware requirement, prefer smaller n to precision */
834 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
835 /* based on hardware requirement, prefere larger m1,m2 */
836 for (clock.m1 = limit->m1.max;
837 clock.m1 >= limit->m1.min; clock.m1--) {
838 for (clock.m2 = limit->m2.max;
839 clock.m2 >= limit->m2.min; clock.m2--) {
840 for (clock.p1 = limit->p1.max;
841 clock.p1 >= limit->p1.min; clock.p1--) {
844 i9xx_calc_dpll_params(refclk, &clock);
845 if (!intel_PLL_is_valid(to_i915(dev),
850 this_err = abs(clock.dot - target);
851 if (this_err < err_most) {
865 * Check if the calculated PLL configuration is more optimal compared to the
866 * best configuration and error found so far. Return the calculated error.
868 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
869 const struct dpll *calculated_clock,
870 const struct dpll *best_clock,
871 unsigned int best_error_ppm,
872 unsigned int *error_ppm)
875 * For CHV ignore the error and consider only the P value.
876 * Prefer a bigger P value based on HW requirements.
878 if (IS_CHERRYVIEW(to_i915(dev))) {
881 return calculated_clock->p > best_clock->p;
884 if (drm_WARN_ON_ONCE(dev, !target_freq))
887 *error_ppm = div_u64(1000000ULL *
888 abs(target_freq - calculated_clock->dot),
891 * Prefer a better P value over a better (smaller) error if the error
892 * is small. Ensure this preference for future configurations too by
893 * setting the error to 0.
895 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
901 return *error_ppm + 10 < best_error_ppm;
905 * Returns a set of divisors for the desired target clock with the given
906 * refclk, or FALSE. The returned values represent the clock equation:
907 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
910 vlv_find_best_dpll(const struct intel_limit *limit,
911 struct intel_crtc_state *crtc_state,
912 int target, int refclk, struct dpll *match_clock,
913 struct dpll *best_clock)
915 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
916 struct drm_device *dev = crtc->base.dev;
918 unsigned int bestppm = 1000000;
919 /* min update 19.2 MHz */
920 int max_n = min(limit->n.max, refclk / 19200);
923 target *= 5; /* fast clock */
925 memset(best_clock, 0, sizeof(*best_clock));
927 /* based on hardware requirement, prefer smaller n to precision */
928 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
929 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
930 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
931 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
932 clock.p = clock.p1 * clock.p2;
933 /* based on hardware requirement, prefer bigger m1,m2 values */
934 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
937 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
940 vlv_calc_dpll_params(refclk, &clock);
942 if (!intel_PLL_is_valid(to_i915(dev),
947 if (!vlv_PLL_is_optimal(dev, target,
965 * Returns a set of divisors for the desired target clock with the given
966 * refclk, or FALSE. The returned values represent the clock equation:
967 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
970 chv_find_best_dpll(const struct intel_limit *limit,
971 struct intel_crtc_state *crtc_state,
972 int target, int refclk, struct dpll *match_clock,
973 struct dpll *best_clock)
975 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
976 struct drm_device *dev = crtc->base.dev;
977 unsigned int best_error_ppm;
982 memset(best_clock, 0, sizeof(*best_clock));
983 best_error_ppm = 1000000;
986 * Based on hardware doc, the n always set to 1, and m1 always
987 * set to 2. If requires to support 200Mhz refclk, we need to
988 * revisit this because n may not 1 anymore.
990 clock.n = 1, clock.m1 = 2;
991 target *= 5; /* fast clock */
993 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
994 for (clock.p2 = limit->p2.p2_fast;
995 clock.p2 >= limit->p2.p2_slow;
996 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
997 unsigned int error_ppm;
999 clock.p = clock.p1 * clock.p2;
1001 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
1004 if (m2 > INT_MAX/clock.m1)
1009 chv_calc_dpll_params(refclk, &clock);
1011 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
1014 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
1015 best_error_ppm, &error_ppm))
1018 *best_clock = clock;
1019 best_error_ppm = error_ppm;
1027 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
1028 struct dpll *best_clock)
1030 int refclk = 100000;
1031 const struct intel_limit *limit = &intel_limits_bxt;
1033 return chv_find_best_dpll(limit, crtc_state,
1034 crtc_state->port_clock, refclk,
1038 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1041 i915_reg_t reg = PIPEDSL(pipe);
1045 if (IS_GEN(dev_priv, 2))
1046 line_mask = DSL_LINEMASK_GEN2;
1048 line_mask = DSL_LINEMASK_GEN3;
1050 line1 = intel_de_read(dev_priv, reg) & line_mask;
1052 line2 = intel_de_read(dev_priv, reg) & line_mask;
1054 return line1 != line2;
1057 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1059 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1060 enum pipe pipe = crtc->pipe;
1062 /* Wait for the display line to settle/start moving */
1063 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1064 drm_err(&dev_priv->drm,
1065 "pipe %c scanline %s wait timed out\n",
1066 pipe_name(pipe), onoff(state));
1069 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1071 wait_for_pipe_scanline_moving(crtc, false);
1074 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1076 wait_for_pipe_scanline_moving(crtc, true);
1080 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1082 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1083 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1085 if (INTEL_GEN(dev_priv) >= 4) {
1086 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1087 i915_reg_t reg = PIPECONF(cpu_transcoder);
1089 /* Wait for the Pipe State to go off */
1090 if (intel_de_wait_for_clear(dev_priv, reg,
1091 I965_PIPECONF_ACTIVE, 100))
1092 drm_WARN(&dev_priv->drm, 1,
1093 "pipe_off wait timed out\n");
1095 intel_wait_for_pipe_scanline_stopped(crtc);
1099 /* Only for pre-ILK configs */
1100 void assert_pll(struct drm_i915_private *dev_priv,
1101 enum pipe pipe, bool state)
1106 val = intel_de_read(dev_priv, DPLL(pipe));
1107 cur_state = !!(val & DPLL_VCO_ENABLE);
1108 I915_STATE_WARN(cur_state != state,
1109 "PLL state assertion failure (expected %s, current %s)\n",
1110 onoff(state), onoff(cur_state));
1113 /* XXX: the dsi pll is shared between MIPI DSI ports */
1114 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1119 vlv_cck_get(dev_priv);
1120 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1121 vlv_cck_put(dev_priv);
1123 cur_state = val & DSI_PLL_VCO_EN;
1124 I915_STATE_WARN(cur_state != state,
1125 "DSI PLL state assertion failure (expected %s, current %s)\n",
1126 onoff(state), onoff(cur_state));
1129 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1130 enum pipe pipe, bool state)
1134 if (HAS_DDI(dev_priv)) {
1136 * DDI does not have a specific FDI_TX register.
1138 * FDI is never fed from EDP transcoder
1139 * so pipe->transcoder cast is fine here.
1141 enum transcoder cpu_transcoder = (enum transcoder)pipe;
1142 u32 val = intel_de_read(dev_priv,
1143 TRANS_DDI_FUNC_CTL(cpu_transcoder));
1144 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1146 u32 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
1147 cur_state = !!(val & FDI_TX_ENABLE);
1149 I915_STATE_WARN(cur_state != state,
1150 "FDI TX state assertion failure (expected %s, current %s)\n",
1151 onoff(state), onoff(cur_state));
1153 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1154 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1156 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1157 enum pipe pipe, bool state)
1162 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
1163 cur_state = !!(val & FDI_RX_ENABLE);
1164 I915_STATE_WARN(cur_state != state,
1165 "FDI RX state assertion failure (expected %s, current %s)\n",
1166 onoff(state), onoff(cur_state));
1168 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1169 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1171 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1176 /* ILK FDI PLL is always enabled */
1177 if (IS_GEN(dev_priv, 5))
1180 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1181 if (HAS_DDI(dev_priv))
1184 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
1185 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1188 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1189 enum pipe pipe, bool state)
1194 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
1195 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1196 I915_STATE_WARN(cur_state != state,
1197 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1198 onoff(state), onoff(cur_state));
1201 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1205 enum pipe panel_pipe = INVALID_PIPE;
1208 if (drm_WARN_ON(&dev_priv->drm, HAS_DDI(dev_priv)))
1211 if (HAS_PCH_SPLIT(dev_priv)) {
1214 pp_reg = PP_CONTROL(0);
1215 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1218 case PANEL_PORT_SELECT_LVDS:
1219 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1221 case PANEL_PORT_SELECT_DPA:
1222 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1224 case PANEL_PORT_SELECT_DPC:
1225 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1227 case PANEL_PORT_SELECT_DPD:
1228 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1231 MISSING_CASE(port_sel);
1234 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1235 /* presumably write lock depends on pipe, not port select */
1236 pp_reg = PP_CONTROL(pipe);
1241 pp_reg = PP_CONTROL(0);
1242 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1244 drm_WARN_ON(&dev_priv->drm,
1245 port_sel != PANEL_PORT_SELECT_LVDS);
1246 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1249 val = intel_de_read(dev_priv, pp_reg);
1250 if (!(val & PANEL_POWER_ON) ||
1251 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1254 I915_STATE_WARN(panel_pipe == pipe && locked,
1255 "panel assertion failure, pipe %c regs locked\n",
1259 void assert_pipe(struct drm_i915_private *dev_priv,
1260 enum transcoder cpu_transcoder, bool state)
1263 enum intel_display_power_domain power_domain;
1264 intel_wakeref_t wakeref;
1266 /* we keep both pipes enabled on 830 */
1267 if (IS_I830(dev_priv))
1270 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1271 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1273 u32 val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
1274 cur_state = !!(val & PIPECONF_ENABLE);
1276 intel_display_power_put(dev_priv, power_domain, wakeref);
1281 I915_STATE_WARN(cur_state != state,
1282 "transcoder %s assertion failure (expected %s, current %s)\n",
1283 transcoder_name(cpu_transcoder),
1284 onoff(state), onoff(cur_state));
1287 static void assert_plane(struct intel_plane *plane, bool state)
1292 cur_state = plane->get_hw_state(plane, &pipe);
1294 I915_STATE_WARN(cur_state != state,
1295 "%s assertion failure (expected %s, current %s)\n",
1296 plane->base.name, onoff(state), onoff(cur_state));
1299 #define assert_plane_enabled(p) assert_plane(p, true)
1300 #define assert_plane_disabled(p) assert_plane(p, false)
1302 static void assert_planes_disabled(struct intel_crtc *crtc)
1304 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1305 struct intel_plane *plane;
1307 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1308 assert_plane_disabled(plane);
1311 static void assert_vblank_disabled(struct drm_crtc *crtc)
1313 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1314 drm_crtc_vblank_put(crtc);
1317 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1323 val = intel_de_read(dev_priv, PCH_TRANSCONF(pipe));
1324 enabled = !!(val & TRANS_ENABLE);
1325 I915_STATE_WARN(enabled,
1326 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1330 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1331 enum pipe pipe, enum port port,
1334 enum pipe port_pipe;
1337 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1339 I915_STATE_WARN(state && port_pipe == pipe,
1340 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1341 port_name(port), pipe_name(pipe));
1343 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1344 "IBX PCH DP %c still using transcoder B\n",
1348 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1349 enum pipe pipe, enum port port,
1350 i915_reg_t hdmi_reg)
1352 enum pipe port_pipe;
1355 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1357 I915_STATE_WARN(state && port_pipe == pipe,
1358 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1359 port_name(port), pipe_name(pipe));
1361 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1362 "IBX PCH HDMI %c still using transcoder B\n",
1366 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1369 enum pipe port_pipe;
1371 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1372 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1373 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1375 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1377 "PCH VGA enabled on transcoder %c, should be disabled\n",
1380 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1382 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1385 /* PCH SDVOB multiplex with HDMIB */
1386 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1387 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1388 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1391 static void _vlv_enable_pll(struct intel_crtc *crtc,
1392 const struct intel_crtc_state *pipe_config)
1394 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1395 enum pipe pipe = crtc->pipe;
1397 intel_de_write(dev_priv, DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1398 intel_de_posting_read(dev_priv, DPLL(pipe));
1401 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1402 drm_err(&dev_priv->drm, "DPLL %d failed to lock\n", pipe);
1405 static void vlv_enable_pll(struct intel_crtc *crtc,
1406 const struct intel_crtc_state *pipe_config)
1408 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1409 enum pipe pipe = crtc->pipe;
1411 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1413 /* PLL is protected by panel, make sure we can write it */
1414 assert_panel_unlocked(dev_priv, pipe);
1416 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1417 _vlv_enable_pll(crtc, pipe_config);
1419 intel_de_write(dev_priv, DPLL_MD(pipe),
1420 pipe_config->dpll_hw_state.dpll_md);
1421 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
1425 static void _chv_enable_pll(struct intel_crtc *crtc,
1426 const struct intel_crtc_state *pipe_config)
1428 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1429 enum pipe pipe = crtc->pipe;
1430 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1433 vlv_dpio_get(dev_priv);
1435 /* Enable back the 10bit clock to display controller */
1436 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1437 tmp |= DPIO_DCLKP_EN;
1438 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1440 vlv_dpio_put(dev_priv);
1443 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1448 intel_de_write(dev_priv, DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1450 /* Check PLL is locked */
1451 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1452 drm_err(&dev_priv->drm, "PLL %d failed to lock\n", pipe);
1455 static void chv_enable_pll(struct intel_crtc *crtc,
1456 const struct intel_crtc_state *pipe_config)
1458 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1459 enum pipe pipe = crtc->pipe;
1461 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
1463 /* PLL is protected by panel, make sure we can write it */
1464 assert_panel_unlocked(dev_priv, pipe);
1466 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1467 _chv_enable_pll(crtc, pipe_config);
1469 if (pipe != PIPE_A) {
1471 * WaPixelRepeatModeFixForC0:chv
1473 * DPLLCMD is AWOL. Use chicken bits to propagate
1474 * the value from DPLLBMD to either pipe B or C.
1476 intel_de_write(dev_priv, CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1477 intel_de_write(dev_priv, DPLL_MD(PIPE_B),
1478 pipe_config->dpll_hw_state.dpll_md);
1479 intel_de_write(dev_priv, CBR4_VLV, 0);
1480 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1483 * DPLLB VGA mode also seems to cause problems.
1484 * We should always have it disabled.
1486 drm_WARN_ON(&dev_priv->drm,
1487 (intel_de_read(dev_priv, DPLL(PIPE_B)) &
1488 DPLL_VGA_MODE_DIS) == 0);
1490 intel_de_write(dev_priv, DPLL_MD(pipe),
1491 pipe_config->dpll_hw_state.dpll_md);
1492 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
1496 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1498 if (IS_I830(dev_priv))
1501 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1504 static void i9xx_enable_pll(struct intel_crtc *crtc,
1505 const struct intel_crtc_state *crtc_state)
1507 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1508 i915_reg_t reg = DPLL(crtc->pipe);
1509 u32 dpll = crtc_state->dpll_hw_state.dpll;
1512 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1514 /* PLL is protected by panel, make sure we can write it */
1515 if (i9xx_has_pps(dev_priv))
1516 assert_panel_unlocked(dev_priv, crtc->pipe);
1519 * Apparently we need to have VGA mode enabled prior to changing
1520 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1521 * dividers, even though the register value does change.
1523 intel_de_write(dev_priv, reg, dpll & ~DPLL_VGA_MODE_DIS);
1524 intel_de_write(dev_priv, reg, dpll);
1526 /* Wait for the clocks to stabilize. */
1527 intel_de_posting_read(dev_priv, reg);
1530 if (INTEL_GEN(dev_priv) >= 4) {
1531 intel_de_write(dev_priv, DPLL_MD(crtc->pipe),
1532 crtc_state->dpll_hw_state.dpll_md);
1534 /* The pixel multiplier can only be updated once the
1535 * DPLL is enabled and the clocks are stable.
1537 * So write it again.
1539 intel_de_write(dev_priv, reg, dpll);
1542 /* We do this three times for luck */
1543 for (i = 0; i < 3; i++) {
1544 intel_de_write(dev_priv, reg, dpll);
1545 intel_de_posting_read(dev_priv, reg);
1546 udelay(150); /* wait for warmup */
1550 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1552 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1553 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1554 enum pipe pipe = crtc->pipe;
1556 /* Don't disable pipe or pipe PLLs if needed */
1557 if (IS_I830(dev_priv))
1560 /* Make sure the pipe isn't still relying on us */
1561 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
1563 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
1564 intel_de_posting_read(dev_priv, DPLL(pipe));
1567 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1571 /* Make sure the pipe isn't still relying on us */
1572 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1574 val = DPLL_INTEGRATED_REF_CLK_VLV |
1575 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1577 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1579 intel_de_write(dev_priv, DPLL(pipe), val);
1580 intel_de_posting_read(dev_priv, DPLL(pipe));
1583 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1585 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1588 /* Make sure the pipe isn't still relying on us */
1589 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
1591 val = DPLL_SSC_REF_CLK_CHV |
1592 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1594 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1596 intel_de_write(dev_priv, DPLL(pipe), val);
1597 intel_de_posting_read(dev_priv, DPLL(pipe));
1599 vlv_dpio_get(dev_priv);
1601 /* Disable 10bit clock to display controller */
1602 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1603 val &= ~DPIO_DCLKP_EN;
1604 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1606 vlv_dpio_put(dev_priv);
1609 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1610 struct intel_digital_port *dport,
1611 unsigned int expected_mask)
1614 i915_reg_t dpll_reg;
1616 switch (dport->base.port) {
1618 port_mask = DPLL_PORTB_READY_MASK;
1622 port_mask = DPLL_PORTC_READY_MASK;
1624 expected_mask <<= 4;
1627 port_mask = DPLL_PORTD_READY_MASK;
1628 dpll_reg = DPIO_PHY_STATUS;
1634 if (intel_de_wait_for_register(dev_priv, dpll_reg,
1635 port_mask, expected_mask, 1000))
1636 drm_WARN(&dev_priv->drm, 1,
1637 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
1638 dport->base.base.base.id, dport->base.base.name,
1639 intel_de_read(dev_priv, dpll_reg) & port_mask,
1643 static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1645 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1646 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1647 enum pipe pipe = crtc->pipe;
1649 u32 val, pipeconf_val;
1651 /* Make sure PCH DPLL is enabled */
1652 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1654 /* FDI must be feeding us bits for PCH ports */
1655 assert_fdi_tx_enabled(dev_priv, pipe);
1656 assert_fdi_rx_enabled(dev_priv, pipe);
1658 if (HAS_PCH_CPT(dev_priv)) {
1659 reg = TRANS_CHICKEN2(pipe);
1660 val = intel_de_read(dev_priv, reg);
1662 * Workaround: Set the timing override bit
1663 * before enabling the pch transcoder.
1665 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1666 /* Configure frame start delay to match the CPU */
1667 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1668 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1669 intel_de_write(dev_priv, reg, val);
1672 reg = PCH_TRANSCONF(pipe);
1673 val = intel_de_read(dev_priv, reg);
1674 pipeconf_val = intel_de_read(dev_priv, PIPECONF(pipe));
1676 if (HAS_PCH_IBX(dev_priv)) {
1677 /* Configure frame start delay to match the CPU */
1678 val &= ~TRANS_FRAME_START_DELAY_MASK;
1679 val |= TRANS_FRAME_START_DELAY(0);
1682 * Make the BPC in transcoder be consistent with
1683 * that in pipeconf reg. For HDMI we must use 8bpc
1684 * here for both 8bpc and 12bpc.
1686 val &= ~PIPECONF_BPC_MASK;
1687 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1688 val |= PIPECONF_8BPC;
1690 val |= pipeconf_val & PIPECONF_BPC_MASK;
1693 val &= ~TRANS_INTERLACE_MASK;
1694 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
1695 if (HAS_PCH_IBX(dev_priv) &&
1696 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1697 val |= TRANS_LEGACY_INTERLACED_ILK;
1699 val |= TRANS_INTERLACED;
1701 val |= TRANS_PROGRESSIVE;
1704 intel_de_write(dev_priv, reg, val | TRANS_ENABLE);
1705 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
1706 drm_err(&dev_priv->drm, "failed to enable transcoder %c\n",
1710 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1711 enum transcoder cpu_transcoder)
1713 u32 val, pipeconf_val;
1715 /* FDI must be feeding us bits for PCH ports */
1716 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1717 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1719 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
1720 /* Workaround: set timing override bit. */
1721 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1722 /* Configure frame start delay to match the CPU */
1723 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
1724 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
1725 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
1728 pipeconf_val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
1730 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1731 PIPECONF_INTERLACED_ILK)
1732 val |= TRANS_INTERLACED;
1734 val |= TRANS_PROGRESSIVE;
1736 intel_de_write(dev_priv, LPT_TRANSCONF, val);
1737 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
1738 TRANS_STATE_ENABLE, 100))
1739 drm_err(&dev_priv->drm, "Failed to enable PCH transcoder\n");
1742 static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1748 /* FDI relies on the transcoder */
1749 assert_fdi_tx_disabled(dev_priv, pipe);
1750 assert_fdi_rx_disabled(dev_priv, pipe);
1752 /* Ports must be off as well */
1753 assert_pch_ports_disabled(dev_priv, pipe);
1755 reg = PCH_TRANSCONF(pipe);
1756 val = intel_de_read(dev_priv, reg);
1757 val &= ~TRANS_ENABLE;
1758 intel_de_write(dev_priv, reg, val);
1759 /* wait for PCH transcoder off, transcoder state */
1760 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
1761 drm_err(&dev_priv->drm, "failed to disable transcoder %c\n",
1764 if (HAS_PCH_CPT(dev_priv)) {
1765 /* Workaround: Clear the timing override chicken bit again. */
1766 reg = TRANS_CHICKEN2(pipe);
1767 val = intel_de_read(dev_priv, reg);
1768 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1769 intel_de_write(dev_priv, reg, val);
1773 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1777 val = intel_de_read(dev_priv, LPT_TRANSCONF);
1778 val &= ~TRANS_ENABLE;
1779 intel_de_write(dev_priv, LPT_TRANSCONF, val);
1780 /* wait for PCH transcoder off, transcoder state */
1781 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
1782 TRANS_STATE_ENABLE, 50))
1783 drm_err(&dev_priv->drm, "Failed to disable PCH transcoder\n");
1785 /* Workaround: clear timing override bit. */
1786 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
1787 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1788 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
1791 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1793 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1795 if (HAS_PCH_LPT(dev_priv))
1801 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1803 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1806 * On i965gm the hardware frame counter reads
1807 * zero when the TV encoder is enabled :(
1809 if (IS_I965GM(dev_priv) &&
1810 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1813 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1814 return 0xffffffff; /* full 32 bit counter */
1815 else if (INTEL_GEN(dev_priv) >= 3)
1816 return 0xffffff; /* only 24 bits of frame count */
1818 return 0; /* Gen2 doesn't have a hardware frame counter */
1821 void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1823 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1825 assert_vblank_disabled(&crtc->base);
1826 drm_crtc_set_max_vblank_count(&crtc->base,
1827 intel_crtc_max_vblank_count(crtc_state));
1828 drm_crtc_vblank_on(&crtc->base);
1831 void intel_crtc_vblank_off(const struct intel_crtc_state *crtc_state)
1833 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1835 drm_crtc_vblank_off(&crtc->base);
1836 assert_vblank_disabled(&crtc->base);
1839 void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1841 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
1842 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1843 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1844 enum pipe pipe = crtc->pipe;
1848 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
1850 assert_planes_disabled(crtc);
1853 * A pipe without a PLL won't actually be able to drive bits from
1854 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1857 if (HAS_GMCH(dev_priv)) {
1858 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1859 assert_dsi_pll_enabled(dev_priv);
1861 assert_pll_enabled(dev_priv, pipe);
1863 if (new_crtc_state->has_pch_encoder) {
1864 /* if driving the PCH, we need FDI enabled */
1865 assert_fdi_rx_pll_enabled(dev_priv,
1866 intel_crtc_pch_transcoder(crtc));
1867 assert_fdi_tx_pll_enabled(dev_priv,
1868 (enum pipe) cpu_transcoder);
1870 /* FIXME: assert CPU port conditions for SNB+ */
1873 trace_intel_pipe_enable(crtc);
1875 reg = PIPECONF(cpu_transcoder);
1876 val = intel_de_read(dev_priv, reg);
1877 if (val & PIPECONF_ENABLE) {
1878 /* we keep both pipes enabled on 830 */
1879 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
1883 intel_de_write(dev_priv, reg, val | PIPECONF_ENABLE);
1884 intel_de_posting_read(dev_priv, reg);
1887 * Until the pipe starts PIPEDSL reads will return a stale value,
1888 * which causes an apparent vblank timestamp jump when PIPEDSL
1889 * resets to its proper value. That also messes up the frame count
1890 * when it's derived from the timestamps. So let's wait for the
1891 * pipe to start properly before we call drm_crtc_vblank_on()
1893 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1894 intel_wait_for_pipe_scanline_moving(crtc);
1897 void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1899 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1900 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1901 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1902 enum pipe pipe = crtc->pipe;
1906 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
1909 * Make sure planes won't keep trying to pump pixels to us,
1910 * or we might hang the display.
1912 assert_planes_disabled(crtc);
1914 trace_intel_pipe_disable(crtc);
1916 reg = PIPECONF(cpu_transcoder);
1917 val = intel_de_read(dev_priv, reg);
1918 if ((val & PIPECONF_ENABLE) == 0)
1922 * Double wide has implications for planes
1923 * so best keep it disabled when not needed.
1925 if (old_crtc_state->double_wide)
1926 val &= ~PIPECONF_DOUBLE_WIDE;
1928 /* Don't disable pipe or pipe PLLs if needed */
1929 if (!IS_I830(dev_priv))
1930 val &= ~PIPECONF_ENABLE;
1932 intel_de_write(dev_priv, reg, val);
1933 if ((val & PIPECONF_ENABLE) == 0)
1934 intel_wait_for_pipe_off(old_crtc_state);
1937 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1939 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1942 static bool is_ccs_plane(const struct drm_framebuffer *fb, int plane)
1944 if (!is_ccs_modifier(fb->modifier))
1947 return plane >= fb->format->num_planes / 2;
1950 static bool is_gen12_ccs_modifier(u64 modifier)
1952 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
1953 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
1957 static bool is_gen12_ccs_plane(const struct drm_framebuffer *fb, int plane)
1959 return is_gen12_ccs_modifier(fb->modifier) && is_ccs_plane(fb, plane);
1962 static bool is_aux_plane(const struct drm_framebuffer *fb, int plane)
1964 if (is_ccs_modifier(fb->modifier))
1965 return is_ccs_plane(fb, plane);
1970 static int main_to_ccs_plane(const struct drm_framebuffer *fb, int main_plane)
1972 WARN_ON(!is_ccs_modifier(fb->modifier) ||
1973 (main_plane && main_plane >= fb->format->num_planes / 2));
1975 return fb->format->num_planes / 2 + main_plane;
1978 static int ccs_to_main_plane(const struct drm_framebuffer *fb, int ccs_plane)
1980 WARN_ON(!is_ccs_modifier(fb->modifier) ||
1981 ccs_plane < fb->format->num_planes / 2);
1983 return ccs_plane - fb->format->num_planes / 2;
1986 /* Return either the main plane's CCS or - if not a CCS FB - UV plane */
1987 int intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane)
1989 if (is_ccs_modifier(fb->modifier))
1990 return main_to_ccs_plane(fb, main_plane);
1996 intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
1999 return info->is_yuv &&
2000 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
2003 static bool is_semiplanar_uv_plane(const struct drm_framebuffer *fb,
2006 return intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
2011 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
2013 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2014 unsigned int cpp = fb->format->cpp[color_plane];
2016 switch (fb->modifier) {
2017 case DRM_FORMAT_MOD_LINEAR:
2018 return intel_tile_size(dev_priv);
2019 case I915_FORMAT_MOD_X_TILED:
2020 if (IS_GEN(dev_priv, 2))
2024 case I915_FORMAT_MOD_Y_TILED_CCS:
2025 if (is_ccs_plane(fb, color_plane))
2028 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2029 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2030 if (is_ccs_plane(fb, color_plane))
2033 case I915_FORMAT_MOD_Y_TILED:
2034 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
2038 case I915_FORMAT_MOD_Yf_TILED_CCS:
2039 if (is_ccs_plane(fb, color_plane))
2042 case I915_FORMAT_MOD_Yf_TILED:
2058 MISSING_CASE(fb->modifier);
2064 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
2066 if (is_gen12_ccs_plane(fb, color_plane))
2069 return intel_tile_size(to_i915(fb->dev)) /
2070 intel_tile_width_bytes(fb, color_plane);
2073 /* Return the tile dimensions in pixel units */
2074 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
2075 unsigned int *tile_width,
2076 unsigned int *tile_height)
2078 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
2079 unsigned int cpp = fb->format->cpp[color_plane];
2081 *tile_width = tile_width_bytes / cpp;
2082 *tile_height = intel_tile_height(fb, color_plane);
2085 static unsigned int intel_tile_row_size(const struct drm_framebuffer *fb,
2088 unsigned int tile_width, tile_height;
2090 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2092 return fb->pitches[color_plane] * tile_height;
2096 intel_fb_align_height(const struct drm_framebuffer *fb,
2097 int color_plane, unsigned int height)
2099 unsigned int tile_height = intel_tile_height(fb, color_plane);
2101 return ALIGN(height, tile_height);
2104 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2106 unsigned int size = 0;
2109 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2110 size += rot_info->plane[i].width * rot_info->plane[i].height;
2115 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
2117 unsigned int size = 0;
2120 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
2121 size += rem_info->plane[i].width * rem_info->plane[i].height;
2127 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2128 const struct drm_framebuffer *fb,
2129 unsigned int rotation)
2131 view->type = I915_GGTT_VIEW_NORMAL;
2132 if (drm_rotation_90_or_270(rotation)) {
2133 view->type = I915_GGTT_VIEW_ROTATED;
2134 view->rotated = to_intel_framebuffer(fb)->rot_info;
2138 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2140 if (IS_I830(dev_priv))
2142 else if (IS_I85X(dev_priv))
2144 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2150 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2152 if (INTEL_GEN(dev_priv) >= 9)
2154 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2155 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2157 else if (INTEL_GEN(dev_priv) >= 4)
2163 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2166 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2168 /* AUX_DIST needs only 4K alignment */
2169 if ((INTEL_GEN(dev_priv) < 12 && is_aux_plane(fb, color_plane)) ||
2170 is_ccs_plane(fb, color_plane))
2173 switch (fb->modifier) {
2174 case DRM_FORMAT_MOD_LINEAR:
2175 return intel_linear_alignment(dev_priv);
2176 case I915_FORMAT_MOD_X_TILED:
2177 if (INTEL_GEN(dev_priv) >= 9)
2180 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2181 if (is_semiplanar_uv_plane(fb, color_plane))
2182 return intel_tile_row_size(fb, color_plane);
2184 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2186 case I915_FORMAT_MOD_Y_TILED_CCS:
2187 case I915_FORMAT_MOD_Yf_TILED_CCS:
2188 case I915_FORMAT_MOD_Y_TILED:
2189 if (INTEL_GEN(dev_priv) >= 12 &&
2190 is_semiplanar_uv_plane(fb, color_plane))
2191 return intel_tile_row_size(fb, color_plane);
2193 case I915_FORMAT_MOD_Yf_TILED:
2194 return 1 * 1024 * 1024;
2196 MISSING_CASE(fb->modifier);
2201 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2203 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2204 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2206 return INTEL_GEN(dev_priv) < 4 ||
2208 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
2212 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2213 const struct i915_ggtt_view *view,
2215 unsigned long *out_flags)
2217 struct drm_device *dev = fb->dev;
2218 struct drm_i915_private *dev_priv = to_i915(dev);
2219 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2220 intel_wakeref_t wakeref;
2221 struct i915_vma *vma;
2222 unsigned int pinctl;
2225 if (drm_WARN_ON(dev, !i915_gem_object_is_framebuffer(obj)))
2226 return ERR_PTR(-EINVAL);
2228 alignment = intel_surf_alignment(fb, 0);
2229 if (drm_WARN_ON(dev, alignment && !is_power_of_2(alignment)))
2230 return ERR_PTR(-EINVAL);
2232 /* Note that the w/a also requires 64 PTE of padding following the
2233 * bo. We currently fill all unused PTE with the shadow page and so
2234 * we should always have valid PTE following the scanout preventing
2237 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2238 alignment = 256 * 1024;
2241 * Global gtt pte registers are special registers which actually forward
2242 * writes to a chunk of system memory. Which means that there is no risk
2243 * that the register values disappear as soon as we call
2244 * intel_runtime_pm_put(), so it is correct to wrap only the
2245 * pin/unpin/fence and not more.
2247 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
2249 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2252 * Valleyview is definitely limited to scanning out the first
2253 * 512MiB. Lets presume this behaviour was inherited from the
2254 * g4x display engine and that all earlier gen are similarly
2255 * limited. Testing suggests that it is a little more
2256 * complicated than this. For example, Cherryview appears quite
2257 * happy to scanout from anywhere within its global aperture.
2260 if (HAS_GMCH(dev_priv))
2261 pinctl |= PIN_MAPPABLE;
2263 vma = i915_gem_object_pin_to_display_plane(obj,
2264 alignment, view, pinctl);
2268 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2272 * Install a fence for tiled scan-out. Pre-i965 always needs a
2273 * fence, whereas 965+ only requires a fence if using
2274 * framebuffer compression. For simplicity, we always, when
2275 * possible, install a fence as the cost is not that onerous.
2277 * If we fail to fence the tiled scanout, then either the
2278 * modeset will reject the change (which is highly unlikely as
2279 * the affected systems, all but one, do not have unmappable
2280 * space) or we will not be able to enable full powersaving
2281 * techniques (also likely not to apply due to various limits
2282 * FBC and the like impose on the size of the buffer, which
2283 * presumably we violated anyway with this unmappable buffer).
2284 * Anyway, it is presumably better to stumble onwards with
2285 * something and try to run the system in a "less than optimal"
2286 * mode that matches the user configuration.
2288 ret = i915_vma_pin_fence(vma);
2289 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2290 i915_gem_object_unpin_from_display_plane(vma);
2295 if (ret == 0 && vma->fence)
2296 *out_flags |= PLANE_HAS_FENCE;
2301 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2302 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
2306 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2308 i915_gem_object_lock(vma->obj);
2309 if (flags & PLANE_HAS_FENCE)
2310 i915_vma_unpin_fence(vma);
2311 i915_gem_object_unpin_from_display_plane(vma);
2312 i915_gem_object_unlock(vma->obj);
2317 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2318 unsigned int rotation)
2320 if (drm_rotation_90_or_270(rotation))
2321 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2323 return fb->pitches[color_plane];
2327 * Convert the x/y offsets into a linear offset.
2328 * Only valid with 0/180 degree rotation, which is fine since linear
2329 * offset is only used with linear buffers on pre-hsw and tiled buffers
2330 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2332 u32 intel_fb_xy_to_linear(int x, int y,
2333 const struct intel_plane_state *state,
2336 const struct drm_framebuffer *fb = state->hw.fb;
2337 unsigned int cpp = fb->format->cpp[color_plane];
2338 unsigned int pitch = state->color_plane[color_plane].stride;
2340 return y * pitch + x * cpp;
2344 * Add the x/y offsets derived from fb->offsets[] to the user
2345 * specified plane src x/y offsets. The resulting x/y offsets
2346 * specify the start of scanout from the beginning of the gtt mapping.
2348 void intel_add_fb_offsets(int *x, int *y,
2349 const struct intel_plane_state *state,
2353 *x += state->color_plane[color_plane].x;
2354 *y += state->color_plane[color_plane].y;
2357 static u32 intel_adjust_tile_offset(int *x, int *y,
2358 unsigned int tile_width,
2359 unsigned int tile_height,
2360 unsigned int tile_size,
2361 unsigned int pitch_tiles,
2365 unsigned int pitch_pixels = pitch_tiles * tile_width;
2368 WARN_ON(old_offset & (tile_size - 1));
2369 WARN_ON(new_offset & (tile_size - 1));
2370 WARN_ON(new_offset > old_offset);
2372 tiles = (old_offset - new_offset) / tile_size;
2374 *y += tiles / pitch_tiles * tile_height;
2375 *x += tiles % pitch_tiles * tile_width;
2377 /* minimize x in case it got needlessly big */
2378 *y += *x / pitch_pixels * tile_height;
2384 static bool is_surface_linear(const struct drm_framebuffer *fb, int color_plane)
2386 return fb->modifier == DRM_FORMAT_MOD_LINEAR ||
2387 is_gen12_ccs_plane(fb, color_plane);
2390 static u32 intel_adjust_aligned_offset(int *x, int *y,
2391 const struct drm_framebuffer *fb,
2393 unsigned int rotation,
2395 u32 old_offset, u32 new_offset)
2397 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2398 unsigned int cpp = fb->format->cpp[color_plane];
2400 drm_WARN_ON(&dev_priv->drm, new_offset > old_offset);
2402 if (!is_surface_linear(fb, color_plane)) {
2403 unsigned int tile_size, tile_width, tile_height;
2404 unsigned int pitch_tiles;
2406 tile_size = intel_tile_size(dev_priv);
2407 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2409 if (drm_rotation_90_or_270(rotation)) {
2410 pitch_tiles = pitch / tile_height;
2411 swap(tile_width, tile_height);
2413 pitch_tiles = pitch / (tile_width * cpp);
2416 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2417 tile_size, pitch_tiles,
2418 old_offset, new_offset);
2420 old_offset += *y * pitch + *x * cpp;
2422 *y = (old_offset - new_offset) / pitch;
2423 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2430 * Adjust the tile offset by moving the difference into
2433 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2434 const struct intel_plane_state *state,
2436 u32 old_offset, u32 new_offset)
2438 return intel_adjust_aligned_offset(x, y, state->hw.fb, color_plane,
2440 state->color_plane[color_plane].stride,
2441 old_offset, new_offset);
2445 * Computes the aligned offset to the base tile and adjusts
2446 * x, y. bytes per pixel is assumed to be a power-of-two.
2448 * In the 90/270 rotated case, x and y are assumed
2449 * to be already rotated to match the rotated GTT view, and
2450 * pitch is the tile_height aligned framebuffer height.
2452 * This function is used when computing the derived information
2453 * under intel_framebuffer, so using any of that information
2454 * here is not allowed. Anything under drm_framebuffer can be
2455 * used. This is why the user has to pass in the pitch since it
2456 * is specified in the rotated orientation.
2458 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2460 const struct drm_framebuffer *fb,
2463 unsigned int rotation,
2466 unsigned int cpp = fb->format->cpp[color_plane];
2467 u32 offset, offset_aligned;
2469 if (!is_surface_linear(fb, color_plane)) {
2470 unsigned int tile_size, tile_width, tile_height;
2471 unsigned int tile_rows, tiles, pitch_tiles;
2473 tile_size = intel_tile_size(dev_priv);
2474 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2476 if (drm_rotation_90_or_270(rotation)) {
2477 pitch_tiles = pitch / tile_height;
2478 swap(tile_width, tile_height);
2480 pitch_tiles = pitch / (tile_width * cpp);
2483 tile_rows = *y / tile_height;
2486 tiles = *x / tile_width;
2489 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2491 offset_aligned = offset;
2493 offset_aligned = rounddown(offset_aligned, alignment);
2495 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2496 tile_size, pitch_tiles,
2497 offset, offset_aligned);
2499 offset = *y * pitch + *x * cpp;
2500 offset_aligned = offset;
2502 offset_aligned = rounddown(offset_aligned, alignment);
2503 *y = (offset % alignment) / pitch;
2504 *x = ((offset % alignment) - *y * pitch) / cpp;
2510 return offset_aligned;
2513 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2514 const struct intel_plane_state *state,
2517 struct intel_plane *intel_plane = to_intel_plane(state->uapi.plane);
2518 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2519 const struct drm_framebuffer *fb = state->hw.fb;
2520 unsigned int rotation = state->hw.rotation;
2521 int pitch = state->color_plane[color_plane].stride;
2524 if (intel_plane->id == PLANE_CURSOR)
2525 alignment = intel_cursor_alignment(dev_priv);
2527 alignment = intel_surf_alignment(fb, color_plane);
2529 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2530 pitch, rotation, alignment);
2533 /* Convert the fb->offset[] into x/y offsets */
2534 static int intel_fb_offset_to_xy(int *x, int *y,
2535 const struct drm_framebuffer *fb,
2538 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2539 unsigned int height;
2542 if (INTEL_GEN(dev_priv) >= 12 &&
2543 is_semiplanar_uv_plane(fb, color_plane))
2544 alignment = intel_tile_row_size(fb, color_plane);
2545 else if (fb->modifier != DRM_FORMAT_MOD_LINEAR)
2546 alignment = intel_tile_size(dev_priv);
2550 if (alignment != 0 && fb->offsets[color_plane] % alignment) {
2551 drm_dbg_kms(&dev_priv->drm,
2552 "Misaligned offset 0x%08x for color plane %d\n",
2553 fb->offsets[color_plane], color_plane);
2557 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2558 height = ALIGN(height, intel_tile_height(fb, color_plane));
2560 /* Catch potential overflows early */
2561 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2562 fb->offsets[color_plane])) {
2563 drm_dbg_kms(&dev_priv->drm,
2564 "Bad offset 0x%08x or pitch %d for color plane %d\n",
2565 fb->offsets[color_plane], fb->pitches[color_plane],
2573 intel_adjust_aligned_offset(x, y,
2574 fb, color_plane, DRM_MODE_ROTATE_0,
2575 fb->pitches[color_plane],
2576 fb->offsets[color_plane], 0);
2581 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2583 switch (fb_modifier) {
2584 case I915_FORMAT_MOD_X_TILED:
2585 return I915_TILING_X;
2586 case I915_FORMAT_MOD_Y_TILED:
2587 case I915_FORMAT_MOD_Y_TILED_CCS:
2588 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2589 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2590 return I915_TILING_Y;
2592 return I915_TILING_NONE;
2597 * From the Sky Lake PRM:
2598 * "The Color Control Surface (CCS) contains the compression status of
2599 * the cache-line pairs. The compression state of the cache-line pair
2600 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2601 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2602 * cache-line-pairs. CCS is always Y tiled."
2604 * Since cache line pairs refers to horizontally adjacent cache lines,
2605 * each cache line in the CCS corresponds to an area of 32x16 cache
2606 * lines on the main surface. Since each pixel is 4 bytes, this gives
2607 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2610 static const struct drm_format_info skl_ccs_formats[] = {
2611 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2612 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2613 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2614 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2615 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2616 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2617 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2618 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
2622 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
2623 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
2624 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
2625 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
2628 static const struct drm_format_info gen12_ccs_formats[] = {
2629 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
2630 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2631 .hsub = 1, .vsub = 1, },
2632 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
2633 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2634 .hsub = 1, .vsub = 1, },
2635 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
2636 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2637 .hsub = 1, .vsub = 1, .has_alpha = true },
2638 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
2639 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2640 .hsub = 1, .vsub = 1, .has_alpha = true },
2641 { .format = DRM_FORMAT_YUYV, .num_planes = 2,
2642 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2643 .hsub = 2, .vsub = 1, .is_yuv = true },
2644 { .format = DRM_FORMAT_YVYU, .num_planes = 2,
2645 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2646 .hsub = 2, .vsub = 1, .is_yuv = true },
2647 { .format = DRM_FORMAT_UYVY, .num_planes = 2,
2648 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2649 .hsub = 2, .vsub = 1, .is_yuv = true },
2650 { .format = DRM_FORMAT_VYUY, .num_planes = 2,
2651 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
2652 .hsub = 2, .vsub = 1, .is_yuv = true },
2653 { .format = DRM_FORMAT_NV12, .num_planes = 4,
2654 .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 },
2655 .hsub = 2, .vsub = 2, .is_yuv = true },
2656 { .format = DRM_FORMAT_P010, .num_planes = 4,
2657 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2658 .hsub = 2, .vsub = 2, .is_yuv = true },
2659 { .format = DRM_FORMAT_P012, .num_planes = 4,
2660 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2661 .hsub = 2, .vsub = 2, .is_yuv = true },
2662 { .format = DRM_FORMAT_P016, .num_planes = 4,
2663 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
2664 .hsub = 2, .vsub = 2, .is_yuv = true },
2667 static const struct drm_format_info *
2668 lookup_format_info(const struct drm_format_info formats[],
2669 int num_formats, u32 format)
2673 for (i = 0; i < num_formats; i++) {
2674 if (formats[i].format == format)
2681 static const struct drm_format_info *
2682 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2684 switch (cmd->modifier[0]) {
2685 case I915_FORMAT_MOD_Y_TILED_CCS:
2686 case I915_FORMAT_MOD_Yf_TILED_CCS:
2687 return lookup_format_info(skl_ccs_formats,
2688 ARRAY_SIZE(skl_ccs_formats),
2690 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2691 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
2692 return lookup_format_info(gen12_ccs_formats,
2693 ARRAY_SIZE(gen12_ccs_formats),
2700 bool is_ccs_modifier(u64 modifier)
2702 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
2703 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS ||
2704 modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2705 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2708 static int gen12_ccs_aux_stride(struct drm_framebuffer *fb, int ccs_plane)
2710 return DIV_ROUND_UP(fb->pitches[ccs_to_main_plane(fb, ccs_plane)],
2714 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
2715 u32 pixel_format, u64 modifier)
2717 struct intel_crtc *crtc;
2718 struct intel_plane *plane;
2721 * We assume the primary plane for pipe A has
2722 * the highest stride limits of them all,
2723 * if in case pipe A is disabled, use the first pipe from pipe_mask.
2725 crtc = intel_get_first_crtc(dev_priv);
2729 plane = to_intel_plane(crtc->base.primary);
2731 return plane->max_stride(plane, pixel_format, modifier,
2736 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
2737 u32 pixel_format, u64 modifier)
2740 * Arbitrary limit for gen4+ chosen to match the
2741 * render engine max stride.
2743 * The new CCS hash mode makes remapping impossible
2745 if (!is_ccs_modifier(modifier)) {
2746 if (INTEL_GEN(dev_priv) >= 7)
2748 else if (INTEL_GEN(dev_priv) >= 4)
2752 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
2756 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
2758 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2761 if (is_surface_linear(fb, color_plane)) {
2762 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
2767 * To make remapping with linear generally feasible
2768 * we need the stride to be page aligned.
2770 if (fb->pitches[color_plane] > max_stride &&
2771 !is_ccs_modifier(fb->modifier))
2772 return intel_tile_size(dev_priv);
2777 tile_width = intel_tile_width_bytes(fb, color_plane);
2778 if (is_ccs_modifier(fb->modifier)) {
2780 * Display WA #0531: skl,bxt,kbl,glk
2782 * Render decompression and plane width > 3840
2783 * combined with horizontal panning requires the
2784 * plane stride to be a multiple of 4. We'll just
2785 * require the entire fb to accommodate that to avoid
2786 * potential runtime errors at plane configuration time.
2788 if (IS_GEN(dev_priv, 9) && color_plane == 0 && fb->width > 3840)
2791 * The main surface pitch must be padded to a multiple of four
2794 else if (INTEL_GEN(dev_priv) >= 12)
2800 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
2802 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2803 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2804 const struct drm_framebuffer *fb = plane_state->hw.fb;
2807 /* We don't want to deal with remapping with cursors */
2808 if (plane->id == PLANE_CURSOR)
2812 * The display engine limits already match/exceed the
2813 * render engine limits, so not much point in remapping.
2814 * Would also need to deal with the fence POT alignment
2815 * and gen2 2KiB GTT tile size.
2817 if (INTEL_GEN(dev_priv) < 4)
2821 * The new CCS hash mode isn't compatible with remapping as
2822 * the virtual address of the pages affects the compressed data.
2824 if (is_ccs_modifier(fb->modifier))
2827 /* Linear needs a page aligned stride for remapping */
2828 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2829 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2831 for (i = 0; i < fb->format->num_planes; i++) {
2832 if (fb->pitches[i] & alignment)
2840 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2842 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2843 const struct drm_framebuffer *fb = plane_state->hw.fb;
2844 unsigned int rotation = plane_state->hw.rotation;
2845 u32 stride, max_stride;
2848 * No remapping for invisible planes since we don't have
2849 * an actual source viewport to remap.
2851 if (!plane_state->uapi.visible)
2854 if (!intel_plane_can_remap(plane_state))
2858 * FIXME: aux plane limits on gen9+ are
2859 * unclear in Bspec, for now no checking.
2861 stride = intel_fb_pitch(fb, 0, rotation);
2862 max_stride = plane->max_stride(plane, fb->format->format,
2863 fb->modifier, rotation);
2865 return stride > max_stride;
2869 intel_fb_plane_get_subsampling(int *hsub, int *vsub,
2870 const struct drm_framebuffer *fb,
2875 if (color_plane == 0) {
2883 * TODO: Deduct the subsampling from the char block for all CCS
2884 * formats and planes.
2886 if (!is_gen12_ccs_plane(fb, color_plane)) {
2887 *hsub = fb->format->hsub;
2888 *vsub = fb->format->vsub;
2893 main_plane = ccs_to_main_plane(fb, color_plane);
2894 *hsub = drm_format_info_block_width(fb->format, color_plane) /
2895 drm_format_info_block_width(fb->format, main_plane);
2898 * The min stride check in the core framebuffer_check() function
2899 * assumes that format->hsub applies to every plane except for the
2900 * first plane. That's incorrect for the CCS AUX plane of the first
2901 * plane, but for the above check to pass we must define the block
2902 * width with that subsampling applied to it. Adjust the width here
2903 * accordingly, so we can calculate the actual subsampling factor.
2905 if (main_plane == 0)
2906 *hsub *= fb->format->hsub;
2911 intel_fb_check_ccs_xy(struct drm_framebuffer *fb, int ccs_plane, int x, int y)
2913 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2916 int tile_width, tile_height;
2920 if (!is_ccs_plane(fb, ccs_plane))
2923 intel_tile_dims(fb, ccs_plane, &tile_width, &tile_height);
2924 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
2927 tile_height *= vsub;
2929 ccs_x = (x * hsub) % tile_width;
2930 ccs_y = (y * vsub) % tile_height;
2932 main_plane = ccs_to_main_plane(fb, ccs_plane);
2933 main_x = intel_fb->normal[main_plane].x % tile_width;
2934 main_y = intel_fb->normal[main_plane].y % tile_height;
2937 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2938 * x/y offsets must match between CCS and the main surface.
2940 if (main_x != ccs_x || main_y != ccs_y) {
2941 DRM_DEBUG_KMS("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 icl_enable_trans_port_sync(const struct intel_crtc_state *crtc_state)
5003 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5004 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5005 u32 trans_ddi_func_ctl2_val;
5009 * Configure the master select and enable Transcoder Port Sync for
5010 * Slave CRTCs transcoder.
5012 if (crtc_state->master_transcoder == INVALID_TRANSCODER)
5015 if (crtc_state->master_transcoder == TRANSCODER_EDP)
5018 master_select = crtc_state->master_transcoder + 1;
5020 /* Set the master select bits for Tranascoder Port Sync */
5021 trans_ddi_func_ctl2_val = (PORT_SYNC_MODE_MASTER_SELECT(master_select) &
5022 PORT_SYNC_MODE_MASTER_SELECT_MASK) <<
5023 PORT_SYNC_MODE_MASTER_SELECT_SHIFT;
5024 /* Enable Transcoder Port Sync */
5025 trans_ddi_func_ctl2_val |= PORT_SYNC_MODE_ENABLE;
5027 intel_de_write(dev_priv,
5028 TRANS_DDI_FUNC_CTL2(crtc_state->cpu_transcoder),
5029 trans_ddi_func_ctl2_val);
5032 static void intel_fdi_normal_train(struct intel_crtc *crtc)
5034 struct drm_device *dev = crtc->base.dev;
5035 struct drm_i915_private *dev_priv = to_i915(dev);
5036 enum pipe pipe = crtc->pipe;
5040 /* enable normal train */
5041 reg = FDI_TX_CTL(pipe);
5042 temp = intel_de_read(dev_priv, reg);
5043 if (IS_IVYBRIDGE(dev_priv)) {
5044 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
5045 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
5047 temp &= ~FDI_LINK_TRAIN_NONE;
5048 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
5050 intel_de_write(dev_priv, reg, temp);
5052 reg = FDI_RX_CTL(pipe);
5053 temp = intel_de_read(dev_priv, reg);
5054 if (HAS_PCH_CPT(dev_priv)) {
5055 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5056 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
5058 temp &= ~FDI_LINK_TRAIN_NONE;
5059 temp |= FDI_LINK_TRAIN_NONE;
5061 intel_de_write(dev_priv, reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
5063 /* wait one idle pattern time */
5064 intel_de_posting_read(dev_priv, reg);
5067 /* IVB wants error correction enabled */
5068 if (IS_IVYBRIDGE(dev_priv))
5069 intel_de_write(dev_priv, reg,
5070 intel_de_read(dev_priv, reg) | FDI_FS_ERRC_ENABLE | FDI_FE_ERRC_ENABLE);
5073 /* The FDI link training functions for ILK/Ibexpeak. */
5074 static void ilk_fdi_link_train(struct intel_crtc *crtc,
5075 const struct intel_crtc_state *crtc_state)
5077 struct drm_device *dev = crtc->base.dev;
5078 struct drm_i915_private *dev_priv = to_i915(dev);
5079 enum pipe pipe = crtc->pipe;
5083 /* FDI needs bits from pipe first */
5084 assert_pipe_enabled(dev_priv, crtc_state->cpu_transcoder);
5086 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5088 reg = FDI_RX_IMR(pipe);
5089 temp = intel_de_read(dev_priv, reg);
5090 temp &= ~FDI_RX_SYMBOL_LOCK;
5091 temp &= ~FDI_RX_BIT_LOCK;
5092 intel_de_write(dev_priv, reg, temp);
5093 intel_de_read(dev_priv, reg);
5096 /* enable CPU FDI TX and PCH FDI RX */
5097 reg = FDI_TX_CTL(pipe);
5098 temp = intel_de_read(dev_priv, reg);
5099 temp &= ~FDI_DP_PORT_WIDTH_MASK;
5100 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5101 temp &= ~FDI_LINK_TRAIN_NONE;
5102 temp |= FDI_LINK_TRAIN_PATTERN_1;
5103 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
5105 reg = FDI_RX_CTL(pipe);
5106 temp = intel_de_read(dev_priv, reg);
5107 temp &= ~FDI_LINK_TRAIN_NONE;
5108 temp |= FDI_LINK_TRAIN_PATTERN_1;
5109 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
5111 intel_de_posting_read(dev_priv, reg);
5114 /* Ironlake workaround, enable clock pointer after FDI enable*/
5115 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
5116 FDI_RX_PHASE_SYNC_POINTER_OVR);
5117 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
5118 FDI_RX_PHASE_SYNC_POINTER_OVR | FDI_RX_PHASE_SYNC_POINTER_EN);
5120 reg = FDI_RX_IIR(pipe);
5121 for (tries = 0; tries < 5; tries++) {
5122 temp = intel_de_read(dev_priv, reg);
5123 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5125 if ((temp & FDI_RX_BIT_LOCK)) {
5126 drm_dbg_kms(&dev_priv->drm, "FDI train 1 done.\n");
5127 intel_de_write(dev_priv, reg, temp | FDI_RX_BIT_LOCK);
5132 drm_err(&dev_priv->drm, "FDI train 1 fail!\n");
5135 reg = FDI_TX_CTL(pipe);
5136 temp = intel_de_read(dev_priv, reg);
5137 temp &= ~FDI_LINK_TRAIN_NONE;
5138 temp |= FDI_LINK_TRAIN_PATTERN_2;
5139 intel_de_write(dev_priv, reg, temp);
5141 reg = FDI_RX_CTL(pipe);
5142 temp = intel_de_read(dev_priv, reg);
5143 temp &= ~FDI_LINK_TRAIN_NONE;
5144 temp |= FDI_LINK_TRAIN_PATTERN_2;
5145 intel_de_write(dev_priv, reg, temp);
5147 intel_de_posting_read(dev_priv, reg);
5150 reg = FDI_RX_IIR(pipe);
5151 for (tries = 0; tries < 5; tries++) {
5152 temp = intel_de_read(dev_priv, reg);
5153 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5155 if (temp & FDI_RX_SYMBOL_LOCK) {
5156 intel_de_write(dev_priv, reg,
5157 temp | FDI_RX_SYMBOL_LOCK);
5158 drm_dbg_kms(&dev_priv->drm, "FDI train 2 done.\n");
5163 drm_err(&dev_priv->drm, "FDI train 2 fail!\n");
5165 drm_dbg_kms(&dev_priv->drm, "FDI train done\n");
5169 static const int snb_b_fdi_train_param[] = {
5170 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
5171 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
5172 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
5173 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
5176 /* The FDI link training functions for SNB/Cougarpoint. */
5177 static void gen6_fdi_link_train(struct intel_crtc *crtc,
5178 const struct intel_crtc_state *crtc_state)
5180 struct drm_device *dev = crtc->base.dev;
5181 struct drm_i915_private *dev_priv = to_i915(dev);
5182 enum pipe pipe = crtc->pipe;
5186 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5188 reg = FDI_RX_IMR(pipe);
5189 temp = intel_de_read(dev_priv, reg);
5190 temp &= ~FDI_RX_SYMBOL_LOCK;
5191 temp &= ~FDI_RX_BIT_LOCK;
5192 intel_de_write(dev_priv, reg, temp);
5194 intel_de_posting_read(dev_priv, reg);
5197 /* enable CPU FDI TX and PCH FDI RX */
5198 reg = FDI_TX_CTL(pipe);
5199 temp = intel_de_read(dev_priv, reg);
5200 temp &= ~FDI_DP_PORT_WIDTH_MASK;
5201 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5202 temp &= ~FDI_LINK_TRAIN_NONE;
5203 temp |= FDI_LINK_TRAIN_PATTERN_1;
5204 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5206 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
5207 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
5209 intel_de_write(dev_priv, FDI_RX_MISC(pipe),
5210 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
5212 reg = FDI_RX_CTL(pipe);
5213 temp = intel_de_read(dev_priv, reg);
5214 if (HAS_PCH_CPT(dev_priv)) {
5215 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5216 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5218 temp &= ~FDI_LINK_TRAIN_NONE;
5219 temp |= FDI_LINK_TRAIN_PATTERN_1;
5221 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
5223 intel_de_posting_read(dev_priv, reg);
5226 for (i = 0; i < 4; i++) {
5227 reg = FDI_TX_CTL(pipe);
5228 temp = intel_de_read(dev_priv, reg);
5229 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5230 temp |= snb_b_fdi_train_param[i];
5231 intel_de_write(dev_priv, reg, temp);
5233 intel_de_posting_read(dev_priv, reg);
5236 for (retry = 0; retry < 5; retry++) {
5237 reg = FDI_RX_IIR(pipe);
5238 temp = intel_de_read(dev_priv, reg);
5239 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5240 if (temp & FDI_RX_BIT_LOCK) {
5241 intel_de_write(dev_priv, reg,
5242 temp | FDI_RX_BIT_LOCK);
5243 drm_dbg_kms(&dev_priv->drm,
5244 "FDI train 1 done.\n");
5253 drm_err(&dev_priv->drm, "FDI train 1 fail!\n");
5256 reg = FDI_TX_CTL(pipe);
5257 temp = intel_de_read(dev_priv, reg);
5258 temp &= ~FDI_LINK_TRAIN_NONE;
5259 temp |= FDI_LINK_TRAIN_PATTERN_2;
5260 if (IS_GEN(dev_priv, 6)) {
5261 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5263 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
5265 intel_de_write(dev_priv, reg, temp);
5267 reg = FDI_RX_CTL(pipe);
5268 temp = intel_de_read(dev_priv, reg);
5269 if (HAS_PCH_CPT(dev_priv)) {
5270 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5271 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
5273 temp &= ~FDI_LINK_TRAIN_NONE;
5274 temp |= FDI_LINK_TRAIN_PATTERN_2;
5276 intel_de_write(dev_priv, reg, temp);
5278 intel_de_posting_read(dev_priv, reg);
5281 for (i = 0; i < 4; i++) {
5282 reg = FDI_TX_CTL(pipe);
5283 temp = intel_de_read(dev_priv, reg);
5284 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5285 temp |= snb_b_fdi_train_param[i];
5286 intel_de_write(dev_priv, reg, temp);
5288 intel_de_posting_read(dev_priv, reg);
5291 for (retry = 0; retry < 5; retry++) {
5292 reg = FDI_RX_IIR(pipe);
5293 temp = intel_de_read(dev_priv, reg);
5294 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5295 if (temp & FDI_RX_SYMBOL_LOCK) {
5296 intel_de_write(dev_priv, reg,
5297 temp | FDI_RX_SYMBOL_LOCK);
5298 drm_dbg_kms(&dev_priv->drm,
5299 "FDI train 2 done.\n");
5308 drm_err(&dev_priv->drm, "FDI train 2 fail!\n");
5310 drm_dbg_kms(&dev_priv->drm, "FDI train done.\n");
5313 /* Manual link training for Ivy Bridge A0 parts */
5314 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
5315 const struct intel_crtc_state *crtc_state)
5317 struct drm_device *dev = crtc->base.dev;
5318 struct drm_i915_private *dev_priv = to_i915(dev);
5319 enum pipe pipe = crtc->pipe;
5323 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
5325 reg = FDI_RX_IMR(pipe);
5326 temp = intel_de_read(dev_priv, reg);
5327 temp &= ~FDI_RX_SYMBOL_LOCK;
5328 temp &= ~FDI_RX_BIT_LOCK;
5329 intel_de_write(dev_priv, reg, temp);
5331 intel_de_posting_read(dev_priv, reg);
5334 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR before link train 0x%x\n",
5335 intel_de_read(dev_priv, FDI_RX_IIR(pipe)));
5337 /* Try each vswing and preemphasis setting twice before moving on */
5338 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
5339 /* disable first in case we need to retry */
5340 reg = FDI_TX_CTL(pipe);
5341 temp = intel_de_read(dev_priv, reg);
5342 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
5343 temp &= ~FDI_TX_ENABLE;
5344 intel_de_write(dev_priv, reg, temp);
5346 reg = FDI_RX_CTL(pipe);
5347 temp = intel_de_read(dev_priv, reg);
5348 temp &= ~FDI_LINK_TRAIN_AUTO;
5349 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5350 temp &= ~FDI_RX_ENABLE;
5351 intel_de_write(dev_priv, reg, temp);
5353 /* enable CPU FDI TX and PCH FDI RX */
5354 reg = FDI_TX_CTL(pipe);
5355 temp = intel_de_read(dev_priv, reg);
5356 temp &= ~FDI_DP_PORT_WIDTH_MASK;
5357 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5358 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
5359 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
5360 temp |= snb_b_fdi_train_param[j/2];
5361 temp |= FDI_COMPOSITE_SYNC;
5362 intel_de_write(dev_priv, reg, temp | FDI_TX_ENABLE);
5364 intel_de_write(dev_priv, FDI_RX_MISC(pipe),
5365 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
5367 reg = FDI_RX_CTL(pipe);
5368 temp = intel_de_read(dev_priv, reg);
5369 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5370 temp |= FDI_COMPOSITE_SYNC;
5371 intel_de_write(dev_priv, reg, temp | FDI_RX_ENABLE);
5373 intel_de_posting_read(dev_priv, reg);
5374 udelay(1); /* should be 0.5us */
5376 for (i = 0; i < 4; i++) {
5377 reg = FDI_RX_IIR(pipe);
5378 temp = intel_de_read(dev_priv, reg);
5379 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5381 if (temp & FDI_RX_BIT_LOCK ||
5382 (intel_de_read(dev_priv, reg) & FDI_RX_BIT_LOCK)) {
5383 intel_de_write(dev_priv, reg,
5384 temp | FDI_RX_BIT_LOCK);
5385 drm_dbg_kms(&dev_priv->drm,
5386 "FDI train 1 done, level %i.\n",
5390 udelay(1); /* should be 0.5us */
5393 drm_dbg_kms(&dev_priv->drm,
5394 "FDI train 1 fail on vswing %d\n", j / 2);
5399 reg = FDI_TX_CTL(pipe);
5400 temp = intel_de_read(dev_priv, reg);
5401 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
5402 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
5403 intel_de_write(dev_priv, reg, temp);
5405 reg = FDI_RX_CTL(pipe);
5406 temp = intel_de_read(dev_priv, reg);
5407 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5408 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
5409 intel_de_write(dev_priv, reg, temp);
5411 intel_de_posting_read(dev_priv, reg);
5412 udelay(2); /* should be 1.5us */
5414 for (i = 0; i < 4; i++) {
5415 reg = FDI_RX_IIR(pipe);
5416 temp = intel_de_read(dev_priv, reg);
5417 drm_dbg_kms(&dev_priv->drm, "FDI_RX_IIR 0x%x\n", temp);
5419 if (temp & FDI_RX_SYMBOL_LOCK ||
5420 (intel_de_read(dev_priv, reg) & FDI_RX_SYMBOL_LOCK)) {
5421 intel_de_write(dev_priv, reg,
5422 temp | FDI_RX_SYMBOL_LOCK);
5423 drm_dbg_kms(&dev_priv->drm,
5424 "FDI train 2 done, level %i.\n",
5428 udelay(2); /* should be 1.5us */
5431 drm_dbg_kms(&dev_priv->drm,
5432 "FDI train 2 fail on vswing %d\n", j / 2);
5436 drm_dbg_kms(&dev_priv->drm, "FDI train done.\n");
5439 static void ilk_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
5441 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
5442 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5443 enum pipe pipe = intel_crtc->pipe;
5447 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
5448 reg = FDI_RX_CTL(pipe);
5449 temp = intel_de_read(dev_priv, reg);
5450 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
5451 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
5452 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5453 intel_de_write(dev_priv, reg, temp | FDI_RX_PLL_ENABLE);
5455 intel_de_posting_read(dev_priv, reg);
5458 /* Switch from Rawclk to PCDclk */
5459 temp = intel_de_read(dev_priv, reg);
5460 intel_de_write(dev_priv, reg, temp | FDI_PCDCLK);
5462 intel_de_posting_read(dev_priv, reg);
5465 /* Enable CPU FDI TX PLL, always on for Ironlake */
5466 reg = FDI_TX_CTL(pipe);
5467 temp = intel_de_read(dev_priv, reg);
5468 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
5469 intel_de_write(dev_priv, reg, temp | FDI_TX_PLL_ENABLE);
5471 intel_de_posting_read(dev_priv, reg);
5476 static void ilk_fdi_pll_disable(struct intel_crtc *intel_crtc)
5478 struct drm_device *dev = intel_crtc->base.dev;
5479 struct drm_i915_private *dev_priv = to_i915(dev);
5480 enum pipe pipe = intel_crtc->pipe;
5484 /* Switch from PCDclk to Rawclk */
5485 reg = FDI_RX_CTL(pipe);
5486 temp = intel_de_read(dev_priv, reg);
5487 intel_de_write(dev_priv, reg, temp & ~FDI_PCDCLK);
5489 /* Disable CPU FDI TX PLL */
5490 reg = FDI_TX_CTL(pipe);
5491 temp = intel_de_read(dev_priv, reg);
5492 intel_de_write(dev_priv, reg, temp & ~FDI_TX_PLL_ENABLE);
5494 intel_de_posting_read(dev_priv, reg);
5497 reg = FDI_RX_CTL(pipe);
5498 temp = intel_de_read(dev_priv, reg);
5499 intel_de_write(dev_priv, reg, temp & ~FDI_RX_PLL_ENABLE);
5501 /* Wait for the clocks to turn off. */
5502 intel_de_posting_read(dev_priv, reg);
5506 static void ilk_fdi_disable(struct intel_crtc *crtc)
5508 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5509 enum pipe pipe = crtc->pipe;
5513 /* disable CPU FDI tx and PCH FDI rx */
5514 reg = FDI_TX_CTL(pipe);
5515 temp = intel_de_read(dev_priv, reg);
5516 intel_de_write(dev_priv, reg, temp & ~FDI_TX_ENABLE);
5517 intel_de_posting_read(dev_priv, reg);
5519 reg = FDI_RX_CTL(pipe);
5520 temp = intel_de_read(dev_priv, reg);
5521 temp &= ~(0x7 << 16);
5522 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5523 intel_de_write(dev_priv, reg, temp & ~FDI_RX_ENABLE);
5525 intel_de_posting_read(dev_priv, reg);
5528 /* Ironlake workaround, disable clock pointer after downing FDI */
5529 if (HAS_PCH_IBX(dev_priv))
5530 intel_de_write(dev_priv, FDI_RX_CHICKEN(pipe),
5531 FDI_RX_PHASE_SYNC_POINTER_OVR);
5533 /* still set train pattern 1 */
5534 reg = FDI_TX_CTL(pipe);
5535 temp = intel_de_read(dev_priv, reg);
5536 temp &= ~FDI_LINK_TRAIN_NONE;
5537 temp |= FDI_LINK_TRAIN_PATTERN_1;
5538 intel_de_write(dev_priv, reg, temp);
5540 reg = FDI_RX_CTL(pipe);
5541 temp = intel_de_read(dev_priv, reg);
5542 if (HAS_PCH_CPT(dev_priv)) {
5543 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
5544 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
5546 temp &= ~FDI_LINK_TRAIN_NONE;
5547 temp |= FDI_LINK_TRAIN_PATTERN_1;
5549 /* BPC in FDI rx is consistent with that in PIPECONF */
5550 temp &= ~(0x07 << 16);
5551 temp |= (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
5552 intel_de_write(dev_priv, reg, temp);
5554 intel_de_posting_read(dev_priv, reg);
5558 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
5560 struct drm_crtc *crtc;
5563 drm_for_each_crtc(crtc, &dev_priv->drm) {
5564 struct drm_crtc_commit *commit;
5565 spin_lock(&crtc->commit_lock);
5566 commit = list_first_entry_or_null(&crtc->commit_list,
5567 struct drm_crtc_commit, commit_entry);
5568 cleanup_done = commit ?
5569 try_wait_for_completion(&commit->cleanup_done) : true;
5570 spin_unlock(&crtc->commit_lock);
5575 drm_crtc_wait_one_vblank(crtc);
5583 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
5587 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_GATE);
5589 mutex_lock(&dev_priv->sb_lock);
5591 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5592 temp |= SBI_SSCCTL_DISABLE;
5593 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5595 mutex_unlock(&dev_priv->sb_lock);
5598 /* Program iCLKIP clock to the desired frequency */
5599 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
5601 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5602 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5603 int clock = crtc_state->hw.adjusted_mode.crtc_clock;
5604 u32 divsel, phaseinc, auxdiv, phasedir = 0;
5607 lpt_disable_iclkip(dev_priv);
5609 /* The iCLK virtual clock root frequency is in MHz,
5610 * but the adjusted_mode->crtc_clock in in KHz. To get the
5611 * divisors, it is necessary to divide one by another, so we
5612 * convert the virtual clock precision to KHz here for higher
5615 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
5616 u32 iclk_virtual_root_freq = 172800 * 1000;
5617 u32 iclk_pi_range = 64;
5618 u32 desired_divisor;
5620 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5622 divsel = (desired_divisor / iclk_pi_range) - 2;
5623 phaseinc = desired_divisor % iclk_pi_range;
5626 * Near 20MHz is a corner case which is
5627 * out of range for the 7-bit divisor
5633 /* This should not happen with any sane values */
5634 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
5635 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
5636 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIR(phasedir) &
5637 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
5639 drm_dbg_kms(&dev_priv->drm,
5640 "iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
5641 clock, auxdiv, divsel, phasedir, phaseinc);
5643 mutex_lock(&dev_priv->sb_lock);
5645 /* Program SSCDIVINTPHASE6 */
5646 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5647 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
5648 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
5649 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
5650 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
5651 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
5652 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
5653 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
5655 /* Program SSCAUXDIV */
5656 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5657 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
5658 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
5659 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
5661 /* Enable modulator and associated divider */
5662 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5663 temp &= ~SBI_SSCCTL_DISABLE;
5664 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
5666 mutex_unlock(&dev_priv->sb_lock);
5668 /* Wait for initialization time */
5671 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_UNGATE);
5674 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
5676 u32 divsel, phaseinc, auxdiv;
5677 u32 iclk_virtual_root_freq = 172800 * 1000;
5678 u32 iclk_pi_range = 64;
5679 u32 desired_divisor;
5682 if ((intel_de_read(dev_priv, PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
5685 mutex_lock(&dev_priv->sb_lock);
5687 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
5688 if (temp & SBI_SSCCTL_DISABLE) {
5689 mutex_unlock(&dev_priv->sb_lock);
5693 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
5694 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
5695 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
5696 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
5697 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
5699 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
5700 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
5701 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
5703 mutex_unlock(&dev_priv->sb_lock);
5705 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
5707 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
5708 desired_divisor << auxdiv);
5711 static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
5712 enum pipe pch_transcoder)
5714 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5715 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5716 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5718 intel_de_write(dev_priv, PCH_TRANS_HTOTAL(pch_transcoder),
5719 intel_de_read(dev_priv, HTOTAL(cpu_transcoder)));
5720 intel_de_write(dev_priv, PCH_TRANS_HBLANK(pch_transcoder),
5721 intel_de_read(dev_priv, HBLANK(cpu_transcoder)));
5722 intel_de_write(dev_priv, PCH_TRANS_HSYNC(pch_transcoder),
5723 intel_de_read(dev_priv, HSYNC(cpu_transcoder)));
5725 intel_de_write(dev_priv, PCH_TRANS_VTOTAL(pch_transcoder),
5726 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
5727 intel_de_write(dev_priv, PCH_TRANS_VBLANK(pch_transcoder),
5728 intel_de_read(dev_priv, VBLANK(cpu_transcoder)));
5729 intel_de_write(dev_priv, PCH_TRANS_VSYNC(pch_transcoder),
5730 intel_de_read(dev_priv, VSYNC(cpu_transcoder)));
5731 intel_de_write(dev_priv, PCH_TRANS_VSYNCSHIFT(pch_transcoder),
5732 intel_de_read(dev_priv, VSYNCSHIFT(cpu_transcoder)));
5735 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
5739 temp = intel_de_read(dev_priv, SOUTH_CHICKEN1);
5740 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
5743 drm_WARN_ON(&dev_priv->drm,
5744 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_B)) &
5746 drm_WARN_ON(&dev_priv->drm,
5747 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_C)) &
5750 temp &= ~FDI_BC_BIFURCATION_SELECT;
5752 temp |= FDI_BC_BIFURCATION_SELECT;
5754 drm_dbg_kms(&dev_priv->drm, "%sabling fdi C rx\n",
5755 enable ? "en" : "dis");
5756 intel_de_write(dev_priv, SOUTH_CHICKEN1, temp);
5757 intel_de_posting_read(dev_priv, SOUTH_CHICKEN1);
5760 static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
5762 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5763 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5765 switch (crtc->pipe) {
5769 if (crtc_state->fdi_lanes > 2)
5770 cpt_set_fdi_bc_bifurcation(dev_priv, false);
5772 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5776 cpt_set_fdi_bc_bifurcation(dev_priv, true);
5785 * Finds the encoder associated with the given CRTC. This can only be
5786 * used when we know that the CRTC isn't feeding multiple encoders!
5788 static struct intel_encoder *
5789 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
5790 const struct intel_crtc_state *crtc_state)
5792 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5793 const struct drm_connector_state *connector_state;
5794 const struct drm_connector *connector;
5795 struct intel_encoder *encoder = NULL;
5796 int num_encoders = 0;
5799 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5800 if (connector_state->crtc != &crtc->base)
5803 encoder = to_intel_encoder(connector_state->best_encoder);
5807 drm_WARN(encoder->base.dev, num_encoders != 1,
5808 "%d encoders for pipe %c\n",
5809 num_encoders, pipe_name(crtc->pipe));
5815 * Enable PCH resources required for PCH ports:
5817 * - FDI training & RX/TX
5818 * - update transcoder timings
5819 * - DP transcoding bits
5822 static void ilk_pch_enable(const struct intel_atomic_state *state,
5823 const struct intel_crtc_state *crtc_state)
5825 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5826 struct drm_device *dev = crtc->base.dev;
5827 struct drm_i915_private *dev_priv = to_i915(dev);
5828 enum pipe pipe = crtc->pipe;
5831 assert_pch_transcoder_disabled(dev_priv, pipe);
5833 if (IS_IVYBRIDGE(dev_priv))
5834 ivb_update_fdi_bc_bifurcation(crtc_state);
5836 /* Write the TU size bits before fdi link training, so that error
5837 * detection works. */
5838 intel_de_write(dev_priv, FDI_RX_TUSIZE1(pipe),
5839 intel_de_read(dev_priv, PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
5841 /* For PCH output, training FDI link */
5842 dev_priv->display.fdi_link_train(crtc, crtc_state);
5844 /* We need to program the right clock selection before writing the pixel
5845 * mutliplier into the DPLL. */
5846 if (HAS_PCH_CPT(dev_priv)) {
5849 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
5850 temp |= TRANS_DPLL_ENABLE(pipe);
5851 sel = TRANS_DPLLB_SEL(pipe);
5852 if (crtc_state->shared_dpll ==
5853 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
5857 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
5860 /* XXX: pch pll's can be enabled any time before we enable the PCH
5861 * transcoder, and we actually should do this to not upset any PCH
5862 * transcoder that already use the clock when we share it.
5864 * Note that enable_shared_dpll tries to do the right thing, but
5865 * get_shared_dpll unconditionally resets the pll - we need that to have
5866 * the right LVDS enable sequence. */
5867 intel_enable_shared_dpll(crtc_state);
5869 /* set transcoder timing, panel must allow it */
5870 assert_panel_unlocked(dev_priv, pipe);
5871 ilk_pch_transcoder_set_timings(crtc_state, pipe);
5873 intel_fdi_normal_train(crtc);
5875 /* For PCH DP, enable TRANS_DP_CTL */
5876 if (HAS_PCH_CPT(dev_priv) &&
5877 intel_crtc_has_dp_encoder(crtc_state)) {
5878 const struct drm_display_mode *adjusted_mode =
5879 &crtc_state->hw.adjusted_mode;
5880 u32 bpc = (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
5881 i915_reg_t reg = TRANS_DP_CTL(pipe);
5884 temp = intel_de_read(dev_priv, reg);
5885 temp &= ~(TRANS_DP_PORT_SEL_MASK |
5886 TRANS_DP_SYNC_MASK |
5888 temp |= TRANS_DP_OUTPUT_ENABLE;
5889 temp |= bpc << 9; /* same format but at 11:9 */
5891 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
5892 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
5893 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
5894 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
5896 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
5897 drm_WARN_ON(dev, port < PORT_B || port > PORT_D);
5898 temp |= TRANS_DP_PORT_SEL(port);
5900 intel_de_write(dev_priv, reg, temp);
5903 ilk_enable_pch_transcoder(crtc_state);
5906 void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
5908 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5909 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5910 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5912 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
5914 lpt_program_iclkip(crtc_state);
5916 /* Set transcoder timing. */
5917 ilk_pch_transcoder_set_timings(crtc_state, PIPE_A);
5919 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
5922 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
5925 i915_reg_t dslreg = PIPEDSL(pipe);
5928 temp = intel_de_read(dev_priv, dslreg);
5930 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) {
5931 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5))
5932 drm_err(&dev_priv->drm,
5933 "mode set failed: pipe %c stuck\n",
5939 * The hardware phase 0.0 refers to the center of the pixel.
5940 * We want to start from the top/left edge which is phase
5941 * -0.5. That matches how the hardware calculates the scaling
5942 * factors (from top-left of the first pixel to bottom-right
5943 * of the last pixel, as opposed to the pixel centers).
5945 * For 4:2:0 subsampled chroma planes we obviously have to
5946 * adjust that so that the chroma sample position lands in
5949 * Note that for packed YCbCr 4:2:2 formats there is no way to
5950 * control chroma siting. The hardware simply replicates the
5951 * chroma samples for both of the luma samples, and thus we don't
5952 * actually get the expected MPEG2 chroma siting convention :(
5953 * The same behaviour is observed on pre-SKL platforms as well.
5955 * Theory behind the formula (note that we ignore sub-pixel
5956 * source coordinates):
5957 * s = source sample position
5958 * d = destination sample position
5963 * | | 1.5 (initial phase)
5971 * | -0.375 (initial phase)
5978 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5980 int phase = -0x8000;
5984 phase += (sub - 1) * 0x8000 / sub;
5986 phase += scale / (2 * sub);
5989 * Hardware initial phase limited to [-0.5:1.5].
5990 * Since the max hardware scale factor is 3.0, we
5991 * should never actually excdeed 1.0 here.
5993 WARN_ON(phase < -0x8000 || phase > 0x18000);
5996 phase = 0x10000 + phase;
5998 trip = PS_PHASE_TRIP;
6000 return ((phase >> 2) & PS_PHASE_MASK) | trip;
6003 #define SKL_MIN_SRC_W 8
6004 #define SKL_MAX_SRC_W 4096
6005 #define SKL_MIN_SRC_H 8
6006 #define SKL_MAX_SRC_H 4096
6007 #define SKL_MIN_DST_W 8
6008 #define SKL_MAX_DST_W 4096
6009 #define SKL_MIN_DST_H 8
6010 #define SKL_MAX_DST_H 4096
6011 #define ICL_MAX_SRC_W 5120
6012 #define ICL_MAX_SRC_H 4096
6013 #define ICL_MAX_DST_W 5120
6014 #define ICL_MAX_DST_H 4096
6015 #define SKL_MIN_YUV_420_SRC_W 16
6016 #define SKL_MIN_YUV_420_SRC_H 16
6019 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
6020 unsigned int scaler_user, int *scaler_id,
6021 int src_w, int src_h, int dst_w, int dst_h,
6022 const struct drm_format_info *format,
6023 u64 modifier, bool need_scaler)
6025 struct intel_crtc_scaler_state *scaler_state =
6026 &crtc_state->scaler_state;
6027 struct intel_crtc *intel_crtc =
6028 to_intel_crtc(crtc_state->uapi.crtc);
6029 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
6030 const struct drm_display_mode *adjusted_mode =
6031 &crtc_state->hw.adjusted_mode;
6034 * Src coordinates are already rotated by 270 degrees for
6035 * the 90/270 degree plane rotation cases (to match the
6036 * GTT mapping), hence no need to account for rotation here.
6038 if (src_w != dst_w || src_h != dst_h)
6042 * Scaling/fitting not supported in IF-ID mode in GEN9+
6043 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
6044 * Once NV12 is enabled, handle it here while allocating scaler
6047 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->hw.enable &&
6048 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
6049 drm_dbg_kms(&dev_priv->drm,
6050 "Pipe/Plane scaling not supported with IF-ID mode\n");
6055 * if plane is being disabled or scaler is no more required or force detach
6056 * - free scaler binded to this plane/crtc
6057 * - in order to do this, update crtc->scaler_usage
6059 * Here scaler state in crtc_state is set free so that
6060 * scaler can be assigned to other user. Actual register
6061 * update to free the scaler is done in plane/panel-fit programming.
6062 * For this purpose crtc/plane_state->scaler_id isn't reset here.
6064 if (force_detach || !need_scaler) {
6065 if (*scaler_id >= 0) {
6066 scaler_state->scaler_users &= ~(1 << scaler_user);
6067 scaler_state->scalers[*scaler_id].in_use = 0;
6069 drm_dbg_kms(&dev_priv->drm,
6070 "scaler_user index %u.%u: "
6071 "Staged freeing scaler id %d scaler_users = 0x%x\n",
6072 intel_crtc->pipe, scaler_user, *scaler_id,
6073 scaler_state->scaler_users);
6079 if (format && intel_format_info_is_yuv_semiplanar(format, modifier) &&
6080 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
6081 drm_dbg_kms(&dev_priv->drm,
6082 "Planar YUV: src dimensions not met\n");
6087 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
6088 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
6089 (INTEL_GEN(dev_priv) >= 11 &&
6090 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
6091 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
6092 (INTEL_GEN(dev_priv) < 11 &&
6093 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
6094 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
6095 drm_dbg_kms(&dev_priv->drm,
6096 "scaler_user index %u.%u: src %ux%u dst %ux%u "
6097 "size is out of scaler range\n",
6098 intel_crtc->pipe, scaler_user, src_w, src_h,
6103 /* mark this plane as a scaler user in crtc_state */
6104 scaler_state->scaler_users |= (1 << scaler_user);
6105 drm_dbg_kms(&dev_priv->drm, "scaler_user index %u.%u: "
6106 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
6107 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
6108 scaler_state->scaler_users);
6114 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
6116 * @state: crtc's scaler state
6119 * 0 - scaler_usage updated successfully
6120 * error - requested scaling cannot be supported or other error condition
6122 int skl_update_scaler_crtc(struct intel_crtc_state *state)
6124 const struct drm_display_mode *adjusted_mode = &state->hw.adjusted_mode;
6125 bool need_scaler = false;
6127 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6128 state->pch_pfit.enabled)
6131 return skl_update_scaler(state, !state->hw.active, SKL_CRTC_INDEX,
6132 &state->scaler_state.scaler_id,
6133 state->pipe_src_w, state->pipe_src_h,
6134 adjusted_mode->crtc_hdisplay,
6135 adjusted_mode->crtc_vdisplay, NULL, 0,
6140 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
6141 * @crtc_state: crtc's scaler state
6142 * @plane_state: atomic plane state to update
6145 * 0 - scaler_usage updated successfully
6146 * error - requested scaling cannot be supported or other error condition
6148 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
6149 struct intel_plane_state *plane_state)
6151 struct intel_plane *intel_plane =
6152 to_intel_plane(plane_state->uapi.plane);
6153 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
6154 struct drm_framebuffer *fb = plane_state->hw.fb;
6156 bool force_detach = !fb || !plane_state->uapi.visible;
6157 bool need_scaler = false;
6159 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
6160 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
6161 fb && intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
6164 ret = skl_update_scaler(crtc_state, force_detach,
6165 drm_plane_index(&intel_plane->base),
6166 &plane_state->scaler_id,
6167 drm_rect_width(&plane_state->uapi.src) >> 16,
6168 drm_rect_height(&plane_state->uapi.src) >> 16,
6169 drm_rect_width(&plane_state->uapi.dst),
6170 drm_rect_height(&plane_state->uapi.dst),
6171 fb ? fb->format : NULL,
6172 fb ? fb->modifier : 0,
6175 if (ret || plane_state->scaler_id < 0)
6178 /* check colorkey */
6179 if (plane_state->ckey.flags) {
6180 drm_dbg_kms(&dev_priv->drm,
6181 "[PLANE:%d:%s] scaling with color key not allowed",
6182 intel_plane->base.base.id,
6183 intel_plane->base.name);
6187 /* Check src format */
6188 switch (fb->format->format) {
6189 case DRM_FORMAT_RGB565:
6190 case DRM_FORMAT_XBGR8888:
6191 case DRM_FORMAT_XRGB8888:
6192 case DRM_FORMAT_ABGR8888:
6193 case DRM_FORMAT_ARGB8888:
6194 case DRM_FORMAT_XRGB2101010:
6195 case DRM_FORMAT_XBGR2101010:
6196 case DRM_FORMAT_ARGB2101010:
6197 case DRM_FORMAT_ABGR2101010:
6198 case DRM_FORMAT_YUYV:
6199 case DRM_FORMAT_YVYU:
6200 case DRM_FORMAT_UYVY:
6201 case DRM_FORMAT_VYUY:
6202 case DRM_FORMAT_NV12:
6203 case DRM_FORMAT_P010:
6204 case DRM_FORMAT_P012:
6205 case DRM_FORMAT_P016:
6206 case DRM_FORMAT_Y210:
6207 case DRM_FORMAT_Y212:
6208 case DRM_FORMAT_Y216:
6209 case DRM_FORMAT_XVYU2101010:
6210 case DRM_FORMAT_XVYU12_16161616:
6211 case DRM_FORMAT_XVYU16161616:
6213 case DRM_FORMAT_XBGR16161616F:
6214 case DRM_FORMAT_ABGR16161616F:
6215 case DRM_FORMAT_XRGB16161616F:
6216 case DRM_FORMAT_ARGB16161616F:
6217 if (INTEL_GEN(dev_priv) >= 11)
6221 drm_dbg_kms(&dev_priv->drm,
6222 "[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
6223 intel_plane->base.base.id, intel_plane->base.name,
6224 fb->base.id, fb->format->format);
6231 void skl_scaler_disable(const struct intel_crtc_state *old_crtc_state)
6233 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
6236 for (i = 0; i < crtc->num_scalers; i++)
6237 skl_detach_scaler(crtc, i);
6240 static void skl_pfit_enable(const struct intel_crtc_state *crtc_state)
6242 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6243 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6244 enum pipe pipe = crtc->pipe;
6245 const struct intel_crtc_scaler_state *scaler_state =
6246 &crtc_state->scaler_state;
6248 if (crtc_state->pch_pfit.enabled) {
6249 u16 uv_rgb_hphase, uv_rgb_vphase;
6250 int pfit_w, pfit_h, hscale, vscale;
6251 unsigned long irqflags;
6254 if (drm_WARN_ON(&dev_priv->drm,
6255 crtc_state->scaler_state.scaler_id < 0))
6258 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
6259 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
6261 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
6262 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
6264 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
6265 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
6267 id = scaler_state->scaler_id;
6269 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
6271 intel_de_write_fw(dev_priv, SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
6272 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
6273 intel_de_write_fw(dev_priv, SKL_PS_VPHASE(pipe, id),
6274 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
6275 intel_de_write_fw(dev_priv, SKL_PS_HPHASE(pipe, id),
6276 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
6277 intel_de_write_fw(dev_priv, SKL_PS_WIN_POS(pipe, id),
6278 crtc_state->pch_pfit.pos);
6279 intel_de_write_fw(dev_priv, SKL_PS_WIN_SZ(pipe, id),
6280 crtc_state->pch_pfit.size);
6282 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
6286 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
6288 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6289 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6290 enum pipe pipe = crtc->pipe;
6292 if (crtc_state->pch_pfit.enabled) {
6293 /* Force use of hard-coded filter coefficients
6294 * as some pre-programmed values are broken,
6297 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
6298 intel_de_write(dev_priv, PF_CTL(pipe),
6299 PF_ENABLE | PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
6301 intel_de_write(dev_priv, PF_CTL(pipe),
6302 PF_ENABLE | PF_FILTER_MED_3x3);
6303 intel_de_write(dev_priv, PF_WIN_POS(pipe),
6304 crtc_state->pch_pfit.pos);
6305 intel_de_write(dev_priv, PF_WIN_SZ(pipe),
6306 crtc_state->pch_pfit.size);
6310 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
6312 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6313 struct drm_device *dev = crtc->base.dev;
6314 struct drm_i915_private *dev_priv = to_i915(dev);
6316 if (!crtc_state->ips_enabled)
6320 * We can only enable IPS after we enable a plane and wait for a vblank
6321 * This function is called from post_plane_update, which is run after
6324 drm_WARN_ON(dev, !(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
6326 if (IS_BROADWELL(dev_priv)) {
6327 drm_WARN_ON(dev, sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
6328 IPS_ENABLE | IPS_PCODE_CONTROL));
6329 /* Quoting Art Runyan: "its not safe to expect any particular
6330 * value in IPS_CTL bit 31 after enabling IPS through the
6331 * mailbox." Moreover, the mailbox may return a bogus state,
6332 * so we need to just enable it and continue on.
6335 intel_de_write(dev_priv, IPS_CTL, IPS_ENABLE);
6336 /* The bit only becomes 1 in the next vblank, so this wait here
6337 * is essentially intel_wait_for_vblank. If we don't have this
6338 * and don't wait for vblanks until the end of crtc_enable, then
6339 * the HW state readout code will complain that the expected
6340 * IPS_CTL value is not the one we read. */
6341 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
6342 drm_err(&dev_priv->drm,
6343 "Timed out waiting for IPS enable\n");
6347 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
6349 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6350 struct drm_device *dev = crtc->base.dev;
6351 struct drm_i915_private *dev_priv = to_i915(dev);
6353 if (!crtc_state->ips_enabled)
6356 if (IS_BROADWELL(dev_priv)) {
6358 sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
6360 * Wait for PCODE to finish disabling IPS. The BSpec specified
6361 * 42ms timeout value leads to occasional timeouts so use 100ms
6364 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
6365 drm_err(&dev_priv->drm,
6366 "Timed out waiting for IPS disable\n");
6368 intel_de_write(dev_priv, IPS_CTL, 0);
6369 intel_de_posting_read(dev_priv, IPS_CTL);
6372 /* We need to wait for a vblank before we can disable the plane. */
6373 intel_wait_for_vblank(dev_priv, crtc->pipe);
6376 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
6378 if (intel_crtc->overlay)
6379 (void) intel_overlay_switch_off(intel_crtc->overlay);
6381 /* Let userspace switch the overlay on again. In most cases userspace
6382 * has to recompute where to put it anyway.
6386 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
6387 const struct intel_crtc_state *new_crtc_state)
6389 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6390 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6392 if (!old_crtc_state->ips_enabled)
6395 if (needs_modeset(new_crtc_state))
6399 * Workaround : Do not read or write the pipe palette/gamma data while
6400 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6402 * Disable IPS before we program the LUT.
6404 if (IS_HASWELL(dev_priv) &&
6405 (new_crtc_state->uapi.color_mgmt_changed ||
6406 new_crtc_state->update_pipe) &&
6407 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6410 return !new_crtc_state->ips_enabled;
6413 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
6414 const struct intel_crtc_state *new_crtc_state)
6416 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6417 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6419 if (!new_crtc_state->ips_enabled)
6422 if (needs_modeset(new_crtc_state))
6426 * Workaround : Do not read or write the pipe palette/gamma data while
6427 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6429 * Re-enable IPS after the LUT has been programmed.
6431 if (IS_HASWELL(dev_priv) &&
6432 (new_crtc_state->uapi.color_mgmt_changed ||
6433 new_crtc_state->update_pipe) &&
6434 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
6438 * We can't read out IPS on broadwell, assume the worst and
6439 * forcibly enable IPS on the first fastset.
6441 if (new_crtc_state->update_pipe &&
6442 old_crtc_state->hw.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
6445 return !old_crtc_state->ips_enabled;
6448 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
6450 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6452 if (!crtc_state->nv12_planes)
6455 /* WA Display #0827: Gen9:all */
6456 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
6462 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
6464 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6466 /* Wa_2006604312:icl */
6467 if (crtc_state->scaler_state.scaler_users > 0 && IS_ICELAKE(dev_priv))
6473 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
6474 const struct intel_crtc_state *new_crtc_state)
6476 return (!old_crtc_state->active_planes || needs_modeset(new_crtc_state)) &&
6477 new_crtc_state->active_planes;
6480 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
6481 const struct intel_crtc_state *new_crtc_state)
6483 return old_crtc_state->active_planes &&
6484 (!new_crtc_state->active_planes || needs_modeset(new_crtc_state));
6487 static void intel_post_plane_update(struct intel_atomic_state *state,
6488 struct intel_crtc *crtc)
6490 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6491 const struct intel_crtc_state *old_crtc_state =
6492 intel_atomic_get_old_crtc_state(state, crtc);
6493 const struct intel_crtc_state *new_crtc_state =
6494 intel_atomic_get_new_crtc_state(state, crtc);
6495 enum pipe pipe = crtc->pipe;
6497 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
6499 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
6500 intel_update_watermarks(crtc);
6502 if (hsw_post_update_enable_ips(old_crtc_state, new_crtc_state))
6503 hsw_enable_ips(new_crtc_state);
6505 intel_fbc_post_update(state, crtc);
6507 if (needs_nv12_wa(old_crtc_state) &&
6508 !needs_nv12_wa(new_crtc_state))
6509 skl_wa_827(dev_priv, pipe, false);
6511 if (needs_scalerclk_wa(old_crtc_state) &&
6512 !needs_scalerclk_wa(new_crtc_state))
6513 icl_wa_scalerclkgating(dev_priv, pipe, false);
6516 static void intel_pre_plane_update(struct intel_atomic_state *state,
6517 struct intel_crtc *crtc)
6519 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6520 const struct intel_crtc_state *old_crtc_state =
6521 intel_atomic_get_old_crtc_state(state, crtc);
6522 const struct intel_crtc_state *new_crtc_state =
6523 intel_atomic_get_new_crtc_state(state, crtc);
6524 enum pipe pipe = crtc->pipe;
6526 if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
6527 hsw_disable_ips(old_crtc_state);
6529 if (intel_fbc_pre_update(state, crtc))
6530 intel_wait_for_vblank(dev_priv, pipe);
6532 /* Display WA 827 */
6533 if (!needs_nv12_wa(old_crtc_state) &&
6534 needs_nv12_wa(new_crtc_state))
6535 skl_wa_827(dev_priv, pipe, true);
6537 /* Wa_2006604312:icl */
6538 if (!needs_scalerclk_wa(old_crtc_state) &&
6539 needs_scalerclk_wa(new_crtc_state))
6540 icl_wa_scalerclkgating(dev_priv, pipe, true);
6543 * Vblank time updates from the shadow to live plane control register
6544 * are blocked if the memory self-refresh mode is active at that
6545 * moment. So to make sure the plane gets truly disabled, disable
6546 * first the self-refresh mode. The self-refresh enable bit in turn
6547 * will be checked/applied by the HW only at the next frame start
6548 * event which is after the vblank start event, so we need to have a
6549 * wait-for-vblank between disabling the plane and the pipe.
6551 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
6552 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
6553 intel_wait_for_vblank(dev_priv, pipe);
6556 * IVB workaround: must disable low power watermarks for at least
6557 * one frame before enabling scaling. LP watermarks can be re-enabled
6558 * when scaling is disabled.
6560 * WaCxSRDisabledForSpriteScaling:ivb
6562 if (old_crtc_state->hw.active &&
6563 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
6564 intel_wait_for_vblank(dev_priv, pipe);
6567 * If we're doing a modeset we don't need to do any
6568 * pre-vblank watermark programming here.
6570 if (!needs_modeset(new_crtc_state)) {
6572 * For platforms that support atomic watermarks, program the
6573 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
6574 * will be the intermediate values that are safe for both pre- and
6575 * post- vblank; when vblank happens, the 'active' values will be set
6576 * to the final 'target' values and we'll do this again to get the
6577 * optimal watermarks. For gen9+ platforms, the values we program here
6578 * will be the final target values which will get automatically latched
6579 * at vblank time; no further programming will be necessary.
6581 * If a platform hasn't been transitioned to atomic watermarks yet,
6582 * we'll continue to update watermarks the old way, if flags tell
6585 if (dev_priv->display.initial_watermarks)
6586 dev_priv->display.initial_watermarks(state, crtc);
6587 else if (new_crtc_state->update_wm_pre)
6588 intel_update_watermarks(crtc);
6592 * Gen2 reports pipe underruns whenever all planes are disabled.
6593 * So disable underrun reporting before all the planes get disabled.
6595 * We do this after .initial_watermarks() so that we have a
6596 * chance of catching underruns with the intermediate watermarks
6597 * vs. the old plane configuration.
6599 if (IS_GEN(dev_priv, 2) && planes_disabling(old_crtc_state, new_crtc_state))
6600 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6603 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
6604 struct intel_crtc *crtc)
6606 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6607 const struct intel_crtc_state *new_crtc_state =
6608 intel_atomic_get_new_crtc_state(state, crtc);
6609 unsigned int update_mask = new_crtc_state->update_planes;
6610 const struct intel_plane_state *old_plane_state;
6611 struct intel_plane *plane;
6612 unsigned fb_bits = 0;
6615 intel_crtc_dpms_overlay_disable(crtc);
6617 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
6618 if (crtc->pipe != plane->pipe ||
6619 !(update_mask & BIT(plane->id)))
6622 intel_disable_plane(plane, new_crtc_state);
6624 if (old_plane_state->uapi.visible)
6625 fb_bits |= plane->frontbuffer_bit;
6628 intel_frontbuffer_flip(dev_priv, fb_bits);
6632 * intel_connector_primary_encoder - get the primary encoder for a connector
6633 * @connector: connector for which to return the encoder
6635 * Returns the primary encoder for a connector. There is a 1:1 mapping from
6636 * all connectors to their encoder, except for DP-MST connectors which have
6637 * both a virtual and a primary encoder. These DP-MST primary encoders can be
6638 * pointed to by as many DP-MST connectors as there are pipes.
6640 static struct intel_encoder *
6641 intel_connector_primary_encoder(struct intel_connector *connector)
6643 struct intel_encoder *encoder;
6645 if (connector->mst_port)
6646 return &dp_to_dig_port(connector->mst_port)->base;
6648 encoder = intel_attached_encoder(connector);
6654 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
6656 struct drm_connector_state *new_conn_state;
6657 struct drm_connector *connector;
6660 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6662 struct intel_connector *intel_connector;
6663 struct intel_encoder *encoder;
6664 struct intel_crtc *crtc;
6666 if (!intel_connector_needs_modeset(state, connector))
6669 intel_connector = to_intel_connector(connector);
6670 encoder = intel_connector_primary_encoder(intel_connector);
6671 if (!encoder->update_prepare)
6674 crtc = new_conn_state->crtc ?
6675 to_intel_crtc(new_conn_state->crtc) : NULL;
6676 encoder->update_prepare(state, encoder, crtc);
6680 static void intel_encoders_update_complete(struct intel_atomic_state *state)
6682 struct drm_connector_state *new_conn_state;
6683 struct drm_connector *connector;
6686 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
6688 struct intel_connector *intel_connector;
6689 struct intel_encoder *encoder;
6690 struct intel_crtc *crtc;
6692 if (!intel_connector_needs_modeset(state, connector))
6695 intel_connector = to_intel_connector(connector);
6696 encoder = intel_connector_primary_encoder(intel_connector);
6697 if (!encoder->update_complete)
6700 crtc = new_conn_state->crtc ?
6701 to_intel_crtc(new_conn_state->crtc) : NULL;
6702 encoder->update_complete(state, encoder, crtc);
6706 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
6707 struct intel_crtc *crtc)
6709 const struct intel_crtc_state *crtc_state =
6710 intel_atomic_get_new_crtc_state(state, crtc);
6711 const struct drm_connector_state *conn_state;
6712 struct drm_connector *conn;
6715 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6716 struct intel_encoder *encoder =
6717 to_intel_encoder(conn_state->best_encoder);
6719 if (conn_state->crtc != &crtc->base)
6722 if (encoder->pre_pll_enable)
6723 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
6727 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
6728 struct intel_crtc *crtc)
6730 const struct intel_crtc_state *crtc_state =
6731 intel_atomic_get_new_crtc_state(state, crtc);
6732 const struct drm_connector_state *conn_state;
6733 struct drm_connector *conn;
6736 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6737 struct intel_encoder *encoder =
6738 to_intel_encoder(conn_state->best_encoder);
6740 if (conn_state->crtc != &crtc->base)
6743 if (encoder->pre_enable)
6744 encoder->pre_enable(encoder, crtc_state, conn_state);
6748 static void intel_encoders_enable(struct intel_atomic_state *state,
6749 struct intel_crtc *crtc)
6751 const struct intel_crtc_state *crtc_state =
6752 intel_atomic_get_new_crtc_state(state, crtc);
6753 const struct drm_connector_state *conn_state;
6754 struct drm_connector *conn;
6757 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6758 struct intel_encoder *encoder =
6759 to_intel_encoder(conn_state->best_encoder);
6761 if (conn_state->crtc != &crtc->base)
6764 if (encoder->enable)
6765 encoder->enable(encoder, crtc_state, conn_state);
6766 intel_opregion_notify_encoder(encoder, true);
6770 static void intel_encoders_disable(struct intel_atomic_state *state,
6771 struct intel_crtc *crtc)
6773 const struct intel_crtc_state *old_crtc_state =
6774 intel_atomic_get_old_crtc_state(state, crtc);
6775 const struct drm_connector_state *old_conn_state;
6776 struct drm_connector *conn;
6779 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6780 struct intel_encoder *encoder =
6781 to_intel_encoder(old_conn_state->best_encoder);
6783 if (old_conn_state->crtc != &crtc->base)
6786 intel_opregion_notify_encoder(encoder, false);
6787 if (encoder->disable)
6788 encoder->disable(encoder, old_crtc_state, old_conn_state);
6792 static void intel_encoders_post_disable(struct intel_atomic_state *state,
6793 struct intel_crtc *crtc)
6795 const struct intel_crtc_state *old_crtc_state =
6796 intel_atomic_get_old_crtc_state(state, crtc);
6797 const struct drm_connector_state *old_conn_state;
6798 struct drm_connector *conn;
6801 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6802 struct intel_encoder *encoder =
6803 to_intel_encoder(old_conn_state->best_encoder);
6805 if (old_conn_state->crtc != &crtc->base)
6808 if (encoder->post_disable)
6809 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
6813 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
6814 struct intel_crtc *crtc)
6816 const struct intel_crtc_state *old_crtc_state =
6817 intel_atomic_get_old_crtc_state(state, crtc);
6818 const struct drm_connector_state *old_conn_state;
6819 struct drm_connector *conn;
6822 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
6823 struct intel_encoder *encoder =
6824 to_intel_encoder(old_conn_state->best_encoder);
6826 if (old_conn_state->crtc != &crtc->base)
6829 if (encoder->post_pll_disable)
6830 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
6834 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
6835 struct intel_crtc *crtc)
6837 const struct intel_crtc_state *crtc_state =
6838 intel_atomic_get_new_crtc_state(state, crtc);
6839 const struct drm_connector_state *conn_state;
6840 struct drm_connector *conn;
6843 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
6844 struct intel_encoder *encoder =
6845 to_intel_encoder(conn_state->best_encoder);
6847 if (conn_state->crtc != &crtc->base)
6850 if (encoder->update_pipe)
6851 encoder->update_pipe(encoder, crtc_state, conn_state);
6855 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
6857 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6858 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6860 plane->disable_plane(plane, crtc_state);
6863 static void ilk_crtc_enable(struct intel_atomic_state *state,
6864 struct intel_crtc *crtc)
6866 const struct intel_crtc_state *new_crtc_state =
6867 intel_atomic_get_new_crtc_state(state, crtc);
6868 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6869 enum pipe pipe = crtc->pipe;
6871 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
6875 * Sometimes spurious CPU pipe underruns happen during FDI
6876 * training, at least with VGA+HDMI cloning. Suppress them.
6878 * On ILK we get an occasional spurious CPU pipe underruns
6879 * between eDP port A enable and vdd enable. Also PCH port
6880 * enable seems to result in the occasional CPU pipe underrun.
6882 * Spurious PCH underruns also occur during PCH enabling.
6884 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6885 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6887 if (new_crtc_state->has_pch_encoder)
6888 intel_prepare_shared_dpll(new_crtc_state);
6890 if (intel_crtc_has_dp_encoder(new_crtc_state))
6891 intel_dp_set_m_n(new_crtc_state, M1_N1);
6893 intel_set_pipe_timings(new_crtc_state);
6894 intel_set_pipe_src_size(new_crtc_state);
6896 if (new_crtc_state->has_pch_encoder)
6897 intel_cpu_transcoder_set_m_n(new_crtc_state,
6898 &new_crtc_state->fdi_m_n, NULL);
6900 ilk_set_pipeconf(new_crtc_state);
6902 crtc->active = true;
6904 intel_encoders_pre_enable(state, crtc);
6906 if (new_crtc_state->has_pch_encoder) {
6907 /* Note: FDI PLL enabling _must_ be done before we enable the
6908 * cpu pipes, hence this is separate from all the other fdi/pch
6910 ilk_fdi_pll_enable(new_crtc_state);
6912 assert_fdi_tx_disabled(dev_priv, pipe);
6913 assert_fdi_rx_disabled(dev_priv, pipe);
6916 ilk_pfit_enable(new_crtc_state);
6919 * On ILK+ LUT must be loaded before the pipe is running but with
6922 intel_color_load_luts(new_crtc_state);
6923 intel_color_commit(new_crtc_state);
6924 /* update DSPCNTR to configure gamma for pipe bottom color */
6925 intel_disable_primary_plane(new_crtc_state);
6927 if (dev_priv->display.initial_watermarks)
6928 dev_priv->display.initial_watermarks(state, crtc);
6929 intel_enable_pipe(new_crtc_state);
6931 if (new_crtc_state->has_pch_encoder)
6932 ilk_pch_enable(state, new_crtc_state);
6934 intel_crtc_vblank_on(new_crtc_state);
6936 intel_encoders_enable(state, crtc);
6938 if (HAS_PCH_CPT(dev_priv))
6939 cpt_verify_modeset(dev_priv, pipe);
6942 * Must wait for vblank to avoid spurious PCH FIFO underruns.
6943 * And a second vblank wait is needed at least on ILK with
6944 * some interlaced HDMI modes. Let's do the double wait always
6945 * in case there are more corner cases we don't know about.
6947 if (new_crtc_state->has_pch_encoder) {
6948 intel_wait_for_vblank(dev_priv, pipe);
6949 intel_wait_for_vblank(dev_priv, pipe);
6951 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6952 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6955 /* IPS only exists on ULT machines and is tied to pipe A. */
6956 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
6958 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
6961 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
6962 enum pipe pipe, bool apply)
6964 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
6965 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
6972 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
6975 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
6977 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6978 enum pipe pipe = crtc->pipe;
6981 val = MBUS_DBOX_A_CREDIT(2);
6983 if (INTEL_GEN(dev_priv) >= 12) {
6984 val |= MBUS_DBOX_BW_CREDIT(2);
6985 val |= MBUS_DBOX_B_CREDIT(12);
6987 val |= MBUS_DBOX_BW_CREDIT(1);
6988 val |= MBUS_DBOX_B_CREDIT(8);
6991 intel_de_write(dev_priv, PIPE_MBUS_DBOX_CTL(pipe), val);
6994 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
6996 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6997 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6999 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
7000 HSW_LINETIME(crtc_state->linetime) |
7001 HSW_IPS_LINETIME(crtc_state->ips_linetime));
7004 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
7006 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7007 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7008 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
7011 val = intel_de_read(dev_priv, reg);
7012 val &= ~HSW_FRAME_START_DELAY_MASK;
7013 val |= HSW_FRAME_START_DELAY(0);
7014 intel_de_write(dev_priv, reg, val);
7017 static void hsw_crtc_enable(struct intel_atomic_state *state,
7018 struct intel_crtc *crtc)
7020 const struct intel_crtc_state *new_crtc_state =
7021 intel_atomic_get_new_crtc_state(state, crtc);
7022 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7023 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
7024 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
7025 bool psl_clkgate_wa;
7027 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
7030 intel_encoders_pre_pll_enable(state, crtc);
7032 if (new_crtc_state->shared_dpll)
7033 intel_enable_shared_dpll(new_crtc_state);
7035 intel_encoders_pre_enable(state, crtc);
7037 if (!transcoder_is_dsi(cpu_transcoder))
7038 intel_set_pipe_timings(new_crtc_state);
7040 if (INTEL_GEN(dev_priv) >= 11)
7041 icl_enable_trans_port_sync(new_crtc_state);
7043 intel_set_pipe_src_size(new_crtc_state);
7045 if (cpu_transcoder != TRANSCODER_EDP &&
7046 !transcoder_is_dsi(cpu_transcoder))
7047 intel_de_write(dev_priv, PIPE_MULT(cpu_transcoder),
7048 new_crtc_state->pixel_multiplier - 1);
7050 if (new_crtc_state->has_pch_encoder)
7051 intel_cpu_transcoder_set_m_n(new_crtc_state,
7052 &new_crtc_state->fdi_m_n, NULL);
7054 if (!transcoder_is_dsi(cpu_transcoder)) {
7055 hsw_set_frame_start_delay(new_crtc_state);
7056 hsw_set_pipeconf(new_crtc_state);
7059 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
7060 bdw_set_pipemisc(new_crtc_state);
7062 crtc->active = true;
7064 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
7065 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
7066 new_crtc_state->pch_pfit.enabled;
7068 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
7070 if (INTEL_GEN(dev_priv) >= 9)
7071 skl_pfit_enable(new_crtc_state);
7073 ilk_pfit_enable(new_crtc_state);
7076 * On ILK+ LUT must be loaded before the pipe is running but with
7079 intel_color_load_luts(new_crtc_state);
7080 intel_color_commit(new_crtc_state);
7081 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
7082 if (INTEL_GEN(dev_priv) < 9)
7083 intel_disable_primary_plane(new_crtc_state);
7085 hsw_set_linetime_wm(new_crtc_state);
7087 if (INTEL_GEN(dev_priv) >= 11)
7088 icl_set_pipe_chicken(crtc);
7090 if (!transcoder_is_dsi(cpu_transcoder))
7091 intel_ddi_enable_transcoder_func(new_crtc_state);
7093 if (dev_priv->display.initial_watermarks)
7094 dev_priv->display.initial_watermarks(state, crtc);
7096 if (INTEL_GEN(dev_priv) >= 11)
7097 icl_pipe_mbus_enable(crtc);
7099 intel_encoders_enable(state, crtc);
7101 if (psl_clkgate_wa) {
7102 intel_wait_for_vblank(dev_priv, pipe);
7103 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
7106 /* If we change the relative order between pipe/planes enabling, we need
7107 * to change the workaround. */
7108 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
7109 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
7110 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
7111 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
7115 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
7117 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
7118 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7119 enum pipe pipe = crtc->pipe;
7121 /* To avoid upsetting the power well on haswell only disable the pfit if
7122 * it's in use. The hw state code will make sure we get this right. */
7123 if (old_crtc_state->pch_pfit.enabled) {
7124 intel_de_write(dev_priv, PF_CTL(pipe), 0);
7125 intel_de_write(dev_priv, PF_WIN_POS(pipe), 0);
7126 intel_de_write(dev_priv, PF_WIN_SZ(pipe), 0);
7130 static void ilk_crtc_disable(struct intel_atomic_state *state,
7131 struct intel_crtc *crtc)
7133 const struct intel_crtc_state *old_crtc_state =
7134 intel_atomic_get_old_crtc_state(state, crtc);
7135 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7136 enum pipe pipe = crtc->pipe;
7139 * Sometimes spurious CPU pipe underruns happen when the
7140 * pipe is already disabled, but FDI RX/TX is still enabled.
7141 * Happens at least with VGA+HDMI cloning. Suppress them.
7143 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7144 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
7146 intel_encoders_disable(state, crtc);
7148 intel_crtc_vblank_off(old_crtc_state);
7150 intel_disable_pipe(old_crtc_state);
7152 ilk_pfit_disable(old_crtc_state);
7154 if (old_crtc_state->has_pch_encoder)
7155 ilk_fdi_disable(crtc);
7157 intel_encoders_post_disable(state, crtc);
7159 if (old_crtc_state->has_pch_encoder) {
7160 ilk_disable_pch_transcoder(dev_priv, pipe);
7162 if (HAS_PCH_CPT(dev_priv)) {
7166 /* disable TRANS_DP_CTL */
7167 reg = TRANS_DP_CTL(pipe);
7168 temp = intel_de_read(dev_priv, reg);
7169 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
7170 TRANS_DP_PORT_SEL_MASK);
7171 temp |= TRANS_DP_PORT_SEL_NONE;
7172 intel_de_write(dev_priv, reg, temp);
7174 /* disable DPLL_SEL */
7175 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
7176 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
7177 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
7180 ilk_fdi_pll_disable(crtc);
7183 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7184 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
7187 static void hsw_crtc_disable(struct intel_atomic_state *state,
7188 struct intel_crtc *crtc)
7191 * FIXME collapse everything to one hook.
7192 * Need care with mst->ddi interactions.
7194 intel_encoders_disable(state, crtc);
7195 intel_encoders_post_disable(state, crtc);
7198 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
7200 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7201 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7203 if (!crtc_state->gmch_pfit.control)
7207 * The panel fitter should only be adjusted whilst the pipe is disabled,
7208 * according to register description and PRM.
7210 drm_WARN_ON(&dev_priv->drm,
7211 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
7212 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
7214 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
7215 crtc_state->gmch_pfit.pgm_ratios);
7216 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
7218 /* Border color in case we don't scale up to the full screen. Black by
7219 * default, change to something else for debugging. */
7220 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
7223 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
7225 if (phy == PHY_NONE)
7228 if (IS_ELKHARTLAKE(dev_priv))
7229 return phy <= PHY_C;
7231 if (INTEL_GEN(dev_priv) >= 11)
7232 return phy <= PHY_B;
7237 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
7239 if (INTEL_GEN(dev_priv) >= 12)
7240 return phy >= PHY_D && phy <= PHY_I;
7242 if (INTEL_GEN(dev_priv) >= 11 && !IS_ELKHARTLAKE(dev_priv))
7243 return phy >= PHY_C && phy <= PHY_F;
7248 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
7250 if (IS_ELKHARTLAKE(i915) && port == PORT_D)
7253 return (enum phy)port;
7256 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
7258 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
7259 return PORT_TC_NONE;
7261 if (INTEL_GEN(dev_priv) >= 12)
7262 return port - PORT_D;
7264 return port - PORT_C;
7267 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
7271 return POWER_DOMAIN_PORT_DDI_A_LANES;
7273 return POWER_DOMAIN_PORT_DDI_B_LANES;
7275 return POWER_DOMAIN_PORT_DDI_C_LANES;
7277 return POWER_DOMAIN_PORT_DDI_D_LANES;
7279 return POWER_DOMAIN_PORT_DDI_E_LANES;
7281 return POWER_DOMAIN_PORT_DDI_F_LANES;
7283 return POWER_DOMAIN_PORT_DDI_G_LANES;
7286 return POWER_DOMAIN_PORT_OTHER;
7290 enum intel_display_power_domain
7291 intel_aux_power_domain(struct intel_digital_port *dig_port)
7293 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
7294 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
7296 if (intel_phy_is_tc(dev_priv, phy) &&
7297 dig_port->tc_mode == TC_PORT_TBT_ALT) {
7298 switch (dig_port->aux_ch) {
7300 return POWER_DOMAIN_AUX_C_TBT;
7302 return POWER_DOMAIN_AUX_D_TBT;
7304 return POWER_DOMAIN_AUX_E_TBT;
7306 return POWER_DOMAIN_AUX_F_TBT;
7308 return POWER_DOMAIN_AUX_G_TBT;
7310 MISSING_CASE(dig_port->aux_ch);
7311 return POWER_DOMAIN_AUX_C_TBT;
7315 switch (dig_port->aux_ch) {
7317 return POWER_DOMAIN_AUX_A;
7319 return POWER_DOMAIN_AUX_B;
7321 return POWER_DOMAIN_AUX_C;
7323 return POWER_DOMAIN_AUX_D;
7325 return POWER_DOMAIN_AUX_E;
7327 return POWER_DOMAIN_AUX_F;
7329 return POWER_DOMAIN_AUX_G;
7331 MISSING_CASE(dig_port->aux_ch);
7332 return POWER_DOMAIN_AUX_A;
7336 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7338 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7339 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7340 struct drm_encoder *encoder;
7341 enum pipe pipe = crtc->pipe;
7343 enum transcoder transcoder = crtc_state->cpu_transcoder;
7345 if (!crtc_state->hw.active)
7348 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
7349 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
7350 if (crtc_state->pch_pfit.enabled ||
7351 crtc_state->pch_pfit.force_thru)
7352 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
7354 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
7355 crtc_state->uapi.encoder_mask) {
7356 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7358 mask |= BIT_ULL(intel_encoder->power_domain);
7361 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
7362 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
7364 if (crtc_state->shared_dpll)
7365 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
7371 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
7373 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7374 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7375 enum intel_display_power_domain domain;
7376 u64 domains, new_domains, old_domains;
7378 old_domains = crtc->enabled_power_domains;
7379 crtc->enabled_power_domains = new_domains =
7380 get_crtc_power_domains(crtc_state);
7382 domains = new_domains & ~old_domains;
7384 for_each_power_domain(domain, domains)
7385 intel_display_power_get(dev_priv, domain);
7387 return old_domains & ~new_domains;
7390 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
7393 enum intel_display_power_domain domain;
7395 for_each_power_domain(domain, domains)
7396 intel_display_power_put_unchecked(dev_priv, domain);
7399 static void valleyview_crtc_enable(struct intel_atomic_state *state,
7400 struct intel_crtc *crtc)
7402 const struct intel_crtc_state *new_crtc_state =
7403 intel_atomic_get_new_crtc_state(state, crtc);
7404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7405 enum pipe pipe = crtc->pipe;
7407 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
7410 if (intel_crtc_has_dp_encoder(new_crtc_state))
7411 intel_dp_set_m_n(new_crtc_state, M1_N1);
7413 intel_set_pipe_timings(new_crtc_state);
7414 intel_set_pipe_src_size(new_crtc_state);
7416 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
7417 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
7418 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
7421 i9xx_set_pipeconf(new_crtc_state);
7423 crtc->active = true;
7425 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7427 intel_encoders_pre_pll_enable(state, crtc);
7429 if (IS_CHERRYVIEW(dev_priv)) {
7430 chv_prepare_pll(crtc, new_crtc_state);
7431 chv_enable_pll(crtc, new_crtc_state);
7433 vlv_prepare_pll(crtc, new_crtc_state);
7434 vlv_enable_pll(crtc, new_crtc_state);
7437 intel_encoders_pre_enable(state, crtc);
7439 i9xx_pfit_enable(new_crtc_state);
7441 intel_color_load_luts(new_crtc_state);
7442 intel_color_commit(new_crtc_state);
7443 /* update DSPCNTR to configure gamma for pipe bottom color */
7444 intel_disable_primary_plane(new_crtc_state);
7446 dev_priv->display.initial_watermarks(state, crtc);
7447 intel_enable_pipe(new_crtc_state);
7449 intel_crtc_vblank_on(new_crtc_state);
7451 intel_encoders_enable(state, crtc);
7454 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
7456 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7457 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7459 intel_de_write(dev_priv, FP0(crtc->pipe),
7460 crtc_state->dpll_hw_state.fp0);
7461 intel_de_write(dev_priv, FP1(crtc->pipe),
7462 crtc_state->dpll_hw_state.fp1);
7465 static void i9xx_crtc_enable(struct intel_atomic_state *state,
7466 struct intel_crtc *crtc)
7468 const struct intel_crtc_state *new_crtc_state =
7469 intel_atomic_get_new_crtc_state(state, crtc);
7470 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7471 enum pipe pipe = crtc->pipe;
7473 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
7476 i9xx_set_pll_dividers(new_crtc_state);
7478 if (intel_crtc_has_dp_encoder(new_crtc_state))
7479 intel_dp_set_m_n(new_crtc_state, M1_N1);
7481 intel_set_pipe_timings(new_crtc_state);
7482 intel_set_pipe_src_size(new_crtc_state);
7484 i9xx_set_pipeconf(new_crtc_state);
7486 crtc->active = true;
7488 if (!IS_GEN(dev_priv, 2))
7489 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
7491 intel_encoders_pre_enable(state, crtc);
7493 i9xx_enable_pll(crtc, new_crtc_state);
7495 i9xx_pfit_enable(new_crtc_state);
7497 intel_color_load_luts(new_crtc_state);
7498 intel_color_commit(new_crtc_state);
7499 /* update DSPCNTR to configure gamma for pipe bottom color */
7500 intel_disable_primary_plane(new_crtc_state);
7502 if (dev_priv->display.initial_watermarks)
7503 dev_priv->display.initial_watermarks(state, crtc);
7505 intel_update_watermarks(crtc);
7506 intel_enable_pipe(new_crtc_state);
7508 intel_crtc_vblank_on(new_crtc_state);
7510 intel_encoders_enable(state, crtc);
7513 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
7515 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
7516 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7518 if (!old_crtc_state->gmch_pfit.control)
7521 assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
7523 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
7524 intel_de_read(dev_priv, PFIT_CONTROL));
7525 intel_de_write(dev_priv, PFIT_CONTROL, 0);
7528 static void i9xx_crtc_disable(struct intel_atomic_state *state,
7529 struct intel_crtc *crtc)
7531 struct intel_crtc_state *old_crtc_state =
7532 intel_atomic_get_old_crtc_state(state, crtc);
7533 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7534 enum pipe pipe = crtc->pipe;
7537 * On gen2 planes are double buffered but the pipe isn't, so we must
7538 * wait for planes to fully turn off before disabling the pipe.
7540 if (IS_GEN(dev_priv, 2))
7541 intel_wait_for_vblank(dev_priv, pipe);
7543 intel_encoders_disable(state, crtc);
7545 intel_crtc_vblank_off(old_crtc_state);
7547 intel_disable_pipe(old_crtc_state);
7549 i9xx_pfit_disable(old_crtc_state);
7551 intel_encoders_post_disable(state, crtc);
7553 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
7554 if (IS_CHERRYVIEW(dev_priv))
7555 chv_disable_pll(dev_priv, pipe);
7556 else if (IS_VALLEYVIEW(dev_priv))
7557 vlv_disable_pll(dev_priv, pipe);
7559 i9xx_disable_pll(old_crtc_state);
7562 intel_encoders_post_pll_disable(state, crtc);
7564 if (!IS_GEN(dev_priv, 2))
7565 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
7567 if (!dev_priv->display.initial_watermarks)
7568 intel_update_watermarks(crtc);
7570 /* clock the pipe down to 640x480@60 to potentially save power */
7571 if (IS_I830(dev_priv))
7572 i830_enable_pipe(dev_priv, pipe);
7575 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc,
7576 struct drm_modeset_acquire_ctx *ctx)
7578 struct intel_encoder *encoder;
7579 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7580 struct intel_bw_state *bw_state =
7581 to_intel_bw_state(dev_priv->bw_obj.state);
7582 struct intel_cdclk_state *cdclk_state =
7583 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
7584 struct intel_crtc_state *crtc_state =
7585 to_intel_crtc_state(crtc->base.state);
7586 enum intel_display_power_domain domain;
7587 struct intel_plane *plane;
7588 struct drm_atomic_state *state;
7589 struct intel_crtc_state *temp_crtc_state;
7590 enum pipe pipe = crtc->pipe;
7594 if (!crtc_state->hw.active)
7597 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
7598 const struct intel_plane_state *plane_state =
7599 to_intel_plane_state(plane->base.state);
7601 if (plane_state->uapi.visible)
7602 intel_plane_disable_noatomic(crtc, plane);
7605 state = drm_atomic_state_alloc(&dev_priv->drm);
7607 drm_dbg_kms(&dev_priv->drm,
7608 "failed to disable [CRTC:%d:%s], out of memory",
7609 crtc->base.base.id, crtc->base.name);
7613 state->acquire_ctx = ctx;
7615 /* Everything's already locked, -EDEADLK can't happen. */
7616 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc);
7617 ret = drm_atomic_add_affected_connectors(state, &crtc->base);
7619 drm_WARN_ON(&dev_priv->drm, IS_ERR(temp_crtc_state) || ret);
7621 dev_priv->display.crtc_disable(to_intel_atomic_state(state), crtc);
7623 drm_atomic_state_put(state);
7625 drm_dbg_kms(&dev_priv->drm,
7626 "[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
7627 crtc->base.base.id, crtc->base.name);
7629 crtc->active = false;
7630 crtc->base.enabled = false;
7632 drm_WARN_ON(&dev_priv->drm,
7633 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0);
7634 crtc_state->uapi.active = false;
7635 crtc_state->uapi.connector_mask = 0;
7636 crtc_state->uapi.encoder_mask = 0;
7637 intel_crtc_free_hw_state(crtc_state);
7638 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw));
7640 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder)
7641 encoder->base.crtc = NULL;
7643 intel_fbc_disable(crtc);
7644 intel_update_watermarks(crtc);
7645 intel_disable_shared_dpll(crtc_state);
7647 domains = crtc->enabled_power_domains;
7648 for_each_power_domain(domain, domains)
7649 intel_display_power_put_unchecked(dev_priv, domain);
7650 crtc->enabled_power_domains = 0;
7652 dev_priv->active_pipes &= ~BIT(pipe);
7653 cdclk_state->min_cdclk[pipe] = 0;
7654 cdclk_state->min_voltage_level[pipe] = 0;
7655 cdclk_state->active_pipes &= ~BIT(pipe);
7657 bw_state->data_rate[pipe] = 0;
7658 bw_state->num_active_planes[pipe] = 0;
7662 * turn all crtc's off, but do not adjust state
7663 * This has to be paired with a call to intel_modeset_setup_hw_state.
7665 int intel_display_suspend(struct drm_device *dev)
7667 struct drm_i915_private *dev_priv = to_i915(dev);
7668 struct drm_atomic_state *state;
7671 state = drm_atomic_helper_suspend(dev);
7672 ret = PTR_ERR_OR_ZERO(state);
7674 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
7677 dev_priv->modeset_restore_state = state;
7681 void intel_encoder_destroy(struct drm_encoder *encoder)
7683 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
7685 drm_encoder_cleanup(encoder);
7686 kfree(intel_encoder);
7689 /* Cross check the actual hw state with our own modeset state tracking (and it's
7690 * internal consistency). */
7691 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
7692 struct drm_connector_state *conn_state)
7694 struct intel_connector *connector = to_intel_connector(conn_state->connector);
7695 struct drm_i915_private *i915 = to_i915(connector->base.dev);
7697 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n",
7698 connector->base.base.id, connector->base.name);
7700 if (connector->get_hw_state(connector)) {
7701 struct intel_encoder *encoder = intel_attached_encoder(connector);
7703 I915_STATE_WARN(!crtc_state,
7704 "connector enabled without attached crtc\n");
7709 I915_STATE_WARN(!crtc_state->hw.active,
7710 "connector is active, but attached crtc isn't\n");
7712 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
7715 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
7716 "atomic encoder doesn't match attached encoder\n");
7718 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
7719 "attached encoder crtc differs from connector crtc\n");
7721 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
7722 "attached crtc is active, but connector isn't\n");
7723 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
7724 "best encoder set without crtc!\n");
7728 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
7730 if (crtc_state->hw.enable && crtc_state->has_pch_encoder)
7731 return crtc_state->fdi_lanes;
7736 static int ilk_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
7737 struct intel_crtc_state *pipe_config)
7739 struct drm_i915_private *dev_priv = to_i915(dev);
7740 struct drm_atomic_state *state = pipe_config->uapi.state;
7741 struct intel_crtc *other_crtc;
7742 struct intel_crtc_state *other_crtc_state;
7744 drm_dbg_kms(&dev_priv->drm,
7745 "checking fdi config on pipe %c, lanes %i\n",
7746 pipe_name(pipe), pipe_config->fdi_lanes);
7747 if (pipe_config->fdi_lanes > 4) {
7748 drm_dbg_kms(&dev_priv->drm,
7749 "invalid fdi lane config on pipe %c: %i lanes\n",
7750 pipe_name(pipe), pipe_config->fdi_lanes);
7754 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7755 if (pipe_config->fdi_lanes > 2) {
7756 drm_dbg_kms(&dev_priv->drm,
7757 "only 2 lanes on haswell, required: %i lanes\n",
7758 pipe_config->fdi_lanes);
7765 if (INTEL_NUM_PIPES(dev_priv) == 2)
7768 /* Ivybridge 3 pipe is really complicated */
7773 if (pipe_config->fdi_lanes <= 2)
7776 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
7778 intel_atomic_get_crtc_state(state, other_crtc);
7779 if (IS_ERR(other_crtc_state))
7780 return PTR_ERR(other_crtc_state);
7782 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
7783 drm_dbg_kms(&dev_priv->drm,
7784 "invalid shared fdi lane config on pipe %c: %i lanes\n",
7785 pipe_name(pipe), pipe_config->fdi_lanes);
7790 if (pipe_config->fdi_lanes > 2) {
7791 drm_dbg_kms(&dev_priv->drm,
7792 "only 2 lanes on pipe %c: required %i lanes\n",
7793 pipe_name(pipe), pipe_config->fdi_lanes);
7797 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
7799 intel_atomic_get_crtc_state(state, other_crtc);
7800 if (IS_ERR(other_crtc_state))
7801 return PTR_ERR(other_crtc_state);
7803 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
7804 drm_dbg_kms(&dev_priv->drm,
7805 "fdi link B uses too many lanes to enable link C\n");
7815 static int ilk_fdi_compute_config(struct intel_crtc *intel_crtc,
7816 struct intel_crtc_state *pipe_config)
7818 struct drm_device *dev = intel_crtc->base.dev;
7819 struct drm_i915_private *i915 = to_i915(dev);
7820 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7821 int lane, link_bw, fdi_dotclock, ret;
7822 bool needs_recompute = false;
7825 /* FDI is a binary signal running at ~2.7GHz, encoding
7826 * each output octet as 10 bits. The actual frequency
7827 * is stored as a divider into a 100MHz clock, and the
7828 * mode pixel clock is stored in units of 1KHz.
7829 * Hence the bw of each lane in terms of the mode signal
7832 link_bw = intel_fdi_link_freq(i915, pipe_config);
7834 fdi_dotclock = adjusted_mode->crtc_clock;
7836 lane = ilk_get_lanes_required(fdi_dotclock, link_bw,
7837 pipe_config->pipe_bpp);
7839 pipe_config->fdi_lanes = lane;
7841 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
7842 link_bw, &pipe_config->fdi_m_n, false, false);
7844 ret = ilk_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
7845 if (ret == -EDEADLK)
7848 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
7849 pipe_config->pipe_bpp -= 2*3;
7850 drm_dbg_kms(&i915->drm,
7851 "fdi link bw constraint, reducing pipe bpp to %i\n",
7852 pipe_config->pipe_bpp);
7853 needs_recompute = true;
7854 pipe_config->bw_constrained = true;
7859 if (needs_recompute)
7865 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
7867 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7868 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7870 /* IPS only exists on ULT machines and is tied to pipe A. */
7871 if (!hsw_crtc_supports_ips(crtc))
7874 if (!i915_modparams.enable_ips)
7877 if (crtc_state->pipe_bpp > 24)
7881 * We compare against max which means we must take
7882 * the increased cdclk requirement into account when
7883 * calculating the new cdclk.
7885 * Should measure whether using a lower cdclk w/o IPS
7887 if (IS_BROADWELL(dev_priv) &&
7888 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
7894 static int hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
7896 struct drm_i915_private *dev_priv =
7897 to_i915(crtc_state->uapi.crtc->dev);
7898 struct intel_atomic_state *state =
7899 to_intel_atomic_state(crtc_state->uapi.state);
7901 crtc_state->ips_enabled = false;
7903 if (!hsw_crtc_state_ips_capable(crtc_state))
7907 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
7908 * enabled and disabled dynamically based on package C states,
7909 * user space can't make reliable use of the CRCs, so let's just
7910 * completely disable it.
7912 if (crtc_state->crc_enabled)
7915 /* IPS should be fine as long as at least one plane is enabled. */
7916 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
7919 if (IS_BROADWELL(dev_priv)) {
7920 const struct intel_cdclk_state *cdclk_state;
7922 cdclk_state = intel_atomic_get_cdclk_state(state);
7923 if (IS_ERR(cdclk_state))
7924 return PTR_ERR(cdclk_state);
7926 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
7927 if (crtc_state->pixel_rate > cdclk_state->logical.cdclk * 95 / 100)
7931 crtc_state->ips_enabled = true;
7936 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
7938 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7940 /* GDG double wide on either pipe, otherwise pipe A only */
7941 return INTEL_GEN(dev_priv) < 4 &&
7942 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
7945 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
7949 pixel_rate = pipe_config->hw.adjusted_mode.crtc_clock;
7952 * We only use IF-ID interlacing. If we ever use
7953 * PF-ID we'll need to adjust the pixel_rate here.
7956 if (pipe_config->pch_pfit.enabled) {
7957 u64 pipe_w, pipe_h, pfit_w, pfit_h;
7958 u32 pfit_size = pipe_config->pch_pfit.size;
7960 pipe_w = pipe_config->pipe_src_w;
7961 pipe_h = pipe_config->pipe_src_h;
7963 pfit_w = (pfit_size >> 16) & 0xFFFF;
7964 pfit_h = pfit_size & 0xFFFF;
7965 if (pipe_w < pfit_w)
7967 if (pipe_h < pfit_h)
7970 if (WARN_ON(!pfit_w || !pfit_h))
7973 pixel_rate = div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
7980 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
7982 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
7984 if (HAS_GMCH(dev_priv))
7985 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
7986 crtc_state->pixel_rate =
7987 crtc_state->hw.adjusted_mode.crtc_clock;
7989 crtc_state->pixel_rate =
7990 ilk_pipe_pixel_rate(crtc_state);
7993 static int intel_crtc_compute_config(struct intel_crtc *crtc,
7994 struct intel_crtc_state *pipe_config)
7996 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7997 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
7998 int clock_limit = dev_priv->max_dotclk_freq;
8000 if (INTEL_GEN(dev_priv) < 4) {
8001 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
8004 * Enable double wide mode when the dot clock
8005 * is > 90% of the (display) core speed.
8007 if (intel_crtc_supports_double_wide(crtc) &&
8008 adjusted_mode->crtc_clock > clock_limit) {
8009 clock_limit = dev_priv->max_dotclk_freq;
8010 pipe_config->double_wide = true;
8014 if (adjusted_mode->crtc_clock > clock_limit) {
8015 drm_dbg_kms(&dev_priv->drm,
8016 "requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
8017 adjusted_mode->crtc_clock, clock_limit,
8018 yesno(pipe_config->double_wide));
8022 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8023 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
8024 pipe_config->hw.ctm) {
8026 * There is only one pipe CSC unit per pipe, and we need that
8027 * for output conversion from RGB->YCBCR. So if CTM is already
8028 * applied we can't support YCBCR420 output.
8030 drm_dbg_kms(&dev_priv->drm,
8031 "YCBCR420 and CTM together are not possible\n");
8036 * Pipe horizontal size must be even in:
8038 * - LVDS dual channel mode
8039 * - Double wide pipe
8041 if (pipe_config->pipe_src_w & 1) {
8042 if (pipe_config->double_wide) {
8043 drm_dbg_kms(&dev_priv->drm,
8044 "Odd pipe source width not supported with double wide pipe\n");
8048 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
8049 intel_is_dual_link_lvds(dev_priv)) {
8050 drm_dbg_kms(&dev_priv->drm,
8051 "Odd pipe source width not supported with dual link LVDS\n");
8056 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
8057 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
8059 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
8060 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
8063 intel_crtc_compute_pixel_rate(pipe_config);
8065 if (pipe_config->has_pch_encoder)
8066 return ilk_fdi_compute_config(crtc, pipe_config);
8072 intel_reduce_m_n_ratio(u32 *num, u32 *den)
8074 while (*num > DATA_LINK_M_N_MASK ||
8075 *den > DATA_LINK_M_N_MASK) {
8081 static void compute_m_n(unsigned int m, unsigned int n,
8082 u32 *ret_m, u32 *ret_n,
8086 * Several DP dongles in particular seem to be fussy about
8087 * too large link M/N values. Give N value as 0x8000 that
8088 * should be acceptable by specific devices. 0x8000 is the
8089 * specified fixed N value for asynchronous clock mode,
8090 * which the devices expect also in synchronous clock mode.
8095 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
8097 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
8098 intel_reduce_m_n_ratio(ret_m, ret_n);
8102 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
8103 int pixel_clock, int link_clock,
8104 struct intel_link_m_n *m_n,
8105 bool constant_n, bool fec_enable)
8107 u32 data_clock = bits_per_pixel * pixel_clock;
8110 data_clock = intel_dp_mode_to_fec_clock(data_clock);
8113 compute_m_n(data_clock,
8114 link_clock * nlanes * 8,
8115 &m_n->gmch_m, &m_n->gmch_n,
8118 compute_m_n(pixel_clock, link_clock,
8119 &m_n->link_m, &m_n->link_n,
8123 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
8126 * There may be no VBT; and if the BIOS enabled SSC we can
8127 * just keep using it to avoid unnecessary flicker. Whereas if the
8128 * BIOS isn't using it, don't assume it will work even if the VBT
8129 * indicates as much.
8131 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
8132 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
8136 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
8137 drm_dbg_kms(&dev_priv->drm,
8138 "SSC %s by BIOS, overriding VBT which says %s\n",
8139 enableddisabled(bios_lvds_use_ssc),
8140 enableddisabled(dev_priv->vbt.lvds_use_ssc));
8141 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
8146 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
8148 if (i915_modparams.panel_use_ssc >= 0)
8149 return i915_modparams.panel_use_ssc != 0;
8150 return dev_priv->vbt.lvds_use_ssc
8151 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
8154 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
8156 return (1 << dpll->n) << 16 | dpll->m2;
8159 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
8161 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
8164 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
8165 struct intel_crtc_state *crtc_state,
8166 struct dpll *reduced_clock)
8168 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8171 if (IS_PINEVIEW(dev_priv)) {
8172 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
8174 fp2 = pnv_dpll_compute_fp(reduced_clock);
8176 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8178 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8181 crtc_state->dpll_hw_state.fp0 = fp;
8183 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8185 crtc_state->dpll_hw_state.fp1 = fp2;
8187 crtc_state->dpll_hw_state.fp1 = fp;
8191 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
8197 * PLLB opamp always calibrates to max value of 0x3f, force enable it
8198 * and set it to a reasonable value instead.
8200 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
8201 reg_val &= 0xffffff00;
8202 reg_val |= 0x00000030;
8203 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
8205 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
8206 reg_val &= 0x00ffffff;
8207 reg_val |= 0x8c000000;
8208 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
8210 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
8211 reg_val &= 0xffffff00;
8212 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
8214 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
8215 reg_val &= 0x00ffffff;
8216 reg_val |= 0xb0000000;
8217 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
8220 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
8221 const struct intel_link_m_n *m_n)
8223 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8224 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8225 enum pipe pipe = crtc->pipe;
8227 intel_de_write(dev_priv, PCH_TRANS_DATA_M1(pipe),
8228 TU_SIZE(m_n->tu) | m_n->gmch_m);
8229 intel_de_write(dev_priv, PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
8230 intel_de_write(dev_priv, PCH_TRANS_LINK_M1(pipe), m_n->link_m);
8231 intel_de_write(dev_priv, PCH_TRANS_LINK_N1(pipe), m_n->link_n);
8234 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
8235 enum transcoder transcoder)
8237 if (IS_HASWELL(dev_priv))
8238 return transcoder == TRANSCODER_EDP;
8241 * Strictly speaking some registers are available before
8242 * gen7, but we only support DRRS on gen7+
8244 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
8247 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
8248 const struct intel_link_m_n *m_n,
8249 const struct intel_link_m_n *m2_n2)
8251 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8252 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8253 enum pipe pipe = crtc->pipe;
8254 enum transcoder transcoder = crtc_state->cpu_transcoder;
8256 if (INTEL_GEN(dev_priv) >= 5) {
8257 intel_de_write(dev_priv, PIPE_DATA_M1(transcoder),
8258 TU_SIZE(m_n->tu) | m_n->gmch_m);
8259 intel_de_write(dev_priv, PIPE_DATA_N1(transcoder),
8261 intel_de_write(dev_priv, PIPE_LINK_M1(transcoder),
8263 intel_de_write(dev_priv, PIPE_LINK_N1(transcoder),
8266 * M2_N2 registers are set only if DRRS is supported
8267 * (to make sure the registers are not unnecessarily accessed).
8269 if (m2_n2 && crtc_state->has_drrs &&
8270 transcoder_has_m2_n2(dev_priv, transcoder)) {
8271 intel_de_write(dev_priv, PIPE_DATA_M2(transcoder),
8272 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
8273 intel_de_write(dev_priv, PIPE_DATA_N2(transcoder),
8275 intel_de_write(dev_priv, PIPE_LINK_M2(transcoder),
8277 intel_de_write(dev_priv, PIPE_LINK_N2(transcoder),
8281 intel_de_write(dev_priv, PIPE_DATA_M_G4X(pipe),
8282 TU_SIZE(m_n->tu) | m_n->gmch_m);
8283 intel_de_write(dev_priv, PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
8284 intel_de_write(dev_priv, PIPE_LINK_M_G4X(pipe), m_n->link_m);
8285 intel_de_write(dev_priv, PIPE_LINK_N_G4X(pipe), m_n->link_n);
8289 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
8291 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
8292 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
8295 dp_m_n = &crtc_state->dp_m_n;
8296 dp_m2_n2 = &crtc_state->dp_m2_n2;
8297 } else if (m_n == M2_N2) {
8300 * M2_N2 registers are not supported. Hence m2_n2 divider value
8301 * needs to be programmed into M1_N1.
8303 dp_m_n = &crtc_state->dp_m2_n2;
8305 drm_err(&i915->drm, "Unsupported divider value\n");
8309 if (crtc_state->has_pch_encoder)
8310 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
8312 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
8315 static void vlv_compute_dpll(struct intel_crtc *crtc,
8316 struct intel_crtc_state *pipe_config)
8318 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
8319 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8320 if (crtc->pipe != PIPE_A)
8321 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8323 /* DPLL not used with DSI, but still need the rest set up */
8324 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8325 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
8326 DPLL_EXT_BUFFER_ENABLE_VLV;
8328 pipe_config->dpll_hw_state.dpll_md =
8329 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8332 static void chv_compute_dpll(struct intel_crtc *crtc,
8333 struct intel_crtc_state *pipe_config)
8335 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
8336 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
8337 if (crtc->pipe != PIPE_A)
8338 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
8340 /* DPLL not used with DSI, but still need the rest set up */
8341 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
8342 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
8344 pipe_config->dpll_hw_state.dpll_md =
8345 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8348 static void vlv_prepare_pll(struct intel_crtc *crtc,
8349 const struct intel_crtc_state *pipe_config)
8351 struct drm_device *dev = crtc->base.dev;
8352 struct drm_i915_private *dev_priv = to_i915(dev);
8353 enum pipe pipe = crtc->pipe;
8355 u32 bestn, bestm1, bestm2, bestp1, bestp2;
8356 u32 coreclk, reg_val;
8359 intel_de_write(dev_priv, DPLL(pipe),
8360 pipe_config->dpll_hw_state.dpll & ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
8362 /* No need to actually set up the DPLL with DSI */
8363 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8366 vlv_dpio_get(dev_priv);
8368 bestn = pipe_config->dpll.n;
8369 bestm1 = pipe_config->dpll.m1;
8370 bestm2 = pipe_config->dpll.m2;
8371 bestp1 = pipe_config->dpll.p1;
8372 bestp2 = pipe_config->dpll.p2;
8374 /* See eDP HDMI DPIO driver vbios notes doc */
8376 /* PLL B needs special handling */
8378 vlv_pllb_recal_opamp(dev_priv, pipe);
8380 /* Set up Tx target for periodic Rcomp update */
8381 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
8383 /* Disable target IRef on PLL */
8384 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
8385 reg_val &= 0x00ffffff;
8386 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
8388 /* Disable fast lock */
8389 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
8391 /* Set idtafcrecal before PLL is enabled */
8392 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
8393 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
8394 mdiv |= ((bestn << DPIO_N_SHIFT));
8395 mdiv |= (1 << DPIO_K_SHIFT);
8398 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
8399 * but we don't support that).
8400 * Note: don't use the DAC post divider as it seems unstable.
8402 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
8403 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8405 mdiv |= DPIO_ENABLE_CALIBRATION;
8406 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
8408 /* Set HBR and RBR LPF coefficients */
8409 if (pipe_config->port_clock == 162000 ||
8410 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
8411 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
8412 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8415 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
8418 if (intel_crtc_has_dp_encoder(pipe_config)) {
8419 /* Use SSC source */
8421 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8424 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8426 } else { /* HDMI or VGA */
8427 /* Use bend source */
8429 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8432 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
8436 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
8437 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
8438 if (intel_crtc_has_dp_encoder(pipe_config))
8439 coreclk |= 0x01000000;
8440 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
8442 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
8444 vlv_dpio_put(dev_priv);
8447 static void chv_prepare_pll(struct intel_crtc *crtc,
8448 const struct intel_crtc_state *pipe_config)
8450 struct drm_device *dev = crtc->base.dev;
8451 struct drm_i915_private *dev_priv = to_i915(dev);
8452 enum pipe pipe = crtc->pipe;
8453 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8454 u32 loopfilter, tribuf_calcntr;
8455 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
8459 /* Enable Refclk and SSC */
8460 intel_de_write(dev_priv, DPLL(pipe),
8461 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
8463 /* No need to actually set up the DPLL with DSI */
8464 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8467 bestn = pipe_config->dpll.n;
8468 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
8469 bestm1 = pipe_config->dpll.m1;
8470 bestm2 = pipe_config->dpll.m2 >> 22;
8471 bestp1 = pipe_config->dpll.p1;
8472 bestp2 = pipe_config->dpll.p2;
8473 vco = pipe_config->dpll.vco;
8477 vlv_dpio_get(dev_priv);
8479 /* p1 and p2 divider */
8480 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
8481 5 << DPIO_CHV_S1_DIV_SHIFT |
8482 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
8483 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
8484 1 << DPIO_CHV_K_DIV_SHIFT);
8486 /* Feedback post-divider - m2 */
8487 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
8489 /* Feedback refclk divider - n and m1 */
8490 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
8491 DPIO_CHV_M1_DIV_BY_2 |
8492 1 << DPIO_CHV_N_DIV_SHIFT);
8494 /* M2 fraction division */
8495 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
8497 /* M2 fraction division enable */
8498 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8499 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
8500 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
8502 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
8503 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
8505 /* Program digital lock detect threshold */
8506 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
8507 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
8508 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
8509 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
8511 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
8512 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
8515 if (vco == 5400000) {
8516 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
8517 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
8518 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
8519 tribuf_calcntr = 0x9;
8520 } else if (vco <= 6200000) {
8521 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
8522 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
8523 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8524 tribuf_calcntr = 0x9;
8525 } else if (vco <= 6480000) {
8526 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8527 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8528 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8529 tribuf_calcntr = 0x8;
8531 /* Not supported. Apply the same limits as in the max case */
8532 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
8533 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
8534 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
8537 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
8539 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
8540 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
8541 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
8542 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
8545 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
8546 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
8549 vlv_dpio_put(dev_priv);
8553 * vlv_force_pll_on - forcibly enable just the PLL
8554 * @dev_priv: i915 private structure
8555 * @pipe: pipe PLL to enable
8556 * @dpll: PLL configuration
8558 * Enable the PLL for @pipe using the supplied @dpll config. To be used
8559 * in cases where we need the PLL enabled even when @pipe is not going to
8562 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
8563 const struct dpll *dpll)
8565 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
8566 struct intel_crtc_state *pipe_config;
8568 pipe_config = intel_crtc_state_alloc(crtc);
8572 pipe_config->cpu_transcoder = (enum transcoder)pipe;
8573 pipe_config->pixel_multiplier = 1;
8574 pipe_config->dpll = *dpll;
8576 if (IS_CHERRYVIEW(dev_priv)) {
8577 chv_compute_dpll(crtc, pipe_config);
8578 chv_prepare_pll(crtc, pipe_config);
8579 chv_enable_pll(crtc, pipe_config);
8581 vlv_compute_dpll(crtc, pipe_config);
8582 vlv_prepare_pll(crtc, pipe_config);
8583 vlv_enable_pll(crtc, pipe_config);
8592 * vlv_force_pll_off - forcibly disable just the PLL
8593 * @dev_priv: i915 private structure
8594 * @pipe: pipe PLL to disable
8596 * Disable the PLL for @pipe. To be used in cases where we need
8597 * the PLL enabled even when @pipe is not going to be enabled.
8599 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
8601 if (IS_CHERRYVIEW(dev_priv))
8602 chv_disable_pll(dev_priv, pipe);
8604 vlv_disable_pll(dev_priv, pipe);
8607 static void i9xx_compute_dpll(struct intel_crtc *crtc,
8608 struct intel_crtc_state *crtc_state,
8609 struct dpll *reduced_clock)
8611 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8613 struct dpll *clock = &crtc_state->dpll;
8615 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8617 dpll = DPLL_VGA_MODE_DIS;
8619 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8620 dpll |= DPLLB_MODE_LVDS;
8622 dpll |= DPLLB_MODE_DAC_SERIAL;
8624 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8625 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8626 dpll |= (crtc_state->pixel_multiplier - 1)
8627 << SDVO_MULTIPLIER_SHIFT_HIRES;
8630 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8631 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8632 dpll |= DPLL_SDVO_HIGH_SPEED;
8634 if (intel_crtc_has_dp_encoder(crtc_state))
8635 dpll |= DPLL_SDVO_HIGH_SPEED;
8637 /* compute bitmask from p1 value */
8638 if (IS_PINEVIEW(dev_priv))
8639 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
8641 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8642 if (IS_G4X(dev_priv) && reduced_clock)
8643 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8645 switch (clock->p2) {
8647 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8650 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8653 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8656 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8659 if (INTEL_GEN(dev_priv) >= 4)
8660 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
8662 if (crtc_state->sdvo_tv_clock)
8663 dpll |= PLL_REF_INPUT_TVCLKINBC;
8664 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8665 intel_panel_use_ssc(dev_priv))
8666 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8668 dpll |= PLL_REF_INPUT_DREFCLK;
8670 dpll |= DPLL_VCO_ENABLE;
8671 crtc_state->dpll_hw_state.dpll = dpll;
8673 if (INTEL_GEN(dev_priv) >= 4) {
8674 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
8675 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
8676 crtc_state->dpll_hw_state.dpll_md = dpll_md;
8680 static void i8xx_compute_dpll(struct intel_crtc *crtc,
8681 struct intel_crtc_state *crtc_state,
8682 struct dpll *reduced_clock)
8684 struct drm_device *dev = crtc->base.dev;
8685 struct drm_i915_private *dev_priv = to_i915(dev);
8687 struct dpll *clock = &crtc_state->dpll;
8689 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
8691 dpll = DPLL_VGA_MODE_DIS;
8693 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8694 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8697 dpll |= PLL_P1_DIVIDE_BY_TWO;
8699 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8701 dpll |= PLL_P2_DIVIDE_BY_4;
8706 * "[Almador Errata}: For the correct operation of the muxed DVO pins
8707 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
8708 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
8709 * Enable) must be set to “1” in both the DPLL A Control Register
8710 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
8712 * For simplicity We simply keep both bits always enabled in
8713 * both DPLLS. The spec says we should disable the DVO 2X clock
8714 * when not needed, but this seems to work fine in practice.
8716 if (IS_I830(dev_priv) ||
8717 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
8718 dpll |= DPLL_DVO_2X_MODE;
8720 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8721 intel_panel_use_ssc(dev_priv))
8722 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8724 dpll |= PLL_REF_INPUT_DREFCLK;
8726 dpll |= DPLL_VCO_ENABLE;
8727 crtc_state->dpll_hw_state.dpll = dpll;
8730 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
8732 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8733 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8734 enum pipe pipe = crtc->pipe;
8735 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8736 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
8737 u32 crtc_vtotal, crtc_vblank_end;
8740 /* We need to be careful not to changed the adjusted mode, for otherwise
8741 * the hw state checker will get angry at the mismatch. */
8742 crtc_vtotal = adjusted_mode->crtc_vtotal;
8743 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
8745 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
8746 /* the chip adds 2 halflines automatically */
8748 crtc_vblank_end -= 1;
8750 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8751 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
8753 vsyncshift = adjusted_mode->crtc_hsync_start -
8754 adjusted_mode->crtc_htotal / 2;
8756 vsyncshift += adjusted_mode->crtc_htotal;
8759 if (INTEL_GEN(dev_priv) > 3)
8760 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder),
8763 intel_de_write(dev_priv, HTOTAL(cpu_transcoder),
8764 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
8765 intel_de_write(dev_priv, HBLANK(cpu_transcoder),
8766 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
8767 intel_de_write(dev_priv, HSYNC(cpu_transcoder),
8768 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
8770 intel_de_write(dev_priv, VTOTAL(cpu_transcoder),
8771 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16));
8772 intel_de_write(dev_priv, VBLANK(cpu_transcoder),
8773 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16));
8774 intel_de_write(dev_priv, VSYNC(cpu_transcoder),
8775 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
8777 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
8778 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
8779 * documented on the DDI_FUNC_CTL register description, EDP Input Select
8781 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
8782 (pipe == PIPE_B || pipe == PIPE_C))
8783 intel_de_write(dev_priv, VTOTAL(pipe),
8784 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
8788 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
8790 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8791 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8792 enum pipe pipe = crtc->pipe;
8794 /* pipesrc controls the size that is scaled from, which should
8795 * always be the user's requested size.
8797 intel_de_write(dev_priv, PIPESRC(pipe),
8798 ((crtc_state->pipe_src_w - 1) << 16) | (crtc_state->pipe_src_h - 1));
8801 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
8803 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
8804 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8806 if (IS_GEN(dev_priv, 2))
8809 if (INTEL_GEN(dev_priv) >= 9 ||
8810 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
8811 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
8813 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
8816 static void intel_get_pipe_timings(struct intel_crtc *crtc,
8817 struct intel_crtc_state *pipe_config)
8819 struct drm_device *dev = crtc->base.dev;
8820 struct drm_i915_private *dev_priv = to_i915(dev);
8821 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8824 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder));
8825 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
8826 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
8828 if (!transcoder_is_dsi(cpu_transcoder)) {
8829 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder));
8830 pipe_config->hw.adjusted_mode.crtc_hblank_start =
8832 pipe_config->hw.adjusted_mode.crtc_hblank_end =
8833 ((tmp >> 16) & 0xffff) + 1;
8835 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder));
8836 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
8837 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
8839 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder));
8840 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
8841 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
8843 if (!transcoder_is_dsi(cpu_transcoder)) {
8844 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder));
8845 pipe_config->hw.adjusted_mode.crtc_vblank_start =
8847 pipe_config->hw.adjusted_mode.crtc_vblank_end =
8848 ((tmp >> 16) & 0xffff) + 1;
8850 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder));
8851 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
8852 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
8854 if (intel_pipe_is_interlaced(pipe_config)) {
8855 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
8856 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
8857 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
8861 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
8862 struct intel_crtc_state *pipe_config)
8864 struct drm_device *dev = crtc->base.dev;
8865 struct drm_i915_private *dev_priv = to_i915(dev);
8868 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
8869 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
8870 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
8872 pipe_config->hw.mode.vdisplay = pipe_config->pipe_src_h;
8873 pipe_config->hw.mode.hdisplay = pipe_config->pipe_src_w;
8876 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
8877 struct intel_crtc_state *pipe_config)
8879 mode->hdisplay = pipe_config->hw.adjusted_mode.crtc_hdisplay;
8880 mode->htotal = pipe_config->hw.adjusted_mode.crtc_htotal;
8881 mode->hsync_start = pipe_config->hw.adjusted_mode.crtc_hsync_start;
8882 mode->hsync_end = pipe_config->hw.adjusted_mode.crtc_hsync_end;
8884 mode->vdisplay = pipe_config->hw.adjusted_mode.crtc_vdisplay;
8885 mode->vtotal = pipe_config->hw.adjusted_mode.crtc_vtotal;
8886 mode->vsync_start = pipe_config->hw.adjusted_mode.crtc_vsync_start;
8887 mode->vsync_end = pipe_config->hw.adjusted_mode.crtc_vsync_end;
8889 mode->flags = pipe_config->hw.adjusted_mode.flags;
8890 mode->type = DRM_MODE_TYPE_DRIVER;
8892 mode->clock = pipe_config->hw.adjusted_mode.crtc_clock;
8894 mode->hsync = drm_mode_hsync(mode);
8895 mode->vrefresh = drm_mode_vrefresh(mode);
8896 drm_mode_set_name(mode);
8899 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
8901 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8902 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8907 /* we keep both pipes enabled on 830 */
8908 if (IS_I830(dev_priv))
8909 pipeconf |= intel_de_read(dev_priv, PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
8911 if (crtc_state->double_wide)
8912 pipeconf |= PIPECONF_DOUBLE_WIDE;
8914 /* only g4x and later have fancy bpc/dither controls */
8915 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8916 IS_CHERRYVIEW(dev_priv)) {
8917 /* Bspec claims that we can't use dithering for 30bpp pipes. */
8918 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
8919 pipeconf |= PIPECONF_DITHER_EN |
8920 PIPECONF_DITHER_TYPE_SP;
8922 switch (crtc_state->pipe_bpp) {
8924 pipeconf |= PIPECONF_6BPC;
8927 pipeconf |= PIPECONF_8BPC;
8930 pipeconf |= PIPECONF_10BPC;
8933 /* Case prevented by intel_choose_pipe_bpp_dither. */
8938 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
8939 if (INTEL_GEN(dev_priv) < 4 ||
8940 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8941 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
8943 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
8945 pipeconf |= PIPECONF_PROGRESSIVE;
8948 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8949 crtc_state->limited_color_range)
8950 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
8952 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8954 pipeconf |= PIPECONF_FRAME_START_DELAY(0);
8956 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf);
8957 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe));
8960 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
8961 struct intel_crtc_state *crtc_state)
8963 struct drm_device *dev = crtc->base.dev;
8964 struct drm_i915_private *dev_priv = to_i915(dev);
8965 const struct intel_limit *limit;
8968 memset(&crtc_state->dpll_hw_state, 0,
8969 sizeof(crtc_state->dpll_hw_state));
8971 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8972 if (intel_panel_use_ssc(dev_priv)) {
8973 refclk = dev_priv->vbt.lvds_ssc_freq;
8974 drm_dbg_kms(&dev_priv->drm,
8975 "using SSC reference clock of %d kHz\n",
8979 limit = &intel_limits_i8xx_lvds;
8980 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
8981 limit = &intel_limits_i8xx_dvo;
8983 limit = &intel_limits_i8xx_dac;
8986 if (!crtc_state->clock_set &&
8987 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8988 refclk, NULL, &crtc_state->dpll)) {
8989 drm_err(&dev_priv->drm,
8990 "Couldn't find PLL settings for mode!\n");
8994 i8xx_compute_dpll(crtc, crtc_state, NULL);
8999 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
9000 struct intel_crtc_state *crtc_state)
9002 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9003 const struct intel_limit *limit;
9006 memset(&crtc_state->dpll_hw_state, 0,
9007 sizeof(crtc_state->dpll_hw_state));
9009 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9010 if (intel_panel_use_ssc(dev_priv)) {
9011 refclk = dev_priv->vbt.lvds_ssc_freq;
9012 drm_dbg_kms(&dev_priv->drm,
9013 "using SSC reference clock of %d kHz\n",
9017 if (intel_is_dual_link_lvds(dev_priv))
9018 limit = &intel_limits_g4x_dual_channel_lvds;
9020 limit = &intel_limits_g4x_single_channel_lvds;
9021 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
9022 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
9023 limit = &intel_limits_g4x_hdmi;
9024 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
9025 limit = &intel_limits_g4x_sdvo;
9027 /* The option is for other outputs */
9028 limit = &intel_limits_i9xx_sdvo;
9031 if (!crtc_state->clock_set &&
9032 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9033 refclk, NULL, &crtc_state->dpll)) {
9034 drm_err(&dev_priv->drm,
9035 "Couldn't find PLL settings for mode!\n");
9039 i9xx_compute_dpll(crtc, crtc_state, NULL);
9044 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
9045 struct intel_crtc_state *crtc_state)
9047 struct drm_device *dev = crtc->base.dev;
9048 struct drm_i915_private *dev_priv = to_i915(dev);
9049 const struct intel_limit *limit;
9052 memset(&crtc_state->dpll_hw_state, 0,
9053 sizeof(crtc_state->dpll_hw_state));
9055 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9056 if (intel_panel_use_ssc(dev_priv)) {
9057 refclk = dev_priv->vbt.lvds_ssc_freq;
9058 drm_dbg_kms(&dev_priv->drm,
9059 "using SSC reference clock of %d kHz\n",
9063 limit = &pnv_limits_lvds;
9065 limit = &pnv_limits_sdvo;
9068 if (!crtc_state->clock_set &&
9069 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9070 refclk, NULL, &crtc_state->dpll)) {
9071 drm_err(&dev_priv->drm,
9072 "Couldn't find PLL settings for mode!\n");
9076 i9xx_compute_dpll(crtc, crtc_state, NULL);
9081 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
9082 struct intel_crtc_state *crtc_state)
9084 struct drm_device *dev = crtc->base.dev;
9085 struct drm_i915_private *dev_priv = to_i915(dev);
9086 const struct intel_limit *limit;
9089 memset(&crtc_state->dpll_hw_state, 0,
9090 sizeof(crtc_state->dpll_hw_state));
9092 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
9093 if (intel_panel_use_ssc(dev_priv)) {
9094 refclk = dev_priv->vbt.lvds_ssc_freq;
9095 drm_dbg_kms(&dev_priv->drm,
9096 "using SSC reference clock of %d kHz\n",
9100 limit = &intel_limits_i9xx_lvds;
9102 limit = &intel_limits_i9xx_sdvo;
9105 if (!crtc_state->clock_set &&
9106 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9107 refclk, NULL, &crtc_state->dpll)) {
9108 drm_err(&dev_priv->drm,
9109 "Couldn't find PLL settings for mode!\n");
9113 i9xx_compute_dpll(crtc, crtc_state, NULL);
9118 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
9119 struct intel_crtc_state *crtc_state)
9121 int refclk = 100000;
9122 const struct intel_limit *limit = &intel_limits_chv;
9123 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
9125 memset(&crtc_state->dpll_hw_state, 0,
9126 sizeof(crtc_state->dpll_hw_state));
9128 if (!crtc_state->clock_set &&
9129 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9130 refclk, NULL, &crtc_state->dpll)) {
9131 drm_err(&i915->drm, "Couldn't find PLL settings for mode!\n");
9135 chv_compute_dpll(crtc, crtc_state);
9140 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
9141 struct intel_crtc_state *crtc_state)
9143 int refclk = 100000;
9144 const struct intel_limit *limit = &intel_limits_vlv;
9145 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
9147 memset(&crtc_state->dpll_hw_state, 0,
9148 sizeof(crtc_state->dpll_hw_state));
9150 if (!crtc_state->clock_set &&
9151 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
9152 refclk, NULL, &crtc_state->dpll)) {
9153 drm_err(&i915->drm, "Couldn't find PLL settings for mode!\n");
9157 vlv_compute_dpll(crtc, crtc_state);
9162 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
9164 if (IS_I830(dev_priv))
9167 return INTEL_GEN(dev_priv) >= 4 ||
9168 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
9171 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
9172 struct intel_crtc_state *pipe_config)
9174 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9177 if (!i9xx_has_pfit(dev_priv))
9180 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
9181 if (!(tmp & PFIT_ENABLE))
9184 /* Check whether the pfit is attached to our pipe. */
9185 if (INTEL_GEN(dev_priv) < 4) {
9186 if (crtc->pipe != PIPE_B)
9189 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
9193 pipe_config->gmch_pfit.control = tmp;
9194 pipe_config->gmch_pfit.pgm_ratios = intel_de_read(dev_priv,
9198 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
9199 struct intel_crtc_state *pipe_config)
9201 struct drm_device *dev = crtc->base.dev;
9202 struct drm_i915_private *dev_priv = to_i915(dev);
9203 enum pipe pipe = crtc->pipe;
9206 int refclk = 100000;
9208 /* In case of DSI, DPLL will not be used */
9209 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
9212 vlv_dpio_get(dev_priv);
9213 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
9214 vlv_dpio_put(dev_priv);
9216 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
9217 clock.m2 = mdiv & DPIO_M2DIV_MASK;
9218 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
9219 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
9220 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
9222 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
9226 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
9227 struct intel_initial_plane_config *plane_config)
9229 struct drm_device *dev = crtc->base.dev;
9230 struct drm_i915_private *dev_priv = to_i915(dev);
9231 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9232 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
9234 u32 val, base, offset;
9235 int fourcc, pixel_format;
9236 unsigned int aligned_height;
9237 struct drm_framebuffer *fb;
9238 struct intel_framebuffer *intel_fb;
9240 if (!plane->get_hw_state(plane, &pipe))
9243 drm_WARN_ON(dev, pipe != crtc->pipe);
9245 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9247 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
9251 fb = &intel_fb->base;
9255 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
9257 if (INTEL_GEN(dev_priv) >= 4) {
9258 if (val & DISPPLANE_TILED) {
9259 plane_config->tiling = I915_TILING_X;
9260 fb->modifier = I915_FORMAT_MOD_X_TILED;
9263 if (val & DISPPLANE_ROTATE_180)
9264 plane_config->rotation = DRM_MODE_ROTATE_180;
9267 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
9268 val & DISPPLANE_MIRROR)
9269 plane_config->rotation |= DRM_MODE_REFLECT_X;
9271 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
9272 fourcc = i9xx_format_to_fourcc(pixel_format);
9273 fb->format = drm_format_info(fourcc);
9275 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
9276 offset = intel_de_read(dev_priv, DSPOFFSET(i9xx_plane));
9277 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
9278 } else if (INTEL_GEN(dev_priv) >= 4) {
9279 if (plane_config->tiling)
9280 offset = intel_de_read(dev_priv,
9281 DSPTILEOFF(i9xx_plane));
9283 offset = intel_de_read(dev_priv,
9284 DSPLINOFF(i9xx_plane));
9285 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
9287 base = intel_de_read(dev_priv, DSPADDR(i9xx_plane));
9289 plane_config->base = base;
9291 val = intel_de_read(dev_priv, PIPESRC(pipe));
9292 fb->width = ((val >> 16) & 0xfff) + 1;
9293 fb->height = ((val >> 0) & 0xfff) + 1;
9295 val = intel_de_read(dev_priv, DSPSTRIDE(i9xx_plane));
9296 fb->pitches[0] = val & 0xffffffc0;
9298 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9300 plane_config->size = fb->pitches[0] * aligned_height;
9302 drm_dbg_kms(&dev_priv->drm,
9303 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9304 crtc->base.name, plane->base.name, fb->width, fb->height,
9305 fb->format->cpp[0] * 8, base, fb->pitches[0],
9306 plane_config->size);
9308 plane_config->fb = intel_fb;
9311 static void chv_crtc_clock_get(struct intel_crtc *crtc,
9312 struct intel_crtc_state *pipe_config)
9314 struct drm_device *dev = crtc->base.dev;
9315 struct drm_i915_private *dev_priv = to_i915(dev);
9316 enum pipe pipe = crtc->pipe;
9317 enum dpio_channel port = vlv_pipe_to_channel(pipe);
9319 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
9320 int refclk = 100000;
9322 /* In case of DSI, DPLL will not be used */
9323 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
9326 vlv_dpio_get(dev_priv);
9327 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
9328 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
9329 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
9330 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
9331 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
9332 vlv_dpio_put(dev_priv);
9334 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
9335 clock.m2 = (pll_dw0 & 0xff) << 22;
9336 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
9337 clock.m2 |= pll_dw2 & 0x3fffff;
9338 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
9339 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
9340 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
9342 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
9345 static enum intel_output_format
9346 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
9348 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9351 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
9353 if (tmp & PIPEMISC_YUV420_ENABLE) {
9354 /* We support 4:2:0 in full blend mode only */
9355 drm_WARN_ON(&dev_priv->drm,
9356 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
9358 return INTEL_OUTPUT_FORMAT_YCBCR420;
9359 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
9360 return INTEL_OUTPUT_FORMAT_YCBCR444;
9362 return INTEL_OUTPUT_FORMAT_RGB;
9366 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
9368 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9369 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9370 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9371 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
9374 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
9376 if (tmp & DISPPLANE_GAMMA_ENABLE)
9377 crtc_state->gamma_enable = true;
9379 if (!HAS_GMCH(dev_priv) &&
9380 tmp & DISPPLANE_PIPE_CSC_ENABLE)
9381 crtc_state->csc_enable = true;
9384 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
9385 struct intel_crtc_state *pipe_config)
9387 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9388 enum intel_display_power_domain power_domain;
9389 intel_wakeref_t wakeref;
9393 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9394 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9398 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9399 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9400 pipe_config->shared_dpll = NULL;
9401 pipe_config->master_transcoder = INVALID_TRANSCODER;
9405 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
9406 if (!(tmp & PIPECONF_ENABLE))
9409 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
9410 IS_CHERRYVIEW(dev_priv)) {
9411 switch (tmp & PIPECONF_BPC_MASK) {
9413 pipe_config->pipe_bpp = 18;
9416 pipe_config->pipe_bpp = 24;
9418 case PIPECONF_10BPC:
9419 pipe_config->pipe_bpp = 30;
9426 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
9427 (tmp & PIPECONF_COLOR_RANGE_SELECT))
9428 pipe_config->limited_color_range = true;
9430 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
9431 PIPECONF_GAMMA_MODE_SHIFT;
9433 if (IS_CHERRYVIEW(dev_priv))
9434 pipe_config->cgm_mode = intel_de_read(dev_priv,
9435 CGM_PIPE_MODE(crtc->pipe));
9437 i9xx_get_pipe_color_config(pipe_config);
9438 intel_color_get_config(pipe_config);
9440 if (INTEL_GEN(dev_priv) < 4)
9441 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
9443 intel_get_pipe_timings(crtc, pipe_config);
9444 intel_get_pipe_src_size(crtc, pipe_config);
9446 i9xx_get_pfit_config(crtc, pipe_config);
9448 if (INTEL_GEN(dev_priv) >= 4) {
9449 /* No way to read it out on pipes B and C */
9450 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
9451 tmp = dev_priv->chv_dpll_md[crtc->pipe];
9453 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
9454 pipe_config->pixel_multiplier =
9455 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
9456 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
9457 pipe_config->dpll_hw_state.dpll_md = tmp;
9458 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
9459 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
9460 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
9461 pipe_config->pixel_multiplier =
9462 ((tmp & SDVO_MULTIPLIER_MASK)
9463 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
9465 /* Note that on i915G/GM the pixel multiplier is in the sdvo
9466 * port and will be fixed up in the encoder->get_config
9468 pipe_config->pixel_multiplier = 1;
9470 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
9472 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
9473 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
9475 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
9478 /* Mask out read-only status bits. */
9479 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
9480 DPLL_PORTC_READY_MASK |
9481 DPLL_PORTB_READY_MASK);
9484 if (IS_CHERRYVIEW(dev_priv))
9485 chv_crtc_clock_get(crtc, pipe_config);
9486 else if (IS_VALLEYVIEW(dev_priv))
9487 vlv_crtc_clock_get(crtc, pipe_config);
9489 i9xx_crtc_clock_get(crtc, pipe_config);
9492 * Normally the dotclock is filled in by the encoder .get_config()
9493 * but in case the pipe is enabled w/o any ports we need a sane
9496 pipe_config->hw.adjusted_mode.crtc_clock =
9497 pipe_config->port_clock / pipe_config->pixel_multiplier;
9502 intel_display_power_put(dev_priv, power_domain, wakeref);
9507 static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv)
9509 struct intel_encoder *encoder;
9512 bool has_lvds = false;
9513 bool has_cpu_edp = false;
9514 bool has_panel = false;
9515 bool has_ck505 = false;
9516 bool can_ssc = false;
9517 bool using_ssc_source = false;
9519 /* We need to take the global config into account */
9520 for_each_intel_encoder(&dev_priv->drm, encoder) {
9521 switch (encoder->type) {
9522 case INTEL_OUTPUT_LVDS:
9526 case INTEL_OUTPUT_EDP:
9528 if (encoder->port == PORT_A)
9536 if (HAS_PCH_IBX(dev_priv)) {
9537 has_ck505 = dev_priv->vbt.display_clock_mode;
9538 can_ssc = has_ck505;
9544 /* Check if any DPLLs are using the SSC source */
9545 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++) {
9546 u32 temp = intel_de_read(dev_priv, PCH_DPLL(i));
9548 if (!(temp & DPLL_VCO_ENABLE))
9551 if ((temp & PLL_REF_INPUT_MASK) ==
9552 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
9553 using_ssc_source = true;
9558 drm_dbg_kms(&dev_priv->drm,
9559 "has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
9560 has_panel, has_lvds, has_ck505, using_ssc_source);
9562 /* Ironlake: try to setup display ref clock before DPLL
9563 * enabling. This is only under driver's control after
9564 * PCH B stepping, previous chipset stepping should be
9565 * ignoring this setting.
9567 val = intel_de_read(dev_priv, PCH_DREF_CONTROL);
9569 /* As we must carefully and slowly disable/enable each source in turn,
9570 * compute the final state we want first and check if we need to
9571 * make any changes at all.
9574 final &= ~DREF_NONSPREAD_SOURCE_MASK;
9576 final |= DREF_NONSPREAD_CK505_ENABLE;
9578 final |= DREF_NONSPREAD_SOURCE_ENABLE;
9580 final &= ~DREF_SSC_SOURCE_MASK;
9581 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9582 final &= ~DREF_SSC1_ENABLE;
9585 final |= DREF_SSC_SOURCE_ENABLE;
9587 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9588 final |= DREF_SSC1_ENABLE;
9591 if (intel_panel_use_ssc(dev_priv) && can_ssc)
9592 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9594 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9596 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9597 } else if (using_ssc_source) {
9598 final |= DREF_SSC_SOURCE_ENABLE;
9599 final |= DREF_SSC1_ENABLE;
9605 /* Always enable nonspread source */
9606 val &= ~DREF_NONSPREAD_SOURCE_MASK;
9609 val |= DREF_NONSPREAD_CK505_ENABLE;
9611 val |= DREF_NONSPREAD_SOURCE_ENABLE;
9614 val &= ~DREF_SSC_SOURCE_MASK;
9615 val |= DREF_SSC_SOURCE_ENABLE;
9617 /* SSC must be turned on before enabling the CPU output */
9618 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9619 drm_dbg_kms(&dev_priv->drm, "Using SSC on panel\n");
9620 val |= DREF_SSC1_ENABLE;
9622 val &= ~DREF_SSC1_ENABLE;
9624 /* Get SSC going before enabling the outputs */
9625 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9626 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9629 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9631 /* Enable CPU source on CPU attached eDP */
9633 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
9634 drm_dbg_kms(&dev_priv->drm,
9635 "Using SSC on eDP\n");
9636 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
9638 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
9640 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9642 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9643 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9646 drm_dbg_kms(&dev_priv->drm, "Disabling CPU source output\n");
9648 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
9650 /* Turn off CPU output */
9651 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
9653 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9654 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9657 if (!using_ssc_source) {
9658 drm_dbg_kms(&dev_priv->drm, "Disabling SSC source\n");
9660 /* Turn off the SSC source */
9661 val &= ~DREF_SSC_SOURCE_MASK;
9662 val |= DREF_SSC_SOURCE_DISABLE;
9665 val &= ~DREF_SSC1_ENABLE;
9667 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
9668 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
9673 BUG_ON(val != final);
9676 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
9680 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
9681 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
9682 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
9684 if (wait_for_us(intel_de_read(dev_priv, SOUTH_CHICKEN2) &
9685 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
9686 drm_err(&dev_priv->drm, "FDI mPHY reset assert timeout\n");
9688 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
9689 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
9690 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
9692 if (wait_for_us((intel_de_read(dev_priv, SOUTH_CHICKEN2) &
9693 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
9694 drm_err(&dev_priv->drm, "FDI mPHY reset de-assert timeout\n");
9697 /* WaMPhyProgramming:hsw */
9698 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
9702 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
9703 tmp &= ~(0xFF << 24);
9704 tmp |= (0x12 << 24);
9705 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
9707 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
9709 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
9711 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
9713 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
9715 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
9716 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9717 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
9719 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
9720 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
9721 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
9723 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
9726 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
9728 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
9731 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
9733 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
9736 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
9738 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
9741 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
9743 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
9744 tmp &= ~(0xFF << 16);
9745 tmp |= (0x1C << 16);
9746 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
9748 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
9749 tmp &= ~(0xFF << 16);
9750 tmp |= (0x1C << 16);
9751 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
9753 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
9755 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
9757 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
9759 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
9761 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
9762 tmp &= ~(0xF << 28);
9764 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
9766 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
9767 tmp &= ~(0xF << 28);
9769 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
9772 /* Implements 3 different sequences from BSpec chapter "Display iCLK
9773 * Programming" based on the parameters passed:
9774 * - Sequence to enable CLKOUT_DP
9775 * - Sequence to enable CLKOUT_DP without spread
9776 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
9778 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
9779 bool with_spread, bool with_fdi)
9783 if (drm_WARN(&dev_priv->drm, with_fdi && !with_spread,
9784 "FDI requires downspread\n"))
9786 if (drm_WARN(&dev_priv->drm, HAS_PCH_LPT_LP(dev_priv) &&
9787 with_fdi, "LP PCH doesn't have FDI\n"))
9790 mutex_lock(&dev_priv->sb_lock);
9792 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9793 tmp &= ~SBI_SSCCTL_DISABLE;
9794 tmp |= SBI_SSCCTL_PATHALT;
9795 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9800 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9801 tmp &= ~SBI_SSCCTL_PATHALT;
9802 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9805 lpt_reset_fdi_mphy(dev_priv);
9806 lpt_program_fdi_mphy(dev_priv);
9810 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9811 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9812 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9813 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9815 mutex_unlock(&dev_priv->sb_lock);
9818 /* Sequence to disable CLKOUT_DP */
9819 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
9823 mutex_lock(&dev_priv->sb_lock);
9825 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
9826 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
9827 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
9828 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
9830 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
9831 if (!(tmp & SBI_SSCCTL_DISABLE)) {
9832 if (!(tmp & SBI_SSCCTL_PATHALT)) {
9833 tmp |= SBI_SSCCTL_PATHALT;
9834 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9837 tmp |= SBI_SSCCTL_DISABLE;
9838 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
9841 mutex_unlock(&dev_priv->sb_lock);
9844 #define BEND_IDX(steps) ((50 + (steps)) / 5)
9846 static const u16 sscdivintphase[] = {
9847 [BEND_IDX( 50)] = 0x3B23,
9848 [BEND_IDX( 45)] = 0x3B23,
9849 [BEND_IDX( 40)] = 0x3C23,
9850 [BEND_IDX( 35)] = 0x3C23,
9851 [BEND_IDX( 30)] = 0x3D23,
9852 [BEND_IDX( 25)] = 0x3D23,
9853 [BEND_IDX( 20)] = 0x3E23,
9854 [BEND_IDX( 15)] = 0x3E23,
9855 [BEND_IDX( 10)] = 0x3F23,
9856 [BEND_IDX( 5)] = 0x3F23,
9857 [BEND_IDX( 0)] = 0x0025,
9858 [BEND_IDX( -5)] = 0x0025,
9859 [BEND_IDX(-10)] = 0x0125,
9860 [BEND_IDX(-15)] = 0x0125,
9861 [BEND_IDX(-20)] = 0x0225,
9862 [BEND_IDX(-25)] = 0x0225,
9863 [BEND_IDX(-30)] = 0x0325,
9864 [BEND_IDX(-35)] = 0x0325,
9865 [BEND_IDX(-40)] = 0x0425,
9866 [BEND_IDX(-45)] = 0x0425,
9867 [BEND_IDX(-50)] = 0x0525,
9872 * steps -50 to 50 inclusive, in steps of 5
9873 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
9874 * change in clock period = -(steps / 10) * 5.787 ps
9876 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
9879 int idx = BEND_IDX(steps);
9881 if (drm_WARN_ON(&dev_priv->drm, steps % 5 != 0))
9884 if (drm_WARN_ON(&dev_priv->drm, idx >= ARRAY_SIZE(sscdivintphase)))
9887 mutex_lock(&dev_priv->sb_lock);
9889 if (steps % 10 != 0)
9893 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
9895 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
9897 tmp |= sscdivintphase[idx];
9898 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
9900 mutex_unlock(&dev_priv->sb_lock);
9905 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
9907 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
9908 u32 ctl = intel_de_read(dev_priv, SPLL_CTL);
9910 if ((ctl & SPLL_PLL_ENABLE) == 0)
9913 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
9914 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9917 if (IS_BROADWELL(dev_priv) &&
9918 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
9924 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
9925 enum intel_dpll_id id)
9927 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
9928 u32 ctl = intel_de_read(dev_priv, WRPLL_CTL(id));
9930 if ((ctl & WRPLL_PLL_ENABLE) == 0)
9933 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
9936 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
9937 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
9938 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
9944 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
9946 struct intel_encoder *encoder;
9947 bool has_fdi = false;
9949 for_each_intel_encoder(&dev_priv->drm, encoder) {
9950 switch (encoder->type) {
9951 case INTEL_OUTPUT_ANALOG:
9960 * The BIOS may have decided to use the PCH SSC
9961 * reference so we must not disable it until the
9962 * relevant PLLs have stopped relying on it. We'll
9963 * just leave the PCH SSC reference enabled in case
9964 * any active PLL is using it. It will get disabled
9965 * after runtime suspend if we don't have FDI.
9967 * TODO: Move the whole reference clock handling
9968 * to the modeset sequence proper so that we can
9969 * actually enable/disable/reconfigure these things
9970 * safely. To do that we need to introduce a real
9971 * clock hierarchy. That would also allow us to do
9972 * clock bending finally.
9974 dev_priv->pch_ssc_use = 0;
9976 if (spll_uses_pch_ssc(dev_priv)) {
9977 drm_dbg_kms(&dev_priv->drm, "SPLL using PCH SSC\n");
9978 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
9981 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
9982 drm_dbg_kms(&dev_priv->drm, "WRPLL1 using PCH SSC\n");
9983 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
9986 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
9987 drm_dbg_kms(&dev_priv->drm, "WRPLL2 using PCH SSC\n");
9988 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
9991 if (dev_priv->pch_ssc_use)
9995 lpt_bend_clkout_dp(dev_priv, 0);
9996 lpt_enable_clkout_dp(dev_priv, true, true);
9998 lpt_disable_clkout_dp(dev_priv);
10003 * Initialize reference clocks when the driver loads
10005 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
10007 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
10008 ilk_init_pch_refclk(dev_priv);
10009 else if (HAS_PCH_LPT(dev_priv))
10010 lpt_init_pch_refclk(dev_priv);
10013 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
10015 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10016 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10017 enum pipe pipe = crtc->pipe;
10022 switch (crtc_state->pipe_bpp) {
10024 val |= PIPECONF_6BPC;
10027 val |= PIPECONF_8BPC;
10030 val |= PIPECONF_10BPC;
10033 val |= PIPECONF_12BPC;
10036 /* Case prevented by intel_choose_pipe_bpp_dither. */
10040 if (crtc_state->dither)
10041 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
10043 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
10044 val |= PIPECONF_INTERLACED_ILK;
10046 val |= PIPECONF_PROGRESSIVE;
10049 * This would end up with an odd purple hue over
10050 * the entire display. Make sure we don't do it.
10052 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
10053 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
10055 if (crtc_state->limited_color_range)
10056 val |= PIPECONF_COLOR_RANGE_SELECT;
10058 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
10059 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
10061 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
10063 val |= PIPECONF_FRAME_START_DELAY(0);
10065 intel_de_write(dev_priv, PIPECONF(pipe), val);
10066 intel_de_posting_read(dev_priv, PIPECONF(pipe));
10069 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state)
10071 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10072 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10073 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
10076 if (IS_HASWELL(dev_priv) && crtc_state->dither)
10077 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
10079 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
10080 val |= PIPECONF_INTERLACED_ILK;
10082 val |= PIPECONF_PROGRESSIVE;
10084 if (IS_HASWELL(dev_priv) &&
10085 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
10086 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
10088 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val);
10089 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder));
10092 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
10094 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10095 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10098 switch (crtc_state->pipe_bpp) {
10100 val |= PIPEMISC_DITHER_6_BPC;
10103 val |= PIPEMISC_DITHER_8_BPC;
10106 val |= PIPEMISC_DITHER_10_BPC;
10109 val |= PIPEMISC_DITHER_12_BPC;
10112 MISSING_CASE(crtc_state->pipe_bpp);
10116 if (crtc_state->dither)
10117 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
10119 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
10120 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
10121 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
10123 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
10124 val |= PIPEMISC_YUV420_ENABLE |
10125 PIPEMISC_YUV420_MODE_FULL_BLEND;
10127 if (INTEL_GEN(dev_priv) >= 11 &&
10128 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
10129 BIT(PLANE_CURSOR))) == 0)
10130 val |= PIPEMISC_HDR_MODE_PRECISION;
10132 if (INTEL_GEN(dev_priv) >= 12)
10133 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC;
10135 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val);
10138 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
10140 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10143 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
10145 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
10146 case PIPEMISC_DITHER_6_BPC:
10148 case PIPEMISC_DITHER_8_BPC:
10150 case PIPEMISC_DITHER_10_BPC:
10152 case PIPEMISC_DITHER_12_BPC:
10160 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
10163 * Account for spread spectrum to avoid
10164 * oversubscribing the link. Max center spread
10165 * is 2.5%; use 5% for safety's sake.
10167 u32 bps = target_clock * bpp * 21 / 20;
10168 return DIV_ROUND_UP(bps, link_bw * 8);
10171 static bool ilk_needs_fb_cb_tune(struct dpll *dpll, int factor)
10173 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
10176 static void ilk_compute_dpll(struct intel_crtc *crtc,
10177 struct intel_crtc_state *crtc_state,
10178 struct dpll *reduced_clock)
10180 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10184 /* Enable autotuning of the PLL clock (if permissible) */
10186 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
10187 if ((intel_panel_use_ssc(dev_priv) &&
10188 dev_priv->vbt.lvds_ssc_freq == 100000) ||
10189 (HAS_PCH_IBX(dev_priv) &&
10190 intel_is_dual_link_lvds(dev_priv)))
10192 } else if (crtc_state->sdvo_tv_clock) {
10196 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
10198 if (ilk_needs_fb_cb_tune(&crtc_state->dpll, factor))
10201 if (reduced_clock) {
10202 fp2 = i9xx_dpll_compute_fp(reduced_clock);
10204 if (reduced_clock->m < factor * reduced_clock->n)
10212 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
10213 dpll |= DPLLB_MODE_LVDS;
10215 dpll |= DPLLB_MODE_DAC_SERIAL;
10217 dpll |= (crtc_state->pixel_multiplier - 1)
10218 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
10220 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
10221 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
10222 dpll |= DPLL_SDVO_HIGH_SPEED;
10224 if (intel_crtc_has_dp_encoder(crtc_state))
10225 dpll |= DPLL_SDVO_HIGH_SPEED;
10228 * The high speed IO clock is only really required for
10229 * SDVO/HDMI/DP, but we also enable it for CRT to make it
10230 * possible to share the DPLL between CRT and HDMI. Enabling
10231 * the clock needlessly does no real harm, except use up a
10232 * bit of power potentially.
10234 * We'll limit this to IVB with 3 pipes, since it has only two
10235 * DPLLs and so DPLL sharing is the only way to get three pipes
10236 * driving PCH ports at the same time. On SNB we could do this,
10237 * and potentially avoid enabling the second DPLL, but it's not
10238 * clear if it''s a win or loss power wise. No point in doing
10239 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
10241 if (INTEL_NUM_PIPES(dev_priv) == 3 &&
10242 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
10243 dpll |= DPLL_SDVO_HIGH_SPEED;
10245 /* compute bitmask from p1 value */
10246 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
10248 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
10250 switch (crtc_state->dpll.p2) {
10252 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
10255 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
10258 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
10261 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
10265 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
10266 intel_panel_use_ssc(dev_priv))
10267 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
10269 dpll |= PLL_REF_INPUT_DREFCLK;
10271 dpll |= DPLL_VCO_ENABLE;
10273 crtc_state->dpll_hw_state.dpll = dpll;
10274 crtc_state->dpll_hw_state.fp0 = fp;
10275 crtc_state->dpll_hw_state.fp1 = fp2;
10278 static int ilk_crtc_compute_clock(struct intel_crtc *crtc,
10279 struct intel_crtc_state *crtc_state)
10281 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10282 struct intel_atomic_state *state =
10283 to_intel_atomic_state(crtc_state->uapi.state);
10284 const struct intel_limit *limit;
10285 int refclk = 120000;
10287 memset(&crtc_state->dpll_hw_state, 0,
10288 sizeof(crtc_state->dpll_hw_state));
10290 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
10291 if (!crtc_state->has_pch_encoder)
10294 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
10295 if (intel_panel_use_ssc(dev_priv)) {
10296 drm_dbg_kms(&dev_priv->drm,
10297 "using SSC reference clock of %d kHz\n",
10298 dev_priv->vbt.lvds_ssc_freq);
10299 refclk = dev_priv->vbt.lvds_ssc_freq;
10302 if (intel_is_dual_link_lvds(dev_priv)) {
10303 if (refclk == 100000)
10304 limit = &ilk_limits_dual_lvds_100m;
10306 limit = &ilk_limits_dual_lvds;
10308 if (refclk == 100000)
10309 limit = &ilk_limits_single_lvds_100m;
10311 limit = &ilk_limits_single_lvds;
10314 limit = &ilk_limits_dac;
10317 if (!crtc_state->clock_set &&
10318 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
10319 refclk, NULL, &crtc_state->dpll)) {
10320 drm_err(&dev_priv->drm,
10321 "Couldn't find PLL settings for mode!\n");
10325 ilk_compute_dpll(crtc, crtc_state, NULL);
10327 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
10328 drm_dbg_kms(&dev_priv->drm,
10329 "failed to find PLL for pipe %c\n",
10330 pipe_name(crtc->pipe));
10337 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
10338 struct intel_link_m_n *m_n)
10340 struct drm_device *dev = crtc->base.dev;
10341 struct drm_i915_private *dev_priv = to_i915(dev);
10342 enum pipe pipe = crtc->pipe;
10344 m_n->link_m = intel_de_read(dev_priv, PCH_TRANS_LINK_M1(pipe));
10345 m_n->link_n = intel_de_read(dev_priv, PCH_TRANS_LINK_N1(pipe));
10346 m_n->gmch_m = intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
10348 m_n->gmch_n = intel_de_read(dev_priv, PCH_TRANS_DATA_N1(pipe));
10349 m_n->tu = ((intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
10350 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10353 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
10354 enum transcoder transcoder,
10355 struct intel_link_m_n *m_n,
10356 struct intel_link_m_n *m2_n2)
10358 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10359 enum pipe pipe = crtc->pipe;
10361 if (INTEL_GEN(dev_priv) >= 5) {
10362 m_n->link_m = intel_de_read(dev_priv,
10363 PIPE_LINK_M1(transcoder));
10364 m_n->link_n = intel_de_read(dev_priv,
10365 PIPE_LINK_N1(transcoder));
10366 m_n->gmch_m = intel_de_read(dev_priv,
10367 PIPE_DATA_M1(transcoder))
10369 m_n->gmch_n = intel_de_read(dev_priv,
10370 PIPE_DATA_N1(transcoder));
10371 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M1(transcoder))
10372 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10374 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
10375 m2_n2->link_m = intel_de_read(dev_priv,
10376 PIPE_LINK_M2(transcoder));
10377 m2_n2->link_n = intel_de_read(dev_priv,
10378 PIPE_LINK_N2(transcoder));
10379 m2_n2->gmch_m = intel_de_read(dev_priv,
10380 PIPE_DATA_M2(transcoder))
10382 m2_n2->gmch_n = intel_de_read(dev_priv,
10383 PIPE_DATA_N2(transcoder));
10384 m2_n2->tu = ((intel_de_read(dev_priv, PIPE_DATA_M2(transcoder))
10385 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10388 m_n->link_m = intel_de_read(dev_priv, PIPE_LINK_M_G4X(pipe));
10389 m_n->link_n = intel_de_read(dev_priv, PIPE_LINK_N_G4X(pipe));
10390 m_n->gmch_m = intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
10392 m_n->gmch_n = intel_de_read(dev_priv, PIPE_DATA_N_G4X(pipe));
10393 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
10394 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
10398 void intel_dp_get_m_n(struct intel_crtc *crtc,
10399 struct intel_crtc_state *pipe_config)
10401 if (pipe_config->has_pch_encoder)
10402 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
10404 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10405 &pipe_config->dp_m_n,
10406 &pipe_config->dp_m2_n2);
10409 static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc,
10410 struct intel_crtc_state *pipe_config)
10412 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
10413 &pipe_config->fdi_m_n, NULL);
10416 static void skl_get_pfit_config(struct intel_crtc *crtc,
10417 struct intel_crtc_state *pipe_config)
10419 struct drm_device *dev = crtc->base.dev;
10420 struct drm_i915_private *dev_priv = to_i915(dev);
10421 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
10426 /* find scaler attached to this pipe */
10427 for (i = 0; i < crtc->num_scalers; i++) {
10428 ps_ctrl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i));
10429 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
10431 pipe_config->pch_pfit.enabled = true;
10432 pipe_config->pch_pfit.pos = intel_de_read(dev_priv,
10433 SKL_PS_WIN_POS(crtc->pipe, i));
10434 pipe_config->pch_pfit.size = intel_de_read(dev_priv,
10435 SKL_PS_WIN_SZ(crtc->pipe, i));
10436 scaler_state->scalers[i].in_use = true;
10441 scaler_state->scaler_id = id;
10443 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
10445 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
10450 skl_get_initial_plane_config(struct intel_crtc *crtc,
10451 struct intel_initial_plane_config *plane_config)
10453 struct drm_device *dev = crtc->base.dev;
10454 struct drm_i915_private *dev_priv = to_i915(dev);
10455 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
10456 enum plane_id plane_id = plane->id;
10458 u32 val, base, offset, stride_mult, tiling, alpha;
10459 int fourcc, pixel_format;
10460 unsigned int aligned_height;
10461 struct drm_framebuffer *fb;
10462 struct intel_framebuffer *intel_fb;
10464 if (!plane->get_hw_state(plane, &pipe))
10467 drm_WARN_ON(dev, pipe != crtc->pipe);
10469 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10471 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
10475 fb = &intel_fb->base;
10479 val = intel_de_read(dev_priv, PLANE_CTL(pipe, plane_id));
10481 if (INTEL_GEN(dev_priv) >= 11)
10482 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
10484 pixel_format = val & PLANE_CTL_FORMAT_MASK;
10486 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
10487 alpha = intel_de_read(dev_priv,
10488 PLANE_COLOR_CTL(pipe, plane_id));
10489 alpha &= PLANE_COLOR_ALPHA_MASK;
10491 alpha = val & PLANE_CTL_ALPHA_MASK;
10494 fourcc = skl_format_to_fourcc(pixel_format,
10495 val & PLANE_CTL_ORDER_RGBX, alpha);
10496 fb->format = drm_format_info(fourcc);
10498 tiling = val & PLANE_CTL_TILED_MASK;
10500 case PLANE_CTL_TILED_LINEAR:
10501 fb->modifier = DRM_FORMAT_MOD_LINEAR;
10503 case PLANE_CTL_TILED_X:
10504 plane_config->tiling = I915_TILING_X;
10505 fb->modifier = I915_FORMAT_MOD_X_TILED;
10507 case PLANE_CTL_TILED_Y:
10508 plane_config->tiling = I915_TILING_Y;
10509 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10510 fb->modifier = INTEL_GEN(dev_priv) >= 12 ?
10511 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS :
10512 I915_FORMAT_MOD_Y_TILED_CCS;
10513 else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE)
10514 fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
10516 fb->modifier = I915_FORMAT_MOD_Y_TILED;
10518 case PLANE_CTL_TILED_YF:
10519 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
10520 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
10522 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
10525 MISSING_CASE(tiling);
10530 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
10531 * while i915 HW rotation is clockwise, thats why this swapping.
10533 switch (val & PLANE_CTL_ROTATE_MASK) {
10534 case PLANE_CTL_ROTATE_0:
10535 plane_config->rotation = DRM_MODE_ROTATE_0;
10537 case PLANE_CTL_ROTATE_90:
10538 plane_config->rotation = DRM_MODE_ROTATE_270;
10540 case PLANE_CTL_ROTATE_180:
10541 plane_config->rotation = DRM_MODE_ROTATE_180;
10543 case PLANE_CTL_ROTATE_270:
10544 plane_config->rotation = DRM_MODE_ROTATE_90;
10548 if (INTEL_GEN(dev_priv) >= 10 &&
10549 val & PLANE_CTL_FLIP_HORIZONTAL)
10550 plane_config->rotation |= DRM_MODE_REFLECT_X;
10552 base = intel_de_read(dev_priv, PLANE_SURF(pipe, plane_id)) & 0xfffff000;
10553 plane_config->base = base;
10555 offset = intel_de_read(dev_priv, PLANE_OFFSET(pipe, plane_id));
10557 val = intel_de_read(dev_priv, PLANE_SIZE(pipe, plane_id));
10558 fb->height = ((val >> 16) & 0xffff) + 1;
10559 fb->width = ((val >> 0) & 0xffff) + 1;
10561 val = intel_de_read(dev_priv, PLANE_STRIDE(pipe, plane_id));
10562 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
10563 fb->pitches[0] = (val & 0x3ff) * stride_mult;
10565 aligned_height = intel_fb_align_height(fb, 0, fb->height);
10567 plane_config->size = fb->pitches[0] * aligned_height;
10569 drm_dbg_kms(&dev_priv->drm,
10570 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
10571 crtc->base.name, plane->base.name, fb->width, fb->height,
10572 fb->format->cpp[0] * 8, base, fb->pitches[0],
10573 plane_config->size);
10575 plane_config->fb = intel_fb;
10582 static void ilk_get_pfit_config(struct intel_crtc *crtc,
10583 struct intel_crtc_state *pipe_config)
10585 struct drm_device *dev = crtc->base.dev;
10586 struct drm_i915_private *dev_priv = to_i915(dev);
10589 tmp = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
10591 if (tmp & PF_ENABLE) {
10592 pipe_config->pch_pfit.enabled = true;
10593 pipe_config->pch_pfit.pos = intel_de_read(dev_priv,
10594 PF_WIN_POS(crtc->pipe));
10595 pipe_config->pch_pfit.size = intel_de_read(dev_priv,
10596 PF_WIN_SZ(crtc->pipe));
10598 /* We currently do not free assignements of panel fitters on
10599 * ivb/hsw (since we don't use the higher upscaling modes which
10600 * differentiates them) so just WARN about this case for now. */
10601 if (IS_GEN(dev_priv, 7)) {
10602 drm_WARN_ON(dev, (tmp & PF_PIPE_SEL_MASK_IVB) !=
10603 PF_PIPE_SEL_IVB(crtc->pipe));
10608 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
10609 struct intel_crtc_state *pipe_config)
10611 struct drm_device *dev = crtc->base.dev;
10612 struct drm_i915_private *dev_priv = to_i915(dev);
10613 enum intel_display_power_domain power_domain;
10614 intel_wakeref_t wakeref;
10618 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
10619 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10623 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10624 pipe_config->shared_dpll = NULL;
10625 pipe_config->master_transcoder = INVALID_TRANSCODER;
10628 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
10629 if (!(tmp & PIPECONF_ENABLE))
10632 switch (tmp & PIPECONF_BPC_MASK) {
10633 case PIPECONF_6BPC:
10634 pipe_config->pipe_bpp = 18;
10636 case PIPECONF_8BPC:
10637 pipe_config->pipe_bpp = 24;
10639 case PIPECONF_10BPC:
10640 pipe_config->pipe_bpp = 30;
10642 case PIPECONF_12BPC:
10643 pipe_config->pipe_bpp = 36;
10649 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
10650 pipe_config->limited_color_range = true;
10652 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
10653 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
10654 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
10655 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
10658 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
10662 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
10663 PIPECONF_GAMMA_MODE_SHIFT;
10665 pipe_config->csc_mode = intel_de_read(dev_priv,
10666 PIPE_CSC_MODE(crtc->pipe));
10668 i9xx_get_pipe_color_config(pipe_config);
10669 intel_color_get_config(pipe_config);
10671 if (intel_de_read(dev_priv, PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
10672 struct intel_shared_dpll *pll;
10673 enum intel_dpll_id pll_id;
10675 pipe_config->has_pch_encoder = true;
10677 tmp = intel_de_read(dev_priv, FDI_RX_CTL(crtc->pipe));
10678 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
10679 FDI_DP_PORT_WIDTH_SHIFT) + 1;
10681 ilk_get_fdi_m_n_config(crtc, pipe_config);
10683 if (HAS_PCH_IBX(dev_priv)) {
10685 * The pipe->pch transcoder and pch transcoder->pll
10686 * mapping is fixed.
10688 pll_id = (enum intel_dpll_id) crtc->pipe;
10690 tmp = intel_de_read(dev_priv, PCH_DPLL_SEL);
10691 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
10692 pll_id = DPLL_ID_PCH_PLL_B;
10694 pll_id= DPLL_ID_PCH_PLL_A;
10697 pipe_config->shared_dpll =
10698 intel_get_shared_dpll_by_id(dev_priv, pll_id);
10699 pll = pipe_config->shared_dpll;
10701 drm_WARN_ON(dev, !pll->info->funcs->get_hw_state(dev_priv, pll,
10702 &pipe_config->dpll_hw_state));
10704 tmp = pipe_config->dpll_hw_state.dpll;
10705 pipe_config->pixel_multiplier =
10706 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
10707 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
10709 ilk_pch_clock_get(crtc, pipe_config);
10711 pipe_config->pixel_multiplier = 1;
10714 intel_get_pipe_timings(crtc, pipe_config);
10715 intel_get_pipe_src_size(crtc, pipe_config);
10717 ilk_get_pfit_config(crtc, pipe_config);
10722 intel_display_power_put(dev_priv, power_domain, wakeref);
10727 static int hsw_crtc_compute_clock(struct intel_crtc *crtc,
10728 struct intel_crtc_state *crtc_state)
10730 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10731 struct intel_atomic_state *state =
10732 to_intel_atomic_state(crtc_state->uapi.state);
10734 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
10735 INTEL_GEN(dev_priv) >= 11) {
10736 struct intel_encoder *encoder =
10737 intel_get_crtc_new_encoder(state, crtc_state);
10739 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
10740 drm_dbg_kms(&dev_priv->drm,
10741 "failed to find PLL for pipe %c\n",
10742 pipe_name(crtc->pipe));
10750 static void cnl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10751 struct intel_crtc_state *pipe_config)
10753 enum intel_dpll_id id;
10756 temp = intel_de_read(dev_priv, DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
10757 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
10759 if (drm_WARN_ON(&dev_priv->drm, id < SKL_DPLL0 || id > SKL_DPLL2))
10762 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10765 static void icl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10766 struct intel_crtc_state *pipe_config)
10768 enum phy phy = intel_port_to_phy(dev_priv, port);
10769 enum icl_port_dpll_id port_dpll_id;
10770 enum intel_dpll_id id;
10773 if (intel_phy_is_combo(dev_priv, phy)) {
10774 temp = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0) &
10775 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
10776 id = temp >> ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
10777 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10778 } else if (intel_phy_is_tc(dev_priv, phy)) {
10779 u32 clk_sel = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
10781 if (clk_sel == DDI_CLK_SEL_MG) {
10782 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
10784 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
10786 drm_WARN_ON(&dev_priv->drm,
10787 clk_sel < DDI_CLK_SEL_TBT_162);
10788 id = DPLL_ID_ICL_TBTPLL;
10789 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
10792 drm_WARN(&dev_priv->drm, 1, "Invalid port %x\n", port);
10796 pipe_config->icl_port_dplls[port_dpll_id].pll =
10797 intel_get_shared_dpll_by_id(dev_priv, id);
10799 icl_set_active_port_dpll(pipe_config, port_dpll_id);
10802 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
10804 struct intel_crtc_state *pipe_config)
10806 enum intel_dpll_id id;
10810 id = DPLL_ID_SKL_DPLL0;
10813 id = DPLL_ID_SKL_DPLL1;
10816 id = DPLL_ID_SKL_DPLL2;
10819 drm_err(&dev_priv->drm, "Incorrect port type\n");
10823 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10826 static void skl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10827 struct intel_crtc_state *pipe_config)
10829 enum intel_dpll_id id;
10832 temp = intel_de_read(dev_priv, DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
10833 id = temp >> (port * 3 + 1);
10835 if (drm_WARN_ON(&dev_priv->drm, id < SKL_DPLL0 || id > SKL_DPLL3))
10838 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10841 static void hsw_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
10842 struct intel_crtc_state *pipe_config)
10844 enum intel_dpll_id id;
10845 u32 ddi_pll_sel = intel_de_read(dev_priv, PORT_CLK_SEL(port));
10847 switch (ddi_pll_sel) {
10848 case PORT_CLK_SEL_WRPLL1:
10849 id = DPLL_ID_WRPLL1;
10851 case PORT_CLK_SEL_WRPLL2:
10852 id = DPLL_ID_WRPLL2;
10854 case PORT_CLK_SEL_SPLL:
10857 case PORT_CLK_SEL_LCPLL_810:
10858 id = DPLL_ID_LCPLL_810;
10860 case PORT_CLK_SEL_LCPLL_1350:
10861 id = DPLL_ID_LCPLL_1350;
10863 case PORT_CLK_SEL_LCPLL_2700:
10864 id = DPLL_ID_LCPLL_2700;
10867 MISSING_CASE(ddi_pll_sel);
10869 case PORT_CLK_SEL_NONE:
10873 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
10876 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
10877 struct intel_crtc_state *pipe_config,
10878 u64 *power_domain_mask,
10879 intel_wakeref_t *wakerefs)
10881 struct drm_device *dev = crtc->base.dev;
10882 struct drm_i915_private *dev_priv = to_i915(dev);
10883 enum intel_display_power_domain power_domain;
10884 unsigned long panel_transcoder_mask = 0;
10885 unsigned long enabled_panel_transcoders = 0;
10886 enum transcoder panel_transcoder;
10887 intel_wakeref_t wf;
10890 if (INTEL_GEN(dev_priv) >= 11)
10891 panel_transcoder_mask |=
10892 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
10894 if (HAS_TRANSCODER_EDP(dev_priv))
10895 panel_transcoder_mask |= BIT(TRANSCODER_EDP);
10898 * The pipe->transcoder mapping is fixed with the exception of the eDP
10899 * and DSI transcoders handled below.
10901 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
10904 * XXX: Do intel_display_power_get_if_enabled before reading this (for
10905 * consistency and less surprising code; it's in always on power).
10907 for_each_set_bit(panel_transcoder,
10908 &panel_transcoder_mask,
10909 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
10910 bool force_thru = false;
10911 enum pipe trans_pipe;
10913 tmp = intel_de_read(dev_priv,
10914 TRANS_DDI_FUNC_CTL(panel_transcoder));
10915 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
10919 * Log all enabled ones, only use the first one.
10921 * FIXME: This won't work for two separate DSI displays.
10923 enabled_panel_transcoders |= BIT(panel_transcoder);
10924 if (enabled_panel_transcoders != BIT(panel_transcoder))
10927 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
10930 "unknown pipe linked to transcoder %s\n",
10931 transcoder_name(panel_transcoder));
10933 case TRANS_DDI_EDP_INPUT_A_ONOFF:
10936 case TRANS_DDI_EDP_INPUT_A_ON:
10937 trans_pipe = PIPE_A;
10939 case TRANS_DDI_EDP_INPUT_B_ONOFF:
10940 trans_pipe = PIPE_B;
10942 case TRANS_DDI_EDP_INPUT_C_ONOFF:
10943 trans_pipe = PIPE_C;
10945 case TRANS_DDI_EDP_INPUT_D_ONOFF:
10946 trans_pipe = PIPE_D;
10950 if (trans_pipe == crtc->pipe) {
10951 pipe_config->cpu_transcoder = panel_transcoder;
10952 pipe_config->pch_pfit.force_thru = force_thru;
10957 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
10959 drm_WARN_ON(dev, (enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
10960 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
10962 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
10963 drm_WARN_ON(dev, *power_domain_mask & BIT_ULL(power_domain));
10965 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
10969 wakerefs[power_domain] = wf;
10970 *power_domain_mask |= BIT_ULL(power_domain);
10972 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder));
10974 return tmp & PIPECONF_ENABLE;
10977 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
10978 struct intel_crtc_state *pipe_config,
10979 u64 *power_domain_mask,
10980 intel_wakeref_t *wakerefs)
10982 struct drm_device *dev = crtc->base.dev;
10983 struct drm_i915_private *dev_priv = to_i915(dev);
10984 enum intel_display_power_domain power_domain;
10985 enum transcoder cpu_transcoder;
10986 intel_wakeref_t wf;
10990 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
10991 if (port == PORT_A)
10992 cpu_transcoder = TRANSCODER_DSI_A;
10994 cpu_transcoder = TRANSCODER_DSI_C;
10996 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
10997 drm_WARN_ON(dev, *power_domain_mask & BIT_ULL(power_domain));
10999 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
11003 wakerefs[power_domain] = wf;
11004 *power_domain_mask |= BIT_ULL(power_domain);
11007 * The PLL needs to be enabled with a valid divider
11008 * configuration, otherwise accessing DSI registers will hang
11009 * the machine. See BSpec North Display Engine
11010 * registers/MIPI[BXT]. We can break out here early, since we
11011 * need the same DSI PLL to be enabled for both DSI ports.
11013 if (!bxt_dsi_pll_is_enabled(dev_priv))
11016 /* XXX: this works for video mode only */
11017 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
11018 if (!(tmp & DPI_ENABLE))
11021 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
11022 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
11025 pipe_config->cpu_transcoder = cpu_transcoder;
11029 return transcoder_is_dsi(pipe_config->cpu_transcoder);
11032 static void hsw_get_ddi_port_state(struct intel_crtc *crtc,
11033 struct intel_crtc_state *pipe_config)
11035 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11036 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
11037 struct intel_shared_dpll *pll;
11041 if (transcoder_is_dsi(cpu_transcoder)) {
11042 port = (cpu_transcoder == TRANSCODER_DSI_A) ?
11045 tmp = intel_de_read(dev_priv,
11046 TRANS_DDI_FUNC_CTL(cpu_transcoder));
11047 if (INTEL_GEN(dev_priv) >= 12)
11048 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
11050 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
11053 if (INTEL_GEN(dev_priv) >= 11)
11054 icl_get_ddi_pll(dev_priv, port, pipe_config);
11055 else if (IS_CANNONLAKE(dev_priv))
11056 cnl_get_ddi_pll(dev_priv, port, pipe_config);
11057 else if (IS_GEN9_BC(dev_priv))
11058 skl_get_ddi_pll(dev_priv, port, pipe_config);
11059 else if (IS_GEN9_LP(dev_priv))
11060 bxt_get_ddi_pll(dev_priv, port, pipe_config);
11062 hsw_get_ddi_pll(dev_priv, port, pipe_config);
11064 pll = pipe_config->shared_dpll;
11066 drm_WARN_ON(&dev_priv->drm,
11067 !pll->info->funcs->get_hw_state(dev_priv, pll,
11068 &pipe_config->dpll_hw_state));
11072 * Haswell has only FDI/PCH transcoder A. It is which is connected to
11073 * DDI E. So just check whether this pipe is wired to DDI E and whether
11074 * the PCH transcoder is on.
11076 if (INTEL_GEN(dev_priv) < 9 &&
11077 (port == PORT_E) && intel_de_read(dev_priv, LPT_TRANSCONF) & TRANS_ENABLE) {
11078 pipe_config->has_pch_encoder = true;
11080 tmp = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
11081 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
11082 FDI_DP_PORT_WIDTH_SHIFT) + 1;
11084 ilk_get_fdi_m_n_config(crtc, pipe_config);
11088 static enum transcoder transcoder_master_readout(struct drm_i915_private *dev_priv,
11089 enum transcoder cpu_transcoder)
11091 u32 trans_port_sync, master_select;
11093 trans_port_sync = intel_de_read(dev_priv,
11094 TRANS_DDI_FUNC_CTL2(cpu_transcoder));
11096 if ((trans_port_sync & PORT_SYNC_MODE_ENABLE) == 0)
11097 return INVALID_TRANSCODER;
11099 master_select = trans_port_sync &
11100 PORT_SYNC_MODE_MASTER_SELECT_MASK;
11101 if (master_select == 0)
11102 return TRANSCODER_EDP;
11104 return master_select - 1;
11107 static void icl_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
11109 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
11111 enum transcoder cpu_transcoder;
11113 crtc_state->master_transcoder = transcoder_master_readout(dev_priv,
11114 crtc_state->cpu_transcoder);
11116 transcoders = BIT(TRANSCODER_A) |
11117 BIT(TRANSCODER_B) |
11118 BIT(TRANSCODER_C) |
11120 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) {
11121 enum intel_display_power_domain power_domain;
11122 intel_wakeref_t trans_wakeref;
11124 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
11125 trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
11128 if (!trans_wakeref)
11131 if (transcoder_master_readout(dev_priv, cpu_transcoder) ==
11132 crtc_state->cpu_transcoder)
11133 crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder);
11135 intel_display_power_put(dev_priv, power_domain, trans_wakeref);
11138 drm_WARN_ON(&dev_priv->drm,
11139 crtc_state->master_transcoder != INVALID_TRANSCODER &&
11140 crtc_state->sync_mode_slaves_mask);
11143 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
11144 struct intel_crtc_state *pipe_config)
11146 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11147 intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf;
11148 enum intel_display_power_domain power_domain;
11149 u64 power_domain_mask;
11153 pipe_config->master_transcoder = INVALID_TRANSCODER;
11155 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
11156 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
11160 wakerefs[power_domain] = wf;
11161 power_domain_mask = BIT_ULL(power_domain);
11163 pipe_config->shared_dpll = NULL;
11165 active = hsw_get_transcoder_state(crtc, pipe_config,
11166 &power_domain_mask, wakerefs);
11168 if (IS_GEN9_LP(dev_priv) &&
11169 bxt_get_dsi_transcoder_state(crtc, pipe_config,
11170 &power_domain_mask, wakerefs)) {
11171 drm_WARN_ON(&dev_priv->drm, active);
11178 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
11179 INTEL_GEN(dev_priv) >= 11) {
11180 hsw_get_ddi_port_state(crtc, pipe_config);
11181 intel_get_pipe_timings(crtc, pipe_config);
11184 intel_get_pipe_src_size(crtc, pipe_config);
11186 if (IS_HASWELL(dev_priv)) {
11187 u32 tmp = intel_de_read(dev_priv,
11188 PIPECONF(pipe_config->cpu_transcoder));
11190 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
11191 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
11193 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
11195 pipe_config->output_format =
11196 bdw_get_pipemisc_output_format(crtc);
11199 * Currently there is no interface defined to
11200 * check user preference between RGB/YCBCR444
11201 * or YCBCR420. So the only possible case for
11202 * YCBCR444 usage is driving YCBCR420 output
11203 * with LSPCON, when pipe is configured for
11204 * YCBCR444 output and LSPCON takes care of
11207 pipe_config->lspcon_downsampling =
11208 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444;
11211 pipe_config->gamma_mode = intel_de_read(dev_priv,
11212 GAMMA_MODE(crtc->pipe));
11214 pipe_config->csc_mode = intel_de_read(dev_priv,
11215 PIPE_CSC_MODE(crtc->pipe));
11217 if (INTEL_GEN(dev_priv) >= 9) {
11218 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
11220 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
11221 pipe_config->gamma_enable = true;
11223 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
11224 pipe_config->csc_enable = true;
11226 i9xx_get_pipe_color_config(pipe_config);
11229 intel_color_get_config(pipe_config);
11231 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
11232 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
11233 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
11234 pipe_config->ips_linetime =
11235 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
11237 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
11238 drm_WARN_ON(&dev_priv->drm, power_domain_mask & BIT_ULL(power_domain));
11240 wf = intel_display_power_get_if_enabled(dev_priv, power_domain);
11242 wakerefs[power_domain] = wf;
11243 power_domain_mask |= BIT_ULL(power_domain);
11245 if (INTEL_GEN(dev_priv) >= 9)
11246 skl_get_pfit_config(crtc, pipe_config);
11248 ilk_get_pfit_config(crtc, pipe_config);
11251 if (hsw_crtc_supports_ips(crtc)) {
11252 if (IS_HASWELL(dev_priv))
11253 pipe_config->ips_enabled = intel_de_read(dev_priv,
11254 IPS_CTL) & IPS_ENABLE;
11257 * We cannot readout IPS state on broadwell, set to
11258 * true so we can set it to a defined state on first
11261 pipe_config->ips_enabled = true;
11265 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
11266 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
11267 pipe_config->pixel_multiplier =
11268 intel_de_read(dev_priv,
11269 PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
11271 pipe_config->pixel_multiplier = 1;
11274 if (INTEL_GEN(dev_priv) >= 11 &&
11275 !transcoder_is_dsi(pipe_config->cpu_transcoder))
11276 icl_get_trans_port_sync_config(pipe_config);
11279 for_each_power_domain(power_domain, power_domain_mask)
11280 intel_display_power_put(dev_priv,
11281 power_domain, wakerefs[power_domain]);
11286 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
11288 struct drm_i915_private *dev_priv =
11289 to_i915(plane_state->uapi.plane->dev);
11290 const struct drm_framebuffer *fb = plane_state->hw.fb;
11291 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11294 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
11295 base = sg_dma_address(obj->mm.pages->sgl);
11297 base = intel_plane_ggtt_offset(plane_state);
11299 return base + plane_state->color_plane[0].offset;
11302 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
11304 int x = plane_state->uapi.dst.x1;
11305 int y = plane_state->uapi.dst.y1;
11309 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
11312 pos |= x << CURSOR_X_SHIFT;
11315 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
11318 pos |= y << CURSOR_Y_SHIFT;
11323 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
11325 const struct drm_mode_config *config =
11326 &plane_state->uapi.plane->dev->mode_config;
11327 int width = drm_rect_width(&plane_state->uapi.dst);
11328 int height = drm_rect_height(&plane_state->uapi.dst);
11330 return width > 0 && width <= config->cursor_width &&
11331 height > 0 && height <= config->cursor_height;
11334 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
11336 struct drm_i915_private *dev_priv =
11337 to_i915(plane_state->uapi.plane->dev);
11338 unsigned int rotation = plane_state->hw.rotation;
11343 ret = intel_plane_compute_gtt(plane_state);
11347 if (!plane_state->uapi.visible)
11350 src_x = plane_state->uapi.src.x1 >> 16;
11351 src_y = plane_state->uapi.src.y1 >> 16;
11353 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
11354 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
11357 if (src_x != 0 || src_y != 0) {
11358 drm_dbg_kms(&dev_priv->drm,
11359 "Arbitrary cursor panning not supported\n");
11364 * Put the final coordinates back so that the src
11365 * coordinate checks will see the right values.
11367 drm_rect_translate_to(&plane_state->uapi.src,
11368 src_x << 16, src_y << 16);
11370 /* ILK+ do this automagically in hardware */
11371 if (HAS_GMCH(dev_priv) && rotation & DRM_MODE_ROTATE_180) {
11372 const struct drm_framebuffer *fb = plane_state->hw.fb;
11373 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
11374 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
11376 offset += (src_h * src_w - 1) * fb->format->cpp[0];
11379 plane_state->color_plane[0].offset = offset;
11380 plane_state->color_plane[0].x = src_x;
11381 plane_state->color_plane[0].y = src_y;
11386 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
11387 struct intel_plane_state *plane_state)
11389 const struct drm_framebuffer *fb = plane_state->hw.fb;
11390 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
11393 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
11394 drm_dbg_kms(&i915->drm, "cursor cannot be tiled\n");
11398 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
11400 DRM_PLANE_HELPER_NO_SCALING,
11401 DRM_PLANE_HELPER_NO_SCALING,
11406 /* Use the unclipped src/dst rectangles, which we program to hw */
11407 plane_state->uapi.src = drm_plane_state_src(&plane_state->uapi);
11408 plane_state->uapi.dst = drm_plane_state_dest(&plane_state->uapi);
11410 ret = intel_cursor_check_surface(plane_state);
11414 if (!plane_state->uapi.visible)
11417 ret = intel_plane_check_src_coordinates(plane_state);
11424 static unsigned int
11425 i845_cursor_max_stride(struct intel_plane *plane,
11426 u32 pixel_format, u64 modifier,
11427 unsigned int rotation)
11432 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11436 if (crtc_state->gamma_enable)
11437 cntl |= CURSOR_GAMMA_ENABLE;
11442 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
11443 const struct intel_plane_state *plane_state)
11445 return CURSOR_ENABLE |
11446 CURSOR_FORMAT_ARGB |
11447 CURSOR_STRIDE(plane_state->color_plane[0].stride);
11450 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
11452 int width = drm_rect_width(&plane_state->uapi.dst);
11455 * 845g/865g are only limited by the width of their cursors,
11456 * the height is arbitrary up to the precision of the register.
11458 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
11461 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
11462 struct intel_plane_state *plane_state)
11464 const struct drm_framebuffer *fb = plane_state->hw.fb;
11465 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
11468 ret = intel_check_cursor(crtc_state, plane_state);
11472 /* if we want to turn off the cursor ignore width and height */
11476 /* Check for which cursor types we support */
11477 if (!i845_cursor_size_ok(plane_state)) {
11478 drm_dbg_kms(&i915->drm,
11479 "Cursor dimension %dx%d not supported\n",
11480 drm_rect_width(&plane_state->uapi.dst),
11481 drm_rect_height(&plane_state->uapi.dst));
11485 drm_WARN_ON(&i915->drm, plane_state->uapi.visible &&
11486 plane_state->color_plane[0].stride != fb->pitches[0]);
11488 switch (fb->pitches[0]) {
11495 drm_dbg_kms(&i915->drm, "Invalid cursor stride (%u)\n",
11500 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
11505 static void i845_update_cursor(struct intel_plane *plane,
11506 const struct intel_crtc_state *crtc_state,
11507 const struct intel_plane_state *plane_state)
11509 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11510 u32 cntl = 0, base = 0, pos = 0, size = 0;
11511 unsigned long irqflags;
11513 if (plane_state && plane_state->uapi.visible) {
11514 unsigned int width = drm_rect_width(&plane_state->uapi.dst);
11515 unsigned int height = drm_rect_height(&plane_state->uapi.dst);
11517 cntl = plane_state->ctl |
11518 i845_cursor_ctl_crtc(crtc_state);
11520 size = (height << 12) | width;
11522 base = intel_cursor_base(plane_state);
11523 pos = intel_cursor_position(plane_state);
11526 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11528 /* On these chipsets we can only modify the base/size/stride
11529 * whilst the cursor is disabled.
11531 if (plane->cursor.base != base ||
11532 plane->cursor.size != size ||
11533 plane->cursor.cntl != cntl) {
11534 intel_de_write_fw(dev_priv, CURCNTR(PIPE_A), 0);
11535 intel_de_write_fw(dev_priv, CURBASE(PIPE_A), base);
11536 intel_de_write_fw(dev_priv, CURSIZE, size);
11537 intel_de_write_fw(dev_priv, CURPOS(PIPE_A), pos);
11538 intel_de_write_fw(dev_priv, CURCNTR(PIPE_A), cntl);
11540 plane->cursor.base = base;
11541 plane->cursor.size = size;
11542 plane->cursor.cntl = cntl;
11544 intel_de_write_fw(dev_priv, CURPOS(PIPE_A), pos);
11547 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11550 static void i845_disable_cursor(struct intel_plane *plane,
11551 const struct intel_crtc_state *crtc_state)
11553 i845_update_cursor(plane, crtc_state, NULL);
11556 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
11559 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11560 enum intel_display_power_domain power_domain;
11561 intel_wakeref_t wakeref;
11564 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
11565 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11569 ret = intel_de_read(dev_priv, CURCNTR(PIPE_A)) & CURSOR_ENABLE;
11573 intel_display_power_put(dev_priv, power_domain, wakeref);
11578 static unsigned int
11579 i9xx_cursor_max_stride(struct intel_plane *plane,
11580 u32 pixel_format, u64 modifier,
11581 unsigned int rotation)
11583 return plane->base.dev->mode_config.cursor_width * 4;
11586 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
11588 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11589 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11592 if (INTEL_GEN(dev_priv) >= 11)
11595 if (crtc_state->gamma_enable)
11596 cntl = MCURSOR_GAMMA_ENABLE;
11598 if (crtc_state->csc_enable)
11599 cntl |= MCURSOR_PIPE_CSC_ENABLE;
11601 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11602 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
11607 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
11608 const struct intel_plane_state *plane_state)
11610 struct drm_i915_private *dev_priv =
11611 to_i915(plane_state->uapi.plane->dev);
11614 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
11615 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
11617 switch (drm_rect_width(&plane_state->uapi.dst)) {
11619 cntl |= MCURSOR_MODE_64_ARGB_AX;
11622 cntl |= MCURSOR_MODE_128_ARGB_AX;
11625 cntl |= MCURSOR_MODE_256_ARGB_AX;
11628 MISSING_CASE(drm_rect_width(&plane_state->uapi.dst));
11632 if (plane_state->hw.rotation & DRM_MODE_ROTATE_180)
11633 cntl |= MCURSOR_ROTATE_180;
11638 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
11640 struct drm_i915_private *dev_priv =
11641 to_i915(plane_state->uapi.plane->dev);
11642 int width = drm_rect_width(&plane_state->uapi.dst);
11643 int height = drm_rect_height(&plane_state->uapi.dst);
11645 if (!intel_cursor_size_ok(plane_state))
11648 /* Cursor width is limited to a few power-of-two sizes */
11659 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
11660 * height from 8 lines up to the cursor width, when the
11661 * cursor is not rotated. Everything else requires square
11664 if (HAS_CUR_FBC(dev_priv) &&
11665 plane_state->hw.rotation & DRM_MODE_ROTATE_0) {
11666 if (height < 8 || height > width)
11669 if (height != width)
11676 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
11677 struct intel_plane_state *plane_state)
11679 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
11680 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11681 const struct drm_framebuffer *fb = plane_state->hw.fb;
11682 enum pipe pipe = plane->pipe;
11685 ret = intel_check_cursor(crtc_state, plane_state);
11689 /* if we want to turn off the cursor ignore width and height */
11693 /* Check for which cursor types we support */
11694 if (!i9xx_cursor_size_ok(plane_state)) {
11695 drm_dbg(&dev_priv->drm,
11696 "Cursor dimension %dx%d not supported\n",
11697 drm_rect_width(&plane_state->uapi.dst),
11698 drm_rect_height(&plane_state->uapi.dst));
11702 drm_WARN_ON(&dev_priv->drm, plane_state->uapi.visible &&
11703 plane_state->color_plane[0].stride != fb->pitches[0]);
11705 if (fb->pitches[0] !=
11706 drm_rect_width(&plane_state->uapi.dst) * fb->format->cpp[0]) {
11707 drm_dbg_kms(&dev_priv->drm,
11708 "Invalid cursor stride (%u) (cursor width %d)\n",
11710 drm_rect_width(&plane_state->uapi.dst));
11715 * There's something wrong with the cursor on CHV pipe C.
11716 * If it straddles the left edge of the screen then
11717 * moving it away from the edge or disabling it often
11718 * results in a pipe underrun, and often that can lead to
11719 * dead pipe (constant underrun reported, and it scans
11720 * out just a solid color). To recover from that, the
11721 * display power well must be turned off and on again.
11722 * Refuse the put the cursor into that compromised position.
11724 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
11725 plane_state->uapi.visible && plane_state->uapi.dst.x1 < 0) {
11726 drm_dbg_kms(&dev_priv->drm,
11727 "CHV cursor C not allowed to straddle the left screen edge\n");
11731 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
11736 static void i9xx_update_cursor(struct intel_plane *plane,
11737 const struct intel_crtc_state *crtc_state,
11738 const struct intel_plane_state *plane_state)
11740 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11741 enum pipe pipe = plane->pipe;
11742 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
11743 unsigned long irqflags;
11745 if (plane_state && plane_state->uapi.visible) {
11746 unsigned width = drm_rect_width(&plane_state->uapi.dst);
11747 unsigned height = drm_rect_height(&plane_state->uapi.dst);
11749 cntl = plane_state->ctl |
11750 i9xx_cursor_ctl_crtc(crtc_state);
11752 if (width != height)
11753 fbc_ctl = CUR_FBC_CTL_EN | (height - 1);
11755 base = intel_cursor_base(plane_state);
11756 pos = intel_cursor_position(plane_state);
11759 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
11762 * On some platforms writing CURCNTR first will also
11763 * cause CURPOS to be armed by the CURBASE write.
11764 * Without the CURCNTR write the CURPOS write would
11765 * arm itself. Thus we always update CURCNTR before
11768 * On other platforms CURPOS always requires the
11769 * CURBASE write to arm the update. Additonally
11770 * a write to any of the cursor register will cancel
11771 * an already armed cursor update. Thus leaving out
11772 * the CURBASE write after CURPOS could lead to a
11773 * cursor that doesn't appear to move, or even change
11774 * shape. Thus we always write CURBASE.
11776 * The other registers are armed by by the CURBASE write
11777 * except when the plane is getting enabled at which time
11778 * the CURCNTR write arms the update.
11781 if (INTEL_GEN(dev_priv) >= 9)
11782 skl_write_cursor_wm(plane, crtc_state);
11784 if (plane->cursor.base != base ||
11785 plane->cursor.size != fbc_ctl ||
11786 plane->cursor.cntl != cntl) {
11787 if (HAS_CUR_FBC(dev_priv))
11788 intel_de_write_fw(dev_priv, CUR_FBC_CTL(pipe),
11790 intel_de_write_fw(dev_priv, CURCNTR(pipe), cntl);
11791 intel_de_write_fw(dev_priv, CURPOS(pipe), pos);
11792 intel_de_write_fw(dev_priv, CURBASE(pipe), base);
11794 plane->cursor.base = base;
11795 plane->cursor.size = fbc_ctl;
11796 plane->cursor.cntl = cntl;
11798 intel_de_write_fw(dev_priv, CURPOS(pipe), pos);
11799 intel_de_write_fw(dev_priv, CURBASE(pipe), base);
11802 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
11805 static void i9xx_disable_cursor(struct intel_plane *plane,
11806 const struct intel_crtc_state *crtc_state)
11808 i9xx_update_cursor(plane, crtc_state, NULL);
11811 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
11814 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11815 enum intel_display_power_domain power_domain;
11816 intel_wakeref_t wakeref;
11821 * Not 100% correct for planes that can move between pipes,
11822 * but that's only the case for gen2-3 which don't have any
11823 * display power wells.
11825 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
11826 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
11830 val = intel_de_read(dev_priv, CURCNTR(plane->pipe));
11832 ret = val & MCURSOR_MODE;
11834 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
11835 *pipe = plane->pipe;
11837 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
11838 MCURSOR_PIPE_SELECT_SHIFT;
11840 intel_display_power_put(dev_priv, power_domain, wakeref);
11845 /* VESA 640x480x72Hz mode to set on the pipe */
11846 static const struct drm_display_mode load_detect_mode = {
11847 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
11848 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
11851 struct drm_framebuffer *
11852 intel_framebuffer_create(struct drm_i915_gem_object *obj,
11853 struct drm_mode_fb_cmd2 *mode_cmd)
11855 struct intel_framebuffer *intel_fb;
11858 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
11860 return ERR_PTR(-ENOMEM);
11862 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
11866 return &intel_fb->base;
11870 return ERR_PTR(ret);
11873 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
11874 struct drm_crtc *crtc)
11876 struct drm_plane *plane;
11877 struct drm_plane_state *plane_state;
11880 ret = drm_atomic_add_affected_planes(state, crtc);
11884 for_each_new_plane_in_state(state, plane, plane_state, i) {
11885 if (plane_state->crtc != crtc)
11888 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
11892 drm_atomic_set_fb_for_plane(plane_state, NULL);
11898 int intel_get_load_detect_pipe(struct drm_connector *connector,
11899 struct intel_load_detect_pipe *old,
11900 struct drm_modeset_acquire_ctx *ctx)
11902 struct intel_crtc *intel_crtc;
11903 struct intel_encoder *intel_encoder =
11904 intel_attached_encoder(to_intel_connector(connector));
11905 struct drm_crtc *possible_crtc;
11906 struct drm_encoder *encoder = &intel_encoder->base;
11907 struct drm_crtc *crtc = NULL;
11908 struct drm_device *dev = encoder->dev;
11909 struct drm_i915_private *dev_priv = to_i915(dev);
11910 struct drm_mode_config *config = &dev->mode_config;
11911 struct drm_atomic_state *state = NULL, *restore_state = NULL;
11912 struct drm_connector_state *connector_state;
11913 struct intel_crtc_state *crtc_state;
11916 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
11917 connector->base.id, connector->name,
11918 encoder->base.id, encoder->name);
11920 old->restore_state = NULL;
11922 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex));
11925 * Algorithm gets a little messy:
11927 * - if the connector already has an assigned crtc, use it (but make
11928 * sure it's on first)
11930 * - try to find the first unused crtc that can drive this connector,
11931 * and use that if we find one
11934 /* See if we already have a CRTC for this connector */
11935 if (connector->state->crtc) {
11936 crtc = connector->state->crtc;
11938 ret = drm_modeset_lock(&crtc->mutex, ctx);
11942 /* Make sure the crtc and connector are running */
11946 /* Find an unused one (if possible) */
11947 for_each_crtc(dev, possible_crtc) {
11949 if (!(encoder->possible_crtcs & (1 << i)))
11952 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
11956 if (possible_crtc->state->enable) {
11957 drm_modeset_unlock(&possible_crtc->mutex);
11961 crtc = possible_crtc;
11966 * If we didn't find an unused CRTC, don't use any.
11969 drm_dbg_kms(&dev_priv->drm,
11970 "no pipe available for load-detect\n");
11976 intel_crtc = to_intel_crtc(crtc);
11978 state = drm_atomic_state_alloc(dev);
11979 restore_state = drm_atomic_state_alloc(dev);
11980 if (!state || !restore_state) {
11985 state->acquire_ctx = ctx;
11986 restore_state->acquire_ctx = ctx;
11988 connector_state = drm_atomic_get_connector_state(state, connector);
11989 if (IS_ERR(connector_state)) {
11990 ret = PTR_ERR(connector_state);
11994 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
11998 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
11999 if (IS_ERR(crtc_state)) {
12000 ret = PTR_ERR(crtc_state);
12004 crtc_state->uapi.active = true;
12006 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
12007 &load_detect_mode);
12011 ret = intel_modeset_disable_planes(state, crtc);
12015 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
12017 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
12019 ret = drm_atomic_add_affected_planes(restore_state, crtc);
12021 drm_dbg_kms(&dev_priv->drm,
12022 "Failed to create a copy of old state to restore: %i\n",
12027 ret = drm_atomic_commit(state);
12029 drm_dbg_kms(&dev_priv->drm,
12030 "failed to set mode on load-detect pipe\n");
12034 old->restore_state = restore_state;
12035 drm_atomic_state_put(state);
12037 /* let the connector get through one full cycle before testing */
12038 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
12043 drm_atomic_state_put(state);
12046 if (restore_state) {
12047 drm_atomic_state_put(restore_state);
12048 restore_state = NULL;
12051 if (ret == -EDEADLK)
12057 void intel_release_load_detect_pipe(struct drm_connector *connector,
12058 struct intel_load_detect_pipe *old,
12059 struct drm_modeset_acquire_ctx *ctx)
12061 struct intel_encoder *intel_encoder =
12062 intel_attached_encoder(to_intel_connector(connector));
12063 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev);
12064 struct drm_encoder *encoder = &intel_encoder->base;
12065 struct drm_atomic_state *state = old->restore_state;
12068 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
12069 connector->base.id, connector->name,
12070 encoder->base.id, encoder->name);
12075 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
12077 drm_dbg_kms(&i915->drm,
12078 "Couldn't release load detect pipe: %i\n", ret);
12079 drm_atomic_state_put(state);
12082 static int i9xx_pll_refclk(struct drm_device *dev,
12083 const struct intel_crtc_state *pipe_config)
12085 struct drm_i915_private *dev_priv = to_i915(dev);
12086 u32 dpll = pipe_config->dpll_hw_state.dpll;
12088 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
12089 return dev_priv->vbt.lvds_ssc_freq;
12090 else if (HAS_PCH_SPLIT(dev_priv))
12092 else if (!IS_GEN(dev_priv, 2))
12098 /* Returns the clock of the currently programmed mode of the given pipe. */
12099 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
12100 struct intel_crtc_state *pipe_config)
12102 struct drm_device *dev = crtc->base.dev;
12103 struct drm_i915_private *dev_priv = to_i915(dev);
12104 enum pipe pipe = crtc->pipe;
12105 u32 dpll = pipe_config->dpll_hw_state.dpll;
12109 int refclk = i9xx_pll_refclk(dev, pipe_config);
12111 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
12112 fp = pipe_config->dpll_hw_state.fp0;
12114 fp = pipe_config->dpll_hw_state.fp1;
12116 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
12117 if (IS_PINEVIEW(dev_priv)) {
12118 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
12119 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
12121 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
12122 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
12125 if (!IS_GEN(dev_priv, 2)) {
12126 if (IS_PINEVIEW(dev_priv))
12127 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
12128 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
12130 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
12131 DPLL_FPA01_P1_POST_DIV_SHIFT);
12133 switch (dpll & DPLL_MODE_MASK) {
12134 case DPLLB_MODE_DAC_SERIAL:
12135 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
12138 case DPLLB_MODE_LVDS:
12139 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
12143 drm_dbg_kms(&dev_priv->drm,
12144 "Unknown DPLL mode %08x in programmed "
12145 "mode\n", (int)(dpll & DPLL_MODE_MASK));
12149 if (IS_PINEVIEW(dev_priv))
12150 port_clock = pnv_calc_dpll_params(refclk, &clock);
12152 port_clock = i9xx_calc_dpll_params(refclk, &clock);
12154 u32 lvds = IS_I830(dev_priv) ? 0 : intel_de_read(dev_priv,
12156 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
12159 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
12160 DPLL_FPA01_P1_POST_DIV_SHIFT);
12162 if (lvds & LVDS_CLKB_POWER_UP)
12167 if (dpll & PLL_P1_DIVIDE_BY_TWO)
12170 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
12171 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
12173 if (dpll & PLL_P2_DIVIDE_BY_4)
12179 port_clock = i9xx_calc_dpll_params(refclk, &clock);
12183 * This value includes pixel_multiplier. We will use
12184 * port_clock to compute adjusted_mode.crtc_clock in the
12185 * encoder's get_config() function.
12187 pipe_config->port_clock = port_clock;
12190 int intel_dotclock_calculate(int link_freq,
12191 const struct intel_link_m_n *m_n)
12194 * The calculation for the data clock is:
12195 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
12196 * But we want to avoid losing precison if possible, so:
12197 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
12199 * and the link clock is simpler:
12200 * link_clock = (m * link_clock) / n
12206 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
12209 static void ilk_pch_clock_get(struct intel_crtc *crtc,
12210 struct intel_crtc_state *pipe_config)
12212 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12214 /* read out port_clock from the DPLL */
12215 i9xx_crtc_clock_get(crtc, pipe_config);
12218 * In case there is an active pipe without active ports,
12219 * we may need some idea for the dotclock anyway.
12220 * Calculate one based on the FDI configuration.
12222 pipe_config->hw.adjusted_mode.crtc_clock =
12223 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
12224 &pipe_config->fdi_m_n);
12227 static void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
12228 struct intel_crtc *crtc)
12230 memset(crtc_state, 0, sizeof(*crtc_state));
12232 __drm_atomic_helper_crtc_state_reset(&crtc_state->uapi, &crtc->base);
12234 crtc_state->cpu_transcoder = INVALID_TRANSCODER;
12235 crtc_state->master_transcoder = INVALID_TRANSCODER;
12236 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
12237 crtc_state->output_format = INTEL_OUTPUT_FORMAT_INVALID;
12238 crtc_state->scaler_state.scaler_id = -1;
12239 crtc_state->mst_master_transcoder = INVALID_TRANSCODER;
12242 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc)
12244 struct intel_crtc_state *crtc_state;
12246 crtc_state = kmalloc(sizeof(*crtc_state), GFP_KERNEL);
12249 intel_crtc_state_reset(crtc_state, crtc);
12254 /* Returns the currently programmed mode of the given encoder. */
12255 struct drm_display_mode *
12256 intel_encoder_current_mode(struct intel_encoder *encoder)
12258 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
12259 struct intel_crtc_state *crtc_state;
12260 struct drm_display_mode *mode;
12261 struct intel_crtc *crtc;
12264 if (!encoder->get_hw_state(encoder, &pipe))
12267 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12269 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
12273 crtc_state = intel_crtc_state_alloc(crtc);
12279 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
12285 encoder->get_config(encoder, crtc_state);
12287 intel_mode_from_pipe_config(mode, crtc_state);
12294 static void intel_crtc_destroy(struct drm_crtc *crtc)
12296 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12298 drm_crtc_cleanup(crtc);
12303 * intel_wm_need_update - Check whether watermarks need updating
12304 * @cur: current plane state
12305 * @new: new plane state
12307 * Check current plane state versus the new one to determine whether
12308 * watermarks need to be recalculated.
12310 * Returns true or false.
12312 static bool intel_wm_need_update(const struct intel_plane_state *cur,
12313 struct intel_plane_state *new)
12315 /* Update watermarks on tiling or size changes. */
12316 if (new->uapi.visible != cur->uapi.visible)
12319 if (!cur->hw.fb || !new->hw.fb)
12322 if (cur->hw.fb->modifier != new->hw.fb->modifier ||
12323 cur->hw.rotation != new->hw.rotation ||
12324 drm_rect_width(&new->uapi.src) != drm_rect_width(&cur->uapi.src) ||
12325 drm_rect_height(&new->uapi.src) != drm_rect_height(&cur->uapi.src) ||
12326 drm_rect_width(&new->uapi.dst) != drm_rect_width(&cur->uapi.dst) ||
12327 drm_rect_height(&new->uapi.dst) != drm_rect_height(&cur->uapi.dst))
12333 static bool needs_scaling(const struct intel_plane_state *state)
12335 int src_w = drm_rect_width(&state->uapi.src) >> 16;
12336 int src_h = drm_rect_height(&state->uapi.src) >> 16;
12337 int dst_w = drm_rect_width(&state->uapi.dst);
12338 int dst_h = drm_rect_height(&state->uapi.dst);
12340 return (src_w != dst_w || src_h != dst_h);
12343 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
12344 struct intel_crtc_state *crtc_state,
12345 const struct intel_plane_state *old_plane_state,
12346 struct intel_plane_state *plane_state)
12348 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12349 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
12350 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12351 bool mode_changed = needs_modeset(crtc_state);
12352 bool was_crtc_enabled = old_crtc_state->hw.active;
12353 bool is_crtc_enabled = crtc_state->hw.active;
12354 bool turn_off, turn_on, visible, was_visible;
12357 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
12358 ret = skl_update_scaler_plane(crtc_state, plane_state);
12363 was_visible = old_plane_state->uapi.visible;
12364 visible = plane_state->uapi.visible;
12366 if (!was_crtc_enabled && drm_WARN_ON(&dev_priv->drm, was_visible))
12367 was_visible = false;
12370 * Visibility is calculated as if the crtc was on, but
12371 * after scaler setup everything depends on it being off
12372 * when the crtc isn't active.
12374 * FIXME this is wrong for watermarks. Watermarks should also
12375 * be computed as if the pipe would be active. Perhaps move
12376 * per-plane wm computation to the .check_plane() hook, and
12377 * only combine the results from all planes in the current place?
12379 if (!is_crtc_enabled) {
12380 plane_state->uapi.visible = visible = false;
12381 crtc_state->active_planes &= ~BIT(plane->id);
12382 crtc_state->data_rate[plane->id] = 0;
12383 crtc_state->min_cdclk[plane->id] = 0;
12386 if (!was_visible && !visible)
12389 turn_off = was_visible && (!visible || mode_changed);
12390 turn_on = visible && (!was_visible || mode_changed);
12392 drm_dbg_atomic(&dev_priv->drm,
12393 "[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
12394 crtc->base.base.id, crtc->base.name,
12395 plane->base.base.id, plane->base.name,
12396 was_visible, visible,
12397 turn_off, turn_on, mode_changed);
12400 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
12401 crtc_state->update_wm_pre = true;
12403 /* must disable cxsr around plane enable/disable */
12404 if (plane->id != PLANE_CURSOR)
12405 crtc_state->disable_cxsr = true;
12406 } else if (turn_off) {
12407 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
12408 crtc_state->update_wm_post = true;
12410 /* must disable cxsr around plane enable/disable */
12411 if (plane->id != PLANE_CURSOR)
12412 crtc_state->disable_cxsr = true;
12413 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
12414 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
12415 /* FIXME bollocks */
12416 crtc_state->update_wm_pre = true;
12417 crtc_state->update_wm_post = true;
12421 if (visible || was_visible)
12422 crtc_state->fb_bits |= plane->frontbuffer_bit;
12425 * ILK/SNB DVSACNTR/Sprite Enable
12426 * IVB SPR_CTL/Sprite Enable
12427 * "When in Self Refresh Big FIFO mode, a write to enable the
12428 * plane will be internally buffered and delayed while Big FIFO
12429 * mode is exiting."
12431 * Which means that enabling the sprite can take an extra frame
12432 * when we start in big FIFO mode (LP1+). Thus we need to drop
12433 * down to LP0 and wait for vblank in order to make sure the
12434 * sprite gets enabled on the next vblank after the register write.
12435 * Doing otherwise would risk enabling the sprite one frame after
12436 * we've already signalled flip completion. We can resume LP1+
12437 * once the sprite has been enabled.
12440 * WaCxSRDisabledForSpriteScaling:ivb
12441 * IVB SPR_SCALE/Scaling Enable
12442 * "Low Power watermarks must be disabled for at least one
12443 * frame before enabling sprite scaling, and kept disabled
12444 * until sprite scaling is disabled."
12446 * ILK/SNB DVSASCALE/Scaling Enable
12447 * "When in Self Refresh Big FIFO mode, scaling enable will be
12448 * masked off while Big FIFO mode is exiting."
12450 * Despite the w/a only being listed for IVB we assume that
12451 * the ILK/SNB note has similar ramifications, hence we apply
12452 * the w/a on all three platforms.
12454 * With experimental results seems this is needed also for primary
12455 * plane, not only sprite plane.
12457 if (plane->id != PLANE_CURSOR &&
12458 (IS_GEN_RANGE(dev_priv, 5, 6) ||
12459 IS_IVYBRIDGE(dev_priv)) &&
12460 (turn_on || (!needs_scaling(old_plane_state) &&
12461 needs_scaling(plane_state))))
12462 crtc_state->disable_lp_wm = true;
12467 static bool encoders_cloneable(const struct intel_encoder *a,
12468 const struct intel_encoder *b)
12470 /* masks could be asymmetric, so check both ways */
12471 return a == b || (a->cloneable & (1 << b->type) &&
12472 b->cloneable & (1 << a->type));
12475 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
12476 struct intel_crtc *crtc,
12477 struct intel_encoder *encoder)
12479 struct intel_encoder *source_encoder;
12480 struct drm_connector *connector;
12481 struct drm_connector_state *connector_state;
12484 for_each_new_connector_in_state(state, connector, connector_state, i) {
12485 if (connector_state->crtc != &crtc->base)
12489 to_intel_encoder(connector_state->best_encoder);
12490 if (!encoders_cloneable(encoder, source_encoder))
12497 static int icl_add_linked_planes(struct intel_atomic_state *state)
12499 struct intel_plane *plane, *linked;
12500 struct intel_plane_state *plane_state, *linked_plane_state;
12503 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12504 linked = plane_state->planar_linked_plane;
12509 linked_plane_state = intel_atomic_get_plane_state(state, linked);
12510 if (IS_ERR(linked_plane_state))
12511 return PTR_ERR(linked_plane_state);
12513 WARN_ON(linked_plane_state->planar_linked_plane != plane);
12514 WARN_ON(linked_plane_state->planar_slave == plane_state->planar_slave);
12520 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
12522 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12523 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12524 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
12525 struct intel_plane *plane, *linked;
12526 struct intel_plane_state *plane_state;
12529 if (INTEL_GEN(dev_priv) < 11)
12533 * Destroy all old plane links and make the slave plane invisible
12534 * in the crtc_state->active_planes mask.
12536 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12537 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
12540 plane_state->planar_linked_plane = NULL;
12541 if (plane_state->planar_slave && !plane_state->uapi.visible) {
12542 crtc_state->active_planes &= ~BIT(plane->id);
12543 crtc_state->update_planes |= BIT(plane->id);
12546 plane_state->planar_slave = false;
12549 if (!crtc_state->nv12_planes)
12552 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12553 struct intel_plane_state *linked_state = NULL;
12555 if (plane->pipe != crtc->pipe ||
12556 !(crtc_state->nv12_planes & BIT(plane->id)))
12559 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
12560 if (!icl_is_nv12_y_plane(linked->id))
12563 if (crtc_state->active_planes & BIT(linked->id))
12566 linked_state = intel_atomic_get_plane_state(state, linked);
12567 if (IS_ERR(linked_state))
12568 return PTR_ERR(linked_state);
12573 if (!linked_state) {
12574 drm_dbg_kms(&dev_priv->drm,
12575 "Need %d free Y planes for planar YUV\n",
12576 hweight8(crtc_state->nv12_planes));
12581 plane_state->planar_linked_plane = linked;
12583 linked_state->planar_slave = true;
12584 linked_state->planar_linked_plane = plane;
12585 crtc_state->active_planes |= BIT(linked->id);
12586 crtc_state->update_planes |= BIT(linked->id);
12587 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
12588 linked->base.name, plane->base.name);
12590 /* Copy parameters to slave plane */
12591 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
12592 linked_state->color_ctl = plane_state->color_ctl;
12593 linked_state->view = plane_state->view;
12594 memcpy(linked_state->color_plane, plane_state->color_plane,
12595 sizeof(linked_state->color_plane));
12597 intel_plane_copy_uapi_to_hw_state(linked_state, plane_state);
12598 linked_state->uapi.src = plane_state->uapi.src;
12599 linked_state->uapi.dst = plane_state->uapi.dst;
12601 if (icl_is_hdr_plane(dev_priv, plane->id)) {
12602 if (linked->id == PLANE_SPRITE5)
12603 plane_state->cus_ctl |= PLANE_CUS_PLANE_7;
12604 else if (linked->id == PLANE_SPRITE4)
12605 plane_state->cus_ctl |= PLANE_CUS_PLANE_6;
12607 MISSING_CASE(linked->id);
12614 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
12616 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
12617 struct intel_atomic_state *state =
12618 to_intel_atomic_state(new_crtc_state->uapi.state);
12619 const struct intel_crtc_state *old_crtc_state =
12620 intel_atomic_get_old_crtc_state(state, crtc);
12622 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
12625 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
12627 const struct drm_display_mode *adjusted_mode =
12628 &crtc_state->hw.adjusted_mode;
12630 if (!crtc_state->hw.enable)
12633 return DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8,
12634 adjusted_mode->crtc_clock);
12637 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
12638 const struct intel_cdclk_state *cdclk_state)
12640 const struct drm_display_mode *adjusted_mode =
12641 &crtc_state->hw.adjusted_mode;
12643 if (!crtc_state->hw.enable)
12646 return DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8,
12647 cdclk_state->logical.cdclk);
12650 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
12652 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12653 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12654 const struct drm_display_mode *adjusted_mode =
12655 &crtc_state->hw.adjusted_mode;
12658 if (!crtc_state->hw.enable)
12661 linetime_wm = DIV_ROUND_UP(adjusted_mode->crtc_htotal * 1000 * 8,
12662 crtc_state->pixel_rate);
12664 /* Display WA #1135: BXT:ALL GLK:ALL */
12665 if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled)
12668 return linetime_wm;
12671 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
12672 struct intel_crtc *crtc)
12674 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12675 struct intel_crtc_state *crtc_state =
12676 intel_atomic_get_new_crtc_state(state, crtc);
12677 const struct intel_cdclk_state *cdclk_state;
12679 if (INTEL_GEN(dev_priv) >= 9)
12680 crtc_state->linetime = skl_linetime_wm(crtc_state);
12682 crtc_state->linetime = hsw_linetime_wm(crtc_state);
12684 if (!hsw_crtc_supports_ips(crtc))
12687 cdclk_state = intel_atomic_get_cdclk_state(state);
12688 if (IS_ERR(cdclk_state))
12689 return PTR_ERR(cdclk_state);
12691 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
12697 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
12698 struct intel_crtc *crtc)
12700 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12701 struct intel_crtc_state *crtc_state =
12702 intel_atomic_get_new_crtc_state(state, crtc);
12703 bool mode_changed = needs_modeset(crtc_state);
12706 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
12707 mode_changed && !crtc_state->hw.active)
12708 crtc_state->update_wm_post = true;
12710 if (mode_changed && crtc_state->hw.enable &&
12711 dev_priv->display.crtc_compute_clock &&
12712 !drm_WARN_ON(&dev_priv->drm, crtc_state->shared_dpll)) {
12713 ret = dev_priv->display.crtc_compute_clock(crtc, crtc_state);
12719 * May need to update pipe gamma enable bits
12720 * when C8 planes are getting enabled/disabled.
12722 if (c8_planes_changed(crtc_state))
12723 crtc_state->uapi.color_mgmt_changed = true;
12725 if (mode_changed || crtc_state->update_pipe ||
12726 crtc_state->uapi.color_mgmt_changed) {
12727 ret = intel_color_check(crtc_state);
12732 if (dev_priv->display.compute_pipe_wm) {
12733 ret = dev_priv->display.compute_pipe_wm(crtc_state);
12735 drm_dbg_kms(&dev_priv->drm,
12736 "Target pipe watermarks are invalid\n");
12741 if (dev_priv->display.compute_intermediate_wm) {
12742 if (drm_WARN_ON(&dev_priv->drm,
12743 !dev_priv->display.compute_pipe_wm))
12747 * Calculate 'intermediate' watermarks that satisfy both the
12748 * old state and the new state. We can program these
12751 ret = dev_priv->display.compute_intermediate_wm(crtc_state);
12753 drm_dbg_kms(&dev_priv->drm,
12754 "No valid intermediate pipe watermarks are possible\n");
12759 if (INTEL_GEN(dev_priv) >= 9) {
12760 if (mode_changed || crtc_state->update_pipe) {
12761 ret = skl_update_scaler_crtc(crtc_state);
12766 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
12771 if (HAS_IPS(dev_priv)) {
12772 ret = hsw_compute_ips_config(crtc_state);
12777 if (INTEL_GEN(dev_priv) >= 9 ||
12778 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
12779 ret = hsw_compute_linetime_wm(state, crtc);
12788 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
12790 struct intel_connector *connector;
12791 struct drm_connector_list_iter conn_iter;
12793 drm_connector_list_iter_begin(dev, &conn_iter);
12794 for_each_intel_connector_iter(connector, &conn_iter) {
12795 if (connector->base.state->crtc)
12796 drm_connector_put(&connector->base);
12798 if (connector->base.encoder) {
12799 connector->base.state->best_encoder =
12800 connector->base.encoder;
12801 connector->base.state->crtc =
12802 connector->base.encoder->crtc;
12804 drm_connector_get(&connector->base);
12806 connector->base.state->best_encoder = NULL;
12807 connector->base.state->crtc = NULL;
12810 drm_connector_list_iter_end(&conn_iter);
12814 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
12815 struct intel_crtc_state *pipe_config)
12817 struct drm_connector *connector = conn_state->connector;
12818 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
12819 const struct drm_display_info *info = &connector->display_info;
12822 switch (conn_state->max_bpc) {
12839 if (bpp < pipe_config->pipe_bpp) {
12840 drm_dbg_kms(&i915->drm,
12841 "[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
12842 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
12843 connector->base.id, connector->name,
12844 bpp, 3 * info->bpc,
12845 3 * conn_state->max_requested_bpc,
12846 pipe_config->pipe_bpp);
12848 pipe_config->pipe_bpp = bpp;
12855 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
12856 struct intel_crtc_state *pipe_config)
12858 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12859 struct drm_atomic_state *state = pipe_config->uapi.state;
12860 struct drm_connector *connector;
12861 struct drm_connector_state *connector_state;
12864 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
12865 IS_CHERRYVIEW(dev_priv)))
12867 else if (INTEL_GEN(dev_priv) >= 5)
12872 pipe_config->pipe_bpp = bpp;
12874 /* Clamp display bpp to connector max bpp */
12875 for_each_new_connector_in_state(state, connector, connector_state, i) {
12878 if (connector_state->crtc != &crtc->base)
12881 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
12889 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
12891 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
12892 "type: 0x%x flags: 0x%x\n",
12894 mode->crtc_hdisplay, mode->crtc_hsync_start,
12895 mode->crtc_hsync_end, mode->crtc_htotal,
12896 mode->crtc_vdisplay, mode->crtc_vsync_start,
12897 mode->crtc_vsync_end, mode->crtc_vtotal,
12898 mode->type, mode->flags);
12902 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
12903 const char *id, unsigned int lane_count,
12904 const struct intel_link_m_n *m_n)
12906 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
12908 drm_dbg_kms(&i915->drm,
12909 "%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
12911 m_n->gmch_m, m_n->gmch_n,
12912 m_n->link_m, m_n->link_n, m_n->tu);
12916 intel_dump_infoframe(struct drm_i915_private *dev_priv,
12917 const union hdmi_infoframe *frame)
12919 if (!drm_debug_enabled(DRM_UT_KMS))
12922 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
12925 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
12927 static const char * const output_type_str[] = {
12928 OUTPUT_TYPE(UNUSED),
12929 OUTPUT_TYPE(ANALOG),
12933 OUTPUT_TYPE(TVOUT),
12939 OUTPUT_TYPE(DP_MST),
12944 static void snprintf_output_types(char *buf, size_t len,
12945 unsigned int output_types)
12952 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
12955 if ((output_types & BIT(i)) == 0)
12958 r = snprintf(str, len, "%s%s",
12959 str != buf ? "," : "", output_type_str[i]);
12965 output_types &= ~BIT(i);
12968 WARN_ON_ONCE(output_types != 0);
12971 static const char * const output_format_str[] = {
12972 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
12973 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
12974 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
12975 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
12978 static const char *output_formats(enum intel_output_format format)
12980 if (format >= ARRAY_SIZE(output_format_str))
12981 format = INTEL_OUTPUT_FORMAT_INVALID;
12982 return output_format_str[format];
12985 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
12987 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
12988 struct drm_i915_private *i915 = to_i915(plane->base.dev);
12989 const struct drm_framebuffer *fb = plane_state->hw.fb;
12990 struct drm_format_name_buf format_name;
12993 drm_dbg_kms(&i915->drm,
12994 "[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
12995 plane->base.base.id, plane->base.name,
12996 yesno(plane_state->uapi.visible));
13000 drm_dbg_kms(&i915->drm,
13001 "[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s, visible: %s\n",
13002 plane->base.base.id, plane->base.name,
13003 fb->base.id, fb->width, fb->height,
13004 drm_get_format_name(fb->format->format, &format_name),
13005 yesno(plane_state->uapi.visible));
13006 drm_dbg_kms(&i915->drm, "\trotation: 0x%x, scaler: %d\n",
13007 plane_state->hw.rotation, plane_state->scaler_id);
13008 if (plane_state->uapi.visible)
13009 drm_dbg_kms(&i915->drm,
13010 "\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
13011 DRM_RECT_FP_ARG(&plane_state->uapi.src),
13012 DRM_RECT_ARG(&plane_state->uapi.dst));
13015 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
13016 struct intel_atomic_state *state,
13017 const char *context)
13019 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
13020 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13021 const struct intel_plane_state *plane_state;
13022 struct intel_plane *plane;
13026 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s] enable: %s %s\n",
13027 crtc->base.base.id, crtc->base.name,
13028 yesno(pipe_config->hw.enable), context);
13030 if (!pipe_config->hw.enable)
13033 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
13034 drm_dbg_kms(&dev_priv->drm,
13035 "active: %s, output_types: %s (0x%x), output format: %s\n",
13036 yesno(pipe_config->hw.active),
13037 buf, pipe_config->output_types,
13038 output_formats(pipe_config->output_format));
13040 drm_dbg_kms(&dev_priv->drm,
13041 "cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
13042 transcoder_name(pipe_config->cpu_transcoder),
13043 pipe_config->pipe_bpp, pipe_config->dither);
13045 if (pipe_config->has_pch_encoder)
13046 intel_dump_m_n_config(pipe_config, "fdi",
13047 pipe_config->fdi_lanes,
13048 &pipe_config->fdi_m_n);
13050 if (intel_crtc_has_dp_encoder(pipe_config)) {
13051 intel_dump_m_n_config(pipe_config, "dp m_n",
13052 pipe_config->lane_count, &pipe_config->dp_m_n);
13053 if (pipe_config->has_drrs)
13054 intel_dump_m_n_config(pipe_config, "dp m2_n2",
13055 pipe_config->lane_count,
13056 &pipe_config->dp_m2_n2);
13059 drm_dbg_kms(&dev_priv->drm,
13060 "audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
13061 pipe_config->has_audio, pipe_config->has_infoframe,
13062 pipe_config->infoframes.enable);
13064 if (pipe_config->infoframes.enable &
13065 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
13066 drm_dbg_kms(&dev_priv->drm, "GCP: 0x%x\n",
13067 pipe_config->infoframes.gcp);
13068 if (pipe_config->infoframes.enable &
13069 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
13070 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
13071 if (pipe_config->infoframes.enable &
13072 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
13073 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
13074 if (pipe_config->infoframes.enable &
13075 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
13076 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
13078 drm_dbg_kms(&dev_priv->drm, "requested mode:\n");
13079 drm_mode_debug_printmodeline(&pipe_config->hw.mode);
13080 drm_dbg_kms(&dev_priv->drm, "adjusted mode:\n");
13081 drm_mode_debug_printmodeline(&pipe_config->hw.adjusted_mode);
13082 intel_dump_crtc_timings(&pipe_config->hw.adjusted_mode);
13083 drm_dbg_kms(&dev_priv->drm,
13084 "port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
13085 pipe_config->port_clock,
13086 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
13087 pipe_config->pixel_rate);
13089 drm_dbg_kms(&dev_priv->drm, "linetime: %d, ips linetime: %d\n",
13090 pipe_config->linetime, pipe_config->ips_linetime);
13092 if (INTEL_GEN(dev_priv) >= 9)
13093 drm_dbg_kms(&dev_priv->drm,
13094 "num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
13096 pipe_config->scaler_state.scaler_users,
13097 pipe_config->scaler_state.scaler_id);
13099 if (HAS_GMCH(dev_priv))
13100 drm_dbg_kms(&dev_priv->drm,
13101 "gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
13102 pipe_config->gmch_pfit.control,
13103 pipe_config->gmch_pfit.pgm_ratios,
13104 pipe_config->gmch_pfit.lvds_border_bits);
13106 drm_dbg_kms(&dev_priv->drm,
13107 "pch pfit: pos: 0x%08x, size: 0x%08x, %s, force thru: %s\n",
13108 pipe_config->pch_pfit.pos,
13109 pipe_config->pch_pfit.size,
13110 enableddisabled(pipe_config->pch_pfit.enabled),
13111 yesno(pipe_config->pch_pfit.force_thru));
13113 drm_dbg_kms(&dev_priv->drm, "ips: %i, double wide: %i\n",
13114 pipe_config->ips_enabled, pipe_config->double_wide);
13116 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
13118 if (IS_CHERRYVIEW(dev_priv))
13119 drm_dbg_kms(&dev_priv->drm,
13120 "cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
13121 pipe_config->cgm_mode, pipe_config->gamma_mode,
13122 pipe_config->gamma_enable, pipe_config->csc_enable);
13124 drm_dbg_kms(&dev_priv->drm,
13125 "csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
13126 pipe_config->csc_mode, pipe_config->gamma_mode,
13127 pipe_config->gamma_enable, pipe_config->csc_enable);
13129 drm_dbg_kms(&dev_priv->drm, "MST master transcoder: %s\n",
13130 transcoder_name(pipe_config->mst_master_transcoder));
13136 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
13137 if (plane->pipe == crtc->pipe)
13138 intel_dump_plane_state(plane_state);
13142 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
13144 struct drm_device *dev = state->base.dev;
13145 struct drm_connector *connector;
13146 struct drm_connector_list_iter conn_iter;
13147 unsigned int used_ports = 0;
13148 unsigned int used_mst_ports = 0;
13152 * We're going to peek into connector->state,
13153 * hence connection_mutex must be held.
13155 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
13158 * Walk the connector list instead of the encoder
13159 * list to detect the problem on ddi platforms
13160 * where there's just one encoder per digital port.
13162 drm_connector_list_iter_begin(dev, &conn_iter);
13163 drm_for_each_connector_iter(connector, &conn_iter) {
13164 struct drm_connector_state *connector_state;
13165 struct intel_encoder *encoder;
13168 drm_atomic_get_new_connector_state(&state->base,
13170 if (!connector_state)
13171 connector_state = connector->state;
13173 if (!connector_state->best_encoder)
13176 encoder = to_intel_encoder(connector_state->best_encoder);
13178 drm_WARN_ON(dev, !connector_state->crtc);
13180 switch (encoder->type) {
13181 case INTEL_OUTPUT_DDI:
13182 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
13184 /* else, fall through */
13185 case INTEL_OUTPUT_DP:
13186 case INTEL_OUTPUT_HDMI:
13187 case INTEL_OUTPUT_EDP:
13188 /* the same port mustn't appear more than once */
13189 if (used_ports & BIT(encoder->port))
13192 used_ports |= BIT(encoder->port);
13194 case INTEL_OUTPUT_DP_MST:
13196 1 << encoder->port;
13202 drm_connector_list_iter_end(&conn_iter);
13204 /* can't mix MST and SST/HDMI on the same port */
13205 if (used_ports & used_mst_ports)
13212 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_crtc_state *crtc_state)
13214 intel_crtc_copy_color_blobs(crtc_state);
13218 intel_crtc_copy_uapi_to_hw_state(struct intel_crtc_state *crtc_state)
13220 crtc_state->hw.enable = crtc_state->uapi.enable;
13221 crtc_state->hw.active = crtc_state->uapi.active;
13222 crtc_state->hw.mode = crtc_state->uapi.mode;
13223 crtc_state->hw.adjusted_mode = crtc_state->uapi.adjusted_mode;
13224 intel_crtc_copy_uapi_to_hw_state_nomodeset(crtc_state);
13227 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state)
13229 crtc_state->uapi.enable = crtc_state->hw.enable;
13230 crtc_state->uapi.active = crtc_state->hw.active;
13231 WARN_ON(drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0);
13233 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode;
13235 /* copy color blobs to uapi */
13236 drm_property_replace_blob(&crtc_state->uapi.degamma_lut,
13237 crtc_state->hw.degamma_lut);
13238 drm_property_replace_blob(&crtc_state->uapi.gamma_lut,
13239 crtc_state->hw.gamma_lut);
13240 drm_property_replace_blob(&crtc_state->uapi.ctm,
13241 crtc_state->hw.ctm);
13245 intel_crtc_prepare_cleared_state(struct intel_crtc_state *crtc_state)
13247 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
13248 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13249 struct intel_crtc_state *saved_state;
13251 saved_state = intel_crtc_state_alloc(crtc);
13255 /* free the old crtc_state->hw members */
13256 intel_crtc_free_hw_state(crtc_state);
13258 /* FIXME: before the switch to atomic started, a new pipe_config was
13259 * kzalloc'd. Code that depends on any field being zero should be
13260 * fixed, so that the crtc_state can be safely duplicated. For now,
13261 * only fields that are know to not cause problems are preserved. */
13263 saved_state->uapi = crtc_state->uapi;
13264 saved_state->scaler_state = crtc_state->scaler_state;
13265 saved_state->shared_dpll = crtc_state->shared_dpll;
13266 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
13267 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
13268 sizeof(saved_state->icl_port_dplls));
13269 saved_state->crc_enabled = crtc_state->crc_enabled;
13270 if (IS_G4X(dev_priv) ||
13271 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13272 saved_state->wm = crtc_state->wm;
13274 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
13275 kfree(saved_state);
13277 intel_crtc_copy_uapi_to_hw_state(crtc_state);
13283 intel_modeset_pipe_config(struct intel_crtc_state *pipe_config)
13285 struct drm_crtc *crtc = pipe_config->uapi.crtc;
13286 struct drm_atomic_state *state = pipe_config->uapi.state;
13287 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
13288 struct drm_connector *connector;
13289 struct drm_connector_state *connector_state;
13290 int base_bpp, ret, i;
13293 pipe_config->cpu_transcoder =
13294 (enum transcoder) to_intel_crtc(crtc)->pipe;
13297 * Sanitize sync polarity flags based on requested ones. If neither
13298 * positive or negative polarity is requested, treat this as meaning
13299 * negative polarity.
13301 if (!(pipe_config->hw.adjusted_mode.flags &
13302 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
13303 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
13305 if (!(pipe_config->hw.adjusted_mode.flags &
13306 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
13307 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
13309 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
13314 base_bpp = pipe_config->pipe_bpp;
13317 * Determine the real pipe dimensions. Note that stereo modes can
13318 * increase the actual pipe size due to the frame doubling and
13319 * insertion of additional space for blanks between the frame. This
13320 * is stored in the crtc timings. We use the requested mode to do this
13321 * computation to clearly distinguish it from the adjusted mode, which
13322 * can be changed by the connectors in the below retry loop.
13324 drm_mode_get_hv_timing(&pipe_config->hw.mode,
13325 &pipe_config->pipe_src_w,
13326 &pipe_config->pipe_src_h);
13328 for_each_new_connector_in_state(state, connector, connector_state, i) {
13329 struct intel_encoder *encoder =
13330 to_intel_encoder(connector_state->best_encoder);
13332 if (connector_state->crtc != crtc)
13335 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
13336 drm_dbg_kms(&i915->drm,
13337 "rejecting invalid cloning configuration\n");
13342 * Determine output_types before calling the .compute_config()
13343 * hooks so that the hooks can use this information safely.
13345 if (encoder->compute_output_type)
13346 pipe_config->output_types |=
13347 BIT(encoder->compute_output_type(encoder, pipe_config,
13350 pipe_config->output_types |= BIT(encoder->type);
13354 /* Ensure the port clock defaults are reset when retrying. */
13355 pipe_config->port_clock = 0;
13356 pipe_config->pixel_multiplier = 1;
13358 /* Fill in default crtc timings, allow encoders to overwrite them. */
13359 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
13360 CRTC_STEREO_DOUBLE);
13362 /* Pass our mode to the connectors and the CRTC to give them a chance to
13363 * adjust it according to limitations or connector properties, and also
13364 * a chance to reject the mode entirely.
13366 for_each_new_connector_in_state(state, connector, connector_state, i) {
13367 struct intel_encoder *encoder =
13368 to_intel_encoder(connector_state->best_encoder);
13370 if (connector_state->crtc != crtc)
13373 ret = encoder->compute_config(encoder, pipe_config,
13376 if (ret != -EDEADLK)
13377 drm_dbg_kms(&i915->drm,
13378 "Encoder config failure: %d\n",
13384 /* Set default port clock if not overwritten by the encoder. Needs to be
13385 * done afterwards in case the encoder adjusts the mode. */
13386 if (!pipe_config->port_clock)
13387 pipe_config->port_clock = pipe_config->hw.adjusted_mode.crtc_clock
13388 * pipe_config->pixel_multiplier;
13390 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
13391 if (ret == -EDEADLK)
13394 drm_dbg_kms(&i915->drm, "CRTC fixup failed\n");
13398 if (ret == RETRY) {
13399 if (drm_WARN(&i915->drm, !retry,
13400 "loop in pipe configuration computation\n"))
13403 drm_dbg_kms(&i915->drm, "CRTC bw constrained, retrying\n");
13405 goto encoder_retry;
13408 /* Dithering seems to not pass-through bits correctly when it should, so
13409 * only enable it on 6bpc panels and when its not a compliance
13410 * test requesting 6bpc video pattern.
13412 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
13413 !pipe_config->dither_force_disable;
13414 drm_dbg_kms(&i915->drm,
13415 "hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
13416 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
13419 * Make drm_calc_timestamping_constants in
13420 * drm_atomic_helper_update_legacy_modeset_state() happy
13422 pipe_config->uapi.adjusted_mode = pipe_config->hw.adjusted_mode;
13428 intel_modeset_pipe_config_late(struct intel_crtc_state *crtc_state)
13430 struct intel_atomic_state *state =
13431 to_intel_atomic_state(crtc_state->uapi.state);
13432 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
13433 struct drm_connector_state *conn_state;
13434 struct drm_connector *connector;
13437 for_each_new_connector_in_state(&state->base, connector,
13439 struct intel_encoder *encoder =
13440 to_intel_encoder(conn_state->best_encoder);
13443 if (conn_state->crtc != &crtc->base ||
13444 !encoder->compute_config_late)
13447 ret = encoder->compute_config_late(encoder, crtc_state,
13456 bool intel_fuzzy_clock_check(int clock1, int clock2)
13460 if (clock1 == clock2)
13463 if (!clock1 || !clock2)
13466 diff = abs(clock1 - clock2);
13468 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
13475 intel_compare_m_n(unsigned int m, unsigned int n,
13476 unsigned int m2, unsigned int n2,
13479 if (m == m2 && n == n2)
13482 if (exact || !m || !n || !m2 || !n2)
13485 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
13492 } else if (n < n2) {
13502 return intel_fuzzy_clock_check(m, m2);
13506 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
13507 const struct intel_link_m_n *m2_n2,
13510 return m_n->tu == m2_n2->tu &&
13511 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
13512 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
13513 intel_compare_m_n(m_n->link_m, m_n->link_n,
13514 m2_n2->link_m, m2_n2->link_n, exact);
13518 intel_compare_infoframe(const union hdmi_infoframe *a,
13519 const union hdmi_infoframe *b)
13521 return memcmp(a, b, sizeof(*a)) == 0;
13525 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
13526 bool fastset, const char *name,
13527 const union hdmi_infoframe *a,
13528 const union hdmi_infoframe *b)
13531 if (!drm_debug_enabled(DRM_UT_KMS))
13534 drm_dbg_kms(&dev_priv->drm,
13535 "fastset mismatch in %s infoframe\n", name);
13536 drm_dbg_kms(&dev_priv->drm, "expected:\n");
13537 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
13538 drm_dbg_kms(&dev_priv->drm, "found:\n");
13539 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
13541 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
13542 drm_err(&dev_priv->drm, "expected:\n");
13543 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
13544 drm_err(&dev_priv->drm, "found:\n");
13545 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
13549 static void __printf(4, 5)
13550 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
13551 const char *name, const char *format, ...)
13553 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
13554 struct va_format vaf;
13557 va_start(args, format);
13562 drm_dbg_kms(&i915->drm,
13563 "[CRTC:%d:%s] fastset mismatch in %s %pV\n",
13564 crtc->base.base.id, crtc->base.name, name, &vaf);
13566 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
13567 crtc->base.base.id, crtc->base.name, name, &vaf);
13572 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
13574 if (i915_modparams.fastboot != -1)
13575 return i915_modparams.fastboot;
13577 /* Enable fastboot by default on Skylake and newer */
13578 if (INTEL_GEN(dev_priv) >= 9)
13581 /* Enable fastboot by default on VLV and CHV */
13582 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13585 /* Disabled by default on all others */
13590 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
13591 const struct intel_crtc_state *pipe_config,
13594 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
13595 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
13598 bool fixup_inherited = fastset &&
13599 (current_config->hw.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
13600 !(pipe_config->hw.mode.private_flags & I915_MODE_FLAG_INHERITED);
13602 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
13603 drm_dbg_kms(&dev_priv->drm,
13604 "initial modeset and fastboot not set\n");
13608 #define PIPE_CONF_CHECK_X(name) do { \
13609 if (current_config->name != pipe_config->name) { \
13610 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13611 "(expected 0x%08x, found 0x%08x)", \
13612 current_config->name, \
13613 pipe_config->name); \
13618 #define PIPE_CONF_CHECK_I(name) do { \
13619 if (current_config->name != pipe_config->name) { \
13620 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13621 "(expected %i, found %i)", \
13622 current_config->name, \
13623 pipe_config->name); \
13628 #define PIPE_CONF_CHECK_BOOL(name) do { \
13629 if (current_config->name != pipe_config->name) { \
13630 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13631 "(expected %s, found %s)", \
13632 yesno(current_config->name), \
13633 yesno(pipe_config->name)); \
13639 * Checks state where we only read out the enabling, but not the entire
13640 * state itself (like full infoframes or ELD for audio). These states
13641 * require a full modeset on bootup to fix up.
13643 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
13644 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
13645 PIPE_CONF_CHECK_BOOL(name); \
13647 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13648 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
13649 yesno(current_config->name), \
13650 yesno(pipe_config->name)); \
13655 #define PIPE_CONF_CHECK_P(name) do { \
13656 if (current_config->name != pipe_config->name) { \
13657 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13658 "(expected %p, found %p)", \
13659 current_config->name, \
13660 pipe_config->name); \
13665 #define PIPE_CONF_CHECK_M_N(name) do { \
13666 if (!intel_compare_link_m_n(¤t_config->name, \
13667 &pipe_config->name,\
13669 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13670 "(expected tu %i gmch %i/%i link %i/%i, " \
13671 "found tu %i, gmch %i/%i link %i/%i)", \
13672 current_config->name.tu, \
13673 current_config->name.gmch_m, \
13674 current_config->name.gmch_n, \
13675 current_config->name.link_m, \
13676 current_config->name.link_n, \
13677 pipe_config->name.tu, \
13678 pipe_config->name.gmch_m, \
13679 pipe_config->name.gmch_n, \
13680 pipe_config->name.link_m, \
13681 pipe_config->name.link_n); \
13686 /* This is required for BDW+ where there is only one set of registers for
13687 * switching between high and low RR.
13688 * This macro can be used whenever a comparison has to be made between one
13689 * hw state and multiple sw state variables.
13691 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
13692 if (!intel_compare_link_m_n(¤t_config->name, \
13693 &pipe_config->name, !fastset) && \
13694 !intel_compare_link_m_n(¤t_config->alt_name, \
13695 &pipe_config->name, !fastset)) { \
13696 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13697 "(expected tu %i gmch %i/%i link %i/%i, " \
13698 "or tu %i gmch %i/%i link %i/%i, " \
13699 "found tu %i, gmch %i/%i link %i/%i)", \
13700 current_config->name.tu, \
13701 current_config->name.gmch_m, \
13702 current_config->name.gmch_n, \
13703 current_config->name.link_m, \
13704 current_config->name.link_n, \
13705 current_config->alt_name.tu, \
13706 current_config->alt_name.gmch_m, \
13707 current_config->alt_name.gmch_n, \
13708 current_config->alt_name.link_m, \
13709 current_config->alt_name.link_n, \
13710 pipe_config->name.tu, \
13711 pipe_config->name.gmch_m, \
13712 pipe_config->name.gmch_n, \
13713 pipe_config->name.link_m, \
13714 pipe_config->name.link_n); \
13719 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
13720 if ((current_config->name ^ pipe_config->name) & (mask)) { \
13721 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13722 "(%x) (expected %i, found %i)", \
13724 current_config->name & (mask), \
13725 pipe_config->name & (mask)); \
13730 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
13731 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
13732 pipe_config_mismatch(fastset, crtc, __stringify(name), \
13733 "(expected %i, found %i)", \
13734 current_config->name, \
13735 pipe_config->name); \
13740 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
13741 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
13742 &pipe_config->infoframes.name)) { \
13743 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
13744 ¤t_config->infoframes.name, \
13745 &pipe_config->infoframes.name); \
13750 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
13751 if (current_config->name1 != pipe_config->name1) { \
13752 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
13753 "(expected %i, found %i, won't compare lut values)", \
13754 current_config->name1, \
13755 pipe_config->name1); \
13758 if (!intel_color_lut_equal(current_config->name2, \
13759 pipe_config->name2, pipe_config->name1, \
13760 bit_precision)) { \
13761 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
13762 "hw_state doesn't match sw_state"); \
13768 #define PIPE_CONF_QUIRK(quirk) \
13769 ((current_config->quirks | pipe_config->quirks) & (quirk))
13771 PIPE_CONF_CHECK_I(cpu_transcoder);
13773 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
13774 PIPE_CONF_CHECK_I(fdi_lanes);
13775 PIPE_CONF_CHECK_M_N(fdi_m_n);
13777 PIPE_CONF_CHECK_I(lane_count);
13778 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
13780 if (INTEL_GEN(dev_priv) < 8) {
13781 PIPE_CONF_CHECK_M_N(dp_m_n);
13783 if (current_config->has_drrs)
13784 PIPE_CONF_CHECK_M_N(dp_m2_n2);
13786 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
13788 PIPE_CONF_CHECK_X(output_types);
13790 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hdisplay);
13791 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_htotal);
13792 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_start);
13793 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_end);
13794 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_start);
13795 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_end);
13797 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vdisplay);
13798 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vtotal);
13799 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_start);
13800 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_end);
13801 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_start);
13802 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_end);
13804 PIPE_CONF_CHECK_I(pixel_multiplier);
13805 PIPE_CONF_CHECK_I(output_format);
13806 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
13807 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
13808 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13809 PIPE_CONF_CHECK_BOOL(limited_color_range);
13811 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
13812 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
13813 PIPE_CONF_CHECK_BOOL(has_infoframe);
13814 PIPE_CONF_CHECK_BOOL(fec_enable);
13816 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
13818 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13819 DRM_MODE_FLAG_INTERLACE);
13821 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
13822 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13823 DRM_MODE_FLAG_PHSYNC);
13824 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13825 DRM_MODE_FLAG_NHSYNC);
13826 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13827 DRM_MODE_FLAG_PVSYNC);
13828 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
13829 DRM_MODE_FLAG_NVSYNC);
13832 PIPE_CONF_CHECK_X(gmch_pfit.control);
13833 /* pfit ratios are autocomputed by the hw on gen4+ */
13834 if (INTEL_GEN(dev_priv) < 4)
13835 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
13836 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
13839 * Changing the EDP transcoder input mux
13840 * (A_ONOFF vs. A_ON) requires a full modeset.
13842 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
13845 PIPE_CONF_CHECK_I(pipe_src_w);
13846 PIPE_CONF_CHECK_I(pipe_src_h);
13848 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
13849 if (current_config->pch_pfit.enabled) {
13850 PIPE_CONF_CHECK_X(pch_pfit.pos);
13851 PIPE_CONF_CHECK_X(pch_pfit.size);
13854 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
13855 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
13857 PIPE_CONF_CHECK_X(gamma_mode);
13858 if (IS_CHERRYVIEW(dev_priv))
13859 PIPE_CONF_CHECK_X(cgm_mode);
13861 PIPE_CONF_CHECK_X(csc_mode);
13862 PIPE_CONF_CHECK_BOOL(gamma_enable);
13863 PIPE_CONF_CHECK_BOOL(csc_enable);
13865 PIPE_CONF_CHECK_I(linetime);
13866 PIPE_CONF_CHECK_I(ips_linetime);
13868 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
13870 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
13873 PIPE_CONF_CHECK_BOOL(double_wide);
13875 PIPE_CONF_CHECK_P(shared_dpll);
13876 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
13877 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
13878 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
13879 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
13880 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
13881 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
13882 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
13883 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
13884 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
13885 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
13886 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
13887 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
13888 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
13889 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
13890 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
13891 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
13892 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
13893 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
13894 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
13895 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
13896 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
13897 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
13898 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
13899 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
13900 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
13901 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
13902 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
13903 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
13904 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
13905 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
13906 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
13908 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
13909 PIPE_CONF_CHECK_X(dsi_pll.div);
13911 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
13912 PIPE_CONF_CHECK_I(pipe_bpp);
13914 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
13915 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
13917 PIPE_CONF_CHECK_I(min_voltage_level);
13919 PIPE_CONF_CHECK_X(infoframes.enable);
13920 PIPE_CONF_CHECK_X(infoframes.gcp);
13921 PIPE_CONF_CHECK_INFOFRAME(avi);
13922 PIPE_CONF_CHECK_INFOFRAME(spd);
13923 PIPE_CONF_CHECK_INFOFRAME(hdmi);
13924 PIPE_CONF_CHECK_INFOFRAME(drm);
13926 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
13927 PIPE_CONF_CHECK_I(master_transcoder);
13929 PIPE_CONF_CHECK_I(dsc.compression_enable);
13930 PIPE_CONF_CHECK_I(dsc.dsc_split);
13931 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
13933 PIPE_CONF_CHECK_I(mst_master_transcoder);
13935 #undef PIPE_CONF_CHECK_X
13936 #undef PIPE_CONF_CHECK_I
13937 #undef PIPE_CONF_CHECK_BOOL
13938 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
13939 #undef PIPE_CONF_CHECK_P
13940 #undef PIPE_CONF_CHECK_FLAGS
13941 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
13942 #undef PIPE_CONF_CHECK_COLOR_LUT
13943 #undef PIPE_CONF_QUIRK
13948 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
13949 const struct intel_crtc_state *pipe_config)
13951 if (pipe_config->has_pch_encoder) {
13952 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
13953 &pipe_config->fdi_m_n);
13954 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
13957 * FDI already provided one idea for the dotclock.
13958 * Yell if the encoder disagrees.
13960 drm_WARN(&dev_priv->drm,
13961 !intel_fuzzy_clock_check(fdi_dotclock, dotclock),
13962 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
13963 fdi_dotclock, dotclock);
13967 static void verify_wm_state(struct intel_crtc *crtc,
13968 struct intel_crtc_state *new_crtc_state)
13970 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13971 struct skl_hw_state {
13972 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
13973 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
13974 struct skl_pipe_wm wm;
13976 struct skl_pipe_wm *sw_wm;
13977 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
13978 u8 hw_enabled_slices;
13979 const enum pipe pipe = crtc->pipe;
13980 int plane, level, max_level = ilk_wm_max_level(dev_priv);
13982 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->hw.active)
13985 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
13989 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
13990 sw_wm = &new_crtc_state->wm.skl.optimal;
13992 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
13994 hw_enabled_slices = intel_enabled_dbuf_slices_mask(dev_priv);
13996 if (INTEL_GEN(dev_priv) >= 11 &&
13997 hw_enabled_slices != dev_priv->enabled_dbuf_slices_mask)
13998 drm_err(&dev_priv->drm,
13999 "mismatch in DBUF Slices (expected 0x%x, got 0x%x)\n",
14000 dev_priv->enabled_dbuf_slices_mask,
14001 hw_enabled_slices);
14004 for_each_universal_plane(dev_priv, pipe, plane) {
14005 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
14007 hw_plane_wm = &hw->wm.planes[plane];
14008 sw_plane_wm = &sw_wm->planes[plane];
14011 for (level = 0; level <= max_level; level++) {
14012 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
14013 &sw_plane_wm->wm[level]))
14016 drm_err(&dev_priv->drm,
14017 "mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
14018 pipe_name(pipe), plane + 1, level,
14019 sw_plane_wm->wm[level].plane_en,
14020 sw_plane_wm->wm[level].plane_res_b,
14021 sw_plane_wm->wm[level].plane_res_l,
14022 hw_plane_wm->wm[level].plane_en,
14023 hw_plane_wm->wm[level].plane_res_b,
14024 hw_plane_wm->wm[level].plane_res_l);
14027 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
14028 &sw_plane_wm->trans_wm)) {
14029 drm_err(&dev_priv->drm,
14030 "mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
14031 pipe_name(pipe), plane + 1,
14032 sw_plane_wm->trans_wm.plane_en,
14033 sw_plane_wm->trans_wm.plane_res_b,
14034 sw_plane_wm->trans_wm.plane_res_l,
14035 hw_plane_wm->trans_wm.plane_en,
14036 hw_plane_wm->trans_wm.plane_res_b,
14037 hw_plane_wm->trans_wm.plane_res_l);
14041 hw_ddb_entry = &hw->ddb_y[plane];
14042 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
14044 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
14045 drm_err(&dev_priv->drm,
14046 "mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
14047 pipe_name(pipe), plane + 1,
14048 sw_ddb_entry->start, sw_ddb_entry->end,
14049 hw_ddb_entry->start, hw_ddb_entry->end);
14055 * If the cursor plane isn't active, we may not have updated it's ddb
14056 * allocation. In that case since the ddb allocation will be updated
14057 * once the plane becomes visible, we can skip this check
14060 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
14062 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
14063 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
14066 for (level = 0; level <= max_level; level++) {
14067 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
14068 &sw_plane_wm->wm[level]))
14071 drm_err(&dev_priv->drm,
14072 "mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
14073 pipe_name(pipe), level,
14074 sw_plane_wm->wm[level].plane_en,
14075 sw_plane_wm->wm[level].plane_res_b,
14076 sw_plane_wm->wm[level].plane_res_l,
14077 hw_plane_wm->wm[level].plane_en,
14078 hw_plane_wm->wm[level].plane_res_b,
14079 hw_plane_wm->wm[level].plane_res_l);
14082 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
14083 &sw_plane_wm->trans_wm)) {
14084 drm_err(&dev_priv->drm,
14085 "mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
14087 sw_plane_wm->trans_wm.plane_en,
14088 sw_plane_wm->trans_wm.plane_res_b,
14089 sw_plane_wm->trans_wm.plane_res_l,
14090 hw_plane_wm->trans_wm.plane_en,
14091 hw_plane_wm->trans_wm.plane_res_b,
14092 hw_plane_wm->trans_wm.plane_res_l);
14096 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
14097 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
14099 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
14100 drm_err(&dev_priv->drm,
14101 "mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
14103 sw_ddb_entry->start, sw_ddb_entry->end,
14104 hw_ddb_entry->start, hw_ddb_entry->end);
14112 verify_connector_state(struct intel_atomic_state *state,
14113 struct intel_crtc *crtc)
14115 struct drm_connector *connector;
14116 struct drm_connector_state *new_conn_state;
14119 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
14120 struct drm_encoder *encoder = connector->encoder;
14121 struct intel_crtc_state *crtc_state = NULL;
14123 if (new_conn_state->crtc != &crtc->base)
14127 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
14129 intel_connector_verify_state(crtc_state, new_conn_state);
14131 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
14132 "connector's atomic encoder doesn't match legacy encoder\n");
14137 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
14139 struct intel_encoder *encoder;
14140 struct drm_connector *connector;
14141 struct drm_connector_state *old_conn_state, *new_conn_state;
14144 for_each_intel_encoder(&dev_priv->drm, encoder) {
14145 bool enabled = false, found = false;
14148 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s]\n",
14149 encoder->base.base.id,
14150 encoder->base.name);
14152 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
14153 new_conn_state, i) {
14154 if (old_conn_state->best_encoder == &encoder->base)
14157 if (new_conn_state->best_encoder != &encoder->base)
14159 found = enabled = true;
14161 I915_STATE_WARN(new_conn_state->crtc !=
14162 encoder->base.crtc,
14163 "connector's crtc doesn't match encoder crtc\n");
14169 I915_STATE_WARN(!!encoder->base.crtc != enabled,
14170 "encoder's enabled state mismatch "
14171 "(expected %i, found %i)\n",
14172 !!encoder->base.crtc, enabled);
14174 if (!encoder->base.crtc) {
14177 active = encoder->get_hw_state(encoder, &pipe);
14178 I915_STATE_WARN(active,
14179 "encoder detached but still enabled on pipe %c.\n",
14186 verify_crtc_state(struct intel_crtc *crtc,
14187 struct intel_crtc_state *old_crtc_state,
14188 struct intel_crtc_state *new_crtc_state)
14190 struct drm_device *dev = crtc->base.dev;
14191 struct drm_i915_private *dev_priv = to_i915(dev);
14192 struct intel_encoder *encoder;
14193 struct intel_crtc_state *pipe_config = old_crtc_state;
14194 struct drm_atomic_state *state = old_crtc_state->uapi.state;
14197 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
14198 intel_crtc_free_hw_state(old_crtc_state);
14199 intel_crtc_state_reset(old_crtc_state, crtc);
14200 old_crtc_state->uapi.state = state;
14202 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s]\n", crtc->base.base.id,
14205 active = dev_priv->display.get_pipe_config(crtc, pipe_config);
14207 /* we keep both pipes enabled on 830 */
14208 if (IS_I830(dev_priv))
14209 active = new_crtc_state->hw.active;
14211 I915_STATE_WARN(new_crtc_state->hw.active != active,
14212 "crtc active state doesn't match with hw state "
14213 "(expected %i, found %i)\n",
14214 new_crtc_state->hw.active, active);
14216 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
14217 "transitional active state does not match atomic hw state "
14218 "(expected %i, found %i)\n",
14219 new_crtc_state->hw.active, crtc->active);
14221 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
14224 active = encoder->get_hw_state(encoder, &pipe);
14225 I915_STATE_WARN(active != new_crtc_state->hw.active,
14226 "[ENCODER:%i] active %i with crtc active %i\n",
14227 encoder->base.base.id, active,
14228 new_crtc_state->hw.active);
14230 I915_STATE_WARN(active && crtc->pipe != pipe,
14231 "Encoder connected to wrong pipe %c\n",
14235 encoder->get_config(encoder, pipe_config);
14238 intel_crtc_compute_pixel_rate(pipe_config);
14240 if (!new_crtc_state->hw.active)
14243 intel_pipe_config_sanity_check(dev_priv, pipe_config);
14245 if (!intel_pipe_config_compare(new_crtc_state,
14246 pipe_config, false)) {
14247 I915_STATE_WARN(1, "pipe state doesn't match!\n");
14248 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
14249 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
14254 intel_verify_planes(struct intel_atomic_state *state)
14256 struct intel_plane *plane;
14257 const struct intel_plane_state *plane_state;
14260 for_each_new_intel_plane_in_state(state, plane,
14262 assert_plane(plane, plane_state->planar_slave ||
14263 plane_state->uapi.visible);
14267 verify_single_dpll_state(struct drm_i915_private *dev_priv,
14268 struct intel_shared_dpll *pll,
14269 struct intel_crtc *crtc,
14270 struct intel_crtc_state *new_crtc_state)
14272 struct intel_dpll_hw_state dpll_hw_state;
14273 unsigned int crtc_mask;
14276 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
14278 drm_dbg_kms(&dev_priv->drm, "%s\n", pll->info->name);
14280 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
14282 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
14283 I915_STATE_WARN(!pll->on && pll->active_mask,
14284 "pll in active use but not on in sw tracking\n");
14285 I915_STATE_WARN(pll->on && !pll->active_mask,
14286 "pll is on but not used by any active crtc\n");
14287 I915_STATE_WARN(pll->on != active,
14288 "pll on state mismatch (expected %i, found %i)\n",
14293 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
14294 "more active pll users than references: %x vs %x\n",
14295 pll->active_mask, pll->state.crtc_mask);
14300 crtc_mask = drm_crtc_mask(&crtc->base);
14302 if (new_crtc_state->hw.active)
14303 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
14304 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
14305 pipe_name(crtc->pipe), pll->active_mask);
14307 I915_STATE_WARN(pll->active_mask & crtc_mask,
14308 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
14309 pipe_name(crtc->pipe), pll->active_mask);
14311 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
14312 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
14313 crtc_mask, pll->state.crtc_mask);
14315 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
14317 sizeof(dpll_hw_state)),
14318 "pll hw state mismatch\n");
14322 verify_shared_dpll_state(struct intel_crtc *crtc,
14323 struct intel_crtc_state *old_crtc_state,
14324 struct intel_crtc_state *new_crtc_state)
14326 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14328 if (new_crtc_state->shared_dpll)
14329 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
14331 if (old_crtc_state->shared_dpll &&
14332 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
14333 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
14334 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
14336 I915_STATE_WARN(pll->active_mask & crtc_mask,
14337 "pll active mismatch (didn't expect pipe %c in active mask)\n",
14338 pipe_name(crtc->pipe));
14339 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
14340 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
14341 pipe_name(crtc->pipe));
14346 intel_modeset_verify_crtc(struct intel_crtc *crtc,
14347 struct intel_atomic_state *state,
14348 struct intel_crtc_state *old_crtc_state,
14349 struct intel_crtc_state *new_crtc_state)
14351 if (!needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
14354 verify_wm_state(crtc, new_crtc_state);
14355 verify_connector_state(state, crtc);
14356 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
14357 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
14361 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
14365 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++)
14366 verify_single_dpll_state(dev_priv,
14367 &dev_priv->dpll.shared_dplls[i],
14372 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
14373 struct intel_atomic_state *state)
14375 verify_encoder_state(dev_priv, state);
14376 verify_connector_state(state, NULL);
14377 verify_disabled_dpll_state(dev_priv);
14381 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
14383 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
14384 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14385 const struct drm_display_mode *adjusted_mode =
14386 &crtc_state->hw.adjusted_mode;
14388 drm_calc_timestamping_constants(&crtc->base, adjusted_mode);
14391 * The scanline counter increments at the leading edge of hsync.
14393 * On most platforms it starts counting from vtotal-1 on the
14394 * first active line. That means the scanline counter value is
14395 * always one less than what we would expect. Ie. just after
14396 * start of vblank, which also occurs at start of hsync (on the
14397 * last active line), the scanline counter will read vblank_start-1.
14399 * On gen2 the scanline counter starts counting from 1 instead
14400 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
14401 * to keep the value positive), instead of adding one.
14403 * On HSW+ the behaviour of the scanline counter depends on the output
14404 * type. For DP ports it behaves like most other platforms, but on HDMI
14405 * there's an extra 1 line difference. So we need to add two instead of
14406 * one to the value.
14408 * On VLV/CHV DSI the scanline counter would appear to increment
14409 * approx. 1/3 of a scanline before start of vblank. Unfortunately
14410 * that means we can't tell whether we're in vblank or not while
14411 * we're on that particular line. We must still set scanline_offset
14412 * to 1 so that the vblank timestamps come out correct when we query
14413 * the scanline counter from within the vblank interrupt handler.
14414 * However if queried just before the start of vblank we'll get an
14415 * answer that's slightly in the future.
14417 if (IS_GEN(dev_priv, 2)) {
14420 vtotal = adjusted_mode->crtc_vtotal;
14421 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
14424 crtc->scanline_offset = vtotal - 1;
14425 } else if (HAS_DDI(dev_priv) &&
14426 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
14427 crtc->scanline_offset = 2;
14429 crtc->scanline_offset = 1;
14433 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
14435 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14436 struct intel_crtc_state *new_crtc_state;
14437 struct intel_crtc *crtc;
14440 if (!dev_priv->display.crtc_compute_clock)
14443 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14444 if (!needs_modeset(new_crtc_state))
14447 intel_release_shared_dplls(state, crtc);
14452 * This implements the workaround described in the "notes" section of the mode
14453 * set sequence documentation. When going from no pipes or single pipe to
14454 * multiple pipes, and planes are enabled after the pipe, we need to wait at
14455 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
14457 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
14459 struct intel_crtc_state *crtc_state;
14460 struct intel_crtc *crtc;
14461 struct intel_crtc_state *first_crtc_state = NULL;
14462 struct intel_crtc_state *other_crtc_state = NULL;
14463 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
14466 /* look at all crtc's that are going to be enabled in during modeset */
14467 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14468 if (!crtc_state->hw.active ||
14469 !needs_modeset(crtc_state))
14472 if (first_crtc_state) {
14473 other_crtc_state = crtc_state;
14476 first_crtc_state = crtc_state;
14477 first_pipe = crtc->pipe;
14481 /* No workaround needed? */
14482 if (!first_crtc_state)
14485 /* w/a possibly needed, check how many crtc's are already enabled. */
14486 for_each_intel_crtc(state->base.dev, crtc) {
14487 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
14488 if (IS_ERR(crtc_state))
14489 return PTR_ERR(crtc_state);
14491 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
14493 if (!crtc_state->hw.active ||
14494 needs_modeset(crtc_state))
14497 /* 2 or more enabled crtcs means no need for w/a */
14498 if (enabled_pipe != INVALID_PIPE)
14501 enabled_pipe = crtc->pipe;
14504 if (enabled_pipe != INVALID_PIPE)
14505 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
14506 else if (other_crtc_state)
14507 other_crtc_state->hsw_workaround_pipe = first_pipe;
14512 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
14515 const struct intel_crtc_state *crtc_state;
14516 struct intel_crtc *crtc;
14519 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14520 if (crtc_state->hw.active)
14521 active_pipes |= BIT(crtc->pipe);
14523 active_pipes &= ~BIT(crtc->pipe);
14526 return active_pipes;
14529 static int intel_modeset_checks(struct intel_atomic_state *state)
14531 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14534 state->modeset = true;
14535 state->active_pipes = intel_calc_active_pipes(state, dev_priv->active_pipes);
14537 state->active_pipe_changes = state->active_pipes ^ dev_priv->active_pipes;
14539 if (state->active_pipe_changes) {
14540 ret = _intel_atomic_lock_global_state(state);
14545 ret = intel_modeset_calc_cdclk(state);
14549 intel_modeset_clear_plls(state);
14551 if (IS_HASWELL(dev_priv))
14552 return hsw_mode_set_planes_workaround(state);
14558 * Handle calculation of various watermark data at the end of the atomic check
14559 * phase. The code here should be run after the per-crtc and per-plane 'check'
14560 * handlers to ensure that all derived state has been updated.
14562 static int calc_watermark_data(struct intel_atomic_state *state)
14564 struct drm_device *dev = state->base.dev;
14565 struct drm_i915_private *dev_priv = to_i915(dev);
14567 /* Is there platform-specific watermark information to calculate? */
14568 if (dev_priv->display.compute_global_watermarks)
14569 return dev_priv->display.compute_global_watermarks(state);
14574 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
14575 struct intel_crtc_state *new_crtc_state)
14577 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
14580 new_crtc_state->uapi.mode_changed = false;
14581 new_crtc_state->update_pipe = true;
14584 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
14585 struct intel_crtc_state *new_crtc_state)
14588 * If we're not doing the full modeset we want to
14589 * keep the current M/N values as they may be
14590 * sufficiently different to the computed values
14591 * to cause problems.
14593 * FIXME: should really copy more fuzzy state here
14595 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
14596 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
14597 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
14598 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
14601 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
14602 struct intel_crtc *crtc,
14605 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14606 struct intel_plane *plane;
14608 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
14609 struct intel_plane_state *plane_state;
14611 if ((plane_ids_mask & BIT(plane->id)) == 0)
14614 plane_state = intel_atomic_get_plane_state(state, plane);
14615 if (IS_ERR(plane_state))
14616 return PTR_ERR(plane_state);
14622 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
14624 /* See {hsw,vlv,ivb}_plane_ratio() */
14625 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
14626 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
14627 IS_IVYBRIDGE(dev_priv);
14630 static int intel_atomic_check_planes(struct intel_atomic_state *state,
14631 bool *need_cdclk_calc)
14633 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
14634 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14635 struct intel_plane_state *plane_state;
14636 struct intel_plane *plane;
14637 struct intel_crtc *crtc;
14640 ret = icl_add_linked_planes(state);
14644 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14645 ret = intel_plane_atomic_check(state, plane);
14647 drm_dbg_atomic(&dev_priv->drm,
14648 "[PLANE:%d:%s] atomic driver check failed\n",
14649 plane->base.base.id, plane->base.name);
14654 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14655 new_crtc_state, i) {
14656 u8 old_active_planes, new_active_planes;
14658 ret = icl_check_nv12_planes(new_crtc_state);
14663 * On some platforms the number of active planes affects
14664 * the planes' minimum cdclk calculation. Add such planes
14665 * to the state before we compute the minimum cdclk.
14667 if (!active_planes_affects_min_cdclk(dev_priv))
14670 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14671 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
14673 if (hweight8(old_active_planes) == hweight8(new_active_planes))
14676 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
14682 * active_planes bitmask has been updated, and potentially
14683 * affected planes are part of the state. We can now
14684 * compute the minimum cdclk for each plane.
14686 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
14687 ret = intel_plane_calc_min_cdclk(state, plane, need_cdclk_calc);
14695 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
14697 struct intel_crtc_state *crtc_state;
14698 struct intel_crtc *crtc;
14701 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
14702 int ret = intel_crtc_atomic_check(state, crtc);
14703 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
14705 drm_dbg_atomic(&i915->drm,
14706 "[CRTC:%d:%s] atomic driver check failed\n",
14707 crtc->base.base.id, crtc->base.name);
14715 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
14718 const struct intel_crtc_state *new_crtc_state;
14719 struct intel_crtc *crtc;
14722 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14723 if (new_crtc_state->hw.enable &&
14724 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
14725 needs_modeset(new_crtc_state))
14733 * intel_atomic_check - validate state object
14735 * @_state: state to validate
14737 static int intel_atomic_check(struct drm_device *dev,
14738 struct drm_atomic_state *_state)
14740 struct drm_i915_private *dev_priv = to_i915(dev);
14741 struct intel_atomic_state *state = to_intel_atomic_state(_state);
14742 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
14743 struct intel_cdclk_state *new_cdclk_state;
14744 struct intel_crtc *crtc;
14746 bool any_ms = false;
14748 /* Catch I915_MODE_FLAG_INHERITED */
14749 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14750 new_crtc_state, i) {
14751 if (new_crtc_state->uapi.mode.private_flags !=
14752 old_crtc_state->uapi.mode.private_flags)
14753 new_crtc_state->uapi.mode_changed = true;
14756 ret = drm_atomic_helper_check_modeset(dev, &state->base);
14760 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14761 new_crtc_state, i) {
14762 if (!needs_modeset(new_crtc_state)) {
14764 intel_crtc_copy_uapi_to_hw_state_nomodeset(new_crtc_state);
14769 ret = intel_crtc_prepare_cleared_state(new_crtc_state);
14773 if (!new_crtc_state->hw.enable)
14776 ret = intel_modeset_pipe_config(new_crtc_state);
14781 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14782 new_crtc_state, i) {
14783 if (!needs_modeset(new_crtc_state))
14786 ret = intel_modeset_pipe_config_late(new_crtc_state);
14790 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
14794 * Check if fastset is allowed by external dependencies like other
14795 * pipes and transcoders.
14797 * Right now it only forces a fullmodeset when the MST master
14798 * transcoder did not changed but the pipe of the master transcoder
14799 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
14800 * in case of port synced crtcs, if one of the synced crtcs
14801 * needs a full modeset, all other synced crtcs should be
14802 * forced a full modeset.
14804 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
14805 if (!new_crtc_state->hw.enable || needs_modeset(new_crtc_state))
14808 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
14809 enum transcoder master = new_crtc_state->mst_master_transcoder;
14811 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
14812 new_crtc_state->uapi.mode_changed = true;
14813 new_crtc_state->update_pipe = false;
14817 if (is_trans_port_sync_mode(new_crtc_state)) {
14818 u8 trans = new_crtc_state->sync_mode_slaves_mask;
14820 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
14821 trans |= BIT(new_crtc_state->master_transcoder);
14823 if (intel_cpu_transcoders_need_modeset(state, trans)) {
14824 new_crtc_state->uapi.mode_changed = true;
14825 new_crtc_state->update_pipe = false;
14830 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14831 new_crtc_state, i) {
14832 if (needs_modeset(new_crtc_state)) {
14837 if (!new_crtc_state->update_pipe)
14840 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
14843 if (any_ms && !check_digital_port_conflicts(state)) {
14844 drm_dbg_kms(&dev_priv->drm,
14845 "rejecting conflicting digital port configuration\n");
14850 ret = drm_dp_mst_atomic_check(&state->base);
14854 ret = intel_atomic_check_planes(state, &any_ms);
14858 new_cdclk_state = intel_atomic_get_new_cdclk_state(state);
14859 if (new_cdclk_state && new_cdclk_state->force_min_cdclk_changed)
14863 * distrust_bios_wm will force a full dbuf recomputation
14864 * but the hardware state will only get updated accordingly
14865 * if state->modeset==true. Hence distrust_bios_wm==true &&
14866 * state->modeset==false is an invalid combination which
14867 * would cause the hardware and software dbuf state to get
14868 * out of sync. We must prevent that.
14870 * FIXME clean up this mess and introduce better
14871 * state tracking for dbuf.
14873 if (dev_priv->wm.distrust_bios_wm)
14877 ret = intel_modeset_checks(state);
14882 ret = intel_atomic_check_crtcs(state);
14886 intel_fbc_choose_crtc(dev_priv, state);
14887 ret = calc_watermark_data(state);
14891 ret = intel_bw_atomic_check(state);
14895 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14896 new_crtc_state, i) {
14897 if (!needs_modeset(new_crtc_state) &&
14898 !new_crtc_state->update_pipe)
14901 intel_dump_pipe_config(new_crtc_state, state,
14902 needs_modeset(new_crtc_state) ?
14903 "[modeset]" : "[fastset]");
14909 if (ret == -EDEADLK)
14913 * FIXME would probably be nice to know which crtc specifically
14914 * caused the failure, in cases where we can pinpoint it.
14916 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
14918 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
14923 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
14925 return drm_atomic_helper_prepare_planes(state->base.dev,
14929 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
14931 struct drm_device *dev = crtc->base.dev;
14932 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
14934 if (!vblank->max_vblank_count)
14935 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
14937 return crtc->base.funcs->get_vblank_counter(&crtc->base);
14940 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
14941 struct intel_crtc_state *crtc_state)
14943 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14945 if (!IS_GEN(dev_priv, 2) || crtc_state->active_planes)
14946 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
14948 if (crtc_state->has_pch_encoder) {
14949 enum pipe pch_transcoder =
14950 intel_crtc_pch_transcoder(crtc);
14952 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
14956 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
14957 const struct intel_crtc_state *new_crtc_state)
14959 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
14960 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14963 * Update pipe size and adjust fitter if needed: the reason for this is
14964 * that in compute_mode_changes we check the native mode (not the pfit
14965 * mode) to see if we can flip rather than do a full mode set. In the
14966 * fastboot case, we'll flip, but if we don't update the pipesrc and
14967 * pfit state, we'll end up with a big fb scanned out into the wrong
14970 intel_set_pipe_src_size(new_crtc_state);
14972 /* on skylake this is done by detaching scalers */
14973 if (INTEL_GEN(dev_priv) >= 9) {
14974 skl_detach_scalers(new_crtc_state);
14976 if (new_crtc_state->pch_pfit.enabled)
14977 skl_pfit_enable(new_crtc_state);
14978 } else if (HAS_PCH_SPLIT(dev_priv)) {
14979 if (new_crtc_state->pch_pfit.enabled)
14980 ilk_pfit_enable(new_crtc_state);
14981 else if (old_crtc_state->pch_pfit.enabled)
14982 ilk_pfit_disable(old_crtc_state);
14986 * The register is supposedly single buffered so perhaps
14987 * not 100% correct to do this here. But SKL+ calculate
14988 * this based on the adjust pixel rate so pfit changes do
14989 * affect it and so it must be updated for fastsets.
14990 * HSW/BDW only really need this here for fastboot, after
14991 * that the value should not change without a full modeset.
14993 if (INTEL_GEN(dev_priv) >= 9 ||
14994 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14995 hsw_set_linetime_wm(new_crtc_state);
14997 if (INTEL_GEN(dev_priv) >= 11)
14998 icl_set_pipe_chicken(crtc);
15001 static void commit_pipe_config(struct intel_atomic_state *state,
15002 struct intel_crtc_state *old_crtc_state,
15003 struct intel_crtc_state *new_crtc_state)
15005 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
15006 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15007 bool modeset = needs_modeset(new_crtc_state);
15010 * During modesets pipe configuration was programmed as the
15011 * CRTC was enabled.
15014 if (new_crtc_state->uapi.color_mgmt_changed ||
15015 new_crtc_state->update_pipe)
15016 intel_color_commit(new_crtc_state);
15018 if (INTEL_GEN(dev_priv) >= 9)
15019 skl_detach_scalers(new_crtc_state);
15021 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
15022 bdw_set_pipemisc(new_crtc_state);
15024 if (new_crtc_state->update_pipe)
15025 intel_pipe_fastset(old_crtc_state, new_crtc_state);
15028 if (dev_priv->display.atomic_update_watermarks)
15029 dev_priv->display.atomic_update_watermarks(state, crtc);
15032 static void intel_update_crtc(struct intel_crtc *crtc,
15033 struct intel_atomic_state *state,
15034 struct intel_crtc_state *old_crtc_state,
15035 struct intel_crtc_state *new_crtc_state)
15037 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15038 bool modeset = needs_modeset(new_crtc_state);
15041 intel_crtc_update_active_timings(new_crtc_state);
15043 dev_priv->display.crtc_enable(state, crtc);
15045 /* vblanks work again, re-enable pipe CRC. */
15046 intel_crtc_enable_pipe_crc(crtc);
15048 if (new_crtc_state->preload_luts &&
15049 (new_crtc_state->uapi.color_mgmt_changed ||
15050 new_crtc_state->update_pipe))
15051 intel_color_load_luts(new_crtc_state);
15053 intel_pre_plane_update(state, crtc);
15055 if (new_crtc_state->update_pipe)
15056 intel_encoders_update_pipe(state, crtc);
15059 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
15060 intel_fbc_disable(crtc);
15062 intel_fbc_enable(state, crtc);
15064 /* Perform vblank evasion around commit operation */
15065 intel_pipe_update_start(new_crtc_state);
15067 commit_pipe_config(state, old_crtc_state, new_crtc_state);
15069 if (INTEL_GEN(dev_priv) >= 9)
15070 skl_update_planes_on_crtc(state, crtc);
15072 i9xx_update_planes_on_crtc(state, crtc);
15074 intel_pipe_update_end(new_crtc_state);
15077 * We usually enable FIFO underrun interrupts as part of the
15078 * CRTC enable sequence during modesets. But when we inherit a
15079 * valid pipe configuration from the BIOS we need to take care
15080 * of enabling them on the CRTC's first fastset.
15082 if (new_crtc_state->update_pipe && !modeset &&
15083 old_crtc_state->hw.mode.private_flags & I915_MODE_FLAG_INHERITED)
15084 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
15087 static struct intel_crtc *intel_get_slave_crtc(const struct intel_crtc_state *new_crtc_state)
15089 struct drm_i915_private *dev_priv = to_i915(new_crtc_state->uapi.crtc->dev);
15090 enum transcoder slave_transcoder;
15092 drm_WARN_ON(&dev_priv->drm,
15093 !is_power_of_2(new_crtc_state->sync_mode_slaves_mask));
15095 slave_transcoder = ffs(new_crtc_state->sync_mode_slaves_mask) - 1;
15096 return intel_get_crtc_for_pipe(dev_priv,
15097 (enum pipe)slave_transcoder);
15100 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
15101 struct intel_crtc_state *old_crtc_state,
15102 struct intel_crtc_state *new_crtc_state,
15103 struct intel_crtc *crtc)
15105 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15107 intel_crtc_disable_planes(state, crtc);
15110 * We need to disable pipe CRC before disabling the pipe,
15111 * or we race against vblank off.
15113 intel_crtc_disable_pipe_crc(crtc);
15115 dev_priv->display.crtc_disable(state, crtc);
15116 crtc->active = false;
15117 intel_fbc_disable(crtc);
15118 intel_disable_shared_dpll(old_crtc_state);
15120 /* FIXME unify this for all platforms */
15121 if (!new_crtc_state->hw.active &&
15122 !HAS_GMCH(dev_priv) &&
15123 dev_priv->display.initial_watermarks)
15124 dev_priv->display.initial_watermarks(state, crtc);
15127 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
15129 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
15130 struct intel_crtc *crtc;
15134 /* Only disable port sync and MST slaves */
15135 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15136 new_crtc_state, i) {
15137 if (!needs_modeset(new_crtc_state))
15140 if (!old_crtc_state->hw.active)
15143 /* In case of Transcoder port Sync master slave CRTCs can be
15144 * assigned in any order and we need to make sure that
15145 * slave CRTCs are disabled first and then master CRTC since
15146 * Slave vblanks are masked till Master Vblanks.
15148 if (!is_trans_port_sync_slave(old_crtc_state) &&
15149 !intel_dp_mst_is_slave_trans(old_crtc_state))
15152 intel_pre_plane_update(state, crtc);
15153 intel_old_crtc_state_disables(state, old_crtc_state,
15154 new_crtc_state, crtc);
15155 handled |= BIT(crtc->pipe);
15158 /* Disable everything else left on */
15159 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15160 new_crtc_state, i) {
15161 if (!needs_modeset(new_crtc_state) ||
15162 (handled & BIT(crtc->pipe)))
15165 intel_pre_plane_update(state, crtc);
15166 if (old_crtc_state->hw.active)
15167 intel_old_crtc_state_disables(state, old_crtc_state,
15168 new_crtc_state, crtc);
15172 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
15174 struct intel_crtc *crtc;
15175 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
15178 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15179 if (!new_crtc_state->hw.active)
15182 intel_update_crtc(crtc, state, old_crtc_state,
15187 static void intel_crtc_enable_trans_port_sync(struct intel_crtc *crtc,
15188 struct intel_atomic_state *state,
15189 struct intel_crtc_state *new_crtc_state)
15191 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15193 intel_crtc_update_active_timings(new_crtc_state);
15194 dev_priv->display.crtc_enable(state, crtc);
15195 intel_crtc_enable_pipe_crc(crtc);
15198 static void intel_set_dp_tp_ctl_normal(struct intel_crtc *crtc,
15199 struct intel_atomic_state *state)
15201 struct drm_connector *uninitialized_var(conn);
15202 struct drm_connector_state *conn_state;
15203 struct intel_dp *intel_dp;
15206 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
15207 if (conn_state->crtc == &crtc->base)
15210 intel_dp = intel_attached_dp(to_intel_connector(conn));
15211 intel_dp_stop_link_train(intel_dp);
15215 * TODO: This is only called from port sync and it is identical to what will be
15216 * executed again in intel_update_crtc() over port sync pipes
15218 static void intel_post_crtc_enable_updates(struct intel_crtc *crtc,
15219 struct intel_atomic_state *state)
15221 struct intel_crtc_state *new_crtc_state =
15222 intel_atomic_get_new_crtc_state(state, crtc);
15223 struct intel_crtc_state *old_crtc_state =
15224 intel_atomic_get_old_crtc_state(state, crtc);
15225 bool modeset = needs_modeset(new_crtc_state);
15227 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
15228 intel_fbc_disable(crtc);
15230 intel_fbc_enable(state, crtc);
15232 /* Perform vblank evasion around commit operation */
15233 intel_pipe_update_start(new_crtc_state);
15234 commit_pipe_config(state, old_crtc_state, new_crtc_state);
15235 skl_update_planes_on_crtc(state, crtc);
15236 intel_pipe_update_end(new_crtc_state);
15239 * We usually enable FIFO underrun interrupts as part of the
15240 * CRTC enable sequence during modesets. But when we inherit a
15241 * valid pipe configuration from the BIOS we need to take care
15242 * of enabling them on the CRTC's first fastset.
15244 if (new_crtc_state->update_pipe && !modeset &&
15245 old_crtc_state->hw.mode.private_flags & I915_MODE_FLAG_INHERITED)
15246 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
15249 static void intel_update_trans_port_sync_crtcs(struct intel_crtc *crtc,
15250 struct intel_atomic_state *state,
15251 struct intel_crtc_state *old_crtc_state,
15252 struct intel_crtc_state *new_crtc_state)
15254 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
15255 struct intel_crtc *slave_crtc = intel_get_slave_crtc(new_crtc_state);
15256 struct intel_crtc_state *new_slave_crtc_state =
15257 intel_atomic_get_new_crtc_state(state, slave_crtc);
15258 struct intel_crtc_state *old_slave_crtc_state =
15259 intel_atomic_get_old_crtc_state(state, slave_crtc);
15261 drm_WARN_ON(&i915->drm, !slave_crtc || !new_slave_crtc_state ||
15262 !old_slave_crtc_state);
15264 drm_dbg_kms(&i915->drm,
15265 "Updating Transcoder Port Sync Master CRTC = %d %s and Slave CRTC %d %s\n",
15266 crtc->base.base.id, crtc->base.name,
15267 slave_crtc->base.base.id, slave_crtc->base.name);
15269 /* Enable seq for slave with with DP_TP_CTL left Idle until the
15272 intel_crtc_enable_trans_port_sync(slave_crtc,
15274 new_slave_crtc_state);
15276 /* Enable seq for master with with DP_TP_CTL left Idle */
15277 intel_crtc_enable_trans_port_sync(crtc,
15281 /* Set Slave's DP_TP_CTL to Normal */
15282 intel_set_dp_tp_ctl_normal(slave_crtc,
15285 /* Set Master's DP_TP_CTL To Normal */
15286 usleep_range(200, 400);
15287 intel_set_dp_tp_ctl_normal(crtc,
15290 /* Now do the post crtc enable for all master and slaves */
15291 intel_post_crtc_enable_updates(slave_crtc,
15293 intel_post_crtc_enable_updates(crtc,
15297 static void icl_dbuf_slice_pre_update(struct intel_atomic_state *state)
15299 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15300 u8 hw_enabled_slices = dev_priv->enabled_dbuf_slices_mask;
15301 u8 required_slices = state->enabled_dbuf_slices_mask;
15302 u8 slices_union = hw_enabled_slices | required_slices;
15304 /* If 2nd DBuf slice required, enable it here */
15305 if (INTEL_GEN(dev_priv) >= 11 && slices_union != hw_enabled_slices)
15306 icl_dbuf_slices_update(dev_priv, slices_union);
15309 static void icl_dbuf_slice_post_update(struct intel_atomic_state *state)
15311 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15312 u8 hw_enabled_slices = dev_priv->enabled_dbuf_slices_mask;
15313 u8 required_slices = state->enabled_dbuf_slices_mask;
15315 /* If 2nd DBuf slice is no more required disable it */
15316 if (INTEL_GEN(dev_priv) >= 11 && required_slices != hw_enabled_slices)
15317 icl_dbuf_slices_update(dev_priv, required_slices);
15320 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
15322 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
15323 struct intel_crtc *crtc;
15324 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
15325 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
15326 u8 update_pipes = 0, modeset_pipes = 0;
15329 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15330 enum pipe pipe = crtc->pipe;
15332 if (!new_crtc_state->hw.active)
15335 /* ignore allocations for crtc's that have been turned off. */
15336 if (!needs_modeset(new_crtc_state)) {
15337 entries[pipe] = old_crtc_state->wm.skl.ddb;
15338 update_pipes |= BIT(pipe);
15340 modeset_pipes |= BIT(pipe);
15345 * Whenever the number of active pipes changes, we need to make sure we
15346 * update the pipes in the right order so that their ddb allocations
15347 * never overlap with each other between CRTC updates. Otherwise we'll
15348 * cause pipe underruns and other bad stuff.
15350 * So first lets enable all pipes that do not need a fullmodeset as
15351 * those don't have any external dependency.
15353 while (update_pipes) {
15354 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15355 new_crtc_state, i) {
15356 enum pipe pipe = crtc->pipe;
15358 if ((update_pipes & BIT(pipe)) == 0)
15361 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
15362 entries, I915_MAX_PIPES, pipe))
15365 entries[pipe] = new_crtc_state->wm.skl.ddb;
15366 update_pipes &= ~BIT(pipe);
15368 intel_update_crtc(crtc, state, old_crtc_state,
15372 * If this is an already active pipe, it's DDB changed,
15373 * and this isn't the last pipe that needs updating
15374 * then we need to wait for a vblank to pass for the
15375 * new ddb allocation to take effect.
15377 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
15378 &old_crtc_state->wm.skl.ddb) &&
15379 (update_pipes | modeset_pipes))
15380 intel_wait_for_vblank(dev_priv, pipe);
15385 * Enable all pipes that needs a modeset and do not depends on other
15388 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15389 new_crtc_state, i) {
15390 enum pipe pipe = crtc->pipe;
15392 if ((modeset_pipes & BIT(pipe)) == 0)
15395 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
15396 is_trans_port_sync_slave(new_crtc_state))
15399 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
15400 entries, I915_MAX_PIPES, pipe));
15402 entries[pipe] = new_crtc_state->wm.skl.ddb;
15403 modeset_pipes &= ~BIT(pipe);
15405 if (is_trans_port_sync_mode(new_crtc_state)) {
15406 struct intel_crtc *slave_crtc;
15408 intel_update_trans_port_sync_crtcs(crtc, state,
15412 slave_crtc = intel_get_slave_crtc(new_crtc_state);
15413 /* TODO: update entries[] of slave */
15414 modeset_pipes &= ~BIT(slave_crtc->pipe);
15417 intel_update_crtc(crtc, state, old_crtc_state,
15423 * Finally enable all pipes that needs a modeset and depends on
15424 * other pipes, right now it is only MST slaves as both port sync slave
15425 * and master are enabled together
15427 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15428 new_crtc_state, i) {
15429 enum pipe pipe = crtc->pipe;
15431 if ((modeset_pipes & BIT(pipe)) == 0)
15434 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
15435 entries, I915_MAX_PIPES, pipe));
15437 entries[pipe] = new_crtc_state->wm.skl.ddb;
15438 modeset_pipes &= ~BIT(pipe);
15440 intel_update_crtc(crtc, state, old_crtc_state, new_crtc_state);
15443 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
15447 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
15449 struct intel_atomic_state *state, *next;
15450 struct llist_node *freed;
15452 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
15453 llist_for_each_entry_safe(state, next, freed, freed)
15454 drm_atomic_state_put(&state->base);
15457 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
15459 struct drm_i915_private *dev_priv =
15460 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
15462 intel_atomic_helper_free_state(dev_priv);
15465 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
15467 struct wait_queue_entry wait_fence, wait_reset;
15468 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
15470 init_wait_entry(&wait_fence, 0);
15471 init_wait_entry(&wait_reset, 0);
15473 prepare_to_wait(&intel_state->commit_ready.wait,
15474 &wait_fence, TASK_UNINTERRUPTIBLE);
15475 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
15476 I915_RESET_MODESET),
15477 &wait_reset, TASK_UNINTERRUPTIBLE);
15480 if (i915_sw_fence_done(&intel_state->commit_ready) ||
15481 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
15486 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
15487 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
15488 I915_RESET_MODESET),
15492 static void intel_atomic_cleanup_work(struct work_struct *work)
15494 struct drm_atomic_state *state =
15495 container_of(work, struct drm_atomic_state, commit_work);
15496 struct drm_i915_private *i915 = to_i915(state->dev);
15498 drm_atomic_helper_cleanup_planes(&i915->drm, state);
15499 drm_atomic_helper_commit_cleanup_done(state);
15500 drm_atomic_state_put(state);
15502 intel_atomic_helper_free_state(i915);
15505 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
15507 struct drm_device *dev = state->base.dev;
15508 struct drm_i915_private *dev_priv = to_i915(dev);
15509 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
15510 struct intel_crtc *crtc;
15511 u64 put_domains[I915_MAX_PIPES] = {};
15512 intel_wakeref_t wakeref = 0;
15515 intel_atomic_commit_fence_wait(state);
15517 drm_atomic_helper_wait_for_dependencies(&state->base);
15519 if (state->modeset)
15520 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
15522 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15523 new_crtc_state, i) {
15524 if (needs_modeset(new_crtc_state) ||
15525 new_crtc_state->update_pipe) {
15527 put_domains[crtc->pipe] =
15528 modeset_get_crtc_power_domains(new_crtc_state);
15532 intel_commit_modeset_disables(state);
15534 /* FIXME: Eventually get rid of our crtc->config pointer */
15535 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15536 crtc->config = new_crtc_state;
15538 if (state->modeset) {
15539 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
15541 intel_set_cdclk_pre_plane_update(state);
15544 * SKL workaround: bspec recommends we disable the SAGV when we
15545 * have more then one pipe enabled
15547 if (!intel_can_enable_sagv(state))
15548 intel_disable_sagv(dev_priv);
15550 intel_modeset_verify_disabled(dev_priv, state);
15553 /* Complete the events for pipes that have now been disabled */
15554 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15555 bool modeset = needs_modeset(new_crtc_state);
15557 /* Complete events for now disable pipes here. */
15558 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
15559 spin_lock_irq(&dev->event_lock);
15560 drm_crtc_send_vblank_event(&crtc->base,
15561 new_crtc_state->uapi.event);
15562 spin_unlock_irq(&dev->event_lock);
15564 new_crtc_state->uapi.event = NULL;
15568 if (state->modeset)
15569 intel_encoders_update_prepare(state);
15571 /* Enable all new slices, we might need */
15572 if (state->modeset)
15573 icl_dbuf_slice_pre_update(state);
15575 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
15576 dev_priv->display.commit_modeset_enables(state);
15578 if (state->modeset) {
15579 intel_encoders_update_complete(state);
15581 intel_set_cdclk_post_plane_update(state);
15584 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
15585 * already, but still need the state for the delayed optimization. To
15587 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
15588 * - schedule that vblank worker _before_ calling hw_done
15589 * - at the start of commit_tail, cancel it _synchrously
15590 * - switch over to the vblank wait helper in the core after that since
15591 * we don't need out special handling any more.
15593 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
15595 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
15596 if (new_crtc_state->hw.active &&
15597 !needs_modeset(new_crtc_state) &&
15598 !new_crtc_state->preload_luts &&
15599 (new_crtc_state->uapi.color_mgmt_changed ||
15600 new_crtc_state->update_pipe))
15601 intel_color_load_luts(new_crtc_state);
15605 * Now that the vblank has passed, we can go ahead and program the
15606 * optimal watermarks on platforms that need two-step watermark
15609 * TODO: Move this (and other cleanup) to an async worker eventually.
15611 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
15612 new_crtc_state, i) {
15614 * Gen2 reports pipe underruns whenever all planes are disabled.
15615 * So re-enable underrun reporting after some planes get enabled.
15617 * We do this before .optimize_watermarks() so that we have a
15618 * chance of catching underruns with the intermediate watermarks
15619 * vs. the new plane configuration.
15621 if (IS_GEN(dev_priv, 2) && planes_enabling(old_crtc_state, new_crtc_state))
15622 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
15624 if (dev_priv->display.optimize_watermarks)
15625 dev_priv->display.optimize_watermarks(state, crtc);
15628 /* Disable all slices, we don't need */
15629 if (state->modeset)
15630 icl_dbuf_slice_post_update(state);
15632 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
15633 intel_post_plane_update(state, crtc);
15635 if (put_domains[i])
15636 modeset_put_power_domains(dev_priv, put_domains[i]);
15638 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
15641 /* Underruns don't always raise interrupts, so check manually */
15642 intel_check_cpu_fifo_underruns(dev_priv);
15643 intel_check_pch_fifo_underruns(dev_priv);
15645 if (state->modeset)
15646 intel_verify_planes(state);
15648 if (state->modeset && intel_can_enable_sagv(state))
15649 intel_enable_sagv(dev_priv);
15651 drm_atomic_helper_commit_hw_done(&state->base);
15653 if (state->modeset) {
15654 /* As one of the primary mmio accessors, KMS has a high
15655 * likelihood of triggering bugs in unclaimed access. After we
15656 * finish modesetting, see if an error has been flagged, and if
15657 * so enable debugging for the next modeset - and hope we catch
15660 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
15661 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
15663 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15666 * Defer the cleanup of the old state to a separate worker to not
15667 * impede the current task (userspace for blocking modesets) that
15668 * are executed inline. For out-of-line asynchronous modesets/flips,
15669 * deferring to a new worker seems overkill, but we would place a
15670 * schedule point (cond_resched()) here anyway to keep latencies
15673 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
15674 queue_work(system_highpri_wq, &state->base.commit_work);
15677 static void intel_atomic_commit_work(struct work_struct *work)
15679 struct intel_atomic_state *state =
15680 container_of(work, struct intel_atomic_state, base.commit_work);
15682 intel_atomic_commit_tail(state);
15685 static int __i915_sw_fence_call
15686 intel_atomic_commit_ready(struct i915_sw_fence *fence,
15687 enum i915_sw_fence_notify notify)
15689 struct intel_atomic_state *state =
15690 container_of(fence, struct intel_atomic_state, commit_ready);
15693 case FENCE_COMPLETE:
15694 /* we do blocking waits in the worker, nothing to do here */
15698 struct intel_atomic_helper *helper =
15699 &to_i915(state->base.dev)->atomic_helper;
15701 if (llist_add(&state->freed, &helper->free_list))
15702 schedule_work(&helper->free_work);
15707 return NOTIFY_DONE;
15710 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
15712 struct intel_plane_state *old_plane_state, *new_plane_state;
15713 struct intel_plane *plane;
15716 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
15717 new_plane_state, i)
15718 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
15719 to_intel_frontbuffer(new_plane_state->hw.fb),
15720 plane->frontbuffer_bit);
15723 static void assert_global_state_locked(struct drm_i915_private *dev_priv)
15725 struct intel_crtc *crtc;
15727 for_each_intel_crtc(&dev_priv->drm, crtc)
15728 drm_modeset_lock_assert_held(&crtc->base.mutex);
15731 static int intel_atomic_commit(struct drm_device *dev,
15732 struct drm_atomic_state *_state,
15735 struct intel_atomic_state *state = to_intel_atomic_state(_state);
15736 struct drm_i915_private *dev_priv = to_i915(dev);
15739 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
15741 drm_atomic_state_get(&state->base);
15742 i915_sw_fence_init(&state->commit_ready,
15743 intel_atomic_commit_ready);
15746 * The intel_legacy_cursor_update() fast path takes care
15747 * of avoiding the vblank waits for simple cursor
15748 * movement and flips. For cursor on/off and size changes,
15749 * we want to perform the vblank waits so that watermark
15750 * updates happen during the correct frames. Gen9+ have
15751 * double buffered watermarks and so shouldn't need this.
15753 * Unset state->legacy_cursor_update before the call to
15754 * drm_atomic_helper_setup_commit() because otherwise
15755 * drm_atomic_helper_wait_for_flip_done() is a noop and
15756 * we get FIFO underruns because we didn't wait
15759 * FIXME doing watermarks and fb cleanup from a vblank worker
15760 * (assuming we had any) would solve these problems.
15762 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
15763 struct intel_crtc_state *new_crtc_state;
15764 struct intel_crtc *crtc;
15767 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
15768 if (new_crtc_state->wm.need_postvbl_update ||
15769 new_crtc_state->update_wm_post)
15770 state->base.legacy_cursor_update = false;
15773 ret = intel_atomic_prepare_commit(state);
15775 drm_dbg_atomic(&dev_priv->drm,
15776 "Preparing state failed with %i\n", ret);
15777 i915_sw_fence_commit(&state->commit_ready);
15778 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15782 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
15784 ret = drm_atomic_helper_swap_state(&state->base, true);
15786 intel_atomic_swap_global_state(state);
15789 i915_sw_fence_commit(&state->commit_ready);
15791 drm_atomic_helper_cleanup_planes(dev, &state->base);
15792 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
15795 dev_priv->wm.distrust_bios_wm = false;
15796 intel_shared_dpll_swap_state(state);
15797 intel_atomic_track_fbs(state);
15799 if (state->global_state_changed) {
15800 assert_global_state_locked(dev_priv);
15802 dev_priv->active_pipes = state->active_pipes;
15805 drm_atomic_state_get(&state->base);
15806 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
15808 i915_sw_fence_commit(&state->commit_ready);
15809 if (nonblock && state->modeset) {
15810 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
15811 } else if (nonblock) {
15812 queue_work(dev_priv->flip_wq, &state->base.commit_work);
15814 if (state->modeset)
15815 flush_workqueue(dev_priv->modeset_wq);
15816 intel_atomic_commit_tail(state);
15822 struct wait_rps_boost {
15823 struct wait_queue_entry wait;
15825 struct drm_crtc *crtc;
15826 struct i915_request *request;
15829 static int do_rps_boost(struct wait_queue_entry *_wait,
15830 unsigned mode, int sync, void *key)
15832 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
15833 struct i915_request *rq = wait->request;
15836 * If we missed the vblank, but the request is already running it
15837 * is reasonable to assume that it will complete before the next
15838 * vblank without our intervention, so leave RPS alone.
15840 if (!i915_request_started(rq))
15841 intel_rps_boost(rq);
15842 i915_request_put(rq);
15844 drm_crtc_vblank_put(wait->crtc);
15846 list_del(&wait->wait.entry);
15851 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
15852 struct dma_fence *fence)
15854 struct wait_rps_boost *wait;
15856 if (!dma_fence_is_i915(fence))
15859 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
15862 if (drm_crtc_vblank_get(crtc))
15865 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
15867 drm_crtc_vblank_put(crtc);
15871 wait->request = to_request(dma_fence_get(fence));
15874 wait->wait.func = do_rps_boost;
15875 wait->wait.flags = 0;
15877 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
15880 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
15882 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
15883 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
15884 struct drm_framebuffer *fb = plane_state->hw.fb;
15885 struct i915_vma *vma;
15887 if (plane->id == PLANE_CURSOR &&
15888 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
15889 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
15890 const int align = intel_cursor_alignment(dev_priv);
15893 err = i915_gem_object_attach_phys(obj, align);
15898 vma = intel_pin_and_fence_fb_obj(fb,
15899 &plane_state->view,
15900 intel_plane_uses_fence(plane_state),
15901 &plane_state->flags);
15903 return PTR_ERR(vma);
15905 plane_state->vma = vma;
15910 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
15912 struct i915_vma *vma;
15914 vma = fetch_and_zero(&old_plane_state->vma);
15916 intel_unpin_fb_vma(vma, old_plane_state->flags);
15919 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
15921 struct i915_sched_attr attr = {
15922 .priority = I915_USER_PRIORITY(I915_PRIORITY_DISPLAY),
15925 i915_gem_object_wait_priority(obj, 0, &attr);
15929 * intel_prepare_plane_fb - Prepare fb for usage on plane
15930 * @_plane: drm plane to prepare for
15931 * @_new_plane_state: the plane state being prepared
15933 * Prepares a framebuffer for usage on a display plane. Generally this
15934 * involves pinning the underlying object and updating the frontbuffer tracking
15935 * bits. Some older platforms need special physical address handling for
15938 * Returns 0 on success, negative error code on failure.
15941 intel_prepare_plane_fb(struct drm_plane *_plane,
15942 struct drm_plane_state *_new_plane_state)
15944 struct intel_plane *plane = to_intel_plane(_plane);
15945 struct intel_plane_state *new_plane_state =
15946 to_intel_plane_state(_new_plane_state);
15947 struct intel_atomic_state *state =
15948 to_intel_atomic_state(new_plane_state->uapi.state);
15949 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
15950 const struct intel_plane_state *old_plane_state =
15951 intel_atomic_get_old_plane_state(state, plane);
15952 struct drm_i915_gem_object *obj = intel_fb_obj(new_plane_state->hw.fb);
15953 struct drm_i915_gem_object *old_obj = intel_fb_obj(old_plane_state->hw.fb);
15957 const struct intel_crtc_state *crtc_state =
15958 intel_atomic_get_new_crtc_state(state,
15959 to_intel_crtc(old_plane_state->hw.crtc));
15961 /* Big Hammer, we also need to ensure that any pending
15962 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
15963 * current scanout is retired before unpinning the old
15964 * framebuffer. Note that we rely on userspace rendering
15965 * into the buffer attached to the pipe they are waiting
15966 * on. If not, userspace generates a GPU hang with IPEHR
15967 * point to the MI_WAIT_FOR_EVENT.
15969 * This should only fail upon a hung GPU, in which case we
15970 * can safely continue.
15972 if (needs_modeset(crtc_state)) {
15973 ret = i915_sw_fence_await_reservation(&state->commit_ready,
15974 old_obj->base.resv, NULL,
15982 if (new_plane_state->uapi.fence) { /* explicit fencing */
15983 ret = i915_sw_fence_await_dma_fence(&state->commit_ready,
15984 new_plane_state->uapi.fence,
15985 I915_FENCE_TIMEOUT,
15994 ret = i915_gem_object_pin_pages(obj);
15998 ret = intel_plane_pin_fb(new_plane_state);
16000 i915_gem_object_unpin_pages(obj);
16004 fb_obj_bump_render_priority(obj);
16005 i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
16007 if (!new_plane_state->uapi.fence) { /* implicit fencing */
16008 struct dma_fence *fence;
16010 ret = i915_sw_fence_await_reservation(&state->commit_ready,
16011 obj->base.resv, NULL,
16012 false, I915_FENCE_TIMEOUT,
16017 fence = dma_resv_get_excl_rcu(obj->base.resv);
16019 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
16021 dma_fence_put(fence);
16024 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
16025 new_plane_state->uapi.fence);
16029 * We declare pageflips to be interactive and so merit a small bias
16030 * towards upclocking to deliver the frame on time. By only changing
16031 * the RPS thresholds to sample more regularly and aim for higher
16032 * clocks we can hopefully deliver low power workloads (like kodi)
16033 * that are not quite steady state without resorting to forcing
16034 * maximum clocks following a vblank miss (see do_rps_boost()).
16036 if (!state->rps_interactive) {
16037 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
16038 state->rps_interactive = true;
16044 intel_plane_unpin_fb(new_plane_state);
16050 * intel_cleanup_plane_fb - Cleans up an fb after plane use
16051 * @plane: drm plane to clean up for
16052 * @_old_plane_state: the state from the previous modeset
16054 * Cleans up a framebuffer that has just been removed from a plane.
16057 intel_cleanup_plane_fb(struct drm_plane *plane,
16058 struct drm_plane_state *_old_plane_state)
16060 struct intel_plane_state *old_plane_state =
16061 to_intel_plane_state(_old_plane_state);
16062 struct intel_atomic_state *state =
16063 to_intel_atomic_state(old_plane_state->uapi.state);
16064 struct drm_i915_private *dev_priv = to_i915(plane->dev);
16065 struct drm_i915_gem_object *obj = intel_fb_obj(old_plane_state->hw.fb);
16070 if (state->rps_interactive) {
16071 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
16072 state->rps_interactive = false;
16075 /* Should only be called after a successful intel_prepare_plane_fb()! */
16076 intel_plane_unpin_fb(old_plane_state);
16080 * intel_plane_destroy - destroy a plane
16081 * @plane: plane to destroy
16083 * Common destruction function for all types of planes (primary, cursor,
16086 void intel_plane_destroy(struct drm_plane *plane)
16088 drm_plane_cleanup(plane);
16089 kfree(to_intel_plane(plane));
16092 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
16093 u32 format, u64 modifier)
16095 switch (modifier) {
16096 case DRM_FORMAT_MOD_LINEAR:
16097 case I915_FORMAT_MOD_X_TILED:
16104 case DRM_FORMAT_C8:
16105 case DRM_FORMAT_RGB565:
16106 case DRM_FORMAT_XRGB1555:
16107 case DRM_FORMAT_XRGB8888:
16108 return modifier == DRM_FORMAT_MOD_LINEAR ||
16109 modifier == I915_FORMAT_MOD_X_TILED;
16115 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
16116 u32 format, u64 modifier)
16118 switch (modifier) {
16119 case DRM_FORMAT_MOD_LINEAR:
16120 case I915_FORMAT_MOD_X_TILED:
16127 case DRM_FORMAT_C8:
16128 case DRM_FORMAT_RGB565:
16129 case DRM_FORMAT_XRGB8888:
16130 case DRM_FORMAT_XBGR8888:
16131 case DRM_FORMAT_ARGB8888:
16132 case DRM_FORMAT_ABGR8888:
16133 case DRM_FORMAT_XRGB2101010:
16134 case DRM_FORMAT_XBGR2101010:
16135 case DRM_FORMAT_ARGB2101010:
16136 case DRM_FORMAT_ABGR2101010:
16137 case DRM_FORMAT_XBGR16161616F:
16138 return modifier == DRM_FORMAT_MOD_LINEAR ||
16139 modifier == I915_FORMAT_MOD_X_TILED;
16145 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
16146 u32 format, u64 modifier)
16148 return modifier == DRM_FORMAT_MOD_LINEAR &&
16149 format == DRM_FORMAT_ARGB8888;
16152 static const struct drm_plane_funcs i965_plane_funcs = {
16153 .update_plane = drm_atomic_helper_update_plane,
16154 .disable_plane = drm_atomic_helper_disable_plane,
16155 .destroy = intel_plane_destroy,
16156 .atomic_duplicate_state = intel_plane_duplicate_state,
16157 .atomic_destroy_state = intel_plane_destroy_state,
16158 .format_mod_supported = i965_plane_format_mod_supported,
16161 static const struct drm_plane_funcs i8xx_plane_funcs = {
16162 .update_plane = drm_atomic_helper_update_plane,
16163 .disable_plane = drm_atomic_helper_disable_plane,
16164 .destroy = intel_plane_destroy,
16165 .atomic_duplicate_state = intel_plane_duplicate_state,
16166 .atomic_destroy_state = intel_plane_destroy_state,
16167 .format_mod_supported = i8xx_plane_format_mod_supported,
16171 intel_legacy_cursor_update(struct drm_plane *_plane,
16172 struct drm_crtc *_crtc,
16173 struct drm_framebuffer *fb,
16174 int crtc_x, int crtc_y,
16175 unsigned int crtc_w, unsigned int crtc_h,
16176 u32 src_x, u32 src_y,
16177 u32 src_w, u32 src_h,
16178 struct drm_modeset_acquire_ctx *ctx)
16180 struct intel_plane *plane = to_intel_plane(_plane);
16181 struct intel_crtc *crtc = to_intel_crtc(_crtc);
16182 struct intel_plane_state *old_plane_state =
16183 to_intel_plane_state(plane->base.state);
16184 struct intel_plane_state *new_plane_state;
16185 struct intel_crtc_state *crtc_state =
16186 to_intel_crtc_state(crtc->base.state);
16187 struct intel_crtc_state *new_crtc_state;
16191 * When crtc is inactive or there is a modeset pending,
16192 * wait for it to complete in the slowpath
16194 if (!crtc_state->hw.active || needs_modeset(crtc_state) ||
16195 crtc_state->update_pipe)
16199 * Don't do an async update if there is an outstanding commit modifying
16200 * the plane. This prevents our async update's changes from getting
16201 * overridden by a previous synchronous update's state.
16203 if (old_plane_state->uapi.commit &&
16204 !try_wait_for_completion(&old_plane_state->uapi.commit->hw_done))
16208 * If any parameters change that may affect watermarks,
16209 * take the slowpath. Only changing fb or position should be
16212 if (old_plane_state->uapi.crtc != &crtc->base ||
16213 old_plane_state->uapi.src_w != src_w ||
16214 old_plane_state->uapi.src_h != src_h ||
16215 old_plane_state->uapi.crtc_w != crtc_w ||
16216 old_plane_state->uapi.crtc_h != crtc_h ||
16217 !old_plane_state->uapi.fb != !fb)
16220 new_plane_state = to_intel_plane_state(intel_plane_duplicate_state(&plane->base));
16221 if (!new_plane_state)
16224 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(&crtc->base));
16225 if (!new_crtc_state) {
16230 drm_atomic_set_fb_for_plane(&new_plane_state->uapi, fb);
16232 new_plane_state->uapi.src_x = src_x;
16233 new_plane_state->uapi.src_y = src_y;
16234 new_plane_state->uapi.src_w = src_w;
16235 new_plane_state->uapi.src_h = src_h;
16236 new_plane_state->uapi.crtc_x = crtc_x;
16237 new_plane_state->uapi.crtc_y = crtc_y;
16238 new_plane_state->uapi.crtc_w = crtc_w;
16239 new_plane_state->uapi.crtc_h = crtc_h;
16241 intel_plane_copy_uapi_to_hw_state(new_plane_state, new_plane_state);
16243 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
16244 old_plane_state, new_plane_state);
16248 ret = intel_plane_pin_fb(new_plane_state);
16252 intel_frontbuffer_flush(to_intel_frontbuffer(new_plane_state->hw.fb),
16254 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
16255 to_intel_frontbuffer(new_plane_state->hw.fb),
16256 plane->frontbuffer_bit);
16258 /* Swap plane state */
16259 plane->base.state = &new_plane_state->uapi;
16262 * We cannot swap crtc_state as it may be in use by an atomic commit or
16263 * page flip that's running simultaneously. If we swap crtc_state and
16264 * destroy the old state, we will cause a use-after-free there.
16266 * Only update active_planes, which is needed for our internal
16267 * bookkeeping. Either value will do the right thing when updating
16268 * planes atomically. If the cursor was part of the atomic update then
16269 * we would have taken the slowpath.
16271 crtc_state->active_planes = new_crtc_state->active_planes;
16273 if (new_plane_state->uapi.visible)
16274 intel_update_plane(plane, crtc_state, new_plane_state);
16276 intel_disable_plane(plane, crtc_state);
16278 intel_plane_unpin_fb(old_plane_state);
16281 if (new_crtc_state)
16282 intel_crtc_destroy_state(&crtc->base, &new_crtc_state->uapi);
16284 intel_plane_destroy_state(&plane->base, &new_plane_state->uapi);
16286 intel_plane_destroy_state(&plane->base, &old_plane_state->uapi);
16290 return drm_atomic_helper_update_plane(&plane->base, &crtc->base, fb,
16291 crtc_x, crtc_y, crtc_w, crtc_h,
16292 src_x, src_y, src_w, src_h, ctx);
16295 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
16296 .update_plane = intel_legacy_cursor_update,
16297 .disable_plane = drm_atomic_helper_disable_plane,
16298 .destroy = intel_plane_destroy,
16299 .atomic_duplicate_state = intel_plane_duplicate_state,
16300 .atomic_destroy_state = intel_plane_destroy_state,
16301 .format_mod_supported = intel_cursor_format_mod_supported,
16304 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
16305 enum i9xx_plane_id i9xx_plane)
16307 if (!HAS_FBC(dev_priv))
16310 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
16311 return i9xx_plane == PLANE_A; /* tied to pipe A */
16312 else if (IS_IVYBRIDGE(dev_priv))
16313 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
16314 i9xx_plane == PLANE_C;
16315 else if (INTEL_GEN(dev_priv) >= 4)
16316 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
16318 return i9xx_plane == PLANE_A;
16321 static struct intel_plane *
16322 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
16324 struct intel_plane *plane;
16325 const struct drm_plane_funcs *plane_funcs;
16326 unsigned int supported_rotations;
16327 const u32 *formats;
16331 if (INTEL_GEN(dev_priv) >= 9)
16332 return skl_universal_plane_create(dev_priv, pipe,
16335 plane = intel_plane_alloc();
16339 plane->pipe = pipe;
16341 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
16342 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
16344 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
16345 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
16347 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
16348 plane->id = PLANE_PRIMARY;
16349 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
16351 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
16352 if (plane->has_fbc) {
16353 struct intel_fbc *fbc = &dev_priv->fbc;
16355 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
16358 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16359 formats = vlv_primary_formats;
16360 num_formats = ARRAY_SIZE(vlv_primary_formats);
16361 } else if (INTEL_GEN(dev_priv) >= 4) {
16363 * WaFP16GammaEnabling:ivb
16364 * "Workaround : When using the 64-bit format, the plane
16365 * output on each color channel has one quarter amplitude.
16366 * It can be brought up to full amplitude by using pipe
16367 * gamma correction or pipe color space conversion to
16368 * multiply the plane output by four."
16370 * There is no dedicated plane gamma for the primary plane,
16371 * and using the pipe gamma/csc could conflict with other
16372 * planes, so we choose not to expose fp16 on IVB primary
16373 * planes. HSW primary planes no longer have this problem.
16375 if (IS_IVYBRIDGE(dev_priv)) {
16376 formats = ivb_primary_formats;
16377 num_formats = ARRAY_SIZE(ivb_primary_formats);
16379 formats = i965_primary_formats;
16380 num_formats = ARRAY_SIZE(i965_primary_formats);
16383 formats = i8xx_primary_formats;
16384 num_formats = ARRAY_SIZE(i8xx_primary_formats);
16387 if (INTEL_GEN(dev_priv) >= 4)
16388 plane_funcs = &i965_plane_funcs;
16390 plane_funcs = &i8xx_plane_funcs;
16392 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16393 plane->min_cdclk = vlv_plane_min_cdclk;
16394 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
16395 plane->min_cdclk = hsw_plane_min_cdclk;
16396 else if (IS_IVYBRIDGE(dev_priv))
16397 plane->min_cdclk = ivb_plane_min_cdclk;
16399 plane->min_cdclk = i9xx_plane_min_cdclk;
16401 plane->max_stride = i9xx_plane_max_stride;
16402 plane->update_plane = i9xx_update_plane;
16403 plane->disable_plane = i9xx_disable_plane;
16404 plane->get_hw_state = i9xx_plane_get_hw_state;
16405 plane->check_plane = i9xx_plane_check;
16407 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
16408 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
16410 formats, num_formats,
16411 i9xx_format_modifiers,
16412 DRM_PLANE_TYPE_PRIMARY,
16413 "primary %c", pipe_name(pipe));
16415 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
16417 formats, num_formats,
16418 i9xx_format_modifiers,
16419 DRM_PLANE_TYPE_PRIMARY,
16421 plane_name(plane->i9xx_plane));
16425 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
16426 supported_rotations =
16427 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
16428 DRM_MODE_REFLECT_X;
16429 } else if (INTEL_GEN(dev_priv) >= 4) {
16430 supported_rotations =
16431 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
16433 supported_rotations = DRM_MODE_ROTATE_0;
16436 if (INTEL_GEN(dev_priv) >= 4)
16437 drm_plane_create_rotation_property(&plane->base,
16439 supported_rotations);
16442 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
16444 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
16449 intel_plane_free(plane);
16451 return ERR_PTR(ret);
16454 static struct intel_plane *
16455 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
16458 struct intel_plane *cursor;
16461 cursor = intel_plane_alloc();
16462 if (IS_ERR(cursor))
16465 cursor->pipe = pipe;
16466 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
16467 cursor->id = PLANE_CURSOR;
16468 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
16470 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
16471 cursor->max_stride = i845_cursor_max_stride;
16472 cursor->update_plane = i845_update_cursor;
16473 cursor->disable_plane = i845_disable_cursor;
16474 cursor->get_hw_state = i845_cursor_get_hw_state;
16475 cursor->check_plane = i845_check_cursor;
16477 cursor->max_stride = i9xx_cursor_max_stride;
16478 cursor->update_plane = i9xx_update_cursor;
16479 cursor->disable_plane = i9xx_disable_cursor;
16480 cursor->get_hw_state = i9xx_cursor_get_hw_state;
16481 cursor->check_plane = i9xx_check_cursor;
16484 cursor->cursor.base = ~0;
16485 cursor->cursor.cntl = ~0;
16487 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
16488 cursor->cursor.size = ~0;
16490 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
16491 0, &intel_cursor_plane_funcs,
16492 intel_cursor_formats,
16493 ARRAY_SIZE(intel_cursor_formats),
16494 cursor_format_modifiers,
16495 DRM_PLANE_TYPE_CURSOR,
16496 "cursor %c", pipe_name(pipe));
16500 if (INTEL_GEN(dev_priv) >= 4)
16501 drm_plane_create_rotation_property(&cursor->base,
16503 DRM_MODE_ROTATE_0 |
16504 DRM_MODE_ROTATE_180);
16506 zpos = RUNTIME_INFO(dev_priv)->num_sprites[pipe] + 1;
16507 drm_plane_create_zpos_immutable_property(&cursor->base, zpos);
16509 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
16514 intel_plane_free(cursor);
16516 return ERR_PTR(ret);
16519 #define INTEL_CRTC_FUNCS \
16520 .gamma_set = drm_atomic_helper_legacy_gamma_set, \
16521 .set_config = drm_atomic_helper_set_config, \
16522 .destroy = intel_crtc_destroy, \
16523 .page_flip = drm_atomic_helper_page_flip, \
16524 .atomic_duplicate_state = intel_crtc_duplicate_state, \
16525 .atomic_destroy_state = intel_crtc_destroy_state, \
16526 .set_crc_source = intel_crtc_set_crc_source, \
16527 .verify_crc_source = intel_crtc_verify_crc_source, \
16528 .get_crc_sources = intel_crtc_get_crc_sources
16530 static const struct drm_crtc_funcs bdw_crtc_funcs = {
16533 .get_vblank_counter = g4x_get_vblank_counter,
16534 .enable_vblank = bdw_enable_vblank,
16535 .disable_vblank = bdw_disable_vblank,
16536 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
16539 static const struct drm_crtc_funcs ilk_crtc_funcs = {
16542 .get_vblank_counter = g4x_get_vblank_counter,
16543 .enable_vblank = ilk_enable_vblank,
16544 .disable_vblank = ilk_disable_vblank,
16545 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
16548 static const struct drm_crtc_funcs g4x_crtc_funcs = {
16551 .get_vblank_counter = g4x_get_vblank_counter,
16552 .enable_vblank = i965_enable_vblank,
16553 .disable_vblank = i965_disable_vblank,
16554 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
16557 static const struct drm_crtc_funcs i965_crtc_funcs = {
16560 .get_vblank_counter = i915_get_vblank_counter,
16561 .enable_vblank = i965_enable_vblank,
16562 .disable_vblank = i965_disable_vblank,
16563 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
16566 static const struct drm_crtc_funcs i915gm_crtc_funcs = {
16569 .get_vblank_counter = i915_get_vblank_counter,
16570 .enable_vblank = i915gm_enable_vblank,
16571 .disable_vblank = i915gm_disable_vblank,
16572 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
16575 static const struct drm_crtc_funcs i915_crtc_funcs = {
16578 .get_vblank_counter = i915_get_vblank_counter,
16579 .enable_vblank = i8xx_enable_vblank,
16580 .disable_vblank = i8xx_disable_vblank,
16581 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
16584 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
16587 /* no hw vblank counter */
16588 .enable_vblank = i8xx_enable_vblank,
16589 .disable_vblank = i8xx_disable_vblank,
16590 .get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
16593 static struct intel_crtc *intel_crtc_alloc(void)
16595 struct intel_crtc_state *crtc_state;
16596 struct intel_crtc *crtc;
16598 crtc = kzalloc(sizeof(*crtc), GFP_KERNEL);
16600 return ERR_PTR(-ENOMEM);
16602 crtc_state = intel_crtc_state_alloc(crtc);
16605 return ERR_PTR(-ENOMEM);
16608 crtc->base.state = &crtc_state->uapi;
16609 crtc->config = crtc_state;
16614 static void intel_crtc_free(struct intel_crtc *crtc)
16616 intel_crtc_destroy_state(&crtc->base, crtc->base.state);
16620 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv)
16622 struct intel_plane *plane;
16624 for_each_intel_plane(&dev_priv->drm, plane) {
16625 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
16628 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
16632 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
16634 struct intel_plane *primary, *cursor;
16635 const struct drm_crtc_funcs *funcs;
16636 struct intel_crtc *crtc;
16639 crtc = intel_crtc_alloc();
16641 return PTR_ERR(crtc);
16644 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[pipe];
16646 primary = intel_primary_plane_create(dev_priv, pipe);
16647 if (IS_ERR(primary)) {
16648 ret = PTR_ERR(primary);
16651 crtc->plane_ids_mask |= BIT(primary->id);
16653 for_each_sprite(dev_priv, pipe, sprite) {
16654 struct intel_plane *plane;
16656 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
16657 if (IS_ERR(plane)) {
16658 ret = PTR_ERR(plane);
16661 crtc->plane_ids_mask |= BIT(plane->id);
16664 cursor = intel_cursor_plane_create(dev_priv, pipe);
16665 if (IS_ERR(cursor)) {
16666 ret = PTR_ERR(cursor);
16669 crtc->plane_ids_mask |= BIT(cursor->id);
16671 if (HAS_GMCH(dev_priv)) {
16672 if (IS_CHERRYVIEW(dev_priv) ||
16673 IS_VALLEYVIEW(dev_priv) || IS_G4X(dev_priv))
16674 funcs = &g4x_crtc_funcs;
16675 else if (IS_GEN(dev_priv, 4))
16676 funcs = &i965_crtc_funcs;
16677 else if (IS_I945GM(dev_priv) || IS_I915GM(dev_priv))
16678 funcs = &i915gm_crtc_funcs;
16679 else if (IS_GEN(dev_priv, 3))
16680 funcs = &i915_crtc_funcs;
16682 funcs = &i8xx_crtc_funcs;
16684 if (INTEL_GEN(dev_priv) >= 8)
16685 funcs = &bdw_crtc_funcs;
16687 funcs = &ilk_crtc_funcs;
16690 ret = drm_crtc_init_with_planes(&dev_priv->drm, &crtc->base,
16691 &primary->base, &cursor->base,
16692 funcs, "pipe %c", pipe_name(pipe));
16696 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
16697 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
16698 dev_priv->pipe_to_crtc_mapping[pipe] = crtc;
16700 if (INTEL_GEN(dev_priv) < 9) {
16701 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
16703 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
16704 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
16705 dev_priv->plane_to_crtc_mapping[i9xx_plane] = crtc;
16708 intel_color_init(crtc);
16710 intel_crtc_crc_init(crtc);
16712 drm_WARN_ON(&dev_priv->drm, drm_crtc_index(&crtc->base) != crtc->pipe);
16717 intel_crtc_free(crtc);
16722 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
16723 struct drm_file *file)
16725 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
16726 struct drm_crtc *drmmode_crtc;
16727 struct intel_crtc *crtc;
16729 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
16733 crtc = to_intel_crtc(drmmode_crtc);
16734 pipe_from_crtc_id->pipe = crtc->pipe;
16739 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
16741 struct drm_device *dev = encoder->base.dev;
16742 struct intel_encoder *source_encoder;
16743 u32 possible_clones = 0;
16745 for_each_intel_encoder(dev, source_encoder) {
16746 if (encoders_cloneable(encoder, source_encoder))
16747 possible_clones |= drm_encoder_mask(&source_encoder->base);
16750 return possible_clones;
16753 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
16755 struct drm_device *dev = encoder->base.dev;
16756 struct intel_crtc *crtc;
16757 u32 possible_crtcs = 0;
16759 for_each_intel_crtc(dev, crtc) {
16760 if (encoder->pipe_mask & BIT(crtc->pipe))
16761 possible_crtcs |= drm_crtc_mask(&crtc->base);
16764 return possible_crtcs;
16767 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
16769 if (!IS_MOBILE(dev_priv))
16772 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
16775 if (IS_GEN(dev_priv, 5) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
16781 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
16783 if (INTEL_GEN(dev_priv) >= 9)
16786 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
16789 if (HAS_PCH_LPT_H(dev_priv) &&
16790 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
16793 /* DDI E can't be used if DDI A requires 4 lanes */
16794 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
16797 if (!dev_priv->vbt.int_crt_support)
16803 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
16808 if (HAS_DDI(dev_priv))
16811 * This w/a is needed at least on CPT/PPT, but to be sure apply it
16812 * everywhere where registers can be write protected.
16814 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16819 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
16820 u32 val = intel_de_read(dev_priv, PP_CONTROL(pps_idx));
16822 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
16823 intel_de_write(dev_priv, PP_CONTROL(pps_idx), val);
16827 static void intel_pps_init(struct drm_i915_private *dev_priv)
16829 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
16830 dev_priv->pps_mmio_base = PCH_PPS_BASE;
16831 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
16832 dev_priv->pps_mmio_base = VLV_PPS_BASE;
16834 dev_priv->pps_mmio_base = PPS_BASE;
16836 intel_pps_unlock_regs_wa(dev_priv);
16839 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
16841 struct intel_encoder *encoder;
16842 bool dpd_is_edp = false;
16844 intel_pps_init(dev_priv);
16846 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
16849 if (INTEL_GEN(dev_priv) >= 12) {
16850 intel_ddi_init(dev_priv, PORT_A);
16851 intel_ddi_init(dev_priv, PORT_B);
16852 intel_ddi_init(dev_priv, PORT_D);
16853 intel_ddi_init(dev_priv, PORT_E);
16854 intel_ddi_init(dev_priv, PORT_F);
16855 intel_ddi_init(dev_priv, PORT_G);
16856 intel_ddi_init(dev_priv, PORT_H);
16857 intel_ddi_init(dev_priv, PORT_I);
16858 icl_dsi_init(dev_priv);
16859 } else if (IS_ELKHARTLAKE(dev_priv)) {
16860 intel_ddi_init(dev_priv, PORT_A);
16861 intel_ddi_init(dev_priv, PORT_B);
16862 intel_ddi_init(dev_priv, PORT_C);
16863 intel_ddi_init(dev_priv, PORT_D);
16864 icl_dsi_init(dev_priv);
16865 } else if (IS_GEN(dev_priv, 11)) {
16866 intel_ddi_init(dev_priv, PORT_A);
16867 intel_ddi_init(dev_priv, PORT_B);
16868 intel_ddi_init(dev_priv, PORT_C);
16869 intel_ddi_init(dev_priv, PORT_D);
16870 intel_ddi_init(dev_priv, PORT_E);
16872 * On some ICL SKUs port F is not present. No strap bits for
16873 * this, so rely on VBT.
16874 * Work around broken VBTs on SKUs known to have no port F.
16876 if (IS_ICL_WITH_PORT_F(dev_priv) &&
16877 intel_bios_is_port_present(dev_priv, PORT_F))
16878 intel_ddi_init(dev_priv, PORT_F);
16880 icl_dsi_init(dev_priv);
16881 } else if (IS_GEN9_LP(dev_priv)) {
16883 * FIXME: Broxton doesn't support port detection via the
16884 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
16885 * detect the ports.
16887 intel_ddi_init(dev_priv, PORT_A);
16888 intel_ddi_init(dev_priv, PORT_B);
16889 intel_ddi_init(dev_priv, PORT_C);
16891 vlv_dsi_init(dev_priv);
16892 } else if (HAS_DDI(dev_priv)) {
16895 if (intel_ddi_crt_present(dev_priv))
16896 intel_crt_init(dev_priv);
16899 * Haswell uses DDI functions to detect digital outputs.
16900 * On SKL pre-D0 the strap isn't connected, so we assume
16903 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
16904 /* WaIgnoreDDIAStrap: skl */
16905 if (found || IS_GEN9_BC(dev_priv))
16906 intel_ddi_init(dev_priv, PORT_A);
16908 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
16910 found = intel_de_read(dev_priv, SFUSE_STRAP);
16912 if (found & SFUSE_STRAP_DDIB_DETECTED)
16913 intel_ddi_init(dev_priv, PORT_B);
16914 if (found & SFUSE_STRAP_DDIC_DETECTED)
16915 intel_ddi_init(dev_priv, PORT_C);
16916 if (found & SFUSE_STRAP_DDID_DETECTED)
16917 intel_ddi_init(dev_priv, PORT_D);
16918 if (found & SFUSE_STRAP_DDIF_DETECTED)
16919 intel_ddi_init(dev_priv, PORT_F);
16921 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
16923 if (IS_GEN9_BC(dev_priv) &&
16924 intel_bios_is_port_present(dev_priv, PORT_E))
16925 intel_ddi_init(dev_priv, PORT_E);
16927 } else if (HAS_PCH_SPLIT(dev_priv)) {
16931 * intel_edp_init_connector() depends on this completing first,
16932 * to prevent the registration of both eDP and LVDS and the
16933 * incorrect sharing of the PPS.
16935 intel_lvds_init(dev_priv);
16936 intel_crt_init(dev_priv);
16938 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
16940 if (ilk_has_edp_a(dev_priv))
16941 intel_dp_init(dev_priv, DP_A, PORT_A);
16943 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
16944 /* PCH SDVOB multiplex with HDMIB */
16945 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
16947 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
16948 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
16949 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
16952 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
16953 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
16955 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
16956 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
16958 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
16959 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
16961 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
16962 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
16963 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16964 bool has_edp, has_port;
16966 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
16967 intel_crt_init(dev_priv);
16970 * The DP_DETECTED bit is the latched state of the DDC
16971 * SDA pin at boot. However since eDP doesn't require DDC
16972 * (no way to plug in a DP->HDMI dongle) the DDC pins for
16973 * eDP ports may have been muxed to an alternate function.
16974 * Thus we can't rely on the DP_DETECTED bit alone to detect
16975 * eDP ports. Consult the VBT as well as DP_DETECTED to
16976 * detect eDP ports.
16978 * Sadly the straps seem to be missing sometimes even for HDMI
16979 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
16980 * and VBT for the presence of the port. Additionally we can't
16981 * trust the port type the VBT declares as we've seen at least
16982 * HDMI ports that the VBT claim are DP or eDP.
16984 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
16985 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
16986 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
16987 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
16988 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
16989 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
16991 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
16992 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
16993 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
16994 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
16995 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
16996 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
16998 if (IS_CHERRYVIEW(dev_priv)) {
17000 * eDP not supported on port D,
17001 * so no need to worry about it
17003 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
17004 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
17005 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
17006 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
17007 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
17010 vlv_dsi_init(dev_priv);
17011 } else if (IS_PINEVIEW(dev_priv)) {
17012 intel_lvds_init(dev_priv);
17013 intel_crt_init(dev_priv);
17014 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
17015 bool found = false;
17017 if (IS_MOBILE(dev_priv))
17018 intel_lvds_init(dev_priv);
17020 intel_crt_init(dev_priv);
17022 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
17023 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
17024 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
17025 if (!found && IS_G4X(dev_priv)) {
17026 drm_dbg_kms(&dev_priv->drm,
17027 "probing HDMI on SDVOB\n");
17028 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
17031 if (!found && IS_G4X(dev_priv))
17032 intel_dp_init(dev_priv, DP_B, PORT_B);
17035 /* Before G4X SDVOC doesn't have its own detect register */
17037 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
17038 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
17039 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
17042 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
17044 if (IS_G4X(dev_priv)) {
17045 drm_dbg_kms(&dev_priv->drm,
17046 "probing HDMI on SDVOC\n");
17047 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
17049 if (IS_G4X(dev_priv))
17050 intel_dp_init(dev_priv, DP_C, PORT_C);
17053 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
17054 intel_dp_init(dev_priv, DP_D, PORT_D);
17056 if (SUPPORTS_TV(dev_priv))
17057 intel_tv_init(dev_priv);
17058 } else if (IS_GEN(dev_priv, 2)) {
17059 if (IS_I85X(dev_priv))
17060 intel_lvds_init(dev_priv);
17062 intel_crt_init(dev_priv);
17063 intel_dvo_init(dev_priv);
17066 intel_psr_init(dev_priv);
17068 for_each_intel_encoder(&dev_priv->drm, encoder) {
17069 encoder->base.possible_crtcs =
17070 intel_encoder_possible_crtcs(encoder);
17071 encoder->base.possible_clones =
17072 intel_encoder_possible_clones(encoder);
17075 intel_init_pch_refclk(dev_priv);
17077 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
17080 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
17082 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
17084 drm_framebuffer_cleanup(fb);
17085 intel_frontbuffer_put(intel_fb->frontbuffer);
17090 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
17091 struct drm_file *file,
17092 unsigned int *handle)
17094 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
17095 struct drm_i915_private *i915 = to_i915(obj->base.dev);
17097 if (obj->userptr.mm) {
17098 drm_dbg(&i915->drm,
17099 "attempting to use a userptr for a framebuffer, denied\n");
17103 return drm_gem_handle_create(file, &obj->base, handle);
17106 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
17107 struct drm_file *file,
17108 unsigned flags, unsigned color,
17109 struct drm_clip_rect *clips,
17110 unsigned num_clips)
17112 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
17114 i915_gem_object_flush_if_display(obj);
17115 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
17120 static const struct drm_framebuffer_funcs intel_fb_funcs = {
17121 .destroy = intel_user_framebuffer_destroy,
17122 .create_handle = intel_user_framebuffer_create_handle,
17123 .dirty = intel_user_framebuffer_dirty,
17126 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
17127 struct drm_i915_gem_object *obj,
17128 struct drm_mode_fb_cmd2 *mode_cmd)
17130 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
17131 struct drm_framebuffer *fb = &intel_fb->base;
17133 unsigned int tiling, stride;
17137 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
17138 if (!intel_fb->frontbuffer)
17141 i915_gem_object_lock(obj);
17142 tiling = i915_gem_object_get_tiling(obj);
17143 stride = i915_gem_object_get_stride(obj);
17144 i915_gem_object_unlock(obj);
17146 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
17148 * If there's a fence, enforce that
17149 * the fb modifier and tiling mode match.
17151 if (tiling != I915_TILING_NONE &&
17152 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
17153 drm_dbg_kms(&dev_priv->drm,
17154 "tiling_mode doesn't match fb modifier\n");
17158 if (tiling == I915_TILING_X) {
17159 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
17160 } else if (tiling == I915_TILING_Y) {
17161 drm_dbg_kms(&dev_priv->drm,
17162 "No Y tiling for legacy addfb\n");
17167 if (!drm_any_plane_has_format(&dev_priv->drm,
17168 mode_cmd->pixel_format,
17169 mode_cmd->modifier[0])) {
17170 struct drm_format_name_buf format_name;
17172 drm_dbg_kms(&dev_priv->drm,
17173 "unsupported pixel format %s / modifier 0x%llx\n",
17174 drm_get_format_name(mode_cmd->pixel_format,
17176 mode_cmd->modifier[0]);
17181 * gen2/3 display engine uses the fence if present,
17182 * so the tiling mode must match the fb modifier exactly.
17184 if (INTEL_GEN(dev_priv) < 4 &&
17185 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
17186 drm_dbg_kms(&dev_priv->drm,
17187 "tiling_mode must match fb modifier exactly on gen2/3\n");
17191 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
17192 mode_cmd->modifier[0]);
17193 if (mode_cmd->pitches[0] > max_stride) {
17194 drm_dbg_kms(&dev_priv->drm,
17195 "%s pitch (%u) must be at most %d\n",
17196 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
17197 "tiled" : "linear",
17198 mode_cmd->pitches[0], max_stride);
17203 * If there's a fence, enforce that
17204 * the fb pitch and fence stride match.
17206 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
17207 drm_dbg_kms(&dev_priv->drm,
17208 "pitch (%d) must match tiling stride (%d)\n",
17209 mode_cmd->pitches[0], stride);
17213 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
17214 if (mode_cmd->offsets[0] != 0) {
17215 drm_dbg_kms(&dev_priv->drm,
17216 "plane 0 offset (0x%08x) must be 0\n",
17217 mode_cmd->offsets[0]);
17221 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
17223 for (i = 0; i < fb->format->num_planes; i++) {
17224 u32 stride_alignment;
17226 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
17227 drm_dbg_kms(&dev_priv->drm, "bad plane %d handle\n",
17232 stride_alignment = intel_fb_stride_alignment(fb, i);
17233 if (fb->pitches[i] & (stride_alignment - 1)) {
17234 drm_dbg_kms(&dev_priv->drm,
17235 "plane %d pitch (%d) must be at least %u byte aligned\n",
17236 i, fb->pitches[i], stride_alignment);
17240 if (is_gen12_ccs_plane(fb, i)) {
17241 int ccs_aux_stride = gen12_ccs_aux_stride(fb, i);
17243 if (fb->pitches[i] != ccs_aux_stride) {
17244 drm_dbg_kms(&dev_priv->drm,
17245 "ccs aux plane %d pitch (%d) must be %d\n",
17247 fb->pitches[i], ccs_aux_stride);
17252 fb->obj[i] = &obj->base;
17255 ret = intel_fill_fb_info(dev_priv, fb);
17259 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
17261 drm_err(&dev_priv->drm, "framebuffer init failed %d\n", ret);
17268 intel_frontbuffer_put(intel_fb->frontbuffer);
17272 static struct drm_framebuffer *
17273 intel_user_framebuffer_create(struct drm_device *dev,
17274 struct drm_file *filp,
17275 const struct drm_mode_fb_cmd2 *user_mode_cmd)
17277 struct drm_framebuffer *fb;
17278 struct drm_i915_gem_object *obj;
17279 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
17281 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
17283 return ERR_PTR(-ENOENT);
17285 fb = intel_framebuffer_create(obj, &mode_cmd);
17286 i915_gem_object_put(obj);
17291 static enum drm_mode_status
17292 intel_mode_valid(struct drm_device *dev,
17293 const struct drm_display_mode *mode)
17295 struct drm_i915_private *dev_priv = to_i915(dev);
17296 int hdisplay_max, htotal_max;
17297 int vdisplay_max, vtotal_max;
17300 * Can't reject DBLSCAN here because Xorg ddxen can add piles
17301 * of DBLSCAN modes to the output's mode list when they detect
17302 * the scaling mode property on the connector. And they don't
17303 * ask the kernel to validate those modes in any way until
17304 * modeset time at which point the client gets a protocol error.
17305 * So in order to not upset those clients we silently ignore the
17306 * DBLSCAN flag on such connectors. For other connectors we will
17307 * reject modes with the DBLSCAN flag in encoder->compute_config().
17308 * And we always reject DBLSCAN modes in connector->mode_valid()
17309 * as we never want such modes on the connector's mode list.
17312 if (mode->vscan > 1)
17313 return MODE_NO_VSCAN;
17315 if (mode->flags & DRM_MODE_FLAG_HSKEW)
17316 return MODE_H_ILLEGAL;
17318 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
17319 DRM_MODE_FLAG_NCSYNC |
17320 DRM_MODE_FLAG_PCSYNC))
17323 if (mode->flags & (DRM_MODE_FLAG_BCAST |
17324 DRM_MODE_FLAG_PIXMUX |
17325 DRM_MODE_FLAG_CLKDIV2))
17328 /* Transcoder timing limits */
17329 if (INTEL_GEN(dev_priv) >= 11) {
17330 hdisplay_max = 16384;
17331 vdisplay_max = 8192;
17332 htotal_max = 16384;
17334 } else if (INTEL_GEN(dev_priv) >= 9 ||
17335 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
17336 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
17337 vdisplay_max = 4096;
17340 } else if (INTEL_GEN(dev_priv) >= 3) {
17341 hdisplay_max = 4096;
17342 vdisplay_max = 4096;
17346 hdisplay_max = 2048;
17347 vdisplay_max = 2048;
17352 if (mode->hdisplay > hdisplay_max ||
17353 mode->hsync_start > htotal_max ||
17354 mode->hsync_end > htotal_max ||
17355 mode->htotal > htotal_max)
17356 return MODE_H_ILLEGAL;
17358 if (mode->vdisplay > vdisplay_max ||
17359 mode->vsync_start > vtotal_max ||
17360 mode->vsync_end > vtotal_max ||
17361 mode->vtotal > vtotal_max)
17362 return MODE_V_ILLEGAL;
17364 if (INTEL_GEN(dev_priv) >= 5) {
17365 if (mode->hdisplay < 64 ||
17366 mode->htotal - mode->hdisplay < 32)
17367 return MODE_H_ILLEGAL;
17369 if (mode->vtotal - mode->vdisplay < 5)
17370 return MODE_V_ILLEGAL;
17372 if (mode->htotal - mode->hdisplay < 32)
17373 return MODE_H_ILLEGAL;
17375 if (mode->vtotal - mode->vdisplay < 3)
17376 return MODE_V_ILLEGAL;
17382 enum drm_mode_status
17383 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
17384 const struct drm_display_mode *mode)
17386 int plane_width_max, plane_height_max;
17389 * intel_mode_valid() should be
17390 * sufficient on older platforms.
17392 if (INTEL_GEN(dev_priv) < 9)
17396 * Most people will probably want a fullscreen
17397 * plane so let's not advertize modes that are
17398 * too big for that.
17400 if (INTEL_GEN(dev_priv) >= 11) {
17401 plane_width_max = 5120;
17402 plane_height_max = 4320;
17404 plane_width_max = 5120;
17405 plane_height_max = 4096;
17408 if (mode->hdisplay > plane_width_max)
17409 return MODE_H_ILLEGAL;
17411 if (mode->vdisplay > plane_height_max)
17412 return MODE_V_ILLEGAL;
17417 static const struct drm_mode_config_funcs intel_mode_funcs = {
17418 .fb_create = intel_user_framebuffer_create,
17419 .get_format_info = intel_get_format_info,
17420 .output_poll_changed = intel_fbdev_output_poll_changed,
17421 .mode_valid = intel_mode_valid,
17422 .atomic_check = intel_atomic_check,
17423 .atomic_commit = intel_atomic_commit,
17424 .atomic_state_alloc = intel_atomic_state_alloc,
17425 .atomic_state_clear = intel_atomic_state_clear,
17426 .atomic_state_free = intel_atomic_state_free,
17430 * intel_init_display_hooks - initialize the display modesetting hooks
17431 * @dev_priv: device private
17433 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
17435 intel_init_cdclk_hooks(dev_priv);
17437 if (INTEL_GEN(dev_priv) >= 9) {
17438 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
17439 dev_priv->display.get_initial_plane_config =
17440 skl_get_initial_plane_config;
17441 dev_priv->display.crtc_compute_clock = hsw_crtc_compute_clock;
17442 dev_priv->display.crtc_enable = hsw_crtc_enable;
17443 dev_priv->display.crtc_disable = hsw_crtc_disable;
17444 } else if (HAS_DDI(dev_priv)) {
17445 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
17446 dev_priv->display.get_initial_plane_config =
17447 i9xx_get_initial_plane_config;
17448 dev_priv->display.crtc_compute_clock =
17449 hsw_crtc_compute_clock;
17450 dev_priv->display.crtc_enable = hsw_crtc_enable;
17451 dev_priv->display.crtc_disable = hsw_crtc_disable;
17452 } else if (HAS_PCH_SPLIT(dev_priv)) {
17453 dev_priv->display.get_pipe_config = ilk_get_pipe_config;
17454 dev_priv->display.get_initial_plane_config =
17455 i9xx_get_initial_plane_config;
17456 dev_priv->display.crtc_compute_clock =
17457 ilk_crtc_compute_clock;
17458 dev_priv->display.crtc_enable = ilk_crtc_enable;
17459 dev_priv->display.crtc_disable = ilk_crtc_disable;
17460 } else if (IS_CHERRYVIEW(dev_priv)) {
17461 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17462 dev_priv->display.get_initial_plane_config =
17463 i9xx_get_initial_plane_config;
17464 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
17465 dev_priv->display.crtc_enable = valleyview_crtc_enable;
17466 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17467 } else if (IS_VALLEYVIEW(dev_priv)) {
17468 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17469 dev_priv->display.get_initial_plane_config =
17470 i9xx_get_initial_plane_config;
17471 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
17472 dev_priv->display.crtc_enable = valleyview_crtc_enable;
17473 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17474 } else if (IS_G4X(dev_priv)) {
17475 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17476 dev_priv->display.get_initial_plane_config =
17477 i9xx_get_initial_plane_config;
17478 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
17479 dev_priv->display.crtc_enable = i9xx_crtc_enable;
17480 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17481 } else if (IS_PINEVIEW(dev_priv)) {
17482 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17483 dev_priv->display.get_initial_plane_config =
17484 i9xx_get_initial_plane_config;
17485 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
17486 dev_priv->display.crtc_enable = i9xx_crtc_enable;
17487 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17488 } else if (!IS_GEN(dev_priv, 2)) {
17489 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17490 dev_priv->display.get_initial_plane_config =
17491 i9xx_get_initial_plane_config;
17492 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
17493 dev_priv->display.crtc_enable = i9xx_crtc_enable;
17494 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17496 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
17497 dev_priv->display.get_initial_plane_config =
17498 i9xx_get_initial_plane_config;
17499 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
17500 dev_priv->display.crtc_enable = i9xx_crtc_enable;
17501 dev_priv->display.crtc_disable = i9xx_crtc_disable;
17504 if (IS_GEN(dev_priv, 5)) {
17505 dev_priv->display.fdi_link_train = ilk_fdi_link_train;
17506 } else if (IS_GEN(dev_priv, 6)) {
17507 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
17508 } else if (IS_IVYBRIDGE(dev_priv)) {
17509 /* FIXME: detect B0+ stepping and use auto training */
17510 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
17513 if (INTEL_GEN(dev_priv) >= 9)
17514 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
17516 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
17520 void intel_modeset_init_hw(struct drm_i915_private *i915)
17522 struct intel_cdclk_state *cdclk_state =
17523 to_intel_cdclk_state(i915->cdclk.obj.state);
17525 intel_update_cdclk(i915);
17526 intel_dump_cdclk_config(&i915->cdclk.hw, "Current CDCLK");
17527 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw;
17530 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state)
17532 struct drm_plane *plane;
17533 struct drm_crtc *crtc;
17535 drm_for_each_crtc(crtc, state->dev) {
17536 struct drm_crtc_state *crtc_state;
17538 crtc_state = drm_atomic_get_crtc_state(state, crtc);
17539 if (IS_ERR(crtc_state))
17540 return PTR_ERR(crtc_state);
17543 drm_for_each_plane(plane, state->dev) {
17544 struct drm_plane_state *plane_state;
17546 plane_state = drm_atomic_get_plane_state(state, plane);
17547 if (IS_ERR(plane_state))
17548 return PTR_ERR(plane_state);
17555 * Calculate what we think the watermarks should be for the state we've read
17556 * out of the hardware and then immediately program those watermarks so that
17557 * we ensure the hardware settings match our internal state.
17559 * We can calculate what we think WM's should be by creating a duplicate of the
17560 * current state (which was constructed during hardware readout) and running it
17561 * through the atomic check code to calculate new watermark values in the
17564 static void sanitize_watermarks(struct drm_i915_private *dev_priv)
17566 struct drm_atomic_state *state;
17567 struct intel_atomic_state *intel_state;
17568 struct intel_crtc *crtc;
17569 struct intel_crtc_state *crtc_state;
17570 struct drm_modeset_acquire_ctx ctx;
17574 /* Only supported on platforms that use atomic watermark design */
17575 if (!dev_priv->display.optimize_watermarks)
17578 state = drm_atomic_state_alloc(&dev_priv->drm);
17579 if (drm_WARN_ON(&dev_priv->drm, !state))
17582 intel_state = to_intel_atomic_state(state);
17584 drm_modeset_acquire_init(&ctx, 0);
17587 state->acquire_ctx = &ctx;
17590 * Hardware readout is the only time we don't want to calculate
17591 * intermediate watermarks (since we don't trust the current
17594 if (!HAS_GMCH(dev_priv))
17595 intel_state->skip_intermediate_wm = true;
17597 ret = sanitize_watermarks_add_affected(state);
17601 ret = intel_atomic_check(&dev_priv->drm, state);
17605 /* Write calculated watermark values back */
17606 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
17607 crtc_state->wm.need_postvbl_update = true;
17608 dev_priv->display.optimize_watermarks(intel_state, crtc);
17610 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
17614 if (ret == -EDEADLK) {
17615 drm_atomic_state_clear(state);
17616 drm_modeset_backoff(&ctx);
17621 * If we fail here, it means that the hardware appears to be
17622 * programmed in a way that shouldn't be possible, given our
17623 * understanding of watermark requirements. This might mean a
17624 * mistake in the hardware readout code or a mistake in the
17625 * watermark calculations for a given platform. Raise a WARN
17626 * so that this is noticeable.
17628 * If this actually happens, we'll have to just leave the
17629 * BIOS-programmed watermarks untouched and hope for the best.
17631 drm_WARN(&dev_priv->drm, ret,
17632 "Could not determine valid watermarks for inherited state\n");
17634 drm_atomic_state_put(state);
17636 drm_modeset_drop_locks(&ctx);
17637 drm_modeset_acquire_fini(&ctx);
17640 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
17642 if (IS_GEN(dev_priv, 5)) {
17644 intel_de_read(dev_priv, FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
17646 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
17647 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
17648 dev_priv->fdi_pll_freq = 270000;
17653 drm_dbg(&dev_priv->drm, "FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
17656 static int intel_initial_commit(struct drm_device *dev)
17658 struct drm_atomic_state *state = NULL;
17659 struct drm_modeset_acquire_ctx ctx;
17660 struct intel_crtc *crtc;
17663 state = drm_atomic_state_alloc(dev);
17667 drm_modeset_acquire_init(&ctx, 0);
17670 state->acquire_ctx = &ctx;
17672 for_each_intel_crtc(dev, crtc) {
17673 struct intel_crtc_state *crtc_state =
17674 intel_atomic_get_crtc_state(state, crtc);
17676 if (IS_ERR(crtc_state)) {
17677 ret = PTR_ERR(crtc_state);
17681 if (crtc_state->hw.active) {
17682 ret = drm_atomic_add_affected_planes(state, &crtc->base);
17687 * FIXME hack to force a LUT update to avoid the
17688 * plane update forcing the pipe gamma on without
17689 * having a proper LUT loaded. Remove once we
17690 * have readout for pipe gamma enable.
17692 crtc_state->uapi.color_mgmt_changed = true;
17695 * FIXME hack to force full modeset when DSC is being
17698 * As long as we do not have full state readout and
17699 * config comparison of crtc_state->dsc, we have no way
17700 * to ensure reliable fastset. Remove once we have
17703 if (crtc_state->dsc.compression_enable) {
17704 ret = drm_atomic_add_affected_connectors(state,
17708 crtc_state->uapi.mode_changed = true;
17709 drm_dbg_kms(dev, "Force full modeset for DSC\n");
17714 ret = drm_atomic_commit(state);
17717 if (ret == -EDEADLK) {
17718 drm_atomic_state_clear(state);
17719 drm_modeset_backoff(&ctx);
17723 drm_atomic_state_put(state);
17725 drm_modeset_drop_locks(&ctx);
17726 drm_modeset_acquire_fini(&ctx);
17731 static void intel_mode_config_init(struct drm_i915_private *i915)
17733 struct drm_mode_config *mode_config = &i915->drm.mode_config;
17735 drm_mode_config_init(&i915->drm);
17736 INIT_LIST_HEAD(&i915->global_obj_list);
17738 mode_config->min_width = 0;
17739 mode_config->min_height = 0;
17741 mode_config->preferred_depth = 24;
17742 mode_config->prefer_shadow = 1;
17744 mode_config->allow_fb_modifiers = true;
17746 mode_config->funcs = &intel_mode_funcs;
17749 * Maximum framebuffer dimensions, chosen to match
17750 * the maximum render engine surface size on gen4+.
17752 if (INTEL_GEN(i915) >= 7) {
17753 mode_config->max_width = 16384;
17754 mode_config->max_height = 16384;
17755 } else if (INTEL_GEN(i915) >= 4) {
17756 mode_config->max_width = 8192;
17757 mode_config->max_height = 8192;
17758 } else if (IS_GEN(i915, 3)) {
17759 mode_config->max_width = 4096;
17760 mode_config->max_height = 4096;
17762 mode_config->max_width = 2048;
17763 mode_config->max_height = 2048;
17766 if (IS_I845G(i915) || IS_I865G(i915)) {
17767 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
17768 mode_config->cursor_height = 1023;
17769 } else if (IS_GEN(i915, 2)) {
17770 mode_config->cursor_width = 64;
17771 mode_config->cursor_height = 64;
17773 mode_config->cursor_width = 256;
17774 mode_config->cursor_height = 256;
17778 static void intel_mode_config_cleanup(struct drm_i915_private *i915)
17780 intel_atomic_global_obj_cleanup(i915);
17781 drm_mode_config_cleanup(&i915->drm);
17784 static void plane_config_fini(struct intel_initial_plane_config *plane_config)
17786 if (plane_config->fb) {
17787 struct drm_framebuffer *fb = &plane_config->fb->base;
17789 /* We may only have the stub and not a full framebuffer */
17790 if (drm_framebuffer_read_refcount(fb))
17791 drm_framebuffer_put(fb);
17796 if (plane_config->vma)
17797 i915_vma_put(plane_config->vma);
17800 /* part #1: call before irq install */
17801 int intel_modeset_init_noirq(struct drm_i915_private *i915)
17805 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
17806 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
17807 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
17809 intel_mode_config_init(i915);
17811 ret = intel_cdclk_init(i915);
17815 ret = intel_bw_init(i915);
17819 init_llist_head(&i915->atomic_helper.free_list);
17820 INIT_WORK(&i915->atomic_helper.free_work,
17821 intel_atomic_helper_free_state_worker);
17823 intel_init_quirks(i915);
17825 intel_fbc_init(i915);
17830 /* part #2: call after irq install */
17831 int intel_modeset_init(struct drm_i915_private *i915)
17833 struct drm_device *dev = &i915->drm;
17835 struct intel_crtc *crtc;
17838 intel_init_pm(i915);
17840 intel_panel_sanitize_ssc(i915);
17842 intel_gmbus_setup(i915);
17844 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n",
17845 INTEL_NUM_PIPES(i915),
17846 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
17848 if (HAS_DISPLAY(i915) && INTEL_DISPLAY_ENABLED(i915)) {
17849 for_each_pipe(i915, pipe) {
17850 ret = intel_crtc_init(i915, pipe);
17852 intel_mode_config_cleanup(i915);
17858 intel_plane_possible_crtcs_init(i915);
17859 intel_shared_dpll_init(dev);
17860 intel_update_fdi_pll_freq(i915);
17862 intel_update_czclk(i915);
17863 intel_modeset_init_hw(i915);
17865 intel_hdcp_component_init(i915);
17867 if (i915->max_cdclk_freq == 0)
17868 intel_update_max_cdclk(i915);
17870 /* Just disable it once at startup */
17871 intel_vga_disable(i915);
17872 intel_setup_outputs(i915);
17874 drm_modeset_lock_all(dev);
17875 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
17876 drm_modeset_unlock_all(dev);
17878 for_each_intel_crtc(dev, crtc) {
17879 struct intel_initial_plane_config plane_config = {};
17885 * Note that reserving the BIOS fb up front prevents us
17886 * from stuffing other stolen allocations like the ring
17887 * on top. This prevents some ugliness at boot time, and
17888 * can even allow for smooth boot transitions if the BIOS
17889 * fb is large enough for the active pipe configuration.
17891 i915->display.get_initial_plane_config(crtc, &plane_config);
17894 * If the fb is shared between multiple heads, we'll
17895 * just get the first one.
17897 intel_find_initial_plane_obj(crtc, &plane_config);
17899 plane_config_fini(&plane_config);
17903 * Make sure hardware watermarks really match the state we read out.
17904 * Note that we need to do this after reconstructing the BIOS fb's
17905 * since the watermark calculation done here will use pstate->fb.
17907 if (!HAS_GMCH(i915))
17908 sanitize_watermarks(i915);
17911 * Force all active planes to recompute their states. So that on
17912 * mode_setcrtc after probe, all the intel_plane_state variables
17913 * are already calculated and there is no assert_plane warnings
17916 ret = intel_initial_commit(dev);
17918 drm_dbg_kms(&i915->drm, "Initial commit in probe failed.\n");
17923 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17925 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17926 /* 640x480@60Hz, ~25175 kHz */
17927 struct dpll clock = {
17937 drm_WARN_ON(&dev_priv->drm,
17938 i9xx_calc_dpll_params(48000, &clock) != 25154);
17940 drm_dbg_kms(&dev_priv->drm,
17941 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
17942 pipe_name(pipe), clock.vco, clock.dot);
17944 fp = i9xx_dpll_compute_fp(&clock);
17945 dpll = DPLL_DVO_2X_MODE |
17946 DPLL_VGA_MODE_DIS |
17947 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
17948 PLL_P2_DIVIDE_BY_4 |
17949 PLL_REF_INPUT_DREFCLK |
17952 intel_de_write(dev_priv, FP0(pipe), fp);
17953 intel_de_write(dev_priv, FP1(pipe), fp);
17955 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
17956 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
17957 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
17958 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
17959 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
17960 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
17961 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
17964 * Apparently we need to have VGA mode enabled prior to changing
17965 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
17966 * dividers, even though the register value does change.
17968 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
17969 intel_de_write(dev_priv, DPLL(pipe), dpll);
17971 /* Wait for the clocks to stabilize. */
17972 intel_de_posting_read(dev_priv, DPLL(pipe));
17975 /* The pixel multiplier can only be updated once the
17976 * DPLL is enabled and the clocks are stable.
17978 * So write it again.
17980 intel_de_write(dev_priv, DPLL(pipe), dpll);
17982 /* We do this three times for luck */
17983 for (i = 0; i < 3 ; i++) {
17984 intel_de_write(dev_priv, DPLL(pipe), dpll);
17985 intel_de_posting_read(dev_priv, DPLL(pipe));
17986 udelay(150); /* wait for warmup */
17989 intel_de_write(dev_priv, PIPECONF(pipe),
17990 PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
17991 intel_de_posting_read(dev_priv, PIPECONF(pipe));
17993 intel_wait_for_pipe_scanline_moving(crtc);
17996 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
17998 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
18000 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
18003 drm_WARN_ON(&dev_priv->drm,
18004 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) &
18005 DISPLAY_PLANE_ENABLE);
18006 drm_WARN_ON(&dev_priv->drm,
18007 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) &
18008 DISPLAY_PLANE_ENABLE);
18009 drm_WARN_ON(&dev_priv->drm,
18010 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) &
18011 DISPLAY_PLANE_ENABLE);
18012 drm_WARN_ON(&dev_priv->drm,
18013 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE);
18014 drm_WARN_ON(&dev_priv->drm,
18015 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE);
18017 intel_de_write(dev_priv, PIPECONF(pipe), 0);
18018 intel_de_posting_read(dev_priv, PIPECONF(pipe));
18020 intel_wait_for_pipe_scanline_stopped(crtc);
18022 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
18023 intel_de_posting_read(dev_priv, DPLL(pipe));
18027 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
18029 struct intel_crtc *crtc;
18031 if (INTEL_GEN(dev_priv) >= 4)
18034 for_each_intel_crtc(&dev_priv->drm, crtc) {
18035 struct intel_plane *plane =
18036 to_intel_plane(crtc->base.primary);
18037 struct intel_crtc *plane_crtc;
18040 if (!plane->get_hw_state(plane, &pipe))
18043 if (pipe == crtc->pipe)
18046 drm_dbg_kms(&dev_priv->drm,
18047 "[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
18048 plane->base.base.id, plane->base.name);
18050 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
18051 intel_plane_disable_noatomic(plane_crtc, plane);
18055 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
18057 struct drm_device *dev = crtc->base.dev;
18058 struct intel_encoder *encoder;
18060 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
18066 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
18068 struct drm_device *dev = encoder->base.dev;
18069 struct intel_connector *connector;
18071 for_each_connector_on_encoder(dev, &encoder->base, connector)
18077 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
18078 enum pipe pch_transcoder)
18080 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
18081 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
18084 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state *crtc_state)
18086 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
18087 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
18088 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
18090 if (INTEL_GEN(dev_priv) >= 9 ||
18091 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
18092 i915_reg_t reg = CHICKEN_TRANS(cpu_transcoder);
18095 if (transcoder_is_dsi(cpu_transcoder))
18098 val = intel_de_read(dev_priv, reg);
18099 val &= ~HSW_FRAME_START_DELAY_MASK;
18100 val |= HSW_FRAME_START_DELAY(0);
18101 intel_de_write(dev_priv, reg, val);
18103 i915_reg_t reg = PIPECONF(cpu_transcoder);
18106 val = intel_de_read(dev_priv, reg);
18107 val &= ~PIPECONF_FRAME_START_DELAY_MASK;
18108 val |= PIPECONF_FRAME_START_DELAY(0);
18109 intel_de_write(dev_priv, reg, val);
18112 if (!crtc_state->has_pch_encoder)
18115 if (HAS_PCH_IBX(dev_priv)) {
18116 i915_reg_t reg = PCH_TRANSCONF(crtc->pipe);
18119 val = intel_de_read(dev_priv, reg);
18120 val &= ~TRANS_FRAME_START_DELAY_MASK;
18121 val |= TRANS_FRAME_START_DELAY(0);
18122 intel_de_write(dev_priv, reg, val);
18124 enum pipe pch_transcoder = intel_crtc_pch_transcoder(crtc);
18125 i915_reg_t reg = TRANS_CHICKEN2(pch_transcoder);
18128 val = intel_de_read(dev_priv, reg);
18129 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
18130 val |= TRANS_CHICKEN2_FRAME_START_DELAY(0);
18131 intel_de_write(dev_priv, reg, val);
18135 static void intel_sanitize_crtc(struct intel_crtc *crtc,
18136 struct drm_modeset_acquire_ctx *ctx)
18138 struct drm_device *dev = crtc->base.dev;
18139 struct drm_i915_private *dev_priv = to_i915(dev);
18140 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
18142 if (crtc_state->hw.active) {
18143 struct intel_plane *plane;
18145 /* Clear any frame start delays used for debugging left by the BIOS */
18146 intel_sanitize_frame_start_delay(crtc_state);
18148 /* Disable everything but the primary plane */
18149 for_each_intel_plane_on_crtc(dev, crtc, plane) {
18150 const struct intel_plane_state *plane_state =
18151 to_intel_plane_state(plane->base.state);
18153 if (plane_state->uapi.visible &&
18154 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
18155 intel_plane_disable_noatomic(crtc, plane);
18159 * Disable any background color set by the BIOS, but enable the
18160 * gamma and CSC to match how we program our planes.
18162 if (INTEL_GEN(dev_priv) >= 9)
18163 intel_de_write(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe),
18164 SKL_BOTTOM_COLOR_GAMMA_ENABLE | SKL_BOTTOM_COLOR_CSC_ENABLE);
18167 /* Adjust the state of the output pipe according to whether we
18168 * have active connectors/encoders. */
18169 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc))
18170 intel_crtc_disable_noatomic(crtc, ctx);
18172 if (crtc_state->hw.active || HAS_GMCH(dev_priv)) {
18174 * We start out with underrun reporting disabled to avoid races.
18175 * For correct bookkeeping mark this on active crtcs.
18177 * Also on gmch platforms we dont have any hardware bits to
18178 * disable the underrun reporting. Which means we need to start
18179 * out with underrun reporting disabled also on inactive pipes,
18180 * since otherwise we'll complain about the garbage we read when
18181 * e.g. coming up after runtime pm.
18183 * No protection against concurrent access is required - at
18184 * worst a fifo underrun happens which also sets this to false.
18186 crtc->cpu_fifo_underrun_disabled = true;
18188 * We track the PCH trancoder underrun reporting state
18189 * within the crtc. With crtc for pipe A housing the underrun
18190 * reporting state for PCH transcoder A, crtc for pipe B housing
18191 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
18192 * and marking underrun reporting as disabled for the non-existing
18193 * PCH transcoders B and C would prevent enabling the south
18194 * error interrupt (see cpt_can_enable_serr_int()).
18196 if (has_pch_trancoder(dev_priv, crtc->pipe))
18197 crtc->pch_fifo_underrun_disabled = true;
18201 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
18203 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
18206 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
18207 * the hardware when a high res displays plugged in. DPLL P
18208 * divider is zero, and the pipe timings are bonkers. We'll
18209 * try to disable everything in that case.
18211 * FIXME would be nice to be able to sanitize this state
18212 * without several WARNs, but for now let's take the easy
18215 return IS_GEN(dev_priv, 6) &&
18216 crtc_state->hw.active &&
18217 crtc_state->shared_dpll &&
18218 crtc_state->port_clock == 0;
18221 static void intel_sanitize_encoder(struct intel_encoder *encoder)
18223 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
18224 struct intel_connector *connector;
18225 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
18226 struct intel_crtc_state *crtc_state = crtc ?
18227 to_intel_crtc_state(crtc->base.state) : NULL;
18229 /* We need to check both for a crtc link (meaning that the
18230 * encoder is active and trying to read from a pipe) and the
18231 * pipe itself being active. */
18232 bool has_active_crtc = crtc_state &&
18233 crtc_state->hw.active;
18235 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
18236 drm_dbg_kms(&dev_priv->drm,
18237 "BIOS has misprogrammed the hardware. Disabling pipe %c\n",
18238 pipe_name(crtc->pipe));
18239 has_active_crtc = false;
18242 connector = intel_encoder_find_connector(encoder);
18243 if (connector && !has_active_crtc) {
18244 drm_dbg_kms(&dev_priv->drm,
18245 "[ENCODER:%d:%s] has active connectors but no active pipe!\n",
18246 encoder->base.base.id,
18247 encoder->base.name);
18249 /* Connector is active, but has no active pipe. This is
18250 * fallout from our resume register restoring. Disable
18251 * the encoder manually again. */
18253 struct drm_encoder *best_encoder;
18255 drm_dbg_kms(&dev_priv->drm,
18256 "[ENCODER:%d:%s] manually disabled\n",
18257 encoder->base.base.id,
18258 encoder->base.name);
18260 /* avoid oopsing in case the hooks consult best_encoder */
18261 best_encoder = connector->base.state->best_encoder;
18262 connector->base.state->best_encoder = &encoder->base;
18264 if (encoder->disable)
18265 encoder->disable(encoder, crtc_state,
18266 connector->base.state);
18267 if (encoder->post_disable)
18268 encoder->post_disable(encoder, crtc_state,
18269 connector->base.state);
18271 connector->base.state->best_encoder = best_encoder;
18273 encoder->base.crtc = NULL;
18275 /* Inconsistent output/port/pipe state happens presumably due to
18276 * a bug in one of the get_hw_state functions. Or someplace else
18277 * in our code, like the register restore mess on resume. Clamp
18278 * things to off as a safer default. */
18280 connector->base.dpms = DRM_MODE_DPMS_OFF;
18281 connector->base.encoder = NULL;
18284 /* notify opregion of the sanitized encoder state */
18285 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
18287 if (INTEL_GEN(dev_priv) >= 11)
18288 icl_sanitize_encoder_pll_mapping(encoder);
18291 /* FIXME read out full plane state for all planes */
18292 static void readout_plane_state(struct drm_i915_private *dev_priv)
18294 struct intel_plane *plane;
18295 struct intel_crtc *crtc;
18297 for_each_intel_plane(&dev_priv->drm, plane) {
18298 struct intel_plane_state *plane_state =
18299 to_intel_plane_state(plane->base.state);
18300 struct intel_crtc_state *crtc_state;
18301 enum pipe pipe = PIPE_A;
18304 visible = plane->get_hw_state(plane, &pipe);
18306 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
18307 crtc_state = to_intel_crtc_state(crtc->base.state);
18309 intel_set_plane_visible(crtc_state, plane_state, visible);
18311 drm_dbg_kms(&dev_priv->drm,
18312 "[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
18313 plane->base.base.id, plane->base.name,
18314 enableddisabled(visible), pipe_name(pipe));
18317 for_each_intel_crtc(&dev_priv->drm, crtc) {
18318 struct intel_crtc_state *crtc_state =
18319 to_intel_crtc_state(crtc->base.state);
18321 fixup_active_planes(crtc_state);
18325 static void intel_modeset_readout_hw_state(struct drm_device *dev)
18327 struct drm_i915_private *dev_priv = to_i915(dev);
18328 struct intel_cdclk_state *cdclk_state =
18329 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
18331 struct intel_crtc *crtc;
18332 struct intel_encoder *encoder;
18333 struct intel_connector *connector;
18334 struct drm_connector_list_iter conn_iter;
18335 u8 active_pipes = 0;
18337 for_each_intel_crtc(dev, crtc) {
18338 struct intel_crtc_state *crtc_state =
18339 to_intel_crtc_state(crtc->base.state);
18341 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
18342 intel_crtc_free_hw_state(crtc_state);
18343 intel_crtc_state_reset(crtc_state, crtc);
18345 crtc_state->hw.active = crtc_state->hw.enable =
18346 dev_priv->display.get_pipe_config(crtc, crtc_state);
18348 crtc->base.enabled = crtc_state->hw.enable;
18349 crtc->active = crtc_state->hw.active;
18351 if (crtc_state->hw.active)
18352 active_pipes |= BIT(crtc->pipe);
18354 drm_dbg_kms(&dev_priv->drm,
18355 "[CRTC:%d:%s] hw state readout: %s\n",
18356 crtc->base.base.id, crtc->base.name,
18357 enableddisabled(crtc_state->hw.active));
18360 dev_priv->active_pipes = cdclk_state->active_pipes = active_pipes;
18362 readout_plane_state(dev_priv);
18364 intel_dpll_readout_hw_state(dev_priv);
18366 for_each_intel_encoder(dev, encoder) {
18369 if (encoder->get_hw_state(encoder, &pipe)) {
18370 struct intel_crtc_state *crtc_state;
18372 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
18373 crtc_state = to_intel_crtc_state(crtc->base.state);
18375 encoder->base.crtc = &crtc->base;
18376 encoder->get_config(encoder, crtc_state);
18378 encoder->base.crtc = NULL;
18381 drm_dbg_kms(&dev_priv->drm,
18382 "[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
18383 encoder->base.base.id, encoder->base.name,
18384 enableddisabled(encoder->base.crtc),
18388 drm_connector_list_iter_begin(dev, &conn_iter);
18389 for_each_intel_connector_iter(connector, &conn_iter) {
18390 if (connector->get_hw_state(connector)) {
18391 struct intel_crtc_state *crtc_state;
18392 struct intel_crtc *crtc;
18394 connector->base.dpms = DRM_MODE_DPMS_ON;
18396 encoder = intel_attached_encoder(connector);
18397 connector->base.encoder = &encoder->base;
18399 crtc = to_intel_crtc(encoder->base.crtc);
18400 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
18402 if (crtc_state && crtc_state->hw.active) {
18404 * This has to be done during hardware readout
18405 * because anything calling .crtc_disable may
18406 * rely on the connector_mask being accurate.
18408 crtc_state->uapi.connector_mask |=
18409 drm_connector_mask(&connector->base);
18410 crtc_state->uapi.encoder_mask |=
18411 drm_encoder_mask(&encoder->base);
18414 connector->base.dpms = DRM_MODE_DPMS_OFF;
18415 connector->base.encoder = NULL;
18417 drm_dbg_kms(&dev_priv->drm,
18418 "[CONNECTOR:%d:%s] hw state readout: %s\n",
18419 connector->base.base.id, connector->base.name,
18420 enableddisabled(connector->base.encoder));
18422 drm_connector_list_iter_end(&conn_iter);
18424 for_each_intel_crtc(dev, crtc) {
18425 struct intel_bw_state *bw_state =
18426 to_intel_bw_state(dev_priv->bw_obj.state);
18427 struct intel_crtc_state *crtc_state =
18428 to_intel_crtc_state(crtc->base.state);
18429 struct intel_plane *plane;
18432 if (crtc_state->hw.active) {
18433 struct drm_display_mode *mode = &crtc_state->hw.mode;
18435 intel_mode_from_pipe_config(&crtc_state->hw.adjusted_mode,
18438 *mode = crtc_state->hw.adjusted_mode;
18439 mode->hdisplay = crtc_state->pipe_src_w;
18440 mode->vdisplay = crtc_state->pipe_src_h;
18443 * The initial mode needs to be set in order to keep
18444 * the atomic core happy. It wants a valid mode if the
18445 * crtc's enabled, so we do the above call.
18447 * But we don't set all the derived state fully, hence
18448 * set a flag to indicate that a full recalculation is
18449 * needed on the next commit.
18451 mode->private_flags = I915_MODE_FLAG_INHERITED;
18453 intel_crtc_compute_pixel_rate(crtc_state);
18455 intel_crtc_update_active_timings(crtc_state);
18457 intel_crtc_copy_hw_to_uapi_state(crtc_state);
18460 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
18461 const struct intel_plane_state *plane_state =
18462 to_intel_plane_state(plane->base.state);
18465 * FIXME don't have the fb yet, so can't
18466 * use intel_plane_data_rate() :(
18468 if (plane_state->uapi.visible)
18469 crtc_state->data_rate[plane->id] =
18470 4 * crtc_state->pixel_rate;
18472 * FIXME don't have the fb yet, so can't
18473 * use plane->min_cdclk() :(
18475 if (plane_state->uapi.visible && plane->min_cdclk) {
18476 if (crtc_state->double_wide ||
18477 INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
18478 crtc_state->min_cdclk[plane->id] =
18479 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
18481 crtc_state->min_cdclk[plane->id] =
18482 crtc_state->pixel_rate;
18484 drm_dbg_kms(&dev_priv->drm,
18485 "[PLANE:%d:%s] min_cdclk %d kHz\n",
18486 plane->base.base.id, plane->base.name,
18487 crtc_state->min_cdclk[plane->id]);
18490 if (crtc_state->hw.active) {
18491 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
18492 if (drm_WARN_ON(dev, min_cdclk < 0))
18496 cdclk_state->min_cdclk[crtc->pipe] = min_cdclk;
18497 cdclk_state->min_voltage_level[crtc->pipe] =
18498 crtc_state->min_voltage_level;
18500 intel_bw_crtc_update(bw_state, crtc_state);
18502 intel_pipe_config_sanity_check(dev_priv, crtc_state);
18507 get_encoder_power_domains(struct drm_i915_private *dev_priv)
18509 struct intel_encoder *encoder;
18511 for_each_intel_encoder(&dev_priv->drm, encoder) {
18512 struct intel_crtc_state *crtc_state;
18514 if (!encoder->get_power_domains)
18518 * MST-primary and inactive encoders don't have a crtc state
18519 * and neither of these require any power domain references.
18521 if (!encoder->base.crtc)
18524 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
18525 encoder->get_power_domains(encoder, crtc_state);
18529 static void intel_early_display_was(struct drm_i915_private *dev_priv)
18532 * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl
18533 * Also known as Wa_14010480278.
18535 if (IS_GEN_RANGE(dev_priv, 10, 12) || IS_GEMINILAKE(dev_priv))
18536 intel_de_write(dev_priv, GEN9_CLKGATE_DIS_0,
18537 intel_de_read(dev_priv, GEN9_CLKGATE_DIS_0) | DARBF_GATING_DIS);
18539 if (IS_HASWELL(dev_priv)) {
18541 * WaRsPkgCStateDisplayPMReq:hsw
18542 * System hang if this isn't done before disabling all planes!
18544 intel_de_write(dev_priv, CHICKEN_PAR1_1,
18545 intel_de_read(dev_priv, CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
18549 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
18550 enum port port, i915_reg_t hdmi_reg)
18552 u32 val = intel_de_read(dev_priv, hdmi_reg);
18554 if (val & SDVO_ENABLE ||
18555 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
18558 drm_dbg_kms(&dev_priv->drm,
18559 "Sanitizing transcoder select for HDMI %c\n",
18562 val &= ~SDVO_PIPE_SEL_MASK;
18563 val |= SDVO_PIPE_SEL(PIPE_A);
18565 intel_de_write(dev_priv, hdmi_reg, val);
18568 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
18569 enum port port, i915_reg_t dp_reg)
18571 u32 val = intel_de_read(dev_priv, dp_reg);
18573 if (val & DP_PORT_EN ||
18574 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
18577 drm_dbg_kms(&dev_priv->drm,
18578 "Sanitizing transcoder select for DP %c\n",
18581 val &= ~DP_PIPE_SEL_MASK;
18582 val |= DP_PIPE_SEL(PIPE_A);
18584 intel_de_write(dev_priv, dp_reg, val);
18587 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
18590 * The BIOS may select transcoder B on some of the PCH
18591 * ports even it doesn't enable the port. This would trip
18592 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
18593 * Sanitize the transcoder select bits to prevent that. We
18594 * assume that the BIOS never actually enabled the port,
18595 * because if it did we'd actually have to toggle the port
18596 * on and back off to make the transcoder A select stick
18597 * (see. intel_dp_link_down(), intel_disable_hdmi(),
18598 * intel_disable_sdvo()).
18600 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
18601 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
18602 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
18604 /* PCH SDVOB multiplex with HDMIB */
18605 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
18606 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
18607 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
18610 /* Scan out the current hw modeset state,
18611 * and sanitizes it to the current state
18614 intel_modeset_setup_hw_state(struct drm_device *dev,
18615 struct drm_modeset_acquire_ctx *ctx)
18617 struct drm_i915_private *dev_priv = to_i915(dev);
18618 struct intel_encoder *encoder;
18619 struct intel_crtc *crtc;
18620 intel_wakeref_t wakeref;
18622 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
18624 intel_early_display_was(dev_priv);
18625 intel_modeset_readout_hw_state(dev);
18627 /* HW state is read out, now we need to sanitize this mess. */
18629 /* Sanitize the TypeC port mode upfront, encoders depend on this */
18630 for_each_intel_encoder(dev, encoder) {
18631 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
18633 /* We need to sanitize only the MST primary port. */
18634 if (encoder->type != INTEL_OUTPUT_DP_MST &&
18635 intel_phy_is_tc(dev_priv, phy))
18636 intel_tc_port_sanitize(enc_to_dig_port(encoder));
18639 get_encoder_power_domains(dev_priv);
18641 if (HAS_PCH_IBX(dev_priv))
18642 ibx_sanitize_pch_ports(dev_priv);
18645 * intel_sanitize_plane_mapping() may need to do vblank
18646 * waits, so we need vblank interrupts restored beforehand.
18648 for_each_intel_crtc(&dev_priv->drm, crtc) {
18649 struct intel_crtc_state *crtc_state =
18650 to_intel_crtc_state(crtc->base.state);
18652 drm_crtc_vblank_reset(&crtc->base);
18654 if (crtc_state->hw.active)
18655 intel_crtc_vblank_on(crtc_state);
18658 intel_sanitize_plane_mapping(dev_priv);
18660 for_each_intel_encoder(dev, encoder)
18661 intel_sanitize_encoder(encoder);
18663 for_each_intel_crtc(&dev_priv->drm, crtc) {
18664 struct intel_crtc_state *crtc_state =
18665 to_intel_crtc_state(crtc->base.state);
18667 intel_sanitize_crtc(crtc, ctx);
18668 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
18671 intel_modeset_update_connector_atomic_state(dev);
18673 intel_dpll_sanitize_state(dev_priv);
18675 if (IS_G4X(dev_priv)) {
18676 g4x_wm_get_hw_state(dev_priv);
18677 g4x_wm_sanitize(dev_priv);
18678 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
18679 vlv_wm_get_hw_state(dev_priv);
18680 vlv_wm_sanitize(dev_priv);
18681 } else if (INTEL_GEN(dev_priv) >= 9) {
18682 skl_wm_get_hw_state(dev_priv);
18683 } else if (HAS_PCH_SPLIT(dev_priv)) {
18684 ilk_wm_get_hw_state(dev_priv);
18687 for_each_intel_crtc(dev, crtc) {
18688 struct intel_crtc_state *crtc_state =
18689 to_intel_crtc_state(crtc->base.state);
18692 put_domains = modeset_get_crtc_power_domains(crtc_state);
18693 if (drm_WARN_ON(dev, put_domains))
18694 modeset_put_power_domains(dev_priv, put_domains);
18697 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
18700 void intel_display_resume(struct drm_device *dev)
18702 struct drm_i915_private *dev_priv = to_i915(dev);
18703 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
18704 struct drm_modeset_acquire_ctx ctx;
18707 dev_priv->modeset_restore_state = NULL;
18709 state->acquire_ctx = &ctx;
18711 drm_modeset_acquire_init(&ctx, 0);
18714 ret = drm_modeset_lock_all_ctx(dev, &ctx);
18715 if (ret != -EDEADLK)
18718 drm_modeset_backoff(&ctx);
18722 ret = __intel_display_resume(dev, state, &ctx);
18724 intel_enable_ipc(dev_priv);
18725 drm_modeset_drop_locks(&ctx);
18726 drm_modeset_acquire_fini(&ctx);
18729 drm_err(&dev_priv->drm,
18730 "Restoring old state failed with %i\n", ret);
18732 drm_atomic_state_put(state);
18735 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
18737 struct intel_connector *connector;
18738 struct drm_connector_list_iter conn_iter;
18740 /* Kill all the work that may have been queued by hpd. */
18741 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
18742 for_each_intel_connector_iter(connector, &conn_iter) {
18743 if (connector->modeset_retry_work.func)
18744 cancel_work_sync(&connector->modeset_retry_work);
18745 if (connector->hdcp.shim) {
18746 cancel_delayed_work_sync(&connector->hdcp.check_work);
18747 cancel_work_sync(&connector->hdcp.prop_work);
18750 drm_connector_list_iter_end(&conn_iter);
18753 /* part #1: call before irq uninstall */
18754 void intel_modeset_driver_remove(struct drm_i915_private *i915)
18756 flush_workqueue(i915->flip_wq);
18757 flush_workqueue(i915->modeset_wq);
18759 flush_work(&i915->atomic_helper.free_work);
18760 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list));
18763 /* part #2: call after irq uninstall */
18764 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915)
18767 * Due to the hpd irq storm handling the hotplug work can re-arm the
18768 * poll handlers. Hence disable polling after hpd handling is shut down.
18770 intel_hpd_poll_fini(i915);
18773 * MST topology needs to be suspended so we don't have any calls to
18774 * fbdev after it's finalized. MST will be destroyed later as part of
18775 * drm_mode_config_cleanup()
18777 intel_dp_mst_suspend(i915);
18779 /* poll work can call into fbdev, hence clean that up afterwards */
18780 intel_fbdev_fini(i915);
18782 intel_unregister_dsm_handler();
18784 intel_fbc_global_disable(i915);
18786 /* flush any delayed tasks or pending work */
18787 flush_scheduled_work();
18789 intel_hdcp_component_fini(i915);
18791 intel_mode_config_cleanup(i915);
18793 intel_overlay_cleanup(i915);
18795 intel_gmbus_teardown(i915);
18797 destroy_workqueue(i915->flip_wq);
18798 destroy_workqueue(i915->modeset_wq);
18800 intel_fbc_cleanup_cfb(i915);
18803 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
18806 has_transcoder(struct drm_i915_private *dev_priv, enum transcoder cpu_transcoder)
18808 if (cpu_transcoder == TRANSCODER_EDP)
18809 return HAS_TRANSCODER_EDP(dev_priv);
18811 return INTEL_INFO(dev_priv)->pipe_mask & BIT(cpu_transcoder);
18814 struct intel_display_error_state {
18816 u32 power_well_driver;
18818 struct intel_cursor_error_state {
18823 } cursor[I915_MAX_PIPES];
18825 struct intel_pipe_error_state {
18826 bool power_domain_on;
18829 } pipe[I915_MAX_PIPES];
18831 struct intel_plane_error_state {
18839 } plane[I915_MAX_PIPES];
18841 struct intel_transcoder_error_state {
18843 bool power_domain_on;
18844 enum transcoder cpu_transcoder;
18857 struct intel_display_error_state *
18858 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
18860 struct intel_display_error_state *error;
18861 int transcoders[] = {
18870 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
18872 if (!HAS_DISPLAY(dev_priv) || !INTEL_DISPLAY_ENABLED(dev_priv))
18875 error = kzalloc(sizeof(*error), GFP_ATOMIC);
18879 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18880 error->power_well_driver = intel_de_read(dev_priv,
18881 HSW_PWR_WELL_CTL2);
18883 for_each_pipe(dev_priv, i) {
18884 error->pipe[i].power_domain_on =
18885 __intel_display_power_is_enabled(dev_priv,
18886 POWER_DOMAIN_PIPE(i));
18887 if (!error->pipe[i].power_domain_on)
18890 error->cursor[i].control = intel_de_read(dev_priv, CURCNTR(i));
18891 error->cursor[i].position = intel_de_read(dev_priv, CURPOS(i));
18892 error->cursor[i].base = intel_de_read(dev_priv, CURBASE(i));
18894 error->plane[i].control = intel_de_read(dev_priv, DSPCNTR(i));
18895 error->plane[i].stride = intel_de_read(dev_priv, DSPSTRIDE(i));
18896 if (INTEL_GEN(dev_priv) <= 3) {
18897 error->plane[i].size = intel_de_read(dev_priv,
18899 error->plane[i].pos = intel_de_read(dev_priv,
18902 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18903 error->plane[i].addr = intel_de_read(dev_priv,
18905 if (INTEL_GEN(dev_priv) >= 4) {
18906 error->plane[i].surface = intel_de_read(dev_priv,
18908 error->plane[i].tile_offset = intel_de_read(dev_priv,
18912 error->pipe[i].source = intel_de_read(dev_priv, PIPESRC(i));
18914 if (HAS_GMCH(dev_priv))
18915 error->pipe[i].stat = intel_de_read(dev_priv,
18919 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18920 enum transcoder cpu_transcoder = transcoders[i];
18922 if (!has_transcoder(dev_priv, cpu_transcoder))
18925 error->transcoder[i].available = true;
18926 error->transcoder[i].power_domain_on =
18927 __intel_display_power_is_enabled(dev_priv,
18928 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
18929 if (!error->transcoder[i].power_domain_on)
18932 error->transcoder[i].cpu_transcoder = cpu_transcoder;
18934 error->transcoder[i].conf = intel_de_read(dev_priv,
18935 PIPECONF(cpu_transcoder));
18936 error->transcoder[i].htotal = intel_de_read(dev_priv,
18937 HTOTAL(cpu_transcoder));
18938 error->transcoder[i].hblank = intel_de_read(dev_priv,
18939 HBLANK(cpu_transcoder));
18940 error->transcoder[i].hsync = intel_de_read(dev_priv,
18941 HSYNC(cpu_transcoder));
18942 error->transcoder[i].vtotal = intel_de_read(dev_priv,
18943 VTOTAL(cpu_transcoder));
18944 error->transcoder[i].vblank = intel_de_read(dev_priv,
18945 VBLANK(cpu_transcoder));
18946 error->transcoder[i].vsync = intel_de_read(dev_priv,
18947 VSYNC(cpu_transcoder));
18953 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
18956 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
18957 struct intel_display_error_state *error)
18959 struct drm_i915_private *dev_priv = m->i915;
18965 err_printf(m, "Num Pipes: %d\n", INTEL_NUM_PIPES(dev_priv));
18966 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
18967 err_printf(m, "PWR_WELL_CTL2: %08x\n",
18968 error->power_well_driver);
18969 for_each_pipe(dev_priv, i) {
18970 err_printf(m, "Pipe [%d]:\n", i);
18971 err_printf(m, " Power: %s\n",
18972 onoff(error->pipe[i].power_domain_on));
18973 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
18974 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
18976 err_printf(m, "Plane [%d]:\n", i);
18977 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
18978 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
18979 if (INTEL_GEN(dev_priv) <= 3) {
18980 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
18981 err_printf(m, " POS: %08x\n", error->plane[i].pos);
18983 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
18984 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
18985 if (INTEL_GEN(dev_priv) >= 4) {
18986 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
18987 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
18990 err_printf(m, "Cursor [%d]:\n", i);
18991 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
18992 err_printf(m, " POS: %08x\n", error->cursor[i].position);
18993 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
18996 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
18997 if (!error->transcoder[i].available)
19000 err_printf(m, "CPU transcoder: %s\n",
19001 transcoder_name(error->transcoder[i].cpu_transcoder));
19002 err_printf(m, " Power: %s\n",
19003 onoff(error->transcoder[i].power_domain_on));
19004 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
19005 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
19006 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
19007 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
19008 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
19009 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
19010 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);