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
78 static const uint32_t intel_cursor_formats[] = {
82 static const uint64_t cursor_format_modifiers[] = {
83 DRM_FORMAT_MOD_LINEAR,
84 DRM_FORMAT_MOD_INVALID
87 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
88 struct intel_crtc_state *pipe_config);
89 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
90 struct intel_crtc_state *pipe_config);
92 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
93 struct drm_i915_gem_object *obj,
94 struct drm_mode_fb_cmd2 *mode_cmd);
95 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
96 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
97 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
98 struct intel_link_m_n *m_n,
99 struct intel_link_m_n *m2_n2);
100 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
101 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
102 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
103 static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state);
104 static void vlv_prepare_pll(struct intel_crtc *crtc,
105 const struct intel_crtc_state *pipe_config);
106 static void chv_prepare_pll(struct intel_crtc *crtc,
107 const struct intel_crtc_state *pipe_config);
108 static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
109 static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
110 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
111 struct intel_crtc_state *crtc_state);
112 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
113 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
114 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
115 static void intel_modeset_setup_hw_state(struct drm_device *dev,
116 struct drm_modeset_acquire_ctx *ctx);
117 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
122 } dot, vco, n, m, m1, m2, p, p1;
126 int p2_slow, p2_fast;
130 /* returns HPLL frequency in kHz */
131 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
133 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
135 /* Obtain SKU information */
136 mutex_lock(&dev_priv->sb_lock);
137 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
138 CCK_FUSE_HPLL_FREQ_MASK;
139 mutex_unlock(&dev_priv->sb_lock);
141 return vco_freq[hpll_freq] * 1000;
144 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
145 const char *name, u32 reg, int ref_freq)
150 mutex_lock(&dev_priv->sb_lock);
151 val = vlv_cck_read(dev_priv, reg);
152 mutex_unlock(&dev_priv->sb_lock);
154 divider = val & CCK_FREQUENCY_VALUES;
156 WARN((val & CCK_FREQUENCY_STATUS) !=
157 (divider << CCK_FREQUENCY_STATUS_SHIFT),
158 "%s change in progress\n", name);
160 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
163 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
164 const char *name, u32 reg)
166 if (dev_priv->hpll_freq == 0)
167 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
169 return vlv_get_cck_clock(dev_priv, name, reg,
170 dev_priv->hpll_freq);
173 static void intel_update_czclk(struct drm_i915_private *dev_priv)
175 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
178 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
179 CCK_CZ_CLOCK_CONTROL);
181 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
184 static inline u32 /* units of 100MHz */
185 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
186 const struct intel_crtc_state *pipe_config)
188 if (HAS_DDI(dev_priv))
189 return pipe_config->port_clock; /* SPLL */
191 return dev_priv->fdi_pll_freq;
194 static const struct intel_limit intel_limits_i8xx_dac = {
195 .dot = { .min = 25000, .max = 350000 },
196 .vco = { .min = 908000, .max = 1512000 },
197 .n = { .min = 2, .max = 16 },
198 .m = { .min = 96, .max = 140 },
199 .m1 = { .min = 18, .max = 26 },
200 .m2 = { .min = 6, .max = 16 },
201 .p = { .min = 4, .max = 128 },
202 .p1 = { .min = 2, .max = 33 },
203 .p2 = { .dot_limit = 165000,
204 .p2_slow = 4, .p2_fast = 2 },
207 static const struct intel_limit intel_limits_i8xx_dvo = {
208 .dot = { .min = 25000, .max = 350000 },
209 .vco = { .min = 908000, .max = 1512000 },
210 .n = { .min = 2, .max = 16 },
211 .m = { .min = 96, .max = 140 },
212 .m1 = { .min = 18, .max = 26 },
213 .m2 = { .min = 6, .max = 16 },
214 .p = { .min = 4, .max = 128 },
215 .p1 = { .min = 2, .max = 33 },
216 .p2 = { .dot_limit = 165000,
217 .p2_slow = 4, .p2_fast = 4 },
220 static const struct intel_limit intel_limits_i8xx_lvds = {
221 .dot = { .min = 25000, .max = 350000 },
222 .vco = { .min = 908000, .max = 1512000 },
223 .n = { .min = 2, .max = 16 },
224 .m = { .min = 96, .max = 140 },
225 .m1 = { .min = 18, .max = 26 },
226 .m2 = { .min = 6, .max = 16 },
227 .p = { .min = 4, .max = 128 },
228 .p1 = { .min = 1, .max = 6 },
229 .p2 = { .dot_limit = 165000,
230 .p2_slow = 14, .p2_fast = 7 },
233 static const struct intel_limit intel_limits_i9xx_sdvo = {
234 .dot = { .min = 20000, .max = 400000 },
235 .vco = { .min = 1400000, .max = 2800000 },
236 .n = { .min = 1, .max = 6 },
237 .m = { .min = 70, .max = 120 },
238 .m1 = { .min = 8, .max = 18 },
239 .m2 = { .min = 3, .max = 7 },
240 .p = { .min = 5, .max = 80 },
241 .p1 = { .min = 1, .max = 8 },
242 .p2 = { .dot_limit = 200000,
243 .p2_slow = 10, .p2_fast = 5 },
246 static const struct intel_limit intel_limits_i9xx_lvds = {
247 .dot = { .min = 20000, .max = 400000 },
248 .vco = { .min = 1400000, .max = 2800000 },
249 .n = { .min = 1, .max = 6 },
250 .m = { .min = 70, .max = 120 },
251 .m1 = { .min = 8, .max = 18 },
252 .m2 = { .min = 3, .max = 7 },
253 .p = { .min = 7, .max = 98 },
254 .p1 = { .min = 1, .max = 8 },
255 .p2 = { .dot_limit = 112000,
256 .p2_slow = 14, .p2_fast = 7 },
260 static const struct intel_limit intel_limits_g4x_sdvo = {
261 .dot = { .min = 25000, .max = 270000 },
262 .vco = { .min = 1750000, .max = 3500000},
263 .n = { .min = 1, .max = 4 },
264 .m = { .min = 104, .max = 138 },
265 .m1 = { .min = 17, .max = 23 },
266 .m2 = { .min = 5, .max = 11 },
267 .p = { .min = 10, .max = 30 },
268 .p1 = { .min = 1, .max = 3},
269 .p2 = { .dot_limit = 270000,
275 static const struct intel_limit intel_limits_g4x_hdmi = {
276 .dot = { .min = 22000, .max = 400000 },
277 .vco = { .min = 1750000, .max = 3500000},
278 .n = { .min = 1, .max = 4 },
279 .m = { .min = 104, .max = 138 },
280 .m1 = { .min = 16, .max = 23 },
281 .m2 = { .min = 5, .max = 11 },
282 .p = { .min = 5, .max = 80 },
283 .p1 = { .min = 1, .max = 8},
284 .p2 = { .dot_limit = 165000,
285 .p2_slow = 10, .p2_fast = 5 },
288 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
289 .dot = { .min = 20000, .max = 115000 },
290 .vco = { .min = 1750000, .max = 3500000 },
291 .n = { .min = 1, .max = 3 },
292 .m = { .min = 104, .max = 138 },
293 .m1 = { .min = 17, .max = 23 },
294 .m2 = { .min = 5, .max = 11 },
295 .p = { .min = 28, .max = 112 },
296 .p1 = { .min = 2, .max = 8 },
297 .p2 = { .dot_limit = 0,
298 .p2_slow = 14, .p2_fast = 14
302 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
303 .dot = { .min = 80000, .max = 224000 },
304 .vco = { .min = 1750000, .max = 3500000 },
305 .n = { .min = 1, .max = 3 },
306 .m = { .min = 104, .max = 138 },
307 .m1 = { .min = 17, .max = 23 },
308 .m2 = { .min = 5, .max = 11 },
309 .p = { .min = 14, .max = 42 },
310 .p1 = { .min = 2, .max = 6 },
311 .p2 = { .dot_limit = 0,
312 .p2_slow = 7, .p2_fast = 7
316 static const struct intel_limit intel_limits_pineview_sdvo = {
317 .dot = { .min = 20000, .max = 400000},
318 .vco = { .min = 1700000, .max = 3500000 },
319 /* Pineview's Ncounter is a ring counter */
320 .n = { .min = 3, .max = 6 },
321 .m = { .min = 2, .max = 256 },
322 /* Pineview only has one combined m divider, which we treat as m2. */
323 .m1 = { .min = 0, .max = 0 },
324 .m2 = { .min = 0, .max = 254 },
325 .p = { .min = 5, .max = 80 },
326 .p1 = { .min = 1, .max = 8 },
327 .p2 = { .dot_limit = 200000,
328 .p2_slow = 10, .p2_fast = 5 },
331 static const struct intel_limit intel_limits_pineview_lvds = {
332 .dot = { .min = 20000, .max = 400000 },
333 .vco = { .min = 1700000, .max = 3500000 },
334 .n = { .min = 3, .max = 6 },
335 .m = { .min = 2, .max = 256 },
336 .m1 = { .min = 0, .max = 0 },
337 .m2 = { .min = 0, .max = 254 },
338 .p = { .min = 7, .max = 112 },
339 .p1 = { .min = 1, .max = 8 },
340 .p2 = { .dot_limit = 112000,
341 .p2_slow = 14, .p2_fast = 14 },
344 /* Ironlake / Sandybridge
346 * We calculate clock using (register_value + 2) for N/M1/M2, so here
347 * the range value for them is (actual_value - 2).
349 static const struct intel_limit intel_limits_ironlake_dac = {
350 .dot = { .min = 25000, .max = 350000 },
351 .vco = { .min = 1760000, .max = 3510000 },
352 .n = { .min = 1, .max = 5 },
353 .m = { .min = 79, .max = 127 },
354 .m1 = { .min = 12, .max = 22 },
355 .m2 = { .min = 5, .max = 9 },
356 .p = { .min = 5, .max = 80 },
357 .p1 = { .min = 1, .max = 8 },
358 .p2 = { .dot_limit = 225000,
359 .p2_slow = 10, .p2_fast = 5 },
362 static const struct intel_limit intel_limits_ironlake_single_lvds = {
363 .dot = { .min = 25000, .max = 350000 },
364 .vco = { .min = 1760000, .max = 3510000 },
365 .n = { .min = 1, .max = 3 },
366 .m = { .min = 79, .max = 118 },
367 .m1 = { .min = 12, .max = 22 },
368 .m2 = { .min = 5, .max = 9 },
369 .p = { .min = 28, .max = 112 },
370 .p1 = { .min = 2, .max = 8 },
371 .p2 = { .dot_limit = 225000,
372 .p2_slow = 14, .p2_fast = 14 },
375 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
376 .dot = { .min = 25000, .max = 350000 },
377 .vco = { .min = 1760000, .max = 3510000 },
378 .n = { .min = 1, .max = 3 },
379 .m = { .min = 79, .max = 127 },
380 .m1 = { .min = 12, .max = 22 },
381 .m2 = { .min = 5, .max = 9 },
382 .p = { .min = 14, .max = 56 },
383 .p1 = { .min = 2, .max = 8 },
384 .p2 = { .dot_limit = 225000,
385 .p2_slow = 7, .p2_fast = 7 },
388 /* LVDS 100mhz refclk limits. */
389 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
390 .dot = { .min = 25000, .max = 350000 },
391 .vco = { .min = 1760000, .max = 3510000 },
392 .n = { .min = 1, .max = 2 },
393 .m = { .min = 79, .max = 126 },
394 .m1 = { .min = 12, .max = 22 },
395 .m2 = { .min = 5, .max = 9 },
396 .p = { .min = 28, .max = 112 },
397 .p1 = { .min = 2, .max = 8 },
398 .p2 = { .dot_limit = 225000,
399 .p2_slow = 14, .p2_fast = 14 },
402 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
403 .dot = { .min = 25000, .max = 350000 },
404 .vco = { .min = 1760000, .max = 3510000 },
405 .n = { .min = 1, .max = 3 },
406 .m = { .min = 79, .max = 126 },
407 .m1 = { .min = 12, .max = 22 },
408 .m2 = { .min = 5, .max = 9 },
409 .p = { .min = 14, .max = 42 },
410 .p1 = { .min = 2, .max = 6 },
411 .p2 = { .dot_limit = 225000,
412 .p2_slow = 7, .p2_fast = 7 },
415 static const struct intel_limit intel_limits_vlv = {
417 * These are the data rate limits (measured in fast clocks)
418 * since those are the strictest limits we have. The fast
419 * clock and actual rate limits are more relaxed, so checking
420 * them would make no difference.
422 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
423 .vco = { .min = 4000000, .max = 6000000 },
424 .n = { .min = 1, .max = 7 },
425 .m1 = { .min = 2, .max = 3 },
426 .m2 = { .min = 11, .max = 156 },
427 .p1 = { .min = 2, .max = 3 },
428 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
431 static const struct intel_limit intel_limits_chv = {
433 * These are the data rate limits (measured in fast clocks)
434 * since those are the strictest limits we have. The fast
435 * clock and actual rate limits are more relaxed, so checking
436 * them would make no difference.
438 .dot = { .min = 25000 * 5, .max = 540000 * 5},
439 .vco = { .min = 4800000, .max = 6480000 },
440 .n = { .min = 1, .max = 1 },
441 .m1 = { .min = 2, .max = 2 },
442 .m2 = { .min = 24 << 22, .max = 175 << 22 },
443 .p1 = { .min = 2, .max = 4 },
444 .p2 = { .p2_slow = 1, .p2_fast = 14 },
447 static const struct intel_limit intel_limits_bxt = {
448 /* FIXME: find real dot limits */
449 .dot = { .min = 0, .max = INT_MAX },
450 .vco = { .min = 4800000, .max = 6700000 },
451 .n = { .min = 1, .max = 1 },
452 .m1 = { .min = 2, .max = 2 },
453 /* FIXME: find real m2 limits */
454 .m2 = { .min = 2 << 22, .max = 255 << 22 },
455 .p1 = { .min = 2, .max = 4 },
456 .p2 = { .p2_slow = 1, .p2_fast = 20 },
460 skl_wa_528(struct drm_i915_private *dev_priv, int pipe, bool enable)
462 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
466 I915_WRITE(CHICKEN_PIPESL_1(pipe), HSW_FBCQ_DIS);
468 I915_WRITE(CHICKEN_PIPESL_1(pipe), 0);
472 skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
474 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
478 I915_WRITE(CLKGATE_DIS_PSL(pipe),
479 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
481 I915_WRITE(CLKGATE_DIS_PSL(pipe),
482 I915_READ(CLKGATE_DIS_PSL(pipe)) &
483 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
487 needs_modeset(const struct drm_crtc_state *state)
489 return drm_atomic_crtc_needs_modeset(state);
493 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
494 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
495 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
496 * The helpers' return value is the rate of the clock that is fed to the
497 * display engine's pipe which can be the above fast dot clock rate or a
498 * divided-down version of it.
500 /* m1 is reserved as 0 in Pineview, n is a ring counter */
501 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
503 clock->m = clock->m2 + 2;
504 clock->p = clock->p1 * clock->p2;
505 if (WARN_ON(clock->n == 0 || clock->p == 0))
507 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
508 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
513 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
515 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
518 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
520 clock->m = i9xx_dpll_compute_m(clock);
521 clock->p = clock->p1 * clock->p2;
522 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
524 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
525 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
530 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
532 clock->m = clock->m1 * clock->m2;
533 clock->p = clock->p1 * clock->p2;
534 if (WARN_ON(clock->n == 0 || clock->p == 0))
536 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
537 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
539 return clock->dot / 5;
542 int chv_calc_dpll_params(int refclk, struct dpll *clock)
544 clock->m = clock->m1 * clock->m2;
545 clock->p = clock->p1 * clock->p2;
546 if (WARN_ON(clock->n == 0 || clock->p == 0))
548 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
550 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
552 return clock->dot / 5;
555 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
558 * Returns whether the given set of divisors are valid for a given refclk with
559 * the given connectors.
561 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
562 const struct intel_limit *limit,
563 const struct dpll *clock)
565 if (clock->n < limit->n.min || limit->n.max < clock->n)
566 INTELPllInvalid("n out of range\n");
567 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
568 INTELPllInvalid("p1 out of range\n");
569 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
570 INTELPllInvalid("m2 out of range\n");
571 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
572 INTELPllInvalid("m1 out of range\n");
574 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
575 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
576 if (clock->m1 <= clock->m2)
577 INTELPllInvalid("m1 <= m2\n");
579 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
580 !IS_GEN9_LP(dev_priv)) {
581 if (clock->p < limit->p.min || limit->p.max < clock->p)
582 INTELPllInvalid("p out of range\n");
583 if (clock->m < limit->m.min || limit->m.max < clock->m)
584 INTELPllInvalid("m out of range\n");
587 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
588 INTELPllInvalid("vco out of range\n");
589 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
590 * connector, etc., rather than just a single range.
592 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
593 INTELPllInvalid("dot out of range\n");
599 i9xx_select_p2_div(const struct intel_limit *limit,
600 const struct intel_crtc_state *crtc_state,
603 struct drm_device *dev = crtc_state->base.crtc->dev;
605 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
607 * For LVDS just rely on its current settings for dual-channel.
608 * We haven't figured out how to reliably set up different
609 * single/dual channel state, if we even can.
611 if (intel_is_dual_link_lvds(dev))
612 return limit->p2.p2_fast;
614 return limit->p2.p2_slow;
616 if (target < limit->p2.dot_limit)
617 return limit->p2.p2_slow;
619 return limit->p2.p2_fast;
624 * Returns a set of divisors for the desired target clock with the given
625 * refclk, or FALSE. The returned values represent the clock equation:
626 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
628 * Target and reference clocks are specified in kHz.
630 * If match_clock is provided, then best_clock P divider must match the P
631 * divider from @match_clock used for LVDS downclocking.
634 i9xx_find_best_dpll(const struct intel_limit *limit,
635 struct intel_crtc_state *crtc_state,
636 int target, int refclk, struct dpll *match_clock,
637 struct dpll *best_clock)
639 struct drm_device *dev = crtc_state->base.crtc->dev;
643 memset(best_clock, 0, sizeof(*best_clock));
645 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
647 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
649 for (clock.m2 = limit->m2.min;
650 clock.m2 <= limit->m2.max; clock.m2++) {
651 if (clock.m2 >= clock.m1)
653 for (clock.n = limit->n.min;
654 clock.n <= limit->n.max; clock.n++) {
655 for (clock.p1 = limit->p1.min;
656 clock.p1 <= limit->p1.max; clock.p1++) {
659 i9xx_calc_dpll_params(refclk, &clock);
660 if (!intel_PLL_is_valid(to_i915(dev),
665 clock.p != match_clock->p)
668 this_err = abs(clock.dot - target);
669 if (this_err < err) {
678 return (err != target);
682 * Returns a set of divisors for the desired target clock with the given
683 * refclk, or FALSE. The returned values represent the clock equation:
684 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
686 * Target and reference clocks are specified in kHz.
688 * If match_clock is provided, then best_clock P divider must match the P
689 * divider from @match_clock used for LVDS downclocking.
692 pnv_find_best_dpll(const struct intel_limit *limit,
693 struct intel_crtc_state *crtc_state,
694 int target, int refclk, struct dpll *match_clock,
695 struct dpll *best_clock)
697 struct drm_device *dev = crtc_state->base.crtc->dev;
701 memset(best_clock, 0, sizeof(*best_clock));
703 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
705 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
707 for (clock.m2 = limit->m2.min;
708 clock.m2 <= limit->m2.max; clock.m2++) {
709 for (clock.n = limit->n.min;
710 clock.n <= limit->n.max; clock.n++) {
711 for (clock.p1 = limit->p1.min;
712 clock.p1 <= limit->p1.max; clock.p1++) {
715 pnv_calc_dpll_params(refclk, &clock);
716 if (!intel_PLL_is_valid(to_i915(dev),
721 clock.p != match_clock->p)
724 this_err = abs(clock.dot - target);
725 if (this_err < err) {
734 return (err != target);
738 * Returns a set of divisors for the desired target clock with the given
739 * refclk, or FALSE. The returned values represent the clock equation:
740 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
742 * Target and reference clocks are specified in kHz.
744 * If match_clock is provided, then best_clock P divider must match the P
745 * divider from @match_clock used for LVDS downclocking.
748 g4x_find_best_dpll(const struct intel_limit *limit,
749 struct intel_crtc_state *crtc_state,
750 int target, int refclk, struct dpll *match_clock,
751 struct dpll *best_clock)
753 struct drm_device *dev = crtc_state->base.crtc->dev;
757 /* approximately equals target * 0.00585 */
758 int err_most = (target >> 8) + (target >> 9);
760 memset(best_clock, 0, sizeof(*best_clock));
762 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
764 max_n = limit->n.max;
765 /* based on hardware requirement, prefer smaller n to precision */
766 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
767 /* based on hardware requirement, prefere larger m1,m2 */
768 for (clock.m1 = limit->m1.max;
769 clock.m1 >= limit->m1.min; clock.m1--) {
770 for (clock.m2 = limit->m2.max;
771 clock.m2 >= limit->m2.min; clock.m2--) {
772 for (clock.p1 = limit->p1.max;
773 clock.p1 >= limit->p1.min; clock.p1--) {
776 i9xx_calc_dpll_params(refclk, &clock);
777 if (!intel_PLL_is_valid(to_i915(dev),
782 this_err = abs(clock.dot - target);
783 if (this_err < err_most) {
797 * Check if the calculated PLL configuration is more optimal compared to the
798 * best configuration and error found so far. Return the calculated error.
800 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
801 const struct dpll *calculated_clock,
802 const struct dpll *best_clock,
803 unsigned int best_error_ppm,
804 unsigned int *error_ppm)
807 * For CHV ignore the error and consider only the P value.
808 * Prefer a bigger P value based on HW requirements.
810 if (IS_CHERRYVIEW(to_i915(dev))) {
813 return calculated_clock->p > best_clock->p;
816 if (WARN_ON_ONCE(!target_freq))
819 *error_ppm = div_u64(1000000ULL *
820 abs(target_freq - calculated_clock->dot),
823 * Prefer a better P value over a better (smaller) error if the error
824 * is small. Ensure this preference for future configurations too by
825 * setting the error to 0.
827 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
833 return *error_ppm + 10 < best_error_ppm;
837 * Returns a set of divisors for the desired target clock with the given
838 * refclk, or FALSE. The returned values represent the clock equation:
839 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
842 vlv_find_best_dpll(const struct intel_limit *limit,
843 struct intel_crtc_state *crtc_state,
844 int target, int refclk, struct dpll *match_clock,
845 struct dpll *best_clock)
847 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
848 struct drm_device *dev = crtc->base.dev;
850 unsigned int bestppm = 1000000;
851 /* min update 19.2 MHz */
852 int max_n = min(limit->n.max, refclk / 19200);
855 target *= 5; /* fast clock */
857 memset(best_clock, 0, sizeof(*best_clock));
859 /* based on hardware requirement, prefer smaller n to precision */
860 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
861 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
862 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
863 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
864 clock.p = clock.p1 * clock.p2;
865 /* based on hardware requirement, prefer bigger m1,m2 values */
866 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
869 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
872 vlv_calc_dpll_params(refclk, &clock);
874 if (!intel_PLL_is_valid(to_i915(dev),
879 if (!vlv_PLL_is_optimal(dev, target,
897 * Returns a set of divisors for the desired target clock with the given
898 * refclk, or FALSE. The returned values represent the clock equation:
899 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
902 chv_find_best_dpll(const struct intel_limit *limit,
903 struct intel_crtc_state *crtc_state,
904 int target, int refclk, struct dpll *match_clock,
905 struct dpll *best_clock)
907 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
908 struct drm_device *dev = crtc->base.dev;
909 unsigned int best_error_ppm;
914 memset(best_clock, 0, sizeof(*best_clock));
915 best_error_ppm = 1000000;
918 * Based on hardware doc, the n always set to 1, and m1 always
919 * set to 2. If requires to support 200Mhz refclk, we need to
920 * revisit this because n may not 1 anymore.
922 clock.n = 1, clock.m1 = 2;
923 target *= 5; /* fast clock */
925 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
926 for (clock.p2 = limit->p2.p2_fast;
927 clock.p2 >= limit->p2.p2_slow;
928 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
929 unsigned int error_ppm;
931 clock.p = clock.p1 * clock.p2;
933 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
934 clock.n) << 22, refclk * clock.m1);
936 if (m2 > INT_MAX/clock.m1)
941 chv_calc_dpll_params(refclk, &clock);
943 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
946 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
947 best_error_ppm, &error_ppm))
951 best_error_ppm = error_ppm;
959 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
960 struct dpll *best_clock)
963 const struct intel_limit *limit = &intel_limits_bxt;
965 return chv_find_best_dpll(limit, crtc_state,
966 target_clock, refclk, NULL, best_clock);
969 bool intel_crtc_active(struct intel_crtc *crtc)
971 /* Be paranoid as we can arrive here with only partial
972 * state retrieved from the hardware during setup.
974 * We can ditch the adjusted_mode.crtc_clock check as soon
975 * as Haswell has gained clock readout/fastboot support.
977 * We can ditch the crtc->primary->state->fb check as soon as we can
978 * properly reconstruct framebuffers.
980 * FIXME: The intel_crtc->active here should be switched to
981 * crtc->state->active once we have proper CRTC states wired up
984 return crtc->active && crtc->base.primary->state->fb &&
985 crtc->config->base.adjusted_mode.crtc_clock;
988 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
991 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
993 return crtc->config->cpu_transcoder;
996 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
999 i915_reg_t reg = PIPEDSL(pipe);
1003 if (IS_GEN2(dev_priv))
1004 line_mask = DSL_LINEMASK_GEN2;
1006 line_mask = DSL_LINEMASK_GEN3;
1008 line1 = I915_READ(reg) & line_mask;
1010 line2 = I915_READ(reg) & line_mask;
1012 return line1 != line2;
1015 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1017 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1018 enum pipe pipe = crtc->pipe;
1020 /* Wait for the display line to settle/start moving */
1021 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1022 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1023 pipe_name(pipe), onoff(state));
1026 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1028 wait_for_pipe_scanline_moving(crtc, false);
1031 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1033 wait_for_pipe_scanline_moving(crtc, true);
1037 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1039 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1040 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1042 if (INTEL_GEN(dev_priv) >= 4) {
1043 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1044 i915_reg_t reg = PIPECONF(cpu_transcoder);
1046 /* Wait for the Pipe State to go off */
1047 if (intel_wait_for_register(dev_priv,
1048 reg, I965_PIPECONF_ACTIVE, 0,
1050 WARN(1, "pipe_off wait timed out\n");
1052 intel_wait_for_pipe_scanline_stopped(crtc);
1056 /* Only for pre-ILK configs */
1057 void assert_pll(struct drm_i915_private *dev_priv,
1058 enum pipe pipe, bool state)
1063 val = I915_READ(DPLL(pipe));
1064 cur_state = !!(val & DPLL_VCO_ENABLE);
1065 I915_STATE_WARN(cur_state != state,
1066 "PLL state assertion failure (expected %s, current %s)\n",
1067 onoff(state), onoff(cur_state));
1070 /* XXX: the dsi pll is shared between MIPI DSI ports */
1071 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1076 mutex_lock(&dev_priv->sb_lock);
1077 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1078 mutex_unlock(&dev_priv->sb_lock);
1080 cur_state = val & DSI_PLL_VCO_EN;
1081 I915_STATE_WARN(cur_state != state,
1082 "DSI PLL state assertion failure (expected %s, current %s)\n",
1083 onoff(state), onoff(cur_state));
1086 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1087 enum pipe pipe, bool state)
1090 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1093 if (HAS_DDI(dev_priv)) {
1094 /* DDI does not have a specific FDI_TX register */
1095 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1096 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1098 u32 val = I915_READ(FDI_TX_CTL(pipe));
1099 cur_state = !!(val & FDI_TX_ENABLE);
1101 I915_STATE_WARN(cur_state != state,
1102 "FDI TX state assertion failure (expected %s, current %s)\n",
1103 onoff(state), onoff(cur_state));
1105 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1106 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1108 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1109 enum pipe pipe, bool state)
1114 val = I915_READ(FDI_RX_CTL(pipe));
1115 cur_state = !!(val & FDI_RX_ENABLE);
1116 I915_STATE_WARN(cur_state != state,
1117 "FDI RX state assertion failure (expected %s, current %s)\n",
1118 onoff(state), onoff(cur_state));
1120 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1121 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1123 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1128 /* ILK FDI PLL is always enabled */
1129 if (IS_GEN5(dev_priv))
1132 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1133 if (HAS_DDI(dev_priv))
1136 val = I915_READ(FDI_TX_CTL(pipe));
1137 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1140 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1141 enum pipe pipe, bool state)
1146 val = I915_READ(FDI_RX_CTL(pipe));
1147 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1148 I915_STATE_WARN(cur_state != state,
1149 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1150 onoff(state), onoff(cur_state));
1153 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1157 enum pipe panel_pipe = INVALID_PIPE;
1160 if (WARN_ON(HAS_DDI(dev_priv)))
1163 if (HAS_PCH_SPLIT(dev_priv)) {
1166 pp_reg = PP_CONTROL(0);
1167 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1170 case PANEL_PORT_SELECT_LVDS:
1171 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1173 case PANEL_PORT_SELECT_DPA:
1174 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1176 case PANEL_PORT_SELECT_DPC:
1177 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1179 case PANEL_PORT_SELECT_DPD:
1180 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1183 MISSING_CASE(port_sel);
1186 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1187 /* presumably write lock depends on pipe, not port select */
1188 pp_reg = PP_CONTROL(pipe);
1193 pp_reg = PP_CONTROL(0);
1194 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1196 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1197 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1200 val = I915_READ(pp_reg);
1201 if (!(val & PANEL_POWER_ON) ||
1202 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1205 I915_STATE_WARN(panel_pipe == pipe && locked,
1206 "panel assertion failure, pipe %c regs locked\n",
1210 void assert_pipe(struct drm_i915_private *dev_priv,
1211 enum pipe pipe, bool state)
1214 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1216 enum intel_display_power_domain power_domain;
1218 /* we keep both pipes enabled on 830 */
1219 if (IS_I830(dev_priv))
1222 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1223 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
1224 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1225 cur_state = !!(val & PIPECONF_ENABLE);
1227 intel_display_power_put(dev_priv, power_domain);
1232 I915_STATE_WARN(cur_state != state,
1233 "pipe %c assertion failure (expected %s, current %s)\n",
1234 pipe_name(pipe), onoff(state), onoff(cur_state));
1237 static void assert_plane(struct intel_plane *plane, bool state)
1242 cur_state = plane->get_hw_state(plane, &pipe);
1244 I915_STATE_WARN(cur_state != state,
1245 "%s assertion failure (expected %s, current %s)\n",
1246 plane->base.name, onoff(state), onoff(cur_state));
1249 #define assert_plane_enabled(p) assert_plane(p, true)
1250 #define assert_plane_disabled(p) assert_plane(p, false)
1252 static void assert_planes_disabled(struct intel_crtc *crtc)
1254 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1255 struct intel_plane *plane;
1257 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1258 assert_plane_disabled(plane);
1261 static void assert_vblank_disabled(struct drm_crtc *crtc)
1263 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1264 drm_crtc_vblank_put(crtc);
1267 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1273 val = I915_READ(PCH_TRANSCONF(pipe));
1274 enabled = !!(val & TRANS_ENABLE);
1275 I915_STATE_WARN(enabled,
1276 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1280 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1281 enum pipe pipe, enum port port,
1284 enum pipe port_pipe;
1287 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1289 I915_STATE_WARN(state && port_pipe == pipe,
1290 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1291 port_name(port), pipe_name(pipe));
1293 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1294 "IBX PCH DP %c still using transcoder B\n",
1298 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1299 enum pipe pipe, enum port port,
1300 i915_reg_t hdmi_reg)
1302 enum pipe port_pipe;
1305 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1307 I915_STATE_WARN(state && port_pipe == pipe,
1308 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1309 port_name(port), pipe_name(pipe));
1311 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1312 "IBX PCH HDMI %c still using transcoder B\n",
1316 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1319 enum pipe port_pipe;
1321 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1322 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1323 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1325 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1327 "PCH VGA enabled on transcoder %c, should be disabled\n",
1330 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1332 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1335 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1336 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1337 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1340 static void _vlv_enable_pll(struct intel_crtc *crtc,
1341 const struct intel_crtc_state *pipe_config)
1343 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1344 enum pipe pipe = crtc->pipe;
1346 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1347 POSTING_READ(DPLL(pipe));
1350 if (intel_wait_for_register(dev_priv,
1355 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1358 static void vlv_enable_pll(struct intel_crtc *crtc,
1359 const struct intel_crtc_state *pipe_config)
1361 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1362 enum pipe pipe = crtc->pipe;
1364 assert_pipe_disabled(dev_priv, pipe);
1366 /* PLL is protected by panel, make sure we can write it */
1367 assert_panel_unlocked(dev_priv, pipe);
1369 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1370 _vlv_enable_pll(crtc, pipe_config);
1372 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1373 POSTING_READ(DPLL_MD(pipe));
1377 static void _chv_enable_pll(struct intel_crtc *crtc,
1378 const struct intel_crtc_state *pipe_config)
1380 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1381 enum pipe pipe = crtc->pipe;
1382 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1385 mutex_lock(&dev_priv->sb_lock);
1387 /* Enable back the 10bit clock to display controller */
1388 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1389 tmp |= DPIO_DCLKP_EN;
1390 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1392 mutex_unlock(&dev_priv->sb_lock);
1395 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1400 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1402 /* Check PLL is locked */
1403 if (intel_wait_for_register(dev_priv,
1404 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1406 DRM_ERROR("PLL %d failed to lock\n", pipe);
1409 static void chv_enable_pll(struct intel_crtc *crtc,
1410 const struct intel_crtc_state *pipe_config)
1412 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1413 enum pipe pipe = crtc->pipe;
1415 assert_pipe_disabled(dev_priv, pipe);
1417 /* PLL is protected by panel, make sure we can write it */
1418 assert_panel_unlocked(dev_priv, pipe);
1420 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1421 _chv_enable_pll(crtc, pipe_config);
1423 if (pipe != PIPE_A) {
1425 * WaPixelRepeatModeFixForC0:chv
1427 * DPLLCMD is AWOL. Use chicken bits to propagate
1428 * the value from DPLLBMD to either pipe B or C.
1430 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1431 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1432 I915_WRITE(CBR4_VLV, 0);
1433 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1436 * DPLLB VGA mode also seems to cause problems.
1437 * We should always have it disabled.
1439 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1441 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1442 POSTING_READ(DPLL_MD(pipe));
1446 static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
1448 struct intel_crtc *crtc;
1451 for_each_intel_crtc(&dev_priv->drm, crtc) {
1452 count += crtc->base.state->active &&
1453 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1459 static void i9xx_enable_pll(struct intel_crtc *crtc,
1460 const struct intel_crtc_state *crtc_state)
1462 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1463 i915_reg_t reg = DPLL(crtc->pipe);
1464 u32 dpll = crtc_state->dpll_hw_state.dpll;
1467 assert_pipe_disabled(dev_priv, crtc->pipe);
1469 /* PLL is protected by panel, make sure we can write it */
1470 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
1471 assert_panel_unlocked(dev_priv, crtc->pipe);
1473 /* Enable DVO 2x clock on both PLLs if necessary */
1474 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
1476 * It appears to be important that we don't enable this
1477 * for the current pipe before otherwise configuring the
1478 * PLL. No idea how this should be handled if multiple
1479 * DVO outputs are enabled simultaneosly.
1481 dpll |= DPLL_DVO_2X_MODE;
1482 I915_WRITE(DPLL(!crtc->pipe),
1483 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1487 * Apparently we need to have VGA mode enabled prior to changing
1488 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1489 * dividers, even though the register value does change.
1493 I915_WRITE(reg, dpll);
1495 /* Wait for the clocks to stabilize. */
1499 if (INTEL_GEN(dev_priv) >= 4) {
1500 I915_WRITE(DPLL_MD(crtc->pipe),
1501 crtc_state->dpll_hw_state.dpll_md);
1503 /* The pixel multiplier can only be updated once the
1504 * DPLL is enabled and the clocks are stable.
1506 * So write it again.
1508 I915_WRITE(reg, dpll);
1511 /* We do this three times for luck */
1512 for (i = 0; i < 3; i++) {
1513 I915_WRITE(reg, dpll);
1515 udelay(150); /* wait for warmup */
1519 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1521 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1522 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1523 enum pipe pipe = crtc->pipe;
1525 /* Disable DVO 2x clock on both PLLs if necessary */
1526 if (IS_I830(dev_priv) &&
1527 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
1528 !intel_num_dvo_pipes(dev_priv)) {
1529 I915_WRITE(DPLL(PIPE_B),
1530 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1531 I915_WRITE(DPLL(PIPE_A),
1532 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1535 /* Don't disable pipe or pipe PLLs if needed */
1536 if (IS_I830(dev_priv))
1539 /* Make sure the pipe isn't still relying on us */
1540 assert_pipe_disabled(dev_priv, pipe);
1542 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1543 POSTING_READ(DPLL(pipe));
1546 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1550 /* Make sure the pipe isn't still relying on us */
1551 assert_pipe_disabled(dev_priv, pipe);
1553 val = DPLL_INTEGRATED_REF_CLK_VLV |
1554 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1556 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1558 I915_WRITE(DPLL(pipe), val);
1559 POSTING_READ(DPLL(pipe));
1562 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1564 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1567 /* Make sure the pipe isn't still relying on us */
1568 assert_pipe_disabled(dev_priv, pipe);
1570 val = DPLL_SSC_REF_CLK_CHV |
1571 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1573 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1575 I915_WRITE(DPLL(pipe), val);
1576 POSTING_READ(DPLL(pipe));
1578 mutex_lock(&dev_priv->sb_lock);
1580 /* Disable 10bit clock to display controller */
1581 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1582 val &= ~DPIO_DCLKP_EN;
1583 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1585 mutex_unlock(&dev_priv->sb_lock);
1588 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1589 struct intel_digital_port *dport,
1590 unsigned int expected_mask)
1593 i915_reg_t dpll_reg;
1595 switch (dport->base.port) {
1597 port_mask = DPLL_PORTB_READY_MASK;
1601 port_mask = DPLL_PORTC_READY_MASK;
1603 expected_mask <<= 4;
1606 port_mask = DPLL_PORTD_READY_MASK;
1607 dpll_reg = DPIO_PHY_STATUS;
1613 if (intel_wait_for_register(dev_priv,
1614 dpll_reg, port_mask, expected_mask,
1616 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1617 port_name(dport->base.port),
1618 I915_READ(dpll_reg) & port_mask, expected_mask);
1621 static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1623 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1624 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1625 enum pipe pipe = crtc->pipe;
1627 uint32_t val, pipeconf_val;
1629 /* Make sure PCH DPLL is enabled */
1630 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1632 /* FDI must be feeding us bits for PCH ports */
1633 assert_fdi_tx_enabled(dev_priv, pipe);
1634 assert_fdi_rx_enabled(dev_priv, pipe);
1636 if (HAS_PCH_CPT(dev_priv)) {
1637 /* Workaround: Set the timing override bit before enabling the
1638 * pch transcoder. */
1639 reg = TRANS_CHICKEN2(pipe);
1640 val = I915_READ(reg);
1641 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1642 I915_WRITE(reg, val);
1645 reg = PCH_TRANSCONF(pipe);
1646 val = I915_READ(reg);
1647 pipeconf_val = I915_READ(PIPECONF(pipe));
1649 if (HAS_PCH_IBX(dev_priv)) {
1651 * Make the BPC in transcoder be consistent with
1652 * that in pipeconf reg. For HDMI we must use 8bpc
1653 * here for both 8bpc and 12bpc.
1655 val &= ~PIPECONF_BPC_MASK;
1656 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1657 val |= PIPECONF_8BPC;
1659 val |= pipeconf_val & PIPECONF_BPC_MASK;
1662 val &= ~TRANS_INTERLACE_MASK;
1663 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1664 if (HAS_PCH_IBX(dev_priv) &&
1665 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1666 val |= TRANS_LEGACY_INTERLACED_ILK;
1668 val |= TRANS_INTERLACED;
1670 val |= TRANS_PROGRESSIVE;
1672 I915_WRITE(reg, val | TRANS_ENABLE);
1673 if (intel_wait_for_register(dev_priv,
1674 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1676 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1679 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1680 enum transcoder cpu_transcoder)
1682 u32 val, pipeconf_val;
1684 /* FDI must be feeding us bits for PCH ports */
1685 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1686 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1688 /* Workaround: set timing override bit. */
1689 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1690 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1691 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1694 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1696 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1697 PIPECONF_INTERLACED_ILK)
1698 val |= TRANS_INTERLACED;
1700 val |= TRANS_PROGRESSIVE;
1702 I915_WRITE(LPT_TRANSCONF, val);
1703 if (intel_wait_for_register(dev_priv,
1708 DRM_ERROR("Failed to enable PCH transcoder\n");
1711 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1717 /* FDI relies on the transcoder */
1718 assert_fdi_tx_disabled(dev_priv, pipe);
1719 assert_fdi_rx_disabled(dev_priv, pipe);
1721 /* Ports must be off as well */
1722 assert_pch_ports_disabled(dev_priv, pipe);
1724 reg = PCH_TRANSCONF(pipe);
1725 val = I915_READ(reg);
1726 val &= ~TRANS_ENABLE;
1727 I915_WRITE(reg, val);
1728 /* wait for PCH transcoder off, transcoder state */
1729 if (intel_wait_for_register(dev_priv,
1730 reg, TRANS_STATE_ENABLE, 0,
1732 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1734 if (HAS_PCH_CPT(dev_priv)) {
1735 /* Workaround: Clear the timing override chicken bit again. */
1736 reg = TRANS_CHICKEN2(pipe);
1737 val = I915_READ(reg);
1738 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1739 I915_WRITE(reg, val);
1743 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1747 val = I915_READ(LPT_TRANSCONF);
1748 val &= ~TRANS_ENABLE;
1749 I915_WRITE(LPT_TRANSCONF, val);
1750 /* wait for PCH transcoder off, transcoder state */
1751 if (intel_wait_for_register(dev_priv,
1752 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1754 DRM_ERROR("Failed to disable PCH transcoder\n");
1756 /* Workaround: clear timing override bit. */
1757 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1758 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1759 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1762 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1764 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1766 if (HAS_PCH_LPT(dev_priv))
1772 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1774 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1775 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1776 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1777 enum pipe pipe = crtc->pipe;
1781 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1783 assert_planes_disabled(crtc);
1786 * A pipe without a PLL won't actually be able to drive bits from
1787 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1790 if (HAS_GMCH_DISPLAY(dev_priv)) {
1791 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1792 assert_dsi_pll_enabled(dev_priv);
1794 assert_pll_enabled(dev_priv, pipe);
1796 if (new_crtc_state->has_pch_encoder) {
1797 /* if driving the PCH, we need FDI enabled */
1798 assert_fdi_rx_pll_enabled(dev_priv,
1799 intel_crtc_pch_transcoder(crtc));
1800 assert_fdi_tx_pll_enabled(dev_priv,
1801 (enum pipe) cpu_transcoder);
1803 /* FIXME: assert CPU port conditions for SNB+ */
1806 reg = PIPECONF(cpu_transcoder);
1807 val = I915_READ(reg);
1808 if (val & PIPECONF_ENABLE) {
1809 /* we keep both pipes enabled on 830 */
1810 WARN_ON(!IS_I830(dev_priv));
1814 I915_WRITE(reg, val | PIPECONF_ENABLE);
1818 * Until the pipe starts PIPEDSL reads will return a stale value,
1819 * which causes an apparent vblank timestamp jump when PIPEDSL
1820 * resets to its proper value. That also messes up the frame count
1821 * when it's derived from the timestamps. So let's wait for the
1822 * pipe to start properly before we call drm_crtc_vblank_on()
1824 if (dev_priv->drm.max_vblank_count == 0)
1825 intel_wait_for_pipe_scanline_moving(crtc);
1828 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1830 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1831 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1832 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1833 enum pipe pipe = crtc->pipe;
1837 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1840 * Make sure planes won't keep trying to pump pixels to us,
1841 * or we might hang the display.
1843 assert_planes_disabled(crtc);
1845 reg = PIPECONF(cpu_transcoder);
1846 val = I915_READ(reg);
1847 if ((val & PIPECONF_ENABLE) == 0)
1851 * Double wide has implications for planes
1852 * so best keep it disabled when not needed.
1854 if (old_crtc_state->double_wide)
1855 val &= ~PIPECONF_DOUBLE_WIDE;
1857 /* Don't disable pipe or pipe PLLs if needed */
1858 if (!IS_I830(dev_priv))
1859 val &= ~PIPECONF_ENABLE;
1861 I915_WRITE(reg, val);
1862 if ((val & PIPECONF_ENABLE) == 0)
1863 intel_wait_for_pipe_off(old_crtc_state);
1866 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1868 return IS_GEN2(dev_priv) ? 2048 : 4096;
1872 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1874 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1875 unsigned int cpp = fb->format->cpp[color_plane];
1877 switch (fb->modifier) {
1878 case DRM_FORMAT_MOD_LINEAR:
1880 case I915_FORMAT_MOD_X_TILED:
1881 if (IS_GEN2(dev_priv))
1885 case I915_FORMAT_MOD_Y_TILED_CCS:
1886 if (color_plane == 1)
1889 case I915_FORMAT_MOD_Y_TILED:
1890 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1894 case I915_FORMAT_MOD_Yf_TILED_CCS:
1895 if (color_plane == 1)
1898 case I915_FORMAT_MOD_Yf_TILED:
1914 MISSING_CASE(fb->modifier);
1920 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
1922 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
1925 return intel_tile_size(to_i915(fb->dev)) /
1926 intel_tile_width_bytes(fb, color_plane);
1929 /* Return the tile dimensions in pixel units */
1930 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
1931 unsigned int *tile_width,
1932 unsigned int *tile_height)
1934 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1935 unsigned int cpp = fb->format->cpp[color_plane];
1937 *tile_width = tile_width_bytes / cpp;
1938 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1942 intel_fb_align_height(const struct drm_framebuffer *fb,
1943 int color_plane, unsigned int height)
1945 unsigned int tile_height = intel_tile_height(fb, color_plane);
1947 return ALIGN(height, tile_height);
1950 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1952 unsigned int size = 0;
1955 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1956 size += rot_info->plane[i].width * rot_info->plane[i].height;
1962 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1963 const struct drm_framebuffer *fb,
1964 unsigned int rotation)
1966 view->type = I915_GGTT_VIEW_NORMAL;
1967 if (drm_rotation_90_or_270(rotation)) {
1968 view->type = I915_GGTT_VIEW_ROTATED;
1969 view->rotated = to_intel_framebuffer(fb)->rot_info;
1973 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
1975 if (IS_I830(dev_priv))
1977 else if (IS_I85X(dev_priv))
1979 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
1985 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
1987 if (INTEL_GEN(dev_priv) >= 9)
1989 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
1990 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1992 else if (INTEL_GEN(dev_priv) >= 4)
1998 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2001 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2003 /* AUX_DIST needs only 4K alignment */
2004 if (color_plane == 1)
2007 switch (fb->modifier) {
2008 case DRM_FORMAT_MOD_LINEAR:
2009 return intel_linear_alignment(dev_priv);
2010 case I915_FORMAT_MOD_X_TILED:
2011 if (INTEL_GEN(dev_priv) >= 9)
2014 case I915_FORMAT_MOD_Y_TILED_CCS:
2015 case I915_FORMAT_MOD_Yf_TILED_CCS:
2016 case I915_FORMAT_MOD_Y_TILED:
2017 case I915_FORMAT_MOD_Yf_TILED:
2018 return 1 * 1024 * 1024;
2020 MISSING_CASE(fb->modifier);
2025 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2027 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2028 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2030 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
2034 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2035 const struct i915_ggtt_view *view,
2037 unsigned long *out_flags)
2039 struct drm_device *dev = fb->dev;
2040 struct drm_i915_private *dev_priv = to_i915(dev);
2041 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2042 struct i915_vma *vma;
2043 unsigned int pinctl;
2046 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2048 alignment = intel_surf_alignment(fb, 0);
2050 /* Note that the w/a also requires 64 PTE of padding following the
2051 * bo. We currently fill all unused PTE with the shadow page and so
2052 * we should always have valid PTE following the scanout preventing
2055 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2056 alignment = 256 * 1024;
2059 * Global gtt pte registers are special registers which actually forward
2060 * writes to a chunk of system memory. Which means that there is no risk
2061 * that the register values disappear as soon as we call
2062 * intel_runtime_pm_put(), so it is correct to wrap only the
2063 * pin/unpin/fence and not more.
2065 intel_runtime_pm_get(dev_priv);
2067 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2071 /* Valleyview is definitely limited to scanning out the first
2072 * 512MiB. Lets presume this behaviour was inherited from the
2073 * g4x display engine and that all earlier gen are similarly
2074 * limited. Testing suggests that it is a little more
2075 * complicated than this. For example, Cherryview appears quite
2076 * happy to scanout from anywhere within its global aperture.
2078 if (HAS_GMCH_DISPLAY(dev_priv))
2079 pinctl |= PIN_MAPPABLE;
2081 vma = i915_gem_object_pin_to_display_plane(obj,
2082 alignment, view, pinctl);
2086 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2089 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2090 * fence, whereas 965+ only requires a fence if using
2091 * framebuffer compression. For simplicity, we always, when
2092 * possible, install a fence as the cost is not that onerous.
2094 * If we fail to fence the tiled scanout, then either the
2095 * modeset will reject the change (which is highly unlikely as
2096 * the affected systems, all but one, do not have unmappable
2097 * space) or we will not be able to enable full powersaving
2098 * techniques (also likely not to apply due to various limits
2099 * FBC and the like impose on the size of the buffer, which
2100 * presumably we violated anyway with this unmappable buffer).
2101 * Anyway, it is presumably better to stumble onwards with
2102 * something and try to run the system in a "less than optimal"
2103 * mode that matches the user configuration.
2105 ret = i915_vma_pin_fence(vma);
2106 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2107 i915_gem_object_unpin_from_display_plane(vma);
2112 if (ret == 0 && vma->fence)
2113 *out_flags |= PLANE_HAS_FENCE;
2118 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2120 intel_runtime_pm_put(dev_priv);
2124 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2126 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2128 if (flags & PLANE_HAS_FENCE)
2129 i915_vma_unpin_fence(vma);
2130 i915_gem_object_unpin_from_display_plane(vma);
2134 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2135 unsigned int rotation)
2137 if (drm_rotation_90_or_270(rotation))
2138 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2140 return fb->pitches[color_plane];
2144 * Convert the x/y offsets into a linear offset.
2145 * Only valid with 0/180 degree rotation, which is fine since linear
2146 * offset is only used with linear buffers on pre-hsw and tiled buffers
2147 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2149 u32 intel_fb_xy_to_linear(int x, int y,
2150 const struct intel_plane_state *state,
2153 const struct drm_framebuffer *fb = state->base.fb;
2154 unsigned int cpp = fb->format->cpp[color_plane];
2155 unsigned int pitch = state->color_plane[color_plane].stride;
2157 return y * pitch + x * cpp;
2161 * Add the x/y offsets derived from fb->offsets[] to the user
2162 * specified plane src x/y offsets. The resulting x/y offsets
2163 * specify the start of scanout from the beginning of the gtt mapping.
2165 void intel_add_fb_offsets(int *x, int *y,
2166 const struct intel_plane_state *state,
2170 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2171 unsigned int rotation = state->base.rotation;
2173 if (drm_rotation_90_or_270(rotation)) {
2174 *x += intel_fb->rotated[color_plane].x;
2175 *y += intel_fb->rotated[color_plane].y;
2177 *x += intel_fb->normal[color_plane].x;
2178 *y += intel_fb->normal[color_plane].y;
2182 static u32 intel_adjust_tile_offset(int *x, int *y,
2183 unsigned int tile_width,
2184 unsigned int tile_height,
2185 unsigned int tile_size,
2186 unsigned int pitch_tiles,
2190 unsigned int pitch_pixels = pitch_tiles * tile_width;
2193 WARN_ON(old_offset & (tile_size - 1));
2194 WARN_ON(new_offset & (tile_size - 1));
2195 WARN_ON(new_offset > old_offset);
2197 tiles = (old_offset - new_offset) / tile_size;
2199 *y += tiles / pitch_tiles * tile_height;
2200 *x += tiles % pitch_tiles * tile_width;
2202 /* minimize x in case it got needlessly big */
2203 *y += *x / pitch_pixels * tile_height;
2209 static u32 intel_adjust_aligned_offset(int *x, int *y,
2210 const struct drm_framebuffer *fb,
2212 unsigned int rotation,
2214 u32 old_offset, u32 new_offset)
2216 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2217 unsigned int cpp = fb->format->cpp[color_plane];
2219 WARN_ON(new_offset > old_offset);
2221 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2222 unsigned int tile_size, tile_width, tile_height;
2223 unsigned int pitch_tiles;
2225 tile_size = intel_tile_size(dev_priv);
2226 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2228 if (drm_rotation_90_or_270(rotation)) {
2229 pitch_tiles = pitch / tile_height;
2230 swap(tile_width, tile_height);
2232 pitch_tiles = pitch / (tile_width * cpp);
2235 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2236 tile_size, pitch_tiles,
2237 old_offset, new_offset);
2239 old_offset += *y * pitch + *x * cpp;
2241 *y = (old_offset - new_offset) / pitch;
2242 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2249 * Adjust the tile offset by moving the difference into
2252 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2253 const struct intel_plane_state *state,
2255 u32 old_offset, u32 new_offset)
2257 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
2258 state->base.rotation,
2259 state->color_plane[color_plane].stride,
2260 old_offset, new_offset);
2264 * Computes the aligned offset to the base tile and adjusts
2265 * x, y. bytes per pixel is assumed to be a power-of-two.
2267 * In the 90/270 rotated case, x and y are assumed
2268 * to be already rotated to match the rotated GTT view, and
2269 * pitch is the tile_height aligned framebuffer height.
2271 * This function is used when computing the derived information
2272 * under intel_framebuffer, so using any of that information
2273 * here is not allowed. Anything under drm_framebuffer can be
2274 * used. This is why the user has to pass in the pitch since it
2275 * is specified in the rotated orientation.
2277 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2279 const struct drm_framebuffer *fb,
2282 unsigned int rotation,
2285 uint64_t fb_modifier = fb->modifier;
2286 unsigned int cpp = fb->format->cpp[color_plane];
2287 u32 offset, offset_aligned;
2292 if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
2293 unsigned int tile_size, tile_width, tile_height;
2294 unsigned int tile_rows, tiles, pitch_tiles;
2296 tile_size = intel_tile_size(dev_priv);
2297 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2299 if (drm_rotation_90_or_270(rotation)) {
2300 pitch_tiles = pitch / tile_height;
2301 swap(tile_width, tile_height);
2303 pitch_tiles = pitch / (tile_width * cpp);
2306 tile_rows = *y / tile_height;
2309 tiles = *x / tile_width;
2312 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2313 offset_aligned = offset & ~alignment;
2315 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2316 tile_size, pitch_tiles,
2317 offset, offset_aligned);
2319 offset = *y * pitch + *x * cpp;
2320 offset_aligned = offset & ~alignment;
2322 *y = (offset & alignment) / pitch;
2323 *x = ((offset & alignment) - *y * pitch) / cpp;
2326 return offset_aligned;
2329 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2330 const struct intel_plane_state *state,
2333 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2334 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2335 const struct drm_framebuffer *fb = state->base.fb;
2336 unsigned int rotation = state->base.rotation;
2337 int pitch = state->color_plane[color_plane].stride;
2340 if (intel_plane->id == PLANE_CURSOR)
2341 alignment = intel_cursor_alignment(dev_priv);
2343 alignment = intel_surf_alignment(fb, color_plane);
2345 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2346 pitch, rotation, alignment);
2349 /* Convert the fb->offset[] into x/y offsets */
2350 static int intel_fb_offset_to_xy(int *x, int *y,
2351 const struct drm_framebuffer *fb,
2354 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2356 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2357 fb->offsets[color_plane] % intel_tile_size(dev_priv))
2363 intel_adjust_aligned_offset(x, y,
2364 fb, color_plane, DRM_MODE_ROTATE_0,
2365 fb->pitches[color_plane],
2366 fb->offsets[color_plane], 0);
2371 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2373 switch (fb_modifier) {
2374 case I915_FORMAT_MOD_X_TILED:
2375 return I915_TILING_X;
2376 case I915_FORMAT_MOD_Y_TILED:
2377 case I915_FORMAT_MOD_Y_TILED_CCS:
2378 return I915_TILING_Y;
2380 return I915_TILING_NONE;
2385 * From the Sky Lake PRM:
2386 * "The Color Control Surface (CCS) contains the compression status of
2387 * the cache-line pairs. The compression state of the cache-line pair
2388 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2389 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2390 * cache-line-pairs. CCS is always Y tiled."
2392 * Since cache line pairs refers to horizontally adjacent cache lines,
2393 * each cache line in the CCS corresponds to an area of 32x16 cache
2394 * lines on the main surface. Since each pixel is 4 bytes, this gives
2395 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2398 static const struct drm_format_info ccs_formats[] = {
2399 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2400 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2401 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2402 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2405 static const struct drm_format_info *
2406 lookup_format_info(const struct drm_format_info formats[],
2407 int num_formats, u32 format)
2411 for (i = 0; i < num_formats; i++) {
2412 if (formats[i].format == format)
2419 static const struct drm_format_info *
2420 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2422 switch (cmd->modifier[0]) {
2423 case I915_FORMAT_MOD_Y_TILED_CCS:
2424 case I915_FORMAT_MOD_Yf_TILED_CCS:
2425 return lookup_format_info(ccs_formats,
2426 ARRAY_SIZE(ccs_formats),
2433 bool is_ccs_modifier(u64 modifier)
2435 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2436 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2440 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2441 struct drm_framebuffer *fb)
2443 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2444 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2445 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2446 u32 gtt_offset_rotated = 0;
2447 unsigned int max_size = 0;
2448 int i, num_planes = fb->format->num_planes;
2449 unsigned int tile_size = intel_tile_size(dev_priv);
2451 for (i = 0; i < num_planes; i++) {
2452 unsigned int width, height;
2453 unsigned int cpp, size;
2458 cpp = fb->format->cpp[i];
2459 width = drm_framebuffer_plane_width(fb->width, fb, i);
2460 height = drm_framebuffer_plane_height(fb->height, fb, i);
2462 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2464 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2469 if (is_ccs_modifier(fb->modifier) && i == 1) {
2470 int hsub = fb->format->hsub;
2471 int vsub = fb->format->vsub;
2472 int tile_width, tile_height;
2476 intel_tile_dims(fb, i, &tile_width, &tile_height);
2478 tile_height *= vsub;
2480 ccs_x = (x * hsub) % tile_width;
2481 ccs_y = (y * vsub) % tile_height;
2482 main_x = intel_fb->normal[0].x % tile_width;
2483 main_y = intel_fb->normal[0].y % tile_height;
2486 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2487 * x/y offsets must match between CCS and the main surface.
2489 if (main_x != ccs_x || main_y != ccs_y) {
2490 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2493 intel_fb->normal[0].x,
2494 intel_fb->normal[0].y,
2501 * The fence (if used) is aligned to the start of the object
2502 * so having the framebuffer wrap around across the edge of the
2503 * fenced region doesn't really work. We have no API to configure
2504 * the fence start offset within the object (nor could we probably
2505 * on gen2/3). So it's just easier if we just require that the
2506 * fb layout agrees with the fence layout. We already check that the
2507 * fb stride matches the fence stride elsewhere.
2509 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2510 (x + width) * cpp > fb->pitches[i]) {
2511 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2517 * First pixel of the framebuffer from
2518 * the start of the normal gtt mapping.
2520 intel_fb->normal[i].x = x;
2521 intel_fb->normal[i].y = y;
2523 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2527 offset /= tile_size;
2529 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2530 unsigned int tile_width, tile_height;
2531 unsigned int pitch_tiles;
2534 intel_tile_dims(fb, i, &tile_width, &tile_height);
2536 rot_info->plane[i].offset = offset;
2537 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2538 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2539 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2541 intel_fb->rotated[i].pitch =
2542 rot_info->plane[i].height * tile_height;
2544 /* how many tiles does this plane need */
2545 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2547 * If the plane isn't horizontally tile aligned,
2548 * we need one more tile.
2553 /* rotate the x/y offsets to match the GTT view */
2559 rot_info->plane[i].width * tile_width,
2560 rot_info->plane[i].height * tile_height,
2561 DRM_MODE_ROTATE_270);
2565 /* rotate the tile dimensions to match the GTT view */
2566 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2567 swap(tile_width, tile_height);
2570 * We only keep the x/y offsets, so push all of the
2571 * gtt offset into the x/y offsets.
2573 intel_adjust_tile_offset(&x, &y,
2574 tile_width, tile_height,
2575 tile_size, pitch_tiles,
2576 gtt_offset_rotated * tile_size, 0);
2578 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2581 * First pixel of the framebuffer from
2582 * the start of the rotated gtt mapping.
2584 intel_fb->rotated[i].x = x;
2585 intel_fb->rotated[i].y = y;
2587 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2588 x * cpp, tile_size);
2591 /* how many tiles in total needed in the bo */
2592 max_size = max(max_size, offset + size);
2595 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2596 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2597 mul_u32_u32(max_size, tile_size), obj->base.size);
2604 static int i9xx_format_to_fourcc(int format)
2607 case DISPPLANE_8BPP:
2608 return DRM_FORMAT_C8;
2609 case DISPPLANE_BGRX555:
2610 return DRM_FORMAT_XRGB1555;
2611 case DISPPLANE_BGRX565:
2612 return DRM_FORMAT_RGB565;
2614 case DISPPLANE_BGRX888:
2615 return DRM_FORMAT_XRGB8888;
2616 case DISPPLANE_RGBX888:
2617 return DRM_FORMAT_XBGR8888;
2618 case DISPPLANE_BGRX101010:
2619 return DRM_FORMAT_XRGB2101010;
2620 case DISPPLANE_RGBX101010:
2621 return DRM_FORMAT_XBGR2101010;
2625 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2628 case PLANE_CTL_FORMAT_RGB_565:
2629 return DRM_FORMAT_RGB565;
2630 case PLANE_CTL_FORMAT_NV12:
2631 return DRM_FORMAT_NV12;
2633 case PLANE_CTL_FORMAT_XRGB_8888:
2636 return DRM_FORMAT_ABGR8888;
2638 return DRM_FORMAT_XBGR8888;
2641 return DRM_FORMAT_ARGB8888;
2643 return DRM_FORMAT_XRGB8888;
2645 case PLANE_CTL_FORMAT_XRGB_2101010:
2647 return DRM_FORMAT_XBGR2101010;
2649 return DRM_FORMAT_XRGB2101010;
2654 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2655 struct intel_initial_plane_config *plane_config)
2657 struct drm_device *dev = crtc->base.dev;
2658 struct drm_i915_private *dev_priv = to_i915(dev);
2659 struct drm_i915_gem_object *obj = NULL;
2660 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2661 struct drm_framebuffer *fb = &plane_config->fb->base;
2662 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2663 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2666 size_aligned -= base_aligned;
2668 if (plane_config->size == 0)
2671 /* If the FB is too big, just don't use it since fbdev is not very
2672 * important and we should probably use that space with FBC or other
2674 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2677 mutex_lock(&dev->struct_mutex);
2678 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2682 mutex_unlock(&dev->struct_mutex);
2686 if (plane_config->tiling == I915_TILING_X)
2687 obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X;
2689 mode_cmd.pixel_format = fb->format->format;
2690 mode_cmd.width = fb->width;
2691 mode_cmd.height = fb->height;
2692 mode_cmd.pitches[0] = fb->pitches[0];
2693 mode_cmd.modifier[0] = fb->modifier;
2694 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2696 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2697 DRM_DEBUG_KMS("intel fb init failed\n");
2702 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2706 i915_gem_object_put(obj);
2711 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2712 struct intel_plane_state *plane_state,
2715 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2717 plane_state->base.visible = visible;
2720 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
2722 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
2725 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2727 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2728 struct drm_plane *plane;
2731 * Active_planes aliases if multiple "primary" or cursor planes
2732 * have been used on the same (or wrong) pipe. plane_mask uses
2733 * unique ids, hence we can use that to reconstruct active_planes.
2735 crtc_state->active_planes = 0;
2737 drm_for_each_plane_mask(plane, &dev_priv->drm,
2738 crtc_state->base.plane_mask)
2739 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2742 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2743 struct intel_plane *plane)
2745 struct intel_crtc_state *crtc_state =
2746 to_intel_crtc_state(crtc->base.state);
2747 struct intel_plane_state *plane_state =
2748 to_intel_plane_state(plane->base.state);
2750 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2751 plane->base.base.id, plane->base.name,
2752 crtc->base.base.id, crtc->base.name);
2754 intel_set_plane_visible(crtc_state, plane_state, false);
2755 fixup_active_planes(crtc_state);
2757 if (plane->id == PLANE_PRIMARY)
2758 intel_pre_disable_primary_noatomic(&crtc->base);
2760 trace_intel_disable_plane(&plane->base, crtc);
2761 plane->disable_plane(plane, crtc);
2765 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2766 struct intel_initial_plane_config *plane_config)
2768 struct drm_device *dev = intel_crtc->base.dev;
2769 struct drm_i915_private *dev_priv = to_i915(dev);
2771 struct drm_i915_gem_object *obj;
2772 struct drm_plane *primary = intel_crtc->base.primary;
2773 struct drm_plane_state *plane_state = primary->state;
2774 struct intel_plane *intel_plane = to_intel_plane(primary);
2775 struct intel_plane_state *intel_state =
2776 to_intel_plane_state(plane_state);
2777 struct drm_framebuffer *fb;
2779 if (!plane_config->fb)
2782 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2783 fb = &plane_config->fb->base;
2787 kfree(plane_config->fb);
2790 * Failed to alloc the obj, check to see if we should share
2791 * an fb with another CRTC instead
2793 for_each_crtc(dev, c) {
2794 struct intel_plane_state *state;
2796 if (c == &intel_crtc->base)
2799 if (!to_intel_crtc(c)->active)
2802 state = to_intel_plane_state(c->primary->state);
2806 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2807 fb = state->base.fb;
2808 drm_framebuffer_get(fb);
2814 * We've failed to reconstruct the BIOS FB. Current display state
2815 * indicates that the primary plane is visible, but has a NULL FB,
2816 * which will lead to problems later if we don't fix it up. The
2817 * simplest solution is to just disable the primary plane now and
2818 * pretend the BIOS never had it enabled.
2820 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2825 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2826 intel_state->base.rotation);
2827 intel_state->color_plane[0].stride =
2828 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2830 mutex_lock(&dev->struct_mutex);
2832 intel_pin_and_fence_fb_obj(fb,
2834 intel_plane_uses_fence(intel_state),
2835 &intel_state->flags);
2836 mutex_unlock(&dev->struct_mutex);
2837 if (IS_ERR(intel_state->vma)) {
2838 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2839 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2841 intel_state->vma = NULL;
2842 drm_framebuffer_put(fb);
2846 obj = intel_fb_obj(fb);
2847 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2849 plane_state->src_x = 0;
2850 plane_state->src_y = 0;
2851 plane_state->src_w = fb->width << 16;
2852 plane_state->src_h = fb->height << 16;
2854 plane_state->crtc_x = 0;
2855 plane_state->crtc_y = 0;
2856 plane_state->crtc_w = fb->width;
2857 plane_state->crtc_h = fb->height;
2859 intel_state->base.src = drm_plane_state_src(plane_state);
2860 intel_state->base.dst = drm_plane_state_dest(plane_state);
2862 if (i915_gem_object_is_tiled(obj))
2863 dev_priv->preserve_bios_swizzle = true;
2865 plane_state->fb = fb;
2866 plane_state->crtc = &intel_crtc->base;
2868 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2869 &obj->frontbuffer_bits);
2872 static int skl_max_plane_width(const struct drm_framebuffer *fb,
2874 unsigned int rotation)
2876 int cpp = fb->format->cpp[color_plane];
2878 switch (fb->modifier) {
2879 case DRM_FORMAT_MOD_LINEAR:
2880 case I915_FORMAT_MOD_X_TILED:
2893 case I915_FORMAT_MOD_Y_TILED_CCS:
2894 case I915_FORMAT_MOD_Yf_TILED_CCS:
2895 /* FIXME AUX plane? */
2896 case I915_FORMAT_MOD_Y_TILED:
2897 case I915_FORMAT_MOD_Yf_TILED:
2912 MISSING_CASE(fb->modifier);
2918 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2919 int main_x, int main_y, u32 main_offset)
2921 const struct drm_framebuffer *fb = plane_state->base.fb;
2922 int hsub = fb->format->hsub;
2923 int vsub = fb->format->vsub;
2924 int aux_x = plane_state->color_plane[1].x;
2925 int aux_y = plane_state->color_plane[1].y;
2926 u32 aux_offset = plane_state->color_plane[1].offset;
2927 u32 alignment = intel_surf_alignment(fb, 1);
2929 while (aux_offset >= main_offset && aux_y <= main_y) {
2932 if (aux_x == main_x && aux_y == main_y)
2935 if (aux_offset == 0)
2940 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
2941 aux_offset, aux_offset - alignment);
2942 aux_x = x * hsub + aux_x % hsub;
2943 aux_y = y * vsub + aux_y % vsub;
2946 if (aux_x != main_x || aux_y != main_y)
2949 plane_state->color_plane[1].offset = aux_offset;
2950 plane_state->color_plane[1].x = aux_x;
2951 plane_state->color_plane[1].y = aux_y;
2956 static int skl_check_main_surface(struct intel_plane_state *plane_state)
2958 const struct drm_framebuffer *fb = plane_state->base.fb;
2959 unsigned int rotation = plane_state->base.rotation;
2960 int x = plane_state->base.src.x1 >> 16;
2961 int y = plane_state->base.src.y1 >> 16;
2962 int w = drm_rect_width(&plane_state->base.src) >> 16;
2963 int h = drm_rect_height(&plane_state->base.src) >> 16;
2964 int max_width = skl_max_plane_width(fb, 0, rotation);
2965 int max_height = 4096;
2966 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
2968 if (w > max_width || h > max_height) {
2969 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2970 w, h, max_width, max_height);
2974 intel_add_fb_offsets(&x, &y, plane_state, 0);
2975 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
2976 alignment = intel_surf_alignment(fb, 0);
2979 * AUX surface offset is specified as the distance from the
2980 * main surface offset, and it must be non-negative. Make
2981 * sure that is what we will get.
2983 if (offset > aux_offset)
2984 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
2985 offset, aux_offset & ~(alignment - 1));
2988 * When using an X-tiled surface, the plane blows up
2989 * if the x offset + width exceed the stride.
2991 * TODO: linear and Y-tiled seem fine, Yf untested,
2993 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
2994 int cpp = fb->format->cpp[0];
2996 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
2998 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3002 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3003 offset, offset - alignment);
3008 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3009 * they match with the main surface x/y offsets.
3011 if (is_ccs_modifier(fb->modifier)) {
3012 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3016 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3017 offset, offset - alignment);
3020 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3021 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3026 plane_state->color_plane[0].offset = offset;
3027 plane_state->color_plane[0].x = x;
3028 plane_state->color_plane[0].y = y;
3034 skl_check_nv12_surface(struct intel_plane_state *plane_state)
3036 /* Display WA #1106 */
3037 if (plane_state->base.rotation !=
3038 (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90) &&
3039 plane_state->base.rotation != DRM_MODE_ROTATE_270)
3043 * src coordinates are rotated here.
3044 * We check height but report it as width
3046 if (((drm_rect_height(&plane_state->base.src) >> 16) % 4) != 0) {
3047 DRM_DEBUG_KMS("src width must be multiple "
3048 "of 4 for rotated NV12\n");
3055 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3057 const struct drm_framebuffer *fb = plane_state->base.fb;
3058 unsigned int rotation = plane_state->base.rotation;
3059 int max_width = skl_max_plane_width(fb, 1, rotation);
3060 int max_height = 4096;
3061 int x = plane_state->base.src.x1 >> 17;
3062 int y = plane_state->base.src.y1 >> 17;
3063 int w = drm_rect_width(&plane_state->base.src) >> 17;
3064 int h = drm_rect_height(&plane_state->base.src) >> 17;
3067 intel_add_fb_offsets(&x, &y, plane_state, 1);
3068 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3070 /* FIXME not quite sure how/if these apply to the chroma plane */
3071 if (w > max_width || h > max_height) {
3072 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3073 w, h, max_width, max_height);
3077 plane_state->color_plane[1].offset = offset;
3078 plane_state->color_plane[1].x = x;
3079 plane_state->color_plane[1].y = y;
3084 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3086 const struct drm_framebuffer *fb = plane_state->base.fb;
3087 int src_x = plane_state->base.src.x1 >> 16;
3088 int src_y = plane_state->base.src.y1 >> 16;
3089 int hsub = fb->format->hsub;
3090 int vsub = fb->format->vsub;
3091 int x = src_x / hsub;
3092 int y = src_y / vsub;
3095 intel_add_fb_offsets(&x, &y, plane_state, 1);
3096 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3098 plane_state->color_plane[1].offset = offset;
3099 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3100 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3105 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3107 const struct drm_framebuffer *fb = plane_state->base.fb;
3108 unsigned int rotation = plane_state->base.rotation;
3111 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3112 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3113 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3115 ret = intel_plane_check_stride(plane_state);
3119 /* HW only has 8 bits pixel precision, disable plane if invisible */
3120 if (!(plane_state->base.alpha >> 8))
3121 plane_state->base.visible = false;
3123 if (!plane_state->base.visible)
3126 /* Rotate src coordinates to match rotated GTT view */
3127 if (drm_rotation_90_or_270(rotation))
3128 drm_rect_rotate(&plane_state->base.src,
3129 fb->width << 16, fb->height << 16,
3130 DRM_MODE_ROTATE_270);
3133 * Handle the AUX surface first since
3134 * the main surface setup depends on it.
3136 if (fb->format->format == DRM_FORMAT_NV12) {
3137 ret = skl_check_nv12_surface(plane_state);
3140 ret = skl_check_nv12_aux_surface(plane_state);
3143 } else if (is_ccs_modifier(fb->modifier)) {
3144 ret = skl_check_ccs_aux_surface(plane_state);
3148 plane_state->color_plane[1].offset = ~0xfff;
3149 plane_state->color_plane[1].x = 0;
3150 plane_state->color_plane[1].y = 0;
3153 ret = skl_check_main_surface(plane_state);
3161 i9xx_plane_max_stride(struct intel_plane *plane,
3162 u32 pixel_format, u64 modifier,
3163 unsigned int rotation)
3165 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3167 if (!HAS_GMCH_DISPLAY(dev_priv)) {
3169 } else if (INTEL_GEN(dev_priv) >= 4) {
3170 if (modifier == I915_FORMAT_MOD_X_TILED)
3174 } else if (INTEL_GEN(dev_priv) >= 3) {
3175 if (modifier == I915_FORMAT_MOD_X_TILED)
3180 if (plane->i9xx_plane == PLANE_C)
3187 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3188 const struct intel_plane_state *plane_state)
3190 struct drm_i915_private *dev_priv =
3191 to_i915(plane_state->base.plane->dev);
3192 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3193 const struct drm_framebuffer *fb = plane_state->base.fb;
3194 unsigned int rotation = plane_state->base.rotation;
3197 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
3199 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3200 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
3201 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3203 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3204 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3206 if (INTEL_GEN(dev_priv) < 5)
3207 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3209 switch (fb->format->format) {
3211 dspcntr |= DISPPLANE_8BPP;
3213 case DRM_FORMAT_XRGB1555:
3214 dspcntr |= DISPPLANE_BGRX555;
3216 case DRM_FORMAT_RGB565:
3217 dspcntr |= DISPPLANE_BGRX565;
3219 case DRM_FORMAT_XRGB8888:
3220 dspcntr |= DISPPLANE_BGRX888;
3222 case DRM_FORMAT_XBGR8888:
3223 dspcntr |= DISPPLANE_RGBX888;
3225 case DRM_FORMAT_XRGB2101010:
3226 dspcntr |= DISPPLANE_BGRX101010;
3228 case DRM_FORMAT_XBGR2101010:
3229 dspcntr |= DISPPLANE_RGBX101010;
3232 MISSING_CASE(fb->format->format);
3236 if (INTEL_GEN(dev_priv) >= 4 &&
3237 fb->modifier == I915_FORMAT_MOD_X_TILED)
3238 dspcntr |= DISPPLANE_TILED;
3240 if (rotation & DRM_MODE_ROTATE_180)
3241 dspcntr |= DISPPLANE_ROTATE_180;
3243 if (rotation & DRM_MODE_REFLECT_X)
3244 dspcntr |= DISPPLANE_MIRROR;
3249 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3251 struct drm_i915_private *dev_priv =
3252 to_i915(plane_state->base.plane->dev);
3253 const struct drm_framebuffer *fb = plane_state->base.fb;
3254 unsigned int rotation = plane_state->base.rotation;
3255 int src_x = plane_state->base.src.x1 >> 16;
3256 int src_y = plane_state->base.src.y1 >> 16;
3260 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3261 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3263 ret = intel_plane_check_stride(plane_state);
3267 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3269 if (INTEL_GEN(dev_priv) >= 4)
3270 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3275 /* HSW/BDW do this automagically in hardware */
3276 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3277 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3278 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3280 if (rotation & DRM_MODE_ROTATE_180) {
3283 } else if (rotation & DRM_MODE_REFLECT_X) {
3288 plane_state->color_plane[0].offset = offset;
3289 plane_state->color_plane[0].x = src_x;
3290 plane_state->color_plane[0].y = src_y;
3296 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3297 struct intel_plane_state *plane_state)
3301 ret = chv_plane_check_rotation(plane_state);
3305 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3307 DRM_PLANE_HELPER_NO_SCALING,
3308 DRM_PLANE_HELPER_NO_SCALING,
3313 if (!plane_state->base.visible)
3316 ret = intel_plane_check_src_coordinates(plane_state);
3320 ret = i9xx_check_plane_surface(plane_state);
3324 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3329 static void i9xx_update_plane(struct intel_plane *plane,
3330 const struct intel_crtc_state *crtc_state,
3331 const struct intel_plane_state *plane_state)
3333 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3334 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3336 u32 dspcntr = plane_state->ctl;
3337 i915_reg_t reg = DSPCNTR(i9xx_plane);
3338 int x = plane_state->color_plane[0].x;
3339 int y = plane_state->color_plane[0].y;
3340 unsigned long irqflags;
3343 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3345 if (INTEL_GEN(dev_priv) >= 4)
3346 dspaddr_offset = plane_state->color_plane[0].offset;
3348 dspaddr_offset = linear_offset;
3350 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3352 if (INTEL_GEN(dev_priv) < 4) {
3353 /* pipesrc and dspsize control the size that is scaled from,
3354 * which should always be the user's requested size.
3356 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3357 ((crtc_state->pipe_src_h - 1) << 16) |
3358 (crtc_state->pipe_src_w - 1));
3359 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3360 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3361 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3362 ((crtc_state->pipe_src_h - 1) << 16) |
3363 (crtc_state->pipe_src_w - 1));
3364 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3365 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3368 I915_WRITE_FW(reg, dspcntr);
3370 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3371 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3372 I915_WRITE_FW(DSPSURF(i9xx_plane),
3373 intel_plane_ggtt_offset(plane_state) +
3375 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3376 } else if (INTEL_GEN(dev_priv) >= 4) {
3377 I915_WRITE_FW(DSPSURF(i9xx_plane),
3378 intel_plane_ggtt_offset(plane_state) +
3380 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3381 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3383 I915_WRITE_FW(DSPADDR(i9xx_plane),
3384 intel_plane_ggtt_offset(plane_state) +
3387 POSTING_READ_FW(reg);
3389 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3392 static void i9xx_disable_plane(struct intel_plane *plane,
3393 struct intel_crtc *crtc)
3395 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3396 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3397 unsigned long irqflags;
3399 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3401 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3402 if (INTEL_GEN(dev_priv) >= 4)
3403 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3405 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3406 POSTING_READ_FW(DSPCNTR(i9xx_plane));
3408 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3411 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3414 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3415 enum intel_display_power_domain power_domain;
3416 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3421 * Not 100% correct for planes that can move between pipes,
3422 * but that's only the case for gen2-4 which don't have any
3423 * display power wells.
3425 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3426 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3429 val = I915_READ(DSPCNTR(i9xx_plane));
3431 ret = val & DISPLAY_PLANE_ENABLE;
3433 if (INTEL_GEN(dev_priv) >= 5)
3434 *pipe = plane->pipe;
3436 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3437 DISPPLANE_SEL_PIPE_SHIFT;
3439 intel_display_power_put(dev_priv, power_domain);
3445 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
3447 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3450 return intel_tile_width_bytes(fb, color_plane);
3453 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3455 struct drm_device *dev = intel_crtc->base.dev;
3456 struct drm_i915_private *dev_priv = to_i915(dev);
3458 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3459 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3460 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3464 * This function detaches (aka. unbinds) unused scalers in hardware
3466 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
3468 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3469 const struct intel_crtc_scaler_state *scaler_state =
3470 &crtc_state->scaler_state;
3473 /* loop through and disable scalers that aren't in use */
3474 for (i = 0; i < intel_crtc->num_scalers; i++) {
3475 if (!scaler_state->scalers[i].in_use)
3476 skl_detach_scaler(intel_crtc, i);
3480 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3483 const struct drm_framebuffer *fb = plane_state->base.fb;
3484 unsigned int rotation = plane_state->base.rotation;
3485 u32 stride = plane_state->color_plane[color_plane].stride;
3487 if (color_plane >= fb->format->num_planes)
3491 * The stride is either expressed as a multiple of 64 bytes chunks for
3492 * linear buffers or in number of tiles for tiled buffers.
3494 if (drm_rotation_90_or_270(rotation))
3495 stride /= intel_tile_height(fb, color_plane);
3497 stride /= intel_fb_stride_alignment(fb, color_plane);
3502 static u32 skl_plane_ctl_format(uint32_t pixel_format)
3504 switch (pixel_format) {
3506 return PLANE_CTL_FORMAT_INDEXED;
3507 case DRM_FORMAT_RGB565:
3508 return PLANE_CTL_FORMAT_RGB_565;
3509 case DRM_FORMAT_XBGR8888:
3510 case DRM_FORMAT_ABGR8888:
3511 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3512 case DRM_FORMAT_XRGB8888:
3513 case DRM_FORMAT_ARGB8888:
3514 return PLANE_CTL_FORMAT_XRGB_8888;
3515 case DRM_FORMAT_XRGB2101010:
3516 return PLANE_CTL_FORMAT_XRGB_2101010;
3517 case DRM_FORMAT_XBGR2101010:
3518 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3519 case DRM_FORMAT_YUYV:
3520 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3521 case DRM_FORMAT_YVYU:
3522 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3523 case DRM_FORMAT_UYVY:
3524 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3525 case DRM_FORMAT_VYUY:
3526 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3527 case DRM_FORMAT_NV12:
3528 return PLANE_CTL_FORMAT_NV12;
3530 MISSING_CASE(pixel_format);
3536 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
3538 if (!plane_state->base.fb->format->has_alpha)
3539 return PLANE_CTL_ALPHA_DISABLE;
3541 switch (plane_state->base.pixel_blend_mode) {
3542 case DRM_MODE_BLEND_PIXEL_NONE:
3543 return PLANE_CTL_ALPHA_DISABLE;
3544 case DRM_MODE_BLEND_PREMULTI:
3545 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3546 case DRM_MODE_BLEND_COVERAGE:
3547 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
3549 MISSING_CASE(plane_state->base.pixel_blend_mode);
3550 return PLANE_CTL_ALPHA_DISABLE;
3554 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
3556 if (!plane_state->base.fb->format->has_alpha)
3557 return PLANE_COLOR_ALPHA_DISABLE;
3559 switch (plane_state->base.pixel_blend_mode) {
3560 case DRM_MODE_BLEND_PIXEL_NONE:
3561 return PLANE_COLOR_ALPHA_DISABLE;
3562 case DRM_MODE_BLEND_PREMULTI:
3563 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3564 case DRM_MODE_BLEND_COVERAGE:
3565 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
3567 MISSING_CASE(plane_state->base.pixel_blend_mode);
3568 return PLANE_COLOR_ALPHA_DISABLE;
3572 static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
3574 switch (fb_modifier) {
3575 case DRM_FORMAT_MOD_LINEAR:
3577 case I915_FORMAT_MOD_X_TILED:
3578 return PLANE_CTL_TILED_X;
3579 case I915_FORMAT_MOD_Y_TILED:
3580 return PLANE_CTL_TILED_Y;
3581 case I915_FORMAT_MOD_Y_TILED_CCS:
3582 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3583 case I915_FORMAT_MOD_Yf_TILED:
3584 return PLANE_CTL_TILED_YF;
3585 case I915_FORMAT_MOD_Yf_TILED_CCS:
3586 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3588 MISSING_CASE(fb_modifier);
3594 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3597 case DRM_MODE_ROTATE_0:
3600 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3601 * while i915 HW rotation is clockwise, thats why this swapping.
3603 case DRM_MODE_ROTATE_90:
3604 return PLANE_CTL_ROTATE_270;
3605 case DRM_MODE_ROTATE_180:
3606 return PLANE_CTL_ROTATE_180;
3607 case DRM_MODE_ROTATE_270:
3608 return PLANE_CTL_ROTATE_90;
3610 MISSING_CASE(rotate);
3616 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3621 case DRM_MODE_REFLECT_X:
3622 return PLANE_CTL_FLIP_HORIZONTAL;
3623 case DRM_MODE_REFLECT_Y:
3625 MISSING_CASE(reflect);
3631 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3632 const struct intel_plane_state *plane_state)
3634 struct drm_i915_private *dev_priv =
3635 to_i915(plane_state->base.plane->dev);
3636 const struct drm_framebuffer *fb = plane_state->base.fb;
3637 unsigned int rotation = plane_state->base.rotation;
3638 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3641 plane_ctl = PLANE_CTL_ENABLE;
3643 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3644 plane_ctl |= skl_plane_ctl_alpha(plane_state);
3646 PLANE_CTL_PIPE_GAMMA_ENABLE |
3647 PLANE_CTL_PIPE_CSC_ENABLE |
3648 PLANE_CTL_PLANE_GAMMA_DISABLE;
3650 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3651 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3653 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3654 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3657 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3658 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3659 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3661 if (INTEL_GEN(dev_priv) >= 10)
3662 plane_ctl |= cnl_plane_ctl_flip(rotation &
3663 DRM_MODE_REFLECT_MASK);
3665 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3666 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3667 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3668 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3673 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3674 const struct intel_plane_state *plane_state)
3676 struct drm_i915_private *dev_priv =
3677 to_i915(plane_state->base.plane->dev);
3678 const struct drm_framebuffer *fb = plane_state->base.fb;
3679 u32 plane_color_ctl = 0;
3681 if (INTEL_GEN(dev_priv) < 11) {
3682 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3683 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3685 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3686 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
3688 if (fb->format->is_yuv) {
3689 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3690 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3692 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
3694 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3695 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3698 return plane_color_ctl;
3702 __intel_display_resume(struct drm_device *dev,
3703 struct drm_atomic_state *state,
3704 struct drm_modeset_acquire_ctx *ctx)
3706 struct drm_crtc_state *crtc_state;
3707 struct drm_crtc *crtc;
3710 intel_modeset_setup_hw_state(dev, ctx);
3711 i915_redisable_vga(to_i915(dev));
3717 * We've duplicated the state, pointers to the old state are invalid.
3719 * Don't attempt to use the old state until we commit the duplicated state.
3721 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3723 * Force recalculation even if we restore
3724 * current state. With fast modeset this may not result
3725 * in a modeset when the state is compatible.
3727 crtc_state->mode_changed = true;
3730 /* ignore any reset values/BIOS leftovers in the WM registers */
3731 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3732 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3734 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3736 WARN_ON(ret == -EDEADLK);
3740 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3742 return intel_has_gpu_reset(dev_priv) &&
3743 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
3746 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3748 struct drm_device *dev = &dev_priv->drm;
3749 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3750 struct drm_atomic_state *state;
3753 /* reset doesn't touch the display */
3754 if (!i915_modparams.force_reset_modeset_test &&
3755 !gpu_reset_clobbers_display(dev_priv))
3758 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3759 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3760 wake_up_all(&dev_priv->gpu_error.wait_queue);
3762 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3763 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3764 i915_gem_set_wedged(dev_priv);
3768 * Need mode_config.mutex so that we don't
3769 * trample ongoing ->detect() and whatnot.
3771 mutex_lock(&dev->mode_config.mutex);
3772 drm_modeset_acquire_init(ctx, 0);
3774 ret = drm_modeset_lock_all_ctx(dev, ctx);
3775 if (ret != -EDEADLK)
3778 drm_modeset_backoff(ctx);
3781 * Disabling the crtcs gracefully seems nicer. Also the
3782 * g33 docs say we should at least disable all the planes.
3784 state = drm_atomic_helper_duplicate_state(dev, ctx);
3785 if (IS_ERR(state)) {
3786 ret = PTR_ERR(state);
3787 DRM_ERROR("Duplicating state failed with %i\n", ret);
3791 ret = drm_atomic_helper_disable_all(dev, ctx);
3793 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3794 drm_atomic_state_put(state);
3798 dev_priv->modeset_restore_state = state;
3799 state->acquire_ctx = ctx;
3802 void intel_finish_reset(struct drm_i915_private *dev_priv)
3804 struct drm_device *dev = &dev_priv->drm;
3805 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3806 struct drm_atomic_state *state;
3809 /* reset doesn't touch the display */
3810 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
3813 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3817 /* reset doesn't touch the display */
3818 if (!gpu_reset_clobbers_display(dev_priv)) {
3819 /* for testing only restore the display */
3820 ret = __intel_display_resume(dev, state, ctx);
3822 DRM_ERROR("Restoring old state failed with %i\n", ret);
3825 * The display has been reset as well,
3826 * so need a full re-initialization.
3828 intel_runtime_pm_disable_interrupts(dev_priv);
3829 intel_runtime_pm_enable_interrupts(dev_priv);
3831 intel_pps_unlock_regs_wa(dev_priv);
3832 intel_modeset_init_hw(dev);
3833 intel_init_clock_gating(dev_priv);
3835 spin_lock_irq(&dev_priv->irq_lock);
3836 if (dev_priv->display.hpd_irq_setup)
3837 dev_priv->display.hpd_irq_setup(dev_priv);
3838 spin_unlock_irq(&dev_priv->irq_lock);
3840 ret = __intel_display_resume(dev, state, ctx);
3842 DRM_ERROR("Restoring old state failed with %i\n", ret);
3844 intel_hpd_init(dev_priv);
3847 drm_atomic_state_put(state);
3849 drm_modeset_drop_locks(ctx);
3850 drm_modeset_acquire_fini(ctx);
3851 mutex_unlock(&dev->mode_config.mutex);
3853 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3856 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3857 const struct intel_crtc_state *new_crtc_state)
3859 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
3860 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3862 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3863 crtc->base.mode = new_crtc_state->base.mode;
3866 * Update pipe size and adjust fitter if needed: the reason for this is
3867 * that in compute_mode_changes we check the native mode (not the pfit
3868 * mode) to see if we can flip rather than do a full mode set. In the
3869 * fastboot case, we'll flip, but if we don't update the pipesrc and
3870 * pfit state, we'll end up with a big fb scanned out into the wrong
3874 I915_WRITE(PIPESRC(crtc->pipe),
3875 ((new_crtc_state->pipe_src_w - 1) << 16) |
3876 (new_crtc_state->pipe_src_h - 1));
3878 /* on skylake this is done by detaching scalers */
3879 if (INTEL_GEN(dev_priv) >= 9) {
3880 skl_detach_scalers(new_crtc_state);
3882 if (new_crtc_state->pch_pfit.enabled)
3883 skylake_pfit_enable(new_crtc_state);
3884 } else if (HAS_PCH_SPLIT(dev_priv)) {
3885 if (new_crtc_state->pch_pfit.enabled)
3886 ironlake_pfit_enable(new_crtc_state);
3887 else if (old_crtc_state->pch_pfit.enabled)
3888 ironlake_pfit_disable(old_crtc_state);
3892 static void intel_fdi_normal_train(struct intel_crtc *crtc)
3894 struct drm_device *dev = crtc->base.dev;
3895 struct drm_i915_private *dev_priv = to_i915(dev);
3896 int pipe = crtc->pipe;
3900 /* enable normal train */
3901 reg = FDI_TX_CTL(pipe);
3902 temp = I915_READ(reg);
3903 if (IS_IVYBRIDGE(dev_priv)) {
3904 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3905 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3907 temp &= ~FDI_LINK_TRAIN_NONE;
3908 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3910 I915_WRITE(reg, temp);
3912 reg = FDI_RX_CTL(pipe);
3913 temp = I915_READ(reg);
3914 if (HAS_PCH_CPT(dev_priv)) {
3915 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3916 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3918 temp &= ~FDI_LINK_TRAIN_NONE;
3919 temp |= FDI_LINK_TRAIN_NONE;
3921 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3923 /* wait one idle pattern time */
3927 /* IVB wants error correction enabled */
3928 if (IS_IVYBRIDGE(dev_priv))
3929 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3930 FDI_FE_ERRC_ENABLE);
3933 /* The FDI link training functions for ILK/Ibexpeak. */
3934 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3935 const struct intel_crtc_state *crtc_state)
3937 struct drm_device *dev = crtc->base.dev;
3938 struct drm_i915_private *dev_priv = to_i915(dev);
3939 int pipe = crtc->pipe;
3943 /* FDI needs bits from pipe first */
3944 assert_pipe_enabled(dev_priv, pipe);
3946 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3948 reg = FDI_RX_IMR(pipe);
3949 temp = I915_READ(reg);
3950 temp &= ~FDI_RX_SYMBOL_LOCK;
3951 temp &= ~FDI_RX_BIT_LOCK;
3952 I915_WRITE(reg, temp);
3956 /* enable CPU FDI TX and PCH FDI RX */
3957 reg = FDI_TX_CTL(pipe);
3958 temp = I915_READ(reg);
3959 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3960 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3961 temp &= ~FDI_LINK_TRAIN_NONE;
3962 temp |= FDI_LINK_TRAIN_PATTERN_1;
3963 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3965 reg = FDI_RX_CTL(pipe);
3966 temp = I915_READ(reg);
3967 temp &= ~FDI_LINK_TRAIN_NONE;
3968 temp |= FDI_LINK_TRAIN_PATTERN_1;
3969 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3974 /* Ironlake workaround, enable clock pointer after FDI enable*/
3975 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3976 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3977 FDI_RX_PHASE_SYNC_POINTER_EN);
3979 reg = FDI_RX_IIR(pipe);
3980 for (tries = 0; tries < 5; tries++) {
3981 temp = I915_READ(reg);
3982 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3984 if ((temp & FDI_RX_BIT_LOCK)) {
3985 DRM_DEBUG_KMS("FDI train 1 done.\n");
3986 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3991 DRM_ERROR("FDI train 1 fail!\n");
3994 reg = FDI_TX_CTL(pipe);
3995 temp = I915_READ(reg);
3996 temp &= ~FDI_LINK_TRAIN_NONE;
3997 temp |= FDI_LINK_TRAIN_PATTERN_2;
3998 I915_WRITE(reg, temp);
4000 reg = FDI_RX_CTL(pipe);
4001 temp = I915_READ(reg);
4002 temp &= ~FDI_LINK_TRAIN_NONE;
4003 temp |= FDI_LINK_TRAIN_PATTERN_2;
4004 I915_WRITE(reg, temp);
4009 reg = FDI_RX_IIR(pipe);
4010 for (tries = 0; tries < 5; tries++) {
4011 temp = I915_READ(reg);
4012 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4014 if (temp & FDI_RX_SYMBOL_LOCK) {
4015 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4016 DRM_DEBUG_KMS("FDI train 2 done.\n");
4021 DRM_ERROR("FDI train 2 fail!\n");
4023 DRM_DEBUG_KMS("FDI train done\n");
4027 static const int snb_b_fdi_train_param[] = {
4028 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4029 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4030 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4031 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4034 /* The FDI link training functions for SNB/Cougarpoint. */
4035 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4036 const struct intel_crtc_state *crtc_state)
4038 struct drm_device *dev = crtc->base.dev;
4039 struct drm_i915_private *dev_priv = to_i915(dev);
4040 int pipe = crtc->pipe;
4044 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4046 reg = FDI_RX_IMR(pipe);
4047 temp = I915_READ(reg);
4048 temp &= ~FDI_RX_SYMBOL_LOCK;
4049 temp &= ~FDI_RX_BIT_LOCK;
4050 I915_WRITE(reg, temp);
4055 /* enable CPU FDI TX and PCH FDI RX */
4056 reg = FDI_TX_CTL(pipe);
4057 temp = I915_READ(reg);
4058 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4059 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4060 temp &= ~FDI_LINK_TRAIN_NONE;
4061 temp |= FDI_LINK_TRAIN_PATTERN_1;
4062 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4064 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4065 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4067 I915_WRITE(FDI_RX_MISC(pipe),
4068 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4070 reg = FDI_RX_CTL(pipe);
4071 temp = I915_READ(reg);
4072 if (HAS_PCH_CPT(dev_priv)) {
4073 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4074 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4076 temp &= ~FDI_LINK_TRAIN_NONE;
4077 temp |= FDI_LINK_TRAIN_PATTERN_1;
4079 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4084 for (i = 0; i < 4; i++) {
4085 reg = FDI_TX_CTL(pipe);
4086 temp = I915_READ(reg);
4087 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4088 temp |= snb_b_fdi_train_param[i];
4089 I915_WRITE(reg, temp);
4094 for (retry = 0; retry < 5; retry++) {
4095 reg = FDI_RX_IIR(pipe);
4096 temp = I915_READ(reg);
4097 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4098 if (temp & FDI_RX_BIT_LOCK) {
4099 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4100 DRM_DEBUG_KMS("FDI train 1 done.\n");
4109 DRM_ERROR("FDI train 1 fail!\n");
4112 reg = FDI_TX_CTL(pipe);
4113 temp = I915_READ(reg);
4114 temp &= ~FDI_LINK_TRAIN_NONE;
4115 temp |= FDI_LINK_TRAIN_PATTERN_2;
4116 if (IS_GEN6(dev_priv)) {
4117 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4119 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4121 I915_WRITE(reg, temp);
4123 reg = FDI_RX_CTL(pipe);
4124 temp = I915_READ(reg);
4125 if (HAS_PCH_CPT(dev_priv)) {
4126 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4127 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4129 temp &= ~FDI_LINK_TRAIN_NONE;
4130 temp |= FDI_LINK_TRAIN_PATTERN_2;
4132 I915_WRITE(reg, temp);
4137 for (i = 0; i < 4; i++) {
4138 reg = FDI_TX_CTL(pipe);
4139 temp = I915_READ(reg);
4140 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4141 temp |= snb_b_fdi_train_param[i];
4142 I915_WRITE(reg, temp);
4147 for (retry = 0; retry < 5; retry++) {
4148 reg = FDI_RX_IIR(pipe);
4149 temp = I915_READ(reg);
4150 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4151 if (temp & FDI_RX_SYMBOL_LOCK) {
4152 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4153 DRM_DEBUG_KMS("FDI train 2 done.\n");
4162 DRM_ERROR("FDI train 2 fail!\n");
4164 DRM_DEBUG_KMS("FDI train done.\n");
4167 /* Manual link training for Ivy Bridge A0 parts */
4168 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4169 const struct intel_crtc_state *crtc_state)
4171 struct drm_device *dev = crtc->base.dev;
4172 struct drm_i915_private *dev_priv = to_i915(dev);
4173 int pipe = crtc->pipe;
4177 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4179 reg = FDI_RX_IMR(pipe);
4180 temp = I915_READ(reg);
4181 temp &= ~FDI_RX_SYMBOL_LOCK;
4182 temp &= ~FDI_RX_BIT_LOCK;
4183 I915_WRITE(reg, temp);
4188 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4189 I915_READ(FDI_RX_IIR(pipe)));
4191 /* Try each vswing and preemphasis setting twice before moving on */
4192 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4193 /* disable first in case we need to retry */
4194 reg = FDI_TX_CTL(pipe);
4195 temp = I915_READ(reg);
4196 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4197 temp &= ~FDI_TX_ENABLE;
4198 I915_WRITE(reg, temp);
4200 reg = FDI_RX_CTL(pipe);
4201 temp = I915_READ(reg);
4202 temp &= ~FDI_LINK_TRAIN_AUTO;
4203 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4204 temp &= ~FDI_RX_ENABLE;
4205 I915_WRITE(reg, temp);
4207 /* enable CPU FDI TX and PCH FDI RX */
4208 reg = FDI_TX_CTL(pipe);
4209 temp = I915_READ(reg);
4210 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4211 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4212 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4213 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4214 temp |= snb_b_fdi_train_param[j/2];
4215 temp |= FDI_COMPOSITE_SYNC;
4216 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4218 I915_WRITE(FDI_RX_MISC(pipe),
4219 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4221 reg = FDI_RX_CTL(pipe);
4222 temp = I915_READ(reg);
4223 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4224 temp |= FDI_COMPOSITE_SYNC;
4225 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4228 udelay(1); /* should be 0.5us */
4230 for (i = 0; i < 4; i++) {
4231 reg = FDI_RX_IIR(pipe);
4232 temp = I915_READ(reg);
4233 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4235 if (temp & FDI_RX_BIT_LOCK ||
4236 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4237 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4238 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4242 udelay(1); /* should be 0.5us */
4245 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4250 reg = FDI_TX_CTL(pipe);
4251 temp = I915_READ(reg);
4252 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4253 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4254 I915_WRITE(reg, temp);
4256 reg = FDI_RX_CTL(pipe);
4257 temp = I915_READ(reg);
4258 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4259 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4260 I915_WRITE(reg, temp);
4263 udelay(2); /* should be 1.5us */
4265 for (i = 0; i < 4; i++) {
4266 reg = FDI_RX_IIR(pipe);
4267 temp = I915_READ(reg);
4268 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4270 if (temp & FDI_RX_SYMBOL_LOCK ||
4271 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4272 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4273 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4277 udelay(2); /* should be 1.5us */
4280 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4284 DRM_DEBUG_KMS("FDI train done.\n");
4287 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4289 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4290 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4291 int pipe = intel_crtc->pipe;
4295 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4296 reg = FDI_RX_CTL(pipe);
4297 temp = I915_READ(reg);
4298 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4299 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4300 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4301 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4306 /* Switch from Rawclk to PCDclk */
4307 temp = I915_READ(reg);
4308 I915_WRITE(reg, temp | FDI_PCDCLK);
4313 /* Enable CPU FDI TX PLL, always on for Ironlake */
4314 reg = FDI_TX_CTL(pipe);
4315 temp = I915_READ(reg);
4316 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4317 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4324 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4326 struct drm_device *dev = intel_crtc->base.dev;
4327 struct drm_i915_private *dev_priv = to_i915(dev);
4328 int pipe = intel_crtc->pipe;
4332 /* Switch from PCDclk to Rawclk */
4333 reg = FDI_RX_CTL(pipe);
4334 temp = I915_READ(reg);
4335 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4337 /* Disable CPU FDI TX PLL */
4338 reg = FDI_TX_CTL(pipe);
4339 temp = I915_READ(reg);
4340 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4345 reg = FDI_RX_CTL(pipe);
4346 temp = I915_READ(reg);
4347 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4349 /* Wait for the clocks to turn off. */
4354 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4356 struct drm_device *dev = crtc->dev;
4357 struct drm_i915_private *dev_priv = to_i915(dev);
4358 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4359 int pipe = intel_crtc->pipe;
4363 /* disable CPU FDI tx and PCH FDI rx */
4364 reg = FDI_TX_CTL(pipe);
4365 temp = I915_READ(reg);
4366 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4369 reg = FDI_RX_CTL(pipe);
4370 temp = I915_READ(reg);
4371 temp &= ~(0x7 << 16);
4372 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4373 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4378 /* Ironlake workaround, disable clock pointer after downing FDI */
4379 if (HAS_PCH_IBX(dev_priv))
4380 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4382 /* still set train pattern 1 */
4383 reg = FDI_TX_CTL(pipe);
4384 temp = I915_READ(reg);
4385 temp &= ~FDI_LINK_TRAIN_NONE;
4386 temp |= FDI_LINK_TRAIN_PATTERN_1;
4387 I915_WRITE(reg, temp);
4389 reg = FDI_RX_CTL(pipe);
4390 temp = I915_READ(reg);
4391 if (HAS_PCH_CPT(dev_priv)) {
4392 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4393 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4395 temp &= ~FDI_LINK_TRAIN_NONE;
4396 temp |= FDI_LINK_TRAIN_PATTERN_1;
4398 /* BPC in FDI rx is consistent with that in PIPECONF */
4399 temp &= ~(0x07 << 16);
4400 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4401 I915_WRITE(reg, temp);
4407 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4409 struct drm_crtc *crtc;
4412 drm_for_each_crtc(crtc, &dev_priv->drm) {
4413 struct drm_crtc_commit *commit;
4414 spin_lock(&crtc->commit_lock);
4415 commit = list_first_entry_or_null(&crtc->commit_list,
4416 struct drm_crtc_commit, commit_entry);
4417 cleanup_done = commit ?
4418 try_wait_for_completion(&commit->cleanup_done) : true;
4419 spin_unlock(&crtc->commit_lock);
4424 drm_crtc_wait_one_vblank(crtc);
4432 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4436 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4438 mutex_lock(&dev_priv->sb_lock);
4440 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4441 temp |= SBI_SSCCTL_DISABLE;
4442 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4444 mutex_unlock(&dev_priv->sb_lock);
4447 /* Program iCLKIP clock to the desired frequency */
4448 static void lpt_program_iclkip(struct intel_crtc *crtc)
4450 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4451 int clock = crtc->config->base.adjusted_mode.crtc_clock;
4452 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4455 lpt_disable_iclkip(dev_priv);
4457 /* The iCLK virtual clock root frequency is in MHz,
4458 * but the adjusted_mode->crtc_clock in in KHz. To get the
4459 * divisors, it is necessary to divide one by another, so we
4460 * convert the virtual clock precision to KHz here for higher
4463 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4464 u32 iclk_virtual_root_freq = 172800 * 1000;
4465 u32 iclk_pi_range = 64;
4466 u32 desired_divisor;
4468 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4470 divsel = (desired_divisor / iclk_pi_range) - 2;
4471 phaseinc = desired_divisor % iclk_pi_range;
4474 * Near 20MHz is a corner case which is
4475 * out of range for the 7-bit divisor
4481 /* This should not happen with any sane values */
4482 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4483 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4484 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4485 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4487 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4494 mutex_lock(&dev_priv->sb_lock);
4496 /* Program SSCDIVINTPHASE6 */
4497 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4498 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4499 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4500 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4501 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4502 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4503 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4504 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4506 /* Program SSCAUXDIV */
4507 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4508 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4509 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4510 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4512 /* Enable modulator and associated divider */
4513 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4514 temp &= ~SBI_SSCCTL_DISABLE;
4515 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4517 mutex_unlock(&dev_priv->sb_lock);
4519 /* Wait for initialization time */
4522 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4525 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4527 u32 divsel, phaseinc, auxdiv;
4528 u32 iclk_virtual_root_freq = 172800 * 1000;
4529 u32 iclk_pi_range = 64;
4530 u32 desired_divisor;
4533 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4536 mutex_lock(&dev_priv->sb_lock);
4538 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4539 if (temp & SBI_SSCCTL_DISABLE) {
4540 mutex_unlock(&dev_priv->sb_lock);
4544 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4545 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4546 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4547 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4548 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4550 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4551 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4552 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4554 mutex_unlock(&dev_priv->sb_lock);
4556 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4558 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4559 desired_divisor << auxdiv);
4562 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
4563 enum pipe pch_transcoder)
4565 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4566 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4567 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4569 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4570 I915_READ(HTOTAL(cpu_transcoder)));
4571 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4572 I915_READ(HBLANK(cpu_transcoder)));
4573 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4574 I915_READ(HSYNC(cpu_transcoder)));
4576 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4577 I915_READ(VTOTAL(cpu_transcoder)));
4578 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4579 I915_READ(VBLANK(cpu_transcoder)));
4580 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4581 I915_READ(VSYNC(cpu_transcoder)));
4582 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4583 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4586 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4588 struct drm_i915_private *dev_priv = to_i915(dev);
4591 temp = I915_READ(SOUTH_CHICKEN1);
4592 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4595 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4596 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4598 temp &= ~FDI_BC_BIFURCATION_SELECT;
4600 temp |= FDI_BC_BIFURCATION_SELECT;
4602 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4603 I915_WRITE(SOUTH_CHICKEN1, temp);
4604 POSTING_READ(SOUTH_CHICKEN1);
4607 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4609 struct drm_device *dev = intel_crtc->base.dev;
4611 switch (intel_crtc->pipe) {
4615 if (intel_crtc->config->fdi_lanes > 2)
4616 cpt_set_fdi_bc_bifurcation(dev, false);
4618 cpt_set_fdi_bc_bifurcation(dev, true);
4622 cpt_set_fdi_bc_bifurcation(dev, true);
4631 * Finds the encoder associated with the given CRTC. This can only be
4632 * used when we know that the CRTC isn't feeding multiple encoders!
4634 static struct intel_encoder *
4635 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4636 const struct intel_crtc_state *crtc_state)
4638 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4639 const struct drm_connector_state *connector_state;
4640 const struct drm_connector *connector;
4641 struct intel_encoder *encoder = NULL;
4642 int num_encoders = 0;
4645 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4646 if (connector_state->crtc != &crtc->base)
4649 encoder = to_intel_encoder(connector_state->best_encoder);
4653 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4654 num_encoders, pipe_name(crtc->pipe));
4660 * Enable PCH resources required for PCH ports:
4662 * - FDI training & RX/TX
4663 * - update transcoder timings
4664 * - DP transcoding bits
4667 static void ironlake_pch_enable(const struct intel_atomic_state *state,
4668 const struct intel_crtc_state *crtc_state)
4670 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4671 struct drm_device *dev = crtc->base.dev;
4672 struct drm_i915_private *dev_priv = to_i915(dev);
4673 int pipe = crtc->pipe;
4676 assert_pch_transcoder_disabled(dev_priv, pipe);
4678 if (IS_IVYBRIDGE(dev_priv))
4679 ivybridge_update_fdi_bc_bifurcation(crtc);
4681 /* Write the TU size bits before fdi link training, so that error
4682 * detection works. */
4683 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4684 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4686 /* For PCH output, training FDI link */
4687 dev_priv->display.fdi_link_train(crtc, crtc_state);
4689 /* We need to program the right clock selection before writing the pixel
4690 * mutliplier into the DPLL. */
4691 if (HAS_PCH_CPT(dev_priv)) {
4694 temp = I915_READ(PCH_DPLL_SEL);
4695 temp |= TRANS_DPLL_ENABLE(pipe);
4696 sel = TRANS_DPLLB_SEL(pipe);
4697 if (crtc_state->shared_dpll ==
4698 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4702 I915_WRITE(PCH_DPLL_SEL, temp);
4705 /* XXX: pch pll's can be enabled any time before we enable the PCH
4706 * transcoder, and we actually should do this to not upset any PCH
4707 * transcoder that already use the clock when we share it.
4709 * Note that enable_shared_dpll tries to do the right thing, but
4710 * get_shared_dpll unconditionally resets the pll - we need that to have
4711 * the right LVDS enable sequence. */
4712 intel_enable_shared_dpll(crtc_state);
4714 /* set transcoder timing, panel must allow it */
4715 assert_panel_unlocked(dev_priv, pipe);
4716 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
4718 intel_fdi_normal_train(crtc);
4720 /* For PCH DP, enable TRANS_DP_CTL */
4721 if (HAS_PCH_CPT(dev_priv) &&
4722 intel_crtc_has_dp_encoder(crtc_state)) {
4723 const struct drm_display_mode *adjusted_mode =
4724 &crtc_state->base.adjusted_mode;
4725 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4726 i915_reg_t reg = TRANS_DP_CTL(pipe);
4729 temp = I915_READ(reg);
4730 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4731 TRANS_DP_SYNC_MASK |
4733 temp |= TRANS_DP_OUTPUT_ENABLE;
4734 temp |= bpc << 9; /* same format but at 11:9 */
4736 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4737 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4738 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4739 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4741 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
4742 WARN_ON(port < PORT_B || port > PORT_D);
4743 temp |= TRANS_DP_PORT_SEL(port);
4745 I915_WRITE(reg, temp);
4748 ironlake_enable_pch_transcoder(crtc_state);
4751 static void lpt_pch_enable(const struct intel_atomic_state *state,
4752 const struct intel_crtc_state *crtc_state)
4754 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4755 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4756 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4758 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4760 lpt_program_iclkip(crtc);
4762 /* Set transcoder timing. */
4763 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
4765 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4768 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4770 struct drm_i915_private *dev_priv = to_i915(dev);
4771 i915_reg_t dslreg = PIPEDSL(pipe);
4774 temp = I915_READ(dslreg);
4776 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4777 if (wait_for(I915_READ(dslreg) != temp, 5))
4778 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4783 * The hardware phase 0.0 refers to the center of the pixel.
4784 * We want to start from the top/left edge which is phase
4785 * -0.5. That matches how the hardware calculates the scaling
4786 * factors (from top-left of the first pixel to bottom-right
4787 * of the last pixel, as opposed to the pixel centers).
4789 * For 4:2:0 subsampled chroma planes we obviously have to
4790 * adjust that so that the chroma sample position lands in
4793 * Note that for packed YCbCr 4:2:2 formats there is no way to
4794 * control chroma siting. The hardware simply replicates the
4795 * chroma samples for both of the luma samples, and thus we don't
4796 * actually get the expected MPEG2 chroma siting convention :(
4797 * The same behaviour is observed on pre-SKL platforms as well.
4799 u16 skl_scaler_calc_phase(int sub, bool chroma_cosited)
4801 int phase = -0x8000;
4805 phase += (sub - 1) * 0x8000 / sub;
4808 phase = 0x10000 + phase;
4810 trip = PS_PHASE_TRIP;
4812 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4816 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4817 unsigned int scaler_user, int *scaler_id,
4818 int src_w, int src_h, int dst_w, int dst_h,
4819 bool plane_scaler_check,
4820 uint32_t pixel_format)
4822 struct intel_crtc_scaler_state *scaler_state =
4823 &crtc_state->scaler_state;
4824 struct intel_crtc *intel_crtc =
4825 to_intel_crtc(crtc_state->base.crtc);
4826 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4827 const struct drm_display_mode *adjusted_mode =
4828 &crtc_state->base.adjusted_mode;
4832 * Src coordinates are already rotated by 270 degrees for
4833 * the 90/270 degree plane rotation cases (to match the
4834 * GTT mapping), hence no need to account for rotation here.
4836 need_scaling = src_w != dst_w || src_h != dst_h;
4838 if (plane_scaler_check)
4839 if (pixel_format == DRM_FORMAT_NV12)
4840 need_scaling = true;
4842 if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX)
4843 need_scaling = true;
4846 * Scaling/fitting not supported in IF-ID mode in GEN9+
4847 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4848 * Once NV12 is enabled, handle it here while allocating scaler
4851 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4852 need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4853 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4858 * if plane is being disabled or scaler is no more required or force detach
4859 * - free scaler binded to this plane/crtc
4860 * - in order to do this, update crtc->scaler_usage
4862 * Here scaler state in crtc_state is set free so that
4863 * scaler can be assigned to other user. Actual register
4864 * update to free the scaler is done in plane/panel-fit programming.
4865 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4867 if (force_detach || !need_scaling) {
4868 if (*scaler_id >= 0) {
4869 scaler_state->scaler_users &= ~(1 << scaler_user);
4870 scaler_state->scalers[*scaler_id].in_use = 0;
4872 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4873 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4874 intel_crtc->pipe, scaler_user, *scaler_id,
4875 scaler_state->scaler_users);
4881 if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 &&
4882 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
4883 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4888 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4889 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4890 (IS_GEN11(dev_priv) &&
4891 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4892 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4893 (!IS_GEN11(dev_priv) &&
4894 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4895 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
4896 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4897 "size is out of scaler range\n",
4898 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4902 /* mark this plane as a scaler user in crtc_state */
4903 scaler_state->scaler_users |= (1 << scaler_user);
4904 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4905 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4906 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4907 scaler_state->scaler_users);
4913 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4915 * @state: crtc's scaler state
4918 * 0 - scaler_usage updated successfully
4919 * error - requested scaling cannot be supported or other error condition
4921 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4923 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
4925 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4926 &state->scaler_state.scaler_id,
4927 state->pipe_src_w, state->pipe_src_h,
4928 adjusted_mode->crtc_hdisplay,
4929 adjusted_mode->crtc_vdisplay, false, 0);
4933 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4934 * @crtc_state: crtc's scaler state
4935 * @plane_state: atomic plane state to update
4938 * 0 - scaler_usage updated successfully
4939 * error - requested scaling cannot be supported or other error condition
4941 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4942 struct intel_plane_state *plane_state)
4945 struct intel_plane *intel_plane =
4946 to_intel_plane(plane_state->base.plane);
4947 struct drm_framebuffer *fb = plane_state->base.fb;
4950 bool force_detach = !fb || !plane_state->base.visible;
4952 ret = skl_update_scaler(crtc_state, force_detach,
4953 drm_plane_index(&intel_plane->base),
4954 &plane_state->scaler_id,
4955 drm_rect_width(&plane_state->base.src) >> 16,
4956 drm_rect_height(&plane_state->base.src) >> 16,
4957 drm_rect_width(&plane_state->base.dst),
4958 drm_rect_height(&plane_state->base.dst),
4959 fb ? true : false, fb ? fb->format->format : 0);
4961 if (ret || plane_state->scaler_id < 0)
4964 /* check colorkey */
4965 if (plane_state->ckey.flags) {
4966 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4967 intel_plane->base.base.id,
4968 intel_plane->base.name);
4972 /* Check src format */
4973 switch (fb->format->format) {
4974 case DRM_FORMAT_RGB565:
4975 case DRM_FORMAT_XBGR8888:
4976 case DRM_FORMAT_XRGB8888:
4977 case DRM_FORMAT_ABGR8888:
4978 case DRM_FORMAT_ARGB8888:
4979 case DRM_FORMAT_XRGB2101010:
4980 case DRM_FORMAT_XBGR2101010:
4981 case DRM_FORMAT_YUYV:
4982 case DRM_FORMAT_YVYU:
4983 case DRM_FORMAT_UYVY:
4984 case DRM_FORMAT_VYUY:
4985 case DRM_FORMAT_NV12:
4988 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4989 intel_plane->base.base.id, intel_plane->base.name,
4990 fb->base.id, fb->format->format);
4997 static void skylake_scaler_disable(struct intel_crtc *crtc)
5001 for (i = 0; i < crtc->num_scalers; i++)
5002 skl_detach_scaler(crtc, i);
5005 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
5007 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5008 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5009 enum pipe pipe = crtc->pipe;
5010 const struct intel_crtc_scaler_state *scaler_state =
5011 &crtc_state->scaler_state;
5013 if (crtc_state->pch_pfit.enabled) {
5014 u16 uv_rgb_hphase, uv_rgb_vphase;
5017 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
5020 uv_rgb_hphase = skl_scaler_calc_phase(1, false);
5021 uv_rgb_vphase = skl_scaler_calc_phase(1, false);
5023 id = scaler_state->scaler_id;
5024 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5025 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5026 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5027 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5028 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5029 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5030 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5031 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
5035 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
5037 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5038 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5039 int pipe = crtc->pipe;
5041 if (crtc_state->pch_pfit.enabled) {
5042 /* Force use of hard-coded filter coefficients
5043 * as some pre-programmed values are broken,
5046 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5047 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5048 PF_PIPE_SEL_IVB(pipe));
5050 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5051 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5052 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
5056 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5058 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5059 struct drm_device *dev = crtc->base.dev;
5060 struct drm_i915_private *dev_priv = to_i915(dev);
5062 if (!crtc_state->ips_enabled)
5066 * We can only enable IPS after we enable a plane and wait for a vblank
5067 * This function is called from post_plane_update, which is run after
5070 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5072 if (IS_BROADWELL(dev_priv)) {
5073 mutex_lock(&dev_priv->pcu_lock);
5074 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5075 IPS_ENABLE | IPS_PCODE_CONTROL));
5076 mutex_unlock(&dev_priv->pcu_lock);
5077 /* Quoting Art Runyan: "its not safe to expect any particular
5078 * value in IPS_CTL bit 31 after enabling IPS through the
5079 * mailbox." Moreover, the mailbox may return a bogus state,
5080 * so we need to just enable it and continue on.
5083 I915_WRITE(IPS_CTL, IPS_ENABLE);
5084 /* The bit only becomes 1 in the next vblank, so this wait here
5085 * is essentially intel_wait_for_vblank. If we don't have this
5086 * and don't wait for vblanks until the end of crtc_enable, then
5087 * the HW state readout code will complain that the expected
5088 * IPS_CTL value is not the one we read. */
5089 if (intel_wait_for_register(dev_priv,
5090 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5092 DRM_ERROR("Timed out waiting for IPS enable\n");
5096 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5098 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5099 struct drm_device *dev = crtc->base.dev;
5100 struct drm_i915_private *dev_priv = to_i915(dev);
5102 if (!crtc_state->ips_enabled)
5105 if (IS_BROADWELL(dev_priv)) {
5106 mutex_lock(&dev_priv->pcu_lock);
5107 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5108 mutex_unlock(&dev_priv->pcu_lock);
5110 * Wait for PCODE to finish disabling IPS. The BSpec specified
5111 * 42ms timeout value leads to occasional timeouts so use 100ms
5114 if (intel_wait_for_register(dev_priv,
5115 IPS_CTL, IPS_ENABLE, 0,
5117 DRM_ERROR("Timed out waiting for IPS disable\n");
5119 I915_WRITE(IPS_CTL, 0);
5120 POSTING_READ(IPS_CTL);
5123 /* We need to wait for a vblank before we can disable the plane. */
5124 intel_wait_for_vblank(dev_priv, crtc->pipe);
5127 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5129 if (intel_crtc->overlay) {
5130 struct drm_device *dev = intel_crtc->base.dev;
5132 mutex_lock(&dev->struct_mutex);
5133 (void) intel_overlay_switch_off(intel_crtc->overlay);
5134 mutex_unlock(&dev->struct_mutex);
5137 /* Let userspace switch the overlay on again. In most cases userspace
5138 * has to recompute where to put it anyway.
5143 * intel_post_enable_primary - Perform operations after enabling primary plane
5144 * @crtc: the CRTC whose primary plane was just enabled
5145 * @new_crtc_state: the enabling state
5147 * Performs potentially sleeping operations that must be done after the primary
5148 * plane is enabled, such as updating FBC and IPS. Note that this may be
5149 * called due to an explicit primary plane update, or due to an implicit
5150 * re-enable that is caused when a sprite plane is updated to no longer
5151 * completely hide the primary plane.
5154 intel_post_enable_primary(struct drm_crtc *crtc,
5155 const struct intel_crtc_state *new_crtc_state)
5157 struct drm_device *dev = crtc->dev;
5158 struct drm_i915_private *dev_priv = to_i915(dev);
5159 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5160 int pipe = intel_crtc->pipe;
5163 * Gen2 reports pipe underruns whenever all planes are disabled.
5164 * So don't enable underrun reporting before at least some planes
5166 * FIXME: Need to fix the logic to work when we turn off all planes
5167 * but leave the pipe running.
5169 if (IS_GEN2(dev_priv))
5170 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5172 /* Underruns don't always raise interrupts, so check manually. */
5173 intel_check_cpu_fifo_underruns(dev_priv);
5174 intel_check_pch_fifo_underruns(dev_priv);
5177 /* FIXME get rid of this and use pre_plane_update */
5179 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5181 struct drm_device *dev = crtc->dev;
5182 struct drm_i915_private *dev_priv = to_i915(dev);
5183 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5184 int pipe = intel_crtc->pipe;
5187 * Gen2 reports pipe underruns whenever all planes are disabled.
5188 * So disable underrun reporting before all the planes get disabled.
5190 if (IS_GEN2(dev_priv))
5191 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5193 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5196 * Vblank time updates from the shadow to live plane control register
5197 * are blocked if the memory self-refresh mode is active at that
5198 * moment. So to make sure the plane gets truly disabled, disable
5199 * first the self-refresh mode. The self-refresh enable bit in turn
5200 * will be checked/applied by the HW only at the next frame start
5201 * event which is after the vblank start event, so we need to have a
5202 * wait-for-vblank between disabling the plane and the pipe.
5204 if (HAS_GMCH_DISPLAY(dev_priv) &&
5205 intel_set_memory_cxsr(dev_priv, false))
5206 intel_wait_for_vblank(dev_priv, pipe);
5209 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5210 const struct intel_crtc_state *new_crtc_state)
5212 if (!old_crtc_state->ips_enabled)
5215 if (needs_modeset(&new_crtc_state->base))
5218 return !new_crtc_state->ips_enabled;
5221 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5222 const struct intel_crtc_state *new_crtc_state)
5224 if (!new_crtc_state->ips_enabled)
5227 if (needs_modeset(&new_crtc_state->base))
5231 * We can't read out IPS on broadwell, assume the worst and
5232 * forcibly enable IPS on the first fastset.
5234 if (new_crtc_state->update_pipe &&
5235 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5238 return !old_crtc_state->ips_enabled;
5241 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5242 const struct intel_crtc_state *crtc_state)
5244 if (!crtc_state->nv12_planes)
5247 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
5250 if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
5251 IS_CANNONLAKE(dev_priv))
5257 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5259 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5260 struct drm_device *dev = crtc->base.dev;
5261 struct drm_i915_private *dev_priv = to_i915(dev);
5262 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5263 struct intel_crtc_state *pipe_config =
5264 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5266 struct drm_plane *primary = crtc->base.primary;
5267 struct drm_plane_state *old_primary_state =
5268 drm_atomic_get_old_plane_state(old_state, primary);
5270 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5272 if (pipe_config->update_wm_post && pipe_config->base.active)
5273 intel_update_watermarks(crtc);
5275 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5276 hsw_enable_ips(pipe_config);
5278 if (old_primary_state) {
5279 struct drm_plane_state *new_primary_state =
5280 drm_atomic_get_new_plane_state(old_state, primary);
5282 intel_fbc_post_update(crtc);
5284 if (new_primary_state->visible &&
5285 (needs_modeset(&pipe_config->base) ||
5286 !old_primary_state->visible))
5287 intel_post_enable_primary(&crtc->base, pipe_config);
5290 /* Display WA 827 */
5291 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5292 !needs_nv12_wa(dev_priv, pipe_config)) {
5293 skl_wa_clkgate(dev_priv, crtc->pipe, false);
5294 skl_wa_528(dev_priv, crtc->pipe, false);
5298 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5299 struct intel_crtc_state *pipe_config)
5301 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5302 struct drm_device *dev = crtc->base.dev;
5303 struct drm_i915_private *dev_priv = to_i915(dev);
5304 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5305 struct drm_plane *primary = crtc->base.primary;
5306 struct drm_plane_state *old_primary_state =
5307 drm_atomic_get_old_plane_state(old_state, primary);
5308 bool modeset = needs_modeset(&pipe_config->base);
5309 struct intel_atomic_state *old_intel_state =
5310 to_intel_atomic_state(old_state);
5312 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5313 hsw_disable_ips(old_crtc_state);
5315 if (old_primary_state) {
5316 struct intel_plane_state *new_primary_state =
5317 intel_atomic_get_new_plane_state(old_intel_state,
5318 to_intel_plane(primary));
5320 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5322 * Gen2 reports pipe underruns whenever all planes are disabled.
5323 * So disable underrun reporting before all the planes get disabled.
5325 if (IS_GEN2(dev_priv) && old_primary_state->visible &&
5326 (modeset || !new_primary_state->base.visible))
5327 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5330 /* Display WA 827 */
5331 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5332 needs_nv12_wa(dev_priv, pipe_config)) {
5333 skl_wa_clkgate(dev_priv, crtc->pipe, true);
5334 skl_wa_528(dev_priv, crtc->pipe, true);
5338 * Vblank time updates from the shadow to live plane control register
5339 * are blocked if the memory self-refresh mode is active at that
5340 * moment. So to make sure the plane gets truly disabled, disable
5341 * first the self-refresh mode. The self-refresh enable bit in turn
5342 * will be checked/applied by the HW only at the next frame start
5343 * event which is after the vblank start event, so we need to have a
5344 * wait-for-vblank between disabling the plane and the pipe.
5346 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5347 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5348 intel_wait_for_vblank(dev_priv, crtc->pipe);
5351 * IVB workaround: must disable low power watermarks for at least
5352 * one frame before enabling scaling. LP watermarks can be re-enabled
5353 * when scaling is disabled.
5355 * WaCxSRDisabledForSpriteScaling:ivb
5357 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5358 old_crtc_state->base.active)
5359 intel_wait_for_vblank(dev_priv, crtc->pipe);
5362 * If we're doing a modeset, we're done. No need to do any pre-vblank
5363 * watermark programming here.
5365 if (needs_modeset(&pipe_config->base))
5369 * For platforms that support atomic watermarks, program the
5370 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5371 * will be the intermediate values that are safe for both pre- and
5372 * post- vblank; when vblank happens, the 'active' values will be set
5373 * to the final 'target' values and we'll do this again to get the
5374 * optimal watermarks. For gen9+ platforms, the values we program here
5375 * will be the final target values which will get automatically latched
5376 * at vblank time; no further programming will be necessary.
5378 * If a platform hasn't been transitioned to atomic watermarks yet,
5379 * we'll continue to update watermarks the old way, if flags tell
5382 if (dev_priv->display.initial_watermarks != NULL)
5383 dev_priv->display.initial_watermarks(old_intel_state,
5385 else if (pipe_config->update_wm_pre)
5386 intel_update_watermarks(crtc);
5389 static void intel_crtc_disable_planes(struct intel_crtc *crtc, unsigned plane_mask)
5391 struct drm_device *dev = crtc->base.dev;
5392 struct intel_plane *plane;
5393 unsigned fb_bits = 0;
5395 intel_crtc_dpms_overlay_disable(crtc);
5397 for_each_intel_plane_on_crtc(dev, crtc, plane) {
5398 if (plane_mask & BIT(plane->id)) {
5399 plane->disable_plane(plane, crtc);
5401 fb_bits |= plane->frontbuffer_bit;
5405 intel_frontbuffer_flip(to_i915(dev), fb_bits);
5408 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5409 struct intel_crtc_state *crtc_state,
5410 struct drm_atomic_state *old_state)
5412 struct drm_connector_state *conn_state;
5413 struct drm_connector *conn;
5416 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5417 struct intel_encoder *encoder =
5418 to_intel_encoder(conn_state->best_encoder);
5420 if (conn_state->crtc != crtc)
5423 if (encoder->pre_pll_enable)
5424 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5428 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5429 struct intel_crtc_state *crtc_state,
5430 struct drm_atomic_state *old_state)
5432 struct drm_connector_state *conn_state;
5433 struct drm_connector *conn;
5436 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5437 struct intel_encoder *encoder =
5438 to_intel_encoder(conn_state->best_encoder);
5440 if (conn_state->crtc != crtc)
5443 if (encoder->pre_enable)
5444 encoder->pre_enable(encoder, crtc_state, conn_state);
5448 static void intel_encoders_enable(struct drm_crtc *crtc,
5449 struct intel_crtc_state *crtc_state,
5450 struct drm_atomic_state *old_state)
5452 struct drm_connector_state *conn_state;
5453 struct drm_connector *conn;
5456 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5457 struct intel_encoder *encoder =
5458 to_intel_encoder(conn_state->best_encoder);
5460 if (conn_state->crtc != crtc)
5463 encoder->enable(encoder, crtc_state, conn_state);
5464 intel_opregion_notify_encoder(encoder, true);
5468 static void intel_encoders_disable(struct drm_crtc *crtc,
5469 struct intel_crtc_state *old_crtc_state,
5470 struct drm_atomic_state *old_state)
5472 struct drm_connector_state *old_conn_state;
5473 struct drm_connector *conn;
5476 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5477 struct intel_encoder *encoder =
5478 to_intel_encoder(old_conn_state->best_encoder);
5480 if (old_conn_state->crtc != crtc)
5483 intel_opregion_notify_encoder(encoder, false);
5484 encoder->disable(encoder, old_crtc_state, old_conn_state);
5488 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5489 struct intel_crtc_state *old_crtc_state,
5490 struct drm_atomic_state *old_state)
5492 struct drm_connector_state *old_conn_state;
5493 struct drm_connector *conn;
5496 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5497 struct intel_encoder *encoder =
5498 to_intel_encoder(old_conn_state->best_encoder);
5500 if (old_conn_state->crtc != crtc)
5503 if (encoder->post_disable)
5504 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5508 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5509 struct intel_crtc_state *old_crtc_state,
5510 struct drm_atomic_state *old_state)
5512 struct drm_connector_state *old_conn_state;
5513 struct drm_connector *conn;
5516 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5517 struct intel_encoder *encoder =
5518 to_intel_encoder(old_conn_state->best_encoder);
5520 if (old_conn_state->crtc != crtc)
5523 if (encoder->post_pll_disable)
5524 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5528 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5529 struct drm_atomic_state *old_state)
5531 struct drm_crtc *crtc = pipe_config->base.crtc;
5532 struct drm_device *dev = crtc->dev;
5533 struct drm_i915_private *dev_priv = to_i915(dev);
5534 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5535 int pipe = intel_crtc->pipe;
5536 struct intel_atomic_state *old_intel_state =
5537 to_intel_atomic_state(old_state);
5539 if (WARN_ON(intel_crtc->active))
5543 * Sometimes spurious CPU pipe underruns happen during FDI
5544 * training, at least with VGA+HDMI cloning. Suppress them.
5546 * On ILK we get an occasional spurious CPU pipe underruns
5547 * between eDP port A enable and vdd enable. Also PCH port
5548 * enable seems to result in the occasional CPU pipe underrun.
5550 * Spurious PCH underruns also occur during PCH enabling.
5552 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5553 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5555 if (pipe_config->has_pch_encoder)
5556 intel_prepare_shared_dpll(pipe_config);
5558 if (intel_crtc_has_dp_encoder(pipe_config))
5559 intel_dp_set_m_n(intel_crtc, M1_N1);
5561 intel_set_pipe_timings(pipe_config);
5562 intel_set_pipe_src_size(pipe_config);
5564 if (pipe_config->has_pch_encoder) {
5565 intel_cpu_transcoder_set_m_n(intel_crtc,
5566 &pipe_config->fdi_m_n, NULL);
5569 ironlake_set_pipeconf(pipe_config);
5571 intel_crtc->active = true;
5573 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5575 if (pipe_config->has_pch_encoder) {
5576 /* Note: FDI PLL enabling _must_ be done before we enable the
5577 * cpu pipes, hence this is separate from all the other fdi/pch
5579 ironlake_fdi_pll_enable(pipe_config);
5581 assert_fdi_tx_disabled(dev_priv, pipe);
5582 assert_fdi_rx_disabled(dev_priv, pipe);
5585 ironlake_pfit_enable(pipe_config);
5588 * On ILK+ LUT must be loaded before the pipe is running but with
5591 intel_color_load_luts(&pipe_config->base);
5593 if (dev_priv->display.initial_watermarks != NULL)
5594 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5595 intel_enable_pipe(pipe_config);
5597 if (pipe_config->has_pch_encoder)
5598 ironlake_pch_enable(old_intel_state, pipe_config);
5600 assert_vblank_disabled(crtc);
5601 drm_crtc_vblank_on(crtc);
5603 intel_encoders_enable(crtc, pipe_config, old_state);
5605 if (HAS_PCH_CPT(dev_priv))
5606 cpt_verify_modeset(dev, intel_crtc->pipe);
5609 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5610 * And a second vblank wait is needed at least on ILK with
5611 * some interlaced HDMI modes. Let's do the double wait always
5612 * in case there are more corner cases we don't know about.
5614 if (pipe_config->has_pch_encoder) {
5615 intel_wait_for_vblank(dev_priv, pipe);
5616 intel_wait_for_vblank(dev_priv, pipe);
5618 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5619 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5622 /* IPS only exists on ULT machines and is tied to pipe A. */
5623 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5625 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5628 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5629 enum pipe pipe, bool apply)
5631 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5632 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5639 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5642 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5644 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5645 enum pipe pipe = crtc->pipe;
5648 val = MBUS_DBOX_A_CREDIT(2);
5649 val |= MBUS_DBOX_BW_CREDIT(1);
5650 val |= MBUS_DBOX_B_CREDIT(8);
5652 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5655 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5656 struct drm_atomic_state *old_state)
5658 struct drm_crtc *crtc = pipe_config->base.crtc;
5659 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5660 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5661 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5662 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
5663 struct intel_atomic_state *old_intel_state =
5664 to_intel_atomic_state(old_state);
5665 bool psl_clkgate_wa;
5668 if (WARN_ON(intel_crtc->active))
5671 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5673 if (pipe_config->shared_dpll)
5674 intel_enable_shared_dpll(pipe_config);
5676 if (INTEL_GEN(dev_priv) >= 11)
5677 icl_map_plls_to_ports(crtc, pipe_config, old_state);
5679 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5681 if (intel_crtc_has_dp_encoder(pipe_config))
5682 intel_dp_set_m_n(intel_crtc, M1_N1);
5684 if (!transcoder_is_dsi(cpu_transcoder))
5685 intel_set_pipe_timings(pipe_config);
5687 intel_set_pipe_src_size(pipe_config);
5689 if (cpu_transcoder != TRANSCODER_EDP &&
5690 !transcoder_is_dsi(cpu_transcoder)) {
5691 I915_WRITE(PIPE_MULT(cpu_transcoder),
5692 pipe_config->pixel_multiplier - 1);
5695 if (pipe_config->has_pch_encoder) {
5696 intel_cpu_transcoder_set_m_n(intel_crtc,
5697 &pipe_config->fdi_m_n, NULL);
5700 if (!transcoder_is_dsi(cpu_transcoder))
5701 haswell_set_pipeconf(pipe_config);
5703 haswell_set_pipemisc(pipe_config);
5705 intel_color_set_csc(&pipe_config->base);
5707 intel_crtc->active = true;
5709 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5710 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5711 pipe_config->pch_pfit.enabled;
5713 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5715 if (INTEL_GEN(dev_priv) >= 9)
5716 skylake_pfit_enable(pipe_config);
5718 ironlake_pfit_enable(pipe_config);
5721 * On ILK+ LUT must be loaded before the pipe is running but with
5724 intel_color_load_luts(&pipe_config->base);
5727 * Display WA #1153: enable hardware to bypass the alpha math
5728 * and rounding for per-pixel values 00 and 0xff
5730 if (INTEL_GEN(dev_priv) >= 11) {
5731 pipe_chicken = I915_READ(PIPE_CHICKEN(pipe));
5732 if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN))
5733 I915_WRITE_FW(PIPE_CHICKEN(pipe),
5734 pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN);
5737 intel_ddi_set_pipe_settings(pipe_config);
5738 if (!transcoder_is_dsi(cpu_transcoder))
5739 intel_ddi_enable_transcoder_func(pipe_config);
5741 if (dev_priv->display.initial_watermarks != NULL)
5742 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5744 if (INTEL_GEN(dev_priv) >= 11)
5745 icl_pipe_mbus_enable(intel_crtc);
5747 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5748 if (!transcoder_is_dsi(cpu_transcoder))
5749 intel_enable_pipe(pipe_config);
5751 if (pipe_config->has_pch_encoder)
5752 lpt_pch_enable(old_intel_state, pipe_config);
5754 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
5755 intel_ddi_set_vc_payload_alloc(pipe_config, true);
5757 assert_vblank_disabled(crtc);
5758 drm_crtc_vblank_on(crtc);
5760 intel_encoders_enable(crtc, pipe_config, old_state);
5762 if (psl_clkgate_wa) {
5763 intel_wait_for_vblank(dev_priv, pipe);
5764 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5767 /* If we change the relative order between pipe/planes enabling, we need
5768 * to change the workaround. */
5769 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
5770 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5771 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5772 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5776 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
5778 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5779 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5780 enum pipe pipe = crtc->pipe;
5782 /* To avoid upsetting the power well on haswell only disable the pfit if
5783 * it's in use. The hw state code will make sure we get this right. */
5784 if (old_crtc_state->pch_pfit.enabled) {
5785 I915_WRITE(PF_CTL(pipe), 0);
5786 I915_WRITE(PF_WIN_POS(pipe), 0);
5787 I915_WRITE(PF_WIN_SZ(pipe), 0);
5791 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5792 struct drm_atomic_state *old_state)
5794 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5795 struct drm_device *dev = crtc->dev;
5796 struct drm_i915_private *dev_priv = to_i915(dev);
5797 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5798 int pipe = intel_crtc->pipe;
5801 * Sometimes spurious CPU pipe underruns happen when the
5802 * pipe is already disabled, but FDI RX/TX is still enabled.
5803 * Happens at least with VGA+HDMI cloning. Suppress them.
5805 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5806 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5808 intel_encoders_disable(crtc, old_crtc_state, old_state);
5810 drm_crtc_vblank_off(crtc);
5811 assert_vblank_disabled(crtc);
5813 intel_disable_pipe(old_crtc_state);
5815 ironlake_pfit_disable(old_crtc_state);
5817 if (old_crtc_state->has_pch_encoder)
5818 ironlake_fdi_disable(crtc);
5820 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5822 if (old_crtc_state->has_pch_encoder) {
5823 ironlake_disable_pch_transcoder(dev_priv, pipe);
5825 if (HAS_PCH_CPT(dev_priv)) {
5829 /* disable TRANS_DP_CTL */
5830 reg = TRANS_DP_CTL(pipe);
5831 temp = I915_READ(reg);
5832 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5833 TRANS_DP_PORT_SEL_MASK);
5834 temp |= TRANS_DP_PORT_SEL_NONE;
5835 I915_WRITE(reg, temp);
5837 /* disable DPLL_SEL */
5838 temp = I915_READ(PCH_DPLL_SEL);
5839 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5840 I915_WRITE(PCH_DPLL_SEL, temp);
5843 ironlake_fdi_pll_disable(intel_crtc);
5846 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5847 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5850 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5851 struct drm_atomic_state *old_state)
5853 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5854 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5855 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5856 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
5858 intel_encoders_disable(crtc, old_crtc_state, old_state);
5860 drm_crtc_vblank_off(crtc);
5861 assert_vblank_disabled(crtc);
5863 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5864 if (!transcoder_is_dsi(cpu_transcoder))
5865 intel_disable_pipe(old_crtc_state);
5867 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
5868 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
5870 if (!transcoder_is_dsi(cpu_transcoder))
5871 intel_ddi_disable_transcoder_func(old_crtc_state);
5873 if (INTEL_GEN(dev_priv) >= 9)
5874 skylake_scaler_disable(intel_crtc);
5876 ironlake_pfit_disable(old_crtc_state);
5878 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5880 if (INTEL_GEN(dev_priv) >= 11)
5881 icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state);
5884 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
5886 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5887 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5889 if (!crtc_state->gmch_pfit.control)
5893 * The panel fitter should only be adjusted whilst the pipe is disabled,
5894 * according to register description and PRM.
5896 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5897 assert_pipe_disabled(dev_priv, crtc->pipe);
5899 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
5900 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
5902 /* Border color in case we don't scale up to the full screen. Black by
5903 * default, change to something else for debugging. */
5904 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5907 bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
5909 if (IS_ICELAKE(dev_priv))
5910 return port >= PORT_C && port <= PORT_F;
5915 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
5917 if (!intel_port_is_tc(dev_priv, port))
5918 return PORT_TC_NONE;
5920 return port - PORT_C;
5923 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
5927 return POWER_DOMAIN_PORT_DDI_A_LANES;
5929 return POWER_DOMAIN_PORT_DDI_B_LANES;
5931 return POWER_DOMAIN_PORT_DDI_C_LANES;
5933 return POWER_DOMAIN_PORT_DDI_D_LANES;
5935 return POWER_DOMAIN_PORT_DDI_E_LANES;
5937 return POWER_DOMAIN_PORT_DDI_F_LANES;
5940 return POWER_DOMAIN_PORT_OTHER;
5944 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
5945 struct intel_crtc_state *crtc_state)
5947 struct drm_device *dev = crtc->dev;
5948 struct drm_i915_private *dev_priv = to_i915(dev);
5949 struct drm_encoder *encoder;
5950 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5951 enum pipe pipe = intel_crtc->pipe;
5953 enum transcoder transcoder = crtc_state->cpu_transcoder;
5955 if (!crtc_state->base.active)
5958 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
5959 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
5960 if (crtc_state->pch_pfit.enabled ||
5961 crtc_state->pch_pfit.force_thru)
5962 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5964 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
5965 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5967 mask |= BIT_ULL(intel_encoder->power_domain);
5970 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
5971 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
5973 if (crtc_state->shared_dpll)
5974 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
5980 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
5981 struct intel_crtc_state *crtc_state)
5983 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5984 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5985 enum intel_display_power_domain domain;
5986 u64 domains, new_domains, old_domains;
5988 old_domains = intel_crtc->enabled_power_domains;
5989 intel_crtc->enabled_power_domains = new_domains =
5990 get_crtc_power_domains(crtc, crtc_state);
5992 domains = new_domains & ~old_domains;
5994 for_each_power_domain(domain, domains)
5995 intel_display_power_get(dev_priv, domain);
5997 return old_domains & ~new_domains;
6000 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6003 enum intel_display_power_domain domain;
6005 for_each_power_domain(domain, domains)
6006 intel_display_power_put(dev_priv, domain);
6009 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6010 struct drm_atomic_state *old_state)
6012 struct intel_atomic_state *old_intel_state =
6013 to_intel_atomic_state(old_state);
6014 struct drm_crtc *crtc = pipe_config->base.crtc;
6015 struct drm_device *dev = crtc->dev;
6016 struct drm_i915_private *dev_priv = to_i915(dev);
6017 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6018 int pipe = intel_crtc->pipe;
6020 if (WARN_ON(intel_crtc->active))
6023 if (intel_crtc_has_dp_encoder(pipe_config))
6024 intel_dp_set_m_n(intel_crtc, M1_N1);
6026 intel_set_pipe_timings(pipe_config);
6027 intel_set_pipe_src_size(pipe_config);
6029 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6030 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6031 I915_WRITE(CHV_CANVAS(pipe), 0);
6034 i9xx_set_pipeconf(pipe_config);
6036 intel_color_set_csc(&pipe_config->base);
6038 intel_crtc->active = true;
6040 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6042 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
6044 if (IS_CHERRYVIEW(dev_priv)) {
6045 chv_prepare_pll(intel_crtc, pipe_config);
6046 chv_enable_pll(intel_crtc, pipe_config);
6048 vlv_prepare_pll(intel_crtc, pipe_config);
6049 vlv_enable_pll(intel_crtc, pipe_config);
6052 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6054 i9xx_pfit_enable(pipe_config);
6056 intel_color_load_luts(&pipe_config->base);
6058 dev_priv->display.initial_watermarks(old_intel_state,
6060 intel_enable_pipe(pipe_config);
6062 assert_vblank_disabled(crtc);
6063 drm_crtc_vblank_on(crtc);
6065 intel_encoders_enable(crtc, pipe_config, old_state);
6068 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
6070 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6071 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6073 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6074 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
6077 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6078 struct drm_atomic_state *old_state)
6080 struct intel_atomic_state *old_intel_state =
6081 to_intel_atomic_state(old_state);
6082 struct drm_crtc *crtc = pipe_config->base.crtc;
6083 struct drm_device *dev = crtc->dev;
6084 struct drm_i915_private *dev_priv = to_i915(dev);
6085 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6086 enum pipe pipe = intel_crtc->pipe;
6088 if (WARN_ON(intel_crtc->active))
6091 i9xx_set_pll_dividers(pipe_config);
6093 if (intel_crtc_has_dp_encoder(pipe_config))
6094 intel_dp_set_m_n(intel_crtc, M1_N1);
6096 intel_set_pipe_timings(pipe_config);
6097 intel_set_pipe_src_size(pipe_config);
6099 i9xx_set_pipeconf(pipe_config);
6101 intel_crtc->active = true;
6103 if (!IS_GEN2(dev_priv))
6104 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6106 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6108 i9xx_enable_pll(intel_crtc, pipe_config);
6110 i9xx_pfit_enable(pipe_config);
6112 intel_color_load_luts(&pipe_config->base);
6114 if (dev_priv->display.initial_watermarks != NULL)
6115 dev_priv->display.initial_watermarks(old_intel_state,
6118 intel_update_watermarks(intel_crtc);
6119 intel_enable_pipe(pipe_config);
6121 assert_vblank_disabled(crtc);
6122 drm_crtc_vblank_on(crtc);
6124 intel_encoders_enable(crtc, pipe_config, old_state);
6127 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6129 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6130 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6132 if (!old_crtc_state->gmch_pfit.control)
6135 assert_pipe_disabled(dev_priv, crtc->pipe);
6137 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6138 I915_READ(PFIT_CONTROL));
6139 I915_WRITE(PFIT_CONTROL, 0);
6142 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6143 struct drm_atomic_state *old_state)
6145 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6146 struct drm_device *dev = crtc->dev;
6147 struct drm_i915_private *dev_priv = to_i915(dev);
6148 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6149 int pipe = intel_crtc->pipe;
6152 * On gen2 planes are double buffered but the pipe isn't, so we must
6153 * wait for planes to fully turn off before disabling the pipe.
6155 if (IS_GEN2(dev_priv))
6156 intel_wait_for_vblank(dev_priv, pipe);
6158 intel_encoders_disable(crtc, old_crtc_state, old_state);
6160 drm_crtc_vblank_off(crtc);
6161 assert_vblank_disabled(crtc);
6163 intel_disable_pipe(old_crtc_state);
6165 i9xx_pfit_disable(old_crtc_state);
6167 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6169 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
6170 if (IS_CHERRYVIEW(dev_priv))
6171 chv_disable_pll(dev_priv, pipe);
6172 else if (IS_VALLEYVIEW(dev_priv))
6173 vlv_disable_pll(dev_priv, pipe);
6175 i9xx_disable_pll(old_crtc_state);
6178 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6180 if (!IS_GEN2(dev_priv))
6181 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6183 if (!dev_priv->display.initial_watermarks)
6184 intel_update_watermarks(intel_crtc);
6186 /* clock the pipe down to 640x480@60 to potentially save power */
6187 if (IS_I830(dev_priv))
6188 i830_enable_pipe(dev_priv, pipe);
6191 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6192 struct drm_modeset_acquire_ctx *ctx)
6194 struct intel_encoder *encoder;
6195 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6196 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6197 enum intel_display_power_domain domain;
6198 struct intel_plane *plane;
6200 struct drm_atomic_state *state;
6201 struct intel_crtc_state *crtc_state;
6204 if (!intel_crtc->active)
6207 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6208 const struct intel_plane_state *plane_state =
6209 to_intel_plane_state(plane->base.state);
6211 if (plane_state->base.visible)
6212 intel_plane_disable_noatomic(intel_crtc, plane);
6215 state = drm_atomic_state_alloc(crtc->dev);
6217 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6218 crtc->base.id, crtc->name);
6222 state->acquire_ctx = ctx;
6224 /* Everything's already locked, -EDEADLK can't happen. */
6225 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6226 ret = drm_atomic_add_affected_connectors(state, crtc);
6228 WARN_ON(IS_ERR(crtc_state) || ret);
6230 dev_priv->display.crtc_disable(crtc_state, state);
6232 drm_atomic_state_put(state);
6234 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6235 crtc->base.id, crtc->name);
6237 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6238 crtc->state->active = false;
6239 intel_crtc->active = false;
6240 crtc->enabled = false;
6241 crtc->state->connector_mask = 0;
6242 crtc->state->encoder_mask = 0;
6244 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6245 encoder->base.crtc = NULL;
6247 intel_fbc_disable(intel_crtc);
6248 intel_update_watermarks(intel_crtc);
6249 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
6251 domains = intel_crtc->enabled_power_domains;
6252 for_each_power_domain(domain, domains)
6253 intel_display_power_put(dev_priv, domain);
6254 intel_crtc->enabled_power_domains = 0;
6256 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6257 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6258 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6262 * turn all crtc's off, but do not adjust state
6263 * This has to be paired with a call to intel_modeset_setup_hw_state.
6265 int intel_display_suspend(struct drm_device *dev)
6267 struct drm_i915_private *dev_priv = to_i915(dev);
6268 struct drm_atomic_state *state;
6271 state = drm_atomic_helper_suspend(dev);
6272 ret = PTR_ERR_OR_ZERO(state);
6274 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6276 dev_priv->modeset_restore_state = state;
6280 void intel_encoder_destroy(struct drm_encoder *encoder)
6282 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6284 drm_encoder_cleanup(encoder);
6285 kfree(intel_encoder);
6288 /* Cross check the actual hw state with our own modeset state tracking (and it's
6289 * internal consistency). */
6290 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6291 struct drm_connector_state *conn_state)
6293 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6295 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6296 connector->base.base.id,
6297 connector->base.name);
6299 if (connector->get_hw_state(connector)) {
6300 struct intel_encoder *encoder = connector->encoder;
6302 I915_STATE_WARN(!crtc_state,
6303 "connector enabled without attached crtc\n");
6308 I915_STATE_WARN(!crtc_state->active,
6309 "connector is active, but attached crtc isn't\n");
6311 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6314 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6315 "atomic encoder doesn't match attached encoder\n");
6317 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6318 "attached encoder crtc differs from connector crtc\n");
6320 I915_STATE_WARN(crtc_state && crtc_state->active,
6321 "attached crtc is active, but connector isn't\n");
6322 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6323 "best encoder set without crtc!\n");
6327 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6329 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6330 return crtc_state->fdi_lanes;
6335 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6336 struct intel_crtc_state *pipe_config)
6338 struct drm_i915_private *dev_priv = to_i915(dev);
6339 struct drm_atomic_state *state = pipe_config->base.state;
6340 struct intel_crtc *other_crtc;
6341 struct intel_crtc_state *other_crtc_state;
6343 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6344 pipe_name(pipe), pipe_config->fdi_lanes);
6345 if (pipe_config->fdi_lanes > 4) {
6346 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6347 pipe_name(pipe), pipe_config->fdi_lanes);
6351 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6352 if (pipe_config->fdi_lanes > 2) {
6353 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6354 pipe_config->fdi_lanes);
6361 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6364 /* Ivybridge 3 pipe is really complicated */
6369 if (pipe_config->fdi_lanes <= 2)
6372 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6374 intel_atomic_get_crtc_state(state, other_crtc);
6375 if (IS_ERR(other_crtc_state))
6376 return PTR_ERR(other_crtc_state);
6378 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6379 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6380 pipe_name(pipe), pipe_config->fdi_lanes);
6385 if (pipe_config->fdi_lanes > 2) {
6386 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6387 pipe_name(pipe), pipe_config->fdi_lanes);
6391 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6393 intel_atomic_get_crtc_state(state, other_crtc);
6394 if (IS_ERR(other_crtc_state))
6395 return PTR_ERR(other_crtc_state);
6397 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6398 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6408 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6409 struct intel_crtc_state *pipe_config)
6411 struct drm_device *dev = intel_crtc->base.dev;
6412 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6413 int lane, link_bw, fdi_dotclock, ret;
6414 bool needs_recompute = false;
6417 /* FDI is a binary signal running at ~2.7GHz, encoding
6418 * each output octet as 10 bits. The actual frequency
6419 * is stored as a divider into a 100MHz clock, and the
6420 * mode pixel clock is stored in units of 1KHz.
6421 * Hence the bw of each lane in terms of the mode signal
6424 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6426 fdi_dotclock = adjusted_mode->crtc_clock;
6428 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6429 pipe_config->pipe_bpp);
6431 pipe_config->fdi_lanes = lane;
6433 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6434 link_bw, &pipe_config->fdi_m_n, false);
6436 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6437 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6438 pipe_config->pipe_bpp -= 2*3;
6439 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6440 pipe_config->pipe_bpp);
6441 needs_recompute = true;
6442 pipe_config->bw_constrained = true;
6447 if (needs_recompute)
6453 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6455 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6456 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6458 /* IPS only exists on ULT machines and is tied to pipe A. */
6459 if (!hsw_crtc_supports_ips(crtc))
6462 if (!i915_modparams.enable_ips)
6465 if (crtc_state->pipe_bpp > 24)
6469 * We compare against max which means we must take
6470 * the increased cdclk requirement into account when
6471 * calculating the new cdclk.
6473 * Should measure whether using a lower cdclk w/o IPS
6475 if (IS_BROADWELL(dev_priv) &&
6476 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6482 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6484 struct drm_i915_private *dev_priv =
6485 to_i915(crtc_state->base.crtc->dev);
6486 struct intel_atomic_state *intel_state =
6487 to_intel_atomic_state(crtc_state->base.state);
6489 if (!hsw_crtc_state_ips_capable(crtc_state))
6492 if (crtc_state->ips_force_disable)
6495 /* IPS should be fine as long as at least one plane is enabled. */
6496 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6499 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6500 if (IS_BROADWELL(dev_priv) &&
6501 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6507 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6509 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6511 /* GDG double wide on either pipe, otherwise pipe A only */
6512 return INTEL_GEN(dev_priv) < 4 &&
6513 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6516 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6518 uint32_t pixel_rate;
6520 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6523 * We only use IF-ID interlacing. If we ever use
6524 * PF-ID we'll need to adjust the pixel_rate here.
6527 if (pipe_config->pch_pfit.enabled) {
6528 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6529 uint32_t pfit_size = pipe_config->pch_pfit.size;
6531 pipe_w = pipe_config->pipe_src_w;
6532 pipe_h = pipe_config->pipe_src_h;
6534 pfit_w = (pfit_size >> 16) & 0xFFFF;
6535 pfit_h = pfit_size & 0xFFFF;
6536 if (pipe_w < pfit_w)
6538 if (pipe_h < pfit_h)
6541 if (WARN_ON(!pfit_w || !pfit_h))
6544 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6551 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6553 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6555 if (HAS_GMCH_DISPLAY(dev_priv))
6556 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6557 crtc_state->pixel_rate =
6558 crtc_state->base.adjusted_mode.crtc_clock;
6560 crtc_state->pixel_rate =
6561 ilk_pipe_pixel_rate(crtc_state);
6564 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6565 struct intel_crtc_state *pipe_config)
6567 struct drm_device *dev = crtc->base.dev;
6568 struct drm_i915_private *dev_priv = to_i915(dev);
6569 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6570 int clock_limit = dev_priv->max_dotclk_freq;
6572 if (INTEL_GEN(dev_priv) < 4) {
6573 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6576 * Enable double wide mode when the dot clock
6577 * is > 90% of the (display) core speed.
6579 if (intel_crtc_supports_double_wide(crtc) &&
6580 adjusted_mode->crtc_clock > clock_limit) {
6581 clock_limit = dev_priv->max_dotclk_freq;
6582 pipe_config->double_wide = true;
6586 if (adjusted_mode->crtc_clock > clock_limit) {
6587 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6588 adjusted_mode->crtc_clock, clock_limit,
6589 yesno(pipe_config->double_wide));
6593 if (pipe_config->ycbcr420 && pipe_config->base.ctm) {
6595 * There is only one pipe CSC unit per pipe, and we need that
6596 * for output conversion from RGB->YCBCR. So if CTM is already
6597 * applied we can't support YCBCR420 output.
6599 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6604 * Pipe horizontal size must be even in:
6606 * - LVDS dual channel mode
6607 * - Double wide pipe
6609 if (pipe_config->pipe_src_w & 1) {
6610 if (pipe_config->double_wide) {
6611 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6615 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6616 intel_is_dual_link_lvds(dev)) {
6617 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6622 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6623 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6625 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6626 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6629 intel_crtc_compute_pixel_rate(pipe_config);
6631 if (pipe_config->has_pch_encoder)
6632 return ironlake_fdi_compute_config(crtc, pipe_config);
6638 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6640 while (*num > DATA_LINK_M_N_MASK ||
6641 *den > DATA_LINK_M_N_MASK) {
6647 static void compute_m_n(unsigned int m, unsigned int n,
6648 uint32_t *ret_m, uint32_t *ret_n,
6652 * Several DP dongles in particular seem to be fussy about
6653 * too large link M/N values. Give N value as 0x8000 that
6654 * should be acceptable by specific devices. 0x8000 is the
6655 * specified fixed N value for asynchronous clock mode,
6656 * which the devices expect also in synchronous clock mode.
6661 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6663 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6664 intel_reduce_m_n_ratio(ret_m, ret_n);
6668 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6669 int pixel_clock, int link_clock,
6670 struct intel_link_m_n *m_n,
6675 compute_m_n(bits_per_pixel * pixel_clock,
6676 link_clock * nlanes * 8,
6677 &m_n->gmch_m, &m_n->gmch_n,
6680 compute_m_n(pixel_clock, link_clock,
6681 &m_n->link_m, &m_n->link_n,
6685 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6687 if (i915_modparams.panel_use_ssc >= 0)
6688 return i915_modparams.panel_use_ssc != 0;
6689 return dev_priv->vbt.lvds_use_ssc
6690 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6693 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
6695 return (1 << dpll->n) << 16 | dpll->m2;
6698 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6700 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
6703 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
6704 struct intel_crtc_state *crtc_state,
6705 struct dpll *reduced_clock)
6707 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6710 if (IS_PINEVIEW(dev_priv)) {
6711 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
6713 fp2 = pnv_dpll_compute_fp(reduced_clock);
6715 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
6717 fp2 = i9xx_dpll_compute_fp(reduced_clock);
6720 crtc_state->dpll_hw_state.fp0 = fp;
6722 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6724 crtc_state->dpll_hw_state.fp1 = fp2;
6726 crtc_state->dpll_hw_state.fp1 = fp;
6730 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6736 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6737 * and set it to a reasonable value instead.
6739 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6740 reg_val &= 0xffffff00;
6741 reg_val |= 0x00000030;
6742 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6744 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6745 reg_val &= 0x00ffffff;
6746 reg_val |= 0x8c000000;
6747 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6749 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6750 reg_val &= 0xffffff00;
6751 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6753 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6754 reg_val &= 0x00ffffff;
6755 reg_val |= 0xb0000000;
6756 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6759 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
6760 struct intel_link_m_n *m_n)
6762 struct drm_device *dev = crtc->base.dev;
6763 struct drm_i915_private *dev_priv = to_i915(dev);
6764 int pipe = crtc->pipe;
6766 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6767 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6768 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6769 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6772 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
6773 struct intel_link_m_n *m_n,
6774 struct intel_link_m_n *m2_n2)
6776 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6777 int pipe = crtc->pipe;
6778 enum transcoder transcoder = crtc->config->cpu_transcoder;
6780 if (INTEL_GEN(dev_priv) >= 5) {
6781 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6782 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6783 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6784 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
6785 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6786 * for gen < 8) and if DRRS is supported (to make sure the
6787 * registers are not unnecessarily accessed).
6789 if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
6790 INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
6791 I915_WRITE(PIPE_DATA_M2(transcoder),
6792 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6793 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6794 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6795 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6798 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6799 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6800 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6801 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
6805 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
6807 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6810 dp_m_n = &crtc->config->dp_m_n;
6811 dp_m2_n2 = &crtc->config->dp_m2_n2;
6812 } else if (m_n == M2_N2) {
6815 * M2_N2 registers are not supported. Hence m2_n2 divider value
6816 * needs to be programmed into M1_N1.
6818 dp_m_n = &crtc->config->dp_m2_n2;
6820 DRM_ERROR("Unsupported divider value\n");
6824 if (crtc->config->has_pch_encoder)
6825 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
6827 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
6830 static void vlv_compute_dpll(struct intel_crtc *crtc,
6831 struct intel_crtc_state *pipe_config)
6833 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
6834 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6835 if (crtc->pipe != PIPE_A)
6836 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6838 /* DPLL not used with DSI, but still need the rest set up */
6839 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6840 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6841 DPLL_EXT_BUFFER_ENABLE_VLV;
6843 pipe_config->dpll_hw_state.dpll_md =
6844 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6847 static void chv_compute_dpll(struct intel_crtc *crtc,
6848 struct intel_crtc_state *pipe_config)
6850 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
6851 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6852 if (crtc->pipe != PIPE_A)
6853 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6855 /* DPLL not used with DSI, but still need the rest set up */
6856 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6857 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6859 pipe_config->dpll_hw_state.dpll_md =
6860 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6863 static void vlv_prepare_pll(struct intel_crtc *crtc,
6864 const struct intel_crtc_state *pipe_config)
6866 struct drm_device *dev = crtc->base.dev;
6867 struct drm_i915_private *dev_priv = to_i915(dev);
6868 enum pipe pipe = crtc->pipe;
6870 u32 bestn, bestm1, bestm2, bestp1, bestp2;
6871 u32 coreclk, reg_val;
6874 I915_WRITE(DPLL(pipe),
6875 pipe_config->dpll_hw_state.dpll &
6876 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6878 /* No need to actually set up the DPLL with DSI */
6879 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6882 mutex_lock(&dev_priv->sb_lock);
6884 bestn = pipe_config->dpll.n;
6885 bestm1 = pipe_config->dpll.m1;
6886 bestm2 = pipe_config->dpll.m2;
6887 bestp1 = pipe_config->dpll.p1;
6888 bestp2 = pipe_config->dpll.p2;
6890 /* See eDP HDMI DPIO driver vbios notes doc */
6892 /* PLL B needs special handling */
6894 vlv_pllb_recal_opamp(dev_priv, pipe);
6896 /* Set up Tx target for periodic Rcomp update */
6897 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
6899 /* Disable target IRef on PLL */
6900 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
6901 reg_val &= 0x00ffffff;
6902 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
6904 /* Disable fast lock */
6905 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
6907 /* Set idtafcrecal before PLL is enabled */
6908 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6909 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6910 mdiv |= ((bestn << DPIO_N_SHIFT));
6911 mdiv |= (1 << DPIO_K_SHIFT);
6914 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6915 * but we don't support that).
6916 * Note: don't use the DAC post divider as it seems unstable.
6918 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
6919 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6921 mdiv |= DPIO_ENABLE_CALIBRATION;
6922 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6924 /* Set HBR and RBR LPF coefficients */
6925 if (pipe_config->port_clock == 162000 ||
6926 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) ||
6927 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI))
6928 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6931 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6934 if (intel_crtc_has_dp_encoder(pipe_config)) {
6935 /* Use SSC source */
6937 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6940 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6942 } else { /* HDMI or VGA */
6943 /* Use bend source */
6945 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6948 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6952 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
6953 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
6954 if (intel_crtc_has_dp_encoder(crtc->config))
6955 coreclk |= 0x01000000;
6956 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
6958 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
6959 mutex_unlock(&dev_priv->sb_lock);
6962 static void chv_prepare_pll(struct intel_crtc *crtc,
6963 const struct intel_crtc_state *pipe_config)
6965 struct drm_device *dev = crtc->base.dev;
6966 struct drm_i915_private *dev_priv = to_i915(dev);
6967 enum pipe pipe = crtc->pipe;
6968 enum dpio_channel port = vlv_pipe_to_channel(pipe);
6969 u32 loopfilter, tribuf_calcntr;
6970 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
6974 /* Enable Refclk and SSC */
6975 I915_WRITE(DPLL(pipe),
6976 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
6978 /* No need to actually set up the DPLL with DSI */
6979 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6982 bestn = pipe_config->dpll.n;
6983 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
6984 bestm1 = pipe_config->dpll.m1;
6985 bestm2 = pipe_config->dpll.m2 >> 22;
6986 bestp1 = pipe_config->dpll.p1;
6987 bestp2 = pipe_config->dpll.p2;
6988 vco = pipe_config->dpll.vco;
6992 mutex_lock(&dev_priv->sb_lock);
6994 /* p1 and p2 divider */
6995 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
6996 5 << DPIO_CHV_S1_DIV_SHIFT |
6997 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
6998 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
6999 1 << DPIO_CHV_K_DIV_SHIFT);
7001 /* Feedback post-divider - m2 */
7002 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7004 /* Feedback refclk divider - n and m1 */
7005 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7006 DPIO_CHV_M1_DIV_BY_2 |
7007 1 << DPIO_CHV_N_DIV_SHIFT);
7009 /* M2 fraction division */
7010 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7012 /* M2 fraction division enable */
7013 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7014 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7015 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7017 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7018 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7020 /* Program digital lock detect threshold */
7021 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7022 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7023 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7024 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7026 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7027 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7030 if (vco == 5400000) {
7031 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7032 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7033 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7034 tribuf_calcntr = 0x9;
7035 } else if (vco <= 6200000) {
7036 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7037 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7038 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7039 tribuf_calcntr = 0x9;
7040 } else if (vco <= 6480000) {
7041 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7042 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7043 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7044 tribuf_calcntr = 0x8;
7046 /* Not supported. Apply the same limits as in the max case */
7047 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7048 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7049 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7052 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7054 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7055 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7056 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7057 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7060 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7061 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7064 mutex_unlock(&dev_priv->sb_lock);
7068 * vlv_force_pll_on - forcibly enable just the PLL
7069 * @dev_priv: i915 private structure
7070 * @pipe: pipe PLL to enable
7071 * @dpll: PLL configuration
7073 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7074 * in cases where we need the PLL enabled even when @pipe is not going to
7077 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7078 const struct dpll *dpll)
7080 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7081 struct intel_crtc_state *pipe_config;
7083 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7087 pipe_config->base.crtc = &crtc->base;
7088 pipe_config->pixel_multiplier = 1;
7089 pipe_config->dpll = *dpll;
7091 if (IS_CHERRYVIEW(dev_priv)) {
7092 chv_compute_dpll(crtc, pipe_config);
7093 chv_prepare_pll(crtc, pipe_config);
7094 chv_enable_pll(crtc, pipe_config);
7096 vlv_compute_dpll(crtc, pipe_config);
7097 vlv_prepare_pll(crtc, pipe_config);
7098 vlv_enable_pll(crtc, pipe_config);
7107 * vlv_force_pll_off - forcibly disable just the PLL
7108 * @dev_priv: i915 private structure
7109 * @pipe: pipe PLL to disable
7111 * Disable the PLL for @pipe. To be used in cases where we need
7112 * the PLL enabled even when @pipe is not going to be enabled.
7114 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7116 if (IS_CHERRYVIEW(dev_priv))
7117 chv_disable_pll(dev_priv, pipe);
7119 vlv_disable_pll(dev_priv, pipe);
7122 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7123 struct intel_crtc_state *crtc_state,
7124 struct dpll *reduced_clock)
7126 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7128 struct dpll *clock = &crtc_state->dpll;
7130 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7132 dpll = DPLL_VGA_MODE_DIS;
7134 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7135 dpll |= DPLLB_MODE_LVDS;
7137 dpll |= DPLLB_MODE_DAC_SERIAL;
7139 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7140 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7141 dpll |= (crtc_state->pixel_multiplier - 1)
7142 << SDVO_MULTIPLIER_SHIFT_HIRES;
7145 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7146 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7147 dpll |= DPLL_SDVO_HIGH_SPEED;
7149 if (intel_crtc_has_dp_encoder(crtc_state))
7150 dpll |= DPLL_SDVO_HIGH_SPEED;
7152 /* compute bitmask from p1 value */
7153 if (IS_PINEVIEW(dev_priv))
7154 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7156 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7157 if (IS_G4X(dev_priv) && reduced_clock)
7158 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7160 switch (clock->p2) {
7162 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7165 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7168 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7171 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7174 if (INTEL_GEN(dev_priv) >= 4)
7175 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7177 if (crtc_state->sdvo_tv_clock)
7178 dpll |= PLL_REF_INPUT_TVCLKINBC;
7179 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7180 intel_panel_use_ssc(dev_priv))
7181 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7183 dpll |= PLL_REF_INPUT_DREFCLK;
7185 dpll |= DPLL_VCO_ENABLE;
7186 crtc_state->dpll_hw_state.dpll = dpll;
7188 if (INTEL_GEN(dev_priv) >= 4) {
7189 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7190 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7191 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7195 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7196 struct intel_crtc_state *crtc_state,
7197 struct dpll *reduced_clock)
7199 struct drm_device *dev = crtc->base.dev;
7200 struct drm_i915_private *dev_priv = to_i915(dev);
7202 struct dpll *clock = &crtc_state->dpll;
7204 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7206 dpll = DPLL_VGA_MODE_DIS;
7208 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7209 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7212 dpll |= PLL_P1_DIVIDE_BY_TWO;
7214 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7216 dpll |= PLL_P2_DIVIDE_BY_4;
7219 if (!IS_I830(dev_priv) &&
7220 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7221 dpll |= DPLL_DVO_2X_MODE;
7223 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7224 intel_panel_use_ssc(dev_priv))
7225 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7227 dpll |= PLL_REF_INPUT_DREFCLK;
7229 dpll |= DPLL_VCO_ENABLE;
7230 crtc_state->dpll_hw_state.dpll = dpll;
7233 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
7235 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7236 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7237 enum pipe pipe = crtc->pipe;
7238 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7239 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
7240 uint32_t crtc_vtotal, crtc_vblank_end;
7243 /* We need to be careful not to changed the adjusted mode, for otherwise
7244 * the hw state checker will get angry at the mismatch. */
7245 crtc_vtotal = adjusted_mode->crtc_vtotal;
7246 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7248 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7249 /* the chip adds 2 halflines automatically */
7251 crtc_vblank_end -= 1;
7253 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7254 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7256 vsyncshift = adjusted_mode->crtc_hsync_start -
7257 adjusted_mode->crtc_htotal / 2;
7259 vsyncshift += adjusted_mode->crtc_htotal;
7262 if (INTEL_GEN(dev_priv) > 3)
7263 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7265 I915_WRITE(HTOTAL(cpu_transcoder),
7266 (adjusted_mode->crtc_hdisplay - 1) |
7267 ((adjusted_mode->crtc_htotal - 1) << 16));
7268 I915_WRITE(HBLANK(cpu_transcoder),
7269 (adjusted_mode->crtc_hblank_start - 1) |
7270 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7271 I915_WRITE(HSYNC(cpu_transcoder),
7272 (adjusted_mode->crtc_hsync_start - 1) |
7273 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7275 I915_WRITE(VTOTAL(cpu_transcoder),
7276 (adjusted_mode->crtc_vdisplay - 1) |
7277 ((crtc_vtotal - 1) << 16));
7278 I915_WRITE(VBLANK(cpu_transcoder),
7279 (adjusted_mode->crtc_vblank_start - 1) |
7280 ((crtc_vblank_end - 1) << 16));
7281 I915_WRITE(VSYNC(cpu_transcoder),
7282 (adjusted_mode->crtc_vsync_start - 1) |
7283 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7285 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7286 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7287 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7289 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7290 (pipe == PIPE_B || pipe == PIPE_C))
7291 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7295 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
7297 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7298 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7299 enum pipe pipe = crtc->pipe;
7301 /* pipesrc controls the size that is scaled from, which should
7302 * always be the user's requested size.
7304 I915_WRITE(PIPESRC(pipe),
7305 ((crtc_state->pipe_src_w - 1) << 16) |
7306 (crtc_state->pipe_src_h - 1));
7309 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7310 struct intel_crtc_state *pipe_config)
7312 struct drm_device *dev = crtc->base.dev;
7313 struct drm_i915_private *dev_priv = to_i915(dev);
7314 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7317 tmp = I915_READ(HTOTAL(cpu_transcoder));
7318 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7319 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7320 tmp = I915_READ(HBLANK(cpu_transcoder));
7321 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7322 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7323 tmp = I915_READ(HSYNC(cpu_transcoder));
7324 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7325 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7327 tmp = I915_READ(VTOTAL(cpu_transcoder));
7328 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7329 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7330 tmp = I915_READ(VBLANK(cpu_transcoder));
7331 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7332 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7333 tmp = I915_READ(VSYNC(cpu_transcoder));
7334 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7335 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7337 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7338 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7339 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7340 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7344 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7345 struct intel_crtc_state *pipe_config)
7347 struct drm_device *dev = crtc->base.dev;
7348 struct drm_i915_private *dev_priv = to_i915(dev);
7351 tmp = I915_READ(PIPESRC(crtc->pipe));
7352 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7353 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7355 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7356 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7359 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7360 struct intel_crtc_state *pipe_config)
7362 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7363 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7364 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7365 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7367 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7368 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7369 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7370 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7372 mode->flags = pipe_config->base.adjusted_mode.flags;
7373 mode->type = DRM_MODE_TYPE_DRIVER;
7375 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7377 mode->hsync = drm_mode_hsync(mode);
7378 mode->vrefresh = drm_mode_vrefresh(mode);
7379 drm_mode_set_name(mode);
7382 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
7384 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7385 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7390 /* we keep both pipes enabled on 830 */
7391 if (IS_I830(dev_priv))
7392 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
7394 if (crtc_state->double_wide)
7395 pipeconf |= PIPECONF_DOUBLE_WIDE;
7397 /* only g4x and later have fancy bpc/dither controls */
7398 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7399 IS_CHERRYVIEW(dev_priv)) {
7400 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7401 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
7402 pipeconf |= PIPECONF_DITHER_EN |
7403 PIPECONF_DITHER_TYPE_SP;
7405 switch (crtc_state->pipe_bpp) {
7407 pipeconf |= PIPECONF_6BPC;
7410 pipeconf |= PIPECONF_8BPC;
7413 pipeconf |= PIPECONF_10BPC;
7416 /* Case prevented by intel_choose_pipe_bpp_dither. */
7421 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7422 if (INTEL_GEN(dev_priv) < 4 ||
7423 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7424 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7426 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7428 pipeconf |= PIPECONF_PROGRESSIVE;
7430 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7431 crtc_state->limited_color_range)
7432 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7434 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7435 POSTING_READ(PIPECONF(crtc->pipe));
7438 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7439 struct intel_crtc_state *crtc_state)
7441 struct drm_device *dev = crtc->base.dev;
7442 struct drm_i915_private *dev_priv = to_i915(dev);
7443 const struct intel_limit *limit;
7446 memset(&crtc_state->dpll_hw_state, 0,
7447 sizeof(crtc_state->dpll_hw_state));
7449 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7450 if (intel_panel_use_ssc(dev_priv)) {
7451 refclk = dev_priv->vbt.lvds_ssc_freq;
7452 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7455 limit = &intel_limits_i8xx_lvds;
7456 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7457 limit = &intel_limits_i8xx_dvo;
7459 limit = &intel_limits_i8xx_dac;
7462 if (!crtc_state->clock_set &&
7463 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7464 refclk, NULL, &crtc_state->dpll)) {
7465 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7469 i8xx_compute_dpll(crtc, crtc_state, NULL);
7474 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7475 struct intel_crtc_state *crtc_state)
7477 struct drm_device *dev = crtc->base.dev;
7478 struct drm_i915_private *dev_priv = to_i915(dev);
7479 const struct intel_limit *limit;
7482 memset(&crtc_state->dpll_hw_state, 0,
7483 sizeof(crtc_state->dpll_hw_state));
7485 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7486 if (intel_panel_use_ssc(dev_priv)) {
7487 refclk = dev_priv->vbt.lvds_ssc_freq;
7488 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7491 if (intel_is_dual_link_lvds(dev))
7492 limit = &intel_limits_g4x_dual_channel_lvds;
7494 limit = &intel_limits_g4x_single_channel_lvds;
7495 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7496 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7497 limit = &intel_limits_g4x_hdmi;
7498 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7499 limit = &intel_limits_g4x_sdvo;
7501 /* The option is for other outputs */
7502 limit = &intel_limits_i9xx_sdvo;
7505 if (!crtc_state->clock_set &&
7506 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7507 refclk, NULL, &crtc_state->dpll)) {
7508 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7512 i9xx_compute_dpll(crtc, crtc_state, NULL);
7517 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7518 struct intel_crtc_state *crtc_state)
7520 struct drm_device *dev = crtc->base.dev;
7521 struct drm_i915_private *dev_priv = to_i915(dev);
7522 const struct intel_limit *limit;
7525 memset(&crtc_state->dpll_hw_state, 0,
7526 sizeof(crtc_state->dpll_hw_state));
7528 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7529 if (intel_panel_use_ssc(dev_priv)) {
7530 refclk = dev_priv->vbt.lvds_ssc_freq;
7531 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7534 limit = &intel_limits_pineview_lvds;
7536 limit = &intel_limits_pineview_sdvo;
7539 if (!crtc_state->clock_set &&
7540 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7541 refclk, NULL, &crtc_state->dpll)) {
7542 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7546 i9xx_compute_dpll(crtc, crtc_state, NULL);
7551 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7552 struct intel_crtc_state *crtc_state)
7554 struct drm_device *dev = crtc->base.dev;
7555 struct drm_i915_private *dev_priv = to_i915(dev);
7556 const struct intel_limit *limit;
7559 memset(&crtc_state->dpll_hw_state, 0,
7560 sizeof(crtc_state->dpll_hw_state));
7562 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7563 if (intel_panel_use_ssc(dev_priv)) {
7564 refclk = dev_priv->vbt.lvds_ssc_freq;
7565 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7568 limit = &intel_limits_i9xx_lvds;
7570 limit = &intel_limits_i9xx_sdvo;
7573 if (!crtc_state->clock_set &&
7574 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7575 refclk, NULL, &crtc_state->dpll)) {
7576 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7580 i9xx_compute_dpll(crtc, crtc_state, NULL);
7585 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7586 struct intel_crtc_state *crtc_state)
7588 int refclk = 100000;
7589 const struct intel_limit *limit = &intel_limits_chv;
7591 memset(&crtc_state->dpll_hw_state, 0,
7592 sizeof(crtc_state->dpll_hw_state));
7594 if (!crtc_state->clock_set &&
7595 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7596 refclk, NULL, &crtc_state->dpll)) {
7597 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7601 chv_compute_dpll(crtc, crtc_state);
7606 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7607 struct intel_crtc_state *crtc_state)
7609 int refclk = 100000;
7610 const struct intel_limit *limit = &intel_limits_vlv;
7612 memset(&crtc_state->dpll_hw_state, 0,
7613 sizeof(crtc_state->dpll_hw_state));
7615 if (!crtc_state->clock_set &&
7616 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7617 refclk, NULL, &crtc_state->dpll)) {
7618 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7622 vlv_compute_dpll(crtc, crtc_state);
7627 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7628 struct intel_crtc_state *pipe_config)
7630 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7633 if (INTEL_GEN(dev_priv) <= 3 &&
7634 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7637 tmp = I915_READ(PFIT_CONTROL);
7638 if (!(tmp & PFIT_ENABLE))
7641 /* Check whether the pfit is attached to our pipe. */
7642 if (INTEL_GEN(dev_priv) < 4) {
7643 if (crtc->pipe != PIPE_B)
7646 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7650 pipe_config->gmch_pfit.control = tmp;
7651 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7654 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7655 struct intel_crtc_state *pipe_config)
7657 struct drm_device *dev = crtc->base.dev;
7658 struct drm_i915_private *dev_priv = to_i915(dev);
7659 int pipe = pipe_config->cpu_transcoder;
7662 int refclk = 100000;
7664 /* In case of DSI, DPLL will not be used */
7665 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7668 mutex_lock(&dev_priv->sb_lock);
7669 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7670 mutex_unlock(&dev_priv->sb_lock);
7672 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7673 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7674 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7675 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7676 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7678 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7682 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7683 struct intel_initial_plane_config *plane_config)
7685 struct drm_device *dev = crtc->base.dev;
7686 struct drm_i915_private *dev_priv = to_i915(dev);
7687 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7688 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7690 u32 val, base, offset;
7691 int fourcc, pixel_format;
7692 unsigned int aligned_height;
7693 struct drm_framebuffer *fb;
7694 struct intel_framebuffer *intel_fb;
7696 if (!plane->get_hw_state(plane, &pipe))
7699 WARN_ON(pipe != crtc->pipe);
7701 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7703 DRM_DEBUG_KMS("failed to alloc fb\n");
7707 fb = &intel_fb->base;
7711 val = I915_READ(DSPCNTR(i9xx_plane));
7713 if (INTEL_GEN(dev_priv) >= 4) {
7714 if (val & DISPPLANE_TILED) {
7715 plane_config->tiling = I915_TILING_X;
7716 fb->modifier = I915_FORMAT_MOD_X_TILED;
7720 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7721 fourcc = i9xx_format_to_fourcc(pixel_format);
7722 fb->format = drm_format_info(fourcc);
7724 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7725 offset = I915_READ(DSPOFFSET(i9xx_plane));
7726 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7727 } else if (INTEL_GEN(dev_priv) >= 4) {
7728 if (plane_config->tiling)
7729 offset = I915_READ(DSPTILEOFF(i9xx_plane));
7731 offset = I915_READ(DSPLINOFF(i9xx_plane));
7732 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7734 base = I915_READ(DSPADDR(i9xx_plane));
7736 plane_config->base = base;
7738 val = I915_READ(PIPESRC(pipe));
7739 fb->width = ((val >> 16) & 0xfff) + 1;
7740 fb->height = ((val >> 0) & 0xfff) + 1;
7742 val = I915_READ(DSPSTRIDE(i9xx_plane));
7743 fb->pitches[0] = val & 0xffffffc0;
7745 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7747 plane_config->size = fb->pitches[0] * aligned_height;
7749 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7750 crtc->base.name, plane->base.name, fb->width, fb->height,
7751 fb->format->cpp[0] * 8, base, fb->pitches[0],
7752 plane_config->size);
7754 plane_config->fb = intel_fb;
7757 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7758 struct intel_crtc_state *pipe_config)
7760 struct drm_device *dev = crtc->base.dev;
7761 struct drm_i915_private *dev_priv = to_i915(dev);
7762 int pipe = pipe_config->cpu_transcoder;
7763 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7765 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7766 int refclk = 100000;
7768 /* In case of DSI, DPLL will not be used */
7769 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7772 mutex_lock(&dev_priv->sb_lock);
7773 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7774 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7775 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7776 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7777 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7778 mutex_unlock(&dev_priv->sb_lock);
7780 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7781 clock.m2 = (pll_dw0 & 0xff) << 22;
7782 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7783 clock.m2 |= pll_dw2 & 0x3fffff;
7784 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7785 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7786 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7788 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7791 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7792 struct intel_crtc_state *pipe_config)
7794 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7795 enum intel_display_power_domain power_domain;
7799 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7800 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7803 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7804 pipe_config->shared_dpll = NULL;
7808 tmp = I915_READ(PIPECONF(crtc->pipe));
7809 if (!(tmp & PIPECONF_ENABLE))
7812 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7813 IS_CHERRYVIEW(dev_priv)) {
7814 switch (tmp & PIPECONF_BPC_MASK) {
7816 pipe_config->pipe_bpp = 18;
7819 pipe_config->pipe_bpp = 24;
7821 case PIPECONF_10BPC:
7822 pipe_config->pipe_bpp = 30;
7829 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7830 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7831 pipe_config->limited_color_range = true;
7833 if (INTEL_GEN(dev_priv) < 4)
7834 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7836 intel_get_pipe_timings(crtc, pipe_config);
7837 intel_get_pipe_src_size(crtc, pipe_config);
7839 i9xx_get_pfit_config(crtc, pipe_config);
7841 if (INTEL_GEN(dev_priv) >= 4) {
7842 /* No way to read it out on pipes B and C */
7843 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
7844 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7846 tmp = I915_READ(DPLL_MD(crtc->pipe));
7847 pipe_config->pixel_multiplier =
7848 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7849 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
7850 pipe_config->dpll_hw_state.dpll_md = tmp;
7851 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7852 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7853 tmp = I915_READ(DPLL(crtc->pipe));
7854 pipe_config->pixel_multiplier =
7855 ((tmp & SDVO_MULTIPLIER_MASK)
7856 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7858 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7859 * port and will be fixed up in the encoder->get_config
7861 pipe_config->pixel_multiplier = 1;
7863 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
7864 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
7866 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7867 * on 830. Filter it out here so that we don't
7868 * report errors due to that.
7870 if (IS_I830(dev_priv))
7871 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
7873 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
7874 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
7876 /* Mask out read-only status bits. */
7877 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7878 DPLL_PORTC_READY_MASK |
7879 DPLL_PORTB_READY_MASK);
7882 if (IS_CHERRYVIEW(dev_priv))
7883 chv_crtc_clock_get(crtc, pipe_config);
7884 else if (IS_VALLEYVIEW(dev_priv))
7885 vlv_crtc_clock_get(crtc, pipe_config);
7887 i9xx_crtc_clock_get(crtc, pipe_config);
7890 * Normally the dotclock is filled in by the encoder .get_config()
7891 * but in case the pipe is enabled w/o any ports we need a sane
7894 pipe_config->base.adjusted_mode.crtc_clock =
7895 pipe_config->port_clock / pipe_config->pixel_multiplier;
7900 intel_display_power_put(dev_priv, power_domain);
7905 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
7907 struct intel_encoder *encoder;
7910 bool has_lvds = false;
7911 bool has_cpu_edp = false;
7912 bool has_panel = false;
7913 bool has_ck505 = false;
7914 bool can_ssc = false;
7915 bool using_ssc_source = false;
7917 /* We need to take the global config into account */
7918 for_each_intel_encoder(&dev_priv->drm, encoder) {
7919 switch (encoder->type) {
7920 case INTEL_OUTPUT_LVDS:
7924 case INTEL_OUTPUT_EDP:
7926 if (encoder->port == PORT_A)
7934 if (HAS_PCH_IBX(dev_priv)) {
7935 has_ck505 = dev_priv->vbt.display_clock_mode;
7936 can_ssc = has_ck505;
7942 /* Check if any DPLLs are using the SSC source */
7943 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
7944 u32 temp = I915_READ(PCH_DPLL(i));
7946 if (!(temp & DPLL_VCO_ENABLE))
7949 if ((temp & PLL_REF_INPUT_MASK) ==
7950 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
7951 using_ssc_source = true;
7956 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7957 has_panel, has_lvds, has_ck505, using_ssc_source);
7959 /* Ironlake: try to setup display ref clock before DPLL
7960 * enabling. This is only under driver's control after
7961 * PCH B stepping, previous chipset stepping should be
7962 * ignoring this setting.
7964 val = I915_READ(PCH_DREF_CONTROL);
7966 /* As we must carefully and slowly disable/enable each source in turn,
7967 * compute the final state we want first and check if we need to
7968 * make any changes at all.
7971 final &= ~DREF_NONSPREAD_SOURCE_MASK;
7973 final |= DREF_NONSPREAD_CK505_ENABLE;
7975 final |= DREF_NONSPREAD_SOURCE_ENABLE;
7977 final &= ~DREF_SSC_SOURCE_MASK;
7978 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7979 final &= ~DREF_SSC1_ENABLE;
7982 final |= DREF_SSC_SOURCE_ENABLE;
7984 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7985 final |= DREF_SSC1_ENABLE;
7988 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7989 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7991 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7993 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7994 } else if (using_ssc_source) {
7995 final |= DREF_SSC_SOURCE_ENABLE;
7996 final |= DREF_SSC1_ENABLE;
8002 /* Always enable nonspread source */
8003 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8006 val |= DREF_NONSPREAD_CK505_ENABLE;
8008 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8011 val &= ~DREF_SSC_SOURCE_MASK;
8012 val |= DREF_SSC_SOURCE_ENABLE;
8014 /* SSC must be turned on before enabling the CPU output */
8015 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8016 DRM_DEBUG_KMS("Using SSC on panel\n");
8017 val |= DREF_SSC1_ENABLE;
8019 val &= ~DREF_SSC1_ENABLE;
8021 /* Get SSC going before enabling the outputs */
8022 I915_WRITE(PCH_DREF_CONTROL, val);
8023 POSTING_READ(PCH_DREF_CONTROL);
8026 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8028 /* Enable CPU source on CPU attached eDP */
8030 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8031 DRM_DEBUG_KMS("Using SSC on eDP\n");
8032 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8034 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8036 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8038 I915_WRITE(PCH_DREF_CONTROL, val);
8039 POSTING_READ(PCH_DREF_CONTROL);
8042 DRM_DEBUG_KMS("Disabling CPU source output\n");
8044 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8046 /* Turn off CPU output */
8047 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8049 I915_WRITE(PCH_DREF_CONTROL, val);
8050 POSTING_READ(PCH_DREF_CONTROL);
8053 if (!using_ssc_source) {
8054 DRM_DEBUG_KMS("Disabling SSC source\n");
8056 /* Turn off the SSC source */
8057 val &= ~DREF_SSC_SOURCE_MASK;
8058 val |= DREF_SSC_SOURCE_DISABLE;
8061 val &= ~DREF_SSC1_ENABLE;
8063 I915_WRITE(PCH_DREF_CONTROL, val);
8064 POSTING_READ(PCH_DREF_CONTROL);
8069 BUG_ON(val != final);
8072 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8076 tmp = I915_READ(SOUTH_CHICKEN2);
8077 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8078 I915_WRITE(SOUTH_CHICKEN2, tmp);
8080 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8081 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8082 DRM_ERROR("FDI mPHY reset assert timeout\n");
8084 tmp = I915_READ(SOUTH_CHICKEN2);
8085 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8086 I915_WRITE(SOUTH_CHICKEN2, tmp);
8088 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8089 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8090 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8093 /* WaMPhyProgramming:hsw */
8094 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8098 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8099 tmp &= ~(0xFF << 24);
8100 tmp |= (0x12 << 24);
8101 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8103 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8105 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8107 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8109 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8111 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8112 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8113 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8115 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8116 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8117 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8119 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8122 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8124 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8127 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8129 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8132 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8134 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8137 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8139 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8140 tmp &= ~(0xFF << 16);
8141 tmp |= (0x1C << 16);
8142 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8144 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8145 tmp &= ~(0xFF << 16);
8146 tmp |= (0x1C << 16);
8147 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8149 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8151 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8153 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8155 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8157 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8158 tmp &= ~(0xF << 28);
8160 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8162 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8163 tmp &= ~(0xF << 28);
8165 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8168 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8169 * Programming" based on the parameters passed:
8170 * - Sequence to enable CLKOUT_DP
8171 * - Sequence to enable CLKOUT_DP without spread
8172 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8174 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8175 bool with_spread, bool with_fdi)
8179 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8181 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8182 with_fdi, "LP PCH doesn't have FDI\n"))
8185 mutex_lock(&dev_priv->sb_lock);
8187 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8188 tmp &= ~SBI_SSCCTL_DISABLE;
8189 tmp |= SBI_SSCCTL_PATHALT;
8190 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8195 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8196 tmp &= ~SBI_SSCCTL_PATHALT;
8197 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8200 lpt_reset_fdi_mphy(dev_priv);
8201 lpt_program_fdi_mphy(dev_priv);
8205 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8206 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8207 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8208 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8210 mutex_unlock(&dev_priv->sb_lock);
8213 /* Sequence to disable CLKOUT_DP */
8214 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8218 mutex_lock(&dev_priv->sb_lock);
8220 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8221 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8222 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8223 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8225 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8226 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8227 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8228 tmp |= SBI_SSCCTL_PATHALT;
8229 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8232 tmp |= SBI_SSCCTL_DISABLE;
8233 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8236 mutex_unlock(&dev_priv->sb_lock);
8239 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8241 static const uint16_t sscdivintphase[] = {
8242 [BEND_IDX( 50)] = 0x3B23,
8243 [BEND_IDX( 45)] = 0x3B23,
8244 [BEND_IDX( 40)] = 0x3C23,
8245 [BEND_IDX( 35)] = 0x3C23,
8246 [BEND_IDX( 30)] = 0x3D23,
8247 [BEND_IDX( 25)] = 0x3D23,
8248 [BEND_IDX( 20)] = 0x3E23,
8249 [BEND_IDX( 15)] = 0x3E23,
8250 [BEND_IDX( 10)] = 0x3F23,
8251 [BEND_IDX( 5)] = 0x3F23,
8252 [BEND_IDX( 0)] = 0x0025,
8253 [BEND_IDX( -5)] = 0x0025,
8254 [BEND_IDX(-10)] = 0x0125,
8255 [BEND_IDX(-15)] = 0x0125,
8256 [BEND_IDX(-20)] = 0x0225,
8257 [BEND_IDX(-25)] = 0x0225,
8258 [BEND_IDX(-30)] = 0x0325,
8259 [BEND_IDX(-35)] = 0x0325,
8260 [BEND_IDX(-40)] = 0x0425,
8261 [BEND_IDX(-45)] = 0x0425,
8262 [BEND_IDX(-50)] = 0x0525,
8267 * steps -50 to 50 inclusive, in steps of 5
8268 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8269 * change in clock period = -(steps / 10) * 5.787 ps
8271 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8274 int idx = BEND_IDX(steps);
8276 if (WARN_ON(steps % 5 != 0))
8279 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8282 mutex_lock(&dev_priv->sb_lock);
8284 if (steps % 10 != 0)
8288 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8290 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8292 tmp |= sscdivintphase[idx];
8293 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8295 mutex_unlock(&dev_priv->sb_lock);
8300 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8302 struct intel_encoder *encoder;
8303 bool has_vga = false;
8305 for_each_intel_encoder(&dev_priv->drm, encoder) {
8306 switch (encoder->type) {
8307 case INTEL_OUTPUT_ANALOG:
8316 lpt_bend_clkout_dp(dev_priv, 0);
8317 lpt_enable_clkout_dp(dev_priv, true, true);
8319 lpt_disable_clkout_dp(dev_priv);
8324 * Initialize reference clocks when the driver loads
8326 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8328 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8329 ironlake_init_pch_refclk(dev_priv);
8330 else if (HAS_PCH_LPT(dev_priv))
8331 lpt_init_pch_refclk(dev_priv);
8334 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
8336 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8337 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8338 enum pipe pipe = crtc->pipe;
8343 switch (crtc_state->pipe_bpp) {
8345 val |= PIPECONF_6BPC;
8348 val |= PIPECONF_8BPC;
8351 val |= PIPECONF_10BPC;
8354 val |= PIPECONF_12BPC;
8357 /* Case prevented by intel_choose_pipe_bpp_dither. */
8361 if (crtc_state->dither)
8362 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8364 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8365 val |= PIPECONF_INTERLACED_ILK;
8367 val |= PIPECONF_PROGRESSIVE;
8369 if (crtc_state->limited_color_range)
8370 val |= PIPECONF_COLOR_RANGE_SELECT;
8372 I915_WRITE(PIPECONF(pipe), val);
8373 POSTING_READ(PIPECONF(pipe));
8376 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
8378 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8379 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8380 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8383 if (IS_HASWELL(dev_priv) && crtc_state->dither)
8384 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8386 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8387 val |= PIPECONF_INTERLACED_ILK;
8389 val |= PIPECONF_PROGRESSIVE;
8391 I915_WRITE(PIPECONF(cpu_transcoder), val);
8392 POSTING_READ(PIPECONF(cpu_transcoder));
8395 static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
8397 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8398 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
8400 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8403 switch (crtc_state->pipe_bpp) {
8405 val |= PIPEMISC_DITHER_6_BPC;
8408 val |= PIPEMISC_DITHER_8_BPC;
8411 val |= PIPEMISC_DITHER_10_BPC;
8414 val |= PIPEMISC_DITHER_12_BPC;
8417 /* Case prevented by pipe_config_set_bpp. */
8421 if (crtc_state->dither)
8422 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8424 if (crtc_state->ycbcr420) {
8425 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV |
8426 PIPEMISC_YUV420_ENABLE |
8427 PIPEMISC_YUV420_MODE_FULL_BLEND;
8430 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8434 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8437 * Account for spread spectrum to avoid
8438 * oversubscribing the link. Max center spread
8439 * is 2.5%; use 5% for safety's sake.
8441 u32 bps = target_clock * bpp * 21 / 20;
8442 return DIV_ROUND_UP(bps, link_bw * 8);
8445 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8447 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8450 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8451 struct intel_crtc_state *crtc_state,
8452 struct dpll *reduced_clock)
8454 struct drm_crtc *crtc = &intel_crtc->base;
8455 struct drm_device *dev = crtc->dev;
8456 struct drm_i915_private *dev_priv = to_i915(dev);
8460 /* Enable autotuning of the PLL clock (if permissible) */
8462 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8463 if ((intel_panel_use_ssc(dev_priv) &&
8464 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8465 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8467 } else if (crtc_state->sdvo_tv_clock)
8470 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8472 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8475 if (reduced_clock) {
8476 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8478 if (reduced_clock->m < factor * reduced_clock->n)
8486 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8487 dpll |= DPLLB_MODE_LVDS;
8489 dpll |= DPLLB_MODE_DAC_SERIAL;
8491 dpll |= (crtc_state->pixel_multiplier - 1)
8492 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8494 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8495 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8496 dpll |= DPLL_SDVO_HIGH_SPEED;
8498 if (intel_crtc_has_dp_encoder(crtc_state))
8499 dpll |= DPLL_SDVO_HIGH_SPEED;
8502 * The high speed IO clock is only really required for
8503 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8504 * possible to share the DPLL between CRT and HDMI. Enabling
8505 * the clock needlessly does no real harm, except use up a
8506 * bit of power potentially.
8508 * We'll limit this to IVB with 3 pipes, since it has only two
8509 * DPLLs and so DPLL sharing is the only way to get three pipes
8510 * driving PCH ports at the same time. On SNB we could do this,
8511 * and potentially avoid enabling the second DPLL, but it's not
8512 * clear if it''s a win or loss power wise. No point in doing
8513 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8515 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8516 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8517 dpll |= DPLL_SDVO_HIGH_SPEED;
8519 /* compute bitmask from p1 value */
8520 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8522 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8524 switch (crtc_state->dpll.p2) {
8526 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8529 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8532 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8535 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8539 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8540 intel_panel_use_ssc(dev_priv))
8541 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8543 dpll |= PLL_REF_INPUT_DREFCLK;
8545 dpll |= DPLL_VCO_ENABLE;
8547 crtc_state->dpll_hw_state.dpll = dpll;
8548 crtc_state->dpll_hw_state.fp0 = fp;
8549 crtc_state->dpll_hw_state.fp1 = fp2;
8552 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8553 struct intel_crtc_state *crtc_state)
8555 struct drm_device *dev = crtc->base.dev;
8556 struct drm_i915_private *dev_priv = to_i915(dev);
8557 const struct intel_limit *limit;
8558 int refclk = 120000;
8560 memset(&crtc_state->dpll_hw_state, 0,
8561 sizeof(crtc_state->dpll_hw_state));
8563 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8564 if (!crtc_state->has_pch_encoder)
8567 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8568 if (intel_panel_use_ssc(dev_priv)) {
8569 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8570 dev_priv->vbt.lvds_ssc_freq);
8571 refclk = dev_priv->vbt.lvds_ssc_freq;
8574 if (intel_is_dual_link_lvds(dev)) {
8575 if (refclk == 100000)
8576 limit = &intel_limits_ironlake_dual_lvds_100m;
8578 limit = &intel_limits_ironlake_dual_lvds;
8580 if (refclk == 100000)
8581 limit = &intel_limits_ironlake_single_lvds_100m;
8583 limit = &intel_limits_ironlake_single_lvds;
8586 limit = &intel_limits_ironlake_dac;
8589 if (!crtc_state->clock_set &&
8590 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8591 refclk, NULL, &crtc_state->dpll)) {
8592 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8596 ironlake_compute_dpll(crtc, crtc_state, NULL);
8598 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8599 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8600 pipe_name(crtc->pipe));
8607 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8608 struct intel_link_m_n *m_n)
8610 struct drm_device *dev = crtc->base.dev;
8611 struct drm_i915_private *dev_priv = to_i915(dev);
8612 enum pipe pipe = crtc->pipe;
8614 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8615 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8616 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8618 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8619 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8620 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8623 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8624 enum transcoder transcoder,
8625 struct intel_link_m_n *m_n,
8626 struct intel_link_m_n *m2_n2)
8628 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8629 enum pipe pipe = crtc->pipe;
8631 if (INTEL_GEN(dev_priv) >= 5) {
8632 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8633 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8634 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8636 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8637 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8638 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8639 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8640 * gen < 8) and if DRRS is supported (to make sure the
8641 * registers are not unnecessarily read).
8643 if (m2_n2 && INTEL_GEN(dev_priv) < 8 &&
8644 crtc->config->has_drrs) {
8645 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8646 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8647 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8649 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8650 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8651 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8654 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8655 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8656 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8658 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8659 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8660 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8664 void intel_dp_get_m_n(struct intel_crtc *crtc,
8665 struct intel_crtc_state *pipe_config)
8667 if (pipe_config->has_pch_encoder)
8668 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8670 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8671 &pipe_config->dp_m_n,
8672 &pipe_config->dp_m2_n2);
8675 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8676 struct intel_crtc_state *pipe_config)
8678 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8679 &pipe_config->fdi_m_n, NULL);
8682 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8683 struct intel_crtc_state *pipe_config)
8685 struct drm_device *dev = crtc->base.dev;
8686 struct drm_i915_private *dev_priv = to_i915(dev);
8687 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8688 uint32_t ps_ctrl = 0;
8692 /* find scaler attached to this pipe */
8693 for (i = 0; i < crtc->num_scalers; i++) {
8694 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8695 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8697 pipe_config->pch_pfit.enabled = true;
8698 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8699 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8704 scaler_state->scaler_id = id;
8706 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8708 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8713 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8714 struct intel_initial_plane_config *plane_config)
8716 struct drm_device *dev = crtc->base.dev;
8717 struct drm_i915_private *dev_priv = to_i915(dev);
8718 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8719 enum plane_id plane_id = plane->id;
8721 u32 val, base, offset, stride_mult, tiling, alpha;
8722 int fourcc, pixel_format;
8723 unsigned int aligned_height;
8724 struct drm_framebuffer *fb;
8725 struct intel_framebuffer *intel_fb;
8727 if (!plane->get_hw_state(plane, &pipe))
8730 WARN_ON(pipe != crtc->pipe);
8732 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8734 DRM_DEBUG_KMS("failed to alloc fb\n");
8738 fb = &intel_fb->base;
8742 val = I915_READ(PLANE_CTL(pipe, plane_id));
8744 if (INTEL_GEN(dev_priv) >= 11)
8745 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8747 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8749 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8750 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
8751 alpha &= PLANE_COLOR_ALPHA_MASK;
8753 alpha = val & PLANE_CTL_ALPHA_MASK;
8756 fourcc = skl_format_to_fourcc(pixel_format,
8757 val & PLANE_CTL_ORDER_RGBX, alpha);
8758 fb->format = drm_format_info(fourcc);
8760 tiling = val & PLANE_CTL_TILED_MASK;
8762 case PLANE_CTL_TILED_LINEAR:
8763 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8765 case PLANE_CTL_TILED_X:
8766 plane_config->tiling = I915_TILING_X;
8767 fb->modifier = I915_FORMAT_MOD_X_TILED;
8769 case PLANE_CTL_TILED_Y:
8770 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8771 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8773 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8775 case PLANE_CTL_TILED_YF:
8776 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8777 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8779 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8782 MISSING_CASE(tiling);
8786 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8787 plane_config->base = base;
8789 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
8791 val = I915_READ(PLANE_SIZE(pipe, plane_id));
8792 fb->height = ((val >> 16) & 0xfff) + 1;
8793 fb->width = ((val >> 0) & 0x1fff) + 1;
8795 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
8796 stride_mult = intel_fb_stride_alignment(fb, 0);
8797 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8799 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8801 plane_config->size = fb->pitches[0] * aligned_height;
8803 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8804 crtc->base.name, plane->base.name, fb->width, fb->height,
8805 fb->format->cpp[0] * 8, base, fb->pitches[0],
8806 plane_config->size);
8808 plane_config->fb = intel_fb;
8815 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
8816 struct intel_crtc_state *pipe_config)
8818 struct drm_device *dev = crtc->base.dev;
8819 struct drm_i915_private *dev_priv = to_i915(dev);
8822 tmp = I915_READ(PF_CTL(crtc->pipe));
8824 if (tmp & PF_ENABLE) {
8825 pipe_config->pch_pfit.enabled = true;
8826 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8827 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
8829 /* We currently do not free assignements of panel fitters on
8830 * ivb/hsw (since we don't use the higher upscaling modes which
8831 * differentiates them) so just WARN about this case for now. */
8832 if (IS_GEN7(dev_priv)) {
8833 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
8834 PF_PIPE_SEL_IVB(crtc->pipe));
8839 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
8840 struct intel_crtc_state *pipe_config)
8842 struct drm_device *dev = crtc->base.dev;
8843 struct drm_i915_private *dev_priv = to_i915(dev);
8844 enum intel_display_power_domain power_domain;
8848 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8849 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
8852 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8853 pipe_config->shared_dpll = NULL;
8856 tmp = I915_READ(PIPECONF(crtc->pipe));
8857 if (!(tmp & PIPECONF_ENABLE))
8860 switch (tmp & PIPECONF_BPC_MASK) {
8862 pipe_config->pipe_bpp = 18;
8865 pipe_config->pipe_bpp = 24;
8867 case PIPECONF_10BPC:
8868 pipe_config->pipe_bpp = 30;
8870 case PIPECONF_12BPC:
8871 pipe_config->pipe_bpp = 36;
8877 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8878 pipe_config->limited_color_range = true;
8880 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
8881 struct intel_shared_dpll *pll;
8882 enum intel_dpll_id pll_id;
8884 pipe_config->has_pch_encoder = true;
8886 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
8887 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8888 FDI_DP_PORT_WIDTH_SHIFT) + 1;
8890 ironlake_get_fdi_m_n_config(crtc, pipe_config);
8892 if (HAS_PCH_IBX(dev_priv)) {
8894 * The pipe->pch transcoder and pch transcoder->pll
8897 pll_id = (enum intel_dpll_id) crtc->pipe;
8899 tmp = I915_READ(PCH_DPLL_SEL);
8900 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
8901 pll_id = DPLL_ID_PCH_PLL_B;
8903 pll_id= DPLL_ID_PCH_PLL_A;
8906 pipe_config->shared_dpll =
8907 intel_get_shared_dpll_by_id(dev_priv, pll_id);
8908 pll = pipe_config->shared_dpll;
8910 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
8911 &pipe_config->dpll_hw_state));
8913 tmp = pipe_config->dpll_hw_state.dpll;
8914 pipe_config->pixel_multiplier =
8915 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
8916 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
8918 ironlake_pch_clock_get(crtc, pipe_config);
8920 pipe_config->pixel_multiplier = 1;
8923 intel_get_pipe_timings(crtc, pipe_config);
8924 intel_get_pipe_src_size(crtc, pipe_config);
8926 ironlake_get_pfit_config(crtc, pipe_config);
8931 intel_display_power_put(dev_priv, power_domain);
8936 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
8938 struct drm_device *dev = &dev_priv->drm;
8939 struct intel_crtc *crtc;
8941 for_each_intel_crtc(dev, crtc)
8942 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
8943 pipe_name(crtc->pipe));
8945 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
8946 "Display power well on\n");
8947 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
8948 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
8949 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
8950 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
8951 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
8952 "CPU PWM1 enabled\n");
8953 if (IS_HASWELL(dev_priv))
8954 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
8955 "CPU PWM2 enabled\n");
8956 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
8957 "PCH PWM1 enabled\n");
8958 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
8959 "Utility pin enabled\n");
8960 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
8963 * In theory we can still leave IRQs enabled, as long as only the HPD
8964 * interrupts remain enabled. We used to check for that, but since it's
8965 * gen-specific and since we only disable LCPLL after we fully disable
8966 * the interrupts, the check below should be enough.
8968 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
8971 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
8973 if (IS_HASWELL(dev_priv))
8974 return I915_READ(D_COMP_HSW);
8976 return I915_READ(D_COMP_BDW);
8979 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
8981 if (IS_HASWELL(dev_priv)) {
8982 mutex_lock(&dev_priv->pcu_lock);
8983 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
8985 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8986 mutex_unlock(&dev_priv->pcu_lock);
8988 I915_WRITE(D_COMP_BDW, val);
8989 POSTING_READ(D_COMP_BDW);
8994 * This function implements pieces of two sequences from BSpec:
8995 * - Sequence for display software to disable LCPLL
8996 * - Sequence for display software to allow package C8+
8997 * The steps implemented here are just the steps that actually touch the LCPLL
8998 * register. Callers should take care of disabling all the display engine
8999 * functions, doing the mode unset, fixing interrupts, etc.
9001 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9002 bool switch_to_fclk, bool allow_power_down)
9006 assert_can_disable_lcpll(dev_priv);
9008 val = I915_READ(LCPLL_CTL);
9010 if (switch_to_fclk) {
9011 val |= LCPLL_CD_SOURCE_FCLK;
9012 I915_WRITE(LCPLL_CTL, val);
9014 if (wait_for_us(I915_READ(LCPLL_CTL) &
9015 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9016 DRM_ERROR("Switching to FCLK failed\n");
9018 val = I915_READ(LCPLL_CTL);
9021 val |= LCPLL_PLL_DISABLE;
9022 I915_WRITE(LCPLL_CTL, val);
9023 POSTING_READ(LCPLL_CTL);
9025 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
9026 DRM_ERROR("LCPLL still locked\n");
9028 val = hsw_read_dcomp(dev_priv);
9029 val |= D_COMP_COMP_DISABLE;
9030 hsw_write_dcomp(dev_priv, val);
9033 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9035 DRM_ERROR("D_COMP RCOMP still in progress\n");
9037 if (allow_power_down) {
9038 val = I915_READ(LCPLL_CTL);
9039 val |= LCPLL_POWER_DOWN_ALLOW;
9040 I915_WRITE(LCPLL_CTL, val);
9041 POSTING_READ(LCPLL_CTL);
9046 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9049 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9053 val = I915_READ(LCPLL_CTL);
9055 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9056 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9060 * Make sure we're not on PC8 state before disabling PC8, otherwise
9061 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9063 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9065 if (val & LCPLL_POWER_DOWN_ALLOW) {
9066 val &= ~LCPLL_POWER_DOWN_ALLOW;
9067 I915_WRITE(LCPLL_CTL, val);
9068 POSTING_READ(LCPLL_CTL);
9071 val = hsw_read_dcomp(dev_priv);
9072 val |= D_COMP_COMP_FORCE;
9073 val &= ~D_COMP_COMP_DISABLE;
9074 hsw_write_dcomp(dev_priv, val);
9076 val = I915_READ(LCPLL_CTL);
9077 val &= ~LCPLL_PLL_DISABLE;
9078 I915_WRITE(LCPLL_CTL, val);
9080 if (intel_wait_for_register(dev_priv,
9081 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9083 DRM_ERROR("LCPLL not locked yet\n");
9085 if (val & LCPLL_CD_SOURCE_FCLK) {
9086 val = I915_READ(LCPLL_CTL);
9087 val &= ~LCPLL_CD_SOURCE_FCLK;
9088 I915_WRITE(LCPLL_CTL, val);
9090 if (wait_for_us((I915_READ(LCPLL_CTL) &
9091 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9092 DRM_ERROR("Switching back to LCPLL failed\n");
9095 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9097 intel_update_cdclk(dev_priv);
9098 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
9102 * Package states C8 and deeper are really deep PC states that can only be
9103 * reached when all the devices on the system allow it, so even if the graphics
9104 * device allows PC8+, it doesn't mean the system will actually get to these
9105 * states. Our driver only allows PC8+ when going into runtime PM.
9107 * The requirements for PC8+ are that all the outputs are disabled, the power
9108 * well is disabled and most interrupts are disabled, and these are also
9109 * requirements for runtime PM. When these conditions are met, we manually do
9110 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9111 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9114 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9115 * the state of some registers, so when we come back from PC8+ we need to
9116 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9117 * need to take care of the registers kept by RC6. Notice that this happens even
9118 * if we don't put the device in PCI D3 state (which is what currently happens
9119 * because of the runtime PM support).
9121 * For more, read "Display Sequences for Package C8" on the hardware
9124 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9128 DRM_DEBUG_KMS("Enabling package C8+\n");
9130 if (HAS_PCH_LPT_LP(dev_priv)) {
9131 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9132 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9133 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9136 lpt_disable_clkout_dp(dev_priv);
9137 hsw_disable_lcpll(dev_priv, true, true);
9140 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9144 DRM_DEBUG_KMS("Disabling package C8+\n");
9146 hsw_restore_lcpll(dev_priv);
9147 lpt_init_pch_refclk(dev_priv);
9149 if (HAS_PCH_LPT_LP(dev_priv)) {
9150 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9151 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9152 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9156 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9157 struct intel_crtc_state *crtc_state)
9159 struct intel_atomic_state *state =
9160 to_intel_atomic_state(crtc_state->base.state);
9162 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
9163 struct intel_encoder *encoder =
9164 intel_get_crtc_new_encoder(state, crtc_state);
9166 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9167 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9168 pipe_name(crtc->pipe));
9176 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9178 struct intel_crtc_state *pipe_config)
9180 enum intel_dpll_id id;
9183 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9184 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9186 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9189 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9192 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9194 struct intel_crtc_state *pipe_config)
9196 enum intel_dpll_id id;
9199 /* TODO: TBT pll not implemented. */
9203 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9204 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9205 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9207 if (WARN_ON(id != DPLL_ID_ICL_DPLL0 && id != DPLL_ID_ICL_DPLL1))
9211 id = DPLL_ID_ICL_MGPLL1;
9214 id = DPLL_ID_ICL_MGPLL2;
9217 id = DPLL_ID_ICL_MGPLL3;
9220 id = DPLL_ID_ICL_MGPLL4;
9227 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9230 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9232 struct intel_crtc_state *pipe_config)
9234 enum intel_dpll_id id;
9238 id = DPLL_ID_SKL_DPLL0;
9241 id = DPLL_ID_SKL_DPLL1;
9244 id = DPLL_ID_SKL_DPLL2;
9247 DRM_ERROR("Incorrect port type\n");
9251 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9254 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9256 struct intel_crtc_state *pipe_config)
9258 enum intel_dpll_id id;
9261 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9262 id = temp >> (port * 3 + 1);
9264 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9267 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9270 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9272 struct intel_crtc_state *pipe_config)
9274 enum intel_dpll_id id;
9275 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9277 switch (ddi_pll_sel) {
9278 case PORT_CLK_SEL_WRPLL1:
9279 id = DPLL_ID_WRPLL1;
9281 case PORT_CLK_SEL_WRPLL2:
9282 id = DPLL_ID_WRPLL2;
9284 case PORT_CLK_SEL_SPLL:
9287 case PORT_CLK_SEL_LCPLL_810:
9288 id = DPLL_ID_LCPLL_810;
9290 case PORT_CLK_SEL_LCPLL_1350:
9291 id = DPLL_ID_LCPLL_1350;
9293 case PORT_CLK_SEL_LCPLL_2700:
9294 id = DPLL_ID_LCPLL_2700;
9297 MISSING_CASE(ddi_pll_sel);
9299 case PORT_CLK_SEL_NONE:
9303 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9306 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9307 struct intel_crtc_state *pipe_config,
9308 u64 *power_domain_mask)
9310 struct drm_device *dev = crtc->base.dev;
9311 struct drm_i915_private *dev_priv = to_i915(dev);
9312 enum intel_display_power_domain power_domain;
9316 * The pipe->transcoder mapping is fixed with the exception of the eDP
9317 * transcoder handled below.
9319 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9322 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9323 * consistency and less surprising code; it's in always on power).
9325 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9326 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9327 enum pipe trans_edp_pipe;
9328 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9330 WARN(1, "unknown pipe linked to edp transcoder\n");
9332 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9333 case TRANS_DDI_EDP_INPUT_A_ON:
9334 trans_edp_pipe = PIPE_A;
9336 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9337 trans_edp_pipe = PIPE_B;
9339 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9340 trans_edp_pipe = PIPE_C;
9344 if (trans_edp_pipe == crtc->pipe)
9345 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9348 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9349 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9351 *power_domain_mask |= BIT_ULL(power_domain);
9353 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9355 return tmp & PIPECONF_ENABLE;
9358 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9359 struct intel_crtc_state *pipe_config,
9360 u64 *power_domain_mask)
9362 struct drm_device *dev = crtc->base.dev;
9363 struct drm_i915_private *dev_priv = to_i915(dev);
9364 enum intel_display_power_domain power_domain;
9366 enum transcoder cpu_transcoder;
9369 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9371 cpu_transcoder = TRANSCODER_DSI_A;
9373 cpu_transcoder = TRANSCODER_DSI_C;
9375 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9376 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9378 *power_domain_mask |= BIT_ULL(power_domain);
9381 * The PLL needs to be enabled with a valid divider
9382 * configuration, otherwise accessing DSI registers will hang
9383 * the machine. See BSpec North Display Engine
9384 * registers/MIPI[BXT]. We can break out here early, since we
9385 * need the same DSI PLL to be enabled for both DSI ports.
9387 if (!bxt_dsi_pll_is_enabled(dev_priv))
9390 /* XXX: this works for video mode only */
9391 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9392 if (!(tmp & DPI_ENABLE))
9395 tmp = I915_READ(MIPI_CTRL(port));
9396 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9399 pipe_config->cpu_transcoder = cpu_transcoder;
9403 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9406 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9407 struct intel_crtc_state *pipe_config)
9409 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9410 struct intel_shared_dpll *pll;
9414 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9416 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9418 if (IS_ICELAKE(dev_priv))
9419 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9420 else if (IS_CANNONLAKE(dev_priv))
9421 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9422 else if (IS_GEN9_BC(dev_priv))
9423 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9424 else if (IS_GEN9_LP(dev_priv))
9425 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9427 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9429 pll = pipe_config->shared_dpll;
9431 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9432 &pipe_config->dpll_hw_state));
9436 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9437 * DDI E. So just check whether this pipe is wired to DDI E and whether
9438 * the PCH transcoder is on.
9440 if (INTEL_GEN(dev_priv) < 9 &&
9441 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9442 pipe_config->has_pch_encoder = true;
9444 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9445 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9446 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9448 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9452 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9453 struct intel_crtc_state *pipe_config)
9455 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9456 enum intel_display_power_domain power_domain;
9457 u64 power_domain_mask;
9460 intel_crtc_init_scalers(crtc, pipe_config);
9462 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9463 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9465 power_domain_mask = BIT_ULL(power_domain);
9467 pipe_config->shared_dpll = NULL;
9469 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9471 if (IS_GEN9_LP(dev_priv) &&
9472 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9480 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9481 haswell_get_ddi_port_state(crtc, pipe_config);
9482 intel_get_pipe_timings(crtc, pipe_config);
9485 intel_get_pipe_src_size(crtc, pipe_config);
9487 pipe_config->gamma_mode =
9488 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9490 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
9491 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
9492 bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV;
9494 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
9495 bool blend_mode_420 = tmp &
9496 PIPEMISC_YUV420_MODE_FULL_BLEND;
9498 pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE;
9499 if (pipe_config->ycbcr420 != clrspace_yuv ||
9500 pipe_config->ycbcr420 != blend_mode_420)
9501 DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp);
9502 } else if (clrspace_yuv) {
9503 DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
9507 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9508 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9509 power_domain_mask |= BIT_ULL(power_domain);
9510 if (INTEL_GEN(dev_priv) >= 9)
9511 skylake_get_pfit_config(crtc, pipe_config);
9513 ironlake_get_pfit_config(crtc, pipe_config);
9516 if (hsw_crtc_supports_ips(crtc)) {
9517 if (IS_HASWELL(dev_priv))
9518 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9521 * We cannot readout IPS state on broadwell, set to
9522 * true so we can set it to a defined state on first
9525 pipe_config->ips_enabled = true;
9529 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9530 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9531 pipe_config->pixel_multiplier =
9532 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9534 pipe_config->pixel_multiplier = 1;
9538 for_each_power_domain(power_domain, power_domain_mask)
9539 intel_display_power_put(dev_priv, power_domain);
9544 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9546 struct drm_i915_private *dev_priv =
9547 to_i915(plane_state->base.plane->dev);
9548 const struct drm_framebuffer *fb = plane_state->base.fb;
9549 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9552 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9553 base = obj->phys_handle->busaddr;
9555 base = intel_plane_ggtt_offset(plane_state);
9557 base += plane_state->color_plane[0].offset;
9559 /* ILK+ do this automagically */
9560 if (HAS_GMCH_DISPLAY(dev_priv) &&
9561 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9562 base += (plane_state->base.crtc_h *
9563 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9568 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9570 int x = plane_state->base.crtc_x;
9571 int y = plane_state->base.crtc_y;
9575 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9578 pos |= x << CURSOR_X_SHIFT;
9581 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9584 pos |= y << CURSOR_Y_SHIFT;
9589 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9591 const struct drm_mode_config *config =
9592 &plane_state->base.plane->dev->mode_config;
9593 int width = plane_state->base.crtc_w;
9594 int height = plane_state->base.crtc_h;
9596 return width > 0 && width <= config->cursor_width &&
9597 height > 0 && height <= config->cursor_height;
9600 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
9602 const struct drm_framebuffer *fb = plane_state->base.fb;
9603 unsigned int rotation = plane_state->base.rotation;
9608 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
9609 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
9611 ret = intel_plane_check_stride(plane_state);
9615 src_x = plane_state->base.src_x >> 16;
9616 src_y = plane_state->base.src_y >> 16;
9618 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9619 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
9622 if (src_x != 0 || src_y != 0) {
9623 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9627 plane_state->color_plane[0].offset = offset;
9632 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9633 struct intel_plane_state *plane_state)
9635 const struct drm_framebuffer *fb = plane_state->base.fb;
9638 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9639 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9643 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9645 DRM_PLANE_HELPER_NO_SCALING,
9646 DRM_PLANE_HELPER_NO_SCALING,
9651 if (!plane_state->base.visible)
9654 ret = intel_plane_check_src_coordinates(plane_state);
9658 ret = intel_cursor_check_surface(plane_state);
9666 i845_cursor_max_stride(struct intel_plane *plane,
9667 u32 pixel_format, u64 modifier,
9668 unsigned int rotation)
9673 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9674 const struct intel_plane_state *plane_state)
9676 return CURSOR_ENABLE |
9677 CURSOR_GAMMA_ENABLE |
9678 CURSOR_FORMAT_ARGB |
9679 CURSOR_STRIDE(plane_state->color_plane[0].stride);
9682 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9684 int width = plane_state->base.crtc_w;
9687 * 845g/865g are only limited by the width of their cursors,
9688 * the height is arbitrary up to the precision of the register.
9690 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
9693 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
9694 struct intel_plane_state *plane_state)
9696 const struct drm_framebuffer *fb = plane_state->base.fb;
9699 ret = intel_check_cursor(crtc_state, plane_state);
9703 /* if we want to turn off the cursor ignore width and height */
9707 /* Check for which cursor types we support */
9708 if (!i845_cursor_size_ok(plane_state)) {
9709 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9710 plane_state->base.crtc_w,
9711 plane_state->base.crtc_h);
9715 WARN_ON(plane_state->base.visible &&
9716 plane_state->color_plane[0].stride != fb->pitches[0]);
9718 switch (fb->pitches[0]) {
9725 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9730 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9735 static void i845_update_cursor(struct intel_plane *plane,
9736 const struct intel_crtc_state *crtc_state,
9737 const struct intel_plane_state *plane_state)
9739 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9740 u32 cntl = 0, base = 0, pos = 0, size = 0;
9741 unsigned long irqflags;
9743 if (plane_state && plane_state->base.visible) {
9744 unsigned int width = plane_state->base.crtc_w;
9745 unsigned int height = plane_state->base.crtc_h;
9747 cntl = plane_state->ctl;
9748 size = (height << 12) | width;
9750 base = intel_cursor_base(plane_state);
9751 pos = intel_cursor_position(plane_state);
9754 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9756 /* On these chipsets we can only modify the base/size/stride
9757 * whilst the cursor is disabled.
9759 if (plane->cursor.base != base ||
9760 plane->cursor.size != size ||
9761 plane->cursor.cntl != cntl) {
9762 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
9763 I915_WRITE_FW(CURBASE(PIPE_A), base);
9764 I915_WRITE_FW(CURSIZE, size);
9765 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9766 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
9768 plane->cursor.base = base;
9769 plane->cursor.size = size;
9770 plane->cursor.cntl = cntl;
9772 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9775 POSTING_READ_FW(CURCNTR(PIPE_A));
9777 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9780 static void i845_disable_cursor(struct intel_plane *plane,
9781 struct intel_crtc *crtc)
9783 i845_update_cursor(plane, NULL, NULL);
9786 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
9789 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9790 enum intel_display_power_domain power_domain;
9793 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9794 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9797 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9801 intel_display_power_put(dev_priv, power_domain);
9807 i9xx_cursor_max_stride(struct intel_plane *plane,
9808 u32 pixel_format, u64 modifier,
9809 unsigned int rotation)
9811 return plane->base.dev->mode_config.cursor_width * 4;
9814 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9815 const struct intel_plane_state *plane_state)
9817 struct drm_i915_private *dev_priv =
9818 to_i915(plane_state->base.plane->dev);
9819 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9822 if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
9823 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
9825 if (INTEL_GEN(dev_priv) <= 10) {
9826 cntl |= MCURSOR_GAMMA_ENABLE;
9828 if (HAS_DDI(dev_priv))
9829 cntl |= MCURSOR_PIPE_CSC_ENABLE;
9832 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9833 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
9835 switch (plane_state->base.crtc_w) {
9837 cntl |= MCURSOR_MODE_64_ARGB_AX;
9840 cntl |= MCURSOR_MODE_128_ARGB_AX;
9843 cntl |= MCURSOR_MODE_256_ARGB_AX;
9846 MISSING_CASE(plane_state->base.crtc_w);
9850 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
9851 cntl |= MCURSOR_ROTATE_180;
9856 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
9858 struct drm_i915_private *dev_priv =
9859 to_i915(plane_state->base.plane->dev);
9860 int width = plane_state->base.crtc_w;
9861 int height = plane_state->base.crtc_h;
9863 if (!intel_cursor_size_ok(plane_state))
9866 /* Cursor width is limited to a few power-of-two sizes */
9877 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9878 * height from 8 lines up to the cursor width, when the
9879 * cursor is not rotated. Everything else requires square
9882 if (HAS_CUR_FBC(dev_priv) &&
9883 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
9884 if (height < 8 || height > width)
9887 if (height != width)
9894 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
9895 struct intel_plane_state *plane_state)
9897 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
9898 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9899 const struct drm_framebuffer *fb = plane_state->base.fb;
9900 enum pipe pipe = plane->pipe;
9903 ret = intel_check_cursor(crtc_state, plane_state);
9907 /* if we want to turn off the cursor ignore width and height */
9911 /* Check for which cursor types we support */
9912 if (!i9xx_cursor_size_ok(plane_state)) {
9913 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9914 plane_state->base.crtc_w,
9915 plane_state->base.crtc_h);
9919 WARN_ON(plane_state->base.visible &&
9920 plane_state->color_plane[0].stride != fb->pitches[0]);
9922 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
9923 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9924 fb->pitches[0], plane_state->base.crtc_w);
9929 * There's something wrong with the cursor on CHV pipe C.
9930 * If it straddles the left edge of the screen then
9931 * moving it away from the edge or disabling it often
9932 * results in a pipe underrun, and often that can lead to
9933 * dead pipe (constant underrun reported, and it scans
9934 * out just a solid color). To recover from that, the
9935 * display power well must be turned off and on again.
9936 * Refuse the put the cursor into that compromised position.
9938 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
9939 plane_state->base.visible && plane_state->base.crtc_x < 0) {
9940 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9944 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
9949 static void i9xx_update_cursor(struct intel_plane *plane,
9950 const struct intel_crtc_state *crtc_state,
9951 const struct intel_plane_state *plane_state)
9953 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9954 enum pipe pipe = plane->pipe;
9955 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
9956 unsigned long irqflags;
9958 if (plane_state && plane_state->base.visible) {
9959 cntl = plane_state->ctl;
9961 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
9962 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
9964 base = intel_cursor_base(plane_state);
9965 pos = intel_cursor_position(plane_state);
9968 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9971 * On some platforms writing CURCNTR first will also
9972 * cause CURPOS to be armed by the CURBASE write.
9973 * Without the CURCNTR write the CURPOS write would
9974 * arm itself. Thus we always start the full update
9975 * with a CURCNTR write.
9977 * On other platforms CURPOS always requires the
9978 * CURBASE write to arm the update. Additonally
9979 * a write to any of the cursor register will cancel
9980 * an already armed cursor update. Thus leaving out
9981 * the CURBASE write after CURPOS could lead to a
9982 * cursor that doesn't appear to move, or even change
9983 * shape. Thus we always write CURBASE.
9985 * CURCNTR and CUR_FBC_CTL are always
9986 * armed by the CURBASE write only.
9988 if (plane->cursor.base != base ||
9989 plane->cursor.size != fbc_ctl ||
9990 plane->cursor.cntl != cntl) {
9991 I915_WRITE_FW(CURCNTR(pipe), cntl);
9992 if (HAS_CUR_FBC(dev_priv))
9993 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
9994 I915_WRITE_FW(CURPOS(pipe), pos);
9995 I915_WRITE_FW(CURBASE(pipe), base);
9997 plane->cursor.base = base;
9998 plane->cursor.size = fbc_ctl;
9999 plane->cursor.cntl = cntl;
10001 I915_WRITE_FW(CURPOS(pipe), pos);
10002 I915_WRITE_FW(CURBASE(pipe), base);
10005 POSTING_READ_FW(CURBASE(pipe));
10007 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10010 static void i9xx_disable_cursor(struct intel_plane *plane,
10011 struct intel_crtc *crtc)
10013 i9xx_update_cursor(plane, NULL, NULL);
10016 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10019 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10020 enum intel_display_power_domain power_domain;
10025 * Not 100% correct for planes that can move between pipes,
10026 * but that's only the case for gen2-3 which don't have any
10027 * display power wells.
10029 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
10030 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
10033 val = I915_READ(CURCNTR(plane->pipe));
10035 ret = val & MCURSOR_MODE;
10037 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10038 *pipe = plane->pipe;
10040 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10041 MCURSOR_PIPE_SELECT_SHIFT;
10043 intel_display_power_put(dev_priv, power_domain);
10048 /* VESA 640x480x72Hz mode to set on the pipe */
10049 static const struct drm_display_mode load_detect_mode = {
10050 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10051 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10054 struct drm_framebuffer *
10055 intel_framebuffer_create(struct drm_i915_gem_object *obj,
10056 struct drm_mode_fb_cmd2 *mode_cmd)
10058 struct intel_framebuffer *intel_fb;
10061 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10063 return ERR_PTR(-ENOMEM);
10065 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
10069 return &intel_fb->base;
10073 return ERR_PTR(ret);
10076 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10077 struct drm_crtc *crtc)
10079 struct drm_plane *plane;
10080 struct drm_plane_state *plane_state;
10083 ret = drm_atomic_add_affected_planes(state, crtc);
10087 for_each_new_plane_in_state(state, plane, plane_state, i) {
10088 if (plane_state->crtc != crtc)
10091 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10095 drm_atomic_set_fb_for_plane(plane_state, NULL);
10101 int intel_get_load_detect_pipe(struct drm_connector *connector,
10102 const struct drm_display_mode *mode,
10103 struct intel_load_detect_pipe *old,
10104 struct drm_modeset_acquire_ctx *ctx)
10106 struct intel_crtc *intel_crtc;
10107 struct intel_encoder *intel_encoder =
10108 intel_attached_encoder(connector);
10109 struct drm_crtc *possible_crtc;
10110 struct drm_encoder *encoder = &intel_encoder->base;
10111 struct drm_crtc *crtc = NULL;
10112 struct drm_device *dev = encoder->dev;
10113 struct drm_i915_private *dev_priv = to_i915(dev);
10114 struct drm_mode_config *config = &dev->mode_config;
10115 struct drm_atomic_state *state = NULL, *restore_state = NULL;
10116 struct drm_connector_state *connector_state;
10117 struct intel_crtc_state *crtc_state;
10120 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10121 connector->base.id, connector->name,
10122 encoder->base.id, encoder->name);
10124 old->restore_state = NULL;
10126 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
10129 * Algorithm gets a little messy:
10131 * - if the connector already has an assigned crtc, use it (but make
10132 * sure it's on first)
10134 * - try to find the first unused crtc that can drive this connector,
10135 * and use that if we find one
10138 /* See if we already have a CRTC for this connector */
10139 if (connector->state->crtc) {
10140 crtc = connector->state->crtc;
10142 ret = drm_modeset_lock(&crtc->mutex, ctx);
10146 /* Make sure the crtc and connector are running */
10150 /* Find an unused one (if possible) */
10151 for_each_crtc(dev, possible_crtc) {
10153 if (!(encoder->possible_crtcs & (1 << i)))
10156 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10160 if (possible_crtc->state->enable) {
10161 drm_modeset_unlock(&possible_crtc->mutex);
10165 crtc = possible_crtc;
10170 * If we didn't find an unused CRTC, don't use any.
10173 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10179 intel_crtc = to_intel_crtc(crtc);
10181 state = drm_atomic_state_alloc(dev);
10182 restore_state = drm_atomic_state_alloc(dev);
10183 if (!state || !restore_state) {
10188 state->acquire_ctx = ctx;
10189 restore_state->acquire_ctx = ctx;
10191 connector_state = drm_atomic_get_connector_state(state, connector);
10192 if (IS_ERR(connector_state)) {
10193 ret = PTR_ERR(connector_state);
10197 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10201 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10202 if (IS_ERR(crtc_state)) {
10203 ret = PTR_ERR(crtc_state);
10207 crtc_state->base.active = crtc_state->base.enable = true;
10210 mode = &load_detect_mode;
10212 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
10216 ret = intel_modeset_disable_planes(state, crtc);
10220 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10222 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
10224 ret = drm_atomic_add_affected_planes(restore_state, crtc);
10226 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10230 ret = drm_atomic_commit(state);
10232 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10236 old->restore_state = restore_state;
10237 drm_atomic_state_put(state);
10239 /* let the connector get through one full cycle before testing */
10240 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
10245 drm_atomic_state_put(state);
10248 if (restore_state) {
10249 drm_atomic_state_put(restore_state);
10250 restore_state = NULL;
10253 if (ret == -EDEADLK)
10259 void intel_release_load_detect_pipe(struct drm_connector *connector,
10260 struct intel_load_detect_pipe *old,
10261 struct drm_modeset_acquire_ctx *ctx)
10263 struct intel_encoder *intel_encoder =
10264 intel_attached_encoder(connector);
10265 struct drm_encoder *encoder = &intel_encoder->base;
10266 struct drm_atomic_state *state = old->restore_state;
10269 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10270 connector->base.id, connector->name,
10271 encoder->base.id, encoder->name);
10276 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10278 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10279 drm_atomic_state_put(state);
10282 static int i9xx_pll_refclk(struct drm_device *dev,
10283 const struct intel_crtc_state *pipe_config)
10285 struct drm_i915_private *dev_priv = to_i915(dev);
10286 u32 dpll = pipe_config->dpll_hw_state.dpll;
10288 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10289 return dev_priv->vbt.lvds_ssc_freq;
10290 else if (HAS_PCH_SPLIT(dev_priv))
10292 else if (!IS_GEN2(dev_priv))
10298 /* Returns the clock of the currently programmed mode of the given pipe. */
10299 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10300 struct intel_crtc_state *pipe_config)
10302 struct drm_device *dev = crtc->base.dev;
10303 struct drm_i915_private *dev_priv = to_i915(dev);
10304 int pipe = pipe_config->cpu_transcoder;
10305 u32 dpll = pipe_config->dpll_hw_state.dpll;
10309 int refclk = i9xx_pll_refclk(dev, pipe_config);
10311 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10312 fp = pipe_config->dpll_hw_state.fp0;
10314 fp = pipe_config->dpll_hw_state.fp1;
10316 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10317 if (IS_PINEVIEW(dev_priv)) {
10318 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10319 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10321 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10322 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10325 if (!IS_GEN2(dev_priv)) {
10326 if (IS_PINEVIEW(dev_priv))
10327 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10328 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10330 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10331 DPLL_FPA01_P1_POST_DIV_SHIFT);
10333 switch (dpll & DPLL_MODE_MASK) {
10334 case DPLLB_MODE_DAC_SERIAL:
10335 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10338 case DPLLB_MODE_LVDS:
10339 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10343 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10344 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10348 if (IS_PINEVIEW(dev_priv))
10349 port_clock = pnv_calc_dpll_params(refclk, &clock);
10351 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10353 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10354 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10357 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10358 DPLL_FPA01_P1_POST_DIV_SHIFT);
10360 if (lvds & LVDS_CLKB_POWER_UP)
10365 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10368 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10369 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10371 if (dpll & PLL_P2_DIVIDE_BY_4)
10377 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10381 * This value includes pixel_multiplier. We will use
10382 * port_clock to compute adjusted_mode.crtc_clock in the
10383 * encoder's get_config() function.
10385 pipe_config->port_clock = port_clock;
10388 int intel_dotclock_calculate(int link_freq,
10389 const struct intel_link_m_n *m_n)
10392 * The calculation for the data clock is:
10393 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10394 * But we want to avoid losing precison if possible, so:
10395 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10397 * and the link clock is simpler:
10398 * link_clock = (m * link_clock) / n
10404 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10407 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10408 struct intel_crtc_state *pipe_config)
10410 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10412 /* read out port_clock from the DPLL */
10413 i9xx_crtc_clock_get(crtc, pipe_config);
10416 * In case there is an active pipe without active ports,
10417 * we may need some idea for the dotclock anyway.
10418 * Calculate one based on the FDI configuration.
10420 pipe_config->base.adjusted_mode.crtc_clock =
10421 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10422 &pipe_config->fdi_m_n);
10425 /* Returns the currently programmed mode of the given encoder. */
10426 struct drm_display_mode *
10427 intel_encoder_current_mode(struct intel_encoder *encoder)
10429 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10430 struct intel_crtc_state *crtc_state;
10431 struct drm_display_mode *mode;
10432 struct intel_crtc *crtc;
10435 if (!encoder->get_hw_state(encoder, &pipe))
10438 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10440 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10444 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10450 crtc_state->base.crtc = &crtc->base;
10452 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10458 encoder->get_config(encoder, crtc_state);
10460 intel_mode_from_pipe_config(mode, crtc_state);
10467 static void intel_crtc_destroy(struct drm_crtc *crtc)
10469 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10471 drm_crtc_cleanup(crtc);
10476 * intel_wm_need_update - Check whether watermarks need updating
10477 * @plane: drm plane
10478 * @state: new plane state
10480 * Check current plane state versus the new one to determine whether
10481 * watermarks need to be recalculated.
10483 * Returns true or false.
10485 static bool intel_wm_need_update(struct drm_plane *plane,
10486 struct drm_plane_state *state)
10488 struct intel_plane_state *new = to_intel_plane_state(state);
10489 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10491 /* Update watermarks on tiling or size changes. */
10492 if (new->base.visible != cur->base.visible)
10495 if (!cur->base.fb || !new->base.fb)
10498 if (cur->base.fb->modifier != new->base.fb->modifier ||
10499 cur->base.rotation != new->base.rotation ||
10500 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10501 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10502 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10503 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10509 static bool needs_scaling(const struct intel_plane_state *state)
10511 int src_w = drm_rect_width(&state->base.src) >> 16;
10512 int src_h = drm_rect_height(&state->base.src) >> 16;
10513 int dst_w = drm_rect_width(&state->base.dst);
10514 int dst_h = drm_rect_height(&state->base.dst);
10516 return (src_w != dst_w || src_h != dst_h);
10519 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10520 struct drm_crtc_state *crtc_state,
10521 const struct intel_plane_state *old_plane_state,
10522 struct drm_plane_state *plane_state)
10524 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10525 struct drm_crtc *crtc = crtc_state->crtc;
10526 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10527 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10528 struct drm_device *dev = crtc->dev;
10529 struct drm_i915_private *dev_priv = to_i915(dev);
10530 bool mode_changed = needs_modeset(crtc_state);
10531 bool was_crtc_enabled = old_crtc_state->base.active;
10532 bool is_crtc_enabled = crtc_state->active;
10533 bool turn_off, turn_on, visible, was_visible;
10534 struct drm_framebuffer *fb = plane_state->fb;
10537 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10538 ret = skl_update_scaler_plane(
10539 to_intel_crtc_state(crtc_state),
10540 to_intel_plane_state(plane_state));
10545 was_visible = old_plane_state->base.visible;
10546 visible = plane_state->visible;
10548 if (!was_crtc_enabled && WARN_ON(was_visible))
10549 was_visible = false;
10552 * Visibility is calculated as if the crtc was on, but
10553 * after scaler setup everything depends on it being off
10554 * when the crtc isn't active.
10556 * FIXME this is wrong for watermarks. Watermarks should also
10557 * be computed as if the pipe would be active. Perhaps move
10558 * per-plane wm computation to the .check_plane() hook, and
10559 * only combine the results from all planes in the current place?
10561 if (!is_crtc_enabled) {
10562 plane_state->visible = visible = false;
10563 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10566 if (!was_visible && !visible)
10569 if (fb != old_plane_state->base.fb)
10570 pipe_config->fb_changed = true;
10572 turn_off = was_visible && (!visible || mode_changed);
10573 turn_on = visible && (!was_visible || mode_changed);
10575 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10576 intel_crtc->base.base.id, intel_crtc->base.name,
10577 plane->base.base.id, plane->base.name,
10578 fb ? fb->base.id : -1);
10580 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10581 plane->base.base.id, plane->base.name,
10582 was_visible, visible,
10583 turn_off, turn_on, mode_changed);
10586 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10587 pipe_config->update_wm_pre = true;
10589 /* must disable cxsr around plane enable/disable */
10590 if (plane->id != PLANE_CURSOR)
10591 pipe_config->disable_cxsr = true;
10592 } else if (turn_off) {
10593 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10594 pipe_config->update_wm_post = true;
10596 /* must disable cxsr around plane enable/disable */
10597 if (plane->id != PLANE_CURSOR)
10598 pipe_config->disable_cxsr = true;
10599 } else if (intel_wm_need_update(&plane->base, plane_state)) {
10600 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
10601 /* FIXME bollocks */
10602 pipe_config->update_wm_pre = true;
10603 pipe_config->update_wm_post = true;
10607 if (visible || was_visible)
10608 pipe_config->fb_bits |= plane->frontbuffer_bit;
10611 * ILK/SNB DVSACNTR/Sprite Enable
10612 * IVB SPR_CTL/Sprite Enable
10613 * "When in Self Refresh Big FIFO mode, a write to enable the
10614 * plane will be internally buffered and delayed while Big FIFO
10615 * mode is exiting."
10617 * Which means that enabling the sprite can take an extra frame
10618 * when we start in big FIFO mode (LP1+). Thus we need to drop
10619 * down to LP0 and wait for vblank in order to make sure the
10620 * sprite gets enabled on the next vblank after the register write.
10621 * Doing otherwise would risk enabling the sprite one frame after
10622 * we've already signalled flip completion. We can resume LP1+
10623 * once the sprite has been enabled.
10626 * WaCxSRDisabledForSpriteScaling:ivb
10627 * IVB SPR_SCALE/Scaling Enable
10628 * "Low Power watermarks must be disabled for at least one
10629 * frame before enabling sprite scaling, and kept disabled
10630 * until sprite scaling is disabled."
10632 * ILK/SNB DVSASCALE/Scaling Enable
10633 * "When in Self Refresh Big FIFO mode, scaling enable will be
10634 * masked off while Big FIFO mode is exiting."
10636 * Despite the w/a only being listed for IVB we assume that
10637 * the ILK/SNB note has similar ramifications, hence we apply
10638 * the w/a on all three platforms.
10640 if (plane->id == PLANE_SPRITE0 &&
10641 (IS_GEN5(dev_priv) || IS_GEN6(dev_priv) ||
10642 IS_IVYBRIDGE(dev_priv)) &&
10643 (turn_on || (!needs_scaling(old_plane_state) &&
10644 needs_scaling(to_intel_plane_state(plane_state)))))
10645 pipe_config->disable_lp_wm = true;
10650 static bool encoders_cloneable(const struct intel_encoder *a,
10651 const struct intel_encoder *b)
10653 /* masks could be asymmetric, so check both ways */
10654 return a == b || (a->cloneable & (1 << b->type) &&
10655 b->cloneable & (1 << a->type));
10658 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10659 struct intel_crtc *crtc,
10660 struct intel_encoder *encoder)
10662 struct intel_encoder *source_encoder;
10663 struct drm_connector *connector;
10664 struct drm_connector_state *connector_state;
10667 for_each_new_connector_in_state(state, connector, connector_state, i) {
10668 if (connector_state->crtc != &crtc->base)
10672 to_intel_encoder(connector_state->best_encoder);
10673 if (!encoders_cloneable(encoder, source_encoder))
10680 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10681 struct drm_crtc_state *crtc_state)
10683 struct drm_device *dev = crtc->dev;
10684 struct drm_i915_private *dev_priv = to_i915(dev);
10685 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10686 struct intel_crtc_state *pipe_config =
10687 to_intel_crtc_state(crtc_state);
10688 struct drm_atomic_state *state = crtc_state->state;
10690 bool mode_changed = needs_modeset(crtc_state);
10692 if (mode_changed && !crtc_state->active)
10693 pipe_config->update_wm_post = true;
10695 if (mode_changed && crtc_state->enable &&
10696 dev_priv->display.crtc_compute_clock &&
10697 !WARN_ON(pipe_config->shared_dpll)) {
10698 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10704 if (crtc_state->color_mgmt_changed) {
10705 ret = intel_color_check(crtc, crtc_state);
10710 * Changing color management on Intel hardware is
10711 * handled as part of planes update.
10713 crtc_state->planes_changed = true;
10717 if (dev_priv->display.compute_pipe_wm) {
10718 ret = dev_priv->display.compute_pipe_wm(pipe_config);
10720 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10725 if (dev_priv->display.compute_intermediate_wm &&
10726 !to_intel_atomic_state(state)->skip_intermediate_wm) {
10727 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10731 * Calculate 'intermediate' watermarks that satisfy both the
10732 * old state and the new state. We can program these
10735 ret = dev_priv->display.compute_intermediate_wm(dev,
10739 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10742 } else if (dev_priv->display.compute_intermediate_wm) {
10743 if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
10744 pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
10747 if (INTEL_GEN(dev_priv) >= 9) {
10749 ret = skl_update_scaler_crtc(pipe_config);
10752 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10755 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
10759 if (HAS_IPS(dev_priv))
10760 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10765 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
10766 .atomic_check = intel_crtc_atomic_check,
10769 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10771 struct intel_connector *connector;
10772 struct drm_connector_list_iter conn_iter;
10774 drm_connector_list_iter_begin(dev, &conn_iter);
10775 for_each_intel_connector_iter(connector, &conn_iter) {
10776 if (connector->base.state->crtc)
10777 drm_connector_put(&connector->base);
10779 if (connector->base.encoder) {
10780 connector->base.state->best_encoder =
10781 connector->base.encoder;
10782 connector->base.state->crtc =
10783 connector->base.encoder->crtc;
10785 drm_connector_get(&connector->base);
10787 connector->base.state->best_encoder = NULL;
10788 connector->base.state->crtc = NULL;
10791 drm_connector_list_iter_end(&conn_iter);
10795 connected_sink_compute_bpp(struct intel_connector *connector,
10796 struct intel_crtc_state *pipe_config)
10798 const struct drm_display_info *info = &connector->base.display_info;
10799 int bpp = pipe_config->pipe_bpp;
10801 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10802 connector->base.base.id,
10803 connector->base.name);
10805 /* Don't use an invalid EDID bpc value */
10806 if (info->bpc != 0 && info->bpc * 3 < bpp) {
10807 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10808 bpp, info->bpc * 3);
10809 pipe_config->pipe_bpp = info->bpc * 3;
10812 /* Clamp bpp to 8 on screens without EDID 1.4 */
10813 if (info->bpc == 0 && bpp > 24) {
10814 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10816 pipe_config->pipe_bpp = 24;
10821 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
10822 struct intel_crtc_state *pipe_config)
10824 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10825 struct drm_atomic_state *state;
10826 struct drm_connector *connector;
10827 struct drm_connector_state *connector_state;
10830 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10831 IS_CHERRYVIEW(dev_priv)))
10833 else if (INTEL_GEN(dev_priv) >= 5)
10839 pipe_config->pipe_bpp = bpp;
10841 state = pipe_config->base.state;
10843 /* Clamp display bpp to EDID value */
10844 for_each_new_connector_in_state(state, connector, connector_state, i) {
10845 if (connector_state->crtc != &crtc->base)
10848 connected_sink_compute_bpp(to_intel_connector(connector),
10855 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
10857 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10858 "type: 0x%x flags: 0x%x\n",
10860 mode->crtc_hdisplay, mode->crtc_hsync_start,
10861 mode->crtc_hsync_end, mode->crtc_htotal,
10862 mode->crtc_vdisplay, mode->crtc_vsync_start,
10863 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
10867 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
10868 unsigned int lane_count, struct intel_link_m_n *m_n)
10870 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10872 m_n->gmch_m, m_n->gmch_n,
10873 m_n->link_m, m_n->link_n, m_n->tu);
10876 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
10878 static const char * const output_type_str[] = {
10879 OUTPUT_TYPE(UNUSED),
10880 OUTPUT_TYPE(ANALOG),
10884 OUTPUT_TYPE(TVOUT),
10890 OUTPUT_TYPE(DP_MST),
10895 static void snprintf_output_types(char *buf, size_t len,
10896 unsigned int output_types)
10903 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
10906 if ((output_types & BIT(i)) == 0)
10909 r = snprintf(str, len, "%s%s",
10910 str != buf ? "," : "", output_type_str[i]);
10916 output_types &= ~BIT(i);
10919 WARN_ON_ONCE(output_types != 0);
10922 static void intel_dump_pipe_config(struct intel_crtc *crtc,
10923 struct intel_crtc_state *pipe_config,
10924 const char *context)
10926 struct drm_device *dev = crtc->base.dev;
10927 struct drm_i915_private *dev_priv = to_i915(dev);
10928 struct drm_plane *plane;
10929 struct intel_plane *intel_plane;
10930 struct intel_plane_state *state;
10931 struct drm_framebuffer *fb;
10934 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10935 crtc->base.base.id, crtc->base.name, context);
10937 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
10938 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
10939 buf, pipe_config->output_types);
10941 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10942 transcoder_name(pipe_config->cpu_transcoder),
10943 pipe_config->pipe_bpp, pipe_config->dither);
10945 if (pipe_config->has_pch_encoder)
10946 intel_dump_m_n_config(pipe_config, "fdi",
10947 pipe_config->fdi_lanes,
10948 &pipe_config->fdi_m_n);
10950 if (pipe_config->ycbcr420)
10951 DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
10953 if (intel_crtc_has_dp_encoder(pipe_config)) {
10954 intel_dump_m_n_config(pipe_config, "dp m_n",
10955 pipe_config->lane_count, &pipe_config->dp_m_n);
10956 if (pipe_config->has_drrs)
10957 intel_dump_m_n_config(pipe_config, "dp m2_n2",
10958 pipe_config->lane_count,
10959 &pipe_config->dp_m2_n2);
10962 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10963 pipe_config->has_audio, pipe_config->has_infoframe);
10965 DRM_DEBUG_KMS("requested mode:\n");
10966 drm_mode_debug_printmodeline(&pipe_config->base.mode);
10967 DRM_DEBUG_KMS("adjusted mode:\n");
10968 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
10969 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
10970 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10971 pipe_config->port_clock,
10972 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
10973 pipe_config->pixel_rate);
10975 if (INTEL_GEN(dev_priv) >= 9)
10976 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10978 pipe_config->scaler_state.scaler_users,
10979 pipe_config->scaler_state.scaler_id);
10981 if (HAS_GMCH_DISPLAY(dev_priv))
10982 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10983 pipe_config->gmch_pfit.control,
10984 pipe_config->gmch_pfit.pgm_ratios,
10985 pipe_config->gmch_pfit.lvds_border_bits);
10987 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10988 pipe_config->pch_pfit.pos,
10989 pipe_config->pch_pfit.size,
10990 enableddisabled(pipe_config->pch_pfit.enabled));
10992 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10993 pipe_config->ips_enabled, pipe_config->double_wide);
10995 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
10997 DRM_DEBUG_KMS("planes on this crtc\n");
10998 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
10999 struct drm_format_name_buf format_name;
11000 intel_plane = to_intel_plane(plane);
11001 if (intel_plane->pipe != crtc->pipe)
11004 state = to_intel_plane_state(plane->state);
11005 fb = state->base.fb;
11007 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11008 plane->base.id, plane->name, state->scaler_id);
11012 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11013 plane->base.id, plane->name,
11014 fb->base.id, fb->width, fb->height,
11015 drm_get_format_name(fb->format->format, &format_name));
11016 if (INTEL_GEN(dev_priv) >= 9)
11017 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11019 state->base.src.x1 >> 16,
11020 state->base.src.y1 >> 16,
11021 drm_rect_width(&state->base.src) >> 16,
11022 drm_rect_height(&state->base.src) >> 16,
11023 state->base.dst.x1, state->base.dst.y1,
11024 drm_rect_width(&state->base.dst),
11025 drm_rect_height(&state->base.dst));
11029 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
11031 struct drm_device *dev = state->dev;
11032 struct drm_connector *connector;
11033 struct drm_connector_list_iter conn_iter;
11034 unsigned int used_ports = 0;
11035 unsigned int used_mst_ports = 0;
11039 * Walk the connector list instead of the encoder
11040 * list to detect the problem on ddi platforms
11041 * where there's just one encoder per digital port.
11043 drm_connector_list_iter_begin(dev, &conn_iter);
11044 drm_for_each_connector_iter(connector, &conn_iter) {
11045 struct drm_connector_state *connector_state;
11046 struct intel_encoder *encoder;
11048 connector_state = drm_atomic_get_new_connector_state(state, connector);
11049 if (!connector_state)
11050 connector_state = connector->state;
11052 if (!connector_state->best_encoder)
11055 encoder = to_intel_encoder(connector_state->best_encoder);
11057 WARN_ON(!connector_state->crtc);
11059 switch (encoder->type) {
11060 unsigned int port_mask;
11061 case INTEL_OUTPUT_DDI:
11062 if (WARN_ON(!HAS_DDI(to_i915(dev))))
11064 /* else: fall through */
11065 case INTEL_OUTPUT_DP:
11066 case INTEL_OUTPUT_HDMI:
11067 case INTEL_OUTPUT_EDP:
11068 port_mask = 1 << encoder->port;
11070 /* the same port mustn't appear more than once */
11071 if (used_ports & port_mask)
11074 used_ports |= port_mask;
11076 case INTEL_OUTPUT_DP_MST:
11078 1 << encoder->port;
11084 drm_connector_list_iter_end(&conn_iter);
11086 /* can't mix MST and SST/HDMI on the same port */
11087 if (used_ports & used_mst_ports)
11094 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11096 struct drm_i915_private *dev_priv =
11097 to_i915(crtc_state->base.crtc->dev);
11098 struct intel_crtc_scaler_state scaler_state;
11099 struct intel_dpll_hw_state dpll_hw_state;
11100 struct intel_shared_dpll *shared_dpll;
11101 struct intel_crtc_wm_state wm_state;
11102 bool force_thru, ips_force_disable;
11104 /* FIXME: before the switch to atomic started, a new pipe_config was
11105 * kzalloc'd. Code that depends on any field being zero should be
11106 * fixed, so that the crtc_state can be safely duplicated. For now,
11107 * only fields that are know to not cause problems are preserved. */
11109 scaler_state = crtc_state->scaler_state;
11110 shared_dpll = crtc_state->shared_dpll;
11111 dpll_hw_state = crtc_state->dpll_hw_state;
11112 force_thru = crtc_state->pch_pfit.force_thru;
11113 ips_force_disable = crtc_state->ips_force_disable;
11114 if (IS_G4X(dev_priv) ||
11115 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11116 wm_state = crtc_state->wm;
11118 /* Keep base drm_crtc_state intact, only clear our extended struct */
11119 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11120 memset(&crtc_state->base + 1, 0,
11121 sizeof(*crtc_state) - sizeof(crtc_state->base));
11123 crtc_state->scaler_state = scaler_state;
11124 crtc_state->shared_dpll = shared_dpll;
11125 crtc_state->dpll_hw_state = dpll_hw_state;
11126 crtc_state->pch_pfit.force_thru = force_thru;
11127 crtc_state->ips_force_disable = ips_force_disable;
11128 if (IS_G4X(dev_priv) ||
11129 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11130 crtc_state->wm = wm_state;
11134 intel_modeset_pipe_config(struct drm_crtc *crtc,
11135 struct intel_crtc_state *pipe_config)
11137 struct drm_atomic_state *state = pipe_config->base.state;
11138 struct intel_encoder *encoder;
11139 struct drm_connector *connector;
11140 struct drm_connector_state *connector_state;
11141 int base_bpp, ret = -EINVAL;
11145 clear_intel_crtc_state(pipe_config);
11147 pipe_config->cpu_transcoder =
11148 (enum transcoder) to_intel_crtc(crtc)->pipe;
11151 * Sanitize sync polarity flags based on requested ones. If neither
11152 * positive or negative polarity is requested, treat this as meaning
11153 * negative polarity.
11155 if (!(pipe_config->base.adjusted_mode.flags &
11156 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
11157 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
11159 if (!(pipe_config->base.adjusted_mode.flags &
11160 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
11161 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
11163 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11169 * Determine the real pipe dimensions. Note that stereo modes can
11170 * increase the actual pipe size due to the frame doubling and
11171 * insertion of additional space for blanks between the frame. This
11172 * is stored in the crtc timings. We use the requested mode to do this
11173 * computation to clearly distinguish it from the adjusted mode, which
11174 * can be changed by the connectors in the below retry loop.
11176 drm_mode_get_hv_timing(&pipe_config->base.mode,
11177 &pipe_config->pipe_src_w,
11178 &pipe_config->pipe_src_h);
11180 for_each_new_connector_in_state(state, connector, connector_state, i) {
11181 if (connector_state->crtc != crtc)
11184 encoder = to_intel_encoder(connector_state->best_encoder);
11186 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11187 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11192 * Determine output_types before calling the .compute_config()
11193 * hooks so that the hooks can use this information safely.
11195 if (encoder->compute_output_type)
11196 pipe_config->output_types |=
11197 BIT(encoder->compute_output_type(encoder, pipe_config,
11200 pipe_config->output_types |= BIT(encoder->type);
11204 /* Ensure the port clock defaults are reset when retrying. */
11205 pipe_config->port_clock = 0;
11206 pipe_config->pixel_multiplier = 1;
11208 /* Fill in default crtc timings, allow encoders to overwrite them. */
11209 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11210 CRTC_STEREO_DOUBLE);
11212 /* Pass our mode to the connectors and the CRTC to give them a chance to
11213 * adjust it according to limitations or connector properties, and also
11214 * a chance to reject the mode entirely.
11216 for_each_new_connector_in_state(state, connector, connector_state, i) {
11217 if (connector_state->crtc != crtc)
11220 encoder = to_intel_encoder(connector_state->best_encoder);
11222 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
11223 DRM_DEBUG_KMS("Encoder config failure\n");
11228 /* Set default port clock if not overwritten by the encoder. Needs to be
11229 * done afterwards in case the encoder adjusts the mode. */
11230 if (!pipe_config->port_clock)
11231 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
11232 * pipe_config->pixel_multiplier;
11234 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
11236 DRM_DEBUG_KMS("CRTC fixup failed\n");
11240 if (ret == RETRY) {
11241 if (WARN(!retry, "loop in pipe configuration computation\n")) {
11246 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11248 goto encoder_retry;
11251 /* Dithering seems to not pass-through bits correctly when it should, so
11252 * only enable it on 6bpc panels and when its not a compliance
11253 * test requesting 6bpc video pattern.
11255 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11256 !pipe_config->dither_force_disable;
11257 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11258 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
11264 static bool intel_fuzzy_clock_check(int clock1, int clock2)
11268 if (clock1 == clock2)
11271 if (!clock1 || !clock2)
11274 diff = abs(clock1 - clock2);
11276 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11283 intel_compare_m_n(unsigned int m, unsigned int n,
11284 unsigned int m2, unsigned int n2,
11287 if (m == m2 && n == n2)
11290 if (exact || !m || !n || !m2 || !n2)
11293 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11300 } else if (n < n2) {
11310 return intel_fuzzy_clock_check(m, m2);
11314 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11315 struct intel_link_m_n *m2_n2,
11318 if (m_n->tu == m2_n2->tu &&
11319 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11320 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11321 intel_compare_m_n(m_n->link_m, m_n->link_n,
11322 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11332 static void __printf(3, 4)
11333 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11335 struct va_format vaf;
11338 va_start(args, format);
11343 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11345 drm_err("mismatch in %s %pV", name, &vaf);
11351 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11352 struct intel_crtc_state *current_config,
11353 struct intel_crtc_state *pipe_config,
11357 bool fixup_inherited = adjust &&
11358 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11359 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11361 #define PIPE_CONF_CHECK_X(name) do { \
11362 if (current_config->name != pipe_config->name) { \
11363 pipe_config_err(adjust, __stringify(name), \
11364 "(expected 0x%08x, found 0x%08x)\n", \
11365 current_config->name, \
11366 pipe_config->name); \
11371 #define PIPE_CONF_CHECK_I(name) do { \
11372 if (current_config->name != pipe_config->name) { \
11373 pipe_config_err(adjust, __stringify(name), \
11374 "(expected %i, found %i)\n", \
11375 current_config->name, \
11376 pipe_config->name); \
11381 #define PIPE_CONF_CHECK_BOOL(name) do { \
11382 if (current_config->name != pipe_config->name) { \
11383 pipe_config_err(adjust, __stringify(name), \
11384 "(expected %s, found %s)\n", \
11385 yesno(current_config->name), \
11386 yesno(pipe_config->name)); \
11392 * Checks state where we only read out the enabling, but not the entire
11393 * state itself (like full infoframes or ELD for audio). These states
11394 * require a full modeset on bootup to fix up.
11396 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11397 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11398 PIPE_CONF_CHECK_BOOL(name); \
11400 pipe_config_err(adjust, __stringify(name), \
11401 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11402 yesno(current_config->name), \
11403 yesno(pipe_config->name)); \
11408 #define PIPE_CONF_CHECK_P(name) do { \
11409 if (current_config->name != pipe_config->name) { \
11410 pipe_config_err(adjust, __stringify(name), \
11411 "(expected %p, found %p)\n", \
11412 current_config->name, \
11413 pipe_config->name); \
11418 #define PIPE_CONF_CHECK_M_N(name) do { \
11419 if (!intel_compare_link_m_n(¤t_config->name, \
11420 &pipe_config->name,\
11422 pipe_config_err(adjust, __stringify(name), \
11423 "(expected tu %i gmch %i/%i link %i/%i, " \
11424 "found tu %i, gmch %i/%i link %i/%i)\n", \
11425 current_config->name.tu, \
11426 current_config->name.gmch_m, \
11427 current_config->name.gmch_n, \
11428 current_config->name.link_m, \
11429 current_config->name.link_n, \
11430 pipe_config->name.tu, \
11431 pipe_config->name.gmch_m, \
11432 pipe_config->name.gmch_n, \
11433 pipe_config->name.link_m, \
11434 pipe_config->name.link_n); \
11439 /* This is required for BDW+ where there is only one set of registers for
11440 * switching between high and low RR.
11441 * This macro can be used whenever a comparison has to be made between one
11442 * hw state and multiple sw state variables.
11444 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
11445 if (!intel_compare_link_m_n(¤t_config->name, \
11446 &pipe_config->name, adjust) && \
11447 !intel_compare_link_m_n(¤t_config->alt_name, \
11448 &pipe_config->name, adjust)) { \
11449 pipe_config_err(adjust, __stringify(name), \
11450 "(expected tu %i gmch %i/%i link %i/%i, " \
11451 "or tu %i gmch %i/%i link %i/%i, " \
11452 "found tu %i, gmch %i/%i link %i/%i)\n", \
11453 current_config->name.tu, \
11454 current_config->name.gmch_m, \
11455 current_config->name.gmch_n, \
11456 current_config->name.link_m, \
11457 current_config->name.link_n, \
11458 current_config->alt_name.tu, \
11459 current_config->alt_name.gmch_m, \
11460 current_config->alt_name.gmch_n, \
11461 current_config->alt_name.link_m, \
11462 current_config->alt_name.link_n, \
11463 pipe_config->name.tu, \
11464 pipe_config->name.gmch_m, \
11465 pipe_config->name.gmch_n, \
11466 pipe_config->name.link_m, \
11467 pipe_config->name.link_n); \
11472 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
11473 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11474 pipe_config_err(adjust, __stringify(name), \
11475 "(%x) (expected %i, found %i)\n", \
11477 current_config->name & (mask), \
11478 pipe_config->name & (mask)); \
11483 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
11484 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11485 pipe_config_err(adjust, __stringify(name), \
11486 "(expected %i, found %i)\n", \
11487 current_config->name, \
11488 pipe_config->name); \
11493 #define PIPE_CONF_QUIRK(quirk) \
11494 ((current_config->quirks | pipe_config->quirks) & (quirk))
11496 PIPE_CONF_CHECK_I(cpu_transcoder);
11498 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11499 PIPE_CONF_CHECK_I(fdi_lanes);
11500 PIPE_CONF_CHECK_M_N(fdi_m_n);
11502 PIPE_CONF_CHECK_I(lane_count);
11503 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11505 if (INTEL_GEN(dev_priv) < 8) {
11506 PIPE_CONF_CHECK_M_N(dp_m_n);
11508 if (current_config->has_drrs)
11509 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11511 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11513 PIPE_CONF_CHECK_X(output_types);
11515 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11516 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11517 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11518 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11519 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11520 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
11522 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11523 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11524 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11525 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11526 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11527 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
11529 PIPE_CONF_CHECK_I(pixel_multiplier);
11530 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11531 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11532 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11533 PIPE_CONF_CHECK_BOOL(limited_color_range);
11535 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11536 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11537 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
11538 PIPE_CONF_CHECK_BOOL(ycbcr420);
11540 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11542 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11543 DRM_MODE_FLAG_INTERLACE);
11545 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11546 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11547 DRM_MODE_FLAG_PHSYNC);
11548 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11549 DRM_MODE_FLAG_NHSYNC);
11550 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11551 DRM_MODE_FLAG_PVSYNC);
11552 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11553 DRM_MODE_FLAG_NVSYNC);
11556 PIPE_CONF_CHECK_X(gmch_pfit.control);
11557 /* pfit ratios are autocomputed by the hw on gen4+ */
11558 if (INTEL_GEN(dev_priv) < 4)
11559 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11560 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11563 PIPE_CONF_CHECK_I(pipe_src_w);
11564 PIPE_CONF_CHECK_I(pipe_src_h);
11566 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11567 if (current_config->pch_pfit.enabled) {
11568 PIPE_CONF_CHECK_X(pch_pfit.pos);
11569 PIPE_CONF_CHECK_X(pch_pfit.size);
11572 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11573 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11576 PIPE_CONF_CHECK_BOOL(double_wide);
11578 PIPE_CONF_CHECK_P(shared_dpll);
11579 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11580 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11581 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11582 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11583 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11584 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11585 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11586 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11587 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11588 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11589 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11590 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11591 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11592 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11593 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11594 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11595 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11596 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11597 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11598 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11599 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11600 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11601 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11602 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11603 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11604 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11605 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11606 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11607 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11608 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11609 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
11611 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11612 PIPE_CONF_CHECK_X(dsi_pll.div);
11614 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11615 PIPE_CONF_CHECK_I(pipe_bpp);
11617 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
11618 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11620 PIPE_CONF_CHECK_I(min_voltage_level);
11622 #undef PIPE_CONF_CHECK_X
11623 #undef PIPE_CONF_CHECK_I
11624 #undef PIPE_CONF_CHECK_BOOL
11625 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11626 #undef PIPE_CONF_CHECK_P
11627 #undef PIPE_CONF_CHECK_FLAGS
11628 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11629 #undef PIPE_CONF_QUIRK
11634 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11635 const struct intel_crtc_state *pipe_config)
11637 if (pipe_config->has_pch_encoder) {
11638 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11639 &pipe_config->fdi_m_n);
11640 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11643 * FDI already provided one idea for the dotclock.
11644 * Yell if the encoder disagrees.
11646 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11647 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11648 fdi_dotclock, dotclock);
11652 static void verify_wm_state(struct drm_crtc *crtc,
11653 struct drm_crtc_state *new_state)
11655 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11656 struct skl_ddb_allocation hw_ddb, *sw_ddb;
11657 struct skl_pipe_wm hw_wm, *sw_wm;
11658 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11659 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11660 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11661 const enum pipe pipe = intel_crtc->pipe;
11662 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11664 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
11667 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
11668 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
11670 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11671 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11673 if (INTEL_GEN(dev_priv) >= 11)
11674 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11675 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11676 sw_ddb->enabled_slices,
11677 hw_ddb.enabled_slices);
11679 for_each_universal_plane(dev_priv, pipe, plane) {
11680 hw_plane_wm = &hw_wm.planes[plane];
11681 sw_plane_wm = &sw_wm->planes[plane];
11684 for (level = 0; level <= max_level; level++) {
11685 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11686 &sw_plane_wm->wm[level]))
11689 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",
11690 pipe_name(pipe), plane + 1, level,
11691 sw_plane_wm->wm[level].plane_en,
11692 sw_plane_wm->wm[level].plane_res_b,
11693 sw_plane_wm->wm[level].plane_res_l,
11694 hw_plane_wm->wm[level].plane_en,
11695 hw_plane_wm->wm[level].plane_res_b,
11696 hw_plane_wm->wm[level].plane_res_l);
11699 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11700 &sw_plane_wm->trans_wm)) {
11701 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",
11702 pipe_name(pipe), plane + 1,
11703 sw_plane_wm->trans_wm.plane_en,
11704 sw_plane_wm->trans_wm.plane_res_b,
11705 sw_plane_wm->trans_wm.plane_res_l,
11706 hw_plane_wm->trans_wm.plane_en,
11707 hw_plane_wm->trans_wm.plane_res_b,
11708 hw_plane_wm->trans_wm.plane_res_l);
11712 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11713 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11715 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11716 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11717 pipe_name(pipe), plane + 1,
11718 sw_ddb_entry->start, sw_ddb_entry->end,
11719 hw_ddb_entry->start, hw_ddb_entry->end);
11725 * If the cursor plane isn't active, we may not have updated it's ddb
11726 * allocation. In that case since the ddb allocation will be updated
11727 * once the plane becomes visible, we can skip this check
11730 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11731 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
11734 for (level = 0; level <= max_level; level++) {
11735 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11736 &sw_plane_wm->wm[level]))
11739 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",
11740 pipe_name(pipe), level,
11741 sw_plane_wm->wm[level].plane_en,
11742 sw_plane_wm->wm[level].plane_res_b,
11743 sw_plane_wm->wm[level].plane_res_l,
11744 hw_plane_wm->wm[level].plane_en,
11745 hw_plane_wm->wm[level].plane_res_b,
11746 hw_plane_wm->wm[level].plane_res_l);
11749 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11750 &sw_plane_wm->trans_wm)) {
11751 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11753 sw_plane_wm->trans_wm.plane_en,
11754 sw_plane_wm->trans_wm.plane_res_b,
11755 sw_plane_wm->trans_wm.plane_res_l,
11756 hw_plane_wm->trans_wm.plane_en,
11757 hw_plane_wm->trans_wm.plane_res_b,
11758 hw_plane_wm->trans_wm.plane_res_l);
11762 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11763 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11765 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11766 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11768 sw_ddb_entry->start, sw_ddb_entry->end,
11769 hw_ddb_entry->start, hw_ddb_entry->end);
11775 verify_connector_state(struct drm_device *dev,
11776 struct drm_atomic_state *state,
11777 struct drm_crtc *crtc)
11779 struct drm_connector *connector;
11780 struct drm_connector_state *new_conn_state;
11783 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
11784 struct drm_encoder *encoder = connector->encoder;
11785 struct drm_crtc_state *crtc_state = NULL;
11787 if (new_conn_state->crtc != crtc)
11791 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11793 intel_connector_verify_state(crtc_state, new_conn_state);
11795 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
11796 "connector's atomic encoder doesn't match legacy encoder\n");
11801 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
11803 struct intel_encoder *encoder;
11804 struct drm_connector *connector;
11805 struct drm_connector_state *old_conn_state, *new_conn_state;
11808 for_each_intel_encoder(dev, encoder) {
11809 bool enabled = false, found = false;
11812 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11813 encoder->base.base.id,
11814 encoder->base.name);
11816 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
11817 new_conn_state, i) {
11818 if (old_conn_state->best_encoder == &encoder->base)
11821 if (new_conn_state->best_encoder != &encoder->base)
11823 found = enabled = true;
11825 I915_STATE_WARN(new_conn_state->crtc !=
11826 encoder->base.crtc,
11827 "connector's crtc doesn't match encoder crtc\n");
11833 I915_STATE_WARN(!!encoder->base.crtc != enabled,
11834 "encoder's enabled state mismatch "
11835 "(expected %i, found %i)\n",
11836 !!encoder->base.crtc, enabled);
11838 if (!encoder->base.crtc) {
11841 active = encoder->get_hw_state(encoder, &pipe);
11842 I915_STATE_WARN(active,
11843 "encoder detached but still enabled on pipe %c.\n",
11850 verify_crtc_state(struct drm_crtc *crtc,
11851 struct drm_crtc_state *old_crtc_state,
11852 struct drm_crtc_state *new_crtc_state)
11854 struct drm_device *dev = crtc->dev;
11855 struct drm_i915_private *dev_priv = to_i915(dev);
11856 struct intel_encoder *encoder;
11857 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11858 struct intel_crtc_state *pipe_config, *sw_config;
11859 struct drm_atomic_state *old_state;
11862 old_state = old_crtc_state->state;
11863 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
11864 pipe_config = to_intel_crtc_state(old_crtc_state);
11865 memset(pipe_config, 0, sizeof(*pipe_config));
11866 pipe_config->base.crtc = crtc;
11867 pipe_config->base.state = old_state;
11869 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
11871 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
11873 /* we keep both pipes enabled on 830 */
11874 if (IS_I830(dev_priv))
11875 active = new_crtc_state->active;
11877 I915_STATE_WARN(new_crtc_state->active != active,
11878 "crtc active state doesn't match with hw state "
11879 "(expected %i, found %i)\n", new_crtc_state->active, active);
11881 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
11882 "transitional active state does not match atomic hw state "
11883 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
11885 for_each_encoder_on_crtc(dev, crtc, encoder) {
11888 active = encoder->get_hw_state(encoder, &pipe);
11889 I915_STATE_WARN(active != new_crtc_state->active,
11890 "[ENCODER:%i] active %i with crtc active %i\n",
11891 encoder->base.base.id, active, new_crtc_state->active);
11893 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
11894 "Encoder connected to wrong pipe %c\n",
11898 encoder->get_config(encoder, pipe_config);
11901 intel_crtc_compute_pixel_rate(pipe_config);
11903 if (!new_crtc_state->active)
11906 intel_pipe_config_sanity_check(dev_priv, pipe_config);
11908 sw_config = to_intel_crtc_state(new_crtc_state);
11909 if (!intel_pipe_config_compare(dev_priv, sw_config,
11910 pipe_config, false)) {
11911 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11912 intel_dump_pipe_config(intel_crtc, pipe_config,
11914 intel_dump_pipe_config(intel_crtc, sw_config,
11920 intel_verify_planes(struct intel_atomic_state *state)
11922 struct intel_plane *plane;
11923 const struct intel_plane_state *plane_state;
11926 for_each_new_intel_plane_in_state(state, plane,
11928 assert_plane(plane, plane_state->base.visible);
11932 verify_single_dpll_state(struct drm_i915_private *dev_priv,
11933 struct intel_shared_dpll *pll,
11934 struct drm_crtc *crtc,
11935 struct drm_crtc_state *new_state)
11937 struct intel_dpll_hw_state dpll_hw_state;
11938 unsigned int crtc_mask;
11941 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
11943 DRM_DEBUG_KMS("%s\n", pll->info->name);
11945 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
11947 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
11948 I915_STATE_WARN(!pll->on && pll->active_mask,
11949 "pll in active use but not on in sw tracking\n");
11950 I915_STATE_WARN(pll->on && !pll->active_mask,
11951 "pll is on but not used by any active crtc\n");
11952 I915_STATE_WARN(pll->on != active,
11953 "pll on state mismatch (expected %i, found %i)\n",
11958 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
11959 "more active pll users than references: %x vs %x\n",
11960 pll->active_mask, pll->state.crtc_mask);
11965 crtc_mask = drm_crtc_mask(crtc);
11967 if (new_state->active)
11968 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
11969 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11970 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11972 I915_STATE_WARN(pll->active_mask & crtc_mask,
11973 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11974 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11976 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
11977 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11978 crtc_mask, pll->state.crtc_mask);
11980 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
11982 sizeof(dpll_hw_state)),
11983 "pll hw state mismatch\n");
11987 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
11988 struct drm_crtc_state *old_crtc_state,
11989 struct drm_crtc_state *new_crtc_state)
11991 struct drm_i915_private *dev_priv = to_i915(dev);
11992 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
11993 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
11995 if (new_state->shared_dpll)
11996 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
11998 if (old_state->shared_dpll &&
11999 old_state->shared_dpll != new_state->shared_dpll) {
12000 unsigned int crtc_mask = drm_crtc_mask(crtc);
12001 struct intel_shared_dpll *pll = old_state->shared_dpll;
12003 I915_STATE_WARN(pll->active_mask & crtc_mask,
12004 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12005 pipe_name(drm_crtc_index(crtc)));
12006 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
12007 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12008 pipe_name(drm_crtc_index(crtc)));
12013 intel_modeset_verify_crtc(struct drm_crtc *crtc,
12014 struct drm_atomic_state *state,
12015 struct drm_crtc_state *old_state,
12016 struct drm_crtc_state *new_state)
12018 if (!needs_modeset(new_state) &&
12019 !to_intel_crtc_state(new_state)->update_pipe)
12022 verify_wm_state(crtc, new_state);
12023 verify_connector_state(crtc->dev, state, crtc);
12024 verify_crtc_state(crtc, old_state, new_state);
12025 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
12029 verify_disabled_dpll_state(struct drm_device *dev)
12031 struct drm_i915_private *dev_priv = to_i915(dev);
12034 for (i = 0; i < dev_priv->num_shared_dpll; i++)
12035 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
12039 intel_modeset_verify_disabled(struct drm_device *dev,
12040 struct drm_atomic_state *state)
12042 verify_encoder_state(dev, state);
12043 verify_connector_state(dev, state, NULL);
12044 verify_disabled_dpll_state(dev);
12047 static void update_scanline_offset(struct intel_crtc *crtc)
12049 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12052 * The scanline counter increments at the leading edge of hsync.
12054 * On most platforms it starts counting from vtotal-1 on the
12055 * first active line. That means the scanline counter value is
12056 * always one less than what we would expect. Ie. just after
12057 * start of vblank, which also occurs at start of hsync (on the
12058 * last active line), the scanline counter will read vblank_start-1.
12060 * On gen2 the scanline counter starts counting from 1 instead
12061 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12062 * to keep the value positive), instead of adding one.
12064 * On HSW+ the behaviour of the scanline counter depends on the output
12065 * type. For DP ports it behaves like most other platforms, but on HDMI
12066 * there's an extra 1 line difference. So we need to add two instead of
12067 * one to the value.
12069 * On VLV/CHV DSI the scanline counter would appear to increment
12070 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12071 * that means we can't tell whether we're in vblank or not while
12072 * we're on that particular line. We must still set scanline_offset
12073 * to 1 so that the vblank timestamps come out correct when we query
12074 * the scanline counter from within the vblank interrupt handler.
12075 * However if queried just before the start of vblank we'll get an
12076 * answer that's slightly in the future.
12078 if (IS_GEN2(dev_priv)) {
12079 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
12082 vtotal = adjusted_mode->crtc_vtotal;
12083 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
12086 crtc->scanline_offset = vtotal - 1;
12087 } else if (HAS_DDI(dev_priv) &&
12088 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) {
12089 crtc->scanline_offset = 2;
12091 crtc->scanline_offset = 1;
12094 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
12096 struct drm_device *dev = state->dev;
12097 struct drm_i915_private *dev_priv = to_i915(dev);
12098 struct drm_crtc *crtc;
12099 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12102 if (!dev_priv->display.crtc_compute_clock)
12105 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12106 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12107 struct intel_shared_dpll *old_dpll =
12108 to_intel_crtc_state(old_crtc_state)->shared_dpll;
12110 if (!needs_modeset(new_crtc_state))
12113 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
12118 intel_release_shared_dpll(old_dpll, intel_crtc, state);
12123 * This implements the workaround described in the "notes" section of the mode
12124 * set sequence documentation. When going from no pipes or single pipe to
12125 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12126 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12128 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12130 struct drm_crtc_state *crtc_state;
12131 struct intel_crtc *intel_crtc;
12132 struct drm_crtc *crtc;
12133 struct intel_crtc_state *first_crtc_state = NULL;
12134 struct intel_crtc_state *other_crtc_state = NULL;
12135 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12138 /* look at all crtc's that are going to be enabled in during modeset */
12139 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
12140 intel_crtc = to_intel_crtc(crtc);
12142 if (!crtc_state->active || !needs_modeset(crtc_state))
12145 if (first_crtc_state) {
12146 other_crtc_state = to_intel_crtc_state(crtc_state);
12149 first_crtc_state = to_intel_crtc_state(crtc_state);
12150 first_pipe = intel_crtc->pipe;
12154 /* No workaround needed? */
12155 if (!first_crtc_state)
12158 /* w/a possibly needed, check how many crtc's are already enabled. */
12159 for_each_intel_crtc(state->dev, intel_crtc) {
12160 struct intel_crtc_state *pipe_config;
12162 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12163 if (IS_ERR(pipe_config))
12164 return PTR_ERR(pipe_config);
12166 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12168 if (!pipe_config->base.active ||
12169 needs_modeset(&pipe_config->base))
12172 /* 2 or more enabled crtcs means no need for w/a */
12173 if (enabled_pipe != INVALID_PIPE)
12176 enabled_pipe = intel_crtc->pipe;
12179 if (enabled_pipe != INVALID_PIPE)
12180 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12181 else if (other_crtc_state)
12182 other_crtc_state->hsw_workaround_pipe = first_pipe;
12187 static int intel_lock_all_pipes(struct drm_atomic_state *state)
12189 struct drm_crtc *crtc;
12191 /* Add all pipes to the state */
12192 for_each_crtc(state->dev, crtc) {
12193 struct drm_crtc_state *crtc_state;
12195 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12196 if (IS_ERR(crtc_state))
12197 return PTR_ERR(crtc_state);
12203 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12205 struct drm_crtc *crtc;
12208 * Add all pipes to the state, and force
12209 * a modeset on all the active ones.
12211 for_each_crtc(state->dev, crtc) {
12212 struct drm_crtc_state *crtc_state;
12215 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12216 if (IS_ERR(crtc_state))
12217 return PTR_ERR(crtc_state);
12219 if (!crtc_state->active || needs_modeset(crtc_state))
12222 crtc_state->mode_changed = true;
12224 ret = drm_atomic_add_affected_connectors(state, crtc);
12228 ret = drm_atomic_add_affected_planes(state, crtc);
12236 static int intel_modeset_checks(struct drm_atomic_state *state)
12238 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12239 struct drm_i915_private *dev_priv = to_i915(state->dev);
12240 struct drm_crtc *crtc;
12241 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12244 if (!check_digital_port_conflicts(state)) {
12245 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12249 intel_state->modeset = true;
12250 intel_state->active_crtcs = dev_priv->active_crtcs;
12251 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12252 intel_state->cdclk.actual = dev_priv->cdclk.actual;
12254 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12255 if (new_crtc_state->active)
12256 intel_state->active_crtcs |= 1 << i;
12258 intel_state->active_crtcs &= ~(1 << i);
12260 if (old_crtc_state->active != new_crtc_state->active)
12261 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
12265 * See if the config requires any additional preparation, e.g.
12266 * to adjust global state with pipes off. We need to do this
12267 * here so we can get the modeset_pipe updated config for the new
12268 * mode set on this crtc. For other crtcs we need to use the
12269 * adjusted_mode bits in the crtc directly.
12271 if (dev_priv->display.modeset_calc_cdclk) {
12272 ret = dev_priv->display.modeset_calc_cdclk(state);
12277 * Writes to dev_priv->cdclk.logical must protected by
12278 * holding all the crtc locks, even if we don't end up
12279 * touching the hardware
12281 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12282 &intel_state->cdclk.logical)) {
12283 ret = intel_lock_all_pipes(state);
12288 /* All pipes must be switched off while we change the cdclk. */
12289 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12290 &intel_state->cdclk.actual)) {
12291 ret = intel_modeset_all_pipes(state);
12296 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12297 intel_state->cdclk.logical.cdclk,
12298 intel_state->cdclk.actual.cdclk);
12299 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12300 intel_state->cdclk.logical.voltage_level,
12301 intel_state->cdclk.actual.voltage_level);
12303 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12306 intel_modeset_clear_plls(state);
12308 if (IS_HASWELL(dev_priv))
12309 return haswell_mode_set_planes_workaround(state);
12315 * Handle calculation of various watermark data at the end of the atomic check
12316 * phase. The code here should be run after the per-crtc and per-plane 'check'
12317 * handlers to ensure that all derived state has been updated.
12319 static int calc_watermark_data(struct drm_atomic_state *state)
12321 struct drm_device *dev = state->dev;
12322 struct drm_i915_private *dev_priv = to_i915(dev);
12324 /* Is there platform-specific watermark information to calculate? */
12325 if (dev_priv->display.compute_global_watermarks)
12326 return dev_priv->display.compute_global_watermarks(state);
12332 * intel_atomic_check - validate state object
12334 * @state: state to validate
12336 static int intel_atomic_check(struct drm_device *dev,
12337 struct drm_atomic_state *state)
12339 struct drm_i915_private *dev_priv = to_i915(dev);
12340 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12341 struct drm_crtc *crtc;
12342 struct drm_crtc_state *old_crtc_state, *crtc_state;
12344 bool any_ms = false;
12346 /* Catch I915_MODE_FLAG_INHERITED */
12347 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12349 if (crtc_state->mode.private_flags !=
12350 old_crtc_state->mode.private_flags)
12351 crtc_state->mode_changed = true;
12354 ret = drm_atomic_helper_check_modeset(dev, state);
12358 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12359 struct intel_crtc_state *pipe_config =
12360 to_intel_crtc_state(crtc_state);
12362 if (!needs_modeset(crtc_state))
12365 if (!crtc_state->enable) {
12370 ret = intel_modeset_pipe_config(crtc, pipe_config);
12372 intel_dump_pipe_config(to_intel_crtc(crtc),
12373 pipe_config, "[failed]");
12377 if (i915_modparams.fastboot &&
12378 intel_pipe_config_compare(dev_priv,
12379 to_intel_crtc_state(old_crtc_state),
12380 pipe_config, true)) {
12381 crtc_state->mode_changed = false;
12382 pipe_config->update_pipe = true;
12385 if (needs_modeset(crtc_state))
12388 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12389 needs_modeset(crtc_state) ?
12390 "[modeset]" : "[fastset]");
12394 ret = intel_modeset_checks(state);
12399 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12402 ret = drm_atomic_helper_check_planes(dev, state);
12406 intel_fbc_choose_crtc(dev_priv, intel_state);
12407 return calc_watermark_data(state);
12410 static int intel_atomic_prepare_commit(struct drm_device *dev,
12411 struct drm_atomic_state *state)
12413 return drm_atomic_helper_prepare_planes(dev, state);
12416 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12418 struct drm_device *dev = crtc->base.dev;
12420 if (!dev->max_vblank_count)
12421 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
12423 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12426 static void intel_update_crtc(struct drm_crtc *crtc,
12427 struct drm_atomic_state *state,
12428 struct drm_crtc_state *old_crtc_state,
12429 struct drm_crtc_state *new_crtc_state)
12431 struct drm_device *dev = crtc->dev;
12432 struct drm_i915_private *dev_priv = to_i915(dev);
12433 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12434 struct intel_crtc_state *old_intel_cstate = to_intel_crtc_state(old_crtc_state);
12435 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12436 bool modeset = needs_modeset(new_crtc_state);
12437 struct intel_plane_state *new_plane_state =
12438 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12439 to_intel_plane(crtc->primary));
12442 update_scanline_offset(intel_crtc);
12443 dev_priv->display.crtc_enable(pipe_config, state);
12445 /* vblanks work again, re-enable pipe CRC. */
12446 intel_crtc_enable_pipe_crc(intel_crtc);
12448 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12452 if (new_plane_state)
12453 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
12455 intel_begin_crtc_commit(crtc, old_crtc_state);
12457 intel_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc,
12458 old_intel_cstate, pipe_config);
12460 intel_finish_crtc_commit(crtc, old_crtc_state);
12463 static void intel_update_crtcs(struct drm_atomic_state *state)
12465 struct drm_crtc *crtc;
12466 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12469 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12470 if (!new_crtc_state->active)
12473 intel_update_crtc(crtc, state, old_crtc_state,
12478 static void skl_update_crtcs(struct drm_atomic_state *state)
12480 struct drm_i915_private *dev_priv = to_i915(state->dev);
12481 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12482 struct drm_crtc *crtc;
12483 struct intel_crtc *intel_crtc;
12484 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12485 struct intel_crtc_state *cstate;
12486 unsigned int updated = 0;
12490 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12491 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
12493 const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
12495 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
12496 /* ignore allocations for crtc's that have been turned off. */
12497 if (new_crtc_state->active)
12498 entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
12500 /* If 2nd DBuf slice required, enable it here */
12501 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12502 icl_dbuf_slices_update(dev_priv, required_slices);
12505 * Whenever the number of active pipes changes, we need to make sure we
12506 * update the pipes in the right order so that their ddb allocations
12507 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12508 * cause pipe underruns and other bad stuff.
12513 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12514 bool vbl_wait = false;
12515 unsigned int cmask = drm_crtc_mask(crtc);
12517 intel_crtc = to_intel_crtc(crtc);
12518 cstate = to_intel_crtc_state(new_crtc_state);
12519 pipe = intel_crtc->pipe;
12521 if (updated & cmask || !cstate->base.active)
12524 if (skl_ddb_allocation_overlaps(dev_priv,
12526 &cstate->wm.skl.ddb,
12531 entries[i] = &cstate->wm.skl.ddb;
12534 * If this is an already active pipe, it's DDB changed,
12535 * and this isn't the last pipe that needs updating
12536 * then we need to wait for a vblank to pass for the
12537 * new ddb allocation to take effect.
12539 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
12540 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
12541 !new_crtc_state->active_changed &&
12542 intel_state->wm_results.dirty_pipes != updated)
12545 intel_update_crtc(crtc, state, old_crtc_state,
12549 intel_wait_for_vblank(dev_priv, pipe);
12553 } while (progress);
12555 /* If 2nd DBuf slice is no more required disable it */
12556 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12557 icl_dbuf_slices_update(dev_priv, required_slices);
12560 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12562 struct intel_atomic_state *state, *next;
12563 struct llist_node *freed;
12565 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12566 llist_for_each_entry_safe(state, next, freed, freed)
12567 drm_atomic_state_put(&state->base);
12570 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12572 struct drm_i915_private *dev_priv =
12573 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12575 intel_atomic_helper_free_state(dev_priv);
12578 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12580 struct wait_queue_entry wait_fence, wait_reset;
12581 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12583 init_wait_entry(&wait_fence, 0);
12584 init_wait_entry(&wait_reset, 0);
12586 prepare_to_wait(&intel_state->commit_ready.wait,
12587 &wait_fence, TASK_UNINTERRUPTIBLE);
12588 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12589 &wait_reset, TASK_UNINTERRUPTIBLE);
12592 if (i915_sw_fence_done(&intel_state->commit_ready)
12593 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12598 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12599 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12602 static void intel_atomic_cleanup_work(struct work_struct *work)
12604 struct drm_atomic_state *state =
12605 container_of(work, struct drm_atomic_state, commit_work);
12606 struct drm_i915_private *i915 = to_i915(state->dev);
12608 drm_atomic_helper_cleanup_planes(&i915->drm, state);
12609 drm_atomic_helper_commit_cleanup_done(state);
12610 drm_atomic_state_put(state);
12612 intel_atomic_helper_free_state(i915);
12615 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
12617 struct drm_device *dev = state->dev;
12618 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12619 struct drm_i915_private *dev_priv = to_i915(dev);
12620 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12621 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
12622 struct drm_crtc *crtc;
12623 struct intel_crtc *intel_crtc;
12624 u64 put_domains[I915_MAX_PIPES] = {};
12627 intel_atomic_commit_fence_wait(intel_state);
12629 drm_atomic_helper_wait_for_dependencies(state);
12631 if (intel_state->modeset)
12632 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
12634 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12635 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
12636 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
12637 intel_crtc = to_intel_crtc(crtc);
12639 if (needs_modeset(new_crtc_state) ||
12640 to_intel_crtc_state(new_crtc_state)->update_pipe) {
12642 put_domains[intel_crtc->pipe] =
12643 modeset_get_crtc_power_domains(crtc,
12644 new_intel_crtc_state);
12647 if (!needs_modeset(new_crtc_state))
12650 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
12652 if (old_crtc_state->active) {
12653 intel_crtc_disable_planes(intel_crtc, old_intel_crtc_state->active_planes);
12656 * We need to disable pipe CRC before disabling the pipe,
12657 * or we race against vblank off.
12659 intel_crtc_disable_pipe_crc(intel_crtc);
12661 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
12662 intel_crtc->active = false;
12663 intel_fbc_disable(intel_crtc);
12664 intel_disable_shared_dpll(old_intel_crtc_state);
12667 * Underruns don't always raise
12668 * interrupts, so check manually.
12670 intel_check_cpu_fifo_underruns(dev_priv);
12671 intel_check_pch_fifo_underruns(dev_priv);
12673 if (!new_crtc_state->active) {
12675 * Make sure we don't call initial_watermarks
12676 * for ILK-style watermark updates.
12678 * No clue what this is supposed to achieve.
12680 if (INTEL_GEN(dev_priv) >= 9)
12681 dev_priv->display.initial_watermarks(intel_state,
12682 new_intel_crtc_state);
12687 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12688 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12689 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
12691 if (intel_state->modeset) {
12692 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12694 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
12697 * SKL workaround: bspec recommends we disable the SAGV when we
12698 * have more then one pipe enabled
12700 if (!intel_can_enable_sagv(state))
12701 intel_disable_sagv(dev_priv);
12703 intel_modeset_verify_disabled(dev, state);
12706 /* Complete the events for pipes that have now been disabled */
12707 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12708 bool modeset = needs_modeset(new_crtc_state);
12710 /* Complete events for now disable pipes here. */
12711 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
12712 spin_lock_irq(&dev->event_lock);
12713 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
12714 spin_unlock_irq(&dev->event_lock);
12716 new_crtc_state->event = NULL;
12720 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12721 dev_priv->display.update_crtcs(state);
12723 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12724 * already, but still need the state for the delayed optimization. To
12726 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12727 * - schedule that vblank worker _before_ calling hw_done
12728 * - at the start of commit_tail, cancel it _synchrously
12729 * - switch over to the vblank wait helper in the core after that since
12730 * we don't need out special handling any more.
12732 drm_atomic_helper_wait_for_flip_done(dev, state);
12735 * Now that the vblank has passed, we can go ahead and program the
12736 * optimal watermarks on platforms that need two-step watermark
12739 * TODO: Move this (and other cleanup) to an async worker eventually.
12741 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12742 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
12744 if (dev_priv->display.optimize_watermarks)
12745 dev_priv->display.optimize_watermarks(intel_state,
12746 new_intel_crtc_state);
12749 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12750 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12752 if (put_domains[i])
12753 modeset_put_power_domains(dev_priv, put_domains[i]);
12755 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
12758 if (intel_state->modeset)
12759 intel_verify_planes(intel_state);
12761 if (intel_state->modeset && intel_can_enable_sagv(state))
12762 intel_enable_sagv(dev_priv);
12764 drm_atomic_helper_commit_hw_done(state);
12766 if (intel_state->modeset) {
12767 /* As one of the primary mmio accessors, KMS has a high
12768 * likelihood of triggering bugs in unclaimed access. After we
12769 * finish modesetting, see if an error has been flagged, and if
12770 * so enable debugging for the next modeset - and hope we catch
12773 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
12774 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
12778 * Defer the cleanup of the old state to a separate worker to not
12779 * impede the current task (userspace for blocking modesets) that
12780 * are executed inline. For out-of-line asynchronous modesets/flips,
12781 * deferring to a new worker seems overkill, but we would place a
12782 * schedule point (cond_resched()) here anyway to keep latencies
12785 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
12786 queue_work(system_highpri_wq, &state->commit_work);
12789 static void intel_atomic_commit_work(struct work_struct *work)
12791 struct drm_atomic_state *state =
12792 container_of(work, struct drm_atomic_state, commit_work);
12794 intel_atomic_commit_tail(state);
12797 static int __i915_sw_fence_call
12798 intel_atomic_commit_ready(struct i915_sw_fence *fence,
12799 enum i915_sw_fence_notify notify)
12801 struct intel_atomic_state *state =
12802 container_of(fence, struct intel_atomic_state, commit_ready);
12805 case FENCE_COMPLETE:
12806 /* we do blocking waits in the worker, nothing to do here */
12810 struct intel_atomic_helper *helper =
12811 &to_i915(state->base.dev)->atomic_helper;
12813 if (llist_add(&state->freed, &helper->free_list))
12814 schedule_work(&helper->free_work);
12819 return NOTIFY_DONE;
12822 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
12824 struct drm_plane_state *old_plane_state, *new_plane_state;
12825 struct drm_plane *plane;
12828 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
12829 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
12830 intel_fb_obj(new_plane_state->fb),
12831 to_intel_plane(plane)->frontbuffer_bit);
12835 * intel_atomic_commit - commit validated state object
12837 * @state: the top-level driver state object
12838 * @nonblock: nonblocking commit
12840 * This function commits a top-level state object that has been validated
12841 * with drm_atomic_helper_check().
12844 * Zero for success or -errno.
12846 static int intel_atomic_commit(struct drm_device *dev,
12847 struct drm_atomic_state *state,
12850 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12851 struct drm_i915_private *dev_priv = to_i915(dev);
12854 drm_atomic_state_get(state);
12855 i915_sw_fence_init(&intel_state->commit_ready,
12856 intel_atomic_commit_ready);
12859 * The intel_legacy_cursor_update() fast path takes care
12860 * of avoiding the vblank waits for simple cursor
12861 * movement and flips. For cursor on/off and size changes,
12862 * we want to perform the vblank waits so that watermark
12863 * updates happen during the correct frames. Gen9+ have
12864 * double buffered watermarks and so shouldn't need this.
12866 * Unset state->legacy_cursor_update before the call to
12867 * drm_atomic_helper_setup_commit() because otherwise
12868 * drm_atomic_helper_wait_for_flip_done() is a noop and
12869 * we get FIFO underruns because we didn't wait
12872 * FIXME doing watermarks and fb cleanup from a vblank worker
12873 * (assuming we had any) would solve these problems.
12875 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
12876 struct intel_crtc_state *new_crtc_state;
12877 struct intel_crtc *crtc;
12880 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
12881 if (new_crtc_state->wm.need_postvbl_update ||
12882 new_crtc_state->update_wm_post)
12883 state->legacy_cursor_update = false;
12886 ret = intel_atomic_prepare_commit(dev, state);
12888 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
12889 i915_sw_fence_commit(&intel_state->commit_ready);
12893 ret = drm_atomic_helper_setup_commit(state, nonblock);
12895 ret = drm_atomic_helper_swap_state(state, true);
12898 i915_sw_fence_commit(&intel_state->commit_ready);
12900 drm_atomic_helper_cleanup_planes(dev, state);
12903 dev_priv->wm.distrust_bios_wm = false;
12904 intel_shared_dpll_swap_state(state);
12905 intel_atomic_track_fbs(state);
12907 if (intel_state->modeset) {
12908 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
12909 sizeof(intel_state->min_cdclk));
12910 memcpy(dev_priv->min_voltage_level,
12911 intel_state->min_voltage_level,
12912 sizeof(intel_state->min_voltage_level));
12913 dev_priv->active_crtcs = intel_state->active_crtcs;
12914 dev_priv->cdclk.logical = intel_state->cdclk.logical;
12915 dev_priv->cdclk.actual = intel_state->cdclk.actual;
12918 drm_atomic_state_get(state);
12919 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
12921 i915_sw_fence_commit(&intel_state->commit_ready);
12922 if (nonblock && intel_state->modeset) {
12923 queue_work(dev_priv->modeset_wq, &state->commit_work);
12924 } else if (nonblock) {
12925 queue_work(system_unbound_wq, &state->commit_work);
12927 if (intel_state->modeset)
12928 flush_workqueue(dev_priv->modeset_wq);
12929 intel_atomic_commit_tail(state);
12935 static const struct drm_crtc_funcs intel_crtc_funcs = {
12936 .gamma_set = drm_atomic_helper_legacy_gamma_set,
12937 .set_config = drm_atomic_helper_set_config,
12938 .destroy = intel_crtc_destroy,
12939 .page_flip = drm_atomic_helper_page_flip,
12940 .atomic_duplicate_state = intel_crtc_duplicate_state,
12941 .atomic_destroy_state = intel_crtc_destroy_state,
12942 .set_crc_source = intel_crtc_set_crc_source,
12943 .verify_crc_source = intel_crtc_verify_crc_source,
12944 .get_crc_sources = intel_crtc_get_crc_sources,
12947 struct wait_rps_boost {
12948 struct wait_queue_entry wait;
12950 struct drm_crtc *crtc;
12951 struct i915_request *request;
12954 static int do_rps_boost(struct wait_queue_entry *_wait,
12955 unsigned mode, int sync, void *key)
12957 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
12958 struct i915_request *rq = wait->request;
12961 * If we missed the vblank, but the request is already running it
12962 * is reasonable to assume that it will complete before the next
12963 * vblank without our intervention, so leave RPS alone.
12965 if (!i915_request_started(rq))
12966 gen6_rps_boost(rq, NULL);
12967 i915_request_put(rq);
12969 drm_crtc_vblank_put(wait->crtc);
12971 list_del(&wait->wait.entry);
12976 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
12977 struct dma_fence *fence)
12979 struct wait_rps_boost *wait;
12981 if (!dma_fence_is_i915(fence))
12984 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
12987 if (drm_crtc_vblank_get(crtc))
12990 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
12992 drm_crtc_vblank_put(crtc);
12996 wait->request = to_request(dma_fence_get(fence));
12999 wait->wait.func = do_rps_boost;
13000 wait->wait.flags = 0;
13002 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13005 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13007 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13008 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13009 struct drm_framebuffer *fb = plane_state->base.fb;
13010 struct i915_vma *vma;
13012 if (plane->id == PLANE_CURSOR &&
13013 INTEL_INFO(dev_priv)->cursor_needs_physical) {
13014 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13015 const int align = intel_cursor_alignment(dev_priv);
13018 err = i915_gem_object_attach_phys(obj, align);
13023 vma = intel_pin_and_fence_fb_obj(fb,
13024 &plane_state->view,
13025 intel_plane_uses_fence(plane_state),
13026 &plane_state->flags);
13028 return PTR_ERR(vma);
13030 plane_state->vma = vma;
13035 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13037 struct i915_vma *vma;
13039 vma = fetch_and_zero(&old_plane_state->vma);
13041 intel_unpin_fb_vma(vma, old_plane_state->flags);
13044 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13046 struct i915_sched_attr attr = {
13047 .priority = I915_PRIORITY_DISPLAY,
13050 i915_gem_object_wait_priority(obj, 0, &attr);
13054 * intel_prepare_plane_fb - Prepare fb for usage on plane
13055 * @plane: drm plane to prepare for
13056 * @new_state: the plane state being prepared
13058 * Prepares a framebuffer for usage on a display plane. Generally this
13059 * involves pinning the underlying object and updating the frontbuffer tracking
13060 * bits. Some older platforms need special physical address handling for
13063 * Must be called with struct_mutex held.
13065 * Returns 0 on success, negative error code on failure.
13068 intel_prepare_plane_fb(struct drm_plane *plane,
13069 struct drm_plane_state *new_state)
13071 struct intel_atomic_state *intel_state =
13072 to_intel_atomic_state(new_state->state);
13073 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13074 struct drm_framebuffer *fb = new_state->fb;
13075 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13076 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
13080 struct drm_crtc_state *crtc_state =
13081 drm_atomic_get_new_crtc_state(new_state->state,
13082 plane->state->crtc);
13084 /* Big Hammer, we also need to ensure that any pending
13085 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13086 * current scanout is retired before unpinning the old
13087 * framebuffer. Note that we rely on userspace rendering
13088 * into the buffer attached to the pipe they are waiting
13089 * on. If not, userspace generates a GPU hang with IPEHR
13090 * point to the MI_WAIT_FOR_EVENT.
13092 * This should only fail upon a hung GPU, in which case we
13093 * can safely continue.
13095 if (needs_modeset(crtc_state)) {
13096 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13097 old_obj->resv, NULL,
13105 if (new_state->fence) { /* explicit fencing */
13106 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13108 I915_FENCE_TIMEOUT,
13117 ret = i915_gem_object_pin_pages(obj);
13121 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13123 i915_gem_object_unpin_pages(obj);
13127 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
13129 mutex_unlock(&dev_priv->drm.struct_mutex);
13130 i915_gem_object_unpin_pages(obj);
13134 fb_obj_bump_render_priority(obj);
13135 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13137 if (!new_state->fence) { /* implicit fencing */
13138 struct dma_fence *fence;
13140 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13142 false, I915_FENCE_TIMEOUT,
13147 fence = reservation_object_get_excl_rcu(obj->resv);
13149 add_rps_boost_after_vblank(new_state->crtc, fence);
13150 dma_fence_put(fence);
13153 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
13157 * We declare pageflips to be interactive and so merit a small bias
13158 * towards upclocking to deliver the frame on time. By only changing
13159 * the RPS thresholds to sample more regularly and aim for higher
13160 * clocks we can hopefully deliver low power workloads (like kodi)
13161 * that are not quite steady state without resorting to forcing
13162 * maximum clocks following a vblank miss (see do_rps_boost()).
13164 if (!intel_state->rps_interactive) {
13165 intel_rps_mark_interactive(dev_priv, true);
13166 intel_state->rps_interactive = true;
13173 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13174 * @plane: drm plane to clean up for
13175 * @old_state: the state from the previous modeset
13177 * Cleans up a framebuffer that has just been removed from a plane.
13179 * Must be called with struct_mutex held.
13182 intel_cleanup_plane_fb(struct drm_plane *plane,
13183 struct drm_plane_state *old_state)
13185 struct intel_atomic_state *intel_state =
13186 to_intel_atomic_state(old_state->state);
13187 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13189 if (intel_state->rps_interactive) {
13190 intel_rps_mark_interactive(dev_priv, false);
13191 intel_state->rps_interactive = false;
13194 /* Should only be called after a successful intel_prepare_plane_fb()! */
13195 mutex_lock(&dev_priv->drm.struct_mutex);
13196 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13197 mutex_unlock(&dev_priv->drm.struct_mutex);
13201 skl_max_scale(const struct intel_crtc_state *crtc_state,
13204 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13205 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13206 int max_scale, mult;
13207 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
13209 if (!crtc_state->base.enable)
13210 return DRM_PLANE_HELPER_NO_SCALING;
13212 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13213 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13215 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
13218 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
13219 return DRM_PLANE_HELPER_NO_SCALING;
13222 * skl max scale is lower of:
13223 * close to 3 but not 3, -1 is for that purpose
13227 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13228 tmpclk1 = (1 << 16) * mult - 1;
13229 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13230 max_scale = min(tmpclk1, tmpclk2);
13235 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13236 struct drm_crtc_state *old_crtc_state)
13238 struct drm_device *dev = crtc->dev;
13239 struct drm_i915_private *dev_priv = to_i915(dev);
13240 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13241 struct intel_crtc_state *old_intel_cstate =
13242 to_intel_crtc_state(old_crtc_state);
13243 struct intel_atomic_state *old_intel_state =
13244 to_intel_atomic_state(old_crtc_state->state);
13245 struct intel_crtc_state *intel_cstate =
13246 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13247 bool modeset = needs_modeset(&intel_cstate->base);
13250 (intel_cstate->base.color_mgmt_changed ||
13251 intel_cstate->update_pipe)) {
13252 intel_color_set_csc(&intel_cstate->base);
13253 intel_color_load_luts(&intel_cstate->base);
13256 /* Perform vblank evasion around commit operation */
13257 intel_pipe_update_start(intel_cstate);
13262 if (intel_cstate->update_pipe)
13263 intel_update_pipe_config(old_intel_cstate, intel_cstate);
13264 else if (INTEL_GEN(dev_priv) >= 9)
13265 skl_detach_scalers(intel_cstate);
13268 if (dev_priv->display.atomic_update_watermarks)
13269 dev_priv->display.atomic_update_watermarks(old_intel_state,
13273 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13274 struct intel_crtc_state *crtc_state)
13276 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13278 if (!IS_GEN2(dev_priv))
13279 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13281 if (crtc_state->has_pch_encoder) {
13282 enum pipe pch_transcoder =
13283 intel_crtc_pch_transcoder(crtc);
13285 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13289 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13290 struct drm_crtc_state *old_crtc_state)
13292 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13293 struct intel_atomic_state *old_intel_state =
13294 to_intel_atomic_state(old_crtc_state->state);
13295 struct intel_crtc_state *new_crtc_state =
13296 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13298 intel_pipe_update_end(new_crtc_state);
13300 if (new_crtc_state->update_pipe &&
13301 !needs_modeset(&new_crtc_state->base) &&
13302 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13303 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
13307 * intel_plane_destroy - destroy a plane
13308 * @plane: plane to destroy
13310 * Common destruction function for all types of planes (primary, cursor,
13313 void intel_plane_destroy(struct drm_plane *plane)
13315 drm_plane_cleanup(plane);
13316 kfree(to_intel_plane(plane));
13319 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13320 u32 format, u64 modifier)
13322 switch (modifier) {
13323 case DRM_FORMAT_MOD_LINEAR:
13324 case I915_FORMAT_MOD_X_TILED:
13331 case DRM_FORMAT_C8:
13332 case DRM_FORMAT_RGB565:
13333 case DRM_FORMAT_XRGB1555:
13334 case DRM_FORMAT_XRGB8888:
13335 return modifier == DRM_FORMAT_MOD_LINEAR ||
13336 modifier == I915_FORMAT_MOD_X_TILED;
13342 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13343 u32 format, u64 modifier)
13345 switch (modifier) {
13346 case DRM_FORMAT_MOD_LINEAR:
13347 case I915_FORMAT_MOD_X_TILED:
13354 case DRM_FORMAT_C8:
13355 case DRM_FORMAT_RGB565:
13356 case DRM_FORMAT_XRGB8888:
13357 case DRM_FORMAT_XBGR8888:
13358 case DRM_FORMAT_XRGB2101010:
13359 case DRM_FORMAT_XBGR2101010:
13360 return modifier == DRM_FORMAT_MOD_LINEAR ||
13361 modifier == I915_FORMAT_MOD_X_TILED;
13367 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13368 u32 format, u64 modifier)
13370 return modifier == DRM_FORMAT_MOD_LINEAR &&
13371 format == DRM_FORMAT_ARGB8888;
13374 static const struct drm_plane_funcs i965_plane_funcs = {
13375 .update_plane = drm_atomic_helper_update_plane,
13376 .disable_plane = drm_atomic_helper_disable_plane,
13377 .destroy = intel_plane_destroy,
13378 .atomic_get_property = intel_plane_atomic_get_property,
13379 .atomic_set_property = intel_plane_atomic_set_property,
13380 .atomic_duplicate_state = intel_plane_duplicate_state,
13381 .atomic_destroy_state = intel_plane_destroy_state,
13382 .format_mod_supported = i965_plane_format_mod_supported,
13385 static const struct drm_plane_funcs i8xx_plane_funcs = {
13386 .update_plane = drm_atomic_helper_update_plane,
13387 .disable_plane = drm_atomic_helper_disable_plane,
13388 .destroy = intel_plane_destroy,
13389 .atomic_get_property = intel_plane_atomic_get_property,
13390 .atomic_set_property = intel_plane_atomic_set_property,
13391 .atomic_duplicate_state = intel_plane_duplicate_state,
13392 .atomic_destroy_state = intel_plane_destroy_state,
13393 .format_mod_supported = i8xx_plane_format_mod_supported,
13397 intel_legacy_cursor_update(struct drm_plane *plane,
13398 struct drm_crtc *crtc,
13399 struct drm_framebuffer *fb,
13400 int crtc_x, int crtc_y,
13401 unsigned int crtc_w, unsigned int crtc_h,
13402 uint32_t src_x, uint32_t src_y,
13403 uint32_t src_w, uint32_t src_h,
13404 struct drm_modeset_acquire_ctx *ctx)
13406 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13408 struct drm_plane_state *old_plane_state, *new_plane_state;
13409 struct intel_plane *intel_plane = to_intel_plane(plane);
13410 struct drm_framebuffer *old_fb;
13411 struct intel_crtc_state *crtc_state =
13412 to_intel_crtc_state(crtc->state);
13413 struct intel_crtc_state *new_crtc_state;
13416 * When crtc is inactive or there is a modeset pending,
13417 * wait for it to complete in the slowpath
13419 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
13420 crtc_state->update_pipe)
13423 old_plane_state = plane->state;
13425 * Don't do an async update if there is an outstanding commit modifying
13426 * the plane. This prevents our async update's changes from getting
13427 * overridden by a previous synchronous update's state.
13429 if (old_plane_state->commit &&
13430 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13434 * If any parameters change that may affect watermarks,
13435 * take the slowpath. Only changing fb or position should be
13438 if (old_plane_state->crtc != crtc ||
13439 old_plane_state->src_w != src_w ||
13440 old_plane_state->src_h != src_h ||
13441 old_plane_state->crtc_w != crtc_w ||
13442 old_plane_state->crtc_h != crtc_h ||
13443 !old_plane_state->fb != !fb)
13446 new_plane_state = intel_plane_duplicate_state(plane);
13447 if (!new_plane_state)
13450 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
13451 if (!new_crtc_state) {
13456 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13458 new_plane_state->src_x = src_x;
13459 new_plane_state->src_y = src_y;
13460 new_plane_state->src_w = src_w;
13461 new_plane_state->src_h = src_h;
13462 new_plane_state->crtc_x = crtc_x;
13463 new_plane_state->crtc_y = crtc_y;
13464 new_plane_state->crtc_w = crtc_w;
13465 new_plane_state->crtc_h = crtc_h;
13467 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
13468 to_intel_plane_state(old_plane_state),
13469 to_intel_plane_state(new_plane_state));
13473 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13477 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13481 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
13483 old_fb = old_plane_state->fb;
13484 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13485 intel_plane->frontbuffer_bit);
13487 /* Swap plane state */
13488 plane->state = new_plane_state;
13491 * We cannot swap crtc_state as it may be in use by an atomic commit or
13492 * page flip that's running simultaneously. If we swap crtc_state and
13493 * destroy the old state, we will cause a use-after-free there.
13495 * Only update active_planes, which is needed for our internal
13496 * bookkeeping. Either value will do the right thing when updating
13497 * planes atomically. If the cursor was part of the atomic update then
13498 * we would have taken the slowpath.
13500 crtc_state->active_planes = new_crtc_state->active_planes;
13502 if (plane->state->visible) {
13503 trace_intel_update_plane(plane, to_intel_crtc(crtc));
13504 intel_plane->update_plane(intel_plane, crtc_state,
13505 to_intel_plane_state(plane->state));
13507 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
13508 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
13511 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
13514 mutex_unlock(&dev_priv->drm.struct_mutex);
13516 if (new_crtc_state)
13517 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
13519 intel_plane_destroy_state(plane, new_plane_state);
13521 intel_plane_destroy_state(plane, old_plane_state);
13525 return drm_atomic_helper_update_plane(plane, crtc, fb,
13526 crtc_x, crtc_y, crtc_w, crtc_h,
13527 src_x, src_y, src_w, src_h, ctx);
13530 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13531 .update_plane = intel_legacy_cursor_update,
13532 .disable_plane = drm_atomic_helper_disable_plane,
13533 .destroy = intel_plane_destroy,
13534 .atomic_get_property = intel_plane_atomic_get_property,
13535 .atomic_set_property = intel_plane_atomic_set_property,
13536 .atomic_duplicate_state = intel_plane_duplicate_state,
13537 .atomic_destroy_state = intel_plane_destroy_state,
13538 .format_mod_supported = intel_cursor_format_mod_supported,
13541 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13542 enum i9xx_plane_id i9xx_plane)
13544 if (!HAS_FBC(dev_priv))
13547 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13548 return i9xx_plane == PLANE_A; /* tied to pipe A */
13549 else if (IS_IVYBRIDGE(dev_priv))
13550 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13551 i9xx_plane == PLANE_C;
13552 else if (INTEL_GEN(dev_priv) >= 4)
13553 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13555 return i9xx_plane == PLANE_A;
13558 static struct intel_plane *
13559 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
13561 struct intel_plane *plane;
13562 const struct drm_plane_funcs *plane_funcs;
13563 unsigned int supported_rotations;
13564 unsigned int possible_crtcs;
13565 const u64 *modifiers;
13566 const u32 *formats;
13570 if (INTEL_GEN(dev_priv) >= 9)
13571 return skl_universal_plane_create(dev_priv, pipe,
13574 plane = intel_plane_alloc();
13578 plane->pipe = pipe;
13580 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13581 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13583 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
13584 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
13586 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
13587 plane->id = PLANE_PRIMARY;
13588 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
13590 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
13591 if (plane->has_fbc) {
13592 struct intel_fbc *fbc = &dev_priv->fbc;
13594 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
13597 if (INTEL_GEN(dev_priv) >= 4) {
13598 formats = i965_primary_formats;
13599 num_formats = ARRAY_SIZE(i965_primary_formats);
13600 modifiers = i9xx_format_modifiers;
13602 plane->max_stride = i9xx_plane_max_stride;
13603 plane->update_plane = i9xx_update_plane;
13604 plane->disable_plane = i9xx_disable_plane;
13605 plane->get_hw_state = i9xx_plane_get_hw_state;
13606 plane->check_plane = i9xx_plane_check;
13608 plane_funcs = &i965_plane_funcs;
13610 formats = i8xx_primary_formats;
13611 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13612 modifiers = i9xx_format_modifiers;
13614 plane->max_stride = i9xx_plane_max_stride;
13615 plane->update_plane = i9xx_update_plane;
13616 plane->disable_plane = i9xx_disable_plane;
13617 plane->get_hw_state = i9xx_plane_get_hw_state;
13618 plane->check_plane = i9xx_plane_check;
13620 plane_funcs = &i8xx_plane_funcs;
13623 possible_crtcs = BIT(pipe);
13625 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
13626 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
13627 possible_crtcs, plane_funcs,
13628 formats, num_formats, modifiers,
13629 DRM_PLANE_TYPE_PRIMARY,
13630 "primary %c", pipe_name(pipe));
13632 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
13633 possible_crtcs, plane_funcs,
13634 formats, num_formats, modifiers,
13635 DRM_PLANE_TYPE_PRIMARY,
13637 plane_name(plane->i9xx_plane));
13641 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13642 supported_rotations =
13643 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13644 DRM_MODE_REFLECT_X;
13645 } else if (INTEL_GEN(dev_priv) >= 4) {
13646 supported_rotations =
13647 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
13649 supported_rotations = DRM_MODE_ROTATE_0;
13652 if (INTEL_GEN(dev_priv) >= 4)
13653 drm_plane_create_rotation_property(&plane->base,
13655 supported_rotations);
13657 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
13662 intel_plane_free(plane);
13664 return ERR_PTR(ret);
13667 static struct intel_plane *
13668 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13671 unsigned int possible_crtcs;
13672 struct intel_plane *cursor;
13675 cursor = intel_plane_alloc();
13676 if (IS_ERR(cursor))
13679 cursor->pipe = pipe;
13680 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
13681 cursor->id = PLANE_CURSOR;
13682 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
13684 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
13685 cursor->max_stride = i845_cursor_max_stride;
13686 cursor->update_plane = i845_update_cursor;
13687 cursor->disable_plane = i845_disable_cursor;
13688 cursor->get_hw_state = i845_cursor_get_hw_state;
13689 cursor->check_plane = i845_check_cursor;
13691 cursor->max_stride = i9xx_cursor_max_stride;
13692 cursor->update_plane = i9xx_update_cursor;
13693 cursor->disable_plane = i9xx_disable_cursor;
13694 cursor->get_hw_state = i9xx_cursor_get_hw_state;
13695 cursor->check_plane = i9xx_check_cursor;
13698 cursor->cursor.base = ~0;
13699 cursor->cursor.cntl = ~0;
13701 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13702 cursor->cursor.size = ~0;
13704 possible_crtcs = BIT(pipe);
13706 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
13707 possible_crtcs, &intel_cursor_plane_funcs,
13708 intel_cursor_formats,
13709 ARRAY_SIZE(intel_cursor_formats),
13710 cursor_format_modifiers,
13711 DRM_PLANE_TYPE_CURSOR,
13712 "cursor %c", pipe_name(pipe));
13716 if (INTEL_GEN(dev_priv) >= 4)
13717 drm_plane_create_rotation_property(&cursor->base,
13719 DRM_MODE_ROTATE_0 |
13720 DRM_MODE_ROTATE_180);
13722 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13727 intel_plane_free(cursor);
13729 return ERR_PTR(ret);
13732 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
13733 struct intel_crtc_state *crtc_state)
13735 struct intel_crtc_scaler_state *scaler_state =
13736 &crtc_state->scaler_state;
13737 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13740 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
13741 if (!crtc->num_scalers)
13744 for (i = 0; i < crtc->num_scalers; i++) {
13745 struct intel_scaler *scaler = &scaler_state->scalers[i];
13747 scaler->in_use = 0;
13751 scaler_state->scaler_id = -1;
13754 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
13756 struct intel_crtc *intel_crtc;
13757 struct intel_crtc_state *crtc_state = NULL;
13758 struct intel_plane *primary = NULL;
13759 struct intel_plane *cursor = NULL;
13762 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
13766 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
13771 intel_crtc->config = crtc_state;
13772 intel_crtc->base.state = &crtc_state->base;
13773 crtc_state->base.crtc = &intel_crtc->base;
13775 primary = intel_primary_plane_create(dev_priv, pipe);
13776 if (IS_ERR(primary)) {
13777 ret = PTR_ERR(primary);
13780 intel_crtc->plane_ids_mask |= BIT(primary->id);
13782 for_each_sprite(dev_priv, pipe, sprite) {
13783 struct intel_plane *plane;
13785 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
13786 if (IS_ERR(plane)) {
13787 ret = PTR_ERR(plane);
13790 intel_crtc->plane_ids_mask |= BIT(plane->id);
13793 cursor = intel_cursor_plane_create(dev_priv, pipe);
13794 if (IS_ERR(cursor)) {
13795 ret = PTR_ERR(cursor);
13798 intel_crtc->plane_ids_mask |= BIT(cursor->id);
13800 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
13801 &primary->base, &cursor->base,
13803 "pipe %c", pipe_name(pipe));
13807 intel_crtc->pipe = pipe;
13809 /* initialize shared scalers */
13810 intel_crtc_init_scalers(intel_crtc, crtc_state);
13812 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
13813 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
13814 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
13816 if (INTEL_GEN(dev_priv) < 9) {
13817 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
13819 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
13820 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
13821 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
13824 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
13826 intel_color_init(&intel_crtc->base);
13828 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
13834 * drm_mode_config_cleanup() will free up any
13835 * crtcs/planes already initialized.
13843 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
13845 struct drm_device *dev = connector->base.dev;
13847 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
13849 if (!connector->base.state->crtc)
13850 return INVALID_PIPE;
13852 return to_intel_crtc(connector->base.state->crtc)->pipe;
13855 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
13856 struct drm_file *file)
13858 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
13859 struct drm_crtc *drmmode_crtc;
13860 struct intel_crtc *crtc;
13862 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
13866 crtc = to_intel_crtc(drmmode_crtc);
13867 pipe_from_crtc_id->pipe = crtc->pipe;
13872 static int intel_encoder_clones(struct intel_encoder *encoder)
13874 struct drm_device *dev = encoder->base.dev;
13875 struct intel_encoder *source_encoder;
13876 int index_mask = 0;
13879 for_each_intel_encoder(dev, source_encoder) {
13880 if (encoders_cloneable(encoder, source_encoder))
13881 index_mask |= (1 << entry);
13889 static bool has_edp_a(struct drm_i915_private *dev_priv)
13891 if (!IS_MOBILE(dev_priv))
13894 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
13897 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
13903 static bool intel_crt_present(struct drm_i915_private *dev_priv)
13905 if (INTEL_GEN(dev_priv) >= 9)
13908 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
13911 if (IS_CHERRYVIEW(dev_priv))
13914 if (HAS_PCH_LPT_H(dev_priv) &&
13915 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
13918 /* DDI E can't be used if DDI A requires 4 lanes */
13919 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
13922 if (!dev_priv->vbt.int_crt_support)
13928 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
13933 if (HAS_DDI(dev_priv))
13936 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13937 * everywhere where registers can be write protected.
13939 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13944 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
13945 u32 val = I915_READ(PP_CONTROL(pps_idx));
13947 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
13948 I915_WRITE(PP_CONTROL(pps_idx), val);
13952 static void intel_pps_init(struct drm_i915_private *dev_priv)
13954 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
13955 dev_priv->pps_mmio_base = PCH_PPS_BASE;
13956 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13957 dev_priv->pps_mmio_base = VLV_PPS_BASE;
13959 dev_priv->pps_mmio_base = PPS_BASE;
13961 intel_pps_unlock_regs_wa(dev_priv);
13964 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
13966 struct intel_encoder *encoder;
13967 bool dpd_is_edp = false;
13969 intel_pps_init(dev_priv);
13971 if (INTEL_INFO(dev_priv)->num_pipes == 0)
13975 * intel_edp_init_connector() depends on this completing first, to
13976 * prevent the registeration of both eDP and LVDS and the incorrect
13977 * sharing of the PPS.
13979 intel_lvds_init(dev_priv);
13981 if (intel_crt_present(dev_priv))
13982 intel_crt_init(dev_priv);
13984 if (IS_ICELAKE(dev_priv)) {
13985 intel_ddi_init(dev_priv, PORT_A);
13986 intel_ddi_init(dev_priv, PORT_B);
13987 intel_ddi_init(dev_priv, PORT_C);
13988 intel_ddi_init(dev_priv, PORT_D);
13989 intel_ddi_init(dev_priv, PORT_E);
13990 intel_ddi_init(dev_priv, PORT_F);
13991 } else if (IS_GEN9_LP(dev_priv)) {
13993 * FIXME: Broxton doesn't support port detection via the
13994 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13995 * detect the ports.
13997 intel_ddi_init(dev_priv, PORT_A);
13998 intel_ddi_init(dev_priv, PORT_B);
13999 intel_ddi_init(dev_priv, PORT_C);
14001 vlv_dsi_init(dev_priv);
14002 } else if (HAS_DDI(dev_priv)) {
14006 * Haswell uses DDI functions to detect digital outputs.
14007 * On SKL pre-D0 the strap isn't connected, so we assume
14010 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
14011 /* WaIgnoreDDIAStrap: skl */
14012 if (found || IS_GEN9_BC(dev_priv))
14013 intel_ddi_init(dev_priv, PORT_A);
14015 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
14017 found = I915_READ(SFUSE_STRAP);
14019 if (found & SFUSE_STRAP_DDIB_DETECTED)
14020 intel_ddi_init(dev_priv, PORT_B);
14021 if (found & SFUSE_STRAP_DDIC_DETECTED)
14022 intel_ddi_init(dev_priv, PORT_C);
14023 if (found & SFUSE_STRAP_DDID_DETECTED)
14024 intel_ddi_init(dev_priv, PORT_D);
14025 if (found & SFUSE_STRAP_DDIF_DETECTED)
14026 intel_ddi_init(dev_priv, PORT_F);
14028 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14030 if (IS_GEN9_BC(dev_priv) &&
14031 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14032 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14033 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
14034 intel_ddi_init(dev_priv, PORT_E);
14036 } else if (HAS_PCH_SPLIT(dev_priv)) {
14038 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
14040 if (has_edp_a(dev_priv))
14041 intel_dp_init(dev_priv, DP_A, PORT_A);
14043 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
14044 /* PCH SDVOB multiplex with HDMIB */
14045 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
14047 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
14048 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
14049 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
14052 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
14053 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
14055 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
14056 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
14058 if (I915_READ(PCH_DP_C) & DP_DETECTED)
14059 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
14061 if (I915_READ(PCH_DP_D) & DP_DETECTED)
14062 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
14063 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
14064 bool has_edp, has_port;
14067 * The DP_DETECTED bit is the latched state of the DDC
14068 * SDA pin at boot. However since eDP doesn't require DDC
14069 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14070 * eDP ports may have been muxed to an alternate function.
14071 * Thus we can't rely on the DP_DETECTED bit alone to detect
14072 * eDP ports. Consult the VBT as well as DP_DETECTED to
14073 * detect eDP ports.
14075 * Sadly the straps seem to be missing sometimes even for HDMI
14076 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14077 * and VBT for the presence of the port. Additionally we can't
14078 * trust the port type the VBT declares as we've seen at least
14079 * HDMI ports that the VBT claim are DP or eDP.
14081 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
14082 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14083 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
14084 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
14085 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
14086 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
14088 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
14089 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14090 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
14091 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
14092 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
14093 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
14095 if (IS_CHERRYVIEW(dev_priv)) {
14097 * eDP not supported on port D,
14098 * so no need to worry about it
14100 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14101 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
14102 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
14103 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
14104 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
14107 vlv_dsi_init(dev_priv);
14108 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
14109 bool found = false;
14111 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14112 DRM_DEBUG_KMS("probing SDVOB\n");
14113 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
14114 if (!found && IS_G4X(dev_priv)) {
14115 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14116 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
14119 if (!found && IS_G4X(dev_priv))
14120 intel_dp_init(dev_priv, DP_B, PORT_B);
14123 /* Before G4X SDVOC doesn't have its own detect register */
14125 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14126 DRM_DEBUG_KMS("probing SDVOC\n");
14127 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
14130 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14132 if (IS_G4X(dev_priv)) {
14133 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14134 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
14136 if (IS_G4X(dev_priv))
14137 intel_dp_init(dev_priv, DP_C, PORT_C);
14140 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
14141 intel_dp_init(dev_priv, DP_D, PORT_D);
14142 } else if (IS_GEN2(dev_priv))
14143 intel_dvo_init(dev_priv);
14145 if (SUPPORTS_TV(dev_priv))
14146 intel_tv_init(dev_priv);
14148 intel_psr_init(dev_priv);
14150 for_each_intel_encoder(&dev_priv->drm, encoder) {
14151 encoder->base.possible_crtcs = encoder->crtc_mask;
14152 encoder->base.possible_clones =
14153 intel_encoder_clones(encoder);
14156 intel_init_pch_refclk(dev_priv);
14158 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14161 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14163 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14164 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14166 drm_framebuffer_cleanup(fb);
14168 i915_gem_object_lock(obj);
14169 WARN_ON(!obj->framebuffer_references--);
14170 i915_gem_object_unlock(obj);
14172 i915_gem_object_put(obj);
14177 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14178 struct drm_file *file,
14179 unsigned int *handle)
14181 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14183 if (obj->userptr.mm) {
14184 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14188 return drm_gem_handle_create(file, &obj->base, handle);
14191 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14192 struct drm_file *file,
14193 unsigned flags, unsigned color,
14194 struct drm_clip_rect *clips,
14195 unsigned num_clips)
14197 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14199 i915_gem_object_flush_if_display(obj);
14200 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14205 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14206 .destroy = intel_user_framebuffer_destroy,
14207 .create_handle = intel_user_framebuffer_create_handle,
14208 .dirty = intel_user_framebuffer_dirty,
14212 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14213 uint64_t fb_modifier, uint32_t pixel_format)
14215 struct intel_crtc *crtc;
14216 struct intel_plane *plane;
14219 * We assume the primary plane for pipe A has
14220 * the highest stride limits of them all.
14222 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14223 plane = to_intel_plane(crtc->base.primary);
14225 return plane->max_stride(plane, pixel_format, fb_modifier,
14226 DRM_MODE_ROTATE_0);
14229 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14230 struct drm_i915_gem_object *obj,
14231 struct drm_mode_fb_cmd2 *mode_cmd)
14233 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14234 struct drm_framebuffer *fb = &intel_fb->base;
14235 struct drm_format_name_buf format_name;
14237 unsigned int tiling, stride;
14241 i915_gem_object_lock(obj);
14242 obj->framebuffer_references++;
14243 tiling = i915_gem_object_get_tiling(obj);
14244 stride = i915_gem_object_get_stride(obj);
14245 i915_gem_object_unlock(obj);
14247 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14249 * If there's a fence, enforce that
14250 * the fb modifier and tiling mode match.
14252 if (tiling != I915_TILING_NONE &&
14253 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14254 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14258 if (tiling == I915_TILING_X) {
14259 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14260 } else if (tiling == I915_TILING_Y) {
14261 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14266 /* Passed in modifier sanity checking. */
14267 switch (mode_cmd->modifier[0]) {
14268 case I915_FORMAT_MOD_Y_TILED_CCS:
14269 case I915_FORMAT_MOD_Yf_TILED_CCS:
14270 switch (mode_cmd->pixel_format) {
14271 case DRM_FORMAT_XBGR8888:
14272 case DRM_FORMAT_ABGR8888:
14273 case DRM_FORMAT_XRGB8888:
14274 case DRM_FORMAT_ARGB8888:
14277 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
14281 case I915_FORMAT_MOD_Y_TILED:
14282 case I915_FORMAT_MOD_Yf_TILED:
14283 if (INTEL_GEN(dev_priv) < 9) {
14284 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14285 mode_cmd->modifier[0]);
14288 case DRM_FORMAT_MOD_LINEAR:
14289 case I915_FORMAT_MOD_X_TILED:
14292 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14293 mode_cmd->modifier[0]);
14298 * gen2/3 display engine uses the fence if present,
14299 * so the tiling mode must match the fb modifier exactly.
14301 if (INTEL_GEN(dev_priv) < 4 &&
14302 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14303 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14307 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
14308 mode_cmd->pixel_format);
14309 if (mode_cmd->pitches[0] > pitch_limit) {
14310 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14311 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14312 "tiled" : "linear",
14313 mode_cmd->pitches[0], pitch_limit);
14318 * If there's a fence, enforce that
14319 * the fb pitch and fence stride match.
14321 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14322 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14323 mode_cmd->pitches[0], stride);
14327 /* Reject formats not supported by any plane early. */
14328 switch (mode_cmd->pixel_format) {
14329 case DRM_FORMAT_C8:
14330 case DRM_FORMAT_RGB565:
14331 case DRM_FORMAT_XRGB8888:
14332 case DRM_FORMAT_ARGB8888:
14334 case DRM_FORMAT_XRGB1555:
14335 if (INTEL_GEN(dev_priv) > 3) {
14336 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14337 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14341 case DRM_FORMAT_ABGR8888:
14342 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
14343 INTEL_GEN(dev_priv) < 9) {
14344 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14345 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14349 case DRM_FORMAT_XBGR8888:
14350 case DRM_FORMAT_XRGB2101010:
14351 case DRM_FORMAT_XBGR2101010:
14352 if (INTEL_GEN(dev_priv) < 4) {
14353 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14354 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14358 case DRM_FORMAT_ABGR2101010:
14359 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
14360 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14361 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14365 case DRM_FORMAT_YUYV:
14366 case DRM_FORMAT_UYVY:
14367 case DRM_FORMAT_YVYU:
14368 case DRM_FORMAT_VYUY:
14369 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
14370 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14371 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14375 case DRM_FORMAT_NV12:
14376 if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) ||
14377 IS_BROXTON(dev_priv) || INTEL_GEN(dev_priv) >= 11) {
14378 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14379 drm_get_format_name(mode_cmd->pixel_format,
14385 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14386 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14390 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14391 if (mode_cmd->offsets[0] != 0)
14394 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14396 if (fb->format->format == DRM_FORMAT_NV12 &&
14397 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14398 fb->height < SKL_MIN_YUV_420_SRC_H ||
14399 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14400 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
14404 for (i = 0; i < fb->format->num_planes; i++) {
14405 u32 stride_alignment;
14407 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14408 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14412 stride_alignment = intel_fb_stride_alignment(fb, i);
14415 * Display WA #0531: skl,bxt,kbl,glk
14417 * Render decompression and plane width > 3840
14418 * combined with horizontal panning requires the
14419 * plane stride to be a multiple of 4. We'll just
14420 * require the entire fb to accommodate that to avoid
14421 * potential runtime errors at plane configuration time.
14423 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
14424 is_ccs_modifier(fb->modifier))
14425 stride_alignment *= 4;
14427 if (fb->pitches[i] & (stride_alignment - 1)) {
14428 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14429 i, fb->pitches[i], stride_alignment);
14433 fb->obj[i] = &obj->base;
14436 ret = intel_fill_fb_info(dev_priv, fb);
14440 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14442 DRM_ERROR("framebuffer init failed %d\n", ret);
14449 i915_gem_object_lock(obj);
14450 obj->framebuffer_references--;
14451 i915_gem_object_unlock(obj);
14455 static struct drm_framebuffer *
14456 intel_user_framebuffer_create(struct drm_device *dev,
14457 struct drm_file *filp,
14458 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14460 struct drm_framebuffer *fb;
14461 struct drm_i915_gem_object *obj;
14462 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14464 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14466 return ERR_PTR(-ENOENT);
14468 fb = intel_framebuffer_create(obj, &mode_cmd);
14470 i915_gem_object_put(obj);
14475 static void intel_atomic_state_free(struct drm_atomic_state *state)
14477 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14479 drm_atomic_state_default_release(state);
14481 i915_sw_fence_fini(&intel_state->commit_ready);
14486 static enum drm_mode_status
14487 intel_mode_valid(struct drm_device *dev,
14488 const struct drm_display_mode *mode)
14490 struct drm_i915_private *dev_priv = to_i915(dev);
14491 int hdisplay_max, htotal_max;
14492 int vdisplay_max, vtotal_max;
14495 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14496 * of DBLSCAN modes to the output's mode list when they detect
14497 * the scaling mode property on the connector. And they don't
14498 * ask the kernel to validate those modes in any way until
14499 * modeset time at which point the client gets a protocol error.
14500 * So in order to not upset those clients we silently ignore the
14501 * DBLSCAN flag on such connectors. For other connectors we will
14502 * reject modes with the DBLSCAN flag in encoder->compute_config().
14503 * And we always reject DBLSCAN modes in connector->mode_valid()
14504 * as we never want such modes on the connector's mode list.
14507 if (mode->vscan > 1)
14508 return MODE_NO_VSCAN;
14510 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14511 return MODE_H_ILLEGAL;
14513 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14514 DRM_MODE_FLAG_NCSYNC |
14515 DRM_MODE_FLAG_PCSYNC))
14518 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14519 DRM_MODE_FLAG_PIXMUX |
14520 DRM_MODE_FLAG_CLKDIV2))
14523 if (INTEL_GEN(dev_priv) >= 9 ||
14524 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14525 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14526 vdisplay_max = 4096;
14529 } else if (INTEL_GEN(dev_priv) >= 3) {
14530 hdisplay_max = 4096;
14531 vdisplay_max = 4096;
14535 hdisplay_max = 2048;
14536 vdisplay_max = 2048;
14541 if (mode->hdisplay > hdisplay_max ||
14542 mode->hsync_start > htotal_max ||
14543 mode->hsync_end > htotal_max ||
14544 mode->htotal > htotal_max)
14545 return MODE_H_ILLEGAL;
14547 if (mode->vdisplay > vdisplay_max ||
14548 mode->vsync_start > vtotal_max ||
14549 mode->vsync_end > vtotal_max ||
14550 mode->vtotal > vtotal_max)
14551 return MODE_V_ILLEGAL;
14556 static const struct drm_mode_config_funcs intel_mode_funcs = {
14557 .fb_create = intel_user_framebuffer_create,
14558 .get_format_info = intel_get_format_info,
14559 .output_poll_changed = intel_fbdev_output_poll_changed,
14560 .mode_valid = intel_mode_valid,
14561 .atomic_check = intel_atomic_check,
14562 .atomic_commit = intel_atomic_commit,
14563 .atomic_state_alloc = intel_atomic_state_alloc,
14564 .atomic_state_clear = intel_atomic_state_clear,
14565 .atomic_state_free = intel_atomic_state_free,
14569 * intel_init_display_hooks - initialize the display modesetting hooks
14570 * @dev_priv: device private
14572 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14574 intel_init_cdclk_hooks(dev_priv);
14576 if (INTEL_GEN(dev_priv) >= 9) {
14577 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14578 dev_priv->display.get_initial_plane_config =
14579 skylake_get_initial_plane_config;
14580 dev_priv->display.crtc_compute_clock =
14581 haswell_crtc_compute_clock;
14582 dev_priv->display.crtc_enable = haswell_crtc_enable;
14583 dev_priv->display.crtc_disable = haswell_crtc_disable;
14584 } else if (HAS_DDI(dev_priv)) {
14585 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14586 dev_priv->display.get_initial_plane_config =
14587 i9xx_get_initial_plane_config;
14588 dev_priv->display.crtc_compute_clock =
14589 haswell_crtc_compute_clock;
14590 dev_priv->display.crtc_enable = haswell_crtc_enable;
14591 dev_priv->display.crtc_disable = haswell_crtc_disable;
14592 } else if (HAS_PCH_SPLIT(dev_priv)) {
14593 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14594 dev_priv->display.get_initial_plane_config =
14595 i9xx_get_initial_plane_config;
14596 dev_priv->display.crtc_compute_clock =
14597 ironlake_crtc_compute_clock;
14598 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14599 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14600 } else if (IS_CHERRYVIEW(dev_priv)) {
14601 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14602 dev_priv->display.get_initial_plane_config =
14603 i9xx_get_initial_plane_config;
14604 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14605 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14606 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14607 } else if (IS_VALLEYVIEW(dev_priv)) {
14608 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14609 dev_priv->display.get_initial_plane_config =
14610 i9xx_get_initial_plane_config;
14611 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
14612 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14613 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14614 } else if (IS_G4X(dev_priv)) {
14615 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14616 dev_priv->display.get_initial_plane_config =
14617 i9xx_get_initial_plane_config;
14618 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14619 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14620 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14621 } else if (IS_PINEVIEW(dev_priv)) {
14622 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14623 dev_priv->display.get_initial_plane_config =
14624 i9xx_get_initial_plane_config;
14625 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14626 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14627 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14628 } else if (!IS_GEN2(dev_priv)) {
14629 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14630 dev_priv->display.get_initial_plane_config =
14631 i9xx_get_initial_plane_config;
14632 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14633 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14634 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14636 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14637 dev_priv->display.get_initial_plane_config =
14638 i9xx_get_initial_plane_config;
14639 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14640 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14641 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14644 if (IS_GEN5(dev_priv)) {
14645 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14646 } else if (IS_GEN6(dev_priv)) {
14647 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14648 } else if (IS_IVYBRIDGE(dev_priv)) {
14649 /* FIXME: detect B0+ stepping and use auto training */
14650 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14651 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
14652 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14655 if (INTEL_GEN(dev_priv) >= 9)
14656 dev_priv->display.update_crtcs = skl_update_crtcs;
14658 dev_priv->display.update_crtcs = intel_update_crtcs;
14662 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14664 static void quirk_ssc_force_disable(struct drm_device *dev)
14666 struct drm_i915_private *dev_priv = to_i915(dev);
14667 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14668 DRM_INFO("applying lvds SSC disable quirk\n");
14672 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14675 static void quirk_invert_brightness(struct drm_device *dev)
14677 struct drm_i915_private *dev_priv = to_i915(dev);
14678 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14679 DRM_INFO("applying inverted panel brightness quirk\n");
14682 /* Some VBT's incorrectly indicate no backlight is present */
14683 static void quirk_backlight_present(struct drm_device *dev)
14685 struct drm_i915_private *dev_priv = to_i915(dev);
14686 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14687 DRM_INFO("applying backlight present quirk\n");
14690 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
14691 * which is 300 ms greater than eDP spec T12 min.
14693 static void quirk_increase_t12_delay(struct drm_device *dev)
14695 struct drm_i915_private *dev_priv = to_i915(dev);
14697 dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY;
14698 DRM_INFO("Applying T12 delay quirk\n");
14702 * GeminiLake NUC HDMI outputs require additional off time
14703 * this allows the onboard retimer to correctly sync to signal
14705 static void quirk_increase_ddi_disabled_time(struct drm_device *dev)
14707 struct drm_i915_private *dev_priv = to_i915(dev);
14709 dev_priv->quirks |= QUIRK_INCREASE_DDI_DISABLED_TIME;
14710 DRM_INFO("Applying Increase DDI Disabled quirk\n");
14713 struct intel_quirk {
14715 int subsystem_vendor;
14716 int subsystem_device;
14717 void (*hook)(struct drm_device *dev);
14720 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14721 struct intel_dmi_quirk {
14722 void (*hook)(struct drm_device *dev);
14723 const struct dmi_system_id (*dmi_id_list)[];
14726 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
14728 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
14732 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
14734 .dmi_id_list = &(const struct dmi_system_id[]) {
14736 .callback = intel_dmi_reverse_brightness,
14737 .ident = "NCR Corporation",
14738 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
14739 DMI_MATCH(DMI_PRODUCT_NAME, ""),
14742 { } /* terminating entry */
14744 .hook = quirk_invert_brightness,
14748 static struct intel_quirk intel_quirks[] = {
14749 /* Lenovo U160 cannot use SSC on LVDS */
14750 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
14752 /* Sony Vaio Y cannot use SSC on LVDS */
14753 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
14755 /* Acer Aspire 5734Z must invert backlight brightness */
14756 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
14758 /* Acer/eMachines G725 */
14759 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
14761 /* Acer/eMachines e725 */
14762 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
14764 /* Acer/Packard Bell NCL20 */
14765 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
14767 /* Acer Aspire 4736Z */
14768 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
14770 /* Acer Aspire 5336 */
14771 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
14773 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14774 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
14776 /* Acer C720 Chromebook (Core i3 4005U) */
14777 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
14779 /* Apple Macbook 2,1 (Core 2 T7400) */
14780 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
14782 /* Apple Macbook 4,1 */
14783 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
14785 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14786 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
14788 /* HP Chromebook 14 (Celeron 2955U) */
14789 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
14791 /* Dell Chromebook 11 */
14792 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
14794 /* Dell Chromebook 11 (2015 version) */
14795 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
14797 /* Toshiba Satellite P50-C-18C */
14798 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
14800 /* GeminiLake NUC */
14801 { 0x3185, 0x8086, 0x2072, quirk_increase_ddi_disabled_time },
14802 { 0x3184, 0x8086, 0x2072, quirk_increase_ddi_disabled_time },
14804 { 0x3185, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },
14805 { 0x3184, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },
14808 static void intel_init_quirks(struct drm_device *dev)
14810 struct pci_dev *d = dev->pdev;
14813 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
14814 struct intel_quirk *q = &intel_quirks[i];
14816 if (d->device == q->device &&
14817 (d->subsystem_vendor == q->subsystem_vendor ||
14818 q->subsystem_vendor == PCI_ANY_ID) &&
14819 (d->subsystem_device == q->subsystem_device ||
14820 q->subsystem_device == PCI_ANY_ID))
14823 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
14824 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
14825 intel_dmi_quirks[i].hook(dev);
14829 /* Disable the VGA plane that we never use */
14830 static void i915_disable_vga(struct drm_i915_private *dev_priv)
14832 struct pci_dev *pdev = dev_priv->drm.pdev;
14834 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
14836 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14837 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
14838 outb(SR01, VGA_SR_INDEX);
14839 sr1 = inb(VGA_SR_DATA);
14840 outb(sr1 | 1<<5, VGA_SR_DATA);
14841 vga_put(pdev, VGA_RSRC_LEGACY_IO);
14844 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
14845 POSTING_READ(vga_reg);
14848 void intel_modeset_init_hw(struct drm_device *dev)
14850 struct drm_i915_private *dev_priv = to_i915(dev);
14852 intel_update_cdclk(dev_priv);
14853 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
14854 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
14858 * Calculate what we think the watermarks should be for the state we've read
14859 * out of the hardware and then immediately program those watermarks so that
14860 * we ensure the hardware settings match our internal state.
14862 * We can calculate what we think WM's should be by creating a duplicate of the
14863 * current state (which was constructed during hardware readout) and running it
14864 * through the atomic check code to calculate new watermark values in the
14867 static void sanitize_watermarks(struct drm_device *dev)
14869 struct drm_i915_private *dev_priv = to_i915(dev);
14870 struct drm_atomic_state *state;
14871 struct intel_atomic_state *intel_state;
14872 struct drm_crtc *crtc;
14873 struct drm_crtc_state *cstate;
14874 struct drm_modeset_acquire_ctx ctx;
14878 /* Only supported on platforms that use atomic watermark design */
14879 if (!dev_priv->display.optimize_watermarks)
14883 * We need to hold connection_mutex before calling duplicate_state so
14884 * that the connector loop is protected.
14886 drm_modeset_acquire_init(&ctx, 0);
14888 ret = drm_modeset_lock_all_ctx(dev, &ctx);
14889 if (ret == -EDEADLK) {
14890 drm_modeset_backoff(&ctx);
14892 } else if (WARN_ON(ret)) {
14896 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14897 if (WARN_ON(IS_ERR(state)))
14900 intel_state = to_intel_atomic_state(state);
14903 * Hardware readout is the only time we don't want to calculate
14904 * intermediate watermarks (since we don't trust the current
14907 if (!HAS_GMCH_DISPLAY(dev_priv))
14908 intel_state->skip_intermediate_wm = true;
14910 ret = intel_atomic_check(dev, state);
14913 * If we fail here, it means that the hardware appears to be
14914 * programmed in a way that shouldn't be possible, given our
14915 * understanding of watermark requirements. This might mean a
14916 * mistake in the hardware readout code or a mistake in the
14917 * watermark calculations for a given platform. Raise a WARN
14918 * so that this is noticeable.
14920 * If this actually happens, we'll have to just leave the
14921 * BIOS-programmed watermarks untouched and hope for the best.
14923 WARN(true, "Could not determine valid watermarks for inherited state\n");
14927 /* Write calculated watermark values back */
14928 for_each_new_crtc_in_state(state, crtc, cstate, i) {
14929 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14931 cs->wm.need_postvbl_update = true;
14932 dev_priv->display.optimize_watermarks(intel_state, cs);
14934 to_intel_crtc_state(crtc->state)->wm = cs->wm;
14938 drm_atomic_state_put(state);
14940 drm_modeset_drop_locks(&ctx);
14941 drm_modeset_acquire_fini(&ctx);
14944 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14946 if (IS_GEN5(dev_priv)) {
14948 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14950 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14951 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
14952 dev_priv->fdi_pll_freq = 270000;
14957 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14960 static int intel_initial_commit(struct drm_device *dev)
14962 struct drm_atomic_state *state = NULL;
14963 struct drm_modeset_acquire_ctx ctx;
14964 struct drm_crtc *crtc;
14965 struct drm_crtc_state *crtc_state;
14968 state = drm_atomic_state_alloc(dev);
14972 drm_modeset_acquire_init(&ctx, 0);
14975 state->acquire_ctx = &ctx;
14977 drm_for_each_crtc(crtc, dev) {
14978 crtc_state = drm_atomic_get_crtc_state(state, crtc);
14979 if (IS_ERR(crtc_state)) {
14980 ret = PTR_ERR(crtc_state);
14984 if (crtc_state->active) {
14985 ret = drm_atomic_add_affected_planes(state, crtc);
14991 ret = drm_atomic_commit(state);
14994 if (ret == -EDEADLK) {
14995 drm_atomic_state_clear(state);
14996 drm_modeset_backoff(&ctx);
15000 drm_atomic_state_put(state);
15002 drm_modeset_drop_locks(&ctx);
15003 drm_modeset_acquire_fini(&ctx);
15008 int intel_modeset_init(struct drm_device *dev)
15010 struct drm_i915_private *dev_priv = to_i915(dev);
15011 struct i915_ggtt *ggtt = &dev_priv->ggtt;
15013 struct intel_crtc *crtc;
15016 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15018 drm_mode_config_init(dev);
15020 dev->mode_config.min_width = 0;
15021 dev->mode_config.min_height = 0;
15023 dev->mode_config.preferred_depth = 24;
15024 dev->mode_config.prefer_shadow = 1;
15026 dev->mode_config.allow_fb_modifiers = true;
15028 dev->mode_config.funcs = &intel_mode_funcs;
15030 init_llist_head(&dev_priv->atomic_helper.free_list);
15031 INIT_WORK(&dev_priv->atomic_helper.free_work,
15032 intel_atomic_helper_free_state_worker);
15034 intel_init_quirks(dev);
15036 intel_init_pm(dev_priv);
15039 * There may be no VBT; and if the BIOS enabled SSC we can
15040 * just keep using it to avoid unnecessary flicker. Whereas if the
15041 * BIOS isn't using it, don't assume it will work even if the VBT
15042 * indicates as much.
15044 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
15045 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15048 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15049 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15050 bios_lvds_use_ssc ? "en" : "dis",
15051 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15052 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15056 /* maximum framebuffer dimensions */
15057 if (IS_GEN2(dev_priv)) {
15058 dev->mode_config.max_width = 2048;
15059 dev->mode_config.max_height = 2048;
15060 } else if (IS_GEN3(dev_priv)) {
15061 dev->mode_config.max_width = 4096;
15062 dev->mode_config.max_height = 4096;
15064 dev->mode_config.max_width = 8192;
15065 dev->mode_config.max_height = 8192;
15068 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15069 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
15070 dev->mode_config.cursor_height = 1023;
15071 } else if (IS_GEN2(dev_priv)) {
15072 dev->mode_config.cursor_width = 64;
15073 dev->mode_config.cursor_height = 64;
15075 dev->mode_config.cursor_width = 256;
15076 dev->mode_config.cursor_height = 256;
15079 dev->mode_config.fb_base = ggtt->gmadr.start;
15081 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15082 INTEL_INFO(dev_priv)->num_pipes,
15083 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
15085 for_each_pipe(dev_priv, pipe) {
15086 ret = intel_crtc_init(dev_priv, pipe);
15088 drm_mode_config_cleanup(dev);
15093 intel_shared_dpll_init(dev);
15094 intel_update_fdi_pll_freq(dev_priv);
15096 intel_update_czclk(dev_priv);
15097 intel_modeset_init_hw(dev);
15099 if (dev_priv->max_cdclk_freq == 0)
15100 intel_update_max_cdclk(dev_priv);
15102 /* Just disable it once at startup */
15103 i915_disable_vga(dev_priv);
15104 intel_setup_outputs(dev_priv);
15106 drm_modeset_lock_all(dev);
15107 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
15108 drm_modeset_unlock_all(dev);
15110 for_each_intel_crtc(dev, crtc) {
15111 struct intel_initial_plane_config plane_config = {};
15117 * Note that reserving the BIOS fb up front prevents us
15118 * from stuffing other stolen allocations like the ring
15119 * on top. This prevents some ugliness at boot time, and
15120 * can even allow for smooth boot transitions if the BIOS
15121 * fb is large enough for the active pipe configuration.
15123 dev_priv->display.get_initial_plane_config(crtc,
15127 * If the fb is shared between multiple heads, we'll
15128 * just get the first one.
15130 intel_find_initial_plane_obj(crtc, &plane_config);
15134 * Make sure hardware watermarks really match the state we read out.
15135 * Note that we need to do this after reconstructing the BIOS fb's
15136 * since the watermark calculation done here will use pstate->fb.
15138 if (!HAS_GMCH_DISPLAY(dev_priv))
15139 sanitize_watermarks(dev);
15142 * Force all active planes to recompute their states. So that on
15143 * mode_setcrtc after probe, all the intel_plane_state variables
15144 * are already calculated and there is no assert_plane warnings
15147 ret = intel_initial_commit(dev);
15149 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15154 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15156 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15157 /* 640x480@60Hz, ~25175 kHz */
15158 struct dpll clock = {
15168 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15170 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15171 pipe_name(pipe), clock.vco, clock.dot);
15173 fp = i9xx_dpll_compute_fp(&clock);
15174 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15175 DPLL_VGA_MODE_DIS |
15176 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15177 PLL_P2_DIVIDE_BY_4 |
15178 PLL_REF_INPUT_DREFCLK |
15181 I915_WRITE(FP0(pipe), fp);
15182 I915_WRITE(FP1(pipe), fp);
15184 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15185 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15186 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15187 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15188 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15189 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15190 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15193 * Apparently we need to have VGA mode enabled prior to changing
15194 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15195 * dividers, even though the register value does change.
15197 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15198 I915_WRITE(DPLL(pipe), dpll);
15200 /* Wait for the clocks to stabilize. */
15201 POSTING_READ(DPLL(pipe));
15204 /* The pixel multiplier can only be updated once the
15205 * DPLL is enabled and the clocks are stable.
15207 * So write it again.
15209 I915_WRITE(DPLL(pipe), dpll);
15211 /* We do this three times for luck */
15212 for (i = 0; i < 3 ; i++) {
15213 I915_WRITE(DPLL(pipe), dpll);
15214 POSTING_READ(DPLL(pipe));
15215 udelay(150); /* wait for warmup */
15218 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15219 POSTING_READ(PIPECONF(pipe));
15221 intel_wait_for_pipe_scanline_moving(crtc);
15224 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15226 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15228 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15231 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15232 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15233 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
15234 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15235 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
15237 I915_WRITE(PIPECONF(pipe), 0);
15238 POSTING_READ(PIPECONF(pipe));
15240 intel_wait_for_pipe_scanline_stopped(crtc);
15242 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15243 POSTING_READ(DPLL(pipe));
15247 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15249 struct intel_crtc *crtc;
15251 if (INTEL_GEN(dev_priv) >= 4)
15254 for_each_intel_crtc(&dev_priv->drm, crtc) {
15255 struct intel_plane *plane =
15256 to_intel_plane(crtc->base.primary);
15257 struct intel_crtc *plane_crtc;
15260 if (!plane->get_hw_state(plane, &pipe))
15263 if (pipe == crtc->pipe)
15266 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15267 plane->base.base.id, plane->base.name);
15269 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15270 intel_plane_disable_noatomic(plane_crtc, plane);
15274 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15276 struct drm_device *dev = crtc->base.dev;
15277 struct intel_encoder *encoder;
15279 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15285 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15287 struct drm_device *dev = encoder->base.dev;
15288 struct intel_connector *connector;
15290 for_each_connector_on_encoder(dev, &encoder->base, connector)
15296 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15297 enum pipe pch_transcoder)
15299 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15300 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15303 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15304 struct drm_modeset_acquire_ctx *ctx)
15306 struct drm_device *dev = crtc->base.dev;
15307 struct drm_i915_private *dev_priv = to_i915(dev);
15308 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
15310 /* Clear any frame start delays used for debugging left by the BIOS */
15311 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
15312 i915_reg_t reg = PIPECONF(cpu_transcoder);
15315 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15318 if (crtc->active) {
15319 struct intel_plane *plane;
15321 /* Disable everything but the primary plane */
15322 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15323 const struct intel_plane_state *plane_state =
15324 to_intel_plane_state(plane->base.state);
15326 if (plane_state->base.visible &&
15327 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15328 intel_plane_disable_noatomic(crtc, plane);
15332 /* Adjust the state of the output pipe according to whether we
15333 * have active connectors/encoders. */
15334 if (crtc->active && !intel_crtc_has_encoders(crtc))
15335 intel_crtc_disable_noatomic(&crtc->base, ctx);
15337 if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) {
15339 * We start out with underrun reporting disabled to avoid races.
15340 * For correct bookkeeping mark this on active crtcs.
15342 * Also on gmch platforms we dont have any hardware bits to
15343 * disable the underrun reporting. Which means we need to start
15344 * out with underrun reporting disabled also on inactive pipes,
15345 * since otherwise we'll complain about the garbage we read when
15346 * e.g. coming up after runtime pm.
15348 * No protection against concurrent access is required - at
15349 * worst a fifo underrun happens which also sets this to false.
15351 crtc->cpu_fifo_underrun_disabled = true;
15353 * We track the PCH trancoder underrun reporting state
15354 * within the crtc. With crtc for pipe A housing the underrun
15355 * reporting state for PCH transcoder A, crtc for pipe B housing
15356 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15357 * and marking underrun reporting as disabled for the non-existing
15358 * PCH transcoders B and C would prevent enabling the south
15359 * error interrupt (see cpt_can_enable_serr_int()).
15361 if (has_pch_trancoder(dev_priv, crtc->pipe))
15362 crtc->pch_fifo_underrun_disabled = true;
15366 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15368 struct intel_connector *connector;
15370 /* We need to check both for a crtc link (meaning that the
15371 * encoder is active and trying to read from a pipe) and the
15372 * pipe itself being active. */
15373 bool has_active_crtc = encoder->base.crtc &&
15374 to_intel_crtc(encoder->base.crtc)->active;
15376 connector = intel_encoder_find_connector(encoder);
15377 if (connector && !has_active_crtc) {
15378 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15379 encoder->base.base.id,
15380 encoder->base.name);
15382 /* Connector is active, but has no active pipe. This is
15383 * fallout from our resume register restoring. Disable
15384 * the encoder manually again. */
15385 if (encoder->base.crtc) {
15386 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15388 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15389 encoder->base.base.id,
15390 encoder->base.name);
15391 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15392 if (encoder->post_disable)
15393 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15395 encoder->base.crtc = NULL;
15397 /* Inconsistent output/port/pipe state happens presumably due to
15398 * a bug in one of the get_hw_state functions. Or someplace else
15399 * in our code, like the register restore mess on resume. Clamp
15400 * things to off as a safer default. */
15402 connector->base.dpms = DRM_MODE_DPMS_OFF;
15403 connector->base.encoder = NULL;
15406 /* notify opregion of the sanitized encoder state */
15407 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
15410 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15412 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15414 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15415 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15416 i915_disable_vga(dev_priv);
15420 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15422 /* This function can be called both from intel_modeset_setup_hw_state or
15423 * at a very early point in our resume sequence, where the power well
15424 * structures are not yet restored. Since this function is at a very
15425 * paranoid "someone might have enabled VGA while we were not looking"
15426 * level, just check if the power well is enabled instead of trying to
15427 * follow the "don't touch the power well if we don't need it" policy
15428 * the rest of the driver uses. */
15429 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
15432 i915_redisable_vga_power_on(dev_priv);
15434 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
15437 /* FIXME read out full plane state for all planes */
15438 static void readout_plane_state(struct drm_i915_private *dev_priv)
15440 struct intel_plane *plane;
15441 struct intel_crtc *crtc;
15443 for_each_intel_plane(&dev_priv->drm, plane) {
15444 struct intel_plane_state *plane_state =
15445 to_intel_plane_state(plane->base.state);
15446 struct intel_crtc_state *crtc_state;
15447 enum pipe pipe = PIPE_A;
15450 visible = plane->get_hw_state(plane, &pipe);
15452 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15453 crtc_state = to_intel_crtc_state(crtc->base.state);
15455 intel_set_plane_visible(crtc_state, plane_state, visible);
15457 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15458 plane->base.base.id, plane->base.name,
15459 enableddisabled(visible), pipe_name(pipe));
15462 for_each_intel_crtc(&dev_priv->drm, crtc) {
15463 struct intel_crtc_state *crtc_state =
15464 to_intel_crtc_state(crtc->base.state);
15466 fixup_active_planes(crtc_state);
15470 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15472 struct drm_i915_private *dev_priv = to_i915(dev);
15474 struct intel_crtc *crtc;
15475 struct intel_encoder *encoder;
15476 struct intel_connector *connector;
15477 struct drm_connector_list_iter conn_iter;
15480 dev_priv->active_crtcs = 0;
15482 for_each_intel_crtc(dev, crtc) {
15483 struct intel_crtc_state *crtc_state =
15484 to_intel_crtc_state(crtc->base.state);
15486 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15487 memset(crtc_state, 0, sizeof(*crtc_state));
15488 crtc_state->base.crtc = &crtc->base;
15490 crtc_state->base.active = crtc_state->base.enable =
15491 dev_priv->display.get_pipe_config(crtc, crtc_state);
15493 crtc->base.enabled = crtc_state->base.enable;
15494 crtc->active = crtc_state->base.active;
15496 if (crtc_state->base.active)
15497 dev_priv->active_crtcs |= 1 << crtc->pipe;
15499 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15500 crtc->base.base.id, crtc->base.name,
15501 enableddisabled(crtc_state->base.active));
15504 readout_plane_state(dev_priv);
15506 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15507 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15509 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15510 &pll->state.hw_state);
15511 pll->state.crtc_mask = 0;
15512 for_each_intel_crtc(dev, crtc) {
15513 struct intel_crtc_state *crtc_state =
15514 to_intel_crtc_state(crtc->base.state);
15516 if (crtc_state->base.active &&
15517 crtc_state->shared_dpll == pll)
15518 pll->state.crtc_mask |= 1 << crtc->pipe;
15520 pll->active_mask = pll->state.crtc_mask;
15522 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15523 pll->info->name, pll->state.crtc_mask, pll->on);
15526 for_each_intel_encoder(dev, encoder) {
15529 if (encoder->get_hw_state(encoder, &pipe)) {
15530 struct intel_crtc_state *crtc_state;
15532 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15533 crtc_state = to_intel_crtc_state(crtc->base.state);
15535 encoder->base.crtc = &crtc->base;
15536 encoder->get_config(encoder, crtc_state);
15538 encoder->base.crtc = NULL;
15541 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15542 encoder->base.base.id, encoder->base.name,
15543 enableddisabled(encoder->base.crtc),
15547 drm_connector_list_iter_begin(dev, &conn_iter);
15548 for_each_intel_connector_iter(connector, &conn_iter) {
15549 if (connector->get_hw_state(connector)) {
15550 connector->base.dpms = DRM_MODE_DPMS_ON;
15552 encoder = connector->encoder;
15553 connector->base.encoder = &encoder->base;
15555 if (encoder->base.crtc &&
15556 encoder->base.crtc->state->active) {
15558 * This has to be done during hardware readout
15559 * because anything calling .crtc_disable may
15560 * rely on the connector_mask being accurate.
15562 encoder->base.crtc->state->connector_mask |=
15563 drm_connector_mask(&connector->base);
15564 encoder->base.crtc->state->encoder_mask |=
15565 drm_encoder_mask(&encoder->base);
15569 connector->base.dpms = DRM_MODE_DPMS_OFF;
15570 connector->base.encoder = NULL;
15572 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15573 connector->base.base.id, connector->base.name,
15574 enableddisabled(connector->base.encoder));
15576 drm_connector_list_iter_end(&conn_iter);
15578 for_each_intel_crtc(dev, crtc) {
15579 struct intel_crtc_state *crtc_state =
15580 to_intel_crtc_state(crtc->base.state);
15583 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15584 if (crtc_state->base.active) {
15585 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15586 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15587 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
15588 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15589 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15592 * The initial mode needs to be set in order to keep
15593 * the atomic core happy. It wants a valid mode if the
15594 * crtc's enabled, so we do the above call.
15596 * But we don't set all the derived state fully, hence
15597 * set a flag to indicate that a full recalculation is
15598 * needed on the next commit.
15600 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
15602 intel_crtc_compute_pixel_rate(crtc_state);
15604 if (dev_priv->display.modeset_calc_cdclk) {
15605 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15606 if (WARN_ON(min_cdclk < 0))
15610 drm_calc_timestamping_constants(&crtc->base,
15611 &crtc_state->base.adjusted_mode);
15612 update_scanline_offset(crtc);
15615 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
15616 dev_priv->min_voltage_level[crtc->pipe] =
15617 crtc_state->min_voltage_level;
15619 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15624 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15626 struct intel_encoder *encoder;
15628 for_each_intel_encoder(&dev_priv->drm, encoder) {
15630 enum intel_display_power_domain domain;
15631 struct intel_crtc_state *crtc_state;
15633 if (!encoder->get_power_domains)
15637 * MST-primary and inactive encoders don't have a crtc state
15638 * and neither of these require any power domain references.
15640 if (!encoder->base.crtc)
15643 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
15644 get_domains = encoder->get_power_domains(encoder, crtc_state);
15645 for_each_power_domain(domain, get_domains)
15646 intel_display_power_get(dev_priv, domain);
15650 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15652 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15653 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15654 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15657 if (IS_HASWELL(dev_priv)) {
15659 * WaRsPkgCStateDisplayPMReq:hsw
15660 * System hang if this isn't done before disabling all planes!
15662 I915_WRITE(CHICKEN_PAR1_1,
15663 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15667 /* Scan out the current hw modeset state,
15668 * and sanitizes it to the current state
15671 intel_modeset_setup_hw_state(struct drm_device *dev,
15672 struct drm_modeset_acquire_ctx *ctx)
15674 struct drm_i915_private *dev_priv = to_i915(dev);
15675 struct intel_crtc *crtc;
15676 struct intel_encoder *encoder;
15679 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15681 intel_early_display_was(dev_priv);
15682 intel_modeset_readout_hw_state(dev);
15684 /* HW state is read out, now we need to sanitize this mess. */
15685 get_encoder_power_domains(dev_priv);
15688 * intel_sanitize_plane_mapping() may need to do vblank
15689 * waits, so we need vblank interrupts restored beforehand.
15691 for_each_intel_crtc(&dev_priv->drm, crtc) {
15692 drm_crtc_vblank_reset(&crtc->base);
15695 drm_crtc_vblank_on(&crtc->base);
15698 intel_sanitize_plane_mapping(dev_priv);
15700 for_each_intel_encoder(dev, encoder)
15701 intel_sanitize_encoder(encoder);
15703 for_each_intel_crtc(&dev_priv->drm, crtc) {
15704 intel_sanitize_crtc(crtc, ctx);
15705 intel_dump_pipe_config(crtc, crtc->config,
15706 "[setup_hw_state]");
15709 intel_modeset_update_connector_atomic_state(dev);
15711 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15712 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15714 if (!pll->on || pll->active_mask)
15717 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15720 pll->info->funcs->disable(dev_priv, pll);
15724 if (IS_G4X(dev_priv)) {
15725 g4x_wm_get_hw_state(dev);
15726 g4x_wm_sanitize(dev_priv);
15727 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15728 vlv_wm_get_hw_state(dev);
15729 vlv_wm_sanitize(dev_priv);
15730 } else if (INTEL_GEN(dev_priv) >= 9) {
15731 skl_wm_get_hw_state(dev);
15732 } else if (HAS_PCH_SPLIT(dev_priv)) {
15733 ilk_wm_get_hw_state(dev);
15736 for_each_intel_crtc(dev, crtc) {
15739 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config);
15740 if (WARN_ON(put_domains))
15741 modeset_put_power_domains(dev_priv, put_domains);
15744 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
15746 intel_fbc_init_pipe_state(dev_priv);
15749 void intel_display_resume(struct drm_device *dev)
15751 struct drm_i915_private *dev_priv = to_i915(dev);
15752 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15753 struct drm_modeset_acquire_ctx ctx;
15756 dev_priv->modeset_restore_state = NULL;
15758 state->acquire_ctx = &ctx;
15760 drm_modeset_acquire_init(&ctx, 0);
15763 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15764 if (ret != -EDEADLK)
15767 drm_modeset_backoff(&ctx);
15771 ret = __intel_display_resume(dev, state, &ctx);
15773 intel_enable_ipc(dev_priv);
15774 drm_modeset_drop_locks(&ctx);
15775 drm_modeset_acquire_fini(&ctx);
15778 DRM_ERROR("Restoring old state failed with %i\n", ret);
15780 drm_atomic_state_put(state);
15783 static void intel_hpd_poll_fini(struct drm_device *dev)
15785 struct intel_connector *connector;
15786 struct drm_connector_list_iter conn_iter;
15788 /* Kill all the work that may have been queued by hpd. */
15789 drm_connector_list_iter_begin(dev, &conn_iter);
15790 for_each_intel_connector_iter(connector, &conn_iter) {
15791 if (connector->modeset_retry_work.func)
15792 cancel_work_sync(&connector->modeset_retry_work);
15793 if (connector->hdcp_shim) {
15794 cancel_delayed_work_sync(&connector->hdcp_check_work);
15795 cancel_work_sync(&connector->hdcp_prop_work);
15798 drm_connector_list_iter_end(&conn_iter);
15801 void intel_modeset_cleanup(struct drm_device *dev)
15803 struct drm_i915_private *dev_priv = to_i915(dev);
15805 flush_workqueue(dev_priv->modeset_wq);
15807 flush_work(&dev_priv->atomic_helper.free_work);
15808 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15811 * Interrupts and polling as the first thing to avoid creating havoc.
15812 * Too much stuff here (turning of connectors, ...) would
15813 * experience fancy races otherwise.
15815 intel_irq_uninstall(dev_priv);
15818 * Due to the hpd irq storm handling the hotplug work can re-arm the
15819 * poll handlers. Hence disable polling after hpd handling is shut down.
15821 intel_hpd_poll_fini(dev);
15823 /* poll work can call into fbdev, hence clean that up afterwards */
15824 intel_fbdev_fini(dev_priv);
15826 intel_unregister_dsm_handler();
15828 intel_fbc_global_disable(dev_priv);
15830 /* flush any delayed tasks or pending work */
15831 flush_scheduled_work();
15833 drm_mode_config_cleanup(dev);
15835 intel_cleanup_overlay(dev_priv);
15837 intel_teardown_gmbus(dev_priv);
15839 destroy_workqueue(dev_priv->modeset_wq);
15843 * set vga decode state - true == enable VGA decode
15845 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
15847 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
15850 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15851 DRM_ERROR("failed to read control word\n");
15855 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15859 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15861 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
15863 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15864 DRM_ERROR("failed to write control word\n");
15871 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15873 struct intel_display_error_state {
15875 u32 power_well_driver;
15877 int num_transcoders;
15879 struct intel_cursor_error_state {
15884 } cursor[I915_MAX_PIPES];
15886 struct intel_pipe_error_state {
15887 bool power_domain_on;
15890 } pipe[I915_MAX_PIPES];
15892 struct intel_plane_error_state {
15900 } plane[I915_MAX_PIPES];
15902 struct intel_transcoder_error_state {
15903 bool power_domain_on;
15904 enum transcoder cpu_transcoder;
15917 struct intel_display_error_state *
15918 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
15920 struct intel_display_error_state *error;
15921 int transcoders[] = {
15929 if (INTEL_INFO(dev_priv)->num_pipes == 0)
15932 error = kzalloc(sizeof(*error), GFP_ATOMIC);
15936 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15937 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
15939 for_each_pipe(dev_priv, i) {
15940 error->pipe[i].power_domain_on =
15941 __intel_display_power_is_enabled(dev_priv,
15942 POWER_DOMAIN_PIPE(i));
15943 if (!error->pipe[i].power_domain_on)
15946 error->cursor[i].control = I915_READ(CURCNTR(i));
15947 error->cursor[i].position = I915_READ(CURPOS(i));
15948 error->cursor[i].base = I915_READ(CURBASE(i));
15950 error->plane[i].control = I915_READ(DSPCNTR(i));
15951 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
15952 if (INTEL_GEN(dev_priv) <= 3) {
15953 error->plane[i].size = I915_READ(DSPSIZE(i));
15954 error->plane[i].pos = I915_READ(DSPPOS(i));
15956 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15957 error->plane[i].addr = I915_READ(DSPADDR(i));
15958 if (INTEL_GEN(dev_priv) >= 4) {
15959 error->plane[i].surface = I915_READ(DSPSURF(i));
15960 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
15963 error->pipe[i].source = I915_READ(PIPESRC(i));
15965 if (HAS_GMCH_DISPLAY(dev_priv))
15966 error->pipe[i].stat = I915_READ(PIPESTAT(i));
15969 /* Note: this does not include DSI transcoders. */
15970 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
15971 if (HAS_DDI(dev_priv))
15972 error->num_transcoders++; /* Account for eDP. */
15974 for (i = 0; i < error->num_transcoders; i++) {
15975 enum transcoder cpu_transcoder = transcoders[i];
15977 error->transcoder[i].power_domain_on =
15978 __intel_display_power_is_enabled(dev_priv,
15979 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
15980 if (!error->transcoder[i].power_domain_on)
15983 error->transcoder[i].cpu_transcoder = cpu_transcoder;
15985 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
15986 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
15987 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
15988 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
15989 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
15990 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
15991 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
15997 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16000 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
16001 struct intel_display_error_state *error)
16003 struct drm_i915_private *dev_priv = m->i915;
16009 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
16010 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16011 err_printf(m, "PWR_WELL_CTL2: %08x\n",
16012 error->power_well_driver);
16013 for_each_pipe(dev_priv, i) {
16014 err_printf(m, "Pipe [%d]:\n", i);
16015 err_printf(m, " Power: %s\n",
16016 onoff(error->pipe[i].power_domain_on));
16017 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
16018 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
16020 err_printf(m, "Plane [%d]:\n", i);
16021 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16022 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
16023 if (INTEL_GEN(dev_priv) <= 3) {
16024 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16025 err_printf(m, " POS: %08x\n", error->plane[i].pos);
16027 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16028 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
16029 if (INTEL_GEN(dev_priv) >= 4) {
16030 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16031 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
16034 err_printf(m, "Cursor [%d]:\n", i);
16035 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16036 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16037 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
16040 for (i = 0; i < error->num_transcoders; i++) {
16041 err_printf(m, "CPU transcoder: %s\n",
16042 transcoder_name(error->transcoder[i].cpu_transcoder));
16043 err_printf(m, " Power: %s\n",
16044 onoff(error->transcoder[i].power_domain_on));
16045 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16046 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16047 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16048 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16049 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16050 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16051 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);