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)
562 * Returns whether the given set of divisors are valid for a given refclk with
563 * 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_INFO(dev_priv)->gen >= 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_INFO(dev_priv)->gen >= 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);
2071 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation)
2073 struct drm_device *dev = fb->dev;
2074 struct drm_i915_private *dev_priv = to_i915(dev);
2075 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2076 struct i915_ggtt_view view;
2077 struct i915_vma *vma;
2080 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2082 alignment = intel_surf_alignment(fb, 0);
2084 intel_fill_fb_ggtt_view(&view, fb, rotation);
2086 /* Note that the w/a also requires 64 PTE of padding following the
2087 * bo. We currently fill all unused PTE with the shadow page and so
2088 * we should always have valid PTE following the scanout preventing
2091 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2092 alignment = 256 * 1024;
2095 * Global gtt pte registers are special registers which actually forward
2096 * writes to a chunk of system memory. Which means that there is no risk
2097 * that the register values disappear as soon as we call
2098 * intel_runtime_pm_put(), so it is correct to wrap only the
2099 * pin/unpin/fence and not more.
2101 intel_runtime_pm_get(dev_priv);
2103 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2105 vma = i915_gem_object_pin_to_display_plane(obj, alignment, &view);
2109 if (i915_vma_is_map_and_fenceable(vma)) {
2110 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2111 * fence, whereas 965+ only requires a fence if using
2112 * framebuffer compression. For simplicity, we always, when
2113 * possible, install a fence as the cost is not that onerous.
2115 * If we fail to fence the tiled scanout, then either the
2116 * modeset will reject the change (which is highly unlikely as
2117 * the affected systems, all but one, do not have unmappable
2118 * space) or we will not be able to enable full powersaving
2119 * techniques (also likely not to apply due to various limits
2120 * FBC and the like impose on the size of the buffer, which
2121 * presumably we violated anyway with this unmappable buffer).
2122 * Anyway, it is presumably better to stumble onwards with
2123 * something and try to run the system in a "less than optimal"
2124 * mode that matches the user configuration.
2126 i915_vma_pin_fence(vma);
2131 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2133 intel_runtime_pm_put(dev_priv);
2137 void intel_unpin_fb_vma(struct i915_vma *vma)
2139 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2141 i915_vma_unpin_fence(vma);
2142 i915_gem_object_unpin_from_display_plane(vma);
2146 static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
2147 unsigned int rotation)
2149 if (drm_rotation_90_or_270(rotation))
2150 return to_intel_framebuffer(fb)->rotated[plane].pitch;
2152 return fb->pitches[plane];
2156 * Convert the x/y offsets into a linear offset.
2157 * Only valid with 0/180 degree rotation, which is fine since linear
2158 * offset is only used with linear buffers on pre-hsw and tiled buffers
2159 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2161 u32 intel_fb_xy_to_linear(int x, int y,
2162 const struct intel_plane_state *state,
2165 const struct drm_framebuffer *fb = state->base.fb;
2166 unsigned int cpp = fb->format->cpp[plane];
2167 unsigned int pitch = fb->pitches[plane];
2169 return y * pitch + x * cpp;
2173 * Add the x/y offsets derived from fb->offsets[] to the user
2174 * specified plane src x/y offsets. The resulting x/y offsets
2175 * specify the start of scanout from the beginning of the gtt mapping.
2177 void intel_add_fb_offsets(int *x, int *y,
2178 const struct intel_plane_state *state,
2182 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2183 unsigned int rotation = state->base.rotation;
2185 if (drm_rotation_90_or_270(rotation)) {
2186 *x += intel_fb->rotated[plane].x;
2187 *y += intel_fb->rotated[plane].y;
2189 *x += intel_fb->normal[plane].x;
2190 *y += intel_fb->normal[plane].y;
2194 static u32 __intel_adjust_tile_offset(int *x, int *y,
2195 unsigned int tile_width,
2196 unsigned int tile_height,
2197 unsigned int tile_size,
2198 unsigned int pitch_tiles,
2202 unsigned int pitch_pixels = pitch_tiles * tile_width;
2205 WARN_ON(old_offset & (tile_size - 1));
2206 WARN_ON(new_offset & (tile_size - 1));
2207 WARN_ON(new_offset > old_offset);
2209 tiles = (old_offset - new_offset) / tile_size;
2211 *y += tiles / pitch_tiles * tile_height;
2212 *x += tiles % pitch_tiles * tile_width;
2214 /* minimize x in case it got needlessly big */
2215 *y += *x / pitch_pixels * tile_height;
2221 static u32 _intel_adjust_tile_offset(int *x, int *y,
2222 const struct drm_framebuffer *fb, int plane,
2223 unsigned int rotation,
2224 u32 old_offset, u32 new_offset)
2226 const struct drm_i915_private *dev_priv = to_i915(fb->dev);
2227 unsigned int cpp = fb->format->cpp[plane];
2228 unsigned int pitch = intel_fb_pitch(fb, plane, rotation);
2230 WARN_ON(new_offset > old_offset);
2232 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2233 unsigned int tile_size, tile_width, tile_height;
2234 unsigned int pitch_tiles;
2236 tile_size = intel_tile_size(dev_priv);
2237 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2239 if (drm_rotation_90_or_270(rotation)) {
2240 pitch_tiles = pitch / tile_height;
2241 swap(tile_width, tile_height);
2243 pitch_tiles = pitch / (tile_width * cpp);
2246 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2247 tile_size, pitch_tiles,
2248 old_offset, new_offset);
2250 old_offset += *y * pitch + *x * cpp;
2252 *y = (old_offset - new_offset) / pitch;
2253 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2260 * Adjust the tile offset by moving the difference into
2263 static u32 intel_adjust_tile_offset(int *x, int *y,
2264 const struct intel_plane_state *state, int plane,
2265 u32 old_offset, u32 new_offset)
2267 return _intel_adjust_tile_offset(x, y, state->base.fb, plane,
2268 state->base.rotation,
2269 old_offset, new_offset);
2273 * Computes the linear offset to the base tile and adjusts
2274 * x, y. bytes per pixel is assumed to be a power-of-two.
2276 * In the 90/270 rotated case, x and y are assumed
2277 * to be already rotated to match the rotated GTT view, and
2278 * pitch is the tile_height aligned framebuffer height.
2280 * This function is used when computing the derived information
2281 * under intel_framebuffer, so using any of that information
2282 * here is not allowed. Anything under drm_framebuffer can be
2283 * used. This is why the user has to pass in the pitch since it
2284 * is specified in the rotated orientation.
2286 static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv,
2288 const struct drm_framebuffer *fb, int plane,
2290 unsigned int rotation,
2293 uint64_t fb_modifier = fb->modifier;
2294 unsigned int cpp = fb->format->cpp[plane];
2295 u32 offset, offset_aligned;
2300 if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
2301 unsigned int tile_size, tile_width, tile_height;
2302 unsigned int tile_rows, tiles, pitch_tiles;
2304 tile_size = intel_tile_size(dev_priv);
2305 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2307 if (drm_rotation_90_or_270(rotation)) {
2308 pitch_tiles = pitch / tile_height;
2309 swap(tile_width, tile_height);
2311 pitch_tiles = pitch / (tile_width * cpp);
2314 tile_rows = *y / tile_height;
2317 tiles = *x / tile_width;
2320 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2321 offset_aligned = offset & ~alignment;
2323 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2324 tile_size, pitch_tiles,
2325 offset, offset_aligned);
2327 offset = *y * pitch + *x * cpp;
2328 offset_aligned = offset & ~alignment;
2330 *y = (offset & alignment) / pitch;
2331 *x = ((offset & alignment) - *y * pitch) / cpp;
2334 return offset_aligned;
2337 u32 intel_compute_tile_offset(int *x, int *y,
2338 const struct intel_plane_state *state,
2341 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2342 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2343 const struct drm_framebuffer *fb = state->base.fb;
2344 unsigned int rotation = state->base.rotation;
2345 int pitch = intel_fb_pitch(fb, plane, rotation);
2348 if (intel_plane->id == PLANE_CURSOR)
2349 alignment = intel_cursor_alignment(dev_priv);
2351 alignment = intel_surf_alignment(fb, plane);
2353 return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch,
2354 rotation, alignment);
2357 /* Convert the fb->offset[] into x/y offsets */
2358 static int intel_fb_offset_to_xy(int *x, int *y,
2359 const struct drm_framebuffer *fb, int plane)
2361 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2363 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2364 fb->offsets[plane] % intel_tile_size(dev_priv))
2370 _intel_adjust_tile_offset(x, y,
2371 fb, plane, DRM_MODE_ROTATE_0,
2372 fb->offsets[plane], 0);
2377 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2379 switch (fb_modifier) {
2380 case I915_FORMAT_MOD_X_TILED:
2381 return I915_TILING_X;
2382 case I915_FORMAT_MOD_Y_TILED:
2383 case I915_FORMAT_MOD_Y_TILED_CCS:
2384 return I915_TILING_Y;
2386 return I915_TILING_NONE;
2390 static const struct drm_format_info ccs_formats[] = {
2391 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2392 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2393 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2394 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2397 static const struct drm_format_info *
2398 lookup_format_info(const struct drm_format_info formats[],
2399 int num_formats, u32 format)
2403 for (i = 0; i < num_formats; i++) {
2404 if (formats[i].format == format)
2411 static const struct drm_format_info *
2412 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2414 switch (cmd->modifier[0]) {
2415 case I915_FORMAT_MOD_Y_TILED_CCS:
2416 case I915_FORMAT_MOD_Yf_TILED_CCS:
2417 return lookup_format_info(ccs_formats,
2418 ARRAY_SIZE(ccs_formats),
2426 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2427 struct drm_framebuffer *fb)
2429 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2430 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2431 u32 gtt_offset_rotated = 0;
2432 unsigned int max_size = 0;
2433 int i, num_planes = fb->format->num_planes;
2434 unsigned int tile_size = intel_tile_size(dev_priv);
2436 for (i = 0; i < num_planes; i++) {
2437 unsigned int width, height;
2438 unsigned int cpp, size;
2443 cpp = fb->format->cpp[i];
2444 width = drm_framebuffer_plane_width(fb->width, fb, i);
2445 height = drm_framebuffer_plane_height(fb->height, fb, i);
2447 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2449 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2454 if ((fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2455 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) && i == 1) {
2456 int hsub = fb->format->hsub;
2457 int vsub = fb->format->vsub;
2458 int tile_width, tile_height;
2462 intel_tile_dims(fb, i, &tile_width, &tile_height);
2464 tile_height *= vsub;
2466 ccs_x = (x * hsub) % tile_width;
2467 ccs_y = (y * vsub) % tile_height;
2468 main_x = intel_fb->normal[0].x % tile_width;
2469 main_y = intel_fb->normal[0].y % tile_height;
2472 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2473 * x/y offsets must match between CCS and the main surface.
2475 if (main_x != ccs_x || main_y != ccs_y) {
2476 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2479 intel_fb->normal[0].x,
2480 intel_fb->normal[0].y,
2487 * The fence (if used) is aligned to the start of the object
2488 * so having the framebuffer wrap around across the edge of the
2489 * fenced region doesn't really work. We have no API to configure
2490 * the fence start offset within the object (nor could we probably
2491 * on gen2/3). So it's just easier if we just require that the
2492 * fb layout agrees with the fence layout. We already check that the
2493 * fb stride matches the fence stride elsewhere.
2495 if (i == 0 && i915_gem_object_is_tiled(intel_fb->obj) &&
2496 (x + width) * cpp > fb->pitches[i]) {
2497 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2503 * First pixel of the framebuffer from
2504 * the start of the normal gtt mapping.
2506 intel_fb->normal[i].x = x;
2507 intel_fb->normal[i].y = y;
2509 offset = _intel_compute_tile_offset(dev_priv, &x, &y,
2510 fb, i, fb->pitches[i],
2511 DRM_MODE_ROTATE_0, tile_size);
2512 offset /= tile_size;
2514 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2515 unsigned int tile_width, tile_height;
2516 unsigned int pitch_tiles;
2519 intel_tile_dims(fb, i, &tile_width, &tile_height);
2521 rot_info->plane[i].offset = offset;
2522 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2523 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2524 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2526 intel_fb->rotated[i].pitch =
2527 rot_info->plane[i].height * tile_height;
2529 /* how many tiles does this plane need */
2530 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2532 * If the plane isn't horizontally tile aligned,
2533 * we need one more tile.
2538 /* rotate the x/y offsets to match the GTT view */
2544 rot_info->plane[i].width * tile_width,
2545 rot_info->plane[i].height * tile_height,
2546 DRM_MODE_ROTATE_270);
2550 /* rotate the tile dimensions to match the GTT view */
2551 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2552 swap(tile_width, tile_height);
2555 * We only keep the x/y offsets, so push all of the
2556 * gtt offset into the x/y offsets.
2558 __intel_adjust_tile_offset(&x, &y,
2559 tile_width, tile_height,
2560 tile_size, pitch_tiles,
2561 gtt_offset_rotated * tile_size, 0);
2563 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2566 * First pixel of the framebuffer from
2567 * the start of the rotated gtt mapping.
2569 intel_fb->rotated[i].x = x;
2570 intel_fb->rotated[i].y = y;
2572 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2573 x * cpp, tile_size);
2576 /* how many tiles in total needed in the bo */
2577 max_size = max(max_size, offset + size);
2580 if (max_size * tile_size > intel_fb->obj->base.size) {
2581 DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
2582 max_size * tile_size, intel_fb->obj->base.size);
2589 static int i9xx_format_to_fourcc(int format)
2592 case DISPPLANE_8BPP:
2593 return DRM_FORMAT_C8;
2594 case DISPPLANE_BGRX555:
2595 return DRM_FORMAT_XRGB1555;
2596 case DISPPLANE_BGRX565:
2597 return DRM_FORMAT_RGB565;
2599 case DISPPLANE_BGRX888:
2600 return DRM_FORMAT_XRGB8888;
2601 case DISPPLANE_RGBX888:
2602 return DRM_FORMAT_XBGR8888;
2603 case DISPPLANE_BGRX101010:
2604 return DRM_FORMAT_XRGB2101010;
2605 case DISPPLANE_RGBX101010:
2606 return DRM_FORMAT_XBGR2101010;
2610 static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2613 case PLANE_CTL_FORMAT_RGB_565:
2614 return DRM_FORMAT_RGB565;
2616 case PLANE_CTL_FORMAT_XRGB_8888:
2619 return DRM_FORMAT_ABGR8888;
2621 return DRM_FORMAT_XBGR8888;
2624 return DRM_FORMAT_ARGB8888;
2626 return DRM_FORMAT_XRGB8888;
2628 case PLANE_CTL_FORMAT_XRGB_2101010:
2630 return DRM_FORMAT_XBGR2101010;
2632 return DRM_FORMAT_XRGB2101010;
2637 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2638 struct intel_initial_plane_config *plane_config)
2640 struct drm_device *dev = crtc->base.dev;
2641 struct drm_i915_private *dev_priv = to_i915(dev);
2642 struct i915_ggtt *ggtt = &dev_priv->ggtt;
2643 struct drm_i915_gem_object *obj = NULL;
2644 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2645 struct drm_framebuffer *fb = &plane_config->fb->base;
2646 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2647 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2650 size_aligned -= base_aligned;
2652 if (plane_config->size == 0)
2655 /* If the FB is too big, just don't use it since fbdev is not very
2656 * important and we should probably use that space with FBC or other
2658 if (size_aligned * 2 > ggtt->stolen_usable_size)
2661 mutex_lock(&dev->struct_mutex);
2662 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2666 mutex_unlock(&dev->struct_mutex);
2670 if (plane_config->tiling == I915_TILING_X)
2671 obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X;
2673 mode_cmd.pixel_format = fb->format->format;
2674 mode_cmd.width = fb->width;
2675 mode_cmd.height = fb->height;
2676 mode_cmd.pitches[0] = fb->pitches[0];
2677 mode_cmd.modifier[0] = fb->modifier;
2678 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2680 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2681 DRM_DEBUG_KMS("intel fb init failed\n");
2686 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2690 i915_gem_object_put(obj);
2695 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2696 struct intel_plane_state *plane_state,
2699 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2701 plane_state->base.visible = visible;
2703 /* FIXME pre-g4x don't work like this */
2705 crtc_state->base.plane_mask |= BIT(drm_plane_index(&plane->base));
2706 crtc_state->active_planes |= BIT(plane->id);
2708 crtc_state->base.plane_mask &= ~BIT(drm_plane_index(&plane->base));
2709 crtc_state->active_planes &= ~BIT(plane->id);
2712 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2713 crtc_state->base.crtc->name,
2714 crtc_state->active_planes);
2717 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2718 struct intel_plane *plane)
2720 struct intel_crtc_state *crtc_state =
2721 to_intel_crtc_state(crtc->base.state);
2722 struct intel_plane_state *plane_state =
2723 to_intel_plane_state(plane->base.state);
2725 intel_set_plane_visible(crtc_state, plane_state, false);
2727 if (plane->id == PLANE_PRIMARY)
2728 intel_pre_disable_primary_noatomic(&crtc->base);
2730 trace_intel_disable_plane(&plane->base, crtc);
2731 plane->disable_plane(plane, crtc);
2735 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2736 struct intel_initial_plane_config *plane_config)
2738 struct drm_device *dev = intel_crtc->base.dev;
2739 struct drm_i915_private *dev_priv = to_i915(dev);
2741 struct drm_i915_gem_object *obj;
2742 struct drm_plane *primary = intel_crtc->base.primary;
2743 struct drm_plane_state *plane_state = primary->state;
2744 struct drm_crtc_state *crtc_state = intel_crtc->base.state;
2745 struct intel_plane *intel_plane = to_intel_plane(primary);
2746 struct intel_plane_state *intel_state =
2747 to_intel_plane_state(plane_state);
2748 struct drm_framebuffer *fb;
2750 if (!plane_config->fb)
2753 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2754 fb = &plane_config->fb->base;
2758 kfree(plane_config->fb);
2761 * Failed to alloc the obj, check to see if we should share
2762 * an fb with another CRTC instead
2764 for_each_crtc(dev, c) {
2765 struct intel_plane_state *state;
2767 if (c == &intel_crtc->base)
2770 if (!to_intel_crtc(c)->active)
2773 state = to_intel_plane_state(c->primary->state);
2777 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2778 fb = c->primary->fb;
2779 drm_framebuffer_get(fb);
2785 * We've failed to reconstruct the BIOS FB. Current display state
2786 * indicates that the primary plane is visible, but has a NULL FB,
2787 * which will lead to problems later if we don't fix it up. The
2788 * simplest solution is to just disable the primary plane now and
2789 * pretend the BIOS never had it enabled.
2791 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2796 mutex_lock(&dev->struct_mutex);
2798 intel_pin_and_fence_fb_obj(fb, primary->state->rotation);
2799 mutex_unlock(&dev->struct_mutex);
2800 if (IS_ERR(intel_state->vma)) {
2801 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2802 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2804 intel_state->vma = NULL;
2805 drm_framebuffer_put(fb);
2809 plane_state->src_x = 0;
2810 plane_state->src_y = 0;
2811 plane_state->src_w = fb->width << 16;
2812 plane_state->src_h = fb->height << 16;
2814 plane_state->crtc_x = 0;
2815 plane_state->crtc_y = 0;
2816 plane_state->crtc_w = fb->width;
2817 plane_state->crtc_h = fb->height;
2819 intel_state->base.src = drm_plane_state_src(plane_state);
2820 intel_state->base.dst = drm_plane_state_dest(plane_state);
2822 obj = intel_fb_obj(fb);
2823 if (i915_gem_object_is_tiled(obj))
2824 dev_priv->preserve_bios_swizzle = true;
2826 drm_framebuffer_get(fb);
2827 primary->fb = primary->state->fb = fb;
2828 primary->crtc = primary->state->crtc = &intel_crtc->base;
2830 intel_set_plane_visible(to_intel_crtc_state(crtc_state),
2831 to_intel_plane_state(plane_state),
2834 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2835 &obj->frontbuffer_bits);
2838 static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane,
2839 unsigned int rotation)
2841 int cpp = fb->format->cpp[plane];
2843 switch (fb->modifier) {
2844 case DRM_FORMAT_MOD_LINEAR:
2845 case I915_FORMAT_MOD_X_TILED:
2858 case I915_FORMAT_MOD_Y_TILED_CCS:
2859 case I915_FORMAT_MOD_Yf_TILED_CCS:
2860 /* FIXME AUX plane? */
2861 case I915_FORMAT_MOD_Y_TILED:
2862 case I915_FORMAT_MOD_Yf_TILED:
2877 MISSING_CASE(fb->modifier);
2883 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2884 int main_x, int main_y, u32 main_offset)
2886 const struct drm_framebuffer *fb = plane_state->base.fb;
2887 int hsub = fb->format->hsub;
2888 int vsub = fb->format->vsub;
2889 int aux_x = plane_state->aux.x;
2890 int aux_y = plane_state->aux.y;
2891 u32 aux_offset = plane_state->aux.offset;
2892 u32 alignment = intel_surf_alignment(fb, 1);
2894 while (aux_offset >= main_offset && aux_y <= main_y) {
2897 if (aux_x == main_x && aux_y == main_y)
2900 if (aux_offset == 0)
2905 aux_offset = intel_adjust_tile_offset(&x, &y, plane_state, 1,
2906 aux_offset, aux_offset - alignment);
2907 aux_x = x * hsub + aux_x % hsub;
2908 aux_y = y * vsub + aux_y % vsub;
2911 if (aux_x != main_x || aux_y != main_y)
2914 plane_state->aux.offset = aux_offset;
2915 plane_state->aux.x = aux_x;
2916 plane_state->aux.y = aux_y;
2921 static int skl_check_main_surface(struct intel_plane_state *plane_state)
2923 const struct drm_framebuffer *fb = plane_state->base.fb;
2924 unsigned int rotation = plane_state->base.rotation;
2925 int x = plane_state->base.src.x1 >> 16;
2926 int y = plane_state->base.src.y1 >> 16;
2927 int w = drm_rect_width(&plane_state->base.src) >> 16;
2928 int h = drm_rect_height(&plane_state->base.src) >> 16;
2929 int max_width = skl_max_plane_width(fb, 0, rotation);
2930 int max_height = 4096;
2931 u32 alignment, offset, aux_offset = plane_state->aux.offset;
2933 if (w > max_width || h > max_height) {
2934 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2935 w, h, max_width, max_height);
2939 intel_add_fb_offsets(&x, &y, plane_state, 0);
2940 offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
2941 alignment = intel_surf_alignment(fb, 0);
2944 * AUX surface offset is specified as the distance from the
2945 * main surface offset, and it must be non-negative. Make
2946 * sure that is what we will get.
2948 if (offset > aux_offset)
2949 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
2950 offset, aux_offset & ~(alignment - 1));
2953 * When using an X-tiled surface, the plane blows up
2954 * if the x offset + width exceed the stride.
2956 * TODO: linear and Y-tiled seem fine, Yf untested,
2958 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
2959 int cpp = fb->format->cpp[0];
2961 while ((x + w) * cpp > fb->pitches[0]) {
2963 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
2967 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
2968 offset, offset - alignment);
2973 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
2974 * they match with the main surface x/y offsets.
2976 if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2977 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
2978 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
2982 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
2983 offset, offset - alignment);
2986 if (x != plane_state->aux.x || y != plane_state->aux.y) {
2987 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
2992 plane_state->main.offset = offset;
2993 plane_state->main.x = x;
2994 plane_state->main.y = y;
2999 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3001 const struct drm_framebuffer *fb = plane_state->base.fb;
3002 unsigned int rotation = plane_state->base.rotation;
3003 int max_width = skl_max_plane_width(fb, 1, rotation);
3004 int max_height = 4096;
3005 int x = plane_state->base.src.x1 >> 17;
3006 int y = plane_state->base.src.y1 >> 17;
3007 int w = drm_rect_width(&plane_state->base.src) >> 17;
3008 int h = drm_rect_height(&plane_state->base.src) >> 17;
3011 intel_add_fb_offsets(&x, &y, plane_state, 1);
3012 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3014 /* FIXME not quite sure how/if these apply to the chroma plane */
3015 if (w > max_width || h > max_height) {
3016 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3017 w, h, max_width, max_height);
3021 plane_state->aux.offset = offset;
3022 plane_state->aux.x = x;
3023 plane_state->aux.y = y;
3028 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3030 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3031 struct intel_crtc *crtc = to_intel_crtc(plane_state->base.crtc);
3032 const struct drm_framebuffer *fb = plane_state->base.fb;
3033 int src_x = plane_state->base.src.x1 >> 16;
3034 int src_y = plane_state->base.src.y1 >> 16;
3035 int hsub = fb->format->hsub;
3036 int vsub = fb->format->vsub;
3037 int x = src_x / hsub;
3038 int y = src_y / vsub;
3041 switch (plane->id) {
3046 DRM_DEBUG_KMS("RC support only on plane 1 and 2\n");
3050 if (crtc->pipe == PIPE_C) {
3051 DRM_DEBUG_KMS("No RC support on pipe C\n");
3055 if (plane_state->base.rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180)) {
3056 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation %x\n",
3057 plane_state->base.rotation);
3061 intel_add_fb_offsets(&x, &y, plane_state, 1);
3062 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3064 plane_state->aux.offset = offset;
3065 plane_state->aux.x = x * hsub + src_x % hsub;
3066 plane_state->aux.y = y * vsub + src_y % vsub;
3071 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3073 const struct drm_framebuffer *fb = plane_state->base.fb;
3074 unsigned int rotation = plane_state->base.rotation;
3077 if (!plane_state->base.visible)
3080 /* Rotate src coordinates to match rotated GTT view */
3081 if (drm_rotation_90_or_270(rotation))
3082 drm_rect_rotate(&plane_state->base.src,
3083 fb->width << 16, fb->height << 16,
3084 DRM_MODE_ROTATE_270);
3087 * Handle the AUX surface first since
3088 * the main surface setup depends on it.
3090 if (fb->format->format == DRM_FORMAT_NV12) {
3091 ret = skl_check_nv12_aux_surface(plane_state);
3094 } else if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
3095 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
3096 ret = skl_check_ccs_aux_surface(plane_state);
3100 plane_state->aux.offset = ~0xfff;
3101 plane_state->aux.x = 0;
3102 plane_state->aux.y = 0;
3105 ret = skl_check_main_surface(plane_state);
3112 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3113 const struct intel_plane_state *plane_state)
3115 struct drm_i915_private *dev_priv =
3116 to_i915(plane_state->base.plane->dev);
3117 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3118 const struct drm_framebuffer *fb = plane_state->base.fb;
3119 unsigned int rotation = plane_state->base.rotation;
3122 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
3124 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3125 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
3126 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3128 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3129 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3131 if (INTEL_GEN(dev_priv) < 4)
3132 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3134 switch (fb->format->format) {
3136 dspcntr |= DISPPLANE_8BPP;
3138 case DRM_FORMAT_XRGB1555:
3139 dspcntr |= DISPPLANE_BGRX555;
3141 case DRM_FORMAT_RGB565:
3142 dspcntr |= DISPPLANE_BGRX565;
3144 case DRM_FORMAT_XRGB8888:
3145 dspcntr |= DISPPLANE_BGRX888;
3147 case DRM_FORMAT_XBGR8888:
3148 dspcntr |= DISPPLANE_RGBX888;
3150 case DRM_FORMAT_XRGB2101010:
3151 dspcntr |= DISPPLANE_BGRX101010;
3153 case DRM_FORMAT_XBGR2101010:
3154 dspcntr |= DISPPLANE_RGBX101010;
3157 MISSING_CASE(fb->format->format);
3161 if (INTEL_GEN(dev_priv) >= 4 &&
3162 fb->modifier == I915_FORMAT_MOD_X_TILED)
3163 dspcntr |= DISPPLANE_TILED;
3165 if (rotation & DRM_MODE_ROTATE_180)
3166 dspcntr |= DISPPLANE_ROTATE_180;
3168 if (rotation & DRM_MODE_REFLECT_X)
3169 dspcntr |= DISPPLANE_MIRROR;
3174 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3176 struct drm_i915_private *dev_priv =
3177 to_i915(plane_state->base.plane->dev);
3178 int src_x = plane_state->base.src.x1 >> 16;
3179 int src_y = plane_state->base.src.y1 >> 16;
3182 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3184 if (INTEL_GEN(dev_priv) >= 4)
3185 offset = intel_compute_tile_offset(&src_x, &src_y,
3190 /* HSW/BDW do this automagically in hardware */
3191 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3192 unsigned int rotation = plane_state->base.rotation;
3193 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3194 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3196 if (rotation & DRM_MODE_ROTATE_180) {
3199 } else if (rotation & DRM_MODE_REFLECT_X) {
3204 plane_state->main.offset = offset;
3205 plane_state->main.x = src_x;
3206 plane_state->main.y = src_y;
3211 static void i9xx_update_plane(struct intel_plane *plane,
3212 const struct intel_crtc_state *crtc_state,
3213 const struct intel_plane_state *plane_state)
3215 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3216 const struct drm_framebuffer *fb = plane_state->base.fb;
3217 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3219 u32 dspcntr = plane_state->ctl;
3220 i915_reg_t reg = DSPCNTR(i9xx_plane);
3221 int x = plane_state->main.x;
3222 int y = plane_state->main.y;
3223 unsigned long irqflags;
3226 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3228 if (INTEL_GEN(dev_priv) >= 4)
3229 dspaddr_offset = plane_state->main.offset;
3231 dspaddr_offset = linear_offset;
3233 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3235 if (INTEL_GEN(dev_priv) < 4) {
3236 /* pipesrc and dspsize control the size that is scaled from,
3237 * which should always be the user's requested size.
3239 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3240 ((crtc_state->pipe_src_h - 1) << 16) |
3241 (crtc_state->pipe_src_w - 1));
3242 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3243 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3244 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3245 ((crtc_state->pipe_src_h - 1) << 16) |
3246 (crtc_state->pipe_src_w - 1));
3247 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3248 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3251 I915_WRITE_FW(reg, dspcntr);
3253 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), fb->pitches[0]);
3254 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3255 I915_WRITE_FW(DSPSURF(i9xx_plane),
3256 intel_plane_ggtt_offset(plane_state) +
3258 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3259 } else if (INTEL_GEN(dev_priv) >= 4) {
3260 I915_WRITE_FW(DSPSURF(i9xx_plane),
3261 intel_plane_ggtt_offset(plane_state) +
3263 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3264 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3266 I915_WRITE_FW(DSPADDR(i9xx_plane),
3267 intel_plane_ggtt_offset(plane_state) +
3270 POSTING_READ_FW(reg);
3272 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3275 static void i9xx_disable_plane(struct intel_plane *plane,
3276 struct intel_crtc *crtc)
3278 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3279 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3280 unsigned long irqflags;
3282 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3284 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3285 if (INTEL_GEN(dev_priv) >= 4)
3286 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3288 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3289 POSTING_READ_FW(DSPCNTR(i9xx_plane));
3291 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3294 static bool i9xx_plane_get_hw_state(struct intel_plane *plane)
3296 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3297 enum intel_display_power_domain power_domain;
3298 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3299 enum pipe pipe = plane->pipe;
3303 * Not 100% correct for planes that can move between pipes,
3304 * but that's only the case for gen2-4 which don't have any
3305 * display power wells.
3307 power_domain = POWER_DOMAIN_PIPE(pipe);
3308 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3311 ret = I915_READ(DSPCNTR(i9xx_plane)) & DISPLAY_PLANE_ENABLE;
3313 intel_display_power_put(dev_priv, power_domain);
3319 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int plane)
3321 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3324 return intel_tile_width_bytes(fb, plane);
3327 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3329 struct drm_device *dev = intel_crtc->base.dev;
3330 struct drm_i915_private *dev_priv = to_i915(dev);
3332 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3333 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3334 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3338 * This function detaches (aka. unbinds) unused scalers in hardware
3340 static void skl_detach_scalers(struct intel_crtc *intel_crtc)
3342 struct intel_crtc_scaler_state *scaler_state;
3345 scaler_state = &intel_crtc->config->scaler_state;
3347 /* loop through and disable scalers that aren't in use */
3348 for (i = 0; i < intel_crtc->num_scalers; i++) {
3349 if (!scaler_state->scalers[i].in_use)
3350 skl_detach_scaler(intel_crtc, i);
3354 u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
3355 unsigned int rotation)
3359 if (plane >= fb->format->num_planes)
3362 stride = intel_fb_pitch(fb, plane, rotation);
3365 * The stride is either expressed as a multiple of 64 bytes chunks for
3366 * linear buffers or in number of tiles for tiled buffers.
3368 if (drm_rotation_90_or_270(rotation))
3369 stride /= intel_tile_height(fb, plane);
3371 stride /= intel_fb_stride_alignment(fb, plane);
3376 static u32 skl_plane_ctl_format(uint32_t pixel_format)
3378 switch (pixel_format) {
3380 return PLANE_CTL_FORMAT_INDEXED;
3381 case DRM_FORMAT_RGB565:
3382 return PLANE_CTL_FORMAT_RGB_565;
3383 case DRM_FORMAT_XBGR8888:
3384 case DRM_FORMAT_ABGR8888:
3385 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3386 case DRM_FORMAT_XRGB8888:
3387 case DRM_FORMAT_ARGB8888:
3388 return PLANE_CTL_FORMAT_XRGB_8888;
3389 case DRM_FORMAT_XRGB2101010:
3390 return PLANE_CTL_FORMAT_XRGB_2101010;
3391 case DRM_FORMAT_XBGR2101010:
3392 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3393 case DRM_FORMAT_YUYV:
3394 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3395 case DRM_FORMAT_YVYU:
3396 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3397 case DRM_FORMAT_UYVY:
3398 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3399 case DRM_FORMAT_VYUY:
3400 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3402 MISSING_CASE(pixel_format);
3409 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3410 * to be already pre-multiplied. We need to add a knob (or a different
3411 * DRM_FORMAT) for user-space to configure that.
3413 static u32 skl_plane_ctl_alpha(uint32_t pixel_format)
3415 switch (pixel_format) {
3416 case DRM_FORMAT_ABGR8888:
3417 case DRM_FORMAT_ARGB8888:
3418 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3420 return PLANE_CTL_ALPHA_DISABLE;
3424 static u32 glk_plane_color_ctl_alpha(uint32_t pixel_format)
3426 switch (pixel_format) {
3427 case DRM_FORMAT_ABGR8888:
3428 case DRM_FORMAT_ARGB8888:
3429 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3431 return PLANE_COLOR_ALPHA_DISABLE;
3435 static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
3437 switch (fb_modifier) {
3438 case DRM_FORMAT_MOD_LINEAR:
3440 case I915_FORMAT_MOD_X_TILED:
3441 return PLANE_CTL_TILED_X;
3442 case I915_FORMAT_MOD_Y_TILED:
3443 return PLANE_CTL_TILED_Y;
3444 case I915_FORMAT_MOD_Y_TILED_CCS:
3445 return PLANE_CTL_TILED_Y | PLANE_CTL_DECOMPRESSION_ENABLE;
3446 case I915_FORMAT_MOD_Yf_TILED:
3447 return PLANE_CTL_TILED_YF;
3448 case I915_FORMAT_MOD_Yf_TILED_CCS:
3449 return PLANE_CTL_TILED_YF | PLANE_CTL_DECOMPRESSION_ENABLE;
3451 MISSING_CASE(fb_modifier);
3457 static u32 skl_plane_ctl_rotation(unsigned int rotation)
3460 case DRM_MODE_ROTATE_0:
3463 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3464 * while i915 HW rotation is clockwise, thats why this swapping.
3466 case DRM_MODE_ROTATE_90:
3467 return PLANE_CTL_ROTATE_270;
3468 case DRM_MODE_ROTATE_180:
3469 return PLANE_CTL_ROTATE_180;
3470 case DRM_MODE_ROTATE_270:
3471 return PLANE_CTL_ROTATE_90;
3473 MISSING_CASE(rotation);
3479 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3480 const struct intel_plane_state *plane_state)
3482 struct drm_i915_private *dev_priv =
3483 to_i915(plane_state->base.plane->dev);
3484 const struct drm_framebuffer *fb = plane_state->base.fb;
3485 unsigned int rotation = plane_state->base.rotation;
3486 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3489 plane_ctl = PLANE_CTL_ENABLE;
3491 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3492 plane_ctl |= skl_plane_ctl_alpha(fb->format->format);
3494 PLANE_CTL_PIPE_GAMMA_ENABLE |
3495 PLANE_CTL_PIPE_CSC_ENABLE |
3496 PLANE_CTL_PLANE_GAMMA_DISABLE;
3499 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3500 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3501 plane_ctl |= skl_plane_ctl_rotation(rotation);
3503 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3504 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3505 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3506 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3511 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3512 const struct intel_plane_state *plane_state)
3514 const struct drm_framebuffer *fb = plane_state->base.fb;
3515 u32 plane_color_ctl = 0;
3517 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3518 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3519 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3520 plane_color_ctl |= glk_plane_color_ctl_alpha(fb->format->format);
3522 return plane_color_ctl;
3526 __intel_display_resume(struct drm_device *dev,
3527 struct drm_atomic_state *state,
3528 struct drm_modeset_acquire_ctx *ctx)
3530 struct drm_crtc_state *crtc_state;
3531 struct drm_crtc *crtc;
3534 intel_modeset_setup_hw_state(dev, ctx);
3535 i915_redisable_vga(to_i915(dev));
3541 * We've duplicated the state, pointers to the old state are invalid.
3543 * Don't attempt to use the old state until we commit the duplicated state.
3545 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3547 * Force recalculation even if we restore
3548 * current state. With fast modeset this may not result
3549 * in a modeset when the state is compatible.
3551 crtc_state->mode_changed = true;
3554 /* ignore any reset values/BIOS leftovers in the WM registers */
3555 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3556 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3558 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3560 WARN_ON(ret == -EDEADLK);
3564 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3566 return intel_has_gpu_reset(dev_priv) &&
3567 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
3570 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3572 struct drm_device *dev = &dev_priv->drm;
3573 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3574 struct drm_atomic_state *state;
3578 /* reset doesn't touch the display */
3579 if (!i915_modparams.force_reset_modeset_test &&
3580 !gpu_reset_clobbers_display(dev_priv))
3583 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3584 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3585 wake_up_all(&dev_priv->gpu_error.wait_queue);
3587 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3588 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3589 i915_gem_set_wedged(dev_priv);
3593 * Need mode_config.mutex so that we don't
3594 * trample ongoing ->detect() and whatnot.
3596 mutex_lock(&dev->mode_config.mutex);
3597 drm_modeset_acquire_init(ctx, 0);
3599 ret = drm_modeset_lock_all_ctx(dev, ctx);
3600 if (ret != -EDEADLK)
3603 drm_modeset_backoff(ctx);
3606 * Disabling the crtcs gracefully seems nicer. Also the
3607 * g33 docs say we should at least disable all the planes.
3609 state = drm_atomic_helper_duplicate_state(dev, ctx);
3610 if (IS_ERR(state)) {
3611 ret = PTR_ERR(state);
3612 DRM_ERROR("Duplicating state failed with %i\n", ret);
3616 ret = drm_atomic_helper_disable_all(dev, ctx);
3618 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3619 drm_atomic_state_put(state);
3623 dev_priv->modeset_restore_state = state;
3624 state->acquire_ctx = ctx;
3627 void intel_finish_reset(struct drm_i915_private *dev_priv)
3629 struct drm_device *dev = &dev_priv->drm;
3630 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3631 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
3634 /* reset doesn't touch the display */
3635 if (!i915_modparams.force_reset_modeset_test &&
3636 !gpu_reset_clobbers_display(dev_priv))
3642 dev_priv->modeset_restore_state = NULL;
3644 /* reset doesn't touch the display */
3645 if (!gpu_reset_clobbers_display(dev_priv)) {
3646 /* for testing only restore the display */
3647 ret = __intel_display_resume(dev, state, ctx);
3649 DRM_ERROR("Restoring old state failed with %i\n", ret);
3652 * The display has been reset as well,
3653 * so need a full re-initialization.
3655 intel_runtime_pm_disable_interrupts(dev_priv);
3656 intel_runtime_pm_enable_interrupts(dev_priv);
3658 intel_pps_unlock_regs_wa(dev_priv);
3659 intel_modeset_init_hw(dev);
3660 intel_init_clock_gating(dev_priv);
3662 spin_lock_irq(&dev_priv->irq_lock);
3663 if (dev_priv->display.hpd_irq_setup)
3664 dev_priv->display.hpd_irq_setup(dev_priv);
3665 spin_unlock_irq(&dev_priv->irq_lock);
3667 ret = __intel_display_resume(dev, state, ctx);
3669 DRM_ERROR("Restoring old state failed with %i\n", ret);
3671 intel_hpd_init(dev_priv);
3674 drm_atomic_state_put(state);
3676 drm_modeset_drop_locks(ctx);
3677 drm_modeset_acquire_fini(ctx);
3678 mutex_unlock(&dev->mode_config.mutex);
3680 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3683 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3684 const struct intel_crtc_state *new_crtc_state)
3686 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
3687 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3689 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3690 crtc->base.mode = new_crtc_state->base.mode;
3693 * Update pipe size and adjust fitter if needed: the reason for this is
3694 * that in compute_mode_changes we check the native mode (not the pfit
3695 * mode) to see if we can flip rather than do a full mode set. In the
3696 * fastboot case, we'll flip, but if we don't update the pipesrc and
3697 * pfit state, we'll end up with a big fb scanned out into the wrong
3701 I915_WRITE(PIPESRC(crtc->pipe),
3702 ((new_crtc_state->pipe_src_w - 1) << 16) |
3703 (new_crtc_state->pipe_src_h - 1));
3705 /* on skylake this is done by detaching scalers */
3706 if (INTEL_GEN(dev_priv) >= 9) {
3707 skl_detach_scalers(crtc);
3709 if (new_crtc_state->pch_pfit.enabled)
3710 skylake_pfit_enable(crtc);
3711 } else if (HAS_PCH_SPLIT(dev_priv)) {
3712 if (new_crtc_state->pch_pfit.enabled)
3713 ironlake_pfit_enable(crtc);
3714 else if (old_crtc_state->pch_pfit.enabled)
3715 ironlake_pfit_disable(crtc, true);
3719 static void intel_fdi_normal_train(struct intel_crtc *crtc)
3721 struct drm_device *dev = crtc->base.dev;
3722 struct drm_i915_private *dev_priv = to_i915(dev);
3723 int pipe = crtc->pipe;
3727 /* enable normal train */
3728 reg = FDI_TX_CTL(pipe);
3729 temp = I915_READ(reg);
3730 if (IS_IVYBRIDGE(dev_priv)) {
3731 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3732 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3734 temp &= ~FDI_LINK_TRAIN_NONE;
3735 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3737 I915_WRITE(reg, temp);
3739 reg = FDI_RX_CTL(pipe);
3740 temp = I915_READ(reg);
3741 if (HAS_PCH_CPT(dev_priv)) {
3742 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3743 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3745 temp &= ~FDI_LINK_TRAIN_NONE;
3746 temp |= FDI_LINK_TRAIN_NONE;
3748 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3750 /* wait one idle pattern time */
3754 /* IVB wants error correction enabled */
3755 if (IS_IVYBRIDGE(dev_priv))
3756 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3757 FDI_FE_ERRC_ENABLE);
3760 /* The FDI link training functions for ILK/Ibexpeak. */
3761 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3762 const struct intel_crtc_state *crtc_state)
3764 struct drm_device *dev = crtc->base.dev;
3765 struct drm_i915_private *dev_priv = to_i915(dev);
3766 int pipe = crtc->pipe;
3770 /* FDI needs bits from pipe first */
3771 assert_pipe_enabled(dev_priv, pipe);
3773 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3775 reg = FDI_RX_IMR(pipe);
3776 temp = I915_READ(reg);
3777 temp &= ~FDI_RX_SYMBOL_LOCK;
3778 temp &= ~FDI_RX_BIT_LOCK;
3779 I915_WRITE(reg, temp);
3783 /* enable CPU FDI TX and PCH FDI RX */
3784 reg = FDI_TX_CTL(pipe);
3785 temp = I915_READ(reg);
3786 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3787 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3788 temp &= ~FDI_LINK_TRAIN_NONE;
3789 temp |= FDI_LINK_TRAIN_PATTERN_1;
3790 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3792 reg = FDI_RX_CTL(pipe);
3793 temp = I915_READ(reg);
3794 temp &= ~FDI_LINK_TRAIN_NONE;
3795 temp |= FDI_LINK_TRAIN_PATTERN_1;
3796 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3801 /* Ironlake workaround, enable clock pointer after FDI enable*/
3802 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3803 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3804 FDI_RX_PHASE_SYNC_POINTER_EN);
3806 reg = FDI_RX_IIR(pipe);
3807 for (tries = 0; tries < 5; tries++) {
3808 temp = I915_READ(reg);
3809 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3811 if ((temp & FDI_RX_BIT_LOCK)) {
3812 DRM_DEBUG_KMS("FDI train 1 done.\n");
3813 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3818 DRM_ERROR("FDI train 1 fail!\n");
3821 reg = FDI_TX_CTL(pipe);
3822 temp = I915_READ(reg);
3823 temp &= ~FDI_LINK_TRAIN_NONE;
3824 temp |= FDI_LINK_TRAIN_PATTERN_2;
3825 I915_WRITE(reg, temp);
3827 reg = FDI_RX_CTL(pipe);
3828 temp = I915_READ(reg);
3829 temp &= ~FDI_LINK_TRAIN_NONE;
3830 temp |= FDI_LINK_TRAIN_PATTERN_2;
3831 I915_WRITE(reg, temp);
3836 reg = FDI_RX_IIR(pipe);
3837 for (tries = 0; tries < 5; tries++) {
3838 temp = I915_READ(reg);
3839 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3841 if (temp & FDI_RX_SYMBOL_LOCK) {
3842 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3843 DRM_DEBUG_KMS("FDI train 2 done.\n");
3848 DRM_ERROR("FDI train 2 fail!\n");
3850 DRM_DEBUG_KMS("FDI train done\n");
3854 static const int snb_b_fdi_train_param[] = {
3855 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
3856 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
3857 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
3858 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
3861 /* The FDI link training functions for SNB/Cougarpoint. */
3862 static void gen6_fdi_link_train(struct intel_crtc *crtc,
3863 const struct intel_crtc_state *crtc_state)
3865 struct drm_device *dev = crtc->base.dev;
3866 struct drm_i915_private *dev_priv = to_i915(dev);
3867 int pipe = crtc->pipe;
3871 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3873 reg = FDI_RX_IMR(pipe);
3874 temp = I915_READ(reg);
3875 temp &= ~FDI_RX_SYMBOL_LOCK;
3876 temp &= ~FDI_RX_BIT_LOCK;
3877 I915_WRITE(reg, temp);
3882 /* enable CPU FDI TX and PCH FDI RX */
3883 reg = FDI_TX_CTL(pipe);
3884 temp = I915_READ(reg);
3885 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3886 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3887 temp &= ~FDI_LINK_TRAIN_NONE;
3888 temp |= FDI_LINK_TRAIN_PATTERN_1;
3889 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3891 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
3892 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3894 I915_WRITE(FDI_RX_MISC(pipe),
3895 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
3897 reg = FDI_RX_CTL(pipe);
3898 temp = I915_READ(reg);
3899 if (HAS_PCH_CPT(dev_priv)) {
3900 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3901 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
3903 temp &= ~FDI_LINK_TRAIN_NONE;
3904 temp |= FDI_LINK_TRAIN_PATTERN_1;
3906 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3911 for (i = 0; i < 4; i++) {
3912 reg = FDI_TX_CTL(pipe);
3913 temp = I915_READ(reg);
3914 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3915 temp |= snb_b_fdi_train_param[i];
3916 I915_WRITE(reg, temp);
3921 for (retry = 0; retry < 5; retry++) {
3922 reg = FDI_RX_IIR(pipe);
3923 temp = I915_READ(reg);
3924 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3925 if (temp & FDI_RX_BIT_LOCK) {
3926 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3927 DRM_DEBUG_KMS("FDI train 1 done.\n");
3936 DRM_ERROR("FDI train 1 fail!\n");
3939 reg = FDI_TX_CTL(pipe);
3940 temp = I915_READ(reg);
3941 temp &= ~FDI_LINK_TRAIN_NONE;
3942 temp |= FDI_LINK_TRAIN_PATTERN_2;
3943 if (IS_GEN6(dev_priv)) {
3944 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3946 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
3948 I915_WRITE(reg, temp);
3950 reg = FDI_RX_CTL(pipe);
3951 temp = I915_READ(reg);
3952 if (HAS_PCH_CPT(dev_priv)) {
3953 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3954 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
3956 temp &= ~FDI_LINK_TRAIN_NONE;
3957 temp |= FDI_LINK_TRAIN_PATTERN_2;
3959 I915_WRITE(reg, temp);
3964 for (i = 0; i < 4; i++) {
3965 reg = FDI_TX_CTL(pipe);
3966 temp = I915_READ(reg);
3967 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
3968 temp |= snb_b_fdi_train_param[i];
3969 I915_WRITE(reg, temp);
3974 for (retry = 0; retry < 5; retry++) {
3975 reg = FDI_RX_IIR(pipe);
3976 temp = I915_READ(reg);
3977 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3978 if (temp & FDI_RX_SYMBOL_LOCK) {
3979 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3980 DRM_DEBUG_KMS("FDI train 2 done.\n");
3989 DRM_ERROR("FDI train 2 fail!\n");
3991 DRM_DEBUG_KMS("FDI train done.\n");
3994 /* Manual link training for Ivy Bridge A0 parts */
3995 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
3996 const struct intel_crtc_state *crtc_state)
3998 struct drm_device *dev = crtc->base.dev;
3999 struct drm_i915_private *dev_priv = to_i915(dev);
4000 int pipe = crtc->pipe;
4004 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4006 reg = FDI_RX_IMR(pipe);
4007 temp = I915_READ(reg);
4008 temp &= ~FDI_RX_SYMBOL_LOCK;
4009 temp &= ~FDI_RX_BIT_LOCK;
4010 I915_WRITE(reg, temp);
4015 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4016 I915_READ(FDI_RX_IIR(pipe)));
4018 /* Try each vswing and preemphasis setting twice before moving on */
4019 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4020 /* disable first in case we need to retry */
4021 reg = FDI_TX_CTL(pipe);
4022 temp = I915_READ(reg);
4023 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4024 temp &= ~FDI_TX_ENABLE;
4025 I915_WRITE(reg, temp);
4027 reg = FDI_RX_CTL(pipe);
4028 temp = I915_READ(reg);
4029 temp &= ~FDI_LINK_TRAIN_AUTO;
4030 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4031 temp &= ~FDI_RX_ENABLE;
4032 I915_WRITE(reg, temp);
4034 /* enable CPU FDI TX and PCH FDI RX */
4035 reg = FDI_TX_CTL(pipe);
4036 temp = I915_READ(reg);
4037 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4038 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4039 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4040 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4041 temp |= snb_b_fdi_train_param[j/2];
4042 temp |= FDI_COMPOSITE_SYNC;
4043 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4045 I915_WRITE(FDI_RX_MISC(pipe),
4046 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4048 reg = FDI_RX_CTL(pipe);
4049 temp = I915_READ(reg);
4050 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4051 temp |= FDI_COMPOSITE_SYNC;
4052 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4055 udelay(1); /* should be 0.5us */
4057 for (i = 0; i < 4; i++) {
4058 reg = FDI_RX_IIR(pipe);
4059 temp = I915_READ(reg);
4060 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4062 if (temp & FDI_RX_BIT_LOCK ||
4063 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4064 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4065 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4069 udelay(1); /* should be 0.5us */
4072 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4077 reg = FDI_TX_CTL(pipe);
4078 temp = I915_READ(reg);
4079 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4080 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4081 I915_WRITE(reg, temp);
4083 reg = FDI_RX_CTL(pipe);
4084 temp = I915_READ(reg);
4085 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4086 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4087 I915_WRITE(reg, temp);
4090 udelay(2); /* should be 1.5us */
4092 for (i = 0; i < 4; i++) {
4093 reg = FDI_RX_IIR(pipe);
4094 temp = I915_READ(reg);
4095 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4097 if (temp & FDI_RX_SYMBOL_LOCK ||
4098 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4099 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4100 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4104 udelay(2); /* should be 1.5us */
4107 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4111 DRM_DEBUG_KMS("FDI train done.\n");
4114 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
4116 struct drm_device *dev = intel_crtc->base.dev;
4117 struct drm_i915_private *dev_priv = to_i915(dev);
4118 int pipe = intel_crtc->pipe;
4122 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4123 reg = FDI_RX_CTL(pipe);
4124 temp = I915_READ(reg);
4125 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4126 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
4127 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4128 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4133 /* Switch from Rawclk to PCDclk */
4134 temp = I915_READ(reg);
4135 I915_WRITE(reg, temp | FDI_PCDCLK);
4140 /* Enable CPU FDI TX PLL, always on for Ironlake */
4141 reg = FDI_TX_CTL(pipe);
4142 temp = I915_READ(reg);
4143 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4144 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4151 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4153 struct drm_device *dev = intel_crtc->base.dev;
4154 struct drm_i915_private *dev_priv = to_i915(dev);
4155 int pipe = intel_crtc->pipe;
4159 /* Switch from PCDclk to Rawclk */
4160 reg = FDI_RX_CTL(pipe);
4161 temp = I915_READ(reg);
4162 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4164 /* Disable CPU FDI TX PLL */
4165 reg = FDI_TX_CTL(pipe);
4166 temp = I915_READ(reg);
4167 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4172 reg = FDI_RX_CTL(pipe);
4173 temp = I915_READ(reg);
4174 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4176 /* Wait for the clocks to turn off. */
4181 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4183 struct drm_device *dev = crtc->dev;
4184 struct drm_i915_private *dev_priv = to_i915(dev);
4185 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4186 int pipe = intel_crtc->pipe;
4190 /* disable CPU FDI tx and PCH FDI rx */
4191 reg = FDI_TX_CTL(pipe);
4192 temp = I915_READ(reg);
4193 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4196 reg = FDI_RX_CTL(pipe);
4197 temp = I915_READ(reg);
4198 temp &= ~(0x7 << 16);
4199 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4200 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4205 /* Ironlake workaround, disable clock pointer after downing FDI */
4206 if (HAS_PCH_IBX(dev_priv))
4207 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4209 /* still set train pattern 1 */
4210 reg = FDI_TX_CTL(pipe);
4211 temp = I915_READ(reg);
4212 temp &= ~FDI_LINK_TRAIN_NONE;
4213 temp |= FDI_LINK_TRAIN_PATTERN_1;
4214 I915_WRITE(reg, temp);
4216 reg = FDI_RX_CTL(pipe);
4217 temp = I915_READ(reg);
4218 if (HAS_PCH_CPT(dev_priv)) {
4219 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4220 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4222 temp &= ~FDI_LINK_TRAIN_NONE;
4223 temp |= FDI_LINK_TRAIN_PATTERN_1;
4225 /* BPC in FDI rx is consistent with that in PIPECONF */
4226 temp &= ~(0x07 << 16);
4227 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4228 I915_WRITE(reg, temp);
4234 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4236 struct drm_crtc *crtc;
4239 drm_for_each_crtc(crtc, &dev_priv->drm) {
4240 struct drm_crtc_commit *commit;
4241 spin_lock(&crtc->commit_lock);
4242 commit = list_first_entry_or_null(&crtc->commit_list,
4243 struct drm_crtc_commit, commit_entry);
4244 cleanup_done = commit ?
4245 try_wait_for_completion(&commit->cleanup_done) : true;
4246 spin_unlock(&crtc->commit_lock);
4251 drm_crtc_wait_one_vblank(crtc);
4259 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4263 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4265 mutex_lock(&dev_priv->sb_lock);
4267 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4268 temp |= SBI_SSCCTL_DISABLE;
4269 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4271 mutex_unlock(&dev_priv->sb_lock);
4274 /* Program iCLKIP clock to the desired frequency */
4275 static void lpt_program_iclkip(struct intel_crtc *crtc)
4277 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4278 int clock = crtc->config->base.adjusted_mode.crtc_clock;
4279 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4282 lpt_disable_iclkip(dev_priv);
4284 /* The iCLK virtual clock root frequency is in MHz,
4285 * but the adjusted_mode->crtc_clock in in KHz. To get the
4286 * divisors, it is necessary to divide one by another, so we
4287 * convert the virtual clock precision to KHz here for higher
4290 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4291 u32 iclk_virtual_root_freq = 172800 * 1000;
4292 u32 iclk_pi_range = 64;
4293 u32 desired_divisor;
4295 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4297 divsel = (desired_divisor / iclk_pi_range) - 2;
4298 phaseinc = desired_divisor % iclk_pi_range;
4301 * Near 20MHz is a corner case which is
4302 * out of range for the 7-bit divisor
4308 /* This should not happen with any sane values */
4309 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4310 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4311 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4312 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4314 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4321 mutex_lock(&dev_priv->sb_lock);
4323 /* Program SSCDIVINTPHASE6 */
4324 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4325 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4326 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4327 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4328 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4329 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4330 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4331 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4333 /* Program SSCAUXDIV */
4334 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4335 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4336 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4337 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4339 /* Enable modulator and associated divider */
4340 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4341 temp &= ~SBI_SSCCTL_DISABLE;
4342 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4344 mutex_unlock(&dev_priv->sb_lock);
4346 /* Wait for initialization time */
4349 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4352 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4354 u32 divsel, phaseinc, auxdiv;
4355 u32 iclk_virtual_root_freq = 172800 * 1000;
4356 u32 iclk_pi_range = 64;
4357 u32 desired_divisor;
4360 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4363 mutex_lock(&dev_priv->sb_lock);
4365 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4366 if (temp & SBI_SSCCTL_DISABLE) {
4367 mutex_unlock(&dev_priv->sb_lock);
4371 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4372 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4373 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4374 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4375 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4377 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4378 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4379 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4381 mutex_unlock(&dev_priv->sb_lock);
4383 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4385 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4386 desired_divisor << auxdiv);
4389 static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
4390 enum pipe pch_transcoder)
4392 struct drm_device *dev = crtc->base.dev;
4393 struct drm_i915_private *dev_priv = to_i915(dev);
4394 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
4396 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4397 I915_READ(HTOTAL(cpu_transcoder)));
4398 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4399 I915_READ(HBLANK(cpu_transcoder)));
4400 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4401 I915_READ(HSYNC(cpu_transcoder)));
4403 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4404 I915_READ(VTOTAL(cpu_transcoder)));
4405 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4406 I915_READ(VBLANK(cpu_transcoder)));
4407 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4408 I915_READ(VSYNC(cpu_transcoder)));
4409 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4410 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4413 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4415 struct drm_i915_private *dev_priv = to_i915(dev);
4418 temp = I915_READ(SOUTH_CHICKEN1);
4419 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4422 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4423 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4425 temp &= ~FDI_BC_BIFURCATION_SELECT;
4427 temp |= FDI_BC_BIFURCATION_SELECT;
4429 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4430 I915_WRITE(SOUTH_CHICKEN1, temp);
4431 POSTING_READ(SOUTH_CHICKEN1);
4434 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4436 struct drm_device *dev = intel_crtc->base.dev;
4438 switch (intel_crtc->pipe) {
4442 if (intel_crtc->config->fdi_lanes > 2)
4443 cpt_set_fdi_bc_bifurcation(dev, false);
4445 cpt_set_fdi_bc_bifurcation(dev, true);
4449 cpt_set_fdi_bc_bifurcation(dev, true);
4457 /* Return which DP Port should be selected for Transcoder DP control */
4459 intel_trans_dp_port_sel(struct intel_crtc *crtc)
4461 struct drm_device *dev = crtc->base.dev;
4462 struct intel_encoder *encoder;
4464 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
4465 if (encoder->type == INTEL_OUTPUT_DP ||
4466 encoder->type == INTEL_OUTPUT_EDP)
4467 return encoder->port;
4474 * Enable PCH resources required for PCH ports:
4476 * - FDI training & RX/TX
4477 * - update transcoder timings
4478 * - DP transcoding bits
4481 static void ironlake_pch_enable(const struct intel_crtc_state *crtc_state)
4483 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4484 struct drm_device *dev = crtc->base.dev;
4485 struct drm_i915_private *dev_priv = to_i915(dev);
4486 int pipe = crtc->pipe;
4489 assert_pch_transcoder_disabled(dev_priv, pipe);
4491 if (IS_IVYBRIDGE(dev_priv))
4492 ivybridge_update_fdi_bc_bifurcation(crtc);
4494 /* Write the TU size bits before fdi link training, so that error
4495 * detection works. */
4496 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4497 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4499 /* For PCH output, training FDI link */
4500 dev_priv->display.fdi_link_train(crtc, crtc_state);
4502 /* We need to program the right clock selection before writing the pixel
4503 * mutliplier into the DPLL. */
4504 if (HAS_PCH_CPT(dev_priv)) {
4507 temp = I915_READ(PCH_DPLL_SEL);
4508 temp |= TRANS_DPLL_ENABLE(pipe);
4509 sel = TRANS_DPLLB_SEL(pipe);
4510 if (crtc_state->shared_dpll ==
4511 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4515 I915_WRITE(PCH_DPLL_SEL, temp);
4518 /* XXX: pch pll's can be enabled any time before we enable the PCH
4519 * transcoder, and we actually should do this to not upset any PCH
4520 * transcoder that already use the clock when we share it.
4522 * Note that enable_shared_dpll tries to do the right thing, but
4523 * get_shared_dpll unconditionally resets the pll - we need that to have
4524 * the right LVDS enable sequence. */
4525 intel_enable_shared_dpll(crtc);
4527 /* set transcoder timing, panel must allow it */
4528 assert_panel_unlocked(dev_priv, pipe);
4529 ironlake_pch_transcoder_set_timings(crtc, pipe);
4531 intel_fdi_normal_train(crtc);
4533 /* For PCH DP, enable TRANS_DP_CTL */
4534 if (HAS_PCH_CPT(dev_priv) &&
4535 intel_crtc_has_dp_encoder(crtc_state)) {
4536 const struct drm_display_mode *adjusted_mode =
4537 &crtc_state->base.adjusted_mode;
4538 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4539 i915_reg_t reg = TRANS_DP_CTL(pipe);
4540 temp = I915_READ(reg);
4541 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4542 TRANS_DP_SYNC_MASK |
4544 temp |= TRANS_DP_OUTPUT_ENABLE;
4545 temp |= bpc << 9; /* same format but at 11:9 */
4547 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4548 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4549 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4550 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4552 switch (intel_trans_dp_port_sel(crtc)) {
4554 temp |= TRANS_DP_PORT_SEL_B;
4557 temp |= TRANS_DP_PORT_SEL_C;
4560 temp |= TRANS_DP_PORT_SEL_D;
4566 I915_WRITE(reg, temp);
4569 ironlake_enable_pch_transcoder(dev_priv, pipe);
4572 static void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
4574 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4575 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4576 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4578 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4580 lpt_program_iclkip(crtc);
4582 /* Set transcoder timing. */
4583 ironlake_pch_transcoder_set_timings(crtc, PIPE_A);
4585 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4588 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4590 struct drm_i915_private *dev_priv = to_i915(dev);
4591 i915_reg_t dslreg = PIPEDSL(pipe);
4594 temp = I915_READ(dslreg);
4596 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4597 if (wait_for(I915_READ(dslreg) != temp, 5))
4598 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4603 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4604 unsigned int scaler_user, int *scaler_id,
4605 int src_w, int src_h, int dst_w, int dst_h)
4607 struct intel_crtc_scaler_state *scaler_state =
4608 &crtc_state->scaler_state;
4609 struct intel_crtc *intel_crtc =
4610 to_intel_crtc(crtc_state->base.crtc);
4611 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4612 const struct drm_display_mode *adjusted_mode =
4613 &crtc_state->base.adjusted_mode;
4617 * Src coordinates are already rotated by 270 degrees for
4618 * the 90/270 degree plane rotation cases (to match the
4619 * GTT mapping), hence no need to account for rotation here.
4621 need_scaling = src_w != dst_w || src_h != dst_h;
4623 if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX)
4624 need_scaling = true;
4627 * Scaling/fitting not supported in IF-ID mode in GEN9+
4628 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4629 * Once NV12 is enabled, handle it here while allocating scaler
4632 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4633 need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4634 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4639 * if plane is being disabled or scaler is no more required or force detach
4640 * - free scaler binded to this plane/crtc
4641 * - in order to do this, update crtc->scaler_usage
4643 * Here scaler state in crtc_state is set free so that
4644 * scaler can be assigned to other user. Actual register
4645 * update to free the scaler is done in plane/panel-fit programming.
4646 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4648 if (force_detach || !need_scaling) {
4649 if (*scaler_id >= 0) {
4650 scaler_state->scaler_users &= ~(1 << scaler_user);
4651 scaler_state->scalers[*scaler_id].in_use = 0;
4653 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4654 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4655 intel_crtc->pipe, scaler_user, *scaler_id,
4656 scaler_state->scaler_users);
4663 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4664 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4666 src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4667 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) {
4668 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4669 "size is out of scaler range\n",
4670 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4674 /* mark this plane as a scaler user in crtc_state */
4675 scaler_state->scaler_users |= (1 << scaler_user);
4676 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4677 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4678 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4679 scaler_state->scaler_users);
4685 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4687 * @state: crtc's scaler state
4690 * 0 - scaler_usage updated successfully
4691 * error - requested scaling cannot be supported or other error condition
4693 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4695 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
4697 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4698 &state->scaler_state.scaler_id,
4699 state->pipe_src_w, state->pipe_src_h,
4700 adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay);
4704 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4706 * @state: crtc's scaler state
4707 * @plane_state: atomic plane state to update
4710 * 0 - scaler_usage updated successfully
4711 * error - requested scaling cannot be supported or other error condition
4713 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4714 struct intel_plane_state *plane_state)
4717 struct intel_plane *intel_plane =
4718 to_intel_plane(plane_state->base.plane);
4719 struct drm_framebuffer *fb = plane_state->base.fb;
4722 bool force_detach = !fb || !plane_state->base.visible;
4724 ret = skl_update_scaler(crtc_state, force_detach,
4725 drm_plane_index(&intel_plane->base),
4726 &plane_state->scaler_id,
4727 drm_rect_width(&plane_state->base.src) >> 16,
4728 drm_rect_height(&plane_state->base.src) >> 16,
4729 drm_rect_width(&plane_state->base.dst),
4730 drm_rect_height(&plane_state->base.dst));
4732 if (ret || plane_state->scaler_id < 0)
4735 /* check colorkey */
4736 if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) {
4737 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4738 intel_plane->base.base.id,
4739 intel_plane->base.name);
4743 /* Check src format */
4744 switch (fb->format->format) {
4745 case DRM_FORMAT_RGB565:
4746 case DRM_FORMAT_XBGR8888:
4747 case DRM_FORMAT_XRGB8888:
4748 case DRM_FORMAT_ABGR8888:
4749 case DRM_FORMAT_ARGB8888:
4750 case DRM_FORMAT_XRGB2101010:
4751 case DRM_FORMAT_XBGR2101010:
4752 case DRM_FORMAT_YUYV:
4753 case DRM_FORMAT_YVYU:
4754 case DRM_FORMAT_UYVY:
4755 case DRM_FORMAT_VYUY:
4758 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4759 intel_plane->base.base.id, intel_plane->base.name,
4760 fb->base.id, fb->format->format);
4767 static void skylake_scaler_disable(struct intel_crtc *crtc)
4771 for (i = 0; i < crtc->num_scalers; i++)
4772 skl_detach_scaler(crtc, i);
4775 static void skylake_pfit_enable(struct intel_crtc *crtc)
4777 struct drm_device *dev = crtc->base.dev;
4778 struct drm_i915_private *dev_priv = to_i915(dev);
4779 int pipe = crtc->pipe;
4780 struct intel_crtc_scaler_state *scaler_state =
4781 &crtc->config->scaler_state;
4783 if (crtc->config->pch_pfit.enabled) {
4786 if (WARN_ON(crtc->config->scaler_state.scaler_id < 0))
4789 id = scaler_state->scaler_id;
4790 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
4791 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
4792 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
4793 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
4797 static void ironlake_pfit_enable(struct intel_crtc *crtc)
4799 struct drm_device *dev = crtc->base.dev;
4800 struct drm_i915_private *dev_priv = to_i915(dev);
4801 int pipe = crtc->pipe;
4803 if (crtc->config->pch_pfit.enabled) {
4804 /* Force use of hard-coded filter coefficients
4805 * as some pre-programmed values are broken,
4808 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
4809 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
4810 PF_PIPE_SEL_IVB(pipe));
4812 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
4813 I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
4814 I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
4818 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
4820 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4821 struct drm_device *dev = crtc->base.dev;
4822 struct drm_i915_private *dev_priv = to_i915(dev);
4824 if (!crtc_state->ips_enabled)
4828 * We can only enable IPS after we enable a plane and wait for a vblank
4829 * This function is called from post_plane_update, which is run after
4832 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
4834 if (IS_BROADWELL(dev_priv)) {
4835 mutex_lock(&dev_priv->pcu_lock);
4836 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
4837 IPS_ENABLE | IPS_PCODE_CONTROL));
4838 mutex_unlock(&dev_priv->pcu_lock);
4839 /* Quoting Art Runyan: "its not safe to expect any particular
4840 * value in IPS_CTL bit 31 after enabling IPS through the
4841 * mailbox." Moreover, the mailbox may return a bogus state,
4842 * so we need to just enable it and continue on.
4845 I915_WRITE(IPS_CTL, IPS_ENABLE);
4846 /* The bit only becomes 1 in the next vblank, so this wait here
4847 * is essentially intel_wait_for_vblank. If we don't have this
4848 * and don't wait for vblanks until the end of crtc_enable, then
4849 * the HW state readout code will complain that the expected
4850 * IPS_CTL value is not the one we read. */
4851 if (intel_wait_for_register(dev_priv,
4852 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
4854 DRM_ERROR("Timed out waiting for IPS enable\n");
4858 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
4860 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4861 struct drm_device *dev = crtc->base.dev;
4862 struct drm_i915_private *dev_priv = to_i915(dev);
4864 if (!crtc_state->ips_enabled)
4867 if (IS_BROADWELL(dev_priv)) {
4868 mutex_lock(&dev_priv->pcu_lock);
4869 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
4870 mutex_unlock(&dev_priv->pcu_lock);
4871 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
4872 if (intel_wait_for_register(dev_priv,
4873 IPS_CTL, IPS_ENABLE, 0,
4875 DRM_ERROR("Timed out waiting for IPS disable\n");
4877 I915_WRITE(IPS_CTL, 0);
4878 POSTING_READ(IPS_CTL);
4881 /* We need to wait for a vblank before we can disable the plane. */
4882 intel_wait_for_vblank(dev_priv, crtc->pipe);
4885 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
4887 if (intel_crtc->overlay) {
4888 struct drm_device *dev = intel_crtc->base.dev;
4890 mutex_lock(&dev->struct_mutex);
4891 (void) intel_overlay_switch_off(intel_crtc->overlay);
4892 mutex_unlock(&dev->struct_mutex);
4895 /* Let userspace switch the overlay on again. In most cases userspace
4896 * has to recompute where to put it anyway.
4901 * intel_post_enable_primary - Perform operations after enabling primary plane
4902 * @crtc: the CRTC whose primary plane was just enabled
4904 * Performs potentially sleeping operations that must be done after the primary
4905 * plane is enabled, such as updating FBC and IPS. Note that this may be
4906 * called due to an explicit primary plane update, or due to an implicit
4907 * re-enable that is caused when a sprite plane is updated to no longer
4908 * completely hide the primary plane.
4911 intel_post_enable_primary(struct drm_crtc *crtc,
4912 const struct intel_crtc_state *new_crtc_state)
4914 struct drm_device *dev = crtc->dev;
4915 struct drm_i915_private *dev_priv = to_i915(dev);
4916 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4917 int pipe = intel_crtc->pipe;
4920 * Gen2 reports pipe underruns whenever all planes are disabled.
4921 * So don't enable underrun reporting before at least some planes
4923 * FIXME: Need to fix the logic to work when we turn off all planes
4924 * but leave the pipe running.
4926 if (IS_GEN2(dev_priv))
4927 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
4929 /* Underruns don't always raise interrupts, so check manually. */
4930 intel_check_cpu_fifo_underruns(dev_priv);
4931 intel_check_pch_fifo_underruns(dev_priv);
4934 /* FIXME get rid of this and use pre_plane_update */
4936 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
4938 struct drm_device *dev = crtc->dev;
4939 struct drm_i915_private *dev_priv = to_i915(dev);
4940 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4941 int pipe = intel_crtc->pipe;
4944 * Gen2 reports pipe underruns whenever all planes are disabled.
4945 * So disable underrun reporting before all the planes get disabled.
4947 if (IS_GEN2(dev_priv))
4948 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
4950 hsw_disable_ips(to_intel_crtc_state(crtc->state));
4953 * Vblank time updates from the shadow to live plane control register
4954 * are blocked if the memory self-refresh mode is active at that
4955 * moment. So to make sure the plane gets truly disabled, disable
4956 * first the self-refresh mode. The self-refresh enable bit in turn
4957 * will be checked/applied by the HW only at the next frame start
4958 * event which is after the vblank start event, so we need to have a
4959 * wait-for-vblank between disabling the plane and the pipe.
4961 if (HAS_GMCH_DISPLAY(dev_priv) &&
4962 intel_set_memory_cxsr(dev_priv, false))
4963 intel_wait_for_vblank(dev_priv, pipe);
4966 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
4967 const struct intel_crtc_state *new_crtc_state)
4969 if (!old_crtc_state->ips_enabled)
4972 if (needs_modeset(&new_crtc_state->base))
4975 return !new_crtc_state->ips_enabled;
4978 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
4979 const struct intel_crtc_state *new_crtc_state)
4981 if (!new_crtc_state->ips_enabled)
4984 if (needs_modeset(&new_crtc_state->base))
4988 * We can't read out IPS on broadwell, assume the worst and
4989 * forcibly enable IPS on the first fastset.
4991 if (new_crtc_state->update_pipe &&
4992 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
4995 return !old_crtc_state->ips_enabled;
4998 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5000 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5001 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5002 struct intel_crtc_state *pipe_config =
5003 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5005 struct drm_plane *primary = crtc->base.primary;
5006 struct drm_plane_state *old_pri_state =
5007 drm_atomic_get_existing_plane_state(old_state, primary);
5009 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5011 if (pipe_config->update_wm_post && pipe_config->base.active)
5012 intel_update_watermarks(crtc);
5014 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5015 hsw_enable_ips(pipe_config);
5017 if (old_pri_state) {
5018 struct intel_plane_state *primary_state =
5019 intel_atomic_get_new_plane_state(to_intel_atomic_state(old_state),
5020 to_intel_plane(primary));
5021 struct intel_plane_state *old_primary_state =
5022 to_intel_plane_state(old_pri_state);
5024 intel_fbc_post_update(crtc);
5026 if (primary_state->base.visible &&
5027 (needs_modeset(&pipe_config->base) ||
5028 !old_primary_state->base.visible))
5029 intel_post_enable_primary(&crtc->base, pipe_config);
5033 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5034 struct intel_crtc_state *pipe_config)
5036 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5037 struct drm_device *dev = crtc->base.dev;
5038 struct drm_i915_private *dev_priv = to_i915(dev);
5039 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5040 struct drm_plane *primary = crtc->base.primary;
5041 struct drm_plane_state *old_pri_state =
5042 drm_atomic_get_existing_plane_state(old_state, primary);
5043 bool modeset = needs_modeset(&pipe_config->base);
5044 struct intel_atomic_state *old_intel_state =
5045 to_intel_atomic_state(old_state);
5047 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5048 hsw_disable_ips(old_crtc_state);
5050 if (old_pri_state) {
5051 struct intel_plane_state *primary_state =
5052 intel_atomic_get_new_plane_state(old_intel_state,
5053 to_intel_plane(primary));
5054 struct intel_plane_state *old_primary_state =
5055 to_intel_plane_state(old_pri_state);
5057 intel_fbc_pre_update(crtc, pipe_config, primary_state);
5059 * Gen2 reports pipe underruns whenever all planes are disabled.
5060 * So disable underrun reporting before all the planes get disabled.
5062 if (IS_GEN2(dev_priv) && old_primary_state->base.visible &&
5063 (modeset || !primary_state->base.visible))
5064 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5068 * Vblank time updates from the shadow to live plane control register
5069 * are blocked if the memory self-refresh mode is active at that
5070 * moment. So to make sure the plane gets truly disabled, disable
5071 * first the self-refresh mode. The self-refresh enable bit in turn
5072 * will be checked/applied by the HW only at the next frame start
5073 * event which is after the vblank start event, so we need to have a
5074 * wait-for-vblank between disabling the plane and the pipe.
5076 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5077 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5078 intel_wait_for_vblank(dev_priv, crtc->pipe);
5081 * IVB workaround: must disable low power watermarks for at least
5082 * one frame before enabling scaling. LP watermarks can be re-enabled
5083 * when scaling is disabled.
5085 * WaCxSRDisabledForSpriteScaling:ivb
5087 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev))
5088 intel_wait_for_vblank(dev_priv, crtc->pipe);
5091 * If we're doing a modeset, we're done. No need to do any pre-vblank
5092 * watermark programming here.
5094 if (needs_modeset(&pipe_config->base))
5098 * For platforms that support atomic watermarks, program the
5099 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5100 * will be the intermediate values that are safe for both pre- and
5101 * post- vblank; when vblank happens, the 'active' values will be set
5102 * to the final 'target' values and we'll do this again to get the
5103 * optimal watermarks. For gen9+ platforms, the values we program here
5104 * will be the final target values which will get automatically latched
5105 * at vblank time; no further programming will be necessary.
5107 * If a platform hasn't been transitioned to atomic watermarks yet,
5108 * we'll continue to update watermarks the old way, if flags tell
5111 if (dev_priv->display.initial_watermarks != NULL)
5112 dev_priv->display.initial_watermarks(old_intel_state,
5114 else if (pipe_config->update_wm_pre)
5115 intel_update_watermarks(crtc);
5118 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
5120 struct drm_device *dev = crtc->dev;
5121 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5122 struct drm_plane *p;
5123 int pipe = intel_crtc->pipe;
5125 intel_crtc_dpms_overlay_disable(intel_crtc);
5127 drm_for_each_plane_mask(p, dev, plane_mask)
5128 to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc);
5131 * FIXME: Once we grow proper nuclear flip support out of this we need
5132 * to compute the mask of flip planes precisely. For the time being
5133 * consider this a flip to a NULL plane.
5135 intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe));
5138 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5139 struct intel_crtc_state *crtc_state,
5140 struct drm_atomic_state *old_state)
5142 struct drm_connector_state *conn_state;
5143 struct drm_connector *conn;
5146 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5147 struct intel_encoder *encoder =
5148 to_intel_encoder(conn_state->best_encoder);
5150 if (conn_state->crtc != crtc)
5153 if (encoder->pre_pll_enable)
5154 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5158 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5159 struct intel_crtc_state *crtc_state,
5160 struct drm_atomic_state *old_state)
5162 struct drm_connector_state *conn_state;
5163 struct drm_connector *conn;
5166 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5167 struct intel_encoder *encoder =
5168 to_intel_encoder(conn_state->best_encoder);
5170 if (conn_state->crtc != crtc)
5173 if (encoder->pre_enable)
5174 encoder->pre_enable(encoder, crtc_state, conn_state);
5178 static void intel_encoders_enable(struct drm_crtc *crtc,
5179 struct intel_crtc_state *crtc_state,
5180 struct drm_atomic_state *old_state)
5182 struct drm_connector_state *conn_state;
5183 struct drm_connector *conn;
5186 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5187 struct intel_encoder *encoder =
5188 to_intel_encoder(conn_state->best_encoder);
5190 if (conn_state->crtc != crtc)
5193 encoder->enable(encoder, crtc_state, conn_state);
5194 intel_opregion_notify_encoder(encoder, true);
5198 static void intel_encoders_disable(struct drm_crtc *crtc,
5199 struct intel_crtc_state *old_crtc_state,
5200 struct drm_atomic_state *old_state)
5202 struct drm_connector_state *old_conn_state;
5203 struct drm_connector *conn;
5206 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5207 struct intel_encoder *encoder =
5208 to_intel_encoder(old_conn_state->best_encoder);
5210 if (old_conn_state->crtc != crtc)
5213 intel_opregion_notify_encoder(encoder, false);
5214 encoder->disable(encoder, old_crtc_state, old_conn_state);
5218 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5219 struct intel_crtc_state *old_crtc_state,
5220 struct drm_atomic_state *old_state)
5222 struct drm_connector_state *old_conn_state;
5223 struct drm_connector *conn;
5226 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5227 struct intel_encoder *encoder =
5228 to_intel_encoder(old_conn_state->best_encoder);
5230 if (old_conn_state->crtc != crtc)
5233 if (encoder->post_disable)
5234 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5238 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5239 struct intel_crtc_state *old_crtc_state,
5240 struct drm_atomic_state *old_state)
5242 struct drm_connector_state *old_conn_state;
5243 struct drm_connector *conn;
5246 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5247 struct intel_encoder *encoder =
5248 to_intel_encoder(old_conn_state->best_encoder);
5250 if (old_conn_state->crtc != crtc)
5253 if (encoder->post_pll_disable)
5254 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5258 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5259 struct drm_atomic_state *old_state)
5261 struct drm_crtc *crtc = pipe_config->base.crtc;
5262 struct drm_device *dev = crtc->dev;
5263 struct drm_i915_private *dev_priv = to_i915(dev);
5264 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5265 int pipe = intel_crtc->pipe;
5266 struct intel_atomic_state *old_intel_state =
5267 to_intel_atomic_state(old_state);
5269 if (WARN_ON(intel_crtc->active))
5273 * Sometimes spurious CPU pipe underruns happen during FDI
5274 * training, at least with VGA+HDMI cloning. Suppress them.
5276 * On ILK we get an occasional spurious CPU pipe underruns
5277 * between eDP port A enable and vdd enable. Also PCH port
5278 * enable seems to result in the occasional CPU pipe underrun.
5280 * Spurious PCH underruns also occur during PCH enabling.
5282 if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv))
5283 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5284 if (intel_crtc->config->has_pch_encoder)
5285 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5287 if (intel_crtc->config->has_pch_encoder)
5288 intel_prepare_shared_dpll(intel_crtc);
5290 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5291 intel_dp_set_m_n(intel_crtc, M1_N1);
5293 intel_set_pipe_timings(intel_crtc);
5294 intel_set_pipe_src_size(intel_crtc);
5296 if (intel_crtc->config->has_pch_encoder) {
5297 intel_cpu_transcoder_set_m_n(intel_crtc,
5298 &intel_crtc->config->fdi_m_n, NULL);
5301 ironlake_set_pipeconf(crtc);
5303 intel_crtc->active = true;
5305 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5307 if (intel_crtc->config->has_pch_encoder) {
5308 /* Note: FDI PLL enabling _must_ be done before we enable the
5309 * cpu pipes, hence this is separate from all the other fdi/pch
5311 ironlake_fdi_pll_enable(intel_crtc);
5313 assert_fdi_tx_disabled(dev_priv, pipe);
5314 assert_fdi_rx_disabled(dev_priv, pipe);
5317 ironlake_pfit_enable(intel_crtc);
5320 * On ILK+ LUT must be loaded before the pipe is running but with
5323 intel_color_load_luts(&pipe_config->base);
5325 if (dev_priv->display.initial_watermarks != NULL)
5326 dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config);
5327 intel_enable_pipe(pipe_config);
5329 if (intel_crtc->config->has_pch_encoder)
5330 ironlake_pch_enable(pipe_config);
5332 assert_vblank_disabled(crtc);
5333 drm_crtc_vblank_on(crtc);
5335 intel_encoders_enable(crtc, pipe_config, old_state);
5337 if (HAS_PCH_CPT(dev_priv))
5338 cpt_verify_modeset(dev, intel_crtc->pipe);
5340 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5341 if (intel_crtc->config->has_pch_encoder)
5342 intel_wait_for_vblank(dev_priv, pipe);
5343 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5344 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5347 /* IPS only exists on ULT machines and is tied to pipe A. */
5348 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5350 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5353 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5354 enum pipe pipe, bool apply)
5356 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5357 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5364 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5367 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5368 struct drm_atomic_state *old_state)
5370 struct drm_crtc *crtc = pipe_config->base.crtc;
5371 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5372 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5373 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5374 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5375 struct intel_atomic_state *old_intel_state =
5376 to_intel_atomic_state(old_state);
5377 bool psl_clkgate_wa;
5379 if (WARN_ON(intel_crtc->active))
5382 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5384 if (intel_crtc->config->shared_dpll)
5385 intel_enable_shared_dpll(intel_crtc);
5387 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5388 intel_dp_set_m_n(intel_crtc, M1_N1);
5390 if (!transcoder_is_dsi(cpu_transcoder))
5391 intel_set_pipe_timings(intel_crtc);
5393 intel_set_pipe_src_size(intel_crtc);
5395 if (cpu_transcoder != TRANSCODER_EDP &&
5396 !transcoder_is_dsi(cpu_transcoder)) {
5397 I915_WRITE(PIPE_MULT(cpu_transcoder),
5398 intel_crtc->config->pixel_multiplier - 1);
5401 if (intel_crtc->config->has_pch_encoder) {
5402 intel_cpu_transcoder_set_m_n(intel_crtc,
5403 &intel_crtc->config->fdi_m_n, NULL);
5406 if (!transcoder_is_dsi(cpu_transcoder))
5407 haswell_set_pipeconf(crtc);
5409 haswell_set_pipemisc(crtc);
5411 intel_color_set_csc(&pipe_config->base);
5413 intel_crtc->active = true;
5415 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5417 if (!transcoder_is_dsi(cpu_transcoder))
5418 intel_ddi_enable_pipe_clock(pipe_config);
5420 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5421 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5422 intel_crtc->config->pch_pfit.enabled;
5424 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5426 if (INTEL_GEN(dev_priv) >= 9)
5427 skylake_pfit_enable(intel_crtc);
5429 ironlake_pfit_enable(intel_crtc);
5432 * On ILK+ LUT must be loaded before the pipe is running but with
5435 intel_color_load_luts(&pipe_config->base);
5437 intel_ddi_set_pipe_settings(pipe_config);
5438 if (!transcoder_is_dsi(cpu_transcoder))
5439 intel_ddi_enable_transcoder_func(pipe_config);
5441 if (dev_priv->display.initial_watermarks != NULL)
5442 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5444 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5445 if (!transcoder_is_dsi(cpu_transcoder))
5446 intel_enable_pipe(pipe_config);
5448 if (intel_crtc->config->has_pch_encoder)
5449 lpt_pch_enable(pipe_config);
5451 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5452 intel_ddi_set_vc_payload_alloc(pipe_config, true);
5454 assert_vblank_disabled(crtc);
5455 drm_crtc_vblank_on(crtc);
5457 intel_encoders_enable(crtc, pipe_config, old_state);
5459 if (psl_clkgate_wa) {
5460 intel_wait_for_vblank(dev_priv, pipe);
5461 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5464 /* If we change the relative order between pipe/planes enabling, we need
5465 * to change the workaround. */
5466 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
5467 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5468 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5469 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5473 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force)
5475 struct drm_device *dev = crtc->base.dev;
5476 struct drm_i915_private *dev_priv = to_i915(dev);
5477 int pipe = crtc->pipe;
5479 /* To avoid upsetting the power well on haswell only disable the pfit if
5480 * it's in use. The hw state code will make sure we get this right. */
5481 if (force || crtc->config->pch_pfit.enabled) {
5482 I915_WRITE(PF_CTL(pipe), 0);
5483 I915_WRITE(PF_WIN_POS(pipe), 0);
5484 I915_WRITE(PF_WIN_SZ(pipe), 0);
5488 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5489 struct drm_atomic_state *old_state)
5491 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5492 struct drm_device *dev = crtc->dev;
5493 struct drm_i915_private *dev_priv = to_i915(dev);
5494 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5495 int pipe = intel_crtc->pipe;
5498 * Sometimes spurious CPU pipe underruns happen when the
5499 * pipe is already disabled, but FDI RX/TX is still enabled.
5500 * Happens at least with VGA+HDMI cloning. Suppress them.
5502 if (intel_crtc->config->has_pch_encoder) {
5503 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5504 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5507 intel_encoders_disable(crtc, old_crtc_state, old_state);
5509 drm_crtc_vblank_off(crtc);
5510 assert_vblank_disabled(crtc);
5512 intel_disable_pipe(old_crtc_state);
5514 ironlake_pfit_disable(intel_crtc, false);
5516 if (intel_crtc->config->has_pch_encoder)
5517 ironlake_fdi_disable(crtc);
5519 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5521 if (intel_crtc->config->has_pch_encoder) {
5522 ironlake_disable_pch_transcoder(dev_priv, pipe);
5524 if (HAS_PCH_CPT(dev_priv)) {
5528 /* disable TRANS_DP_CTL */
5529 reg = TRANS_DP_CTL(pipe);
5530 temp = I915_READ(reg);
5531 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5532 TRANS_DP_PORT_SEL_MASK);
5533 temp |= TRANS_DP_PORT_SEL_NONE;
5534 I915_WRITE(reg, temp);
5536 /* disable DPLL_SEL */
5537 temp = I915_READ(PCH_DPLL_SEL);
5538 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5539 I915_WRITE(PCH_DPLL_SEL, temp);
5542 ironlake_fdi_pll_disable(intel_crtc);
5545 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5546 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5549 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5550 struct drm_atomic_state *old_state)
5552 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5553 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5554 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5555 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5557 intel_encoders_disable(crtc, old_crtc_state, old_state);
5559 drm_crtc_vblank_off(crtc);
5560 assert_vblank_disabled(crtc);
5562 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5563 if (!transcoder_is_dsi(cpu_transcoder))
5564 intel_disable_pipe(old_crtc_state);
5566 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5567 intel_ddi_set_vc_payload_alloc(intel_crtc->config, false);
5569 if (!transcoder_is_dsi(cpu_transcoder))
5570 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
5572 if (INTEL_GEN(dev_priv) >= 9)
5573 skylake_scaler_disable(intel_crtc);
5575 ironlake_pfit_disable(intel_crtc, false);
5577 if (!transcoder_is_dsi(cpu_transcoder))
5578 intel_ddi_disable_pipe_clock(intel_crtc->config);
5580 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5583 static void i9xx_pfit_enable(struct intel_crtc *crtc)
5585 struct drm_device *dev = crtc->base.dev;
5586 struct drm_i915_private *dev_priv = to_i915(dev);
5587 struct intel_crtc_state *pipe_config = crtc->config;
5589 if (!pipe_config->gmch_pfit.control)
5593 * The panel fitter should only be adjusted whilst the pipe is disabled,
5594 * according to register description and PRM.
5596 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5597 assert_pipe_disabled(dev_priv, crtc->pipe);
5599 I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
5600 I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
5602 /* Border color in case we don't scale up to the full screen. Black by
5603 * default, change to something else for debugging. */
5604 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5607 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
5611 return POWER_DOMAIN_PORT_DDI_A_LANES;
5613 return POWER_DOMAIN_PORT_DDI_B_LANES;
5615 return POWER_DOMAIN_PORT_DDI_C_LANES;
5617 return POWER_DOMAIN_PORT_DDI_D_LANES;
5619 return POWER_DOMAIN_PORT_DDI_E_LANES;
5622 return POWER_DOMAIN_PORT_OTHER;
5626 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
5627 struct intel_crtc_state *crtc_state)
5629 struct drm_device *dev = crtc->dev;
5630 struct drm_i915_private *dev_priv = to_i915(dev);
5631 struct drm_encoder *encoder;
5632 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5633 enum pipe pipe = intel_crtc->pipe;
5635 enum transcoder transcoder = crtc_state->cpu_transcoder;
5637 if (!crtc_state->base.active)
5640 mask = BIT(POWER_DOMAIN_PIPE(pipe));
5641 mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
5642 if (crtc_state->pch_pfit.enabled ||
5643 crtc_state->pch_pfit.force_thru)
5644 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5646 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
5647 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5649 mask |= BIT_ULL(intel_encoder->power_domain);
5652 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
5653 mask |= BIT(POWER_DOMAIN_AUDIO);
5655 if (crtc_state->shared_dpll)
5656 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
5662 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
5663 struct intel_crtc_state *crtc_state)
5665 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5666 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5667 enum intel_display_power_domain domain;
5668 u64 domains, new_domains, old_domains;
5670 old_domains = intel_crtc->enabled_power_domains;
5671 intel_crtc->enabled_power_domains = new_domains =
5672 get_crtc_power_domains(crtc, crtc_state);
5674 domains = new_domains & ~old_domains;
5676 for_each_power_domain(domain, domains)
5677 intel_display_power_get(dev_priv, domain);
5679 return old_domains & ~new_domains;
5682 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
5685 enum intel_display_power_domain domain;
5687 for_each_power_domain(domain, domains)
5688 intel_display_power_put(dev_priv, domain);
5691 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
5692 struct drm_atomic_state *old_state)
5694 struct intel_atomic_state *old_intel_state =
5695 to_intel_atomic_state(old_state);
5696 struct drm_crtc *crtc = pipe_config->base.crtc;
5697 struct drm_device *dev = crtc->dev;
5698 struct drm_i915_private *dev_priv = to_i915(dev);
5699 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5700 int pipe = intel_crtc->pipe;
5702 if (WARN_ON(intel_crtc->active))
5705 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5706 intel_dp_set_m_n(intel_crtc, M1_N1);
5708 intel_set_pipe_timings(intel_crtc);
5709 intel_set_pipe_src_size(intel_crtc);
5711 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
5712 struct drm_i915_private *dev_priv = to_i915(dev);
5714 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
5715 I915_WRITE(CHV_CANVAS(pipe), 0);
5718 i9xx_set_pipeconf(intel_crtc);
5720 intel_crtc->active = true;
5722 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5724 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5726 if (IS_CHERRYVIEW(dev_priv)) {
5727 chv_prepare_pll(intel_crtc, intel_crtc->config);
5728 chv_enable_pll(intel_crtc, intel_crtc->config);
5730 vlv_prepare_pll(intel_crtc, intel_crtc->config);
5731 vlv_enable_pll(intel_crtc, intel_crtc->config);
5734 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5736 i9xx_pfit_enable(intel_crtc);
5738 intel_color_load_luts(&pipe_config->base);
5740 dev_priv->display.initial_watermarks(old_intel_state,
5742 intel_enable_pipe(pipe_config);
5744 assert_vblank_disabled(crtc);
5745 drm_crtc_vblank_on(crtc);
5747 intel_encoders_enable(crtc, pipe_config, old_state);
5750 static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
5752 struct drm_device *dev = crtc->base.dev;
5753 struct drm_i915_private *dev_priv = to_i915(dev);
5755 I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
5756 I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
5759 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
5760 struct drm_atomic_state *old_state)
5762 struct intel_atomic_state *old_intel_state =
5763 to_intel_atomic_state(old_state);
5764 struct drm_crtc *crtc = pipe_config->base.crtc;
5765 struct drm_device *dev = crtc->dev;
5766 struct drm_i915_private *dev_priv = to_i915(dev);
5767 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5768 enum pipe pipe = intel_crtc->pipe;
5770 if (WARN_ON(intel_crtc->active))
5773 i9xx_set_pll_dividers(intel_crtc);
5775 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5776 intel_dp_set_m_n(intel_crtc, M1_N1);
5778 intel_set_pipe_timings(intel_crtc);
5779 intel_set_pipe_src_size(intel_crtc);
5781 i9xx_set_pipeconf(intel_crtc);
5783 intel_crtc->active = true;
5785 if (!IS_GEN2(dev_priv))
5786 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5788 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5790 i9xx_enable_pll(intel_crtc, pipe_config);
5792 i9xx_pfit_enable(intel_crtc);
5794 intel_color_load_luts(&pipe_config->base);
5796 if (dev_priv->display.initial_watermarks != NULL)
5797 dev_priv->display.initial_watermarks(old_intel_state,
5798 intel_crtc->config);
5800 intel_update_watermarks(intel_crtc);
5801 intel_enable_pipe(pipe_config);
5803 assert_vblank_disabled(crtc);
5804 drm_crtc_vblank_on(crtc);
5806 intel_encoders_enable(crtc, pipe_config, old_state);
5809 static void i9xx_pfit_disable(struct intel_crtc *crtc)
5811 struct drm_device *dev = crtc->base.dev;
5812 struct drm_i915_private *dev_priv = to_i915(dev);
5814 if (!crtc->config->gmch_pfit.control)
5817 assert_pipe_disabled(dev_priv, crtc->pipe);
5819 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
5820 I915_READ(PFIT_CONTROL));
5821 I915_WRITE(PFIT_CONTROL, 0);
5824 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
5825 struct drm_atomic_state *old_state)
5827 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5828 struct drm_device *dev = crtc->dev;
5829 struct drm_i915_private *dev_priv = to_i915(dev);
5830 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5831 int pipe = intel_crtc->pipe;
5834 * On gen2 planes are double buffered but the pipe isn't, so we must
5835 * wait for planes to fully turn off before disabling the pipe.
5837 if (IS_GEN2(dev_priv))
5838 intel_wait_for_vblank(dev_priv, pipe);
5840 intel_encoders_disable(crtc, old_crtc_state, old_state);
5842 drm_crtc_vblank_off(crtc);
5843 assert_vblank_disabled(crtc);
5845 intel_disable_pipe(old_crtc_state);
5847 i9xx_pfit_disable(intel_crtc);
5849 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5851 if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) {
5852 if (IS_CHERRYVIEW(dev_priv))
5853 chv_disable_pll(dev_priv, pipe);
5854 else if (IS_VALLEYVIEW(dev_priv))
5855 vlv_disable_pll(dev_priv, pipe);
5857 i9xx_disable_pll(intel_crtc);
5860 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
5862 if (!IS_GEN2(dev_priv))
5863 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5865 if (!dev_priv->display.initial_watermarks)
5866 intel_update_watermarks(intel_crtc);
5868 /* clock the pipe down to 640x480@60 to potentially save power */
5869 if (IS_I830(dev_priv))
5870 i830_enable_pipe(dev_priv, pipe);
5873 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
5874 struct drm_modeset_acquire_ctx *ctx)
5876 struct intel_encoder *encoder;
5877 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5878 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5879 enum intel_display_power_domain domain;
5880 struct intel_plane *plane;
5882 struct drm_atomic_state *state;
5883 struct intel_crtc_state *crtc_state;
5886 if (!intel_crtc->active)
5889 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
5890 const struct intel_plane_state *plane_state =
5891 to_intel_plane_state(plane->base.state);
5893 if (plane_state->base.visible)
5894 intel_plane_disable_noatomic(intel_crtc, plane);
5897 state = drm_atomic_state_alloc(crtc->dev);
5899 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
5900 crtc->base.id, crtc->name);
5904 state->acquire_ctx = ctx;
5906 /* Everything's already locked, -EDEADLK can't happen. */
5907 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
5908 ret = drm_atomic_add_affected_connectors(state, crtc);
5910 WARN_ON(IS_ERR(crtc_state) || ret);
5912 dev_priv->display.crtc_disable(crtc_state, state);
5914 drm_atomic_state_put(state);
5916 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
5917 crtc->base.id, crtc->name);
5919 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
5920 crtc->state->active = false;
5921 intel_crtc->active = false;
5922 crtc->enabled = false;
5923 crtc->state->connector_mask = 0;
5924 crtc->state->encoder_mask = 0;
5926 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
5927 encoder->base.crtc = NULL;
5929 intel_fbc_disable(intel_crtc);
5930 intel_update_watermarks(intel_crtc);
5931 intel_disable_shared_dpll(intel_crtc);
5933 domains = intel_crtc->enabled_power_domains;
5934 for_each_power_domain(domain, domains)
5935 intel_display_power_put(dev_priv, domain);
5936 intel_crtc->enabled_power_domains = 0;
5938 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
5939 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
5940 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
5944 * turn all crtc's off, but do not adjust state
5945 * This has to be paired with a call to intel_modeset_setup_hw_state.
5947 int intel_display_suspend(struct drm_device *dev)
5949 struct drm_i915_private *dev_priv = to_i915(dev);
5950 struct drm_atomic_state *state;
5953 state = drm_atomic_helper_suspend(dev);
5954 ret = PTR_ERR_OR_ZERO(state);
5956 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
5958 dev_priv->modeset_restore_state = state;
5962 void intel_encoder_destroy(struct drm_encoder *encoder)
5964 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5966 drm_encoder_cleanup(encoder);
5967 kfree(intel_encoder);
5970 /* Cross check the actual hw state with our own modeset state tracking (and it's
5971 * internal consistency). */
5972 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
5973 struct drm_connector_state *conn_state)
5975 struct intel_connector *connector = to_intel_connector(conn_state->connector);
5977 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5978 connector->base.base.id,
5979 connector->base.name);
5981 if (connector->get_hw_state(connector)) {
5982 struct intel_encoder *encoder = connector->encoder;
5984 I915_STATE_WARN(!crtc_state,
5985 "connector enabled without attached crtc\n");
5990 I915_STATE_WARN(!crtc_state->active,
5991 "connector is active, but attached crtc isn't\n");
5993 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
5996 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
5997 "atomic encoder doesn't match attached encoder\n");
5999 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6000 "attached encoder crtc differs from connector crtc\n");
6002 I915_STATE_WARN(crtc_state && crtc_state->active,
6003 "attached crtc is active, but connector isn't\n");
6004 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6005 "best encoder set without crtc!\n");
6009 int intel_connector_init(struct intel_connector *connector)
6011 struct intel_digital_connector_state *conn_state;
6014 * Allocate enough memory to hold intel_digital_connector_state,
6015 * This might be a few bytes too many, but for connectors that don't
6016 * need it we'll free the state and allocate a smaller one on the first
6017 * succesful commit anyway.
6019 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
6023 __drm_atomic_helper_connector_reset(&connector->base,
6029 struct intel_connector *intel_connector_alloc(void)
6031 struct intel_connector *connector;
6033 connector = kzalloc(sizeof *connector, GFP_KERNEL);
6037 if (intel_connector_init(connector) < 0) {
6046 * Free the bits allocated by intel_connector_alloc.
6047 * This should only be used after intel_connector_alloc has returned
6048 * successfully, and before drm_connector_init returns successfully.
6049 * Otherwise the destroy callbacks for the connector and the state should
6050 * take care of proper cleanup/free
6052 void intel_connector_free(struct intel_connector *connector)
6054 kfree(to_intel_digital_connector_state(connector->base.state));
6058 /* Simple connector->get_hw_state implementation for encoders that support only
6059 * one connector and no cloning and hence the encoder state determines the state
6060 * of the connector. */
6061 bool intel_connector_get_hw_state(struct intel_connector *connector)
6064 struct intel_encoder *encoder = connector->encoder;
6066 return encoder->get_hw_state(encoder, &pipe);
6069 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6071 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6072 return crtc_state->fdi_lanes;
6077 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6078 struct intel_crtc_state *pipe_config)
6080 struct drm_i915_private *dev_priv = to_i915(dev);
6081 struct drm_atomic_state *state = pipe_config->base.state;
6082 struct intel_crtc *other_crtc;
6083 struct intel_crtc_state *other_crtc_state;
6085 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6086 pipe_name(pipe), pipe_config->fdi_lanes);
6087 if (pipe_config->fdi_lanes > 4) {
6088 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6089 pipe_name(pipe), pipe_config->fdi_lanes);
6093 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6094 if (pipe_config->fdi_lanes > 2) {
6095 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6096 pipe_config->fdi_lanes);
6103 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6106 /* Ivybridge 3 pipe is really complicated */
6111 if (pipe_config->fdi_lanes <= 2)
6114 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6116 intel_atomic_get_crtc_state(state, other_crtc);
6117 if (IS_ERR(other_crtc_state))
6118 return PTR_ERR(other_crtc_state);
6120 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6121 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6122 pipe_name(pipe), pipe_config->fdi_lanes);
6127 if (pipe_config->fdi_lanes > 2) {
6128 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6129 pipe_name(pipe), pipe_config->fdi_lanes);
6133 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6135 intel_atomic_get_crtc_state(state, other_crtc);
6136 if (IS_ERR(other_crtc_state))
6137 return PTR_ERR(other_crtc_state);
6139 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6140 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6150 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6151 struct intel_crtc_state *pipe_config)
6153 struct drm_device *dev = intel_crtc->base.dev;
6154 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6155 int lane, link_bw, fdi_dotclock, ret;
6156 bool needs_recompute = false;
6159 /* FDI is a binary signal running at ~2.7GHz, encoding
6160 * each output octet as 10 bits. The actual frequency
6161 * is stored as a divider into a 100MHz clock, and the
6162 * mode pixel clock is stored in units of 1KHz.
6163 * Hence the bw of each lane in terms of the mode signal
6166 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6168 fdi_dotclock = adjusted_mode->crtc_clock;
6170 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6171 pipe_config->pipe_bpp);
6173 pipe_config->fdi_lanes = lane;
6175 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6176 link_bw, &pipe_config->fdi_m_n, false);
6178 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6179 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6180 pipe_config->pipe_bpp -= 2*3;
6181 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6182 pipe_config->pipe_bpp);
6183 needs_recompute = true;
6184 pipe_config->bw_constrained = true;
6189 if (needs_recompute)
6195 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6197 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6198 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6200 /* IPS only exists on ULT machines and is tied to pipe A. */
6201 if (!hsw_crtc_supports_ips(crtc))
6204 if (!i915_modparams.enable_ips)
6207 if (crtc_state->pipe_bpp > 24)
6211 * We compare against max which means we must take
6212 * the increased cdclk requirement into account when
6213 * calculating the new cdclk.
6215 * Should measure whether using a lower cdclk w/o IPS
6217 if (IS_BROADWELL(dev_priv) &&
6218 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6224 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6226 struct drm_i915_private *dev_priv =
6227 to_i915(crtc_state->base.crtc->dev);
6228 struct intel_atomic_state *intel_state =
6229 to_intel_atomic_state(crtc_state->base.state);
6231 if (!hsw_crtc_state_ips_capable(crtc_state))
6234 if (crtc_state->ips_force_disable)
6237 /* IPS should be fine as long as at least one plane is enabled. */
6238 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6241 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6242 if (IS_BROADWELL(dev_priv) &&
6243 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6249 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6251 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6253 /* GDG double wide on either pipe, otherwise pipe A only */
6254 return INTEL_INFO(dev_priv)->gen < 4 &&
6255 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6258 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6260 uint32_t pixel_rate;
6262 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6265 * We only use IF-ID interlacing. If we ever use
6266 * PF-ID we'll need to adjust the pixel_rate here.
6269 if (pipe_config->pch_pfit.enabled) {
6270 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6271 uint32_t pfit_size = pipe_config->pch_pfit.size;
6273 pipe_w = pipe_config->pipe_src_w;
6274 pipe_h = pipe_config->pipe_src_h;
6276 pfit_w = (pfit_size >> 16) & 0xFFFF;
6277 pfit_h = pfit_size & 0xFFFF;
6278 if (pipe_w < pfit_w)
6280 if (pipe_h < pfit_h)
6283 if (WARN_ON(!pfit_w || !pfit_h))
6286 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6293 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6295 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6297 if (HAS_GMCH_DISPLAY(dev_priv))
6298 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6299 crtc_state->pixel_rate =
6300 crtc_state->base.adjusted_mode.crtc_clock;
6302 crtc_state->pixel_rate =
6303 ilk_pipe_pixel_rate(crtc_state);
6306 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6307 struct intel_crtc_state *pipe_config)
6309 struct drm_device *dev = crtc->base.dev;
6310 struct drm_i915_private *dev_priv = to_i915(dev);
6311 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6312 int clock_limit = dev_priv->max_dotclk_freq;
6314 if (INTEL_GEN(dev_priv) < 4) {
6315 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6318 * Enable double wide mode when the dot clock
6319 * is > 90% of the (display) core speed.
6321 if (intel_crtc_supports_double_wide(crtc) &&
6322 adjusted_mode->crtc_clock > clock_limit) {
6323 clock_limit = dev_priv->max_dotclk_freq;
6324 pipe_config->double_wide = true;
6328 if (adjusted_mode->crtc_clock > clock_limit) {
6329 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6330 adjusted_mode->crtc_clock, clock_limit,
6331 yesno(pipe_config->double_wide));
6335 if (pipe_config->ycbcr420 && pipe_config->base.ctm) {
6337 * There is only one pipe CSC unit per pipe, and we need that
6338 * for output conversion from RGB->YCBCR. So if CTM is already
6339 * applied we can't support YCBCR420 output.
6341 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6346 * Pipe horizontal size must be even in:
6348 * - LVDS dual channel mode
6349 * - Double wide pipe
6351 if ((intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6352 intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
6353 pipe_config->pipe_src_w &= ~1;
6355 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6356 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6358 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6359 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6362 intel_crtc_compute_pixel_rate(pipe_config);
6364 if (pipe_config->has_pch_encoder)
6365 return ironlake_fdi_compute_config(crtc, pipe_config);
6371 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6373 while (*num > DATA_LINK_M_N_MASK ||
6374 *den > DATA_LINK_M_N_MASK) {
6380 static void compute_m_n(unsigned int m, unsigned int n,
6381 uint32_t *ret_m, uint32_t *ret_n,
6385 * Reduce M/N as much as possible without loss in precision. Several DP
6386 * dongles in particular seem to be fussy about too large *link* M/N
6387 * values. The passed in values are more likely to have the least
6388 * significant bits zero than M after rounding below, so do this first.
6391 while ((m & 1) == 0 && (n & 1) == 0) {
6397 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6398 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6399 intel_reduce_m_n_ratio(ret_m, ret_n);
6403 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6404 int pixel_clock, int link_clock,
6405 struct intel_link_m_n *m_n,
6410 compute_m_n(bits_per_pixel * pixel_clock,
6411 link_clock * nlanes * 8,
6412 &m_n->gmch_m, &m_n->gmch_n,
6415 compute_m_n(pixel_clock, link_clock,
6416 &m_n->link_m, &m_n->link_n,
6420 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6422 if (i915_modparams.panel_use_ssc >= 0)
6423 return i915_modparams.panel_use_ssc != 0;
6424 return dev_priv->vbt.lvds_use_ssc
6425 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6428 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
6430 return (1 << dpll->n) << 16 | dpll->m2;
6433 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6435 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
6438 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
6439 struct intel_crtc_state *crtc_state,
6440 struct dpll *reduced_clock)
6442 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6445 if (IS_PINEVIEW(dev_priv)) {
6446 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
6448 fp2 = pnv_dpll_compute_fp(reduced_clock);
6450 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
6452 fp2 = i9xx_dpll_compute_fp(reduced_clock);
6455 crtc_state->dpll_hw_state.fp0 = fp;
6457 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6459 crtc_state->dpll_hw_state.fp1 = fp2;
6461 crtc_state->dpll_hw_state.fp1 = fp;
6465 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6471 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6472 * and set it to a reasonable value instead.
6474 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6475 reg_val &= 0xffffff00;
6476 reg_val |= 0x00000030;
6477 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6479 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6480 reg_val &= 0x00ffffff;
6481 reg_val |= 0x8c000000;
6482 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6484 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6485 reg_val &= 0xffffff00;
6486 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6488 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6489 reg_val &= 0x00ffffff;
6490 reg_val |= 0xb0000000;
6491 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6494 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
6495 struct intel_link_m_n *m_n)
6497 struct drm_device *dev = crtc->base.dev;
6498 struct drm_i915_private *dev_priv = to_i915(dev);
6499 int pipe = crtc->pipe;
6501 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6502 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6503 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6504 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6507 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
6508 struct intel_link_m_n *m_n,
6509 struct intel_link_m_n *m2_n2)
6511 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6512 int pipe = crtc->pipe;
6513 enum transcoder transcoder = crtc->config->cpu_transcoder;
6515 if (INTEL_GEN(dev_priv) >= 5) {
6516 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6517 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6518 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6519 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
6520 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6521 * for gen < 8) and if DRRS is supported (to make sure the
6522 * registers are not unnecessarily accessed).
6524 if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
6525 INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
6526 I915_WRITE(PIPE_DATA_M2(transcoder),
6527 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6528 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6529 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6530 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6533 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6534 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6535 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6536 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
6540 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
6542 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6545 dp_m_n = &crtc->config->dp_m_n;
6546 dp_m2_n2 = &crtc->config->dp_m2_n2;
6547 } else if (m_n == M2_N2) {
6550 * M2_N2 registers are not supported. Hence m2_n2 divider value
6551 * needs to be programmed into M1_N1.
6553 dp_m_n = &crtc->config->dp_m2_n2;
6555 DRM_ERROR("Unsupported divider value\n");
6559 if (crtc->config->has_pch_encoder)
6560 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
6562 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
6565 static void vlv_compute_dpll(struct intel_crtc *crtc,
6566 struct intel_crtc_state *pipe_config)
6568 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
6569 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6570 if (crtc->pipe != PIPE_A)
6571 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6573 /* DPLL not used with DSI, but still need the rest set up */
6574 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6575 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6576 DPLL_EXT_BUFFER_ENABLE_VLV;
6578 pipe_config->dpll_hw_state.dpll_md =
6579 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6582 static void chv_compute_dpll(struct intel_crtc *crtc,
6583 struct intel_crtc_state *pipe_config)
6585 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
6586 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6587 if (crtc->pipe != PIPE_A)
6588 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6590 /* DPLL not used with DSI, but still need the rest set up */
6591 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6592 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6594 pipe_config->dpll_hw_state.dpll_md =
6595 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6598 static void vlv_prepare_pll(struct intel_crtc *crtc,
6599 const struct intel_crtc_state *pipe_config)
6601 struct drm_device *dev = crtc->base.dev;
6602 struct drm_i915_private *dev_priv = to_i915(dev);
6603 enum pipe pipe = crtc->pipe;
6605 u32 bestn, bestm1, bestm2, bestp1, bestp2;
6606 u32 coreclk, reg_val;
6609 I915_WRITE(DPLL(pipe),
6610 pipe_config->dpll_hw_state.dpll &
6611 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6613 /* No need to actually set up the DPLL with DSI */
6614 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6617 mutex_lock(&dev_priv->sb_lock);
6619 bestn = pipe_config->dpll.n;
6620 bestm1 = pipe_config->dpll.m1;
6621 bestm2 = pipe_config->dpll.m2;
6622 bestp1 = pipe_config->dpll.p1;
6623 bestp2 = pipe_config->dpll.p2;
6625 /* See eDP HDMI DPIO driver vbios notes doc */
6627 /* PLL B needs special handling */
6629 vlv_pllb_recal_opamp(dev_priv, pipe);
6631 /* Set up Tx target for periodic Rcomp update */
6632 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
6634 /* Disable target IRef on PLL */
6635 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
6636 reg_val &= 0x00ffffff;
6637 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
6639 /* Disable fast lock */
6640 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
6642 /* Set idtafcrecal before PLL is enabled */
6643 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6644 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6645 mdiv |= ((bestn << DPIO_N_SHIFT));
6646 mdiv |= (1 << DPIO_K_SHIFT);
6649 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6650 * but we don't support that).
6651 * Note: don't use the DAC post divider as it seems unstable.
6653 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
6654 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6656 mdiv |= DPIO_ENABLE_CALIBRATION;
6657 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6659 /* Set HBR and RBR LPF coefficients */
6660 if (pipe_config->port_clock == 162000 ||
6661 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) ||
6662 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI))
6663 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6666 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6669 if (intel_crtc_has_dp_encoder(pipe_config)) {
6670 /* Use SSC source */
6672 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6675 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6677 } else { /* HDMI or VGA */
6678 /* Use bend source */
6680 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6683 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6687 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
6688 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
6689 if (intel_crtc_has_dp_encoder(crtc->config))
6690 coreclk |= 0x01000000;
6691 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
6693 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
6694 mutex_unlock(&dev_priv->sb_lock);
6697 static void chv_prepare_pll(struct intel_crtc *crtc,
6698 const struct intel_crtc_state *pipe_config)
6700 struct drm_device *dev = crtc->base.dev;
6701 struct drm_i915_private *dev_priv = to_i915(dev);
6702 enum pipe pipe = crtc->pipe;
6703 enum dpio_channel port = vlv_pipe_to_channel(pipe);
6704 u32 loopfilter, tribuf_calcntr;
6705 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
6709 /* Enable Refclk and SSC */
6710 I915_WRITE(DPLL(pipe),
6711 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
6713 /* No need to actually set up the DPLL with DSI */
6714 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6717 bestn = pipe_config->dpll.n;
6718 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
6719 bestm1 = pipe_config->dpll.m1;
6720 bestm2 = pipe_config->dpll.m2 >> 22;
6721 bestp1 = pipe_config->dpll.p1;
6722 bestp2 = pipe_config->dpll.p2;
6723 vco = pipe_config->dpll.vco;
6727 mutex_lock(&dev_priv->sb_lock);
6729 /* p1 and p2 divider */
6730 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
6731 5 << DPIO_CHV_S1_DIV_SHIFT |
6732 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
6733 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
6734 1 << DPIO_CHV_K_DIV_SHIFT);
6736 /* Feedback post-divider - m2 */
6737 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
6739 /* Feedback refclk divider - n and m1 */
6740 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
6741 DPIO_CHV_M1_DIV_BY_2 |
6742 1 << DPIO_CHV_N_DIV_SHIFT);
6744 /* M2 fraction division */
6745 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
6747 /* M2 fraction division enable */
6748 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
6749 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
6750 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
6752 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
6753 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
6755 /* Program digital lock detect threshold */
6756 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
6757 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
6758 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
6759 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
6761 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
6762 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
6765 if (vco == 5400000) {
6766 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
6767 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
6768 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
6769 tribuf_calcntr = 0x9;
6770 } else if (vco <= 6200000) {
6771 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
6772 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
6773 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6774 tribuf_calcntr = 0x9;
6775 } else if (vco <= 6480000) {
6776 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
6777 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
6778 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6779 tribuf_calcntr = 0x8;
6781 /* Not supported. Apply the same limits as in the max case */
6782 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
6783 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
6784 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6787 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
6789 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
6790 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
6791 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
6792 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
6795 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
6796 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
6799 mutex_unlock(&dev_priv->sb_lock);
6803 * vlv_force_pll_on - forcibly enable just the PLL
6804 * @dev_priv: i915 private structure
6805 * @pipe: pipe PLL to enable
6806 * @dpll: PLL configuration
6808 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6809 * in cases where we need the PLL enabled even when @pipe is not going to
6812 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
6813 const struct dpll *dpll)
6815 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
6816 struct intel_crtc_state *pipe_config;
6818 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
6822 pipe_config->base.crtc = &crtc->base;
6823 pipe_config->pixel_multiplier = 1;
6824 pipe_config->dpll = *dpll;
6826 if (IS_CHERRYVIEW(dev_priv)) {
6827 chv_compute_dpll(crtc, pipe_config);
6828 chv_prepare_pll(crtc, pipe_config);
6829 chv_enable_pll(crtc, pipe_config);
6831 vlv_compute_dpll(crtc, pipe_config);
6832 vlv_prepare_pll(crtc, pipe_config);
6833 vlv_enable_pll(crtc, pipe_config);
6842 * vlv_force_pll_off - forcibly disable just the PLL
6843 * @dev_priv: i915 private structure
6844 * @pipe: pipe PLL to disable
6846 * Disable the PLL for @pipe. To be used in cases where we need
6847 * the PLL enabled even when @pipe is not going to be enabled.
6849 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
6851 if (IS_CHERRYVIEW(dev_priv))
6852 chv_disable_pll(dev_priv, pipe);
6854 vlv_disable_pll(dev_priv, pipe);
6857 static void i9xx_compute_dpll(struct intel_crtc *crtc,
6858 struct intel_crtc_state *crtc_state,
6859 struct dpll *reduced_clock)
6861 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6863 struct dpll *clock = &crtc_state->dpll;
6865 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
6867 dpll = DPLL_VGA_MODE_DIS;
6869 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
6870 dpll |= DPLLB_MODE_LVDS;
6872 dpll |= DPLLB_MODE_DAC_SERIAL;
6874 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
6875 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
6876 dpll |= (crtc_state->pixel_multiplier - 1)
6877 << SDVO_MULTIPLIER_SHIFT_HIRES;
6880 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
6881 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
6882 dpll |= DPLL_SDVO_HIGH_SPEED;
6884 if (intel_crtc_has_dp_encoder(crtc_state))
6885 dpll |= DPLL_SDVO_HIGH_SPEED;
6887 /* compute bitmask from p1 value */
6888 if (IS_PINEVIEW(dev_priv))
6889 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
6891 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
6892 if (IS_G4X(dev_priv) && reduced_clock)
6893 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
6895 switch (clock->p2) {
6897 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
6900 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
6903 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
6906 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
6909 if (INTEL_GEN(dev_priv) >= 4)
6910 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
6912 if (crtc_state->sdvo_tv_clock)
6913 dpll |= PLL_REF_INPUT_TVCLKINBC;
6914 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6915 intel_panel_use_ssc(dev_priv))
6916 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
6918 dpll |= PLL_REF_INPUT_DREFCLK;
6920 dpll |= DPLL_VCO_ENABLE;
6921 crtc_state->dpll_hw_state.dpll = dpll;
6923 if (INTEL_GEN(dev_priv) >= 4) {
6924 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
6925 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6926 crtc_state->dpll_hw_state.dpll_md = dpll_md;
6930 static void i8xx_compute_dpll(struct intel_crtc *crtc,
6931 struct intel_crtc_state *crtc_state,
6932 struct dpll *reduced_clock)
6934 struct drm_device *dev = crtc->base.dev;
6935 struct drm_i915_private *dev_priv = to_i915(dev);
6937 struct dpll *clock = &crtc_state->dpll;
6939 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
6941 dpll = DPLL_VGA_MODE_DIS;
6943 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
6944 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
6947 dpll |= PLL_P1_DIVIDE_BY_TWO;
6949 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
6951 dpll |= PLL_P2_DIVIDE_BY_4;
6954 if (!IS_I830(dev_priv) &&
6955 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
6956 dpll |= DPLL_DVO_2X_MODE;
6958 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6959 intel_panel_use_ssc(dev_priv))
6960 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
6962 dpll |= PLL_REF_INPUT_DREFCLK;
6964 dpll |= DPLL_VCO_ENABLE;
6965 crtc_state->dpll_hw_state.dpll = dpll;
6968 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
6970 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
6971 enum pipe pipe = intel_crtc->pipe;
6972 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
6973 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
6974 uint32_t crtc_vtotal, crtc_vblank_end;
6977 /* We need to be careful not to changed the adjusted mode, for otherwise
6978 * the hw state checker will get angry at the mismatch. */
6979 crtc_vtotal = adjusted_mode->crtc_vtotal;
6980 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
6982 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
6983 /* the chip adds 2 halflines automatically */
6985 crtc_vblank_end -= 1;
6987 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
6988 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
6990 vsyncshift = adjusted_mode->crtc_hsync_start -
6991 adjusted_mode->crtc_htotal / 2;
6993 vsyncshift += adjusted_mode->crtc_htotal;
6996 if (INTEL_GEN(dev_priv) > 3)
6997 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
6999 I915_WRITE(HTOTAL(cpu_transcoder),
7000 (adjusted_mode->crtc_hdisplay - 1) |
7001 ((adjusted_mode->crtc_htotal - 1) << 16));
7002 I915_WRITE(HBLANK(cpu_transcoder),
7003 (adjusted_mode->crtc_hblank_start - 1) |
7004 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7005 I915_WRITE(HSYNC(cpu_transcoder),
7006 (adjusted_mode->crtc_hsync_start - 1) |
7007 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7009 I915_WRITE(VTOTAL(cpu_transcoder),
7010 (adjusted_mode->crtc_vdisplay - 1) |
7011 ((crtc_vtotal - 1) << 16));
7012 I915_WRITE(VBLANK(cpu_transcoder),
7013 (adjusted_mode->crtc_vblank_start - 1) |
7014 ((crtc_vblank_end - 1) << 16));
7015 I915_WRITE(VSYNC(cpu_transcoder),
7016 (adjusted_mode->crtc_vsync_start - 1) |
7017 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7019 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7020 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7021 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7023 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7024 (pipe == PIPE_B || pipe == PIPE_C))
7025 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7029 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc)
7031 struct drm_device *dev = intel_crtc->base.dev;
7032 struct drm_i915_private *dev_priv = to_i915(dev);
7033 enum pipe pipe = intel_crtc->pipe;
7035 /* pipesrc controls the size that is scaled from, which should
7036 * always be the user's requested size.
7038 I915_WRITE(PIPESRC(pipe),
7039 ((intel_crtc->config->pipe_src_w - 1) << 16) |
7040 (intel_crtc->config->pipe_src_h - 1));
7043 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7044 struct intel_crtc_state *pipe_config)
7046 struct drm_device *dev = crtc->base.dev;
7047 struct drm_i915_private *dev_priv = to_i915(dev);
7048 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7051 tmp = I915_READ(HTOTAL(cpu_transcoder));
7052 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7053 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7054 tmp = I915_READ(HBLANK(cpu_transcoder));
7055 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7056 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7057 tmp = I915_READ(HSYNC(cpu_transcoder));
7058 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7059 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7061 tmp = I915_READ(VTOTAL(cpu_transcoder));
7062 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7063 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7064 tmp = I915_READ(VBLANK(cpu_transcoder));
7065 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7066 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7067 tmp = I915_READ(VSYNC(cpu_transcoder));
7068 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7069 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7071 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7072 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7073 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7074 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7078 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7079 struct intel_crtc_state *pipe_config)
7081 struct drm_device *dev = crtc->base.dev;
7082 struct drm_i915_private *dev_priv = to_i915(dev);
7085 tmp = I915_READ(PIPESRC(crtc->pipe));
7086 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7087 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7089 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7090 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7093 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7094 struct intel_crtc_state *pipe_config)
7096 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7097 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7098 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7099 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7101 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7102 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7103 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7104 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7106 mode->flags = pipe_config->base.adjusted_mode.flags;
7107 mode->type = DRM_MODE_TYPE_DRIVER;
7109 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7111 mode->hsync = drm_mode_hsync(mode);
7112 mode->vrefresh = drm_mode_vrefresh(mode);
7113 drm_mode_set_name(mode);
7116 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
7118 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7123 /* we keep both pipes enabled on 830 */
7124 if (IS_I830(dev_priv))
7125 pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
7127 if (intel_crtc->config->double_wide)
7128 pipeconf |= PIPECONF_DOUBLE_WIDE;
7130 /* only g4x and later have fancy bpc/dither controls */
7131 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7132 IS_CHERRYVIEW(dev_priv)) {
7133 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7134 if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
7135 pipeconf |= PIPECONF_DITHER_EN |
7136 PIPECONF_DITHER_TYPE_SP;
7138 switch (intel_crtc->config->pipe_bpp) {
7140 pipeconf |= PIPECONF_6BPC;
7143 pipeconf |= PIPECONF_8BPC;
7146 pipeconf |= PIPECONF_10BPC;
7149 /* Case prevented by intel_choose_pipe_bpp_dither. */
7154 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7155 if (INTEL_GEN(dev_priv) < 4 ||
7156 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7157 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7159 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7161 pipeconf |= PIPECONF_PROGRESSIVE;
7163 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7164 intel_crtc->config->limited_color_range)
7165 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7167 I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
7168 POSTING_READ(PIPECONF(intel_crtc->pipe));
7171 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7172 struct intel_crtc_state *crtc_state)
7174 struct drm_device *dev = crtc->base.dev;
7175 struct drm_i915_private *dev_priv = to_i915(dev);
7176 const struct intel_limit *limit;
7179 memset(&crtc_state->dpll_hw_state, 0,
7180 sizeof(crtc_state->dpll_hw_state));
7182 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7183 if (intel_panel_use_ssc(dev_priv)) {
7184 refclk = dev_priv->vbt.lvds_ssc_freq;
7185 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7188 limit = &intel_limits_i8xx_lvds;
7189 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7190 limit = &intel_limits_i8xx_dvo;
7192 limit = &intel_limits_i8xx_dac;
7195 if (!crtc_state->clock_set &&
7196 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7197 refclk, NULL, &crtc_state->dpll)) {
7198 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7202 i8xx_compute_dpll(crtc, crtc_state, NULL);
7207 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7208 struct intel_crtc_state *crtc_state)
7210 struct drm_device *dev = crtc->base.dev;
7211 struct drm_i915_private *dev_priv = to_i915(dev);
7212 const struct intel_limit *limit;
7215 memset(&crtc_state->dpll_hw_state, 0,
7216 sizeof(crtc_state->dpll_hw_state));
7218 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7219 if (intel_panel_use_ssc(dev_priv)) {
7220 refclk = dev_priv->vbt.lvds_ssc_freq;
7221 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7224 if (intel_is_dual_link_lvds(dev))
7225 limit = &intel_limits_g4x_dual_channel_lvds;
7227 limit = &intel_limits_g4x_single_channel_lvds;
7228 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7229 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7230 limit = &intel_limits_g4x_hdmi;
7231 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7232 limit = &intel_limits_g4x_sdvo;
7234 /* The option is for other outputs */
7235 limit = &intel_limits_i9xx_sdvo;
7238 if (!crtc_state->clock_set &&
7239 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7240 refclk, NULL, &crtc_state->dpll)) {
7241 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7245 i9xx_compute_dpll(crtc, crtc_state, NULL);
7250 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7251 struct intel_crtc_state *crtc_state)
7253 struct drm_device *dev = crtc->base.dev;
7254 struct drm_i915_private *dev_priv = to_i915(dev);
7255 const struct intel_limit *limit;
7258 memset(&crtc_state->dpll_hw_state, 0,
7259 sizeof(crtc_state->dpll_hw_state));
7261 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7262 if (intel_panel_use_ssc(dev_priv)) {
7263 refclk = dev_priv->vbt.lvds_ssc_freq;
7264 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7267 limit = &intel_limits_pineview_lvds;
7269 limit = &intel_limits_pineview_sdvo;
7272 if (!crtc_state->clock_set &&
7273 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7274 refclk, NULL, &crtc_state->dpll)) {
7275 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7279 i9xx_compute_dpll(crtc, crtc_state, NULL);
7284 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7285 struct intel_crtc_state *crtc_state)
7287 struct drm_device *dev = crtc->base.dev;
7288 struct drm_i915_private *dev_priv = to_i915(dev);
7289 const struct intel_limit *limit;
7292 memset(&crtc_state->dpll_hw_state, 0,
7293 sizeof(crtc_state->dpll_hw_state));
7295 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7296 if (intel_panel_use_ssc(dev_priv)) {
7297 refclk = dev_priv->vbt.lvds_ssc_freq;
7298 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7301 limit = &intel_limits_i9xx_lvds;
7303 limit = &intel_limits_i9xx_sdvo;
7306 if (!crtc_state->clock_set &&
7307 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7308 refclk, NULL, &crtc_state->dpll)) {
7309 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7313 i9xx_compute_dpll(crtc, crtc_state, NULL);
7318 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7319 struct intel_crtc_state *crtc_state)
7321 int refclk = 100000;
7322 const struct intel_limit *limit = &intel_limits_chv;
7324 memset(&crtc_state->dpll_hw_state, 0,
7325 sizeof(crtc_state->dpll_hw_state));
7327 if (!crtc_state->clock_set &&
7328 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7329 refclk, NULL, &crtc_state->dpll)) {
7330 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7334 chv_compute_dpll(crtc, crtc_state);
7339 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7340 struct intel_crtc_state *crtc_state)
7342 int refclk = 100000;
7343 const struct intel_limit *limit = &intel_limits_vlv;
7345 memset(&crtc_state->dpll_hw_state, 0,
7346 sizeof(crtc_state->dpll_hw_state));
7348 if (!crtc_state->clock_set &&
7349 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7350 refclk, NULL, &crtc_state->dpll)) {
7351 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7355 vlv_compute_dpll(crtc, crtc_state);
7360 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7361 struct intel_crtc_state *pipe_config)
7363 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7366 if (INTEL_GEN(dev_priv) <= 3 &&
7367 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7370 tmp = I915_READ(PFIT_CONTROL);
7371 if (!(tmp & PFIT_ENABLE))
7374 /* Check whether the pfit is attached to our pipe. */
7375 if (INTEL_GEN(dev_priv) < 4) {
7376 if (crtc->pipe != PIPE_B)
7379 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7383 pipe_config->gmch_pfit.control = tmp;
7384 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7387 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7388 struct intel_crtc_state *pipe_config)
7390 struct drm_device *dev = crtc->base.dev;
7391 struct drm_i915_private *dev_priv = to_i915(dev);
7392 int pipe = pipe_config->cpu_transcoder;
7395 int refclk = 100000;
7397 /* In case of DSI, DPLL will not be used */
7398 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7401 mutex_lock(&dev_priv->sb_lock);
7402 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7403 mutex_unlock(&dev_priv->sb_lock);
7405 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7406 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7407 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7408 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7409 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7411 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7415 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7416 struct intel_initial_plane_config *plane_config)
7418 struct drm_device *dev = crtc->base.dev;
7419 struct drm_i915_private *dev_priv = to_i915(dev);
7420 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7421 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7422 enum pipe pipe = crtc->pipe;
7423 u32 val, base, offset;
7424 int fourcc, pixel_format;
7425 unsigned int aligned_height;
7426 struct drm_framebuffer *fb;
7427 struct intel_framebuffer *intel_fb;
7429 if (!plane->get_hw_state(plane))
7432 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7434 DRM_DEBUG_KMS("failed to alloc fb\n");
7438 fb = &intel_fb->base;
7442 val = I915_READ(DSPCNTR(i9xx_plane));
7444 if (INTEL_GEN(dev_priv) >= 4) {
7445 if (val & DISPPLANE_TILED) {
7446 plane_config->tiling = I915_TILING_X;
7447 fb->modifier = I915_FORMAT_MOD_X_TILED;
7451 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7452 fourcc = i9xx_format_to_fourcc(pixel_format);
7453 fb->format = drm_format_info(fourcc);
7455 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7456 offset = I915_READ(DSPOFFSET(i9xx_plane));
7457 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7458 } else if (INTEL_GEN(dev_priv) >= 4) {
7459 if (plane_config->tiling)
7460 offset = I915_READ(DSPTILEOFF(i9xx_plane));
7462 offset = I915_READ(DSPLINOFF(i9xx_plane));
7463 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7465 base = I915_READ(DSPADDR(i9xx_plane));
7467 plane_config->base = base;
7469 val = I915_READ(PIPESRC(pipe));
7470 fb->width = ((val >> 16) & 0xfff) + 1;
7471 fb->height = ((val >> 0) & 0xfff) + 1;
7473 val = I915_READ(DSPSTRIDE(i9xx_plane));
7474 fb->pitches[0] = val & 0xffffffc0;
7476 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7478 plane_config->size = fb->pitches[0] * aligned_height;
7480 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7481 crtc->base.name, plane->base.name, fb->width, fb->height,
7482 fb->format->cpp[0] * 8, base, fb->pitches[0],
7483 plane_config->size);
7485 plane_config->fb = intel_fb;
7488 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7489 struct intel_crtc_state *pipe_config)
7491 struct drm_device *dev = crtc->base.dev;
7492 struct drm_i915_private *dev_priv = to_i915(dev);
7493 int pipe = pipe_config->cpu_transcoder;
7494 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7496 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7497 int refclk = 100000;
7499 /* In case of DSI, DPLL will not be used */
7500 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7503 mutex_lock(&dev_priv->sb_lock);
7504 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7505 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7506 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7507 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7508 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7509 mutex_unlock(&dev_priv->sb_lock);
7511 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7512 clock.m2 = (pll_dw0 & 0xff) << 22;
7513 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7514 clock.m2 |= pll_dw2 & 0x3fffff;
7515 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7516 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7517 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7519 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7522 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7523 struct intel_crtc_state *pipe_config)
7525 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7526 enum intel_display_power_domain power_domain;
7530 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7531 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7534 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7535 pipe_config->shared_dpll = NULL;
7539 tmp = I915_READ(PIPECONF(crtc->pipe));
7540 if (!(tmp & PIPECONF_ENABLE))
7543 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7544 IS_CHERRYVIEW(dev_priv)) {
7545 switch (tmp & PIPECONF_BPC_MASK) {
7547 pipe_config->pipe_bpp = 18;
7550 pipe_config->pipe_bpp = 24;
7552 case PIPECONF_10BPC:
7553 pipe_config->pipe_bpp = 30;
7560 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7561 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7562 pipe_config->limited_color_range = true;
7564 if (INTEL_GEN(dev_priv) < 4)
7565 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7567 intel_get_pipe_timings(crtc, pipe_config);
7568 intel_get_pipe_src_size(crtc, pipe_config);
7570 i9xx_get_pfit_config(crtc, pipe_config);
7572 if (INTEL_GEN(dev_priv) >= 4) {
7573 /* No way to read it out on pipes B and C */
7574 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
7575 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7577 tmp = I915_READ(DPLL_MD(crtc->pipe));
7578 pipe_config->pixel_multiplier =
7579 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7580 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
7581 pipe_config->dpll_hw_state.dpll_md = tmp;
7582 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7583 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7584 tmp = I915_READ(DPLL(crtc->pipe));
7585 pipe_config->pixel_multiplier =
7586 ((tmp & SDVO_MULTIPLIER_MASK)
7587 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7589 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7590 * port and will be fixed up in the encoder->get_config
7592 pipe_config->pixel_multiplier = 1;
7594 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
7595 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
7597 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7598 * on 830. Filter it out here so that we don't
7599 * report errors due to that.
7601 if (IS_I830(dev_priv))
7602 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
7604 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
7605 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
7607 /* Mask out read-only status bits. */
7608 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7609 DPLL_PORTC_READY_MASK |
7610 DPLL_PORTB_READY_MASK);
7613 if (IS_CHERRYVIEW(dev_priv))
7614 chv_crtc_clock_get(crtc, pipe_config);
7615 else if (IS_VALLEYVIEW(dev_priv))
7616 vlv_crtc_clock_get(crtc, pipe_config);
7618 i9xx_crtc_clock_get(crtc, pipe_config);
7621 * Normally the dotclock is filled in by the encoder .get_config()
7622 * but in case the pipe is enabled w/o any ports we need a sane
7625 pipe_config->base.adjusted_mode.crtc_clock =
7626 pipe_config->port_clock / pipe_config->pixel_multiplier;
7631 intel_display_power_put(dev_priv, power_domain);
7636 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
7638 struct intel_encoder *encoder;
7641 bool has_lvds = false;
7642 bool has_cpu_edp = false;
7643 bool has_panel = false;
7644 bool has_ck505 = false;
7645 bool can_ssc = false;
7646 bool using_ssc_source = false;
7648 /* We need to take the global config into account */
7649 for_each_intel_encoder(&dev_priv->drm, encoder) {
7650 switch (encoder->type) {
7651 case INTEL_OUTPUT_LVDS:
7655 case INTEL_OUTPUT_EDP:
7657 if (encoder->port == PORT_A)
7665 if (HAS_PCH_IBX(dev_priv)) {
7666 has_ck505 = dev_priv->vbt.display_clock_mode;
7667 can_ssc = has_ck505;
7673 /* Check if any DPLLs are using the SSC source */
7674 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
7675 u32 temp = I915_READ(PCH_DPLL(i));
7677 if (!(temp & DPLL_VCO_ENABLE))
7680 if ((temp & PLL_REF_INPUT_MASK) ==
7681 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
7682 using_ssc_source = true;
7687 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7688 has_panel, has_lvds, has_ck505, using_ssc_source);
7690 /* Ironlake: try to setup display ref clock before DPLL
7691 * enabling. This is only under driver's control after
7692 * PCH B stepping, previous chipset stepping should be
7693 * ignoring this setting.
7695 val = I915_READ(PCH_DREF_CONTROL);
7697 /* As we must carefully and slowly disable/enable each source in turn,
7698 * compute the final state we want first and check if we need to
7699 * make any changes at all.
7702 final &= ~DREF_NONSPREAD_SOURCE_MASK;
7704 final |= DREF_NONSPREAD_CK505_ENABLE;
7706 final |= DREF_NONSPREAD_SOURCE_ENABLE;
7708 final &= ~DREF_SSC_SOURCE_MASK;
7709 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7710 final &= ~DREF_SSC1_ENABLE;
7713 final |= DREF_SSC_SOURCE_ENABLE;
7715 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7716 final |= DREF_SSC1_ENABLE;
7719 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7720 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7722 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7724 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7725 } else if (using_ssc_source) {
7726 final |= DREF_SSC_SOURCE_ENABLE;
7727 final |= DREF_SSC1_ENABLE;
7733 /* Always enable nonspread source */
7734 val &= ~DREF_NONSPREAD_SOURCE_MASK;
7737 val |= DREF_NONSPREAD_CK505_ENABLE;
7739 val |= DREF_NONSPREAD_SOURCE_ENABLE;
7742 val &= ~DREF_SSC_SOURCE_MASK;
7743 val |= DREF_SSC_SOURCE_ENABLE;
7745 /* SSC must be turned on before enabling the CPU output */
7746 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
7747 DRM_DEBUG_KMS("Using SSC on panel\n");
7748 val |= DREF_SSC1_ENABLE;
7750 val &= ~DREF_SSC1_ENABLE;
7752 /* Get SSC going before enabling the outputs */
7753 I915_WRITE(PCH_DREF_CONTROL, val);
7754 POSTING_READ(PCH_DREF_CONTROL);
7757 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7759 /* Enable CPU source on CPU attached eDP */
7761 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
7762 DRM_DEBUG_KMS("Using SSC on eDP\n");
7763 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7765 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7767 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7769 I915_WRITE(PCH_DREF_CONTROL, val);
7770 POSTING_READ(PCH_DREF_CONTROL);
7773 DRM_DEBUG_KMS("Disabling CPU source output\n");
7775 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7777 /* Turn off CPU output */
7778 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7780 I915_WRITE(PCH_DREF_CONTROL, val);
7781 POSTING_READ(PCH_DREF_CONTROL);
7784 if (!using_ssc_source) {
7785 DRM_DEBUG_KMS("Disabling SSC source\n");
7787 /* Turn off the SSC source */
7788 val &= ~DREF_SSC_SOURCE_MASK;
7789 val |= DREF_SSC_SOURCE_DISABLE;
7792 val &= ~DREF_SSC1_ENABLE;
7794 I915_WRITE(PCH_DREF_CONTROL, val);
7795 POSTING_READ(PCH_DREF_CONTROL);
7800 BUG_ON(val != final);
7803 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
7807 tmp = I915_READ(SOUTH_CHICKEN2);
7808 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
7809 I915_WRITE(SOUTH_CHICKEN2, tmp);
7811 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
7812 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
7813 DRM_ERROR("FDI mPHY reset assert timeout\n");
7815 tmp = I915_READ(SOUTH_CHICKEN2);
7816 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
7817 I915_WRITE(SOUTH_CHICKEN2, tmp);
7819 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
7820 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
7821 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
7824 /* WaMPhyProgramming:hsw */
7825 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
7829 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
7830 tmp &= ~(0xFF << 24);
7831 tmp |= (0x12 << 24);
7832 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
7834 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
7836 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
7838 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
7840 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
7842 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
7843 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
7844 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
7846 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
7847 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
7848 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
7850 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
7853 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
7855 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
7858 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
7860 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
7863 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
7865 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
7868 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
7870 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
7871 tmp &= ~(0xFF << 16);
7872 tmp |= (0x1C << 16);
7873 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
7875 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
7876 tmp &= ~(0xFF << 16);
7877 tmp |= (0x1C << 16);
7878 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
7880 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
7882 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
7884 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
7886 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
7888 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
7889 tmp &= ~(0xF << 28);
7891 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
7893 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
7894 tmp &= ~(0xF << 28);
7896 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
7899 /* Implements 3 different sequences from BSpec chapter "Display iCLK
7900 * Programming" based on the parameters passed:
7901 * - Sequence to enable CLKOUT_DP
7902 * - Sequence to enable CLKOUT_DP without spread
7903 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
7905 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
7906 bool with_spread, bool with_fdi)
7910 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
7912 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
7913 with_fdi, "LP PCH doesn't have FDI\n"))
7916 mutex_lock(&dev_priv->sb_lock);
7918 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
7919 tmp &= ~SBI_SSCCTL_DISABLE;
7920 tmp |= SBI_SSCCTL_PATHALT;
7921 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
7926 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
7927 tmp &= ~SBI_SSCCTL_PATHALT;
7928 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
7931 lpt_reset_fdi_mphy(dev_priv);
7932 lpt_program_fdi_mphy(dev_priv);
7936 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
7937 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
7938 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
7939 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
7941 mutex_unlock(&dev_priv->sb_lock);
7944 /* Sequence to disable CLKOUT_DP */
7945 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
7949 mutex_lock(&dev_priv->sb_lock);
7951 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
7952 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
7953 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
7954 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
7956 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
7957 if (!(tmp & SBI_SSCCTL_DISABLE)) {
7958 if (!(tmp & SBI_SSCCTL_PATHALT)) {
7959 tmp |= SBI_SSCCTL_PATHALT;
7960 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
7963 tmp |= SBI_SSCCTL_DISABLE;
7964 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
7967 mutex_unlock(&dev_priv->sb_lock);
7970 #define BEND_IDX(steps) ((50 + (steps)) / 5)
7972 static const uint16_t sscdivintphase[] = {
7973 [BEND_IDX( 50)] = 0x3B23,
7974 [BEND_IDX( 45)] = 0x3B23,
7975 [BEND_IDX( 40)] = 0x3C23,
7976 [BEND_IDX( 35)] = 0x3C23,
7977 [BEND_IDX( 30)] = 0x3D23,
7978 [BEND_IDX( 25)] = 0x3D23,
7979 [BEND_IDX( 20)] = 0x3E23,
7980 [BEND_IDX( 15)] = 0x3E23,
7981 [BEND_IDX( 10)] = 0x3F23,
7982 [BEND_IDX( 5)] = 0x3F23,
7983 [BEND_IDX( 0)] = 0x0025,
7984 [BEND_IDX( -5)] = 0x0025,
7985 [BEND_IDX(-10)] = 0x0125,
7986 [BEND_IDX(-15)] = 0x0125,
7987 [BEND_IDX(-20)] = 0x0225,
7988 [BEND_IDX(-25)] = 0x0225,
7989 [BEND_IDX(-30)] = 0x0325,
7990 [BEND_IDX(-35)] = 0x0325,
7991 [BEND_IDX(-40)] = 0x0425,
7992 [BEND_IDX(-45)] = 0x0425,
7993 [BEND_IDX(-50)] = 0x0525,
7998 * steps -50 to 50 inclusive, in steps of 5
7999 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8000 * change in clock period = -(steps / 10) * 5.787 ps
8002 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8005 int idx = BEND_IDX(steps);
8007 if (WARN_ON(steps % 5 != 0))
8010 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8013 mutex_lock(&dev_priv->sb_lock);
8015 if (steps % 10 != 0)
8019 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8021 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8023 tmp |= sscdivintphase[idx];
8024 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8026 mutex_unlock(&dev_priv->sb_lock);
8031 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8033 struct intel_encoder *encoder;
8034 bool has_vga = false;
8036 for_each_intel_encoder(&dev_priv->drm, encoder) {
8037 switch (encoder->type) {
8038 case INTEL_OUTPUT_ANALOG:
8047 lpt_bend_clkout_dp(dev_priv, 0);
8048 lpt_enable_clkout_dp(dev_priv, true, true);
8050 lpt_disable_clkout_dp(dev_priv);
8055 * Initialize reference clocks when the driver loads
8057 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8059 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8060 ironlake_init_pch_refclk(dev_priv);
8061 else if (HAS_PCH_LPT(dev_priv))
8062 lpt_init_pch_refclk(dev_priv);
8065 static void ironlake_set_pipeconf(struct drm_crtc *crtc)
8067 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8068 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8069 int pipe = intel_crtc->pipe;
8074 switch (intel_crtc->config->pipe_bpp) {
8076 val |= PIPECONF_6BPC;
8079 val |= PIPECONF_8BPC;
8082 val |= PIPECONF_10BPC;
8085 val |= PIPECONF_12BPC;
8088 /* Case prevented by intel_choose_pipe_bpp_dither. */
8092 if (intel_crtc->config->dither)
8093 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8095 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8096 val |= PIPECONF_INTERLACED_ILK;
8098 val |= PIPECONF_PROGRESSIVE;
8100 if (intel_crtc->config->limited_color_range)
8101 val |= PIPECONF_COLOR_RANGE_SELECT;
8103 I915_WRITE(PIPECONF(pipe), val);
8104 POSTING_READ(PIPECONF(pipe));
8107 static void haswell_set_pipeconf(struct drm_crtc *crtc)
8109 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8110 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8111 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
8114 if (IS_HASWELL(dev_priv) && intel_crtc->config->dither)
8115 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8117 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8118 val |= PIPECONF_INTERLACED_ILK;
8120 val |= PIPECONF_PROGRESSIVE;
8122 I915_WRITE(PIPECONF(cpu_transcoder), val);
8123 POSTING_READ(PIPECONF(cpu_transcoder));
8126 static void haswell_set_pipemisc(struct drm_crtc *crtc)
8128 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8129 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8130 struct intel_crtc_state *config = intel_crtc->config;
8132 if (IS_BROADWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 9) {
8135 switch (intel_crtc->config->pipe_bpp) {
8137 val |= PIPEMISC_DITHER_6_BPC;
8140 val |= PIPEMISC_DITHER_8_BPC;
8143 val |= PIPEMISC_DITHER_10_BPC;
8146 val |= PIPEMISC_DITHER_12_BPC;
8149 /* Case prevented by pipe_config_set_bpp. */
8153 if (intel_crtc->config->dither)
8154 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8156 if (config->ycbcr420) {
8157 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV |
8158 PIPEMISC_YUV420_ENABLE |
8159 PIPEMISC_YUV420_MODE_FULL_BLEND;
8162 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8166 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8169 * Account for spread spectrum to avoid
8170 * oversubscribing the link. Max center spread
8171 * is 2.5%; use 5% for safety's sake.
8173 u32 bps = target_clock * bpp * 21 / 20;
8174 return DIV_ROUND_UP(bps, link_bw * 8);
8177 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8179 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8182 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8183 struct intel_crtc_state *crtc_state,
8184 struct dpll *reduced_clock)
8186 struct drm_crtc *crtc = &intel_crtc->base;
8187 struct drm_device *dev = crtc->dev;
8188 struct drm_i915_private *dev_priv = to_i915(dev);
8192 /* Enable autotuning of the PLL clock (if permissible) */
8194 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8195 if ((intel_panel_use_ssc(dev_priv) &&
8196 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8197 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8199 } else if (crtc_state->sdvo_tv_clock)
8202 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8204 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8207 if (reduced_clock) {
8208 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8210 if (reduced_clock->m < factor * reduced_clock->n)
8218 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8219 dpll |= DPLLB_MODE_LVDS;
8221 dpll |= DPLLB_MODE_DAC_SERIAL;
8223 dpll |= (crtc_state->pixel_multiplier - 1)
8224 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8226 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8227 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8228 dpll |= DPLL_SDVO_HIGH_SPEED;
8230 if (intel_crtc_has_dp_encoder(crtc_state))
8231 dpll |= DPLL_SDVO_HIGH_SPEED;
8234 * The high speed IO clock is only really required for
8235 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8236 * possible to share the DPLL between CRT and HDMI. Enabling
8237 * the clock needlessly does no real harm, except use up a
8238 * bit of power potentially.
8240 * We'll limit this to IVB with 3 pipes, since it has only two
8241 * DPLLs and so DPLL sharing is the only way to get three pipes
8242 * driving PCH ports at the same time. On SNB we could do this,
8243 * and potentially avoid enabling the second DPLL, but it's not
8244 * clear if it''s a win or loss power wise. No point in doing
8245 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8247 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8248 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8249 dpll |= DPLL_SDVO_HIGH_SPEED;
8251 /* compute bitmask from p1 value */
8252 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8254 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8256 switch (crtc_state->dpll.p2) {
8258 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8261 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8264 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8267 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8271 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8272 intel_panel_use_ssc(dev_priv))
8273 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8275 dpll |= PLL_REF_INPUT_DREFCLK;
8277 dpll |= DPLL_VCO_ENABLE;
8279 crtc_state->dpll_hw_state.dpll = dpll;
8280 crtc_state->dpll_hw_state.fp0 = fp;
8281 crtc_state->dpll_hw_state.fp1 = fp2;
8284 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8285 struct intel_crtc_state *crtc_state)
8287 struct drm_device *dev = crtc->base.dev;
8288 struct drm_i915_private *dev_priv = to_i915(dev);
8289 const struct intel_limit *limit;
8290 int refclk = 120000;
8292 memset(&crtc_state->dpll_hw_state, 0,
8293 sizeof(crtc_state->dpll_hw_state));
8295 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8296 if (!crtc_state->has_pch_encoder)
8299 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8300 if (intel_panel_use_ssc(dev_priv)) {
8301 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8302 dev_priv->vbt.lvds_ssc_freq);
8303 refclk = dev_priv->vbt.lvds_ssc_freq;
8306 if (intel_is_dual_link_lvds(dev)) {
8307 if (refclk == 100000)
8308 limit = &intel_limits_ironlake_dual_lvds_100m;
8310 limit = &intel_limits_ironlake_dual_lvds;
8312 if (refclk == 100000)
8313 limit = &intel_limits_ironlake_single_lvds_100m;
8315 limit = &intel_limits_ironlake_single_lvds;
8318 limit = &intel_limits_ironlake_dac;
8321 if (!crtc_state->clock_set &&
8322 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8323 refclk, NULL, &crtc_state->dpll)) {
8324 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8328 ironlake_compute_dpll(crtc, crtc_state, NULL);
8330 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8331 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8332 pipe_name(crtc->pipe));
8339 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8340 struct intel_link_m_n *m_n)
8342 struct drm_device *dev = crtc->base.dev;
8343 struct drm_i915_private *dev_priv = to_i915(dev);
8344 enum pipe pipe = crtc->pipe;
8346 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8347 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8348 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8350 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8351 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8352 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8355 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8356 enum transcoder transcoder,
8357 struct intel_link_m_n *m_n,
8358 struct intel_link_m_n *m2_n2)
8360 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8361 enum pipe pipe = crtc->pipe;
8363 if (INTEL_GEN(dev_priv) >= 5) {
8364 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8365 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8366 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8368 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8369 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8370 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8371 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8372 * gen < 8) and if DRRS is supported (to make sure the
8373 * registers are not unnecessarily read).
8375 if (m2_n2 && INTEL_GEN(dev_priv) < 8 &&
8376 crtc->config->has_drrs) {
8377 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8378 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8379 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8381 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8382 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8383 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8386 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8387 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8388 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8390 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8391 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8392 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8396 void intel_dp_get_m_n(struct intel_crtc *crtc,
8397 struct intel_crtc_state *pipe_config)
8399 if (pipe_config->has_pch_encoder)
8400 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8402 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8403 &pipe_config->dp_m_n,
8404 &pipe_config->dp_m2_n2);
8407 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8408 struct intel_crtc_state *pipe_config)
8410 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8411 &pipe_config->fdi_m_n, NULL);
8414 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8415 struct intel_crtc_state *pipe_config)
8417 struct drm_device *dev = crtc->base.dev;
8418 struct drm_i915_private *dev_priv = to_i915(dev);
8419 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8420 uint32_t ps_ctrl = 0;
8424 /* find scaler attached to this pipe */
8425 for (i = 0; i < crtc->num_scalers; i++) {
8426 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8427 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8429 pipe_config->pch_pfit.enabled = true;
8430 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8431 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8436 scaler_state->scaler_id = id;
8438 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8440 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8445 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8446 struct intel_initial_plane_config *plane_config)
8448 struct drm_device *dev = crtc->base.dev;
8449 struct drm_i915_private *dev_priv = to_i915(dev);
8450 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8451 enum plane_id plane_id = plane->id;
8452 enum pipe pipe = crtc->pipe;
8453 u32 val, base, offset, stride_mult, tiling, alpha;
8454 int fourcc, pixel_format;
8455 unsigned int aligned_height;
8456 struct drm_framebuffer *fb;
8457 struct intel_framebuffer *intel_fb;
8459 if (!plane->get_hw_state(plane))
8462 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8464 DRM_DEBUG_KMS("failed to alloc fb\n");
8468 fb = &intel_fb->base;
8472 val = I915_READ(PLANE_CTL(pipe, plane_id));
8474 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8476 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8477 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
8478 alpha &= PLANE_COLOR_ALPHA_MASK;
8480 alpha = val & PLANE_CTL_ALPHA_MASK;
8483 fourcc = skl_format_to_fourcc(pixel_format,
8484 val & PLANE_CTL_ORDER_RGBX, alpha);
8485 fb->format = drm_format_info(fourcc);
8487 tiling = val & PLANE_CTL_TILED_MASK;
8489 case PLANE_CTL_TILED_LINEAR:
8490 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8492 case PLANE_CTL_TILED_X:
8493 plane_config->tiling = I915_TILING_X;
8494 fb->modifier = I915_FORMAT_MOD_X_TILED;
8496 case PLANE_CTL_TILED_Y:
8497 if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
8498 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8500 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8502 case PLANE_CTL_TILED_YF:
8503 if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
8504 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8506 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8509 MISSING_CASE(tiling);
8513 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8514 plane_config->base = base;
8516 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
8518 val = I915_READ(PLANE_SIZE(pipe, plane_id));
8519 fb->height = ((val >> 16) & 0xfff) + 1;
8520 fb->width = ((val >> 0) & 0x1fff) + 1;
8522 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
8523 stride_mult = intel_fb_stride_alignment(fb, 0);
8524 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8526 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8528 plane_config->size = fb->pitches[0] * aligned_height;
8530 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8531 crtc->base.name, plane->base.name, fb->width, fb->height,
8532 fb->format->cpp[0] * 8, base, fb->pitches[0],
8533 plane_config->size);
8535 plane_config->fb = intel_fb;
8542 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
8543 struct intel_crtc_state *pipe_config)
8545 struct drm_device *dev = crtc->base.dev;
8546 struct drm_i915_private *dev_priv = to_i915(dev);
8549 tmp = I915_READ(PF_CTL(crtc->pipe));
8551 if (tmp & PF_ENABLE) {
8552 pipe_config->pch_pfit.enabled = true;
8553 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8554 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
8556 /* We currently do not free assignements of panel fitters on
8557 * ivb/hsw (since we don't use the higher upscaling modes which
8558 * differentiates them) so just WARN about this case for now. */
8559 if (IS_GEN7(dev_priv)) {
8560 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
8561 PF_PIPE_SEL_IVB(crtc->pipe));
8566 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
8567 struct intel_crtc_state *pipe_config)
8569 struct drm_device *dev = crtc->base.dev;
8570 struct drm_i915_private *dev_priv = to_i915(dev);
8571 enum intel_display_power_domain power_domain;
8575 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8576 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
8579 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8580 pipe_config->shared_dpll = NULL;
8583 tmp = I915_READ(PIPECONF(crtc->pipe));
8584 if (!(tmp & PIPECONF_ENABLE))
8587 switch (tmp & PIPECONF_BPC_MASK) {
8589 pipe_config->pipe_bpp = 18;
8592 pipe_config->pipe_bpp = 24;
8594 case PIPECONF_10BPC:
8595 pipe_config->pipe_bpp = 30;
8597 case PIPECONF_12BPC:
8598 pipe_config->pipe_bpp = 36;
8604 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8605 pipe_config->limited_color_range = true;
8607 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
8608 struct intel_shared_dpll *pll;
8609 enum intel_dpll_id pll_id;
8611 pipe_config->has_pch_encoder = true;
8613 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
8614 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8615 FDI_DP_PORT_WIDTH_SHIFT) + 1;
8617 ironlake_get_fdi_m_n_config(crtc, pipe_config);
8619 if (HAS_PCH_IBX(dev_priv)) {
8621 * The pipe->pch transcoder and pch transcoder->pll
8624 pll_id = (enum intel_dpll_id) crtc->pipe;
8626 tmp = I915_READ(PCH_DPLL_SEL);
8627 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
8628 pll_id = DPLL_ID_PCH_PLL_B;
8630 pll_id= DPLL_ID_PCH_PLL_A;
8633 pipe_config->shared_dpll =
8634 intel_get_shared_dpll_by_id(dev_priv, pll_id);
8635 pll = pipe_config->shared_dpll;
8637 WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll,
8638 &pipe_config->dpll_hw_state));
8640 tmp = pipe_config->dpll_hw_state.dpll;
8641 pipe_config->pixel_multiplier =
8642 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
8643 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
8645 ironlake_pch_clock_get(crtc, pipe_config);
8647 pipe_config->pixel_multiplier = 1;
8650 intel_get_pipe_timings(crtc, pipe_config);
8651 intel_get_pipe_src_size(crtc, pipe_config);
8653 ironlake_get_pfit_config(crtc, pipe_config);
8658 intel_display_power_put(dev_priv, power_domain);
8663 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
8665 struct drm_device *dev = &dev_priv->drm;
8666 struct intel_crtc *crtc;
8668 for_each_intel_crtc(dev, crtc)
8669 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
8670 pipe_name(crtc->pipe));
8672 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)),
8673 "Display power well on\n");
8674 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
8675 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
8676 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
8677 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
8678 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
8679 "CPU PWM1 enabled\n");
8680 if (IS_HASWELL(dev_priv))
8681 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
8682 "CPU PWM2 enabled\n");
8683 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
8684 "PCH PWM1 enabled\n");
8685 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
8686 "Utility pin enabled\n");
8687 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
8690 * In theory we can still leave IRQs enabled, as long as only the HPD
8691 * interrupts remain enabled. We used to check for that, but since it's
8692 * gen-specific and since we only disable LCPLL after we fully disable
8693 * the interrupts, the check below should be enough.
8695 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
8698 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
8700 if (IS_HASWELL(dev_priv))
8701 return I915_READ(D_COMP_HSW);
8703 return I915_READ(D_COMP_BDW);
8706 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
8708 if (IS_HASWELL(dev_priv)) {
8709 mutex_lock(&dev_priv->pcu_lock);
8710 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
8712 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8713 mutex_unlock(&dev_priv->pcu_lock);
8715 I915_WRITE(D_COMP_BDW, val);
8716 POSTING_READ(D_COMP_BDW);
8721 * This function implements pieces of two sequences from BSpec:
8722 * - Sequence for display software to disable LCPLL
8723 * - Sequence for display software to allow package C8+
8724 * The steps implemented here are just the steps that actually touch the LCPLL
8725 * register. Callers should take care of disabling all the display engine
8726 * functions, doing the mode unset, fixing interrupts, etc.
8728 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
8729 bool switch_to_fclk, bool allow_power_down)
8733 assert_can_disable_lcpll(dev_priv);
8735 val = I915_READ(LCPLL_CTL);
8737 if (switch_to_fclk) {
8738 val |= LCPLL_CD_SOURCE_FCLK;
8739 I915_WRITE(LCPLL_CTL, val);
8741 if (wait_for_us(I915_READ(LCPLL_CTL) &
8742 LCPLL_CD_SOURCE_FCLK_DONE, 1))
8743 DRM_ERROR("Switching to FCLK failed\n");
8745 val = I915_READ(LCPLL_CTL);
8748 val |= LCPLL_PLL_DISABLE;
8749 I915_WRITE(LCPLL_CTL, val);
8750 POSTING_READ(LCPLL_CTL);
8752 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
8753 DRM_ERROR("LCPLL still locked\n");
8755 val = hsw_read_dcomp(dev_priv);
8756 val |= D_COMP_COMP_DISABLE;
8757 hsw_write_dcomp(dev_priv, val);
8760 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
8762 DRM_ERROR("D_COMP RCOMP still in progress\n");
8764 if (allow_power_down) {
8765 val = I915_READ(LCPLL_CTL);
8766 val |= LCPLL_POWER_DOWN_ALLOW;
8767 I915_WRITE(LCPLL_CTL, val);
8768 POSTING_READ(LCPLL_CTL);
8773 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8776 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
8780 val = I915_READ(LCPLL_CTL);
8782 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
8783 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
8787 * Make sure we're not on PC8 state before disabling PC8, otherwise
8788 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8790 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
8792 if (val & LCPLL_POWER_DOWN_ALLOW) {
8793 val &= ~LCPLL_POWER_DOWN_ALLOW;
8794 I915_WRITE(LCPLL_CTL, val);
8795 POSTING_READ(LCPLL_CTL);
8798 val = hsw_read_dcomp(dev_priv);
8799 val |= D_COMP_COMP_FORCE;
8800 val &= ~D_COMP_COMP_DISABLE;
8801 hsw_write_dcomp(dev_priv, val);
8803 val = I915_READ(LCPLL_CTL);
8804 val &= ~LCPLL_PLL_DISABLE;
8805 I915_WRITE(LCPLL_CTL, val);
8807 if (intel_wait_for_register(dev_priv,
8808 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
8810 DRM_ERROR("LCPLL not locked yet\n");
8812 if (val & LCPLL_CD_SOURCE_FCLK) {
8813 val = I915_READ(LCPLL_CTL);
8814 val &= ~LCPLL_CD_SOURCE_FCLK;
8815 I915_WRITE(LCPLL_CTL, val);
8817 if (wait_for_us((I915_READ(LCPLL_CTL) &
8818 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
8819 DRM_ERROR("Switching back to LCPLL failed\n");
8822 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
8824 intel_update_cdclk(dev_priv);
8825 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
8829 * Package states C8 and deeper are really deep PC states that can only be
8830 * reached when all the devices on the system allow it, so even if the graphics
8831 * device allows PC8+, it doesn't mean the system will actually get to these
8832 * states. Our driver only allows PC8+ when going into runtime PM.
8834 * The requirements for PC8+ are that all the outputs are disabled, the power
8835 * well is disabled and most interrupts are disabled, and these are also
8836 * requirements for runtime PM. When these conditions are met, we manually do
8837 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
8838 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
8841 * When we really reach PC8 or deeper states (not just when we allow it) we lose
8842 * the state of some registers, so when we come back from PC8+ we need to
8843 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
8844 * need to take care of the registers kept by RC6. Notice that this happens even
8845 * if we don't put the device in PCI D3 state (which is what currently happens
8846 * because of the runtime PM support).
8848 * For more, read "Display Sequences for Package C8" on the hardware
8851 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
8855 DRM_DEBUG_KMS("Enabling package C8+\n");
8857 if (HAS_PCH_LPT_LP(dev_priv)) {
8858 val = I915_READ(SOUTH_DSPCLK_GATE_D);
8859 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
8860 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
8863 lpt_disable_clkout_dp(dev_priv);
8864 hsw_disable_lcpll(dev_priv, true, true);
8867 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
8871 DRM_DEBUG_KMS("Disabling package C8+\n");
8873 hsw_restore_lcpll(dev_priv);
8874 lpt_init_pch_refclk(dev_priv);
8876 if (HAS_PCH_LPT_LP(dev_priv)) {
8877 val = I915_READ(SOUTH_DSPCLK_GATE_D);
8878 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
8879 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
8883 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
8884 struct intel_crtc_state *crtc_state)
8886 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
8887 struct intel_encoder *encoder =
8888 intel_ddi_get_crtc_new_encoder(crtc_state);
8890 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
8891 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8892 pipe_name(crtc->pipe));
8900 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
8902 struct intel_crtc_state *pipe_config)
8904 enum intel_dpll_id id;
8907 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
8908 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
8910 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
8913 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
8916 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
8918 struct intel_crtc_state *pipe_config)
8920 enum intel_dpll_id id;
8924 id = DPLL_ID_SKL_DPLL0;
8927 id = DPLL_ID_SKL_DPLL1;
8930 id = DPLL_ID_SKL_DPLL2;
8933 DRM_ERROR("Incorrect port type\n");
8937 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
8940 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
8942 struct intel_crtc_state *pipe_config)
8944 enum intel_dpll_id id;
8947 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
8948 id = temp >> (port * 3 + 1);
8950 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
8953 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
8956 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
8958 struct intel_crtc_state *pipe_config)
8960 enum intel_dpll_id id;
8961 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
8963 switch (ddi_pll_sel) {
8964 case PORT_CLK_SEL_WRPLL1:
8965 id = DPLL_ID_WRPLL1;
8967 case PORT_CLK_SEL_WRPLL2:
8968 id = DPLL_ID_WRPLL2;
8970 case PORT_CLK_SEL_SPLL:
8973 case PORT_CLK_SEL_LCPLL_810:
8974 id = DPLL_ID_LCPLL_810;
8976 case PORT_CLK_SEL_LCPLL_1350:
8977 id = DPLL_ID_LCPLL_1350;
8979 case PORT_CLK_SEL_LCPLL_2700:
8980 id = DPLL_ID_LCPLL_2700;
8983 MISSING_CASE(ddi_pll_sel);
8985 case PORT_CLK_SEL_NONE:
8989 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
8992 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
8993 struct intel_crtc_state *pipe_config,
8994 u64 *power_domain_mask)
8996 struct drm_device *dev = crtc->base.dev;
8997 struct drm_i915_private *dev_priv = to_i915(dev);
8998 enum intel_display_power_domain power_domain;
9002 * The pipe->transcoder mapping is fixed with the exception of the eDP
9003 * transcoder handled below.
9005 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9008 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9009 * consistency and less surprising code; it's in always on power).
9011 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9012 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9013 enum pipe trans_edp_pipe;
9014 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9016 WARN(1, "unknown pipe linked to edp transcoder\n");
9017 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9018 case TRANS_DDI_EDP_INPUT_A_ON:
9019 trans_edp_pipe = PIPE_A;
9021 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9022 trans_edp_pipe = PIPE_B;
9024 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9025 trans_edp_pipe = PIPE_C;
9029 if (trans_edp_pipe == crtc->pipe)
9030 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9033 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9034 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9036 *power_domain_mask |= BIT_ULL(power_domain);
9038 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9040 return tmp & PIPECONF_ENABLE;
9043 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9044 struct intel_crtc_state *pipe_config,
9045 u64 *power_domain_mask)
9047 struct drm_device *dev = crtc->base.dev;
9048 struct drm_i915_private *dev_priv = to_i915(dev);
9049 enum intel_display_power_domain power_domain;
9051 enum transcoder cpu_transcoder;
9054 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9056 cpu_transcoder = TRANSCODER_DSI_A;
9058 cpu_transcoder = TRANSCODER_DSI_C;
9060 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9061 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9063 *power_domain_mask |= BIT_ULL(power_domain);
9066 * The PLL needs to be enabled with a valid divider
9067 * configuration, otherwise accessing DSI registers will hang
9068 * the machine. See BSpec North Display Engine
9069 * registers/MIPI[BXT]. We can break out here early, since we
9070 * need the same DSI PLL to be enabled for both DSI ports.
9072 if (!intel_dsi_pll_is_enabled(dev_priv))
9075 /* XXX: this works for video mode only */
9076 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9077 if (!(tmp & DPI_ENABLE))
9080 tmp = I915_READ(MIPI_CTRL(port));
9081 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9084 pipe_config->cpu_transcoder = cpu_transcoder;
9088 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9091 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9092 struct intel_crtc_state *pipe_config)
9094 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9095 struct intel_shared_dpll *pll;
9099 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9101 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9103 if (IS_CANNONLAKE(dev_priv))
9104 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9105 else if (IS_GEN9_BC(dev_priv))
9106 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9107 else if (IS_GEN9_LP(dev_priv))
9108 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9110 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9112 pll = pipe_config->shared_dpll;
9114 WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll,
9115 &pipe_config->dpll_hw_state));
9119 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9120 * DDI E. So just check whether this pipe is wired to DDI E and whether
9121 * the PCH transcoder is on.
9123 if (INTEL_GEN(dev_priv) < 9 &&
9124 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9125 pipe_config->has_pch_encoder = true;
9127 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9128 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9129 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9131 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9135 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9136 struct intel_crtc_state *pipe_config)
9138 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9139 enum intel_display_power_domain power_domain;
9140 u64 power_domain_mask;
9143 intel_crtc_init_scalers(crtc, pipe_config);
9145 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9146 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9148 power_domain_mask = BIT_ULL(power_domain);
9150 pipe_config->shared_dpll = NULL;
9152 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9154 if (IS_GEN9_LP(dev_priv) &&
9155 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9163 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9164 haswell_get_ddi_port_state(crtc, pipe_config);
9165 intel_get_pipe_timings(crtc, pipe_config);
9168 intel_get_pipe_src_size(crtc, pipe_config);
9170 pipe_config->gamma_mode =
9171 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9173 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
9174 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
9175 bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV;
9177 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
9178 bool blend_mode_420 = tmp &
9179 PIPEMISC_YUV420_MODE_FULL_BLEND;
9181 pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE;
9182 if (pipe_config->ycbcr420 != clrspace_yuv ||
9183 pipe_config->ycbcr420 != blend_mode_420)
9184 DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp);
9185 } else if (clrspace_yuv) {
9186 DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
9190 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9191 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9192 power_domain_mask |= BIT_ULL(power_domain);
9193 if (INTEL_GEN(dev_priv) >= 9)
9194 skylake_get_pfit_config(crtc, pipe_config);
9196 ironlake_get_pfit_config(crtc, pipe_config);
9199 if (hsw_crtc_supports_ips(crtc)) {
9200 if (IS_HASWELL(dev_priv))
9201 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9204 * We cannot readout IPS state on broadwell, set to
9205 * true so we can set it to a defined state on first
9208 pipe_config->ips_enabled = true;
9212 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9213 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9214 pipe_config->pixel_multiplier =
9215 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9217 pipe_config->pixel_multiplier = 1;
9221 for_each_power_domain(power_domain, power_domain_mask)
9222 intel_display_power_put(dev_priv, power_domain);
9227 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9229 struct drm_i915_private *dev_priv =
9230 to_i915(plane_state->base.plane->dev);
9231 const struct drm_framebuffer *fb = plane_state->base.fb;
9232 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9235 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9236 base = obj->phys_handle->busaddr;
9238 base = intel_plane_ggtt_offset(plane_state);
9240 base += plane_state->main.offset;
9242 /* ILK+ do this automagically */
9243 if (HAS_GMCH_DISPLAY(dev_priv) &&
9244 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9245 base += (plane_state->base.crtc_h *
9246 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9251 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9253 int x = plane_state->base.crtc_x;
9254 int y = plane_state->base.crtc_y;
9258 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9261 pos |= x << CURSOR_X_SHIFT;
9264 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9267 pos |= y << CURSOR_Y_SHIFT;
9272 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9274 const struct drm_mode_config *config =
9275 &plane_state->base.plane->dev->mode_config;
9276 int width = plane_state->base.crtc_w;
9277 int height = plane_state->base.crtc_h;
9279 return width > 0 && width <= config->cursor_width &&
9280 height > 0 && height <= config->cursor_height;
9283 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9284 struct intel_plane_state *plane_state)
9286 const struct drm_framebuffer *fb = plane_state->base.fb;
9291 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9294 DRM_PLANE_HELPER_NO_SCALING,
9295 DRM_PLANE_HELPER_NO_SCALING,
9303 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9304 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9308 src_x = plane_state->base.src_x >> 16;
9309 src_y = plane_state->base.src_y >> 16;
9311 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9312 offset = intel_compute_tile_offset(&src_x, &src_y, plane_state, 0);
9314 if (src_x != 0 || src_y != 0) {
9315 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9319 plane_state->main.offset = offset;
9324 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9325 const struct intel_plane_state *plane_state)
9327 const struct drm_framebuffer *fb = plane_state->base.fb;
9329 return CURSOR_ENABLE |
9330 CURSOR_GAMMA_ENABLE |
9331 CURSOR_FORMAT_ARGB |
9332 CURSOR_STRIDE(fb->pitches[0]);
9335 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9337 int width = plane_state->base.crtc_w;
9340 * 845g/865g are only limited by the width of their cursors,
9341 * the height is arbitrary up to the precision of the register.
9343 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
9346 static int i845_check_cursor(struct intel_plane *plane,
9347 struct intel_crtc_state *crtc_state,
9348 struct intel_plane_state *plane_state)
9350 const struct drm_framebuffer *fb = plane_state->base.fb;
9353 ret = intel_check_cursor(crtc_state, plane_state);
9357 /* if we want to turn off the cursor ignore width and height */
9361 /* Check for which cursor types we support */
9362 if (!i845_cursor_size_ok(plane_state)) {
9363 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9364 plane_state->base.crtc_w,
9365 plane_state->base.crtc_h);
9369 switch (fb->pitches[0]) {
9376 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9381 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9386 static void i845_update_cursor(struct intel_plane *plane,
9387 const struct intel_crtc_state *crtc_state,
9388 const struct intel_plane_state *plane_state)
9390 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9391 u32 cntl = 0, base = 0, pos = 0, size = 0;
9392 unsigned long irqflags;
9394 if (plane_state && plane_state->base.visible) {
9395 unsigned int width = plane_state->base.crtc_w;
9396 unsigned int height = plane_state->base.crtc_h;
9398 cntl = plane_state->ctl;
9399 size = (height << 12) | width;
9401 base = intel_cursor_base(plane_state);
9402 pos = intel_cursor_position(plane_state);
9405 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9407 /* On these chipsets we can only modify the base/size/stride
9408 * whilst the cursor is disabled.
9410 if (plane->cursor.base != base ||
9411 plane->cursor.size != size ||
9412 plane->cursor.cntl != cntl) {
9413 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
9414 I915_WRITE_FW(CURBASE(PIPE_A), base);
9415 I915_WRITE_FW(CURSIZE, size);
9416 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9417 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
9419 plane->cursor.base = base;
9420 plane->cursor.size = size;
9421 plane->cursor.cntl = cntl;
9423 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9426 POSTING_READ_FW(CURCNTR(PIPE_A));
9428 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9431 static void i845_disable_cursor(struct intel_plane *plane,
9432 struct intel_crtc *crtc)
9434 i845_update_cursor(plane, NULL, NULL);
9437 static bool i845_cursor_get_hw_state(struct intel_plane *plane)
9439 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9440 enum intel_display_power_domain power_domain;
9443 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9444 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9447 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9449 intel_display_power_put(dev_priv, power_domain);
9454 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9455 const struct intel_plane_state *plane_state)
9457 struct drm_i915_private *dev_priv =
9458 to_i915(plane_state->base.plane->dev);
9459 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9462 cntl = MCURSOR_GAMMA_ENABLE;
9464 if (HAS_DDI(dev_priv))
9465 cntl |= CURSOR_PIPE_CSC_ENABLE;
9467 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
9469 switch (plane_state->base.crtc_w) {
9471 cntl |= CURSOR_MODE_64_ARGB_AX;
9474 cntl |= CURSOR_MODE_128_ARGB_AX;
9477 cntl |= CURSOR_MODE_256_ARGB_AX;
9480 MISSING_CASE(plane_state->base.crtc_w);
9484 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
9485 cntl |= CURSOR_ROTATE_180;
9490 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
9492 struct drm_i915_private *dev_priv =
9493 to_i915(plane_state->base.plane->dev);
9494 int width = plane_state->base.crtc_w;
9495 int height = plane_state->base.crtc_h;
9497 if (!intel_cursor_size_ok(plane_state))
9500 /* Cursor width is limited to a few power-of-two sizes */
9511 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9512 * height from 8 lines up to the cursor width, when the
9513 * cursor is not rotated. Everything else requires square
9516 if (HAS_CUR_FBC(dev_priv) &&
9517 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
9518 if (height < 8 || height > width)
9521 if (height != width)
9528 static int i9xx_check_cursor(struct intel_plane *plane,
9529 struct intel_crtc_state *crtc_state,
9530 struct intel_plane_state *plane_state)
9532 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9533 const struct drm_framebuffer *fb = plane_state->base.fb;
9534 enum pipe pipe = plane->pipe;
9537 ret = intel_check_cursor(crtc_state, plane_state);
9541 /* if we want to turn off the cursor ignore width and height */
9545 /* Check for which cursor types we support */
9546 if (!i9xx_cursor_size_ok(plane_state)) {
9547 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9548 plane_state->base.crtc_w,
9549 plane_state->base.crtc_h);
9553 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
9554 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9555 fb->pitches[0], plane_state->base.crtc_w);
9560 * There's something wrong with the cursor on CHV pipe C.
9561 * If it straddles the left edge of the screen then
9562 * moving it away from the edge or disabling it often
9563 * results in a pipe underrun, and often that can lead to
9564 * dead pipe (constant underrun reported, and it scans
9565 * out just a solid color). To recover from that, the
9566 * display power well must be turned off and on again.
9567 * Refuse the put the cursor into that compromised position.
9569 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
9570 plane_state->base.visible && plane_state->base.crtc_x < 0) {
9571 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9575 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
9580 static void i9xx_update_cursor(struct intel_plane *plane,
9581 const struct intel_crtc_state *crtc_state,
9582 const struct intel_plane_state *plane_state)
9584 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9585 enum pipe pipe = plane->pipe;
9586 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
9587 unsigned long irqflags;
9589 if (plane_state && plane_state->base.visible) {
9590 cntl = plane_state->ctl;
9592 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
9593 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
9595 base = intel_cursor_base(plane_state);
9596 pos = intel_cursor_position(plane_state);
9599 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9602 * On some platforms writing CURCNTR first will also
9603 * cause CURPOS to be armed by the CURBASE write.
9604 * Without the CURCNTR write the CURPOS write would
9605 * arm itself. Thus we always start the full update
9606 * with a CURCNTR write.
9608 * On other platforms CURPOS always requires the
9609 * CURBASE write to arm the update. Additonally
9610 * a write to any of the cursor register will cancel
9611 * an already armed cursor update. Thus leaving out
9612 * the CURBASE write after CURPOS could lead to a
9613 * cursor that doesn't appear to move, or even change
9614 * shape. Thus we always write CURBASE.
9616 * CURCNTR and CUR_FBC_CTL are always
9617 * armed by the CURBASE write only.
9619 if (plane->cursor.base != base ||
9620 plane->cursor.size != fbc_ctl ||
9621 plane->cursor.cntl != cntl) {
9622 I915_WRITE_FW(CURCNTR(pipe), cntl);
9623 if (HAS_CUR_FBC(dev_priv))
9624 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
9625 I915_WRITE_FW(CURPOS(pipe), pos);
9626 I915_WRITE_FW(CURBASE(pipe), base);
9628 plane->cursor.base = base;
9629 plane->cursor.size = fbc_ctl;
9630 plane->cursor.cntl = cntl;
9632 I915_WRITE_FW(CURPOS(pipe), pos);
9633 I915_WRITE_FW(CURBASE(pipe), base);
9636 POSTING_READ_FW(CURBASE(pipe));
9638 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9641 static void i9xx_disable_cursor(struct intel_plane *plane,
9642 struct intel_crtc *crtc)
9644 i9xx_update_cursor(plane, NULL, NULL);
9647 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane)
9649 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9650 enum intel_display_power_domain power_domain;
9651 enum pipe pipe = plane->pipe;
9655 * Not 100% correct for planes that can move between pipes,
9656 * but that's only the case for gen2-3 which don't have any
9657 * display power wells.
9659 power_domain = POWER_DOMAIN_PIPE(pipe);
9660 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9663 ret = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
9665 intel_display_power_put(dev_priv, power_domain);
9670 /* VESA 640x480x72Hz mode to set on the pipe */
9671 static const struct drm_display_mode load_detect_mode = {
9672 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
9673 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
9676 struct drm_framebuffer *
9677 intel_framebuffer_create(struct drm_i915_gem_object *obj,
9678 struct drm_mode_fb_cmd2 *mode_cmd)
9680 struct intel_framebuffer *intel_fb;
9683 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9685 return ERR_PTR(-ENOMEM);
9687 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
9691 return &intel_fb->base;
9695 return ERR_PTR(ret);
9699 intel_framebuffer_pitch_for_width(int width, int bpp)
9701 u32 pitch = DIV_ROUND_UP(width * bpp, 8);
9702 return ALIGN(pitch, 64);
9706 intel_framebuffer_size_for_mode(const struct drm_display_mode *mode, int bpp)
9708 u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
9709 return PAGE_ALIGN(pitch * mode->vdisplay);
9712 static struct drm_framebuffer *
9713 intel_framebuffer_create_for_mode(struct drm_device *dev,
9714 const struct drm_display_mode *mode,
9717 struct drm_framebuffer *fb;
9718 struct drm_i915_gem_object *obj;
9719 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
9721 obj = i915_gem_object_create(to_i915(dev),
9722 intel_framebuffer_size_for_mode(mode, bpp));
9724 return ERR_CAST(obj);
9726 mode_cmd.width = mode->hdisplay;
9727 mode_cmd.height = mode->vdisplay;
9728 mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
9730 mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
9732 fb = intel_framebuffer_create(obj, &mode_cmd);
9734 i915_gem_object_put(obj);
9739 static struct drm_framebuffer *
9740 mode_fits_in_fbdev(struct drm_device *dev,
9741 const struct drm_display_mode *mode)
9743 #ifdef CONFIG_DRM_FBDEV_EMULATION
9744 struct drm_i915_private *dev_priv = to_i915(dev);
9745 struct drm_i915_gem_object *obj;
9746 struct drm_framebuffer *fb;
9748 if (!dev_priv->fbdev)
9751 if (!dev_priv->fbdev->fb)
9754 obj = dev_priv->fbdev->fb->obj;
9757 fb = &dev_priv->fbdev->fb->base;
9758 if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
9759 fb->format->cpp[0] * 8))
9762 if (obj->base.size < mode->vdisplay * fb->pitches[0])
9765 drm_framebuffer_get(fb);
9772 static int intel_modeset_setup_plane_state(struct drm_atomic_state *state,
9773 struct drm_crtc *crtc,
9774 const struct drm_display_mode *mode,
9775 struct drm_framebuffer *fb,
9778 struct drm_plane_state *plane_state;
9779 int hdisplay, vdisplay;
9782 plane_state = drm_atomic_get_plane_state(state, crtc->primary);
9783 if (IS_ERR(plane_state))
9784 return PTR_ERR(plane_state);
9787 drm_mode_get_hv_timing(mode, &hdisplay, &vdisplay);
9789 hdisplay = vdisplay = 0;
9791 ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL);
9794 drm_atomic_set_fb_for_plane(plane_state, fb);
9795 plane_state->crtc_x = 0;
9796 plane_state->crtc_y = 0;
9797 plane_state->crtc_w = hdisplay;
9798 plane_state->crtc_h = vdisplay;
9799 plane_state->src_x = x << 16;
9800 plane_state->src_y = y << 16;
9801 plane_state->src_w = hdisplay << 16;
9802 plane_state->src_h = vdisplay << 16;
9807 int intel_get_load_detect_pipe(struct drm_connector *connector,
9808 const struct drm_display_mode *mode,
9809 struct intel_load_detect_pipe *old,
9810 struct drm_modeset_acquire_ctx *ctx)
9812 struct intel_crtc *intel_crtc;
9813 struct intel_encoder *intel_encoder =
9814 intel_attached_encoder(connector);
9815 struct drm_crtc *possible_crtc;
9816 struct drm_encoder *encoder = &intel_encoder->base;
9817 struct drm_crtc *crtc = NULL;
9818 struct drm_device *dev = encoder->dev;
9819 struct drm_i915_private *dev_priv = to_i915(dev);
9820 struct drm_framebuffer *fb;
9821 struct drm_mode_config *config = &dev->mode_config;
9822 struct drm_atomic_state *state = NULL, *restore_state = NULL;
9823 struct drm_connector_state *connector_state;
9824 struct intel_crtc_state *crtc_state;
9827 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9828 connector->base.id, connector->name,
9829 encoder->base.id, encoder->name);
9831 old->restore_state = NULL;
9833 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
9836 * Algorithm gets a little messy:
9838 * - if the connector already has an assigned crtc, use it (but make
9839 * sure it's on first)
9841 * - try to find the first unused crtc that can drive this connector,
9842 * and use that if we find one
9845 /* See if we already have a CRTC for this connector */
9846 if (connector->state->crtc) {
9847 crtc = connector->state->crtc;
9849 ret = drm_modeset_lock(&crtc->mutex, ctx);
9853 /* Make sure the crtc and connector are running */
9857 /* Find an unused one (if possible) */
9858 for_each_crtc(dev, possible_crtc) {
9860 if (!(encoder->possible_crtcs & (1 << i)))
9863 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
9867 if (possible_crtc->state->enable) {
9868 drm_modeset_unlock(&possible_crtc->mutex);
9872 crtc = possible_crtc;
9877 * If we didn't find an unused CRTC, don't use any.
9880 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9886 intel_crtc = to_intel_crtc(crtc);
9888 ret = drm_modeset_lock(&crtc->primary->mutex, ctx);
9892 state = drm_atomic_state_alloc(dev);
9893 restore_state = drm_atomic_state_alloc(dev);
9894 if (!state || !restore_state) {
9899 state->acquire_ctx = ctx;
9900 restore_state->acquire_ctx = ctx;
9902 connector_state = drm_atomic_get_connector_state(state, connector);
9903 if (IS_ERR(connector_state)) {
9904 ret = PTR_ERR(connector_state);
9908 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
9912 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
9913 if (IS_ERR(crtc_state)) {
9914 ret = PTR_ERR(crtc_state);
9918 crtc_state->base.active = crtc_state->base.enable = true;
9921 mode = &load_detect_mode;
9923 /* We need a framebuffer large enough to accommodate all accesses
9924 * that the plane may generate whilst we perform load detection.
9925 * We can not rely on the fbcon either being present (we get called
9926 * during its initialisation to detect all boot displays, or it may
9927 * not even exist) or that it is large enough to satisfy the
9930 fb = mode_fits_in_fbdev(dev, mode);
9932 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
9933 fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
9935 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
9937 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
9942 ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0);
9943 drm_framebuffer_put(fb);
9947 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
9951 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
9953 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
9955 ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary));
9957 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
9961 ret = drm_atomic_commit(state);
9963 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9967 old->restore_state = restore_state;
9968 drm_atomic_state_put(state);
9970 /* let the connector get through one full cycle before testing */
9971 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
9976 drm_atomic_state_put(state);
9979 if (restore_state) {
9980 drm_atomic_state_put(restore_state);
9981 restore_state = NULL;
9984 if (ret == -EDEADLK)
9990 void intel_release_load_detect_pipe(struct drm_connector *connector,
9991 struct intel_load_detect_pipe *old,
9992 struct drm_modeset_acquire_ctx *ctx)
9994 struct intel_encoder *intel_encoder =
9995 intel_attached_encoder(connector);
9996 struct drm_encoder *encoder = &intel_encoder->base;
9997 struct drm_atomic_state *state = old->restore_state;
10000 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10001 connector->base.id, connector->name,
10002 encoder->base.id, encoder->name);
10007 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10009 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10010 drm_atomic_state_put(state);
10013 static int i9xx_pll_refclk(struct drm_device *dev,
10014 const struct intel_crtc_state *pipe_config)
10016 struct drm_i915_private *dev_priv = to_i915(dev);
10017 u32 dpll = pipe_config->dpll_hw_state.dpll;
10019 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10020 return dev_priv->vbt.lvds_ssc_freq;
10021 else if (HAS_PCH_SPLIT(dev_priv))
10023 else if (!IS_GEN2(dev_priv))
10029 /* Returns the clock of the currently programmed mode of the given pipe. */
10030 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10031 struct intel_crtc_state *pipe_config)
10033 struct drm_device *dev = crtc->base.dev;
10034 struct drm_i915_private *dev_priv = to_i915(dev);
10035 int pipe = pipe_config->cpu_transcoder;
10036 u32 dpll = pipe_config->dpll_hw_state.dpll;
10040 int refclk = i9xx_pll_refclk(dev, pipe_config);
10042 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10043 fp = pipe_config->dpll_hw_state.fp0;
10045 fp = pipe_config->dpll_hw_state.fp1;
10047 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10048 if (IS_PINEVIEW(dev_priv)) {
10049 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10050 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10052 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10053 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10056 if (!IS_GEN2(dev_priv)) {
10057 if (IS_PINEVIEW(dev_priv))
10058 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10059 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10061 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10062 DPLL_FPA01_P1_POST_DIV_SHIFT);
10064 switch (dpll & DPLL_MODE_MASK) {
10065 case DPLLB_MODE_DAC_SERIAL:
10066 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10069 case DPLLB_MODE_LVDS:
10070 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10074 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10075 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10079 if (IS_PINEVIEW(dev_priv))
10080 port_clock = pnv_calc_dpll_params(refclk, &clock);
10082 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10084 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10085 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10088 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10089 DPLL_FPA01_P1_POST_DIV_SHIFT);
10091 if (lvds & LVDS_CLKB_POWER_UP)
10096 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10099 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10100 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10102 if (dpll & PLL_P2_DIVIDE_BY_4)
10108 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10112 * This value includes pixel_multiplier. We will use
10113 * port_clock to compute adjusted_mode.crtc_clock in the
10114 * encoder's get_config() function.
10116 pipe_config->port_clock = port_clock;
10119 int intel_dotclock_calculate(int link_freq,
10120 const struct intel_link_m_n *m_n)
10123 * The calculation for the data clock is:
10124 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10125 * But we want to avoid losing precison if possible, so:
10126 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10128 * and the link clock is simpler:
10129 * link_clock = (m * link_clock) / n
10135 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10138 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10139 struct intel_crtc_state *pipe_config)
10141 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10143 /* read out port_clock from the DPLL */
10144 i9xx_crtc_clock_get(crtc, pipe_config);
10147 * In case there is an active pipe without active ports,
10148 * we may need some idea for the dotclock anyway.
10149 * Calculate one based on the FDI configuration.
10151 pipe_config->base.adjusted_mode.crtc_clock =
10152 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10153 &pipe_config->fdi_m_n);
10156 /* Returns the currently programmed mode of the given encoder. */
10157 struct drm_display_mode *
10158 intel_encoder_current_mode(struct intel_encoder *encoder)
10160 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10161 struct intel_crtc_state *crtc_state;
10162 struct drm_display_mode *mode;
10163 struct intel_crtc *crtc;
10166 if (!encoder->get_hw_state(encoder, &pipe))
10169 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10171 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10175 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10181 crtc_state->base.crtc = &crtc->base;
10183 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10189 encoder->get_config(encoder, crtc_state);
10191 intel_mode_from_pipe_config(mode, crtc_state);
10198 static void intel_crtc_destroy(struct drm_crtc *crtc)
10200 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10202 drm_crtc_cleanup(crtc);
10207 * intel_wm_need_update - Check whether watermarks need updating
10208 * @plane: drm plane
10209 * @state: new plane state
10211 * Check current plane state versus the new one to determine whether
10212 * watermarks need to be recalculated.
10214 * Returns true or false.
10216 static bool intel_wm_need_update(struct drm_plane *plane,
10217 struct drm_plane_state *state)
10219 struct intel_plane_state *new = to_intel_plane_state(state);
10220 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10222 /* Update watermarks on tiling or size changes. */
10223 if (new->base.visible != cur->base.visible)
10226 if (!cur->base.fb || !new->base.fb)
10229 if (cur->base.fb->modifier != new->base.fb->modifier ||
10230 cur->base.rotation != new->base.rotation ||
10231 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10232 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10233 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10234 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10240 static bool needs_scaling(const struct intel_plane_state *state)
10242 int src_w = drm_rect_width(&state->base.src) >> 16;
10243 int src_h = drm_rect_height(&state->base.src) >> 16;
10244 int dst_w = drm_rect_width(&state->base.dst);
10245 int dst_h = drm_rect_height(&state->base.dst);
10247 return (src_w != dst_w || src_h != dst_h);
10250 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10251 struct drm_crtc_state *crtc_state,
10252 const struct intel_plane_state *old_plane_state,
10253 struct drm_plane_state *plane_state)
10255 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10256 struct drm_crtc *crtc = crtc_state->crtc;
10257 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10258 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10259 struct drm_device *dev = crtc->dev;
10260 struct drm_i915_private *dev_priv = to_i915(dev);
10261 bool mode_changed = needs_modeset(crtc_state);
10262 bool was_crtc_enabled = old_crtc_state->base.active;
10263 bool is_crtc_enabled = crtc_state->active;
10264 bool turn_off, turn_on, visible, was_visible;
10265 struct drm_framebuffer *fb = plane_state->fb;
10268 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10269 ret = skl_update_scaler_plane(
10270 to_intel_crtc_state(crtc_state),
10271 to_intel_plane_state(plane_state));
10276 was_visible = old_plane_state->base.visible;
10277 visible = plane_state->visible;
10279 if (!was_crtc_enabled && WARN_ON(was_visible))
10280 was_visible = false;
10283 * Visibility is calculated as if the crtc was on, but
10284 * after scaler setup everything depends on it being off
10285 * when the crtc isn't active.
10287 * FIXME this is wrong for watermarks. Watermarks should also
10288 * be computed as if the pipe would be active. Perhaps move
10289 * per-plane wm computation to the .check_plane() hook, and
10290 * only combine the results from all planes in the current place?
10292 if (!is_crtc_enabled) {
10293 plane_state->visible = visible = false;
10294 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10297 if (!was_visible && !visible)
10300 if (fb != old_plane_state->base.fb)
10301 pipe_config->fb_changed = true;
10303 turn_off = was_visible && (!visible || mode_changed);
10304 turn_on = visible && (!was_visible || mode_changed);
10306 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10307 intel_crtc->base.base.id, intel_crtc->base.name,
10308 plane->base.base.id, plane->base.name,
10309 fb ? fb->base.id : -1);
10311 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10312 plane->base.base.id, plane->base.name,
10313 was_visible, visible,
10314 turn_off, turn_on, mode_changed);
10317 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10318 pipe_config->update_wm_pre = true;
10320 /* must disable cxsr around plane enable/disable */
10321 if (plane->id != PLANE_CURSOR)
10322 pipe_config->disable_cxsr = true;
10323 } else if (turn_off) {
10324 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10325 pipe_config->update_wm_post = true;
10327 /* must disable cxsr around plane enable/disable */
10328 if (plane->id != PLANE_CURSOR)
10329 pipe_config->disable_cxsr = true;
10330 } else if (intel_wm_need_update(&plane->base, plane_state)) {
10331 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
10332 /* FIXME bollocks */
10333 pipe_config->update_wm_pre = true;
10334 pipe_config->update_wm_post = true;
10338 if (visible || was_visible)
10339 pipe_config->fb_bits |= plane->frontbuffer_bit;
10342 * WaCxSRDisabledForSpriteScaling:ivb
10344 * cstate->update_wm was already set above, so this flag will
10345 * take effect when we commit and program watermarks.
10347 if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) &&
10348 needs_scaling(to_intel_plane_state(plane_state)) &&
10349 !needs_scaling(old_plane_state))
10350 pipe_config->disable_lp_wm = true;
10355 static bool encoders_cloneable(const struct intel_encoder *a,
10356 const struct intel_encoder *b)
10358 /* masks could be asymmetric, so check both ways */
10359 return a == b || (a->cloneable & (1 << b->type) &&
10360 b->cloneable & (1 << a->type));
10363 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10364 struct intel_crtc *crtc,
10365 struct intel_encoder *encoder)
10367 struct intel_encoder *source_encoder;
10368 struct drm_connector *connector;
10369 struct drm_connector_state *connector_state;
10372 for_each_new_connector_in_state(state, connector, connector_state, i) {
10373 if (connector_state->crtc != &crtc->base)
10377 to_intel_encoder(connector_state->best_encoder);
10378 if (!encoders_cloneable(encoder, source_encoder))
10385 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10386 struct drm_crtc_state *crtc_state)
10388 struct drm_device *dev = crtc->dev;
10389 struct drm_i915_private *dev_priv = to_i915(dev);
10390 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10391 struct intel_crtc_state *pipe_config =
10392 to_intel_crtc_state(crtc_state);
10393 struct drm_atomic_state *state = crtc_state->state;
10395 bool mode_changed = needs_modeset(crtc_state);
10397 if (mode_changed && !crtc_state->active)
10398 pipe_config->update_wm_post = true;
10400 if (mode_changed && crtc_state->enable &&
10401 dev_priv->display.crtc_compute_clock &&
10402 !WARN_ON(pipe_config->shared_dpll)) {
10403 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10409 if (crtc_state->color_mgmt_changed) {
10410 ret = intel_color_check(crtc, crtc_state);
10415 * Changing color management on Intel hardware is
10416 * handled as part of planes update.
10418 crtc_state->planes_changed = true;
10422 if (dev_priv->display.compute_pipe_wm) {
10423 ret = dev_priv->display.compute_pipe_wm(pipe_config);
10425 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10430 if (dev_priv->display.compute_intermediate_wm &&
10431 !to_intel_atomic_state(state)->skip_intermediate_wm) {
10432 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10436 * Calculate 'intermediate' watermarks that satisfy both the
10437 * old state and the new state. We can program these
10440 ret = dev_priv->display.compute_intermediate_wm(dev,
10444 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10447 } else if (dev_priv->display.compute_intermediate_wm) {
10448 if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
10449 pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
10452 if (INTEL_GEN(dev_priv) >= 9) {
10454 ret = skl_update_scaler_crtc(pipe_config);
10457 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10460 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
10464 if (HAS_IPS(dev_priv))
10465 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10470 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
10471 .atomic_begin = intel_begin_crtc_commit,
10472 .atomic_flush = intel_finish_crtc_commit,
10473 .atomic_check = intel_crtc_atomic_check,
10476 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10478 struct intel_connector *connector;
10479 struct drm_connector_list_iter conn_iter;
10481 drm_connector_list_iter_begin(dev, &conn_iter);
10482 for_each_intel_connector_iter(connector, &conn_iter) {
10483 if (connector->base.state->crtc)
10484 drm_connector_unreference(&connector->base);
10486 if (connector->base.encoder) {
10487 connector->base.state->best_encoder =
10488 connector->base.encoder;
10489 connector->base.state->crtc =
10490 connector->base.encoder->crtc;
10492 drm_connector_reference(&connector->base);
10494 connector->base.state->best_encoder = NULL;
10495 connector->base.state->crtc = NULL;
10498 drm_connector_list_iter_end(&conn_iter);
10502 connected_sink_compute_bpp(struct intel_connector *connector,
10503 struct intel_crtc_state *pipe_config)
10505 const struct drm_display_info *info = &connector->base.display_info;
10506 int bpp = pipe_config->pipe_bpp;
10508 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10509 connector->base.base.id,
10510 connector->base.name);
10512 /* Don't use an invalid EDID bpc value */
10513 if (info->bpc != 0 && info->bpc * 3 < bpp) {
10514 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10515 bpp, info->bpc * 3);
10516 pipe_config->pipe_bpp = info->bpc * 3;
10519 /* Clamp bpp to 8 on screens without EDID 1.4 */
10520 if (info->bpc == 0 && bpp > 24) {
10521 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10523 pipe_config->pipe_bpp = 24;
10528 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
10529 struct intel_crtc_state *pipe_config)
10531 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10532 struct drm_atomic_state *state;
10533 struct drm_connector *connector;
10534 struct drm_connector_state *connector_state;
10537 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10538 IS_CHERRYVIEW(dev_priv)))
10540 else if (INTEL_GEN(dev_priv) >= 5)
10546 pipe_config->pipe_bpp = bpp;
10548 state = pipe_config->base.state;
10550 /* Clamp display bpp to EDID value */
10551 for_each_new_connector_in_state(state, connector, connector_state, i) {
10552 if (connector_state->crtc != &crtc->base)
10555 connected_sink_compute_bpp(to_intel_connector(connector),
10562 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
10564 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10565 "type: 0x%x flags: 0x%x\n",
10567 mode->crtc_hdisplay, mode->crtc_hsync_start,
10568 mode->crtc_hsync_end, mode->crtc_htotal,
10569 mode->crtc_vdisplay, mode->crtc_vsync_start,
10570 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
10574 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
10575 unsigned int lane_count, struct intel_link_m_n *m_n)
10577 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10579 m_n->gmch_m, m_n->gmch_n,
10580 m_n->link_m, m_n->link_n, m_n->tu);
10583 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
10585 static const char * const output_type_str[] = {
10586 OUTPUT_TYPE(UNUSED),
10587 OUTPUT_TYPE(ANALOG),
10591 OUTPUT_TYPE(TVOUT),
10597 OUTPUT_TYPE(DP_MST),
10602 static void snprintf_output_types(char *buf, size_t len,
10603 unsigned int output_types)
10610 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
10613 if ((output_types & BIT(i)) == 0)
10616 r = snprintf(str, len, "%s%s",
10617 str != buf ? "," : "", output_type_str[i]);
10623 output_types &= ~BIT(i);
10626 WARN_ON_ONCE(output_types != 0);
10629 static void intel_dump_pipe_config(struct intel_crtc *crtc,
10630 struct intel_crtc_state *pipe_config,
10631 const char *context)
10633 struct drm_device *dev = crtc->base.dev;
10634 struct drm_i915_private *dev_priv = to_i915(dev);
10635 struct drm_plane *plane;
10636 struct intel_plane *intel_plane;
10637 struct intel_plane_state *state;
10638 struct drm_framebuffer *fb;
10641 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10642 crtc->base.base.id, crtc->base.name, context);
10644 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
10645 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
10646 buf, pipe_config->output_types);
10648 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10649 transcoder_name(pipe_config->cpu_transcoder),
10650 pipe_config->pipe_bpp, pipe_config->dither);
10652 if (pipe_config->has_pch_encoder)
10653 intel_dump_m_n_config(pipe_config, "fdi",
10654 pipe_config->fdi_lanes,
10655 &pipe_config->fdi_m_n);
10657 if (pipe_config->ycbcr420)
10658 DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
10660 if (intel_crtc_has_dp_encoder(pipe_config)) {
10661 intel_dump_m_n_config(pipe_config, "dp m_n",
10662 pipe_config->lane_count, &pipe_config->dp_m_n);
10663 if (pipe_config->has_drrs)
10664 intel_dump_m_n_config(pipe_config, "dp m2_n2",
10665 pipe_config->lane_count,
10666 &pipe_config->dp_m2_n2);
10669 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10670 pipe_config->has_audio, pipe_config->has_infoframe);
10672 DRM_DEBUG_KMS("requested mode:\n");
10673 drm_mode_debug_printmodeline(&pipe_config->base.mode);
10674 DRM_DEBUG_KMS("adjusted mode:\n");
10675 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
10676 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
10677 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10678 pipe_config->port_clock,
10679 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
10680 pipe_config->pixel_rate);
10682 if (INTEL_GEN(dev_priv) >= 9)
10683 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10685 pipe_config->scaler_state.scaler_users,
10686 pipe_config->scaler_state.scaler_id);
10688 if (HAS_GMCH_DISPLAY(dev_priv))
10689 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10690 pipe_config->gmch_pfit.control,
10691 pipe_config->gmch_pfit.pgm_ratios,
10692 pipe_config->gmch_pfit.lvds_border_bits);
10694 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10695 pipe_config->pch_pfit.pos,
10696 pipe_config->pch_pfit.size,
10697 enableddisabled(pipe_config->pch_pfit.enabled));
10699 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10700 pipe_config->ips_enabled, pipe_config->double_wide);
10702 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
10704 DRM_DEBUG_KMS("planes on this crtc\n");
10705 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
10706 struct drm_format_name_buf format_name;
10707 intel_plane = to_intel_plane(plane);
10708 if (intel_plane->pipe != crtc->pipe)
10711 state = to_intel_plane_state(plane->state);
10712 fb = state->base.fb;
10714 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10715 plane->base.id, plane->name, state->scaler_id);
10719 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10720 plane->base.id, plane->name,
10721 fb->base.id, fb->width, fb->height,
10722 drm_get_format_name(fb->format->format, &format_name));
10723 if (INTEL_GEN(dev_priv) >= 9)
10724 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10726 state->base.src.x1 >> 16,
10727 state->base.src.y1 >> 16,
10728 drm_rect_width(&state->base.src) >> 16,
10729 drm_rect_height(&state->base.src) >> 16,
10730 state->base.dst.x1, state->base.dst.y1,
10731 drm_rect_width(&state->base.dst),
10732 drm_rect_height(&state->base.dst));
10736 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
10738 struct drm_device *dev = state->dev;
10739 struct drm_connector *connector;
10740 struct drm_connector_list_iter conn_iter;
10741 unsigned int used_ports = 0;
10742 unsigned int used_mst_ports = 0;
10745 * Walk the connector list instead of the encoder
10746 * list to detect the problem on ddi platforms
10747 * where there's just one encoder per digital port.
10749 drm_connector_list_iter_begin(dev, &conn_iter);
10750 drm_for_each_connector_iter(connector, &conn_iter) {
10751 struct drm_connector_state *connector_state;
10752 struct intel_encoder *encoder;
10754 connector_state = drm_atomic_get_existing_connector_state(state, connector);
10755 if (!connector_state)
10756 connector_state = connector->state;
10758 if (!connector_state->best_encoder)
10761 encoder = to_intel_encoder(connector_state->best_encoder);
10763 WARN_ON(!connector_state->crtc);
10765 switch (encoder->type) {
10766 unsigned int port_mask;
10767 case INTEL_OUTPUT_DDI:
10768 if (WARN_ON(!HAS_DDI(to_i915(dev))))
10770 case INTEL_OUTPUT_DP:
10771 case INTEL_OUTPUT_HDMI:
10772 case INTEL_OUTPUT_EDP:
10773 port_mask = 1 << encoder->port;
10775 /* the same port mustn't appear more than once */
10776 if (used_ports & port_mask)
10779 used_ports |= port_mask;
10781 case INTEL_OUTPUT_DP_MST:
10783 1 << encoder->port;
10789 drm_connector_list_iter_end(&conn_iter);
10791 /* can't mix MST and SST/HDMI on the same port */
10792 if (used_ports & used_mst_ports)
10799 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
10801 struct drm_i915_private *dev_priv =
10802 to_i915(crtc_state->base.crtc->dev);
10803 struct intel_crtc_scaler_state scaler_state;
10804 struct intel_dpll_hw_state dpll_hw_state;
10805 struct intel_shared_dpll *shared_dpll;
10806 struct intel_crtc_wm_state wm_state;
10807 bool force_thru, ips_force_disable;
10809 /* FIXME: before the switch to atomic started, a new pipe_config was
10810 * kzalloc'd. Code that depends on any field being zero should be
10811 * fixed, so that the crtc_state can be safely duplicated. For now,
10812 * only fields that are know to not cause problems are preserved. */
10814 scaler_state = crtc_state->scaler_state;
10815 shared_dpll = crtc_state->shared_dpll;
10816 dpll_hw_state = crtc_state->dpll_hw_state;
10817 force_thru = crtc_state->pch_pfit.force_thru;
10818 ips_force_disable = crtc_state->ips_force_disable;
10819 if (IS_G4X(dev_priv) ||
10820 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10821 wm_state = crtc_state->wm;
10823 /* Keep base drm_crtc_state intact, only clear our extended struct */
10824 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
10825 memset(&crtc_state->base + 1, 0,
10826 sizeof(*crtc_state) - sizeof(crtc_state->base));
10828 crtc_state->scaler_state = scaler_state;
10829 crtc_state->shared_dpll = shared_dpll;
10830 crtc_state->dpll_hw_state = dpll_hw_state;
10831 crtc_state->pch_pfit.force_thru = force_thru;
10832 crtc_state->ips_force_disable = ips_force_disable;
10833 if (IS_G4X(dev_priv) ||
10834 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10835 crtc_state->wm = wm_state;
10839 intel_modeset_pipe_config(struct drm_crtc *crtc,
10840 struct intel_crtc_state *pipe_config)
10842 struct drm_atomic_state *state = pipe_config->base.state;
10843 struct intel_encoder *encoder;
10844 struct drm_connector *connector;
10845 struct drm_connector_state *connector_state;
10846 int base_bpp, ret = -EINVAL;
10850 clear_intel_crtc_state(pipe_config);
10852 pipe_config->cpu_transcoder =
10853 (enum transcoder) to_intel_crtc(crtc)->pipe;
10856 * Sanitize sync polarity flags based on requested ones. If neither
10857 * positive or negative polarity is requested, treat this as meaning
10858 * negative polarity.
10860 if (!(pipe_config->base.adjusted_mode.flags &
10861 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
10862 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
10864 if (!(pipe_config->base.adjusted_mode.flags &
10865 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
10866 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
10868 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
10874 * Determine the real pipe dimensions. Note that stereo modes can
10875 * increase the actual pipe size due to the frame doubling and
10876 * insertion of additional space for blanks between the frame. This
10877 * is stored in the crtc timings. We use the requested mode to do this
10878 * computation to clearly distinguish it from the adjusted mode, which
10879 * can be changed by the connectors in the below retry loop.
10881 drm_mode_get_hv_timing(&pipe_config->base.mode,
10882 &pipe_config->pipe_src_w,
10883 &pipe_config->pipe_src_h);
10885 for_each_new_connector_in_state(state, connector, connector_state, i) {
10886 if (connector_state->crtc != crtc)
10889 encoder = to_intel_encoder(connector_state->best_encoder);
10891 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
10892 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10897 * Determine output_types before calling the .compute_config()
10898 * hooks so that the hooks can use this information safely.
10900 if (encoder->compute_output_type)
10901 pipe_config->output_types |=
10902 BIT(encoder->compute_output_type(encoder, pipe_config,
10905 pipe_config->output_types |= BIT(encoder->type);
10909 /* Ensure the port clock defaults are reset when retrying. */
10910 pipe_config->port_clock = 0;
10911 pipe_config->pixel_multiplier = 1;
10913 /* Fill in default crtc timings, allow encoders to overwrite them. */
10914 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
10915 CRTC_STEREO_DOUBLE);
10917 /* Pass our mode to the connectors and the CRTC to give them a chance to
10918 * adjust it according to limitations or connector properties, and also
10919 * a chance to reject the mode entirely.
10921 for_each_new_connector_in_state(state, connector, connector_state, i) {
10922 if (connector_state->crtc != crtc)
10925 encoder = to_intel_encoder(connector_state->best_encoder);
10927 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
10928 DRM_DEBUG_KMS("Encoder config failure\n");
10933 /* Set default port clock if not overwritten by the encoder. Needs to be
10934 * done afterwards in case the encoder adjusts the mode. */
10935 if (!pipe_config->port_clock)
10936 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
10937 * pipe_config->pixel_multiplier;
10939 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
10941 DRM_DEBUG_KMS("CRTC fixup failed\n");
10945 if (ret == RETRY) {
10946 if (WARN(!retry, "loop in pipe configuration computation\n")) {
10951 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10953 goto encoder_retry;
10956 /* Dithering seems to not pass-through bits correctly when it should, so
10957 * only enable it on 6bpc panels and when its not a compliance
10958 * test requesting 6bpc video pattern.
10960 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
10961 !pipe_config->dither_force_disable;
10962 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
10963 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
10969 static bool intel_fuzzy_clock_check(int clock1, int clock2)
10973 if (clock1 == clock2)
10976 if (!clock1 || !clock2)
10979 diff = abs(clock1 - clock2);
10981 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
10988 intel_compare_m_n(unsigned int m, unsigned int n,
10989 unsigned int m2, unsigned int n2,
10992 if (m == m2 && n == n2)
10995 if (exact || !m || !n || !m2 || !n2)
10998 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11005 } else if (n < n2) {
11015 return intel_fuzzy_clock_check(m, m2);
11019 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11020 struct intel_link_m_n *m2_n2,
11023 if (m_n->tu == m2_n2->tu &&
11024 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11025 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11026 intel_compare_m_n(m_n->link_m, m_n->link_n,
11027 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11037 static void __printf(3, 4)
11038 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11041 unsigned int category;
11042 struct va_format vaf;
11046 level = KERN_DEBUG;
11047 category = DRM_UT_KMS;
11050 category = DRM_UT_NONE;
11053 va_start(args, format);
11057 drm_printk(level, category, "mismatch in %s %pV", name, &vaf);
11063 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11064 struct intel_crtc_state *current_config,
11065 struct intel_crtc_state *pipe_config,
11069 bool fixup_inherited = adjust &&
11070 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11071 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11073 #define PIPE_CONF_CHECK_X(name) \
11074 if (current_config->name != pipe_config->name) { \
11075 pipe_config_err(adjust, __stringify(name), \
11076 "(expected 0x%08x, found 0x%08x)\n", \
11077 current_config->name, \
11078 pipe_config->name); \
11082 #define PIPE_CONF_CHECK_I(name) \
11083 if (current_config->name != pipe_config->name) { \
11084 pipe_config_err(adjust, __stringify(name), \
11085 "(expected %i, found %i)\n", \
11086 current_config->name, \
11087 pipe_config->name); \
11091 #define PIPE_CONF_CHECK_BOOL(name) \
11092 if (current_config->name != pipe_config->name) { \
11093 pipe_config_err(adjust, __stringify(name), \
11094 "(expected %s, found %s)\n", \
11095 yesno(current_config->name), \
11096 yesno(pipe_config->name)); \
11101 * Checks state where we only read out the enabling, but not the entire
11102 * state itself (like full infoframes or ELD for audio). These states
11103 * require a full modeset on bootup to fix up.
11105 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) \
11106 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11107 PIPE_CONF_CHECK_BOOL(name); \
11109 pipe_config_err(adjust, __stringify(name), \
11110 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11111 yesno(current_config->name), \
11112 yesno(pipe_config->name)); \
11116 #define PIPE_CONF_CHECK_P(name) \
11117 if (current_config->name != pipe_config->name) { \
11118 pipe_config_err(adjust, __stringify(name), \
11119 "(expected %p, found %p)\n", \
11120 current_config->name, \
11121 pipe_config->name); \
11125 #define PIPE_CONF_CHECK_M_N(name) \
11126 if (!intel_compare_link_m_n(¤t_config->name, \
11127 &pipe_config->name,\
11129 pipe_config_err(adjust, __stringify(name), \
11130 "(expected tu %i gmch %i/%i link %i/%i, " \
11131 "found tu %i, gmch %i/%i link %i/%i)\n", \
11132 current_config->name.tu, \
11133 current_config->name.gmch_m, \
11134 current_config->name.gmch_n, \
11135 current_config->name.link_m, \
11136 current_config->name.link_n, \
11137 pipe_config->name.tu, \
11138 pipe_config->name.gmch_m, \
11139 pipe_config->name.gmch_n, \
11140 pipe_config->name.link_m, \
11141 pipe_config->name.link_n); \
11145 /* This is required for BDW+ where there is only one set of registers for
11146 * switching between high and low RR.
11147 * This macro can be used whenever a comparison has to be made between one
11148 * hw state and multiple sw state variables.
11150 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \
11151 if (!intel_compare_link_m_n(¤t_config->name, \
11152 &pipe_config->name, adjust) && \
11153 !intel_compare_link_m_n(¤t_config->alt_name, \
11154 &pipe_config->name, adjust)) { \
11155 pipe_config_err(adjust, __stringify(name), \
11156 "(expected tu %i gmch %i/%i link %i/%i, " \
11157 "or tu %i gmch %i/%i link %i/%i, " \
11158 "found tu %i, gmch %i/%i link %i/%i)\n", \
11159 current_config->name.tu, \
11160 current_config->name.gmch_m, \
11161 current_config->name.gmch_n, \
11162 current_config->name.link_m, \
11163 current_config->name.link_n, \
11164 current_config->alt_name.tu, \
11165 current_config->alt_name.gmch_m, \
11166 current_config->alt_name.gmch_n, \
11167 current_config->alt_name.link_m, \
11168 current_config->alt_name.link_n, \
11169 pipe_config->name.tu, \
11170 pipe_config->name.gmch_m, \
11171 pipe_config->name.gmch_n, \
11172 pipe_config->name.link_m, \
11173 pipe_config->name.link_n); \
11177 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
11178 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11179 pipe_config_err(adjust, __stringify(name), \
11180 "(%x) (expected %i, found %i)\n", \
11182 current_config->name & (mask), \
11183 pipe_config->name & (mask)); \
11187 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
11188 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11189 pipe_config_err(adjust, __stringify(name), \
11190 "(expected %i, found %i)\n", \
11191 current_config->name, \
11192 pipe_config->name); \
11196 #define PIPE_CONF_QUIRK(quirk) \
11197 ((current_config->quirks | pipe_config->quirks) & (quirk))
11199 PIPE_CONF_CHECK_I(cpu_transcoder);
11201 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11202 PIPE_CONF_CHECK_I(fdi_lanes);
11203 PIPE_CONF_CHECK_M_N(fdi_m_n);
11205 PIPE_CONF_CHECK_I(lane_count);
11206 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11208 if (INTEL_GEN(dev_priv) < 8) {
11209 PIPE_CONF_CHECK_M_N(dp_m_n);
11211 if (current_config->has_drrs)
11212 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11214 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11216 PIPE_CONF_CHECK_X(output_types);
11218 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11219 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11220 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11221 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11222 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11223 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
11225 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11226 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11227 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11228 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11229 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11230 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
11232 PIPE_CONF_CHECK_I(pixel_multiplier);
11233 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11234 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11235 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11236 PIPE_CONF_CHECK_BOOL(limited_color_range);
11238 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11239 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11240 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
11241 PIPE_CONF_CHECK_BOOL(ycbcr420);
11243 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11245 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11246 DRM_MODE_FLAG_INTERLACE);
11248 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11249 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11250 DRM_MODE_FLAG_PHSYNC);
11251 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11252 DRM_MODE_FLAG_NHSYNC);
11253 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11254 DRM_MODE_FLAG_PVSYNC);
11255 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11256 DRM_MODE_FLAG_NVSYNC);
11259 PIPE_CONF_CHECK_X(gmch_pfit.control);
11260 /* pfit ratios are autocomputed by the hw on gen4+ */
11261 if (INTEL_GEN(dev_priv) < 4)
11262 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11263 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11266 PIPE_CONF_CHECK_I(pipe_src_w);
11267 PIPE_CONF_CHECK_I(pipe_src_h);
11269 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11270 if (current_config->pch_pfit.enabled) {
11271 PIPE_CONF_CHECK_X(pch_pfit.pos);
11272 PIPE_CONF_CHECK_X(pch_pfit.size);
11275 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11276 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11279 PIPE_CONF_CHECK_BOOL(double_wide);
11281 PIPE_CONF_CHECK_P(shared_dpll);
11282 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11283 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11284 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11285 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11286 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11287 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11288 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11289 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11290 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11291 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11292 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11293 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11294 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11295 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11296 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11297 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11298 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11299 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11300 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11301 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11302 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11304 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11305 PIPE_CONF_CHECK_X(dsi_pll.div);
11307 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11308 PIPE_CONF_CHECK_I(pipe_bpp);
11310 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
11311 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11313 PIPE_CONF_CHECK_I(min_voltage_level);
11315 #undef PIPE_CONF_CHECK_X
11316 #undef PIPE_CONF_CHECK_I
11317 #undef PIPE_CONF_CHECK_BOOL
11318 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11319 #undef PIPE_CONF_CHECK_P
11320 #undef PIPE_CONF_CHECK_FLAGS
11321 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11322 #undef PIPE_CONF_QUIRK
11327 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11328 const struct intel_crtc_state *pipe_config)
11330 if (pipe_config->has_pch_encoder) {
11331 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11332 &pipe_config->fdi_m_n);
11333 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11336 * FDI already provided one idea for the dotclock.
11337 * Yell if the encoder disagrees.
11339 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11340 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11341 fdi_dotclock, dotclock);
11345 static void verify_wm_state(struct drm_crtc *crtc,
11346 struct drm_crtc_state *new_state)
11348 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11349 struct skl_ddb_allocation hw_ddb, *sw_ddb;
11350 struct skl_pipe_wm hw_wm, *sw_wm;
11351 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11352 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11353 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11354 const enum pipe pipe = intel_crtc->pipe;
11355 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11357 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
11360 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
11361 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
11363 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11364 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11367 for_each_universal_plane(dev_priv, pipe, plane) {
11368 hw_plane_wm = &hw_wm.planes[plane];
11369 sw_plane_wm = &sw_wm->planes[plane];
11372 for (level = 0; level <= max_level; level++) {
11373 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11374 &sw_plane_wm->wm[level]))
11377 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",
11378 pipe_name(pipe), plane + 1, level,
11379 sw_plane_wm->wm[level].plane_en,
11380 sw_plane_wm->wm[level].plane_res_b,
11381 sw_plane_wm->wm[level].plane_res_l,
11382 hw_plane_wm->wm[level].plane_en,
11383 hw_plane_wm->wm[level].plane_res_b,
11384 hw_plane_wm->wm[level].plane_res_l);
11387 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11388 &sw_plane_wm->trans_wm)) {
11389 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",
11390 pipe_name(pipe), plane + 1,
11391 sw_plane_wm->trans_wm.plane_en,
11392 sw_plane_wm->trans_wm.plane_res_b,
11393 sw_plane_wm->trans_wm.plane_res_l,
11394 hw_plane_wm->trans_wm.plane_en,
11395 hw_plane_wm->trans_wm.plane_res_b,
11396 hw_plane_wm->trans_wm.plane_res_l);
11400 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11401 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11403 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11404 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11405 pipe_name(pipe), plane + 1,
11406 sw_ddb_entry->start, sw_ddb_entry->end,
11407 hw_ddb_entry->start, hw_ddb_entry->end);
11413 * If the cursor plane isn't active, we may not have updated it's ddb
11414 * allocation. In that case since the ddb allocation will be updated
11415 * once the plane becomes visible, we can skip this check
11418 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11419 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
11422 for (level = 0; level <= max_level; level++) {
11423 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11424 &sw_plane_wm->wm[level]))
11427 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",
11428 pipe_name(pipe), level,
11429 sw_plane_wm->wm[level].plane_en,
11430 sw_plane_wm->wm[level].plane_res_b,
11431 sw_plane_wm->wm[level].plane_res_l,
11432 hw_plane_wm->wm[level].plane_en,
11433 hw_plane_wm->wm[level].plane_res_b,
11434 hw_plane_wm->wm[level].plane_res_l);
11437 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11438 &sw_plane_wm->trans_wm)) {
11439 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11441 sw_plane_wm->trans_wm.plane_en,
11442 sw_plane_wm->trans_wm.plane_res_b,
11443 sw_plane_wm->trans_wm.plane_res_l,
11444 hw_plane_wm->trans_wm.plane_en,
11445 hw_plane_wm->trans_wm.plane_res_b,
11446 hw_plane_wm->trans_wm.plane_res_l);
11450 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11451 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11453 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11454 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11456 sw_ddb_entry->start, sw_ddb_entry->end,
11457 hw_ddb_entry->start, hw_ddb_entry->end);
11463 verify_connector_state(struct drm_device *dev,
11464 struct drm_atomic_state *state,
11465 struct drm_crtc *crtc)
11467 struct drm_connector *connector;
11468 struct drm_connector_state *new_conn_state;
11471 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
11472 struct drm_encoder *encoder = connector->encoder;
11473 struct drm_crtc_state *crtc_state = NULL;
11475 if (new_conn_state->crtc != crtc)
11479 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11481 intel_connector_verify_state(crtc_state, new_conn_state);
11483 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
11484 "connector's atomic encoder doesn't match legacy encoder\n");
11489 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
11491 struct intel_encoder *encoder;
11492 struct drm_connector *connector;
11493 struct drm_connector_state *old_conn_state, *new_conn_state;
11496 for_each_intel_encoder(dev, encoder) {
11497 bool enabled = false, found = false;
11500 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11501 encoder->base.base.id,
11502 encoder->base.name);
11504 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
11505 new_conn_state, i) {
11506 if (old_conn_state->best_encoder == &encoder->base)
11509 if (new_conn_state->best_encoder != &encoder->base)
11511 found = enabled = true;
11513 I915_STATE_WARN(new_conn_state->crtc !=
11514 encoder->base.crtc,
11515 "connector's crtc doesn't match encoder crtc\n");
11521 I915_STATE_WARN(!!encoder->base.crtc != enabled,
11522 "encoder's enabled state mismatch "
11523 "(expected %i, found %i)\n",
11524 !!encoder->base.crtc, enabled);
11526 if (!encoder->base.crtc) {
11529 active = encoder->get_hw_state(encoder, &pipe);
11530 I915_STATE_WARN(active,
11531 "encoder detached but still enabled on pipe %c.\n",
11538 verify_crtc_state(struct drm_crtc *crtc,
11539 struct drm_crtc_state *old_crtc_state,
11540 struct drm_crtc_state *new_crtc_state)
11542 struct drm_device *dev = crtc->dev;
11543 struct drm_i915_private *dev_priv = to_i915(dev);
11544 struct intel_encoder *encoder;
11545 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11546 struct intel_crtc_state *pipe_config, *sw_config;
11547 struct drm_atomic_state *old_state;
11550 old_state = old_crtc_state->state;
11551 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
11552 pipe_config = to_intel_crtc_state(old_crtc_state);
11553 memset(pipe_config, 0, sizeof(*pipe_config));
11554 pipe_config->base.crtc = crtc;
11555 pipe_config->base.state = old_state;
11557 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
11559 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
11561 /* we keep both pipes enabled on 830 */
11562 if (IS_I830(dev_priv))
11563 active = new_crtc_state->active;
11565 I915_STATE_WARN(new_crtc_state->active != active,
11566 "crtc active state doesn't match with hw state "
11567 "(expected %i, found %i)\n", new_crtc_state->active, active);
11569 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
11570 "transitional active state does not match atomic hw state "
11571 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
11573 for_each_encoder_on_crtc(dev, crtc, encoder) {
11576 active = encoder->get_hw_state(encoder, &pipe);
11577 I915_STATE_WARN(active != new_crtc_state->active,
11578 "[ENCODER:%i] active %i with crtc active %i\n",
11579 encoder->base.base.id, active, new_crtc_state->active);
11581 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
11582 "Encoder connected to wrong pipe %c\n",
11586 encoder->get_config(encoder, pipe_config);
11589 intel_crtc_compute_pixel_rate(pipe_config);
11591 if (!new_crtc_state->active)
11594 intel_pipe_config_sanity_check(dev_priv, pipe_config);
11596 sw_config = to_intel_crtc_state(new_crtc_state);
11597 if (!intel_pipe_config_compare(dev_priv, sw_config,
11598 pipe_config, false)) {
11599 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11600 intel_dump_pipe_config(intel_crtc, pipe_config,
11602 intel_dump_pipe_config(intel_crtc, sw_config,
11608 intel_verify_planes(struct intel_atomic_state *state)
11610 struct intel_plane *plane;
11611 const struct intel_plane_state *plane_state;
11614 for_each_new_intel_plane_in_state(state, plane,
11616 assert_plane(plane, plane_state->base.visible);
11620 verify_single_dpll_state(struct drm_i915_private *dev_priv,
11621 struct intel_shared_dpll *pll,
11622 struct drm_crtc *crtc,
11623 struct drm_crtc_state *new_state)
11625 struct intel_dpll_hw_state dpll_hw_state;
11626 unsigned crtc_mask;
11629 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
11631 DRM_DEBUG_KMS("%s\n", pll->name);
11633 active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state);
11635 if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) {
11636 I915_STATE_WARN(!pll->on && pll->active_mask,
11637 "pll in active use but not on in sw tracking\n");
11638 I915_STATE_WARN(pll->on && !pll->active_mask,
11639 "pll is on but not used by any active crtc\n");
11640 I915_STATE_WARN(pll->on != active,
11641 "pll on state mismatch (expected %i, found %i)\n",
11646 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
11647 "more active pll users than references: %x vs %x\n",
11648 pll->active_mask, pll->state.crtc_mask);
11653 crtc_mask = 1 << drm_crtc_index(crtc);
11655 if (new_state->active)
11656 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
11657 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11658 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11660 I915_STATE_WARN(pll->active_mask & crtc_mask,
11661 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11662 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11664 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
11665 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11666 crtc_mask, pll->state.crtc_mask);
11668 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
11670 sizeof(dpll_hw_state)),
11671 "pll hw state mismatch\n");
11675 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
11676 struct drm_crtc_state *old_crtc_state,
11677 struct drm_crtc_state *new_crtc_state)
11679 struct drm_i915_private *dev_priv = to_i915(dev);
11680 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
11681 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
11683 if (new_state->shared_dpll)
11684 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
11686 if (old_state->shared_dpll &&
11687 old_state->shared_dpll != new_state->shared_dpll) {
11688 unsigned crtc_mask = 1 << drm_crtc_index(crtc);
11689 struct intel_shared_dpll *pll = old_state->shared_dpll;
11691 I915_STATE_WARN(pll->active_mask & crtc_mask,
11692 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11693 pipe_name(drm_crtc_index(crtc)));
11694 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
11695 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11696 pipe_name(drm_crtc_index(crtc)));
11701 intel_modeset_verify_crtc(struct drm_crtc *crtc,
11702 struct drm_atomic_state *state,
11703 struct drm_crtc_state *old_state,
11704 struct drm_crtc_state *new_state)
11706 if (!needs_modeset(new_state) &&
11707 !to_intel_crtc_state(new_state)->update_pipe)
11710 verify_wm_state(crtc, new_state);
11711 verify_connector_state(crtc->dev, state, crtc);
11712 verify_crtc_state(crtc, old_state, new_state);
11713 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
11717 verify_disabled_dpll_state(struct drm_device *dev)
11719 struct drm_i915_private *dev_priv = to_i915(dev);
11722 for (i = 0; i < dev_priv->num_shared_dpll; i++)
11723 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
11727 intel_modeset_verify_disabled(struct drm_device *dev,
11728 struct drm_atomic_state *state)
11730 verify_encoder_state(dev, state);
11731 verify_connector_state(dev, state, NULL);
11732 verify_disabled_dpll_state(dev);
11735 static void update_scanline_offset(struct intel_crtc *crtc)
11737 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11740 * The scanline counter increments at the leading edge of hsync.
11742 * On most platforms it starts counting from vtotal-1 on the
11743 * first active line. That means the scanline counter value is
11744 * always one less than what we would expect. Ie. just after
11745 * start of vblank, which also occurs at start of hsync (on the
11746 * last active line), the scanline counter will read vblank_start-1.
11748 * On gen2 the scanline counter starts counting from 1 instead
11749 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11750 * to keep the value positive), instead of adding one.
11752 * On HSW+ the behaviour of the scanline counter depends on the output
11753 * type. For DP ports it behaves like most other platforms, but on HDMI
11754 * there's an extra 1 line difference. So we need to add two instead of
11755 * one to the value.
11757 * On VLV/CHV DSI the scanline counter would appear to increment
11758 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11759 * that means we can't tell whether we're in vblank or not while
11760 * we're on that particular line. We must still set scanline_offset
11761 * to 1 so that the vblank timestamps come out correct when we query
11762 * the scanline counter from within the vblank interrupt handler.
11763 * However if queried just before the start of vblank we'll get an
11764 * answer that's slightly in the future.
11766 if (IS_GEN2(dev_priv)) {
11767 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
11770 vtotal = adjusted_mode->crtc_vtotal;
11771 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
11774 crtc->scanline_offset = vtotal - 1;
11775 } else if (HAS_DDI(dev_priv) &&
11776 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) {
11777 crtc->scanline_offset = 2;
11779 crtc->scanline_offset = 1;
11782 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
11784 struct drm_device *dev = state->dev;
11785 struct drm_i915_private *dev_priv = to_i915(dev);
11786 struct drm_crtc *crtc;
11787 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
11790 if (!dev_priv->display.crtc_compute_clock)
11793 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
11794 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11795 struct intel_shared_dpll *old_dpll =
11796 to_intel_crtc_state(old_crtc_state)->shared_dpll;
11798 if (!needs_modeset(new_crtc_state))
11801 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
11806 intel_release_shared_dpll(old_dpll, intel_crtc, state);
11811 * This implements the workaround described in the "notes" section of the mode
11812 * set sequence documentation. When going from no pipes or single pipe to
11813 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11814 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11816 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
11818 struct drm_crtc_state *crtc_state;
11819 struct intel_crtc *intel_crtc;
11820 struct drm_crtc *crtc;
11821 struct intel_crtc_state *first_crtc_state = NULL;
11822 struct intel_crtc_state *other_crtc_state = NULL;
11823 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
11826 /* look at all crtc's that are going to be enabled in during modeset */
11827 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
11828 intel_crtc = to_intel_crtc(crtc);
11830 if (!crtc_state->active || !needs_modeset(crtc_state))
11833 if (first_crtc_state) {
11834 other_crtc_state = to_intel_crtc_state(crtc_state);
11837 first_crtc_state = to_intel_crtc_state(crtc_state);
11838 first_pipe = intel_crtc->pipe;
11842 /* No workaround needed? */
11843 if (!first_crtc_state)
11846 /* w/a possibly needed, check how many crtc's are already enabled. */
11847 for_each_intel_crtc(state->dev, intel_crtc) {
11848 struct intel_crtc_state *pipe_config;
11850 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
11851 if (IS_ERR(pipe_config))
11852 return PTR_ERR(pipe_config);
11854 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
11856 if (!pipe_config->base.active ||
11857 needs_modeset(&pipe_config->base))
11860 /* 2 or more enabled crtcs means no need for w/a */
11861 if (enabled_pipe != INVALID_PIPE)
11864 enabled_pipe = intel_crtc->pipe;
11867 if (enabled_pipe != INVALID_PIPE)
11868 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
11869 else if (other_crtc_state)
11870 other_crtc_state->hsw_workaround_pipe = first_pipe;
11875 static int intel_lock_all_pipes(struct drm_atomic_state *state)
11877 struct drm_crtc *crtc;
11879 /* Add all pipes to the state */
11880 for_each_crtc(state->dev, crtc) {
11881 struct drm_crtc_state *crtc_state;
11883 crtc_state = drm_atomic_get_crtc_state(state, crtc);
11884 if (IS_ERR(crtc_state))
11885 return PTR_ERR(crtc_state);
11891 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
11893 struct drm_crtc *crtc;
11896 * Add all pipes to the state, and force
11897 * a modeset on all the active ones.
11899 for_each_crtc(state->dev, crtc) {
11900 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);
11907 if (!crtc_state->active || needs_modeset(crtc_state))
11910 crtc_state->mode_changed = true;
11912 ret = drm_atomic_add_affected_connectors(state, crtc);
11916 ret = drm_atomic_add_affected_planes(state, crtc);
11924 static int intel_modeset_checks(struct drm_atomic_state *state)
11926 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
11927 struct drm_i915_private *dev_priv = to_i915(state->dev);
11928 struct drm_crtc *crtc;
11929 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
11932 if (!check_digital_port_conflicts(state)) {
11933 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
11937 intel_state->modeset = true;
11938 intel_state->active_crtcs = dev_priv->active_crtcs;
11939 intel_state->cdclk.logical = dev_priv->cdclk.logical;
11940 intel_state->cdclk.actual = dev_priv->cdclk.actual;
11942 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
11943 if (new_crtc_state->active)
11944 intel_state->active_crtcs |= 1 << i;
11946 intel_state->active_crtcs &= ~(1 << i);
11948 if (old_crtc_state->active != new_crtc_state->active)
11949 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
11953 * See if the config requires any additional preparation, e.g.
11954 * to adjust global state with pipes off. We need to do this
11955 * here so we can get the modeset_pipe updated config for the new
11956 * mode set on this crtc. For other crtcs we need to use the
11957 * adjusted_mode bits in the crtc directly.
11959 if (dev_priv->display.modeset_calc_cdclk) {
11960 ret = dev_priv->display.modeset_calc_cdclk(state);
11965 * Writes to dev_priv->cdclk.logical must protected by
11966 * holding all the crtc locks, even if we don't end up
11967 * touching the hardware
11969 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
11970 &intel_state->cdclk.logical)) {
11971 ret = intel_lock_all_pipes(state);
11976 /* All pipes must be switched off while we change the cdclk. */
11977 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
11978 &intel_state->cdclk.actual)) {
11979 ret = intel_modeset_all_pipes(state);
11984 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
11985 intel_state->cdclk.logical.cdclk,
11986 intel_state->cdclk.actual.cdclk);
11987 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
11988 intel_state->cdclk.logical.voltage_level,
11989 intel_state->cdclk.actual.voltage_level);
11991 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
11994 intel_modeset_clear_plls(state);
11996 if (IS_HASWELL(dev_priv))
11997 return haswell_mode_set_planes_workaround(state);
12003 * Handle calculation of various watermark data at the end of the atomic check
12004 * phase. The code here should be run after the per-crtc and per-plane 'check'
12005 * handlers to ensure that all derived state has been updated.
12007 static int calc_watermark_data(struct drm_atomic_state *state)
12009 struct drm_device *dev = state->dev;
12010 struct drm_i915_private *dev_priv = to_i915(dev);
12012 /* Is there platform-specific watermark information to calculate? */
12013 if (dev_priv->display.compute_global_watermarks)
12014 return dev_priv->display.compute_global_watermarks(state);
12020 * intel_atomic_check - validate state object
12022 * @state: state to validate
12024 static int intel_atomic_check(struct drm_device *dev,
12025 struct drm_atomic_state *state)
12027 struct drm_i915_private *dev_priv = to_i915(dev);
12028 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12029 struct drm_crtc *crtc;
12030 struct drm_crtc_state *old_crtc_state, *crtc_state;
12032 bool any_ms = false;
12034 ret = drm_atomic_helper_check_modeset(dev, state);
12038 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12039 struct intel_crtc_state *pipe_config =
12040 to_intel_crtc_state(crtc_state);
12042 /* Catch I915_MODE_FLAG_INHERITED */
12043 if (crtc_state->mode.private_flags != old_crtc_state->mode.private_flags)
12044 crtc_state->mode_changed = true;
12046 if (!needs_modeset(crtc_state))
12049 if (!crtc_state->enable) {
12054 /* FIXME: For only active_changed we shouldn't need to do any
12055 * state recomputation at all. */
12057 ret = drm_atomic_add_affected_connectors(state, crtc);
12061 ret = intel_modeset_pipe_config(crtc, pipe_config);
12063 intel_dump_pipe_config(to_intel_crtc(crtc),
12064 pipe_config, "[failed]");
12068 if (i915_modparams.fastboot &&
12069 intel_pipe_config_compare(dev_priv,
12070 to_intel_crtc_state(old_crtc_state),
12071 pipe_config, true)) {
12072 crtc_state->mode_changed = false;
12073 pipe_config->update_pipe = true;
12076 if (needs_modeset(crtc_state))
12079 ret = drm_atomic_add_affected_planes(state, crtc);
12083 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12084 needs_modeset(crtc_state) ?
12085 "[modeset]" : "[fastset]");
12089 ret = intel_modeset_checks(state);
12094 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12097 ret = drm_atomic_helper_check_planes(dev, state);
12101 intel_fbc_choose_crtc(dev_priv, intel_state);
12102 return calc_watermark_data(state);
12105 static int intel_atomic_prepare_commit(struct drm_device *dev,
12106 struct drm_atomic_state *state)
12108 return drm_atomic_helper_prepare_planes(dev, state);
12111 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12113 struct drm_device *dev = crtc->base.dev;
12115 if (!dev->max_vblank_count)
12116 return drm_crtc_accurate_vblank_count(&crtc->base);
12118 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12121 static void intel_update_crtc(struct drm_crtc *crtc,
12122 struct drm_atomic_state *state,
12123 struct drm_crtc_state *old_crtc_state,
12124 struct drm_crtc_state *new_crtc_state)
12126 struct drm_device *dev = crtc->dev;
12127 struct drm_i915_private *dev_priv = to_i915(dev);
12128 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12129 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12130 bool modeset = needs_modeset(new_crtc_state);
12133 update_scanline_offset(intel_crtc);
12134 dev_priv->display.crtc_enable(pipe_config, state);
12136 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12140 if (drm_atomic_get_existing_plane_state(state, crtc->primary)) {
12142 intel_crtc, pipe_config,
12143 to_intel_plane_state(crtc->primary->state));
12146 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state);
12149 static void intel_update_crtcs(struct drm_atomic_state *state)
12151 struct drm_crtc *crtc;
12152 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12155 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12156 if (!new_crtc_state->active)
12159 intel_update_crtc(crtc, state, old_crtc_state,
12164 static void skl_update_crtcs(struct drm_atomic_state *state)
12166 struct drm_i915_private *dev_priv = to_i915(state->dev);
12167 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12168 struct drm_crtc *crtc;
12169 struct intel_crtc *intel_crtc;
12170 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12171 struct intel_crtc_state *cstate;
12172 unsigned int updated = 0;
12177 const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
12179 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
12180 /* ignore allocations for crtc's that have been turned off. */
12181 if (new_crtc_state->active)
12182 entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
12185 * Whenever the number of active pipes changes, we need to make sure we
12186 * update the pipes in the right order so that their ddb allocations
12187 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12188 * cause pipe underruns and other bad stuff.
12193 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12194 bool vbl_wait = false;
12195 unsigned int cmask = drm_crtc_mask(crtc);
12197 intel_crtc = to_intel_crtc(crtc);
12198 cstate = to_intel_crtc_state(new_crtc_state);
12199 pipe = intel_crtc->pipe;
12201 if (updated & cmask || !cstate->base.active)
12204 if (skl_ddb_allocation_overlaps(dev_priv,
12206 &cstate->wm.skl.ddb,
12211 entries[i] = &cstate->wm.skl.ddb;
12214 * If this is an already active pipe, it's DDB changed,
12215 * and this isn't the last pipe that needs updating
12216 * then we need to wait for a vblank to pass for the
12217 * new ddb allocation to take effect.
12219 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
12220 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
12221 !new_crtc_state->active_changed &&
12222 intel_state->wm_results.dirty_pipes != updated)
12225 intel_update_crtc(crtc, state, old_crtc_state,
12229 intel_wait_for_vblank(dev_priv, pipe);
12233 } while (progress);
12236 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12238 struct intel_atomic_state *state, *next;
12239 struct llist_node *freed;
12241 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12242 llist_for_each_entry_safe(state, next, freed, freed)
12243 drm_atomic_state_put(&state->base);
12246 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12248 struct drm_i915_private *dev_priv =
12249 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12251 intel_atomic_helper_free_state(dev_priv);
12254 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12256 struct wait_queue_entry wait_fence, wait_reset;
12257 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12259 init_wait_entry(&wait_fence, 0);
12260 init_wait_entry(&wait_reset, 0);
12262 prepare_to_wait(&intel_state->commit_ready.wait,
12263 &wait_fence, TASK_UNINTERRUPTIBLE);
12264 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12265 &wait_reset, TASK_UNINTERRUPTIBLE);
12268 if (i915_sw_fence_done(&intel_state->commit_ready)
12269 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12274 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12275 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12278 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
12280 struct drm_device *dev = state->dev;
12281 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12282 struct drm_i915_private *dev_priv = to_i915(dev);
12283 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12284 struct drm_crtc *crtc;
12285 struct intel_crtc_state *intel_cstate;
12286 u64 put_domains[I915_MAX_PIPES] = {};
12289 intel_atomic_commit_fence_wait(intel_state);
12291 drm_atomic_helper_wait_for_dependencies(state);
12293 if (intel_state->modeset)
12294 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
12296 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12297 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12299 if (needs_modeset(new_crtc_state) ||
12300 to_intel_crtc_state(new_crtc_state)->update_pipe) {
12302 put_domains[to_intel_crtc(crtc)->pipe] =
12303 modeset_get_crtc_power_domains(crtc,
12304 to_intel_crtc_state(new_crtc_state));
12307 if (!needs_modeset(new_crtc_state))
12310 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12311 to_intel_crtc_state(new_crtc_state));
12313 if (old_crtc_state->active) {
12314 intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask);
12315 dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state);
12316 intel_crtc->active = false;
12317 intel_fbc_disable(intel_crtc);
12318 intel_disable_shared_dpll(intel_crtc);
12321 * Underruns don't always raise
12322 * interrupts, so check manually.
12324 intel_check_cpu_fifo_underruns(dev_priv);
12325 intel_check_pch_fifo_underruns(dev_priv);
12327 if (!new_crtc_state->active) {
12329 * Make sure we don't call initial_watermarks
12330 * for ILK-style watermark updates.
12332 * No clue what this is supposed to achieve.
12334 if (INTEL_GEN(dev_priv) >= 9)
12335 dev_priv->display.initial_watermarks(intel_state,
12336 to_intel_crtc_state(new_crtc_state));
12341 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12342 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12343 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
12345 if (intel_state->modeset) {
12346 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12348 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
12351 * SKL workaround: bspec recommends we disable the SAGV when we
12352 * have more then one pipe enabled
12354 if (!intel_can_enable_sagv(state))
12355 intel_disable_sagv(dev_priv);
12357 intel_modeset_verify_disabled(dev, state);
12360 /* Complete the events for pipes that have now been disabled */
12361 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12362 bool modeset = needs_modeset(new_crtc_state);
12364 /* Complete events for now disable pipes here. */
12365 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
12366 spin_lock_irq(&dev->event_lock);
12367 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
12368 spin_unlock_irq(&dev->event_lock);
12370 new_crtc_state->event = NULL;
12374 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12375 dev_priv->display.update_crtcs(state);
12377 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12378 * already, but still need the state for the delayed optimization. To
12380 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12381 * - schedule that vblank worker _before_ calling hw_done
12382 * - at the start of commit_tail, cancel it _synchrously
12383 * - switch over to the vblank wait helper in the core after that since
12384 * we don't need out special handling any more.
12386 drm_atomic_helper_wait_for_flip_done(dev, state);
12389 * Now that the vblank has passed, we can go ahead and program the
12390 * optimal watermarks on platforms that need two-step watermark
12393 * TODO: Move this (and other cleanup) to an async worker eventually.
12395 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12396 intel_cstate = to_intel_crtc_state(new_crtc_state);
12398 if (dev_priv->display.optimize_watermarks)
12399 dev_priv->display.optimize_watermarks(intel_state,
12403 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12404 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12406 if (put_domains[i])
12407 modeset_put_power_domains(dev_priv, put_domains[i]);
12409 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
12412 if (intel_state->modeset)
12413 intel_verify_planes(intel_state);
12415 if (intel_state->modeset && intel_can_enable_sagv(state))
12416 intel_enable_sagv(dev_priv);
12418 drm_atomic_helper_commit_hw_done(state);
12420 if (intel_state->modeset) {
12421 /* As one of the primary mmio accessors, KMS has a high
12422 * likelihood of triggering bugs in unclaimed access. After we
12423 * finish modesetting, see if an error has been flagged, and if
12424 * so enable debugging for the next modeset - and hope we catch
12427 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
12428 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
12431 drm_atomic_helper_cleanup_planes(dev, state);
12433 drm_atomic_helper_commit_cleanup_done(state);
12435 drm_atomic_state_put(state);
12437 intel_atomic_helper_free_state(dev_priv);
12440 static void intel_atomic_commit_work(struct work_struct *work)
12442 struct drm_atomic_state *state =
12443 container_of(work, struct drm_atomic_state, commit_work);
12445 intel_atomic_commit_tail(state);
12448 static int __i915_sw_fence_call
12449 intel_atomic_commit_ready(struct i915_sw_fence *fence,
12450 enum i915_sw_fence_notify notify)
12452 struct intel_atomic_state *state =
12453 container_of(fence, struct intel_atomic_state, commit_ready);
12456 case FENCE_COMPLETE:
12457 /* we do blocking waits in the worker, nothing to do here */
12461 struct intel_atomic_helper *helper =
12462 &to_i915(state->base.dev)->atomic_helper;
12464 if (llist_add(&state->freed, &helper->free_list))
12465 schedule_work(&helper->free_work);
12470 return NOTIFY_DONE;
12473 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
12475 struct drm_plane_state *old_plane_state, *new_plane_state;
12476 struct drm_plane *plane;
12479 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
12480 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
12481 intel_fb_obj(new_plane_state->fb),
12482 to_intel_plane(plane)->frontbuffer_bit);
12486 * intel_atomic_commit - commit validated state object
12488 * @state: the top-level driver state object
12489 * @nonblock: nonblocking commit
12491 * This function commits a top-level state object that has been validated
12492 * with drm_atomic_helper_check().
12495 * Zero for success or -errno.
12497 static int intel_atomic_commit(struct drm_device *dev,
12498 struct drm_atomic_state *state,
12501 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12502 struct drm_i915_private *dev_priv = to_i915(dev);
12505 drm_atomic_state_get(state);
12506 i915_sw_fence_init(&intel_state->commit_ready,
12507 intel_atomic_commit_ready);
12510 * The intel_legacy_cursor_update() fast path takes care
12511 * of avoiding the vblank waits for simple cursor
12512 * movement and flips. For cursor on/off and size changes,
12513 * we want to perform the vblank waits so that watermark
12514 * updates happen during the correct frames. Gen9+ have
12515 * double buffered watermarks and so shouldn't need this.
12517 * Unset state->legacy_cursor_update before the call to
12518 * drm_atomic_helper_setup_commit() because otherwise
12519 * drm_atomic_helper_wait_for_flip_done() is a noop and
12520 * we get FIFO underruns because we didn't wait
12523 * FIXME doing watermarks and fb cleanup from a vblank worker
12524 * (assuming we had any) would solve these problems.
12526 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
12527 struct intel_crtc_state *new_crtc_state;
12528 struct intel_crtc *crtc;
12531 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
12532 if (new_crtc_state->wm.need_postvbl_update ||
12533 new_crtc_state->update_wm_post)
12534 state->legacy_cursor_update = false;
12537 ret = intel_atomic_prepare_commit(dev, state);
12539 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
12540 i915_sw_fence_commit(&intel_state->commit_ready);
12544 ret = drm_atomic_helper_setup_commit(state, nonblock);
12546 ret = drm_atomic_helper_swap_state(state, true);
12549 i915_sw_fence_commit(&intel_state->commit_ready);
12551 drm_atomic_helper_cleanup_planes(dev, state);
12554 dev_priv->wm.distrust_bios_wm = false;
12555 intel_shared_dpll_swap_state(state);
12556 intel_atomic_track_fbs(state);
12558 if (intel_state->modeset) {
12559 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
12560 sizeof(intel_state->min_cdclk));
12561 memcpy(dev_priv->min_voltage_level,
12562 intel_state->min_voltage_level,
12563 sizeof(intel_state->min_voltage_level));
12564 dev_priv->active_crtcs = intel_state->active_crtcs;
12565 dev_priv->cdclk.logical = intel_state->cdclk.logical;
12566 dev_priv->cdclk.actual = intel_state->cdclk.actual;
12569 drm_atomic_state_get(state);
12570 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
12572 i915_sw_fence_commit(&intel_state->commit_ready);
12574 queue_work(system_unbound_wq, &state->commit_work);
12576 intel_atomic_commit_tail(state);
12582 static const struct drm_crtc_funcs intel_crtc_funcs = {
12583 .gamma_set = drm_atomic_helper_legacy_gamma_set,
12584 .set_config = drm_atomic_helper_set_config,
12585 .destroy = intel_crtc_destroy,
12586 .page_flip = drm_atomic_helper_page_flip,
12587 .atomic_duplicate_state = intel_crtc_duplicate_state,
12588 .atomic_destroy_state = intel_crtc_destroy_state,
12589 .set_crc_source = intel_crtc_set_crc_source,
12592 struct wait_rps_boost {
12593 struct wait_queue_entry wait;
12595 struct drm_crtc *crtc;
12596 struct drm_i915_gem_request *request;
12599 static int do_rps_boost(struct wait_queue_entry *_wait,
12600 unsigned mode, int sync, void *key)
12602 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
12603 struct drm_i915_gem_request *rq = wait->request;
12605 gen6_rps_boost(rq, NULL);
12606 i915_gem_request_put(rq);
12608 drm_crtc_vblank_put(wait->crtc);
12610 list_del(&wait->wait.entry);
12615 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
12616 struct dma_fence *fence)
12618 struct wait_rps_boost *wait;
12620 if (!dma_fence_is_i915(fence))
12623 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
12626 if (drm_crtc_vblank_get(crtc))
12629 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
12631 drm_crtc_vblank_put(crtc);
12635 wait->request = to_request(dma_fence_get(fence));
12638 wait->wait.func = do_rps_boost;
12639 wait->wait.flags = 0;
12641 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
12645 * intel_prepare_plane_fb - Prepare fb for usage on plane
12646 * @plane: drm plane to prepare for
12647 * @fb: framebuffer to prepare for presentation
12649 * Prepares a framebuffer for usage on a display plane. Generally this
12650 * involves pinning the underlying object and updating the frontbuffer tracking
12651 * bits. Some older platforms need special physical address handling for
12654 * Must be called with struct_mutex held.
12656 * Returns 0 on success, negative error code on failure.
12659 intel_prepare_plane_fb(struct drm_plane *plane,
12660 struct drm_plane_state *new_state)
12662 struct intel_atomic_state *intel_state =
12663 to_intel_atomic_state(new_state->state);
12664 struct drm_i915_private *dev_priv = to_i915(plane->dev);
12665 struct drm_framebuffer *fb = new_state->fb;
12666 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12667 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
12671 struct drm_crtc_state *crtc_state =
12672 drm_atomic_get_existing_crtc_state(new_state->state,
12673 plane->state->crtc);
12675 /* Big Hammer, we also need to ensure that any pending
12676 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
12677 * current scanout is retired before unpinning the old
12678 * framebuffer. Note that we rely on userspace rendering
12679 * into the buffer attached to the pipe they are waiting
12680 * on. If not, userspace generates a GPU hang with IPEHR
12681 * point to the MI_WAIT_FOR_EVENT.
12683 * This should only fail upon a hung GPU, in which case we
12684 * can safely continue.
12686 if (needs_modeset(crtc_state)) {
12687 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
12688 old_obj->resv, NULL,
12696 if (new_state->fence) { /* explicit fencing */
12697 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
12699 I915_FENCE_TIMEOUT,
12708 ret = i915_gem_object_pin_pages(obj);
12712 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
12714 i915_gem_object_unpin_pages(obj);
12718 if (plane->type == DRM_PLANE_TYPE_CURSOR &&
12719 INTEL_INFO(dev_priv)->cursor_needs_physical) {
12720 const int align = intel_cursor_alignment(dev_priv);
12722 ret = i915_gem_object_attach_phys(obj, align);
12724 struct i915_vma *vma;
12726 vma = intel_pin_and_fence_fb_obj(fb, new_state->rotation);
12728 to_intel_plane_state(new_state)->vma = vma;
12730 ret = PTR_ERR(vma);
12733 i915_gem_object_wait_priority(obj, 0, I915_PRIORITY_DISPLAY);
12735 mutex_unlock(&dev_priv->drm.struct_mutex);
12736 i915_gem_object_unpin_pages(obj);
12740 if (!new_state->fence) { /* implicit fencing */
12741 struct dma_fence *fence;
12743 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
12745 false, I915_FENCE_TIMEOUT,
12750 fence = reservation_object_get_excl_rcu(obj->resv);
12752 add_rps_boost_after_vblank(new_state->crtc, fence);
12753 dma_fence_put(fence);
12756 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
12763 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12764 * @plane: drm plane to clean up for
12765 * @fb: old framebuffer that was on plane
12767 * Cleans up a framebuffer that has just been removed from a plane.
12769 * Must be called with struct_mutex held.
12772 intel_cleanup_plane_fb(struct drm_plane *plane,
12773 struct drm_plane_state *old_state)
12775 struct i915_vma *vma;
12777 /* Should only be called after a successful intel_prepare_plane_fb()! */
12778 vma = fetch_and_zero(&to_intel_plane_state(old_state)->vma);
12780 mutex_lock(&plane->dev->struct_mutex);
12781 intel_unpin_fb_vma(vma);
12782 mutex_unlock(&plane->dev->struct_mutex);
12787 skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state)
12789 struct drm_i915_private *dev_priv;
12791 int crtc_clock, max_dotclk;
12793 if (!intel_crtc || !crtc_state->base.enable)
12794 return DRM_PLANE_HELPER_NO_SCALING;
12796 dev_priv = to_i915(intel_crtc->base.dev);
12798 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
12799 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
12801 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
12804 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
12805 return DRM_PLANE_HELPER_NO_SCALING;
12808 * skl max scale is lower of:
12809 * close to 3 but not 3, -1 is for that purpose
12813 max_scale = min((1 << 16) * 3 - 1,
12814 (1 << 8) * ((max_dotclk << 8) / crtc_clock));
12820 intel_check_primary_plane(struct intel_plane *plane,
12821 struct intel_crtc_state *crtc_state,
12822 struct intel_plane_state *state)
12824 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
12825 struct drm_crtc *crtc = state->base.crtc;
12826 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
12827 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
12828 bool can_position = false;
12831 if (INTEL_GEN(dev_priv) >= 9) {
12832 /* use scaler when colorkey is not required */
12833 if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
12835 max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state);
12837 can_position = true;
12840 ret = drm_atomic_helper_check_plane_state(&state->base,
12843 min_scale, max_scale,
12844 can_position, true);
12848 if (!state->base.fb)
12851 if (INTEL_GEN(dev_priv) >= 9) {
12852 ret = skl_check_plane_surface(state);
12856 state->ctl = skl_plane_ctl(crtc_state, state);
12858 ret = i9xx_check_plane_surface(state);
12862 state->ctl = i9xx_plane_ctl(crtc_state, state);
12865 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
12866 state->color_ctl = glk_plane_color_ctl(crtc_state, state);
12871 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
12872 struct drm_crtc_state *old_crtc_state)
12874 struct drm_device *dev = crtc->dev;
12875 struct drm_i915_private *dev_priv = to_i915(dev);
12876 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12877 struct intel_crtc_state *old_intel_cstate =
12878 to_intel_crtc_state(old_crtc_state);
12879 struct intel_atomic_state *old_intel_state =
12880 to_intel_atomic_state(old_crtc_state->state);
12881 struct intel_crtc_state *intel_cstate =
12882 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
12883 bool modeset = needs_modeset(&intel_cstate->base);
12886 (intel_cstate->base.color_mgmt_changed ||
12887 intel_cstate->update_pipe)) {
12888 intel_color_set_csc(&intel_cstate->base);
12889 intel_color_load_luts(&intel_cstate->base);
12892 /* Perform vblank evasion around commit operation */
12893 intel_pipe_update_start(intel_cstate);
12898 if (intel_cstate->update_pipe)
12899 intel_update_pipe_config(old_intel_cstate, intel_cstate);
12900 else if (INTEL_GEN(dev_priv) >= 9)
12901 skl_detach_scalers(intel_crtc);
12904 if (dev_priv->display.atomic_update_watermarks)
12905 dev_priv->display.atomic_update_watermarks(old_intel_state,
12909 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
12910 struct drm_crtc_state *old_crtc_state)
12912 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
12913 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12914 struct intel_atomic_state *old_intel_state =
12915 to_intel_atomic_state(old_crtc_state->state);
12916 struct intel_crtc_state *new_crtc_state =
12917 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
12919 intel_pipe_update_end(new_crtc_state);
12921 if (new_crtc_state->update_pipe &&
12922 !needs_modeset(&new_crtc_state->base) &&
12923 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) {
12924 if (!IS_GEN2(dev_priv))
12925 intel_set_cpu_fifo_underrun_reporting(dev_priv, intel_crtc->pipe, true);
12927 if (new_crtc_state->has_pch_encoder) {
12928 enum pipe pch_transcoder =
12929 intel_crtc_pch_transcoder(intel_crtc);
12931 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
12937 * intel_plane_destroy - destroy a plane
12938 * @plane: plane to destroy
12940 * Common destruction function for all types of planes (primary, cursor,
12943 void intel_plane_destroy(struct drm_plane *plane)
12945 drm_plane_cleanup(plane);
12946 kfree(to_intel_plane(plane));
12949 static bool i8xx_mod_supported(uint32_t format, uint64_t modifier)
12952 case DRM_FORMAT_C8:
12953 case DRM_FORMAT_RGB565:
12954 case DRM_FORMAT_XRGB1555:
12955 case DRM_FORMAT_XRGB8888:
12956 return modifier == DRM_FORMAT_MOD_LINEAR ||
12957 modifier == I915_FORMAT_MOD_X_TILED;
12963 static bool i965_mod_supported(uint32_t format, uint64_t modifier)
12966 case DRM_FORMAT_C8:
12967 case DRM_FORMAT_RGB565:
12968 case DRM_FORMAT_XRGB8888:
12969 case DRM_FORMAT_XBGR8888:
12970 case DRM_FORMAT_XRGB2101010:
12971 case DRM_FORMAT_XBGR2101010:
12972 return modifier == DRM_FORMAT_MOD_LINEAR ||
12973 modifier == I915_FORMAT_MOD_X_TILED;
12979 static bool skl_mod_supported(uint32_t format, uint64_t modifier)
12982 case DRM_FORMAT_XRGB8888:
12983 case DRM_FORMAT_XBGR8888:
12984 case DRM_FORMAT_ARGB8888:
12985 case DRM_FORMAT_ABGR8888:
12986 if (modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
12987 modifier == I915_FORMAT_MOD_Y_TILED_CCS)
12990 case DRM_FORMAT_RGB565:
12991 case DRM_FORMAT_XRGB2101010:
12992 case DRM_FORMAT_XBGR2101010:
12993 case DRM_FORMAT_YUYV:
12994 case DRM_FORMAT_YVYU:
12995 case DRM_FORMAT_UYVY:
12996 case DRM_FORMAT_VYUY:
12997 if (modifier == I915_FORMAT_MOD_Yf_TILED)
13000 case DRM_FORMAT_C8:
13001 if (modifier == DRM_FORMAT_MOD_LINEAR ||
13002 modifier == I915_FORMAT_MOD_X_TILED ||
13003 modifier == I915_FORMAT_MOD_Y_TILED)
13011 static bool intel_primary_plane_format_mod_supported(struct drm_plane *plane,
13015 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13017 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
13020 if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
13021 modifier != DRM_FORMAT_MOD_LINEAR)
13024 if (INTEL_GEN(dev_priv) >= 9)
13025 return skl_mod_supported(format, modifier);
13026 else if (INTEL_GEN(dev_priv) >= 4)
13027 return i965_mod_supported(format, modifier);
13029 return i8xx_mod_supported(format, modifier);
13034 static bool intel_cursor_plane_format_mod_supported(struct drm_plane *plane,
13038 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
13041 return modifier == DRM_FORMAT_MOD_LINEAR && format == DRM_FORMAT_ARGB8888;
13044 static struct drm_plane_funcs intel_plane_funcs = {
13045 .update_plane = drm_atomic_helper_update_plane,
13046 .disable_plane = drm_atomic_helper_disable_plane,
13047 .destroy = intel_plane_destroy,
13048 .atomic_get_property = intel_plane_atomic_get_property,
13049 .atomic_set_property = intel_plane_atomic_set_property,
13050 .atomic_duplicate_state = intel_plane_duplicate_state,
13051 .atomic_destroy_state = intel_plane_destroy_state,
13052 .format_mod_supported = intel_primary_plane_format_mod_supported,
13056 intel_legacy_cursor_update(struct drm_plane *plane,
13057 struct drm_crtc *crtc,
13058 struct drm_framebuffer *fb,
13059 int crtc_x, int crtc_y,
13060 unsigned int crtc_w, unsigned int crtc_h,
13061 uint32_t src_x, uint32_t src_y,
13062 uint32_t src_w, uint32_t src_h,
13063 struct drm_modeset_acquire_ctx *ctx)
13065 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13067 struct drm_plane_state *old_plane_state, *new_plane_state;
13068 struct intel_plane *intel_plane = to_intel_plane(plane);
13069 struct drm_framebuffer *old_fb;
13070 struct drm_crtc_state *crtc_state = crtc->state;
13071 struct i915_vma *old_vma, *vma;
13074 * When crtc is inactive or there is a modeset pending,
13075 * wait for it to complete in the slowpath
13077 if (!crtc_state->active || needs_modeset(crtc_state) ||
13078 to_intel_crtc_state(crtc_state)->update_pipe)
13081 old_plane_state = plane->state;
13083 * Don't do an async update if there is an outstanding commit modifying
13084 * the plane. This prevents our async update's changes from getting
13085 * overridden by a previous synchronous update's state.
13087 if (old_plane_state->commit &&
13088 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13092 * If any parameters change that may affect watermarks,
13093 * take the slowpath. Only changing fb or position should be
13096 if (old_plane_state->crtc != crtc ||
13097 old_plane_state->src_w != src_w ||
13098 old_plane_state->src_h != src_h ||
13099 old_plane_state->crtc_w != crtc_w ||
13100 old_plane_state->crtc_h != crtc_h ||
13101 !old_plane_state->fb != !fb)
13104 new_plane_state = intel_plane_duplicate_state(plane);
13105 if (!new_plane_state)
13108 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13110 new_plane_state->src_x = src_x;
13111 new_plane_state->src_y = src_y;
13112 new_plane_state->src_w = src_w;
13113 new_plane_state->src_h = src_h;
13114 new_plane_state->crtc_x = crtc_x;
13115 new_plane_state->crtc_y = crtc_y;
13116 new_plane_state->crtc_w = crtc_w;
13117 new_plane_state->crtc_h = crtc_h;
13119 ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state),
13120 to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */
13121 to_intel_plane_state(plane->state),
13122 to_intel_plane_state(new_plane_state));
13126 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13130 if (INTEL_INFO(dev_priv)->cursor_needs_physical) {
13131 int align = intel_cursor_alignment(dev_priv);
13133 ret = i915_gem_object_attach_phys(intel_fb_obj(fb), align);
13135 DRM_DEBUG_KMS("failed to attach phys object\n");
13139 vma = intel_pin_and_fence_fb_obj(fb, new_plane_state->rotation);
13141 DRM_DEBUG_KMS("failed to pin object\n");
13143 ret = PTR_ERR(vma);
13147 to_intel_plane_state(new_plane_state)->vma = vma;
13150 old_fb = old_plane_state->fb;
13152 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13153 intel_plane->frontbuffer_bit);
13155 /* Swap plane state */
13156 plane->state = new_plane_state;
13158 if (plane->state->visible) {
13159 trace_intel_update_plane(plane, to_intel_crtc(crtc));
13160 intel_plane->update_plane(intel_plane,
13161 to_intel_crtc_state(crtc->state),
13162 to_intel_plane_state(plane->state));
13164 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
13165 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
13168 old_vma = fetch_and_zero(&to_intel_plane_state(old_plane_state)->vma);
13170 intel_unpin_fb_vma(old_vma);
13173 mutex_unlock(&dev_priv->drm.struct_mutex);
13176 intel_plane_destroy_state(plane, new_plane_state);
13178 intel_plane_destroy_state(plane, old_plane_state);
13182 return drm_atomic_helper_update_plane(plane, crtc, fb,
13183 crtc_x, crtc_y, crtc_w, crtc_h,
13184 src_x, src_y, src_w, src_h, ctx);
13187 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13188 .update_plane = intel_legacy_cursor_update,
13189 .disable_plane = drm_atomic_helper_disable_plane,
13190 .destroy = intel_plane_destroy,
13191 .atomic_get_property = intel_plane_atomic_get_property,
13192 .atomic_set_property = intel_plane_atomic_set_property,
13193 .atomic_duplicate_state = intel_plane_duplicate_state,
13194 .atomic_destroy_state = intel_plane_destroy_state,
13195 .format_mod_supported = intel_cursor_plane_format_mod_supported,
13198 static struct intel_plane *
13199 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
13201 struct intel_plane *primary = NULL;
13202 struct intel_plane_state *state = NULL;
13203 const uint32_t *intel_primary_formats;
13204 unsigned int supported_rotations;
13205 unsigned int num_formats;
13206 const uint64_t *modifiers;
13209 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
13215 state = intel_create_plane_state(&primary->base);
13221 primary->base.state = &state->base;
13223 primary->can_scale = false;
13224 primary->max_downscale = 1;
13225 if (INTEL_GEN(dev_priv) >= 9) {
13226 primary->can_scale = true;
13227 state->scaler_id = -1;
13229 primary->pipe = pipe;
13231 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13232 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13234 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
13235 primary->i9xx_plane = (enum i9xx_plane_id) !pipe;
13237 primary->i9xx_plane = (enum i9xx_plane_id) pipe;
13238 primary->id = PLANE_PRIMARY;
13239 primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe);
13240 primary->check_plane = intel_check_primary_plane;
13242 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
13243 intel_primary_formats = skl_primary_formats;
13244 num_formats = ARRAY_SIZE(skl_primary_formats);
13245 modifiers = skl_format_modifiers_ccs;
13247 primary->update_plane = skl_update_plane;
13248 primary->disable_plane = skl_disable_plane;
13249 primary->get_hw_state = skl_plane_get_hw_state;
13250 } else if (INTEL_GEN(dev_priv) >= 9) {
13251 intel_primary_formats = skl_primary_formats;
13252 num_formats = ARRAY_SIZE(skl_primary_formats);
13254 modifiers = skl_format_modifiers_ccs;
13256 modifiers = skl_format_modifiers_noccs;
13258 primary->update_plane = skl_update_plane;
13259 primary->disable_plane = skl_disable_plane;
13260 primary->get_hw_state = skl_plane_get_hw_state;
13261 } else if (INTEL_GEN(dev_priv) >= 4) {
13262 intel_primary_formats = i965_primary_formats;
13263 num_formats = ARRAY_SIZE(i965_primary_formats);
13264 modifiers = i9xx_format_modifiers;
13266 primary->update_plane = i9xx_update_plane;
13267 primary->disable_plane = i9xx_disable_plane;
13268 primary->get_hw_state = i9xx_plane_get_hw_state;
13270 intel_primary_formats = i8xx_primary_formats;
13271 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13272 modifiers = i9xx_format_modifiers;
13274 primary->update_plane = i9xx_update_plane;
13275 primary->disable_plane = i9xx_disable_plane;
13276 primary->get_hw_state = i9xx_plane_get_hw_state;
13279 if (INTEL_GEN(dev_priv) >= 9)
13280 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13281 0, &intel_plane_funcs,
13282 intel_primary_formats, num_formats,
13284 DRM_PLANE_TYPE_PRIMARY,
13285 "plane 1%c", pipe_name(pipe));
13286 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
13287 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13288 0, &intel_plane_funcs,
13289 intel_primary_formats, num_formats,
13291 DRM_PLANE_TYPE_PRIMARY,
13292 "primary %c", pipe_name(pipe));
13294 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13295 0, &intel_plane_funcs,
13296 intel_primary_formats, num_formats,
13298 DRM_PLANE_TYPE_PRIMARY,
13300 plane_name(primary->i9xx_plane));
13304 if (INTEL_GEN(dev_priv) >= 9) {
13305 supported_rotations =
13306 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13307 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
13308 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13309 supported_rotations =
13310 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13311 DRM_MODE_REFLECT_X;
13312 } else if (INTEL_GEN(dev_priv) >= 4) {
13313 supported_rotations =
13314 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
13316 supported_rotations = DRM_MODE_ROTATE_0;
13319 if (INTEL_GEN(dev_priv) >= 4)
13320 drm_plane_create_rotation_property(&primary->base,
13322 supported_rotations);
13324 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
13332 return ERR_PTR(ret);
13335 static struct intel_plane *
13336 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13339 struct intel_plane *cursor = NULL;
13340 struct intel_plane_state *state = NULL;
13343 cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
13349 state = intel_create_plane_state(&cursor->base);
13355 cursor->base.state = &state->base;
13357 cursor->can_scale = false;
13358 cursor->max_downscale = 1;
13359 cursor->pipe = pipe;
13360 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
13361 cursor->id = PLANE_CURSOR;
13362 cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe);
13364 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
13365 cursor->update_plane = i845_update_cursor;
13366 cursor->disable_plane = i845_disable_cursor;
13367 cursor->get_hw_state = i845_cursor_get_hw_state;
13368 cursor->check_plane = i845_check_cursor;
13370 cursor->update_plane = i9xx_update_cursor;
13371 cursor->disable_plane = i9xx_disable_cursor;
13372 cursor->get_hw_state = i9xx_cursor_get_hw_state;
13373 cursor->check_plane = i9xx_check_cursor;
13376 cursor->cursor.base = ~0;
13377 cursor->cursor.cntl = ~0;
13379 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13380 cursor->cursor.size = ~0;
13382 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
13383 0, &intel_cursor_plane_funcs,
13384 intel_cursor_formats,
13385 ARRAY_SIZE(intel_cursor_formats),
13386 cursor_format_modifiers,
13387 DRM_PLANE_TYPE_CURSOR,
13388 "cursor %c", pipe_name(pipe));
13392 if (INTEL_GEN(dev_priv) >= 4)
13393 drm_plane_create_rotation_property(&cursor->base,
13395 DRM_MODE_ROTATE_0 |
13396 DRM_MODE_ROTATE_180);
13398 if (INTEL_GEN(dev_priv) >= 9)
13399 state->scaler_id = -1;
13401 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13409 return ERR_PTR(ret);
13412 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
13413 struct intel_crtc_state *crtc_state)
13415 struct intel_crtc_scaler_state *scaler_state =
13416 &crtc_state->scaler_state;
13417 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13420 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
13421 if (!crtc->num_scalers)
13424 for (i = 0; i < crtc->num_scalers; i++) {
13425 struct intel_scaler *scaler = &scaler_state->scalers[i];
13427 scaler->in_use = 0;
13428 scaler->mode = PS_SCALER_MODE_DYN;
13431 scaler_state->scaler_id = -1;
13434 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
13436 struct intel_crtc *intel_crtc;
13437 struct intel_crtc_state *crtc_state = NULL;
13438 struct intel_plane *primary = NULL;
13439 struct intel_plane *cursor = NULL;
13442 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
13446 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
13451 intel_crtc->config = crtc_state;
13452 intel_crtc->base.state = &crtc_state->base;
13453 crtc_state->base.crtc = &intel_crtc->base;
13455 primary = intel_primary_plane_create(dev_priv, pipe);
13456 if (IS_ERR(primary)) {
13457 ret = PTR_ERR(primary);
13460 intel_crtc->plane_ids_mask |= BIT(primary->id);
13462 for_each_sprite(dev_priv, pipe, sprite) {
13463 struct intel_plane *plane;
13465 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
13466 if (IS_ERR(plane)) {
13467 ret = PTR_ERR(plane);
13470 intel_crtc->plane_ids_mask |= BIT(plane->id);
13473 cursor = intel_cursor_plane_create(dev_priv, pipe);
13474 if (IS_ERR(cursor)) {
13475 ret = PTR_ERR(cursor);
13478 intel_crtc->plane_ids_mask |= BIT(cursor->id);
13480 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
13481 &primary->base, &cursor->base,
13483 "pipe %c", pipe_name(pipe));
13487 intel_crtc->pipe = pipe;
13489 /* initialize shared scalers */
13490 intel_crtc_init_scalers(intel_crtc, crtc_state);
13492 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
13493 dev_priv->plane_to_crtc_mapping[primary->i9xx_plane] != NULL);
13494 dev_priv->plane_to_crtc_mapping[primary->i9xx_plane] = intel_crtc;
13495 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = intel_crtc;
13497 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
13499 intel_color_init(&intel_crtc->base);
13501 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
13507 * drm_mode_config_cleanup() will free up any
13508 * crtcs/planes already initialized.
13516 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
13518 struct drm_device *dev = connector->base.dev;
13520 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
13522 if (!connector->base.state->crtc)
13523 return INVALID_PIPE;
13525 return to_intel_crtc(connector->base.state->crtc)->pipe;
13528 int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
13529 struct drm_file *file)
13531 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
13532 struct drm_crtc *drmmode_crtc;
13533 struct intel_crtc *crtc;
13535 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
13539 crtc = to_intel_crtc(drmmode_crtc);
13540 pipe_from_crtc_id->pipe = crtc->pipe;
13545 static int intel_encoder_clones(struct intel_encoder *encoder)
13547 struct drm_device *dev = encoder->base.dev;
13548 struct intel_encoder *source_encoder;
13549 int index_mask = 0;
13552 for_each_intel_encoder(dev, source_encoder) {
13553 if (encoders_cloneable(encoder, source_encoder))
13554 index_mask |= (1 << entry);
13562 static bool has_edp_a(struct drm_i915_private *dev_priv)
13564 if (!IS_MOBILE(dev_priv))
13567 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
13570 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
13576 static bool intel_crt_present(struct drm_i915_private *dev_priv)
13578 if (INTEL_GEN(dev_priv) >= 9)
13581 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
13584 if (IS_CHERRYVIEW(dev_priv))
13587 if (HAS_PCH_LPT_H(dev_priv) &&
13588 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
13591 /* DDI E can't be used if DDI A requires 4 lanes */
13592 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
13595 if (!dev_priv->vbt.int_crt_support)
13601 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
13606 if (HAS_DDI(dev_priv))
13609 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13610 * everywhere where registers can be write protected.
13612 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13617 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
13618 u32 val = I915_READ(PP_CONTROL(pps_idx));
13620 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
13621 I915_WRITE(PP_CONTROL(pps_idx), val);
13625 static void intel_pps_init(struct drm_i915_private *dev_priv)
13627 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
13628 dev_priv->pps_mmio_base = PCH_PPS_BASE;
13629 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13630 dev_priv->pps_mmio_base = VLV_PPS_BASE;
13632 dev_priv->pps_mmio_base = PPS_BASE;
13634 intel_pps_unlock_regs_wa(dev_priv);
13637 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
13639 struct intel_encoder *encoder;
13640 bool dpd_is_edp = false;
13642 intel_pps_init(dev_priv);
13645 * intel_edp_init_connector() depends on this completing first, to
13646 * prevent the registeration of both eDP and LVDS and the incorrect
13647 * sharing of the PPS.
13649 intel_lvds_init(dev_priv);
13651 if (intel_crt_present(dev_priv))
13652 intel_crt_init(dev_priv);
13654 if (IS_GEN9_LP(dev_priv)) {
13656 * FIXME: Broxton doesn't support port detection via the
13657 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13658 * detect the ports.
13660 intel_ddi_init(dev_priv, PORT_A);
13661 intel_ddi_init(dev_priv, PORT_B);
13662 intel_ddi_init(dev_priv, PORT_C);
13664 intel_dsi_init(dev_priv);
13665 } else if (HAS_DDI(dev_priv)) {
13669 * Haswell uses DDI functions to detect digital outputs.
13670 * On SKL pre-D0 the strap isn't connected, so we assume
13673 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
13674 /* WaIgnoreDDIAStrap: skl */
13675 if (found || IS_GEN9_BC(dev_priv))
13676 intel_ddi_init(dev_priv, PORT_A);
13678 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
13680 found = I915_READ(SFUSE_STRAP);
13682 if (found & SFUSE_STRAP_DDIB_DETECTED)
13683 intel_ddi_init(dev_priv, PORT_B);
13684 if (found & SFUSE_STRAP_DDIC_DETECTED)
13685 intel_ddi_init(dev_priv, PORT_C);
13686 if (found & SFUSE_STRAP_DDID_DETECTED)
13687 intel_ddi_init(dev_priv, PORT_D);
13689 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13691 if (IS_GEN9_BC(dev_priv) &&
13692 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
13693 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
13694 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
13695 intel_ddi_init(dev_priv, PORT_E);
13697 } else if (HAS_PCH_SPLIT(dev_priv)) {
13699 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
13701 if (has_edp_a(dev_priv))
13702 intel_dp_init(dev_priv, DP_A, PORT_A);
13704 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
13705 /* PCH SDVOB multiplex with HDMIB */
13706 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
13708 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
13709 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
13710 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
13713 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
13714 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
13716 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
13717 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
13719 if (I915_READ(PCH_DP_C) & DP_DETECTED)
13720 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
13722 if (I915_READ(PCH_DP_D) & DP_DETECTED)
13723 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
13724 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
13725 bool has_edp, has_port;
13728 * The DP_DETECTED bit is the latched state of the DDC
13729 * SDA pin at boot. However since eDP doesn't require DDC
13730 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13731 * eDP ports may have been muxed to an alternate function.
13732 * Thus we can't rely on the DP_DETECTED bit alone to detect
13733 * eDP ports. Consult the VBT as well as DP_DETECTED to
13734 * detect eDP ports.
13736 * Sadly the straps seem to be missing sometimes even for HDMI
13737 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
13738 * and VBT for the presence of the port. Additionally we can't
13739 * trust the port type the VBT declares as we've seen at least
13740 * HDMI ports that the VBT claim are DP or eDP.
13742 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
13743 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
13744 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
13745 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
13746 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
13747 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
13749 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
13750 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
13751 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
13752 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
13753 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
13754 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
13756 if (IS_CHERRYVIEW(dev_priv)) {
13758 * eDP not supported on port D,
13759 * so no need to worry about it
13761 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
13762 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
13763 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
13764 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
13765 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
13768 intel_dsi_init(dev_priv);
13769 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
13770 bool found = false;
13772 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
13773 DRM_DEBUG_KMS("probing SDVOB\n");
13774 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
13775 if (!found && IS_G4X(dev_priv)) {
13776 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
13777 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
13780 if (!found && IS_G4X(dev_priv))
13781 intel_dp_init(dev_priv, DP_B, PORT_B);
13784 /* Before G4X SDVOC doesn't have its own detect register */
13786 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
13787 DRM_DEBUG_KMS("probing SDVOC\n");
13788 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
13791 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
13793 if (IS_G4X(dev_priv)) {
13794 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
13795 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
13797 if (IS_G4X(dev_priv))
13798 intel_dp_init(dev_priv, DP_C, PORT_C);
13801 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
13802 intel_dp_init(dev_priv, DP_D, PORT_D);
13803 } else if (IS_GEN2(dev_priv))
13804 intel_dvo_init(dev_priv);
13806 if (SUPPORTS_TV(dev_priv))
13807 intel_tv_init(dev_priv);
13809 intel_psr_init(dev_priv);
13811 for_each_intel_encoder(&dev_priv->drm, encoder) {
13812 encoder->base.possible_crtcs = encoder->crtc_mask;
13813 encoder->base.possible_clones =
13814 intel_encoder_clones(encoder);
13817 intel_init_pch_refclk(dev_priv);
13819 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
13822 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
13824 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
13826 drm_framebuffer_cleanup(fb);
13828 i915_gem_object_lock(intel_fb->obj);
13829 WARN_ON(!intel_fb->obj->framebuffer_references--);
13830 i915_gem_object_unlock(intel_fb->obj);
13832 i915_gem_object_put(intel_fb->obj);
13837 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
13838 struct drm_file *file,
13839 unsigned int *handle)
13841 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
13842 struct drm_i915_gem_object *obj = intel_fb->obj;
13844 if (obj->userptr.mm) {
13845 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
13849 return drm_gem_handle_create(file, &obj->base, handle);
13852 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
13853 struct drm_file *file,
13854 unsigned flags, unsigned color,
13855 struct drm_clip_rect *clips,
13856 unsigned num_clips)
13858 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13860 i915_gem_object_flush_if_display(obj);
13861 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13866 static const struct drm_framebuffer_funcs intel_fb_funcs = {
13867 .destroy = intel_user_framebuffer_destroy,
13868 .create_handle = intel_user_framebuffer_create_handle,
13869 .dirty = intel_user_framebuffer_dirty,
13873 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
13874 uint64_t fb_modifier, uint32_t pixel_format)
13876 u32 gen = INTEL_GEN(dev_priv);
13879 int cpp = drm_format_plane_cpp(pixel_format, 0);
13881 /* "The stride in bytes must not exceed the of the size of 8K
13882 * pixels and 32K bytes."
13884 return min(8192 * cpp, 32768);
13885 } else if (gen >= 5 && !HAS_GMCH_DISPLAY(dev_priv)) {
13887 } else if (gen >= 4) {
13888 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
13892 } else if (gen >= 3) {
13893 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
13898 /* XXX DSPC is limited to 4k tiled */
13903 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
13904 struct drm_i915_gem_object *obj,
13905 struct drm_mode_fb_cmd2 *mode_cmd)
13907 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
13908 struct drm_framebuffer *fb = &intel_fb->base;
13909 struct drm_format_name_buf format_name;
13911 unsigned int tiling, stride;
13915 i915_gem_object_lock(obj);
13916 obj->framebuffer_references++;
13917 tiling = i915_gem_object_get_tiling(obj);
13918 stride = i915_gem_object_get_stride(obj);
13919 i915_gem_object_unlock(obj);
13921 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
13923 * If there's a fence, enforce that
13924 * the fb modifier and tiling mode match.
13926 if (tiling != I915_TILING_NONE &&
13927 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
13928 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
13932 if (tiling == I915_TILING_X) {
13933 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
13934 } else if (tiling == I915_TILING_Y) {
13935 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
13940 /* Passed in modifier sanity checking. */
13941 switch (mode_cmd->modifier[0]) {
13942 case I915_FORMAT_MOD_Y_TILED_CCS:
13943 case I915_FORMAT_MOD_Yf_TILED_CCS:
13944 switch (mode_cmd->pixel_format) {
13945 case DRM_FORMAT_XBGR8888:
13946 case DRM_FORMAT_ABGR8888:
13947 case DRM_FORMAT_XRGB8888:
13948 case DRM_FORMAT_ARGB8888:
13951 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
13955 case I915_FORMAT_MOD_Y_TILED:
13956 case I915_FORMAT_MOD_Yf_TILED:
13957 if (INTEL_GEN(dev_priv) < 9) {
13958 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
13959 mode_cmd->modifier[0]);
13962 case DRM_FORMAT_MOD_LINEAR:
13963 case I915_FORMAT_MOD_X_TILED:
13966 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
13967 mode_cmd->modifier[0]);
13972 * gen2/3 display engine uses the fence if present,
13973 * so the tiling mode must match the fb modifier exactly.
13975 if (INTEL_INFO(dev_priv)->gen < 4 &&
13976 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
13977 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
13981 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
13982 mode_cmd->pixel_format);
13983 if (mode_cmd->pitches[0] > pitch_limit) {
13984 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
13985 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
13986 "tiled" : "linear",
13987 mode_cmd->pitches[0], pitch_limit);
13992 * If there's a fence, enforce that
13993 * the fb pitch and fence stride match.
13995 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
13996 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
13997 mode_cmd->pitches[0], stride);
14001 /* Reject formats not supported by any plane early. */
14002 switch (mode_cmd->pixel_format) {
14003 case DRM_FORMAT_C8:
14004 case DRM_FORMAT_RGB565:
14005 case DRM_FORMAT_XRGB8888:
14006 case DRM_FORMAT_ARGB8888:
14008 case DRM_FORMAT_XRGB1555:
14009 if (INTEL_GEN(dev_priv) > 3) {
14010 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14011 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14015 case DRM_FORMAT_ABGR8888:
14016 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
14017 INTEL_GEN(dev_priv) < 9) {
14018 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14019 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14023 case DRM_FORMAT_XBGR8888:
14024 case DRM_FORMAT_XRGB2101010:
14025 case DRM_FORMAT_XBGR2101010:
14026 if (INTEL_GEN(dev_priv) < 4) {
14027 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14028 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14032 case DRM_FORMAT_ABGR2101010:
14033 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
14034 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14035 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14039 case DRM_FORMAT_YUYV:
14040 case DRM_FORMAT_UYVY:
14041 case DRM_FORMAT_YVYU:
14042 case DRM_FORMAT_VYUY:
14043 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
14044 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14045 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14050 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14051 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14055 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14056 if (mode_cmd->offsets[0] != 0)
14059 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14061 for (i = 0; i < fb->format->num_planes; i++) {
14062 u32 stride_alignment;
14064 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14065 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14069 stride_alignment = intel_fb_stride_alignment(fb, i);
14072 * Display WA #0531: skl,bxt,kbl,glk
14074 * Render decompression and plane width > 3840
14075 * combined with horizontal panning requires the
14076 * plane stride to be a multiple of 4. We'll just
14077 * require the entire fb to accommodate that to avoid
14078 * potential runtime errors at plane configuration time.
14080 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
14081 (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
14082 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS))
14083 stride_alignment *= 4;
14085 if (fb->pitches[i] & (stride_alignment - 1)) {
14086 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14087 i, fb->pitches[i], stride_alignment);
14092 intel_fb->obj = obj;
14094 ret = intel_fill_fb_info(dev_priv, fb);
14098 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14100 DRM_ERROR("framebuffer init failed %d\n", ret);
14107 i915_gem_object_lock(obj);
14108 obj->framebuffer_references--;
14109 i915_gem_object_unlock(obj);
14113 static struct drm_framebuffer *
14114 intel_user_framebuffer_create(struct drm_device *dev,
14115 struct drm_file *filp,
14116 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14118 struct drm_framebuffer *fb;
14119 struct drm_i915_gem_object *obj;
14120 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14122 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14124 return ERR_PTR(-ENOENT);
14126 fb = intel_framebuffer_create(obj, &mode_cmd);
14128 i915_gem_object_put(obj);
14133 static void intel_atomic_state_free(struct drm_atomic_state *state)
14135 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14137 drm_atomic_state_default_release(state);
14139 i915_sw_fence_fini(&intel_state->commit_ready);
14144 static const struct drm_mode_config_funcs intel_mode_funcs = {
14145 .fb_create = intel_user_framebuffer_create,
14146 .get_format_info = intel_get_format_info,
14147 .output_poll_changed = intel_fbdev_output_poll_changed,
14148 .atomic_check = intel_atomic_check,
14149 .atomic_commit = intel_atomic_commit,
14150 .atomic_state_alloc = intel_atomic_state_alloc,
14151 .atomic_state_clear = intel_atomic_state_clear,
14152 .atomic_state_free = intel_atomic_state_free,
14156 * intel_init_display_hooks - initialize the display modesetting hooks
14157 * @dev_priv: device private
14159 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14161 intel_init_cdclk_hooks(dev_priv);
14163 if (INTEL_INFO(dev_priv)->gen >= 9) {
14164 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14165 dev_priv->display.get_initial_plane_config =
14166 skylake_get_initial_plane_config;
14167 dev_priv->display.crtc_compute_clock =
14168 haswell_crtc_compute_clock;
14169 dev_priv->display.crtc_enable = haswell_crtc_enable;
14170 dev_priv->display.crtc_disable = haswell_crtc_disable;
14171 } else if (HAS_DDI(dev_priv)) {
14172 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14173 dev_priv->display.get_initial_plane_config =
14174 i9xx_get_initial_plane_config;
14175 dev_priv->display.crtc_compute_clock =
14176 haswell_crtc_compute_clock;
14177 dev_priv->display.crtc_enable = haswell_crtc_enable;
14178 dev_priv->display.crtc_disable = haswell_crtc_disable;
14179 } else if (HAS_PCH_SPLIT(dev_priv)) {
14180 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14181 dev_priv->display.get_initial_plane_config =
14182 i9xx_get_initial_plane_config;
14183 dev_priv->display.crtc_compute_clock =
14184 ironlake_crtc_compute_clock;
14185 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14186 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14187 } else if (IS_CHERRYVIEW(dev_priv)) {
14188 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14189 dev_priv->display.get_initial_plane_config =
14190 i9xx_get_initial_plane_config;
14191 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14192 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14193 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14194 } else if (IS_VALLEYVIEW(dev_priv)) {
14195 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14196 dev_priv->display.get_initial_plane_config =
14197 i9xx_get_initial_plane_config;
14198 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
14199 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14200 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14201 } else if (IS_G4X(dev_priv)) {
14202 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14203 dev_priv->display.get_initial_plane_config =
14204 i9xx_get_initial_plane_config;
14205 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14206 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14207 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14208 } else if (IS_PINEVIEW(dev_priv)) {
14209 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14210 dev_priv->display.get_initial_plane_config =
14211 i9xx_get_initial_plane_config;
14212 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14213 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14214 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14215 } else if (!IS_GEN2(dev_priv)) {
14216 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14217 dev_priv->display.get_initial_plane_config =
14218 i9xx_get_initial_plane_config;
14219 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14220 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14221 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14223 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14224 dev_priv->display.get_initial_plane_config =
14225 i9xx_get_initial_plane_config;
14226 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14227 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14228 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14231 if (IS_GEN5(dev_priv)) {
14232 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14233 } else if (IS_GEN6(dev_priv)) {
14234 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14235 } else if (IS_IVYBRIDGE(dev_priv)) {
14236 /* FIXME: detect B0+ stepping and use auto training */
14237 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14238 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
14239 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14242 if (INTEL_GEN(dev_priv) >= 9)
14243 dev_priv->display.update_crtcs = skl_update_crtcs;
14245 dev_priv->display.update_crtcs = intel_update_crtcs;
14249 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14251 static void quirk_ssc_force_disable(struct drm_device *dev)
14253 struct drm_i915_private *dev_priv = to_i915(dev);
14254 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14255 DRM_INFO("applying lvds SSC disable quirk\n");
14259 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14262 static void quirk_invert_brightness(struct drm_device *dev)
14264 struct drm_i915_private *dev_priv = to_i915(dev);
14265 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14266 DRM_INFO("applying inverted panel brightness quirk\n");
14269 /* Some VBT's incorrectly indicate no backlight is present */
14270 static void quirk_backlight_present(struct drm_device *dev)
14272 struct drm_i915_private *dev_priv = to_i915(dev);
14273 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14274 DRM_INFO("applying backlight present quirk\n");
14277 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
14278 * which is 300 ms greater than eDP spec T12 min.
14280 static void quirk_increase_t12_delay(struct drm_device *dev)
14282 struct drm_i915_private *dev_priv = to_i915(dev);
14284 dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY;
14285 DRM_INFO("Applying T12 delay quirk\n");
14288 struct intel_quirk {
14290 int subsystem_vendor;
14291 int subsystem_device;
14292 void (*hook)(struct drm_device *dev);
14295 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14296 struct intel_dmi_quirk {
14297 void (*hook)(struct drm_device *dev);
14298 const struct dmi_system_id (*dmi_id_list)[];
14301 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
14303 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
14307 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
14309 .dmi_id_list = &(const struct dmi_system_id[]) {
14311 .callback = intel_dmi_reverse_brightness,
14312 .ident = "NCR Corporation",
14313 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
14314 DMI_MATCH(DMI_PRODUCT_NAME, ""),
14317 { } /* terminating entry */
14319 .hook = quirk_invert_brightness,
14323 static struct intel_quirk intel_quirks[] = {
14324 /* Lenovo U160 cannot use SSC on LVDS */
14325 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
14327 /* Sony Vaio Y cannot use SSC on LVDS */
14328 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
14330 /* Acer Aspire 5734Z must invert backlight brightness */
14331 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
14333 /* Acer/eMachines G725 */
14334 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
14336 /* Acer/eMachines e725 */
14337 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
14339 /* Acer/Packard Bell NCL20 */
14340 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
14342 /* Acer Aspire 4736Z */
14343 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
14345 /* Acer Aspire 5336 */
14346 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
14348 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14349 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
14351 /* Acer C720 Chromebook (Core i3 4005U) */
14352 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
14354 /* Apple Macbook 2,1 (Core 2 T7400) */
14355 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
14357 /* Apple Macbook 4,1 */
14358 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
14360 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14361 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
14363 /* HP Chromebook 14 (Celeron 2955U) */
14364 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
14366 /* Dell Chromebook 11 */
14367 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
14369 /* Dell Chromebook 11 (2015 version) */
14370 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
14372 /* Toshiba Satellite P50-C-18C */
14373 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
14376 static void intel_init_quirks(struct drm_device *dev)
14378 struct pci_dev *d = dev->pdev;
14381 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
14382 struct intel_quirk *q = &intel_quirks[i];
14384 if (d->device == q->device &&
14385 (d->subsystem_vendor == q->subsystem_vendor ||
14386 q->subsystem_vendor == PCI_ANY_ID) &&
14387 (d->subsystem_device == q->subsystem_device ||
14388 q->subsystem_device == PCI_ANY_ID))
14391 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
14392 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
14393 intel_dmi_quirks[i].hook(dev);
14397 /* Disable the VGA plane that we never use */
14398 static void i915_disable_vga(struct drm_i915_private *dev_priv)
14400 struct pci_dev *pdev = dev_priv->drm.pdev;
14402 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
14404 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14405 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
14406 outb(SR01, VGA_SR_INDEX);
14407 sr1 = inb(VGA_SR_DATA);
14408 outb(sr1 | 1<<5, VGA_SR_DATA);
14409 vga_put(pdev, VGA_RSRC_LEGACY_IO);
14412 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
14413 POSTING_READ(vga_reg);
14416 void intel_modeset_init_hw(struct drm_device *dev)
14418 struct drm_i915_private *dev_priv = to_i915(dev);
14420 intel_update_cdclk(dev_priv);
14421 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
14422 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
14426 * Calculate what we think the watermarks should be for the state we've read
14427 * out of the hardware and then immediately program those watermarks so that
14428 * we ensure the hardware settings match our internal state.
14430 * We can calculate what we think WM's should be by creating a duplicate of the
14431 * current state (which was constructed during hardware readout) and running it
14432 * through the atomic check code to calculate new watermark values in the
14435 static void sanitize_watermarks(struct drm_device *dev)
14437 struct drm_i915_private *dev_priv = to_i915(dev);
14438 struct drm_atomic_state *state;
14439 struct intel_atomic_state *intel_state;
14440 struct drm_crtc *crtc;
14441 struct drm_crtc_state *cstate;
14442 struct drm_modeset_acquire_ctx ctx;
14446 /* Only supported on platforms that use atomic watermark design */
14447 if (!dev_priv->display.optimize_watermarks)
14451 * We need to hold connection_mutex before calling duplicate_state so
14452 * that the connector loop is protected.
14454 drm_modeset_acquire_init(&ctx, 0);
14456 ret = drm_modeset_lock_all_ctx(dev, &ctx);
14457 if (ret == -EDEADLK) {
14458 drm_modeset_backoff(&ctx);
14460 } else if (WARN_ON(ret)) {
14464 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14465 if (WARN_ON(IS_ERR(state)))
14468 intel_state = to_intel_atomic_state(state);
14471 * Hardware readout is the only time we don't want to calculate
14472 * intermediate watermarks (since we don't trust the current
14475 if (!HAS_GMCH_DISPLAY(dev_priv))
14476 intel_state->skip_intermediate_wm = true;
14478 ret = intel_atomic_check(dev, state);
14481 * If we fail here, it means that the hardware appears to be
14482 * programmed in a way that shouldn't be possible, given our
14483 * understanding of watermark requirements. This might mean a
14484 * mistake in the hardware readout code or a mistake in the
14485 * watermark calculations for a given platform. Raise a WARN
14486 * so that this is noticeable.
14488 * If this actually happens, we'll have to just leave the
14489 * BIOS-programmed watermarks untouched and hope for the best.
14491 WARN(true, "Could not determine valid watermarks for inherited state\n");
14495 /* Write calculated watermark values back */
14496 for_each_new_crtc_in_state(state, crtc, cstate, i) {
14497 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14499 cs->wm.need_postvbl_update = true;
14500 dev_priv->display.optimize_watermarks(intel_state, cs);
14502 to_intel_crtc_state(crtc->state)->wm = cs->wm;
14506 drm_atomic_state_put(state);
14508 drm_modeset_drop_locks(&ctx);
14509 drm_modeset_acquire_fini(&ctx);
14512 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14514 if (IS_GEN5(dev_priv)) {
14516 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14518 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14519 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
14520 dev_priv->fdi_pll_freq = 270000;
14525 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14528 int intel_modeset_init(struct drm_device *dev)
14530 struct drm_i915_private *dev_priv = to_i915(dev);
14531 struct i915_ggtt *ggtt = &dev_priv->ggtt;
14533 struct intel_crtc *crtc;
14535 drm_mode_config_init(dev);
14537 dev->mode_config.min_width = 0;
14538 dev->mode_config.min_height = 0;
14540 dev->mode_config.preferred_depth = 24;
14541 dev->mode_config.prefer_shadow = 1;
14543 dev->mode_config.allow_fb_modifiers = true;
14545 dev->mode_config.funcs = &intel_mode_funcs;
14547 init_llist_head(&dev_priv->atomic_helper.free_list);
14548 INIT_WORK(&dev_priv->atomic_helper.free_work,
14549 intel_atomic_helper_free_state_worker);
14551 intel_init_quirks(dev);
14553 intel_init_pm(dev_priv);
14555 if (INTEL_INFO(dev_priv)->num_pipes == 0)
14559 * There may be no VBT; and if the BIOS enabled SSC we can
14560 * just keep using it to avoid unnecessary flicker. Whereas if the
14561 * BIOS isn't using it, don't assume it will work even if the VBT
14562 * indicates as much.
14564 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
14565 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
14568 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
14569 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14570 bios_lvds_use_ssc ? "en" : "dis",
14571 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
14572 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
14576 if (IS_GEN2(dev_priv)) {
14577 dev->mode_config.max_width = 2048;
14578 dev->mode_config.max_height = 2048;
14579 } else if (IS_GEN3(dev_priv)) {
14580 dev->mode_config.max_width = 4096;
14581 dev->mode_config.max_height = 4096;
14583 dev->mode_config.max_width = 8192;
14584 dev->mode_config.max_height = 8192;
14587 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14588 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
14589 dev->mode_config.cursor_height = 1023;
14590 } else if (IS_GEN2(dev_priv)) {
14591 dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
14592 dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
14594 dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
14595 dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
14598 dev->mode_config.fb_base = ggtt->mappable_base;
14600 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14601 INTEL_INFO(dev_priv)->num_pipes,
14602 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
14604 for_each_pipe(dev_priv, pipe) {
14607 ret = intel_crtc_init(dev_priv, pipe);
14609 drm_mode_config_cleanup(dev);
14614 intel_shared_dpll_init(dev);
14615 intel_update_fdi_pll_freq(dev_priv);
14617 intel_update_czclk(dev_priv);
14618 intel_modeset_init_hw(dev);
14620 if (dev_priv->max_cdclk_freq == 0)
14621 intel_update_max_cdclk(dev_priv);
14623 /* Just disable it once at startup */
14624 i915_disable_vga(dev_priv);
14625 intel_setup_outputs(dev_priv);
14627 drm_modeset_lock_all(dev);
14628 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
14629 drm_modeset_unlock_all(dev);
14631 for_each_intel_crtc(dev, crtc) {
14632 struct intel_initial_plane_config plane_config = {};
14638 * Note that reserving the BIOS fb up front prevents us
14639 * from stuffing other stolen allocations like the ring
14640 * on top. This prevents some ugliness at boot time, and
14641 * can even allow for smooth boot transitions if the BIOS
14642 * fb is large enough for the active pipe configuration.
14644 dev_priv->display.get_initial_plane_config(crtc,
14648 * If the fb is shared between multiple heads, we'll
14649 * just get the first one.
14651 intel_find_initial_plane_obj(crtc, &plane_config);
14655 * Make sure hardware watermarks really match the state we read out.
14656 * Note that we need to do this after reconstructing the BIOS fb's
14657 * since the watermark calculation done here will use pstate->fb.
14659 if (!HAS_GMCH_DISPLAY(dev_priv))
14660 sanitize_watermarks(dev);
14665 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
14667 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
14668 /* 640x480@60Hz, ~25175 kHz */
14669 struct dpll clock = {
14679 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
14681 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
14682 pipe_name(pipe), clock.vco, clock.dot);
14684 fp = i9xx_dpll_compute_fp(&clock);
14685 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
14686 DPLL_VGA_MODE_DIS |
14687 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
14688 PLL_P2_DIVIDE_BY_4 |
14689 PLL_REF_INPUT_DREFCLK |
14692 I915_WRITE(FP0(pipe), fp);
14693 I915_WRITE(FP1(pipe), fp);
14695 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
14696 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
14697 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
14698 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
14699 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
14700 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
14701 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
14704 * Apparently we need to have VGA mode enabled prior to changing
14705 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
14706 * dividers, even though the register value does change.
14708 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
14709 I915_WRITE(DPLL(pipe), dpll);
14711 /* Wait for the clocks to stabilize. */
14712 POSTING_READ(DPLL(pipe));
14715 /* The pixel multiplier can only be updated once the
14716 * DPLL is enabled and the clocks are stable.
14718 * So write it again.
14720 I915_WRITE(DPLL(pipe), dpll);
14722 /* We do this three times for luck */
14723 for (i = 0; i < 3 ; i++) {
14724 I915_WRITE(DPLL(pipe), dpll);
14725 POSTING_READ(DPLL(pipe));
14726 udelay(150); /* wait for warmup */
14729 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
14730 POSTING_READ(PIPECONF(pipe));
14732 intel_wait_for_pipe_scanline_moving(crtc);
14735 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
14737 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
14739 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
14742 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
14743 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
14744 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
14745 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & CURSOR_MODE);
14746 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & CURSOR_MODE);
14748 I915_WRITE(PIPECONF(pipe), 0);
14749 POSTING_READ(PIPECONF(pipe));
14751 intel_wait_for_pipe_scanline_stopped(crtc);
14753 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
14754 POSTING_READ(DPLL(pipe));
14757 static bool intel_plane_mapping_ok(struct intel_crtc *crtc,
14758 struct intel_plane *plane)
14760 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14761 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
14762 u32 val = I915_READ(DSPCNTR(i9xx_plane));
14764 return (val & DISPLAY_PLANE_ENABLE) == 0 ||
14765 (val & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE(crtc->pipe);
14769 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
14771 struct intel_crtc *crtc;
14773 if (INTEL_GEN(dev_priv) >= 4)
14776 for_each_intel_crtc(&dev_priv->drm, crtc) {
14777 struct intel_plane *plane =
14778 to_intel_plane(crtc->base.primary);
14780 if (intel_plane_mapping_ok(crtc, plane))
14783 DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n",
14785 intel_plane_disable_noatomic(crtc, plane);
14789 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
14791 struct drm_device *dev = crtc->base.dev;
14792 struct intel_encoder *encoder;
14794 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
14800 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
14802 struct drm_device *dev = encoder->base.dev;
14803 struct intel_connector *connector;
14805 for_each_connector_on_encoder(dev, &encoder->base, connector)
14811 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
14812 enum pipe pch_transcoder)
14814 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
14815 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
14818 static void intel_sanitize_crtc(struct intel_crtc *crtc,
14819 struct drm_modeset_acquire_ctx *ctx)
14821 struct drm_device *dev = crtc->base.dev;
14822 struct drm_i915_private *dev_priv = to_i915(dev);
14823 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
14825 /* Clear any frame start delays used for debugging left by the BIOS */
14826 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
14827 i915_reg_t reg = PIPECONF(cpu_transcoder);
14830 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
14833 /* restore vblank interrupts to correct state */
14834 drm_crtc_vblank_reset(&crtc->base);
14835 if (crtc->active) {
14836 struct intel_plane *plane;
14838 drm_crtc_vblank_on(&crtc->base);
14840 /* Disable everything but the primary plane */
14841 for_each_intel_plane_on_crtc(dev, crtc, plane) {
14842 const struct intel_plane_state *plane_state =
14843 to_intel_plane_state(plane->base.state);
14845 if (plane_state->base.visible &&
14846 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
14847 intel_plane_disable_noatomic(crtc, plane);
14851 /* Adjust the state of the output pipe according to whether we
14852 * have active connectors/encoders. */
14853 if (crtc->active && !intel_crtc_has_encoders(crtc))
14854 intel_crtc_disable_noatomic(&crtc->base, ctx);
14856 if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) {
14858 * We start out with underrun reporting disabled to avoid races.
14859 * For correct bookkeeping mark this on active crtcs.
14861 * Also on gmch platforms we dont have any hardware bits to
14862 * disable the underrun reporting. Which means we need to start
14863 * out with underrun reporting disabled also on inactive pipes,
14864 * since otherwise we'll complain about the garbage we read when
14865 * e.g. coming up after runtime pm.
14867 * No protection against concurrent access is required - at
14868 * worst a fifo underrun happens which also sets this to false.
14870 crtc->cpu_fifo_underrun_disabled = true;
14872 * We track the PCH trancoder underrun reporting state
14873 * within the crtc. With crtc for pipe A housing the underrun
14874 * reporting state for PCH transcoder A, crtc for pipe B housing
14875 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
14876 * and marking underrun reporting as disabled for the non-existing
14877 * PCH transcoders B and C would prevent enabling the south
14878 * error interrupt (see cpt_can_enable_serr_int()).
14880 if (has_pch_trancoder(dev_priv, crtc->pipe))
14881 crtc->pch_fifo_underrun_disabled = true;
14885 static void intel_sanitize_encoder(struct intel_encoder *encoder)
14887 struct intel_connector *connector;
14889 /* We need to check both for a crtc link (meaning that the
14890 * encoder is active and trying to read from a pipe) and the
14891 * pipe itself being active. */
14892 bool has_active_crtc = encoder->base.crtc &&
14893 to_intel_crtc(encoder->base.crtc)->active;
14895 connector = intel_encoder_find_connector(encoder);
14896 if (connector && !has_active_crtc) {
14897 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
14898 encoder->base.base.id,
14899 encoder->base.name);
14901 /* Connector is active, but has no active pipe. This is
14902 * fallout from our resume register restoring. Disable
14903 * the encoder manually again. */
14904 if (encoder->base.crtc) {
14905 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
14907 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
14908 encoder->base.base.id,
14909 encoder->base.name);
14910 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
14911 if (encoder->post_disable)
14912 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
14914 encoder->base.crtc = NULL;
14916 /* Inconsistent output/port/pipe state happens presumably due to
14917 * a bug in one of the get_hw_state functions. Or someplace else
14918 * in our code, like the register restore mess on resume. Clamp
14919 * things to off as a safer default. */
14921 connector->base.dpms = DRM_MODE_DPMS_OFF;
14922 connector->base.encoder = NULL;
14926 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
14928 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
14930 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
14931 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
14932 i915_disable_vga(dev_priv);
14936 void i915_redisable_vga(struct drm_i915_private *dev_priv)
14938 /* This function can be called both from intel_modeset_setup_hw_state or
14939 * at a very early point in our resume sequence, where the power well
14940 * structures are not yet restored. Since this function is at a very
14941 * paranoid "someone might have enabled VGA while we were not looking"
14942 * level, just check if the power well is enabled instead of trying to
14943 * follow the "don't touch the power well if we don't need it" policy
14944 * the rest of the driver uses. */
14945 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
14948 i915_redisable_vga_power_on(dev_priv);
14950 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
14953 /* FIXME read out full plane state for all planes */
14954 static void readout_plane_state(struct intel_crtc *crtc)
14956 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14957 struct intel_crtc_state *crtc_state =
14958 to_intel_crtc_state(crtc->base.state);
14959 struct intel_plane *plane;
14961 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
14962 struct intel_plane_state *plane_state =
14963 to_intel_plane_state(plane->base.state);
14964 bool visible = plane->get_hw_state(plane);
14966 intel_set_plane_visible(crtc_state, plane_state, visible);
14970 static void intel_modeset_readout_hw_state(struct drm_device *dev)
14972 struct drm_i915_private *dev_priv = to_i915(dev);
14974 struct intel_crtc *crtc;
14975 struct intel_encoder *encoder;
14976 struct intel_connector *connector;
14977 struct drm_connector_list_iter conn_iter;
14980 dev_priv->active_crtcs = 0;
14982 for_each_intel_crtc(dev, crtc) {
14983 struct intel_crtc_state *crtc_state =
14984 to_intel_crtc_state(crtc->base.state);
14986 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
14987 memset(crtc_state, 0, sizeof(*crtc_state));
14988 crtc_state->base.crtc = &crtc->base;
14990 crtc_state->base.active = crtc_state->base.enable =
14991 dev_priv->display.get_pipe_config(crtc, crtc_state);
14993 crtc->base.enabled = crtc_state->base.enable;
14994 crtc->active = crtc_state->base.active;
14996 if (crtc_state->base.active)
14997 dev_priv->active_crtcs |= 1 << crtc->pipe;
14999 readout_plane_state(crtc);
15001 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15002 crtc->base.base.id, crtc->base.name,
15003 enableddisabled(crtc_state->base.active));
15006 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15007 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15009 pll->on = pll->funcs.get_hw_state(dev_priv, pll,
15010 &pll->state.hw_state);
15011 pll->state.crtc_mask = 0;
15012 for_each_intel_crtc(dev, crtc) {
15013 struct intel_crtc_state *crtc_state =
15014 to_intel_crtc_state(crtc->base.state);
15016 if (crtc_state->base.active &&
15017 crtc_state->shared_dpll == pll)
15018 pll->state.crtc_mask |= 1 << crtc->pipe;
15020 pll->active_mask = pll->state.crtc_mask;
15022 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15023 pll->name, pll->state.crtc_mask, pll->on);
15026 for_each_intel_encoder(dev, encoder) {
15029 if (encoder->get_hw_state(encoder, &pipe)) {
15030 struct intel_crtc_state *crtc_state;
15032 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15033 crtc_state = to_intel_crtc_state(crtc->base.state);
15035 encoder->base.crtc = &crtc->base;
15036 encoder->get_config(encoder, crtc_state);
15038 encoder->base.crtc = NULL;
15041 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15042 encoder->base.base.id, encoder->base.name,
15043 enableddisabled(encoder->base.crtc),
15047 drm_connector_list_iter_begin(dev, &conn_iter);
15048 for_each_intel_connector_iter(connector, &conn_iter) {
15049 if (connector->get_hw_state(connector)) {
15050 connector->base.dpms = DRM_MODE_DPMS_ON;
15052 encoder = connector->encoder;
15053 connector->base.encoder = &encoder->base;
15055 if (encoder->base.crtc &&
15056 encoder->base.crtc->state->active) {
15058 * This has to be done during hardware readout
15059 * because anything calling .crtc_disable may
15060 * rely on the connector_mask being accurate.
15062 encoder->base.crtc->state->connector_mask |=
15063 1 << drm_connector_index(&connector->base);
15064 encoder->base.crtc->state->encoder_mask |=
15065 1 << drm_encoder_index(&encoder->base);
15069 connector->base.dpms = DRM_MODE_DPMS_OFF;
15070 connector->base.encoder = NULL;
15072 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15073 connector->base.base.id, connector->base.name,
15074 enableddisabled(connector->base.encoder));
15076 drm_connector_list_iter_end(&conn_iter);
15078 for_each_intel_crtc(dev, crtc) {
15079 struct intel_crtc_state *crtc_state =
15080 to_intel_crtc_state(crtc->base.state);
15083 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15084 if (crtc_state->base.active) {
15085 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15086 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15087 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15090 * The initial mode needs to be set in order to keep
15091 * the atomic core happy. It wants a valid mode if the
15092 * crtc's enabled, so we do the above call.
15094 * But we don't set all the derived state fully, hence
15095 * set a flag to indicate that a full recalculation is
15096 * needed on the next commit.
15098 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
15100 intel_crtc_compute_pixel_rate(crtc_state);
15102 if (dev_priv->display.modeset_calc_cdclk) {
15103 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15104 if (WARN_ON(min_cdclk < 0))
15108 drm_calc_timestamping_constants(&crtc->base,
15109 &crtc_state->base.adjusted_mode);
15110 update_scanline_offset(crtc);
15113 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
15114 dev_priv->min_voltage_level[crtc->pipe] =
15115 crtc_state->min_voltage_level;
15117 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15122 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15124 struct intel_encoder *encoder;
15126 for_each_intel_encoder(&dev_priv->drm, encoder) {
15128 enum intel_display_power_domain domain;
15130 if (!encoder->get_power_domains)
15133 get_domains = encoder->get_power_domains(encoder);
15134 for_each_power_domain(domain, get_domains)
15135 intel_display_power_get(dev_priv, domain);
15139 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15141 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15142 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15143 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15146 if (IS_HASWELL(dev_priv)) {
15148 * WaRsPkgCStateDisplayPMReq:hsw
15149 * System hang if this isn't done before disabling all planes!
15151 I915_WRITE(CHICKEN_PAR1_1,
15152 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15156 /* Scan out the current hw modeset state,
15157 * and sanitizes it to the current state
15160 intel_modeset_setup_hw_state(struct drm_device *dev,
15161 struct drm_modeset_acquire_ctx *ctx)
15163 struct drm_i915_private *dev_priv = to_i915(dev);
15165 struct intel_crtc *crtc;
15166 struct intel_encoder *encoder;
15169 intel_early_display_was(dev_priv);
15170 intel_modeset_readout_hw_state(dev);
15172 /* HW state is read out, now we need to sanitize this mess. */
15173 get_encoder_power_domains(dev_priv);
15175 intel_sanitize_plane_mapping(dev_priv);
15177 for_each_intel_encoder(dev, encoder) {
15178 intel_sanitize_encoder(encoder);
15181 for_each_pipe(dev_priv, pipe) {
15182 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15184 intel_sanitize_crtc(crtc, ctx);
15185 intel_dump_pipe_config(crtc, crtc->config,
15186 "[setup_hw_state]");
15189 intel_modeset_update_connector_atomic_state(dev);
15191 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15192 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15194 if (!pll->on || pll->active_mask)
15197 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
15199 pll->funcs.disable(dev_priv, pll);
15203 if (IS_G4X(dev_priv)) {
15204 g4x_wm_get_hw_state(dev);
15205 g4x_wm_sanitize(dev_priv);
15206 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15207 vlv_wm_get_hw_state(dev);
15208 vlv_wm_sanitize(dev_priv);
15209 } else if (INTEL_GEN(dev_priv) >= 9) {
15210 skl_wm_get_hw_state(dev);
15211 } else if (HAS_PCH_SPLIT(dev_priv)) {
15212 ilk_wm_get_hw_state(dev);
15215 for_each_intel_crtc(dev, crtc) {
15218 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config);
15219 if (WARN_ON(put_domains))
15220 modeset_put_power_domains(dev_priv, put_domains);
15222 intel_display_set_init_power(dev_priv, false);
15224 intel_power_domains_verify_state(dev_priv);
15226 intel_fbc_init_pipe_state(dev_priv);
15229 void intel_display_resume(struct drm_device *dev)
15231 struct drm_i915_private *dev_priv = to_i915(dev);
15232 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15233 struct drm_modeset_acquire_ctx ctx;
15236 dev_priv->modeset_restore_state = NULL;
15238 state->acquire_ctx = &ctx;
15240 drm_modeset_acquire_init(&ctx, 0);
15243 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15244 if (ret != -EDEADLK)
15247 drm_modeset_backoff(&ctx);
15251 ret = __intel_display_resume(dev, state, &ctx);
15253 intel_enable_ipc(dev_priv);
15254 drm_modeset_drop_locks(&ctx);
15255 drm_modeset_acquire_fini(&ctx);
15258 DRM_ERROR("Restoring old state failed with %i\n", ret);
15260 drm_atomic_state_put(state);
15263 int intel_connector_register(struct drm_connector *connector)
15265 struct intel_connector *intel_connector = to_intel_connector(connector);
15268 ret = intel_backlight_device_register(intel_connector);
15278 void intel_connector_unregister(struct drm_connector *connector)
15280 struct intel_connector *intel_connector = to_intel_connector(connector);
15282 intel_backlight_device_unregister(intel_connector);
15283 intel_panel_destroy_backlight(connector);
15286 static void intel_hpd_poll_fini(struct drm_device *dev)
15288 struct intel_connector *connector;
15289 struct drm_connector_list_iter conn_iter;
15291 /* Kill all the work that may have been queued by hpd. */
15292 drm_connector_list_iter_begin(dev, &conn_iter);
15293 for_each_intel_connector_iter(connector, &conn_iter) {
15294 if (connector->modeset_retry_work.func)
15295 cancel_work_sync(&connector->modeset_retry_work);
15297 drm_connector_list_iter_end(&conn_iter);
15300 void intel_modeset_cleanup(struct drm_device *dev)
15302 struct drm_i915_private *dev_priv = to_i915(dev);
15304 flush_work(&dev_priv->atomic_helper.free_work);
15305 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15307 intel_disable_gt_powersave(dev_priv);
15310 * Interrupts and polling as the first thing to avoid creating havoc.
15311 * Too much stuff here (turning of connectors, ...) would
15312 * experience fancy races otherwise.
15314 intel_irq_uninstall(dev_priv);
15317 * Due to the hpd irq storm handling the hotplug work can re-arm the
15318 * poll handlers. Hence disable polling after hpd handling is shut down.
15320 intel_hpd_poll_fini(dev);
15322 /* poll work can call into fbdev, hence clean that up afterwards */
15323 intel_fbdev_fini(dev_priv);
15325 intel_unregister_dsm_handler();
15327 intel_fbc_global_disable(dev_priv);
15329 /* flush any delayed tasks or pending work */
15330 flush_scheduled_work();
15332 drm_mode_config_cleanup(dev);
15334 intel_cleanup_overlay(dev_priv);
15336 intel_cleanup_gt_powersave(dev_priv);
15338 intel_teardown_gmbus(dev_priv);
15341 void intel_connector_attach_encoder(struct intel_connector *connector,
15342 struct intel_encoder *encoder)
15344 connector->encoder = encoder;
15345 drm_mode_connector_attach_encoder(&connector->base,
15350 * set vga decode state - true == enable VGA decode
15352 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
15354 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
15357 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15358 DRM_ERROR("failed to read control word\n");
15362 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15366 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15368 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
15370 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15371 DRM_ERROR("failed to write control word\n");
15378 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15380 struct intel_display_error_state {
15382 u32 power_well_driver;
15384 int num_transcoders;
15386 struct intel_cursor_error_state {
15391 } cursor[I915_MAX_PIPES];
15393 struct intel_pipe_error_state {
15394 bool power_domain_on;
15397 } pipe[I915_MAX_PIPES];
15399 struct intel_plane_error_state {
15407 } plane[I915_MAX_PIPES];
15409 struct intel_transcoder_error_state {
15410 bool power_domain_on;
15411 enum transcoder cpu_transcoder;
15424 struct intel_display_error_state *
15425 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
15427 struct intel_display_error_state *error;
15428 int transcoders[] = {
15436 if (INTEL_INFO(dev_priv)->num_pipes == 0)
15439 error = kzalloc(sizeof(*error), GFP_ATOMIC);
15443 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15444 error->power_well_driver =
15445 I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL));
15447 for_each_pipe(dev_priv, i) {
15448 error->pipe[i].power_domain_on =
15449 __intel_display_power_is_enabled(dev_priv,
15450 POWER_DOMAIN_PIPE(i));
15451 if (!error->pipe[i].power_domain_on)
15454 error->cursor[i].control = I915_READ(CURCNTR(i));
15455 error->cursor[i].position = I915_READ(CURPOS(i));
15456 error->cursor[i].base = I915_READ(CURBASE(i));
15458 error->plane[i].control = I915_READ(DSPCNTR(i));
15459 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
15460 if (INTEL_GEN(dev_priv) <= 3) {
15461 error->plane[i].size = I915_READ(DSPSIZE(i));
15462 error->plane[i].pos = I915_READ(DSPPOS(i));
15464 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15465 error->plane[i].addr = I915_READ(DSPADDR(i));
15466 if (INTEL_GEN(dev_priv) >= 4) {
15467 error->plane[i].surface = I915_READ(DSPSURF(i));
15468 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
15471 error->pipe[i].source = I915_READ(PIPESRC(i));
15473 if (HAS_GMCH_DISPLAY(dev_priv))
15474 error->pipe[i].stat = I915_READ(PIPESTAT(i));
15477 /* Note: this does not include DSI transcoders. */
15478 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
15479 if (HAS_DDI(dev_priv))
15480 error->num_transcoders++; /* Account for eDP. */
15482 for (i = 0; i < error->num_transcoders; i++) {
15483 enum transcoder cpu_transcoder = transcoders[i];
15485 error->transcoder[i].power_domain_on =
15486 __intel_display_power_is_enabled(dev_priv,
15487 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
15488 if (!error->transcoder[i].power_domain_on)
15491 error->transcoder[i].cpu_transcoder = cpu_transcoder;
15493 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
15494 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
15495 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
15496 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
15497 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
15498 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
15499 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
15505 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15508 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
15509 struct intel_display_error_state *error)
15511 struct drm_i915_private *dev_priv = m->i915;
15517 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
15518 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15519 err_printf(m, "PWR_WELL_CTL2: %08x\n",
15520 error->power_well_driver);
15521 for_each_pipe(dev_priv, i) {
15522 err_printf(m, "Pipe [%d]:\n", i);
15523 err_printf(m, " Power: %s\n",
15524 onoff(error->pipe[i].power_domain_on));
15525 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
15526 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
15528 err_printf(m, "Plane [%d]:\n", i);
15529 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
15530 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
15531 if (INTEL_GEN(dev_priv) <= 3) {
15532 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
15533 err_printf(m, " POS: %08x\n", error->plane[i].pos);
15535 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15536 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
15537 if (INTEL_GEN(dev_priv) >= 4) {
15538 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
15539 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
15542 err_printf(m, "Cursor [%d]:\n", i);
15543 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
15544 err_printf(m, " POS: %08x\n", error->cursor[i].position);
15545 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
15548 for (i = 0; i < error->num_transcoders; i++) {
15549 err_printf(m, "CPU transcoder: %s\n",
15550 transcoder_name(error->transcoder[i].cpu_transcoder));
15551 err_printf(m, " Power: %s\n",
15552 onoff(error->transcoder[i].power_domain_on));
15553 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
15554 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
15555 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
15556 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
15557 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
15558 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
15559 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);