2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include "intel_frontbuffer.h"
38 #include <drm/i915_drm.h>
40 #include "i915_gem_clflush.h"
41 #include "intel_dsi.h"
42 #include "i915_trace.h"
43 #include <drm/drm_atomic.h>
44 #include <drm/drm_atomic_helper.h>
45 #include <drm/drm_dp_helper.h>
46 #include <drm/drm_crtc_helper.h>
47 #include <drm/drm_plane_helper.h>
48 #include <drm/drm_rect.h>
49 #include <linux/dma_remapping.h>
50 #include <linux/reservation.h>
52 /* Primary plane formats for gen <= 3 */
53 static const uint32_t i8xx_primary_formats[] = {
60 /* Primary plane formats for gen >= 4 */
61 static const uint32_t i965_primary_formats[] = {
66 DRM_FORMAT_XRGB2101010,
67 DRM_FORMAT_XBGR2101010,
70 static const uint64_t i9xx_format_modifiers[] = {
71 I915_FORMAT_MOD_X_TILED,
72 DRM_FORMAT_MOD_LINEAR,
73 DRM_FORMAT_MOD_INVALID
76 static const uint32_t skl_primary_formats[] = {
83 DRM_FORMAT_XRGB2101010,
84 DRM_FORMAT_XBGR2101010,
91 static const uint64_t skl_format_modifiers_noccs[] = {
92 I915_FORMAT_MOD_Yf_TILED,
93 I915_FORMAT_MOD_Y_TILED,
94 I915_FORMAT_MOD_X_TILED,
95 DRM_FORMAT_MOD_LINEAR,
96 DRM_FORMAT_MOD_INVALID
99 static const uint64_t skl_format_modifiers_ccs[] = {
100 I915_FORMAT_MOD_Yf_TILED_CCS,
101 I915_FORMAT_MOD_Y_TILED_CCS,
102 I915_FORMAT_MOD_Yf_TILED,
103 I915_FORMAT_MOD_Y_TILED,
104 I915_FORMAT_MOD_X_TILED,
105 DRM_FORMAT_MOD_LINEAR,
106 DRM_FORMAT_MOD_INVALID
110 static const uint32_t intel_cursor_formats[] = {
114 static const uint64_t cursor_format_modifiers[] = {
115 DRM_FORMAT_MOD_LINEAR,
116 DRM_FORMAT_MOD_INVALID
119 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
120 struct intel_crtc_state *pipe_config);
121 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
122 struct intel_crtc_state *pipe_config);
124 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
125 struct drm_i915_gem_object *obj,
126 struct drm_mode_fb_cmd2 *mode_cmd);
127 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
128 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
129 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc);
130 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
131 struct intel_link_m_n *m_n,
132 struct intel_link_m_n *m2_n2);
133 static void ironlake_set_pipeconf(struct drm_crtc *crtc);
134 static void haswell_set_pipeconf(struct drm_crtc *crtc);
135 static void haswell_set_pipemisc(struct drm_crtc *crtc);
136 static void vlv_prepare_pll(struct intel_crtc *crtc,
137 const struct intel_crtc_state *pipe_config);
138 static void chv_prepare_pll(struct intel_crtc *crtc,
139 const struct intel_crtc_state *pipe_config);
140 static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
141 static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
142 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
143 struct intel_crtc_state *crtc_state);
144 static void skylake_pfit_enable(struct intel_crtc *crtc);
145 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force);
146 static void ironlake_pfit_enable(struct intel_crtc *crtc);
147 static void intel_modeset_setup_hw_state(struct drm_device *dev,
148 struct drm_modeset_acquire_ctx *ctx);
149 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
154 } dot, vco, n, m, m1, m2, p, p1;
158 int p2_slow, p2_fast;
162 /* returns HPLL frequency in kHz */
163 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
165 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
167 /* Obtain SKU information */
168 mutex_lock(&dev_priv->sb_lock);
169 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
170 CCK_FUSE_HPLL_FREQ_MASK;
171 mutex_unlock(&dev_priv->sb_lock);
173 return vco_freq[hpll_freq] * 1000;
176 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
177 const char *name, u32 reg, int ref_freq)
182 mutex_lock(&dev_priv->sb_lock);
183 val = vlv_cck_read(dev_priv, reg);
184 mutex_unlock(&dev_priv->sb_lock);
186 divider = val & CCK_FREQUENCY_VALUES;
188 WARN((val & CCK_FREQUENCY_STATUS) !=
189 (divider << CCK_FREQUENCY_STATUS_SHIFT),
190 "%s change in progress\n", name);
192 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
195 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
196 const char *name, u32 reg)
198 if (dev_priv->hpll_freq == 0)
199 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
201 return vlv_get_cck_clock(dev_priv, name, reg,
202 dev_priv->hpll_freq);
205 static void intel_update_czclk(struct drm_i915_private *dev_priv)
207 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
210 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
211 CCK_CZ_CLOCK_CONTROL);
213 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
216 static inline u32 /* units of 100MHz */
217 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
218 const struct intel_crtc_state *pipe_config)
220 if (HAS_DDI(dev_priv))
221 return pipe_config->port_clock; /* SPLL */
223 return dev_priv->fdi_pll_freq;
226 static const struct intel_limit intel_limits_i8xx_dac = {
227 .dot = { .min = 25000, .max = 350000 },
228 .vco = { .min = 908000, .max = 1512000 },
229 .n = { .min = 2, .max = 16 },
230 .m = { .min = 96, .max = 140 },
231 .m1 = { .min = 18, .max = 26 },
232 .m2 = { .min = 6, .max = 16 },
233 .p = { .min = 4, .max = 128 },
234 .p1 = { .min = 2, .max = 33 },
235 .p2 = { .dot_limit = 165000,
236 .p2_slow = 4, .p2_fast = 2 },
239 static const struct intel_limit intel_limits_i8xx_dvo = {
240 .dot = { .min = 25000, .max = 350000 },
241 .vco = { .min = 908000, .max = 1512000 },
242 .n = { .min = 2, .max = 16 },
243 .m = { .min = 96, .max = 140 },
244 .m1 = { .min = 18, .max = 26 },
245 .m2 = { .min = 6, .max = 16 },
246 .p = { .min = 4, .max = 128 },
247 .p1 = { .min = 2, .max = 33 },
248 .p2 = { .dot_limit = 165000,
249 .p2_slow = 4, .p2_fast = 4 },
252 static const struct intel_limit intel_limits_i8xx_lvds = {
253 .dot = { .min = 25000, .max = 350000 },
254 .vco = { .min = 908000, .max = 1512000 },
255 .n = { .min = 2, .max = 16 },
256 .m = { .min = 96, .max = 140 },
257 .m1 = { .min = 18, .max = 26 },
258 .m2 = { .min = 6, .max = 16 },
259 .p = { .min = 4, .max = 128 },
260 .p1 = { .min = 1, .max = 6 },
261 .p2 = { .dot_limit = 165000,
262 .p2_slow = 14, .p2_fast = 7 },
265 static const struct intel_limit intel_limits_i9xx_sdvo = {
266 .dot = { .min = 20000, .max = 400000 },
267 .vco = { .min = 1400000, .max = 2800000 },
268 .n = { .min = 1, .max = 6 },
269 .m = { .min = 70, .max = 120 },
270 .m1 = { .min = 8, .max = 18 },
271 .m2 = { .min = 3, .max = 7 },
272 .p = { .min = 5, .max = 80 },
273 .p1 = { .min = 1, .max = 8 },
274 .p2 = { .dot_limit = 200000,
275 .p2_slow = 10, .p2_fast = 5 },
278 static const struct intel_limit intel_limits_i9xx_lvds = {
279 .dot = { .min = 20000, .max = 400000 },
280 .vco = { .min = 1400000, .max = 2800000 },
281 .n = { .min = 1, .max = 6 },
282 .m = { .min = 70, .max = 120 },
283 .m1 = { .min = 8, .max = 18 },
284 .m2 = { .min = 3, .max = 7 },
285 .p = { .min = 7, .max = 98 },
286 .p1 = { .min = 1, .max = 8 },
287 .p2 = { .dot_limit = 112000,
288 .p2_slow = 14, .p2_fast = 7 },
292 static const struct intel_limit intel_limits_g4x_sdvo = {
293 .dot = { .min = 25000, .max = 270000 },
294 .vco = { .min = 1750000, .max = 3500000},
295 .n = { .min = 1, .max = 4 },
296 .m = { .min = 104, .max = 138 },
297 .m1 = { .min = 17, .max = 23 },
298 .m2 = { .min = 5, .max = 11 },
299 .p = { .min = 10, .max = 30 },
300 .p1 = { .min = 1, .max = 3},
301 .p2 = { .dot_limit = 270000,
307 static const struct intel_limit intel_limits_g4x_hdmi = {
308 .dot = { .min = 22000, .max = 400000 },
309 .vco = { .min = 1750000, .max = 3500000},
310 .n = { .min = 1, .max = 4 },
311 .m = { .min = 104, .max = 138 },
312 .m1 = { .min = 16, .max = 23 },
313 .m2 = { .min = 5, .max = 11 },
314 .p = { .min = 5, .max = 80 },
315 .p1 = { .min = 1, .max = 8},
316 .p2 = { .dot_limit = 165000,
317 .p2_slow = 10, .p2_fast = 5 },
320 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
321 .dot = { .min = 20000, .max = 115000 },
322 .vco = { .min = 1750000, .max = 3500000 },
323 .n = { .min = 1, .max = 3 },
324 .m = { .min = 104, .max = 138 },
325 .m1 = { .min = 17, .max = 23 },
326 .m2 = { .min = 5, .max = 11 },
327 .p = { .min = 28, .max = 112 },
328 .p1 = { .min = 2, .max = 8 },
329 .p2 = { .dot_limit = 0,
330 .p2_slow = 14, .p2_fast = 14
334 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
335 .dot = { .min = 80000, .max = 224000 },
336 .vco = { .min = 1750000, .max = 3500000 },
337 .n = { .min = 1, .max = 3 },
338 .m = { .min = 104, .max = 138 },
339 .m1 = { .min = 17, .max = 23 },
340 .m2 = { .min = 5, .max = 11 },
341 .p = { .min = 14, .max = 42 },
342 .p1 = { .min = 2, .max = 6 },
343 .p2 = { .dot_limit = 0,
344 .p2_slow = 7, .p2_fast = 7
348 static const struct intel_limit intel_limits_pineview_sdvo = {
349 .dot = { .min = 20000, .max = 400000},
350 .vco = { .min = 1700000, .max = 3500000 },
351 /* Pineview's Ncounter is a ring counter */
352 .n = { .min = 3, .max = 6 },
353 .m = { .min = 2, .max = 256 },
354 /* Pineview only has one combined m divider, which we treat as m2. */
355 .m1 = { .min = 0, .max = 0 },
356 .m2 = { .min = 0, .max = 254 },
357 .p = { .min = 5, .max = 80 },
358 .p1 = { .min = 1, .max = 8 },
359 .p2 = { .dot_limit = 200000,
360 .p2_slow = 10, .p2_fast = 5 },
363 static const struct intel_limit intel_limits_pineview_lvds = {
364 .dot = { .min = 20000, .max = 400000 },
365 .vco = { .min = 1700000, .max = 3500000 },
366 .n = { .min = 3, .max = 6 },
367 .m = { .min = 2, .max = 256 },
368 .m1 = { .min = 0, .max = 0 },
369 .m2 = { .min = 0, .max = 254 },
370 .p = { .min = 7, .max = 112 },
371 .p1 = { .min = 1, .max = 8 },
372 .p2 = { .dot_limit = 112000,
373 .p2_slow = 14, .p2_fast = 14 },
376 /* Ironlake / Sandybridge
378 * We calculate clock using (register_value + 2) for N/M1/M2, so here
379 * the range value for them is (actual_value - 2).
381 static const struct intel_limit intel_limits_ironlake_dac = {
382 .dot = { .min = 25000, .max = 350000 },
383 .vco = { .min = 1760000, .max = 3510000 },
384 .n = { .min = 1, .max = 5 },
385 .m = { .min = 79, .max = 127 },
386 .m1 = { .min = 12, .max = 22 },
387 .m2 = { .min = 5, .max = 9 },
388 .p = { .min = 5, .max = 80 },
389 .p1 = { .min = 1, .max = 8 },
390 .p2 = { .dot_limit = 225000,
391 .p2_slow = 10, .p2_fast = 5 },
394 static const struct intel_limit intel_limits_ironlake_single_lvds = {
395 .dot = { .min = 25000, .max = 350000 },
396 .vco = { .min = 1760000, .max = 3510000 },
397 .n = { .min = 1, .max = 3 },
398 .m = { .min = 79, .max = 118 },
399 .m1 = { .min = 12, .max = 22 },
400 .m2 = { .min = 5, .max = 9 },
401 .p = { .min = 28, .max = 112 },
402 .p1 = { .min = 2, .max = 8 },
403 .p2 = { .dot_limit = 225000,
404 .p2_slow = 14, .p2_fast = 14 },
407 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
408 .dot = { .min = 25000, .max = 350000 },
409 .vco = { .min = 1760000, .max = 3510000 },
410 .n = { .min = 1, .max = 3 },
411 .m = { .min = 79, .max = 127 },
412 .m1 = { .min = 12, .max = 22 },
413 .m2 = { .min = 5, .max = 9 },
414 .p = { .min = 14, .max = 56 },
415 .p1 = { .min = 2, .max = 8 },
416 .p2 = { .dot_limit = 225000,
417 .p2_slow = 7, .p2_fast = 7 },
420 /* LVDS 100mhz refclk limits. */
421 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
422 .dot = { .min = 25000, .max = 350000 },
423 .vco = { .min = 1760000, .max = 3510000 },
424 .n = { .min = 1, .max = 2 },
425 .m = { .min = 79, .max = 126 },
426 .m1 = { .min = 12, .max = 22 },
427 .m2 = { .min = 5, .max = 9 },
428 .p = { .min = 28, .max = 112 },
429 .p1 = { .min = 2, .max = 8 },
430 .p2 = { .dot_limit = 225000,
431 .p2_slow = 14, .p2_fast = 14 },
434 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
435 .dot = { .min = 25000, .max = 350000 },
436 .vco = { .min = 1760000, .max = 3510000 },
437 .n = { .min = 1, .max = 3 },
438 .m = { .min = 79, .max = 126 },
439 .m1 = { .min = 12, .max = 22 },
440 .m2 = { .min = 5, .max = 9 },
441 .p = { .min = 14, .max = 42 },
442 .p1 = { .min = 2, .max = 6 },
443 .p2 = { .dot_limit = 225000,
444 .p2_slow = 7, .p2_fast = 7 },
447 static const struct intel_limit intel_limits_vlv = {
449 * These are the data rate limits (measured in fast clocks)
450 * since those are the strictest limits we have. The fast
451 * clock and actual rate limits are more relaxed, so checking
452 * them would make no difference.
454 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
455 .vco = { .min = 4000000, .max = 6000000 },
456 .n = { .min = 1, .max = 7 },
457 .m1 = { .min = 2, .max = 3 },
458 .m2 = { .min = 11, .max = 156 },
459 .p1 = { .min = 2, .max = 3 },
460 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
463 static const struct intel_limit intel_limits_chv = {
465 * These are the data rate limits (measured in fast clocks)
466 * since those are the strictest limits we have. The fast
467 * clock and actual rate limits are more relaxed, so checking
468 * them would make no difference.
470 .dot = { .min = 25000 * 5, .max = 540000 * 5},
471 .vco = { .min = 4800000, .max = 6480000 },
472 .n = { .min = 1, .max = 1 },
473 .m1 = { .min = 2, .max = 2 },
474 .m2 = { .min = 24 << 22, .max = 175 << 22 },
475 .p1 = { .min = 2, .max = 4 },
476 .p2 = { .p2_slow = 1, .p2_fast = 14 },
479 static const struct intel_limit intel_limits_bxt = {
480 /* FIXME: find real dot limits */
481 .dot = { .min = 0, .max = INT_MAX },
482 .vco = { .min = 4800000, .max = 6700000 },
483 .n = { .min = 1, .max = 1 },
484 .m1 = { .min = 2, .max = 2 },
485 /* FIXME: find real m2 limits */
486 .m2 = { .min = 2 << 22, .max = 255 << 22 },
487 .p1 = { .min = 2, .max = 4 },
488 .p2 = { .p2_slow = 1, .p2_fast = 20 },
492 needs_modeset(const struct drm_crtc_state *state)
494 return drm_atomic_crtc_needs_modeset(state);
498 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
499 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
500 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
501 * The helpers' return value is the rate of the clock that is fed to the
502 * display engine's pipe which can be the above fast dot clock rate or a
503 * divided-down version of it.
505 /* m1 is reserved as 0 in Pineview, n is a ring counter */
506 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
508 clock->m = clock->m2 + 2;
509 clock->p = clock->p1 * clock->p2;
510 if (WARN_ON(clock->n == 0 || clock->p == 0))
512 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
513 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
518 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
520 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
523 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
525 clock->m = i9xx_dpll_compute_m(clock);
526 clock->p = clock->p1 * clock->p2;
527 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
529 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
530 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
535 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
537 clock->m = clock->m1 * clock->m2;
538 clock->p = clock->p1 * clock->p2;
539 if (WARN_ON(clock->n == 0 || clock->p == 0))
541 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
542 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
544 return clock->dot / 5;
547 int chv_calc_dpll_params(int refclk, struct dpll *clock)
549 clock->m = clock->m1 * clock->m2;
550 clock->p = clock->p1 * clock->p2;
551 if (WARN_ON(clock->n == 0 || clock->p == 0))
553 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
555 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
557 return clock->dot / 5;
560 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
563 * Returns whether the given set of divisors are valid for a given refclk with
564 * the given connectors.
566 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
567 const struct intel_limit *limit,
568 const struct dpll *clock)
570 if (clock->n < limit->n.min || limit->n.max < clock->n)
571 INTELPllInvalid("n out of range\n");
572 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
573 INTELPllInvalid("p1 out of range\n");
574 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
575 INTELPllInvalid("m2 out of range\n");
576 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
577 INTELPllInvalid("m1 out of range\n");
579 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
580 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
581 if (clock->m1 <= clock->m2)
582 INTELPllInvalid("m1 <= m2\n");
584 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
585 !IS_GEN9_LP(dev_priv)) {
586 if (clock->p < limit->p.min || limit->p.max < clock->p)
587 INTELPllInvalid("p out of range\n");
588 if (clock->m < limit->m.min || limit->m.max < clock->m)
589 INTELPllInvalid("m out of range\n");
592 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
593 INTELPllInvalid("vco out of range\n");
594 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
595 * connector, etc., rather than just a single range.
597 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
598 INTELPllInvalid("dot out of range\n");
604 i9xx_select_p2_div(const struct intel_limit *limit,
605 const struct intel_crtc_state *crtc_state,
608 struct drm_device *dev = crtc_state->base.crtc->dev;
610 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
612 * For LVDS just rely on its current settings for dual-channel.
613 * We haven't figured out how to reliably set up different
614 * single/dual channel state, if we even can.
616 if (intel_is_dual_link_lvds(dev))
617 return limit->p2.p2_fast;
619 return limit->p2.p2_slow;
621 if (target < limit->p2.dot_limit)
622 return limit->p2.p2_slow;
624 return limit->p2.p2_fast;
629 * Returns a set of divisors for the desired target clock with the given
630 * refclk, or FALSE. The returned values represent the clock equation:
631 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
633 * Target and reference clocks are specified in kHz.
635 * If match_clock is provided, then best_clock P divider must match the P
636 * divider from @match_clock used for LVDS downclocking.
639 i9xx_find_best_dpll(const struct intel_limit *limit,
640 struct intel_crtc_state *crtc_state,
641 int target, int refclk, struct dpll *match_clock,
642 struct dpll *best_clock)
644 struct drm_device *dev = crtc_state->base.crtc->dev;
648 memset(best_clock, 0, sizeof(*best_clock));
650 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
652 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
654 for (clock.m2 = limit->m2.min;
655 clock.m2 <= limit->m2.max; clock.m2++) {
656 if (clock.m2 >= clock.m1)
658 for (clock.n = limit->n.min;
659 clock.n <= limit->n.max; clock.n++) {
660 for (clock.p1 = limit->p1.min;
661 clock.p1 <= limit->p1.max; clock.p1++) {
664 i9xx_calc_dpll_params(refclk, &clock);
665 if (!intel_PLL_is_valid(to_i915(dev),
670 clock.p != match_clock->p)
673 this_err = abs(clock.dot - target);
674 if (this_err < err) {
683 return (err != target);
687 * Returns a set of divisors for the desired target clock with the given
688 * refclk, or FALSE. The returned values represent the clock equation:
689 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
691 * Target and reference clocks are specified in kHz.
693 * If match_clock is provided, then best_clock P divider must match the P
694 * divider from @match_clock used for LVDS downclocking.
697 pnv_find_best_dpll(const struct intel_limit *limit,
698 struct intel_crtc_state *crtc_state,
699 int target, int refclk, struct dpll *match_clock,
700 struct dpll *best_clock)
702 struct drm_device *dev = crtc_state->base.crtc->dev;
706 memset(best_clock, 0, sizeof(*best_clock));
708 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
710 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
712 for (clock.m2 = limit->m2.min;
713 clock.m2 <= limit->m2.max; clock.m2++) {
714 for (clock.n = limit->n.min;
715 clock.n <= limit->n.max; clock.n++) {
716 for (clock.p1 = limit->p1.min;
717 clock.p1 <= limit->p1.max; clock.p1++) {
720 pnv_calc_dpll_params(refclk, &clock);
721 if (!intel_PLL_is_valid(to_i915(dev),
726 clock.p != match_clock->p)
729 this_err = abs(clock.dot - target);
730 if (this_err < err) {
739 return (err != target);
743 * Returns a set of divisors for the desired target clock with the given
744 * refclk, or FALSE. The returned values represent the clock equation:
745 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
747 * Target and reference clocks are specified in kHz.
749 * If match_clock is provided, then best_clock P divider must match the P
750 * divider from @match_clock used for LVDS downclocking.
753 g4x_find_best_dpll(const struct intel_limit *limit,
754 struct intel_crtc_state *crtc_state,
755 int target, int refclk, struct dpll *match_clock,
756 struct dpll *best_clock)
758 struct drm_device *dev = crtc_state->base.crtc->dev;
762 /* approximately equals target * 0.00585 */
763 int err_most = (target >> 8) + (target >> 9);
765 memset(best_clock, 0, sizeof(*best_clock));
767 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
769 max_n = limit->n.max;
770 /* based on hardware requirement, prefer smaller n to precision */
771 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
772 /* based on hardware requirement, prefere larger m1,m2 */
773 for (clock.m1 = limit->m1.max;
774 clock.m1 >= limit->m1.min; clock.m1--) {
775 for (clock.m2 = limit->m2.max;
776 clock.m2 >= limit->m2.min; clock.m2--) {
777 for (clock.p1 = limit->p1.max;
778 clock.p1 >= limit->p1.min; clock.p1--) {
781 i9xx_calc_dpll_params(refclk, &clock);
782 if (!intel_PLL_is_valid(to_i915(dev),
787 this_err = abs(clock.dot - target);
788 if (this_err < err_most) {
802 * Check if the calculated PLL configuration is more optimal compared to the
803 * best configuration and error found so far. Return the calculated error.
805 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
806 const struct dpll *calculated_clock,
807 const struct dpll *best_clock,
808 unsigned int best_error_ppm,
809 unsigned int *error_ppm)
812 * For CHV ignore the error and consider only the P value.
813 * Prefer a bigger P value based on HW requirements.
815 if (IS_CHERRYVIEW(to_i915(dev))) {
818 return calculated_clock->p > best_clock->p;
821 if (WARN_ON_ONCE(!target_freq))
824 *error_ppm = div_u64(1000000ULL *
825 abs(target_freq - calculated_clock->dot),
828 * Prefer a better P value over a better (smaller) error if the error
829 * is small. Ensure this preference for future configurations too by
830 * setting the error to 0.
832 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
838 return *error_ppm + 10 < best_error_ppm;
842 * Returns a set of divisors for the desired target clock with the given
843 * refclk, or FALSE. The returned values represent the clock equation:
844 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
847 vlv_find_best_dpll(const struct intel_limit *limit,
848 struct intel_crtc_state *crtc_state,
849 int target, int refclk, struct dpll *match_clock,
850 struct dpll *best_clock)
852 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
853 struct drm_device *dev = crtc->base.dev;
855 unsigned int bestppm = 1000000;
856 /* min update 19.2 MHz */
857 int max_n = min(limit->n.max, refclk / 19200);
860 target *= 5; /* fast clock */
862 memset(best_clock, 0, sizeof(*best_clock));
864 /* based on hardware requirement, prefer smaller n to precision */
865 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
866 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
867 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
868 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
869 clock.p = clock.p1 * clock.p2;
870 /* based on hardware requirement, prefer bigger m1,m2 values */
871 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
874 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
877 vlv_calc_dpll_params(refclk, &clock);
879 if (!intel_PLL_is_valid(to_i915(dev),
884 if (!vlv_PLL_is_optimal(dev, target,
902 * Returns a set of divisors for the desired target clock with the given
903 * refclk, or FALSE. The returned values represent the clock equation:
904 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
907 chv_find_best_dpll(const struct intel_limit *limit,
908 struct intel_crtc_state *crtc_state,
909 int target, int refclk, struct dpll *match_clock,
910 struct dpll *best_clock)
912 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
913 struct drm_device *dev = crtc->base.dev;
914 unsigned int best_error_ppm;
919 memset(best_clock, 0, sizeof(*best_clock));
920 best_error_ppm = 1000000;
923 * Based on hardware doc, the n always set to 1, and m1 always
924 * set to 2. If requires to support 200Mhz refclk, we need to
925 * revisit this because n may not 1 anymore.
927 clock.n = 1, clock.m1 = 2;
928 target *= 5; /* fast clock */
930 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
931 for (clock.p2 = limit->p2.p2_fast;
932 clock.p2 >= limit->p2.p2_slow;
933 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
934 unsigned int error_ppm;
936 clock.p = clock.p1 * clock.p2;
938 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
939 clock.n) << 22, refclk * clock.m1);
941 if (m2 > INT_MAX/clock.m1)
946 chv_calc_dpll_params(refclk, &clock);
948 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
951 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
952 best_error_ppm, &error_ppm))
956 best_error_ppm = error_ppm;
964 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
965 struct dpll *best_clock)
968 const struct intel_limit *limit = &intel_limits_bxt;
970 return chv_find_best_dpll(limit, crtc_state,
971 target_clock, refclk, NULL, best_clock);
974 bool intel_crtc_active(struct intel_crtc *crtc)
976 /* Be paranoid as we can arrive here with only partial
977 * state retrieved from the hardware during setup.
979 * We can ditch the adjusted_mode.crtc_clock check as soon
980 * as Haswell has gained clock readout/fastboot support.
982 * We can ditch the crtc->primary->fb check as soon as we can
983 * properly reconstruct framebuffers.
985 * FIXME: The intel_crtc->active here should be switched to
986 * crtc->state->active once we have proper CRTC states wired up
989 return crtc->active && crtc->base.primary->state->fb &&
990 crtc->config->base.adjusted_mode.crtc_clock;
993 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
996 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
998 return crtc->config->cpu_transcoder;
1001 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1004 i915_reg_t reg = PIPEDSL(pipe);
1008 if (IS_GEN2(dev_priv))
1009 line_mask = DSL_LINEMASK_GEN2;
1011 line_mask = DSL_LINEMASK_GEN3;
1013 line1 = I915_READ(reg) & line_mask;
1015 line2 = I915_READ(reg) & line_mask;
1017 return line1 != line2;
1020 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1022 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1023 enum pipe pipe = crtc->pipe;
1025 /* Wait for the display line to settle/start moving */
1026 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1027 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1028 pipe_name(pipe), onoff(state));
1031 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1033 wait_for_pipe_scanline_moving(crtc, false);
1036 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1038 wait_for_pipe_scanline_moving(crtc, true);
1042 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1044 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1045 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1047 if (INTEL_GEN(dev_priv) >= 4) {
1048 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1049 i915_reg_t reg = PIPECONF(cpu_transcoder);
1051 /* Wait for the Pipe State to go off */
1052 if (intel_wait_for_register(dev_priv,
1053 reg, I965_PIPECONF_ACTIVE, 0,
1055 WARN(1, "pipe_off wait timed out\n");
1057 intel_wait_for_pipe_scanline_stopped(crtc);
1061 /* Only for pre-ILK configs */
1062 void assert_pll(struct drm_i915_private *dev_priv,
1063 enum pipe pipe, bool state)
1068 val = I915_READ(DPLL(pipe));
1069 cur_state = !!(val & DPLL_VCO_ENABLE);
1070 I915_STATE_WARN(cur_state != state,
1071 "PLL state assertion failure (expected %s, current %s)\n",
1072 onoff(state), onoff(cur_state));
1075 /* XXX: the dsi pll is shared between MIPI DSI ports */
1076 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1081 mutex_lock(&dev_priv->sb_lock);
1082 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1083 mutex_unlock(&dev_priv->sb_lock);
1085 cur_state = val & DSI_PLL_VCO_EN;
1086 I915_STATE_WARN(cur_state != state,
1087 "DSI PLL state assertion failure (expected %s, current %s)\n",
1088 onoff(state), onoff(cur_state));
1091 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1092 enum pipe pipe, bool state)
1095 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1098 if (HAS_DDI(dev_priv)) {
1099 /* DDI does not have a specific FDI_TX register */
1100 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1101 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1103 u32 val = I915_READ(FDI_TX_CTL(pipe));
1104 cur_state = !!(val & FDI_TX_ENABLE);
1106 I915_STATE_WARN(cur_state != state,
1107 "FDI TX state assertion failure (expected %s, current %s)\n",
1108 onoff(state), onoff(cur_state));
1110 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1111 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1113 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1114 enum pipe pipe, bool state)
1119 val = I915_READ(FDI_RX_CTL(pipe));
1120 cur_state = !!(val & FDI_RX_ENABLE);
1121 I915_STATE_WARN(cur_state != state,
1122 "FDI RX state assertion failure (expected %s, current %s)\n",
1123 onoff(state), onoff(cur_state));
1125 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1126 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1128 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1133 /* ILK FDI PLL is always enabled */
1134 if (IS_GEN5(dev_priv))
1137 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1138 if (HAS_DDI(dev_priv))
1141 val = I915_READ(FDI_TX_CTL(pipe));
1142 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1145 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1146 enum pipe pipe, bool state)
1151 val = I915_READ(FDI_RX_CTL(pipe));
1152 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1153 I915_STATE_WARN(cur_state != state,
1154 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1155 onoff(state), onoff(cur_state));
1158 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1162 enum pipe panel_pipe = PIPE_A;
1165 if (WARN_ON(HAS_DDI(dev_priv)))
1168 if (HAS_PCH_SPLIT(dev_priv)) {
1171 pp_reg = PP_CONTROL(0);
1172 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1174 if (port_sel == PANEL_PORT_SELECT_LVDS &&
1175 I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
1176 panel_pipe = PIPE_B;
1177 /* XXX: else fix for eDP */
1178 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1179 /* presumably write lock depends on pipe, not port select */
1180 pp_reg = PP_CONTROL(pipe);
1183 pp_reg = PP_CONTROL(0);
1184 if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
1185 panel_pipe = PIPE_B;
1188 val = I915_READ(pp_reg);
1189 if (!(val & PANEL_POWER_ON) ||
1190 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1193 I915_STATE_WARN(panel_pipe == pipe && locked,
1194 "panel assertion failure, pipe %c regs locked\n",
1198 void assert_pipe(struct drm_i915_private *dev_priv,
1199 enum pipe pipe, bool state)
1202 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1204 enum intel_display_power_domain power_domain;
1206 /* we keep both pipes enabled on 830 */
1207 if (IS_I830(dev_priv))
1210 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1211 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
1212 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1213 cur_state = !!(val & PIPECONF_ENABLE);
1215 intel_display_power_put(dev_priv, power_domain);
1220 I915_STATE_WARN(cur_state != state,
1221 "pipe %c assertion failure (expected %s, current %s)\n",
1222 pipe_name(pipe), onoff(state), onoff(cur_state));
1225 static void assert_plane(struct intel_plane *plane, bool state)
1227 bool cur_state = plane->get_hw_state(plane);
1229 I915_STATE_WARN(cur_state != state,
1230 "%s assertion failure (expected %s, current %s)\n",
1231 plane->base.name, onoff(state), onoff(cur_state));
1234 #define assert_plane_enabled(p) assert_plane(p, true)
1235 #define assert_plane_disabled(p) assert_plane(p, false)
1237 static void assert_planes_disabled(struct intel_crtc *crtc)
1239 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1240 struct intel_plane *plane;
1242 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1243 assert_plane_disabled(plane);
1246 static void assert_vblank_disabled(struct drm_crtc *crtc)
1248 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1249 drm_crtc_vblank_put(crtc);
1252 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1258 val = I915_READ(PCH_TRANSCONF(pipe));
1259 enabled = !!(val & TRANS_ENABLE);
1260 I915_STATE_WARN(enabled,
1261 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1265 static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
1266 enum pipe pipe, u32 port_sel, u32 val)
1268 if ((val & DP_PORT_EN) == 0)
1271 if (HAS_PCH_CPT(dev_priv)) {
1272 u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe));
1273 if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
1275 } else if (IS_CHERRYVIEW(dev_priv)) {
1276 if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
1279 if ((val & DP_PIPE_MASK) != (pipe << 30))
1285 static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1286 enum pipe pipe, u32 val)
1288 if ((val & SDVO_ENABLE) == 0)
1291 if (HAS_PCH_CPT(dev_priv)) {
1292 if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
1294 } else if (IS_CHERRYVIEW(dev_priv)) {
1295 if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
1298 if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
1304 static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
1305 enum pipe pipe, u32 val)
1307 if ((val & LVDS_PORT_EN) == 0)
1310 if (HAS_PCH_CPT(dev_priv)) {
1311 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1314 if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
1320 static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
1321 enum pipe pipe, u32 val)
1323 if ((val & ADPA_DAC_ENABLE) == 0)
1325 if (HAS_PCH_CPT(dev_priv)) {
1326 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1329 if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
1335 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1336 enum pipe pipe, i915_reg_t reg,
1339 u32 val = I915_READ(reg);
1340 I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
1341 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1342 i915_mmio_reg_offset(reg), pipe_name(pipe));
1344 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0
1345 && (val & DP_PIPEB_SELECT),
1346 "IBX PCH dp port still using transcoder B\n");
1349 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1350 enum pipe pipe, i915_reg_t reg)
1352 u32 val = I915_READ(reg);
1353 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1354 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1355 i915_mmio_reg_offset(reg), pipe_name(pipe));
1357 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0
1358 && (val & SDVO_PIPE_B_SELECT),
1359 "IBX PCH hdmi port still using transcoder B\n");
1362 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1367 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
1368 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
1369 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
1371 val = I915_READ(PCH_ADPA);
1372 I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val),
1373 "PCH VGA enabled on transcoder %c, should be disabled\n",
1376 val = I915_READ(PCH_LVDS);
1377 I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1378 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1381 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
1382 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
1383 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
1386 static void _vlv_enable_pll(struct intel_crtc *crtc,
1387 const struct intel_crtc_state *pipe_config)
1389 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1390 enum pipe pipe = crtc->pipe;
1392 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1393 POSTING_READ(DPLL(pipe));
1396 if (intel_wait_for_register(dev_priv,
1401 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1404 static void vlv_enable_pll(struct intel_crtc *crtc,
1405 const struct intel_crtc_state *pipe_config)
1407 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1408 enum pipe pipe = crtc->pipe;
1410 assert_pipe_disabled(dev_priv, pipe);
1412 /* PLL is protected by panel, make sure we can write it */
1413 assert_panel_unlocked(dev_priv, pipe);
1415 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1416 _vlv_enable_pll(crtc, pipe_config);
1418 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1419 POSTING_READ(DPLL_MD(pipe));
1423 static void _chv_enable_pll(struct intel_crtc *crtc,
1424 const struct intel_crtc_state *pipe_config)
1426 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1427 enum pipe pipe = crtc->pipe;
1428 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1431 mutex_lock(&dev_priv->sb_lock);
1433 /* Enable back the 10bit clock to display controller */
1434 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1435 tmp |= DPIO_DCLKP_EN;
1436 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1438 mutex_unlock(&dev_priv->sb_lock);
1441 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1446 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1448 /* Check PLL is locked */
1449 if (intel_wait_for_register(dev_priv,
1450 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1452 DRM_ERROR("PLL %d failed to lock\n", pipe);
1455 static void chv_enable_pll(struct intel_crtc *crtc,
1456 const struct intel_crtc_state *pipe_config)
1458 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1459 enum pipe pipe = crtc->pipe;
1461 assert_pipe_disabled(dev_priv, pipe);
1463 /* PLL is protected by panel, make sure we can write it */
1464 assert_panel_unlocked(dev_priv, pipe);
1466 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1467 _chv_enable_pll(crtc, pipe_config);
1469 if (pipe != PIPE_A) {
1471 * WaPixelRepeatModeFixForC0:chv
1473 * DPLLCMD is AWOL. Use chicken bits to propagate
1474 * the value from DPLLBMD to either pipe B or C.
1476 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1477 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1478 I915_WRITE(CBR4_VLV, 0);
1479 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1482 * DPLLB VGA mode also seems to cause problems.
1483 * We should always have it disabled.
1485 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1487 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1488 POSTING_READ(DPLL_MD(pipe));
1492 static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
1494 struct intel_crtc *crtc;
1497 for_each_intel_crtc(&dev_priv->drm, crtc) {
1498 count += crtc->base.state->active &&
1499 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1505 static void i9xx_enable_pll(struct intel_crtc *crtc,
1506 const struct intel_crtc_state *crtc_state)
1508 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1509 i915_reg_t reg = DPLL(crtc->pipe);
1510 u32 dpll = crtc_state->dpll_hw_state.dpll;
1513 assert_pipe_disabled(dev_priv, crtc->pipe);
1515 /* PLL is protected by panel, make sure we can write it */
1516 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
1517 assert_panel_unlocked(dev_priv, crtc->pipe);
1519 /* Enable DVO 2x clock on both PLLs if necessary */
1520 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
1522 * It appears to be important that we don't enable this
1523 * for the current pipe before otherwise configuring the
1524 * PLL. No idea how this should be handled if multiple
1525 * DVO outputs are enabled simultaneosly.
1527 dpll |= DPLL_DVO_2X_MODE;
1528 I915_WRITE(DPLL(!crtc->pipe),
1529 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1533 * Apparently we need to have VGA mode enabled prior to changing
1534 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1535 * dividers, even though the register value does change.
1539 I915_WRITE(reg, dpll);
1541 /* Wait for the clocks to stabilize. */
1545 if (INTEL_GEN(dev_priv) >= 4) {
1546 I915_WRITE(DPLL_MD(crtc->pipe),
1547 crtc_state->dpll_hw_state.dpll_md);
1549 /* The pixel multiplier can only be updated once the
1550 * DPLL is enabled and the clocks are stable.
1552 * So write it again.
1554 I915_WRITE(reg, dpll);
1557 /* We do this three times for luck */
1558 for (i = 0; i < 3; i++) {
1559 I915_WRITE(reg, dpll);
1561 udelay(150); /* wait for warmup */
1565 static void i9xx_disable_pll(struct intel_crtc *crtc)
1567 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1568 enum pipe pipe = crtc->pipe;
1570 /* Disable DVO 2x clock on both PLLs if necessary */
1571 if (IS_I830(dev_priv) &&
1572 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) &&
1573 !intel_num_dvo_pipes(dev_priv)) {
1574 I915_WRITE(DPLL(PIPE_B),
1575 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1576 I915_WRITE(DPLL(PIPE_A),
1577 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1580 /* Don't disable pipe or pipe PLLs if needed */
1581 if (IS_I830(dev_priv))
1584 /* Make sure the pipe isn't still relying on us */
1585 assert_pipe_disabled(dev_priv, pipe);
1587 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1588 POSTING_READ(DPLL(pipe));
1591 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1595 /* Make sure the pipe isn't still relying on us */
1596 assert_pipe_disabled(dev_priv, pipe);
1598 val = DPLL_INTEGRATED_REF_CLK_VLV |
1599 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1601 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1603 I915_WRITE(DPLL(pipe), val);
1604 POSTING_READ(DPLL(pipe));
1607 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1609 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1612 /* Make sure the pipe isn't still relying on us */
1613 assert_pipe_disabled(dev_priv, pipe);
1615 val = DPLL_SSC_REF_CLK_CHV |
1616 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1618 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1620 I915_WRITE(DPLL(pipe), val);
1621 POSTING_READ(DPLL(pipe));
1623 mutex_lock(&dev_priv->sb_lock);
1625 /* Disable 10bit clock to display controller */
1626 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1627 val &= ~DPIO_DCLKP_EN;
1628 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1630 mutex_unlock(&dev_priv->sb_lock);
1633 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1634 struct intel_digital_port *dport,
1635 unsigned int expected_mask)
1638 i915_reg_t dpll_reg;
1640 switch (dport->base.port) {
1642 port_mask = DPLL_PORTB_READY_MASK;
1646 port_mask = DPLL_PORTC_READY_MASK;
1648 expected_mask <<= 4;
1651 port_mask = DPLL_PORTD_READY_MASK;
1652 dpll_reg = DPIO_PHY_STATUS;
1658 if (intel_wait_for_register(dev_priv,
1659 dpll_reg, port_mask, expected_mask,
1661 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1662 port_name(dport->base.port),
1663 I915_READ(dpll_reg) & port_mask, expected_mask);
1666 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1669 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
1672 uint32_t val, pipeconf_val;
1674 /* Make sure PCH DPLL is enabled */
1675 assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll);
1677 /* FDI must be feeding us bits for PCH ports */
1678 assert_fdi_tx_enabled(dev_priv, pipe);
1679 assert_fdi_rx_enabled(dev_priv, pipe);
1681 if (HAS_PCH_CPT(dev_priv)) {
1682 /* Workaround: Set the timing override bit before enabling the
1683 * pch transcoder. */
1684 reg = TRANS_CHICKEN2(pipe);
1685 val = I915_READ(reg);
1686 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1687 I915_WRITE(reg, val);
1690 reg = PCH_TRANSCONF(pipe);
1691 val = I915_READ(reg);
1692 pipeconf_val = I915_READ(PIPECONF(pipe));
1694 if (HAS_PCH_IBX(dev_priv)) {
1696 * Make the BPC in transcoder be consistent with
1697 * that in pipeconf reg. For HDMI we must use 8bpc
1698 * here for both 8bpc and 12bpc.
1700 val &= ~PIPECONF_BPC_MASK;
1701 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI))
1702 val |= PIPECONF_8BPC;
1704 val |= pipeconf_val & PIPECONF_BPC_MASK;
1707 val &= ~TRANS_INTERLACE_MASK;
1708 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1709 if (HAS_PCH_IBX(dev_priv) &&
1710 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
1711 val |= TRANS_LEGACY_INTERLACED_ILK;
1713 val |= TRANS_INTERLACED;
1715 val |= TRANS_PROGRESSIVE;
1717 I915_WRITE(reg, val | TRANS_ENABLE);
1718 if (intel_wait_for_register(dev_priv,
1719 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1721 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1724 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1725 enum transcoder cpu_transcoder)
1727 u32 val, pipeconf_val;
1729 /* FDI must be feeding us bits for PCH ports */
1730 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1731 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1733 /* Workaround: set timing override bit. */
1734 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1735 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1736 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1739 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1741 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1742 PIPECONF_INTERLACED_ILK)
1743 val |= TRANS_INTERLACED;
1745 val |= TRANS_PROGRESSIVE;
1747 I915_WRITE(LPT_TRANSCONF, val);
1748 if (intel_wait_for_register(dev_priv,
1753 DRM_ERROR("Failed to enable PCH transcoder\n");
1756 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1762 /* FDI relies on the transcoder */
1763 assert_fdi_tx_disabled(dev_priv, pipe);
1764 assert_fdi_rx_disabled(dev_priv, pipe);
1766 /* Ports must be off as well */
1767 assert_pch_ports_disabled(dev_priv, pipe);
1769 reg = PCH_TRANSCONF(pipe);
1770 val = I915_READ(reg);
1771 val &= ~TRANS_ENABLE;
1772 I915_WRITE(reg, val);
1773 /* wait for PCH transcoder off, transcoder state */
1774 if (intel_wait_for_register(dev_priv,
1775 reg, TRANS_STATE_ENABLE, 0,
1777 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1779 if (HAS_PCH_CPT(dev_priv)) {
1780 /* Workaround: Clear the timing override chicken bit again. */
1781 reg = TRANS_CHICKEN2(pipe);
1782 val = I915_READ(reg);
1783 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1784 I915_WRITE(reg, val);
1788 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1792 val = I915_READ(LPT_TRANSCONF);
1793 val &= ~TRANS_ENABLE;
1794 I915_WRITE(LPT_TRANSCONF, val);
1795 /* wait for PCH transcoder off, transcoder state */
1796 if (intel_wait_for_register(dev_priv,
1797 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1799 DRM_ERROR("Failed to disable PCH transcoder\n");
1801 /* Workaround: clear timing override bit. */
1802 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1803 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1804 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1807 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1809 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1811 if (HAS_PCH_LPT(dev_priv))
1817 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1819 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1820 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1821 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1822 enum pipe pipe = crtc->pipe;
1826 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1828 assert_planes_disabled(crtc);
1831 * A pipe without a PLL won't actually be able to drive bits from
1832 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1835 if (HAS_GMCH_DISPLAY(dev_priv)) {
1836 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1837 assert_dsi_pll_enabled(dev_priv);
1839 assert_pll_enabled(dev_priv, pipe);
1841 if (new_crtc_state->has_pch_encoder) {
1842 /* if driving the PCH, we need FDI enabled */
1843 assert_fdi_rx_pll_enabled(dev_priv,
1844 intel_crtc_pch_transcoder(crtc));
1845 assert_fdi_tx_pll_enabled(dev_priv,
1846 (enum pipe) cpu_transcoder);
1848 /* FIXME: assert CPU port conditions for SNB+ */
1851 reg = PIPECONF(cpu_transcoder);
1852 val = I915_READ(reg);
1853 if (val & PIPECONF_ENABLE) {
1854 /* we keep both pipes enabled on 830 */
1855 WARN_ON(!IS_I830(dev_priv));
1859 I915_WRITE(reg, val | PIPECONF_ENABLE);
1863 * Until the pipe starts PIPEDSL reads will return a stale value,
1864 * which causes an apparent vblank timestamp jump when PIPEDSL
1865 * resets to its proper value. That also messes up the frame count
1866 * when it's derived from the timestamps. So let's wait for the
1867 * pipe to start properly before we call drm_crtc_vblank_on()
1869 if (dev_priv->drm.max_vblank_count == 0)
1870 intel_wait_for_pipe_scanline_moving(crtc);
1873 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1875 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1876 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1877 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1878 enum pipe pipe = crtc->pipe;
1882 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1885 * Make sure planes won't keep trying to pump pixels to us,
1886 * or we might hang the display.
1888 assert_planes_disabled(crtc);
1890 reg = PIPECONF(cpu_transcoder);
1891 val = I915_READ(reg);
1892 if ((val & PIPECONF_ENABLE) == 0)
1896 * Double wide has implications for planes
1897 * so best keep it disabled when not needed.
1899 if (old_crtc_state->double_wide)
1900 val &= ~PIPECONF_DOUBLE_WIDE;
1902 /* Don't disable pipe or pipe PLLs if needed */
1903 if (!IS_I830(dev_priv))
1904 val &= ~PIPECONF_ENABLE;
1906 I915_WRITE(reg, val);
1907 if ((val & PIPECONF_ENABLE) == 0)
1908 intel_wait_for_pipe_off(old_crtc_state);
1911 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1913 return IS_GEN2(dev_priv) ? 2048 : 4096;
1917 intel_tile_width_bytes(const struct drm_framebuffer *fb, int plane)
1919 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1920 unsigned int cpp = fb->format->cpp[plane];
1922 switch (fb->modifier) {
1923 case DRM_FORMAT_MOD_LINEAR:
1925 case I915_FORMAT_MOD_X_TILED:
1926 if (IS_GEN2(dev_priv))
1930 case I915_FORMAT_MOD_Y_TILED_CCS:
1934 case I915_FORMAT_MOD_Y_TILED:
1935 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1939 case I915_FORMAT_MOD_Yf_TILED_CCS:
1943 case I915_FORMAT_MOD_Yf_TILED:
1959 MISSING_CASE(fb->modifier);
1965 intel_tile_height(const struct drm_framebuffer *fb, int plane)
1967 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
1970 return intel_tile_size(to_i915(fb->dev)) /
1971 intel_tile_width_bytes(fb, plane);
1974 /* Return the tile dimensions in pixel units */
1975 static void intel_tile_dims(const struct drm_framebuffer *fb, int plane,
1976 unsigned int *tile_width,
1977 unsigned int *tile_height)
1979 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, plane);
1980 unsigned int cpp = fb->format->cpp[plane];
1982 *tile_width = tile_width_bytes / cpp;
1983 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1987 intel_fb_align_height(const struct drm_framebuffer *fb,
1988 int plane, unsigned int height)
1990 unsigned int tile_height = intel_tile_height(fb, plane);
1992 return ALIGN(height, tile_height);
1995 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1997 unsigned int size = 0;
2000 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2001 size += rot_info->plane[i].width * rot_info->plane[i].height;
2007 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2008 const struct drm_framebuffer *fb,
2009 unsigned int rotation)
2011 view->type = I915_GGTT_VIEW_NORMAL;
2012 if (drm_rotation_90_or_270(rotation)) {
2013 view->type = I915_GGTT_VIEW_ROTATED;
2014 view->rotated = to_intel_framebuffer(fb)->rot_info;
2018 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2020 if (IS_I830(dev_priv))
2022 else if (IS_I85X(dev_priv))
2024 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2030 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2032 if (INTEL_GEN(dev_priv) >= 9)
2034 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2035 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2037 else if (INTEL_GEN(dev_priv) >= 4)
2043 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2046 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2048 /* AUX_DIST needs only 4K alignment */
2052 switch (fb->modifier) {
2053 case DRM_FORMAT_MOD_LINEAR:
2054 return intel_linear_alignment(dev_priv);
2055 case I915_FORMAT_MOD_X_TILED:
2056 if (INTEL_GEN(dev_priv) >= 9)
2059 case I915_FORMAT_MOD_Y_TILED_CCS:
2060 case I915_FORMAT_MOD_Yf_TILED_CCS:
2061 case I915_FORMAT_MOD_Y_TILED:
2062 case I915_FORMAT_MOD_Yf_TILED:
2063 return 1 * 1024 * 1024;
2065 MISSING_CASE(fb->modifier);
2070 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2072 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2073 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2075 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
2079 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2080 unsigned int rotation,
2082 unsigned long *out_flags)
2084 struct drm_device *dev = fb->dev;
2085 struct drm_i915_private *dev_priv = to_i915(dev);
2086 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2087 struct i915_ggtt_view view;
2088 struct i915_vma *vma;
2089 unsigned int pinctl;
2092 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2094 alignment = intel_surf_alignment(fb, 0);
2096 intel_fill_fb_ggtt_view(&view, fb, rotation);
2098 /* Note that the w/a also requires 64 PTE of padding following the
2099 * bo. We currently fill all unused PTE with the shadow page and so
2100 * we should always have valid PTE following the scanout preventing
2103 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2104 alignment = 256 * 1024;
2107 * Global gtt pte registers are special registers which actually forward
2108 * writes to a chunk of system memory. Which means that there is no risk
2109 * that the register values disappear as soon as we call
2110 * intel_runtime_pm_put(), so it is correct to wrap only the
2111 * pin/unpin/fence and not more.
2113 intel_runtime_pm_get(dev_priv);
2115 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2119 /* Valleyview is definitely limited to scanning out the first
2120 * 512MiB. Lets presume this behaviour was inherited from the
2121 * g4x display engine and that all earlier gen are similarly
2122 * limited. Testing suggests that it is a little more
2123 * complicated than this. For example, Cherryview appears quite
2124 * happy to scanout from anywhere within its global aperture.
2126 if (HAS_GMCH_DISPLAY(dev_priv))
2127 pinctl |= PIN_MAPPABLE;
2129 vma = i915_gem_object_pin_to_display_plane(obj,
2130 alignment, &view, pinctl);
2134 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2137 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2138 * fence, whereas 965+ only requires a fence if using
2139 * framebuffer compression. For simplicity, we always, when
2140 * possible, install a fence as the cost is not that onerous.
2142 * If we fail to fence the tiled scanout, then either the
2143 * modeset will reject the change (which is highly unlikely as
2144 * the affected systems, all but one, do not have unmappable
2145 * space) or we will not be able to enable full powersaving
2146 * techniques (also likely not to apply due to various limits
2147 * FBC and the like impose on the size of the buffer, which
2148 * presumably we violated anyway with this unmappable buffer).
2149 * Anyway, it is presumably better to stumble onwards with
2150 * something and try to run the system in a "less than optimal"
2151 * mode that matches the user configuration.
2153 ret = i915_vma_pin_fence(vma);
2154 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2155 i915_gem_object_unpin_from_display_plane(vma);
2160 if (ret == 0 && vma->fence)
2161 *out_flags |= PLANE_HAS_FENCE;
2166 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2168 intel_runtime_pm_put(dev_priv);
2172 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2174 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2176 if (flags & PLANE_HAS_FENCE)
2177 i915_vma_unpin_fence(vma);
2178 i915_gem_object_unpin_from_display_plane(vma);
2182 static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
2183 unsigned int rotation)
2185 if (drm_rotation_90_or_270(rotation))
2186 return to_intel_framebuffer(fb)->rotated[plane].pitch;
2188 return fb->pitches[plane];
2192 * Convert the x/y offsets into a linear offset.
2193 * Only valid with 0/180 degree rotation, which is fine since linear
2194 * offset is only used with linear buffers on pre-hsw and tiled buffers
2195 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2197 u32 intel_fb_xy_to_linear(int x, int y,
2198 const struct intel_plane_state *state,
2201 const struct drm_framebuffer *fb = state->base.fb;
2202 unsigned int cpp = fb->format->cpp[plane];
2203 unsigned int pitch = fb->pitches[plane];
2205 return y * pitch + x * cpp;
2209 * Add the x/y offsets derived from fb->offsets[] to the user
2210 * specified plane src x/y offsets. The resulting x/y offsets
2211 * specify the start of scanout from the beginning of the gtt mapping.
2213 void intel_add_fb_offsets(int *x, int *y,
2214 const struct intel_plane_state *state,
2218 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2219 unsigned int rotation = state->base.rotation;
2221 if (drm_rotation_90_or_270(rotation)) {
2222 *x += intel_fb->rotated[plane].x;
2223 *y += intel_fb->rotated[plane].y;
2225 *x += intel_fb->normal[plane].x;
2226 *y += intel_fb->normal[plane].y;
2230 static u32 __intel_adjust_tile_offset(int *x, int *y,
2231 unsigned int tile_width,
2232 unsigned int tile_height,
2233 unsigned int tile_size,
2234 unsigned int pitch_tiles,
2238 unsigned int pitch_pixels = pitch_tiles * tile_width;
2241 WARN_ON(old_offset & (tile_size - 1));
2242 WARN_ON(new_offset & (tile_size - 1));
2243 WARN_ON(new_offset > old_offset);
2245 tiles = (old_offset - new_offset) / tile_size;
2247 *y += tiles / pitch_tiles * tile_height;
2248 *x += tiles % pitch_tiles * tile_width;
2250 /* minimize x in case it got needlessly big */
2251 *y += *x / pitch_pixels * tile_height;
2257 static u32 _intel_adjust_tile_offset(int *x, int *y,
2258 const struct drm_framebuffer *fb, int plane,
2259 unsigned int rotation,
2260 u32 old_offset, u32 new_offset)
2262 const struct drm_i915_private *dev_priv = to_i915(fb->dev);
2263 unsigned int cpp = fb->format->cpp[plane];
2264 unsigned int pitch = intel_fb_pitch(fb, plane, rotation);
2266 WARN_ON(new_offset > old_offset);
2268 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2269 unsigned int tile_size, tile_width, tile_height;
2270 unsigned int pitch_tiles;
2272 tile_size = intel_tile_size(dev_priv);
2273 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2275 if (drm_rotation_90_or_270(rotation)) {
2276 pitch_tiles = pitch / tile_height;
2277 swap(tile_width, tile_height);
2279 pitch_tiles = pitch / (tile_width * cpp);
2282 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2283 tile_size, pitch_tiles,
2284 old_offset, new_offset);
2286 old_offset += *y * pitch + *x * cpp;
2288 *y = (old_offset - new_offset) / pitch;
2289 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2296 * Adjust the tile offset by moving the difference into
2299 static u32 intel_adjust_tile_offset(int *x, int *y,
2300 const struct intel_plane_state *state, int plane,
2301 u32 old_offset, u32 new_offset)
2303 return _intel_adjust_tile_offset(x, y, state->base.fb, plane,
2304 state->base.rotation,
2305 old_offset, new_offset);
2309 * Computes the linear offset to the base tile and adjusts
2310 * x, y. bytes per pixel is assumed to be a power-of-two.
2312 * In the 90/270 rotated case, x and y are assumed
2313 * to be already rotated to match the rotated GTT view, and
2314 * pitch is the tile_height aligned framebuffer height.
2316 * This function is used when computing the derived information
2317 * under intel_framebuffer, so using any of that information
2318 * here is not allowed. Anything under drm_framebuffer can be
2319 * used. This is why the user has to pass in the pitch since it
2320 * is specified in the rotated orientation.
2322 static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv,
2324 const struct drm_framebuffer *fb, int plane,
2326 unsigned int rotation,
2329 uint64_t fb_modifier = fb->modifier;
2330 unsigned int cpp = fb->format->cpp[plane];
2331 u32 offset, offset_aligned;
2336 if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
2337 unsigned int tile_size, tile_width, tile_height;
2338 unsigned int tile_rows, tiles, pitch_tiles;
2340 tile_size = intel_tile_size(dev_priv);
2341 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2343 if (drm_rotation_90_or_270(rotation)) {
2344 pitch_tiles = pitch / tile_height;
2345 swap(tile_width, tile_height);
2347 pitch_tiles = pitch / (tile_width * cpp);
2350 tile_rows = *y / tile_height;
2353 tiles = *x / tile_width;
2356 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2357 offset_aligned = offset & ~alignment;
2359 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2360 tile_size, pitch_tiles,
2361 offset, offset_aligned);
2363 offset = *y * pitch + *x * cpp;
2364 offset_aligned = offset & ~alignment;
2366 *y = (offset & alignment) / pitch;
2367 *x = ((offset & alignment) - *y * pitch) / cpp;
2370 return offset_aligned;
2373 u32 intel_compute_tile_offset(int *x, int *y,
2374 const struct intel_plane_state *state,
2377 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2378 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2379 const struct drm_framebuffer *fb = state->base.fb;
2380 unsigned int rotation = state->base.rotation;
2381 int pitch = intel_fb_pitch(fb, plane, rotation);
2384 if (intel_plane->id == PLANE_CURSOR)
2385 alignment = intel_cursor_alignment(dev_priv);
2387 alignment = intel_surf_alignment(fb, plane);
2389 return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch,
2390 rotation, alignment);
2393 /* Convert the fb->offset[] into x/y offsets */
2394 static int intel_fb_offset_to_xy(int *x, int *y,
2395 const struct drm_framebuffer *fb, int plane)
2397 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2399 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2400 fb->offsets[plane] % intel_tile_size(dev_priv))
2406 _intel_adjust_tile_offset(x, y,
2407 fb, plane, DRM_MODE_ROTATE_0,
2408 fb->offsets[plane], 0);
2413 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2415 switch (fb_modifier) {
2416 case I915_FORMAT_MOD_X_TILED:
2417 return I915_TILING_X;
2418 case I915_FORMAT_MOD_Y_TILED:
2419 case I915_FORMAT_MOD_Y_TILED_CCS:
2420 return I915_TILING_Y;
2422 return I915_TILING_NONE;
2427 * From the Sky Lake PRM:
2428 * "The Color Control Surface (CCS) contains the compression status of
2429 * the cache-line pairs. The compression state of the cache-line pair
2430 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2431 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2432 * cache-line-pairs. CCS is always Y tiled."
2434 * Since cache line pairs refers to horizontally adjacent cache lines,
2435 * each cache line in the CCS corresponds to an area of 32x16 cache
2436 * lines on the main surface. Since each pixel is 4 bytes, this gives
2437 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2440 static const struct drm_format_info ccs_formats[] = {
2441 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2442 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2443 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2444 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2447 static const struct drm_format_info *
2448 lookup_format_info(const struct drm_format_info formats[],
2449 int num_formats, u32 format)
2453 for (i = 0; i < num_formats; i++) {
2454 if (formats[i].format == format)
2461 static const struct drm_format_info *
2462 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2464 switch (cmd->modifier[0]) {
2465 case I915_FORMAT_MOD_Y_TILED_CCS:
2466 case I915_FORMAT_MOD_Yf_TILED_CCS:
2467 return lookup_format_info(ccs_formats,
2468 ARRAY_SIZE(ccs_formats),
2476 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2477 struct drm_framebuffer *fb)
2479 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2480 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2481 u32 gtt_offset_rotated = 0;
2482 unsigned int max_size = 0;
2483 int i, num_planes = fb->format->num_planes;
2484 unsigned int tile_size = intel_tile_size(dev_priv);
2486 for (i = 0; i < num_planes; i++) {
2487 unsigned int width, height;
2488 unsigned int cpp, size;
2493 cpp = fb->format->cpp[i];
2494 width = drm_framebuffer_plane_width(fb->width, fb, i);
2495 height = drm_framebuffer_plane_height(fb->height, fb, i);
2497 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2499 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2504 if ((fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2505 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) && i == 1) {
2506 int hsub = fb->format->hsub;
2507 int vsub = fb->format->vsub;
2508 int tile_width, tile_height;
2512 intel_tile_dims(fb, i, &tile_width, &tile_height);
2514 tile_height *= vsub;
2516 ccs_x = (x * hsub) % tile_width;
2517 ccs_y = (y * vsub) % tile_height;
2518 main_x = intel_fb->normal[0].x % tile_width;
2519 main_y = intel_fb->normal[0].y % tile_height;
2522 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2523 * x/y offsets must match between CCS and the main surface.
2525 if (main_x != ccs_x || main_y != ccs_y) {
2526 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2529 intel_fb->normal[0].x,
2530 intel_fb->normal[0].y,
2537 * The fence (if used) is aligned to the start of the object
2538 * so having the framebuffer wrap around across the edge of the
2539 * fenced region doesn't really work. We have no API to configure
2540 * the fence start offset within the object (nor could we probably
2541 * on gen2/3). So it's just easier if we just require that the
2542 * fb layout agrees with the fence layout. We already check that the
2543 * fb stride matches the fence stride elsewhere.
2545 if (i == 0 && i915_gem_object_is_tiled(intel_fb->obj) &&
2546 (x + width) * cpp > fb->pitches[i]) {
2547 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2553 * First pixel of the framebuffer from
2554 * the start of the normal gtt mapping.
2556 intel_fb->normal[i].x = x;
2557 intel_fb->normal[i].y = y;
2559 offset = _intel_compute_tile_offset(dev_priv, &x, &y,
2560 fb, i, fb->pitches[i],
2561 DRM_MODE_ROTATE_0, tile_size);
2562 offset /= tile_size;
2564 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2565 unsigned int tile_width, tile_height;
2566 unsigned int pitch_tiles;
2569 intel_tile_dims(fb, i, &tile_width, &tile_height);
2571 rot_info->plane[i].offset = offset;
2572 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2573 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2574 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2576 intel_fb->rotated[i].pitch =
2577 rot_info->plane[i].height * tile_height;
2579 /* how many tiles does this plane need */
2580 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2582 * If the plane isn't horizontally tile aligned,
2583 * we need one more tile.
2588 /* rotate the x/y offsets to match the GTT view */
2594 rot_info->plane[i].width * tile_width,
2595 rot_info->plane[i].height * tile_height,
2596 DRM_MODE_ROTATE_270);
2600 /* rotate the tile dimensions to match the GTT view */
2601 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2602 swap(tile_width, tile_height);
2605 * We only keep the x/y offsets, so push all of the
2606 * gtt offset into the x/y offsets.
2608 __intel_adjust_tile_offset(&x, &y,
2609 tile_width, tile_height,
2610 tile_size, pitch_tiles,
2611 gtt_offset_rotated * tile_size, 0);
2613 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2616 * First pixel of the framebuffer from
2617 * the start of the rotated gtt mapping.
2619 intel_fb->rotated[i].x = x;
2620 intel_fb->rotated[i].y = y;
2622 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2623 x * cpp, tile_size);
2626 /* how many tiles in total needed in the bo */
2627 max_size = max(max_size, offset + size);
2630 if (max_size * tile_size > intel_fb->obj->base.size) {
2631 DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
2632 max_size * tile_size, intel_fb->obj->base.size);
2639 static int i9xx_format_to_fourcc(int format)
2642 case DISPPLANE_8BPP:
2643 return DRM_FORMAT_C8;
2644 case DISPPLANE_BGRX555:
2645 return DRM_FORMAT_XRGB1555;
2646 case DISPPLANE_BGRX565:
2647 return DRM_FORMAT_RGB565;
2649 case DISPPLANE_BGRX888:
2650 return DRM_FORMAT_XRGB8888;
2651 case DISPPLANE_RGBX888:
2652 return DRM_FORMAT_XBGR8888;
2653 case DISPPLANE_BGRX101010:
2654 return DRM_FORMAT_XRGB2101010;
2655 case DISPPLANE_RGBX101010:
2656 return DRM_FORMAT_XBGR2101010;
2660 static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2663 case PLANE_CTL_FORMAT_RGB_565:
2664 return DRM_FORMAT_RGB565;
2666 case PLANE_CTL_FORMAT_XRGB_8888:
2669 return DRM_FORMAT_ABGR8888;
2671 return DRM_FORMAT_XBGR8888;
2674 return DRM_FORMAT_ARGB8888;
2676 return DRM_FORMAT_XRGB8888;
2678 case PLANE_CTL_FORMAT_XRGB_2101010:
2680 return DRM_FORMAT_XBGR2101010;
2682 return DRM_FORMAT_XRGB2101010;
2687 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2688 struct intel_initial_plane_config *plane_config)
2690 struct drm_device *dev = crtc->base.dev;
2691 struct drm_i915_private *dev_priv = to_i915(dev);
2692 struct drm_i915_gem_object *obj = NULL;
2693 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2694 struct drm_framebuffer *fb = &plane_config->fb->base;
2695 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2696 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2699 size_aligned -= base_aligned;
2701 if (plane_config->size == 0)
2704 /* If the FB is too big, just don't use it since fbdev is not very
2705 * important and we should probably use that space with FBC or other
2707 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2710 mutex_lock(&dev->struct_mutex);
2711 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2715 mutex_unlock(&dev->struct_mutex);
2719 if (plane_config->tiling == I915_TILING_X)
2720 obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X;
2722 mode_cmd.pixel_format = fb->format->format;
2723 mode_cmd.width = fb->width;
2724 mode_cmd.height = fb->height;
2725 mode_cmd.pitches[0] = fb->pitches[0];
2726 mode_cmd.modifier[0] = fb->modifier;
2727 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2729 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2730 DRM_DEBUG_KMS("intel fb init failed\n");
2735 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2739 i915_gem_object_put(obj);
2744 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2745 struct intel_plane_state *plane_state,
2748 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2750 plane_state->base.visible = visible;
2752 /* FIXME pre-g4x don't work like this */
2754 crtc_state->base.plane_mask |= BIT(drm_plane_index(&plane->base));
2755 crtc_state->active_planes |= BIT(plane->id);
2757 crtc_state->base.plane_mask &= ~BIT(drm_plane_index(&plane->base));
2758 crtc_state->active_planes &= ~BIT(plane->id);
2761 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2762 crtc_state->base.crtc->name,
2763 crtc_state->active_planes);
2766 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2767 struct intel_plane *plane)
2769 struct intel_crtc_state *crtc_state =
2770 to_intel_crtc_state(crtc->base.state);
2771 struct intel_plane_state *plane_state =
2772 to_intel_plane_state(plane->base.state);
2774 intel_set_plane_visible(crtc_state, plane_state, false);
2776 if (plane->id == PLANE_PRIMARY)
2777 intel_pre_disable_primary_noatomic(&crtc->base);
2779 trace_intel_disable_plane(&plane->base, crtc);
2780 plane->disable_plane(plane, crtc);
2784 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2785 struct intel_initial_plane_config *plane_config)
2787 struct drm_device *dev = intel_crtc->base.dev;
2788 struct drm_i915_private *dev_priv = to_i915(dev);
2790 struct drm_i915_gem_object *obj;
2791 struct drm_plane *primary = intel_crtc->base.primary;
2792 struct drm_plane_state *plane_state = primary->state;
2793 struct drm_crtc_state *crtc_state = intel_crtc->base.state;
2794 struct intel_plane *intel_plane = to_intel_plane(primary);
2795 struct intel_plane_state *intel_state =
2796 to_intel_plane_state(plane_state);
2797 struct drm_framebuffer *fb;
2799 if (!plane_config->fb)
2802 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2803 fb = &plane_config->fb->base;
2807 kfree(plane_config->fb);
2810 * Failed to alloc the obj, check to see if we should share
2811 * an fb with another CRTC instead
2813 for_each_crtc(dev, c) {
2814 struct intel_plane_state *state;
2816 if (c == &intel_crtc->base)
2819 if (!to_intel_crtc(c)->active)
2822 state = to_intel_plane_state(c->primary->state);
2826 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2827 fb = c->primary->fb;
2828 drm_framebuffer_get(fb);
2834 * We've failed to reconstruct the BIOS FB. Current display state
2835 * indicates that the primary plane is visible, but has a NULL FB,
2836 * which will lead to problems later if we don't fix it up. The
2837 * simplest solution is to just disable the primary plane now and
2838 * pretend the BIOS never had it enabled.
2840 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2845 mutex_lock(&dev->struct_mutex);
2847 intel_pin_and_fence_fb_obj(fb,
2848 primary->state->rotation,
2849 intel_plane_uses_fence(intel_state),
2850 &intel_state->flags);
2851 mutex_unlock(&dev->struct_mutex);
2852 if (IS_ERR(intel_state->vma)) {
2853 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2854 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2856 intel_state->vma = NULL;
2857 drm_framebuffer_put(fb);
2861 plane_state->src_x = 0;
2862 plane_state->src_y = 0;
2863 plane_state->src_w = fb->width << 16;
2864 plane_state->src_h = fb->height << 16;
2866 plane_state->crtc_x = 0;
2867 plane_state->crtc_y = 0;
2868 plane_state->crtc_w = fb->width;
2869 plane_state->crtc_h = fb->height;
2871 intel_state->base.src = drm_plane_state_src(plane_state);
2872 intel_state->base.dst = drm_plane_state_dest(plane_state);
2874 obj = intel_fb_obj(fb);
2875 if (i915_gem_object_is_tiled(obj))
2876 dev_priv->preserve_bios_swizzle = true;
2878 drm_framebuffer_get(fb);
2879 primary->fb = primary->state->fb = fb;
2880 primary->crtc = primary->state->crtc = &intel_crtc->base;
2882 intel_set_plane_visible(to_intel_crtc_state(crtc_state),
2883 to_intel_plane_state(plane_state),
2886 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2887 &obj->frontbuffer_bits);
2890 static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane,
2891 unsigned int rotation)
2893 int cpp = fb->format->cpp[plane];
2895 switch (fb->modifier) {
2896 case DRM_FORMAT_MOD_LINEAR:
2897 case I915_FORMAT_MOD_X_TILED:
2910 case I915_FORMAT_MOD_Y_TILED_CCS:
2911 case I915_FORMAT_MOD_Yf_TILED_CCS:
2912 /* FIXME AUX plane? */
2913 case I915_FORMAT_MOD_Y_TILED:
2914 case I915_FORMAT_MOD_Yf_TILED:
2929 MISSING_CASE(fb->modifier);
2935 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2936 int main_x, int main_y, u32 main_offset)
2938 const struct drm_framebuffer *fb = plane_state->base.fb;
2939 int hsub = fb->format->hsub;
2940 int vsub = fb->format->vsub;
2941 int aux_x = plane_state->aux.x;
2942 int aux_y = plane_state->aux.y;
2943 u32 aux_offset = plane_state->aux.offset;
2944 u32 alignment = intel_surf_alignment(fb, 1);
2946 while (aux_offset >= main_offset && aux_y <= main_y) {
2949 if (aux_x == main_x && aux_y == main_y)
2952 if (aux_offset == 0)
2957 aux_offset = intel_adjust_tile_offset(&x, &y, plane_state, 1,
2958 aux_offset, aux_offset - alignment);
2959 aux_x = x * hsub + aux_x % hsub;
2960 aux_y = y * vsub + aux_y % vsub;
2963 if (aux_x != main_x || aux_y != main_y)
2966 plane_state->aux.offset = aux_offset;
2967 plane_state->aux.x = aux_x;
2968 plane_state->aux.y = aux_y;
2973 static int skl_check_main_surface(const struct intel_crtc_state *crtc_state,
2974 struct intel_plane_state *plane_state)
2976 struct drm_i915_private *dev_priv =
2977 to_i915(plane_state->base.plane->dev);
2978 const struct drm_framebuffer *fb = plane_state->base.fb;
2979 unsigned int rotation = plane_state->base.rotation;
2980 int x = plane_state->base.src.x1 >> 16;
2981 int y = plane_state->base.src.y1 >> 16;
2982 int w = drm_rect_width(&plane_state->base.src) >> 16;
2983 int h = drm_rect_height(&plane_state->base.src) >> 16;
2984 int dst_x = plane_state->base.dst.x1;
2985 int pipe_src_w = crtc_state->pipe_src_w;
2986 int max_width = skl_max_plane_width(fb, 0, rotation);
2987 int max_height = 4096;
2988 u32 alignment, offset, aux_offset = plane_state->aux.offset;
2990 if (w > max_width || h > max_height) {
2991 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2992 w, h, max_width, max_height);
2997 * Display WA #1175: cnl,glk
2998 * Planes other than the cursor may cause FIFO underflow and display
2999 * corruption if starting less than 4 pixels from the right edge of
3001 * Besides the above WA fix the similar problem, where planes other
3002 * than the cursor ending less than 4 pixels from the left edge of the
3003 * screen may cause FIFO underflow and display corruption.
3005 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
3006 (dst_x + w < 4 || dst_x > pipe_src_w - 4)) {
3007 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
3008 dst_x + w < 4 ? "end" : "start",
3009 dst_x + w < 4 ? dst_x + w : dst_x,
3014 intel_add_fb_offsets(&x, &y, plane_state, 0);
3015 offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
3016 alignment = intel_surf_alignment(fb, 0);
3019 * AUX surface offset is specified as the distance from the
3020 * main surface offset, and it must be non-negative. Make
3021 * sure that is what we will get.
3023 if (offset > aux_offset)
3024 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3025 offset, aux_offset & ~(alignment - 1));
3028 * When using an X-tiled surface, the plane blows up
3029 * if the x offset + width exceed the stride.
3031 * TODO: linear and Y-tiled seem fine, Yf untested,
3033 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3034 int cpp = fb->format->cpp[0];
3036 while ((x + w) * cpp > fb->pitches[0]) {
3038 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3042 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3043 offset, offset - alignment);
3048 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3049 * they match with the main surface x/y offsets.
3051 if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
3052 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
3053 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3057 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3058 offset, offset - alignment);
3061 if (x != plane_state->aux.x || y != plane_state->aux.y) {
3062 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3067 plane_state->main.offset = offset;
3068 plane_state->main.x = x;
3069 plane_state->main.y = y;
3074 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3076 const struct drm_framebuffer *fb = plane_state->base.fb;
3077 unsigned int rotation = plane_state->base.rotation;
3078 int max_width = skl_max_plane_width(fb, 1, rotation);
3079 int max_height = 4096;
3080 int x = plane_state->base.src.x1 >> 17;
3081 int y = plane_state->base.src.y1 >> 17;
3082 int w = drm_rect_width(&plane_state->base.src) >> 17;
3083 int h = drm_rect_height(&plane_state->base.src) >> 17;
3086 intel_add_fb_offsets(&x, &y, plane_state, 1);
3087 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3089 /* FIXME not quite sure how/if these apply to the chroma plane */
3090 if (w > max_width || h > max_height) {
3091 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3092 w, h, max_width, max_height);
3096 plane_state->aux.offset = offset;
3097 plane_state->aux.x = x;
3098 plane_state->aux.y = y;
3103 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3105 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3106 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3107 struct intel_crtc *crtc = to_intel_crtc(plane_state->base.crtc);
3108 const struct drm_framebuffer *fb = plane_state->base.fb;
3109 int src_x = plane_state->base.src.x1 >> 16;
3110 int src_y = plane_state->base.src.y1 >> 16;
3111 int hsub = fb->format->hsub;
3112 int vsub = fb->format->vsub;
3113 int x = src_x / hsub;
3114 int y = src_y / vsub;
3117 if (!skl_plane_has_ccs(dev_priv, crtc->pipe, plane->id)) {
3118 DRM_DEBUG_KMS("No RC support on %s\n", plane->base.name);
3122 if (plane_state->base.rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180)) {
3123 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation %x\n",
3124 plane_state->base.rotation);
3128 intel_add_fb_offsets(&x, &y, plane_state, 1);
3129 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3131 plane_state->aux.offset = offset;
3132 plane_state->aux.x = x * hsub + src_x % hsub;
3133 plane_state->aux.y = y * vsub + src_y % vsub;
3138 int skl_check_plane_surface(const struct intel_crtc_state *crtc_state,
3139 struct intel_plane_state *plane_state)
3141 const struct drm_framebuffer *fb = plane_state->base.fb;
3142 unsigned int rotation = plane_state->base.rotation;
3145 if (rotation & DRM_MODE_REFLECT_X &&
3146 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
3147 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
3151 if (!plane_state->base.visible)
3154 /* Rotate src coordinates to match rotated GTT view */
3155 if (drm_rotation_90_or_270(rotation))
3156 drm_rect_rotate(&plane_state->base.src,
3157 fb->width << 16, fb->height << 16,
3158 DRM_MODE_ROTATE_270);
3161 * Handle the AUX surface first since
3162 * the main surface setup depends on it.
3164 if (fb->format->format == DRM_FORMAT_NV12) {
3165 ret = skl_check_nv12_aux_surface(plane_state);
3168 } else if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
3169 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
3170 ret = skl_check_ccs_aux_surface(plane_state);
3174 plane_state->aux.offset = ~0xfff;
3175 plane_state->aux.x = 0;
3176 plane_state->aux.y = 0;
3179 ret = skl_check_main_surface(crtc_state, plane_state);
3186 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3187 const struct intel_plane_state *plane_state)
3189 struct drm_i915_private *dev_priv =
3190 to_i915(plane_state->base.plane->dev);
3191 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3192 const struct drm_framebuffer *fb = plane_state->base.fb;
3193 unsigned int rotation = plane_state->base.rotation;
3196 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
3198 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3199 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
3200 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3202 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3203 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3205 if (INTEL_GEN(dev_priv) < 5)
3206 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3208 switch (fb->format->format) {
3210 dspcntr |= DISPPLANE_8BPP;
3212 case DRM_FORMAT_XRGB1555:
3213 dspcntr |= DISPPLANE_BGRX555;
3215 case DRM_FORMAT_RGB565:
3216 dspcntr |= DISPPLANE_BGRX565;
3218 case DRM_FORMAT_XRGB8888:
3219 dspcntr |= DISPPLANE_BGRX888;
3221 case DRM_FORMAT_XBGR8888:
3222 dspcntr |= DISPPLANE_RGBX888;
3224 case DRM_FORMAT_XRGB2101010:
3225 dspcntr |= DISPPLANE_BGRX101010;
3227 case DRM_FORMAT_XBGR2101010:
3228 dspcntr |= DISPPLANE_RGBX101010;
3231 MISSING_CASE(fb->format->format);
3235 if (INTEL_GEN(dev_priv) >= 4 &&
3236 fb->modifier == I915_FORMAT_MOD_X_TILED)
3237 dspcntr |= DISPPLANE_TILED;
3239 if (rotation & DRM_MODE_ROTATE_180)
3240 dspcntr |= DISPPLANE_ROTATE_180;
3242 if (rotation & DRM_MODE_REFLECT_X)
3243 dspcntr |= DISPPLANE_MIRROR;
3248 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3250 struct drm_i915_private *dev_priv =
3251 to_i915(plane_state->base.plane->dev);
3252 int src_x = plane_state->base.src.x1 >> 16;
3253 int src_y = plane_state->base.src.y1 >> 16;
3256 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3258 if (INTEL_GEN(dev_priv) >= 4)
3259 offset = intel_compute_tile_offset(&src_x, &src_y,
3264 /* HSW/BDW do this automagically in hardware */
3265 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3266 unsigned int rotation = plane_state->base.rotation;
3267 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3268 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3270 if (rotation & DRM_MODE_ROTATE_180) {
3273 } else if (rotation & DRM_MODE_REFLECT_X) {
3278 plane_state->main.offset = offset;
3279 plane_state->main.x = src_x;
3280 plane_state->main.y = src_y;
3285 static void i9xx_update_plane(struct intel_plane *plane,
3286 const struct intel_crtc_state *crtc_state,
3287 const struct intel_plane_state *plane_state)
3289 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3290 const struct drm_framebuffer *fb = plane_state->base.fb;
3291 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3293 u32 dspcntr = plane_state->ctl;
3294 i915_reg_t reg = DSPCNTR(i9xx_plane);
3295 int x = plane_state->main.x;
3296 int y = plane_state->main.y;
3297 unsigned long irqflags;
3300 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3302 if (INTEL_GEN(dev_priv) >= 4)
3303 dspaddr_offset = plane_state->main.offset;
3305 dspaddr_offset = linear_offset;
3307 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3309 if (INTEL_GEN(dev_priv) < 4) {
3310 /* pipesrc and dspsize control the size that is scaled from,
3311 * which should always be the user's requested size.
3313 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3314 ((crtc_state->pipe_src_h - 1) << 16) |
3315 (crtc_state->pipe_src_w - 1));
3316 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3317 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3318 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3319 ((crtc_state->pipe_src_h - 1) << 16) |
3320 (crtc_state->pipe_src_w - 1));
3321 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3322 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3325 I915_WRITE_FW(reg, dspcntr);
3327 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), fb->pitches[0]);
3328 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3329 I915_WRITE_FW(DSPSURF(i9xx_plane),
3330 intel_plane_ggtt_offset(plane_state) +
3332 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3333 } else if (INTEL_GEN(dev_priv) >= 4) {
3334 I915_WRITE_FW(DSPSURF(i9xx_plane),
3335 intel_plane_ggtt_offset(plane_state) +
3337 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3338 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3340 I915_WRITE_FW(DSPADDR(i9xx_plane),
3341 intel_plane_ggtt_offset(plane_state) +
3344 POSTING_READ_FW(reg);
3346 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3349 static void i9xx_disable_plane(struct intel_plane *plane,
3350 struct intel_crtc *crtc)
3352 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3353 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3354 unsigned long irqflags;
3356 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3358 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3359 if (INTEL_GEN(dev_priv) >= 4)
3360 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3362 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3363 POSTING_READ_FW(DSPCNTR(i9xx_plane));
3365 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3368 static bool i9xx_plane_get_hw_state(struct intel_plane *plane)
3370 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3371 enum intel_display_power_domain power_domain;
3372 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3373 enum pipe pipe = plane->pipe;
3377 * Not 100% correct for planes that can move between pipes,
3378 * but that's only the case for gen2-4 which don't have any
3379 * display power wells.
3381 power_domain = POWER_DOMAIN_PIPE(pipe);
3382 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3385 ret = I915_READ(DSPCNTR(i9xx_plane)) & DISPLAY_PLANE_ENABLE;
3387 intel_display_power_put(dev_priv, power_domain);
3393 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int plane)
3395 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3398 return intel_tile_width_bytes(fb, plane);
3401 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3403 struct drm_device *dev = intel_crtc->base.dev;
3404 struct drm_i915_private *dev_priv = to_i915(dev);
3406 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3407 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3408 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3412 * This function detaches (aka. unbinds) unused scalers in hardware
3414 static void skl_detach_scalers(struct intel_crtc *intel_crtc)
3416 struct intel_crtc_scaler_state *scaler_state;
3419 scaler_state = &intel_crtc->config->scaler_state;
3421 /* loop through and disable scalers that aren't in use */
3422 for (i = 0; i < intel_crtc->num_scalers; i++) {
3423 if (!scaler_state->scalers[i].in_use)
3424 skl_detach_scaler(intel_crtc, i);
3428 u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
3429 unsigned int rotation)
3433 if (plane >= fb->format->num_planes)
3436 stride = intel_fb_pitch(fb, plane, rotation);
3439 * The stride is either expressed as a multiple of 64 bytes chunks for
3440 * linear buffers or in number of tiles for tiled buffers.
3442 if (drm_rotation_90_or_270(rotation))
3443 stride /= intel_tile_height(fb, plane);
3445 stride /= intel_fb_stride_alignment(fb, plane);
3450 static u32 skl_plane_ctl_format(uint32_t pixel_format)
3452 switch (pixel_format) {
3454 return PLANE_CTL_FORMAT_INDEXED;
3455 case DRM_FORMAT_RGB565:
3456 return PLANE_CTL_FORMAT_RGB_565;
3457 case DRM_FORMAT_XBGR8888:
3458 case DRM_FORMAT_ABGR8888:
3459 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3460 case DRM_FORMAT_XRGB8888:
3461 case DRM_FORMAT_ARGB8888:
3462 return PLANE_CTL_FORMAT_XRGB_8888;
3463 case DRM_FORMAT_XRGB2101010:
3464 return PLANE_CTL_FORMAT_XRGB_2101010;
3465 case DRM_FORMAT_XBGR2101010:
3466 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3467 case DRM_FORMAT_YUYV:
3468 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3469 case DRM_FORMAT_YVYU:
3470 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3471 case DRM_FORMAT_UYVY:
3472 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3473 case DRM_FORMAT_VYUY:
3474 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3476 MISSING_CASE(pixel_format);
3483 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3484 * to be already pre-multiplied. We need to add a knob (or a different
3485 * DRM_FORMAT) for user-space to configure that.
3487 static u32 skl_plane_ctl_alpha(uint32_t pixel_format)
3489 switch (pixel_format) {
3490 case DRM_FORMAT_ABGR8888:
3491 case DRM_FORMAT_ARGB8888:
3492 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3494 return PLANE_CTL_ALPHA_DISABLE;
3498 static u32 glk_plane_color_ctl_alpha(uint32_t pixel_format)
3500 switch (pixel_format) {
3501 case DRM_FORMAT_ABGR8888:
3502 case DRM_FORMAT_ARGB8888:
3503 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3505 return PLANE_COLOR_ALPHA_DISABLE;
3509 static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
3511 switch (fb_modifier) {
3512 case DRM_FORMAT_MOD_LINEAR:
3514 case I915_FORMAT_MOD_X_TILED:
3515 return PLANE_CTL_TILED_X;
3516 case I915_FORMAT_MOD_Y_TILED:
3517 return PLANE_CTL_TILED_Y;
3518 case I915_FORMAT_MOD_Y_TILED_CCS:
3519 return PLANE_CTL_TILED_Y | PLANE_CTL_DECOMPRESSION_ENABLE;
3520 case I915_FORMAT_MOD_Yf_TILED:
3521 return PLANE_CTL_TILED_YF;
3522 case I915_FORMAT_MOD_Yf_TILED_CCS:
3523 return PLANE_CTL_TILED_YF | PLANE_CTL_DECOMPRESSION_ENABLE;
3525 MISSING_CASE(fb_modifier);
3531 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3534 case DRM_MODE_ROTATE_0:
3537 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3538 * while i915 HW rotation is clockwise, thats why this swapping.
3540 case DRM_MODE_ROTATE_90:
3541 return PLANE_CTL_ROTATE_270;
3542 case DRM_MODE_ROTATE_180:
3543 return PLANE_CTL_ROTATE_180;
3544 case DRM_MODE_ROTATE_270:
3545 return PLANE_CTL_ROTATE_90;
3547 MISSING_CASE(rotate);
3553 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3558 case DRM_MODE_REFLECT_X:
3559 return PLANE_CTL_FLIP_HORIZONTAL;
3560 case DRM_MODE_REFLECT_Y:
3562 MISSING_CASE(reflect);
3568 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3569 const struct intel_plane_state *plane_state)
3571 struct drm_i915_private *dev_priv =
3572 to_i915(plane_state->base.plane->dev);
3573 const struct drm_framebuffer *fb = plane_state->base.fb;
3574 unsigned int rotation = plane_state->base.rotation;
3575 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3578 plane_ctl = PLANE_CTL_ENABLE;
3580 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3581 plane_ctl |= skl_plane_ctl_alpha(fb->format->format);
3583 PLANE_CTL_PIPE_GAMMA_ENABLE |
3584 PLANE_CTL_PIPE_CSC_ENABLE |
3585 PLANE_CTL_PLANE_GAMMA_DISABLE;
3588 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3589 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3590 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3592 if (INTEL_GEN(dev_priv) >= 10)
3593 plane_ctl |= cnl_plane_ctl_flip(rotation &
3594 DRM_MODE_REFLECT_MASK);
3596 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3597 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3598 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3599 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3604 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3605 const struct intel_plane_state *plane_state)
3607 const struct drm_framebuffer *fb = plane_state->base.fb;
3608 u32 plane_color_ctl = 0;
3610 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3611 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3612 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3613 plane_color_ctl |= glk_plane_color_ctl_alpha(fb->format->format);
3615 return plane_color_ctl;
3619 __intel_display_resume(struct drm_device *dev,
3620 struct drm_atomic_state *state,
3621 struct drm_modeset_acquire_ctx *ctx)
3623 struct drm_crtc_state *crtc_state;
3624 struct drm_crtc *crtc;
3627 intel_modeset_setup_hw_state(dev, ctx);
3628 i915_redisable_vga(to_i915(dev));
3634 * We've duplicated the state, pointers to the old state are invalid.
3636 * Don't attempt to use the old state until we commit the duplicated state.
3638 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3640 * Force recalculation even if we restore
3641 * current state. With fast modeset this may not result
3642 * in a modeset when the state is compatible.
3644 crtc_state->mode_changed = true;
3647 /* ignore any reset values/BIOS leftovers in the WM registers */
3648 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3649 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3651 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3653 WARN_ON(ret == -EDEADLK);
3657 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3659 return intel_has_gpu_reset(dev_priv) &&
3660 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
3663 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3665 struct drm_device *dev = &dev_priv->drm;
3666 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3667 struct drm_atomic_state *state;
3671 /* reset doesn't touch the display */
3672 if (!i915_modparams.force_reset_modeset_test &&
3673 !gpu_reset_clobbers_display(dev_priv))
3676 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3677 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3678 wake_up_all(&dev_priv->gpu_error.wait_queue);
3680 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3681 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3682 i915_gem_set_wedged(dev_priv);
3686 * Need mode_config.mutex so that we don't
3687 * trample ongoing ->detect() and whatnot.
3689 mutex_lock(&dev->mode_config.mutex);
3690 drm_modeset_acquire_init(ctx, 0);
3692 ret = drm_modeset_lock_all_ctx(dev, ctx);
3693 if (ret != -EDEADLK)
3696 drm_modeset_backoff(ctx);
3699 * Disabling the crtcs gracefully seems nicer. Also the
3700 * g33 docs say we should at least disable all the planes.
3702 state = drm_atomic_helper_duplicate_state(dev, ctx);
3703 if (IS_ERR(state)) {
3704 ret = PTR_ERR(state);
3705 DRM_ERROR("Duplicating state failed with %i\n", ret);
3709 ret = drm_atomic_helper_disable_all(dev, ctx);
3711 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3712 drm_atomic_state_put(state);
3716 dev_priv->modeset_restore_state = state;
3717 state->acquire_ctx = ctx;
3720 void intel_finish_reset(struct drm_i915_private *dev_priv)
3722 struct drm_device *dev = &dev_priv->drm;
3723 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3724 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
3727 /* reset doesn't touch the display */
3728 if (!i915_modparams.force_reset_modeset_test &&
3729 !gpu_reset_clobbers_display(dev_priv))
3735 dev_priv->modeset_restore_state = NULL;
3737 /* reset doesn't touch the display */
3738 if (!gpu_reset_clobbers_display(dev_priv)) {
3739 /* for testing only restore the display */
3740 ret = __intel_display_resume(dev, state, ctx);
3742 DRM_ERROR("Restoring old state failed with %i\n", ret);
3745 * The display has been reset as well,
3746 * so need a full re-initialization.
3748 intel_runtime_pm_disable_interrupts(dev_priv);
3749 intel_runtime_pm_enable_interrupts(dev_priv);
3751 intel_pps_unlock_regs_wa(dev_priv);
3752 intel_modeset_init_hw(dev);
3753 intel_init_clock_gating(dev_priv);
3755 spin_lock_irq(&dev_priv->irq_lock);
3756 if (dev_priv->display.hpd_irq_setup)
3757 dev_priv->display.hpd_irq_setup(dev_priv);
3758 spin_unlock_irq(&dev_priv->irq_lock);
3760 ret = __intel_display_resume(dev, state, ctx);
3762 DRM_ERROR("Restoring old state failed with %i\n", ret);
3764 intel_hpd_init(dev_priv);
3767 drm_atomic_state_put(state);
3769 drm_modeset_drop_locks(ctx);
3770 drm_modeset_acquire_fini(ctx);
3771 mutex_unlock(&dev->mode_config.mutex);
3773 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3776 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3777 const struct intel_crtc_state *new_crtc_state)
3779 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
3780 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3782 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3783 crtc->base.mode = new_crtc_state->base.mode;
3786 * Update pipe size and adjust fitter if needed: the reason for this is
3787 * that in compute_mode_changes we check the native mode (not the pfit
3788 * mode) to see if we can flip rather than do a full mode set. In the
3789 * fastboot case, we'll flip, but if we don't update the pipesrc and
3790 * pfit state, we'll end up with a big fb scanned out into the wrong
3794 I915_WRITE(PIPESRC(crtc->pipe),
3795 ((new_crtc_state->pipe_src_w - 1) << 16) |
3796 (new_crtc_state->pipe_src_h - 1));
3798 /* on skylake this is done by detaching scalers */
3799 if (INTEL_GEN(dev_priv) >= 9) {
3800 skl_detach_scalers(crtc);
3802 if (new_crtc_state->pch_pfit.enabled)
3803 skylake_pfit_enable(crtc);
3804 } else if (HAS_PCH_SPLIT(dev_priv)) {
3805 if (new_crtc_state->pch_pfit.enabled)
3806 ironlake_pfit_enable(crtc);
3807 else if (old_crtc_state->pch_pfit.enabled)
3808 ironlake_pfit_disable(crtc, true);
3812 static void intel_fdi_normal_train(struct intel_crtc *crtc)
3814 struct drm_device *dev = crtc->base.dev;
3815 struct drm_i915_private *dev_priv = to_i915(dev);
3816 int pipe = crtc->pipe;
3820 /* enable normal train */
3821 reg = FDI_TX_CTL(pipe);
3822 temp = I915_READ(reg);
3823 if (IS_IVYBRIDGE(dev_priv)) {
3824 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3825 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3827 temp &= ~FDI_LINK_TRAIN_NONE;
3828 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3830 I915_WRITE(reg, temp);
3832 reg = FDI_RX_CTL(pipe);
3833 temp = I915_READ(reg);
3834 if (HAS_PCH_CPT(dev_priv)) {
3835 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3836 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3838 temp &= ~FDI_LINK_TRAIN_NONE;
3839 temp |= FDI_LINK_TRAIN_NONE;
3841 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3843 /* wait one idle pattern time */
3847 /* IVB wants error correction enabled */
3848 if (IS_IVYBRIDGE(dev_priv))
3849 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3850 FDI_FE_ERRC_ENABLE);
3853 /* The FDI link training functions for ILK/Ibexpeak. */
3854 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3855 const struct intel_crtc_state *crtc_state)
3857 struct drm_device *dev = crtc->base.dev;
3858 struct drm_i915_private *dev_priv = to_i915(dev);
3859 int pipe = crtc->pipe;
3863 /* FDI needs bits from pipe first */
3864 assert_pipe_enabled(dev_priv, pipe);
3866 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3868 reg = FDI_RX_IMR(pipe);
3869 temp = I915_READ(reg);
3870 temp &= ~FDI_RX_SYMBOL_LOCK;
3871 temp &= ~FDI_RX_BIT_LOCK;
3872 I915_WRITE(reg, temp);
3876 /* enable CPU FDI TX and PCH FDI RX */
3877 reg = FDI_TX_CTL(pipe);
3878 temp = I915_READ(reg);
3879 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3880 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3881 temp &= ~FDI_LINK_TRAIN_NONE;
3882 temp |= FDI_LINK_TRAIN_PATTERN_1;
3883 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3885 reg = FDI_RX_CTL(pipe);
3886 temp = I915_READ(reg);
3887 temp &= ~FDI_LINK_TRAIN_NONE;
3888 temp |= FDI_LINK_TRAIN_PATTERN_1;
3889 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3894 /* Ironlake workaround, enable clock pointer after FDI enable*/
3895 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3896 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3897 FDI_RX_PHASE_SYNC_POINTER_EN);
3899 reg = FDI_RX_IIR(pipe);
3900 for (tries = 0; tries < 5; tries++) {
3901 temp = I915_READ(reg);
3902 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3904 if ((temp & FDI_RX_BIT_LOCK)) {
3905 DRM_DEBUG_KMS("FDI train 1 done.\n");
3906 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3911 DRM_ERROR("FDI train 1 fail!\n");
3914 reg = FDI_TX_CTL(pipe);
3915 temp = I915_READ(reg);
3916 temp &= ~FDI_LINK_TRAIN_NONE;
3917 temp |= FDI_LINK_TRAIN_PATTERN_2;
3918 I915_WRITE(reg, temp);
3920 reg = FDI_RX_CTL(pipe);
3921 temp = I915_READ(reg);
3922 temp &= ~FDI_LINK_TRAIN_NONE;
3923 temp |= FDI_LINK_TRAIN_PATTERN_2;
3924 I915_WRITE(reg, temp);
3929 reg = FDI_RX_IIR(pipe);
3930 for (tries = 0; tries < 5; tries++) {
3931 temp = I915_READ(reg);
3932 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3934 if (temp & FDI_RX_SYMBOL_LOCK) {
3935 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3936 DRM_DEBUG_KMS("FDI train 2 done.\n");
3941 DRM_ERROR("FDI train 2 fail!\n");
3943 DRM_DEBUG_KMS("FDI train done\n");
3947 static const int snb_b_fdi_train_param[] = {
3948 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
3949 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
3950 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
3951 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
3954 /* The FDI link training functions for SNB/Cougarpoint. */
3955 static void gen6_fdi_link_train(struct intel_crtc *crtc,
3956 const struct intel_crtc_state *crtc_state)
3958 struct drm_device *dev = crtc->base.dev;
3959 struct drm_i915_private *dev_priv = to_i915(dev);
3960 int pipe = crtc->pipe;
3964 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3966 reg = FDI_RX_IMR(pipe);
3967 temp = I915_READ(reg);
3968 temp &= ~FDI_RX_SYMBOL_LOCK;
3969 temp &= ~FDI_RX_BIT_LOCK;
3970 I915_WRITE(reg, temp);
3975 /* enable CPU FDI TX and PCH FDI RX */
3976 reg = FDI_TX_CTL(pipe);
3977 temp = I915_READ(reg);
3978 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3979 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3980 temp &= ~FDI_LINK_TRAIN_NONE;
3981 temp |= FDI_LINK_TRAIN_PATTERN_1;
3982 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3984 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
3985 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3987 I915_WRITE(FDI_RX_MISC(pipe),
3988 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
3990 reg = FDI_RX_CTL(pipe);
3991 temp = I915_READ(reg);
3992 if (HAS_PCH_CPT(dev_priv)) {
3993 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3994 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
3996 temp &= ~FDI_LINK_TRAIN_NONE;
3997 temp |= FDI_LINK_TRAIN_PATTERN_1;
3999 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4004 for (i = 0; i < 4; i++) {
4005 reg = FDI_TX_CTL(pipe);
4006 temp = I915_READ(reg);
4007 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4008 temp |= snb_b_fdi_train_param[i];
4009 I915_WRITE(reg, temp);
4014 for (retry = 0; retry < 5; retry++) {
4015 reg = FDI_RX_IIR(pipe);
4016 temp = I915_READ(reg);
4017 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4018 if (temp & FDI_RX_BIT_LOCK) {
4019 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4020 DRM_DEBUG_KMS("FDI train 1 done.\n");
4029 DRM_ERROR("FDI train 1 fail!\n");
4032 reg = FDI_TX_CTL(pipe);
4033 temp = I915_READ(reg);
4034 temp &= ~FDI_LINK_TRAIN_NONE;
4035 temp |= FDI_LINK_TRAIN_PATTERN_2;
4036 if (IS_GEN6(dev_priv)) {
4037 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4039 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4041 I915_WRITE(reg, temp);
4043 reg = FDI_RX_CTL(pipe);
4044 temp = I915_READ(reg);
4045 if (HAS_PCH_CPT(dev_priv)) {
4046 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4047 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4049 temp &= ~FDI_LINK_TRAIN_NONE;
4050 temp |= FDI_LINK_TRAIN_PATTERN_2;
4052 I915_WRITE(reg, temp);
4057 for (i = 0; i < 4; i++) {
4058 reg = FDI_TX_CTL(pipe);
4059 temp = I915_READ(reg);
4060 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4061 temp |= snb_b_fdi_train_param[i];
4062 I915_WRITE(reg, temp);
4067 for (retry = 0; retry < 5; retry++) {
4068 reg = FDI_RX_IIR(pipe);
4069 temp = I915_READ(reg);
4070 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4071 if (temp & FDI_RX_SYMBOL_LOCK) {
4072 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4073 DRM_DEBUG_KMS("FDI train 2 done.\n");
4082 DRM_ERROR("FDI train 2 fail!\n");
4084 DRM_DEBUG_KMS("FDI train done.\n");
4087 /* Manual link training for Ivy Bridge A0 parts */
4088 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4089 const struct intel_crtc_state *crtc_state)
4091 struct drm_device *dev = crtc->base.dev;
4092 struct drm_i915_private *dev_priv = to_i915(dev);
4093 int pipe = crtc->pipe;
4097 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4099 reg = FDI_RX_IMR(pipe);
4100 temp = I915_READ(reg);
4101 temp &= ~FDI_RX_SYMBOL_LOCK;
4102 temp &= ~FDI_RX_BIT_LOCK;
4103 I915_WRITE(reg, temp);
4108 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4109 I915_READ(FDI_RX_IIR(pipe)));
4111 /* Try each vswing and preemphasis setting twice before moving on */
4112 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4113 /* disable first in case we need to retry */
4114 reg = FDI_TX_CTL(pipe);
4115 temp = I915_READ(reg);
4116 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4117 temp &= ~FDI_TX_ENABLE;
4118 I915_WRITE(reg, temp);
4120 reg = FDI_RX_CTL(pipe);
4121 temp = I915_READ(reg);
4122 temp &= ~FDI_LINK_TRAIN_AUTO;
4123 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4124 temp &= ~FDI_RX_ENABLE;
4125 I915_WRITE(reg, temp);
4127 /* enable CPU FDI TX and PCH FDI RX */
4128 reg = FDI_TX_CTL(pipe);
4129 temp = I915_READ(reg);
4130 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4131 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4132 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4133 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4134 temp |= snb_b_fdi_train_param[j/2];
4135 temp |= FDI_COMPOSITE_SYNC;
4136 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4138 I915_WRITE(FDI_RX_MISC(pipe),
4139 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4141 reg = FDI_RX_CTL(pipe);
4142 temp = I915_READ(reg);
4143 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4144 temp |= FDI_COMPOSITE_SYNC;
4145 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4148 udelay(1); /* should be 0.5us */
4150 for (i = 0; i < 4; i++) {
4151 reg = FDI_RX_IIR(pipe);
4152 temp = I915_READ(reg);
4153 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4155 if (temp & FDI_RX_BIT_LOCK ||
4156 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4157 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4158 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4162 udelay(1); /* should be 0.5us */
4165 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4170 reg = FDI_TX_CTL(pipe);
4171 temp = I915_READ(reg);
4172 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4173 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4174 I915_WRITE(reg, temp);
4176 reg = FDI_RX_CTL(pipe);
4177 temp = I915_READ(reg);
4178 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4179 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4180 I915_WRITE(reg, temp);
4183 udelay(2); /* should be 1.5us */
4185 for (i = 0; i < 4; i++) {
4186 reg = FDI_RX_IIR(pipe);
4187 temp = I915_READ(reg);
4188 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4190 if (temp & FDI_RX_SYMBOL_LOCK ||
4191 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4192 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4193 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4197 udelay(2); /* should be 1.5us */
4200 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4204 DRM_DEBUG_KMS("FDI train done.\n");
4207 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
4209 struct drm_device *dev = intel_crtc->base.dev;
4210 struct drm_i915_private *dev_priv = to_i915(dev);
4211 int pipe = intel_crtc->pipe;
4215 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4216 reg = FDI_RX_CTL(pipe);
4217 temp = I915_READ(reg);
4218 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4219 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
4220 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4221 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4226 /* Switch from Rawclk to PCDclk */
4227 temp = I915_READ(reg);
4228 I915_WRITE(reg, temp | FDI_PCDCLK);
4233 /* Enable CPU FDI TX PLL, always on for Ironlake */
4234 reg = FDI_TX_CTL(pipe);
4235 temp = I915_READ(reg);
4236 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4237 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4244 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4246 struct drm_device *dev = intel_crtc->base.dev;
4247 struct drm_i915_private *dev_priv = to_i915(dev);
4248 int pipe = intel_crtc->pipe;
4252 /* Switch from PCDclk to Rawclk */
4253 reg = FDI_RX_CTL(pipe);
4254 temp = I915_READ(reg);
4255 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4257 /* Disable CPU FDI TX PLL */
4258 reg = FDI_TX_CTL(pipe);
4259 temp = I915_READ(reg);
4260 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4265 reg = FDI_RX_CTL(pipe);
4266 temp = I915_READ(reg);
4267 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4269 /* Wait for the clocks to turn off. */
4274 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4276 struct drm_device *dev = crtc->dev;
4277 struct drm_i915_private *dev_priv = to_i915(dev);
4278 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4279 int pipe = intel_crtc->pipe;
4283 /* disable CPU FDI tx and PCH FDI rx */
4284 reg = FDI_TX_CTL(pipe);
4285 temp = I915_READ(reg);
4286 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4289 reg = FDI_RX_CTL(pipe);
4290 temp = I915_READ(reg);
4291 temp &= ~(0x7 << 16);
4292 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4293 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4298 /* Ironlake workaround, disable clock pointer after downing FDI */
4299 if (HAS_PCH_IBX(dev_priv))
4300 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4302 /* still set train pattern 1 */
4303 reg = FDI_TX_CTL(pipe);
4304 temp = I915_READ(reg);
4305 temp &= ~FDI_LINK_TRAIN_NONE;
4306 temp |= FDI_LINK_TRAIN_PATTERN_1;
4307 I915_WRITE(reg, temp);
4309 reg = FDI_RX_CTL(pipe);
4310 temp = I915_READ(reg);
4311 if (HAS_PCH_CPT(dev_priv)) {
4312 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4313 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4315 temp &= ~FDI_LINK_TRAIN_NONE;
4316 temp |= FDI_LINK_TRAIN_PATTERN_1;
4318 /* BPC in FDI rx is consistent with that in PIPECONF */
4319 temp &= ~(0x07 << 16);
4320 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4321 I915_WRITE(reg, temp);
4327 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4329 struct drm_crtc *crtc;
4332 drm_for_each_crtc(crtc, &dev_priv->drm) {
4333 struct drm_crtc_commit *commit;
4334 spin_lock(&crtc->commit_lock);
4335 commit = list_first_entry_or_null(&crtc->commit_list,
4336 struct drm_crtc_commit, commit_entry);
4337 cleanup_done = commit ?
4338 try_wait_for_completion(&commit->cleanup_done) : true;
4339 spin_unlock(&crtc->commit_lock);
4344 drm_crtc_wait_one_vblank(crtc);
4352 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4356 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4358 mutex_lock(&dev_priv->sb_lock);
4360 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4361 temp |= SBI_SSCCTL_DISABLE;
4362 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4364 mutex_unlock(&dev_priv->sb_lock);
4367 /* Program iCLKIP clock to the desired frequency */
4368 static void lpt_program_iclkip(struct intel_crtc *crtc)
4370 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4371 int clock = crtc->config->base.adjusted_mode.crtc_clock;
4372 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4375 lpt_disable_iclkip(dev_priv);
4377 /* The iCLK virtual clock root frequency is in MHz,
4378 * but the adjusted_mode->crtc_clock in in KHz. To get the
4379 * divisors, it is necessary to divide one by another, so we
4380 * convert the virtual clock precision to KHz here for higher
4383 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4384 u32 iclk_virtual_root_freq = 172800 * 1000;
4385 u32 iclk_pi_range = 64;
4386 u32 desired_divisor;
4388 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4390 divsel = (desired_divisor / iclk_pi_range) - 2;
4391 phaseinc = desired_divisor % iclk_pi_range;
4394 * Near 20MHz is a corner case which is
4395 * out of range for the 7-bit divisor
4401 /* This should not happen with any sane values */
4402 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4403 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4404 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4405 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4407 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4414 mutex_lock(&dev_priv->sb_lock);
4416 /* Program SSCDIVINTPHASE6 */
4417 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4418 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4419 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4420 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4421 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4422 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4423 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4424 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4426 /* Program SSCAUXDIV */
4427 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4428 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4429 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4430 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4432 /* Enable modulator and associated divider */
4433 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4434 temp &= ~SBI_SSCCTL_DISABLE;
4435 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4437 mutex_unlock(&dev_priv->sb_lock);
4439 /* Wait for initialization time */
4442 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4445 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4447 u32 divsel, phaseinc, auxdiv;
4448 u32 iclk_virtual_root_freq = 172800 * 1000;
4449 u32 iclk_pi_range = 64;
4450 u32 desired_divisor;
4453 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4456 mutex_lock(&dev_priv->sb_lock);
4458 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4459 if (temp & SBI_SSCCTL_DISABLE) {
4460 mutex_unlock(&dev_priv->sb_lock);
4464 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4465 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4466 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4467 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4468 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4470 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4471 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4472 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4474 mutex_unlock(&dev_priv->sb_lock);
4476 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4478 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4479 desired_divisor << auxdiv);
4482 static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
4483 enum pipe pch_transcoder)
4485 struct drm_device *dev = crtc->base.dev;
4486 struct drm_i915_private *dev_priv = to_i915(dev);
4487 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
4489 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4490 I915_READ(HTOTAL(cpu_transcoder)));
4491 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4492 I915_READ(HBLANK(cpu_transcoder)));
4493 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4494 I915_READ(HSYNC(cpu_transcoder)));
4496 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4497 I915_READ(VTOTAL(cpu_transcoder)));
4498 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4499 I915_READ(VBLANK(cpu_transcoder)));
4500 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4501 I915_READ(VSYNC(cpu_transcoder)));
4502 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4503 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4506 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4508 struct drm_i915_private *dev_priv = to_i915(dev);
4511 temp = I915_READ(SOUTH_CHICKEN1);
4512 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4515 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4516 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4518 temp &= ~FDI_BC_BIFURCATION_SELECT;
4520 temp |= FDI_BC_BIFURCATION_SELECT;
4522 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4523 I915_WRITE(SOUTH_CHICKEN1, temp);
4524 POSTING_READ(SOUTH_CHICKEN1);
4527 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4529 struct drm_device *dev = intel_crtc->base.dev;
4531 switch (intel_crtc->pipe) {
4535 if (intel_crtc->config->fdi_lanes > 2)
4536 cpt_set_fdi_bc_bifurcation(dev, false);
4538 cpt_set_fdi_bc_bifurcation(dev, true);
4542 cpt_set_fdi_bc_bifurcation(dev, true);
4550 /* Return which DP Port should be selected for Transcoder DP control */
4552 intel_trans_dp_port_sel(struct intel_crtc *crtc)
4554 struct drm_device *dev = crtc->base.dev;
4555 struct intel_encoder *encoder;
4557 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
4558 if (encoder->type == INTEL_OUTPUT_DP ||
4559 encoder->type == INTEL_OUTPUT_EDP)
4560 return encoder->port;
4567 * Enable PCH resources required for PCH ports:
4569 * - FDI training & RX/TX
4570 * - update transcoder timings
4571 * - DP transcoding bits
4574 static void ironlake_pch_enable(const struct intel_crtc_state *crtc_state)
4576 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4577 struct drm_device *dev = crtc->base.dev;
4578 struct drm_i915_private *dev_priv = to_i915(dev);
4579 int pipe = crtc->pipe;
4582 assert_pch_transcoder_disabled(dev_priv, pipe);
4584 if (IS_IVYBRIDGE(dev_priv))
4585 ivybridge_update_fdi_bc_bifurcation(crtc);
4587 /* Write the TU size bits before fdi link training, so that error
4588 * detection works. */
4589 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4590 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4592 /* For PCH output, training FDI link */
4593 dev_priv->display.fdi_link_train(crtc, crtc_state);
4595 /* We need to program the right clock selection before writing the pixel
4596 * mutliplier into the DPLL. */
4597 if (HAS_PCH_CPT(dev_priv)) {
4600 temp = I915_READ(PCH_DPLL_SEL);
4601 temp |= TRANS_DPLL_ENABLE(pipe);
4602 sel = TRANS_DPLLB_SEL(pipe);
4603 if (crtc_state->shared_dpll ==
4604 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4608 I915_WRITE(PCH_DPLL_SEL, temp);
4611 /* XXX: pch pll's can be enabled any time before we enable the PCH
4612 * transcoder, and we actually should do this to not upset any PCH
4613 * transcoder that already use the clock when we share it.
4615 * Note that enable_shared_dpll tries to do the right thing, but
4616 * get_shared_dpll unconditionally resets the pll - we need that to have
4617 * the right LVDS enable sequence. */
4618 intel_enable_shared_dpll(crtc);
4620 /* set transcoder timing, panel must allow it */
4621 assert_panel_unlocked(dev_priv, pipe);
4622 ironlake_pch_transcoder_set_timings(crtc, pipe);
4624 intel_fdi_normal_train(crtc);
4626 /* For PCH DP, enable TRANS_DP_CTL */
4627 if (HAS_PCH_CPT(dev_priv) &&
4628 intel_crtc_has_dp_encoder(crtc_state)) {
4629 const struct drm_display_mode *adjusted_mode =
4630 &crtc_state->base.adjusted_mode;
4631 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4632 i915_reg_t reg = TRANS_DP_CTL(pipe);
4633 temp = I915_READ(reg);
4634 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4635 TRANS_DP_SYNC_MASK |
4637 temp |= TRANS_DP_OUTPUT_ENABLE;
4638 temp |= bpc << 9; /* same format but at 11:9 */
4640 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4641 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4642 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4643 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4645 switch (intel_trans_dp_port_sel(crtc)) {
4647 temp |= TRANS_DP_PORT_SEL_B;
4650 temp |= TRANS_DP_PORT_SEL_C;
4653 temp |= TRANS_DP_PORT_SEL_D;
4659 I915_WRITE(reg, temp);
4662 ironlake_enable_pch_transcoder(dev_priv, pipe);
4665 static void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
4667 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4668 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4669 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4671 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4673 lpt_program_iclkip(crtc);
4675 /* Set transcoder timing. */
4676 ironlake_pch_transcoder_set_timings(crtc, PIPE_A);
4678 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4681 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4683 struct drm_i915_private *dev_priv = to_i915(dev);
4684 i915_reg_t dslreg = PIPEDSL(pipe);
4687 temp = I915_READ(dslreg);
4689 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4690 if (wait_for(I915_READ(dslreg) != temp, 5))
4691 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4696 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4697 unsigned int scaler_user, int *scaler_id,
4698 int src_w, int src_h, int dst_w, int dst_h)
4700 struct intel_crtc_scaler_state *scaler_state =
4701 &crtc_state->scaler_state;
4702 struct intel_crtc *intel_crtc =
4703 to_intel_crtc(crtc_state->base.crtc);
4704 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4705 const struct drm_display_mode *adjusted_mode =
4706 &crtc_state->base.adjusted_mode;
4710 * Src coordinates are already rotated by 270 degrees for
4711 * the 90/270 degree plane rotation cases (to match the
4712 * GTT mapping), hence no need to account for rotation here.
4714 need_scaling = src_w != dst_w || src_h != dst_h;
4716 if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX)
4717 need_scaling = true;
4720 * Scaling/fitting not supported in IF-ID mode in GEN9+
4721 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4722 * Once NV12 is enabled, handle it here while allocating scaler
4725 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4726 need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4727 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4732 * if plane is being disabled or scaler is no more required or force detach
4733 * - free scaler binded to this plane/crtc
4734 * - in order to do this, update crtc->scaler_usage
4736 * Here scaler state in crtc_state is set free so that
4737 * scaler can be assigned to other user. Actual register
4738 * update to free the scaler is done in plane/panel-fit programming.
4739 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4741 if (force_detach || !need_scaling) {
4742 if (*scaler_id >= 0) {
4743 scaler_state->scaler_users &= ~(1 << scaler_user);
4744 scaler_state->scalers[*scaler_id].in_use = 0;
4746 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4747 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4748 intel_crtc->pipe, scaler_user, *scaler_id,
4749 scaler_state->scaler_users);
4756 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4757 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4759 src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4760 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) {
4761 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4762 "size is out of scaler range\n",
4763 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4767 /* mark this plane as a scaler user in crtc_state */
4768 scaler_state->scaler_users |= (1 << scaler_user);
4769 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4770 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4771 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4772 scaler_state->scaler_users);
4778 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4780 * @state: crtc's scaler state
4783 * 0 - scaler_usage updated successfully
4784 * error - requested scaling cannot be supported or other error condition
4786 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4788 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
4790 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4791 &state->scaler_state.scaler_id,
4792 state->pipe_src_w, state->pipe_src_h,
4793 adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay);
4797 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4798 * @crtc_state: crtc's scaler state
4799 * @plane_state: atomic plane state to update
4802 * 0 - scaler_usage updated successfully
4803 * error - requested scaling cannot be supported or other error condition
4805 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4806 struct intel_plane_state *plane_state)
4809 struct intel_plane *intel_plane =
4810 to_intel_plane(plane_state->base.plane);
4811 struct drm_framebuffer *fb = plane_state->base.fb;
4814 bool force_detach = !fb || !plane_state->base.visible;
4816 ret = skl_update_scaler(crtc_state, force_detach,
4817 drm_plane_index(&intel_plane->base),
4818 &plane_state->scaler_id,
4819 drm_rect_width(&plane_state->base.src) >> 16,
4820 drm_rect_height(&plane_state->base.src) >> 16,
4821 drm_rect_width(&plane_state->base.dst),
4822 drm_rect_height(&plane_state->base.dst));
4824 if (ret || plane_state->scaler_id < 0)
4827 /* check colorkey */
4828 if (plane_state->ckey.flags) {
4829 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4830 intel_plane->base.base.id,
4831 intel_plane->base.name);
4835 /* Check src format */
4836 switch (fb->format->format) {
4837 case DRM_FORMAT_RGB565:
4838 case DRM_FORMAT_XBGR8888:
4839 case DRM_FORMAT_XRGB8888:
4840 case DRM_FORMAT_ABGR8888:
4841 case DRM_FORMAT_ARGB8888:
4842 case DRM_FORMAT_XRGB2101010:
4843 case DRM_FORMAT_XBGR2101010:
4844 case DRM_FORMAT_YUYV:
4845 case DRM_FORMAT_YVYU:
4846 case DRM_FORMAT_UYVY:
4847 case DRM_FORMAT_VYUY:
4850 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4851 intel_plane->base.base.id, intel_plane->base.name,
4852 fb->base.id, fb->format->format);
4859 static void skylake_scaler_disable(struct intel_crtc *crtc)
4863 for (i = 0; i < crtc->num_scalers; i++)
4864 skl_detach_scaler(crtc, i);
4867 static void skylake_pfit_enable(struct intel_crtc *crtc)
4869 struct drm_device *dev = crtc->base.dev;
4870 struct drm_i915_private *dev_priv = to_i915(dev);
4871 int pipe = crtc->pipe;
4872 struct intel_crtc_scaler_state *scaler_state =
4873 &crtc->config->scaler_state;
4875 if (crtc->config->pch_pfit.enabled) {
4878 if (WARN_ON(crtc->config->scaler_state.scaler_id < 0))
4881 id = scaler_state->scaler_id;
4882 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
4883 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
4884 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
4885 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
4889 static void ironlake_pfit_enable(struct intel_crtc *crtc)
4891 struct drm_device *dev = crtc->base.dev;
4892 struct drm_i915_private *dev_priv = to_i915(dev);
4893 int pipe = crtc->pipe;
4895 if (crtc->config->pch_pfit.enabled) {
4896 /* Force use of hard-coded filter coefficients
4897 * as some pre-programmed values are broken,
4900 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
4901 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
4902 PF_PIPE_SEL_IVB(pipe));
4904 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
4905 I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
4906 I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
4910 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
4912 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4913 struct drm_device *dev = crtc->base.dev;
4914 struct drm_i915_private *dev_priv = to_i915(dev);
4916 if (!crtc_state->ips_enabled)
4920 * We can only enable IPS after we enable a plane and wait for a vblank
4921 * This function is called from post_plane_update, which is run after
4924 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
4926 if (IS_BROADWELL(dev_priv)) {
4927 mutex_lock(&dev_priv->pcu_lock);
4928 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
4929 IPS_ENABLE | IPS_PCODE_CONTROL));
4930 mutex_unlock(&dev_priv->pcu_lock);
4931 /* Quoting Art Runyan: "its not safe to expect any particular
4932 * value in IPS_CTL bit 31 after enabling IPS through the
4933 * mailbox." Moreover, the mailbox may return a bogus state,
4934 * so we need to just enable it and continue on.
4937 I915_WRITE(IPS_CTL, IPS_ENABLE);
4938 /* The bit only becomes 1 in the next vblank, so this wait here
4939 * is essentially intel_wait_for_vblank. If we don't have this
4940 * and don't wait for vblanks until the end of crtc_enable, then
4941 * the HW state readout code will complain that the expected
4942 * IPS_CTL value is not the one we read. */
4943 if (intel_wait_for_register(dev_priv,
4944 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
4946 DRM_ERROR("Timed out waiting for IPS enable\n");
4950 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
4952 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4953 struct drm_device *dev = crtc->base.dev;
4954 struct drm_i915_private *dev_priv = to_i915(dev);
4956 if (!crtc_state->ips_enabled)
4959 if (IS_BROADWELL(dev_priv)) {
4960 mutex_lock(&dev_priv->pcu_lock);
4961 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
4962 mutex_unlock(&dev_priv->pcu_lock);
4963 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4964 if (intel_wait_for_register(dev_priv,
4965 IPS_CTL, IPS_ENABLE, 0,
4967 DRM_ERROR("Timed out waiting for IPS disable\n");
4969 I915_WRITE(IPS_CTL, 0);
4970 POSTING_READ(IPS_CTL);
4973 /* We need to wait for a vblank before we can disable the plane. */
4974 intel_wait_for_vblank(dev_priv, crtc->pipe);
4977 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
4979 if (intel_crtc->overlay) {
4980 struct drm_device *dev = intel_crtc->base.dev;
4982 mutex_lock(&dev->struct_mutex);
4983 (void) intel_overlay_switch_off(intel_crtc->overlay);
4984 mutex_unlock(&dev->struct_mutex);
4987 /* Let userspace switch the overlay on again. In most cases userspace
4988 * has to recompute where to put it anyway.
4993 * intel_post_enable_primary - Perform operations after enabling primary plane
4994 * @crtc: the CRTC whose primary plane was just enabled
4995 * @new_crtc_state: the enabling state
4997 * Performs potentially sleeping operations that must be done after the primary
4998 * plane is enabled, such as updating FBC and IPS. Note that this may be
4999 * called due to an explicit primary plane update, or due to an implicit
5000 * re-enable that is caused when a sprite plane is updated to no longer
5001 * completely hide the primary plane.
5004 intel_post_enable_primary(struct drm_crtc *crtc,
5005 const struct intel_crtc_state *new_crtc_state)
5007 struct drm_device *dev = crtc->dev;
5008 struct drm_i915_private *dev_priv = to_i915(dev);
5009 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5010 int pipe = intel_crtc->pipe;
5013 * Gen2 reports pipe underruns whenever all planes are disabled.
5014 * So don't enable underrun reporting before at least some planes
5016 * FIXME: Need to fix the logic to work when we turn off all planes
5017 * but leave the pipe running.
5019 if (IS_GEN2(dev_priv))
5020 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5022 /* Underruns don't always raise interrupts, so check manually. */
5023 intel_check_cpu_fifo_underruns(dev_priv);
5024 intel_check_pch_fifo_underruns(dev_priv);
5027 /* FIXME get rid of this and use pre_plane_update */
5029 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5031 struct drm_device *dev = crtc->dev;
5032 struct drm_i915_private *dev_priv = to_i915(dev);
5033 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5034 int pipe = intel_crtc->pipe;
5037 * Gen2 reports pipe underruns whenever all planes are disabled.
5038 * So disable underrun reporting before all the planes get disabled.
5040 if (IS_GEN2(dev_priv))
5041 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5043 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5046 * Vblank time updates from the shadow to live plane control register
5047 * are blocked if the memory self-refresh mode is active at that
5048 * moment. So to make sure the plane gets truly disabled, disable
5049 * first the self-refresh mode. The self-refresh enable bit in turn
5050 * will be checked/applied by the HW only at the next frame start
5051 * event which is after the vblank start event, so we need to have a
5052 * wait-for-vblank between disabling the plane and the pipe.
5054 if (HAS_GMCH_DISPLAY(dev_priv) &&
5055 intel_set_memory_cxsr(dev_priv, false))
5056 intel_wait_for_vblank(dev_priv, pipe);
5059 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5060 const struct intel_crtc_state *new_crtc_state)
5062 if (!old_crtc_state->ips_enabled)
5065 if (needs_modeset(&new_crtc_state->base))
5068 return !new_crtc_state->ips_enabled;
5071 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5072 const struct intel_crtc_state *new_crtc_state)
5074 if (!new_crtc_state->ips_enabled)
5077 if (needs_modeset(&new_crtc_state->base))
5081 * We can't read out IPS on broadwell, assume the worst and
5082 * forcibly enable IPS on the first fastset.
5084 if (new_crtc_state->update_pipe &&
5085 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5088 return !old_crtc_state->ips_enabled;
5091 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5093 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5094 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5095 struct intel_crtc_state *pipe_config =
5096 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5098 struct drm_plane *primary = crtc->base.primary;
5099 struct drm_plane_state *old_pri_state =
5100 drm_atomic_get_existing_plane_state(old_state, primary);
5102 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5104 if (pipe_config->update_wm_post && pipe_config->base.active)
5105 intel_update_watermarks(crtc);
5107 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5108 hsw_enable_ips(pipe_config);
5110 if (old_pri_state) {
5111 struct intel_plane_state *primary_state =
5112 intel_atomic_get_new_plane_state(to_intel_atomic_state(old_state),
5113 to_intel_plane(primary));
5114 struct intel_plane_state *old_primary_state =
5115 to_intel_plane_state(old_pri_state);
5117 intel_fbc_post_update(crtc);
5119 if (primary_state->base.visible &&
5120 (needs_modeset(&pipe_config->base) ||
5121 !old_primary_state->base.visible))
5122 intel_post_enable_primary(&crtc->base, pipe_config);
5126 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5127 struct intel_crtc_state *pipe_config)
5129 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5130 struct drm_device *dev = crtc->base.dev;
5131 struct drm_i915_private *dev_priv = to_i915(dev);
5132 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5133 struct drm_plane *primary = crtc->base.primary;
5134 struct drm_plane_state *old_pri_state =
5135 drm_atomic_get_existing_plane_state(old_state, primary);
5136 bool modeset = needs_modeset(&pipe_config->base);
5137 struct intel_atomic_state *old_intel_state =
5138 to_intel_atomic_state(old_state);
5140 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5141 hsw_disable_ips(old_crtc_state);
5143 if (old_pri_state) {
5144 struct intel_plane_state *primary_state =
5145 intel_atomic_get_new_plane_state(old_intel_state,
5146 to_intel_plane(primary));
5147 struct intel_plane_state *old_primary_state =
5148 to_intel_plane_state(old_pri_state);
5150 intel_fbc_pre_update(crtc, pipe_config, primary_state);
5152 * Gen2 reports pipe underruns whenever all planes are disabled.
5153 * So disable underrun reporting before all the planes get disabled.
5155 if (IS_GEN2(dev_priv) && old_primary_state->base.visible &&
5156 (modeset || !primary_state->base.visible))
5157 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5161 * Vblank time updates from the shadow to live plane control register
5162 * are blocked if the memory self-refresh mode is active at that
5163 * moment. So to make sure the plane gets truly disabled, disable
5164 * first the self-refresh mode. The self-refresh enable bit in turn
5165 * will be checked/applied by the HW only at the next frame start
5166 * event which is after the vblank start event, so we need to have a
5167 * wait-for-vblank between disabling the plane and the pipe.
5169 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5170 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5171 intel_wait_for_vblank(dev_priv, crtc->pipe);
5174 * IVB workaround: must disable low power watermarks for at least
5175 * one frame before enabling scaling. LP watermarks can be re-enabled
5176 * when scaling is disabled.
5178 * WaCxSRDisabledForSpriteScaling:ivb
5180 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev))
5181 intel_wait_for_vblank(dev_priv, crtc->pipe);
5184 * If we're doing a modeset, we're done. No need to do any pre-vblank
5185 * watermark programming here.
5187 if (needs_modeset(&pipe_config->base))
5191 * For platforms that support atomic watermarks, program the
5192 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5193 * will be the intermediate values that are safe for both pre- and
5194 * post- vblank; when vblank happens, the 'active' values will be set
5195 * to the final 'target' values and we'll do this again to get the
5196 * optimal watermarks. For gen9+ platforms, the values we program here
5197 * will be the final target values which will get automatically latched
5198 * at vblank time; no further programming will be necessary.
5200 * If a platform hasn't been transitioned to atomic watermarks yet,
5201 * we'll continue to update watermarks the old way, if flags tell
5204 if (dev_priv->display.initial_watermarks != NULL)
5205 dev_priv->display.initial_watermarks(old_intel_state,
5207 else if (pipe_config->update_wm_pre)
5208 intel_update_watermarks(crtc);
5211 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
5213 struct drm_device *dev = crtc->dev;
5214 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5215 struct drm_plane *p;
5216 int pipe = intel_crtc->pipe;
5218 intel_crtc_dpms_overlay_disable(intel_crtc);
5220 drm_for_each_plane_mask(p, dev, plane_mask)
5221 to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc);
5224 * FIXME: Once we grow proper nuclear flip support out of this we need
5225 * to compute the mask of flip planes precisely. For the time being
5226 * consider this a flip to a NULL plane.
5228 intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe));
5231 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5232 struct intel_crtc_state *crtc_state,
5233 struct drm_atomic_state *old_state)
5235 struct drm_connector_state *conn_state;
5236 struct drm_connector *conn;
5239 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5240 struct intel_encoder *encoder =
5241 to_intel_encoder(conn_state->best_encoder);
5243 if (conn_state->crtc != crtc)
5246 if (encoder->pre_pll_enable)
5247 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5251 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5252 struct intel_crtc_state *crtc_state,
5253 struct drm_atomic_state *old_state)
5255 struct drm_connector_state *conn_state;
5256 struct drm_connector *conn;
5259 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5260 struct intel_encoder *encoder =
5261 to_intel_encoder(conn_state->best_encoder);
5263 if (conn_state->crtc != crtc)
5266 if (encoder->pre_enable)
5267 encoder->pre_enable(encoder, crtc_state, conn_state);
5271 static void intel_encoders_enable(struct drm_crtc *crtc,
5272 struct intel_crtc_state *crtc_state,
5273 struct drm_atomic_state *old_state)
5275 struct drm_connector_state *conn_state;
5276 struct drm_connector *conn;
5279 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5280 struct intel_encoder *encoder =
5281 to_intel_encoder(conn_state->best_encoder);
5283 if (conn_state->crtc != crtc)
5286 encoder->enable(encoder, crtc_state, conn_state);
5287 intel_opregion_notify_encoder(encoder, true);
5291 static void intel_encoders_disable(struct drm_crtc *crtc,
5292 struct intel_crtc_state *old_crtc_state,
5293 struct drm_atomic_state *old_state)
5295 struct drm_connector_state *old_conn_state;
5296 struct drm_connector *conn;
5299 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5300 struct intel_encoder *encoder =
5301 to_intel_encoder(old_conn_state->best_encoder);
5303 if (old_conn_state->crtc != crtc)
5306 intel_opregion_notify_encoder(encoder, false);
5307 encoder->disable(encoder, old_crtc_state, old_conn_state);
5311 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5312 struct intel_crtc_state *old_crtc_state,
5313 struct drm_atomic_state *old_state)
5315 struct drm_connector_state *old_conn_state;
5316 struct drm_connector *conn;
5319 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5320 struct intel_encoder *encoder =
5321 to_intel_encoder(old_conn_state->best_encoder);
5323 if (old_conn_state->crtc != crtc)
5326 if (encoder->post_disable)
5327 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5331 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5332 struct intel_crtc_state *old_crtc_state,
5333 struct drm_atomic_state *old_state)
5335 struct drm_connector_state *old_conn_state;
5336 struct drm_connector *conn;
5339 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5340 struct intel_encoder *encoder =
5341 to_intel_encoder(old_conn_state->best_encoder);
5343 if (old_conn_state->crtc != crtc)
5346 if (encoder->post_pll_disable)
5347 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5351 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5352 struct drm_atomic_state *old_state)
5354 struct drm_crtc *crtc = pipe_config->base.crtc;
5355 struct drm_device *dev = crtc->dev;
5356 struct drm_i915_private *dev_priv = to_i915(dev);
5357 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5358 int pipe = intel_crtc->pipe;
5359 struct intel_atomic_state *old_intel_state =
5360 to_intel_atomic_state(old_state);
5362 if (WARN_ON(intel_crtc->active))
5366 * Sometimes spurious CPU pipe underruns happen during FDI
5367 * training, at least with VGA+HDMI cloning. Suppress them.
5369 * On ILK we get an occasional spurious CPU pipe underruns
5370 * between eDP port A enable and vdd enable. Also PCH port
5371 * enable seems to result in the occasional CPU pipe underrun.
5373 * Spurious PCH underruns also occur during PCH enabling.
5375 if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv))
5376 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5377 if (intel_crtc->config->has_pch_encoder)
5378 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5380 if (intel_crtc->config->has_pch_encoder)
5381 intel_prepare_shared_dpll(intel_crtc);
5383 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5384 intel_dp_set_m_n(intel_crtc, M1_N1);
5386 intel_set_pipe_timings(intel_crtc);
5387 intel_set_pipe_src_size(intel_crtc);
5389 if (intel_crtc->config->has_pch_encoder) {
5390 intel_cpu_transcoder_set_m_n(intel_crtc,
5391 &intel_crtc->config->fdi_m_n, NULL);
5394 ironlake_set_pipeconf(crtc);
5396 intel_crtc->active = true;
5398 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5400 if (intel_crtc->config->has_pch_encoder) {
5401 /* Note: FDI PLL enabling _must_ be done before we enable the
5402 * cpu pipes, hence this is separate from all the other fdi/pch
5404 ironlake_fdi_pll_enable(intel_crtc);
5406 assert_fdi_tx_disabled(dev_priv, pipe);
5407 assert_fdi_rx_disabled(dev_priv, pipe);
5410 ironlake_pfit_enable(intel_crtc);
5413 * On ILK+ LUT must be loaded before the pipe is running but with
5416 intel_color_load_luts(&pipe_config->base);
5418 if (dev_priv->display.initial_watermarks != NULL)
5419 dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config);
5420 intel_enable_pipe(pipe_config);
5422 if (intel_crtc->config->has_pch_encoder)
5423 ironlake_pch_enable(pipe_config);
5425 assert_vblank_disabled(crtc);
5426 drm_crtc_vblank_on(crtc);
5428 intel_encoders_enable(crtc, pipe_config, old_state);
5430 if (HAS_PCH_CPT(dev_priv))
5431 cpt_verify_modeset(dev, intel_crtc->pipe);
5433 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5434 if (intel_crtc->config->has_pch_encoder)
5435 intel_wait_for_vblank(dev_priv, pipe);
5436 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5437 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5440 /* IPS only exists on ULT machines and is tied to pipe A. */
5441 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5443 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5446 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5447 enum pipe pipe, bool apply)
5449 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5450 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5457 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5460 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5462 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5463 enum pipe pipe = crtc->pipe;
5466 val = MBUS_DBOX_BW_CREDIT(1) | MBUS_DBOX_A_CREDIT(2);
5468 /* Program B credit equally to all pipes */
5469 val |= MBUS_DBOX_B_CREDIT(24 / INTEL_INFO(dev_priv)->num_pipes);
5471 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5474 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5475 struct drm_atomic_state *old_state)
5477 struct drm_crtc *crtc = pipe_config->base.crtc;
5478 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5479 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5480 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5481 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5482 struct intel_atomic_state *old_intel_state =
5483 to_intel_atomic_state(old_state);
5484 bool psl_clkgate_wa;
5486 if (WARN_ON(intel_crtc->active))
5489 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5491 if (intel_crtc->config->shared_dpll)
5492 intel_enable_shared_dpll(intel_crtc);
5494 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5495 intel_dp_set_m_n(intel_crtc, M1_N1);
5497 if (!transcoder_is_dsi(cpu_transcoder))
5498 intel_set_pipe_timings(intel_crtc);
5500 intel_set_pipe_src_size(intel_crtc);
5502 if (cpu_transcoder != TRANSCODER_EDP &&
5503 !transcoder_is_dsi(cpu_transcoder)) {
5504 I915_WRITE(PIPE_MULT(cpu_transcoder),
5505 intel_crtc->config->pixel_multiplier - 1);
5508 if (intel_crtc->config->has_pch_encoder) {
5509 intel_cpu_transcoder_set_m_n(intel_crtc,
5510 &intel_crtc->config->fdi_m_n, NULL);
5513 if (!transcoder_is_dsi(cpu_transcoder))
5514 haswell_set_pipeconf(crtc);
5516 haswell_set_pipemisc(crtc);
5518 intel_color_set_csc(&pipe_config->base);
5520 intel_crtc->active = true;
5522 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5524 if (!transcoder_is_dsi(cpu_transcoder))
5525 intel_ddi_enable_pipe_clock(pipe_config);
5527 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5528 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5529 intel_crtc->config->pch_pfit.enabled;
5531 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5533 if (INTEL_GEN(dev_priv) >= 9)
5534 skylake_pfit_enable(intel_crtc);
5536 ironlake_pfit_enable(intel_crtc);
5539 * On ILK+ LUT must be loaded before the pipe is running but with
5542 intel_color_load_luts(&pipe_config->base);
5544 intel_ddi_set_pipe_settings(pipe_config);
5545 if (!transcoder_is_dsi(cpu_transcoder))
5546 intel_ddi_enable_transcoder_func(pipe_config);
5548 if (dev_priv->display.initial_watermarks != NULL)
5549 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5551 if (INTEL_GEN(dev_priv) >= 11)
5552 icl_pipe_mbus_enable(intel_crtc);
5554 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5555 if (!transcoder_is_dsi(cpu_transcoder))
5556 intel_enable_pipe(pipe_config);
5558 if (intel_crtc->config->has_pch_encoder)
5559 lpt_pch_enable(pipe_config);
5561 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5562 intel_ddi_set_vc_payload_alloc(pipe_config, true);
5564 assert_vblank_disabled(crtc);
5565 drm_crtc_vblank_on(crtc);
5567 intel_encoders_enable(crtc, pipe_config, old_state);
5569 if (psl_clkgate_wa) {
5570 intel_wait_for_vblank(dev_priv, pipe);
5571 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5574 /* If we change the relative order between pipe/planes enabling, we need
5575 * to change the workaround. */
5576 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
5577 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5578 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5579 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5583 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force)
5585 struct drm_device *dev = crtc->base.dev;
5586 struct drm_i915_private *dev_priv = to_i915(dev);
5587 int pipe = crtc->pipe;
5589 /* To avoid upsetting the power well on haswell only disable the pfit if
5590 * it's in use. The hw state code will make sure we get this right. */
5591 if (force || crtc->config->pch_pfit.enabled) {
5592 I915_WRITE(PF_CTL(pipe), 0);
5593 I915_WRITE(PF_WIN_POS(pipe), 0);
5594 I915_WRITE(PF_WIN_SZ(pipe), 0);
5598 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5599 struct drm_atomic_state *old_state)
5601 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5602 struct drm_device *dev = crtc->dev;
5603 struct drm_i915_private *dev_priv = to_i915(dev);
5604 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5605 int pipe = intel_crtc->pipe;
5608 * Sometimes spurious CPU pipe underruns happen when the
5609 * pipe is already disabled, but FDI RX/TX is still enabled.
5610 * Happens at least with VGA+HDMI cloning. Suppress them.
5612 if (intel_crtc->config->has_pch_encoder) {
5613 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5614 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5617 intel_encoders_disable(crtc, old_crtc_state, old_state);
5619 drm_crtc_vblank_off(crtc);
5620 assert_vblank_disabled(crtc);
5622 intel_disable_pipe(old_crtc_state);
5624 ironlake_pfit_disable(intel_crtc, false);
5626 if (intel_crtc->config->has_pch_encoder)
5627 ironlake_fdi_disable(crtc);
5629 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5631 if (intel_crtc->config->has_pch_encoder) {
5632 ironlake_disable_pch_transcoder(dev_priv, pipe);
5634 if (HAS_PCH_CPT(dev_priv)) {
5638 /* disable TRANS_DP_CTL */
5639 reg = TRANS_DP_CTL(pipe);
5640 temp = I915_READ(reg);
5641 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5642 TRANS_DP_PORT_SEL_MASK);
5643 temp |= TRANS_DP_PORT_SEL_NONE;
5644 I915_WRITE(reg, temp);
5646 /* disable DPLL_SEL */
5647 temp = I915_READ(PCH_DPLL_SEL);
5648 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5649 I915_WRITE(PCH_DPLL_SEL, temp);
5652 ironlake_fdi_pll_disable(intel_crtc);
5655 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5656 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5659 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5660 struct drm_atomic_state *old_state)
5662 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5663 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5664 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5665 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5667 intel_encoders_disable(crtc, old_crtc_state, old_state);
5669 drm_crtc_vblank_off(crtc);
5670 assert_vblank_disabled(crtc);
5672 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5673 if (!transcoder_is_dsi(cpu_transcoder))
5674 intel_disable_pipe(old_crtc_state);
5676 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5677 intel_ddi_set_vc_payload_alloc(intel_crtc->config, false);
5679 if (!transcoder_is_dsi(cpu_transcoder))
5680 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
5682 if (INTEL_GEN(dev_priv) >= 9)
5683 skylake_scaler_disable(intel_crtc);
5685 ironlake_pfit_disable(intel_crtc, false);
5687 if (!transcoder_is_dsi(cpu_transcoder))
5688 intel_ddi_disable_pipe_clock(intel_crtc->config);
5690 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5693 static void i9xx_pfit_enable(struct intel_crtc *crtc)
5695 struct drm_device *dev = crtc->base.dev;
5696 struct drm_i915_private *dev_priv = to_i915(dev);
5697 struct intel_crtc_state *pipe_config = crtc->config;
5699 if (!pipe_config->gmch_pfit.control)
5703 * The panel fitter should only be adjusted whilst the pipe is disabled,
5704 * according to register description and PRM.
5706 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5707 assert_pipe_disabled(dev_priv, crtc->pipe);
5709 I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
5710 I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
5712 /* Border color in case we don't scale up to the full screen. Black by
5713 * default, change to something else for debugging. */
5714 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5717 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
5721 return POWER_DOMAIN_PORT_DDI_A_LANES;
5723 return POWER_DOMAIN_PORT_DDI_B_LANES;
5725 return POWER_DOMAIN_PORT_DDI_C_LANES;
5727 return POWER_DOMAIN_PORT_DDI_D_LANES;
5729 return POWER_DOMAIN_PORT_DDI_E_LANES;
5731 return POWER_DOMAIN_PORT_DDI_F_LANES;
5734 return POWER_DOMAIN_PORT_OTHER;
5738 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
5739 struct intel_crtc_state *crtc_state)
5741 struct drm_device *dev = crtc->dev;
5742 struct drm_i915_private *dev_priv = to_i915(dev);
5743 struct drm_encoder *encoder;
5744 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5745 enum pipe pipe = intel_crtc->pipe;
5747 enum transcoder transcoder = crtc_state->cpu_transcoder;
5749 if (!crtc_state->base.active)
5752 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
5753 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
5754 if (crtc_state->pch_pfit.enabled ||
5755 crtc_state->pch_pfit.force_thru)
5756 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5758 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
5759 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5761 mask |= BIT_ULL(intel_encoder->power_domain);
5764 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
5765 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
5767 if (crtc_state->shared_dpll)
5768 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
5774 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
5775 struct intel_crtc_state *crtc_state)
5777 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5778 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5779 enum intel_display_power_domain domain;
5780 u64 domains, new_domains, old_domains;
5782 old_domains = intel_crtc->enabled_power_domains;
5783 intel_crtc->enabled_power_domains = new_domains =
5784 get_crtc_power_domains(crtc, crtc_state);
5786 domains = new_domains & ~old_domains;
5788 for_each_power_domain(domain, domains)
5789 intel_display_power_get(dev_priv, domain);
5791 return old_domains & ~new_domains;
5794 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
5797 enum intel_display_power_domain domain;
5799 for_each_power_domain(domain, domains)
5800 intel_display_power_put(dev_priv, domain);
5803 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
5804 struct drm_atomic_state *old_state)
5806 struct intel_atomic_state *old_intel_state =
5807 to_intel_atomic_state(old_state);
5808 struct drm_crtc *crtc = pipe_config->base.crtc;
5809 struct drm_device *dev = crtc->dev;
5810 struct drm_i915_private *dev_priv = to_i915(dev);
5811 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5812 int pipe = intel_crtc->pipe;
5814 if (WARN_ON(intel_crtc->active))
5817 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5818 intel_dp_set_m_n(intel_crtc, M1_N1);
5820 intel_set_pipe_timings(intel_crtc);
5821 intel_set_pipe_src_size(intel_crtc);
5823 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
5824 struct drm_i915_private *dev_priv = to_i915(dev);
5826 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
5827 I915_WRITE(CHV_CANVAS(pipe), 0);
5830 i9xx_set_pipeconf(intel_crtc);
5832 intel_crtc->active = true;
5834 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5836 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5838 if (IS_CHERRYVIEW(dev_priv)) {
5839 chv_prepare_pll(intel_crtc, intel_crtc->config);
5840 chv_enable_pll(intel_crtc, intel_crtc->config);
5842 vlv_prepare_pll(intel_crtc, intel_crtc->config);
5843 vlv_enable_pll(intel_crtc, intel_crtc->config);
5846 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5848 i9xx_pfit_enable(intel_crtc);
5850 intel_color_load_luts(&pipe_config->base);
5852 dev_priv->display.initial_watermarks(old_intel_state,
5854 intel_enable_pipe(pipe_config);
5856 assert_vblank_disabled(crtc);
5857 drm_crtc_vblank_on(crtc);
5859 intel_encoders_enable(crtc, pipe_config, old_state);
5862 static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
5864 struct drm_device *dev = crtc->base.dev;
5865 struct drm_i915_private *dev_priv = to_i915(dev);
5867 I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
5868 I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
5871 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
5872 struct drm_atomic_state *old_state)
5874 struct intel_atomic_state *old_intel_state =
5875 to_intel_atomic_state(old_state);
5876 struct drm_crtc *crtc = pipe_config->base.crtc;
5877 struct drm_device *dev = crtc->dev;
5878 struct drm_i915_private *dev_priv = to_i915(dev);
5879 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5880 enum pipe pipe = intel_crtc->pipe;
5882 if (WARN_ON(intel_crtc->active))
5885 i9xx_set_pll_dividers(intel_crtc);
5887 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5888 intel_dp_set_m_n(intel_crtc, M1_N1);
5890 intel_set_pipe_timings(intel_crtc);
5891 intel_set_pipe_src_size(intel_crtc);
5893 i9xx_set_pipeconf(intel_crtc);
5895 intel_crtc->active = true;
5897 if (!IS_GEN2(dev_priv))
5898 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5900 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5902 i9xx_enable_pll(intel_crtc, pipe_config);
5904 i9xx_pfit_enable(intel_crtc);
5906 intel_color_load_luts(&pipe_config->base);
5908 if (dev_priv->display.initial_watermarks != NULL)
5909 dev_priv->display.initial_watermarks(old_intel_state,
5910 intel_crtc->config);
5912 intel_update_watermarks(intel_crtc);
5913 intel_enable_pipe(pipe_config);
5915 assert_vblank_disabled(crtc);
5916 drm_crtc_vblank_on(crtc);
5918 intel_encoders_enable(crtc, pipe_config, old_state);
5921 static void i9xx_pfit_disable(struct intel_crtc *crtc)
5923 struct drm_device *dev = crtc->base.dev;
5924 struct drm_i915_private *dev_priv = to_i915(dev);
5926 if (!crtc->config->gmch_pfit.control)
5929 assert_pipe_disabled(dev_priv, crtc->pipe);
5931 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5932 I915_READ(PFIT_CONTROL));
5933 I915_WRITE(PFIT_CONTROL, 0);
5936 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
5937 struct drm_atomic_state *old_state)
5939 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5940 struct drm_device *dev = crtc->dev;
5941 struct drm_i915_private *dev_priv = to_i915(dev);
5942 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5943 int pipe = intel_crtc->pipe;
5946 * On gen2 planes are double buffered but the pipe isn't, so we must
5947 * wait for planes to fully turn off before disabling the pipe.
5949 if (IS_GEN2(dev_priv))
5950 intel_wait_for_vblank(dev_priv, pipe);
5952 intel_encoders_disable(crtc, old_crtc_state, old_state);
5954 drm_crtc_vblank_off(crtc);
5955 assert_vblank_disabled(crtc);
5957 intel_disable_pipe(old_crtc_state);
5959 i9xx_pfit_disable(intel_crtc);
5961 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5963 if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) {
5964 if (IS_CHERRYVIEW(dev_priv))
5965 chv_disable_pll(dev_priv, pipe);
5966 else if (IS_VALLEYVIEW(dev_priv))
5967 vlv_disable_pll(dev_priv, pipe);
5969 i9xx_disable_pll(intel_crtc);
5972 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
5974 if (!IS_GEN2(dev_priv))
5975 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5977 if (!dev_priv->display.initial_watermarks)
5978 intel_update_watermarks(intel_crtc);
5980 /* clock the pipe down to 640x480@60 to potentially save power */
5981 if (IS_I830(dev_priv))
5982 i830_enable_pipe(dev_priv, pipe);
5985 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
5986 struct drm_modeset_acquire_ctx *ctx)
5988 struct intel_encoder *encoder;
5989 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5990 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5991 enum intel_display_power_domain domain;
5992 struct intel_plane *plane;
5994 struct drm_atomic_state *state;
5995 struct intel_crtc_state *crtc_state;
5998 if (!intel_crtc->active)
6001 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6002 const struct intel_plane_state *plane_state =
6003 to_intel_plane_state(plane->base.state);
6005 if (plane_state->base.visible)
6006 intel_plane_disable_noatomic(intel_crtc, plane);
6009 state = drm_atomic_state_alloc(crtc->dev);
6011 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6012 crtc->base.id, crtc->name);
6016 state->acquire_ctx = ctx;
6018 /* Everything's already locked, -EDEADLK can't happen. */
6019 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6020 ret = drm_atomic_add_affected_connectors(state, crtc);
6022 WARN_ON(IS_ERR(crtc_state) || ret);
6024 dev_priv->display.crtc_disable(crtc_state, state);
6026 drm_atomic_state_put(state);
6028 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6029 crtc->base.id, crtc->name);
6031 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6032 crtc->state->active = false;
6033 intel_crtc->active = false;
6034 crtc->enabled = false;
6035 crtc->state->connector_mask = 0;
6036 crtc->state->encoder_mask = 0;
6038 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6039 encoder->base.crtc = NULL;
6041 intel_fbc_disable(intel_crtc);
6042 intel_update_watermarks(intel_crtc);
6043 intel_disable_shared_dpll(intel_crtc);
6045 domains = intel_crtc->enabled_power_domains;
6046 for_each_power_domain(domain, domains)
6047 intel_display_power_put(dev_priv, domain);
6048 intel_crtc->enabled_power_domains = 0;
6050 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6051 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6052 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6056 * turn all crtc's off, but do not adjust state
6057 * This has to be paired with a call to intel_modeset_setup_hw_state.
6059 int intel_display_suspend(struct drm_device *dev)
6061 struct drm_i915_private *dev_priv = to_i915(dev);
6062 struct drm_atomic_state *state;
6065 state = drm_atomic_helper_suspend(dev);
6066 ret = PTR_ERR_OR_ZERO(state);
6068 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6070 dev_priv->modeset_restore_state = state;
6074 void intel_encoder_destroy(struct drm_encoder *encoder)
6076 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6078 drm_encoder_cleanup(encoder);
6079 kfree(intel_encoder);
6082 /* Cross check the actual hw state with our own modeset state tracking (and it's
6083 * internal consistency). */
6084 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6085 struct drm_connector_state *conn_state)
6087 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6089 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6090 connector->base.base.id,
6091 connector->base.name);
6093 if (connector->get_hw_state(connector)) {
6094 struct intel_encoder *encoder = connector->encoder;
6096 I915_STATE_WARN(!crtc_state,
6097 "connector enabled without attached crtc\n");
6102 I915_STATE_WARN(!crtc_state->active,
6103 "connector is active, but attached crtc isn't\n");
6105 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6108 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6109 "atomic encoder doesn't match attached encoder\n");
6111 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6112 "attached encoder crtc differs from connector crtc\n");
6114 I915_STATE_WARN(crtc_state && crtc_state->active,
6115 "attached crtc is active, but connector isn't\n");
6116 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6117 "best encoder set without crtc!\n");
6121 int intel_connector_init(struct intel_connector *connector)
6123 struct intel_digital_connector_state *conn_state;
6126 * Allocate enough memory to hold intel_digital_connector_state,
6127 * This might be a few bytes too many, but for connectors that don't
6128 * need it we'll free the state and allocate a smaller one on the first
6129 * succesful commit anyway.
6131 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
6135 __drm_atomic_helper_connector_reset(&connector->base,
6141 struct intel_connector *intel_connector_alloc(void)
6143 struct intel_connector *connector;
6145 connector = kzalloc(sizeof *connector, GFP_KERNEL);
6149 if (intel_connector_init(connector) < 0) {
6158 * Free the bits allocated by intel_connector_alloc.
6159 * This should only be used after intel_connector_alloc has returned
6160 * successfully, and before drm_connector_init returns successfully.
6161 * Otherwise the destroy callbacks for the connector and the state should
6162 * take care of proper cleanup/free
6164 void intel_connector_free(struct intel_connector *connector)
6166 kfree(to_intel_digital_connector_state(connector->base.state));
6170 /* Simple connector->get_hw_state implementation for encoders that support only
6171 * one connector and no cloning and hence the encoder state determines the state
6172 * of the connector. */
6173 bool intel_connector_get_hw_state(struct intel_connector *connector)
6176 struct intel_encoder *encoder = connector->encoder;
6178 return encoder->get_hw_state(encoder, &pipe);
6181 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6183 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6184 return crtc_state->fdi_lanes;
6189 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6190 struct intel_crtc_state *pipe_config)
6192 struct drm_i915_private *dev_priv = to_i915(dev);
6193 struct drm_atomic_state *state = pipe_config->base.state;
6194 struct intel_crtc *other_crtc;
6195 struct intel_crtc_state *other_crtc_state;
6197 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6198 pipe_name(pipe), pipe_config->fdi_lanes);
6199 if (pipe_config->fdi_lanes > 4) {
6200 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6201 pipe_name(pipe), pipe_config->fdi_lanes);
6205 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6206 if (pipe_config->fdi_lanes > 2) {
6207 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6208 pipe_config->fdi_lanes);
6215 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6218 /* Ivybridge 3 pipe is really complicated */
6223 if (pipe_config->fdi_lanes <= 2)
6226 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6228 intel_atomic_get_crtc_state(state, other_crtc);
6229 if (IS_ERR(other_crtc_state))
6230 return PTR_ERR(other_crtc_state);
6232 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6233 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6234 pipe_name(pipe), pipe_config->fdi_lanes);
6239 if (pipe_config->fdi_lanes > 2) {
6240 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6241 pipe_name(pipe), pipe_config->fdi_lanes);
6245 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6247 intel_atomic_get_crtc_state(state, other_crtc);
6248 if (IS_ERR(other_crtc_state))
6249 return PTR_ERR(other_crtc_state);
6251 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6252 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6262 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6263 struct intel_crtc_state *pipe_config)
6265 struct drm_device *dev = intel_crtc->base.dev;
6266 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6267 int lane, link_bw, fdi_dotclock, ret;
6268 bool needs_recompute = false;
6271 /* FDI is a binary signal running at ~2.7GHz, encoding
6272 * each output octet as 10 bits. The actual frequency
6273 * is stored as a divider into a 100MHz clock, and the
6274 * mode pixel clock is stored in units of 1KHz.
6275 * Hence the bw of each lane in terms of the mode signal
6278 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6280 fdi_dotclock = adjusted_mode->crtc_clock;
6282 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6283 pipe_config->pipe_bpp);
6285 pipe_config->fdi_lanes = lane;
6287 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6288 link_bw, &pipe_config->fdi_m_n, false);
6290 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6291 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6292 pipe_config->pipe_bpp -= 2*3;
6293 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6294 pipe_config->pipe_bpp);
6295 needs_recompute = true;
6296 pipe_config->bw_constrained = true;
6301 if (needs_recompute)
6307 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6309 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6310 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6312 /* IPS only exists on ULT machines and is tied to pipe A. */
6313 if (!hsw_crtc_supports_ips(crtc))
6316 if (!i915_modparams.enable_ips)
6319 if (crtc_state->pipe_bpp > 24)
6323 * We compare against max which means we must take
6324 * the increased cdclk requirement into account when
6325 * calculating the new cdclk.
6327 * Should measure whether using a lower cdclk w/o IPS
6329 if (IS_BROADWELL(dev_priv) &&
6330 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6336 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6338 struct drm_i915_private *dev_priv =
6339 to_i915(crtc_state->base.crtc->dev);
6340 struct intel_atomic_state *intel_state =
6341 to_intel_atomic_state(crtc_state->base.state);
6343 if (!hsw_crtc_state_ips_capable(crtc_state))
6346 if (crtc_state->ips_force_disable)
6349 /* IPS should be fine as long as at least one plane is enabled. */
6350 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6353 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6354 if (IS_BROADWELL(dev_priv) &&
6355 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6361 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6363 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6365 /* GDG double wide on either pipe, otherwise pipe A only */
6366 return INTEL_GEN(dev_priv) < 4 &&
6367 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6370 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6372 uint32_t pixel_rate;
6374 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6377 * We only use IF-ID interlacing. If we ever use
6378 * PF-ID we'll need to adjust the pixel_rate here.
6381 if (pipe_config->pch_pfit.enabled) {
6382 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6383 uint32_t pfit_size = pipe_config->pch_pfit.size;
6385 pipe_w = pipe_config->pipe_src_w;
6386 pipe_h = pipe_config->pipe_src_h;
6388 pfit_w = (pfit_size >> 16) & 0xFFFF;
6389 pfit_h = pfit_size & 0xFFFF;
6390 if (pipe_w < pfit_w)
6392 if (pipe_h < pfit_h)
6395 if (WARN_ON(!pfit_w || !pfit_h))
6398 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6405 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6407 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6409 if (HAS_GMCH_DISPLAY(dev_priv))
6410 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6411 crtc_state->pixel_rate =
6412 crtc_state->base.adjusted_mode.crtc_clock;
6414 crtc_state->pixel_rate =
6415 ilk_pipe_pixel_rate(crtc_state);
6418 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6419 struct intel_crtc_state *pipe_config)
6421 struct drm_device *dev = crtc->base.dev;
6422 struct drm_i915_private *dev_priv = to_i915(dev);
6423 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6424 int clock_limit = dev_priv->max_dotclk_freq;
6426 if (INTEL_GEN(dev_priv) < 4) {
6427 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6430 * Enable double wide mode when the dot clock
6431 * is > 90% of the (display) core speed.
6433 if (intel_crtc_supports_double_wide(crtc) &&
6434 adjusted_mode->crtc_clock > clock_limit) {
6435 clock_limit = dev_priv->max_dotclk_freq;
6436 pipe_config->double_wide = true;
6440 if (adjusted_mode->crtc_clock > clock_limit) {
6441 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6442 adjusted_mode->crtc_clock, clock_limit,
6443 yesno(pipe_config->double_wide));
6447 if (pipe_config->ycbcr420 && pipe_config->base.ctm) {
6449 * There is only one pipe CSC unit per pipe, and we need that
6450 * for output conversion from RGB->YCBCR. So if CTM is already
6451 * applied we can't support YCBCR420 output.
6453 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6458 * Pipe horizontal size must be even in:
6460 * - LVDS dual channel mode
6461 * - Double wide pipe
6463 if (pipe_config->pipe_src_w & 1) {
6464 if (pipe_config->double_wide) {
6465 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6469 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6470 intel_is_dual_link_lvds(dev)) {
6471 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6476 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6477 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6479 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6480 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6483 intel_crtc_compute_pixel_rate(pipe_config);
6485 if (pipe_config->has_pch_encoder)
6486 return ironlake_fdi_compute_config(crtc, pipe_config);
6492 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6494 while (*num > DATA_LINK_M_N_MASK ||
6495 *den > DATA_LINK_M_N_MASK) {
6501 static void compute_m_n(unsigned int m, unsigned int n,
6502 uint32_t *ret_m, uint32_t *ret_n,
6506 * Reduce M/N as much as possible without loss in precision. Several DP
6507 * dongles in particular seem to be fussy about too large *link* M/N
6508 * values. The passed in values are more likely to have the least
6509 * significant bits zero than M after rounding below, so do this first.
6512 while ((m & 1) == 0 && (n & 1) == 0) {
6518 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6519 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6520 intel_reduce_m_n_ratio(ret_m, ret_n);
6524 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6525 int pixel_clock, int link_clock,
6526 struct intel_link_m_n *m_n,
6531 compute_m_n(bits_per_pixel * pixel_clock,
6532 link_clock * nlanes * 8,
6533 &m_n->gmch_m, &m_n->gmch_n,
6536 compute_m_n(pixel_clock, link_clock,
6537 &m_n->link_m, &m_n->link_n,
6541 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6543 if (i915_modparams.panel_use_ssc >= 0)
6544 return i915_modparams.panel_use_ssc != 0;
6545 return dev_priv->vbt.lvds_use_ssc
6546 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6549 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
6551 return (1 << dpll->n) << 16 | dpll->m2;
6554 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6556 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
6559 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
6560 struct intel_crtc_state *crtc_state,
6561 struct dpll *reduced_clock)
6563 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6566 if (IS_PINEVIEW(dev_priv)) {
6567 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
6569 fp2 = pnv_dpll_compute_fp(reduced_clock);
6571 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
6573 fp2 = i9xx_dpll_compute_fp(reduced_clock);
6576 crtc_state->dpll_hw_state.fp0 = fp;
6578 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6580 crtc_state->dpll_hw_state.fp1 = fp2;
6582 crtc_state->dpll_hw_state.fp1 = fp;
6586 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6592 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6593 * and set it to a reasonable value instead.
6595 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6596 reg_val &= 0xffffff00;
6597 reg_val |= 0x00000030;
6598 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6600 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6601 reg_val &= 0x00ffffff;
6602 reg_val |= 0x8c000000;
6603 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6605 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6606 reg_val &= 0xffffff00;
6607 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6609 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6610 reg_val &= 0x00ffffff;
6611 reg_val |= 0xb0000000;
6612 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6615 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
6616 struct intel_link_m_n *m_n)
6618 struct drm_device *dev = crtc->base.dev;
6619 struct drm_i915_private *dev_priv = to_i915(dev);
6620 int pipe = crtc->pipe;
6622 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6623 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6624 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6625 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6628 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
6629 struct intel_link_m_n *m_n,
6630 struct intel_link_m_n *m2_n2)
6632 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6633 int pipe = crtc->pipe;
6634 enum transcoder transcoder = crtc->config->cpu_transcoder;
6636 if (INTEL_GEN(dev_priv) >= 5) {
6637 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6638 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6639 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6640 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
6641 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6642 * for gen < 8) and if DRRS is supported (to make sure the
6643 * registers are not unnecessarily accessed).
6645 if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
6646 INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
6647 I915_WRITE(PIPE_DATA_M2(transcoder),
6648 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6649 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6650 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6651 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6654 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6655 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6656 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6657 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
6661 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
6663 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6666 dp_m_n = &crtc->config->dp_m_n;
6667 dp_m2_n2 = &crtc->config->dp_m2_n2;
6668 } else if (m_n == M2_N2) {
6671 * M2_N2 registers are not supported. Hence m2_n2 divider value
6672 * needs to be programmed into M1_N1.
6674 dp_m_n = &crtc->config->dp_m2_n2;
6676 DRM_ERROR("Unsupported divider value\n");
6680 if (crtc->config->has_pch_encoder)
6681 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
6683 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
6686 static void vlv_compute_dpll(struct intel_crtc *crtc,
6687 struct intel_crtc_state *pipe_config)
6689 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
6690 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6691 if (crtc->pipe != PIPE_A)
6692 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6694 /* DPLL not used with DSI, but still need the rest set up */
6695 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6696 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6697 DPLL_EXT_BUFFER_ENABLE_VLV;
6699 pipe_config->dpll_hw_state.dpll_md =
6700 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6703 static void chv_compute_dpll(struct intel_crtc *crtc,
6704 struct intel_crtc_state *pipe_config)
6706 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
6707 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6708 if (crtc->pipe != PIPE_A)
6709 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6711 /* DPLL not used with DSI, but still need the rest set up */
6712 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6713 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6715 pipe_config->dpll_hw_state.dpll_md =
6716 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6719 static void vlv_prepare_pll(struct intel_crtc *crtc,
6720 const struct intel_crtc_state *pipe_config)
6722 struct drm_device *dev = crtc->base.dev;
6723 struct drm_i915_private *dev_priv = to_i915(dev);
6724 enum pipe pipe = crtc->pipe;
6726 u32 bestn, bestm1, bestm2, bestp1, bestp2;
6727 u32 coreclk, reg_val;
6730 I915_WRITE(DPLL(pipe),
6731 pipe_config->dpll_hw_state.dpll &
6732 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6734 /* No need to actually set up the DPLL with DSI */
6735 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6738 mutex_lock(&dev_priv->sb_lock);
6740 bestn = pipe_config->dpll.n;
6741 bestm1 = pipe_config->dpll.m1;
6742 bestm2 = pipe_config->dpll.m2;
6743 bestp1 = pipe_config->dpll.p1;
6744 bestp2 = pipe_config->dpll.p2;
6746 /* See eDP HDMI DPIO driver vbios notes doc */
6748 /* PLL B needs special handling */
6750 vlv_pllb_recal_opamp(dev_priv, pipe);
6752 /* Set up Tx target for periodic Rcomp update */
6753 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
6755 /* Disable target IRef on PLL */
6756 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
6757 reg_val &= 0x00ffffff;
6758 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
6760 /* Disable fast lock */
6761 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
6763 /* Set idtafcrecal before PLL is enabled */
6764 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6765 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6766 mdiv |= ((bestn << DPIO_N_SHIFT));
6767 mdiv |= (1 << DPIO_K_SHIFT);
6770 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6771 * but we don't support that).
6772 * Note: don't use the DAC post divider as it seems unstable.
6774 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
6775 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6777 mdiv |= DPIO_ENABLE_CALIBRATION;
6778 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6780 /* Set HBR and RBR LPF coefficients */
6781 if (pipe_config->port_clock == 162000 ||
6782 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) ||
6783 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI))
6784 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6787 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6790 if (intel_crtc_has_dp_encoder(pipe_config)) {
6791 /* Use SSC source */
6793 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6796 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6798 } else { /* HDMI or VGA */
6799 /* Use bend source */
6801 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6804 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6808 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
6809 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
6810 if (intel_crtc_has_dp_encoder(crtc->config))
6811 coreclk |= 0x01000000;
6812 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
6814 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
6815 mutex_unlock(&dev_priv->sb_lock);
6818 static void chv_prepare_pll(struct intel_crtc *crtc,
6819 const struct intel_crtc_state *pipe_config)
6821 struct drm_device *dev = crtc->base.dev;
6822 struct drm_i915_private *dev_priv = to_i915(dev);
6823 enum pipe pipe = crtc->pipe;
6824 enum dpio_channel port = vlv_pipe_to_channel(pipe);
6825 u32 loopfilter, tribuf_calcntr;
6826 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
6830 /* Enable Refclk and SSC */
6831 I915_WRITE(DPLL(pipe),
6832 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
6834 /* No need to actually set up the DPLL with DSI */
6835 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6838 bestn = pipe_config->dpll.n;
6839 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
6840 bestm1 = pipe_config->dpll.m1;
6841 bestm2 = pipe_config->dpll.m2 >> 22;
6842 bestp1 = pipe_config->dpll.p1;
6843 bestp2 = pipe_config->dpll.p2;
6844 vco = pipe_config->dpll.vco;
6848 mutex_lock(&dev_priv->sb_lock);
6850 /* p1 and p2 divider */
6851 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
6852 5 << DPIO_CHV_S1_DIV_SHIFT |
6853 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
6854 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
6855 1 << DPIO_CHV_K_DIV_SHIFT);
6857 /* Feedback post-divider - m2 */
6858 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
6860 /* Feedback refclk divider - n and m1 */
6861 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
6862 DPIO_CHV_M1_DIV_BY_2 |
6863 1 << DPIO_CHV_N_DIV_SHIFT);
6865 /* M2 fraction division */
6866 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
6868 /* M2 fraction division enable */
6869 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
6870 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
6871 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
6873 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
6874 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
6876 /* Program digital lock detect threshold */
6877 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
6878 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
6879 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
6880 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
6882 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
6883 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
6886 if (vco == 5400000) {
6887 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
6888 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
6889 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
6890 tribuf_calcntr = 0x9;
6891 } else if (vco <= 6200000) {
6892 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
6893 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
6894 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6895 tribuf_calcntr = 0x9;
6896 } else if (vco <= 6480000) {
6897 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
6898 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
6899 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6900 tribuf_calcntr = 0x8;
6902 /* Not supported. Apply the same limits as in the max case */
6903 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
6904 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
6905 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6908 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
6910 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
6911 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
6912 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
6913 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
6916 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
6917 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
6920 mutex_unlock(&dev_priv->sb_lock);
6924 * vlv_force_pll_on - forcibly enable just the PLL
6925 * @dev_priv: i915 private structure
6926 * @pipe: pipe PLL to enable
6927 * @dpll: PLL configuration
6929 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6930 * in cases where we need the PLL enabled even when @pipe is not going to
6933 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
6934 const struct dpll *dpll)
6936 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
6937 struct intel_crtc_state *pipe_config;
6939 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
6943 pipe_config->base.crtc = &crtc->base;
6944 pipe_config->pixel_multiplier = 1;
6945 pipe_config->dpll = *dpll;
6947 if (IS_CHERRYVIEW(dev_priv)) {
6948 chv_compute_dpll(crtc, pipe_config);
6949 chv_prepare_pll(crtc, pipe_config);
6950 chv_enable_pll(crtc, pipe_config);
6952 vlv_compute_dpll(crtc, pipe_config);
6953 vlv_prepare_pll(crtc, pipe_config);
6954 vlv_enable_pll(crtc, pipe_config);
6963 * vlv_force_pll_off - forcibly disable just the PLL
6964 * @dev_priv: i915 private structure
6965 * @pipe: pipe PLL to disable
6967 * Disable the PLL for @pipe. To be used in cases where we need
6968 * the PLL enabled even when @pipe is not going to be enabled.
6970 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
6972 if (IS_CHERRYVIEW(dev_priv))
6973 chv_disable_pll(dev_priv, pipe);
6975 vlv_disable_pll(dev_priv, pipe);
6978 static void i9xx_compute_dpll(struct intel_crtc *crtc,
6979 struct intel_crtc_state *crtc_state,
6980 struct dpll *reduced_clock)
6982 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6984 struct dpll *clock = &crtc_state->dpll;
6986 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
6988 dpll = DPLL_VGA_MODE_DIS;
6990 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
6991 dpll |= DPLLB_MODE_LVDS;
6993 dpll |= DPLLB_MODE_DAC_SERIAL;
6995 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
6996 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
6997 dpll |= (crtc_state->pixel_multiplier - 1)
6998 << SDVO_MULTIPLIER_SHIFT_HIRES;
7001 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7002 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7003 dpll |= DPLL_SDVO_HIGH_SPEED;
7005 if (intel_crtc_has_dp_encoder(crtc_state))
7006 dpll |= DPLL_SDVO_HIGH_SPEED;
7008 /* compute bitmask from p1 value */
7009 if (IS_PINEVIEW(dev_priv))
7010 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7012 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7013 if (IS_G4X(dev_priv) && reduced_clock)
7014 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7016 switch (clock->p2) {
7018 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7021 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7024 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7027 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7030 if (INTEL_GEN(dev_priv) >= 4)
7031 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7033 if (crtc_state->sdvo_tv_clock)
7034 dpll |= PLL_REF_INPUT_TVCLKINBC;
7035 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7036 intel_panel_use_ssc(dev_priv))
7037 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7039 dpll |= PLL_REF_INPUT_DREFCLK;
7041 dpll |= DPLL_VCO_ENABLE;
7042 crtc_state->dpll_hw_state.dpll = dpll;
7044 if (INTEL_GEN(dev_priv) >= 4) {
7045 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7046 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7047 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7051 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7052 struct intel_crtc_state *crtc_state,
7053 struct dpll *reduced_clock)
7055 struct drm_device *dev = crtc->base.dev;
7056 struct drm_i915_private *dev_priv = to_i915(dev);
7058 struct dpll *clock = &crtc_state->dpll;
7060 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7062 dpll = DPLL_VGA_MODE_DIS;
7064 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7065 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7068 dpll |= PLL_P1_DIVIDE_BY_TWO;
7070 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7072 dpll |= PLL_P2_DIVIDE_BY_4;
7075 if (!IS_I830(dev_priv) &&
7076 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7077 dpll |= DPLL_DVO_2X_MODE;
7079 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7080 intel_panel_use_ssc(dev_priv))
7081 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7083 dpll |= PLL_REF_INPUT_DREFCLK;
7085 dpll |= DPLL_VCO_ENABLE;
7086 crtc_state->dpll_hw_state.dpll = dpll;
7089 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
7091 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7092 enum pipe pipe = intel_crtc->pipe;
7093 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
7094 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
7095 uint32_t crtc_vtotal, crtc_vblank_end;
7098 /* We need to be careful not to changed the adjusted mode, for otherwise
7099 * the hw state checker will get angry at the mismatch. */
7100 crtc_vtotal = adjusted_mode->crtc_vtotal;
7101 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7103 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7104 /* the chip adds 2 halflines automatically */
7106 crtc_vblank_end -= 1;
7108 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7109 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7111 vsyncshift = adjusted_mode->crtc_hsync_start -
7112 adjusted_mode->crtc_htotal / 2;
7114 vsyncshift += adjusted_mode->crtc_htotal;
7117 if (INTEL_GEN(dev_priv) > 3)
7118 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7120 I915_WRITE(HTOTAL(cpu_transcoder),
7121 (adjusted_mode->crtc_hdisplay - 1) |
7122 ((adjusted_mode->crtc_htotal - 1) << 16));
7123 I915_WRITE(HBLANK(cpu_transcoder),
7124 (adjusted_mode->crtc_hblank_start - 1) |
7125 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7126 I915_WRITE(HSYNC(cpu_transcoder),
7127 (adjusted_mode->crtc_hsync_start - 1) |
7128 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7130 I915_WRITE(VTOTAL(cpu_transcoder),
7131 (adjusted_mode->crtc_vdisplay - 1) |
7132 ((crtc_vtotal - 1) << 16));
7133 I915_WRITE(VBLANK(cpu_transcoder),
7134 (adjusted_mode->crtc_vblank_start - 1) |
7135 ((crtc_vblank_end - 1) << 16));
7136 I915_WRITE(VSYNC(cpu_transcoder),
7137 (adjusted_mode->crtc_vsync_start - 1) |
7138 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7140 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7141 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7142 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7144 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7145 (pipe == PIPE_B || pipe == PIPE_C))
7146 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7150 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc)
7152 struct drm_device *dev = intel_crtc->base.dev;
7153 struct drm_i915_private *dev_priv = to_i915(dev);
7154 enum pipe pipe = intel_crtc->pipe;
7156 /* pipesrc controls the size that is scaled from, which should
7157 * always be the user's requested size.
7159 I915_WRITE(PIPESRC(pipe),
7160 ((intel_crtc->config->pipe_src_w - 1) << 16) |
7161 (intel_crtc->config->pipe_src_h - 1));
7164 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7165 struct intel_crtc_state *pipe_config)
7167 struct drm_device *dev = crtc->base.dev;
7168 struct drm_i915_private *dev_priv = to_i915(dev);
7169 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7172 tmp = I915_READ(HTOTAL(cpu_transcoder));
7173 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7174 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7175 tmp = I915_READ(HBLANK(cpu_transcoder));
7176 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7177 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7178 tmp = I915_READ(HSYNC(cpu_transcoder));
7179 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7180 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7182 tmp = I915_READ(VTOTAL(cpu_transcoder));
7183 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7184 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7185 tmp = I915_READ(VBLANK(cpu_transcoder));
7186 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7187 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7188 tmp = I915_READ(VSYNC(cpu_transcoder));
7189 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7190 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7192 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7193 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7194 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7195 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7199 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7200 struct intel_crtc_state *pipe_config)
7202 struct drm_device *dev = crtc->base.dev;
7203 struct drm_i915_private *dev_priv = to_i915(dev);
7206 tmp = I915_READ(PIPESRC(crtc->pipe));
7207 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7208 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7210 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7211 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7214 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7215 struct intel_crtc_state *pipe_config)
7217 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7218 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7219 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7220 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7222 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7223 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7224 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7225 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7227 mode->flags = pipe_config->base.adjusted_mode.flags;
7228 mode->type = DRM_MODE_TYPE_DRIVER;
7230 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7232 mode->hsync = drm_mode_hsync(mode);
7233 mode->vrefresh = drm_mode_vrefresh(mode);
7234 drm_mode_set_name(mode);
7237 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
7239 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7244 /* we keep both pipes enabled on 830 */
7245 if (IS_I830(dev_priv))
7246 pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
7248 if (intel_crtc->config->double_wide)
7249 pipeconf |= PIPECONF_DOUBLE_WIDE;
7251 /* only g4x and later have fancy bpc/dither controls */
7252 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7253 IS_CHERRYVIEW(dev_priv)) {
7254 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7255 if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
7256 pipeconf |= PIPECONF_DITHER_EN |
7257 PIPECONF_DITHER_TYPE_SP;
7259 switch (intel_crtc->config->pipe_bpp) {
7261 pipeconf |= PIPECONF_6BPC;
7264 pipeconf |= PIPECONF_8BPC;
7267 pipeconf |= PIPECONF_10BPC;
7270 /* Case prevented by intel_choose_pipe_bpp_dither. */
7275 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7276 if (INTEL_GEN(dev_priv) < 4 ||
7277 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7278 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7280 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7282 pipeconf |= PIPECONF_PROGRESSIVE;
7284 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7285 intel_crtc->config->limited_color_range)
7286 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7288 I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
7289 POSTING_READ(PIPECONF(intel_crtc->pipe));
7292 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7293 struct intel_crtc_state *crtc_state)
7295 struct drm_device *dev = crtc->base.dev;
7296 struct drm_i915_private *dev_priv = to_i915(dev);
7297 const struct intel_limit *limit;
7300 memset(&crtc_state->dpll_hw_state, 0,
7301 sizeof(crtc_state->dpll_hw_state));
7303 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7304 if (intel_panel_use_ssc(dev_priv)) {
7305 refclk = dev_priv->vbt.lvds_ssc_freq;
7306 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7309 limit = &intel_limits_i8xx_lvds;
7310 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7311 limit = &intel_limits_i8xx_dvo;
7313 limit = &intel_limits_i8xx_dac;
7316 if (!crtc_state->clock_set &&
7317 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7318 refclk, NULL, &crtc_state->dpll)) {
7319 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7323 i8xx_compute_dpll(crtc, crtc_state, NULL);
7328 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7329 struct intel_crtc_state *crtc_state)
7331 struct drm_device *dev = crtc->base.dev;
7332 struct drm_i915_private *dev_priv = to_i915(dev);
7333 const struct intel_limit *limit;
7336 memset(&crtc_state->dpll_hw_state, 0,
7337 sizeof(crtc_state->dpll_hw_state));
7339 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7340 if (intel_panel_use_ssc(dev_priv)) {
7341 refclk = dev_priv->vbt.lvds_ssc_freq;
7342 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7345 if (intel_is_dual_link_lvds(dev))
7346 limit = &intel_limits_g4x_dual_channel_lvds;
7348 limit = &intel_limits_g4x_single_channel_lvds;
7349 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7350 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7351 limit = &intel_limits_g4x_hdmi;
7352 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7353 limit = &intel_limits_g4x_sdvo;
7355 /* The option is for other outputs */
7356 limit = &intel_limits_i9xx_sdvo;
7359 if (!crtc_state->clock_set &&
7360 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7361 refclk, NULL, &crtc_state->dpll)) {
7362 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7366 i9xx_compute_dpll(crtc, crtc_state, NULL);
7371 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7372 struct intel_crtc_state *crtc_state)
7374 struct drm_device *dev = crtc->base.dev;
7375 struct drm_i915_private *dev_priv = to_i915(dev);
7376 const struct intel_limit *limit;
7379 memset(&crtc_state->dpll_hw_state, 0,
7380 sizeof(crtc_state->dpll_hw_state));
7382 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7383 if (intel_panel_use_ssc(dev_priv)) {
7384 refclk = dev_priv->vbt.lvds_ssc_freq;
7385 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7388 limit = &intel_limits_pineview_lvds;
7390 limit = &intel_limits_pineview_sdvo;
7393 if (!crtc_state->clock_set &&
7394 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7395 refclk, NULL, &crtc_state->dpll)) {
7396 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7400 i9xx_compute_dpll(crtc, crtc_state, NULL);
7405 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7406 struct intel_crtc_state *crtc_state)
7408 struct drm_device *dev = crtc->base.dev;
7409 struct drm_i915_private *dev_priv = to_i915(dev);
7410 const struct intel_limit *limit;
7413 memset(&crtc_state->dpll_hw_state, 0,
7414 sizeof(crtc_state->dpll_hw_state));
7416 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7417 if (intel_panel_use_ssc(dev_priv)) {
7418 refclk = dev_priv->vbt.lvds_ssc_freq;
7419 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7422 limit = &intel_limits_i9xx_lvds;
7424 limit = &intel_limits_i9xx_sdvo;
7427 if (!crtc_state->clock_set &&
7428 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7429 refclk, NULL, &crtc_state->dpll)) {
7430 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7434 i9xx_compute_dpll(crtc, crtc_state, NULL);
7439 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7440 struct intel_crtc_state *crtc_state)
7442 int refclk = 100000;
7443 const struct intel_limit *limit = &intel_limits_chv;
7445 memset(&crtc_state->dpll_hw_state, 0,
7446 sizeof(crtc_state->dpll_hw_state));
7448 if (!crtc_state->clock_set &&
7449 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7450 refclk, NULL, &crtc_state->dpll)) {
7451 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7455 chv_compute_dpll(crtc, crtc_state);
7460 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7461 struct intel_crtc_state *crtc_state)
7463 int refclk = 100000;
7464 const struct intel_limit *limit = &intel_limits_vlv;
7466 memset(&crtc_state->dpll_hw_state, 0,
7467 sizeof(crtc_state->dpll_hw_state));
7469 if (!crtc_state->clock_set &&
7470 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7471 refclk, NULL, &crtc_state->dpll)) {
7472 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7476 vlv_compute_dpll(crtc, crtc_state);
7481 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7482 struct intel_crtc_state *pipe_config)
7484 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7487 if (INTEL_GEN(dev_priv) <= 3 &&
7488 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7491 tmp = I915_READ(PFIT_CONTROL);
7492 if (!(tmp & PFIT_ENABLE))
7495 /* Check whether the pfit is attached to our pipe. */
7496 if (INTEL_GEN(dev_priv) < 4) {
7497 if (crtc->pipe != PIPE_B)
7500 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7504 pipe_config->gmch_pfit.control = tmp;
7505 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7508 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7509 struct intel_crtc_state *pipe_config)
7511 struct drm_device *dev = crtc->base.dev;
7512 struct drm_i915_private *dev_priv = to_i915(dev);
7513 int pipe = pipe_config->cpu_transcoder;
7516 int refclk = 100000;
7518 /* In case of DSI, DPLL will not be used */
7519 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7522 mutex_lock(&dev_priv->sb_lock);
7523 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7524 mutex_unlock(&dev_priv->sb_lock);
7526 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7527 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7528 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7529 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7530 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7532 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7536 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7537 struct intel_initial_plane_config *plane_config)
7539 struct drm_device *dev = crtc->base.dev;
7540 struct drm_i915_private *dev_priv = to_i915(dev);
7541 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7542 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7543 enum pipe pipe = crtc->pipe;
7544 u32 val, base, offset;
7545 int fourcc, pixel_format;
7546 unsigned int aligned_height;
7547 struct drm_framebuffer *fb;
7548 struct intel_framebuffer *intel_fb;
7550 if (!plane->get_hw_state(plane))
7553 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7555 DRM_DEBUG_KMS("failed to alloc fb\n");
7559 fb = &intel_fb->base;
7563 val = I915_READ(DSPCNTR(i9xx_plane));
7565 if (INTEL_GEN(dev_priv) >= 4) {
7566 if (val & DISPPLANE_TILED) {
7567 plane_config->tiling = I915_TILING_X;
7568 fb->modifier = I915_FORMAT_MOD_X_TILED;
7572 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7573 fourcc = i9xx_format_to_fourcc(pixel_format);
7574 fb->format = drm_format_info(fourcc);
7576 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7577 offset = I915_READ(DSPOFFSET(i9xx_plane));
7578 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7579 } else if (INTEL_GEN(dev_priv) >= 4) {
7580 if (plane_config->tiling)
7581 offset = I915_READ(DSPTILEOFF(i9xx_plane));
7583 offset = I915_READ(DSPLINOFF(i9xx_plane));
7584 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7586 base = I915_READ(DSPADDR(i9xx_plane));
7588 plane_config->base = base;
7590 val = I915_READ(PIPESRC(pipe));
7591 fb->width = ((val >> 16) & 0xfff) + 1;
7592 fb->height = ((val >> 0) & 0xfff) + 1;
7594 val = I915_READ(DSPSTRIDE(i9xx_plane));
7595 fb->pitches[0] = val & 0xffffffc0;
7597 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7599 plane_config->size = fb->pitches[0] * aligned_height;
7601 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7602 crtc->base.name, plane->base.name, fb->width, fb->height,
7603 fb->format->cpp[0] * 8, base, fb->pitches[0],
7604 plane_config->size);
7606 plane_config->fb = intel_fb;
7609 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7610 struct intel_crtc_state *pipe_config)
7612 struct drm_device *dev = crtc->base.dev;
7613 struct drm_i915_private *dev_priv = to_i915(dev);
7614 int pipe = pipe_config->cpu_transcoder;
7615 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7617 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7618 int refclk = 100000;
7620 /* In case of DSI, DPLL will not be used */
7621 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7624 mutex_lock(&dev_priv->sb_lock);
7625 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7626 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7627 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7628 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7629 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7630 mutex_unlock(&dev_priv->sb_lock);
7632 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7633 clock.m2 = (pll_dw0 & 0xff) << 22;
7634 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7635 clock.m2 |= pll_dw2 & 0x3fffff;
7636 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7637 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7638 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7640 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7643 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7644 struct intel_crtc_state *pipe_config)
7646 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7647 enum intel_display_power_domain power_domain;
7651 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7652 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7655 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7656 pipe_config->shared_dpll = NULL;
7660 tmp = I915_READ(PIPECONF(crtc->pipe));
7661 if (!(tmp & PIPECONF_ENABLE))
7664 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7665 IS_CHERRYVIEW(dev_priv)) {
7666 switch (tmp & PIPECONF_BPC_MASK) {
7668 pipe_config->pipe_bpp = 18;
7671 pipe_config->pipe_bpp = 24;
7673 case PIPECONF_10BPC:
7674 pipe_config->pipe_bpp = 30;
7681 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7682 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7683 pipe_config->limited_color_range = true;
7685 if (INTEL_GEN(dev_priv) < 4)
7686 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7688 intel_get_pipe_timings(crtc, pipe_config);
7689 intel_get_pipe_src_size(crtc, pipe_config);
7691 i9xx_get_pfit_config(crtc, pipe_config);
7693 if (INTEL_GEN(dev_priv) >= 4) {
7694 /* No way to read it out on pipes B and C */
7695 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
7696 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7698 tmp = I915_READ(DPLL_MD(crtc->pipe));
7699 pipe_config->pixel_multiplier =
7700 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7701 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
7702 pipe_config->dpll_hw_state.dpll_md = tmp;
7703 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7704 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7705 tmp = I915_READ(DPLL(crtc->pipe));
7706 pipe_config->pixel_multiplier =
7707 ((tmp & SDVO_MULTIPLIER_MASK)
7708 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7710 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7711 * port and will be fixed up in the encoder->get_config
7713 pipe_config->pixel_multiplier = 1;
7715 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
7716 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
7718 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7719 * on 830. Filter it out here so that we don't
7720 * report errors due to that.
7722 if (IS_I830(dev_priv))
7723 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
7725 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
7726 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
7728 /* Mask out read-only status bits. */
7729 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7730 DPLL_PORTC_READY_MASK |
7731 DPLL_PORTB_READY_MASK);
7734 if (IS_CHERRYVIEW(dev_priv))
7735 chv_crtc_clock_get(crtc, pipe_config);
7736 else if (IS_VALLEYVIEW(dev_priv))
7737 vlv_crtc_clock_get(crtc, pipe_config);
7739 i9xx_crtc_clock_get(crtc, pipe_config);
7742 * Normally the dotclock is filled in by the encoder .get_config()
7743 * but in case the pipe is enabled w/o any ports we need a sane
7746 pipe_config->base.adjusted_mode.crtc_clock =
7747 pipe_config->port_clock / pipe_config->pixel_multiplier;
7752 intel_display_power_put(dev_priv, power_domain);
7757 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
7759 struct intel_encoder *encoder;
7762 bool has_lvds = false;
7763 bool has_cpu_edp = false;
7764 bool has_panel = false;
7765 bool has_ck505 = false;
7766 bool can_ssc = false;
7767 bool using_ssc_source = false;
7769 /* We need to take the global config into account */
7770 for_each_intel_encoder(&dev_priv->drm, encoder) {
7771 switch (encoder->type) {
7772 case INTEL_OUTPUT_LVDS:
7776 case INTEL_OUTPUT_EDP:
7778 if (encoder->port == PORT_A)
7786 if (HAS_PCH_IBX(dev_priv)) {
7787 has_ck505 = dev_priv->vbt.display_clock_mode;
7788 can_ssc = has_ck505;
7794 /* Check if any DPLLs are using the SSC source */
7795 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
7796 u32 temp = I915_READ(PCH_DPLL(i));
7798 if (!(temp & DPLL_VCO_ENABLE))
7801 if ((temp & PLL_REF_INPUT_MASK) ==
7802 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
7803 using_ssc_source = true;
7808 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7809 has_panel, has_lvds, has_ck505, using_ssc_source);
7811 /* Ironlake: try to setup display ref clock before DPLL
7812 * enabling. This is only under driver's control after
7813 * PCH B stepping, previous chipset stepping should be
7814 * ignoring this setting.
7816 val = I915_READ(PCH_DREF_CONTROL);
7818 /* As we must carefully and slowly disable/enable each source in turn,
7819 * compute the final state we want first and check if we need to
7820 * make any changes at all.
7823 final &= ~DREF_NONSPREAD_SOURCE_MASK;
7825 final |= DREF_NONSPREAD_CK505_ENABLE;
7827 final |= DREF_NONSPREAD_SOURCE_ENABLE;
7829 final &= ~DREF_SSC_SOURCE_MASK;
7830 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7831 final &= ~DREF_SSC1_ENABLE;
7834 final |= DREF_SSC_SOURCE_ENABLE;
7836 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7837 final |= DREF_SSC1_ENABLE;
7840 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7841 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7843 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7845 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7846 } else if (using_ssc_source) {
7847 final |= DREF_SSC_SOURCE_ENABLE;
7848 final |= DREF_SSC1_ENABLE;
7854 /* Always enable nonspread source */
7855 val &= ~DREF_NONSPREAD_SOURCE_MASK;
7858 val |= DREF_NONSPREAD_CK505_ENABLE;
7860 val |= DREF_NONSPREAD_SOURCE_ENABLE;
7863 val &= ~DREF_SSC_SOURCE_MASK;
7864 val |= DREF_SSC_SOURCE_ENABLE;
7866 /* SSC must be turned on before enabling the CPU output */
7867 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
7868 DRM_DEBUG_KMS("Using SSC on panel\n");
7869 val |= DREF_SSC1_ENABLE;
7871 val &= ~DREF_SSC1_ENABLE;
7873 /* Get SSC going before enabling the outputs */
7874 I915_WRITE(PCH_DREF_CONTROL, val);
7875 POSTING_READ(PCH_DREF_CONTROL);
7878 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7880 /* Enable CPU source on CPU attached eDP */
7882 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
7883 DRM_DEBUG_KMS("Using SSC on eDP\n");
7884 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7886 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7888 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7890 I915_WRITE(PCH_DREF_CONTROL, val);
7891 POSTING_READ(PCH_DREF_CONTROL);
7894 DRM_DEBUG_KMS("Disabling CPU source output\n");
7896 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7898 /* Turn off CPU output */
7899 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7901 I915_WRITE(PCH_DREF_CONTROL, val);
7902 POSTING_READ(PCH_DREF_CONTROL);
7905 if (!using_ssc_source) {
7906 DRM_DEBUG_KMS("Disabling SSC source\n");
7908 /* Turn off the SSC source */
7909 val &= ~DREF_SSC_SOURCE_MASK;
7910 val |= DREF_SSC_SOURCE_DISABLE;
7913 val &= ~DREF_SSC1_ENABLE;
7915 I915_WRITE(PCH_DREF_CONTROL, val);
7916 POSTING_READ(PCH_DREF_CONTROL);
7921 BUG_ON(val != final);
7924 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
7928 tmp = I915_READ(SOUTH_CHICKEN2);
7929 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
7930 I915_WRITE(SOUTH_CHICKEN2, tmp);
7932 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
7933 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
7934 DRM_ERROR("FDI mPHY reset assert timeout\n");
7936 tmp = I915_READ(SOUTH_CHICKEN2);
7937 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
7938 I915_WRITE(SOUTH_CHICKEN2, tmp);
7940 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
7941 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
7942 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7945 /* WaMPhyProgramming:hsw */
7946 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
7950 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
7951 tmp &= ~(0xFF << 24);
7952 tmp |= (0x12 << 24);
7953 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
7955 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
7957 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
7959 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
7961 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
7963 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
7964 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
7965 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
7967 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
7968 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
7969 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
7971 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
7974 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
7976 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
7979 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
7981 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
7984 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
7986 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
7989 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
7991 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
7992 tmp &= ~(0xFF << 16);
7993 tmp |= (0x1C << 16);
7994 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
7996 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
7997 tmp &= ~(0xFF << 16);
7998 tmp |= (0x1C << 16);
7999 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8001 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8003 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8005 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8007 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8009 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8010 tmp &= ~(0xF << 28);
8012 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8014 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8015 tmp &= ~(0xF << 28);
8017 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8020 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8021 * Programming" based on the parameters passed:
8022 * - Sequence to enable CLKOUT_DP
8023 * - Sequence to enable CLKOUT_DP without spread
8024 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8026 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8027 bool with_spread, bool with_fdi)
8031 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8033 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8034 with_fdi, "LP PCH doesn't have FDI\n"))
8037 mutex_lock(&dev_priv->sb_lock);
8039 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8040 tmp &= ~SBI_SSCCTL_DISABLE;
8041 tmp |= SBI_SSCCTL_PATHALT;
8042 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8047 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8048 tmp &= ~SBI_SSCCTL_PATHALT;
8049 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8052 lpt_reset_fdi_mphy(dev_priv);
8053 lpt_program_fdi_mphy(dev_priv);
8057 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8058 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8059 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8060 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8062 mutex_unlock(&dev_priv->sb_lock);
8065 /* Sequence to disable CLKOUT_DP */
8066 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8070 mutex_lock(&dev_priv->sb_lock);
8072 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8073 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8074 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8075 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8077 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8078 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8079 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8080 tmp |= SBI_SSCCTL_PATHALT;
8081 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8084 tmp |= SBI_SSCCTL_DISABLE;
8085 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8088 mutex_unlock(&dev_priv->sb_lock);
8091 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8093 static const uint16_t sscdivintphase[] = {
8094 [BEND_IDX( 50)] = 0x3B23,
8095 [BEND_IDX( 45)] = 0x3B23,
8096 [BEND_IDX( 40)] = 0x3C23,
8097 [BEND_IDX( 35)] = 0x3C23,
8098 [BEND_IDX( 30)] = 0x3D23,
8099 [BEND_IDX( 25)] = 0x3D23,
8100 [BEND_IDX( 20)] = 0x3E23,
8101 [BEND_IDX( 15)] = 0x3E23,
8102 [BEND_IDX( 10)] = 0x3F23,
8103 [BEND_IDX( 5)] = 0x3F23,
8104 [BEND_IDX( 0)] = 0x0025,
8105 [BEND_IDX( -5)] = 0x0025,
8106 [BEND_IDX(-10)] = 0x0125,
8107 [BEND_IDX(-15)] = 0x0125,
8108 [BEND_IDX(-20)] = 0x0225,
8109 [BEND_IDX(-25)] = 0x0225,
8110 [BEND_IDX(-30)] = 0x0325,
8111 [BEND_IDX(-35)] = 0x0325,
8112 [BEND_IDX(-40)] = 0x0425,
8113 [BEND_IDX(-45)] = 0x0425,
8114 [BEND_IDX(-50)] = 0x0525,
8119 * steps -50 to 50 inclusive, in steps of 5
8120 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8121 * change in clock period = -(steps / 10) * 5.787 ps
8123 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8126 int idx = BEND_IDX(steps);
8128 if (WARN_ON(steps % 5 != 0))
8131 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8134 mutex_lock(&dev_priv->sb_lock);
8136 if (steps % 10 != 0)
8140 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8142 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8144 tmp |= sscdivintphase[idx];
8145 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8147 mutex_unlock(&dev_priv->sb_lock);
8152 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8154 struct intel_encoder *encoder;
8155 bool has_vga = false;
8157 for_each_intel_encoder(&dev_priv->drm, encoder) {
8158 switch (encoder->type) {
8159 case INTEL_OUTPUT_ANALOG:
8168 lpt_bend_clkout_dp(dev_priv, 0);
8169 lpt_enable_clkout_dp(dev_priv, true, true);
8171 lpt_disable_clkout_dp(dev_priv);
8176 * Initialize reference clocks when the driver loads
8178 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8180 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8181 ironlake_init_pch_refclk(dev_priv);
8182 else if (HAS_PCH_LPT(dev_priv))
8183 lpt_init_pch_refclk(dev_priv);
8186 static void ironlake_set_pipeconf(struct drm_crtc *crtc)
8188 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8189 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8190 int pipe = intel_crtc->pipe;
8195 switch (intel_crtc->config->pipe_bpp) {
8197 val |= PIPECONF_6BPC;
8200 val |= PIPECONF_8BPC;
8203 val |= PIPECONF_10BPC;
8206 val |= PIPECONF_12BPC;
8209 /* Case prevented by intel_choose_pipe_bpp_dither. */
8213 if (intel_crtc->config->dither)
8214 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8216 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8217 val |= PIPECONF_INTERLACED_ILK;
8219 val |= PIPECONF_PROGRESSIVE;
8221 if (intel_crtc->config->limited_color_range)
8222 val |= PIPECONF_COLOR_RANGE_SELECT;
8224 I915_WRITE(PIPECONF(pipe), val);
8225 POSTING_READ(PIPECONF(pipe));
8228 static void haswell_set_pipeconf(struct drm_crtc *crtc)
8230 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8231 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8232 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
8235 if (IS_HASWELL(dev_priv) && intel_crtc->config->dither)
8236 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8238 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8239 val |= PIPECONF_INTERLACED_ILK;
8241 val |= PIPECONF_PROGRESSIVE;
8243 I915_WRITE(PIPECONF(cpu_transcoder), val);
8244 POSTING_READ(PIPECONF(cpu_transcoder));
8247 static void haswell_set_pipemisc(struct drm_crtc *crtc)
8249 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8250 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8251 struct intel_crtc_state *config = intel_crtc->config;
8253 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8256 switch (intel_crtc->config->pipe_bpp) {
8258 val |= PIPEMISC_DITHER_6_BPC;
8261 val |= PIPEMISC_DITHER_8_BPC;
8264 val |= PIPEMISC_DITHER_10_BPC;
8267 val |= PIPEMISC_DITHER_12_BPC;
8270 /* Case prevented by pipe_config_set_bpp. */
8274 if (intel_crtc->config->dither)
8275 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8277 if (config->ycbcr420) {
8278 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV |
8279 PIPEMISC_YUV420_ENABLE |
8280 PIPEMISC_YUV420_MODE_FULL_BLEND;
8283 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8287 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8290 * Account for spread spectrum to avoid
8291 * oversubscribing the link. Max center spread
8292 * is 2.5%; use 5% for safety's sake.
8294 u32 bps = target_clock * bpp * 21 / 20;
8295 return DIV_ROUND_UP(bps, link_bw * 8);
8298 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8300 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8303 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8304 struct intel_crtc_state *crtc_state,
8305 struct dpll *reduced_clock)
8307 struct drm_crtc *crtc = &intel_crtc->base;
8308 struct drm_device *dev = crtc->dev;
8309 struct drm_i915_private *dev_priv = to_i915(dev);
8313 /* Enable autotuning of the PLL clock (if permissible) */
8315 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8316 if ((intel_panel_use_ssc(dev_priv) &&
8317 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8318 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8320 } else if (crtc_state->sdvo_tv_clock)
8323 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8325 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8328 if (reduced_clock) {
8329 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8331 if (reduced_clock->m < factor * reduced_clock->n)
8339 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8340 dpll |= DPLLB_MODE_LVDS;
8342 dpll |= DPLLB_MODE_DAC_SERIAL;
8344 dpll |= (crtc_state->pixel_multiplier - 1)
8345 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8347 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8348 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8349 dpll |= DPLL_SDVO_HIGH_SPEED;
8351 if (intel_crtc_has_dp_encoder(crtc_state))
8352 dpll |= DPLL_SDVO_HIGH_SPEED;
8355 * The high speed IO clock is only really required for
8356 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8357 * possible to share the DPLL between CRT and HDMI. Enabling
8358 * the clock needlessly does no real harm, except use up a
8359 * bit of power potentially.
8361 * We'll limit this to IVB with 3 pipes, since it has only two
8362 * DPLLs and so DPLL sharing is the only way to get three pipes
8363 * driving PCH ports at the same time. On SNB we could do this,
8364 * and potentially avoid enabling the second DPLL, but it's not
8365 * clear if it''s a win or loss power wise. No point in doing
8366 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8368 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8369 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8370 dpll |= DPLL_SDVO_HIGH_SPEED;
8372 /* compute bitmask from p1 value */
8373 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8375 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8377 switch (crtc_state->dpll.p2) {
8379 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8382 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8385 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8388 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8392 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8393 intel_panel_use_ssc(dev_priv))
8394 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8396 dpll |= PLL_REF_INPUT_DREFCLK;
8398 dpll |= DPLL_VCO_ENABLE;
8400 crtc_state->dpll_hw_state.dpll = dpll;
8401 crtc_state->dpll_hw_state.fp0 = fp;
8402 crtc_state->dpll_hw_state.fp1 = fp2;
8405 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8406 struct intel_crtc_state *crtc_state)
8408 struct drm_device *dev = crtc->base.dev;
8409 struct drm_i915_private *dev_priv = to_i915(dev);
8410 const struct intel_limit *limit;
8411 int refclk = 120000;
8413 memset(&crtc_state->dpll_hw_state, 0,
8414 sizeof(crtc_state->dpll_hw_state));
8416 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8417 if (!crtc_state->has_pch_encoder)
8420 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8421 if (intel_panel_use_ssc(dev_priv)) {
8422 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8423 dev_priv->vbt.lvds_ssc_freq);
8424 refclk = dev_priv->vbt.lvds_ssc_freq;
8427 if (intel_is_dual_link_lvds(dev)) {
8428 if (refclk == 100000)
8429 limit = &intel_limits_ironlake_dual_lvds_100m;
8431 limit = &intel_limits_ironlake_dual_lvds;
8433 if (refclk == 100000)
8434 limit = &intel_limits_ironlake_single_lvds_100m;
8436 limit = &intel_limits_ironlake_single_lvds;
8439 limit = &intel_limits_ironlake_dac;
8442 if (!crtc_state->clock_set &&
8443 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8444 refclk, NULL, &crtc_state->dpll)) {
8445 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8449 ironlake_compute_dpll(crtc, crtc_state, NULL);
8451 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8452 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8453 pipe_name(crtc->pipe));
8460 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8461 struct intel_link_m_n *m_n)
8463 struct drm_device *dev = crtc->base.dev;
8464 struct drm_i915_private *dev_priv = to_i915(dev);
8465 enum pipe pipe = crtc->pipe;
8467 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8468 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8469 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8471 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8472 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8473 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8476 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8477 enum transcoder transcoder,
8478 struct intel_link_m_n *m_n,
8479 struct intel_link_m_n *m2_n2)
8481 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8482 enum pipe pipe = crtc->pipe;
8484 if (INTEL_GEN(dev_priv) >= 5) {
8485 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8486 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8487 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8489 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8490 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8491 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8492 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8493 * gen < 8) and if DRRS is supported (to make sure the
8494 * registers are not unnecessarily read).
8496 if (m2_n2 && INTEL_GEN(dev_priv) < 8 &&
8497 crtc->config->has_drrs) {
8498 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8499 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8500 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8502 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8503 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8504 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8507 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8508 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8509 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8511 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8512 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8513 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8517 void intel_dp_get_m_n(struct intel_crtc *crtc,
8518 struct intel_crtc_state *pipe_config)
8520 if (pipe_config->has_pch_encoder)
8521 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8523 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8524 &pipe_config->dp_m_n,
8525 &pipe_config->dp_m2_n2);
8528 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8529 struct intel_crtc_state *pipe_config)
8531 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8532 &pipe_config->fdi_m_n, NULL);
8535 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8536 struct intel_crtc_state *pipe_config)
8538 struct drm_device *dev = crtc->base.dev;
8539 struct drm_i915_private *dev_priv = to_i915(dev);
8540 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8541 uint32_t ps_ctrl = 0;
8545 /* find scaler attached to this pipe */
8546 for (i = 0; i < crtc->num_scalers; i++) {
8547 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8548 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8550 pipe_config->pch_pfit.enabled = true;
8551 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8552 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8557 scaler_state->scaler_id = id;
8559 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8561 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8566 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8567 struct intel_initial_plane_config *plane_config)
8569 struct drm_device *dev = crtc->base.dev;
8570 struct drm_i915_private *dev_priv = to_i915(dev);
8571 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8572 enum plane_id plane_id = plane->id;
8573 enum pipe pipe = crtc->pipe;
8574 u32 val, base, offset, stride_mult, tiling, alpha;
8575 int fourcc, pixel_format;
8576 unsigned int aligned_height;
8577 struct drm_framebuffer *fb;
8578 struct intel_framebuffer *intel_fb;
8580 if (!plane->get_hw_state(plane))
8583 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8585 DRM_DEBUG_KMS("failed to alloc fb\n");
8589 fb = &intel_fb->base;
8593 val = I915_READ(PLANE_CTL(pipe, plane_id));
8595 if (INTEL_GEN(dev_priv) >= 11)
8596 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8598 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8600 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8601 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
8602 alpha &= PLANE_COLOR_ALPHA_MASK;
8604 alpha = val & PLANE_CTL_ALPHA_MASK;
8607 fourcc = skl_format_to_fourcc(pixel_format,
8608 val & PLANE_CTL_ORDER_RGBX, alpha);
8609 fb->format = drm_format_info(fourcc);
8611 tiling = val & PLANE_CTL_TILED_MASK;
8613 case PLANE_CTL_TILED_LINEAR:
8614 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8616 case PLANE_CTL_TILED_X:
8617 plane_config->tiling = I915_TILING_X;
8618 fb->modifier = I915_FORMAT_MOD_X_TILED;
8620 case PLANE_CTL_TILED_Y:
8621 if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
8622 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8624 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8626 case PLANE_CTL_TILED_YF:
8627 if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
8628 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8630 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8633 MISSING_CASE(tiling);
8637 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8638 plane_config->base = base;
8640 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
8642 val = I915_READ(PLANE_SIZE(pipe, plane_id));
8643 fb->height = ((val >> 16) & 0xfff) + 1;
8644 fb->width = ((val >> 0) & 0x1fff) + 1;
8646 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
8647 stride_mult = intel_fb_stride_alignment(fb, 0);
8648 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8650 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8652 plane_config->size = fb->pitches[0] * aligned_height;
8654 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8655 crtc->base.name, plane->base.name, fb->width, fb->height,
8656 fb->format->cpp[0] * 8, base, fb->pitches[0],
8657 plane_config->size);
8659 plane_config->fb = intel_fb;
8666 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
8667 struct intel_crtc_state *pipe_config)
8669 struct drm_device *dev = crtc->base.dev;
8670 struct drm_i915_private *dev_priv = to_i915(dev);
8673 tmp = I915_READ(PF_CTL(crtc->pipe));
8675 if (tmp & PF_ENABLE) {
8676 pipe_config->pch_pfit.enabled = true;
8677 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8678 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
8680 /* We currently do not free assignements of panel fitters on
8681 * ivb/hsw (since we don't use the higher upscaling modes which
8682 * differentiates them) so just WARN about this case for now. */
8683 if (IS_GEN7(dev_priv)) {
8684 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
8685 PF_PIPE_SEL_IVB(crtc->pipe));
8690 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
8691 struct intel_crtc_state *pipe_config)
8693 struct drm_device *dev = crtc->base.dev;
8694 struct drm_i915_private *dev_priv = to_i915(dev);
8695 enum intel_display_power_domain power_domain;
8699 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8700 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
8703 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8704 pipe_config->shared_dpll = NULL;
8707 tmp = I915_READ(PIPECONF(crtc->pipe));
8708 if (!(tmp & PIPECONF_ENABLE))
8711 switch (tmp & PIPECONF_BPC_MASK) {
8713 pipe_config->pipe_bpp = 18;
8716 pipe_config->pipe_bpp = 24;
8718 case PIPECONF_10BPC:
8719 pipe_config->pipe_bpp = 30;
8721 case PIPECONF_12BPC:
8722 pipe_config->pipe_bpp = 36;
8728 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8729 pipe_config->limited_color_range = true;
8731 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
8732 struct intel_shared_dpll *pll;
8733 enum intel_dpll_id pll_id;
8735 pipe_config->has_pch_encoder = true;
8737 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
8738 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8739 FDI_DP_PORT_WIDTH_SHIFT) + 1;
8741 ironlake_get_fdi_m_n_config(crtc, pipe_config);
8743 if (HAS_PCH_IBX(dev_priv)) {
8745 * The pipe->pch transcoder and pch transcoder->pll
8748 pll_id = (enum intel_dpll_id) crtc->pipe;
8750 tmp = I915_READ(PCH_DPLL_SEL);
8751 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
8752 pll_id = DPLL_ID_PCH_PLL_B;
8754 pll_id= DPLL_ID_PCH_PLL_A;
8757 pipe_config->shared_dpll =
8758 intel_get_shared_dpll_by_id(dev_priv, pll_id);
8759 pll = pipe_config->shared_dpll;
8761 WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll,
8762 &pipe_config->dpll_hw_state));
8764 tmp = pipe_config->dpll_hw_state.dpll;
8765 pipe_config->pixel_multiplier =
8766 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
8767 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
8769 ironlake_pch_clock_get(crtc, pipe_config);
8771 pipe_config->pixel_multiplier = 1;
8774 intel_get_pipe_timings(crtc, pipe_config);
8775 intel_get_pipe_src_size(crtc, pipe_config);
8777 ironlake_get_pfit_config(crtc, pipe_config);
8782 intel_display_power_put(dev_priv, power_domain);
8787 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
8789 struct drm_device *dev = &dev_priv->drm;
8790 struct intel_crtc *crtc;
8792 for_each_intel_crtc(dev, crtc)
8793 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
8794 pipe_name(crtc->pipe));
8796 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)),
8797 "Display power well on\n");
8798 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
8799 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
8800 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
8801 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
8802 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
8803 "CPU PWM1 enabled\n");
8804 if (IS_HASWELL(dev_priv))
8805 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
8806 "CPU PWM2 enabled\n");
8807 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
8808 "PCH PWM1 enabled\n");
8809 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
8810 "Utility pin enabled\n");
8811 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
8814 * In theory we can still leave IRQs enabled, as long as only the HPD
8815 * interrupts remain enabled. We used to check for that, but since it's
8816 * gen-specific and since we only disable LCPLL after we fully disable
8817 * the interrupts, the check below should be enough.
8819 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
8822 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
8824 if (IS_HASWELL(dev_priv))
8825 return I915_READ(D_COMP_HSW);
8827 return I915_READ(D_COMP_BDW);
8830 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
8832 if (IS_HASWELL(dev_priv)) {
8833 mutex_lock(&dev_priv->pcu_lock);
8834 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
8836 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8837 mutex_unlock(&dev_priv->pcu_lock);
8839 I915_WRITE(D_COMP_BDW, val);
8840 POSTING_READ(D_COMP_BDW);
8845 * This function implements pieces of two sequences from BSpec:
8846 * - Sequence for display software to disable LCPLL
8847 * - Sequence for display software to allow package C8+
8848 * The steps implemented here are just the steps that actually touch the LCPLL
8849 * register. Callers should take care of disabling all the display engine
8850 * functions, doing the mode unset, fixing interrupts, etc.
8852 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
8853 bool switch_to_fclk, bool allow_power_down)
8857 assert_can_disable_lcpll(dev_priv);
8859 val = I915_READ(LCPLL_CTL);
8861 if (switch_to_fclk) {
8862 val |= LCPLL_CD_SOURCE_FCLK;
8863 I915_WRITE(LCPLL_CTL, val);
8865 if (wait_for_us(I915_READ(LCPLL_CTL) &
8866 LCPLL_CD_SOURCE_FCLK_DONE, 1))
8867 DRM_ERROR("Switching to FCLK failed\n");
8869 val = I915_READ(LCPLL_CTL);
8872 val |= LCPLL_PLL_DISABLE;
8873 I915_WRITE(LCPLL_CTL, val);
8874 POSTING_READ(LCPLL_CTL);
8876 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
8877 DRM_ERROR("LCPLL still locked\n");
8879 val = hsw_read_dcomp(dev_priv);
8880 val |= D_COMP_COMP_DISABLE;
8881 hsw_write_dcomp(dev_priv, val);
8884 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
8886 DRM_ERROR("D_COMP RCOMP still in progress\n");
8888 if (allow_power_down) {
8889 val = I915_READ(LCPLL_CTL);
8890 val |= LCPLL_POWER_DOWN_ALLOW;
8891 I915_WRITE(LCPLL_CTL, val);
8892 POSTING_READ(LCPLL_CTL);
8897 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8900 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
8904 val = I915_READ(LCPLL_CTL);
8906 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
8907 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
8911 * Make sure we're not on PC8 state before disabling PC8, otherwise
8912 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8914 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
8916 if (val & LCPLL_POWER_DOWN_ALLOW) {
8917 val &= ~LCPLL_POWER_DOWN_ALLOW;
8918 I915_WRITE(LCPLL_CTL, val);
8919 POSTING_READ(LCPLL_CTL);
8922 val = hsw_read_dcomp(dev_priv);
8923 val |= D_COMP_COMP_FORCE;
8924 val &= ~D_COMP_COMP_DISABLE;
8925 hsw_write_dcomp(dev_priv, val);
8927 val = I915_READ(LCPLL_CTL);
8928 val &= ~LCPLL_PLL_DISABLE;
8929 I915_WRITE(LCPLL_CTL, val);
8931 if (intel_wait_for_register(dev_priv,
8932 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
8934 DRM_ERROR("LCPLL not locked yet\n");
8936 if (val & LCPLL_CD_SOURCE_FCLK) {
8937 val = I915_READ(LCPLL_CTL);
8938 val &= ~LCPLL_CD_SOURCE_FCLK;
8939 I915_WRITE(LCPLL_CTL, val);
8941 if (wait_for_us((I915_READ(LCPLL_CTL) &
8942 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
8943 DRM_ERROR("Switching back to LCPLL failed\n");
8946 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
8948 intel_update_cdclk(dev_priv);
8949 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
8953 * Package states C8 and deeper are really deep PC states that can only be
8954 * reached when all the devices on the system allow it, so even if the graphics
8955 * device allows PC8+, it doesn't mean the system will actually get to these
8956 * states. Our driver only allows PC8+ when going into runtime PM.
8958 * The requirements for PC8+ are that all the outputs are disabled, the power
8959 * well is disabled and most interrupts are disabled, and these are also
8960 * requirements for runtime PM. When these conditions are met, we manually do
8961 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
8962 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
8965 * When we really reach PC8 or deeper states (not just when we allow it) we lose
8966 * the state of some registers, so when we come back from PC8+ we need to
8967 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
8968 * need to take care of the registers kept by RC6. Notice that this happens even
8969 * if we don't put the device in PCI D3 state (which is what currently happens
8970 * because of the runtime PM support).
8972 * For more, read "Display Sequences for Package C8" on the hardware
8975 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
8979 DRM_DEBUG_KMS("Enabling package C8+\n");
8981 if (HAS_PCH_LPT_LP(dev_priv)) {
8982 val = I915_READ(SOUTH_DSPCLK_GATE_D);
8983 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
8984 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
8987 lpt_disable_clkout_dp(dev_priv);
8988 hsw_disable_lcpll(dev_priv, true, true);
8991 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
8995 DRM_DEBUG_KMS("Disabling package C8+\n");
8997 hsw_restore_lcpll(dev_priv);
8998 lpt_init_pch_refclk(dev_priv);
9000 if (HAS_PCH_LPT_LP(dev_priv)) {
9001 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9002 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9003 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9007 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9008 struct intel_crtc_state *crtc_state)
9010 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
9011 struct intel_encoder *encoder =
9012 intel_ddi_get_crtc_new_encoder(crtc_state);
9014 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9015 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
9016 pipe_name(crtc->pipe));
9024 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9026 struct intel_crtc_state *pipe_config)
9028 enum intel_dpll_id id;
9031 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9032 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9034 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9037 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9040 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9042 struct intel_crtc_state *pipe_config)
9044 enum intel_dpll_id id;
9048 id = DPLL_ID_SKL_DPLL0;
9051 id = DPLL_ID_SKL_DPLL1;
9054 id = DPLL_ID_SKL_DPLL2;
9057 DRM_ERROR("Incorrect port type\n");
9061 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9064 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9066 struct intel_crtc_state *pipe_config)
9068 enum intel_dpll_id id;
9071 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9072 id = temp >> (port * 3 + 1);
9074 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9077 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9080 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9082 struct intel_crtc_state *pipe_config)
9084 enum intel_dpll_id id;
9085 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9087 switch (ddi_pll_sel) {
9088 case PORT_CLK_SEL_WRPLL1:
9089 id = DPLL_ID_WRPLL1;
9091 case PORT_CLK_SEL_WRPLL2:
9092 id = DPLL_ID_WRPLL2;
9094 case PORT_CLK_SEL_SPLL:
9097 case PORT_CLK_SEL_LCPLL_810:
9098 id = DPLL_ID_LCPLL_810;
9100 case PORT_CLK_SEL_LCPLL_1350:
9101 id = DPLL_ID_LCPLL_1350;
9103 case PORT_CLK_SEL_LCPLL_2700:
9104 id = DPLL_ID_LCPLL_2700;
9107 MISSING_CASE(ddi_pll_sel);
9109 case PORT_CLK_SEL_NONE:
9113 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9116 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9117 struct intel_crtc_state *pipe_config,
9118 u64 *power_domain_mask)
9120 struct drm_device *dev = crtc->base.dev;
9121 struct drm_i915_private *dev_priv = to_i915(dev);
9122 enum intel_display_power_domain power_domain;
9126 * The pipe->transcoder mapping is fixed with the exception of the eDP
9127 * transcoder handled below.
9129 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9132 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9133 * consistency and less surprising code; it's in always on power).
9135 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9136 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9137 enum pipe trans_edp_pipe;
9138 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9140 WARN(1, "unknown pipe linked to edp transcoder\n");
9141 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9142 case TRANS_DDI_EDP_INPUT_A_ON:
9143 trans_edp_pipe = PIPE_A;
9145 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9146 trans_edp_pipe = PIPE_B;
9148 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9149 trans_edp_pipe = PIPE_C;
9153 if (trans_edp_pipe == crtc->pipe)
9154 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9157 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9158 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9160 *power_domain_mask |= BIT_ULL(power_domain);
9162 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9164 return tmp & PIPECONF_ENABLE;
9167 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9168 struct intel_crtc_state *pipe_config,
9169 u64 *power_domain_mask)
9171 struct drm_device *dev = crtc->base.dev;
9172 struct drm_i915_private *dev_priv = to_i915(dev);
9173 enum intel_display_power_domain power_domain;
9175 enum transcoder cpu_transcoder;
9178 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9180 cpu_transcoder = TRANSCODER_DSI_A;
9182 cpu_transcoder = TRANSCODER_DSI_C;
9184 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9185 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9187 *power_domain_mask |= BIT_ULL(power_domain);
9190 * The PLL needs to be enabled with a valid divider
9191 * configuration, otherwise accessing DSI registers will hang
9192 * the machine. See BSpec North Display Engine
9193 * registers/MIPI[BXT]. We can break out here early, since we
9194 * need the same DSI PLL to be enabled for both DSI ports.
9196 if (!intel_dsi_pll_is_enabled(dev_priv))
9199 /* XXX: this works for video mode only */
9200 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9201 if (!(tmp & DPI_ENABLE))
9204 tmp = I915_READ(MIPI_CTRL(port));
9205 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9208 pipe_config->cpu_transcoder = cpu_transcoder;
9212 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9215 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9216 struct intel_crtc_state *pipe_config)
9218 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9219 struct intel_shared_dpll *pll;
9223 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9225 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9227 if (IS_CANNONLAKE(dev_priv))
9228 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9229 else if (IS_GEN9_BC(dev_priv))
9230 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9231 else if (IS_GEN9_LP(dev_priv))
9232 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9234 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9236 pll = pipe_config->shared_dpll;
9238 WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll,
9239 &pipe_config->dpll_hw_state));
9243 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9244 * DDI E. So just check whether this pipe is wired to DDI E and whether
9245 * the PCH transcoder is on.
9247 if (INTEL_GEN(dev_priv) < 9 &&
9248 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9249 pipe_config->has_pch_encoder = true;
9251 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9252 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9253 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9255 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9259 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9260 struct intel_crtc_state *pipe_config)
9262 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9263 enum intel_display_power_domain power_domain;
9264 u64 power_domain_mask;
9267 intel_crtc_init_scalers(crtc, pipe_config);
9269 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9270 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9272 power_domain_mask = BIT_ULL(power_domain);
9274 pipe_config->shared_dpll = NULL;
9276 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9278 if (IS_GEN9_LP(dev_priv) &&
9279 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9287 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9288 haswell_get_ddi_port_state(crtc, pipe_config);
9289 intel_get_pipe_timings(crtc, pipe_config);
9292 intel_get_pipe_src_size(crtc, pipe_config);
9294 pipe_config->gamma_mode =
9295 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9297 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
9298 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
9299 bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV;
9301 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
9302 bool blend_mode_420 = tmp &
9303 PIPEMISC_YUV420_MODE_FULL_BLEND;
9305 pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE;
9306 if (pipe_config->ycbcr420 != clrspace_yuv ||
9307 pipe_config->ycbcr420 != blend_mode_420)
9308 DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp);
9309 } else if (clrspace_yuv) {
9310 DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
9314 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9315 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9316 power_domain_mask |= BIT_ULL(power_domain);
9317 if (INTEL_GEN(dev_priv) >= 9)
9318 skylake_get_pfit_config(crtc, pipe_config);
9320 ironlake_get_pfit_config(crtc, pipe_config);
9323 if (hsw_crtc_supports_ips(crtc)) {
9324 if (IS_HASWELL(dev_priv))
9325 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9328 * We cannot readout IPS state on broadwell, set to
9329 * true so we can set it to a defined state on first
9332 pipe_config->ips_enabled = true;
9336 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9337 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9338 pipe_config->pixel_multiplier =
9339 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9341 pipe_config->pixel_multiplier = 1;
9345 for_each_power_domain(power_domain, power_domain_mask)
9346 intel_display_power_put(dev_priv, power_domain);
9351 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9353 struct drm_i915_private *dev_priv =
9354 to_i915(plane_state->base.plane->dev);
9355 const struct drm_framebuffer *fb = plane_state->base.fb;
9356 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9359 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9360 base = obj->phys_handle->busaddr;
9362 base = intel_plane_ggtt_offset(plane_state);
9364 base += plane_state->main.offset;
9366 /* ILK+ do this automagically */
9367 if (HAS_GMCH_DISPLAY(dev_priv) &&
9368 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9369 base += (plane_state->base.crtc_h *
9370 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9375 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9377 int x = plane_state->base.crtc_x;
9378 int y = plane_state->base.crtc_y;
9382 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9385 pos |= x << CURSOR_X_SHIFT;
9388 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9391 pos |= y << CURSOR_Y_SHIFT;
9396 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9398 const struct drm_mode_config *config =
9399 &plane_state->base.plane->dev->mode_config;
9400 int width = plane_state->base.crtc_w;
9401 int height = plane_state->base.crtc_h;
9403 return width > 0 && width <= config->cursor_width &&
9404 height > 0 && height <= config->cursor_height;
9407 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9408 struct intel_plane_state *plane_state)
9410 const struct drm_framebuffer *fb = plane_state->base.fb;
9411 struct drm_rect clip = {};
9416 if (crtc_state->base.enable)
9417 drm_mode_get_hv_timing(&crtc_state->base.mode,
9418 &clip.x2, &clip.y2);
9420 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9423 DRM_PLANE_HELPER_NO_SCALING,
9424 DRM_PLANE_HELPER_NO_SCALING,
9432 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9433 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9437 src_x = plane_state->base.src_x >> 16;
9438 src_y = plane_state->base.src_y >> 16;
9440 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9441 offset = intel_compute_tile_offset(&src_x, &src_y, plane_state, 0);
9443 if (src_x != 0 || src_y != 0) {
9444 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9448 plane_state->main.offset = offset;
9453 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9454 const struct intel_plane_state *plane_state)
9456 const struct drm_framebuffer *fb = plane_state->base.fb;
9458 return CURSOR_ENABLE |
9459 CURSOR_GAMMA_ENABLE |
9460 CURSOR_FORMAT_ARGB |
9461 CURSOR_STRIDE(fb->pitches[0]);
9464 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9466 int width = plane_state->base.crtc_w;
9469 * 845g/865g are only limited by the width of their cursors,
9470 * the height is arbitrary up to the precision of the register.
9472 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
9475 static int i845_check_cursor(struct intel_plane *plane,
9476 struct intel_crtc_state *crtc_state,
9477 struct intel_plane_state *plane_state)
9479 const struct drm_framebuffer *fb = plane_state->base.fb;
9482 ret = intel_check_cursor(crtc_state, plane_state);
9486 /* if we want to turn off the cursor ignore width and height */
9490 /* Check for which cursor types we support */
9491 if (!i845_cursor_size_ok(plane_state)) {
9492 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9493 plane_state->base.crtc_w,
9494 plane_state->base.crtc_h);
9498 switch (fb->pitches[0]) {
9505 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9510 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9515 static void i845_update_cursor(struct intel_plane *plane,
9516 const struct intel_crtc_state *crtc_state,
9517 const struct intel_plane_state *plane_state)
9519 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9520 u32 cntl = 0, base = 0, pos = 0, size = 0;
9521 unsigned long irqflags;
9523 if (plane_state && plane_state->base.visible) {
9524 unsigned int width = plane_state->base.crtc_w;
9525 unsigned int height = plane_state->base.crtc_h;
9527 cntl = plane_state->ctl;
9528 size = (height << 12) | width;
9530 base = intel_cursor_base(plane_state);
9531 pos = intel_cursor_position(plane_state);
9534 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9536 /* On these chipsets we can only modify the base/size/stride
9537 * whilst the cursor is disabled.
9539 if (plane->cursor.base != base ||
9540 plane->cursor.size != size ||
9541 plane->cursor.cntl != cntl) {
9542 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
9543 I915_WRITE_FW(CURBASE(PIPE_A), base);
9544 I915_WRITE_FW(CURSIZE, size);
9545 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9546 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
9548 plane->cursor.base = base;
9549 plane->cursor.size = size;
9550 plane->cursor.cntl = cntl;
9552 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9555 POSTING_READ_FW(CURCNTR(PIPE_A));
9557 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9560 static void i845_disable_cursor(struct intel_plane *plane,
9561 struct intel_crtc *crtc)
9563 i845_update_cursor(plane, NULL, NULL);
9566 static bool i845_cursor_get_hw_state(struct intel_plane *plane)
9568 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9569 enum intel_display_power_domain power_domain;
9572 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9573 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9576 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9578 intel_display_power_put(dev_priv, power_domain);
9583 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9584 const struct intel_plane_state *plane_state)
9586 struct drm_i915_private *dev_priv =
9587 to_i915(plane_state->base.plane->dev);
9588 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9591 cntl = MCURSOR_GAMMA_ENABLE;
9593 if (HAS_DDI(dev_priv))
9594 cntl |= CURSOR_PIPE_CSC_ENABLE;
9596 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9597 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
9599 switch (plane_state->base.crtc_w) {
9601 cntl |= CURSOR_MODE_64_ARGB_AX;
9604 cntl |= CURSOR_MODE_128_ARGB_AX;
9607 cntl |= CURSOR_MODE_256_ARGB_AX;
9610 MISSING_CASE(plane_state->base.crtc_w);
9614 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
9615 cntl |= CURSOR_ROTATE_180;
9620 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
9622 struct drm_i915_private *dev_priv =
9623 to_i915(plane_state->base.plane->dev);
9624 int width = plane_state->base.crtc_w;
9625 int height = plane_state->base.crtc_h;
9627 if (!intel_cursor_size_ok(plane_state))
9630 /* Cursor width is limited to a few power-of-two sizes */
9641 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9642 * height from 8 lines up to the cursor width, when the
9643 * cursor is not rotated. Everything else requires square
9646 if (HAS_CUR_FBC(dev_priv) &&
9647 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
9648 if (height < 8 || height > width)
9651 if (height != width)
9658 static int i9xx_check_cursor(struct intel_plane *plane,
9659 struct intel_crtc_state *crtc_state,
9660 struct intel_plane_state *plane_state)
9662 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9663 const struct drm_framebuffer *fb = plane_state->base.fb;
9664 enum pipe pipe = plane->pipe;
9667 ret = intel_check_cursor(crtc_state, plane_state);
9671 /* if we want to turn off the cursor ignore width and height */
9675 /* Check for which cursor types we support */
9676 if (!i9xx_cursor_size_ok(plane_state)) {
9677 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9678 plane_state->base.crtc_w,
9679 plane_state->base.crtc_h);
9683 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
9684 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9685 fb->pitches[0], plane_state->base.crtc_w);
9690 * There's something wrong with the cursor on CHV pipe C.
9691 * If it straddles the left edge of the screen then
9692 * moving it away from the edge or disabling it often
9693 * results in a pipe underrun, and often that can lead to
9694 * dead pipe (constant underrun reported, and it scans
9695 * out just a solid color). To recover from that, the
9696 * display power well must be turned off and on again.
9697 * Refuse the put the cursor into that compromised position.
9699 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
9700 plane_state->base.visible && plane_state->base.crtc_x < 0) {
9701 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9705 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
9710 static void i9xx_update_cursor(struct intel_plane *plane,
9711 const struct intel_crtc_state *crtc_state,
9712 const struct intel_plane_state *plane_state)
9714 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9715 enum pipe pipe = plane->pipe;
9716 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
9717 unsigned long irqflags;
9719 if (plane_state && plane_state->base.visible) {
9720 cntl = plane_state->ctl;
9722 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
9723 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
9725 base = intel_cursor_base(plane_state);
9726 pos = intel_cursor_position(plane_state);
9729 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9732 * On some platforms writing CURCNTR first will also
9733 * cause CURPOS to be armed by the CURBASE write.
9734 * Without the CURCNTR write the CURPOS write would
9735 * arm itself. Thus we always start the full update
9736 * with a CURCNTR write.
9738 * On other platforms CURPOS always requires the
9739 * CURBASE write to arm the update. Additonally
9740 * a write to any of the cursor register will cancel
9741 * an already armed cursor update. Thus leaving out
9742 * the CURBASE write after CURPOS could lead to a
9743 * cursor that doesn't appear to move, or even change
9744 * shape. Thus we always write CURBASE.
9746 * CURCNTR and CUR_FBC_CTL are always
9747 * armed by the CURBASE write only.
9749 if (plane->cursor.base != base ||
9750 plane->cursor.size != fbc_ctl ||
9751 plane->cursor.cntl != cntl) {
9752 I915_WRITE_FW(CURCNTR(pipe), cntl);
9753 if (HAS_CUR_FBC(dev_priv))
9754 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
9755 I915_WRITE_FW(CURPOS(pipe), pos);
9756 I915_WRITE_FW(CURBASE(pipe), base);
9758 plane->cursor.base = base;
9759 plane->cursor.size = fbc_ctl;
9760 plane->cursor.cntl = cntl;
9762 I915_WRITE_FW(CURPOS(pipe), pos);
9763 I915_WRITE_FW(CURBASE(pipe), base);
9766 POSTING_READ_FW(CURBASE(pipe));
9768 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9771 static void i9xx_disable_cursor(struct intel_plane *plane,
9772 struct intel_crtc *crtc)
9774 i9xx_update_cursor(plane, NULL, NULL);
9777 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane)
9779 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9780 enum intel_display_power_domain power_domain;
9781 enum pipe pipe = plane->pipe;
9785 * Not 100% correct for planes that can move between pipes,
9786 * but that's only the case for gen2-3 which don't have any
9787 * display power wells.
9789 power_domain = POWER_DOMAIN_PIPE(pipe);
9790 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9793 ret = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
9795 intel_display_power_put(dev_priv, power_domain);
9800 /* VESA 640x480x72Hz mode to set on the pipe */
9801 static const struct drm_display_mode load_detect_mode = {
9802 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
9803 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
9806 struct drm_framebuffer *
9807 intel_framebuffer_create(struct drm_i915_gem_object *obj,
9808 struct drm_mode_fb_cmd2 *mode_cmd)
9810 struct intel_framebuffer *intel_fb;
9813 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9815 return ERR_PTR(-ENOMEM);
9817 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
9821 return &intel_fb->base;
9825 return ERR_PTR(ret);
9828 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
9829 struct drm_crtc *crtc)
9831 struct drm_plane *plane;
9832 struct drm_plane_state *plane_state;
9835 ret = drm_atomic_add_affected_planes(state, crtc);
9839 for_each_new_plane_in_state(state, plane, plane_state, i) {
9840 if (plane_state->crtc != crtc)
9843 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
9847 drm_atomic_set_fb_for_plane(plane_state, NULL);
9853 int intel_get_load_detect_pipe(struct drm_connector *connector,
9854 const struct drm_display_mode *mode,
9855 struct intel_load_detect_pipe *old,
9856 struct drm_modeset_acquire_ctx *ctx)
9858 struct intel_crtc *intel_crtc;
9859 struct intel_encoder *intel_encoder =
9860 intel_attached_encoder(connector);
9861 struct drm_crtc *possible_crtc;
9862 struct drm_encoder *encoder = &intel_encoder->base;
9863 struct drm_crtc *crtc = NULL;
9864 struct drm_device *dev = encoder->dev;
9865 struct drm_i915_private *dev_priv = to_i915(dev);
9866 struct drm_mode_config *config = &dev->mode_config;
9867 struct drm_atomic_state *state = NULL, *restore_state = NULL;
9868 struct drm_connector_state *connector_state;
9869 struct intel_crtc_state *crtc_state;
9872 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9873 connector->base.id, connector->name,
9874 encoder->base.id, encoder->name);
9876 old->restore_state = NULL;
9878 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
9881 * Algorithm gets a little messy:
9883 * - if the connector already has an assigned crtc, use it (but make
9884 * sure it's on first)
9886 * - try to find the first unused crtc that can drive this connector,
9887 * and use that if we find one
9890 /* See if we already have a CRTC for this connector */
9891 if (connector->state->crtc) {
9892 crtc = connector->state->crtc;
9894 ret = drm_modeset_lock(&crtc->mutex, ctx);
9898 /* Make sure the crtc and connector are running */
9902 /* Find an unused one (if possible) */
9903 for_each_crtc(dev, possible_crtc) {
9905 if (!(encoder->possible_crtcs & (1 << i)))
9908 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
9912 if (possible_crtc->state->enable) {
9913 drm_modeset_unlock(&possible_crtc->mutex);
9917 crtc = possible_crtc;
9922 * If we didn't find an unused CRTC, don't use any.
9925 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9931 intel_crtc = to_intel_crtc(crtc);
9933 state = drm_atomic_state_alloc(dev);
9934 restore_state = drm_atomic_state_alloc(dev);
9935 if (!state || !restore_state) {
9940 state->acquire_ctx = ctx;
9941 restore_state->acquire_ctx = ctx;
9943 connector_state = drm_atomic_get_connector_state(state, connector);
9944 if (IS_ERR(connector_state)) {
9945 ret = PTR_ERR(connector_state);
9949 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
9953 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
9954 if (IS_ERR(crtc_state)) {
9955 ret = PTR_ERR(crtc_state);
9959 crtc_state->base.active = crtc_state->base.enable = true;
9962 mode = &load_detect_mode;
9964 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
9968 ret = intel_modeset_disable_planes(state, crtc);
9972 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
9974 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
9976 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
9980 ret = drm_atomic_commit(state);
9982 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9986 old->restore_state = restore_state;
9987 drm_atomic_state_put(state);
9989 /* let the connector get through one full cycle before testing */
9990 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
9995 drm_atomic_state_put(state);
9998 if (restore_state) {
9999 drm_atomic_state_put(restore_state);
10000 restore_state = NULL;
10003 if (ret == -EDEADLK)
10009 void intel_release_load_detect_pipe(struct drm_connector *connector,
10010 struct intel_load_detect_pipe *old,
10011 struct drm_modeset_acquire_ctx *ctx)
10013 struct intel_encoder *intel_encoder =
10014 intel_attached_encoder(connector);
10015 struct drm_encoder *encoder = &intel_encoder->base;
10016 struct drm_atomic_state *state = old->restore_state;
10019 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10020 connector->base.id, connector->name,
10021 encoder->base.id, encoder->name);
10026 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10028 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10029 drm_atomic_state_put(state);
10032 static int i9xx_pll_refclk(struct drm_device *dev,
10033 const struct intel_crtc_state *pipe_config)
10035 struct drm_i915_private *dev_priv = to_i915(dev);
10036 u32 dpll = pipe_config->dpll_hw_state.dpll;
10038 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10039 return dev_priv->vbt.lvds_ssc_freq;
10040 else if (HAS_PCH_SPLIT(dev_priv))
10042 else if (!IS_GEN2(dev_priv))
10048 /* Returns the clock of the currently programmed mode of the given pipe. */
10049 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10050 struct intel_crtc_state *pipe_config)
10052 struct drm_device *dev = crtc->base.dev;
10053 struct drm_i915_private *dev_priv = to_i915(dev);
10054 int pipe = pipe_config->cpu_transcoder;
10055 u32 dpll = pipe_config->dpll_hw_state.dpll;
10059 int refclk = i9xx_pll_refclk(dev, pipe_config);
10061 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10062 fp = pipe_config->dpll_hw_state.fp0;
10064 fp = pipe_config->dpll_hw_state.fp1;
10066 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10067 if (IS_PINEVIEW(dev_priv)) {
10068 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10069 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10071 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10072 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10075 if (!IS_GEN2(dev_priv)) {
10076 if (IS_PINEVIEW(dev_priv))
10077 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10078 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10080 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10081 DPLL_FPA01_P1_POST_DIV_SHIFT);
10083 switch (dpll & DPLL_MODE_MASK) {
10084 case DPLLB_MODE_DAC_SERIAL:
10085 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10088 case DPLLB_MODE_LVDS:
10089 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10093 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10094 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10098 if (IS_PINEVIEW(dev_priv))
10099 port_clock = pnv_calc_dpll_params(refclk, &clock);
10101 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10103 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10104 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10107 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10108 DPLL_FPA01_P1_POST_DIV_SHIFT);
10110 if (lvds & LVDS_CLKB_POWER_UP)
10115 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10118 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10119 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10121 if (dpll & PLL_P2_DIVIDE_BY_4)
10127 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10131 * This value includes pixel_multiplier. We will use
10132 * port_clock to compute adjusted_mode.crtc_clock in the
10133 * encoder's get_config() function.
10135 pipe_config->port_clock = port_clock;
10138 int intel_dotclock_calculate(int link_freq,
10139 const struct intel_link_m_n *m_n)
10142 * The calculation for the data clock is:
10143 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10144 * But we want to avoid losing precison if possible, so:
10145 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10147 * and the link clock is simpler:
10148 * link_clock = (m * link_clock) / n
10154 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10157 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10158 struct intel_crtc_state *pipe_config)
10160 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10162 /* read out port_clock from the DPLL */
10163 i9xx_crtc_clock_get(crtc, pipe_config);
10166 * In case there is an active pipe without active ports,
10167 * we may need some idea for the dotclock anyway.
10168 * Calculate one based on the FDI configuration.
10170 pipe_config->base.adjusted_mode.crtc_clock =
10171 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10172 &pipe_config->fdi_m_n);
10175 /* Returns the currently programmed mode of the given encoder. */
10176 struct drm_display_mode *
10177 intel_encoder_current_mode(struct intel_encoder *encoder)
10179 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10180 struct intel_crtc_state *crtc_state;
10181 struct drm_display_mode *mode;
10182 struct intel_crtc *crtc;
10185 if (!encoder->get_hw_state(encoder, &pipe))
10188 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10190 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10194 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10200 crtc_state->base.crtc = &crtc->base;
10202 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10208 encoder->get_config(encoder, crtc_state);
10210 intel_mode_from_pipe_config(mode, crtc_state);
10217 static void intel_crtc_destroy(struct drm_crtc *crtc)
10219 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10221 drm_crtc_cleanup(crtc);
10226 * intel_wm_need_update - Check whether watermarks need updating
10227 * @plane: drm plane
10228 * @state: new plane state
10230 * Check current plane state versus the new one to determine whether
10231 * watermarks need to be recalculated.
10233 * Returns true or false.
10235 static bool intel_wm_need_update(struct drm_plane *plane,
10236 struct drm_plane_state *state)
10238 struct intel_plane_state *new = to_intel_plane_state(state);
10239 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10241 /* Update watermarks on tiling or size changes. */
10242 if (new->base.visible != cur->base.visible)
10245 if (!cur->base.fb || !new->base.fb)
10248 if (cur->base.fb->modifier != new->base.fb->modifier ||
10249 cur->base.rotation != new->base.rotation ||
10250 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10251 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10252 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10253 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10259 static bool needs_scaling(const struct intel_plane_state *state)
10261 int src_w = drm_rect_width(&state->base.src) >> 16;
10262 int src_h = drm_rect_height(&state->base.src) >> 16;
10263 int dst_w = drm_rect_width(&state->base.dst);
10264 int dst_h = drm_rect_height(&state->base.dst);
10266 return (src_w != dst_w || src_h != dst_h);
10269 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10270 struct drm_crtc_state *crtc_state,
10271 const struct intel_plane_state *old_plane_state,
10272 struct drm_plane_state *plane_state)
10274 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10275 struct drm_crtc *crtc = crtc_state->crtc;
10276 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10277 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10278 struct drm_device *dev = crtc->dev;
10279 struct drm_i915_private *dev_priv = to_i915(dev);
10280 bool mode_changed = needs_modeset(crtc_state);
10281 bool was_crtc_enabled = old_crtc_state->base.active;
10282 bool is_crtc_enabled = crtc_state->active;
10283 bool turn_off, turn_on, visible, was_visible;
10284 struct drm_framebuffer *fb = plane_state->fb;
10287 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10288 ret = skl_update_scaler_plane(
10289 to_intel_crtc_state(crtc_state),
10290 to_intel_plane_state(plane_state));
10295 was_visible = old_plane_state->base.visible;
10296 visible = plane_state->visible;
10298 if (!was_crtc_enabled && WARN_ON(was_visible))
10299 was_visible = false;
10302 * Visibility is calculated as if the crtc was on, but
10303 * after scaler setup everything depends on it being off
10304 * when the crtc isn't active.
10306 * FIXME this is wrong for watermarks. Watermarks should also
10307 * be computed as if the pipe would be active. Perhaps move
10308 * per-plane wm computation to the .check_plane() hook, and
10309 * only combine the results from all planes in the current place?
10311 if (!is_crtc_enabled) {
10312 plane_state->visible = visible = false;
10313 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10316 if (!was_visible && !visible)
10319 if (fb != old_plane_state->base.fb)
10320 pipe_config->fb_changed = true;
10322 turn_off = was_visible && (!visible || mode_changed);
10323 turn_on = visible && (!was_visible || mode_changed);
10325 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10326 intel_crtc->base.base.id, intel_crtc->base.name,
10327 plane->base.base.id, plane->base.name,
10328 fb ? fb->base.id : -1);
10330 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10331 plane->base.base.id, plane->base.name,
10332 was_visible, visible,
10333 turn_off, turn_on, mode_changed);
10336 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10337 pipe_config->update_wm_pre = true;
10339 /* must disable cxsr around plane enable/disable */
10340 if (plane->id != PLANE_CURSOR)
10341 pipe_config->disable_cxsr = true;
10342 } else if (turn_off) {
10343 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10344 pipe_config->update_wm_post = true;
10346 /* must disable cxsr around plane enable/disable */
10347 if (plane->id != PLANE_CURSOR)
10348 pipe_config->disable_cxsr = true;
10349 } else if (intel_wm_need_update(&plane->base, plane_state)) {
10350 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
10351 /* FIXME bollocks */
10352 pipe_config->update_wm_pre = true;
10353 pipe_config->update_wm_post = true;
10357 if (visible || was_visible)
10358 pipe_config->fb_bits |= plane->frontbuffer_bit;
10361 * WaCxSRDisabledForSpriteScaling:ivb
10363 * cstate->update_wm was already set above, so this flag will
10364 * take effect when we commit and program watermarks.
10366 if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) &&
10367 needs_scaling(to_intel_plane_state(plane_state)) &&
10368 !needs_scaling(old_plane_state))
10369 pipe_config->disable_lp_wm = true;
10374 static bool encoders_cloneable(const struct intel_encoder *a,
10375 const struct intel_encoder *b)
10377 /* masks could be asymmetric, so check both ways */
10378 return a == b || (a->cloneable & (1 << b->type) &&
10379 b->cloneable & (1 << a->type));
10382 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10383 struct intel_crtc *crtc,
10384 struct intel_encoder *encoder)
10386 struct intel_encoder *source_encoder;
10387 struct drm_connector *connector;
10388 struct drm_connector_state *connector_state;
10391 for_each_new_connector_in_state(state, connector, connector_state, i) {
10392 if (connector_state->crtc != &crtc->base)
10396 to_intel_encoder(connector_state->best_encoder);
10397 if (!encoders_cloneable(encoder, source_encoder))
10404 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10405 struct drm_crtc_state *crtc_state)
10407 struct drm_device *dev = crtc->dev;
10408 struct drm_i915_private *dev_priv = to_i915(dev);
10409 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10410 struct intel_crtc_state *pipe_config =
10411 to_intel_crtc_state(crtc_state);
10412 struct drm_atomic_state *state = crtc_state->state;
10414 bool mode_changed = needs_modeset(crtc_state);
10416 if (mode_changed && !crtc_state->active)
10417 pipe_config->update_wm_post = true;
10419 if (mode_changed && crtc_state->enable &&
10420 dev_priv->display.crtc_compute_clock &&
10421 !WARN_ON(pipe_config->shared_dpll)) {
10422 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10428 if (crtc_state->color_mgmt_changed) {
10429 ret = intel_color_check(crtc, crtc_state);
10434 * Changing color management on Intel hardware is
10435 * handled as part of planes update.
10437 crtc_state->planes_changed = true;
10441 if (dev_priv->display.compute_pipe_wm) {
10442 ret = dev_priv->display.compute_pipe_wm(pipe_config);
10444 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10449 if (dev_priv->display.compute_intermediate_wm &&
10450 !to_intel_atomic_state(state)->skip_intermediate_wm) {
10451 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10455 * Calculate 'intermediate' watermarks that satisfy both the
10456 * old state and the new state. We can program these
10459 ret = dev_priv->display.compute_intermediate_wm(dev,
10463 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10466 } else if (dev_priv->display.compute_intermediate_wm) {
10467 if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
10468 pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
10471 if (INTEL_GEN(dev_priv) >= 9) {
10473 ret = skl_update_scaler_crtc(pipe_config);
10476 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10479 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
10483 if (HAS_IPS(dev_priv))
10484 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10489 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
10490 .atomic_begin = intel_begin_crtc_commit,
10491 .atomic_flush = intel_finish_crtc_commit,
10492 .atomic_check = intel_crtc_atomic_check,
10495 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10497 struct intel_connector *connector;
10498 struct drm_connector_list_iter conn_iter;
10500 drm_connector_list_iter_begin(dev, &conn_iter);
10501 for_each_intel_connector_iter(connector, &conn_iter) {
10502 if (connector->base.state->crtc)
10503 drm_connector_unreference(&connector->base);
10505 if (connector->base.encoder) {
10506 connector->base.state->best_encoder =
10507 connector->base.encoder;
10508 connector->base.state->crtc =
10509 connector->base.encoder->crtc;
10511 drm_connector_reference(&connector->base);
10513 connector->base.state->best_encoder = NULL;
10514 connector->base.state->crtc = NULL;
10517 drm_connector_list_iter_end(&conn_iter);
10521 connected_sink_compute_bpp(struct intel_connector *connector,
10522 struct intel_crtc_state *pipe_config)
10524 const struct drm_display_info *info = &connector->base.display_info;
10525 int bpp = pipe_config->pipe_bpp;
10527 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10528 connector->base.base.id,
10529 connector->base.name);
10531 /* Don't use an invalid EDID bpc value */
10532 if (info->bpc != 0 && info->bpc * 3 < bpp) {
10533 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10534 bpp, info->bpc * 3);
10535 pipe_config->pipe_bpp = info->bpc * 3;
10538 /* Clamp bpp to 8 on screens without EDID 1.4 */
10539 if (info->bpc == 0 && bpp > 24) {
10540 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10542 pipe_config->pipe_bpp = 24;
10547 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
10548 struct intel_crtc_state *pipe_config)
10550 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10551 struct drm_atomic_state *state;
10552 struct drm_connector *connector;
10553 struct drm_connector_state *connector_state;
10556 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10557 IS_CHERRYVIEW(dev_priv)))
10559 else if (INTEL_GEN(dev_priv) >= 5)
10565 pipe_config->pipe_bpp = bpp;
10567 state = pipe_config->base.state;
10569 /* Clamp display bpp to EDID value */
10570 for_each_new_connector_in_state(state, connector, connector_state, i) {
10571 if (connector_state->crtc != &crtc->base)
10574 connected_sink_compute_bpp(to_intel_connector(connector),
10581 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
10583 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10584 "type: 0x%x flags: 0x%x\n",
10586 mode->crtc_hdisplay, mode->crtc_hsync_start,
10587 mode->crtc_hsync_end, mode->crtc_htotal,
10588 mode->crtc_vdisplay, mode->crtc_vsync_start,
10589 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
10593 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
10594 unsigned int lane_count, struct intel_link_m_n *m_n)
10596 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10598 m_n->gmch_m, m_n->gmch_n,
10599 m_n->link_m, m_n->link_n, m_n->tu);
10602 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
10604 static const char * const output_type_str[] = {
10605 OUTPUT_TYPE(UNUSED),
10606 OUTPUT_TYPE(ANALOG),
10610 OUTPUT_TYPE(TVOUT),
10616 OUTPUT_TYPE(DP_MST),
10621 static void snprintf_output_types(char *buf, size_t len,
10622 unsigned int output_types)
10629 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
10632 if ((output_types & BIT(i)) == 0)
10635 r = snprintf(str, len, "%s%s",
10636 str != buf ? "," : "", output_type_str[i]);
10642 output_types &= ~BIT(i);
10645 WARN_ON_ONCE(output_types != 0);
10648 static void intel_dump_pipe_config(struct intel_crtc *crtc,
10649 struct intel_crtc_state *pipe_config,
10650 const char *context)
10652 struct drm_device *dev = crtc->base.dev;
10653 struct drm_i915_private *dev_priv = to_i915(dev);
10654 struct drm_plane *plane;
10655 struct intel_plane *intel_plane;
10656 struct intel_plane_state *state;
10657 struct drm_framebuffer *fb;
10660 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10661 crtc->base.base.id, crtc->base.name, context);
10663 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
10664 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
10665 buf, pipe_config->output_types);
10667 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10668 transcoder_name(pipe_config->cpu_transcoder),
10669 pipe_config->pipe_bpp, pipe_config->dither);
10671 if (pipe_config->has_pch_encoder)
10672 intel_dump_m_n_config(pipe_config, "fdi",
10673 pipe_config->fdi_lanes,
10674 &pipe_config->fdi_m_n);
10676 if (pipe_config->ycbcr420)
10677 DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
10679 if (intel_crtc_has_dp_encoder(pipe_config)) {
10680 intel_dump_m_n_config(pipe_config, "dp m_n",
10681 pipe_config->lane_count, &pipe_config->dp_m_n);
10682 if (pipe_config->has_drrs)
10683 intel_dump_m_n_config(pipe_config, "dp m2_n2",
10684 pipe_config->lane_count,
10685 &pipe_config->dp_m2_n2);
10688 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10689 pipe_config->has_audio, pipe_config->has_infoframe);
10691 DRM_DEBUG_KMS("requested mode:\n");
10692 drm_mode_debug_printmodeline(&pipe_config->base.mode);
10693 DRM_DEBUG_KMS("adjusted mode:\n");
10694 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
10695 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
10696 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10697 pipe_config->port_clock,
10698 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
10699 pipe_config->pixel_rate);
10701 if (INTEL_GEN(dev_priv) >= 9)
10702 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10704 pipe_config->scaler_state.scaler_users,
10705 pipe_config->scaler_state.scaler_id);
10707 if (HAS_GMCH_DISPLAY(dev_priv))
10708 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10709 pipe_config->gmch_pfit.control,
10710 pipe_config->gmch_pfit.pgm_ratios,
10711 pipe_config->gmch_pfit.lvds_border_bits);
10713 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10714 pipe_config->pch_pfit.pos,
10715 pipe_config->pch_pfit.size,
10716 enableddisabled(pipe_config->pch_pfit.enabled));
10718 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10719 pipe_config->ips_enabled, pipe_config->double_wide);
10721 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
10723 DRM_DEBUG_KMS("planes on this crtc\n");
10724 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
10725 struct drm_format_name_buf format_name;
10726 intel_plane = to_intel_plane(plane);
10727 if (intel_plane->pipe != crtc->pipe)
10730 state = to_intel_plane_state(plane->state);
10731 fb = state->base.fb;
10733 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10734 plane->base.id, plane->name, state->scaler_id);
10738 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10739 plane->base.id, plane->name,
10740 fb->base.id, fb->width, fb->height,
10741 drm_get_format_name(fb->format->format, &format_name));
10742 if (INTEL_GEN(dev_priv) >= 9)
10743 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10745 state->base.src.x1 >> 16,
10746 state->base.src.y1 >> 16,
10747 drm_rect_width(&state->base.src) >> 16,
10748 drm_rect_height(&state->base.src) >> 16,
10749 state->base.dst.x1, state->base.dst.y1,
10750 drm_rect_width(&state->base.dst),
10751 drm_rect_height(&state->base.dst));
10755 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
10757 struct drm_device *dev = state->dev;
10758 struct drm_connector *connector;
10759 struct drm_connector_list_iter conn_iter;
10760 unsigned int used_ports = 0;
10761 unsigned int used_mst_ports = 0;
10765 * Walk the connector list instead of the encoder
10766 * list to detect the problem on ddi platforms
10767 * where there's just one encoder per digital port.
10769 drm_connector_list_iter_begin(dev, &conn_iter);
10770 drm_for_each_connector_iter(connector, &conn_iter) {
10771 struct drm_connector_state *connector_state;
10772 struct intel_encoder *encoder;
10774 connector_state = drm_atomic_get_existing_connector_state(state, connector);
10775 if (!connector_state)
10776 connector_state = connector->state;
10778 if (!connector_state->best_encoder)
10781 encoder = to_intel_encoder(connector_state->best_encoder);
10783 WARN_ON(!connector_state->crtc);
10785 switch (encoder->type) {
10786 unsigned int port_mask;
10787 case INTEL_OUTPUT_DDI:
10788 if (WARN_ON(!HAS_DDI(to_i915(dev))))
10790 case INTEL_OUTPUT_DP:
10791 case INTEL_OUTPUT_HDMI:
10792 case INTEL_OUTPUT_EDP:
10793 port_mask = 1 << encoder->port;
10795 /* the same port mustn't appear more than once */
10796 if (used_ports & port_mask)
10799 used_ports |= port_mask;
10801 case INTEL_OUTPUT_DP_MST:
10803 1 << encoder->port;
10809 drm_connector_list_iter_end(&conn_iter);
10811 /* can't mix MST and SST/HDMI on the same port */
10812 if (used_ports & used_mst_ports)
10819 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
10821 struct drm_i915_private *dev_priv =
10822 to_i915(crtc_state->base.crtc->dev);
10823 struct intel_crtc_scaler_state scaler_state;
10824 struct intel_dpll_hw_state dpll_hw_state;
10825 struct intel_shared_dpll *shared_dpll;
10826 struct intel_crtc_wm_state wm_state;
10827 bool force_thru, ips_force_disable;
10829 /* FIXME: before the switch to atomic started, a new pipe_config was
10830 * kzalloc'd. Code that depends on any field being zero should be
10831 * fixed, so that the crtc_state can be safely duplicated. For now,
10832 * only fields that are know to not cause problems are preserved. */
10834 scaler_state = crtc_state->scaler_state;
10835 shared_dpll = crtc_state->shared_dpll;
10836 dpll_hw_state = crtc_state->dpll_hw_state;
10837 force_thru = crtc_state->pch_pfit.force_thru;
10838 ips_force_disable = crtc_state->ips_force_disable;
10839 if (IS_G4X(dev_priv) ||
10840 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10841 wm_state = crtc_state->wm;
10843 /* Keep base drm_crtc_state intact, only clear our extended struct */
10844 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
10845 memset(&crtc_state->base + 1, 0,
10846 sizeof(*crtc_state) - sizeof(crtc_state->base));
10848 crtc_state->scaler_state = scaler_state;
10849 crtc_state->shared_dpll = shared_dpll;
10850 crtc_state->dpll_hw_state = dpll_hw_state;
10851 crtc_state->pch_pfit.force_thru = force_thru;
10852 crtc_state->ips_force_disable = ips_force_disable;
10853 if (IS_G4X(dev_priv) ||
10854 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10855 crtc_state->wm = wm_state;
10859 intel_modeset_pipe_config(struct drm_crtc *crtc,
10860 struct intel_crtc_state *pipe_config)
10862 struct drm_atomic_state *state = pipe_config->base.state;
10863 struct intel_encoder *encoder;
10864 struct drm_connector *connector;
10865 struct drm_connector_state *connector_state;
10866 int base_bpp, ret = -EINVAL;
10870 clear_intel_crtc_state(pipe_config);
10872 pipe_config->cpu_transcoder =
10873 (enum transcoder) to_intel_crtc(crtc)->pipe;
10876 * Sanitize sync polarity flags based on requested ones. If neither
10877 * positive or negative polarity is requested, treat this as meaning
10878 * negative polarity.
10880 if (!(pipe_config->base.adjusted_mode.flags &
10881 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
10882 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
10884 if (!(pipe_config->base.adjusted_mode.flags &
10885 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
10886 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
10888 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
10894 * Determine the real pipe dimensions. Note that stereo modes can
10895 * increase the actual pipe size due to the frame doubling and
10896 * insertion of additional space for blanks between the frame. This
10897 * is stored in the crtc timings. We use the requested mode to do this
10898 * computation to clearly distinguish it from the adjusted mode, which
10899 * can be changed by the connectors in the below retry loop.
10901 drm_mode_get_hv_timing(&pipe_config->base.mode,
10902 &pipe_config->pipe_src_w,
10903 &pipe_config->pipe_src_h);
10905 for_each_new_connector_in_state(state, connector, connector_state, i) {
10906 if (connector_state->crtc != crtc)
10909 encoder = to_intel_encoder(connector_state->best_encoder);
10911 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
10912 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10917 * Determine output_types before calling the .compute_config()
10918 * hooks so that the hooks can use this information safely.
10920 if (encoder->compute_output_type)
10921 pipe_config->output_types |=
10922 BIT(encoder->compute_output_type(encoder, pipe_config,
10925 pipe_config->output_types |= BIT(encoder->type);
10929 /* Ensure the port clock defaults are reset when retrying. */
10930 pipe_config->port_clock = 0;
10931 pipe_config->pixel_multiplier = 1;
10933 /* Fill in default crtc timings, allow encoders to overwrite them. */
10934 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
10935 CRTC_STEREO_DOUBLE);
10937 /* Pass our mode to the connectors and the CRTC to give them a chance to
10938 * adjust it according to limitations or connector properties, and also
10939 * a chance to reject the mode entirely.
10941 for_each_new_connector_in_state(state, connector, connector_state, i) {
10942 if (connector_state->crtc != crtc)
10945 encoder = to_intel_encoder(connector_state->best_encoder);
10947 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
10948 DRM_DEBUG_KMS("Encoder config failure\n");
10953 /* Set default port clock if not overwritten by the encoder. Needs to be
10954 * done afterwards in case the encoder adjusts the mode. */
10955 if (!pipe_config->port_clock)
10956 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
10957 * pipe_config->pixel_multiplier;
10959 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
10961 DRM_DEBUG_KMS("CRTC fixup failed\n");
10965 if (ret == RETRY) {
10966 if (WARN(!retry, "loop in pipe configuration computation\n")) {
10971 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10973 goto encoder_retry;
10976 /* Dithering seems to not pass-through bits correctly when it should, so
10977 * only enable it on 6bpc panels and when its not a compliance
10978 * test requesting 6bpc video pattern.
10980 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
10981 !pipe_config->dither_force_disable;
10982 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
10983 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
10989 static bool intel_fuzzy_clock_check(int clock1, int clock2)
10993 if (clock1 == clock2)
10996 if (!clock1 || !clock2)
10999 diff = abs(clock1 - clock2);
11001 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11008 intel_compare_m_n(unsigned int m, unsigned int n,
11009 unsigned int m2, unsigned int n2,
11012 if (m == m2 && n == n2)
11015 if (exact || !m || !n || !m2 || !n2)
11018 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11025 } else if (n < n2) {
11035 return intel_fuzzy_clock_check(m, m2);
11039 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11040 struct intel_link_m_n *m2_n2,
11043 if (m_n->tu == m2_n2->tu &&
11044 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11045 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11046 intel_compare_m_n(m_n->link_m, m_n->link_n,
11047 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11057 static void __printf(3, 4)
11058 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11061 unsigned int category;
11062 struct va_format vaf;
11066 level = KERN_DEBUG;
11067 category = DRM_UT_KMS;
11070 category = DRM_UT_NONE;
11073 va_start(args, format);
11077 drm_printk(level, category, "mismatch in %s %pV", name, &vaf);
11083 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11084 struct intel_crtc_state *current_config,
11085 struct intel_crtc_state *pipe_config,
11089 bool fixup_inherited = adjust &&
11090 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11091 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11093 #define PIPE_CONF_CHECK_X(name) \
11094 if (current_config->name != pipe_config->name) { \
11095 pipe_config_err(adjust, __stringify(name), \
11096 "(expected 0x%08x, found 0x%08x)\n", \
11097 current_config->name, \
11098 pipe_config->name); \
11102 #define PIPE_CONF_CHECK_I(name) \
11103 if (current_config->name != pipe_config->name) { \
11104 pipe_config_err(adjust, __stringify(name), \
11105 "(expected %i, found %i)\n", \
11106 current_config->name, \
11107 pipe_config->name); \
11111 #define PIPE_CONF_CHECK_BOOL(name) \
11112 if (current_config->name != pipe_config->name) { \
11113 pipe_config_err(adjust, __stringify(name), \
11114 "(expected %s, found %s)\n", \
11115 yesno(current_config->name), \
11116 yesno(pipe_config->name)); \
11121 * Checks state where we only read out the enabling, but not the entire
11122 * state itself (like full infoframes or ELD for audio). These states
11123 * require a full modeset on bootup to fix up.
11125 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) \
11126 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11127 PIPE_CONF_CHECK_BOOL(name); \
11129 pipe_config_err(adjust, __stringify(name), \
11130 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11131 yesno(current_config->name), \
11132 yesno(pipe_config->name)); \
11136 #define PIPE_CONF_CHECK_P(name) \
11137 if (current_config->name != pipe_config->name) { \
11138 pipe_config_err(adjust, __stringify(name), \
11139 "(expected %p, found %p)\n", \
11140 current_config->name, \
11141 pipe_config->name); \
11145 #define PIPE_CONF_CHECK_M_N(name) \
11146 if (!intel_compare_link_m_n(¤t_config->name, \
11147 &pipe_config->name,\
11149 pipe_config_err(adjust, __stringify(name), \
11150 "(expected tu %i gmch %i/%i link %i/%i, " \
11151 "found tu %i, gmch %i/%i link %i/%i)\n", \
11152 current_config->name.tu, \
11153 current_config->name.gmch_m, \
11154 current_config->name.gmch_n, \
11155 current_config->name.link_m, \
11156 current_config->name.link_n, \
11157 pipe_config->name.tu, \
11158 pipe_config->name.gmch_m, \
11159 pipe_config->name.gmch_n, \
11160 pipe_config->name.link_m, \
11161 pipe_config->name.link_n); \
11165 /* This is required for BDW+ where there is only one set of registers for
11166 * switching between high and low RR.
11167 * This macro can be used whenever a comparison has to be made between one
11168 * hw state and multiple sw state variables.
11170 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
11171 if (!intel_compare_link_m_n(¤t_config->name, \
11172 &pipe_config->name, adjust) && \
11173 !intel_compare_link_m_n(¤t_config->alt_name, \
11174 &pipe_config->name, adjust)) { \
11175 pipe_config_err(adjust, __stringify(name), \
11176 "(expected tu %i gmch %i/%i link %i/%i, " \
11177 "or tu %i gmch %i/%i link %i/%i, " \
11178 "found tu %i, gmch %i/%i link %i/%i)\n", \
11179 current_config->name.tu, \
11180 current_config->name.gmch_m, \
11181 current_config->name.gmch_n, \
11182 current_config->name.link_m, \
11183 current_config->name.link_n, \
11184 current_config->alt_name.tu, \
11185 current_config->alt_name.gmch_m, \
11186 current_config->alt_name.gmch_n, \
11187 current_config->alt_name.link_m, \
11188 current_config->alt_name.link_n, \
11189 pipe_config->name.tu, \
11190 pipe_config->name.gmch_m, \
11191 pipe_config->name.gmch_n, \
11192 pipe_config->name.link_m, \
11193 pipe_config->name.link_n); \
11197 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
11198 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11199 pipe_config_err(adjust, __stringify(name), \
11200 "(%x) (expected %i, found %i)\n", \
11202 current_config->name & (mask), \
11203 pipe_config->name & (mask)); \
11207 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
11208 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11209 pipe_config_err(adjust, __stringify(name), \
11210 "(expected %i, found %i)\n", \
11211 current_config->name, \
11212 pipe_config->name); \
11216 #define PIPE_CONF_QUIRK(quirk) \
11217 ((current_config->quirks | pipe_config->quirks) & (quirk))
11219 PIPE_CONF_CHECK_I(cpu_transcoder);
11221 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11222 PIPE_CONF_CHECK_I(fdi_lanes);
11223 PIPE_CONF_CHECK_M_N(fdi_m_n);
11225 PIPE_CONF_CHECK_I(lane_count);
11226 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11228 if (INTEL_GEN(dev_priv) < 8) {
11229 PIPE_CONF_CHECK_M_N(dp_m_n);
11231 if (current_config->has_drrs)
11232 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11234 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11236 PIPE_CONF_CHECK_X(output_types);
11238 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11239 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11240 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11241 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11242 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11243 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
11245 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11246 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11247 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11248 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11249 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11250 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
11252 PIPE_CONF_CHECK_I(pixel_multiplier);
11253 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11254 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11255 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11256 PIPE_CONF_CHECK_BOOL(limited_color_range);
11258 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11259 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11260 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
11261 PIPE_CONF_CHECK_BOOL(ycbcr420);
11263 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11265 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11266 DRM_MODE_FLAG_INTERLACE);
11268 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11269 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11270 DRM_MODE_FLAG_PHSYNC);
11271 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11272 DRM_MODE_FLAG_NHSYNC);
11273 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11274 DRM_MODE_FLAG_PVSYNC);
11275 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11276 DRM_MODE_FLAG_NVSYNC);
11279 PIPE_CONF_CHECK_X(gmch_pfit.control);
11280 /* pfit ratios are autocomputed by the hw on gen4+ */
11281 if (INTEL_GEN(dev_priv) < 4)
11282 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11283 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11286 PIPE_CONF_CHECK_I(pipe_src_w);
11287 PIPE_CONF_CHECK_I(pipe_src_h);
11289 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11290 if (current_config->pch_pfit.enabled) {
11291 PIPE_CONF_CHECK_X(pch_pfit.pos);
11292 PIPE_CONF_CHECK_X(pch_pfit.size);
11295 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11296 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11299 PIPE_CONF_CHECK_BOOL(double_wide);
11301 PIPE_CONF_CHECK_P(shared_dpll);
11302 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11303 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11304 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11305 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11306 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11307 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11308 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11309 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11310 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11311 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11312 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11313 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11314 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11315 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11316 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11317 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11318 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11319 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11320 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11321 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11322 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11324 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11325 PIPE_CONF_CHECK_X(dsi_pll.div);
11327 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11328 PIPE_CONF_CHECK_I(pipe_bpp);
11330 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
11331 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11333 PIPE_CONF_CHECK_I(min_voltage_level);
11335 #undef PIPE_CONF_CHECK_X
11336 #undef PIPE_CONF_CHECK_I
11337 #undef PIPE_CONF_CHECK_BOOL
11338 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11339 #undef PIPE_CONF_CHECK_P
11340 #undef PIPE_CONF_CHECK_FLAGS
11341 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11342 #undef PIPE_CONF_QUIRK
11347 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11348 const struct intel_crtc_state *pipe_config)
11350 if (pipe_config->has_pch_encoder) {
11351 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11352 &pipe_config->fdi_m_n);
11353 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11356 * FDI already provided one idea for the dotclock.
11357 * Yell if the encoder disagrees.
11359 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11360 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11361 fdi_dotclock, dotclock);
11365 static void verify_wm_state(struct drm_crtc *crtc,
11366 struct drm_crtc_state *new_state)
11368 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11369 struct skl_ddb_allocation hw_ddb, *sw_ddb;
11370 struct skl_pipe_wm hw_wm, *sw_wm;
11371 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11372 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11373 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11374 const enum pipe pipe = intel_crtc->pipe;
11375 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11377 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
11380 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
11381 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
11383 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11384 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11387 for_each_universal_plane(dev_priv, pipe, plane) {
11388 hw_plane_wm = &hw_wm.planes[plane];
11389 sw_plane_wm = &sw_wm->planes[plane];
11392 for (level = 0; level <= max_level; level++) {
11393 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11394 &sw_plane_wm->wm[level]))
11397 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",
11398 pipe_name(pipe), plane + 1, level,
11399 sw_plane_wm->wm[level].plane_en,
11400 sw_plane_wm->wm[level].plane_res_b,
11401 sw_plane_wm->wm[level].plane_res_l,
11402 hw_plane_wm->wm[level].plane_en,
11403 hw_plane_wm->wm[level].plane_res_b,
11404 hw_plane_wm->wm[level].plane_res_l);
11407 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11408 &sw_plane_wm->trans_wm)) {
11409 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",
11410 pipe_name(pipe), plane + 1,
11411 sw_plane_wm->trans_wm.plane_en,
11412 sw_plane_wm->trans_wm.plane_res_b,
11413 sw_plane_wm->trans_wm.plane_res_l,
11414 hw_plane_wm->trans_wm.plane_en,
11415 hw_plane_wm->trans_wm.plane_res_b,
11416 hw_plane_wm->trans_wm.plane_res_l);
11420 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11421 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11423 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11424 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11425 pipe_name(pipe), plane + 1,
11426 sw_ddb_entry->start, sw_ddb_entry->end,
11427 hw_ddb_entry->start, hw_ddb_entry->end);
11433 * If the cursor plane isn't active, we may not have updated it's ddb
11434 * allocation. In that case since the ddb allocation will be updated
11435 * once the plane becomes visible, we can skip this check
11438 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11439 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
11442 for (level = 0; level <= max_level; level++) {
11443 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11444 &sw_plane_wm->wm[level]))
11447 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",
11448 pipe_name(pipe), level,
11449 sw_plane_wm->wm[level].plane_en,
11450 sw_plane_wm->wm[level].plane_res_b,
11451 sw_plane_wm->wm[level].plane_res_l,
11452 hw_plane_wm->wm[level].plane_en,
11453 hw_plane_wm->wm[level].plane_res_b,
11454 hw_plane_wm->wm[level].plane_res_l);
11457 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11458 &sw_plane_wm->trans_wm)) {
11459 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11461 sw_plane_wm->trans_wm.plane_en,
11462 sw_plane_wm->trans_wm.plane_res_b,
11463 sw_plane_wm->trans_wm.plane_res_l,
11464 hw_plane_wm->trans_wm.plane_en,
11465 hw_plane_wm->trans_wm.plane_res_b,
11466 hw_plane_wm->trans_wm.plane_res_l);
11470 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11471 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11473 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11474 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11476 sw_ddb_entry->start, sw_ddb_entry->end,
11477 hw_ddb_entry->start, hw_ddb_entry->end);
11483 verify_connector_state(struct drm_device *dev,
11484 struct drm_atomic_state *state,
11485 struct drm_crtc *crtc)
11487 struct drm_connector *connector;
11488 struct drm_connector_state *new_conn_state;
11491 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
11492 struct drm_encoder *encoder = connector->encoder;
11493 struct drm_crtc_state *crtc_state = NULL;
11495 if (new_conn_state->crtc != crtc)
11499 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11501 intel_connector_verify_state(crtc_state, new_conn_state);
11503 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
11504 "connector's atomic encoder doesn't match legacy encoder\n");
11509 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
11511 struct intel_encoder *encoder;
11512 struct drm_connector *connector;
11513 struct drm_connector_state *old_conn_state, *new_conn_state;
11516 for_each_intel_encoder(dev, encoder) {
11517 bool enabled = false, found = false;
11520 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11521 encoder->base.base.id,
11522 encoder->base.name);
11524 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
11525 new_conn_state, i) {
11526 if (old_conn_state->best_encoder == &encoder->base)
11529 if (new_conn_state->best_encoder != &encoder->base)
11531 found = enabled = true;
11533 I915_STATE_WARN(new_conn_state->crtc !=
11534 encoder->base.crtc,
11535 "connector's crtc doesn't match encoder crtc\n");
11541 I915_STATE_WARN(!!encoder->base.crtc != enabled,
11542 "encoder's enabled state mismatch "
11543 "(expected %i, found %i)\n",
11544 !!encoder->base.crtc, enabled);
11546 if (!encoder->base.crtc) {
11549 active = encoder->get_hw_state(encoder, &pipe);
11550 I915_STATE_WARN(active,
11551 "encoder detached but still enabled on pipe %c.\n",
11558 verify_crtc_state(struct drm_crtc *crtc,
11559 struct drm_crtc_state *old_crtc_state,
11560 struct drm_crtc_state *new_crtc_state)
11562 struct drm_device *dev = crtc->dev;
11563 struct drm_i915_private *dev_priv = to_i915(dev);
11564 struct intel_encoder *encoder;
11565 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11566 struct intel_crtc_state *pipe_config, *sw_config;
11567 struct drm_atomic_state *old_state;
11570 old_state = old_crtc_state->state;
11571 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
11572 pipe_config = to_intel_crtc_state(old_crtc_state);
11573 memset(pipe_config, 0, sizeof(*pipe_config));
11574 pipe_config->base.crtc = crtc;
11575 pipe_config->base.state = old_state;
11577 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
11579 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
11581 /* we keep both pipes enabled on 830 */
11582 if (IS_I830(dev_priv))
11583 active = new_crtc_state->active;
11585 I915_STATE_WARN(new_crtc_state->active != active,
11586 "crtc active state doesn't match with hw state "
11587 "(expected %i, found %i)\n", new_crtc_state->active, active);
11589 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
11590 "transitional active state does not match atomic hw state "
11591 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
11593 for_each_encoder_on_crtc(dev, crtc, encoder) {
11596 active = encoder->get_hw_state(encoder, &pipe);
11597 I915_STATE_WARN(active != new_crtc_state->active,
11598 "[ENCODER:%i] active %i with crtc active %i\n",
11599 encoder->base.base.id, active, new_crtc_state->active);
11601 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
11602 "Encoder connected to wrong pipe %c\n",
11606 encoder->get_config(encoder, pipe_config);
11609 intel_crtc_compute_pixel_rate(pipe_config);
11611 if (!new_crtc_state->active)
11614 intel_pipe_config_sanity_check(dev_priv, pipe_config);
11616 sw_config = to_intel_crtc_state(new_crtc_state);
11617 if (!intel_pipe_config_compare(dev_priv, sw_config,
11618 pipe_config, false)) {
11619 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11620 intel_dump_pipe_config(intel_crtc, pipe_config,
11622 intel_dump_pipe_config(intel_crtc, sw_config,
11628 intel_verify_planes(struct intel_atomic_state *state)
11630 struct intel_plane *plane;
11631 const struct intel_plane_state *plane_state;
11634 for_each_new_intel_plane_in_state(state, plane,
11636 assert_plane(plane, plane_state->base.visible);
11640 verify_single_dpll_state(struct drm_i915_private *dev_priv,
11641 struct intel_shared_dpll *pll,
11642 struct drm_crtc *crtc,
11643 struct drm_crtc_state *new_state)
11645 struct intel_dpll_hw_state dpll_hw_state;
11646 unsigned crtc_mask;
11649 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
11651 DRM_DEBUG_KMS("%s\n", pll->name);
11653 active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state);
11655 if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) {
11656 I915_STATE_WARN(!pll->on && pll->active_mask,
11657 "pll in active use but not on in sw tracking\n");
11658 I915_STATE_WARN(pll->on && !pll->active_mask,
11659 "pll is on but not used by any active crtc\n");
11660 I915_STATE_WARN(pll->on != active,
11661 "pll on state mismatch (expected %i, found %i)\n",
11666 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
11667 "more active pll users than references: %x vs %x\n",
11668 pll->active_mask, pll->state.crtc_mask);
11673 crtc_mask = 1 << drm_crtc_index(crtc);
11675 if (new_state->active)
11676 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
11677 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11678 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11680 I915_STATE_WARN(pll->active_mask & crtc_mask,
11681 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11682 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11684 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
11685 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11686 crtc_mask, pll->state.crtc_mask);
11688 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
11690 sizeof(dpll_hw_state)),
11691 "pll hw state mismatch\n");
11695 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
11696 struct drm_crtc_state *old_crtc_state,
11697 struct drm_crtc_state *new_crtc_state)
11699 struct drm_i915_private *dev_priv = to_i915(dev);
11700 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
11701 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
11703 if (new_state->shared_dpll)
11704 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
11706 if (old_state->shared_dpll &&
11707 old_state->shared_dpll != new_state->shared_dpll) {
11708 unsigned crtc_mask = 1 << drm_crtc_index(crtc);
11709 struct intel_shared_dpll *pll = old_state->shared_dpll;
11711 I915_STATE_WARN(pll->active_mask & crtc_mask,
11712 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11713 pipe_name(drm_crtc_index(crtc)));
11714 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
11715 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11716 pipe_name(drm_crtc_index(crtc)));
11721 intel_modeset_verify_crtc(struct drm_crtc *crtc,
11722 struct drm_atomic_state *state,
11723 struct drm_crtc_state *old_state,
11724 struct drm_crtc_state *new_state)
11726 if (!needs_modeset(new_state) &&
11727 !to_intel_crtc_state(new_state)->update_pipe)
11730 verify_wm_state(crtc, new_state);
11731 verify_connector_state(crtc->dev, state, crtc);
11732 verify_crtc_state(crtc, old_state, new_state);
11733 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
11737 verify_disabled_dpll_state(struct drm_device *dev)
11739 struct drm_i915_private *dev_priv = to_i915(dev);
11742 for (i = 0; i < dev_priv->num_shared_dpll; i++)
11743 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
11747 intel_modeset_verify_disabled(struct drm_device *dev,
11748 struct drm_atomic_state *state)
11750 verify_encoder_state(dev, state);
11751 verify_connector_state(dev, state, NULL);
11752 verify_disabled_dpll_state(dev);
11755 static void update_scanline_offset(struct intel_crtc *crtc)
11757 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11760 * The scanline counter increments at the leading edge of hsync.
11762 * On most platforms it starts counting from vtotal-1 on the
11763 * first active line. That means the scanline counter value is
11764 * always one less than what we would expect. Ie. just after
11765 * start of vblank, which also occurs at start of hsync (on the
11766 * last active line), the scanline counter will read vblank_start-1.
11768 * On gen2 the scanline counter starts counting from 1 instead
11769 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11770 * to keep the value positive), instead of adding one.
11772 * On HSW+ the behaviour of the scanline counter depends on the output
11773 * type. For DP ports it behaves like most other platforms, but on HDMI
11774 * there's an extra 1 line difference. So we need to add two instead of
11775 * one to the value.
11777 * On VLV/CHV DSI the scanline counter would appear to increment
11778 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11779 * that means we can't tell whether we're in vblank or not while
11780 * we're on that particular line. We must still set scanline_offset
11781 * to 1 so that the vblank timestamps come out correct when we query
11782 * the scanline counter from within the vblank interrupt handler.
11783 * However if queried just before the start of vblank we'll get an
11784 * answer that's slightly in the future.
11786 if (IS_GEN2(dev_priv)) {
11787 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
11790 vtotal = adjusted_mode->crtc_vtotal;
11791 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
11794 crtc->scanline_offset = vtotal - 1;
11795 } else if (HAS_DDI(dev_priv) &&
11796 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) {
11797 crtc->scanline_offset = 2;
11799 crtc->scanline_offset = 1;
11802 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
11804 struct drm_device *dev = state->dev;
11805 struct drm_i915_private *dev_priv = to_i915(dev);
11806 struct drm_crtc *crtc;
11807 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
11810 if (!dev_priv->display.crtc_compute_clock)
11813 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
11814 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11815 struct intel_shared_dpll *old_dpll =
11816 to_intel_crtc_state(old_crtc_state)->shared_dpll;
11818 if (!needs_modeset(new_crtc_state))
11821 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
11826 intel_release_shared_dpll(old_dpll, intel_crtc, state);
11831 * This implements the workaround described in the "notes" section of the mode
11832 * set sequence documentation. When going from no pipes or single pipe to
11833 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11834 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11836 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
11838 struct drm_crtc_state *crtc_state;
11839 struct intel_crtc *intel_crtc;
11840 struct drm_crtc *crtc;
11841 struct intel_crtc_state *first_crtc_state = NULL;
11842 struct intel_crtc_state *other_crtc_state = NULL;
11843 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
11846 /* look at all crtc's that are going to be enabled in during modeset */
11847 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
11848 intel_crtc = to_intel_crtc(crtc);
11850 if (!crtc_state->active || !needs_modeset(crtc_state))
11853 if (first_crtc_state) {
11854 other_crtc_state = to_intel_crtc_state(crtc_state);
11857 first_crtc_state = to_intel_crtc_state(crtc_state);
11858 first_pipe = intel_crtc->pipe;
11862 /* No workaround needed? */
11863 if (!first_crtc_state)
11866 /* w/a possibly needed, check how many crtc's are already enabled. */
11867 for_each_intel_crtc(state->dev, intel_crtc) {
11868 struct intel_crtc_state *pipe_config;
11870 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
11871 if (IS_ERR(pipe_config))
11872 return PTR_ERR(pipe_config);
11874 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
11876 if (!pipe_config->base.active ||
11877 needs_modeset(&pipe_config->base))
11880 /* 2 or more enabled crtcs means no need for w/a */
11881 if (enabled_pipe != INVALID_PIPE)
11884 enabled_pipe = intel_crtc->pipe;
11887 if (enabled_pipe != INVALID_PIPE)
11888 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
11889 else if (other_crtc_state)
11890 other_crtc_state->hsw_workaround_pipe = first_pipe;
11895 static int intel_lock_all_pipes(struct drm_atomic_state *state)
11897 struct drm_crtc *crtc;
11899 /* Add all pipes to the state */
11900 for_each_crtc(state->dev, crtc) {
11901 struct drm_crtc_state *crtc_state;
11903 crtc_state = drm_atomic_get_crtc_state(state, crtc);
11904 if (IS_ERR(crtc_state))
11905 return PTR_ERR(crtc_state);
11911 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
11913 struct drm_crtc *crtc;
11916 * Add all pipes to the state, and force
11917 * a modeset on all the active ones.
11919 for_each_crtc(state->dev, crtc) {
11920 struct drm_crtc_state *crtc_state;
11923 crtc_state = drm_atomic_get_crtc_state(state, crtc);
11924 if (IS_ERR(crtc_state))
11925 return PTR_ERR(crtc_state);
11927 if (!crtc_state->active || needs_modeset(crtc_state))
11930 crtc_state->mode_changed = true;
11932 ret = drm_atomic_add_affected_connectors(state, crtc);
11936 ret = drm_atomic_add_affected_planes(state, crtc);
11944 static int intel_modeset_checks(struct drm_atomic_state *state)
11946 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
11947 struct drm_i915_private *dev_priv = to_i915(state->dev);
11948 struct drm_crtc *crtc;
11949 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
11952 if (!check_digital_port_conflicts(state)) {
11953 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11957 intel_state->modeset = true;
11958 intel_state->active_crtcs = dev_priv->active_crtcs;
11959 intel_state->cdclk.logical = dev_priv->cdclk.logical;
11960 intel_state->cdclk.actual = dev_priv->cdclk.actual;
11962 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
11963 if (new_crtc_state->active)
11964 intel_state->active_crtcs |= 1 << i;
11966 intel_state->active_crtcs &= ~(1 << i);
11968 if (old_crtc_state->active != new_crtc_state->active)
11969 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
11973 * See if the config requires any additional preparation, e.g.
11974 * to adjust global state with pipes off. We need to do this
11975 * here so we can get the modeset_pipe updated config for the new
11976 * mode set on this crtc. For other crtcs we need to use the
11977 * adjusted_mode bits in the crtc directly.
11979 if (dev_priv->display.modeset_calc_cdclk) {
11980 ret = dev_priv->display.modeset_calc_cdclk(state);
11985 * Writes to dev_priv->cdclk.logical must protected by
11986 * holding all the crtc locks, even if we don't end up
11987 * touching the hardware
11989 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
11990 &intel_state->cdclk.logical)) {
11991 ret = intel_lock_all_pipes(state);
11996 /* All pipes must be switched off while we change the cdclk. */
11997 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
11998 &intel_state->cdclk.actual)) {
11999 ret = intel_modeset_all_pipes(state);
12004 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12005 intel_state->cdclk.logical.cdclk,
12006 intel_state->cdclk.actual.cdclk);
12007 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12008 intel_state->cdclk.logical.voltage_level,
12009 intel_state->cdclk.actual.voltage_level);
12011 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12014 intel_modeset_clear_plls(state);
12016 if (IS_HASWELL(dev_priv))
12017 return haswell_mode_set_planes_workaround(state);
12023 * Handle calculation of various watermark data at the end of the atomic check
12024 * phase. The code here should be run after the per-crtc and per-plane 'check'
12025 * handlers to ensure that all derived state has been updated.
12027 static int calc_watermark_data(struct drm_atomic_state *state)
12029 struct drm_device *dev = state->dev;
12030 struct drm_i915_private *dev_priv = to_i915(dev);
12032 /* Is there platform-specific watermark information to calculate? */
12033 if (dev_priv->display.compute_global_watermarks)
12034 return dev_priv->display.compute_global_watermarks(state);
12040 * intel_atomic_check - validate state object
12042 * @state: state to validate
12044 static int intel_atomic_check(struct drm_device *dev,
12045 struct drm_atomic_state *state)
12047 struct drm_i915_private *dev_priv = to_i915(dev);
12048 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12049 struct drm_crtc *crtc;
12050 struct drm_crtc_state *old_crtc_state, *crtc_state;
12052 bool any_ms = false;
12054 /* Catch I915_MODE_FLAG_INHERITED */
12055 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12057 if (crtc_state->mode.private_flags !=
12058 old_crtc_state->mode.private_flags)
12059 crtc_state->mode_changed = true;
12062 ret = drm_atomic_helper_check_modeset(dev, state);
12066 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12067 struct intel_crtc_state *pipe_config =
12068 to_intel_crtc_state(crtc_state);
12070 if (!needs_modeset(crtc_state))
12073 if (!crtc_state->enable) {
12078 ret = intel_modeset_pipe_config(crtc, pipe_config);
12080 intel_dump_pipe_config(to_intel_crtc(crtc),
12081 pipe_config, "[failed]");
12085 if (i915_modparams.fastboot &&
12086 intel_pipe_config_compare(dev_priv,
12087 to_intel_crtc_state(old_crtc_state),
12088 pipe_config, true)) {
12089 crtc_state->mode_changed = false;
12090 pipe_config->update_pipe = true;
12093 if (needs_modeset(crtc_state))
12096 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12097 needs_modeset(crtc_state) ?
12098 "[modeset]" : "[fastset]");
12102 ret = intel_modeset_checks(state);
12107 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12110 ret = drm_atomic_helper_check_planes(dev, state);
12114 intel_fbc_choose_crtc(dev_priv, intel_state);
12115 return calc_watermark_data(state);
12118 static int intel_atomic_prepare_commit(struct drm_device *dev,
12119 struct drm_atomic_state *state)
12121 return drm_atomic_helper_prepare_planes(dev, state);
12124 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12126 struct drm_device *dev = crtc->base.dev;
12128 if (!dev->max_vblank_count)
12129 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
12131 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12134 static void intel_update_crtc(struct drm_crtc *crtc,
12135 struct drm_atomic_state *state,
12136 struct drm_crtc_state *old_crtc_state,
12137 struct drm_crtc_state *new_crtc_state)
12139 struct drm_device *dev = crtc->dev;
12140 struct drm_i915_private *dev_priv = to_i915(dev);
12141 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12142 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12143 bool modeset = needs_modeset(new_crtc_state);
12146 update_scanline_offset(intel_crtc);
12147 dev_priv->display.crtc_enable(pipe_config, state);
12149 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12153 if (drm_atomic_get_existing_plane_state(state, crtc->primary)) {
12155 intel_crtc, pipe_config,
12156 to_intel_plane_state(crtc->primary->state));
12159 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state);
12162 static void intel_update_crtcs(struct drm_atomic_state *state)
12164 struct drm_crtc *crtc;
12165 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12168 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12169 if (!new_crtc_state->active)
12172 intel_update_crtc(crtc, state, old_crtc_state,
12177 static void skl_update_crtcs(struct drm_atomic_state *state)
12179 struct drm_i915_private *dev_priv = to_i915(state->dev);
12180 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12181 struct drm_crtc *crtc;
12182 struct intel_crtc *intel_crtc;
12183 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12184 struct intel_crtc_state *cstate;
12185 unsigned int updated = 0;
12190 const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
12192 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
12193 /* ignore allocations for crtc's that have been turned off. */
12194 if (new_crtc_state->active)
12195 entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
12198 * Whenever the number of active pipes changes, we need to make sure we
12199 * update the pipes in the right order so that their ddb allocations
12200 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12201 * cause pipe underruns and other bad stuff.
12206 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12207 bool vbl_wait = false;
12208 unsigned int cmask = drm_crtc_mask(crtc);
12210 intel_crtc = to_intel_crtc(crtc);
12211 cstate = to_intel_crtc_state(new_crtc_state);
12212 pipe = intel_crtc->pipe;
12214 if (updated & cmask || !cstate->base.active)
12217 if (skl_ddb_allocation_overlaps(dev_priv,
12219 &cstate->wm.skl.ddb,
12224 entries[i] = &cstate->wm.skl.ddb;
12227 * If this is an already active pipe, it's DDB changed,
12228 * and this isn't the last pipe that needs updating
12229 * then we need to wait for a vblank to pass for the
12230 * new ddb allocation to take effect.
12232 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
12233 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
12234 !new_crtc_state->active_changed &&
12235 intel_state->wm_results.dirty_pipes != updated)
12238 intel_update_crtc(crtc, state, old_crtc_state,
12242 intel_wait_for_vblank(dev_priv, pipe);
12246 } while (progress);
12249 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12251 struct intel_atomic_state *state, *next;
12252 struct llist_node *freed;
12254 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12255 llist_for_each_entry_safe(state, next, freed, freed)
12256 drm_atomic_state_put(&state->base);
12259 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12261 struct drm_i915_private *dev_priv =
12262 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12264 intel_atomic_helper_free_state(dev_priv);
12267 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12269 struct wait_queue_entry wait_fence, wait_reset;
12270 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12272 init_wait_entry(&wait_fence, 0);
12273 init_wait_entry(&wait_reset, 0);
12275 prepare_to_wait(&intel_state->commit_ready.wait,
12276 &wait_fence, TASK_UNINTERRUPTIBLE);
12277 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12278 &wait_reset, TASK_UNINTERRUPTIBLE);
12281 if (i915_sw_fence_done(&intel_state->commit_ready)
12282 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12287 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12288 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12291 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
12293 struct drm_device *dev = state->dev;
12294 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12295 struct drm_i915_private *dev_priv = to_i915(dev);
12296 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12297 struct drm_crtc *crtc;
12298 struct intel_crtc_state *intel_cstate;
12299 u64 put_domains[I915_MAX_PIPES] = {};
12302 intel_atomic_commit_fence_wait(intel_state);
12304 drm_atomic_helper_wait_for_dependencies(state);
12306 if (intel_state->modeset)
12307 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
12309 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12310 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12312 if (needs_modeset(new_crtc_state) ||
12313 to_intel_crtc_state(new_crtc_state)->update_pipe) {
12315 put_domains[to_intel_crtc(crtc)->pipe] =
12316 modeset_get_crtc_power_domains(crtc,
12317 to_intel_crtc_state(new_crtc_state));
12320 if (!needs_modeset(new_crtc_state))
12323 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12324 to_intel_crtc_state(new_crtc_state));
12326 if (old_crtc_state->active) {
12327 intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask);
12328 dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state);
12329 intel_crtc->active = false;
12330 intel_fbc_disable(intel_crtc);
12331 intel_disable_shared_dpll(intel_crtc);
12334 * Underruns don't always raise
12335 * interrupts, so check manually.
12337 intel_check_cpu_fifo_underruns(dev_priv);
12338 intel_check_pch_fifo_underruns(dev_priv);
12340 if (!new_crtc_state->active) {
12342 * Make sure we don't call initial_watermarks
12343 * for ILK-style watermark updates.
12345 * No clue what this is supposed to achieve.
12347 if (INTEL_GEN(dev_priv) >= 9)
12348 dev_priv->display.initial_watermarks(intel_state,
12349 to_intel_crtc_state(new_crtc_state));
12354 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12355 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12356 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
12358 if (intel_state->modeset) {
12359 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12361 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
12364 * SKL workaround: bspec recommends we disable the SAGV when we
12365 * have more then one pipe enabled
12367 if (!intel_can_enable_sagv(state))
12368 intel_disable_sagv(dev_priv);
12370 intel_modeset_verify_disabled(dev, state);
12373 /* Complete the events for pipes that have now been disabled */
12374 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12375 bool modeset = needs_modeset(new_crtc_state);
12377 /* Complete events for now disable pipes here. */
12378 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
12379 spin_lock_irq(&dev->event_lock);
12380 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
12381 spin_unlock_irq(&dev->event_lock);
12383 new_crtc_state->event = NULL;
12387 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12388 dev_priv->display.update_crtcs(state);
12390 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12391 * already, but still need the state for the delayed optimization. To
12393 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12394 * - schedule that vblank worker _before_ calling hw_done
12395 * - at the start of commit_tail, cancel it _synchrously
12396 * - switch over to the vblank wait helper in the core after that since
12397 * we don't need out special handling any more.
12399 drm_atomic_helper_wait_for_flip_done(dev, state);
12402 * Now that the vblank has passed, we can go ahead and program the
12403 * optimal watermarks on platforms that need two-step watermark
12406 * TODO: Move this (and other cleanup) to an async worker eventually.
12408 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12409 intel_cstate = to_intel_crtc_state(new_crtc_state);
12411 if (dev_priv->display.optimize_watermarks)
12412 dev_priv->display.optimize_watermarks(intel_state,
12416 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12417 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12419 if (put_domains[i])
12420 modeset_put_power_domains(dev_priv, put_domains[i]);
12422 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
12425 if (intel_state->modeset)
12426 intel_verify_planes(intel_state);
12428 if (intel_state->modeset && intel_can_enable_sagv(state))
12429 intel_enable_sagv(dev_priv);
12431 drm_atomic_helper_commit_hw_done(state);
12433 if (intel_state->modeset) {
12434 /* As one of the primary mmio accessors, KMS has a high
12435 * likelihood of triggering bugs in unclaimed access. After we
12436 * finish modesetting, see if an error has been flagged, and if
12437 * so enable debugging for the next modeset - and hope we catch
12440 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
12441 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
12444 drm_atomic_helper_cleanup_planes(dev, state);
12446 drm_atomic_helper_commit_cleanup_done(state);
12448 drm_atomic_state_put(state);
12450 intel_atomic_helper_free_state(dev_priv);
12453 static void intel_atomic_commit_work(struct work_struct *work)
12455 struct drm_atomic_state *state =
12456 container_of(work, struct drm_atomic_state, commit_work);
12458 intel_atomic_commit_tail(state);
12461 static int __i915_sw_fence_call
12462 intel_atomic_commit_ready(struct i915_sw_fence *fence,
12463 enum i915_sw_fence_notify notify)
12465 struct intel_atomic_state *state =
12466 container_of(fence, struct intel_atomic_state, commit_ready);
12469 case FENCE_COMPLETE:
12470 /* we do blocking waits in the worker, nothing to do here */
12474 struct intel_atomic_helper *helper =
12475 &to_i915(state->base.dev)->atomic_helper;
12477 if (llist_add(&state->freed, &helper->free_list))
12478 schedule_work(&helper->free_work);
12483 return NOTIFY_DONE;
12486 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
12488 struct drm_plane_state *old_plane_state, *new_plane_state;
12489 struct drm_plane *plane;
12492 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
12493 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
12494 intel_fb_obj(new_plane_state->fb),
12495 to_intel_plane(plane)->frontbuffer_bit);
12499 * intel_atomic_commit - commit validated state object
12501 * @state: the top-level driver state object
12502 * @nonblock: nonblocking commit
12504 * This function commits a top-level state object that has been validated
12505 * with drm_atomic_helper_check().
12508 * Zero for success or -errno.
12510 static int intel_atomic_commit(struct drm_device *dev,
12511 struct drm_atomic_state *state,
12514 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12515 struct drm_i915_private *dev_priv = to_i915(dev);
12518 drm_atomic_state_get(state);
12519 i915_sw_fence_init(&intel_state->commit_ready,
12520 intel_atomic_commit_ready);
12523 * The intel_legacy_cursor_update() fast path takes care
12524 * of avoiding the vblank waits for simple cursor
12525 * movement and flips. For cursor on/off and size changes,
12526 * we want to perform the vblank waits so that watermark
12527 * updates happen during the correct frames. Gen9+ have
12528 * double buffered watermarks and so shouldn't need this.
12530 * Unset state->legacy_cursor_update before the call to
12531 * drm_atomic_helper_setup_commit() because otherwise
12532 * drm_atomic_helper_wait_for_flip_done() is a noop and
12533 * we get FIFO underruns because we didn't wait
12536 * FIXME doing watermarks and fb cleanup from a vblank worker
12537 * (assuming we had any) would solve these problems.
12539 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
12540 struct intel_crtc_state *new_crtc_state;
12541 struct intel_crtc *crtc;
12544 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
12545 if (new_crtc_state->wm.need_postvbl_update ||
12546 new_crtc_state->update_wm_post)
12547 state->legacy_cursor_update = false;
12550 ret = intel_atomic_prepare_commit(dev, state);
12552 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
12553 i915_sw_fence_commit(&intel_state->commit_ready);
12557 ret = drm_atomic_helper_setup_commit(state, nonblock);
12559 ret = drm_atomic_helper_swap_state(state, true);
12562 i915_sw_fence_commit(&intel_state->commit_ready);
12564 drm_atomic_helper_cleanup_planes(dev, state);
12567 dev_priv->wm.distrust_bios_wm = false;
12568 intel_shared_dpll_swap_state(state);
12569 intel_atomic_track_fbs(state);
12571 if (intel_state->modeset) {
12572 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
12573 sizeof(intel_state->min_cdclk));
12574 memcpy(dev_priv->min_voltage_level,
12575 intel_state->min_voltage_level,
12576 sizeof(intel_state->min_voltage_level));
12577 dev_priv->active_crtcs = intel_state->active_crtcs;
12578 dev_priv->cdclk.logical = intel_state->cdclk.logical;
12579 dev_priv->cdclk.actual = intel_state->cdclk.actual;
12582 drm_atomic_state_get(state);
12583 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
12585 i915_sw_fence_commit(&intel_state->commit_ready);
12586 if (nonblock && intel_state->modeset) {
12587 queue_work(dev_priv->modeset_wq, &state->commit_work);
12588 } else if (nonblock) {
12589 queue_work(system_unbound_wq, &state->commit_work);
12591 if (intel_state->modeset)
12592 flush_workqueue(dev_priv->modeset_wq);
12593 intel_atomic_commit_tail(state);
12599 static const struct drm_crtc_funcs intel_crtc_funcs = {
12600 .gamma_set = drm_atomic_helper_legacy_gamma_set,
12601 .set_config = drm_atomic_helper_set_config,
12602 .destroy = intel_crtc_destroy,
12603 .page_flip = drm_atomic_helper_page_flip,
12604 .atomic_duplicate_state = intel_crtc_duplicate_state,
12605 .atomic_destroy_state = intel_crtc_destroy_state,
12606 .set_crc_source = intel_crtc_set_crc_source,
12609 struct wait_rps_boost {
12610 struct wait_queue_entry wait;
12612 struct drm_crtc *crtc;
12613 struct i915_request *request;
12616 static int do_rps_boost(struct wait_queue_entry *_wait,
12617 unsigned mode, int sync, void *key)
12619 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
12620 struct i915_request *rq = wait->request;
12623 * If we missed the vblank, but the request is already running it
12624 * is reasonable to assume that it will complete before the next
12625 * vblank without our intervention, so leave RPS alone.
12627 if (!i915_request_started(rq))
12628 gen6_rps_boost(rq, NULL);
12629 i915_request_put(rq);
12631 drm_crtc_vblank_put(wait->crtc);
12633 list_del(&wait->wait.entry);
12638 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
12639 struct dma_fence *fence)
12641 struct wait_rps_boost *wait;
12643 if (!dma_fence_is_i915(fence))
12646 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
12649 if (drm_crtc_vblank_get(crtc))
12652 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
12654 drm_crtc_vblank_put(crtc);
12658 wait->request = to_request(dma_fence_get(fence));
12661 wait->wait.func = do_rps_boost;
12662 wait->wait.flags = 0;
12664 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
12667 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
12669 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
12670 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
12671 struct drm_framebuffer *fb = plane_state->base.fb;
12672 struct i915_vma *vma;
12674 if (plane->id == PLANE_CURSOR &&
12675 INTEL_INFO(dev_priv)->cursor_needs_physical) {
12676 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12677 const int align = intel_cursor_alignment(dev_priv);
12679 return i915_gem_object_attach_phys(obj, align);
12682 vma = intel_pin_and_fence_fb_obj(fb,
12683 plane_state->base.rotation,
12684 intel_plane_uses_fence(plane_state),
12685 &plane_state->flags);
12687 return PTR_ERR(vma);
12689 plane_state->vma = vma;
12694 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
12696 struct i915_vma *vma;
12698 vma = fetch_and_zero(&old_plane_state->vma);
12700 intel_unpin_fb_vma(vma, old_plane_state->flags);
12704 * intel_prepare_plane_fb - Prepare fb for usage on plane
12705 * @plane: drm plane to prepare for
12706 * @new_state: the plane state being prepared
12708 * Prepares a framebuffer for usage on a display plane. Generally this
12709 * involves pinning the underlying object and updating the frontbuffer tracking
12710 * bits. Some older platforms need special physical address handling for
12713 * Must be called with struct_mutex held.
12715 * Returns 0 on success, negative error code on failure.
12718 intel_prepare_plane_fb(struct drm_plane *plane,
12719 struct drm_plane_state *new_state)
12721 struct intel_atomic_state *intel_state =
12722 to_intel_atomic_state(new_state->state);
12723 struct drm_i915_private *dev_priv = to_i915(plane->dev);
12724 struct drm_framebuffer *fb = new_state->fb;
12725 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12726 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
12730 struct drm_crtc_state *crtc_state =
12731 drm_atomic_get_existing_crtc_state(new_state->state,
12732 plane->state->crtc);
12734 /* Big Hammer, we also need to ensure that any pending
12735 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
12736 * current scanout is retired before unpinning the old
12737 * framebuffer. Note that we rely on userspace rendering
12738 * into the buffer attached to the pipe they are waiting
12739 * on. If not, userspace generates a GPU hang with IPEHR
12740 * point to the MI_WAIT_FOR_EVENT.
12742 * This should only fail upon a hung GPU, in which case we
12743 * can safely continue.
12745 if (needs_modeset(crtc_state)) {
12746 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
12747 old_obj->resv, NULL,
12755 if (new_state->fence) { /* explicit fencing */
12756 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
12758 I915_FENCE_TIMEOUT,
12767 ret = i915_gem_object_pin_pages(obj);
12771 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
12773 i915_gem_object_unpin_pages(obj);
12777 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
12779 i915_gem_object_wait_priority(obj, 0, I915_PRIORITY_DISPLAY);
12781 mutex_unlock(&dev_priv->drm.struct_mutex);
12782 i915_gem_object_unpin_pages(obj);
12786 if (!new_state->fence) { /* implicit fencing */
12787 struct dma_fence *fence;
12789 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
12791 false, I915_FENCE_TIMEOUT,
12796 fence = reservation_object_get_excl_rcu(obj->resv);
12798 add_rps_boost_after_vblank(new_state->crtc, fence);
12799 dma_fence_put(fence);
12802 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
12809 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12810 * @plane: drm plane to clean up for
12811 * @old_state: the state from the previous modeset
12813 * Cleans up a framebuffer that has just been removed from a plane.
12815 * Must be called with struct_mutex held.
12818 intel_cleanup_plane_fb(struct drm_plane *plane,
12819 struct drm_plane_state *old_state)
12821 struct drm_i915_private *dev_priv = to_i915(plane->dev);
12823 /* Should only be called after a successful intel_prepare_plane_fb()! */
12824 mutex_lock(&dev_priv->drm.struct_mutex);
12825 intel_plane_unpin_fb(to_intel_plane_state(old_state));
12826 mutex_unlock(&dev_priv->drm.struct_mutex);
12830 skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state)
12832 struct drm_i915_private *dev_priv;
12834 int crtc_clock, max_dotclk;
12836 if (!intel_crtc || !crtc_state->base.enable)
12837 return DRM_PLANE_HELPER_NO_SCALING;
12839 dev_priv = to_i915(intel_crtc->base.dev);
12841 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
12842 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
12844 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
12847 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
12848 return DRM_PLANE_HELPER_NO_SCALING;
12851 * skl max scale is lower of:
12852 * close to 3 but not 3, -1 is for that purpose
12856 max_scale = min((1 << 16) * 3 - 1,
12857 (1 << 8) * ((max_dotclk << 8) / crtc_clock));
12863 intel_check_primary_plane(struct intel_plane *plane,
12864 struct intel_crtc_state *crtc_state,
12865 struct intel_plane_state *state)
12867 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
12868 struct drm_crtc *crtc = state->base.crtc;
12869 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
12870 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
12871 bool can_position = false;
12872 struct drm_rect clip = {};
12875 if (INTEL_GEN(dev_priv) >= 9) {
12876 /* use scaler when colorkey is not required */
12877 if (!state->ckey.flags) {
12879 max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state);
12881 can_position = true;
12884 if (crtc_state->base.enable)
12885 drm_mode_get_hv_timing(&crtc_state->base.mode,
12886 &clip.x2, &clip.y2);
12888 ret = drm_atomic_helper_check_plane_state(&state->base,
12891 min_scale, max_scale,
12892 can_position, true);
12896 if (!state->base.fb)
12899 if (INTEL_GEN(dev_priv) >= 9) {
12900 ret = skl_check_plane_surface(crtc_state, state);
12904 state->ctl = skl_plane_ctl(crtc_state, state);
12906 ret = i9xx_check_plane_surface(state);
12910 state->ctl = i9xx_plane_ctl(crtc_state, state);
12913 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
12914 state->color_ctl = glk_plane_color_ctl(crtc_state, state);
12919 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
12920 struct drm_crtc_state *old_crtc_state)
12922 struct drm_device *dev = crtc->dev;
12923 struct drm_i915_private *dev_priv = to_i915(dev);
12924 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12925 struct intel_crtc_state *old_intel_cstate =
12926 to_intel_crtc_state(old_crtc_state);
12927 struct intel_atomic_state *old_intel_state =
12928 to_intel_atomic_state(old_crtc_state->state);
12929 struct intel_crtc_state *intel_cstate =
12930 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
12931 bool modeset = needs_modeset(&intel_cstate->base);
12934 (intel_cstate->base.color_mgmt_changed ||
12935 intel_cstate->update_pipe)) {
12936 intel_color_set_csc(&intel_cstate->base);
12937 intel_color_load_luts(&intel_cstate->base);
12940 /* Perform vblank evasion around commit operation */
12941 intel_pipe_update_start(intel_cstate);
12946 if (intel_cstate->update_pipe)
12947 intel_update_pipe_config(old_intel_cstate, intel_cstate);
12948 else if (INTEL_GEN(dev_priv) >= 9)
12949 skl_detach_scalers(intel_crtc);
12952 if (dev_priv->display.atomic_update_watermarks)
12953 dev_priv->display.atomic_update_watermarks(old_intel_state,
12957 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
12958 struct drm_crtc_state *old_crtc_state)
12960 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
12961 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12962 struct intel_atomic_state *old_intel_state =
12963 to_intel_atomic_state(old_crtc_state->state);
12964 struct intel_crtc_state *new_crtc_state =
12965 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
12967 intel_pipe_update_end(new_crtc_state);
12969 if (new_crtc_state->update_pipe &&
12970 !needs_modeset(&new_crtc_state->base) &&
12971 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) {
12972 if (!IS_GEN2(dev_priv))
12973 intel_set_cpu_fifo_underrun_reporting(dev_priv, intel_crtc->pipe, true);
12975 if (new_crtc_state->has_pch_encoder) {
12976 enum pipe pch_transcoder =
12977 intel_crtc_pch_transcoder(intel_crtc);
12979 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
12985 * intel_plane_destroy - destroy a plane
12986 * @plane: plane to destroy
12988 * Common destruction function for all types of planes (primary, cursor,
12991 void intel_plane_destroy(struct drm_plane *plane)
12993 drm_plane_cleanup(plane);
12994 kfree(to_intel_plane(plane));
12997 static bool i8xx_mod_supported(uint32_t format, uint64_t modifier)
13000 case DRM_FORMAT_C8:
13001 case DRM_FORMAT_RGB565:
13002 case DRM_FORMAT_XRGB1555:
13003 case DRM_FORMAT_XRGB8888:
13004 return modifier == DRM_FORMAT_MOD_LINEAR ||
13005 modifier == I915_FORMAT_MOD_X_TILED;
13011 static bool i965_mod_supported(uint32_t format, uint64_t modifier)
13014 case DRM_FORMAT_C8:
13015 case DRM_FORMAT_RGB565:
13016 case DRM_FORMAT_XRGB8888:
13017 case DRM_FORMAT_XBGR8888:
13018 case DRM_FORMAT_XRGB2101010:
13019 case DRM_FORMAT_XBGR2101010:
13020 return modifier == DRM_FORMAT_MOD_LINEAR ||
13021 modifier == I915_FORMAT_MOD_X_TILED;
13027 static bool skl_mod_supported(uint32_t format, uint64_t modifier)
13030 case DRM_FORMAT_XRGB8888:
13031 case DRM_FORMAT_XBGR8888:
13032 case DRM_FORMAT_ARGB8888:
13033 case DRM_FORMAT_ABGR8888:
13034 if (modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
13035 modifier == I915_FORMAT_MOD_Y_TILED_CCS)
13038 case DRM_FORMAT_RGB565:
13039 case DRM_FORMAT_XRGB2101010:
13040 case DRM_FORMAT_XBGR2101010:
13041 case DRM_FORMAT_YUYV:
13042 case DRM_FORMAT_YVYU:
13043 case DRM_FORMAT_UYVY:
13044 case DRM_FORMAT_VYUY:
13045 if (modifier == I915_FORMAT_MOD_Yf_TILED)
13048 case DRM_FORMAT_C8:
13049 if (modifier == DRM_FORMAT_MOD_LINEAR ||
13050 modifier == I915_FORMAT_MOD_X_TILED ||
13051 modifier == I915_FORMAT_MOD_Y_TILED)
13059 static bool intel_primary_plane_format_mod_supported(struct drm_plane *plane,
13063 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13065 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
13068 if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
13069 modifier != DRM_FORMAT_MOD_LINEAR)
13072 if (INTEL_GEN(dev_priv) >= 9)
13073 return skl_mod_supported(format, modifier);
13074 else if (INTEL_GEN(dev_priv) >= 4)
13075 return i965_mod_supported(format, modifier);
13077 return i8xx_mod_supported(format, modifier);
13080 static bool intel_cursor_plane_format_mod_supported(struct drm_plane *plane,
13084 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
13087 return modifier == DRM_FORMAT_MOD_LINEAR && format == DRM_FORMAT_ARGB8888;
13090 static struct drm_plane_funcs intel_plane_funcs = {
13091 .update_plane = drm_atomic_helper_update_plane,
13092 .disable_plane = drm_atomic_helper_disable_plane,
13093 .destroy = intel_plane_destroy,
13094 .atomic_get_property = intel_plane_atomic_get_property,
13095 .atomic_set_property = intel_plane_atomic_set_property,
13096 .atomic_duplicate_state = intel_plane_duplicate_state,
13097 .atomic_destroy_state = intel_plane_destroy_state,
13098 .format_mod_supported = intel_primary_plane_format_mod_supported,
13102 intel_legacy_cursor_update(struct drm_plane *plane,
13103 struct drm_crtc *crtc,
13104 struct drm_framebuffer *fb,
13105 int crtc_x, int crtc_y,
13106 unsigned int crtc_w, unsigned int crtc_h,
13107 uint32_t src_x, uint32_t src_y,
13108 uint32_t src_w, uint32_t src_h,
13109 struct drm_modeset_acquire_ctx *ctx)
13111 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13113 struct drm_plane_state *old_plane_state, *new_plane_state;
13114 struct intel_plane *intel_plane = to_intel_plane(plane);
13115 struct drm_framebuffer *old_fb;
13116 struct drm_crtc_state *crtc_state = crtc->state;
13119 * When crtc is inactive or there is a modeset pending,
13120 * wait for it to complete in the slowpath
13122 if (!crtc_state->active || needs_modeset(crtc_state) ||
13123 to_intel_crtc_state(crtc_state)->update_pipe)
13126 old_plane_state = plane->state;
13128 * Don't do an async update if there is an outstanding commit modifying
13129 * the plane. This prevents our async update's changes from getting
13130 * overridden by a previous synchronous update's state.
13132 if (old_plane_state->commit &&
13133 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13137 * If any parameters change that may affect watermarks,
13138 * take the slowpath. Only changing fb or position should be
13141 if (old_plane_state->crtc != crtc ||
13142 old_plane_state->src_w != src_w ||
13143 old_plane_state->src_h != src_h ||
13144 old_plane_state->crtc_w != crtc_w ||
13145 old_plane_state->crtc_h != crtc_h ||
13146 !old_plane_state->fb != !fb)
13149 new_plane_state = intel_plane_duplicate_state(plane);
13150 if (!new_plane_state)
13153 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13155 new_plane_state->src_x = src_x;
13156 new_plane_state->src_y = src_y;
13157 new_plane_state->src_w = src_w;
13158 new_plane_state->src_h = src_h;
13159 new_plane_state->crtc_x = crtc_x;
13160 new_plane_state->crtc_y = crtc_y;
13161 new_plane_state->crtc_w = crtc_w;
13162 new_plane_state->crtc_h = crtc_h;
13164 ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state),
13165 to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */
13166 to_intel_plane_state(plane->state),
13167 to_intel_plane_state(new_plane_state));
13171 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13175 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13179 old_fb = old_plane_state->fb;
13181 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13182 intel_plane->frontbuffer_bit);
13184 /* Swap plane state */
13185 plane->state = new_plane_state;
13187 if (plane->state->visible) {
13188 trace_intel_update_plane(plane, to_intel_crtc(crtc));
13189 intel_plane->update_plane(intel_plane,
13190 to_intel_crtc_state(crtc->state),
13191 to_intel_plane_state(plane->state));
13193 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
13194 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
13197 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
13200 mutex_unlock(&dev_priv->drm.struct_mutex);
13203 intel_plane_destroy_state(plane, new_plane_state);
13205 intel_plane_destroy_state(plane, old_plane_state);
13209 return drm_atomic_helper_update_plane(plane, crtc, fb,
13210 crtc_x, crtc_y, crtc_w, crtc_h,
13211 src_x, src_y, src_w, src_h, ctx);
13214 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13215 .update_plane = intel_legacy_cursor_update,
13216 .disable_plane = drm_atomic_helper_disable_plane,
13217 .destroy = intel_plane_destroy,
13218 .atomic_get_property = intel_plane_atomic_get_property,
13219 .atomic_set_property = intel_plane_atomic_set_property,
13220 .atomic_duplicate_state = intel_plane_duplicate_state,
13221 .atomic_destroy_state = intel_plane_destroy_state,
13222 .format_mod_supported = intel_cursor_plane_format_mod_supported,
13225 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13226 enum i9xx_plane_id i9xx_plane)
13228 if (!HAS_FBC(dev_priv))
13231 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13232 return i9xx_plane == PLANE_A; /* tied to pipe A */
13233 else if (IS_IVYBRIDGE(dev_priv))
13234 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13235 i9xx_plane == PLANE_C;
13236 else if (INTEL_GEN(dev_priv) >= 4)
13237 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13239 return i9xx_plane == PLANE_A;
13242 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
13243 enum pipe pipe, enum plane_id plane_id)
13245 if (!HAS_FBC(dev_priv))
13248 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
13251 static struct intel_plane *
13252 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
13254 struct intel_plane *primary = NULL;
13255 struct intel_plane_state *state = NULL;
13256 const uint32_t *intel_primary_formats;
13257 unsigned int supported_rotations;
13258 unsigned int num_formats;
13259 const uint64_t *modifiers;
13262 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
13268 state = intel_create_plane_state(&primary->base);
13274 primary->base.state = &state->base;
13276 primary->can_scale = false;
13277 primary->max_downscale = 1;
13278 if (INTEL_GEN(dev_priv) >= 9) {
13279 primary->can_scale = true;
13280 state->scaler_id = -1;
13282 primary->pipe = pipe;
13284 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13285 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13287 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
13288 primary->i9xx_plane = (enum i9xx_plane_id) !pipe;
13290 primary->i9xx_plane = (enum i9xx_plane_id) pipe;
13291 primary->id = PLANE_PRIMARY;
13292 primary->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, primary->id);
13294 if (INTEL_GEN(dev_priv) >= 9)
13295 primary->has_fbc = skl_plane_has_fbc(dev_priv,
13299 primary->has_fbc = i9xx_plane_has_fbc(dev_priv,
13300 primary->i9xx_plane);
13302 if (primary->has_fbc) {
13303 struct intel_fbc *fbc = &dev_priv->fbc;
13305 fbc->possible_framebuffer_bits |= primary->frontbuffer_bit;
13308 primary->check_plane = intel_check_primary_plane;
13310 if (INTEL_GEN(dev_priv) >= 9) {
13311 intel_primary_formats = skl_primary_formats;
13312 num_formats = ARRAY_SIZE(skl_primary_formats);
13314 if (skl_plane_has_ccs(dev_priv, pipe, PLANE_PRIMARY))
13315 modifiers = skl_format_modifiers_ccs;
13317 modifiers = skl_format_modifiers_noccs;
13319 primary->update_plane = skl_update_plane;
13320 primary->disable_plane = skl_disable_plane;
13321 primary->get_hw_state = skl_plane_get_hw_state;
13322 } else if (INTEL_GEN(dev_priv) >= 4) {
13323 intel_primary_formats = i965_primary_formats;
13324 num_formats = ARRAY_SIZE(i965_primary_formats);
13325 modifiers = i9xx_format_modifiers;
13327 primary->update_plane = i9xx_update_plane;
13328 primary->disable_plane = i9xx_disable_plane;
13329 primary->get_hw_state = i9xx_plane_get_hw_state;
13331 intel_primary_formats = i8xx_primary_formats;
13332 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13333 modifiers = i9xx_format_modifiers;
13335 primary->update_plane = i9xx_update_plane;
13336 primary->disable_plane = i9xx_disable_plane;
13337 primary->get_hw_state = i9xx_plane_get_hw_state;
13340 if (INTEL_GEN(dev_priv) >= 9)
13341 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13342 0, &intel_plane_funcs,
13343 intel_primary_formats, num_formats,
13345 DRM_PLANE_TYPE_PRIMARY,
13346 "plane 1%c", pipe_name(pipe));
13347 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
13348 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13349 0, &intel_plane_funcs,
13350 intel_primary_formats, num_formats,
13352 DRM_PLANE_TYPE_PRIMARY,
13353 "primary %c", pipe_name(pipe));
13355 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13356 0, &intel_plane_funcs,
13357 intel_primary_formats, num_formats,
13359 DRM_PLANE_TYPE_PRIMARY,
13361 plane_name(primary->i9xx_plane));
13365 if (INTEL_GEN(dev_priv) >= 10) {
13366 supported_rotations =
13367 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13368 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 |
13369 DRM_MODE_REFLECT_X;
13370 } else if (INTEL_GEN(dev_priv) >= 9) {
13371 supported_rotations =
13372 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13373 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
13374 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13375 supported_rotations =
13376 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13377 DRM_MODE_REFLECT_X;
13378 } else if (INTEL_GEN(dev_priv) >= 4) {
13379 supported_rotations =
13380 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
13382 supported_rotations = DRM_MODE_ROTATE_0;
13385 if (INTEL_GEN(dev_priv) >= 4)
13386 drm_plane_create_rotation_property(&primary->base,
13388 supported_rotations);
13390 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
13398 return ERR_PTR(ret);
13401 static struct intel_plane *
13402 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13405 struct intel_plane *cursor = NULL;
13406 struct intel_plane_state *state = NULL;
13409 cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
13415 state = intel_create_plane_state(&cursor->base);
13421 cursor->base.state = &state->base;
13423 cursor->can_scale = false;
13424 cursor->max_downscale = 1;
13425 cursor->pipe = pipe;
13426 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
13427 cursor->id = PLANE_CURSOR;
13428 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
13430 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
13431 cursor->update_plane = i845_update_cursor;
13432 cursor->disable_plane = i845_disable_cursor;
13433 cursor->get_hw_state = i845_cursor_get_hw_state;
13434 cursor->check_plane = i845_check_cursor;
13436 cursor->update_plane = i9xx_update_cursor;
13437 cursor->disable_plane = i9xx_disable_cursor;
13438 cursor->get_hw_state = i9xx_cursor_get_hw_state;
13439 cursor->check_plane = i9xx_check_cursor;
13442 cursor->cursor.base = ~0;
13443 cursor->cursor.cntl = ~0;
13445 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13446 cursor->cursor.size = ~0;
13448 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
13449 0, &intel_cursor_plane_funcs,
13450 intel_cursor_formats,
13451 ARRAY_SIZE(intel_cursor_formats),
13452 cursor_format_modifiers,
13453 DRM_PLANE_TYPE_CURSOR,
13454 "cursor %c", pipe_name(pipe));
13458 if (INTEL_GEN(dev_priv) >= 4)
13459 drm_plane_create_rotation_property(&cursor->base,
13461 DRM_MODE_ROTATE_0 |
13462 DRM_MODE_ROTATE_180);
13464 if (INTEL_GEN(dev_priv) >= 9)
13465 state->scaler_id = -1;
13467 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13475 return ERR_PTR(ret);
13478 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
13479 struct intel_crtc_state *crtc_state)
13481 struct intel_crtc_scaler_state *scaler_state =
13482 &crtc_state->scaler_state;
13483 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13486 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
13487 if (!crtc->num_scalers)
13490 for (i = 0; i < crtc->num_scalers; i++) {
13491 struct intel_scaler *scaler = &scaler_state->scalers[i];
13493 scaler->in_use = 0;
13494 scaler->mode = PS_SCALER_MODE_DYN;
13497 scaler_state->scaler_id = -1;
13500 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
13502 struct intel_crtc *intel_crtc;
13503 struct intel_crtc_state *crtc_state = NULL;
13504 struct intel_plane *primary = NULL;
13505 struct intel_plane *cursor = NULL;
13508 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
13512 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
13517 intel_crtc->config = crtc_state;
13518 intel_crtc->base.state = &crtc_state->base;
13519 crtc_state->base.crtc = &intel_crtc->base;
13521 primary = intel_primary_plane_create(dev_priv, pipe);
13522 if (IS_ERR(primary)) {
13523 ret = PTR_ERR(primary);
13526 intel_crtc->plane_ids_mask |= BIT(primary->id);
13528 for_each_sprite(dev_priv, pipe, sprite) {
13529 struct intel_plane *plane;
13531 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
13532 if (IS_ERR(plane)) {
13533 ret = PTR_ERR(plane);
13536 intel_crtc->plane_ids_mask |= BIT(plane->id);
13539 cursor = intel_cursor_plane_create(dev_priv, pipe);
13540 if (IS_ERR(cursor)) {
13541 ret = PTR_ERR(cursor);
13544 intel_crtc->plane_ids_mask |= BIT(cursor->id);
13546 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
13547 &primary->base, &cursor->base,
13549 "pipe %c", pipe_name(pipe));
13553 intel_crtc->pipe = pipe;
13555 /* initialize shared scalers */
13556 intel_crtc_init_scalers(intel_crtc, crtc_state);
13558 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
13559 dev_priv->plane_to_crtc_mapping[primary->i9xx_plane] != NULL);
13560 dev_priv->plane_to_crtc_mapping[primary->i9xx_plane] = intel_crtc;
13561 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = intel_crtc;
13563 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
13565 intel_color_init(&intel_crtc->base);
13567 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
13573 * drm_mode_config_cleanup() will free up any
13574 * crtcs/planes already initialized.
13582 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
13584 struct drm_device *dev = connector->base.dev;
13586 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
13588 if (!connector->base.state->crtc)
13589 return INVALID_PIPE;
13591 return to_intel_crtc(connector->base.state->crtc)->pipe;
13594 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
13595 struct drm_file *file)
13597 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
13598 struct drm_crtc *drmmode_crtc;
13599 struct intel_crtc *crtc;
13601 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
13605 crtc = to_intel_crtc(drmmode_crtc);
13606 pipe_from_crtc_id->pipe = crtc->pipe;
13611 static int intel_encoder_clones(struct intel_encoder *encoder)
13613 struct drm_device *dev = encoder->base.dev;
13614 struct intel_encoder *source_encoder;
13615 int index_mask = 0;
13618 for_each_intel_encoder(dev, source_encoder) {
13619 if (encoders_cloneable(encoder, source_encoder))
13620 index_mask |= (1 << entry);
13628 static bool has_edp_a(struct drm_i915_private *dev_priv)
13630 if (!IS_MOBILE(dev_priv))
13633 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
13636 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
13642 static bool intel_crt_present(struct drm_i915_private *dev_priv)
13644 if (INTEL_GEN(dev_priv) >= 9)
13647 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
13650 if (IS_CHERRYVIEW(dev_priv))
13653 if (HAS_PCH_LPT_H(dev_priv) &&
13654 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
13657 /* DDI E can't be used if DDI A requires 4 lanes */
13658 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
13661 if (!dev_priv->vbt.int_crt_support)
13667 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
13672 if (HAS_DDI(dev_priv))
13675 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13676 * everywhere where registers can be write protected.
13678 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13683 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
13684 u32 val = I915_READ(PP_CONTROL(pps_idx));
13686 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
13687 I915_WRITE(PP_CONTROL(pps_idx), val);
13691 static void intel_pps_init(struct drm_i915_private *dev_priv)
13693 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
13694 dev_priv->pps_mmio_base = PCH_PPS_BASE;
13695 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13696 dev_priv->pps_mmio_base = VLV_PPS_BASE;
13698 dev_priv->pps_mmio_base = PPS_BASE;
13700 intel_pps_unlock_regs_wa(dev_priv);
13703 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
13705 struct intel_encoder *encoder;
13706 bool dpd_is_edp = false;
13708 intel_pps_init(dev_priv);
13711 * intel_edp_init_connector() depends on this completing first, to
13712 * prevent the registeration of both eDP and LVDS and the incorrect
13713 * sharing of the PPS.
13715 intel_lvds_init(dev_priv);
13717 if (intel_crt_present(dev_priv))
13718 intel_crt_init(dev_priv);
13720 if (IS_GEN9_LP(dev_priv)) {
13722 * FIXME: Broxton doesn't support port detection via the
13723 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13724 * detect the ports.
13726 intel_ddi_init(dev_priv, PORT_A);
13727 intel_ddi_init(dev_priv, PORT_B);
13728 intel_ddi_init(dev_priv, PORT_C);
13730 intel_dsi_init(dev_priv);
13731 } else if (HAS_DDI(dev_priv)) {
13735 * Haswell uses DDI functions to detect digital outputs.
13736 * On SKL pre-D0 the strap isn't connected, so we assume
13739 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
13740 /* WaIgnoreDDIAStrap: skl */
13741 if (found || IS_GEN9_BC(dev_priv))
13742 intel_ddi_init(dev_priv, PORT_A);
13744 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
13746 found = I915_READ(SFUSE_STRAP);
13748 if (found & SFUSE_STRAP_DDIB_DETECTED)
13749 intel_ddi_init(dev_priv, PORT_B);
13750 if (found & SFUSE_STRAP_DDIC_DETECTED)
13751 intel_ddi_init(dev_priv, PORT_C);
13752 if (found & SFUSE_STRAP_DDID_DETECTED)
13753 intel_ddi_init(dev_priv, PORT_D);
13754 if (found & SFUSE_STRAP_DDIF_DETECTED)
13755 intel_ddi_init(dev_priv, PORT_F);
13757 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13759 if (IS_GEN9_BC(dev_priv) &&
13760 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
13761 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
13762 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
13763 intel_ddi_init(dev_priv, PORT_E);
13765 } else if (HAS_PCH_SPLIT(dev_priv)) {
13767 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
13769 if (has_edp_a(dev_priv))
13770 intel_dp_init(dev_priv, DP_A, PORT_A);
13772 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
13773 /* PCH SDVOB multiplex with HDMIB */
13774 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
13776 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
13777 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
13778 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
13781 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
13782 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
13784 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
13785 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
13787 if (I915_READ(PCH_DP_C) & DP_DETECTED)
13788 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
13790 if (I915_READ(PCH_DP_D) & DP_DETECTED)
13791 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
13792 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
13793 bool has_edp, has_port;
13796 * The DP_DETECTED bit is the latched state of the DDC
13797 * SDA pin at boot. However since eDP doesn't require DDC
13798 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13799 * eDP ports may have been muxed to an alternate function.
13800 * Thus we can't rely on the DP_DETECTED bit alone to detect
13801 * eDP ports. Consult the VBT as well as DP_DETECTED to
13802 * detect eDP ports.
13804 * Sadly the straps seem to be missing sometimes even for HDMI
13805 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
13806 * and VBT for the presence of the port. Additionally we can't
13807 * trust the port type the VBT declares as we've seen at least
13808 * HDMI ports that the VBT claim are DP or eDP.
13810 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
13811 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
13812 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
13813 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
13814 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
13815 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
13817 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
13818 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
13819 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
13820 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
13821 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
13822 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
13824 if (IS_CHERRYVIEW(dev_priv)) {
13826 * eDP not supported on port D,
13827 * so no need to worry about it
13829 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
13830 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
13831 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
13832 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
13833 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
13836 intel_dsi_init(dev_priv);
13837 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
13838 bool found = false;
13840 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
13841 DRM_DEBUG_KMS("probing SDVOB\n");
13842 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
13843 if (!found && IS_G4X(dev_priv)) {
13844 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
13845 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
13848 if (!found && IS_G4X(dev_priv))
13849 intel_dp_init(dev_priv, DP_B, PORT_B);
13852 /* Before G4X SDVOC doesn't have its own detect register */
13854 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
13855 DRM_DEBUG_KMS("probing SDVOC\n");
13856 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
13859 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
13861 if (IS_G4X(dev_priv)) {
13862 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
13863 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
13865 if (IS_G4X(dev_priv))
13866 intel_dp_init(dev_priv, DP_C, PORT_C);
13869 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
13870 intel_dp_init(dev_priv, DP_D, PORT_D);
13871 } else if (IS_GEN2(dev_priv))
13872 intel_dvo_init(dev_priv);
13874 if (SUPPORTS_TV(dev_priv))
13875 intel_tv_init(dev_priv);
13877 intel_psr_init(dev_priv);
13879 for_each_intel_encoder(&dev_priv->drm, encoder) {
13880 encoder->base.possible_crtcs = encoder->crtc_mask;
13881 encoder->base.possible_clones =
13882 intel_encoder_clones(encoder);
13885 intel_init_pch_refclk(dev_priv);
13887 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
13890 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
13892 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
13894 drm_framebuffer_cleanup(fb);
13896 i915_gem_object_lock(intel_fb->obj);
13897 WARN_ON(!intel_fb->obj->framebuffer_references--);
13898 i915_gem_object_unlock(intel_fb->obj);
13900 i915_gem_object_put(intel_fb->obj);
13905 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
13906 struct drm_file *file,
13907 unsigned int *handle)
13909 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
13910 struct drm_i915_gem_object *obj = intel_fb->obj;
13912 if (obj->userptr.mm) {
13913 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
13917 return drm_gem_handle_create(file, &obj->base, handle);
13920 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
13921 struct drm_file *file,
13922 unsigned flags, unsigned color,
13923 struct drm_clip_rect *clips,
13924 unsigned num_clips)
13926 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13928 i915_gem_object_flush_if_display(obj);
13929 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13934 static const struct drm_framebuffer_funcs intel_fb_funcs = {
13935 .destroy = intel_user_framebuffer_destroy,
13936 .create_handle = intel_user_framebuffer_create_handle,
13937 .dirty = intel_user_framebuffer_dirty,
13941 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
13942 uint64_t fb_modifier, uint32_t pixel_format)
13944 u32 gen = INTEL_GEN(dev_priv);
13947 int cpp = drm_format_plane_cpp(pixel_format, 0);
13949 /* "The stride in bytes must not exceed the of the size of 8K
13950 * pixels and 32K bytes."
13952 return min(8192 * cpp, 32768);
13953 } else if (gen >= 5 && !HAS_GMCH_DISPLAY(dev_priv)) {
13955 } else if (gen >= 4) {
13956 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
13960 } else if (gen >= 3) {
13961 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
13966 /* XXX DSPC is limited to 4k tiled */
13971 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
13972 struct drm_i915_gem_object *obj,
13973 struct drm_mode_fb_cmd2 *mode_cmd)
13975 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
13976 struct drm_framebuffer *fb = &intel_fb->base;
13977 struct drm_format_name_buf format_name;
13979 unsigned int tiling, stride;
13983 i915_gem_object_lock(obj);
13984 obj->framebuffer_references++;
13985 tiling = i915_gem_object_get_tiling(obj);
13986 stride = i915_gem_object_get_stride(obj);
13987 i915_gem_object_unlock(obj);
13989 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
13991 * If there's a fence, enforce that
13992 * the fb modifier and tiling mode match.
13994 if (tiling != I915_TILING_NONE &&
13995 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
13996 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14000 if (tiling == I915_TILING_X) {
14001 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14002 } else if (tiling == I915_TILING_Y) {
14003 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14008 /* Passed in modifier sanity checking. */
14009 switch (mode_cmd->modifier[0]) {
14010 case I915_FORMAT_MOD_Y_TILED_CCS:
14011 case I915_FORMAT_MOD_Yf_TILED_CCS:
14012 switch (mode_cmd->pixel_format) {
14013 case DRM_FORMAT_XBGR8888:
14014 case DRM_FORMAT_ABGR8888:
14015 case DRM_FORMAT_XRGB8888:
14016 case DRM_FORMAT_ARGB8888:
14019 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
14023 case I915_FORMAT_MOD_Y_TILED:
14024 case I915_FORMAT_MOD_Yf_TILED:
14025 if (INTEL_GEN(dev_priv) < 9) {
14026 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14027 mode_cmd->modifier[0]);
14030 case DRM_FORMAT_MOD_LINEAR:
14031 case I915_FORMAT_MOD_X_TILED:
14034 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14035 mode_cmd->modifier[0]);
14040 * gen2/3 display engine uses the fence if present,
14041 * so the tiling mode must match the fb modifier exactly.
14043 if (INTEL_GEN(dev_priv) < 4 &&
14044 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14045 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14049 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
14050 mode_cmd->pixel_format);
14051 if (mode_cmd->pitches[0] > pitch_limit) {
14052 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14053 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14054 "tiled" : "linear",
14055 mode_cmd->pitches[0], pitch_limit);
14060 * If there's a fence, enforce that
14061 * the fb pitch and fence stride match.
14063 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14064 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14065 mode_cmd->pitches[0], stride);
14069 /* Reject formats not supported by any plane early. */
14070 switch (mode_cmd->pixel_format) {
14071 case DRM_FORMAT_C8:
14072 case DRM_FORMAT_RGB565:
14073 case DRM_FORMAT_XRGB8888:
14074 case DRM_FORMAT_ARGB8888:
14076 case DRM_FORMAT_XRGB1555:
14077 if (INTEL_GEN(dev_priv) > 3) {
14078 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14079 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14083 case DRM_FORMAT_ABGR8888:
14084 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
14085 INTEL_GEN(dev_priv) < 9) {
14086 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14087 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14091 case DRM_FORMAT_XBGR8888:
14092 case DRM_FORMAT_XRGB2101010:
14093 case DRM_FORMAT_XBGR2101010:
14094 if (INTEL_GEN(dev_priv) < 4) {
14095 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14096 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14100 case DRM_FORMAT_ABGR2101010:
14101 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
14102 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14103 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14107 case DRM_FORMAT_YUYV:
14108 case DRM_FORMAT_UYVY:
14109 case DRM_FORMAT_YVYU:
14110 case DRM_FORMAT_VYUY:
14111 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
14112 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14113 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14118 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14119 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14123 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14124 if (mode_cmd->offsets[0] != 0)
14127 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14129 for (i = 0; i < fb->format->num_planes; i++) {
14130 u32 stride_alignment;
14132 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14133 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14137 stride_alignment = intel_fb_stride_alignment(fb, i);
14140 * Display WA #0531: skl,bxt,kbl,glk
14142 * Render decompression and plane width > 3840
14143 * combined with horizontal panning requires the
14144 * plane stride to be a multiple of 4. We'll just
14145 * require the entire fb to accommodate that to avoid
14146 * potential runtime errors at plane configuration time.
14148 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
14149 (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
14150 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS))
14151 stride_alignment *= 4;
14153 if (fb->pitches[i] & (stride_alignment - 1)) {
14154 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14155 i, fb->pitches[i], stride_alignment);
14160 intel_fb->obj = obj;
14162 ret = intel_fill_fb_info(dev_priv, fb);
14166 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14168 DRM_ERROR("framebuffer init failed %d\n", ret);
14175 i915_gem_object_lock(obj);
14176 obj->framebuffer_references--;
14177 i915_gem_object_unlock(obj);
14181 static struct drm_framebuffer *
14182 intel_user_framebuffer_create(struct drm_device *dev,
14183 struct drm_file *filp,
14184 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14186 struct drm_framebuffer *fb;
14187 struct drm_i915_gem_object *obj;
14188 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14190 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14192 return ERR_PTR(-ENOENT);
14194 fb = intel_framebuffer_create(obj, &mode_cmd);
14196 i915_gem_object_put(obj);
14201 static void intel_atomic_state_free(struct drm_atomic_state *state)
14203 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14205 drm_atomic_state_default_release(state);
14207 i915_sw_fence_fini(&intel_state->commit_ready);
14212 static enum drm_mode_status
14213 intel_mode_valid(struct drm_device *dev,
14214 const struct drm_display_mode *mode)
14216 if (mode->vscan > 1)
14217 return MODE_NO_VSCAN;
14219 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
14220 return MODE_NO_DBLESCAN;
14222 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14223 return MODE_H_ILLEGAL;
14225 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14226 DRM_MODE_FLAG_NCSYNC |
14227 DRM_MODE_FLAG_PCSYNC))
14230 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14231 DRM_MODE_FLAG_PIXMUX |
14232 DRM_MODE_FLAG_CLKDIV2))
14238 static const struct drm_mode_config_funcs intel_mode_funcs = {
14239 .fb_create = intel_user_framebuffer_create,
14240 .get_format_info = intel_get_format_info,
14241 .output_poll_changed = intel_fbdev_output_poll_changed,
14242 .mode_valid = intel_mode_valid,
14243 .atomic_check = intel_atomic_check,
14244 .atomic_commit = intel_atomic_commit,
14245 .atomic_state_alloc = intel_atomic_state_alloc,
14246 .atomic_state_clear = intel_atomic_state_clear,
14247 .atomic_state_free = intel_atomic_state_free,
14251 * intel_init_display_hooks - initialize the display modesetting hooks
14252 * @dev_priv: device private
14254 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14256 intel_init_cdclk_hooks(dev_priv);
14258 if (INTEL_GEN(dev_priv) >= 9) {
14259 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14260 dev_priv->display.get_initial_plane_config =
14261 skylake_get_initial_plane_config;
14262 dev_priv->display.crtc_compute_clock =
14263 haswell_crtc_compute_clock;
14264 dev_priv->display.crtc_enable = haswell_crtc_enable;
14265 dev_priv->display.crtc_disable = haswell_crtc_disable;
14266 } else if (HAS_DDI(dev_priv)) {
14267 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14268 dev_priv->display.get_initial_plane_config =
14269 i9xx_get_initial_plane_config;
14270 dev_priv->display.crtc_compute_clock =
14271 haswell_crtc_compute_clock;
14272 dev_priv->display.crtc_enable = haswell_crtc_enable;
14273 dev_priv->display.crtc_disable = haswell_crtc_disable;
14274 } else if (HAS_PCH_SPLIT(dev_priv)) {
14275 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14276 dev_priv->display.get_initial_plane_config =
14277 i9xx_get_initial_plane_config;
14278 dev_priv->display.crtc_compute_clock =
14279 ironlake_crtc_compute_clock;
14280 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14281 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14282 } else if (IS_CHERRYVIEW(dev_priv)) {
14283 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14284 dev_priv->display.get_initial_plane_config =
14285 i9xx_get_initial_plane_config;
14286 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14287 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14288 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14289 } else if (IS_VALLEYVIEW(dev_priv)) {
14290 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14291 dev_priv->display.get_initial_plane_config =
14292 i9xx_get_initial_plane_config;
14293 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
14294 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14295 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14296 } else if (IS_G4X(dev_priv)) {
14297 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14298 dev_priv->display.get_initial_plane_config =
14299 i9xx_get_initial_plane_config;
14300 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14301 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14302 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14303 } else if (IS_PINEVIEW(dev_priv)) {
14304 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14305 dev_priv->display.get_initial_plane_config =
14306 i9xx_get_initial_plane_config;
14307 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14308 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14309 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14310 } else if (!IS_GEN2(dev_priv)) {
14311 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14312 dev_priv->display.get_initial_plane_config =
14313 i9xx_get_initial_plane_config;
14314 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14315 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14316 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14318 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14319 dev_priv->display.get_initial_plane_config =
14320 i9xx_get_initial_plane_config;
14321 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14322 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14323 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14326 if (IS_GEN5(dev_priv)) {
14327 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14328 } else if (IS_GEN6(dev_priv)) {
14329 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14330 } else if (IS_IVYBRIDGE(dev_priv)) {
14331 /* FIXME: detect B0+ stepping and use auto training */
14332 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14333 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
14334 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14337 if (INTEL_GEN(dev_priv) >= 9)
14338 dev_priv->display.update_crtcs = skl_update_crtcs;
14340 dev_priv->display.update_crtcs = intel_update_crtcs;
14344 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14346 static void quirk_ssc_force_disable(struct drm_device *dev)
14348 struct drm_i915_private *dev_priv = to_i915(dev);
14349 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14350 DRM_INFO("applying lvds SSC disable quirk\n");
14354 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14357 static void quirk_invert_brightness(struct drm_device *dev)
14359 struct drm_i915_private *dev_priv = to_i915(dev);
14360 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14361 DRM_INFO("applying inverted panel brightness quirk\n");
14364 /* Some VBT's incorrectly indicate no backlight is present */
14365 static void quirk_backlight_present(struct drm_device *dev)
14367 struct drm_i915_private *dev_priv = to_i915(dev);
14368 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14369 DRM_INFO("applying backlight present quirk\n");
14372 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
14373 * which is 300 ms greater than eDP spec T12 min.
14375 static void quirk_increase_t12_delay(struct drm_device *dev)
14377 struct drm_i915_private *dev_priv = to_i915(dev);
14379 dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY;
14380 DRM_INFO("Applying T12 delay quirk\n");
14383 struct intel_quirk {
14385 int subsystem_vendor;
14386 int subsystem_device;
14387 void (*hook)(struct drm_device *dev);
14390 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14391 struct intel_dmi_quirk {
14392 void (*hook)(struct drm_device *dev);
14393 const struct dmi_system_id (*dmi_id_list)[];
14396 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
14398 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
14402 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
14404 .dmi_id_list = &(const struct dmi_system_id[]) {
14406 .callback = intel_dmi_reverse_brightness,
14407 .ident = "NCR Corporation",
14408 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
14409 DMI_MATCH(DMI_PRODUCT_NAME, ""),
14412 { } /* terminating entry */
14414 .hook = quirk_invert_brightness,
14418 static struct intel_quirk intel_quirks[] = {
14419 /* Lenovo U160 cannot use SSC on LVDS */
14420 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
14422 /* Sony Vaio Y cannot use SSC on LVDS */
14423 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
14425 /* Acer Aspire 5734Z must invert backlight brightness */
14426 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
14428 /* Acer/eMachines G725 */
14429 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
14431 /* Acer/eMachines e725 */
14432 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
14434 /* Acer/Packard Bell NCL20 */
14435 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
14437 /* Acer Aspire 4736Z */
14438 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
14440 /* Acer Aspire 5336 */
14441 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
14443 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14444 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
14446 /* Acer C720 Chromebook (Core i3 4005U) */
14447 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
14449 /* Apple Macbook 2,1 (Core 2 T7400) */
14450 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
14452 /* Apple Macbook 4,1 */
14453 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
14455 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14456 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
14458 /* HP Chromebook 14 (Celeron 2955U) */
14459 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
14461 /* Dell Chromebook 11 */
14462 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
14464 /* Dell Chromebook 11 (2015 version) */
14465 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
14467 /* Toshiba Satellite P50-C-18C */
14468 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
14471 static void intel_init_quirks(struct drm_device *dev)
14473 struct pci_dev *d = dev->pdev;
14476 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
14477 struct intel_quirk *q = &intel_quirks[i];
14479 if (d->device == q->device &&
14480 (d->subsystem_vendor == q->subsystem_vendor ||
14481 q->subsystem_vendor == PCI_ANY_ID) &&
14482 (d->subsystem_device == q->subsystem_device ||
14483 q->subsystem_device == PCI_ANY_ID))
14486 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
14487 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
14488 intel_dmi_quirks[i].hook(dev);
14492 /* Disable the VGA plane that we never use */
14493 static void i915_disable_vga(struct drm_i915_private *dev_priv)
14495 struct pci_dev *pdev = dev_priv->drm.pdev;
14497 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
14499 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14500 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
14501 outb(SR01, VGA_SR_INDEX);
14502 sr1 = inb(VGA_SR_DATA);
14503 outb(sr1 | 1<<5, VGA_SR_DATA);
14504 vga_put(pdev, VGA_RSRC_LEGACY_IO);
14507 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
14508 POSTING_READ(vga_reg);
14511 void intel_modeset_init_hw(struct drm_device *dev)
14513 struct drm_i915_private *dev_priv = to_i915(dev);
14515 intel_update_cdclk(dev_priv);
14516 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
14517 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
14521 * Calculate what we think the watermarks should be for the state we've read
14522 * out of the hardware and then immediately program those watermarks so that
14523 * we ensure the hardware settings match our internal state.
14525 * We can calculate what we think WM's should be by creating a duplicate of the
14526 * current state (which was constructed during hardware readout) and running it
14527 * through the atomic check code to calculate new watermark values in the
14530 static void sanitize_watermarks(struct drm_device *dev)
14532 struct drm_i915_private *dev_priv = to_i915(dev);
14533 struct drm_atomic_state *state;
14534 struct intel_atomic_state *intel_state;
14535 struct drm_crtc *crtc;
14536 struct drm_crtc_state *cstate;
14537 struct drm_modeset_acquire_ctx ctx;
14541 /* Only supported on platforms that use atomic watermark design */
14542 if (!dev_priv->display.optimize_watermarks)
14546 * We need to hold connection_mutex before calling duplicate_state so
14547 * that the connector loop is protected.
14549 drm_modeset_acquire_init(&ctx, 0);
14551 ret = drm_modeset_lock_all_ctx(dev, &ctx);
14552 if (ret == -EDEADLK) {
14553 drm_modeset_backoff(&ctx);
14555 } else if (WARN_ON(ret)) {
14559 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14560 if (WARN_ON(IS_ERR(state)))
14563 intel_state = to_intel_atomic_state(state);
14566 * Hardware readout is the only time we don't want to calculate
14567 * intermediate watermarks (since we don't trust the current
14570 if (!HAS_GMCH_DISPLAY(dev_priv))
14571 intel_state->skip_intermediate_wm = true;
14573 ret = intel_atomic_check(dev, state);
14576 * If we fail here, it means that the hardware appears to be
14577 * programmed in a way that shouldn't be possible, given our
14578 * understanding of watermark requirements. This might mean a
14579 * mistake in the hardware readout code or a mistake in the
14580 * watermark calculations for a given platform. Raise a WARN
14581 * so that this is noticeable.
14583 * If this actually happens, we'll have to just leave the
14584 * BIOS-programmed watermarks untouched and hope for the best.
14586 WARN(true, "Could not determine valid watermarks for inherited state\n");
14590 /* Write calculated watermark values back */
14591 for_each_new_crtc_in_state(state, crtc, cstate, i) {
14592 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14594 cs->wm.need_postvbl_update = true;
14595 dev_priv->display.optimize_watermarks(intel_state, cs);
14597 to_intel_crtc_state(crtc->state)->wm = cs->wm;
14601 drm_atomic_state_put(state);
14603 drm_modeset_drop_locks(&ctx);
14604 drm_modeset_acquire_fini(&ctx);
14607 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14609 if (IS_GEN5(dev_priv)) {
14611 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14613 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14614 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
14615 dev_priv->fdi_pll_freq = 270000;
14620 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14623 int intel_modeset_init(struct drm_device *dev)
14625 struct drm_i915_private *dev_priv = to_i915(dev);
14626 struct i915_ggtt *ggtt = &dev_priv->ggtt;
14628 struct intel_crtc *crtc;
14630 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
14632 drm_mode_config_init(dev);
14634 dev->mode_config.min_width = 0;
14635 dev->mode_config.min_height = 0;
14637 dev->mode_config.preferred_depth = 24;
14638 dev->mode_config.prefer_shadow = 1;
14640 dev->mode_config.allow_fb_modifiers = true;
14642 dev->mode_config.funcs = &intel_mode_funcs;
14644 init_llist_head(&dev_priv->atomic_helper.free_list);
14645 INIT_WORK(&dev_priv->atomic_helper.free_work,
14646 intel_atomic_helper_free_state_worker);
14648 intel_init_quirks(dev);
14650 intel_init_pm(dev_priv);
14652 if (INTEL_INFO(dev_priv)->num_pipes == 0)
14656 * There may be no VBT; and if the BIOS enabled SSC we can
14657 * just keep using it to avoid unnecessary flicker. Whereas if the
14658 * BIOS isn't using it, don't assume it will work even if the VBT
14659 * indicates as much.
14661 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
14662 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
14665 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
14666 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14667 bios_lvds_use_ssc ? "en" : "dis",
14668 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
14669 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
14673 if (IS_GEN2(dev_priv)) {
14674 dev->mode_config.max_width = 2048;
14675 dev->mode_config.max_height = 2048;
14676 } else if (IS_GEN3(dev_priv)) {
14677 dev->mode_config.max_width = 4096;
14678 dev->mode_config.max_height = 4096;
14680 dev->mode_config.max_width = 8192;
14681 dev->mode_config.max_height = 8192;
14684 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14685 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
14686 dev->mode_config.cursor_height = 1023;
14687 } else if (IS_GEN2(dev_priv)) {
14688 dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
14689 dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
14691 dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
14692 dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
14695 dev->mode_config.fb_base = ggtt->gmadr.start;
14697 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14698 INTEL_INFO(dev_priv)->num_pipes,
14699 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
14701 for_each_pipe(dev_priv, pipe) {
14704 ret = intel_crtc_init(dev_priv, pipe);
14706 drm_mode_config_cleanup(dev);
14711 intel_shared_dpll_init(dev);
14712 intel_update_fdi_pll_freq(dev_priv);
14714 intel_update_czclk(dev_priv);
14715 intel_modeset_init_hw(dev);
14717 if (dev_priv->max_cdclk_freq == 0)
14718 intel_update_max_cdclk(dev_priv);
14720 /* Just disable it once at startup */
14721 i915_disable_vga(dev_priv);
14722 intel_setup_outputs(dev_priv);
14724 drm_modeset_lock_all(dev);
14725 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
14726 drm_modeset_unlock_all(dev);
14728 for_each_intel_crtc(dev, crtc) {
14729 struct intel_initial_plane_config plane_config = {};
14735 * Note that reserving the BIOS fb up front prevents us
14736 * from stuffing other stolen allocations like the ring
14737 * on top. This prevents some ugliness at boot time, and
14738 * can even allow for smooth boot transitions if the BIOS
14739 * fb is large enough for the active pipe configuration.
14741 dev_priv->display.get_initial_plane_config(crtc,
14745 * If the fb is shared between multiple heads, we'll
14746 * just get the first one.
14748 intel_find_initial_plane_obj(crtc, &plane_config);
14752 * Make sure hardware watermarks really match the state we read out.
14753 * Note that we need to do this after reconstructing the BIOS fb's
14754 * since the watermark calculation done here will use pstate->fb.
14756 if (!HAS_GMCH_DISPLAY(dev_priv))
14757 sanitize_watermarks(dev);
14762 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
14764 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
14765 /* 640x480@60Hz, ~25175 kHz */
14766 struct dpll clock = {
14776 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
14778 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
14779 pipe_name(pipe), clock.vco, clock.dot);
14781 fp = i9xx_dpll_compute_fp(&clock);
14782 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
14783 DPLL_VGA_MODE_DIS |
14784 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
14785 PLL_P2_DIVIDE_BY_4 |
14786 PLL_REF_INPUT_DREFCLK |
14789 I915_WRITE(FP0(pipe), fp);
14790 I915_WRITE(FP1(pipe), fp);
14792 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
14793 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
14794 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
14795 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
14796 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
14797 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
14798 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
14801 * Apparently we need to have VGA mode enabled prior to changing
14802 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
14803 * dividers, even though the register value does change.
14805 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
14806 I915_WRITE(DPLL(pipe), dpll);
14808 /* Wait for the clocks to stabilize. */
14809 POSTING_READ(DPLL(pipe));
14812 /* The pixel multiplier can only be updated once the
14813 * DPLL is enabled and the clocks are stable.
14815 * So write it again.
14817 I915_WRITE(DPLL(pipe), dpll);
14819 /* We do this three times for luck */
14820 for (i = 0; i < 3 ; i++) {
14821 I915_WRITE(DPLL(pipe), dpll);
14822 POSTING_READ(DPLL(pipe));
14823 udelay(150); /* wait for warmup */
14826 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
14827 POSTING_READ(PIPECONF(pipe));
14829 intel_wait_for_pipe_scanline_moving(crtc);
14832 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
14834 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
14836 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
14839 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
14840 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
14841 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
14842 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & CURSOR_MODE);
14843 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & CURSOR_MODE);
14845 I915_WRITE(PIPECONF(pipe), 0);
14846 POSTING_READ(PIPECONF(pipe));
14848 intel_wait_for_pipe_scanline_stopped(crtc);
14850 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
14851 POSTING_READ(DPLL(pipe));
14854 static bool intel_plane_mapping_ok(struct intel_crtc *crtc,
14855 struct intel_plane *plane)
14857 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14858 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
14859 u32 val = I915_READ(DSPCNTR(i9xx_plane));
14861 return (val & DISPLAY_PLANE_ENABLE) == 0 ||
14862 (val & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE(crtc->pipe);
14866 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
14868 struct intel_crtc *crtc;
14870 if (INTEL_GEN(dev_priv) >= 4)
14873 for_each_intel_crtc(&dev_priv->drm, crtc) {
14874 struct intel_plane *plane =
14875 to_intel_plane(crtc->base.primary);
14877 if (intel_plane_mapping_ok(crtc, plane))
14880 DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n",
14882 intel_plane_disable_noatomic(crtc, plane);
14886 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
14888 struct drm_device *dev = crtc->base.dev;
14889 struct intel_encoder *encoder;
14891 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
14897 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
14899 struct drm_device *dev = encoder->base.dev;
14900 struct intel_connector *connector;
14902 for_each_connector_on_encoder(dev, &encoder->base, connector)
14908 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
14909 enum pipe pch_transcoder)
14911 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
14912 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
14915 static void intel_sanitize_crtc(struct intel_crtc *crtc,
14916 struct drm_modeset_acquire_ctx *ctx)
14918 struct drm_device *dev = crtc->base.dev;
14919 struct drm_i915_private *dev_priv = to_i915(dev);
14920 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
14922 /* Clear any frame start delays used for debugging left by the BIOS */
14923 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
14924 i915_reg_t reg = PIPECONF(cpu_transcoder);
14927 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
14930 /* restore vblank interrupts to correct state */
14931 drm_crtc_vblank_reset(&crtc->base);
14932 if (crtc->active) {
14933 struct intel_plane *plane;
14935 drm_crtc_vblank_on(&crtc->base);
14937 /* Disable everything but the primary plane */
14938 for_each_intel_plane_on_crtc(dev, crtc, plane) {
14939 const struct intel_plane_state *plane_state =
14940 to_intel_plane_state(plane->base.state);
14942 if (plane_state->base.visible &&
14943 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
14944 intel_plane_disable_noatomic(crtc, plane);
14948 /* Adjust the state of the output pipe according to whether we
14949 * have active connectors/encoders. */
14950 if (crtc->active && !intel_crtc_has_encoders(crtc))
14951 intel_crtc_disable_noatomic(&crtc->base, ctx);
14953 if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) {
14955 * We start out with underrun reporting disabled to avoid races.
14956 * For correct bookkeeping mark this on active crtcs.
14958 * Also on gmch platforms we dont have any hardware bits to
14959 * disable the underrun reporting. Which means we need to start
14960 * out with underrun reporting disabled also on inactive pipes,
14961 * since otherwise we'll complain about the garbage we read when
14962 * e.g. coming up after runtime pm.
14964 * No protection against concurrent access is required - at
14965 * worst a fifo underrun happens which also sets this to false.
14967 crtc->cpu_fifo_underrun_disabled = true;
14969 * We track the PCH trancoder underrun reporting state
14970 * within the crtc. With crtc for pipe A housing the underrun
14971 * reporting state for PCH transcoder A, crtc for pipe B housing
14972 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
14973 * and marking underrun reporting as disabled for the non-existing
14974 * PCH transcoders B and C would prevent enabling the south
14975 * error interrupt (see cpt_can_enable_serr_int()).
14977 if (has_pch_trancoder(dev_priv, crtc->pipe))
14978 crtc->pch_fifo_underrun_disabled = true;
14982 static void intel_sanitize_encoder(struct intel_encoder *encoder)
14984 struct intel_connector *connector;
14986 /* We need to check both for a crtc link (meaning that the
14987 * encoder is active and trying to read from a pipe) and the
14988 * pipe itself being active. */
14989 bool has_active_crtc = encoder->base.crtc &&
14990 to_intel_crtc(encoder->base.crtc)->active;
14992 connector = intel_encoder_find_connector(encoder);
14993 if (connector && !has_active_crtc) {
14994 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14995 encoder->base.base.id,
14996 encoder->base.name);
14998 /* Connector is active, but has no active pipe. This is
14999 * fallout from our resume register restoring. Disable
15000 * the encoder manually again. */
15001 if (encoder->base.crtc) {
15002 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15004 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15005 encoder->base.base.id,
15006 encoder->base.name);
15007 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15008 if (encoder->post_disable)
15009 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15011 encoder->base.crtc = NULL;
15013 /* Inconsistent output/port/pipe state happens presumably due to
15014 * a bug in one of the get_hw_state functions. Or someplace else
15015 * in our code, like the register restore mess on resume. Clamp
15016 * things to off as a safer default. */
15018 connector->base.dpms = DRM_MODE_DPMS_OFF;
15019 connector->base.encoder = NULL;
15023 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15025 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15027 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15028 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15029 i915_disable_vga(dev_priv);
15033 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15035 /* This function can be called both from intel_modeset_setup_hw_state or
15036 * at a very early point in our resume sequence, where the power well
15037 * structures are not yet restored. Since this function is at a very
15038 * paranoid "someone might have enabled VGA while we were not looking"
15039 * level, just check if the power well is enabled instead of trying to
15040 * follow the "don't touch the power well if we don't need it" policy
15041 * the rest of the driver uses. */
15042 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
15045 i915_redisable_vga_power_on(dev_priv);
15047 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
15050 /* FIXME read out full plane state for all planes */
15051 static void readout_plane_state(struct intel_crtc *crtc)
15053 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15054 struct intel_crtc_state *crtc_state =
15055 to_intel_crtc_state(crtc->base.state);
15056 struct intel_plane *plane;
15058 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
15059 struct intel_plane_state *plane_state =
15060 to_intel_plane_state(plane->base.state);
15061 bool visible = plane->get_hw_state(plane);
15063 intel_set_plane_visible(crtc_state, plane_state, visible);
15067 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15069 struct drm_i915_private *dev_priv = to_i915(dev);
15071 struct intel_crtc *crtc;
15072 struct intel_encoder *encoder;
15073 struct intel_connector *connector;
15074 struct drm_connector_list_iter conn_iter;
15077 dev_priv->active_crtcs = 0;
15079 for_each_intel_crtc(dev, crtc) {
15080 struct intel_crtc_state *crtc_state =
15081 to_intel_crtc_state(crtc->base.state);
15083 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15084 memset(crtc_state, 0, sizeof(*crtc_state));
15085 crtc_state->base.crtc = &crtc->base;
15087 crtc_state->base.active = crtc_state->base.enable =
15088 dev_priv->display.get_pipe_config(crtc, crtc_state);
15090 crtc->base.enabled = crtc_state->base.enable;
15091 crtc->active = crtc_state->base.active;
15093 if (crtc_state->base.active)
15094 dev_priv->active_crtcs |= 1 << crtc->pipe;
15096 readout_plane_state(crtc);
15098 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15099 crtc->base.base.id, crtc->base.name,
15100 enableddisabled(crtc_state->base.active));
15103 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15104 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15106 pll->on = pll->funcs.get_hw_state(dev_priv, pll,
15107 &pll->state.hw_state);
15108 pll->state.crtc_mask = 0;
15109 for_each_intel_crtc(dev, crtc) {
15110 struct intel_crtc_state *crtc_state =
15111 to_intel_crtc_state(crtc->base.state);
15113 if (crtc_state->base.active &&
15114 crtc_state->shared_dpll == pll)
15115 pll->state.crtc_mask |= 1 << crtc->pipe;
15117 pll->active_mask = pll->state.crtc_mask;
15119 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15120 pll->name, pll->state.crtc_mask, pll->on);
15123 for_each_intel_encoder(dev, encoder) {
15126 if (encoder->get_hw_state(encoder, &pipe)) {
15127 struct intel_crtc_state *crtc_state;
15129 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15130 crtc_state = to_intel_crtc_state(crtc->base.state);
15132 encoder->base.crtc = &crtc->base;
15133 encoder->get_config(encoder, crtc_state);
15135 encoder->base.crtc = NULL;
15138 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15139 encoder->base.base.id, encoder->base.name,
15140 enableddisabled(encoder->base.crtc),
15144 drm_connector_list_iter_begin(dev, &conn_iter);
15145 for_each_intel_connector_iter(connector, &conn_iter) {
15146 if (connector->get_hw_state(connector)) {
15147 connector->base.dpms = DRM_MODE_DPMS_ON;
15149 encoder = connector->encoder;
15150 connector->base.encoder = &encoder->base;
15152 if (encoder->base.crtc &&
15153 encoder->base.crtc->state->active) {
15155 * This has to be done during hardware readout
15156 * because anything calling .crtc_disable may
15157 * rely on the connector_mask being accurate.
15159 encoder->base.crtc->state->connector_mask |=
15160 1 << drm_connector_index(&connector->base);
15161 encoder->base.crtc->state->encoder_mask |=
15162 1 << drm_encoder_index(&encoder->base);
15166 connector->base.dpms = DRM_MODE_DPMS_OFF;
15167 connector->base.encoder = NULL;
15169 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15170 connector->base.base.id, connector->base.name,
15171 enableddisabled(connector->base.encoder));
15173 drm_connector_list_iter_end(&conn_iter);
15175 for_each_intel_crtc(dev, crtc) {
15176 struct intel_crtc_state *crtc_state =
15177 to_intel_crtc_state(crtc->base.state);
15180 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15181 if (crtc_state->base.active) {
15182 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15183 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15184 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15187 * The initial mode needs to be set in order to keep
15188 * the atomic core happy. It wants a valid mode if the
15189 * crtc's enabled, so we do the above call.
15191 * But we don't set all the derived state fully, hence
15192 * set a flag to indicate that a full recalculation is
15193 * needed on the next commit.
15195 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
15197 intel_crtc_compute_pixel_rate(crtc_state);
15199 if (dev_priv->display.modeset_calc_cdclk) {
15200 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15201 if (WARN_ON(min_cdclk < 0))
15205 drm_calc_timestamping_constants(&crtc->base,
15206 &crtc_state->base.adjusted_mode);
15207 update_scanline_offset(crtc);
15210 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
15211 dev_priv->min_voltage_level[crtc->pipe] =
15212 crtc_state->min_voltage_level;
15214 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15219 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15221 struct intel_encoder *encoder;
15223 for_each_intel_encoder(&dev_priv->drm, encoder) {
15225 enum intel_display_power_domain domain;
15227 if (!encoder->get_power_domains)
15230 get_domains = encoder->get_power_domains(encoder);
15231 for_each_power_domain(domain, get_domains)
15232 intel_display_power_get(dev_priv, domain);
15236 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15238 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15239 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15240 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15243 if (IS_HASWELL(dev_priv)) {
15245 * WaRsPkgCStateDisplayPMReq:hsw
15246 * System hang if this isn't done before disabling all planes!
15248 I915_WRITE(CHICKEN_PAR1_1,
15249 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15253 /* Scan out the current hw modeset state,
15254 * and sanitizes it to the current state
15257 intel_modeset_setup_hw_state(struct drm_device *dev,
15258 struct drm_modeset_acquire_ctx *ctx)
15260 struct drm_i915_private *dev_priv = to_i915(dev);
15262 struct intel_crtc *crtc;
15263 struct intel_encoder *encoder;
15266 intel_early_display_was(dev_priv);
15267 intel_modeset_readout_hw_state(dev);
15269 /* HW state is read out, now we need to sanitize this mess. */
15270 get_encoder_power_domains(dev_priv);
15272 intel_sanitize_plane_mapping(dev_priv);
15274 for_each_intel_encoder(dev, encoder) {
15275 intel_sanitize_encoder(encoder);
15278 for_each_pipe(dev_priv, pipe) {
15279 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15281 intel_sanitize_crtc(crtc, ctx);
15282 intel_dump_pipe_config(crtc, crtc->config,
15283 "[setup_hw_state]");
15286 intel_modeset_update_connector_atomic_state(dev);
15288 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15289 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15291 if (!pll->on || pll->active_mask)
15294 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
15296 pll->funcs.disable(dev_priv, pll);
15300 if (IS_G4X(dev_priv)) {
15301 g4x_wm_get_hw_state(dev);
15302 g4x_wm_sanitize(dev_priv);
15303 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15304 vlv_wm_get_hw_state(dev);
15305 vlv_wm_sanitize(dev_priv);
15306 } else if (INTEL_GEN(dev_priv) >= 9) {
15307 skl_wm_get_hw_state(dev);
15308 } else if (HAS_PCH_SPLIT(dev_priv)) {
15309 ilk_wm_get_hw_state(dev);
15312 for_each_intel_crtc(dev, crtc) {
15315 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config);
15316 if (WARN_ON(put_domains))
15317 modeset_put_power_domains(dev_priv, put_domains);
15319 intel_display_set_init_power(dev_priv, false);
15321 intel_power_domains_verify_state(dev_priv);
15323 intel_fbc_init_pipe_state(dev_priv);
15326 void intel_display_resume(struct drm_device *dev)
15328 struct drm_i915_private *dev_priv = to_i915(dev);
15329 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15330 struct drm_modeset_acquire_ctx ctx;
15333 dev_priv->modeset_restore_state = NULL;
15335 state->acquire_ctx = &ctx;
15337 drm_modeset_acquire_init(&ctx, 0);
15340 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15341 if (ret != -EDEADLK)
15344 drm_modeset_backoff(&ctx);
15348 ret = __intel_display_resume(dev, state, &ctx);
15350 intel_enable_ipc(dev_priv);
15351 drm_modeset_drop_locks(&ctx);
15352 drm_modeset_acquire_fini(&ctx);
15355 DRM_ERROR("Restoring old state failed with %i\n", ret);
15357 drm_atomic_state_put(state);
15360 int intel_connector_register(struct drm_connector *connector)
15362 struct intel_connector *intel_connector = to_intel_connector(connector);
15365 ret = intel_backlight_device_register(intel_connector);
15375 void intel_connector_unregister(struct drm_connector *connector)
15377 struct intel_connector *intel_connector = to_intel_connector(connector);
15379 intel_backlight_device_unregister(intel_connector);
15380 intel_panel_destroy_backlight(connector);
15383 static void intel_hpd_poll_fini(struct drm_device *dev)
15385 struct intel_connector *connector;
15386 struct drm_connector_list_iter conn_iter;
15388 /* Kill all the work that may have been queued by hpd. */
15389 drm_connector_list_iter_begin(dev, &conn_iter);
15390 for_each_intel_connector_iter(connector, &conn_iter) {
15391 if (connector->modeset_retry_work.func)
15392 cancel_work_sync(&connector->modeset_retry_work);
15393 if (connector->hdcp_shim) {
15394 cancel_delayed_work_sync(&connector->hdcp_check_work);
15395 cancel_work_sync(&connector->hdcp_prop_work);
15398 drm_connector_list_iter_end(&conn_iter);
15401 void intel_modeset_cleanup(struct drm_device *dev)
15403 struct drm_i915_private *dev_priv = to_i915(dev);
15405 flush_work(&dev_priv->atomic_helper.free_work);
15406 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15408 intel_disable_gt_powersave(dev_priv);
15411 * Interrupts and polling as the first thing to avoid creating havoc.
15412 * Too much stuff here (turning of connectors, ...) would
15413 * experience fancy races otherwise.
15415 intel_irq_uninstall(dev_priv);
15418 * Due to the hpd irq storm handling the hotplug work can re-arm the
15419 * poll handlers. Hence disable polling after hpd handling is shut down.
15421 intel_hpd_poll_fini(dev);
15423 /* poll work can call into fbdev, hence clean that up afterwards */
15424 intel_fbdev_fini(dev_priv);
15426 intel_unregister_dsm_handler();
15428 intel_fbc_global_disable(dev_priv);
15430 /* flush any delayed tasks or pending work */
15431 flush_scheduled_work();
15433 drm_mode_config_cleanup(dev);
15435 intel_cleanup_overlay(dev_priv);
15437 intel_cleanup_gt_powersave(dev_priv);
15439 intel_teardown_gmbus(dev_priv);
15441 destroy_workqueue(dev_priv->modeset_wq);
15444 void intel_connector_attach_encoder(struct intel_connector *connector,
15445 struct intel_encoder *encoder)
15447 connector->encoder = encoder;
15448 drm_mode_connector_attach_encoder(&connector->base,
15453 * set vga decode state - true == enable VGA decode
15455 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
15457 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
15460 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15461 DRM_ERROR("failed to read control word\n");
15465 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15469 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15471 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
15473 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15474 DRM_ERROR("failed to write control word\n");
15481 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15483 struct intel_display_error_state {
15485 u32 power_well_driver;
15487 int num_transcoders;
15489 struct intel_cursor_error_state {
15494 } cursor[I915_MAX_PIPES];
15496 struct intel_pipe_error_state {
15497 bool power_domain_on;
15500 } pipe[I915_MAX_PIPES];
15502 struct intel_plane_error_state {
15510 } plane[I915_MAX_PIPES];
15512 struct intel_transcoder_error_state {
15513 bool power_domain_on;
15514 enum transcoder cpu_transcoder;
15527 struct intel_display_error_state *
15528 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
15530 struct intel_display_error_state *error;
15531 int transcoders[] = {
15539 if (INTEL_INFO(dev_priv)->num_pipes == 0)
15542 error = kzalloc(sizeof(*error), GFP_ATOMIC);
15546 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15547 error->power_well_driver =
15548 I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL));
15550 for_each_pipe(dev_priv, i) {
15551 error->pipe[i].power_domain_on =
15552 __intel_display_power_is_enabled(dev_priv,
15553 POWER_DOMAIN_PIPE(i));
15554 if (!error->pipe[i].power_domain_on)
15557 error->cursor[i].control = I915_READ(CURCNTR(i));
15558 error->cursor[i].position = I915_READ(CURPOS(i));
15559 error->cursor[i].base = I915_READ(CURBASE(i));
15561 error->plane[i].control = I915_READ(DSPCNTR(i));
15562 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
15563 if (INTEL_GEN(dev_priv) <= 3) {
15564 error->plane[i].size = I915_READ(DSPSIZE(i));
15565 error->plane[i].pos = I915_READ(DSPPOS(i));
15567 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15568 error->plane[i].addr = I915_READ(DSPADDR(i));
15569 if (INTEL_GEN(dev_priv) >= 4) {
15570 error->plane[i].surface = I915_READ(DSPSURF(i));
15571 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
15574 error->pipe[i].source = I915_READ(PIPESRC(i));
15576 if (HAS_GMCH_DISPLAY(dev_priv))
15577 error->pipe[i].stat = I915_READ(PIPESTAT(i));
15580 /* Note: this does not include DSI transcoders. */
15581 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
15582 if (HAS_DDI(dev_priv))
15583 error->num_transcoders++; /* Account for eDP. */
15585 for (i = 0; i < error->num_transcoders; i++) {
15586 enum transcoder cpu_transcoder = transcoders[i];
15588 error->transcoder[i].power_domain_on =
15589 __intel_display_power_is_enabled(dev_priv,
15590 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
15591 if (!error->transcoder[i].power_domain_on)
15594 error->transcoder[i].cpu_transcoder = cpu_transcoder;
15596 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
15597 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
15598 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
15599 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
15600 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
15601 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
15602 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
15608 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15611 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
15612 struct intel_display_error_state *error)
15614 struct drm_i915_private *dev_priv = m->i915;
15620 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
15621 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15622 err_printf(m, "PWR_WELL_CTL2: %08x\n",
15623 error->power_well_driver);
15624 for_each_pipe(dev_priv, i) {
15625 err_printf(m, "Pipe [%d]:\n", i);
15626 err_printf(m, " Power: %s\n",
15627 onoff(error->pipe[i].power_domain_on));
15628 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
15629 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
15631 err_printf(m, "Plane [%d]:\n", i);
15632 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
15633 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
15634 if (INTEL_GEN(dev_priv) <= 3) {
15635 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
15636 err_printf(m, " POS: %08x\n", error->plane[i].pos);
15638 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15639 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
15640 if (INTEL_GEN(dev_priv) >= 4) {
15641 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
15642 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
15645 err_printf(m, "Cursor [%d]:\n", i);
15646 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
15647 err_printf(m, " POS: %08x\n", error->cursor[i].position);
15648 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
15651 for (i = 0; i < error->num_transcoders; i++) {
15652 err_printf(m, "CPU transcoder: %s\n",
15653 transcoder_name(error->transcoder[i].cpu_transcoder));
15654 err_printf(m, " Power: %s\n",
15655 onoff(error->transcoder[i].power_domain_on));
15656 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
15657 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
15658 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
15659 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
15660 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
15661 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
15662 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);