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.
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->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 = PIPE_A;
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;
1217 if (port_sel == PANEL_PORT_SELECT_LVDS &&
1218 I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
1219 panel_pipe = PIPE_B;
1220 /* XXX: else fix for eDP */
1221 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1222 /* presumably write lock depends on pipe, not port select */
1223 pp_reg = PP_CONTROL(pipe);
1226 pp_reg = PP_CONTROL(0);
1227 if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
1228 panel_pipe = PIPE_B;
1231 val = I915_READ(pp_reg);
1232 if (!(val & PANEL_POWER_ON) ||
1233 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1236 I915_STATE_WARN(panel_pipe == pipe && locked,
1237 "panel assertion failure, pipe %c regs locked\n",
1241 void assert_pipe(struct drm_i915_private *dev_priv,
1242 enum pipe pipe, bool state)
1245 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1247 enum intel_display_power_domain power_domain;
1249 /* we keep both pipes enabled on 830 */
1250 if (IS_I830(dev_priv))
1253 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1254 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
1255 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1256 cur_state = !!(val & PIPECONF_ENABLE);
1258 intel_display_power_put(dev_priv, power_domain);
1263 I915_STATE_WARN(cur_state != state,
1264 "pipe %c assertion failure (expected %s, current %s)\n",
1265 pipe_name(pipe), onoff(state), onoff(cur_state));
1268 static void assert_plane(struct intel_plane *plane, bool state)
1270 bool cur_state = plane->get_hw_state(plane);
1272 I915_STATE_WARN(cur_state != state,
1273 "%s assertion failure (expected %s, current %s)\n",
1274 plane->base.name, onoff(state), onoff(cur_state));
1277 #define assert_plane_enabled(p) assert_plane(p, true)
1278 #define assert_plane_disabled(p) assert_plane(p, false)
1280 static void assert_planes_disabled(struct intel_crtc *crtc)
1282 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1283 struct intel_plane *plane;
1285 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1286 assert_plane_disabled(plane);
1289 static void assert_vblank_disabled(struct drm_crtc *crtc)
1291 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1292 drm_crtc_vblank_put(crtc);
1295 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1301 val = I915_READ(PCH_TRANSCONF(pipe));
1302 enabled = !!(val & TRANS_ENABLE);
1303 I915_STATE_WARN(enabled,
1304 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1308 static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
1309 enum pipe pipe, u32 port_sel, u32 val)
1311 if ((val & DP_PORT_EN) == 0)
1314 if (HAS_PCH_CPT(dev_priv)) {
1315 u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe));
1316 if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
1318 } else if (IS_CHERRYVIEW(dev_priv)) {
1319 if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
1322 if ((val & DP_PIPE_MASK) != (pipe << 30))
1328 static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1329 enum pipe pipe, u32 val)
1331 if ((val & SDVO_ENABLE) == 0)
1334 if (HAS_PCH_CPT(dev_priv)) {
1335 if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
1337 } else if (IS_CHERRYVIEW(dev_priv)) {
1338 if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
1341 if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
1347 static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
1348 enum pipe pipe, u32 val)
1350 if ((val & LVDS_PORT_EN) == 0)
1353 if (HAS_PCH_CPT(dev_priv)) {
1354 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1357 if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
1363 static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
1364 enum pipe pipe, u32 val)
1366 if ((val & ADPA_DAC_ENABLE) == 0)
1368 if (HAS_PCH_CPT(dev_priv)) {
1369 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1372 if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
1378 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1379 enum pipe pipe, i915_reg_t reg,
1382 u32 val = I915_READ(reg);
1383 I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
1384 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1385 i915_mmio_reg_offset(reg), pipe_name(pipe));
1387 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0
1388 && (val & DP_PIPEB_SELECT),
1389 "IBX PCH dp port still using transcoder B\n");
1392 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1393 enum pipe pipe, i915_reg_t reg)
1395 u32 val = I915_READ(reg);
1396 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1397 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1398 i915_mmio_reg_offset(reg), pipe_name(pipe));
1400 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0
1401 && (val & SDVO_PIPE_B_SELECT),
1402 "IBX PCH hdmi port still using transcoder B\n");
1405 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1410 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
1411 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
1412 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
1414 val = I915_READ(PCH_ADPA);
1415 I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val),
1416 "PCH VGA enabled on transcoder %c, should be disabled\n",
1419 val = I915_READ(PCH_LVDS);
1420 I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1421 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1424 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
1425 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
1426 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
1429 static void _vlv_enable_pll(struct intel_crtc *crtc,
1430 const struct intel_crtc_state *pipe_config)
1432 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1433 enum pipe pipe = crtc->pipe;
1435 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1436 POSTING_READ(DPLL(pipe));
1439 if (intel_wait_for_register(dev_priv,
1444 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1447 static void vlv_enable_pll(struct intel_crtc *crtc,
1448 const struct intel_crtc_state *pipe_config)
1450 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1451 enum pipe pipe = crtc->pipe;
1453 assert_pipe_disabled(dev_priv, pipe);
1455 /* PLL is protected by panel, make sure we can write it */
1456 assert_panel_unlocked(dev_priv, pipe);
1458 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1459 _vlv_enable_pll(crtc, pipe_config);
1461 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1462 POSTING_READ(DPLL_MD(pipe));
1466 static void _chv_enable_pll(struct intel_crtc *crtc,
1467 const struct intel_crtc_state *pipe_config)
1469 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1470 enum pipe pipe = crtc->pipe;
1471 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1474 mutex_lock(&dev_priv->sb_lock);
1476 /* Enable back the 10bit clock to display controller */
1477 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1478 tmp |= DPIO_DCLKP_EN;
1479 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1481 mutex_unlock(&dev_priv->sb_lock);
1484 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1489 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1491 /* Check PLL is locked */
1492 if (intel_wait_for_register(dev_priv,
1493 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1495 DRM_ERROR("PLL %d failed to lock\n", pipe);
1498 static void chv_enable_pll(struct intel_crtc *crtc,
1499 const struct intel_crtc_state *pipe_config)
1501 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1502 enum pipe pipe = crtc->pipe;
1504 assert_pipe_disabled(dev_priv, pipe);
1506 /* PLL is protected by panel, make sure we can write it */
1507 assert_panel_unlocked(dev_priv, pipe);
1509 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1510 _chv_enable_pll(crtc, pipe_config);
1512 if (pipe != PIPE_A) {
1514 * WaPixelRepeatModeFixForC0:chv
1516 * DPLLCMD is AWOL. Use chicken bits to propagate
1517 * the value from DPLLBMD to either pipe B or C.
1519 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1520 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1521 I915_WRITE(CBR4_VLV, 0);
1522 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1525 * DPLLB VGA mode also seems to cause problems.
1526 * We should always have it disabled.
1528 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1530 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1531 POSTING_READ(DPLL_MD(pipe));
1535 static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
1537 struct intel_crtc *crtc;
1540 for_each_intel_crtc(&dev_priv->drm, crtc) {
1541 count += crtc->base.state->active &&
1542 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1548 static void i9xx_enable_pll(struct intel_crtc *crtc,
1549 const struct intel_crtc_state *crtc_state)
1551 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1552 i915_reg_t reg = DPLL(crtc->pipe);
1553 u32 dpll = crtc_state->dpll_hw_state.dpll;
1556 assert_pipe_disabled(dev_priv, crtc->pipe);
1558 /* PLL is protected by panel, make sure we can write it */
1559 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
1560 assert_panel_unlocked(dev_priv, crtc->pipe);
1562 /* Enable DVO 2x clock on both PLLs if necessary */
1563 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
1565 * It appears to be important that we don't enable this
1566 * for the current pipe before otherwise configuring the
1567 * PLL. No idea how this should be handled if multiple
1568 * DVO outputs are enabled simultaneosly.
1570 dpll |= DPLL_DVO_2X_MODE;
1571 I915_WRITE(DPLL(!crtc->pipe),
1572 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1576 * Apparently we need to have VGA mode enabled prior to changing
1577 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1578 * dividers, even though the register value does change.
1582 I915_WRITE(reg, dpll);
1584 /* Wait for the clocks to stabilize. */
1588 if (INTEL_GEN(dev_priv) >= 4) {
1589 I915_WRITE(DPLL_MD(crtc->pipe),
1590 crtc_state->dpll_hw_state.dpll_md);
1592 /* The pixel multiplier can only be updated once the
1593 * DPLL is enabled and the clocks are stable.
1595 * So write it again.
1597 I915_WRITE(reg, dpll);
1600 /* We do this three times for luck */
1601 for (i = 0; i < 3; i++) {
1602 I915_WRITE(reg, dpll);
1604 udelay(150); /* wait for warmup */
1608 static void i9xx_disable_pll(struct intel_crtc *crtc)
1610 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1611 enum pipe pipe = crtc->pipe;
1613 /* Disable DVO 2x clock on both PLLs if necessary */
1614 if (IS_I830(dev_priv) &&
1615 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) &&
1616 !intel_num_dvo_pipes(dev_priv)) {
1617 I915_WRITE(DPLL(PIPE_B),
1618 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1619 I915_WRITE(DPLL(PIPE_A),
1620 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1623 /* Don't disable pipe or pipe PLLs if needed */
1624 if (IS_I830(dev_priv))
1627 /* Make sure the pipe isn't still relying on us */
1628 assert_pipe_disabled(dev_priv, pipe);
1630 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1631 POSTING_READ(DPLL(pipe));
1634 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1638 /* Make sure the pipe isn't still relying on us */
1639 assert_pipe_disabled(dev_priv, pipe);
1641 val = DPLL_INTEGRATED_REF_CLK_VLV |
1642 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1644 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1646 I915_WRITE(DPLL(pipe), val);
1647 POSTING_READ(DPLL(pipe));
1650 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1652 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1655 /* Make sure the pipe isn't still relying on us */
1656 assert_pipe_disabled(dev_priv, pipe);
1658 val = DPLL_SSC_REF_CLK_CHV |
1659 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1661 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1663 I915_WRITE(DPLL(pipe), val);
1664 POSTING_READ(DPLL(pipe));
1666 mutex_lock(&dev_priv->sb_lock);
1668 /* Disable 10bit clock to display controller */
1669 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1670 val &= ~DPIO_DCLKP_EN;
1671 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1673 mutex_unlock(&dev_priv->sb_lock);
1676 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1677 struct intel_digital_port *dport,
1678 unsigned int expected_mask)
1681 i915_reg_t dpll_reg;
1683 switch (dport->base.port) {
1685 port_mask = DPLL_PORTB_READY_MASK;
1689 port_mask = DPLL_PORTC_READY_MASK;
1691 expected_mask <<= 4;
1694 port_mask = DPLL_PORTD_READY_MASK;
1695 dpll_reg = DPIO_PHY_STATUS;
1701 if (intel_wait_for_register(dev_priv,
1702 dpll_reg, port_mask, expected_mask,
1704 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1705 port_name(dport->base.port),
1706 I915_READ(dpll_reg) & port_mask, expected_mask);
1709 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1712 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
1715 uint32_t val, pipeconf_val;
1717 /* Make sure PCH DPLL is enabled */
1718 assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll);
1720 /* FDI must be feeding us bits for PCH ports */
1721 assert_fdi_tx_enabled(dev_priv, pipe);
1722 assert_fdi_rx_enabled(dev_priv, pipe);
1724 if (HAS_PCH_CPT(dev_priv)) {
1725 /* Workaround: Set the timing override bit before enabling the
1726 * pch transcoder. */
1727 reg = TRANS_CHICKEN2(pipe);
1728 val = I915_READ(reg);
1729 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1730 I915_WRITE(reg, val);
1733 reg = PCH_TRANSCONF(pipe);
1734 val = I915_READ(reg);
1735 pipeconf_val = I915_READ(PIPECONF(pipe));
1737 if (HAS_PCH_IBX(dev_priv)) {
1739 * Make the BPC in transcoder be consistent with
1740 * that in pipeconf reg. For HDMI we must use 8bpc
1741 * here for both 8bpc and 12bpc.
1743 val &= ~PIPECONF_BPC_MASK;
1744 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI))
1745 val |= PIPECONF_8BPC;
1747 val |= pipeconf_val & PIPECONF_BPC_MASK;
1750 val &= ~TRANS_INTERLACE_MASK;
1751 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1752 if (HAS_PCH_IBX(dev_priv) &&
1753 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
1754 val |= TRANS_LEGACY_INTERLACED_ILK;
1756 val |= TRANS_INTERLACED;
1758 val |= TRANS_PROGRESSIVE;
1760 I915_WRITE(reg, val | TRANS_ENABLE);
1761 if (intel_wait_for_register(dev_priv,
1762 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1764 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1767 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1768 enum transcoder cpu_transcoder)
1770 u32 val, pipeconf_val;
1772 /* FDI must be feeding us bits for PCH ports */
1773 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1774 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1776 /* Workaround: set timing override bit. */
1777 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1778 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1779 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1782 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1784 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1785 PIPECONF_INTERLACED_ILK)
1786 val |= TRANS_INTERLACED;
1788 val |= TRANS_PROGRESSIVE;
1790 I915_WRITE(LPT_TRANSCONF, val);
1791 if (intel_wait_for_register(dev_priv,
1796 DRM_ERROR("Failed to enable PCH transcoder\n");
1799 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1805 /* FDI relies on the transcoder */
1806 assert_fdi_tx_disabled(dev_priv, pipe);
1807 assert_fdi_rx_disabled(dev_priv, pipe);
1809 /* Ports must be off as well */
1810 assert_pch_ports_disabled(dev_priv, pipe);
1812 reg = PCH_TRANSCONF(pipe);
1813 val = I915_READ(reg);
1814 val &= ~TRANS_ENABLE;
1815 I915_WRITE(reg, val);
1816 /* wait for PCH transcoder off, transcoder state */
1817 if (intel_wait_for_register(dev_priv,
1818 reg, TRANS_STATE_ENABLE, 0,
1820 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1822 if (HAS_PCH_CPT(dev_priv)) {
1823 /* Workaround: Clear the timing override chicken bit again. */
1824 reg = TRANS_CHICKEN2(pipe);
1825 val = I915_READ(reg);
1826 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1827 I915_WRITE(reg, val);
1831 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1835 val = I915_READ(LPT_TRANSCONF);
1836 val &= ~TRANS_ENABLE;
1837 I915_WRITE(LPT_TRANSCONF, val);
1838 /* wait for PCH transcoder off, transcoder state */
1839 if (intel_wait_for_register(dev_priv,
1840 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1842 DRM_ERROR("Failed to disable PCH transcoder\n");
1844 /* Workaround: clear timing override bit. */
1845 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1846 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1847 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1850 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1852 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1854 if (HAS_PCH_LPT(dev_priv))
1860 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1862 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1863 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1864 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1865 enum pipe pipe = crtc->pipe;
1869 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1871 assert_planes_disabled(crtc);
1874 * A pipe without a PLL won't actually be able to drive bits from
1875 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1878 if (HAS_GMCH_DISPLAY(dev_priv)) {
1879 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1880 assert_dsi_pll_enabled(dev_priv);
1882 assert_pll_enabled(dev_priv, pipe);
1884 if (new_crtc_state->has_pch_encoder) {
1885 /* if driving the PCH, we need FDI enabled */
1886 assert_fdi_rx_pll_enabled(dev_priv,
1887 intel_crtc_pch_transcoder(crtc));
1888 assert_fdi_tx_pll_enabled(dev_priv,
1889 (enum pipe) cpu_transcoder);
1891 /* FIXME: assert CPU port conditions for SNB+ */
1894 reg = PIPECONF(cpu_transcoder);
1895 val = I915_READ(reg);
1896 if (val & PIPECONF_ENABLE) {
1897 /* we keep both pipes enabled on 830 */
1898 WARN_ON(!IS_I830(dev_priv));
1902 I915_WRITE(reg, val | PIPECONF_ENABLE);
1906 * Until the pipe starts PIPEDSL reads will return a stale value,
1907 * which causes an apparent vblank timestamp jump when PIPEDSL
1908 * resets to its proper value. That also messes up the frame count
1909 * when it's derived from the timestamps. So let's wait for the
1910 * pipe to start properly before we call drm_crtc_vblank_on()
1912 if (dev_priv->drm.max_vblank_count == 0)
1913 intel_wait_for_pipe_scanline_moving(crtc);
1916 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1918 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1919 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1920 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1921 enum pipe pipe = crtc->pipe;
1925 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1928 * Make sure planes won't keep trying to pump pixels to us,
1929 * or we might hang the display.
1931 assert_planes_disabled(crtc);
1933 reg = PIPECONF(cpu_transcoder);
1934 val = I915_READ(reg);
1935 if ((val & PIPECONF_ENABLE) == 0)
1939 * Double wide has implications for planes
1940 * so best keep it disabled when not needed.
1942 if (old_crtc_state->double_wide)
1943 val &= ~PIPECONF_DOUBLE_WIDE;
1945 /* Don't disable pipe or pipe PLLs if needed */
1946 if (!IS_I830(dev_priv))
1947 val &= ~PIPECONF_ENABLE;
1949 I915_WRITE(reg, val);
1950 if ((val & PIPECONF_ENABLE) == 0)
1951 intel_wait_for_pipe_off(old_crtc_state);
1954 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1956 return IS_GEN2(dev_priv) ? 2048 : 4096;
1960 intel_tile_width_bytes(const struct drm_framebuffer *fb, int plane)
1962 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1963 unsigned int cpp = fb->format->cpp[plane];
1965 switch (fb->modifier) {
1966 case DRM_FORMAT_MOD_LINEAR:
1968 case I915_FORMAT_MOD_X_TILED:
1969 if (IS_GEN2(dev_priv))
1973 case I915_FORMAT_MOD_Y_TILED_CCS:
1977 case I915_FORMAT_MOD_Y_TILED:
1978 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1982 case I915_FORMAT_MOD_Yf_TILED_CCS:
1986 case I915_FORMAT_MOD_Yf_TILED:
2002 MISSING_CASE(fb->modifier);
2008 intel_tile_height(const struct drm_framebuffer *fb, int plane)
2010 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
2013 return intel_tile_size(to_i915(fb->dev)) /
2014 intel_tile_width_bytes(fb, plane);
2017 /* Return the tile dimensions in pixel units */
2018 static void intel_tile_dims(const struct drm_framebuffer *fb, int plane,
2019 unsigned int *tile_width,
2020 unsigned int *tile_height)
2022 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, plane);
2023 unsigned int cpp = fb->format->cpp[plane];
2025 *tile_width = tile_width_bytes / cpp;
2026 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
2030 intel_fb_align_height(const struct drm_framebuffer *fb,
2031 int plane, unsigned int height)
2033 unsigned int tile_height = intel_tile_height(fb, plane);
2035 return ALIGN(height, tile_height);
2038 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2040 unsigned int size = 0;
2043 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2044 size += rot_info->plane[i].width * rot_info->plane[i].height;
2050 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2051 const struct drm_framebuffer *fb,
2052 unsigned int rotation)
2054 view->type = I915_GGTT_VIEW_NORMAL;
2055 if (drm_rotation_90_or_270(rotation)) {
2056 view->type = I915_GGTT_VIEW_ROTATED;
2057 view->rotated = to_intel_framebuffer(fb)->rot_info;
2061 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2063 if (IS_I830(dev_priv))
2065 else if (IS_I85X(dev_priv))
2067 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2073 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2075 if (INTEL_GEN(dev_priv) >= 9)
2077 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2078 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2080 else if (INTEL_GEN(dev_priv) >= 4)
2086 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2089 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2091 /* AUX_DIST needs only 4K alignment */
2095 switch (fb->modifier) {
2096 case DRM_FORMAT_MOD_LINEAR:
2097 return intel_linear_alignment(dev_priv);
2098 case I915_FORMAT_MOD_X_TILED:
2099 if (INTEL_GEN(dev_priv) >= 9)
2102 case I915_FORMAT_MOD_Y_TILED_CCS:
2103 case I915_FORMAT_MOD_Yf_TILED_CCS:
2104 case I915_FORMAT_MOD_Y_TILED:
2105 case I915_FORMAT_MOD_Yf_TILED:
2106 return 1 * 1024 * 1024;
2108 MISSING_CASE(fb->modifier);
2113 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2115 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2116 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2118 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
2122 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2123 unsigned int rotation,
2125 unsigned long *out_flags)
2127 struct drm_device *dev = fb->dev;
2128 struct drm_i915_private *dev_priv = to_i915(dev);
2129 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2130 struct i915_ggtt_view view;
2131 struct i915_vma *vma;
2132 unsigned int pinctl;
2135 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2137 alignment = intel_surf_alignment(fb, 0);
2139 intel_fill_fb_ggtt_view(&view, fb, rotation);
2141 /* Note that the w/a also requires 64 PTE of padding following the
2142 * bo. We currently fill all unused PTE with the shadow page and so
2143 * we should always have valid PTE following the scanout preventing
2146 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2147 alignment = 256 * 1024;
2150 * Global gtt pte registers are special registers which actually forward
2151 * writes to a chunk of system memory. Which means that there is no risk
2152 * that the register values disappear as soon as we call
2153 * intel_runtime_pm_put(), so it is correct to wrap only the
2154 * pin/unpin/fence and not more.
2156 intel_runtime_pm_get(dev_priv);
2158 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2162 /* Valleyview is definitely limited to scanning out the first
2163 * 512MiB. Lets presume this behaviour was inherited from the
2164 * g4x display engine and that all earlier gen are similarly
2165 * limited. Testing suggests that it is a little more
2166 * complicated than this. For example, Cherryview appears quite
2167 * happy to scanout from anywhere within its global aperture.
2169 if (HAS_GMCH_DISPLAY(dev_priv))
2170 pinctl |= PIN_MAPPABLE;
2172 vma = i915_gem_object_pin_to_display_plane(obj,
2173 alignment, &view, pinctl);
2177 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2180 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2181 * fence, whereas 965+ only requires a fence if using
2182 * framebuffer compression. For simplicity, we always, when
2183 * possible, install a fence as the cost is not that onerous.
2185 * If we fail to fence the tiled scanout, then either the
2186 * modeset will reject the change (which is highly unlikely as
2187 * the affected systems, all but one, do not have unmappable
2188 * space) or we will not be able to enable full powersaving
2189 * techniques (also likely not to apply due to various limits
2190 * FBC and the like impose on the size of the buffer, which
2191 * presumably we violated anyway with this unmappable buffer).
2192 * Anyway, it is presumably better to stumble onwards with
2193 * something and try to run the system in a "less than optimal"
2194 * mode that matches the user configuration.
2196 ret = i915_vma_pin_fence(vma);
2197 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2198 i915_gem_object_unpin_from_display_plane(vma);
2203 if (ret == 0 && vma->fence)
2204 *out_flags |= PLANE_HAS_FENCE;
2209 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2211 intel_runtime_pm_put(dev_priv);
2215 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2217 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2219 if (flags & PLANE_HAS_FENCE)
2220 i915_vma_unpin_fence(vma);
2221 i915_gem_object_unpin_from_display_plane(vma);
2225 static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
2226 unsigned int rotation)
2228 if (drm_rotation_90_or_270(rotation))
2229 return to_intel_framebuffer(fb)->rotated[plane].pitch;
2231 return fb->pitches[plane];
2235 * Convert the x/y offsets into a linear offset.
2236 * Only valid with 0/180 degree rotation, which is fine since linear
2237 * offset is only used with linear buffers on pre-hsw and tiled buffers
2238 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2240 u32 intel_fb_xy_to_linear(int x, int y,
2241 const struct intel_plane_state *state,
2244 const struct drm_framebuffer *fb = state->base.fb;
2245 unsigned int cpp = fb->format->cpp[plane];
2246 unsigned int pitch = fb->pitches[plane];
2248 return y * pitch + x * cpp;
2252 * Add the x/y offsets derived from fb->offsets[] to the user
2253 * specified plane src x/y offsets. The resulting x/y offsets
2254 * specify the start of scanout from the beginning of the gtt mapping.
2256 void intel_add_fb_offsets(int *x, int *y,
2257 const struct intel_plane_state *state,
2261 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2262 unsigned int rotation = state->base.rotation;
2264 if (drm_rotation_90_or_270(rotation)) {
2265 *x += intel_fb->rotated[plane].x;
2266 *y += intel_fb->rotated[plane].y;
2268 *x += intel_fb->normal[plane].x;
2269 *y += intel_fb->normal[plane].y;
2273 static u32 __intel_adjust_tile_offset(int *x, int *y,
2274 unsigned int tile_width,
2275 unsigned int tile_height,
2276 unsigned int tile_size,
2277 unsigned int pitch_tiles,
2281 unsigned int pitch_pixels = pitch_tiles * tile_width;
2284 WARN_ON(old_offset & (tile_size - 1));
2285 WARN_ON(new_offset & (tile_size - 1));
2286 WARN_ON(new_offset > old_offset);
2288 tiles = (old_offset - new_offset) / tile_size;
2290 *y += tiles / pitch_tiles * tile_height;
2291 *x += tiles % pitch_tiles * tile_width;
2293 /* minimize x in case it got needlessly big */
2294 *y += *x / pitch_pixels * tile_height;
2300 static u32 _intel_adjust_tile_offset(int *x, int *y,
2301 const struct drm_framebuffer *fb, int plane,
2302 unsigned int rotation,
2303 u32 old_offset, u32 new_offset)
2305 const struct drm_i915_private *dev_priv = to_i915(fb->dev);
2306 unsigned int cpp = fb->format->cpp[plane];
2307 unsigned int pitch = intel_fb_pitch(fb, plane, rotation);
2309 WARN_ON(new_offset > old_offset);
2311 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2312 unsigned int tile_size, tile_width, tile_height;
2313 unsigned int pitch_tiles;
2315 tile_size = intel_tile_size(dev_priv);
2316 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2318 if (drm_rotation_90_or_270(rotation)) {
2319 pitch_tiles = pitch / tile_height;
2320 swap(tile_width, tile_height);
2322 pitch_tiles = pitch / (tile_width * cpp);
2325 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2326 tile_size, pitch_tiles,
2327 old_offset, new_offset);
2329 old_offset += *y * pitch + *x * cpp;
2331 *y = (old_offset - new_offset) / pitch;
2332 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2339 * Adjust the tile offset by moving the difference into
2342 static u32 intel_adjust_tile_offset(int *x, int *y,
2343 const struct intel_plane_state *state, int plane,
2344 u32 old_offset, u32 new_offset)
2346 return _intel_adjust_tile_offset(x, y, state->base.fb, plane,
2347 state->base.rotation,
2348 old_offset, new_offset);
2352 * Computes the linear offset to the base tile and adjusts
2353 * x, y. bytes per pixel is assumed to be a power-of-two.
2355 * In the 90/270 rotated case, x and y are assumed
2356 * to be already rotated to match the rotated GTT view, and
2357 * pitch is the tile_height aligned framebuffer height.
2359 * This function is used when computing the derived information
2360 * under intel_framebuffer, so using any of that information
2361 * here is not allowed. Anything under drm_framebuffer can be
2362 * used. This is why the user has to pass in the pitch since it
2363 * is specified in the rotated orientation.
2365 static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv,
2367 const struct drm_framebuffer *fb, int plane,
2369 unsigned int rotation,
2372 uint64_t fb_modifier = fb->modifier;
2373 unsigned int cpp = fb->format->cpp[plane];
2374 u32 offset, offset_aligned;
2379 if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
2380 unsigned int tile_size, tile_width, tile_height;
2381 unsigned int tile_rows, tiles, pitch_tiles;
2383 tile_size = intel_tile_size(dev_priv);
2384 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2386 if (drm_rotation_90_or_270(rotation)) {
2387 pitch_tiles = pitch / tile_height;
2388 swap(tile_width, tile_height);
2390 pitch_tiles = pitch / (tile_width * cpp);
2393 tile_rows = *y / tile_height;
2396 tiles = *x / tile_width;
2399 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2400 offset_aligned = offset & ~alignment;
2402 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2403 tile_size, pitch_tiles,
2404 offset, offset_aligned);
2406 offset = *y * pitch + *x * cpp;
2407 offset_aligned = offset & ~alignment;
2409 *y = (offset & alignment) / pitch;
2410 *x = ((offset & alignment) - *y * pitch) / cpp;
2413 return offset_aligned;
2416 u32 intel_compute_tile_offset(int *x, int *y,
2417 const struct intel_plane_state *state,
2420 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2421 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2422 const struct drm_framebuffer *fb = state->base.fb;
2423 unsigned int rotation = state->base.rotation;
2424 int pitch = intel_fb_pitch(fb, plane, rotation);
2427 if (intel_plane->id == PLANE_CURSOR)
2428 alignment = intel_cursor_alignment(dev_priv);
2430 alignment = intel_surf_alignment(fb, plane);
2432 return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch,
2433 rotation, alignment);
2436 /* Convert the fb->offset[] into x/y offsets */
2437 static int intel_fb_offset_to_xy(int *x, int *y,
2438 const struct drm_framebuffer *fb, int plane)
2440 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2442 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2443 fb->offsets[plane] % intel_tile_size(dev_priv))
2449 _intel_adjust_tile_offset(x, y,
2450 fb, plane, DRM_MODE_ROTATE_0,
2451 fb->offsets[plane], 0);
2456 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2458 switch (fb_modifier) {
2459 case I915_FORMAT_MOD_X_TILED:
2460 return I915_TILING_X;
2461 case I915_FORMAT_MOD_Y_TILED:
2462 case I915_FORMAT_MOD_Y_TILED_CCS:
2463 return I915_TILING_Y;
2465 return I915_TILING_NONE;
2470 * From the Sky Lake PRM:
2471 * "The Color Control Surface (CCS) contains the compression status of
2472 * the cache-line pairs. The compression state of the cache-line pair
2473 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2474 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2475 * cache-line-pairs. CCS is always Y tiled."
2477 * Since cache line pairs refers to horizontally adjacent cache lines,
2478 * each cache line in the CCS corresponds to an area of 32x16 cache
2479 * lines on the main surface. Since each pixel is 4 bytes, this gives
2480 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2483 static const struct drm_format_info ccs_formats[] = {
2484 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2485 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2486 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2487 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2490 static const struct drm_format_info *
2491 lookup_format_info(const struct drm_format_info formats[],
2492 int num_formats, u32 format)
2496 for (i = 0; i < num_formats; i++) {
2497 if (formats[i].format == format)
2504 static const struct drm_format_info *
2505 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2507 switch (cmd->modifier[0]) {
2508 case I915_FORMAT_MOD_Y_TILED_CCS:
2509 case I915_FORMAT_MOD_Yf_TILED_CCS:
2510 return lookup_format_info(ccs_formats,
2511 ARRAY_SIZE(ccs_formats),
2519 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2520 struct drm_framebuffer *fb)
2522 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2523 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2524 u32 gtt_offset_rotated = 0;
2525 unsigned int max_size = 0;
2526 int i, num_planes = fb->format->num_planes;
2527 unsigned int tile_size = intel_tile_size(dev_priv);
2529 for (i = 0; i < num_planes; i++) {
2530 unsigned int width, height;
2531 unsigned int cpp, size;
2536 cpp = fb->format->cpp[i];
2537 width = drm_framebuffer_plane_width(fb->width, fb, i);
2538 height = drm_framebuffer_plane_height(fb->height, fb, i);
2540 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2542 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2547 if ((fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2548 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) && i == 1) {
2549 int hsub = fb->format->hsub;
2550 int vsub = fb->format->vsub;
2551 int tile_width, tile_height;
2555 intel_tile_dims(fb, i, &tile_width, &tile_height);
2557 tile_height *= vsub;
2559 ccs_x = (x * hsub) % tile_width;
2560 ccs_y = (y * vsub) % tile_height;
2561 main_x = intel_fb->normal[0].x % tile_width;
2562 main_y = intel_fb->normal[0].y % tile_height;
2565 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2566 * x/y offsets must match between CCS and the main surface.
2568 if (main_x != ccs_x || main_y != ccs_y) {
2569 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2572 intel_fb->normal[0].x,
2573 intel_fb->normal[0].y,
2580 * The fence (if used) is aligned to the start of the object
2581 * so having the framebuffer wrap around across the edge of the
2582 * fenced region doesn't really work. We have no API to configure
2583 * the fence start offset within the object (nor could we probably
2584 * on gen2/3). So it's just easier if we just require that the
2585 * fb layout agrees with the fence layout. We already check that the
2586 * fb stride matches the fence stride elsewhere.
2588 if (i == 0 && i915_gem_object_is_tiled(intel_fb->obj) &&
2589 (x + width) * cpp > fb->pitches[i]) {
2590 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2596 * First pixel of the framebuffer from
2597 * the start of the normal gtt mapping.
2599 intel_fb->normal[i].x = x;
2600 intel_fb->normal[i].y = y;
2602 offset = _intel_compute_tile_offset(dev_priv, &x, &y,
2603 fb, i, fb->pitches[i],
2604 DRM_MODE_ROTATE_0, tile_size);
2605 offset /= tile_size;
2607 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2608 unsigned int tile_width, tile_height;
2609 unsigned int pitch_tiles;
2612 intel_tile_dims(fb, i, &tile_width, &tile_height);
2614 rot_info->plane[i].offset = offset;
2615 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2616 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2617 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2619 intel_fb->rotated[i].pitch =
2620 rot_info->plane[i].height * tile_height;
2622 /* how many tiles does this plane need */
2623 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2625 * If the plane isn't horizontally tile aligned,
2626 * we need one more tile.
2631 /* rotate the x/y offsets to match the GTT view */
2637 rot_info->plane[i].width * tile_width,
2638 rot_info->plane[i].height * tile_height,
2639 DRM_MODE_ROTATE_270);
2643 /* rotate the tile dimensions to match the GTT view */
2644 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2645 swap(tile_width, tile_height);
2648 * We only keep the x/y offsets, so push all of the
2649 * gtt offset into the x/y offsets.
2651 __intel_adjust_tile_offset(&x, &y,
2652 tile_width, tile_height,
2653 tile_size, pitch_tiles,
2654 gtt_offset_rotated * tile_size, 0);
2656 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2659 * First pixel of the framebuffer from
2660 * the start of the rotated gtt mapping.
2662 intel_fb->rotated[i].x = x;
2663 intel_fb->rotated[i].y = y;
2665 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2666 x * cpp, tile_size);
2669 /* how many tiles in total needed in the bo */
2670 max_size = max(max_size, offset + size);
2673 if (max_size * tile_size > intel_fb->obj->base.size) {
2674 DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
2675 max_size * tile_size, intel_fb->obj->base.size);
2682 static int i9xx_format_to_fourcc(int format)
2685 case DISPPLANE_8BPP:
2686 return DRM_FORMAT_C8;
2687 case DISPPLANE_BGRX555:
2688 return DRM_FORMAT_XRGB1555;
2689 case DISPPLANE_BGRX565:
2690 return DRM_FORMAT_RGB565;
2692 case DISPPLANE_BGRX888:
2693 return DRM_FORMAT_XRGB8888;
2694 case DISPPLANE_RGBX888:
2695 return DRM_FORMAT_XBGR8888;
2696 case DISPPLANE_BGRX101010:
2697 return DRM_FORMAT_XRGB2101010;
2698 case DISPPLANE_RGBX101010:
2699 return DRM_FORMAT_XBGR2101010;
2703 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2706 case PLANE_CTL_FORMAT_RGB_565:
2707 return DRM_FORMAT_RGB565;
2708 case PLANE_CTL_FORMAT_NV12:
2709 return DRM_FORMAT_NV12;
2711 case PLANE_CTL_FORMAT_XRGB_8888:
2714 return DRM_FORMAT_ABGR8888;
2716 return DRM_FORMAT_XBGR8888;
2719 return DRM_FORMAT_ARGB8888;
2721 return DRM_FORMAT_XRGB8888;
2723 case PLANE_CTL_FORMAT_XRGB_2101010:
2725 return DRM_FORMAT_XBGR2101010;
2727 return DRM_FORMAT_XRGB2101010;
2732 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2733 struct intel_initial_plane_config *plane_config)
2735 struct drm_device *dev = crtc->base.dev;
2736 struct drm_i915_private *dev_priv = to_i915(dev);
2737 struct drm_i915_gem_object *obj = NULL;
2738 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2739 struct drm_framebuffer *fb = &plane_config->fb->base;
2740 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2741 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2744 size_aligned -= base_aligned;
2746 if (plane_config->size == 0)
2749 /* If the FB is too big, just don't use it since fbdev is not very
2750 * important and we should probably use that space with FBC or other
2752 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2755 mutex_lock(&dev->struct_mutex);
2756 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2760 mutex_unlock(&dev->struct_mutex);
2764 if (plane_config->tiling == I915_TILING_X)
2765 obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X;
2767 mode_cmd.pixel_format = fb->format->format;
2768 mode_cmd.width = fb->width;
2769 mode_cmd.height = fb->height;
2770 mode_cmd.pitches[0] = fb->pitches[0];
2771 mode_cmd.modifier[0] = fb->modifier;
2772 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2774 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2775 DRM_DEBUG_KMS("intel fb init failed\n");
2780 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2784 i915_gem_object_put(obj);
2789 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2790 struct intel_plane_state *plane_state,
2793 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2795 plane_state->base.visible = visible;
2797 /* FIXME pre-g4x don't work like this */
2799 crtc_state->base.plane_mask |= BIT(drm_plane_index(&plane->base));
2800 crtc_state->active_planes |= BIT(plane->id);
2802 crtc_state->base.plane_mask &= ~BIT(drm_plane_index(&plane->base));
2803 crtc_state->active_planes &= ~BIT(plane->id);
2806 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2807 crtc_state->base.crtc->name,
2808 crtc_state->active_planes);
2811 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2812 struct intel_plane *plane)
2814 struct intel_crtc_state *crtc_state =
2815 to_intel_crtc_state(crtc->base.state);
2816 struct intel_plane_state *plane_state =
2817 to_intel_plane_state(plane->base.state);
2819 intel_set_plane_visible(crtc_state, plane_state, false);
2821 if (plane->id == PLANE_PRIMARY)
2822 intel_pre_disable_primary_noatomic(&crtc->base);
2824 trace_intel_disable_plane(&plane->base, crtc);
2825 plane->disable_plane(plane, crtc);
2829 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2830 struct intel_initial_plane_config *plane_config)
2832 struct drm_device *dev = intel_crtc->base.dev;
2833 struct drm_i915_private *dev_priv = to_i915(dev);
2835 struct drm_i915_gem_object *obj;
2836 struct drm_plane *primary = intel_crtc->base.primary;
2837 struct drm_plane_state *plane_state = primary->state;
2838 struct drm_crtc_state *crtc_state = intel_crtc->base.state;
2839 struct intel_plane *intel_plane = to_intel_plane(primary);
2840 struct intel_plane_state *intel_state =
2841 to_intel_plane_state(plane_state);
2842 struct drm_framebuffer *fb;
2844 if (!plane_config->fb)
2847 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2848 fb = &plane_config->fb->base;
2852 kfree(plane_config->fb);
2855 * Failed to alloc the obj, check to see if we should share
2856 * an fb with another CRTC instead
2858 for_each_crtc(dev, c) {
2859 struct intel_plane_state *state;
2861 if (c == &intel_crtc->base)
2864 if (!to_intel_crtc(c)->active)
2867 state = to_intel_plane_state(c->primary->state);
2871 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2872 fb = state->base.fb;
2873 drm_framebuffer_get(fb);
2879 * We've failed to reconstruct the BIOS FB. Current display state
2880 * indicates that the primary plane is visible, but has a NULL FB,
2881 * which will lead to problems later if we don't fix it up. The
2882 * simplest solution is to just disable the primary plane now and
2883 * pretend the BIOS never had it enabled.
2885 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2890 mutex_lock(&dev->struct_mutex);
2892 intel_pin_and_fence_fb_obj(fb,
2893 primary->state->rotation,
2894 intel_plane_uses_fence(intel_state),
2895 &intel_state->flags);
2896 mutex_unlock(&dev->struct_mutex);
2897 if (IS_ERR(intel_state->vma)) {
2898 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2899 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2901 intel_state->vma = NULL;
2902 drm_framebuffer_put(fb);
2906 obj = intel_fb_obj(fb);
2907 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2909 plane_state->src_x = 0;
2910 plane_state->src_y = 0;
2911 plane_state->src_w = fb->width << 16;
2912 plane_state->src_h = fb->height << 16;
2914 plane_state->crtc_x = 0;
2915 plane_state->crtc_y = 0;
2916 plane_state->crtc_w = fb->width;
2917 plane_state->crtc_h = fb->height;
2919 intel_state->base.src = drm_plane_state_src(plane_state);
2920 intel_state->base.dst = drm_plane_state_dest(plane_state);
2922 if (i915_gem_object_is_tiled(obj))
2923 dev_priv->preserve_bios_swizzle = true;
2925 drm_framebuffer_get(fb);
2926 primary->fb = primary->state->fb = fb;
2927 primary->crtc = primary->state->crtc = &intel_crtc->base;
2929 intel_set_plane_visible(to_intel_crtc_state(crtc_state),
2930 to_intel_plane_state(plane_state),
2933 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2934 &obj->frontbuffer_bits);
2937 static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane,
2938 unsigned int rotation)
2940 int cpp = fb->format->cpp[plane];
2942 switch (fb->modifier) {
2943 case DRM_FORMAT_MOD_LINEAR:
2944 case I915_FORMAT_MOD_X_TILED:
2957 case I915_FORMAT_MOD_Y_TILED_CCS:
2958 case I915_FORMAT_MOD_Yf_TILED_CCS:
2959 /* FIXME AUX plane? */
2960 case I915_FORMAT_MOD_Y_TILED:
2961 case I915_FORMAT_MOD_Yf_TILED:
2976 MISSING_CASE(fb->modifier);
2982 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2983 int main_x, int main_y, u32 main_offset)
2985 const struct drm_framebuffer *fb = plane_state->base.fb;
2986 int hsub = fb->format->hsub;
2987 int vsub = fb->format->vsub;
2988 int aux_x = plane_state->aux.x;
2989 int aux_y = plane_state->aux.y;
2990 u32 aux_offset = plane_state->aux.offset;
2991 u32 alignment = intel_surf_alignment(fb, 1);
2993 while (aux_offset >= main_offset && aux_y <= main_y) {
2996 if (aux_x == main_x && aux_y == main_y)
2999 if (aux_offset == 0)
3004 aux_offset = intel_adjust_tile_offset(&x, &y, plane_state, 1,
3005 aux_offset, aux_offset - alignment);
3006 aux_x = x * hsub + aux_x % hsub;
3007 aux_y = y * vsub + aux_y % vsub;
3010 if (aux_x != main_x || aux_y != main_y)
3013 plane_state->aux.offset = aux_offset;
3014 plane_state->aux.x = aux_x;
3015 plane_state->aux.y = aux_y;
3020 static int skl_check_main_surface(const struct intel_crtc_state *crtc_state,
3021 struct intel_plane_state *plane_state)
3023 struct drm_i915_private *dev_priv =
3024 to_i915(plane_state->base.plane->dev);
3025 const struct drm_framebuffer *fb = plane_state->base.fb;
3026 unsigned int rotation = plane_state->base.rotation;
3027 int x = plane_state->base.src.x1 >> 16;
3028 int y = plane_state->base.src.y1 >> 16;
3029 int w = drm_rect_width(&plane_state->base.src) >> 16;
3030 int h = drm_rect_height(&plane_state->base.src) >> 16;
3031 int dst_x = plane_state->base.dst.x1;
3032 int pipe_src_w = crtc_state->pipe_src_w;
3033 int max_width = skl_max_plane_width(fb, 0, rotation);
3034 int max_height = 4096;
3035 u32 alignment, offset, aux_offset = plane_state->aux.offset;
3037 if (w > max_width || h > max_height) {
3038 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3039 w, h, max_width, max_height);
3044 * Display WA #1175: cnl,glk
3045 * Planes other than the cursor may cause FIFO underflow and display
3046 * corruption if starting less than 4 pixels from the right edge of
3048 * Besides the above WA fix the similar problem, where planes other
3049 * than the cursor ending less than 4 pixels from the left edge of the
3050 * screen may cause FIFO underflow and display corruption.
3052 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
3053 (dst_x + w < 4 || dst_x > pipe_src_w - 4)) {
3054 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
3055 dst_x + w < 4 ? "end" : "start",
3056 dst_x + w < 4 ? dst_x + w : dst_x,
3061 intel_add_fb_offsets(&x, &y, plane_state, 0);
3062 offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
3063 alignment = intel_surf_alignment(fb, 0);
3066 * AUX surface offset is specified as the distance from the
3067 * main surface offset, and it must be non-negative. Make
3068 * sure that is what we will get.
3070 if (offset > aux_offset)
3071 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3072 offset, aux_offset & ~(alignment - 1));
3075 * When using an X-tiled surface, the plane blows up
3076 * if the x offset + width exceed the stride.
3078 * TODO: linear and Y-tiled seem fine, Yf untested,
3080 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3081 int cpp = fb->format->cpp[0];
3083 while ((x + w) * cpp > fb->pitches[0]) {
3085 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3089 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3090 offset, offset - alignment);
3095 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3096 * they match with the main surface x/y offsets.
3098 if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
3099 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
3100 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3104 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3105 offset, offset - alignment);
3108 if (x != plane_state->aux.x || y != plane_state->aux.y) {
3109 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3114 plane_state->main.offset = offset;
3115 plane_state->main.x = x;
3116 plane_state->main.y = y;
3122 skl_check_nv12_surface(const struct intel_crtc_state *crtc_state,
3123 struct intel_plane_state *plane_state)
3125 /* Display WA #1106 */
3126 if (plane_state->base.rotation !=
3127 (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90) &&
3128 plane_state->base.rotation != DRM_MODE_ROTATE_270)
3132 * src coordinates are rotated here.
3133 * We check height but report it as width
3135 if (((drm_rect_height(&plane_state->base.src) >> 16) % 4) != 0) {
3136 DRM_DEBUG_KMS("src width must be multiple "
3137 "of 4 for rotated NV12\n");
3144 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3146 const struct drm_framebuffer *fb = plane_state->base.fb;
3147 unsigned int rotation = plane_state->base.rotation;
3148 int max_width = skl_max_plane_width(fb, 1, rotation);
3149 int max_height = 4096;
3150 int x = plane_state->base.src.x1 >> 17;
3151 int y = plane_state->base.src.y1 >> 17;
3152 int w = drm_rect_width(&plane_state->base.src) >> 17;
3153 int h = drm_rect_height(&plane_state->base.src) >> 17;
3156 intel_add_fb_offsets(&x, &y, plane_state, 1);
3157 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3159 /* FIXME not quite sure how/if these apply to the chroma plane */
3160 if (w > max_width || h > max_height) {
3161 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3162 w, h, max_width, max_height);
3166 plane_state->aux.offset = offset;
3167 plane_state->aux.x = x;
3168 plane_state->aux.y = y;
3173 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3175 const struct drm_framebuffer *fb = plane_state->base.fb;
3176 int src_x = plane_state->base.src.x1 >> 16;
3177 int src_y = plane_state->base.src.y1 >> 16;
3178 int hsub = fb->format->hsub;
3179 int vsub = fb->format->vsub;
3180 int x = src_x / hsub;
3181 int y = src_y / vsub;
3184 if (plane_state->base.rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180)) {
3185 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation %x\n",
3186 plane_state->base.rotation);
3190 intel_add_fb_offsets(&x, &y, plane_state, 1);
3191 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3193 plane_state->aux.offset = offset;
3194 plane_state->aux.x = x * hsub + src_x % hsub;
3195 plane_state->aux.y = y * vsub + src_y % vsub;
3200 int skl_check_plane_surface(const struct intel_crtc_state *crtc_state,
3201 struct intel_plane_state *plane_state)
3203 const struct drm_framebuffer *fb = plane_state->base.fb;
3204 unsigned int rotation = plane_state->base.rotation;
3207 if (rotation & DRM_MODE_REFLECT_X &&
3208 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
3209 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
3213 if (!plane_state->base.visible)
3216 /* Rotate src coordinates to match rotated GTT view */
3217 if (drm_rotation_90_or_270(rotation))
3218 drm_rect_rotate(&plane_state->base.src,
3219 fb->width << 16, fb->height << 16,
3220 DRM_MODE_ROTATE_270);
3223 * Handle the AUX surface first since
3224 * the main surface setup depends on it.
3226 if (fb->format->format == DRM_FORMAT_NV12) {
3227 ret = skl_check_nv12_surface(crtc_state, plane_state);
3230 ret = skl_check_nv12_aux_surface(plane_state);
3233 } else if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
3234 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
3235 ret = skl_check_ccs_aux_surface(plane_state);
3239 plane_state->aux.offset = ~0xfff;
3240 plane_state->aux.x = 0;
3241 plane_state->aux.y = 0;
3244 ret = skl_check_main_surface(crtc_state, plane_state);
3251 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3252 const struct intel_plane_state *plane_state)
3254 struct drm_i915_private *dev_priv =
3255 to_i915(plane_state->base.plane->dev);
3256 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3257 const struct drm_framebuffer *fb = plane_state->base.fb;
3258 unsigned int rotation = plane_state->base.rotation;
3261 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
3263 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3264 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
3265 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3267 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3268 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3270 if (INTEL_GEN(dev_priv) < 5)
3271 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3273 switch (fb->format->format) {
3275 dspcntr |= DISPPLANE_8BPP;
3277 case DRM_FORMAT_XRGB1555:
3278 dspcntr |= DISPPLANE_BGRX555;
3280 case DRM_FORMAT_RGB565:
3281 dspcntr |= DISPPLANE_BGRX565;
3283 case DRM_FORMAT_XRGB8888:
3284 dspcntr |= DISPPLANE_BGRX888;
3286 case DRM_FORMAT_XBGR8888:
3287 dspcntr |= DISPPLANE_RGBX888;
3289 case DRM_FORMAT_XRGB2101010:
3290 dspcntr |= DISPPLANE_BGRX101010;
3292 case DRM_FORMAT_XBGR2101010:
3293 dspcntr |= DISPPLANE_RGBX101010;
3296 MISSING_CASE(fb->format->format);
3300 if (INTEL_GEN(dev_priv) >= 4 &&
3301 fb->modifier == I915_FORMAT_MOD_X_TILED)
3302 dspcntr |= DISPPLANE_TILED;
3304 if (rotation & DRM_MODE_ROTATE_180)
3305 dspcntr |= DISPPLANE_ROTATE_180;
3307 if (rotation & DRM_MODE_REFLECT_X)
3308 dspcntr |= DISPPLANE_MIRROR;
3313 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3315 struct drm_i915_private *dev_priv =
3316 to_i915(plane_state->base.plane->dev);
3317 int src_x = plane_state->base.src.x1 >> 16;
3318 int src_y = plane_state->base.src.y1 >> 16;
3321 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3323 if (INTEL_GEN(dev_priv) >= 4)
3324 offset = intel_compute_tile_offset(&src_x, &src_y,
3329 /* HSW/BDW do this automagically in hardware */
3330 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3331 unsigned int rotation = plane_state->base.rotation;
3332 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3333 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3335 if (rotation & DRM_MODE_ROTATE_180) {
3338 } else if (rotation & DRM_MODE_REFLECT_X) {
3343 plane_state->main.offset = offset;
3344 plane_state->main.x = src_x;
3345 plane_state->main.y = src_y;
3350 static void i9xx_update_plane(struct intel_plane *plane,
3351 const struct intel_crtc_state *crtc_state,
3352 const struct intel_plane_state *plane_state)
3354 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3355 const struct drm_framebuffer *fb = plane_state->base.fb;
3356 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3358 u32 dspcntr = plane_state->ctl;
3359 i915_reg_t reg = DSPCNTR(i9xx_plane);
3360 int x = plane_state->main.x;
3361 int y = plane_state->main.y;
3362 unsigned long irqflags;
3365 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3367 if (INTEL_GEN(dev_priv) >= 4)
3368 dspaddr_offset = plane_state->main.offset;
3370 dspaddr_offset = linear_offset;
3372 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3374 if (INTEL_GEN(dev_priv) < 4) {
3375 /* pipesrc and dspsize control the size that is scaled from,
3376 * which should always be the user's requested size.
3378 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3379 ((crtc_state->pipe_src_h - 1) << 16) |
3380 (crtc_state->pipe_src_w - 1));
3381 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3382 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3383 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3384 ((crtc_state->pipe_src_h - 1) << 16) |
3385 (crtc_state->pipe_src_w - 1));
3386 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3387 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3390 I915_WRITE_FW(reg, dspcntr);
3392 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), fb->pitches[0]);
3393 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3394 I915_WRITE_FW(DSPSURF(i9xx_plane),
3395 intel_plane_ggtt_offset(plane_state) +
3397 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3398 } else if (INTEL_GEN(dev_priv) >= 4) {
3399 I915_WRITE_FW(DSPSURF(i9xx_plane),
3400 intel_plane_ggtt_offset(plane_state) +
3402 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3403 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3405 I915_WRITE_FW(DSPADDR(i9xx_plane),
3406 intel_plane_ggtt_offset(plane_state) +
3409 POSTING_READ_FW(reg);
3411 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3414 static void i9xx_disable_plane(struct intel_plane *plane,
3415 struct intel_crtc *crtc)
3417 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3418 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3419 unsigned long irqflags;
3421 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3423 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3424 if (INTEL_GEN(dev_priv) >= 4)
3425 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3427 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3428 POSTING_READ_FW(DSPCNTR(i9xx_plane));
3430 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3433 static bool i9xx_plane_get_hw_state(struct intel_plane *plane)
3435 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3436 enum intel_display_power_domain power_domain;
3437 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3438 enum pipe pipe = plane->pipe;
3442 * Not 100% correct for planes that can move between pipes,
3443 * but that's only the case for gen2-4 which don't have any
3444 * display power wells.
3446 power_domain = POWER_DOMAIN_PIPE(pipe);
3447 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3450 ret = I915_READ(DSPCNTR(i9xx_plane)) & DISPLAY_PLANE_ENABLE;
3452 intel_display_power_put(dev_priv, power_domain);
3458 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int plane)
3460 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3463 return intel_tile_width_bytes(fb, plane);
3466 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3468 struct drm_device *dev = intel_crtc->base.dev;
3469 struct drm_i915_private *dev_priv = to_i915(dev);
3471 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3472 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3473 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3477 * This function detaches (aka. unbinds) unused scalers in hardware
3479 static void skl_detach_scalers(struct intel_crtc *intel_crtc)
3481 struct intel_crtc_scaler_state *scaler_state;
3484 scaler_state = &intel_crtc->config->scaler_state;
3486 /* loop through and disable scalers that aren't in use */
3487 for (i = 0; i < intel_crtc->num_scalers; i++) {
3488 if (!scaler_state->scalers[i].in_use)
3489 skl_detach_scaler(intel_crtc, i);
3493 u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
3494 unsigned int rotation)
3498 if (plane >= fb->format->num_planes)
3501 stride = intel_fb_pitch(fb, plane, rotation);
3504 * The stride is either expressed as a multiple of 64 bytes chunks for
3505 * linear buffers or in number of tiles for tiled buffers.
3507 if (drm_rotation_90_or_270(rotation))
3508 stride /= intel_tile_height(fb, plane);
3510 stride /= intel_fb_stride_alignment(fb, plane);
3515 static u32 skl_plane_ctl_format(uint32_t pixel_format)
3517 switch (pixel_format) {
3519 return PLANE_CTL_FORMAT_INDEXED;
3520 case DRM_FORMAT_RGB565:
3521 return PLANE_CTL_FORMAT_RGB_565;
3522 case DRM_FORMAT_XBGR8888:
3523 case DRM_FORMAT_ABGR8888:
3524 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3525 case DRM_FORMAT_XRGB8888:
3526 case DRM_FORMAT_ARGB8888:
3527 return PLANE_CTL_FORMAT_XRGB_8888;
3528 case DRM_FORMAT_XRGB2101010:
3529 return PLANE_CTL_FORMAT_XRGB_2101010;
3530 case DRM_FORMAT_XBGR2101010:
3531 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3532 case DRM_FORMAT_YUYV:
3533 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3534 case DRM_FORMAT_YVYU:
3535 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3536 case DRM_FORMAT_UYVY:
3537 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3538 case DRM_FORMAT_VYUY:
3539 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3540 case DRM_FORMAT_NV12:
3541 return PLANE_CTL_FORMAT_NV12;
3543 MISSING_CASE(pixel_format);
3550 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3551 * to be already pre-multiplied. We need to add a knob (or a different
3552 * DRM_FORMAT) for user-space to configure that.
3554 static u32 skl_plane_ctl_alpha(uint32_t pixel_format)
3556 switch (pixel_format) {
3557 case DRM_FORMAT_ABGR8888:
3558 case DRM_FORMAT_ARGB8888:
3559 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3561 return PLANE_CTL_ALPHA_DISABLE;
3565 static u32 glk_plane_color_ctl_alpha(uint32_t pixel_format)
3567 switch (pixel_format) {
3568 case DRM_FORMAT_ABGR8888:
3569 case DRM_FORMAT_ARGB8888:
3570 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3572 return PLANE_COLOR_ALPHA_DISABLE;
3576 static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
3578 switch (fb_modifier) {
3579 case DRM_FORMAT_MOD_LINEAR:
3581 case I915_FORMAT_MOD_X_TILED:
3582 return PLANE_CTL_TILED_X;
3583 case I915_FORMAT_MOD_Y_TILED:
3584 return PLANE_CTL_TILED_Y;
3585 case I915_FORMAT_MOD_Y_TILED_CCS:
3586 return PLANE_CTL_TILED_Y | PLANE_CTL_DECOMPRESSION_ENABLE;
3587 case I915_FORMAT_MOD_Yf_TILED:
3588 return PLANE_CTL_TILED_YF;
3589 case I915_FORMAT_MOD_Yf_TILED_CCS:
3590 return PLANE_CTL_TILED_YF | PLANE_CTL_DECOMPRESSION_ENABLE;
3592 MISSING_CASE(fb_modifier);
3598 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3601 case DRM_MODE_ROTATE_0:
3604 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3605 * while i915 HW rotation is clockwise, thats why this swapping.
3607 case DRM_MODE_ROTATE_90:
3608 return PLANE_CTL_ROTATE_270;
3609 case DRM_MODE_ROTATE_180:
3610 return PLANE_CTL_ROTATE_180;
3611 case DRM_MODE_ROTATE_270:
3612 return PLANE_CTL_ROTATE_90;
3614 MISSING_CASE(rotate);
3620 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3625 case DRM_MODE_REFLECT_X:
3626 return PLANE_CTL_FLIP_HORIZONTAL;
3627 case DRM_MODE_REFLECT_Y:
3629 MISSING_CASE(reflect);
3635 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3636 const struct intel_plane_state *plane_state)
3638 struct drm_i915_private *dev_priv =
3639 to_i915(plane_state->base.plane->dev);
3640 const struct drm_framebuffer *fb = plane_state->base.fb;
3641 unsigned int rotation = plane_state->base.rotation;
3642 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3645 plane_ctl = PLANE_CTL_ENABLE;
3647 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3648 plane_ctl |= skl_plane_ctl_alpha(fb->format->format);
3650 PLANE_CTL_PIPE_GAMMA_ENABLE |
3651 PLANE_CTL_PIPE_CSC_ENABLE |
3652 PLANE_CTL_PLANE_GAMMA_DISABLE;
3654 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3655 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3657 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3658 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3661 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3662 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3663 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3665 if (INTEL_GEN(dev_priv) >= 10)
3666 plane_ctl |= cnl_plane_ctl_flip(rotation &
3667 DRM_MODE_REFLECT_MASK);
3669 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3670 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3671 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3672 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3677 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3678 const struct intel_plane_state *plane_state)
3680 struct drm_i915_private *dev_priv =
3681 to_i915(plane_state->base.plane->dev);
3682 const struct drm_framebuffer *fb = plane_state->base.fb;
3683 u32 plane_color_ctl = 0;
3685 if (INTEL_GEN(dev_priv) < 11) {
3686 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3687 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3689 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3690 plane_color_ctl |= glk_plane_color_ctl_alpha(fb->format->format);
3692 if (intel_format_is_yuv(fb->format->format)) {
3693 if (fb->format->format == DRM_FORMAT_NV12) {
3695 PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3698 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3699 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3701 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
3703 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3704 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3707 return plane_color_ctl;
3711 __intel_display_resume(struct drm_device *dev,
3712 struct drm_atomic_state *state,
3713 struct drm_modeset_acquire_ctx *ctx)
3715 struct drm_crtc_state *crtc_state;
3716 struct drm_crtc *crtc;
3719 intel_modeset_setup_hw_state(dev, ctx);
3720 i915_redisable_vga(to_i915(dev));
3726 * We've duplicated the state, pointers to the old state are invalid.
3728 * Don't attempt to use the old state until we commit the duplicated state.
3730 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3732 * Force recalculation even if we restore
3733 * current state. With fast modeset this may not result
3734 * in a modeset when the state is compatible.
3736 crtc_state->mode_changed = true;
3739 /* ignore any reset values/BIOS leftovers in the WM registers */
3740 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3741 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3743 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3745 WARN_ON(ret == -EDEADLK);
3749 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3751 return intel_has_gpu_reset(dev_priv) &&
3752 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
3755 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3757 struct drm_device *dev = &dev_priv->drm;
3758 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3759 struct drm_atomic_state *state;
3762 /* reset doesn't touch the display */
3763 if (!i915_modparams.force_reset_modeset_test &&
3764 !gpu_reset_clobbers_display(dev_priv))
3767 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3768 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3769 wake_up_all(&dev_priv->gpu_error.wait_queue);
3771 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3772 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3773 i915_gem_set_wedged(dev_priv);
3777 * Need mode_config.mutex so that we don't
3778 * trample ongoing ->detect() and whatnot.
3780 mutex_lock(&dev->mode_config.mutex);
3781 drm_modeset_acquire_init(ctx, 0);
3783 ret = drm_modeset_lock_all_ctx(dev, ctx);
3784 if (ret != -EDEADLK)
3787 drm_modeset_backoff(ctx);
3790 * Disabling the crtcs gracefully seems nicer. Also the
3791 * g33 docs say we should at least disable all the planes.
3793 state = drm_atomic_helper_duplicate_state(dev, ctx);
3794 if (IS_ERR(state)) {
3795 ret = PTR_ERR(state);
3796 DRM_ERROR("Duplicating state failed with %i\n", ret);
3800 ret = drm_atomic_helper_disable_all(dev, ctx);
3802 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3803 drm_atomic_state_put(state);
3807 dev_priv->modeset_restore_state = state;
3808 state->acquire_ctx = ctx;
3811 void intel_finish_reset(struct drm_i915_private *dev_priv)
3813 struct drm_device *dev = &dev_priv->drm;
3814 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3815 struct drm_atomic_state *state;
3818 /* reset doesn't touch the display */
3819 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
3822 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3826 /* reset doesn't touch the display */
3827 if (!gpu_reset_clobbers_display(dev_priv)) {
3828 /* for testing only restore the display */
3829 ret = __intel_display_resume(dev, state, ctx);
3831 DRM_ERROR("Restoring old state failed with %i\n", ret);
3834 * The display has been reset as well,
3835 * so need a full re-initialization.
3837 intel_runtime_pm_disable_interrupts(dev_priv);
3838 intel_runtime_pm_enable_interrupts(dev_priv);
3840 intel_pps_unlock_regs_wa(dev_priv);
3841 intel_modeset_init_hw(dev);
3842 intel_init_clock_gating(dev_priv);
3844 spin_lock_irq(&dev_priv->irq_lock);
3845 if (dev_priv->display.hpd_irq_setup)
3846 dev_priv->display.hpd_irq_setup(dev_priv);
3847 spin_unlock_irq(&dev_priv->irq_lock);
3849 ret = __intel_display_resume(dev, state, ctx);
3851 DRM_ERROR("Restoring old state failed with %i\n", ret);
3853 intel_hpd_init(dev_priv);
3856 drm_atomic_state_put(state);
3858 drm_modeset_drop_locks(ctx);
3859 drm_modeset_acquire_fini(ctx);
3860 mutex_unlock(&dev->mode_config.mutex);
3862 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3865 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3866 const struct intel_crtc_state *new_crtc_state)
3868 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
3869 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3871 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3872 crtc->base.mode = new_crtc_state->base.mode;
3875 * Update pipe size and adjust fitter if needed: the reason for this is
3876 * that in compute_mode_changes we check the native mode (not the pfit
3877 * mode) to see if we can flip rather than do a full mode set. In the
3878 * fastboot case, we'll flip, but if we don't update the pipesrc and
3879 * pfit state, we'll end up with a big fb scanned out into the wrong
3883 I915_WRITE(PIPESRC(crtc->pipe),
3884 ((new_crtc_state->pipe_src_w - 1) << 16) |
3885 (new_crtc_state->pipe_src_h - 1));
3887 /* on skylake this is done by detaching scalers */
3888 if (INTEL_GEN(dev_priv) >= 9) {
3889 skl_detach_scalers(crtc);
3891 if (new_crtc_state->pch_pfit.enabled)
3892 skylake_pfit_enable(crtc);
3893 } else if (HAS_PCH_SPLIT(dev_priv)) {
3894 if (new_crtc_state->pch_pfit.enabled)
3895 ironlake_pfit_enable(crtc);
3896 else if (old_crtc_state->pch_pfit.enabled)
3897 ironlake_pfit_disable(crtc, true);
3901 static void intel_fdi_normal_train(struct intel_crtc *crtc)
3903 struct drm_device *dev = crtc->base.dev;
3904 struct drm_i915_private *dev_priv = to_i915(dev);
3905 int pipe = crtc->pipe;
3909 /* enable normal train */
3910 reg = FDI_TX_CTL(pipe);
3911 temp = I915_READ(reg);
3912 if (IS_IVYBRIDGE(dev_priv)) {
3913 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3914 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3916 temp &= ~FDI_LINK_TRAIN_NONE;
3917 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3919 I915_WRITE(reg, temp);
3921 reg = FDI_RX_CTL(pipe);
3922 temp = I915_READ(reg);
3923 if (HAS_PCH_CPT(dev_priv)) {
3924 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3925 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3927 temp &= ~FDI_LINK_TRAIN_NONE;
3928 temp |= FDI_LINK_TRAIN_NONE;
3930 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3932 /* wait one idle pattern time */
3936 /* IVB wants error correction enabled */
3937 if (IS_IVYBRIDGE(dev_priv))
3938 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3939 FDI_FE_ERRC_ENABLE);
3942 /* The FDI link training functions for ILK/Ibexpeak. */
3943 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3944 const struct intel_crtc_state *crtc_state)
3946 struct drm_device *dev = crtc->base.dev;
3947 struct drm_i915_private *dev_priv = to_i915(dev);
3948 int pipe = crtc->pipe;
3952 /* FDI needs bits from pipe first */
3953 assert_pipe_enabled(dev_priv, pipe);
3955 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3957 reg = FDI_RX_IMR(pipe);
3958 temp = I915_READ(reg);
3959 temp &= ~FDI_RX_SYMBOL_LOCK;
3960 temp &= ~FDI_RX_BIT_LOCK;
3961 I915_WRITE(reg, temp);
3965 /* enable CPU FDI TX and PCH FDI RX */
3966 reg = FDI_TX_CTL(pipe);
3967 temp = I915_READ(reg);
3968 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3969 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3970 temp &= ~FDI_LINK_TRAIN_NONE;
3971 temp |= FDI_LINK_TRAIN_PATTERN_1;
3972 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3974 reg = FDI_RX_CTL(pipe);
3975 temp = I915_READ(reg);
3976 temp &= ~FDI_LINK_TRAIN_NONE;
3977 temp |= FDI_LINK_TRAIN_PATTERN_1;
3978 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3983 /* Ironlake workaround, enable clock pointer after FDI enable*/
3984 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3985 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3986 FDI_RX_PHASE_SYNC_POINTER_EN);
3988 reg = FDI_RX_IIR(pipe);
3989 for (tries = 0; tries < 5; tries++) {
3990 temp = I915_READ(reg);
3991 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3993 if ((temp & FDI_RX_BIT_LOCK)) {
3994 DRM_DEBUG_KMS("FDI train 1 done.\n");
3995 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4000 DRM_ERROR("FDI train 1 fail!\n");
4003 reg = FDI_TX_CTL(pipe);
4004 temp = I915_READ(reg);
4005 temp &= ~FDI_LINK_TRAIN_NONE;
4006 temp |= FDI_LINK_TRAIN_PATTERN_2;
4007 I915_WRITE(reg, temp);
4009 reg = FDI_RX_CTL(pipe);
4010 temp = I915_READ(reg);
4011 temp &= ~FDI_LINK_TRAIN_NONE;
4012 temp |= FDI_LINK_TRAIN_PATTERN_2;
4013 I915_WRITE(reg, temp);
4018 reg = FDI_RX_IIR(pipe);
4019 for (tries = 0; tries < 5; tries++) {
4020 temp = I915_READ(reg);
4021 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4023 if (temp & FDI_RX_SYMBOL_LOCK) {
4024 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4025 DRM_DEBUG_KMS("FDI train 2 done.\n");
4030 DRM_ERROR("FDI train 2 fail!\n");
4032 DRM_DEBUG_KMS("FDI train done\n");
4036 static const int snb_b_fdi_train_param[] = {
4037 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4038 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4039 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4040 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4043 /* The FDI link training functions for SNB/Cougarpoint. */
4044 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4045 const struct intel_crtc_state *crtc_state)
4047 struct drm_device *dev = crtc->base.dev;
4048 struct drm_i915_private *dev_priv = to_i915(dev);
4049 int pipe = crtc->pipe;
4053 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4055 reg = FDI_RX_IMR(pipe);
4056 temp = I915_READ(reg);
4057 temp &= ~FDI_RX_SYMBOL_LOCK;
4058 temp &= ~FDI_RX_BIT_LOCK;
4059 I915_WRITE(reg, temp);
4064 /* enable CPU FDI TX and PCH FDI RX */
4065 reg = FDI_TX_CTL(pipe);
4066 temp = I915_READ(reg);
4067 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4068 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4069 temp &= ~FDI_LINK_TRAIN_NONE;
4070 temp |= FDI_LINK_TRAIN_PATTERN_1;
4071 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4073 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4074 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4076 I915_WRITE(FDI_RX_MISC(pipe),
4077 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4079 reg = FDI_RX_CTL(pipe);
4080 temp = I915_READ(reg);
4081 if (HAS_PCH_CPT(dev_priv)) {
4082 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4083 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4085 temp &= ~FDI_LINK_TRAIN_NONE;
4086 temp |= FDI_LINK_TRAIN_PATTERN_1;
4088 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4093 for (i = 0; i < 4; i++) {
4094 reg = FDI_TX_CTL(pipe);
4095 temp = I915_READ(reg);
4096 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4097 temp |= snb_b_fdi_train_param[i];
4098 I915_WRITE(reg, temp);
4103 for (retry = 0; retry < 5; retry++) {
4104 reg = FDI_RX_IIR(pipe);
4105 temp = I915_READ(reg);
4106 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4107 if (temp & FDI_RX_BIT_LOCK) {
4108 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4109 DRM_DEBUG_KMS("FDI train 1 done.\n");
4118 DRM_ERROR("FDI train 1 fail!\n");
4121 reg = FDI_TX_CTL(pipe);
4122 temp = I915_READ(reg);
4123 temp &= ~FDI_LINK_TRAIN_NONE;
4124 temp |= FDI_LINK_TRAIN_PATTERN_2;
4125 if (IS_GEN6(dev_priv)) {
4126 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4128 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4130 I915_WRITE(reg, temp);
4132 reg = FDI_RX_CTL(pipe);
4133 temp = I915_READ(reg);
4134 if (HAS_PCH_CPT(dev_priv)) {
4135 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4136 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4138 temp &= ~FDI_LINK_TRAIN_NONE;
4139 temp |= FDI_LINK_TRAIN_PATTERN_2;
4141 I915_WRITE(reg, temp);
4146 for (i = 0; i < 4; i++) {
4147 reg = FDI_TX_CTL(pipe);
4148 temp = I915_READ(reg);
4149 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4150 temp |= snb_b_fdi_train_param[i];
4151 I915_WRITE(reg, temp);
4156 for (retry = 0; retry < 5; retry++) {
4157 reg = FDI_RX_IIR(pipe);
4158 temp = I915_READ(reg);
4159 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4160 if (temp & FDI_RX_SYMBOL_LOCK) {
4161 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4162 DRM_DEBUG_KMS("FDI train 2 done.\n");
4171 DRM_ERROR("FDI train 2 fail!\n");
4173 DRM_DEBUG_KMS("FDI train done.\n");
4176 /* Manual link training for Ivy Bridge A0 parts */
4177 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4178 const struct intel_crtc_state *crtc_state)
4180 struct drm_device *dev = crtc->base.dev;
4181 struct drm_i915_private *dev_priv = to_i915(dev);
4182 int pipe = crtc->pipe;
4186 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4188 reg = FDI_RX_IMR(pipe);
4189 temp = I915_READ(reg);
4190 temp &= ~FDI_RX_SYMBOL_LOCK;
4191 temp &= ~FDI_RX_BIT_LOCK;
4192 I915_WRITE(reg, temp);
4197 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4198 I915_READ(FDI_RX_IIR(pipe)));
4200 /* Try each vswing and preemphasis setting twice before moving on */
4201 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4202 /* disable first in case we need to retry */
4203 reg = FDI_TX_CTL(pipe);
4204 temp = I915_READ(reg);
4205 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4206 temp &= ~FDI_TX_ENABLE;
4207 I915_WRITE(reg, temp);
4209 reg = FDI_RX_CTL(pipe);
4210 temp = I915_READ(reg);
4211 temp &= ~FDI_LINK_TRAIN_AUTO;
4212 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4213 temp &= ~FDI_RX_ENABLE;
4214 I915_WRITE(reg, temp);
4216 /* enable CPU FDI TX and PCH FDI RX */
4217 reg = FDI_TX_CTL(pipe);
4218 temp = I915_READ(reg);
4219 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4220 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4221 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4222 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4223 temp |= snb_b_fdi_train_param[j/2];
4224 temp |= FDI_COMPOSITE_SYNC;
4225 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4227 I915_WRITE(FDI_RX_MISC(pipe),
4228 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4230 reg = FDI_RX_CTL(pipe);
4231 temp = I915_READ(reg);
4232 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4233 temp |= FDI_COMPOSITE_SYNC;
4234 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4237 udelay(1); /* should be 0.5us */
4239 for (i = 0; i < 4; i++) {
4240 reg = FDI_RX_IIR(pipe);
4241 temp = I915_READ(reg);
4242 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4244 if (temp & FDI_RX_BIT_LOCK ||
4245 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4246 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4247 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4251 udelay(1); /* should be 0.5us */
4254 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4259 reg = FDI_TX_CTL(pipe);
4260 temp = I915_READ(reg);
4261 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4262 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4263 I915_WRITE(reg, temp);
4265 reg = FDI_RX_CTL(pipe);
4266 temp = I915_READ(reg);
4267 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4268 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4269 I915_WRITE(reg, temp);
4272 udelay(2); /* should be 1.5us */
4274 for (i = 0; i < 4; i++) {
4275 reg = FDI_RX_IIR(pipe);
4276 temp = I915_READ(reg);
4277 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4279 if (temp & FDI_RX_SYMBOL_LOCK ||
4280 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4281 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4282 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4286 udelay(2); /* should be 1.5us */
4289 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4293 DRM_DEBUG_KMS("FDI train done.\n");
4296 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
4298 struct drm_device *dev = intel_crtc->base.dev;
4299 struct drm_i915_private *dev_priv = to_i915(dev);
4300 int pipe = intel_crtc->pipe;
4304 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4305 reg = FDI_RX_CTL(pipe);
4306 temp = I915_READ(reg);
4307 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4308 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
4309 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4310 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4315 /* Switch from Rawclk to PCDclk */
4316 temp = I915_READ(reg);
4317 I915_WRITE(reg, temp | FDI_PCDCLK);
4322 /* Enable CPU FDI TX PLL, always on for Ironlake */
4323 reg = FDI_TX_CTL(pipe);
4324 temp = I915_READ(reg);
4325 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4326 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4333 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4335 struct drm_device *dev = intel_crtc->base.dev;
4336 struct drm_i915_private *dev_priv = to_i915(dev);
4337 int pipe = intel_crtc->pipe;
4341 /* Switch from PCDclk to Rawclk */
4342 reg = FDI_RX_CTL(pipe);
4343 temp = I915_READ(reg);
4344 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4346 /* Disable CPU FDI TX PLL */
4347 reg = FDI_TX_CTL(pipe);
4348 temp = I915_READ(reg);
4349 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4354 reg = FDI_RX_CTL(pipe);
4355 temp = I915_READ(reg);
4356 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4358 /* Wait for the clocks to turn off. */
4363 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4365 struct drm_device *dev = crtc->dev;
4366 struct drm_i915_private *dev_priv = to_i915(dev);
4367 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4368 int pipe = intel_crtc->pipe;
4372 /* disable CPU FDI tx and PCH FDI rx */
4373 reg = FDI_TX_CTL(pipe);
4374 temp = I915_READ(reg);
4375 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4378 reg = FDI_RX_CTL(pipe);
4379 temp = I915_READ(reg);
4380 temp &= ~(0x7 << 16);
4381 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4382 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4387 /* Ironlake workaround, disable clock pointer after downing FDI */
4388 if (HAS_PCH_IBX(dev_priv))
4389 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4391 /* still set train pattern 1 */
4392 reg = FDI_TX_CTL(pipe);
4393 temp = I915_READ(reg);
4394 temp &= ~FDI_LINK_TRAIN_NONE;
4395 temp |= FDI_LINK_TRAIN_PATTERN_1;
4396 I915_WRITE(reg, temp);
4398 reg = FDI_RX_CTL(pipe);
4399 temp = I915_READ(reg);
4400 if (HAS_PCH_CPT(dev_priv)) {
4401 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4402 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4404 temp &= ~FDI_LINK_TRAIN_NONE;
4405 temp |= FDI_LINK_TRAIN_PATTERN_1;
4407 /* BPC in FDI rx is consistent with that in PIPECONF */
4408 temp &= ~(0x07 << 16);
4409 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4410 I915_WRITE(reg, temp);
4416 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4418 struct drm_crtc *crtc;
4421 drm_for_each_crtc(crtc, &dev_priv->drm) {
4422 struct drm_crtc_commit *commit;
4423 spin_lock(&crtc->commit_lock);
4424 commit = list_first_entry_or_null(&crtc->commit_list,
4425 struct drm_crtc_commit, commit_entry);
4426 cleanup_done = commit ?
4427 try_wait_for_completion(&commit->cleanup_done) : true;
4428 spin_unlock(&crtc->commit_lock);
4433 drm_crtc_wait_one_vblank(crtc);
4441 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4445 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4447 mutex_lock(&dev_priv->sb_lock);
4449 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4450 temp |= SBI_SSCCTL_DISABLE;
4451 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4453 mutex_unlock(&dev_priv->sb_lock);
4456 /* Program iCLKIP clock to the desired frequency */
4457 static void lpt_program_iclkip(struct intel_crtc *crtc)
4459 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4460 int clock = crtc->config->base.adjusted_mode.crtc_clock;
4461 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4464 lpt_disable_iclkip(dev_priv);
4466 /* The iCLK virtual clock root frequency is in MHz,
4467 * but the adjusted_mode->crtc_clock in in KHz. To get the
4468 * divisors, it is necessary to divide one by another, so we
4469 * convert the virtual clock precision to KHz here for higher
4472 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4473 u32 iclk_virtual_root_freq = 172800 * 1000;
4474 u32 iclk_pi_range = 64;
4475 u32 desired_divisor;
4477 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4479 divsel = (desired_divisor / iclk_pi_range) - 2;
4480 phaseinc = desired_divisor % iclk_pi_range;
4483 * Near 20MHz is a corner case which is
4484 * out of range for the 7-bit divisor
4490 /* This should not happen with any sane values */
4491 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4492 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4493 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4494 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4496 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4503 mutex_lock(&dev_priv->sb_lock);
4505 /* Program SSCDIVINTPHASE6 */
4506 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4507 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4508 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4509 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4510 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4511 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4512 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4513 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4515 /* Program SSCAUXDIV */
4516 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4517 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4518 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4519 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4521 /* Enable modulator and associated divider */
4522 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4523 temp &= ~SBI_SSCCTL_DISABLE;
4524 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4526 mutex_unlock(&dev_priv->sb_lock);
4528 /* Wait for initialization time */
4531 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4534 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4536 u32 divsel, phaseinc, auxdiv;
4537 u32 iclk_virtual_root_freq = 172800 * 1000;
4538 u32 iclk_pi_range = 64;
4539 u32 desired_divisor;
4542 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4545 mutex_lock(&dev_priv->sb_lock);
4547 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4548 if (temp & SBI_SSCCTL_DISABLE) {
4549 mutex_unlock(&dev_priv->sb_lock);
4553 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4554 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4555 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4556 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4557 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4559 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4560 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4561 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4563 mutex_unlock(&dev_priv->sb_lock);
4565 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4567 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4568 desired_divisor << auxdiv);
4571 static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
4572 enum pipe pch_transcoder)
4574 struct drm_device *dev = crtc->base.dev;
4575 struct drm_i915_private *dev_priv = to_i915(dev);
4576 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
4578 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4579 I915_READ(HTOTAL(cpu_transcoder)));
4580 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4581 I915_READ(HBLANK(cpu_transcoder)));
4582 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4583 I915_READ(HSYNC(cpu_transcoder)));
4585 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4586 I915_READ(VTOTAL(cpu_transcoder)));
4587 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4588 I915_READ(VBLANK(cpu_transcoder)));
4589 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4590 I915_READ(VSYNC(cpu_transcoder)));
4591 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4592 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4595 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4597 struct drm_i915_private *dev_priv = to_i915(dev);
4600 temp = I915_READ(SOUTH_CHICKEN1);
4601 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4604 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4605 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4607 temp &= ~FDI_BC_BIFURCATION_SELECT;
4609 temp |= FDI_BC_BIFURCATION_SELECT;
4611 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4612 I915_WRITE(SOUTH_CHICKEN1, temp);
4613 POSTING_READ(SOUTH_CHICKEN1);
4616 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4618 struct drm_device *dev = intel_crtc->base.dev;
4620 switch (intel_crtc->pipe) {
4624 if (intel_crtc->config->fdi_lanes > 2)
4625 cpt_set_fdi_bc_bifurcation(dev, false);
4627 cpt_set_fdi_bc_bifurcation(dev, true);
4631 cpt_set_fdi_bc_bifurcation(dev, true);
4639 /* Return which DP Port should be selected for Transcoder DP control */
4641 intel_trans_dp_port_sel(struct intel_crtc *crtc)
4643 struct drm_device *dev = crtc->base.dev;
4644 struct intel_encoder *encoder;
4646 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
4647 if (encoder->type == INTEL_OUTPUT_DP ||
4648 encoder->type == INTEL_OUTPUT_EDP)
4649 return encoder->port;
4656 * Enable PCH resources required for PCH ports:
4658 * - FDI training & RX/TX
4659 * - update transcoder timings
4660 * - DP transcoding bits
4663 static void ironlake_pch_enable(const struct intel_crtc_state *crtc_state)
4665 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4666 struct drm_device *dev = crtc->base.dev;
4667 struct drm_i915_private *dev_priv = to_i915(dev);
4668 int pipe = crtc->pipe;
4671 assert_pch_transcoder_disabled(dev_priv, pipe);
4673 if (IS_IVYBRIDGE(dev_priv))
4674 ivybridge_update_fdi_bc_bifurcation(crtc);
4676 /* Write the TU size bits before fdi link training, so that error
4677 * detection works. */
4678 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4679 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4681 /* For PCH output, training FDI link */
4682 dev_priv->display.fdi_link_train(crtc, crtc_state);
4684 /* We need to program the right clock selection before writing the pixel
4685 * mutliplier into the DPLL. */
4686 if (HAS_PCH_CPT(dev_priv)) {
4689 temp = I915_READ(PCH_DPLL_SEL);
4690 temp |= TRANS_DPLL_ENABLE(pipe);
4691 sel = TRANS_DPLLB_SEL(pipe);
4692 if (crtc_state->shared_dpll ==
4693 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4697 I915_WRITE(PCH_DPLL_SEL, temp);
4700 /* XXX: pch pll's can be enabled any time before we enable the PCH
4701 * transcoder, and we actually should do this to not upset any PCH
4702 * transcoder that already use the clock when we share it.
4704 * Note that enable_shared_dpll tries to do the right thing, but
4705 * get_shared_dpll unconditionally resets the pll - we need that to have
4706 * the right LVDS enable sequence. */
4707 intel_enable_shared_dpll(crtc);
4709 /* set transcoder timing, panel must allow it */
4710 assert_panel_unlocked(dev_priv, pipe);
4711 ironlake_pch_transcoder_set_timings(crtc, pipe);
4713 intel_fdi_normal_train(crtc);
4715 /* For PCH DP, enable TRANS_DP_CTL */
4716 if (HAS_PCH_CPT(dev_priv) &&
4717 intel_crtc_has_dp_encoder(crtc_state)) {
4718 const struct drm_display_mode *adjusted_mode =
4719 &crtc_state->base.adjusted_mode;
4720 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4721 i915_reg_t reg = TRANS_DP_CTL(pipe);
4722 temp = I915_READ(reg);
4723 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4724 TRANS_DP_SYNC_MASK |
4726 temp |= TRANS_DP_OUTPUT_ENABLE;
4727 temp |= bpc << 9; /* same format but at 11:9 */
4729 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4730 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4731 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4732 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4734 switch (intel_trans_dp_port_sel(crtc)) {
4736 temp |= TRANS_DP_PORT_SEL_B;
4739 temp |= TRANS_DP_PORT_SEL_C;
4742 temp |= TRANS_DP_PORT_SEL_D;
4748 I915_WRITE(reg, temp);
4751 ironlake_enable_pch_transcoder(dev_priv, pipe);
4754 static void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
4756 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4757 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4758 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4760 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4762 lpt_program_iclkip(crtc);
4764 /* Set transcoder timing. */
4765 ironlake_pch_transcoder_set_timings(crtc, PIPE_A);
4767 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4770 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4772 struct drm_i915_private *dev_priv = to_i915(dev);
4773 i915_reg_t dslreg = PIPEDSL(pipe);
4776 temp = I915_READ(dslreg);
4778 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4779 if (wait_for(I915_READ(dslreg) != temp, 5))
4780 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4785 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4786 unsigned int scaler_user, int *scaler_id,
4787 int src_w, int src_h, int dst_w, int dst_h,
4788 bool plane_scaler_check,
4789 uint32_t pixel_format)
4791 struct intel_crtc_scaler_state *scaler_state =
4792 &crtc_state->scaler_state;
4793 struct intel_crtc *intel_crtc =
4794 to_intel_crtc(crtc_state->base.crtc);
4795 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4796 const struct drm_display_mode *adjusted_mode =
4797 &crtc_state->base.adjusted_mode;
4801 * Src coordinates are already rotated by 270 degrees for
4802 * the 90/270 degree plane rotation cases (to match the
4803 * GTT mapping), hence no need to account for rotation here.
4805 need_scaling = src_w != dst_w || src_h != dst_h;
4807 if (plane_scaler_check)
4808 if (pixel_format == DRM_FORMAT_NV12)
4809 need_scaling = true;
4811 if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX)
4812 need_scaling = true;
4815 * Scaling/fitting not supported in IF-ID mode in GEN9+
4816 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4817 * Once NV12 is enabled, handle it here while allocating scaler
4820 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4821 need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4822 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4827 * if plane is being disabled or scaler is no more required or force detach
4828 * - free scaler binded to this plane/crtc
4829 * - in order to do this, update crtc->scaler_usage
4831 * Here scaler state in crtc_state is set free so that
4832 * scaler can be assigned to other user. Actual register
4833 * update to free the scaler is done in plane/panel-fit programming.
4834 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4836 if (force_detach || !need_scaling) {
4837 if (*scaler_id >= 0) {
4838 scaler_state->scaler_users &= ~(1 << scaler_user);
4839 scaler_state->scalers[*scaler_id].in_use = 0;
4841 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4842 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4843 intel_crtc->pipe, scaler_user, *scaler_id,
4844 scaler_state->scaler_users);
4850 if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 &&
4851 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
4852 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4857 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4858 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4859 (IS_GEN11(dev_priv) &&
4860 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4861 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4862 (!IS_GEN11(dev_priv) &&
4863 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4864 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
4865 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4866 "size is out of scaler range\n",
4867 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4871 /* mark this plane as a scaler user in crtc_state */
4872 scaler_state->scaler_users |= (1 << scaler_user);
4873 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4874 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4875 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4876 scaler_state->scaler_users);
4882 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4884 * @state: crtc's scaler state
4887 * 0 - scaler_usage updated successfully
4888 * error - requested scaling cannot be supported or other error condition
4890 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4892 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
4894 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4895 &state->scaler_state.scaler_id,
4896 state->pipe_src_w, state->pipe_src_h,
4897 adjusted_mode->crtc_hdisplay,
4898 adjusted_mode->crtc_vdisplay, false, 0);
4902 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4903 * @crtc_state: crtc's scaler state
4904 * @plane_state: atomic plane state to update
4907 * 0 - scaler_usage updated successfully
4908 * error - requested scaling cannot be supported or other error condition
4910 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4911 struct intel_plane_state *plane_state)
4914 struct intel_plane *intel_plane =
4915 to_intel_plane(plane_state->base.plane);
4916 struct drm_framebuffer *fb = plane_state->base.fb;
4919 bool force_detach = !fb || !plane_state->base.visible;
4921 ret = skl_update_scaler(crtc_state, force_detach,
4922 drm_plane_index(&intel_plane->base),
4923 &plane_state->scaler_id,
4924 drm_rect_width(&plane_state->base.src) >> 16,
4925 drm_rect_height(&plane_state->base.src) >> 16,
4926 drm_rect_width(&plane_state->base.dst),
4927 drm_rect_height(&plane_state->base.dst),
4928 fb ? true : false, fb ? fb->format->format : 0);
4930 if (ret || plane_state->scaler_id < 0)
4933 /* check colorkey */
4934 if (plane_state->ckey.flags) {
4935 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4936 intel_plane->base.base.id,
4937 intel_plane->base.name);
4941 /* Check src format */
4942 switch (fb->format->format) {
4943 case DRM_FORMAT_RGB565:
4944 case DRM_FORMAT_XBGR8888:
4945 case DRM_FORMAT_XRGB8888:
4946 case DRM_FORMAT_ABGR8888:
4947 case DRM_FORMAT_ARGB8888:
4948 case DRM_FORMAT_XRGB2101010:
4949 case DRM_FORMAT_XBGR2101010:
4950 case DRM_FORMAT_YUYV:
4951 case DRM_FORMAT_YVYU:
4952 case DRM_FORMAT_UYVY:
4953 case DRM_FORMAT_VYUY:
4954 case DRM_FORMAT_NV12:
4957 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4958 intel_plane->base.base.id, intel_plane->base.name,
4959 fb->base.id, fb->format->format);
4966 static void skylake_scaler_disable(struct intel_crtc *crtc)
4970 for (i = 0; i < crtc->num_scalers; i++)
4971 skl_detach_scaler(crtc, i);
4974 static void skylake_pfit_enable(struct intel_crtc *crtc)
4976 struct drm_device *dev = crtc->base.dev;
4977 struct drm_i915_private *dev_priv = to_i915(dev);
4978 int pipe = crtc->pipe;
4979 struct intel_crtc_scaler_state *scaler_state =
4980 &crtc->config->scaler_state;
4982 if (crtc->config->pch_pfit.enabled) {
4985 if (WARN_ON(crtc->config->scaler_state.scaler_id < 0))
4988 id = scaler_state->scaler_id;
4989 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
4990 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
4991 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
4992 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
4996 static void ironlake_pfit_enable(struct intel_crtc *crtc)
4998 struct drm_device *dev = crtc->base.dev;
4999 struct drm_i915_private *dev_priv = to_i915(dev);
5000 int pipe = crtc->pipe;
5002 if (crtc->config->pch_pfit.enabled) {
5003 /* Force use of hard-coded filter coefficients
5004 * as some pre-programmed values are broken,
5007 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5008 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5009 PF_PIPE_SEL_IVB(pipe));
5011 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5012 I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
5013 I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
5017 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5019 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5020 struct drm_device *dev = crtc->base.dev;
5021 struct drm_i915_private *dev_priv = to_i915(dev);
5023 if (!crtc_state->ips_enabled)
5027 * We can only enable IPS after we enable a plane and wait for a vblank
5028 * This function is called from post_plane_update, which is run after
5031 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5033 if (IS_BROADWELL(dev_priv)) {
5034 mutex_lock(&dev_priv->pcu_lock);
5035 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5036 IPS_ENABLE | IPS_PCODE_CONTROL));
5037 mutex_unlock(&dev_priv->pcu_lock);
5038 /* Quoting Art Runyan: "its not safe to expect any particular
5039 * value in IPS_CTL bit 31 after enabling IPS through the
5040 * mailbox." Moreover, the mailbox may return a bogus state,
5041 * so we need to just enable it and continue on.
5044 I915_WRITE(IPS_CTL, IPS_ENABLE);
5045 /* The bit only becomes 1 in the next vblank, so this wait here
5046 * is essentially intel_wait_for_vblank. If we don't have this
5047 * and don't wait for vblanks until the end of crtc_enable, then
5048 * the HW state readout code will complain that the expected
5049 * IPS_CTL value is not the one we read. */
5050 if (intel_wait_for_register(dev_priv,
5051 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5053 DRM_ERROR("Timed out waiting for IPS enable\n");
5057 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5059 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5060 struct drm_device *dev = crtc->base.dev;
5061 struct drm_i915_private *dev_priv = to_i915(dev);
5063 if (!crtc_state->ips_enabled)
5066 if (IS_BROADWELL(dev_priv)) {
5067 mutex_lock(&dev_priv->pcu_lock);
5068 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5069 mutex_unlock(&dev_priv->pcu_lock);
5070 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
5071 if (intel_wait_for_register(dev_priv,
5072 IPS_CTL, IPS_ENABLE, 0,
5074 DRM_ERROR("Timed out waiting for IPS disable\n");
5076 I915_WRITE(IPS_CTL, 0);
5077 POSTING_READ(IPS_CTL);
5080 /* We need to wait for a vblank before we can disable the plane. */
5081 intel_wait_for_vblank(dev_priv, crtc->pipe);
5084 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5086 if (intel_crtc->overlay) {
5087 struct drm_device *dev = intel_crtc->base.dev;
5089 mutex_lock(&dev->struct_mutex);
5090 (void) intel_overlay_switch_off(intel_crtc->overlay);
5091 mutex_unlock(&dev->struct_mutex);
5094 /* Let userspace switch the overlay on again. In most cases userspace
5095 * has to recompute where to put it anyway.
5100 * intel_post_enable_primary - Perform operations after enabling primary plane
5101 * @crtc: the CRTC whose primary plane was just enabled
5102 * @new_crtc_state: the enabling state
5104 * Performs potentially sleeping operations that must be done after the primary
5105 * plane is enabled, such as updating FBC and IPS. Note that this may be
5106 * called due to an explicit primary plane update, or due to an implicit
5107 * re-enable that is caused when a sprite plane is updated to no longer
5108 * completely hide the primary plane.
5111 intel_post_enable_primary(struct drm_crtc *crtc,
5112 const struct intel_crtc_state *new_crtc_state)
5114 struct drm_device *dev = crtc->dev;
5115 struct drm_i915_private *dev_priv = to_i915(dev);
5116 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5117 int pipe = intel_crtc->pipe;
5120 * Gen2 reports pipe underruns whenever all planes are disabled.
5121 * So don't enable underrun reporting before at least some planes
5123 * FIXME: Need to fix the logic to work when we turn off all planes
5124 * but leave the pipe running.
5126 if (IS_GEN2(dev_priv))
5127 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5129 /* Underruns don't always raise interrupts, so check manually. */
5130 intel_check_cpu_fifo_underruns(dev_priv);
5131 intel_check_pch_fifo_underruns(dev_priv);
5134 /* FIXME get rid of this and use pre_plane_update */
5136 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5138 struct drm_device *dev = crtc->dev;
5139 struct drm_i915_private *dev_priv = to_i915(dev);
5140 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5141 int pipe = intel_crtc->pipe;
5144 * Gen2 reports pipe underruns whenever all planes are disabled.
5145 * So disable underrun reporting before all the planes get disabled.
5147 if (IS_GEN2(dev_priv))
5148 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5150 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5153 * Vblank time updates from the shadow to live plane control register
5154 * are blocked if the memory self-refresh mode is active at that
5155 * moment. So to make sure the plane gets truly disabled, disable
5156 * first the self-refresh mode. The self-refresh enable bit in turn
5157 * will be checked/applied by the HW only at the next frame start
5158 * event which is after the vblank start event, so we need to have a
5159 * wait-for-vblank between disabling the plane and the pipe.
5161 if (HAS_GMCH_DISPLAY(dev_priv) &&
5162 intel_set_memory_cxsr(dev_priv, false))
5163 intel_wait_for_vblank(dev_priv, pipe);
5166 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5167 const struct intel_crtc_state *new_crtc_state)
5169 if (!old_crtc_state->ips_enabled)
5172 if (needs_modeset(&new_crtc_state->base))
5175 return !new_crtc_state->ips_enabled;
5178 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5179 const struct intel_crtc_state *new_crtc_state)
5181 if (!new_crtc_state->ips_enabled)
5184 if (needs_modeset(&new_crtc_state->base))
5188 * We can't read out IPS on broadwell, assume the worst and
5189 * forcibly enable IPS on the first fastset.
5191 if (new_crtc_state->update_pipe &&
5192 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5195 return !old_crtc_state->ips_enabled;
5198 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5199 const struct intel_crtc_state *crtc_state)
5201 if (!crtc_state->nv12_planes)
5204 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
5207 if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
5208 IS_CANNONLAKE(dev_priv))
5214 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5216 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5217 struct drm_device *dev = crtc->base.dev;
5218 struct drm_i915_private *dev_priv = to_i915(dev);
5219 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5220 struct intel_crtc_state *pipe_config =
5221 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5223 struct drm_plane *primary = crtc->base.primary;
5224 struct drm_plane_state *old_primary_state =
5225 drm_atomic_get_old_plane_state(old_state, primary);
5227 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5229 if (pipe_config->update_wm_post && pipe_config->base.active)
5230 intel_update_watermarks(crtc);
5232 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5233 hsw_enable_ips(pipe_config);
5235 if (old_primary_state) {
5236 struct drm_plane_state *new_primary_state =
5237 drm_atomic_get_new_plane_state(old_state, primary);
5239 intel_fbc_post_update(crtc);
5241 if (new_primary_state->visible &&
5242 (needs_modeset(&pipe_config->base) ||
5243 !old_primary_state->visible))
5244 intel_post_enable_primary(&crtc->base, pipe_config);
5247 /* Display WA 827 */
5248 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5249 !needs_nv12_wa(dev_priv, pipe_config)) {
5250 skl_wa_clkgate(dev_priv, crtc->pipe, false);
5251 skl_wa_528(dev_priv, crtc->pipe, false);
5255 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5256 struct intel_crtc_state *pipe_config)
5258 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5259 struct drm_device *dev = crtc->base.dev;
5260 struct drm_i915_private *dev_priv = to_i915(dev);
5261 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5262 struct drm_plane *primary = crtc->base.primary;
5263 struct drm_plane_state *old_primary_state =
5264 drm_atomic_get_old_plane_state(old_state, primary);
5265 bool modeset = needs_modeset(&pipe_config->base);
5266 struct intel_atomic_state *old_intel_state =
5267 to_intel_atomic_state(old_state);
5269 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5270 hsw_disable_ips(old_crtc_state);
5272 if (old_primary_state) {
5273 struct intel_plane_state *new_primary_state =
5274 intel_atomic_get_new_plane_state(old_intel_state,
5275 to_intel_plane(primary));
5277 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5279 * Gen2 reports pipe underruns whenever all planes are disabled.
5280 * So disable underrun reporting before all the planes get disabled.
5282 if (IS_GEN2(dev_priv) && old_primary_state->visible &&
5283 (modeset || !new_primary_state->base.visible))
5284 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5287 /* Display WA 827 */
5288 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5289 needs_nv12_wa(dev_priv, pipe_config)) {
5290 skl_wa_clkgate(dev_priv, crtc->pipe, true);
5291 skl_wa_528(dev_priv, crtc->pipe, true);
5295 * Vblank time updates from the shadow to live plane control register
5296 * are blocked if the memory self-refresh mode is active at that
5297 * moment. So to make sure the plane gets truly disabled, disable
5298 * first the self-refresh mode. The self-refresh enable bit in turn
5299 * will be checked/applied by the HW only at the next frame start
5300 * event which is after the vblank start event, so we need to have a
5301 * wait-for-vblank between disabling the plane and the pipe.
5303 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5304 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5305 intel_wait_for_vblank(dev_priv, crtc->pipe);
5308 * IVB workaround: must disable low power watermarks for at least
5309 * one frame before enabling scaling. LP watermarks can be re-enabled
5310 * when scaling is disabled.
5312 * WaCxSRDisabledForSpriteScaling:ivb
5314 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev))
5315 intel_wait_for_vblank(dev_priv, crtc->pipe);
5318 * If we're doing a modeset, we're done. No need to do any pre-vblank
5319 * watermark programming here.
5321 if (needs_modeset(&pipe_config->base))
5325 * For platforms that support atomic watermarks, program the
5326 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5327 * will be the intermediate values that are safe for both pre- and
5328 * post- vblank; when vblank happens, the 'active' values will be set
5329 * to the final 'target' values and we'll do this again to get the
5330 * optimal watermarks. For gen9+ platforms, the values we program here
5331 * will be the final target values which will get automatically latched
5332 * at vblank time; no further programming will be necessary.
5334 * If a platform hasn't been transitioned to atomic watermarks yet,
5335 * we'll continue to update watermarks the old way, if flags tell
5338 if (dev_priv->display.initial_watermarks != NULL)
5339 dev_priv->display.initial_watermarks(old_intel_state,
5341 else if (pipe_config->update_wm_pre)
5342 intel_update_watermarks(crtc);
5345 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
5347 struct drm_device *dev = crtc->dev;
5348 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5349 struct drm_plane *p;
5350 int pipe = intel_crtc->pipe;
5352 intel_crtc_dpms_overlay_disable(intel_crtc);
5354 drm_for_each_plane_mask(p, dev, plane_mask)
5355 to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc);
5358 * FIXME: Once we grow proper nuclear flip support out of this we need
5359 * to compute the mask of flip planes precisely. For the time being
5360 * consider this a flip to a NULL plane.
5362 intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe));
5365 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5366 struct intel_crtc_state *crtc_state,
5367 struct drm_atomic_state *old_state)
5369 struct drm_connector_state *conn_state;
5370 struct drm_connector *conn;
5373 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5374 struct intel_encoder *encoder =
5375 to_intel_encoder(conn_state->best_encoder);
5377 if (conn_state->crtc != crtc)
5380 if (encoder->pre_pll_enable)
5381 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5385 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5386 struct intel_crtc_state *crtc_state,
5387 struct drm_atomic_state *old_state)
5389 struct drm_connector_state *conn_state;
5390 struct drm_connector *conn;
5393 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5394 struct intel_encoder *encoder =
5395 to_intel_encoder(conn_state->best_encoder);
5397 if (conn_state->crtc != crtc)
5400 if (encoder->pre_enable)
5401 encoder->pre_enable(encoder, crtc_state, conn_state);
5405 static void intel_encoders_enable(struct drm_crtc *crtc,
5406 struct intel_crtc_state *crtc_state,
5407 struct drm_atomic_state *old_state)
5409 struct drm_connector_state *conn_state;
5410 struct drm_connector *conn;
5413 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5414 struct intel_encoder *encoder =
5415 to_intel_encoder(conn_state->best_encoder);
5417 if (conn_state->crtc != crtc)
5420 encoder->enable(encoder, crtc_state, conn_state);
5421 intel_opregion_notify_encoder(encoder, true);
5425 static void intel_encoders_disable(struct drm_crtc *crtc,
5426 struct intel_crtc_state *old_crtc_state,
5427 struct drm_atomic_state *old_state)
5429 struct drm_connector_state *old_conn_state;
5430 struct drm_connector *conn;
5433 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5434 struct intel_encoder *encoder =
5435 to_intel_encoder(old_conn_state->best_encoder);
5437 if (old_conn_state->crtc != crtc)
5440 intel_opregion_notify_encoder(encoder, false);
5441 encoder->disable(encoder, old_crtc_state, old_conn_state);
5445 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5446 struct intel_crtc_state *old_crtc_state,
5447 struct drm_atomic_state *old_state)
5449 struct drm_connector_state *old_conn_state;
5450 struct drm_connector *conn;
5453 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5454 struct intel_encoder *encoder =
5455 to_intel_encoder(old_conn_state->best_encoder);
5457 if (old_conn_state->crtc != crtc)
5460 if (encoder->post_disable)
5461 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5465 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5466 struct intel_crtc_state *old_crtc_state,
5467 struct drm_atomic_state *old_state)
5469 struct drm_connector_state *old_conn_state;
5470 struct drm_connector *conn;
5473 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5474 struct intel_encoder *encoder =
5475 to_intel_encoder(old_conn_state->best_encoder);
5477 if (old_conn_state->crtc != crtc)
5480 if (encoder->post_pll_disable)
5481 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5485 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5486 struct drm_atomic_state *old_state)
5488 struct drm_crtc *crtc = pipe_config->base.crtc;
5489 struct drm_device *dev = crtc->dev;
5490 struct drm_i915_private *dev_priv = to_i915(dev);
5491 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5492 int pipe = intel_crtc->pipe;
5493 struct intel_atomic_state *old_intel_state =
5494 to_intel_atomic_state(old_state);
5496 if (WARN_ON(intel_crtc->active))
5500 * Sometimes spurious CPU pipe underruns happen during FDI
5501 * training, at least with VGA+HDMI cloning. Suppress them.
5503 * On ILK we get an occasional spurious CPU pipe underruns
5504 * between eDP port A enable and vdd enable. Also PCH port
5505 * enable seems to result in the occasional CPU pipe underrun.
5507 * Spurious PCH underruns also occur during PCH enabling.
5509 if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv))
5510 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5511 if (intel_crtc->config->has_pch_encoder)
5512 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5514 if (intel_crtc->config->has_pch_encoder)
5515 intel_prepare_shared_dpll(intel_crtc);
5517 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5518 intel_dp_set_m_n(intel_crtc, M1_N1);
5520 intel_set_pipe_timings(intel_crtc);
5521 intel_set_pipe_src_size(intel_crtc);
5523 if (intel_crtc->config->has_pch_encoder) {
5524 intel_cpu_transcoder_set_m_n(intel_crtc,
5525 &intel_crtc->config->fdi_m_n, NULL);
5528 ironlake_set_pipeconf(crtc);
5530 intel_crtc->active = true;
5532 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5534 if (intel_crtc->config->has_pch_encoder) {
5535 /* Note: FDI PLL enabling _must_ be done before we enable the
5536 * cpu pipes, hence this is separate from all the other fdi/pch
5538 ironlake_fdi_pll_enable(intel_crtc);
5540 assert_fdi_tx_disabled(dev_priv, pipe);
5541 assert_fdi_rx_disabled(dev_priv, pipe);
5544 ironlake_pfit_enable(intel_crtc);
5547 * On ILK+ LUT must be loaded before the pipe is running but with
5550 intel_color_load_luts(&pipe_config->base);
5552 if (dev_priv->display.initial_watermarks != NULL)
5553 dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config);
5554 intel_enable_pipe(pipe_config);
5556 if (intel_crtc->config->has_pch_encoder)
5557 ironlake_pch_enable(pipe_config);
5559 assert_vblank_disabled(crtc);
5560 drm_crtc_vblank_on(crtc);
5562 intel_encoders_enable(crtc, pipe_config, old_state);
5564 if (HAS_PCH_CPT(dev_priv))
5565 cpt_verify_modeset(dev, intel_crtc->pipe);
5567 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5568 if (intel_crtc->config->has_pch_encoder)
5569 intel_wait_for_vblank(dev_priv, pipe);
5570 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5571 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5574 /* IPS only exists on ULT machines and is tied to pipe A. */
5575 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5577 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5580 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5581 enum pipe pipe, bool apply)
5583 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5584 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5591 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5594 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5596 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5597 enum pipe pipe = crtc->pipe;
5600 val = MBUS_DBOX_BW_CREDIT(1) | MBUS_DBOX_A_CREDIT(2);
5602 /* Program B credit equally to all pipes */
5603 val |= MBUS_DBOX_B_CREDIT(24 / INTEL_INFO(dev_priv)->num_pipes);
5605 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5608 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5609 struct drm_atomic_state *old_state)
5611 struct drm_crtc *crtc = pipe_config->base.crtc;
5612 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5613 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5614 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5615 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5616 struct intel_atomic_state *old_intel_state =
5617 to_intel_atomic_state(old_state);
5618 bool psl_clkgate_wa;
5620 if (WARN_ON(intel_crtc->active))
5623 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5625 if (intel_crtc->config->shared_dpll)
5626 intel_enable_shared_dpll(intel_crtc);
5628 if (INTEL_GEN(dev_priv) >= 11)
5629 icl_map_plls_to_ports(crtc, pipe_config, old_state);
5631 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5632 intel_dp_set_m_n(intel_crtc, M1_N1);
5634 if (!transcoder_is_dsi(cpu_transcoder))
5635 intel_set_pipe_timings(intel_crtc);
5637 intel_set_pipe_src_size(intel_crtc);
5639 if (cpu_transcoder != TRANSCODER_EDP &&
5640 !transcoder_is_dsi(cpu_transcoder)) {
5641 I915_WRITE(PIPE_MULT(cpu_transcoder),
5642 intel_crtc->config->pixel_multiplier - 1);
5645 if (intel_crtc->config->has_pch_encoder) {
5646 intel_cpu_transcoder_set_m_n(intel_crtc,
5647 &intel_crtc->config->fdi_m_n, NULL);
5650 if (!transcoder_is_dsi(cpu_transcoder))
5651 haswell_set_pipeconf(crtc);
5653 haswell_set_pipemisc(crtc);
5655 intel_color_set_csc(&pipe_config->base);
5657 intel_crtc->active = true;
5659 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5661 if (!transcoder_is_dsi(cpu_transcoder))
5662 intel_ddi_enable_pipe_clock(pipe_config);
5664 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5665 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5666 intel_crtc->config->pch_pfit.enabled;
5668 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5670 if (INTEL_GEN(dev_priv) >= 9)
5671 skylake_pfit_enable(intel_crtc);
5673 ironlake_pfit_enable(intel_crtc);
5676 * On ILK+ LUT must be loaded before the pipe is running but with
5679 intel_color_load_luts(&pipe_config->base);
5681 intel_ddi_set_pipe_settings(pipe_config);
5682 if (!transcoder_is_dsi(cpu_transcoder))
5683 intel_ddi_enable_transcoder_func(pipe_config);
5685 if (dev_priv->display.initial_watermarks != NULL)
5686 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5688 if (INTEL_GEN(dev_priv) >= 11)
5689 icl_pipe_mbus_enable(intel_crtc);
5691 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5692 if (!transcoder_is_dsi(cpu_transcoder))
5693 intel_enable_pipe(pipe_config);
5695 if (intel_crtc->config->has_pch_encoder)
5696 lpt_pch_enable(pipe_config);
5698 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5699 intel_ddi_set_vc_payload_alloc(pipe_config, true);
5701 assert_vblank_disabled(crtc);
5702 drm_crtc_vblank_on(crtc);
5704 intel_encoders_enable(crtc, pipe_config, old_state);
5706 if (psl_clkgate_wa) {
5707 intel_wait_for_vblank(dev_priv, pipe);
5708 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5711 /* If we change the relative order between pipe/planes enabling, we need
5712 * to change the workaround. */
5713 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
5714 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5715 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5716 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5720 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force)
5722 struct drm_device *dev = crtc->base.dev;
5723 struct drm_i915_private *dev_priv = to_i915(dev);
5724 int pipe = crtc->pipe;
5726 /* To avoid upsetting the power well on haswell only disable the pfit if
5727 * it's in use. The hw state code will make sure we get this right. */
5728 if (force || crtc->config->pch_pfit.enabled) {
5729 I915_WRITE(PF_CTL(pipe), 0);
5730 I915_WRITE(PF_WIN_POS(pipe), 0);
5731 I915_WRITE(PF_WIN_SZ(pipe), 0);
5735 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5736 struct drm_atomic_state *old_state)
5738 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5739 struct drm_device *dev = crtc->dev;
5740 struct drm_i915_private *dev_priv = to_i915(dev);
5741 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5742 int pipe = intel_crtc->pipe;
5745 * Sometimes spurious CPU pipe underruns happen when the
5746 * pipe is already disabled, but FDI RX/TX is still enabled.
5747 * Happens at least with VGA+HDMI cloning. Suppress them.
5749 if (intel_crtc->config->has_pch_encoder) {
5750 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5751 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5754 intel_encoders_disable(crtc, old_crtc_state, old_state);
5756 drm_crtc_vblank_off(crtc);
5757 assert_vblank_disabled(crtc);
5759 intel_disable_pipe(old_crtc_state);
5761 ironlake_pfit_disable(intel_crtc, false);
5763 if (intel_crtc->config->has_pch_encoder)
5764 ironlake_fdi_disable(crtc);
5766 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5768 if (intel_crtc->config->has_pch_encoder) {
5769 ironlake_disable_pch_transcoder(dev_priv, pipe);
5771 if (HAS_PCH_CPT(dev_priv)) {
5775 /* disable TRANS_DP_CTL */
5776 reg = TRANS_DP_CTL(pipe);
5777 temp = I915_READ(reg);
5778 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5779 TRANS_DP_PORT_SEL_MASK);
5780 temp |= TRANS_DP_PORT_SEL_NONE;
5781 I915_WRITE(reg, temp);
5783 /* disable DPLL_SEL */
5784 temp = I915_READ(PCH_DPLL_SEL);
5785 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5786 I915_WRITE(PCH_DPLL_SEL, temp);
5789 ironlake_fdi_pll_disable(intel_crtc);
5792 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5793 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5796 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5797 struct drm_atomic_state *old_state)
5799 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5800 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5801 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5802 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5804 intel_encoders_disable(crtc, old_crtc_state, old_state);
5806 drm_crtc_vblank_off(crtc);
5807 assert_vblank_disabled(crtc);
5809 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5810 if (!transcoder_is_dsi(cpu_transcoder))
5811 intel_disable_pipe(old_crtc_state);
5813 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5814 intel_ddi_set_vc_payload_alloc(intel_crtc->config, false);
5816 if (!transcoder_is_dsi(cpu_transcoder))
5817 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
5819 if (INTEL_GEN(dev_priv) >= 9)
5820 skylake_scaler_disable(intel_crtc);
5822 ironlake_pfit_disable(intel_crtc, false);
5824 if (!transcoder_is_dsi(cpu_transcoder))
5825 intel_ddi_disable_pipe_clock(intel_crtc->config);
5827 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5829 if (INTEL_GEN(dev_priv) >= 11)
5830 icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state);
5833 static void i9xx_pfit_enable(struct intel_crtc *crtc)
5835 struct drm_device *dev = crtc->base.dev;
5836 struct drm_i915_private *dev_priv = to_i915(dev);
5837 struct intel_crtc_state *pipe_config = crtc->config;
5839 if (!pipe_config->gmch_pfit.control)
5843 * The panel fitter should only be adjusted whilst the pipe is disabled,
5844 * according to register description and PRM.
5846 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5847 assert_pipe_disabled(dev_priv, crtc->pipe);
5849 I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
5850 I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
5852 /* Border color in case we don't scale up to the full screen. Black by
5853 * default, change to something else for debugging. */
5854 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5857 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
5861 return POWER_DOMAIN_PORT_DDI_A_LANES;
5863 return POWER_DOMAIN_PORT_DDI_B_LANES;
5865 return POWER_DOMAIN_PORT_DDI_C_LANES;
5867 return POWER_DOMAIN_PORT_DDI_D_LANES;
5869 return POWER_DOMAIN_PORT_DDI_E_LANES;
5871 return POWER_DOMAIN_PORT_DDI_F_LANES;
5874 return POWER_DOMAIN_PORT_OTHER;
5878 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
5879 struct intel_crtc_state *crtc_state)
5881 struct drm_device *dev = crtc->dev;
5882 struct drm_i915_private *dev_priv = to_i915(dev);
5883 struct drm_encoder *encoder;
5884 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5885 enum pipe pipe = intel_crtc->pipe;
5887 enum transcoder transcoder = crtc_state->cpu_transcoder;
5889 if (!crtc_state->base.active)
5892 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
5893 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
5894 if (crtc_state->pch_pfit.enabled ||
5895 crtc_state->pch_pfit.force_thru)
5896 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5898 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
5899 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5901 mask |= BIT_ULL(intel_encoder->power_domain);
5904 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
5905 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
5907 if (crtc_state->shared_dpll)
5908 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
5914 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
5915 struct intel_crtc_state *crtc_state)
5917 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5918 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5919 enum intel_display_power_domain domain;
5920 u64 domains, new_domains, old_domains;
5922 old_domains = intel_crtc->enabled_power_domains;
5923 intel_crtc->enabled_power_domains = new_domains =
5924 get_crtc_power_domains(crtc, crtc_state);
5926 domains = new_domains & ~old_domains;
5928 for_each_power_domain(domain, domains)
5929 intel_display_power_get(dev_priv, domain);
5931 return old_domains & ~new_domains;
5934 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
5937 enum intel_display_power_domain domain;
5939 for_each_power_domain(domain, domains)
5940 intel_display_power_put(dev_priv, domain);
5943 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
5944 struct drm_atomic_state *old_state)
5946 struct intel_atomic_state *old_intel_state =
5947 to_intel_atomic_state(old_state);
5948 struct drm_crtc *crtc = pipe_config->base.crtc;
5949 struct drm_device *dev = crtc->dev;
5950 struct drm_i915_private *dev_priv = to_i915(dev);
5951 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5952 int pipe = intel_crtc->pipe;
5954 if (WARN_ON(intel_crtc->active))
5957 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5958 intel_dp_set_m_n(intel_crtc, M1_N1);
5960 intel_set_pipe_timings(intel_crtc);
5961 intel_set_pipe_src_size(intel_crtc);
5963 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
5964 struct drm_i915_private *dev_priv = to_i915(dev);
5966 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
5967 I915_WRITE(CHV_CANVAS(pipe), 0);
5970 i9xx_set_pipeconf(intel_crtc);
5972 intel_crtc->active = true;
5974 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5976 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5978 if (IS_CHERRYVIEW(dev_priv)) {
5979 chv_prepare_pll(intel_crtc, intel_crtc->config);
5980 chv_enable_pll(intel_crtc, intel_crtc->config);
5982 vlv_prepare_pll(intel_crtc, intel_crtc->config);
5983 vlv_enable_pll(intel_crtc, intel_crtc->config);
5986 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5988 i9xx_pfit_enable(intel_crtc);
5990 intel_color_load_luts(&pipe_config->base);
5992 dev_priv->display.initial_watermarks(old_intel_state,
5994 intel_enable_pipe(pipe_config);
5996 assert_vblank_disabled(crtc);
5997 drm_crtc_vblank_on(crtc);
5999 intel_encoders_enable(crtc, pipe_config, old_state);
6002 static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
6004 struct drm_device *dev = crtc->base.dev;
6005 struct drm_i915_private *dev_priv = to_i915(dev);
6007 I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
6008 I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
6011 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6012 struct drm_atomic_state *old_state)
6014 struct intel_atomic_state *old_intel_state =
6015 to_intel_atomic_state(old_state);
6016 struct drm_crtc *crtc = pipe_config->base.crtc;
6017 struct drm_device *dev = crtc->dev;
6018 struct drm_i915_private *dev_priv = to_i915(dev);
6019 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6020 enum pipe pipe = intel_crtc->pipe;
6022 if (WARN_ON(intel_crtc->active))
6025 i9xx_set_pll_dividers(intel_crtc);
6027 if (intel_crtc_has_dp_encoder(intel_crtc->config))
6028 intel_dp_set_m_n(intel_crtc, M1_N1);
6030 intel_set_pipe_timings(intel_crtc);
6031 intel_set_pipe_src_size(intel_crtc);
6033 i9xx_set_pipeconf(intel_crtc);
6035 intel_crtc->active = true;
6037 if (!IS_GEN2(dev_priv))
6038 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6040 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6042 i9xx_enable_pll(intel_crtc, pipe_config);
6044 i9xx_pfit_enable(intel_crtc);
6046 intel_color_load_luts(&pipe_config->base);
6048 if (dev_priv->display.initial_watermarks != NULL)
6049 dev_priv->display.initial_watermarks(old_intel_state,
6050 intel_crtc->config);
6052 intel_update_watermarks(intel_crtc);
6053 intel_enable_pipe(pipe_config);
6055 assert_vblank_disabled(crtc);
6056 drm_crtc_vblank_on(crtc);
6058 intel_encoders_enable(crtc, pipe_config, old_state);
6061 static void i9xx_pfit_disable(struct intel_crtc *crtc)
6063 struct drm_device *dev = crtc->base.dev;
6064 struct drm_i915_private *dev_priv = to_i915(dev);
6066 if (!crtc->config->gmch_pfit.control)
6069 assert_pipe_disabled(dev_priv, crtc->pipe);
6071 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6072 I915_READ(PFIT_CONTROL));
6073 I915_WRITE(PFIT_CONTROL, 0);
6076 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6077 struct drm_atomic_state *old_state)
6079 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6080 struct drm_device *dev = crtc->dev;
6081 struct drm_i915_private *dev_priv = to_i915(dev);
6082 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6083 int pipe = intel_crtc->pipe;
6086 * On gen2 planes are double buffered but the pipe isn't, so we must
6087 * wait for planes to fully turn off before disabling the pipe.
6089 if (IS_GEN2(dev_priv))
6090 intel_wait_for_vblank(dev_priv, pipe);
6092 intel_encoders_disable(crtc, old_crtc_state, old_state);
6094 drm_crtc_vblank_off(crtc);
6095 assert_vblank_disabled(crtc);
6097 intel_disable_pipe(old_crtc_state);
6099 i9xx_pfit_disable(intel_crtc);
6101 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6103 if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) {
6104 if (IS_CHERRYVIEW(dev_priv))
6105 chv_disable_pll(dev_priv, pipe);
6106 else if (IS_VALLEYVIEW(dev_priv))
6107 vlv_disable_pll(dev_priv, pipe);
6109 i9xx_disable_pll(intel_crtc);
6112 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6114 if (!IS_GEN2(dev_priv))
6115 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6117 if (!dev_priv->display.initial_watermarks)
6118 intel_update_watermarks(intel_crtc);
6120 /* clock the pipe down to 640x480@60 to potentially save power */
6121 if (IS_I830(dev_priv))
6122 i830_enable_pipe(dev_priv, pipe);
6125 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6126 struct drm_modeset_acquire_ctx *ctx)
6128 struct intel_encoder *encoder;
6129 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6130 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6131 enum intel_display_power_domain domain;
6132 struct intel_plane *plane;
6134 struct drm_atomic_state *state;
6135 struct intel_crtc_state *crtc_state;
6138 if (!intel_crtc->active)
6141 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6142 const struct intel_plane_state *plane_state =
6143 to_intel_plane_state(plane->base.state);
6145 if (plane_state->base.visible)
6146 intel_plane_disable_noatomic(intel_crtc, plane);
6149 state = drm_atomic_state_alloc(crtc->dev);
6151 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6152 crtc->base.id, crtc->name);
6156 state->acquire_ctx = ctx;
6158 /* Everything's already locked, -EDEADLK can't happen. */
6159 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6160 ret = drm_atomic_add_affected_connectors(state, crtc);
6162 WARN_ON(IS_ERR(crtc_state) || ret);
6164 dev_priv->display.crtc_disable(crtc_state, state);
6166 drm_atomic_state_put(state);
6168 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6169 crtc->base.id, crtc->name);
6171 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6172 crtc->state->active = false;
6173 intel_crtc->active = false;
6174 crtc->enabled = false;
6175 crtc->state->connector_mask = 0;
6176 crtc->state->encoder_mask = 0;
6178 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6179 encoder->base.crtc = NULL;
6181 intel_fbc_disable(intel_crtc);
6182 intel_update_watermarks(intel_crtc);
6183 intel_disable_shared_dpll(intel_crtc);
6185 domains = intel_crtc->enabled_power_domains;
6186 for_each_power_domain(domain, domains)
6187 intel_display_power_put(dev_priv, domain);
6188 intel_crtc->enabled_power_domains = 0;
6190 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6191 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6192 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6196 * turn all crtc's off, but do not adjust state
6197 * This has to be paired with a call to intel_modeset_setup_hw_state.
6199 int intel_display_suspend(struct drm_device *dev)
6201 struct drm_i915_private *dev_priv = to_i915(dev);
6202 struct drm_atomic_state *state;
6205 state = drm_atomic_helper_suspend(dev);
6206 ret = PTR_ERR_OR_ZERO(state);
6208 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6210 dev_priv->modeset_restore_state = state;
6214 void intel_encoder_destroy(struct drm_encoder *encoder)
6216 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6218 drm_encoder_cleanup(encoder);
6219 kfree(intel_encoder);
6222 /* Cross check the actual hw state with our own modeset state tracking (and it's
6223 * internal consistency). */
6224 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6225 struct drm_connector_state *conn_state)
6227 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6229 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6230 connector->base.base.id,
6231 connector->base.name);
6233 if (connector->get_hw_state(connector)) {
6234 struct intel_encoder *encoder = connector->encoder;
6236 I915_STATE_WARN(!crtc_state,
6237 "connector enabled without attached crtc\n");
6242 I915_STATE_WARN(!crtc_state->active,
6243 "connector is active, but attached crtc isn't\n");
6245 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6248 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6249 "atomic encoder doesn't match attached encoder\n");
6251 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6252 "attached encoder crtc differs from connector crtc\n");
6254 I915_STATE_WARN(crtc_state && crtc_state->active,
6255 "attached crtc is active, but connector isn't\n");
6256 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6257 "best encoder set without crtc!\n");
6261 int intel_connector_init(struct intel_connector *connector)
6263 struct intel_digital_connector_state *conn_state;
6266 * Allocate enough memory to hold intel_digital_connector_state,
6267 * This might be a few bytes too many, but for connectors that don't
6268 * need it we'll free the state and allocate a smaller one on the first
6269 * succesful commit anyway.
6271 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
6275 __drm_atomic_helper_connector_reset(&connector->base,
6281 struct intel_connector *intel_connector_alloc(void)
6283 struct intel_connector *connector;
6285 connector = kzalloc(sizeof *connector, GFP_KERNEL);
6289 if (intel_connector_init(connector) < 0) {
6298 * Free the bits allocated by intel_connector_alloc.
6299 * This should only be used after intel_connector_alloc has returned
6300 * successfully, and before drm_connector_init returns successfully.
6301 * Otherwise the destroy callbacks for the connector and the state should
6302 * take care of proper cleanup/free
6304 void intel_connector_free(struct intel_connector *connector)
6306 kfree(to_intel_digital_connector_state(connector->base.state));
6310 /* Simple connector->get_hw_state implementation for encoders that support only
6311 * one connector and no cloning and hence the encoder state determines the state
6312 * of the connector. */
6313 bool intel_connector_get_hw_state(struct intel_connector *connector)
6316 struct intel_encoder *encoder = connector->encoder;
6318 return encoder->get_hw_state(encoder, &pipe);
6321 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6323 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6324 return crtc_state->fdi_lanes;
6329 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6330 struct intel_crtc_state *pipe_config)
6332 struct drm_i915_private *dev_priv = to_i915(dev);
6333 struct drm_atomic_state *state = pipe_config->base.state;
6334 struct intel_crtc *other_crtc;
6335 struct intel_crtc_state *other_crtc_state;
6337 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6338 pipe_name(pipe), pipe_config->fdi_lanes);
6339 if (pipe_config->fdi_lanes > 4) {
6340 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6341 pipe_name(pipe), pipe_config->fdi_lanes);
6345 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6346 if (pipe_config->fdi_lanes > 2) {
6347 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6348 pipe_config->fdi_lanes);
6355 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6358 /* Ivybridge 3 pipe is really complicated */
6363 if (pipe_config->fdi_lanes <= 2)
6366 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6368 intel_atomic_get_crtc_state(state, other_crtc);
6369 if (IS_ERR(other_crtc_state))
6370 return PTR_ERR(other_crtc_state);
6372 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6373 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6374 pipe_name(pipe), pipe_config->fdi_lanes);
6379 if (pipe_config->fdi_lanes > 2) {
6380 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6381 pipe_name(pipe), pipe_config->fdi_lanes);
6385 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6387 intel_atomic_get_crtc_state(state, other_crtc);
6388 if (IS_ERR(other_crtc_state))
6389 return PTR_ERR(other_crtc_state);
6391 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6392 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6402 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6403 struct intel_crtc_state *pipe_config)
6405 struct drm_device *dev = intel_crtc->base.dev;
6406 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6407 int lane, link_bw, fdi_dotclock, ret;
6408 bool needs_recompute = false;
6411 /* FDI is a binary signal running at ~2.7GHz, encoding
6412 * each output octet as 10 bits. The actual frequency
6413 * is stored as a divider into a 100MHz clock, and the
6414 * mode pixel clock is stored in units of 1KHz.
6415 * Hence the bw of each lane in terms of the mode signal
6418 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6420 fdi_dotclock = adjusted_mode->crtc_clock;
6422 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6423 pipe_config->pipe_bpp);
6425 pipe_config->fdi_lanes = lane;
6427 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6428 link_bw, &pipe_config->fdi_m_n, false);
6430 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6431 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6432 pipe_config->pipe_bpp -= 2*3;
6433 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6434 pipe_config->pipe_bpp);
6435 needs_recompute = true;
6436 pipe_config->bw_constrained = true;
6441 if (needs_recompute)
6447 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6449 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6450 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6452 /* IPS only exists on ULT machines and is tied to pipe A. */
6453 if (!hsw_crtc_supports_ips(crtc))
6456 if (!i915_modparams.enable_ips)
6459 if (crtc_state->pipe_bpp > 24)
6463 * We compare against max which means we must take
6464 * the increased cdclk requirement into account when
6465 * calculating the new cdclk.
6467 * Should measure whether using a lower cdclk w/o IPS
6469 if (IS_BROADWELL(dev_priv) &&
6470 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6476 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6478 struct drm_i915_private *dev_priv =
6479 to_i915(crtc_state->base.crtc->dev);
6480 struct intel_atomic_state *intel_state =
6481 to_intel_atomic_state(crtc_state->base.state);
6483 if (!hsw_crtc_state_ips_capable(crtc_state))
6486 if (crtc_state->ips_force_disable)
6489 /* IPS should be fine as long as at least one plane is enabled. */
6490 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6493 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6494 if (IS_BROADWELL(dev_priv) &&
6495 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6501 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6503 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6505 /* GDG double wide on either pipe, otherwise pipe A only */
6506 return INTEL_GEN(dev_priv) < 4 &&
6507 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6510 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6512 uint32_t pixel_rate;
6514 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6517 * We only use IF-ID interlacing. If we ever use
6518 * PF-ID we'll need to adjust the pixel_rate here.
6521 if (pipe_config->pch_pfit.enabled) {
6522 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6523 uint32_t pfit_size = pipe_config->pch_pfit.size;
6525 pipe_w = pipe_config->pipe_src_w;
6526 pipe_h = pipe_config->pipe_src_h;
6528 pfit_w = (pfit_size >> 16) & 0xFFFF;
6529 pfit_h = pfit_size & 0xFFFF;
6530 if (pipe_w < pfit_w)
6532 if (pipe_h < pfit_h)
6535 if (WARN_ON(!pfit_w || !pfit_h))
6538 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6545 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6547 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6549 if (HAS_GMCH_DISPLAY(dev_priv))
6550 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6551 crtc_state->pixel_rate =
6552 crtc_state->base.adjusted_mode.crtc_clock;
6554 crtc_state->pixel_rate =
6555 ilk_pipe_pixel_rate(crtc_state);
6558 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6559 struct intel_crtc_state *pipe_config)
6561 struct drm_device *dev = crtc->base.dev;
6562 struct drm_i915_private *dev_priv = to_i915(dev);
6563 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6564 int clock_limit = dev_priv->max_dotclk_freq;
6566 if (INTEL_GEN(dev_priv) < 4) {
6567 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6570 * Enable double wide mode when the dot clock
6571 * is > 90% of the (display) core speed.
6573 if (intel_crtc_supports_double_wide(crtc) &&
6574 adjusted_mode->crtc_clock > clock_limit) {
6575 clock_limit = dev_priv->max_dotclk_freq;
6576 pipe_config->double_wide = true;
6580 if (adjusted_mode->crtc_clock > clock_limit) {
6581 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6582 adjusted_mode->crtc_clock, clock_limit,
6583 yesno(pipe_config->double_wide));
6587 if (pipe_config->ycbcr420 && pipe_config->base.ctm) {
6589 * There is only one pipe CSC unit per pipe, and we need that
6590 * for output conversion from RGB->YCBCR. So if CTM is already
6591 * applied we can't support YCBCR420 output.
6593 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6598 * Pipe horizontal size must be even in:
6600 * - LVDS dual channel mode
6601 * - Double wide pipe
6603 if (pipe_config->pipe_src_w & 1) {
6604 if (pipe_config->double_wide) {
6605 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6609 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6610 intel_is_dual_link_lvds(dev)) {
6611 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6616 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6617 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6619 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6620 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6623 intel_crtc_compute_pixel_rate(pipe_config);
6625 if (pipe_config->has_pch_encoder)
6626 return ironlake_fdi_compute_config(crtc, pipe_config);
6632 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6634 while (*num > DATA_LINK_M_N_MASK ||
6635 *den > DATA_LINK_M_N_MASK) {
6641 static void compute_m_n(unsigned int m, unsigned int n,
6642 uint32_t *ret_m, uint32_t *ret_n,
6646 * Reduce M/N as much as possible without loss in precision. Several DP
6647 * dongles in particular seem to be fussy about too large *link* M/N
6648 * values. The passed in values are more likely to have the least
6649 * significant bits zero than M after rounding below, so do this first.
6652 while ((m & 1) == 0 && (n & 1) == 0) {
6658 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6659 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6660 intel_reduce_m_n_ratio(ret_m, ret_n);
6664 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6665 int pixel_clock, int link_clock,
6666 struct intel_link_m_n *m_n,
6671 compute_m_n(bits_per_pixel * pixel_clock,
6672 link_clock * nlanes * 8,
6673 &m_n->gmch_m, &m_n->gmch_n,
6676 compute_m_n(pixel_clock, link_clock,
6677 &m_n->link_m, &m_n->link_n,
6681 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6683 if (i915_modparams.panel_use_ssc >= 0)
6684 return i915_modparams.panel_use_ssc != 0;
6685 return dev_priv->vbt.lvds_use_ssc
6686 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6689 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
6691 return (1 << dpll->n) << 16 | dpll->m2;
6694 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6696 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
6699 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
6700 struct intel_crtc_state *crtc_state,
6701 struct dpll *reduced_clock)
6703 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6706 if (IS_PINEVIEW(dev_priv)) {
6707 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
6709 fp2 = pnv_dpll_compute_fp(reduced_clock);
6711 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
6713 fp2 = i9xx_dpll_compute_fp(reduced_clock);
6716 crtc_state->dpll_hw_state.fp0 = fp;
6718 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6720 crtc_state->dpll_hw_state.fp1 = fp2;
6722 crtc_state->dpll_hw_state.fp1 = fp;
6726 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6732 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6733 * and set it to a reasonable value instead.
6735 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6736 reg_val &= 0xffffff00;
6737 reg_val |= 0x00000030;
6738 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6740 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6741 reg_val &= 0x00ffffff;
6742 reg_val |= 0x8c000000;
6743 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6745 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6746 reg_val &= 0xffffff00;
6747 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6749 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6750 reg_val &= 0x00ffffff;
6751 reg_val |= 0xb0000000;
6752 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6755 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
6756 struct intel_link_m_n *m_n)
6758 struct drm_device *dev = crtc->base.dev;
6759 struct drm_i915_private *dev_priv = to_i915(dev);
6760 int pipe = crtc->pipe;
6762 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6763 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6764 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6765 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6768 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
6769 struct intel_link_m_n *m_n,
6770 struct intel_link_m_n *m2_n2)
6772 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6773 int pipe = crtc->pipe;
6774 enum transcoder transcoder = crtc->config->cpu_transcoder;
6776 if (INTEL_GEN(dev_priv) >= 5) {
6777 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6778 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6779 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6780 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
6781 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6782 * for gen < 8) and if DRRS is supported (to make sure the
6783 * registers are not unnecessarily accessed).
6785 if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
6786 INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
6787 I915_WRITE(PIPE_DATA_M2(transcoder),
6788 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6789 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6790 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6791 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6794 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6795 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6796 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6797 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
6801 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
6803 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6806 dp_m_n = &crtc->config->dp_m_n;
6807 dp_m2_n2 = &crtc->config->dp_m2_n2;
6808 } else if (m_n == M2_N2) {
6811 * M2_N2 registers are not supported. Hence m2_n2 divider value
6812 * needs to be programmed into M1_N1.
6814 dp_m_n = &crtc->config->dp_m2_n2;
6816 DRM_ERROR("Unsupported divider value\n");
6820 if (crtc->config->has_pch_encoder)
6821 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
6823 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
6826 static void vlv_compute_dpll(struct intel_crtc *crtc,
6827 struct intel_crtc_state *pipe_config)
6829 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
6830 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6831 if (crtc->pipe != PIPE_A)
6832 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6834 /* DPLL not used with DSI, but still need the rest set up */
6835 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6836 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6837 DPLL_EXT_BUFFER_ENABLE_VLV;
6839 pipe_config->dpll_hw_state.dpll_md =
6840 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6843 static void chv_compute_dpll(struct intel_crtc *crtc,
6844 struct intel_crtc_state *pipe_config)
6846 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
6847 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6848 if (crtc->pipe != PIPE_A)
6849 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6851 /* DPLL not used with DSI, but still need the rest set up */
6852 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6853 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6855 pipe_config->dpll_hw_state.dpll_md =
6856 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6859 static void vlv_prepare_pll(struct intel_crtc *crtc,
6860 const struct intel_crtc_state *pipe_config)
6862 struct drm_device *dev = crtc->base.dev;
6863 struct drm_i915_private *dev_priv = to_i915(dev);
6864 enum pipe pipe = crtc->pipe;
6866 u32 bestn, bestm1, bestm2, bestp1, bestp2;
6867 u32 coreclk, reg_val;
6870 I915_WRITE(DPLL(pipe),
6871 pipe_config->dpll_hw_state.dpll &
6872 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6874 /* No need to actually set up the DPLL with DSI */
6875 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6878 mutex_lock(&dev_priv->sb_lock);
6880 bestn = pipe_config->dpll.n;
6881 bestm1 = pipe_config->dpll.m1;
6882 bestm2 = pipe_config->dpll.m2;
6883 bestp1 = pipe_config->dpll.p1;
6884 bestp2 = pipe_config->dpll.p2;
6886 /* See eDP HDMI DPIO driver vbios notes doc */
6888 /* PLL B needs special handling */
6890 vlv_pllb_recal_opamp(dev_priv, pipe);
6892 /* Set up Tx target for periodic Rcomp update */
6893 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
6895 /* Disable target IRef on PLL */
6896 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
6897 reg_val &= 0x00ffffff;
6898 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
6900 /* Disable fast lock */
6901 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
6903 /* Set idtafcrecal before PLL is enabled */
6904 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6905 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6906 mdiv |= ((bestn << DPIO_N_SHIFT));
6907 mdiv |= (1 << DPIO_K_SHIFT);
6910 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6911 * but we don't support that).
6912 * Note: don't use the DAC post divider as it seems unstable.
6914 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
6915 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6917 mdiv |= DPIO_ENABLE_CALIBRATION;
6918 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6920 /* Set HBR and RBR LPF coefficients */
6921 if (pipe_config->port_clock == 162000 ||
6922 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) ||
6923 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI))
6924 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6927 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6930 if (intel_crtc_has_dp_encoder(pipe_config)) {
6931 /* Use SSC source */
6933 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6936 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6938 } else { /* HDMI or VGA */
6939 /* Use bend source */
6941 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6944 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6948 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
6949 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
6950 if (intel_crtc_has_dp_encoder(crtc->config))
6951 coreclk |= 0x01000000;
6952 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
6954 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
6955 mutex_unlock(&dev_priv->sb_lock);
6958 static void chv_prepare_pll(struct intel_crtc *crtc,
6959 const struct intel_crtc_state *pipe_config)
6961 struct drm_device *dev = crtc->base.dev;
6962 struct drm_i915_private *dev_priv = to_i915(dev);
6963 enum pipe pipe = crtc->pipe;
6964 enum dpio_channel port = vlv_pipe_to_channel(pipe);
6965 u32 loopfilter, tribuf_calcntr;
6966 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
6970 /* Enable Refclk and SSC */
6971 I915_WRITE(DPLL(pipe),
6972 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
6974 /* No need to actually set up the DPLL with DSI */
6975 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6978 bestn = pipe_config->dpll.n;
6979 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
6980 bestm1 = pipe_config->dpll.m1;
6981 bestm2 = pipe_config->dpll.m2 >> 22;
6982 bestp1 = pipe_config->dpll.p1;
6983 bestp2 = pipe_config->dpll.p2;
6984 vco = pipe_config->dpll.vco;
6988 mutex_lock(&dev_priv->sb_lock);
6990 /* p1 and p2 divider */
6991 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
6992 5 << DPIO_CHV_S1_DIV_SHIFT |
6993 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
6994 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
6995 1 << DPIO_CHV_K_DIV_SHIFT);
6997 /* Feedback post-divider - m2 */
6998 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7000 /* Feedback refclk divider - n and m1 */
7001 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7002 DPIO_CHV_M1_DIV_BY_2 |
7003 1 << DPIO_CHV_N_DIV_SHIFT);
7005 /* M2 fraction division */
7006 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7008 /* M2 fraction division enable */
7009 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7010 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7011 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7013 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7014 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7016 /* Program digital lock detect threshold */
7017 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7018 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7019 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7020 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7022 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7023 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7026 if (vco == 5400000) {
7027 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7028 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7029 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7030 tribuf_calcntr = 0x9;
7031 } else if (vco <= 6200000) {
7032 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7033 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7034 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7035 tribuf_calcntr = 0x9;
7036 } else if (vco <= 6480000) {
7037 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7038 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7039 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7040 tribuf_calcntr = 0x8;
7042 /* Not supported. Apply the same limits as in the max case */
7043 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7044 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7045 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7048 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7050 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7051 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7052 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7053 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7056 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7057 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7060 mutex_unlock(&dev_priv->sb_lock);
7064 * vlv_force_pll_on - forcibly enable just the PLL
7065 * @dev_priv: i915 private structure
7066 * @pipe: pipe PLL to enable
7067 * @dpll: PLL configuration
7069 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7070 * in cases where we need the PLL enabled even when @pipe is not going to
7073 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7074 const struct dpll *dpll)
7076 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7077 struct intel_crtc_state *pipe_config;
7079 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7083 pipe_config->base.crtc = &crtc->base;
7084 pipe_config->pixel_multiplier = 1;
7085 pipe_config->dpll = *dpll;
7087 if (IS_CHERRYVIEW(dev_priv)) {
7088 chv_compute_dpll(crtc, pipe_config);
7089 chv_prepare_pll(crtc, pipe_config);
7090 chv_enable_pll(crtc, pipe_config);
7092 vlv_compute_dpll(crtc, pipe_config);
7093 vlv_prepare_pll(crtc, pipe_config);
7094 vlv_enable_pll(crtc, pipe_config);
7103 * vlv_force_pll_off - forcibly disable just the PLL
7104 * @dev_priv: i915 private structure
7105 * @pipe: pipe PLL to disable
7107 * Disable the PLL for @pipe. To be used in cases where we need
7108 * the PLL enabled even when @pipe is not going to be enabled.
7110 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7112 if (IS_CHERRYVIEW(dev_priv))
7113 chv_disable_pll(dev_priv, pipe);
7115 vlv_disable_pll(dev_priv, pipe);
7118 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7119 struct intel_crtc_state *crtc_state,
7120 struct dpll *reduced_clock)
7122 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7124 struct dpll *clock = &crtc_state->dpll;
7126 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7128 dpll = DPLL_VGA_MODE_DIS;
7130 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7131 dpll |= DPLLB_MODE_LVDS;
7133 dpll |= DPLLB_MODE_DAC_SERIAL;
7135 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7136 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7137 dpll |= (crtc_state->pixel_multiplier - 1)
7138 << SDVO_MULTIPLIER_SHIFT_HIRES;
7141 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7142 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7143 dpll |= DPLL_SDVO_HIGH_SPEED;
7145 if (intel_crtc_has_dp_encoder(crtc_state))
7146 dpll |= DPLL_SDVO_HIGH_SPEED;
7148 /* compute bitmask from p1 value */
7149 if (IS_PINEVIEW(dev_priv))
7150 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7152 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7153 if (IS_G4X(dev_priv) && reduced_clock)
7154 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7156 switch (clock->p2) {
7158 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7161 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7164 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7167 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7170 if (INTEL_GEN(dev_priv) >= 4)
7171 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7173 if (crtc_state->sdvo_tv_clock)
7174 dpll |= PLL_REF_INPUT_TVCLKINBC;
7175 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7176 intel_panel_use_ssc(dev_priv))
7177 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7179 dpll |= PLL_REF_INPUT_DREFCLK;
7181 dpll |= DPLL_VCO_ENABLE;
7182 crtc_state->dpll_hw_state.dpll = dpll;
7184 if (INTEL_GEN(dev_priv) >= 4) {
7185 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7186 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7187 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7191 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7192 struct intel_crtc_state *crtc_state,
7193 struct dpll *reduced_clock)
7195 struct drm_device *dev = crtc->base.dev;
7196 struct drm_i915_private *dev_priv = to_i915(dev);
7198 struct dpll *clock = &crtc_state->dpll;
7200 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7202 dpll = DPLL_VGA_MODE_DIS;
7204 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7205 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7208 dpll |= PLL_P1_DIVIDE_BY_TWO;
7210 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7212 dpll |= PLL_P2_DIVIDE_BY_4;
7215 if (!IS_I830(dev_priv) &&
7216 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7217 dpll |= DPLL_DVO_2X_MODE;
7219 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;
7229 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
7231 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7232 enum pipe pipe = intel_crtc->pipe;
7233 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
7234 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
7235 uint32_t crtc_vtotal, crtc_vblank_end;
7238 /* We need to be careful not to changed the adjusted mode, for otherwise
7239 * the hw state checker will get angry at the mismatch. */
7240 crtc_vtotal = adjusted_mode->crtc_vtotal;
7241 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7243 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7244 /* the chip adds 2 halflines automatically */
7246 crtc_vblank_end -= 1;
7248 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7249 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7251 vsyncshift = adjusted_mode->crtc_hsync_start -
7252 adjusted_mode->crtc_htotal / 2;
7254 vsyncshift += adjusted_mode->crtc_htotal;
7257 if (INTEL_GEN(dev_priv) > 3)
7258 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7260 I915_WRITE(HTOTAL(cpu_transcoder),
7261 (adjusted_mode->crtc_hdisplay - 1) |
7262 ((adjusted_mode->crtc_htotal - 1) << 16));
7263 I915_WRITE(HBLANK(cpu_transcoder),
7264 (adjusted_mode->crtc_hblank_start - 1) |
7265 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7266 I915_WRITE(HSYNC(cpu_transcoder),
7267 (adjusted_mode->crtc_hsync_start - 1) |
7268 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7270 I915_WRITE(VTOTAL(cpu_transcoder),
7271 (adjusted_mode->crtc_vdisplay - 1) |
7272 ((crtc_vtotal - 1) << 16));
7273 I915_WRITE(VBLANK(cpu_transcoder),
7274 (adjusted_mode->crtc_vblank_start - 1) |
7275 ((crtc_vblank_end - 1) << 16));
7276 I915_WRITE(VSYNC(cpu_transcoder),
7277 (adjusted_mode->crtc_vsync_start - 1) |
7278 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7280 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7281 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7282 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7284 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7285 (pipe == PIPE_B || pipe == PIPE_C))
7286 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7290 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc)
7292 struct drm_device *dev = intel_crtc->base.dev;
7293 struct drm_i915_private *dev_priv = to_i915(dev);
7294 enum pipe pipe = intel_crtc->pipe;
7296 /* pipesrc controls the size that is scaled from, which should
7297 * always be the user's requested size.
7299 I915_WRITE(PIPESRC(pipe),
7300 ((intel_crtc->config->pipe_src_w - 1) << 16) |
7301 (intel_crtc->config->pipe_src_h - 1));
7304 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7305 struct intel_crtc_state *pipe_config)
7307 struct drm_device *dev = crtc->base.dev;
7308 struct drm_i915_private *dev_priv = to_i915(dev);
7309 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7312 tmp = I915_READ(HTOTAL(cpu_transcoder));
7313 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7314 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7315 tmp = I915_READ(HBLANK(cpu_transcoder));
7316 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7317 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7318 tmp = I915_READ(HSYNC(cpu_transcoder));
7319 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7320 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7322 tmp = I915_READ(VTOTAL(cpu_transcoder));
7323 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7324 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7325 tmp = I915_READ(VBLANK(cpu_transcoder));
7326 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7327 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7328 tmp = I915_READ(VSYNC(cpu_transcoder));
7329 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7330 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7332 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7333 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7334 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7335 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7339 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7340 struct intel_crtc_state *pipe_config)
7342 struct drm_device *dev = crtc->base.dev;
7343 struct drm_i915_private *dev_priv = to_i915(dev);
7346 tmp = I915_READ(PIPESRC(crtc->pipe));
7347 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7348 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7350 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7351 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7354 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7355 struct intel_crtc_state *pipe_config)
7357 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7358 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7359 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7360 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7362 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7363 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7364 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7365 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7367 mode->flags = pipe_config->base.adjusted_mode.flags;
7368 mode->type = DRM_MODE_TYPE_DRIVER;
7370 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7372 mode->hsync = drm_mode_hsync(mode);
7373 mode->vrefresh = drm_mode_vrefresh(mode);
7374 drm_mode_set_name(mode);
7377 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
7379 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7384 /* we keep both pipes enabled on 830 */
7385 if (IS_I830(dev_priv))
7386 pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
7388 if (intel_crtc->config->double_wide)
7389 pipeconf |= PIPECONF_DOUBLE_WIDE;
7391 /* only g4x and later have fancy bpc/dither controls */
7392 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7393 IS_CHERRYVIEW(dev_priv)) {
7394 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7395 if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
7396 pipeconf |= PIPECONF_DITHER_EN |
7397 PIPECONF_DITHER_TYPE_SP;
7399 switch (intel_crtc->config->pipe_bpp) {
7401 pipeconf |= PIPECONF_6BPC;
7404 pipeconf |= PIPECONF_8BPC;
7407 pipeconf |= PIPECONF_10BPC;
7410 /* Case prevented by intel_choose_pipe_bpp_dither. */
7415 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7416 if (INTEL_GEN(dev_priv) < 4 ||
7417 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7418 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7420 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7422 pipeconf |= PIPECONF_PROGRESSIVE;
7424 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7425 intel_crtc->config->limited_color_range)
7426 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7428 I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
7429 POSTING_READ(PIPECONF(intel_crtc->pipe));
7432 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7433 struct intel_crtc_state *crtc_state)
7435 struct drm_device *dev = crtc->base.dev;
7436 struct drm_i915_private *dev_priv = to_i915(dev);
7437 const struct intel_limit *limit;
7440 memset(&crtc_state->dpll_hw_state, 0,
7441 sizeof(crtc_state->dpll_hw_state));
7443 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7444 if (intel_panel_use_ssc(dev_priv)) {
7445 refclk = dev_priv->vbt.lvds_ssc_freq;
7446 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7449 limit = &intel_limits_i8xx_lvds;
7450 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7451 limit = &intel_limits_i8xx_dvo;
7453 limit = &intel_limits_i8xx_dac;
7456 if (!crtc_state->clock_set &&
7457 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7458 refclk, NULL, &crtc_state->dpll)) {
7459 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7463 i8xx_compute_dpll(crtc, crtc_state, NULL);
7468 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7469 struct intel_crtc_state *crtc_state)
7471 struct drm_device *dev = crtc->base.dev;
7472 struct drm_i915_private *dev_priv = to_i915(dev);
7473 const struct intel_limit *limit;
7476 memset(&crtc_state->dpll_hw_state, 0,
7477 sizeof(crtc_state->dpll_hw_state));
7479 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7480 if (intel_panel_use_ssc(dev_priv)) {
7481 refclk = dev_priv->vbt.lvds_ssc_freq;
7482 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7485 if (intel_is_dual_link_lvds(dev))
7486 limit = &intel_limits_g4x_dual_channel_lvds;
7488 limit = &intel_limits_g4x_single_channel_lvds;
7489 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7490 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7491 limit = &intel_limits_g4x_hdmi;
7492 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7493 limit = &intel_limits_g4x_sdvo;
7495 /* The option is for other outputs */
7496 limit = &intel_limits_i9xx_sdvo;
7499 if (!crtc_state->clock_set &&
7500 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7501 refclk, NULL, &crtc_state->dpll)) {
7502 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7506 i9xx_compute_dpll(crtc, crtc_state, NULL);
7511 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7512 struct intel_crtc_state *crtc_state)
7514 struct drm_device *dev = crtc->base.dev;
7515 struct drm_i915_private *dev_priv = to_i915(dev);
7516 const struct intel_limit *limit;
7519 memset(&crtc_state->dpll_hw_state, 0,
7520 sizeof(crtc_state->dpll_hw_state));
7522 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7523 if (intel_panel_use_ssc(dev_priv)) {
7524 refclk = dev_priv->vbt.lvds_ssc_freq;
7525 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7528 limit = &intel_limits_pineview_lvds;
7530 limit = &intel_limits_pineview_sdvo;
7533 if (!crtc_state->clock_set &&
7534 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7535 refclk, NULL, &crtc_state->dpll)) {
7536 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7540 i9xx_compute_dpll(crtc, crtc_state, NULL);
7545 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7546 struct intel_crtc_state *crtc_state)
7548 struct drm_device *dev = crtc->base.dev;
7549 struct drm_i915_private *dev_priv = to_i915(dev);
7550 const struct intel_limit *limit;
7553 memset(&crtc_state->dpll_hw_state, 0,
7554 sizeof(crtc_state->dpll_hw_state));
7556 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7557 if (intel_panel_use_ssc(dev_priv)) {
7558 refclk = dev_priv->vbt.lvds_ssc_freq;
7559 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7562 limit = &intel_limits_i9xx_lvds;
7564 limit = &intel_limits_i9xx_sdvo;
7567 if (!crtc_state->clock_set &&
7568 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7569 refclk, NULL, &crtc_state->dpll)) {
7570 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7574 i9xx_compute_dpll(crtc, crtc_state, NULL);
7579 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7580 struct intel_crtc_state *crtc_state)
7582 int refclk = 100000;
7583 const struct intel_limit *limit = &intel_limits_chv;
7585 memset(&crtc_state->dpll_hw_state, 0,
7586 sizeof(crtc_state->dpll_hw_state));
7588 if (!crtc_state->clock_set &&
7589 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7590 refclk, NULL, &crtc_state->dpll)) {
7591 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7595 chv_compute_dpll(crtc, crtc_state);
7600 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7601 struct intel_crtc_state *crtc_state)
7603 int refclk = 100000;
7604 const struct intel_limit *limit = &intel_limits_vlv;
7606 memset(&crtc_state->dpll_hw_state, 0,
7607 sizeof(crtc_state->dpll_hw_state));
7609 if (!crtc_state->clock_set &&
7610 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7611 refclk, NULL, &crtc_state->dpll)) {
7612 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7616 vlv_compute_dpll(crtc, crtc_state);
7621 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7622 struct intel_crtc_state *pipe_config)
7624 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7627 if (INTEL_GEN(dev_priv) <= 3 &&
7628 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7631 tmp = I915_READ(PFIT_CONTROL);
7632 if (!(tmp & PFIT_ENABLE))
7635 /* Check whether the pfit is attached to our pipe. */
7636 if (INTEL_GEN(dev_priv) < 4) {
7637 if (crtc->pipe != PIPE_B)
7640 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7644 pipe_config->gmch_pfit.control = tmp;
7645 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7648 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7649 struct intel_crtc_state *pipe_config)
7651 struct drm_device *dev = crtc->base.dev;
7652 struct drm_i915_private *dev_priv = to_i915(dev);
7653 int pipe = pipe_config->cpu_transcoder;
7656 int refclk = 100000;
7658 /* In case of DSI, DPLL will not be used */
7659 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7662 mutex_lock(&dev_priv->sb_lock);
7663 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7664 mutex_unlock(&dev_priv->sb_lock);
7666 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7667 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7668 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7669 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7670 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7672 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7676 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7677 struct intel_initial_plane_config *plane_config)
7679 struct drm_device *dev = crtc->base.dev;
7680 struct drm_i915_private *dev_priv = to_i915(dev);
7681 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7682 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7683 enum pipe pipe = crtc->pipe;
7684 u32 val, base, offset;
7685 int fourcc, pixel_format;
7686 unsigned int aligned_height;
7687 struct drm_framebuffer *fb;
7688 struct intel_framebuffer *intel_fb;
7690 if (!plane->get_hw_state(plane))
7693 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7695 DRM_DEBUG_KMS("failed to alloc fb\n");
7699 fb = &intel_fb->base;
7703 val = I915_READ(DSPCNTR(i9xx_plane));
7705 if (INTEL_GEN(dev_priv) >= 4) {
7706 if (val & DISPPLANE_TILED) {
7707 plane_config->tiling = I915_TILING_X;
7708 fb->modifier = I915_FORMAT_MOD_X_TILED;
7712 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7713 fourcc = i9xx_format_to_fourcc(pixel_format);
7714 fb->format = drm_format_info(fourcc);
7716 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7717 offset = I915_READ(DSPOFFSET(i9xx_plane));
7718 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7719 } else if (INTEL_GEN(dev_priv) >= 4) {
7720 if (plane_config->tiling)
7721 offset = I915_READ(DSPTILEOFF(i9xx_plane));
7723 offset = I915_READ(DSPLINOFF(i9xx_plane));
7724 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7726 base = I915_READ(DSPADDR(i9xx_plane));
7728 plane_config->base = base;
7730 val = I915_READ(PIPESRC(pipe));
7731 fb->width = ((val >> 16) & 0xfff) + 1;
7732 fb->height = ((val >> 0) & 0xfff) + 1;
7734 val = I915_READ(DSPSTRIDE(i9xx_plane));
7735 fb->pitches[0] = val & 0xffffffc0;
7737 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7739 plane_config->size = fb->pitches[0] * aligned_height;
7741 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7742 crtc->base.name, plane->base.name, fb->width, fb->height,
7743 fb->format->cpp[0] * 8, base, fb->pitches[0],
7744 plane_config->size);
7746 plane_config->fb = intel_fb;
7749 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7750 struct intel_crtc_state *pipe_config)
7752 struct drm_device *dev = crtc->base.dev;
7753 struct drm_i915_private *dev_priv = to_i915(dev);
7754 int pipe = pipe_config->cpu_transcoder;
7755 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7757 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7758 int refclk = 100000;
7760 /* In case of DSI, DPLL will not be used */
7761 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7764 mutex_lock(&dev_priv->sb_lock);
7765 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7766 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7767 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7768 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7769 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7770 mutex_unlock(&dev_priv->sb_lock);
7772 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7773 clock.m2 = (pll_dw0 & 0xff) << 22;
7774 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7775 clock.m2 |= pll_dw2 & 0x3fffff;
7776 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7777 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7778 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7780 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7783 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7784 struct intel_crtc_state *pipe_config)
7786 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7787 enum intel_display_power_domain power_domain;
7791 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7792 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7795 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7796 pipe_config->shared_dpll = NULL;
7800 tmp = I915_READ(PIPECONF(crtc->pipe));
7801 if (!(tmp & PIPECONF_ENABLE))
7804 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7805 IS_CHERRYVIEW(dev_priv)) {
7806 switch (tmp & PIPECONF_BPC_MASK) {
7808 pipe_config->pipe_bpp = 18;
7811 pipe_config->pipe_bpp = 24;
7813 case PIPECONF_10BPC:
7814 pipe_config->pipe_bpp = 30;
7821 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7822 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7823 pipe_config->limited_color_range = true;
7825 if (INTEL_GEN(dev_priv) < 4)
7826 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7828 intel_get_pipe_timings(crtc, pipe_config);
7829 intel_get_pipe_src_size(crtc, pipe_config);
7831 i9xx_get_pfit_config(crtc, pipe_config);
7833 if (INTEL_GEN(dev_priv) >= 4) {
7834 /* No way to read it out on pipes B and C */
7835 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
7836 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7838 tmp = I915_READ(DPLL_MD(crtc->pipe));
7839 pipe_config->pixel_multiplier =
7840 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7841 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
7842 pipe_config->dpll_hw_state.dpll_md = tmp;
7843 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7844 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7845 tmp = I915_READ(DPLL(crtc->pipe));
7846 pipe_config->pixel_multiplier =
7847 ((tmp & SDVO_MULTIPLIER_MASK)
7848 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7850 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7851 * port and will be fixed up in the encoder->get_config
7853 pipe_config->pixel_multiplier = 1;
7855 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
7856 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
7858 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7859 * on 830. Filter it out here so that we don't
7860 * report errors due to that.
7862 if (IS_I830(dev_priv))
7863 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
7865 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
7866 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
7868 /* Mask out read-only status bits. */
7869 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7870 DPLL_PORTC_READY_MASK |
7871 DPLL_PORTB_READY_MASK);
7874 if (IS_CHERRYVIEW(dev_priv))
7875 chv_crtc_clock_get(crtc, pipe_config);
7876 else if (IS_VALLEYVIEW(dev_priv))
7877 vlv_crtc_clock_get(crtc, pipe_config);
7879 i9xx_crtc_clock_get(crtc, pipe_config);
7882 * Normally the dotclock is filled in by the encoder .get_config()
7883 * but in case the pipe is enabled w/o any ports we need a sane
7886 pipe_config->base.adjusted_mode.crtc_clock =
7887 pipe_config->port_clock / pipe_config->pixel_multiplier;
7892 intel_display_power_put(dev_priv, power_domain);
7897 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
7899 struct intel_encoder *encoder;
7902 bool has_lvds = false;
7903 bool has_cpu_edp = false;
7904 bool has_panel = false;
7905 bool has_ck505 = false;
7906 bool can_ssc = false;
7907 bool using_ssc_source = false;
7909 /* We need to take the global config into account */
7910 for_each_intel_encoder(&dev_priv->drm, encoder) {
7911 switch (encoder->type) {
7912 case INTEL_OUTPUT_LVDS:
7916 case INTEL_OUTPUT_EDP:
7918 if (encoder->port == PORT_A)
7926 if (HAS_PCH_IBX(dev_priv)) {
7927 has_ck505 = dev_priv->vbt.display_clock_mode;
7928 can_ssc = has_ck505;
7934 /* Check if any DPLLs are using the SSC source */
7935 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
7936 u32 temp = I915_READ(PCH_DPLL(i));
7938 if (!(temp & DPLL_VCO_ENABLE))
7941 if ((temp & PLL_REF_INPUT_MASK) ==
7942 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
7943 using_ssc_source = true;
7948 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7949 has_panel, has_lvds, has_ck505, using_ssc_source);
7951 /* Ironlake: try to setup display ref clock before DPLL
7952 * enabling. This is only under driver's control after
7953 * PCH B stepping, previous chipset stepping should be
7954 * ignoring this setting.
7956 val = I915_READ(PCH_DREF_CONTROL);
7958 /* As we must carefully and slowly disable/enable each source in turn,
7959 * compute the final state we want first and check if we need to
7960 * make any changes at all.
7963 final &= ~DREF_NONSPREAD_SOURCE_MASK;
7965 final |= DREF_NONSPREAD_CK505_ENABLE;
7967 final |= DREF_NONSPREAD_SOURCE_ENABLE;
7969 final &= ~DREF_SSC_SOURCE_MASK;
7970 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7971 final &= ~DREF_SSC1_ENABLE;
7974 final |= DREF_SSC_SOURCE_ENABLE;
7976 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7977 final |= DREF_SSC1_ENABLE;
7980 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7981 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7983 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7985 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7986 } else if (using_ssc_source) {
7987 final |= DREF_SSC_SOURCE_ENABLE;
7988 final |= DREF_SSC1_ENABLE;
7994 /* Always enable nonspread source */
7995 val &= ~DREF_NONSPREAD_SOURCE_MASK;
7998 val |= DREF_NONSPREAD_CK505_ENABLE;
8000 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8003 val &= ~DREF_SSC_SOURCE_MASK;
8004 val |= DREF_SSC_SOURCE_ENABLE;
8006 /* SSC must be turned on before enabling the CPU output */
8007 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8008 DRM_DEBUG_KMS("Using SSC on panel\n");
8009 val |= DREF_SSC1_ENABLE;
8011 val &= ~DREF_SSC1_ENABLE;
8013 /* Get SSC going before enabling the outputs */
8014 I915_WRITE(PCH_DREF_CONTROL, val);
8015 POSTING_READ(PCH_DREF_CONTROL);
8018 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8020 /* Enable CPU source on CPU attached eDP */
8022 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8023 DRM_DEBUG_KMS("Using SSC on eDP\n");
8024 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8026 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8028 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8030 I915_WRITE(PCH_DREF_CONTROL, val);
8031 POSTING_READ(PCH_DREF_CONTROL);
8034 DRM_DEBUG_KMS("Disabling CPU source output\n");
8036 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8038 /* Turn off CPU output */
8039 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8041 I915_WRITE(PCH_DREF_CONTROL, val);
8042 POSTING_READ(PCH_DREF_CONTROL);
8045 if (!using_ssc_source) {
8046 DRM_DEBUG_KMS("Disabling SSC source\n");
8048 /* Turn off the SSC source */
8049 val &= ~DREF_SSC_SOURCE_MASK;
8050 val |= DREF_SSC_SOURCE_DISABLE;
8053 val &= ~DREF_SSC1_ENABLE;
8055 I915_WRITE(PCH_DREF_CONTROL, val);
8056 POSTING_READ(PCH_DREF_CONTROL);
8061 BUG_ON(val != final);
8064 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8068 tmp = I915_READ(SOUTH_CHICKEN2);
8069 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8070 I915_WRITE(SOUTH_CHICKEN2, tmp);
8072 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8073 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8074 DRM_ERROR("FDI mPHY reset assert timeout\n");
8076 tmp = I915_READ(SOUTH_CHICKEN2);
8077 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8078 I915_WRITE(SOUTH_CHICKEN2, tmp);
8080 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8081 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8082 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8085 /* WaMPhyProgramming:hsw */
8086 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8090 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8091 tmp &= ~(0xFF << 24);
8092 tmp |= (0x12 << 24);
8093 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8095 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8097 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8099 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8101 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8103 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8104 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8105 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8107 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8108 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8109 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8111 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8114 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8116 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8119 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8121 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8124 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8126 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8129 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8131 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8132 tmp &= ~(0xFF << 16);
8133 tmp |= (0x1C << 16);
8134 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8136 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8137 tmp &= ~(0xFF << 16);
8138 tmp |= (0x1C << 16);
8139 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8141 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8143 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8145 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8147 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8149 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8150 tmp &= ~(0xF << 28);
8152 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8154 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8155 tmp &= ~(0xF << 28);
8157 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8160 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8161 * Programming" based on the parameters passed:
8162 * - Sequence to enable CLKOUT_DP
8163 * - Sequence to enable CLKOUT_DP without spread
8164 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8166 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8167 bool with_spread, bool with_fdi)
8171 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8173 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8174 with_fdi, "LP PCH doesn't have FDI\n"))
8177 mutex_lock(&dev_priv->sb_lock);
8179 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8180 tmp &= ~SBI_SSCCTL_DISABLE;
8181 tmp |= SBI_SSCCTL_PATHALT;
8182 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8187 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8188 tmp &= ~SBI_SSCCTL_PATHALT;
8189 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8192 lpt_reset_fdi_mphy(dev_priv);
8193 lpt_program_fdi_mphy(dev_priv);
8197 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8198 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8199 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8200 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8202 mutex_unlock(&dev_priv->sb_lock);
8205 /* Sequence to disable CLKOUT_DP */
8206 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8210 mutex_lock(&dev_priv->sb_lock);
8212 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8213 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8214 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8215 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8217 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8218 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8219 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8220 tmp |= SBI_SSCCTL_PATHALT;
8221 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8224 tmp |= SBI_SSCCTL_DISABLE;
8225 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8228 mutex_unlock(&dev_priv->sb_lock);
8231 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8233 static const uint16_t sscdivintphase[] = {
8234 [BEND_IDX( 50)] = 0x3B23,
8235 [BEND_IDX( 45)] = 0x3B23,
8236 [BEND_IDX( 40)] = 0x3C23,
8237 [BEND_IDX( 35)] = 0x3C23,
8238 [BEND_IDX( 30)] = 0x3D23,
8239 [BEND_IDX( 25)] = 0x3D23,
8240 [BEND_IDX( 20)] = 0x3E23,
8241 [BEND_IDX( 15)] = 0x3E23,
8242 [BEND_IDX( 10)] = 0x3F23,
8243 [BEND_IDX( 5)] = 0x3F23,
8244 [BEND_IDX( 0)] = 0x0025,
8245 [BEND_IDX( -5)] = 0x0025,
8246 [BEND_IDX(-10)] = 0x0125,
8247 [BEND_IDX(-15)] = 0x0125,
8248 [BEND_IDX(-20)] = 0x0225,
8249 [BEND_IDX(-25)] = 0x0225,
8250 [BEND_IDX(-30)] = 0x0325,
8251 [BEND_IDX(-35)] = 0x0325,
8252 [BEND_IDX(-40)] = 0x0425,
8253 [BEND_IDX(-45)] = 0x0425,
8254 [BEND_IDX(-50)] = 0x0525,
8259 * steps -50 to 50 inclusive, in steps of 5
8260 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8261 * change in clock period = -(steps / 10) * 5.787 ps
8263 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8266 int idx = BEND_IDX(steps);
8268 if (WARN_ON(steps % 5 != 0))
8271 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8274 mutex_lock(&dev_priv->sb_lock);
8276 if (steps % 10 != 0)
8280 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8282 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8284 tmp |= sscdivintphase[idx];
8285 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8287 mutex_unlock(&dev_priv->sb_lock);
8292 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8294 struct intel_encoder *encoder;
8295 bool has_vga = false;
8297 for_each_intel_encoder(&dev_priv->drm, encoder) {
8298 switch (encoder->type) {
8299 case INTEL_OUTPUT_ANALOG:
8308 lpt_bend_clkout_dp(dev_priv, 0);
8309 lpt_enable_clkout_dp(dev_priv, true, true);
8311 lpt_disable_clkout_dp(dev_priv);
8316 * Initialize reference clocks when the driver loads
8318 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8320 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8321 ironlake_init_pch_refclk(dev_priv);
8322 else if (HAS_PCH_LPT(dev_priv))
8323 lpt_init_pch_refclk(dev_priv);
8326 static void ironlake_set_pipeconf(struct drm_crtc *crtc)
8328 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8329 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8330 int pipe = intel_crtc->pipe;
8335 switch (intel_crtc->config->pipe_bpp) {
8337 val |= PIPECONF_6BPC;
8340 val |= PIPECONF_8BPC;
8343 val |= PIPECONF_10BPC;
8346 val |= PIPECONF_12BPC;
8349 /* Case prevented by intel_choose_pipe_bpp_dither. */
8353 if (intel_crtc->config->dither)
8354 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8356 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8357 val |= PIPECONF_INTERLACED_ILK;
8359 val |= PIPECONF_PROGRESSIVE;
8361 if (intel_crtc->config->limited_color_range)
8362 val |= PIPECONF_COLOR_RANGE_SELECT;
8364 I915_WRITE(PIPECONF(pipe), val);
8365 POSTING_READ(PIPECONF(pipe));
8368 static void haswell_set_pipeconf(struct drm_crtc *crtc)
8370 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8371 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8372 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
8375 if (IS_HASWELL(dev_priv) && intel_crtc->config->dither)
8376 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8378 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8379 val |= PIPECONF_INTERLACED_ILK;
8381 val |= PIPECONF_PROGRESSIVE;
8383 I915_WRITE(PIPECONF(cpu_transcoder), val);
8384 POSTING_READ(PIPECONF(cpu_transcoder));
8387 static void haswell_set_pipemisc(struct drm_crtc *crtc)
8389 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8390 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8391 struct intel_crtc_state *config = intel_crtc->config;
8393 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8396 switch (intel_crtc->config->pipe_bpp) {
8398 val |= PIPEMISC_DITHER_6_BPC;
8401 val |= PIPEMISC_DITHER_8_BPC;
8404 val |= PIPEMISC_DITHER_10_BPC;
8407 val |= PIPEMISC_DITHER_12_BPC;
8410 /* Case prevented by pipe_config_set_bpp. */
8414 if (intel_crtc->config->dither)
8415 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8417 if (config->ycbcr420) {
8418 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV |
8419 PIPEMISC_YUV420_ENABLE |
8420 PIPEMISC_YUV420_MODE_FULL_BLEND;
8423 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8427 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8430 * Account for spread spectrum to avoid
8431 * oversubscribing the link. Max center spread
8432 * is 2.5%; use 5% for safety's sake.
8434 u32 bps = target_clock * bpp * 21 / 20;
8435 return DIV_ROUND_UP(bps, link_bw * 8);
8438 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8440 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8443 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8444 struct intel_crtc_state *crtc_state,
8445 struct dpll *reduced_clock)
8447 struct drm_crtc *crtc = &intel_crtc->base;
8448 struct drm_device *dev = crtc->dev;
8449 struct drm_i915_private *dev_priv = to_i915(dev);
8453 /* Enable autotuning of the PLL clock (if permissible) */
8455 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8456 if ((intel_panel_use_ssc(dev_priv) &&
8457 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8458 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8460 } else if (crtc_state->sdvo_tv_clock)
8463 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8465 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8468 if (reduced_clock) {
8469 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8471 if (reduced_clock->m < factor * reduced_clock->n)
8479 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8480 dpll |= DPLLB_MODE_LVDS;
8482 dpll |= DPLLB_MODE_DAC_SERIAL;
8484 dpll |= (crtc_state->pixel_multiplier - 1)
8485 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8487 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8488 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8489 dpll |= DPLL_SDVO_HIGH_SPEED;
8491 if (intel_crtc_has_dp_encoder(crtc_state))
8492 dpll |= DPLL_SDVO_HIGH_SPEED;
8495 * The high speed IO clock is only really required for
8496 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8497 * possible to share the DPLL between CRT and HDMI. Enabling
8498 * the clock needlessly does no real harm, except use up a
8499 * bit of power potentially.
8501 * We'll limit this to IVB with 3 pipes, since it has only two
8502 * DPLLs and so DPLL sharing is the only way to get three pipes
8503 * driving PCH ports at the same time. On SNB we could do this,
8504 * and potentially avoid enabling the second DPLL, but it's not
8505 * clear if it''s a win or loss power wise. No point in doing
8506 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8508 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8509 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8510 dpll |= DPLL_SDVO_HIGH_SPEED;
8512 /* compute bitmask from p1 value */
8513 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8515 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8517 switch (crtc_state->dpll.p2) {
8519 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8522 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8525 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8528 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8532 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8533 intel_panel_use_ssc(dev_priv))
8534 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8536 dpll |= PLL_REF_INPUT_DREFCLK;
8538 dpll |= DPLL_VCO_ENABLE;
8540 crtc_state->dpll_hw_state.dpll = dpll;
8541 crtc_state->dpll_hw_state.fp0 = fp;
8542 crtc_state->dpll_hw_state.fp1 = fp2;
8545 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8546 struct intel_crtc_state *crtc_state)
8548 struct drm_device *dev = crtc->base.dev;
8549 struct drm_i915_private *dev_priv = to_i915(dev);
8550 const struct intel_limit *limit;
8551 int refclk = 120000;
8553 memset(&crtc_state->dpll_hw_state, 0,
8554 sizeof(crtc_state->dpll_hw_state));
8556 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8557 if (!crtc_state->has_pch_encoder)
8560 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8561 if (intel_panel_use_ssc(dev_priv)) {
8562 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8563 dev_priv->vbt.lvds_ssc_freq);
8564 refclk = dev_priv->vbt.lvds_ssc_freq;
8567 if (intel_is_dual_link_lvds(dev)) {
8568 if (refclk == 100000)
8569 limit = &intel_limits_ironlake_dual_lvds_100m;
8571 limit = &intel_limits_ironlake_dual_lvds;
8573 if (refclk == 100000)
8574 limit = &intel_limits_ironlake_single_lvds_100m;
8576 limit = &intel_limits_ironlake_single_lvds;
8579 limit = &intel_limits_ironlake_dac;
8582 if (!crtc_state->clock_set &&
8583 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8584 refclk, NULL, &crtc_state->dpll)) {
8585 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8589 ironlake_compute_dpll(crtc, crtc_state, NULL);
8591 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8592 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8593 pipe_name(crtc->pipe));
8600 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8601 struct intel_link_m_n *m_n)
8603 struct drm_device *dev = crtc->base.dev;
8604 struct drm_i915_private *dev_priv = to_i915(dev);
8605 enum pipe pipe = crtc->pipe;
8607 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8608 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8609 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8611 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8612 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8613 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8616 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8617 enum transcoder transcoder,
8618 struct intel_link_m_n *m_n,
8619 struct intel_link_m_n *m2_n2)
8621 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8622 enum pipe pipe = crtc->pipe;
8624 if (INTEL_GEN(dev_priv) >= 5) {
8625 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8626 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8627 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8629 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8630 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8631 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8632 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8633 * gen < 8) and if DRRS is supported (to make sure the
8634 * registers are not unnecessarily read).
8636 if (m2_n2 && INTEL_GEN(dev_priv) < 8 &&
8637 crtc->config->has_drrs) {
8638 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8639 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8640 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8642 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8643 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8644 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8647 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8648 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8649 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8651 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8652 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8653 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8657 void intel_dp_get_m_n(struct intel_crtc *crtc,
8658 struct intel_crtc_state *pipe_config)
8660 if (pipe_config->has_pch_encoder)
8661 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8663 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8664 &pipe_config->dp_m_n,
8665 &pipe_config->dp_m2_n2);
8668 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8669 struct intel_crtc_state *pipe_config)
8671 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8672 &pipe_config->fdi_m_n, NULL);
8675 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8676 struct intel_crtc_state *pipe_config)
8678 struct drm_device *dev = crtc->base.dev;
8679 struct drm_i915_private *dev_priv = to_i915(dev);
8680 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8681 uint32_t ps_ctrl = 0;
8685 /* find scaler attached to this pipe */
8686 for (i = 0; i < crtc->num_scalers; i++) {
8687 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8688 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8690 pipe_config->pch_pfit.enabled = true;
8691 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8692 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8697 scaler_state->scaler_id = id;
8699 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8701 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8706 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8707 struct intel_initial_plane_config *plane_config)
8709 struct drm_device *dev = crtc->base.dev;
8710 struct drm_i915_private *dev_priv = to_i915(dev);
8711 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8712 enum plane_id plane_id = plane->id;
8713 enum pipe pipe = crtc->pipe;
8714 u32 val, base, offset, stride_mult, tiling, alpha;
8715 int fourcc, pixel_format;
8716 unsigned int aligned_height;
8717 struct drm_framebuffer *fb;
8718 struct intel_framebuffer *intel_fb;
8720 if (!plane->get_hw_state(plane))
8723 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8725 DRM_DEBUG_KMS("failed to alloc fb\n");
8729 fb = &intel_fb->base;
8733 val = I915_READ(PLANE_CTL(pipe, plane_id));
8735 if (INTEL_GEN(dev_priv) >= 11)
8736 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8738 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8740 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8741 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
8742 alpha &= PLANE_COLOR_ALPHA_MASK;
8744 alpha = val & PLANE_CTL_ALPHA_MASK;
8747 fourcc = skl_format_to_fourcc(pixel_format,
8748 val & PLANE_CTL_ORDER_RGBX, alpha);
8749 fb->format = drm_format_info(fourcc);
8751 tiling = val & PLANE_CTL_TILED_MASK;
8753 case PLANE_CTL_TILED_LINEAR:
8754 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8756 case PLANE_CTL_TILED_X:
8757 plane_config->tiling = I915_TILING_X;
8758 fb->modifier = I915_FORMAT_MOD_X_TILED;
8760 case PLANE_CTL_TILED_Y:
8761 if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
8762 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8764 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8766 case PLANE_CTL_TILED_YF:
8767 if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
8768 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8770 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8773 MISSING_CASE(tiling);
8777 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8778 plane_config->base = base;
8780 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
8782 val = I915_READ(PLANE_SIZE(pipe, plane_id));
8783 fb->height = ((val >> 16) & 0xfff) + 1;
8784 fb->width = ((val >> 0) & 0x1fff) + 1;
8786 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
8787 stride_mult = intel_fb_stride_alignment(fb, 0);
8788 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8790 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8792 plane_config->size = fb->pitches[0] * aligned_height;
8794 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8795 crtc->base.name, plane->base.name, fb->width, fb->height,
8796 fb->format->cpp[0] * 8, base, fb->pitches[0],
8797 plane_config->size);
8799 plane_config->fb = intel_fb;
8806 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
8807 struct intel_crtc_state *pipe_config)
8809 struct drm_device *dev = crtc->base.dev;
8810 struct drm_i915_private *dev_priv = to_i915(dev);
8813 tmp = I915_READ(PF_CTL(crtc->pipe));
8815 if (tmp & PF_ENABLE) {
8816 pipe_config->pch_pfit.enabled = true;
8817 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8818 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
8820 /* We currently do not free assignements of panel fitters on
8821 * ivb/hsw (since we don't use the higher upscaling modes which
8822 * differentiates them) so just WARN about this case for now. */
8823 if (IS_GEN7(dev_priv)) {
8824 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
8825 PF_PIPE_SEL_IVB(crtc->pipe));
8830 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
8831 struct intel_crtc_state *pipe_config)
8833 struct drm_device *dev = crtc->base.dev;
8834 struct drm_i915_private *dev_priv = to_i915(dev);
8835 enum intel_display_power_domain power_domain;
8839 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8840 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
8843 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8844 pipe_config->shared_dpll = NULL;
8847 tmp = I915_READ(PIPECONF(crtc->pipe));
8848 if (!(tmp & PIPECONF_ENABLE))
8851 switch (tmp & PIPECONF_BPC_MASK) {
8853 pipe_config->pipe_bpp = 18;
8856 pipe_config->pipe_bpp = 24;
8858 case PIPECONF_10BPC:
8859 pipe_config->pipe_bpp = 30;
8861 case PIPECONF_12BPC:
8862 pipe_config->pipe_bpp = 36;
8868 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8869 pipe_config->limited_color_range = true;
8871 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
8872 struct intel_shared_dpll *pll;
8873 enum intel_dpll_id pll_id;
8875 pipe_config->has_pch_encoder = true;
8877 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
8878 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8879 FDI_DP_PORT_WIDTH_SHIFT) + 1;
8881 ironlake_get_fdi_m_n_config(crtc, pipe_config);
8883 if (HAS_PCH_IBX(dev_priv)) {
8885 * The pipe->pch transcoder and pch transcoder->pll
8888 pll_id = (enum intel_dpll_id) crtc->pipe;
8890 tmp = I915_READ(PCH_DPLL_SEL);
8891 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
8892 pll_id = DPLL_ID_PCH_PLL_B;
8894 pll_id= DPLL_ID_PCH_PLL_A;
8897 pipe_config->shared_dpll =
8898 intel_get_shared_dpll_by_id(dev_priv, pll_id);
8899 pll = pipe_config->shared_dpll;
8901 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
8902 &pipe_config->dpll_hw_state));
8904 tmp = pipe_config->dpll_hw_state.dpll;
8905 pipe_config->pixel_multiplier =
8906 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
8907 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
8909 ironlake_pch_clock_get(crtc, pipe_config);
8911 pipe_config->pixel_multiplier = 1;
8914 intel_get_pipe_timings(crtc, pipe_config);
8915 intel_get_pipe_src_size(crtc, pipe_config);
8917 ironlake_get_pfit_config(crtc, pipe_config);
8922 intel_display_power_put(dev_priv, power_domain);
8927 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
8929 struct drm_device *dev = &dev_priv->drm;
8930 struct intel_crtc *crtc;
8932 for_each_intel_crtc(dev, crtc)
8933 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
8934 pipe_name(crtc->pipe));
8936 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)),
8937 "Display power well on\n");
8938 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
8939 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
8940 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
8941 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
8942 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
8943 "CPU PWM1 enabled\n");
8944 if (IS_HASWELL(dev_priv))
8945 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
8946 "CPU PWM2 enabled\n");
8947 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
8948 "PCH PWM1 enabled\n");
8949 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
8950 "Utility pin enabled\n");
8951 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
8954 * In theory we can still leave IRQs enabled, as long as only the HPD
8955 * interrupts remain enabled. We used to check for that, but since it's
8956 * gen-specific and since we only disable LCPLL after we fully disable
8957 * the interrupts, the check below should be enough.
8959 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
8962 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
8964 if (IS_HASWELL(dev_priv))
8965 return I915_READ(D_COMP_HSW);
8967 return I915_READ(D_COMP_BDW);
8970 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
8972 if (IS_HASWELL(dev_priv)) {
8973 mutex_lock(&dev_priv->pcu_lock);
8974 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
8976 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8977 mutex_unlock(&dev_priv->pcu_lock);
8979 I915_WRITE(D_COMP_BDW, val);
8980 POSTING_READ(D_COMP_BDW);
8985 * This function implements pieces of two sequences from BSpec:
8986 * - Sequence for display software to disable LCPLL
8987 * - Sequence for display software to allow package C8+
8988 * The steps implemented here are just the steps that actually touch the LCPLL
8989 * register. Callers should take care of disabling all the display engine
8990 * functions, doing the mode unset, fixing interrupts, etc.
8992 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
8993 bool switch_to_fclk, bool allow_power_down)
8997 assert_can_disable_lcpll(dev_priv);
8999 val = I915_READ(LCPLL_CTL);
9001 if (switch_to_fclk) {
9002 val |= LCPLL_CD_SOURCE_FCLK;
9003 I915_WRITE(LCPLL_CTL, val);
9005 if (wait_for_us(I915_READ(LCPLL_CTL) &
9006 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9007 DRM_ERROR("Switching to FCLK failed\n");
9009 val = I915_READ(LCPLL_CTL);
9012 val |= LCPLL_PLL_DISABLE;
9013 I915_WRITE(LCPLL_CTL, val);
9014 POSTING_READ(LCPLL_CTL);
9016 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
9017 DRM_ERROR("LCPLL still locked\n");
9019 val = hsw_read_dcomp(dev_priv);
9020 val |= D_COMP_COMP_DISABLE;
9021 hsw_write_dcomp(dev_priv, val);
9024 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9026 DRM_ERROR("D_COMP RCOMP still in progress\n");
9028 if (allow_power_down) {
9029 val = I915_READ(LCPLL_CTL);
9030 val |= LCPLL_POWER_DOWN_ALLOW;
9031 I915_WRITE(LCPLL_CTL, val);
9032 POSTING_READ(LCPLL_CTL);
9037 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9040 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9044 val = I915_READ(LCPLL_CTL);
9046 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9047 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9051 * Make sure we're not on PC8 state before disabling PC8, otherwise
9052 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9054 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9056 if (val & LCPLL_POWER_DOWN_ALLOW) {
9057 val &= ~LCPLL_POWER_DOWN_ALLOW;
9058 I915_WRITE(LCPLL_CTL, val);
9059 POSTING_READ(LCPLL_CTL);
9062 val = hsw_read_dcomp(dev_priv);
9063 val |= D_COMP_COMP_FORCE;
9064 val &= ~D_COMP_COMP_DISABLE;
9065 hsw_write_dcomp(dev_priv, val);
9067 val = I915_READ(LCPLL_CTL);
9068 val &= ~LCPLL_PLL_DISABLE;
9069 I915_WRITE(LCPLL_CTL, val);
9071 if (intel_wait_for_register(dev_priv,
9072 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9074 DRM_ERROR("LCPLL not locked yet\n");
9076 if (val & LCPLL_CD_SOURCE_FCLK) {
9077 val = I915_READ(LCPLL_CTL);
9078 val &= ~LCPLL_CD_SOURCE_FCLK;
9079 I915_WRITE(LCPLL_CTL, val);
9081 if (wait_for_us((I915_READ(LCPLL_CTL) &
9082 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9083 DRM_ERROR("Switching back to LCPLL failed\n");
9086 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9088 intel_update_cdclk(dev_priv);
9089 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
9093 * Package states C8 and deeper are really deep PC states that can only be
9094 * reached when all the devices on the system allow it, so even if the graphics
9095 * device allows PC8+, it doesn't mean the system will actually get to these
9096 * states. Our driver only allows PC8+ when going into runtime PM.
9098 * The requirements for PC8+ are that all the outputs are disabled, the power
9099 * well is disabled and most interrupts are disabled, and these are also
9100 * requirements for runtime PM. When these conditions are met, we manually do
9101 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9102 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9105 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9106 * the state of some registers, so when we come back from PC8+ we need to
9107 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9108 * need to take care of the registers kept by RC6. Notice that this happens even
9109 * if we don't put the device in PCI D3 state (which is what currently happens
9110 * because of the runtime PM support).
9112 * For more, read "Display Sequences for Package C8" on the hardware
9115 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9119 DRM_DEBUG_KMS("Enabling package C8+\n");
9121 if (HAS_PCH_LPT_LP(dev_priv)) {
9122 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9123 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9124 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9127 lpt_disable_clkout_dp(dev_priv);
9128 hsw_disable_lcpll(dev_priv, true, true);
9131 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9135 DRM_DEBUG_KMS("Disabling package C8+\n");
9137 hsw_restore_lcpll(dev_priv);
9138 lpt_init_pch_refclk(dev_priv);
9140 if (HAS_PCH_LPT_LP(dev_priv)) {
9141 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9142 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9143 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9147 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9148 struct intel_crtc_state *crtc_state)
9150 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
9151 struct intel_encoder *encoder =
9152 intel_ddi_get_crtc_new_encoder(crtc_state);
9154 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9155 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
9156 pipe_name(crtc->pipe));
9164 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9166 struct intel_crtc_state *pipe_config)
9168 enum intel_dpll_id id;
9171 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9172 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9174 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9177 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9180 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9182 struct intel_crtc_state *pipe_config)
9184 enum intel_dpll_id id;
9188 id = DPLL_ID_SKL_DPLL0;
9191 id = DPLL_ID_SKL_DPLL1;
9194 id = DPLL_ID_SKL_DPLL2;
9197 DRM_ERROR("Incorrect port type\n");
9201 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9204 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9206 struct intel_crtc_state *pipe_config)
9208 enum intel_dpll_id id;
9211 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9212 id = temp >> (port * 3 + 1);
9214 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9217 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9220 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9222 struct intel_crtc_state *pipe_config)
9224 enum intel_dpll_id id;
9225 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9227 switch (ddi_pll_sel) {
9228 case PORT_CLK_SEL_WRPLL1:
9229 id = DPLL_ID_WRPLL1;
9231 case PORT_CLK_SEL_WRPLL2:
9232 id = DPLL_ID_WRPLL2;
9234 case PORT_CLK_SEL_SPLL:
9237 case PORT_CLK_SEL_LCPLL_810:
9238 id = DPLL_ID_LCPLL_810;
9240 case PORT_CLK_SEL_LCPLL_1350:
9241 id = DPLL_ID_LCPLL_1350;
9243 case PORT_CLK_SEL_LCPLL_2700:
9244 id = DPLL_ID_LCPLL_2700;
9247 MISSING_CASE(ddi_pll_sel);
9249 case PORT_CLK_SEL_NONE:
9253 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9256 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9257 struct intel_crtc_state *pipe_config,
9258 u64 *power_domain_mask)
9260 struct drm_device *dev = crtc->base.dev;
9261 struct drm_i915_private *dev_priv = to_i915(dev);
9262 enum intel_display_power_domain power_domain;
9266 * The pipe->transcoder mapping is fixed with the exception of the eDP
9267 * transcoder handled below.
9269 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9272 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9273 * consistency and less surprising code; it's in always on power).
9275 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9276 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9277 enum pipe trans_edp_pipe;
9278 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9280 WARN(1, "unknown pipe linked to edp transcoder\n");
9281 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9282 case TRANS_DDI_EDP_INPUT_A_ON:
9283 trans_edp_pipe = PIPE_A;
9285 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9286 trans_edp_pipe = PIPE_B;
9288 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9289 trans_edp_pipe = PIPE_C;
9293 if (trans_edp_pipe == crtc->pipe)
9294 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9297 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9298 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9300 *power_domain_mask |= BIT_ULL(power_domain);
9302 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9304 return tmp & PIPECONF_ENABLE;
9307 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9308 struct intel_crtc_state *pipe_config,
9309 u64 *power_domain_mask)
9311 struct drm_device *dev = crtc->base.dev;
9312 struct drm_i915_private *dev_priv = to_i915(dev);
9313 enum intel_display_power_domain power_domain;
9315 enum transcoder cpu_transcoder;
9318 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9320 cpu_transcoder = TRANSCODER_DSI_A;
9322 cpu_transcoder = TRANSCODER_DSI_C;
9324 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9325 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9327 *power_domain_mask |= BIT_ULL(power_domain);
9330 * The PLL needs to be enabled with a valid divider
9331 * configuration, otherwise accessing DSI registers will hang
9332 * the machine. See BSpec North Display Engine
9333 * registers/MIPI[BXT]. We can break out here early, since we
9334 * need the same DSI PLL to be enabled for both DSI ports.
9336 if (!intel_dsi_pll_is_enabled(dev_priv))
9339 /* XXX: this works for video mode only */
9340 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9341 if (!(tmp & DPI_ENABLE))
9344 tmp = I915_READ(MIPI_CTRL(port));
9345 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9348 pipe_config->cpu_transcoder = cpu_transcoder;
9352 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9355 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9356 struct intel_crtc_state *pipe_config)
9358 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9359 struct intel_shared_dpll *pll;
9363 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9365 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9367 if (IS_CANNONLAKE(dev_priv))
9368 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9369 else if (IS_GEN9_BC(dev_priv))
9370 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9371 else if (IS_GEN9_LP(dev_priv))
9372 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9374 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9376 pll = pipe_config->shared_dpll;
9378 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9379 &pipe_config->dpll_hw_state));
9383 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9384 * DDI E. So just check whether this pipe is wired to DDI E and whether
9385 * the PCH transcoder is on.
9387 if (INTEL_GEN(dev_priv) < 9 &&
9388 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9389 pipe_config->has_pch_encoder = true;
9391 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9392 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9393 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9395 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9399 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9400 struct intel_crtc_state *pipe_config)
9402 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9403 enum intel_display_power_domain power_domain;
9404 u64 power_domain_mask;
9407 intel_crtc_init_scalers(crtc, pipe_config);
9409 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9410 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9412 power_domain_mask = BIT_ULL(power_domain);
9414 pipe_config->shared_dpll = NULL;
9416 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9418 if (IS_GEN9_LP(dev_priv) &&
9419 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9427 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9428 haswell_get_ddi_port_state(crtc, pipe_config);
9429 intel_get_pipe_timings(crtc, pipe_config);
9432 intel_get_pipe_src_size(crtc, pipe_config);
9434 pipe_config->gamma_mode =
9435 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9437 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
9438 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
9439 bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV;
9441 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
9442 bool blend_mode_420 = tmp &
9443 PIPEMISC_YUV420_MODE_FULL_BLEND;
9445 pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE;
9446 if (pipe_config->ycbcr420 != clrspace_yuv ||
9447 pipe_config->ycbcr420 != blend_mode_420)
9448 DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp);
9449 } else if (clrspace_yuv) {
9450 DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
9454 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9455 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9456 power_domain_mask |= BIT_ULL(power_domain);
9457 if (INTEL_GEN(dev_priv) >= 9)
9458 skylake_get_pfit_config(crtc, pipe_config);
9460 ironlake_get_pfit_config(crtc, pipe_config);
9463 if (hsw_crtc_supports_ips(crtc)) {
9464 if (IS_HASWELL(dev_priv))
9465 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9468 * We cannot readout IPS state on broadwell, set to
9469 * true so we can set it to a defined state on first
9472 pipe_config->ips_enabled = true;
9476 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9477 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9478 pipe_config->pixel_multiplier =
9479 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9481 pipe_config->pixel_multiplier = 1;
9485 for_each_power_domain(power_domain, power_domain_mask)
9486 intel_display_power_put(dev_priv, power_domain);
9491 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9493 struct drm_i915_private *dev_priv =
9494 to_i915(plane_state->base.plane->dev);
9495 const struct drm_framebuffer *fb = plane_state->base.fb;
9496 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9499 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9500 base = obj->phys_handle->busaddr;
9502 base = intel_plane_ggtt_offset(plane_state);
9504 base += plane_state->main.offset;
9506 /* ILK+ do this automagically */
9507 if (HAS_GMCH_DISPLAY(dev_priv) &&
9508 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9509 base += (plane_state->base.crtc_h *
9510 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9515 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9517 int x = plane_state->base.crtc_x;
9518 int y = plane_state->base.crtc_y;
9522 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9525 pos |= x << CURSOR_X_SHIFT;
9528 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9531 pos |= y << CURSOR_Y_SHIFT;
9536 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9538 const struct drm_mode_config *config =
9539 &plane_state->base.plane->dev->mode_config;
9540 int width = plane_state->base.crtc_w;
9541 int height = plane_state->base.crtc_h;
9543 return width > 0 && width <= config->cursor_width &&
9544 height > 0 && height <= config->cursor_height;
9547 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9548 struct intel_plane_state *plane_state)
9550 const struct drm_framebuffer *fb = plane_state->base.fb;
9555 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9557 DRM_PLANE_HELPER_NO_SCALING,
9558 DRM_PLANE_HELPER_NO_SCALING,
9566 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9567 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9571 src_x = plane_state->base.src_x >> 16;
9572 src_y = plane_state->base.src_y >> 16;
9574 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9575 offset = intel_compute_tile_offset(&src_x, &src_y, plane_state, 0);
9577 if (src_x != 0 || src_y != 0) {
9578 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9582 plane_state->main.offset = offset;
9587 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9588 const struct intel_plane_state *plane_state)
9590 const struct drm_framebuffer *fb = plane_state->base.fb;
9592 return CURSOR_ENABLE |
9593 CURSOR_GAMMA_ENABLE |
9594 CURSOR_FORMAT_ARGB |
9595 CURSOR_STRIDE(fb->pitches[0]);
9598 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9600 int width = plane_state->base.crtc_w;
9603 * 845g/865g are only limited by the width of their cursors,
9604 * the height is arbitrary up to the precision of the register.
9606 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
9609 static int i845_check_cursor(struct intel_plane *plane,
9610 struct intel_crtc_state *crtc_state,
9611 struct intel_plane_state *plane_state)
9613 const struct drm_framebuffer *fb = plane_state->base.fb;
9616 ret = intel_check_cursor(crtc_state, plane_state);
9620 /* if we want to turn off the cursor ignore width and height */
9624 /* Check for which cursor types we support */
9625 if (!i845_cursor_size_ok(plane_state)) {
9626 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9627 plane_state->base.crtc_w,
9628 plane_state->base.crtc_h);
9632 switch (fb->pitches[0]) {
9639 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9644 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9649 static void i845_update_cursor(struct intel_plane *plane,
9650 const struct intel_crtc_state *crtc_state,
9651 const struct intel_plane_state *plane_state)
9653 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9654 u32 cntl = 0, base = 0, pos = 0, size = 0;
9655 unsigned long irqflags;
9657 if (plane_state && plane_state->base.visible) {
9658 unsigned int width = plane_state->base.crtc_w;
9659 unsigned int height = plane_state->base.crtc_h;
9661 cntl = plane_state->ctl;
9662 size = (height << 12) | width;
9664 base = intel_cursor_base(plane_state);
9665 pos = intel_cursor_position(plane_state);
9668 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9670 /* On these chipsets we can only modify the base/size/stride
9671 * whilst the cursor is disabled.
9673 if (plane->cursor.base != base ||
9674 plane->cursor.size != size ||
9675 plane->cursor.cntl != cntl) {
9676 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
9677 I915_WRITE_FW(CURBASE(PIPE_A), base);
9678 I915_WRITE_FW(CURSIZE, size);
9679 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9680 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
9682 plane->cursor.base = base;
9683 plane->cursor.size = size;
9684 plane->cursor.cntl = cntl;
9686 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9689 POSTING_READ_FW(CURCNTR(PIPE_A));
9691 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9694 static void i845_disable_cursor(struct intel_plane *plane,
9695 struct intel_crtc *crtc)
9697 i845_update_cursor(plane, NULL, NULL);
9700 static bool i845_cursor_get_hw_state(struct intel_plane *plane)
9702 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9703 enum intel_display_power_domain power_domain;
9706 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9707 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9710 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9712 intel_display_power_put(dev_priv, power_domain);
9717 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9718 const struct intel_plane_state *plane_state)
9720 struct drm_i915_private *dev_priv =
9721 to_i915(plane_state->base.plane->dev);
9722 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9725 cntl = MCURSOR_GAMMA_ENABLE;
9727 if (HAS_DDI(dev_priv))
9728 cntl |= CURSOR_PIPE_CSC_ENABLE;
9730 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9731 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
9733 switch (plane_state->base.crtc_w) {
9735 cntl |= CURSOR_MODE_64_ARGB_AX;
9738 cntl |= CURSOR_MODE_128_ARGB_AX;
9741 cntl |= CURSOR_MODE_256_ARGB_AX;
9744 MISSING_CASE(plane_state->base.crtc_w);
9748 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
9749 cntl |= CURSOR_ROTATE_180;
9754 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
9756 struct drm_i915_private *dev_priv =
9757 to_i915(plane_state->base.plane->dev);
9758 int width = plane_state->base.crtc_w;
9759 int height = plane_state->base.crtc_h;
9761 if (!intel_cursor_size_ok(plane_state))
9764 /* Cursor width is limited to a few power-of-two sizes */
9775 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9776 * height from 8 lines up to the cursor width, when the
9777 * cursor is not rotated. Everything else requires square
9780 if (HAS_CUR_FBC(dev_priv) &&
9781 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
9782 if (height < 8 || height > width)
9785 if (height != width)
9792 static int i9xx_check_cursor(struct intel_plane *plane,
9793 struct intel_crtc_state *crtc_state,
9794 struct intel_plane_state *plane_state)
9796 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9797 const struct drm_framebuffer *fb = plane_state->base.fb;
9798 enum pipe pipe = plane->pipe;
9801 ret = intel_check_cursor(crtc_state, plane_state);
9805 /* if we want to turn off the cursor ignore width and height */
9809 /* Check for which cursor types we support */
9810 if (!i9xx_cursor_size_ok(plane_state)) {
9811 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9812 plane_state->base.crtc_w,
9813 plane_state->base.crtc_h);
9817 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
9818 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9819 fb->pitches[0], plane_state->base.crtc_w);
9824 * There's something wrong with the cursor on CHV pipe C.
9825 * If it straddles the left edge of the screen then
9826 * moving it away from the edge or disabling it often
9827 * results in a pipe underrun, and often that can lead to
9828 * dead pipe (constant underrun reported, and it scans
9829 * out just a solid color). To recover from that, the
9830 * display power well must be turned off and on again.
9831 * Refuse the put the cursor into that compromised position.
9833 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
9834 plane_state->base.visible && plane_state->base.crtc_x < 0) {
9835 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9839 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
9844 static void i9xx_update_cursor(struct intel_plane *plane,
9845 const struct intel_crtc_state *crtc_state,
9846 const struct intel_plane_state *plane_state)
9848 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9849 enum pipe pipe = plane->pipe;
9850 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
9851 unsigned long irqflags;
9853 if (plane_state && plane_state->base.visible) {
9854 cntl = plane_state->ctl;
9856 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
9857 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
9859 base = intel_cursor_base(plane_state);
9860 pos = intel_cursor_position(plane_state);
9863 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9866 * On some platforms writing CURCNTR first will also
9867 * cause CURPOS to be armed by the CURBASE write.
9868 * Without the CURCNTR write the CURPOS write would
9869 * arm itself. Thus we always start the full update
9870 * with a CURCNTR write.
9872 * On other platforms CURPOS always requires the
9873 * CURBASE write to arm the update. Additonally
9874 * a write to any of the cursor register will cancel
9875 * an already armed cursor update. Thus leaving out
9876 * the CURBASE write after CURPOS could lead to a
9877 * cursor that doesn't appear to move, or even change
9878 * shape. Thus we always write CURBASE.
9880 * CURCNTR and CUR_FBC_CTL are always
9881 * armed by the CURBASE write only.
9883 if (plane->cursor.base != base ||
9884 plane->cursor.size != fbc_ctl ||
9885 plane->cursor.cntl != cntl) {
9886 I915_WRITE_FW(CURCNTR(pipe), cntl);
9887 if (HAS_CUR_FBC(dev_priv))
9888 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
9889 I915_WRITE_FW(CURPOS(pipe), pos);
9890 I915_WRITE_FW(CURBASE(pipe), base);
9892 plane->cursor.base = base;
9893 plane->cursor.size = fbc_ctl;
9894 plane->cursor.cntl = cntl;
9896 I915_WRITE_FW(CURPOS(pipe), pos);
9897 I915_WRITE_FW(CURBASE(pipe), base);
9900 POSTING_READ_FW(CURBASE(pipe));
9902 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9905 static void i9xx_disable_cursor(struct intel_plane *plane,
9906 struct intel_crtc *crtc)
9908 i9xx_update_cursor(plane, NULL, NULL);
9911 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane)
9913 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9914 enum intel_display_power_domain power_domain;
9915 enum pipe pipe = plane->pipe;
9919 * Not 100% correct for planes that can move between pipes,
9920 * but that's only the case for gen2-3 which don't have any
9921 * display power wells.
9923 power_domain = POWER_DOMAIN_PIPE(pipe);
9924 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9927 ret = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
9929 intel_display_power_put(dev_priv, power_domain);
9934 /* VESA 640x480x72Hz mode to set on the pipe */
9935 static const struct drm_display_mode load_detect_mode = {
9936 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
9937 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
9940 struct drm_framebuffer *
9941 intel_framebuffer_create(struct drm_i915_gem_object *obj,
9942 struct drm_mode_fb_cmd2 *mode_cmd)
9944 struct intel_framebuffer *intel_fb;
9947 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9949 return ERR_PTR(-ENOMEM);
9951 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
9955 return &intel_fb->base;
9959 return ERR_PTR(ret);
9962 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
9963 struct drm_crtc *crtc)
9965 struct drm_plane *plane;
9966 struct drm_plane_state *plane_state;
9969 ret = drm_atomic_add_affected_planes(state, crtc);
9973 for_each_new_plane_in_state(state, plane, plane_state, i) {
9974 if (plane_state->crtc != crtc)
9977 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
9981 drm_atomic_set_fb_for_plane(plane_state, NULL);
9987 int intel_get_load_detect_pipe(struct drm_connector *connector,
9988 const struct drm_display_mode *mode,
9989 struct intel_load_detect_pipe *old,
9990 struct drm_modeset_acquire_ctx *ctx)
9992 struct intel_crtc *intel_crtc;
9993 struct intel_encoder *intel_encoder =
9994 intel_attached_encoder(connector);
9995 struct drm_crtc *possible_crtc;
9996 struct drm_encoder *encoder = &intel_encoder->base;
9997 struct drm_crtc *crtc = NULL;
9998 struct drm_device *dev = encoder->dev;
9999 struct drm_i915_private *dev_priv = to_i915(dev);
10000 struct drm_mode_config *config = &dev->mode_config;
10001 struct drm_atomic_state *state = NULL, *restore_state = NULL;
10002 struct drm_connector_state *connector_state;
10003 struct intel_crtc_state *crtc_state;
10006 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10007 connector->base.id, connector->name,
10008 encoder->base.id, encoder->name);
10010 old->restore_state = NULL;
10012 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
10015 * Algorithm gets a little messy:
10017 * - if the connector already has an assigned crtc, use it (but make
10018 * sure it's on first)
10020 * - try to find the first unused crtc that can drive this connector,
10021 * and use that if we find one
10024 /* See if we already have a CRTC for this connector */
10025 if (connector->state->crtc) {
10026 crtc = connector->state->crtc;
10028 ret = drm_modeset_lock(&crtc->mutex, ctx);
10032 /* Make sure the crtc and connector are running */
10036 /* Find an unused one (if possible) */
10037 for_each_crtc(dev, possible_crtc) {
10039 if (!(encoder->possible_crtcs & (1 << i)))
10042 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10046 if (possible_crtc->state->enable) {
10047 drm_modeset_unlock(&possible_crtc->mutex);
10051 crtc = possible_crtc;
10056 * If we didn't find an unused CRTC, don't use any.
10059 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10065 intel_crtc = to_intel_crtc(crtc);
10067 state = drm_atomic_state_alloc(dev);
10068 restore_state = drm_atomic_state_alloc(dev);
10069 if (!state || !restore_state) {
10074 state->acquire_ctx = ctx;
10075 restore_state->acquire_ctx = ctx;
10077 connector_state = drm_atomic_get_connector_state(state, connector);
10078 if (IS_ERR(connector_state)) {
10079 ret = PTR_ERR(connector_state);
10083 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10087 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10088 if (IS_ERR(crtc_state)) {
10089 ret = PTR_ERR(crtc_state);
10093 crtc_state->base.active = crtc_state->base.enable = true;
10096 mode = &load_detect_mode;
10098 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
10102 ret = intel_modeset_disable_planes(state, crtc);
10106 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10108 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
10110 ret = drm_atomic_add_affected_planes(restore_state, crtc);
10112 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10116 ret = drm_atomic_commit(state);
10118 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10122 old->restore_state = restore_state;
10123 drm_atomic_state_put(state);
10125 /* let the connector get through one full cycle before testing */
10126 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
10131 drm_atomic_state_put(state);
10134 if (restore_state) {
10135 drm_atomic_state_put(restore_state);
10136 restore_state = NULL;
10139 if (ret == -EDEADLK)
10145 void intel_release_load_detect_pipe(struct drm_connector *connector,
10146 struct intel_load_detect_pipe *old,
10147 struct drm_modeset_acquire_ctx *ctx)
10149 struct intel_encoder *intel_encoder =
10150 intel_attached_encoder(connector);
10151 struct drm_encoder *encoder = &intel_encoder->base;
10152 struct drm_atomic_state *state = old->restore_state;
10155 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10156 connector->base.id, connector->name,
10157 encoder->base.id, encoder->name);
10162 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10164 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10165 drm_atomic_state_put(state);
10168 static int i9xx_pll_refclk(struct drm_device *dev,
10169 const struct intel_crtc_state *pipe_config)
10171 struct drm_i915_private *dev_priv = to_i915(dev);
10172 u32 dpll = pipe_config->dpll_hw_state.dpll;
10174 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10175 return dev_priv->vbt.lvds_ssc_freq;
10176 else if (HAS_PCH_SPLIT(dev_priv))
10178 else if (!IS_GEN2(dev_priv))
10184 /* Returns the clock of the currently programmed mode of the given pipe. */
10185 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10186 struct intel_crtc_state *pipe_config)
10188 struct drm_device *dev = crtc->base.dev;
10189 struct drm_i915_private *dev_priv = to_i915(dev);
10190 int pipe = pipe_config->cpu_transcoder;
10191 u32 dpll = pipe_config->dpll_hw_state.dpll;
10195 int refclk = i9xx_pll_refclk(dev, pipe_config);
10197 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10198 fp = pipe_config->dpll_hw_state.fp0;
10200 fp = pipe_config->dpll_hw_state.fp1;
10202 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10203 if (IS_PINEVIEW(dev_priv)) {
10204 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10205 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10207 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10208 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10211 if (!IS_GEN2(dev_priv)) {
10212 if (IS_PINEVIEW(dev_priv))
10213 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10214 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10216 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10217 DPLL_FPA01_P1_POST_DIV_SHIFT);
10219 switch (dpll & DPLL_MODE_MASK) {
10220 case DPLLB_MODE_DAC_SERIAL:
10221 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10224 case DPLLB_MODE_LVDS:
10225 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10229 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10230 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10234 if (IS_PINEVIEW(dev_priv))
10235 port_clock = pnv_calc_dpll_params(refclk, &clock);
10237 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10239 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10240 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10243 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10244 DPLL_FPA01_P1_POST_DIV_SHIFT);
10246 if (lvds & LVDS_CLKB_POWER_UP)
10251 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10254 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10255 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10257 if (dpll & PLL_P2_DIVIDE_BY_4)
10263 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10267 * This value includes pixel_multiplier. We will use
10268 * port_clock to compute adjusted_mode.crtc_clock in the
10269 * encoder's get_config() function.
10271 pipe_config->port_clock = port_clock;
10274 int intel_dotclock_calculate(int link_freq,
10275 const struct intel_link_m_n *m_n)
10278 * The calculation for the data clock is:
10279 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10280 * But we want to avoid losing precison if possible, so:
10281 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10283 * and the link clock is simpler:
10284 * link_clock = (m * link_clock) / n
10290 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10293 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10294 struct intel_crtc_state *pipe_config)
10296 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10298 /* read out port_clock from the DPLL */
10299 i9xx_crtc_clock_get(crtc, pipe_config);
10302 * In case there is an active pipe without active ports,
10303 * we may need some idea for the dotclock anyway.
10304 * Calculate one based on the FDI configuration.
10306 pipe_config->base.adjusted_mode.crtc_clock =
10307 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10308 &pipe_config->fdi_m_n);
10311 /* Returns the currently programmed mode of the given encoder. */
10312 struct drm_display_mode *
10313 intel_encoder_current_mode(struct intel_encoder *encoder)
10315 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10316 struct intel_crtc_state *crtc_state;
10317 struct drm_display_mode *mode;
10318 struct intel_crtc *crtc;
10321 if (!encoder->get_hw_state(encoder, &pipe))
10324 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10326 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10330 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10336 crtc_state->base.crtc = &crtc->base;
10338 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10344 encoder->get_config(encoder, crtc_state);
10346 intel_mode_from_pipe_config(mode, crtc_state);
10353 static void intel_crtc_destroy(struct drm_crtc *crtc)
10355 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10357 drm_crtc_cleanup(crtc);
10362 * intel_wm_need_update - Check whether watermarks need updating
10363 * @plane: drm plane
10364 * @state: new plane state
10366 * Check current plane state versus the new one to determine whether
10367 * watermarks need to be recalculated.
10369 * Returns true or false.
10371 static bool intel_wm_need_update(struct drm_plane *plane,
10372 struct drm_plane_state *state)
10374 struct intel_plane_state *new = to_intel_plane_state(state);
10375 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10377 /* Update watermarks on tiling or size changes. */
10378 if (new->base.visible != cur->base.visible)
10381 if (!cur->base.fb || !new->base.fb)
10384 if (cur->base.fb->modifier != new->base.fb->modifier ||
10385 cur->base.rotation != new->base.rotation ||
10386 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10387 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10388 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10389 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10395 static bool needs_scaling(const struct intel_plane_state *state)
10397 int src_w = drm_rect_width(&state->base.src) >> 16;
10398 int src_h = drm_rect_height(&state->base.src) >> 16;
10399 int dst_w = drm_rect_width(&state->base.dst);
10400 int dst_h = drm_rect_height(&state->base.dst);
10402 return (src_w != dst_w || src_h != dst_h);
10405 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10406 struct drm_crtc_state *crtc_state,
10407 const struct intel_plane_state *old_plane_state,
10408 struct drm_plane_state *plane_state)
10410 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10411 struct drm_crtc *crtc = crtc_state->crtc;
10412 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10413 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10414 struct drm_device *dev = crtc->dev;
10415 struct drm_i915_private *dev_priv = to_i915(dev);
10416 bool mode_changed = needs_modeset(crtc_state);
10417 bool was_crtc_enabled = old_crtc_state->base.active;
10418 bool is_crtc_enabled = crtc_state->active;
10419 bool turn_off, turn_on, visible, was_visible;
10420 struct drm_framebuffer *fb = plane_state->fb;
10423 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10424 ret = skl_update_scaler_plane(
10425 to_intel_crtc_state(crtc_state),
10426 to_intel_plane_state(plane_state));
10431 was_visible = old_plane_state->base.visible;
10432 visible = plane_state->visible;
10434 if (!was_crtc_enabled && WARN_ON(was_visible))
10435 was_visible = false;
10438 * Visibility is calculated as if the crtc was on, but
10439 * after scaler setup everything depends on it being off
10440 * when the crtc isn't active.
10442 * FIXME this is wrong for watermarks. Watermarks should also
10443 * be computed as if the pipe would be active. Perhaps move
10444 * per-plane wm computation to the .check_plane() hook, and
10445 * only combine the results from all planes in the current place?
10447 if (!is_crtc_enabled) {
10448 plane_state->visible = visible = false;
10449 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10452 if (!was_visible && !visible)
10455 if (fb != old_plane_state->base.fb)
10456 pipe_config->fb_changed = true;
10458 turn_off = was_visible && (!visible || mode_changed);
10459 turn_on = visible && (!was_visible || mode_changed);
10461 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10462 intel_crtc->base.base.id, intel_crtc->base.name,
10463 plane->base.base.id, plane->base.name,
10464 fb ? fb->base.id : -1);
10466 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10467 plane->base.base.id, plane->base.name,
10468 was_visible, visible,
10469 turn_off, turn_on, mode_changed);
10472 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10473 pipe_config->update_wm_pre = true;
10475 /* must disable cxsr around plane enable/disable */
10476 if (plane->id != PLANE_CURSOR)
10477 pipe_config->disable_cxsr = true;
10478 } else if (turn_off) {
10479 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10480 pipe_config->update_wm_post = true;
10482 /* must disable cxsr around plane enable/disable */
10483 if (plane->id != PLANE_CURSOR)
10484 pipe_config->disable_cxsr = true;
10485 } else if (intel_wm_need_update(&plane->base, plane_state)) {
10486 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
10487 /* FIXME bollocks */
10488 pipe_config->update_wm_pre = true;
10489 pipe_config->update_wm_post = true;
10493 if (visible || was_visible)
10494 pipe_config->fb_bits |= plane->frontbuffer_bit;
10497 * WaCxSRDisabledForSpriteScaling:ivb
10499 * cstate->update_wm was already set above, so this flag will
10500 * take effect when we commit and program watermarks.
10502 if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) &&
10503 needs_scaling(to_intel_plane_state(plane_state)) &&
10504 !needs_scaling(old_plane_state))
10505 pipe_config->disable_lp_wm = true;
10510 static bool encoders_cloneable(const struct intel_encoder *a,
10511 const struct intel_encoder *b)
10513 /* masks could be asymmetric, so check both ways */
10514 return a == b || (a->cloneable & (1 << b->type) &&
10515 b->cloneable & (1 << a->type));
10518 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10519 struct intel_crtc *crtc,
10520 struct intel_encoder *encoder)
10522 struct intel_encoder *source_encoder;
10523 struct drm_connector *connector;
10524 struct drm_connector_state *connector_state;
10527 for_each_new_connector_in_state(state, connector, connector_state, i) {
10528 if (connector_state->crtc != &crtc->base)
10532 to_intel_encoder(connector_state->best_encoder);
10533 if (!encoders_cloneable(encoder, source_encoder))
10540 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10541 struct drm_crtc_state *crtc_state)
10543 struct drm_device *dev = crtc->dev;
10544 struct drm_i915_private *dev_priv = to_i915(dev);
10545 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10546 struct intel_crtc_state *pipe_config =
10547 to_intel_crtc_state(crtc_state);
10548 struct drm_atomic_state *state = crtc_state->state;
10550 bool mode_changed = needs_modeset(crtc_state);
10552 if (mode_changed && !crtc_state->active)
10553 pipe_config->update_wm_post = true;
10555 if (mode_changed && crtc_state->enable &&
10556 dev_priv->display.crtc_compute_clock &&
10557 !WARN_ON(pipe_config->shared_dpll)) {
10558 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10564 if (crtc_state->color_mgmt_changed) {
10565 ret = intel_color_check(crtc, crtc_state);
10570 * Changing color management on Intel hardware is
10571 * handled as part of planes update.
10573 crtc_state->planes_changed = true;
10577 if (dev_priv->display.compute_pipe_wm) {
10578 ret = dev_priv->display.compute_pipe_wm(pipe_config);
10580 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10585 if (dev_priv->display.compute_intermediate_wm &&
10586 !to_intel_atomic_state(state)->skip_intermediate_wm) {
10587 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10591 * Calculate 'intermediate' watermarks that satisfy both the
10592 * old state and the new state. We can program these
10595 ret = dev_priv->display.compute_intermediate_wm(dev,
10599 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10602 } else if (dev_priv->display.compute_intermediate_wm) {
10603 if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
10604 pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
10607 if (INTEL_GEN(dev_priv) >= 9) {
10609 ret = skl_update_scaler_crtc(pipe_config);
10612 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10615 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
10619 if (HAS_IPS(dev_priv))
10620 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10625 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
10626 .atomic_begin = intel_begin_crtc_commit,
10627 .atomic_flush = intel_finish_crtc_commit,
10628 .atomic_check = intel_crtc_atomic_check,
10631 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10633 struct intel_connector *connector;
10634 struct drm_connector_list_iter conn_iter;
10636 drm_connector_list_iter_begin(dev, &conn_iter);
10637 for_each_intel_connector_iter(connector, &conn_iter) {
10638 if (connector->base.state->crtc)
10639 drm_connector_unreference(&connector->base);
10641 if (connector->base.encoder) {
10642 connector->base.state->best_encoder =
10643 connector->base.encoder;
10644 connector->base.state->crtc =
10645 connector->base.encoder->crtc;
10647 drm_connector_reference(&connector->base);
10649 connector->base.state->best_encoder = NULL;
10650 connector->base.state->crtc = NULL;
10653 drm_connector_list_iter_end(&conn_iter);
10657 connected_sink_compute_bpp(struct intel_connector *connector,
10658 struct intel_crtc_state *pipe_config)
10660 const struct drm_display_info *info = &connector->base.display_info;
10661 int bpp = pipe_config->pipe_bpp;
10663 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10664 connector->base.base.id,
10665 connector->base.name);
10667 /* Don't use an invalid EDID bpc value */
10668 if (info->bpc != 0 && info->bpc * 3 < bpp) {
10669 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10670 bpp, info->bpc * 3);
10671 pipe_config->pipe_bpp = info->bpc * 3;
10674 /* Clamp bpp to 8 on screens without EDID 1.4 */
10675 if (info->bpc == 0 && bpp > 24) {
10676 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10678 pipe_config->pipe_bpp = 24;
10683 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
10684 struct intel_crtc_state *pipe_config)
10686 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10687 struct drm_atomic_state *state;
10688 struct drm_connector *connector;
10689 struct drm_connector_state *connector_state;
10692 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10693 IS_CHERRYVIEW(dev_priv)))
10695 else if (INTEL_GEN(dev_priv) >= 5)
10701 pipe_config->pipe_bpp = bpp;
10703 state = pipe_config->base.state;
10705 /* Clamp display bpp to EDID value */
10706 for_each_new_connector_in_state(state, connector, connector_state, i) {
10707 if (connector_state->crtc != &crtc->base)
10710 connected_sink_compute_bpp(to_intel_connector(connector),
10717 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
10719 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10720 "type: 0x%x flags: 0x%x\n",
10722 mode->crtc_hdisplay, mode->crtc_hsync_start,
10723 mode->crtc_hsync_end, mode->crtc_htotal,
10724 mode->crtc_vdisplay, mode->crtc_vsync_start,
10725 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
10729 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
10730 unsigned int lane_count, struct intel_link_m_n *m_n)
10732 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10734 m_n->gmch_m, m_n->gmch_n,
10735 m_n->link_m, m_n->link_n, m_n->tu);
10738 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
10740 static const char * const output_type_str[] = {
10741 OUTPUT_TYPE(UNUSED),
10742 OUTPUT_TYPE(ANALOG),
10746 OUTPUT_TYPE(TVOUT),
10752 OUTPUT_TYPE(DP_MST),
10757 static void snprintf_output_types(char *buf, size_t len,
10758 unsigned int output_types)
10765 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
10768 if ((output_types & BIT(i)) == 0)
10771 r = snprintf(str, len, "%s%s",
10772 str != buf ? "," : "", output_type_str[i]);
10778 output_types &= ~BIT(i);
10781 WARN_ON_ONCE(output_types != 0);
10784 static void intel_dump_pipe_config(struct intel_crtc *crtc,
10785 struct intel_crtc_state *pipe_config,
10786 const char *context)
10788 struct drm_device *dev = crtc->base.dev;
10789 struct drm_i915_private *dev_priv = to_i915(dev);
10790 struct drm_plane *plane;
10791 struct intel_plane *intel_plane;
10792 struct intel_plane_state *state;
10793 struct drm_framebuffer *fb;
10796 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10797 crtc->base.base.id, crtc->base.name, context);
10799 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
10800 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
10801 buf, pipe_config->output_types);
10803 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10804 transcoder_name(pipe_config->cpu_transcoder),
10805 pipe_config->pipe_bpp, pipe_config->dither);
10807 if (pipe_config->has_pch_encoder)
10808 intel_dump_m_n_config(pipe_config, "fdi",
10809 pipe_config->fdi_lanes,
10810 &pipe_config->fdi_m_n);
10812 if (pipe_config->ycbcr420)
10813 DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
10815 if (intel_crtc_has_dp_encoder(pipe_config)) {
10816 intel_dump_m_n_config(pipe_config, "dp m_n",
10817 pipe_config->lane_count, &pipe_config->dp_m_n);
10818 if (pipe_config->has_drrs)
10819 intel_dump_m_n_config(pipe_config, "dp m2_n2",
10820 pipe_config->lane_count,
10821 &pipe_config->dp_m2_n2);
10824 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10825 pipe_config->has_audio, pipe_config->has_infoframe);
10827 DRM_DEBUG_KMS("requested mode:\n");
10828 drm_mode_debug_printmodeline(&pipe_config->base.mode);
10829 DRM_DEBUG_KMS("adjusted mode:\n");
10830 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
10831 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
10832 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10833 pipe_config->port_clock,
10834 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
10835 pipe_config->pixel_rate);
10837 if (INTEL_GEN(dev_priv) >= 9)
10838 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10840 pipe_config->scaler_state.scaler_users,
10841 pipe_config->scaler_state.scaler_id);
10843 if (HAS_GMCH_DISPLAY(dev_priv))
10844 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10845 pipe_config->gmch_pfit.control,
10846 pipe_config->gmch_pfit.pgm_ratios,
10847 pipe_config->gmch_pfit.lvds_border_bits);
10849 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10850 pipe_config->pch_pfit.pos,
10851 pipe_config->pch_pfit.size,
10852 enableddisabled(pipe_config->pch_pfit.enabled));
10854 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10855 pipe_config->ips_enabled, pipe_config->double_wide);
10857 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
10859 DRM_DEBUG_KMS("planes on this crtc\n");
10860 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
10861 struct drm_format_name_buf format_name;
10862 intel_plane = to_intel_plane(plane);
10863 if (intel_plane->pipe != crtc->pipe)
10866 state = to_intel_plane_state(plane->state);
10867 fb = state->base.fb;
10869 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10870 plane->base.id, plane->name, state->scaler_id);
10874 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10875 plane->base.id, plane->name,
10876 fb->base.id, fb->width, fb->height,
10877 drm_get_format_name(fb->format->format, &format_name));
10878 if (INTEL_GEN(dev_priv) >= 9)
10879 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10881 state->base.src.x1 >> 16,
10882 state->base.src.y1 >> 16,
10883 drm_rect_width(&state->base.src) >> 16,
10884 drm_rect_height(&state->base.src) >> 16,
10885 state->base.dst.x1, state->base.dst.y1,
10886 drm_rect_width(&state->base.dst),
10887 drm_rect_height(&state->base.dst));
10891 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
10893 struct drm_device *dev = state->dev;
10894 struct drm_connector *connector;
10895 struct drm_connector_list_iter conn_iter;
10896 unsigned int used_ports = 0;
10897 unsigned int used_mst_ports = 0;
10901 * Walk the connector list instead of the encoder
10902 * list to detect the problem on ddi platforms
10903 * where there's just one encoder per digital port.
10905 drm_connector_list_iter_begin(dev, &conn_iter);
10906 drm_for_each_connector_iter(connector, &conn_iter) {
10907 struct drm_connector_state *connector_state;
10908 struct intel_encoder *encoder;
10910 connector_state = drm_atomic_get_new_connector_state(state, connector);
10911 if (!connector_state)
10912 connector_state = connector->state;
10914 if (!connector_state->best_encoder)
10917 encoder = to_intel_encoder(connector_state->best_encoder);
10919 WARN_ON(!connector_state->crtc);
10921 switch (encoder->type) {
10922 unsigned int port_mask;
10923 case INTEL_OUTPUT_DDI:
10924 if (WARN_ON(!HAS_DDI(to_i915(dev))))
10926 case INTEL_OUTPUT_DP:
10927 case INTEL_OUTPUT_HDMI:
10928 case INTEL_OUTPUT_EDP:
10929 port_mask = 1 << encoder->port;
10931 /* the same port mustn't appear more than once */
10932 if (used_ports & port_mask)
10935 used_ports |= port_mask;
10937 case INTEL_OUTPUT_DP_MST:
10939 1 << encoder->port;
10945 drm_connector_list_iter_end(&conn_iter);
10947 /* can't mix MST and SST/HDMI on the same port */
10948 if (used_ports & used_mst_ports)
10955 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
10957 struct drm_i915_private *dev_priv =
10958 to_i915(crtc_state->base.crtc->dev);
10959 struct intel_crtc_scaler_state scaler_state;
10960 struct intel_dpll_hw_state dpll_hw_state;
10961 struct intel_shared_dpll *shared_dpll;
10962 struct intel_crtc_wm_state wm_state;
10963 bool force_thru, ips_force_disable;
10965 /* FIXME: before the switch to atomic started, a new pipe_config was
10966 * kzalloc'd. Code that depends on any field being zero should be
10967 * fixed, so that the crtc_state can be safely duplicated. For now,
10968 * only fields that are know to not cause problems are preserved. */
10970 scaler_state = crtc_state->scaler_state;
10971 shared_dpll = crtc_state->shared_dpll;
10972 dpll_hw_state = crtc_state->dpll_hw_state;
10973 force_thru = crtc_state->pch_pfit.force_thru;
10974 ips_force_disable = crtc_state->ips_force_disable;
10975 if (IS_G4X(dev_priv) ||
10976 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10977 wm_state = crtc_state->wm;
10979 /* Keep base drm_crtc_state intact, only clear our extended struct */
10980 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
10981 memset(&crtc_state->base + 1, 0,
10982 sizeof(*crtc_state) - sizeof(crtc_state->base));
10984 crtc_state->scaler_state = scaler_state;
10985 crtc_state->shared_dpll = shared_dpll;
10986 crtc_state->dpll_hw_state = dpll_hw_state;
10987 crtc_state->pch_pfit.force_thru = force_thru;
10988 crtc_state->ips_force_disable = ips_force_disable;
10989 if (IS_G4X(dev_priv) ||
10990 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10991 crtc_state->wm = wm_state;
10995 intel_modeset_pipe_config(struct drm_crtc *crtc,
10996 struct intel_crtc_state *pipe_config)
10998 struct drm_atomic_state *state = pipe_config->base.state;
10999 struct intel_encoder *encoder;
11000 struct drm_connector *connector;
11001 struct drm_connector_state *connector_state;
11002 int base_bpp, ret = -EINVAL;
11006 clear_intel_crtc_state(pipe_config);
11008 pipe_config->cpu_transcoder =
11009 (enum transcoder) to_intel_crtc(crtc)->pipe;
11012 * Sanitize sync polarity flags based on requested ones. If neither
11013 * positive or negative polarity is requested, treat this as meaning
11014 * negative polarity.
11016 if (!(pipe_config->base.adjusted_mode.flags &
11017 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
11018 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
11020 if (!(pipe_config->base.adjusted_mode.flags &
11021 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
11022 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
11024 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11030 * Determine the real pipe dimensions. Note that stereo modes can
11031 * increase the actual pipe size due to the frame doubling and
11032 * insertion of additional space for blanks between the frame. This
11033 * is stored in the crtc timings. We use the requested mode to do this
11034 * computation to clearly distinguish it from the adjusted mode, which
11035 * can be changed by the connectors in the below retry loop.
11037 drm_mode_get_hv_timing(&pipe_config->base.mode,
11038 &pipe_config->pipe_src_w,
11039 &pipe_config->pipe_src_h);
11041 for_each_new_connector_in_state(state, connector, connector_state, i) {
11042 if (connector_state->crtc != crtc)
11045 encoder = to_intel_encoder(connector_state->best_encoder);
11047 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11048 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11053 * Determine output_types before calling the .compute_config()
11054 * hooks so that the hooks can use this information safely.
11056 if (encoder->compute_output_type)
11057 pipe_config->output_types |=
11058 BIT(encoder->compute_output_type(encoder, pipe_config,
11061 pipe_config->output_types |= BIT(encoder->type);
11065 /* Ensure the port clock defaults are reset when retrying. */
11066 pipe_config->port_clock = 0;
11067 pipe_config->pixel_multiplier = 1;
11069 /* Fill in default crtc timings, allow encoders to overwrite them. */
11070 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11071 CRTC_STEREO_DOUBLE);
11073 /* Pass our mode to the connectors and the CRTC to give them a chance to
11074 * adjust it according to limitations or connector properties, and also
11075 * a chance to reject the mode entirely.
11077 for_each_new_connector_in_state(state, connector, connector_state, i) {
11078 if (connector_state->crtc != crtc)
11081 encoder = to_intel_encoder(connector_state->best_encoder);
11083 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
11084 DRM_DEBUG_KMS("Encoder config failure\n");
11089 /* Set default port clock if not overwritten by the encoder. Needs to be
11090 * done afterwards in case the encoder adjusts the mode. */
11091 if (!pipe_config->port_clock)
11092 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
11093 * pipe_config->pixel_multiplier;
11095 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
11097 DRM_DEBUG_KMS("CRTC fixup failed\n");
11101 if (ret == RETRY) {
11102 if (WARN(!retry, "loop in pipe configuration computation\n")) {
11107 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11109 goto encoder_retry;
11112 /* Dithering seems to not pass-through bits correctly when it should, so
11113 * only enable it on 6bpc panels and when its not a compliance
11114 * test requesting 6bpc video pattern.
11116 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11117 !pipe_config->dither_force_disable;
11118 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11119 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
11125 static bool intel_fuzzy_clock_check(int clock1, int clock2)
11129 if (clock1 == clock2)
11132 if (!clock1 || !clock2)
11135 diff = abs(clock1 - clock2);
11137 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11144 intel_compare_m_n(unsigned int m, unsigned int n,
11145 unsigned int m2, unsigned int n2,
11148 if (m == m2 && n == n2)
11151 if (exact || !m || !n || !m2 || !n2)
11154 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11161 } else if (n < n2) {
11171 return intel_fuzzy_clock_check(m, m2);
11175 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11176 struct intel_link_m_n *m2_n2,
11179 if (m_n->tu == m2_n2->tu &&
11180 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11181 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11182 intel_compare_m_n(m_n->link_m, m_n->link_n,
11183 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11193 static void __printf(3, 4)
11194 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11196 struct va_format vaf;
11199 va_start(args, format);
11204 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11206 drm_err("mismatch in %s %pV", name, &vaf);
11212 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11213 struct intel_crtc_state *current_config,
11214 struct intel_crtc_state *pipe_config,
11218 bool fixup_inherited = adjust &&
11219 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11220 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11222 #define PIPE_CONF_CHECK_X(name) do { \
11223 if (current_config->name != pipe_config->name) { \
11224 pipe_config_err(adjust, __stringify(name), \
11225 "(expected 0x%08x, found 0x%08x)\n", \
11226 current_config->name, \
11227 pipe_config->name); \
11232 #define PIPE_CONF_CHECK_I(name) do { \
11233 if (current_config->name != pipe_config->name) { \
11234 pipe_config_err(adjust, __stringify(name), \
11235 "(expected %i, found %i)\n", \
11236 current_config->name, \
11237 pipe_config->name); \
11242 #define PIPE_CONF_CHECK_BOOL(name) do { \
11243 if (current_config->name != pipe_config->name) { \
11244 pipe_config_err(adjust, __stringify(name), \
11245 "(expected %s, found %s)\n", \
11246 yesno(current_config->name), \
11247 yesno(pipe_config->name)); \
11253 * Checks state where we only read out the enabling, but not the entire
11254 * state itself (like full infoframes or ELD for audio). These states
11255 * require a full modeset on bootup to fix up.
11257 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11258 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11259 PIPE_CONF_CHECK_BOOL(name); \
11261 pipe_config_err(adjust, __stringify(name), \
11262 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11263 yesno(current_config->name), \
11264 yesno(pipe_config->name)); \
11269 #define PIPE_CONF_CHECK_P(name) do { \
11270 if (current_config->name != pipe_config->name) { \
11271 pipe_config_err(adjust, __stringify(name), \
11272 "(expected %p, found %p)\n", \
11273 current_config->name, \
11274 pipe_config->name); \
11279 #define PIPE_CONF_CHECK_M_N(name) do { \
11280 if (!intel_compare_link_m_n(¤t_config->name, \
11281 &pipe_config->name,\
11283 pipe_config_err(adjust, __stringify(name), \
11284 "(expected tu %i gmch %i/%i link %i/%i, " \
11285 "found tu %i, gmch %i/%i link %i/%i)\n", \
11286 current_config->name.tu, \
11287 current_config->name.gmch_m, \
11288 current_config->name.gmch_n, \
11289 current_config->name.link_m, \
11290 current_config->name.link_n, \
11291 pipe_config->name.tu, \
11292 pipe_config->name.gmch_m, \
11293 pipe_config->name.gmch_n, \
11294 pipe_config->name.link_m, \
11295 pipe_config->name.link_n); \
11300 /* This is required for BDW+ where there is only one set of registers for
11301 * switching between high and low RR.
11302 * This macro can be used whenever a comparison has to be made between one
11303 * hw state and multiple sw state variables.
11305 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
11306 if (!intel_compare_link_m_n(¤t_config->name, \
11307 &pipe_config->name, adjust) && \
11308 !intel_compare_link_m_n(¤t_config->alt_name, \
11309 &pipe_config->name, adjust)) { \
11310 pipe_config_err(adjust, __stringify(name), \
11311 "(expected tu %i gmch %i/%i link %i/%i, " \
11312 "or tu %i gmch %i/%i link %i/%i, " \
11313 "found tu %i, gmch %i/%i link %i/%i)\n", \
11314 current_config->name.tu, \
11315 current_config->name.gmch_m, \
11316 current_config->name.gmch_n, \
11317 current_config->name.link_m, \
11318 current_config->name.link_n, \
11319 current_config->alt_name.tu, \
11320 current_config->alt_name.gmch_m, \
11321 current_config->alt_name.gmch_n, \
11322 current_config->alt_name.link_m, \
11323 current_config->alt_name.link_n, \
11324 pipe_config->name.tu, \
11325 pipe_config->name.gmch_m, \
11326 pipe_config->name.gmch_n, \
11327 pipe_config->name.link_m, \
11328 pipe_config->name.link_n); \
11333 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
11334 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11335 pipe_config_err(adjust, __stringify(name), \
11336 "(%x) (expected %i, found %i)\n", \
11338 current_config->name & (mask), \
11339 pipe_config->name & (mask)); \
11344 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
11345 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11346 pipe_config_err(adjust, __stringify(name), \
11347 "(expected %i, found %i)\n", \
11348 current_config->name, \
11349 pipe_config->name); \
11354 #define PIPE_CONF_QUIRK(quirk) \
11355 ((current_config->quirks | pipe_config->quirks) & (quirk))
11357 PIPE_CONF_CHECK_I(cpu_transcoder);
11359 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11360 PIPE_CONF_CHECK_I(fdi_lanes);
11361 PIPE_CONF_CHECK_M_N(fdi_m_n);
11363 PIPE_CONF_CHECK_I(lane_count);
11364 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11366 if (INTEL_GEN(dev_priv) < 8) {
11367 PIPE_CONF_CHECK_M_N(dp_m_n);
11369 if (current_config->has_drrs)
11370 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11372 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11374 PIPE_CONF_CHECK_X(output_types);
11376 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11377 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11378 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11379 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11380 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11381 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
11383 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11384 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11385 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11386 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11387 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11388 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
11390 PIPE_CONF_CHECK_I(pixel_multiplier);
11391 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11392 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11393 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11394 PIPE_CONF_CHECK_BOOL(limited_color_range);
11396 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11397 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11398 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
11399 PIPE_CONF_CHECK_BOOL(ycbcr420);
11401 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11403 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11404 DRM_MODE_FLAG_INTERLACE);
11406 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11407 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11408 DRM_MODE_FLAG_PHSYNC);
11409 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11410 DRM_MODE_FLAG_NHSYNC);
11411 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11412 DRM_MODE_FLAG_PVSYNC);
11413 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11414 DRM_MODE_FLAG_NVSYNC);
11417 PIPE_CONF_CHECK_X(gmch_pfit.control);
11418 /* pfit ratios are autocomputed by the hw on gen4+ */
11419 if (INTEL_GEN(dev_priv) < 4)
11420 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11421 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11424 PIPE_CONF_CHECK_I(pipe_src_w);
11425 PIPE_CONF_CHECK_I(pipe_src_h);
11427 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11428 if (current_config->pch_pfit.enabled) {
11429 PIPE_CONF_CHECK_X(pch_pfit.pos);
11430 PIPE_CONF_CHECK_X(pch_pfit.size);
11433 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11434 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11437 PIPE_CONF_CHECK_BOOL(double_wide);
11439 PIPE_CONF_CHECK_P(shared_dpll);
11440 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11441 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11442 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11443 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11444 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11445 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11446 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11447 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11448 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11449 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11450 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11451 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11452 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11453 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11454 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11455 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11456 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11457 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11458 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11459 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11460 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11461 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11462 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11463 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11464 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11465 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11466 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11467 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11468 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11469 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11470 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
11472 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11473 PIPE_CONF_CHECK_X(dsi_pll.div);
11475 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11476 PIPE_CONF_CHECK_I(pipe_bpp);
11478 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
11479 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11481 PIPE_CONF_CHECK_I(min_voltage_level);
11483 #undef PIPE_CONF_CHECK_X
11484 #undef PIPE_CONF_CHECK_I
11485 #undef PIPE_CONF_CHECK_BOOL
11486 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11487 #undef PIPE_CONF_CHECK_P
11488 #undef PIPE_CONF_CHECK_FLAGS
11489 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11490 #undef PIPE_CONF_QUIRK
11495 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11496 const struct intel_crtc_state *pipe_config)
11498 if (pipe_config->has_pch_encoder) {
11499 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11500 &pipe_config->fdi_m_n);
11501 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11504 * FDI already provided one idea for the dotclock.
11505 * Yell if the encoder disagrees.
11507 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11508 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11509 fdi_dotclock, dotclock);
11513 static void verify_wm_state(struct drm_crtc *crtc,
11514 struct drm_crtc_state *new_state)
11516 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11517 struct skl_ddb_allocation hw_ddb, *sw_ddb;
11518 struct skl_pipe_wm hw_wm, *sw_wm;
11519 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11520 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11521 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11522 const enum pipe pipe = intel_crtc->pipe;
11523 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11525 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
11528 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
11529 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
11531 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11532 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11534 if (INTEL_GEN(dev_priv) >= 11)
11535 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11536 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11537 sw_ddb->enabled_slices,
11538 hw_ddb.enabled_slices);
11540 for_each_universal_plane(dev_priv, pipe, plane) {
11541 hw_plane_wm = &hw_wm.planes[plane];
11542 sw_plane_wm = &sw_wm->planes[plane];
11545 for (level = 0; level <= max_level; level++) {
11546 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11547 &sw_plane_wm->wm[level]))
11550 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",
11551 pipe_name(pipe), plane + 1, level,
11552 sw_plane_wm->wm[level].plane_en,
11553 sw_plane_wm->wm[level].plane_res_b,
11554 sw_plane_wm->wm[level].plane_res_l,
11555 hw_plane_wm->wm[level].plane_en,
11556 hw_plane_wm->wm[level].plane_res_b,
11557 hw_plane_wm->wm[level].plane_res_l);
11560 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11561 &sw_plane_wm->trans_wm)) {
11562 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",
11563 pipe_name(pipe), plane + 1,
11564 sw_plane_wm->trans_wm.plane_en,
11565 sw_plane_wm->trans_wm.plane_res_b,
11566 sw_plane_wm->trans_wm.plane_res_l,
11567 hw_plane_wm->trans_wm.plane_en,
11568 hw_plane_wm->trans_wm.plane_res_b,
11569 hw_plane_wm->trans_wm.plane_res_l);
11573 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11574 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11576 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11577 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11578 pipe_name(pipe), plane + 1,
11579 sw_ddb_entry->start, sw_ddb_entry->end,
11580 hw_ddb_entry->start, hw_ddb_entry->end);
11586 * If the cursor plane isn't active, we may not have updated it's ddb
11587 * allocation. In that case since the ddb allocation will be updated
11588 * once the plane becomes visible, we can skip this check
11591 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11592 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
11595 for (level = 0; level <= max_level; level++) {
11596 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11597 &sw_plane_wm->wm[level]))
11600 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",
11601 pipe_name(pipe), level,
11602 sw_plane_wm->wm[level].plane_en,
11603 sw_plane_wm->wm[level].plane_res_b,
11604 sw_plane_wm->wm[level].plane_res_l,
11605 hw_plane_wm->wm[level].plane_en,
11606 hw_plane_wm->wm[level].plane_res_b,
11607 hw_plane_wm->wm[level].plane_res_l);
11610 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11611 &sw_plane_wm->trans_wm)) {
11612 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11614 sw_plane_wm->trans_wm.plane_en,
11615 sw_plane_wm->trans_wm.plane_res_b,
11616 sw_plane_wm->trans_wm.plane_res_l,
11617 hw_plane_wm->trans_wm.plane_en,
11618 hw_plane_wm->trans_wm.plane_res_b,
11619 hw_plane_wm->trans_wm.plane_res_l);
11623 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11624 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11626 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11627 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11629 sw_ddb_entry->start, sw_ddb_entry->end,
11630 hw_ddb_entry->start, hw_ddb_entry->end);
11636 verify_connector_state(struct drm_device *dev,
11637 struct drm_atomic_state *state,
11638 struct drm_crtc *crtc)
11640 struct drm_connector *connector;
11641 struct drm_connector_state *new_conn_state;
11644 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
11645 struct drm_encoder *encoder = connector->encoder;
11646 struct drm_crtc_state *crtc_state = NULL;
11648 if (new_conn_state->crtc != crtc)
11652 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11654 intel_connector_verify_state(crtc_state, new_conn_state);
11656 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
11657 "connector's atomic encoder doesn't match legacy encoder\n");
11662 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
11664 struct intel_encoder *encoder;
11665 struct drm_connector *connector;
11666 struct drm_connector_state *old_conn_state, *new_conn_state;
11669 for_each_intel_encoder(dev, encoder) {
11670 bool enabled = false, found = false;
11673 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11674 encoder->base.base.id,
11675 encoder->base.name);
11677 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
11678 new_conn_state, i) {
11679 if (old_conn_state->best_encoder == &encoder->base)
11682 if (new_conn_state->best_encoder != &encoder->base)
11684 found = enabled = true;
11686 I915_STATE_WARN(new_conn_state->crtc !=
11687 encoder->base.crtc,
11688 "connector's crtc doesn't match encoder crtc\n");
11694 I915_STATE_WARN(!!encoder->base.crtc != enabled,
11695 "encoder's enabled state mismatch "
11696 "(expected %i, found %i)\n",
11697 !!encoder->base.crtc, enabled);
11699 if (!encoder->base.crtc) {
11702 active = encoder->get_hw_state(encoder, &pipe);
11703 I915_STATE_WARN(active,
11704 "encoder detached but still enabled on pipe %c.\n",
11711 verify_crtc_state(struct drm_crtc *crtc,
11712 struct drm_crtc_state *old_crtc_state,
11713 struct drm_crtc_state *new_crtc_state)
11715 struct drm_device *dev = crtc->dev;
11716 struct drm_i915_private *dev_priv = to_i915(dev);
11717 struct intel_encoder *encoder;
11718 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11719 struct intel_crtc_state *pipe_config, *sw_config;
11720 struct drm_atomic_state *old_state;
11723 old_state = old_crtc_state->state;
11724 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
11725 pipe_config = to_intel_crtc_state(old_crtc_state);
11726 memset(pipe_config, 0, sizeof(*pipe_config));
11727 pipe_config->base.crtc = crtc;
11728 pipe_config->base.state = old_state;
11730 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
11732 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
11734 /* we keep both pipes enabled on 830 */
11735 if (IS_I830(dev_priv))
11736 active = new_crtc_state->active;
11738 I915_STATE_WARN(new_crtc_state->active != active,
11739 "crtc active state doesn't match with hw state "
11740 "(expected %i, found %i)\n", new_crtc_state->active, active);
11742 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
11743 "transitional active state does not match atomic hw state "
11744 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
11746 for_each_encoder_on_crtc(dev, crtc, encoder) {
11749 active = encoder->get_hw_state(encoder, &pipe);
11750 I915_STATE_WARN(active != new_crtc_state->active,
11751 "[ENCODER:%i] active %i with crtc active %i\n",
11752 encoder->base.base.id, active, new_crtc_state->active);
11754 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
11755 "Encoder connected to wrong pipe %c\n",
11759 encoder->get_config(encoder, pipe_config);
11762 intel_crtc_compute_pixel_rate(pipe_config);
11764 if (!new_crtc_state->active)
11767 intel_pipe_config_sanity_check(dev_priv, pipe_config);
11769 sw_config = to_intel_crtc_state(new_crtc_state);
11770 if (!intel_pipe_config_compare(dev_priv, sw_config,
11771 pipe_config, false)) {
11772 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11773 intel_dump_pipe_config(intel_crtc, pipe_config,
11775 intel_dump_pipe_config(intel_crtc, sw_config,
11781 intel_verify_planes(struct intel_atomic_state *state)
11783 struct intel_plane *plane;
11784 const struct intel_plane_state *plane_state;
11787 for_each_new_intel_plane_in_state(state, plane,
11789 assert_plane(plane, plane_state->base.visible);
11793 verify_single_dpll_state(struct drm_i915_private *dev_priv,
11794 struct intel_shared_dpll *pll,
11795 struct drm_crtc *crtc,
11796 struct drm_crtc_state *new_state)
11798 struct intel_dpll_hw_state dpll_hw_state;
11799 unsigned crtc_mask;
11802 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
11804 DRM_DEBUG_KMS("%s\n", pll->info->name);
11806 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
11808 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
11809 I915_STATE_WARN(!pll->on && pll->active_mask,
11810 "pll in active use but not on in sw tracking\n");
11811 I915_STATE_WARN(pll->on && !pll->active_mask,
11812 "pll is on but not used by any active crtc\n");
11813 I915_STATE_WARN(pll->on != active,
11814 "pll on state mismatch (expected %i, found %i)\n",
11819 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
11820 "more active pll users than references: %x vs %x\n",
11821 pll->active_mask, pll->state.crtc_mask);
11826 crtc_mask = 1 << drm_crtc_index(crtc);
11828 if (new_state->active)
11829 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
11830 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11831 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11833 I915_STATE_WARN(pll->active_mask & crtc_mask,
11834 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11835 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11837 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
11838 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11839 crtc_mask, pll->state.crtc_mask);
11841 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
11843 sizeof(dpll_hw_state)),
11844 "pll hw state mismatch\n");
11848 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
11849 struct drm_crtc_state *old_crtc_state,
11850 struct drm_crtc_state *new_crtc_state)
11852 struct drm_i915_private *dev_priv = to_i915(dev);
11853 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
11854 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
11856 if (new_state->shared_dpll)
11857 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
11859 if (old_state->shared_dpll &&
11860 old_state->shared_dpll != new_state->shared_dpll) {
11861 unsigned crtc_mask = 1 << drm_crtc_index(crtc);
11862 struct intel_shared_dpll *pll = old_state->shared_dpll;
11864 I915_STATE_WARN(pll->active_mask & crtc_mask,
11865 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11866 pipe_name(drm_crtc_index(crtc)));
11867 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
11868 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11869 pipe_name(drm_crtc_index(crtc)));
11874 intel_modeset_verify_crtc(struct drm_crtc *crtc,
11875 struct drm_atomic_state *state,
11876 struct drm_crtc_state *old_state,
11877 struct drm_crtc_state *new_state)
11879 if (!needs_modeset(new_state) &&
11880 !to_intel_crtc_state(new_state)->update_pipe)
11883 verify_wm_state(crtc, new_state);
11884 verify_connector_state(crtc->dev, state, crtc);
11885 verify_crtc_state(crtc, old_state, new_state);
11886 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
11890 verify_disabled_dpll_state(struct drm_device *dev)
11892 struct drm_i915_private *dev_priv = to_i915(dev);
11895 for (i = 0; i < dev_priv->num_shared_dpll; i++)
11896 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
11900 intel_modeset_verify_disabled(struct drm_device *dev,
11901 struct drm_atomic_state *state)
11903 verify_encoder_state(dev, state);
11904 verify_connector_state(dev, state, NULL);
11905 verify_disabled_dpll_state(dev);
11908 static void update_scanline_offset(struct intel_crtc *crtc)
11910 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11913 * The scanline counter increments at the leading edge of hsync.
11915 * On most platforms it starts counting from vtotal-1 on the
11916 * first active line. That means the scanline counter value is
11917 * always one less than what we would expect. Ie. just after
11918 * start of vblank, which also occurs at start of hsync (on the
11919 * last active line), the scanline counter will read vblank_start-1.
11921 * On gen2 the scanline counter starts counting from 1 instead
11922 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11923 * to keep the value positive), instead of adding one.
11925 * On HSW+ the behaviour of the scanline counter depends on the output
11926 * type. For DP ports it behaves like most other platforms, but on HDMI
11927 * there's an extra 1 line difference. So we need to add two instead of
11928 * one to the value.
11930 * On VLV/CHV DSI the scanline counter would appear to increment
11931 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11932 * that means we can't tell whether we're in vblank or not while
11933 * we're on that particular line. We must still set scanline_offset
11934 * to 1 so that the vblank timestamps come out correct when we query
11935 * the scanline counter from within the vblank interrupt handler.
11936 * However if queried just before the start of vblank we'll get an
11937 * answer that's slightly in the future.
11939 if (IS_GEN2(dev_priv)) {
11940 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
11943 vtotal = adjusted_mode->crtc_vtotal;
11944 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
11947 crtc->scanline_offset = vtotal - 1;
11948 } else if (HAS_DDI(dev_priv) &&
11949 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) {
11950 crtc->scanline_offset = 2;
11952 crtc->scanline_offset = 1;
11955 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
11957 struct drm_device *dev = state->dev;
11958 struct drm_i915_private *dev_priv = to_i915(dev);
11959 struct drm_crtc *crtc;
11960 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
11963 if (!dev_priv->display.crtc_compute_clock)
11966 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
11967 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11968 struct intel_shared_dpll *old_dpll =
11969 to_intel_crtc_state(old_crtc_state)->shared_dpll;
11971 if (!needs_modeset(new_crtc_state))
11974 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
11979 intel_release_shared_dpll(old_dpll, intel_crtc, state);
11984 * This implements the workaround described in the "notes" section of the mode
11985 * set sequence documentation. When going from no pipes or single pipe to
11986 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11987 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11989 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
11991 struct drm_crtc_state *crtc_state;
11992 struct intel_crtc *intel_crtc;
11993 struct drm_crtc *crtc;
11994 struct intel_crtc_state *first_crtc_state = NULL;
11995 struct intel_crtc_state *other_crtc_state = NULL;
11996 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
11999 /* look at all crtc's that are going to be enabled in during modeset */
12000 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
12001 intel_crtc = to_intel_crtc(crtc);
12003 if (!crtc_state->active || !needs_modeset(crtc_state))
12006 if (first_crtc_state) {
12007 other_crtc_state = to_intel_crtc_state(crtc_state);
12010 first_crtc_state = to_intel_crtc_state(crtc_state);
12011 first_pipe = intel_crtc->pipe;
12015 /* No workaround needed? */
12016 if (!first_crtc_state)
12019 /* w/a possibly needed, check how many crtc's are already enabled. */
12020 for_each_intel_crtc(state->dev, intel_crtc) {
12021 struct intel_crtc_state *pipe_config;
12023 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12024 if (IS_ERR(pipe_config))
12025 return PTR_ERR(pipe_config);
12027 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12029 if (!pipe_config->base.active ||
12030 needs_modeset(&pipe_config->base))
12033 /* 2 or more enabled crtcs means no need for w/a */
12034 if (enabled_pipe != INVALID_PIPE)
12037 enabled_pipe = intel_crtc->pipe;
12040 if (enabled_pipe != INVALID_PIPE)
12041 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12042 else if (other_crtc_state)
12043 other_crtc_state->hsw_workaround_pipe = first_pipe;
12048 static int intel_lock_all_pipes(struct drm_atomic_state *state)
12050 struct drm_crtc *crtc;
12052 /* Add all pipes to the state */
12053 for_each_crtc(state->dev, crtc) {
12054 struct drm_crtc_state *crtc_state;
12056 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12057 if (IS_ERR(crtc_state))
12058 return PTR_ERR(crtc_state);
12064 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12066 struct drm_crtc *crtc;
12069 * Add all pipes to the state, and force
12070 * a modeset on all the active ones.
12072 for_each_crtc(state->dev, crtc) {
12073 struct drm_crtc_state *crtc_state;
12076 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12077 if (IS_ERR(crtc_state))
12078 return PTR_ERR(crtc_state);
12080 if (!crtc_state->active || needs_modeset(crtc_state))
12083 crtc_state->mode_changed = true;
12085 ret = drm_atomic_add_affected_connectors(state, crtc);
12089 ret = drm_atomic_add_affected_planes(state, crtc);
12097 static int intel_modeset_checks(struct drm_atomic_state *state)
12099 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12100 struct drm_i915_private *dev_priv = to_i915(state->dev);
12101 struct drm_crtc *crtc;
12102 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12105 if (!check_digital_port_conflicts(state)) {
12106 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12110 intel_state->modeset = true;
12111 intel_state->active_crtcs = dev_priv->active_crtcs;
12112 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12113 intel_state->cdclk.actual = dev_priv->cdclk.actual;
12115 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12116 if (new_crtc_state->active)
12117 intel_state->active_crtcs |= 1 << i;
12119 intel_state->active_crtcs &= ~(1 << i);
12121 if (old_crtc_state->active != new_crtc_state->active)
12122 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
12126 * See if the config requires any additional preparation, e.g.
12127 * to adjust global state with pipes off. We need to do this
12128 * here so we can get the modeset_pipe updated config for the new
12129 * mode set on this crtc. For other crtcs we need to use the
12130 * adjusted_mode bits in the crtc directly.
12132 if (dev_priv->display.modeset_calc_cdclk) {
12133 ret = dev_priv->display.modeset_calc_cdclk(state);
12138 * Writes to dev_priv->cdclk.logical must protected by
12139 * holding all the crtc locks, even if we don't end up
12140 * touching the hardware
12142 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12143 &intel_state->cdclk.logical)) {
12144 ret = intel_lock_all_pipes(state);
12149 /* All pipes must be switched off while we change the cdclk. */
12150 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12151 &intel_state->cdclk.actual)) {
12152 ret = intel_modeset_all_pipes(state);
12157 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12158 intel_state->cdclk.logical.cdclk,
12159 intel_state->cdclk.actual.cdclk);
12160 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12161 intel_state->cdclk.logical.voltage_level,
12162 intel_state->cdclk.actual.voltage_level);
12164 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12167 intel_modeset_clear_plls(state);
12169 if (IS_HASWELL(dev_priv))
12170 return haswell_mode_set_planes_workaround(state);
12176 * Handle calculation of various watermark data at the end of the atomic check
12177 * phase. The code here should be run after the per-crtc and per-plane 'check'
12178 * handlers to ensure that all derived state has been updated.
12180 static int calc_watermark_data(struct drm_atomic_state *state)
12182 struct drm_device *dev = state->dev;
12183 struct drm_i915_private *dev_priv = to_i915(dev);
12185 /* Is there platform-specific watermark information to calculate? */
12186 if (dev_priv->display.compute_global_watermarks)
12187 return dev_priv->display.compute_global_watermarks(state);
12193 * intel_atomic_check - validate state object
12195 * @state: state to validate
12197 static int intel_atomic_check(struct drm_device *dev,
12198 struct drm_atomic_state *state)
12200 struct drm_i915_private *dev_priv = to_i915(dev);
12201 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12202 struct drm_crtc *crtc;
12203 struct drm_crtc_state *old_crtc_state, *crtc_state;
12205 bool any_ms = false;
12207 /* Catch I915_MODE_FLAG_INHERITED */
12208 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12210 if (crtc_state->mode.private_flags !=
12211 old_crtc_state->mode.private_flags)
12212 crtc_state->mode_changed = true;
12215 ret = drm_atomic_helper_check_modeset(dev, state);
12219 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12220 struct intel_crtc_state *pipe_config =
12221 to_intel_crtc_state(crtc_state);
12223 if (!needs_modeset(crtc_state))
12226 if (!crtc_state->enable) {
12231 ret = intel_modeset_pipe_config(crtc, pipe_config);
12233 intel_dump_pipe_config(to_intel_crtc(crtc),
12234 pipe_config, "[failed]");
12238 if (i915_modparams.fastboot &&
12239 intel_pipe_config_compare(dev_priv,
12240 to_intel_crtc_state(old_crtc_state),
12241 pipe_config, true)) {
12242 crtc_state->mode_changed = false;
12243 pipe_config->update_pipe = true;
12246 if (needs_modeset(crtc_state))
12249 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12250 needs_modeset(crtc_state) ?
12251 "[modeset]" : "[fastset]");
12255 ret = intel_modeset_checks(state);
12260 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12263 ret = drm_atomic_helper_check_planes(dev, state);
12267 intel_fbc_choose_crtc(dev_priv, intel_state);
12268 return calc_watermark_data(state);
12271 static int intel_atomic_prepare_commit(struct drm_device *dev,
12272 struct drm_atomic_state *state)
12274 return drm_atomic_helper_prepare_planes(dev, state);
12277 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12279 struct drm_device *dev = crtc->base.dev;
12281 if (!dev->max_vblank_count)
12282 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
12284 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12287 static void intel_update_crtc(struct drm_crtc *crtc,
12288 struct drm_atomic_state *state,
12289 struct drm_crtc_state *old_crtc_state,
12290 struct drm_crtc_state *new_crtc_state)
12292 struct drm_device *dev = crtc->dev;
12293 struct drm_i915_private *dev_priv = to_i915(dev);
12294 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12295 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12296 bool modeset = needs_modeset(new_crtc_state);
12297 struct intel_plane_state *new_plane_state =
12298 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12299 to_intel_plane(crtc->primary));
12302 update_scanline_offset(intel_crtc);
12303 dev_priv->display.crtc_enable(pipe_config, state);
12305 /* vblanks work again, re-enable pipe CRC. */
12306 intel_crtc_enable_pipe_crc(intel_crtc);
12308 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12312 if (new_plane_state)
12313 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
12315 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state);
12318 static void intel_update_crtcs(struct drm_atomic_state *state)
12320 struct drm_crtc *crtc;
12321 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12324 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12325 if (!new_crtc_state->active)
12328 intel_update_crtc(crtc, state, old_crtc_state,
12333 static void skl_update_crtcs(struct drm_atomic_state *state)
12335 struct drm_i915_private *dev_priv = to_i915(state->dev);
12336 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12337 struct drm_crtc *crtc;
12338 struct intel_crtc *intel_crtc;
12339 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12340 struct intel_crtc_state *cstate;
12341 unsigned int updated = 0;
12345 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12346 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
12348 const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
12350 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
12351 /* ignore allocations for crtc's that have been turned off. */
12352 if (new_crtc_state->active)
12353 entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
12355 /* If 2nd DBuf slice required, enable it here */
12356 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12357 icl_dbuf_slices_update(dev_priv, required_slices);
12360 * Whenever the number of active pipes changes, we need to make sure we
12361 * update the pipes in the right order so that their ddb allocations
12362 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12363 * cause pipe underruns and other bad stuff.
12368 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12369 bool vbl_wait = false;
12370 unsigned int cmask = drm_crtc_mask(crtc);
12372 intel_crtc = to_intel_crtc(crtc);
12373 cstate = to_intel_crtc_state(new_crtc_state);
12374 pipe = intel_crtc->pipe;
12376 if (updated & cmask || !cstate->base.active)
12379 if (skl_ddb_allocation_overlaps(dev_priv,
12381 &cstate->wm.skl.ddb,
12386 entries[i] = &cstate->wm.skl.ddb;
12389 * If this is an already active pipe, it's DDB changed,
12390 * and this isn't the last pipe that needs updating
12391 * then we need to wait for a vblank to pass for the
12392 * new ddb allocation to take effect.
12394 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
12395 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
12396 !new_crtc_state->active_changed &&
12397 intel_state->wm_results.dirty_pipes != updated)
12400 intel_update_crtc(crtc, state, old_crtc_state,
12404 intel_wait_for_vblank(dev_priv, pipe);
12408 } while (progress);
12410 /* If 2nd DBuf slice is no more required disable it */
12411 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12412 icl_dbuf_slices_update(dev_priv, required_slices);
12415 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12417 struct intel_atomic_state *state, *next;
12418 struct llist_node *freed;
12420 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12421 llist_for_each_entry_safe(state, next, freed, freed)
12422 drm_atomic_state_put(&state->base);
12425 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12427 struct drm_i915_private *dev_priv =
12428 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12430 intel_atomic_helper_free_state(dev_priv);
12433 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12435 struct wait_queue_entry wait_fence, wait_reset;
12436 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12438 init_wait_entry(&wait_fence, 0);
12439 init_wait_entry(&wait_reset, 0);
12441 prepare_to_wait(&intel_state->commit_ready.wait,
12442 &wait_fence, TASK_UNINTERRUPTIBLE);
12443 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12444 &wait_reset, TASK_UNINTERRUPTIBLE);
12447 if (i915_sw_fence_done(&intel_state->commit_ready)
12448 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12453 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12454 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12457 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
12459 struct drm_device *dev = state->dev;
12460 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12461 struct drm_i915_private *dev_priv = to_i915(dev);
12462 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12463 struct drm_crtc *crtc;
12464 struct intel_crtc_state *intel_cstate;
12465 u64 put_domains[I915_MAX_PIPES] = {};
12468 intel_atomic_commit_fence_wait(intel_state);
12470 drm_atomic_helper_wait_for_dependencies(state);
12472 if (intel_state->modeset)
12473 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
12475 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12476 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12478 if (needs_modeset(new_crtc_state) ||
12479 to_intel_crtc_state(new_crtc_state)->update_pipe) {
12481 put_domains[to_intel_crtc(crtc)->pipe] =
12482 modeset_get_crtc_power_domains(crtc,
12483 to_intel_crtc_state(new_crtc_state));
12486 if (!needs_modeset(new_crtc_state))
12489 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12490 to_intel_crtc_state(new_crtc_state));
12492 if (old_crtc_state->active) {
12493 intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask);
12496 * We need to disable pipe CRC before disabling the pipe,
12497 * or we race against vblank off.
12499 intel_crtc_disable_pipe_crc(intel_crtc);
12501 dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state);
12502 intel_crtc->active = false;
12503 intel_fbc_disable(intel_crtc);
12504 intel_disable_shared_dpll(intel_crtc);
12507 * Underruns don't always raise
12508 * interrupts, so check manually.
12510 intel_check_cpu_fifo_underruns(dev_priv);
12511 intel_check_pch_fifo_underruns(dev_priv);
12513 if (!new_crtc_state->active) {
12515 * Make sure we don't call initial_watermarks
12516 * for ILK-style watermark updates.
12518 * No clue what this is supposed to achieve.
12520 if (INTEL_GEN(dev_priv) >= 9)
12521 dev_priv->display.initial_watermarks(intel_state,
12522 to_intel_crtc_state(new_crtc_state));
12527 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12528 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12529 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
12531 if (intel_state->modeset) {
12532 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12534 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
12537 * SKL workaround: bspec recommends we disable the SAGV when we
12538 * have more then one pipe enabled
12540 if (!intel_can_enable_sagv(state))
12541 intel_disable_sagv(dev_priv);
12543 intel_modeset_verify_disabled(dev, state);
12546 /* Complete the events for pipes that have now been disabled */
12547 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12548 bool modeset = needs_modeset(new_crtc_state);
12550 /* Complete events for now disable pipes here. */
12551 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
12552 spin_lock_irq(&dev->event_lock);
12553 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
12554 spin_unlock_irq(&dev->event_lock);
12556 new_crtc_state->event = NULL;
12560 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12561 dev_priv->display.update_crtcs(state);
12563 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12564 * already, but still need the state for the delayed optimization. To
12566 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12567 * - schedule that vblank worker _before_ calling hw_done
12568 * - at the start of commit_tail, cancel it _synchrously
12569 * - switch over to the vblank wait helper in the core after that since
12570 * we don't need out special handling any more.
12572 drm_atomic_helper_wait_for_flip_done(dev, state);
12575 * Now that the vblank has passed, we can go ahead and program the
12576 * optimal watermarks on platforms that need two-step watermark
12579 * TODO: Move this (and other cleanup) to an async worker eventually.
12581 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12582 intel_cstate = to_intel_crtc_state(new_crtc_state);
12584 if (dev_priv->display.optimize_watermarks)
12585 dev_priv->display.optimize_watermarks(intel_state,
12589 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12590 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12592 if (put_domains[i])
12593 modeset_put_power_domains(dev_priv, put_domains[i]);
12595 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
12598 if (intel_state->modeset)
12599 intel_verify_planes(intel_state);
12601 if (intel_state->modeset && intel_can_enable_sagv(state))
12602 intel_enable_sagv(dev_priv);
12604 drm_atomic_helper_commit_hw_done(state);
12606 if (intel_state->modeset) {
12607 /* As one of the primary mmio accessors, KMS has a high
12608 * likelihood of triggering bugs in unclaimed access. After we
12609 * finish modesetting, see if an error has been flagged, and if
12610 * so enable debugging for the next modeset - and hope we catch
12613 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
12614 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
12617 drm_atomic_helper_cleanup_planes(dev, state);
12619 drm_atomic_helper_commit_cleanup_done(state);
12621 drm_atomic_state_put(state);
12623 intel_atomic_helper_free_state(dev_priv);
12626 static void intel_atomic_commit_work(struct work_struct *work)
12628 struct drm_atomic_state *state =
12629 container_of(work, struct drm_atomic_state, commit_work);
12631 intel_atomic_commit_tail(state);
12634 static int __i915_sw_fence_call
12635 intel_atomic_commit_ready(struct i915_sw_fence *fence,
12636 enum i915_sw_fence_notify notify)
12638 struct intel_atomic_state *state =
12639 container_of(fence, struct intel_atomic_state, commit_ready);
12642 case FENCE_COMPLETE:
12643 /* we do blocking waits in the worker, nothing to do here */
12647 struct intel_atomic_helper *helper =
12648 &to_i915(state->base.dev)->atomic_helper;
12650 if (llist_add(&state->freed, &helper->free_list))
12651 schedule_work(&helper->free_work);
12656 return NOTIFY_DONE;
12659 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
12661 struct drm_plane_state *old_plane_state, *new_plane_state;
12662 struct drm_plane *plane;
12665 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
12666 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
12667 intel_fb_obj(new_plane_state->fb),
12668 to_intel_plane(plane)->frontbuffer_bit);
12672 * intel_atomic_commit - commit validated state object
12674 * @state: the top-level driver state object
12675 * @nonblock: nonblocking commit
12677 * This function commits a top-level state object that has been validated
12678 * with drm_atomic_helper_check().
12681 * Zero for success or -errno.
12683 static int intel_atomic_commit(struct drm_device *dev,
12684 struct drm_atomic_state *state,
12687 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12688 struct drm_i915_private *dev_priv = to_i915(dev);
12691 drm_atomic_state_get(state);
12692 i915_sw_fence_init(&intel_state->commit_ready,
12693 intel_atomic_commit_ready);
12696 * The intel_legacy_cursor_update() fast path takes care
12697 * of avoiding the vblank waits for simple cursor
12698 * movement and flips. For cursor on/off and size changes,
12699 * we want to perform the vblank waits so that watermark
12700 * updates happen during the correct frames. Gen9+ have
12701 * double buffered watermarks and so shouldn't need this.
12703 * Unset state->legacy_cursor_update before the call to
12704 * drm_atomic_helper_setup_commit() because otherwise
12705 * drm_atomic_helper_wait_for_flip_done() is a noop and
12706 * we get FIFO underruns because we didn't wait
12709 * FIXME doing watermarks and fb cleanup from a vblank worker
12710 * (assuming we had any) would solve these problems.
12712 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
12713 struct intel_crtc_state *new_crtc_state;
12714 struct intel_crtc *crtc;
12717 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
12718 if (new_crtc_state->wm.need_postvbl_update ||
12719 new_crtc_state->update_wm_post)
12720 state->legacy_cursor_update = false;
12723 ret = intel_atomic_prepare_commit(dev, state);
12725 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
12726 i915_sw_fence_commit(&intel_state->commit_ready);
12730 ret = drm_atomic_helper_setup_commit(state, nonblock);
12732 ret = drm_atomic_helper_swap_state(state, true);
12735 i915_sw_fence_commit(&intel_state->commit_ready);
12737 drm_atomic_helper_cleanup_planes(dev, state);
12740 dev_priv->wm.distrust_bios_wm = false;
12741 intel_shared_dpll_swap_state(state);
12742 intel_atomic_track_fbs(state);
12744 if (intel_state->modeset) {
12745 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
12746 sizeof(intel_state->min_cdclk));
12747 memcpy(dev_priv->min_voltage_level,
12748 intel_state->min_voltage_level,
12749 sizeof(intel_state->min_voltage_level));
12750 dev_priv->active_crtcs = intel_state->active_crtcs;
12751 dev_priv->cdclk.logical = intel_state->cdclk.logical;
12752 dev_priv->cdclk.actual = intel_state->cdclk.actual;
12755 drm_atomic_state_get(state);
12756 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
12758 i915_sw_fence_commit(&intel_state->commit_ready);
12759 if (nonblock && intel_state->modeset) {
12760 queue_work(dev_priv->modeset_wq, &state->commit_work);
12761 } else if (nonblock) {
12762 queue_work(system_unbound_wq, &state->commit_work);
12764 if (intel_state->modeset)
12765 flush_workqueue(dev_priv->modeset_wq);
12766 intel_atomic_commit_tail(state);
12772 static const struct drm_crtc_funcs intel_crtc_funcs = {
12773 .gamma_set = drm_atomic_helper_legacy_gamma_set,
12774 .set_config = drm_atomic_helper_set_config,
12775 .destroy = intel_crtc_destroy,
12776 .page_flip = drm_atomic_helper_page_flip,
12777 .atomic_duplicate_state = intel_crtc_duplicate_state,
12778 .atomic_destroy_state = intel_crtc_destroy_state,
12779 .set_crc_source = intel_crtc_set_crc_source,
12782 struct wait_rps_boost {
12783 struct wait_queue_entry wait;
12785 struct drm_crtc *crtc;
12786 struct i915_request *request;
12789 static int do_rps_boost(struct wait_queue_entry *_wait,
12790 unsigned mode, int sync, void *key)
12792 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
12793 struct i915_request *rq = wait->request;
12796 * If we missed the vblank, but the request is already running it
12797 * is reasonable to assume that it will complete before the next
12798 * vblank without our intervention, so leave RPS alone.
12800 if (!i915_request_started(rq))
12801 gen6_rps_boost(rq, NULL);
12802 i915_request_put(rq);
12804 drm_crtc_vblank_put(wait->crtc);
12806 list_del(&wait->wait.entry);
12811 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
12812 struct dma_fence *fence)
12814 struct wait_rps_boost *wait;
12816 if (!dma_fence_is_i915(fence))
12819 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
12822 if (drm_crtc_vblank_get(crtc))
12825 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
12827 drm_crtc_vblank_put(crtc);
12831 wait->request = to_request(dma_fence_get(fence));
12834 wait->wait.func = do_rps_boost;
12835 wait->wait.flags = 0;
12837 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
12840 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
12842 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
12843 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
12844 struct drm_framebuffer *fb = plane_state->base.fb;
12845 struct i915_vma *vma;
12847 if (plane->id == PLANE_CURSOR &&
12848 INTEL_INFO(dev_priv)->cursor_needs_physical) {
12849 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12850 const int align = intel_cursor_alignment(dev_priv);
12852 return i915_gem_object_attach_phys(obj, align);
12855 vma = intel_pin_and_fence_fb_obj(fb,
12856 plane_state->base.rotation,
12857 intel_plane_uses_fence(plane_state),
12858 &plane_state->flags);
12860 return PTR_ERR(vma);
12862 plane_state->vma = vma;
12867 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
12869 struct i915_vma *vma;
12871 vma = fetch_and_zero(&old_plane_state->vma);
12873 intel_unpin_fb_vma(vma, old_plane_state->flags);
12876 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
12878 struct i915_sched_attr attr = {
12879 .priority = I915_PRIORITY_DISPLAY,
12882 i915_gem_object_wait_priority(obj, 0, &attr);
12886 * intel_prepare_plane_fb - Prepare fb for usage on plane
12887 * @plane: drm plane to prepare for
12888 * @new_state: the plane state being prepared
12890 * Prepares a framebuffer for usage on a display plane. Generally this
12891 * involves pinning the underlying object and updating the frontbuffer tracking
12892 * bits. Some older platforms need special physical address handling for
12895 * Must be called with struct_mutex held.
12897 * Returns 0 on success, negative error code on failure.
12900 intel_prepare_plane_fb(struct drm_plane *plane,
12901 struct drm_plane_state *new_state)
12903 struct intel_atomic_state *intel_state =
12904 to_intel_atomic_state(new_state->state);
12905 struct drm_i915_private *dev_priv = to_i915(plane->dev);
12906 struct drm_framebuffer *fb = new_state->fb;
12907 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12908 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
12912 struct drm_crtc_state *crtc_state =
12913 drm_atomic_get_new_crtc_state(new_state->state,
12914 plane->state->crtc);
12916 /* Big Hammer, we also need to ensure that any pending
12917 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
12918 * current scanout is retired before unpinning the old
12919 * framebuffer. Note that we rely on userspace rendering
12920 * into the buffer attached to the pipe they are waiting
12921 * on. If not, userspace generates a GPU hang with IPEHR
12922 * point to the MI_WAIT_FOR_EVENT.
12924 * This should only fail upon a hung GPU, in which case we
12925 * can safely continue.
12927 if (needs_modeset(crtc_state)) {
12928 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
12929 old_obj->resv, NULL,
12937 if (new_state->fence) { /* explicit fencing */
12938 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
12940 I915_FENCE_TIMEOUT,
12949 ret = i915_gem_object_pin_pages(obj);
12953 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
12955 i915_gem_object_unpin_pages(obj);
12959 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
12961 fb_obj_bump_render_priority(obj);
12963 mutex_unlock(&dev_priv->drm.struct_mutex);
12964 i915_gem_object_unpin_pages(obj);
12968 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
12970 if (!new_state->fence) { /* implicit fencing */
12971 struct dma_fence *fence;
12973 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
12975 false, I915_FENCE_TIMEOUT,
12980 fence = reservation_object_get_excl_rcu(obj->resv);
12982 add_rps_boost_after_vblank(new_state->crtc, fence);
12983 dma_fence_put(fence);
12986 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
12993 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12994 * @plane: drm plane to clean up for
12995 * @old_state: the state from the previous modeset
12997 * Cleans up a framebuffer that has just been removed from a plane.
12999 * Must be called with struct_mutex held.
13002 intel_cleanup_plane_fb(struct drm_plane *plane,
13003 struct drm_plane_state *old_state)
13005 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13007 /* Should only be called after a successful intel_prepare_plane_fb()! */
13008 mutex_lock(&dev_priv->drm.struct_mutex);
13009 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13010 mutex_unlock(&dev_priv->drm.struct_mutex);
13014 skl_max_scale(struct intel_crtc *intel_crtc,
13015 struct intel_crtc_state *crtc_state,
13016 uint32_t pixel_format)
13018 struct drm_i915_private *dev_priv;
13019 int max_scale, mult;
13020 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
13022 if (!intel_crtc || !crtc_state->base.enable)
13023 return DRM_PLANE_HELPER_NO_SCALING;
13025 dev_priv = to_i915(intel_crtc->base.dev);
13027 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13028 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13030 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
13033 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
13034 return DRM_PLANE_HELPER_NO_SCALING;
13037 * skl max scale is lower of:
13038 * close to 3 but not 3, -1 is for that purpose
13042 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13043 tmpclk1 = (1 << 16) * mult - 1;
13044 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13045 max_scale = min(tmpclk1, tmpclk2);
13051 intel_check_primary_plane(struct intel_plane *plane,
13052 struct intel_crtc_state *crtc_state,
13053 struct intel_plane_state *state)
13055 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13056 struct drm_crtc *crtc = state->base.crtc;
13057 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
13058 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
13059 bool can_position = false;
13061 uint32_t pixel_format = 0;
13063 if (INTEL_GEN(dev_priv) >= 9) {
13064 /* use scaler when colorkey is not required */
13065 if (!state->ckey.flags) {
13067 if (state->base.fb)
13068 pixel_format = state->base.fb->format->format;
13069 max_scale = skl_max_scale(to_intel_crtc(crtc),
13070 crtc_state, pixel_format);
13072 can_position = true;
13075 ret = drm_atomic_helper_check_plane_state(&state->base,
13077 min_scale, max_scale,
13078 can_position, true);
13082 if (!state->base.fb)
13085 if (INTEL_GEN(dev_priv) >= 9) {
13086 ret = skl_check_plane_surface(crtc_state, state);
13090 state->ctl = skl_plane_ctl(crtc_state, state);
13092 ret = i9xx_check_plane_surface(state);
13096 state->ctl = i9xx_plane_ctl(crtc_state, state);
13099 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
13100 state->color_ctl = glk_plane_color_ctl(crtc_state, state);
13105 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13106 struct drm_crtc_state *old_crtc_state)
13108 struct drm_device *dev = crtc->dev;
13109 struct drm_i915_private *dev_priv = to_i915(dev);
13110 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13111 struct intel_crtc_state *old_intel_cstate =
13112 to_intel_crtc_state(old_crtc_state);
13113 struct intel_atomic_state *old_intel_state =
13114 to_intel_atomic_state(old_crtc_state->state);
13115 struct intel_crtc_state *intel_cstate =
13116 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13117 bool modeset = needs_modeset(&intel_cstate->base);
13120 (intel_cstate->base.color_mgmt_changed ||
13121 intel_cstate->update_pipe)) {
13122 intel_color_set_csc(&intel_cstate->base);
13123 intel_color_load_luts(&intel_cstate->base);
13126 /* Perform vblank evasion around commit operation */
13127 intel_pipe_update_start(intel_cstate);
13132 if (intel_cstate->update_pipe)
13133 intel_update_pipe_config(old_intel_cstate, intel_cstate);
13134 else if (INTEL_GEN(dev_priv) >= 9)
13135 skl_detach_scalers(intel_crtc);
13138 if (dev_priv->display.atomic_update_watermarks)
13139 dev_priv->display.atomic_update_watermarks(old_intel_state,
13143 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13144 struct intel_crtc_state *crtc_state)
13146 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13148 if (!IS_GEN2(dev_priv))
13149 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13151 if (crtc_state->has_pch_encoder) {
13152 enum pipe pch_transcoder =
13153 intel_crtc_pch_transcoder(crtc);
13155 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13159 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13160 struct drm_crtc_state *old_crtc_state)
13162 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13163 struct intel_atomic_state *old_intel_state =
13164 to_intel_atomic_state(old_crtc_state->state);
13165 struct intel_crtc_state *new_crtc_state =
13166 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13168 intel_pipe_update_end(new_crtc_state);
13170 if (new_crtc_state->update_pipe &&
13171 !needs_modeset(&new_crtc_state->base) &&
13172 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13173 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
13177 * intel_plane_destroy - destroy a plane
13178 * @plane: plane to destroy
13180 * Common destruction function for all types of planes (primary, cursor,
13183 void intel_plane_destroy(struct drm_plane *plane)
13185 drm_plane_cleanup(plane);
13186 kfree(to_intel_plane(plane));
13189 static bool i8xx_mod_supported(uint32_t format, uint64_t modifier)
13192 case DRM_FORMAT_C8:
13193 case DRM_FORMAT_RGB565:
13194 case DRM_FORMAT_XRGB1555:
13195 case DRM_FORMAT_XRGB8888:
13196 return modifier == DRM_FORMAT_MOD_LINEAR ||
13197 modifier == I915_FORMAT_MOD_X_TILED;
13203 static bool i965_mod_supported(uint32_t format, uint64_t modifier)
13206 case DRM_FORMAT_C8:
13207 case DRM_FORMAT_RGB565:
13208 case DRM_FORMAT_XRGB8888:
13209 case DRM_FORMAT_XBGR8888:
13210 case DRM_FORMAT_XRGB2101010:
13211 case DRM_FORMAT_XBGR2101010:
13212 return modifier == DRM_FORMAT_MOD_LINEAR ||
13213 modifier == I915_FORMAT_MOD_X_TILED;
13219 static bool skl_mod_supported(uint32_t format, uint64_t modifier)
13222 case DRM_FORMAT_XRGB8888:
13223 case DRM_FORMAT_XBGR8888:
13224 case DRM_FORMAT_ARGB8888:
13225 case DRM_FORMAT_ABGR8888:
13226 if (modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
13227 modifier == I915_FORMAT_MOD_Y_TILED_CCS)
13230 case DRM_FORMAT_RGB565:
13231 case DRM_FORMAT_XRGB2101010:
13232 case DRM_FORMAT_XBGR2101010:
13233 case DRM_FORMAT_YUYV:
13234 case DRM_FORMAT_YVYU:
13235 case DRM_FORMAT_UYVY:
13236 case DRM_FORMAT_VYUY:
13237 case DRM_FORMAT_NV12:
13238 if (modifier == I915_FORMAT_MOD_Yf_TILED)
13241 case DRM_FORMAT_C8:
13242 if (modifier == DRM_FORMAT_MOD_LINEAR ||
13243 modifier == I915_FORMAT_MOD_X_TILED ||
13244 modifier == I915_FORMAT_MOD_Y_TILED)
13252 static bool intel_primary_plane_format_mod_supported(struct drm_plane *plane,
13256 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13258 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
13261 if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
13262 modifier != DRM_FORMAT_MOD_LINEAR)
13265 if (INTEL_GEN(dev_priv) >= 9)
13266 return skl_mod_supported(format, modifier);
13267 else if (INTEL_GEN(dev_priv) >= 4)
13268 return i965_mod_supported(format, modifier);
13270 return i8xx_mod_supported(format, modifier);
13273 static bool intel_cursor_plane_format_mod_supported(struct drm_plane *plane,
13277 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
13280 return modifier == DRM_FORMAT_MOD_LINEAR && format == DRM_FORMAT_ARGB8888;
13283 static struct drm_plane_funcs intel_plane_funcs = {
13284 .update_plane = drm_atomic_helper_update_plane,
13285 .disable_plane = drm_atomic_helper_disable_plane,
13286 .destroy = intel_plane_destroy,
13287 .atomic_get_property = intel_plane_atomic_get_property,
13288 .atomic_set_property = intel_plane_atomic_set_property,
13289 .atomic_duplicate_state = intel_plane_duplicate_state,
13290 .atomic_destroy_state = intel_plane_destroy_state,
13291 .format_mod_supported = intel_primary_plane_format_mod_supported,
13295 intel_legacy_cursor_update(struct drm_plane *plane,
13296 struct drm_crtc *crtc,
13297 struct drm_framebuffer *fb,
13298 int crtc_x, int crtc_y,
13299 unsigned int crtc_w, unsigned int crtc_h,
13300 uint32_t src_x, uint32_t src_y,
13301 uint32_t src_w, uint32_t src_h,
13302 struct drm_modeset_acquire_ctx *ctx)
13304 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13306 struct drm_plane_state *old_plane_state, *new_plane_state;
13307 struct intel_plane *intel_plane = to_intel_plane(plane);
13308 struct drm_framebuffer *old_fb;
13309 struct drm_crtc_state *crtc_state = crtc->state;
13312 * When crtc is inactive or there is a modeset pending,
13313 * wait for it to complete in the slowpath
13315 if (!crtc_state->active || needs_modeset(crtc_state) ||
13316 to_intel_crtc_state(crtc_state)->update_pipe)
13319 old_plane_state = plane->state;
13321 * Don't do an async update if there is an outstanding commit modifying
13322 * the plane. This prevents our async update's changes from getting
13323 * overridden by a previous synchronous update's state.
13325 if (old_plane_state->commit &&
13326 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13330 * If any parameters change that may affect watermarks,
13331 * take the slowpath. Only changing fb or position should be
13334 if (old_plane_state->crtc != crtc ||
13335 old_plane_state->src_w != src_w ||
13336 old_plane_state->src_h != src_h ||
13337 old_plane_state->crtc_w != crtc_w ||
13338 old_plane_state->crtc_h != crtc_h ||
13339 !old_plane_state->fb != !fb)
13342 new_plane_state = intel_plane_duplicate_state(plane);
13343 if (!new_plane_state)
13346 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13348 new_plane_state->src_x = src_x;
13349 new_plane_state->src_y = src_y;
13350 new_plane_state->src_w = src_w;
13351 new_plane_state->src_h = src_h;
13352 new_plane_state->crtc_x = crtc_x;
13353 new_plane_state->crtc_y = crtc_y;
13354 new_plane_state->crtc_w = crtc_w;
13355 new_plane_state->crtc_h = crtc_h;
13357 ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state),
13358 to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */
13359 to_intel_plane_state(plane->state),
13360 to_intel_plane_state(new_plane_state));
13364 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13368 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13372 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
13374 old_fb = old_plane_state->fb;
13375 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13376 intel_plane->frontbuffer_bit);
13378 /* Swap plane state */
13379 plane->state = new_plane_state;
13381 if (plane->state->visible) {
13382 trace_intel_update_plane(plane, to_intel_crtc(crtc));
13383 intel_plane->update_plane(intel_plane,
13384 to_intel_crtc_state(crtc->state),
13385 to_intel_plane_state(plane->state));
13387 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
13388 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
13391 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
13394 mutex_unlock(&dev_priv->drm.struct_mutex);
13397 intel_plane_destroy_state(plane, new_plane_state);
13399 intel_plane_destroy_state(plane, old_plane_state);
13403 return drm_atomic_helper_update_plane(plane, crtc, fb,
13404 crtc_x, crtc_y, crtc_w, crtc_h,
13405 src_x, src_y, src_w, src_h, ctx);
13408 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13409 .update_plane = intel_legacy_cursor_update,
13410 .disable_plane = drm_atomic_helper_disable_plane,
13411 .destroy = intel_plane_destroy,
13412 .atomic_get_property = intel_plane_atomic_get_property,
13413 .atomic_set_property = intel_plane_atomic_set_property,
13414 .atomic_duplicate_state = intel_plane_duplicate_state,
13415 .atomic_destroy_state = intel_plane_destroy_state,
13416 .format_mod_supported = intel_cursor_plane_format_mod_supported,
13419 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13420 enum i9xx_plane_id i9xx_plane)
13422 if (!HAS_FBC(dev_priv))
13425 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13426 return i9xx_plane == PLANE_A; /* tied to pipe A */
13427 else if (IS_IVYBRIDGE(dev_priv))
13428 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13429 i9xx_plane == PLANE_C;
13430 else if (INTEL_GEN(dev_priv) >= 4)
13431 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13433 return i9xx_plane == PLANE_A;
13436 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
13437 enum pipe pipe, enum plane_id plane_id)
13439 if (!HAS_FBC(dev_priv))
13442 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
13445 bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
13446 enum pipe pipe, enum plane_id plane_id)
13448 if (plane_id == PLANE_PRIMARY) {
13449 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
13451 else if ((INTEL_GEN(dev_priv) == 9 && pipe == PIPE_C) &&
13452 !IS_GEMINILAKE(dev_priv))
13454 } else if (plane_id >= PLANE_SPRITE0) {
13455 if (plane_id == PLANE_CURSOR)
13457 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) == 10) {
13458 if (plane_id != PLANE_SPRITE0)
13461 if (plane_id != PLANE_SPRITE0 || pipe == PIPE_C ||
13462 IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
13469 static struct intel_plane *
13470 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
13472 struct intel_plane *primary = NULL;
13473 struct intel_plane_state *state = NULL;
13474 const uint32_t *intel_primary_formats;
13475 unsigned int supported_rotations;
13476 unsigned int num_formats;
13477 const uint64_t *modifiers;
13480 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
13486 state = intel_create_plane_state(&primary->base);
13492 primary->base.state = &state->base;
13494 primary->can_scale = false;
13495 primary->max_downscale = 1;
13496 if (INTEL_GEN(dev_priv) >= 9) {
13497 primary->can_scale = true;
13498 state->scaler_id = -1;
13500 primary->pipe = pipe;
13502 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13503 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13505 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
13506 primary->i9xx_plane = (enum i9xx_plane_id) !pipe;
13508 primary->i9xx_plane = (enum i9xx_plane_id) pipe;
13509 primary->id = PLANE_PRIMARY;
13510 primary->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, primary->id);
13512 if (INTEL_GEN(dev_priv) >= 9)
13513 primary->has_fbc = skl_plane_has_fbc(dev_priv,
13517 primary->has_fbc = i9xx_plane_has_fbc(dev_priv,
13518 primary->i9xx_plane);
13520 if (primary->has_fbc) {
13521 struct intel_fbc *fbc = &dev_priv->fbc;
13523 fbc->possible_framebuffer_bits |= primary->frontbuffer_bit;
13526 primary->check_plane = intel_check_primary_plane;
13528 if (INTEL_GEN(dev_priv) >= 9) {
13529 if (skl_plane_has_planar(dev_priv, pipe, PLANE_PRIMARY)) {
13530 intel_primary_formats = skl_pri_planar_formats;
13531 num_formats = ARRAY_SIZE(skl_pri_planar_formats);
13533 intel_primary_formats = skl_primary_formats;
13534 num_formats = ARRAY_SIZE(skl_primary_formats);
13537 if (skl_plane_has_ccs(dev_priv, pipe, PLANE_PRIMARY))
13538 modifiers = skl_format_modifiers_ccs;
13540 modifiers = skl_format_modifiers_noccs;
13542 primary->update_plane = skl_update_plane;
13543 primary->disable_plane = skl_disable_plane;
13544 primary->get_hw_state = skl_plane_get_hw_state;
13545 } else if (INTEL_GEN(dev_priv) >= 4) {
13546 intel_primary_formats = i965_primary_formats;
13547 num_formats = ARRAY_SIZE(i965_primary_formats);
13548 modifiers = i9xx_format_modifiers;
13550 primary->update_plane = i9xx_update_plane;
13551 primary->disable_plane = i9xx_disable_plane;
13552 primary->get_hw_state = i9xx_plane_get_hw_state;
13554 intel_primary_formats = i8xx_primary_formats;
13555 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13556 modifiers = i9xx_format_modifiers;
13558 primary->update_plane = i9xx_update_plane;
13559 primary->disable_plane = i9xx_disable_plane;
13560 primary->get_hw_state = i9xx_plane_get_hw_state;
13563 if (INTEL_GEN(dev_priv) >= 9)
13564 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13565 0, &intel_plane_funcs,
13566 intel_primary_formats, num_formats,
13568 DRM_PLANE_TYPE_PRIMARY,
13569 "plane 1%c", pipe_name(pipe));
13570 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
13571 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13572 0, &intel_plane_funcs,
13573 intel_primary_formats, num_formats,
13575 DRM_PLANE_TYPE_PRIMARY,
13576 "primary %c", pipe_name(pipe));
13578 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13579 0, &intel_plane_funcs,
13580 intel_primary_formats, num_formats,
13582 DRM_PLANE_TYPE_PRIMARY,
13584 plane_name(primary->i9xx_plane));
13588 if (INTEL_GEN(dev_priv) >= 10) {
13589 supported_rotations =
13590 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13591 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 |
13592 DRM_MODE_REFLECT_X;
13593 } else if (INTEL_GEN(dev_priv) >= 9) {
13594 supported_rotations =
13595 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13596 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
13597 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13598 supported_rotations =
13599 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13600 DRM_MODE_REFLECT_X;
13601 } else if (INTEL_GEN(dev_priv) >= 4) {
13602 supported_rotations =
13603 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
13605 supported_rotations = DRM_MODE_ROTATE_0;
13608 if (INTEL_GEN(dev_priv) >= 4)
13609 drm_plane_create_rotation_property(&primary->base,
13611 supported_rotations);
13613 if (INTEL_GEN(dev_priv) >= 9)
13614 drm_plane_create_color_properties(&primary->base,
13615 BIT(DRM_COLOR_YCBCR_BT601) |
13616 BIT(DRM_COLOR_YCBCR_BT709),
13617 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
13618 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
13619 DRM_COLOR_YCBCR_BT709,
13620 DRM_COLOR_YCBCR_LIMITED_RANGE);
13622 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
13630 return ERR_PTR(ret);
13633 static struct intel_plane *
13634 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13637 struct intel_plane *cursor = NULL;
13638 struct intel_plane_state *state = NULL;
13641 cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
13647 state = intel_create_plane_state(&cursor->base);
13653 cursor->base.state = &state->base;
13655 cursor->can_scale = false;
13656 cursor->max_downscale = 1;
13657 cursor->pipe = pipe;
13658 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
13659 cursor->id = PLANE_CURSOR;
13660 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
13662 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
13663 cursor->update_plane = i845_update_cursor;
13664 cursor->disable_plane = i845_disable_cursor;
13665 cursor->get_hw_state = i845_cursor_get_hw_state;
13666 cursor->check_plane = i845_check_cursor;
13668 cursor->update_plane = i9xx_update_cursor;
13669 cursor->disable_plane = i9xx_disable_cursor;
13670 cursor->get_hw_state = i9xx_cursor_get_hw_state;
13671 cursor->check_plane = i9xx_check_cursor;
13674 cursor->cursor.base = ~0;
13675 cursor->cursor.cntl = ~0;
13677 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13678 cursor->cursor.size = ~0;
13680 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
13681 0, &intel_cursor_plane_funcs,
13682 intel_cursor_formats,
13683 ARRAY_SIZE(intel_cursor_formats),
13684 cursor_format_modifiers,
13685 DRM_PLANE_TYPE_CURSOR,
13686 "cursor %c", pipe_name(pipe));
13690 if (INTEL_GEN(dev_priv) >= 4)
13691 drm_plane_create_rotation_property(&cursor->base,
13693 DRM_MODE_ROTATE_0 |
13694 DRM_MODE_ROTATE_180);
13696 if (INTEL_GEN(dev_priv) >= 9)
13697 state->scaler_id = -1;
13699 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13707 return ERR_PTR(ret);
13710 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
13711 struct intel_crtc_state *crtc_state)
13713 struct intel_crtc_scaler_state *scaler_state =
13714 &crtc_state->scaler_state;
13715 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13718 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
13719 if (!crtc->num_scalers)
13722 for (i = 0; i < crtc->num_scalers; i++) {
13723 struct intel_scaler *scaler = &scaler_state->scalers[i];
13725 scaler->in_use = 0;
13726 scaler->mode = PS_SCALER_MODE_DYN;
13729 scaler_state->scaler_id = -1;
13732 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
13734 struct intel_crtc *intel_crtc;
13735 struct intel_crtc_state *crtc_state = NULL;
13736 struct intel_plane *primary = NULL;
13737 struct intel_plane *cursor = NULL;
13740 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
13744 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
13749 intel_crtc->config = crtc_state;
13750 intel_crtc->base.state = &crtc_state->base;
13751 crtc_state->base.crtc = &intel_crtc->base;
13753 primary = intel_primary_plane_create(dev_priv, pipe);
13754 if (IS_ERR(primary)) {
13755 ret = PTR_ERR(primary);
13758 intel_crtc->plane_ids_mask |= BIT(primary->id);
13760 for_each_sprite(dev_priv, pipe, sprite) {
13761 struct intel_plane *plane;
13763 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
13764 if (IS_ERR(plane)) {
13765 ret = PTR_ERR(plane);
13768 intel_crtc->plane_ids_mask |= BIT(plane->id);
13771 cursor = intel_cursor_plane_create(dev_priv, pipe);
13772 if (IS_ERR(cursor)) {
13773 ret = PTR_ERR(cursor);
13776 intel_crtc->plane_ids_mask |= BIT(cursor->id);
13778 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
13779 &primary->base, &cursor->base,
13781 "pipe %c", pipe_name(pipe));
13785 intel_crtc->pipe = pipe;
13787 /* initialize shared scalers */
13788 intel_crtc_init_scalers(intel_crtc, crtc_state);
13790 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
13791 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
13792 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
13794 if (INTEL_GEN(dev_priv) < 9) {
13795 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
13797 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
13798 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
13799 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
13802 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
13804 intel_color_init(&intel_crtc->base);
13806 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
13812 * drm_mode_config_cleanup() will free up any
13813 * crtcs/planes already initialized.
13821 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
13823 struct drm_device *dev = connector->base.dev;
13825 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
13827 if (!connector->base.state->crtc)
13828 return INVALID_PIPE;
13830 return to_intel_crtc(connector->base.state->crtc)->pipe;
13833 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
13834 struct drm_file *file)
13836 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
13837 struct drm_crtc *drmmode_crtc;
13838 struct intel_crtc *crtc;
13840 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
13844 crtc = to_intel_crtc(drmmode_crtc);
13845 pipe_from_crtc_id->pipe = crtc->pipe;
13850 static int intel_encoder_clones(struct intel_encoder *encoder)
13852 struct drm_device *dev = encoder->base.dev;
13853 struct intel_encoder *source_encoder;
13854 int index_mask = 0;
13857 for_each_intel_encoder(dev, source_encoder) {
13858 if (encoders_cloneable(encoder, source_encoder))
13859 index_mask |= (1 << entry);
13867 static bool has_edp_a(struct drm_i915_private *dev_priv)
13869 if (!IS_MOBILE(dev_priv))
13872 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
13875 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
13881 static bool intel_crt_present(struct drm_i915_private *dev_priv)
13883 if (INTEL_GEN(dev_priv) >= 9)
13886 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
13889 if (IS_CHERRYVIEW(dev_priv))
13892 if (HAS_PCH_LPT_H(dev_priv) &&
13893 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
13896 /* DDI E can't be used if DDI A requires 4 lanes */
13897 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
13900 if (!dev_priv->vbt.int_crt_support)
13906 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
13911 if (HAS_DDI(dev_priv))
13914 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13915 * everywhere where registers can be write protected.
13917 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13922 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
13923 u32 val = I915_READ(PP_CONTROL(pps_idx));
13925 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
13926 I915_WRITE(PP_CONTROL(pps_idx), val);
13930 static void intel_pps_init(struct drm_i915_private *dev_priv)
13932 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
13933 dev_priv->pps_mmio_base = PCH_PPS_BASE;
13934 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13935 dev_priv->pps_mmio_base = VLV_PPS_BASE;
13937 dev_priv->pps_mmio_base = PPS_BASE;
13939 intel_pps_unlock_regs_wa(dev_priv);
13942 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
13944 struct intel_encoder *encoder;
13945 bool dpd_is_edp = false;
13947 intel_pps_init(dev_priv);
13950 * intel_edp_init_connector() depends on this completing first, to
13951 * prevent the registeration of both eDP and LVDS and the incorrect
13952 * sharing of the PPS.
13954 intel_lvds_init(dev_priv);
13956 if (intel_crt_present(dev_priv))
13957 intel_crt_init(dev_priv);
13959 if (IS_GEN9_LP(dev_priv)) {
13961 * FIXME: Broxton doesn't support port detection via the
13962 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13963 * detect the ports.
13965 intel_ddi_init(dev_priv, PORT_A);
13966 intel_ddi_init(dev_priv, PORT_B);
13967 intel_ddi_init(dev_priv, PORT_C);
13969 intel_dsi_init(dev_priv);
13970 } else if (HAS_DDI(dev_priv)) {
13974 * Haswell uses DDI functions to detect digital outputs.
13975 * On SKL pre-D0 the strap isn't connected, so we assume
13978 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
13979 /* WaIgnoreDDIAStrap: skl */
13980 if (found || IS_GEN9_BC(dev_priv))
13981 intel_ddi_init(dev_priv, PORT_A);
13983 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
13985 found = I915_READ(SFUSE_STRAP);
13987 if (found & SFUSE_STRAP_DDIB_DETECTED)
13988 intel_ddi_init(dev_priv, PORT_B);
13989 if (found & SFUSE_STRAP_DDIC_DETECTED)
13990 intel_ddi_init(dev_priv, PORT_C);
13991 if (found & SFUSE_STRAP_DDID_DETECTED)
13992 intel_ddi_init(dev_priv, PORT_D);
13993 if (found & SFUSE_STRAP_DDIF_DETECTED)
13994 intel_ddi_init(dev_priv, PORT_F);
13996 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13998 if (IS_GEN9_BC(dev_priv) &&
13999 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14000 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14001 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
14002 intel_ddi_init(dev_priv, PORT_E);
14004 } else if (HAS_PCH_SPLIT(dev_priv)) {
14006 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
14008 if (has_edp_a(dev_priv))
14009 intel_dp_init(dev_priv, DP_A, PORT_A);
14011 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
14012 /* PCH SDVOB multiplex with HDMIB */
14013 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
14015 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
14016 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
14017 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
14020 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
14021 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
14023 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
14024 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
14026 if (I915_READ(PCH_DP_C) & DP_DETECTED)
14027 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
14029 if (I915_READ(PCH_DP_D) & DP_DETECTED)
14030 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
14031 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
14032 bool has_edp, has_port;
14035 * The DP_DETECTED bit is the latched state of the DDC
14036 * SDA pin at boot. However since eDP doesn't require DDC
14037 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14038 * eDP ports may have been muxed to an alternate function.
14039 * Thus we can't rely on the DP_DETECTED bit alone to detect
14040 * eDP ports. Consult the VBT as well as DP_DETECTED to
14041 * detect eDP ports.
14043 * Sadly the straps seem to be missing sometimes even for HDMI
14044 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14045 * and VBT for the presence of the port. Additionally we can't
14046 * trust the port type the VBT declares as we've seen at least
14047 * HDMI ports that the VBT claim are DP or eDP.
14049 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
14050 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14051 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
14052 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
14053 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
14054 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
14056 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
14057 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14058 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
14059 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
14060 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
14061 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
14063 if (IS_CHERRYVIEW(dev_priv)) {
14065 * eDP not supported on port D,
14066 * so no need to worry about it
14068 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14069 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
14070 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
14071 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
14072 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
14075 intel_dsi_init(dev_priv);
14076 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
14077 bool found = false;
14079 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14080 DRM_DEBUG_KMS("probing SDVOB\n");
14081 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
14082 if (!found && IS_G4X(dev_priv)) {
14083 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14084 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
14087 if (!found && IS_G4X(dev_priv))
14088 intel_dp_init(dev_priv, DP_B, PORT_B);
14091 /* Before G4X SDVOC doesn't have its own detect register */
14093 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14094 DRM_DEBUG_KMS("probing SDVOC\n");
14095 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
14098 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14100 if (IS_G4X(dev_priv)) {
14101 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14102 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
14104 if (IS_G4X(dev_priv))
14105 intel_dp_init(dev_priv, DP_C, PORT_C);
14108 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
14109 intel_dp_init(dev_priv, DP_D, PORT_D);
14110 } else if (IS_GEN2(dev_priv))
14111 intel_dvo_init(dev_priv);
14113 if (SUPPORTS_TV(dev_priv))
14114 intel_tv_init(dev_priv);
14116 intel_psr_init(dev_priv);
14118 for_each_intel_encoder(&dev_priv->drm, encoder) {
14119 encoder->base.possible_crtcs = encoder->crtc_mask;
14120 encoder->base.possible_clones =
14121 intel_encoder_clones(encoder);
14124 intel_init_pch_refclk(dev_priv);
14126 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14129 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14131 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14133 drm_framebuffer_cleanup(fb);
14135 i915_gem_object_lock(intel_fb->obj);
14136 WARN_ON(!intel_fb->obj->framebuffer_references--);
14137 i915_gem_object_unlock(intel_fb->obj);
14139 i915_gem_object_put(intel_fb->obj);
14144 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14145 struct drm_file *file,
14146 unsigned int *handle)
14148 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14149 struct drm_i915_gem_object *obj = intel_fb->obj;
14151 if (obj->userptr.mm) {
14152 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14156 return drm_gem_handle_create(file, &obj->base, handle);
14159 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14160 struct drm_file *file,
14161 unsigned flags, unsigned color,
14162 struct drm_clip_rect *clips,
14163 unsigned num_clips)
14165 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14167 i915_gem_object_flush_if_display(obj);
14168 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14173 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14174 .destroy = intel_user_framebuffer_destroy,
14175 .create_handle = intel_user_framebuffer_create_handle,
14176 .dirty = intel_user_framebuffer_dirty,
14180 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14181 uint64_t fb_modifier, uint32_t pixel_format)
14183 u32 gen = INTEL_GEN(dev_priv);
14186 int cpp = drm_format_plane_cpp(pixel_format, 0);
14188 /* "The stride in bytes must not exceed the of the size of 8K
14189 * pixels and 32K bytes."
14191 return min(8192 * cpp, 32768);
14192 } else if (gen >= 5 && !HAS_GMCH_DISPLAY(dev_priv)) {
14194 } else if (gen >= 4) {
14195 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14199 } else if (gen >= 3) {
14200 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14205 /* XXX DSPC is limited to 4k tiled */
14210 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14211 struct drm_i915_gem_object *obj,
14212 struct drm_mode_fb_cmd2 *mode_cmd)
14214 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14215 struct drm_framebuffer *fb = &intel_fb->base;
14216 struct drm_format_name_buf format_name;
14218 unsigned int tiling, stride;
14222 i915_gem_object_lock(obj);
14223 obj->framebuffer_references++;
14224 tiling = i915_gem_object_get_tiling(obj);
14225 stride = i915_gem_object_get_stride(obj);
14226 i915_gem_object_unlock(obj);
14228 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14230 * If there's a fence, enforce that
14231 * the fb modifier and tiling mode match.
14233 if (tiling != I915_TILING_NONE &&
14234 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14235 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14239 if (tiling == I915_TILING_X) {
14240 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14241 } else if (tiling == I915_TILING_Y) {
14242 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14247 /* Passed in modifier sanity checking. */
14248 switch (mode_cmd->modifier[0]) {
14249 case I915_FORMAT_MOD_Y_TILED_CCS:
14250 case I915_FORMAT_MOD_Yf_TILED_CCS:
14251 switch (mode_cmd->pixel_format) {
14252 case DRM_FORMAT_XBGR8888:
14253 case DRM_FORMAT_ABGR8888:
14254 case DRM_FORMAT_XRGB8888:
14255 case DRM_FORMAT_ARGB8888:
14258 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
14262 case I915_FORMAT_MOD_Y_TILED:
14263 case I915_FORMAT_MOD_Yf_TILED:
14264 if (INTEL_GEN(dev_priv) < 9) {
14265 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14266 mode_cmd->modifier[0]);
14269 case DRM_FORMAT_MOD_LINEAR:
14270 case I915_FORMAT_MOD_X_TILED:
14273 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14274 mode_cmd->modifier[0]);
14279 * gen2/3 display engine uses the fence if present,
14280 * so the tiling mode must match the fb modifier exactly.
14282 if (INTEL_GEN(dev_priv) < 4 &&
14283 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14284 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14288 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
14289 mode_cmd->pixel_format);
14290 if (mode_cmd->pitches[0] > pitch_limit) {
14291 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14292 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14293 "tiled" : "linear",
14294 mode_cmd->pitches[0], pitch_limit);
14299 * If there's a fence, enforce that
14300 * the fb pitch and fence stride match.
14302 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14303 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14304 mode_cmd->pitches[0], stride);
14308 /* Reject formats not supported by any plane early. */
14309 switch (mode_cmd->pixel_format) {
14310 case DRM_FORMAT_C8:
14311 case DRM_FORMAT_RGB565:
14312 case DRM_FORMAT_XRGB8888:
14313 case DRM_FORMAT_ARGB8888:
14315 case DRM_FORMAT_XRGB1555:
14316 if (INTEL_GEN(dev_priv) > 3) {
14317 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14318 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14322 case DRM_FORMAT_ABGR8888:
14323 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
14324 INTEL_GEN(dev_priv) < 9) {
14325 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14326 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14330 case DRM_FORMAT_XBGR8888:
14331 case DRM_FORMAT_XRGB2101010:
14332 case DRM_FORMAT_XBGR2101010:
14333 if (INTEL_GEN(dev_priv) < 4) {
14334 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14335 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14339 case DRM_FORMAT_ABGR2101010:
14340 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
14341 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14342 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14346 case DRM_FORMAT_YUYV:
14347 case DRM_FORMAT_UYVY:
14348 case DRM_FORMAT_YVYU:
14349 case DRM_FORMAT_VYUY:
14350 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
14351 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14352 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14356 case DRM_FORMAT_NV12:
14357 if (mode_cmd->modifier[0] == I915_FORMAT_MOD_Y_TILED_CCS ||
14358 mode_cmd->modifier[0] == I915_FORMAT_MOD_Yf_TILED_CCS) {
14359 DRM_DEBUG_KMS("RC not to be enabled with NV12\n");
14362 if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) ||
14363 IS_BROXTON(dev_priv)) {
14364 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14365 drm_get_format_name(mode_cmd->pixel_format,
14371 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14372 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14376 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14377 if (mode_cmd->offsets[0] != 0)
14380 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14382 if (fb->format->format == DRM_FORMAT_NV12 &&
14383 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14384 fb->height < SKL_MIN_YUV_420_SRC_H ||
14385 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14386 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
14390 for (i = 0; i < fb->format->num_planes; i++) {
14391 u32 stride_alignment;
14393 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14394 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14398 stride_alignment = intel_fb_stride_alignment(fb, i);
14401 * Display WA #0531: skl,bxt,kbl,glk
14403 * Render decompression and plane width > 3840
14404 * combined with horizontal panning requires the
14405 * plane stride to be a multiple of 4. We'll just
14406 * require the entire fb to accommodate that to avoid
14407 * potential runtime errors at plane configuration time.
14409 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
14410 (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
14411 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS))
14412 stride_alignment *= 4;
14414 if (fb->pitches[i] & (stride_alignment - 1)) {
14415 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14416 i, fb->pitches[i], stride_alignment);
14421 intel_fb->obj = obj;
14423 ret = intel_fill_fb_info(dev_priv, fb);
14427 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14429 DRM_ERROR("framebuffer init failed %d\n", ret);
14436 i915_gem_object_lock(obj);
14437 obj->framebuffer_references--;
14438 i915_gem_object_unlock(obj);
14442 static struct drm_framebuffer *
14443 intel_user_framebuffer_create(struct drm_device *dev,
14444 struct drm_file *filp,
14445 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14447 struct drm_framebuffer *fb;
14448 struct drm_i915_gem_object *obj;
14449 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14451 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14453 return ERR_PTR(-ENOENT);
14455 fb = intel_framebuffer_create(obj, &mode_cmd);
14457 i915_gem_object_put(obj);
14462 static void intel_atomic_state_free(struct drm_atomic_state *state)
14464 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14466 drm_atomic_state_default_release(state);
14468 i915_sw_fence_fini(&intel_state->commit_ready);
14473 static enum drm_mode_status
14474 intel_mode_valid(struct drm_device *dev,
14475 const struct drm_display_mode *mode)
14477 if (mode->vscan > 1)
14478 return MODE_NO_VSCAN;
14480 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
14481 return MODE_NO_DBLESCAN;
14483 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14484 return MODE_H_ILLEGAL;
14486 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14487 DRM_MODE_FLAG_NCSYNC |
14488 DRM_MODE_FLAG_PCSYNC))
14491 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14492 DRM_MODE_FLAG_PIXMUX |
14493 DRM_MODE_FLAG_CLKDIV2))
14499 static const struct drm_mode_config_funcs intel_mode_funcs = {
14500 .fb_create = intel_user_framebuffer_create,
14501 .get_format_info = intel_get_format_info,
14502 .output_poll_changed = intel_fbdev_output_poll_changed,
14503 .mode_valid = intel_mode_valid,
14504 .atomic_check = intel_atomic_check,
14505 .atomic_commit = intel_atomic_commit,
14506 .atomic_state_alloc = intel_atomic_state_alloc,
14507 .atomic_state_clear = intel_atomic_state_clear,
14508 .atomic_state_free = intel_atomic_state_free,
14512 * intel_init_display_hooks - initialize the display modesetting hooks
14513 * @dev_priv: device private
14515 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14517 intel_init_cdclk_hooks(dev_priv);
14519 if (INTEL_GEN(dev_priv) >= 9) {
14520 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14521 dev_priv->display.get_initial_plane_config =
14522 skylake_get_initial_plane_config;
14523 dev_priv->display.crtc_compute_clock =
14524 haswell_crtc_compute_clock;
14525 dev_priv->display.crtc_enable = haswell_crtc_enable;
14526 dev_priv->display.crtc_disable = haswell_crtc_disable;
14527 } else if (HAS_DDI(dev_priv)) {
14528 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14529 dev_priv->display.get_initial_plane_config =
14530 i9xx_get_initial_plane_config;
14531 dev_priv->display.crtc_compute_clock =
14532 haswell_crtc_compute_clock;
14533 dev_priv->display.crtc_enable = haswell_crtc_enable;
14534 dev_priv->display.crtc_disable = haswell_crtc_disable;
14535 } else if (HAS_PCH_SPLIT(dev_priv)) {
14536 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14537 dev_priv->display.get_initial_plane_config =
14538 i9xx_get_initial_plane_config;
14539 dev_priv->display.crtc_compute_clock =
14540 ironlake_crtc_compute_clock;
14541 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14542 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14543 } else if (IS_CHERRYVIEW(dev_priv)) {
14544 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14545 dev_priv->display.get_initial_plane_config =
14546 i9xx_get_initial_plane_config;
14547 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14548 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14549 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14550 } else if (IS_VALLEYVIEW(dev_priv)) {
14551 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14552 dev_priv->display.get_initial_plane_config =
14553 i9xx_get_initial_plane_config;
14554 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
14555 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14556 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14557 } else if (IS_G4X(dev_priv)) {
14558 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14559 dev_priv->display.get_initial_plane_config =
14560 i9xx_get_initial_plane_config;
14561 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14562 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14563 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14564 } else if (IS_PINEVIEW(dev_priv)) {
14565 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14566 dev_priv->display.get_initial_plane_config =
14567 i9xx_get_initial_plane_config;
14568 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14569 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14570 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14571 } else if (!IS_GEN2(dev_priv)) {
14572 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14573 dev_priv->display.get_initial_plane_config =
14574 i9xx_get_initial_plane_config;
14575 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14576 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14577 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14579 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14580 dev_priv->display.get_initial_plane_config =
14581 i9xx_get_initial_plane_config;
14582 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14583 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14584 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14587 if (IS_GEN5(dev_priv)) {
14588 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14589 } else if (IS_GEN6(dev_priv)) {
14590 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14591 } else if (IS_IVYBRIDGE(dev_priv)) {
14592 /* FIXME: detect B0+ stepping and use auto training */
14593 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14594 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
14595 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14598 if (INTEL_GEN(dev_priv) >= 9)
14599 dev_priv->display.update_crtcs = skl_update_crtcs;
14601 dev_priv->display.update_crtcs = intel_update_crtcs;
14605 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14607 static void quirk_ssc_force_disable(struct drm_device *dev)
14609 struct drm_i915_private *dev_priv = to_i915(dev);
14610 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14611 DRM_INFO("applying lvds SSC disable quirk\n");
14615 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14618 static void quirk_invert_brightness(struct drm_device *dev)
14620 struct drm_i915_private *dev_priv = to_i915(dev);
14621 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14622 DRM_INFO("applying inverted panel brightness quirk\n");
14625 /* Some VBT's incorrectly indicate no backlight is present */
14626 static void quirk_backlight_present(struct drm_device *dev)
14628 struct drm_i915_private *dev_priv = to_i915(dev);
14629 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14630 DRM_INFO("applying backlight present quirk\n");
14633 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
14634 * which is 300 ms greater than eDP spec T12 min.
14636 static void quirk_increase_t12_delay(struct drm_device *dev)
14638 struct drm_i915_private *dev_priv = to_i915(dev);
14640 dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY;
14641 DRM_INFO("Applying T12 delay quirk\n");
14644 struct intel_quirk {
14646 int subsystem_vendor;
14647 int subsystem_device;
14648 void (*hook)(struct drm_device *dev);
14651 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14652 struct intel_dmi_quirk {
14653 void (*hook)(struct drm_device *dev);
14654 const struct dmi_system_id (*dmi_id_list)[];
14657 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
14659 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
14663 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
14665 .dmi_id_list = &(const struct dmi_system_id[]) {
14667 .callback = intel_dmi_reverse_brightness,
14668 .ident = "NCR Corporation",
14669 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
14670 DMI_MATCH(DMI_PRODUCT_NAME, ""),
14673 { } /* terminating entry */
14675 .hook = quirk_invert_brightness,
14679 static struct intel_quirk intel_quirks[] = {
14680 /* Lenovo U160 cannot use SSC on LVDS */
14681 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
14683 /* Sony Vaio Y cannot use SSC on LVDS */
14684 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
14686 /* Acer Aspire 5734Z must invert backlight brightness */
14687 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
14689 /* Acer/eMachines G725 */
14690 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
14692 /* Acer/eMachines e725 */
14693 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
14695 /* Acer/Packard Bell NCL20 */
14696 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
14698 /* Acer Aspire 4736Z */
14699 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
14701 /* Acer Aspire 5336 */
14702 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
14704 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14705 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
14707 /* Acer C720 Chromebook (Core i3 4005U) */
14708 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
14710 /* Apple Macbook 2,1 (Core 2 T7400) */
14711 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
14713 /* Apple Macbook 4,1 */
14714 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
14716 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14717 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
14719 /* HP Chromebook 14 (Celeron 2955U) */
14720 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
14722 /* Dell Chromebook 11 */
14723 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
14725 /* Dell Chromebook 11 (2015 version) */
14726 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
14728 /* Toshiba Satellite P50-C-18C */
14729 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
14732 static void intel_init_quirks(struct drm_device *dev)
14734 struct pci_dev *d = dev->pdev;
14737 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
14738 struct intel_quirk *q = &intel_quirks[i];
14740 if (d->device == q->device &&
14741 (d->subsystem_vendor == q->subsystem_vendor ||
14742 q->subsystem_vendor == PCI_ANY_ID) &&
14743 (d->subsystem_device == q->subsystem_device ||
14744 q->subsystem_device == PCI_ANY_ID))
14747 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
14748 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
14749 intel_dmi_quirks[i].hook(dev);
14753 /* Disable the VGA plane that we never use */
14754 static void i915_disable_vga(struct drm_i915_private *dev_priv)
14756 struct pci_dev *pdev = dev_priv->drm.pdev;
14758 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
14760 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14761 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
14762 outb(SR01, VGA_SR_INDEX);
14763 sr1 = inb(VGA_SR_DATA);
14764 outb(sr1 | 1<<5, VGA_SR_DATA);
14765 vga_put(pdev, VGA_RSRC_LEGACY_IO);
14768 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
14769 POSTING_READ(vga_reg);
14772 void intel_modeset_init_hw(struct drm_device *dev)
14774 struct drm_i915_private *dev_priv = to_i915(dev);
14776 intel_update_cdclk(dev_priv);
14777 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
14778 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
14782 * Calculate what we think the watermarks should be for the state we've read
14783 * out of the hardware and then immediately program those watermarks so that
14784 * we ensure the hardware settings match our internal state.
14786 * We can calculate what we think WM's should be by creating a duplicate of the
14787 * current state (which was constructed during hardware readout) and running it
14788 * through the atomic check code to calculate new watermark values in the
14791 static void sanitize_watermarks(struct drm_device *dev)
14793 struct drm_i915_private *dev_priv = to_i915(dev);
14794 struct drm_atomic_state *state;
14795 struct intel_atomic_state *intel_state;
14796 struct drm_crtc *crtc;
14797 struct drm_crtc_state *cstate;
14798 struct drm_modeset_acquire_ctx ctx;
14802 /* Only supported on platforms that use atomic watermark design */
14803 if (!dev_priv->display.optimize_watermarks)
14807 * We need to hold connection_mutex before calling duplicate_state so
14808 * that the connector loop is protected.
14810 drm_modeset_acquire_init(&ctx, 0);
14812 ret = drm_modeset_lock_all_ctx(dev, &ctx);
14813 if (ret == -EDEADLK) {
14814 drm_modeset_backoff(&ctx);
14816 } else if (WARN_ON(ret)) {
14820 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14821 if (WARN_ON(IS_ERR(state)))
14824 intel_state = to_intel_atomic_state(state);
14827 * Hardware readout is the only time we don't want to calculate
14828 * intermediate watermarks (since we don't trust the current
14831 if (!HAS_GMCH_DISPLAY(dev_priv))
14832 intel_state->skip_intermediate_wm = true;
14834 ret = intel_atomic_check(dev, state);
14837 * If we fail here, it means that the hardware appears to be
14838 * programmed in a way that shouldn't be possible, given our
14839 * understanding of watermark requirements. This might mean a
14840 * mistake in the hardware readout code or a mistake in the
14841 * watermark calculations for a given platform. Raise a WARN
14842 * so that this is noticeable.
14844 * If this actually happens, we'll have to just leave the
14845 * BIOS-programmed watermarks untouched and hope for the best.
14847 WARN(true, "Could not determine valid watermarks for inherited state\n");
14851 /* Write calculated watermark values back */
14852 for_each_new_crtc_in_state(state, crtc, cstate, i) {
14853 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14855 cs->wm.need_postvbl_update = true;
14856 dev_priv->display.optimize_watermarks(intel_state, cs);
14858 to_intel_crtc_state(crtc->state)->wm = cs->wm;
14862 drm_atomic_state_put(state);
14864 drm_modeset_drop_locks(&ctx);
14865 drm_modeset_acquire_fini(&ctx);
14868 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14870 if (IS_GEN5(dev_priv)) {
14872 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14874 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14875 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
14876 dev_priv->fdi_pll_freq = 270000;
14881 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14884 int intel_modeset_init(struct drm_device *dev)
14886 struct drm_i915_private *dev_priv = to_i915(dev);
14887 struct i915_ggtt *ggtt = &dev_priv->ggtt;
14889 struct intel_crtc *crtc;
14891 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
14893 drm_mode_config_init(dev);
14895 dev->mode_config.min_width = 0;
14896 dev->mode_config.min_height = 0;
14898 dev->mode_config.preferred_depth = 24;
14899 dev->mode_config.prefer_shadow = 1;
14901 dev->mode_config.allow_fb_modifiers = true;
14903 dev->mode_config.funcs = &intel_mode_funcs;
14905 init_llist_head(&dev_priv->atomic_helper.free_list);
14906 INIT_WORK(&dev_priv->atomic_helper.free_work,
14907 intel_atomic_helper_free_state_worker);
14909 intel_init_quirks(dev);
14911 intel_init_pm(dev_priv);
14913 if (INTEL_INFO(dev_priv)->num_pipes == 0)
14917 * There may be no VBT; and if the BIOS enabled SSC we can
14918 * just keep using it to avoid unnecessary flicker. Whereas if the
14919 * BIOS isn't using it, don't assume it will work even if the VBT
14920 * indicates as much.
14922 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
14923 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
14926 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
14927 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14928 bios_lvds_use_ssc ? "en" : "dis",
14929 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
14930 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
14934 if (IS_GEN2(dev_priv)) {
14935 dev->mode_config.max_width = 2048;
14936 dev->mode_config.max_height = 2048;
14937 } else if (IS_GEN3(dev_priv)) {
14938 dev->mode_config.max_width = 4096;
14939 dev->mode_config.max_height = 4096;
14941 dev->mode_config.max_width = 8192;
14942 dev->mode_config.max_height = 8192;
14945 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14946 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
14947 dev->mode_config.cursor_height = 1023;
14948 } else if (IS_GEN2(dev_priv)) {
14949 dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
14950 dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
14952 dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
14953 dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
14956 dev->mode_config.fb_base = ggtt->gmadr.start;
14958 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14959 INTEL_INFO(dev_priv)->num_pipes,
14960 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
14962 for_each_pipe(dev_priv, pipe) {
14965 ret = intel_crtc_init(dev_priv, pipe);
14967 drm_mode_config_cleanup(dev);
14972 intel_shared_dpll_init(dev);
14973 intel_update_fdi_pll_freq(dev_priv);
14975 intel_update_czclk(dev_priv);
14976 intel_modeset_init_hw(dev);
14978 if (dev_priv->max_cdclk_freq == 0)
14979 intel_update_max_cdclk(dev_priv);
14981 /* Just disable it once at startup */
14982 i915_disable_vga(dev_priv);
14983 intel_setup_outputs(dev_priv);
14985 drm_modeset_lock_all(dev);
14986 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
14987 drm_modeset_unlock_all(dev);
14989 for_each_intel_crtc(dev, crtc) {
14990 struct intel_initial_plane_config plane_config = {};
14996 * Note that reserving the BIOS fb up front prevents us
14997 * from stuffing other stolen allocations like the ring
14998 * on top. This prevents some ugliness at boot time, and
14999 * can even allow for smooth boot transitions if the BIOS
15000 * fb is large enough for the active pipe configuration.
15002 dev_priv->display.get_initial_plane_config(crtc,
15006 * If the fb is shared between multiple heads, we'll
15007 * just get the first one.
15009 intel_find_initial_plane_obj(crtc, &plane_config);
15013 * Make sure hardware watermarks really match the state we read out.
15014 * Note that we need to do this after reconstructing the BIOS fb's
15015 * since the watermark calculation done here will use pstate->fb.
15017 if (!HAS_GMCH_DISPLAY(dev_priv))
15018 sanitize_watermarks(dev);
15023 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15025 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15026 /* 640x480@60Hz, ~25175 kHz */
15027 struct dpll clock = {
15037 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15039 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15040 pipe_name(pipe), clock.vco, clock.dot);
15042 fp = i9xx_dpll_compute_fp(&clock);
15043 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15044 DPLL_VGA_MODE_DIS |
15045 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15046 PLL_P2_DIVIDE_BY_4 |
15047 PLL_REF_INPUT_DREFCLK |
15050 I915_WRITE(FP0(pipe), fp);
15051 I915_WRITE(FP1(pipe), fp);
15053 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15054 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15055 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15056 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15057 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15058 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15059 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15062 * Apparently we need to have VGA mode enabled prior to changing
15063 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15064 * dividers, even though the register value does change.
15066 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15067 I915_WRITE(DPLL(pipe), dpll);
15069 /* Wait for the clocks to stabilize. */
15070 POSTING_READ(DPLL(pipe));
15073 /* The pixel multiplier can only be updated once the
15074 * DPLL is enabled and the clocks are stable.
15076 * So write it again.
15078 I915_WRITE(DPLL(pipe), dpll);
15080 /* We do this three times for luck */
15081 for (i = 0; i < 3 ; i++) {
15082 I915_WRITE(DPLL(pipe), dpll);
15083 POSTING_READ(DPLL(pipe));
15084 udelay(150); /* wait for warmup */
15087 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15088 POSTING_READ(PIPECONF(pipe));
15090 intel_wait_for_pipe_scanline_moving(crtc);
15093 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15095 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15097 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15100 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15101 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15102 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
15103 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & CURSOR_MODE);
15104 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & CURSOR_MODE);
15106 I915_WRITE(PIPECONF(pipe), 0);
15107 POSTING_READ(PIPECONF(pipe));
15109 intel_wait_for_pipe_scanline_stopped(crtc);
15111 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15112 POSTING_READ(DPLL(pipe));
15115 static bool intel_plane_mapping_ok(struct intel_crtc *crtc,
15116 struct intel_plane *plane)
15118 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15119 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
15120 u32 val = I915_READ(DSPCNTR(i9xx_plane));
15122 return (val & DISPLAY_PLANE_ENABLE) == 0 ||
15123 (val & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE(crtc->pipe);
15127 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15129 struct intel_crtc *crtc;
15131 if (INTEL_GEN(dev_priv) >= 4)
15134 for_each_intel_crtc(&dev_priv->drm, crtc) {
15135 struct intel_plane *plane =
15136 to_intel_plane(crtc->base.primary);
15138 if (intel_plane_mapping_ok(crtc, plane))
15141 DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n",
15143 intel_plane_disable_noatomic(crtc, plane);
15147 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15149 struct drm_device *dev = crtc->base.dev;
15150 struct intel_encoder *encoder;
15152 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15158 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15160 struct drm_device *dev = encoder->base.dev;
15161 struct intel_connector *connector;
15163 for_each_connector_on_encoder(dev, &encoder->base, connector)
15169 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15170 enum pipe pch_transcoder)
15172 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15173 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15176 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15177 struct drm_modeset_acquire_ctx *ctx)
15179 struct drm_device *dev = crtc->base.dev;
15180 struct drm_i915_private *dev_priv = to_i915(dev);
15181 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
15183 /* Clear any frame start delays used for debugging left by the BIOS */
15184 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
15185 i915_reg_t reg = PIPECONF(cpu_transcoder);
15188 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15191 /* restore vblank interrupts to correct state */
15192 drm_crtc_vblank_reset(&crtc->base);
15193 if (crtc->active) {
15194 struct intel_plane *plane;
15196 drm_crtc_vblank_on(&crtc->base);
15198 /* Disable everything but the primary plane */
15199 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15200 const struct intel_plane_state *plane_state =
15201 to_intel_plane_state(plane->base.state);
15203 if (plane_state->base.visible &&
15204 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15205 intel_plane_disable_noatomic(crtc, plane);
15209 /* Adjust the state of the output pipe according to whether we
15210 * have active connectors/encoders. */
15211 if (crtc->active && !intel_crtc_has_encoders(crtc))
15212 intel_crtc_disable_noatomic(&crtc->base, ctx);
15214 if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) {
15216 * We start out with underrun reporting disabled to avoid races.
15217 * For correct bookkeeping mark this on active crtcs.
15219 * Also on gmch platforms we dont have any hardware bits to
15220 * disable the underrun reporting. Which means we need to start
15221 * out with underrun reporting disabled also on inactive pipes,
15222 * since otherwise we'll complain about the garbage we read when
15223 * e.g. coming up after runtime pm.
15225 * No protection against concurrent access is required - at
15226 * worst a fifo underrun happens which also sets this to false.
15228 crtc->cpu_fifo_underrun_disabled = true;
15230 * We track the PCH trancoder underrun reporting state
15231 * within the crtc. With crtc for pipe A housing the underrun
15232 * reporting state for PCH transcoder A, crtc for pipe B housing
15233 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15234 * and marking underrun reporting as disabled for the non-existing
15235 * PCH transcoders B and C would prevent enabling the south
15236 * error interrupt (see cpt_can_enable_serr_int()).
15238 if (has_pch_trancoder(dev_priv, crtc->pipe))
15239 crtc->pch_fifo_underrun_disabled = true;
15243 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15245 struct intel_connector *connector;
15247 /* We need to check both for a crtc link (meaning that the
15248 * encoder is active and trying to read from a pipe) and the
15249 * pipe itself being active. */
15250 bool has_active_crtc = encoder->base.crtc &&
15251 to_intel_crtc(encoder->base.crtc)->active;
15253 connector = intel_encoder_find_connector(encoder);
15254 if (connector && !has_active_crtc) {
15255 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15256 encoder->base.base.id,
15257 encoder->base.name);
15259 /* Connector is active, but has no active pipe. This is
15260 * fallout from our resume register restoring. Disable
15261 * the encoder manually again. */
15262 if (encoder->base.crtc) {
15263 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15265 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15266 encoder->base.base.id,
15267 encoder->base.name);
15268 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15269 if (encoder->post_disable)
15270 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15272 encoder->base.crtc = NULL;
15274 /* Inconsistent output/port/pipe state happens presumably due to
15275 * a bug in one of the get_hw_state functions. Or someplace else
15276 * in our code, like the register restore mess on resume. Clamp
15277 * things to off as a safer default. */
15279 connector->base.dpms = DRM_MODE_DPMS_OFF;
15280 connector->base.encoder = NULL;
15284 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15286 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15288 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15289 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15290 i915_disable_vga(dev_priv);
15294 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15296 /* This function can be called both from intel_modeset_setup_hw_state or
15297 * at a very early point in our resume sequence, where the power well
15298 * structures are not yet restored. Since this function is at a very
15299 * paranoid "someone might have enabled VGA while we were not looking"
15300 * level, just check if the power well is enabled instead of trying to
15301 * follow the "don't touch the power well if we don't need it" policy
15302 * the rest of the driver uses. */
15303 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
15306 i915_redisable_vga_power_on(dev_priv);
15308 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
15311 /* FIXME read out full plane state for all planes */
15312 static void readout_plane_state(struct intel_crtc *crtc)
15314 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15315 struct intel_crtc_state *crtc_state =
15316 to_intel_crtc_state(crtc->base.state);
15317 struct intel_plane *plane;
15319 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
15320 struct intel_plane_state *plane_state =
15321 to_intel_plane_state(plane->base.state);
15322 bool visible = plane->get_hw_state(plane);
15324 intel_set_plane_visible(crtc_state, plane_state, visible);
15328 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15330 struct drm_i915_private *dev_priv = to_i915(dev);
15332 struct intel_crtc *crtc;
15333 struct intel_encoder *encoder;
15334 struct intel_connector *connector;
15335 struct drm_connector_list_iter conn_iter;
15338 dev_priv->active_crtcs = 0;
15340 for_each_intel_crtc(dev, crtc) {
15341 struct intel_crtc_state *crtc_state =
15342 to_intel_crtc_state(crtc->base.state);
15344 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15345 memset(crtc_state, 0, sizeof(*crtc_state));
15346 crtc_state->base.crtc = &crtc->base;
15348 crtc_state->base.active = crtc_state->base.enable =
15349 dev_priv->display.get_pipe_config(crtc, crtc_state);
15351 crtc->base.enabled = crtc_state->base.enable;
15352 crtc->active = crtc_state->base.active;
15354 if (crtc_state->base.active)
15355 dev_priv->active_crtcs |= 1 << crtc->pipe;
15357 readout_plane_state(crtc);
15359 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15360 crtc->base.base.id, crtc->base.name,
15361 enableddisabled(crtc_state->base.active));
15364 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15365 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15367 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15368 &pll->state.hw_state);
15369 pll->state.crtc_mask = 0;
15370 for_each_intel_crtc(dev, crtc) {
15371 struct intel_crtc_state *crtc_state =
15372 to_intel_crtc_state(crtc->base.state);
15374 if (crtc_state->base.active &&
15375 crtc_state->shared_dpll == pll)
15376 pll->state.crtc_mask |= 1 << crtc->pipe;
15378 pll->active_mask = pll->state.crtc_mask;
15380 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15381 pll->info->name, pll->state.crtc_mask, pll->on);
15384 for_each_intel_encoder(dev, encoder) {
15387 if (encoder->get_hw_state(encoder, &pipe)) {
15388 struct intel_crtc_state *crtc_state;
15390 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15391 crtc_state = to_intel_crtc_state(crtc->base.state);
15393 encoder->base.crtc = &crtc->base;
15394 encoder->get_config(encoder, crtc_state);
15396 encoder->base.crtc = NULL;
15399 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15400 encoder->base.base.id, encoder->base.name,
15401 enableddisabled(encoder->base.crtc),
15405 drm_connector_list_iter_begin(dev, &conn_iter);
15406 for_each_intel_connector_iter(connector, &conn_iter) {
15407 if (connector->get_hw_state(connector)) {
15408 connector->base.dpms = DRM_MODE_DPMS_ON;
15410 encoder = connector->encoder;
15411 connector->base.encoder = &encoder->base;
15413 if (encoder->base.crtc &&
15414 encoder->base.crtc->state->active) {
15416 * This has to be done during hardware readout
15417 * because anything calling .crtc_disable may
15418 * rely on the connector_mask being accurate.
15420 encoder->base.crtc->state->connector_mask |=
15421 1 << drm_connector_index(&connector->base);
15422 encoder->base.crtc->state->encoder_mask |=
15423 1 << drm_encoder_index(&encoder->base);
15427 connector->base.dpms = DRM_MODE_DPMS_OFF;
15428 connector->base.encoder = NULL;
15430 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15431 connector->base.base.id, connector->base.name,
15432 enableddisabled(connector->base.encoder));
15434 drm_connector_list_iter_end(&conn_iter);
15436 for_each_intel_crtc(dev, crtc) {
15437 struct intel_crtc_state *crtc_state =
15438 to_intel_crtc_state(crtc->base.state);
15441 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15442 if (crtc_state->base.active) {
15443 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15444 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15445 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
15446 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15447 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15450 * The initial mode needs to be set in order to keep
15451 * the atomic core happy. It wants a valid mode if the
15452 * crtc's enabled, so we do the above call.
15454 * But we don't set all the derived state fully, hence
15455 * set a flag to indicate that a full recalculation is
15456 * needed on the next commit.
15458 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
15460 intel_crtc_compute_pixel_rate(crtc_state);
15462 if (dev_priv->display.modeset_calc_cdclk) {
15463 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15464 if (WARN_ON(min_cdclk < 0))
15468 drm_calc_timestamping_constants(&crtc->base,
15469 &crtc_state->base.adjusted_mode);
15470 update_scanline_offset(crtc);
15473 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
15474 dev_priv->min_voltage_level[crtc->pipe] =
15475 crtc_state->min_voltage_level;
15477 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15482 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15484 struct intel_encoder *encoder;
15486 for_each_intel_encoder(&dev_priv->drm, encoder) {
15488 enum intel_display_power_domain domain;
15490 if (!encoder->get_power_domains)
15493 get_domains = encoder->get_power_domains(encoder);
15494 for_each_power_domain(domain, get_domains)
15495 intel_display_power_get(dev_priv, domain);
15499 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15501 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15502 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15503 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15506 if (IS_HASWELL(dev_priv)) {
15508 * WaRsPkgCStateDisplayPMReq:hsw
15509 * System hang if this isn't done before disabling all planes!
15511 I915_WRITE(CHICKEN_PAR1_1,
15512 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15516 /* Scan out the current hw modeset state,
15517 * and sanitizes it to the current state
15520 intel_modeset_setup_hw_state(struct drm_device *dev,
15521 struct drm_modeset_acquire_ctx *ctx)
15523 struct drm_i915_private *dev_priv = to_i915(dev);
15525 struct intel_crtc *crtc;
15526 struct intel_encoder *encoder;
15529 intel_early_display_was(dev_priv);
15530 intel_modeset_readout_hw_state(dev);
15532 /* HW state is read out, now we need to sanitize this mess. */
15533 get_encoder_power_domains(dev_priv);
15535 intel_sanitize_plane_mapping(dev_priv);
15537 for_each_intel_encoder(dev, encoder) {
15538 intel_sanitize_encoder(encoder);
15541 for_each_pipe(dev_priv, pipe) {
15542 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15544 intel_sanitize_crtc(crtc, ctx);
15545 intel_dump_pipe_config(crtc, crtc->config,
15546 "[setup_hw_state]");
15549 intel_modeset_update_connector_atomic_state(dev);
15551 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15552 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15554 if (!pll->on || pll->active_mask)
15557 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15560 pll->info->funcs->disable(dev_priv, pll);
15564 if (IS_G4X(dev_priv)) {
15565 g4x_wm_get_hw_state(dev);
15566 g4x_wm_sanitize(dev_priv);
15567 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15568 vlv_wm_get_hw_state(dev);
15569 vlv_wm_sanitize(dev_priv);
15570 } else if (INTEL_GEN(dev_priv) >= 9) {
15571 skl_wm_get_hw_state(dev);
15572 } else if (HAS_PCH_SPLIT(dev_priv)) {
15573 ilk_wm_get_hw_state(dev);
15576 for_each_intel_crtc(dev, crtc) {
15579 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config);
15580 if (WARN_ON(put_domains))
15581 modeset_put_power_domains(dev_priv, put_domains);
15583 intel_display_set_init_power(dev_priv, false);
15585 intel_power_domains_verify_state(dev_priv);
15587 intel_fbc_init_pipe_state(dev_priv);
15590 void intel_display_resume(struct drm_device *dev)
15592 struct drm_i915_private *dev_priv = to_i915(dev);
15593 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15594 struct drm_modeset_acquire_ctx ctx;
15597 dev_priv->modeset_restore_state = NULL;
15599 state->acquire_ctx = &ctx;
15601 drm_modeset_acquire_init(&ctx, 0);
15604 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15605 if (ret != -EDEADLK)
15608 drm_modeset_backoff(&ctx);
15612 ret = __intel_display_resume(dev, state, &ctx);
15614 intel_enable_ipc(dev_priv);
15615 drm_modeset_drop_locks(&ctx);
15616 drm_modeset_acquire_fini(&ctx);
15619 DRM_ERROR("Restoring old state failed with %i\n", ret);
15621 drm_atomic_state_put(state);
15624 int intel_connector_register(struct drm_connector *connector)
15626 struct intel_connector *intel_connector = to_intel_connector(connector);
15629 ret = intel_backlight_device_register(intel_connector);
15639 void intel_connector_unregister(struct drm_connector *connector)
15641 struct intel_connector *intel_connector = to_intel_connector(connector);
15643 intel_backlight_device_unregister(intel_connector);
15644 intel_panel_destroy_backlight(connector);
15647 static void intel_hpd_poll_fini(struct drm_device *dev)
15649 struct intel_connector *connector;
15650 struct drm_connector_list_iter conn_iter;
15652 /* Kill all the work that may have been queued by hpd. */
15653 drm_connector_list_iter_begin(dev, &conn_iter);
15654 for_each_intel_connector_iter(connector, &conn_iter) {
15655 if (connector->modeset_retry_work.func)
15656 cancel_work_sync(&connector->modeset_retry_work);
15657 if (connector->hdcp_shim) {
15658 cancel_delayed_work_sync(&connector->hdcp_check_work);
15659 cancel_work_sync(&connector->hdcp_prop_work);
15662 drm_connector_list_iter_end(&conn_iter);
15665 void intel_modeset_cleanup(struct drm_device *dev)
15667 struct drm_i915_private *dev_priv = to_i915(dev);
15669 flush_work(&dev_priv->atomic_helper.free_work);
15670 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15672 intel_disable_gt_powersave(dev_priv);
15675 * Interrupts and polling as the first thing to avoid creating havoc.
15676 * Too much stuff here (turning of connectors, ...) would
15677 * experience fancy races otherwise.
15679 intel_irq_uninstall(dev_priv);
15682 * Due to the hpd irq storm handling the hotplug work can re-arm the
15683 * poll handlers. Hence disable polling after hpd handling is shut down.
15685 intel_hpd_poll_fini(dev);
15687 /* poll work can call into fbdev, hence clean that up afterwards */
15688 intel_fbdev_fini(dev_priv);
15690 intel_unregister_dsm_handler();
15692 intel_fbc_global_disable(dev_priv);
15694 /* flush any delayed tasks or pending work */
15695 flush_scheduled_work();
15697 drm_mode_config_cleanup(dev);
15699 intel_cleanup_overlay(dev_priv);
15701 intel_cleanup_gt_powersave(dev_priv);
15703 intel_teardown_gmbus(dev_priv);
15705 destroy_workqueue(dev_priv->modeset_wq);
15708 void intel_connector_attach_encoder(struct intel_connector *connector,
15709 struct intel_encoder *encoder)
15711 connector->encoder = encoder;
15712 drm_mode_connector_attach_encoder(&connector->base,
15717 * set vga decode state - true == enable VGA decode
15719 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
15721 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
15724 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15725 DRM_ERROR("failed to read control word\n");
15729 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15733 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15735 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
15737 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15738 DRM_ERROR("failed to write control word\n");
15745 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15747 struct intel_display_error_state {
15749 u32 power_well_driver;
15751 int num_transcoders;
15753 struct intel_cursor_error_state {
15758 } cursor[I915_MAX_PIPES];
15760 struct intel_pipe_error_state {
15761 bool power_domain_on;
15764 } pipe[I915_MAX_PIPES];
15766 struct intel_plane_error_state {
15774 } plane[I915_MAX_PIPES];
15776 struct intel_transcoder_error_state {
15777 bool power_domain_on;
15778 enum transcoder cpu_transcoder;
15791 struct intel_display_error_state *
15792 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
15794 struct intel_display_error_state *error;
15795 int transcoders[] = {
15803 if (INTEL_INFO(dev_priv)->num_pipes == 0)
15806 error = kzalloc(sizeof(*error), GFP_ATOMIC);
15810 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15811 error->power_well_driver =
15812 I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL));
15814 for_each_pipe(dev_priv, i) {
15815 error->pipe[i].power_domain_on =
15816 __intel_display_power_is_enabled(dev_priv,
15817 POWER_DOMAIN_PIPE(i));
15818 if (!error->pipe[i].power_domain_on)
15821 error->cursor[i].control = I915_READ(CURCNTR(i));
15822 error->cursor[i].position = I915_READ(CURPOS(i));
15823 error->cursor[i].base = I915_READ(CURBASE(i));
15825 error->plane[i].control = I915_READ(DSPCNTR(i));
15826 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
15827 if (INTEL_GEN(dev_priv) <= 3) {
15828 error->plane[i].size = I915_READ(DSPSIZE(i));
15829 error->plane[i].pos = I915_READ(DSPPOS(i));
15831 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15832 error->plane[i].addr = I915_READ(DSPADDR(i));
15833 if (INTEL_GEN(dev_priv) >= 4) {
15834 error->plane[i].surface = I915_READ(DSPSURF(i));
15835 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
15838 error->pipe[i].source = I915_READ(PIPESRC(i));
15840 if (HAS_GMCH_DISPLAY(dev_priv))
15841 error->pipe[i].stat = I915_READ(PIPESTAT(i));
15844 /* Note: this does not include DSI transcoders. */
15845 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
15846 if (HAS_DDI(dev_priv))
15847 error->num_transcoders++; /* Account for eDP. */
15849 for (i = 0; i < error->num_transcoders; i++) {
15850 enum transcoder cpu_transcoder = transcoders[i];
15852 error->transcoder[i].power_domain_on =
15853 __intel_display_power_is_enabled(dev_priv,
15854 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
15855 if (!error->transcoder[i].power_domain_on)
15858 error->transcoder[i].cpu_transcoder = cpu_transcoder;
15860 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
15861 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
15862 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
15863 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
15864 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
15865 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
15866 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
15872 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15875 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
15876 struct intel_display_error_state *error)
15878 struct drm_i915_private *dev_priv = m->i915;
15884 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
15885 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15886 err_printf(m, "PWR_WELL_CTL2: %08x\n",
15887 error->power_well_driver);
15888 for_each_pipe(dev_priv, i) {
15889 err_printf(m, "Pipe [%d]:\n", i);
15890 err_printf(m, " Power: %s\n",
15891 onoff(error->pipe[i].power_domain_on));
15892 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
15893 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
15895 err_printf(m, "Plane [%d]:\n", i);
15896 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
15897 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
15898 if (INTEL_GEN(dev_priv) <= 3) {
15899 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
15900 err_printf(m, " POS: %08x\n", error->plane[i].pos);
15902 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15903 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
15904 if (INTEL_GEN(dev_priv) >= 4) {
15905 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
15906 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
15909 err_printf(m, "Cursor [%d]:\n", i);
15910 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
15911 err_printf(m, " POS: %08x\n", error->cursor[i].position);
15912 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
15915 for (i = 0; i < error->num_transcoders; i++) {
15916 err_printf(m, "CPU transcoder: %s\n",
15917 transcoder_name(error->transcoder[i].cpu_transcoder));
15918 err_printf(m, " Power: %s\n",
15919 onoff(error->transcoder[i].power_domain_on));
15920 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
15921 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
15922 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
15923 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
15924 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
15925 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
15926 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);