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/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include "intel_frontbuffer.h"
38 #include <drm/i915_drm.h>
40 #include "i915_gem_clflush.h"
41 #include "intel_dsi.h"
42 #include "i915_trace.h"
43 #include <drm/drm_atomic.h>
44 #include <drm/drm_atomic_helper.h>
45 #include <drm/drm_dp_helper.h>
46 #include <drm/drm_crtc_helper.h>
47 #include <drm/drm_plane_helper.h>
48 #include <drm/drm_rect.h>
49 #include <linux/dma_remapping.h>
50 #include <linux/reservation.h>
52 /* Primary plane formats for gen <= 3 */
53 static const uint32_t i8xx_primary_formats[] = {
60 /* Primary plane formats for gen >= 4 */
61 static const uint32_t i965_primary_formats[] = {
66 DRM_FORMAT_XRGB2101010,
67 DRM_FORMAT_XBGR2101010,
70 static const uint64_t i9xx_format_modifiers[] = {
71 I915_FORMAT_MOD_X_TILED,
72 DRM_FORMAT_MOD_LINEAR,
73 DRM_FORMAT_MOD_INVALID
76 static const uint32_t skl_primary_formats[] = {
83 DRM_FORMAT_XRGB2101010,
84 DRM_FORMAT_XBGR2101010,
91 static const uint32_t skl_pri_planar_formats[] = {
98 DRM_FORMAT_XRGB2101010,
99 DRM_FORMAT_XBGR2101010,
107 static const uint64_t skl_format_modifiers_noccs[] = {
108 I915_FORMAT_MOD_Yf_TILED,
109 I915_FORMAT_MOD_Y_TILED,
110 I915_FORMAT_MOD_X_TILED,
111 DRM_FORMAT_MOD_LINEAR,
112 DRM_FORMAT_MOD_INVALID
115 static const uint64_t skl_format_modifiers_ccs[] = {
116 I915_FORMAT_MOD_Yf_TILED_CCS,
117 I915_FORMAT_MOD_Y_TILED_CCS,
118 I915_FORMAT_MOD_Yf_TILED,
119 I915_FORMAT_MOD_Y_TILED,
120 I915_FORMAT_MOD_X_TILED,
121 DRM_FORMAT_MOD_LINEAR,
122 DRM_FORMAT_MOD_INVALID
126 static const uint32_t intel_cursor_formats[] = {
130 static const uint64_t cursor_format_modifiers[] = {
131 DRM_FORMAT_MOD_LINEAR,
132 DRM_FORMAT_MOD_INVALID
135 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
136 struct intel_crtc_state *pipe_config);
137 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
138 struct intel_crtc_state *pipe_config);
140 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
141 struct drm_i915_gem_object *obj,
142 struct drm_mode_fb_cmd2 *mode_cmd);
143 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
144 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
145 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc);
146 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
147 struct intel_link_m_n *m_n,
148 struct intel_link_m_n *m2_n2);
149 static void ironlake_set_pipeconf(struct drm_crtc *crtc);
150 static void haswell_set_pipeconf(struct drm_crtc *crtc);
151 static void haswell_set_pipemisc(struct drm_crtc *crtc);
152 static void vlv_prepare_pll(struct intel_crtc *crtc,
153 const struct intel_crtc_state *pipe_config);
154 static void chv_prepare_pll(struct intel_crtc *crtc,
155 const struct intel_crtc_state *pipe_config);
156 static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
157 static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
158 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
159 struct intel_crtc_state *crtc_state);
160 static void skylake_pfit_enable(struct intel_crtc *crtc);
161 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force);
162 static void ironlake_pfit_enable(struct intel_crtc *crtc);
163 static void intel_modeset_setup_hw_state(struct drm_device *dev,
164 struct drm_modeset_acquire_ctx *ctx);
165 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
170 } dot, vco, n, m, m1, m2, p, p1;
174 int p2_slow, p2_fast;
178 /* returns HPLL frequency in kHz */
179 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
181 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
183 /* Obtain SKU information */
184 mutex_lock(&dev_priv->sb_lock);
185 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
186 CCK_FUSE_HPLL_FREQ_MASK;
187 mutex_unlock(&dev_priv->sb_lock);
189 return vco_freq[hpll_freq] * 1000;
192 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
193 const char *name, u32 reg, int ref_freq)
198 mutex_lock(&dev_priv->sb_lock);
199 val = vlv_cck_read(dev_priv, reg);
200 mutex_unlock(&dev_priv->sb_lock);
202 divider = val & CCK_FREQUENCY_VALUES;
204 WARN((val & CCK_FREQUENCY_STATUS) !=
205 (divider << CCK_FREQUENCY_STATUS_SHIFT),
206 "%s change in progress\n", name);
208 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
211 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
212 const char *name, u32 reg)
214 if (dev_priv->hpll_freq == 0)
215 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
217 return vlv_get_cck_clock(dev_priv, name, reg,
218 dev_priv->hpll_freq);
221 static void intel_update_czclk(struct drm_i915_private *dev_priv)
223 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
226 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
227 CCK_CZ_CLOCK_CONTROL);
229 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
232 static inline u32 /* units of 100MHz */
233 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
234 const struct intel_crtc_state *pipe_config)
236 if (HAS_DDI(dev_priv))
237 return pipe_config->port_clock; /* SPLL */
239 return dev_priv->fdi_pll_freq;
242 static const struct intel_limit intel_limits_i8xx_dac = {
243 .dot = { .min = 25000, .max = 350000 },
244 .vco = { .min = 908000, .max = 1512000 },
245 .n = { .min = 2, .max = 16 },
246 .m = { .min = 96, .max = 140 },
247 .m1 = { .min = 18, .max = 26 },
248 .m2 = { .min = 6, .max = 16 },
249 .p = { .min = 4, .max = 128 },
250 .p1 = { .min = 2, .max = 33 },
251 .p2 = { .dot_limit = 165000,
252 .p2_slow = 4, .p2_fast = 2 },
255 static const struct intel_limit intel_limits_i8xx_dvo = {
256 .dot = { .min = 25000, .max = 350000 },
257 .vco = { .min = 908000, .max = 1512000 },
258 .n = { .min = 2, .max = 16 },
259 .m = { .min = 96, .max = 140 },
260 .m1 = { .min = 18, .max = 26 },
261 .m2 = { .min = 6, .max = 16 },
262 .p = { .min = 4, .max = 128 },
263 .p1 = { .min = 2, .max = 33 },
264 .p2 = { .dot_limit = 165000,
265 .p2_slow = 4, .p2_fast = 4 },
268 static const struct intel_limit intel_limits_i8xx_lvds = {
269 .dot = { .min = 25000, .max = 350000 },
270 .vco = { .min = 908000, .max = 1512000 },
271 .n = { .min = 2, .max = 16 },
272 .m = { .min = 96, .max = 140 },
273 .m1 = { .min = 18, .max = 26 },
274 .m2 = { .min = 6, .max = 16 },
275 .p = { .min = 4, .max = 128 },
276 .p1 = { .min = 1, .max = 6 },
277 .p2 = { .dot_limit = 165000,
278 .p2_slow = 14, .p2_fast = 7 },
281 static const struct intel_limit intel_limits_i9xx_sdvo = {
282 .dot = { .min = 20000, .max = 400000 },
283 .vco = { .min = 1400000, .max = 2800000 },
284 .n = { .min = 1, .max = 6 },
285 .m = { .min = 70, .max = 120 },
286 .m1 = { .min = 8, .max = 18 },
287 .m2 = { .min = 3, .max = 7 },
288 .p = { .min = 5, .max = 80 },
289 .p1 = { .min = 1, .max = 8 },
290 .p2 = { .dot_limit = 200000,
291 .p2_slow = 10, .p2_fast = 5 },
294 static const struct intel_limit intel_limits_i9xx_lvds = {
295 .dot = { .min = 20000, .max = 400000 },
296 .vco = { .min = 1400000, .max = 2800000 },
297 .n = { .min = 1, .max = 6 },
298 .m = { .min = 70, .max = 120 },
299 .m1 = { .min = 8, .max = 18 },
300 .m2 = { .min = 3, .max = 7 },
301 .p = { .min = 7, .max = 98 },
302 .p1 = { .min = 1, .max = 8 },
303 .p2 = { .dot_limit = 112000,
304 .p2_slow = 14, .p2_fast = 7 },
308 static const struct intel_limit intel_limits_g4x_sdvo = {
309 .dot = { .min = 25000, .max = 270000 },
310 .vco = { .min = 1750000, .max = 3500000},
311 .n = { .min = 1, .max = 4 },
312 .m = { .min = 104, .max = 138 },
313 .m1 = { .min = 17, .max = 23 },
314 .m2 = { .min = 5, .max = 11 },
315 .p = { .min = 10, .max = 30 },
316 .p1 = { .min = 1, .max = 3},
317 .p2 = { .dot_limit = 270000,
323 static const struct intel_limit intel_limits_g4x_hdmi = {
324 .dot = { .min = 22000, .max = 400000 },
325 .vco = { .min = 1750000, .max = 3500000},
326 .n = { .min = 1, .max = 4 },
327 .m = { .min = 104, .max = 138 },
328 .m1 = { .min = 16, .max = 23 },
329 .m2 = { .min = 5, .max = 11 },
330 .p = { .min = 5, .max = 80 },
331 .p1 = { .min = 1, .max = 8},
332 .p2 = { .dot_limit = 165000,
333 .p2_slow = 10, .p2_fast = 5 },
336 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
337 .dot = { .min = 20000, .max = 115000 },
338 .vco = { .min = 1750000, .max = 3500000 },
339 .n = { .min = 1, .max = 3 },
340 .m = { .min = 104, .max = 138 },
341 .m1 = { .min = 17, .max = 23 },
342 .m2 = { .min = 5, .max = 11 },
343 .p = { .min = 28, .max = 112 },
344 .p1 = { .min = 2, .max = 8 },
345 .p2 = { .dot_limit = 0,
346 .p2_slow = 14, .p2_fast = 14
350 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
351 .dot = { .min = 80000, .max = 224000 },
352 .vco = { .min = 1750000, .max = 3500000 },
353 .n = { .min = 1, .max = 3 },
354 .m = { .min = 104, .max = 138 },
355 .m1 = { .min = 17, .max = 23 },
356 .m2 = { .min = 5, .max = 11 },
357 .p = { .min = 14, .max = 42 },
358 .p1 = { .min = 2, .max = 6 },
359 .p2 = { .dot_limit = 0,
360 .p2_slow = 7, .p2_fast = 7
364 static const struct intel_limit intel_limits_pineview_sdvo = {
365 .dot = { .min = 20000, .max = 400000},
366 .vco = { .min = 1700000, .max = 3500000 },
367 /* Pineview's Ncounter is a ring counter */
368 .n = { .min = 3, .max = 6 },
369 .m = { .min = 2, .max = 256 },
370 /* Pineview only has one combined m divider, which we treat as m2. */
371 .m1 = { .min = 0, .max = 0 },
372 .m2 = { .min = 0, .max = 254 },
373 .p = { .min = 5, .max = 80 },
374 .p1 = { .min = 1, .max = 8 },
375 .p2 = { .dot_limit = 200000,
376 .p2_slow = 10, .p2_fast = 5 },
379 static const struct intel_limit intel_limits_pineview_lvds = {
380 .dot = { .min = 20000, .max = 400000 },
381 .vco = { .min = 1700000, .max = 3500000 },
382 .n = { .min = 3, .max = 6 },
383 .m = { .min = 2, .max = 256 },
384 .m1 = { .min = 0, .max = 0 },
385 .m2 = { .min = 0, .max = 254 },
386 .p = { .min = 7, .max = 112 },
387 .p1 = { .min = 1, .max = 8 },
388 .p2 = { .dot_limit = 112000,
389 .p2_slow = 14, .p2_fast = 14 },
392 /* Ironlake / Sandybridge
394 * We calculate clock using (register_value + 2) for N/M1/M2, so here
395 * the range value for them is (actual_value - 2).
397 static const struct intel_limit intel_limits_ironlake_dac = {
398 .dot = { .min = 25000, .max = 350000 },
399 .vco = { .min = 1760000, .max = 3510000 },
400 .n = { .min = 1, .max = 5 },
401 .m = { .min = 79, .max = 127 },
402 .m1 = { .min = 12, .max = 22 },
403 .m2 = { .min = 5, .max = 9 },
404 .p = { .min = 5, .max = 80 },
405 .p1 = { .min = 1, .max = 8 },
406 .p2 = { .dot_limit = 225000,
407 .p2_slow = 10, .p2_fast = 5 },
410 static const struct intel_limit intel_limits_ironlake_single_lvds = {
411 .dot = { .min = 25000, .max = 350000 },
412 .vco = { .min = 1760000, .max = 3510000 },
413 .n = { .min = 1, .max = 3 },
414 .m = { .min = 79, .max = 118 },
415 .m1 = { .min = 12, .max = 22 },
416 .m2 = { .min = 5, .max = 9 },
417 .p = { .min = 28, .max = 112 },
418 .p1 = { .min = 2, .max = 8 },
419 .p2 = { .dot_limit = 225000,
420 .p2_slow = 14, .p2_fast = 14 },
423 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
424 .dot = { .min = 25000, .max = 350000 },
425 .vco = { .min = 1760000, .max = 3510000 },
426 .n = { .min = 1, .max = 3 },
427 .m = { .min = 79, .max = 127 },
428 .m1 = { .min = 12, .max = 22 },
429 .m2 = { .min = 5, .max = 9 },
430 .p = { .min = 14, .max = 56 },
431 .p1 = { .min = 2, .max = 8 },
432 .p2 = { .dot_limit = 225000,
433 .p2_slow = 7, .p2_fast = 7 },
436 /* LVDS 100mhz refclk limits. */
437 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
438 .dot = { .min = 25000, .max = 350000 },
439 .vco = { .min = 1760000, .max = 3510000 },
440 .n = { .min = 1, .max = 2 },
441 .m = { .min = 79, .max = 126 },
442 .m1 = { .min = 12, .max = 22 },
443 .m2 = { .min = 5, .max = 9 },
444 .p = { .min = 28, .max = 112 },
445 .p1 = { .min = 2, .max = 8 },
446 .p2 = { .dot_limit = 225000,
447 .p2_slow = 14, .p2_fast = 14 },
450 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
451 .dot = { .min = 25000, .max = 350000 },
452 .vco = { .min = 1760000, .max = 3510000 },
453 .n = { .min = 1, .max = 3 },
454 .m = { .min = 79, .max = 126 },
455 .m1 = { .min = 12, .max = 22 },
456 .m2 = { .min = 5, .max = 9 },
457 .p = { .min = 14, .max = 42 },
458 .p1 = { .min = 2, .max = 6 },
459 .p2 = { .dot_limit = 225000,
460 .p2_slow = 7, .p2_fast = 7 },
463 static const struct intel_limit intel_limits_vlv = {
465 * These are the data rate limits (measured in fast clocks)
466 * since those are the strictest limits we have. The fast
467 * clock and actual rate limits are more relaxed, so checking
468 * them would make no difference.
470 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
471 .vco = { .min = 4000000, .max = 6000000 },
472 .n = { .min = 1, .max = 7 },
473 .m1 = { .min = 2, .max = 3 },
474 .m2 = { .min = 11, .max = 156 },
475 .p1 = { .min = 2, .max = 3 },
476 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
479 static const struct intel_limit intel_limits_chv = {
481 * These are the data rate limits (measured in fast clocks)
482 * since those are the strictest limits we have. The fast
483 * clock and actual rate limits are more relaxed, so checking
484 * them would make no difference.
486 .dot = { .min = 25000 * 5, .max = 540000 * 5},
487 .vco = { .min = 4800000, .max = 6480000 },
488 .n = { .min = 1, .max = 1 },
489 .m1 = { .min = 2, .max = 2 },
490 .m2 = { .min = 24 << 22, .max = 175 << 22 },
491 .p1 = { .min = 2, .max = 4 },
492 .p2 = { .p2_slow = 1, .p2_fast = 14 },
495 static const struct intel_limit intel_limits_bxt = {
496 /* FIXME: find real dot limits */
497 .dot = { .min = 0, .max = INT_MAX },
498 .vco = { .min = 4800000, .max = 6700000 },
499 .n = { .min = 1, .max = 1 },
500 .m1 = { .min = 2, .max = 2 },
501 /* FIXME: find real m2 limits */
502 .m2 = { .min = 2 << 22, .max = 255 << 22 },
503 .p1 = { .min = 2, .max = 4 },
504 .p2 = { .p2_slow = 1, .p2_fast = 20 },
508 skl_wa_528(struct drm_i915_private *dev_priv, int pipe, bool enable)
510 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
514 I915_WRITE(CHICKEN_PIPESL_1(pipe), HSW_FBCQ_DIS);
516 I915_WRITE(CHICKEN_PIPESL_1(pipe), 0);
520 skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
522 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
526 I915_WRITE(CLKGATE_DIS_PSL(pipe),
527 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
529 I915_WRITE(CLKGATE_DIS_PSL(pipe),
530 I915_READ(CLKGATE_DIS_PSL(pipe)) &
531 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
535 needs_modeset(const struct drm_crtc_state *state)
537 return drm_atomic_crtc_needs_modeset(state);
541 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
542 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
543 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
544 * The helpers' return value is the rate of the clock that is fed to the
545 * display engine's pipe which can be the above fast dot clock rate or a
546 * divided-down version of it.
548 /* m1 is reserved as 0 in Pineview, n is a ring counter */
549 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
551 clock->m = clock->m2 + 2;
552 clock->p = clock->p1 * clock->p2;
553 if (WARN_ON(clock->n == 0 || clock->p == 0))
555 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
556 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
561 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
563 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
566 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
568 clock->m = i9xx_dpll_compute_m(clock);
569 clock->p = clock->p1 * clock->p2;
570 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
572 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
573 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
578 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
580 clock->m = clock->m1 * clock->m2;
581 clock->p = clock->p1 * clock->p2;
582 if (WARN_ON(clock->n == 0 || clock->p == 0))
584 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
585 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
587 return clock->dot / 5;
590 int chv_calc_dpll_params(int refclk, struct dpll *clock)
592 clock->m = clock->m1 * clock->m2;
593 clock->p = clock->p1 * clock->p2;
594 if (WARN_ON(clock->n == 0 || clock->p == 0))
596 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
598 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
600 return clock->dot / 5;
603 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
606 * Returns whether the given set of divisors are valid for a given refclk with
607 * the given connectors.
609 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
610 const struct intel_limit *limit,
611 const struct dpll *clock)
613 if (clock->n < limit->n.min || limit->n.max < clock->n)
614 INTELPllInvalid("n out of range\n");
615 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
616 INTELPllInvalid("p1 out of range\n");
617 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
618 INTELPllInvalid("m2 out of range\n");
619 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
620 INTELPllInvalid("m1 out of range\n");
622 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
623 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
624 if (clock->m1 <= clock->m2)
625 INTELPllInvalid("m1 <= m2\n");
627 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
628 !IS_GEN9_LP(dev_priv)) {
629 if (clock->p < limit->p.min || limit->p.max < clock->p)
630 INTELPllInvalid("p out of range\n");
631 if (clock->m < limit->m.min || limit->m.max < clock->m)
632 INTELPllInvalid("m out of range\n");
635 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
636 INTELPllInvalid("vco out of range\n");
637 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
638 * connector, etc., rather than just a single range.
640 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
641 INTELPllInvalid("dot out of range\n");
647 i9xx_select_p2_div(const struct intel_limit *limit,
648 const struct intel_crtc_state *crtc_state,
651 struct drm_device *dev = crtc_state->base.crtc->dev;
653 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
655 * For LVDS just rely on its current settings for dual-channel.
656 * We haven't figured out how to reliably set up different
657 * single/dual channel state, if we even can.
659 if (intel_is_dual_link_lvds(dev))
660 return limit->p2.p2_fast;
662 return limit->p2.p2_slow;
664 if (target < limit->p2.dot_limit)
665 return limit->p2.p2_slow;
667 return limit->p2.p2_fast;
672 * Returns a set of divisors for the desired target clock with the given
673 * refclk, or FALSE. The returned values represent the clock equation:
674 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
676 * Target and reference clocks are specified in kHz.
678 * If match_clock is provided, then best_clock P divider must match the P
679 * divider from @match_clock used for LVDS downclocking.
682 i9xx_find_best_dpll(const struct intel_limit *limit,
683 struct intel_crtc_state *crtc_state,
684 int target, int refclk, struct dpll *match_clock,
685 struct dpll *best_clock)
687 struct drm_device *dev = crtc_state->base.crtc->dev;
691 memset(best_clock, 0, sizeof(*best_clock));
693 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
695 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
697 for (clock.m2 = limit->m2.min;
698 clock.m2 <= limit->m2.max; clock.m2++) {
699 if (clock.m2 >= clock.m1)
701 for (clock.n = limit->n.min;
702 clock.n <= limit->n.max; clock.n++) {
703 for (clock.p1 = limit->p1.min;
704 clock.p1 <= limit->p1.max; clock.p1++) {
707 i9xx_calc_dpll_params(refclk, &clock);
708 if (!intel_PLL_is_valid(to_i915(dev),
713 clock.p != match_clock->p)
716 this_err = abs(clock.dot - target);
717 if (this_err < err) {
726 return (err != target);
730 * Returns a set of divisors for the desired target clock with the given
731 * refclk, or FALSE. The returned values represent the clock equation:
732 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
734 * Target and reference clocks are specified in kHz.
736 * If match_clock is provided, then best_clock P divider must match the P
737 * divider from @match_clock used for LVDS downclocking.
740 pnv_find_best_dpll(const struct intel_limit *limit,
741 struct intel_crtc_state *crtc_state,
742 int target, int refclk, struct dpll *match_clock,
743 struct dpll *best_clock)
745 struct drm_device *dev = crtc_state->base.crtc->dev;
749 memset(best_clock, 0, sizeof(*best_clock));
751 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
753 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
755 for (clock.m2 = limit->m2.min;
756 clock.m2 <= limit->m2.max; clock.m2++) {
757 for (clock.n = limit->n.min;
758 clock.n <= limit->n.max; clock.n++) {
759 for (clock.p1 = limit->p1.min;
760 clock.p1 <= limit->p1.max; clock.p1++) {
763 pnv_calc_dpll_params(refclk, &clock);
764 if (!intel_PLL_is_valid(to_i915(dev),
769 clock.p != match_clock->p)
772 this_err = abs(clock.dot - target);
773 if (this_err < err) {
782 return (err != target);
786 * Returns a set of divisors for the desired target clock with the given
787 * refclk, or FALSE. The returned values represent the clock equation:
788 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
790 * Target and reference clocks are specified in kHz.
792 * If match_clock is provided, then best_clock P divider must match the P
793 * divider from @match_clock used for LVDS downclocking.
796 g4x_find_best_dpll(const struct intel_limit *limit,
797 struct intel_crtc_state *crtc_state,
798 int target, int refclk, struct dpll *match_clock,
799 struct dpll *best_clock)
801 struct drm_device *dev = crtc_state->base.crtc->dev;
805 /* approximately equals target * 0.00585 */
806 int err_most = (target >> 8) + (target >> 9);
808 memset(best_clock, 0, sizeof(*best_clock));
810 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
812 max_n = limit->n.max;
813 /* based on hardware requirement, prefer smaller n to precision */
814 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
815 /* based on hardware requirement, prefere larger m1,m2 */
816 for (clock.m1 = limit->m1.max;
817 clock.m1 >= limit->m1.min; clock.m1--) {
818 for (clock.m2 = limit->m2.max;
819 clock.m2 >= limit->m2.min; clock.m2--) {
820 for (clock.p1 = limit->p1.max;
821 clock.p1 >= limit->p1.min; clock.p1--) {
824 i9xx_calc_dpll_params(refclk, &clock);
825 if (!intel_PLL_is_valid(to_i915(dev),
830 this_err = abs(clock.dot - target);
831 if (this_err < err_most) {
845 * Check if the calculated PLL configuration is more optimal compared to the
846 * best configuration and error found so far. Return the calculated error.
848 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
849 const struct dpll *calculated_clock,
850 const struct dpll *best_clock,
851 unsigned int best_error_ppm,
852 unsigned int *error_ppm)
855 * For CHV ignore the error and consider only the P value.
856 * Prefer a bigger P value based on HW requirements.
858 if (IS_CHERRYVIEW(to_i915(dev))) {
861 return calculated_clock->p > best_clock->p;
864 if (WARN_ON_ONCE(!target_freq))
867 *error_ppm = div_u64(1000000ULL *
868 abs(target_freq - calculated_clock->dot),
871 * Prefer a better P value over a better (smaller) error if the error
872 * is small. Ensure this preference for future configurations too by
873 * setting the error to 0.
875 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
881 return *error_ppm + 10 < best_error_ppm;
885 * Returns a set of divisors for the desired target clock with the given
886 * refclk, or FALSE. The returned values represent the clock equation:
887 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
890 vlv_find_best_dpll(const struct intel_limit *limit,
891 struct intel_crtc_state *crtc_state,
892 int target, int refclk, struct dpll *match_clock,
893 struct dpll *best_clock)
895 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
896 struct drm_device *dev = crtc->base.dev;
898 unsigned int bestppm = 1000000;
899 /* min update 19.2 MHz */
900 int max_n = min(limit->n.max, refclk / 19200);
903 target *= 5; /* fast clock */
905 memset(best_clock, 0, sizeof(*best_clock));
907 /* based on hardware requirement, prefer smaller n to precision */
908 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
909 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
910 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
911 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
912 clock.p = clock.p1 * clock.p2;
913 /* based on hardware requirement, prefer bigger m1,m2 values */
914 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
917 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
920 vlv_calc_dpll_params(refclk, &clock);
922 if (!intel_PLL_is_valid(to_i915(dev),
927 if (!vlv_PLL_is_optimal(dev, target,
945 * Returns a set of divisors for the desired target clock with the given
946 * refclk, or FALSE. The returned values represent the clock equation:
947 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
950 chv_find_best_dpll(const struct intel_limit *limit,
951 struct intel_crtc_state *crtc_state,
952 int target, int refclk, struct dpll *match_clock,
953 struct dpll *best_clock)
955 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
956 struct drm_device *dev = crtc->base.dev;
957 unsigned int best_error_ppm;
962 memset(best_clock, 0, sizeof(*best_clock));
963 best_error_ppm = 1000000;
966 * Based on hardware doc, the n always set to 1, and m1 always
967 * set to 2. If requires to support 200Mhz refclk, we need to
968 * revisit this because n may not 1 anymore.
970 clock.n = 1, clock.m1 = 2;
971 target *= 5; /* fast clock */
973 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
974 for (clock.p2 = limit->p2.p2_fast;
975 clock.p2 >= limit->p2.p2_slow;
976 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
977 unsigned int error_ppm;
979 clock.p = clock.p1 * clock.p2;
981 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
982 clock.n) << 22, refclk * clock.m1);
984 if (m2 > INT_MAX/clock.m1)
989 chv_calc_dpll_params(refclk, &clock);
991 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
994 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
995 best_error_ppm, &error_ppm))
999 best_error_ppm = error_ppm;
1007 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
1008 struct dpll *best_clock)
1010 int refclk = 100000;
1011 const struct intel_limit *limit = &intel_limits_bxt;
1013 return chv_find_best_dpll(limit, crtc_state,
1014 target_clock, refclk, NULL, best_clock);
1017 bool intel_crtc_active(struct intel_crtc *crtc)
1019 /* Be paranoid as we can arrive here with only partial
1020 * state retrieved from the hardware during setup.
1022 * We can ditch the adjusted_mode.crtc_clock check as soon
1023 * as Haswell has gained clock readout/fastboot support.
1025 * We can ditch the crtc->primary->state->fb check as soon as we can
1026 * properly reconstruct framebuffers.
1028 * FIXME: The intel_crtc->active here should be switched to
1029 * crtc->state->active once we have proper CRTC states wired up
1032 return crtc->active && crtc->base.primary->state->fb &&
1033 crtc->config->base.adjusted_mode.crtc_clock;
1036 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
1039 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1041 return crtc->config->cpu_transcoder;
1044 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1047 i915_reg_t reg = PIPEDSL(pipe);
1051 if (IS_GEN2(dev_priv))
1052 line_mask = DSL_LINEMASK_GEN2;
1054 line_mask = DSL_LINEMASK_GEN3;
1056 line1 = I915_READ(reg) & line_mask;
1058 line2 = I915_READ(reg) & line_mask;
1060 return line1 != line2;
1063 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1065 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1066 enum pipe pipe = crtc->pipe;
1068 /* Wait for the display line to settle/start moving */
1069 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1070 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1071 pipe_name(pipe), onoff(state));
1074 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1076 wait_for_pipe_scanline_moving(crtc, false);
1079 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1081 wait_for_pipe_scanline_moving(crtc, true);
1085 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1087 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1088 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1090 if (INTEL_GEN(dev_priv) >= 4) {
1091 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1092 i915_reg_t reg = PIPECONF(cpu_transcoder);
1094 /* Wait for the Pipe State to go off */
1095 if (intel_wait_for_register(dev_priv,
1096 reg, I965_PIPECONF_ACTIVE, 0,
1098 WARN(1, "pipe_off wait timed out\n");
1100 intel_wait_for_pipe_scanline_stopped(crtc);
1104 /* Only for pre-ILK configs */
1105 void assert_pll(struct drm_i915_private *dev_priv,
1106 enum pipe pipe, bool state)
1111 val = I915_READ(DPLL(pipe));
1112 cur_state = !!(val & DPLL_VCO_ENABLE);
1113 I915_STATE_WARN(cur_state != state,
1114 "PLL state assertion failure (expected %s, current %s)\n",
1115 onoff(state), onoff(cur_state));
1118 /* XXX: the dsi pll is shared between MIPI DSI ports */
1119 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1124 mutex_lock(&dev_priv->sb_lock);
1125 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1126 mutex_unlock(&dev_priv->sb_lock);
1128 cur_state = val & DSI_PLL_VCO_EN;
1129 I915_STATE_WARN(cur_state != state,
1130 "DSI PLL state assertion failure (expected %s, current %s)\n",
1131 onoff(state), onoff(cur_state));
1134 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1135 enum pipe pipe, bool state)
1138 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1141 if (HAS_DDI(dev_priv)) {
1142 /* DDI does not have a specific FDI_TX register */
1143 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1144 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1146 u32 val = I915_READ(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 = I915_READ(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_GEN5(dev_priv))
1180 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1181 if (HAS_DDI(dev_priv))
1184 val = I915_READ(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 = I915_READ(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 (WARN_ON(HAS_DDI(dev_priv)))
1211 if (HAS_PCH_SPLIT(dev_priv)) {
1214 pp_reg = PP_CONTROL(0);
1215 port_sel = I915_READ(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 = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1244 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1245 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1248 val = I915_READ(pp_reg);
1249 if (!(val & PANEL_POWER_ON) ||
1250 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1253 I915_STATE_WARN(panel_pipe == pipe && locked,
1254 "panel assertion failure, pipe %c regs locked\n",
1258 void assert_pipe(struct drm_i915_private *dev_priv,
1259 enum pipe pipe, bool state)
1262 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1264 enum intel_display_power_domain power_domain;
1266 /* we keep both pipes enabled on 830 */
1267 if (IS_I830(dev_priv))
1270 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1271 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
1272 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1273 cur_state = !!(val & PIPECONF_ENABLE);
1275 intel_display_power_put(dev_priv, power_domain);
1280 I915_STATE_WARN(cur_state != state,
1281 "pipe %c assertion failure (expected %s, current %s)\n",
1282 pipe_name(pipe), onoff(state), onoff(cur_state));
1285 static void assert_plane(struct intel_plane *plane, bool state)
1290 cur_state = plane->get_hw_state(plane, &pipe);
1292 I915_STATE_WARN(cur_state != state,
1293 "%s assertion failure (expected %s, current %s)\n",
1294 plane->base.name, onoff(state), onoff(cur_state));
1297 #define assert_plane_enabled(p) assert_plane(p, true)
1298 #define assert_plane_disabled(p) assert_plane(p, false)
1300 static void assert_planes_disabled(struct intel_crtc *crtc)
1302 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1303 struct intel_plane *plane;
1305 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1306 assert_plane_disabled(plane);
1309 static void assert_vblank_disabled(struct drm_crtc *crtc)
1311 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1312 drm_crtc_vblank_put(crtc);
1315 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1321 val = I915_READ(PCH_TRANSCONF(pipe));
1322 enabled = !!(val & TRANS_ENABLE);
1323 I915_STATE_WARN(enabled,
1324 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1328 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1329 enum pipe pipe, enum port port,
1332 enum pipe port_pipe;
1335 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1337 I915_STATE_WARN(state && port_pipe == pipe,
1338 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1339 port_name(port), pipe_name(pipe));
1341 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1342 "IBX PCH DP %c still using transcoder B\n",
1346 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1347 enum pipe pipe, enum port port,
1348 i915_reg_t hdmi_reg)
1350 enum pipe port_pipe;
1353 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1355 I915_STATE_WARN(state && port_pipe == pipe,
1356 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1357 port_name(port), pipe_name(pipe));
1359 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1360 "IBX PCH HDMI %c still using transcoder B\n",
1364 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1367 enum pipe port_pipe;
1369 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1370 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1371 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1373 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1375 "PCH VGA enabled on transcoder %c, should be disabled\n",
1378 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1380 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1383 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1384 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1385 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1388 static void _vlv_enable_pll(struct intel_crtc *crtc,
1389 const struct intel_crtc_state *pipe_config)
1391 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1392 enum pipe pipe = crtc->pipe;
1394 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1395 POSTING_READ(DPLL(pipe));
1398 if (intel_wait_for_register(dev_priv,
1403 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1406 static void vlv_enable_pll(struct intel_crtc *crtc,
1407 const struct intel_crtc_state *pipe_config)
1409 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1410 enum pipe pipe = crtc->pipe;
1412 assert_pipe_disabled(dev_priv, pipe);
1414 /* PLL is protected by panel, make sure we can write it */
1415 assert_panel_unlocked(dev_priv, pipe);
1417 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1418 _vlv_enable_pll(crtc, pipe_config);
1420 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1421 POSTING_READ(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 mutex_lock(&dev_priv->sb_lock);
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 mutex_unlock(&dev_priv->sb_lock);
1443 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1448 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1450 /* Check PLL is locked */
1451 if (intel_wait_for_register(dev_priv,
1452 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1454 DRM_ERROR("PLL %d failed to lock\n", pipe);
1457 static void chv_enable_pll(struct intel_crtc *crtc,
1458 const struct intel_crtc_state *pipe_config)
1460 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1461 enum pipe pipe = crtc->pipe;
1463 assert_pipe_disabled(dev_priv, pipe);
1465 /* PLL is protected by panel, make sure we can write it */
1466 assert_panel_unlocked(dev_priv, pipe);
1468 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1469 _chv_enable_pll(crtc, pipe_config);
1471 if (pipe != PIPE_A) {
1473 * WaPixelRepeatModeFixForC0:chv
1475 * DPLLCMD is AWOL. Use chicken bits to propagate
1476 * the value from DPLLBMD to either pipe B or C.
1478 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1479 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1480 I915_WRITE(CBR4_VLV, 0);
1481 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1484 * DPLLB VGA mode also seems to cause problems.
1485 * We should always have it disabled.
1487 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1489 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1490 POSTING_READ(DPLL_MD(pipe));
1494 static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
1496 struct intel_crtc *crtc;
1499 for_each_intel_crtc(&dev_priv->drm, crtc) {
1500 count += crtc->base.state->active &&
1501 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1507 static void i9xx_enable_pll(struct intel_crtc *crtc,
1508 const struct intel_crtc_state *crtc_state)
1510 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1511 i915_reg_t reg = DPLL(crtc->pipe);
1512 u32 dpll = crtc_state->dpll_hw_state.dpll;
1515 assert_pipe_disabled(dev_priv, crtc->pipe);
1517 /* PLL is protected by panel, make sure we can write it */
1518 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
1519 assert_panel_unlocked(dev_priv, crtc->pipe);
1521 /* Enable DVO 2x clock on both PLLs if necessary */
1522 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
1524 * It appears to be important that we don't enable this
1525 * for the current pipe before otherwise configuring the
1526 * PLL. No idea how this should be handled if multiple
1527 * DVO outputs are enabled simultaneosly.
1529 dpll |= DPLL_DVO_2X_MODE;
1530 I915_WRITE(DPLL(!crtc->pipe),
1531 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1535 * Apparently we need to have VGA mode enabled prior to changing
1536 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1537 * dividers, even though the register value does change.
1541 I915_WRITE(reg, dpll);
1543 /* Wait for the clocks to stabilize. */
1547 if (INTEL_GEN(dev_priv) >= 4) {
1548 I915_WRITE(DPLL_MD(crtc->pipe),
1549 crtc_state->dpll_hw_state.dpll_md);
1551 /* The pixel multiplier can only be updated once the
1552 * DPLL is enabled and the clocks are stable.
1554 * So write it again.
1556 I915_WRITE(reg, dpll);
1559 /* We do this three times for luck */
1560 for (i = 0; i < 3; i++) {
1561 I915_WRITE(reg, dpll);
1563 udelay(150); /* wait for warmup */
1567 static void i9xx_disable_pll(struct intel_crtc *crtc)
1569 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1570 enum pipe pipe = crtc->pipe;
1572 /* Disable DVO 2x clock on both PLLs if necessary */
1573 if (IS_I830(dev_priv) &&
1574 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) &&
1575 !intel_num_dvo_pipes(dev_priv)) {
1576 I915_WRITE(DPLL(PIPE_B),
1577 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1578 I915_WRITE(DPLL(PIPE_A),
1579 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1582 /* Don't disable pipe or pipe PLLs if needed */
1583 if (IS_I830(dev_priv))
1586 /* Make sure the pipe isn't still relying on us */
1587 assert_pipe_disabled(dev_priv, pipe);
1589 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1590 POSTING_READ(DPLL(pipe));
1593 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1597 /* Make sure the pipe isn't still relying on us */
1598 assert_pipe_disabled(dev_priv, pipe);
1600 val = DPLL_INTEGRATED_REF_CLK_VLV |
1601 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1603 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1605 I915_WRITE(DPLL(pipe), val);
1606 POSTING_READ(DPLL(pipe));
1609 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1611 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1614 /* Make sure the pipe isn't still relying on us */
1615 assert_pipe_disabled(dev_priv, pipe);
1617 val = DPLL_SSC_REF_CLK_CHV |
1618 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1620 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1622 I915_WRITE(DPLL(pipe), val);
1623 POSTING_READ(DPLL(pipe));
1625 mutex_lock(&dev_priv->sb_lock);
1627 /* Disable 10bit clock to display controller */
1628 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1629 val &= ~DPIO_DCLKP_EN;
1630 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1632 mutex_unlock(&dev_priv->sb_lock);
1635 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1636 struct intel_digital_port *dport,
1637 unsigned int expected_mask)
1640 i915_reg_t dpll_reg;
1642 switch (dport->base.port) {
1644 port_mask = DPLL_PORTB_READY_MASK;
1648 port_mask = DPLL_PORTC_READY_MASK;
1650 expected_mask <<= 4;
1653 port_mask = DPLL_PORTD_READY_MASK;
1654 dpll_reg = DPIO_PHY_STATUS;
1660 if (intel_wait_for_register(dev_priv,
1661 dpll_reg, port_mask, expected_mask,
1663 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1664 port_name(dport->base.port),
1665 I915_READ(dpll_reg) & port_mask, expected_mask);
1668 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1671 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
1674 uint32_t val, pipeconf_val;
1676 /* Make sure PCH DPLL is enabled */
1677 assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll);
1679 /* FDI must be feeding us bits for PCH ports */
1680 assert_fdi_tx_enabled(dev_priv, pipe);
1681 assert_fdi_rx_enabled(dev_priv, pipe);
1683 if (HAS_PCH_CPT(dev_priv)) {
1684 /* Workaround: Set the timing override bit before enabling the
1685 * pch transcoder. */
1686 reg = TRANS_CHICKEN2(pipe);
1687 val = I915_READ(reg);
1688 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1689 I915_WRITE(reg, val);
1692 reg = PCH_TRANSCONF(pipe);
1693 val = I915_READ(reg);
1694 pipeconf_val = I915_READ(PIPECONF(pipe));
1696 if (HAS_PCH_IBX(dev_priv)) {
1698 * Make the BPC in transcoder be consistent with
1699 * that in pipeconf reg. For HDMI we must use 8bpc
1700 * here for both 8bpc and 12bpc.
1702 val &= ~PIPECONF_BPC_MASK;
1703 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI))
1704 val |= PIPECONF_8BPC;
1706 val |= pipeconf_val & PIPECONF_BPC_MASK;
1709 val &= ~TRANS_INTERLACE_MASK;
1710 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1711 if (HAS_PCH_IBX(dev_priv) &&
1712 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
1713 val |= TRANS_LEGACY_INTERLACED_ILK;
1715 val |= TRANS_INTERLACED;
1717 val |= TRANS_PROGRESSIVE;
1719 I915_WRITE(reg, val | TRANS_ENABLE);
1720 if (intel_wait_for_register(dev_priv,
1721 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1723 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1726 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1727 enum transcoder cpu_transcoder)
1729 u32 val, pipeconf_val;
1731 /* FDI must be feeding us bits for PCH ports */
1732 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1733 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1735 /* Workaround: set timing override bit. */
1736 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1737 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1738 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1741 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1743 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1744 PIPECONF_INTERLACED_ILK)
1745 val |= TRANS_INTERLACED;
1747 val |= TRANS_PROGRESSIVE;
1749 I915_WRITE(LPT_TRANSCONF, val);
1750 if (intel_wait_for_register(dev_priv,
1755 DRM_ERROR("Failed to enable PCH transcoder\n");
1758 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1764 /* FDI relies on the transcoder */
1765 assert_fdi_tx_disabled(dev_priv, pipe);
1766 assert_fdi_rx_disabled(dev_priv, pipe);
1768 /* Ports must be off as well */
1769 assert_pch_ports_disabled(dev_priv, pipe);
1771 reg = PCH_TRANSCONF(pipe);
1772 val = I915_READ(reg);
1773 val &= ~TRANS_ENABLE;
1774 I915_WRITE(reg, val);
1775 /* wait for PCH transcoder off, transcoder state */
1776 if (intel_wait_for_register(dev_priv,
1777 reg, TRANS_STATE_ENABLE, 0,
1779 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1781 if (HAS_PCH_CPT(dev_priv)) {
1782 /* Workaround: Clear the timing override chicken bit again. */
1783 reg = TRANS_CHICKEN2(pipe);
1784 val = I915_READ(reg);
1785 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1786 I915_WRITE(reg, val);
1790 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1794 val = I915_READ(LPT_TRANSCONF);
1795 val &= ~TRANS_ENABLE;
1796 I915_WRITE(LPT_TRANSCONF, val);
1797 /* wait for PCH transcoder off, transcoder state */
1798 if (intel_wait_for_register(dev_priv,
1799 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1801 DRM_ERROR("Failed to disable PCH transcoder\n");
1803 /* Workaround: clear timing override bit. */
1804 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1805 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1806 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1809 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1811 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1813 if (HAS_PCH_LPT(dev_priv))
1819 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1821 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1822 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1823 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1824 enum pipe pipe = crtc->pipe;
1828 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1830 assert_planes_disabled(crtc);
1833 * A pipe without a PLL won't actually be able to drive bits from
1834 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1837 if (HAS_GMCH_DISPLAY(dev_priv)) {
1838 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1839 assert_dsi_pll_enabled(dev_priv);
1841 assert_pll_enabled(dev_priv, pipe);
1843 if (new_crtc_state->has_pch_encoder) {
1844 /* if driving the PCH, we need FDI enabled */
1845 assert_fdi_rx_pll_enabled(dev_priv,
1846 intel_crtc_pch_transcoder(crtc));
1847 assert_fdi_tx_pll_enabled(dev_priv,
1848 (enum pipe) cpu_transcoder);
1850 /* FIXME: assert CPU port conditions for SNB+ */
1853 reg = PIPECONF(cpu_transcoder);
1854 val = I915_READ(reg);
1855 if (val & PIPECONF_ENABLE) {
1856 /* we keep both pipes enabled on 830 */
1857 WARN_ON(!IS_I830(dev_priv));
1861 I915_WRITE(reg, val | PIPECONF_ENABLE);
1865 * Until the pipe starts PIPEDSL reads will return a stale value,
1866 * which causes an apparent vblank timestamp jump when PIPEDSL
1867 * resets to its proper value. That also messes up the frame count
1868 * when it's derived from the timestamps. So let's wait for the
1869 * pipe to start properly before we call drm_crtc_vblank_on()
1871 if (dev_priv->drm.max_vblank_count == 0)
1872 intel_wait_for_pipe_scanline_moving(crtc);
1875 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1877 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1878 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1879 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1880 enum pipe pipe = crtc->pipe;
1884 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1887 * Make sure planes won't keep trying to pump pixels to us,
1888 * or we might hang the display.
1890 assert_planes_disabled(crtc);
1892 reg = PIPECONF(cpu_transcoder);
1893 val = I915_READ(reg);
1894 if ((val & PIPECONF_ENABLE) == 0)
1898 * Double wide has implications for planes
1899 * so best keep it disabled when not needed.
1901 if (old_crtc_state->double_wide)
1902 val &= ~PIPECONF_DOUBLE_WIDE;
1904 /* Don't disable pipe or pipe PLLs if needed */
1905 if (!IS_I830(dev_priv))
1906 val &= ~PIPECONF_ENABLE;
1908 I915_WRITE(reg, val);
1909 if ((val & PIPECONF_ENABLE) == 0)
1910 intel_wait_for_pipe_off(old_crtc_state);
1913 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1915 return IS_GEN2(dev_priv) ? 2048 : 4096;
1919 intel_tile_width_bytes(const struct drm_framebuffer *fb, int plane)
1921 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1922 unsigned int cpp = fb->format->cpp[plane];
1924 switch (fb->modifier) {
1925 case DRM_FORMAT_MOD_LINEAR:
1927 case I915_FORMAT_MOD_X_TILED:
1928 if (IS_GEN2(dev_priv))
1932 case I915_FORMAT_MOD_Y_TILED_CCS:
1936 case I915_FORMAT_MOD_Y_TILED:
1937 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1941 case I915_FORMAT_MOD_Yf_TILED_CCS:
1945 case I915_FORMAT_MOD_Yf_TILED:
1961 MISSING_CASE(fb->modifier);
1967 intel_tile_height(const struct drm_framebuffer *fb, int plane)
1969 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
1972 return intel_tile_size(to_i915(fb->dev)) /
1973 intel_tile_width_bytes(fb, plane);
1976 /* Return the tile dimensions in pixel units */
1977 static void intel_tile_dims(const struct drm_framebuffer *fb, int plane,
1978 unsigned int *tile_width,
1979 unsigned int *tile_height)
1981 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, plane);
1982 unsigned int cpp = fb->format->cpp[plane];
1984 *tile_width = tile_width_bytes / cpp;
1985 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1989 intel_fb_align_height(const struct drm_framebuffer *fb,
1990 int plane, unsigned int height)
1992 unsigned int tile_height = intel_tile_height(fb, plane);
1994 return ALIGN(height, tile_height);
1997 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1999 unsigned int size = 0;
2002 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2003 size += rot_info->plane[i].width * rot_info->plane[i].height;
2009 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2010 const struct drm_framebuffer *fb,
2011 unsigned int rotation)
2013 view->type = I915_GGTT_VIEW_NORMAL;
2014 if (drm_rotation_90_or_270(rotation)) {
2015 view->type = I915_GGTT_VIEW_ROTATED;
2016 view->rotated = to_intel_framebuffer(fb)->rot_info;
2020 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2022 if (IS_I830(dev_priv))
2024 else if (IS_I85X(dev_priv))
2026 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2032 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2034 if (INTEL_GEN(dev_priv) >= 9)
2036 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2037 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2039 else if (INTEL_GEN(dev_priv) >= 4)
2045 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2048 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2050 /* AUX_DIST needs only 4K alignment */
2054 switch (fb->modifier) {
2055 case DRM_FORMAT_MOD_LINEAR:
2056 return intel_linear_alignment(dev_priv);
2057 case I915_FORMAT_MOD_X_TILED:
2058 if (INTEL_GEN(dev_priv) >= 9)
2061 case I915_FORMAT_MOD_Y_TILED_CCS:
2062 case I915_FORMAT_MOD_Yf_TILED_CCS:
2063 case I915_FORMAT_MOD_Y_TILED:
2064 case I915_FORMAT_MOD_Yf_TILED:
2065 return 1 * 1024 * 1024;
2067 MISSING_CASE(fb->modifier);
2072 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2074 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2075 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2077 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
2081 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2082 unsigned int rotation,
2084 unsigned long *out_flags)
2086 struct drm_device *dev = fb->dev;
2087 struct drm_i915_private *dev_priv = to_i915(dev);
2088 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2089 struct i915_ggtt_view view;
2090 struct i915_vma *vma;
2091 unsigned int pinctl;
2094 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2096 alignment = intel_surf_alignment(fb, 0);
2098 intel_fill_fb_ggtt_view(&view, fb, rotation);
2100 /* Note that the w/a also requires 64 PTE of padding following the
2101 * bo. We currently fill all unused PTE with the shadow page and so
2102 * we should always have valid PTE following the scanout preventing
2105 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2106 alignment = 256 * 1024;
2109 * Global gtt pte registers are special registers which actually forward
2110 * writes to a chunk of system memory. Which means that there is no risk
2111 * that the register values disappear as soon as we call
2112 * intel_runtime_pm_put(), so it is correct to wrap only the
2113 * pin/unpin/fence and not more.
2115 intel_runtime_pm_get(dev_priv);
2117 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2121 /* Valleyview is definitely limited to scanning out the first
2122 * 512MiB. Lets presume this behaviour was inherited from the
2123 * g4x display engine and that all earlier gen are similarly
2124 * limited. Testing suggests that it is a little more
2125 * complicated than this. For example, Cherryview appears quite
2126 * happy to scanout from anywhere within its global aperture.
2128 if (HAS_GMCH_DISPLAY(dev_priv))
2129 pinctl |= PIN_MAPPABLE;
2131 vma = i915_gem_object_pin_to_display_plane(obj,
2132 alignment, &view, pinctl);
2136 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2139 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2140 * fence, whereas 965+ only requires a fence if using
2141 * framebuffer compression. For simplicity, we always, when
2142 * possible, install a fence as the cost is not that onerous.
2144 * If we fail to fence the tiled scanout, then either the
2145 * modeset will reject the change (which is highly unlikely as
2146 * the affected systems, all but one, do not have unmappable
2147 * space) or we will not be able to enable full powersaving
2148 * techniques (also likely not to apply due to various limits
2149 * FBC and the like impose on the size of the buffer, which
2150 * presumably we violated anyway with this unmappable buffer).
2151 * Anyway, it is presumably better to stumble onwards with
2152 * something and try to run the system in a "less than optimal"
2153 * mode that matches the user configuration.
2155 ret = i915_vma_pin_fence(vma);
2156 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2157 i915_gem_object_unpin_from_display_plane(vma);
2162 if (ret == 0 && vma->fence)
2163 *out_flags |= PLANE_HAS_FENCE;
2168 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2170 intel_runtime_pm_put(dev_priv);
2174 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2176 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2178 if (flags & PLANE_HAS_FENCE)
2179 i915_vma_unpin_fence(vma);
2180 i915_gem_object_unpin_from_display_plane(vma);
2184 static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
2185 unsigned int rotation)
2187 if (drm_rotation_90_or_270(rotation))
2188 return to_intel_framebuffer(fb)->rotated[plane].pitch;
2190 return fb->pitches[plane];
2194 * Convert the x/y offsets into a linear offset.
2195 * Only valid with 0/180 degree rotation, which is fine since linear
2196 * offset is only used with linear buffers on pre-hsw and tiled buffers
2197 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2199 u32 intel_fb_xy_to_linear(int x, int y,
2200 const struct intel_plane_state *state,
2203 const struct drm_framebuffer *fb = state->base.fb;
2204 unsigned int cpp = fb->format->cpp[plane];
2205 unsigned int pitch = fb->pitches[plane];
2207 return y * pitch + x * cpp;
2211 * Add the x/y offsets derived from fb->offsets[] to the user
2212 * specified plane src x/y offsets. The resulting x/y offsets
2213 * specify the start of scanout from the beginning of the gtt mapping.
2215 void intel_add_fb_offsets(int *x, int *y,
2216 const struct intel_plane_state *state,
2220 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2221 unsigned int rotation = state->base.rotation;
2223 if (drm_rotation_90_or_270(rotation)) {
2224 *x += intel_fb->rotated[plane].x;
2225 *y += intel_fb->rotated[plane].y;
2227 *x += intel_fb->normal[plane].x;
2228 *y += intel_fb->normal[plane].y;
2232 static u32 __intel_adjust_tile_offset(int *x, int *y,
2233 unsigned int tile_width,
2234 unsigned int tile_height,
2235 unsigned int tile_size,
2236 unsigned int pitch_tiles,
2240 unsigned int pitch_pixels = pitch_tiles * tile_width;
2243 WARN_ON(old_offset & (tile_size - 1));
2244 WARN_ON(new_offset & (tile_size - 1));
2245 WARN_ON(new_offset > old_offset);
2247 tiles = (old_offset - new_offset) / tile_size;
2249 *y += tiles / pitch_tiles * tile_height;
2250 *x += tiles % pitch_tiles * tile_width;
2252 /* minimize x in case it got needlessly big */
2253 *y += *x / pitch_pixels * tile_height;
2259 static u32 _intel_adjust_tile_offset(int *x, int *y,
2260 const struct drm_framebuffer *fb, int plane,
2261 unsigned int rotation,
2262 u32 old_offset, u32 new_offset)
2264 const struct drm_i915_private *dev_priv = to_i915(fb->dev);
2265 unsigned int cpp = fb->format->cpp[plane];
2266 unsigned int pitch = intel_fb_pitch(fb, plane, rotation);
2268 WARN_ON(new_offset > old_offset);
2270 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2271 unsigned int tile_size, tile_width, tile_height;
2272 unsigned int pitch_tiles;
2274 tile_size = intel_tile_size(dev_priv);
2275 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2277 if (drm_rotation_90_or_270(rotation)) {
2278 pitch_tiles = pitch / tile_height;
2279 swap(tile_width, tile_height);
2281 pitch_tiles = pitch / (tile_width * cpp);
2284 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2285 tile_size, pitch_tiles,
2286 old_offset, new_offset);
2288 old_offset += *y * pitch + *x * cpp;
2290 *y = (old_offset - new_offset) / pitch;
2291 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2298 * Adjust the tile offset by moving the difference into
2301 static u32 intel_adjust_tile_offset(int *x, int *y,
2302 const struct intel_plane_state *state, int plane,
2303 u32 old_offset, u32 new_offset)
2305 return _intel_adjust_tile_offset(x, y, state->base.fb, plane,
2306 state->base.rotation,
2307 old_offset, new_offset);
2311 * Computes the linear offset to the base tile and adjusts
2312 * x, y. bytes per pixel is assumed to be a power-of-two.
2314 * In the 90/270 rotated case, x and y are assumed
2315 * to be already rotated to match the rotated GTT view, and
2316 * pitch is the tile_height aligned framebuffer height.
2318 * This function is used when computing the derived information
2319 * under intel_framebuffer, so using any of that information
2320 * here is not allowed. Anything under drm_framebuffer can be
2321 * used. This is why the user has to pass in the pitch since it
2322 * is specified in the rotated orientation.
2324 static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv,
2326 const struct drm_framebuffer *fb, int plane,
2328 unsigned int rotation,
2331 uint64_t fb_modifier = fb->modifier;
2332 unsigned int cpp = fb->format->cpp[plane];
2333 u32 offset, offset_aligned;
2338 if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
2339 unsigned int tile_size, tile_width, tile_height;
2340 unsigned int tile_rows, tiles, pitch_tiles;
2342 tile_size = intel_tile_size(dev_priv);
2343 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2345 if (drm_rotation_90_or_270(rotation)) {
2346 pitch_tiles = pitch / tile_height;
2347 swap(tile_width, tile_height);
2349 pitch_tiles = pitch / (tile_width * cpp);
2352 tile_rows = *y / tile_height;
2355 tiles = *x / tile_width;
2358 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2359 offset_aligned = offset & ~alignment;
2361 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2362 tile_size, pitch_tiles,
2363 offset, offset_aligned);
2365 offset = *y * pitch + *x * cpp;
2366 offset_aligned = offset & ~alignment;
2368 *y = (offset & alignment) / pitch;
2369 *x = ((offset & alignment) - *y * pitch) / cpp;
2372 return offset_aligned;
2375 u32 intel_compute_tile_offset(int *x, int *y,
2376 const struct intel_plane_state *state,
2379 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2380 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2381 const struct drm_framebuffer *fb = state->base.fb;
2382 unsigned int rotation = state->base.rotation;
2383 int pitch = intel_fb_pitch(fb, plane, rotation);
2386 if (intel_plane->id == PLANE_CURSOR)
2387 alignment = intel_cursor_alignment(dev_priv);
2389 alignment = intel_surf_alignment(fb, plane);
2391 return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch,
2392 rotation, alignment);
2395 /* Convert the fb->offset[] into x/y offsets */
2396 static int intel_fb_offset_to_xy(int *x, int *y,
2397 const struct drm_framebuffer *fb, int plane)
2399 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2401 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2402 fb->offsets[plane] % intel_tile_size(dev_priv))
2408 _intel_adjust_tile_offset(x, y,
2409 fb, plane, DRM_MODE_ROTATE_0,
2410 fb->offsets[plane], 0);
2415 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2417 switch (fb_modifier) {
2418 case I915_FORMAT_MOD_X_TILED:
2419 return I915_TILING_X;
2420 case I915_FORMAT_MOD_Y_TILED:
2421 case I915_FORMAT_MOD_Y_TILED_CCS:
2422 return I915_TILING_Y;
2424 return I915_TILING_NONE;
2429 * From the Sky Lake PRM:
2430 * "The Color Control Surface (CCS) contains the compression status of
2431 * the cache-line pairs. The compression state of the cache-line pair
2432 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2433 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2434 * cache-line-pairs. CCS is always Y tiled."
2436 * Since cache line pairs refers to horizontally adjacent cache lines,
2437 * each cache line in the CCS corresponds to an area of 32x16 cache
2438 * lines on the main surface. Since each pixel is 4 bytes, this gives
2439 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2442 static const struct drm_format_info ccs_formats[] = {
2443 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2444 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2445 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2446 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2449 static const struct drm_format_info *
2450 lookup_format_info(const struct drm_format_info formats[],
2451 int num_formats, u32 format)
2455 for (i = 0; i < num_formats; i++) {
2456 if (formats[i].format == format)
2463 static const struct drm_format_info *
2464 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2466 switch (cmd->modifier[0]) {
2467 case I915_FORMAT_MOD_Y_TILED_CCS:
2468 case I915_FORMAT_MOD_Yf_TILED_CCS:
2469 return lookup_format_info(ccs_formats,
2470 ARRAY_SIZE(ccs_formats),
2477 bool is_ccs_modifier(u64 modifier)
2479 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2480 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2484 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2485 struct drm_framebuffer *fb)
2487 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2488 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2489 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2490 u32 gtt_offset_rotated = 0;
2491 unsigned int max_size = 0;
2492 int i, num_planes = fb->format->num_planes;
2493 unsigned int tile_size = intel_tile_size(dev_priv);
2495 for (i = 0; i < num_planes; i++) {
2496 unsigned int width, height;
2497 unsigned int cpp, size;
2502 cpp = fb->format->cpp[i];
2503 width = drm_framebuffer_plane_width(fb->width, fb, i);
2504 height = drm_framebuffer_plane_height(fb->height, fb, i);
2506 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2508 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2513 if (is_ccs_modifier(fb->modifier) && i == 1) {
2514 int hsub = fb->format->hsub;
2515 int vsub = fb->format->vsub;
2516 int tile_width, tile_height;
2520 intel_tile_dims(fb, i, &tile_width, &tile_height);
2522 tile_height *= vsub;
2524 ccs_x = (x * hsub) % tile_width;
2525 ccs_y = (y * vsub) % tile_height;
2526 main_x = intel_fb->normal[0].x % tile_width;
2527 main_y = intel_fb->normal[0].y % tile_height;
2530 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2531 * x/y offsets must match between CCS and the main surface.
2533 if (main_x != ccs_x || main_y != ccs_y) {
2534 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2537 intel_fb->normal[0].x,
2538 intel_fb->normal[0].y,
2545 * The fence (if used) is aligned to the start of the object
2546 * so having the framebuffer wrap around across the edge of the
2547 * fenced region doesn't really work. We have no API to configure
2548 * the fence start offset within the object (nor could we probably
2549 * on gen2/3). So it's just easier if we just require that the
2550 * fb layout agrees with the fence layout. We already check that the
2551 * fb stride matches the fence stride elsewhere.
2553 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2554 (x + width) * cpp > fb->pitches[i]) {
2555 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2561 * First pixel of the framebuffer from
2562 * the start of the normal gtt mapping.
2564 intel_fb->normal[i].x = x;
2565 intel_fb->normal[i].y = y;
2567 offset = _intel_compute_tile_offset(dev_priv, &x, &y,
2568 fb, i, fb->pitches[i],
2569 DRM_MODE_ROTATE_0, tile_size);
2570 offset /= tile_size;
2572 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2573 unsigned int tile_width, tile_height;
2574 unsigned int pitch_tiles;
2577 intel_tile_dims(fb, i, &tile_width, &tile_height);
2579 rot_info->plane[i].offset = offset;
2580 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2581 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2582 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2584 intel_fb->rotated[i].pitch =
2585 rot_info->plane[i].height * tile_height;
2587 /* how many tiles does this plane need */
2588 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2590 * If the plane isn't horizontally tile aligned,
2591 * we need one more tile.
2596 /* rotate the x/y offsets to match the GTT view */
2602 rot_info->plane[i].width * tile_width,
2603 rot_info->plane[i].height * tile_height,
2604 DRM_MODE_ROTATE_270);
2608 /* rotate the tile dimensions to match the GTT view */
2609 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2610 swap(tile_width, tile_height);
2613 * We only keep the x/y offsets, so push all of the
2614 * gtt offset into the x/y offsets.
2616 __intel_adjust_tile_offset(&x, &y,
2617 tile_width, tile_height,
2618 tile_size, pitch_tiles,
2619 gtt_offset_rotated * tile_size, 0);
2621 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2624 * First pixel of the framebuffer from
2625 * the start of the rotated gtt mapping.
2627 intel_fb->rotated[i].x = x;
2628 intel_fb->rotated[i].y = y;
2630 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2631 x * cpp, tile_size);
2634 /* how many tiles in total needed in the bo */
2635 max_size = max(max_size, offset + size);
2638 if (max_size * tile_size > obj->base.size) {
2639 DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
2640 max_size * tile_size, obj->base.size);
2647 static int i9xx_format_to_fourcc(int format)
2650 case DISPPLANE_8BPP:
2651 return DRM_FORMAT_C8;
2652 case DISPPLANE_BGRX555:
2653 return DRM_FORMAT_XRGB1555;
2654 case DISPPLANE_BGRX565:
2655 return DRM_FORMAT_RGB565;
2657 case DISPPLANE_BGRX888:
2658 return DRM_FORMAT_XRGB8888;
2659 case DISPPLANE_RGBX888:
2660 return DRM_FORMAT_XBGR8888;
2661 case DISPPLANE_BGRX101010:
2662 return DRM_FORMAT_XRGB2101010;
2663 case DISPPLANE_RGBX101010:
2664 return DRM_FORMAT_XBGR2101010;
2668 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2671 case PLANE_CTL_FORMAT_RGB_565:
2672 return DRM_FORMAT_RGB565;
2673 case PLANE_CTL_FORMAT_NV12:
2674 return DRM_FORMAT_NV12;
2676 case PLANE_CTL_FORMAT_XRGB_8888:
2679 return DRM_FORMAT_ABGR8888;
2681 return DRM_FORMAT_XBGR8888;
2684 return DRM_FORMAT_ARGB8888;
2686 return DRM_FORMAT_XRGB8888;
2688 case PLANE_CTL_FORMAT_XRGB_2101010:
2690 return DRM_FORMAT_XBGR2101010;
2692 return DRM_FORMAT_XRGB2101010;
2697 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2698 struct intel_initial_plane_config *plane_config)
2700 struct drm_device *dev = crtc->base.dev;
2701 struct drm_i915_private *dev_priv = to_i915(dev);
2702 struct drm_i915_gem_object *obj = NULL;
2703 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2704 struct drm_framebuffer *fb = &plane_config->fb->base;
2705 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2706 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2709 size_aligned -= base_aligned;
2711 if (plane_config->size == 0)
2714 /* If the FB is too big, just don't use it since fbdev is not very
2715 * important and we should probably use that space with FBC or other
2717 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2720 mutex_lock(&dev->struct_mutex);
2721 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2725 mutex_unlock(&dev->struct_mutex);
2729 if (plane_config->tiling == I915_TILING_X)
2730 obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X;
2732 mode_cmd.pixel_format = fb->format->format;
2733 mode_cmd.width = fb->width;
2734 mode_cmd.height = fb->height;
2735 mode_cmd.pitches[0] = fb->pitches[0];
2736 mode_cmd.modifier[0] = fb->modifier;
2737 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2739 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2740 DRM_DEBUG_KMS("intel fb init failed\n");
2745 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2749 i915_gem_object_put(obj);
2754 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2755 struct intel_plane_state *plane_state,
2758 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2760 plane_state->base.visible = visible;
2762 /* FIXME pre-g4x don't work like this */
2764 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
2765 crtc_state->active_planes |= BIT(plane->id);
2767 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
2768 crtc_state->active_planes &= ~BIT(plane->id);
2771 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2772 crtc_state->base.crtc->name,
2773 crtc_state->active_planes);
2776 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2777 struct intel_plane *plane)
2779 struct intel_crtc_state *crtc_state =
2780 to_intel_crtc_state(crtc->base.state);
2781 struct intel_plane_state *plane_state =
2782 to_intel_plane_state(plane->base.state);
2784 intel_set_plane_visible(crtc_state, plane_state, false);
2786 if (plane->id == PLANE_PRIMARY)
2787 intel_pre_disable_primary_noatomic(&crtc->base);
2789 trace_intel_disable_plane(&plane->base, crtc);
2790 plane->disable_plane(plane, crtc);
2794 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2795 struct intel_initial_plane_config *plane_config)
2797 struct drm_device *dev = intel_crtc->base.dev;
2798 struct drm_i915_private *dev_priv = to_i915(dev);
2800 struct drm_i915_gem_object *obj;
2801 struct drm_plane *primary = intel_crtc->base.primary;
2802 struct drm_plane_state *plane_state = primary->state;
2803 struct drm_crtc_state *crtc_state = intel_crtc->base.state;
2804 struct intel_plane *intel_plane = to_intel_plane(primary);
2805 struct intel_plane_state *intel_state =
2806 to_intel_plane_state(plane_state);
2807 struct drm_framebuffer *fb;
2809 if (!plane_config->fb)
2812 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2813 fb = &plane_config->fb->base;
2817 kfree(plane_config->fb);
2820 * Failed to alloc the obj, check to see if we should share
2821 * an fb with another CRTC instead
2823 for_each_crtc(dev, c) {
2824 struct intel_plane_state *state;
2826 if (c == &intel_crtc->base)
2829 if (!to_intel_crtc(c)->active)
2832 state = to_intel_plane_state(c->primary->state);
2836 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2837 fb = state->base.fb;
2838 drm_framebuffer_get(fb);
2844 * We've failed to reconstruct the BIOS FB. Current display state
2845 * indicates that the primary plane is visible, but has a NULL FB,
2846 * which will lead to problems later if we don't fix it up. The
2847 * simplest solution is to just disable the primary plane now and
2848 * pretend the BIOS never had it enabled.
2850 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2855 mutex_lock(&dev->struct_mutex);
2857 intel_pin_and_fence_fb_obj(fb,
2858 primary->state->rotation,
2859 intel_plane_uses_fence(intel_state),
2860 &intel_state->flags);
2861 mutex_unlock(&dev->struct_mutex);
2862 if (IS_ERR(intel_state->vma)) {
2863 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2864 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2866 intel_state->vma = NULL;
2867 drm_framebuffer_put(fb);
2871 obj = intel_fb_obj(fb);
2872 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2874 plane_state->src_x = 0;
2875 plane_state->src_y = 0;
2876 plane_state->src_w = fb->width << 16;
2877 plane_state->src_h = fb->height << 16;
2879 plane_state->crtc_x = 0;
2880 plane_state->crtc_y = 0;
2881 plane_state->crtc_w = fb->width;
2882 plane_state->crtc_h = fb->height;
2884 intel_state->base.src = drm_plane_state_src(plane_state);
2885 intel_state->base.dst = drm_plane_state_dest(plane_state);
2887 if (i915_gem_object_is_tiled(obj))
2888 dev_priv->preserve_bios_swizzle = true;
2890 plane_state->fb = fb;
2891 plane_state->crtc = &intel_crtc->base;
2893 intel_set_plane_visible(to_intel_crtc_state(crtc_state),
2894 to_intel_plane_state(plane_state),
2897 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2898 &obj->frontbuffer_bits);
2901 static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane,
2902 unsigned int rotation)
2904 int cpp = fb->format->cpp[plane];
2906 switch (fb->modifier) {
2907 case DRM_FORMAT_MOD_LINEAR:
2908 case I915_FORMAT_MOD_X_TILED:
2921 case I915_FORMAT_MOD_Y_TILED_CCS:
2922 case I915_FORMAT_MOD_Yf_TILED_CCS:
2923 /* FIXME AUX plane? */
2924 case I915_FORMAT_MOD_Y_TILED:
2925 case I915_FORMAT_MOD_Yf_TILED:
2940 MISSING_CASE(fb->modifier);
2946 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2947 int main_x, int main_y, u32 main_offset)
2949 const struct drm_framebuffer *fb = plane_state->base.fb;
2950 int hsub = fb->format->hsub;
2951 int vsub = fb->format->vsub;
2952 int aux_x = plane_state->aux.x;
2953 int aux_y = plane_state->aux.y;
2954 u32 aux_offset = plane_state->aux.offset;
2955 u32 alignment = intel_surf_alignment(fb, 1);
2957 while (aux_offset >= main_offset && aux_y <= main_y) {
2960 if (aux_x == main_x && aux_y == main_y)
2963 if (aux_offset == 0)
2968 aux_offset = intel_adjust_tile_offset(&x, &y, plane_state, 1,
2969 aux_offset, aux_offset - alignment);
2970 aux_x = x * hsub + aux_x % hsub;
2971 aux_y = y * vsub + aux_y % vsub;
2974 if (aux_x != main_x || aux_y != main_y)
2977 plane_state->aux.offset = aux_offset;
2978 plane_state->aux.x = aux_x;
2979 plane_state->aux.y = aux_y;
2984 static int skl_check_main_surface(const struct intel_crtc_state *crtc_state,
2985 struct intel_plane_state *plane_state)
2987 struct drm_i915_private *dev_priv =
2988 to_i915(plane_state->base.plane->dev);
2989 const struct drm_framebuffer *fb = plane_state->base.fb;
2990 unsigned int rotation = plane_state->base.rotation;
2991 int x = plane_state->base.src.x1 >> 16;
2992 int y = plane_state->base.src.y1 >> 16;
2993 int w = drm_rect_width(&plane_state->base.src) >> 16;
2994 int h = drm_rect_height(&plane_state->base.src) >> 16;
2995 int dst_x = plane_state->base.dst.x1;
2996 int dst_w = drm_rect_width(&plane_state->base.dst);
2997 int pipe_src_w = crtc_state->pipe_src_w;
2998 int max_width = skl_max_plane_width(fb, 0, rotation);
2999 int max_height = 4096;
3000 u32 alignment, offset, aux_offset = plane_state->aux.offset;
3002 if (w > max_width || h > max_height) {
3003 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3004 w, h, max_width, max_height);
3009 * Display WA #1175: cnl,glk
3010 * Planes other than the cursor may cause FIFO underflow and display
3011 * corruption if starting less than 4 pixels from the right edge of
3013 * Besides the above WA fix the similar problem, where planes other
3014 * than the cursor ending less than 4 pixels from the left edge of the
3015 * screen may cause FIFO underflow and display corruption.
3017 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
3018 (dst_x + dst_w < 4 || dst_x > pipe_src_w - 4)) {
3019 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
3020 dst_x + dst_w < 4 ? "end" : "start",
3021 dst_x + dst_w < 4 ? dst_x + dst_w : dst_x,
3026 intel_add_fb_offsets(&x, &y, plane_state, 0);
3027 offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
3028 alignment = intel_surf_alignment(fb, 0);
3031 * AUX surface offset is specified as the distance from the
3032 * main surface offset, and it must be non-negative. Make
3033 * sure that is what we will get.
3035 if (offset > aux_offset)
3036 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3037 offset, aux_offset & ~(alignment - 1));
3040 * When using an X-tiled surface, the plane blows up
3041 * if the x offset + width exceed the stride.
3043 * TODO: linear and Y-tiled seem fine, Yf untested,
3045 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3046 int cpp = fb->format->cpp[0];
3048 while ((x + w) * cpp > fb->pitches[0]) {
3050 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3054 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3055 offset, offset - alignment);
3060 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3061 * they match with the main surface x/y offsets.
3063 if (is_ccs_modifier(fb->modifier)) {
3064 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3068 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3069 offset, offset - alignment);
3072 if (x != plane_state->aux.x || y != plane_state->aux.y) {
3073 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3078 plane_state->main.offset = offset;
3079 plane_state->main.x = x;
3080 plane_state->main.y = y;
3086 skl_check_nv12_surface(const struct intel_crtc_state *crtc_state,
3087 struct intel_plane_state *plane_state)
3089 /* Display WA #1106 */
3090 if (plane_state->base.rotation !=
3091 (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90) &&
3092 plane_state->base.rotation != DRM_MODE_ROTATE_270)
3096 * src coordinates are rotated here.
3097 * We check height but report it as width
3099 if (((drm_rect_height(&plane_state->base.src) >> 16) % 4) != 0) {
3100 DRM_DEBUG_KMS("src width must be multiple "
3101 "of 4 for rotated NV12\n");
3108 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3110 const struct drm_framebuffer *fb = plane_state->base.fb;
3111 unsigned int rotation = plane_state->base.rotation;
3112 int max_width = skl_max_plane_width(fb, 1, rotation);
3113 int max_height = 4096;
3114 int x = plane_state->base.src.x1 >> 17;
3115 int y = plane_state->base.src.y1 >> 17;
3116 int w = drm_rect_width(&plane_state->base.src) >> 17;
3117 int h = drm_rect_height(&plane_state->base.src) >> 17;
3120 intel_add_fb_offsets(&x, &y, plane_state, 1);
3121 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3123 /* FIXME not quite sure how/if these apply to the chroma plane */
3124 if (w > max_width || h > max_height) {
3125 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3126 w, h, max_width, max_height);
3130 plane_state->aux.offset = offset;
3131 plane_state->aux.x = x;
3132 plane_state->aux.y = y;
3137 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3139 const struct drm_framebuffer *fb = plane_state->base.fb;
3140 int src_x = plane_state->base.src.x1 >> 16;
3141 int src_y = plane_state->base.src.y1 >> 16;
3142 int hsub = fb->format->hsub;
3143 int vsub = fb->format->vsub;
3144 int x = src_x / hsub;
3145 int y = src_y / vsub;
3148 if (plane_state->base.rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180)) {
3149 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation %x\n",
3150 plane_state->base.rotation);
3154 intel_add_fb_offsets(&x, &y, plane_state, 1);
3155 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3157 plane_state->aux.offset = offset;
3158 plane_state->aux.x = x * hsub + src_x % hsub;
3159 plane_state->aux.y = y * vsub + src_y % vsub;
3164 int skl_check_plane_surface(const struct intel_crtc_state *crtc_state,
3165 struct intel_plane_state *plane_state)
3167 const struct drm_framebuffer *fb = plane_state->base.fb;
3168 unsigned int rotation = plane_state->base.rotation;
3171 if (rotation & DRM_MODE_REFLECT_X &&
3172 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
3173 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
3177 if (!plane_state->base.visible)
3180 /* Rotate src coordinates to match rotated GTT view */
3181 if (drm_rotation_90_or_270(rotation))
3182 drm_rect_rotate(&plane_state->base.src,
3183 fb->width << 16, fb->height << 16,
3184 DRM_MODE_ROTATE_270);
3187 * Handle the AUX surface first since
3188 * the main surface setup depends on it.
3190 if (fb->format->format == DRM_FORMAT_NV12) {
3191 ret = skl_check_nv12_surface(crtc_state, plane_state);
3194 ret = skl_check_nv12_aux_surface(plane_state);
3197 } else if (is_ccs_modifier(fb->modifier)) {
3198 ret = skl_check_ccs_aux_surface(plane_state);
3202 plane_state->aux.offset = ~0xfff;
3203 plane_state->aux.x = 0;
3204 plane_state->aux.y = 0;
3207 ret = skl_check_main_surface(crtc_state, plane_state);
3214 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3215 const struct intel_plane_state *plane_state)
3217 struct drm_i915_private *dev_priv =
3218 to_i915(plane_state->base.plane->dev);
3219 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3220 const struct drm_framebuffer *fb = plane_state->base.fb;
3221 unsigned int rotation = plane_state->base.rotation;
3224 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
3226 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3227 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
3228 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3230 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3231 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3233 if (INTEL_GEN(dev_priv) < 5)
3234 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3236 switch (fb->format->format) {
3238 dspcntr |= DISPPLANE_8BPP;
3240 case DRM_FORMAT_XRGB1555:
3241 dspcntr |= DISPPLANE_BGRX555;
3243 case DRM_FORMAT_RGB565:
3244 dspcntr |= DISPPLANE_BGRX565;
3246 case DRM_FORMAT_XRGB8888:
3247 dspcntr |= DISPPLANE_BGRX888;
3249 case DRM_FORMAT_XBGR8888:
3250 dspcntr |= DISPPLANE_RGBX888;
3252 case DRM_FORMAT_XRGB2101010:
3253 dspcntr |= DISPPLANE_BGRX101010;
3255 case DRM_FORMAT_XBGR2101010:
3256 dspcntr |= DISPPLANE_RGBX101010;
3259 MISSING_CASE(fb->format->format);
3263 if (INTEL_GEN(dev_priv) >= 4 &&
3264 fb->modifier == I915_FORMAT_MOD_X_TILED)
3265 dspcntr |= DISPPLANE_TILED;
3267 if (rotation & DRM_MODE_ROTATE_180)
3268 dspcntr |= DISPPLANE_ROTATE_180;
3270 if (rotation & DRM_MODE_REFLECT_X)
3271 dspcntr |= DISPPLANE_MIRROR;
3276 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3278 struct drm_i915_private *dev_priv =
3279 to_i915(plane_state->base.plane->dev);
3280 int src_x = plane_state->base.src.x1 >> 16;
3281 int src_y = plane_state->base.src.y1 >> 16;
3284 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3286 if (INTEL_GEN(dev_priv) >= 4)
3287 offset = intel_compute_tile_offset(&src_x, &src_y,
3292 /* HSW/BDW do this automagically in hardware */
3293 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3294 unsigned int rotation = plane_state->base.rotation;
3295 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3296 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3298 if (rotation & DRM_MODE_ROTATE_180) {
3301 } else if (rotation & DRM_MODE_REFLECT_X) {
3306 plane_state->main.offset = offset;
3307 plane_state->main.x = src_x;
3308 plane_state->main.y = src_y;
3313 static void i9xx_update_plane(struct intel_plane *plane,
3314 const struct intel_crtc_state *crtc_state,
3315 const struct intel_plane_state *plane_state)
3317 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3318 const struct drm_framebuffer *fb = plane_state->base.fb;
3319 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3321 u32 dspcntr = plane_state->ctl;
3322 i915_reg_t reg = DSPCNTR(i9xx_plane);
3323 int x = plane_state->main.x;
3324 int y = plane_state->main.y;
3325 unsigned long irqflags;
3328 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3330 if (INTEL_GEN(dev_priv) >= 4)
3331 dspaddr_offset = plane_state->main.offset;
3333 dspaddr_offset = linear_offset;
3335 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3337 if (INTEL_GEN(dev_priv) < 4) {
3338 /* pipesrc and dspsize control the size that is scaled from,
3339 * which should always be the user's requested size.
3341 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3342 ((crtc_state->pipe_src_h - 1) << 16) |
3343 (crtc_state->pipe_src_w - 1));
3344 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3345 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3346 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3347 ((crtc_state->pipe_src_h - 1) << 16) |
3348 (crtc_state->pipe_src_w - 1));
3349 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3350 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3353 I915_WRITE_FW(reg, dspcntr);
3355 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), fb->pitches[0]);
3356 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3357 I915_WRITE_FW(DSPSURF(i9xx_plane),
3358 intel_plane_ggtt_offset(plane_state) +
3360 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3361 } else if (INTEL_GEN(dev_priv) >= 4) {
3362 I915_WRITE_FW(DSPSURF(i9xx_plane),
3363 intel_plane_ggtt_offset(plane_state) +
3365 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3366 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3368 I915_WRITE_FW(DSPADDR(i9xx_plane),
3369 intel_plane_ggtt_offset(plane_state) +
3372 POSTING_READ_FW(reg);
3374 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3377 static void i9xx_disable_plane(struct intel_plane *plane,
3378 struct intel_crtc *crtc)
3380 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3381 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3382 unsigned long irqflags;
3384 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3386 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3387 if (INTEL_GEN(dev_priv) >= 4)
3388 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3390 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3391 POSTING_READ_FW(DSPCNTR(i9xx_plane));
3393 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3396 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3399 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3400 enum intel_display_power_domain power_domain;
3401 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3406 * Not 100% correct for planes that can move between pipes,
3407 * but that's only the case for gen2-4 which don't have any
3408 * display power wells.
3410 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3411 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3414 val = I915_READ(DSPCNTR(i9xx_plane));
3416 ret = val & DISPLAY_PLANE_ENABLE;
3418 if (INTEL_GEN(dev_priv) >= 5)
3419 *pipe = plane->pipe;
3421 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3422 DISPPLANE_SEL_PIPE_SHIFT;
3424 intel_display_power_put(dev_priv, power_domain);
3430 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int plane)
3432 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3435 return intel_tile_width_bytes(fb, plane);
3438 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3440 struct drm_device *dev = intel_crtc->base.dev;
3441 struct drm_i915_private *dev_priv = to_i915(dev);
3443 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3444 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3445 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3449 * This function detaches (aka. unbinds) unused scalers in hardware
3451 static void skl_detach_scalers(struct intel_crtc *intel_crtc)
3453 struct intel_crtc_scaler_state *scaler_state;
3456 scaler_state = &intel_crtc->config->scaler_state;
3458 /* loop through and disable scalers that aren't in use */
3459 for (i = 0; i < intel_crtc->num_scalers; i++) {
3460 if (!scaler_state->scalers[i].in_use)
3461 skl_detach_scaler(intel_crtc, i);
3465 u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
3466 unsigned int rotation)
3470 if (plane >= fb->format->num_planes)
3473 stride = intel_fb_pitch(fb, plane, rotation);
3476 * The stride is either expressed as a multiple of 64 bytes chunks for
3477 * linear buffers or in number of tiles for tiled buffers.
3479 if (drm_rotation_90_or_270(rotation))
3480 stride /= intel_tile_height(fb, plane);
3482 stride /= intel_fb_stride_alignment(fb, plane);
3487 static u32 skl_plane_ctl_format(uint32_t pixel_format)
3489 switch (pixel_format) {
3491 return PLANE_CTL_FORMAT_INDEXED;
3492 case DRM_FORMAT_RGB565:
3493 return PLANE_CTL_FORMAT_RGB_565;
3494 case DRM_FORMAT_XBGR8888:
3495 case DRM_FORMAT_ABGR8888:
3496 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3497 case DRM_FORMAT_XRGB8888:
3498 case DRM_FORMAT_ARGB8888:
3499 return PLANE_CTL_FORMAT_XRGB_8888;
3500 case DRM_FORMAT_XRGB2101010:
3501 return PLANE_CTL_FORMAT_XRGB_2101010;
3502 case DRM_FORMAT_XBGR2101010:
3503 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3504 case DRM_FORMAT_YUYV:
3505 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3506 case DRM_FORMAT_YVYU:
3507 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3508 case DRM_FORMAT_UYVY:
3509 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3510 case DRM_FORMAT_VYUY:
3511 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3512 case DRM_FORMAT_NV12:
3513 return PLANE_CTL_FORMAT_NV12;
3515 MISSING_CASE(pixel_format);
3522 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3523 * to be already pre-multiplied. We need to add a knob (or a different
3524 * DRM_FORMAT) for user-space to configure that.
3526 static u32 skl_plane_ctl_alpha(uint32_t pixel_format)
3528 switch (pixel_format) {
3529 case DRM_FORMAT_ABGR8888:
3530 case DRM_FORMAT_ARGB8888:
3531 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3533 return PLANE_CTL_ALPHA_DISABLE;
3537 static u32 glk_plane_color_ctl_alpha(uint32_t pixel_format)
3539 switch (pixel_format) {
3540 case DRM_FORMAT_ABGR8888:
3541 case DRM_FORMAT_ARGB8888:
3542 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3544 return PLANE_COLOR_ALPHA_DISABLE;
3548 static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
3550 switch (fb_modifier) {
3551 case DRM_FORMAT_MOD_LINEAR:
3553 case I915_FORMAT_MOD_X_TILED:
3554 return PLANE_CTL_TILED_X;
3555 case I915_FORMAT_MOD_Y_TILED:
3556 return PLANE_CTL_TILED_Y;
3557 case I915_FORMAT_MOD_Y_TILED_CCS:
3558 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3559 case I915_FORMAT_MOD_Yf_TILED:
3560 return PLANE_CTL_TILED_YF;
3561 case I915_FORMAT_MOD_Yf_TILED_CCS:
3562 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3564 MISSING_CASE(fb_modifier);
3570 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3573 case DRM_MODE_ROTATE_0:
3576 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3577 * while i915 HW rotation is clockwise, thats why this swapping.
3579 case DRM_MODE_ROTATE_90:
3580 return PLANE_CTL_ROTATE_270;
3581 case DRM_MODE_ROTATE_180:
3582 return PLANE_CTL_ROTATE_180;
3583 case DRM_MODE_ROTATE_270:
3584 return PLANE_CTL_ROTATE_90;
3586 MISSING_CASE(rotate);
3592 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3597 case DRM_MODE_REFLECT_X:
3598 return PLANE_CTL_FLIP_HORIZONTAL;
3599 case DRM_MODE_REFLECT_Y:
3601 MISSING_CASE(reflect);
3607 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3608 const struct intel_plane_state *plane_state)
3610 struct drm_i915_private *dev_priv =
3611 to_i915(plane_state->base.plane->dev);
3612 const struct drm_framebuffer *fb = plane_state->base.fb;
3613 unsigned int rotation = plane_state->base.rotation;
3614 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3617 plane_ctl = PLANE_CTL_ENABLE;
3619 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3620 plane_ctl |= skl_plane_ctl_alpha(fb->format->format);
3622 PLANE_CTL_PIPE_GAMMA_ENABLE |
3623 PLANE_CTL_PIPE_CSC_ENABLE |
3624 PLANE_CTL_PLANE_GAMMA_DISABLE;
3626 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3627 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3629 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3630 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3633 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3634 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3635 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3637 if (INTEL_GEN(dev_priv) >= 10)
3638 plane_ctl |= cnl_plane_ctl_flip(rotation &
3639 DRM_MODE_REFLECT_MASK);
3641 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3642 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3643 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3644 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3649 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3650 const struct intel_plane_state *plane_state)
3652 struct drm_i915_private *dev_priv =
3653 to_i915(plane_state->base.plane->dev);
3654 const struct drm_framebuffer *fb = plane_state->base.fb;
3655 u32 plane_color_ctl = 0;
3657 if (INTEL_GEN(dev_priv) < 11) {
3658 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3659 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3661 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3662 plane_color_ctl |= glk_plane_color_ctl_alpha(fb->format->format);
3664 if (fb->format->is_yuv) {
3665 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3666 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3668 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
3670 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3671 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3674 return plane_color_ctl;
3678 __intel_display_resume(struct drm_device *dev,
3679 struct drm_atomic_state *state,
3680 struct drm_modeset_acquire_ctx *ctx)
3682 struct drm_crtc_state *crtc_state;
3683 struct drm_crtc *crtc;
3686 intel_modeset_setup_hw_state(dev, ctx);
3687 i915_redisable_vga(to_i915(dev));
3693 * We've duplicated the state, pointers to the old state are invalid.
3695 * Don't attempt to use the old state until we commit the duplicated state.
3697 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3699 * Force recalculation even if we restore
3700 * current state. With fast modeset this may not result
3701 * in a modeset when the state is compatible.
3703 crtc_state->mode_changed = true;
3706 /* ignore any reset values/BIOS leftovers in the WM registers */
3707 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3708 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3710 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3712 WARN_ON(ret == -EDEADLK);
3716 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3718 return intel_has_gpu_reset(dev_priv) &&
3719 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
3722 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3724 struct drm_device *dev = &dev_priv->drm;
3725 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3726 struct drm_atomic_state *state;
3729 /* reset doesn't touch the display */
3730 if (!i915_modparams.force_reset_modeset_test &&
3731 !gpu_reset_clobbers_display(dev_priv))
3734 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3735 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3736 wake_up_all(&dev_priv->gpu_error.wait_queue);
3738 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3739 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3740 i915_gem_set_wedged(dev_priv);
3744 * Need mode_config.mutex so that we don't
3745 * trample ongoing ->detect() and whatnot.
3747 mutex_lock(&dev->mode_config.mutex);
3748 drm_modeset_acquire_init(ctx, 0);
3750 ret = drm_modeset_lock_all_ctx(dev, ctx);
3751 if (ret != -EDEADLK)
3754 drm_modeset_backoff(ctx);
3757 * Disabling the crtcs gracefully seems nicer. Also the
3758 * g33 docs say we should at least disable all the planes.
3760 state = drm_atomic_helper_duplicate_state(dev, ctx);
3761 if (IS_ERR(state)) {
3762 ret = PTR_ERR(state);
3763 DRM_ERROR("Duplicating state failed with %i\n", ret);
3767 ret = drm_atomic_helper_disable_all(dev, ctx);
3769 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3770 drm_atomic_state_put(state);
3774 dev_priv->modeset_restore_state = state;
3775 state->acquire_ctx = ctx;
3778 void intel_finish_reset(struct drm_i915_private *dev_priv)
3780 struct drm_device *dev = &dev_priv->drm;
3781 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3782 struct drm_atomic_state *state;
3785 /* reset doesn't touch the display */
3786 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
3789 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3793 /* reset doesn't touch the display */
3794 if (!gpu_reset_clobbers_display(dev_priv)) {
3795 /* for testing only restore the display */
3796 ret = __intel_display_resume(dev, state, ctx);
3798 DRM_ERROR("Restoring old state failed with %i\n", ret);
3801 * The display has been reset as well,
3802 * so need a full re-initialization.
3804 intel_runtime_pm_disable_interrupts(dev_priv);
3805 intel_runtime_pm_enable_interrupts(dev_priv);
3807 intel_pps_unlock_regs_wa(dev_priv);
3808 intel_modeset_init_hw(dev);
3809 intel_init_clock_gating(dev_priv);
3811 spin_lock_irq(&dev_priv->irq_lock);
3812 if (dev_priv->display.hpd_irq_setup)
3813 dev_priv->display.hpd_irq_setup(dev_priv);
3814 spin_unlock_irq(&dev_priv->irq_lock);
3816 ret = __intel_display_resume(dev, state, ctx);
3818 DRM_ERROR("Restoring old state failed with %i\n", ret);
3820 intel_hpd_init(dev_priv);
3823 drm_atomic_state_put(state);
3825 drm_modeset_drop_locks(ctx);
3826 drm_modeset_acquire_fini(ctx);
3827 mutex_unlock(&dev->mode_config.mutex);
3829 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3832 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3833 const struct intel_crtc_state *new_crtc_state)
3835 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
3836 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3838 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3839 crtc->base.mode = new_crtc_state->base.mode;
3842 * Update pipe size and adjust fitter if needed: the reason for this is
3843 * that in compute_mode_changes we check the native mode (not the pfit
3844 * mode) to see if we can flip rather than do a full mode set. In the
3845 * fastboot case, we'll flip, but if we don't update the pipesrc and
3846 * pfit state, we'll end up with a big fb scanned out into the wrong
3850 I915_WRITE(PIPESRC(crtc->pipe),
3851 ((new_crtc_state->pipe_src_w - 1) << 16) |
3852 (new_crtc_state->pipe_src_h - 1));
3854 /* on skylake this is done by detaching scalers */
3855 if (INTEL_GEN(dev_priv) >= 9) {
3856 skl_detach_scalers(crtc);
3858 if (new_crtc_state->pch_pfit.enabled)
3859 skylake_pfit_enable(crtc);
3860 } else if (HAS_PCH_SPLIT(dev_priv)) {
3861 if (new_crtc_state->pch_pfit.enabled)
3862 ironlake_pfit_enable(crtc);
3863 else if (old_crtc_state->pch_pfit.enabled)
3864 ironlake_pfit_disable(crtc, true);
3868 static void intel_fdi_normal_train(struct intel_crtc *crtc)
3870 struct drm_device *dev = crtc->base.dev;
3871 struct drm_i915_private *dev_priv = to_i915(dev);
3872 int pipe = crtc->pipe;
3876 /* enable normal train */
3877 reg = FDI_TX_CTL(pipe);
3878 temp = I915_READ(reg);
3879 if (IS_IVYBRIDGE(dev_priv)) {
3880 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3881 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3883 temp &= ~FDI_LINK_TRAIN_NONE;
3884 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3886 I915_WRITE(reg, temp);
3888 reg = FDI_RX_CTL(pipe);
3889 temp = I915_READ(reg);
3890 if (HAS_PCH_CPT(dev_priv)) {
3891 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3892 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3894 temp &= ~FDI_LINK_TRAIN_NONE;
3895 temp |= FDI_LINK_TRAIN_NONE;
3897 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3899 /* wait one idle pattern time */
3903 /* IVB wants error correction enabled */
3904 if (IS_IVYBRIDGE(dev_priv))
3905 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3906 FDI_FE_ERRC_ENABLE);
3909 /* The FDI link training functions for ILK/Ibexpeak. */
3910 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3911 const struct intel_crtc_state *crtc_state)
3913 struct drm_device *dev = crtc->base.dev;
3914 struct drm_i915_private *dev_priv = to_i915(dev);
3915 int pipe = crtc->pipe;
3919 /* FDI needs bits from pipe first */
3920 assert_pipe_enabled(dev_priv, pipe);
3922 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3924 reg = FDI_RX_IMR(pipe);
3925 temp = I915_READ(reg);
3926 temp &= ~FDI_RX_SYMBOL_LOCK;
3927 temp &= ~FDI_RX_BIT_LOCK;
3928 I915_WRITE(reg, temp);
3932 /* enable CPU FDI TX and PCH FDI RX */
3933 reg = FDI_TX_CTL(pipe);
3934 temp = I915_READ(reg);
3935 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3936 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3937 temp &= ~FDI_LINK_TRAIN_NONE;
3938 temp |= FDI_LINK_TRAIN_PATTERN_1;
3939 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3941 reg = FDI_RX_CTL(pipe);
3942 temp = I915_READ(reg);
3943 temp &= ~FDI_LINK_TRAIN_NONE;
3944 temp |= FDI_LINK_TRAIN_PATTERN_1;
3945 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3950 /* Ironlake workaround, enable clock pointer after FDI enable*/
3951 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3952 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3953 FDI_RX_PHASE_SYNC_POINTER_EN);
3955 reg = FDI_RX_IIR(pipe);
3956 for (tries = 0; tries < 5; tries++) {
3957 temp = I915_READ(reg);
3958 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3960 if ((temp & FDI_RX_BIT_LOCK)) {
3961 DRM_DEBUG_KMS("FDI train 1 done.\n");
3962 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3967 DRM_ERROR("FDI train 1 fail!\n");
3970 reg = FDI_TX_CTL(pipe);
3971 temp = I915_READ(reg);
3972 temp &= ~FDI_LINK_TRAIN_NONE;
3973 temp |= FDI_LINK_TRAIN_PATTERN_2;
3974 I915_WRITE(reg, temp);
3976 reg = FDI_RX_CTL(pipe);
3977 temp = I915_READ(reg);
3978 temp &= ~FDI_LINK_TRAIN_NONE;
3979 temp |= FDI_LINK_TRAIN_PATTERN_2;
3980 I915_WRITE(reg, temp);
3985 reg = FDI_RX_IIR(pipe);
3986 for (tries = 0; tries < 5; tries++) {
3987 temp = I915_READ(reg);
3988 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3990 if (temp & FDI_RX_SYMBOL_LOCK) {
3991 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3992 DRM_DEBUG_KMS("FDI train 2 done.\n");
3997 DRM_ERROR("FDI train 2 fail!\n");
3999 DRM_DEBUG_KMS("FDI train done\n");
4003 static const int snb_b_fdi_train_param[] = {
4004 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4005 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4006 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4007 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4010 /* The FDI link training functions for SNB/Cougarpoint. */
4011 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4012 const struct intel_crtc_state *crtc_state)
4014 struct drm_device *dev = crtc->base.dev;
4015 struct drm_i915_private *dev_priv = to_i915(dev);
4016 int pipe = crtc->pipe;
4020 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4022 reg = FDI_RX_IMR(pipe);
4023 temp = I915_READ(reg);
4024 temp &= ~FDI_RX_SYMBOL_LOCK;
4025 temp &= ~FDI_RX_BIT_LOCK;
4026 I915_WRITE(reg, temp);
4031 /* enable CPU FDI TX and PCH FDI RX */
4032 reg = FDI_TX_CTL(pipe);
4033 temp = I915_READ(reg);
4034 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4035 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4036 temp &= ~FDI_LINK_TRAIN_NONE;
4037 temp |= FDI_LINK_TRAIN_PATTERN_1;
4038 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4040 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4041 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4043 I915_WRITE(FDI_RX_MISC(pipe),
4044 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4046 reg = FDI_RX_CTL(pipe);
4047 temp = I915_READ(reg);
4048 if (HAS_PCH_CPT(dev_priv)) {
4049 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4050 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4052 temp &= ~FDI_LINK_TRAIN_NONE;
4053 temp |= FDI_LINK_TRAIN_PATTERN_1;
4055 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4060 for (i = 0; i < 4; i++) {
4061 reg = FDI_TX_CTL(pipe);
4062 temp = I915_READ(reg);
4063 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4064 temp |= snb_b_fdi_train_param[i];
4065 I915_WRITE(reg, temp);
4070 for (retry = 0; retry < 5; retry++) {
4071 reg = FDI_RX_IIR(pipe);
4072 temp = I915_READ(reg);
4073 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4074 if (temp & FDI_RX_BIT_LOCK) {
4075 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4076 DRM_DEBUG_KMS("FDI train 1 done.\n");
4085 DRM_ERROR("FDI train 1 fail!\n");
4088 reg = FDI_TX_CTL(pipe);
4089 temp = I915_READ(reg);
4090 temp &= ~FDI_LINK_TRAIN_NONE;
4091 temp |= FDI_LINK_TRAIN_PATTERN_2;
4092 if (IS_GEN6(dev_priv)) {
4093 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4095 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4097 I915_WRITE(reg, temp);
4099 reg = FDI_RX_CTL(pipe);
4100 temp = I915_READ(reg);
4101 if (HAS_PCH_CPT(dev_priv)) {
4102 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4103 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4105 temp &= ~FDI_LINK_TRAIN_NONE;
4106 temp |= FDI_LINK_TRAIN_PATTERN_2;
4108 I915_WRITE(reg, temp);
4113 for (i = 0; i < 4; i++) {
4114 reg = FDI_TX_CTL(pipe);
4115 temp = I915_READ(reg);
4116 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4117 temp |= snb_b_fdi_train_param[i];
4118 I915_WRITE(reg, temp);
4123 for (retry = 0; retry < 5; retry++) {
4124 reg = FDI_RX_IIR(pipe);
4125 temp = I915_READ(reg);
4126 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4127 if (temp & FDI_RX_SYMBOL_LOCK) {
4128 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4129 DRM_DEBUG_KMS("FDI train 2 done.\n");
4138 DRM_ERROR("FDI train 2 fail!\n");
4140 DRM_DEBUG_KMS("FDI train done.\n");
4143 /* Manual link training for Ivy Bridge A0 parts */
4144 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4145 const struct intel_crtc_state *crtc_state)
4147 struct drm_device *dev = crtc->base.dev;
4148 struct drm_i915_private *dev_priv = to_i915(dev);
4149 int pipe = crtc->pipe;
4153 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4155 reg = FDI_RX_IMR(pipe);
4156 temp = I915_READ(reg);
4157 temp &= ~FDI_RX_SYMBOL_LOCK;
4158 temp &= ~FDI_RX_BIT_LOCK;
4159 I915_WRITE(reg, temp);
4164 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4165 I915_READ(FDI_RX_IIR(pipe)));
4167 /* Try each vswing and preemphasis setting twice before moving on */
4168 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4169 /* disable first in case we need to retry */
4170 reg = FDI_TX_CTL(pipe);
4171 temp = I915_READ(reg);
4172 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4173 temp &= ~FDI_TX_ENABLE;
4174 I915_WRITE(reg, temp);
4176 reg = FDI_RX_CTL(pipe);
4177 temp = I915_READ(reg);
4178 temp &= ~FDI_LINK_TRAIN_AUTO;
4179 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4180 temp &= ~FDI_RX_ENABLE;
4181 I915_WRITE(reg, temp);
4183 /* enable CPU FDI TX and PCH FDI RX */
4184 reg = FDI_TX_CTL(pipe);
4185 temp = I915_READ(reg);
4186 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4187 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4188 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4189 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4190 temp |= snb_b_fdi_train_param[j/2];
4191 temp |= FDI_COMPOSITE_SYNC;
4192 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4194 I915_WRITE(FDI_RX_MISC(pipe),
4195 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4197 reg = FDI_RX_CTL(pipe);
4198 temp = I915_READ(reg);
4199 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4200 temp |= FDI_COMPOSITE_SYNC;
4201 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4204 udelay(1); /* should be 0.5us */
4206 for (i = 0; i < 4; i++) {
4207 reg = FDI_RX_IIR(pipe);
4208 temp = I915_READ(reg);
4209 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4211 if (temp & FDI_RX_BIT_LOCK ||
4212 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4213 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4214 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4218 udelay(1); /* should be 0.5us */
4221 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4226 reg = FDI_TX_CTL(pipe);
4227 temp = I915_READ(reg);
4228 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4229 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4230 I915_WRITE(reg, temp);
4232 reg = FDI_RX_CTL(pipe);
4233 temp = I915_READ(reg);
4234 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4235 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4236 I915_WRITE(reg, temp);
4239 udelay(2); /* should be 1.5us */
4241 for (i = 0; i < 4; i++) {
4242 reg = FDI_RX_IIR(pipe);
4243 temp = I915_READ(reg);
4244 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4246 if (temp & FDI_RX_SYMBOL_LOCK ||
4247 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4248 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4249 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4253 udelay(2); /* should be 1.5us */
4256 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4260 DRM_DEBUG_KMS("FDI train done.\n");
4263 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
4265 struct drm_device *dev = intel_crtc->base.dev;
4266 struct drm_i915_private *dev_priv = to_i915(dev);
4267 int pipe = intel_crtc->pipe;
4271 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4272 reg = FDI_RX_CTL(pipe);
4273 temp = I915_READ(reg);
4274 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4275 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
4276 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4277 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4282 /* Switch from Rawclk to PCDclk */
4283 temp = I915_READ(reg);
4284 I915_WRITE(reg, temp | FDI_PCDCLK);
4289 /* Enable CPU FDI TX PLL, always on for Ironlake */
4290 reg = FDI_TX_CTL(pipe);
4291 temp = I915_READ(reg);
4292 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4293 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4300 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4302 struct drm_device *dev = intel_crtc->base.dev;
4303 struct drm_i915_private *dev_priv = to_i915(dev);
4304 int pipe = intel_crtc->pipe;
4308 /* Switch from PCDclk to Rawclk */
4309 reg = FDI_RX_CTL(pipe);
4310 temp = I915_READ(reg);
4311 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4313 /* Disable CPU FDI TX PLL */
4314 reg = FDI_TX_CTL(pipe);
4315 temp = I915_READ(reg);
4316 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4321 reg = FDI_RX_CTL(pipe);
4322 temp = I915_READ(reg);
4323 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4325 /* Wait for the clocks to turn off. */
4330 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4332 struct drm_device *dev = crtc->dev;
4333 struct drm_i915_private *dev_priv = to_i915(dev);
4334 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4335 int pipe = intel_crtc->pipe;
4339 /* disable CPU FDI tx and PCH FDI rx */
4340 reg = FDI_TX_CTL(pipe);
4341 temp = I915_READ(reg);
4342 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4345 reg = FDI_RX_CTL(pipe);
4346 temp = I915_READ(reg);
4347 temp &= ~(0x7 << 16);
4348 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4349 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4354 /* Ironlake workaround, disable clock pointer after downing FDI */
4355 if (HAS_PCH_IBX(dev_priv))
4356 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4358 /* still set train pattern 1 */
4359 reg = FDI_TX_CTL(pipe);
4360 temp = I915_READ(reg);
4361 temp &= ~FDI_LINK_TRAIN_NONE;
4362 temp |= FDI_LINK_TRAIN_PATTERN_1;
4363 I915_WRITE(reg, temp);
4365 reg = FDI_RX_CTL(pipe);
4366 temp = I915_READ(reg);
4367 if (HAS_PCH_CPT(dev_priv)) {
4368 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4369 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4371 temp &= ~FDI_LINK_TRAIN_NONE;
4372 temp |= FDI_LINK_TRAIN_PATTERN_1;
4374 /* BPC in FDI rx is consistent with that in PIPECONF */
4375 temp &= ~(0x07 << 16);
4376 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4377 I915_WRITE(reg, temp);
4383 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4385 struct drm_crtc *crtc;
4388 drm_for_each_crtc(crtc, &dev_priv->drm) {
4389 struct drm_crtc_commit *commit;
4390 spin_lock(&crtc->commit_lock);
4391 commit = list_first_entry_or_null(&crtc->commit_list,
4392 struct drm_crtc_commit, commit_entry);
4393 cleanup_done = commit ?
4394 try_wait_for_completion(&commit->cleanup_done) : true;
4395 spin_unlock(&crtc->commit_lock);
4400 drm_crtc_wait_one_vblank(crtc);
4408 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4412 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4414 mutex_lock(&dev_priv->sb_lock);
4416 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4417 temp |= SBI_SSCCTL_DISABLE;
4418 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4420 mutex_unlock(&dev_priv->sb_lock);
4423 /* Program iCLKIP clock to the desired frequency */
4424 static void lpt_program_iclkip(struct intel_crtc *crtc)
4426 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4427 int clock = crtc->config->base.adjusted_mode.crtc_clock;
4428 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4431 lpt_disable_iclkip(dev_priv);
4433 /* The iCLK virtual clock root frequency is in MHz,
4434 * but the adjusted_mode->crtc_clock in in KHz. To get the
4435 * divisors, it is necessary to divide one by another, so we
4436 * convert the virtual clock precision to KHz here for higher
4439 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4440 u32 iclk_virtual_root_freq = 172800 * 1000;
4441 u32 iclk_pi_range = 64;
4442 u32 desired_divisor;
4444 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4446 divsel = (desired_divisor / iclk_pi_range) - 2;
4447 phaseinc = desired_divisor % iclk_pi_range;
4450 * Near 20MHz is a corner case which is
4451 * out of range for the 7-bit divisor
4457 /* This should not happen with any sane values */
4458 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4459 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4460 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4461 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4463 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4470 mutex_lock(&dev_priv->sb_lock);
4472 /* Program SSCDIVINTPHASE6 */
4473 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4474 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4475 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4476 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4477 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4478 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4479 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4480 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4482 /* Program SSCAUXDIV */
4483 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4484 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4485 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4486 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4488 /* Enable modulator and associated divider */
4489 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4490 temp &= ~SBI_SSCCTL_DISABLE;
4491 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4493 mutex_unlock(&dev_priv->sb_lock);
4495 /* Wait for initialization time */
4498 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4501 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4503 u32 divsel, phaseinc, auxdiv;
4504 u32 iclk_virtual_root_freq = 172800 * 1000;
4505 u32 iclk_pi_range = 64;
4506 u32 desired_divisor;
4509 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4512 mutex_lock(&dev_priv->sb_lock);
4514 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4515 if (temp & SBI_SSCCTL_DISABLE) {
4516 mutex_unlock(&dev_priv->sb_lock);
4520 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4521 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4522 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4523 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4524 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4526 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4527 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4528 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4530 mutex_unlock(&dev_priv->sb_lock);
4532 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4534 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4535 desired_divisor << auxdiv);
4538 static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
4539 enum pipe pch_transcoder)
4541 struct drm_device *dev = crtc->base.dev;
4542 struct drm_i915_private *dev_priv = to_i915(dev);
4543 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
4545 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4546 I915_READ(HTOTAL(cpu_transcoder)));
4547 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4548 I915_READ(HBLANK(cpu_transcoder)));
4549 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4550 I915_READ(HSYNC(cpu_transcoder)));
4552 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4553 I915_READ(VTOTAL(cpu_transcoder)));
4554 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4555 I915_READ(VBLANK(cpu_transcoder)));
4556 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4557 I915_READ(VSYNC(cpu_transcoder)));
4558 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4559 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4562 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4564 struct drm_i915_private *dev_priv = to_i915(dev);
4567 temp = I915_READ(SOUTH_CHICKEN1);
4568 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4571 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4572 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4574 temp &= ~FDI_BC_BIFURCATION_SELECT;
4576 temp |= FDI_BC_BIFURCATION_SELECT;
4578 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4579 I915_WRITE(SOUTH_CHICKEN1, temp);
4580 POSTING_READ(SOUTH_CHICKEN1);
4583 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4585 struct drm_device *dev = intel_crtc->base.dev;
4587 switch (intel_crtc->pipe) {
4591 if (intel_crtc->config->fdi_lanes > 2)
4592 cpt_set_fdi_bc_bifurcation(dev, false);
4594 cpt_set_fdi_bc_bifurcation(dev, true);
4598 cpt_set_fdi_bc_bifurcation(dev, true);
4607 * Finds the encoder associated with the given CRTC. This can only be
4608 * used when we know that the CRTC isn't feeding multiple encoders!
4610 static struct intel_encoder *
4611 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4612 const struct intel_crtc_state *crtc_state)
4614 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4615 const struct drm_connector_state *connector_state;
4616 const struct drm_connector *connector;
4617 struct intel_encoder *encoder = NULL;
4618 int num_encoders = 0;
4621 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4622 if (connector_state->crtc != &crtc->base)
4625 encoder = to_intel_encoder(connector_state->best_encoder);
4629 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4630 num_encoders, pipe_name(crtc->pipe));
4636 * Enable PCH resources required for PCH ports:
4638 * - FDI training & RX/TX
4639 * - update transcoder timings
4640 * - DP transcoding bits
4643 static void ironlake_pch_enable(const struct intel_atomic_state *state,
4644 const struct intel_crtc_state *crtc_state)
4646 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4647 struct drm_device *dev = crtc->base.dev;
4648 struct drm_i915_private *dev_priv = to_i915(dev);
4649 int pipe = crtc->pipe;
4652 assert_pch_transcoder_disabled(dev_priv, pipe);
4654 if (IS_IVYBRIDGE(dev_priv))
4655 ivybridge_update_fdi_bc_bifurcation(crtc);
4657 /* Write the TU size bits before fdi link training, so that error
4658 * detection works. */
4659 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4660 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4662 /* For PCH output, training FDI link */
4663 dev_priv->display.fdi_link_train(crtc, crtc_state);
4665 /* We need to program the right clock selection before writing the pixel
4666 * mutliplier into the DPLL. */
4667 if (HAS_PCH_CPT(dev_priv)) {
4670 temp = I915_READ(PCH_DPLL_SEL);
4671 temp |= TRANS_DPLL_ENABLE(pipe);
4672 sel = TRANS_DPLLB_SEL(pipe);
4673 if (crtc_state->shared_dpll ==
4674 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4678 I915_WRITE(PCH_DPLL_SEL, temp);
4681 /* XXX: pch pll's can be enabled any time before we enable the PCH
4682 * transcoder, and we actually should do this to not upset any PCH
4683 * transcoder that already use the clock when we share it.
4685 * Note that enable_shared_dpll tries to do the right thing, but
4686 * get_shared_dpll unconditionally resets the pll - we need that to have
4687 * the right LVDS enable sequence. */
4688 intel_enable_shared_dpll(crtc);
4690 /* set transcoder timing, panel must allow it */
4691 assert_panel_unlocked(dev_priv, pipe);
4692 ironlake_pch_transcoder_set_timings(crtc, pipe);
4694 intel_fdi_normal_train(crtc);
4696 /* For PCH DP, enable TRANS_DP_CTL */
4697 if (HAS_PCH_CPT(dev_priv) &&
4698 intel_crtc_has_dp_encoder(crtc_state)) {
4699 const struct drm_display_mode *adjusted_mode =
4700 &crtc_state->base.adjusted_mode;
4701 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4702 i915_reg_t reg = TRANS_DP_CTL(pipe);
4705 temp = I915_READ(reg);
4706 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4707 TRANS_DP_SYNC_MASK |
4709 temp |= TRANS_DP_OUTPUT_ENABLE;
4710 temp |= bpc << 9; /* same format but at 11:9 */
4712 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4713 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4714 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4715 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4717 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
4718 WARN_ON(port < PORT_B || port > PORT_D);
4719 temp |= TRANS_DP_PORT_SEL(port);
4721 I915_WRITE(reg, temp);
4724 ironlake_enable_pch_transcoder(dev_priv, pipe);
4727 static void lpt_pch_enable(const struct intel_atomic_state *state,
4728 const struct intel_crtc_state *crtc_state)
4730 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4731 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4732 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4734 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4736 lpt_program_iclkip(crtc);
4738 /* Set transcoder timing. */
4739 ironlake_pch_transcoder_set_timings(crtc, PIPE_A);
4741 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4744 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4746 struct drm_i915_private *dev_priv = to_i915(dev);
4747 i915_reg_t dslreg = PIPEDSL(pipe);
4750 temp = I915_READ(dslreg);
4752 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4753 if (wait_for(I915_READ(dslreg) != temp, 5))
4754 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4759 * The hardware phase 0.0 refers to the center of the pixel.
4760 * We want to start from the top/left edge which is phase
4761 * -0.5. That matches how the hardware calculates the scaling
4762 * factors (from top-left of the first pixel to bottom-right
4763 * of the last pixel, as opposed to the pixel centers).
4765 * For 4:2:0 subsampled chroma planes we obviously have to
4766 * adjust that so that the chroma sample position lands in
4769 * Note that for packed YCbCr 4:2:2 formats there is no way to
4770 * control chroma siting. The hardware simply replicates the
4771 * chroma samples for both of the luma samples, and thus we don't
4772 * actually get the expected MPEG2 chroma siting convention :(
4773 * The same behaviour is observed on pre-SKL platforms as well.
4775 u16 skl_scaler_calc_phase(int sub, bool chroma_cosited)
4777 int phase = -0x8000;
4781 phase += (sub - 1) * 0x8000 / sub;
4784 phase = 0x10000 + phase;
4786 trip = PS_PHASE_TRIP;
4788 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4792 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4793 unsigned int scaler_user, int *scaler_id,
4794 int src_w, int src_h, int dst_w, int dst_h,
4795 bool plane_scaler_check,
4796 uint32_t pixel_format)
4798 struct intel_crtc_scaler_state *scaler_state =
4799 &crtc_state->scaler_state;
4800 struct intel_crtc *intel_crtc =
4801 to_intel_crtc(crtc_state->base.crtc);
4802 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4803 const struct drm_display_mode *adjusted_mode =
4804 &crtc_state->base.adjusted_mode;
4808 * Src coordinates are already rotated by 270 degrees for
4809 * the 90/270 degree plane rotation cases (to match the
4810 * GTT mapping), hence no need to account for rotation here.
4812 need_scaling = src_w != dst_w || src_h != dst_h;
4814 if (plane_scaler_check)
4815 if (pixel_format == DRM_FORMAT_NV12)
4816 need_scaling = true;
4818 if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX)
4819 need_scaling = true;
4822 * Scaling/fitting not supported in IF-ID mode in GEN9+
4823 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4824 * Once NV12 is enabled, handle it here while allocating scaler
4827 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4828 need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4829 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4834 * if plane is being disabled or scaler is no more required or force detach
4835 * - free scaler binded to this plane/crtc
4836 * - in order to do this, update crtc->scaler_usage
4838 * Here scaler state in crtc_state is set free so that
4839 * scaler can be assigned to other user. Actual register
4840 * update to free the scaler is done in plane/panel-fit programming.
4841 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4843 if (force_detach || !need_scaling) {
4844 if (*scaler_id >= 0) {
4845 scaler_state->scaler_users &= ~(1 << scaler_user);
4846 scaler_state->scalers[*scaler_id].in_use = 0;
4848 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4849 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4850 intel_crtc->pipe, scaler_user, *scaler_id,
4851 scaler_state->scaler_users);
4857 if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 &&
4858 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
4859 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4864 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4865 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4866 (IS_GEN11(dev_priv) &&
4867 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4868 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4869 (!IS_GEN11(dev_priv) &&
4870 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4871 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
4872 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4873 "size is out of scaler range\n",
4874 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4878 /* mark this plane as a scaler user in crtc_state */
4879 scaler_state->scaler_users |= (1 << scaler_user);
4880 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4881 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4882 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4883 scaler_state->scaler_users);
4889 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4891 * @state: crtc's scaler state
4894 * 0 - scaler_usage updated successfully
4895 * error - requested scaling cannot be supported or other error condition
4897 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4899 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
4901 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4902 &state->scaler_state.scaler_id,
4903 state->pipe_src_w, state->pipe_src_h,
4904 adjusted_mode->crtc_hdisplay,
4905 adjusted_mode->crtc_vdisplay, false, 0);
4909 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4910 * @crtc_state: crtc's scaler state
4911 * @plane_state: atomic plane state to update
4914 * 0 - scaler_usage updated successfully
4915 * error - requested scaling cannot be supported or other error condition
4917 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4918 struct intel_plane_state *plane_state)
4921 struct intel_plane *intel_plane =
4922 to_intel_plane(plane_state->base.plane);
4923 struct drm_framebuffer *fb = plane_state->base.fb;
4926 bool force_detach = !fb || !plane_state->base.visible;
4928 ret = skl_update_scaler(crtc_state, force_detach,
4929 drm_plane_index(&intel_plane->base),
4930 &plane_state->scaler_id,
4931 drm_rect_width(&plane_state->base.src) >> 16,
4932 drm_rect_height(&plane_state->base.src) >> 16,
4933 drm_rect_width(&plane_state->base.dst),
4934 drm_rect_height(&plane_state->base.dst),
4935 fb ? true : false, fb ? fb->format->format : 0);
4937 if (ret || plane_state->scaler_id < 0)
4940 /* check colorkey */
4941 if (plane_state->ckey.flags) {
4942 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4943 intel_plane->base.base.id,
4944 intel_plane->base.name);
4948 /* Check src format */
4949 switch (fb->format->format) {
4950 case DRM_FORMAT_RGB565:
4951 case DRM_FORMAT_XBGR8888:
4952 case DRM_FORMAT_XRGB8888:
4953 case DRM_FORMAT_ABGR8888:
4954 case DRM_FORMAT_ARGB8888:
4955 case DRM_FORMAT_XRGB2101010:
4956 case DRM_FORMAT_XBGR2101010:
4957 case DRM_FORMAT_YUYV:
4958 case DRM_FORMAT_YVYU:
4959 case DRM_FORMAT_UYVY:
4960 case DRM_FORMAT_VYUY:
4961 case DRM_FORMAT_NV12:
4964 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4965 intel_plane->base.base.id, intel_plane->base.name,
4966 fb->base.id, fb->format->format);
4973 static void skylake_scaler_disable(struct intel_crtc *crtc)
4977 for (i = 0; i < crtc->num_scalers; i++)
4978 skl_detach_scaler(crtc, i);
4981 static void skylake_pfit_enable(struct intel_crtc *crtc)
4983 struct drm_device *dev = crtc->base.dev;
4984 struct drm_i915_private *dev_priv = to_i915(dev);
4985 int pipe = crtc->pipe;
4986 struct intel_crtc_scaler_state *scaler_state =
4987 &crtc->config->scaler_state;
4989 if (crtc->config->pch_pfit.enabled) {
4990 u16 uv_rgb_hphase, uv_rgb_vphase;
4993 if (WARN_ON(crtc->config->scaler_state.scaler_id < 0))
4996 uv_rgb_hphase = skl_scaler_calc_phase(1, false);
4997 uv_rgb_vphase = skl_scaler_calc_phase(1, false);
4999 id = scaler_state->scaler_id;
5000 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5001 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5002 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5003 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5004 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5005 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5006 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
5007 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
5011 static void ironlake_pfit_enable(struct intel_crtc *crtc)
5013 struct drm_device *dev = crtc->base.dev;
5014 struct drm_i915_private *dev_priv = to_i915(dev);
5015 int pipe = crtc->pipe;
5017 if (crtc->config->pch_pfit.enabled) {
5018 /* Force use of hard-coded filter coefficients
5019 * as some pre-programmed values are broken,
5022 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5023 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5024 PF_PIPE_SEL_IVB(pipe));
5026 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5027 I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
5028 I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
5032 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5034 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5035 struct drm_device *dev = crtc->base.dev;
5036 struct drm_i915_private *dev_priv = to_i915(dev);
5038 if (!crtc_state->ips_enabled)
5042 * We can only enable IPS after we enable a plane and wait for a vblank
5043 * This function is called from post_plane_update, which is run after
5046 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5048 if (IS_BROADWELL(dev_priv)) {
5049 mutex_lock(&dev_priv->pcu_lock);
5050 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5051 IPS_ENABLE | IPS_PCODE_CONTROL));
5052 mutex_unlock(&dev_priv->pcu_lock);
5053 /* Quoting Art Runyan: "its not safe to expect any particular
5054 * value in IPS_CTL bit 31 after enabling IPS through the
5055 * mailbox." Moreover, the mailbox may return a bogus state,
5056 * so we need to just enable it and continue on.
5059 I915_WRITE(IPS_CTL, IPS_ENABLE);
5060 /* The bit only becomes 1 in the next vblank, so this wait here
5061 * is essentially intel_wait_for_vblank. If we don't have this
5062 * and don't wait for vblanks until the end of crtc_enable, then
5063 * the HW state readout code will complain that the expected
5064 * IPS_CTL value is not the one we read. */
5065 if (intel_wait_for_register(dev_priv,
5066 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5068 DRM_ERROR("Timed out waiting for IPS enable\n");
5072 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5074 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5075 struct drm_device *dev = crtc->base.dev;
5076 struct drm_i915_private *dev_priv = to_i915(dev);
5078 if (!crtc_state->ips_enabled)
5081 if (IS_BROADWELL(dev_priv)) {
5082 mutex_lock(&dev_priv->pcu_lock);
5083 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5084 mutex_unlock(&dev_priv->pcu_lock);
5086 * Wait for PCODE to finish disabling IPS. The BSpec specified
5087 * 42ms timeout value leads to occasional timeouts so use 100ms
5090 if (intel_wait_for_register(dev_priv,
5091 IPS_CTL, IPS_ENABLE, 0,
5093 DRM_ERROR("Timed out waiting for IPS disable\n");
5095 I915_WRITE(IPS_CTL, 0);
5096 POSTING_READ(IPS_CTL);
5099 /* We need to wait for a vblank before we can disable the plane. */
5100 intel_wait_for_vblank(dev_priv, crtc->pipe);
5103 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5105 if (intel_crtc->overlay) {
5106 struct drm_device *dev = intel_crtc->base.dev;
5108 mutex_lock(&dev->struct_mutex);
5109 (void) intel_overlay_switch_off(intel_crtc->overlay);
5110 mutex_unlock(&dev->struct_mutex);
5113 /* Let userspace switch the overlay on again. In most cases userspace
5114 * has to recompute where to put it anyway.
5119 * intel_post_enable_primary - Perform operations after enabling primary plane
5120 * @crtc: the CRTC whose primary plane was just enabled
5121 * @new_crtc_state: the enabling state
5123 * Performs potentially sleeping operations that must be done after the primary
5124 * plane is enabled, such as updating FBC and IPS. Note that this may be
5125 * called due to an explicit primary plane update, or due to an implicit
5126 * re-enable that is caused when a sprite plane is updated to no longer
5127 * completely hide the primary plane.
5130 intel_post_enable_primary(struct drm_crtc *crtc,
5131 const struct intel_crtc_state *new_crtc_state)
5133 struct drm_device *dev = crtc->dev;
5134 struct drm_i915_private *dev_priv = to_i915(dev);
5135 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5136 int pipe = intel_crtc->pipe;
5139 * Gen2 reports pipe underruns whenever all planes are disabled.
5140 * So don't enable underrun reporting before at least some planes
5142 * FIXME: Need to fix the logic to work when we turn off all planes
5143 * but leave the pipe running.
5145 if (IS_GEN2(dev_priv))
5146 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5148 /* Underruns don't always raise interrupts, so check manually. */
5149 intel_check_cpu_fifo_underruns(dev_priv);
5150 intel_check_pch_fifo_underruns(dev_priv);
5153 /* FIXME get rid of this and use pre_plane_update */
5155 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5157 struct drm_device *dev = crtc->dev;
5158 struct drm_i915_private *dev_priv = to_i915(dev);
5159 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5160 int pipe = intel_crtc->pipe;
5163 * Gen2 reports pipe underruns whenever all planes are disabled.
5164 * So disable underrun reporting before all the planes get disabled.
5166 if (IS_GEN2(dev_priv))
5167 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5169 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5172 * Vblank time updates from the shadow to live plane control register
5173 * are blocked if the memory self-refresh mode is active at that
5174 * moment. So to make sure the plane gets truly disabled, disable
5175 * first the self-refresh mode. The self-refresh enable bit in turn
5176 * will be checked/applied by the HW only at the next frame start
5177 * event which is after the vblank start event, so we need to have a
5178 * wait-for-vblank between disabling the plane and the pipe.
5180 if (HAS_GMCH_DISPLAY(dev_priv) &&
5181 intel_set_memory_cxsr(dev_priv, false))
5182 intel_wait_for_vblank(dev_priv, pipe);
5185 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5186 const struct intel_crtc_state *new_crtc_state)
5188 if (!old_crtc_state->ips_enabled)
5191 if (needs_modeset(&new_crtc_state->base))
5194 return !new_crtc_state->ips_enabled;
5197 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5198 const struct intel_crtc_state *new_crtc_state)
5200 if (!new_crtc_state->ips_enabled)
5203 if (needs_modeset(&new_crtc_state->base))
5207 * We can't read out IPS on broadwell, assume the worst and
5208 * forcibly enable IPS on the first fastset.
5210 if (new_crtc_state->update_pipe &&
5211 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5214 return !old_crtc_state->ips_enabled;
5217 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5218 const struct intel_crtc_state *crtc_state)
5220 if (!crtc_state->nv12_planes)
5223 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
5226 if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
5227 IS_CANNONLAKE(dev_priv))
5233 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5235 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5236 struct drm_device *dev = crtc->base.dev;
5237 struct drm_i915_private *dev_priv = to_i915(dev);
5238 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5239 struct intel_crtc_state *pipe_config =
5240 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5242 struct drm_plane *primary = crtc->base.primary;
5243 struct drm_plane_state *old_primary_state =
5244 drm_atomic_get_old_plane_state(old_state, primary);
5246 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5248 if (pipe_config->update_wm_post && pipe_config->base.active)
5249 intel_update_watermarks(crtc);
5251 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5252 hsw_enable_ips(pipe_config);
5254 if (old_primary_state) {
5255 struct drm_plane_state *new_primary_state =
5256 drm_atomic_get_new_plane_state(old_state, primary);
5258 intel_fbc_post_update(crtc);
5260 if (new_primary_state->visible &&
5261 (needs_modeset(&pipe_config->base) ||
5262 !old_primary_state->visible))
5263 intel_post_enable_primary(&crtc->base, pipe_config);
5266 /* Display WA 827 */
5267 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5268 !needs_nv12_wa(dev_priv, pipe_config)) {
5269 skl_wa_clkgate(dev_priv, crtc->pipe, false);
5270 skl_wa_528(dev_priv, crtc->pipe, false);
5274 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5275 struct intel_crtc_state *pipe_config)
5277 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5278 struct drm_device *dev = crtc->base.dev;
5279 struct drm_i915_private *dev_priv = to_i915(dev);
5280 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5281 struct drm_plane *primary = crtc->base.primary;
5282 struct drm_plane_state *old_primary_state =
5283 drm_atomic_get_old_plane_state(old_state, primary);
5284 bool modeset = needs_modeset(&pipe_config->base);
5285 struct intel_atomic_state *old_intel_state =
5286 to_intel_atomic_state(old_state);
5288 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5289 hsw_disable_ips(old_crtc_state);
5291 if (old_primary_state) {
5292 struct intel_plane_state *new_primary_state =
5293 intel_atomic_get_new_plane_state(old_intel_state,
5294 to_intel_plane(primary));
5296 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5298 * Gen2 reports pipe underruns whenever all planes are disabled.
5299 * So disable underrun reporting before all the planes get disabled.
5301 if (IS_GEN2(dev_priv) && old_primary_state->visible &&
5302 (modeset || !new_primary_state->base.visible))
5303 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5306 /* Display WA 827 */
5307 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5308 needs_nv12_wa(dev_priv, pipe_config)) {
5309 skl_wa_clkgate(dev_priv, crtc->pipe, true);
5310 skl_wa_528(dev_priv, crtc->pipe, true);
5314 * Vblank time updates from the shadow to live plane control register
5315 * are blocked if the memory self-refresh mode is active at that
5316 * moment. So to make sure the plane gets truly disabled, disable
5317 * first the self-refresh mode. The self-refresh enable bit in turn
5318 * will be checked/applied by the HW only at the next frame start
5319 * event which is after the vblank start event, so we need to have a
5320 * wait-for-vblank between disabling the plane and the pipe.
5322 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5323 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5324 intel_wait_for_vblank(dev_priv, crtc->pipe);
5327 * IVB workaround: must disable low power watermarks for at least
5328 * one frame before enabling scaling. LP watermarks can be re-enabled
5329 * when scaling is disabled.
5331 * WaCxSRDisabledForSpriteScaling:ivb
5333 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev))
5334 intel_wait_for_vblank(dev_priv, crtc->pipe);
5337 * If we're doing a modeset, we're done. No need to do any pre-vblank
5338 * watermark programming here.
5340 if (needs_modeset(&pipe_config->base))
5344 * For platforms that support atomic watermarks, program the
5345 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5346 * will be the intermediate values that are safe for both pre- and
5347 * post- vblank; when vblank happens, the 'active' values will be set
5348 * to the final 'target' values and we'll do this again to get the
5349 * optimal watermarks. For gen9+ platforms, the values we program here
5350 * will be the final target values which will get automatically latched
5351 * at vblank time; no further programming will be necessary.
5353 * If a platform hasn't been transitioned to atomic watermarks yet,
5354 * we'll continue to update watermarks the old way, if flags tell
5357 if (dev_priv->display.initial_watermarks != NULL)
5358 dev_priv->display.initial_watermarks(old_intel_state,
5360 else if (pipe_config->update_wm_pre)
5361 intel_update_watermarks(crtc);
5364 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
5366 struct drm_device *dev = crtc->dev;
5367 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5368 struct drm_plane *p;
5369 int pipe = intel_crtc->pipe;
5371 intel_crtc_dpms_overlay_disable(intel_crtc);
5373 drm_for_each_plane_mask(p, dev, plane_mask)
5374 to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc);
5377 * FIXME: Once we grow proper nuclear flip support out of this we need
5378 * to compute the mask of flip planes precisely. For the time being
5379 * consider this a flip to a NULL plane.
5381 intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe));
5384 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5385 struct intel_crtc_state *crtc_state,
5386 struct drm_atomic_state *old_state)
5388 struct drm_connector_state *conn_state;
5389 struct drm_connector *conn;
5392 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5393 struct intel_encoder *encoder =
5394 to_intel_encoder(conn_state->best_encoder);
5396 if (conn_state->crtc != crtc)
5399 if (encoder->pre_pll_enable)
5400 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5404 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5405 struct intel_crtc_state *crtc_state,
5406 struct drm_atomic_state *old_state)
5408 struct drm_connector_state *conn_state;
5409 struct drm_connector *conn;
5412 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5413 struct intel_encoder *encoder =
5414 to_intel_encoder(conn_state->best_encoder);
5416 if (conn_state->crtc != crtc)
5419 if (encoder->pre_enable)
5420 encoder->pre_enable(encoder, crtc_state, conn_state);
5424 static void intel_encoders_enable(struct drm_crtc *crtc,
5425 struct intel_crtc_state *crtc_state,
5426 struct drm_atomic_state *old_state)
5428 struct drm_connector_state *conn_state;
5429 struct drm_connector *conn;
5432 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5433 struct intel_encoder *encoder =
5434 to_intel_encoder(conn_state->best_encoder);
5436 if (conn_state->crtc != crtc)
5439 encoder->enable(encoder, crtc_state, conn_state);
5440 intel_opregion_notify_encoder(encoder, true);
5444 static void intel_encoders_disable(struct drm_crtc *crtc,
5445 struct intel_crtc_state *old_crtc_state,
5446 struct drm_atomic_state *old_state)
5448 struct drm_connector_state *old_conn_state;
5449 struct drm_connector *conn;
5452 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5453 struct intel_encoder *encoder =
5454 to_intel_encoder(old_conn_state->best_encoder);
5456 if (old_conn_state->crtc != crtc)
5459 intel_opregion_notify_encoder(encoder, false);
5460 encoder->disable(encoder, old_crtc_state, old_conn_state);
5464 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5465 struct intel_crtc_state *old_crtc_state,
5466 struct drm_atomic_state *old_state)
5468 struct drm_connector_state *old_conn_state;
5469 struct drm_connector *conn;
5472 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5473 struct intel_encoder *encoder =
5474 to_intel_encoder(old_conn_state->best_encoder);
5476 if (old_conn_state->crtc != crtc)
5479 if (encoder->post_disable)
5480 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5484 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5485 struct intel_crtc_state *old_crtc_state,
5486 struct drm_atomic_state *old_state)
5488 struct drm_connector_state *old_conn_state;
5489 struct drm_connector *conn;
5492 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5493 struct intel_encoder *encoder =
5494 to_intel_encoder(old_conn_state->best_encoder);
5496 if (old_conn_state->crtc != crtc)
5499 if (encoder->post_pll_disable)
5500 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5504 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5505 struct drm_atomic_state *old_state)
5507 struct drm_crtc *crtc = pipe_config->base.crtc;
5508 struct drm_device *dev = crtc->dev;
5509 struct drm_i915_private *dev_priv = to_i915(dev);
5510 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5511 int pipe = intel_crtc->pipe;
5512 struct intel_atomic_state *old_intel_state =
5513 to_intel_atomic_state(old_state);
5515 if (WARN_ON(intel_crtc->active))
5519 * Sometimes spurious CPU pipe underruns happen during FDI
5520 * training, at least with VGA+HDMI cloning. Suppress them.
5522 * On ILK we get an occasional spurious CPU pipe underruns
5523 * between eDP port A enable and vdd enable. Also PCH port
5524 * enable seems to result in the occasional CPU pipe underrun.
5526 * Spurious PCH underruns also occur during PCH enabling.
5528 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5529 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5531 if (intel_crtc->config->has_pch_encoder)
5532 intel_prepare_shared_dpll(intel_crtc);
5534 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5535 intel_dp_set_m_n(intel_crtc, M1_N1);
5537 intel_set_pipe_timings(intel_crtc);
5538 intel_set_pipe_src_size(intel_crtc);
5540 if (intel_crtc->config->has_pch_encoder) {
5541 intel_cpu_transcoder_set_m_n(intel_crtc,
5542 &intel_crtc->config->fdi_m_n, NULL);
5545 ironlake_set_pipeconf(crtc);
5547 intel_crtc->active = true;
5549 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5551 if (intel_crtc->config->has_pch_encoder) {
5552 /* Note: FDI PLL enabling _must_ be done before we enable the
5553 * cpu pipes, hence this is separate from all the other fdi/pch
5555 ironlake_fdi_pll_enable(intel_crtc);
5557 assert_fdi_tx_disabled(dev_priv, pipe);
5558 assert_fdi_rx_disabled(dev_priv, pipe);
5561 ironlake_pfit_enable(intel_crtc);
5564 * On ILK+ LUT must be loaded before the pipe is running but with
5567 intel_color_load_luts(&pipe_config->base);
5569 if (dev_priv->display.initial_watermarks != NULL)
5570 dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config);
5571 intel_enable_pipe(pipe_config);
5573 if (intel_crtc->config->has_pch_encoder)
5574 ironlake_pch_enable(old_intel_state, pipe_config);
5576 assert_vblank_disabled(crtc);
5577 drm_crtc_vblank_on(crtc);
5579 intel_encoders_enable(crtc, pipe_config, old_state);
5581 if (HAS_PCH_CPT(dev_priv))
5582 cpt_verify_modeset(dev, intel_crtc->pipe);
5585 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5586 * And a second vblank wait is needed at least on ILK with
5587 * some interlaced HDMI modes. Let's do the double wait always
5588 * in case there are more corner cases we don't know about.
5590 if (intel_crtc->config->has_pch_encoder) {
5591 intel_wait_for_vblank(dev_priv, pipe);
5592 intel_wait_for_vblank(dev_priv, pipe);
5594 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5595 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5598 /* IPS only exists on ULT machines and is tied to pipe A. */
5599 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5601 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5604 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5605 enum pipe pipe, bool apply)
5607 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5608 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5615 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5618 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5620 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5621 enum pipe pipe = crtc->pipe;
5624 val = MBUS_DBOX_BW_CREDIT(1) | MBUS_DBOX_A_CREDIT(2);
5626 /* Program B credit equally to all pipes */
5627 val |= MBUS_DBOX_B_CREDIT(24 / INTEL_INFO(dev_priv)->num_pipes);
5629 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5632 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5633 struct drm_atomic_state *old_state)
5635 struct drm_crtc *crtc = pipe_config->base.crtc;
5636 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5637 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5638 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5639 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5640 struct intel_atomic_state *old_intel_state =
5641 to_intel_atomic_state(old_state);
5642 bool psl_clkgate_wa;
5645 if (WARN_ON(intel_crtc->active))
5648 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5650 if (intel_crtc->config->shared_dpll)
5651 intel_enable_shared_dpll(intel_crtc);
5653 if (INTEL_GEN(dev_priv) >= 11)
5654 icl_map_plls_to_ports(crtc, pipe_config, old_state);
5656 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5658 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5659 intel_dp_set_m_n(intel_crtc, M1_N1);
5661 if (!transcoder_is_dsi(cpu_transcoder))
5662 intel_set_pipe_timings(intel_crtc);
5664 intel_set_pipe_src_size(intel_crtc);
5666 if (cpu_transcoder != TRANSCODER_EDP &&
5667 !transcoder_is_dsi(cpu_transcoder)) {
5668 I915_WRITE(PIPE_MULT(cpu_transcoder),
5669 intel_crtc->config->pixel_multiplier - 1);
5672 if (intel_crtc->config->has_pch_encoder) {
5673 intel_cpu_transcoder_set_m_n(intel_crtc,
5674 &intel_crtc->config->fdi_m_n, NULL);
5677 if (!transcoder_is_dsi(cpu_transcoder))
5678 haswell_set_pipeconf(crtc);
5680 haswell_set_pipemisc(crtc);
5682 intel_color_set_csc(&pipe_config->base);
5684 intel_crtc->active = true;
5686 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5687 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5688 intel_crtc->config->pch_pfit.enabled;
5690 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5692 if (INTEL_GEN(dev_priv) >= 9)
5693 skylake_pfit_enable(intel_crtc);
5695 ironlake_pfit_enable(intel_crtc);
5698 * On ILK+ LUT must be loaded before the pipe is running but with
5701 intel_color_load_luts(&pipe_config->base);
5704 * Display WA #1153: enable hardware to bypass the alpha math
5705 * and rounding for per-pixel values 00 and 0xff
5707 if (INTEL_GEN(dev_priv) >= 11) {
5708 pipe_chicken = I915_READ(PIPE_CHICKEN(pipe));
5709 if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN))
5710 I915_WRITE_FW(PIPE_CHICKEN(pipe),
5711 pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN);
5714 intel_ddi_set_pipe_settings(pipe_config);
5715 if (!transcoder_is_dsi(cpu_transcoder))
5716 intel_ddi_enable_transcoder_func(pipe_config);
5718 if (dev_priv->display.initial_watermarks != NULL)
5719 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5721 if (INTEL_GEN(dev_priv) >= 11)
5722 icl_pipe_mbus_enable(intel_crtc);
5724 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5725 if (!transcoder_is_dsi(cpu_transcoder))
5726 intel_enable_pipe(pipe_config);
5728 if (intel_crtc->config->has_pch_encoder)
5729 lpt_pch_enable(old_intel_state, pipe_config);
5731 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5732 intel_ddi_set_vc_payload_alloc(pipe_config, true);
5734 assert_vblank_disabled(crtc);
5735 drm_crtc_vblank_on(crtc);
5737 intel_encoders_enable(crtc, pipe_config, old_state);
5739 if (psl_clkgate_wa) {
5740 intel_wait_for_vblank(dev_priv, pipe);
5741 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5744 /* If we change the relative order between pipe/planes enabling, we need
5745 * to change the workaround. */
5746 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
5747 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5748 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5749 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5753 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force)
5755 struct drm_device *dev = crtc->base.dev;
5756 struct drm_i915_private *dev_priv = to_i915(dev);
5757 int pipe = crtc->pipe;
5759 /* To avoid upsetting the power well on haswell only disable the pfit if
5760 * it's in use. The hw state code will make sure we get this right. */
5761 if (force || crtc->config->pch_pfit.enabled) {
5762 I915_WRITE(PF_CTL(pipe), 0);
5763 I915_WRITE(PF_WIN_POS(pipe), 0);
5764 I915_WRITE(PF_WIN_SZ(pipe), 0);
5768 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5769 struct drm_atomic_state *old_state)
5771 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5772 struct drm_device *dev = crtc->dev;
5773 struct drm_i915_private *dev_priv = to_i915(dev);
5774 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5775 int pipe = intel_crtc->pipe;
5778 * Sometimes spurious CPU pipe underruns happen when the
5779 * pipe is already disabled, but FDI RX/TX is still enabled.
5780 * Happens at least with VGA+HDMI cloning. Suppress them.
5782 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5783 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5785 intel_encoders_disable(crtc, old_crtc_state, old_state);
5787 drm_crtc_vblank_off(crtc);
5788 assert_vblank_disabled(crtc);
5790 intel_disable_pipe(old_crtc_state);
5792 ironlake_pfit_disable(intel_crtc, false);
5794 if (intel_crtc->config->has_pch_encoder)
5795 ironlake_fdi_disable(crtc);
5797 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5799 if (intel_crtc->config->has_pch_encoder) {
5800 ironlake_disable_pch_transcoder(dev_priv, pipe);
5802 if (HAS_PCH_CPT(dev_priv)) {
5806 /* disable TRANS_DP_CTL */
5807 reg = TRANS_DP_CTL(pipe);
5808 temp = I915_READ(reg);
5809 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5810 TRANS_DP_PORT_SEL_MASK);
5811 temp |= TRANS_DP_PORT_SEL_NONE;
5812 I915_WRITE(reg, temp);
5814 /* disable DPLL_SEL */
5815 temp = I915_READ(PCH_DPLL_SEL);
5816 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5817 I915_WRITE(PCH_DPLL_SEL, temp);
5820 ironlake_fdi_pll_disable(intel_crtc);
5823 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5824 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5827 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5828 struct drm_atomic_state *old_state)
5830 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5831 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5832 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5833 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
5835 intel_encoders_disable(crtc, old_crtc_state, old_state);
5837 drm_crtc_vblank_off(crtc);
5838 assert_vblank_disabled(crtc);
5840 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5841 if (!transcoder_is_dsi(cpu_transcoder))
5842 intel_disable_pipe(old_crtc_state);
5844 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
5845 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
5847 if (!transcoder_is_dsi(cpu_transcoder))
5848 intel_ddi_disable_transcoder_func(old_crtc_state);
5850 if (INTEL_GEN(dev_priv) >= 9)
5851 skylake_scaler_disable(intel_crtc);
5853 ironlake_pfit_disable(intel_crtc, false);
5855 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5857 if (INTEL_GEN(dev_priv) >= 11)
5858 icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state);
5861 static void i9xx_pfit_enable(struct intel_crtc *crtc)
5863 struct drm_device *dev = crtc->base.dev;
5864 struct drm_i915_private *dev_priv = to_i915(dev);
5865 struct intel_crtc_state *pipe_config = crtc->config;
5867 if (!pipe_config->gmch_pfit.control)
5871 * The panel fitter should only be adjusted whilst the pipe is disabled,
5872 * according to register description and PRM.
5874 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5875 assert_pipe_disabled(dev_priv, crtc->pipe);
5877 I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
5878 I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
5880 /* Border color in case we don't scale up to the full screen. Black by
5881 * default, change to something else for debugging. */
5882 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5885 bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
5887 if (IS_ICELAKE(dev_priv))
5888 return port >= PORT_C && port <= PORT_F;
5893 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
5895 if (!intel_port_is_tc(dev_priv, port))
5896 return PORT_TC_NONE;
5898 return port - PORT_C;
5901 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
5905 return POWER_DOMAIN_PORT_DDI_A_LANES;
5907 return POWER_DOMAIN_PORT_DDI_B_LANES;
5909 return POWER_DOMAIN_PORT_DDI_C_LANES;
5911 return POWER_DOMAIN_PORT_DDI_D_LANES;
5913 return POWER_DOMAIN_PORT_DDI_E_LANES;
5915 return POWER_DOMAIN_PORT_DDI_F_LANES;
5918 return POWER_DOMAIN_PORT_OTHER;
5922 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
5923 struct intel_crtc_state *crtc_state)
5925 struct drm_device *dev = crtc->dev;
5926 struct drm_i915_private *dev_priv = to_i915(dev);
5927 struct drm_encoder *encoder;
5928 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5929 enum pipe pipe = intel_crtc->pipe;
5931 enum transcoder transcoder = crtc_state->cpu_transcoder;
5933 if (!crtc_state->base.active)
5936 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
5937 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
5938 if (crtc_state->pch_pfit.enabled ||
5939 crtc_state->pch_pfit.force_thru)
5940 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5942 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
5943 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5945 mask |= BIT_ULL(intel_encoder->power_domain);
5948 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
5949 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
5951 if (crtc_state->shared_dpll)
5952 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
5958 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
5959 struct intel_crtc_state *crtc_state)
5961 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5962 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5963 enum intel_display_power_domain domain;
5964 u64 domains, new_domains, old_domains;
5966 old_domains = intel_crtc->enabled_power_domains;
5967 intel_crtc->enabled_power_domains = new_domains =
5968 get_crtc_power_domains(crtc, crtc_state);
5970 domains = new_domains & ~old_domains;
5972 for_each_power_domain(domain, domains)
5973 intel_display_power_get(dev_priv, domain);
5975 return old_domains & ~new_domains;
5978 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
5981 enum intel_display_power_domain domain;
5983 for_each_power_domain(domain, domains)
5984 intel_display_power_put(dev_priv, domain);
5987 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
5988 struct drm_atomic_state *old_state)
5990 struct intel_atomic_state *old_intel_state =
5991 to_intel_atomic_state(old_state);
5992 struct drm_crtc *crtc = pipe_config->base.crtc;
5993 struct drm_device *dev = crtc->dev;
5994 struct drm_i915_private *dev_priv = to_i915(dev);
5995 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5996 int pipe = intel_crtc->pipe;
5998 if (WARN_ON(intel_crtc->active))
6001 if (intel_crtc_has_dp_encoder(intel_crtc->config))
6002 intel_dp_set_m_n(intel_crtc, M1_N1);
6004 intel_set_pipe_timings(intel_crtc);
6005 intel_set_pipe_src_size(intel_crtc);
6007 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6008 struct drm_i915_private *dev_priv = to_i915(dev);
6010 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6011 I915_WRITE(CHV_CANVAS(pipe), 0);
6014 i9xx_set_pipeconf(intel_crtc);
6016 intel_crtc->active = true;
6018 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6020 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
6022 if (IS_CHERRYVIEW(dev_priv)) {
6023 chv_prepare_pll(intel_crtc, intel_crtc->config);
6024 chv_enable_pll(intel_crtc, intel_crtc->config);
6026 vlv_prepare_pll(intel_crtc, intel_crtc->config);
6027 vlv_enable_pll(intel_crtc, intel_crtc->config);
6030 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6032 i9xx_pfit_enable(intel_crtc);
6034 intel_color_load_luts(&pipe_config->base);
6036 dev_priv->display.initial_watermarks(old_intel_state,
6038 intel_enable_pipe(pipe_config);
6040 assert_vblank_disabled(crtc);
6041 drm_crtc_vblank_on(crtc);
6043 intel_encoders_enable(crtc, pipe_config, old_state);
6046 static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
6048 struct drm_device *dev = crtc->base.dev;
6049 struct drm_i915_private *dev_priv = to_i915(dev);
6051 I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
6052 I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
6055 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6056 struct drm_atomic_state *old_state)
6058 struct intel_atomic_state *old_intel_state =
6059 to_intel_atomic_state(old_state);
6060 struct drm_crtc *crtc = pipe_config->base.crtc;
6061 struct drm_device *dev = crtc->dev;
6062 struct drm_i915_private *dev_priv = to_i915(dev);
6063 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6064 enum pipe pipe = intel_crtc->pipe;
6066 if (WARN_ON(intel_crtc->active))
6069 i9xx_set_pll_dividers(intel_crtc);
6071 if (intel_crtc_has_dp_encoder(intel_crtc->config))
6072 intel_dp_set_m_n(intel_crtc, M1_N1);
6074 intel_set_pipe_timings(intel_crtc);
6075 intel_set_pipe_src_size(intel_crtc);
6077 i9xx_set_pipeconf(intel_crtc);
6079 intel_crtc->active = true;
6081 if (!IS_GEN2(dev_priv))
6082 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6084 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6086 i9xx_enable_pll(intel_crtc, pipe_config);
6088 i9xx_pfit_enable(intel_crtc);
6090 intel_color_load_luts(&pipe_config->base);
6092 if (dev_priv->display.initial_watermarks != NULL)
6093 dev_priv->display.initial_watermarks(old_intel_state,
6094 intel_crtc->config);
6096 intel_update_watermarks(intel_crtc);
6097 intel_enable_pipe(pipe_config);
6099 assert_vblank_disabled(crtc);
6100 drm_crtc_vblank_on(crtc);
6102 intel_encoders_enable(crtc, pipe_config, old_state);
6105 static void i9xx_pfit_disable(struct intel_crtc *crtc)
6107 struct drm_device *dev = crtc->base.dev;
6108 struct drm_i915_private *dev_priv = to_i915(dev);
6110 if (!crtc->config->gmch_pfit.control)
6113 assert_pipe_disabled(dev_priv, crtc->pipe);
6115 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6116 I915_READ(PFIT_CONTROL));
6117 I915_WRITE(PFIT_CONTROL, 0);
6120 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6121 struct drm_atomic_state *old_state)
6123 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6124 struct drm_device *dev = crtc->dev;
6125 struct drm_i915_private *dev_priv = to_i915(dev);
6126 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6127 int pipe = intel_crtc->pipe;
6130 * On gen2 planes are double buffered but the pipe isn't, so we must
6131 * wait for planes to fully turn off before disabling the pipe.
6133 if (IS_GEN2(dev_priv))
6134 intel_wait_for_vblank(dev_priv, pipe);
6136 intel_encoders_disable(crtc, old_crtc_state, old_state);
6138 drm_crtc_vblank_off(crtc);
6139 assert_vblank_disabled(crtc);
6141 intel_disable_pipe(old_crtc_state);
6143 i9xx_pfit_disable(intel_crtc);
6145 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6147 if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) {
6148 if (IS_CHERRYVIEW(dev_priv))
6149 chv_disable_pll(dev_priv, pipe);
6150 else if (IS_VALLEYVIEW(dev_priv))
6151 vlv_disable_pll(dev_priv, pipe);
6153 i9xx_disable_pll(intel_crtc);
6156 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6158 if (!IS_GEN2(dev_priv))
6159 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6161 if (!dev_priv->display.initial_watermarks)
6162 intel_update_watermarks(intel_crtc);
6164 /* clock the pipe down to 640x480@60 to potentially save power */
6165 if (IS_I830(dev_priv))
6166 i830_enable_pipe(dev_priv, pipe);
6169 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6170 struct drm_modeset_acquire_ctx *ctx)
6172 struct intel_encoder *encoder;
6173 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6174 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6175 enum intel_display_power_domain domain;
6176 struct intel_plane *plane;
6178 struct drm_atomic_state *state;
6179 struct intel_crtc_state *crtc_state;
6182 if (!intel_crtc->active)
6185 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6186 const struct intel_plane_state *plane_state =
6187 to_intel_plane_state(plane->base.state);
6189 if (plane_state->base.visible)
6190 intel_plane_disable_noatomic(intel_crtc, plane);
6193 state = drm_atomic_state_alloc(crtc->dev);
6195 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6196 crtc->base.id, crtc->name);
6200 state->acquire_ctx = ctx;
6202 /* Everything's already locked, -EDEADLK can't happen. */
6203 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6204 ret = drm_atomic_add_affected_connectors(state, crtc);
6206 WARN_ON(IS_ERR(crtc_state) || ret);
6208 dev_priv->display.crtc_disable(crtc_state, state);
6210 drm_atomic_state_put(state);
6212 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6213 crtc->base.id, crtc->name);
6215 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6216 crtc->state->active = false;
6217 intel_crtc->active = false;
6218 crtc->enabled = false;
6219 crtc->state->connector_mask = 0;
6220 crtc->state->encoder_mask = 0;
6222 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6223 encoder->base.crtc = NULL;
6225 intel_fbc_disable(intel_crtc);
6226 intel_update_watermarks(intel_crtc);
6227 intel_disable_shared_dpll(intel_crtc);
6229 domains = intel_crtc->enabled_power_domains;
6230 for_each_power_domain(domain, domains)
6231 intel_display_power_put(dev_priv, domain);
6232 intel_crtc->enabled_power_domains = 0;
6234 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6235 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6236 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6240 * turn all crtc's off, but do not adjust state
6241 * This has to be paired with a call to intel_modeset_setup_hw_state.
6243 int intel_display_suspend(struct drm_device *dev)
6245 struct drm_i915_private *dev_priv = to_i915(dev);
6246 struct drm_atomic_state *state;
6249 state = drm_atomic_helper_suspend(dev);
6250 ret = PTR_ERR_OR_ZERO(state);
6252 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6254 dev_priv->modeset_restore_state = state;
6258 void intel_encoder_destroy(struct drm_encoder *encoder)
6260 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6262 drm_encoder_cleanup(encoder);
6263 kfree(intel_encoder);
6266 /* Cross check the actual hw state with our own modeset state tracking (and it's
6267 * internal consistency). */
6268 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6269 struct drm_connector_state *conn_state)
6271 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6273 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6274 connector->base.base.id,
6275 connector->base.name);
6277 if (connector->get_hw_state(connector)) {
6278 struct intel_encoder *encoder = connector->encoder;
6280 I915_STATE_WARN(!crtc_state,
6281 "connector enabled without attached crtc\n");
6286 I915_STATE_WARN(!crtc_state->active,
6287 "connector is active, but attached crtc isn't\n");
6289 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6292 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6293 "atomic encoder doesn't match attached encoder\n");
6295 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6296 "attached encoder crtc differs from connector crtc\n");
6298 I915_STATE_WARN(crtc_state && crtc_state->active,
6299 "attached crtc is active, but connector isn't\n");
6300 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6301 "best encoder set without crtc!\n");
6305 int intel_connector_init(struct intel_connector *connector)
6307 struct intel_digital_connector_state *conn_state;
6310 * Allocate enough memory to hold intel_digital_connector_state,
6311 * This might be a few bytes too many, but for connectors that don't
6312 * need it we'll free the state and allocate a smaller one on the first
6313 * succesful commit anyway.
6315 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
6319 __drm_atomic_helper_connector_reset(&connector->base,
6325 struct intel_connector *intel_connector_alloc(void)
6327 struct intel_connector *connector;
6329 connector = kzalloc(sizeof *connector, GFP_KERNEL);
6333 if (intel_connector_init(connector) < 0) {
6342 * Free the bits allocated by intel_connector_alloc.
6343 * This should only be used after intel_connector_alloc has returned
6344 * successfully, and before drm_connector_init returns successfully.
6345 * Otherwise the destroy callbacks for the connector and the state should
6346 * take care of proper cleanup/free
6348 void intel_connector_free(struct intel_connector *connector)
6350 kfree(to_intel_digital_connector_state(connector->base.state));
6354 /* Simple connector->get_hw_state implementation for encoders that support only
6355 * one connector and no cloning and hence the encoder state determines the state
6356 * of the connector. */
6357 bool intel_connector_get_hw_state(struct intel_connector *connector)
6360 struct intel_encoder *encoder = connector->encoder;
6362 return encoder->get_hw_state(encoder, &pipe);
6365 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6367 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6368 return crtc_state->fdi_lanes;
6373 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6374 struct intel_crtc_state *pipe_config)
6376 struct drm_i915_private *dev_priv = to_i915(dev);
6377 struct drm_atomic_state *state = pipe_config->base.state;
6378 struct intel_crtc *other_crtc;
6379 struct intel_crtc_state *other_crtc_state;
6381 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6382 pipe_name(pipe), pipe_config->fdi_lanes);
6383 if (pipe_config->fdi_lanes > 4) {
6384 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6385 pipe_name(pipe), pipe_config->fdi_lanes);
6389 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6390 if (pipe_config->fdi_lanes > 2) {
6391 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6392 pipe_config->fdi_lanes);
6399 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6402 /* Ivybridge 3 pipe is really complicated */
6407 if (pipe_config->fdi_lanes <= 2)
6410 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6412 intel_atomic_get_crtc_state(state, other_crtc);
6413 if (IS_ERR(other_crtc_state))
6414 return PTR_ERR(other_crtc_state);
6416 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6417 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6418 pipe_name(pipe), pipe_config->fdi_lanes);
6423 if (pipe_config->fdi_lanes > 2) {
6424 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6425 pipe_name(pipe), pipe_config->fdi_lanes);
6429 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6431 intel_atomic_get_crtc_state(state, other_crtc);
6432 if (IS_ERR(other_crtc_state))
6433 return PTR_ERR(other_crtc_state);
6435 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6436 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6446 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6447 struct intel_crtc_state *pipe_config)
6449 struct drm_device *dev = intel_crtc->base.dev;
6450 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6451 int lane, link_bw, fdi_dotclock, ret;
6452 bool needs_recompute = false;
6455 /* FDI is a binary signal running at ~2.7GHz, encoding
6456 * each output octet as 10 bits. The actual frequency
6457 * is stored as a divider into a 100MHz clock, and the
6458 * mode pixel clock is stored in units of 1KHz.
6459 * Hence the bw of each lane in terms of the mode signal
6462 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6464 fdi_dotclock = adjusted_mode->crtc_clock;
6466 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6467 pipe_config->pipe_bpp);
6469 pipe_config->fdi_lanes = lane;
6471 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6472 link_bw, &pipe_config->fdi_m_n, false);
6474 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6475 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6476 pipe_config->pipe_bpp -= 2*3;
6477 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6478 pipe_config->pipe_bpp);
6479 needs_recompute = true;
6480 pipe_config->bw_constrained = true;
6485 if (needs_recompute)
6491 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6493 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6494 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6496 /* IPS only exists on ULT machines and is tied to pipe A. */
6497 if (!hsw_crtc_supports_ips(crtc))
6500 if (!i915_modparams.enable_ips)
6503 if (crtc_state->pipe_bpp > 24)
6507 * We compare against max which means we must take
6508 * the increased cdclk requirement into account when
6509 * calculating the new cdclk.
6511 * Should measure whether using a lower cdclk w/o IPS
6513 if (IS_BROADWELL(dev_priv) &&
6514 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6520 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6522 struct drm_i915_private *dev_priv =
6523 to_i915(crtc_state->base.crtc->dev);
6524 struct intel_atomic_state *intel_state =
6525 to_intel_atomic_state(crtc_state->base.state);
6527 if (!hsw_crtc_state_ips_capable(crtc_state))
6530 if (crtc_state->ips_force_disable)
6533 /* IPS should be fine as long as at least one plane is enabled. */
6534 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6537 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6538 if (IS_BROADWELL(dev_priv) &&
6539 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6545 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6547 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6549 /* GDG double wide on either pipe, otherwise pipe A only */
6550 return INTEL_GEN(dev_priv) < 4 &&
6551 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6554 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6556 uint32_t pixel_rate;
6558 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6561 * We only use IF-ID interlacing. If we ever use
6562 * PF-ID we'll need to adjust the pixel_rate here.
6565 if (pipe_config->pch_pfit.enabled) {
6566 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6567 uint32_t pfit_size = pipe_config->pch_pfit.size;
6569 pipe_w = pipe_config->pipe_src_w;
6570 pipe_h = pipe_config->pipe_src_h;
6572 pfit_w = (pfit_size >> 16) & 0xFFFF;
6573 pfit_h = pfit_size & 0xFFFF;
6574 if (pipe_w < pfit_w)
6576 if (pipe_h < pfit_h)
6579 if (WARN_ON(!pfit_w || !pfit_h))
6582 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6589 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6591 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6593 if (HAS_GMCH_DISPLAY(dev_priv))
6594 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6595 crtc_state->pixel_rate =
6596 crtc_state->base.adjusted_mode.crtc_clock;
6598 crtc_state->pixel_rate =
6599 ilk_pipe_pixel_rate(crtc_state);
6602 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6603 struct intel_crtc_state *pipe_config)
6605 struct drm_device *dev = crtc->base.dev;
6606 struct drm_i915_private *dev_priv = to_i915(dev);
6607 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6608 int clock_limit = dev_priv->max_dotclk_freq;
6610 if (INTEL_GEN(dev_priv) < 4) {
6611 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6614 * Enable double wide mode when the dot clock
6615 * is > 90% of the (display) core speed.
6617 if (intel_crtc_supports_double_wide(crtc) &&
6618 adjusted_mode->crtc_clock > clock_limit) {
6619 clock_limit = dev_priv->max_dotclk_freq;
6620 pipe_config->double_wide = true;
6624 if (adjusted_mode->crtc_clock > clock_limit) {
6625 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6626 adjusted_mode->crtc_clock, clock_limit,
6627 yesno(pipe_config->double_wide));
6631 if (pipe_config->ycbcr420 && pipe_config->base.ctm) {
6633 * There is only one pipe CSC unit per pipe, and we need that
6634 * for output conversion from RGB->YCBCR. So if CTM is already
6635 * applied we can't support YCBCR420 output.
6637 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6642 * Pipe horizontal size must be even in:
6644 * - LVDS dual channel mode
6645 * - Double wide pipe
6647 if (pipe_config->pipe_src_w & 1) {
6648 if (pipe_config->double_wide) {
6649 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6653 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6654 intel_is_dual_link_lvds(dev)) {
6655 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6660 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6661 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6663 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6664 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6667 intel_crtc_compute_pixel_rate(pipe_config);
6669 if (pipe_config->has_pch_encoder)
6670 return ironlake_fdi_compute_config(crtc, pipe_config);
6676 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6678 while (*num > DATA_LINK_M_N_MASK ||
6679 *den > DATA_LINK_M_N_MASK) {
6685 static void compute_m_n(unsigned int m, unsigned int n,
6686 uint32_t *ret_m, uint32_t *ret_n,
6690 * Reduce M/N as much as possible without loss in precision. Several DP
6691 * dongles in particular seem to be fussy about too large *link* M/N
6692 * values. The passed in values are more likely to have the least
6693 * significant bits zero than M after rounding below, so do this first.
6696 while ((m & 1) == 0 && (n & 1) == 0) {
6702 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6703 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6704 intel_reduce_m_n_ratio(ret_m, ret_n);
6708 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6709 int pixel_clock, int link_clock,
6710 struct intel_link_m_n *m_n,
6715 compute_m_n(bits_per_pixel * pixel_clock,
6716 link_clock * nlanes * 8,
6717 &m_n->gmch_m, &m_n->gmch_n,
6720 compute_m_n(pixel_clock, link_clock,
6721 &m_n->link_m, &m_n->link_n,
6725 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6727 if (i915_modparams.panel_use_ssc >= 0)
6728 return i915_modparams.panel_use_ssc != 0;
6729 return dev_priv->vbt.lvds_use_ssc
6730 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6733 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
6735 return (1 << dpll->n) << 16 | dpll->m2;
6738 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6740 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
6743 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
6744 struct intel_crtc_state *crtc_state,
6745 struct dpll *reduced_clock)
6747 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6750 if (IS_PINEVIEW(dev_priv)) {
6751 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
6753 fp2 = pnv_dpll_compute_fp(reduced_clock);
6755 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
6757 fp2 = i9xx_dpll_compute_fp(reduced_clock);
6760 crtc_state->dpll_hw_state.fp0 = fp;
6762 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6764 crtc_state->dpll_hw_state.fp1 = fp2;
6766 crtc_state->dpll_hw_state.fp1 = fp;
6770 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6776 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6777 * and set it to a reasonable value instead.
6779 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6780 reg_val &= 0xffffff00;
6781 reg_val |= 0x00000030;
6782 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6784 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6785 reg_val &= 0x00ffffff;
6786 reg_val |= 0x8c000000;
6787 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6789 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6790 reg_val &= 0xffffff00;
6791 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6793 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6794 reg_val &= 0x00ffffff;
6795 reg_val |= 0xb0000000;
6796 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6799 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
6800 struct intel_link_m_n *m_n)
6802 struct drm_device *dev = crtc->base.dev;
6803 struct drm_i915_private *dev_priv = to_i915(dev);
6804 int pipe = crtc->pipe;
6806 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6807 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6808 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6809 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6812 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
6813 struct intel_link_m_n *m_n,
6814 struct intel_link_m_n *m2_n2)
6816 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6817 int pipe = crtc->pipe;
6818 enum transcoder transcoder = crtc->config->cpu_transcoder;
6820 if (INTEL_GEN(dev_priv) >= 5) {
6821 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6822 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6823 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6824 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
6825 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6826 * for gen < 8) and if DRRS is supported (to make sure the
6827 * registers are not unnecessarily accessed).
6829 if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
6830 INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
6831 I915_WRITE(PIPE_DATA_M2(transcoder),
6832 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6833 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6834 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6835 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6838 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6839 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6840 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6841 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
6845 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
6847 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6850 dp_m_n = &crtc->config->dp_m_n;
6851 dp_m2_n2 = &crtc->config->dp_m2_n2;
6852 } else if (m_n == M2_N2) {
6855 * M2_N2 registers are not supported. Hence m2_n2 divider value
6856 * needs to be programmed into M1_N1.
6858 dp_m_n = &crtc->config->dp_m2_n2;
6860 DRM_ERROR("Unsupported divider value\n");
6864 if (crtc->config->has_pch_encoder)
6865 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
6867 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
6870 static void vlv_compute_dpll(struct intel_crtc *crtc,
6871 struct intel_crtc_state *pipe_config)
6873 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
6874 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6875 if (crtc->pipe != PIPE_A)
6876 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6878 /* DPLL not used with DSI, but still need the rest set up */
6879 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6880 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6881 DPLL_EXT_BUFFER_ENABLE_VLV;
6883 pipe_config->dpll_hw_state.dpll_md =
6884 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6887 static void chv_compute_dpll(struct intel_crtc *crtc,
6888 struct intel_crtc_state *pipe_config)
6890 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
6891 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6892 if (crtc->pipe != PIPE_A)
6893 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6895 /* DPLL not used with DSI, but still need the rest set up */
6896 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6897 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6899 pipe_config->dpll_hw_state.dpll_md =
6900 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6903 static void vlv_prepare_pll(struct intel_crtc *crtc,
6904 const struct intel_crtc_state *pipe_config)
6906 struct drm_device *dev = crtc->base.dev;
6907 struct drm_i915_private *dev_priv = to_i915(dev);
6908 enum pipe pipe = crtc->pipe;
6910 u32 bestn, bestm1, bestm2, bestp1, bestp2;
6911 u32 coreclk, reg_val;
6914 I915_WRITE(DPLL(pipe),
6915 pipe_config->dpll_hw_state.dpll &
6916 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6918 /* No need to actually set up the DPLL with DSI */
6919 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6922 mutex_lock(&dev_priv->sb_lock);
6924 bestn = pipe_config->dpll.n;
6925 bestm1 = pipe_config->dpll.m1;
6926 bestm2 = pipe_config->dpll.m2;
6927 bestp1 = pipe_config->dpll.p1;
6928 bestp2 = pipe_config->dpll.p2;
6930 /* See eDP HDMI DPIO driver vbios notes doc */
6932 /* PLL B needs special handling */
6934 vlv_pllb_recal_opamp(dev_priv, pipe);
6936 /* Set up Tx target for periodic Rcomp update */
6937 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
6939 /* Disable target IRef on PLL */
6940 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
6941 reg_val &= 0x00ffffff;
6942 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
6944 /* Disable fast lock */
6945 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
6947 /* Set idtafcrecal before PLL is enabled */
6948 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6949 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6950 mdiv |= ((bestn << DPIO_N_SHIFT));
6951 mdiv |= (1 << DPIO_K_SHIFT);
6954 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6955 * but we don't support that).
6956 * Note: don't use the DAC post divider as it seems unstable.
6958 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
6959 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6961 mdiv |= DPIO_ENABLE_CALIBRATION;
6962 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6964 /* Set HBR and RBR LPF coefficients */
6965 if (pipe_config->port_clock == 162000 ||
6966 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) ||
6967 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI))
6968 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6971 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6974 if (intel_crtc_has_dp_encoder(pipe_config)) {
6975 /* Use SSC source */
6977 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6980 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6982 } else { /* HDMI or VGA */
6983 /* Use bend source */
6985 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6988 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6992 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
6993 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
6994 if (intel_crtc_has_dp_encoder(crtc->config))
6995 coreclk |= 0x01000000;
6996 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
6998 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
6999 mutex_unlock(&dev_priv->sb_lock);
7002 static void chv_prepare_pll(struct intel_crtc *crtc,
7003 const struct intel_crtc_state *pipe_config)
7005 struct drm_device *dev = crtc->base.dev;
7006 struct drm_i915_private *dev_priv = to_i915(dev);
7007 enum pipe pipe = crtc->pipe;
7008 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7009 u32 loopfilter, tribuf_calcntr;
7010 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7014 /* Enable Refclk and SSC */
7015 I915_WRITE(DPLL(pipe),
7016 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7018 /* No need to actually set up the DPLL with DSI */
7019 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7022 bestn = pipe_config->dpll.n;
7023 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7024 bestm1 = pipe_config->dpll.m1;
7025 bestm2 = pipe_config->dpll.m2 >> 22;
7026 bestp1 = pipe_config->dpll.p1;
7027 bestp2 = pipe_config->dpll.p2;
7028 vco = pipe_config->dpll.vco;
7032 mutex_lock(&dev_priv->sb_lock);
7034 /* p1 and p2 divider */
7035 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7036 5 << DPIO_CHV_S1_DIV_SHIFT |
7037 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7038 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7039 1 << DPIO_CHV_K_DIV_SHIFT);
7041 /* Feedback post-divider - m2 */
7042 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7044 /* Feedback refclk divider - n and m1 */
7045 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7046 DPIO_CHV_M1_DIV_BY_2 |
7047 1 << DPIO_CHV_N_DIV_SHIFT);
7049 /* M2 fraction division */
7050 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7052 /* M2 fraction division enable */
7053 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7054 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7055 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7057 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7058 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7060 /* Program digital lock detect threshold */
7061 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7062 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7063 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7064 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7066 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7067 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7070 if (vco == 5400000) {
7071 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7072 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7073 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7074 tribuf_calcntr = 0x9;
7075 } else if (vco <= 6200000) {
7076 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7077 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7078 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7079 tribuf_calcntr = 0x9;
7080 } else if (vco <= 6480000) {
7081 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7082 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7083 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7084 tribuf_calcntr = 0x8;
7086 /* Not supported. Apply the same limits as in the max case */
7087 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7088 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7089 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7092 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7094 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7095 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7096 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7097 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7100 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7101 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7104 mutex_unlock(&dev_priv->sb_lock);
7108 * vlv_force_pll_on - forcibly enable just the PLL
7109 * @dev_priv: i915 private structure
7110 * @pipe: pipe PLL to enable
7111 * @dpll: PLL configuration
7113 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7114 * in cases where we need the PLL enabled even when @pipe is not going to
7117 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7118 const struct dpll *dpll)
7120 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7121 struct intel_crtc_state *pipe_config;
7123 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7127 pipe_config->base.crtc = &crtc->base;
7128 pipe_config->pixel_multiplier = 1;
7129 pipe_config->dpll = *dpll;
7131 if (IS_CHERRYVIEW(dev_priv)) {
7132 chv_compute_dpll(crtc, pipe_config);
7133 chv_prepare_pll(crtc, pipe_config);
7134 chv_enable_pll(crtc, pipe_config);
7136 vlv_compute_dpll(crtc, pipe_config);
7137 vlv_prepare_pll(crtc, pipe_config);
7138 vlv_enable_pll(crtc, pipe_config);
7147 * vlv_force_pll_off - forcibly disable just the PLL
7148 * @dev_priv: i915 private structure
7149 * @pipe: pipe PLL to disable
7151 * Disable the PLL for @pipe. To be used in cases where we need
7152 * the PLL enabled even when @pipe is not going to be enabled.
7154 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7156 if (IS_CHERRYVIEW(dev_priv))
7157 chv_disable_pll(dev_priv, pipe);
7159 vlv_disable_pll(dev_priv, pipe);
7162 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7163 struct intel_crtc_state *crtc_state,
7164 struct dpll *reduced_clock)
7166 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7168 struct dpll *clock = &crtc_state->dpll;
7170 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7172 dpll = DPLL_VGA_MODE_DIS;
7174 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7175 dpll |= DPLLB_MODE_LVDS;
7177 dpll |= DPLLB_MODE_DAC_SERIAL;
7179 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7180 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7181 dpll |= (crtc_state->pixel_multiplier - 1)
7182 << SDVO_MULTIPLIER_SHIFT_HIRES;
7185 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7186 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7187 dpll |= DPLL_SDVO_HIGH_SPEED;
7189 if (intel_crtc_has_dp_encoder(crtc_state))
7190 dpll |= DPLL_SDVO_HIGH_SPEED;
7192 /* compute bitmask from p1 value */
7193 if (IS_PINEVIEW(dev_priv))
7194 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7196 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7197 if (IS_G4X(dev_priv) && reduced_clock)
7198 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7200 switch (clock->p2) {
7202 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7205 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7208 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7211 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7214 if (INTEL_GEN(dev_priv) >= 4)
7215 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7217 if (crtc_state->sdvo_tv_clock)
7218 dpll |= PLL_REF_INPUT_TVCLKINBC;
7219 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7220 intel_panel_use_ssc(dev_priv))
7221 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7223 dpll |= PLL_REF_INPUT_DREFCLK;
7225 dpll |= DPLL_VCO_ENABLE;
7226 crtc_state->dpll_hw_state.dpll = dpll;
7228 if (INTEL_GEN(dev_priv) >= 4) {
7229 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7230 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7231 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7235 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7236 struct intel_crtc_state *crtc_state,
7237 struct dpll *reduced_clock)
7239 struct drm_device *dev = crtc->base.dev;
7240 struct drm_i915_private *dev_priv = to_i915(dev);
7242 struct dpll *clock = &crtc_state->dpll;
7244 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7246 dpll = DPLL_VGA_MODE_DIS;
7248 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7249 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7252 dpll |= PLL_P1_DIVIDE_BY_TWO;
7254 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7256 dpll |= PLL_P2_DIVIDE_BY_4;
7259 if (!IS_I830(dev_priv) &&
7260 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7261 dpll |= DPLL_DVO_2X_MODE;
7263 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7264 intel_panel_use_ssc(dev_priv))
7265 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7267 dpll |= PLL_REF_INPUT_DREFCLK;
7269 dpll |= DPLL_VCO_ENABLE;
7270 crtc_state->dpll_hw_state.dpll = dpll;
7273 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
7275 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7276 enum pipe pipe = intel_crtc->pipe;
7277 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
7278 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
7279 uint32_t crtc_vtotal, crtc_vblank_end;
7282 /* We need to be careful not to changed the adjusted mode, for otherwise
7283 * the hw state checker will get angry at the mismatch. */
7284 crtc_vtotal = adjusted_mode->crtc_vtotal;
7285 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7287 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7288 /* the chip adds 2 halflines automatically */
7290 crtc_vblank_end -= 1;
7292 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7293 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7295 vsyncshift = adjusted_mode->crtc_hsync_start -
7296 adjusted_mode->crtc_htotal / 2;
7298 vsyncshift += adjusted_mode->crtc_htotal;
7301 if (INTEL_GEN(dev_priv) > 3)
7302 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7304 I915_WRITE(HTOTAL(cpu_transcoder),
7305 (adjusted_mode->crtc_hdisplay - 1) |
7306 ((adjusted_mode->crtc_htotal - 1) << 16));
7307 I915_WRITE(HBLANK(cpu_transcoder),
7308 (adjusted_mode->crtc_hblank_start - 1) |
7309 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7310 I915_WRITE(HSYNC(cpu_transcoder),
7311 (adjusted_mode->crtc_hsync_start - 1) |
7312 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7314 I915_WRITE(VTOTAL(cpu_transcoder),
7315 (adjusted_mode->crtc_vdisplay - 1) |
7316 ((crtc_vtotal - 1) << 16));
7317 I915_WRITE(VBLANK(cpu_transcoder),
7318 (adjusted_mode->crtc_vblank_start - 1) |
7319 ((crtc_vblank_end - 1) << 16));
7320 I915_WRITE(VSYNC(cpu_transcoder),
7321 (adjusted_mode->crtc_vsync_start - 1) |
7322 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7324 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7325 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7326 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7328 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7329 (pipe == PIPE_B || pipe == PIPE_C))
7330 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7334 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc)
7336 struct drm_device *dev = intel_crtc->base.dev;
7337 struct drm_i915_private *dev_priv = to_i915(dev);
7338 enum pipe pipe = intel_crtc->pipe;
7340 /* pipesrc controls the size that is scaled from, which should
7341 * always be the user's requested size.
7343 I915_WRITE(PIPESRC(pipe),
7344 ((intel_crtc->config->pipe_src_w - 1) << 16) |
7345 (intel_crtc->config->pipe_src_h - 1));
7348 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7349 struct intel_crtc_state *pipe_config)
7351 struct drm_device *dev = crtc->base.dev;
7352 struct drm_i915_private *dev_priv = to_i915(dev);
7353 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7356 tmp = I915_READ(HTOTAL(cpu_transcoder));
7357 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7358 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7359 tmp = I915_READ(HBLANK(cpu_transcoder));
7360 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7361 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7362 tmp = I915_READ(HSYNC(cpu_transcoder));
7363 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7364 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7366 tmp = I915_READ(VTOTAL(cpu_transcoder));
7367 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7368 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7369 tmp = I915_READ(VBLANK(cpu_transcoder));
7370 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7371 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7372 tmp = I915_READ(VSYNC(cpu_transcoder));
7373 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7374 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7376 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7377 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7378 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7379 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7383 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7384 struct intel_crtc_state *pipe_config)
7386 struct drm_device *dev = crtc->base.dev;
7387 struct drm_i915_private *dev_priv = to_i915(dev);
7390 tmp = I915_READ(PIPESRC(crtc->pipe));
7391 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7392 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7394 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7395 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7398 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7399 struct intel_crtc_state *pipe_config)
7401 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7402 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7403 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7404 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7406 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7407 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7408 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7409 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7411 mode->flags = pipe_config->base.adjusted_mode.flags;
7412 mode->type = DRM_MODE_TYPE_DRIVER;
7414 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7416 mode->hsync = drm_mode_hsync(mode);
7417 mode->vrefresh = drm_mode_vrefresh(mode);
7418 drm_mode_set_name(mode);
7421 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
7423 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7428 /* we keep both pipes enabled on 830 */
7429 if (IS_I830(dev_priv))
7430 pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
7432 if (intel_crtc->config->double_wide)
7433 pipeconf |= PIPECONF_DOUBLE_WIDE;
7435 /* only g4x and later have fancy bpc/dither controls */
7436 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7437 IS_CHERRYVIEW(dev_priv)) {
7438 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7439 if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
7440 pipeconf |= PIPECONF_DITHER_EN |
7441 PIPECONF_DITHER_TYPE_SP;
7443 switch (intel_crtc->config->pipe_bpp) {
7445 pipeconf |= PIPECONF_6BPC;
7448 pipeconf |= PIPECONF_8BPC;
7451 pipeconf |= PIPECONF_10BPC;
7454 /* Case prevented by intel_choose_pipe_bpp_dither. */
7459 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7460 if (INTEL_GEN(dev_priv) < 4 ||
7461 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7462 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7464 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7466 pipeconf |= PIPECONF_PROGRESSIVE;
7468 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7469 intel_crtc->config->limited_color_range)
7470 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7472 I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
7473 POSTING_READ(PIPECONF(intel_crtc->pipe));
7476 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7477 struct intel_crtc_state *crtc_state)
7479 struct drm_device *dev = crtc->base.dev;
7480 struct drm_i915_private *dev_priv = to_i915(dev);
7481 const struct intel_limit *limit;
7484 memset(&crtc_state->dpll_hw_state, 0,
7485 sizeof(crtc_state->dpll_hw_state));
7487 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7488 if (intel_panel_use_ssc(dev_priv)) {
7489 refclk = dev_priv->vbt.lvds_ssc_freq;
7490 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7493 limit = &intel_limits_i8xx_lvds;
7494 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7495 limit = &intel_limits_i8xx_dvo;
7497 limit = &intel_limits_i8xx_dac;
7500 if (!crtc_state->clock_set &&
7501 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7502 refclk, NULL, &crtc_state->dpll)) {
7503 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7507 i8xx_compute_dpll(crtc, crtc_state, NULL);
7512 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7513 struct intel_crtc_state *crtc_state)
7515 struct drm_device *dev = crtc->base.dev;
7516 struct drm_i915_private *dev_priv = to_i915(dev);
7517 const struct intel_limit *limit;
7520 memset(&crtc_state->dpll_hw_state, 0,
7521 sizeof(crtc_state->dpll_hw_state));
7523 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7524 if (intel_panel_use_ssc(dev_priv)) {
7525 refclk = dev_priv->vbt.lvds_ssc_freq;
7526 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7529 if (intel_is_dual_link_lvds(dev))
7530 limit = &intel_limits_g4x_dual_channel_lvds;
7532 limit = &intel_limits_g4x_single_channel_lvds;
7533 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7534 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7535 limit = &intel_limits_g4x_hdmi;
7536 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7537 limit = &intel_limits_g4x_sdvo;
7539 /* The option is for other outputs */
7540 limit = &intel_limits_i9xx_sdvo;
7543 if (!crtc_state->clock_set &&
7544 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7545 refclk, NULL, &crtc_state->dpll)) {
7546 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7550 i9xx_compute_dpll(crtc, crtc_state, NULL);
7555 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7556 struct intel_crtc_state *crtc_state)
7558 struct drm_device *dev = crtc->base.dev;
7559 struct drm_i915_private *dev_priv = to_i915(dev);
7560 const struct intel_limit *limit;
7563 memset(&crtc_state->dpll_hw_state, 0,
7564 sizeof(crtc_state->dpll_hw_state));
7566 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7567 if (intel_panel_use_ssc(dev_priv)) {
7568 refclk = dev_priv->vbt.lvds_ssc_freq;
7569 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7572 limit = &intel_limits_pineview_lvds;
7574 limit = &intel_limits_pineview_sdvo;
7577 if (!crtc_state->clock_set &&
7578 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7579 refclk, NULL, &crtc_state->dpll)) {
7580 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7584 i9xx_compute_dpll(crtc, crtc_state, NULL);
7589 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7590 struct intel_crtc_state *crtc_state)
7592 struct drm_device *dev = crtc->base.dev;
7593 struct drm_i915_private *dev_priv = to_i915(dev);
7594 const struct intel_limit *limit;
7597 memset(&crtc_state->dpll_hw_state, 0,
7598 sizeof(crtc_state->dpll_hw_state));
7600 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7601 if (intel_panel_use_ssc(dev_priv)) {
7602 refclk = dev_priv->vbt.lvds_ssc_freq;
7603 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7606 limit = &intel_limits_i9xx_lvds;
7608 limit = &intel_limits_i9xx_sdvo;
7611 if (!crtc_state->clock_set &&
7612 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7613 refclk, NULL, &crtc_state->dpll)) {
7614 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7618 i9xx_compute_dpll(crtc, crtc_state, NULL);
7623 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7624 struct intel_crtc_state *crtc_state)
7626 int refclk = 100000;
7627 const struct intel_limit *limit = &intel_limits_chv;
7629 memset(&crtc_state->dpll_hw_state, 0,
7630 sizeof(crtc_state->dpll_hw_state));
7632 if (!crtc_state->clock_set &&
7633 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7634 refclk, NULL, &crtc_state->dpll)) {
7635 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7639 chv_compute_dpll(crtc, crtc_state);
7644 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7645 struct intel_crtc_state *crtc_state)
7647 int refclk = 100000;
7648 const struct intel_limit *limit = &intel_limits_vlv;
7650 memset(&crtc_state->dpll_hw_state, 0,
7651 sizeof(crtc_state->dpll_hw_state));
7653 if (!crtc_state->clock_set &&
7654 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7655 refclk, NULL, &crtc_state->dpll)) {
7656 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7660 vlv_compute_dpll(crtc, crtc_state);
7665 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7666 struct intel_crtc_state *pipe_config)
7668 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7671 if (INTEL_GEN(dev_priv) <= 3 &&
7672 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7675 tmp = I915_READ(PFIT_CONTROL);
7676 if (!(tmp & PFIT_ENABLE))
7679 /* Check whether the pfit is attached to our pipe. */
7680 if (INTEL_GEN(dev_priv) < 4) {
7681 if (crtc->pipe != PIPE_B)
7684 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7688 pipe_config->gmch_pfit.control = tmp;
7689 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7692 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7693 struct intel_crtc_state *pipe_config)
7695 struct drm_device *dev = crtc->base.dev;
7696 struct drm_i915_private *dev_priv = to_i915(dev);
7697 int pipe = pipe_config->cpu_transcoder;
7700 int refclk = 100000;
7702 /* In case of DSI, DPLL will not be used */
7703 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7706 mutex_lock(&dev_priv->sb_lock);
7707 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7708 mutex_unlock(&dev_priv->sb_lock);
7710 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7711 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7712 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7713 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7714 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7716 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7720 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7721 struct intel_initial_plane_config *plane_config)
7723 struct drm_device *dev = crtc->base.dev;
7724 struct drm_i915_private *dev_priv = to_i915(dev);
7725 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7726 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7728 u32 val, base, offset;
7729 int fourcc, pixel_format;
7730 unsigned int aligned_height;
7731 struct drm_framebuffer *fb;
7732 struct intel_framebuffer *intel_fb;
7734 if (!plane->get_hw_state(plane, &pipe))
7737 WARN_ON(pipe != crtc->pipe);
7739 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7741 DRM_DEBUG_KMS("failed to alloc fb\n");
7745 fb = &intel_fb->base;
7749 val = I915_READ(DSPCNTR(i9xx_plane));
7751 if (INTEL_GEN(dev_priv) >= 4) {
7752 if (val & DISPPLANE_TILED) {
7753 plane_config->tiling = I915_TILING_X;
7754 fb->modifier = I915_FORMAT_MOD_X_TILED;
7758 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7759 fourcc = i9xx_format_to_fourcc(pixel_format);
7760 fb->format = drm_format_info(fourcc);
7762 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7763 offset = I915_READ(DSPOFFSET(i9xx_plane));
7764 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7765 } else if (INTEL_GEN(dev_priv) >= 4) {
7766 if (plane_config->tiling)
7767 offset = I915_READ(DSPTILEOFF(i9xx_plane));
7769 offset = I915_READ(DSPLINOFF(i9xx_plane));
7770 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7772 base = I915_READ(DSPADDR(i9xx_plane));
7774 plane_config->base = base;
7776 val = I915_READ(PIPESRC(pipe));
7777 fb->width = ((val >> 16) & 0xfff) + 1;
7778 fb->height = ((val >> 0) & 0xfff) + 1;
7780 val = I915_READ(DSPSTRIDE(i9xx_plane));
7781 fb->pitches[0] = val & 0xffffffc0;
7783 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7785 plane_config->size = fb->pitches[0] * aligned_height;
7787 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7788 crtc->base.name, plane->base.name, fb->width, fb->height,
7789 fb->format->cpp[0] * 8, base, fb->pitches[0],
7790 plane_config->size);
7792 plane_config->fb = intel_fb;
7795 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7796 struct intel_crtc_state *pipe_config)
7798 struct drm_device *dev = crtc->base.dev;
7799 struct drm_i915_private *dev_priv = to_i915(dev);
7800 int pipe = pipe_config->cpu_transcoder;
7801 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7803 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7804 int refclk = 100000;
7806 /* In case of DSI, DPLL will not be used */
7807 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7810 mutex_lock(&dev_priv->sb_lock);
7811 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7812 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7813 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7814 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7815 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7816 mutex_unlock(&dev_priv->sb_lock);
7818 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7819 clock.m2 = (pll_dw0 & 0xff) << 22;
7820 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7821 clock.m2 |= pll_dw2 & 0x3fffff;
7822 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7823 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7824 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7826 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7829 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7830 struct intel_crtc_state *pipe_config)
7832 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7833 enum intel_display_power_domain power_domain;
7837 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7838 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7841 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7842 pipe_config->shared_dpll = NULL;
7846 tmp = I915_READ(PIPECONF(crtc->pipe));
7847 if (!(tmp & PIPECONF_ENABLE))
7850 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7851 IS_CHERRYVIEW(dev_priv)) {
7852 switch (tmp & PIPECONF_BPC_MASK) {
7854 pipe_config->pipe_bpp = 18;
7857 pipe_config->pipe_bpp = 24;
7859 case PIPECONF_10BPC:
7860 pipe_config->pipe_bpp = 30;
7867 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7868 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7869 pipe_config->limited_color_range = true;
7871 if (INTEL_GEN(dev_priv) < 4)
7872 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7874 intel_get_pipe_timings(crtc, pipe_config);
7875 intel_get_pipe_src_size(crtc, pipe_config);
7877 i9xx_get_pfit_config(crtc, pipe_config);
7879 if (INTEL_GEN(dev_priv) >= 4) {
7880 /* No way to read it out on pipes B and C */
7881 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
7882 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7884 tmp = I915_READ(DPLL_MD(crtc->pipe));
7885 pipe_config->pixel_multiplier =
7886 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7887 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
7888 pipe_config->dpll_hw_state.dpll_md = tmp;
7889 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7890 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7891 tmp = I915_READ(DPLL(crtc->pipe));
7892 pipe_config->pixel_multiplier =
7893 ((tmp & SDVO_MULTIPLIER_MASK)
7894 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7896 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7897 * port and will be fixed up in the encoder->get_config
7899 pipe_config->pixel_multiplier = 1;
7901 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
7902 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
7904 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7905 * on 830. Filter it out here so that we don't
7906 * report errors due to that.
7908 if (IS_I830(dev_priv))
7909 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
7911 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
7912 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
7914 /* Mask out read-only status bits. */
7915 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7916 DPLL_PORTC_READY_MASK |
7917 DPLL_PORTB_READY_MASK);
7920 if (IS_CHERRYVIEW(dev_priv))
7921 chv_crtc_clock_get(crtc, pipe_config);
7922 else if (IS_VALLEYVIEW(dev_priv))
7923 vlv_crtc_clock_get(crtc, pipe_config);
7925 i9xx_crtc_clock_get(crtc, pipe_config);
7928 * Normally the dotclock is filled in by the encoder .get_config()
7929 * but in case the pipe is enabled w/o any ports we need a sane
7932 pipe_config->base.adjusted_mode.crtc_clock =
7933 pipe_config->port_clock / pipe_config->pixel_multiplier;
7938 intel_display_power_put(dev_priv, power_domain);
7943 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
7945 struct intel_encoder *encoder;
7948 bool has_lvds = false;
7949 bool has_cpu_edp = false;
7950 bool has_panel = false;
7951 bool has_ck505 = false;
7952 bool can_ssc = false;
7953 bool using_ssc_source = false;
7955 /* We need to take the global config into account */
7956 for_each_intel_encoder(&dev_priv->drm, encoder) {
7957 switch (encoder->type) {
7958 case INTEL_OUTPUT_LVDS:
7962 case INTEL_OUTPUT_EDP:
7964 if (encoder->port == PORT_A)
7972 if (HAS_PCH_IBX(dev_priv)) {
7973 has_ck505 = dev_priv->vbt.display_clock_mode;
7974 can_ssc = has_ck505;
7980 /* Check if any DPLLs are using the SSC source */
7981 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
7982 u32 temp = I915_READ(PCH_DPLL(i));
7984 if (!(temp & DPLL_VCO_ENABLE))
7987 if ((temp & PLL_REF_INPUT_MASK) ==
7988 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
7989 using_ssc_source = true;
7994 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7995 has_panel, has_lvds, has_ck505, using_ssc_source);
7997 /* Ironlake: try to setup display ref clock before DPLL
7998 * enabling. This is only under driver's control after
7999 * PCH B stepping, previous chipset stepping should be
8000 * ignoring this setting.
8002 val = I915_READ(PCH_DREF_CONTROL);
8004 /* As we must carefully and slowly disable/enable each source in turn,
8005 * compute the final state we want first and check if we need to
8006 * make any changes at all.
8009 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8011 final |= DREF_NONSPREAD_CK505_ENABLE;
8013 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8015 final &= ~DREF_SSC_SOURCE_MASK;
8016 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8017 final &= ~DREF_SSC1_ENABLE;
8020 final |= DREF_SSC_SOURCE_ENABLE;
8022 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8023 final |= DREF_SSC1_ENABLE;
8026 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8027 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8029 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8031 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8032 } else if (using_ssc_source) {
8033 final |= DREF_SSC_SOURCE_ENABLE;
8034 final |= DREF_SSC1_ENABLE;
8040 /* Always enable nonspread source */
8041 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8044 val |= DREF_NONSPREAD_CK505_ENABLE;
8046 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8049 val &= ~DREF_SSC_SOURCE_MASK;
8050 val |= DREF_SSC_SOURCE_ENABLE;
8052 /* SSC must be turned on before enabling the CPU output */
8053 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8054 DRM_DEBUG_KMS("Using SSC on panel\n");
8055 val |= DREF_SSC1_ENABLE;
8057 val &= ~DREF_SSC1_ENABLE;
8059 /* Get SSC going before enabling the outputs */
8060 I915_WRITE(PCH_DREF_CONTROL, val);
8061 POSTING_READ(PCH_DREF_CONTROL);
8064 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8066 /* Enable CPU source on CPU attached eDP */
8068 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8069 DRM_DEBUG_KMS("Using SSC on eDP\n");
8070 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8072 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8074 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8076 I915_WRITE(PCH_DREF_CONTROL, val);
8077 POSTING_READ(PCH_DREF_CONTROL);
8080 DRM_DEBUG_KMS("Disabling CPU source output\n");
8082 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8084 /* Turn off CPU output */
8085 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8087 I915_WRITE(PCH_DREF_CONTROL, val);
8088 POSTING_READ(PCH_DREF_CONTROL);
8091 if (!using_ssc_source) {
8092 DRM_DEBUG_KMS("Disabling SSC source\n");
8094 /* Turn off the SSC source */
8095 val &= ~DREF_SSC_SOURCE_MASK;
8096 val |= DREF_SSC_SOURCE_DISABLE;
8099 val &= ~DREF_SSC1_ENABLE;
8101 I915_WRITE(PCH_DREF_CONTROL, val);
8102 POSTING_READ(PCH_DREF_CONTROL);
8107 BUG_ON(val != final);
8110 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8114 tmp = I915_READ(SOUTH_CHICKEN2);
8115 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8116 I915_WRITE(SOUTH_CHICKEN2, tmp);
8118 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8119 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8120 DRM_ERROR("FDI mPHY reset assert timeout\n");
8122 tmp = I915_READ(SOUTH_CHICKEN2);
8123 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8124 I915_WRITE(SOUTH_CHICKEN2, tmp);
8126 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8127 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8128 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8131 /* WaMPhyProgramming:hsw */
8132 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8136 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8137 tmp &= ~(0xFF << 24);
8138 tmp |= (0x12 << 24);
8139 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8141 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8143 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8145 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8147 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8149 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8150 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8151 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8153 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8154 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8155 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8157 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8160 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8162 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8165 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8167 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8170 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8172 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8175 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8177 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8178 tmp &= ~(0xFF << 16);
8179 tmp |= (0x1C << 16);
8180 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8182 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8183 tmp &= ~(0xFF << 16);
8184 tmp |= (0x1C << 16);
8185 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8187 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8189 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8191 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8193 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8195 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8196 tmp &= ~(0xF << 28);
8198 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8200 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8201 tmp &= ~(0xF << 28);
8203 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8206 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8207 * Programming" based on the parameters passed:
8208 * - Sequence to enable CLKOUT_DP
8209 * - Sequence to enable CLKOUT_DP without spread
8210 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8212 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8213 bool with_spread, bool with_fdi)
8217 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8219 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8220 with_fdi, "LP PCH doesn't have FDI\n"))
8223 mutex_lock(&dev_priv->sb_lock);
8225 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8226 tmp &= ~SBI_SSCCTL_DISABLE;
8227 tmp |= SBI_SSCCTL_PATHALT;
8228 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8233 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8234 tmp &= ~SBI_SSCCTL_PATHALT;
8235 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8238 lpt_reset_fdi_mphy(dev_priv);
8239 lpt_program_fdi_mphy(dev_priv);
8243 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8244 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8245 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8246 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8248 mutex_unlock(&dev_priv->sb_lock);
8251 /* Sequence to disable CLKOUT_DP */
8252 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8256 mutex_lock(&dev_priv->sb_lock);
8258 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8259 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8260 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8261 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8263 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8264 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8265 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8266 tmp |= SBI_SSCCTL_PATHALT;
8267 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8270 tmp |= SBI_SSCCTL_DISABLE;
8271 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8274 mutex_unlock(&dev_priv->sb_lock);
8277 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8279 static const uint16_t sscdivintphase[] = {
8280 [BEND_IDX( 50)] = 0x3B23,
8281 [BEND_IDX( 45)] = 0x3B23,
8282 [BEND_IDX( 40)] = 0x3C23,
8283 [BEND_IDX( 35)] = 0x3C23,
8284 [BEND_IDX( 30)] = 0x3D23,
8285 [BEND_IDX( 25)] = 0x3D23,
8286 [BEND_IDX( 20)] = 0x3E23,
8287 [BEND_IDX( 15)] = 0x3E23,
8288 [BEND_IDX( 10)] = 0x3F23,
8289 [BEND_IDX( 5)] = 0x3F23,
8290 [BEND_IDX( 0)] = 0x0025,
8291 [BEND_IDX( -5)] = 0x0025,
8292 [BEND_IDX(-10)] = 0x0125,
8293 [BEND_IDX(-15)] = 0x0125,
8294 [BEND_IDX(-20)] = 0x0225,
8295 [BEND_IDX(-25)] = 0x0225,
8296 [BEND_IDX(-30)] = 0x0325,
8297 [BEND_IDX(-35)] = 0x0325,
8298 [BEND_IDX(-40)] = 0x0425,
8299 [BEND_IDX(-45)] = 0x0425,
8300 [BEND_IDX(-50)] = 0x0525,
8305 * steps -50 to 50 inclusive, in steps of 5
8306 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8307 * change in clock period = -(steps / 10) * 5.787 ps
8309 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8312 int idx = BEND_IDX(steps);
8314 if (WARN_ON(steps % 5 != 0))
8317 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8320 mutex_lock(&dev_priv->sb_lock);
8322 if (steps % 10 != 0)
8326 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8328 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8330 tmp |= sscdivintphase[idx];
8331 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8333 mutex_unlock(&dev_priv->sb_lock);
8338 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8340 struct intel_encoder *encoder;
8341 bool has_vga = false;
8343 for_each_intel_encoder(&dev_priv->drm, encoder) {
8344 switch (encoder->type) {
8345 case INTEL_OUTPUT_ANALOG:
8354 lpt_bend_clkout_dp(dev_priv, 0);
8355 lpt_enable_clkout_dp(dev_priv, true, true);
8357 lpt_disable_clkout_dp(dev_priv);
8362 * Initialize reference clocks when the driver loads
8364 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8366 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8367 ironlake_init_pch_refclk(dev_priv);
8368 else if (HAS_PCH_LPT(dev_priv))
8369 lpt_init_pch_refclk(dev_priv);
8372 static void ironlake_set_pipeconf(struct drm_crtc *crtc)
8374 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8375 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8376 int pipe = intel_crtc->pipe;
8381 switch (intel_crtc->config->pipe_bpp) {
8383 val |= PIPECONF_6BPC;
8386 val |= PIPECONF_8BPC;
8389 val |= PIPECONF_10BPC;
8392 val |= PIPECONF_12BPC;
8395 /* Case prevented by intel_choose_pipe_bpp_dither. */
8399 if (intel_crtc->config->dither)
8400 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8402 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8403 val |= PIPECONF_INTERLACED_ILK;
8405 val |= PIPECONF_PROGRESSIVE;
8407 if (intel_crtc->config->limited_color_range)
8408 val |= PIPECONF_COLOR_RANGE_SELECT;
8410 I915_WRITE(PIPECONF(pipe), val);
8411 POSTING_READ(PIPECONF(pipe));
8414 static void haswell_set_pipeconf(struct drm_crtc *crtc)
8416 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8417 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8418 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
8421 if (IS_HASWELL(dev_priv) && intel_crtc->config->dither)
8422 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8424 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8425 val |= PIPECONF_INTERLACED_ILK;
8427 val |= PIPECONF_PROGRESSIVE;
8429 I915_WRITE(PIPECONF(cpu_transcoder), val);
8430 POSTING_READ(PIPECONF(cpu_transcoder));
8433 static void haswell_set_pipemisc(struct drm_crtc *crtc)
8435 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8436 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8437 struct intel_crtc_state *config = intel_crtc->config;
8439 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8442 switch (intel_crtc->config->pipe_bpp) {
8444 val |= PIPEMISC_DITHER_6_BPC;
8447 val |= PIPEMISC_DITHER_8_BPC;
8450 val |= PIPEMISC_DITHER_10_BPC;
8453 val |= PIPEMISC_DITHER_12_BPC;
8456 /* Case prevented by pipe_config_set_bpp. */
8460 if (intel_crtc->config->dither)
8461 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8463 if (config->ycbcr420) {
8464 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV |
8465 PIPEMISC_YUV420_ENABLE |
8466 PIPEMISC_YUV420_MODE_FULL_BLEND;
8469 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8473 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8476 * Account for spread spectrum to avoid
8477 * oversubscribing the link. Max center spread
8478 * is 2.5%; use 5% for safety's sake.
8480 u32 bps = target_clock * bpp * 21 / 20;
8481 return DIV_ROUND_UP(bps, link_bw * 8);
8484 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8486 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8489 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8490 struct intel_crtc_state *crtc_state,
8491 struct dpll *reduced_clock)
8493 struct drm_crtc *crtc = &intel_crtc->base;
8494 struct drm_device *dev = crtc->dev;
8495 struct drm_i915_private *dev_priv = to_i915(dev);
8499 /* Enable autotuning of the PLL clock (if permissible) */
8501 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8502 if ((intel_panel_use_ssc(dev_priv) &&
8503 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8504 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8506 } else if (crtc_state->sdvo_tv_clock)
8509 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8511 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8514 if (reduced_clock) {
8515 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8517 if (reduced_clock->m < factor * reduced_clock->n)
8525 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8526 dpll |= DPLLB_MODE_LVDS;
8528 dpll |= DPLLB_MODE_DAC_SERIAL;
8530 dpll |= (crtc_state->pixel_multiplier - 1)
8531 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8533 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8534 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8535 dpll |= DPLL_SDVO_HIGH_SPEED;
8537 if (intel_crtc_has_dp_encoder(crtc_state))
8538 dpll |= DPLL_SDVO_HIGH_SPEED;
8541 * The high speed IO clock is only really required for
8542 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8543 * possible to share the DPLL between CRT and HDMI. Enabling
8544 * the clock needlessly does no real harm, except use up a
8545 * bit of power potentially.
8547 * We'll limit this to IVB with 3 pipes, since it has only two
8548 * DPLLs and so DPLL sharing is the only way to get three pipes
8549 * driving PCH ports at the same time. On SNB we could do this,
8550 * and potentially avoid enabling the second DPLL, but it's not
8551 * clear if it''s a win or loss power wise. No point in doing
8552 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8554 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8555 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8556 dpll |= DPLL_SDVO_HIGH_SPEED;
8558 /* compute bitmask from p1 value */
8559 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8561 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8563 switch (crtc_state->dpll.p2) {
8565 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8568 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8571 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8574 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8578 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8579 intel_panel_use_ssc(dev_priv))
8580 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8582 dpll |= PLL_REF_INPUT_DREFCLK;
8584 dpll |= DPLL_VCO_ENABLE;
8586 crtc_state->dpll_hw_state.dpll = dpll;
8587 crtc_state->dpll_hw_state.fp0 = fp;
8588 crtc_state->dpll_hw_state.fp1 = fp2;
8591 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8592 struct intel_crtc_state *crtc_state)
8594 struct drm_device *dev = crtc->base.dev;
8595 struct drm_i915_private *dev_priv = to_i915(dev);
8596 const struct intel_limit *limit;
8597 int refclk = 120000;
8599 memset(&crtc_state->dpll_hw_state, 0,
8600 sizeof(crtc_state->dpll_hw_state));
8602 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8603 if (!crtc_state->has_pch_encoder)
8606 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8607 if (intel_panel_use_ssc(dev_priv)) {
8608 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8609 dev_priv->vbt.lvds_ssc_freq);
8610 refclk = dev_priv->vbt.lvds_ssc_freq;
8613 if (intel_is_dual_link_lvds(dev)) {
8614 if (refclk == 100000)
8615 limit = &intel_limits_ironlake_dual_lvds_100m;
8617 limit = &intel_limits_ironlake_dual_lvds;
8619 if (refclk == 100000)
8620 limit = &intel_limits_ironlake_single_lvds_100m;
8622 limit = &intel_limits_ironlake_single_lvds;
8625 limit = &intel_limits_ironlake_dac;
8628 if (!crtc_state->clock_set &&
8629 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8630 refclk, NULL, &crtc_state->dpll)) {
8631 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8635 ironlake_compute_dpll(crtc, crtc_state, NULL);
8637 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8638 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8639 pipe_name(crtc->pipe));
8646 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8647 struct intel_link_m_n *m_n)
8649 struct drm_device *dev = crtc->base.dev;
8650 struct drm_i915_private *dev_priv = to_i915(dev);
8651 enum pipe pipe = crtc->pipe;
8653 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8654 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8655 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8657 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8658 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8659 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8662 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8663 enum transcoder transcoder,
8664 struct intel_link_m_n *m_n,
8665 struct intel_link_m_n *m2_n2)
8667 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8668 enum pipe pipe = crtc->pipe;
8670 if (INTEL_GEN(dev_priv) >= 5) {
8671 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8672 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8673 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8675 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8676 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8677 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8678 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8679 * gen < 8) and if DRRS is supported (to make sure the
8680 * registers are not unnecessarily read).
8682 if (m2_n2 && INTEL_GEN(dev_priv) < 8 &&
8683 crtc->config->has_drrs) {
8684 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8685 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8686 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8688 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8689 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8690 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8693 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8694 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8695 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8697 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8698 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8699 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8703 void intel_dp_get_m_n(struct intel_crtc *crtc,
8704 struct intel_crtc_state *pipe_config)
8706 if (pipe_config->has_pch_encoder)
8707 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8709 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8710 &pipe_config->dp_m_n,
8711 &pipe_config->dp_m2_n2);
8714 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8715 struct intel_crtc_state *pipe_config)
8717 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8718 &pipe_config->fdi_m_n, NULL);
8721 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8722 struct intel_crtc_state *pipe_config)
8724 struct drm_device *dev = crtc->base.dev;
8725 struct drm_i915_private *dev_priv = to_i915(dev);
8726 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8727 uint32_t ps_ctrl = 0;
8731 /* find scaler attached to this pipe */
8732 for (i = 0; i < crtc->num_scalers; i++) {
8733 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8734 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8736 pipe_config->pch_pfit.enabled = true;
8737 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8738 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8743 scaler_state->scaler_id = id;
8745 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8747 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8752 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8753 struct intel_initial_plane_config *plane_config)
8755 struct drm_device *dev = crtc->base.dev;
8756 struct drm_i915_private *dev_priv = to_i915(dev);
8757 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8758 enum plane_id plane_id = plane->id;
8760 u32 val, base, offset, stride_mult, tiling, alpha;
8761 int fourcc, pixel_format;
8762 unsigned int aligned_height;
8763 struct drm_framebuffer *fb;
8764 struct intel_framebuffer *intel_fb;
8766 if (!plane->get_hw_state(plane, &pipe))
8769 WARN_ON(pipe != crtc->pipe);
8771 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8773 DRM_DEBUG_KMS("failed to alloc fb\n");
8777 fb = &intel_fb->base;
8781 val = I915_READ(PLANE_CTL(pipe, plane_id));
8783 if (INTEL_GEN(dev_priv) >= 11)
8784 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8786 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8788 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8789 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
8790 alpha &= PLANE_COLOR_ALPHA_MASK;
8792 alpha = val & PLANE_CTL_ALPHA_MASK;
8795 fourcc = skl_format_to_fourcc(pixel_format,
8796 val & PLANE_CTL_ORDER_RGBX, alpha);
8797 fb->format = drm_format_info(fourcc);
8799 tiling = val & PLANE_CTL_TILED_MASK;
8801 case PLANE_CTL_TILED_LINEAR:
8802 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8804 case PLANE_CTL_TILED_X:
8805 plane_config->tiling = I915_TILING_X;
8806 fb->modifier = I915_FORMAT_MOD_X_TILED;
8808 case PLANE_CTL_TILED_Y:
8809 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8810 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8812 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8814 case PLANE_CTL_TILED_YF:
8815 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8816 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8818 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8821 MISSING_CASE(tiling);
8825 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8826 plane_config->base = base;
8828 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
8830 val = I915_READ(PLANE_SIZE(pipe, plane_id));
8831 fb->height = ((val >> 16) & 0xfff) + 1;
8832 fb->width = ((val >> 0) & 0x1fff) + 1;
8834 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
8835 stride_mult = intel_fb_stride_alignment(fb, 0);
8836 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8838 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8840 plane_config->size = fb->pitches[0] * aligned_height;
8842 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8843 crtc->base.name, plane->base.name, fb->width, fb->height,
8844 fb->format->cpp[0] * 8, base, fb->pitches[0],
8845 plane_config->size);
8847 plane_config->fb = intel_fb;
8854 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
8855 struct intel_crtc_state *pipe_config)
8857 struct drm_device *dev = crtc->base.dev;
8858 struct drm_i915_private *dev_priv = to_i915(dev);
8861 tmp = I915_READ(PF_CTL(crtc->pipe));
8863 if (tmp & PF_ENABLE) {
8864 pipe_config->pch_pfit.enabled = true;
8865 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8866 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
8868 /* We currently do not free assignements of panel fitters on
8869 * ivb/hsw (since we don't use the higher upscaling modes which
8870 * differentiates them) so just WARN about this case for now. */
8871 if (IS_GEN7(dev_priv)) {
8872 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
8873 PF_PIPE_SEL_IVB(crtc->pipe));
8878 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
8879 struct intel_crtc_state *pipe_config)
8881 struct drm_device *dev = crtc->base.dev;
8882 struct drm_i915_private *dev_priv = to_i915(dev);
8883 enum intel_display_power_domain power_domain;
8887 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8888 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
8891 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8892 pipe_config->shared_dpll = NULL;
8895 tmp = I915_READ(PIPECONF(crtc->pipe));
8896 if (!(tmp & PIPECONF_ENABLE))
8899 switch (tmp & PIPECONF_BPC_MASK) {
8901 pipe_config->pipe_bpp = 18;
8904 pipe_config->pipe_bpp = 24;
8906 case PIPECONF_10BPC:
8907 pipe_config->pipe_bpp = 30;
8909 case PIPECONF_12BPC:
8910 pipe_config->pipe_bpp = 36;
8916 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8917 pipe_config->limited_color_range = true;
8919 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
8920 struct intel_shared_dpll *pll;
8921 enum intel_dpll_id pll_id;
8923 pipe_config->has_pch_encoder = true;
8925 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
8926 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8927 FDI_DP_PORT_WIDTH_SHIFT) + 1;
8929 ironlake_get_fdi_m_n_config(crtc, pipe_config);
8931 if (HAS_PCH_IBX(dev_priv)) {
8933 * The pipe->pch transcoder and pch transcoder->pll
8936 pll_id = (enum intel_dpll_id) crtc->pipe;
8938 tmp = I915_READ(PCH_DPLL_SEL);
8939 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
8940 pll_id = DPLL_ID_PCH_PLL_B;
8942 pll_id= DPLL_ID_PCH_PLL_A;
8945 pipe_config->shared_dpll =
8946 intel_get_shared_dpll_by_id(dev_priv, pll_id);
8947 pll = pipe_config->shared_dpll;
8949 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
8950 &pipe_config->dpll_hw_state));
8952 tmp = pipe_config->dpll_hw_state.dpll;
8953 pipe_config->pixel_multiplier =
8954 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
8955 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
8957 ironlake_pch_clock_get(crtc, pipe_config);
8959 pipe_config->pixel_multiplier = 1;
8962 intel_get_pipe_timings(crtc, pipe_config);
8963 intel_get_pipe_src_size(crtc, pipe_config);
8965 ironlake_get_pfit_config(crtc, pipe_config);
8970 intel_display_power_put(dev_priv, power_domain);
8975 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
8977 struct drm_device *dev = &dev_priv->drm;
8978 struct intel_crtc *crtc;
8980 for_each_intel_crtc(dev, crtc)
8981 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
8982 pipe_name(crtc->pipe));
8984 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
8985 "Display power well on\n");
8986 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
8987 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
8988 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
8989 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
8990 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
8991 "CPU PWM1 enabled\n");
8992 if (IS_HASWELL(dev_priv))
8993 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
8994 "CPU PWM2 enabled\n");
8995 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
8996 "PCH PWM1 enabled\n");
8997 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
8998 "Utility pin enabled\n");
8999 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
9002 * In theory we can still leave IRQs enabled, as long as only the HPD
9003 * interrupts remain enabled. We used to check for that, but since it's
9004 * gen-specific and since we only disable LCPLL after we fully disable
9005 * the interrupts, the check below should be enough.
9007 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
9010 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9012 if (IS_HASWELL(dev_priv))
9013 return I915_READ(D_COMP_HSW);
9015 return I915_READ(D_COMP_BDW);
9018 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9020 if (IS_HASWELL(dev_priv)) {
9021 mutex_lock(&dev_priv->pcu_lock);
9022 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9024 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
9025 mutex_unlock(&dev_priv->pcu_lock);
9027 I915_WRITE(D_COMP_BDW, val);
9028 POSTING_READ(D_COMP_BDW);
9033 * This function implements pieces of two sequences from BSpec:
9034 * - Sequence for display software to disable LCPLL
9035 * - Sequence for display software to allow package C8+
9036 * The steps implemented here are just the steps that actually touch the LCPLL
9037 * register. Callers should take care of disabling all the display engine
9038 * functions, doing the mode unset, fixing interrupts, etc.
9040 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9041 bool switch_to_fclk, bool allow_power_down)
9045 assert_can_disable_lcpll(dev_priv);
9047 val = I915_READ(LCPLL_CTL);
9049 if (switch_to_fclk) {
9050 val |= LCPLL_CD_SOURCE_FCLK;
9051 I915_WRITE(LCPLL_CTL, val);
9053 if (wait_for_us(I915_READ(LCPLL_CTL) &
9054 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9055 DRM_ERROR("Switching to FCLK failed\n");
9057 val = I915_READ(LCPLL_CTL);
9060 val |= LCPLL_PLL_DISABLE;
9061 I915_WRITE(LCPLL_CTL, val);
9062 POSTING_READ(LCPLL_CTL);
9064 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
9065 DRM_ERROR("LCPLL still locked\n");
9067 val = hsw_read_dcomp(dev_priv);
9068 val |= D_COMP_COMP_DISABLE;
9069 hsw_write_dcomp(dev_priv, val);
9072 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9074 DRM_ERROR("D_COMP RCOMP still in progress\n");
9076 if (allow_power_down) {
9077 val = I915_READ(LCPLL_CTL);
9078 val |= LCPLL_POWER_DOWN_ALLOW;
9079 I915_WRITE(LCPLL_CTL, val);
9080 POSTING_READ(LCPLL_CTL);
9085 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9088 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9092 val = I915_READ(LCPLL_CTL);
9094 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9095 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9099 * Make sure we're not on PC8 state before disabling PC8, otherwise
9100 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9102 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9104 if (val & LCPLL_POWER_DOWN_ALLOW) {
9105 val &= ~LCPLL_POWER_DOWN_ALLOW;
9106 I915_WRITE(LCPLL_CTL, val);
9107 POSTING_READ(LCPLL_CTL);
9110 val = hsw_read_dcomp(dev_priv);
9111 val |= D_COMP_COMP_FORCE;
9112 val &= ~D_COMP_COMP_DISABLE;
9113 hsw_write_dcomp(dev_priv, val);
9115 val = I915_READ(LCPLL_CTL);
9116 val &= ~LCPLL_PLL_DISABLE;
9117 I915_WRITE(LCPLL_CTL, val);
9119 if (intel_wait_for_register(dev_priv,
9120 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9122 DRM_ERROR("LCPLL not locked yet\n");
9124 if (val & LCPLL_CD_SOURCE_FCLK) {
9125 val = I915_READ(LCPLL_CTL);
9126 val &= ~LCPLL_CD_SOURCE_FCLK;
9127 I915_WRITE(LCPLL_CTL, val);
9129 if (wait_for_us((I915_READ(LCPLL_CTL) &
9130 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9131 DRM_ERROR("Switching back to LCPLL failed\n");
9134 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9136 intel_update_cdclk(dev_priv);
9137 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
9141 * Package states C8 and deeper are really deep PC states that can only be
9142 * reached when all the devices on the system allow it, so even if the graphics
9143 * device allows PC8+, it doesn't mean the system will actually get to these
9144 * states. Our driver only allows PC8+ when going into runtime PM.
9146 * The requirements for PC8+ are that all the outputs are disabled, the power
9147 * well is disabled and most interrupts are disabled, and these are also
9148 * requirements for runtime PM. When these conditions are met, we manually do
9149 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9150 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9153 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9154 * the state of some registers, so when we come back from PC8+ we need to
9155 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9156 * need to take care of the registers kept by RC6. Notice that this happens even
9157 * if we don't put the device in PCI D3 state (which is what currently happens
9158 * because of the runtime PM support).
9160 * For more, read "Display Sequences for Package C8" on the hardware
9163 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9167 DRM_DEBUG_KMS("Enabling package C8+\n");
9169 if (HAS_PCH_LPT_LP(dev_priv)) {
9170 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9171 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9172 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9175 lpt_disable_clkout_dp(dev_priv);
9176 hsw_disable_lcpll(dev_priv, true, true);
9179 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9183 DRM_DEBUG_KMS("Disabling package C8+\n");
9185 hsw_restore_lcpll(dev_priv);
9186 lpt_init_pch_refclk(dev_priv);
9188 if (HAS_PCH_LPT_LP(dev_priv)) {
9189 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9190 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9191 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9195 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9196 struct intel_crtc_state *crtc_state)
9198 struct intel_atomic_state *state =
9199 to_intel_atomic_state(crtc_state->base.state);
9201 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
9202 struct intel_encoder *encoder =
9203 intel_get_crtc_new_encoder(state, crtc_state);
9205 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9206 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
9207 pipe_name(crtc->pipe));
9215 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9217 struct intel_crtc_state *pipe_config)
9219 enum intel_dpll_id id;
9222 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9223 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9225 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9228 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9231 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9233 struct intel_crtc_state *pipe_config)
9235 enum intel_dpll_id id;
9238 /* TODO: TBT pll not implemented. */
9242 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9243 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9244 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9246 if (WARN_ON(id != DPLL_ID_ICL_DPLL0 && id != DPLL_ID_ICL_DPLL1))
9250 id = DPLL_ID_ICL_MGPLL1;
9253 id = DPLL_ID_ICL_MGPLL2;
9256 id = DPLL_ID_ICL_MGPLL3;
9259 id = DPLL_ID_ICL_MGPLL4;
9266 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9269 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9271 struct intel_crtc_state *pipe_config)
9273 enum intel_dpll_id id;
9277 id = DPLL_ID_SKL_DPLL0;
9280 id = DPLL_ID_SKL_DPLL1;
9283 id = DPLL_ID_SKL_DPLL2;
9286 DRM_ERROR("Incorrect port type\n");
9290 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9293 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9295 struct intel_crtc_state *pipe_config)
9297 enum intel_dpll_id id;
9300 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9301 id = temp >> (port * 3 + 1);
9303 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9306 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9309 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9311 struct intel_crtc_state *pipe_config)
9313 enum intel_dpll_id id;
9314 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9316 switch (ddi_pll_sel) {
9317 case PORT_CLK_SEL_WRPLL1:
9318 id = DPLL_ID_WRPLL1;
9320 case PORT_CLK_SEL_WRPLL2:
9321 id = DPLL_ID_WRPLL2;
9323 case PORT_CLK_SEL_SPLL:
9326 case PORT_CLK_SEL_LCPLL_810:
9327 id = DPLL_ID_LCPLL_810;
9329 case PORT_CLK_SEL_LCPLL_1350:
9330 id = DPLL_ID_LCPLL_1350;
9332 case PORT_CLK_SEL_LCPLL_2700:
9333 id = DPLL_ID_LCPLL_2700;
9336 MISSING_CASE(ddi_pll_sel);
9338 case PORT_CLK_SEL_NONE:
9342 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9345 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9346 struct intel_crtc_state *pipe_config,
9347 u64 *power_domain_mask)
9349 struct drm_device *dev = crtc->base.dev;
9350 struct drm_i915_private *dev_priv = to_i915(dev);
9351 enum intel_display_power_domain power_domain;
9355 * The pipe->transcoder mapping is fixed with the exception of the eDP
9356 * transcoder handled below.
9358 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9361 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9362 * consistency and less surprising code; it's in always on power).
9364 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9365 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9366 enum pipe trans_edp_pipe;
9367 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9369 WARN(1, "unknown pipe linked to edp transcoder\n");
9371 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9372 case TRANS_DDI_EDP_INPUT_A_ON:
9373 trans_edp_pipe = PIPE_A;
9375 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9376 trans_edp_pipe = PIPE_B;
9378 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9379 trans_edp_pipe = PIPE_C;
9383 if (trans_edp_pipe == crtc->pipe)
9384 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9387 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9388 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9390 *power_domain_mask |= BIT_ULL(power_domain);
9392 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9394 return tmp & PIPECONF_ENABLE;
9397 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9398 struct intel_crtc_state *pipe_config,
9399 u64 *power_domain_mask)
9401 struct drm_device *dev = crtc->base.dev;
9402 struct drm_i915_private *dev_priv = to_i915(dev);
9403 enum intel_display_power_domain power_domain;
9405 enum transcoder cpu_transcoder;
9408 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9410 cpu_transcoder = TRANSCODER_DSI_A;
9412 cpu_transcoder = TRANSCODER_DSI_C;
9414 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9415 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9417 *power_domain_mask |= BIT_ULL(power_domain);
9420 * The PLL needs to be enabled with a valid divider
9421 * configuration, otherwise accessing DSI registers will hang
9422 * the machine. See BSpec North Display Engine
9423 * registers/MIPI[BXT]. We can break out here early, since we
9424 * need the same DSI PLL to be enabled for both DSI ports.
9426 if (!bxt_dsi_pll_is_enabled(dev_priv))
9429 /* XXX: this works for video mode only */
9430 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9431 if (!(tmp & DPI_ENABLE))
9434 tmp = I915_READ(MIPI_CTRL(port));
9435 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9438 pipe_config->cpu_transcoder = cpu_transcoder;
9442 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9445 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9446 struct intel_crtc_state *pipe_config)
9448 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9449 struct intel_shared_dpll *pll;
9453 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9455 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9457 if (IS_ICELAKE(dev_priv))
9458 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9459 else if (IS_CANNONLAKE(dev_priv))
9460 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9461 else if (IS_GEN9_BC(dev_priv))
9462 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9463 else if (IS_GEN9_LP(dev_priv))
9464 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9466 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9468 pll = pipe_config->shared_dpll;
9470 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9471 &pipe_config->dpll_hw_state));
9475 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9476 * DDI E. So just check whether this pipe is wired to DDI E and whether
9477 * the PCH transcoder is on.
9479 if (INTEL_GEN(dev_priv) < 9 &&
9480 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9481 pipe_config->has_pch_encoder = true;
9483 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9484 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9485 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9487 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9491 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9492 struct intel_crtc_state *pipe_config)
9494 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9495 enum intel_display_power_domain power_domain;
9496 u64 power_domain_mask;
9499 intel_crtc_init_scalers(crtc, pipe_config);
9501 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9502 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9504 power_domain_mask = BIT_ULL(power_domain);
9506 pipe_config->shared_dpll = NULL;
9508 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9510 if (IS_GEN9_LP(dev_priv) &&
9511 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9519 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9520 haswell_get_ddi_port_state(crtc, pipe_config);
9521 intel_get_pipe_timings(crtc, pipe_config);
9524 intel_get_pipe_src_size(crtc, pipe_config);
9526 pipe_config->gamma_mode =
9527 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9529 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
9530 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
9531 bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV;
9533 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
9534 bool blend_mode_420 = tmp &
9535 PIPEMISC_YUV420_MODE_FULL_BLEND;
9537 pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE;
9538 if (pipe_config->ycbcr420 != clrspace_yuv ||
9539 pipe_config->ycbcr420 != blend_mode_420)
9540 DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp);
9541 } else if (clrspace_yuv) {
9542 DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
9546 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9547 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9548 power_domain_mask |= BIT_ULL(power_domain);
9549 if (INTEL_GEN(dev_priv) >= 9)
9550 skylake_get_pfit_config(crtc, pipe_config);
9552 ironlake_get_pfit_config(crtc, pipe_config);
9555 if (hsw_crtc_supports_ips(crtc)) {
9556 if (IS_HASWELL(dev_priv))
9557 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9560 * We cannot readout IPS state on broadwell, set to
9561 * true so we can set it to a defined state on first
9564 pipe_config->ips_enabled = true;
9568 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9569 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9570 pipe_config->pixel_multiplier =
9571 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9573 pipe_config->pixel_multiplier = 1;
9577 for_each_power_domain(power_domain, power_domain_mask)
9578 intel_display_power_put(dev_priv, power_domain);
9583 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9585 struct drm_i915_private *dev_priv =
9586 to_i915(plane_state->base.plane->dev);
9587 const struct drm_framebuffer *fb = plane_state->base.fb;
9588 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9591 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9592 base = obj->phys_handle->busaddr;
9594 base = intel_plane_ggtt_offset(plane_state);
9596 base += plane_state->main.offset;
9598 /* ILK+ do this automagically */
9599 if (HAS_GMCH_DISPLAY(dev_priv) &&
9600 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9601 base += (plane_state->base.crtc_h *
9602 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9607 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9609 int x = plane_state->base.crtc_x;
9610 int y = plane_state->base.crtc_y;
9614 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9617 pos |= x << CURSOR_X_SHIFT;
9620 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9623 pos |= y << CURSOR_Y_SHIFT;
9628 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9630 const struct drm_mode_config *config =
9631 &plane_state->base.plane->dev->mode_config;
9632 int width = plane_state->base.crtc_w;
9633 int height = plane_state->base.crtc_h;
9635 return width > 0 && width <= config->cursor_width &&
9636 height > 0 && height <= config->cursor_height;
9639 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9640 struct intel_plane_state *plane_state)
9642 const struct drm_framebuffer *fb = plane_state->base.fb;
9647 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9649 DRM_PLANE_HELPER_NO_SCALING,
9650 DRM_PLANE_HELPER_NO_SCALING,
9658 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9659 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9663 src_x = plane_state->base.src_x >> 16;
9664 src_y = plane_state->base.src_y >> 16;
9666 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9667 offset = intel_compute_tile_offset(&src_x, &src_y, plane_state, 0);
9669 if (src_x != 0 || src_y != 0) {
9670 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9674 plane_state->main.offset = offset;
9679 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9680 const struct intel_plane_state *plane_state)
9682 const struct drm_framebuffer *fb = plane_state->base.fb;
9684 return CURSOR_ENABLE |
9685 CURSOR_GAMMA_ENABLE |
9686 CURSOR_FORMAT_ARGB |
9687 CURSOR_STRIDE(fb->pitches[0]);
9690 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9692 int width = plane_state->base.crtc_w;
9695 * 845g/865g are only limited by the width of their cursors,
9696 * the height is arbitrary up to the precision of the register.
9698 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
9701 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
9702 struct intel_plane_state *plane_state)
9704 const struct drm_framebuffer *fb = plane_state->base.fb;
9707 ret = intel_check_cursor(crtc_state, plane_state);
9711 /* if we want to turn off the cursor ignore width and height */
9715 /* Check for which cursor types we support */
9716 if (!i845_cursor_size_ok(plane_state)) {
9717 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9718 plane_state->base.crtc_w,
9719 plane_state->base.crtc_h);
9723 switch (fb->pitches[0]) {
9730 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9735 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9740 static void i845_update_cursor(struct intel_plane *plane,
9741 const struct intel_crtc_state *crtc_state,
9742 const struct intel_plane_state *plane_state)
9744 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9745 u32 cntl = 0, base = 0, pos = 0, size = 0;
9746 unsigned long irqflags;
9748 if (plane_state && plane_state->base.visible) {
9749 unsigned int width = plane_state->base.crtc_w;
9750 unsigned int height = plane_state->base.crtc_h;
9752 cntl = plane_state->ctl;
9753 size = (height << 12) | width;
9755 base = intel_cursor_base(plane_state);
9756 pos = intel_cursor_position(plane_state);
9759 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9761 /* On these chipsets we can only modify the base/size/stride
9762 * whilst the cursor is disabled.
9764 if (plane->cursor.base != base ||
9765 plane->cursor.size != size ||
9766 plane->cursor.cntl != cntl) {
9767 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
9768 I915_WRITE_FW(CURBASE(PIPE_A), base);
9769 I915_WRITE_FW(CURSIZE, size);
9770 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9771 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
9773 plane->cursor.base = base;
9774 plane->cursor.size = size;
9775 plane->cursor.cntl = cntl;
9777 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9780 POSTING_READ_FW(CURCNTR(PIPE_A));
9782 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9785 static void i845_disable_cursor(struct intel_plane *plane,
9786 struct intel_crtc *crtc)
9788 i845_update_cursor(plane, NULL, NULL);
9791 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
9794 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9795 enum intel_display_power_domain power_domain;
9798 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9799 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9802 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9806 intel_display_power_put(dev_priv, power_domain);
9811 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9812 const struct intel_plane_state *plane_state)
9814 struct drm_i915_private *dev_priv =
9815 to_i915(plane_state->base.plane->dev);
9816 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9819 if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
9820 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
9822 if (INTEL_GEN(dev_priv) <= 10) {
9823 cntl |= MCURSOR_GAMMA_ENABLE;
9825 if (HAS_DDI(dev_priv))
9826 cntl |= MCURSOR_PIPE_CSC_ENABLE;
9829 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9830 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
9832 switch (plane_state->base.crtc_w) {
9834 cntl |= MCURSOR_MODE_64_ARGB_AX;
9837 cntl |= MCURSOR_MODE_128_ARGB_AX;
9840 cntl |= MCURSOR_MODE_256_ARGB_AX;
9843 MISSING_CASE(plane_state->base.crtc_w);
9847 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
9848 cntl |= MCURSOR_ROTATE_180;
9853 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
9855 struct drm_i915_private *dev_priv =
9856 to_i915(plane_state->base.plane->dev);
9857 int width = plane_state->base.crtc_w;
9858 int height = plane_state->base.crtc_h;
9860 if (!intel_cursor_size_ok(plane_state))
9863 /* Cursor width is limited to a few power-of-two sizes */
9874 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9875 * height from 8 lines up to the cursor width, when the
9876 * cursor is not rotated. Everything else requires square
9879 if (HAS_CUR_FBC(dev_priv) &&
9880 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
9881 if (height < 8 || height > width)
9884 if (height != width)
9891 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
9892 struct intel_plane_state *plane_state)
9894 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
9895 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9896 const struct drm_framebuffer *fb = plane_state->base.fb;
9897 enum pipe pipe = plane->pipe;
9900 ret = intel_check_cursor(crtc_state, plane_state);
9904 /* if we want to turn off the cursor ignore width and height */
9908 /* Check for which cursor types we support */
9909 if (!i9xx_cursor_size_ok(plane_state)) {
9910 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9911 plane_state->base.crtc_w,
9912 plane_state->base.crtc_h);
9916 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
9917 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9918 fb->pitches[0], plane_state->base.crtc_w);
9923 * There's something wrong with the cursor on CHV pipe C.
9924 * If it straddles the left edge of the screen then
9925 * moving it away from the edge or disabling it often
9926 * results in a pipe underrun, and often that can lead to
9927 * dead pipe (constant underrun reported, and it scans
9928 * out just a solid color). To recover from that, the
9929 * display power well must be turned off and on again.
9930 * Refuse the put the cursor into that compromised position.
9932 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
9933 plane_state->base.visible && plane_state->base.crtc_x < 0) {
9934 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9938 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
9943 static void i9xx_update_cursor(struct intel_plane *plane,
9944 const struct intel_crtc_state *crtc_state,
9945 const struct intel_plane_state *plane_state)
9947 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9948 enum pipe pipe = plane->pipe;
9949 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
9950 unsigned long irqflags;
9952 if (plane_state && plane_state->base.visible) {
9953 cntl = plane_state->ctl;
9955 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
9956 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
9958 base = intel_cursor_base(plane_state);
9959 pos = intel_cursor_position(plane_state);
9962 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9965 * On some platforms writing CURCNTR first will also
9966 * cause CURPOS to be armed by the CURBASE write.
9967 * Without the CURCNTR write the CURPOS write would
9968 * arm itself. Thus we always start the full update
9969 * with a CURCNTR write.
9971 * On other platforms CURPOS always requires the
9972 * CURBASE write to arm the update. Additonally
9973 * a write to any of the cursor register will cancel
9974 * an already armed cursor update. Thus leaving out
9975 * the CURBASE write after CURPOS could lead to a
9976 * cursor that doesn't appear to move, or even change
9977 * shape. Thus we always write CURBASE.
9979 * CURCNTR and CUR_FBC_CTL are always
9980 * armed by the CURBASE write only.
9982 if (plane->cursor.base != base ||
9983 plane->cursor.size != fbc_ctl ||
9984 plane->cursor.cntl != cntl) {
9985 I915_WRITE_FW(CURCNTR(pipe), cntl);
9986 if (HAS_CUR_FBC(dev_priv))
9987 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
9988 I915_WRITE_FW(CURPOS(pipe), pos);
9989 I915_WRITE_FW(CURBASE(pipe), base);
9991 plane->cursor.base = base;
9992 plane->cursor.size = fbc_ctl;
9993 plane->cursor.cntl = cntl;
9995 I915_WRITE_FW(CURPOS(pipe), pos);
9996 I915_WRITE_FW(CURBASE(pipe), base);
9999 POSTING_READ_FW(CURBASE(pipe));
10001 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10004 static void i9xx_disable_cursor(struct intel_plane *plane,
10005 struct intel_crtc *crtc)
10007 i9xx_update_cursor(plane, NULL, NULL);
10010 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10013 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10014 enum intel_display_power_domain power_domain;
10019 * Not 100% correct for planes that can move between pipes,
10020 * but that's only the case for gen2-3 which don't have any
10021 * display power wells.
10023 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
10024 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
10027 val = I915_READ(CURCNTR(plane->pipe));
10029 ret = val & MCURSOR_MODE;
10031 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10032 *pipe = plane->pipe;
10034 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10035 MCURSOR_PIPE_SELECT_SHIFT;
10037 intel_display_power_put(dev_priv, power_domain);
10042 /* VESA 640x480x72Hz mode to set on the pipe */
10043 static const struct drm_display_mode load_detect_mode = {
10044 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10045 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10048 struct drm_framebuffer *
10049 intel_framebuffer_create(struct drm_i915_gem_object *obj,
10050 struct drm_mode_fb_cmd2 *mode_cmd)
10052 struct intel_framebuffer *intel_fb;
10055 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10057 return ERR_PTR(-ENOMEM);
10059 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
10063 return &intel_fb->base;
10067 return ERR_PTR(ret);
10070 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10071 struct drm_crtc *crtc)
10073 struct drm_plane *plane;
10074 struct drm_plane_state *plane_state;
10077 ret = drm_atomic_add_affected_planes(state, crtc);
10081 for_each_new_plane_in_state(state, plane, plane_state, i) {
10082 if (plane_state->crtc != crtc)
10085 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10089 drm_atomic_set_fb_for_plane(plane_state, NULL);
10095 int intel_get_load_detect_pipe(struct drm_connector *connector,
10096 const struct drm_display_mode *mode,
10097 struct intel_load_detect_pipe *old,
10098 struct drm_modeset_acquire_ctx *ctx)
10100 struct intel_crtc *intel_crtc;
10101 struct intel_encoder *intel_encoder =
10102 intel_attached_encoder(connector);
10103 struct drm_crtc *possible_crtc;
10104 struct drm_encoder *encoder = &intel_encoder->base;
10105 struct drm_crtc *crtc = NULL;
10106 struct drm_device *dev = encoder->dev;
10107 struct drm_i915_private *dev_priv = to_i915(dev);
10108 struct drm_mode_config *config = &dev->mode_config;
10109 struct drm_atomic_state *state = NULL, *restore_state = NULL;
10110 struct drm_connector_state *connector_state;
10111 struct intel_crtc_state *crtc_state;
10114 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10115 connector->base.id, connector->name,
10116 encoder->base.id, encoder->name);
10118 old->restore_state = NULL;
10120 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
10123 * Algorithm gets a little messy:
10125 * - if the connector already has an assigned crtc, use it (but make
10126 * sure it's on first)
10128 * - try to find the first unused crtc that can drive this connector,
10129 * and use that if we find one
10132 /* See if we already have a CRTC for this connector */
10133 if (connector->state->crtc) {
10134 crtc = connector->state->crtc;
10136 ret = drm_modeset_lock(&crtc->mutex, ctx);
10140 /* Make sure the crtc and connector are running */
10144 /* Find an unused one (if possible) */
10145 for_each_crtc(dev, possible_crtc) {
10147 if (!(encoder->possible_crtcs & (1 << i)))
10150 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10154 if (possible_crtc->state->enable) {
10155 drm_modeset_unlock(&possible_crtc->mutex);
10159 crtc = possible_crtc;
10164 * If we didn't find an unused CRTC, don't use any.
10167 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10173 intel_crtc = to_intel_crtc(crtc);
10175 state = drm_atomic_state_alloc(dev);
10176 restore_state = drm_atomic_state_alloc(dev);
10177 if (!state || !restore_state) {
10182 state->acquire_ctx = ctx;
10183 restore_state->acquire_ctx = ctx;
10185 connector_state = drm_atomic_get_connector_state(state, connector);
10186 if (IS_ERR(connector_state)) {
10187 ret = PTR_ERR(connector_state);
10191 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10195 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10196 if (IS_ERR(crtc_state)) {
10197 ret = PTR_ERR(crtc_state);
10201 crtc_state->base.active = crtc_state->base.enable = true;
10204 mode = &load_detect_mode;
10206 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
10210 ret = intel_modeset_disable_planes(state, crtc);
10214 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10216 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
10218 ret = drm_atomic_add_affected_planes(restore_state, crtc);
10220 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10224 ret = drm_atomic_commit(state);
10226 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10230 old->restore_state = restore_state;
10231 drm_atomic_state_put(state);
10233 /* let the connector get through one full cycle before testing */
10234 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
10239 drm_atomic_state_put(state);
10242 if (restore_state) {
10243 drm_atomic_state_put(restore_state);
10244 restore_state = NULL;
10247 if (ret == -EDEADLK)
10253 void intel_release_load_detect_pipe(struct drm_connector *connector,
10254 struct intel_load_detect_pipe *old,
10255 struct drm_modeset_acquire_ctx *ctx)
10257 struct intel_encoder *intel_encoder =
10258 intel_attached_encoder(connector);
10259 struct drm_encoder *encoder = &intel_encoder->base;
10260 struct drm_atomic_state *state = old->restore_state;
10263 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10264 connector->base.id, connector->name,
10265 encoder->base.id, encoder->name);
10270 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10272 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10273 drm_atomic_state_put(state);
10276 static int i9xx_pll_refclk(struct drm_device *dev,
10277 const struct intel_crtc_state *pipe_config)
10279 struct drm_i915_private *dev_priv = to_i915(dev);
10280 u32 dpll = pipe_config->dpll_hw_state.dpll;
10282 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10283 return dev_priv->vbt.lvds_ssc_freq;
10284 else if (HAS_PCH_SPLIT(dev_priv))
10286 else if (!IS_GEN2(dev_priv))
10292 /* Returns the clock of the currently programmed mode of the given pipe. */
10293 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10294 struct intel_crtc_state *pipe_config)
10296 struct drm_device *dev = crtc->base.dev;
10297 struct drm_i915_private *dev_priv = to_i915(dev);
10298 int pipe = pipe_config->cpu_transcoder;
10299 u32 dpll = pipe_config->dpll_hw_state.dpll;
10303 int refclk = i9xx_pll_refclk(dev, pipe_config);
10305 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10306 fp = pipe_config->dpll_hw_state.fp0;
10308 fp = pipe_config->dpll_hw_state.fp1;
10310 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10311 if (IS_PINEVIEW(dev_priv)) {
10312 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10313 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10315 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10316 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10319 if (!IS_GEN2(dev_priv)) {
10320 if (IS_PINEVIEW(dev_priv))
10321 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10322 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10324 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10325 DPLL_FPA01_P1_POST_DIV_SHIFT);
10327 switch (dpll & DPLL_MODE_MASK) {
10328 case DPLLB_MODE_DAC_SERIAL:
10329 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10332 case DPLLB_MODE_LVDS:
10333 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10337 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10338 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10342 if (IS_PINEVIEW(dev_priv))
10343 port_clock = pnv_calc_dpll_params(refclk, &clock);
10345 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10347 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10348 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10351 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10352 DPLL_FPA01_P1_POST_DIV_SHIFT);
10354 if (lvds & LVDS_CLKB_POWER_UP)
10359 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10362 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10363 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10365 if (dpll & PLL_P2_DIVIDE_BY_4)
10371 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10375 * This value includes pixel_multiplier. We will use
10376 * port_clock to compute adjusted_mode.crtc_clock in the
10377 * encoder's get_config() function.
10379 pipe_config->port_clock = port_clock;
10382 int intel_dotclock_calculate(int link_freq,
10383 const struct intel_link_m_n *m_n)
10386 * The calculation for the data clock is:
10387 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10388 * But we want to avoid losing precison if possible, so:
10389 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10391 * and the link clock is simpler:
10392 * link_clock = (m * link_clock) / n
10398 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10401 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10402 struct intel_crtc_state *pipe_config)
10404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10406 /* read out port_clock from the DPLL */
10407 i9xx_crtc_clock_get(crtc, pipe_config);
10410 * In case there is an active pipe without active ports,
10411 * we may need some idea for the dotclock anyway.
10412 * Calculate one based on the FDI configuration.
10414 pipe_config->base.adjusted_mode.crtc_clock =
10415 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10416 &pipe_config->fdi_m_n);
10419 /* Returns the currently programmed mode of the given encoder. */
10420 struct drm_display_mode *
10421 intel_encoder_current_mode(struct intel_encoder *encoder)
10423 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10424 struct intel_crtc_state *crtc_state;
10425 struct drm_display_mode *mode;
10426 struct intel_crtc *crtc;
10429 if (!encoder->get_hw_state(encoder, &pipe))
10432 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10434 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10438 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10444 crtc_state->base.crtc = &crtc->base;
10446 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10452 encoder->get_config(encoder, crtc_state);
10454 intel_mode_from_pipe_config(mode, crtc_state);
10461 static void intel_crtc_destroy(struct drm_crtc *crtc)
10463 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10465 drm_crtc_cleanup(crtc);
10470 * intel_wm_need_update - Check whether watermarks need updating
10471 * @plane: drm plane
10472 * @state: new plane state
10474 * Check current plane state versus the new one to determine whether
10475 * watermarks need to be recalculated.
10477 * Returns true or false.
10479 static bool intel_wm_need_update(struct drm_plane *plane,
10480 struct drm_plane_state *state)
10482 struct intel_plane_state *new = to_intel_plane_state(state);
10483 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10485 /* Update watermarks on tiling or size changes. */
10486 if (new->base.visible != cur->base.visible)
10489 if (!cur->base.fb || !new->base.fb)
10492 if (cur->base.fb->modifier != new->base.fb->modifier ||
10493 cur->base.rotation != new->base.rotation ||
10494 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10495 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10496 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10497 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10503 static bool needs_scaling(const struct intel_plane_state *state)
10505 int src_w = drm_rect_width(&state->base.src) >> 16;
10506 int src_h = drm_rect_height(&state->base.src) >> 16;
10507 int dst_w = drm_rect_width(&state->base.dst);
10508 int dst_h = drm_rect_height(&state->base.dst);
10510 return (src_w != dst_w || src_h != dst_h);
10513 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10514 struct drm_crtc_state *crtc_state,
10515 const struct intel_plane_state *old_plane_state,
10516 struct drm_plane_state *plane_state)
10518 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10519 struct drm_crtc *crtc = crtc_state->crtc;
10520 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10521 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10522 struct drm_device *dev = crtc->dev;
10523 struct drm_i915_private *dev_priv = to_i915(dev);
10524 bool mode_changed = needs_modeset(crtc_state);
10525 bool was_crtc_enabled = old_crtc_state->base.active;
10526 bool is_crtc_enabled = crtc_state->active;
10527 bool turn_off, turn_on, visible, was_visible;
10528 struct drm_framebuffer *fb = plane_state->fb;
10531 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10532 ret = skl_update_scaler_plane(
10533 to_intel_crtc_state(crtc_state),
10534 to_intel_plane_state(plane_state));
10539 was_visible = old_plane_state->base.visible;
10540 visible = plane_state->visible;
10542 if (!was_crtc_enabled && WARN_ON(was_visible))
10543 was_visible = false;
10546 * Visibility is calculated as if the crtc was on, but
10547 * after scaler setup everything depends on it being off
10548 * when the crtc isn't active.
10550 * FIXME this is wrong for watermarks. Watermarks should also
10551 * be computed as if the pipe would be active. Perhaps move
10552 * per-plane wm computation to the .check_plane() hook, and
10553 * only combine the results from all planes in the current place?
10555 if (!is_crtc_enabled) {
10556 plane_state->visible = visible = false;
10557 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10560 if (!was_visible && !visible)
10563 if (fb != old_plane_state->base.fb)
10564 pipe_config->fb_changed = true;
10566 turn_off = was_visible && (!visible || mode_changed);
10567 turn_on = visible && (!was_visible || mode_changed);
10569 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10570 intel_crtc->base.base.id, intel_crtc->base.name,
10571 plane->base.base.id, plane->base.name,
10572 fb ? fb->base.id : -1);
10574 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10575 plane->base.base.id, plane->base.name,
10576 was_visible, visible,
10577 turn_off, turn_on, mode_changed);
10580 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10581 pipe_config->update_wm_pre = true;
10583 /* must disable cxsr around plane enable/disable */
10584 if (plane->id != PLANE_CURSOR)
10585 pipe_config->disable_cxsr = true;
10586 } else if (turn_off) {
10587 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10588 pipe_config->update_wm_post = true;
10590 /* must disable cxsr around plane enable/disable */
10591 if (plane->id != PLANE_CURSOR)
10592 pipe_config->disable_cxsr = true;
10593 } else if (intel_wm_need_update(&plane->base, plane_state)) {
10594 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
10595 /* FIXME bollocks */
10596 pipe_config->update_wm_pre = true;
10597 pipe_config->update_wm_post = true;
10601 if (visible || was_visible)
10602 pipe_config->fb_bits |= plane->frontbuffer_bit;
10605 * WaCxSRDisabledForSpriteScaling:ivb
10607 * cstate->update_wm was already set above, so this flag will
10608 * take effect when we commit and program watermarks.
10610 if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) &&
10611 needs_scaling(to_intel_plane_state(plane_state)) &&
10612 !needs_scaling(old_plane_state))
10613 pipe_config->disable_lp_wm = true;
10618 static bool encoders_cloneable(const struct intel_encoder *a,
10619 const struct intel_encoder *b)
10621 /* masks could be asymmetric, so check both ways */
10622 return a == b || (a->cloneable & (1 << b->type) &&
10623 b->cloneable & (1 << a->type));
10626 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10627 struct intel_crtc *crtc,
10628 struct intel_encoder *encoder)
10630 struct intel_encoder *source_encoder;
10631 struct drm_connector *connector;
10632 struct drm_connector_state *connector_state;
10635 for_each_new_connector_in_state(state, connector, connector_state, i) {
10636 if (connector_state->crtc != &crtc->base)
10640 to_intel_encoder(connector_state->best_encoder);
10641 if (!encoders_cloneable(encoder, source_encoder))
10648 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10649 struct drm_crtc_state *crtc_state)
10651 struct drm_device *dev = crtc->dev;
10652 struct drm_i915_private *dev_priv = to_i915(dev);
10653 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10654 struct intel_crtc_state *pipe_config =
10655 to_intel_crtc_state(crtc_state);
10656 struct drm_atomic_state *state = crtc_state->state;
10658 bool mode_changed = needs_modeset(crtc_state);
10660 if (mode_changed && !crtc_state->active)
10661 pipe_config->update_wm_post = true;
10663 if (mode_changed && crtc_state->enable &&
10664 dev_priv->display.crtc_compute_clock &&
10665 !WARN_ON(pipe_config->shared_dpll)) {
10666 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10672 if (crtc_state->color_mgmt_changed) {
10673 ret = intel_color_check(crtc, crtc_state);
10678 * Changing color management on Intel hardware is
10679 * handled as part of planes update.
10681 crtc_state->planes_changed = true;
10685 if (dev_priv->display.compute_pipe_wm) {
10686 ret = dev_priv->display.compute_pipe_wm(pipe_config);
10688 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10693 if (dev_priv->display.compute_intermediate_wm &&
10694 !to_intel_atomic_state(state)->skip_intermediate_wm) {
10695 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10699 * Calculate 'intermediate' watermarks that satisfy both the
10700 * old state and the new state. We can program these
10703 ret = dev_priv->display.compute_intermediate_wm(dev,
10707 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10710 } else if (dev_priv->display.compute_intermediate_wm) {
10711 if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
10712 pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
10715 if (INTEL_GEN(dev_priv) >= 9) {
10717 ret = skl_update_scaler_crtc(pipe_config);
10720 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10723 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
10727 if (HAS_IPS(dev_priv))
10728 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10733 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
10734 .atomic_begin = intel_begin_crtc_commit,
10735 .atomic_flush = intel_finish_crtc_commit,
10736 .atomic_check = intel_crtc_atomic_check,
10739 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10741 struct intel_connector *connector;
10742 struct drm_connector_list_iter conn_iter;
10744 drm_connector_list_iter_begin(dev, &conn_iter);
10745 for_each_intel_connector_iter(connector, &conn_iter) {
10746 if (connector->base.state->crtc)
10747 drm_connector_put(&connector->base);
10749 if (connector->base.encoder) {
10750 connector->base.state->best_encoder =
10751 connector->base.encoder;
10752 connector->base.state->crtc =
10753 connector->base.encoder->crtc;
10755 drm_connector_get(&connector->base);
10757 connector->base.state->best_encoder = NULL;
10758 connector->base.state->crtc = NULL;
10761 drm_connector_list_iter_end(&conn_iter);
10765 connected_sink_compute_bpp(struct intel_connector *connector,
10766 struct intel_crtc_state *pipe_config)
10768 const struct drm_display_info *info = &connector->base.display_info;
10769 int bpp = pipe_config->pipe_bpp;
10771 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10772 connector->base.base.id,
10773 connector->base.name);
10775 /* Don't use an invalid EDID bpc value */
10776 if (info->bpc != 0 && info->bpc * 3 < bpp) {
10777 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10778 bpp, info->bpc * 3);
10779 pipe_config->pipe_bpp = info->bpc * 3;
10782 /* Clamp bpp to 8 on screens without EDID 1.4 */
10783 if (info->bpc == 0 && bpp > 24) {
10784 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10786 pipe_config->pipe_bpp = 24;
10791 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
10792 struct intel_crtc_state *pipe_config)
10794 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10795 struct drm_atomic_state *state;
10796 struct drm_connector *connector;
10797 struct drm_connector_state *connector_state;
10800 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10801 IS_CHERRYVIEW(dev_priv)))
10803 else if (INTEL_GEN(dev_priv) >= 5)
10809 pipe_config->pipe_bpp = bpp;
10811 state = pipe_config->base.state;
10813 /* Clamp display bpp to EDID value */
10814 for_each_new_connector_in_state(state, connector, connector_state, i) {
10815 if (connector_state->crtc != &crtc->base)
10818 connected_sink_compute_bpp(to_intel_connector(connector),
10825 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
10827 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10828 "type: 0x%x flags: 0x%x\n",
10830 mode->crtc_hdisplay, mode->crtc_hsync_start,
10831 mode->crtc_hsync_end, mode->crtc_htotal,
10832 mode->crtc_vdisplay, mode->crtc_vsync_start,
10833 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
10837 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
10838 unsigned int lane_count, struct intel_link_m_n *m_n)
10840 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10842 m_n->gmch_m, m_n->gmch_n,
10843 m_n->link_m, m_n->link_n, m_n->tu);
10846 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
10848 static const char * const output_type_str[] = {
10849 OUTPUT_TYPE(UNUSED),
10850 OUTPUT_TYPE(ANALOG),
10854 OUTPUT_TYPE(TVOUT),
10860 OUTPUT_TYPE(DP_MST),
10865 static void snprintf_output_types(char *buf, size_t len,
10866 unsigned int output_types)
10873 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
10876 if ((output_types & BIT(i)) == 0)
10879 r = snprintf(str, len, "%s%s",
10880 str != buf ? "," : "", output_type_str[i]);
10886 output_types &= ~BIT(i);
10889 WARN_ON_ONCE(output_types != 0);
10892 static void intel_dump_pipe_config(struct intel_crtc *crtc,
10893 struct intel_crtc_state *pipe_config,
10894 const char *context)
10896 struct drm_device *dev = crtc->base.dev;
10897 struct drm_i915_private *dev_priv = to_i915(dev);
10898 struct drm_plane *plane;
10899 struct intel_plane *intel_plane;
10900 struct intel_plane_state *state;
10901 struct drm_framebuffer *fb;
10904 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10905 crtc->base.base.id, crtc->base.name, context);
10907 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
10908 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
10909 buf, pipe_config->output_types);
10911 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10912 transcoder_name(pipe_config->cpu_transcoder),
10913 pipe_config->pipe_bpp, pipe_config->dither);
10915 if (pipe_config->has_pch_encoder)
10916 intel_dump_m_n_config(pipe_config, "fdi",
10917 pipe_config->fdi_lanes,
10918 &pipe_config->fdi_m_n);
10920 if (pipe_config->ycbcr420)
10921 DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
10923 if (intel_crtc_has_dp_encoder(pipe_config)) {
10924 intel_dump_m_n_config(pipe_config, "dp m_n",
10925 pipe_config->lane_count, &pipe_config->dp_m_n);
10926 if (pipe_config->has_drrs)
10927 intel_dump_m_n_config(pipe_config, "dp m2_n2",
10928 pipe_config->lane_count,
10929 &pipe_config->dp_m2_n2);
10932 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10933 pipe_config->has_audio, pipe_config->has_infoframe);
10935 DRM_DEBUG_KMS("requested mode:\n");
10936 drm_mode_debug_printmodeline(&pipe_config->base.mode);
10937 DRM_DEBUG_KMS("adjusted mode:\n");
10938 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
10939 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
10940 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10941 pipe_config->port_clock,
10942 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
10943 pipe_config->pixel_rate);
10945 if (INTEL_GEN(dev_priv) >= 9)
10946 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10948 pipe_config->scaler_state.scaler_users,
10949 pipe_config->scaler_state.scaler_id);
10951 if (HAS_GMCH_DISPLAY(dev_priv))
10952 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10953 pipe_config->gmch_pfit.control,
10954 pipe_config->gmch_pfit.pgm_ratios,
10955 pipe_config->gmch_pfit.lvds_border_bits);
10957 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10958 pipe_config->pch_pfit.pos,
10959 pipe_config->pch_pfit.size,
10960 enableddisabled(pipe_config->pch_pfit.enabled));
10962 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10963 pipe_config->ips_enabled, pipe_config->double_wide);
10965 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
10967 DRM_DEBUG_KMS("planes on this crtc\n");
10968 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
10969 struct drm_format_name_buf format_name;
10970 intel_plane = to_intel_plane(plane);
10971 if (intel_plane->pipe != crtc->pipe)
10974 state = to_intel_plane_state(plane->state);
10975 fb = state->base.fb;
10977 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10978 plane->base.id, plane->name, state->scaler_id);
10982 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10983 plane->base.id, plane->name,
10984 fb->base.id, fb->width, fb->height,
10985 drm_get_format_name(fb->format->format, &format_name));
10986 if (INTEL_GEN(dev_priv) >= 9)
10987 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10989 state->base.src.x1 >> 16,
10990 state->base.src.y1 >> 16,
10991 drm_rect_width(&state->base.src) >> 16,
10992 drm_rect_height(&state->base.src) >> 16,
10993 state->base.dst.x1, state->base.dst.y1,
10994 drm_rect_width(&state->base.dst),
10995 drm_rect_height(&state->base.dst));
10999 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
11001 struct drm_device *dev = state->dev;
11002 struct drm_connector *connector;
11003 struct drm_connector_list_iter conn_iter;
11004 unsigned int used_ports = 0;
11005 unsigned int used_mst_ports = 0;
11009 * Walk the connector list instead of the encoder
11010 * list to detect the problem on ddi platforms
11011 * where there's just one encoder per digital port.
11013 drm_connector_list_iter_begin(dev, &conn_iter);
11014 drm_for_each_connector_iter(connector, &conn_iter) {
11015 struct drm_connector_state *connector_state;
11016 struct intel_encoder *encoder;
11018 connector_state = drm_atomic_get_new_connector_state(state, connector);
11019 if (!connector_state)
11020 connector_state = connector->state;
11022 if (!connector_state->best_encoder)
11025 encoder = to_intel_encoder(connector_state->best_encoder);
11027 WARN_ON(!connector_state->crtc);
11029 switch (encoder->type) {
11030 unsigned int port_mask;
11031 case INTEL_OUTPUT_DDI:
11032 if (WARN_ON(!HAS_DDI(to_i915(dev))))
11034 /* else: fall through */
11035 case INTEL_OUTPUT_DP:
11036 case INTEL_OUTPUT_HDMI:
11037 case INTEL_OUTPUT_EDP:
11038 port_mask = 1 << encoder->port;
11040 /* the same port mustn't appear more than once */
11041 if (used_ports & port_mask)
11044 used_ports |= port_mask;
11046 case INTEL_OUTPUT_DP_MST:
11048 1 << encoder->port;
11054 drm_connector_list_iter_end(&conn_iter);
11056 /* can't mix MST and SST/HDMI on the same port */
11057 if (used_ports & used_mst_ports)
11064 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11066 struct drm_i915_private *dev_priv =
11067 to_i915(crtc_state->base.crtc->dev);
11068 struct intel_crtc_scaler_state scaler_state;
11069 struct intel_dpll_hw_state dpll_hw_state;
11070 struct intel_shared_dpll *shared_dpll;
11071 struct intel_crtc_wm_state wm_state;
11072 bool force_thru, ips_force_disable;
11074 /* FIXME: before the switch to atomic started, a new pipe_config was
11075 * kzalloc'd. Code that depends on any field being zero should be
11076 * fixed, so that the crtc_state can be safely duplicated. For now,
11077 * only fields that are know to not cause problems are preserved. */
11079 scaler_state = crtc_state->scaler_state;
11080 shared_dpll = crtc_state->shared_dpll;
11081 dpll_hw_state = crtc_state->dpll_hw_state;
11082 force_thru = crtc_state->pch_pfit.force_thru;
11083 ips_force_disable = crtc_state->ips_force_disable;
11084 if (IS_G4X(dev_priv) ||
11085 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11086 wm_state = crtc_state->wm;
11088 /* Keep base drm_crtc_state intact, only clear our extended struct */
11089 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11090 memset(&crtc_state->base + 1, 0,
11091 sizeof(*crtc_state) - sizeof(crtc_state->base));
11093 crtc_state->scaler_state = scaler_state;
11094 crtc_state->shared_dpll = shared_dpll;
11095 crtc_state->dpll_hw_state = dpll_hw_state;
11096 crtc_state->pch_pfit.force_thru = force_thru;
11097 crtc_state->ips_force_disable = ips_force_disable;
11098 if (IS_G4X(dev_priv) ||
11099 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11100 crtc_state->wm = wm_state;
11104 intel_modeset_pipe_config(struct drm_crtc *crtc,
11105 struct intel_crtc_state *pipe_config)
11107 struct drm_atomic_state *state = pipe_config->base.state;
11108 struct intel_encoder *encoder;
11109 struct drm_connector *connector;
11110 struct drm_connector_state *connector_state;
11111 int base_bpp, ret = -EINVAL;
11115 clear_intel_crtc_state(pipe_config);
11117 pipe_config->cpu_transcoder =
11118 (enum transcoder) to_intel_crtc(crtc)->pipe;
11121 * Sanitize sync polarity flags based on requested ones. If neither
11122 * positive or negative polarity is requested, treat this as meaning
11123 * negative polarity.
11125 if (!(pipe_config->base.adjusted_mode.flags &
11126 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
11127 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
11129 if (!(pipe_config->base.adjusted_mode.flags &
11130 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
11131 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
11133 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11139 * Determine the real pipe dimensions. Note that stereo modes can
11140 * increase the actual pipe size due to the frame doubling and
11141 * insertion of additional space for blanks between the frame. This
11142 * is stored in the crtc timings. We use the requested mode to do this
11143 * computation to clearly distinguish it from the adjusted mode, which
11144 * can be changed by the connectors in the below retry loop.
11146 drm_mode_get_hv_timing(&pipe_config->base.mode,
11147 &pipe_config->pipe_src_w,
11148 &pipe_config->pipe_src_h);
11150 for_each_new_connector_in_state(state, connector, connector_state, i) {
11151 if (connector_state->crtc != crtc)
11154 encoder = to_intel_encoder(connector_state->best_encoder);
11156 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11157 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11162 * Determine output_types before calling the .compute_config()
11163 * hooks so that the hooks can use this information safely.
11165 if (encoder->compute_output_type)
11166 pipe_config->output_types |=
11167 BIT(encoder->compute_output_type(encoder, pipe_config,
11170 pipe_config->output_types |= BIT(encoder->type);
11174 /* Ensure the port clock defaults are reset when retrying. */
11175 pipe_config->port_clock = 0;
11176 pipe_config->pixel_multiplier = 1;
11178 /* Fill in default crtc timings, allow encoders to overwrite them. */
11179 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11180 CRTC_STEREO_DOUBLE);
11182 /* Pass our mode to the connectors and the CRTC to give them a chance to
11183 * adjust it according to limitations or connector properties, and also
11184 * a chance to reject the mode entirely.
11186 for_each_new_connector_in_state(state, connector, connector_state, i) {
11187 if (connector_state->crtc != crtc)
11190 encoder = to_intel_encoder(connector_state->best_encoder);
11192 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
11193 DRM_DEBUG_KMS("Encoder config failure\n");
11198 /* Set default port clock if not overwritten by the encoder. Needs to be
11199 * done afterwards in case the encoder adjusts the mode. */
11200 if (!pipe_config->port_clock)
11201 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
11202 * pipe_config->pixel_multiplier;
11204 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
11206 DRM_DEBUG_KMS("CRTC fixup failed\n");
11210 if (ret == RETRY) {
11211 if (WARN(!retry, "loop in pipe configuration computation\n")) {
11216 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11218 goto encoder_retry;
11221 /* Dithering seems to not pass-through bits correctly when it should, so
11222 * only enable it on 6bpc panels and when its not a compliance
11223 * test requesting 6bpc video pattern.
11225 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11226 !pipe_config->dither_force_disable;
11227 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11228 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
11234 static bool intel_fuzzy_clock_check(int clock1, int clock2)
11238 if (clock1 == clock2)
11241 if (!clock1 || !clock2)
11244 diff = abs(clock1 - clock2);
11246 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11253 intel_compare_m_n(unsigned int m, unsigned int n,
11254 unsigned int m2, unsigned int n2,
11257 if (m == m2 && n == n2)
11260 if (exact || !m || !n || !m2 || !n2)
11263 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11270 } else if (n < n2) {
11280 return intel_fuzzy_clock_check(m, m2);
11284 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11285 struct intel_link_m_n *m2_n2,
11288 if (m_n->tu == m2_n2->tu &&
11289 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11290 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11291 intel_compare_m_n(m_n->link_m, m_n->link_n,
11292 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11302 static void __printf(3, 4)
11303 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11305 struct va_format vaf;
11308 va_start(args, format);
11313 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11315 drm_err("mismatch in %s %pV", name, &vaf);
11321 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11322 struct intel_crtc_state *current_config,
11323 struct intel_crtc_state *pipe_config,
11327 bool fixup_inherited = adjust &&
11328 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11329 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11331 #define PIPE_CONF_CHECK_X(name) do { \
11332 if (current_config->name != pipe_config->name) { \
11333 pipe_config_err(adjust, __stringify(name), \
11334 "(expected 0x%08x, found 0x%08x)\n", \
11335 current_config->name, \
11336 pipe_config->name); \
11341 #define PIPE_CONF_CHECK_I(name) do { \
11342 if (current_config->name != pipe_config->name) { \
11343 pipe_config_err(adjust, __stringify(name), \
11344 "(expected %i, found %i)\n", \
11345 current_config->name, \
11346 pipe_config->name); \
11351 #define PIPE_CONF_CHECK_BOOL(name) do { \
11352 if (current_config->name != pipe_config->name) { \
11353 pipe_config_err(adjust, __stringify(name), \
11354 "(expected %s, found %s)\n", \
11355 yesno(current_config->name), \
11356 yesno(pipe_config->name)); \
11362 * Checks state where we only read out the enabling, but not the entire
11363 * state itself (like full infoframes or ELD for audio). These states
11364 * require a full modeset on bootup to fix up.
11366 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11367 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11368 PIPE_CONF_CHECK_BOOL(name); \
11370 pipe_config_err(adjust, __stringify(name), \
11371 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11372 yesno(current_config->name), \
11373 yesno(pipe_config->name)); \
11378 #define PIPE_CONF_CHECK_P(name) do { \
11379 if (current_config->name != pipe_config->name) { \
11380 pipe_config_err(adjust, __stringify(name), \
11381 "(expected %p, found %p)\n", \
11382 current_config->name, \
11383 pipe_config->name); \
11388 #define PIPE_CONF_CHECK_M_N(name) do { \
11389 if (!intel_compare_link_m_n(¤t_config->name, \
11390 &pipe_config->name,\
11392 pipe_config_err(adjust, __stringify(name), \
11393 "(expected tu %i gmch %i/%i link %i/%i, " \
11394 "found tu %i, gmch %i/%i link %i/%i)\n", \
11395 current_config->name.tu, \
11396 current_config->name.gmch_m, \
11397 current_config->name.gmch_n, \
11398 current_config->name.link_m, \
11399 current_config->name.link_n, \
11400 pipe_config->name.tu, \
11401 pipe_config->name.gmch_m, \
11402 pipe_config->name.gmch_n, \
11403 pipe_config->name.link_m, \
11404 pipe_config->name.link_n); \
11409 /* This is required for BDW+ where there is only one set of registers for
11410 * switching between high and low RR.
11411 * This macro can be used whenever a comparison has to be made between one
11412 * hw state and multiple sw state variables.
11414 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
11415 if (!intel_compare_link_m_n(¤t_config->name, \
11416 &pipe_config->name, adjust) && \
11417 !intel_compare_link_m_n(¤t_config->alt_name, \
11418 &pipe_config->name, adjust)) { \
11419 pipe_config_err(adjust, __stringify(name), \
11420 "(expected tu %i gmch %i/%i link %i/%i, " \
11421 "or tu %i gmch %i/%i link %i/%i, " \
11422 "found tu %i, gmch %i/%i link %i/%i)\n", \
11423 current_config->name.tu, \
11424 current_config->name.gmch_m, \
11425 current_config->name.gmch_n, \
11426 current_config->name.link_m, \
11427 current_config->name.link_n, \
11428 current_config->alt_name.tu, \
11429 current_config->alt_name.gmch_m, \
11430 current_config->alt_name.gmch_n, \
11431 current_config->alt_name.link_m, \
11432 current_config->alt_name.link_n, \
11433 pipe_config->name.tu, \
11434 pipe_config->name.gmch_m, \
11435 pipe_config->name.gmch_n, \
11436 pipe_config->name.link_m, \
11437 pipe_config->name.link_n); \
11442 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
11443 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11444 pipe_config_err(adjust, __stringify(name), \
11445 "(%x) (expected %i, found %i)\n", \
11447 current_config->name & (mask), \
11448 pipe_config->name & (mask)); \
11453 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
11454 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11455 pipe_config_err(adjust, __stringify(name), \
11456 "(expected %i, found %i)\n", \
11457 current_config->name, \
11458 pipe_config->name); \
11463 #define PIPE_CONF_QUIRK(quirk) \
11464 ((current_config->quirks | pipe_config->quirks) & (quirk))
11466 PIPE_CONF_CHECK_I(cpu_transcoder);
11468 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11469 PIPE_CONF_CHECK_I(fdi_lanes);
11470 PIPE_CONF_CHECK_M_N(fdi_m_n);
11472 PIPE_CONF_CHECK_I(lane_count);
11473 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11475 if (INTEL_GEN(dev_priv) < 8) {
11476 PIPE_CONF_CHECK_M_N(dp_m_n);
11478 if (current_config->has_drrs)
11479 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11481 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11483 PIPE_CONF_CHECK_X(output_types);
11485 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11486 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11487 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11488 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11489 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11490 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
11492 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11493 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11494 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11495 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11496 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11497 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
11499 PIPE_CONF_CHECK_I(pixel_multiplier);
11500 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11501 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11502 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11503 PIPE_CONF_CHECK_BOOL(limited_color_range);
11505 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11506 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11507 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
11508 PIPE_CONF_CHECK_BOOL(ycbcr420);
11510 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11512 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11513 DRM_MODE_FLAG_INTERLACE);
11515 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11516 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11517 DRM_MODE_FLAG_PHSYNC);
11518 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11519 DRM_MODE_FLAG_NHSYNC);
11520 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11521 DRM_MODE_FLAG_PVSYNC);
11522 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11523 DRM_MODE_FLAG_NVSYNC);
11526 PIPE_CONF_CHECK_X(gmch_pfit.control);
11527 /* pfit ratios are autocomputed by the hw on gen4+ */
11528 if (INTEL_GEN(dev_priv) < 4)
11529 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11530 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11533 PIPE_CONF_CHECK_I(pipe_src_w);
11534 PIPE_CONF_CHECK_I(pipe_src_h);
11536 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11537 if (current_config->pch_pfit.enabled) {
11538 PIPE_CONF_CHECK_X(pch_pfit.pos);
11539 PIPE_CONF_CHECK_X(pch_pfit.size);
11542 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11543 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11546 PIPE_CONF_CHECK_BOOL(double_wide);
11548 PIPE_CONF_CHECK_P(shared_dpll);
11549 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11550 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11551 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11552 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11553 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11554 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11555 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11556 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11557 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11558 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11559 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11560 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11561 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11562 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11563 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11564 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11565 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11566 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11567 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11568 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11569 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11570 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11571 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11572 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11573 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11574 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11575 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11576 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11577 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11578 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11579 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
11581 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11582 PIPE_CONF_CHECK_X(dsi_pll.div);
11584 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11585 PIPE_CONF_CHECK_I(pipe_bpp);
11587 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
11588 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11590 PIPE_CONF_CHECK_I(min_voltage_level);
11592 #undef PIPE_CONF_CHECK_X
11593 #undef PIPE_CONF_CHECK_I
11594 #undef PIPE_CONF_CHECK_BOOL
11595 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11596 #undef PIPE_CONF_CHECK_P
11597 #undef PIPE_CONF_CHECK_FLAGS
11598 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11599 #undef PIPE_CONF_QUIRK
11604 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11605 const struct intel_crtc_state *pipe_config)
11607 if (pipe_config->has_pch_encoder) {
11608 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11609 &pipe_config->fdi_m_n);
11610 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11613 * FDI already provided one idea for the dotclock.
11614 * Yell if the encoder disagrees.
11616 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11617 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11618 fdi_dotclock, dotclock);
11622 static void verify_wm_state(struct drm_crtc *crtc,
11623 struct drm_crtc_state *new_state)
11625 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11626 struct skl_ddb_allocation hw_ddb, *sw_ddb;
11627 struct skl_pipe_wm hw_wm, *sw_wm;
11628 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11629 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11630 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11631 const enum pipe pipe = intel_crtc->pipe;
11632 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11634 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
11637 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
11638 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
11640 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11641 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11643 if (INTEL_GEN(dev_priv) >= 11)
11644 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11645 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11646 sw_ddb->enabled_slices,
11647 hw_ddb.enabled_slices);
11649 for_each_universal_plane(dev_priv, pipe, plane) {
11650 hw_plane_wm = &hw_wm.planes[plane];
11651 sw_plane_wm = &sw_wm->planes[plane];
11654 for (level = 0; level <= max_level; level++) {
11655 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11656 &sw_plane_wm->wm[level]))
11659 DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11660 pipe_name(pipe), plane + 1, level,
11661 sw_plane_wm->wm[level].plane_en,
11662 sw_plane_wm->wm[level].plane_res_b,
11663 sw_plane_wm->wm[level].plane_res_l,
11664 hw_plane_wm->wm[level].plane_en,
11665 hw_plane_wm->wm[level].plane_res_b,
11666 hw_plane_wm->wm[level].plane_res_l);
11669 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11670 &sw_plane_wm->trans_wm)) {
11671 DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11672 pipe_name(pipe), plane + 1,
11673 sw_plane_wm->trans_wm.plane_en,
11674 sw_plane_wm->trans_wm.plane_res_b,
11675 sw_plane_wm->trans_wm.plane_res_l,
11676 hw_plane_wm->trans_wm.plane_en,
11677 hw_plane_wm->trans_wm.plane_res_b,
11678 hw_plane_wm->trans_wm.plane_res_l);
11682 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11683 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11685 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11686 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11687 pipe_name(pipe), plane + 1,
11688 sw_ddb_entry->start, sw_ddb_entry->end,
11689 hw_ddb_entry->start, hw_ddb_entry->end);
11695 * If the cursor plane isn't active, we may not have updated it's ddb
11696 * allocation. In that case since the ddb allocation will be updated
11697 * once the plane becomes visible, we can skip this check
11700 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11701 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
11704 for (level = 0; level <= max_level; level++) {
11705 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11706 &sw_plane_wm->wm[level]))
11709 DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11710 pipe_name(pipe), level,
11711 sw_plane_wm->wm[level].plane_en,
11712 sw_plane_wm->wm[level].plane_res_b,
11713 sw_plane_wm->wm[level].plane_res_l,
11714 hw_plane_wm->wm[level].plane_en,
11715 hw_plane_wm->wm[level].plane_res_b,
11716 hw_plane_wm->wm[level].plane_res_l);
11719 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11720 &sw_plane_wm->trans_wm)) {
11721 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11723 sw_plane_wm->trans_wm.plane_en,
11724 sw_plane_wm->trans_wm.plane_res_b,
11725 sw_plane_wm->trans_wm.plane_res_l,
11726 hw_plane_wm->trans_wm.plane_en,
11727 hw_plane_wm->trans_wm.plane_res_b,
11728 hw_plane_wm->trans_wm.plane_res_l);
11732 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11733 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11735 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11736 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11738 sw_ddb_entry->start, sw_ddb_entry->end,
11739 hw_ddb_entry->start, hw_ddb_entry->end);
11745 verify_connector_state(struct drm_device *dev,
11746 struct drm_atomic_state *state,
11747 struct drm_crtc *crtc)
11749 struct drm_connector *connector;
11750 struct drm_connector_state *new_conn_state;
11753 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
11754 struct drm_encoder *encoder = connector->encoder;
11755 struct drm_crtc_state *crtc_state = NULL;
11757 if (new_conn_state->crtc != crtc)
11761 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11763 intel_connector_verify_state(crtc_state, new_conn_state);
11765 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
11766 "connector's atomic encoder doesn't match legacy encoder\n");
11771 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
11773 struct intel_encoder *encoder;
11774 struct drm_connector *connector;
11775 struct drm_connector_state *old_conn_state, *new_conn_state;
11778 for_each_intel_encoder(dev, encoder) {
11779 bool enabled = false, found = false;
11782 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11783 encoder->base.base.id,
11784 encoder->base.name);
11786 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
11787 new_conn_state, i) {
11788 if (old_conn_state->best_encoder == &encoder->base)
11791 if (new_conn_state->best_encoder != &encoder->base)
11793 found = enabled = true;
11795 I915_STATE_WARN(new_conn_state->crtc !=
11796 encoder->base.crtc,
11797 "connector's crtc doesn't match encoder crtc\n");
11803 I915_STATE_WARN(!!encoder->base.crtc != enabled,
11804 "encoder's enabled state mismatch "
11805 "(expected %i, found %i)\n",
11806 !!encoder->base.crtc, enabled);
11808 if (!encoder->base.crtc) {
11811 active = encoder->get_hw_state(encoder, &pipe);
11812 I915_STATE_WARN(active,
11813 "encoder detached but still enabled on pipe %c.\n",
11820 verify_crtc_state(struct drm_crtc *crtc,
11821 struct drm_crtc_state *old_crtc_state,
11822 struct drm_crtc_state *new_crtc_state)
11824 struct drm_device *dev = crtc->dev;
11825 struct drm_i915_private *dev_priv = to_i915(dev);
11826 struct intel_encoder *encoder;
11827 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11828 struct intel_crtc_state *pipe_config, *sw_config;
11829 struct drm_atomic_state *old_state;
11832 old_state = old_crtc_state->state;
11833 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
11834 pipe_config = to_intel_crtc_state(old_crtc_state);
11835 memset(pipe_config, 0, sizeof(*pipe_config));
11836 pipe_config->base.crtc = crtc;
11837 pipe_config->base.state = old_state;
11839 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
11841 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
11843 /* we keep both pipes enabled on 830 */
11844 if (IS_I830(dev_priv))
11845 active = new_crtc_state->active;
11847 I915_STATE_WARN(new_crtc_state->active != active,
11848 "crtc active state doesn't match with hw state "
11849 "(expected %i, found %i)\n", new_crtc_state->active, active);
11851 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
11852 "transitional active state does not match atomic hw state "
11853 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
11855 for_each_encoder_on_crtc(dev, crtc, encoder) {
11858 active = encoder->get_hw_state(encoder, &pipe);
11859 I915_STATE_WARN(active != new_crtc_state->active,
11860 "[ENCODER:%i] active %i with crtc active %i\n",
11861 encoder->base.base.id, active, new_crtc_state->active);
11863 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
11864 "Encoder connected to wrong pipe %c\n",
11868 encoder->get_config(encoder, pipe_config);
11871 intel_crtc_compute_pixel_rate(pipe_config);
11873 if (!new_crtc_state->active)
11876 intel_pipe_config_sanity_check(dev_priv, pipe_config);
11878 sw_config = to_intel_crtc_state(new_crtc_state);
11879 if (!intel_pipe_config_compare(dev_priv, sw_config,
11880 pipe_config, false)) {
11881 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11882 intel_dump_pipe_config(intel_crtc, pipe_config,
11884 intel_dump_pipe_config(intel_crtc, sw_config,
11890 intel_verify_planes(struct intel_atomic_state *state)
11892 struct intel_plane *plane;
11893 const struct intel_plane_state *plane_state;
11896 for_each_new_intel_plane_in_state(state, plane,
11898 assert_plane(plane, plane_state->base.visible);
11902 verify_single_dpll_state(struct drm_i915_private *dev_priv,
11903 struct intel_shared_dpll *pll,
11904 struct drm_crtc *crtc,
11905 struct drm_crtc_state *new_state)
11907 struct intel_dpll_hw_state dpll_hw_state;
11908 unsigned int crtc_mask;
11911 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
11913 DRM_DEBUG_KMS("%s\n", pll->info->name);
11915 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
11917 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
11918 I915_STATE_WARN(!pll->on && pll->active_mask,
11919 "pll in active use but not on in sw tracking\n");
11920 I915_STATE_WARN(pll->on && !pll->active_mask,
11921 "pll is on but not used by any active crtc\n");
11922 I915_STATE_WARN(pll->on != active,
11923 "pll on state mismatch (expected %i, found %i)\n",
11928 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
11929 "more active pll users than references: %x vs %x\n",
11930 pll->active_mask, pll->state.crtc_mask);
11935 crtc_mask = drm_crtc_mask(crtc);
11937 if (new_state->active)
11938 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
11939 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11940 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11942 I915_STATE_WARN(pll->active_mask & crtc_mask,
11943 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11944 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11946 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
11947 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11948 crtc_mask, pll->state.crtc_mask);
11950 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
11952 sizeof(dpll_hw_state)),
11953 "pll hw state mismatch\n");
11957 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
11958 struct drm_crtc_state *old_crtc_state,
11959 struct drm_crtc_state *new_crtc_state)
11961 struct drm_i915_private *dev_priv = to_i915(dev);
11962 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
11963 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
11965 if (new_state->shared_dpll)
11966 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
11968 if (old_state->shared_dpll &&
11969 old_state->shared_dpll != new_state->shared_dpll) {
11970 unsigned int crtc_mask = drm_crtc_mask(crtc);
11971 struct intel_shared_dpll *pll = old_state->shared_dpll;
11973 I915_STATE_WARN(pll->active_mask & crtc_mask,
11974 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11975 pipe_name(drm_crtc_index(crtc)));
11976 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
11977 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11978 pipe_name(drm_crtc_index(crtc)));
11983 intel_modeset_verify_crtc(struct drm_crtc *crtc,
11984 struct drm_atomic_state *state,
11985 struct drm_crtc_state *old_state,
11986 struct drm_crtc_state *new_state)
11988 if (!needs_modeset(new_state) &&
11989 !to_intel_crtc_state(new_state)->update_pipe)
11992 verify_wm_state(crtc, new_state);
11993 verify_connector_state(crtc->dev, state, crtc);
11994 verify_crtc_state(crtc, old_state, new_state);
11995 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
11999 verify_disabled_dpll_state(struct drm_device *dev)
12001 struct drm_i915_private *dev_priv = to_i915(dev);
12004 for (i = 0; i < dev_priv->num_shared_dpll; i++)
12005 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
12009 intel_modeset_verify_disabled(struct drm_device *dev,
12010 struct drm_atomic_state *state)
12012 verify_encoder_state(dev, state);
12013 verify_connector_state(dev, state, NULL);
12014 verify_disabled_dpll_state(dev);
12017 static void update_scanline_offset(struct intel_crtc *crtc)
12019 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12022 * The scanline counter increments at the leading edge of hsync.
12024 * On most platforms it starts counting from vtotal-1 on the
12025 * first active line. That means the scanline counter value is
12026 * always one less than what we would expect. Ie. just after
12027 * start of vblank, which also occurs at start of hsync (on the
12028 * last active line), the scanline counter will read vblank_start-1.
12030 * On gen2 the scanline counter starts counting from 1 instead
12031 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12032 * to keep the value positive), instead of adding one.
12034 * On HSW+ the behaviour of the scanline counter depends on the output
12035 * type. For DP ports it behaves like most other platforms, but on HDMI
12036 * there's an extra 1 line difference. So we need to add two instead of
12037 * one to the value.
12039 * On VLV/CHV DSI the scanline counter would appear to increment
12040 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12041 * that means we can't tell whether we're in vblank or not while
12042 * we're on that particular line. We must still set scanline_offset
12043 * to 1 so that the vblank timestamps come out correct when we query
12044 * the scanline counter from within the vblank interrupt handler.
12045 * However if queried just before the start of vblank we'll get an
12046 * answer that's slightly in the future.
12048 if (IS_GEN2(dev_priv)) {
12049 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
12052 vtotal = adjusted_mode->crtc_vtotal;
12053 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
12056 crtc->scanline_offset = vtotal - 1;
12057 } else if (HAS_DDI(dev_priv) &&
12058 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) {
12059 crtc->scanline_offset = 2;
12061 crtc->scanline_offset = 1;
12064 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
12066 struct drm_device *dev = state->dev;
12067 struct drm_i915_private *dev_priv = to_i915(dev);
12068 struct drm_crtc *crtc;
12069 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12072 if (!dev_priv->display.crtc_compute_clock)
12075 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12076 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12077 struct intel_shared_dpll *old_dpll =
12078 to_intel_crtc_state(old_crtc_state)->shared_dpll;
12080 if (!needs_modeset(new_crtc_state))
12083 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
12088 intel_release_shared_dpll(old_dpll, intel_crtc, state);
12093 * This implements the workaround described in the "notes" section of the mode
12094 * set sequence documentation. When going from no pipes or single pipe to
12095 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12096 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12098 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12100 struct drm_crtc_state *crtc_state;
12101 struct intel_crtc *intel_crtc;
12102 struct drm_crtc *crtc;
12103 struct intel_crtc_state *first_crtc_state = NULL;
12104 struct intel_crtc_state *other_crtc_state = NULL;
12105 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12108 /* look at all crtc's that are going to be enabled in during modeset */
12109 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
12110 intel_crtc = to_intel_crtc(crtc);
12112 if (!crtc_state->active || !needs_modeset(crtc_state))
12115 if (first_crtc_state) {
12116 other_crtc_state = to_intel_crtc_state(crtc_state);
12119 first_crtc_state = to_intel_crtc_state(crtc_state);
12120 first_pipe = intel_crtc->pipe;
12124 /* No workaround needed? */
12125 if (!first_crtc_state)
12128 /* w/a possibly needed, check how many crtc's are already enabled. */
12129 for_each_intel_crtc(state->dev, intel_crtc) {
12130 struct intel_crtc_state *pipe_config;
12132 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12133 if (IS_ERR(pipe_config))
12134 return PTR_ERR(pipe_config);
12136 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12138 if (!pipe_config->base.active ||
12139 needs_modeset(&pipe_config->base))
12142 /* 2 or more enabled crtcs means no need for w/a */
12143 if (enabled_pipe != INVALID_PIPE)
12146 enabled_pipe = intel_crtc->pipe;
12149 if (enabled_pipe != INVALID_PIPE)
12150 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12151 else if (other_crtc_state)
12152 other_crtc_state->hsw_workaround_pipe = first_pipe;
12157 static int intel_lock_all_pipes(struct drm_atomic_state *state)
12159 struct drm_crtc *crtc;
12161 /* Add all pipes to the state */
12162 for_each_crtc(state->dev, crtc) {
12163 struct drm_crtc_state *crtc_state;
12165 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12166 if (IS_ERR(crtc_state))
12167 return PTR_ERR(crtc_state);
12173 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12175 struct drm_crtc *crtc;
12178 * Add all pipes to the state, and force
12179 * a modeset on all the active ones.
12181 for_each_crtc(state->dev, crtc) {
12182 struct drm_crtc_state *crtc_state;
12185 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12186 if (IS_ERR(crtc_state))
12187 return PTR_ERR(crtc_state);
12189 if (!crtc_state->active || needs_modeset(crtc_state))
12192 crtc_state->mode_changed = true;
12194 ret = drm_atomic_add_affected_connectors(state, crtc);
12198 ret = drm_atomic_add_affected_planes(state, crtc);
12206 static int intel_modeset_checks(struct drm_atomic_state *state)
12208 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12209 struct drm_i915_private *dev_priv = to_i915(state->dev);
12210 struct drm_crtc *crtc;
12211 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12214 if (!check_digital_port_conflicts(state)) {
12215 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12219 intel_state->modeset = true;
12220 intel_state->active_crtcs = dev_priv->active_crtcs;
12221 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12222 intel_state->cdclk.actual = dev_priv->cdclk.actual;
12224 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12225 if (new_crtc_state->active)
12226 intel_state->active_crtcs |= 1 << i;
12228 intel_state->active_crtcs &= ~(1 << i);
12230 if (old_crtc_state->active != new_crtc_state->active)
12231 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
12235 * See if the config requires any additional preparation, e.g.
12236 * to adjust global state with pipes off. We need to do this
12237 * here so we can get the modeset_pipe updated config for the new
12238 * mode set on this crtc. For other crtcs we need to use the
12239 * adjusted_mode bits in the crtc directly.
12241 if (dev_priv->display.modeset_calc_cdclk) {
12242 ret = dev_priv->display.modeset_calc_cdclk(state);
12247 * Writes to dev_priv->cdclk.logical must protected by
12248 * holding all the crtc locks, even if we don't end up
12249 * touching the hardware
12251 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12252 &intel_state->cdclk.logical)) {
12253 ret = intel_lock_all_pipes(state);
12258 /* All pipes must be switched off while we change the cdclk. */
12259 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12260 &intel_state->cdclk.actual)) {
12261 ret = intel_modeset_all_pipes(state);
12266 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12267 intel_state->cdclk.logical.cdclk,
12268 intel_state->cdclk.actual.cdclk);
12269 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12270 intel_state->cdclk.logical.voltage_level,
12271 intel_state->cdclk.actual.voltage_level);
12273 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12276 intel_modeset_clear_plls(state);
12278 if (IS_HASWELL(dev_priv))
12279 return haswell_mode_set_planes_workaround(state);
12285 * Handle calculation of various watermark data at the end of the atomic check
12286 * phase. The code here should be run after the per-crtc and per-plane 'check'
12287 * handlers to ensure that all derived state has been updated.
12289 static int calc_watermark_data(struct drm_atomic_state *state)
12291 struct drm_device *dev = state->dev;
12292 struct drm_i915_private *dev_priv = to_i915(dev);
12294 /* Is there platform-specific watermark information to calculate? */
12295 if (dev_priv->display.compute_global_watermarks)
12296 return dev_priv->display.compute_global_watermarks(state);
12302 * intel_atomic_check - validate state object
12304 * @state: state to validate
12306 static int intel_atomic_check(struct drm_device *dev,
12307 struct drm_atomic_state *state)
12309 struct drm_i915_private *dev_priv = to_i915(dev);
12310 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12311 struct drm_crtc *crtc;
12312 struct drm_crtc_state *old_crtc_state, *crtc_state;
12314 bool any_ms = false;
12316 /* Catch I915_MODE_FLAG_INHERITED */
12317 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12319 if (crtc_state->mode.private_flags !=
12320 old_crtc_state->mode.private_flags)
12321 crtc_state->mode_changed = true;
12324 ret = drm_atomic_helper_check_modeset(dev, state);
12328 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12329 struct intel_crtc_state *pipe_config =
12330 to_intel_crtc_state(crtc_state);
12332 if (!needs_modeset(crtc_state))
12335 if (!crtc_state->enable) {
12340 ret = intel_modeset_pipe_config(crtc, pipe_config);
12342 intel_dump_pipe_config(to_intel_crtc(crtc),
12343 pipe_config, "[failed]");
12347 if (i915_modparams.fastboot &&
12348 intel_pipe_config_compare(dev_priv,
12349 to_intel_crtc_state(old_crtc_state),
12350 pipe_config, true)) {
12351 crtc_state->mode_changed = false;
12352 pipe_config->update_pipe = true;
12355 if (needs_modeset(crtc_state))
12358 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12359 needs_modeset(crtc_state) ?
12360 "[modeset]" : "[fastset]");
12364 ret = intel_modeset_checks(state);
12369 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12372 ret = drm_atomic_helper_check_planes(dev, state);
12376 intel_fbc_choose_crtc(dev_priv, intel_state);
12377 return calc_watermark_data(state);
12380 static int intel_atomic_prepare_commit(struct drm_device *dev,
12381 struct drm_atomic_state *state)
12383 return drm_atomic_helper_prepare_planes(dev, state);
12386 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12388 struct drm_device *dev = crtc->base.dev;
12390 if (!dev->max_vblank_count)
12391 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
12393 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12396 static void intel_update_crtc(struct drm_crtc *crtc,
12397 struct drm_atomic_state *state,
12398 struct drm_crtc_state *old_crtc_state,
12399 struct drm_crtc_state *new_crtc_state)
12401 struct drm_device *dev = crtc->dev;
12402 struct drm_i915_private *dev_priv = to_i915(dev);
12403 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12404 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12405 bool modeset = needs_modeset(new_crtc_state);
12406 struct intel_plane_state *new_plane_state =
12407 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12408 to_intel_plane(crtc->primary));
12411 update_scanline_offset(intel_crtc);
12412 dev_priv->display.crtc_enable(pipe_config, state);
12414 /* vblanks work again, re-enable pipe CRC. */
12415 intel_crtc_enable_pipe_crc(intel_crtc);
12417 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12421 if (new_plane_state)
12422 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
12424 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state);
12427 static void intel_update_crtcs(struct drm_atomic_state *state)
12429 struct drm_crtc *crtc;
12430 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12433 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12434 if (!new_crtc_state->active)
12437 intel_update_crtc(crtc, state, old_crtc_state,
12442 static void skl_update_crtcs(struct drm_atomic_state *state)
12444 struct drm_i915_private *dev_priv = to_i915(state->dev);
12445 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12446 struct drm_crtc *crtc;
12447 struct intel_crtc *intel_crtc;
12448 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12449 struct intel_crtc_state *cstate;
12450 unsigned int updated = 0;
12454 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12455 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
12457 const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
12459 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
12460 /* ignore allocations for crtc's that have been turned off. */
12461 if (new_crtc_state->active)
12462 entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
12464 /* If 2nd DBuf slice required, enable it here */
12465 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12466 icl_dbuf_slices_update(dev_priv, required_slices);
12469 * Whenever the number of active pipes changes, we need to make sure we
12470 * update the pipes in the right order so that their ddb allocations
12471 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12472 * cause pipe underruns and other bad stuff.
12477 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12478 bool vbl_wait = false;
12479 unsigned int cmask = drm_crtc_mask(crtc);
12481 intel_crtc = to_intel_crtc(crtc);
12482 cstate = to_intel_crtc_state(new_crtc_state);
12483 pipe = intel_crtc->pipe;
12485 if (updated & cmask || !cstate->base.active)
12488 if (skl_ddb_allocation_overlaps(dev_priv,
12490 &cstate->wm.skl.ddb,
12495 entries[i] = &cstate->wm.skl.ddb;
12498 * If this is an already active pipe, it's DDB changed,
12499 * and this isn't the last pipe that needs updating
12500 * then we need to wait for a vblank to pass for the
12501 * new ddb allocation to take effect.
12503 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
12504 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
12505 !new_crtc_state->active_changed &&
12506 intel_state->wm_results.dirty_pipes != updated)
12509 intel_update_crtc(crtc, state, old_crtc_state,
12513 intel_wait_for_vblank(dev_priv, pipe);
12517 } while (progress);
12519 /* If 2nd DBuf slice is no more required disable it */
12520 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12521 icl_dbuf_slices_update(dev_priv, required_slices);
12524 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12526 struct intel_atomic_state *state, *next;
12527 struct llist_node *freed;
12529 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12530 llist_for_each_entry_safe(state, next, freed, freed)
12531 drm_atomic_state_put(&state->base);
12534 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12536 struct drm_i915_private *dev_priv =
12537 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12539 intel_atomic_helper_free_state(dev_priv);
12542 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12544 struct wait_queue_entry wait_fence, wait_reset;
12545 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12547 init_wait_entry(&wait_fence, 0);
12548 init_wait_entry(&wait_reset, 0);
12550 prepare_to_wait(&intel_state->commit_ready.wait,
12551 &wait_fence, TASK_UNINTERRUPTIBLE);
12552 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12553 &wait_reset, TASK_UNINTERRUPTIBLE);
12556 if (i915_sw_fence_done(&intel_state->commit_ready)
12557 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12562 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12563 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12566 static void intel_atomic_cleanup_work(struct work_struct *work)
12568 struct drm_atomic_state *state =
12569 container_of(work, struct drm_atomic_state, commit_work);
12570 struct drm_i915_private *i915 = to_i915(state->dev);
12572 drm_atomic_helper_cleanup_planes(&i915->drm, state);
12573 drm_atomic_helper_commit_cleanup_done(state);
12574 drm_atomic_state_put(state);
12576 intel_atomic_helper_free_state(i915);
12579 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
12581 struct drm_device *dev = state->dev;
12582 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12583 struct drm_i915_private *dev_priv = to_i915(dev);
12584 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12585 struct drm_crtc *crtc;
12586 struct intel_crtc_state *intel_cstate;
12587 u64 put_domains[I915_MAX_PIPES] = {};
12590 intel_atomic_commit_fence_wait(intel_state);
12592 drm_atomic_helper_wait_for_dependencies(state);
12594 if (intel_state->modeset)
12595 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
12597 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12598 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12600 if (needs_modeset(new_crtc_state) ||
12601 to_intel_crtc_state(new_crtc_state)->update_pipe) {
12603 put_domains[to_intel_crtc(crtc)->pipe] =
12604 modeset_get_crtc_power_domains(crtc,
12605 to_intel_crtc_state(new_crtc_state));
12608 if (!needs_modeset(new_crtc_state))
12611 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12612 to_intel_crtc_state(new_crtc_state));
12614 if (old_crtc_state->active) {
12615 intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask);
12618 * We need to disable pipe CRC before disabling the pipe,
12619 * or we race against vblank off.
12621 intel_crtc_disable_pipe_crc(intel_crtc);
12623 dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state);
12624 intel_crtc->active = false;
12625 intel_fbc_disable(intel_crtc);
12626 intel_disable_shared_dpll(intel_crtc);
12629 * Underruns don't always raise
12630 * interrupts, so check manually.
12632 intel_check_cpu_fifo_underruns(dev_priv);
12633 intel_check_pch_fifo_underruns(dev_priv);
12635 if (!new_crtc_state->active) {
12637 * Make sure we don't call initial_watermarks
12638 * for ILK-style watermark updates.
12640 * No clue what this is supposed to achieve.
12642 if (INTEL_GEN(dev_priv) >= 9)
12643 dev_priv->display.initial_watermarks(intel_state,
12644 to_intel_crtc_state(new_crtc_state));
12649 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12650 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12651 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
12653 if (intel_state->modeset) {
12654 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12656 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
12659 * SKL workaround: bspec recommends we disable the SAGV when we
12660 * have more then one pipe enabled
12662 if (!intel_can_enable_sagv(state))
12663 intel_disable_sagv(dev_priv);
12665 intel_modeset_verify_disabled(dev, state);
12668 /* Complete the events for pipes that have now been disabled */
12669 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12670 bool modeset = needs_modeset(new_crtc_state);
12672 /* Complete events for now disable pipes here. */
12673 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
12674 spin_lock_irq(&dev->event_lock);
12675 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
12676 spin_unlock_irq(&dev->event_lock);
12678 new_crtc_state->event = NULL;
12682 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12683 dev_priv->display.update_crtcs(state);
12685 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12686 * already, but still need the state for the delayed optimization. To
12688 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12689 * - schedule that vblank worker _before_ calling hw_done
12690 * - at the start of commit_tail, cancel it _synchrously
12691 * - switch over to the vblank wait helper in the core after that since
12692 * we don't need out special handling any more.
12694 drm_atomic_helper_wait_for_flip_done(dev, state);
12697 * Now that the vblank has passed, we can go ahead and program the
12698 * optimal watermarks on platforms that need two-step watermark
12701 * TODO: Move this (and other cleanup) to an async worker eventually.
12703 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12704 intel_cstate = to_intel_crtc_state(new_crtc_state);
12706 if (dev_priv->display.optimize_watermarks)
12707 dev_priv->display.optimize_watermarks(intel_state,
12711 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12712 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12714 if (put_domains[i])
12715 modeset_put_power_domains(dev_priv, put_domains[i]);
12717 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
12720 if (intel_state->modeset)
12721 intel_verify_planes(intel_state);
12723 if (intel_state->modeset && intel_can_enable_sagv(state))
12724 intel_enable_sagv(dev_priv);
12726 drm_atomic_helper_commit_hw_done(state);
12728 if (intel_state->modeset) {
12729 /* As one of the primary mmio accessors, KMS has a high
12730 * likelihood of triggering bugs in unclaimed access. After we
12731 * finish modesetting, see if an error has been flagged, and if
12732 * so enable debugging for the next modeset - and hope we catch
12735 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
12736 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
12740 * Defer the cleanup of the old state to a separate worker to not
12741 * impede the current task (userspace for blocking modesets) that
12742 * are executed inline. For out-of-line asynchronous modesets/flips,
12743 * deferring to a new worker seems overkill, but we would place a
12744 * schedule point (cond_resched()) here anyway to keep latencies
12747 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
12748 queue_work(system_highpri_wq, &state->commit_work);
12751 static void intel_atomic_commit_work(struct work_struct *work)
12753 struct drm_atomic_state *state =
12754 container_of(work, struct drm_atomic_state, commit_work);
12756 intel_atomic_commit_tail(state);
12759 static int __i915_sw_fence_call
12760 intel_atomic_commit_ready(struct i915_sw_fence *fence,
12761 enum i915_sw_fence_notify notify)
12763 struct intel_atomic_state *state =
12764 container_of(fence, struct intel_atomic_state, commit_ready);
12767 case FENCE_COMPLETE:
12768 /* we do blocking waits in the worker, nothing to do here */
12772 struct intel_atomic_helper *helper =
12773 &to_i915(state->base.dev)->atomic_helper;
12775 if (llist_add(&state->freed, &helper->free_list))
12776 schedule_work(&helper->free_work);
12781 return NOTIFY_DONE;
12784 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
12786 struct drm_plane_state *old_plane_state, *new_plane_state;
12787 struct drm_plane *plane;
12790 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
12791 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
12792 intel_fb_obj(new_plane_state->fb),
12793 to_intel_plane(plane)->frontbuffer_bit);
12797 * intel_atomic_commit - commit validated state object
12799 * @state: the top-level driver state object
12800 * @nonblock: nonblocking commit
12802 * This function commits a top-level state object that has been validated
12803 * with drm_atomic_helper_check().
12806 * Zero for success or -errno.
12808 static int intel_atomic_commit(struct drm_device *dev,
12809 struct drm_atomic_state *state,
12812 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12813 struct drm_i915_private *dev_priv = to_i915(dev);
12816 drm_atomic_state_get(state);
12817 i915_sw_fence_init(&intel_state->commit_ready,
12818 intel_atomic_commit_ready);
12821 * The intel_legacy_cursor_update() fast path takes care
12822 * of avoiding the vblank waits for simple cursor
12823 * movement and flips. For cursor on/off and size changes,
12824 * we want to perform the vblank waits so that watermark
12825 * updates happen during the correct frames. Gen9+ have
12826 * double buffered watermarks and so shouldn't need this.
12828 * Unset state->legacy_cursor_update before the call to
12829 * drm_atomic_helper_setup_commit() because otherwise
12830 * drm_atomic_helper_wait_for_flip_done() is a noop and
12831 * we get FIFO underruns because we didn't wait
12834 * FIXME doing watermarks and fb cleanup from a vblank worker
12835 * (assuming we had any) would solve these problems.
12837 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
12838 struct intel_crtc_state *new_crtc_state;
12839 struct intel_crtc *crtc;
12842 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
12843 if (new_crtc_state->wm.need_postvbl_update ||
12844 new_crtc_state->update_wm_post)
12845 state->legacy_cursor_update = false;
12848 ret = intel_atomic_prepare_commit(dev, state);
12850 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
12851 i915_sw_fence_commit(&intel_state->commit_ready);
12855 ret = drm_atomic_helper_setup_commit(state, nonblock);
12857 ret = drm_atomic_helper_swap_state(state, true);
12860 i915_sw_fence_commit(&intel_state->commit_ready);
12862 drm_atomic_helper_cleanup_planes(dev, state);
12865 dev_priv->wm.distrust_bios_wm = false;
12866 intel_shared_dpll_swap_state(state);
12867 intel_atomic_track_fbs(state);
12869 if (intel_state->modeset) {
12870 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
12871 sizeof(intel_state->min_cdclk));
12872 memcpy(dev_priv->min_voltage_level,
12873 intel_state->min_voltage_level,
12874 sizeof(intel_state->min_voltage_level));
12875 dev_priv->active_crtcs = intel_state->active_crtcs;
12876 dev_priv->cdclk.logical = intel_state->cdclk.logical;
12877 dev_priv->cdclk.actual = intel_state->cdclk.actual;
12880 drm_atomic_state_get(state);
12881 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
12883 i915_sw_fence_commit(&intel_state->commit_ready);
12884 if (nonblock && intel_state->modeset) {
12885 queue_work(dev_priv->modeset_wq, &state->commit_work);
12886 } else if (nonblock) {
12887 queue_work(system_unbound_wq, &state->commit_work);
12889 if (intel_state->modeset)
12890 flush_workqueue(dev_priv->modeset_wq);
12891 intel_atomic_commit_tail(state);
12897 static const struct drm_crtc_funcs intel_crtc_funcs = {
12898 .gamma_set = drm_atomic_helper_legacy_gamma_set,
12899 .set_config = drm_atomic_helper_set_config,
12900 .destroy = intel_crtc_destroy,
12901 .page_flip = drm_atomic_helper_page_flip,
12902 .atomic_duplicate_state = intel_crtc_duplicate_state,
12903 .atomic_destroy_state = intel_crtc_destroy_state,
12904 .set_crc_source = intel_crtc_set_crc_source,
12905 .verify_crc_source = intel_crtc_verify_crc_source,
12906 .get_crc_sources = intel_crtc_get_crc_sources,
12909 struct wait_rps_boost {
12910 struct wait_queue_entry wait;
12912 struct drm_crtc *crtc;
12913 struct i915_request *request;
12916 static int do_rps_boost(struct wait_queue_entry *_wait,
12917 unsigned mode, int sync, void *key)
12919 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
12920 struct i915_request *rq = wait->request;
12923 * If we missed the vblank, but the request is already running it
12924 * is reasonable to assume that it will complete before the next
12925 * vblank without our intervention, so leave RPS alone.
12927 if (!i915_request_started(rq))
12928 gen6_rps_boost(rq, NULL);
12929 i915_request_put(rq);
12931 drm_crtc_vblank_put(wait->crtc);
12933 list_del(&wait->wait.entry);
12938 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
12939 struct dma_fence *fence)
12941 struct wait_rps_boost *wait;
12943 if (!dma_fence_is_i915(fence))
12946 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
12949 if (drm_crtc_vblank_get(crtc))
12952 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
12954 drm_crtc_vblank_put(crtc);
12958 wait->request = to_request(dma_fence_get(fence));
12961 wait->wait.func = do_rps_boost;
12962 wait->wait.flags = 0;
12964 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
12967 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
12969 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
12970 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
12971 struct drm_framebuffer *fb = plane_state->base.fb;
12972 struct i915_vma *vma;
12974 if (plane->id == PLANE_CURSOR &&
12975 INTEL_INFO(dev_priv)->cursor_needs_physical) {
12976 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12977 const int align = intel_cursor_alignment(dev_priv);
12980 err = i915_gem_object_attach_phys(obj, align);
12985 vma = intel_pin_and_fence_fb_obj(fb,
12986 plane_state->base.rotation,
12987 intel_plane_uses_fence(plane_state),
12988 &plane_state->flags);
12990 return PTR_ERR(vma);
12992 plane_state->vma = vma;
12997 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
12999 struct i915_vma *vma;
13001 vma = fetch_and_zero(&old_plane_state->vma);
13003 intel_unpin_fb_vma(vma, old_plane_state->flags);
13006 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13008 struct i915_sched_attr attr = {
13009 .priority = I915_PRIORITY_DISPLAY,
13012 i915_gem_object_wait_priority(obj, 0, &attr);
13016 * intel_prepare_plane_fb - Prepare fb for usage on plane
13017 * @plane: drm plane to prepare for
13018 * @new_state: the plane state being prepared
13020 * Prepares a framebuffer for usage on a display plane. Generally this
13021 * involves pinning the underlying object and updating the frontbuffer tracking
13022 * bits. Some older platforms need special physical address handling for
13025 * Must be called with struct_mutex held.
13027 * Returns 0 on success, negative error code on failure.
13030 intel_prepare_plane_fb(struct drm_plane *plane,
13031 struct drm_plane_state *new_state)
13033 struct intel_atomic_state *intel_state =
13034 to_intel_atomic_state(new_state->state);
13035 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13036 struct drm_framebuffer *fb = new_state->fb;
13037 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13038 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
13042 struct drm_crtc_state *crtc_state =
13043 drm_atomic_get_new_crtc_state(new_state->state,
13044 plane->state->crtc);
13046 /* Big Hammer, we also need to ensure that any pending
13047 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13048 * current scanout is retired before unpinning the old
13049 * framebuffer. Note that we rely on userspace rendering
13050 * into the buffer attached to the pipe they are waiting
13051 * on. If not, userspace generates a GPU hang with IPEHR
13052 * point to the MI_WAIT_FOR_EVENT.
13054 * This should only fail upon a hung GPU, in which case we
13055 * can safely continue.
13057 if (needs_modeset(crtc_state)) {
13058 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13059 old_obj->resv, NULL,
13067 if (new_state->fence) { /* explicit fencing */
13068 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13070 I915_FENCE_TIMEOUT,
13079 ret = i915_gem_object_pin_pages(obj);
13083 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13085 i915_gem_object_unpin_pages(obj);
13089 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
13091 fb_obj_bump_render_priority(obj);
13093 mutex_unlock(&dev_priv->drm.struct_mutex);
13094 i915_gem_object_unpin_pages(obj);
13098 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13100 if (!new_state->fence) { /* implicit fencing */
13101 struct dma_fence *fence;
13103 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13105 false, I915_FENCE_TIMEOUT,
13110 fence = reservation_object_get_excl_rcu(obj->resv);
13112 add_rps_boost_after_vblank(new_state->crtc, fence);
13113 dma_fence_put(fence);
13116 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
13120 * We declare pageflips to be interactive and so merit a small bias
13121 * towards upclocking to deliver the frame on time. By only changing
13122 * the RPS thresholds to sample more regularly and aim for higher
13123 * clocks we can hopefully deliver low power workloads (like kodi)
13124 * that are not quite steady state without resorting to forcing
13125 * maximum clocks following a vblank miss (see do_rps_boost()).
13127 if (!intel_state->rps_interactive) {
13128 intel_rps_mark_interactive(dev_priv, true);
13129 intel_state->rps_interactive = true;
13136 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13137 * @plane: drm plane to clean up for
13138 * @old_state: the state from the previous modeset
13140 * Cleans up a framebuffer that has just been removed from a plane.
13142 * Must be called with struct_mutex held.
13145 intel_cleanup_plane_fb(struct drm_plane *plane,
13146 struct drm_plane_state *old_state)
13148 struct intel_atomic_state *intel_state =
13149 to_intel_atomic_state(old_state->state);
13150 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13152 if (intel_state->rps_interactive) {
13153 intel_rps_mark_interactive(dev_priv, false);
13154 intel_state->rps_interactive = false;
13157 /* Should only be called after a successful intel_prepare_plane_fb()! */
13158 mutex_lock(&dev_priv->drm.struct_mutex);
13159 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13160 mutex_unlock(&dev_priv->drm.struct_mutex);
13164 skl_max_scale(struct intel_crtc *intel_crtc,
13165 struct intel_crtc_state *crtc_state,
13166 uint32_t pixel_format)
13168 struct drm_i915_private *dev_priv;
13169 int max_scale, mult;
13170 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
13172 if (!intel_crtc || !crtc_state->base.enable)
13173 return DRM_PLANE_HELPER_NO_SCALING;
13175 dev_priv = to_i915(intel_crtc->base.dev);
13177 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13178 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13180 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
13183 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
13184 return DRM_PLANE_HELPER_NO_SCALING;
13187 * skl max scale is lower of:
13188 * close to 3 but not 3, -1 is for that purpose
13192 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13193 tmpclk1 = (1 << 16) * mult - 1;
13194 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13195 max_scale = min(tmpclk1, tmpclk2);
13201 intel_check_primary_plane(struct intel_crtc_state *crtc_state,
13202 struct intel_plane_state *state)
13204 struct intel_plane *plane = to_intel_plane(state->base.plane);
13205 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13206 struct drm_crtc *crtc = state->base.crtc;
13207 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
13208 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
13209 bool can_position = false;
13211 uint32_t pixel_format = 0;
13213 if (INTEL_GEN(dev_priv) >= 9) {
13214 /* use scaler when colorkey is not required */
13215 if (!state->ckey.flags) {
13217 if (state->base.fb)
13218 pixel_format = state->base.fb->format->format;
13219 max_scale = skl_max_scale(to_intel_crtc(crtc),
13220 crtc_state, pixel_format);
13222 can_position = true;
13225 ret = drm_atomic_helper_check_plane_state(&state->base,
13227 min_scale, max_scale,
13228 can_position, true);
13232 if (!state->base.fb)
13235 if (INTEL_GEN(dev_priv) >= 9) {
13236 ret = skl_check_plane_surface(crtc_state, state);
13240 state->ctl = skl_plane_ctl(crtc_state, state);
13242 ret = i9xx_check_plane_surface(state);
13246 state->ctl = i9xx_plane_ctl(crtc_state, state);
13249 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
13250 state->color_ctl = glk_plane_color_ctl(crtc_state, state);
13255 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13256 struct drm_crtc_state *old_crtc_state)
13258 struct drm_device *dev = crtc->dev;
13259 struct drm_i915_private *dev_priv = to_i915(dev);
13260 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13261 struct intel_crtc_state *old_intel_cstate =
13262 to_intel_crtc_state(old_crtc_state);
13263 struct intel_atomic_state *old_intel_state =
13264 to_intel_atomic_state(old_crtc_state->state);
13265 struct intel_crtc_state *intel_cstate =
13266 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13267 bool modeset = needs_modeset(&intel_cstate->base);
13270 (intel_cstate->base.color_mgmt_changed ||
13271 intel_cstate->update_pipe)) {
13272 intel_color_set_csc(&intel_cstate->base);
13273 intel_color_load_luts(&intel_cstate->base);
13276 /* Perform vblank evasion around commit operation */
13277 intel_pipe_update_start(intel_cstate);
13282 if (intel_cstate->update_pipe)
13283 intel_update_pipe_config(old_intel_cstate, intel_cstate);
13284 else if (INTEL_GEN(dev_priv) >= 9)
13285 skl_detach_scalers(intel_crtc);
13288 if (dev_priv->display.atomic_update_watermarks)
13289 dev_priv->display.atomic_update_watermarks(old_intel_state,
13293 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13294 struct intel_crtc_state *crtc_state)
13296 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13298 if (!IS_GEN2(dev_priv))
13299 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13301 if (crtc_state->has_pch_encoder) {
13302 enum pipe pch_transcoder =
13303 intel_crtc_pch_transcoder(crtc);
13305 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13309 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13310 struct drm_crtc_state *old_crtc_state)
13312 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13313 struct intel_atomic_state *old_intel_state =
13314 to_intel_atomic_state(old_crtc_state->state);
13315 struct intel_crtc_state *new_crtc_state =
13316 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13318 intel_pipe_update_end(new_crtc_state);
13320 if (new_crtc_state->update_pipe &&
13321 !needs_modeset(&new_crtc_state->base) &&
13322 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13323 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
13327 * intel_plane_destroy - destroy a plane
13328 * @plane: plane to destroy
13330 * Common destruction function for all types of planes (primary, cursor,
13333 void intel_plane_destroy(struct drm_plane *plane)
13335 drm_plane_cleanup(plane);
13336 kfree(to_intel_plane(plane));
13339 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13340 u32 format, u64 modifier)
13342 switch (modifier) {
13343 case DRM_FORMAT_MOD_LINEAR:
13344 case I915_FORMAT_MOD_X_TILED:
13351 case DRM_FORMAT_C8:
13352 case DRM_FORMAT_RGB565:
13353 case DRM_FORMAT_XRGB1555:
13354 case DRM_FORMAT_XRGB8888:
13355 return modifier == DRM_FORMAT_MOD_LINEAR ||
13356 modifier == I915_FORMAT_MOD_X_TILED;
13362 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13363 u32 format, u64 modifier)
13365 switch (modifier) {
13366 case DRM_FORMAT_MOD_LINEAR:
13367 case I915_FORMAT_MOD_X_TILED:
13374 case DRM_FORMAT_C8:
13375 case DRM_FORMAT_RGB565:
13376 case DRM_FORMAT_XRGB8888:
13377 case DRM_FORMAT_XBGR8888:
13378 case DRM_FORMAT_XRGB2101010:
13379 case DRM_FORMAT_XBGR2101010:
13380 return modifier == DRM_FORMAT_MOD_LINEAR ||
13381 modifier == I915_FORMAT_MOD_X_TILED;
13387 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
13388 u32 format, u64 modifier)
13390 struct intel_plane *plane = to_intel_plane(_plane);
13392 switch (modifier) {
13393 case DRM_FORMAT_MOD_LINEAR:
13394 case I915_FORMAT_MOD_X_TILED:
13395 case I915_FORMAT_MOD_Y_TILED:
13396 case I915_FORMAT_MOD_Yf_TILED:
13398 case I915_FORMAT_MOD_Y_TILED_CCS:
13399 case I915_FORMAT_MOD_Yf_TILED_CCS:
13400 if (!plane->has_ccs)
13408 case DRM_FORMAT_XRGB8888:
13409 case DRM_FORMAT_XBGR8888:
13410 case DRM_FORMAT_ARGB8888:
13411 case DRM_FORMAT_ABGR8888:
13412 if (is_ccs_modifier(modifier))
13415 case DRM_FORMAT_RGB565:
13416 case DRM_FORMAT_XRGB2101010:
13417 case DRM_FORMAT_XBGR2101010:
13418 case DRM_FORMAT_YUYV:
13419 case DRM_FORMAT_YVYU:
13420 case DRM_FORMAT_UYVY:
13421 case DRM_FORMAT_VYUY:
13422 case DRM_FORMAT_NV12:
13423 if (modifier == I915_FORMAT_MOD_Yf_TILED)
13426 case DRM_FORMAT_C8:
13427 if (modifier == DRM_FORMAT_MOD_LINEAR ||
13428 modifier == I915_FORMAT_MOD_X_TILED ||
13429 modifier == I915_FORMAT_MOD_Y_TILED)
13437 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13438 u32 format, u64 modifier)
13440 return modifier == DRM_FORMAT_MOD_LINEAR &&
13441 format == DRM_FORMAT_ARGB8888;
13444 static struct drm_plane_funcs skl_plane_funcs = {
13445 .update_plane = drm_atomic_helper_update_plane,
13446 .disable_plane = drm_atomic_helper_disable_plane,
13447 .destroy = intel_plane_destroy,
13448 .atomic_get_property = intel_plane_atomic_get_property,
13449 .atomic_set_property = intel_plane_atomic_set_property,
13450 .atomic_duplicate_state = intel_plane_duplicate_state,
13451 .atomic_destroy_state = intel_plane_destroy_state,
13452 .format_mod_supported = skl_plane_format_mod_supported,
13455 static struct drm_plane_funcs i965_plane_funcs = {
13456 .update_plane = drm_atomic_helper_update_plane,
13457 .disable_plane = drm_atomic_helper_disable_plane,
13458 .destroy = intel_plane_destroy,
13459 .atomic_get_property = intel_plane_atomic_get_property,
13460 .atomic_set_property = intel_plane_atomic_set_property,
13461 .atomic_duplicate_state = intel_plane_duplicate_state,
13462 .atomic_destroy_state = intel_plane_destroy_state,
13463 .format_mod_supported = i965_plane_format_mod_supported,
13466 static struct drm_plane_funcs i8xx_plane_funcs = {
13467 .update_plane = drm_atomic_helper_update_plane,
13468 .disable_plane = drm_atomic_helper_disable_plane,
13469 .destroy = intel_plane_destroy,
13470 .atomic_get_property = intel_plane_atomic_get_property,
13471 .atomic_set_property = intel_plane_atomic_set_property,
13472 .atomic_duplicate_state = intel_plane_duplicate_state,
13473 .atomic_destroy_state = intel_plane_destroy_state,
13474 .format_mod_supported = i8xx_plane_format_mod_supported,
13478 intel_legacy_cursor_update(struct drm_plane *plane,
13479 struct drm_crtc *crtc,
13480 struct drm_framebuffer *fb,
13481 int crtc_x, int crtc_y,
13482 unsigned int crtc_w, unsigned int crtc_h,
13483 uint32_t src_x, uint32_t src_y,
13484 uint32_t src_w, uint32_t src_h,
13485 struct drm_modeset_acquire_ctx *ctx)
13487 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13489 struct drm_plane_state *old_plane_state, *new_plane_state;
13490 struct intel_plane *intel_plane = to_intel_plane(plane);
13491 struct drm_framebuffer *old_fb;
13492 struct drm_crtc_state *crtc_state = crtc->state;
13495 * When crtc is inactive or there is a modeset pending,
13496 * wait for it to complete in the slowpath
13498 if (!crtc_state->active || needs_modeset(crtc_state) ||
13499 to_intel_crtc_state(crtc_state)->update_pipe)
13502 old_plane_state = plane->state;
13504 * Don't do an async update if there is an outstanding commit modifying
13505 * the plane. This prevents our async update's changes from getting
13506 * overridden by a previous synchronous update's state.
13508 if (old_plane_state->commit &&
13509 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13513 * If any parameters change that may affect watermarks,
13514 * take the slowpath. Only changing fb or position should be
13517 if (old_plane_state->crtc != crtc ||
13518 old_plane_state->src_w != src_w ||
13519 old_plane_state->src_h != src_h ||
13520 old_plane_state->crtc_w != crtc_w ||
13521 old_plane_state->crtc_h != crtc_h ||
13522 !old_plane_state->fb != !fb)
13525 new_plane_state = intel_plane_duplicate_state(plane);
13526 if (!new_plane_state)
13529 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13531 new_plane_state->src_x = src_x;
13532 new_plane_state->src_y = src_y;
13533 new_plane_state->src_w = src_w;
13534 new_plane_state->src_h = src_h;
13535 new_plane_state->crtc_x = crtc_x;
13536 new_plane_state->crtc_y = crtc_y;
13537 new_plane_state->crtc_w = crtc_w;
13538 new_plane_state->crtc_h = crtc_h;
13540 ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state),
13541 to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */
13542 to_intel_plane_state(plane->state),
13543 to_intel_plane_state(new_plane_state));
13547 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13551 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13555 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
13557 old_fb = old_plane_state->fb;
13558 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13559 intel_plane->frontbuffer_bit);
13561 /* Swap plane state */
13562 plane->state = new_plane_state;
13564 if (plane->state->visible) {
13565 trace_intel_update_plane(plane, to_intel_crtc(crtc));
13566 intel_plane->update_plane(intel_plane,
13567 to_intel_crtc_state(crtc->state),
13568 to_intel_plane_state(plane->state));
13570 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
13571 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
13574 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
13577 mutex_unlock(&dev_priv->drm.struct_mutex);
13580 intel_plane_destroy_state(plane, new_plane_state);
13582 intel_plane_destroy_state(plane, old_plane_state);
13586 return drm_atomic_helper_update_plane(plane, crtc, fb,
13587 crtc_x, crtc_y, crtc_w, crtc_h,
13588 src_x, src_y, src_w, src_h, ctx);
13591 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13592 .update_plane = intel_legacy_cursor_update,
13593 .disable_plane = drm_atomic_helper_disable_plane,
13594 .destroy = intel_plane_destroy,
13595 .atomic_get_property = intel_plane_atomic_get_property,
13596 .atomic_set_property = intel_plane_atomic_set_property,
13597 .atomic_duplicate_state = intel_plane_duplicate_state,
13598 .atomic_destroy_state = intel_plane_destroy_state,
13599 .format_mod_supported = intel_cursor_format_mod_supported,
13602 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13603 enum i9xx_plane_id i9xx_plane)
13605 if (!HAS_FBC(dev_priv))
13608 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13609 return i9xx_plane == PLANE_A; /* tied to pipe A */
13610 else if (IS_IVYBRIDGE(dev_priv))
13611 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13612 i9xx_plane == PLANE_C;
13613 else if (INTEL_GEN(dev_priv) >= 4)
13614 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13616 return i9xx_plane == PLANE_A;
13619 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
13620 enum pipe pipe, enum plane_id plane_id)
13622 if (!HAS_FBC(dev_priv))
13625 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
13628 bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
13629 enum pipe pipe, enum plane_id plane_id)
13632 * FIXME: ICL requires two hardware planes for scanning out NV12
13633 * framebuffers. Do not advertize support until this is implemented.
13635 if (INTEL_GEN(dev_priv) >= 11)
13638 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
13641 if (INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv) && pipe == PIPE_C)
13644 if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
13650 static struct intel_plane *
13651 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
13653 struct intel_plane *primary = NULL;
13654 struct intel_plane_state *state = NULL;
13655 const struct drm_plane_funcs *plane_funcs;
13656 const uint32_t *intel_primary_formats;
13657 unsigned int supported_rotations;
13658 unsigned int num_formats;
13659 const uint64_t *modifiers;
13662 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
13668 state = intel_create_plane_state(&primary->base);
13674 primary->base.state = &state->base;
13676 primary->can_scale = false;
13677 primary->max_downscale = 1;
13678 if (INTEL_GEN(dev_priv) >= 9) {
13679 primary->can_scale = true;
13680 state->scaler_id = -1;
13682 primary->pipe = pipe;
13684 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13685 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13687 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
13688 primary->i9xx_plane = (enum i9xx_plane_id) !pipe;
13690 primary->i9xx_plane = (enum i9xx_plane_id) pipe;
13691 primary->id = PLANE_PRIMARY;
13692 primary->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, primary->id);
13694 if (INTEL_GEN(dev_priv) >= 9)
13695 primary->has_fbc = skl_plane_has_fbc(dev_priv,
13699 primary->has_fbc = i9xx_plane_has_fbc(dev_priv,
13700 primary->i9xx_plane);
13702 if (primary->has_fbc) {
13703 struct intel_fbc *fbc = &dev_priv->fbc;
13705 fbc->possible_framebuffer_bits |= primary->frontbuffer_bit;
13708 primary->check_plane = intel_check_primary_plane;
13710 if (INTEL_GEN(dev_priv) >= 9) {
13711 primary->has_ccs = skl_plane_has_ccs(dev_priv, pipe,
13714 if (skl_plane_has_planar(dev_priv, pipe, PLANE_PRIMARY)) {
13715 intel_primary_formats = skl_pri_planar_formats;
13716 num_formats = ARRAY_SIZE(skl_pri_planar_formats);
13718 intel_primary_formats = skl_primary_formats;
13719 num_formats = ARRAY_SIZE(skl_primary_formats);
13722 if (primary->has_ccs)
13723 modifiers = skl_format_modifiers_ccs;
13725 modifiers = skl_format_modifiers_noccs;
13727 primary->update_plane = skl_update_plane;
13728 primary->disable_plane = skl_disable_plane;
13729 primary->get_hw_state = skl_plane_get_hw_state;
13731 plane_funcs = &skl_plane_funcs;
13732 } else if (INTEL_GEN(dev_priv) >= 4) {
13733 intel_primary_formats = i965_primary_formats;
13734 num_formats = ARRAY_SIZE(i965_primary_formats);
13735 modifiers = i9xx_format_modifiers;
13737 primary->update_plane = i9xx_update_plane;
13738 primary->disable_plane = i9xx_disable_plane;
13739 primary->get_hw_state = i9xx_plane_get_hw_state;
13741 plane_funcs = &i965_plane_funcs;
13743 intel_primary_formats = i8xx_primary_formats;
13744 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13745 modifiers = i9xx_format_modifiers;
13747 primary->update_plane = i9xx_update_plane;
13748 primary->disable_plane = i9xx_disable_plane;
13749 primary->get_hw_state = i9xx_plane_get_hw_state;
13751 plane_funcs = &i8xx_plane_funcs;
13754 if (INTEL_GEN(dev_priv) >= 9)
13755 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13757 intel_primary_formats, num_formats,
13759 DRM_PLANE_TYPE_PRIMARY,
13760 "plane 1%c", pipe_name(pipe));
13761 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
13762 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13764 intel_primary_formats, num_formats,
13766 DRM_PLANE_TYPE_PRIMARY,
13767 "primary %c", pipe_name(pipe));
13769 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13771 intel_primary_formats, num_formats,
13773 DRM_PLANE_TYPE_PRIMARY,
13775 plane_name(primary->i9xx_plane));
13779 if (INTEL_GEN(dev_priv) >= 10) {
13780 supported_rotations =
13781 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13782 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 |
13783 DRM_MODE_REFLECT_X;
13784 } else if (INTEL_GEN(dev_priv) >= 9) {
13785 supported_rotations =
13786 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13787 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
13788 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13789 supported_rotations =
13790 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13791 DRM_MODE_REFLECT_X;
13792 } else if (INTEL_GEN(dev_priv) >= 4) {
13793 supported_rotations =
13794 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
13796 supported_rotations = DRM_MODE_ROTATE_0;
13799 if (INTEL_GEN(dev_priv) >= 4)
13800 drm_plane_create_rotation_property(&primary->base,
13802 supported_rotations);
13804 if (INTEL_GEN(dev_priv) >= 9)
13805 drm_plane_create_color_properties(&primary->base,
13806 BIT(DRM_COLOR_YCBCR_BT601) |
13807 BIT(DRM_COLOR_YCBCR_BT709),
13808 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
13809 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
13810 DRM_COLOR_YCBCR_BT709,
13811 DRM_COLOR_YCBCR_LIMITED_RANGE);
13813 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
13821 return ERR_PTR(ret);
13824 static struct intel_plane *
13825 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13828 struct intel_plane *cursor = NULL;
13829 struct intel_plane_state *state = NULL;
13832 cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
13838 state = intel_create_plane_state(&cursor->base);
13844 cursor->base.state = &state->base;
13846 cursor->can_scale = false;
13847 cursor->max_downscale = 1;
13848 cursor->pipe = pipe;
13849 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
13850 cursor->id = PLANE_CURSOR;
13851 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
13853 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
13854 cursor->update_plane = i845_update_cursor;
13855 cursor->disable_plane = i845_disable_cursor;
13856 cursor->get_hw_state = i845_cursor_get_hw_state;
13857 cursor->check_plane = i845_check_cursor;
13859 cursor->update_plane = i9xx_update_cursor;
13860 cursor->disable_plane = i9xx_disable_cursor;
13861 cursor->get_hw_state = i9xx_cursor_get_hw_state;
13862 cursor->check_plane = i9xx_check_cursor;
13865 cursor->cursor.base = ~0;
13866 cursor->cursor.cntl = ~0;
13868 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13869 cursor->cursor.size = ~0;
13871 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
13872 0, &intel_cursor_plane_funcs,
13873 intel_cursor_formats,
13874 ARRAY_SIZE(intel_cursor_formats),
13875 cursor_format_modifiers,
13876 DRM_PLANE_TYPE_CURSOR,
13877 "cursor %c", pipe_name(pipe));
13881 if (INTEL_GEN(dev_priv) >= 4)
13882 drm_plane_create_rotation_property(&cursor->base,
13884 DRM_MODE_ROTATE_0 |
13885 DRM_MODE_ROTATE_180);
13887 if (INTEL_GEN(dev_priv) >= 9)
13888 state->scaler_id = -1;
13890 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13898 return ERR_PTR(ret);
13901 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
13902 struct intel_crtc_state *crtc_state)
13904 struct intel_crtc_scaler_state *scaler_state =
13905 &crtc_state->scaler_state;
13906 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13909 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
13910 if (!crtc->num_scalers)
13913 for (i = 0; i < crtc->num_scalers; i++) {
13914 struct intel_scaler *scaler = &scaler_state->scalers[i];
13916 scaler->in_use = 0;
13917 scaler->mode = PS_SCALER_MODE_DYN;
13920 scaler_state->scaler_id = -1;
13923 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
13925 struct intel_crtc *intel_crtc;
13926 struct intel_crtc_state *crtc_state = NULL;
13927 struct intel_plane *primary = NULL;
13928 struct intel_plane *cursor = NULL;
13931 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
13935 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
13940 intel_crtc->config = crtc_state;
13941 intel_crtc->base.state = &crtc_state->base;
13942 crtc_state->base.crtc = &intel_crtc->base;
13944 primary = intel_primary_plane_create(dev_priv, pipe);
13945 if (IS_ERR(primary)) {
13946 ret = PTR_ERR(primary);
13949 intel_crtc->plane_ids_mask |= BIT(primary->id);
13951 for_each_sprite(dev_priv, pipe, sprite) {
13952 struct intel_plane *plane;
13954 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
13955 if (IS_ERR(plane)) {
13956 ret = PTR_ERR(plane);
13959 intel_crtc->plane_ids_mask |= BIT(plane->id);
13962 cursor = intel_cursor_plane_create(dev_priv, pipe);
13963 if (IS_ERR(cursor)) {
13964 ret = PTR_ERR(cursor);
13967 intel_crtc->plane_ids_mask |= BIT(cursor->id);
13969 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
13970 &primary->base, &cursor->base,
13972 "pipe %c", pipe_name(pipe));
13976 intel_crtc->pipe = pipe;
13978 /* initialize shared scalers */
13979 intel_crtc_init_scalers(intel_crtc, crtc_state);
13981 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
13982 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
13983 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
13985 if (INTEL_GEN(dev_priv) < 9) {
13986 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
13988 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
13989 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
13990 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
13993 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
13995 intel_color_init(&intel_crtc->base);
13997 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
14003 * drm_mode_config_cleanup() will free up any
14004 * crtcs/planes already initialized.
14012 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
14014 struct drm_device *dev = connector->base.dev;
14016 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
14018 if (!connector->base.state->crtc)
14019 return INVALID_PIPE;
14021 return to_intel_crtc(connector->base.state->crtc)->pipe;
14024 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14025 struct drm_file *file)
14027 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
14028 struct drm_crtc *drmmode_crtc;
14029 struct intel_crtc *crtc;
14031 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
14035 crtc = to_intel_crtc(drmmode_crtc);
14036 pipe_from_crtc_id->pipe = crtc->pipe;
14041 static int intel_encoder_clones(struct intel_encoder *encoder)
14043 struct drm_device *dev = encoder->base.dev;
14044 struct intel_encoder *source_encoder;
14045 int index_mask = 0;
14048 for_each_intel_encoder(dev, source_encoder) {
14049 if (encoders_cloneable(encoder, source_encoder))
14050 index_mask |= (1 << entry);
14058 static bool has_edp_a(struct drm_i915_private *dev_priv)
14060 if (!IS_MOBILE(dev_priv))
14063 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14066 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
14072 static bool intel_crt_present(struct drm_i915_private *dev_priv)
14074 if (INTEL_GEN(dev_priv) >= 9)
14077 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
14080 if (IS_CHERRYVIEW(dev_priv))
14083 if (HAS_PCH_LPT_H(dev_priv) &&
14084 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
14087 /* DDI E can't be used if DDI A requires 4 lanes */
14088 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
14091 if (!dev_priv->vbt.int_crt_support)
14097 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14102 if (HAS_DDI(dev_priv))
14105 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14106 * everywhere where registers can be write protected.
14108 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14113 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14114 u32 val = I915_READ(PP_CONTROL(pps_idx));
14116 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14117 I915_WRITE(PP_CONTROL(pps_idx), val);
14121 static void intel_pps_init(struct drm_i915_private *dev_priv)
14123 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
14124 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14125 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14126 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14128 dev_priv->pps_mmio_base = PPS_BASE;
14130 intel_pps_unlock_regs_wa(dev_priv);
14133 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
14135 struct intel_encoder *encoder;
14136 bool dpd_is_edp = false;
14138 intel_pps_init(dev_priv);
14140 if (INTEL_INFO(dev_priv)->num_pipes == 0)
14144 * intel_edp_init_connector() depends on this completing first, to
14145 * prevent the registeration of both eDP and LVDS and the incorrect
14146 * sharing of the PPS.
14148 intel_lvds_init(dev_priv);
14150 if (intel_crt_present(dev_priv))
14151 intel_crt_init(dev_priv);
14153 if (IS_ICELAKE(dev_priv)) {
14154 intel_ddi_init(dev_priv, PORT_A);
14155 intel_ddi_init(dev_priv, PORT_B);
14156 intel_ddi_init(dev_priv, PORT_C);
14157 intel_ddi_init(dev_priv, PORT_D);
14158 intel_ddi_init(dev_priv, PORT_E);
14159 intel_ddi_init(dev_priv, PORT_F);
14160 } else if (IS_GEN9_LP(dev_priv)) {
14162 * FIXME: Broxton doesn't support port detection via the
14163 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14164 * detect the ports.
14166 intel_ddi_init(dev_priv, PORT_A);
14167 intel_ddi_init(dev_priv, PORT_B);
14168 intel_ddi_init(dev_priv, PORT_C);
14170 vlv_dsi_init(dev_priv);
14171 } else if (HAS_DDI(dev_priv)) {
14175 * Haswell uses DDI functions to detect digital outputs.
14176 * On SKL pre-D0 the strap isn't connected, so we assume
14179 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
14180 /* WaIgnoreDDIAStrap: skl */
14181 if (found || IS_GEN9_BC(dev_priv))
14182 intel_ddi_init(dev_priv, PORT_A);
14184 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
14186 found = I915_READ(SFUSE_STRAP);
14188 if (found & SFUSE_STRAP_DDIB_DETECTED)
14189 intel_ddi_init(dev_priv, PORT_B);
14190 if (found & SFUSE_STRAP_DDIC_DETECTED)
14191 intel_ddi_init(dev_priv, PORT_C);
14192 if (found & SFUSE_STRAP_DDID_DETECTED)
14193 intel_ddi_init(dev_priv, PORT_D);
14194 if (found & SFUSE_STRAP_DDIF_DETECTED)
14195 intel_ddi_init(dev_priv, PORT_F);
14197 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14199 if (IS_GEN9_BC(dev_priv) &&
14200 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14201 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14202 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
14203 intel_ddi_init(dev_priv, PORT_E);
14205 } else if (HAS_PCH_SPLIT(dev_priv)) {
14207 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
14209 if (has_edp_a(dev_priv))
14210 intel_dp_init(dev_priv, DP_A, PORT_A);
14212 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
14213 /* PCH SDVOB multiplex with HDMIB */
14214 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
14216 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
14217 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
14218 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
14221 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
14222 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
14224 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
14225 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
14227 if (I915_READ(PCH_DP_C) & DP_DETECTED)
14228 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
14230 if (I915_READ(PCH_DP_D) & DP_DETECTED)
14231 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
14232 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
14233 bool has_edp, has_port;
14236 * The DP_DETECTED bit is the latched state of the DDC
14237 * SDA pin at boot. However since eDP doesn't require DDC
14238 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14239 * eDP ports may have been muxed to an alternate function.
14240 * Thus we can't rely on the DP_DETECTED bit alone to detect
14241 * eDP ports. Consult the VBT as well as DP_DETECTED to
14242 * detect eDP ports.
14244 * Sadly the straps seem to be missing sometimes even for HDMI
14245 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14246 * and VBT for the presence of the port. Additionally we can't
14247 * trust the port type the VBT declares as we've seen at least
14248 * HDMI ports that the VBT claim are DP or eDP.
14250 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
14251 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14252 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
14253 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
14254 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
14255 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
14257 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
14258 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14259 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
14260 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
14261 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
14262 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
14264 if (IS_CHERRYVIEW(dev_priv)) {
14266 * eDP not supported on port D,
14267 * so no need to worry about it
14269 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14270 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
14271 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
14272 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
14273 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
14276 vlv_dsi_init(dev_priv);
14277 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
14278 bool found = false;
14280 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14281 DRM_DEBUG_KMS("probing SDVOB\n");
14282 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
14283 if (!found && IS_G4X(dev_priv)) {
14284 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14285 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
14288 if (!found && IS_G4X(dev_priv))
14289 intel_dp_init(dev_priv, DP_B, PORT_B);
14292 /* Before G4X SDVOC doesn't have its own detect register */
14294 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14295 DRM_DEBUG_KMS("probing SDVOC\n");
14296 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
14299 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14301 if (IS_G4X(dev_priv)) {
14302 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14303 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
14305 if (IS_G4X(dev_priv))
14306 intel_dp_init(dev_priv, DP_C, PORT_C);
14309 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
14310 intel_dp_init(dev_priv, DP_D, PORT_D);
14311 } else if (IS_GEN2(dev_priv))
14312 intel_dvo_init(dev_priv);
14314 if (SUPPORTS_TV(dev_priv))
14315 intel_tv_init(dev_priv);
14317 intel_psr_init(dev_priv);
14319 for_each_intel_encoder(&dev_priv->drm, encoder) {
14320 encoder->base.possible_crtcs = encoder->crtc_mask;
14321 encoder->base.possible_clones =
14322 intel_encoder_clones(encoder);
14325 intel_init_pch_refclk(dev_priv);
14327 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14330 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14332 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14333 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14335 drm_framebuffer_cleanup(fb);
14337 i915_gem_object_lock(obj);
14338 WARN_ON(!obj->framebuffer_references--);
14339 i915_gem_object_unlock(obj);
14341 i915_gem_object_put(obj);
14346 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14347 struct drm_file *file,
14348 unsigned int *handle)
14350 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14352 if (obj->userptr.mm) {
14353 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14357 return drm_gem_handle_create(file, &obj->base, handle);
14360 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14361 struct drm_file *file,
14362 unsigned flags, unsigned color,
14363 struct drm_clip_rect *clips,
14364 unsigned num_clips)
14366 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14368 i915_gem_object_flush_if_display(obj);
14369 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14374 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14375 .destroy = intel_user_framebuffer_destroy,
14376 .create_handle = intel_user_framebuffer_create_handle,
14377 .dirty = intel_user_framebuffer_dirty,
14381 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14382 uint64_t fb_modifier, uint32_t pixel_format)
14384 u32 gen = INTEL_GEN(dev_priv);
14387 int cpp = drm_format_plane_cpp(pixel_format, 0);
14389 /* "The stride in bytes must not exceed the of the size of 8K
14390 * pixels and 32K bytes."
14392 return min(8192 * cpp, 32768);
14393 } else if (gen >= 5 && !HAS_GMCH_DISPLAY(dev_priv)) {
14395 } else if (gen >= 4) {
14396 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14400 } else if (gen >= 3) {
14401 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14406 /* XXX DSPC is limited to 4k tiled */
14411 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14412 struct drm_i915_gem_object *obj,
14413 struct drm_mode_fb_cmd2 *mode_cmd)
14415 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14416 struct drm_framebuffer *fb = &intel_fb->base;
14417 struct drm_format_name_buf format_name;
14419 unsigned int tiling, stride;
14423 i915_gem_object_lock(obj);
14424 obj->framebuffer_references++;
14425 tiling = i915_gem_object_get_tiling(obj);
14426 stride = i915_gem_object_get_stride(obj);
14427 i915_gem_object_unlock(obj);
14429 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14431 * If there's a fence, enforce that
14432 * the fb modifier and tiling mode match.
14434 if (tiling != I915_TILING_NONE &&
14435 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14436 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14440 if (tiling == I915_TILING_X) {
14441 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14442 } else if (tiling == I915_TILING_Y) {
14443 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14448 /* Passed in modifier sanity checking. */
14449 switch (mode_cmd->modifier[0]) {
14450 case I915_FORMAT_MOD_Y_TILED_CCS:
14451 case I915_FORMAT_MOD_Yf_TILED_CCS:
14452 switch (mode_cmd->pixel_format) {
14453 case DRM_FORMAT_XBGR8888:
14454 case DRM_FORMAT_ABGR8888:
14455 case DRM_FORMAT_XRGB8888:
14456 case DRM_FORMAT_ARGB8888:
14459 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
14463 case I915_FORMAT_MOD_Y_TILED:
14464 case I915_FORMAT_MOD_Yf_TILED:
14465 if (INTEL_GEN(dev_priv) < 9) {
14466 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14467 mode_cmd->modifier[0]);
14470 case DRM_FORMAT_MOD_LINEAR:
14471 case I915_FORMAT_MOD_X_TILED:
14474 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14475 mode_cmd->modifier[0]);
14480 * gen2/3 display engine uses the fence if present,
14481 * so the tiling mode must match the fb modifier exactly.
14483 if (INTEL_GEN(dev_priv) < 4 &&
14484 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14485 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14489 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
14490 mode_cmd->pixel_format);
14491 if (mode_cmd->pitches[0] > pitch_limit) {
14492 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14493 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14494 "tiled" : "linear",
14495 mode_cmd->pitches[0], pitch_limit);
14500 * If there's a fence, enforce that
14501 * the fb pitch and fence stride match.
14503 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14504 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14505 mode_cmd->pitches[0], stride);
14509 /* Reject formats not supported by any plane early. */
14510 switch (mode_cmd->pixel_format) {
14511 case DRM_FORMAT_C8:
14512 case DRM_FORMAT_RGB565:
14513 case DRM_FORMAT_XRGB8888:
14514 case DRM_FORMAT_ARGB8888:
14516 case DRM_FORMAT_XRGB1555:
14517 if (INTEL_GEN(dev_priv) > 3) {
14518 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14519 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14523 case DRM_FORMAT_ABGR8888:
14524 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
14525 INTEL_GEN(dev_priv) < 9) {
14526 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14527 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14531 case DRM_FORMAT_XBGR8888:
14532 case DRM_FORMAT_XRGB2101010:
14533 case DRM_FORMAT_XBGR2101010:
14534 if (INTEL_GEN(dev_priv) < 4) {
14535 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14536 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14540 case DRM_FORMAT_ABGR2101010:
14541 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
14542 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14543 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14547 case DRM_FORMAT_YUYV:
14548 case DRM_FORMAT_UYVY:
14549 case DRM_FORMAT_YVYU:
14550 case DRM_FORMAT_VYUY:
14551 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
14552 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14553 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14557 case DRM_FORMAT_NV12:
14558 if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) ||
14559 IS_BROXTON(dev_priv) || INTEL_GEN(dev_priv) >= 11) {
14560 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14561 drm_get_format_name(mode_cmd->pixel_format,
14567 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14568 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14572 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14573 if (mode_cmd->offsets[0] != 0)
14576 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14578 if (fb->format->format == DRM_FORMAT_NV12 &&
14579 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14580 fb->height < SKL_MIN_YUV_420_SRC_H ||
14581 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14582 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
14586 for (i = 0; i < fb->format->num_planes; i++) {
14587 u32 stride_alignment;
14589 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14590 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14594 stride_alignment = intel_fb_stride_alignment(fb, i);
14597 * Display WA #0531: skl,bxt,kbl,glk
14599 * Render decompression and plane width > 3840
14600 * combined with horizontal panning requires the
14601 * plane stride to be a multiple of 4. We'll just
14602 * require the entire fb to accommodate that to avoid
14603 * potential runtime errors at plane configuration time.
14605 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
14606 is_ccs_modifier(fb->modifier))
14607 stride_alignment *= 4;
14609 if (fb->pitches[i] & (stride_alignment - 1)) {
14610 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14611 i, fb->pitches[i], stride_alignment);
14615 fb->obj[i] = &obj->base;
14618 ret = intel_fill_fb_info(dev_priv, fb);
14622 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14624 DRM_ERROR("framebuffer init failed %d\n", ret);
14631 i915_gem_object_lock(obj);
14632 obj->framebuffer_references--;
14633 i915_gem_object_unlock(obj);
14637 static struct drm_framebuffer *
14638 intel_user_framebuffer_create(struct drm_device *dev,
14639 struct drm_file *filp,
14640 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14642 struct drm_framebuffer *fb;
14643 struct drm_i915_gem_object *obj;
14644 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14646 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14648 return ERR_PTR(-ENOENT);
14650 fb = intel_framebuffer_create(obj, &mode_cmd);
14652 i915_gem_object_put(obj);
14657 static void intel_atomic_state_free(struct drm_atomic_state *state)
14659 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14661 drm_atomic_state_default_release(state);
14663 i915_sw_fence_fini(&intel_state->commit_ready);
14668 static enum drm_mode_status
14669 intel_mode_valid(struct drm_device *dev,
14670 const struct drm_display_mode *mode)
14672 struct drm_i915_private *dev_priv = to_i915(dev);
14673 int hdisplay_max, htotal_max;
14674 int vdisplay_max, vtotal_max;
14677 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14678 * of DBLSCAN modes to the output's mode list when they detect
14679 * the scaling mode property on the connector. And they don't
14680 * ask the kernel to validate those modes in any way until
14681 * modeset time at which point the client gets a protocol error.
14682 * So in order to not upset those clients we silently ignore the
14683 * DBLSCAN flag on such connectors. For other connectors we will
14684 * reject modes with the DBLSCAN flag in encoder->compute_config().
14685 * And we always reject DBLSCAN modes in connector->mode_valid()
14686 * as we never want such modes on the connector's mode list.
14689 if (mode->vscan > 1)
14690 return MODE_NO_VSCAN;
14692 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14693 return MODE_H_ILLEGAL;
14695 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14696 DRM_MODE_FLAG_NCSYNC |
14697 DRM_MODE_FLAG_PCSYNC))
14700 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14701 DRM_MODE_FLAG_PIXMUX |
14702 DRM_MODE_FLAG_CLKDIV2))
14705 if (INTEL_GEN(dev_priv) >= 9 ||
14706 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14707 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14708 vdisplay_max = 4096;
14711 } else if (INTEL_GEN(dev_priv) >= 3) {
14712 hdisplay_max = 4096;
14713 vdisplay_max = 4096;
14717 hdisplay_max = 2048;
14718 vdisplay_max = 2048;
14723 if (mode->hdisplay > hdisplay_max ||
14724 mode->hsync_start > htotal_max ||
14725 mode->hsync_end > htotal_max ||
14726 mode->htotal > htotal_max)
14727 return MODE_H_ILLEGAL;
14729 if (mode->vdisplay > vdisplay_max ||
14730 mode->vsync_start > vtotal_max ||
14731 mode->vsync_end > vtotal_max ||
14732 mode->vtotal > vtotal_max)
14733 return MODE_V_ILLEGAL;
14738 static const struct drm_mode_config_funcs intel_mode_funcs = {
14739 .fb_create = intel_user_framebuffer_create,
14740 .get_format_info = intel_get_format_info,
14741 .output_poll_changed = intel_fbdev_output_poll_changed,
14742 .mode_valid = intel_mode_valid,
14743 .atomic_check = intel_atomic_check,
14744 .atomic_commit = intel_atomic_commit,
14745 .atomic_state_alloc = intel_atomic_state_alloc,
14746 .atomic_state_clear = intel_atomic_state_clear,
14747 .atomic_state_free = intel_atomic_state_free,
14751 * intel_init_display_hooks - initialize the display modesetting hooks
14752 * @dev_priv: device private
14754 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14756 intel_init_cdclk_hooks(dev_priv);
14758 if (INTEL_GEN(dev_priv) >= 9) {
14759 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14760 dev_priv->display.get_initial_plane_config =
14761 skylake_get_initial_plane_config;
14762 dev_priv->display.crtc_compute_clock =
14763 haswell_crtc_compute_clock;
14764 dev_priv->display.crtc_enable = haswell_crtc_enable;
14765 dev_priv->display.crtc_disable = haswell_crtc_disable;
14766 } else if (HAS_DDI(dev_priv)) {
14767 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14768 dev_priv->display.get_initial_plane_config =
14769 i9xx_get_initial_plane_config;
14770 dev_priv->display.crtc_compute_clock =
14771 haswell_crtc_compute_clock;
14772 dev_priv->display.crtc_enable = haswell_crtc_enable;
14773 dev_priv->display.crtc_disable = haswell_crtc_disable;
14774 } else if (HAS_PCH_SPLIT(dev_priv)) {
14775 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14776 dev_priv->display.get_initial_plane_config =
14777 i9xx_get_initial_plane_config;
14778 dev_priv->display.crtc_compute_clock =
14779 ironlake_crtc_compute_clock;
14780 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14781 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14782 } else if (IS_CHERRYVIEW(dev_priv)) {
14783 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14784 dev_priv->display.get_initial_plane_config =
14785 i9xx_get_initial_plane_config;
14786 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14787 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14788 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14789 } else if (IS_VALLEYVIEW(dev_priv)) {
14790 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14791 dev_priv->display.get_initial_plane_config =
14792 i9xx_get_initial_plane_config;
14793 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
14794 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14795 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14796 } else if (IS_G4X(dev_priv)) {
14797 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14798 dev_priv->display.get_initial_plane_config =
14799 i9xx_get_initial_plane_config;
14800 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14801 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14802 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14803 } else if (IS_PINEVIEW(dev_priv)) {
14804 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14805 dev_priv->display.get_initial_plane_config =
14806 i9xx_get_initial_plane_config;
14807 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14808 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14809 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14810 } else if (!IS_GEN2(dev_priv)) {
14811 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14812 dev_priv->display.get_initial_plane_config =
14813 i9xx_get_initial_plane_config;
14814 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14815 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14816 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14818 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14819 dev_priv->display.get_initial_plane_config =
14820 i9xx_get_initial_plane_config;
14821 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14822 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14823 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14826 if (IS_GEN5(dev_priv)) {
14827 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14828 } else if (IS_GEN6(dev_priv)) {
14829 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14830 } else if (IS_IVYBRIDGE(dev_priv)) {
14831 /* FIXME: detect B0+ stepping and use auto training */
14832 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14833 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
14834 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14837 if (INTEL_GEN(dev_priv) >= 9)
14838 dev_priv->display.update_crtcs = skl_update_crtcs;
14840 dev_priv->display.update_crtcs = intel_update_crtcs;
14844 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14846 static void quirk_ssc_force_disable(struct drm_device *dev)
14848 struct drm_i915_private *dev_priv = to_i915(dev);
14849 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14850 DRM_INFO("applying lvds SSC disable quirk\n");
14854 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14857 static void quirk_invert_brightness(struct drm_device *dev)
14859 struct drm_i915_private *dev_priv = to_i915(dev);
14860 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14861 DRM_INFO("applying inverted panel brightness quirk\n");
14864 /* Some VBT's incorrectly indicate no backlight is present */
14865 static void quirk_backlight_present(struct drm_device *dev)
14867 struct drm_i915_private *dev_priv = to_i915(dev);
14868 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14869 DRM_INFO("applying backlight present quirk\n");
14872 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
14873 * which is 300 ms greater than eDP spec T12 min.
14875 static void quirk_increase_t12_delay(struct drm_device *dev)
14877 struct drm_i915_private *dev_priv = to_i915(dev);
14879 dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY;
14880 DRM_INFO("Applying T12 delay quirk\n");
14884 * GeminiLake NUC HDMI outputs require additional off time
14885 * this allows the onboard retimer to correctly sync to signal
14887 static void quirk_increase_ddi_disabled_time(struct drm_device *dev)
14889 struct drm_i915_private *dev_priv = to_i915(dev);
14891 dev_priv->quirks |= QUIRK_INCREASE_DDI_DISABLED_TIME;
14892 DRM_INFO("Applying Increase DDI Disabled quirk\n");
14895 struct intel_quirk {
14897 int subsystem_vendor;
14898 int subsystem_device;
14899 void (*hook)(struct drm_device *dev);
14902 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14903 struct intel_dmi_quirk {
14904 void (*hook)(struct drm_device *dev);
14905 const struct dmi_system_id (*dmi_id_list)[];
14908 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
14910 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
14914 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
14916 .dmi_id_list = &(const struct dmi_system_id[]) {
14918 .callback = intel_dmi_reverse_brightness,
14919 .ident = "NCR Corporation",
14920 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
14921 DMI_MATCH(DMI_PRODUCT_NAME, ""),
14924 { } /* terminating entry */
14926 .hook = quirk_invert_brightness,
14930 static struct intel_quirk intel_quirks[] = {
14931 /* Lenovo U160 cannot use SSC on LVDS */
14932 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
14934 /* Sony Vaio Y cannot use SSC on LVDS */
14935 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
14937 /* Acer Aspire 5734Z must invert backlight brightness */
14938 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
14940 /* Acer/eMachines G725 */
14941 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
14943 /* Acer/eMachines e725 */
14944 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
14946 /* Acer/Packard Bell NCL20 */
14947 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
14949 /* Acer Aspire 4736Z */
14950 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
14952 /* Acer Aspire 5336 */
14953 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
14955 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14956 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
14958 /* Acer C720 Chromebook (Core i3 4005U) */
14959 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
14961 /* Apple Macbook 2,1 (Core 2 T7400) */
14962 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
14964 /* Apple Macbook 4,1 */
14965 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
14967 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14968 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
14970 /* HP Chromebook 14 (Celeron 2955U) */
14971 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
14973 /* Dell Chromebook 11 */
14974 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
14976 /* Dell Chromebook 11 (2015 version) */
14977 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
14979 /* Toshiba Satellite P50-C-18C */
14980 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
14982 /* GeminiLake NUC */
14983 { 0x3185, 0x8086, 0x2072, quirk_increase_ddi_disabled_time },
14984 { 0x3184, 0x8086, 0x2072, quirk_increase_ddi_disabled_time },
14986 { 0x3185, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },
14987 { 0x3184, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },
14990 static void intel_init_quirks(struct drm_device *dev)
14992 struct pci_dev *d = dev->pdev;
14995 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
14996 struct intel_quirk *q = &intel_quirks[i];
14998 if (d->device == q->device &&
14999 (d->subsystem_vendor == q->subsystem_vendor ||
15000 q->subsystem_vendor == PCI_ANY_ID) &&
15001 (d->subsystem_device == q->subsystem_device ||
15002 q->subsystem_device == PCI_ANY_ID))
15005 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
15006 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
15007 intel_dmi_quirks[i].hook(dev);
15011 /* Disable the VGA plane that we never use */
15012 static void i915_disable_vga(struct drm_i915_private *dev_priv)
15014 struct pci_dev *pdev = dev_priv->drm.pdev;
15016 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15018 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15019 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
15020 outb(SR01, VGA_SR_INDEX);
15021 sr1 = inb(VGA_SR_DATA);
15022 outb(sr1 | 1<<5, VGA_SR_DATA);
15023 vga_put(pdev, VGA_RSRC_LEGACY_IO);
15026 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
15027 POSTING_READ(vga_reg);
15030 void intel_modeset_init_hw(struct drm_device *dev)
15032 struct drm_i915_private *dev_priv = to_i915(dev);
15034 intel_update_cdclk(dev_priv);
15035 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
15036 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
15040 * Calculate what we think the watermarks should be for the state we've read
15041 * out of the hardware and then immediately program those watermarks so that
15042 * we ensure the hardware settings match our internal state.
15044 * We can calculate what we think WM's should be by creating a duplicate of the
15045 * current state (which was constructed during hardware readout) and running it
15046 * through the atomic check code to calculate new watermark values in the
15049 static void sanitize_watermarks(struct drm_device *dev)
15051 struct drm_i915_private *dev_priv = to_i915(dev);
15052 struct drm_atomic_state *state;
15053 struct intel_atomic_state *intel_state;
15054 struct drm_crtc *crtc;
15055 struct drm_crtc_state *cstate;
15056 struct drm_modeset_acquire_ctx ctx;
15060 /* Only supported on platforms that use atomic watermark design */
15061 if (!dev_priv->display.optimize_watermarks)
15065 * We need to hold connection_mutex before calling duplicate_state so
15066 * that the connector loop is protected.
15068 drm_modeset_acquire_init(&ctx, 0);
15070 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15071 if (ret == -EDEADLK) {
15072 drm_modeset_backoff(&ctx);
15074 } else if (WARN_ON(ret)) {
15078 state = drm_atomic_helper_duplicate_state(dev, &ctx);
15079 if (WARN_ON(IS_ERR(state)))
15082 intel_state = to_intel_atomic_state(state);
15085 * Hardware readout is the only time we don't want to calculate
15086 * intermediate watermarks (since we don't trust the current
15089 if (!HAS_GMCH_DISPLAY(dev_priv))
15090 intel_state->skip_intermediate_wm = true;
15092 ret = intel_atomic_check(dev, state);
15095 * If we fail here, it means that the hardware appears to be
15096 * programmed in a way that shouldn't be possible, given our
15097 * understanding of watermark requirements. This might mean a
15098 * mistake in the hardware readout code or a mistake in the
15099 * watermark calculations for a given platform. Raise a WARN
15100 * so that this is noticeable.
15102 * If this actually happens, we'll have to just leave the
15103 * BIOS-programmed watermarks untouched and hope for the best.
15105 WARN(true, "Could not determine valid watermarks for inherited state\n");
15109 /* Write calculated watermark values back */
15110 for_each_new_crtc_in_state(state, crtc, cstate, i) {
15111 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
15113 cs->wm.need_postvbl_update = true;
15114 dev_priv->display.optimize_watermarks(intel_state, cs);
15116 to_intel_crtc_state(crtc->state)->wm = cs->wm;
15120 drm_atomic_state_put(state);
15122 drm_modeset_drop_locks(&ctx);
15123 drm_modeset_acquire_fini(&ctx);
15126 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
15128 if (IS_GEN5(dev_priv)) {
15130 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
15132 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
15133 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
15134 dev_priv->fdi_pll_freq = 270000;
15139 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
15142 static int intel_initial_commit(struct drm_device *dev)
15144 struct drm_atomic_state *state = NULL;
15145 struct drm_modeset_acquire_ctx ctx;
15146 struct drm_crtc *crtc;
15147 struct drm_crtc_state *crtc_state;
15150 state = drm_atomic_state_alloc(dev);
15154 drm_modeset_acquire_init(&ctx, 0);
15157 state->acquire_ctx = &ctx;
15159 drm_for_each_crtc(crtc, dev) {
15160 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15161 if (IS_ERR(crtc_state)) {
15162 ret = PTR_ERR(crtc_state);
15166 if (crtc_state->active) {
15167 ret = drm_atomic_add_affected_planes(state, crtc);
15173 ret = drm_atomic_commit(state);
15176 if (ret == -EDEADLK) {
15177 drm_atomic_state_clear(state);
15178 drm_modeset_backoff(&ctx);
15182 drm_atomic_state_put(state);
15184 drm_modeset_drop_locks(&ctx);
15185 drm_modeset_acquire_fini(&ctx);
15190 int intel_modeset_init(struct drm_device *dev)
15192 struct drm_i915_private *dev_priv = to_i915(dev);
15193 struct i915_ggtt *ggtt = &dev_priv->ggtt;
15195 struct intel_crtc *crtc;
15198 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15200 drm_mode_config_init(dev);
15202 dev->mode_config.min_width = 0;
15203 dev->mode_config.min_height = 0;
15205 dev->mode_config.preferred_depth = 24;
15206 dev->mode_config.prefer_shadow = 1;
15208 dev->mode_config.allow_fb_modifiers = true;
15210 dev->mode_config.funcs = &intel_mode_funcs;
15212 init_llist_head(&dev_priv->atomic_helper.free_list);
15213 INIT_WORK(&dev_priv->atomic_helper.free_work,
15214 intel_atomic_helper_free_state_worker);
15216 intel_init_quirks(dev);
15218 intel_init_pm(dev_priv);
15221 * There may be no VBT; and if the BIOS enabled SSC we can
15222 * just keep using it to avoid unnecessary flicker. Whereas if the
15223 * BIOS isn't using it, don't assume it will work even if the VBT
15224 * indicates as much.
15226 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
15227 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15230 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15231 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15232 bios_lvds_use_ssc ? "en" : "dis",
15233 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15234 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15238 /* maximum framebuffer dimensions */
15239 if (IS_GEN2(dev_priv)) {
15240 dev->mode_config.max_width = 2048;
15241 dev->mode_config.max_height = 2048;
15242 } else if (IS_GEN3(dev_priv)) {
15243 dev->mode_config.max_width = 4096;
15244 dev->mode_config.max_height = 4096;
15246 dev->mode_config.max_width = 8192;
15247 dev->mode_config.max_height = 8192;
15250 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15251 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
15252 dev->mode_config.cursor_height = 1023;
15253 } else if (IS_GEN2(dev_priv)) {
15254 dev->mode_config.cursor_width = 64;
15255 dev->mode_config.cursor_height = 64;
15257 dev->mode_config.cursor_width = 256;
15258 dev->mode_config.cursor_height = 256;
15261 dev->mode_config.fb_base = ggtt->gmadr.start;
15263 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15264 INTEL_INFO(dev_priv)->num_pipes,
15265 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
15267 for_each_pipe(dev_priv, pipe) {
15268 ret = intel_crtc_init(dev_priv, pipe);
15270 drm_mode_config_cleanup(dev);
15275 intel_shared_dpll_init(dev);
15276 intel_update_fdi_pll_freq(dev_priv);
15278 intel_update_czclk(dev_priv);
15279 intel_modeset_init_hw(dev);
15281 if (dev_priv->max_cdclk_freq == 0)
15282 intel_update_max_cdclk(dev_priv);
15284 /* Just disable it once at startup */
15285 i915_disable_vga(dev_priv);
15286 intel_setup_outputs(dev_priv);
15288 drm_modeset_lock_all(dev);
15289 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
15290 drm_modeset_unlock_all(dev);
15292 for_each_intel_crtc(dev, crtc) {
15293 struct intel_initial_plane_config plane_config = {};
15299 * Note that reserving the BIOS fb up front prevents us
15300 * from stuffing other stolen allocations like the ring
15301 * on top. This prevents some ugliness at boot time, and
15302 * can even allow for smooth boot transitions if the BIOS
15303 * fb is large enough for the active pipe configuration.
15305 dev_priv->display.get_initial_plane_config(crtc,
15309 * If the fb is shared between multiple heads, we'll
15310 * just get the first one.
15312 intel_find_initial_plane_obj(crtc, &plane_config);
15316 * Make sure hardware watermarks really match the state we read out.
15317 * Note that we need to do this after reconstructing the BIOS fb's
15318 * since the watermark calculation done here will use pstate->fb.
15320 if (!HAS_GMCH_DISPLAY(dev_priv))
15321 sanitize_watermarks(dev);
15324 * Force all active planes to recompute their states. So that on
15325 * mode_setcrtc after probe, all the intel_plane_state variables
15326 * are already calculated and there is no assert_plane warnings
15329 ret = intel_initial_commit(dev);
15331 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15336 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15338 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15339 /* 640x480@60Hz, ~25175 kHz */
15340 struct dpll clock = {
15350 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15352 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15353 pipe_name(pipe), clock.vco, clock.dot);
15355 fp = i9xx_dpll_compute_fp(&clock);
15356 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15357 DPLL_VGA_MODE_DIS |
15358 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15359 PLL_P2_DIVIDE_BY_4 |
15360 PLL_REF_INPUT_DREFCLK |
15363 I915_WRITE(FP0(pipe), fp);
15364 I915_WRITE(FP1(pipe), fp);
15366 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15367 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15368 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15369 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15370 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15371 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15372 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15375 * Apparently we need to have VGA mode enabled prior to changing
15376 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15377 * dividers, even though the register value does change.
15379 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15380 I915_WRITE(DPLL(pipe), dpll);
15382 /* Wait for the clocks to stabilize. */
15383 POSTING_READ(DPLL(pipe));
15386 /* The pixel multiplier can only be updated once the
15387 * DPLL is enabled and the clocks are stable.
15389 * So write it again.
15391 I915_WRITE(DPLL(pipe), dpll);
15393 /* We do this three times for luck */
15394 for (i = 0; i < 3 ; i++) {
15395 I915_WRITE(DPLL(pipe), dpll);
15396 POSTING_READ(DPLL(pipe));
15397 udelay(150); /* wait for warmup */
15400 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15401 POSTING_READ(PIPECONF(pipe));
15403 intel_wait_for_pipe_scanline_moving(crtc);
15406 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15408 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15410 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15413 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15414 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15415 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
15416 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15417 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
15419 I915_WRITE(PIPECONF(pipe), 0);
15420 POSTING_READ(PIPECONF(pipe));
15422 intel_wait_for_pipe_scanline_stopped(crtc);
15424 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15425 POSTING_READ(DPLL(pipe));
15428 static bool intel_plane_mapping_ok(struct intel_crtc *crtc,
15429 struct intel_plane *plane)
15433 if (!plane->get_hw_state(plane, &pipe))
15436 return pipe == crtc->pipe;
15440 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15442 struct intel_crtc *crtc;
15444 if (INTEL_GEN(dev_priv) >= 4)
15447 for_each_intel_crtc(&dev_priv->drm, crtc) {
15448 struct intel_plane *plane =
15449 to_intel_plane(crtc->base.primary);
15451 if (intel_plane_mapping_ok(crtc, plane))
15454 DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n",
15456 intel_plane_disable_noatomic(crtc, plane);
15460 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15462 struct drm_device *dev = crtc->base.dev;
15463 struct intel_encoder *encoder;
15465 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15471 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15473 struct drm_device *dev = encoder->base.dev;
15474 struct intel_connector *connector;
15476 for_each_connector_on_encoder(dev, &encoder->base, connector)
15482 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15483 enum pipe pch_transcoder)
15485 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15486 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15489 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15490 struct drm_modeset_acquire_ctx *ctx)
15492 struct drm_device *dev = crtc->base.dev;
15493 struct drm_i915_private *dev_priv = to_i915(dev);
15494 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
15496 /* Clear any frame start delays used for debugging left by the BIOS */
15497 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
15498 i915_reg_t reg = PIPECONF(cpu_transcoder);
15501 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15504 /* restore vblank interrupts to correct state */
15505 drm_crtc_vblank_reset(&crtc->base);
15506 if (crtc->active) {
15507 struct intel_plane *plane;
15509 drm_crtc_vblank_on(&crtc->base);
15511 /* Disable everything but the primary plane */
15512 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15513 const struct intel_plane_state *plane_state =
15514 to_intel_plane_state(plane->base.state);
15516 if (plane_state->base.visible &&
15517 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15518 intel_plane_disable_noatomic(crtc, plane);
15522 /* Adjust the state of the output pipe according to whether we
15523 * have active connectors/encoders. */
15524 if (crtc->active && !intel_crtc_has_encoders(crtc))
15525 intel_crtc_disable_noatomic(&crtc->base, ctx);
15527 if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) {
15529 * We start out with underrun reporting disabled to avoid races.
15530 * For correct bookkeeping mark this on active crtcs.
15532 * Also on gmch platforms we dont have any hardware bits to
15533 * disable the underrun reporting. Which means we need to start
15534 * out with underrun reporting disabled also on inactive pipes,
15535 * since otherwise we'll complain about the garbage we read when
15536 * e.g. coming up after runtime pm.
15538 * No protection against concurrent access is required - at
15539 * worst a fifo underrun happens which also sets this to false.
15541 crtc->cpu_fifo_underrun_disabled = true;
15543 * We track the PCH trancoder underrun reporting state
15544 * within the crtc. With crtc for pipe A housing the underrun
15545 * reporting state for PCH transcoder A, crtc for pipe B housing
15546 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15547 * and marking underrun reporting as disabled for the non-existing
15548 * PCH transcoders B and C would prevent enabling the south
15549 * error interrupt (see cpt_can_enable_serr_int()).
15551 if (has_pch_trancoder(dev_priv, crtc->pipe))
15552 crtc->pch_fifo_underrun_disabled = true;
15556 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15558 struct intel_connector *connector;
15560 /* We need to check both for a crtc link (meaning that the
15561 * encoder is active and trying to read from a pipe) and the
15562 * pipe itself being active. */
15563 bool has_active_crtc = encoder->base.crtc &&
15564 to_intel_crtc(encoder->base.crtc)->active;
15566 connector = intel_encoder_find_connector(encoder);
15567 if (connector && !has_active_crtc) {
15568 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15569 encoder->base.base.id,
15570 encoder->base.name);
15572 /* Connector is active, but has no active pipe. This is
15573 * fallout from our resume register restoring. Disable
15574 * the encoder manually again. */
15575 if (encoder->base.crtc) {
15576 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15578 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15579 encoder->base.base.id,
15580 encoder->base.name);
15581 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15582 if (encoder->post_disable)
15583 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15585 encoder->base.crtc = NULL;
15587 /* Inconsistent output/port/pipe state happens presumably due to
15588 * a bug in one of the get_hw_state functions. Or someplace else
15589 * in our code, like the register restore mess on resume. Clamp
15590 * things to off as a safer default. */
15592 connector->base.dpms = DRM_MODE_DPMS_OFF;
15593 connector->base.encoder = NULL;
15596 /* notify opregion of the sanitized encoder state */
15597 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
15600 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15602 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15604 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15605 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15606 i915_disable_vga(dev_priv);
15610 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15612 /* This function can be called both from intel_modeset_setup_hw_state or
15613 * at a very early point in our resume sequence, where the power well
15614 * structures are not yet restored. Since this function is at a very
15615 * paranoid "someone might have enabled VGA while we were not looking"
15616 * level, just check if the power well is enabled instead of trying to
15617 * follow the "don't touch the power well if we don't need it" policy
15618 * the rest of the driver uses. */
15619 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
15622 i915_redisable_vga_power_on(dev_priv);
15624 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
15627 /* FIXME read out full plane state for all planes */
15628 static void readout_plane_state(struct intel_crtc *crtc)
15630 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15631 struct intel_crtc_state *crtc_state =
15632 to_intel_crtc_state(crtc->base.state);
15633 struct intel_plane *plane;
15635 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
15636 struct intel_plane_state *plane_state =
15637 to_intel_plane_state(plane->base.state);
15641 visible = plane->get_hw_state(plane, &pipe);
15643 intel_set_plane_visible(crtc_state, plane_state, visible);
15647 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15649 struct drm_i915_private *dev_priv = to_i915(dev);
15651 struct intel_crtc *crtc;
15652 struct intel_encoder *encoder;
15653 struct intel_connector *connector;
15654 struct drm_connector_list_iter conn_iter;
15657 dev_priv->active_crtcs = 0;
15659 for_each_intel_crtc(dev, crtc) {
15660 struct intel_crtc_state *crtc_state =
15661 to_intel_crtc_state(crtc->base.state);
15663 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15664 memset(crtc_state, 0, sizeof(*crtc_state));
15665 crtc_state->base.crtc = &crtc->base;
15667 crtc_state->base.active = crtc_state->base.enable =
15668 dev_priv->display.get_pipe_config(crtc, crtc_state);
15670 crtc->base.enabled = crtc_state->base.enable;
15671 crtc->active = crtc_state->base.active;
15673 if (crtc_state->base.active)
15674 dev_priv->active_crtcs |= 1 << crtc->pipe;
15676 readout_plane_state(crtc);
15678 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15679 crtc->base.base.id, crtc->base.name,
15680 enableddisabled(crtc_state->base.active));
15683 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15684 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15686 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15687 &pll->state.hw_state);
15688 pll->state.crtc_mask = 0;
15689 for_each_intel_crtc(dev, crtc) {
15690 struct intel_crtc_state *crtc_state =
15691 to_intel_crtc_state(crtc->base.state);
15693 if (crtc_state->base.active &&
15694 crtc_state->shared_dpll == pll)
15695 pll->state.crtc_mask |= 1 << crtc->pipe;
15697 pll->active_mask = pll->state.crtc_mask;
15699 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15700 pll->info->name, pll->state.crtc_mask, pll->on);
15703 for_each_intel_encoder(dev, encoder) {
15706 if (encoder->get_hw_state(encoder, &pipe)) {
15707 struct intel_crtc_state *crtc_state;
15709 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15710 crtc_state = to_intel_crtc_state(crtc->base.state);
15712 encoder->base.crtc = &crtc->base;
15713 encoder->get_config(encoder, crtc_state);
15715 encoder->base.crtc = NULL;
15718 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15719 encoder->base.base.id, encoder->base.name,
15720 enableddisabled(encoder->base.crtc),
15724 drm_connector_list_iter_begin(dev, &conn_iter);
15725 for_each_intel_connector_iter(connector, &conn_iter) {
15726 if (connector->get_hw_state(connector)) {
15727 connector->base.dpms = DRM_MODE_DPMS_ON;
15729 encoder = connector->encoder;
15730 connector->base.encoder = &encoder->base;
15732 if (encoder->base.crtc &&
15733 encoder->base.crtc->state->active) {
15735 * This has to be done during hardware readout
15736 * because anything calling .crtc_disable may
15737 * rely on the connector_mask being accurate.
15739 encoder->base.crtc->state->connector_mask |=
15740 drm_connector_mask(&connector->base);
15741 encoder->base.crtc->state->encoder_mask |=
15742 drm_encoder_mask(&encoder->base);
15746 connector->base.dpms = DRM_MODE_DPMS_OFF;
15747 connector->base.encoder = NULL;
15749 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15750 connector->base.base.id, connector->base.name,
15751 enableddisabled(connector->base.encoder));
15753 drm_connector_list_iter_end(&conn_iter);
15755 for_each_intel_crtc(dev, crtc) {
15756 struct intel_crtc_state *crtc_state =
15757 to_intel_crtc_state(crtc->base.state);
15760 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15761 if (crtc_state->base.active) {
15762 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15763 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15764 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
15765 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15766 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15769 * The initial mode needs to be set in order to keep
15770 * the atomic core happy. It wants a valid mode if the
15771 * crtc's enabled, so we do the above call.
15773 * But we don't set all the derived state fully, hence
15774 * set a flag to indicate that a full recalculation is
15775 * needed on the next commit.
15777 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
15779 intel_crtc_compute_pixel_rate(crtc_state);
15781 if (dev_priv->display.modeset_calc_cdclk) {
15782 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15783 if (WARN_ON(min_cdclk < 0))
15787 drm_calc_timestamping_constants(&crtc->base,
15788 &crtc_state->base.adjusted_mode);
15789 update_scanline_offset(crtc);
15792 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
15793 dev_priv->min_voltage_level[crtc->pipe] =
15794 crtc_state->min_voltage_level;
15796 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15801 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15803 struct intel_encoder *encoder;
15805 for_each_intel_encoder(&dev_priv->drm, encoder) {
15807 enum intel_display_power_domain domain;
15808 struct intel_crtc_state *crtc_state;
15810 if (!encoder->get_power_domains)
15814 * MST-primary and inactive encoders don't have a crtc state
15815 * and neither of these require any power domain references.
15817 if (!encoder->base.crtc)
15820 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
15821 get_domains = encoder->get_power_domains(encoder, crtc_state);
15822 for_each_power_domain(domain, get_domains)
15823 intel_display_power_get(dev_priv, domain);
15827 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15829 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15830 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15831 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15834 if (IS_HASWELL(dev_priv)) {
15836 * WaRsPkgCStateDisplayPMReq:hsw
15837 * System hang if this isn't done before disabling all planes!
15839 I915_WRITE(CHICKEN_PAR1_1,
15840 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15844 /* Scan out the current hw modeset state,
15845 * and sanitizes it to the current state
15848 intel_modeset_setup_hw_state(struct drm_device *dev,
15849 struct drm_modeset_acquire_ctx *ctx)
15851 struct drm_i915_private *dev_priv = to_i915(dev);
15853 struct intel_crtc *crtc;
15854 struct intel_encoder *encoder;
15857 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15859 intel_early_display_was(dev_priv);
15860 intel_modeset_readout_hw_state(dev);
15862 /* HW state is read out, now we need to sanitize this mess. */
15863 get_encoder_power_domains(dev_priv);
15865 intel_sanitize_plane_mapping(dev_priv);
15867 for_each_intel_encoder(dev, encoder) {
15868 intel_sanitize_encoder(encoder);
15871 for_each_pipe(dev_priv, pipe) {
15872 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15874 intel_sanitize_crtc(crtc, ctx);
15875 intel_dump_pipe_config(crtc, crtc->config,
15876 "[setup_hw_state]");
15879 intel_modeset_update_connector_atomic_state(dev);
15881 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15882 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15884 if (!pll->on || pll->active_mask)
15887 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15890 pll->info->funcs->disable(dev_priv, pll);
15894 if (IS_G4X(dev_priv)) {
15895 g4x_wm_get_hw_state(dev);
15896 g4x_wm_sanitize(dev_priv);
15897 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15898 vlv_wm_get_hw_state(dev);
15899 vlv_wm_sanitize(dev_priv);
15900 } else if (INTEL_GEN(dev_priv) >= 9) {
15901 skl_wm_get_hw_state(dev);
15902 } else if (HAS_PCH_SPLIT(dev_priv)) {
15903 ilk_wm_get_hw_state(dev);
15906 for_each_intel_crtc(dev, crtc) {
15909 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config);
15910 if (WARN_ON(put_domains))
15911 modeset_put_power_domains(dev_priv, put_domains);
15914 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
15916 intel_fbc_init_pipe_state(dev_priv);
15919 void intel_display_resume(struct drm_device *dev)
15921 struct drm_i915_private *dev_priv = to_i915(dev);
15922 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15923 struct drm_modeset_acquire_ctx ctx;
15926 dev_priv->modeset_restore_state = NULL;
15928 state->acquire_ctx = &ctx;
15930 drm_modeset_acquire_init(&ctx, 0);
15933 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15934 if (ret != -EDEADLK)
15937 drm_modeset_backoff(&ctx);
15941 ret = __intel_display_resume(dev, state, &ctx);
15943 intel_enable_ipc(dev_priv);
15944 drm_modeset_drop_locks(&ctx);
15945 drm_modeset_acquire_fini(&ctx);
15948 DRM_ERROR("Restoring old state failed with %i\n", ret);
15950 drm_atomic_state_put(state);
15953 int intel_connector_register(struct drm_connector *connector)
15955 struct intel_connector *intel_connector = to_intel_connector(connector);
15958 ret = intel_backlight_device_register(intel_connector);
15968 void intel_connector_unregister(struct drm_connector *connector)
15970 struct intel_connector *intel_connector = to_intel_connector(connector);
15972 intel_backlight_device_unregister(intel_connector);
15973 intel_panel_destroy_backlight(connector);
15976 static void intel_hpd_poll_fini(struct drm_device *dev)
15978 struct intel_connector *connector;
15979 struct drm_connector_list_iter conn_iter;
15981 /* Kill all the work that may have been queued by hpd. */
15982 drm_connector_list_iter_begin(dev, &conn_iter);
15983 for_each_intel_connector_iter(connector, &conn_iter) {
15984 if (connector->modeset_retry_work.func)
15985 cancel_work_sync(&connector->modeset_retry_work);
15986 if (connector->hdcp_shim) {
15987 cancel_delayed_work_sync(&connector->hdcp_check_work);
15988 cancel_work_sync(&connector->hdcp_prop_work);
15991 drm_connector_list_iter_end(&conn_iter);
15994 void intel_modeset_cleanup(struct drm_device *dev)
15996 struct drm_i915_private *dev_priv = to_i915(dev);
15998 flush_workqueue(dev_priv->modeset_wq);
16000 flush_work(&dev_priv->atomic_helper.free_work);
16001 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
16004 * Interrupts and polling as the first thing to avoid creating havoc.
16005 * Too much stuff here (turning of connectors, ...) would
16006 * experience fancy races otherwise.
16008 intel_irq_uninstall(dev_priv);
16011 * Due to the hpd irq storm handling the hotplug work can re-arm the
16012 * poll handlers. Hence disable polling after hpd handling is shut down.
16014 intel_hpd_poll_fini(dev);
16016 /* poll work can call into fbdev, hence clean that up afterwards */
16017 intel_fbdev_fini(dev_priv);
16019 intel_unregister_dsm_handler();
16021 intel_fbc_global_disable(dev_priv);
16023 /* flush any delayed tasks or pending work */
16024 flush_scheduled_work();
16026 drm_mode_config_cleanup(dev);
16028 intel_cleanup_overlay(dev_priv);
16030 intel_teardown_gmbus(dev_priv);
16032 destroy_workqueue(dev_priv->modeset_wq);
16035 void intel_connector_attach_encoder(struct intel_connector *connector,
16036 struct intel_encoder *encoder)
16038 connector->encoder = encoder;
16039 drm_connector_attach_encoder(&connector->base, &encoder->base);
16043 * set vga decode state - true == enable VGA decode
16045 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
16047 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
16050 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
16051 DRM_ERROR("failed to read control word\n");
16055 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
16059 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
16061 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
16063 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
16064 DRM_ERROR("failed to write control word\n");
16071 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
16073 struct intel_display_error_state {
16075 u32 power_well_driver;
16077 int num_transcoders;
16079 struct intel_cursor_error_state {
16084 } cursor[I915_MAX_PIPES];
16086 struct intel_pipe_error_state {
16087 bool power_domain_on;
16090 } pipe[I915_MAX_PIPES];
16092 struct intel_plane_error_state {
16100 } plane[I915_MAX_PIPES];
16102 struct intel_transcoder_error_state {
16103 bool power_domain_on;
16104 enum transcoder cpu_transcoder;
16117 struct intel_display_error_state *
16118 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
16120 struct intel_display_error_state *error;
16121 int transcoders[] = {
16129 if (INTEL_INFO(dev_priv)->num_pipes == 0)
16132 error = kzalloc(sizeof(*error), GFP_ATOMIC);
16136 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16137 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
16139 for_each_pipe(dev_priv, i) {
16140 error->pipe[i].power_domain_on =
16141 __intel_display_power_is_enabled(dev_priv,
16142 POWER_DOMAIN_PIPE(i));
16143 if (!error->pipe[i].power_domain_on)
16146 error->cursor[i].control = I915_READ(CURCNTR(i));
16147 error->cursor[i].position = I915_READ(CURPOS(i));
16148 error->cursor[i].base = I915_READ(CURBASE(i));
16150 error->plane[i].control = I915_READ(DSPCNTR(i));
16151 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
16152 if (INTEL_GEN(dev_priv) <= 3) {
16153 error->plane[i].size = I915_READ(DSPSIZE(i));
16154 error->plane[i].pos = I915_READ(DSPPOS(i));
16156 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16157 error->plane[i].addr = I915_READ(DSPADDR(i));
16158 if (INTEL_GEN(dev_priv) >= 4) {
16159 error->plane[i].surface = I915_READ(DSPSURF(i));
16160 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16163 error->pipe[i].source = I915_READ(PIPESRC(i));
16165 if (HAS_GMCH_DISPLAY(dev_priv))
16166 error->pipe[i].stat = I915_READ(PIPESTAT(i));
16169 /* Note: this does not include DSI transcoders. */
16170 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
16171 if (HAS_DDI(dev_priv))
16172 error->num_transcoders++; /* Account for eDP. */
16174 for (i = 0; i < error->num_transcoders; i++) {
16175 enum transcoder cpu_transcoder = transcoders[i];
16177 error->transcoder[i].power_domain_on =
16178 __intel_display_power_is_enabled(dev_priv,
16179 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
16180 if (!error->transcoder[i].power_domain_on)
16183 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16185 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16186 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16187 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16188 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16189 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16190 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16191 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
16197 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16200 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
16201 struct intel_display_error_state *error)
16203 struct drm_i915_private *dev_priv = m->i915;
16209 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
16210 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16211 err_printf(m, "PWR_WELL_CTL2: %08x\n",
16212 error->power_well_driver);
16213 for_each_pipe(dev_priv, i) {
16214 err_printf(m, "Pipe [%d]:\n", i);
16215 err_printf(m, " Power: %s\n",
16216 onoff(error->pipe[i].power_domain_on));
16217 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
16218 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
16220 err_printf(m, "Plane [%d]:\n", i);
16221 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16222 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
16223 if (INTEL_GEN(dev_priv) <= 3) {
16224 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16225 err_printf(m, " POS: %08x\n", error->plane[i].pos);
16227 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16228 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
16229 if (INTEL_GEN(dev_priv) >= 4) {
16230 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16231 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
16234 err_printf(m, "Cursor [%d]:\n", i);
16235 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16236 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16237 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
16240 for (i = 0; i < error->num_transcoders; i++) {
16241 err_printf(m, "CPU transcoder: %s\n",
16242 transcoder_name(error->transcoder[i].cpu_transcoder));
16243 err_printf(m, " Power: %s\n",
16244 onoff(error->transcoder[i].power_domain_on));
16245 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16246 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16247 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16248 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16249 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16250 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16251 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);