2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include "intel_frontbuffer.h"
38 #include <drm/i915_drm.h>
40 #include "i915_gem_clflush.h"
41 #include "intel_dsi.h"
42 #include "i915_trace.h"
43 #include <drm/drm_atomic.h>
44 #include <drm/drm_atomic_helper.h>
45 #include <drm/drm_dp_helper.h>
46 #include <drm/drm_crtc_helper.h>
47 #include <drm/drm_plane_helper.h>
48 #include <drm/drm_rect.h>
49 #include <drm/drm_atomic_uapi.h>
50 #include <linux/dma_remapping.h>
51 #include <linux/reservation.h>
53 /* Primary plane formats for gen <= 3 */
54 static const uint32_t i8xx_primary_formats[] = {
61 /* Primary plane formats for gen >= 4 */
62 static const uint32_t i965_primary_formats[] = {
67 DRM_FORMAT_XRGB2101010,
68 DRM_FORMAT_XBGR2101010,
71 static const uint64_t i9xx_format_modifiers[] = {
72 I915_FORMAT_MOD_X_TILED,
73 DRM_FORMAT_MOD_LINEAR,
74 DRM_FORMAT_MOD_INVALID
77 static const uint32_t skl_primary_formats[] = {
84 DRM_FORMAT_XRGB2101010,
85 DRM_FORMAT_XBGR2101010,
92 static const uint32_t skl_pri_planar_formats[] = {
99 DRM_FORMAT_XRGB2101010,
100 DRM_FORMAT_XBGR2101010,
108 static const uint64_t skl_format_modifiers_noccs[] = {
109 I915_FORMAT_MOD_Yf_TILED,
110 I915_FORMAT_MOD_Y_TILED,
111 I915_FORMAT_MOD_X_TILED,
112 DRM_FORMAT_MOD_LINEAR,
113 DRM_FORMAT_MOD_INVALID
116 static const uint64_t skl_format_modifiers_ccs[] = {
117 I915_FORMAT_MOD_Yf_TILED_CCS,
118 I915_FORMAT_MOD_Y_TILED_CCS,
119 I915_FORMAT_MOD_Yf_TILED,
120 I915_FORMAT_MOD_Y_TILED,
121 I915_FORMAT_MOD_X_TILED,
122 DRM_FORMAT_MOD_LINEAR,
123 DRM_FORMAT_MOD_INVALID
127 static const uint32_t intel_cursor_formats[] = {
131 static const uint64_t cursor_format_modifiers[] = {
132 DRM_FORMAT_MOD_LINEAR,
133 DRM_FORMAT_MOD_INVALID
136 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
137 struct intel_crtc_state *pipe_config);
138 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
139 struct intel_crtc_state *pipe_config);
141 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
142 struct drm_i915_gem_object *obj,
143 struct drm_mode_fb_cmd2 *mode_cmd);
144 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
145 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
146 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc);
147 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
148 struct intel_link_m_n *m_n,
149 struct intel_link_m_n *m2_n2);
150 static void ironlake_set_pipeconf(struct drm_crtc *crtc);
151 static void haswell_set_pipeconf(struct drm_crtc *crtc);
152 static void haswell_set_pipemisc(struct drm_crtc *crtc);
153 static void vlv_prepare_pll(struct intel_crtc *crtc,
154 const struct intel_crtc_state *pipe_config);
155 static void chv_prepare_pll(struct intel_crtc *crtc,
156 const struct intel_crtc_state *pipe_config);
157 static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
158 static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
159 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
160 struct intel_crtc_state *crtc_state);
161 static void skylake_pfit_enable(struct intel_crtc *crtc);
162 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force);
163 static void ironlake_pfit_enable(struct intel_crtc *crtc);
164 static void intel_modeset_setup_hw_state(struct drm_device *dev,
165 struct drm_modeset_acquire_ctx *ctx);
166 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
171 } dot, vco, n, m, m1, m2, p, p1;
175 int p2_slow, p2_fast;
179 /* returns HPLL frequency in kHz */
180 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
182 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
184 /* Obtain SKU information */
185 mutex_lock(&dev_priv->sb_lock);
186 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
187 CCK_FUSE_HPLL_FREQ_MASK;
188 mutex_unlock(&dev_priv->sb_lock);
190 return vco_freq[hpll_freq] * 1000;
193 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
194 const char *name, u32 reg, int ref_freq)
199 mutex_lock(&dev_priv->sb_lock);
200 val = vlv_cck_read(dev_priv, reg);
201 mutex_unlock(&dev_priv->sb_lock);
203 divider = val & CCK_FREQUENCY_VALUES;
205 WARN((val & CCK_FREQUENCY_STATUS) !=
206 (divider << CCK_FREQUENCY_STATUS_SHIFT),
207 "%s change in progress\n", name);
209 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
212 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
213 const char *name, u32 reg)
215 if (dev_priv->hpll_freq == 0)
216 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
218 return vlv_get_cck_clock(dev_priv, name, reg,
219 dev_priv->hpll_freq);
222 static void intel_update_czclk(struct drm_i915_private *dev_priv)
224 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
227 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
228 CCK_CZ_CLOCK_CONTROL);
230 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
233 static inline u32 /* units of 100MHz */
234 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
235 const struct intel_crtc_state *pipe_config)
237 if (HAS_DDI(dev_priv))
238 return pipe_config->port_clock; /* SPLL */
240 return dev_priv->fdi_pll_freq;
243 static const struct intel_limit intel_limits_i8xx_dac = {
244 .dot = { .min = 25000, .max = 350000 },
245 .vco = { .min = 908000, .max = 1512000 },
246 .n = { .min = 2, .max = 16 },
247 .m = { .min = 96, .max = 140 },
248 .m1 = { .min = 18, .max = 26 },
249 .m2 = { .min = 6, .max = 16 },
250 .p = { .min = 4, .max = 128 },
251 .p1 = { .min = 2, .max = 33 },
252 .p2 = { .dot_limit = 165000,
253 .p2_slow = 4, .p2_fast = 2 },
256 static const struct intel_limit intel_limits_i8xx_dvo = {
257 .dot = { .min = 25000, .max = 350000 },
258 .vco = { .min = 908000, .max = 1512000 },
259 .n = { .min = 2, .max = 16 },
260 .m = { .min = 96, .max = 140 },
261 .m1 = { .min = 18, .max = 26 },
262 .m2 = { .min = 6, .max = 16 },
263 .p = { .min = 4, .max = 128 },
264 .p1 = { .min = 2, .max = 33 },
265 .p2 = { .dot_limit = 165000,
266 .p2_slow = 4, .p2_fast = 4 },
269 static const struct intel_limit intel_limits_i8xx_lvds = {
270 .dot = { .min = 25000, .max = 350000 },
271 .vco = { .min = 908000, .max = 1512000 },
272 .n = { .min = 2, .max = 16 },
273 .m = { .min = 96, .max = 140 },
274 .m1 = { .min = 18, .max = 26 },
275 .m2 = { .min = 6, .max = 16 },
276 .p = { .min = 4, .max = 128 },
277 .p1 = { .min = 1, .max = 6 },
278 .p2 = { .dot_limit = 165000,
279 .p2_slow = 14, .p2_fast = 7 },
282 static const struct intel_limit intel_limits_i9xx_sdvo = {
283 .dot = { .min = 20000, .max = 400000 },
284 .vco = { .min = 1400000, .max = 2800000 },
285 .n = { .min = 1, .max = 6 },
286 .m = { .min = 70, .max = 120 },
287 .m1 = { .min = 8, .max = 18 },
288 .m2 = { .min = 3, .max = 7 },
289 .p = { .min = 5, .max = 80 },
290 .p1 = { .min = 1, .max = 8 },
291 .p2 = { .dot_limit = 200000,
292 .p2_slow = 10, .p2_fast = 5 },
295 static const struct intel_limit intel_limits_i9xx_lvds = {
296 .dot = { .min = 20000, .max = 400000 },
297 .vco = { .min = 1400000, .max = 2800000 },
298 .n = { .min = 1, .max = 6 },
299 .m = { .min = 70, .max = 120 },
300 .m1 = { .min = 8, .max = 18 },
301 .m2 = { .min = 3, .max = 7 },
302 .p = { .min = 7, .max = 98 },
303 .p1 = { .min = 1, .max = 8 },
304 .p2 = { .dot_limit = 112000,
305 .p2_slow = 14, .p2_fast = 7 },
309 static const struct intel_limit intel_limits_g4x_sdvo = {
310 .dot = { .min = 25000, .max = 270000 },
311 .vco = { .min = 1750000, .max = 3500000},
312 .n = { .min = 1, .max = 4 },
313 .m = { .min = 104, .max = 138 },
314 .m1 = { .min = 17, .max = 23 },
315 .m2 = { .min = 5, .max = 11 },
316 .p = { .min = 10, .max = 30 },
317 .p1 = { .min = 1, .max = 3},
318 .p2 = { .dot_limit = 270000,
324 static const struct intel_limit intel_limits_g4x_hdmi = {
325 .dot = { .min = 22000, .max = 400000 },
326 .vco = { .min = 1750000, .max = 3500000},
327 .n = { .min = 1, .max = 4 },
328 .m = { .min = 104, .max = 138 },
329 .m1 = { .min = 16, .max = 23 },
330 .m2 = { .min = 5, .max = 11 },
331 .p = { .min = 5, .max = 80 },
332 .p1 = { .min = 1, .max = 8},
333 .p2 = { .dot_limit = 165000,
334 .p2_slow = 10, .p2_fast = 5 },
337 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
338 .dot = { .min = 20000, .max = 115000 },
339 .vco = { .min = 1750000, .max = 3500000 },
340 .n = { .min = 1, .max = 3 },
341 .m = { .min = 104, .max = 138 },
342 .m1 = { .min = 17, .max = 23 },
343 .m2 = { .min = 5, .max = 11 },
344 .p = { .min = 28, .max = 112 },
345 .p1 = { .min = 2, .max = 8 },
346 .p2 = { .dot_limit = 0,
347 .p2_slow = 14, .p2_fast = 14
351 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
352 .dot = { .min = 80000, .max = 224000 },
353 .vco = { .min = 1750000, .max = 3500000 },
354 .n = { .min = 1, .max = 3 },
355 .m = { .min = 104, .max = 138 },
356 .m1 = { .min = 17, .max = 23 },
357 .m2 = { .min = 5, .max = 11 },
358 .p = { .min = 14, .max = 42 },
359 .p1 = { .min = 2, .max = 6 },
360 .p2 = { .dot_limit = 0,
361 .p2_slow = 7, .p2_fast = 7
365 static const struct intel_limit intel_limits_pineview_sdvo = {
366 .dot = { .min = 20000, .max = 400000},
367 .vco = { .min = 1700000, .max = 3500000 },
368 /* Pineview's Ncounter is a ring counter */
369 .n = { .min = 3, .max = 6 },
370 .m = { .min = 2, .max = 256 },
371 /* Pineview only has one combined m divider, which we treat as m2. */
372 .m1 = { .min = 0, .max = 0 },
373 .m2 = { .min = 0, .max = 254 },
374 .p = { .min = 5, .max = 80 },
375 .p1 = { .min = 1, .max = 8 },
376 .p2 = { .dot_limit = 200000,
377 .p2_slow = 10, .p2_fast = 5 },
380 static const struct intel_limit intel_limits_pineview_lvds = {
381 .dot = { .min = 20000, .max = 400000 },
382 .vco = { .min = 1700000, .max = 3500000 },
383 .n = { .min = 3, .max = 6 },
384 .m = { .min = 2, .max = 256 },
385 .m1 = { .min = 0, .max = 0 },
386 .m2 = { .min = 0, .max = 254 },
387 .p = { .min = 7, .max = 112 },
388 .p1 = { .min = 1, .max = 8 },
389 .p2 = { .dot_limit = 112000,
390 .p2_slow = 14, .p2_fast = 14 },
393 /* Ironlake / Sandybridge
395 * We calculate clock using (register_value + 2) for N/M1/M2, so here
396 * the range value for them is (actual_value - 2).
398 static const struct intel_limit intel_limits_ironlake_dac = {
399 .dot = { .min = 25000, .max = 350000 },
400 .vco = { .min = 1760000, .max = 3510000 },
401 .n = { .min = 1, .max = 5 },
402 .m = { .min = 79, .max = 127 },
403 .m1 = { .min = 12, .max = 22 },
404 .m2 = { .min = 5, .max = 9 },
405 .p = { .min = 5, .max = 80 },
406 .p1 = { .min = 1, .max = 8 },
407 .p2 = { .dot_limit = 225000,
408 .p2_slow = 10, .p2_fast = 5 },
411 static const struct intel_limit intel_limits_ironlake_single_lvds = {
412 .dot = { .min = 25000, .max = 350000 },
413 .vco = { .min = 1760000, .max = 3510000 },
414 .n = { .min = 1, .max = 3 },
415 .m = { .min = 79, .max = 118 },
416 .m1 = { .min = 12, .max = 22 },
417 .m2 = { .min = 5, .max = 9 },
418 .p = { .min = 28, .max = 112 },
419 .p1 = { .min = 2, .max = 8 },
420 .p2 = { .dot_limit = 225000,
421 .p2_slow = 14, .p2_fast = 14 },
424 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
425 .dot = { .min = 25000, .max = 350000 },
426 .vco = { .min = 1760000, .max = 3510000 },
427 .n = { .min = 1, .max = 3 },
428 .m = { .min = 79, .max = 127 },
429 .m1 = { .min = 12, .max = 22 },
430 .m2 = { .min = 5, .max = 9 },
431 .p = { .min = 14, .max = 56 },
432 .p1 = { .min = 2, .max = 8 },
433 .p2 = { .dot_limit = 225000,
434 .p2_slow = 7, .p2_fast = 7 },
437 /* LVDS 100mhz refclk limits. */
438 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
439 .dot = { .min = 25000, .max = 350000 },
440 .vco = { .min = 1760000, .max = 3510000 },
441 .n = { .min = 1, .max = 2 },
442 .m = { .min = 79, .max = 126 },
443 .m1 = { .min = 12, .max = 22 },
444 .m2 = { .min = 5, .max = 9 },
445 .p = { .min = 28, .max = 112 },
446 .p1 = { .min = 2, .max = 8 },
447 .p2 = { .dot_limit = 225000,
448 .p2_slow = 14, .p2_fast = 14 },
451 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
452 .dot = { .min = 25000, .max = 350000 },
453 .vco = { .min = 1760000, .max = 3510000 },
454 .n = { .min = 1, .max = 3 },
455 .m = { .min = 79, .max = 126 },
456 .m1 = { .min = 12, .max = 22 },
457 .m2 = { .min = 5, .max = 9 },
458 .p = { .min = 14, .max = 42 },
459 .p1 = { .min = 2, .max = 6 },
460 .p2 = { .dot_limit = 225000,
461 .p2_slow = 7, .p2_fast = 7 },
464 static const struct intel_limit intel_limits_vlv = {
466 * These are the data rate limits (measured in fast clocks)
467 * since those are the strictest limits we have. The fast
468 * clock and actual rate limits are more relaxed, so checking
469 * them would make no difference.
471 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
472 .vco = { .min = 4000000, .max = 6000000 },
473 .n = { .min = 1, .max = 7 },
474 .m1 = { .min = 2, .max = 3 },
475 .m2 = { .min = 11, .max = 156 },
476 .p1 = { .min = 2, .max = 3 },
477 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
480 static const struct intel_limit intel_limits_chv = {
482 * These are the data rate limits (measured in fast clocks)
483 * since those are the strictest limits we have. The fast
484 * clock and actual rate limits are more relaxed, so checking
485 * them would make no difference.
487 .dot = { .min = 25000 * 5, .max = 540000 * 5},
488 .vco = { .min = 4800000, .max = 6480000 },
489 .n = { .min = 1, .max = 1 },
490 .m1 = { .min = 2, .max = 2 },
491 .m2 = { .min = 24 << 22, .max = 175 << 22 },
492 .p1 = { .min = 2, .max = 4 },
493 .p2 = { .p2_slow = 1, .p2_fast = 14 },
496 static const struct intel_limit intel_limits_bxt = {
497 /* FIXME: find real dot limits */
498 .dot = { .min = 0, .max = INT_MAX },
499 .vco = { .min = 4800000, .max = 6700000 },
500 .n = { .min = 1, .max = 1 },
501 .m1 = { .min = 2, .max = 2 },
502 /* FIXME: find real m2 limits */
503 .m2 = { .min = 2 << 22, .max = 255 << 22 },
504 .p1 = { .min = 2, .max = 4 },
505 .p2 = { .p2_slow = 1, .p2_fast = 20 },
509 skl_wa_528(struct drm_i915_private *dev_priv, int pipe, bool enable)
511 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
515 I915_WRITE(CHICKEN_PIPESL_1(pipe), HSW_FBCQ_DIS);
517 I915_WRITE(CHICKEN_PIPESL_1(pipe), 0);
521 skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
523 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
527 I915_WRITE(CLKGATE_DIS_PSL(pipe),
528 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
530 I915_WRITE(CLKGATE_DIS_PSL(pipe),
531 I915_READ(CLKGATE_DIS_PSL(pipe)) &
532 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
536 needs_modeset(const struct drm_crtc_state *state)
538 return drm_atomic_crtc_needs_modeset(state);
542 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
543 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
544 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
545 * The helpers' return value is the rate of the clock that is fed to the
546 * display engine's pipe which can be the above fast dot clock rate or a
547 * divided-down version of it.
549 /* m1 is reserved as 0 in Pineview, n is a ring counter */
550 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
552 clock->m = clock->m2 + 2;
553 clock->p = clock->p1 * clock->p2;
554 if (WARN_ON(clock->n == 0 || clock->p == 0))
556 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
557 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
562 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
564 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
567 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
569 clock->m = i9xx_dpll_compute_m(clock);
570 clock->p = clock->p1 * clock->p2;
571 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
573 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
574 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
579 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
581 clock->m = clock->m1 * clock->m2;
582 clock->p = clock->p1 * clock->p2;
583 if (WARN_ON(clock->n == 0 || clock->p == 0))
585 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
586 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
588 return clock->dot / 5;
591 int chv_calc_dpll_params(int refclk, struct dpll *clock)
593 clock->m = clock->m1 * clock->m2;
594 clock->p = clock->p1 * clock->p2;
595 if (WARN_ON(clock->n == 0 || clock->p == 0))
597 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
599 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
601 return clock->dot / 5;
604 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
607 * Returns whether the given set of divisors are valid for a given refclk with
608 * the given connectors.
610 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
611 const struct intel_limit *limit,
612 const struct dpll *clock)
614 if (clock->n < limit->n.min || limit->n.max < clock->n)
615 INTELPllInvalid("n out of range\n");
616 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
617 INTELPllInvalid("p1 out of range\n");
618 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
619 INTELPllInvalid("m2 out of range\n");
620 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
621 INTELPllInvalid("m1 out of range\n");
623 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
624 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
625 if (clock->m1 <= clock->m2)
626 INTELPllInvalid("m1 <= m2\n");
628 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
629 !IS_GEN9_LP(dev_priv)) {
630 if (clock->p < limit->p.min || limit->p.max < clock->p)
631 INTELPllInvalid("p out of range\n");
632 if (clock->m < limit->m.min || limit->m.max < clock->m)
633 INTELPllInvalid("m out of range\n");
636 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
637 INTELPllInvalid("vco out of range\n");
638 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
639 * connector, etc., rather than just a single range.
641 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
642 INTELPllInvalid("dot out of range\n");
648 i9xx_select_p2_div(const struct intel_limit *limit,
649 const struct intel_crtc_state *crtc_state,
652 struct drm_device *dev = crtc_state->base.crtc->dev;
654 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
656 * For LVDS just rely on its current settings for dual-channel.
657 * We haven't figured out how to reliably set up different
658 * single/dual channel state, if we even can.
660 if (intel_is_dual_link_lvds(dev))
661 return limit->p2.p2_fast;
663 return limit->p2.p2_slow;
665 if (target < limit->p2.dot_limit)
666 return limit->p2.p2_slow;
668 return limit->p2.p2_fast;
673 * Returns a set of divisors for the desired target clock with the given
674 * refclk, or FALSE. The returned values represent the clock equation:
675 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
677 * Target and reference clocks are specified in kHz.
679 * If match_clock is provided, then best_clock P divider must match the P
680 * divider from @match_clock used for LVDS downclocking.
683 i9xx_find_best_dpll(const struct intel_limit *limit,
684 struct intel_crtc_state *crtc_state,
685 int target, int refclk, struct dpll *match_clock,
686 struct dpll *best_clock)
688 struct drm_device *dev = crtc_state->base.crtc->dev;
692 memset(best_clock, 0, sizeof(*best_clock));
694 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
696 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
698 for (clock.m2 = limit->m2.min;
699 clock.m2 <= limit->m2.max; clock.m2++) {
700 if (clock.m2 >= clock.m1)
702 for (clock.n = limit->n.min;
703 clock.n <= limit->n.max; clock.n++) {
704 for (clock.p1 = limit->p1.min;
705 clock.p1 <= limit->p1.max; clock.p1++) {
708 i9xx_calc_dpll_params(refclk, &clock);
709 if (!intel_PLL_is_valid(to_i915(dev),
714 clock.p != match_clock->p)
717 this_err = abs(clock.dot - target);
718 if (this_err < err) {
727 return (err != target);
731 * Returns a set of divisors for the desired target clock with the given
732 * refclk, or FALSE. The returned values represent the clock equation:
733 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
735 * Target and reference clocks are specified in kHz.
737 * If match_clock is provided, then best_clock P divider must match the P
738 * divider from @match_clock used for LVDS downclocking.
741 pnv_find_best_dpll(const struct intel_limit *limit,
742 struct intel_crtc_state *crtc_state,
743 int target, int refclk, struct dpll *match_clock,
744 struct dpll *best_clock)
746 struct drm_device *dev = crtc_state->base.crtc->dev;
750 memset(best_clock, 0, sizeof(*best_clock));
752 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
754 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
756 for (clock.m2 = limit->m2.min;
757 clock.m2 <= limit->m2.max; clock.m2++) {
758 for (clock.n = limit->n.min;
759 clock.n <= limit->n.max; clock.n++) {
760 for (clock.p1 = limit->p1.min;
761 clock.p1 <= limit->p1.max; clock.p1++) {
764 pnv_calc_dpll_params(refclk, &clock);
765 if (!intel_PLL_is_valid(to_i915(dev),
770 clock.p != match_clock->p)
773 this_err = abs(clock.dot - target);
774 if (this_err < err) {
783 return (err != target);
787 * Returns a set of divisors for the desired target clock with the given
788 * refclk, or FALSE. The returned values represent the clock equation:
789 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
791 * Target and reference clocks are specified in kHz.
793 * If match_clock is provided, then best_clock P divider must match the P
794 * divider from @match_clock used for LVDS downclocking.
797 g4x_find_best_dpll(const struct intel_limit *limit,
798 struct intel_crtc_state *crtc_state,
799 int target, int refclk, struct dpll *match_clock,
800 struct dpll *best_clock)
802 struct drm_device *dev = crtc_state->base.crtc->dev;
806 /* approximately equals target * 0.00585 */
807 int err_most = (target >> 8) + (target >> 9);
809 memset(best_clock, 0, sizeof(*best_clock));
811 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
813 max_n = limit->n.max;
814 /* based on hardware requirement, prefer smaller n to precision */
815 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
816 /* based on hardware requirement, prefere larger m1,m2 */
817 for (clock.m1 = limit->m1.max;
818 clock.m1 >= limit->m1.min; clock.m1--) {
819 for (clock.m2 = limit->m2.max;
820 clock.m2 >= limit->m2.min; clock.m2--) {
821 for (clock.p1 = limit->p1.max;
822 clock.p1 >= limit->p1.min; clock.p1--) {
825 i9xx_calc_dpll_params(refclk, &clock);
826 if (!intel_PLL_is_valid(to_i915(dev),
831 this_err = abs(clock.dot - target);
832 if (this_err < err_most) {
846 * Check if the calculated PLL configuration is more optimal compared to the
847 * best configuration and error found so far. Return the calculated error.
849 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
850 const struct dpll *calculated_clock,
851 const struct dpll *best_clock,
852 unsigned int best_error_ppm,
853 unsigned int *error_ppm)
856 * For CHV ignore the error and consider only the P value.
857 * Prefer a bigger P value based on HW requirements.
859 if (IS_CHERRYVIEW(to_i915(dev))) {
862 return calculated_clock->p > best_clock->p;
865 if (WARN_ON_ONCE(!target_freq))
868 *error_ppm = div_u64(1000000ULL *
869 abs(target_freq - calculated_clock->dot),
872 * Prefer a better P value over a better (smaller) error if the error
873 * is small. Ensure this preference for future configurations too by
874 * setting the error to 0.
876 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
882 return *error_ppm + 10 < best_error_ppm;
886 * Returns a set of divisors for the desired target clock with the given
887 * refclk, or FALSE. The returned values represent the clock equation:
888 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
891 vlv_find_best_dpll(const struct intel_limit *limit,
892 struct intel_crtc_state *crtc_state,
893 int target, int refclk, struct dpll *match_clock,
894 struct dpll *best_clock)
896 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
897 struct drm_device *dev = crtc->base.dev;
899 unsigned int bestppm = 1000000;
900 /* min update 19.2 MHz */
901 int max_n = min(limit->n.max, refclk / 19200);
904 target *= 5; /* fast clock */
906 memset(best_clock, 0, sizeof(*best_clock));
908 /* based on hardware requirement, prefer smaller n to precision */
909 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
910 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
911 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
912 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
913 clock.p = clock.p1 * clock.p2;
914 /* based on hardware requirement, prefer bigger m1,m2 values */
915 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
918 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
921 vlv_calc_dpll_params(refclk, &clock);
923 if (!intel_PLL_is_valid(to_i915(dev),
928 if (!vlv_PLL_is_optimal(dev, target,
946 * Returns a set of divisors for the desired target clock with the given
947 * refclk, or FALSE. The returned values represent the clock equation:
948 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
951 chv_find_best_dpll(const struct intel_limit *limit,
952 struct intel_crtc_state *crtc_state,
953 int target, int refclk, struct dpll *match_clock,
954 struct dpll *best_clock)
956 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
957 struct drm_device *dev = crtc->base.dev;
958 unsigned int best_error_ppm;
963 memset(best_clock, 0, sizeof(*best_clock));
964 best_error_ppm = 1000000;
967 * Based on hardware doc, the n always set to 1, and m1 always
968 * set to 2. If requires to support 200Mhz refclk, we need to
969 * revisit this because n may not 1 anymore.
971 clock.n = 1, clock.m1 = 2;
972 target *= 5; /* fast clock */
974 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
975 for (clock.p2 = limit->p2.p2_fast;
976 clock.p2 >= limit->p2.p2_slow;
977 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
978 unsigned int error_ppm;
980 clock.p = clock.p1 * clock.p2;
982 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
983 clock.n) << 22, refclk * clock.m1);
985 if (m2 > INT_MAX/clock.m1)
990 chv_calc_dpll_params(refclk, &clock);
992 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
995 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
996 best_error_ppm, &error_ppm))
1000 best_error_ppm = error_ppm;
1008 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
1009 struct dpll *best_clock)
1011 int refclk = 100000;
1012 const struct intel_limit *limit = &intel_limits_bxt;
1014 return chv_find_best_dpll(limit, crtc_state,
1015 target_clock, refclk, NULL, best_clock);
1018 bool intel_crtc_active(struct intel_crtc *crtc)
1020 /* Be paranoid as we can arrive here with only partial
1021 * state retrieved from the hardware during setup.
1023 * We can ditch the adjusted_mode.crtc_clock check as soon
1024 * as Haswell has gained clock readout/fastboot support.
1026 * We can ditch the crtc->primary->state->fb check as soon as we can
1027 * properly reconstruct framebuffers.
1029 * FIXME: The intel_crtc->active here should be switched to
1030 * crtc->state->active once we have proper CRTC states wired up
1033 return crtc->active && crtc->base.primary->state->fb &&
1034 crtc->config->base.adjusted_mode.crtc_clock;
1037 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
1040 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1042 return crtc->config->cpu_transcoder;
1045 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1048 i915_reg_t reg = PIPEDSL(pipe);
1052 if (IS_GEN2(dev_priv))
1053 line_mask = DSL_LINEMASK_GEN2;
1055 line_mask = DSL_LINEMASK_GEN3;
1057 line1 = I915_READ(reg) & line_mask;
1059 line2 = I915_READ(reg) & line_mask;
1061 return line1 != line2;
1064 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1066 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1067 enum pipe pipe = crtc->pipe;
1069 /* Wait for the display line to settle/start moving */
1070 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1071 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1072 pipe_name(pipe), onoff(state));
1075 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1077 wait_for_pipe_scanline_moving(crtc, false);
1080 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1082 wait_for_pipe_scanline_moving(crtc, true);
1086 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1088 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1089 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1091 if (INTEL_GEN(dev_priv) >= 4) {
1092 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1093 i915_reg_t reg = PIPECONF(cpu_transcoder);
1095 /* Wait for the Pipe State to go off */
1096 if (intel_wait_for_register(dev_priv,
1097 reg, I965_PIPECONF_ACTIVE, 0,
1099 WARN(1, "pipe_off wait timed out\n");
1101 intel_wait_for_pipe_scanline_stopped(crtc);
1105 /* Only for pre-ILK configs */
1106 void assert_pll(struct drm_i915_private *dev_priv,
1107 enum pipe pipe, bool state)
1112 val = I915_READ(DPLL(pipe));
1113 cur_state = !!(val & DPLL_VCO_ENABLE);
1114 I915_STATE_WARN(cur_state != state,
1115 "PLL state assertion failure (expected %s, current %s)\n",
1116 onoff(state), onoff(cur_state));
1119 /* XXX: the dsi pll is shared between MIPI DSI ports */
1120 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1125 mutex_lock(&dev_priv->sb_lock);
1126 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1127 mutex_unlock(&dev_priv->sb_lock);
1129 cur_state = val & DSI_PLL_VCO_EN;
1130 I915_STATE_WARN(cur_state != state,
1131 "DSI PLL state assertion failure (expected %s, current %s)\n",
1132 onoff(state), onoff(cur_state));
1135 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1136 enum pipe pipe, bool state)
1139 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1142 if (HAS_DDI(dev_priv)) {
1143 /* DDI does not have a specific FDI_TX register */
1144 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1145 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1147 u32 val = I915_READ(FDI_TX_CTL(pipe));
1148 cur_state = !!(val & FDI_TX_ENABLE);
1150 I915_STATE_WARN(cur_state != state,
1151 "FDI TX state assertion failure (expected %s, current %s)\n",
1152 onoff(state), onoff(cur_state));
1154 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1155 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1157 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1158 enum pipe pipe, bool state)
1163 val = I915_READ(FDI_RX_CTL(pipe));
1164 cur_state = !!(val & FDI_RX_ENABLE);
1165 I915_STATE_WARN(cur_state != state,
1166 "FDI RX state assertion failure (expected %s, current %s)\n",
1167 onoff(state), onoff(cur_state));
1169 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1170 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1172 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1177 /* ILK FDI PLL is always enabled */
1178 if (IS_GEN5(dev_priv))
1181 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1182 if (HAS_DDI(dev_priv))
1185 val = I915_READ(FDI_TX_CTL(pipe));
1186 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1189 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1190 enum pipe pipe, bool state)
1195 val = I915_READ(FDI_RX_CTL(pipe));
1196 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1197 I915_STATE_WARN(cur_state != state,
1198 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1199 onoff(state), onoff(cur_state));
1202 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1206 enum pipe panel_pipe = INVALID_PIPE;
1209 if (WARN_ON(HAS_DDI(dev_priv)))
1212 if (HAS_PCH_SPLIT(dev_priv)) {
1215 pp_reg = PP_CONTROL(0);
1216 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1219 case PANEL_PORT_SELECT_LVDS:
1220 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1222 case PANEL_PORT_SELECT_DPA:
1223 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1225 case PANEL_PORT_SELECT_DPC:
1226 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1228 case PANEL_PORT_SELECT_DPD:
1229 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1232 MISSING_CASE(port_sel);
1235 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1236 /* presumably write lock depends on pipe, not port select */
1237 pp_reg = PP_CONTROL(pipe);
1242 pp_reg = PP_CONTROL(0);
1243 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1245 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1246 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1249 val = I915_READ(pp_reg);
1250 if (!(val & PANEL_POWER_ON) ||
1251 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1254 I915_STATE_WARN(panel_pipe == pipe && locked,
1255 "panel assertion failure, pipe %c regs locked\n",
1259 void assert_pipe(struct drm_i915_private *dev_priv,
1260 enum pipe pipe, bool state)
1263 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1265 enum intel_display_power_domain power_domain;
1267 /* we keep both pipes enabled on 830 */
1268 if (IS_I830(dev_priv))
1271 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1272 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
1273 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1274 cur_state = !!(val & PIPECONF_ENABLE);
1276 intel_display_power_put(dev_priv, power_domain);
1281 I915_STATE_WARN(cur_state != state,
1282 "pipe %c assertion failure (expected %s, current %s)\n",
1283 pipe_name(pipe), onoff(state), onoff(cur_state));
1286 static void assert_plane(struct intel_plane *plane, bool state)
1291 cur_state = plane->get_hw_state(plane, &pipe);
1293 I915_STATE_WARN(cur_state != state,
1294 "%s assertion failure (expected %s, current %s)\n",
1295 plane->base.name, onoff(state), onoff(cur_state));
1298 #define assert_plane_enabled(p) assert_plane(p, true)
1299 #define assert_plane_disabled(p) assert_plane(p, false)
1301 static void assert_planes_disabled(struct intel_crtc *crtc)
1303 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1304 struct intel_plane *plane;
1306 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1307 assert_plane_disabled(plane);
1310 static void assert_vblank_disabled(struct drm_crtc *crtc)
1312 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1313 drm_crtc_vblank_put(crtc);
1316 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1322 val = I915_READ(PCH_TRANSCONF(pipe));
1323 enabled = !!(val & TRANS_ENABLE);
1324 I915_STATE_WARN(enabled,
1325 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1329 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1330 enum pipe pipe, enum port port,
1333 enum pipe port_pipe;
1336 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1338 I915_STATE_WARN(state && port_pipe == pipe,
1339 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1340 port_name(port), pipe_name(pipe));
1342 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1343 "IBX PCH DP %c still using transcoder B\n",
1347 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1348 enum pipe pipe, enum port port,
1349 i915_reg_t hdmi_reg)
1351 enum pipe port_pipe;
1354 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1356 I915_STATE_WARN(state && port_pipe == pipe,
1357 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1358 port_name(port), pipe_name(pipe));
1360 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1361 "IBX PCH HDMI %c still using transcoder B\n",
1365 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1368 enum pipe port_pipe;
1370 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1371 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1372 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1374 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1376 "PCH VGA enabled on transcoder %c, should be disabled\n",
1379 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1381 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1384 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1385 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1386 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1389 static void _vlv_enable_pll(struct intel_crtc *crtc,
1390 const struct intel_crtc_state *pipe_config)
1392 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1393 enum pipe pipe = crtc->pipe;
1395 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1396 POSTING_READ(DPLL(pipe));
1399 if (intel_wait_for_register(dev_priv,
1404 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1407 static void vlv_enable_pll(struct intel_crtc *crtc,
1408 const struct intel_crtc_state *pipe_config)
1410 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1411 enum pipe pipe = crtc->pipe;
1413 assert_pipe_disabled(dev_priv, pipe);
1415 /* PLL is protected by panel, make sure we can write it */
1416 assert_panel_unlocked(dev_priv, pipe);
1418 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1419 _vlv_enable_pll(crtc, pipe_config);
1421 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1422 POSTING_READ(DPLL_MD(pipe));
1426 static void _chv_enable_pll(struct intel_crtc *crtc,
1427 const struct intel_crtc_state *pipe_config)
1429 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1430 enum pipe pipe = crtc->pipe;
1431 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1434 mutex_lock(&dev_priv->sb_lock);
1436 /* Enable back the 10bit clock to display controller */
1437 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1438 tmp |= DPIO_DCLKP_EN;
1439 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1441 mutex_unlock(&dev_priv->sb_lock);
1444 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1449 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1451 /* Check PLL is locked */
1452 if (intel_wait_for_register(dev_priv,
1453 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1455 DRM_ERROR("PLL %d failed to lock\n", pipe);
1458 static void chv_enable_pll(struct intel_crtc *crtc,
1459 const struct intel_crtc_state *pipe_config)
1461 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1462 enum pipe pipe = crtc->pipe;
1464 assert_pipe_disabled(dev_priv, pipe);
1466 /* PLL is protected by panel, make sure we can write it */
1467 assert_panel_unlocked(dev_priv, pipe);
1469 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1470 _chv_enable_pll(crtc, pipe_config);
1472 if (pipe != PIPE_A) {
1474 * WaPixelRepeatModeFixForC0:chv
1476 * DPLLCMD is AWOL. Use chicken bits to propagate
1477 * the value from DPLLBMD to either pipe B or C.
1479 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1480 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1481 I915_WRITE(CBR4_VLV, 0);
1482 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1485 * DPLLB VGA mode also seems to cause problems.
1486 * We should always have it disabled.
1488 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1490 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1491 POSTING_READ(DPLL_MD(pipe));
1495 static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
1497 struct intel_crtc *crtc;
1500 for_each_intel_crtc(&dev_priv->drm, crtc) {
1501 count += crtc->base.state->active &&
1502 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1508 static void i9xx_enable_pll(struct intel_crtc *crtc,
1509 const struct intel_crtc_state *crtc_state)
1511 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1512 i915_reg_t reg = DPLL(crtc->pipe);
1513 u32 dpll = crtc_state->dpll_hw_state.dpll;
1516 assert_pipe_disabled(dev_priv, crtc->pipe);
1518 /* PLL is protected by panel, make sure we can write it */
1519 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
1520 assert_panel_unlocked(dev_priv, crtc->pipe);
1522 /* Enable DVO 2x clock on both PLLs if necessary */
1523 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
1525 * It appears to be important that we don't enable this
1526 * for the current pipe before otherwise configuring the
1527 * PLL. No idea how this should be handled if multiple
1528 * DVO outputs are enabled simultaneosly.
1530 dpll |= DPLL_DVO_2X_MODE;
1531 I915_WRITE(DPLL(!crtc->pipe),
1532 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1536 * Apparently we need to have VGA mode enabled prior to changing
1537 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1538 * dividers, even though the register value does change.
1542 I915_WRITE(reg, dpll);
1544 /* Wait for the clocks to stabilize. */
1548 if (INTEL_GEN(dev_priv) >= 4) {
1549 I915_WRITE(DPLL_MD(crtc->pipe),
1550 crtc_state->dpll_hw_state.dpll_md);
1552 /* The pixel multiplier can only be updated once the
1553 * DPLL is enabled and the clocks are stable.
1555 * So write it again.
1557 I915_WRITE(reg, dpll);
1560 /* We do this three times for luck */
1561 for (i = 0; i < 3; i++) {
1562 I915_WRITE(reg, dpll);
1564 udelay(150); /* wait for warmup */
1568 static void i9xx_disable_pll(struct intel_crtc *crtc)
1570 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1571 enum pipe pipe = crtc->pipe;
1573 /* Disable DVO 2x clock on both PLLs if necessary */
1574 if (IS_I830(dev_priv) &&
1575 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) &&
1576 !intel_num_dvo_pipes(dev_priv)) {
1577 I915_WRITE(DPLL(PIPE_B),
1578 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1579 I915_WRITE(DPLL(PIPE_A),
1580 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1583 /* Don't disable pipe or pipe PLLs if needed */
1584 if (IS_I830(dev_priv))
1587 /* Make sure the pipe isn't still relying on us */
1588 assert_pipe_disabled(dev_priv, pipe);
1590 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1591 POSTING_READ(DPLL(pipe));
1594 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1598 /* Make sure the pipe isn't still relying on us */
1599 assert_pipe_disabled(dev_priv, pipe);
1601 val = DPLL_INTEGRATED_REF_CLK_VLV |
1602 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1604 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1606 I915_WRITE(DPLL(pipe), val);
1607 POSTING_READ(DPLL(pipe));
1610 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1612 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1615 /* Make sure the pipe isn't still relying on us */
1616 assert_pipe_disabled(dev_priv, pipe);
1618 val = DPLL_SSC_REF_CLK_CHV |
1619 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1621 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1623 I915_WRITE(DPLL(pipe), val);
1624 POSTING_READ(DPLL(pipe));
1626 mutex_lock(&dev_priv->sb_lock);
1628 /* Disable 10bit clock to display controller */
1629 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1630 val &= ~DPIO_DCLKP_EN;
1631 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1633 mutex_unlock(&dev_priv->sb_lock);
1636 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1637 struct intel_digital_port *dport,
1638 unsigned int expected_mask)
1641 i915_reg_t dpll_reg;
1643 switch (dport->base.port) {
1645 port_mask = DPLL_PORTB_READY_MASK;
1649 port_mask = DPLL_PORTC_READY_MASK;
1651 expected_mask <<= 4;
1654 port_mask = DPLL_PORTD_READY_MASK;
1655 dpll_reg = DPIO_PHY_STATUS;
1661 if (intel_wait_for_register(dev_priv,
1662 dpll_reg, port_mask, expected_mask,
1664 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1665 port_name(dport->base.port),
1666 I915_READ(dpll_reg) & port_mask, expected_mask);
1669 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1672 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
1675 uint32_t val, pipeconf_val;
1677 /* Make sure PCH DPLL is enabled */
1678 assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll);
1680 /* FDI must be feeding us bits for PCH ports */
1681 assert_fdi_tx_enabled(dev_priv, pipe);
1682 assert_fdi_rx_enabled(dev_priv, pipe);
1684 if (HAS_PCH_CPT(dev_priv)) {
1685 /* Workaround: Set the timing override bit before enabling the
1686 * pch transcoder. */
1687 reg = TRANS_CHICKEN2(pipe);
1688 val = I915_READ(reg);
1689 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1690 I915_WRITE(reg, val);
1693 reg = PCH_TRANSCONF(pipe);
1694 val = I915_READ(reg);
1695 pipeconf_val = I915_READ(PIPECONF(pipe));
1697 if (HAS_PCH_IBX(dev_priv)) {
1699 * Make the BPC in transcoder be consistent with
1700 * that in pipeconf reg. For HDMI we must use 8bpc
1701 * here for both 8bpc and 12bpc.
1703 val &= ~PIPECONF_BPC_MASK;
1704 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI))
1705 val |= PIPECONF_8BPC;
1707 val |= pipeconf_val & PIPECONF_BPC_MASK;
1710 val &= ~TRANS_INTERLACE_MASK;
1711 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1712 if (HAS_PCH_IBX(dev_priv) &&
1713 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
1714 val |= TRANS_LEGACY_INTERLACED_ILK;
1716 val |= TRANS_INTERLACED;
1718 val |= TRANS_PROGRESSIVE;
1720 I915_WRITE(reg, val | TRANS_ENABLE);
1721 if (intel_wait_for_register(dev_priv,
1722 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1724 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1727 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1728 enum transcoder cpu_transcoder)
1730 u32 val, pipeconf_val;
1732 /* FDI must be feeding us bits for PCH ports */
1733 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1734 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1736 /* Workaround: set timing override bit. */
1737 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1738 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1739 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1742 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1744 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1745 PIPECONF_INTERLACED_ILK)
1746 val |= TRANS_INTERLACED;
1748 val |= TRANS_PROGRESSIVE;
1750 I915_WRITE(LPT_TRANSCONF, val);
1751 if (intel_wait_for_register(dev_priv,
1756 DRM_ERROR("Failed to enable PCH transcoder\n");
1759 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1765 /* FDI relies on the transcoder */
1766 assert_fdi_tx_disabled(dev_priv, pipe);
1767 assert_fdi_rx_disabled(dev_priv, pipe);
1769 /* Ports must be off as well */
1770 assert_pch_ports_disabled(dev_priv, pipe);
1772 reg = PCH_TRANSCONF(pipe);
1773 val = I915_READ(reg);
1774 val &= ~TRANS_ENABLE;
1775 I915_WRITE(reg, val);
1776 /* wait for PCH transcoder off, transcoder state */
1777 if (intel_wait_for_register(dev_priv,
1778 reg, TRANS_STATE_ENABLE, 0,
1780 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1782 if (HAS_PCH_CPT(dev_priv)) {
1783 /* Workaround: Clear the timing override chicken bit again. */
1784 reg = TRANS_CHICKEN2(pipe);
1785 val = I915_READ(reg);
1786 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1787 I915_WRITE(reg, val);
1791 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1795 val = I915_READ(LPT_TRANSCONF);
1796 val &= ~TRANS_ENABLE;
1797 I915_WRITE(LPT_TRANSCONF, val);
1798 /* wait for PCH transcoder off, transcoder state */
1799 if (intel_wait_for_register(dev_priv,
1800 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1802 DRM_ERROR("Failed to disable PCH transcoder\n");
1804 /* Workaround: clear timing override bit. */
1805 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1806 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1807 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1810 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1812 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1814 if (HAS_PCH_LPT(dev_priv))
1820 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1822 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1823 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1824 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1825 enum pipe pipe = crtc->pipe;
1829 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1831 assert_planes_disabled(crtc);
1834 * A pipe without a PLL won't actually be able to drive bits from
1835 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1838 if (HAS_GMCH_DISPLAY(dev_priv)) {
1839 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1840 assert_dsi_pll_enabled(dev_priv);
1842 assert_pll_enabled(dev_priv, pipe);
1844 if (new_crtc_state->has_pch_encoder) {
1845 /* if driving the PCH, we need FDI enabled */
1846 assert_fdi_rx_pll_enabled(dev_priv,
1847 intel_crtc_pch_transcoder(crtc));
1848 assert_fdi_tx_pll_enabled(dev_priv,
1849 (enum pipe) cpu_transcoder);
1851 /* FIXME: assert CPU port conditions for SNB+ */
1854 reg = PIPECONF(cpu_transcoder);
1855 val = I915_READ(reg);
1856 if (val & PIPECONF_ENABLE) {
1857 /* we keep both pipes enabled on 830 */
1858 WARN_ON(!IS_I830(dev_priv));
1862 I915_WRITE(reg, val | PIPECONF_ENABLE);
1866 * Until the pipe starts PIPEDSL reads will return a stale value,
1867 * which causes an apparent vblank timestamp jump when PIPEDSL
1868 * resets to its proper value. That also messes up the frame count
1869 * when it's derived from the timestamps. So let's wait for the
1870 * pipe to start properly before we call drm_crtc_vblank_on()
1872 if (dev_priv->drm.max_vblank_count == 0)
1873 intel_wait_for_pipe_scanline_moving(crtc);
1876 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1878 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1879 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1880 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1881 enum pipe pipe = crtc->pipe;
1885 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1888 * Make sure planes won't keep trying to pump pixels to us,
1889 * or we might hang the display.
1891 assert_planes_disabled(crtc);
1893 reg = PIPECONF(cpu_transcoder);
1894 val = I915_READ(reg);
1895 if ((val & PIPECONF_ENABLE) == 0)
1899 * Double wide has implications for planes
1900 * so best keep it disabled when not needed.
1902 if (old_crtc_state->double_wide)
1903 val &= ~PIPECONF_DOUBLE_WIDE;
1905 /* Don't disable pipe or pipe PLLs if needed */
1906 if (!IS_I830(dev_priv))
1907 val &= ~PIPECONF_ENABLE;
1909 I915_WRITE(reg, val);
1910 if ((val & PIPECONF_ENABLE) == 0)
1911 intel_wait_for_pipe_off(old_crtc_state);
1914 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1916 return IS_GEN2(dev_priv) ? 2048 : 4096;
1920 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1922 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1923 unsigned int cpp = fb->format->cpp[color_plane];
1925 switch (fb->modifier) {
1926 case DRM_FORMAT_MOD_LINEAR:
1928 case I915_FORMAT_MOD_X_TILED:
1929 if (IS_GEN2(dev_priv))
1933 case I915_FORMAT_MOD_Y_TILED_CCS:
1934 if (color_plane == 1)
1937 case I915_FORMAT_MOD_Y_TILED:
1938 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1942 case I915_FORMAT_MOD_Yf_TILED_CCS:
1943 if (color_plane == 1)
1946 case I915_FORMAT_MOD_Yf_TILED:
1962 MISSING_CASE(fb->modifier);
1968 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
1970 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
1973 return intel_tile_size(to_i915(fb->dev)) /
1974 intel_tile_width_bytes(fb, color_plane);
1977 /* Return the tile dimensions in pixel units */
1978 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
1979 unsigned int *tile_width,
1980 unsigned int *tile_height)
1982 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1983 unsigned int cpp = fb->format->cpp[color_plane];
1985 *tile_width = tile_width_bytes / cpp;
1986 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1990 intel_fb_align_height(const struct drm_framebuffer *fb,
1991 int color_plane, unsigned int height)
1993 unsigned int tile_height = intel_tile_height(fb, color_plane);
1995 return ALIGN(height, tile_height);
1998 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2000 unsigned int size = 0;
2003 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2004 size += rot_info->plane[i].width * rot_info->plane[i].height;
2010 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2011 const struct drm_framebuffer *fb,
2012 unsigned int rotation)
2014 view->type = I915_GGTT_VIEW_NORMAL;
2015 if (drm_rotation_90_or_270(rotation)) {
2016 view->type = I915_GGTT_VIEW_ROTATED;
2017 view->rotated = to_intel_framebuffer(fb)->rot_info;
2021 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2023 if (IS_I830(dev_priv))
2025 else if (IS_I85X(dev_priv))
2027 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2033 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2035 if (INTEL_GEN(dev_priv) >= 9)
2037 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2038 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2040 else if (INTEL_GEN(dev_priv) >= 4)
2046 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2049 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2051 /* AUX_DIST needs only 4K alignment */
2052 if (color_plane == 1)
2055 switch (fb->modifier) {
2056 case DRM_FORMAT_MOD_LINEAR:
2057 return intel_linear_alignment(dev_priv);
2058 case I915_FORMAT_MOD_X_TILED:
2059 if (INTEL_GEN(dev_priv) >= 9)
2062 case I915_FORMAT_MOD_Y_TILED_CCS:
2063 case I915_FORMAT_MOD_Yf_TILED_CCS:
2064 case I915_FORMAT_MOD_Y_TILED:
2065 case I915_FORMAT_MOD_Yf_TILED:
2066 return 1 * 1024 * 1024;
2068 MISSING_CASE(fb->modifier);
2073 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2075 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2076 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2078 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
2082 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2083 const struct i915_ggtt_view *view,
2085 unsigned long *out_flags)
2087 struct drm_device *dev = fb->dev;
2088 struct drm_i915_private *dev_priv = to_i915(dev);
2089 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2090 struct i915_vma *vma;
2091 unsigned int pinctl;
2094 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2096 alignment = intel_surf_alignment(fb, 0);
2098 /* Note that the w/a also requires 64 PTE of padding following the
2099 * bo. We currently fill all unused PTE with the shadow page and so
2100 * we should always have valid PTE following the scanout preventing
2103 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2104 alignment = 256 * 1024;
2107 * Global gtt pte registers are special registers which actually forward
2108 * writes to a chunk of system memory. Which means that there is no risk
2109 * that the register values disappear as soon as we call
2110 * intel_runtime_pm_put(), so it is correct to wrap only the
2111 * pin/unpin/fence and not more.
2113 intel_runtime_pm_get(dev_priv);
2115 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2119 /* Valleyview is definitely limited to scanning out the first
2120 * 512MiB. Lets presume this behaviour was inherited from the
2121 * g4x display engine and that all earlier gen are similarly
2122 * limited. Testing suggests that it is a little more
2123 * complicated than this. For example, Cherryview appears quite
2124 * happy to scanout from anywhere within its global aperture.
2126 if (HAS_GMCH_DISPLAY(dev_priv))
2127 pinctl |= PIN_MAPPABLE;
2129 vma = i915_gem_object_pin_to_display_plane(obj,
2130 alignment, view, pinctl);
2134 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2137 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2138 * fence, whereas 965+ only requires a fence if using
2139 * framebuffer compression. For simplicity, we always, when
2140 * possible, install a fence as the cost is not that onerous.
2142 * If we fail to fence the tiled scanout, then either the
2143 * modeset will reject the change (which is highly unlikely as
2144 * the affected systems, all but one, do not have unmappable
2145 * space) or we will not be able to enable full powersaving
2146 * techniques (also likely not to apply due to various limits
2147 * FBC and the like impose on the size of the buffer, which
2148 * presumably we violated anyway with this unmappable buffer).
2149 * Anyway, it is presumably better to stumble onwards with
2150 * something and try to run the system in a "less than optimal"
2151 * mode that matches the user configuration.
2153 ret = i915_vma_pin_fence(vma);
2154 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2155 i915_gem_object_unpin_from_display_plane(vma);
2160 if (ret == 0 && vma->fence)
2161 *out_flags |= PLANE_HAS_FENCE;
2166 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2168 intel_runtime_pm_put(dev_priv);
2172 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2174 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2176 if (flags & PLANE_HAS_FENCE)
2177 i915_vma_unpin_fence(vma);
2178 i915_gem_object_unpin_from_display_plane(vma);
2182 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2183 unsigned int rotation)
2185 if (drm_rotation_90_or_270(rotation))
2186 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2188 return fb->pitches[color_plane];
2192 * Convert the x/y offsets into a linear offset.
2193 * Only valid with 0/180 degree rotation, which is fine since linear
2194 * offset is only used with linear buffers on pre-hsw and tiled buffers
2195 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2197 u32 intel_fb_xy_to_linear(int x, int y,
2198 const struct intel_plane_state *state,
2201 const struct drm_framebuffer *fb = state->base.fb;
2202 unsigned int cpp = fb->format->cpp[color_plane];
2203 unsigned int pitch = state->color_plane[color_plane].stride;
2205 return y * pitch + x * cpp;
2209 * Add the x/y offsets derived from fb->offsets[] to the user
2210 * specified plane src x/y offsets. The resulting x/y offsets
2211 * specify the start of scanout from the beginning of the gtt mapping.
2213 void intel_add_fb_offsets(int *x, int *y,
2214 const struct intel_plane_state *state,
2218 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2219 unsigned int rotation = state->base.rotation;
2221 if (drm_rotation_90_or_270(rotation)) {
2222 *x += intel_fb->rotated[color_plane].x;
2223 *y += intel_fb->rotated[color_plane].y;
2225 *x += intel_fb->normal[color_plane].x;
2226 *y += intel_fb->normal[color_plane].y;
2230 static u32 intel_adjust_tile_offset(int *x, int *y,
2231 unsigned int tile_width,
2232 unsigned int tile_height,
2233 unsigned int tile_size,
2234 unsigned int pitch_tiles,
2238 unsigned int pitch_pixels = pitch_tiles * tile_width;
2241 WARN_ON(old_offset & (tile_size - 1));
2242 WARN_ON(new_offset & (tile_size - 1));
2243 WARN_ON(new_offset > old_offset);
2245 tiles = (old_offset - new_offset) / tile_size;
2247 *y += tiles / pitch_tiles * tile_height;
2248 *x += tiles % pitch_tiles * tile_width;
2250 /* minimize x in case it got needlessly big */
2251 *y += *x / pitch_pixels * tile_height;
2257 static u32 intel_adjust_aligned_offset(int *x, int *y,
2258 const struct drm_framebuffer *fb,
2260 unsigned int rotation,
2262 u32 old_offset, u32 new_offset)
2264 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2265 unsigned int cpp = fb->format->cpp[color_plane];
2267 WARN_ON(new_offset > old_offset);
2269 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2270 unsigned int tile_size, tile_width, tile_height;
2271 unsigned int pitch_tiles;
2273 tile_size = intel_tile_size(dev_priv);
2274 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2276 if (drm_rotation_90_or_270(rotation)) {
2277 pitch_tiles = pitch / tile_height;
2278 swap(tile_width, tile_height);
2280 pitch_tiles = pitch / (tile_width * cpp);
2283 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2284 tile_size, pitch_tiles,
2285 old_offset, new_offset);
2287 old_offset += *y * pitch + *x * cpp;
2289 *y = (old_offset - new_offset) / pitch;
2290 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2297 * Adjust the tile offset by moving the difference into
2300 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2301 const struct intel_plane_state *state,
2303 u32 old_offset, u32 new_offset)
2305 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
2306 state->base.rotation,
2307 state->color_plane[color_plane].stride,
2308 old_offset, new_offset);
2312 * Computes the aligned offset to the base tile and adjusts
2313 * x, y. bytes per pixel is assumed to be a power-of-two.
2315 * In the 90/270 rotated case, x and y are assumed
2316 * to be already rotated to match the rotated GTT view, and
2317 * pitch is the tile_height aligned framebuffer height.
2319 * This function is used when computing the derived information
2320 * under intel_framebuffer, so using any of that information
2321 * here is not allowed. Anything under drm_framebuffer can be
2322 * used. This is why the user has to pass in the pitch since it
2323 * is specified in the rotated orientation.
2325 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2327 const struct drm_framebuffer *fb,
2330 unsigned int rotation,
2333 uint64_t fb_modifier = fb->modifier;
2334 unsigned int cpp = fb->format->cpp[color_plane];
2335 u32 offset, offset_aligned;
2340 if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
2341 unsigned int tile_size, tile_width, tile_height;
2342 unsigned int tile_rows, tiles, pitch_tiles;
2344 tile_size = intel_tile_size(dev_priv);
2345 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2347 if (drm_rotation_90_or_270(rotation)) {
2348 pitch_tiles = pitch / tile_height;
2349 swap(tile_width, tile_height);
2351 pitch_tiles = pitch / (tile_width * cpp);
2354 tile_rows = *y / tile_height;
2357 tiles = *x / tile_width;
2360 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2361 offset_aligned = offset & ~alignment;
2363 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2364 tile_size, pitch_tiles,
2365 offset, offset_aligned);
2367 offset = *y * pitch + *x * cpp;
2368 offset_aligned = offset & ~alignment;
2370 *y = (offset & alignment) / pitch;
2371 *x = ((offset & alignment) - *y * pitch) / cpp;
2374 return offset_aligned;
2377 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2378 const struct intel_plane_state *state,
2381 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2382 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2383 const struct drm_framebuffer *fb = state->base.fb;
2384 unsigned int rotation = state->base.rotation;
2385 int pitch = state->color_plane[color_plane].stride;
2388 if (intel_plane->id == PLANE_CURSOR)
2389 alignment = intel_cursor_alignment(dev_priv);
2391 alignment = intel_surf_alignment(fb, color_plane);
2393 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2394 pitch, rotation, alignment);
2397 /* Convert the fb->offset[] into x/y offsets */
2398 static int intel_fb_offset_to_xy(int *x, int *y,
2399 const struct drm_framebuffer *fb,
2402 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2404 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2405 fb->offsets[color_plane] % intel_tile_size(dev_priv))
2411 intel_adjust_aligned_offset(x, y,
2412 fb, color_plane, DRM_MODE_ROTATE_0,
2413 fb->pitches[color_plane],
2414 fb->offsets[color_plane], 0);
2419 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2421 switch (fb_modifier) {
2422 case I915_FORMAT_MOD_X_TILED:
2423 return I915_TILING_X;
2424 case I915_FORMAT_MOD_Y_TILED:
2425 case I915_FORMAT_MOD_Y_TILED_CCS:
2426 return I915_TILING_Y;
2428 return I915_TILING_NONE;
2433 * From the Sky Lake PRM:
2434 * "The Color Control Surface (CCS) contains the compression status of
2435 * the cache-line pairs. The compression state of the cache-line pair
2436 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2437 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2438 * cache-line-pairs. CCS is always Y tiled."
2440 * Since cache line pairs refers to horizontally adjacent cache lines,
2441 * each cache line in the CCS corresponds to an area of 32x16 cache
2442 * lines on the main surface. Since each pixel is 4 bytes, this gives
2443 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2446 static const struct drm_format_info ccs_formats[] = {
2447 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2448 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2449 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2450 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2453 static const struct drm_format_info *
2454 lookup_format_info(const struct drm_format_info formats[],
2455 int num_formats, u32 format)
2459 for (i = 0; i < num_formats; i++) {
2460 if (formats[i].format == format)
2467 static const struct drm_format_info *
2468 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2470 switch (cmd->modifier[0]) {
2471 case I915_FORMAT_MOD_Y_TILED_CCS:
2472 case I915_FORMAT_MOD_Yf_TILED_CCS:
2473 return lookup_format_info(ccs_formats,
2474 ARRAY_SIZE(ccs_formats),
2481 bool is_ccs_modifier(u64 modifier)
2483 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2484 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2488 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2489 struct drm_framebuffer *fb)
2491 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2492 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2493 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2494 u32 gtt_offset_rotated = 0;
2495 unsigned int max_size = 0;
2496 int i, num_planes = fb->format->num_planes;
2497 unsigned int tile_size = intel_tile_size(dev_priv);
2499 for (i = 0; i < num_planes; i++) {
2500 unsigned int width, height;
2501 unsigned int cpp, size;
2506 cpp = fb->format->cpp[i];
2507 width = drm_framebuffer_plane_width(fb->width, fb, i);
2508 height = drm_framebuffer_plane_height(fb->height, fb, i);
2510 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2512 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2517 if (is_ccs_modifier(fb->modifier) && i == 1) {
2518 int hsub = fb->format->hsub;
2519 int vsub = fb->format->vsub;
2520 int tile_width, tile_height;
2524 intel_tile_dims(fb, i, &tile_width, &tile_height);
2526 tile_height *= vsub;
2528 ccs_x = (x * hsub) % tile_width;
2529 ccs_y = (y * vsub) % tile_height;
2530 main_x = intel_fb->normal[0].x % tile_width;
2531 main_y = intel_fb->normal[0].y % tile_height;
2534 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2535 * x/y offsets must match between CCS and the main surface.
2537 if (main_x != ccs_x || main_y != ccs_y) {
2538 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2541 intel_fb->normal[0].x,
2542 intel_fb->normal[0].y,
2549 * The fence (if used) is aligned to the start of the object
2550 * so having the framebuffer wrap around across the edge of the
2551 * fenced region doesn't really work. We have no API to configure
2552 * the fence start offset within the object (nor could we probably
2553 * on gen2/3). So it's just easier if we just require that the
2554 * fb layout agrees with the fence layout. We already check that the
2555 * fb stride matches the fence stride elsewhere.
2557 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2558 (x + width) * cpp > fb->pitches[i]) {
2559 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2565 * First pixel of the framebuffer from
2566 * the start of the normal gtt mapping.
2568 intel_fb->normal[i].x = x;
2569 intel_fb->normal[i].y = y;
2571 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2575 offset /= tile_size;
2577 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2578 unsigned int tile_width, tile_height;
2579 unsigned int pitch_tiles;
2582 intel_tile_dims(fb, i, &tile_width, &tile_height);
2584 rot_info->plane[i].offset = offset;
2585 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2586 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2587 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2589 intel_fb->rotated[i].pitch =
2590 rot_info->plane[i].height * tile_height;
2592 /* how many tiles does this plane need */
2593 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2595 * If the plane isn't horizontally tile aligned,
2596 * we need one more tile.
2601 /* rotate the x/y offsets to match the GTT view */
2607 rot_info->plane[i].width * tile_width,
2608 rot_info->plane[i].height * tile_height,
2609 DRM_MODE_ROTATE_270);
2613 /* rotate the tile dimensions to match the GTT view */
2614 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2615 swap(tile_width, tile_height);
2618 * We only keep the x/y offsets, so push all of the
2619 * gtt offset into the x/y offsets.
2621 intel_adjust_tile_offset(&x, &y,
2622 tile_width, tile_height,
2623 tile_size, pitch_tiles,
2624 gtt_offset_rotated * tile_size, 0);
2626 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2629 * First pixel of the framebuffer from
2630 * the start of the rotated gtt mapping.
2632 intel_fb->rotated[i].x = x;
2633 intel_fb->rotated[i].y = y;
2635 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2636 x * cpp, tile_size);
2639 /* how many tiles in total needed in the bo */
2640 max_size = max(max_size, offset + size);
2643 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2644 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2645 mul_u32_u32(max_size, tile_size), obj->base.size);
2652 static int i9xx_format_to_fourcc(int format)
2655 case DISPPLANE_8BPP:
2656 return DRM_FORMAT_C8;
2657 case DISPPLANE_BGRX555:
2658 return DRM_FORMAT_XRGB1555;
2659 case DISPPLANE_BGRX565:
2660 return DRM_FORMAT_RGB565;
2662 case DISPPLANE_BGRX888:
2663 return DRM_FORMAT_XRGB8888;
2664 case DISPPLANE_RGBX888:
2665 return DRM_FORMAT_XBGR8888;
2666 case DISPPLANE_BGRX101010:
2667 return DRM_FORMAT_XRGB2101010;
2668 case DISPPLANE_RGBX101010:
2669 return DRM_FORMAT_XBGR2101010;
2673 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2676 case PLANE_CTL_FORMAT_RGB_565:
2677 return DRM_FORMAT_RGB565;
2678 case PLANE_CTL_FORMAT_NV12:
2679 return DRM_FORMAT_NV12;
2681 case PLANE_CTL_FORMAT_XRGB_8888:
2684 return DRM_FORMAT_ABGR8888;
2686 return DRM_FORMAT_XBGR8888;
2689 return DRM_FORMAT_ARGB8888;
2691 return DRM_FORMAT_XRGB8888;
2693 case PLANE_CTL_FORMAT_XRGB_2101010:
2695 return DRM_FORMAT_XBGR2101010;
2697 return DRM_FORMAT_XRGB2101010;
2702 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2703 struct intel_initial_plane_config *plane_config)
2705 struct drm_device *dev = crtc->base.dev;
2706 struct drm_i915_private *dev_priv = to_i915(dev);
2707 struct drm_i915_gem_object *obj = NULL;
2708 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2709 struct drm_framebuffer *fb = &plane_config->fb->base;
2710 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2711 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2714 size_aligned -= base_aligned;
2716 if (plane_config->size == 0)
2719 /* If the FB is too big, just don't use it since fbdev is not very
2720 * important and we should probably use that space with FBC or other
2722 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2725 switch (fb->modifier) {
2726 case DRM_FORMAT_MOD_LINEAR:
2727 case I915_FORMAT_MOD_X_TILED:
2728 case I915_FORMAT_MOD_Y_TILED:
2731 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2736 mutex_lock(&dev->struct_mutex);
2737 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2741 mutex_unlock(&dev->struct_mutex);
2745 switch (plane_config->tiling) {
2746 case I915_TILING_NONE:
2750 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2753 MISSING_CASE(plane_config->tiling);
2757 mode_cmd.pixel_format = fb->format->format;
2758 mode_cmd.width = fb->width;
2759 mode_cmd.height = fb->height;
2760 mode_cmd.pitches[0] = fb->pitches[0];
2761 mode_cmd.modifier[0] = fb->modifier;
2762 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2764 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2765 DRM_DEBUG_KMS("intel fb init failed\n");
2770 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2774 i915_gem_object_put(obj);
2779 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2780 struct intel_plane_state *plane_state,
2783 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2785 plane_state->base.visible = visible;
2788 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
2790 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
2792 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2793 crtc_state->base.crtc->name,
2794 crtc_state->active_planes);
2797 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2799 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2800 struct drm_plane *plane;
2803 * Active_planes aliases if multiple "primary" or cursor planes
2804 * have been used on the same (or wrong) pipe. plane_mask uses
2805 * unique ids, hence we can use that to reconstruct active_planes.
2807 crtc_state->active_planes = 0;
2809 drm_for_each_plane_mask(plane, &dev_priv->drm,
2810 crtc_state->base.plane_mask)
2811 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2814 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2815 struct intel_plane *plane)
2817 struct intel_crtc_state *crtc_state =
2818 to_intel_crtc_state(crtc->base.state);
2819 struct intel_plane_state *plane_state =
2820 to_intel_plane_state(plane->base.state);
2822 intel_set_plane_visible(crtc_state, plane_state, false);
2823 fixup_active_planes(crtc_state);
2825 if (plane->id == PLANE_PRIMARY)
2826 intel_pre_disable_primary_noatomic(&crtc->base);
2828 trace_intel_disable_plane(&plane->base, crtc);
2829 plane->disable_plane(plane, crtc);
2833 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2834 struct intel_initial_plane_config *plane_config)
2836 struct drm_device *dev = intel_crtc->base.dev;
2837 struct drm_i915_private *dev_priv = to_i915(dev);
2839 struct drm_i915_gem_object *obj;
2840 struct drm_plane *primary = intel_crtc->base.primary;
2841 struct drm_plane_state *plane_state = primary->state;
2842 struct intel_plane *intel_plane = to_intel_plane(primary);
2843 struct intel_plane_state *intel_state =
2844 to_intel_plane_state(plane_state);
2845 struct drm_framebuffer *fb;
2847 if (!plane_config->fb)
2850 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2851 fb = &plane_config->fb->base;
2855 kfree(plane_config->fb);
2858 * Failed to alloc the obj, check to see if we should share
2859 * an fb with another CRTC instead
2861 for_each_crtc(dev, c) {
2862 struct intel_plane_state *state;
2864 if (c == &intel_crtc->base)
2867 if (!to_intel_crtc(c)->active)
2870 state = to_intel_plane_state(c->primary->state);
2874 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2875 fb = state->base.fb;
2876 drm_framebuffer_get(fb);
2882 * We've failed to reconstruct the BIOS FB. Current display state
2883 * indicates that the primary plane is visible, but has a NULL FB,
2884 * which will lead to problems later if we don't fix it up. The
2885 * simplest solution is to just disable the primary plane now and
2886 * pretend the BIOS never had it enabled.
2888 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2893 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2894 intel_state->base.rotation);
2895 intel_state->color_plane[0].stride =
2896 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2898 mutex_lock(&dev->struct_mutex);
2900 intel_pin_and_fence_fb_obj(fb,
2902 intel_plane_uses_fence(intel_state),
2903 &intel_state->flags);
2904 mutex_unlock(&dev->struct_mutex);
2905 if (IS_ERR(intel_state->vma)) {
2906 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2907 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2909 intel_state->vma = NULL;
2910 drm_framebuffer_put(fb);
2914 obj = intel_fb_obj(fb);
2915 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2917 plane_state->src_x = 0;
2918 plane_state->src_y = 0;
2919 plane_state->src_w = fb->width << 16;
2920 plane_state->src_h = fb->height << 16;
2922 plane_state->crtc_x = 0;
2923 plane_state->crtc_y = 0;
2924 plane_state->crtc_w = fb->width;
2925 plane_state->crtc_h = fb->height;
2927 intel_state->base.src = drm_plane_state_src(plane_state);
2928 intel_state->base.dst = drm_plane_state_dest(plane_state);
2930 if (i915_gem_object_is_tiled(obj))
2931 dev_priv->preserve_bios_swizzle = true;
2933 plane_state->fb = fb;
2934 plane_state->crtc = &intel_crtc->base;
2936 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2937 &obj->frontbuffer_bits);
2940 static int skl_max_plane_width(const struct drm_framebuffer *fb,
2942 unsigned int rotation)
2944 int cpp = fb->format->cpp[color_plane];
2946 switch (fb->modifier) {
2947 case DRM_FORMAT_MOD_LINEAR:
2948 case I915_FORMAT_MOD_X_TILED:
2961 case I915_FORMAT_MOD_Y_TILED_CCS:
2962 case I915_FORMAT_MOD_Yf_TILED_CCS:
2963 /* FIXME AUX plane? */
2964 case I915_FORMAT_MOD_Y_TILED:
2965 case I915_FORMAT_MOD_Yf_TILED:
2980 MISSING_CASE(fb->modifier);
2986 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2987 int main_x, int main_y, u32 main_offset)
2989 const struct drm_framebuffer *fb = plane_state->base.fb;
2990 int hsub = fb->format->hsub;
2991 int vsub = fb->format->vsub;
2992 int aux_x = plane_state->color_plane[1].x;
2993 int aux_y = plane_state->color_plane[1].y;
2994 u32 aux_offset = plane_state->color_plane[1].offset;
2995 u32 alignment = intel_surf_alignment(fb, 1);
2997 while (aux_offset >= main_offset && aux_y <= main_y) {
3000 if (aux_x == main_x && aux_y == main_y)
3003 if (aux_offset == 0)
3008 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3009 aux_offset, aux_offset - alignment);
3010 aux_x = x * hsub + aux_x % hsub;
3011 aux_y = y * vsub + aux_y % vsub;
3014 if (aux_x != main_x || aux_y != main_y)
3017 plane_state->color_plane[1].offset = aux_offset;
3018 plane_state->color_plane[1].x = aux_x;
3019 plane_state->color_plane[1].y = aux_y;
3024 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3026 const struct drm_framebuffer *fb = plane_state->base.fb;
3027 unsigned int rotation = plane_state->base.rotation;
3028 int x = plane_state->base.src.x1 >> 16;
3029 int y = plane_state->base.src.y1 >> 16;
3030 int w = drm_rect_width(&plane_state->base.src) >> 16;
3031 int h = drm_rect_height(&plane_state->base.src) >> 16;
3032 int max_width = skl_max_plane_width(fb, 0, rotation);
3033 int max_height = 4096;
3034 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
3036 if (w > max_width || h > max_height) {
3037 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3038 w, h, max_width, max_height);
3042 intel_add_fb_offsets(&x, &y, plane_state, 0);
3043 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3044 alignment = intel_surf_alignment(fb, 0);
3047 * AUX surface offset is specified as the distance from the
3048 * main surface offset, and it must be non-negative. Make
3049 * sure that is what we will get.
3051 if (offset > aux_offset)
3052 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3053 offset, aux_offset & ~(alignment - 1));
3056 * When using an X-tiled surface, the plane blows up
3057 * if the x offset + width exceed the stride.
3059 * TODO: linear and Y-tiled seem fine, Yf untested,
3061 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3062 int cpp = fb->format->cpp[0];
3064 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3066 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3070 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3071 offset, offset - alignment);
3076 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3077 * they match with the main surface x/y offsets.
3079 if (is_ccs_modifier(fb->modifier)) {
3080 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3084 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3085 offset, offset - alignment);
3088 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3089 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3094 plane_state->color_plane[0].offset = offset;
3095 plane_state->color_plane[0].x = x;
3096 plane_state->color_plane[0].y = y;
3102 skl_check_nv12_surface(struct intel_plane_state *plane_state)
3104 /* Display WA #1106 */
3105 if (plane_state->base.rotation !=
3106 (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90) &&
3107 plane_state->base.rotation != DRM_MODE_ROTATE_270)
3111 * src coordinates are rotated here.
3112 * We check height but report it as width
3114 if (((drm_rect_height(&plane_state->base.src) >> 16) % 4) != 0) {
3115 DRM_DEBUG_KMS("src width must be multiple "
3116 "of 4 for rotated NV12\n");
3123 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3125 const struct drm_framebuffer *fb = plane_state->base.fb;
3126 unsigned int rotation = plane_state->base.rotation;
3127 int max_width = skl_max_plane_width(fb, 1, rotation);
3128 int max_height = 4096;
3129 int x = plane_state->base.src.x1 >> 17;
3130 int y = plane_state->base.src.y1 >> 17;
3131 int w = drm_rect_width(&plane_state->base.src) >> 17;
3132 int h = drm_rect_height(&plane_state->base.src) >> 17;
3135 intel_add_fb_offsets(&x, &y, plane_state, 1);
3136 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3138 /* FIXME not quite sure how/if these apply to the chroma plane */
3139 if (w > max_width || h > max_height) {
3140 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3141 w, h, max_width, max_height);
3145 plane_state->color_plane[1].offset = offset;
3146 plane_state->color_plane[1].x = x;
3147 plane_state->color_plane[1].y = y;
3152 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3154 const struct drm_framebuffer *fb = plane_state->base.fb;
3155 int src_x = plane_state->base.src.x1 >> 16;
3156 int src_y = plane_state->base.src.y1 >> 16;
3157 int hsub = fb->format->hsub;
3158 int vsub = fb->format->vsub;
3159 int x = src_x / hsub;
3160 int y = src_y / vsub;
3163 intel_add_fb_offsets(&x, &y, plane_state, 1);
3164 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3166 plane_state->color_plane[1].offset = offset;
3167 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3168 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3173 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3175 const struct drm_framebuffer *fb = plane_state->base.fb;
3176 unsigned int rotation = plane_state->base.rotation;
3179 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3180 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3181 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3183 ret = intel_plane_check_stride(plane_state);
3187 if (!plane_state->base.visible)
3190 /* Rotate src coordinates to match rotated GTT view */
3191 if (drm_rotation_90_or_270(rotation))
3192 drm_rect_rotate(&plane_state->base.src,
3193 fb->width << 16, fb->height << 16,
3194 DRM_MODE_ROTATE_270);
3197 * Handle the AUX surface first since
3198 * the main surface setup depends on it.
3200 if (fb->format->format == DRM_FORMAT_NV12) {
3201 ret = skl_check_nv12_surface(plane_state);
3204 ret = skl_check_nv12_aux_surface(plane_state);
3207 } else if (is_ccs_modifier(fb->modifier)) {
3208 ret = skl_check_ccs_aux_surface(plane_state);
3212 plane_state->color_plane[1].offset = ~0xfff;
3213 plane_state->color_plane[1].x = 0;
3214 plane_state->color_plane[1].y = 0;
3217 ret = skl_check_main_surface(plane_state);
3225 i9xx_plane_max_stride(struct intel_plane *plane,
3226 u32 pixel_format, u64 modifier,
3227 unsigned int rotation)
3229 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3231 if (!HAS_GMCH_DISPLAY(dev_priv)) {
3233 } else if (INTEL_GEN(dev_priv) >= 4) {
3234 if (modifier == I915_FORMAT_MOD_X_TILED)
3238 } else if (INTEL_GEN(dev_priv) >= 3) {
3239 if (modifier == I915_FORMAT_MOD_X_TILED)
3244 if (plane->i9xx_plane == PLANE_C)
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 const struct drm_framebuffer *fb = plane_state->base.fb;
3318 unsigned int rotation = plane_state->base.rotation;
3319 int src_x = plane_state->base.src.x1 >> 16;
3320 int src_y = plane_state->base.src.y1 >> 16;
3324 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3325 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3327 ret = intel_plane_check_stride(plane_state);
3331 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3333 if (INTEL_GEN(dev_priv) >= 4)
3334 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3339 /* HSW/BDW do this automagically in hardware */
3340 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3341 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3342 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3344 if (rotation & DRM_MODE_ROTATE_180) {
3347 } else if (rotation & DRM_MODE_REFLECT_X) {
3352 plane_state->color_plane[0].offset = offset;
3353 plane_state->color_plane[0].x = src_x;
3354 plane_state->color_plane[0].y = src_y;
3360 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3361 struct intel_plane_state *plane_state)
3365 ret = chv_plane_check_rotation(plane_state);
3369 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3371 DRM_PLANE_HELPER_NO_SCALING,
3372 DRM_PLANE_HELPER_NO_SCALING,
3377 if (!plane_state->base.visible)
3380 ret = intel_plane_check_src_coordinates(plane_state);
3384 ret = i9xx_check_plane_surface(plane_state);
3388 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3393 static void i9xx_update_plane(struct intel_plane *plane,
3394 const struct intel_crtc_state *crtc_state,
3395 const struct intel_plane_state *plane_state)
3397 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3398 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3400 u32 dspcntr = plane_state->ctl;
3401 i915_reg_t reg = DSPCNTR(i9xx_plane);
3402 int x = plane_state->color_plane[0].x;
3403 int y = plane_state->color_plane[0].y;
3404 unsigned long irqflags;
3407 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3409 if (INTEL_GEN(dev_priv) >= 4)
3410 dspaddr_offset = plane_state->color_plane[0].offset;
3412 dspaddr_offset = linear_offset;
3414 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3416 if (INTEL_GEN(dev_priv) < 4) {
3417 /* pipesrc and dspsize control the size that is scaled from,
3418 * which should always be the user's requested size.
3420 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3421 ((crtc_state->pipe_src_h - 1) << 16) |
3422 (crtc_state->pipe_src_w - 1));
3423 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3424 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3425 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3426 ((crtc_state->pipe_src_h - 1) << 16) |
3427 (crtc_state->pipe_src_w - 1));
3428 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3429 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3432 I915_WRITE_FW(reg, dspcntr);
3434 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3435 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3436 I915_WRITE_FW(DSPSURF(i9xx_plane),
3437 intel_plane_ggtt_offset(plane_state) +
3439 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3440 } else if (INTEL_GEN(dev_priv) >= 4) {
3441 I915_WRITE_FW(DSPSURF(i9xx_plane),
3442 intel_plane_ggtt_offset(plane_state) +
3444 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3445 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3447 I915_WRITE_FW(DSPADDR(i9xx_plane),
3448 intel_plane_ggtt_offset(plane_state) +
3451 POSTING_READ_FW(reg);
3453 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3456 static void i9xx_disable_plane(struct intel_plane *plane,
3457 struct intel_crtc *crtc)
3459 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3460 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3461 unsigned long irqflags;
3463 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3465 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3466 if (INTEL_GEN(dev_priv) >= 4)
3467 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3469 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3470 POSTING_READ_FW(DSPCNTR(i9xx_plane));
3472 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3475 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3478 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3479 enum intel_display_power_domain power_domain;
3480 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3485 * Not 100% correct for planes that can move between pipes,
3486 * but that's only the case for gen2-4 which don't have any
3487 * display power wells.
3489 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3490 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3493 val = I915_READ(DSPCNTR(i9xx_plane));
3495 ret = val & DISPLAY_PLANE_ENABLE;
3497 if (INTEL_GEN(dev_priv) >= 5)
3498 *pipe = plane->pipe;
3500 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3501 DISPPLANE_SEL_PIPE_SHIFT;
3503 intel_display_power_put(dev_priv, power_domain);
3509 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
3511 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3514 return intel_tile_width_bytes(fb, color_plane);
3517 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3519 struct drm_device *dev = intel_crtc->base.dev;
3520 struct drm_i915_private *dev_priv = to_i915(dev);
3522 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3523 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3524 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3528 * This function detaches (aka. unbinds) unused scalers in hardware
3530 static void skl_detach_scalers(struct intel_crtc *intel_crtc)
3532 struct intel_crtc_scaler_state *scaler_state;
3535 scaler_state = &intel_crtc->config->scaler_state;
3537 /* loop through and disable scalers that aren't in use */
3538 for (i = 0; i < intel_crtc->num_scalers; i++) {
3539 if (!scaler_state->scalers[i].in_use)
3540 skl_detach_scaler(intel_crtc, i);
3544 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3547 const struct drm_framebuffer *fb = plane_state->base.fb;
3548 unsigned int rotation = plane_state->base.rotation;
3549 u32 stride = plane_state->color_plane[color_plane].stride;
3551 if (color_plane >= fb->format->num_planes)
3555 * The stride is either expressed as a multiple of 64 bytes chunks for
3556 * linear buffers or in number of tiles for tiled buffers.
3558 if (drm_rotation_90_or_270(rotation))
3559 stride /= intel_tile_height(fb, color_plane);
3561 stride /= intel_fb_stride_alignment(fb, color_plane);
3566 static u32 skl_plane_ctl_format(uint32_t pixel_format)
3568 switch (pixel_format) {
3570 return PLANE_CTL_FORMAT_INDEXED;
3571 case DRM_FORMAT_RGB565:
3572 return PLANE_CTL_FORMAT_RGB_565;
3573 case DRM_FORMAT_XBGR8888:
3574 case DRM_FORMAT_ABGR8888:
3575 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3576 case DRM_FORMAT_XRGB8888:
3577 case DRM_FORMAT_ARGB8888:
3578 return PLANE_CTL_FORMAT_XRGB_8888;
3579 case DRM_FORMAT_XRGB2101010:
3580 return PLANE_CTL_FORMAT_XRGB_2101010;
3581 case DRM_FORMAT_XBGR2101010:
3582 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3583 case DRM_FORMAT_YUYV:
3584 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3585 case DRM_FORMAT_YVYU:
3586 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3587 case DRM_FORMAT_UYVY:
3588 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3589 case DRM_FORMAT_VYUY:
3590 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3591 case DRM_FORMAT_NV12:
3592 return PLANE_CTL_FORMAT_NV12;
3594 MISSING_CASE(pixel_format);
3601 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3602 * to be already pre-multiplied. We need to add a knob (or a different
3603 * DRM_FORMAT) for user-space to configure that.
3605 static u32 skl_plane_ctl_alpha(uint32_t pixel_format)
3607 switch (pixel_format) {
3608 case DRM_FORMAT_ABGR8888:
3609 case DRM_FORMAT_ARGB8888:
3610 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3612 return PLANE_CTL_ALPHA_DISABLE;
3616 static u32 glk_plane_color_ctl_alpha(uint32_t pixel_format)
3618 switch (pixel_format) {
3619 case DRM_FORMAT_ABGR8888:
3620 case DRM_FORMAT_ARGB8888:
3621 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3623 return PLANE_COLOR_ALPHA_DISABLE;
3627 static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
3629 switch (fb_modifier) {
3630 case DRM_FORMAT_MOD_LINEAR:
3632 case I915_FORMAT_MOD_X_TILED:
3633 return PLANE_CTL_TILED_X;
3634 case I915_FORMAT_MOD_Y_TILED:
3635 return PLANE_CTL_TILED_Y;
3636 case I915_FORMAT_MOD_Y_TILED_CCS:
3637 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3638 case I915_FORMAT_MOD_Yf_TILED:
3639 return PLANE_CTL_TILED_YF;
3640 case I915_FORMAT_MOD_Yf_TILED_CCS:
3641 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3643 MISSING_CASE(fb_modifier);
3649 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3652 case DRM_MODE_ROTATE_0:
3655 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3656 * while i915 HW rotation is clockwise, thats why this swapping.
3658 case DRM_MODE_ROTATE_90:
3659 return PLANE_CTL_ROTATE_270;
3660 case DRM_MODE_ROTATE_180:
3661 return PLANE_CTL_ROTATE_180;
3662 case DRM_MODE_ROTATE_270:
3663 return PLANE_CTL_ROTATE_90;
3665 MISSING_CASE(rotate);
3671 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3676 case DRM_MODE_REFLECT_X:
3677 return PLANE_CTL_FLIP_HORIZONTAL;
3678 case DRM_MODE_REFLECT_Y:
3680 MISSING_CASE(reflect);
3686 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3687 const struct intel_plane_state *plane_state)
3689 struct drm_i915_private *dev_priv =
3690 to_i915(plane_state->base.plane->dev);
3691 const struct drm_framebuffer *fb = plane_state->base.fb;
3692 unsigned int rotation = plane_state->base.rotation;
3693 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3696 plane_ctl = PLANE_CTL_ENABLE;
3698 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3699 plane_ctl |= skl_plane_ctl_alpha(fb->format->format);
3701 PLANE_CTL_PIPE_GAMMA_ENABLE |
3702 PLANE_CTL_PIPE_CSC_ENABLE |
3703 PLANE_CTL_PLANE_GAMMA_DISABLE;
3705 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3706 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3708 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3709 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3712 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3713 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3714 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3716 if (INTEL_GEN(dev_priv) >= 10)
3717 plane_ctl |= cnl_plane_ctl_flip(rotation &
3718 DRM_MODE_REFLECT_MASK);
3720 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3721 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3722 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3723 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3728 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3729 const struct intel_plane_state *plane_state)
3731 struct drm_i915_private *dev_priv =
3732 to_i915(plane_state->base.plane->dev);
3733 const struct drm_framebuffer *fb = plane_state->base.fb;
3734 u32 plane_color_ctl = 0;
3736 if (INTEL_GEN(dev_priv) < 11) {
3737 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3738 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3740 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3741 plane_color_ctl |= glk_plane_color_ctl_alpha(fb->format->format);
3743 if (fb->format->is_yuv) {
3744 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3745 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3747 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
3749 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3750 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3753 return plane_color_ctl;
3757 __intel_display_resume(struct drm_device *dev,
3758 struct drm_atomic_state *state,
3759 struct drm_modeset_acquire_ctx *ctx)
3761 struct drm_crtc_state *crtc_state;
3762 struct drm_crtc *crtc;
3765 intel_modeset_setup_hw_state(dev, ctx);
3766 i915_redisable_vga(to_i915(dev));
3772 * We've duplicated the state, pointers to the old state are invalid.
3774 * Don't attempt to use the old state until we commit the duplicated state.
3776 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3778 * Force recalculation even if we restore
3779 * current state. With fast modeset this may not result
3780 * in a modeset when the state is compatible.
3782 crtc_state->mode_changed = true;
3785 /* ignore any reset values/BIOS leftovers in the WM registers */
3786 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3787 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3789 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3791 WARN_ON(ret == -EDEADLK);
3795 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3797 return intel_has_gpu_reset(dev_priv) &&
3798 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
3801 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3803 struct drm_device *dev = &dev_priv->drm;
3804 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3805 struct drm_atomic_state *state;
3808 /* reset doesn't touch the display */
3809 if (!i915_modparams.force_reset_modeset_test &&
3810 !gpu_reset_clobbers_display(dev_priv))
3813 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3814 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3815 wake_up_all(&dev_priv->gpu_error.wait_queue);
3817 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3818 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3819 i915_gem_set_wedged(dev_priv);
3823 * Need mode_config.mutex so that we don't
3824 * trample ongoing ->detect() and whatnot.
3826 mutex_lock(&dev->mode_config.mutex);
3827 drm_modeset_acquire_init(ctx, 0);
3829 ret = drm_modeset_lock_all_ctx(dev, ctx);
3830 if (ret != -EDEADLK)
3833 drm_modeset_backoff(ctx);
3836 * Disabling the crtcs gracefully seems nicer. Also the
3837 * g33 docs say we should at least disable all the planes.
3839 state = drm_atomic_helper_duplicate_state(dev, ctx);
3840 if (IS_ERR(state)) {
3841 ret = PTR_ERR(state);
3842 DRM_ERROR("Duplicating state failed with %i\n", ret);
3846 ret = drm_atomic_helper_disable_all(dev, ctx);
3848 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3849 drm_atomic_state_put(state);
3853 dev_priv->modeset_restore_state = state;
3854 state->acquire_ctx = ctx;
3857 void intel_finish_reset(struct drm_i915_private *dev_priv)
3859 struct drm_device *dev = &dev_priv->drm;
3860 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3861 struct drm_atomic_state *state;
3864 /* reset doesn't touch the display */
3865 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
3868 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3872 /* reset doesn't touch the display */
3873 if (!gpu_reset_clobbers_display(dev_priv)) {
3874 /* for testing only restore the display */
3875 ret = __intel_display_resume(dev, state, ctx);
3877 DRM_ERROR("Restoring old state failed with %i\n", ret);
3880 * The display has been reset as well,
3881 * so need a full re-initialization.
3883 intel_runtime_pm_disable_interrupts(dev_priv);
3884 intel_runtime_pm_enable_interrupts(dev_priv);
3886 intel_pps_unlock_regs_wa(dev_priv);
3887 intel_modeset_init_hw(dev);
3888 intel_init_clock_gating(dev_priv);
3890 spin_lock_irq(&dev_priv->irq_lock);
3891 if (dev_priv->display.hpd_irq_setup)
3892 dev_priv->display.hpd_irq_setup(dev_priv);
3893 spin_unlock_irq(&dev_priv->irq_lock);
3895 ret = __intel_display_resume(dev, state, ctx);
3897 DRM_ERROR("Restoring old state failed with %i\n", ret);
3899 intel_hpd_init(dev_priv);
3902 drm_atomic_state_put(state);
3904 drm_modeset_drop_locks(ctx);
3905 drm_modeset_acquire_fini(ctx);
3906 mutex_unlock(&dev->mode_config.mutex);
3908 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3911 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3912 const struct intel_crtc_state *new_crtc_state)
3914 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
3915 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3917 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3918 crtc->base.mode = new_crtc_state->base.mode;
3921 * Update pipe size and adjust fitter if needed: the reason for this is
3922 * that in compute_mode_changes we check the native mode (not the pfit
3923 * mode) to see if we can flip rather than do a full mode set. In the
3924 * fastboot case, we'll flip, but if we don't update the pipesrc and
3925 * pfit state, we'll end up with a big fb scanned out into the wrong
3929 I915_WRITE(PIPESRC(crtc->pipe),
3930 ((new_crtc_state->pipe_src_w - 1) << 16) |
3931 (new_crtc_state->pipe_src_h - 1));
3933 /* on skylake this is done by detaching scalers */
3934 if (INTEL_GEN(dev_priv) >= 9) {
3935 skl_detach_scalers(crtc);
3937 if (new_crtc_state->pch_pfit.enabled)
3938 skylake_pfit_enable(crtc);
3939 } else if (HAS_PCH_SPLIT(dev_priv)) {
3940 if (new_crtc_state->pch_pfit.enabled)
3941 ironlake_pfit_enable(crtc);
3942 else if (old_crtc_state->pch_pfit.enabled)
3943 ironlake_pfit_disable(crtc, true);
3947 static void intel_fdi_normal_train(struct intel_crtc *crtc)
3949 struct drm_device *dev = crtc->base.dev;
3950 struct drm_i915_private *dev_priv = to_i915(dev);
3951 int pipe = crtc->pipe;
3955 /* enable normal train */
3956 reg = FDI_TX_CTL(pipe);
3957 temp = I915_READ(reg);
3958 if (IS_IVYBRIDGE(dev_priv)) {
3959 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3960 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3962 temp &= ~FDI_LINK_TRAIN_NONE;
3963 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3965 I915_WRITE(reg, temp);
3967 reg = FDI_RX_CTL(pipe);
3968 temp = I915_READ(reg);
3969 if (HAS_PCH_CPT(dev_priv)) {
3970 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3971 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3973 temp &= ~FDI_LINK_TRAIN_NONE;
3974 temp |= FDI_LINK_TRAIN_NONE;
3976 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3978 /* wait one idle pattern time */
3982 /* IVB wants error correction enabled */
3983 if (IS_IVYBRIDGE(dev_priv))
3984 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3985 FDI_FE_ERRC_ENABLE);
3988 /* The FDI link training functions for ILK/Ibexpeak. */
3989 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3990 const struct intel_crtc_state *crtc_state)
3992 struct drm_device *dev = crtc->base.dev;
3993 struct drm_i915_private *dev_priv = to_i915(dev);
3994 int pipe = crtc->pipe;
3998 /* FDI needs bits from pipe first */
3999 assert_pipe_enabled(dev_priv, pipe);
4001 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4003 reg = FDI_RX_IMR(pipe);
4004 temp = I915_READ(reg);
4005 temp &= ~FDI_RX_SYMBOL_LOCK;
4006 temp &= ~FDI_RX_BIT_LOCK;
4007 I915_WRITE(reg, temp);
4011 /* enable CPU FDI TX and PCH FDI RX */
4012 reg = FDI_TX_CTL(pipe);
4013 temp = I915_READ(reg);
4014 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4015 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4016 temp &= ~FDI_LINK_TRAIN_NONE;
4017 temp |= FDI_LINK_TRAIN_PATTERN_1;
4018 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4020 reg = FDI_RX_CTL(pipe);
4021 temp = I915_READ(reg);
4022 temp &= ~FDI_LINK_TRAIN_NONE;
4023 temp |= FDI_LINK_TRAIN_PATTERN_1;
4024 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4029 /* Ironlake workaround, enable clock pointer after FDI enable*/
4030 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4031 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4032 FDI_RX_PHASE_SYNC_POINTER_EN);
4034 reg = FDI_RX_IIR(pipe);
4035 for (tries = 0; tries < 5; tries++) {
4036 temp = I915_READ(reg);
4037 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4039 if ((temp & FDI_RX_BIT_LOCK)) {
4040 DRM_DEBUG_KMS("FDI train 1 done.\n");
4041 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4046 DRM_ERROR("FDI train 1 fail!\n");
4049 reg = FDI_TX_CTL(pipe);
4050 temp = I915_READ(reg);
4051 temp &= ~FDI_LINK_TRAIN_NONE;
4052 temp |= FDI_LINK_TRAIN_PATTERN_2;
4053 I915_WRITE(reg, temp);
4055 reg = FDI_RX_CTL(pipe);
4056 temp = I915_READ(reg);
4057 temp &= ~FDI_LINK_TRAIN_NONE;
4058 temp |= FDI_LINK_TRAIN_PATTERN_2;
4059 I915_WRITE(reg, temp);
4064 reg = FDI_RX_IIR(pipe);
4065 for (tries = 0; tries < 5; tries++) {
4066 temp = I915_READ(reg);
4067 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4069 if (temp & FDI_RX_SYMBOL_LOCK) {
4070 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4071 DRM_DEBUG_KMS("FDI train 2 done.\n");
4076 DRM_ERROR("FDI train 2 fail!\n");
4078 DRM_DEBUG_KMS("FDI train done\n");
4082 static const int snb_b_fdi_train_param[] = {
4083 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4084 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4085 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4086 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4089 /* The FDI link training functions for SNB/Cougarpoint. */
4090 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4091 const struct intel_crtc_state *crtc_state)
4093 struct drm_device *dev = crtc->base.dev;
4094 struct drm_i915_private *dev_priv = to_i915(dev);
4095 int pipe = crtc->pipe;
4099 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4101 reg = FDI_RX_IMR(pipe);
4102 temp = I915_READ(reg);
4103 temp &= ~FDI_RX_SYMBOL_LOCK;
4104 temp &= ~FDI_RX_BIT_LOCK;
4105 I915_WRITE(reg, temp);
4110 /* enable CPU FDI TX and PCH FDI RX */
4111 reg = FDI_TX_CTL(pipe);
4112 temp = I915_READ(reg);
4113 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4114 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4115 temp &= ~FDI_LINK_TRAIN_NONE;
4116 temp |= FDI_LINK_TRAIN_PATTERN_1;
4117 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4119 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4120 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4122 I915_WRITE(FDI_RX_MISC(pipe),
4123 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4125 reg = FDI_RX_CTL(pipe);
4126 temp = I915_READ(reg);
4127 if (HAS_PCH_CPT(dev_priv)) {
4128 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4129 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4131 temp &= ~FDI_LINK_TRAIN_NONE;
4132 temp |= FDI_LINK_TRAIN_PATTERN_1;
4134 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4139 for (i = 0; i < 4; i++) {
4140 reg = FDI_TX_CTL(pipe);
4141 temp = I915_READ(reg);
4142 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4143 temp |= snb_b_fdi_train_param[i];
4144 I915_WRITE(reg, temp);
4149 for (retry = 0; retry < 5; retry++) {
4150 reg = FDI_RX_IIR(pipe);
4151 temp = I915_READ(reg);
4152 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4153 if (temp & FDI_RX_BIT_LOCK) {
4154 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4155 DRM_DEBUG_KMS("FDI train 1 done.\n");
4164 DRM_ERROR("FDI train 1 fail!\n");
4167 reg = FDI_TX_CTL(pipe);
4168 temp = I915_READ(reg);
4169 temp &= ~FDI_LINK_TRAIN_NONE;
4170 temp |= FDI_LINK_TRAIN_PATTERN_2;
4171 if (IS_GEN6(dev_priv)) {
4172 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4174 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4176 I915_WRITE(reg, temp);
4178 reg = FDI_RX_CTL(pipe);
4179 temp = I915_READ(reg);
4180 if (HAS_PCH_CPT(dev_priv)) {
4181 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4182 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4184 temp &= ~FDI_LINK_TRAIN_NONE;
4185 temp |= FDI_LINK_TRAIN_PATTERN_2;
4187 I915_WRITE(reg, temp);
4192 for (i = 0; i < 4; i++) {
4193 reg = FDI_TX_CTL(pipe);
4194 temp = I915_READ(reg);
4195 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4196 temp |= snb_b_fdi_train_param[i];
4197 I915_WRITE(reg, temp);
4202 for (retry = 0; retry < 5; retry++) {
4203 reg = FDI_RX_IIR(pipe);
4204 temp = I915_READ(reg);
4205 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4206 if (temp & FDI_RX_SYMBOL_LOCK) {
4207 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4208 DRM_DEBUG_KMS("FDI train 2 done.\n");
4217 DRM_ERROR("FDI train 2 fail!\n");
4219 DRM_DEBUG_KMS("FDI train done.\n");
4222 /* Manual link training for Ivy Bridge A0 parts */
4223 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4224 const struct intel_crtc_state *crtc_state)
4226 struct drm_device *dev = crtc->base.dev;
4227 struct drm_i915_private *dev_priv = to_i915(dev);
4228 int pipe = crtc->pipe;
4232 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4234 reg = FDI_RX_IMR(pipe);
4235 temp = I915_READ(reg);
4236 temp &= ~FDI_RX_SYMBOL_LOCK;
4237 temp &= ~FDI_RX_BIT_LOCK;
4238 I915_WRITE(reg, temp);
4243 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4244 I915_READ(FDI_RX_IIR(pipe)));
4246 /* Try each vswing and preemphasis setting twice before moving on */
4247 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4248 /* disable first in case we need to retry */
4249 reg = FDI_TX_CTL(pipe);
4250 temp = I915_READ(reg);
4251 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4252 temp &= ~FDI_TX_ENABLE;
4253 I915_WRITE(reg, temp);
4255 reg = FDI_RX_CTL(pipe);
4256 temp = I915_READ(reg);
4257 temp &= ~FDI_LINK_TRAIN_AUTO;
4258 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4259 temp &= ~FDI_RX_ENABLE;
4260 I915_WRITE(reg, temp);
4262 /* enable CPU FDI TX and PCH FDI RX */
4263 reg = FDI_TX_CTL(pipe);
4264 temp = I915_READ(reg);
4265 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4266 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4267 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4268 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4269 temp |= snb_b_fdi_train_param[j/2];
4270 temp |= FDI_COMPOSITE_SYNC;
4271 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4273 I915_WRITE(FDI_RX_MISC(pipe),
4274 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4276 reg = FDI_RX_CTL(pipe);
4277 temp = I915_READ(reg);
4278 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4279 temp |= FDI_COMPOSITE_SYNC;
4280 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4283 udelay(1); /* should be 0.5us */
4285 for (i = 0; i < 4; i++) {
4286 reg = FDI_RX_IIR(pipe);
4287 temp = I915_READ(reg);
4288 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4290 if (temp & FDI_RX_BIT_LOCK ||
4291 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4292 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4293 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4297 udelay(1); /* should be 0.5us */
4300 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4305 reg = FDI_TX_CTL(pipe);
4306 temp = I915_READ(reg);
4307 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4308 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4309 I915_WRITE(reg, temp);
4311 reg = FDI_RX_CTL(pipe);
4312 temp = I915_READ(reg);
4313 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4314 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4315 I915_WRITE(reg, temp);
4318 udelay(2); /* should be 1.5us */
4320 for (i = 0; i < 4; i++) {
4321 reg = FDI_RX_IIR(pipe);
4322 temp = I915_READ(reg);
4323 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4325 if (temp & FDI_RX_SYMBOL_LOCK ||
4326 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4327 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4328 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4332 udelay(2); /* should be 1.5us */
4335 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4339 DRM_DEBUG_KMS("FDI train done.\n");
4342 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
4344 struct drm_device *dev = intel_crtc->base.dev;
4345 struct drm_i915_private *dev_priv = to_i915(dev);
4346 int pipe = intel_crtc->pipe;
4350 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4351 reg = FDI_RX_CTL(pipe);
4352 temp = I915_READ(reg);
4353 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4354 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
4355 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4356 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4361 /* Switch from Rawclk to PCDclk */
4362 temp = I915_READ(reg);
4363 I915_WRITE(reg, temp | FDI_PCDCLK);
4368 /* Enable CPU FDI TX PLL, always on for Ironlake */
4369 reg = FDI_TX_CTL(pipe);
4370 temp = I915_READ(reg);
4371 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4372 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4379 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4381 struct drm_device *dev = intel_crtc->base.dev;
4382 struct drm_i915_private *dev_priv = to_i915(dev);
4383 int pipe = intel_crtc->pipe;
4387 /* Switch from PCDclk to Rawclk */
4388 reg = FDI_RX_CTL(pipe);
4389 temp = I915_READ(reg);
4390 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4392 /* Disable CPU FDI TX PLL */
4393 reg = FDI_TX_CTL(pipe);
4394 temp = I915_READ(reg);
4395 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4400 reg = FDI_RX_CTL(pipe);
4401 temp = I915_READ(reg);
4402 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4404 /* Wait for the clocks to turn off. */
4409 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4411 struct drm_device *dev = crtc->dev;
4412 struct drm_i915_private *dev_priv = to_i915(dev);
4413 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4414 int pipe = intel_crtc->pipe;
4418 /* disable CPU FDI tx and PCH FDI rx */
4419 reg = FDI_TX_CTL(pipe);
4420 temp = I915_READ(reg);
4421 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4424 reg = FDI_RX_CTL(pipe);
4425 temp = I915_READ(reg);
4426 temp &= ~(0x7 << 16);
4427 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4428 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4433 /* Ironlake workaround, disable clock pointer after downing FDI */
4434 if (HAS_PCH_IBX(dev_priv))
4435 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4437 /* still set train pattern 1 */
4438 reg = FDI_TX_CTL(pipe);
4439 temp = I915_READ(reg);
4440 temp &= ~FDI_LINK_TRAIN_NONE;
4441 temp |= FDI_LINK_TRAIN_PATTERN_1;
4442 I915_WRITE(reg, temp);
4444 reg = FDI_RX_CTL(pipe);
4445 temp = I915_READ(reg);
4446 if (HAS_PCH_CPT(dev_priv)) {
4447 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4448 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4450 temp &= ~FDI_LINK_TRAIN_NONE;
4451 temp |= FDI_LINK_TRAIN_PATTERN_1;
4453 /* BPC in FDI rx is consistent with that in PIPECONF */
4454 temp &= ~(0x07 << 16);
4455 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4456 I915_WRITE(reg, temp);
4462 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4464 struct drm_crtc *crtc;
4467 drm_for_each_crtc(crtc, &dev_priv->drm) {
4468 struct drm_crtc_commit *commit;
4469 spin_lock(&crtc->commit_lock);
4470 commit = list_first_entry_or_null(&crtc->commit_list,
4471 struct drm_crtc_commit, commit_entry);
4472 cleanup_done = commit ?
4473 try_wait_for_completion(&commit->cleanup_done) : true;
4474 spin_unlock(&crtc->commit_lock);
4479 drm_crtc_wait_one_vblank(crtc);
4487 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4491 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4493 mutex_lock(&dev_priv->sb_lock);
4495 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4496 temp |= SBI_SSCCTL_DISABLE;
4497 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4499 mutex_unlock(&dev_priv->sb_lock);
4502 /* Program iCLKIP clock to the desired frequency */
4503 static void lpt_program_iclkip(struct intel_crtc *crtc)
4505 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4506 int clock = crtc->config->base.adjusted_mode.crtc_clock;
4507 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4510 lpt_disable_iclkip(dev_priv);
4512 /* The iCLK virtual clock root frequency is in MHz,
4513 * but the adjusted_mode->crtc_clock in in KHz. To get the
4514 * divisors, it is necessary to divide one by another, so we
4515 * convert the virtual clock precision to KHz here for higher
4518 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4519 u32 iclk_virtual_root_freq = 172800 * 1000;
4520 u32 iclk_pi_range = 64;
4521 u32 desired_divisor;
4523 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4525 divsel = (desired_divisor / iclk_pi_range) - 2;
4526 phaseinc = desired_divisor % iclk_pi_range;
4529 * Near 20MHz is a corner case which is
4530 * out of range for the 7-bit divisor
4536 /* This should not happen with any sane values */
4537 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4538 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4539 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4540 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4542 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4549 mutex_lock(&dev_priv->sb_lock);
4551 /* Program SSCDIVINTPHASE6 */
4552 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4553 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4554 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4555 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4556 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4557 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4558 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4559 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4561 /* Program SSCAUXDIV */
4562 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4563 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4564 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4565 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4567 /* Enable modulator and associated divider */
4568 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4569 temp &= ~SBI_SSCCTL_DISABLE;
4570 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4572 mutex_unlock(&dev_priv->sb_lock);
4574 /* Wait for initialization time */
4577 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4580 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4582 u32 divsel, phaseinc, auxdiv;
4583 u32 iclk_virtual_root_freq = 172800 * 1000;
4584 u32 iclk_pi_range = 64;
4585 u32 desired_divisor;
4588 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4591 mutex_lock(&dev_priv->sb_lock);
4593 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4594 if (temp & SBI_SSCCTL_DISABLE) {
4595 mutex_unlock(&dev_priv->sb_lock);
4599 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4600 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4601 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4602 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4603 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4605 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4606 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4607 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4609 mutex_unlock(&dev_priv->sb_lock);
4611 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4613 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4614 desired_divisor << auxdiv);
4617 static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
4618 enum pipe pch_transcoder)
4620 struct drm_device *dev = crtc->base.dev;
4621 struct drm_i915_private *dev_priv = to_i915(dev);
4622 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
4624 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4625 I915_READ(HTOTAL(cpu_transcoder)));
4626 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4627 I915_READ(HBLANK(cpu_transcoder)));
4628 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4629 I915_READ(HSYNC(cpu_transcoder)));
4631 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4632 I915_READ(VTOTAL(cpu_transcoder)));
4633 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4634 I915_READ(VBLANK(cpu_transcoder)));
4635 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4636 I915_READ(VSYNC(cpu_transcoder)));
4637 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4638 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4641 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4643 struct drm_i915_private *dev_priv = to_i915(dev);
4646 temp = I915_READ(SOUTH_CHICKEN1);
4647 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4650 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4651 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4653 temp &= ~FDI_BC_BIFURCATION_SELECT;
4655 temp |= FDI_BC_BIFURCATION_SELECT;
4657 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4658 I915_WRITE(SOUTH_CHICKEN1, temp);
4659 POSTING_READ(SOUTH_CHICKEN1);
4662 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4664 struct drm_device *dev = intel_crtc->base.dev;
4666 switch (intel_crtc->pipe) {
4670 if (intel_crtc->config->fdi_lanes > 2)
4671 cpt_set_fdi_bc_bifurcation(dev, false);
4673 cpt_set_fdi_bc_bifurcation(dev, true);
4677 cpt_set_fdi_bc_bifurcation(dev, true);
4686 * Finds the encoder associated with the given CRTC. This can only be
4687 * used when we know that the CRTC isn't feeding multiple encoders!
4689 static struct intel_encoder *
4690 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4691 const struct intel_crtc_state *crtc_state)
4693 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4694 const struct drm_connector_state *connector_state;
4695 const struct drm_connector *connector;
4696 struct intel_encoder *encoder = NULL;
4697 int num_encoders = 0;
4700 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4701 if (connector_state->crtc != &crtc->base)
4704 encoder = to_intel_encoder(connector_state->best_encoder);
4708 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4709 num_encoders, pipe_name(crtc->pipe));
4715 * Enable PCH resources required for PCH ports:
4717 * - FDI training & RX/TX
4718 * - update transcoder timings
4719 * - DP transcoding bits
4722 static void ironlake_pch_enable(const struct intel_atomic_state *state,
4723 const struct intel_crtc_state *crtc_state)
4725 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4726 struct drm_device *dev = crtc->base.dev;
4727 struct drm_i915_private *dev_priv = to_i915(dev);
4728 int pipe = crtc->pipe;
4731 assert_pch_transcoder_disabled(dev_priv, pipe);
4733 if (IS_IVYBRIDGE(dev_priv))
4734 ivybridge_update_fdi_bc_bifurcation(crtc);
4736 /* Write the TU size bits before fdi link training, so that error
4737 * detection works. */
4738 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4739 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4741 /* For PCH output, training FDI link */
4742 dev_priv->display.fdi_link_train(crtc, crtc_state);
4744 /* We need to program the right clock selection before writing the pixel
4745 * mutliplier into the DPLL. */
4746 if (HAS_PCH_CPT(dev_priv)) {
4749 temp = I915_READ(PCH_DPLL_SEL);
4750 temp |= TRANS_DPLL_ENABLE(pipe);
4751 sel = TRANS_DPLLB_SEL(pipe);
4752 if (crtc_state->shared_dpll ==
4753 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4757 I915_WRITE(PCH_DPLL_SEL, temp);
4760 /* XXX: pch pll's can be enabled any time before we enable the PCH
4761 * transcoder, and we actually should do this to not upset any PCH
4762 * transcoder that already use the clock when we share it.
4764 * Note that enable_shared_dpll tries to do the right thing, but
4765 * get_shared_dpll unconditionally resets the pll - we need that to have
4766 * the right LVDS enable sequence. */
4767 intel_enable_shared_dpll(crtc);
4769 /* set transcoder timing, panel must allow it */
4770 assert_panel_unlocked(dev_priv, pipe);
4771 ironlake_pch_transcoder_set_timings(crtc, pipe);
4773 intel_fdi_normal_train(crtc);
4775 /* For PCH DP, enable TRANS_DP_CTL */
4776 if (HAS_PCH_CPT(dev_priv) &&
4777 intel_crtc_has_dp_encoder(crtc_state)) {
4778 const struct drm_display_mode *adjusted_mode =
4779 &crtc_state->base.adjusted_mode;
4780 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4781 i915_reg_t reg = TRANS_DP_CTL(pipe);
4784 temp = I915_READ(reg);
4785 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4786 TRANS_DP_SYNC_MASK |
4788 temp |= TRANS_DP_OUTPUT_ENABLE;
4789 temp |= bpc << 9; /* same format but at 11:9 */
4791 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4792 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4793 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4794 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4796 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
4797 WARN_ON(port < PORT_B || port > PORT_D);
4798 temp |= TRANS_DP_PORT_SEL(port);
4800 I915_WRITE(reg, temp);
4803 ironlake_enable_pch_transcoder(dev_priv, pipe);
4806 static void lpt_pch_enable(const struct intel_atomic_state *state,
4807 const struct intel_crtc_state *crtc_state)
4809 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4810 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4811 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4813 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4815 lpt_program_iclkip(crtc);
4817 /* Set transcoder timing. */
4818 ironlake_pch_transcoder_set_timings(crtc, PIPE_A);
4820 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4823 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4825 struct drm_i915_private *dev_priv = to_i915(dev);
4826 i915_reg_t dslreg = PIPEDSL(pipe);
4829 temp = I915_READ(dslreg);
4831 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4832 if (wait_for(I915_READ(dslreg) != temp, 5))
4833 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4838 * The hardware phase 0.0 refers to the center of the pixel.
4839 * We want to start from the top/left edge which is phase
4840 * -0.5. That matches how the hardware calculates the scaling
4841 * factors (from top-left of the first pixel to bottom-right
4842 * of the last pixel, as opposed to the pixel centers).
4844 * For 4:2:0 subsampled chroma planes we obviously have to
4845 * adjust that so that the chroma sample position lands in
4848 * Note that for packed YCbCr 4:2:2 formats there is no way to
4849 * control chroma siting. The hardware simply replicates the
4850 * chroma samples for both of the luma samples, and thus we don't
4851 * actually get the expected MPEG2 chroma siting convention :(
4852 * The same behaviour is observed on pre-SKL platforms as well.
4854 * Theory behind the formula (note that we ignore sub-pixel
4855 * source coordinates):
4856 * s = source sample position
4857 * d = destination sample position
4862 * | | 1.5 (initial phase)
4870 * | -0.375 (initial phase)
4877 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
4879 int phase = -0x8000;
4883 phase += (sub - 1) * 0x8000 / sub;
4885 phase += scale / (2 * sub);
4888 * Hardware initial phase limited to [-0.5:1.5].
4889 * Since the max hardware scale factor is 3.0, we
4890 * should never actually excdeed 1.0 here.
4892 WARN_ON(phase < -0x8000 || phase > 0x18000);
4895 phase = 0x10000 + phase;
4897 trip = PS_PHASE_TRIP;
4899 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4903 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4904 unsigned int scaler_user, int *scaler_id,
4905 int src_w, int src_h, int dst_w, int dst_h,
4906 bool plane_scaler_check,
4907 uint32_t pixel_format)
4909 struct intel_crtc_scaler_state *scaler_state =
4910 &crtc_state->scaler_state;
4911 struct intel_crtc *intel_crtc =
4912 to_intel_crtc(crtc_state->base.crtc);
4913 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4914 const struct drm_display_mode *adjusted_mode =
4915 &crtc_state->base.adjusted_mode;
4919 * Src coordinates are already rotated by 270 degrees for
4920 * the 90/270 degree plane rotation cases (to match the
4921 * GTT mapping), hence no need to account for rotation here.
4923 need_scaling = src_w != dst_w || src_h != dst_h;
4925 if (plane_scaler_check)
4926 if (pixel_format == DRM_FORMAT_NV12)
4927 need_scaling = true;
4929 if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX)
4930 need_scaling = true;
4933 * Scaling/fitting not supported in IF-ID mode in GEN9+
4934 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4935 * Once NV12 is enabled, handle it here while allocating scaler
4938 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4939 need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4940 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4945 * if plane is being disabled or scaler is no more required or force detach
4946 * - free scaler binded to this plane/crtc
4947 * - in order to do this, update crtc->scaler_usage
4949 * Here scaler state in crtc_state is set free so that
4950 * scaler can be assigned to other user. Actual register
4951 * update to free the scaler is done in plane/panel-fit programming.
4952 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4954 if (force_detach || !need_scaling) {
4955 if (*scaler_id >= 0) {
4956 scaler_state->scaler_users &= ~(1 << scaler_user);
4957 scaler_state->scalers[*scaler_id].in_use = 0;
4959 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4960 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4961 intel_crtc->pipe, scaler_user, *scaler_id,
4962 scaler_state->scaler_users);
4968 if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 &&
4969 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
4970 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4975 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4976 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4977 (IS_GEN11(dev_priv) &&
4978 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4979 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4980 (!IS_GEN11(dev_priv) &&
4981 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4982 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
4983 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4984 "size is out of scaler range\n",
4985 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4989 /* mark this plane as a scaler user in crtc_state */
4990 scaler_state->scaler_users |= (1 << scaler_user);
4991 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4992 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4993 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4994 scaler_state->scaler_users);
5000 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5002 * @state: crtc's scaler state
5005 * 0 - scaler_usage updated successfully
5006 * error - requested scaling cannot be supported or other error condition
5008 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5010 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
5012 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
5013 &state->scaler_state.scaler_id,
5014 state->pipe_src_w, state->pipe_src_h,
5015 adjusted_mode->crtc_hdisplay,
5016 adjusted_mode->crtc_vdisplay, false, 0);
5020 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5021 * @crtc_state: crtc's scaler state
5022 * @plane_state: atomic plane state to update
5025 * 0 - scaler_usage updated successfully
5026 * error - requested scaling cannot be supported or other error condition
5028 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5029 struct intel_plane_state *plane_state)
5032 struct intel_plane *intel_plane =
5033 to_intel_plane(plane_state->base.plane);
5034 struct drm_framebuffer *fb = plane_state->base.fb;
5037 bool force_detach = !fb || !plane_state->base.visible;
5039 ret = skl_update_scaler(crtc_state, force_detach,
5040 drm_plane_index(&intel_plane->base),
5041 &plane_state->scaler_id,
5042 drm_rect_width(&plane_state->base.src) >> 16,
5043 drm_rect_height(&plane_state->base.src) >> 16,
5044 drm_rect_width(&plane_state->base.dst),
5045 drm_rect_height(&plane_state->base.dst),
5046 fb ? true : false, fb ? fb->format->format : 0);
5048 if (ret || plane_state->scaler_id < 0)
5051 /* check colorkey */
5052 if (plane_state->ckey.flags) {
5053 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5054 intel_plane->base.base.id,
5055 intel_plane->base.name);
5059 /* Check src format */
5060 switch (fb->format->format) {
5061 case DRM_FORMAT_RGB565:
5062 case DRM_FORMAT_XBGR8888:
5063 case DRM_FORMAT_XRGB8888:
5064 case DRM_FORMAT_ABGR8888:
5065 case DRM_FORMAT_ARGB8888:
5066 case DRM_FORMAT_XRGB2101010:
5067 case DRM_FORMAT_XBGR2101010:
5068 case DRM_FORMAT_YUYV:
5069 case DRM_FORMAT_YVYU:
5070 case DRM_FORMAT_UYVY:
5071 case DRM_FORMAT_VYUY:
5072 case DRM_FORMAT_NV12:
5075 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5076 intel_plane->base.base.id, intel_plane->base.name,
5077 fb->base.id, fb->format->format);
5084 static void skylake_scaler_disable(struct intel_crtc *crtc)
5088 for (i = 0; i < crtc->num_scalers; i++)
5089 skl_detach_scaler(crtc, i);
5092 static void skylake_pfit_enable(struct intel_crtc *crtc)
5094 struct drm_device *dev = crtc->base.dev;
5095 struct drm_i915_private *dev_priv = to_i915(dev);
5096 int pipe = crtc->pipe;
5097 struct intel_crtc_scaler_state *scaler_state =
5098 &crtc->config->scaler_state;
5100 if (crtc->config->pch_pfit.enabled) {
5101 u16 uv_rgb_hphase, uv_rgb_vphase;
5102 int pfit_w, pfit_h, hscale, vscale;
5105 if (WARN_ON(crtc->config->scaler_state.scaler_id < 0))
5108 pfit_w = (crtc->config->pch_pfit.size >> 16) & 0xFFFF;
5109 pfit_h = crtc->config->pch_pfit.size & 0xFFFF;
5111 hscale = (crtc->config->pipe_src_w << 16) / pfit_w;
5112 vscale = (crtc->config->pipe_src_h << 16) / pfit_h;
5114 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5115 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5117 id = scaler_state->scaler_id;
5118 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5119 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5120 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5121 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5122 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5123 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5124 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
5125 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
5129 static void ironlake_pfit_enable(struct intel_crtc *crtc)
5131 struct drm_device *dev = crtc->base.dev;
5132 struct drm_i915_private *dev_priv = to_i915(dev);
5133 int pipe = crtc->pipe;
5135 if (crtc->config->pch_pfit.enabled) {
5136 /* Force use of hard-coded filter coefficients
5137 * as some pre-programmed values are broken,
5140 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5141 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5142 PF_PIPE_SEL_IVB(pipe));
5144 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5145 I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
5146 I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
5150 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5152 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5153 struct drm_device *dev = crtc->base.dev;
5154 struct drm_i915_private *dev_priv = to_i915(dev);
5156 if (!crtc_state->ips_enabled)
5160 * We can only enable IPS after we enable a plane and wait for a vblank
5161 * This function is called from post_plane_update, which is run after
5164 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5166 if (IS_BROADWELL(dev_priv)) {
5167 mutex_lock(&dev_priv->pcu_lock);
5168 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5169 IPS_ENABLE | IPS_PCODE_CONTROL));
5170 mutex_unlock(&dev_priv->pcu_lock);
5171 /* Quoting Art Runyan: "its not safe to expect any particular
5172 * value in IPS_CTL bit 31 after enabling IPS through the
5173 * mailbox." Moreover, the mailbox may return a bogus state,
5174 * so we need to just enable it and continue on.
5177 I915_WRITE(IPS_CTL, IPS_ENABLE);
5178 /* The bit only becomes 1 in the next vblank, so this wait here
5179 * is essentially intel_wait_for_vblank. If we don't have this
5180 * and don't wait for vblanks until the end of crtc_enable, then
5181 * the HW state readout code will complain that the expected
5182 * IPS_CTL value is not the one we read. */
5183 if (intel_wait_for_register(dev_priv,
5184 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5186 DRM_ERROR("Timed out waiting for IPS enable\n");
5190 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5192 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5193 struct drm_device *dev = crtc->base.dev;
5194 struct drm_i915_private *dev_priv = to_i915(dev);
5196 if (!crtc_state->ips_enabled)
5199 if (IS_BROADWELL(dev_priv)) {
5200 mutex_lock(&dev_priv->pcu_lock);
5201 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5202 mutex_unlock(&dev_priv->pcu_lock);
5204 * Wait for PCODE to finish disabling IPS. The BSpec specified
5205 * 42ms timeout value leads to occasional timeouts so use 100ms
5208 if (intel_wait_for_register(dev_priv,
5209 IPS_CTL, IPS_ENABLE, 0,
5211 DRM_ERROR("Timed out waiting for IPS disable\n");
5213 I915_WRITE(IPS_CTL, 0);
5214 POSTING_READ(IPS_CTL);
5217 /* We need to wait for a vblank before we can disable the plane. */
5218 intel_wait_for_vblank(dev_priv, crtc->pipe);
5221 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5223 if (intel_crtc->overlay) {
5224 struct drm_device *dev = intel_crtc->base.dev;
5226 mutex_lock(&dev->struct_mutex);
5227 (void) intel_overlay_switch_off(intel_crtc->overlay);
5228 mutex_unlock(&dev->struct_mutex);
5231 /* Let userspace switch the overlay on again. In most cases userspace
5232 * has to recompute where to put it anyway.
5237 * intel_post_enable_primary - Perform operations after enabling primary plane
5238 * @crtc: the CRTC whose primary plane was just enabled
5239 * @new_crtc_state: the enabling state
5241 * Performs potentially sleeping operations that must be done after the primary
5242 * plane is enabled, such as updating FBC and IPS. Note that this may be
5243 * called due to an explicit primary plane update, or due to an implicit
5244 * re-enable that is caused when a sprite plane is updated to no longer
5245 * completely hide the primary plane.
5248 intel_post_enable_primary(struct drm_crtc *crtc,
5249 const struct intel_crtc_state *new_crtc_state)
5251 struct drm_device *dev = crtc->dev;
5252 struct drm_i915_private *dev_priv = to_i915(dev);
5253 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5254 int pipe = intel_crtc->pipe;
5257 * Gen2 reports pipe underruns whenever all planes are disabled.
5258 * So don't enable underrun reporting before at least some planes
5260 * FIXME: Need to fix the logic to work when we turn off all planes
5261 * but leave the pipe running.
5263 if (IS_GEN2(dev_priv))
5264 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5266 /* Underruns don't always raise interrupts, so check manually. */
5267 intel_check_cpu_fifo_underruns(dev_priv);
5268 intel_check_pch_fifo_underruns(dev_priv);
5271 /* FIXME get rid of this and use pre_plane_update */
5273 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5275 struct drm_device *dev = crtc->dev;
5276 struct drm_i915_private *dev_priv = to_i915(dev);
5277 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5278 int pipe = intel_crtc->pipe;
5281 * Gen2 reports pipe underruns whenever all planes are disabled.
5282 * So disable underrun reporting before all the planes get disabled.
5284 if (IS_GEN2(dev_priv))
5285 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5287 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5290 * Vblank time updates from the shadow to live plane control register
5291 * are blocked if the memory self-refresh mode is active at that
5292 * moment. So to make sure the plane gets truly disabled, disable
5293 * first the self-refresh mode. The self-refresh enable bit in turn
5294 * will be checked/applied by the HW only at the next frame start
5295 * event which is after the vblank start event, so we need to have a
5296 * wait-for-vblank between disabling the plane and the pipe.
5298 if (HAS_GMCH_DISPLAY(dev_priv) &&
5299 intel_set_memory_cxsr(dev_priv, false))
5300 intel_wait_for_vblank(dev_priv, pipe);
5303 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5304 const struct intel_crtc_state *new_crtc_state)
5306 if (!old_crtc_state->ips_enabled)
5309 if (needs_modeset(&new_crtc_state->base))
5312 return !new_crtc_state->ips_enabled;
5315 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5316 const struct intel_crtc_state *new_crtc_state)
5318 if (!new_crtc_state->ips_enabled)
5321 if (needs_modeset(&new_crtc_state->base))
5325 * We can't read out IPS on broadwell, assume the worst and
5326 * forcibly enable IPS on the first fastset.
5328 if (new_crtc_state->update_pipe &&
5329 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5332 return !old_crtc_state->ips_enabled;
5335 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5336 const struct intel_crtc_state *crtc_state)
5338 if (!crtc_state->nv12_planes)
5341 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
5344 if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
5345 IS_CANNONLAKE(dev_priv))
5351 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5353 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5354 struct drm_device *dev = crtc->base.dev;
5355 struct drm_i915_private *dev_priv = to_i915(dev);
5356 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5357 struct intel_crtc_state *pipe_config =
5358 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5360 struct drm_plane *primary = crtc->base.primary;
5361 struct drm_plane_state *old_primary_state =
5362 drm_atomic_get_old_plane_state(old_state, primary);
5364 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5366 if (pipe_config->update_wm_post && pipe_config->base.active)
5367 intel_update_watermarks(crtc);
5369 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5370 hsw_enable_ips(pipe_config);
5372 if (old_primary_state) {
5373 struct drm_plane_state *new_primary_state =
5374 drm_atomic_get_new_plane_state(old_state, primary);
5376 intel_fbc_post_update(crtc);
5378 if (new_primary_state->visible &&
5379 (needs_modeset(&pipe_config->base) ||
5380 !old_primary_state->visible))
5381 intel_post_enable_primary(&crtc->base, pipe_config);
5384 /* Display WA 827 */
5385 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5386 !needs_nv12_wa(dev_priv, pipe_config)) {
5387 skl_wa_clkgate(dev_priv, crtc->pipe, false);
5388 skl_wa_528(dev_priv, crtc->pipe, false);
5392 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5393 struct intel_crtc_state *pipe_config)
5395 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5396 struct drm_device *dev = crtc->base.dev;
5397 struct drm_i915_private *dev_priv = to_i915(dev);
5398 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5399 struct drm_plane *primary = crtc->base.primary;
5400 struct drm_plane_state *old_primary_state =
5401 drm_atomic_get_old_plane_state(old_state, primary);
5402 bool modeset = needs_modeset(&pipe_config->base);
5403 struct intel_atomic_state *old_intel_state =
5404 to_intel_atomic_state(old_state);
5406 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5407 hsw_disable_ips(old_crtc_state);
5409 if (old_primary_state) {
5410 struct intel_plane_state *new_primary_state =
5411 intel_atomic_get_new_plane_state(old_intel_state,
5412 to_intel_plane(primary));
5414 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5416 * Gen2 reports pipe underruns whenever all planes are disabled.
5417 * So disable underrun reporting before all the planes get disabled.
5419 if (IS_GEN2(dev_priv) && old_primary_state->visible &&
5420 (modeset || !new_primary_state->base.visible))
5421 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5424 /* Display WA 827 */
5425 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5426 needs_nv12_wa(dev_priv, pipe_config)) {
5427 skl_wa_clkgate(dev_priv, crtc->pipe, true);
5428 skl_wa_528(dev_priv, crtc->pipe, true);
5432 * Vblank time updates from the shadow to live plane control register
5433 * are blocked if the memory self-refresh mode is active at that
5434 * moment. So to make sure the plane gets truly disabled, disable
5435 * first the self-refresh mode. The self-refresh enable bit in turn
5436 * will be checked/applied by the HW only at the next frame start
5437 * event which is after the vblank start event, so we need to have a
5438 * wait-for-vblank between disabling the plane and the pipe.
5440 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5441 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5442 intel_wait_for_vblank(dev_priv, crtc->pipe);
5445 * IVB workaround: must disable low power watermarks for at least
5446 * one frame before enabling scaling. LP watermarks can be re-enabled
5447 * when scaling is disabled.
5449 * WaCxSRDisabledForSpriteScaling:ivb
5451 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev))
5452 intel_wait_for_vblank(dev_priv, crtc->pipe);
5455 * If we're doing a modeset, we're done. No need to do any pre-vblank
5456 * watermark programming here.
5458 if (needs_modeset(&pipe_config->base))
5462 * For platforms that support atomic watermarks, program the
5463 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5464 * will be the intermediate values that are safe for both pre- and
5465 * post- vblank; when vblank happens, the 'active' values will be set
5466 * to the final 'target' values and we'll do this again to get the
5467 * optimal watermarks. For gen9+ platforms, the values we program here
5468 * will be the final target values which will get automatically latched
5469 * at vblank time; no further programming will be necessary.
5471 * If a platform hasn't been transitioned to atomic watermarks yet,
5472 * we'll continue to update watermarks the old way, if flags tell
5475 if (dev_priv->display.initial_watermarks != NULL)
5476 dev_priv->display.initial_watermarks(old_intel_state,
5478 else if (pipe_config->update_wm_pre)
5479 intel_update_watermarks(crtc);
5482 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
5484 struct drm_device *dev = crtc->dev;
5485 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5486 struct drm_plane *p;
5487 int pipe = intel_crtc->pipe;
5489 intel_crtc_dpms_overlay_disable(intel_crtc);
5491 drm_for_each_plane_mask(p, dev, plane_mask)
5492 to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc);
5495 * FIXME: Once we grow proper nuclear flip support out of this we need
5496 * to compute the mask of flip planes precisely. For the time being
5497 * consider this a flip to a NULL plane.
5499 intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe));
5502 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5503 struct intel_crtc_state *crtc_state,
5504 struct drm_atomic_state *old_state)
5506 struct drm_connector_state *conn_state;
5507 struct drm_connector *conn;
5510 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5511 struct intel_encoder *encoder =
5512 to_intel_encoder(conn_state->best_encoder);
5514 if (conn_state->crtc != crtc)
5517 if (encoder->pre_pll_enable)
5518 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5522 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5523 struct intel_crtc_state *crtc_state,
5524 struct drm_atomic_state *old_state)
5526 struct drm_connector_state *conn_state;
5527 struct drm_connector *conn;
5530 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5531 struct intel_encoder *encoder =
5532 to_intel_encoder(conn_state->best_encoder);
5534 if (conn_state->crtc != crtc)
5537 if (encoder->pre_enable)
5538 encoder->pre_enable(encoder, crtc_state, conn_state);
5542 static void intel_encoders_enable(struct drm_crtc *crtc,
5543 struct intel_crtc_state *crtc_state,
5544 struct drm_atomic_state *old_state)
5546 struct drm_connector_state *conn_state;
5547 struct drm_connector *conn;
5550 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5551 struct intel_encoder *encoder =
5552 to_intel_encoder(conn_state->best_encoder);
5554 if (conn_state->crtc != crtc)
5557 encoder->enable(encoder, crtc_state, conn_state);
5558 intel_opregion_notify_encoder(encoder, true);
5562 static void intel_encoders_disable(struct drm_crtc *crtc,
5563 struct intel_crtc_state *old_crtc_state,
5564 struct drm_atomic_state *old_state)
5566 struct drm_connector_state *old_conn_state;
5567 struct drm_connector *conn;
5570 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5571 struct intel_encoder *encoder =
5572 to_intel_encoder(old_conn_state->best_encoder);
5574 if (old_conn_state->crtc != crtc)
5577 intel_opregion_notify_encoder(encoder, false);
5578 encoder->disable(encoder, old_crtc_state, old_conn_state);
5582 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5583 struct intel_crtc_state *old_crtc_state,
5584 struct drm_atomic_state *old_state)
5586 struct drm_connector_state *old_conn_state;
5587 struct drm_connector *conn;
5590 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5591 struct intel_encoder *encoder =
5592 to_intel_encoder(old_conn_state->best_encoder);
5594 if (old_conn_state->crtc != crtc)
5597 if (encoder->post_disable)
5598 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5602 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5603 struct intel_crtc_state *old_crtc_state,
5604 struct drm_atomic_state *old_state)
5606 struct drm_connector_state *old_conn_state;
5607 struct drm_connector *conn;
5610 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5611 struct intel_encoder *encoder =
5612 to_intel_encoder(old_conn_state->best_encoder);
5614 if (old_conn_state->crtc != crtc)
5617 if (encoder->post_pll_disable)
5618 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5622 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5623 struct drm_atomic_state *old_state)
5625 struct drm_crtc *crtc = pipe_config->base.crtc;
5626 struct drm_device *dev = crtc->dev;
5627 struct drm_i915_private *dev_priv = to_i915(dev);
5628 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5629 int pipe = intel_crtc->pipe;
5630 struct intel_atomic_state *old_intel_state =
5631 to_intel_atomic_state(old_state);
5633 if (WARN_ON(intel_crtc->active))
5637 * Sometimes spurious CPU pipe underruns happen during FDI
5638 * training, at least with VGA+HDMI cloning. Suppress them.
5640 * On ILK we get an occasional spurious CPU pipe underruns
5641 * between eDP port A enable and vdd enable. Also PCH port
5642 * enable seems to result in the occasional CPU pipe underrun.
5644 * Spurious PCH underruns also occur during PCH enabling.
5646 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5647 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5649 if (intel_crtc->config->has_pch_encoder)
5650 intel_prepare_shared_dpll(intel_crtc);
5652 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5653 intel_dp_set_m_n(intel_crtc, M1_N1);
5655 intel_set_pipe_timings(intel_crtc);
5656 intel_set_pipe_src_size(intel_crtc);
5658 if (intel_crtc->config->has_pch_encoder) {
5659 intel_cpu_transcoder_set_m_n(intel_crtc,
5660 &intel_crtc->config->fdi_m_n, NULL);
5663 ironlake_set_pipeconf(crtc);
5665 intel_crtc->active = true;
5667 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5669 if (intel_crtc->config->has_pch_encoder) {
5670 /* Note: FDI PLL enabling _must_ be done before we enable the
5671 * cpu pipes, hence this is separate from all the other fdi/pch
5673 ironlake_fdi_pll_enable(intel_crtc);
5675 assert_fdi_tx_disabled(dev_priv, pipe);
5676 assert_fdi_rx_disabled(dev_priv, pipe);
5679 ironlake_pfit_enable(intel_crtc);
5682 * On ILK+ LUT must be loaded before the pipe is running but with
5685 intel_color_load_luts(&pipe_config->base);
5687 if (dev_priv->display.initial_watermarks != NULL)
5688 dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config);
5689 intel_enable_pipe(pipe_config);
5691 if (intel_crtc->config->has_pch_encoder)
5692 ironlake_pch_enable(old_intel_state, pipe_config);
5694 assert_vblank_disabled(crtc);
5695 drm_crtc_vblank_on(crtc);
5697 intel_encoders_enable(crtc, pipe_config, old_state);
5699 if (HAS_PCH_CPT(dev_priv))
5700 cpt_verify_modeset(dev, intel_crtc->pipe);
5703 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5704 * And a second vblank wait is needed at least on ILK with
5705 * some interlaced HDMI modes. Let's do the double wait always
5706 * in case there are more corner cases we don't know about.
5708 if (intel_crtc->config->has_pch_encoder) {
5709 intel_wait_for_vblank(dev_priv, pipe);
5710 intel_wait_for_vblank(dev_priv, pipe);
5712 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5713 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5716 /* IPS only exists on ULT machines and is tied to pipe A. */
5717 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5719 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5722 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5723 enum pipe pipe, bool apply)
5725 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5726 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5733 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5736 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5738 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5739 enum pipe pipe = crtc->pipe;
5742 val = MBUS_DBOX_BW_CREDIT(1) | MBUS_DBOX_A_CREDIT(2);
5744 /* Program B credit equally to all pipes */
5745 val |= MBUS_DBOX_B_CREDIT(24 / INTEL_INFO(dev_priv)->num_pipes);
5747 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5750 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5751 struct drm_atomic_state *old_state)
5753 struct drm_crtc *crtc = pipe_config->base.crtc;
5754 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5755 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5756 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5757 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5758 struct intel_atomic_state *old_intel_state =
5759 to_intel_atomic_state(old_state);
5760 bool psl_clkgate_wa;
5763 if (WARN_ON(intel_crtc->active))
5766 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5768 if (intel_crtc->config->shared_dpll)
5769 intel_enable_shared_dpll(intel_crtc);
5771 if (INTEL_GEN(dev_priv) >= 11)
5772 icl_map_plls_to_ports(crtc, pipe_config, old_state);
5774 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5776 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5777 intel_dp_set_m_n(intel_crtc, M1_N1);
5779 if (!transcoder_is_dsi(cpu_transcoder))
5780 intel_set_pipe_timings(intel_crtc);
5782 intel_set_pipe_src_size(intel_crtc);
5784 if (cpu_transcoder != TRANSCODER_EDP &&
5785 !transcoder_is_dsi(cpu_transcoder)) {
5786 I915_WRITE(PIPE_MULT(cpu_transcoder),
5787 intel_crtc->config->pixel_multiplier - 1);
5790 if (intel_crtc->config->has_pch_encoder) {
5791 intel_cpu_transcoder_set_m_n(intel_crtc,
5792 &intel_crtc->config->fdi_m_n, NULL);
5795 if (!transcoder_is_dsi(cpu_transcoder))
5796 haswell_set_pipeconf(crtc);
5798 haswell_set_pipemisc(crtc);
5800 intel_color_set_csc(&pipe_config->base);
5802 intel_crtc->active = true;
5804 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5805 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5806 intel_crtc->config->pch_pfit.enabled;
5808 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5810 if (INTEL_GEN(dev_priv) >= 9)
5811 skylake_pfit_enable(intel_crtc);
5813 ironlake_pfit_enable(intel_crtc);
5816 * On ILK+ LUT must be loaded before the pipe is running but with
5819 intel_color_load_luts(&pipe_config->base);
5822 * Display WA #1153: enable hardware to bypass the alpha math
5823 * and rounding for per-pixel values 00 and 0xff
5825 if (INTEL_GEN(dev_priv) >= 11) {
5826 pipe_chicken = I915_READ(PIPE_CHICKEN(pipe));
5827 if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN))
5828 I915_WRITE_FW(PIPE_CHICKEN(pipe),
5829 pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN);
5832 intel_ddi_set_pipe_settings(pipe_config);
5833 if (!transcoder_is_dsi(cpu_transcoder))
5834 intel_ddi_enable_transcoder_func(pipe_config);
5836 if (dev_priv->display.initial_watermarks != NULL)
5837 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5839 if (INTEL_GEN(dev_priv) >= 11)
5840 icl_pipe_mbus_enable(intel_crtc);
5842 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5843 if (!transcoder_is_dsi(cpu_transcoder))
5844 intel_enable_pipe(pipe_config);
5846 if (intel_crtc->config->has_pch_encoder)
5847 lpt_pch_enable(old_intel_state, pipe_config);
5849 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5850 intel_ddi_set_vc_payload_alloc(pipe_config, true);
5852 assert_vblank_disabled(crtc);
5853 drm_crtc_vblank_on(crtc);
5855 intel_encoders_enable(crtc, pipe_config, old_state);
5857 if (psl_clkgate_wa) {
5858 intel_wait_for_vblank(dev_priv, pipe);
5859 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5862 /* If we change the relative order between pipe/planes enabling, we need
5863 * to change the workaround. */
5864 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
5865 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5866 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5867 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5871 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force)
5873 struct drm_device *dev = crtc->base.dev;
5874 struct drm_i915_private *dev_priv = to_i915(dev);
5875 int pipe = crtc->pipe;
5877 /* To avoid upsetting the power well on haswell only disable the pfit if
5878 * it's in use. The hw state code will make sure we get this right. */
5879 if (force || crtc->config->pch_pfit.enabled) {
5880 I915_WRITE(PF_CTL(pipe), 0);
5881 I915_WRITE(PF_WIN_POS(pipe), 0);
5882 I915_WRITE(PF_WIN_SZ(pipe), 0);
5886 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5887 struct drm_atomic_state *old_state)
5889 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5890 struct drm_device *dev = crtc->dev;
5891 struct drm_i915_private *dev_priv = to_i915(dev);
5892 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5893 int pipe = intel_crtc->pipe;
5896 * Sometimes spurious CPU pipe underruns happen when the
5897 * pipe is already disabled, but FDI RX/TX is still enabled.
5898 * Happens at least with VGA+HDMI cloning. Suppress them.
5900 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5901 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5903 intel_encoders_disable(crtc, old_crtc_state, old_state);
5905 drm_crtc_vblank_off(crtc);
5906 assert_vblank_disabled(crtc);
5908 intel_disable_pipe(old_crtc_state);
5910 ironlake_pfit_disable(intel_crtc, false);
5912 if (intel_crtc->config->has_pch_encoder)
5913 ironlake_fdi_disable(crtc);
5915 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5917 if (intel_crtc->config->has_pch_encoder) {
5918 ironlake_disable_pch_transcoder(dev_priv, pipe);
5920 if (HAS_PCH_CPT(dev_priv)) {
5924 /* disable TRANS_DP_CTL */
5925 reg = TRANS_DP_CTL(pipe);
5926 temp = I915_READ(reg);
5927 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5928 TRANS_DP_PORT_SEL_MASK);
5929 temp |= TRANS_DP_PORT_SEL_NONE;
5930 I915_WRITE(reg, temp);
5932 /* disable DPLL_SEL */
5933 temp = I915_READ(PCH_DPLL_SEL);
5934 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5935 I915_WRITE(PCH_DPLL_SEL, temp);
5938 ironlake_fdi_pll_disable(intel_crtc);
5941 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5942 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5945 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5946 struct drm_atomic_state *old_state)
5948 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5949 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5950 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5951 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
5953 intel_encoders_disable(crtc, old_crtc_state, old_state);
5955 drm_crtc_vblank_off(crtc);
5956 assert_vblank_disabled(crtc);
5958 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5959 if (!transcoder_is_dsi(cpu_transcoder))
5960 intel_disable_pipe(old_crtc_state);
5962 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
5963 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
5965 if (!transcoder_is_dsi(cpu_transcoder))
5966 intel_ddi_disable_transcoder_func(old_crtc_state);
5968 if (INTEL_GEN(dev_priv) >= 9)
5969 skylake_scaler_disable(intel_crtc);
5971 ironlake_pfit_disable(intel_crtc, false);
5973 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5975 if (INTEL_GEN(dev_priv) >= 11)
5976 icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state);
5979 static void i9xx_pfit_enable(struct intel_crtc *crtc)
5981 struct drm_device *dev = crtc->base.dev;
5982 struct drm_i915_private *dev_priv = to_i915(dev);
5983 struct intel_crtc_state *pipe_config = crtc->config;
5985 if (!pipe_config->gmch_pfit.control)
5989 * The panel fitter should only be adjusted whilst the pipe is disabled,
5990 * according to register description and PRM.
5992 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5993 assert_pipe_disabled(dev_priv, crtc->pipe);
5995 I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
5996 I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
5998 /* Border color in case we don't scale up to the full screen. Black by
5999 * default, change to something else for debugging. */
6000 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6003 bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
6005 if (port == PORT_NONE)
6008 if (IS_ICELAKE(dev_priv))
6009 return port <= PORT_B;
6014 bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
6016 if (IS_ICELAKE(dev_priv))
6017 return port >= PORT_C && port <= PORT_F;
6022 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6024 if (!intel_port_is_tc(dev_priv, port))
6025 return PORT_TC_NONE;
6027 return port - PORT_C;
6030 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
6034 return POWER_DOMAIN_PORT_DDI_A_LANES;
6036 return POWER_DOMAIN_PORT_DDI_B_LANES;
6038 return POWER_DOMAIN_PORT_DDI_C_LANES;
6040 return POWER_DOMAIN_PORT_DDI_D_LANES;
6042 return POWER_DOMAIN_PORT_DDI_E_LANES;
6044 return POWER_DOMAIN_PORT_DDI_F_LANES;
6047 return POWER_DOMAIN_PORT_OTHER;
6051 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
6052 struct intel_crtc_state *crtc_state)
6054 struct drm_device *dev = crtc->dev;
6055 struct drm_i915_private *dev_priv = to_i915(dev);
6056 struct drm_encoder *encoder;
6057 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6058 enum pipe pipe = intel_crtc->pipe;
6060 enum transcoder transcoder = crtc_state->cpu_transcoder;
6062 if (!crtc_state->base.active)
6065 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6066 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
6067 if (crtc_state->pch_pfit.enabled ||
6068 crtc_state->pch_pfit.force_thru)
6069 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
6071 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6072 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6074 mask |= BIT_ULL(intel_encoder->power_domain);
6077 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
6078 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
6080 if (crtc_state->shared_dpll)
6081 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
6087 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6088 struct intel_crtc_state *crtc_state)
6090 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6091 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6092 enum intel_display_power_domain domain;
6093 u64 domains, new_domains, old_domains;
6095 old_domains = intel_crtc->enabled_power_domains;
6096 intel_crtc->enabled_power_domains = new_domains =
6097 get_crtc_power_domains(crtc, crtc_state);
6099 domains = new_domains & ~old_domains;
6101 for_each_power_domain(domain, domains)
6102 intel_display_power_get(dev_priv, domain);
6104 return old_domains & ~new_domains;
6107 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6110 enum intel_display_power_domain domain;
6112 for_each_power_domain(domain, domains)
6113 intel_display_power_put(dev_priv, domain);
6116 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6117 struct drm_atomic_state *old_state)
6119 struct intel_atomic_state *old_intel_state =
6120 to_intel_atomic_state(old_state);
6121 struct drm_crtc *crtc = pipe_config->base.crtc;
6122 struct drm_device *dev = crtc->dev;
6123 struct drm_i915_private *dev_priv = to_i915(dev);
6124 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6125 int pipe = intel_crtc->pipe;
6127 if (WARN_ON(intel_crtc->active))
6130 if (intel_crtc_has_dp_encoder(intel_crtc->config))
6131 intel_dp_set_m_n(intel_crtc, M1_N1);
6133 intel_set_pipe_timings(intel_crtc);
6134 intel_set_pipe_src_size(intel_crtc);
6136 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6137 struct drm_i915_private *dev_priv = to_i915(dev);
6139 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6140 I915_WRITE(CHV_CANVAS(pipe), 0);
6143 i9xx_set_pipeconf(intel_crtc);
6145 intel_color_set_csc(&pipe_config->base);
6147 intel_crtc->active = true;
6149 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6151 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
6153 if (IS_CHERRYVIEW(dev_priv)) {
6154 chv_prepare_pll(intel_crtc, intel_crtc->config);
6155 chv_enable_pll(intel_crtc, intel_crtc->config);
6157 vlv_prepare_pll(intel_crtc, intel_crtc->config);
6158 vlv_enable_pll(intel_crtc, intel_crtc->config);
6161 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6163 i9xx_pfit_enable(intel_crtc);
6165 intel_color_load_luts(&pipe_config->base);
6167 dev_priv->display.initial_watermarks(old_intel_state,
6169 intel_enable_pipe(pipe_config);
6171 assert_vblank_disabled(crtc);
6172 drm_crtc_vblank_on(crtc);
6174 intel_encoders_enable(crtc, pipe_config, old_state);
6177 static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
6179 struct drm_device *dev = crtc->base.dev;
6180 struct drm_i915_private *dev_priv = to_i915(dev);
6182 I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
6183 I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
6186 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6187 struct drm_atomic_state *old_state)
6189 struct intel_atomic_state *old_intel_state =
6190 to_intel_atomic_state(old_state);
6191 struct drm_crtc *crtc = pipe_config->base.crtc;
6192 struct drm_device *dev = crtc->dev;
6193 struct drm_i915_private *dev_priv = to_i915(dev);
6194 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6195 enum pipe pipe = intel_crtc->pipe;
6197 if (WARN_ON(intel_crtc->active))
6200 i9xx_set_pll_dividers(intel_crtc);
6202 if (intel_crtc_has_dp_encoder(intel_crtc->config))
6203 intel_dp_set_m_n(intel_crtc, M1_N1);
6205 intel_set_pipe_timings(intel_crtc);
6206 intel_set_pipe_src_size(intel_crtc);
6208 i9xx_set_pipeconf(intel_crtc);
6210 intel_crtc->active = true;
6212 if (!IS_GEN2(dev_priv))
6213 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6215 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6217 i9xx_enable_pll(intel_crtc, pipe_config);
6219 i9xx_pfit_enable(intel_crtc);
6221 intel_color_load_luts(&pipe_config->base);
6223 if (dev_priv->display.initial_watermarks != NULL)
6224 dev_priv->display.initial_watermarks(old_intel_state,
6225 intel_crtc->config);
6227 intel_update_watermarks(intel_crtc);
6228 intel_enable_pipe(pipe_config);
6230 assert_vblank_disabled(crtc);
6231 drm_crtc_vblank_on(crtc);
6233 intel_encoders_enable(crtc, pipe_config, old_state);
6236 static void i9xx_pfit_disable(struct intel_crtc *crtc)
6238 struct drm_device *dev = crtc->base.dev;
6239 struct drm_i915_private *dev_priv = to_i915(dev);
6241 if (!crtc->config->gmch_pfit.control)
6244 assert_pipe_disabled(dev_priv, crtc->pipe);
6246 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6247 I915_READ(PFIT_CONTROL));
6248 I915_WRITE(PFIT_CONTROL, 0);
6251 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6252 struct drm_atomic_state *old_state)
6254 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6255 struct drm_device *dev = crtc->dev;
6256 struct drm_i915_private *dev_priv = to_i915(dev);
6257 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6258 int pipe = intel_crtc->pipe;
6261 * On gen2 planes are double buffered but the pipe isn't, so we must
6262 * wait for planes to fully turn off before disabling the pipe.
6264 if (IS_GEN2(dev_priv))
6265 intel_wait_for_vblank(dev_priv, pipe);
6267 intel_encoders_disable(crtc, old_crtc_state, old_state);
6269 drm_crtc_vblank_off(crtc);
6270 assert_vblank_disabled(crtc);
6272 intel_disable_pipe(old_crtc_state);
6274 i9xx_pfit_disable(intel_crtc);
6276 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6278 if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) {
6279 if (IS_CHERRYVIEW(dev_priv))
6280 chv_disable_pll(dev_priv, pipe);
6281 else if (IS_VALLEYVIEW(dev_priv))
6282 vlv_disable_pll(dev_priv, pipe);
6284 i9xx_disable_pll(intel_crtc);
6287 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6289 if (!IS_GEN2(dev_priv))
6290 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6292 if (!dev_priv->display.initial_watermarks)
6293 intel_update_watermarks(intel_crtc);
6295 /* clock the pipe down to 640x480@60 to potentially save power */
6296 if (IS_I830(dev_priv))
6297 i830_enable_pipe(dev_priv, pipe);
6300 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6301 struct drm_modeset_acquire_ctx *ctx)
6303 struct intel_encoder *encoder;
6304 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6305 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6306 enum intel_display_power_domain domain;
6307 struct intel_plane *plane;
6309 struct drm_atomic_state *state;
6310 struct intel_crtc_state *crtc_state;
6313 if (!intel_crtc->active)
6316 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6317 const struct intel_plane_state *plane_state =
6318 to_intel_plane_state(plane->base.state);
6320 if (plane_state->base.visible)
6321 intel_plane_disable_noatomic(intel_crtc, plane);
6324 state = drm_atomic_state_alloc(crtc->dev);
6326 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6327 crtc->base.id, crtc->name);
6331 state->acquire_ctx = ctx;
6333 /* Everything's already locked, -EDEADLK can't happen. */
6334 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6335 ret = drm_atomic_add_affected_connectors(state, crtc);
6337 WARN_ON(IS_ERR(crtc_state) || ret);
6339 dev_priv->display.crtc_disable(crtc_state, state);
6341 drm_atomic_state_put(state);
6343 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6344 crtc->base.id, crtc->name);
6346 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6347 crtc->state->active = false;
6348 intel_crtc->active = false;
6349 crtc->enabled = false;
6350 crtc->state->connector_mask = 0;
6351 crtc->state->encoder_mask = 0;
6353 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6354 encoder->base.crtc = NULL;
6356 intel_fbc_disable(intel_crtc);
6357 intel_update_watermarks(intel_crtc);
6358 intel_disable_shared_dpll(intel_crtc);
6360 domains = intel_crtc->enabled_power_domains;
6361 for_each_power_domain(domain, domains)
6362 intel_display_power_put(dev_priv, domain);
6363 intel_crtc->enabled_power_domains = 0;
6365 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6366 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6367 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6371 * turn all crtc's off, but do not adjust state
6372 * This has to be paired with a call to intel_modeset_setup_hw_state.
6374 int intel_display_suspend(struct drm_device *dev)
6376 struct drm_i915_private *dev_priv = to_i915(dev);
6377 struct drm_atomic_state *state;
6380 state = drm_atomic_helper_suspend(dev);
6381 ret = PTR_ERR_OR_ZERO(state);
6383 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6385 dev_priv->modeset_restore_state = state;
6389 void intel_encoder_destroy(struct drm_encoder *encoder)
6391 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6393 drm_encoder_cleanup(encoder);
6394 kfree(intel_encoder);
6397 /* Cross check the actual hw state with our own modeset state tracking (and it's
6398 * internal consistency). */
6399 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6400 struct drm_connector_state *conn_state)
6402 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6404 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6405 connector->base.base.id,
6406 connector->base.name);
6408 if (connector->get_hw_state(connector)) {
6409 struct intel_encoder *encoder = connector->encoder;
6411 I915_STATE_WARN(!crtc_state,
6412 "connector enabled without attached crtc\n");
6417 I915_STATE_WARN(!crtc_state->active,
6418 "connector is active, but attached crtc isn't\n");
6420 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6423 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6424 "atomic encoder doesn't match attached encoder\n");
6426 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6427 "attached encoder crtc differs from connector crtc\n");
6429 I915_STATE_WARN(crtc_state && crtc_state->active,
6430 "attached crtc is active, but connector isn't\n");
6431 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6432 "best encoder set without crtc!\n");
6436 int intel_connector_init(struct intel_connector *connector)
6438 struct intel_digital_connector_state *conn_state;
6441 * Allocate enough memory to hold intel_digital_connector_state,
6442 * This might be a few bytes too many, but for connectors that don't
6443 * need it we'll free the state and allocate a smaller one on the first
6444 * succesful commit anyway.
6446 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
6450 __drm_atomic_helper_connector_reset(&connector->base,
6456 struct intel_connector *intel_connector_alloc(void)
6458 struct intel_connector *connector;
6460 connector = kzalloc(sizeof *connector, GFP_KERNEL);
6464 if (intel_connector_init(connector) < 0) {
6473 * Free the bits allocated by intel_connector_alloc.
6474 * This should only be used after intel_connector_alloc has returned
6475 * successfully, and before drm_connector_init returns successfully.
6476 * Otherwise the destroy callbacks for the connector and the state should
6477 * take care of proper cleanup/free
6479 void intel_connector_free(struct intel_connector *connector)
6481 kfree(to_intel_digital_connector_state(connector->base.state));
6485 /* Simple connector->get_hw_state implementation for encoders that support only
6486 * one connector and no cloning and hence the encoder state determines the state
6487 * of the connector. */
6488 bool intel_connector_get_hw_state(struct intel_connector *connector)
6491 struct intel_encoder *encoder = connector->encoder;
6493 return encoder->get_hw_state(encoder, &pipe);
6496 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6498 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6499 return crtc_state->fdi_lanes;
6504 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6505 struct intel_crtc_state *pipe_config)
6507 struct drm_i915_private *dev_priv = to_i915(dev);
6508 struct drm_atomic_state *state = pipe_config->base.state;
6509 struct intel_crtc *other_crtc;
6510 struct intel_crtc_state *other_crtc_state;
6512 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6513 pipe_name(pipe), pipe_config->fdi_lanes);
6514 if (pipe_config->fdi_lanes > 4) {
6515 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6516 pipe_name(pipe), pipe_config->fdi_lanes);
6520 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6521 if (pipe_config->fdi_lanes > 2) {
6522 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6523 pipe_config->fdi_lanes);
6530 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6533 /* Ivybridge 3 pipe is really complicated */
6538 if (pipe_config->fdi_lanes <= 2)
6541 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6543 intel_atomic_get_crtc_state(state, other_crtc);
6544 if (IS_ERR(other_crtc_state))
6545 return PTR_ERR(other_crtc_state);
6547 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6548 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6549 pipe_name(pipe), pipe_config->fdi_lanes);
6554 if (pipe_config->fdi_lanes > 2) {
6555 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6556 pipe_name(pipe), pipe_config->fdi_lanes);
6560 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6562 intel_atomic_get_crtc_state(state, other_crtc);
6563 if (IS_ERR(other_crtc_state))
6564 return PTR_ERR(other_crtc_state);
6566 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6567 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6577 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6578 struct intel_crtc_state *pipe_config)
6580 struct drm_device *dev = intel_crtc->base.dev;
6581 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6582 int lane, link_bw, fdi_dotclock, ret;
6583 bool needs_recompute = false;
6586 /* FDI is a binary signal running at ~2.7GHz, encoding
6587 * each output octet as 10 bits. The actual frequency
6588 * is stored as a divider into a 100MHz clock, and the
6589 * mode pixel clock is stored in units of 1KHz.
6590 * Hence the bw of each lane in terms of the mode signal
6593 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6595 fdi_dotclock = adjusted_mode->crtc_clock;
6597 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6598 pipe_config->pipe_bpp);
6600 pipe_config->fdi_lanes = lane;
6602 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6603 link_bw, &pipe_config->fdi_m_n, false);
6605 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6606 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6607 pipe_config->pipe_bpp -= 2*3;
6608 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6609 pipe_config->pipe_bpp);
6610 needs_recompute = true;
6611 pipe_config->bw_constrained = true;
6616 if (needs_recompute)
6622 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6624 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6625 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6627 /* IPS only exists on ULT machines and is tied to pipe A. */
6628 if (!hsw_crtc_supports_ips(crtc))
6631 if (!i915_modparams.enable_ips)
6634 if (crtc_state->pipe_bpp > 24)
6638 * We compare against max which means we must take
6639 * the increased cdclk requirement into account when
6640 * calculating the new cdclk.
6642 * Should measure whether using a lower cdclk w/o IPS
6644 if (IS_BROADWELL(dev_priv) &&
6645 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6651 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6653 struct drm_i915_private *dev_priv =
6654 to_i915(crtc_state->base.crtc->dev);
6655 struct intel_atomic_state *intel_state =
6656 to_intel_atomic_state(crtc_state->base.state);
6658 if (!hsw_crtc_state_ips_capable(crtc_state))
6661 if (crtc_state->ips_force_disable)
6664 /* IPS should be fine as long as at least one plane is enabled. */
6665 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6668 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6669 if (IS_BROADWELL(dev_priv) &&
6670 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6676 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6678 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6680 /* GDG double wide on either pipe, otherwise pipe A only */
6681 return INTEL_GEN(dev_priv) < 4 &&
6682 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6685 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6687 uint32_t pixel_rate;
6689 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6692 * We only use IF-ID interlacing. If we ever use
6693 * PF-ID we'll need to adjust the pixel_rate here.
6696 if (pipe_config->pch_pfit.enabled) {
6697 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6698 uint32_t pfit_size = pipe_config->pch_pfit.size;
6700 pipe_w = pipe_config->pipe_src_w;
6701 pipe_h = pipe_config->pipe_src_h;
6703 pfit_w = (pfit_size >> 16) & 0xFFFF;
6704 pfit_h = pfit_size & 0xFFFF;
6705 if (pipe_w < pfit_w)
6707 if (pipe_h < pfit_h)
6710 if (WARN_ON(!pfit_w || !pfit_h))
6713 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6720 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6722 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6724 if (HAS_GMCH_DISPLAY(dev_priv))
6725 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6726 crtc_state->pixel_rate =
6727 crtc_state->base.adjusted_mode.crtc_clock;
6729 crtc_state->pixel_rate =
6730 ilk_pipe_pixel_rate(crtc_state);
6733 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6734 struct intel_crtc_state *pipe_config)
6736 struct drm_device *dev = crtc->base.dev;
6737 struct drm_i915_private *dev_priv = to_i915(dev);
6738 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6739 int clock_limit = dev_priv->max_dotclk_freq;
6741 if (INTEL_GEN(dev_priv) < 4) {
6742 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6745 * Enable double wide mode when the dot clock
6746 * is > 90% of the (display) core speed.
6748 if (intel_crtc_supports_double_wide(crtc) &&
6749 adjusted_mode->crtc_clock > clock_limit) {
6750 clock_limit = dev_priv->max_dotclk_freq;
6751 pipe_config->double_wide = true;
6755 if (adjusted_mode->crtc_clock > clock_limit) {
6756 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6757 adjusted_mode->crtc_clock, clock_limit,
6758 yesno(pipe_config->double_wide));
6762 if (pipe_config->ycbcr420 && pipe_config->base.ctm) {
6764 * There is only one pipe CSC unit per pipe, and we need that
6765 * for output conversion from RGB->YCBCR. So if CTM is already
6766 * applied we can't support YCBCR420 output.
6768 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6773 * Pipe horizontal size must be even in:
6775 * - LVDS dual channel mode
6776 * - Double wide pipe
6778 if (pipe_config->pipe_src_w & 1) {
6779 if (pipe_config->double_wide) {
6780 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6784 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6785 intel_is_dual_link_lvds(dev)) {
6786 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6791 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6792 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6794 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6795 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6798 intel_crtc_compute_pixel_rate(pipe_config);
6800 if (pipe_config->has_pch_encoder)
6801 return ironlake_fdi_compute_config(crtc, pipe_config);
6807 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6809 while (*num > DATA_LINK_M_N_MASK ||
6810 *den > DATA_LINK_M_N_MASK) {
6816 static void compute_m_n(unsigned int m, unsigned int n,
6817 uint32_t *ret_m, uint32_t *ret_n,
6821 * Several DP dongles in particular seem to be fussy about
6822 * too large link M/N values. Give N value as 0x8000 that
6823 * should be acceptable by specific devices. 0x8000 is the
6824 * specified fixed N value for asynchronous clock mode,
6825 * which the devices expect also in synchronous clock mode.
6830 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6832 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6833 intel_reduce_m_n_ratio(ret_m, ret_n);
6837 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6838 int pixel_clock, int link_clock,
6839 struct intel_link_m_n *m_n,
6844 compute_m_n(bits_per_pixel * pixel_clock,
6845 link_clock * nlanes * 8,
6846 &m_n->gmch_m, &m_n->gmch_n,
6849 compute_m_n(pixel_clock, link_clock,
6850 &m_n->link_m, &m_n->link_n,
6854 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6856 if (i915_modparams.panel_use_ssc >= 0)
6857 return i915_modparams.panel_use_ssc != 0;
6858 return dev_priv->vbt.lvds_use_ssc
6859 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6862 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
6864 return (1 << dpll->n) << 16 | dpll->m2;
6867 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6869 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
6872 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
6873 struct intel_crtc_state *crtc_state,
6874 struct dpll *reduced_clock)
6876 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6879 if (IS_PINEVIEW(dev_priv)) {
6880 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
6882 fp2 = pnv_dpll_compute_fp(reduced_clock);
6884 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
6886 fp2 = i9xx_dpll_compute_fp(reduced_clock);
6889 crtc_state->dpll_hw_state.fp0 = fp;
6891 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6893 crtc_state->dpll_hw_state.fp1 = fp2;
6895 crtc_state->dpll_hw_state.fp1 = fp;
6899 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6905 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6906 * and set it to a reasonable value instead.
6908 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6909 reg_val &= 0xffffff00;
6910 reg_val |= 0x00000030;
6911 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6913 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6914 reg_val &= 0x00ffffff;
6915 reg_val |= 0x8c000000;
6916 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6918 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6919 reg_val &= 0xffffff00;
6920 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6922 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6923 reg_val &= 0x00ffffff;
6924 reg_val |= 0xb0000000;
6925 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6928 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
6929 struct intel_link_m_n *m_n)
6931 struct drm_device *dev = crtc->base.dev;
6932 struct drm_i915_private *dev_priv = to_i915(dev);
6933 int pipe = crtc->pipe;
6935 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6936 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6937 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6938 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6941 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
6942 struct intel_link_m_n *m_n,
6943 struct intel_link_m_n *m2_n2)
6945 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6946 int pipe = crtc->pipe;
6947 enum transcoder transcoder = crtc->config->cpu_transcoder;
6949 if (INTEL_GEN(dev_priv) >= 5) {
6950 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6951 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6952 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6953 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
6954 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6955 * for gen < 8) and if DRRS is supported (to make sure the
6956 * registers are not unnecessarily accessed).
6958 if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
6959 INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
6960 I915_WRITE(PIPE_DATA_M2(transcoder),
6961 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6962 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6963 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6964 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6967 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6968 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6969 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6970 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
6974 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
6976 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6979 dp_m_n = &crtc->config->dp_m_n;
6980 dp_m2_n2 = &crtc->config->dp_m2_n2;
6981 } else if (m_n == M2_N2) {
6984 * M2_N2 registers are not supported. Hence m2_n2 divider value
6985 * needs to be programmed into M1_N1.
6987 dp_m_n = &crtc->config->dp_m2_n2;
6989 DRM_ERROR("Unsupported divider value\n");
6993 if (crtc->config->has_pch_encoder)
6994 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
6996 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
6999 static void vlv_compute_dpll(struct intel_crtc *crtc,
7000 struct intel_crtc_state *pipe_config)
7002 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
7003 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7004 if (crtc->pipe != PIPE_A)
7005 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7007 /* DPLL not used with DSI, but still need the rest set up */
7008 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7009 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7010 DPLL_EXT_BUFFER_ENABLE_VLV;
7012 pipe_config->dpll_hw_state.dpll_md =
7013 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7016 static void chv_compute_dpll(struct intel_crtc *crtc,
7017 struct intel_crtc_state *pipe_config)
7019 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
7020 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7021 if (crtc->pipe != PIPE_A)
7022 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7024 /* DPLL not used with DSI, but still need the rest set up */
7025 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7026 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
7028 pipe_config->dpll_hw_state.dpll_md =
7029 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7032 static void vlv_prepare_pll(struct intel_crtc *crtc,
7033 const struct intel_crtc_state *pipe_config)
7035 struct drm_device *dev = crtc->base.dev;
7036 struct drm_i915_private *dev_priv = to_i915(dev);
7037 enum pipe pipe = crtc->pipe;
7039 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7040 u32 coreclk, reg_val;
7043 I915_WRITE(DPLL(pipe),
7044 pipe_config->dpll_hw_state.dpll &
7045 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7047 /* No need to actually set up the DPLL with DSI */
7048 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7051 mutex_lock(&dev_priv->sb_lock);
7053 bestn = pipe_config->dpll.n;
7054 bestm1 = pipe_config->dpll.m1;
7055 bestm2 = pipe_config->dpll.m2;
7056 bestp1 = pipe_config->dpll.p1;
7057 bestp2 = pipe_config->dpll.p2;
7059 /* See eDP HDMI DPIO driver vbios notes doc */
7061 /* PLL B needs special handling */
7063 vlv_pllb_recal_opamp(dev_priv, pipe);
7065 /* Set up Tx target for periodic Rcomp update */
7066 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7068 /* Disable target IRef on PLL */
7069 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7070 reg_val &= 0x00ffffff;
7071 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7073 /* Disable fast lock */
7074 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7076 /* Set idtafcrecal before PLL is enabled */
7077 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7078 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7079 mdiv |= ((bestn << DPIO_N_SHIFT));
7080 mdiv |= (1 << DPIO_K_SHIFT);
7083 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7084 * but we don't support that).
7085 * Note: don't use the DAC post divider as it seems unstable.
7087 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7088 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7090 mdiv |= DPIO_ENABLE_CALIBRATION;
7091 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7093 /* Set HBR and RBR LPF coefficients */
7094 if (pipe_config->port_clock == 162000 ||
7095 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) ||
7096 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI))
7097 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7100 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7103 if (intel_crtc_has_dp_encoder(pipe_config)) {
7104 /* Use SSC source */
7106 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7109 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7111 } else { /* HDMI or VGA */
7112 /* Use bend source */
7114 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7117 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7121 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7122 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7123 if (intel_crtc_has_dp_encoder(crtc->config))
7124 coreclk |= 0x01000000;
7125 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7127 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7128 mutex_unlock(&dev_priv->sb_lock);
7131 static void chv_prepare_pll(struct intel_crtc *crtc,
7132 const struct intel_crtc_state *pipe_config)
7134 struct drm_device *dev = crtc->base.dev;
7135 struct drm_i915_private *dev_priv = to_i915(dev);
7136 enum pipe pipe = crtc->pipe;
7137 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7138 u32 loopfilter, tribuf_calcntr;
7139 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7143 /* Enable Refclk and SSC */
7144 I915_WRITE(DPLL(pipe),
7145 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7147 /* No need to actually set up the DPLL with DSI */
7148 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7151 bestn = pipe_config->dpll.n;
7152 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7153 bestm1 = pipe_config->dpll.m1;
7154 bestm2 = pipe_config->dpll.m2 >> 22;
7155 bestp1 = pipe_config->dpll.p1;
7156 bestp2 = pipe_config->dpll.p2;
7157 vco = pipe_config->dpll.vco;
7161 mutex_lock(&dev_priv->sb_lock);
7163 /* p1 and p2 divider */
7164 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7165 5 << DPIO_CHV_S1_DIV_SHIFT |
7166 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7167 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7168 1 << DPIO_CHV_K_DIV_SHIFT);
7170 /* Feedback post-divider - m2 */
7171 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7173 /* Feedback refclk divider - n and m1 */
7174 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7175 DPIO_CHV_M1_DIV_BY_2 |
7176 1 << DPIO_CHV_N_DIV_SHIFT);
7178 /* M2 fraction division */
7179 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7181 /* M2 fraction division enable */
7182 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7183 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7184 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7186 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7187 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7189 /* Program digital lock detect threshold */
7190 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7191 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7192 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7193 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7195 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7196 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7199 if (vco == 5400000) {
7200 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7201 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7202 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7203 tribuf_calcntr = 0x9;
7204 } else if (vco <= 6200000) {
7205 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7206 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7207 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7208 tribuf_calcntr = 0x9;
7209 } else if (vco <= 6480000) {
7210 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7211 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7212 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7213 tribuf_calcntr = 0x8;
7215 /* Not supported. Apply the same limits as in the max case */
7216 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7217 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7218 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7221 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7223 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7224 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7225 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7226 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7229 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7230 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7233 mutex_unlock(&dev_priv->sb_lock);
7237 * vlv_force_pll_on - forcibly enable just the PLL
7238 * @dev_priv: i915 private structure
7239 * @pipe: pipe PLL to enable
7240 * @dpll: PLL configuration
7242 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7243 * in cases where we need the PLL enabled even when @pipe is not going to
7246 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7247 const struct dpll *dpll)
7249 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7250 struct intel_crtc_state *pipe_config;
7252 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7256 pipe_config->base.crtc = &crtc->base;
7257 pipe_config->pixel_multiplier = 1;
7258 pipe_config->dpll = *dpll;
7260 if (IS_CHERRYVIEW(dev_priv)) {
7261 chv_compute_dpll(crtc, pipe_config);
7262 chv_prepare_pll(crtc, pipe_config);
7263 chv_enable_pll(crtc, pipe_config);
7265 vlv_compute_dpll(crtc, pipe_config);
7266 vlv_prepare_pll(crtc, pipe_config);
7267 vlv_enable_pll(crtc, pipe_config);
7276 * vlv_force_pll_off - forcibly disable just the PLL
7277 * @dev_priv: i915 private structure
7278 * @pipe: pipe PLL to disable
7280 * Disable the PLL for @pipe. To be used in cases where we need
7281 * the PLL enabled even when @pipe is not going to be enabled.
7283 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7285 if (IS_CHERRYVIEW(dev_priv))
7286 chv_disable_pll(dev_priv, pipe);
7288 vlv_disable_pll(dev_priv, pipe);
7291 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7292 struct intel_crtc_state *crtc_state,
7293 struct dpll *reduced_clock)
7295 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7297 struct dpll *clock = &crtc_state->dpll;
7299 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7301 dpll = DPLL_VGA_MODE_DIS;
7303 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7304 dpll |= DPLLB_MODE_LVDS;
7306 dpll |= DPLLB_MODE_DAC_SERIAL;
7308 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7309 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7310 dpll |= (crtc_state->pixel_multiplier - 1)
7311 << SDVO_MULTIPLIER_SHIFT_HIRES;
7314 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7315 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7316 dpll |= DPLL_SDVO_HIGH_SPEED;
7318 if (intel_crtc_has_dp_encoder(crtc_state))
7319 dpll |= DPLL_SDVO_HIGH_SPEED;
7321 /* compute bitmask from p1 value */
7322 if (IS_PINEVIEW(dev_priv))
7323 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7325 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7326 if (IS_G4X(dev_priv) && reduced_clock)
7327 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7329 switch (clock->p2) {
7331 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7334 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7337 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7340 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7343 if (INTEL_GEN(dev_priv) >= 4)
7344 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7346 if (crtc_state->sdvo_tv_clock)
7347 dpll |= PLL_REF_INPUT_TVCLKINBC;
7348 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7349 intel_panel_use_ssc(dev_priv))
7350 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7352 dpll |= PLL_REF_INPUT_DREFCLK;
7354 dpll |= DPLL_VCO_ENABLE;
7355 crtc_state->dpll_hw_state.dpll = dpll;
7357 if (INTEL_GEN(dev_priv) >= 4) {
7358 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7359 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7360 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7364 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7365 struct intel_crtc_state *crtc_state,
7366 struct dpll *reduced_clock)
7368 struct drm_device *dev = crtc->base.dev;
7369 struct drm_i915_private *dev_priv = to_i915(dev);
7371 struct dpll *clock = &crtc_state->dpll;
7373 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7375 dpll = DPLL_VGA_MODE_DIS;
7377 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7378 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7381 dpll |= PLL_P1_DIVIDE_BY_TWO;
7383 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7385 dpll |= PLL_P2_DIVIDE_BY_4;
7388 if (!IS_I830(dev_priv) &&
7389 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7390 dpll |= DPLL_DVO_2X_MODE;
7392 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7393 intel_panel_use_ssc(dev_priv))
7394 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7396 dpll |= PLL_REF_INPUT_DREFCLK;
7398 dpll |= DPLL_VCO_ENABLE;
7399 crtc_state->dpll_hw_state.dpll = dpll;
7402 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
7404 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7405 enum pipe pipe = intel_crtc->pipe;
7406 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
7407 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
7408 uint32_t crtc_vtotal, crtc_vblank_end;
7411 /* We need to be careful not to changed the adjusted mode, for otherwise
7412 * the hw state checker will get angry at the mismatch. */
7413 crtc_vtotal = adjusted_mode->crtc_vtotal;
7414 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7416 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7417 /* the chip adds 2 halflines automatically */
7419 crtc_vblank_end -= 1;
7421 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7422 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7424 vsyncshift = adjusted_mode->crtc_hsync_start -
7425 adjusted_mode->crtc_htotal / 2;
7427 vsyncshift += adjusted_mode->crtc_htotal;
7430 if (INTEL_GEN(dev_priv) > 3)
7431 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7433 I915_WRITE(HTOTAL(cpu_transcoder),
7434 (adjusted_mode->crtc_hdisplay - 1) |
7435 ((adjusted_mode->crtc_htotal - 1) << 16));
7436 I915_WRITE(HBLANK(cpu_transcoder),
7437 (adjusted_mode->crtc_hblank_start - 1) |
7438 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7439 I915_WRITE(HSYNC(cpu_transcoder),
7440 (adjusted_mode->crtc_hsync_start - 1) |
7441 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7443 I915_WRITE(VTOTAL(cpu_transcoder),
7444 (adjusted_mode->crtc_vdisplay - 1) |
7445 ((crtc_vtotal - 1) << 16));
7446 I915_WRITE(VBLANK(cpu_transcoder),
7447 (adjusted_mode->crtc_vblank_start - 1) |
7448 ((crtc_vblank_end - 1) << 16));
7449 I915_WRITE(VSYNC(cpu_transcoder),
7450 (adjusted_mode->crtc_vsync_start - 1) |
7451 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7453 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7454 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7455 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7457 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7458 (pipe == PIPE_B || pipe == PIPE_C))
7459 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7463 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc)
7465 struct drm_device *dev = intel_crtc->base.dev;
7466 struct drm_i915_private *dev_priv = to_i915(dev);
7467 enum pipe pipe = intel_crtc->pipe;
7469 /* pipesrc controls the size that is scaled from, which should
7470 * always be the user's requested size.
7472 I915_WRITE(PIPESRC(pipe),
7473 ((intel_crtc->config->pipe_src_w - 1) << 16) |
7474 (intel_crtc->config->pipe_src_h - 1));
7477 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7478 struct intel_crtc_state *pipe_config)
7480 struct drm_device *dev = crtc->base.dev;
7481 struct drm_i915_private *dev_priv = to_i915(dev);
7482 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7485 tmp = I915_READ(HTOTAL(cpu_transcoder));
7486 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7487 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7488 tmp = I915_READ(HBLANK(cpu_transcoder));
7489 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7490 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7491 tmp = I915_READ(HSYNC(cpu_transcoder));
7492 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7493 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7495 tmp = I915_READ(VTOTAL(cpu_transcoder));
7496 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7497 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7498 tmp = I915_READ(VBLANK(cpu_transcoder));
7499 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7500 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7501 tmp = I915_READ(VSYNC(cpu_transcoder));
7502 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7503 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7505 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7506 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7507 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7508 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7512 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7513 struct intel_crtc_state *pipe_config)
7515 struct drm_device *dev = crtc->base.dev;
7516 struct drm_i915_private *dev_priv = to_i915(dev);
7519 tmp = I915_READ(PIPESRC(crtc->pipe));
7520 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7521 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7523 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7524 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7527 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7528 struct intel_crtc_state *pipe_config)
7530 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7531 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7532 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7533 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7535 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7536 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7537 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7538 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7540 mode->flags = pipe_config->base.adjusted_mode.flags;
7541 mode->type = DRM_MODE_TYPE_DRIVER;
7543 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7545 mode->hsync = drm_mode_hsync(mode);
7546 mode->vrefresh = drm_mode_vrefresh(mode);
7547 drm_mode_set_name(mode);
7550 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
7552 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7557 /* we keep both pipes enabled on 830 */
7558 if (IS_I830(dev_priv))
7559 pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
7561 if (intel_crtc->config->double_wide)
7562 pipeconf |= PIPECONF_DOUBLE_WIDE;
7564 /* only g4x and later have fancy bpc/dither controls */
7565 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7566 IS_CHERRYVIEW(dev_priv)) {
7567 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7568 if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
7569 pipeconf |= PIPECONF_DITHER_EN |
7570 PIPECONF_DITHER_TYPE_SP;
7572 switch (intel_crtc->config->pipe_bpp) {
7574 pipeconf |= PIPECONF_6BPC;
7577 pipeconf |= PIPECONF_8BPC;
7580 pipeconf |= PIPECONF_10BPC;
7583 /* Case prevented by intel_choose_pipe_bpp_dither. */
7588 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7589 if (INTEL_GEN(dev_priv) < 4 ||
7590 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7591 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7593 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7595 pipeconf |= PIPECONF_PROGRESSIVE;
7597 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7598 intel_crtc->config->limited_color_range)
7599 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7601 I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
7602 POSTING_READ(PIPECONF(intel_crtc->pipe));
7605 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7606 struct intel_crtc_state *crtc_state)
7608 struct drm_device *dev = crtc->base.dev;
7609 struct drm_i915_private *dev_priv = to_i915(dev);
7610 const struct intel_limit *limit;
7613 memset(&crtc_state->dpll_hw_state, 0,
7614 sizeof(crtc_state->dpll_hw_state));
7616 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7617 if (intel_panel_use_ssc(dev_priv)) {
7618 refclk = dev_priv->vbt.lvds_ssc_freq;
7619 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7622 limit = &intel_limits_i8xx_lvds;
7623 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7624 limit = &intel_limits_i8xx_dvo;
7626 limit = &intel_limits_i8xx_dac;
7629 if (!crtc_state->clock_set &&
7630 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7631 refclk, NULL, &crtc_state->dpll)) {
7632 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7636 i8xx_compute_dpll(crtc, crtc_state, NULL);
7641 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7642 struct intel_crtc_state *crtc_state)
7644 struct drm_device *dev = crtc->base.dev;
7645 struct drm_i915_private *dev_priv = to_i915(dev);
7646 const struct intel_limit *limit;
7649 memset(&crtc_state->dpll_hw_state, 0,
7650 sizeof(crtc_state->dpll_hw_state));
7652 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7653 if (intel_panel_use_ssc(dev_priv)) {
7654 refclk = dev_priv->vbt.lvds_ssc_freq;
7655 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7658 if (intel_is_dual_link_lvds(dev))
7659 limit = &intel_limits_g4x_dual_channel_lvds;
7661 limit = &intel_limits_g4x_single_channel_lvds;
7662 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7663 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7664 limit = &intel_limits_g4x_hdmi;
7665 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7666 limit = &intel_limits_g4x_sdvo;
7668 /* The option is for other outputs */
7669 limit = &intel_limits_i9xx_sdvo;
7672 if (!crtc_state->clock_set &&
7673 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7674 refclk, NULL, &crtc_state->dpll)) {
7675 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7679 i9xx_compute_dpll(crtc, crtc_state, NULL);
7684 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7685 struct intel_crtc_state *crtc_state)
7687 struct drm_device *dev = crtc->base.dev;
7688 struct drm_i915_private *dev_priv = to_i915(dev);
7689 const struct intel_limit *limit;
7692 memset(&crtc_state->dpll_hw_state, 0,
7693 sizeof(crtc_state->dpll_hw_state));
7695 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7696 if (intel_panel_use_ssc(dev_priv)) {
7697 refclk = dev_priv->vbt.lvds_ssc_freq;
7698 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7701 limit = &intel_limits_pineview_lvds;
7703 limit = &intel_limits_pineview_sdvo;
7706 if (!crtc_state->clock_set &&
7707 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7708 refclk, NULL, &crtc_state->dpll)) {
7709 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7713 i9xx_compute_dpll(crtc, crtc_state, NULL);
7718 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7719 struct intel_crtc_state *crtc_state)
7721 struct drm_device *dev = crtc->base.dev;
7722 struct drm_i915_private *dev_priv = to_i915(dev);
7723 const struct intel_limit *limit;
7726 memset(&crtc_state->dpll_hw_state, 0,
7727 sizeof(crtc_state->dpll_hw_state));
7729 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7730 if (intel_panel_use_ssc(dev_priv)) {
7731 refclk = dev_priv->vbt.lvds_ssc_freq;
7732 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7735 limit = &intel_limits_i9xx_lvds;
7737 limit = &intel_limits_i9xx_sdvo;
7740 if (!crtc_state->clock_set &&
7741 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7742 refclk, NULL, &crtc_state->dpll)) {
7743 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7747 i9xx_compute_dpll(crtc, crtc_state, NULL);
7752 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7753 struct intel_crtc_state *crtc_state)
7755 int refclk = 100000;
7756 const struct intel_limit *limit = &intel_limits_chv;
7758 memset(&crtc_state->dpll_hw_state, 0,
7759 sizeof(crtc_state->dpll_hw_state));
7761 if (!crtc_state->clock_set &&
7762 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7763 refclk, NULL, &crtc_state->dpll)) {
7764 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7768 chv_compute_dpll(crtc, crtc_state);
7773 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7774 struct intel_crtc_state *crtc_state)
7776 int refclk = 100000;
7777 const struct intel_limit *limit = &intel_limits_vlv;
7779 memset(&crtc_state->dpll_hw_state, 0,
7780 sizeof(crtc_state->dpll_hw_state));
7782 if (!crtc_state->clock_set &&
7783 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7784 refclk, NULL, &crtc_state->dpll)) {
7785 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7789 vlv_compute_dpll(crtc, crtc_state);
7794 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7795 struct intel_crtc_state *pipe_config)
7797 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7800 if (INTEL_GEN(dev_priv) <= 3 &&
7801 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7804 tmp = I915_READ(PFIT_CONTROL);
7805 if (!(tmp & PFIT_ENABLE))
7808 /* Check whether the pfit is attached to our pipe. */
7809 if (INTEL_GEN(dev_priv) < 4) {
7810 if (crtc->pipe != PIPE_B)
7813 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7817 pipe_config->gmch_pfit.control = tmp;
7818 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7821 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7822 struct intel_crtc_state *pipe_config)
7824 struct drm_device *dev = crtc->base.dev;
7825 struct drm_i915_private *dev_priv = to_i915(dev);
7826 int pipe = pipe_config->cpu_transcoder;
7829 int refclk = 100000;
7831 /* In case of DSI, DPLL will not be used */
7832 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7835 mutex_lock(&dev_priv->sb_lock);
7836 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7837 mutex_unlock(&dev_priv->sb_lock);
7839 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7840 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7841 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7842 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7843 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7845 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7849 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7850 struct intel_initial_plane_config *plane_config)
7852 struct drm_device *dev = crtc->base.dev;
7853 struct drm_i915_private *dev_priv = to_i915(dev);
7854 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7855 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7857 u32 val, base, offset;
7858 int fourcc, pixel_format;
7859 unsigned int aligned_height;
7860 struct drm_framebuffer *fb;
7861 struct intel_framebuffer *intel_fb;
7863 if (!plane->get_hw_state(plane, &pipe))
7866 WARN_ON(pipe != crtc->pipe);
7868 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7870 DRM_DEBUG_KMS("failed to alloc fb\n");
7874 fb = &intel_fb->base;
7878 val = I915_READ(DSPCNTR(i9xx_plane));
7880 if (INTEL_GEN(dev_priv) >= 4) {
7881 if (val & DISPPLANE_TILED) {
7882 plane_config->tiling = I915_TILING_X;
7883 fb->modifier = I915_FORMAT_MOD_X_TILED;
7887 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7888 fourcc = i9xx_format_to_fourcc(pixel_format);
7889 fb->format = drm_format_info(fourcc);
7891 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7892 offset = I915_READ(DSPOFFSET(i9xx_plane));
7893 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7894 } else if (INTEL_GEN(dev_priv) >= 4) {
7895 if (plane_config->tiling)
7896 offset = I915_READ(DSPTILEOFF(i9xx_plane));
7898 offset = I915_READ(DSPLINOFF(i9xx_plane));
7899 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7901 base = I915_READ(DSPADDR(i9xx_plane));
7903 plane_config->base = base;
7905 val = I915_READ(PIPESRC(pipe));
7906 fb->width = ((val >> 16) & 0xfff) + 1;
7907 fb->height = ((val >> 0) & 0xfff) + 1;
7909 val = I915_READ(DSPSTRIDE(i9xx_plane));
7910 fb->pitches[0] = val & 0xffffffc0;
7912 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7914 plane_config->size = fb->pitches[0] * aligned_height;
7916 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7917 crtc->base.name, plane->base.name, fb->width, fb->height,
7918 fb->format->cpp[0] * 8, base, fb->pitches[0],
7919 plane_config->size);
7921 plane_config->fb = intel_fb;
7924 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7925 struct intel_crtc_state *pipe_config)
7927 struct drm_device *dev = crtc->base.dev;
7928 struct drm_i915_private *dev_priv = to_i915(dev);
7929 int pipe = pipe_config->cpu_transcoder;
7930 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7932 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7933 int refclk = 100000;
7935 /* In case of DSI, DPLL will not be used */
7936 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7939 mutex_lock(&dev_priv->sb_lock);
7940 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7941 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7942 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7943 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7944 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7945 mutex_unlock(&dev_priv->sb_lock);
7947 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7948 clock.m2 = (pll_dw0 & 0xff) << 22;
7949 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7950 clock.m2 |= pll_dw2 & 0x3fffff;
7951 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7952 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7953 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7955 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7958 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7959 struct intel_crtc_state *pipe_config)
7961 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7962 enum intel_display_power_domain power_domain;
7966 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7967 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7970 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7971 pipe_config->shared_dpll = NULL;
7975 tmp = I915_READ(PIPECONF(crtc->pipe));
7976 if (!(tmp & PIPECONF_ENABLE))
7979 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7980 IS_CHERRYVIEW(dev_priv)) {
7981 switch (tmp & PIPECONF_BPC_MASK) {
7983 pipe_config->pipe_bpp = 18;
7986 pipe_config->pipe_bpp = 24;
7988 case PIPECONF_10BPC:
7989 pipe_config->pipe_bpp = 30;
7996 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7997 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7998 pipe_config->limited_color_range = true;
8000 if (INTEL_GEN(dev_priv) < 4)
8001 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8003 intel_get_pipe_timings(crtc, pipe_config);
8004 intel_get_pipe_src_size(crtc, pipe_config);
8006 i9xx_get_pfit_config(crtc, pipe_config);
8008 if (INTEL_GEN(dev_priv) >= 4) {
8009 /* No way to read it out on pipes B and C */
8010 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
8011 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8013 tmp = I915_READ(DPLL_MD(crtc->pipe));
8014 pipe_config->pixel_multiplier =
8015 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8016 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8017 pipe_config->dpll_hw_state.dpll_md = tmp;
8018 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8019 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8020 tmp = I915_READ(DPLL(crtc->pipe));
8021 pipe_config->pixel_multiplier =
8022 ((tmp & SDVO_MULTIPLIER_MASK)
8023 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8025 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8026 * port and will be fixed up in the encoder->get_config
8028 pipe_config->pixel_multiplier = 1;
8030 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8031 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
8033 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8034 * on 830. Filter it out here so that we don't
8035 * report errors due to that.
8037 if (IS_I830(dev_priv))
8038 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8040 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8041 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8043 /* Mask out read-only status bits. */
8044 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8045 DPLL_PORTC_READY_MASK |
8046 DPLL_PORTB_READY_MASK);
8049 if (IS_CHERRYVIEW(dev_priv))
8050 chv_crtc_clock_get(crtc, pipe_config);
8051 else if (IS_VALLEYVIEW(dev_priv))
8052 vlv_crtc_clock_get(crtc, pipe_config);
8054 i9xx_crtc_clock_get(crtc, pipe_config);
8057 * Normally the dotclock is filled in by the encoder .get_config()
8058 * but in case the pipe is enabled w/o any ports we need a sane
8061 pipe_config->base.adjusted_mode.crtc_clock =
8062 pipe_config->port_clock / pipe_config->pixel_multiplier;
8067 intel_display_power_put(dev_priv, power_domain);
8072 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
8074 struct intel_encoder *encoder;
8077 bool has_lvds = false;
8078 bool has_cpu_edp = false;
8079 bool has_panel = false;
8080 bool has_ck505 = false;
8081 bool can_ssc = false;
8082 bool using_ssc_source = false;
8084 /* We need to take the global config into account */
8085 for_each_intel_encoder(&dev_priv->drm, encoder) {
8086 switch (encoder->type) {
8087 case INTEL_OUTPUT_LVDS:
8091 case INTEL_OUTPUT_EDP:
8093 if (encoder->port == PORT_A)
8101 if (HAS_PCH_IBX(dev_priv)) {
8102 has_ck505 = dev_priv->vbt.display_clock_mode;
8103 can_ssc = has_ck505;
8109 /* Check if any DPLLs are using the SSC source */
8110 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8111 u32 temp = I915_READ(PCH_DPLL(i));
8113 if (!(temp & DPLL_VCO_ENABLE))
8116 if ((temp & PLL_REF_INPUT_MASK) ==
8117 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8118 using_ssc_source = true;
8123 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8124 has_panel, has_lvds, has_ck505, using_ssc_source);
8126 /* Ironlake: try to setup display ref clock before DPLL
8127 * enabling. This is only under driver's control after
8128 * PCH B stepping, previous chipset stepping should be
8129 * ignoring this setting.
8131 val = I915_READ(PCH_DREF_CONTROL);
8133 /* As we must carefully and slowly disable/enable each source in turn,
8134 * compute the final state we want first and check if we need to
8135 * make any changes at all.
8138 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8140 final |= DREF_NONSPREAD_CK505_ENABLE;
8142 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8144 final &= ~DREF_SSC_SOURCE_MASK;
8145 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8146 final &= ~DREF_SSC1_ENABLE;
8149 final |= DREF_SSC_SOURCE_ENABLE;
8151 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8152 final |= DREF_SSC1_ENABLE;
8155 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8156 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8158 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8160 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8161 } else if (using_ssc_source) {
8162 final |= DREF_SSC_SOURCE_ENABLE;
8163 final |= DREF_SSC1_ENABLE;
8169 /* Always enable nonspread source */
8170 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8173 val |= DREF_NONSPREAD_CK505_ENABLE;
8175 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8178 val &= ~DREF_SSC_SOURCE_MASK;
8179 val |= DREF_SSC_SOURCE_ENABLE;
8181 /* SSC must be turned on before enabling the CPU output */
8182 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8183 DRM_DEBUG_KMS("Using SSC on panel\n");
8184 val |= DREF_SSC1_ENABLE;
8186 val &= ~DREF_SSC1_ENABLE;
8188 /* Get SSC going before enabling the outputs */
8189 I915_WRITE(PCH_DREF_CONTROL, val);
8190 POSTING_READ(PCH_DREF_CONTROL);
8193 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8195 /* Enable CPU source on CPU attached eDP */
8197 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8198 DRM_DEBUG_KMS("Using SSC on eDP\n");
8199 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8201 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8203 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8205 I915_WRITE(PCH_DREF_CONTROL, val);
8206 POSTING_READ(PCH_DREF_CONTROL);
8209 DRM_DEBUG_KMS("Disabling CPU source output\n");
8211 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8213 /* Turn off CPU output */
8214 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8216 I915_WRITE(PCH_DREF_CONTROL, val);
8217 POSTING_READ(PCH_DREF_CONTROL);
8220 if (!using_ssc_source) {
8221 DRM_DEBUG_KMS("Disabling SSC source\n");
8223 /* Turn off the SSC source */
8224 val &= ~DREF_SSC_SOURCE_MASK;
8225 val |= DREF_SSC_SOURCE_DISABLE;
8228 val &= ~DREF_SSC1_ENABLE;
8230 I915_WRITE(PCH_DREF_CONTROL, val);
8231 POSTING_READ(PCH_DREF_CONTROL);
8236 BUG_ON(val != final);
8239 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8243 tmp = I915_READ(SOUTH_CHICKEN2);
8244 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8245 I915_WRITE(SOUTH_CHICKEN2, tmp);
8247 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8248 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8249 DRM_ERROR("FDI mPHY reset assert timeout\n");
8251 tmp = I915_READ(SOUTH_CHICKEN2);
8252 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8253 I915_WRITE(SOUTH_CHICKEN2, tmp);
8255 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8256 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8257 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8260 /* WaMPhyProgramming:hsw */
8261 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8265 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8266 tmp &= ~(0xFF << 24);
8267 tmp |= (0x12 << 24);
8268 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8270 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8272 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8274 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8276 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8278 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8279 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8280 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8282 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8283 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8284 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8286 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8289 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8291 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8294 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8296 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8299 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8301 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8304 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8306 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8307 tmp &= ~(0xFF << 16);
8308 tmp |= (0x1C << 16);
8309 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8311 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8312 tmp &= ~(0xFF << 16);
8313 tmp |= (0x1C << 16);
8314 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8316 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8318 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8320 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8322 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8324 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8325 tmp &= ~(0xF << 28);
8327 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8329 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8330 tmp &= ~(0xF << 28);
8332 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8335 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8336 * Programming" based on the parameters passed:
8337 * - Sequence to enable CLKOUT_DP
8338 * - Sequence to enable CLKOUT_DP without spread
8339 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8341 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8342 bool with_spread, bool with_fdi)
8346 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8348 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8349 with_fdi, "LP PCH doesn't have FDI\n"))
8352 mutex_lock(&dev_priv->sb_lock);
8354 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8355 tmp &= ~SBI_SSCCTL_DISABLE;
8356 tmp |= SBI_SSCCTL_PATHALT;
8357 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8362 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8363 tmp &= ~SBI_SSCCTL_PATHALT;
8364 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8367 lpt_reset_fdi_mphy(dev_priv);
8368 lpt_program_fdi_mphy(dev_priv);
8372 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8373 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8374 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8375 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8377 mutex_unlock(&dev_priv->sb_lock);
8380 /* Sequence to disable CLKOUT_DP */
8381 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8385 mutex_lock(&dev_priv->sb_lock);
8387 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8388 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8389 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8390 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8392 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8393 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8394 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8395 tmp |= SBI_SSCCTL_PATHALT;
8396 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8399 tmp |= SBI_SSCCTL_DISABLE;
8400 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8403 mutex_unlock(&dev_priv->sb_lock);
8406 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8408 static const uint16_t sscdivintphase[] = {
8409 [BEND_IDX( 50)] = 0x3B23,
8410 [BEND_IDX( 45)] = 0x3B23,
8411 [BEND_IDX( 40)] = 0x3C23,
8412 [BEND_IDX( 35)] = 0x3C23,
8413 [BEND_IDX( 30)] = 0x3D23,
8414 [BEND_IDX( 25)] = 0x3D23,
8415 [BEND_IDX( 20)] = 0x3E23,
8416 [BEND_IDX( 15)] = 0x3E23,
8417 [BEND_IDX( 10)] = 0x3F23,
8418 [BEND_IDX( 5)] = 0x3F23,
8419 [BEND_IDX( 0)] = 0x0025,
8420 [BEND_IDX( -5)] = 0x0025,
8421 [BEND_IDX(-10)] = 0x0125,
8422 [BEND_IDX(-15)] = 0x0125,
8423 [BEND_IDX(-20)] = 0x0225,
8424 [BEND_IDX(-25)] = 0x0225,
8425 [BEND_IDX(-30)] = 0x0325,
8426 [BEND_IDX(-35)] = 0x0325,
8427 [BEND_IDX(-40)] = 0x0425,
8428 [BEND_IDX(-45)] = 0x0425,
8429 [BEND_IDX(-50)] = 0x0525,
8434 * steps -50 to 50 inclusive, in steps of 5
8435 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8436 * change in clock period = -(steps / 10) * 5.787 ps
8438 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8441 int idx = BEND_IDX(steps);
8443 if (WARN_ON(steps % 5 != 0))
8446 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8449 mutex_lock(&dev_priv->sb_lock);
8451 if (steps % 10 != 0)
8455 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8457 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8459 tmp |= sscdivintphase[idx];
8460 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8462 mutex_unlock(&dev_priv->sb_lock);
8467 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8469 struct intel_encoder *encoder;
8470 bool has_vga = false;
8472 for_each_intel_encoder(&dev_priv->drm, encoder) {
8473 switch (encoder->type) {
8474 case INTEL_OUTPUT_ANALOG:
8483 lpt_bend_clkout_dp(dev_priv, 0);
8484 lpt_enable_clkout_dp(dev_priv, true, true);
8486 lpt_disable_clkout_dp(dev_priv);
8491 * Initialize reference clocks when the driver loads
8493 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8495 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8496 ironlake_init_pch_refclk(dev_priv);
8497 else if (HAS_PCH_LPT(dev_priv))
8498 lpt_init_pch_refclk(dev_priv);
8501 static void ironlake_set_pipeconf(struct drm_crtc *crtc)
8503 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8504 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8505 int pipe = intel_crtc->pipe;
8510 switch (intel_crtc->config->pipe_bpp) {
8512 val |= PIPECONF_6BPC;
8515 val |= PIPECONF_8BPC;
8518 val |= PIPECONF_10BPC;
8521 val |= PIPECONF_12BPC;
8524 /* Case prevented by intel_choose_pipe_bpp_dither. */
8528 if (intel_crtc->config->dither)
8529 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8531 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8532 val |= PIPECONF_INTERLACED_ILK;
8534 val |= PIPECONF_PROGRESSIVE;
8536 if (intel_crtc->config->limited_color_range)
8537 val |= PIPECONF_COLOR_RANGE_SELECT;
8539 I915_WRITE(PIPECONF(pipe), val);
8540 POSTING_READ(PIPECONF(pipe));
8543 static void haswell_set_pipeconf(struct drm_crtc *crtc)
8545 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8546 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8547 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
8550 if (IS_HASWELL(dev_priv) && intel_crtc->config->dither)
8551 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8553 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8554 val |= PIPECONF_INTERLACED_ILK;
8556 val |= PIPECONF_PROGRESSIVE;
8558 I915_WRITE(PIPECONF(cpu_transcoder), val);
8559 POSTING_READ(PIPECONF(cpu_transcoder));
8562 static void haswell_set_pipemisc(struct drm_crtc *crtc)
8564 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8565 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8566 struct intel_crtc_state *config = intel_crtc->config;
8568 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8571 switch (intel_crtc->config->pipe_bpp) {
8573 val |= PIPEMISC_DITHER_6_BPC;
8576 val |= PIPEMISC_DITHER_8_BPC;
8579 val |= PIPEMISC_DITHER_10_BPC;
8582 val |= PIPEMISC_DITHER_12_BPC;
8585 /* Case prevented by pipe_config_set_bpp. */
8589 if (intel_crtc->config->dither)
8590 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8592 if (config->ycbcr420) {
8593 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV |
8594 PIPEMISC_YUV420_ENABLE |
8595 PIPEMISC_YUV420_MODE_FULL_BLEND;
8598 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8602 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8605 * Account for spread spectrum to avoid
8606 * oversubscribing the link. Max center spread
8607 * is 2.5%; use 5% for safety's sake.
8609 u32 bps = target_clock * bpp * 21 / 20;
8610 return DIV_ROUND_UP(bps, link_bw * 8);
8613 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8615 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8618 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8619 struct intel_crtc_state *crtc_state,
8620 struct dpll *reduced_clock)
8622 struct drm_crtc *crtc = &intel_crtc->base;
8623 struct drm_device *dev = crtc->dev;
8624 struct drm_i915_private *dev_priv = to_i915(dev);
8628 /* Enable autotuning of the PLL clock (if permissible) */
8630 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8631 if ((intel_panel_use_ssc(dev_priv) &&
8632 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8633 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8635 } else if (crtc_state->sdvo_tv_clock)
8638 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8640 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8643 if (reduced_clock) {
8644 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8646 if (reduced_clock->m < factor * reduced_clock->n)
8654 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8655 dpll |= DPLLB_MODE_LVDS;
8657 dpll |= DPLLB_MODE_DAC_SERIAL;
8659 dpll |= (crtc_state->pixel_multiplier - 1)
8660 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8662 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8663 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8664 dpll |= DPLL_SDVO_HIGH_SPEED;
8666 if (intel_crtc_has_dp_encoder(crtc_state))
8667 dpll |= DPLL_SDVO_HIGH_SPEED;
8670 * The high speed IO clock is only really required for
8671 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8672 * possible to share the DPLL between CRT and HDMI. Enabling
8673 * the clock needlessly does no real harm, except use up a
8674 * bit of power potentially.
8676 * We'll limit this to IVB with 3 pipes, since it has only two
8677 * DPLLs and so DPLL sharing is the only way to get three pipes
8678 * driving PCH ports at the same time. On SNB we could do this,
8679 * and potentially avoid enabling the second DPLL, but it's not
8680 * clear if it''s a win or loss power wise. No point in doing
8681 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8683 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8684 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8685 dpll |= DPLL_SDVO_HIGH_SPEED;
8687 /* compute bitmask from p1 value */
8688 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8690 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8692 switch (crtc_state->dpll.p2) {
8694 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8697 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8700 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8703 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8707 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8708 intel_panel_use_ssc(dev_priv))
8709 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8711 dpll |= PLL_REF_INPUT_DREFCLK;
8713 dpll |= DPLL_VCO_ENABLE;
8715 crtc_state->dpll_hw_state.dpll = dpll;
8716 crtc_state->dpll_hw_state.fp0 = fp;
8717 crtc_state->dpll_hw_state.fp1 = fp2;
8720 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8721 struct intel_crtc_state *crtc_state)
8723 struct drm_device *dev = crtc->base.dev;
8724 struct drm_i915_private *dev_priv = to_i915(dev);
8725 const struct intel_limit *limit;
8726 int refclk = 120000;
8728 memset(&crtc_state->dpll_hw_state, 0,
8729 sizeof(crtc_state->dpll_hw_state));
8731 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8732 if (!crtc_state->has_pch_encoder)
8735 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8736 if (intel_panel_use_ssc(dev_priv)) {
8737 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8738 dev_priv->vbt.lvds_ssc_freq);
8739 refclk = dev_priv->vbt.lvds_ssc_freq;
8742 if (intel_is_dual_link_lvds(dev)) {
8743 if (refclk == 100000)
8744 limit = &intel_limits_ironlake_dual_lvds_100m;
8746 limit = &intel_limits_ironlake_dual_lvds;
8748 if (refclk == 100000)
8749 limit = &intel_limits_ironlake_single_lvds_100m;
8751 limit = &intel_limits_ironlake_single_lvds;
8754 limit = &intel_limits_ironlake_dac;
8757 if (!crtc_state->clock_set &&
8758 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8759 refclk, NULL, &crtc_state->dpll)) {
8760 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8764 ironlake_compute_dpll(crtc, crtc_state, NULL);
8766 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8767 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8768 pipe_name(crtc->pipe));
8775 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8776 struct intel_link_m_n *m_n)
8778 struct drm_device *dev = crtc->base.dev;
8779 struct drm_i915_private *dev_priv = to_i915(dev);
8780 enum pipe pipe = crtc->pipe;
8782 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8783 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8784 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8786 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8787 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8788 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8791 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8792 enum transcoder transcoder,
8793 struct intel_link_m_n *m_n,
8794 struct intel_link_m_n *m2_n2)
8796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8797 enum pipe pipe = crtc->pipe;
8799 if (INTEL_GEN(dev_priv) >= 5) {
8800 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8801 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8802 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8804 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8805 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8806 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8807 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8808 * gen < 8) and if DRRS is supported (to make sure the
8809 * registers are not unnecessarily read).
8811 if (m2_n2 && INTEL_GEN(dev_priv) < 8 &&
8812 crtc->config->has_drrs) {
8813 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8814 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8815 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8817 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8818 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8819 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8822 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8823 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8824 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8826 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8827 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8828 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8832 void intel_dp_get_m_n(struct intel_crtc *crtc,
8833 struct intel_crtc_state *pipe_config)
8835 if (pipe_config->has_pch_encoder)
8836 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8838 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8839 &pipe_config->dp_m_n,
8840 &pipe_config->dp_m2_n2);
8843 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8844 struct intel_crtc_state *pipe_config)
8846 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8847 &pipe_config->fdi_m_n, NULL);
8850 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8851 struct intel_crtc_state *pipe_config)
8853 struct drm_device *dev = crtc->base.dev;
8854 struct drm_i915_private *dev_priv = to_i915(dev);
8855 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8856 uint32_t ps_ctrl = 0;
8860 /* find scaler attached to this pipe */
8861 for (i = 0; i < crtc->num_scalers; i++) {
8862 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8863 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8865 pipe_config->pch_pfit.enabled = true;
8866 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8867 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8872 scaler_state->scaler_id = id;
8874 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8876 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8881 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8882 struct intel_initial_plane_config *plane_config)
8884 struct drm_device *dev = crtc->base.dev;
8885 struct drm_i915_private *dev_priv = to_i915(dev);
8886 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8887 enum plane_id plane_id = plane->id;
8889 u32 val, base, offset, stride_mult, tiling, alpha;
8890 int fourcc, pixel_format;
8891 unsigned int aligned_height;
8892 struct drm_framebuffer *fb;
8893 struct intel_framebuffer *intel_fb;
8895 if (!plane->get_hw_state(plane, &pipe))
8898 WARN_ON(pipe != crtc->pipe);
8900 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8902 DRM_DEBUG_KMS("failed to alloc fb\n");
8906 fb = &intel_fb->base;
8910 val = I915_READ(PLANE_CTL(pipe, plane_id));
8912 if (INTEL_GEN(dev_priv) >= 11)
8913 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8915 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8917 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8918 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
8919 alpha &= PLANE_COLOR_ALPHA_MASK;
8921 alpha = val & PLANE_CTL_ALPHA_MASK;
8924 fourcc = skl_format_to_fourcc(pixel_format,
8925 val & PLANE_CTL_ORDER_RGBX, alpha);
8926 fb->format = drm_format_info(fourcc);
8928 tiling = val & PLANE_CTL_TILED_MASK;
8930 case PLANE_CTL_TILED_LINEAR:
8931 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8933 case PLANE_CTL_TILED_X:
8934 plane_config->tiling = I915_TILING_X;
8935 fb->modifier = I915_FORMAT_MOD_X_TILED;
8937 case PLANE_CTL_TILED_Y:
8938 plane_config->tiling = I915_TILING_Y;
8939 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8940 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8942 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8944 case PLANE_CTL_TILED_YF:
8945 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8946 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8948 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8951 MISSING_CASE(tiling);
8955 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8956 plane_config->base = base;
8958 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
8960 val = I915_READ(PLANE_SIZE(pipe, plane_id));
8961 fb->height = ((val >> 16) & 0xfff) + 1;
8962 fb->width = ((val >> 0) & 0x1fff) + 1;
8964 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
8965 stride_mult = intel_fb_stride_alignment(fb, 0);
8966 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8968 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8970 plane_config->size = fb->pitches[0] * aligned_height;
8972 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8973 crtc->base.name, plane->base.name, fb->width, fb->height,
8974 fb->format->cpp[0] * 8, base, fb->pitches[0],
8975 plane_config->size);
8977 plane_config->fb = intel_fb;
8984 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
8985 struct intel_crtc_state *pipe_config)
8987 struct drm_device *dev = crtc->base.dev;
8988 struct drm_i915_private *dev_priv = to_i915(dev);
8991 tmp = I915_READ(PF_CTL(crtc->pipe));
8993 if (tmp & PF_ENABLE) {
8994 pipe_config->pch_pfit.enabled = true;
8995 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8996 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
8998 /* We currently do not free assignements of panel fitters on
8999 * ivb/hsw (since we don't use the higher upscaling modes which
9000 * differentiates them) so just WARN about this case for now. */
9001 if (IS_GEN7(dev_priv)) {
9002 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9003 PF_PIPE_SEL_IVB(crtc->pipe));
9008 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9009 struct intel_crtc_state *pipe_config)
9011 struct drm_device *dev = crtc->base.dev;
9012 struct drm_i915_private *dev_priv = to_i915(dev);
9013 enum intel_display_power_domain power_domain;
9017 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9018 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9021 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9022 pipe_config->shared_dpll = NULL;
9025 tmp = I915_READ(PIPECONF(crtc->pipe));
9026 if (!(tmp & PIPECONF_ENABLE))
9029 switch (tmp & PIPECONF_BPC_MASK) {
9031 pipe_config->pipe_bpp = 18;
9034 pipe_config->pipe_bpp = 24;
9036 case PIPECONF_10BPC:
9037 pipe_config->pipe_bpp = 30;
9039 case PIPECONF_12BPC:
9040 pipe_config->pipe_bpp = 36;
9046 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9047 pipe_config->limited_color_range = true;
9049 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9050 struct intel_shared_dpll *pll;
9051 enum intel_dpll_id pll_id;
9053 pipe_config->has_pch_encoder = true;
9055 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9056 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9057 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9059 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9061 if (HAS_PCH_IBX(dev_priv)) {
9063 * The pipe->pch transcoder and pch transcoder->pll
9066 pll_id = (enum intel_dpll_id) crtc->pipe;
9068 tmp = I915_READ(PCH_DPLL_SEL);
9069 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
9070 pll_id = DPLL_ID_PCH_PLL_B;
9072 pll_id= DPLL_ID_PCH_PLL_A;
9075 pipe_config->shared_dpll =
9076 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9077 pll = pipe_config->shared_dpll;
9079 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9080 &pipe_config->dpll_hw_state));
9082 tmp = pipe_config->dpll_hw_state.dpll;
9083 pipe_config->pixel_multiplier =
9084 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9085 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
9087 ironlake_pch_clock_get(crtc, pipe_config);
9089 pipe_config->pixel_multiplier = 1;
9092 intel_get_pipe_timings(crtc, pipe_config);
9093 intel_get_pipe_src_size(crtc, pipe_config);
9095 ironlake_get_pfit_config(crtc, pipe_config);
9100 intel_display_power_put(dev_priv, power_domain);
9105 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9107 struct drm_device *dev = &dev_priv->drm;
9108 struct intel_crtc *crtc;
9110 for_each_intel_crtc(dev, crtc)
9111 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
9112 pipe_name(crtc->pipe));
9114 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
9115 "Display power well on\n");
9116 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
9117 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9118 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
9119 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
9120 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
9121 "CPU PWM1 enabled\n");
9122 if (IS_HASWELL(dev_priv))
9123 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
9124 "CPU PWM2 enabled\n");
9125 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
9126 "PCH PWM1 enabled\n");
9127 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
9128 "Utility pin enabled\n");
9129 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
9132 * In theory we can still leave IRQs enabled, as long as only the HPD
9133 * interrupts remain enabled. We used to check for that, but since it's
9134 * gen-specific and since we only disable LCPLL after we fully disable
9135 * the interrupts, the check below should be enough.
9137 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
9140 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9142 if (IS_HASWELL(dev_priv))
9143 return I915_READ(D_COMP_HSW);
9145 return I915_READ(D_COMP_BDW);
9148 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9150 if (IS_HASWELL(dev_priv)) {
9151 mutex_lock(&dev_priv->pcu_lock);
9152 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9154 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
9155 mutex_unlock(&dev_priv->pcu_lock);
9157 I915_WRITE(D_COMP_BDW, val);
9158 POSTING_READ(D_COMP_BDW);
9163 * This function implements pieces of two sequences from BSpec:
9164 * - Sequence for display software to disable LCPLL
9165 * - Sequence for display software to allow package C8+
9166 * The steps implemented here are just the steps that actually touch the LCPLL
9167 * register. Callers should take care of disabling all the display engine
9168 * functions, doing the mode unset, fixing interrupts, etc.
9170 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9171 bool switch_to_fclk, bool allow_power_down)
9175 assert_can_disable_lcpll(dev_priv);
9177 val = I915_READ(LCPLL_CTL);
9179 if (switch_to_fclk) {
9180 val |= LCPLL_CD_SOURCE_FCLK;
9181 I915_WRITE(LCPLL_CTL, val);
9183 if (wait_for_us(I915_READ(LCPLL_CTL) &
9184 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9185 DRM_ERROR("Switching to FCLK failed\n");
9187 val = I915_READ(LCPLL_CTL);
9190 val |= LCPLL_PLL_DISABLE;
9191 I915_WRITE(LCPLL_CTL, val);
9192 POSTING_READ(LCPLL_CTL);
9194 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
9195 DRM_ERROR("LCPLL still locked\n");
9197 val = hsw_read_dcomp(dev_priv);
9198 val |= D_COMP_COMP_DISABLE;
9199 hsw_write_dcomp(dev_priv, val);
9202 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9204 DRM_ERROR("D_COMP RCOMP still in progress\n");
9206 if (allow_power_down) {
9207 val = I915_READ(LCPLL_CTL);
9208 val |= LCPLL_POWER_DOWN_ALLOW;
9209 I915_WRITE(LCPLL_CTL, val);
9210 POSTING_READ(LCPLL_CTL);
9215 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9218 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9222 val = I915_READ(LCPLL_CTL);
9224 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9225 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9229 * Make sure we're not on PC8 state before disabling PC8, otherwise
9230 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9232 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9234 if (val & LCPLL_POWER_DOWN_ALLOW) {
9235 val &= ~LCPLL_POWER_DOWN_ALLOW;
9236 I915_WRITE(LCPLL_CTL, val);
9237 POSTING_READ(LCPLL_CTL);
9240 val = hsw_read_dcomp(dev_priv);
9241 val |= D_COMP_COMP_FORCE;
9242 val &= ~D_COMP_COMP_DISABLE;
9243 hsw_write_dcomp(dev_priv, val);
9245 val = I915_READ(LCPLL_CTL);
9246 val &= ~LCPLL_PLL_DISABLE;
9247 I915_WRITE(LCPLL_CTL, val);
9249 if (intel_wait_for_register(dev_priv,
9250 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9252 DRM_ERROR("LCPLL not locked yet\n");
9254 if (val & LCPLL_CD_SOURCE_FCLK) {
9255 val = I915_READ(LCPLL_CTL);
9256 val &= ~LCPLL_CD_SOURCE_FCLK;
9257 I915_WRITE(LCPLL_CTL, val);
9259 if (wait_for_us((I915_READ(LCPLL_CTL) &
9260 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9261 DRM_ERROR("Switching back to LCPLL failed\n");
9264 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9266 intel_update_cdclk(dev_priv);
9267 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
9271 * Package states C8 and deeper are really deep PC states that can only be
9272 * reached when all the devices on the system allow it, so even if the graphics
9273 * device allows PC8+, it doesn't mean the system will actually get to these
9274 * states. Our driver only allows PC8+ when going into runtime PM.
9276 * The requirements for PC8+ are that all the outputs are disabled, the power
9277 * well is disabled and most interrupts are disabled, and these are also
9278 * requirements for runtime PM. When these conditions are met, we manually do
9279 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9280 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9283 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9284 * the state of some registers, so when we come back from PC8+ we need to
9285 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9286 * need to take care of the registers kept by RC6. Notice that this happens even
9287 * if we don't put the device in PCI D3 state (which is what currently happens
9288 * because of the runtime PM support).
9290 * For more, read "Display Sequences for Package C8" on the hardware
9293 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9297 DRM_DEBUG_KMS("Enabling package C8+\n");
9299 if (HAS_PCH_LPT_LP(dev_priv)) {
9300 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9301 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9302 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9305 lpt_disable_clkout_dp(dev_priv);
9306 hsw_disable_lcpll(dev_priv, true, true);
9309 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9313 DRM_DEBUG_KMS("Disabling package C8+\n");
9315 hsw_restore_lcpll(dev_priv);
9316 lpt_init_pch_refclk(dev_priv);
9318 if (HAS_PCH_LPT_LP(dev_priv)) {
9319 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9320 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9321 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9325 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9326 struct intel_crtc_state *crtc_state)
9328 struct intel_atomic_state *state =
9329 to_intel_atomic_state(crtc_state->base.state);
9331 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
9332 struct intel_encoder *encoder =
9333 intel_get_crtc_new_encoder(state, crtc_state);
9335 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9336 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9337 pipe_name(crtc->pipe));
9345 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9347 struct intel_crtc_state *pipe_config)
9349 enum intel_dpll_id id;
9352 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9353 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9355 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9358 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9361 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9363 struct intel_crtc_state *pipe_config)
9365 enum intel_dpll_id id;
9368 /* TODO: TBT pll not implemented. */
9372 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9373 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9374 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9376 if (WARN_ON(id != DPLL_ID_ICL_DPLL0 && id != DPLL_ID_ICL_DPLL1))
9380 id = DPLL_ID_ICL_MGPLL1;
9383 id = DPLL_ID_ICL_MGPLL2;
9386 id = DPLL_ID_ICL_MGPLL3;
9389 id = DPLL_ID_ICL_MGPLL4;
9396 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9399 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9401 struct intel_crtc_state *pipe_config)
9403 enum intel_dpll_id id;
9407 id = DPLL_ID_SKL_DPLL0;
9410 id = DPLL_ID_SKL_DPLL1;
9413 id = DPLL_ID_SKL_DPLL2;
9416 DRM_ERROR("Incorrect port type\n");
9420 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9423 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9425 struct intel_crtc_state *pipe_config)
9427 enum intel_dpll_id id;
9430 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9431 id = temp >> (port * 3 + 1);
9433 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9436 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9439 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9441 struct intel_crtc_state *pipe_config)
9443 enum intel_dpll_id id;
9444 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9446 switch (ddi_pll_sel) {
9447 case PORT_CLK_SEL_WRPLL1:
9448 id = DPLL_ID_WRPLL1;
9450 case PORT_CLK_SEL_WRPLL2:
9451 id = DPLL_ID_WRPLL2;
9453 case PORT_CLK_SEL_SPLL:
9456 case PORT_CLK_SEL_LCPLL_810:
9457 id = DPLL_ID_LCPLL_810;
9459 case PORT_CLK_SEL_LCPLL_1350:
9460 id = DPLL_ID_LCPLL_1350;
9462 case PORT_CLK_SEL_LCPLL_2700:
9463 id = DPLL_ID_LCPLL_2700;
9466 MISSING_CASE(ddi_pll_sel);
9468 case PORT_CLK_SEL_NONE:
9472 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9475 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9476 struct intel_crtc_state *pipe_config,
9477 u64 *power_domain_mask)
9479 struct drm_device *dev = crtc->base.dev;
9480 struct drm_i915_private *dev_priv = to_i915(dev);
9481 enum intel_display_power_domain power_domain;
9485 * The pipe->transcoder mapping is fixed with the exception of the eDP
9486 * transcoder handled below.
9488 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9491 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9492 * consistency and less surprising code; it's in always on power).
9494 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9495 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9496 enum pipe trans_edp_pipe;
9497 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9499 WARN(1, "unknown pipe linked to edp transcoder\n");
9501 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9502 case TRANS_DDI_EDP_INPUT_A_ON:
9503 trans_edp_pipe = PIPE_A;
9505 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9506 trans_edp_pipe = PIPE_B;
9508 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9509 trans_edp_pipe = PIPE_C;
9513 if (trans_edp_pipe == crtc->pipe)
9514 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9517 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9518 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9520 *power_domain_mask |= BIT_ULL(power_domain);
9522 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9524 return tmp & PIPECONF_ENABLE;
9527 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9528 struct intel_crtc_state *pipe_config,
9529 u64 *power_domain_mask)
9531 struct drm_device *dev = crtc->base.dev;
9532 struct drm_i915_private *dev_priv = to_i915(dev);
9533 enum intel_display_power_domain power_domain;
9535 enum transcoder cpu_transcoder;
9538 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9540 cpu_transcoder = TRANSCODER_DSI_A;
9542 cpu_transcoder = TRANSCODER_DSI_C;
9544 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9545 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9547 *power_domain_mask |= BIT_ULL(power_domain);
9550 * The PLL needs to be enabled with a valid divider
9551 * configuration, otherwise accessing DSI registers will hang
9552 * the machine. See BSpec North Display Engine
9553 * registers/MIPI[BXT]. We can break out here early, since we
9554 * need the same DSI PLL to be enabled for both DSI ports.
9556 if (!bxt_dsi_pll_is_enabled(dev_priv))
9559 /* XXX: this works for video mode only */
9560 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9561 if (!(tmp & DPI_ENABLE))
9564 tmp = I915_READ(MIPI_CTRL(port));
9565 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9568 pipe_config->cpu_transcoder = cpu_transcoder;
9572 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9575 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9576 struct intel_crtc_state *pipe_config)
9578 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9579 struct intel_shared_dpll *pll;
9583 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9585 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9587 if (IS_ICELAKE(dev_priv))
9588 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9589 else if (IS_CANNONLAKE(dev_priv))
9590 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9591 else if (IS_GEN9_BC(dev_priv))
9592 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9593 else if (IS_GEN9_LP(dev_priv))
9594 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9596 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9598 pll = pipe_config->shared_dpll;
9600 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9601 &pipe_config->dpll_hw_state));
9605 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9606 * DDI E. So just check whether this pipe is wired to DDI E and whether
9607 * the PCH transcoder is on.
9609 if (INTEL_GEN(dev_priv) < 9 &&
9610 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9611 pipe_config->has_pch_encoder = true;
9613 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9614 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9615 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9617 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9621 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9622 struct intel_crtc_state *pipe_config)
9624 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9625 enum intel_display_power_domain power_domain;
9626 u64 power_domain_mask;
9629 intel_crtc_init_scalers(crtc, pipe_config);
9631 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9632 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9634 power_domain_mask = BIT_ULL(power_domain);
9636 pipe_config->shared_dpll = NULL;
9638 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9640 if (IS_GEN9_LP(dev_priv) &&
9641 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9649 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9650 haswell_get_ddi_port_state(crtc, pipe_config);
9651 intel_get_pipe_timings(crtc, pipe_config);
9654 intel_get_pipe_src_size(crtc, pipe_config);
9656 pipe_config->gamma_mode =
9657 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9659 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
9660 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
9661 bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV;
9663 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
9664 bool blend_mode_420 = tmp &
9665 PIPEMISC_YUV420_MODE_FULL_BLEND;
9667 pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE;
9668 if (pipe_config->ycbcr420 != clrspace_yuv ||
9669 pipe_config->ycbcr420 != blend_mode_420)
9670 DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp);
9671 } else if (clrspace_yuv) {
9672 DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
9676 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9677 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9678 power_domain_mask |= BIT_ULL(power_domain);
9679 if (INTEL_GEN(dev_priv) >= 9)
9680 skylake_get_pfit_config(crtc, pipe_config);
9682 ironlake_get_pfit_config(crtc, pipe_config);
9685 if (hsw_crtc_supports_ips(crtc)) {
9686 if (IS_HASWELL(dev_priv))
9687 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9690 * We cannot readout IPS state on broadwell, set to
9691 * true so we can set it to a defined state on first
9694 pipe_config->ips_enabled = true;
9698 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9699 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9700 pipe_config->pixel_multiplier =
9701 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9703 pipe_config->pixel_multiplier = 1;
9707 for_each_power_domain(power_domain, power_domain_mask)
9708 intel_display_power_put(dev_priv, power_domain);
9713 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9715 struct drm_i915_private *dev_priv =
9716 to_i915(plane_state->base.plane->dev);
9717 const struct drm_framebuffer *fb = plane_state->base.fb;
9718 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9721 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9722 base = obj->phys_handle->busaddr;
9724 base = intel_plane_ggtt_offset(plane_state);
9726 base += plane_state->color_plane[0].offset;
9728 /* ILK+ do this automagically */
9729 if (HAS_GMCH_DISPLAY(dev_priv) &&
9730 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9731 base += (plane_state->base.crtc_h *
9732 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9737 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9739 int x = plane_state->base.crtc_x;
9740 int y = plane_state->base.crtc_y;
9744 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9747 pos |= x << CURSOR_X_SHIFT;
9750 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9753 pos |= y << CURSOR_Y_SHIFT;
9758 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9760 const struct drm_mode_config *config =
9761 &plane_state->base.plane->dev->mode_config;
9762 int width = plane_state->base.crtc_w;
9763 int height = plane_state->base.crtc_h;
9765 return width > 0 && width <= config->cursor_width &&
9766 height > 0 && height <= config->cursor_height;
9769 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
9771 const struct drm_framebuffer *fb = plane_state->base.fb;
9772 unsigned int rotation = plane_state->base.rotation;
9777 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
9778 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
9780 ret = intel_plane_check_stride(plane_state);
9784 src_x = plane_state->base.src_x >> 16;
9785 src_y = plane_state->base.src_y >> 16;
9787 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9788 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
9791 if (src_x != 0 || src_y != 0) {
9792 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9796 plane_state->color_plane[0].offset = offset;
9801 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9802 struct intel_plane_state *plane_state)
9804 const struct drm_framebuffer *fb = plane_state->base.fb;
9807 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9808 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9812 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9814 DRM_PLANE_HELPER_NO_SCALING,
9815 DRM_PLANE_HELPER_NO_SCALING,
9820 if (!plane_state->base.visible)
9823 ret = intel_plane_check_src_coordinates(plane_state);
9827 ret = intel_cursor_check_surface(plane_state);
9835 i845_cursor_max_stride(struct intel_plane *plane,
9836 u32 pixel_format, u64 modifier,
9837 unsigned int rotation)
9842 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9843 const struct intel_plane_state *plane_state)
9845 return CURSOR_ENABLE |
9846 CURSOR_GAMMA_ENABLE |
9847 CURSOR_FORMAT_ARGB |
9848 CURSOR_STRIDE(plane_state->color_plane[0].stride);
9851 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9853 int width = plane_state->base.crtc_w;
9856 * 845g/865g are only limited by the width of their cursors,
9857 * the height is arbitrary up to the precision of the register.
9859 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
9862 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
9863 struct intel_plane_state *plane_state)
9865 const struct drm_framebuffer *fb = plane_state->base.fb;
9868 ret = intel_check_cursor(crtc_state, plane_state);
9872 /* if we want to turn off the cursor ignore width and height */
9876 /* Check for which cursor types we support */
9877 if (!i845_cursor_size_ok(plane_state)) {
9878 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9879 plane_state->base.crtc_w,
9880 plane_state->base.crtc_h);
9884 WARN_ON(plane_state->base.visible &&
9885 plane_state->color_plane[0].stride != fb->pitches[0]);
9887 switch (fb->pitches[0]) {
9894 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9899 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9904 static void i845_update_cursor(struct intel_plane *plane,
9905 const struct intel_crtc_state *crtc_state,
9906 const struct intel_plane_state *plane_state)
9908 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9909 u32 cntl = 0, base = 0, pos = 0, size = 0;
9910 unsigned long irqflags;
9912 if (plane_state && plane_state->base.visible) {
9913 unsigned int width = plane_state->base.crtc_w;
9914 unsigned int height = plane_state->base.crtc_h;
9916 cntl = plane_state->ctl;
9917 size = (height << 12) | width;
9919 base = intel_cursor_base(plane_state);
9920 pos = intel_cursor_position(plane_state);
9923 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9925 /* On these chipsets we can only modify the base/size/stride
9926 * whilst the cursor is disabled.
9928 if (plane->cursor.base != base ||
9929 plane->cursor.size != size ||
9930 plane->cursor.cntl != cntl) {
9931 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
9932 I915_WRITE_FW(CURBASE(PIPE_A), base);
9933 I915_WRITE_FW(CURSIZE, size);
9934 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9935 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
9937 plane->cursor.base = base;
9938 plane->cursor.size = size;
9939 plane->cursor.cntl = cntl;
9941 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9944 POSTING_READ_FW(CURCNTR(PIPE_A));
9946 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9949 static void i845_disable_cursor(struct intel_plane *plane,
9950 struct intel_crtc *crtc)
9952 i845_update_cursor(plane, NULL, NULL);
9955 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
9958 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9959 enum intel_display_power_domain power_domain;
9962 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9963 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9966 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9970 intel_display_power_put(dev_priv, power_domain);
9976 i9xx_cursor_max_stride(struct intel_plane *plane,
9977 u32 pixel_format, u64 modifier,
9978 unsigned int rotation)
9980 return plane->base.dev->mode_config.cursor_width * 4;
9983 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9984 const struct intel_plane_state *plane_state)
9986 struct drm_i915_private *dev_priv =
9987 to_i915(plane_state->base.plane->dev);
9988 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9991 if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
9992 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
9994 if (INTEL_GEN(dev_priv) <= 10) {
9995 cntl |= MCURSOR_GAMMA_ENABLE;
9997 if (HAS_DDI(dev_priv))
9998 cntl |= MCURSOR_PIPE_CSC_ENABLE;
10001 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10002 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
10004 switch (plane_state->base.crtc_w) {
10006 cntl |= MCURSOR_MODE_64_ARGB_AX;
10009 cntl |= MCURSOR_MODE_128_ARGB_AX;
10012 cntl |= MCURSOR_MODE_256_ARGB_AX;
10015 MISSING_CASE(plane_state->base.crtc_w);
10019 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
10020 cntl |= MCURSOR_ROTATE_180;
10025 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
10027 struct drm_i915_private *dev_priv =
10028 to_i915(plane_state->base.plane->dev);
10029 int width = plane_state->base.crtc_w;
10030 int height = plane_state->base.crtc_h;
10032 if (!intel_cursor_size_ok(plane_state))
10035 /* Cursor width is limited to a few power-of-two sizes */
10046 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10047 * height from 8 lines up to the cursor width, when the
10048 * cursor is not rotated. Everything else requires square
10051 if (HAS_CUR_FBC(dev_priv) &&
10052 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
10053 if (height < 8 || height > width)
10056 if (height != width)
10063 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
10064 struct intel_plane_state *plane_state)
10066 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
10067 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10068 const struct drm_framebuffer *fb = plane_state->base.fb;
10069 enum pipe pipe = plane->pipe;
10072 ret = intel_check_cursor(crtc_state, plane_state);
10076 /* if we want to turn off the cursor ignore width and height */
10080 /* Check for which cursor types we support */
10081 if (!i9xx_cursor_size_ok(plane_state)) {
10082 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10083 plane_state->base.crtc_w,
10084 plane_state->base.crtc_h);
10088 WARN_ON(plane_state->base.visible &&
10089 plane_state->color_plane[0].stride != fb->pitches[0]);
10091 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10092 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10093 fb->pitches[0], plane_state->base.crtc_w);
10098 * There's something wrong with the cursor on CHV pipe C.
10099 * If it straddles the left edge of the screen then
10100 * moving it away from the edge or disabling it often
10101 * results in a pipe underrun, and often that can lead to
10102 * dead pipe (constant underrun reported, and it scans
10103 * out just a solid color). To recover from that, the
10104 * display power well must be turned off and on again.
10105 * Refuse the put the cursor into that compromised position.
10107 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10108 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10109 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10113 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10118 static void i9xx_update_cursor(struct intel_plane *plane,
10119 const struct intel_crtc_state *crtc_state,
10120 const struct intel_plane_state *plane_state)
10122 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10123 enum pipe pipe = plane->pipe;
10124 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
10125 unsigned long irqflags;
10127 if (plane_state && plane_state->base.visible) {
10128 cntl = plane_state->ctl;
10130 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10131 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10133 base = intel_cursor_base(plane_state);
10134 pos = intel_cursor_position(plane_state);
10137 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10140 * On some platforms writing CURCNTR first will also
10141 * cause CURPOS to be armed by the CURBASE write.
10142 * Without the CURCNTR write the CURPOS write would
10143 * arm itself. Thus we always start the full update
10144 * with a CURCNTR write.
10146 * On other platforms CURPOS always requires the
10147 * CURBASE write to arm the update. Additonally
10148 * a write to any of the cursor register will cancel
10149 * an already armed cursor update. Thus leaving out
10150 * the CURBASE write after CURPOS could lead to a
10151 * cursor that doesn't appear to move, or even change
10152 * shape. Thus we always write CURBASE.
10154 * CURCNTR and CUR_FBC_CTL are always
10155 * armed by the CURBASE write only.
10157 if (plane->cursor.base != base ||
10158 plane->cursor.size != fbc_ctl ||
10159 plane->cursor.cntl != cntl) {
10160 I915_WRITE_FW(CURCNTR(pipe), cntl);
10161 if (HAS_CUR_FBC(dev_priv))
10162 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
10163 I915_WRITE_FW(CURPOS(pipe), pos);
10164 I915_WRITE_FW(CURBASE(pipe), base);
10166 plane->cursor.base = base;
10167 plane->cursor.size = fbc_ctl;
10168 plane->cursor.cntl = cntl;
10170 I915_WRITE_FW(CURPOS(pipe), pos);
10171 I915_WRITE_FW(CURBASE(pipe), base);
10174 POSTING_READ_FW(CURBASE(pipe));
10176 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10179 static void i9xx_disable_cursor(struct intel_plane *plane,
10180 struct intel_crtc *crtc)
10182 i9xx_update_cursor(plane, NULL, NULL);
10185 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10188 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10189 enum intel_display_power_domain power_domain;
10194 * Not 100% correct for planes that can move between pipes,
10195 * but that's only the case for gen2-3 which don't have any
10196 * display power wells.
10198 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
10199 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
10202 val = I915_READ(CURCNTR(plane->pipe));
10204 ret = val & MCURSOR_MODE;
10206 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10207 *pipe = plane->pipe;
10209 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10210 MCURSOR_PIPE_SELECT_SHIFT;
10212 intel_display_power_put(dev_priv, power_domain);
10217 /* VESA 640x480x72Hz mode to set on the pipe */
10218 static const struct drm_display_mode load_detect_mode = {
10219 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10220 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10223 struct drm_framebuffer *
10224 intel_framebuffer_create(struct drm_i915_gem_object *obj,
10225 struct drm_mode_fb_cmd2 *mode_cmd)
10227 struct intel_framebuffer *intel_fb;
10230 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10232 return ERR_PTR(-ENOMEM);
10234 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
10238 return &intel_fb->base;
10242 return ERR_PTR(ret);
10245 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10246 struct drm_crtc *crtc)
10248 struct drm_plane *plane;
10249 struct drm_plane_state *plane_state;
10252 ret = drm_atomic_add_affected_planes(state, crtc);
10256 for_each_new_plane_in_state(state, plane, plane_state, i) {
10257 if (plane_state->crtc != crtc)
10260 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10264 drm_atomic_set_fb_for_plane(plane_state, NULL);
10270 int intel_get_load_detect_pipe(struct drm_connector *connector,
10271 const struct drm_display_mode *mode,
10272 struct intel_load_detect_pipe *old,
10273 struct drm_modeset_acquire_ctx *ctx)
10275 struct intel_crtc *intel_crtc;
10276 struct intel_encoder *intel_encoder =
10277 intel_attached_encoder(connector);
10278 struct drm_crtc *possible_crtc;
10279 struct drm_encoder *encoder = &intel_encoder->base;
10280 struct drm_crtc *crtc = NULL;
10281 struct drm_device *dev = encoder->dev;
10282 struct drm_i915_private *dev_priv = to_i915(dev);
10283 struct drm_mode_config *config = &dev->mode_config;
10284 struct drm_atomic_state *state = NULL, *restore_state = NULL;
10285 struct drm_connector_state *connector_state;
10286 struct intel_crtc_state *crtc_state;
10289 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10290 connector->base.id, connector->name,
10291 encoder->base.id, encoder->name);
10293 old->restore_state = NULL;
10295 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
10298 * Algorithm gets a little messy:
10300 * - if the connector already has an assigned crtc, use it (but make
10301 * sure it's on first)
10303 * - try to find the first unused crtc that can drive this connector,
10304 * and use that if we find one
10307 /* See if we already have a CRTC for this connector */
10308 if (connector->state->crtc) {
10309 crtc = connector->state->crtc;
10311 ret = drm_modeset_lock(&crtc->mutex, ctx);
10315 /* Make sure the crtc and connector are running */
10319 /* Find an unused one (if possible) */
10320 for_each_crtc(dev, possible_crtc) {
10322 if (!(encoder->possible_crtcs & (1 << i)))
10325 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10329 if (possible_crtc->state->enable) {
10330 drm_modeset_unlock(&possible_crtc->mutex);
10334 crtc = possible_crtc;
10339 * If we didn't find an unused CRTC, don't use any.
10342 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10348 intel_crtc = to_intel_crtc(crtc);
10350 state = drm_atomic_state_alloc(dev);
10351 restore_state = drm_atomic_state_alloc(dev);
10352 if (!state || !restore_state) {
10357 state->acquire_ctx = ctx;
10358 restore_state->acquire_ctx = ctx;
10360 connector_state = drm_atomic_get_connector_state(state, connector);
10361 if (IS_ERR(connector_state)) {
10362 ret = PTR_ERR(connector_state);
10366 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10370 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10371 if (IS_ERR(crtc_state)) {
10372 ret = PTR_ERR(crtc_state);
10376 crtc_state->base.active = crtc_state->base.enable = true;
10379 mode = &load_detect_mode;
10381 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
10385 ret = intel_modeset_disable_planes(state, crtc);
10389 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10391 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
10393 ret = drm_atomic_add_affected_planes(restore_state, crtc);
10395 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10399 ret = drm_atomic_commit(state);
10401 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10405 old->restore_state = restore_state;
10406 drm_atomic_state_put(state);
10408 /* let the connector get through one full cycle before testing */
10409 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
10414 drm_atomic_state_put(state);
10417 if (restore_state) {
10418 drm_atomic_state_put(restore_state);
10419 restore_state = NULL;
10422 if (ret == -EDEADLK)
10428 void intel_release_load_detect_pipe(struct drm_connector *connector,
10429 struct intel_load_detect_pipe *old,
10430 struct drm_modeset_acquire_ctx *ctx)
10432 struct intel_encoder *intel_encoder =
10433 intel_attached_encoder(connector);
10434 struct drm_encoder *encoder = &intel_encoder->base;
10435 struct drm_atomic_state *state = old->restore_state;
10438 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10439 connector->base.id, connector->name,
10440 encoder->base.id, encoder->name);
10445 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10447 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10448 drm_atomic_state_put(state);
10451 static int i9xx_pll_refclk(struct drm_device *dev,
10452 const struct intel_crtc_state *pipe_config)
10454 struct drm_i915_private *dev_priv = to_i915(dev);
10455 u32 dpll = pipe_config->dpll_hw_state.dpll;
10457 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10458 return dev_priv->vbt.lvds_ssc_freq;
10459 else if (HAS_PCH_SPLIT(dev_priv))
10461 else if (!IS_GEN2(dev_priv))
10467 /* Returns the clock of the currently programmed mode of the given pipe. */
10468 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10469 struct intel_crtc_state *pipe_config)
10471 struct drm_device *dev = crtc->base.dev;
10472 struct drm_i915_private *dev_priv = to_i915(dev);
10473 int pipe = pipe_config->cpu_transcoder;
10474 u32 dpll = pipe_config->dpll_hw_state.dpll;
10478 int refclk = i9xx_pll_refclk(dev, pipe_config);
10480 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10481 fp = pipe_config->dpll_hw_state.fp0;
10483 fp = pipe_config->dpll_hw_state.fp1;
10485 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10486 if (IS_PINEVIEW(dev_priv)) {
10487 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10488 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10490 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10491 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10494 if (!IS_GEN2(dev_priv)) {
10495 if (IS_PINEVIEW(dev_priv))
10496 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10497 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10499 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10500 DPLL_FPA01_P1_POST_DIV_SHIFT);
10502 switch (dpll & DPLL_MODE_MASK) {
10503 case DPLLB_MODE_DAC_SERIAL:
10504 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10507 case DPLLB_MODE_LVDS:
10508 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10512 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10513 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10517 if (IS_PINEVIEW(dev_priv))
10518 port_clock = pnv_calc_dpll_params(refclk, &clock);
10520 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10522 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10523 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10526 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10527 DPLL_FPA01_P1_POST_DIV_SHIFT);
10529 if (lvds & LVDS_CLKB_POWER_UP)
10534 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10537 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10538 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10540 if (dpll & PLL_P2_DIVIDE_BY_4)
10546 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10550 * This value includes pixel_multiplier. We will use
10551 * port_clock to compute adjusted_mode.crtc_clock in the
10552 * encoder's get_config() function.
10554 pipe_config->port_clock = port_clock;
10557 int intel_dotclock_calculate(int link_freq,
10558 const struct intel_link_m_n *m_n)
10561 * The calculation for the data clock is:
10562 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10563 * But we want to avoid losing precison if possible, so:
10564 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10566 * and the link clock is simpler:
10567 * link_clock = (m * link_clock) / n
10573 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10576 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10577 struct intel_crtc_state *pipe_config)
10579 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10581 /* read out port_clock from the DPLL */
10582 i9xx_crtc_clock_get(crtc, pipe_config);
10585 * In case there is an active pipe without active ports,
10586 * we may need some idea for the dotclock anyway.
10587 * Calculate one based on the FDI configuration.
10589 pipe_config->base.adjusted_mode.crtc_clock =
10590 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10591 &pipe_config->fdi_m_n);
10594 /* Returns the currently programmed mode of the given encoder. */
10595 struct drm_display_mode *
10596 intel_encoder_current_mode(struct intel_encoder *encoder)
10598 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10599 struct intel_crtc_state *crtc_state;
10600 struct drm_display_mode *mode;
10601 struct intel_crtc *crtc;
10604 if (!encoder->get_hw_state(encoder, &pipe))
10607 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10609 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10613 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10619 crtc_state->base.crtc = &crtc->base;
10621 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10627 encoder->get_config(encoder, crtc_state);
10629 intel_mode_from_pipe_config(mode, crtc_state);
10636 static void intel_crtc_destroy(struct drm_crtc *crtc)
10638 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10640 drm_crtc_cleanup(crtc);
10645 * intel_wm_need_update - Check whether watermarks need updating
10646 * @plane: drm plane
10647 * @state: new plane state
10649 * Check current plane state versus the new one to determine whether
10650 * watermarks need to be recalculated.
10652 * Returns true or false.
10654 static bool intel_wm_need_update(struct drm_plane *plane,
10655 struct drm_plane_state *state)
10657 struct intel_plane_state *new = to_intel_plane_state(state);
10658 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10660 /* Update watermarks on tiling or size changes. */
10661 if (new->base.visible != cur->base.visible)
10664 if (!cur->base.fb || !new->base.fb)
10667 if (cur->base.fb->modifier != new->base.fb->modifier ||
10668 cur->base.rotation != new->base.rotation ||
10669 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10670 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10671 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10672 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10678 static bool needs_scaling(const struct intel_plane_state *state)
10680 int src_w = drm_rect_width(&state->base.src) >> 16;
10681 int src_h = drm_rect_height(&state->base.src) >> 16;
10682 int dst_w = drm_rect_width(&state->base.dst);
10683 int dst_h = drm_rect_height(&state->base.dst);
10685 return (src_w != dst_w || src_h != dst_h);
10688 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10689 struct drm_crtc_state *crtc_state,
10690 const struct intel_plane_state *old_plane_state,
10691 struct drm_plane_state *plane_state)
10693 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10694 struct drm_crtc *crtc = crtc_state->crtc;
10695 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10696 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10697 struct drm_device *dev = crtc->dev;
10698 struct drm_i915_private *dev_priv = to_i915(dev);
10699 bool mode_changed = needs_modeset(crtc_state);
10700 bool was_crtc_enabled = old_crtc_state->base.active;
10701 bool is_crtc_enabled = crtc_state->active;
10702 bool turn_off, turn_on, visible, was_visible;
10703 struct drm_framebuffer *fb = plane_state->fb;
10706 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10707 ret = skl_update_scaler_plane(
10708 to_intel_crtc_state(crtc_state),
10709 to_intel_plane_state(plane_state));
10714 was_visible = old_plane_state->base.visible;
10715 visible = plane_state->visible;
10717 if (!was_crtc_enabled && WARN_ON(was_visible))
10718 was_visible = false;
10721 * Visibility is calculated as if the crtc was on, but
10722 * after scaler setup everything depends on it being off
10723 * when the crtc isn't active.
10725 * FIXME this is wrong for watermarks. Watermarks should also
10726 * be computed as if the pipe would be active. Perhaps move
10727 * per-plane wm computation to the .check_plane() hook, and
10728 * only combine the results from all planes in the current place?
10730 if (!is_crtc_enabled) {
10731 plane_state->visible = visible = false;
10732 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10735 if (!was_visible && !visible)
10738 if (fb != old_plane_state->base.fb)
10739 pipe_config->fb_changed = true;
10741 turn_off = was_visible && (!visible || mode_changed);
10742 turn_on = visible && (!was_visible || mode_changed);
10744 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10745 intel_crtc->base.base.id, intel_crtc->base.name,
10746 plane->base.base.id, plane->base.name,
10747 fb ? fb->base.id : -1);
10749 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10750 plane->base.base.id, plane->base.name,
10751 was_visible, visible,
10752 turn_off, turn_on, mode_changed);
10755 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10756 pipe_config->update_wm_pre = true;
10758 /* must disable cxsr around plane enable/disable */
10759 if (plane->id != PLANE_CURSOR)
10760 pipe_config->disable_cxsr = true;
10761 } else if (turn_off) {
10762 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10763 pipe_config->update_wm_post = true;
10765 /* must disable cxsr around plane enable/disable */
10766 if (plane->id != PLANE_CURSOR)
10767 pipe_config->disable_cxsr = true;
10768 } else if (intel_wm_need_update(&plane->base, plane_state)) {
10769 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
10770 /* FIXME bollocks */
10771 pipe_config->update_wm_pre = true;
10772 pipe_config->update_wm_post = true;
10776 if (visible || was_visible)
10777 pipe_config->fb_bits |= plane->frontbuffer_bit;
10780 * WaCxSRDisabledForSpriteScaling:ivb
10782 * cstate->update_wm was already set above, so this flag will
10783 * take effect when we commit and program watermarks.
10785 if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) &&
10786 needs_scaling(to_intel_plane_state(plane_state)) &&
10787 !needs_scaling(old_plane_state))
10788 pipe_config->disable_lp_wm = true;
10793 static bool encoders_cloneable(const struct intel_encoder *a,
10794 const struct intel_encoder *b)
10796 /* masks could be asymmetric, so check both ways */
10797 return a == b || (a->cloneable & (1 << b->type) &&
10798 b->cloneable & (1 << a->type));
10801 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10802 struct intel_crtc *crtc,
10803 struct intel_encoder *encoder)
10805 struct intel_encoder *source_encoder;
10806 struct drm_connector *connector;
10807 struct drm_connector_state *connector_state;
10810 for_each_new_connector_in_state(state, connector, connector_state, i) {
10811 if (connector_state->crtc != &crtc->base)
10815 to_intel_encoder(connector_state->best_encoder);
10816 if (!encoders_cloneable(encoder, source_encoder))
10823 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10824 struct drm_crtc_state *crtc_state)
10826 struct drm_device *dev = crtc->dev;
10827 struct drm_i915_private *dev_priv = to_i915(dev);
10828 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10829 struct intel_crtc_state *pipe_config =
10830 to_intel_crtc_state(crtc_state);
10831 struct drm_atomic_state *state = crtc_state->state;
10833 bool mode_changed = needs_modeset(crtc_state);
10835 if (mode_changed && !crtc_state->active)
10836 pipe_config->update_wm_post = true;
10838 if (mode_changed && crtc_state->enable &&
10839 dev_priv->display.crtc_compute_clock &&
10840 !WARN_ON(pipe_config->shared_dpll)) {
10841 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10847 if (crtc_state->color_mgmt_changed) {
10848 ret = intel_color_check(crtc, crtc_state);
10853 * Changing color management on Intel hardware is
10854 * handled as part of planes update.
10856 crtc_state->planes_changed = true;
10860 if (dev_priv->display.compute_pipe_wm) {
10861 ret = dev_priv->display.compute_pipe_wm(pipe_config);
10863 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10868 if (dev_priv->display.compute_intermediate_wm &&
10869 !to_intel_atomic_state(state)->skip_intermediate_wm) {
10870 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10874 * Calculate 'intermediate' watermarks that satisfy both the
10875 * old state and the new state. We can program these
10878 ret = dev_priv->display.compute_intermediate_wm(dev,
10882 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10885 } else if (dev_priv->display.compute_intermediate_wm) {
10886 if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
10887 pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
10890 if (INTEL_GEN(dev_priv) >= 9) {
10892 ret = skl_update_scaler_crtc(pipe_config);
10895 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10898 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
10902 if (HAS_IPS(dev_priv))
10903 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10908 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
10909 .atomic_begin = intel_begin_crtc_commit,
10910 .atomic_flush = intel_finish_crtc_commit,
10911 .atomic_check = intel_crtc_atomic_check,
10914 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10916 struct intel_connector *connector;
10917 struct drm_connector_list_iter conn_iter;
10919 drm_connector_list_iter_begin(dev, &conn_iter);
10920 for_each_intel_connector_iter(connector, &conn_iter) {
10921 if (connector->base.state->crtc)
10922 drm_connector_put(&connector->base);
10924 if (connector->base.encoder) {
10925 connector->base.state->best_encoder =
10926 connector->base.encoder;
10927 connector->base.state->crtc =
10928 connector->base.encoder->crtc;
10930 drm_connector_get(&connector->base);
10932 connector->base.state->best_encoder = NULL;
10933 connector->base.state->crtc = NULL;
10936 drm_connector_list_iter_end(&conn_iter);
10940 connected_sink_compute_bpp(struct intel_connector *connector,
10941 struct intel_crtc_state *pipe_config)
10943 const struct drm_display_info *info = &connector->base.display_info;
10944 int bpp = pipe_config->pipe_bpp;
10946 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10947 connector->base.base.id,
10948 connector->base.name);
10950 /* Don't use an invalid EDID bpc value */
10951 if (info->bpc != 0 && info->bpc * 3 < bpp) {
10952 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10953 bpp, info->bpc * 3);
10954 pipe_config->pipe_bpp = info->bpc * 3;
10957 /* Clamp bpp to 8 on screens without EDID 1.4 */
10958 if (info->bpc == 0 && bpp > 24) {
10959 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10961 pipe_config->pipe_bpp = 24;
10966 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
10967 struct intel_crtc_state *pipe_config)
10969 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10970 struct drm_atomic_state *state;
10971 struct drm_connector *connector;
10972 struct drm_connector_state *connector_state;
10975 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10976 IS_CHERRYVIEW(dev_priv)))
10978 else if (INTEL_GEN(dev_priv) >= 5)
10984 pipe_config->pipe_bpp = bpp;
10986 state = pipe_config->base.state;
10988 /* Clamp display bpp to EDID value */
10989 for_each_new_connector_in_state(state, connector, connector_state, i) {
10990 if (connector_state->crtc != &crtc->base)
10993 connected_sink_compute_bpp(to_intel_connector(connector),
11000 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11002 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11003 "type: 0x%x flags: 0x%x\n",
11005 mode->crtc_hdisplay, mode->crtc_hsync_start,
11006 mode->crtc_hsync_end, mode->crtc_htotal,
11007 mode->crtc_vdisplay, mode->crtc_vsync_start,
11008 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11012 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
11013 unsigned int lane_count, struct intel_link_m_n *m_n)
11015 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11017 m_n->gmch_m, m_n->gmch_n,
11018 m_n->link_m, m_n->link_n, m_n->tu);
11021 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11023 static const char * const output_type_str[] = {
11024 OUTPUT_TYPE(UNUSED),
11025 OUTPUT_TYPE(ANALOG),
11029 OUTPUT_TYPE(TVOUT),
11035 OUTPUT_TYPE(DP_MST),
11040 static void snprintf_output_types(char *buf, size_t len,
11041 unsigned int output_types)
11048 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11051 if ((output_types & BIT(i)) == 0)
11054 r = snprintf(str, len, "%s%s",
11055 str != buf ? "," : "", output_type_str[i]);
11061 output_types &= ~BIT(i);
11064 WARN_ON_ONCE(output_types != 0);
11067 static void intel_dump_pipe_config(struct intel_crtc *crtc,
11068 struct intel_crtc_state *pipe_config,
11069 const char *context)
11071 struct drm_device *dev = crtc->base.dev;
11072 struct drm_i915_private *dev_priv = to_i915(dev);
11073 struct drm_plane *plane;
11074 struct intel_plane *intel_plane;
11075 struct intel_plane_state *state;
11076 struct drm_framebuffer *fb;
11079 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11080 crtc->base.base.id, crtc->base.name, context);
11082 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11083 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11084 buf, pipe_config->output_types);
11086 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11087 transcoder_name(pipe_config->cpu_transcoder),
11088 pipe_config->pipe_bpp, pipe_config->dither);
11090 if (pipe_config->has_pch_encoder)
11091 intel_dump_m_n_config(pipe_config, "fdi",
11092 pipe_config->fdi_lanes,
11093 &pipe_config->fdi_m_n);
11095 if (pipe_config->ycbcr420)
11096 DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
11098 if (intel_crtc_has_dp_encoder(pipe_config)) {
11099 intel_dump_m_n_config(pipe_config, "dp m_n",
11100 pipe_config->lane_count, &pipe_config->dp_m_n);
11101 if (pipe_config->has_drrs)
11102 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11103 pipe_config->lane_count,
11104 &pipe_config->dp_m2_n2);
11107 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11108 pipe_config->has_audio, pipe_config->has_infoframe);
11110 DRM_DEBUG_KMS("requested mode:\n");
11111 drm_mode_debug_printmodeline(&pipe_config->base.mode);
11112 DRM_DEBUG_KMS("adjusted mode:\n");
11113 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11114 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
11115 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
11116 pipe_config->port_clock,
11117 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11118 pipe_config->pixel_rate);
11120 if (INTEL_GEN(dev_priv) >= 9)
11121 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11123 pipe_config->scaler_state.scaler_users,
11124 pipe_config->scaler_state.scaler_id);
11126 if (HAS_GMCH_DISPLAY(dev_priv))
11127 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11128 pipe_config->gmch_pfit.control,
11129 pipe_config->gmch_pfit.pgm_ratios,
11130 pipe_config->gmch_pfit.lvds_border_bits);
11132 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11133 pipe_config->pch_pfit.pos,
11134 pipe_config->pch_pfit.size,
11135 enableddisabled(pipe_config->pch_pfit.enabled));
11137 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11138 pipe_config->ips_enabled, pipe_config->double_wide);
11140 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
11142 DRM_DEBUG_KMS("planes on this crtc\n");
11143 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
11144 struct drm_format_name_buf format_name;
11145 intel_plane = to_intel_plane(plane);
11146 if (intel_plane->pipe != crtc->pipe)
11149 state = to_intel_plane_state(plane->state);
11150 fb = state->base.fb;
11152 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11153 plane->base.id, plane->name, state->scaler_id);
11157 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11158 plane->base.id, plane->name,
11159 fb->base.id, fb->width, fb->height,
11160 drm_get_format_name(fb->format->format, &format_name));
11161 if (INTEL_GEN(dev_priv) >= 9)
11162 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11164 state->base.src.x1 >> 16,
11165 state->base.src.y1 >> 16,
11166 drm_rect_width(&state->base.src) >> 16,
11167 drm_rect_height(&state->base.src) >> 16,
11168 state->base.dst.x1, state->base.dst.y1,
11169 drm_rect_width(&state->base.dst),
11170 drm_rect_height(&state->base.dst));
11174 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
11176 struct drm_device *dev = state->dev;
11177 struct drm_connector *connector;
11178 struct drm_connector_list_iter conn_iter;
11179 unsigned int used_ports = 0;
11180 unsigned int used_mst_ports = 0;
11184 * Walk the connector list instead of the encoder
11185 * list to detect the problem on ddi platforms
11186 * where there's just one encoder per digital port.
11188 drm_connector_list_iter_begin(dev, &conn_iter);
11189 drm_for_each_connector_iter(connector, &conn_iter) {
11190 struct drm_connector_state *connector_state;
11191 struct intel_encoder *encoder;
11193 connector_state = drm_atomic_get_new_connector_state(state, connector);
11194 if (!connector_state)
11195 connector_state = connector->state;
11197 if (!connector_state->best_encoder)
11200 encoder = to_intel_encoder(connector_state->best_encoder);
11202 WARN_ON(!connector_state->crtc);
11204 switch (encoder->type) {
11205 unsigned int port_mask;
11206 case INTEL_OUTPUT_DDI:
11207 if (WARN_ON(!HAS_DDI(to_i915(dev))))
11209 /* else: fall through */
11210 case INTEL_OUTPUT_DP:
11211 case INTEL_OUTPUT_HDMI:
11212 case INTEL_OUTPUT_EDP:
11213 port_mask = 1 << encoder->port;
11215 /* the same port mustn't appear more than once */
11216 if (used_ports & port_mask)
11219 used_ports |= port_mask;
11221 case INTEL_OUTPUT_DP_MST:
11223 1 << encoder->port;
11229 drm_connector_list_iter_end(&conn_iter);
11231 /* can't mix MST and SST/HDMI on the same port */
11232 if (used_ports & used_mst_ports)
11239 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11241 struct drm_i915_private *dev_priv =
11242 to_i915(crtc_state->base.crtc->dev);
11243 struct intel_crtc_scaler_state scaler_state;
11244 struct intel_dpll_hw_state dpll_hw_state;
11245 struct intel_shared_dpll *shared_dpll;
11246 struct intel_crtc_wm_state wm_state;
11247 bool force_thru, ips_force_disable;
11249 /* FIXME: before the switch to atomic started, a new pipe_config was
11250 * kzalloc'd. Code that depends on any field being zero should be
11251 * fixed, so that the crtc_state can be safely duplicated. For now,
11252 * only fields that are know to not cause problems are preserved. */
11254 scaler_state = crtc_state->scaler_state;
11255 shared_dpll = crtc_state->shared_dpll;
11256 dpll_hw_state = crtc_state->dpll_hw_state;
11257 force_thru = crtc_state->pch_pfit.force_thru;
11258 ips_force_disable = crtc_state->ips_force_disable;
11259 if (IS_G4X(dev_priv) ||
11260 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11261 wm_state = crtc_state->wm;
11263 /* Keep base drm_crtc_state intact, only clear our extended struct */
11264 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11265 memset(&crtc_state->base + 1, 0,
11266 sizeof(*crtc_state) - sizeof(crtc_state->base));
11268 crtc_state->scaler_state = scaler_state;
11269 crtc_state->shared_dpll = shared_dpll;
11270 crtc_state->dpll_hw_state = dpll_hw_state;
11271 crtc_state->pch_pfit.force_thru = force_thru;
11272 crtc_state->ips_force_disable = ips_force_disable;
11273 if (IS_G4X(dev_priv) ||
11274 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11275 crtc_state->wm = wm_state;
11279 intel_modeset_pipe_config(struct drm_crtc *crtc,
11280 struct intel_crtc_state *pipe_config)
11282 struct drm_atomic_state *state = pipe_config->base.state;
11283 struct intel_encoder *encoder;
11284 struct drm_connector *connector;
11285 struct drm_connector_state *connector_state;
11286 int base_bpp, ret = -EINVAL;
11290 clear_intel_crtc_state(pipe_config);
11292 pipe_config->cpu_transcoder =
11293 (enum transcoder) to_intel_crtc(crtc)->pipe;
11296 * Sanitize sync polarity flags based on requested ones. If neither
11297 * positive or negative polarity is requested, treat this as meaning
11298 * negative polarity.
11300 if (!(pipe_config->base.adjusted_mode.flags &
11301 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
11302 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
11304 if (!(pipe_config->base.adjusted_mode.flags &
11305 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
11306 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
11308 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11314 * Determine the real pipe dimensions. Note that stereo modes can
11315 * increase the actual pipe size due to the frame doubling and
11316 * insertion of additional space for blanks between the frame. This
11317 * is stored in the crtc timings. We use the requested mode to do this
11318 * computation to clearly distinguish it from the adjusted mode, which
11319 * can be changed by the connectors in the below retry loop.
11321 drm_mode_get_hv_timing(&pipe_config->base.mode,
11322 &pipe_config->pipe_src_w,
11323 &pipe_config->pipe_src_h);
11325 for_each_new_connector_in_state(state, connector, connector_state, i) {
11326 if (connector_state->crtc != crtc)
11329 encoder = to_intel_encoder(connector_state->best_encoder);
11331 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11332 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11337 * Determine output_types before calling the .compute_config()
11338 * hooks so that the hooks can use this information safely.
11340 if (encoder->compute_output_type)
11341 pipe_config->output_types |=
11342 BIT(encoder->compute_output_type(encoder, pipe_config,
11345 pipe_config->output_types |= BIT(encoder->type);
11349 /* Ensure the port clock defaults are reset when retrying. */
11350 pipe_config->port_clock = 0;
11351 pipe_config->pixel_multiplier = 1;
11353 /* Fill in default crtc timings, allow encoders to overwrite them. */
11354 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11355 CRTC_STEREO_DOUBLE);
11357 /* Pass our mode to the connectors and the CRTC to give them a chance to
11358 * adjust it according to limitations or connector properties, and also
11359 * a chance to reject the mode entirely.
11361 for_each_new_connector_in_state(state, connector, connector_state, i) {
11362 if (connector_state->crtc != crtc)
11365 encoder = to_intel_encoder(connector_state->best_encoder);
11367 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
11368 DRM_DEBUG_KMS("Encoder config failure\n");
11373 /* Set default port clock if not overwritten by the encoder. Needs to be
11374 * done afterwards in case the encoder adjusts the mode. */
11375 if (!pipe_config->port_clock)
11376 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
11377 * pipe_config->pixel_multiplier;
11379 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
11381 DRM_DEBUG_KMS("CRTC fixup failed\n");
11385 if (ret == RETRY) {
11386 if (WARN(!retry, "loop in pipe configuration computation\n")) {
11391 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11393 goto encoder_retry;
11396 /* Dithering seems to not pass-through bits correctly when it should, so
11397 * only enable it on 6bpc panels and when its not a compliance
11398 * test requesting 6bpc video pattern.
11400 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11401 !pipe_config->dither_force_disable;
11402 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11403 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
11409 static bool intel_fuzzy_clock_check(int clock1, int clock2)
11413 if (clock1 == clock2)
11416 if (!clock1 || !clock2)
11419 diff = abs(clock1 - clock2);
11421 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11428 intel_compare_m_n(unsigned int m, unsigned int n,
11429 unsigned int m2, unsigned int n2,
11432 if (m == m2 && n == n2)
11435 if (exact || !m || !n || !m2 || !n2)
11438 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11445 } else if (n < n2) {
11455 return intel_fuzzy_clock_check(m, m2);
11459 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11460 struct intel_link_m_n *m2_n2,
11463 if (m_n->tu == m2_n2->tu &&
11464 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11465 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11466 intel_compare_m_n(m_n->link_m, m_n->link_n,
11467 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11477 static void __printf(3, 4)
11478 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11480 struct va_format vaf;
11483 va_start(args, format);
11488 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11490 drm_err("mismatch in %s %pV", name, &vaf);
11496 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11497 struct intel_crtc_state *current_config,
11498 struct intel_crtc_state *pipe_config,
11502 bool fixup_inherited = adjust &&
11503 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11504 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11506 #define PIPE_CONF_CHECK_X(name) do { \
11507 if (current_config->name != pipe_config->name) { \
11508 pipe_config_err(adjust, __stringify(name), \
11509 "(expected 0x%08x, found 0x%08x)\n", \
11510 current_config->name, \
11511 pipe_config->name); \
11516 #define PIPE_CONF_CHECK_I(name) do { \
11517 if (current_config->name != pipe_config->name) { \
11518 pipe_config_err(adjust, __stringify(name), \
11519 "(expected %i, found %i)\n", \
11520 current_config->name, \
11521 pipe_config->name); \
11526 #define PIPE_CONF_CHECK_BOOL(name) do { \
11527 if (current_config->name != pipe_config->name) { \
11528 pipe_config_err(adjust, __stringify(name), \
11529 "(expected %s, found %s)\n", \
11530 yesno(current_config->name), \
11531 yesno(pipe_config->name)); \
11537 * Checks state where we only read out the enabling, but not the entire
11538 * state itself (like full infoframes or ELD for audio). These states
11539 * require a full modeset on bootup to fix up.
11541 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11542 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11543 PIPE_CONF_CHECK_BOOL(name); \
11545 pipe_config_err(adjust, __stringify(name), \
11546 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11547 yesno(current_config->name), \
11548 yesno(pipe_config->name)); \
11553 #define PIPE_CONF_CHECK_P(name) do { \
11554 if (current_config->name != pipe_config->name) { \
11555 pipe_config_err(adjust, __stringify(name), \
11556 "(expected %p, found %p)\n", \
11557 current_config->name, \
11558 pipe_config->name); \
11563 #define PIPE_CONF_CHECK_M_N(name) do { \
11564 if (!intel_compare_link_m_n(¤t_config->name, \
11565 &pipe_config->name,\
11567 pipe_config_err(adjust, __stringify(name), \
11568 "(expected tu %i gmch %i/%i link %i/%i, " \
11569 "found tu %i, gmch %i/%i link %i/%i)\n", \
11570 current_config->name.tu, \
11571 current_config->name.gmch_m, \
11572 current_config->name.gmch_n, \
11573 current_config->name.link_m, \
11574 current_config->name.link_n, \
11575 pipe_config->name.tu, \
11576 pipe_config->name.gmch_m, \
11577 pipe_config->name.gmch_n, \
11578 pipe_config->name.link_m, \
11579 pipe_config->name.link_n); \
11584 /* This is required for BDW+ where there is only one set of registers for
11585 * switching between high and low RR.
11586 * This macro can be used whenever a comparison has to be made between one
11587 * hw state and multiple sw state variables.
11589 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
11590 if (!intel_compare_link_m_n(¤t_config->name, \
11591 &pipe_config->name, adjust) && \
11592 !intel_compare_link_m_n(¤t_config->alt_name, \
11593 &pipe_config->name, adjust)) { \
11594 pipe_config_err(adjust, __stringify(name), \
11595 "(expected tu %i gmch %i/%i link %i/%i, " \
11596 "or tu %i gmch %i/%i link %i/%i, " \
11597 "found tu %i, gmch %i/%i link %i/%i)\n", \
11598 current_config->name.tu, \
11599 current_config->name.gmch_m, \
11600 current_config->name.gmch_n, \
11601 current_config->name.link_m, \
11602 current_config->name.link_n, \
11603 current_config->alt_name.tu, \
11604 current_config->alt_name.gmch_m, \
11605 current_config->alt_name.gmch_n, \
11606 current_config->alt_name.link_m, \
11607 current_config->alt_name.link_n, \
11608 pipe_config->name.tu, \
11609 pipe_config->name.gmch_m, \
11610 pipe_config->name.gmch_n, \
11611 pipe_config->name.link_m, \
11612 pipe_config->name.link_n); \
11617 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
11618 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11619 pipe_config_err(adjust, __stringify(name), \
11620 "(%x) (expected %i, found %i)\n", \
11622 current_config->name & (mask), \
11623 pipe_config->name & (mask)); \
11628 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
11629 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11630 pipe_config_err(adjust, __stringify(name), \
11631 "(expected %i, found %i)\n", \
11632 current_config->name, \
11633 pipe_config->name); \
11638 #define PIPE_CONF_QUIRK(quirk) \
11639 ((current_config->quirks | pipe_config->quirks) & (quirk))
11641 PIPE_CONF_CHECK_I(cpu_transcoder);
11643 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11644 PIPE_CONF_CHECK_I(fdi_lanes);
11645 PIPE_CONF_CHECK_M_N(fdi_m_n);
11647 PIPE_CONF_CHECK_I(lane_count);
11648 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11650 if (INTEL_GEN(dev_priv) < 8) {
11651 PIPE_CONF_CHECK_M_N(dp_m_n);
11653 if (current_config->has_drrs)
11654 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11656 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11658 PIPE_CONF_CHECK_X(output_types);
11660 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11661 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11662 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11663 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11664 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11665 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
11667 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11668 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11669 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11670 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11671 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11672 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
11674 PIPE_CONF_CHECK_I(pixel_multiplier);
11675 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11676 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11677 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11678 PIPE_CONF_CHECK_BOOL(limited_color_range);
11680 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11681 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11682 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
11683 PIPE_CONF_CHECK_BOOL(ycbcr420);
11685 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11687 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11688 DRM_MODE_FLAG_INTERLACE);
11690 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11691 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11692 DRM_MODE_FLAG_PHSYNC);
11693 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11694 DRM_MODE_FLAG_NHSYNC);
11695 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11696 DRM_MODE_FLAG_PVSYNC);
11697 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11698 DRM_MODE_FLAG_NVSYNC);
11701 PIPE_CONF_CHECK_X(gmch_pfit.control);
11702 /* pfit ratios are autocomputed by the hw on gen4+ */
11703 if (INTEL_GEN(dev_priv) < 4)
11704 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11705 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11708 PIPE_CONF_CHECK_I(pipe_src_w);
11709 PIPE_CONF_CHECK_I(pipe_src_h);
11711 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11712 if (current_config->pch_pfit.enabled) {
11713 PIPE_CONF_CHECK_X(pch_pfit.pos);
11714 PIPE_CONF_CHECK_X(pch_pfit.size);
11717 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11718 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11721 PIPE_CONF_CHECK_BOOL(double_wide);
11723 PIPE_CONF_CHECK_P(shared_dpll);
11724 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11725 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11726 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11727 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11728 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11729 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11730 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11731 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11732 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11733 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11734 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11735 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11736 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11737 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11738 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11739 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11740 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11741 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11742 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11743 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11744 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11745 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11746 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11747 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11748 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11749 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11750 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11751 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11752 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11753 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11754 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
11756 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11757 PIPE_CONF_CHECK_X(dsi_pll.div);
11759 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11760 PIPE_CONF_CHECK_I(pipe_bpp);
11762 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
11763 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11765 PIPE_CONF_CHECK_I(min_voltage_level);
11767 #undef PIPE_CONF_CHECK_X
11768 #undef PIPE_CONF_CHECK_I
11769 #undef PIPE_CONF_CHECK_BOOL
11770 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11771 #undef PIPE_CONF_CHECK_P
11772 #undef PIPE_CONF_CHECK_FLAGS
11773 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11774 #undef PIPE_CONF_QUIRK
11779 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11780 const struct intel_crtc_state *pipe_config)
11782 if (pipe_config->has_pch_encoder) {
11783 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11784 &pipe_config->fdi_m_n);
11785 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11788 * FDI already provided one idea for the dotclock.
11789 * Yell if the encoder disagrees.
11791 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11792 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11793 fdi_dotclock, dotclock);
11797 static void verify_wm_state(struct drm_crtc *crtc,
11798 struct drm_crtc_state *new_state)
11800 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11801 struct skl_ddb_allocation hw_ddb, *sw_ddb;
11802 struct skl_pipe_wm hw_wm, *sw_wm;
11803 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11804 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11805 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11806 const enum pipe pipe = intel_crtc->pipe;
11807 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11809 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
11812 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
11813 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
11815 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11816 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11818 if (INTEL_GEN(dev_priv) >= 11)
11819 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11820 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11821 sw_ddb->enabled_slices,
11822 hw_ddb.enabled_slices);
11824 for_each_universal_plane(dev_priv, pipe, plane) {
11825 hw_plane_wm = &hw_wm.planes[plane];
11826 sw_plane_wm = &sw_wm->planes[plane];
11829 for (level = 0; level <= max_level; level++) {
11830 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11831 &sw_plane_wm->wm[level]))
11834 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",
11835 pipe_name(pipe), plane + 1, level,
11836 sw_plane_wm->wm[level].plane_en,
11837 sw_plane_wm->wm[level].plane_res_b,
11838 sw_plane_wm->wm[level].plane_res_l,
11839 hw_plane_wm->wm[level].plane_en,
11840 hw_plane_wm->wm[level].plane_res_b,
11841 hw_plane_wm->wm[level].plane_res_l);
11844 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11845 &sw_plane_wm->trans_wm)) {
11846 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",
11847 pipe_name(pipe), plane + 1,
11848 sw_plane_wm->trans_wm.plane_en,
11849 sw_plane_wm->trans_wm.plane_res_b,
11850 sw_plane_wm->trans_wm.plane_res_l,
11851 hw_plane_wm->trans_wm.plane_en,
11852 hw_plane_wm->trans_wm.plane_res_b,
11853 hw_plane_wm->trans_wm.plane_res_l);
11857 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11858 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11860 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11861 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11862 pipe_name(pipe), plane + 1,
11863 sw_ddb_entry->start, sw_ddb_entry->end,
11864 hw_ddb_entry->start, hw_ddb_entry->end);
11870 * If the cursor plane isn't active, we may not have updated it's ddb
11871 * allocation. In that case since the ddb allocation will be updated
11872 * once the plane becomes visible, we can skip this check
11875 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11876 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
11879 for (level = 0; level <= max_level; level++) {
11880 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11881 &sw_plane_wm->wm[level]))
11884 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",
11885 pipe_name(pipe), level,
11886 sw_plane_wm->wm[level].plane_en,
11887 sw_plane_wm->wm[level].plane_res_b,
11888 sw_plane_wm->wm[level].plane_res_l,
11889 hw_plane_wm->wm[level].plane_en,
11890 hw_plane_wm->wm[level].plane_res_b,
11891 hw_plane_wm->wm[level].plane_res_l);
11894 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11895 &sw_plane_wm->trans_wm)) {
11896 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11898 sw_plane_wm->trans_wm.plane_en,
11899 sw_plane_wm->trans_wm.plane_res_b,
11900 sw_plane_wm->trans_wm.plane_res_l,
11901 hw_plane_wm->trans_wm.plane_en,
11902 hw_plane_wm->trans_wm.plane_res_b,
11903 hw_plane_wm->trans_wm.plane_res_l);
11907 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11908 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11910 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11911 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11913 sw_ddb_entry->start, sw_ddb_entry->end,
11914 hw_ddb_entry->start, hw_ddb_entry->end);
11920 verify_connector_state(struct drm_device *dev,
11921 struct drm_atomic_state *state,
11922 struct drm_crtc *crtc)
11924 struct drm_connector *connector;
11925 struct drm_connector_state *new_conn_state;
11928 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
11929 struct drm_encoder *encoder = connector->encoder;
11930 struct drm_crtc_state *crtc_state = NULL;
11932 if (new_conn_state->crtc != crtc)
11936 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11938 intel_connector_verify_state(crtc_state, new_conn_state);
11940 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
11941 "connector's atomic encoder doesn't match legacy encoder\n");
11946 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
11948 struct intel_encoder *encoder;
11949 struct drm_connector *connector;
11950 struct drm_connector_state *old_conn_state, *new_conn_state;
11953 for_each_intel_encoder(dev, encoder) {
11954 bool enabled = false, found = false;
11957 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11958 encoder->base.base.id,
11959 encoder->base.name);
11961 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
11962 new_conn_state, i) {
11963 if (old_conn_state->best_encoder == &encoder->base)
11966 if (new_conn_state->best_encoder != &encoder->base)
11968 found = enabled = true;
11970 I915_STATE_WARN(new_conn_state->crtc !=
11971 encoder->base.crtc,
11972 "connector's crtc doesn't match encoder crtc\n");
11978 I915_STATE_WARN(!!encoder->base.crtc != enabled,
11979 "encoder's enabled state mismatch "
11980 "(expected %i, found %i)\n",
11981 !!encoder->base.crtc, enabled);
11983 if (!encoder->base.crtc) {
11986 active = encoder->get_hw_state(encoder, &pipe);
11987 I915_STATE_WARN(active,
11988 "encoder detached but still enabled on pipe %c.\n",
11995 verify_crtc_state(struct drm_crtc *crtc,
11996 struct drm_crtc_state *old_crtc_state,
11997 struct drm_crtc_state *new_crtc_state)
11999 struct drm_device *dev = crtc->dev;
12000 struct drm_i915_private *dev_priv = to_i915(dev);
12001 struct intel_encoder *encoder;
12002 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12003 struct intel_crtc_state *pipe_config, *sw_config;
12004 struct drm_atomic_state *old_state;
12007 old_state = old_crtc_state->state;
12008 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
12009 pipe_config = to_intel_crtc_state(old_crtc_state);
12010 memset(pipe_config, 0, sizeof(*pipe_config));
12011 pipe_config->base.crtc = crtc;
12012 pipe_config->base.state = old_state;
12014 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
12016 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
12018 /* we keep both pipes enabled on 830 */
12019 if (IS_I830(dev_priv))
12020 active = new_crtc_state->active;
12022 I915_STATE_WARN(new_crtc_state->active != active,
12023 "crtc active state doesn't match with hw state "
12024 "(expected %i, found %i)\n", new_crtc_state->active, active);
12026 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12027 "transitional active state does not match atomic hw state "
12028 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
12030 for_each_encoder_on_crtc(dev, crtc, encoder) {
12033 active = encoder->get_hw_state(encoder, &pipe);
12034 I915_STATE_WARN(active != new_crtc_state->active,
12035 "[ENCODER:%i] active %i with crtc active %i\n",
12036 encoder->base.base.id, active, new_crtc_state->active);
12038 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12039 "Encoder connected to wrong pipe %c\n",
12043 encoder->get_config(encoder, pipe_config);
12046 intel_crtc_compute_pixel_rate(pipe_config);
12048 if (!new_crtc_state->active)
12051 intel_pipe_config_sanity_check(dev_priv, pipe_config);
12053 sw_config = to_intel_crtc_state(new_crtc_state);
12054 if (!intel_pipe_config_compare(dev_priv, sw_config,
12055 pipe_config, false)) {
12056 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12057 intel_dump_pipe_config(intel_crtc, pipe_config,
12059 intel_dump_pipe_config(intel_crtc, sw_config,
12065 intel_verify_planes(struct intel_atomic_state *state)
12067 struct intel_plane *plane;
12068 const struct intel_plane_state *plane_state;
12071 for_each_new_intel_plane_in_state(state, plane,
12073 assert_plane(plane, plane_state->base.visible);
12077 verify_single_dpll_state(struct drm_i915_private *dev_priv,
12078 struct intel_shared_dpll *pll,
12079 struct drm_crtc *crtc,
12080 struct drm_crtc_state *new_state)
12082 struct intel_dpll_hw_state dpll_hw_state;
12083 unsigned int crtc_mask;
12086 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12088 DRM_DEBUG_KMS("%s\n", pll->info->name);
12090 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
12092 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
12093 I915_STATE_WARN(!pll->on && pll->active_mask,
12094 "pll in active use but not on in sw tracking\n");
12095 I915_STATE_WARN(pll->on && !pll->active_mask,
12096 "pll is on but not used by any active crtc\n");
12097 I915_STATE_WARN(pll->on != active,
12098 "pll on state mismatch (expected %i, found %i)\n",
12103 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
12104 "more active pll users than references: %x vs %x\n",
12105 pll->active_mask, pll->state.crtc_mask);
12110 crtc_mask = drm_crtc_mask(crtc);
12112 if (new_state->active)
12113 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12114 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12115 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12117 I915_STATE_WARN(pll->active_mask & crtc_mask,
12118 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12119 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12121 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
12122 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
12123 crtc_mask, pll->state.crtc_mask);
12125 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
12127 sizeof(dpll_hw_state)),
12128 "pll hw state mismatch\n");
12132 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12133 struct drm_crtc_state *old_crtc_state,
12134 struct drm_crtc_state *new_crtc_state)
12136 struct drm_i915_private *dev_priv = to_i915(dev);
12137 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12138 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12140 if (new_state->shared_dpll)
12141 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
12143 if (old_state->shared_dpll &&
12144 old_state->shared_dpll != new_state->shared_dpll) {
12145 unsigned int crtc_mask = drm_crtc_mask(crtc);
12146 struct intel_shared_dpll *pll = old_state->shared_dpll;
12148 I915_STATE_WARN(pll->active_mask & crtc_mask,
12149 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12150 pipe_name(drm_crtc_index(crtc)));
12151 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
12152 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12153 pipe_name(drm_crtc_index(crtc)));
12158 intel_modeset_verify_crtc(struct drm_crtc *crtc,
12159 struct drm_atomic_state *state,
12160 struct drm_crtc_state *old_state,
12161 struct drm_crtc_state *new_state)
12163 if (!needs_modeset(new_state) &&
12164 !to_intel_crtc_state(new_state)->update_pipe)
12167 verify_wm_state(crtc, new_state);
12168 verify_connector_state(crtc->dev, state, crtc);
12169 verify_crtc_state(crtc, old_state, new_state);
12170 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
12174 verify_disabled_dpll_state(struct drm_device *dev)
12176 struct drm_i915_private *dev_priv = to_i915(dev);
12179 for (i = 0; i < dev_priv->num_shared_dpll; i++)
12180 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
12184 intel_modeset_verify_disabled(struct drm_device *dev,
12185 struct drm_atomic_state *state)
12187 verify_encoder_state(dev, state);
12188 verify_connector_state(dev, state, NULL);
12189 verify_disabled_dpll_state(dev);
12192 static void update_scanline_offset(struct intel_crtc *crtc)
12194 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12197 * The scanline counter increments at the leading edge of hsync.
12199 * On most platforms it starts counting from vtotal-1 on the
12200 * first active line. That means the scanline counter value is
12201 * always one less than what we would expect. Ie. just after
12202 * start of vblank, which also occurs at start of hsync (on the
12203 * last active line), the scanline counter will read vblank_start-1.
12205 * On gen2 the scanline counter starts counting from 1 instead
12206 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12207 * to keep the value positive), instead of adding one.
12209 * On HSW+ the behaviour of the scanline counter depends on the output
12210 * type. For DP ports it behaves like most other platforms, but on HDMI
12211 * there's an extra 1 line difference. So we need to add two instead of
12212 * one to the value.
12214 * On VLV/CHV DSI the scanline counter would appear to increment
12215 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12216 * that means we can't tell whether we're in vblank or not while
12217 * we're on that particular line. We must still set scanline_offset
12218 * to 1 so that the vblank timestamps come out correct when we query
12219 * the scanline counter from within the vblank interrupt handler.
12220 * However if queried just before the start of vblank we'll get an
12221 * answer that's slightly in the future.
12223 if (IS_GEN2(dev_priv)) {
12224 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
12227 vtotal = adjusted_mode->crtc_vtotal;
12228 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
12231 crtc->scanline_offset = vtotal - 1;
12232 } else if (HAS_DDI(dev_priv) &&
12233 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) {
12234 crtc->scanline_offset = 2;
12236 crtc->scanline_offset = 1;
12239 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
12241 struct drm_device *dev = state->dev;
12242 struct drm_i915_private *dev_priv = to_i915(dev);
12243 struct drm_crtc *crtc;
12244 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12247 if (!dev_priv->display.crtc_compute_clock)
12250 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12251 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12252 struct intel_shared_dpll *old_dpll =
12253 to_intel_crtc_state(old_crtc_state)->shared_dpll;
12255 if (!needs_modeset(new_crtc_state))
12258 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
12263 intel_release_shared_dpll(old_dpll, intel_crtc, state);
12268 * This implements the workaround described in the "notes" section of the mode
12269 * set sequence documentation. When going from no pipes or single pipe to
12270 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12271 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12273 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12275 struct drm_crtc_state *crtc_state;
12276 struct intel_crtc *intel_crtc;
12277 struct drm_crtc *crtc;
12278 struct intel_crtc_state *first_crtc_state = NULL;
12279 struct intel_crtc_state *other_crtc_state = NULL;
12280 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12283 /* look at all crtc's that are going to be enabled in during modeset */
12284 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
12285 intel_crtc = to_intel_crtc(crtc);
12287 if (!crtc_state->active || !needs_modeset(crtc_state))
12290 if (first_crtc_state) {
12291 other_crtc_state = to_intel_crtc_state(crtc_state);
12294 first_crtc_state = to_intel_crtc_state(crtc_state);
12295 first_pipe = intel_crtc->pipe;
12299 /* No workaround needed? */
12300 if (!first_crtc_state)
12303 /* w/a possibly needed, check how many crtc's are already enabled. */
12304 for_each_intel_crtc(state->dev, intel_crtc) {
12305 struct intel_crtc_state *pipe_config;
12307 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12308 if (IS_ERR(pipe_config))
12309 return PTR_ERR(pipe_config);
12311 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12313 if (!pipe_config->base.active ||
12314 needs_modeset(&pipe_config->base))
12317 /* 2 or more enabled crtcs means no need for w/a */
12318 if (enabled_pipe != INVALID_PIPE)
12321 enabled_pipe = intel_crtc->pipe;
12324 if (enabled_pipe != INVALID_PIPE)
12325 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12326 else if (other_crtc_state)
12327 other_crtc_state->hsw_workaround_pipe = first_pipe;
12332 static int intel_lock_all_pipes(struct drm_atomic_state *state)
12334 struct drm_crtc *crtc;
12336 /* Add all pipes to the state */
12337 for_each_crtc(state->dev, crtc) {
12338 struct drm_crtc_state *crtc_state;
12340 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12341 if (IS_ERR(crtc_state))
12342 return PTR_ERR(crtc_state);
12348 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12350 struct drm_crtc *crtc;
12353 * Add all pipes to the state, and force
12354 * a modeset on all the active ones.
12356 for_each_crtc(state->dev, crtc) {
12357 struct drm_crtc_state *crtc_state;
12360 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12361 if (IS_ERR(crtc_state))
12362 return PTR_ERR(crtc_state);
12364 if (!crtc_state->active || needs_modeset(crtc_state))
12367 crtc_state->mode_changed = true;
12369 ret = drm_atomic_add_affected_connectors(state, crtc);
12373 ret = drm_atomic_add_affected_planes(state, crtc);
12381 static int intel_modeset_checks(struct drm_atomic_state *state)
12383 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12384 struct drm_i915_private *dev_priv = to_i915(state->dev);
12385 struct drm_crtc *crtc;
12386 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12389 if (!check_digital_port_conflicts(state)) {
12390 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12394 intel_state->modeset = true;
12395 intel_state->active_crtcs = dev_priv->active_crtcs;
12396 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12397 intel_state->cdclk.actual = dev_priv->cdclk.actual;
12399 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12400 if (new_crtc_state->active)
12401 intel_state->active_crtcs |= 1 << i;
12403 intel_state->active_crtcs &= ~(1 << i);
12405 if (old_crtc_state->active != new_crtc_state->active)
12406 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
12410 * See if the config requires any additional preparation, e.g.
12411 * to adjust global state with pipes off. We need to do this
12412 * here so we can get the modeset_pipe updated config for the new
12413 * mode set on this crtc. For other crtcs we need to use the
12414 * adjusted_mode bits in the crtc directly.
12416 if (dev_priv->display.modeset_calc_cdclk) {
12417 ret = dev_priv->display.modeset_calc_cdclk(state);
12422 * Writes to dev_priv->cdclk.logical must protected by
12423 * holding all the crtc locks, even if we don't end up
12424 * touching the hardware
12426 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12427 &intel_state->cdclk.logical)) {
12428 ret = intel_lock_all_pipes(state);
12433 /* All pipes must be switched off while we change the cdclk. */
12434 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12435 &intel_state->cdclk.actual)) {
12436 ret = intel_modeset_all_pipes(state);
12441 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12442 intel_state->cdclk.logical.cdclk,
12443 intel_state->cdclk.actual.cdclk);
12444 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12445 intel_state->cdclk.logical.voltage_level,
12446 intel_state->cdclk.actual.voltage_level);
12448 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12451 intel_modeset_clear_plls(state);
12453 if (IS_HASWELL(dev_priv))
12454 return haswell_mode_set_planes_workaround(state);
12460 * Handle calculation of various watermark data at the end of the atomic check
12461 * phase. The code here should be run after the per-crtc and per-plane 'check'
12462 * handlers to ensure that all derived state has been updated.
12464 static int calc_watermark_data(struct drm_atomic_state *state)
12466 struct drm_device *dev = state->dev;
12467 struct drm_i915_private *dev_priv = to_i915(dev);
12469 /* Is there platform-specific watermark information to calculate? */
12470 if (dev_priv->display.compute_global_watermarks)
12471 return dev_priv->display.compute_global_watermarks(state);
12477 * intel_atomic_check - validate state object
12479 * @state: state to validate
12481 static int intel_atomic_check(struct drm_device *dev,
12482 struct drm_atomic_state *state)
12484 struct drm_i915_private *dev_priv = to_i915(dev);
12485 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12486 struct drm_crtc *crtc;
12487 struct drm_crtc_state *old_crtc_state, *crtc_state;
12489 bool any_ms = false;
12491 /* Catch I915_MODE_FLAG_INHERITED */
12492 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12494 if (crtc_state->mode.private_flags !=
12495 old_crtc_state->mode.private_flags)
12496 crtc_state->mode_changed = true;
12499 ret = drm_atomic_helper_check_modeset(dev, state);
12503 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12504 struct intel_crtc_state *pipe_config =
12505 to_intel_crtc_state(crtc_state);
12507 if (!needs_modeset(crtc_state))
12510 if (!crtc_state->enable) {
12515 ret = intel_modeset_pipe_config(crtc, pipe_config);
12517 intel_dump_pipe_config(to_intel_crtc(crtc),
12518 pipe_config, "[failed]");
12522 if (i915_modparams.fastboot &&
12523 intel_pipe_config_compare(dev_priv,
12524 to_intel_crtc_state(old_crtc_state),
12525 pipe_config, true)) {
12526 crtc_state->mode_changed = false;
12527 pipe_config->update_pipe = true;
12530 if (needs_modeset(crtc_state))
12533 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12534 needs_modeset(crtc_state) ?
12535 "[modeset]" : "[fastset]");
12539 ret = intel_modeset_checks(state);
12544 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12547 ret = drm_atomic_helper_check_planes(dev, state);
12551 intel_fbc_choose_crtc(dev_priv, intel_state);
12552 return calc_watermark_data(state);
12555 static int intel_atomic_prepare_commit(struct drm_device *dev,
12556 struct drm_atomic_state *state)
12558 return drm_atomic_helper_prepare_planes(dev, state);
12561 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12563 struct drm_device *dev = crtc->base.dev;
12565 if (!dev->max_vblank_count)
12566 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
12568 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12571 static void intel_update_crtc(struct drm_crtc *crtc,
12572 struct drm_atomic_state *state,
12573 struct drm_crtc_state *old_crtc_state,
12574 struct drm_crtc_state *new_crtc_state)
12576 struct drm_device *dev = crtc->dev;
12577 struct drm_i915_private *dev_priv = to_i915(dev);
12578 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12579 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12580 bool modeset = needs_modeset(new_crtc_state);
12581 struct intel_plane_state *new_plane_state =
12582 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12583 to_intel_plane(crtc->primary));
12586 update_scanline_offset(intel_crtc);
12587 dev_priv->display.crtc_enable(pipe_config, state);
12589 /* vblanks work again, re-enable pipe CRC. */
12590 intel_crtc_enable_pipe_crc(intel_crtc);
12592 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12596 if (new_plane_state)
12597 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
12599 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state);
12602 static void intel_update_crtcs(struct drm_atomic_state *state)
12604 struct drm_crtc *crtc;
12605 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12608 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12609 if (!new_crtc_state->active)
12612 intel_update_crtc(crtc, state, old_crtc_state,
12617 static void skl_update_crtcs(struct drm_atomic_state *state)
12619 struct drm_i915_private *dev_priv = to_i915(state->dev);
12620 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12621 struct drm_crtc *crtc;
12622 struct intel_crtc *intel_crtc;
12623 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12624 struct intel_crtc_state *cstate;
12625 unsigned int updated = 0;
12629 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12630 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
12632 const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
12634 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
12635 /* ignore allocations for crtc's that have been turned off. */
12636 if (new_crtc_state->active)
12637 entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
12639 /* If 2nd DBuf slice required, enable it here */
12640 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12641 icl_dbuf_slices_update(dev_priv, required_slices);
12644 * Whenever the number of active pipes changes, we need to make sure we
12645 * update the pipes in the right order so that their ddb allocations
12646 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12647 * cause pipe underruns and other bad stuff.
12652 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12653 bool vbl_wait = false;
12654 unsigned int cmask = drm_crtc_mask(crtc);
12656 intel_crtc = to_intel_crtc(crtc);
12657 cstate = to_intel_crtc_state(new_crtc_state);
12658 pipe = intel_crtc->pipe;
12660 if (updated & cmask || !cstate->base.active)
12663 if (skl_ddb_allocation_overlaps(dev_priv,
12665 &cstate->wm.skl.ddb,
12670 entries[i] = &cstate->wm.skl.ddb;
12673 * If this is an already active pipe, it's DDB changed,
12674 * and this isn't the last pipe that needs updating
12675 * then we need to wait for a vblank to pass for the
12676 * new ddb allocation to take effect.
12678 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
12679 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
12680 !new_crtc_state->active_changed &&
12681 intel_state->wm_results.dirty_pipes != updated)
12684 intel_update_crtc(crtc, state, old_crtc_state,
12688 intel_wait_for_vblank(dev_priv, pipe);
12692 } while (progress);
12694 /* If 2nd DBuf slice is no more required disable it */
12695 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12696 icl_dbuf_slices_update(dev_priv, required_slices);
12699 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12701 struct intel_atomic_state *state, *next;
12702 struct llist_node *freed;
12704 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12705 llist_for_each_entry_safe(state, next, freed, freed)
12706 drm_atomic_state_put(&state->base);
12709 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12711 struct drm_i915_private *dev_priv =
12712 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12714 intel_atomic_helper_free_state(dev_priv);
12717 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12719 struct wait_queue_entry wait_fence, wait_reset;
12720 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12722 init_wait_entry(&wait_fence, 0);
12723 init_wait_entry(&wait_reset, 0);
12725 prepare_to_wait(&intel_state->commit_ready.wait,
12726 &wait_fence, TASK_UNINTERRUPTIBLE);
12727 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12728 &wait_reset, TASK_UNINTERRUPTIBLE);
12731 if (i915_sw_fence_done(&intel_state->commit_ready)
12732 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12737 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12738 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12741 static void intel_atomic_cleanup_work(struct work_struct *work)
12743 struct drm_atomic_state *state =
12744 container_of(work, struct drm_atomic_state, commit_work);
12745 struct drm_i915_private *i915 = to_i915(state->dev);
12747 drm_atomic_helper_cleanup_planes(&i915->drm, state);
12748 drm_atomic_helper_commit_cleanup_done(state);
12749 drm_atomic_state_put(state);
12751 intel_atomic_helper_free_state(i915);
12754 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
12756 struct drm_device *dev = state->dev;
12757 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12758 struct drm_i915_private *dev_priv = to_i915(dev);
12759 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12760 struct drm_crtc *crtc;
12761 struct intel_crtc_state *intel_cstate;
12762 u64 put_domains[I915_MAX_PIPES] = {};
12765 intel_atomic_commit_fence_wait(intel_state);
12767 drm_atomic_helper_wait_for_dependencies(state);
12769 if (intel_state->modeset)
12770 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
12772 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12773 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12775 if (needs_modeset(new_crtc_state) ||
12776 to_intel_crtc_state(new_crtc_state)->update_pipe) {
12778 put_domains[to_intel_crtc(crtc)->pipe] =
12779 modeset_get_crtc_power_domains(crtc,
12780 to_intel_crtc_state(new_crtc_state));
12783 if (!needs_modeset(new_crtc_state))
12786 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12787 to_intel_crtc_state(new_crtc_state));
12789 if (old_crtc_state->active) {
12790 intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask);
12793 * We need to disable pipe CRC before disabling the pipe,
12794 * or we race against vblank off.
12796 intel_crtc_disable_pipe_crc(intel_crtc);
12798 dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state);
12799 intel_crtc->active = false;
12800 intel_fbc_disable(intel_crtc);
12801 intel_disable_shared_dpll(intel_crtc);
12804 * Underruns don't always raise
12805 * interrupts, so check manually.
12807 intel_check_cpu_fifo_underruns(dev_priv);
12808 intel_check_pch_fifo_underruns(dev_priv);
12810 /* FIXME unify this for all platforms */
12811 if (!new_crtc_state->active &&
12812 !HAS_GMCH_DISPLAY(dev_priv) &&
12813 dev_priv->display.initial_watermarks)
12814 dev_priv->display.initial_watermarks(intel_state,
12815 to_intel_crtc_state(new_crtc_state));
12819 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12820 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12821 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
12823 if (intel_state->modeset) {
12824 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12826 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
12829 * SKL workaround: bspec recommends we disable the SAGV when we
12830 * have more then one pipe enabled
12832 if (!intel_can_enable_sagv(state))
12833 intel_disable_sagv(dev_priv);
12835 intel_modeset_verify_disabled(dev, state);
12838 /* Complete the events for pipes that have now been disabled */
12839 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12840 bool modeset = needs_modeset(new_crtc_state);
12842 /* Complete events for now disable pipes here. */
12843 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
12844 spin_lock_irq(&dev->event_lock);
12845 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
12846 spin_unlock_irq(&dev->event_lock);
12848 new_crtc_state->event = NULL;
12852 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12853 dev_priv->display.update_crtcs(state);
12855 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12856 * already, but still need the state for the delayed optimization. To
12858 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12859 * - schedule that vblank worker _before_ calling hw_done
12860 * - at the start of commit_tail, cancel it _synchrously
12861 * - switch over to the vblank wait helper in the core after that since
12862 * we don't need out special handling any more.
12864 drm_atomic_helper_wait_for_flip_done(dev, state);
12867 * Now that the vblank has passed, we can go ahead and program the
12868 * optimal watermarks on platforms that need two-step watermark
12871 * TODO: Move this (and other cleanup) to an async worker eventually.
12873 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12874 intel_cstate = to_intel_crtc_state(new_crtc_state);
12876 if (dev_priv->display.optimize_watermarks)
12877 dev_priv->display.optimize_watermarks(intel_state,
12881 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12882 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12884 if (put_domains[i])
12885 modeset_put_power_domains(dev_priv, put_domains[i]);
12887 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
12890 if (intel_state->modeset)
12891 intel_verify_planes(intel_state);
12893 if (intel_state->modeset && intel_can_enable_sagv(state))
12894 intel_enable_sagv(dev_priv);
12896 drm_atomic_helper_commit_hw_done(state);
12898 if (intel_state->modeset) {
12899 /* As one of the primary mmio accessors, KMS has a high
12900 * likelihood of triggering bugs in unclaimed access. After we
12901 * finish modesetting, see if an error has been flagged, and if
12902 * so enable debugging for the next modeset - and hope we catch
12905 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
12906 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
12910 * Defer the cleanup of the old state to a separate worker to not
12911 * impede the current task (userspace for blocking modesets) that
12912 * are executed inline. For out-of-line asynchronous modesets/flips,
12913 * deferring to a new worker seems overkill, but we would place a
12914 * schedule point (cond_resched()) here anyway to keep latencies
12917 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
12918 queue_work(system_highpri_wq, &state->commit_work);
12921 static void intel_atomic_commit_work(struct work_struct *work)
12923 struct drm_atomic_state *state =
12924 container_of(work, struct drm_atomic_state, commit_work);
12926 intel_atomic_commit_tail(state);
12929 static int __i915_sw_fence_call
12930 intel_atomic_commit_ready(struct i915_sw_fence *fence,
12931 enum i915_sw_fence_notify notify)
12933 struct intel_atomic_state *state =
12934 container_of(fence, struct intel_atomic_state, commit_ready);
12937 case FENCE_COMPLETE:
12938 /* we do blocking waits in the worker, nothing to do here */
12942 struct intel_atomic_helper *helper =
12943 &to_i915(state->base.dev)->atomic_helper;
12945 if (llist_add(&state->freed, &helper->free_list))
12946 schedule_work(&helper->free_work);
12951 return NOTIFY_DONE;
12954 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
12956 struct drm_plane_state *old_plane_state, *new_plane_state;
12957 struct drm_plane *plane;
12960 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
12961 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
12962 intel_fb_obj(new_plane_state->fb),
12963 to_intel_plane(plane)->frontbuffer_bit);
12967 * intel_atomic_commit - commit validated state object
12969 * @state: the top-level driver state object
12970 * @nonblock: nonblocking commit
12972 * This function commits a top-level state object that has been validated
12973 * with drm_atomic_helper_check().
12976 * Zero for success or -errno.
12978 static int intel_atomic_commit(struct drm_device *dev,
12979 struct drm_atomic_state *state,
12982 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12983 struct drm_i915_private *dev_priv = to_i915(dev);
12986 drm_atomic_state_get(state);
12987 i915_sw_fence_init(&intel_state->commit_ready,
12988 intel_atomic_commit_ready);
12991 * The intel_legacy_cursor_update() fast path takes care
12992 * of avoiding the vblank waits for simple cursor
12993 * movement and flips. For cursor on/off and size changes,
12994 * we want to perform the vblank waits so that watermark
12995 * updates happen during the correct frames. Gen9+ have
12996 * double buffered watermarks and so shouldn't need this.
12998 * Unset state->legacy_cursor_update before the call to
12999 * drm_atomic_helper_setup_commit() because otherwise
13000 * drm_atomic_helper_wait_for_flip_done() is a noop and
13001 * we get FIFO underruns because we didn't wait
13004 * FIXME doing watermarks and fb cleanup from a vblank worker
13005 * (assuming we had any) would solve these problems.
13007 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13008 struct intel_crtc_state *new_crtc_state;
13009 struct intel_crtc *crtc;
13012 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13013 if (new_crtc_state->wm.need_postvbl_update ||
13014 new_crtc_state->update_wm_post)
13015 state->legacy_cursor_update = false;
13018 ret = intel_atomic_prepare_commit(dev, state);
13020 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13021 i915_sw_fence_commit(&intel_state->commit_ready);
13025 ret = drm_atomic_helper_setup_commit(state, nonblock);
13027 ret = drm_atomic_helper_swap_state(state, true);
13030 i915_sw_fence_commit(&intel_state->commit_ready);
13032 drm_atomic_helper_cleanup_planes(dev, state);
13035 dev_priv->wm.distrust_bios_wm = false;
13036 intel_shared_dpll_swap_state(state);
13037 intel_atomic_track_fbs(state);
13039 if (intel_state->modeset) {
13040 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13041 sizeof(intel_state->min_cdclk));
13042 memcpy(dev_priv->min_voltage_level,
13043 intel_state->min_voltage_level,
13044 sizeof(intel_state->min_voltage_level));
13045 dev_priv->active_crtcs = intel_state->active_crtcs;
13046 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13047 dev_priv->cdclk.actual = intel_state->cdclk.actual;
13050 drm_atomic_state_get(state);
13051 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
13053 i915_sw_fence_commit(&intel_state->commit_ready);
13054 if (nonblock && intel_state->modeset) {
13055 queue_work(dev_priv->modeset_wq, &state->commit_work);
13056 } else if (nonblock) {
13057 queue_work(system_unbound_wq, &state->commit_work);
13059 if (intel_state->modeset)
13060 flush_workqueue(dev_priv->modeset_wq);
13061 intel_atomic_commit_tail(state);
13067 static const struct drm_crtc_funcs intel_crtc_funcs = {
13068 .gamma_set = drm_atomic_helper_legacy_gamma_set,
13069 .set_config = drm_atomic_helper_set_config,
13070 .destroy = intel_crtc_destroy,
13071 .page_flip = drm_atomic_helper_page_flip,
13072 .atomic_duplicate_state = intel_crtc_duplicate_state,
13073 .atomic_destroy_state = intel_crtc_destroy_state,
13074 .set_crc_source = intel_crtc_set_crc_source,
13075 .verify_crc_source = intel_crtc_verify_crc_source,
13076 .get_crc_sources = intel_crtc_get_crc_sources,
13079 struct wait_rps_boost {
13080 struct wait_queue_entry wait;
13082 struct drm_crtc *crtc;
13083 struct i915_request *request;
13086 static int do_rps_boost(struct wait_queue_entry *_wait,
13087 unsigned mode, int sync, void *key)
13089 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
13090 struct i915_request *rq = wait->request;
13093 * If we missed the vblank, but the request is already running it
13094 * is reasonable to assume that it will complete before the next
13095 * vblank without our intervention, so leave RPS alone.
13097 if (!i915_request_started(rq))
13098 gen6_rps_boost(rq, NULL);
13099 i915_request_put(rq);
13101 drm_crtc_vblank_put(wait->crtc);
13103 list_del(&wait->wait.entry);
13108 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13109 struct dma_fence *fence)
13111 struct wait_rps_boost *wait;
13113 if (!dma_fence_is_i915(fence))
13116 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13119 if (drm_crtc_vblank_get(crtc))
13122 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13124 drm_crtc_vblank_put(crtc);
13128 wait->request = to_request(dma_fence_get(fence));
13131 wait->wait.func = do_rps_boost;
13132 wait->wait.flags = 0;
13134 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13137 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13139 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13140 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13141 struct drm_framebuffer *fb = plane_state->base.fb;
13142 struct i915_vma *vma;
13144 if (plane->id == PLANE_CURSOR &&
13145 INTEL_INFO(dev_priv)->cursor_needs_physical) {
13146 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13147 const int align = intel_cursor_alignment(dev_priv);
13150 err = i915_gem_object_attach_phys(obj, align);
13155 vma = intel_pin_and_fence_fb_obj(fb,
13156 &plane_state->view,
13157 intel_plane_uses_fence(plane_state),
13158 &plane_state->flags);
13160 return PTR_ERR(vma);
13162 plane_state->vma = vma;
13167 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13169 struct i915_vma *vma;
13171 vma = fetch_and_zero(&old_plane_state->vma);
13173 intel_unpin_fb_vma(vma, old_plane_state->flags);
13176 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13178 struct i915_sched_attr attr = {
13179 .priority = I915_PRIORITY_DISPLAY,
13182 i915_gem_object_wait_priority(obj, 0, &attr);
13186 * intel_prepare_plane_fb - Prepare fb for usage on plane
13187 * @plane: drm plane to prepare for
13188 * @new_state: the plane state being prepared
13190 * Prepares a framebuffer for usage on a display plane. Generally this
13191 * involves pinning the underlying object and updating the frontbuffer tracking
13192 * bits. Some older platforms need special physical address handling for
13195 * Must be called with struct_mutex held.
13197 * Returns 0 on success, negative error code on failure.
13200 intel_prepare_plane_fb(struct drm_plane *plane,
13201 struct drm_plane_state *new_state)
13203 struct intel_atomic_state *intel_state =
13204 to_intel_atomic_state(new_state->state);
13205 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13206 struct drm_framebuffer *fb = new_state->fb;
13207 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13208 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
13212 struct drm_crtc_state *crtc_state =
13213 drm_atomic_get_new_crtc_state(new_state->state,
13214 plane->state->crtc);
13216 /* Big Hammer, we also need to ensure that any pending
13217 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13218 * current scanout is retired before unpinning the old
13219 * framebuffer. Note that we rely on userspace rendering
13220 * into the buffer attached to the pipe they are waiting
13221 * on. If not, userspace generates a GPU hang with IPEHR
13222 * point to the MI_WAIT_FOR_EVENT.
13224 * This should only fail upon a hung GPU, in which case we
13225 * can safely continue.
13227 if (needs_modeset(crtc_state)) {
13228 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13229 old_obj->resv, NULL,
13237 if (new_state->fence) { /* explicit fencing */
13238 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13240 I915_FENCE_TIMEOUT,
13249 ret = i915_gem_object_pin_pages(obj);
13253 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13255 i915_gem_object_unpin_pages(obj);
13259 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
13261 fb_obj_bump_render_priority(obj);
13263 mutex_unlock(&dev_priv->drm.struct_mutex);
13264 i915_gem_object_unpin_pages(obj);
13268 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13270 if (!new_state->fence) { /* implicit fencing */
13271 struct dma_fence *fence;
13273 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13275 false, I915_FENCE_TIMEOUT,
13280 fence = reservation_object_get_excl_rcu(obj->resv);
13282 add_rps_boost_after_vblank(new_state->crtc, fence);
13283 dma_fence_put(fence);
13286 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
13290 * We declare pageflips to be interactive and so merit a small bias
13291 * towards upclocking to deliver the frame on time. By only changing
13292 * the RPS thresholds to sample more regularly and aim for higher
13293 * clocks we can hopefully deliver low power workloads (like kodi)
13294 * that are not quite steady state without resorting to forcing
13295 * maximum clocks following a vblank miss (see do_rps_boost()).
13297 if (!intel_state->rps_interactive) {
13298 intel_rps_mark_interactive(dev_priv, true);
13299 intel_state->rps_interactive = true;
13306 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13307 * @plane: drm plane to clean up for
13308 * @old_state: the state from the previous modeset
13310 * Cleans up a framebuffer that has just been removed from a plane.
13312 * Must be called with struct_mutex held.
13315 intel_cleanup_plane_fb(struct drm_plane *plane,
13316 struct drm_plane_state *old_state)
13318 struct intel_atomic_state *intel_state =
13319 to_intel_atomic_state(old_state->state);
13320 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13322 if (intel_state->rps_interactive) {
13323 intel_rps_mark_interactive(dev_priv, false);
13324 intel_state->rps_interactive = false;
13327 /* Should only be called after a successful intel_prepare_plane_fb()! */
13328 mutex_lock(&dev_priv->drm.struct_mutex);
13329 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13330 mutex_unlock(&dev_priv->drm.struct_mutex);
13334 skl_max_scale(const struct intel_crtc_state *crtc_state,
13337 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13338 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13339 int max_scale, mult;
13340 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
13342 if (!crtc_state->base.enable)
13343 return DRM_PLANE_HELPER_NO_SCALING;
13345 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13346 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13348 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
13351 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
13352 return DRM_PLANE_HELPER_NO_SCALING;
13355 * skl max scale is lower of:
13356 * close to 3 but not 3, -1 is for that purpose
13360 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13361 tmpclk1 = (1 << 16) * mult - 1;
13362 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13363 max_scale = min(tmpclk1, tmpclk2);
13368 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13369 struct drm_crtc_state *old_crtc_state)
13371 struct drm_device *dev = crtc->dev;
13372 struct drm_i915_private *dev_priv = to_i915(dev);
13373 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13374 struct intel_crtc_state *old_intel_cstate =
13375 to_intel_crtc_state(old_crtc_state);
13376 struct intel_atomic_state *old_intel_state =
13377 to_intel_atomic_state(old_crtc_state->state);
13378 struct intel_crtc_state *intel_cstate =
13379 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13380 bool modeset = needs_modeset(&intel_cstate->base);
13383 (intel_cstate->base.color_mgmt_changed ||
13384 intel_cstate->update_pipe)) {
13385 intel_color_set_csc(&intel_cstate->base);
13386 intel_color_load_luts(&intel_cstate->base);
13389 /* Perform vblank evasion around commit operation */
13390 intel_pipe_update_start(intel_cstate);
13395 if (intel_cstate->update_pipe)
13396 intel_update_pipe_config(old_intel_cstate, intel_cstate);
13397 else if (INTEL_GEN(dev_priv) >= 9)
13398 skl_detach_scalers(intel_crtc);
13401 if (dev_priv->display.atomic_update_watermarks)
13402 dev_priv->display.atomic_update_watermarks(old_intel_state,
13406 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13407 struct intel_crtc_state *crtc_state)
13409 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13411 if (!IS_GEN2(dev_priv))
13412 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13414 if (crtc_state->has_pch_encoder) {
13415 enum pipe pch_transcoder =
13416 intel_crtc_pch_transcoder(crtc);
13418 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13422 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13423 struct drm_crtc_state *old_crtc_state)
13425 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13426 struct intel_atomic_state *old_intel_state =
13427 to_intel_atomic_state(old_crtc_state->state);
13428 struct intel_crtc_state *new_crtc_state =
13429 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13431 intel_pipe_update_end(new_crtc_state);
13433 if (new_crtc_state->update_pipe &&
13434 !needs_modeset(&new_crtc_state->base) &&
13435 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13436 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
13440 * intel_plane_destroy - destroy a plane
13441 * @plane: plane to destroy
13443 * Common destruction function for all types of planes (primary, cursor,
13446 void intel_plane_destroy(struct drm_plane *plane)
13448 drm_plane_cleanup(plane);
13449 kfree(to_intel_plane(plane));
13452 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13453 u32 format, u64 modifier)
13455 switch (modifier) {
13456 case DRM_FORMAT_MOD_LINEAR:
13457 case I915_FORMAT_MOD_X_TILED:
13464 case DRM_FORMAT_C8:
13465 case DRM_FORMAT_RGB565:
13466 case DRM_FORMAT_XRGB1555:
13467 case DRM_FORMAT_XRGB8888:
13468 return modifier == DRM_FORMAT_MOD_LINEAR ||
13469 modifier == I915_FORMAT_MOD_X_TILED;
13475 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13476 u32 format, u64 modifier)
13478 switch (modifier) {
13479 case DRM_FORMAT_MOD_LINEAR:
13480 case I915_FORMAT_MOD_X_TILED:
13487 case DRM_FORMAT_C8:
13488 case DRM_FORMAT_RGB565:
13489 case DRM_FORMAT_XRGB8888:
13490 case DRM_FORMAT_XBGR8888:
13491 case DRM_FORMAT_XRGB2101010:
13492 case DRM_FORMAT_XBGR2101010:
13493 return modifier == DRM_FORMAT_MOD_LINEAR ||
13494 modifier == I915_FORMAT_MOD_X_TILED;
13500 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
13501 u32 format, u64 modifier)
13503 struct intel_plane *plane = to_intel_plane(_plane);
13505 switch (modifier) {
13506 case DRM_FORMAT_MOD_LINEAR:
13507 case I915_FORMAT_MOD_X_TILED:
13508 case I915_FORMAT_MOD_Y_TILED:
13509 case I915_FORMAT_MOD_Yf_TILED:
13511 case I915_FORMAT_MOD_Y_TILED_CCS:
13512 case I915_FORMAT_MOD_Yf_TILED_CCS:
13513 if (!plane->has_ccs)
13521 case DRM_FORMAT_XRGB8888:
13522 case DRM_FORMAT_XBGR8888:
13523 case DRM_FORMAT_ARGB8888:
13524 case DRM_FORMAT_ABGR8888:
13525 if (is_ccs_modifier(modifier))
13528 case DRM_FORMAT_RGB565:
13529 case DRM_FORMAT_XRGB2101010:
13530 case DRM_FORMAT_XBGR2101010:
13531 case DRM_FORMAT_YUYV:
13532 case DRM_FORMAT_YVYU:
13533 case DRM_FORMAT_UYVY:
13534 case DRM_FORMAT_VYUY:
13535 case DRM_FORMAT_NV12:
13536 if (modifier == I915_FORMAT_MOD_Yf_TILED)
13539 case DRM_FORMAT_C8:
13540 if (modifier == DRM_FORMAT_MOD_LINEAR ||
13541 modifier == I915_FORMAT_MOD_X_TILED ||
13542 modifier == I915_FORMAT_MOD_Y_TILED)
13550 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13551 u32 format, u64 modifier)
13553 return modifier == DRM_FORMAT_MOD_LINEAR &&
13554 format == DRM_FORMAT_ARGB8888;
13557 static struct drm_plane_funcs skl_plane_funcs = {
13558 .update_plane = drm_atomic_helper_update_plane,
13559 .disable_plane = drm_atomic_helper_disable_plane,
13560 .destroy = intel_plane_destroy,
13561 .atomic_get_property = intel_plane_atomic_get_property,
13562 .atomic_set_property = intel_plane_atomic_set_property,
13563 .atomic_duplicate_state = intel_plane_duplicate_state,
13564 .atomic_destroy_state = intel_plane_destroy_state,
13565 .format_mod_supported = skl_plane_format_mod_supported,
13568 static struct drm_plane_funcs i965_plane_funcs = {
13569 .update_plane = drm_atomic_helper_update_plane,
13570 .disable_plane = drm_atomic_helper_disable_plane,
13571 .destroy = intel_plane_destroy,
13572 .atomic_get_property = intel_plane_atomic_get_property,
13573 .atomic_set_property = intel_plane_atomic_set_property,
13574 .atomic_duplicate_state = intel_plane_duplicate_state,
13575 .atomic_destroy_state = intel_plane_destroy_state,
13576 .format_mod_supported = i965_plane_format_mod_supported,
13579 static struct drm_plane_funcs i8xx_plane_funcs = {
13580 .update_plane = drm_atomic_helper_update_plane,
13581 .disable_plane = drm_atomic_helper_disable_plane,
13582 .destroy = intel_plane_destroy,
13583 .atomic_get_property = intel_plane_atomic_get_property,
13584 .atomic_set_property = intel_plane_atomic_set_property,
13585 .atomic_duplicate_state = intel_plane_duplicate_state,
13586 .atomic_destroy_state = intel_plane_destroy_state,
13587 .format_mod_supported = i8xx_plane_format_mod_supported,
13591 intel_legacy_cursor_update(struct drm_plane *plane,
13592 struct drm_crtc *crtc,
13593 struct drm_framebuffer *fb,
13594 int crtc_x, int crtc_y,
13595 unsigned int crtc_w, unsigned int crtc_h,
13596 uint32_t src_x, uint32_t src_y,
13597 uint32_t src_w, uint32_t src_h,
13598 struct drm_modeset_acquire_ctx *ctx)
13600 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13602 struct drm_plane_state *old_plane_state, *new_plane_state;
13603 struct intel_plane *intel_plane = to_intel_plane(plane);
13604 struct drm_framebuffer *old_fb;
13605 struct drm_crtc_state *crtc_state = crtc->state;
13608 * When crtc is inactive or there is a modeset pending,
13609 * wait for it to complete in the slowpath
13611 if (!crtc_state->active || needs_modeset(crtc_state) ||
13612 to_intel_crtc_state(crtc_state)->update_pipe)
13615 old_plane_state = plane->state;
13617 * Don't do an async update if there is an outstanding commit modifying
13618 * the plane. This prevents our async update's changes from getting
13619 * overridden by a previous synchronous update's state.
13621 if (old_plane_state->commit &&
13622 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13626 * If any parameters change that may affect watermarks,
13627 * take the slowpath. Only changing fb or position should be
13630 if (old_plane_state->crtc != crtc ||
13631 old_plane_state->src_w != src_w ||
13632 old_plane_state->src_h != src_h ||
13633 old_plane_state->crtc_w != crtc_w ||
13634 old_plane_state->crtc_h != crtc_h ||
13635 !old_plane_state->fb != !fb)
13638 new_plane_state = intel_plane_duplicate_state(plane);
13639 if (!new_plane_state)
13642 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13644 new_plane_state->src_x = src_x;
13645 new_plane_state->src_y = src_y;
13646 new_plane_state->src_w = src_w;
13647 new_plane_state->src_h = src_h;
13648 new_plane_state->crtc_x = crtc_x;
13649 new_plane_state->crtc_y = crtc_y;
13650 new_plane_state->crtc_w = crtc_w;
13651 new_plane_state->crtc_h = crtc_h;
13653 ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state),
13654 to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */
13655 to_intel_plane_state(plane->state),
13656 to_intel_plane_state(new_plane_state));
13660 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13664 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13668 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
13670 old_fb = old_plane_state->fb;
13671 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13672 intel_plane->frontbuffer_bit);
13674 /* Swap plane state */
13675 plane->state = new_plane_state;
13677 if (plane->state->visible) {
13678 trace_intel_update_plane(plane, to_intel_crtc(crtc));
13679 intel_plane->update_plane(intel_plane,
13680 to_intel_crtc_state(crtc->state),
13681 to_intel_plane_state(plane->state));
13683 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
13684 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
13687 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
13690 mutex_unlock(&dev_priv->drm.struct_mutex);
13693 intel_plane_destroy_state(plane, new_plane_state);
13695 intel_plane_destroy_state(plane, old_plane_state);
13699 return drm_atomic_helper_update_plane(plane, crtc, fb,
13700 crtc_x, crtc_y, crtc_w, crtc_h,
13701 src_x, src_y, src_w, src_h, ctx);
13704 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13705 .update_plane = intel_legacy_cursor_update,
13706 .disable_plane = drm_atomic_helper_disable_plane,
13707 .destroy = intel_plane_destroy,
13708 .atomic_get_property = intel_plane_atomic_get_property,
13709 .atomic_set_property = intel_plane_atomic_set_property,
13710 .atomic_duplicate_state = intel_plane_duplicate_state,
13711 .atomic_destroy_state = intel_plane_destroy_state,
13712 .format_mod_supported = intel_cursor_format_mod_supported,
13715 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13716 enum i9xx_plane_id i9xx_plane)
13718 if (!HAS_FBC(dev_priv))
13721 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13722 return i9xx_plane == PLANE_A; /* tied to pipe A */
13723 else if (IS_IVYBRIDGE(dev_priv))
13724 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13725 i9xx_plane == PLANE_C;
13726 else if (INTEL_GEN(dev_priv) >= 4)
13727 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13729 return i9xx_plane == PLANE_A;
13732 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
13733 enum pipe pipe, enum plane_id plane_id)
13735 if (!HAS_FBC(dev_priv))
13738 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
13741 bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
13742 enum pipe pipe, enum plane_id plane_id)
13745 * FIXME: ICL requires two hardware planes for scanning out NV12
13746 * framebuffers. Do not advertize support until this is implemented.
13748 if (INTEL_GEN(dev_priv) >= 11)
13751 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
13754 if (INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv) && pipe == PIPE_C)
13757 if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
13763 static struct intel_plane *
13764 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
13766 struct intel_plane *primary = NULL;
13767 struct intel_plane_state *state = NULL;
13768 const struct drm_plane_funcs *plane_funcs;
13769 const uint32_t *intel_primary_formats;
13770 unsigned int supported_rotations;
13771 unsigned int num_formats;
13772 const uint64_t *modifiers;
13775 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
13781 state = intel_create_plane_state(&primary->base);
13787 primary->base.state = &state->base;
13789 if (INTEL_GEN(dev_priv) >= 9)
13790 state->scaler_id = -1;
13791 primary->pipe = pipe;
13793 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13794 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13796 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
13797 primary->i9xx_plane = (enum i9xx_plane_id) !pipe;
13799 primary->i9xx_plane = (enum i9xx_plane_id) pipe;
13800 primary->id = PLANE_PRIMARY;
13801 primary->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, primary->id);
13803 if (INTEL_GEN(dev_priv) >= 9)
13804 primary->has_fbc = skl_plane_has_fbc(dev_priv,
13808 primary->has_fbc = i9xx_plane_has_fbc(dev_priv,
13809 primary->i9xx_plane);
13811 if (primary->has_fbc) {
13812 struct intel_fbc *fbc = &dev_priv->fbc;
13814 fbc->possible_framebuffer_bits |= primary->frontbuffer_bit;
13817 if (INTEL_GEN(dev_priv) >= 9) {
13818 primary->has_ccs = skl_plane_has_ccs(dev_priv, pipe,
13821 if (skl_plane_has_planar(dev_priv, pipe, PLANE_PRIMARY)) {
13822 intel_primary_formats = skl_pri_planar_formats;
13823 num_formats = ARRAY_SIZE(skl_pri_planar_formats);
13825 intel_primary_formats = skl_primary_formats;
13826 num_formats = ARRAY_SIZE(skl_primary_formats);
13829 if (primary->has_ccs)
13830 modifiers = skl_format_modifiers_ccs;
13832 modifiers = skl_format_modifiers_noccs;
13834 primary->max_stride = skl_plane_max_stride;
13835 primary->update_plane = skl_update_plane;
13836 primary->disable_plane = skl_disable_plane;
13837 primary->get_hw_state = skl_plane_get_hw_state;
13838 primary->check_plane = skl_plane_check;
13840 plane_funcs = &skl_plane_funcs;
13841 } else if (INTEL_GEN(dev_priv) >= 4) {
13842 intel_primary_formats = i965_primary_formats;
13843 num_formats = ARRAY_SIZE(i965_primary_formats);
13844 modifiers = i9xx_format_modifiers;
13846 primary->max_stride = i9xx_plane_max_stride;
13847 primary->update_plane = i9xx_update_plane;
13848 primary->disable_plane = i9xx_disable_plane;
13849 primary->get_hw_state = i9xx_plane_get_hw_state;
13850 primary->check_plane = i9xx_plane_check;
13852 plane_funcs = &i965_plane_funcs;
13854 intel_primary_formats = i8xx_primary_formats;
13855 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13856 modifiers = i9xx_format_modifiers;
13858 primary->max_stride = i9xx_plane_max_stride;
13859 primary->update_plane = i9xx_update_plane;
13860 primary->disable_plane = i9xx_disable_plane;
13861 primary->get_hw_state = i9xx_plane_get_hw_state;
13862 primary->check_plane = i9xx_plane_check;
13864 plane_funcs = &i8xx_plane_funcs;
13867 if (INTEL_GEN(dev_priv) >= 9)
13868 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13870 intel_primary_formats, num_formats,
13872 DRM_PLANE_TYPE_PRIMARY,
13873 "plane 1%c", pipe_name(pipe));
13874 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
13875 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13877 intel_primary_formats, num_formats,
13879 DRM_PLANE_TYPE_PRIMARY,
13880 "primary %c", pipe_name(pipe));
13882 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13884 intel_primary_formats, num_formats,
13886 DRM_PLANE_TYPE_PRIMARY,
13888 plane_name(primary->i9xx_plane));
13892 if (INTEL_GEN(dev_priv) >= 10) {
13893 supported_rotations =
13894 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13895 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 |
13896 DRM_MODE_REFLECT_X;
13897 } else if (INTEL_GEN(dev_priv) >= 9) {
13898 supported_rotations =
13899 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13900 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
13901 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13902 supported_rotations =
13903 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13904 DRM_MODE_REFLECT_X;
13905 } else if (INTEL_GEN(dev_priv) >= 4) {
13906 supported_rotations =
13907 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
13909 supported_rotations = DRM_MODE_ROTATE_0;
13912 if (INTEL_GEN(dev_priv) >= 4)
13913 drm_plane_create_rotation_property(&primary->base,
13915 supported_rotations);
13917 if (INTEL_GEN(dev_priv) >= 9)
13918 drm_plane_create_color_properties(&primary->base,
13919 BIT(DRM_COLOR_YCBCR_BT601) |
13920 BIT(DRM_COLOR_YCBCR_BT709),
13921 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
13922 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
13923 DRM_COLOR_YCBCR_BT709,
13924 DRM_COLOR_YCBCR_LIMITED_RANGE);
13926 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
13934 return ERR_PTR(ret);
13937 static struct intel_plane *
13938 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13941 struct intel_plane *cursor = NULL;
13942 struct intel_plane_state *state = NULL;
13945 cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
13951 state = intel_create_plane_state(&cursor->base);
13957 cursor->base.state = &state->base;
13959 cursor->pipe = pipe;
13960 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
13961 cursor->id = PLANE_CURSOR;
13962 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
13964 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
13965 cursor->max_stride = i845_cursor_max_stride;
13966 cursor->update_plane = i845_update_cursor;
13967 cursor->disable_plane = i845_disable_cursor;
13968 cursor->get_hw_state = i845_cursor_get_hw_state;
13969 cursor->check_plane = i845_check_cursor;
13971 cursor->max_stride = i9xx_cursor_max_stride;
13972 cursor->update_plane = i9xx_update_cursor;
13973 cursor->disable_plane = i9xx_disable_cursor;
13974 cursor->get_hw_state = i9xx_cursor_get_hw_state;
13975 cursor->check_plane = i9xx_check_cursor;
13978 cursor->cursor.base = ~0;
13979 cursor->cursor.cntl = ~0;
13981 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13982 cursor->cursor.size = ~0;
13984 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
13985 0, &intel_cursor_plane_funcs,
13986 intel_cursor_formats,
13987 ARRAY_SIZE(intel_cursor_formats),
13988 cursor_format_modifiers,
13989 DRM_PLANE_TYPE_CURSOR,
13990 "cursor %c", pipe_name(pipe));
13994 if (INTEL_GEN(dev_priv) >= 4)
13995 drm_plane_create_rotation_property(&cursor->base,
13997 DRM_MODE_ROTATE_0 |
13998 DRM_MODE_ROTATE_180);
14000 if (INTEL_GEN(dev_priv) >= 9)
14001 state->scaler_id = -1;
14003 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14011 return ERR_PTR(ret);
14014 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14015 struct intel_crtc_state *crtc_state)
14017 struct intel_crtc_scaler_state *scaler_state =
14018 &crtc_state->scaler_state;
14019 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14022 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
14023 if (!crtc->num_scalers)
14026 for (i = 0; i < crtc->num_scalers; i++) {
14027 struct intel_scaler *scaler = &scaler_state->scalers[i];
14029 scaler->in_use = 0;
14030 scaler->mode = PS_SCALER_MODE_DYN;
14033 scaler_state->scaler_id = -1;
14036 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
14038 struct intel_crtc *intel_crtc;
14039 struct intel_crtc_state *crtc_state = NULL;
14040 struct intel_plane *primary = NULL;
14041 struct intel_plane *cursor = NULL;
14044 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
14048 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
14053 intel_crtc->config = crtc_state;
14054 intel_crtc->base.state = &crtc_state->base;
14055 crtc_state->base.crtc = &intel_crtc->base;
14057 primary = intel_primary_plane_create(dev_priv, pipe);
14058 if (IS_ERR(primary)) {
14059 ret = PTR_ERR(primary);
14062 intel_crtc->plane_ids_mask |= BIT(primary->id);
14064 for_each_sprite(dev_priv, pipe, sprite) {
14065 struct intel_plane *plane;
14067 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
14068 if (IS_ERR(plane)) {
14069 ret = PTR_ERR(plane);
14072 intel_crtc->plane_ids_mask |= BIT(plane->id);
14075 cursor = intel_cursor_plane_create(dev_priv, pipe);
14076 if (IS_ERR(cursor)) {
14077 ret = PTR_ERR(cursor);
14080 intel_crtc->plane_ids_mask |= BIT(cursor->id);
14082 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
14083 &primary->base, &cursor->base,
14085 "pipe %c", pipe_name(pipe));
14089 intel_crtc->pipe = pipe;
14091 /* initialize shared scalers */
14092 intel_crtc_init_scalers(intel_crtc, crtc_state);
14094 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14095 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14096 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14098 if (INTEL_GEN(dev_priv) < 9) {
14099 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14101 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14102 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14103 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14106 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
14108 intel_color_init(&intel_crtc->base);
14110 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
14116 * drm_mode_config_cleanup() will free up any
14117 * crtcs/planes already initialized.
14125 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
14127 struct drm_device *dev = connector->base.dev;
14129 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
14131 if (!connector->base.state->crtc)
14132 return INVALID_PIPE;
14134 return to_intel_crtc(connector->base.state->crtc)->pipe;
14137 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14138 struct drm_file *file)
14140 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
14141 struct drm_crtc *drmmode_crtc;
14142 struct intel_crtc *crtc;
14144 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
14148 crtc = to_intel_crtc(drmmode_crtc);
14149 pipe_from_crtc_id->pipe = crtc->pipe;
14154 static int intel_encoder_clones(struct intel_encoder *encoder)
14156 struct drm_device *dev = encoder->base.dev;
14157 struct intel_encoder *source_encoder;
14158 int index_mask = 0;
14161 for_each_intel_encoder(dev, source_encoder) {
14162 if (encoders_cloneable(encoder, source_encoder))
14163 index_mask |= (1 << entry);
14171 static bool has_edp_a(struct drm_i915_private *dev_priv)
14173 if (!IS_MOBILE(dev_priv))
14176 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14179 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
14185 static bool intel_crt_present(struct drm_i915_private *dev_priv)
14187 if (INTEL_GEN(dev_priv) >= 9)
14190 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
14193 if (IS_CHERRYVIEW(dev_priv))
14196 if (HAS_PCH_LPT_H(dev_priv) &&
14197 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
14200 /* DDI E can't be used if DDI A requires 4 lanes */
14201 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
14204 if (!dev_priv->vbt.int_crt_support)
14210 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14215 if (HAS_DDI(dev_priv))
14218 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14219 * everywhere where registers can be write protected.
14221 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14226 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14227 u32 val = I915_READ(PP_CONTROL(pps_idx));
14229 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14230 I915_WRITE(PP_CONTROL(pps_idx), val);
14234 static void intel_pps_init(struct drm_i915_private *dev_priv)
14236 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
14237 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14238 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14239 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14241 dev_priv->pps_mmio_base = PPS_BASE;
14243 intel_pps_unlock_regs_wa(dev_priv);
14246 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
14248 struct intel_encoder *encoder;
14249 bool dpd_is_edp = false;
14251 intel_pps_init(dev_priv);
14253 if (INTEL_INFO(dev_priv)->num_pipes == 0)
14257 * intel_edp_init_connector() depends on this completing first, to
14258 * prevent the registeration of both eDP and LVDS and the incorrect
14259 * sharing of the PPS.
14261 intel_lvds_init(dev_priv);
14263 if (intel_crt_present(dev_priv))
14264 intel_crt_init(dev_priv);
14266 if (IS_ICELAKE(dev_priv)) {
14267 intel_ddi_init(dev_priv, PORT_A);
14268 intel_ddi_init(dev_priv, PORT_B);
14269 intel_ddi_init(dev_priv, PORT_C);
14270 intel_ddi_init(dev_priv, PORT_D);
14271 intel_ddi_init(dev_priv, PORT_E);
14272 intel_ddi_init(dev_priv, PORT_F);
14273 } else if (IS_GEN9_LP(dev_priv)) {
14275 * FIXME: Broxton doesn't support port detection via the
14276 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14277 * detect the ports.
14279 intel_ddi_init(dev_priv, PORT_A);
14280 intel_ddi_init(dev_priv, PORT_B);
14281 intel_ddi_init(dev_priv, PORT_C);
14283 vlv_dsi_init(dev_priv);
14284 } else if (HAS_DDI(dev_priv)) {
14288 * Haswell uses DDI functions to detect digital outputs.
14289 * On SKL pre-D0 the strap isn't connected, so we assume
14292 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
14293 /* WaIgnoreDDIAStrap: skl */
14294 if (found || IS_GEN9_BC(dev_priv))
14295 intel_ddi_init(dev_priv, PORT_A);
14297 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
14299 found = I915_READ(SFUSE_STRAP);
14301 if (found & SFUSE_STRAP_DDIB_DETECTED)
14302 intel_ddi_init(dev_priv, PORT_B);
14303 if (found & SFUSE_STRAP_DDIC_DETECTED)
14304 intel_ddi_init(dev_priv, PORT_C);
14305 if (found & SFUSE_STRAP_DDID_DETECTED)
14306 intel_ddi_init(dev_priv, PORT_D);
14307 if (found & SFUSE_STRAP_DDIF_DETECTED)
14308 intel_ddi_init(dev_priv, PORT_F);
14310 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14312 if (IS_GEN9_BC(dev_priv) &&
14313 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14314 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14315 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
14316 intel_ddi_init(dev_priv, PORT_E);
14318 } else if (HAS_PCH_SPLIT(dev_priv)) {
14320 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
14322 if (has_edp_a(dev_priv))
14323 intel_dp_init(dev_priv, DP_A, PORT_A);
14325 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
14326 /* PCH SDVOB multiplex with HDMIB */
14327 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
14329 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
14330 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
14331 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
14334 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
14335 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
14337 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
14338 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
14340 if (I915_READ(PCH_DP_C) & DP_DETECTED)
14341 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
14343 if (I915_READ(PCH_DP_D) & DP_DETECTED)
14344 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
14345 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
14346 bool has_edp, has_port;
14349 * The DP_DETECTED bit is the latched state of the DDC
14350 * SDA pin at boot. However since eDP doesn't require DDC
14351 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14352 * eDP ports may have been muxed to an alternate function.
14353 * Thus we can't rely on the DP_DETECTED bit alone to detect
14354 * eDP ports. Consult the VBT as well as DP_DETECTED to
14355 * detect eDP ports.
14357 * Sadly the straps seem to be missing sometimes even for HDMI
14358 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14359 * and VBT for the presence of the port. Additionally we can't
14360 * trust the port type the VBT declares as we've seen at least
14361 * HDMI ports that the VBT claim are DP or eDP.
14363 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
14364 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14365 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
14366 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
14367 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
14368 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
14370 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
14371 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14372 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
14373 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
14374 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
14375 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
14377 if (IS_CHERRYVIEW(dev_priv)) {
14379 * eDP not supported on port D,
14380 * so no need to worry about it
14382 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14383 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
14384 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
14385 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
14386 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
14389 vlv_dsi_init(dev_priv);
14390 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
14391 bool found = false;
14393 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14394 DRM_DEBUG_KMS("probing SDVOB\n");
14395 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
14396 if (!found && IS_G4X(dev_priv)) {
14397 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14398 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
14401 if (!found && IS_G4X(dev_priv))
14402 intel_dp_init(dev_priv, DP_B, PORT_B);
14405 /* Before G4X SDVOC doesn't have its own detect register */
14407 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14408 DRM_DEBUG_KMS("probing SDVOC\n");
14409 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
14412 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14414 if (IS_G4X(dev_priv)) {
14415 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14416 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
14418 if (IS_G4X(dev_priv))
14419 intel_dp_init(dev_priv, DP_C, PORT_C);
14422 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
14423 intel_dp_init(dev_priv, DP_D, PORT_D);
14424 } else if (IS_GEN2(dev_priv))
14425 intel_dvo_init(dev_priv);
14427 if (SUPPORTS_TV(dev_priv))
14428 intel_tv_init(dev_priv);
14430 intel_psr_init(dev_priv);
14432 for_each_intel_encoder(&dev_priv->drm, encoder) {
14433 encoder->base.possible_crtcs = encoder->crtc_mask;
14434 encoder->base.possible_clones =
14435 intel_encoder_clones(encoder);
14438 intel_init_pch_refclk(dev_priv);
14440 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14443 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14445 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14446 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14448 drm_framebuffer_cleanup(fb);
14450 i915_gem_object_lock(obj);
14451 WARN_ON(!obj->framebuffer_references--);
14452 i915_gem_object_unlock(obj);
14454 i915_gem_object_put(obj);
14459 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14460 struct drm_file *file,
14461 unsigned int *handle)
14463 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14465 if (obj->userptr.mm) {
14466 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14470 return drm_gem_handle_create(file, &obj->base, handle);
14473 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14474 struct drm_file *file,
14475 unsigned flags, unsigned color,
14476 struct drm_clip_rect *clips,
14477 unsigned num_clips)
14479 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14481 i915_gem_object_flush_if_display(obj);
14482 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14487 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14488 .destroy = intel_user_framebuffer_destroy,
14489 .create_handle = intel_user_framebuffer_create_handle,
14490 .dirty = intel_user_framebuffer_dirty,
14494 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14495 uint64_t fb_modifier, uint32_t pixel_format)
14497 struct intel_crtc *crtc;
14498 struct intel_plane *plane;
14501 * We assume the primary plane for pipe A has
14502 * the highest stride limits of them all.
14504 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14505 plane = to_intel_plane(crtc->base.primary);
14507 return plane->max_stride(plane, pixel_format, fb_modifier,
14508 DRM_MODE_ROTATE_0);
14511 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14512 struct drm_i915_gem_object *obj,
14513 struct drm_mode_fb_cmd2 *mode_cmd)
14515 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14516 struct drm_framebuffer *fb = &intel_fb->base;
14517 struct drm_format_name_buf format_name;
14519 unsigned int tiling, stride;
14523 i915_gem_object_lock(obj);
14524 obj->framebuffer_references++;
14525 tiling = i915_gem_object_get_tiling(obj);
14526 stride = i915_gem_object_get_stride(obj);
14527 i915_gem_object_unlock(obj);
14529 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14531 * If there's a fence, enforce that
14532 * the fb modifier and tiling mode match.
14534 if (tiling != I915_TILING_NONE &&
14535 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14536 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14540 if (tiling == I915_TILING_X) {
14541 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14542 } else if (tiling == I915_TILING_Y) {
14543 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14548 /* Passed in modifier sanity checking. */
14549 switch (mode_cmd->modifier[0]) {
14550 case I915_FORMAT_MOD_Y_TILED_CCS:
14551 case I915_FORMAT_MOD_Yf_TILED_CCS:
14552 switch (mode_cmd->pixel_format) {
14553 case DRM_FORMAT_XBGR8888:
14554 case DRM_FORMAT_ABGR8888:
14555 case DRM_FORMAT_XRGB8888:
14556 case DRM_FORMAT_ARGB8888:
14559 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
14563 case I915_FORMAT_MOD_Y_TILED:
14564 case I915_FORMAT_MOD_Yf_TILED:
14565 if (INTEL_GEN(dev_priv) < 9) {
14566 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14567 mode_cmd->modifier[0]);
14570 case DRM_FORMAT_MOD_LINEAR:
14571 case I915_FORMAT_MOD_X_TILED:
14574 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14575 mode_cmd->modifier[0]);
14580 * gen2/3 display engine uses the fence if present,
14581 * so the tiling mode must match the fb modifier exactly.
14583 if (INTEL_GEN(dev_priv) < 4 &&
14584 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14585 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14589 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
14590 mode_cmd->pixel_format);
14591 if (mode_cmd->pitches[0] > pitch_limit) {
14592 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14593 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14594 "tiled" : "linear",
14595 mode_cmd->pitches[0], pitch_limit);
14600 * If there's a fence, enforce that
14601 * the fb pitch and fence stride match.
14603 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14604 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14605 mode_cmd->pitches[0], stride);
14609 /* Reject formats not supported by any plane early. */
14610 switch (mode_cmd->pixel_format) {
14611 case DRM_FORMAT_C8:
14612 case DRM_FORMAT_RGB565:
14613 case DRM_FORMAT_XRGB8888:
14614 case DRM_FORMAT_ARGB8888:
14616 case DRM_FORMAT_XRGB1555:
14617 if (INTEL_GEN(dev_priv) > 3) {
14618 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14619 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14623 case DRM_FORMAT_ABGR8888:
14624 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
14625 INTEL_GEN(dev_priv) < 9) {
14626 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14627 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14631 case DRM_FORMAT_XBGR8888:
14632 case DRM_FORMAT_XRGB2101010:
14633 case DRM_FORMAT_XBGR2101010:
14634 if (INTEL_GEN(dev_priv) < 4) {
14635 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14636 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14640 case DRM_FORMAT_ABGR2101010:
14641 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
14642 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14643 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14647 case DRM_FORMAT_YUYV:
14648 case DRM_FORMAT_UYVY:
14649 case DRM_FORMAT_YVYU:
14650 case DRM_FORMAT_VYUY:
14651 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
14652 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14653 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14657 case DRM_FORMAT_NV12:
14658 if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) ||
14659 IS_BROXTON(dev_priv) || INTEL_GEN(dev_priv) >= 11) {
14660 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14661 drm_get_format_name(mode_cmd->pixel_format,
14667 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14668 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14672 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14673 if (mode_cmd->offsets[0] != 0)
14676 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14678 if (fb->format->format == DRM_FORMAT_NV12 &&
14679 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14680 fb->height < SKL_MIN_YUV_420_SRC_H ||
14681 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14682 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
14686 for (i = 0; i < fb->format->num_planes; i++) {
14687 u32 stride_alignment;
14689 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14690 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14694 stride_alignment = intel_fb_stride_alignment(fb, i);
14697 * Display WA #0531: skl,bxt,kbl,glk
14699 * Render decompression and plane width > 3840
14700 * combined with horizontal panning requires the
14701 * plane stride to be a multiple of 4. We'll just
14702 * require the entire fb to accommodate that to avoid
14703 * potential runtime errors at plane configuration time.
14705 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
14706 is_ccs_modifier(fb->modifier))
14707 stride_alignment *= 4;
14709 if (fb->pitches[i] & (stride_alignment - 1)) {
14710 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14711 i, fb->pitches[i], stride_alignment);
14715 fb->obj[i] = &obj->base;
14718 ret = intel_fill_fb_info(dev_priv, fb);
14722 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14724 DRM_ERROR("framebuffer init failed %d\n", ret);
14731 i915_gem_object_lock(obj);
14732 obj->framebuffer_references--;
14733 i915_gem_object_unlock(obj);
14737 static struct drm_framebuffer *
14738 intel_user_framebuffer_create(struct drm_device *dev,
14739 struct drm_file *filp,
14740 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14742 struct drm_framebuffer *fb;
14743 struct drm_i915_gem_object *obj;
14744 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14746 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14748 return ERR_PTR(-ENOENT);
14750 fb = intel_framebuffer_create(obj, &mode_cmd);
14752 i915_gem_object_put(obj);
14757 static void intel_atomic_state_free(struct drm_atomic_state *state)
14759 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14761 drm_atomic_state_default_release(state);
14763 i915_sw_fence_fini(&intel_state->commit_ready);
14768 static enum drm_mode_status
14769 intel_mode_valid(struct drm_device *dev,
14770 const struct drm_display_mode *mode)
14772 struct drm_i915_private *dev_priv = to_i915(dev);
14773 int hdisplay_max, htotal_max;
14774 int vdisplay_max, vtotal_max;
14777 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14778 * of DBLSCAN modes to the output's mode list when they detect
14779 * the scaling mode property on the connector. And they don't
14780 * ask the kernel to validate those modes in any way until
14781 * modeset time at which point the client gets a protocol error.
14782 * So in order to not upset those clients we silently ignore the
14783 * DBLSCAN flag on such connectors. For other connectors we will
14784 * reject modes with the DBLSCAN flag in encoder->compute_config().
14785 * And we always reject DBLSCAN modes in connector->mode_valid()
14786 * as we never want such modes on the connector's mode list.
14789 if (mode->vscan > 1)
14790 return MODE_NO_VSCAN;
14792 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14793 return MODE_H_ILLEGAL;
14795 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14796 DRM_MODE_FLAG_NCSYNC |
14797 DRM_MODE_FLAG_PCSYNC))
14800 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14801 DRM_MODE_FLAG_PIXMUX |
14802 DRM_MODE_FLAG_CLKDIV2))
14805 if (INTEL_GEN(dev_priv) >= 9 ||
14806 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14807 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14808 vdisplay_max = 4096;
14811 } else if (INTEL_GEN(dev_priv) >= 3) {
14812 hdisplay_max = 4096;
14813 vdisplay_max = 4096;
14817 hdisplay_max = 2048;
14818 vdisplay_max = 2048;
14823 if (mode->hdisplay > hdisplay_max ||
14824 mode->hsync_start > htotal_max ||
14825 mode->hsync_end > htotal_max ||
14826 mode->htotal > htotal_max)
14827 return MODE_H_ILLEGAL;
14829 if (mode->vdisplay > vdisplay_max ||
14830 mode->vsync_start > vtotal_max ||
14831 mode->vsync_end > vtotal_max ||
14832 mode->vtotal > vtotal_max)
14833 return MODE_V_ILLEGAL;
14838 static const struct drm_mode_config_funcs intel_mode_funcs = {
14839 .fb_create = intel_user_framebuffer_create,
14840 .get_format_info = intel_get_format_info,
14841 .output_poll_changed = intel_fbdev_output_poll_changed,
14842 .mode_valid = intel_mode_valid,
14843 .atomic_check = intel_atomic_check,
14844 .atomic_commit = intel_atomic_commit,
14845 .atomic_state_alloc = intel_atomic_state_alloc,
14846 .atomic_state_clear = intel_atomic_state_clear,
14847 .atomic_state_free = intel_atomic_state_free,
14851 * intel_init_display_hooks - initialize the display modesetting hooks
14852 * @dev_priv: device private
14854 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14856 intel_init_cdclk_hooks(dev_priv);
14858 if (INTEL_GEN(dev_priv) >= 9) {
14859 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14860 dev_priv->display.get_initial_plane_config =
14861 skylake_get_initial_plane_config;
14862 dev_priv->display.crtc_compute_clock =
14863 haswell_crtc_compute_clock;
14864 dev_priv->display.crtc_enable = haswell_crtc_enable;
14865 dev_priv->display.crtc_disable = haswell_crtc_disable;
14866 } else if (HAS_DDI(dev_priv)) {
14867 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14868 dev_priv->display.get_initial_plane_config =
14869 i9xx_get_initial_plane_config;
14870 dev_priv->display.crtc_compute_clock =
14871 haswell_crtc_compute_clock;
14872 dev_priv->display.crtc_enable = haswell_crtc_enable;
14873 dev_priv->display.crtc_disable = haswell_crtc_disable;
14874 } else if (HAS_PCH_SPLIT(dev_priv)) {
14875 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14876 dev_priv->display.get_initial_plane_config =
14877 i9xx_get_initial_plane_config;
14878 dev_priv->display.crtc_compute_clock =
14879 ironlake_crtc_compute_clock;
14880 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14881 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14882 } else if (IS_CHERRYVIEW(dev_priv)) {
14883 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14884 dev_priv->display.get_initial_plane_config =
14885 i9xx_get_initial_plane_config;
14886 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14887 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14888 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14889 } else if (IS_VALLEYVIEW(dev_priv)) {
14890 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14891 dev_priv->display.get_initial_plane_config =
14892 i9xx_get_initial_plane_config;
14893 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
14894 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14895 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14896 } else if (IS_G4X(dev_priv)) {
14897 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14898 dev_priv->display.get_initial_plane_config =
14899 i9xx_get_initial_plane_config;
14900 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14901 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14902 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14903 } else if (IS_PINEVIEW(dev_priv)) {
14904 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14905 dev_priv->display.get_initial_plane_config =
14906 i9xx_get_initial_plane_config;
14907 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14908 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14909 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14910 } else if (!IS_GEN2(dev_priv)) {
14911 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14912 dev_priv->display.get_initial_plane_config =
14913 i9xx_get_initial_plane_config;
14914 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14915 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14916 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14918 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14919 dev_priv->display.get_initial_plane_config =
14920 i9xx_get_initial_plane_config;
14921 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14922 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14923 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14926 if (IS_GEN5(dev_priv)) {
14927 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14928 } else if (IS_GEN6(dev_priv)) {
14929 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14930 } else if (IS_IVYBRIDGE(dev_priv)) {
14931 /* FIXME: detect B0+ stepping and use auto training */
14932 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14933 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
14934 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14937 if (INTEL_GEN(dev_priv) >= 9)
14938 dev_priv->display.update_crtcs = skl_update_crtcs;
14940 dev_priv->display.update_crtcs = intel_update_crtcs;
14944 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14946 static void quirk_ssc_force_disable(struct drm_device *dev)
14948 struct drm_i915_private *dev_priv = to_i915(dev);
14949 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14950 DRM_INFO("applying lvds SSC disable quirk\n");
14954 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14957 static void quirk_invert_brightness(struct drm_device *dev)
14959 struct drm_i915_private *dev_priv = to_i915(dev);
14960 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14961 DRM_INFO("applying inverted panel brightness quirk\n");
14964 /* Some VBT's incorrectly indicate no backlight is present */
14965 static void quirk_backlight_present(struct drm_device *dev)
14967 struct drm_i915_private *dev_priv = to_i915(dev);
14968 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14969 DRM_INFO("applying backlight present quirk\n");
14972 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
14973 * which is 300 ms greater than eDP spec T12 min.
14975 static void quirk_increase_t12_delay(struct drm_device *dev)
14977 struct drm_i915_private *dev_priv = to_i915(dev);
14979 dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY;
14980 DRM_INFO("Applying T12 delay quirk\n");
14984 * GeminiLake NUC HDMI outputs require additional off time
14985 * this allows the onboard retimer to correctly sync to signal
14987 static void quirk_increase_ddi_disabled_time(struct drm_device *dev)
14989 struct drm_i915_private *dev_priv = to_i915(dev);
14991 dev_priv->quirks |= QUIRK_INCREASE_DDI_DISABLED_TIME;
14992 DRM_INFO("Applying Increase DDI Disabled quirk\n");
14995 struct intel_quirk {
14997 int subsystem_vendor;
14998 int subsystem_device;
14999 void (*hook)(struct drm_device *dev);
15002 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
15003 struct intel_dmi_quirk {
15004 void (*hook)(struct drm_device *dev);
15005 const struct dmi_system_id (*dmi_id_list)[];
15008 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
15010 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
15014 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
15016 .dmi_id_list = &(const struct dmi_system_id[]) {
15018 .callback = intel_dmi_reverse_brightness,
15019 .ident = "NCR Corporation",
15020 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
15021 DMI_MATCH(DMI_PRODUCT_NAME, ""),
15024 { } /* terminating entry */
15026 .hook = quirk_invert_brightness,
15030 static struct intel_quirk intel_quirks[] = {
15031 /* Lenovo U160 cannot use SSC on LVDS */
15032 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
15034 /* Sony Vaio Y cannot use SSC on LVDS */
15035 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
15037 /* Acer Aspire 5734Z must invert backlight brightness */
15038 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
15040 /* Acer/eMachines G725 */
15041 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
15043 /* Acer/eMachines e725 */
15044 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
15046 /* Acer/Packard Bell NCL20 */
15047 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
15049 /* Acer Aspire 4736Z */
15050 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
15052 /* Acer Aspire 5336 */
15053 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
15055 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
15056 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
15058 /* Acer C720 Chromebook (Core i3 4005U) */
15059 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
15061 /* Apple Macbook 2,1 (Core 2 T7400) */
15062 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
15064 /* Apple Macbook 4,1 */
15065 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
15067 /* Toshiba CB35 Chromebook (Celeron 2955U) */
15068 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
15070 /* HP Chromebook 14 (Celeron 2955U) */
15071 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
15073 /* Dell Chromebook 11 */
15074 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
15076 /* Dell Chromebook 11 (2015 version) */
15077 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
15079 /* Toshiba Satellite P50-C-18C */
15080 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
15082 /* GeminiLake NUC */
15083 { 0x3185, 0x8086, 0x2072, quirk_increase_ddi_disabled_time },
15084 { 0x3184, 0x8086, 0x2072, quirk_increase_ddi_disabled_time },
15086 { 0x3185, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },
15087 { 0x3184, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },
15090 static void intel_init_quirks(struct drm_device *dev)
15092 struct pci_dev *d = dev->pdev;
15095 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
15096 struct intel_quirk *q = &intel_quirks[i];
15098 if (d->device == q->device &&
15099 (d->subsystem_vendor == q->subsystem_vendor ||
15100 q->subsystem_vendor == PCI_ANY_ID) &&
15101 (d->subsystem_device == q->subsystem_device ||
15102 q->subsystem_device == PCI_ANY_ID))
15105 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
15106 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
15107 intel_dmi_quirks[i].hook(dev);
15111 /* Disable the VGA plane that we never use */
15112 static void i915_disable_vga(struct drm_i915_private *dev_priv)
15114 struct pci_dev *pdev = dev_priv->drm.pdev;
15116 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15118 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15119 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
15120 outb(SR01, VGA_SR_INDEX);
15121 sr1 = inb(VGA_SR_DATA);
15122 outb(sr1 | 1<<5, VGA_SR_DATA);
15123 vga_put(pdev, VGA_RSRC_LEGACY_IO);
15126 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
15127 POSTING_READ(vga_reg);
15130 void intel_modeset_init_hw(struct drm_device *dev)
15132 struct drm_i915_private *dev_priv = to_i915(dev);
15134 intel_update_cdclk(dev_priv);
15135 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
15136 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
15140 * Calculate what we think the watermarks should be for the state we've read
15141 * out of the hardware and then immediately program those watermarks so that
15142 * we ensure the hardware settings match our internal state.
15144 * We can calculate what we think WM's should be by creating a duplicate of the
15145 * current state (which was constructed during hardware readout) and running it
15146 * through the atomic check code to calculate new watermark values in the
15149 static void sanitize_watermarks(struct drm_device *dev)
15151 struct drm_i915_private *dev_priv = to_i915(dev);
15152 struct drm_atomic_state *state;
15153 struct intel_atomic_state *intel_state;
15154 struct drm_crtc *crtc;
15155 struct drm_crtc_state *cstate;
15156 struct drm_modeset_acquire_ctx ctx;
15160 /* Only supported on platforms that use atomic watermark design */
15161 if (!dev_priv->display.optimize_watermarks)
15165 * We need to hold connection_mutex before calling duplicate_state so
15166 * that the connector loop is protected.
15168 drm_modeset_acquire_init(&ctx, 0);
15170 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15171 if (ret == -EDEADLK) {
15172 drm_modeset_backoff(&ctx);
15174 } else if (WARN_ON(ret)) {
15178 state = drm_atomic_helper_duplicate_state(dev, &ctx);
15179 if (WARN_ON(IS_ERR(state)))
15182 intel_state = to_intel_atomic_state(state);
15185 * Hardware readout is the only time we don't want to calculate
15186 * intermediate watermarks (since we don't trust the current
15189 if (!HAS_GMCH_DISPLAY(dev_priv))
15190 intel_state->skip_intermediate_wm = true;
15192 ret = intel_atomic_check(dev, state);
15195 * If we fail here, it means that the hardware appears to be
15196 * programmed in a way that shouldn't be possible, given our
15197 * understanding of watermark requirements. This might mean a
15198 * mistake in the hardware readout code or a mistake in the
15199 * watermark calculations for a given platform. Raise a WARN
15200 * so that this is noticeable.
15202 * If this actually happens, we'll have to just leave the
15203 * BIOS-programmed watermarks untouched and hope for the best.
15205 WARN(true, "Could not determine valid watermarks for inherited state\n");
15209 /* Write calculated watermark values back */
15210 for_each_new_crtc_in_state(state, crtc, cstate, i) {
15211 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
15213 cs->wm.need_postvbl_update = true;
15214 dev_priv->display.optimize_watermarks(intel_state, cs);
15216 to_intel_crtc_state(crtc->state)->wm = cs->wm;
15220 drm_atomic_state_put(state);
15222 drm_modeset_drop_locks(&ctx);
15223 drm_modeset_acquire_fini(&ctx);
15226 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
15228 if (IS_GEN5(dev_priv)) {
15230 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
15232 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
15233 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
15234 dev_priv->fdi_pll_freq = 270000;
15239 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
15242 static int intel_initial_commit(struct drm_device *dev)
15244 struct drm_atomic_state *state = NULL;
15245 struct drm_modeset_acquire_ctx ctx;
15246 struct drm_crtc *crtc;
15247 struct drm_crtc_state *crtc_state;
15250 state = drm_atomic_state_alloc(dev);
15254 drm_modeset_acquire_init(&ctx, 0);
15257 state->acquire_ctx = &ctx;
15259 drm_for_each_crtc(crtc, dev) {
15260 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15261 if (IS_ERR(crtc_state)) {
15262 ret = PTR_ERR(crtc_state);
15266 if (crtc_state->active) {
15267 ret = drm_atomic_add_affected_planes(state, crtc);
15272 * FIXME hack to force a LUT update to avoid the
15273 * plane update forcing the pipe gamma on without
15274 * having a proper LUT loaded. Remove once we
15275 * have readout for pipe gamma enable.
15277 crtc_state->color_mgmt_changed = true;
15281 ret = drm_atomic_commit(state);
15284 if (ret == -EDEADLK) {
15285 drm_atomic_state_clear(state);
15286 drm_modeset_backoff(&ctx);
15290 drm_atomic_state_put(state);
15292 drm_modeset_drop_locks(&ctx);
15293 drm_modeset_acquire_fini(&ctx);
15298 int intel_modeset_init(struct drm_device *dev)
15300 struct drm_i915_private *dev_priv = to_i915(dev);
15301 struct i915_ggtt *ggtt = &dev_priv->ggtt;
15303 struct intel_crtc *crtc;
15306 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15308 drm_mode_config_init(dev);
15310 dev->mode_config.min_width = 0;
15311 dev->mode_config.min_height = 0;
15313 dev->mode_config.preferred_depth = 24;
15314 dev->mode_config.prefer_shadow = 1;
15316 dev->mode_config.allow_fb_modifiers = true;
15318 dev->mode_config.funcs = &intel_mode_funcs;
15320 init_llist_head(&dev_priv->atomic_helper.free_list);
15321 INIT_WORK(&dev_priv->atomic_helper.free_work,
15322 intel_atomic_helper_free_state_worker);
15324 intel_init_quirks(dev);
15326 intel_init_pm(dev_priv);
15329 * There may be no VBT; and if the BIOS enabled SSC we can
15330 * just keep using it to avoid unnecessary flicker. Whereas if the
15331 * BIOS isn't using it, don't assume it will work even if the VBT
15332 * indicates as much.
15334 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
15335 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15338 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15339 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15340 bios_lvds_use_ssc ? "en" : "dis",
15341 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15342 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15346 /* maximum framebuffer dimensions */
15347 if (IS_GEN2(dev_priv)) {
15348 dev->mode_config.max_width = 2048;
15349 dev->mode_config.max_height = 2048;
15350 } else if (IS_GEN3(dev_priv)) {
15351 dev->mode_config.max_width = 4096;
15352 dev->mode_config.max_height = 4096;
15354 dev->mode_config.max_width = 8192;
15355 dev->mode_config.max_height = 8192;
15358 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15359 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
15360 dev->mode_config.cursor_height = 1023;
15361 } else if (IS_GEN2(dev_priv)) {
15362 dev->mode_config.cursor_width = 64;
15363 dev->mode_config.cursor_height = 64;
15365 dev->mode_config.cursor_width = 256;
15366 dev->mode_config.cursor_height = 256;
15369 dev->mode_config.fb_base = ggtt->gmadr.start;
15371 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15372 INTEL_INFO(dev_priv)->num_pipes,
15373 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
15375 for_each_pipe(dev_priv, pipe) {
15376 ret = intel_crtc_init(dev_priv, pipe);
15378 drm_mode_config_cleanup(dev);
15383 intel_shared_dpll_init(dev);
15384 intel_update_fdi_pll_freq(dev_priv);
15386 intel_update_czclk(dev_priv);
15387 intel_modeset_init_hw(dev);
15389 if (dev_priv->max_cdclk_freq == 0)
15390 intel_update_max_cdclk(dev_priv);
15392 /* Just disable it once at startup */
15393 i915_disable_vga(dev_priv);
15394 intel_setup_outputs(dev_priv);
15396 drm_modeset_lock_all(dev);
15397 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
15398 drm_modeset_unlock_all(dev);
15400 for_each_intel_crtc(dev, crtc) {
15401 struct intel_initial_plane_config plane_config = {};
15407 * Note that reserving the BIOS fb up front prevents us
15408 * from stuffing other stolen allocations like the ring
15409 * on top. This prevents some ugliness at boot time, and
15410 * can even allow for smooth boot transitions if the BIOS
15411 * fb is large enough for the active pipe configuration.
15413 dev_priv->display.get_initial_plane_config(crtc,
15417 * If the fb is shared between multiple heads, we'll
15418 * just get the first one.
15420 intel_find_initial_plane_obj(crtc, &plane_config);
15424 * Make sure hardware watermarks really match the state we read out.
15425 * Note that we need to do this after reconstructing the BIOS fb's
15426 * since the watermark calculation done here will use pstate->fb.
15428 if (!HAS_GMCH_DISPLAY(dev_priv))
15429 sanitize_watermarks(dev);
15432 * Force all active planes to recompute their states. So that on
15433 * mode_setcrtc after probe, all the intel_plane_state variables
15434 * are already calculated and there is no assert_plane warnings
15437 ret = intel_initial_commit(dev);
15439 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15444 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15446 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15447 /* 640x480@60Hz, ~25175 kHz */
15448 struct dpll clock = {
15458 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15460 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15461 pipe_name(pipe), clock.vco, clock.dot);
15463 fp = i9xx_dpll_compute_fp(&clock);
15464 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15465 DPLL_VGA_MODE_DIS |
15466 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15467 PLL_P2_DIVIDE_BY_4 |
15468 PLL_REF_INPUT_DREFCLK |
15471 I915_WRITE(FP0(pipe), fp);
15472 I915_WRITE(FP1(pipe), fp);
15474 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15475 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15476 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15477 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15478 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15479 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15480 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15483 * Apparently we need to have VGA mode enabled prior to changing
15484 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15485 * dividers, even though the register value does change.
15487 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15488 I915_WRITE(DPLL(pipe), dpll);
15490 /* Wait for the clocks to stabilize. */
15491 POSTING_READ(DPLL(pipe));
15494 /* The pixel multiplier can only be updated once the
15495 * DPLL is enabled and the clocks are stable.
15497 * So write it again.
15499 I915_WRITE(DPLL(pipe), dpll);
15501 /* We do this three times for luck */
15502 for (i = 0; i < 3 ; i++) {
15503 I915_WRITE(DPLL(pipe), dpll);
15504 POSTING_READ(DPLL(pipe));
15505 udelay(150); /* wait for warmup */
15508 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15509 POSTING_READ(PIPECONF(pipe));
15511 intel_wait_for_pipe_scanline_moving(crtc);
15514 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15516 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15518 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15521 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15522 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15523 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
15524 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15525 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
15527 I915_WRITE(PIPECONF(pipe), 0);
15528 POSTING_READ(PIPECONF(pipe));
15530 intel_wait_for_pipe_scanline_stopped(crtc);
15532 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15533 POSTING_READ(DPLL(pipe));
15537 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15539 struct intel_crtc *crtc;
15541 if (INTEL_GEN(dev_priv) >= 4)
15544 for_each_intel_crtc(&dev_priv->drm, crtc) {
15545 struct intel_plane *plane =
15546 to_intel_plane(crtc->base.primary);
15547 struct intel_crtc *plane_crtc;
15550 if (!plane->get_hw_state(plane, &pipe))
15553 if (pipe == crtc->pipe)
15556 DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n",
15559 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15560 intel_plane_disable_noatomic(plane_crtc, plane);
15564 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15566 struct drm_device *dev = crtc->base.dev;
15567 struct intel_encoder *encoder;
15569 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15575 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15577 struct drm_device *dev = encoder->base.dev;
15578 struct intel_connector *connector;
15580 for_each_connector_on_encoder(dev, &encoder->base, connector)
15586 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15587 enum pipe pch_transcoder)
15589 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15590 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15593 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15594 struct drm_modeset_acquire_ctx *ctx)
15596 struct drm_device *dev = crtc->base.dev;
15597 struct drm_i915_private *dev_priv = to_i915(dev);
15598 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
15600 /* Clear any frame start delays used for debugging left by the BIOS */
15601 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
15602 i915_reg_t reg = PIPECONF(cpu_transcoder);
15605 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15608 if (crtc->active) {
15609 struct intel_plane *plane;
15611 /* Disable everything but the primary plane */
15612 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15613 const struct intel_plane_state *plane_state =
15614 to_intel_plane_state(plane->base.state);
15616 if (plane_state->base.visible &&
15617 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15618 intel_plane_disable_noatomic(crtc, plane);
15622 /* Adjust the state of the output pipe according to whether we
15623 * have active connectors/encoders. */
15624 if (crtc->active && !intel_crtc_has_encoders(crtc))
15625 intel_crtc_disable_noatomic(&crtc->base, ctx);
15627 if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) {
15629 * We start out with underrun reporting disabled to avoid races.
15630 * For correct bookkeeping mark this on active crtcs.
15632 * Also on gmch platforms we dont have any hardware bits to
15633 * disable the underrun reporting. Which means we need to start
15634 * out with underrun reporting disabled also on inactive pipes,
15635 * since otherwise we'll complain about the garbage we read when
15636 * e.g. coming up after runtime pm.
15638 * No protection against concurrent access is required - at
15639 * worst a fifo underrun happens which also sets this to false.
15641 crtc->cpu_fifo_underrun_disabled = true;
15643 * We track the PCH trancoder underrun reporting state
15644 * within the crtc. With crtc for pipe A housing the underrun
15645 * reporting state for PCH transcoder A, crtc for pipe B housing
15646 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15647 * and marking underrun reporting as disabled for the non-existing
15648 * PCH transcoders B and C would prevent enabling the south
15649 * error interrupt (see cpt_can_enable_serr_int()).
15651 if (has_pch_trancoder(dev_priv, crtc->pipe))
15652 crtc->pch_fifo_underrun_disabled = true;
15656 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15658 struct intel_connector *connector;
15660 /* We need to check both for a crtc link (meaning that the
15661 * encoder is active and trying to read from a pipe) and the
15662 * pipe itself being active. */
15663 bool has_active_crtc = encoder->base.crtc &&
15664 to_intel_crtc(encoder->base.crtc)->active;
15666 connector = intel_encoder_find_connector(encoder);
15667 if (connector && !has_active_crtc) {
15668 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15669 encoder->base.base.id,
15670 encoder->base.name);
15672 /* Connector is active, but has no active pipe. This is
15673 * fallout from our resume register restoring. Disable
15674 * the encoder manually again. */
15675 if (encoder->base.crtc) {
15676 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15678 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15679 encoder->base.base.id,
15680 encoder->base.name);
15681 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15682 if (encoder->post_disable)
15683 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15685 encoder->base.crtc = NULL;
15687 /* Inconsistent output/port/pipe state happens presumably due to
15688 * a bug in one of the get_hw_state functions. Or someplace else
15689 * in our code, like the register restore mess on resume. Clamp
15690 * things to off as a safer default. */
15692 connector->base.dpms = DRM_MODE_DPMS_OFF;
15693 connector->base.encoder = NULL;
15696 /* notify opregion of the sanitized encoder state */
15697 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
15700 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15702 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15704 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15705 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15706 i915_disable_vga(dev_priv);
15710 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15712 /* This function can be called both from intel_modeset_setup_hw_state or
15713 * at a very early point in our resume sequence, where the power well
15714 * structures are not yet restored. Since this function is at a very
15715 * paranoid "someone might have enabled VGA while we were not looking"
15716 * level, just check if the power well is enabled instead of trying to
15717 * follow the "don't touch the power well if we don't need it" policy
15718 * the rest of the driver uses. */
15719 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
15722 i915_redisable_vga_power_on(dev_priv);
15724 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
15727 /* FIXME read out full plane state for all planes */
15728 static void readout_plane_state(struct drm_i915_private *dev_priv)
15730 struct intel_plane *plane;
15731 struct intel_crtc *crtc;
15733 for_each_intel_plane(&dev_priv->drm, plane) {
15734 struct intel_plane_state *plane_state =
15735 to_intel_plane_state(plane->base.state);
15736 struct intel_crtc_state *crtc_state;
15737 enum pipe pipe = PIPE_A;
15740 visible = plane->get_hw_state(plane, &pipe);
15742 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15743 crtc_state = to_intel_crtc_state(crtc->base.state);
15745 intel_set_plane_visible(crtc_state, plane_state, visible);
15748 for_each_intel_crtc(&dev_priv->drm, crtc) {
15749 struct intel_crtc_state *crtc_state =
15750 to_intel_crtc_state(crtc->base.state);
15752 fixup_active_planes(crtc_state);
15756 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15758 struct drm_i915_private *dev_priv = to_i915(dev);
15760 struct intel_crtc *crtc;
15761 struct intel_encoder *encoder;
15762 struct intel_connector *connector;
15763 struct drm_connector_list_iter conn_iter;
15766 dev_priv->active_crtcs = 0;
15768 for_each_intel_crtc(dev, crtc) {
15769 struct intel_crtc_state *crtc_state =
15770 to_intel_crtc_state(crtc->base.state);
15772 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15773 memset(crtc_state, 0, sizeof(*crtc_state));
15774 crtc_state->base.crtc = &crtc->base;
15776 crtc_state->base.active = crtc_state->base.enable =
15777 dev_priv->display.get_pipe_config(crtc, crtc_state);
15779 crtc->base.enabled = crtc_state->base.enable;
15780 crtc->active = crtc_state->base.active;
15782 if (crtc_state->base.active)
15783 dev_priv->active_crtcs |= 1 << crtc->pipe;
15785 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15786 crtc->base.base.id, crtc->base.name,
15787 enableddisabled(crtc_state->base.active));
15790 readout_plane_state(dev_priv);
15792 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15793 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15795 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15796 &pll->state.hw_state);
15797 pll->state.crtc_mask = 0;
15798 for_each_intel_crtc(dev, crtc) {
15799 struct intel_crtc_state *crtc_state =
15800 to_intel_crtc_state(crtc->base.state);
15802 if (crtc_state->base.active &&
15803 crtc_state->shared_dpll == pll)
15804 pll->state.crtc_mask |= 1 << crtc->pipe;
15806 pll->active_mask = pll->state.crtc_mask;
15808 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15809 pll->info->name, pll->state.crtc_mask, pll->on);
15812 for_each_intel_encoder(dev, encoder) {
15815 if (encoder->get_hw_state(encoder, &pipe)) {
15816 struct intel_crtc_state *crtc_state;
15818 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15819 crtc_state = to_intel_crtc_state(crtc->base.state);
15821 encoder->base.crtc = &crtc->base;
15822 encoder->get_config(encoder, crtc_state);
15824 encoder->base.crtc = NULL;
15827 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15828 encoder->base.base.id, encoder->base.name,
15829 enableddisabled(encoder->base.crtc),
15833 drm_connector_list_iter_begin(dev, &conn_iter);
15834 for_each_intel_connector_iter(connector, &conn_iter) {
15835 if (connector->get_hw_state(connector)) {
15836 connector->base.dpms = DRM_MODE_DPMS_ON;
15838 encoder = connector->encoder;
15839 connector->base.encoder = &encoder->base;
15841 if (encoder->base.crtc &&
15842 encoder->base.crtc->state->active) {
15844 * This has to be done during hardware readout
15845 * because anything calling .crtc_disable may
15846 * rely on the connector_mask being accurate.
15848 encoder->base.crtc->state->connector_mask |=
15849 drm_connector_mask(&connector->base);
15850 encoder->base.crtc->state->encoder_mask |=
15851 drm_encoder_mask(&encoder->base);
15855 connector->base.dpms = DRM_MODE_DPMS_OFF;
15856 connector->base.encoder = NULL;
15858 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15859 connector->base.base.id, connector->base.name,
15860 enableddisabled(connector->base.encoder));
15862 drm_connector_list_iter_end(&conn_iter);
15864 for_each_intel_crtc(dev, crtc) {
15865 struct intel_crtc_state *crtc_state =
15866 to_intel_crtc_state(crtc->base.state);
15869 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15870 if (crtc_state->base.active) {
15871 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15872 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15873 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
15874 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15875 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15878 * The initial mode needs to be set in order to keep
15879 * the atomic core happy. It wants a valid mode if the
15880 * crtc's enabled, so we do the above call.
15882 * But we don't set all the derived state fully, hence
15883 * set a flag to indicate that a full recalculation is
15884 * needed on the next commit.
15886 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
15888 intel_crtc_compute_pixel_rate(crtc_state);
15890 if (dev_priv->display.modeset_calc_cdclk) {
15891 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15892 if (WARN_ON(min_cdclk < 0))
15896 drm_calc_timestamping_constants(&crtc->base,
15897 &crtc_state->base.adjusted_mode);
15898 update_scanline_offset(crtc);
15901 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
15902 dev_priv->min_voltage_level[crtc->pipe] =
15903 crtc_state->min_voltage_level;
15905 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15910 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15912 struct intel_encoder *encoder;
15914 for_each_intel_encoder(&dev_priv->drm, encoder) {
15916 enum intel_display_power_domain domain;
15917 struct intel_crtc_state *crtc_state;
15919 if (!encoder->get_power_domains)
15923 * MST-primary and inactive encoders don't have a crtc state
15924 * and neither of these require any power domain references.
15926 if (!encoder->base.crtc)
15929 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
15930 get_domains = encoder->get_power_domains(encoder, crtc_state);
15931 for_each_power_domain(domain, get_domains)
15932 intel_display_power_get(dev_priv, domain);
15936 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15938 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15939 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15940 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15943 if (IS_HASWELL(dev_priv)) {
15945 * WaRsPkgCStateDisplayPMReq:hsw
15946 * System hang if this isn't done before disabling all planes!
15948 I915_WRITE(CHICKEN_PAR1_1,
15949 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15953 /* Scan out the current hw modeset state,
15954 * and sanitizes it to the current state
15957 intel_modeset_setup_hw_state(struct drm_device *dev,
15958 struct drm_modeset_acquire_ctx *ctx)
15960 struct drm_i915_private *dev_priv = to_i915(dev);
15961 struct intel_crtc *crtc;
15962 struct intel_encoder *encoder;
15965 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15967 intel_early_display_was(dev_priv);
15968 intel_modeset_readout_hw_state(dev);
15970 /* HW state is read out, now we need to sanitize this mess. */
15971 get_encoder_power_domains(dev_priv);
15974 * intel_sanitize_plane_mapping() may need to do vblank
15975 * waits, so we need vblank interrupts restored beforehand.
15977 for_each_intel_crtc(&dev_priv->drm, crtc) {
15978 drm_crtc_vblank_reset(&crtc->base);
15981 drm_crtc_vblank_on(&crtc->base);
15984 intel_sanitize_plane_mapping(dev_priv);
15986 for_each_intel_encoder(dev, encoder)
15987 intel_sanitize_encoder(encoder);
15989 for_each_intel_crtc(&dev_priv->drm, crtc) {
15990 intel_sanitize_crtc(crtc, ctx);
15991 intel_dump_pipe_config(crtc, crtc->config,
15992 "[setup_hw_state]");
15995 intel_modeset_update_connector_atomic_state(dev);
15997 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15998 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16000 if (!pll->on || pll->active_mask)
16003 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
16006 pll->info->funcs->disable(dev_priv, pll);
16010 if (IS_G4X(dev_priv)) {
16011 g4x_wm_get_hw_state(dev);
16012 g4x_wm_sanitize(dev_priv);
16013 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16014 vlv_wm_get_hw_state(dev);
16015 vlv_wm_sanitize(dev_priv);
16016 } else if (INTEL_GEN(dev_priv) >= 9) {
16017 skl_wm_get_hw_state(dev);
16018 } else if (HAS_PCH_SPLIT(dev_priv)) {
16019 ilk_wm_get_hw_state(dev);
16022 for_each_intel_crtc(dev, crtc) {
16025 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config);
16026 if (WARN_ON(put_domains))
16027 modeset_put_power_domains(dev_priv, put_domains);
16030 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
16032 intel_fbc_init_pipe_state(dev_priv);
16035 void intel_display_resume(struct drm_device *dev)
16037 struct drm_i915_private *dev_priv = to_i915(dev);
16038 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
16039 struct drm_modeset_acquire_ctx ctx;
16042 dev_priv->modeset_restore_state = NULL;
16044 state->acquire_ctx = &ctx;
16046 drm_modeset_acquire_init(&ctx, 0);
16049 ret = drm_modeset_lock_all_ctx(dev, &ctx);
16050 if (ret != -EDEADLK)
16053 drm_modeset_backoff(&ctx);
16057 ret = __intel_display_resume(dev, state, &ctx);
16059 intel_enable_ipc(dev_priv);
16060 drm_modeset_drop_locks(&ctx);
16061 drm_modeset_acquire_fini(&ctx);
16064 DRM_ERROR("Restoring old state failed with %i\n", ret);
16066 drm_atomic_state_put(state);
16069 int intel_connector_register(struct drm_connector *connector)
16071 struct intel_connector *intel_connector = to_intel_connector(connector);
16074 ret = intel_backlight_device_register(intel_connector);
16084 void intel_connector_unregister(struct drm_connector *connector)
16086 struct intel_connector *intel_connector = to_intel_connector(connector);
16088 intel_backlight_device_unregister(intel_connector);
16089 intel_panel_destroy_backlight(connector);
16092 static void intel_hpd_poll_fini(struct drm_device *dev)
16094 struct intel_connector *connector;
16095 struct drm_connector_list_iter conn_iter;
16097 /* Kill all the work that may have been queued by hpd. */
16098 drm_connector_list_iter_begin(dev, &conn_iter);
16099 for_each_intel_connector_iter(connector, &conn_iter) {
16100 if (connector->modeset_retry_work.func)
16101 cancel_work_sync(&connector->modeset_retry_work);
16102 if (connector->hdcp_shim) {
16103 cancel_delayed_work_sync(&connector->hdcp_check_work);
16104 cancel_work_sync(&connector->hdcp_prop_work);
16107 drm_connector_list_iter_end(&conn_iter);
16110 void intel_modeset_cleanup(struct drm_device *dev)
16112 struct drm_i915_private *dev_priv = to_i915(dev);
16114 flush_workqueue(dev_priv->modeset_wq);
16116 flush_work(&dev_priv->atomic_helper.free_work);
16117 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
16120 * Interrupts and polling as the first thing to avoid creating havoc.
16121 * Too much stuff here (turning of connectors, ...) would
16122 * experience fancy races otherwise.
16124 intel_irq_uninstall(dev_priv);
16127 * Due to the hpd irq storm handling the hotplug work can re-arm the
16128 * poll handlers. Hence disable polling after hpd handling is shut down.
16130 intel_hpd_poll_fini(dev);
16132 /* poll work can call into fbdev, hence clean that up afterwards */
16133 intel_fbdev_fini(dev_priv);
16135 intel_unregister_dsm_handler();
16137 intel_fbc_global_disable(dev_priv);
16139 /* flush any delayed tasks or pending work */
16140 flush_scheduled_work();
16142 drm_mode_config_cleanup(dev);
16144 intel_cleanup_overlay(dev_priv);
16146 intel_teardown_gmbus(dev_priv);
16148 destroy_workqueue(dev_priv->modeset_wq);
16151 void intel_connector_attach_encoder(struct intel_connector *connector,
16152 struct intel_encoder *encoder)
16154 connector->encoder = encoder;
16155 drm_connector_attach_encoder(&connector->base, &encoder->base);
16159 * set vga decode state - true == enable VGA decode
16161 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
16163 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
16166 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
16167 DRM_ERROR("failed to read control word\n");
16171 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
16175 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
16177 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
16179 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
16180 DRM_ERROR("failed to write control word\n");
16187 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
16189 struct intel_display_error_state {
16191 u32 power_well_driver;
16193 int num_transcoders;
16195 struct intel_cursor_error_state {
16200 } cursor[I915_MAX_PIPES];
16202 struct intel_pipe_error_state {
16203 bool power_domain_on;
16206 } pipe[I915_MAX_PIPES];
16208 struct intel_plane_error_state {
16216 } plane[I915_MAX_PIPES];
16218 struct intel_transcoder_error_state {
16219 bool power_domain_on;
16220 enum transcoder cpu_transcoder;
16233 struct intel_display_error_state *
16234 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
16236 struct intel_display_error_state *error;
16237 int transcoders[] = {
16245 if (INTEL_INFO(dev_priv)->num_pipes == 0)
16248 error = kzalloc(sizeof(*error), GFP_ATOMIC);
16252 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16253 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
16255 for_each_pipe(dev_priv, i) {
16256 error->pipe[i].power_domain_on =
16257 __intel_display_power_is_enabled(dev_priv,
16258 POWER_DOMAIN_PIPE(i));
16259 if (!error->pipe[i].power_domain_on)
16262 error->cursor[i].control = I915_READ(CURCNTR(i));
16263 error->cursor[i].position = I915_READ(CURPOS(i));
16264 error->cursor[i].base = I915_READ(CURBASE(i));
16266 error->plane[i].control = I915_READ(DSPCNTR(i));
16267 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
16268 if (INTEL_GEN(dev_priv) <= 3) {
16269 error->plane[i].size = I915_READ(DSPSIZE(i));
16270 error->plane[i].pos = I915_READ(DSPPOS(i));
16272 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16273 error->plane[i].addr = I915_READ(DSPADDR(i));
16274 if (INTEL_GEN(dev_priv) >= 4) {
16275 error->plane[i].surface = I915_READ(DSPSURF(i));
16276 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16279 error->pipe[i].source = I915_READ(PIPESRC(i));
16281 if (HAS_GMCH_DISPLAY(dev_priv))
16282 error->pipe[i].stat = I915_READ(PIPESTAT(i));
16285 /* Note: this does not include DSI transcoders. */
16286 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
16287 if (HAS_DDI(dev_priv))
16288 error->num_transcoders++; /* Account for eDP. */
16290 for (i = 0; i < error->num_transcoders; i++) {
16291 enum transcoder cpu_transcoder = transcoders[i];
16293 error->transcoder[i].power_domain_on =
16294 __intel_display_power_is_enabled(dev_priv,
16295 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
16296 if (!error->transcoder[i].power_domain_on)
16299 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16301 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16302 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16303 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16304 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16305 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16306 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16307 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
16313 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16316 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
16317 struct intel_display_error_state *error)
16319 struct drm_i915_private *dev_priv = m->i915;
16325 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
16326 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16327 err_printf(m, "PWR_WELL_CTL2: %08x\n",
16328 error->power_well_driver);
16329 for_each_pipe(dev_priv, i) {
16330 err_printf(m, "Pipe [%d]:\n", i);
16331 err_printf(m, " Power: %s\n",
16332 onoff(error->pipe[i].power_domain_on));
16333 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
16334 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
16336 err_printf(m, "Plane [%d]:\n", i);
16337 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16338 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
16339 if (INTEL_GEN(dev_priv) <= 3) {
16340 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16341 err_printf(m, " POS: %08x\n", error->plane[i].pos);
16343 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16344 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
16345 if (INTEL_GEN(dev_priv) >= 4) {
16346 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16347 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
16350 err_printf(m, "Cursor [%d]:\n", i);
16351 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16352 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16353 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
16356 for (i = 0; i < error->num_transcoders; i++) {
16357 err_printf(m, "CPU transcoder: %s\n",
16358 transcoder_name(error->transcoder[i].cpu_transcoder));
16359 err_printf(m, " Power: %s\n",
16360 onoff(error->transcoder[i].power_domain_on));
16361 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16362 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16363 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16364 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16365 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16366 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16367 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);