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 skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
494 if (IS_SKYLAKE(dev_priv))
498 I915_WRITE(CLKGATE_DIS_PSL(pipe),
499 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
501 I915_WRITE(CLKGATE_DIS_PSL(pipe),
502 I915_READ(CLKGATE_DIS_PSL(pipe)) &
503 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
507 needs_modeset(const struct drm_crtc_state *state)
509 return drm_atomic_crtc_needs_modeset(state);
513 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
514 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
515 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
516 * The helpers' return value is the rate of the clock that is fed to the
517 * display engine's pipe which can be the above fast dot clock rate or a
518 * divided-down version of it.
520 /* m1 is reserved as 0 in Pineview, n is a ring counter */
521 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
523 clock->m = clock->m2 + 2;
524 clock->p = clock->p1 * clock->p2;
525 if (WARN_ON(clock->n == 0 || clock->p == 0))
527 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
528 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
533 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
535 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
538 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
540 clock->m = i9xx_dpll_compute_m(clock);
541 clock->p = clock->p1 * clock->p2;
542 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
544 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
545 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
550 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
552 clock->m = clock->m1 * clock->m2;
553 clock->p = clock->p1 * clock->p2;
554 if (WARN_ON(clock->n == 0 || clock->p == 0))
556 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
557 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
559 return clock->dot / 5;
562 int chv_calc_dpll_params(int refclk, struct dpll *clock)
564 clock->m = clock->m1 * clock->m2;
565 clock->p = clock->p1 * clock->p2;
566 if (WARN_ON(clock->n == 0 || clock->p == 0))
568 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
570 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
572 return clock->dot / 5;
575 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
578 * Returns whether the given set of divisors are valid for a given refclk with
579 * the given connectors.
581 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
582 const struct intel_limit *limit,
583 const struct dpll *clock)
585 if (clock->n < limit->n.min || limit->n.max < clock->n)
586 INTELPllInvalid("n out of range\n");
587 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
588 INTELPllInvalid("p1 out of range\n");
589 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
590 INTELPllInvalid("m2 out of range\n");
591 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
592 INTELPllInvalid("m1 out of range\n");
594 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
595 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
596 if (clock->m1 <= clock->m2)
597 INTELPllInvalid("m1 <= m2\n");
599 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
600 !IS_GEN9_LP(dev_priv)) {
601 if (clock->p < limit->p.min || limit->p.max < clock->p)
602 INTELPllInvalid("p out of range\n");
603 if (clock->m < limit->m.min || limit->m.max < clock->m)
604 INTELPllInvalid("m out of range\n");
607 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
608 INTELPllInvalid("vco out of range\n");
609 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
610 * connector, etc., rather than just a single range.
612 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
613 INTELPllInvalid("dot out of range\n");
619 i9xx_select_p2_div(const struct intel_limit *limit,
620 const struct intel_crtc_state *crtc_state,
623 struct drm_device *dev = crtc_state->base.crtc->dev;
625 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
627 * For LVDS just rely on its current settings for dual-channel.
628 * We haven't figured out how to reliably set up different
629 * single/dual channel state, if we even can.
631 if (intel_is_dual_link_lvds(dev))
632 return limit->p2.p2_fast;
634 return limit->p2.p2_slow;
636 if (target < limit->p2.dot_limit)
637 return limit->p2.p2_slow;
639 return limit->p2.p2_fast;
644 * Returns a set of divisors for the desired target clock with the given
645 * refclk, or FALSE. The returned values represent the clock equation:
646 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
648 * Target and reference clocks are specified in kHz.
650 * If match_clock is provided, then best_clock P divider must match the P
651 * divider from @match_clock used for LVDS downclocking.
654 i9xx_find_best_dpll(const struct intel_limit *limit,
655 struct intel_crtc_state *crtc_state,
656 int target, int refclk, struct dpll *match_clock,
657 struct dpll *best_clock)
659 struct drm_device *dev = crtc_state->base.crtc->dev;
663 memset(best_clock, 0, sizeof(*best_clock));
665 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
667 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
669 for (clock.m2 = limit->m2.min;
670 clock.m2 <= limit->m2.max; clock.m2++) {
671 if (clock.m2 >= clock.m1)
673 for (clock.n = limit->n.min;
674 clock.n <= limit->n.max; clock.n++) {
675 for (clock.p1 = limit->p1.min;
676 clock.p1 <= limit->p1.max; clock.p1++) {
679 i9xx_calc_dpll_params(refclk, &clock);
680 if (!intel_PLL_is_valid(to_i915(dev),
685 clock.p != match_clock->p)
688 this_err = abs(clock.dot - target);
689 if (this_err < err) {
698 return (err != target);
702 * Returns a set of divisors for the desired target clock with the given
703 * refclk, or FALSE. The returned values represent the clock equation:
704 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
706 * Target and reference clocks are specified in kHz.
708 * If match_clock is provided, then best_clock P divider must match the P
709 * divider from @match_clock used for LVDS downclocking.
712 pnv_find_best_dpll(const struct intel_limit *limit,
713 struct intel_crtc_state *crtc_state,
714 int target, int refclk, struct dpll *match_clock,
715 struct dpll *best_clock)
717 struct drm_device *dev = crtc_state->base.crtc->dev;
721 memset(best_clock, 0, sizeof(*best_clock));
723 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
725 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
727 for (clock.m2 = limit->m2.min;
728 clock.m2 <= limit->m2.max; clock.m2++) {
729 for (clock.n = limit->n.min;
730 clock.n <= limit->n.max; clock.n++) {
731 for (clock.p1 = limit->p1.min;
732 clock.p1 <= limit->p1.max; clock.p1++) {
735 pnv_calc_dpll_params(refclk, &clock);
736 if (!intel_PLL_is_valid(to_i915(dev),
741 clock.p != match_clock->p)
744 this_err = abs(clock.dot - target);
745 if (this_err < err) {
754 return (err != target);
758 * Returns a set of divisors for the desired target clock with the given
759 * refclk, or FALSE. The returned values represent the clock equation:
760 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
762 * Target and reference clocks are specified in kHz.
764 * If match_clock is provided, then best_clock P divider must match the P
765 * divider from @match_clock used for LVDS downclocking.
768 g4x_find_best_dpll(const struct intel_limit *limit,
769 struct intel_crtc_state *crtc_state,
770 int target, int refclk, struct dpll *match_clock,
771 struct dpll *best_clock)
773 struct drm_device *dev = crtc_state->base.crtc->dev;
777 /* approximately equals target * 0.00585 */
778 int err_most = (target >> 8) + (target >> 9);
780 memset(best_clock, 0, sizeof(*best_clock));
782 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
784 max_n = limit->n.max;
785 /* based on hardware requirement, prefer smaller n to precision */
786 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
787 /* based on hardware requirement, prefere larger m1,m2 */
788 for (clock.m1 = limit->m1.max;
789 clock.m1 >= limit->m1.min; clock.m1--) {
790 for (clock.m2 = limit->m2.max;
791 clock.m2 >= limit->m2.min; clock.m2--) {
792 for (clock.p1 = limit->p1.max;
793 clock.p1 >= limit->p1.min; clock.p1--) {
796 i9xx_calc_dpll_params(refclk, &clock);
797 if (!intel_PLL_is_valid(to_i915(dev),
802 this_err = abs(clock.dot - target);
803 if (this_err < err_most) {
817 * Check if the calculated PLL configuration is more optimal compared to the
818 * best configuration and error found so far. Return the calculated error.
820 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
821 const struct dpll *calculated_clock,
822 const struct dpll *best_clock,
823 unsigned int best_error_ppm,
824 unsigned int *error_ppm)
827 * For CHV ignore the error and consider only the P value.
828 * Prefer a bigger P value based on HW requirements.
830 if (IS_CHERRYVIEW(to_i915(dev))) {
833 return calculated_clock->p > best_clock->p;
836 if (WARN_ON_ONCE(!target_freq))
839 *error_ppm = div_u64(1000000ULL *
840 abs(target_freq - calculated_clock->dot),
843 * Prefer a better P value over a better (smaller) error if the error
844 * is small. Ensure this preference for future configurations too by
845 * setting the error to 0.
847 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
853 return *error_ppm + 10 < best_error_ppm;
857 * Returns a set of divisors for the desired target clock with the given
858 * refclk, or FALSE. The returned values represent the clock equation:
859 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
862 vlv_find_best_dpll(const struct intel_limit *limit,
863 struct intel_crtc_state *crtc_state,
864 int target, int refclk, struct dpll *match_clock,
865 struct dpll *best_clock)
867 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
868 struct drm_device *dev = crtc->base.dev;
870 unsigned int bestppm = 1000000;
871 /* min update 19.2 MHz */
872 int max_n = min(limit->n.max, refclk / 19200);
875 target *= 5; /* fast clock */
877 memset(best_clock, 0, sizeof(*best_clock));
879 /* based on hardware requirement, prefer smaller n to precision */
880 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
881 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
882 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
883 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
884 clock.p = clock.p1 * clock.p2;
885 /* based on hardware requirement, prefer bigger m1,m2 values */
886 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
889 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
892 vlv_calc_dpll_params(refclk, &clock);
894 if (!intel_PLL_is_valid(to_i915(dev),
899 if (!vlv_PLL_is_optimal(dev, target,
917 * Returns a set of divisors for the desired target clock with the given
918 * refclk, or FALSE. The returned values represent the clock equation:
919 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
922 chv_find_best_dpll(const struct intel_limit *limit,
923 struct intel_crtc_state *crtc_state,
924 int target, int refclk, struct dpll *match_clock,
925 struct dpll *best_clock)
927 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
928 struct drm_device *dev = crtc->base.dev;
929 unsigned int best_error_ppm;
934 memset(best_clock, 0, sizeof(*best_clock));
935 best_error_ppm = 1000000;
938 * Based on hardware doc, the n always set to 1, and m1 always
939 * set to 2. If requires to support 200Mhz refclk, we need to
940 * revisit this because n may not 1 anymore.
942 clock.n = 1, clock.m1 = 2;
943 target *= 5; /* fast clock */
945 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
946 for (clock.p2 = limit->p2.p2_fast;
947 clock.p2 >= limit->p2.p2_slow;
948 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
949 unsigned int error_ppm;
951 clock.p = clock.p1 * clock.p2;
953 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
954 clock.n) << 22, refclk * clock.m1);
956 if (m2 > INT_MAX/clock.m1)
961 chv_calc_dpll_params(refclk, &clock);
963 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
966 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
967 best_error_ppm, &error_ppm))
971 best_error_ppm = error_ppm;
979 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
980 struct dpll *best_clock)
983 const struct intel_limit *limit = &intel_limits_bxt;
985 return chv_find_best_dpll(limit, crtc_state,
986 target_clock, refclk, NULL, best_clock);
989 bool intel_crtc_active(struct intel_crtc *crtc)
991 /* Be paranoid as we can arrive here with only partial
992 * state retrieved from the hardware during setup.
994 * We can ditch the adjusted_mode.crtc_clock check as soon
995 * as Haswell has gained clock readout/fastboot support.
997 * We can ditch the crtc->primary->fb check as soon as we can
998 * properly reconstruct framebuffers.
1000 * FIXME: The intel_crtc->active here should be switched to
1001 * crtc->state->active once we have proper CRTC states wired up
1004 return crtc->active && crtc->base.primary->state->fb &&
1005 crtc->config->base.adjusted_mode.crtc_clock;
1008 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
1011 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1013 return crtc->config->cpu_transcoder;
1016 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
1019 i915_reg_t reg = PIPEDSL(pipe);
1023 if (IS_GEN2(dev_priv))
1024 line_mask = DSL_LINEMASK_GEN2;
1026 line_mask = DSL_LINEMASK_GEN3;
1028 line1 = I915_READ(reg) & line_mask;
1030 line2 = I915_READ(reg) & line_mask;
1032 return line1 != line2;
1035 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1037 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1038 enum pipe pipe = crtc->pipe;
1040 /* Wait for the display line to settle/start moving */
1041 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1042 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1043 pipe_name(pipe), onoff(state));
1046 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1048 wait_for_pipe_scanline_moving(crtc, false);
1051 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1053 wait_for_pipe_scanline_moving(crtc, true);
1057 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1059 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1060 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1062 if (INTEL_GEN(dev_priv) >= 4) {
1063 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1064 i915_reg_t reg = PIPECONF(cpu_transcoder);
1066 /* Wait for the Pipe State to go off */
1067 if (intel_wait_for_register(dev_priv,
1068 reg, I965_PIPECONF_ACTIVE, 0,
1070 WARN(1, "pipe_off wait timed out\n");
1072 intel_wait_for_pipe_scanline_stopped(crtc);
1076 /* Only for pre-ILK configs */
1077 void assert_pll(struct drm_i915_private *dev_priv,
1078 enum pipe pipe, bool state)
1083 val = I915_READ(DPLL(pipe));
1084 cur_state = !!(val & DPLL_VCO_ENABLE);
1085 I915_STATE_WARN(cur_state != state,
1086 "PLL state assertion failure (expected %s, current %s)\n",
1087 onoff(state), onoff(cur_state));
1090 /* XXX: the dsi pll is shared between MIPI DSI ports */
1091 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1096 mutex_lock(&dev_priv->sb_lock);
1097 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1098 mutex_unlock(&dev_priv->sb_lock);
1100 cur_state = val & DSI_PLL_VCO_EN;
1101 I915_STATE_WARN(cur_state != state,
1102 "DSI PLL state assertion failure (expected %s, current %s)\n",
1103 onoff(state), onoff(cur_state));
1106 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1107 enum pipe pipe, bool state)
1110 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1113 if (HAS_DDI(dev_priv)) {
1114 /* DDI does not have a specific FDI_TX register */
1115 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1116 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1118 u32 val = I915_READ(FDI_TX_CTL(pipe));
1119 cur_state = !!(val & FDI_TX_ENABLE);
1121 I915_STATE_WARN(cur_state != state,
1122 "FDI TX state assertion failure (expected %s, current %s)\n",
1123 onoff(state), onoff(cur_state));
1125 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1126 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1128 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1129 enum pipe pipe, bool state)
1134 val = I915_READ(FDI_RX_CTL(pipe));
1135 cur_state = !!(val & FDI_RX_ENABLE);
1136 I915_STATE_WARN(cur_state != state,
1137 "FDI RX state assertion failure (expected %s, current %s)\n",
1138 onoff(state), onoff(cur_state));
1140 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1141 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1143 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1148 /* ILK FDI PLL is always enabled */
1149 if (IS_GEN5(dev_priv))
1152 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1153 if (HAS_DDI(dev_priv))
1156 val = I915_READ(FDI_TX_CTL(pipe));
1157 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1160 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1161 enum pipe pipe, bool state)
1166 val = I915_READ(FDI_RX_CTL(pipe));
1167 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1168 I915_STATE_WARN(cur_state != state,
1169 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1170 onoff(state), onoff(cur_state));
1173 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1177 enum pipe panel_pipe = PIPE_A;
1180 if (WARN_ON(HAS_DDI(dev_priv)))
1183 if (HAS_PCH_SPLIT(dev_priv)) {
1186 pp_reg = PP_CONTROL(0);
1187 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1189 if (port_sel == PANEL_PORT_SELECT_LVDS &&
1190 I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
1191 panel_pipe = PIPE_B;
1192 /* XXX: else fix for eDP */
1193 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1194 /* presumably write lock depends on pipe, not port select */
1195 pp_reg = PP_CONTROL(pipe);
1198 pp_reg = PP_CONTROL(0);
1199 if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
1200 panel_pipe = PIPE_B;
1203 val = I915_READ(pp_reg);
1204 if (!(val & PANEL_POWER_ON) ||
1205 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1208 I915_STATE_WARN(panel_pipe == pipe && locked,
1209 "panel assertion failure, pipe %c regs locked\n",
1213 void assert_pipe(struct drm_i915_private *dev_priv,
1214 enum pipe pipe, bool state)
1217 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1219 enum intel_display_power_domain power_domain;
1221 /* we keep both pipes enabled on 830 */
1222 if (IS_I830(dev_priv))
1225 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1226 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
1227 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1228 cur_state = !!(val & PIPECONF_ENABLE);
1230 intel_display_power_put(dev_priv, power_domain);
1235 I915_STATE_WARN(cur_state != state,
1236 "pipe %c assertion failure (expected %s, current %s)\n",
1237 pipe_name(pipe), onoff(state), onoff(cur_state));
1240 static void assert_plane(struct intel_plane *plane, bool state)
1242 bool cur_state = plane->get_hw_state(plane);
1244 I915_STATE_WARN(cur_state != state,
1245 "%s assertion failure (expected %s, current %s)\n",
1246 plane->base.name, onoff(state), onoff(cur_state));
1249 #define assert_plane_enabled(p) assert_plane(p, true)
1250 #define assert_plane_disabled(p) assert_plane(p, false)
1252 static void assert_planes_disabled(struct intel_crtc *crtc)
1254 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1255 struct intel_plane *plane;
1257 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1258 assert_plane_disabled(plane);
1261 static void assert_vblank_disabled(struct drm_crtc *crtc)
1263 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1264 drm_crtc_vblank_put(crtc);
1267 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1273 val = I915_READ(PCH_TRANSCONF(pipe));
1274 enabled = !!(val & TRANS_ENABLE);
1275 I915_STATE_WARN(enabled,
1276 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1280 static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
1281 enum pipe pipe, u32 port_sel, u32 val)
1283 if ((val & DP_PORT_EN) == 0)
1286 if (HAS_PCH_CPT(dev_priv)) {
1287 u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe));
1288 if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
1290 } else if (IS_CHERRYVIEW(dev_priv)) {
1291 if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
1294 if ((val & DP_PIPE_MASK) != (pipe << 30))
1300 static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1301 enum pipe pipe, u32 val)
1303 if ((val & SDVO_ENABLE) == 0)
1306 if (HAS_PCH_CPT(dev_priv)) {
1307 if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
1309 } else if (IS_CHERRYVIEW(dev_priv)) {
1310 if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
1313 if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
1319 static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
1320 enum pipe pipe, u32 val)
1322 if ((val & LVDS_PORT_EN) == 0)
1325 if (HAS_PCH_CPT(dev_priv)) {
1326 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1329 if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
1335 static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
1336 enum pipe pipe, u32 val)
1338 if ((val & ADPA_DAC_ENABLE) == 0)
1340 if (HAS_PCH_CPT(dev_priv)) {
1341 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1344 if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
1350 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1351 enum pipe pipe, i915_reg_t reg,
1354 u32 val = I915_READ(reg);
1355 I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
1356 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1357 i915_mmio_reg_offset(reg), pipe_name(pipe));
1359 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0
1360 && (val & DP_PIPEB_SELECT),
1361 "IBX PCH dp port still using transcoder B\n");
1364 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1365 enum pipe pipe, i915_reg_t reg)
1367 u32 val = I915_READ(reg);
1368 I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1369 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1370 i915_mmio_reg_offset(reg), pipe_name(pipe));
1372 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0
1373 && (val & SDVO_PIPE_B_SELECT),
1374 "IBX PCH hdmi port still using transcoder B\n");
1377 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1382 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
1383 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
1384 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
1386 val = I915_READ(PCH_ADPA);
1387 I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val),
1388 "PCH VGA enabled on transcoder %c, should be disabled\n",
1391 val = I915_READ(PCH_LVDS);
1392 I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1393 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1396 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
1397 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
1398 assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
1401 static void _vlv_enable_pll(struct intel_crtc *crtc,
1402 const struct intel_crtc_state *pipe_config)
1404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1405 enum pipe pipe = crtc->pipe;
1407 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1408 POSTING_READ(DPLL(pipe));
1411 if (intel_wait_for_register(dev_priv,
1416 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1419 static void vlv_enable_pll(struct intel_crtc *crtc,
1420 const struct intel_crtc_state *pipe_config)
1422 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1423 enum pipe pipe = crtc->pipe;
1425 assert_pipe_disabled(dev_priv, pipe);
1427 /* PLL is protected by panel, make sure we can write it */
1428 assert_panel_unlocked(dev_priv, pipe);
1430 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1431 _vlv_enable_pll(crtc, pipe_config);
1433 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1434 POSTING_READ(DPLL_MD(pipe));
1438 static void _chv_enable_pll(struct intel_crtc *crtc,
1439 const struct intel_crtc_state *pipe_config)
1441 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1442 enum pipe pipe = crtc->pipe;
1443 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1446 mutex_lock(&dev_priv->sb_lock);
1448 /* Enable back the 10bit clock to display controller */
1449 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1450 tmp |= DPIO_DCLKP_EN;
1451 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1453 mutex_unlock(&dev_priv->sb_lock);
1456 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1461 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1463 /* Check PLL is locked */
1464 if (intel_wait_for_register(dev_priv,
1465 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1467 DRM_ERROR("PLL %d failed to lock\n", pipe);
1470 static void chv_enable_pll(struct intel_crtc *crtc,
1471 const struct intel_crtc_state *pipe_config)
1473 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1474 enum pipe pipe = crtc->pipe;
1476 assert_pipe_disabled(dev_priv, pipe);
1478 /* PLL is protected by panel, make sure we can write it */
1479 assert_panel_unlocked(dev_priv, pipe);
1481 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1482 _chv_enable_pll(crtc, pipe_config);
1484 if (pipe != PIPE_A) {
1486 * WaPixelRepeatModeFixForC0:chv
1488 * DPLLCMD is AWOL. Use chicken bits to propagate
1489 * the value from DPLLBMD to either pipe B or C.
1491 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1492 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1493 I915_WRITE(CBR4_VLV, 0);
1494 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1497 * DPLLB VGA mode also seems to cause problems.
1498 * We should always have it disabled.
1500 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1502 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1503 POSTING_READ(DPLL_MD(pipe));
1507 static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
1509 struct intel_crtc *crtc;
1512 for_each_intel_crtc(&dev_priv->drm, crtc) {
1513 count += crtc->base.state->active &&
1514 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1520 static void i9xx_enable_pll(struct intel_crtc *crtc,
1521 const struct intel_crtc_state *crtc_state)
1523 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1524 i915_reg_t reg = DPLL(crtc->pipe);
1525 u32 dpll = crtc_state->dpll_hw_state.dpll;
1528 assert_pipe_disabled(dev_priv, crtc->pipe);
1530 /* PLL is protected by panel, make sure we can write it */
1531 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
1532 assert_panel_unlocked(dev_priv, crtc->pipe);
1534 /* Enable DVO 2x clock on both PLLs if necessary */
1535 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
1537 * It appears to be important that we don't enable this
1538 * for the current pipe before otherwise configuring the
1539 * PLL. No idea how this should be handled if multiple
1540 * DVO outputs are enabled simultaneosly.
1542 dpll |= DPLL_DVO_2X_MODE;
1543 I915_WRITE(DPLL(!crtc->pipe),
1544 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1548 * Apparently we need to have VGA mode enabled prior to changing
1549 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1550 * dividers, even though the register value does change.
1554 I915_WRITE(reg, dpll);
1556 /* Wait for the clocks to stabilize. */
1560 if (INTEL_GEN(dev_priv) >= 4) {
1561 I915_WRITE(DPLL_MD(crtc->pipe),
1562 crtc_state->dpll_hw_state.dpll_md);
1564 /* The pixel multiplier can only be updated once the
1565 * DPLL is enabled and the clocks are stable.
1567 * So write it again.
1569 I915_WRITE(reg, dpll);
1572 /* We do this three times for luck */
1573 for (i = 0; i < 3; i++) {
1574 I915_WRITE(reg, dpll);
1576 udelay(150); /* wait for warmup */
1580 static void i9xx_disable_pll(struct intel_crtc *crtc)
1582 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1583 enum pipe pipe = crtc->pipe;
1585 /* Disable DVO 2x clock on both PLLs if necessary */
1586 if (IS_I830(dev_priv) &&
1587 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) &&
1588 !intel_num_dvo_pipes(dev_priv)) {
1589 I915_WRITE(DPLL(PIPE_B),
1590 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1591 I915_WRITE(DPLL(PIPE_A),
1592 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1595 /* Don't disable pipe or pipe PLLs if needed */
1596 if (IS_I830(dev_priv))
1599 /* Make sure the pipe isn't still relying on us */
1600 assert_pipe_disabled(dev_priv, pipe);
1602 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1603 POSTING_READ(DPLL(pipe));
1606 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1610 /* Make sure the pipe isn't still relying on us */
1611 assert_pipe_disabled(dev_priv, pipe);
1613 val = DPLL_INTEGRATED_REF_CLK_VLV |
1614 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1616 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1618 I915_WRITE(DPLL(pipe), val);
1619 POSTING_READ(DPLL(pipe));
1622 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1624 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1627 /* Make sure the pipe isn't still relying on us */
1628 assert_pipe_disabled(dev_priv, pipe);
1630 val = DPLL_SSC_REF_CLK_CHV |
1631 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1633 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1635 I915_WRITE(DPLL(pipe), val);
1636 POSTING_READ(DPLL(pipe));
1638 mutex_lock(&dev_priv->sb_lock);
1640 /* Disable 10bit clock to display controller */
1641 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1642 val &= ~DPIO_DCLKP_EN;
1643 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1645 mutex_unlock(&dev_priv->sb_lock);
1648 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1649 struct intel_digital_port *dport,
1650 unsigned int expected_mask)
1653 i915_reg_t dpll_reg;
1655 switch (dport->base.port) {
1657 port_mask = DPLL_PORTB_READY_MASK;
1661 port_mask = DPLL_PORTC_READY_MASK;
1663 expected_mask <<= 4;
1666 port_mask = DPLL_PORTD_READY_MASK;
1667 dpll_reg = DPIO_PHY_STATUS;
1673 if (intel_wait_for_register(dev_priv,
1674 dpll_reg, port_mask, expected_mask,
1676 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1677 port_name(dport->base.port),
1678 I915_READ(dpll_reg) & port_mask, expected_mask);
1681 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1684 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
1687 uint32_t val, pipeconf_val;
1689 /* Make sure PCH DPLL is enabled */
1690 assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll);
1692 /* FDI must be feeding us bits for PCH ports */
1693 assert_fdi_tx_enabled(dev_priv, pipe);
1694 assert_fdi_rx_enabled(dev_priv, pipe);
1696 if (HAS_PCH_CPT(dev_priv)) {
1697 /* Workaround: Set the timing override bit before enabling the
1698 * pch transcoder. */
1699 reg = TRANS_CHICKEN2(pipe);
1700 val = I915_READ(reg);
1701 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1702 I915_WRITE(reg, val);
1705 reg = PCH_TRANSCONF(pipe);
1706 val = I915_READ(reg);
1707 pipeconf_val = I915_READ(PIPECONF(pipe));
1709 if (HAS_PCH_IBX(dev_priv)) {
1711 * Make the BPC in transcoder be consistent with
1712 * that in pipeconf reg. For HDMI we must use 8bpc
1713 * here for both 8bpc and 12bpc.
1715 val &= ~PIPECONF_BPC_MASK;
1716 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI))
1717 val |= PIPECONF_8BPC;
1719 val |= pipeconf_val & PIPECONF_BPC_MASK;
1722 val &= ~TRANS_INTERLACE_MASK;
1723 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1724 if (HAS_PCH_IBX(dev_priv) &&
1725 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
1726 val |= TRANS_LEGACY_INTERLACED_ILK;
1728 val |= TRANS_INTERLACED;
1730 val |= TRANS_PROGRESSIVE;
1732 I915_WRITE(reg, val | TRANS_ENABLE);
1733 if (intel_wait_for_register(dev_priv,
1734 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1736 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1739 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1740 enum transcoder cpu_transcoder)
1742 u32 val, pipeconf_val;
1744 /* FDI must be feeding us bits for PCH ports */
1745 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1746 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1748 /* Workaround: set timing override bit. */
1749 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1750 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1751 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1754 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1756 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1757 PIPECONF_INTERLACED_ILK)
1758 val |= TRANS_INTERLACED;
1760 val |= TRANS_PROGRESSIVE;
1762 I915_WRITE(LPT_TRANSCONF, val);
1763 if (intel_wait_for_register(dev_priv,
1768 DRM_ERROR("Failed to enable PCH transcoder\n");
1771 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1777 /* FDI relies on the transcoder */
1778 assert_fdi_tx_disabled(dev_priv, pipe);
1779 assert_fdi_rx_disabled(dev_priv, pipe);
1781 /* Ports must be off as well */
1782 assert_pch_ports_disabled(dev_priv, pipe);
1784 reg = PCH_TRANSCONF(pipe);
1785 val = I915_READ(reg);
1786 val &= ~TRANS_ENABLE;
1787 I915_WRITE(reg, val);
1788 /* wait for PCH transcoder off, transcoder state */
1789 if (intel_wait_for_register(dev_priv,
1790 reg, TRANS_STATE_ENABLE, 0,
1792 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1794 if (HAS_PCH_CPT(dev_priv)) {
1795 /* Workaround: Clear the timing override chicken bit again. */
1796 reg = TRANS_CHICKEN2(pipe);
1797 val = I915_READ(reg);
1798 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1799 I915_WRITE(reg, val);
1803 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1807 val = I915_READ(LPT_TRANSCONF);
1808 val &= ~TRANS_ENABLE;
1809 I915_WRITE(LPT_TRANSCONF, val);
1810 /* wait for PCH transcoder off, transcoder state */
1811 if (intel_wait_for_register(dev_priv,
1812 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1814 DRM_ERROR("Failed to disable PCH transcoder\n");
1816 /* Workaround: clear timing override bit. */
1817 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1818 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1819 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1822 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1824 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1826 if (HAS_PCH_LPT(dev_priv))
1832 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1834 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1835 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1836 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1837 enum pipe pipe = crtc->pipe;
1841 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1843 assert_planes_disabled(crtc);
1846 * A pipe without a PLL won't actually be able to drive bits from
1847 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1850 if (HAS_GMCH_DISPLAY(dev_priv)) {
1851 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1852 assert_dsi_pll_enabled(dev_priv);
1854 assert_pll_enabled(dev_priv, pipe);
1856 if (new_crtc_state->has_pch_encoder) {
1857 /* if driving the PCH, we need FDI enabled */
1858 assert_fdi_rx_pll_enabled(dev_priv,
1859 intel_crtc_pch_transcoder(crtc));
1860 assert_fdi_tx_pll_enabled(dev_priv,
1861 (enum pipe) cpu_transcoder);
1863 /* FIXME: assert CPU port conditions for SNB+ */
1866 reg = PIPECONF(cpu_transcoder);
1867 val = I915_READ(reg);
1868 if (val & PIPECONF_ENABLE) {
1869 /* we keep both pipes enabled on 830 */
1870 WARN_ON(!IS_I830(dev_priv));
1874 I915_WRITE(reg, val | PIPECONF_ENABLE);
1878 * Until the pipe starts PIPEDSL reads will return a stale value,
1879 * which causes an apparent vblank timestamp jump when PIPEDSL
1880 * resets to its proper value. That also messes up the frame count
1881 * when it's derived from the timestamps. So let's wait for the
1882 * pipe to start properly before we call drm_crtc_vblank_on()
1884 if (dev_priv->drm.max_vblank_count == 0)
1885 intel_wait_for_pipe_scanline_moving(crtc);
1888 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1890 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1891 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1892 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1893 enum pipe pipe = crtc->pipe;
1897 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1900 * Make sure planes won't keep trying to pump pixels to us,
1901 * or we might hang the display.
1903 assert_planes_disabled(crtc);
1905 reg = PIPECONF(cpu_transcoder);
1906 val = I915_READ(reg);
1907 if ((val & PIPECONF_ENABLE) == 0)
1911 * Double wide has implications for planes
1912 * so best keep it disabled when not needed.
1914 if (old_crtc_state->double_wide)
1915 val &= ~PIPECONF_DOUBLE_WIDE;
1917 /* Don't disable pipe or pipe PLLs if needed */
1918 if (!IS_I830(dev_priv))
1919 val &= ~PIPECONF_ENABLE;
1921 I915_WRITE(reg, val);
1922 if ((val & PIPECONF_ENABLE) == 0)
1923 intel_wait_for_pipe_off(old_crtc_state);
1926 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1928 return IS_GEN2(dev_priv) ? 2048 : 4096;
1932 intel_tile_width_bytes(const struct drm_framebuffer *fb, int plane)
1934 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1935 unsigned int cpp = fb->format->cpp[plane];
1937 switch (fb->modifier) {
1938 case DRM_FORMAT_MOD_LINEAR:
1940 case I915_FORMAT_MOD_X_TILED:
1941 if (IS_GEN2(dev_priv))
1945 case I915_FORMAT_MOD_Y_TILED_CCS:
1949 case I915_FORMAT_MOD_Y_TILED:
1950 if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
1954 case I915_FORMAT_MOD_Yf_TILED_CCS:
1958 case I915_FORMAT_MOD_Yf_TILED:
1974 MISSING_CASE(fb->modifier);
1980 intel_tile_height(const struct drm_framebuffer *fb, int plane)
1982 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
1985 return intel_tile_size(to_i915(fb->dev)) /
1986 intel_tile_width_bytes(fb, plane);
1989 /* Return the tile dimensions in pixel units */
1990 static void intel_tile_dims(const struct drm_framebuffer *fb, int plane,
1991 unsigned int *tile_width,
1992 unsigned int *tile_height)
1994 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, plane);
1995 unsigned int cpp = fb->format->cpp[plane];
1997 *tile_width = tile_width_bytes / cpp;
1998 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
2002 intel_fb_align_height(const struct drm_framebuffer *fb,
2003 int plane, unsigned int height)
2005 unsigned int tile_height = intel_tile_height(fb, plane);
2007 return ALIGN(height, tile_height);
2010 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
2012 unsigned int size = 0;
2015 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
2016 size += rot_info->plane[i].width * rot_info->plane[i].height;
2022 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
2023 const struct drm_framebuffer *fb,
2024 unsigned int rotation)
2026 view->type = I915_GGTT_VIEW_NORMAL;
2027 if (drm_rotation_90_or_270(rotation)) {
2028 view->type = I915_GGTT_VIEW_ROTATED;
2029 view->rotated = to_intel_framebuffer(fb)->rot_info;
2033 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2035 if (IS_I830(dev_priv))
2037 else if (IS_I85X(dev_priv))
2039 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2045 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2047 if (INTEL_GEN(dev_priv) >= 9)
2049 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2050 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2052 else if (INTEL_GEN(dev_priv) >= 4)
2058 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2061 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2063 /* AUX_DIST needs only 4K alignment */
2067 switch (fb->modifier) {
2068 case DRM_FORMAT_MOD_LINEAR:
2069 return intel_linear_alignment(dev_priv);
2070 case I915_FORMAT_MOD_X_TILED:
2071 if (INTEL_GEN(dev_priv) >= 9)
2074 case I915_FORMAT_MOD_Y_TILED_CCS:
2075 case I915_FORMAT_MOD_Yf_TILED_CCS:
2076 case I915_FORMAT_MOD_Y_TILED:
2077 case I915_FORMAT_MOD_Yf_TILED:
2078 return 1 * 1024 * 1024;
2080 MISSING_CASE(fb->modifier);
2085 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2087 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2088 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2090 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
2094 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2095 unsigned int rotation,
2097 unsigned long *out_flags)
2099 struct drm_device *dev = fb->dev;
2100 struct drm_i915_private *dev_priv = to_i915(dev);
2101 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2102 struct i915_ggtt_view view;
2103 struct i915_vma *vma;
2104 unsigned int pinctl;
2107 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2109 alignment = intel_surf_alignment(fb, 0);
2111 intel_fill_fb_ggtt_view(&view, fb, rotation);
2113 /* Note that the w/a also requires 64 PTE of padding following the
2114 * bo. We currently fill all unused PTE with the shadow page and so
2115 * we should always have valid PTE following the scanout preventing
2118 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2119 alignment = 256 * 1024;
2122 * Global gtt pte registers are special registers which actually forward
2123 * writes to a chunk of system memory. Which means that there is no risk
2124 * that the register values disappear as soon as we call
2125 * intel_runtime_pm_put(), so it is correct to wrap only the
2126 * pin/unpin/fence and not more.
2128 intel_runtime_pm_get(dev_priv);
2130 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2134 /* Valleyview is definitely limited to scanning out the first
2135 * 512MiB. Lets presume this behaviour was inherited from the
2136 * g4x display engine and that all earlier gen are similarly
2137 * limited. Testing suggests that it is a little more
2138 * complicated than this. For example, Cherryview appears quite
2139 * happy to scanout from anywhere within its global aperture.
2141 if (HAS_GMCH_DISPLAY(dev_priv))
2142 pinctl |= PIN_MAPPABLE;
2144 vma = i915_gem_object_pin_to_display_plane(obj,
2145 alignment, &view, pinctl);
2149 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2152 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2153 * fence, whereas 965+ only requires a fence if using
2154 * framebuffer compression. For simplicity, we always, when
2155 * possible, install a fence as the cost is not that onerous.
2157 * If we fail to fence the tiled scanout, then either the
2158 * modeset will reject the change (which is highly unlikely as
2159 * the affected systems, all but one, do not have unmappable
2160 * space) or we will not be able to enable full powersaving
2161 * techniques (also likely not to apply due to various limits
2162 * FBC and the like impose on the size of the buffer, which
2163 * presumably we violated anyway with this unmappable buffer).
2164 * Anyway, it is presumably better to stumble onwards with
2165 * something and try to run the system in a "less than optimal"
2166 * mode that matches the user configuration.
2168 ret = i915_vma_pin_fence(vma);
2169 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2170 i915_gem_object_unpin_from_display_plane(vma);
2175 if (ret == 0 && vma->fence)
2176 *out_flags |= PLANE_HAS_FENCE;
2181 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2183 intel_runtime_pm_put(dev_priv);
2187 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2189 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2191 if (flags & PLANE_HAS_FENCE)
2192 i915_vma_unpin_fence(vma);
2193 i915_gem_object_unpin_from_display_plane(vma);
2197 static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
2198 unsigned int rotation)
2200 if (drm_rotation_90_or_270(rotation))
2201 return to_intel_framebuffer(fb)->rotated[plane].pitch;
2203 return fb->pitches[plane];
2207 * Convert the x/y offsets into a linear offset.
2208 * Only valid with 0/180 degree rotation, which is fine since linear
2209 * offset is only used with linear buffers on pre-hsw and tiled buffers
2210 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2212 u32 intel_fb_xy_to_linear(int x, int y,
2213 const struct intel_plane_state *state,
2216 const struct drm_framebuffer *fb = state->base.fb;
2217 unsigned int cpp = fb->format->cpp[plane];
2218 unsigned int pitch = fb->pitches[plane];
2220 return y * pitch + x * cpp;
2224 * Add the x/y offsets derived from fb->offsets[] to the user
2225 * specified plane src x/y offsets. The resulting x/y offsets
2226 * specify the start of scanout from the beginning of the gtt mapping.
2228 void intel_add_fb_offsets(int *x, int *y,
2229 const struct intel_plane_state *state,
2233 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2234 unsigned int rotation = state->base.rotation;
2236 if (drm_rotation_90_or_270(rotation)) {
2237 *x += intel_fb->rotated[plane].x;
2238 *y += intel_fb->rotated[plane].y;
2240 *x += intel_fb->normal[plane].x;
2241 *y += intel_fb->normal[plane].y;
2245 static u32 __intel_adjust_tile_offset(int *x, int *y,
2246 unsigned int tile_width,
2247 unsigned int tile_height,
2248 unsigned int tile_size,
2249 unsigned int pitch_tiles,
2253 unsigned int pitch_pixels = pitch_tiles * tile_width;
2256 WARN_ON(old_offset & (tile_size - 1));
2257 WARN_ON(new_offset & (tile_size - 1));
2258 WARN_ON(new_offset > old_offset);
2260 tiles = (old_offset - new_offset) / tile_size;
2262 *y += tiles / pitch_tiles * tile_height;
2263 *x += tiles % pitch_tiles * tile_width;
2265 /* minimize x in case it got needlessly big */
2266 *y += *x / pitch_pixels * tile_height;
2272 static u32 _intel_adjust_tile_offset(int *x, int *y,
2273 const struct drm_framebuffer *fb, int plane,
2274 unsigned int rotation,
2275 u32 old_offset, u32 new_offset)
2277 const struct drm_i915_private *dev_priv = to_i915(fb->dev);
2278 unsigned int cpp = fb->format->cpp[plane];
2279 unsigned int pitch = intel_fb_pitch(fb, plane, rotation);
2281 WARN_ON(new_offset > old_offset);
2283 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2284 unsigned int tile_size, tile_width, tile_height;
2285 unsigned int pitch_tiles;
2287 tile_size = intel_tile_size(dev_priv);
2288 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2290 if (drm_rotation_90_or_270(rotation)) {
2291 pitch_tiles = pitch / tile_height;
2292 swap(tile_width, tile_height);
2294 pitch_tiles = pitch / (tile_width * cpp);
2297 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2298 tile_size, pitch_tiles,
2299 old_offset, new_offset);
2301 old_offset += *y * pitch + *x * cpp;
2303 *y = (old_offset - new_offset) / pitch;
2304 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2311 * Adjust the tile offset by moving the difference into
2314 static u32 intel_adjust_tile_offset(int *x, int *y,
2315 const struct intel_plane_state *state, int plane,
2316 u32 old_offset, u32 new_offset)
2318 return _intel_adjust_tile_offset(x, y, state->base.fb, plane,
2319 state->base.rotation,
2320 old_offset, new_offset);
2324 * Computes the linear offset to the base tile and adjusts
2325 * x, y. bytes per pixel is assumed to be a power-of-two.
2327 * In the 90/270 rotated case, x and y are assumed
2328 * to be already rotated to match the rotated GTT view, and
2329 * pitch is the tile_height aligned framebuffer height.
2331 * This function is used when computing the derived information
2332 * under intel_framebuffer, so using any of that information
2333 * here is not allowed. Anything under drm_framebuffer can be
2334 * used. This is why the user has to pass in the pitch since it
2335 * is specified in the rotated orientation.
2337 static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv,
2339 const struct drm_framebuffer *fb, int plane,
2341 unsigned int rotation,
2344 uint64_t fb_modifier = fb->modifier;
2345 unsigned int cpp = fb->format->cpp[plane];
2346 u32 offset, offset_aligned;
2351 if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
2352 unsigned int tile_size, tile_width, tile_height;
2353 unsigned int tile_rows, tiles, pitch_tiles;
2355 tile_size = intel_tile_size(dev_priv);
2356 intel_tile_dims(fb, plane, &tile_width, &tile_height);
2358 if (drm_rotation_90_or_270(rotation)) {
2359 pitch_tiles = pitch / tile_height;
2360 swap(tile_width, tile_height);
2362 pitch_tiles = pitch / (tile_width * cpp);
2365 tile_rows = *y / tile_height;
2368 tiles = *x / tile_width;
2371 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2372 offset_aligned = offset & ~alignment;
2374 __intel_adjust_tile_offset(x, y, tile_width, tile_height,
2375 tile_size, pitch_tiles,
2376 offset, offset_aligned);
2378 offset = *y * pitch + *x * cpp;
2379 offset_aligned = offset & ~alignment;
2381 *y = (offset & alignment) / pitch;
2382 *x = ((offset & alignment) - *y * pitch) / cpp;
2385 return offset_aligned;
2388 u32 intel_compute_tile_offset(int *x, int *y,
2389 const struct intel_plane_state *state,
2392 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2393 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2394 const struct drm_framebuffer *fb = state->base.fb;
2395 unsigned int rotation = state->base.rotation;
2396 int pitch = intel_fb_pitch(fb, plane, rotation);
2399 if (intel_plane->id == PLANE_CURSOR)
2400 alignment = intel_cursor_alignment(dev_priv);
2402 alignment = intel_surf_alignment(fb, plane);
2404 return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch,
2405 rotation, alignment);
2408 /* Convert the fb->offset[] into x/y offsets */
2409 static int intel_fb_offset_to_xy(int *x, int *y,
2410 const struct drm_framebuffer *fb, int plane)
2412 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2414 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2415 fb->offsets[plane] % intel_tile_size(dev_priv))
2421 _intel_adjust_tile_offset(x, y,
2422 fb, plane, DRM_MODE_ROTATE_0,
2423 fb->offsets[plane], 0);
2428 static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2430 switch (fb_modifier) {
2431 case I915_FORMAT_MOD_X_TILED:
2432 return I915_TILING_X;
2433 case I915_FORMAT_MOD_Y_TILED:
2434 case I915_FORMAT_MOD_Y_TILED_CCS:
2435 return I915_TILING_Y;
2437 return I915_TILING_NONE;
2442 * From the Sky Lake PRM:
2443 * "The Color Control Surface (CCS) contains the compression status of
2444 * the cache-line pairs. The compression state of the cache-line pair
2445 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2446 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2447 * cache-line-pairs. CCS is always Y tiled."
2449 * Since cache line pairs refers to horizontally adjacent cache lines,
2450 * each cache line in the CCS corresponds to an area of 32x16 cache
2451 * lines on the main surface. Since each pixel is 4 bytes, this gives
2452 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2455 static const struct drm_format_info ccs_formats[] = {
2456 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2457 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2458 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2459 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2462 static const struct drm_format_info *
2463 lookup_format_info(const struct drm_format_info formats[],
2464 int num_formats, u32 format)
2468 for (i = 0; i < num_formats; i++) {
2469 if (formats[i].format == format)
2476 static const struct drm_format_info *
2477 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2479 switch (cmd->modifier[0]) {
2480 case I915_FORMAT_MOD_Y_TILED_CCS:
2481 case I915_FORMAT_MOD_Yf_TILED_CCS:
2482 return lookup_format_info(ccs_formats,
2483 ARRAY_SIZE(ccs_formats),
2491 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2492 struct drm_framebuffer *fb)
2494 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2495 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2496 u32 gtt_offset_rotated = 0;
2497 unsigned int max_size = 0;
2498 int i, num_planes = fb->format->num_planes;
2499 unsigned int tile_size = intel_tile_size(dev_priv);
2501 for (i = 0; i < num_planes; i++) {
2502 unsigned int width, height;
2503 unsigned int cpp, size;
2508 cpp = fb->format->cpp[i];
2509 width = drm_framebuffer_plane_width(fb->width, fb, i);
2510 height = drm_framebuffer_plane_height(fb->height, fb, i);
2512 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2514 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2519 if ((fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2520 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) && i == 1) {
2521 int hsub = fb->format->hsub;
2522 int vsub = fb->format->vsub;
2523 int tile_width, tile_height;
2527 intel_tile_dims(fb, i, &tile_width, &tile_height);
2529 tile_height *= vsub;
2531 ccs_x = (x * hsub) % tile_width;
2532 ccs_y = (y * vsub) % tile_height;
2533 main_x = intel_fb->normal[0].x % tile_width;
2534 main_y = intel_fb->normal[0].y % tile_height;
2537 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2538 * x/y offsets must match between CCS and the main surface.
2540 if (main_x != ccs_x || main_y != ccs_y) {
2541 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2544 intel_fb->normal[0].x,
2545 intel_fb->normal[0].y,
2552 * The fence (if used) is aligned to the start of the object
2553 * so having the framebuffer wrap around across the edge of the
2554 * fenced region doesn't really work. We have no API to configure
2555 * the fence start offset within the object (nor could we probably
2556 * on gen2/3). So it's just easier if we just require that the
2557 * fb layout agrees with the fence layout. We already check that the
2558 * fb stride matches the fence stride elsewhere.
2560 if (i == 0 && i915_gem_object_is_tiled(intel_fb->obj) &&
2561 (x + width) * cpp > fb->pitches[i]) {
2562 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2568 * First pixel of the framebuffer from
2569 * the start of the normal gtt mapping.
2571 intel_fb->normal[i].x = x;
2572 intel_fb->normal[i].y = y;
2574 offset = _intel_compute_tile_offset(dev_priv, &x, &y,
2575 fb, i, fb->pitches[i],
2576 DRM_MODE_ROTATE_0, tile_size);
2577 offset /= tile_size;
2579 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
2580 unsigned int tile_width, tile_height;
2581 unsigned int pitch_tiles;
2584 intel_tile_dims(fb, i, &tile_width, &tile_height);
2586 rot_info->plane[i].offset = offset;
2587 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2588 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2589 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2591 intel_fb->rotated[i].pitch =
2592 rot_info->plane[i].height * tile_height;
2594 /* how many tiles does this plane need */
2595 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2597 * If the plane isn't horizontally tile aligned,
2598 * we need one more tile.
2603 /* rotate the x/y offsets to match the GTT view */
2609 rot_info->plane[i].width * tile_width,
2610 rot_info->plane[i].height * tile_height,
2611 DRM_MODE_ROTATE_270);
2615 /* rotate the tile dimensions to match the GTT view */
2616 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2617 swap(tile_width, tile_height);
2620 * We only keep the x/y offsets, so push all of the
2621 * gtt offset into the x/y offsets.
2623 __intel_adjust_tile_offset(&x, &y,
2624 tile_width, tile_height,
2625 tile_size, pitch_tiles,
2626 gtt_offset_rotated * tile_size, 0);
2628 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2631 * First pixel of the framebuffer from
2632 * the start of the rotated gtt mapping.
2634 intel_fb->rotated[i].x = x;
2635 intel_fb->rotated[i].y = y;
2637 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2638 x * cpp, tile_size);
2641 /* how many tiles in total needed in the bo */
2642 max_size = max(max_size, offset + size);
2645 if (max_size * tile_size > intel_fb->obj->base.size) {
2646 DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
2647 max_size * tile_size, intel_fb->obj->base.size);
2654 static int i9xx_format_to_fourcc(int format)
2657 case DISPPLANE_8BPP:
2658 return DRM_FORMAT_C8;
2659 case DISPPLANE_BGRX555:
2660 return DRM_FORMAT_XRGB1555;
2661 case DISPPLANE_BGRX565:
2662 return DRM_FORMAT_RGB565;
2664 case DISPPLANE_BGRX888:
2665 return DRM_FORMAT_XRGB8888;
2666 case DISPPLANE_RGBX888:
2667 return DRM_FORMAT_XBGR8888;
2668 case DISPPLANE_BGRX101010:
2669 return DRM_FORMAT_XRGB2101010;
2670 case DISPPLANE_RGBX101010:
2671 return DRM_FORMAT_XBGR2101010;
2675 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2678 case PLANE_CTL_FORMAT_RGB_565:
2679 return DRM_FORMAT_RGB565;
2680 case PLANE_CTL_FORMAT_NV12:
2681 return DRM_FORMAT_NV12;
2683 case PLANE_CTL_FORMAT_XRGB_8888:
2686 return DRM_FORMAT_ABGR8888;
2688 return DRM_FORMAT_XBGR8888;
2691 return DRM_FORMAT_ARGB8888;
2693 return DRM_FORMAT_XRGB8888;
2695 case PLANE_CTL_FORMAT_XRGB_2101010:
2697 return DRM_FORMAT_XBGR2101010;
2699 return DRM_FORMAT_XRGB2101010;
2704 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2705 struct intel_initial_plane_config *plane_config)
2707 struct drm_device *dev = crtc->base.dev;
2708 struct drm_i915_private *dev_priv = to_i915(dev);
2709 struct drm_i915_gem_object *obj = NULL;
2710 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2711 struct drm_framebuffer *fb = &plane_config->fb->base;
2712 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2713 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2716 size_aligned -= base_aligned;
2718 if (plane_config->size == 0)
2721 /* If the FB is too big, just don't use it since fbdev is not very
2722 * important and we should probably use that space with FBC or other
2724 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2727 mutex_lock(&dev->struct_mutex);
2728 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2732 mutex_unlock(&dev->struct_mutex);
2736 if (plane_config->tiling == I915_TILING_X)
2737 obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X;
2739 mode_cmd.pixel_format = fb->format->format;
2740 mode_cmd.width = fb->width;
2741 mode_cmd.height = fb->height;
2742 mode_cmd.pitches[0] = fb->pitches[0];
2743 mode_cmd.modifier[0] = fb->modifier;
2744 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2746 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2747 DRM_DEBUG_KMS("intel fb init failed\n");
2752 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2756 i915_gem_object_put(obj);
2761 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2762 struct intel_plane_state *plane_state,
2765 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2767 plane_state->base.visible = visible;
2769 /* FIXME pre-g4x don't work like this */
2771 crtc_state->base.plane_mask |= BIT(drm_plane_index(&plane->base));
2772 crtc_state->active_planes |= BIT(plane->id);
2774 crtc_state->base.plane_mask &= ~BIT(drm_plane_index(&plane->base));
2775 crtc_state->active_planes &= ~BIT(plane->id);
2778 DRM_DEBUG_KMS("%s active planes 0x%x\n",
2779 crtc_state->base.crtc->name,
2780 crtc_state->active_planes);
2783 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2784 struct intel_plane *plane)
2786 struct intel_crtc_state *crtc_state =
2787 to_intel_crtc_state(crtc->base.state);
2788 struct intel_plane_state *plane_state =
2789 to_intel_plane_state(plane->base.state);
2791 intel_set_plane_visible(crtc_state, plane_state, false);
2793 if (plane->id == PLANE_PRIMARY)
2794 intel_pre_disable_primary_noatomic(&crtc->base);
2796 trace_intel_disable_plane(&plane->base, crtc);
2797 plane->disable_plane(plane, crtc);
2801 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2802 struct intel_initial_plane_config *plane_config)
2804 struct drm_device *dev = intel_crtc->base.dev;
2805 struct drm_i915_private *dev_priv = to_i915(dev);
2807 struct drm_i915_gem_object *obj;
2808 struct drm_plane *primary = intel_crtc->base.primary;
2809 struct drm_plane_state *plane_state = primary->state;
2810 struct drm_crtc_state *crtc_state = intel_crtc->base.state;
2811 struct intel_plane *intel_plane = to_intel_plane(primary);
2812 struct intel_plane_state *intel_state =
2813 to_intel_plane_state(plane_state);
2814 struct drm_framebuffer *fb;
2816 if (!plane_config->fb)
2819 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2820 fb = &plane_config->fb->base;
2824 kfree(plane_config->fb);
2827 * Failed to alloc the obj, check to see if we should share
2828 * an fb with another CRTC instead
2830 for_each_crtc(dev, c) {
2831 struct intel_plane_state *state;
2833 if (c == &intel_crtc->base)
2836 if (!to_intel_crtc(c)->active)
2839 state = to_intel_plane_state(c->primary->state);
2843 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2844 fb = state->base.fb;
2845 drm_framebuffer_get(fb);
2851 * We've failed to reconstruct the BIOS FB. Current display state
2852 * indicates that the primary plane is visible, but has a NULL FB,
2853 * which will lead to problems later if we don't fix it up. The
2854 * simplest solution is to just disable the primary plane now and
2855 * pretend the BIOS never had it enabled.
2857 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2862 mutex_lock(&dev->struct_mutex);
2864 intel_pin_and_fence_fb_obj(fb,
2865 primary->state->rotation,
2866 intel_plane_uses_fence(intel_state),
2867 &intel_state->flags);
2868 mutex_unlock(&dev->struct_mutex);
2869 if (IS_ERR(intel_state->vma)) {
2870 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2871 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2873 intel_state->vma = NULL;
2874 drm_framebuffer_put(fb);
2878 obj = intel_fb_obj(fb);
2879 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2881 plane_state->src_x = 0;
2882 plane_state->src_y = 0;
2883 plane_state->src_w = fb->width << 16;
2884 plane_state->src_h = fb->height << 16;
2886 plane_state->crtc_x = 0;
2887 plane_state->crtc_y = 0;
2888 plane_state->crtc_w = fb->width;
2889 plane_state->crtc_h = fb->height;
2891 intel_state->base.src = drm_plane_state_src(plane_state);
2892 intel_state->base.dst = drm_plane_state_dest(plane_state);
2894 if (i915_gem_object_is_tiled(obj))
2895 dev_priv->preserve_bios_swizzle = true;
2897 drm_framebuffer_get(fb);
2898 primary->fb = primary->state->fb = fb;
2899 primary->crtc = primary->state->crtc = &intel_crtc->base;
2901 intel_set_plane_visible(to_intel_crtc_state(crtc_state),
2902 to_intel_plane_state(plane_state),
2905 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2906 &obj->frontbuffer_bits);
2909 static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane,
2910 unsigned int rotation)
2912 int cpp = fb->format->cpp[plane];
2914 switch (fb->modifier) {
2915 case DRM_FORMAT_MOD_LINEAR:
2916 case I915_FORMAT_MOD_X_TILED:
2929 case I915_FORMAT_MOD_Y_TILED_CCS:
2930 case I915_FORMAT_MOD_Yf_TILED_CCS:
2931 /* FIXME AUX plane? */
2932 case I915_FORMAT_MOD_Y_TILED:
2933 case I915_FORMAT_MOD_Yf_TILED:
2948 MISSING_CASE(fb->modifier);
2954 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2955 int main_x, int main_y, u32 main_offset)
2957 const struct drm_framebuffer *fb = plane_state->base.fb;
2958 int hsub = fb->format->hsub;
2959 int vsub = fb->format->vsub;
2960 int aux_x = plane_state->aux.x;
2961 int aux_y = plane_state->aux.y;
2962 u32 aux_offset = plane_state->aux.offset;
2963 u32 alignment = intel_surf_alignment(fb, 1);
2965 while (aux_offset >= main_offset && aux_y <= main_y) {
2968 if (aux_x == main_x && aux_y == main_y)
2971 if (aux_offset == 0)
2976 aux_offset = intel_adjust_tile_offset(&x, &y, plane_state, 1,
2977 aux_offset, aux_offset - alignment);
2978 aux_x = x * hsub + aux_x % hsub;
2979 aux_y = y * vsub + aux_y % vsub;
2982 if (aux_x != main_x || aux_y != main_y)
2985 plane_state->aux.offset = aux_offset;
2986 plane_state->aux.x = aux_x;
2987 plane_state->aux.y = aux_y;
2992 static int skl_check_main_surface(const struct intel_crtc_state *crtc_state,
2993 struct intel_plane_state *plane_state)
2995 struct drm_i915_private *dev_priv =
2996 to_i915(plane_state->base.plane->dev);
2997 const struct drm_framebuffer *fb = plane_state->base.fb;
2998 unsigned int rotation = plane_state->base.rotation;
2999 int x = plane_state->base.src.x1 >> 16;
3000 int y = plane_state->base.src.y1 >> 16;
3001 int w = drm_rect_width(&plane_state->base.src) >> 16;
3002 int h = drm_rect_height(&plane_state->base.src) >> 16;
3003 int dst_x = plane_state->base.dst.x1;
3004 int pipe_src_w = crtc_state->pipe_src_w;
3005 int max_width = skl_max_plane_width(fb, 0, rotation);
3006 int max_height = 4096;
3007 u32 alignment, offset, aux_offset = plane_state->aux.offset;
3009 if (w > max_width || h > max_height) {
3010 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3011 w, h, max_width, max_height);
3016 * Display WA #1175: cnl,glk
3017 * Planes other than the cursor may cause FIFO underflow and display
3018 * corruption if starting less than 4 pixels from the right edge of
3020 * Besides the above WA fix the similar problem, where planes other
3021 * than the cursor ending less than 4 pixels from the left edge of the
3022 * screen may cause FIFO underflow and display corruption.
3024 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
3025 (dst_x + w < 4 || dst_x > pipe_src_w - 4)) {
3026 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
3027 dst_x + w < 4 ? "end" : "start",
3028 dst_x + w < 4 ? dst_x + w : dst_x,
3033 intel_add_fb_offsets(&x, &y, plane_state, 0);
3034 offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
3035 alignment = intel_surf_alignment(fb, 0);
3038 * AUX surface offset is specified as the distance from the
3039 * main surface offset, and it must be non-negative. Make
3040 * sure that is what we will get.
3042 if (offset > aux_offset)
3043 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3044 offset, aux_offset & ~(alignment - 1));
3047 * When using an X-tiled surface, the plane blows up
3048 * if the x offset + width exceed the stride.
3050 * TODO: linear and Y-tiled seem fine, Yf untested,
3052 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3053 int cpp = fb->format->cpp[0];
3055 while ((x + w) * cpp > fb->pitches[0]) {
3057 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3061 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3062 offset, offset - alignment);
3067 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3068 * they match with the main surface x/y offsets.
3070 if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
3071 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
3072 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3076 offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
3077 offset, offset - alignment);
3080 if (x != plane_state->aux.x || y != plane_state->aux.y) {
3081 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3086 plane_state->main.offset = offset;
3087 plane_state->main.x = x;
3088 plane_state->main.y = y;
3093 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3095 const struct drm_framebuffer *fb = plane_state->base.fb;
3096 unsigned int rotation = plane_state->base.rotation;
3097 int max_width = skl_max_plane_width(fb, 1, rotation);
3098 int max_height = 4096;
3099 int x = plane_state->base.src.x1 >> 17;
3100 int y = plane_state->base.src.y1 >> 17;
3101 int w = drm_rect_width(&plane_state->base.src) >> 17;
3102 int h = drm_rect_height(&plane_state->base.src) >> 17;
3105 intel_add_fb_offsets(&x, &y, plane_state, 1);
3106 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3108 /* FIXME not quite sure how/if these apply to the chroma plane */
3109 if (w > max_width || h > max_height) {
3110 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3111 w, h, max_width, max_height);
3115 plane_state->aux.offset = offset;
3116 plane_state->aux.x = x;
3117 plane_state->aux.y = y;
3122 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3124 const struct drm_framebuffer *fb = plane_state->base.fb;
3125 int src_x = plane_state->base.src.x1 >> 16;
3126 int src_y = plane_state->base.src.y1 >> 16;
3127 int hsub = fb->format->hsub;
3128 int vsub = fb->format->vsub;
3129 int x = src_x / hsub;
3130 int y = src_y / vsub;
3133 if (plane_state->base.rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180)) {
3134 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation %x\n",
3135 plane_state->base.rotation);
3139 intel_add_fb_offsets(&x, &y, plane_state, 1);
3140 offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
3142 plane_state->aux.offset = offset;
3143 plane_state->aux.x = x * hsub + src_x % hsub;
3144 plane_state->aux.y = y * vsub + src_y % vsub;
3149 int skl_check_plane_surface(const struct intel_crtc_state *crtc_state,
3150 struct intel_plane_state *plane_state)
3152 const struct drm_framebuffer *fb = plane_state->base.fb;
3153 unsigned int rotation = plane_state->base.rotation;
3156 if (rotation & DRM_MODE_REFLECT_X &&
3157 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
3158 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
3162 if (!plane_state->base.visible)
3165 /* Rotate src coordinates to match rotated GTT view */
3166 if (drm_rotation_90_or_270(rotation))
3167 drm_rect_rotate(&plane_state->base.src,
3168 fb->width << 16, fb->height << 16,
3169 DRM_MODE_ROTATE_270);
3172 * Handle the AUX surface first since
3173 * the main surface setup depends on it.
3175 if (fb->format->format == DRM_FORMAT_NV12) {
3176 ret = skl_check_nv12_aux_surface(plane_state);
3179 } else if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
3180 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
3181 ret = skl_check_ccs_aux_surface(plane_state);
3185 plane_state->aux.offset = ~0xfff;
3186 plane_state->aux.x = 0;
3187 plane_state->aux.y = 0;
3190 ret = skl_check_main_surface(crtc_state, plane_state);
3197 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3198 const struct intel_plane_state *plane_state)
3200 struct drm_i915_private *dev_priv =
3201 to_i915(plane_state->base.plane->dev);
3202 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3203 const struct drm_framebuffer *fb = plane_state->base.fb;
3204 unsigned int rotation = plane_state->base.rotation;
3207 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
3209 if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
3210 IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
3211 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3213 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3214 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3216 if (INTEL_GEN(dev_priv) < 5)
3217 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3219 switch (fb->format->format) {
3221 dspcntr |= DISPPLANE_8BPP;
3223 case DRM_FORMAT_XRGB1555:
3224 dspcntr |= DISPPLANE_BGRX555;
3226 case DRM_FORMAT_RGB565:
3227 dspcntr |= DISPPLANE_BGRX565;
3229 case DRM_FORMAT_XRGB8888:
3230 dspcntr |= DISPPLANE_BGRX888;
3232 case DRM_FORMAT_XBGR8888:
3233 dspcntr |= DISPPLANE_RGBX888;
3235 case DRM_FORMAT_XRGB2101010:
3236 dspcntr |= DISPPLANE_BGRX101010;
3238 case DRM_FORMAT_XBGR2101010:
3239 dspcntr |= DISPPLANE_RGBX101010;
3242 MISSING_CASE(fb->format->format);
3246 if (INTEL_GEN(dev_priv) >= 4 &&
3247 fb->modifier == I915_FORMAT_MOD_X_TILED)
3248 dspcntr |= DISPPLANE_TILED;
3250 if (rotation & DRM_MODE_ROTATE_180)
3251 dspcntr |= DISPPLANE_ROTATE_180;
3253 if (rotation & DRM_MODE_REFLECT_X)
3254 dspcntr |= DISPPLANE_MIRROR;
3259 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3261 struct drm_i915_private *dev_priv =
3262 to_i915(plane_state->base.plane->dev);
3263 int src_x = plane_state->base.src.x1 >> 16;
3264 int src_y = plane_state->base.src.y1 >> 16;
3267 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3269 if (INTEL_GEN(dev_priv) >= 4)
3270 offset = intel_compute_tile_offset(&src_x, &src_y,
3275 /* HSW/BDW do this automagically in hardware */
3276 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3277 unsigned int rotation = plane_state->base.rotation;
3278 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3279 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3281 if (rotation & DRM_MODE_ROTATE_180) {
3284 } else if (rotation & DRM_MODE_REFLECT_X) {
3289 plane_state->main.offset = offset;
3290 plane_state->main.x = src_x;
3291 plane_state->main.y = src_y;
3296 static void i9xx_update_plane(struct intel_plane *plane,
3297 const struct intel_crtc_state *crtc_state,
3298 const struct intel_plane_state *plane_state)
3300 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3301 const struct drm_framebuffer *fb = plane_state->base.fb;
3302 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3304 u32 dspcntr = plane_state->ctl;
3305 i915_reg_t reg = DSPCNTR(i9xx_plane);
3306 int x = plane_state->main.x;
3307 int y = plane_state->main.y;
3308 unsigned long irqflags;
3311 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3313 if (INTEL_GEN(dev_priv) >= 4)
3314 dspaddr_offset = plane_state->main.offset;
3316 dspaddr_offset = linear_offset;
3318 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3320 if (INTEL_GEN(dev_priv) < 4) {
3321 /* pipesrc and dspsize control the size that is scaled from,
3322 * which should always be the user's requested size.
3324 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3325 ((crtc_state->pipe_src_h - 1) << 16) |
3326 (crtc_state->pipe_src_w - 1));
3327 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3328 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3329 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3330 ((crtc_state->pipe_src_h - 1) << 16) |
3331 (crtc_state->pipe_src_w - 1));
3332 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3333 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3336 I915_WRITE_FW(reg, dspcntr);
3338 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), fb->pitches[0]);
3339 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3340 I915_WRITE_FW(DSPSURF(i9xx_plane),
3341 intel_plane_ggtt_offset(plane_state) +
3343 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3344 } else if (INTEL_GEN(dev_priv) >= 4) {
3345 I915_WRITE_FW(DSPSURF(i9xx_plane),
3346 intel_plane_ggtt_offset(plane_state) +
3348 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3349 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3351 I915_WRITE_FW(DSPADDR(i9xx_plane),
3352 intel_plane_ggtt_offset(plane_state) +
3355 POSTING_READ_FW(reg);
3357 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3360 static void i9xx_disable_plane(struct intel_plane *plane,
3361 struct intel_crtc *crtc)
3363 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3364 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3365 unsigned long irqflags;
3367 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3369 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3370 if (INTEL_GEN(dev_priv) >= 4)
3371 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3373 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3374 POSTING_READ_FW(DSPCNTR(i9xx_plane));
3376 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3379 static bool i9xx_plane_get_hw_state(struct intel_plane *plane)
3381 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3382 enum intel_display_power_domain power_domain;
3383 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3384 enum pipe pipe = plane->pipe;
3388 * Not 100% correct for planes that can move between pipes,
3389 * but that's only the case for gen2-4 which don't have any
3390 * display power wells.
3392 power_domain = POWER_DOMAIN_PIPE(pipe);
3393 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3396 ret = I915_READ(DSPCNTR(i9xx_plane)) & DISPLAY_PLANE_ENABLE;
3398 intel_display_power_put(dev_priv, power_domain);
3404 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int plane)
3406 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3409 return intel_tile_width_bytes(fb, plane);
3412 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3414 struct drm_device *dev = intel_crtc->base.dev;
3415 struct drm_i915_private *dev_priv = to_i915(dev);
3417 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3418 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3419 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3423 * This function detaches (aka. unbinds) unused scalers in hardware
3425 static void skl_detach_scalers(struct intel_crtc *intel_crtc)
3427 struct intel_crtc_scaler_state *scaler_state;
3430 scaler_state = &intel_crtc->config->scaler_state;
3432 /* loop through and disable scalers that aren't in use */
3433 for (i = 0; i < intel_crtc->num_scalers; i++) {
3434 if (!scaler_state->scalers[i].in_use)
3435 skl_detach_scaler(intel_crtc, i);
3439 u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
3440 unsigned int rotation)
3444 if (plane >= fb->format->num_planes)
3447 stride = intel_fb_pitch(fb, plane, rotation);
3450 * The stride is either expressed as a multiple of 64 bytes chunks for
3451 * linear buffers or in number of tiles for tiled buffers.
3453 if (drm_rotation_90_or_270(rotation))
3454 stride /= intel_tile_height(fb, plane);
3456 stride /= intel_fb_stride_alignment(fb, plane);
3461 static u32 skl_plane_ctl_format(uint32_t pixel_format)
3463 switch (pixel_format) {
3465 return PLANE_CTL_FORMAT_INDEXED;
3466 case DRM_FORMAT_RGB565:
3467 return PLANE_CTL_FORMAT_RGB_565;
3468 case DRM_FORMAT_XBGR8888:
3469 case DRM_FORMAT_ABGR8888:
3470 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3471 case DRM_FORMAT_XRGB8888:
3472 case DRM_FORMAT_ARGB8888:
3473 return PLANE_CTL_FORMAT_XRGB_8888;
3474 case DRM_FORMAT_XRGB2101010:
3475 return PLANE_CTL_FORMAT_XRGB_2101010;
3476 case DRM_FORMAT_XBGR2101010:
3477 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3478 case DRM_FORMAT_YUYV:
3479 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3480 case DRM_FORMAT_YVYU:
3481 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3482 case DRM_FORMAT_UYVY:
3483 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3484 case DRM_FORMAT_VYUY:
3485 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3486 case DRM_FORMAT_NV12:
3487 return PLANE_CTL_FORMAT_NV12;
3489 MISSING_CASE(pixel_format);
3496 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
3497 * to be already pre-multiplied. We need to add a knob (or a different
3498 * DRM_FORMAT) for user-space to configure that.
3500 static u32 skl_plane_ctl_alpha(uint32_t pixel_format)
3502 switch (pixel_format) {
3503 case DRM_FORMAT_ABGR8888:
3504 case DRM_FORMAT_ARGB8888:
3505 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3507 return PLANE_CTL_ALPHA_DISABLE;
3511 static u32 glk_plane_color_ctl_alpha(uint32_t pixel_format)
3513 switch (pixel_format) {
3514 case DRM_FORMAT_ABGR8888:
3515 case DRM_FORMAT_ARGB8888:
3516 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3518 return PLANE_COLOR_ALPHA_DISABLE;
3522 static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
3524 switch (fb_modifier) {
3525 case DRM_FORMAT_MOD_LINEAR:
3527 case I915_FORMAT_MOD_X_TILED:
3528 return PLANE_CTL_TILED_X;
3529 case I915_FORMAT_MOD_Y_TILED:
3530 return PLANE_CTL_TILED_Y;
3531 case I915_FORMAT_MOD_Y_TILED_CCS:
3532 return PLANE_CTL_TILED_Y | PLANE_CTL_DECOMPRESSION_ENABLE;
3533 case I915_FORMAT_MOD_Yf_TILED:
3534 return PLANE_CTL_TILED_YF;
3535 case I915_FORMAT_MOD_Yf_TILED_CCS:
3536 return PLANE_CTL_TILED_YF | PLANE_CTL_DECOMPRESSION_ENABLE;
3538 MISSING_CASE(fb_modifier);
3544 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3547 case DRM_MODE_ROTATE_0:
3550 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3551 * while i915 HW rotation is clockwise, thats why this swapping.
3553 case DRM_MODE_ROTATE_90:
3554 return PLANE_CTL_ROTATE_270;
3555 case DRM_MODE_ROTATE_180:
3556 return PLANE_CTL_ROTATE_180;
3557 case DRM_MODE_ROTATE_270:
3558 return PLANE_CTL_ROTATE_90;
3560 MISSING_CASE(rotate);
3566 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3571 case DRM_MODE_REFLECT_X:
3572 return PLANE_CTL_FLIP_HORIZONTAL;
3573 case DRM_MODE_REFLECT_Y:
3575 MISSING_CASE(reflect);
3581 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3582 const struct intel_plane_state *plane_state)
3584 struct drm_i915_private *dev_priv =
3585 to_i915(plane_state->base.plane->dev);
3586 const struct drm_framebuffer *fb = plane_state->base.fb;
3587 unsigned int rotation = plane_state->base.rotation;
3588 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3591 plane_ctl = PLANE_CTL_ENABLE;
3593 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3594 plane_ctl |= skl_plane_ctl_alpha(fb->format->format);
3596 PLANE_CTL_PIPE_GAMMA_ENABLE |
3597 PLANE_CTL_PIPE_CSC_ENABLE |
3598 PLANE_CTL_PLANE_GAMMA_DISABLE;
3600 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3601 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3603 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3604 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3607 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3608 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3609 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3611 if (INTEL_GEN(dev_priv) >= 10)
3612 plane_ctl |= cnl_plane_ctl_flip(rotation &
3613 DRM_MODE_REFLECT_MASK);
3615 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3616 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3617 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3618 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3623 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3624 const struct intel_plane_state *plane_state)
3626 struct drm_i915_private *dev_priv =
3627 to_i915(plane_state->base.plane->dev);
3628 const struct drm_framebuffer *fb = plane_state->base.fb;
3629 u32 plane_color_ctl = 0;
3631 if (INTEL_GEN(dev_priv) < 11) {
3632 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3633 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3635 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3636 plane_color_ctl |= glk_plane_color_ctl_alpha(fb->format->format);
3638 if (intel_format_is_yuv(fb->format->format)) {
3639 if (fb->format->format == DRM_FORMAT_NV12) {
3641 PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3644 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3645 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3647 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
3649 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3650 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3653 return plane_color_ctl;
3657 __intel_display_resume(struct drm_device *dev,
3658 struct drm_atomic_state *state,
3659 struct drm_modeset_acquire_ctx *ctx)
3661 struct drm_crtc_state *crtc_state;
3662 struct drm_crtc *crtc;
3665 intel_modeset_setup_hw_state(dev, ctx);
3666 i915_redisable_vga(to_i915(dev));
3672 * We've duplicated the state, pointers to the old state are invalid.
3674 * Don't attempt to use the old state until we commit the duplicated state.
3676 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3678 * Force recalculation even if we restore
3679 * current state. With fast modeset this may not result
3680 * in a modeset when the state is compatible.
3682 crtc_state->mode_changed = true;
3685 /* ignore any reset values/BIOS leftovers in the WM registers */
3686 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3687 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3689 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3691 WARN_ON(ret == -EDEADLK);
3695 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3697 return intel_has_gpu_reset(dev_priv) &&
3698 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
3701 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3703 struct drm_device *dev = &dev_priv->drm;
3704 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3705 struct drm_atomic_state *state;
3708 /* reset doesn't touch the display */
3709 if (!i915_modparams.force_reset_modeset_test &&
3710 !gpu_reset_clobbers_display(dev_priv))
3713 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3714 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3715 wake_up_all(&dev_priv->gpu_error.wait_queue);
3717 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3718 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3719 i915_gem_set_wedged(dev_priv);
3723 * Need mode_config.mutex so that we don't
3724 * trample ongoing ->detect() and whatnot.
3726 mutex_lock(&dev->mode_config.mutex);
3727 drm_modeset_acquire_init(ctx, 0);
3729 ret = drm_modeset_lock_all_ctx(dev, ctx);
3730 if (ret != -EDEADLK)
3733 drm_modeset_backoff(ctx);
3736 * Disabling the crtcs gracefully seems nicer. Also the
3737 * g33 docs say we should at least disable all the planes.
3739 state = drm_atomic_helper_duplicate_state(dev, ctx);
3740 if (IS_ERR(state)) {
3741 ret = PTR_ERR(state);
3742 DRM_ERROR("Duplicating state failed with %i\n", ret);
3746 ret = drm_atomic_helper_disable_all(dev, ctx);
3748 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3749 drm_atomic_state_put(state);
3753 dev_priv->modeset_restore_state = state;
3754 state->acquire_ctx = ctx;
3757 void intel_finish_reset(struct drm_i915_private *dev_priv)
3759 struct drm_device *dev = &dev_priv->drm;
3760 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3761 struct drm_atomic_state *state;
3764 /* reset doesn't touch the display */
3765 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
3768 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3772 /* reset doesn't touch the display */
3773 if (!gpu_reset_clobbers_display(dev_priv)) {
3774 /* for testing only restore the display */
3775 ret = __intel_display_resume(dev, state, ctx);
3777 DRM_ERROR("Restoring old state failed with %i\n", ret);
3780 * The display has been reset as well,
3781 * so need a full re-initialization.
3783 intel_runtime_pm_disable_interrupts(dev_priv);
3784 intel_runtime_pm_enable_interrupts(dev_priv);
3786 intel_pps_unlock_regs_wa(dev_priv);
3787 intel_modeset_init_hw(dev);
3788 intel_init_clock_gating(dev_priv);
3790 spin_lock_irq(&dev_priv->irq_lock);
3791 if (dev_priv->display.hpd_irq_setup)
3792 dev_priv->display.hpd_irq_setup(dev_priv);
3793 spin_unlock_irq(&dev_priv->irq_lock);
3795 ret = __intel_display_resume(dev, state, ctx);
3797 DRM_ERROR("Restoring old state failed with %i\n", ret);
3799 intel_hpd_init(dev_priv);
3802 drm_atomic_state_put(state);
3804 drm_modeset_drop_locks(ctx);
3805 drm_modeset_acquire_fini(ctx);
3806 mutex_unlock(&dev->mode_config.mutex);
3808 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3811 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3812 const struct intel_crtc_state *new_crtc_state)
3814 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
3815 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3817 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
3818 crtc->base.mode = new_crtc_state->base.mode;
3821 * Update pipe size and adjust fitter if needed: the reason for this is
3822 * that in compute_mode_changes we check the native mode (not the pfit
3823 * mode) to see if we can flip rather than do a full mode set. In the
3824 * fastboot case, we'll flip, but if we don't update the pipesrc and
3825 * pfit state, we'll end up with a big fb scanned out into the wrong
3829 I915_WRITE(PIPESRC(crtc->pipe),
3830 ((new_crtc_state->pipe_src_w - 1) << 16) |
3831 (new_crtc_state->pipe_src_h - 1));
3833 /* on skylake this is done by detaching scalers */
3834 if (INTEL_GEN(dev_priv) >= 9) {
3835 skl_detach_scalers(crtc);
3837 if (new_crtc_state->pch_pfit.enabled)
3838 skylake_pfit_enable(crtc);
3839 } else if (HAS_PCH_SPLIT(dev_priv)) {
3840 if (new_crtc_state->pch_pfit.enabled)
3841 ironlake_pfit_enable(crtc);
3842 else if (old_crtc_state->pch_pfit.enabled)
3843 ironlake_pfit_disable(crtc, true);
3847 static void intel_fdi_normal_train(struct intel_crtc *crtc)
3849 struct drm_device *dev = crtc->base.dev;
3850 struct drm_i915_private *dev_priv = to_i915(dev);
3851 int pipe = crtc->pipe;
3855 /* enable normal train */
3856 reg = FDI_TX_CTL(pipe);
3857 temp = I915_READ(reg);
3858 if (IS_IVYBRIDGE(dev_priv)) {
3859 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3860 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
3862 temp &= ~FDI_LINK_TRAIN_NONE;
3863 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
3865 I915_WRITE(reg, temp);
3867 reg = FDI_RX_CTL(pipe);
3868 temp = I915_READ(reg);
3869 if (HAS_PCH_CPT(dev_priv)) {
3870 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3871 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3873 temp &= ~FDI_LINK_TRAIN_NONE;
3874 temp |= FDI_LINK_TRAIN_NONE;
3876 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3878 /* wait one idle pattern time */
3882 /* IVB wants error correction enabled */
3883 if (IS_IVYBRIDGE(dev_priv))
3884 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3885 FDI_FE_ERRC_ENABLE);
3888 /* The FDI link training functions for ILK/Ibexpeak. */
3889 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3890 const struct intel_crtc_state *crtc_state)
3892 struct drm_device *dev = crtc->base.dev;
3893 struct drm_i915_private *dev_priv = to_i915(dev);
3894 int pipe = crtc->pipe;
3898 /* FDI needs bits from pipe first */
3899 assert_pipe_enabled(dev_priv, pipe);
3901 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3903 reg = FDI_RX_IMR(pipe);
3904 temp = I915_READ(reg);
3905 temp &= ~FDI_RX_SYMBOL_LOCK;
3906 temp &= ~FDI_RX_BIT_LOCK;
3907 I915_WRITE(reg, temp);
3911 /* enable CPU FDI TX and PCH FDI RX */
3912 reg = FDI_TX_CTL(pipe);
3913 temp = I915_READ(reg);
3914 temp &= ~FDI_DP_PORT_WIDTH_MASK;
3915 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
3916 temp &= ~FDI_LINK_TRAIN_NONE;
3917 temp |= FDI_LINK_TRAIN_PATTERN_1;
3918 I915_WRITE(reg, temp | FDI_TX_ENABLE);
3920 reg = FDI_RX_CTL(pipe);
3921 temp = I915_READ(reg);
3922 temp &= ~FDI_LINK_TRAIN_NONE;
3923 temp |= FDI_LINK_TRAIN_PATTERN_1;
3924 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3929 /* Ironlake workaround, enable clock pointer after FDI enable*/
3930 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3931 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3932 FDI_RX_PHASE_SYNC_POINTER_EN);
3934 reg = FDI_RX_IIR(pipe);
3935 for (tries = 0; tries < 5; tries++) {
3936 temp = I915_READ(reg);
3937 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3939 if ((temp & FDI_RX_BIT_LOCK)) {
3940 DRM_DEBUG_KMS("FDI train 1 done.\n");
3941 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
3946 DRM_ERROR("FDI train 1 fail!\n");
3949 reg = FDI_TX_CTL(pipe);
3950 temp = I915_READ(reg);
3951 temp &= ~FDI_LINK_TRAIN_NONE;
3952 temp |= FDI_LINK_TRAIN_PATTERN_2;
3953 I915_WRITE(reg, temp);
3955 reg = FDI_RX_CTL(pipe);
3956 temp = I915_READ(reg);
3957 temp &= ~FDI_LINK_TRAIN_NONE;
3958 temp |= FDI_LINK_TRAIN_PATTERN_2;
3959 I915_WRITE(reg, temp);
3964 reg = FDI_RX_IIR(pipe);
3965 for (tries = 0; tries < 5; tries++) {
3966 temp = I915_READ(reg);
3967 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3969 if (temp & FDI_RX_SYMBOL_LOCK) {
3970 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
3971 DRM_DEBUG_KMS("FDI train 2 done.\n");
3976 DRM_ERROR("FDI train 2 fail!\n");
3978 DRM_DEBUG_KMS("FDI train done\n");
3982 static const int snb_b_fdi_train_param[] = {
3983 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
3984 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
3985 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
3986 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
3989 /* The FDI link training functions for SNB/Cougarpoint. */
3990 static void gen6_fdi_link_train(struct intel_crtc *crtc,
3991 const struct intel_crtc_state *crtc_state)
3993 struct drm_device *dev = crtc->base.dev;
3994 struct drm_i915_private *dev_priv = to_i915(dev);
3995 int pipe = crtc->pipe;
3999 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4001 reg = FDI_RX_IMR(pipe);
4002 temp = I915_READ(reg);
4003 temp &= ~FDI_RX_SYMBOL_LOCK;
4004 temp &= ~FDI_RX_BIT_LOCK;
4005 I915_WRITE(reg, temp);
4010 /* enable CPU FDI TX and PCH FDI RX */
4011 reg = FDI_TX_CTL(pipe);
4012 temp = I915_READ(reg);
4013 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4014 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4015 temp &= ~FDI_LINK_TRAIN_NONE;
4016 temp |= FDI_LINK_TRAIN_PATTERN_1;
4017 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4019 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4020 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4022 I915_WRITE(FDI_RX_MISC(pipe),
4023 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4025 reg = FDI_RX_CTL(pipe);
4026 temp = I915_READ(reg);
4027 if (HAS_PCH_CPT(dev_priv)) {
4028 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4029 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4031 temp &= ~FDI_LINK_TRAIN_NONE;
4032 temp |= FDI_LINK_TRAIN_PATTERN_1;
4034 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4039 for (i = 0; i < 4; i++) {
4040 reg = FDI_TX_CTL(pipe);
4041 temp = I915_READ(reg);
4042 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4043 temp |= snb_b_fdi_train_param[i];
4044 I915_WRITE(reg, temp);
4049 for (retry = 0; retry < 5; retry++) {
4050 reg = FDI_RX_IIR(pipe);
4051 temp = I915_READ(reg);
4052 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4053 if (temp & FDI_RX_BIT_LOCK) {
4054 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4055 DRM_DEBUG_KMS("FDI train 1 done.\n");
4064 DRM_ERROR("FDI train 1 fail!\n");
4067 reg = FDI_TX_CTL(pipe);
4068 temp = I915_READ(reg);
4069 temp &= ~FDI_LINK_TRAIN_NONE;
4070 temp |= FDI_LINK_TRAIN_PATTERN_2;
4071 if (IS_GEN6(dev_priv)) {
4072 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4074 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4076 I915_WRITE(reg, temp);
4078 reg = FDI_RX_CTL(pipe);
4079 temp = I915_READ(reg);
4080 if (HAS_PCH_CPT(dev_priv)) {
4081 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4082 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4084 temp &= ~FDI_LINK_TRAIN_NONE;
4085 temp |= FDI_LINK_TRAIN_PATTERN_2;
4087 I915_WRITE(reg, temp);
4092 for (i = 0; i < 4; i++) {
4093 reg = FDI_TX_CTL(pipe);
4094 temp = I915_READ(reg);
4095 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4096 temp |= snb_b_fdi_train_param[i];
4097 I915_WRITE(reg, temp);
4102 for (retry = 0; retry < 5; retry++) {
4103 reg = FDI_RX_IIR(pipe);
4104 temp = I915_READ(reg);
4105 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4106 if (temp & FDI_RX_SYMBOL_LOCK) {
4107 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4108 DRM_DEBUG_KMS("FDI train 2 done.\n");
4117 DRM_ERROR("FDI train 2 fail!\n");
4119 DRM_DEBUG_KMS("FDI train done.\n");
4122 /* Manual link training for Ivy Bridge A0 parts */
4123 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4124 const struct intel_crtc_state *crtc_state)
4126 struct drm_device *dev = crtc->base.dev;
4127 struct drm_i915_private *dev_priv = to_i915(dev);
4128 int pipe = crtc->pipe;
4132 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4134 reg = FDI_RX_IMR(pipe);
4135 temp = I915_READ(reg);
4136 temp &= ~FDI_RX_SYMBOL_LOCK;
4137 temp &= ~FDI_RX_BIT_LOCK;
4138 I915_WRITE(reg, temp);
4143 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4144 I915_READ(FDI_RX_IIR(pipe)));
4146 /* Try each vswing and preemphasis setting twice before moving on */
4147 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4148 /* disable first in case we need to retry */
4149 reg = FDI_TX_CTL(pipe);
4150 temp = I915_READ(reg);
4151 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4152 temp &= ~FDI_TX_ENABLE;
4153 I915_WRITE(reg, temp);
4155 reg = FDI_RX_CTL(pipe);
4156 temp = I915_READ(reg);
4157 temp &= ~FDI_LINK_TRAIN_AUTO;
4158 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4159 temp &= ~FDI_RX_ENABLE;
4160 I915_WRITE(reg, temp);
4162 /* enable CPU FDI TX and PCH FDI RX */
4163 reg = FDI_TX_CTL(pipe);
4164 temp = I915_READ(reg);
4165 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4166 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4167 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4168 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4169 temp |= snb_b_fdi_train_param[j/2];
4170 temp |= FDI_COMPOSITE_SYNC;
4171 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4173 I915_WRITE(FDI_RX_MISC(pipe),
4174 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4176 reg = FDI_RX_CTL(pipe);
4177 temp = I915_READ(reg);
4178 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4179 temp |= FDI_COMPOSITE_SYNC;
4180 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4183 udelay(1); /* should be 0.5us */
4185 for (i = 0; i < 4; i++) {
4186 reg = FDI_RX_IIR(pipe);
4187 temp = I915_READ(reg);
4188 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4190 if (temp & FDI_RX_BIT_LOCK ||
4191 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4192 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4193 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4197 udelay(1); /* should be 0.5us */
4200 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4205 reg = FDI_TX_CTL(pipe);
4206 temp = I915_READ(reg);
4207 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4208 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4209 I915_WRITE(reg, temp);
4211 reg = FDI_RX_CTL(pipe);
4212 temp = I915_READ(reg);
4213 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4214 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4215 I915_WRITE(reg, temp);
4218 udelay(2); /* should be 1.5us */
4220 for (i = 0; i < 4; i++) {
4221 reg = FDI_RX_IIR(pipe);
4222 temp = I915_READ(reg);
4223 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4225 if (temp & FDI_RX_SYMBOL_LOCK ||
4226 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4227 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4228 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4232 udelay(2); /* should be 1.5us */
4235 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4239 DRM_DEBUG_KMS("FDI train done.\n");
4242 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
4244 struct drm_device *dev = intel_crtc->base.dev;
4245 struct drm_i915_private *dev_priv = to_i915(dev);
4246 int pipe = intel_crtc->pipe;
4250 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4251 reg = FDI_RX_CTL(pipe);
4252 temp = I915_READ(reg);
4253 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4254 temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
4255 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4256 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4261 /* Switch from Rawclk to PCDclk */
4262 temp = I915_READ(reg);
4263 I915_WRITE(reg, temp | FDI_PCDCLK);
4268 /* Enable CPU FDI TX PLL, always on for Ironlake */
4269 reg = FDI_TX_CTL(pipe);
4270 temp = I915_READ(reg);
4271 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4272 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4279 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4281 struct drm_device *dev = intel_crtc->base.dev;
4282 struct drm_i915_private *dev_priv = to_i915(dev);
4283 int pipe = intel_crtc->pipe;
4287 /* Switch from PCDclk to Rawclk */
4288 reg = FDI_RX_CTL(pipe);
4289 temp = I915_READ(reg);
4290 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4292 /* Disable CPU FDI TX PLL */
4293 reg = FDI_TX_CTL(pipe);
4294 temp = I915_READ(reg);
4295 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4300 reg = FDI_RX_CTL(pipe);
4301 temp = I915_READ(reg);
4302 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4304 /* Wait for the clocks to turn off. */
4309 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4311 struct drm_device *dev = crtc->dev;
4312 struct drm_i915_private *dev_priv = to_i915(dev);
4313 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4314 int pipe = intel_crtc->pipe;
4318 /* disable CPU FDI tx and PCH FDI rx */
4319 reg = FDI_TX_CTL(pipe);
4320 temp = I915_READ(reg);
4321 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4324 reg = FDI_RX_CTL(pipe);
4325 temp = I915_READ(reg);
4326 temp &= ~(0x7 << 16);
4327 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4328 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4333 /* Ironlake workaround, disable clock pointer after downing FDI */
4334 if (HAS_PCH_IBX(dev_priv))
4335 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4337 /* still set train pattern 1 */
4338 reg = FDI_TX_CTL(pipe);
4339 temp = I915_READ(reg);
4340 temp &= ~FDI_LINK_TRAIN_NONE;
4341 temp |= FDI_LINK_TRAIN_PATTERN_1;
4342 I915_WRITE(reg, temp);
4344 reg = FDI_RX_CTL(pipe);
4345 temp = I915_READ(reg);
4346 if (HAS_PCH_CPT(dev_priv)) {
4347 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4348 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4350 temp &= ~FDI_LINK_TRAIN_NONE;
4351 temp |= FDI_LINK_TRAIN_PATTERN_1;
4353 /* BPC in FDI rx is consistent with that in PIPECONF */
4354 temp &= ~(0x07 << 16);
4355 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4356 I915_WRITE(reg, temp);
4362 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4364 struct drm_crtc *crtc;
4367 drm_for_each_crtc(crtc, &dev_priv->drm) {
4368 struct drm_crtc_commit *commit;
4369 spin_lock(&crtc->commit_lock);
4370 commit = list_first_entry_or_null(&crtc->commit_list,
4371 struct drm_crtc_commit, commit_entry);
4372 cleanup_done = commit ?
4373 try_wait_for_completion(&commit->cleanup_done) : true;
4374 spin_unlock(&crtc->commit_lock);
4379 drm_crtc_wait_one_vblank(crtc);
4387 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4391 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4393 mutex_lock(&dev_priv->sb_lock);
4395 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4396 temp |= SBI_SSCCTL_DISABLE;
4397 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4399 mutex_unlock(&dev_priv->sb_lock);
4402 /* Program iCLKIP clock to the desired frequency */
4403 static void lpt_program_iclkip(struct intel_crtc *crtc)
4405 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4406 int clock = crtc->config->base.adjusted_mode.crtc_clock;
4407 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4410 lpt_disable_iclkip(dev_priv);
4412 /* The iCLK virtual clock root frequency is in MHz,
4413 * but the adjusted_mode->crtc_clock in in KHz. To get the
4414 * divisors, it is necessary to divide one by another, so we
4415 * convert the virtual clock precision to KHz here for higher
4418 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4419 u32 iclk_virtual_root_freq = 172800 * 1000;
4420 u32 iclk_pi_range = 64;
4421 u32 desired_divisor;
4423 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4425 divsel = (desired_divisor / iclk_pi_range) - 2;
4426 phaseinc = desired_divisor % iclk_pi_range;
4429 * Near 20MHz is a corner case which is
4430 * out of range for the 7-bit divisor
4436 /* This should not happen with any sane values */
4437 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4438 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4439 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4440 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4442 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4449 mutex_lock(&dev_priv->sb_lock);
4451 /* Program SSCDIVINTPHASE6 */
4452 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4453 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4454 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4455 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4456 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4457 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4458 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4459 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4461 /* Program SSCAUXDIV */
4462 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4463 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4464 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4465 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4467 /* Enable modulator and associated divider */
4468 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4469 temp &= ~SBI_SSCCTL_DISABLE;
4470 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4472 mutex_unlock(&dev_priv->sb_lock);
4474 /* Wait for initialization time */
4477 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4480 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4482 u32 divsel, phaseinc, auxdiv;
4483 u32 iclk_virtual_root_freq = 172800 * 1000;
4484 u32 iclk_pi_range = 64;
4485 u32 desired_divisor;
4488 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4491 mutex_lock(&dev_priv->sb_lock);
4493 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4494 if (temp & SBI_SSCCTL_DISABLE) {
4495 mutex_unlock(&dev_priv->sb_lock);
4499 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4500 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4501 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4502 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4503 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4505 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4506 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4507 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4509 mutex_unlock(&dev_priv->sb_lock);
4511 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4513 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4514 desired_divisor << auxdiv);
4517 static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
4518 enum pipe pch_transcoder)
4520 struct drm_device *dev = crtc->base.dev;
4521 struct drm_i915_private *dev_priv = to_i915(dev);
4522 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
4524 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4525 I915_READ(HTOTAL(cpu_transcoder)));
4526 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4527 I915_READ(HBLANK(cpu_transcoder)));
4528 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4529 I915_READ(HSYNC(cpu_transcoder)));
4531 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4532 I915_READ(VTOTAL(cpu_transcoder)));
4533 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4534 I915_READ(VBLANK(cpu_transcoder)));
4535 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4536 I915_READ(VSYNC(cpu_transcoder)));
4537 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4538 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4541 static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
4543 struct drm_i915_private *dev_priv = to_i915(dev);
4546 temp = I915_READ(SOUTH_CHICKEN1);
4547 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4550 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4551 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4553 temp &= ~FDI_BC_BIFURCATION_SELECT;
4555 temp |= FDI_BC_BIFURCATION_SELECT;
4557 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4558 I915_WRITE(SOUTH_CHICKEN1, temp);
4559 POSTING_READ(SOUTH_CHICKEN1);
4562 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
4564 struct drm_device *dev = intel_crtc->base.dev;
4566 switch (intel_crtc->pipe) {
4570 if (intel_crtc->config->fdi_lanes > 2)
4571 cpt_set_fdi_bc_bifurcation(dev, false);
4573 cpt_set_fdi_bc_bifurcation(dev, true);
4577 cpt_set_fdi_bc_bifurcation(dev, true);
4585 /* Return which DP Port should be selected for Transcoder DP control */
4587 intel_trans_dp_port_sel(struct intel_crtc *crtc)
4589 struct drm_device *dev = crtc->base.dev;
4590 struct intel_encoder *encoder;
4592 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
4593 if (encoder->type == INTEL_OUTPUT_DP ||
4594 encoder->type == INTEL_OUTPUT_EDP)
4595 return encoder->port;
4602 * Enable PCH resources required for PCH ports:
4604 * - FDI training & RX/TX
4605 * - update transcoder timings
4606 * - DP transcoding bits
4609 static void ironlake_pch_enable(const struct intel_crtc_state *crtc_state)
4611 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4612 struct drm_device *dev = crtc->base.dev;
4613 struct drm_i915_private *dev_priv = to_i915(dev);
4614 int pipe = crtc->pipe;
4617 assert_pch_transcoder_disabled(dev_priv, pipe);
4619 if (IS_IVYBRIDGE(dev_priv))
4620 ivybridge_update_fdi_bc_bifurcation(crtc);
4622 /* Write the TU size bits before fdi link training, so that error
4623 * detection works. */
4624 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4625 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4627 /* For PCH output, training FDI link */
4628 dev_priv->display.fdi_link_train(crtc, crtc_state);
4630 /* We need to program the right clock selection before writing the pixel
4631 * mutliplier into the DPLL. */
4632 if (HAS_PCH_CPT(dev_priv)) {
4635 temp = I915_READ(PCH_DPLL_SEL);
4636 temp |= TRANS_DPLL_ENABLE(pipe);
4637 sel = TRANS_DPLLB_SEL(pipe);
4638 if (crtc_state->shared_dpll ==
4639 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4643 I915_WRITE(PCH_DPLL_SEL, temp);
4646 /* XXX: pch pll's can be enabled any time before we enable the PCH
4647 * transcoder, and we actually should do this to not upset any PCH
4648 * transcoder that already use the clock when we share it.
4650 * Note that enable_shared_dpll tries to do the right thing, but
4651 * get_shared_dpll unconditionally resets the pll - we need that to have
4652 * the right LVDS enable sequence. */
4653 intel_enable_shared_dpll(crtc);
4655 /* set transcoder timing, panel must allow it */
4656 assert_panel_unlocked(dev_priv, pipe);
4657 ironlake_pch_transcoder_set_timings(crtc, pipe);
4659 intel_fdi_normal_train(crtc);
4661 /* For PCH DP, enable TRANS_DP_CTL */
4662 if (HAS_PCH_CPT(dev_priv) &&
4663 intel_crtc_has_dp_encoder(crtc_state)) {
4664 const struct drm_display_mode *adjusted_mode =
4665 &crtc_state->base.adjusted_mode;
4666 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4667 i915_reg_t reg = TRANS_DP_CTL(pipe);
4668 temp = I915_READ(reg);
4669 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4670 TRANS_DP_SYNC_MASK |
4672 temp |= TRANS_DP_OUTPUT_ENABLE;
4673 temp |= bpc << 9; /* same format but at 11:9 */
4675 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4676 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4677 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4678 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4680 switch (intel_trans_dp_port_sel(crtc)) {
4682 temp |= TRANS_DP_PORT_SEL_B;
4685 temp |= TRANS_DP_PORT_SEL_C;
4688 temp |= TRANS_DP_PORT_SEL_D;
4694 I915_WRITE(reg, temp);
4697 ironlake_enable_pch_transcoder(dev_priv, pipe);
4700 static void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
4702 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4703 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4704 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4706 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4708 lpt_program_iclkip(crtc);
4710 /* Set transcoder timing. */
4711 ironlake_pch_transcoder_set_timings(crtc, PIPE_A);
4713 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4716 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4718 struct drm_i915_private *dev_priv = to_i915(dev);
4719 i915_reg_t dslreg = PIPEDSL(pipe);
4722 temp = I915_READ(dslreg);
4724 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4725 if (wait_for(I915_READ(dslreg) != temp, 5))
4726 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4731 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4732 unsigned int scaler_user, int *scaler_id,
4733 int src_w, int src_h, int dst_w, int dst_h,
4734 bool plane_scaler_check,
4735 uint32_t pixel_format)
4737 struct intel_crtc_scaler_state *scaler_state =
4738 &crtc_state->scaler_state;
4739 struct intel_crtc *intel_crtc =
4740 to_intel_crtc(crtc_state->base.crtc);
4741 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4742 const struct drm_display_mode *adjusted_mode =
4743 &crtc_state->base.adjusted_mode;
4747 * Src coordinates are already rotated by 270 degrees for
4748 * the 90/270 degree plane rotation cases (to match the
4749 * GTT mapping), hence no need to account for rotation here.
4751 need_scaling = src_w != dst_w || src_h != dst_h;
4753 if (plane_scaler_check)
4754 if (pixel_format == DRM_FORMAT_NV12)
4755 need_scaling = true;
4757 if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX)
4758 need_scaling = true;
4761 * Scaling/fitting not supported in IF-ID mode in GEN9+
4762 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4763 * Once NV12 is enabled, handle it here while allocating scaler
4766 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
4767 need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4768 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4773 * if plane is being disabled or scaler is no more required or force detach
4774 * - free scaler binded to this plane/crtc
4775 * - in order to do this, update crtc->scaler_usage
4777 * Here scaler state in crtc_state is set free so that
4778 * scaler can be assigned to other user. Actual register
4779 * update to free the scaler is done in plane/panel-fit programming.
4780 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4782 if (force_detach || !need_scaling) {
4783 if (*scaler_id >= 0) {
4784 scaler_state->scaler_users &= ~(1 << scaler_user);
4785 scaler_state->scalers[*scaler_id].in_use = 0;
4787 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4788 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4789 intel_crtc->pipe, scaler_user, *scaler_id,
4790 scaler_state->scaler_users);
4796 if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 &&
4797 (src_h < SKL_MIN_YUV_420_SRC_H || (src_w % 4) != 0 ||
4798 (src_h % 4) != 0)) {
4799 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4804 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4805 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4806 (IS_GEN11(dev_priv) &&
4807 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4808 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4809 (!IS_GEN11(dev_priv) &&
4810 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4811 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
4812 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
4813 "size is out of scaler range\n",
4814 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
4818 /* mark this plane as a scaler user in crtc_state */
4819 scaler_state->scaler_users |= (1 << scaler_user);
4820 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4821 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4822 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4823 scaler_state->scaler_users);
4829 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4831 * @state: crtc's scaler state
4834 * 0 - scaler_usage updated successfully
4835 * error - requested scaling cannot be supported or other error condition
4837 int skl_update_scaler_crtc(struct intel_crtc_state *state)
4839 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
4841 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
4842 &state->scaler_state.scaler_id,
4843 state->pipe_src_w, state->pipe_src_h,
4844 adjusted_mode->crtc_hdisplay,
4845 adjusted_mode->crtc_vdisplay, false, 0);
4849 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4850 * @crtc_state: crtc's scaler state
4851 * @plane_state: atomic plane state to update
4854 * 0 - scaler_usage updated successfully
4855 * error - requested scaling cannot be supported or other error condition
4857 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4858 struct intel_plane_state *plane_state)
4861 struct intel_plane *intel_plane =
4862 to_intel_plane(plane_state->base.plane);
4863 struct drm_framebuffer *fb = plane_state->base.fb;
4866 bool force_detach = !fb || !plane_state->base.visible;
4868 ret = skl_update_scaler(crtc_state, force_detach,
4869 drm_plane_index(&intel_plane->base),
4870 &plane_state->scaler_id,
4871 drm_rect_width(&plane_state->base.src) >> 16,
4872 drm_rect_height(&plane_state->base.src) >> 16,
4873 drm_rect_width(&plane_state->base.dst),
4874 drm_rect_height(&plane_state->base.dst),
4875 fb ? true : false, fb ? fb->format->format : 0);
4877 if (ret || plane_state->scaler_id < 0)
4880 /* check colorkey */
4881 if (plane_state->ckey.flags) {
4882 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
4883 intel_plane->base.base.id,
4884 intel_plane->base.name);
4888 /* Check src format */
4889 switch (fb->format->format) {
4890 case DRM_FORMAT_RGB565:
4891 case DRM_FORMAT_XBGR8888:
4892 case DRM_FORMAT_XRGB8888:
4893 case DRM_FORMAT_ABGR8888:
4894 case DRM_FORMAT_ARGB8888:
4895 case DRM_FORMAT_XRGB2101010:
4896 case DRM_FORMAT_XBGR2101010:
4897 case DRM_FORMAT_YUYV:
4898 case DRM_FORMAT_YVYU:
4899 case DRM_FORMAT_UYVY:
4900 case DRM_FORMAT_VYUY:
4901 case DRM_FORMAT_NV12:
4904 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4905 intel_plane->base.base.id, intel_plane->base.name,
4906 fb->base.id, fb->format->format);
4913 static void skylake_scaler_disable(struct intel_crtc *crtc)
4917 for (i = 0; i < crtc->num_scalers; i++)
4918 skl_detach_scaler(crtc, i);
4921 static void skylake_pfit_enable(struct intel_crtc *crtc)
4923 struct drm_device *dev = crtc->base.dev;
4924 struct drm_i915_private *dev_priv = to_i915(dev);
4925 int pipe = crtc->pipe;
4926 struct intel_crtc_scaler_state *scaler_state =
4927 &crtc->config->scaler_state;
4929 if (crtc->config->pch_pfit.enabled) {
4932 if (WARN_ON(crtc->config->scaler_state.scaler_id < 0))
4935 id = scaler_state->scaler_id;
4936 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
4937 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
4938 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
4939 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
4943 static void ironlake_pfit_enable(struct intel_crtc *crtc)
4945 struct drm_device *dev = crtc->base.dev;
4946 struct drm_i915_private *dev_priv = to_i915(dev);
4947 int pipe = crtc->pipe;
4949 if (crtc->config->pch_pfit.enabled) {
4950 /* Force use of hard-coded filter coefficients
4951 * as some pre-programmed values are broken,
4954 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
4955 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
4956 PF_PIPE_SEL_IVB(pipe));
4958 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
4959 I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
4960 I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
4964 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
4966 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4967 struct drm_device *dev = crtc->base.dev;
4968 struct drm_i915_private *dev_priv = to_i915(dev);
4970 if (!crtc_state->ips_enabled)
4974 * We can only enable IPS after we enable a plane and wait for a vblank
4975 * This function is called from post_plane_update, which is run after
4978 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
4980 if (IS_BROADWELL(dev_priv)) {
4981 mutex_lock(&dev_priv->pcu_lock);
4982 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
4983 IPS_ENABLE | IPS_PCODE_CONTROL));
4984 mutex_unlock(&dev_priv->pcu_lock);
4985 /* Quoting Art Runyan: "its not safe to expect any particular
4986 * value in IPS_CTL bit 31 after enabling IPS through the
4987 * mailbox." Moreover, the mailbox may return a bogus state,
4988 * so we need to just enable it and continue on.
4991 I915_WRITE(IPS_CTL, IPS_ENABLE);
4992 /* The bit only becomes 1 in the next vblank, so this wait here
4993 * is essentially intel_wait_for_vblank. If we don't have this
4994 * and don't wait for vblanks until the end of crtc_enable, then
4995 * the HW state readout code will complain that the expected
4996 * IPS_CTL value is not the one we read. */
4997 if (intel_wait_for_register(dev_priv,
4998 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5000 DRM_ERROR("Timed out waiting for IPS enable\n");
5004 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5006 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5007 struct drm_device *dev = crtc->base.dev;
5008 struct drm_i915_private *dev_priv = to_i915(dev);
5010 if (!crtc_state->ips_enabled)
5013 if (IS_BROADWELL(dev_priv)) {
5014 mutex_lock(&dev_priv->pcu_lock);
5015 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5016 mutex_unlock(&dev_priv->pcu_lock);
5017 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
5018 if (intel_wait_for_register(dev_priv,
5019 IPS_CTL, IPS_ENABLE, 0,
5021 DRM_ERROR("Timed out waiting for IPS disable\n");
5023 I915_WRITE(IPS_CTL, 0);
5024 POSTING_READ(IPS_CTL);
5027 /* We need to wait for a vblank before we can disable the plane. */
5028 intel_wait_for_vblank(dev_priv, crtc->pipe);
5031 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5033 if (intel_crtc->overlay) {
5034 struct drm_device *dev = intel_crtc->base.dev;
5036 mutex_lock(&dev->struct_mutex);
5037 (void) intel_overlay_switch_off(intel_crtc->overlay);
5038 mutex_unlock(&dev->struct_mutex);
5041 /* Let userspace switch the overlay on again. In most cases userspace
5042 * has to recompute where to put it anyway.
5047 * intel_post_enable_primary - Perform operations after enabling primary plane
5048 * @crtc: the CRTC whose primary plane was just enabled
5049 * @new_crtc_state: the enabling state
5051 * Performs potentially sleeping operations that must be done after the primary
5052 * plane is enabled, such as updating FBC and IPS. Note that this may be
5053 * called due to an explicit primary plane update, or due to an implicit
5054 * re-enable that is caused when a sprite plane is updated to no longer
5055 * completely hide the primary plane.
5058 intel_post_enable_primary(struct drm_crtc *crtc,
5059 const struct intel_crtc_state *new_crtc_state)
5061 struct drm_device *dev = crtc->dev;
5062 struct drm_i915_private *dev_priv = to_i915(dev);
5063 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5064 int pipe = intel_crtc->pipe;
5067 * Gen2 reports pipe underruns whenever all planes are disabled.
5068 * So don't enable underrun reporting before at least some planes
5070 * FIXME: Need to fix the logic to work when we turn off all planes
5071 * but leave the pipe running.
5073 if (IS_GEN2(dev_priv))
5074 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5076 /* Underruns don't always raise interrupts, so check manually. */
5077 intel_check_cpu_fifo_underruns(dev_priv);
5078 intel_check_pch_fifo_underruns(dev_priv);
5081 /* FIXME get rid of this and use pre_plane_update */
5083 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5085 struct drm_device *dev = crtc->dev;
5086 struct drm_i915_private *dev_priv = to_i915(dev);
5087 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5088 int pipe = intel_crtc->pipe;
5091 * Gen2 reports pipe underruns whenever all planes are disabled.
5092 * So disable underrun reporting before all the planes get disabled.
5094 if (IS_GEN2(dev_priv))
5095 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5097 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5100 * Vblank time updates from the shadow to live plane control register
5101 * are blocked if the memory self-refresh mode is active at that
5102 * moment. So to make sure the plane gets truly disabled, disable
5103 * first the self-refresh mode. The self-refresh enable bit in turn
5104 * will be checked/applied by the HW only at the next frame start
5105 * event which is after the vblank start event, so we need to have a
5106 * wait-for-vblank between disabling the plane and the pipe.
5108 if (HAS_GMCH_DISPLAY(dev_priv) &&
5109 intel_set_memory_cxsr(dev_priv, false))
5110 intel_wait_for_vblank(dev_priv, pipe);
5113 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5114 const struct intel_crtc_state *new_crtc_state)
5116 if (!old_crtc_state->ips_enabled)
5119 if (needs_modeset(&new_crtc_state->base))
5122 return !new_crtc_state->ips_enabled;
5125 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5126 const struct intel_crtc_state *new_crtc_state)
5128 if (!new_crtc_state->ips_enabled)
5131 if (needs_modeset(&new_crtc_state->base))
5135 * We can't read out IPS on broadwell, assume the worst and
5136 * forcibly enable IPS on the first fastset.
5138 if (new_crtc_state->update_pipe &&
5139 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5142 return !old_crtc_state->ips_enabled;
5145 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5147 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5148 struct drm_device *dev = crtc->base.dev;
5149 struct drm_i915_private *dev_priv = to_i915(dev);
5150 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5151 struct intel_crtc_state *pipe_config =
5152 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5154 struct drm_plane *primary = crtc->base.primary;
5155 struct drm_plane_state *old_primary_state =
5156 drm_atomic_get_old_plane_state(old_state, primary);
5158 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5160 if (pipe_config->update_wm_post && pipe_config->base.active)
5161 intel_update_watermarks(crtc);
5163 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5164 hsw_enable_ips(pipe_config);
5166 if (old_primary_state) {
5167 struct drm_plane_state *new_primary_state =
5168 drm_atomic_get_new_plane_state(old_state, primary);
5169 struct drm_framebuffer *fb = new_primary_state->fb;
5171 intel_fbc_post_update(crtc);
5173 if (new_primary_state->visible &&
5174 (needs_modeset(&pipe_config->base) ||
5175 !old_primary_state->visible))
5176 intel_post_enable_primary(&crtc->base, pipe_config);
5178 /* Display WA 827 */
5179 if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
5180 IS_CANNONLAKE(dev_priv)) {
5181 if (fb && fb->format->format == DRM_FORMAT_NV12)
5182 skl_wa_clkgate(dev_priv, crtc->pipe, false);
5188 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5189 struct intel_crtc_state *pipe_config)
5191 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5192 struct drm_device *dev = crtc->base.dev;
5193 struct drm_i915_private *dev_priv = to_i915(dev);
5194 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5195 struct drm_plane *primary = crtc->base.primary;
5196 struct drm_plane_state *old_primary_state =
5197 drm_atomic_get_old_plane_state(old_state, primary);
5198 bool modeset = needs_modeset(&pipe_config->base);
5199 struct intel_atomic_state *old_intel_state =
5200 to_intel_atomic_state(old_state);
5202 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5203 hsw_disable_ips(old_crtc_state);
5205 if (old_primary_state) {
5206 struct intel_plane_state *new_primary_state =
5207 intel_atomic_get_new_plane_state(old_intel_state,
5208 to_intel_plane(primary));
5209 struct drm_framebuffer *fb = new_primary_state->base.fb;
5211 /* Display WA 827 */
5212 if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
5213 IS_CANNONLAKE(dev_priv)) {
5214 if (fb && fb->format->format == DRM_FORMAT_NV12)
5215 skl_wa_clkgate(dev_priv, crtc->pipe, true);
5218 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5220 * Gen2 reports pipe underruns whenever all planes are disabled.
5221 * So disable underrun reporting before all the planes get disabled.
5223 if (IS_GEN2(dev_priv) && old_primary_state->visible &&
5224 (modeset || !new_primary_state->base.visible))
5225 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5229 * Vblank time updates from the shadow to live plane control register
5230 * are blocked if the memory self-refresh mode is active at that
5231 * moment. So to make sure the plane gets truly disabled, disable
5232 * first the self-refresh mode. The self-refresh enable bit in turn
5233 * will be checked/applied by the HW only at the next frame start
5234 * event which is after the vblank start event, so we need to have a
5235 * wait-for-vblank between disabling the plane and the pipe.
5237 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5238 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5239 intel_wait_for_vblank(dev_priv, crtc->pipe);
5242 * IVB workaround: must disable low power watermarks for at least
5243 * one frame before enabling scaling. LP watermarks can be re-enabled
5244 * when scaling is disabled.
5246 * WaCxSRDisabledForSpriteScaling:ivb
5248 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev))
5249 intel_wait_for_vblank(dev_priv, crtc->pipe);
5252 * If we're doing a modeset, we're done. No need to do any pre-vblank
5253 * watermark programming here.
5255 if (needs_modeset(&pipe_config->base))
5259 * For platforms that support atomic watermarks, program the
5260 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5261 * will be the intermediate values that are safe for both pre- and
5262 * post- vblank; when vblank happens, the 'active' values will be set
5263 * to the final 'target' values and we'll do this again to get the
5264 * optimal watermarks. For gen9+ platforms, the values we program here
5265 * will be the final target values which will get automatically latched
5266 * at vblank time; no further programming will be necessary.
5268 * If a platform hasn't been transitioned to atomic watermarks yet,
5269 * we'll continue to update watermarks the old way, if flags tell
5272 if (dev_priv->display.initial_watermarks != NULL)
5273 dev_priv->display.initial_watermarks(old_intel_state,
5275 else if (pipe_config->update_wm_pre)
5276 intel_update_watermarks(crtc);
5279 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
5281 struct drm_device *dev = crtc->dev;
5282 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5283 struct drm_plane *p;
5284 int pipe = intel_crtc->pipe;
5286 intel_crtc_dpms_overlay_disable(intel_crtc);
5288 drm_for_each_plane_mask(p, dev, plane_mask)
5289 to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc);
5292 * FIXME: Once we grow proper nuclear flip support out of this we need
5293 * to compute the mask of flip planes precisely. For the time being
5294 * consider this a flip to a NULL plane.
5296 intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe));
5299 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5300 struct intel_crtc_state *crtc_state,
5301 struct drm_atomic_state *old_state)
5303 struct drm_connector_state *conn_state;
5304 struct drm_connector *conn;
5307 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5308 struct intel_encoder *encoder =
5309 to_intel_encoder(conn_state->best_encoder);
5311 if (conn_state->crtc != crtc)
5314 if (encoder->pre_pll_enable)
5315 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5319 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5320 struct intel_crtc_state *crtc_state,
5321 struct drm_atomic_state *old_state)
5323 struct drm_connector_state *conn_state;
5324 struct drm_connector *conn;
5327 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5328 struct intel_encoder *encoder =
5329 to_intel_encoder(conn_state->best_encoder);
5331 if (conn_state->crtc != crtc)
5334 if (encoder->pre_enable)
5335 encoder->pre_enable(encoder, crtc_state, conn_state);
5339 static void intel_encoders_enable(struct drm_crtc *crtc,
5340 struct intel_crtc_state *crtc_state,
5341 struct drm_atomic_state *old_state)
5343 struct drm_connector_state *conn_state;
5344 struct drm_connector *conn;
5347 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5348 struct intel_encoder *encoder =
5349 to_intel_encoder(conn_state->best_encoder);
5351 if (conn_state->crtc != crtc)
5354 encoder->enable(encoder, crtc_state, conn_state);
5355 intel_opregion_notify_encoder(encoder, true);
5359 static void intel_encoders_disable(struct drm_crtc *crtc,
5360 struct intel_crtc_state *old_crtc_state,
5361 struct drm_atomic_state *old_state)
5363 struct drm_connector_state *old_conn_state;
5364 struct drm_connector *conn;
5367 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5368 struct intel_encoder *encoder =
5369 to_intel_encoder(old_conn_state->best_encoder);
5371 if (old_conn_state->crtc != crtc)
5374 intel_opregion_notify_encoder(encoder, false);
5375 encoder->disable(encoder, old_crtc_state, old_conn_state);
5379 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5380 struct intel_crtc_state *old_crtc_state,
5381 struct drm_atomic_state *old_state)
5383 struct drm_connector_state *old_conn_state;
5384 struct drm_connector *conn;
5387 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5388 struct intel_encoder *encoder =
5389 to_intel_encoder(old_conn_state->best_encoder);
5391 if (old_conn_state->crtc != crtc)
5394 if (encoder->post_disable)
5395 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5399 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5400 struct intel_crtc_state *old_crtc_state,
5401 struct drm_atomic_state *old_state)
5403 struct drm_connector_state *old_conn_state;
5404 struct drm_connector *conn;
5407 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5408 struct intel_encoder *encoder =
5409 to_intel_encoder(old_conn_state->best_encoder);
5411 if (old_conn_state->crtc != crtc)
5414 if (encoder->post_pll_disable)
5415 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5419 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5420 struct drm_atomic_state *old_state)
5422 struct drm_crtc *crtc = pipe_config->base.crtc;
5423 struct drm_device *dev = crtc->dev;
5424 struct drm_i915_private *dev_priv = to_i915(dev);
5425 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5426 int pipe = intel_crtc->pipe;
5427 struct intel_atomic_state *old_intel_state =
5428 to_intel_atomic_state(old_state);
5430 if (WARN_ON(intel_crtc->active))
5434 * Sometimes spurious CPU pipe underruns happen during FDI
5435 * training, at least with VGA+HDMI cloning. Suppress them.
5437 * On ILK we get an occasional spurious CPU pipe underruns
5438 * between eDP port A enable and vdd enable. Also PCH port
5439 * enable seems to result in the occasional CPU pipe underrun.
5441 * Spurious PCH underruns also occur during PCH enabling.
5443 if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv))
5444 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5445 if (intel_crtc->config->has_pch_encoder)
5446 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5448 if (intel_crtc->config->has_pch_encoder)
5449 intel_prepare_shared_dpll(intel_crtc);
5451 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5452 intel_dp_set_m_n(intel_crtc, M1_N1);
5454 intel_set_pipe_timings(intel_crtc);
5455 intel_set_pipe_src_size(intel_crtc);
5457 if (intel_crtc->config->has_pch_encoder) {
5458 intel_cpu_transcoder_set_m_n(intel_crtc,
5459 &intel_crtc->config->fdi_m_n, NULL);
5462 ironlake_set_pipeconf(crtc);
5464 intel_crtc->active = true;
5466 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5468 if (intel_crtc->config->has_pch_encoder) {
5469 /* Note: FDI PLL enabling _must_ be done before we enable the
5470 * cpu pipes, hence this is separate from all the other fdi/pch
5472 ironlake_fdi_pll_enable(intel_crtc);
5474 assert_fdi_tx_disabled(dev_priv, pipe);
5475 assert_fdi_rx_disabled(dev_priv, pipe);
5478 ironlake_pfit_enable(intel_crtc);
5481 * On ILK+ LUT must be loaded before the pipe is running but with
5484 intel_color_load_luts(&pipe_config->base);
5486 if (dev_priv->display.initial_watermarks != NULL)
5487 dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config);
5488 intel_enable_pipe(pipe_config);
5490 if (intel_crtc->config->has_pch_encoder)
5491 ironlake_pch_enable(pipe_config);
5493 assert_vblank_disabled(crtc);
5494 drm_crtc_vblank_on(crtc);
5496 intel_encoders_enable(crtc, pipe_config, old_state);
5498 if (HAS_PCH_CPT(dev_priv))
5499 cpt_verify_modeset(dev, intel_crtc->pipe);
5501 /* Must wait for vblank to avoid spurious PCH FIFO underruns */
5502 if (intel_crtc->config->has_pch_encoder)
5503 intel_wait_for_vblank(dev_priv, pipe);
5504 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5505 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5508 /* IPS only exists on ULT machines and is tied to pipe A. */
5509 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5511 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5514 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5515 enum pipe pipe, bool apply)
5517 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5518 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5525 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5528 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5530 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5531 enum pipe pipe = crtc->pipe;
5534 val = MBUS_DBOX_BW_CREDIT(1) | MBUS_DBOX_A_CREDIT(2);
5536 /* Program B credit equally to all pipes */
5537 val |= MBUS_DBOX_B_CREDIT(24 / INTEL_INFO(dev_priv)->num_pipes);
5539 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5542 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5543 struct drm_atomic_state *old_state)
5545 struct drm_crtc *crtc = pipe_config->base.crtc;
5546 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5547 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5548 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5549 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5550 struct intel_atomic_state *old_intel_state =
5551 to_intel_atomic_state(old_state);
5552 bool psl_clkgate_wa;
5554 if (WARN_ON(intel_crtc->active))
5557 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5559 if (intel_crtc->config->shared_dpll)
5560 intel_enable_shared_dpll(intel_crtc);
5562 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5563 intel_dp_set_m_n(intel_crtc, M1_N1);
5565 if (!transcoder_is_dsi(cpu_transcoder))
5566 intel_set_pipe_timings(intel_crtc);
5568 intel_set_pipe_src_size(intel_crtc);
5570 if (cpu_transcoder != TRANSCODER_EDP &&
5571 !transcoder_is_dsi(cpu_transcoder)) {
5572 I915_WRITE(PIPE_MULT(cpu_transcoder),
5573 intel_crtc->config->pixel_multiplier - 1);
5576 if (intel_crtc->config->has_pch_encoder) {
5577 intel_cpu_transcoder_set_m_n(intel_crtc,
5578 &intel_crtc->config->fdi_m_n, NULL);
5581 if (!transcoder_is_dsi(cpu_transcoder))
5582 haswell_set_pipeconf(crtc);
5584 haswell_set_pipemisc(crtc);
5586 intel_color_set_csc(&pipe_config->base);
5588 intel_crtc->active = true;
5590 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5592 if (!transcoder_is_dsi(cpu_transcoder))
5593 intel_ddi_enable_pipe_clock(pipe_config);
5595 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5596 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5597 intel_crtc->config->pch_pfit.enabled;
5599 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5601 if (INTEL_GEN(dev_priv) >= 9)
5602 skylake_pfit_enable(intel_crtc);
5604 ironlake_pfit_enable(intel_crtc);
5607 * On ILK+ LUT must be loaded before the pipe is running but with
5610 intel_color_load_luts(&pipe_config->base);
5612 intel_ddi_set_pipe_settings(pipe_config);
5613 if (!transcoder_is_dsi(cpu_transcoder))
5614 intel_ddi_enable_transcoder_func(pipe_config);
5616 if (dev_priv->display.initial_watermarks != NULL)
5617 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5619 if (INTEL_GEN(dev_priv) >= 11)
5620 icl_pipe_mbus_enable(intel_crtc);
5622 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5623 if (!transcoder_is_dsi(cpu_transcoder))
5624 intel_enable_pipe(pipe_config);
5626 if (intel_crtc->config->has_pch_encoder)
5627 lpt_pch_enable(pipe_config);
5629 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5630 intel_ddi_set_vc_payload_alloc(pipe_config, true);
5632 assert_vblank_disabled(crtc);
5633 drm_crtc_vblank_on(crtc);
5635 intel_encoders_enable(crtc, pipe_config, old_state);
5637 if (psl_clkgate_wa) {
5638 intel_wait_for_vblank(dev_priv, pipe);
5639 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5642 /* If we change the relative order between pipe/planes enabling, we need
5643 * to change the workaround. */
5644 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
5645 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5646 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5647 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5651 static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force)
5653 struct drm_device *dev = crtc->base.dev;
5654 struct drm_i915_private *dev_priv = to_i915(dev);
5655 int pipe = crtc->pipe;
5657 /* To avoid upsetting the power well on haswell only disable the pfit if
5658 * it's in use. The hw state code will make sure we get this right. */
5659 if (force || crtc->config->pch_pfit.enabled) {
5660 I915_WRITE(PF_CTL(pipe), 0);
5661 I915_WRITE(PF_WIN_POS(pipe), 0);
5662 I915_WRITE(PF_WIN_SZ(pipe), 0);
5666 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5667 struct drm_atomic_state *old_state)
5669 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5670 struct drm_device *dev = crtc->dev;
5671 struct drm_i915_private *dev_priv = to_i915(dev);
5672 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5673 int pipe = intel_crtc->pipe;
5676 * Sometimes spurious CPU pipe underruns happen when the
5677 * pipe is already disabled, but FDI RX/TX is still enabled.
5678 * Happens at least with VGA+HDMI cloning. Suppress them.
5680 if (intel_crtc->config->has_pch_encoder) {
5681 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5682 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5685 intel_encoders_disable(crtc, old_crtc_state, old_state);
5687 drm_crtc_vblank_off(crtc);
5688 assert_vblank_disabled(crtc);
5690 intel_disable_pipe(old_crtc_state);
5692 ironlake_pfit_disable(intel_crtc, false);
5694 if (intel_crtc->config->has_pch_encoder)
5695 ironlake_fdi_disable(crtc);
5697 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5699 if (intel_crtc->config->has_pch_encoder) {
5700 ironlake_disable_pch_transcoder(dev_priv, pipe);
5702 if (HAS_PCH_CPT(dev_priv)) {
5706 /* disable TRANS_DP_CTL */
5707 reg = TRANS_DP_CTL(pipe);
5708 temp = I915_READ(reg);
5709 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5710 TRANS_DP_PORT_SEL_MASK);
5711 temp |= TRANS_DP_PORT_SEL_NONE;
5712 I915_WRITE(reg, temp);
5714 /* disable DPLL_SEL */
5715 temp = I915_READ(PCH_DPLL_SEL);
5716 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5717 I915_WRITE(PCH_DPLL_SEL, temp);
5720 ironlake_fdi_pll_disable(intel_crtc);
5723 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5724 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5727 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5728 struct drm_atomic_state *old_state)
5730 struct drm_crtc *crtc = old_crtc_state->base.crtc;
5731 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5732 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5733 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
5735 intel_encoders_disable(crtc, old_crtc_state, old_state);
5737 drm_crtc_vblank_off(crtc);
5738 assert_vblank_disabled(crtc);
5740 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
5741 if (!transcoder_is_dsi(cpu_transcoder))
5742 intel_disable_pipe(old_crtc_state);
5744 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
5745 intel_ddi_set_vc_payload_alloc(intel_crtc->config, false);
5747 if (!transcoder_is_dsi(cpu_transcoder))
5748 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
5750 if (INTEL_GEN(dev_priv) >= 9)
5751 skylake_scaler_disable(intel_crtc);
5753 ironlake_pfit_disable(intel_crtc, false);
5755 if (!transcoder_is_dsi(cpu_transcoder))
5756 intel_ddi_disable_pipe_clock(intel_crtc->config);
5758 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
5761 static void i9xx_pfit_enable(struct intel_crtc *crtc)
5763 struct drm_device *dev = crtc->base.dev;
5764 struct drm_i915_private *dev_priv = to_i915(dev);
5765 struct intel_crtc_state *pipe_config = crtc->config;
5767 if (!pipe_config->gmch_pfit.control)
5771 * The panel fitter should only be adjusted whilst the pipe is disabled,
5772 * according to register description and PRM.
5774 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5775 assert_pipe_disabled(dev_priv, crtc->pipe);
5777 I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
5778 I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
5780 /* Border color in case we don't scale up to the full screen. Black by
5781 * default, change to something else for debugging. */
5782 I915_WRITE(BCLRPAT(crtc->pipe), 0);
5785 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
5789 return POWER_DOMAIN_PORT_DDI_A_LANES;
5791 return POWER_DOMAIN_PORT_DDI_B_LANES;
5793 return POWER_DOMAIN_PORT_DDI_C_LANES;
5795 return POWER_DOMAIN_PORT_DDI_D_LANES;
5797 return POWER_DOMAIN_PORT_DDI_E_LANES;
5799 return POWER_DOMAIN_PORT_DDI_F_LANES;
5802 return POWER_DOMAIN_PORT_OTHER;
5806 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
5807 struct intel_crtc_state *crtc_state)
5809 struct drm_device *dev = crtc->dev;
5810 struct drm_i915_private *dev_priv = to_i915(dev);
5811 struct drm_encoder *encoder;
5812 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5813 enum pipe pipe = intel_crtc->pipe;
5815 enum transcoder transcoder = crtc_state->cpu_transcoder;
5817 if (!crtc_state->base.active)
5820 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
5821 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
5822 if (crtc_state->pch_pfit.enabled ||
5823 crtc_state->pch_pfit.force_thru)
5824 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5826 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
5827 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5829 mask |= BIT_ULL(intel_encoder->power_domain);
5832 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
5833 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
5835 if (crtc_state->shared_dpll)
5836 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
5842 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
5843 struct intel_crtc_state *crtc_state)
5845 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5846 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5847 enum intel_display_power_domain domain;
5848 u64 domains, new_domains, old_domains;
5850 old_domains = intel_crtc->enabled_power_domains;
5851 intel_crtc->enabled_power_domains = new_domains =
5852 get_crtc_power_domains(crtc, crtc_state);
5854 domains = new_domains & ~old_domains;
5856 for_each_power_domain(domain, domains)
5857 intel_display_power_get(dev_priv, domain);
5859 return old_domains & ~new_domains;
5862 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
5865 enum intel_display_power_domain domain;
5867 for_each_power_domain(domain, domains)
5868 intel_display_power_put(dev_priv, domain);
5871 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
5872 struct drm_atomic_state *old_state)
5874 struct intel_atomic_state *old_intel_state =
5875 to_intel_atomic_state(old_state);
5876 struct drm_crtc *crtc = pipe_config->base.crtc;
5877 struct drm_device *dev = crtc->dev;
5878 struct drm_i915_private *dev_priv = to_i915(dev);
5879 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5880 int pipe = intel_crtc->pipe;
5882 if (WARN_ON(intel_crtc->active))
5885 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5886 intel_dp_set_m_n(intel_crtc, M1_N1);
5888 intel_set_pipe_timings(intel_crtc);
5889 intel_set_pipe_src_size(intel_crtc);
5891 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
5892 struct drm_i915_private *dev_priv = to_i915(dev);
5894 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
5895 I915_WRITE(CHV_CANVAS(pipe), 0);
5898 i9xx_set_pipeconf(intel_crtc);
5900 intel_crtc->active = true;
5902 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5904 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5906 if (IS_CHERRYVIEW(dev_priv)) {
5907 chv_prepare_pll(intel_crtc, intel_crtc->config);
5908 chv_enable_pll(intel_crtc, intel_crtc->config);
5910 vlv_prepare_pll(intel_crtc, intel_crtc->config);
5911 vlv_enable_pll(intel_crtc, intel_crtc->config);
5914 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5916 i9xx_pfit_enable(intel_crtc);
5918 intel_color_load_luts(&pipe_config->base);
5920 dev_priv->display.initial_watermarks(old_intel_state,
5922 intel_enable_pipe(pipe_config);
5924 assert_vblank_disabled(crtc);
5925 drm_crtc_vblank_on(crtc);
5927 intel_encoders_enable(crtc, pipe_config, old_state);
5930 static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
5932 struct drm_device *dev = crtc->base.dev;
5933 struct drm_i915_private *dev_priv = to_i915(dev);
5935 I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
5936 I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
5939 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
5940 struct drm_atomic_state *old_state)
5942 struct intel_atomic_state *old_intel_state =
5943 to_intel_atomic_state(old_state);
5944 struct drm_crtc *crtc = pipe_config->base.crtc;
5945 struct drm_device *dev = crtc->dev;
5946 struct drm_i915_private *dev_priv = to_i915(dev);
5947 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5948 enum pipe pipe = intel_crtc->pipe;
5950 if (WARN_ON(intel_crtc->active))
5953 i9xx_set_pll_dividers(intel_crtc);
5955 if (intel_crtc_has_dp_encoder(intel_crtc->config))
5956 intel_dp_set_m_n(intel_crtc, M1_N1);
5958 intel_set_pipe_timings(intel_crtc);
5959 intel_set_pipe_src_size(intel_crtc);
5961 i9xx_set_pipeconf(intel_crtc);
5963 intel_crtc->active = true;
5965 if (!IS_GEN2(dev_priv))
5966 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5968 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5970 i9xx_enable_pll(intel_crtc, pipe_config);
5972 i9xx_pfit_enable(intel_crtc);
5974 intel_color_load_luts(&pipe_config->base);
5976 if (dev_priv->display.initial_watermarks != NULL)
5977 dev_priv->display.initial_watermarks(old_intel_state,
5978 intel_crtc->config);
5980 intel_update_watermarks(intel_crtc);
5981 intel_enable_pipe(pipe_config);
5983 assert_vblank_disabled(crtc);
5984 drm_crtc_vblank_on(crtc);
5986 intel_encoders_enable(crtc, pipe_config, old_state);
5989 static void i9xx_pfit_disable(struct intel_crtc *crtc)
5991 struct drm_device *dev = crtc->base.dev;
5992 struct drm_i915_private *dev_priv = to_i915(dev);
5994 if (!crtc->config->gmch_pfit.control)
5997 assert_pipe_disabled(dev_priv, crtc->pipe);
5999 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
6000 I915_READ(PFIT_CONTROL));
6001 I915_WRITE(PFIT_CONTROL, 0);
6004 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6005 struct drm_atomic_state *old_state)
6007 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6008 struct drm_device *dev = crtc->dev;
6009 struct drm_i915_private *dev_priv = to_i915(dev);
6010 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6011 int pipe = intel_crtc->pipe;
6014 * On gen2 planes are double buffered but the pipe isn't, so we must
6015 * wait for planes to fully turn off before disabling the pipe.
6017 if (IS_GEN2(dev_priv))
6018 intel_wait_for_vblank(dev_priv, pipe);
6020 intel_encoders_disable(crtc, old_crtc_state, old_state);
6022 drm_crtc_vblank_off(crtc);
6023 assert_vblank_disabled(crtc);
6025 intel_disable_pipe(old_crtc_state);
6027 i9xx_pfit_disable(intel_crtc);
6029 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6031 if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) {
6032 if (IS_CHERRYVIEW(dev_priv))
6033 chv_disable_pll(dev_priv, pipe);
6034 else if (IS_VALLEYVIEW(dev_priv))
6035 vlv_disable_pll(dev_priv, pipe);
6037 i9xx_disable_pll(intel_crtc);
6040 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6042 if (!IS_GEN2(dev_priv))
6043 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6045 if (!dev_priv->display.initial_watermarks)
6046 intel_update_watermarks(intel_crtc);
6048 /* clock the pipe down to 640x480@60 to potentially save power */
6049 if (IS_I830(dev_priv))
6050 i830_enable_pipe(dev_priv, pipe);
6053 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6054 struct drm_modeset_acquire_ctx *ctx)
6056 struct intel_encoder *encoder;
6057 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6058 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6059 enum intel_display_power_domain domain;
6060 struct intel_plane *plane;
6062 struct drm_atomic_state *state;
6063 struct intel_crtc_state *crtc_state;
6066 if (!intel_crtc->active)
6069 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6070 const struct intel_plane_state *plane_state =
6071 to_intel_plane_state(plane->base.state);
6073 if (plane_state->base.visible)
6074 intel_plane_disable_noatomic(intel_crtc, plane);
6077 state = drm_atomic_state_alloc(crtc->dev);
6079 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6080 crtc->base.id, crtc->name);
6084 state->acquire_ctx = ctx;
6086 /* Everything's already locked, -EDEADLK can't happen. */
6087 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6088 ret = drm_atomic_add_affected_connectors(state, crtc);
6090 WARN_ON(IS_ERR(crtc_state) || ret);
6092 dev_priv->display.crtc_disable(crtc_state, state);
6094 drm_atomic_state_put(state);
6096 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6097 crtc->base.id, crtc->name);
6099 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6100 crtc->state->active = false;
6101 intel_crtc->active = false;
6102 crtc->enabled = false;
6103 crtc->state->connector_mask = 0;
6104 crtc->state->encoder_mask = 0;
6106 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6107 encoder->base.crtc = NULL;
6109 intel_fbc_disable(intel_crtc);
6110 intel_update_watermarks(intel_crtc);
6111 intel_disable_shared_dpll(intel_crtc);
6113 domains = intel_crtc->enabled_power_domains;
6114 for_each_power_domain(domain, domains)
6115 intel_display_power_put(dev_priv, domain);
6116 intel_crtc->enabled_power_domains = 0;
6118 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6119 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6120 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6124 * turn all crtc's off, but do not adjust state
6125 * This has to be paired with a call to intel_modeset_setup_hw_state.
6127 int intel_display_suspend(struct drm_device *dev)
6129 struct drm_i915_private *dev_priv = to_i915(dev);
6130 struct drm_atomic_state *state;
6133 state = drm_atomic_helper_suspend(dev);
6134 ret = PTR_ERR_OR_ZERO(state);
6136 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6138 dev_priv->modeset_restore_state = state;
6142 void intel_encoder_destroy(struct drm_encoder *encoder)
6144 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6146 drm_encoder_cleanup(encoder);
6147 kfree(intel_encoder);
6150 /* Cross check the actual hw state with our own modeset state tracking (and it's
6151 * internal consistency). */
6152 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6153 struct drm_connector_state *conn_state)
6155 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6157 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6158 connector->base.base.id,
6159 connector->base.name);
6161 if (connector->get_hw_state(connector)) {
6162 struct intel_encoder *encoder = connector->encoder;
6164 I915_STATE_WARN(!crtc_state,
6165 "connector enabled without attached crtc\n");
6170 I915_STATE_WARN(!crtc_state->active,
6171 "connector is active, but attached crtc isn't\n");
6173 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6176 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6177 "atomic encoder doesn't match attached encoder\n");
6179 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6180 "attached encoder crtc differs from connector crtc\n");
6182 I915_STATE_WARN(crtc_state && crtc_state->active,
6183 "attached crtc is active, but connector isn't\n");
6184 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6185 "best encoder set without crtc!\n");
6189 int intel_connector_init(struct intel_connector *connector)
6191 struct intel_digital_connector_state *conn_state;
6194 * Allocate enough memory to hold intel_digital_connector_state,
6195 * This might be a few bytes too many, but for connectors that don't
6196 * need it we'll free the state and allocate a smaller one on the first
6197 * succesful commit anyway.
6199 conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
6203 __drm_atomic_helper_connector_reset(&connector->base,
6209 struct intel_connector *intel_connector_alloc(void)
6211 struct intel_connector *connector;
6213 connector = kzalloc(sizeof *connector, GFP_KERNEL);
6217 if (intel_connector_init(connector) < 0) {
6226 * Free the bits allocated by intel_connector_alloc.
6227 * This should only be used after intel_connector_alloc has returned
6228 * successfully, and before drm_connector_init returns successfully.
6229 * Otherwise the destroy callbacks for the connector and the state should
6230 * take care of proper cleanup/free
6232 void intel_connector_free(struct intel_connector *connector)
6234 kfree(to_intel_digital_connector_state(connector->base.state));
6238 /* Simple connector->get_hw_state implementation for encoders that support only
6239 * one connector and no cloning and hence the encoder state determines the state
6240 * of the connector. */
6241 bool intel_connector_get_hw_state(struct intel_connector *connector)
6244 struct intel_encoder *encoder = connector->encoder;
6246 return encoder->get_hw_state(encoder, &pipe);
6249 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6251 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6252 return crtc_state->fdi_lanes;
6257 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6258 struct intel_crtc_state *pipe_config)
6260 struct drm_i915_private *dev_priv = to_i915(dev);
6261 struct drm_atomic_state *state = pipe_config->base.state;
6262 struct intel_crtc *other_crtc;
6263 struct intel_crtc_state *other_crtc_state;
6265 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6266 pipe_name(pipe), pipe_config->fdi_lanes);
6267 if (pipe_config->fdi_lanes > 4) {
6268 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6269 pipe_name(pipe), pipe_config->fdi_lanes);
6273 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6274 if (pipe_config->fdi_lanes > 2) {
6275 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6276 pipe_config->fdi_lanes);
6283 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6286 /* Ivybridge 3 pipe is really complicated */
6291 if (pipe_config->fdi_lanes <= 2)
6294 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6296 intel_atomic_get_crtc_state(state, other_crtc);
6297 if (IS_ERR(other_crtc_state))
6298 return PTR_ERR(other_crtc_state);
6300 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6301 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6302 pipe_name(pipe), pipe_config->fdi_lanes);
6307 if (pipe_config->fdi_lanes > 2) {
6308 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6309 pipe_name(pipe), pipe_config->fdi_lanes);
6313 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6315 intel_atomic_get_crtc_state(state, other_crtc);
6316 if (IS_ERR(other_crtc_state))
6317 return PTR_ERR(other_crtc_state);
6319 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6320 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6330 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6331 struct intel_crtc_state *pipe_config)
6333 struct drm_device *dev = intel_crtc->base.dev;
6334 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6335 int lane, link_bw, fdi_dotclock, ret;
6336 bool needs_recompute = false;
6339 /* FDI is a binary signal running at ~2.7GHz, encoding
6340 * each output octet as 10 bits. The actual frequency
6341 * is stored as a divider into a 100MHz clock, and the
6342 * mode pixel clock is stored in units of 1KHz.
6343 * Hence the bw of each lane in terms of the mode signal
6346 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6348 fdi_dotclock = adjusted_mode->crtc_clock;
6350 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6351 pipe_config->pipe_bpp);
6353 pipe_config->fdi_lanes = lane;
6355 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6356 link_bw, &pipe_config->fdi_m_n, false);
6358 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6359 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6360 pipe_config->pipe_bpp -= 2*3;
6361 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6362 pipe_config->pipe_bpp);
6363 needs_recompute = true;
6364 pipe_config->bw_constrained = true;
6369 if (needs_recompute)
6375 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6377 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6378 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6380 /* IPS only exists on ULT machines and is tied to pipe A. */
6381 if (!hsw_crtc_supports_ips(crtc))
6384 if (!i915_modparams.enable_ips)
6387 if (crtc_state->pipe_bpp > 24)
6391 * We compare against max which means we must take
6392 * the increased cdclk requirement into account when
6393 * calculating the new cdclk.
6395 * Should measure whether using a lower cdclk w/o IPS
6397 if (IS_BROADWELL(dev_priv) &&
6398 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6404 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6406 struct drm_i915_private *dev_priv =
6407 to_i915(crtc_state->base.crtc->dev);
6408 struct intel_atomic_state *intel_state =
6409 to_intel_atomic_state(crtc_state->base.state);
6411 if (!hsw_crtc_state_ips_capable(crtc_state))
6414 if (crtc_state->ips_force_disable)
6417 /* IPS should be fine as long as at least one plane is enabled. */
6418 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6421 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6422 if (IS_BROADWELL(dev_priv) &&
6423 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6429 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6431 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6433 /* GDG double wide on either pipe, otherwise pipe A only */
6434 return INTEL_GEN(dev_priv) < 4 &&
6435 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6438 static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6440 uint32_t pixel_rate;
6442 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6445 * We only use IF-ID interlacing. If we ever use
6446 * PF-ID we'll need to adjust the pixel_rate here.
6449 if (pipe_config->pch_pfit.enabled) {
6450 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6451 uint32_t pfit_size = pipe_config->pch_pfit.size;
6453 pipe_w = pipe_config->pipe_src_w;
6454 pipe_h = pipe_config->pipe_src_h;
6456 pfit_w = (pfit_size >> 16) & 0xFFFF;
6457 pfit_h = pfit_size & 0xFFFF;
6458 if (pipe_w < pfit_w)
6460 if (pipe_h < pfit_h)
6463 if (WARN_ON(!pfit_w || !pfit_h))
6466 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6473 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6475 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6477 if (HAS_GMCH_DISPLAY(dev_priv))
6478 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6479 crtc_state->pixel_rate =
6480 crtc_state->base.adjusted_mode.crtc_clock;
6482 crtc_state->pixel_rate =
6483 ilk_pipe_pixel_rate(crtc_state);
6486 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6487 struct intel_crtc_state *pipe_config)
6489 struct drm_device *dev = crtc->base.dev;
6490 struct drm_i915_private *dev_priv = to_i915(dev);
6491 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6492 int clock_limit = dev_priv->max_dotclk_freq;
6494 if (INTEL_GEN(dev_priv) < 4) {
6495 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6498 * Enable double wide mode when the dot clock
6499 * is > 90% of the (display) core speed.
6501 if (intel_crtc_supports_double_wide(crtc) &&
6502 adjusted_mode->crtc_clock > clock_limit) {
6503 clock_limit = dev_priv->max_dotclk_freq;
6504 pipe_config->double_wide = true;
6508 if (adjusted_mode->crtc_clock > clock_limit) {
6509 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6510 adjusted_mode->crtc_clock, clock_limit,
6511 yesno(pipe_config->double_wide));
6515 if (pipe_config->ycbcr420 && pipe_config->base.ctm) {
6517 * There is only one pipe CSC unit per pipe, and we need that
6518 * for output conversion from RGB->YCBCR. So if CTM is already
6519 * applied we can't support YCBCR420 output.
6521 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6526 * Pipe horizontal size must be even in:
6528 * - LVDS dual channel mode
6529 * - Double wide pipe
6531 if (pipe_config->pipe_src_w & 1) {
6532 if (pipe_config->double_wide) {
6533 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6537 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6538 intel_is_dual_link_lvds(dev)) {
6539 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6544 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6545 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6547 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6548 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6551 intel_crtc_compute_pixel_rate(pipe_config);
6553 if (pipe_config->has_pch_encoder)
6554 return ironlake_fdi_compute_config(crtc, pipe_config);
6560 intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
6562 while (*num > DATA_LINK_M_N_MASK ||
6563 *den > DATA_LINK_M_N_MASK) {
6569 static void compute_m_n(unsigned int m, unsigned int n,
6570 uint32_t *ret_m, uint32_t *ret_n,
6574 * Reduce M/N as much as possible without loss in precision. Several DP
6575 * dongles in particular seem to be fussy about too large *link* M/N
6576 * values. The passed in values are more likely to have the least
6577 * significant bits zero than M after rounding below, so do this first.
6580 while ((m & 1) == 0 && (n & 1) == 0) {
6586 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6587 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6588 intel_reduce_m_n_ratio(ret_m, ret_n);
6592 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
6593 int pixel_clock, int link_clock,
6594 struct intel_link_m_n *m_n,
6599 compute_m_n(bits_per_pixel * pixel_clock,
6600 link_clock * nlanes * 8,
6601 &m_n->gmch_m, &m_n->gmch_n,
6604 compute_m_n(pixel_clock, link_clock,
6605 &m_n->link_m, &m_n->link_n,
6609 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6611 if (i915_modparams.panel_use_ssc >= 0)
6612 return i915_modparams.panel_use_ssc != 0;
6613 return dev_priv->vbt.lvds_use_ssc
6614 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6617 static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
6619 return (1 << dpll->n) << 16 | dpll->m2;
6622 static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6624 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
6627 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
6628 struct intel_crtc_state *crtc_state,
6629 struct dpll *reduced_clock)
6631 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6634 if (IS_PINEVIEW(dev_priv)) {
6635 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
6637 fp2 = pnv_dpll_compute_fp(reduced_clock);
6639 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
6641 fp2 = i9xx_dpll_compute_fp(reduced_clock);
6644 crtc_state->dpll_hw_state.fp0 = fp;
6646 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
6648 crtc_state->dpll_hw_state.fp1 = fp2;
6650 crtc_state->dpll_hw_state.fp1 = fp;
6654 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6660 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6661 * and set it to a reasonable value instead.
6663 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6664 reg_val &= 0xffffff00;
6665 reg_val |= 0x00000030;
6666 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6668 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6669 reg_val &= 0x00ffffff;
6670 reg_val |= 0x8c000000;
6671 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6673 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6674 reg_val &= 0xffffff00;
6675 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6677 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6678 reg_val &= 0x00ffffff;
6679 reg_val |= 0xb0000000;
6680 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6683 static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
6684 struct intel_link_m_n *m_n)
6686 struct drm_device *dev = crtc->base.dev;
6687 struct drm_i915_private *dev_priv = to_i915(dev);
6688 int pipe = crtc->pipe;
6690 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6691 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6692 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6693 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6696 static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
6697 struct intel_link_m_n *m_n,
6698 struct intel_link_m_n *m2_n2)
6700 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6701 int pipe = crtc->pipe;
6702 enum transcoder transcoder = crtc->config->cpu_transcoder;
6704 if (INTEL_GEN(dev_priv) >= 5) {
6705 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6706 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6707 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6708 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
6709 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
6710 * for gen < 8) and if DRRS is supported (to make sure the
6711 * registers are not unnecessarily accessed).
6713 if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
6714 INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
6715 I915_WRITE(PIPE_DATA_M2(transcoder),
6716 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6717 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6718 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6719 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6722 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6723 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6724 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6725 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
6729 void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
6731 struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6734 dp_m_n = &crtc->config->dp_m_n;
6735 dp_m2_n2 = &crtc->config->dp_m2_n2;
6736 } else if (m_n == M2_N2) {
6739 * M2_N2 registers are not supported. Hence m2_n2 divider value
6740 * needs to be programmed into M1_N1.
6742 dp_m_n = &crtc->config->dp_m2_n2;
6744 DRM_ERROR("Unsupported divider value\n");
6748 if (crtc->config->has_pch_encoder)
6749 intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
6751 intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
6754 static void vlv_compute_dpll(struct intel_crtc *crtc,
6755 struct intel_crtc_state *pipe_config)
6757 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
6758 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6759 if (crtc->pipe != PIPE_A)
6760 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6762 /* DPLL not used with DSI, but still need the rest set up */
6763 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6764 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6765 DPLL_EXT_BUFFER_ENABLE_VLV;
6767 pipe_config->dpll_hw_state.dpll_md =
6768 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6771 static void chv_compute_dpll(struct intel_crtc *crtc,
6772 struct intel_crtc_state *pipe_config)
6774 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
6775 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
6776 if (crtc->pipe != PIPE_A)
6777 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6779 /* DPLL not used with DSI, but still need the rest set up */
6780 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
6781 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6783 pipe_config->dpll_hw_state.dpll_md =
6784 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6787 static void vlv_prepare_pll(struct intel_crtc *crtc,
6788 const struct intel_crtc_state *pipe_config)
6790 struct drm_device *dev = crtc->base.dev;
6791 struct drm_i915_private *dev_priv = to_i915(dev);
6792 enum pipe pipe = crtc->pipe;
6794 u32 bestn, bestm1, bestm2, bestp1, bestp2;
6795 u32 coreclk, reg_val;
6798 I915_WRITE(DPLL(pipe),
6799 pipe_config->dpll_hw_state.dpll &
6800 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6802 /* No need to actually set up the DPLL with DSI */
6803 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6806 mutex_lock(&dev_priv->sb_lock);
6808 bestn = pipe_config->dpll.n;
6809 bestm1 = pipe_config->dpll.m1;
6810 bestm2 = pipe_config->dpll.m2;
6811 bestp1 = pipe_config->dpll.p1;
6812 bestp2 = pipe_config->dpll.p2;
6814 /* See eDP HDMI DPIO driver vbios notes doc */
6816 /* PLL B needs special handling */
6818 vlv_pllb_recal_opamp(dev_priv, pipe);
6820 /* Set up Tx target for periodic Rcomp update */
6821 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
6823 /* Disable target IRef on PLL */
6824 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
6825 reg_val &= 0x00ffffff;
6826 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
6828 /* Disable fast lock */
6829 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
6831 /* Set idtafcrecal before PLL is enabled */
6832 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6833 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6834 mdiv |= ((bestn << DPIO_N_SHIFT));
6835 mdiv |= (1 << DPIO_K_SHIFT);
6838 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6839 * but we don't support that).
6840 * Note: don't use the DAC post divider as it seems unstable.
6842 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
6843 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6845 mdiv |= DPIO_ENABLE_CALIBRATION;
6846 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6848 /* Set HBR and RBR LPF coefficients */
6849 if (pipe_config->port_clock == 162000 ||
6850 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) ||
6851 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI))
6852 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6855 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6858 if (intel_crtc_has_dp_encoder(pipe_config)) {
6859 /* Use SSC source */
6861 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6864 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6866 } else { /* HDMI or VGA */
6867 /* Use bend source */
6869 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6872 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6876 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
6877 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
6878 if (intel_crtc_has_dp_encoder(crtc->config))
6879 coreclk |= 0x01000000;
6880 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
6882 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
6883 mutex_unlock(&dev_priv->sb_lock);
6886 static void chv_prepare_pll(struct intel_crtc *crtc,
6887 const struct intel_crtc_state *pipe_config)
6889 struct drm_device *dev = crtc->base.dev;
6890 struct drm_i915_private *dev_priv = to_i915(dev);
6891 enum pipe pipe = crtc->pipe;
6892 enum dpio_channel port = vlv_pipe_to_channel(pipe);
6893 u32 loopfilter, tribuf_calcntr;
6894 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
6898 /* Enable Refclk and SSC */
6899 I915_WRITE(DPLL(pipe),
6900 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
6902 /* No need to actually set up the DPLL with DSI */
6903 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6906 bestn = pipe_config->dpll.n;
6907 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
6908 bestm1 = pipe_config->dpll.m1;
6909 bestm2 = pipe_config->dpll.m2 >> 22;
6910 bestp1 = pipe_config->dpll.p1;
6911 bestp2 = pipe_config->dpll.p2;
6912 vco = pipe_config->dpll.vco;
6916 mutex_lock(&dev_priv->sb_lock);
6918 /* p1 and p2 divider */
6919 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
6920 5 << DPIO_CHV_S1_DIV_SHIFT |
6921 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
6922 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
6923 1 << DPIO_CHV_K_DIV_SHIFT);
6925 /* Feedback post-divider - m2 */
6926 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
6928 /* Feedback refclk divider - n and m1 */
6929 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
6930 DPIO_CHV_M1_DIV_BY_2 |
6931 1 << DPIO_CHV_N_DIV_SHIFT);
6933 /* M2 fraction division */
6934 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
6936 /* M2 fraction division enable */
6937 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
6938 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
6939 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
6941 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
6942 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
6944 /* Program digital lock detect threshold */
6945 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
6946 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
6947 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
6948 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
6950 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
6951 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
6954 if (vco == 5400000) {
6955 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
6956 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
6957 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
6958 tribuf_calcntr = 0x9;
6959 } else if (vco <= 6200000) {
6960 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
6961 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
6962 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6963 tribuf_calcntr = 0x9;
6964 } else if (vco <= 6480000) {
6965 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
6966 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
6967 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6968 tribuf_calcntr = 0x8;
6970 /* Not supported. Apply the same limits as in the max case */
6971 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
6972 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
6973 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6976 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
6978 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
6979 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
6980 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
6981 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
6984 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
6985 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
6988 mutex_unlock(&dev_priv->sb_lock);
6992 * vlv_force_pll_on - forcibly enable just the PLL
6993 * @dev_priv: i915 private structure
6994 * @pipe: pipe PLL to enable
6995 * @dpll: PLL configuration
6997 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6998 * in cases where we need the PLL enabled even when @pipe is not going to
7001 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7002 const struct dpll *dpll)
7004 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7005 struct intel_crtc_state *pipe_config;
7007 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7011 pipe_config->base.crtc = &crtc->base;
7012 pipe_config->pixel_multiplier = 1;
7013 pipe_config->dpll = *dpll;
7015 if (IS_CHERRYVIEW(dev_priv)) {
7016 chv_compute_dpll(crtc, pipe_config);
7017 chv_prepare_pll(crtc, pipe_config);
7018 chv_enable_pll(crtc, pipe_config);
7020 vlv_compute_dpll(crtc, pipe_config);
7021 vlv_prepare_pll(crtc, pipe_config);
7022 vlv_enable_pll(crtc, pipe_config);
7031 * vlv_force_pll_off - forcibly disable just the PLL
7032 * @dev_priv: i915 private structure
7033 * @pipe: pipe PLL to disable
7035 * Disable the PLL for @pipe. To be used in cases where we need
7036 * the PLL enabled even when @pipe is not going to be enabled.
7038 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7040 if (IS_CHERRYVIEW(dev_priv))
7041 chv_disable_pll(dev_priv, pipe);
7043 vlv_disable_pll(dev_priv, pipe);
7046 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7047 struct intel_crtc_state *crtc_state,
7048 struct dpll *reduced_clock)
7050 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7052 struct dpll *clock = &crtc_state->dpll;
7054 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7056 dpll = DPLL_VGA_MODE_DIS;
7058 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7059 dpll |= DPLLB_MODE_LVDS;
7061 dpll |= DPLLB_MODE_DAC_SERIAL;
7063 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7064 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7065 dpll |= (crtc_state->pixel_multiplier - 1)
7066 << SDVO_MULTIPLIER_SHIFT_HIRES;
7069 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7070 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7071 dpll |= DPLL_SDVO_HIGH_SPEED;
7073 if (intel_crtc_has_dp_encoder(crtc_state))
7074 dpll |= DPLL_SDVO_HIGH_SPEED;
7076 /* compute bitmask from p1 value */
7077 if (IS_PINEVIEW(dev_priv))
7078 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7080 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7081 if (IS_G4X(dev_priv) && reduced_clock)
7082 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7084 switch (clock->p2) {
7086 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7089 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7092 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7095 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7098 if (INTEL_GEN(dev_priv) >= 4)
7099 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7101 if (crtc_state->sdvo_tv_clock)
7102 dpll |= PLL_REF_INPUT_TVCLKINBC;
7103 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7104 intel_panel_use_ssc(dev_priv))
7105 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7107 dpll |= PLL_REF_INPUT_DREFCLK;
7109 dpll |= DPLL_VCO_ENABLE;
7110 crtc_state->dpll_hw_state.dpll = dpll;
7112 if (INTEL_GEN(dev_priv) >= 4) {
7113 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7114 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7115 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7119 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7120 struct intel_crtc_state *crtc_state,
7121 struct dpll *reduced_clock)
7123 struct drm_device *dev = crtc->base.dev;
7124 struct drm_i915_private *dev_priv = to_i915(dev);
7126 struct dpll *clock = &crtc_state->dpll;
7128 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7130 dpll = DPLL_VGA_MODE_DIS;
7132 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7133 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7136 dpll |= PLL_P1_DIVIDE_BY_TWO;
7138 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7140 dpll |= PLL_P2_DIVIDE_BY_4;
7143 if (!IS_I830(dev_priv) &&
7144 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7145 dpll |= DPLL_DVO_2X_MODE;
7147 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7148 intel_panel_use_ssc(dev_priv))
7149 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7151 dpll |= PLL_REF_INPUT_DREFCLK;
7153 dpll |= DPLL_VCO_ENABLE;
7154 crtc_state->dpll_hw_state.dpll = dpll;
7157 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
7159 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7160 enum pipe pipe = intel_crtc->pipe;
7161 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
7162 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
7163 uint32_t crtc_vtotal, crtc_vblank_end;
7166 /* We need to be careful not to changed the adjusted mode, for otherwise
7167 * the hw state checker will get angry at the mismatch. */
7168 crtc_vtotal = adjusted_mode->crtc_vtotal;
7169 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7171 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7172 /* the chip adds 2 halflines automatically */
7174 crtc_vblank_end -= 1;
7176 if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7177 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7179 vsyncshift = adjusted_mode->crtc_hsync_start -
7180 adjusted_mode->crtc_htotal / 2;
7182 vsyncshift += adjusted_mode->crtc_htotal;
7185 if (INTEL_GEN(dev_priv) > 3)
7186 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7188 I915_WRITE(HTOTAL(cpu_transcoder),
7189 (adjusted_mode->crtc_hdisplay - 1) |
7190 ((adjusted_mode->crtc_htotal - 1) << 16));
7191 I915_WRITE(HBLANK(cpu_transcoder),
7192 (adjusted_mode->crtc_hblank_start - 1) |
7193 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7194 I915_WRITE(HSYNC(cpu_transcoder),
7195 (adjusted_mode->crtc_hsync_start - 1) |
7196 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7198 I915_WRITE(VTOTAL(cpu_transcoder),
7199 (adjusted_mode->crtc_vdisplay - 1) |
7200 ((crtc_vtotal - 1) << 16));
7201 I915_WRITE(VBLANK(cpu_transcoder),
7202 (adjusted_mode->crtc_vblank_start - 1) |
7203 ((crtc_vblank_end - 1) << 16));
7204 I915_WRITE(VSYNC(cpu_transcoder),
7205 (adjusted_mode->crtc_vsync_start - 1) |
7206 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7208 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7209 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7210 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7212 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7213 (pipe == PIPE_B || pipe == PIPE_C))
7214 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7218 static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc)
7220 struct drm_device *dev = intel_crtc->base.dev;
7221 struct drm_i915_private *dev_priv = to_i915(dev);
7222 enum pipe pipe = intel_crtc->pipe;
7224 /* pipesrc controls the size that is scaled from, which should
7225 * always be the user's requested size.
7227 I915_WRITE(PIPESRC(pipe),
7228 ((intel_crtc->config->pipe_src_w - 1) << 16) |
7229 (intel_crtc->config->pipe_src_h - 1));
7232 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7233 struct intel_crtc_state *pipe_config)
7235 struct drm_device *dev = crtc->base.dev;
7236 struct drm_i915_private *dev_priv = to_i915(dev);
7237 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7240 tmp = I915_READ(HTOTAL(cpu_transcoder));
7241 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7242 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7243 tmp = I915_READ(HBLANK(cpu_transcoder));
7244 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7245 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7246 tmp = I915_READ(HSYNC(cpu_transcoder));
7247 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7248 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7250 tmp = I915_READ(VTOTAL(cpu_transcoder));
7251 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7252 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7253 tmp = I915_READ(VBLANK(cpu_transcoder));
7254 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7255 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7256 tmp = I915_READ(VSYNC(cpu_transcoder));
7257 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7258 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7260 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7261 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7262 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7263 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7267 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7268 struct intel_crtc_state *pipe_config)
7270 struct drm_device *dev = crtc->base.dev;
7271 struct drm_i915_private *dev_priv = to_i915(dev);
7274 tmp = I915_READ(PIPESRC(crtc->pipe));
7275 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7276 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7278 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7279 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7282 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7283 struct intel_crtc_state *pipe_config)
7285 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7286 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7287 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7288 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7290 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7291 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7292 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7293 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7295 mode->flags = pipe_config->base.adjusted_mode.flags;
7296 mode->type = DRM_MODE_TYPE_DRIVER;
7298 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7300 mode->hsync = drm_mode_hsync(mode);
7301 mode->vrefresh = drm_mode_vrefresh(mode);
7302 drm_mode_set_name(mode);
7305 static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
7307 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
7312 /* we keep both pipes enabled on 830 */
7313 if (IS_I830(dev_priv))
7314 pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
7316 if (intel_crtc->config->double_wide)
7317 pipeconf |= PIPECONF_DOUBLE_WIDE;
7319 /* only g4x and later have fancy bpc/dither controls */
7320 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7321 IS_CHERRYVIEW(dev_priv)) {
7322 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7323 if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
7324 pipeconf |= PIPECONF_DITHER_EN |
7325 PIPECONF_DITHER_TYPE_SP;
7327 switch (intel_crtc->config->pipe_bpp) {
7329 pipeconf |= PIPECONF_6BPC;
7332 pipeconf |= PIPECONF_8BPC;
7335 pipeconf |= PIPECONF_10BPC;
7338 /* Case prevented by intel_choose_pipe_bpp_dither. */
7343 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7344 if (INTEL_GEN(dev_priv) < 4 ||
7345 intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
7346 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7348 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7350 pipeconf |= PIPECONF_PROGRESSIVE;
7352 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7353 intel_crtc->config->limited_color_range)
7354 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7356 I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
7357 POSTING_READ(PIPECONF(intel_crtc->pipe));
7360 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7361 struct intel_crtc_state *crtc_state)
7363 struct drm_device *dev = crtc->base.dev;
7364 struct drm_i915_private *dev_priv = to_i915(dev);
7365 const struct intel_limit *limit;
7368 memset(&crtc_state->dpll_hw_state, 0,
7369 sizeof(crtc_state->dpll_hw_state));
7371 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7372 if (intel_panel_use_ssc(dev_priv)) {
7373 refclk = dev_priv->vbt.lvds_ssc_freq;
7374 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7377 limit = &intel_limits_i8xx_lvds;
7378 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7379 limit = &intel_limits_i8xx_dvo;
7381 limit = &intel_limits_i8xx_dac;
7384 if (!crtc_state->clock_set &&
7385 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7386 refclk, NULL, &crtc_state->dpll)) {
7387 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7391 i8xx_compute_dpll(crtc, crtc_state, NULL);
7396 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7397 struct intel_crtc_state *crtc_state)
7399 struct drm_device *dev = crtc->base.dev;
7400 struct drm_i915_private *dev_priv = to_i915(dev);
7401 const struct intel_limit *limit;
7404 memset(&crtc_state->dpll_hw_state, 0,
7405 sizeof(crtc_state->dpll_hw_state));
7407 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7408 if (intel_panel_use_ssc(dev_priv)) {
7409 refclk = dev_priv->vbt.lvds_ssc_freq;
7410 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7413 if (intel_is_dual_link_lvds(dev))
7414 limit = &intel_limits_g4x_dual_channel_lvds;
7416 limit = &intel_limits_g4x_single_channel_lvds;
7417 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7418 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7419 limit = &intel_limits_g4x_hdmi;
7420 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7421 limit = &intel_limits_g4x_sdvo;
7423 /* The option is for other outputs */
7424 limit = &intel_limits_i9xx_sdvo;
7427 if (!crtc_state->clock_set &&
7428 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7429 refclk, NULL, &crtc_state->dpll)) {
7430 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7434 i9xx_compute_dpll(crtc, crtc_state, NULL);
7439 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7440 struct intel_crtc_state *crtc_state)
7442 struct drm_device *dev = crtc->base.dev;
7443 struct drm_i915_private *dev_priv = to_i915(dev);
7444 const struct intel_limit *limit;
7447 memset(&crtc_state->dpll_hw_state, 0,
7448 sizeof(crtc_state->dpll_hw_state));
7450 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7451 if (intel_panel_use_ssc(dev_priv)) {
7452 refclk = dev_priv->vbt.lvds_ssc_freq;
7453 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7456 limit = &intel_limits_pineview_lvds;
7458 limit = &intel_limits_pineview_sdvo;
7461 if (!crtc_state->clock_set &&
7462 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7463 refclk, NULL, &crtc_state->dpll)) {
7464 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7468 i9xx_compute_dpll(crtc, crtc_state, NULL);
7473 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7474 struct intel_crtc_state *crtc_state)
7476 struct drm_device *dev = crtc->base.dev;
7477 struct drm_i915_private *dev_priv = to_i915(dev);
7478 const struct intel_limit *limit;
7481 memset(&crtc_state->dpll_hw_state, 0,
7482 sizeof(crtc_state->dpll_hw_state));
7484 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7485 if (intel_panel_use_ssc(dev_priv)) {
7486 refclk = dev_priv->vbt.lvds_ssc_freq;
7487 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7490 limit = &intel_limits_i9xx_lvds;
7492 limit = &intel_limits_i9xx_sdvo;
7495 if (!crtc_state->clock_set &&
7496 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7497 refclk, NULL, &crtc_state->dpll)) {
7498 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7502 i9xx_compute_dpll(crtc, crtc_state, NULL);
7507 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7508 struct intel_crtc_state *crtc_state)
7510 int refclk = 100000;
7511 const struct intel_limit *limit = &intel_limits_chv;
7513 memset(&crtc_state->dpll_hw_state, 0,
7514 sizeof(crtc_state->dpll_hw_state));
7516 if (!crtc_state->clock_set &&
7517 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7518 refclk, NULL, &crtc_state->dpll)) {
7519 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7523 chv_compute_dpll(crtc, crtc_state);
7528 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7529 struct intel_crtc_state *crtc_state)
7531 int refclk = 100000;
7532 const struct intel_limit *limit = &intel_limits_vlv;
7534 memset(&crtc_state->dpll_hw_state, 0,
7535 sizeof(crtc_state->dpll_hw_state));
7537 if (!crtc_state->clock_set &&
7538 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7539 refclk, NULL, &crtc_state->dpll)) {
7540 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7544 vlv_compute_dpll(crtc, crtc_state);
7549 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7550 struct intel_crtc_state *pipe_config)
7552 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7555 if (INTEL_GEN(dev_priv) <= 3 &&
7556 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7559 tmp = I915_READ(PFIT_CONTROL);
7560 if (!(tmp & PFIT_ENABLE))
7563 /* Check whether the pfit is attached to our pipe. */
7564 if (INTEL_GEN(dev_priv) < 4) {
7565 if (crtc->pipe != PIPE_B)
7568 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7572 pipe_config->gmch_pfit.control = tmp;
7573 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7576 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7577 struct intel_crtc_state *pipe_config)
7579 struct drm_device *dev = crtc->base.dev;
7580 struct drm_i915_private *dev_priv = to_i915(dev);
7581 int pipe = pipe_config->cpu_transcoder;
7584 int refclk = 100000;
7586 /* In case of DSI, DPLL will not be used */
7587 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7590 mutex_lock(&dev_priv->sb_lock);
7591 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7592 mutex_unlock(&dev_priv->sb_lock);
7594 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7595 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7596 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7597 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7598 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7600 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7604 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7605 struct intel_initial_plane_config *plane_config)
7607 struct drm_device *dev = crtc->base.dev;
7608 struct drm_i915_private *dev_priv = to_i915(dev);
7609 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7610 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7611 enum pipe pipe = crtc->pipe;
7612 u32 val, base, offset;
7613 int fourcc, pixel_format;
7614 unsigned int aligned_height;
7615 struct drm_framebuffer *fb;
7616 struct intel_framebuffer *intel_fb;
7618 if (!plane->get_hw_state(plane))
7621 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7623 DRM_DEBUG_KMS("failed to alloc fb\n");
7627 fb = &intel_fb->base;
7631 val = I915_READ(DSPCNTR(i9xx_plane));
7633 if (INTEL_GEN(dev_priv) >= 4) {
7634 if (val & DISPPLANE_TILED) {
7635 plane_config->tiling = I915_TILING_X;
7636 fb->modifier = I915_FORMAT_MOD_X_TILED;
7640 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7641 fourcc = i9xx_format_to_fourcc(pixel_format);
7642 fb->format = drm_format_info(fourcc);
7644 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7645 offset = I915_READ(DSPOFFSET(i9xx_plane));
7646 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7647 } else if (INTEL_GEN(dev_priv) >= 4) {
7648 if (plane_config->tiling)
7649 offset = I915_READ(DSPTILEOFF(i9xx_plane));
7651 offset = I915_READ(DSPLINOFF(i9xx_plane));
7652 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7654 base = I915_READ(DSPADDR(i9xx_plane));
7656 plane_config->base = base;
7658 val = I915_READ(PIPESRC(pipe));
7659 fb->width = ((val >> 16) & 0xfff) + 1;
7660 fb->height = ((val >> 0) & 0xfff) + 1;
7662 val = I915_READ(DSPSTRIDE(i9xx_plane));
7663 fb->pitches[0] = val & 0xffffffc0;
7665 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7667 plane_config->size = fb->pitches[0] * aligned_height;
7669 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7670 crtc->base.name, plane->base.name, fb->width, fb->height,
7671 fb->format->cpp[0] * 8, base, fb->pitches[0],
7672 plane_config->size);
7674 plane_config->fb = intel_fb;
7677 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7678 struct intel_crtc_state *pipe_config)
7680 struct drm_device *dev = crtc->base.dev;
7681 struct drm_i915_private *dev_priv = to_i915(dev);
7682 int pipe = pipe_config->cpu_transcoder;
7683 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7685 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7686 int refclk = 100000;
7688 /* In case of DSI, DPLL will not be used */
7689 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7692 mutex_lock(&dev_priv->sb_lock);
7693 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7694 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7695 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7696 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7697 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7698 mutex_unlock(&dev_priv->sb_lock);
7700 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7701 clock.m2 = (pll_dw0 & 0xff) << 22;
7702 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7703 clock.m2 |= pll_dw2 & 0x3fffff;
7704 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7705 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7706 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7708 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7711 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7712 struct intel_crtc_state *pipe_config)
7714 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7715 enum intel_display_power_domain power_domain;
7719 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7720 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7723 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7724 pipe_config->shared_dpll = NULL;
7728 tmp = I915_READ(PIPECONF(crtc->pipe));
7729 if (!(tmp & PIPECONF_ENABLE))
7732 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7733 IS_CHERRYVIEW(dev_priv)) {
7734 switch (tmp & PIPECONF_BPC_MASK) {
7736 pipe_config->pipe_bpp = 18;
7739 pipe_config->pipe_bpp = 24;
7741 case PIPECONF_10BPC:
7742 pipe_config->pipe_bpp = 30;
7749 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7750 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7751 pipe_config->limited_color_range = true;
7753 if (INTEL_GEN(dev_priv) < 4)
7754 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7756 intel_get_pipe_timings(crtc, pipe_config);
7757 intel_get_pipe_src_size(crtc, pipe_config);
7759 i9xx_get_pfit_config(crtc, pipe_config);
7761 if (INTEL_GEN(dev_priv) >= 4) {
7762 /* No way to read it out on pipes B and C */
7763 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
7764 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7766 tmp = I915_READ(DPLL_MD(crtc->pipe));
7767 pipe_config->pixel_multiplier =
7768 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7769 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
7770 pipe_config->dpll_hw_state.dpll_md = tmp;
7771 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7772 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7773 tmp = I915_READ(DPLL(crtc->pipe));
7774 pipe_config->pixel_multiplier =
7775 ((tmp & SDVO_MULTIPLIER_MASK)
7776 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7778 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7779 * port and will be fixed up in the encoder->get_config
7781 pipe_config->pixel_multiplier = 1;
7783 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
7784 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
7786 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
7787 * on 830. Filter it out here so that we don't
7788 * report errors due to that.
7790 if (IS_I830(dev_priv))
7791 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
7793 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
7794 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
7796 /* Mask out read-only status bits. */
7797 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7798 DPLL_PORTC_READY_MASK |
7799 DPLL_PORTB_READY_MASK);
7802 if (IS_CHERRYVIEW(dev_priv))
7803 chv_crtc_clock_get(crtc, pipe_config);
7804 else if (IS_VALLEYVIEW(dev_priv))
7805 vlv_crtc_clock_get(crtc, pipe_config);
7807 i9xx_crtc_clock_get(crtc, pipe_config);
7810 * Normally the dotclock is filled in by the encoder .get_config()
7811 * but in case the pipe is enabled w/o any ports we need a sane
7814 pipe_config->base.adjusted_mode.crtc_clock =
7815 pipe_config->port_clock / pipe_config->pixel_multiplier;
7820 intel_display_power_put(dev_priv, power_domain);
7825 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
7827 struct intel_encoder *encoder;
7830 bool has_lvds = false;
7831 bool has_cpu_edp = false;
7832 bool has_panel = false;
7833 bool has_ck505 = false;
7834 bool can_ssc = false;
7835 bool using_ssc_source = false;
7837 /* We need to take the global config into account */
7838 for_each_intel_encoder(&dev_priv->drm, encoder) {
7839 switch (encoder->type) {
7840 case INTEL_OUTPUT_LVDS:
7844 case INTEL_OUTPUT_EDP:
7846 if (encoder->port == PORT_A)
7854 if (HAS_PCH_IBX(dev_priv)) {
7855 has_ck505 = dev_priv->vbt.display_clock_mode;
7856 can_ssc = has_ck505;
7862 /* Check if any DPLLs are using the SSC source */
7863 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
7864 u32 temp = I915_READ(PCH_DPLL(i));
7866 if (!(temp & DPLL_VCO_ENABLE))
7869 if ((temp & PLL_REF_INPUT_MASK) ==
7870 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
7871 using_ssc_source = true;
7876 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7877 has_panel, has_lvds, has_ck505, using_ssc_source);
7879 /* Ironlake: try to setup display ref clock before DPLL
7880 * enabling. This is only under driver's control after
7881 * PCH B stepping, previous chipset stepping should be
7882 * ignoring this setting.
7884 val = I915_READ(PCH_DREF_CONTROL);
7886 /* As we must carefully and slowly disable/enable each source in turn,
7887 * compute the final state we want first and check if we need to
7888 * make any changes at all.
7891 final &= ~DREF_NONSPREAD_SOURCE_MASK;
7893 final |= DREF_NONSPREAD_CK505_ENABLE;
7895 final |= DREF_NONSPREAD_SOURCE_ENABLE;
7897 final &= ~DREF_SSC_SOURCE_MASK;
7898 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7899 final &= ~DREF_SSC1_ENABLE;
7902 final |= DREF_SSC_SOURCE_ENABLE;
7904 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7905 final |= DREF_SSC1_ENABLE;
7908 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7909 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7911 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7913 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7914 } else if (using_ssc_source) {
7915 final |= DREF_SSC_SOURCE_ENABLE;
7916 final |= DREF_SSC1_ENABLE;
7922 /* Always enable nonspread source */
7923 val &= ~DREF_NONSPREAD_SOURCE_MASK;
7926 val |= DREF_NONSPREAD_CK505_ENABLE;
7928 val |= DREF_NONSPREAD_SOURCE_ENABLE;
7931 val &= ~DREF_SSC_SOURCE_MASK;
7932 val |= DREF_SSC_SOURCE_ENABLE;
7934 /* SSC must be turned on before enabling the CPU output */
7935 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
7936 DRM_DEBUG_KMS("Using SSC on panel\n");
7937 val |= DREF_SSC1_ENABLE;
7939 val &= ~DREF_SSC1_ENABLE;
7941 /* Get SSC going before enabling the outputs */
7942 I915_WRITE(PCH_DREF_CONTROL, val);
7943 POSTING_READ(PCH_DREF_CONTROL);
7946 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7948 /* Enable CPU source on CPU attached eDP */
7950 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
7951 DRM_DEBUG_KMS("Using SSC on eDP\n");
7952 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7954 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7956 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7958 I915_WRITE(PCH_DREF_CONTROL, val);
7959 POSTING_READ(PCH_DREF_CONTROL);
7962 DRM_DEBUG_KMS("Disabling CPU source output\n");
7964 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7966 /* Turn off CPU output */
7967 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7969 I915_WRITE(PCH_DREF_CONTROL, val);
7970 POSTING_READ(PCH_DREF_CONTROL);
7973 if (!using_ssc_source) {
7974 DRM_DEBUG_KMS("Disabling SSC source\n");
7976 /* Turn off the SSC source */
7977 val &= ~DREF_SSC_SOURCE_MASK;
7978 val |= DREF_SSC_SOURCE_DISABLE;
7981 val &= ~DREF_SSC1_ENABLE;
7983 I915_WRITE(PCH_DREF_CONTROL, val);
7984 POSTING_READ(PCH_DREF_CONTROL);
7989 BUG_ON(val != final);
7992 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
7996 tmp = I915_READ(SOUTH_CHICKEN2);
7997 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
7998 I915_WRITE(SOUTH_CHICKEN2, tmp);
8000 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8001 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8002 DRM_ERROR("FDI mPHY reset assert timeout\n");
8004 tmp = I915_READ(SOUTH_CHICKEN2);
8005 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8006 I915_WRITE(SOUTH_CHICKEN2, tmp);
8008 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8009 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8010 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8013 /* WaMPhyProgramming:hsw */
8014 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8018 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8019 tmp &= ~(0xFF << 24);
8020 tmp |= (0x12 << 24);
8021 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8023 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8025 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8027 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8029 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8031 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8032 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8033 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8035 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8036 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8037 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8039 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8042 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8044 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8047 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8049 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8052 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8054 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8057 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8059 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8060 tmp &= ~(0xFF << 16);
8061 tmp |= (0x1C << 16);
8062 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8064 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8065 tmp &= ~(0xFF << 16);
8066 tmp |= (0x1C << 16);
8067 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8069 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8071 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8073 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8075 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8077 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8078 tmp &= ~(0xF << 28);
8080 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8082 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8083 tmp &= ~(0xF << 28);
8085 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8088 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8089 * Programming" based on the parameters passed:
8090 * - Sequence to enable CLKOUT_DP
8091 * - Sequence to enable CLKOUT_DP without spread
8092 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8094 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8095 bool with_spread, bool with_fdi)
8099 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8101 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8102 with_fdi, "LP PCH doesn't have FDI\n"))
8105 mutex_lock(&dev_priv->sb_lock);
8107 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8108 tmp &= ~SBI_SSCCTL_DISABLE;
8109 tmp |= SBI_SSCCTL_PATHALT;
8110 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8115 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8116 tmp &= ~SBI_SSCCTL_PATHALT;
8117 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8120 lpt_reset_fdi_mphy(dev_priv);
8121 lpt_program_fdi_mphy(dev_priv);
8125 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8126 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8127 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8128 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8130 mutex_unlock(&dev_priv->sb_lock);
8133 /* Sequence to disable CLKOUT_DP */
8134 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8138 mutex_lock(&dev_priv->sb_lock);
8140 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8141 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8142 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8143 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8145 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8146 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8147 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8148 tmp |= SBI_SSCCTL_PATHALT;
8149 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8152 tmp |= SBI_SSCCTL_DISABLE;
8153 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8156 mutex_unlock(&dev_priv->sb_lock);
8159 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8161 static const uint16_t sscdivintphase[] = {
8162 [BEND_IDX( 50)] = 0x3B23,
8163 [BEND_IDX( 45)] = 0x3B23,
8164 [BEND_IDX( 40)] = 0x3C23,
8165 [BEND_IDX( 35)] = 0x3C23,
8166 [BEND_IDX( 30)] = 0x3D23,
8167 [BEND_IDX( 25)] = 0x3D23,
8168 [BEND_IDX( 20)] = 0x3E23,
8169 [BEND_IDX( 15)] = 0x3E23,
8170 [BEND_IDX( 10)] = 0x3F23,
8171 [BEND_IDX( 5)] = 0x3F23,
8172 [BEND_IDX( 0)] = 0x0025,
8173 [BEND_IDX( -5)] = 0x0025,
8174 [BEND_IDX(-10)] = 0x0125,
8175 [BEND_IDX(-15)] = 0x0125,
8176 [BEND_IDX(-20)] = 0x0225,
8177 [BEND_IDX(-25)] = 0x0225,
8178 [BEND_IDX(-30)] = 0x0325,
8179 [BEND_IDX(-35)] = 0x0325,
8180 [BEND_IDX(-40)] = 0x0425,
8181 [BEND_IDX(-45)] = 0x0425,
8182 [BEND_IDX(-50)] = 0x0525,
8187 * steps -50 to 50 inclusive, in steps of 5
8188 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8189 * change in clock period = -(steps / 10) * 5.787 ps
8191 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8194 int idx = BEND_IDX(steps);
8196 if (WARN_ON(steps % 5 != 0))
8199 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8202 mutex_lock(&dev_priv->sb_lock);
8204 if (steps % 10 != 0)
8208 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8210 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8212 tmp |= sscdivintphase[idx];
8213 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8215 mutex_unlock(&dev_priv->sb_lock);
8220 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8222 struct intel_encoder *encoder;
8223 bool has_vga = false;
8225 for_each_intel_encoder(&dev_priv->drm, encoder) {
8226 switch (encoder->type) {
8227 case INTEL_OUTPUT_ANALOG:
8236 lpt_bend_clkout_dp(dev_priv, 0);
8237 lpt_enable_clkout_dp(dev_priv, true, true);
8239 lpt_disable_clkout_dp(dev_priv);
8244 * Initialize reference clocks when the driver loads
8246 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8248 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8249 ironlake_init_pch_refclk(dev_priv);
8250 else if (HAS_PCH_LPT(dev_priv))
8251 lpt_init_pch_refclk(dev_priv);
8254 static void ironlake_set_pipeconf(struct drm_crtc *crtc)
8256 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8257 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8258 int pipe = intel_crtc->pipe;
8263 switch (intel_crtc->config->pipe_bpp) {
8265 val |= PIPECONF_6BPC;
8268 val |= PIPECONF_8BPC;
8271 val |= PIPECONF_10BPC;
8274 val |= PIPECONF_12BPC;
8277 /* Case prevented by intel_choose_pipe_bpp_dither. */
8281 if (intel_crtc->config->dither)
8282 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8284 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8285 val |= PIPECONF_INTERLACED_ILK;
8287 val |= PIPECONF_PROGRESSIVE;
8289 if (intel_crtc->config->limited_color_range)
8290 val |= PIPECONF_COLOR_RANGE_SELECT;
8292 I915_WRITE(PIPECONF(pipe), val);
8293 POSTING_READ(PIPECONF(pipe));
8296 static void haswell_set_pipeconf(struct drm_crtc *crtc)
8298 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8299 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8300 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
8303 if (IS_HASWELL(dev_priv) && intel_crtc->config->dither)
8304 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8306 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8307 val |= PIPECONF_INTERLACED_ILK;
8309 val |= PIPECONF_PROGRESSIVE;
8311 I915_WRITE(PIPECONF(cpu_transcoder), val);
8312 POSTING_READ(PIPECONF(cpu_transcoder));
8315 static void haswell_set_pipemisc(struct drm_crtc *crtc)
8317 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
8318 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
8319 struct intel_crtc_state *config = intel_crtc->config;
8321 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8324 switch (intel_crtc->config->pipe_bpp) {
8326 val |= PIPEMISC_DITHER_6_BPC;
8329 val |= PIPEMISC_DITHER_8_BPC;
8332 val |= PIPEMISC_DITHER_10_BPC;
8335 val |= PIPEMISC_DITHER_12_BPC;
8338 /* Case prevented by pipe_config_set_bpp. */
8342 if (intel_crtc->config->dither)
8343 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8345 if (config->ycbcr420) {
8346 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV |
8347 PIPEMISC_YUV420_ENABLE |
8348 PIPEMISC_YUV420_MODE_FULL_BLEND;
8351 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8355 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8358 * Account for spread spectrum to avoid
8359 * oversubscribing the link. Max center spread
8360 * is 2.5%; use 5% for safety's sake.
8362 u32 bps = target_clock * bpp * 21 / 20;
8363 return DIV_ROUND_UP(bps, link_bw * 8);
8366 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8368 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8371 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8372 struct intel_crtc_state *crtc_state,
8373 struct dpll *reduced_clock)
8375 struct drm_crtc *crtc = &intel_crtc->base;
8376 struct drm_device *dev = crtc->dev;
8377 struct drm_i915_private *dev_priv = to_i915(dev);
8381 /* Enable autotuning of the PLL clock (if permissible) */
8383 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8384 if ((intel_panel_use_ssc(dev_priv) &&
8385 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8386 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8388 } else if (crtc_state->sdvo_tv_clock)
8391 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8393 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8396 if (reduced_clock) {
8397 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8399 if (reduced_clock->m < factor * reduced_clock->n)
8407 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8408 dpll |= DPLLB_MODE_LVDS;
8410 dpll |= DPLLB_MODE_DAC_SERIAL;
8412 dpll |= (crtc_state->pixel_multiplier - 1)
8413 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8415 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8416 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8417 dpll |= DPLL_SDVO_HIGH_SPEED;
8419 if (intel_crtc_has_dp_encoder(crtc_state))
8420 dpll |= DPLL_SDVO_HIGH_SPEED;
8423 * The high speed IO clock is only really required for
8424 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8425 * possible to share the DPLL between CRT and HDMI. Enabling
8426 * the clock needlessly does no real harm, except use up a
8427 * bit of power potentially.
8429 * We'll limit this to IVB with 3 pipes, since it has only two
8430 * DPLLs and so DPLL sharing is the only way to get three pipes
8431 * driving PCH ports at the same time. On SNB we could do this,
8432 * and potentially avoid enabling the second DPLL, but it's not
8433 * clear if it''s a win or loss power wise. No point in doing
8434 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8436 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8437 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8438 dpll |= DPLL_SDVO_HIGH_SPEED;
8440 /* compute bitmask from p1 value */
8441 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8443 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8445 switch (crtc_state->dpll.p2) {
8447 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8450 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8453 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8456 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8460 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8461 intel_panel_use_ssc(dev_priv))
8462 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8464 dpll |= PLL_REF_INPUT_DREFCLK;
8466 dpll |= DPLL_VCO_ENABLE;
8468 crtc_state->dpll_hw_state.dpll = dpll;
8469 crtc_state->dpll_hw_state.fp0 = fp;
8470 crtc_state->dpll_hw_state.fp1 = fp2;
8473 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8474 struct intel_crtc_state *crtc_state)
8476 struct drm_device *dev = crtc->base.dev;
8477 struct drm_i915_private *dev_priv = to_i915(dev);
8478 const struct intel_limit *limit;
8479 int refclk = 120000;
8481 memset(&crtc_state->dpll_hw_state, 0,
8482 sizeof(crtc_state->dpll_hw_state));
8484 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8485 if (!crtc_state->has_pch_encoder)
8488 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8489 if (intel_panel_use_ssc(dev_priv)) {
8490 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8491 dev_priv->vbt.lvds_ssc_freq);
8492 refclk = dev_priv->vbt.lvds_ssc_freq;
8495 if (intel_is_dual_link_lvds(dev)) {
8496 if (refclk == 100000)
8497 limit = &intel_limits_ironlake_dual_lvds_100m;
8499 limit = &intel_limits_ironlake_dual_lvds;
8501 if (refclk == 100000)
8502 limit = &intel_limits_ironlake_single_lvds_100m;
8504 limit = &intel_limits_ironlake_single_lvds;
8507 limit = &intel_limits_ironlake_dac;
8510 if (!crtc_state->clock_set &&
8511 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8512 refclk, NULL, &crtc_state->dpll)) {
8513 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8517 ironlake_compute_dpll(crtc, crtc_state, NULL);
8519 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8520 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
8521 pipe_name(crtc->pipe));
8528 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8529 struct intel_link_m_n *m_n)
8531 struct drm_device *dev = crtc->base.dev;
8532 struct drm_i915_private *dev_priv = to_i915(dev);
8533 enum pipe pipe = crtc->pipe;
8535 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8536 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8537 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8539 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8540 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8541 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8544 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8545 enum transcoder transcoder,
8546 struct intel_link_m_n *m_n,
8547 struct intel_link_m_n *m2_n2)
8549 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8550 enum pipe pipe = crtc->pipe;
8552 if (INTEL_GEN(dev_priv) >= 5) {
8553 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8554 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8555 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8557 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8558 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8559 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8560 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
8561 * gen < 8) and if DRRS is supported (to make sure the
8562 * registers are not unnecessarily read).
8564 if (m2_n2 && INTEL_GEN(dev_priv) < 8 &&
8565 crtc->config->has_drrs) {
8566 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8567 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8568 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8570 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8571 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8572 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8575 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8576 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8577 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8579 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8580 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8581 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8585 void intel_dp_get_m_n(struct intel_crtc *crtc,
8586 struct intel_crtc_state *pipe_config)
8588 if (pipe_config->has_pch_encoder)
8589 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8591 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8592 &pipe_config->dp_m_n,
8593 &pipe_config->dp_m2_n2);
8596 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
8597 struct intel_crtc_state *pipe_config)
8599 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8600 &pipe_config->fdi_m_n, NULL);
8603 static void skylake_get_pfit_config(struct intel_crtc *crtc,
8604 struct intel_crtc_state *pipe_config)
8606 struct drm_device *dev = crtc->base.dev;
8607 struct drm_i915_private *dev_priv = to_i915(dev);
8608 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8609 uint32_t ps_ctrl = 0;
8613 /* find scaler attached to this pipe */
8614 for (i = 0; i < crtc->num_scalers; i++) {
8615 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8616 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8618 pipe_config->pch_pfit.enabled = true;
8619 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8620 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8625 scaler_state->scaler_id = id;
8627 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8629 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8634 skylake_get_initial_plane_config(struct intel_crtc *crtc,
8635 struct intel_initial_plane_config *plane_config)
8637 struct drm_device *dev = crtc->base.dev;
8638 struct drm_i915_private *dev_priv = to_i915(dev);
8639 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8640 enum plane_id plane_id = plane->id;
8641 enum pipe pipe = crtc->pipe;
8642 u32 val, base, offset, stride_mult, tiling, alpha;
8643 int fourcc, pixel_format;
8644 unsigned int aligned_height;
8645 struct drm_framebuffer *fb;
8646 struct intel_framebuffer *intel_fb;
8648 if (!plane->get_hw_state(plane))
8651 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8653 DRM_DEBUG_KMS("failed to alloc fb\n");
8657 fb = &intel_fb->base;
8661 val = I915_READ(PLANE_CTL(pipe, plane_id));
8663 if (INTEL_GEN(dev_priv) >= 11)
8664 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8666 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8668 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8669 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
8670 alpha &= PLANE_COLOR_ALPHA_MASK;
8672 alpha = val & PLANE_CTL_ALPHA_MASK;
8675 fourcc = skl_format_to_fourcc(pixel_format,
8676 val & PLANE_CTL_ORDER_RGBX, alpha);
8677 fb->format = drm_format_info(fourcc);
8679 tiling = val & PLANE_CTL_TILED_MASK;
8681 case PLANE_CTL_TILED_LINEAR:
8682 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8684 case PLANE_CTL_TILED_X:
8685 plane_config->tiling = I915_TILING_X;
8686 fb->modifier = I915_FORMAT_MOD_X_TILED;
8688 case PLANE_CTL_TILED_Y:
8689 if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
8690 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8692 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8694 case PLANE_CTL_TILED_YF:
8695 if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
8696 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8698 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8701 MISSING_CASE(tiling);
8705 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8706 plane_config->base = base;
8708 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
8710 val = I915_READ(PLANE_SIZE(pipe, plane_id));
8711 fb->height = ((val >> 16) & 0xfff) + 1;
8712 fb->width = ((val >> 0) & 0x1fff) + 1;
8714 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
8715 stride_mult = intel_fb_stride_alignment(fb, 0);
8716 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8718 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8720 plane_config->size = fb->pitches[0] * aligned_height;
8722 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8723 crtc->base.name, plane->base.name, fb->width, fb->height,
8724 fb->format->cpp[0] * 8, base, fb->pitches[0],
8725 plane_config->size);
8727 plane_config->fb = intel_fb;
8734 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
8735 struct intel_crtc_state *pipe_config)
8737 struct drm_device *dev = crtc->base.dev;
8738 struct drm_i915_private *dev_priv = to_i915(dev);
8741 tmp = I915_READ(PF_CTL(crtc->pipe));
8743 if (tmp & PF_ENABLE) {
8744 pipe_config->pch_pfit.enabled = true;
8745 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
8746 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
8748 /* We currently do not free assignements of panel fitters on
8749 * ivb/hsw (since we don't use the higher upscaling modes which
8750 * differentiates them) so just WARN about this case for now. */
8751 if (IS_GEN7(dev_priv)) {
8752 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
8753 PF_PIPE_SEL_IVB(crtc->pipe));
8758 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
8759 struct intel_crtc_state *pipe_config)
8761 struct drm_device *dev = crtc->base.dev;
8762 struct drm_i915_private *dev_priv = to_i915(dev);
8763 enum intel_display_power_domain power_domain;
8767 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8768 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
8771 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8772 pipe_config->shared_dpll = NULL;
8775 tmp = I915_READ(PIPECONF(crtc->pipe));
8776 if (!(tmp & PIPECONF_ENABLE))
8779 switch (tmp & PIPECONF_BPC_MASK) {
8781 pipe_config->pipe_bpp = 18;
8784 pipe_config->pipe_bpp = 24;
8786 case PIPECONF_10BPC:
8787 pipe_config->pipe_bpp = 30;
8789 case PIPECONF_12BPC:
8790 pipe_config->pipe_bpp = 36;
8796 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8797 pipe_config->limited_color_range = true;
8799 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
8800 struct intel_shared_dpll *pll;
8801 enum intel_dpll_id pll_id;
8803 pipe_config->has_pch_encoder = true;
8805 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
8806 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8807 FDI_DP_PORT_WIDTH_SHIFT) + 1;
8809 ironlake_get_fdi_m_n_config(crtc, pipe_config);
8811 if (HAS_PCH_IBX(dev_priv)) {
8813 * The pipe->pch transcoder and pch transcoder->pll
8816 pll_id = (enum intel_dpll_id) crtc->pipe;
8818 tmp = I915_READ(PCH_DPLL_SEL);
8819 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
8820 pll_id = DPLL_ID_PCH_PLL_B;
8822 pll_id= DPLL_ID_PCH_PLL_A;
8825 pipe_config->shared_dpll =
8826 intel_get_shared_dpll_by_id(dev_priv, pll_id);
8827 pll = pipe_config->shared_dpll;
8829 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
8830 &pipe_config->dpll_hw_state));
8832 tmp = pipe_config->dpll_hw_state.dpll;
8833 pipe_config->pixel_multiplier =
8834 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
8835 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
8837 ironlake_pch_clock_get(crtc, pipe_config);
8839 pipe_config->pixel_multiplier = 1;
8842 intel_get_pipe_timings(crtc, pipe_config);
8843 intel_get_pipe_src_size(crtc, pipe_config);
8845 ironlake_get_pfit_config(crtc, pipe_config);
8850 intel_display_power_put(dev_priv, power_domain);
8855 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
8857 struct drm_device *dev = &dev_priv->drm;
8858 struct intel_crtc *crtc;
8860 for_each_intel_crtc(dev, crtc)
8861 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
8862 pipe_name(crtc->pipe));
8864 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)),
8865 "Display power well on\n");
8866 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
8867 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
8868 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
8869 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
8870 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
8871 "CPU PWM1 enabled\n");
8872 if (IS_HASWELL(dev_priv))
8873 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
8874 "CPU PWM2 enabled\n");
8875 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
8876 "PCH PWM1 enabled\n");
8877 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
8878 "Utility pin enabled\n");
8879 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
8882 * In theory we can still leave IRQs enabled, as long as only the HPD
8883 * interrupts remain enabled. We used to check for that, but since it's
8884 * gen-specific and since we only disable LCPLL after we fully disable
8885 * the interrupts, the check below should be enough.
8887 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
8890 static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
8892 if (IS_HASWELL(dev_priv))
8893 return I915_READ(D_COMP_HSW);
8895 return I915_READ(D_COMP_BDW);
8898 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
8900 if (IS_HASWELL(dev_priv)) {
8901 mutex_lock(&dev_priv->pcu_lock);
8902 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
8904 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
8905 mutex_unlock(&dev_priv->pcu_lock);
8907 I915_WRITE(D_COMP_BDW, val);
8908 POSTING_READ(D_COMP_BDW);
8913 * This function implements pieces of two sequences from BSpec:
8914 * - Sequence for display software to disable LCPLL
8915 * - Sequence for display software to allow package C8+
8916 * The steps implemented here are just the steps that actually touch the LCPLL
8917 * register. Callers should take care of disabling all the display engine
8918 * functions, doing the mode unset, fixing interrupts, etc.
8920 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
8921 bool switch_to_fclk, bool allow_power_down)
8925 assert_can_disable_lcpll(dev_priv);
8927 val = I915_READ(LCPLL_CTL);
8929 if (switch_to_fclk) {
8930 val |= LCPLL_CD_SOURCE_FCLK;
8931 I915_WRITE(LCPLL_CTL, val);
8933 if (wait_for_us(I915_READ(LCPLL_CTL) &
8934 LCPLL_CD_SOURCE_FCLK_DONE, 1))
8935 DRM_ERROR("Switching to FCLK failed\n");
8937 val = I915_READ(LCPLL_CTL);
8940 val |= LCPLL_PLL_DISABLE;
8941 I915_WRITE(LCPLL_CTL, val);
8942 POSTING_READ(LCPLL_CTL);
8944 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
8945 DRM_ERROR("LCPLL still locked\n");
8947 val = hsw_read_dcomp(dev_priv);
8948 val |= D_COMP_COMP_DISABLE;
8949 hsw_write_dcomp(dev_priv, val);
8952 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
8954 DRM_ERROR("D_COMP RCOMP still in progress\n");
8956 if (allow_power_down) {
8957 val = I915_READ(LCPLL_CTL);
8958 val |= LCPLL_POWER_DOWN_ALLOW;
8959 I915_WRITE(LCPLL_CTL, val);
8960 POSTING_READ(LCPLL_CTL);
8965 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
8968 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
8972 val = I915_READ(LCPLL_CTL);
8974 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
8975 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
8979 * Make sure we're not on PC8 state before disabling PC8, otherwise
8980 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
8982 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
8984 if (val & LCPLL_POWER_DOWN_ALLOW) {
8985 val &= ~LCPLL_POWER_DOWN_ALLOW;
8986 I915_WRITE(LCPLL_CTL, val);
8987 POSTING_READ(LCPLL_CTL);
8990 val = hsw_read_dcomp(dev_priv);
8991 val |= D_COMP_COMP_FORCE;
8992 val &= ~D_COMP_COMP_DISABLE;
8993 hsw_write_dcomp(dev_priv, val);
8995 val = I915_READ(LCPLL_CTL);
8996 val &= ~LCPLL_PLL_DISABLE;
8997 I915_WRITE(LCPLL_CTL, val);
8999 if (intel_wait_for_register(dev_priv,
9000 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9002 DRM_ERROR("LCPLL not locked yet\n");
9004 if (val & LCPLL_CD_SOURCE_FCLK) {
9005 val = I915_READ(LCPLL_CTL);
9006 val &= ~LCPLL_CD_SOURCE_FCLK;
9007 I915_WRITE(LCPLL_CTL, val);
9009 if (wait_for_us((I915_READ(LCPLL_CTL) &
9010 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9011 DRM_ERROR("Switching back to LCPLL failed\n");
9014 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9016 intel_update_cdclk(dev_priv);
9017 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
9021 * Package states C8 and deeper are really deep PC states that can only be
9022 * reached when all the devices on the system allow it, so even if the graphics
9023 * device allows PC8+, it doesn't mean the system will actually get to these
9024 * states. Our driver only allows PC8+ when going into runtime PM.
9026 * The requirements for PC8+ are that all the outputs are disabled, the power
9027 * well is disabled and most interrupts are disabled, and these are also
9028 * requirements for runtime PM. When these conditions are met, we manually do
9029 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9030 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9033 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9034 * the state of some registers, so when we come back from PC8+ we need to
9035 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9036 * need to take care of the registers kept by RC6. Notice that this happens even
9037 * if we don't put the device in PCI D3 state (which is what currently happens
9038 * because of the runtime PM support).
9040 * For more, read "Display Sequences for Package C8" on the hardware
9043 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9047 DRM_DEBUG_KMS("Enabling package C8+\n");
9049 if (HAS_PCH_LPT_LP(dev_priv)) {
9050 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9051 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9052 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9055 lpt_disable_clkout_dp(dev_priv);
9056 hsw_disable_lcpll(dev_priv, true, true);
9059 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9063 DRM_DEBUG_KMS("Disabling package C8+\n");
9065 hsw_restore_lcpll(dev_priv);
9066 lpt_init_pch_refclk(dev_priv);
9068 if (HAS_PCH_LPT_LP(dev_priv)) {
9069 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9070 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9071 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9075 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9076 struct intel_crtc_state *crtc_state)
9078 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
9079 struct intel_encoder *encoder =
9080 intel_ddi_get_crtc_new_encoder(crtc_state);
9082 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9083 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
9084 pipe_name(crtc->pipe));
9092 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9094 struct intel_crtc_state *pipe_config)
9096 enum intel_dpll_id id;
9099 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9100 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9102 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9105 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9108 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9110 struct intel_crtc_state *pipe_config)
9112 enum intel_dpll_id id;
9116 id = DPLL_ID_SKL_DPLL0;
9119 id = DPLL_ID_SKL_DPLL1;
9122 id = DPLL_ID_SKL_DPLL2;
9125 DRM_ERROR("Incorrect port type\n");
9129 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9132 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9134 struct intel_crtc_state *pipe_config)
9136 enum intel_dpll_id id;
9139 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9140 id = temp >> (port * 3 + 1);
9142 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9145 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9148 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9150 struct intel_crtc_state *pipe_config)
9152 enum intel_dpll_id id;
9153 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9155 switch (ddi_pll_sel) {
9156 case PORT_CLK_SEL_WRPLL1:
9157 id = DPLL_ID_WRPLL1;
9159 case PORT_CLK_SEL_WRPLL2:
9160 id = DPLL_ID_WRPLL2;
9162 case PORT_CLK_SEL_SPLL:
9165 case PORT_CLK_SEL_LCPLL_810:
9166 id = DPLL_ID_LCPLL_810;
9168 case PORT_CLK_SEL_LCPLL_1350:
9169 id = DPLL_ID_LCPLL_1350;
9171 case PORT_CLK_SEL_LCPLL_2700:
9172 id = DPLL_ID_LCPLL_2700;
9175 MISSING_CASE(ddi_pll_sel);
9177 case PORT_CLK_SEL_NONE:
9181 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9184 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9185 struct intel_crtc_state *pipe_config,
9186 u64 *power_domain_mask)
9188 struct drm_device *dev = crtc->base.dev;
9189 struct drm_i915_private *dev_priv = to_i915(dev);
9190 enum intel_display_power_domain power_domain;
9194 * The pipe->transcoder mapping is fixed with the exception of the eDP
9195 * transcoder handled below.
9197 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9200 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9201 * consistency and less surprising code; it's in always on power).
9203 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9204 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9205 enum pipe trans_edp_pipe;
9206 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9208 WARN(1, "unknown pipe linked to edp transcoder\n");
9209 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9210 case TRANS_DDI_EDP_INPUT_A_ON:
9211 trans_edp_pipe = PIPE_A;
9213 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9214 trans_edp_pipe = PIPE_B;
9216 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9217 trans_edp_pipe = PIPE_C;
9221 if (trans_edp_pipe == crtc->pipe)
9222 pipe_config->cpu_transcoder = TRANSCODER_EDP;
9225 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9226 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9228 *power_domain_mask |= BIT_ULL(power_domain);
9230 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9232 return tmp & PIPECONF_ENABLE;
9235 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9236 struct intel_crtc_state *pipe_config,
9237 u64 *power_domain_mask)
9239 struct drm_device *dev = crtc->base.dev;
9240 struct drm_i915_private *dev_priv = to_i915(dev);
9241 enum intel_display_power_domain power_domain;
9243 enum transcoder cpu_transcoder;
9246 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9248 cpu_transcoder = TRANSCODER_DSI_A;
9250 cpu_transcoder = TRANSCODER_DSI_C;
9252 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9253 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9255 *power_domain_mask |= BIT_ULL(power_domain);
9258 * The PLL needs to be enabled with a valid divider
9259 * configuration, otherwise accessing DSI registers will hang
9260 * the machine. See BSpec North Display Engine
9261 * registers/MIPI[BXT]. We can break out here early, since we
9262 * need the same DSI PLL to be enabled for both DSI ports.
9264 if (!intel_dsi_pll_is_enabled(dev_priv))
9267 /* XXX: this works for video mode only */
9268 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9269 if (!(tmp & DPI_ENABLE))
9272 tmp = I915_READ(MIPI_CTRL(port));
9273 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9276 pipe_config->cpu_transcoder = cpu_transcoder;
9280 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9283 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9284 struct intel_crtc_state *pipe_config)
9286 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9287 struct intel_shared_dpll *pll;
9291 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9293 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9295 if (IS_CANNONLAKE(dev_priv))
9296 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9297 else if (IS_GEN9_BC(dev_priv))
9298 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9299 else if (IS_GEN9_LP(dev_priv))
9300 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9302 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9304 pll = pipe_config->shared_dpll;
9306 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9307 &pipe_config->dpll_hw_state));
9311 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9312 * DDI E. So just check whether this pipe is wired to DDI E and whether
9313 * the PCH transcoder is on.
9315 if (INTEL_GEN(dev_priv) < 9 &&
9316 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9317 pipe_config->has_pch_encoder = true;
9319 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9320 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9321 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9323 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9327 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9328 struct intel_crtc_state *pipe_config)
9330 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9331 enum intel_display_power_domain power_domain;
9332 u64 power_domain_mask;
9335 intel_crtc_init_scalers(crtc, pipe_config);
9337 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9338 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9340 power_domain_mask = BIT_ULL(power_domain);
9342 pipe_config->shared_dpll = NULL;
9344 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9346 if (IS_GEN9_LP(dev_priv) &&
9347 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9355 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9356 haswell_get_ddi_port_state(crtc, pipe_config);
9357 intel_get_pipe_timings(crtc, pipe_config);
9360 intel_get_pipe_src_size(crtc, pipe_config);
9362 pipe_config->gamma_mode =
9363 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9365 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
9366 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
9367 bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV;
9369 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
9370 bool blend_mode_420 = tmp &
9371 PIPEMISC_YUV420_MODE_FULL_BLEND;
9373 pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE;
9374 if (pipe_config->ycbcr420 != clrspace_yuv ||
9375 pipe_config->ycbcr420 != blend_mode_420)
9376 DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp);
9377 } else if (clrspace_yuv) {
9378 DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
9382 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9383 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9384 power_domain_mask |= BIT_ULL(power_domain);
9385 if (INTEL_GEN(dev_priv) >= 9)
9386 skylake_get_pfit_config(crtc, pipe_config);
9388 ironlake_get_pfit_config(crtc, pipe_config);
9391 if (hsw_crtc_supports_ips(crtc)) {
9392 if (IS_HASWELL(dev_priv))
9393 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9396 * We cannot readout IPS state on broadwell, set to
9397 * true so we can set it to a defined state on first
9400 pipe_config->ips_enabled = true;
9404 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9405 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9406 pipe_config->pixel_multiplier =
9407 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9409 pipe_config->pixel_multiplier = 1;
9413 for_each_power_domain(power_domain, power_domain_mask)
9414 intel_display_power_put(dev_priv, power_domain);
9419 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9421 struct drm_i915_private *dev_priv =
9422 to_i915(plane_state->base.plane->dev);
9423 const struct drm_framebuffer *fb = plane_state->base.fb;
9424 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9427 if (INTEL_INFO(dev_priv)->cursor_needs_physical)
9428 base = obj->phys_handle->busaddr;
9430 base = intel_plane_ggtt_offset(plane_state);
9432 base += plane_state->main.offset;
9434 /* ILK+ do this automagically */
9435 if (HAS_GMCH_DISPLAY(dev_priv) &&
9436 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9437 base += (plane_state->base.crtc_h *
9438 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9443 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9445 int x = plane_state->base.crtc_x;
9446 int y = plane_state->base.crtc_y;
9450 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9453 pos |= x << CURSOR_X_SHIFT;
9456 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9459 pos |= y << CURSOR_Y_SHIFT;
9464 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9466 const struct drm_mode_config *config =
9467 &plane_state->base.plane->dev->mode_config;
9468 int width = plane_state->base.crtc_w;
9469 int height = plane_state->base.crtc_h;
9471 return width > 0 && width <= config->cursor_width &&
9472 height > 0 && height <= config->cursor_height;
9475 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9476 struct intel_plane_state *plane_state)
9478 const struct drm_framebuffer *fb = plane_state->base.fb;
9483 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9485 DRM_PLANE_HELPER_NO_SCALING,
9486 DRM_PLANE_HELPER_NO_SCALING,
9494 if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9495 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9499 src_x = plane_state->base.src_x >> 16;
9500 src_y = plane_state->base.src_y >> 16;
9502 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9503 offset = intel_compute_tile_offset(&src_x, &src_y, plane_state, 0);
9505 if (src_x != 0 || src_y != 0) {
9506 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9510 plane_state->main.offset = offset;
9515 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9516 const struct intel_plane_state *plane_state)
9518 const struct drm_framebuffer *fb = plane_state->base.fb;
9520 return CURSOR_ENABLE |
9521 CURSOR_GAMMA_ENABLE |
9522 CURSOR_FORMAT_ARGB |
9523 CURSOR_STRIDE(fb->pitches[0]);
9526 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9528 int width = plane_state->base.crtc_w;
9531 * 845g/865g are only limited by the width of their cursors,
9532 * the height is arbitrary up to the precision of the register.
9534 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
9537 static int i845_check_cursor(struct intel_plane *plane,
9538 struct intel_crtc_state *crtc_state,
9539 struct intel_plane_state *plane_state)
9541 const struct drm_framebuffer *fb = plane_state->base.fb;
9544 ret = intel_check_cursor(crtc_state, plane_state);
9548 /* if we want to turn off the cursor ignore width and height */
9552 /* Check for which cursor types we support */
9553 if (!i845_cursor_size_ok(plane_state)) {
9554 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9555 plane_state->base.crtc_w,
9556 plane_state->base.crtc_h);
9560 switch (fb->pitches[0]) {
9567 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9572 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9577 static void i845_update_cursor(struct intel_plane *plane,
9578 const struct intel_crtc_state *crtc_state,
9579 const struct intel_plane_state *plane_state)
9581 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9582 u32 cntl = 0, base = 0, pos = 0, size = 0;
9583 unsigned long irqflags;
9585 if (plane_state && plane_state->base.visible) {
9586 unsigned int width = plane_state->base.crtc_w;
9587 unsigned int height = plane_state->base.crtc_h;
9589 cntl = plane_state->ctl;
9590 size = (height << 12) | width;
9592 base = intel_cursor_base(plane_state);
9593 pos = intel_cursor_position(plane_state);
9596 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9598 /* On these chipsets we can only modify the base/size/stride
9599 * whilst the cursor is disabled.
9601 if (plane->cursor.base != base ||
9602 plane->cursor.size != size ||
9603 plane->cursor.cntl != cntl) {
9604 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
9605 I915_WRITE_FW(CURBASE(PIPE_A), base);
9606 I915_WRITE_FW(CURSIZE, size);
9607 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9608 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
9610 plane->cursor.base = base;
9611 plane->cursor.size = size;
9612 plane->cursor.cntl = cntl;
9614 I915_WRITE_FW(CURPOS(PIPE_A), pos);
9617 POSTING_READ_FW(CURCNTR(PIPE_A));
9619 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9622 static void i845_disable_cursor(struct intel_plane *plane,
9623 struct intel_crtc *crtc)
9625 i845_update_cursor(plane, NULL, NULL);
9628 static bool i845_cursor_get_hw_state(struct intel_plane *plane)
9630 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9631 enum intel_display_power_domain power_domain;
9634 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9635 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9638 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9640 intel_display_power_put(dev_priv, power_domain);
9645 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9646 const struct intel_plane_state *plane_state)
9648 struct drm_i915_private *dev_priv =
9649 to_i915(plane_state->base.plane->dev);
9650 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
9653 cntl = MCURSOR_GAMMA_ENABLE;
9655 if (HAS_DDI(dev_priv))
9656 cntl |= CURSOR_PIPE_CSC_ENABLE;
9658 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9659 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
9661 switch (plane_state->base.crtc_w) {
9663 cntl |= CURSOR_MODE_64_ARGB_AX;
9666 cntl |= CURSOR_MODE_128_ARGB_AX;
9669 cntl |= CURSOR_MODE_256_ARGB_AX;
9672 MISSING_CASE(plane_state->base.crtc_w);
9676 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
9677 cntl |= CURSOR_ROTATE_180;
9682 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
9684 struct drm_i915_private *dev_priv =
9685 to_i915(plane_state->base.plane->dev);
9686 int width = plane_state->base.crtc_w;
9687 int height = plane_state->base.crtc_h;
9689 if (!intel_cursor_size_ok(plane_state))
9692 /* Cursor width is limited to a few power-of-two sizes */
9703 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
9704 * height from 8 lines up to the cursor width, when the
9705 * cursor is not rotated. Everything else requires square
9708 if (HAS_CUR_FBC(dev_priv) &&
9709 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
9710 if (height < 8 || height > width)
9713 if (height != width)
9720 static int i9xx_check_cursor(struct intel_plane *plane,
9721 struct intel_crtc_state *crtc_state,
9722 struct intel_plane_state *plane_state)
9724 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9725 const struct drm_framebuffer *fb = plane_state->base.fb;
9726 enum pipe pipe = plane->pipe;
9729 ret = intel_check_cursor(crtc_state, plane_state);
9733 /* if we want to turn off the cursor ignore width and height */
9737 /* Check for which cursor types we support */
9738 if (!i9xx_cursor_size_ok(plane_state)) {
9739 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9740 plane_state->base.crtc_w,
9741 plane_state->base.crtc_h);
9745 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
9746 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
9747 fb->pitches[0], plane_state->base.crtc_w);
9752 * There's something wrong with the cursor on CHV pipe C.
9753 * If it straddles the left edge of the screen then
9754 * moving it away from the edge or disabling it often
9755 * results in a pipe underrun, and often that can lead to
9756 * dead pipe (constant underrun reported, and it scans
9757 * out just a solid color). To recover from that, the
9758 * display power well must be turned off and on again.
9759 * Refuse the put the cursor into that compromised position.
9761 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
9762 plane_state->base.visible && plane_state->base.crtc_x < 0) {
9763 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
9767 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
9772 static void i9xx_update_cursor(struct intel_plane *plane,
9773 const struct intel_crtc_state *crtc_state,
9774 const struct intel_plane_state *plane_state)
9776 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9777 enum pipe pipe = plane->pipe;
9778 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
9779 unsigned long irqflags;
9781 if (plane_state && plane_state->base.visible) {
9782 cntl = plane_state->ctl;
9784 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
9785 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
9787 base = intel_cursor_base(plane_state);
9788 pos = intel_cursor_position(plane_state);
9791 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9794 * On some platforms writing CURCNTR first will also
9795 * cause CURPOS to be armed by the CURBASE write.
9796 * Without the CURCNTR write the CURPOS write would
9797 * arm itself. Thus we always start the full update
9798 * with a CURCNTR write.
9800 * On other platforms CURPOS always requires the
9801 * CURBASE write to arm the update. Additonally
9802 * a write to any of the cursor register will cancel
9803 * an already armed cursor update. Thus leaving out
9804 * the CURBASE write after CURPOS could lead to a
9805 * cursor that doesn't appear to move, or even change
9806 * shape. Thus we always write CURBASE.
9808 * CURCNTR and CUR_FBC_CTL are always
9809 * armed by the CURBASE write only.
9811 if (plane->cursor.base != base ||
9812 plane->cursor.size != fbc_ctl ||
9813 plane->cursor.cntl != cntl) {
9814 I915_WRITE_FW(CURCNTR(pipe), cntl);
9815 if (HAS_CUR_FBC(dev_priv))
9816 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
9817 I915_WRITE_FW(CURPOS(pipe), pos);
9818 I915_WRITE_FW(CURBASE(pipe), base);
9820 plane->cursor.base = base;
9821 plane->cursor.size = fbc_ctl;
9822 plane->cursor.cntl = cntl;
9824 I915_WRITE_FW(CURPOS(pipe), pos);
9825 I915_WRITE_FW(CURBASE(pipe), base);
9828 POSTING_READ_FW(CURBASE(pipe));
9830 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9833 static void i9xx_disable_cursor(struct intel_plane *plane,
9834 struct intel_crtc *crtc)
9836 i9xx_update_cursor(plane, NULL, NULL);
9839 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane)
9841 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9842 enum intel_display_power_domain power_domain;
9843 enum pipe pipe = plane->pipe;
9847 * Not 100% correct for planes that can move between pipes,
9848 * but that's only the case for gen2-3 which don't have any
9849 * display power wells.
9851 power_domain = POWER_DOMAIN_PIPE(pipe);
9852 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9855 ret = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
9857 intel_display_power_put(dev_priv, power_domain);
9862 /* VESA 640x480x72Hz mode to set on the pipe */
9863 static const struct drm_display_mode load_detect_mode = {
9864 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
9865 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
9868 struct drm_framebuffer *
9869 intel_framebuffer_create(struct drm_i915_gem_object *obj,
9870 struct drm_mode_fb_cmd2 *mode_cmd)
9872 struct intel_framebuffer *intel_fb;
9875 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9877 return ERR_PTR(-ENOMEM);
9879 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
9883 return &intel_fb->base;
9887 return ERR_PTR(ret);
9890 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
9891 struct drm_crtc *crtc)
9893 struct drm_plane *plane;
9894 struct drm_plane_state *plane_state;
9897 ret = drm_atomic_add_affected_planes(state, crtc);
9901 for_each_new_plane_in_state(state, plane, plane_state, i) {
9902 if (plane_state->crtc != crtc)
9905 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
9909 drm_atomic_set_fb_for_plane(plane_state, NULL);
9915 int intel_get_load_detect_pipe(struct drm_connector *connector,
9916 const struct drm_display_mode *mode,
9917 struct intel_load_detect_pipe *old,
9918 struct drm_modeset_acquire_ctx *ctx)
9920 struct intel_crtc *intel_crtc;
9921 struct intel_encoder *intel_encoder =
9922 intel_attached_encoder(connector);
9923 struct drm_crtc *possible_crtc;
9924 struct drm_encoder *encoder = &intel_encoder->base;
9925 struct drm_crtc *crtc = NULL;
9926 struct drm_device *dev = encoder->dev;
9927 struct drm_i915_private *dev_priv = to_i915(dev);
9928 struct drm_mode_config *config = &dev->mode_config;
9929 struct drm_atomic_state *state = NULL, *restore_state = NULL;
9930 struct drm_connector_state *connector_state;
9931 struct intel_crtc_state *crtc_state;
9934 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9935 connector->base.id, connector->name,
9936 encoder->base.id, encoder->name);
9938 old->restore_state = NULL;
9940 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
9943 * Algorithm gets a little messy:
9945 * - if the connector already has an assigned crtc, use it (but make
9946 * sure it's on first)
9948 * - try to find the first unused crtc that can drive this connector,
9949 * and use that if we find one
9952 /* See if we already have a CRTC for this connector */
9953 if (connector->state->crtc) {
9954 crtc = connector->state->crtc;
9956 ret = drm_modeset_lock(&crtc->mutex, ctx);
9960 /* Make sure the crtc and connector are running */
9964 /* Find an unused one (if possible) */
9965 for_each_crtc(dev, possible_crtc) {
9967 if (!(encoder->possible_crtcs & (1 << i)))
9970 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
9974 if (possible_crtc->state->enable) {
9975 drm_modeset_unlock(&possible_crtc->mutex);
9979 crtc = possible_crtc;
9984 * If we didn't find an unused CRTC, don't use any.
9987 DRM_DEBUG_KMS("no pipe available for load-detect\n");
9993 intel_crtc = to_intel_crtc(crtc);
9995 state = drm_atomic_state_alloc(dev);
9996 restore_state = drm_atomic_state_alloc(dev);
9997 if (!state || !restore_state) {
10002 state->acquire_ctx = ctx;
10003 restore_state->acquire_ctx = ctx;
10005 connector_state = drm_atomic_get_connector_state(state, connector);
10006 if (IS_ERR(connector_state)) {
10007 ret = PTR_ERR(connector_state);
10011 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10015 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10016 if (IS_ERR(crtc_state)) {
10017 ret = PTR_ERR(crtc_state);
10021 crtc_state->base.active = crtc_state->base.enable = true;
10024 mode = &load_detect_mode;
10026 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
10030 ret = intel_modeset_disable_planes(state, crtc);
10034 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10036 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
10038 ret = drm_atomic_add_affected_planes(restore_state, crtc);
10040 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10044 ret = drm_atomic_commit(state);
10046 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10050 old->restore_state = restore_state;
10051 drm_atomic_state_put(state);
10053 /* let the connector get through one full cycle before testing */
10054 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
10059 drm_atomic_state_put(state);
10062 if (restore_state) {
10063 drm_atomic_state_put(restore_state);
10064 restore_state = NULL;
10067 if (ret == -EDEADLK)
10073 void intel_release_load_detect_pipe(struct drm_connector *connector,
10074 struct intel_load_detect_pipe *old,
10075 struct drm_modeset_acquire_ctx *ctx)
10077 struct intel_encoder *intel_encoder =
10078 intel_attached_encoder(connector);
10079 struct drm_encoder *encoder = &intel_encoder->base;
10080 struct drm_atomic_state *state = old->restore_state;
10083 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10084 connector->base.id, connector->name,
10085 encoder->base.id, encoder->name);
10090 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10092 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10093 drm_atomic_state_put(state);
10096 static int i9xx_pll_refclk(struct drm_device *dev,
10097 const struct intel_crtc_state *pipe_config)
10099 struct drm_i915_private *dev_priv = to_i915(dev);
10100 u32 dpll = pipe_config->dpll_hw_state.dpll;
10102 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10103 return dev_priv->vbt.lvds_ssc_freq;
10104 else if (HAS_PCH_SPLIT(dev_priv))
10106 else if (!IS_GEN2(dev_priv))
10112 /* Returns the clock of the currently programmed mode of the given pipe. */
10113 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10114 struct intel_crtc_state *pipe_config)
10116 struct drm_device *dev = crtc->base.dev;
10117 struct drm_i915_private *dev_priv = to_i915(dev);
10118 int pipe = pipe_config->cpu_transcoder;
10119 u32 dpll = pipe_config->dpll_hw_state.dpll;
10123 int refclk = i9xx_pll_refclk(dev, pipe_config);
10125 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10126 fp = pipe_config->dpll_hw_state.fp0;
10128 fp = pipe_config->dpll_hw_state.fp1;
10130 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10131 if (IS_PINEVIEW(dev_priv)) {
10132 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10133 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10135 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10136 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10139 if (!IS_GEN2(dev_priv)) {
10140 if (IS_PINEVIEW(dev_priv))
10141 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10142 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10144 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10145 DPLL_FPA01_P1_POST_DIV_SHIFT);
10147 switch (dpll & DPLL_MODE_MASK) {
10148 case DPLLB_MODE_DAC_SERIAL:
10149 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10152 case DPLLB_MODE_LVDS:
10153 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10157 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10158 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10162 if (IS_PINEVIEW(dev_priv))
10163 port_clock = pnv_calc_dpll_params(refclk, &clock);
10165 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10167 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10168 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10171 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10172 DPLL_FPA01_P1_POST_DIV_SHIFT);
10174 if (lvds & LVDS_CLKB_POWER_UP)
10179 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10182 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10183 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10185 if (dpll & PLL_P2_DIVIDE_BY_4)
10191 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10195 * This value includes pixel_multiplier. We will use
10196 * port_clock to compute adjusted_mode.crtc_clock in the
10197 * encoder's get_config() function.
10199 pipe_config->port_clock = port_clock;
10202 int intel_dotclock_calculate(int link_freq,
10203 const struct intel_link_m_n *m_n)
10206 * The calculation for the data clock is:
10207 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10208 * But we want to avoid losing precison if possible, so:
10209 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10211 * and the link clock is simpler:
10212 * link_clock = (m * link_clock) / n
10218 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10221 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10222 struct intel_crtc_state *pipe_config)
10224 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10226 /* read out port_clock from the DPLL */
10227 i9xx_crtc_clock_get(crtc, pipe_config);
10230 * In case there is an active pipe without active ports,
10231 * we may need some idea for the dotclock anyway.
10232 * Calculate one based on the FDI configuration.
10234 pipe_config->base.adjusted_mode.crtc_clock =
10235 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10236 &pipe_config->fdi_m_n);
10239 /* Returns the currently programmed mode of the given encoder. */
10240 struct drm_display_mode *
10241 intel_encoder_current_mode(struct intel_encoder *encoder)
10243 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10244 struct intel_crtc_state *crtc_state;
10245 struct drm_display_mode *mode;
10246 struct intel_crtc *crtc;
10249 if (!encoder->get_hw_state(encoder, &pipe))
10252 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10254 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10258 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10264 crtc_state->base.crtc = &crtc->base;
10266 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10272 encoder->get_config(encoder, crtc_state);
10274 intel_mode_from_pipe_config(mode, crtc_state);
10281 static void intel_crtc_destroy(struct drm_crtc *crtc)
10283 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10285 drm_crtc_cleanup(crtc);
10290 * intel_wm_need_update - Check whether watermarks need updating
10291 * @plane: drm plane
10292 * @state: new plane state
10294 * Check current plane state versus the new one to determine whether
10295 * watermarks need to be recalculated.
10297 * Returns true or false.
10299 static bool intel_wm_need_update(struct drm_plane *plane,
10300 struct drm_plane_state *state)
10302 struct intel_plane_state *new = to_intel_plane_state(state);
10303 struct intel_plane_state *cur = to_intel_plane_state(plane->state);
10305 /* Update watermarks on tiling or size changes. */
10306 if (new->base.visible != cur->base.visible)
10309 if (!cur->base.fb || !new->base.fb)
10312 if (cur->base.fb->modifier != new->base.fb->modifier ||
10313 cur->base.rotation != new->base.rotation ||
10314 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10315 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10316 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10317 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10323 static bool needs_scaling(const struct intel_plane_state *state)
10325 int src_w = drm_rect_width(&state->base.src) >> 16;
10326 int src_h = drm_rect_height(&state->base.src) >> 16;
10327 int dst_w = drm_rect_width(&state->base.dst);
10328 int dst_h = drm_rect_height(&state->base.dst);
10330 return (src_w != dst_w || src_h != dst_h);
10333 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10334 struct drm_crtc_state *crtc_state,
10335 const struct intel_plane_state *old_plane_state,
10336 struct drm_plane_state *plane_state)
10338 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10339 struct drm_crtc *crtc = crtc_state->crtc;
10340 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10341 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10342 struct drm_device *dev = crtc->dev;
10343 struct drm_i915_private *dev_priv = to_i915(dev);
10344 bool mode_changed = needs_modeset(crtc_state);
10345 bool was_crtc_enabled = old_crtc_state->base.active;
10346 bool is_crtc_enabled = crtc_state->active;
10347 bool turn_off, turn_on, visible, was_visible;
10348 struct drm_framebuffer *fb = plane_state->fb;
10351 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10352 ret = skl_update_scaler_plane(
10353 to_intel_crtc_state(crtc_state),
10354 to_intel_plane_state(plane_state));
10359 was_visible = old_plane_state->base.visible;
10360 visible = plane_state->visible;
10362 if (!was_crtc_enabled && WARN_ON(was_visible))
10363 was_visible = false;
10366 * Visibility is calculated as if the crtc was on, but
10367 * after scaler setup everything depends on it being off
10368 * when the crtc isn't active.
10370 * FIXME this is wrong for watermarks. Watermarks should also
10371 * be computed as if the pipe would be active. Perhaps move
10372 * per-plane wm computation to the .check_plane() hook, and
10373 * only combine the results from all planes in the current place?
10375 if (!is_crtc_enabled) {
10376 plane_state->visible = visible = false;
10377 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10380 if (!was_visible && !visible)
10383 if (fb != old_plane_state->base.fb)
10384 pipe_config->fb_changed = true;
10386 turn_off = was_visible && (!visible || mode_changed);
10387 turn_on = visible && (!was_visible || mode_changed);
10389 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
10390 intel_crtc->base.base.id, intel_crtc->base.name,
10391 plane->base.base.id, plane->base.name,
10392 fb ? fb->base.id : -1);
10394 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
10395 plane->base.base.id, plane->base.name,
10396 was_visible, visible,
10397 turn_off, turn_on, mode_changed);
10400 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10401 pipe_config->update_wm_pre = true;
10403 /* must disable cxsr around plane enable/disable */
10404 if (plane->id != PLANE_CURSOR)
10405 pipe_config->disable_cxsr = true;
10406 } else if (turn_off) {
10407 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10408 pipe_config->update_wm_post = true;
10410 /* must disable cxsr around plane enable/disable */
10411 if (plane->id != PLANE_CURSOR)
10412 pipe_config->disable_cxsr = true;
10413 } else if (intel_wm_need_update(&plane->base, plane_state)) {
10414 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
10415 /* FIXME bollocks */
10416 pipe_config->update_wm_pre = true;
10417 pipe_config->update_wm_post = true;
10421 if (visible || was_visible)
10422 pipe_config->fb_bits |= plane->frontbuffer_bit;
10425 * WaCxSRDisabledForSpriteScaling:ivb
10427 * cstate->update_wm was already set above, so this flag will
10428 * take effect when we commit and program watermarks.
10430 if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) &&
10431 needs_scaling(to_intel_plane_state(plane_state)) &&
10432 !needs_scaling(old_plane_state))
10433 pipe_config->disable_lp_wm = true;
10438 static bool encoders_cloneable(const struct intel_encoder *a,
10439 const struct intel_encoder *b)
10441 /* masks could be asymmetric, so check both ways */
10442 return a == b || (a->cloneable & (1 << b->type) &&
10443 b->cloneable & (1 << a->type));
10446 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10447 struct intel_crtc *crtc,
10448 struct intel_encoder *encoder)
10450 struct intel_encoder *source_encoder;
10451 struct drm_connector *connector;
10452 struct drm_connector_state *connector_state;
10455 for_each_new_connector_in_state(state, connector, connector_state, i) {
10456 if (connector_state->crtc != &crtc->base)
10460 to_intel_encoder(connector_state->best_encoder);
10461 if (!encoders_cloneable(encoder, source_encoder))
10468 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10469 struct drm_crtc_state *crtc_state)
10471 struct drm_device *dev = crtc->dev;
10472 struct drm_i915_private *dev_priv = to_i915(dev);
10473 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10474 struct intel_crtc_state *pipe_config =
10475 to_intel_crtc_state(crtc_state);
10476 struct drm_atomic_state *state = crtc_state->state;
10478 bool mode_changed = needs_modeset(crtc_state);
10480 if (mode_changed && !crtc_state->active)
10481 pipe_config->update_wm_post = true;
10483 if (mode_changed && crtc_state->enable &&
10484 dev_priv->display.crtc_compute_clock &&
10485 !WARN_ON(pipe_config->shared_dpll)) {
10486 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10492 if (crtc_state->color_mgmt_changed) {
10493 ret = intel_color_check(crtc, crtc_state);
10498 * Changing color management on Intel hardware is
10499 * handled as part of planes update.
10501 crtc_state->planes_changed = true;
10505 if (dev_priv->display.compute_pipe_wm) {
10506 ret = dev_priv->display.compute_pipe_wm(pipe_config);
10508 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
10513 if (dev_priv->display.compute_intermediate_wm &&
10514 !to_intel_atomic_state(state)->skip_intermediate_wm) {
10515 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10519 * Calculate 'intermediate' watermarks that satisfy both the
10520 * old state and the new state. We can program these
10523 ret = dev_priv->display.compute_intermediate_wm(dev,
10527 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
10530 } else if (dev_priv->display.compute_intermediate_wm) {
10531 if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
10532 pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
10535 if (INTEL_GEN(dev_priv) >= 9) {
10537 ret = skl_update_scaler_crtc(pipe_config);
10540 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
10543 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
10547 if (HAS_IPS(dev_priv))
10548 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
10553 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
10554 .atomic_begin = intel_begin_crtc_commit,
10555 .atomic_flush = intel_finish_crtc_commit,
10556 .atomic_check = intel_crtc_atomic_check,
10559 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10561 struct intel_connector *connector;
10562 struct drm_connector_list_iter conn_iter;
10564 drm_connector_list_iter_begin(dev, &conn_iter);
10565 for_each_intel_connector_iter(connector, &conn_iter) {
10566 if (connector->base.state->crtc)
10567 drm_connector_unreference(&connector->base);
10569 if (connector->base.encoder) {
10570 connector->base.state->best_encoder =
10571 connector->base.encoder;
10572 connector->base.state->crtc =
10573 connector->base.encoder->crtc;
10575 drm_connector_reference(&connector->base);
10577 connector->base.state->best_encoder = NULL;
10578 connector->base.state->crtc = NULL;
10581 drm_connector_list_iter_end(&conn_iter);
10585 connected_sink_compute_bpp(struct intel_connector *connector,
10586 struct intel_crtc_state *pipe_config)
10588 const struct drm_display_info *info = &connector->base.display_info;
10589 int bpp = pipe_config->pipe_bpp;
10591 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
10592 connector->base.base.id,
10593 connector->base.name);
10595 /* Don't use an invalid EDID bpc value */
10596 if (info->bpc != 0 && info->bpc * 3 < bpp) {
10597 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
10598 bpp, info->bpc * 3);
10599 pipe_config->pipe_bpp = info->bpc * 3;
10602 /* Clamp bpp to 8 on screens without EDID 1.4 */
10603 if (info->bpc == 0 && bpp > 24) {
10604 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
10606 pipe_config->pipe_bpp = 24;
10611 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
10612 struct intel_crtc_state *pipe_config)
10614 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10615 struct drm_atomic_state *state;
10616 struct drm_connector *connector;
10617 struct drm_connector_state *connector_state;
10620 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10621 IS_CHERRYVIEW(dev_priv)))
10623 else if (INTEL_GEN(dev_priv) >= 5)
10629 pipe_config->pipe_bpp = bpp;
10631 state = pipe_config->base.state;
10633 /* Clamp display bpp to EDID value */
10634 for_each_new_connector_in_state(state, connector, connector_state, i) {
10635 if (connector_state->crtc != &crtc->base)
10638 connected_sink_compute_bpp(to_intel_connector(connector),
10645 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
10647 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10648 "type: 0x%x flags: 0x%x\n",
10650 mode->crtc_hdisplay, mode->crtc_hsync_start,
10651 mode->crtc_hsync_end, mode->crtc_htotal,
10652 mode->crtc_vdisplay, mode->crtc_vsync_start,
10653 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
10657 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
10658 unsigned int lane_count, struct intel_link_m_n *m_n)
10660 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10662 m_n->gmch_m, m_n->gmch_n,
10663 m_n->link_m, m_n->link_n, m_n->tu);
10666 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
10668 static const char * const output_type_str[] = {
10669 OUTPUT_TYPE(UNUSED),
10670 OUTPUT_TYPE(ANALOG),
10674 OUTPUT_TYPE(TVOUT),
10680 OUTPUT_TYPE(DP_MST),
10685 static void snprintf_output_types(char *buf, size_t len,
10686 unsigned int output_types)
10693 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
10696 if ((output_types & BIT(i)) == 0)
10699 r = snprintf(str, len, "%s%s",
10700 str != buf ? "," : "", output_type_str[i]);
10706 output_types &= ~BIT(i);
10709 WARN_ON_ONCE(output_types != 0);
10712 static void intel_dump_pipe_config(struct intel_crtc *crtc,
10713 struct intel_crtc_state *pipe_config,
10714 const char *context)
10716 struct drm_device *dev = crtc->base.dev;
10717 struct drm_i915_private *dev_priv = to_i915(dev);
10718 struct drm_plane *plane;
10719 struct intel_plane *intel_plane;
10720 struct intel_plane_state *state;
10721 struct drm_framebuffer *fb;
10724 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
10725 crtc->base.base.id, crtc->base.name, context);
10727 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
10728 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
10729 buf, pipe_config->output_types);
10731 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10732 transcoder_name(pipe_config->cpu_transcoder),
10733 pipe_config->pipe_bpp, pipe_config->dither);
10735 if (pipe_config->has_pch_encoder)
10736 intel_dump_m_n_config(pipe_config, "fdi",
10737 pipe_config->fdi_lanes,
10738 &pipe_config->fdi_m_n);
10740 if (pipe_config->ycbcr420)
10741 DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
10743 if (intel_crtc_has_dp_encoder(pipe_config)) {
10744 intel_dump_m_n_config(pipe_config, "dp m_n",
10745 pipe_config->lane_count, &pipe_config->dp_m_n);
10746 if (pipe_config->has_drrs)
10747 intel_dump_m_n_config(pipe_config, "dp m2_n2",
10748 pipe_config->lane_count,
10749 &pipe_config->dp_m2_n2);
10752 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
10753 pipe_config->has_audio, pipe_config->has_infoframe);
10755 DRM_DEBUG_KMS("requested mode:\n");
10756 drm_mode_debug_printmodeline(&pipe_config->base.mode);
10757 DRM_DEBUG_KMS("adjusted mode:\n");
10758 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
10759 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
10760 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10761 pipe_config->port_clock,
10762 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
10763 pipe_config->pixel_rate);
10765 if (INTEL_GEN(dev_priv) >= 9)
10766 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10768 pipe_config->scaler_state.scaler_users,
10769 pipe_config->scaler_state.scaler_id);
10771 if (HAS_GMCH_DISPLAY(dev_priv))
10772 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10773 pipe_config->gmch_pfit.control,
10774 pipe_config->gmch_pfit.pgm_ratios,
10775 pipe_config->gmch_pfit.lvds_border_bits);
10777 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10778 pipe_config->pch_pfit.pos,
10779 pipe_config->pch_pfit.size,
10780 enableddisabled(pipe_config->pch_pfit.enabled));
10782 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
10783 pipe_config->ips_enabled, pipe_config->double_wide);
10785 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
10787 DRM_DEBUG_KMS("planes on this crtc\n");
10788 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
10789 struct drm_format_name_buf format_name;
10790 intel_plane = to_intel_plane(plane);
10791 if (intel_plane->pipe != crtc->pipe)
10794 state = to_intel_plane_state(plane->state);
10795 fb = state->base.fb;
10797 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
10798 plane->base.id, plane->name, state->scaler_id);
10802 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
10803 plane->base.id, plane->name,
10804 fb->base.id, fb->width, fb->height,
10805 drm_get_format_name(fb->format->format, &format_name));
10806 if (INTEL_GEN(dev_priv) >= 9)
10807 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
10809 state->base.src.x1 >> 16,
10810 state->base.src.y1 >> 16,
10811 drm_rect_width(&state->base.src) >> 16,
10812 drm_rect_height(&state->base.src) >> 16,
10813 state->base.dst.x1, state->base.dst.y1,
10814 drm_rect_width(&state->base.dst),
10815 drm_rect_height(&state->base.dst));
10819 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
10821 struct drm_device *dev = state->dev;
10822 struct drm_connector *connector;
10823 struct drm_connector_list_iter conn_iter;
10824 unsigned int used_ports = 0;
10825 unsigned int used_mst_ports = 0;
10829 * Walk the connector list instead of the encoder
10830 * list to detect the problem on ddi platforms
10831 * where there's just one encoder per digital port.
10833 drm_connector_list_iter_begin(dev, &conn_iter);
10834 drm_for_each_connector_iter(connector, &conn_iter) {
10835 struct drm_connector_state *connector_state;
10836 struct intel_encoder *encoder;
10838 connector_state = drm_atomic_get_new_connector_state(state, connector);
10839 if (!connector_state)
10840 connector_state = connector->state;
10842 if (!connector_state->best_encoder)
10845 encoder = to_intel_encoder(connector_state->best_encoder);
10847 WARN_ON(!connector_state->crtc);
10849 switch (encoder->type) {
10850 unsigned int port_mask;
10851 case INTEL_OUTPUT_DDI:
10852 if (WARN_ON(!HAS_DDI(to_i915(dev))))
10854 case INTEL_OUTPUT_DP:
10855 case INTEL_OUTPUT_HDMI:
10856 case INTEL_OUTPUT_EDP:
10857 port_mask = 1 << encoder->port;
10859 /* the same port mustn't appear more than once */
10860 if (used_ports & port_mask)
10863 used_ports |= port_mask;
10865 case INTEL_OUTPUT_DP_MST:
10867 1 << encoder->port;
10873 drm_connector_list_iter_end(&conn_iter);
10875 /* can't mix MST and SST/HDMI on the same port */
10876 if (used_ports & used_mst_ports)
10883 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
10885 struct drm_i915_private *dev_priv =
10886 to_i915(crtc_state->base.crtc->dev);
10887 struct intel_crtc_scaler_state scaler_state;
10888 struct intel_dpll_hw_state dpll_hw_state;
10889 struct intel_shared_dpll *shared_dpll;
10890 struct intel_crtc_wm_state wm_state;
10891 bool force_thru, ips_force_disable;
10893 /* FIXME: before the switch to atomic started, a new pipe_config was
10894 * kzalloc'd. Code that depends on any field being zero should be
10895 * fixed, so that the crtc_state can be safely duplicated. For now,
10896 * only fields that are know to not cause problems are preserved. */
10898 scaler_state = crtc_state->scaler_state;
10899 shared_dpll = crtc_state->shared_dpll;
10900 dpll_hw_state = crtc_state->dpll_hw_state;
10901 force_thru = crtc_state->pch_pfit.force_thru;
10902 ips_force_disable = crtc_state->ips_force_disable;
10903 if (IS_G4X(dev_priv) ||
10904 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10905 wm_state = crtc_state->wm;
10907 /* Keep base drm_crtc_state intact, only clear our extended struct */
10908 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
10909 memset(&crtc_state->base + 1, 0,
10910 sizeof(*crtc_state) - sizeof(crtc_state->base));
10912 crtc_state->scaler_state = scaler_state;
10913 crtc_state->shared_dpll = shared_dpll;
10914 crtc_state->dpll_hw_state = dpll_hw_state;
10915 crtc_state->pch_pfit.force_thru = force_thru;
10916 crtc_state->ips_force_disable = ips_force_disable;
10917 if (IS_G4X(dev_priv) ||
10918 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10919 crtc_state->wm = wm_state;
10923 intel_modeset_pipe_config(struct drm_crtc *crtc,
10924 struct intel_crtc_state *pipe_config)
10926 struct drm_atomic_state *state = pipe_config->base.state;
10927 struct intel_encoder *encoder;
10928 struct drm_connector *connector;
10929 struct drm_connector_state *connector_state;
10930 int base_bpp, ret = -EINVAL;
10934 clear_intel_crtc_state(pipe_config);
10936 pipe_config->cpu_transcoder =
10937 (enum transcoder) to_intel_crtc(crtc)->pipe;
10940 * Sanitize sync polarity flags based on requested ones. If neither
10941 * positive or negative polarity is requested, treat this as meaning
10942 * negative polarity.
10944 if (!(pipe_config->base.adjusted_mode.flags &
10945 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
10946 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
10948 if (!(pipe_config->base.adjusted_mode.flags &
10949 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
10950 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
10952 base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
10958 * Determine the real pipe dimensions. Note that stereo modes can
10959 * increase the actual pipe size due to the frame doubling and
10960 * insertion of additional space for blanks between the frame. This
10961 * is stored in the crtc timings. We use the requested mode to do this
10962 * computation to clearly distinguish it from the adjusted mode, which
10963 * can be changed by the connectors in the below retry loop.
10965 drm_mode_get_hv_timing(&pipe_config->base.mode,
10966 &pipe_config->pipe_src_w,
10967 &pipe_config->pipe_src_h);
10969 for_each_new_connector_in_state(state, connector, connector_state, i) {
10970 if (connector_state->crtc != crtc)
10973 encoder = to_intel_encoder(connector_state->best_encoder);
10975 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
10976 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10981 * Determine output_types before calling the .compute_config()
10982 * hooks so that the hooks can use this information safely.
10984 if (encoder->compute_output_type)
10985 pipe_config->output_types |=
10986 BIT(encoder->compute_output_type(encoder, pipe_config,
10989 pipe_config->output_types |= BIT(encoder->type);
10993 /* Ensure the port clock defaults are reset when retrying. */
10994 pipe_config->port_clock = 0;
10995 pipe_config->pixel_multiplier = 1;
10997 /* Fill in default crtc timings, allow encoders to overwrite them. */
10998 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
10999 CRTC_STEREO_DOUBLE);
11001 /* Pass our mode to the connectors and the CRTC to give them a chance to
11002 * adjust it according to limitations or connector properties, and also
11003 * a chance to reject the mode entirely.
11005 for_each_new_connector_in_state(state, connector, connector_state, i) {
11006 if (connector_state->crtc != crtc)
11009 encoder = to_intel_encoder(connector_state->best_encoder);
11011 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
11012 DRM_DEBUG_KMS("Encoder config failure\n");
11017 /* Set default port clock if not overwritten by the encoder. Needs to be
11018 * done afterwards in case the encoder adjusts the mode. */
11019 if (!pipe_config->port_clock)
11020 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
11021 * pipe_config->pixel_multiplier;
11023 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
11025 DRM_DEBUG_KMS("CRTC fixup failed\n");
11029 if (ret == RETRY) {
11030 if (WARN(!retry, "loop in pipe configuration computation\n")) {
11035 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11037 goto encoder_retry;
11040 /* Dithering seems to not pass-through bits correctly when it should, so
11041 * only enable it on 6bpc panels and when its not a compliance
11042 * test requesting 6bpc video pattern.
11044 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11045 !pipe_config->dither_force_disable;
11046 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11047 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
11053 static bool intel_fuzzy_clock_check(int clock1, int clock2)
11057 if (clock1 == clock2)
11060 if (!clock1 || !clock2)
11063 diff = abs(clock1 - clock2);
11065 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11072 intel_compare_m_n(unsigned int m, unsigned int n,
11073 unsigned int m2, unsigned int n2,
11076 if (m == m2 && n == n2)
11079 if (exact || !m || !n || !m2 || !n2)
11082 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11089 } else if (n < n2) {
11099 return intel_fuzzy_clock_check(m, m2);
11103 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11104 struct intel_link_m_n *m2_n2,
11107 if (m_n->tu == m2_n2->tu &&
11108 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11109 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11110 intel_compare_m_n(m_n->link_m, m_n->link_n,
11111 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11121 static void __printf(3, 4)
11122 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11124 struct va_format vaf;
11127 va_start(args, format);
11132 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11134 drm_err("mismatch in %s %pV", name, &vaf);
11140 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11141 struct intel_crtc_state *current_config,
11142 struct intel_crtc_state *pipe_config,
11146 bool fixup_inherited = adjust &&
11147 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11148 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11150 #define PIPE_CONF_CHECK_X(name) do { \
11151 if (current_config->name != pipe_config->name) { \
11152 pipe_config_err(adjust, __stringify(name), \
11153 "(expected 0x%08x, found 0x%08x)\n", \
11154 current_config->name, \
11155 pipe_config->name); \
11160 #define PIPE_CONF_CHECK_I(name) do { \
11161 if (current_config->name != pipe_config->name) { \
11162 pipe_config_err(adjust, __stringify(name), \
11163 "(expected %i, found %i)\n", \
11164 current_config->name, \
11165 pipe_config->name); \
11170 #define PIPE_CONF_CHECK_BOOL(name) do { \
11171 if (current_config->name != pipe_config->name) { \
11172 pipe_config_err(adjust, __stringify(name), \
11173 "(expected %s, found %s)\n", \
11174 yesno(current_config->name), \
11175 yesno(pipe_config->name)); \
11181 * Checks state where we only read out the enabling, but not the entire
11182 * state itself (like full infoframes or ELD for audio). These states
11183 * require a full modeset on bootup to fix up.
11185 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11186 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11187 PIPE_CONF_CHECK_BOOL(name); \
11189 pipe_config_err(adjust, __stringify(name), \
11190 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11191 yesno(current_config->name), \
11192 yesno(pipe_config->name)); \
11197 #define PIPE_CONF_CHECK_P(name) do { \
11198 if (current_config->name != pipe_config->name) { \
11199 pipe_config_err(adjust, __stringify(name), \
11200 "(expected %p, found %p)\n", \
11201 current_config->name, \
11202 pipe_config->name); \
11207 #define PIPE_CONF_CHECK_M_N(name) do { \
11208 if (!intel_compare_link_m_n(¤t_config->name, \
11209 &pipe_config->name,\
11211 pipe_config_err(adjust, __stringify(name), \
11212 "(expected tu %i gmch %i/%i link %i/%i, " \
11213 "found tu %i, gmch %i/%i link %i/%i)\n", \
11214 current_config->name.tu, \
11215 current_config->name.gmch_m, \
11216 current_config->name.gmch_n, \
11217 current_config->name.link_m, \
11218 current_config->name.link_n, \
11219 pipe_config->name.tu, \
11220 pipe_config->name.gmch_m, \
11221 pipe_config->name.gmch_n, \
11222 pipe_config->name.link_m, \
11223 pipe_config->name.link_n); \
11228 /* This is required for BDW+ where there is only one set of registers for
11229 * switching between high and low RR.
11230 * This macro can be used whenever a comparison has to be made between one
11231 * hw state and multiple sw state variables.
11233 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
11234 if (!intel_compare_link_m_n(¤t_config->name, \
11235 &pipe_config->name, adjust) && \
11236 !intel_compare_link_m_n(¤t_config->alt_name, \
11237 &pipe_config->name, adjust)) { \
11238 pipe_config_err(adjust, __stringify(name), \
11239 "(expected tu %i gmch %i/%i link %i/%i, " \
11240 "or tu %i gmch %i/%i link %i/%i, " \
11241 "found tu %i, gmch %i/%i link %i/%i)\n", \
11242 current_config->name.tu, \
11243 current_config->name.gmch_m, \
11244 current_config->name.gmch_n, \
11245 current_config->name.link_m, \
11246 current_config->name.link_n, \
11247 current_config->alt_name.tu, \
11248 current_config->alt_name.gmch_m, \
11249 current_config->alt_name.gmch_n, \
11250 current_config->alt_name.link_m, \
11251 current_config->alt_name.link_n, \
11252 pipe_config->name.tu, \
11253 pipe_config->name.gmch_m, \
11254 pipe_config->name.gmch_n, \
11255 pipe_config->name.link_m, \
11256 pipe_config->name.link_n); \
11261 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
11262 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11263 pipe_config_err(adjust, __stringify(name), \
11264 "(%x) (expected %i, found %i)\n", \
11266 current_config->name & (mask), \
11267 pipe_config->name & (mask)); \
11272 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
11273 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11274 pipe_config_err(adjust, __stringify(name), \
11275 "(expected %i, found %i)\n", \
11276 current_config->name, \
11277 pipe_config->name); \
11282 #define PIPE_CONF_QUIRK(quirk) \
11283 ((current_config->quirks | pipe_config->quirks) & (quirk))
11285 PIPE_CONF_CHECK_I(cpu_transcoder);
11287 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11288 PIPE_CONF_CHECK_I(fdi_lanes);
11289 PIPE_CONF_CHECK_M_N(fdi_m_n);
11291 PIPE_CONF_CHECK_I(lane_count);
11292 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11294 if (INTEL_GEN(dev_priv) < 8) {
11295 PIPE_CONF_CHECK_M_N(dp_m_n);
11297 if (current_config->has_drrs)
11298 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11300 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11302 PIPE_CONF_CHECK_X(output_types);
11304 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11305 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11306 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11307 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11308 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11309 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
11311 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11312 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11313 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11314 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11315 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11316 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
11318 PIPE_CONF_CHECK_I(pixel_multiplier);
11319 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11320 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11321 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11322 PIPE_CONF_CHECK_BOOL(limited_color_range);
11324 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11325 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11326 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
11327 PIPE_CONF_CHECK_BOOL(ycbcr420);
11329 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11331 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11332 DRM_MODE_FLAG_INTERLACE);
11334 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11335 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11336 DRM_MODE_FLAG_PHSYNC);
11337 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11338 DRM_MODE_FLAG_NHSYNC);
11339 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11340 DRM_MODE_FLAG_PVSYNC);
11341 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
11342 DRM_MODE_FLAG_NVSYNC);
11345 PIPE_CONF_CHECK_X(gmch_pfit.control);
11346 /* pfit ratios are autocomputed by the hw on gen4+ */
11347 if (INTEL_GEN(dev_priv) < 4)
11348 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11349 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11352 PIPE_CONF_CHECK_I(pipe_src_w);
11353 PIPE_CONF_CHECK_I(pipe_src_h);
11355 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11356 if (current_config->pch_pfit.enabled) {
11357 PIPE_CONF_CHECK_X(pch_pfit.pos);
11358 PIPE_CONF_CHECK_X(pch_pfit.size);
11361 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11362 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11365 PIPE_CONF_CHECK_BOOL(double_wide);
11367 PIPE_CONF_CHECK_P(shared_dpll);
11368 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11369 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11370 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11371 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11372 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11373 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11374 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11375 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11376 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11377 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11378 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11379 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11380 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11381 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11382 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11383 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11384 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11385 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11386 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11387 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11388 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11390 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11391 PIPE_CONF_CHECK_X(dsi_pll.div);
11393 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11394 PIPE_CONF_CHECK_I(pipe_bpp);
11396 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
11397 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11399 PIPE_CONF_CHECK_I(min_voltage_level);
11401 #undef PIPE_CONF_CHECK_X
11402 #undef PIPE_CONF_CHECK_I
11403 #undef PIPE_CONF_CHECK_BOOL
11404 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11405 #undef PIPE_CONF_CHECK_P
11406 #undef PIPE_CONF_CHECK_FLAGS
11407 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11408 #undef PIPE_CONF_QUIRK
11413 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11414 const struct intel_crtc_state *pipe_config)
11416 if (pipe_config->has_pch_encoder) {
11417 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11418 &pipe_config->fdi_m_n);
11419 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11422 * FDI already provided one idea for the dotclock.
11423 * Yell if the encoder disagrees.
11425 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11426 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11427 fdi_dotclock, dotclock);
11431 static void verify_wm_state(struct drm_crtc *crtc,
11432 struct drm_crtc_state *new_state)
11434 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11435 struct skl_ddb_allocation hw_ddb, *sw_ddb;
11436 struct skl_pipe_wm hw_wm, *sw_wm;
11437 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11438 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11439 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11440 const enum pipe pipe = intel_crtc->pipe;
11441 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11443 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
11446 skl_pipe_wm_get_hw_state(crtc, &hw_wm);
11447 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
11449 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11450 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11452 if (INTEL_GEN(dev_priv) >= 11)
11453 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11454 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11455 sw_ddb->enabled_slices,
11456 hw_ddb.enabled_slices);
11458 for_each_universal_plane(dev_priv, pipe, plane) {
11459 hw_plane_wm = &hw_wm.planes[plane];
11460 sw_plane_wm = &sw_wm->planes[plane];
11463 for (level = 0; level <= max_level; level++) {
11464 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11465 &sw_plane_wm->wm[level]))
11468 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",
11469 pipe_name(pipe), plane + 1, level,
11470 sw_plane_wm->wm[level].plane_en,
11471 sw_plane_wm->wm[level].plane_res_b,
11472 sw_plane_wm->wm[level].plane_res_l,
11473 hw_plane_wm->wm[level].plane_en,
11474 hw_plane_wm->wm[level].plane_res_b,
11475 hw_plane_wm->wm[level].plane_res_l);
11478 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11479 &sw_plane_wm->trans_wm)) {
11480 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",
11481 pipe_name(pipe), plane + 1,
11482 sw_plane_wm->trans_wm.plane_en,
11483 sw_plane_wm->trans_wm.plane_res_b,
11484 sw_plane_wm->trans_wm.plane_res_l,
11485 hw_plane_wm->trans_wm.plane_en,
11486 hw_plane_wm->trans_wm.plane_res_b,
11487 hw_plane_wm->trans_wm.plane_res_l);
11491 hw_ddb_entry = &hw_ddb.plane[pipe][plane];
11492 sw_ddb_entry = &sw_ddb->plane[pipe][plane];
11494 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11495 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11496 pipe_name(pipe), plane + 1,
11497 sw_ddb_entry->start, sw_ddb_entry->end,
11498 hw_ddb_entry->start, hw_ddb_entry->end);
11504 * If the cursor plane isn't active, we may not have updated it's ddb
11505 * allocation. In that case since the ddb allocation will be updated
11506 * once the plane becomes visible, we can skip this check
11509 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
11510 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
11513 for (level = 0; level <= max_level; level++) {
11514 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11515 &sw_plane_wm->wm[level]))
11518 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",
11519 pipe_name(pipe), level,
11520 sw_plane_wm->wm[level].plane_en,
11521 sw_plane_wm->wm[level].plane_res_b,
11522 sw_plane_wm->wm[level].plane_res_l,
11523 hw_plane_wm->wm[level].plane_en,
11524 hw_plane_wm->wm[level].plane_res_b,
11525 hw_plane_wm->wm[level].plane_res_l);
11528 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11529 &sw_plane_wm->trans_wm)) {
11530 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11532 sw_plane_wm->trans_wm.plane_en,
11533 sw_plane_wm->trans_wm.plane_res_b,
11534 sw_plane_wm->trans_wm.plane_res_l,
11535 hw_plane_wm->trans_wm.plane_en,
11536 hw_plane_wm->trans_wm.plane_res_b,
11537 hw_plane_wm->trans_wm.plane_res_l);
11541 hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
11542 sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
11544 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11545 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11547 sw_ddb_entry->start, sw_ddb_entry->end,
11548 hw_ddb_entry->start, hw_ddb_entry->end);
11554 verify_connector_state(struct drm_device *dev,
11555 struct drm_atomic_state *state,
11556 struct drm_crtc *crtc)
11558 struct drm_connector *connector;
11559 struct drm_connector_state *new_conn_state;
11562 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
11563 struct drm_encoder *encoder = connector->encoder;
11564 struct drm_crtc_state *crtc_state = NULL;
11566 if (new_conn_state->crtc != crtc)
11570 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
11572 intel_connector_verify_state(crtc_state, new_conn_state);
11574 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
11575 "connector's atomic encoder doesn't match legacy encoder\n");
11580 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
11582 struct intel_encoder *encoder;
11583 struct drm_connector *connector;
11584 struct drm_connector_state *old_conn_state, *new_conn_state;
11587 for_each_intel_encoder(dev, encoder) {
11588 bool enabled = false, found = false;
11591 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
11592 encoder->base.base.id,
11593 encoder->base.name);
11595 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
11596 new_conn_state, i) {
11597 if (old_conn_state->best_encoder == &encoder->base)
11600 if (new_conn_state->best_encoder != &encoder->base)
11602 found = enabled = true;
11604 I915_STATE_WARN(new_conn_state->crtc !=
11605 encoder->base.crtc,
11606 "connector's crtc doesn't match encoder crtc\n");
11612 I915_STATE_WARN(!!encoder->base.crtc != enabled,
11613 "encoder's enabled state mismatch "
11614 "(expected %i, found %i)\n",
11615 !!encoder->base.crtc, enabled);
11617 if (!encoder->base.crtc) {
11620 active = encoder->get_hw_state(encoder, &pipe);
11621 I915_STATE_WARN(active,
11622 "encoder detached but still enabled on pipe %c.\n",
11629 verify_crtc_state(struct drm_crtc *crtc,
11630 struct drm_crtc_state *old_crtc_state,
11631 struct drm_crtc_state *new_crtc_state)
11633 struct drm_device *dev = crtc->dev;
11634 struct drm_i915_private *dev_priv = to_i915(dev);
11635 struct intel_encoder *encoder;
11636 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11637 struct intel_crtc_state *pipe_config, *sw_config;
11638 struct drm_atomic_state *old_state;
11641 old_state = old_crtc_state->state;
11642 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
11643 pipe_config = to_intel_crtc_state(old_crtc_state);
11644 memset(pipe_config, 0, sizeof(*pipe_config));
11645 pipe_config->base.crtc = crtc;
11646 pipe_config->base.state = old_state;
11648 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
11650 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
11652 /* we keep both pipes enabled on 830 */
11653 if (IS_I830(dev_priv))
11654 active = new_crtc_state->active;
11656 I915_STATE_WARN(new_crtc_state->active != active,
11657 "crtc active state doesn't match with hw state "
11658 "(expected %i, found %i)\n", new_crtc_state->active, active);
11660 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
11661 "transitional active state does not match atomic hw state "
11662 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
11664 for_each_encoder_on_crtc(dev, crtc, encoder) {
11667 active = encoder->get_hw_state(encoder, &pipe);
11668 I915_STATE_WARN(active != new_crtc_state->active,
11669 "[ENCODER:%i] active %i with crtc active %i\n",
11670 encoder->base.base.id, active, new_crtc_state->active);
11672 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
11673 "Encoder connected to wrong pipe %c\n",
11677 encoder->get_config(encoder, pipe_config);
11680 intel_crtc_compute_pixel_rate(pipe_config);
11682 if (!new_crtc_state->active)
11685 intel_pipe_config_sanity_check(dev_priv, pipe_config);
11687 sw_config = to_intel_crtc_state(new_crtc_state);
11688 if (!intel_pipe_config_compare(dev_priv, sw_config,
11689 pipe_config, false)) {
11690 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11691 intel_dump_pipe_config(intel_crtc, pipe_config,
11693 intel_dump_pipe_config(intel_crtc, sw_config,
11699 intel_verify_planes(struct intel_atomic_state *state)
11701 struct intel_plane *plane;
11702 const struct intel_plane_state *plane_state;
11705 for_each_new_intel_plane_in_state(state, plane,
11707 assert_plane(plane, plane_state->base.visible);
11711 verify_single_dpll_state(struct drm_i915_private *dev_priv,
11712 struct intel_shared_dpll *pll,
11713 struct drm_crtc *crtc,
11714 struct drm_crtc_state *new_state)
11716 struct intel_dpll_hw_state dpll_hw_state;
11717 unsigned crtc_mask;
11720 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
11722 DRM_DEBUG_KMS("%s\n", pll->info->name);
11724 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
11726 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
11727 I915_STATE_WARN(!pll->on && pll->active_mask,
11728 "pll in active use but not on in sw tracking\n");
11729 I915_STATE_WARN(pll->on && !pll->active_mask,
11730 "pll is on but not used by any active crtc\n");
11731 I915_STATE_WARN(pll->on != active,
11732 "pll on state mismatch (expected %i, found %i)\n",
11737 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
11738 "more active pll users than references: %x vs %x\n",
11739 pll->active_mask, pll->state.crtc_mask);
11744 crtc_mask = 1 << drm_crtc_index(crtc);
11746 if (new_state->active)
11747 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
11748 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11749 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11751 I915_STATE_WARN(pll->active_mask & crtc_mask,
11752 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11753 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
11755 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
11756 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11757 crtc_mask, pll->state.crtc_mask);
11759 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
11761 sizeof(dpll_hw_state)),
11762 "pll hw state mismatch\n");
11766 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
11767 struct drm_crtc_state *old_crtc_state,
11768 struct drm_crtc_state *new_crtc_state)
11770 struct drm_i915_private *dev_priv = to_i915(dev);
11771 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
11772 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
11774 if (new_state->shared_dpll)
11775 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
11777 if (old_state->shared_dpll &&
11778 old_state->shared_dpll != new_state->shared_dpll) {
11779 unsigned crtc_mask = 1 << drm_crtc_index(crtc);
11780 struct intel_shared_dpll *pll = old_state->shared_dpll;
11782 I915_STATE_WARN(pll->active_mask & crtc_mask,
11783 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11784 pipe_name(drm_crtc_index(crtc)));
11785 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
11786 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11787 pipe_name(drm_crtc_index(crtc)));
11792 intel_modeset_verify_crtc(struct drm_crtc *crtc,
11793 struct drm_atomic_state *state,
11794 struct drm_crtc_state *old_state,
11795 struct drm_crtc_state *new_state)
11797 if (!needs_modeset(new_state) &&
11798 !to_intel_crtc_state(new_state)->update_pipe)
11801 verify_wm_state(crtc, new_state);
11802 verify_connector_state(crtc->dev, state, crtc);
11803 verify_crtc_state(crtc, old_state, new_state);
11804 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
11808 verify_disabled_dpll_state(struct drm_device *dev)
11810 struct drm_i915_private *dev_priv = to_i915(dev);
11813 for (i = 0; i < dev_priv->num_shared_dpll; i++)
11814 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
11818 intel_modeset_verify_disabled(struct drm_device *dev,
11819 struct drm_atomic_state *state)
11821 verify_encoder_state(dev, state);
11822 verify_connector_state(dev, state, NULL);
11823 verify_disabled_dpll_state(dev);
11826 static void update_scanline_offset(struct intel_crtc *crtc)
11828 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11831 * The scanline counter increments at the leading edge of hsync.
11833 * On most platforms it starts counting from vtotal-1 on the
11834 * first active line. That means the scanline counter value is
11835 * always one less than what we would expect. Ie. just after
11836 * start of vblank, which also occurs at start of hsync (on the
11837 * last active line), the scanline counter will read vblank_start-1.
11839 * On gen2 the scanline counter starts counting from 1 instead
11840 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11841 * to keep the value positive), instead of adding one.
11843 * On HSW+ the behaviour of the scanline counter depends on the output
11844 * type. For DP ports it behaves like most other platforms, but on HDMI
11845 * there's an extra 1 line difference. So we need to add two instead of
11846 * one to the value.
11848 * On VLV/CHV DSI the scanline counter would appear to increment
11849 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11850 * that means we can't tell whether we're in vblank or not while
11851 * we're on that particular line. We must still set scanline_offset
11852 * to 1 so that the vblank timestamps come out correct when we query
11853 * the scanline counter from within the vblank interrupt handler.
11854 * However if queried just before the start of vblank we'll get an
11855 * answer that's slightly in the future.
11857 if (IS_GEN2(dev_priv)) {
11858 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
11861 vtotal = adjusted_mode->crtc_vtotal;
11862 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
11865 crtc->scanline_offset = vtotal - 1;
11866 } else if (HAS_DDI(dev_priv) &&
11867 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) {
11868 crtc->scanline_offset = 2;
11870 crtc->scanline_offset = 1;
11873 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
11875 struct drm_device *dev = state->dev;
11876 struct drm_i915_private *dev_priv = to_i915(dev);
11877 struct drm_crtc *crtc;
11878 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
11881 if (!dev_priv->display.crtc_compute_clock)
11884 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
11885 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11886 struct intel_shared_dpll *old_dpll =
11887 to_intel_crtc_state(old_crtc_state)->shared_dpll;
11889 if (!needs_modeset(new_crtc_state))
11892 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
11897 intel_release_shared_dpll(old_dpll, intel_crtc, state);
11902 * This implements the workaround described in the "notes" section of the mode
11903 * set sequence documentation. When going from no pipes or single pipe to
11904 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11905 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11907 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
11909 struct drm_crtc_state *crtc_state;
11910 struct intel_crtc *intel_crtc;
11911 struct drm_crtc *crtc;
11912 struct intel_crtc_state *first_crtc_state = NULL;
11913 struct intel_crtc_state *other_crtc_state = NULL;
11914 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
11917 /* look at all crtc's that are going to be enabled in during modeset */
11918 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
11919 intel_crtc = to_intel_crtc(crtc);
11921 if (!crtc_state->active || !needs_modeset(crtc_state))
11924 if (first_crtc_state) {
11925 other_crtc_state = to_intel_crtc_state(crtc_state);
11928 first_crtc_state = to_intel_crtc_state(crtc_state);
11929 first_pipe = intel_crtc->pipe;
11933 /* No workaround needed? */
11934 if (!first_crtc_state)
11937 /* w/a possibly needed, check how many crtc's are already enabled. */
11938 for_each_intel_crtc(state->dev, intel_crtc) {
11939 struct intel_crtc_state *pipe_config;
11941 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
11942 if (IS_ERR(pipe_config))
11943 return PTR_ERR(pipe_config);
11945 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
11947 if (!pipe_config->base.active ||
11948 needs_modeset(&pipe_config->base))
11951 /* 2 or more enabled crtcs means no need for w/a */
11952 if (enabled_pipe != INVALID_PIPE)
11955 enabled_pipe = intel_crtc->pipe;
11958 if (enabled_pipe != INVALID_PIPE)
11959 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
11960 else if (other_crtc_state)
11961 other_crtc_state->hsw_workaround_pipe = first_pipe;
11966 static int intel_lock_all_pipes(struct drm_atomic_state *state)
11968 struct drm_crtc *crtc;
11970 /* Add all pipes to the state */
11971 for_each_crtc(state->dev, crtc) {
11972 struct drm_crtc_state *crtc_state;
11974 crtc_state = drm_atomic_get_crtc_state(state, crtc);
11975 if (IS_ERR(crtc_state))
11976 return PTR_ERR(crtc_state);
11982 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
11984 struct drm_crtc *crtc;
11987 * Add all pipes to the state, and force
11988 * a modeset on all the active ones.
11990 for_each_crtc(state->dev, crtc) {
11991 struct drm_crtc_state *crtc_state;
11994 crtc_state = drm_atomic_get_crtc_state(state, crtc);
11995 if (IS_ERR(crtc_state))
11996 return PTR_ERR(crtc_state);
11998 if (!crtc_state->active || needs_modeset(crtc_state))
12001 crtc_state->mode_changed = true;
12003 ret = drm_atomic_add_affected_connectors(state, crtc);
12007 ret = drm_atomic_add_affected_planes(state, crtc);
12015 static int intel_modeset_checks(struct drm_atomic_state *state)
12017 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12018 struct drm_i915_private *dev_priv = to_i915(state->dev);
12019 struct drm_crtc *crtc;
12020 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12023 if (!check_digital_port_conflicts(state)) {
12024 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12028 intel_state->modeset = true;
12029 intel_state->active_crtcs = dev_priv->active_crtcs;
12030 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12031 intel_state->cdclk.actual = dev_priv->cdclk.actual;
12033 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12034 if (new_crtc_state->active)
12035 intel_state->active_crtcs |= 1 << i;
12037 intel_state->active_crtcs &= ~(1 << i);
12039 if (old_crtc_state->active != new_crtc_state->active)
12040 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
12044 * See if the config requires any additional preparation, e.g.
12045 * to adjust global state with pipes off. We need to do this
12046 * here so we can get the modeset_pipe updated config for the new
12047 * mode set on this crtc. For other crtcs we need to use the
12048 * adjusted_mode bits in the crtc directly.
12050 if (dev_priv->display.modeset_calc_cdclk) {
12051 ret = dev_priv->display.modeset_calc_cdclk(state);
12056 * Writes to dev_priv->cdclk.logical must protected by
12057 * holding all the crtc locks, even if we don't end up
12058 * touching the hardware
12060 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12061 &intel_state->cdclk.logical)) {
12062 ret = intel_lock_all_pipes(state);
12067 /* All pipes must be switched off while we change the cdclk. */
12068 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12069 &intel_state->cdclk.actual)) {
12070 ret = intel_modeset_all_pipes(state);
12075 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12076 intel_state->cdclk.logical.cdclk,
12077 intel_state->cdclk.actual.cdclk);
12078 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12079 intel_state->cdclk.logical.voltage_level,
12080 intel_state->cdclk.actual.voltage_level);
12082 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12085 intel_modeset_clear_plls(state);
12087 if (IS_HASWELL(dev_priv))
12088 return haswell_mode_set_planes_workaround(state);
12094 * Handle calculation of various watermark data at the end of the atomic check
12095 * phase. The code here should be run after the per-crtc and per-plane 'check'
12096 * handlers to ensure that all derived state has been updated.
12098 static int calc_watermark_data(struct drm_atomic_state *state)
12100 struct drm_device *dev = state->dev;
12101 struct drm_i915_private *dev_priv = to_i915(dev);
12103 /* Is there platform-specific watermark information to calculate? */
12104 if (dev_priv->display.compute_global_watermarks)
12105 return dev_priv->display.compute_global_watermarks(state);
12111 * intel_atomic_check - validate state object
12113 * @state: state to validate
12115 static int intel_atomic_check(struct drm_device *dev,
12116 struct drm_atomic_state *state)
12118 struct drm_i915_private *dev_priv = to_i915(dev);
12119 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12120 struct drm_crtc *crtc;
12121 struct drm_crtc_state *old_crtc_state, *crtc_state;
12123 bool any_ms = false;
12125 /* Catch I915_MODE_FLAG_INHERITED */
12126 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12128 if (crtc_state->mode.private_flags !=
12129 old_crtc_state->mode.private_flags)
12130 crtc_state->mode_changed = true;
12133 ret = drm_atomic_helper_check_modeset(dev, state);
12137 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12138 struct intel_crtc_state *pipe_config =
12139 to_intel_crtc_state(crtc_state);
12141 if (!needs_modeset(crtc_state))
12144 if (!crtc_state->enable) {
12149 ret = intel_modeset_pipe_config(crtc, pipe_config);
12151 intel_dump_pipe_config(to_intel_crtc(crtc),
12152 pipe_config, "[failed]");
12156 if (i915_modparams.fastboot &&
12157 intel_pipe_config_compare(dev_priv,
12158 to_intel_crtc_state(old_crtc_state),
12159 pipe_config, true)) {
12160 crtc_state->mode_changed = false;
12161 pipe_config->update_pipe = true;
12164 if (needs_modeset(crtc_state))
12167 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12168 needs_modeset(crtc_state) ?
12169 "[modeset]" : "[fastset]");
12173 ret = intel_modeset_checks(state);
12178 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12181 ret = drm_atomic_helper_check_planes(dev, state);
12185 intel_fbc_choose_crtc(dev_priv, intel_state);
12186 return calc_watermark_data(state);
12189 static int intel_atomic_prepare_commit(struct drm_device *dev,
12190 struct drm_atomic_state *state)
12192 return drm_atomic_helper_prepare_planes(dev, state);
12195 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12197 struct drm_device *dev = crtc->base.dev;
12199 if (!dev->max_vblank_count)
12200 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
12202 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12205 static void intel_update_crtc(struct drm_crtc *crtc,
12206 struct drm_atomic_state *state,
12207 struct drm_crtc_state *old_crtc_state,
12208 struct drm_crtc_state *new_crtc_state)
12210 struct drm_device *dev = crtc->dev;
12211 struct drm_i915_private *dev_priv = to_i915(dev);
12212 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12213 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12214 bool modeset = needs_modeset(new_crtc_state);
12215 struct intel_plane_state *new_plane_state =
12216 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12217 to_intel_plane(crtc->primary));
12220 update_scanline_offset(intel_crtc);
12221 dev_priv->display.crtc_enable(pipe_config, state);
12223 /* vblanks work again, re-enable pipe CRC. */
12224 intel_crtc_enable_pipe_crc(intel_crtc);
12226 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12230 if (new_plane_state)
12231 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
12233 drm_atomic_helper_commit_planes_on_crtc(old_crtc_state);
12236 static void intel_update_crtcs(struct drm_atomic_state *state)
12238 struct drm_crtc *crtc;
12239 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12242 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12243 if (!new_crtc_state->active)
12246 intel_update_crtc(crtc, state, old_crtc_state,
12251 static void skl_update_crtcs(struct drm_atomic_state *state)
12253 struct drm_i915_private *dev_priv = to_i915(state->dev);
12254 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12255 struct drm_crtc *crtc;
12256 struct intel_crtc *intel_crtc;
12257 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12258 struct intel_crtc_state *cstate;
12259 unsigned int updated = 0;
12263 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12264 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
12266 const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
12268 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
12269 /* ignore allocations for crtc's that have been turned off. */
12270 if (new_crtc_state->active)
12271 entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
12273 /* If 2nd DBuf slice required, enable it here */
12274 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12275 icl_dbuf_slices_update(dev_priv, required_slices);
12278 * Whenever the number of active pipes changes, we need to make sure we
12279 * update the pipes in the right order so that their ddb allocations
12280 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12281 * cause pipe underruns and other bad stuff.
12286 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12287 bool vbl_wait = false;
12288 unsigned int cmask = drm_crtc_mask(crtc);
12290 intel_crtc = to_intel_crtc(crtc);
12291 cstate = to_intel_crtc_state(new_crtc_state);
12292 pipe = intel_crtc->pipe;
12294 if (updated & cmask || !cstate->base.active)
12297 if (skl_ddb_allocation_overlaps(dev_priv,
12299 &cstate->wm.skl.ddb,
12304 entries[i] = &cstate->wm.skl.ddb;
12307 * If this is an already active pipe, it's DDB changed,
12308 * and this isn't the last pipe that needs updating
12309 * then we need to wait for a vblank to pass for the
12310 * new ddb allocation to take effect.
12312 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
12313 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
12314 !new_crtc_state->active_changed &&
12315 intel_state->wm_results.dirty_pipes != updated)
12318 intel_update_crtc(crtc, state, old_crtc_state,
12322 intel_wait_for_vblank(dev_priv, pipe);
12326 } while (progress);
12328 /* If 2nd DBuf slice is no more required disable it */
12329 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12330 icl_dbuf_slices_update(dev_priv, required_slices);
12333 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12335 struct intel_atomic_state *state, *next;
12336 struct llist_node *freed;
12338 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12339 llist_for_each_entry_safe(state, next, freed, freed)
12340 drm_atomic_state_put(&state->base);
12343 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12345 struct drm_i915_private *dev_priv =
12346 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12348 intel_atomic_helper_free_state(dev_priv);
12351 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12353 struct wait_queue_entry wait_fence, wait_reset;
12354 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12356 init_wait_entry(&wait_fence, 0);
12357 init_wait_entry(&wait_reset, 0);
12359 prepare_to_wait(&intel_state->commit_ready.wait,
12360 &wait_fence, TASK_UNINTERRUPTIBLE);
12361 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12362 &wait_reset, TASK_UNINTERRUPTIBLE);
12365 if (i915_sw_fence_done(&intel_state->commit_ready)
12366 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12371 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12372 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12375 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
12377 struct drm_device *dev = state->dev;
12378 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12379 struct drm_i915_private *dev_priv = to_i915(dev);
12380 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12381 struct drm_crtc *crtc;
12382 struct intel_crtc_state *intel_cstate;
12383 u64 put_domains[I915_MAX_PIPES] = {};
12386 intel_atomic_commit_fence_wait(intel_state);
12388 drm_atomic_helper_wait_for_dependencies(state);
12390 if (intel_state->modeset)
12391 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
12393 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12394 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12396 if (needs_modeset(new_crtc_state) ||
12397 to_intel_crtc_state(new_crtc_state)->update_pipe) {
12399 put_domains[to_intel_crtc(crtc)->pipe] =
12400 modeset_get_crtc_power_domains(crtc,
12401 to_intel_crtc_state(new_crtc_state));
12404 if (!needs_modeset(new_crtc_state))
12407 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12408 to_intel_crtc_state(new_crtc_state));
12410 if (old_crtc_state->active) {
12411 intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask);
12414 * We need to disable pipe CRC before disabling the pipe,
12415 * or we race against vblank off.
12417 intel_crtc_disable_pipe_crc(intel_crtc);
12419 dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state);
12420 intel_crtc->active = false;
12421 intel_fbc_disable(intel_crtc);
12422 intel_disable_shared_dpll(intel_crtc);
12425 * Underruns don't always raise
12426 * interrupts, so check manually.
12428 intel_check_cpu_fifo_underruns(dev_priv);
12429 intel_check_pch_fifo_underruns(dev_priv);
12431 if (!new_crtc_state->active) {
12433 * Make sure we don't call initial_watermarks
12434 * for ILK-style watermark updates.
12436 * No clue what this is supposed to achieve.
12438 if (INTEL_GEN(dev_priv) >= 9)
12439 dev_priv->display.initial_watermarks(intel_state,
12440 to_intel_crtc_state(new_crtc_state));
12445 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12446 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12447 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
12449 if (intel_state->modeset) {
12450 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
12452 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
12455 * SKL workaround: bspec recommends we disable the SAGV when we
12456 * have more then one pipe enabled
12458 if (!intel_can_enable_sagv(state))
12459 intel_disable_sagv(dev_priv);
12461 intel_modeset_verify_disabled(dev, state);
12464 /* Complete the events for pipes that have now been disabled */
12465 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12466 bool modeset = needs_modeset(new_crtc_state);
12468 /* Complete events for now disable pipes here. */
12469 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
12470 spin_lock_irq(&dev->event_lock);
12471 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
12472 spin_unlock_irq(&dev->event_lock);
12474 new_crtc_state->event = NULL;
12478 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
12479 dev_priv->display.update_crtcs(state);
12481 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
12482 * already, but still need the state for the delayed optimization. To
12484 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
12485 * - schedule that vblank worker _before_ calling hw_done
12486 * - at the start of commit_tail, cancel it _synchrously
12487 * - switch over to the vblank wait helper in the core after that since
12488 * we don't need out special handling any more.
12490 drm_atomic_helper_wait_for_flip_done(dev, state);
12493 * Now that the vblank has passed, we can go ahead and program the
12494 * optimal watermarks on platforms that need two-step watermark
12497 * TODO: Move this (and other cleanup) to an async worker eventually.
12499 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
12500 intel_cstate = to_intel_crtc_state(new_crtc_state);
12502 if (dev_priv->display.optimize_watermarks)
12503 dev_priv->display.optimize_watermarks(intel_state,
12507 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12508 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
12510 if (put_domains[i])
12511 modeset_put_power_domains(dev_priv, put_domains[i]);
12513 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
12516 if (intel_state->modeset)
12517 intel_verify_planes(intel_state);
12519 if (intel_state->modeset && intel_can_enable_sagv(state))
12520 intel_enable_sagv(dev_priv);
12522 drm_atomic_helper_commit_hw_done(state);
12524 if (intel_state->modeset) {
12525 /* As one of the primary mmio accessors, KMS has a high
12526 * likelihood of triggering bugs in unclaimed access. After we
12527 * finish modesetting, see if an error has been flagged, and if
12528 * so enable debugging for the next modeset - and hope we catch
12531 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
12532 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
12535 drm_atomic_helper_cleanup_planes(dev, state);
12537 drm_atomic_helper_commit_cleanup_done(state);
12539 drm_atomic_state_put(state);
12541 intel_atomic_helper_free_state(dev_priv);
12544 static void intel_atomic_commit_work(struct work_struct *work)
12546 struct drm_atomic_state *state =
12547 container_of(work, struct drm_atomic_state, commit_work);
12549 intel_atomic_commit_tail(state);
12552 static int __i915_sw_fence_call
12553 intel_atomic_commit_ready(struct i915_sw_fence *fence,
12554 enum i915_sw_fence_notify notify)
12556 struct intel_atomic_state *state =
12557 container_of(fence, struct intel_atomic_state, commit_ready);
12560 case FENCE_COMPLETE:
12561 /* we do blocking waits in the worker, nothing to do here */
12565 struct intel_atomic_helper *helper =
12566 &to_i915(state->base.dev)->atomic_helper;
12568 if (llist_add(&state->freed, &helper->free_list))
12569 schedule_work(&helper->free_work);
12574 return NOTIFY_DONE;
12577 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
12579 struct drm_plane_state *old_plane_state, *new_plane_state;
12580 struct drm_plane *plane;
12583 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
12584 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
12585 intel_fb_obj(new_plane_state->fb),
12586 to_intel_plane(plane)->frontbuffer_bit);
12590 * intel_atomic_commit - commit validated state object
12592 * @state: the top-level driver state object
12593 * @nonblock: nonblocking commit
12595 * This function commits a top-level state object that has been validated
12596 * with drm_atomic_helper_check().
12599 * Zero for success or -errno.
12601 static int intel_atomic_commit(struct drm_device *dev,
12602 struct drm_atomic_state *state,
12605 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12606 struct drm_i915_private *dev_priv = to_i915(dev);
12609 drm_atomic_state_get(state);
12610 i915_sw_fence_init(&intel_state->commit_ready,
12611 intel_atomic_commit_ready);
12614 * The intel_legacy_cursor_update() fast path takes care
12615 * of avoiding the vblank waits for simple cursor
12616 * movement and flips. For cursor on/off and size changes,
12617 * we want to perform the vblank waits so that watermark
12618 * updates happen during the correct frames. Gen9+ have
12619 * double buffered watermarks and so shouldn't need this.
12621 * Unset state->legacy_cursor_update before the call to
12622 * drm_atomic_helper_setup_commit() because otherwise
12623 * drm_atomic_helper_wait_for_flip_done() is a noop and
12624 * we get FIFO underruns because we didn't wait
12627 * FIXME doing watermarks and fb cleanup from a vblank worker
12628 * (assuming we had any) would solve these problems.
12630 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
12631 struct intel_crtc_state *new_crtc_state;
12632 struct intel_crtc *crtc;
12635 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
12636 if (new_crtc_state->wm.need_postvbl_update ||
12637 new_crtc_state->update_wm_post)
12638 state->legacy_cursor_update = false;
12641 ret = intel_atomic_prepare_commit(dev, state);
12643 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
12644 i915_sw_fence_commit(&intel_state->commit_ready);
12648 ret = drm_atomic_helper_setup_commit(state, nonblock);
12650 ret = drm_atomic_helper_swap_state(state, true);
12653 i915_sw_fence_commit(&intel_state->commit_ready);
12655 drm_atomic_helper_cleanup_planes(dev, state);
12658 dev_priv->wm.distrust_bios_wm = false;
12659 intel_shared_dpll_swap_state(state);
12660 intel_atomic_track_fbs(state);
12662 if (intel_state->modeset) {
12663 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
12664 sizeof(intel_state->min_cdclk));
12665 memcpy(dev_priv->min_voltage_level,
12666 intel_state->min_voltage_level,
12667 sizeof(intel_state->min_voltage_level));
12668 dev_priv->active_crtcs = intel_state->active_crtcs;
12669 dev_priv->cdclk.logical = intel_state->cdclk.logical;
12670 dev_priv->cdclk.actual = intel_state->cdclk.actual;
12673 drm_atomic_state_get(state);
12674 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
12676 i915_sw_fence_commit(&intel_state->commit_ready);
12677 if (nonblock && intel_state->modeset) {
12678 queue_work(dev_priv->modeset_wq, &state->commit_work);
12679 } else if (nonblock) {
12680 queue_work(system_unbound_wq, &state->commit_work);
12682 if (intel_state->modeset)
12683 flush_workqueue(dev_priv->modeset_wq);
12684 intel_atomic_commit_tail(state);
12690 static const struct drm_crtc_funcs intel_crtc_funcs = {
12691 .gamma_set = drm_atomic_helper_legacy_gamma_set,
12692 .set_config = drm_atomic_helper_set_config,
12693 .destroy = intel_crtc_destroy,
12694 .page_flip = drm_atomic_helper_page_flip,
12695 .atomic_duplicate_state = intel_crtc_duplicate_state,
12696 .atomic_destroy_state = intel_crtc_destroy_state,
12697 .set_crc_source = intel_crtc_set_crc_source,
12700 struct wait_rps_boost {
12701 struct wait_queue_entry wait;
12703 struct drm_crtc *crtc;
12704 struct i915_request *request;
12707 static int do_rps_boost(struct wait_queue_entry *_wait,
12708 unsigned mode, int sync, void *key)
12710 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
12711 struct i915_request *rq = wait->request;
12714 * If we missed the vblank, but the request is already running it
12715 * is reasonable to assume that it will complete before the next
12716 * vblank without our intervention, so leave RPS alone.
12718 if (!i915_request_started(rq))
12719 gen6_rps_boost(rq, NULL);
12720 i915_request_put(rq);
12722 drm_crtc_vblank_put(wait->crtc);
12724 list_del(&wait->wait.entry);
12729 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
12730 struct dma_fence *fence)
12732 struct wait_rps_boost *wait;
12734 if (!dma_fence_is_i915(fence))
12737 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
12740 if (drm_crtc_vblank_get(crtc))
12743 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
12745 drm_crtc_vblank_put(crtc);
12749 wait->request = to_request(dma_fence_get(fence));
12752 wait->wait.func = do_rps_boost;
12753 wait->wait.flags = 0;
12755 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
12758 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
12760 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
12761 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
12762 struct drm_framebuffer *fb = plane_state->base.fb;
12763 struct i915_vma *vma;
12765 if (plane->id == PLANE_CURSOR &&
12766 INTEL_INFO(dev_priv)->cursor_needs_physical) {
12767 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12768 const int align = intel_cursor_alignment(dev_priv);
12770 return i915_gem_object_attach_phys(obj, align);
12773 vma = intel_pin_and_fence_fb_obj(fb,
12774 plane_state->base.rotation,
12775 intel_plane_uses_fence(plane_state),
12776 &plane_state->flags);
12778 return PTR_ERR(vma);
12780 plane_state->vma = vma;
12785 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
12787 struct i915_vma *vma;
12789 vma = fetch_and_zero(&old_plane_state->vma);
12791 intel_unpin_fb_vma(vma, old_plane_state->flags);
12794 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
12796 struct i915_sched_attr attr = {
12797 .priority = I915_PRIORITY_DISPLAY,
12800 i915_gem_object_wait_priority(obj, 0, &attr);
12804 * intel_prepare_plane_fb - Prepare fb for usage on plane
12805 * @plane: drm plane to prepare for
12806 * @new_state: the plane state being prepared
12808 * Prepares a framebuffer for usage on a display plane. Generally this
12809 * involves pinning the underlying object and updating the frontbuffer tracking
12810 * bits. Some older platforms need special physical address handling for
12813 * Must be called with struct_mutex held.
12815 * Returns 0 on success, negative error code on failure.
12818 intel_prepare_plane_fb(struct drm_plane *plane,
12819 struct drm_plane_state *new_state)
12821 struct intel_atomic_state *intel_state =
12822 to_intel_atomic_state(new_state->state);
12823 struct drm_i915_private *dev_priv = to_i915(plane->dev);
12824 struct drm_framebuffer *fb = new_state->fb;
12825 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12826 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
12830 struct drm_crtc_state *crtc_state =
12831 drm_atomic_get_new_crtc_state(new_state->state,
12832 plane->state->crtc);
12834 /* Big Hammer, we also need to ensure that any pending
12835 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
12836 * current scanout is retired before unpinning the old
12837 * framebuffer. Note that we rely on userspace rendering
12838 * into the buffer attached to the pipe they are waiting
12839 * on. If not, userspace generates a GPU hang with IPEHR
12840 * point to the MI_WAIT_FOR_EVENT.
12842 * This should only fail upon a hung GPU, in which case we
12843 * can safely continue.
12845 if (needs_modeset(crtc_state)) {
12846 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
12847 old_obj->resv, NULL,
12855 if (new_state->fence) { /* explicit fencing */
12856 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
12858 I915_FENCE_TIMEOUT,
12867 ret = i915_gem_object_pin_pages(obj);
12871 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
12873 i915_gem_object_unpin_pages(obj);
12877 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
12879 fb_obj_bump_render_priority(obj);
12881 mutex_unlock(&dev_priv->drm.struct_mutex);
12882 i915_gem_object_unpin_pages(obj);
12886 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
12888 if (!new_state->fence) { /* implicit fencing */
12889 struct dma_fence *fence;
12891 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
12893 false, I915_FENCE_TIMEOUT,
12898 fence = reservation_object_get_excl_rcu(obj->resv);
12900 add_rps_boost_after_vblank(new_state->crtc, fence);
12901 dma_fence_put(fence);
12904 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
12911 * intel_cleanup_plane_fb - Cleans up an fb after plane use
12912 * @plane: drm plane to clean up for
12913 * @old_state: the state from the previous modeset
12915 * Cleans up a framebuffer that has just been removed from a plane.
12917 * Must be called with struct_mutex held.
12920 intel_cleanup_plane_fb(struct drm_plane *plane,
12921 struct drm_plane_state *old_state)
12923 struct drm_i915_private *dev_priv = to_i915(plane->dev);
12925 /* Should only be called after a successful intel_prepare_plane_fb()! */
12926 mutex_lock(&dev_priv->drm.struct_mutex);
12927 intel_plane_unpin_fb(to_intel_plane_state(old_state));
12928 mutex_unlock(&dev_priv->drm.struct_mutex);
12932 skl_max_scale(struct intel_crtc *intel_crtc,
12933 struct intel_crtc_state *crtc_state,
12934 uint32_t pixel_format)
12936 struct drm_i915_private *dev_priv;
12937 int max_scale, mult;
12938 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
12940 if (!intel_crtc || !crtc_state->base.enable)
12941 return DRM_PLANE_HELPER_NO_SCALING;
12943 dev_priv = to_i915(intel_crtc->base.dev);
12945 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
12946 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
12948 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
12951 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
12952 return DRM_PLANE_HELPER_NO_SCALING;
12955 * skl max scale is lower of:
12956 * close to 3 but not 3, -1 is for that purpose
12960 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
12961 tmpclk1 = (1 << 16) * mult - 1;
12962 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
12963 max_scale = min(tmpclk1, tmpclk2);
12969 intel_check_primary_plane(struct intel_plane *plane,
12970 struct intel_crtc_state *crtc_state,
12971 struct intel_plane_state *state)
12973 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
12974 struct drm_crtc *crtc = state->base.crtc;
12975 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
12976 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
12977 bool can_position = false;
12979 uint32_t pixel_format = 0;
12981 if (INTEL_GEN(dev_priv) >= 9) {
12982 /* use scaler when colorkey is not required */
12983 if (!state->ckey.flags) {
12985 if (state->base.fb)
12986 pixel_format = state->base.fb->format->format;
12987 max_scale = skl_max_scale(to_intel_crtc(crtc),
12988 crtc_state, pixel_format);
12990 can_position = true;
12993 ret = drm_atomic_helper_check_plane_state(&state->base,
12995 min_scale, max_scale,
12996 can_position, true);
13000 if (!state->base.fb)
13003 if (INTEL_GEN(dev_priv) >= 9) {
13004 ret = skl_check_plane_surface(crtc_state, state);
13008 state->ctl = skl_plane_ctl(crtc_state, state);
13010 ret = i9xx_check_plane_surface(state);
13014 state->ctl = i9xx_plane_ctl(crtc_state, state);
13017 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
13018 state->color_ctl = glk_plane_color_ctl(crtc_state, state);
13023 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13024 struct drm_crtc_state *old_crtc_state)
13026 struct drm_device *dev = crtc->dev;
13027 struct drm_i915_private *dev_priv = to_i915(dev);
13028 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13029 struct intel_crtc_state *old_intel_cstate =
13030 to_intel_crtc_state(old_crtc_state);
13031 struct intel_atomic_state *old_intel_state =
13032 to_intel_atomic_state(old_crtc_state->state);
13033 struct intel_crtc_state *intel_cstate =
13034 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13035 bool modeset = needs_modeset(&intel_cstate->base);
13038 (intel_cstate->base.color_mgmt_changed ||
13039 intel_cstate->update_pipe)) {
13040 intel_color_set_csc(&intel_cstate->base);
13041 intel_color_load_luts(&intel_cstate->base);
13044 /* Perform vblank evasion around commit operation */
13045 intel_pipe_update_start(intel_cstate);
13050 if (intel_cstate->update_pipe)
13051 intel_update_pipe_config(old_intel_cstate, intel_cstate);
13052 else if (INTEL_GEN(dev_priv) >= 9)
13053 skl_detach_scalers(intel_crtc);
13056 if (dev_priv->display.atomic_update_watermarks)
13057 dev_priv->display.atomic_update_watermarks(old_intel_state,
13061 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13062 struct intel_crtc_state *crtc_state)
13064 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13066 if (!IS_GEN2(dev_priv))
13067 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13069 if (crtc_state->has_pch_encoder) {
13070 enum pipe pch_transcoder =
13071 intel_crtc_pch_transcoder(crtc);
13073 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13077 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13078 struct drm_crtc_state *old_crtc_state)
13080 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13081 struct intel_atomic_state *old_intel_state =
13082 to_intel_atomic_state(old_crtc_state->state);
13083 struct intel_crtc_state *new_crtc_state =
13084 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13086 intel_pipe_update_end(new_crtc_state);
13088 if (new_crtc_state->update_pipe &&
13089 !needs_modeset(&new_crtc_state->base) &&
13090 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13091 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
13095 * intel_plane_destroy - destroy a plane
13096 * @plane: plane to destroy
13098 * Common destruction function for all types of planes (primary, cursor,
13101 void intel_plane_destroy(struct drm_plane *plane)
13103 drm_plane_cleanup(plane);
13104 kfree(to_intel_plane(plane));
13107 static bool i8xx_mod_supported(uint32_t format, uint64_t modifier)
13110 case DRM_FORMAT_C8:
13111 case DRM_FORMAT_RGB565:
13112 case DRM_FORMAT_XRGB1555:
13113 case DRM_FORMAT_XRGB8888:
13114 return modifier == DRM_FORMAT_MOD_LINEAR ||
13115 modifier == I915_FORMAT_MOD_X_TILED;
13121 static bool i965_mod_supported(uint32_t format, uint64_t modifier)
13124 case DRM_FORMAT_C8:
13125 case DRM_FORMAT_RGB565:
13126 case DRM_FORMAT_XRGB8888:
13127 case DRM_FORMAT_XBGR8888:
13128 case DRM_FORMAT_XRGB2101010:
13129 case DRM_FORMAT_XBGR2101010:
13130 return modifier == DRM_FORMAT_MOD_LINEAR ||
13131 modifier == I915_FORMAT_MOD_X_TILED;
13137 static bool skl_mod_supported(uint32_t format, uint64_t modifier)
13140 case DRM_FORMAT_XRGB8888:
13141 case DRM_FORMAT_XBGR8888:
13142 case DRM_FORMAT_ARGB8888:
13143 case DRM_FORMAT_ABGR8888:
13144 if (modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
13145 modifier == I915_FORMAT_MOD_Y_TILED_CCS)
13148 case DRM_FORMAT_RGB565:
13149 case DRM_FORMAT_XRGB2101010:
13150 case DRM_FORMAT_XBGR2101010:
13151 case DRM_FORMAT_YUYV:
13152 case DRM_FORMAT_YVYU:
13153 case DRM_FORMAT_UYVY:
13154 case DRM_FORMAT_VYUY:
13155 if (modifier == I915_FORMAT_MOD_Yf_TILED)
13158 case DRM_FORMAT_C8:
13159 if (modifier == DRM_FORMAT_MOD_LINEAR ||
13160 modifier == I915_FORMAT_MOD_X_TILED ||
13161 modifier == I915_FORMAT_MOD_Y_TILED)
13169 static bool intel_primary_plane_format_mod_supported(struct drm_plane *plane,
13173 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13175 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
13178 if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
13179 modifier != DRM_FORMAT_MOD_LINEAR)
13182 if (INTEL_GEN(dev_priv) >= 9)
13183 return skl_mod_supported(format, modifier);
13184 else if (INTEL_GEN(dev_priv) >= 4)
13185 return i965_mod_supported(format, modifier);
13187 return i8xx_mod_supported(format, modifier);
13190 static bool intel_cursor_plane_format_mod_supported(struct drm_plane *plane,
13194 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
13197 return modifier == DRM_FORMAT_MOD_LINEAR && format == DRM_FORMAT_ARGB8888;
13200 static struct drm_plane_funcs intel_plane_funcs = {
13201 .update_plane = drm_atomic_helper_update_plane,
13202 .disable_plane = drm_atomic_helper_disable_plane,
13203 .destroy = intel_plane_destroy,
13204 .atomic_get_property = intel_plane_atomic_get_property,
13205 .atomic_set_property = intel_plane_atomic_set_property,
13206 .atomic_duplicate_state = intel_plane_duplicate_state,
13207 .atomic_destroy_state = intel_plane_destroy_state,
13208 .format_mod_supported = intel_primary_plane_format_mod_supported,
13212 intel_legacy_cursor_update(struct drm_plane *plane,
13213 struct drm_crtc *crtc,
13214 struct drm_framebuffer *fb,
13215 int crtc_x, int crtc_y,
13216 unsigned int crtc_w, unsigned int crtc_h,
13217 uint32_t src_x, uint32_t src_y,
13218 uint32_t src_w, uint32_t src_h,
13219 struct drm_modeset_acquire_ctx *ctx)
13221 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13223 struct drm_plane_state *old_plane_state, *new_plane_state;
13224 struct intel_plane *intel_plane = to_intel_plane(plane);
13225 struct drm_framebuffer *old_fb;
13226 struct drm_crtc_state *crtc_state = crtc->state;
13229 * When crtc is inactive or there is a modeset pending,
13230 * wait for it to complete in the slowpath
13232 if (!crtc_state->active || needs_modeset(crtc_state) ||
13233 to_intel_crtc_state(crtc_state)->update_pipe)
13236 old_plane_state = plane->state;
13238 * Don't do an async update if there is an outstanding commit modifying
13239 * the plane. This prevents our async update's changes from getting
13240 * overridden by a previous synchronous update's state.
13242 if (old_plane_state->commit &&
13243 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13247 * If any parameters change that may affect watermarks,
13248 * take the slowpath. Only changing fb or position should be
13251 if (old_plane_state->crtc != crtc ||
13252 old_plane_state->src_w != src_w ||
13253 old_plane_state->src_h != src_h ||
13254 old_plane_state->crtc_w != crtc_w ||
13255 old_plane_state->crtc_h != crtc_h ||
13256 !old_plane_state->fb != !fb)
13259 new_plane_state = intel_plane_duplicate_state(plane);
13260 if (!new_plane_state)
13263 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13265 new_plane_state->src_x = src_x;
13266 new_plane_state->src_y = src_y;
13267 new_plane_state->src_w = src_w;
13268 new_plane_state->src_h = src_h;
13269 new_plane_state->crtc_x = crtc_x;
13270 new_plane_state->crtc_y = crtc_y;
13271 new_plane_state->crtc_w = crtc_w;
13272 new_plane_state->crtc_h = crtc_h;
13274 ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state),
13275 to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */
13276 to_intel_plane_state(plane->state),
13277 to_intel_plane_state(new_plane_state));
13281 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13285 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13289 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
13291 old_fb = old_plane_state->fb;
13292 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13293 intel_plane->frontbuffer_bit);
13295 /* Swap plane state */
13296 plane->state = new_plane_state;
13298 if (plane->state->visible) {
13299 trace_intel_update_plane(plane, to_intel_crtc(crtc));
13300 intel_plane->update_plane(intel_plane,
13301 to_intel_crtc_state(crtc->state),
13302 to_intel_plane_state(plane->state));
13304 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
13305 intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
13308 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
13311 mutex_unlock(&dev_priv->drm.struct_mutex);
13314 intel_plane_destroy_state(plane, new_plane_state);
13316 intel_plane_destroy_state(plane, old_plane_state);
13320 return drm_atomic_helper_update_plane(plane, crtc, fb,
13321 crtc_x, crtc_y, crtc_w, crtc_h,
13322 src_x, src_y, src_w, src_h, ctx);
13325 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13326 .update_plane = intel_legacy_cursor_update,
13327 .disable_plane = drm_atomic_helper_disable_plane,
13328 .destroy = intel_plane_destroy,
13329 .atomic_get_property = intel_plane_atomic_get_property,
13330 .atomic_set_property = intel_plane_atomic_set_property,
13331 .atomic_duplicate_state = intel_plane_duplicate_state,
13332 .atomic_destroy_state = intel_plane_destroy_state,
13333 .format_mod_supported = intel_cursor_plane_format_mod_supported,
13336 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13337 enum i9xx_plane_id i9xx_plane)
13339 if (!HAS_FBC(dev_priv))
13342 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13343 return i9xx_plane == PLANE_A; /* tied to pipe A */
13344 else if (IS_IVYBRIDGE(dev_priv))
13345 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13346 i9xx_plane == PLANE_C;
13347 else if (INTEL_GEN(dev_priv) >= 4)
13348 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13350 return i9xx_plane == PLANE_A;
13353 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
13354 enum pipe pipe, enum plane_id plane_id)
13356 if (!HAS_FBC(dev_priv))
13359 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
13362 static struct intel_plane *
13363 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
13365 struct intel_plane *primary = NULL;
13366 struct intel_plane_state *state = NULL;
13367 const uint32_t *intel_primary_formats;
13368 unsigned int supported_rotations;
13369 unsigned int num_formats;
13370 const uint64_t *modifiers;
13373 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
13379 state = intel_create_plane_state(&primary->base);
13385 primary->base.state = &state->base;
13387 primary->can_scale = false;
13388 primary->max_downscale = 1;
13389 if (INTEL_GEN(dev_priv) >= 9) {
13390 primary->can_scale = true;
13391 state->scaler_id = -1;
13393 primary->pipe = pipe;
13395 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13396 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13398 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
13399 primary->i9xx_plane = (enum i9xx_plane_id) !pipe;
13401 primary->i9xx_plane = (enum i9xx_plane_id) pipe;
13402 primary->id = PLANE_PRIMARY;
13403 primary->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, primary->id);
13405 if (INTEL_GEN(dev_priv) >= 9)
13406 primary->has_fbc = skl_plane_has_fbc(dev_priv,
13410 primary->has_fbc = i9xx_plane_has_fbc(dev_priv,
13411 primary->i9xx_plane);
13413 if (primary->has_fbc) {
13414 struct intel_fbc *fbc = &dev_priv->fbc;
13416 fbc->possible_framebuffer_bits |= primary->frontbuffer_bit;
13419 primary->check_plane = intel_check_primary_plane;
13421 if (INTEL_GEN(dev_priv) >= 9) {
13422 intel_primary_formats = skl_primary_formats;
13423 num_formats = ARRAY_SIZE(skl_primary_formats);
13425 if (skl_plane_has_ccs(dev_priv, pipe, PLANE_PRIMARY))
13426 modifiers = skl_format_modifiers_ccs;
13428 modifiers = skl_format_modifiers_noccs;
13430 primary->update_plane = skl_update_plane;
13431 primary->disable_plane = skl_disable_plane;
13432 primary->get_hw_state = skl_plane_get_hw_state;
13433 } else if (INTEL_GEN(dev_priv) >= 4) {
13434 intel_primary_formats = i965_primary_formats;
13435 num_formats = ARRAY_SIZE(i965_primary_formats);
13436 modifiers = i9xx_format_modifiers;
13438 primary->update_plane = i9xx_update_plane;
13439 primary->disable_plane = i9xx_disable_plane;
13440 primary->get_hw_state = i9xx_plane_get_hw_state;
13442 intel_primary_formats = i8xx_primary_formats;
13443 num_formats = ARRAY_SIZE(i8xx_primary_formats);
13444 modifiers = i9xx_format_modifiers;
13446 primary->update_plane = i9xx_update_plane;
13447 primary->disable_plane = i9xx_disable_plane;
13448 primary->get_hw_state = i9xx_plane_get_hw_state;
13451 if (INTEL_GEN(dev_priv) >= 9)
13452 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13453 0, &intel_plane_funcs,
13454 intel_primary_formats, num_formats,
13456 DRM_PLANE_TYPE_PRIMARY,
13457 "plane 1%c", pipe_name(pipe));
13458 else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
13459 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13460 0, &intel_plane_funcs,
13461 intel_primary_formats, num_formats,
13463 DRM_PLANE_TYPE_PRIMARY,
13464 "primary %c", pipe_name(pipe));
13466 ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
13467 0, &intel_plane_funcs,
13468 intel_primary_formats, num_formats,
13470 DRM_PLANE_TYPE_PRIMARY,
13472 plane_name(primary->i9xx_plane));
13476 if (INTEL_GEN(dev_priv) >= 10) {
13477 supported_rotations =
13478 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13479 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 |
13480 DRM_MODE_REFLECT_X;
13481 } else if (INTEL_GEN(dev_priv) >= 9) {
13482 supported_rotations =
13483 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
13484 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
13485 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
13486 supported_rotations =
13487 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13488 DRM_MODE_REFLECT_X;
13489 } else if (INTEL_GEN(dev_priv) >= 4) {
13490 supported_rotations =
13491 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
13493 supported_rotations = DRM_MODE_ROTATE_0;
13496 if (INTEL_GEN(dev_priv) >= 4)
13497 drm_plane_create_rotation_property(&primary->base,
13499 supported_rotations);
13501 if (INTEL_GEN(dev_priv) >= 9)
13502 drm_plane_create_color_properties(&primary->base,
13503 BIT(DRM_COLOR_YCBCR_BT601) |
13504 BIT(DRM_COLOR_YCBCR_BT709),
13505 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
13506 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
13507 DRM_COLOR_YCBCR_BT709,
13508 DRM_COLOR_YCBCR_LIMITED_RANGE);
13510 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
13518 return ERR_PTR(ret);
13521 static struct intel_plane *
13522 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13525 struct intel_plane *cursor = NULL;
13526 struct intel_plane_state *state = NULL;
13529 cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
13535 state = intel_create_plane_state(&cursor->base);
13541 cursor->base.state = &state->base;
13543 cursor->can_scale = false;
13544 cursor->max_downscale = 1;
13545 cursor->pipe = pipe;
13546 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
13547 cursor->id = PLANE_CURSOR;
13548 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
13550 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
13551 cursor->update_plane = i845_update_cursor;
13552 cursor->disable_plane = i845_disable_cursor;
13553 cursor->get_hw_state = i845_cursor_get_hw_state;
13554 cursor->check_plane = i845_check_cursor;
13556 cursor->update_plane = i9xx_update_cursor;
13557 cursor->disable_plane = i9xx_disable_cursor;
13558 cursor->get_hw_state = i9xx_cursor_get_hw_state;
13559 cursor->check_plane = i9xx_check_cursor;
13562 cursor->cursor.base = ~0;
13563 cursor->cursor.cntl = ~0;
13565 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
13566 cursor->cursor.size = ~0;
13568 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
13569 0, &intel_cursor_plane_funcs,
13570 intel_cursor_formats,
13571 ARRAY_SIZE(intel_cursor_formats),
13572 cursor_format_modifiers,
13573 DRM_PLANE_TYPE_CURSOR,
13574 "cursor %c", pipe_name(pipe));
13578 if (INTEL_GEN(dev_priv) >= 4)
13579 drm_plane_create_rotation_property(&cursor->base,
13581 DRM_MODE_ROTATE_0 |
13582 DRM_MODE_ROTATE_180);
13584 if (INTEL_GEN(dev_priv) >= 9)
13585 state->scaler_id = -1;
13587 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
13595 return ERR_PTR(ret);
13598 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
13599 struct intel_crtc_state *crtc_state)
13601 struct intel_crtc_scaler_state *scaler_state =
13602 &crtc_state->scaler_state;
13603 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13606 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
13607 if (!crtc->num_scalers)
13610 for (i = 0; i < crtc->num_scalers; i++) {
13611 struct intel_scaler *scaler = &scaler_state->scalers[i];
13613 scaler->in_use = 0;
13614 scaler->mode = PS_SCALER_MODE_DYN;
13617 scaler_state->scaler_id = -1;
13620 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
13622 struct intel_crtc *intel_crtc;
13623 struct intel_crtc_state *crtc_state = NULL;
13624 struct intel_plane *primary = NULL;
13625 struct intel_plane *cursor = NULL;
13628 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
13632 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
13637 intel_crtc->config = crtc_state;
13638 intel_crtc->base.state = &crtc_state->base;
13639 crtc_state->base.crtc = &intel_crtc->base;
13641 primary = intel_primary_plane_create(dev_priv, pipe);
13642 if (IS_ERR(primary)) {
13643 ret = PTR_ERR(primary);
13646 intel_crtc->plane_ids_mask |= BIT(primary->id);
13648 for_each_sprite(dev_priv, pipe, sprite) {
13649 struct intel_plane *plane;
13651 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
13652 if (IS_ERR(plane)) {
13653 ret = PTR_ERR(plane);
13656 intel_crtc->plane_ids_mask |= BIT(plane->id);
13659 cursor = intel_cursor_plane_create(dev_priv, pipe);
13660 if (IS_ERR(cursor)) {
13661 ret = PTR_ERR(cursor);
13664 intel_crtc->plane_ids_mask |= BIT(cursor->id);
13666 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
13667 &primary->base, &cursor->base,
13669 "pipe %c", pipe_name(pipe));
13673 intel_crtc->pipe = pipe;
13675 /* initialize shared scalers */
13676 intel_crtc_init_scalers(intel_crtc, crtc_state);
13678 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
13679 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
13680 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
13682 if (INTEL_GEN(dev_priv) < 9) {
13683 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
13685 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
13686 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
13687 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
13690 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
13692 intel_color_init(&intel_crtc->base);
13694 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
13700 * drm_mode_config_cleanup() will free up any
13701 * crtcs/planes already initialized.
13709 enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
13711 struct drm_device *dev = connector->base.dev;
13713 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
13715 if (!connector->base.state->crtc)
13716 return INVALID_PIPE;
13718 return to_intel_crtc(connector->base.state->crtc)->pipe;
13721 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
13722 struct drm_file *file)
13724 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
13725 struct drm_crtc *drmmode_crtc;
13726 struct intel_crtc *crtc;
13728 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
13732 crtc = to_intel_crtc(drmmode_crtc);
13733 pipe_from_crtc_id->pipe = crtc->pipe;
13738 static int intel_encoder_clones(struct intel_encoder *encoder)
13740 struct drm_device *dev = encoder->base.dev;
13741 struct intel_encoder *source_encoder;
13742 int index_mask = 0;
13745 for_each_intel_encoder(dev, source_encoder) {
13746 if (encoders_cloneable(encoder, source_encoder))
13747 index_mask |= (1 << entry);
13755 static bool has_edp_a(struct drm_i915_private *dev_priv)
13757 if (!IS_MOBILE(dev_priv))
13760 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
13763 if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
13769 static bool intel_crt_present(struct drm_i915_private *dev_priv)
13771 if (INTEL_GEN(dev_priv) >= 9)
13774 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
13777 if (IS_CHERRYVIEW(dev_priv))
13780 if (HAS_PCH_LPT_H(dev_priv) &&
13781 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
13784 /* DDI E can't be used if DDI A requires 4 lanes */
13785 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
13788 if (!dev_priv->vbt.int_crt_support)
13794 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
13799 if (HAS_DDI(dev_priv))
13802 * This w/a is needed at least on CPT/PPT, but to be sure apply it
13803 * everywhere where registers can be write protected.
13805 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13810 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
13811 u32 val = I915_READ(PP_CONTROL(pps_idx));
13813 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
13814 I915_WRITE(PP_CONTROL(pps_idx), val);
13818 static void intel_pps_init(struct drm_i915_private *dev_priv)
13820 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
13821 dev_priv->pps_mmio_base = PCH_PPS_BASE;
13822 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
13823 dev_priv->pps_mmio_base = VLV_PPS_BASE;
13825 dev_priv->pps_mmio_base = PPS_BASE;
13827 intel_pps_unlock_regs_wa(dev_priv);
13830 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
13832 struct intel_encoder *encoder;
13833 bool dpd_is_edp = false;
13835 intel_pps_init(dev_priv);
13838 * intel_edp_init_connector() depends on this completing first, to
13839 * prevent the registeration of both eDP and LVDS and the incorrect
13840 * sharing of the PPS.
13842 intel_lvds_init(dev_priv);
13844 if (intel_crt_present(dev_priv))
13845 intel_crt_init(dev_priv);
13847 if (IS_GEN9_LP(dev_priv)) {
13849 * FIXME: Broxton doesn't support port detection via the
13850 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13851 * detect the ports.
13853 intel_ddi_init(dev_priv, PORT_A);
13854 intel_ddi_init(dev_priv, PORT_B);
13855 intel_ddi_init(dev_priv, PORT_C);
13857 intel_dsi_init(dev_priv);
13858 } else if (HAS_DDI(dev_priv)) {
13862 * Haswell uses DDI functions to detect digital outputs.
13863 * On SKL pre-D0 the strap isn't connected, so we assume
13866 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
13867 /* WaIgnoreDDIAStrap: skl */
13868 if (found || IS_GEN9_BC(dev_priv))
13869 intel_ddi_init(dev_priv, PORT_A);
13871 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
13873 found = I915_READ(SFUSE_STRAP);
13875 if (found & SFUSE_STRAP_DDIB_DETECTED)
13876 intel_ddi_init(dev_priv, PORT_B);
13877 if (found & SFUSE_STRAP_DDIC_DETECTED)
13878 intel_ddi_init(dev_priv, PORT_C);
13879 if (found & SFUSE_STRAP_DDID_DETECTED)
13880 intel_ddi_init(dev_priv, PORT_D);
13881 if (found & SFUSE_STRAP_DDIF_DETECTED)
13882 intel_ddi_init(dev_priv, PORT_F);
13884 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
13886 if (IS_GEN9_BC(dev_priv) &&
13887 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
13888 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
13889 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
13890 intel_ddi_init(dev_priv, PORT_E);
13892 } else if (HAS_PCH_SPLIT(dev_priv)) {
13894 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
13896 if (has_edp_a(dev_priv))
13897 intel_dp_init(dev_priv, DP_A, PORT_A);
13899 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
13900 /* PCH SDVOB multiplex with HDMIB */
13901 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
13903 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
13904 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
13905 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
13908 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
13909 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
13911 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
13912 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
13914 if (I915_READ(PCH_DP_C) & DP_DETECTED)
13915 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
13917 if (I915_READ(PCH_DP_D) & DP_DETECTED)
13918 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
13919 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
13920 bool has_edp, has_port;
13923 * The DP_DETECTED bit is the latched state of the DDC
13924 * SDA pin at boot. However since eDP doesn't require DDC
13925 * (no way to plug in a DP->HDMI dongle) the DDC pins for
13926 * eDP ports may have been muxed to an alternate function.
13927 * Thus we can't rely on the DP_DETECTED bit alone to detect
13928 * eDP ports. Consult the VBT as well as DP_DETECTED to
13929 * detect eDP ports.
13931 * Sadly the straps seem to be missing sometimes even for HDMI
13932 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
13933 * and VBT for the presence of the port. Additionally we can't
13934 * trust the port type the VBT declares as we've seen at least
13935 * HDMI ports that the VBT claim are DP or eDP.
13937 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
13938 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
13939 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
13940 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
13941 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
13942 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
13944 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
13945 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
13946 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
13947 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
13948 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
13949 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
13951 if (IS_CHERRYVIEW(dev_priv)) {
13953 * eDP not supported on port D,
13954 * so no need to worry about it
13956 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
13957 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
13958 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
13959 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
13960 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
13963 intel_dsi_init(dev_priv);
13964 } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
13965 bool found = false;
13967 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
13968 DRM_DEBUG_KMS("probing SDVOB\n");
13969 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
13970 if (!found && IS_G4X(dev_priv)) {
13971 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
13972 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
13975 if (!found && IS_G4X(dev_priv))
13976 intel_dp_init(dev_priv, DP_B, PORT_B);
13979 /* Before G4X SDVOC doesn't have its own detect register */
13981 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
13982 DRM_DEBUG_KMS("probing SDVOC\n");
13983 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
13986 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
13988 if (IS_G4X(dev_priv)) {
13989 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
13990 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
13992 if (IS_G4X(dev_priv))
13993 intel_dp_init(dev_priv, DP_C, PORT_C);
13996 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
13997 intel_dp_init(dev_priv, DP_D, PORT_D);
13998 } else if (IS_GEN2(dev_priv))
13999 intel_dvo_init(dev_priv);
14001 if (SUPPORTS_TV(dev_priv))
14002 intel_tv_init(dev_priv);
14004 intel_psr_init(dev_priv);
14006 for_each_intel_encoder(&dev_priv->drm, encoder) {
14007 encoder->base.possible_crtcs = encoder->crtc_mask;
14008 encoder->base.possible_clones =
14009 intel_encoder_clones(encoder);
14012 intel_init_pch_refclk(dev_priv);
14014 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14017 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14019 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14021 drm_framebuffer_cleanup(fb);
14023 i915_gem_object_lock(intel_fb->obj);
14024 WARN_ON(!intel_fb->obj->framebuffer_references--);
14025 i915_gem_object_unlock(intel_fb->obj);
14027 i915_gem_object_put(intel_fb->obj);
14032 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14033 struct drm_file *file,
14034 unsigned int *handle)
14036 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14037 struct drm_i915_gem_object *obj = intel_fb->obj;
14039 if (obj->userptr.mm) {
14040 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14044 return drm_gem_handle_create(file, &obj->base, handle);
14047 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14048 struct drm_file *file,
14049 unsigned flags, unsigned color,
14050 struct drm_clip_rect *clips,
14051 unsigned num_clips)
14053 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14055 i915_gem_object_flush_if_display(obj);
14056 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14061 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14062 .destroy = intel_user_framebuffer_destroy,
14063 .create_handle = intel_user_framebuffer_create_handle,
14064 .dirty = intel_user_framebuffer_dirty,
14068 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14069 uint64_t fb_modifier, uint32_t pixel_format)
14071 u32 gen = INTEL_GEN(dev_priv);
14074 int cpp = drm_format_plane_cpp(pixel_format, 0);
14076 /* "The stride in bytes must not exceed the of the size of 8K
14077 * pixels and 32K bytes."
14079 return min(8192 * cpp, 32768);
14080 } else if (gen >= 5 && !HAS_GMCH_DISPLAY(dev_priv)) {
14082 } else if (gen >= 4) {
14083 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14087 } else if (gen >= 3) {
14088 if (fb_modifier == I915_FORMAT_MOD_X_TILED)
14093 /* XXX DSPC is limited to 4k tiled */
14098 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14099 struct drm_i915_gem_object *obj,
14100 struct drm_mode_fb_cmd2 *mode_cmd)
14102 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14103 struct drm_framebuffer *fb = &intel_fb->base;
14104 struct drm_format_name_buf format_name;
14106 unsigned int tiling, stride;
14110 i915_gem_object_lock(obj);
14111 obj->framebuffer_references++;
14112 tiling = i915_gem_object_get_tiling(obj);
14113 stride = i915_gem_object_get_stride(obj);
14114 i915_gem_object_unlock(obj);
14116 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14118 * If there's a fence, enforce that
14119 * the fb modifier and tiling mode match.
14121 if (tiling != I915_TILING_NONE &&
14122 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14123 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14127 if (tiling == I915_TILING_X) {
14128 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14129 } else if (tiling == I915_TILING_Y) {
14130 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14135 /* Passed in modifier sanity checking. */
14136 switch (mode_cmd->modifier[0]) {
14137 case I915_FORMAT_MOD_Y_TILED_CCS:
14138 case I915_FORMAT_MOD_Yf_TILED_CCS:
14139 switch (mode_cmd->pixel_format) {
14140 case DRM_FORMAT_XBGR8888:
14141 case DRM_FORMAT_ABGR8888:
14142 case DRM_FORMAT_XRGB8888:
14143 case DRM_FORMAT_ARGB8888:
14146 DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
14150 case I915_FORMAT_MOD_Y_TILED:
14151 case I915_FORMAT_MOD_Yf_TILED:
14152 if (INTEL_GEN(dev_priv) < 9) {
14153 DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
14154 mode_cmd->modifier[0]);
14157 case DRM_FORMAT_MOD_LINEAR:
14158 case I915_FORMAT_MOD_X_TILED:
14161 DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
14162 mode_cmd->modifier[0]);
14167 * gen2/3 display engine uses the fence if present,
14168 * so the tiling mode must match the fb modifier exactly.
14170 if (INTEL_GEN(dev_priv) < 4 &&
14171 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14172 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14176 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
14177 mode_cmd->pixel_format);
14178 if (mode_cmd->pitches[0] > pitch_limit) {
14179 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14180 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14181 "tiled" : "linear",
14182 mode_cmd->pitches[0], pitch_limit);
14187 * If there's a fence, enforce that
14188 * the fb pitch and fence stride match.
14190 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14191 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14192 mode_cmd->pitches[0], stride);
14196 /* Reject formats not supported by any plane early. */
14197 switch (mode_cmd->pixel_format) {
14198 case DRM_FORMAT_C8:
14199 case DRM_FORMAT_RGB565:
14200 case DRM_FORMAT_XRGB8888:
14201 case DRM_FORMAT_ARGB8888:
14203 case DRM_FORMAT_XRGB1555:
14204 if (INTEL_GEN(dev_priv) > 3) {
14205 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14206 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14210 case DRM_FORMAT_ABGR8888:
14211 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
14212 INTEL_GEN(dev_priv) < 9) {
14213 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14214 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14218 case DRM_FORMAT_XBGR8888:
14219 case DRM_FORMAT_XRGB2101010:
14220 case DRM_FORMAT_XBGR2101010:
14221 if (INTEL_GEN(dev_priv) < 4) {
14222 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14223 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14227 case DRM_FORMAT_ABGR2101010:
14228 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
14229 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14230 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14234 case DRM_FORMAT_YUYV:
14235 case DRM_FORMAT_UYVY:
14236 case DRM_FORMAT_YVYU:
14237 case DRM_FORMAT_VYUY:
14238 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
14239 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14240 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14245 DRM_DEBUG_KMS("unsupported pixel format: %s\n",
14246 drm_get_format_name(mode_cmd->pixel_format, &format_name));
14250 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14251 if (mode_cmd->offsets[0] != 0)
14254 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14256 for (i = 0; i < fb->format->num_planes; i++) {
14257 u32 stride_alignment;
14259 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14260 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14264 stride_alignment = intel_fb_stride_alignment(fb, i);
14267 * Display WA #0531: skl,bxt,kbl,glk
14269 * Render decompression and plane width > 3840
14270 * combined with horizontal panning requires the
14271 * plane stride to be a multiple of 4. We'll just
14272 * require the entire fb to accommodate that to avoid
14273 * potential runtime errors at plane configuration time.
14275 if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
14276 (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
14277 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS))
14278 stride_alignment *= 4;
14280 if (fb->pitches[i] & (stride_alignment - 1)) {
14281 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14282 i, fb->pitches[i], stride_alignment);
14287 intel_fb->obj = obj;
14289 ret = intel_fill_fb_info(dev_priv, fb);
14293 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14295 DRM_ERROR("framebuffer init failed %d\n", ret);
14302 i915_gem_object_lock(obj);
14303 obj->framebuffer_references--;
14304 i915_gem_object_unlock(obj);
14308 static struct drm_framebuffer *
14309 intel_user_framebuffer_create(struct drm_device *dev,
14310 struct drm_file *filp,
14311 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14313 struct drm_framebuffer *fb;
14314 struct drm_i915_gem_object *obj;
14315 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14317 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14319 return ERR_PTR(-ENOENT);
14321 fb = intel_framebuffer_create(obj, &mode_cmd);
14323 i915_gem_object_put(obj);
14328 static void intel_atomic_state_free(struct drm_atomic_state *state)
14330 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14332 drm_atomic_state_default_release(state);
14334 i915_sw_fence_fini(&intel_state->commit_ready);
14339 static enum drm_mode_status
14340 intel_mode_valid(struct drm_device *dev,
14341 const struct drm_display_mode *mode)
14343 if (mode->vscan > 1)
14344 return MODE_NO_VSCAN;
14346 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
14347 return MODE_NO_DBLESCAN;
14349 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14350 return MODE_H_ILLEGAL;
14352 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14353 DRM_MODE_FLAG_NCSYNC |
14354 DRM_MODE_FLAG_PCSYNC))
14357 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14358 DRM_MODE_FLAG_PIXMUX |
14359 DRM_MODE_FLAG_CLKDIV2))
14365 static const struct drm_mode_config_funcs intel_mode_funcs = {
14366 .fb_create = intel_user_framebuffer_create,
14367 .get_format_info = intel_get_format_info,
14368 .output_poll_changed = intel_fbdev_output_poll_changed,
14369 .mode_valid = intel_mode_valid,
14370 .atomic_check = intel_atomic_check,
14371 .atomic_commit = intel_atomic_commit,
14372 .atomic_state_alloc = intel_atomic_state_alloc,
14373 .atomic_state_clear = intel_atomic_state_clear,
14374 .atomic_state_free = intel_atomic_state_free,
14378 * intel_init_display_hooks - initialize the display modesetting hooks
14379 * @dev_priv: device private
14381 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14383 intel_init_cdclk_hooks(dev_priv);
14385 if (INTEL_GEN(dev_priv) >= 9) {
14386 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14387 dev_priv->display.get_initial_plane_config =
14388 skylake_get_initial_plane_config;
14389 dev_priv->display.crtc_compute_clock =
14390 haswell_crtc_compute_clock;
14391 dev_priv->display.crtc_enable = haswell_crtc_enable;
14392 dev_priv->display.crtc_disable = haswell_crtc_disable;
14393 } else if (HAS_DDI(dev_priv)) {
14394 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
14395 dev_priv->display.get_initial_plane_config =
14396 i9xx_get_initial_plane_config;
14397 dev_priv->display.crtc_compute_clock =
14398 haswell_crtc_compute_clock;
14399 dev_priv->display.crtc_enable = haswell_crtc_enable;
14400 dev_priv->display.crtc_disable = haswell_crtc_disable;
14401 } else if (HAS_PCH_SPLIT(dev_priv)) {
14402 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
14403 dev_priv->display.get_initial_plane_config =
14404 i9xx_get_initial_plane_config;
14405 dev_priv->display.crtc_compute_clock =
14406 ironlake_crtc_compute_clock;
14407 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14408 dev_priv->display.crtc_disable = ironlake_crtc_disable;
14409 } else if (IS_CHERRYVIEW(dev_priv)) {
14410 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14411 dev_priv->display.get_initial_plane_config =
14412 i9xx_get_initial_plane_config;
14413 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14414 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14415 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14416 } else if (IS_VALLEYVIEW(dev_priv)) {
14417 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14418 dev_priv->display.get_initial_plane_config =
14419 i9xx_get_initial_plane_config;
14420 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
14421 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14422 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14423 } else if (IS_G4X(dev_priv)) {
14424 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14425 dev_priv->display.get_initial_plane_config =
14426 i9xx_get_initial_plane_config;
14427 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14428 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14429 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14430 } else if (IS_PINEVIEW(dev_priv)) {
14431 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14432 dev_priv->display.get_initial_plane_config =
14433 i9xx_get_initial_plane_config;
14434 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14435 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14436 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14437 } else if (!IS_GEN2(dev_priv)) {
14438 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14439 dev_priv->display.get_initial_plane_config =
14440 i9xx_get_initial_plane_config;
14441 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
14442 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14443 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14445 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14446 dev_priv->display.get_initial_plane_config =
14447 i9xx_get_initial_plane_config;
14448 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14449 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14450 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14453 if (IS_GEN5(dev_priv)) {
14454 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
14455 } else if (IS_GEN6(dev_priv)) {
14456 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
14457 } else if (IS_IVYBRIDGE(dev_priv)) {
14458 /* FIXME: detect B0+ stepping and use auto training */
14459 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
14460 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
14461 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
14464 if (INTEL_GEN(dev_priv) >= 9)
14465 dev_priv->display.update_crtcs = skl_update_crtcs;
14467 dev_priv->display.update_crtcs = intel_update_crtcs;
14471 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
14473 static void quirk_ssc_force_disable(struct drm_device *dev)
14475 struct drm_i915_private *dev_priv = to_i915(dev);
14476 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
14477 DRM_INFO("applying lvds SSC disable quirk\n");
14481 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
14484 static void quirk_invert_brightness(struct drm_device *dev)
14486 struct drm_i915_private *dev_priv = to_i915(dev);
14487 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
14488 DRM_INFO("applying inverted panel brightness quirk\n");
14491 /* Some VBT's incorrectly indicate no backlight is present */
14492 static void quirk_backlight_present(struct drm_device *dev)
14494 struct drm_i915_private *dev_priv = to_i915(dev);
14495 dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
14496 DRM_INFO("applying backlight present quirk\n");
14499 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
14500 * which is 300 ms greater than eDP spec T12 min.
14502 static void quirk_increase_t12_delay(struct drm_device *dev)
14504 struct drm_i915_private *dev_priv = to_i915(dev);
14506 dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY;
14507 DRM_INFO("Applying T12 delay quirk\n");
14510 struct intel_quirk {
14512 int subsystem_vendor;
14513 int subsystem_device;
14514 void (*hook)(struct drm_device *dev);
14517 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
14518 struct intel_dmi_quirk {
14519 void (*hook)(struct drm_device *dev);
14520 const struct dmi_system_id (*dmi_id_list)[];
14523 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
14525 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
14529 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
14531 .dmi_id_list = &(const struct dmi_system_id[]) {
14533 .callback = intel_dmi_reverse_brightness,
14534 .ident = "NCR Corporation",
14535 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
14536 DMI_MATCH(DMI_PRODUCT_NAME, ""),
14539 { } /* terminating entry */
14541 .hook = quirk_invert_brightness,
14545 static struct intel_quirk intel_quirks[] = {
14546 /* Lenovo U160 cannot use SSC on LVDS */
14547 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
14549 /* Sony Vaio Y cannot use SSC on LVDS */
14550 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
14552 /* Acer Aspire 5734Z must invert backlight brightness */
14553 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
14555 /* Acer/eMachines G725 */
14556 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
14558 /* Acer/eMachines e725 */
14559 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
14561 /* Acer/Packard Bell NCL20 */
14562 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
14564 /* Acer Aspire 4736Z */
14565 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
14567 /* Acer Aspire 5336 */
14568 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
14570 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
14571 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
14573 /* Acer C720 Chromebook (Core i3 4005U) */
14574 { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
14576 /* Apple Macbook 2,1 (Core 2 T7400) */
14577 { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
14579 /* Apple Macbook 4,1 */
14580 { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
14582 /* Toshiba CB35 Chromebook (Celeron 2955U) */
14583 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
14585 /* HP Chromebook 14 (Celeron 2955U) */
14586 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
14588 /* Dell Chromebook 11 */
14589 { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
14591 /* Dell Chromebook 11 (2015 version) */
14592 { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
14594 /* Toshiba Satellite P50-C-18C */
14595 { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
14598 static void intel_init_quirks(struct drm_device *dev)
14600 struct pci_dev *d = dev->pdev;
14603 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
14604 struct intel_quirk *q = &intel_quirks[i];
14606 if (d->device == q->device &&
14607 (d->subsystem_vendor == q->subsystem_vendor ||
14608 q->subsystem_vendor == PCI_ANY_ID) &&
14609 (d->subsystem_device == q->subsystem_device ||
14610 q->subsystem_device == PCI_ANY_ID))
14613 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
14614 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
14615 intel_dmi_quirks[i].hook(dev);
14619 /* Disable the VGA plane that we never use */
14620 static void i915_disable_vga(struct drm_i915_private *dev_priv)
14622 struct pci_dev *pdev = dev_priv->drm.pdev;
14624 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
14626 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
14627 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
14628 outb(SR01, VGA_SR_INDEX);
14629 sr1 = inb(VGA_SR_DATA);
14630 outb(sr1 | 1<<5, VGA_SR_DATA);
14631 vga_put(pdev, VGA_RSRC_LEGACY_IO);
14634 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
14635 POSTING_READ(vga_reg);
14638 void intel_modeset_init_hw(struct drm_device *dev)
14640 struct drm_i915_private *dev_priv = to_i915(dev);
14642 intel_update_cdclk(dev_priv);
14643 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
14644 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
14648 * Calculate what we think the watermarks should be for the state we've read
14649 * out of the hardware and then immediately program those watermarks so that
14650 * we ensure the hardware settings match our internal state.
14652 * We can calculate what we think WM's should be by creating a duplicate of the
14653 * current state (which was constructed during hardware readout) and running it
14654 * through the atomic check code to calculate new watermark values in the
14657 static void sanitize_watermarks(struct drm_device *dev)
14659 struct drm_i915_private *dev_priv = to_i915(dev);
14660 struct drm_atomic_state *state;
14661 struct intel_atomic_state *intel_state;
14662 struct drm_crtc *crtc;
14663 struct drm_crtc_state *cstate;
14664 struct drm_modeset_acquire_ctx ctx;
14668 /* Only supported on platforms that use atomic watermark design */
14669 if (!dev_priv->display.optimize_watermarks)
14673 * We need to hold connection_mutex before calling duplicate_state so
14674 * that the connector loop is protected.
14676 drm_modeset_acquire_init(&ctx, 0);
14678 ret = drm_modeset_lock_all_ctx(dev, &ctx);
14679 if (ret == -EDEADLK) {
14680 drm_modeset_backoff(&ctx);
14682 } else if (WARN_ON(ret)) {
14686 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14687 if (WARN_ON(IS_ERR(state)))
14690 intel_state = to_intel_atomic_state(state);
14693 * Hardware readout is the only time we don't want to calculate
14694 * intermediate watermarks (since we don't trust the current
14697 if (!HAS_GMCH_DISPLAY(dev_priv))
14698 intel_state->skip_intermediate_wm = true;
14700 ret = intel_atomic_check(dev, state);
14703 * If we fail here, it means that the hardware appears to be
14704 * programmed in a way that shouldn't be possible, given our
14705 * understanding of watermark requirements. This might mean a
14706 * mistake in the hardware readout code or a mistake in the
14707 * watermark calculations for a given platform. Raise a WARN
14708 * so that this is noticeable.
14710 * If this actually happens, we'll have to just leave the
14711 * BIOS-programmed watermarks untouched and hope for the best.
14713 WARN(true, "Could not determine valid watermarks for inherited state\n");
14717 /* Write calculated watermark values back */
14718 for_each_new_crtc_in_state(state, crtc, cstate, i) {
14719 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14721 cs->wm.need_postvbl_update = true;
14722 dev_priv->display.optimize_watermarks(intel_state, cs);
14724 to_intel_crtc_state(crtc->state)->wm = cs->wm;
14728 drm_atomic_state_put(state);
14730 drm_modeset_drop_locks(&ctx);
14731 drm_modeset_acquire_fini(&ctx);
14734 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14736 if (IS_GEN5(dev_priv)) {
14738 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14740 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14741 } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
14742 dev_priv->fdi_pll_freq = 270000;
14747 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14750 int intel_modeset_init(struct drm_device *dev)
14752 struct drm_i915_private *dev_priv = to_i915(dev);
14753 struct i915_ggtt *ggtt = &dev_priv->ggtt;
14755 struct intel_crtc *crtc;
14757 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
14759 drm_mode_config_init(dev);
14761 dev->mode_config.min_width = 0;
14762 dev->mode_config.min_height = 0;
14764 dev->mode_config.preferred_depth = 24;
14765 dev->mode_config.prefer_shadow = 1;
14767 dev->mode_config.allow_fb_modifiers = true;
14769 dev->mode_config.funcs = &intel_mode_funcs;
14771 init_llist_head(&dev_priv->atomic_helper.free_list);
14772 INIT_WORK(&dev_priv->atomic_helper.free_work,
14773 intel_atomic_helper_free_state_worker);
14775 intel_init_quirks(dev);
14777 intel_init_pm(dev_priv);
14779 if (INTEL_INFO(dev_priv)->num_pipes == 0)
14783 * There may be no VBT; and if the BIOS enabled SSC we can
14784 * just keep using it to avoid unnecessary flicker. Whereas if the
14785 * BIOS isn't using it, don't assume it will work even if the VBT
14786 * indicates as much.
14788 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
14789 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
14792 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
14793 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
14794 bios_lvds_use_ssc ? "en" : "dis",
14795 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
14796 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
14800 if (IS_GEN2(dev_priv)) {
14801 dev->mode_config.max_width = 2048;
14802 dev->mode_config.max_height = 2048;
14803 } else if (IS_GEN3(dev_priv)) {
14804 dev->mode_config.max_width = 4096;
14805 dev->mode_config.max_height = 4096;
14807 dev->mode_config.max_width = 8192;
14808 dev->mode_config.max_height = 8192;
14811 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14812 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
14813 dev->mode_config.cursor_height = 1023;
14814 } else if (IS_GEN2(dev_priv)) {
14815 dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
14816 dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
14818 dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
14819 dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
14822 dev->mode_config.fb_base = ggtt->gmadr.start;
14824 DRM_DEBUG_KMS("%d display pipe%s available.\n",
14825 INTEL_INFO(dev_priv)->num_pipes,
14826 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
14828 for_each_pipe(dev_priv, pipe) {
14831 ret = intel_crtc_init(dev_priv, pipe);
14833 drm_mode_config_cleanup(dev);
14838 intel_shared_dpll_init(dev);
14839 intel_update_fdi_pll_freq(dev_priv);
14841 intel_update_czclk(dev_priv);
14842 intel_modeset_init_hw(dev);
14844 if (dev_priv->max_cdclk_freq == 0)
14845 intel_update_max_cdclk(dev_priv);
14847 /* Just disable it once at startup */
14848 i915_disable_vga(dev_priv);
14849 intel_setup_outputs(dev_priv);
14851 drm_modeset_lock_all(dev);
14852 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
14853 drm_modeset_unlock_all(dev);
14855 for_each_intel_crtc(dev, crtc) {
14856 struct intel_initial_plane_config plane_config = {};
14862 * Note that reserving the BIOS fb up front prevents us
14863 * from stuffing other stolen allocations like the ring
14864 * on top. This prevents some ugliness at boot time, and
14865 * can even allow for smooth boot transitions if the BIOS
14866 * fb is large enough for the active pipe configuration.
14868 dev_priv->display.get_initial_plane_config(crtc,
14872 * If the fb is shared between multiple heads, we'll
14873 * just get the first one.
14875 intel_find_initial_plane_obj(crtc, &plane_config);
14879 * Make sure hardware watermarks really match the state we read out.
14880 * Note that we need to do this after reconstructing the BIOS fb's
14881 * since the watermark calculation done here will use pstate->fb.
14883 if (!HAS_GMCH_DISPLAY(dev_priv))
14884 sanitize_watermarks(dev);
14889 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
14891 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
14892 /* 640x480@60Hz, ~25175 kHz */
14893 struct dpll clock = {
14903 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
14905 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
14906 pipe_name(pipe), clock.vco, clock.dot);
14908 fp = i9xx_dpll_compute_fp(&clock);
14909 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
14910 DPLL_VGA_MODE_DIS |
14911 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
14912 PLL_P2_DIVIDE_BY_4 |
14913 PLL_REF_INPUT_DREFCLK |
14916 I915_WRITE(FP0(pipe), fp);
14917 I915_WRITE(FP1(pipe), fp);
14919 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
14920 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
14921 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
14922 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
14923 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
14924 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
14925 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
14928 * Apparently we need to have VGA mode enabled prior to changing
14929 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
14930 * dividers, even though the register value does change.
14932 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
14933 I915_WRITE(DPLL(pipe), dpll);
14935 /* Wait for the clocks to stabilize. */
14936 POSTING_READ(DPLL(pipe));
14939 /* The pixel multiplier can only be updated once the
14940 * DPLL is enabled and the clocks are stable.
14942 * So write it again.
14944 I915_WRITE(DPLL(pipe), dpll);
14946 /* We do this three times for luck */
14947 for (i = 0; i < 3 ; i++) {
14948 I915_WRITE(DPLL(pipe), dpll);
14949 POSTING_READ(DPLL(pipe));
14950 udelay(150); /* wait for warmup */
14953 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
14954 POSTING_READ(PIPECONF(pipe));
14956 intel_wait_for_pipe_scanline_moving(crtc);
14959 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
14961 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
14963 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
14966 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
14967 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
14968 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
14969 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & CURSOR_MODE);
14970 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & CURSOR_MODE);
14972 I915_WRITE(PIPECONF(pipe), 0);
14973 POSTING_READ(PIPECONF(pipe));
14975 intel_wait_for_pipe_scanline_stopped(crtc);
14977 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
14978 POSTING_READ(DPLL(pipe));
14981 static bool intel_plane_mapping_ok(struct intel_crtc *crtc,
14982 struct intel_plane *plane)
14984 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14985 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
14986 u32 val = I915_READ(DSPCNTR(i9xx_plane));
14988 return (val & DISPLAY_PLANE_ENABLE) == 0 ||
14989 (val & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE(crtc->pipe);
14993 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
14995 struct intel_crtc *crtc;
14997 if (INTEL_GEN(dev_priv) >= 4)
15000 for_each_intel_crtc(&dev_priv->drm, crtc) {
15001 struct intel_plane *plane =
15002 to_intel_plane(crtc->base.primary);
15004 if (intel_plane_mapping_ok(crtc, plane))
15007 DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n",
15009 intel_plane_disable_noatomic(crtc, plane);
15013 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15015 struct drm_device *dev = crtc->base.dev;
15016 struct intel_encoder *encoder;
15018 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15024 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15026 struct drm_device *dev = encoder->base.dev;
15027 struct intel_connector *connector;
15029 for_each_connector_on_encoder(dev, &encoder->base, connector)
15035 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15036 enum pipe pch_transcoder)
15038 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15039 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15042 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15043 struct drm_modeset_acquire_ctx *ctx)
15045 struct drm_device *dev = crtc->base.dev;
15046 struct drm_i915_private *dev_priv = to_i915(dev);
15047 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
15049 /* Clear any frame start delays used for debugging left by the BIOS */
15050 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
15051 i915_reg_t reg = PIPECONF(cpu_transcoder);
15054 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15057 /* restore vblank interrupts to correct state */
15058 drm_crtc_vblank_reset(&crtc->base);
15059 if (crtc->active) {
15060 struct intel_plane *plane;
15062 drm_crtc_vblank_on(&crtc->base);
15064 /* Disable everything but the primary plane */
15065 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15066 const struct intel_plane_state *plane_state =
15067 to_intel_plane_state(plane->base.state);
15069 if (plane_state->base.visible &&
15070 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15071 intel_plane_disable_noatomic(crtc, plane);
15075 /* Adjust the state of the output pipe according to whether we
15076 * have active connectors/encoders. */
15077 if (crtc->active && !intel_crtc_has_encoders(crtc))
15078 intel_crtc_disable_noatomic(&crtc->base, ctx);
15080 if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) {
15082 * We start out with underrun reporting disabled to avoid races.
15083 * For correct bookkeeping mark this on active crtcs.
15085 * Also on gmch platforms we dont have any hardware bits to
15086 * disable the underrun reporting. Which means we need to start
15087 * out with underrun reporting disabled also on inactive pipes,
15088 * since otherwise we'll complain about the garbage we read when
15089 * e.g. coming up after runtime pm.
15091 * No protection against concurrent access is required - at
15092 * worst a fifo underrun happens which also sets this to false.
15094 crtc->cpu_fifo_underrun_disabled = true;
15096 * We track the PCH trancoder underrun reporting state
15097 * within the crtc. With crtc for pipe A housing the underrun
15098 * reporting state for PCH transcoder A, crtc for pipe B housing
15099 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15100 * and marking underrun reporting as disabled for the non-existing
15101 * PCH transcoders B and C would prevent enabling the south
15102 * error interrupt (see cpt_can_enable_serr_int()).
15104 if (has_pch_trancoder(dev_priv, crtc->pipe))
15105 crtc->pch_fifo_underrun_disabled = true;
15109 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15111 struct intel_connector *connector;
15113 /* We need to check both for a crtc link (meaning that the
15114 * encoder is active and trying to read from a pipe) and the
15115 * pipe itself being active. */
15116 bool has_active_crtc = encoder->base.crtc &&
15117 to_intel_crtc(encoder->base.crtc)->active;
15119 connector = intel_encoder_find_connector(encoder);
15120 if (connector && !has_active_crtc) {
15121 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15122 encoder->base.base.id,
15123 encoder->base.name);
15125 /* Connector is active, but has no active pipe. This is
15126 * fallout from our resume register restoring. Disable
15127 * the encoder manually again. */
15128 if (encoder->base.crtc) {
15129 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15131 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15132 encoder->base.base.id,
15133 encoder->base.name);
15134 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15135 if (encoder->post_disable)
15136 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
15138 encoder->base.crtc = NULL;
15140 /* Inconsistent output/port/pipe state happens presumably due to
15141 * a bug in one of the get_hw_state functions. Or someplace else
15142 * in our code, like the register restore mess on resume. Clamp
15143 * things to off as a safer default. */
15145 connector->base.dpms = DRM_MODE_DPMS_OFF;
15146 connector->base.encoder = NULL;
15150 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15152 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15154 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15155 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15156 i915_disable_vga(dev_priv);
15160 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15162 /* This function can be called both from intel_modeset_setup_hw_state or
15163 * at a very early point in our resume sequence, where the power well
15164 * structures are not yet restored. Since this function is at a very
15165 * paranoid "someone might have enabled VGA while we were not looking"
15166 * level, just check if the power well is enabled instead of trying to
15167 * follow the "don't touch the power well if we don't need it" policy
15168 * the rest of the driver uses. */
15169 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
15172 i915_redisable_vga_power_on(dev_priv);
15174 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
15177 /* FIXME read out full plane state for all planes */
15178 static void readout_plane_state(struct intel_crtc *crtc)
15180 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15181 struct intel_crtc_state *crtc_state =
15182 to_intel_crtc_state(crtc->base.state);
15183 struct intel_plane *plane;
15185 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
15186 struct intel_plane_state *plane_state =
15187 to_intel_plane_state(plane->base.state);
15188 bool visible = plane->get_hw_state(plane);
15190 intel_set_plane_visible(crtc_state, plane_state, visible);
15194 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15196 struct drm_i915_private *dev_priv = to_i915(dev);
15198 struct intel_crtc *crtc;
15199 struct intel_encoder *encoder;
15200 struct intel_connector *connector;
15201 struct drm_connector_list_iter conn_iter;
15204 dev_priv->active_crtcs = 0;
15206 for_each_intel_crtc(dev, crtc) {
15207 struct intel_crtc_state *crtc_state =
15208 to_intel_crtc_state(crtc->base.state);
15210 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15211 memset(crtc_state, 0, sizeof(*crtc_state));
15212 crtc_state->base.crtc = &crtc->base;
15214 crtc_state->base.active = crtc_state->base.enable =
15215 dev_priv->display.get_pipe_config(crtc, crtc_state);
15217 crtc->base.enabled = crtc_state->base.enable;
15218 crtc->active = crtc_state->base.active;
15220 if (crtc_state->base.active)
15221 dev_priv->active_crtcs |= 1 << crtc->pipe;
15223 readout_plane_state(crtc);
15225 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15226 crtc->base.base.id, crtc->base.name,
15227 enableddisabled(crtc_state->base.active));
15230 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15231 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15233 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15234 &pll->state.hw_state);
15235 pll->state.crtc_mask = 0;
15236 for_each_intel_crtc(dev, crtc) {
15237 struct intel_crtc_state *crtc_state =
15238 to_intel_crtc_state(crtc->base.state);
15240 if (crtc_state->base.active &&
15241 crtc_state->shared_dpll == pll)
15242 pll->state.crtc_mask |= 1 << crtc->pipe;
15244 pll->active_mask = pll->state.crtc_mask;
15246 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15247 pll->info->name, pll->state.crtc_mask, pll->on);
15250 for_each_intel_encoder(dev, encoder) {
15253 if (encoder->get_hw_state(encoder, &pipe)) {
15254 struct intel_crtc_state *crtc_state;
15256 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15257 crtc_state = to_intel_crtc_state(crtc->base.state);
15259 encoder->base.crtc = &crtc->base;
15260 encoder->get_config(encoder, crtc_state);
15262 encoder->base.crtc = NULL;
15265 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15266 encoder->base.base.id, encoder->base.name,
15267 enableddisabled(encoder->base.crtc),
15271 drm_connector_list_iter_begin(dev, &conn_iter);
15272 for_each_intel_connector_iter(connector, &conn_iter) {
15273 if (connector->get_hw_state(connector)) {
15274 connector->base.dpms = DRM_MODE_DPMS_ON;
15276 encoder = connector->encoder;
15277 connector->base.encoder = &encoder->base;
15279 if (encoder->base.crtc &&
15280 encoder->base.crtc->state->active) {
15282 * This has to be done during hardware readout
15283 * because anything calling .crtc_disable may
15284 * rely on the connector_mask being accurate.
15286 encoder->base.crtc->state->connector_mask |=
15287 1 << drm_connector_index(&connector->base);
15288 encoder->base.crtc->state->encoder_mask |=
15289 1 << drm_encoder_index(&encoder->base);
15293 connector->base.dpms = DRM_MODE_DPMS_OFF;
15294 connector->base.encoder = NULL;
15296 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15297 connector->base.base.id, connector->base.name,
15298 enableddisabled(connector->base.encoder));
15300 drm_connector_list_iter_end(&conn_iter);
15302 for_each_intel_crtc(dev, crtc) {
15303 struct intel_crtc_state *crtc_state =
15304 to_intel_crtc_state(crtc->base.state);
15307 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15308 if (crtc_state->base.active) {
15309 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15310 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15311 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15314 * The initial mode needs to be set in order to keep
15315 * the atomic core happy. It wants a valid mode if the
15316 * crtc's enabled, so we do the above call.
15318 * But we don't set all the derived state fully, hence
15319 * set a flag to indicate that a full recalculation is
15320 * needed on the next commit.
15322 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
15324 intel_crtc_compute_pixel_rate(crtc_state);
15326 if (dev_priv->display.modeset_calc_cdclk) {
15327 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15328 if (WARN_ON(min_cdclk < 0))
15332 drm_calc_timestamping_constants(&crtc->base,
15333 &crtc_state->base.adjusted_mode);
15334 update_scanline_offset(crtc);
15337 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
15338 dev_priv->min_voltage_level[crtc->pipe] =
15339 crtc_state->min_voltage_level;
15341 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15346 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15348 struct intel_encoder *encoder;
15350 for_each_intel_encoder(&dev_priv->drm, encoder) {
15352 enum intel_display_power_domain domain;
15354 if (!encoder->get_power_domains)
15357 get_domains = encoder->get_power_domains(encoder);
15358 for_each_power_domain(domain, get_domains)
15359 intel_display_power_get(dev_priv, domain);
15363 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15365 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15366 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15367 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15370 if (IS_HASWELL(dev_priv)) {
15372 * WaRsPkgCStateDisplayPMReq:hsw
15373 * System hang if this isn't done before disabling all planes!
15375 I915_WRITE(CHICKEN_PAR1_1,
15376 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15380 /* Scan out the current hw modeset state,
15381 * and sanitizes it to the current state
15384 intel_modeset_setup_hw_state(struct drm_device *dev,
15385 struct drm_modeset_acquire_ctx *ctx)
15387 struct drm_i915_private *dev_priv = to_i915(dev);
15389 struct intel_crtc *crtc;
15390 struct intel_encoder *encoder;
15393 intel_early_display_was(dev_priv);
15394 intel_modeset_readout_hw_state(dev);
15396 /* HW state is read out, now we need to sanitize this mess. */
15397 get_encoder_power_domains(dev_priv);
15399 intel_sanitize_plane_mapping(dev_priv);
15401 for_each_intel_encoder(dev, encoder) {
15402 intel_sanitize_encoder(encoder);
15405 for_each_pipe(dev_priv, pipe) {
15406 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15408 intel_sanitize_crtc(crtc, ctx);
15409 intel_dump_pipe_config(crtc, crtc->config,
15410 "[setup_hw_state]");
15413 intel_modeset_update_connector_atomic_state(dev);
15415 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15416 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15418 if (!pll->on || pll->active_mask)
15421 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15424 pll->info->funcs->disable(dev_priv, pll);
15428 if (IS_G4X(dev_priv)) {
15429 g4x_wm_get_hw_state(dev);
15430 g4x_wm_sanitize(dev_priv);
15431 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15432 vlv_wm_get_hw_state(dev);
15433 vlv_wm_sanitize(dev_priv);
15434 } else if (INTEL_GEN(dev_priv) >= 9) {
15435 skl_wm_get_hw_state(dev);
15436 } else if (HAS_PCH_SPLIT(dev_priv)) {
15437 ilk_wm_get_hw_state(dev);
15440 for_each_intel_crtc(dev, crtc) {
15443 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config);
15444 if (WARN_ON(put_domains))
15445 modeset_put_power_domains(dev_priv, put_domains);
15447 intel_display_set_init_power(dev_priv, false);
15449 intel_power_domains_verify_state(dev_priv);
15451 intel_fbc_init_pipe_state(dev_priv);
15454 void intel_display_resume(struct drm_device *dev)
15456 struct drm_i915_private *dev_priv = to_i915(dev);
15457 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15458 struct drm_modeset_acquire_ctx ctx;
15461 dev_priv->modeset_restore_state = NULL;
15463 state->acquire_ctx = &ctx;
15465 drm_modeset_acquire_init(&ctx, 0);
15468 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15469 if (ret != -EDEADLK)
15472 drm_modeset_backoff(&ctx);
15476 ret = __intel_display_resume(dev, state, &ctx);
15478 intel_enable_ipc(dev_priv);
15479 drm_modeset_drop_locks(&ctx);
15480 drm_modeset_acquire_fini(&ctx);
15483 DRM_ERROR("Restoring old state failed with %i\n", ret);
15485 drm_atomic_state_put(state);
15488 int intel_connector_register(struct drm_connector *connector)
15490 struct intel_connector *intel_connector = to_intel_connector(connector);
15493 ret = intel_backlight_device_register(intel_connector);
15503 void intel_connector_unregister(struct drm_connector *connector)
15505 struct intel_connector *intel_connector = to_intel_connector(connector);
15507 intel_backlight_device_unregister(intel_connector);
15508 intel_panel_destroy_backlight(connector);
15511 static void intel_hpd_poll_fini(struct drm_device *dev)
15513 struct intel_connector *connector;
15514 struct drm_connector_list_iter conn_iter;
15516 /* Kill all the work that may have been queued by hpd. */
15517 drm_connector_list_iter_begin(dev, &conn_iter);
15518 for_each_intel_connector_iter(connector, &conn_iter) {
15519 if (connector->modeset_retry_work.func)
15520 cancel_work_sync(&connector->modeset_retry_work);
15521 if (connector->hdcp_shim) {
15522 cancel_delayed_work_sync(&connector->hdcp_check_work);
15523 cancel_work_sync(&connector->hdcp_prop_work);
15526 drm_connector_list_iter_end(&conn_iter);
15529 void intel_modeset_cleanup(struct drm_device *dev)
15531 struct drm_i915_private *dev_priv = to_i915(dev);
15533 flush_work(&dev_priv->atomic_helper.free_work);
15534 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15536 intel_disable_gt_powersave(dev_priv);
15539 * Interrupts and polling as the first thing to avoid creating havoc.
15540 * Too much stuff here (turning of connectors, ...) would
15541 * experience fancy races otherwise.
15543 intel_irq_uninstall(dev_priv);
15546 * Due to the hpd irq storm handling the hotplug work can re-arm the
15547 * poll handlers. Hence disable polling after hpd handling is shut down.
15549 intel_hpd_poll_fini(dev);
15551 /* poll work can call into fbdev, hence clean that up afterwards */
15552 intel_fbdev_fini(dev_priv);
15554 intel_unregister_dsm_handler();
15556 intel_fbc_global_disable(dev_priv);
15558 /* flush any delayed tasks or pending work */
15559 flush_scheduled_work();
15561 drm_mode_config_cleanup(dev);
15563 intel_cleanup_overlay(dev_priv);
15565 intel_cleanup_gt_powersave(dev_priv);
15567 intel_teardown_gmbus(dev_priv);
15569 destroy_workqueue(dev_priv->modeset_wq);
15572 void intel_connector_attach_encoder(struct intel_connector *connector,
15573 struct intel_encoder *encoder)
15575 connector->encoder = encoder;
15576 drm_mode_connector_attach_encoder(&connector->base,
15581 * set vga decode state - true == enable VGA decode
15583 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
15585 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
15588 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15589 DRM_ERROR("failed to read control word\n");
15593 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15597 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15599 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
15601 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15602 DRM_ERROR("failed to write control word\n");
15609 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15611 struct intel_display_error_state {
15613 u32 power_well_driver;
15615 int num_transcoders;
15617 struct intel_cursor_error_state {
15622 } cursor[I915_MAX_PIPES];
15624 struct intel_pipe_error_state {
15625 bool power_domain_on;
15628 } pipe[I915_MAX_PIPES];
15630 struct intel_plane_error_state {
15638 } plane[I915_MAX_PIPES];
15640 struct intel_transcoder_error_state {
15641 bool power_domain_on;
15642 enum transcoder cpu_transcoder;
15655 struct intel_display_error_state *
15656 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
15658 struct intel_display_error_state *error;
15659 int transcoders[] = {
15667 if (INTEL_INFO(dev_priv)->num_pipes == 0)
15670 error = kzalloc(sizeof(*error), GFP_ATOMIC);
15674 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15675 error->power_well_driver =
15676 I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL));
15678 for_each_pipe(dev_priv, i) {
15679 error->pipe[i].power_domain_on =
15680 __intel_display_power_is_enabled(dev_priv,
15681 POWER_DOMAIN_PIPE(i));
15682 if (!error->pipe[i].power_domain_on)
15685 error->cursor[i].control = I915_READ(CURCNTR(i));
15686 error->cursor[i].position = I915_READ(CURPOS(i));
15687 error->cursor[i].base = I915_READ(CURBASE(i));
15689 error->plane[i].control = I915_READ(DSPCNTR(i));
15690 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
15691 if (INTEL_GEN(dev_priv) <= 3) {
15692 error->plane[i].size = I915_READ(DSPSIZE(i));
15693 error->plane[i].pos = I915_READ(DSPPOS(i));
15695 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15696 error->plane[i].addr = I915_READ(DSPADDR(i));
15697 if (INTEL_GEN(dev_priv) >= 4) {
15698 error->plane[i].surface = I915_READ(DSPSURF(i));
15699 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
15702 error->pipe[i].source = I915_READ(PIPESRC(i));
15704 if (HAS_GMCH_DISPLAY(dev_priv))
15705 error->pipe[i].stat = I915_READ(PIPESTAT(i));
15708 /* Note: this does not include DSI transcoders. */
15709 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
15710 if (HAS_DDI(dev_priv))
15711 error->num_transcoders++; /* Account for eDP. */
15713 for (i = 0; i < error->num_transcoders; i++) {
15714 enum transcoder cpu_transcoder = transcoders[i];
15716 error->transcoder[i].power_domain_on =
15717 __intel_display_power_is_enabled(dev_priv,
15718 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
15719 if (!error->transcoder[i].power_domain_on)
15722 error->transcoder[i].cpu_transcoder = cpu_transcoder;
15724 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
15725 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
15726 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
15727 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
15728 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
15729 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
15730 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
15736 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
15739 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
15740 struct intel_display_error_state *error)
15742 struct drm_i915_private *dev_priv = m->i915;
15748 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
15749 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
15750 err_printf(m, "PWR_WELL_CTL2: %08x\n",
15751 error->power_well_driver);
15752 for_each_pipe(dev_priv, i) {
15753 err_printf(m, "Pipe [%d]:\n", i);
15754 err_printf(m, " Power: %s\n",
15755 onoff(error->pipe[i].power_domain_on));
15756 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
15757 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
15759 err_printf(m, "Plane [%d]:\n", i);
15760 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
15761 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
15762 if (INTEL_GEN(dev_priv) <= 3) {
15763 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
15764 err_printf(m, " POS: %08x\n", error->plane[i].pos);
15766 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
15767 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
15768 if (INTEL_GEN(dev_priv) >= 4) {
15769 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
15770 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
15773 err_printf(m, "Cursor [%d]:\n", i);
15774 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
15775 err_printf(m, " POS: %08x\n", error->cursor[i].position);
15776 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
15779 for (i = 0; i < error->num_transcoders; i++) {
15780 err_printf(m, "CPU transcoder: %s\n",
15781 transcoder_name(error->transcoder[i].cpu_transcoder));
15782 err_printf(m, " Power: %s\n",
15783 onoff(error->transcoder[i].power_domain_on));
15784 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
15785 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
15786 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
15787 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
15788 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
15789 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
15790 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);