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/i2c.h>
28 #include <linux/input.h>
29 #include <linux/intel-iommu.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/reservation.h>
33 #include <linux/slab.h>
34 #include <linux/vgaarb.h>
36 #include <drm/drm_atomic.h>
37 #include <drm/drm_atomic_helper.h>
38 #include <drm/drm_atomic_uapi.h>
39 #include <drm/drm_dp_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_fourcc.h>
42 #include <drm/drm_plane_helper.h>
43 #include <drm/drm_probe_helper.h>
44 #include <drm/drm_rect.h>
45 #include <drm/i915_drm.h>
48 #include "i915_gem_clflush.h"
49 #include "i915_trace.h"
50 #include "intel_drv.h"
51 #include "intel_dsi.h"
52 #include "intel_frontbuffer.h"
54 #include "intel_drv.h"
55 #include "intel_dsi.h"
56 #include "intel_frontbuffer.h"
59 #include "i915_gem_clflush.h"
60 #include "i915_reset.h"
61 #include "i915_trace.h"
63 /* Primary plane formats for gen <= 3 */
64 static const u32 i8xx_primary_formats[] = {
71 /* Primary plane formats for gen >= 4 */
72 static const u32 i965_primary_formats[] = {
77 DRM_FORMAT_XRGB2101010,
78 DRM_FORMAT_XBGR2101010,
81 static const u64 i9xx_format_modifiers[] = {
82 I915_FORMAT_MOD_X_TILED,
83 DRM_FORMAT_MOD_LINEAR,
84 DRM_FORMAT_MOD_INVALID
88 static const u32 intel_cursor_formats[] = {
92 static const u64 cursor_format_modifiers[] = {
93 DRM_FORMAT_MOD_LINEAR,
94 DRM_FORMAT_MOD_INVALID
97 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
98 struct intel_crtc_state *pipe_config);
99 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
100 struct intel_crtc_state *pipe_config);
102 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
103 struct drm_i915_gem_object *obj,
104 struct drm_mode_fb_cmd2 *mode_cmd);
105 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
106 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
107 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
108 const struct intel_link_m_n *m_n,
109 const struct intel_link_m_n *m2_n2);
110 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
111 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
112 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
113 static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state);
114 static void vlv_prepare_pll(struct intel_crtc *crtc,
115 const struct intel_crtc_state *pipe_config);
116 static void chv_prepare_pll(struct intel_crtc *crtc,
117 const struct intel_crtc_state *pipe_config);
118 static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
119 static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
120 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
121 struct intel_crtc_state *crtc_state);
122 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
123 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
124 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
125 static void intel_modeset_setup_hw_state(struct drm_device *dev,
126 struct drm_modeset_acquire_ctx *ctx);
127 static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
132 } dot, vco, n, m, m1, m2, p, p1;
136 int p2_slow, p2_fast;
140 /* returns HPLL frequency in kHz */
141 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
143 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
145 /* Obtain SKU information */
146 mutex_lock(&dev_priv->sb_lock);
147 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
148 CCK_FUSE_HPLL_FREQ_MASK;
149 mutex_unlock(&dev_priv->sb_lock);
151 return vco_freq[hpll_freq] * 1000;
154 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
155 const char *name, u32 reg, int ref_freq)
160 mutex_lock(&dev_priv->sb_lock);
161 val = vlv_cck_read(dev_priv, reg);
162 mutex_unlock(&dev_priv->sb_lock);
164 divider = val & CCK_FREQUENCY_VALUES;
166 WARN((val & CCK_FREQUENCY_STATUS) !=
167 (divider << CCK_FREQUENCY_STATUS_SHIFT),
168 "%s change in progress\n", name);
170 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
173 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
174 const char *name, u32 reg)
176 if (dev_priv->hpll_freq == 0)
177 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
179 return vlv_get_cck_clock(dev_priv, name, reg,
180 dev_priv->hpll_freq);
183 static void intel_update_czclk(struct drm_i915_private *dev_priv)
185 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
188 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
189 CCK_CZ_CLOCK_CONTROL);
191 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
194 static inline u32 /* units of 100MHz */
195 intel_fdi_link_freq(struct drm_i915_private *dev_priv,
196 const struct intel_crtc_state *pipe_config)
198 if (HAS_DDI(dev_priv))
199 return pipe_config->port_clock; /* SPLL */
201 return dev_priv->fdi_pll_freq;
204 static const struct intel_limit intel_limits_i8xx_dac = {
205 .dot = { .min = 25000, .max = 350000 },
206 .vco = { .min = 908000, .max = 1512000 },
207 .n = { .min = 2, .max = 16 },
208 .m = { .min = 96, .max = 140 },
209 .m1 = { .min = 18, .max = 26 },
210 .m2 = { .min = 6, .max = 16 },
211 .p = { .min = 4, .max = 128 },
212 .p1 = { .min = 2, .max = 33 },
213 .p2 = { .dot_limit = 165000,
214 .p2_slow = 4, .p2_fast = 2 },
217 static const struct intel_limit intel_limits_i8xx_dvo = {
218 .dot = { .min = 25000, .max = 350000 },
219 .vco = { .min = 908000, .max = 1512000 },
220 .n = { .min = 2, .max = 16 },
221 .m = { .min = 96, .max = 140 },
222 .m1 = { .min = 18, .max = 26 },
223 .m2 = { .min = 6, .max = 16 },
224 .p = { .min = 4, .max = 128 },
225 .p1 = { .min = 2, .max = 33 },
226 .p2 = { .dot_limit = 165000,
227 .p2_slow = 4, .p2_fast = 4 },
230 static const struct intel_limit intel_limits_i8xx_lvds = {
231 .dot = { .min = 25000, .max = 350000 },
232 .vco = { .min = 908000, .max = 1512000 },
233 .n = { .min = 2, .max = 16 },
234 .m = { .min = 96, .max = 140 },
235 .m1 = { .min = 18, .max = 26 },
236 .m2 = { .min = 6, .max = 16 },
237 .p = { .min = 4, .max = 128 },
238 .p1 = { .min = 1, .max = 6 },
239 .p2 = { .dot_limit = 165000,
240 .p2_slow = 14, .p2_fast = 7 },
243 static const struct intel_limit intel_limits_i9xx_sdvo = {
244 .dot = { .min = 20000, .max = 400000 },
245 .vco = { .min = 1400000, .max = 2800000 },
246 .n = { .min = 1, .max = 6 },
247 .m = { .min = 70, .max = 120 },
248 .m1 = { .min = 8, .max = 18 },
249 .m2 = { .min = 3, .max = 7 },
250 .p = { .min = 5, .max = 80 },
251 .p1 = { .min = 1, .max = 8 },
252 .p2 = { .dot_limit = 200000,
253 .p2_slow = 10, .p2_fast = 5 },
256 static const struct intel_limit intel_limits_i9xx_lvds = {
257 .dot = { .min = 20000, .max = 400000 },
258 .vco = { .min = 1400000, .max = 2800000 },
259 .n = { .min = 1, .max = 6 },
260 .m = { .min = 70, .max = 120 },
261 .m1 = { .min = 8, .max = 18 },
262 .m2 = { .min = 3, .max = 7 },
263 .p = { .min = 7, .max = 98 },
264 .p1 = { .min = 1, .max = 8 },
265 .p2 = { .dot_limit = 112000,
266 .p2_slow = 14, .p2_fast = 7 },
270 static const struct intel_limit intel_limits_g4x_sdvo = {
271 .dot = { .min = 25000, .max = 270000 },
272 .vco = { .min = 1750000, .max = 3500000},
273 .n = { .min = 1, .max = 4 },
274 .m = { .min = 104, .max = 138 },
275 .m1 = { .min = 17, .max = 23 },
276 .m2 = { .min = 5, .max = 11 },
277 .p = { .min = 10, .max = 30 },
278 .p1 = { .min = 1, .max = 3},
279 .p2 = { .dot_limit = 270000,
285 static const struct intel_limit intel_limits_g4x_hdmi = {
286 .dot = { .min = 22000, .max = 400000 },
287 .vco = { .min = 1750000, .max = 3500000},
288 .n = { .min = 1, .max = 4 },
289 .m = { .min = 104, .max = 138 },
290 .m1 = { .min = 16, .max = 23 },
291 .m2 = { .min = 5, .max = 11 },
292 .p = { .min = 5, .max = 80 },
293 .p1 = { .min = 1, .max = 8},
294 .p2 = { .dot_limit = 165000,
295 .p2_slow = 10, .p2_fast = 5 },
298 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
299 .dot = { .min = 20000, .max = 115000 },
300 .vco = { .min = 1750000, .max = 3500000 },
301 .n = { .min = 1, .max = 3 },
302 .m = { .min = 104, .max = 138 },
303 .m1 = { .min = 17, .max = 23 },
304 .m2 = { .min = 5, .max = 11 },
305 .p = { .min = 28, .max = 112 },
306 .p1 = { .min = 2, .max = 8 },
307 .p2 = { .dot_limit = 0,
308 .p2_slow = 14, .p2_fast = 14
312 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
313 .dot = { .min = 80000, .max = 224000 },
314 .vco = { .min = 1750000, .max = 3500000 },
315 .n = { .min = 1, .max = 3 },
316 .m = { .min = 104, .max = 138 },
317 .m1 = { .min = 17, .max = 23 },
318 .m2 = { .min = 5, .max = 11 },
319 .p = { .min = 14, .max = 42 },
320 .p1 = { .min = 2, .max = 6 },
321 .p2 = { .dot_limit = 0,
322 .p2_slow = 7, .p2_fast = 7
326 static const struct intel_limit intel_limits_pineview_sdvo = {
327 .dot = { .min = 20000, .max = 400000},
328 .vco = { .min = 1700000, .max = 3500000 },
329 /* Pineview's Ncounter is a ring counter */
330 .n = { .min = 3, .max = 6 },
331 .m = { .min = 2, .max = 256 },
332 /* Pineview only has one combined m divider, which we treat as m2. */
333 .m1 = { .min = 0, .max = 0 },
334 .m2 = { .min = 0, .max = 254 },
335 .p = { .min = 5, .max = 80 },
336 .p1 = { .min = 1, .max = 8 },
337 .p2 = { .dot_limit = 200000,
338 .p2_slow = 10, .p2_fast = 5 },
341 static const struct intel_limit intel_limits_pineview_lvds = {
342 .dot = { .min = 20000, .max = 400000 },
343 .vco = { .min = 1700000, .max = 3500000 },
344 .n = { .min = 3, .max = 6 },
345 .m = { .min = 2, .max = 256 },
346 .m1 = { .min = 0, .max = 0 },
347 .m2 = { .min = 0, .max = 254 },
348 .p = { .min = 7, .max = 112 },
349 .p1 = { .min = 1, .max = 8 },
350 .p2 = { .dot_limit = 112000,
351 .p2_slow = 14, .p2_fast = 14 },
354 /* Ironlake / Sandybridge
356 * We calculate clock using (register_value + 2) for N/M1/M2, so here
357 * the range value for them is (actual_value - 2).
359 static const struct intel_limit intel_limits_ironlake_dac = {
360 .dot = { .min = 25000, .max = 350000 },
361 .vco = { .min = 1760000, .max = 3510000 },
362 .n = { .min = 1, .max = 5 },
363 .m = { .min = 79, .max = 127 },
364 .m1 = { .min = 12, .max = 22 },
365 .m2 = { .min = 5, .max = 9 },
366 .p = { .min = 5, .max = 80 },
367 .p1 = { .min = 1, .max = 8 },
368 .p2 = { .dot_limit = 225000,
369 .p2_slow = 10, .p2_fast = 5 },
372 static const struct intel_limit intel_limits_ironlake_single_lvds = {
373 .dot = { .min = 25000, .max = 350000 },
374 .vco = { .min = 1760000, .max = 3510000 },
375 .n = { .min = 1, .max = 3 },
376 .m = { .min = 79, .max = 118 },
377 .m1 = { .min = 12, .max = 22 },
378 .m2 = { .min = 5, .max = 9 },
379 .p = { .min = 28, .max = 112 },
380 .p1 = { .min = 2, .max = 8 },
381 .p2 = { .dot_limit = 225000,
382 .p2_slow = 14, .p2_fast = 14 },
385 static const struct intel_limit intel_limits_ironlake_dual_lvds = {
386 .dot = { .min = 25000, .max = 350000 },
387 .vco = { .min = 1760000, .max = 3510000 },
388 .n = { .min = 1, .max = 3 },
389 .m = { .min = 79, .max = 127 },
390 .m1 = { .min = 12, .max = 22 },
391 .m2 = { .min = 5, .max = 9 },
392 .p = { .min = 14, .max = 56 },
393 .p1 = { .min = 2, .max = 8 },
394 .p2 = { .dot_limit = 225000,
395 .p2_slow = 7, .p2_fast = 7 },
398 /* LVDS 100mhz refclk limits. */
399 static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
400 .dot = { .min = 25000, .max = 350000 },
401 .vco = { .min = 1760000, .max = 3510000 },
402 .n = { .min = 1, .max = 2 },
403 .m = { .min = 79, .max = 126 },
404 .m1 = { .min = 12, .max = 22 },
405 .m2 = { .min = 5, .max = 9 },
406 .p = { .min = 28, .max = 112 },
407 .p1 = { .min = 2, .max = 8 },
408 .p2 = { .dot_limit = 225000,
409 .p2_slow = 14, .p2_fast = 14 },
412 static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
413 .dot = { .min = 25000, .max = 350000 },
414 .vco = { .min = 1760000, .max = 3510000 },
415 .n = { .min = 1, .max = 3 },
416 .m = { .min = 79, .max = 126 },
417 .m1 = { .min = 12, .max = 22 },
418 .m2 = { .min = 5, .max = 9 },
419 .p = { .min = 14, .max = 42 },
420 .p1 = { .min = 2, .max = 6 },
421 .p2 = { .dot_limit = 225000,
422 .p2_slow = 7, .p2_fast = 7 },
425 static const struct intel_limit intel_limits_vlv = {
427 * These are the data rate limits (measured in fast clocks)
428 * since those are the strictest limits we have. The fast
429 * clock and actual rate limits are more relaxed, so checking
430 * them would make no difference.
432 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
433 .vco = { .min = 4000000, .max = 6000000 },
434 .n = { .min = 1, .max = 7 },
435 .m1 = { .min = 2, .max = 3 },
436 .m2 = { .min = 11, .max = 156 },
437 .p1 = { .min = 2, .max = 3 },
438 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
441 static const struct intel_limit intel_limits_chv = {
443 * These are the data rate limits (measured in fast clocks)
444 * since those are the strictest limits we have. The fast
445 * clock and actual rate limits are more relaxed, so checking
446 * them would make no difference.
448 .dot = { .min = 25000 * 5, .max = 540000 * 5},
449 .vco = { .min = 4800000, .max = 6480000 },
450 .n = { .min = 1, .max = 1 },
451 .m1 = { .min = 2, .max = 2 },
452 .m2 = { .min = 24 << 22, .max = 175 << 22 },
453 .p1 = { .min = 2, .max = 4 },
454 .p2 = { .p2_slow = 1, .p2_fast = 14 },
457 static const struct intel_limit intel_limits_bxt = {
458 /* FIXME: find real dot limits */
459 .dot = { .min = 0, .max = INT_MAX },
460 .vco = { .min = 4800000, .max = 6700000 },
461 .n = { .min = 1, .max = 1 },
462 .m1 = { .min = 2, .max = 2 },
463 /* FIXME: find real m2 limits */
464 .m2 = { .min = 2 << 22, .max = 255 << 22 },
465 .p1 = { .min = 2, .max = 4 },
466 .p2 = { .p2_slow = 1, .p2_fast = 20 },
470 skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
473 I915_WRITE(CLKGATE_DIS_PSL(pipe),
474 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
476 I915_WRITE(CLKGATE_DIS_PSL(pipe),
477 I915_READ(CLKGATE_DIS_PSL(pipe)) &
478 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
482 needs_modeset(const struct drm_crtc_state *state)
484 return drm_atomic_crtc_needs_modeset(state);
488 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
489 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
490 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
491 * The helpers' return value is the rate of the clock that is fed to the
492 * display engine's pipe which can be the above fast dot clock rate or a
493 * divided-down version of it.
495 /* m1 is reserved as 0 in Pineview, n is a ring counter */
496 static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
498 clock->m = clock->m2 + 2;
499 clock->p = clock->p1 * clock->p2;
500 if (WARN_ON(clock->n == 0 || clock->p == 0))
502 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
503 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
508 static u32 i9xx_dpll_compute_m(struct dpll *dpll)
510 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
513 static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
515 clock->m = i9xx_dpll_compute_m(clock);
516 clock->p = clock->p1 * clock->p2;
517 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
519 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
520 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
525 static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
527 clock->m = clock->m1 * clock->m2;
528 clock->p = clock->p1 * clock->p2;
529 if (WARN_ON(clock->n == 0 || clock->p == 0))
531 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
532 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
534 return clock->dot / 5;
537 int chv_calc_dpll_params(int refclk, struct dpll *clock)
539 clock->m = clock->m1 * clock->m2;
540 clock->p = clock->p1 * clock->p2;
541 if (WARN_ON(clock->n == 0 || clock->p == 0))
543 clock->vco = DIV_ROUND_CLOSEST_ULL((u64)refclk * clock->m,
545 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
547 return clock->dot / 5;
550 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
553 * Returns whether the given set of divisors are valid for a given refclk with
554 * the given connectors.
556 static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
557 const struct intel_limit *limit,
558 const struct dpll *clock)
560 if (clock->n < limit->n.min || limit->n.max < clock->n)
561 INTELPllInvalid("n out of range\n");
562 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
563 INTELPllInvalid("p1 out of range\n");
564 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
565 INTELPllInvalid("m2 out of range\n");
566 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
567 INTELPllInvalid("m1 out of range\n");
569 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
570 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
571 if (clock->m1 <= clock->m2)
572 INTELPllInvalid("m1 <= m2\n");
574 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
575 !IS_GEN9_LP(dev_priv)) {
576 if (clock->p < limit->p.min || limit->p.max < clock->p)
577 INTELPllInvalid("p out of range\n");
578 if (clock->m < limit->m.min || limit->m.max < clock->m)
579 INTELPllInvalid("m out of range\n");
582 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
583 INTELPllInvalid("vco out of range\n");
584 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
585 * connector, etc., rather than just a single range.
587 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
588 INTELPllInvalid("dot out of range\n");
594 i9xx_select_p2_div(const struct intel_limit *limit,
595 const struct intel_crtc_state *crtc_state,
598 struct drm_device *dev = crtc_state->base.crtc->dev;
600 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
602 * For LVDS just rely on its current settings for dual-channel.
603 * We haven't figured out how to reliably set up different
604 * single/dual channel state, if we even can.
606 if (intel_is_dual_link_lvds(dev))
607 return limit->p2.p2_fast;
609 return limit->p2.p2_slow;
611 if (target < limit->p2.dot_limit)
612 return limit->p2.p2_slow;
614 return limit->p2.p2_fast;
619 * Returns a set of divisors for the desired target clock with the given
620 * refclk, or FALSE. The returned values represent the clock equation:
621 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
623 * Target and reference clocks are specified in kHz.
625 * If match_clock is provided, then best_clock P divider must match the P
626 * divider from @match_clock used for LVDS downclocking.
629 i9xx_find_best_dpll(const struct intel_limit *limit,
630 struct intel_crtc_state *crtc_state,
631 int target, int refclk, struct dpll *match_clock,
632 struct dpll *best_clock)
634 struct drm_device *dev = crtc_state->base.crtc->dev;
638 memset(best_clock, 0, sizeof(*best_clock));
640 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
642 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
644 for (clock.m2 = limit->m2.min;
645 clock.m2 <= limit->m2.max; clock.m2++) {
646 if (clock.m2 >= clock.m1)
648 for (clock.n = limit->n.min;
649 clock.n <= limit->n.max; clock.n++) {
650 for (clock.p1 = limit->p1.min;
651 clock.p1 <= limit->p1.max; clock.p1++) {
654 i9xx_calc_dpll_params(refclk, &clock);
655 if (!intel_PLL_is_valid(to_i915(dev),
660 clock.p != match_clock->p)
663 this_err = abs(clock.dot - target);
664 if (this_err < err) {
673 return (err != target);
677 * Returns a set of divisors for the desired target clock with the given
678 * refclk, or FALSE. The returned values represent the clock equation:
679 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
681 * Target and reference clocks are specified in kHz.
683 * If match_clock is provided, then best_clock P divider must match the P
684 * divider from @match_clock used for LVDS downclocking.
687 pnv_find_best_dpll(const struct intel_limit *limit,
688 struct intel_crtc_state *crtc_state,
689 int target, int refclk, struct dpll *match_clock,
690 struct dpll *best_clock)
692 struct drm_device *dev = crtc_state->base.crtc->dev;
696 memset(best_clock, 0, sizeof(*best_clock));
698 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
700 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
702 for (clock.m2 = limit->m2.min;
703 clock.m2 <= limit->m2.max; clock.m2++) {
704 for (clock.n = limit->n.min;
705 clock.n <= limit->n.max; clock.n++) {
706 for (clock.p1 = limit->p1.min;
707 clock.p1 <= limit->p1.max; clock.p1++) {
710 pnv_calc_dpll_params(refclk, &clock);
711 if (!intel_PLL_is_valid(to_i915(dev),
716 clock.p != match_clock->p)
719 this_err = abs(clock.dot - target);
720 if (this_err < err) {
729 return (err != target);
733 * Returns a set of divisors for the desired target clock with the given
734 * refclk, or FALSE. The returned values represent the clock equation:
735 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
737 * Target and reference clocks are specified in kHz.
739 * If match_clock is provided, then best_clock P divider must match the P
740 * divider from @match_clock used for LVDS downclocking.
743 g4x_find_best_dpll(const struct intel_limit *limit,
744 struct intel_crtc_state *crtc_state,
745 int target, int refclk, struct dpll *match_clock,
746 struct dpll *best_clock)
748 struct drm_device *dev = crtc_state->base.crtc->dev;
752 /* approximately equals target * 0.00585 */
753 int err_most = (target >> 8) + (target >> 9);
755 memset(best_clock, 0, sizeof(*best_clock));
757 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
759 max_n = limit->n.max;
760 /* based on hardware requirement, prefer smaller n to precision */
761 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
762 /* based on hardware requirement, prefere larger m1,m2 */
763 for (clock.m1 = limit->m1.max;
764 clock.m1 >= limit->m1.min; clock.m1--) {
765 for (clock.m2 = limit->m2.max;
766 clock.m2 >= limit->m2.min; clock.m2--) {
767 for (clock.p1 = limit->p1.max;
768 clock.p1 >= limit->p1.min; clock.p1--) {
771 i9xx_calc_dpll_params(refclk, &clock);
772 if (!intel_PLL_is_valid(to_i915(dev),
777 this_err = abs(clock.dot - target);
778 if (this_err < err_most) {
792 * Check if the calculated PLL configuration is more optimal compared to the
793 * best configuration and error found so far. Return the calculated error.
795 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
796 const struct dpll *calculated_clock,
797 const struct dpll *best_clock,
798 unsigned int best_error_ppm,
799 unsigned int *error_ppm)
802 * For CHV ignore the error and consider only the P value.
803 * Prefer a bigger P value based on HW requirements.
805 if (IS_CHERRYVIEW(to_i915(dev))) {
808 return calculated_clock->p > best_clock->p;
811 if (WARN_ON_ONCE(!target_freq))
814 *error_ppm = div_u64(1000000ULL *
815 abs(target_freq - calculated_clock->dot),
818 * Prefer a better P value over a better (smaller) error if the error
819 * is small. Ensure this preference for future configurations too by
820 * setting the error to 0.
822 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
828 return *error_ppm + 10 < best_error_ppm;
832 * Returns a set of divisors for the desired target clock with the given
833 * refclk, or FALSE. The returned values represent the clock equation:
834 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
837 vlv_find_best_dpll(const struct intel_limit *limit,
838 struct intel_crtc_state *crtc_state,
839 int target, int refclk, struct dpll *match_clock,
840 struct dpll *best_clock)
842 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
843 struct drm_device *dev = crtc->base.dev;
845 unsigned int bestppm = 1000000;
846 /* min update 19.2 MHz */
847 int max_n = min(limit->n.max, refclk / 19200);
850 target *= 5; /* fast clock */
852 memset(best_clock, 0, sizeof(*best_clock));
854 /* based on hardware requirement, prefer smaller n to precision */
855 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
856 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
857 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
858 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
859 clock.p = clock.p1 * clock.p2;
860 /* based on hardware requirement, prefer bigger m1,m2 values */
861 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
864 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
867 vlv_calc_dpll_params(refclk, &clock);
869 if (!intel_PLL_is_valid(to_i915(dev),
874 if (!vlv_PLL_is_optimal(dev, target,
892 * Returns a set of divisors for the desired target clock with the given
893 * refclk, or FALSE. The returned values represent the clock equation:
894 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
897 chv_find_best_dpll(const struct intel_limit *limit,
898 struct intel_crtc_state *crtc_state,
899 int target, int refclk, struct dpll *match_clock,
900 struct dpll *best_clock)
902 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
903 struct drm_device *dev = crtc->base.dev;
904 unsigned int best_error_ppm;
909 memset(best_clock, 0, sizeof(*best_clock));
910 best_error_ppm = 1000000;
913 * Based on hardware doc, the n always set to 1, and m1 always
914 * set to 2. If requires to support 200Mhz refclk, we need to
915 * revisit this because n may not 1 anymore.
917 clock.n = 1, clock.m1 = 2;
918 target *= 5; /* fast clock */
920 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
921 for (clock.p2 = limit->p2.p2_fast;
922 clock.p2 >= limit->p2.p2_slow;
923 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
924 unsigned int error_ppm;
926 clock.p = clock.p1 * clock.p2;
928 m2 = DIV_ROUND_CLOSEST_ULL(((u64)target * clock.p *
929 clock.n) << 22, refclk * clock.m1);
931 if (m2 > INT_MAX/clock.m1)
936 chv_calc_dpll_params(refclk, &clock);
938 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
941 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
942 best_error_ppm, &error_ppm))
946 best_error_ppm = error_ppm;
954 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
955 struct dpll *best_clock)
958 const struct intel_limit *limit = &intel_limits_bxt;
960 return chv_find_best_dpll(limit, crtc_state,
961 target_clock, refclk, NULL, best_clock);
964 bool intel_crtc_active(struct intel_crtc *crtc)
966 /* Be paranoid as we can arrive here with only partial
967 * state retrieved from the hardware during setup.
969 * We can ditch the adjusted_mode.crtc_clock check as soon
970 * as Haswell has gained clock readout/fastboot support.
972 * We can ditch the crtc->primary->state->fb check as soon as we can
973 * properly reconstruct framebuffers.
975 * FIXME: The intel_crtc->active here should be switched to
976 * crtc->state->active once we have proper CRTC states wired up
979 return crtc->active && crtc->base.primary->state->fb &&
980 crtc->config->base.adjusted_mode.crtc_clock;
983 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
986 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
988 return crtc->config->cpu_transcoder;
991 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
994 i915_reg_t reg = PIPEDSL(pipe);
998 if (IS_GEN(dev_priv, 2))
999 line_mask = DSL_LINEMASK_GEN2;
1001 line_mask = DSL_LINEMASK_GEN3;
1003 line1 = I915_READ(reg) & line_mask;
1005 line2 = I915_READ(reg) & line_mask;
1007 return line1 != line2;
1010 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1012 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1013 enum pipe pipe = crtc->pipe;
1015 /* Wait for the display line to settle/start moving */
1016 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1017 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1018 pipe_name(pipe), onoff(state));
1021 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1023 wait_for_pipe_scanline_moving(crtc, false);
1026 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1028 wait_for_pipe_scanline_moving(crtc, true);
1032 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
1034 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1035 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1037 if (INTEL_GEN(dev_priv) >= 4) {
1038 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1039 i915_reg_t reg = PIPECONF(cpu_transcoder);
1041 /* Wait for the Pipe State to go off */
1042 if (intel_wait_for_register(dev_priv,
1043 reg, I965_PIPECONF_ACTIVE, 0,
1045 WARN(1, "pipe_off wait timed out\n");
1047 intel_wait_for_pipe_scanline_stopped(crtc);
1051 /* Only for pre-ILK configs */
1052 void assert_pll(struct drm_i915_private *dev_priv,
1053 enum pipe pipe, bool state)
1058 val = I915_READ(DPLL(pipe));
1059 cur_state = !!(val & DPLL_VCO_ENABLE);
1060 I915_STATE_WARN(cur_state != state,
1061 "PLL state assertion failure (expected %s, current %s)\n",
1062 onoff(state), onoff(cur_state));
1065 /* XXX: the dsi pll is shared between MIPI DSI ports */
1066 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
1071 mutex_lock(&dev_priv->sb_lock);
1072 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1073 mutex_unlock(&dev_priv->sb_lock);
1075 cur_state = val & DSI_PLL_VCO_EN;
1076 I915_STATE_WARN(cur_state != state,
1077 "DSI PLL state assertion failure (expected %s, current %s)\n",
1078 onoff(state), onoff(cur_state));
1081 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1082 enum pipe pipe, bool state)
1085 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1088 if (HAS_DDI(dev_priv)) {
1089 /* DDI does not have a specific FDI_TX register */
1090 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1091 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1093 u32 val = I915_READ(FDI_TX_CTL(pipe));
1094 cur_state = !!(val & FDI_TX_ENABLE);
1096 I915_STATE_WARN(cur_state != state,
1097 "FDI TX state assertion failure (expected %s, current %s)\n",
1098 onoff(state), onoff(cur_state));
1100 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1101 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1103 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1104 enum pipe pipe, bool state)
1109 val = I915_READ(FDI_RX_CTL(pipe));
1110 cur_state = !!(val & FDI_RX_ENABLE);
1111 I915_STATE_WARN(cur_state != state,
1112 "FDI RX state assertion failure (expected %s, current %s)\n",
1113 onoff(state), onoff(cur_state));
1115 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1116 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1118 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1123 /* ILK FDI PLL is always enabled */
1124 if (IS_GEN(dev_priv, 5))
1127 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1128 if (HAS_DDI(dev_priv))
1131 val = I915_READ(FDI_TX_CTL(pipe));
1132 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1135 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1136 enum pipe pipe, bool state)
1141 val = I915_READ(FDI_RX_CTL(pipe));
1142 cur_state = !!(val & FDI_RX_PLL_ENABLE);
1143 I915_STATE_WARN(cur_state != state,
1144 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1145 onoff(state), onoff(cur_state));
1148 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
1152 enum pipe panel_pipe = INVALID_PIPE;
1155 if (WARN_ON(HAS_DDI(dev_priv)))
1158 if (HAS_PCH_SPLIT(dev_priv)) {
1161 pp_reg = PP_CONTROL(0);
1162 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1165 case PANEL_PORT_SELECT_LVDS:
1166 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1168 case PANEL_PORT_SELECT_DPA:
1169 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1171 case PANEL_PORT_SELECT_DPC:
1172 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1174 case PANEL_PORT_SELECT_DPD:
1175 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1178 MISSING_CASE(port_sel);
1181 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1182 /* presumably write lock depends on pipe, not port select */
1183 pp_reg = PP_CONTROL(pipe);
1188 pp_reg = PP_CONTROL(0);
1189 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1191 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
1192 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1195 val = I915_READ(pp_reg);
1196 if (!(val & PANEL_POWER_ON) ||
1197 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1200 I915_STATE_WARN(panel_pipe == pipe && locked,
1201 "panel assertion failure, pipe %c regs locked\n",
1205 void assert_pipe(struct drm_i915_private *dev_priv,
1206 enum pipe pipe, bool state)
1209 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1211 enum intel_display_power_domain power_domain;
1212 intel_wakeref_t wakeref;
1214 /* we keep both pipes enabled on 830 */
1215 if (IS_I830(dev_priv))
1218 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1219 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1221 u32 val = I915_READ(PIPECONF(cpu_transcoder));
1222 cur_state = !!(val & PIPECONF_ENABLE);
1224 intel_display_power_put(dev_priv, power_domain, wakeref);
1229 I915_STATE_WARN(cur_state != state,
1230 "pipe %c assertion failure (expected %s, current %s)\n",
1231 pipe_name(pipe), onoff(state), onoff(cur_state));
1234 static void assert_plane(struct intel_plane *plane, bool state)
1239 cur_state = plane->get_hw_state(plane, &pipe);
1241 I915_STATE_WARN(cur_state != state,
1242 "%s assertion failure (expected %s, current %s)\n",
1243 plane->base.name, onoff(state), onoff(cur_state));
1246 #define assert_plane_enabled(p) assert_plane(p, true)
1247 #define assert_plane_disabled(p) assert_plane(p, false)
1249 static void assert_planes_disabled(struct intel_crtc *crtc)
1251 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1252 struct intel_plane *plane;
1254 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1255 assert_plane_disabled(plane);
1258 static void assert_vblank_disabled(struct drm_crtc *crtc)
1260 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
1261 drm_crtc_vblank_put(crtc);
1264 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1270 val = I915_READ(PCH_TRANSCONF(pipe));
1271 enabled = !!(val & TRANS_ENABLE);
1272 I915_STATE_WARN(enabled,
1273 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1277 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1278 enum pipe pipe, enum port port,
1281 enum pipe port_pipe;
1284 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1286 I915_STATE_WARN(state && port_pipe == pipe,
1287 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1288 port_name(port), pipe_name(pipe));
1290 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1291 "IBX PCH DP %c still using transcoder B\n",
1295 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1296 enum pipe pipe, enum port port,
1297 i915_reg_t hdmi_reg)
1299 enum pipe port_pipe;
1302 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1304 I915_STATE_WARN(state && port_pipe == pipe,
1305 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1306 port_name(port), pipe_name(pipe));
1308 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1309 "IBX PCH HDMI %c still using transcoder B\n",
1313 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1316 enum pipe port_pipe;
1318 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1319 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1320 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
1322 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1324 "PCH VGA enabled on transcoder %c, should be disabled\n",
1327 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1329 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1332 /* PCH SDVOB multiplex with HDMIB */
1333 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1334 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1335 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
1338 static void _vlv_enable_pll(struct intel_crtc *crtc,
1339 const struct intel_crtc_state *pipe_config)
1341 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1342 enum pipe pipe = crtc->pipe;
1344 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1345 POSTING_READ(DPLL(pipe));
1348 if (intel_wait_for_register(dev_priv,
1353 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1356 static void vlv_enable_pll(struct intel_crtc *crtc,
1357 const struct intel_crtc_state *pipe_config)
1359 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1360 enum pipe pipe = crtc->pipe;
1362 assert_pipe_disabled(dev_priv, pipe);
1364 /* PLL is protected by panel, make sure we can write it */
1365 assert_panel_unlocked(dev_priv, pipe);
1367 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1368 _vlv_enable_pll(crtc, pipe_config);
1370 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1371 POSTING_READ(DPLL_MD(pipe));
1375 static void _chv_enable_pll(struct intel_crtc *crtc,
1376 const struct intel_crtc_state *pipe_config)
1378 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1379 enum pipe pipe = crtc->pipe;
1380 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1383 mutex_lock(&dev_priv->sb_lock);
1385 /* Enable back the 10bit clock to display controller */
1386 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1387 tmp |= DPIO_DCLKP_EN;
1388 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1390 mutex_unlock(&dev_priv->sb_lock);
1393 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1398 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1400 /* Check PLL is locked */
1401 if (intel_wait_for_register(dev_priv,
1402 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1404 DRM_ERROR("PLL %d failed to lock\n", pipe);
1407 static void chv_enable_pll(struct intel_crtc *crtc,
1408 const struct intel_crtc_state *pipe_config)
1410 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1411 enum pipe pipe = crtc->pipe;
1413 assert_pipe_disabled(dev_priv, pipe);
1415 /* PLL is protected by panel, make sure we can write it */
1416 assert_panel_unlocked(dev_priv, pipe);
1418 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1419 _chv_enable_pll(crtc, pipe_config);
1421 if (pipe != PIPE_A) {
1423 * WaPixelRepeatModeFixForC0:chv
1425 * DPLLCMD is AWOL. Use chicken bits to propagate
1426 * the value from DPLLBMD to either pipe B or C.
1428 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1429 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1430 I915_WRITE(CBR4_VLV, 0);
1431 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1434 * DPLLB VGA mode also seems to cause problems.
1435 * We should always have it disabled.
1437 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1439 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1440 POSTING_READ(DPLL_MD(pipe));
1444 static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
1446 struct intel_crtc *crtc;
1449 for_each_intel_crtc(&dev_priv->drm, crtc) {
1450 count += crtc->base.state->active &&
1451 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1457 static void i9xx_enable_pll(struct intel_crtc *crtc,
1458 const struct intel_crtc_state *crtc_state)
1460 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1461 i915_reg_t reg = DPLL(crtc->pipe);
1462 u32 dpll = crtc_state->dpll_hw_state.dpll;
1465 assert_pipe_disabled(dev_priv, crtc->pipe);
1467 /* PLL is protected by panel, make sure we can write it */
1468 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
1469 assert_panel_unlocked(dev_priv, crtc->pipe);
1471 /* Enable DVO 2x clock on both PLLs if necessary */
1472 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
1474 * It appears to be important that we don't enable this
1475 * for the current pipe before otherwise configuring the
1476 * PLL. No idea how this should be handled if multiple
1477 * DVO outputs are enabled simultaneosly.
1479 dpll |= DPLL_DVO_2X_MODE;
1480 I915_WRITE(DPLL(!crtc->pipe),
1481 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1485 * Apparently we need to have VGA mode enabled prior to changing
1486 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1487 * dividers, even though the register value does change.
1491 I915_WRITE(reg, dpll);
1493 /* Wait for the clocks to stabilize. */
1497 if (INTEL_GEN(dev_priv) >= 4) {
1498 I915_WRITE(DPLL_MD(crtc->pipe),
1499 crtc_state->dpll_hw_state.dpll_md);
1501 /* The pixel multiplier can only be updated once the
1502 * DPLL is enabled and the clocks are stable.
1504 * So write it again.
1506 I915_WRITE(reg, dpll);
1509 /* We do this three times for luck */
1510 for (i = 0; i < 3; i++) {
1511 I915_WRITE(reg, dpll);
1513 udelay(150); /* wait for warmup */
1517 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1519 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1520 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1521 enum pipe pipe = crtc->pipe;
1523 /* Disable DVO 2x clock on both PLLs if necessary */
1524 if (IS_I830(dev_priv) &&
1525 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
1526 !intel_num_dvo_pipes(dev_priv)) {
1527 I915_WRITE(DPLL(PIPE_B),
1528 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1529 I915_WRITE(DPLL(PIPE_A),
1530 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1533 /* Don't disable pipe or pipe PLLs if needed */
1534 if (IS_I830(dev_priv))
1537 /* Make sure the pipe isn't still relying on us */
1538 assert_pipe_disabled(dev_priv, pipe);
1540 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
1541 POSTING_READ(DPLL(pipe));
1544 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1548 /* Make sure the pipe isn't still relying on us */
1549 assert_pipe_disabled(dev_priv, pipe);
1551 val = DPLL_INTEGRATED_REF_CLK_VLV |
1552 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1554 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1556 I915_WRITE(DPLL(pipe), val);
1557 POSTING_READ(DPLL(pipe));
1560 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1562 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1565 /* Make sure the pipe isn't still relying on us */
1566 assert_pipe_disabled(dev_priv, pipe);
1568 val = DPLL_SSC_REF_CLK_CHV |
1569 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1571 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1573 I915_WRITE(DPLL(pipe), val);
1574 POSTING_READ(DPLL(pipe));
1576 mutex_lock(&dev_priv->sb_lock);
1578 /* Disable 10bit clock to display controller */
1579 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1580 val &= ~DPIO_DCLKP_EN;
1581 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1583 mutex_unlock(&dev_priv->sb_lock);
1586 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
1587 struct intel_digital_port *dport,
1588 unsigned int expected_mask)
1591 i915_reg_t dpll_reg;
1593 switch (dport->base.port) {
1595 port_mask = DPLL_PORTB_READY_MASK;
1599 port_mask = DPLL_PORTC_READY_MASK;
1601 expected_mask <<= 4;
1604 port_mask = DPLL_PORTD_READY_MASK;
1605 dpll_reg = DPIO_PHY_STATUS;
1611 if (intel_wait_for_register(dev_priv,
1612 dpll_reg, port_mask, expected_mask,
1614 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
1615 port_name(dport->base.port),
1616 I915_READ(dpll_reg) & port_mask, expected_mask);
1619 static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
1621 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1622 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1623 enum pipe pipe = crtc->pipe;
1625 u32 val, pipeconf_val;
1627 /* Make sure PCH DPLL is enabled */
1628 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
1630 /* FDI must be feeding us bits for PCH ports */
1631 assert_fdi_tx_enabled(dev_priv, pipe);
1632 assert_fdi_rx_enabled(dev_priv, pipe);
1634 if (HAS_PCH_CPT(dev_priv)) {
1635 /* Workaround: Set the timing override bit before enabling the
1636 * pch transcoder. */
1637 reg = TRANS_CHICKEN2(pipe);
1638 val = I915_READ(reg);
1639 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1640 I915_WRITE(reg, val);
1643 reg = PCH_TRANSCONF(pipe);
1644 val = I915_READ(reg);
1645 pipeconf_val = I915_READ(PIPECONF(pipe));
1647 if (HAS_PCH_IBX(dev_priv)) {
1649 * Make the BPC in transcoder be consistent with
1650 * that in pipeconf reg. For HDMI we must use 8bpc
1651 * here for both 8bpc and 12bpc.
1653 val &= ~PIPECONF_BPC_MASK;
1654 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1655 val |= PIPECONF_8BPC;
1657 val |= pipeconf_val & PIPECONF_BPC_MASK;
1660 val &= ~TRANS_INTERLACE_MASK;
1661 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1662 if (HAS_PCH_IBX(dev_priv) &&
1663 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
1664 val |= TRANS_LEGACY_INTERLACED_ILK;
1666 val |= TRANS_INTERLACED;
1668 val |= TRANS_PROGRESSIVE;
1670 I915_WRITE(reg, val | TRANS_ENABLE);
1671 if (intel_wait_for_register(dev_priv,
1672 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1674 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
1677 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1678 enum transcoder cpu_transcoder)
1680 u32 val, pipeconf_val;
1682 /* FDI must be feeding us bits for PCH ports */
1683 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1684 assert_fdi_rx_enabled(dev_priv, PIPE_A);
1686 /* Workaround: set timing override bit. */
1687 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1688 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1689 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1692 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1694 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1695 PIPECONF_INTERLACED_ILK)
1696 val |= TRANS_INTERLACED;
1698 val |= TRANS_PROGRESSIVE;
1700 I915_WRITE(LPT_TRANSCONF, val);
1701 if (intel_wait_for_register(dev_priv,
1706 DRM_ERROR("Failed to enable PCH transcoder\n");
1709 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1715 /* FDI relies on the transcoder */
1716 assert_fdi_tx_disabled(dev_priv, pipe);
1717 assert_fdi_rx_disabled(dev_priv, pipe);
1719 /* Ports must be off as well */
1720 assert_pch_ports_disabled(dev_priv, pipe);
1722 reg = PCH_TRANSCONF(pipe);
1723 val = I915_READ(reg);
1724 val &= ~TRANS_ENABLE;
1725 I915_WRITE(reg, val);
1726 /* wait for PCH transcoder off, transcoder state */
1727 if (intel_wait_for_register(dev_priv,
1728 reg, TRANS_STATE_ENABLE, 0,
1730 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
1732 if (HAS_PCH_CPT(dev_priv)) {
1733 /* Workaround: Clear the timing override chicken bit again. */
1734 reg = TRANS_CHICKEN2(pipe);
1735 val = I915_READ(reg);
1736 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1737 I915_WRITE(reg, val);
1741 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1745 val = I915_READ(LPT_TRANSCONF);
1746 val &= ~TRANS_ENABLE;
1747 I915_WRITE(LPT_TRANSCONF, val);
1748 /* wait for PCH transcoder off, transcoder state */
1749 if (intel_wait_for_register(dev_priv,
1750 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1752 DRM_ERROR("Failed to disable PCH transcoder\n");
1754 /* Workaround: clear timing override bit. */
1755 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
1756 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1757 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
1760 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
1762 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1764 if (HAS_PCH_LPT(dev_priv))
1770 static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1772 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1775 * On i965gm the hardware frame counter reads
1776 * zero when the TV encoder is enabled :(
1778 if (IS_I965GM(dev_priv) &&
1779 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1782 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1783 return 0xffffffff; /* full 32 bit counter */
1784 else if (INTEL_GEN(dev_priv) >= 3)
1785 return 0xffffff; /* only 24 bits of frame count */
1787 return 0; /* Gen2 doesn't have a hardware frame counter */
1790 static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1792 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1794 drm_crtc_set_max_vblank_count(&crtc->base,
1795 intel_crtc_max_vblank_count(crtc_state));
1796 drm_crtc_vblank_on(&crtc->base);
1799 static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
1801 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1802 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1803 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1804 enum pipe pipe = crtc->pipe;
1808 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1810 assert_planes_disabled(crtc);
1813 * A pipe without a PLL won't actually be able to drive bits from
1814 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1817 if (HAS_GMCH(dev_priv)) {
1818 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1819 assert_dsi_pll_enabled(dev_priv);
1821 assert_pll_enabled(dev_priv, pipe);
1823 if (new_crtc_state->has_pch_encoder) {
1824 /* if driving the PCH, we need FDI enabled */
1825 assert_fdi_rx_pll_enabled(dev_priv,
1826 intel_crtc_pch_transcoder(crtc));
1827 assert_fdi_tx_pll_enabled(dev_priv,
1828 (enum pipe) cpu_transcoder);
1830 /* FIXME: assert CPU port conditions for SNB+ */
1833 reg = PIPECONF(cpu_transcoder);
1834 val = I915_READ(reg);
1835 if (val & PIPECONF_ENABLE) {
1836 /* we keep both pipes enabled on 830 */
1837 WARN_ON(!IS_I830(dev_priv));
1841 I915_WRITE(reg, val | PIPECONF_ENABLE);
1845 * Until the pipe starts PIPEDSL reads will return a stale value,
1846 * which causes an apparent vblank timestamp jump when PIPEDSL
1847 * resets to its proper value. That also messes up the frame count
1848 * when it's derived from the timestamps. So let's wait for the
1849 * pipe to start properly before we call drm_crtc_vblank_on()
1851 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1852 intel_wait_for_pipe_scanline_moving(crtc);
1855 static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1857 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1858 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1859 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1860 enum pipe pipe = crtc->pipe;
1864 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1867 * Make sure planes won't keep trying to pump pixels to us,
1868 * or we might hang the display.
1870 assert_planes_disabled(crtc);
1872 reg = PIPECONF(cpu_transcoder);
1873 val = I915_READ(reg);
1874 if ((val & PIPECONF_ENABLE) == 0)
1878 * Double wide has implications for planes
1879 * so best keep it disabled when not needed.
1881 if (old_crtc_state->double_wide)
1882 val &= ~PIPECONF_DOUBLE_WIDE;
1884 /* Don't disable pipe or pipe PLLs if needed */
1885 if (!IS_I830(dev_priv))
1886 val &= ~PIPECONF_ENABLE;
1888 I915_WRITE(reg, val);
1889 if ((val & PIPECONF_ENABLE) == 0)
1890 intel_wait_for_pipe_off(old_crtc_state);
1893 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1895 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1899 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1901 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1902 unsigned int cpp = fb->format->cpp[color_plane];
1904 switch (fb->modifier) {
1905 case DRM_FORMAT_MOD_LINEAR:
1907 case I915_FORMAT_MOD_X_TILED:
1908 if (IS_GEN(dev_priv, 2))
1912 case I915_FORMAT_MOD_Y_TILED_CCS:
1913 if (color_plane == 1)
1916 case I915_FORMAT_MOD_Y_TILED:
1917 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
1921 case I915_FORMAT_MOD_Yf_TILED_CCS:
1922 if (color_plane == 1)
1925 case I915_FORMAT_MOD_Yf_TILED:
1941 MISSING_CASE(fb->modifier);
1947 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
1949 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
1952 return intel_tile_size(to_i915(fb->dev)) /
1953 intel_tile_width_bytes(fb, color_plane);
1956 /* Return the tile dimensions in pixel units */
1957 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
1958 unsigned int *tile_width,
1959 unsigned int *tile_height)
1961 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1962 unsigned int cpp = fb->format->cpp[color_plane];
1964 *tile_width = tile_width_bytes / cpp;
1965 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
1969 intel_fb_align_height(const struct drm_framebuffer *fb,
1970 int color_plane, unsigned int height)
1972 unsigned int tile_height = intel_tile_height(fb, color_plane);
1974 return ALIGN(height, tile_height);
1977 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1979 unsigned int size = 0;
1982 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1983 size += rot_info->plane[i].width * rot_info->plane[i].height;
1989 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1990 const struct drm_framebuffer *fb,
1991 unsigned int rotation)
1993 view->type = I915_GGTT_VIEW_NORMAL;
1994 if (drm_rotation_90_or_270(rotation)) {
1995 view->type = I915_GGTT_VIEW_ROTATED;
1996 view->rotated = to_intel_framebuffer(fb)->rot_info;
2000 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2002 if (IS_I830(dev_priv))
2004 else if (IS_I85X(dev_priv))
2006 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2012 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
2014 if (INTEL_GEN(dev_priv) >= 9)
2016 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
2017 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2019 else if (INTEL_GEN(dev_priv) >= 4)
2025 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
2028 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2030 /* AUX_DIST needs only 4K alignment */
2031 if (color_plane == 1)
2034 switch (fb->modifier) {
2035 case DRM_FORMAT_MOD_LINEAR:
2036 return intel_linear_alignment(dev_priv);
2037 case I915_FORMAT_MOD_X_TILED:
2038 if (INTEL_GEN(dev_priv) >= 9)
2041 case I915_FORMAT_MOD_Y_TILED_CCS:
2042 case I915_FORMAT_MOD_Yf_TILED_CCS:
2043 case I915_FORMAT_MOD_Y_TILED:
2044 case I915_FORMAT_MOD_Yf_TILED:
2045 return 1 * 1024 * 1024;
2047 MISSING_CASE(fb->modifier);
2052 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2054 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2055 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2057 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
2061 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
2062 const struct i915_ggtt_view *view,
2064 unsigned long *out_flags)
2066 struct drm_device *dev = fb->dev;
2067 struct drm_i915_private *dev_priv = to_i915(dev);
2068 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2069 intel_wakeref_t wakeref;
2070 struct i915_vma *vma;
2071 unsigned int pinctl;
2074 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2076 alignment = intel_surf_alignment(fb, 0);
2078 /* Note that the w/a also requires 64 PTE of padding following the
2079 * bo. We currently fill all unused PTE with the shadow page and so
2080 * we should always have valid PTE following the scanout preventing
2083 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
2084 alignment = 256 * 1024;
2087 * Global gtt pte registers are special registers which actually forward
2088 * writes to a chunk of system memory. Which means that there is no risk
2089 * that the register values disappear as soon as we call
2090 * intel_runtime_pm_put(), so it is correct to wrap only the
2091 * pin/unpin/fence and not more.
2093 wakeref = intel_runtime_pm_get(dev_priv);
2095 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2099 /* Valleyview is definitely limited to scanning out the first
2100 * 512MiB. Lets presume this behaviour was inherited from the
2101 * g4x display engine and that all earlier gen are similarly
2102 * limited. Testing suggests that it is a little more
2103 * complicated than this. For example, Cherryview appears quite
2104 * happy to scanout from anywhere within its global aperture.
2106 if (HAS_GMCH(dev_priv))
2107 pinctl |= PIN_MAPPABLE;
2109 vma = i915_gem_object_pin_to_display_plane(obj,
2110 alignment, view, pinctl);
2114 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
2117 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2118 * fence, whereas 965+ only requires a fence if using
2119 * framebuffer compression. For simplicity, we always, when
2120 * possible, install a fence as the cost is not that onerous.
2122 * If we fail to fence the tiled scanout, then either the
2123 * modeset will reject the change (which is highly unlikely as
2124 * the affected systems, all but one, do not have unmappable
2125 * space) or we will not be able to enable full powersaving
2126 * techniques (also likely not to apply due to various limits
2127 * FBC and the like impose on the size of the buffer, which
2128 * presumably we violated anyway with this unmappable buffer).
2129 * Anyway, it is presumably better to stumble onwards with
2130 * something and try to run the system in a "less than optimal"
2131 * mode that matches the user configuration.
2133 ret = i915_vma_pin_fence(vma);
2134 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
2135 i915_gem_object_unpin_from_display_plane(vma);
2140 if (ret == 0 && vma->fence)
2141 *out_flags |= PLANE_HAS_FENCE;
2146 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2148 intel_runtime_pm_put(dev_priv, wakeref);
2152 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
2154 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2156 if (flags & PLANE_HAS_FENCE)
2157 i915_vma_unpin_fence(vma);
2158 i915_gem_object_unpin_from_display_plane(vma);
2162 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
2163 unsigned int rotation)
2165 if (drm_rotation_90_or_270(rotation))
2166 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
2168 return fb->pitches[color_plane];
2172 * Convert the x/y offsets into a linear offset.
2173 * Only valid with 0/180 degree rotation, which is fine since linear
2174 * offset is only used with linear buffers on pre-hsw and tiled buffers
2175 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2177 u32 intel_fb_xy_to_linear(int x, int y,
2178 const struct intel_plane_state *state,
2181 const struct drm_framebuffer *fb = state->base.fb;
2182 unsigned int cpp = fb->format->cpp[color_plane];
2183 unsigned int pitch = state->color_plane[color_plane].stride;
2185 return y * pitch + x * cpp;
2189 * Add the x/y offsets derived from fb->offsets[] to the user
2190 * specified plane src x/y offsets. The resulting x/y offsets
2191 * specify the start of scanout from the beginning of the gtt mapping.
2193 void intel_add_fb_offsets(int *x, int *y,
2194 const struct intel_plane_state *state,
2198 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2199 unsigned int rotation = state->base.rotation;
2201 if (drm_rotation_90_or_270(rotation)) {
2202 *x += intel_fb->rotated[color_plane].x;
2203 *y += intel_fb->rotated[color_plane].y;
2205 *x += intel_fb->normal[color_plane].x;
2206 *y += intel_fb->normal[color_plane].y;
2210 static u32 intel_adjust_tile_offset(int *x, int *y,
2211 unsigned int tile_width,
2212 unsigned int tile_height,
2213 unsigned int tile_size,
2214 unsigned int pitch_tiles,
2218 unsigned int pitch_pixels = pitch_tiles * tile_width;
2221 WARN_ON(old_offset & (tile_size - 1));
2222 WARN_ON(new_offset & (tile_size - 1));
2223 WARN_ON(new_offset > old_offset);
2225 tiles = (old_offset - new_offset) / tile_size;
2227 *y += tiles / pitch_tiles * tile_height;
2228 *x += tiles % pitch_tiles * tile_width;
2230 /* minimize x in case it got needlessly big */
2231 *y += *x / pitch_pixels * tile_height;
2237 static bool is_surface_linear(u64 modifier, int color_plane)
2239 return modifier == DRM_FORMAT_MOD_LINEAR;
2242 static u32 intel_adjust_aligned_offset(int *x, int *y,
2243 const struct drm_framebuffer *fb,
2245 unsigned int rotation,
2247 u32 old_offset, u32 new_offset)
2249 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2250 unsigned int cpp = fb->format->cpp[color_plane];
2252 WARN_ON(new_offset > old_offset);
2254 if (!is_surface_linear(fb->modifier, color_plane)) {
2255 unsigned int tile_size, tile_width, tile_height;
2256 unsigned int pitch_tiles;
2258 tile_size = intel_tile_size(dev_priv);
2259 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2261 if (drm_rotation_90_or_270(rotation)) {
2262 pitch_tiles = pitch / tile_height;
2263 swap(tile_width, tile_height);
2265 pitch_tiles = pitch / (tile_width * cpp);
2268 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2269 tile_size, pitch_tiles,
2270 old_offset, new_offset);
2272 old_offset += *y * pitch + *x * cpp;
2274 *y = (old_offset - new_offset) / pitch;
2275 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2282 * Adjust the tile offset by moving the difference into
2285 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2286 const struct intel_plane_state *state,
2288 u32 old_offset, u32 new_offset)
2290 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
2291 state->base.rotation,
2292 state->color_plane[color_plane].stride,
2293 old_offset, new_offset);
2297 * Computes the aligned offset to the base tile and adjusts
2298 * x, y. bytes per pixel is assumed to be a power-of-two.
2300 * In the 90/270 rotated case, x and y are assumed
2301 * to be already rotated to match the rotated GTT view, and
2302 * pitch is the tile_height aligned framebuffer height.
2304 * This function is used when computing the derived information
2305 * under intel_framebuffer, so using any of that information
2306 * here is not allowed. Anything under drm_framebuffer can be
2307 * used. This is why the user has to pass in the pitch since it
2308 * is specified in the rotated orientation.
2310 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2312 const struct drm_framebuffer *fb,
2315 unsigned int rotation,
2318 unsigned int cpp = fb->format->cpp[color_plane];
2319 u32 offset, offset_aligned;
2324 if (!is_surface_linear(fb->modifier, color_plane)) {
2325 unsigned int tile_size, tile_width, tile_height;
2326 unsigned int tile_rows, tiles, pitch_tiles;
2328 tile_size = intel_tile_size(dev_priv);
2329 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
2331 if (drm_rotation_90_or_270(rotation)) {
2332 pitch_tiles = pitch / tile_height;
2333 swap(tile_width, tile_height);
2335 pitch_tiles = pitch / (tile_width * cpp);
2338 tile_rows = *y / tile_height;
2341 tiles = *x / tile_width;
2344 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2345 offset_aligned = offset & ~alignment;
2347 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2348 tile_size, pitch_tiles,
2349 offset, offset_aligned);
2351 offset = *y * pitch + *x * cpp;
2352 offset_aligned = offset & ~alignment;
2354 *y = (offset & alignment) / pitch;
2355 *x = ((offset & alignment) - *y * pitch) / cpp;
2358 return offset_aligned;
2361 static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2362 const struct intel_plane_state *state,
2365 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2366 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
2367 const struct drm_framebuffer *fb = state->base.fb;
2368 unsigned int rotation = state->base.rotation;
2369 int pitch = state->color_plane[color_plane].stride;
2372 if (intel_plane->id == PLANE_CURSOR)
2373 alignment = intel_cursor_alignment(dev_priv);
2375 alignment = intel_surf_alignment(fb, color_plane);
2377 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
2378 pitch, rotation, alignment);
2381 /* Convert the fb->offset[] into x/y offsets */
2382 static int intel_fb_offset_to_xy(int *x, int *y,
2383 const struct drm_framebuffer *fb,
2386 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2387 unsigned int height;
2389 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
2390 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2391 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2392 fb->offsets[color_plane], color_plane);
2396 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2397 height = ALIGN(height, intel_tile_height(fb, color_plane));
2399 /* Catch potential overflows early */
2400 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2401 fb->offsets[color_plane])) {
2402 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2403 fb->offsets[color_plane], fb->pitches[color_plane],
2411 intel_adjust_aligned_offset(x, y,
2412 fb, color_plane, DRM_MODE_ROTATE_0,
2413 fb->pitches[color_plane],
2414 fb->offsets[color_plane], 0);
2419 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
2421 switch (fb_modifier) {
2422 case I915_FORMAT_MOD_X_TILED:
2423 return I915_TILING_X;
2424 case I915_FORMAT_MOD_Y_TILED:
2425 case I915_FORMAT_MOD_Y_TILED_CCS:
2426 return I915_TILING_Y;
2428 return I915_TILING_NONE;
2433 * From the Sky Lake PRM:
2434 * "The Color Control Surface (CCS) contains the compression status of
2435 * the cache-line pairs. The compression state of the cache-line pair
2436 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2437 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2438 * cache-line-pairs. CCS is always Y tiled."
2440 * Since cache line pairs refers to horizontally adjacent cache lines,
2441 * each cache line in the CCS corresponds to an area of 32x16 cache
2442 * lines on the main surface. Since each pixel is 4 bytes, this gives
2443 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2446 static const struct drm_format_info ccs_formats[] = {
2447 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2448 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2449 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2450 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2453 static const struct drm_format_info *
2454 lookup_format_info(const struct drm_format_info formats[],
2455 int num_formats, u32 format)
2459 for (i = 0; i < num_formats; i++) {
2460 if (formats[i].format == format)
2467 static const struct drm_format_info *
2468 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2470 switch (cmd->modifier[0]) {
2471 case I915_FORMAT_MOD_Y_TILED_CCS:
2472 case I915_FORMAT_MOD_Yf_TILED_CCS:
2473 return lookup_format_info(ccs_formats,
2474 ARRAY_SIZE(ccs_formats),
2481 bool is_ccs_modifier(u64 modifier)
2483 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2484 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2488 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2489 struct drm_framebuffer *fb)
2491 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2492 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2493 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2494 u32 gtt_offset_rotated = 0;
2495 unsigned int max_size = 0;
2496 int i, num_planes = fb->format->num_planes;
2497 unsigned int tile_size = intel_tile_size(dev_priv);
2499 for (i = 0; i < num_planes; i++) {
2500 unsigned int width, height;
2501 unsigned int cpp, size;
2506 cpp = fb->format->cpp[i];
2507 width = drm_framebuffer_plane_width(fb->width, fb, i);
2508 height = drm_framebuffer_plane_height(fb->height, fb, i);
2510 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2512 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2517 if (is_ccs_modifier(fb->modifier) && i == 1) {
2518 int hsub = fb->format->hsub;
2519 int vsub = fb->format->vsub;
2520 int tile_width, tile_height;
2524 intel_tile_dims(fb, i, &tile_width, &tile_height);
2526 tile_height *= vsub;
2528 ccs_x = (x * hsub) % tile_width;
2529 ccs_y = (y * vsub) % tile_height;
2530 main_x = intel_fb->normal[0].x % tile_width;
2531 main_y = intel_fb->normal[0].y % tile_height;
2534 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2535 * x/y offsets must match between CCS and the main surface.
2537 if (main_x != ccs_x || main_y != ccs_y) {
2538 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2541 intel_fb->normal[0].x,
2542 intel_fb->normal[0].y,
2549 * The fence (if used) is aligned to the start of the object
2550 * so having the framebuffer wrap around across the edge of the
2551 * fenced region doesn't really work. We have no API to configure
2552 * the fence start offset within the object (nor could we probably
2553 * on gen2/3). So it's just easier if we just require that the
2554 * fb layout agrees with the fence layout. We already check that the
2555 * fb stride matches the fence stride elsewhere.
2557 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2558 (x + width) * cpp > fb->pitches[i]) {
2559 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2565 * First pixel of the framebuffer from
2566 * the start of the normal gtt mapping.
2568 intel_fb->normal[i].x = x;
2569 intel_fb->normal[i].y = y;
2571 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2575 offset /= tile_size;
2577 if (!is_surface_linear(fb->modifier, i)) {
2578 unsigned int tile_width, tile_height;
2579 unsigned int pitch_tiles;
2582 intel_tile_dims(fb, i, &tile_width, &tile_height);
2584 rot_info->plane[i].offset = offset;
2585 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2586 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2587 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2589 intel_fb->rotated[i].pitch =
2590 rot_info->plane[i].height * tile_height;
2592 /* how many tiles does this plane need */
2593 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2595 * If the plane isn't horizontally tile aligned,
2596 * we need one more tile.
2601 /* rotate the x/y offsets to match the GTT view */
2607 rot_info->plane[i].width * tile_width,
2608 rot_info->plane[i].height * tile_height,
2609 DRM_MODE_ROTATE_270);
2613 /* rotate the tile dimensions to match the GTT view */
2614 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2615 swap(tile_width, tile_height);
2618 * We only keep the x/y offsets, so push all of the
2619 * gtt offset into the x/y offsets.
2621 intel_adjust_tile_offset(&x, &y,
2622 tile_width, tile_height,
2623 tile_size, pitch_tiles,
2624 gtt_offset_rotated * tile_size, 0);
2626 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2629 * First pixel of the framebuffer from
2630 * the start of the rotated gtt mapping.
2632 intel_fb->rotated[i].x = x;
2633 intel_fb->rotated[i].y = y;
2635 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2636 x * cpp, tile_size);
2639 /* how many tiles in total needed in the bo */
2640 max_size = max(max_size, offset + size);
2643 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2644 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2645 mul_u32_u32(max_size, tile_size), obj->base.size);
2652 static int i9xx_format_to_fourcc(int format)
2655 case DISPPLANE_8BPP:
2656 return DRM_FORMAT_C8;
2657 case DISPPLANE_BGRX555:
2658 return DRM_FORMAT_XRGB1555;
2659 case DISPPLANE_BGRX565:
2660 return DRM_FORMAT_RGB565;
2662 case DISPPLANE_BGRX888:
2663 return DRM_FORMAT_XRGB8888;
2664 case DISPPLANE_RGBX888:
2665 return DRM_FORMAT_XBGR8888;
2666 case DISPPLANE_BGRX101010:
2667 return DRM_FORMAT_XRGB2101010;
2668 case DISPPLANE_RGBX101010:
2669 return DRM_FORMAT_XBGR2101010;
2673 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2676 case PLANE_CTL_FORMAT_RGB_565:
2677 return DRM_FORMAT_RGB565;
2678 case PLANE_CTL_FORMAT_NV12:
2679 return DRM_FORMAT_NV12;
2680 case PLANE_CTL_FORMAT_P010:
2681 return DRM_FORMAT_P010;
2682 case PLANE_CTL_FORMAT_P012:
2683 return DRM_FORMAT_P012;
2684 case PLANE_CTL_FORMAT_P016:
2685 return DRM_FORMAT_P016;
2686 case PLANE_CTL_FORMAT_Y210:
2687 return DRM_FORMAT_Y210;
2688 case PLANE_CTL_FORMAT_Y212:
2689 return DRM_FORMAT_Y212;
2690 case PLANE_CTL_FORMAT_Y216:
2691 return DRM_FORMAT_Y216;
2692 case PLANE_CTL_FORMAT_Y410:
2693 return DRM_FORMAT_XVYU2101010;
2694 case PLANE_CTL_FORMAT_Y412:
2695 return DRM_FORMAT_XVYU12_16161616;
2696 case PLANE_CTL_FORMAT_Y416:
2697 return DRM_FORMAT_XVYU16161616;
2699 case PLANE_CTL_FORMAT_XRGB_8888:
2702 return DRM_FORMAT_ABGR8888;
2704 return DRM_FORMAT_XBGR8888;
2707 return DRM_FORMAT_ARGB8888;
2709 return DRM_FORMAT_XRGB8888;
2711 case PLANE_CTL_FORMAT_XRGB_2101010:
2713 return DRM_FORMAT_XBGR2101010;
2715 return DRM_FORMAT_XRGB2101010;
2716 case PLANE_CTL_FORMAT_XRGB_16161616F:
2719 return DRM_FORMAT_ABGR16161616F;
2721 return DRM_FORMAT_XBGR16161616F;
2724 return DRM_FORMAT_ARGB16161616F;
2726 return DRM_FORMAT_XRGB16161616F;
2732 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2733 struct intel_initial_plane_config *plane_config)
2735 struct drm_device *dev = crtc->base.dev;
2736 struct drm_i915_private *dev_priv = to_i915(dev);
2737 struct drm_i915_gem_object *obj = NULL;
2738 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2739 struct drm_framebuffer *fb = &plane_config->fb->base;
2740 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2741 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2744 size_aligned -= base_aligned;
2746 if (plane_config->size == 0)
2749 /* If the FB is too big, just don't use it since fbdev is not very
2750 * important and we should probably use that space with FBC or other
2752 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2755 switch (fb->modifier) {
2756 case DRM_FORMAT_MOD_LINEAR:
2757 case I915_FORMAT_MOD_X_TILED:
2758 case I915_FORMAT_MOD_Y_TILED:
2761 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2766 mutex_lock(&dev->struct_mutex);
2767 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2771 mutex_unlock(&dev->struct_mutex);
2775 switch (plane_config->tiling) {
2776 case I915_TILING_NONE:
2780 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2783 MISSING_CASE(plane_config->tiling);
2787 mode_cmd.pixel_format = fb->format->format;
2788 mode_cmd.width = fb->width;
2789 mode_cmd.height = fb->height;
2790 mode_cmd.pitches[0] = fb->pitches[0];
2791 mode_cmd.modifier[0] = fb->modifier;
2792 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2794 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2795 DRM_DEBUG_KMS("intel fb init failed\n");
2800 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2804 i915_gem_object_put(obj);
2809 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2810 struct intel_plane_state *plane_state,
2813 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2815 plane_state->base.visible = visible;
2818 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
2820 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
2823 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2825 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2826 struct drm_plane *plane;
2829 * Active_planes aliases if multiple "primary" or cursor planes
2830 * have been used on the same (or wrong) pipe. plane_mask uses
2831 * unique ids, hence we can use that to reconstruct active_planes.
2833 crtc_state->active_planes = 0;
2835 drm_for_each_plane_mask(plane, &dev_priv->drm,
2836 crtc_state->base.plane_mask)
2837 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2840 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2841 struct intel_plane *plane)
2843 struct intel_crtc_state *crtc_state =
2844 to_intel_crtc_state(crtc->base.state);
2845 struct intel_plane_state *plane_state =
2846 to_intel_plane_state(plane->base.state);
2848 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2849 plane->base.base.id, plane->base.name,
2850 crtc->base.base.id, crtc->base.name);
2852 intel_set_plane_visible(crtc_state, plane_state, false);
2853 fixup_active_planes(crtc_state);
2855 if (plane->id == PLANE_PRIMARY)
2856 intel_pre_disable_primary_noatomic(&crtc->base);
2858 trace_intel_disable_plane(&plane->base, crtc);
2859 plane->disable_plane(plane, crtc_state);
2863 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2864 struct intel_initial_plane_config *plane_config)
2866 struct drm_device *dev = intel_crtc->base.dev;
2867 struct drm_i915_private *dev_priv = to_i915(dev);
2869 struct drm_i915_gem_object *obj;
2870 struct drm_plane *primary = intel_crtc->base.primary;
2871 struct drm_plane_state *plane_state = primary->state;
2872 struct intel_plane *intel_plane = to_intel_plane(primary);
2873 struct intel_plane_state *intel_state =
2874 to_intel_plane_state(plane_state);
2875 struct drm_framebuffer *fb;
2877 if (!plane_config->fb)
2880 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2881 fb = &plane_config->fb->base;
2885 kfree(plane_config->fb);
2888 * Failed to alloc the obj, check to see if we should share
2889 * an fb with another CRTC instead
2891 for_each_crtc(dev, c) {
2892 struct intel_plane_state *state;
2894 if (c == &intel_crtc->base)
2897 if (!to_intel_crtc(c)->active)
2900 state = to_intel_plane_state(c->primary->state);
2904 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2905 fb = state->base.fb;
2906 drm_framebuffer_get(fb);
2912 * We've failed to reconstruct the BIOS FB. Current display state
2913 * indicates that the primary plane is visible, but has a NULL FB,
2914 * which will lead to problems later if we don't fix it up. The
2915 * simplest solution is to just disable the primary plane now and
2916 * pretend the BIOS never had it enabled.
2918 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2923 intel_state->base.rotation = plane_config->rotation;
2924 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2925 intel_state->base.rotation);
2926 intel_state->color_plane[0].stride =
2927 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2929 mutex_lock(&dev->struct_mutex);
2931 intel_pin_and_fence_fb_obj(fb,
2933 intel_plane_uses_fence(intel_state),
2934 &intel_state->flags);
2935 mutex_unlock(&dev->struct_mutex);
2936 if (IS_ERR(intel_state->vma)) {
2937 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2938 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2940 intel_state->vma = NULL;
2941 drm_framebuffer_put(fb);
2945 obj = intel_fb_obj(fb);
2946 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2948 plane_state->src_x = 0;
2949 plane_state->src_y = 0;
2950 plane_state->src_w = fb->width << 16;
2951 plane_state->src_h = fb->height << 16;
2953 plane_state->crtc_x = 0;
2954 plane_state->crtc_y = 0;
2955 plane_state->crtc_w = fb->width;
2956 plane_state->crtc_h = fb->height;
2958 intel_state->base.src = drm_plane_state_src(plane_state);
2959 intel_state->base.dst = drm_plane_state_dest(plane_state);
2961 if (i915_gem_object_is_tiled(obj))
2962 dev_priv->preserve_bios_swizzle = true;
2964 plane_state->fb = fb;
2965 plane_state->crtc = &intel_crtc->base;
2967 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2968 &obj->frontbuffer_bits);
2971 static int skl_max_plane_width(const struct drm_framebuffer *fb,
2973 unsigned int rotation)
2975 int cpp = fb->format->cpp[color_plane];
2977 switch (fb->modifier) {
2978 case DRM_FORMAT_MOD_LINEAR:
2979 case I915_FORMAT_MOD_X_TILED:
2992 case I915_FORMAT_MOD_Y_TILED_CCS:
2993 case I915_FORMAT_MOD_Yf_TILED_CCS:
2994 /* FIXME AUX plane? */
2995 case I915_FORMAT_MOD_Y_TILED:
2996 case I915_FORMAT_MOD_Yf_TILED:
3011 MISSING_CASE(fb->modifier);
3017 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3018 int main_x, int main_y, u32 main_offset)
3020 const struct drm_framebuffer *fb = plane_state->base.fb;
3021 int hsub = fb->format->hsub;
3022 int vsub = fb->format->vsub;
3023 int aux_x = plane_state->color_plane[1].x;
3024 int aux_y = plane_state->color_plane[1].y;
3025 u32 aux_offset = plane_state->color_plane[1].offset;
3026 u32 alignment = intel_surf_alignment(fb, 1);
3028 while (aux_offset >= main_offset && aux_y <= main_y) {
3031 if (aux_x == main_x && aux_y == main_y)
3034 if (aux_offset == 0)
3039 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3040 aux_offset, aux_offset - alignment);
3041 aux_x = x * hsub + aux_x % hsub;
3042 aux_y = y * vsub + aux_y % vsub;
3045 if (aux_x != main_x || aux_y != main_y)
3048 plane_state->color_plane[1].offset = aux_offset;
3049 plane_state->color_plane[1].x = aux_x;
3050 plane_state->color_plane[1].y = aux_y;
3055 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3057 const struct drm_framebuffer *fb = plane_state->base.fb;
3058 unsigned int rotation = plane_state->base.rotation;
3059 int x = plane_state->base.src.x1 >> 16;
3060 int y = plane_state->base.src.y1 >> 16;
3061 int w = drm_rect_width(&plane_state->base.src) >> 16;
3062 int h = drm_rect_height(&plane_state->base.src) >> 16;
3063 int max_width = skl_max_plane_width(fb, 0, rotation);
3064 int max_height = 4096;
3065 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
3067 if (w > max_width || h > max_height) {
3068 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3069 w, h, max_width, max_height);
3073 intel_add_fb_offsets(&x, &y, plane_state, 0);
3074 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3075 alignment = intel_surf_alignment(fb, 0);
3078 * AUX surface offset is specified as the distance from the
3079 * main surface offset, and it must be non-negative. Make
3080 * sure that is what we will get.
3082 if (offset > aux_offset)
3083 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3084 offset, aux_offset & ~(alignment - 1));
3087 * When using an X-tiled surface, the plane blows up
3088 * if the x offset + width exceed the stride.
3090 * TODO: linear and Y-tiled seem fine, Yf untested,
3092 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3093 int cpp = fb->format->cpp[0];
3095 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3097 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3101 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3102 offset, offset - alignment);
3107 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3108 * they match with the main surface x/y offsets.
3110 if (is_ccs_modifier(fb->modifier)) {
3111 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3115 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3116 offset, offset - alignment);
3119 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3120 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3125 plane_state->color_plane[0].offset = offset;
3126 plane_state->color_plane[0].x = x;
3127 plane_state->color_plane[0].y = y;
3132 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3134 const struct drm_framebuffer *fb = plane_state->base.fb;
3135 unsigned int rotation = plane_state->base.rotation;
3136 int max_width = skl_max_plane_width(fb, 1, rotation);
3137 int max_height = 4096;
3138 int x = plane_state->base.src.x1 >> 17;
3139 int y = plane_state->base.src.y1 >> 17;
3140 int w = drm_rect_width(&plane_state->base.src) >> 17;
3141 int h = drm_rect_height(&plane_state->base.src) >> 17;
3144 intel_add_fb_offsets(&x, &y, plane_state, 1);
3145 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3147 /* FIXME not quite sure how/if these apply to the chroma plane */
3148 if (w > max_width || h > max_height) {
3149 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3150 w, h, max_width, max_height);
3154 plane_state->color_plane[1].offset = offset;
3155 plane_state->color_plane[1].x = x;
3156 plane_state->color_plane[1].y = y;
3161 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3163 const struct drm_framebuffer *fb = plane_state->base.fb;
3164 int src_x = plane_state->base.src.x1 >> 16;
3165 int src_y = plane_state->base.src.y1 >> 16;
3166 int hsub = fb->format->hsub;
3167 int vsub = fb->format->vsub;
3168 int x = src_x / hsub;
3169 int y = src_y / vsub;
3172 intel_add_fb_offsets(&x, &y, plane_state, 1);
3173 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3175 plane_state->color_plane[1].offset = offset;
3176 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3177 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3182 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3184 const struct drm_framebuffer *fb = plane_state->base.fb;
3185 unsigned int rotation = plane_state->base.rotation;
3188 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3189 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3190 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3192 ret = intel_plane_check_stride(plane_state);
3196 if (!plane_state->base.visible)
3199 /* Rotate src coordinates to match rotated GTT view */
3200 if (drm_rotation_90_or_270(rotation))
3201 drm_rect_rotate(&plane_state->base.src,
3202 fb->width << 16, fb->height << 16,
3203 DRM_MODE_ROTATE_270);
3206 * Handle the AUX surface first since
3207 * the main surface setup depends on it.
3209 if (is_planar_yuv_format(fb->format->format)) {
3210 ret = skl_check_nv12_aux_surface(plane_state);
3213 } else if (is_ccs_modifier(fb->modifier)) {
3214 ret = skl_check_ccs_aux_surface(plane_state);
3218 plane_state->color_plane[1].offset = ~0xfff;
3219 plane_state->color_plane[1].x = 0;
3220 plane_state->color_plane[1].y = 0;
3223 ret = skl_check_main_surface(plane_state);
3231 i9xx_plane_max_stride(struct intel_plane *plane,
3232 u32 pixel_format, u64 modifier,
3233 unsigned int rotation)
3235 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3237 if (!HAS_GMCH(dev_priv)) {
3239 } else if (INTEL_GEN(dev_priv) >= 4) {
3240 if (modifier == I915_FORMAT_MOD_X_TILED)
3244 } else if (INTEL_GEN(dev_priv) >= 3) {
3245 if (modifier == I915_FORMAT_MOD_X_TILED)
3250 if (plane->i9xx_plane == PLANE_C)
3257 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3259 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3260 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3263 dspcntr |= DISPPLANE_GAMMA_ENABLE;
3265 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3266 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3268 if (INTEL_GEN(dev_priv) < 5)
3269 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3274 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3275 const struct intel_plane_state *plane_state)
3277 struct drm_i915_private *dev_priv =
3278 to_i915(plane_state->base.plane->dev);
3279 const struct drm_framebuffer *fb = plane_state->base.fb;
3280 unsigned int rotation = plane_state->base.rotation;
3283 dspcntr = DISPLAY_PLANE_ENABLE;
3285 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3286 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
3287 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3289 switch (fb->format->format) {
3291 dspcntr |= DISPPLANE_8BPP;
3293 case DRM_FORMAT_XRGB1555:
3294 dspcntr |= DISPPLANE_BGRX555;
3296 case DRM_FORMAT_RGB565:
3297 dspcntr |= DISPPLANE_BGRX565;
3299 case DRM_FORMAT_XRGB8888:
3300 dspcntr |= DISPPLANE_BGRX888;
3302 case DRM_FORMAT_XBGR8888:
3303 dspcntr |= DISPPLANE_RGBX888;
3305 case DRM_FORMAT_XRGB2101010:
3306 dspcntr |= DISPPLANE_BGRX101010;
3308 case DRM_FORMAT_XBGR2101010:
3309 dspcntr |= DISPPLANE_RGBX101010;
3312 MISSING_CASE(fb->format->format);
3316 if (INTEL_GEN(dev_priv) >= 4 &&
3317 fb->modifier == I915_FORMAT_MOD_X_TILED)
3318 dspcntr |= DISPPLANE_TILED;
3320 if (rotation & DRM_MODE_ROTATE_180)
3321 dspcntr |= DISPPLANE_ROTATE_180;
3323 if (rotation & DRM_MODE_REFLECT_X)
3324 dspcntr |= DISPPLANE_MIRROR;
3329 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3331 struct drm_i915_private *dev_priv =
3332 to_i915(plane_state->base.plane->dev);
3333 const struct drm_framebuffer *fb = plane_state->base.fb;
3334 unsigned int rotation = plane_state->base.rotation;
3335 int src_x = plane_state->base.src.x1 >> 16;
3336 int src_y = plane_state->base.src.y1 >> 16;
3340 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3341 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3343 ret = intel_plane_check_stride(plane_state);
3347 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3349 if (INTEL_GEN(dev_priv) >= 4)
3350 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3355 /* HSW/BDW do this automagically in hardware */
3356 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3357 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3358 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3360 if (rotation & DRM_MODE_ROTATE_180) {
3363 } else if (rotation & DRM_MODE_REFLECT_X) {
3368 plane_state->color_plane[0].offset = offset;
3369 plane_state->color_plane[0].x = src_x;
3370 plane_state->color_plane[0].y = src_y;
3376 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3377 struct intel_plane_state *plane_state)
3381 ret = chv_plane_check_rotation(plane_state);
3385 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3387 DRM_PLANE_HELPER_NO_SCALING,
3388 DRM_PLANE_HELPER_NO_SCALING,
3393 if (!plane_state->base.visible)
3396 ret = intel_plane_check_src_coordinates(plane_state);
3400 ret = i9xx_check_plane_surface(plane_state);
3404 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3409 static void i9xx_update_plane(struct intel_plane *plane,
3410 const struct intel_crtc_state *crtc_state,
3411 const struct intel_plane_state *plane_state)
3413 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3414 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3416 int x = plane_state->color_plane[0].x;
3417 int y = plane_state->color_plane[0].y;
3418 unsigned long irqflags;
3422 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
3424 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3426 if (INTEL_GEN(dev_priv) >= 4)
3427 dspaddr_offset = plane_state->color_plane[0].offset;
3429 dspaddr_offset = linear_offset;
3431 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3433 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3435 if (INTEL_GEN(dev_priv) < 4) {
3436 /* pipesrc and dspsize control the size that is scaled from,
3437 * which should always be the user's requested size.
3439 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3440 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3441 ((crtc_state->pipe_src_h - 1) << 16) |
3442 (crtc_state->pipe_src_w - 1));
3443 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3444 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3445 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3446 ((crtc_state->pipe_src_h - 1) << 16) |
3447 (crtc_state->pipe_src_w - 1));
3448 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3451 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3452 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3453 } else if (INTEL_GEN(dev_priv) >= 4) {
3454 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3455 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3459 * The control register self-arms if the plane was previously
3460 * disabled. Try to make the plane enable atomic by writing
3461 * the control register just before the surface register.
3463 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3464 if (INTEL_GEN(dev_priv) >= 4)
3465 I915_WRITE_FW(DSPSURF(i9xx_plane),
3466 intel_plane_ggtt_offset(plane_state) +
3469 I915_WRITE_FW(DSPADDR(i9xx_plane),
3470 intel_plane_ggtt_offset(plane_state) +
3473 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3476 static void i9xx_disable_plane(struct intel_plane *plane,
3477 const struct intel_crtc_state *crtc_state)
3479 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3480 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3481 unsigned long irqflags;
3485 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
3486 * enable on ilk+ affect the pipe bottom color as
3487 * well, so we must configure them even if the plane
3490 * On pre-g4x there is no way to gamma correct the
3491 * pipe bottom color but we'll keep on doing this
3494 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
3496 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3498 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3499 if (INTEL_GEN(dev_priv) >= 4)
3500 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3502 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3504 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3507 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3510 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3511 enum intel_display_power_domain power_domain;
3512 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3513 intel_wakeref_t wakeref;
3518 * Not 100% correct for planes that can move between pipes,
3519 * but that's only the case for gen2-4 which don't have any
3520 * display power wells.
3522 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3523 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3527 val = I915_READ(DSPCNTR(i9xx_plane));
3529 ret = val & DISPLAY_PLANE_ENABLE;
3531 if (INTEL_GEN(dev_priv) >= 5)
3532 *pipe = plane->pipe;
3534 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3535 DISPPLANE_SEL_PIPE_SHIFT;
3537 intel_display_power_put(dev_priv, power_domain, wakeref);
3543 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
3545 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3548 return intel_tile_width_bytes(fb, color_plane);
3551 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3553 struct drm_device *dev = intel_crtc->base.dev;
3554 struct drm_i915_private *dev_priv = to_i915(dev);
3556 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3557 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3558 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3562 * This function detaches (aka. unbinds) unused scalers in hardware
3564 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
3566 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3567 const struct intel_crtc_scaler_state *scaler_state =
3568 &crtc_state->scaler_state;
3571 /* loop through and disable scalers that aren't in use */
3572 for (i = 0; i < intel_crtc->num_scalers; i++) {
3573 if (!scaler_state->scalers[i].in_use)
3574 skl_detach_scaler(intel_crtc, i);
3578 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3579 int color_plane, unsigned int rotation)
3582 * The stride is either expressed as a multiple of 64 bytes chunks for
3583 * linear buffers or in number of tiles for tiled buffers.
3585 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3587 else if (drm_rotation_90_or_270(rotation))
3588 return intel_tile_height(fb, color_plane);
3590 return intel_tile_width_bytes(fb, color_plane);
3593 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3596 const struct drm_framebuffer *fb = plane_state->base.fb;
3597 unsigned int rotation = plane_state->base.rotation;
3598 u32 stride = plane_state->color_plane[color_plane].stride;
3600 if (color_plane >= fb->format->num_planes)
3603 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
3606 static u32 skl_plane_ctl_format(u32 pixel_format)
3608 switch (pixel_format) {
3610 return PLANE_CTL_FORMAT_INDEXED;
3611 case DRM_FORMAT_RGB565:
3612 return PLANE_CTL_FORMAT_RGB_565;
3613 case DRM_FORMAT_XBGR8888:
3614 case DRM_FORMAT_ABGR8888:
3615 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3616 case DRM_FORMAT_XRGB8888:
3617 case DRM_FORMAT_ARGB8888:
3618 return PLANE_CTL_FORMAT_XRGB_8888;
3619 case DRM_FORMAT_XRGB2101010:
3620 return PLANE_CTL_FORMAT_XRGB_2101010;
3621 case DRM_FORMAT_XBGR2101010:
3622 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3623 case DRM_FORMAT_XBGR16161616F:
3624 case DRM_FORMAT_ABGR16161616F:
3625 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
3626 case DRM_FORMAT_XRGB16161616F:
3627 case DRM_FORMAT_ARGB16161616F:
3628 return PLANE_CTL_FORMAT_XRGB_16161616F;
3629 case DRM_FORMAT_YUYV:
3630 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3631 case DRM_FORMAT_YVYU:
3632 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3633 case DRM_FORMAT_UYVY:
3634 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3635 case DRM_FORMAT_VYUY:
3636 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3637 case DRM_FORMAT_NV12:
3638 return PLANE_CTL_FORMAT_NV12;
3639 case DRM_FORMAT_P010:
3640 return PLANE_CTL_FORMAT_P010;
3641 case DRM_FORMAT_P012:
3642 return PLANE_CTL_FORMAT_P012;
3643 case DRM_FORMAT_P016:
3644 return PLANE_CTL_FORMAT_P016;
3645 case DRM_FORMAT_Y210:
3646 return PLANE_CTL_FORMAT_Y210;
3647 case DRM_FORMAT_Y212:
3648 return PLANE_CTL_FORMAT_Y212;
3649 case DRM_FORMAT_Y216:
3650 return PLANE_CTL_FORMAT_Y216;
3651 case DRM_FORMAT_XVYU2101010:
3652 return PLANE_CTL_FORMAT_Y410;
3653 case DRM_FORMAT_XVYU12_16161616:
3654 return PLANE_CTL_FORMAT_Y412;
3655 case DRM_FORMAT_XVYU16161616:
3656 return PLANE_CTL_FORMAT_Y416;
3658 MISSING_CASE(pixel_format);
3664 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
3666 if (!plane_state->base.fb->format->has_alpha)
3667 return PLANE_CTL_ALPHA_DISABLE;
3669 switch (plane_state->base.pixel_blend_mode) {
3670 case DRM_MODE_BLEND_PIXEL_NONE:
3671 return PLANE_CTL_ALPHA_DISABLE;
3672 case DRM_MODE_BLEND_PREMULTI:
3673 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3674 case DRM_MODE_BLEND_COVERAGE:
3675 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
3677 MISSING_CASE(plane_state->base.pixel_blend_mode);
3678 return PLANE_CTL_ALPHA_DISABLE;
3682 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
3684 if (!plane_state->base.fb->format->has_alpha)
3685 return PLANE_COLOR_ALPHA_DISABLE;
3687 switch (plane_state->base.pixel_blend_mode) {
3688 case DRM_MODE_BLEND_PIXEL_NONE:
3689 return PLANE_COLOR_ALPHA_DISABLE;
3690 case DRM_MODE_BLEND_PREMULTI:
3691 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3692 case DRM_MODE_BLEND_COVERAGE:
3693 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
3695 MISSING_CASE(plane_state->base.pixel_blend_mode);
3696 return PLANE_COLOR_ALPHA_DISABLE;
3700 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
3702 switch (fb_modifier) {
3703 case DRM_FORMAT_MOD_LINEAR:
3705 case I915_FORMAT_MOD_X_TILED:
3706 return PLANE_CTL_TILED_X;
3707 case I915_FORMAT_MOD_Y_TILED:
3708 return PLANE_CTL_TILED_Y;
3709 case I915_FORMAT_MOD_Y_TILED_CCS:
3710 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3711 case I915_FORMAT_MOD_Yf_TILED:
3712 return PLANE_CTL_TILED_YF;
3713 case I915_FORMAT_MOD_Yf_TILED_CCS:
3714 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3716 MISSING_CASE(fb_modifier);
3722 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3725 case DRM_MODE_ROTATE_0:
3728 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3729 * while i915 HW rotation is clockwise, thats why this swapping.
3731 case DRM_MODE_ROTATE_90:
3732 return PLANE_CTL_ROTATE_270;
3733 case DRM_MODE_ROTATE_180:
3734 return PLANE_CTL_ROTATE_180;
3735 case DRM_MODE_ROTATE_270:
3736 return PLANE_CTL_ROTATE_90;
3738 MISSING_CASE(rotate);
3744 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3749 case DRM_MODE_REFLECT_X:
3750 return PLANE_CTL_FLIP_HORIZONTAL;
3751 case DRM_MODE_REFLECT_Y:
3753 MISSING_CASE(reflect);
3759 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3761 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3764 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3767 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
3768 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
3773 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3774 const struct intel_plane_state *plane_state)
3776 struct drm_i915_private *dev_priv =
3777 to_i915(plane_state->base.plane->dev);
3778 const struct drm_framebuffer *fb = plane_state->base.fb;
3779 unsigned int rotation = plane_state->base.rotation;
3780 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3783 plane_ctl = PLANE_CTL_ENABLE;
3785 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3786 plane_ctl |= skl_plane_ctl_alpha(plane_state);
3787 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
3789 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3790 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3792 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3793 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3796 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3797 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3798 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3800 if (INTEL_GEN(dev_priv) >= 10)
3801 plane_ctl |= cnl_plane_ctl_flip(rotation &
3802 DRM_MODE_REFLECT_MASK);
3804 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3805 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3806 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3807 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3812 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
3814 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3815 u32 plane_color_ctl = 0;
3817 if (INTEL_GEN(dev_priv) >= 11)
3818 return plane_color_ctl;
3820 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3821 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3823 return plane_color_ctl;
3826 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3827 const struct intel_plane_state *plane_state)
3829 struct drm_i915_private *dev_priv =
3830 to_i915(plane_state->base.plane->dev);
3831 const struct drm_framebuffer *fb = plane_state->base.fb;
3832 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3833 u32 plane_color_ctl = 0;
3835 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3836 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
3838 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
3839 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3840 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3842 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
3844 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3845 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3846 } else if (fb->format->is_yuv) {
3847 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
3850 return plane_color_ctl;
3854 __intel_display_resume(struct drm_device *dev,
3855 struct drm_atomic_state *state,
3856 struct drm_modeset_acquire_ctx *ctx)
3858 struct drm_crtc_state *crtc_state;
3859 struct drm_crtc *crtc;
3862 intel_modeset_setup_hw_state(dev, ctx);
3863 i915_redisable_vga(to_i915(dev));
3869 * We've duplicated the state, pointers to the old state are invalid.
3871 * Don't attempt to use the old state until we commit the duplicated state.
3873 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3875 * Force recalculation even if we restore
3876 * current state. With fast modeset this may not result
3877 * in a modeset when the state is compatible.
3879 crtc_state->mode_changed = true;
3882 /* ignore any reset values/BIOS leftovers in the WM registers */
3883 if (!HAS_GMCH(to_i915(dev)))
3884 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3886 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3888 WARN_ON(ret == -EDEADLK);
3892 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3894 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
3895 intel_has_gpu_reset(dev_priv));
3898 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3900 struct drm_device *dev = &dev_priv->drm;
3901 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3902 struct drm_atomic_state *state;
3905 /* reset doesn't touch the display */
3906 if (!i915_modparams.force_reset_modeset_test &&
3907 !gpu_reset_clobbers_display(dev_priv))
3910 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3911 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3912 wake_up_all(&dev_priv->gpu_error.wait_queue);
3914 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3915 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3916 i915_gem_set_wedged(dev_priv);
3920 * Need mode_config.mutex so that we don't
3921 * trample ongoing ->detect() and whatnot.
3923 mutex_lock(&dev->mode_config.mutex);
3924 drm_modeset_acquire_init(ctx, 0);
3926 ret = drm_modeset_lock_all_ctx(dev, ctx);
3927 if (ret != -EDEADLK)
3930 drm_modeset_backoff(ctx);
3933 * Disabling the crtcs gracefully seems nicer. Also the
3934 * g33 docs say we should at least disable all the planes.
3936 state = drm_atomic_helper_duplicate_state(dev, ctx);
3937 if (IS_ERR(state)) {
3938 ret = PTR_ERR(state);
3939 DRM_ERROR("Duplicating state failed with %i\n", ret);
3943 ret = drm_atomic_helper_disable_all(dev, ctx);
3945 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3946 drm_atomic_state_put(state);
3950 dev_priv->modeset_restore_state = state;
3951 state->acquire_ctx = ctx;
3954 void intel_finish_reset(struct drm_i915_private *dev_priv)
3956 struct drm_device *dev = &dev_priv->drm;
3957 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3958 struct drm_atomic_state *state;
3961 /* reset doesn't touch the display */
3962 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
3965 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3969 /* reset doesn't touch the display */
3970 if (!gpu_reset_clobbers_display(dev_priv)) {
3971 /* for testing only restore the display */
3972 ret = __intel_display_resume(dev, state, ctx);
3974 DRM_ERROR("Restoring old state failed with %i\n", ret);
3977 * The display has been reset as well,
3978 * so need a full re-initialization.
3980 intel_runtime_pm_disable_interrupts(dev_priv);
3981 intel_runtime_pm_enable_interrupts(dev_priv);
3983 intel_pps_unlock_regs_wa(dev_priv);
3984 intel_modeset_init_hw(dev);
3985 intel_init_clock_gating(dev_priv);
3987 spin_lock_irq(&dev_priv->irq_lock);
3988 if (dev_priv->display.hpd_irq_setup)
3989 dev_priv->display.hpd_irq_setup(dev_priv);
3990 spin_unlock_irq(&dev_priv->irq_lock);
3992 ret = __intel_display_resume(dev, state, ctx);
3994 DRM_ERROR("Restoring old state failed with %i\n", ret);
3996 intel_hpd_init(dev_priv);
3999 drm_atomic_state_put(state);
4001 drm_modeset_drop_locks(ctx);
4002 drm_modeset_acquire_fini(ctx);
4003 mutex_unlock(&dev->mode_config.mutex);
4005 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
4008 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
4010 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4011 enum pipe pipe = crtc->pipe;
4014 tmp = I915_READ(PIPE_CHICKEN(pipe));
4017 * Display WA #1153: icl
4018 * enable hardware to bypass the alpha math
4019 * and rounding for per-pixel values 00 and 0xff
4021 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4024 * W/A for underruns with linear/X-tiled with
4027 tmp |= PM_FILL_MAINTAIN_DBUF_FULLNESS;
4029 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4032 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
4033 const struct intel_crtc_state *new_crtc_state)
4035 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
4036 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4038 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
4039 crtc->base.mode = new_crtc_state->base.mode;
4042 * Update pipe size and adjust fitter if needed: the reason for this is
4043 * that in compute_mode_changes we check the native mode (not the pfit
4044 * mode) to see if we can flip rather than do a full mode set. In the
4045 * fastboot case, we'll flip, but if we don't update the pipesrc and
4046 * pfit state, we'll end up with a big fb scanned out into the wrong
4050 I915_WRITE(PIPESRC(crtc->pipe),
4051 ((new_crtc_state->pipe_src_w - 1) << 16) |
4052 (new_crtc_state->pipe_src_h - 1));
4054 /* on skylake this is done by detaching scalers */
4055 if (INTEL_GEN(dev_priv) >= 9) {
4056 skl_detach_scalers(new_crtc_state);
4058 if (new_crtc_state->pch_pfit.enabled)
4059 skylake_pfit_enable(new_crtc_state);
4060 } else if (HAS_PCH_SPLIT(dev_priv)) {
4061 if (new_crtc_state->pch_pfit.enabled)
4062 ironlake_pfit_enable(new_crtc_state);
4063 else if (old_crtc_state->pch_pfit.enabled)
4064 ironlake_pfit_disable(old_crtc_state);
4068 * We don't (yet) allow userspace to control the pipe background color,
4069 * so force it to black, but apply pipe gamma and CSC so that its
4070 * handling will match how we program our planes.
4072 if (INTEL_GEN(dev_priv) >= 9)
4073 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
4074 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
4075 SKL_BOTTOM_COLOR_CSC_ENABLE);
4077 if (INTEL_GEN(dev_priv) >= 11)
4078 icl_set_pipe_chicken(crtc);
4081 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4083 struct drm_device *dev = crtc->base.dev;
4084 struct drm_i915_private *dev_priv = to_i915(dev);
4085 int pipe = crtc->pipe;
4089 /* enable normal train */
4090 reg = FDI_TX_CTL(pipe);
4091 temp = I915_READ(reg);
4092 if (IS_IVYBRIDGE(dev_priv)) {
4093 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4094 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4096 temp &= ~FDI_LINK_TRAIN_NONE;
4097 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4099 I915_WRITE(reg, temp);
4101 reg = FDI_RX_CTL(pipe);
4102 temp = I915_READ(reg);
4103 if (HAS_PCH_CPT(dev_priv)) {
4104 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4105 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4107 temp &= ~FDI_LINK_TRAIN_NONE;
4108 temp |= FDI_LINK_TRAIN_NONE;
4110 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4112 /* wait one idle pattern time */
4116 /* IVB wants error correction enabled */
4117 if (IS_IVYBRIDGE(dev_priv))
4118 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4119 FDI_FE_ERRC_ENABLE);
4122 /* The FDI link training functions for ILK/Ibexpeak. */
4123 static void ironlake_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 /* FDI needs bits from pipe first */
4133 assert_pipe_enabled(dev_priv, pipe);
4135 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4137 reg = FDI_RX_IMR(pipe);
4138 temp = I915_READ(reg);
4139 temp &= ~FDI_RX_SYMBOL_LOCK;
4140 temp &= ~FDI_RX_BIT_LOCK;
4141 I915_WRITE(reg, temp);
4145 /* enable CPU FDI TX and PCH FDI RX */
4146 reg = FDI_TX_CTL(pipe);
4147 temp = I915_READ(reg);
4148 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4149 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4150 temp &= ~FDI_LINK_TRAIN_NONE;
4151 temp |= FDI_LINK_TRAIN_PATTERN_1;
4152 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4154 reg = FDI_RX_CTL(pipe);
4155 temp = I915_READ(reg);
4156 temp &= ~FDI_LINK_TRAIN_NONE;
4157 temp |= FDI_LINK_TRAIN_PATTERN_1;
4158 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4163 /* Ironlake workaround, enable clock pointer after FDI enable*/
4164 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4165 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4166 FDI_RX_PHASE_SYNC_POINTER_EN);
4168 reg = FDI_RX_IIR(pipe);
4169 for (tries = 0; tries < 5; tries++) {
4170 temp = I915_READ(reg);
4171 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4173 if ((temp & FDI_RX_BIT_LOCK)) {
4174 DRM_DEBUG_KMS("FDI train 1 done.\n");
4175 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4180 DRM_ERROR("FDI train 1 fail!\n");
4183 reg = FDI_TX_CTL(pipe);
4184 temp = I915_READ(reg);
4185 temp &= ~FDI_LINK_TRAIN_NONE;
4186 temp |= FDI_LINK_TRAIN_PATTERN_2;
4187 I915_WRITE(reg, temp);
4189 reg = FDI_RX_CTL(pipe);
4190 temp = I915_READ(reg);
4191 temp &= ~FDI_LINK_TRAIN_NONE;
4192 temp |= FDI_LINK_TRAIN_PATTERN_2;
4193 I915_WRITE(reg, temp);
4198 reg = FDI_RX_IIR(pipe);
4199 for (tries = 0; tries < 5; tries++) {
4200 temp = I915_READ(reg);
4201 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4203 if (temp & FDI_RX_SYMBOL_LOCK) {
4204 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4205 DRM_DEBUG_KMS("FDI train 2 done.\n");
4210 DRM_ERROR("FDI train 2 fail!\n");
4212 DRM_DEBUG_KMS("FDI train done\n");
4216 static const int snb_b_fdi_train_param[] = {
4217 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4218 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4219 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4220 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4223 /* The FDI link training functions for SNB/Cougarpoint. */
4224 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4225 const struct intel_crtc_state *crtc_state)
4227 struct drm_device *dev = crtc->base.dev;
4228 struct drm_i915_private *dev_priv = to_i915(dev);
4229 int pipe = crtc->pipe;
4233 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4235 reg = FDI_RX_IMR(pipe);
4236 temp = I915_READ(reg);
4237 temp &= ~FDI_RX_SYMBOL_LOCK;
4238 temp &= ~FDI_RX_BIT_LOCK;
4239 I915_WRITE(reg, temp);
4244 /* enable CPU FDI TX and PCH FDI RX */
4245 reg = FDI_TX_CTL(pipe);
4246 temp = I915_READ(reg);
4247 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4248 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4249 temp &= ~FDI_LINK_TRAIN_NONE;
4250 temp |= FDI_LINK_TRAIN_PATTERN_1;
4251 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4253 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4254 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4256 I915_WRITE(FDI_RX_MISC(pipe),
4257 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4259 reg = FDI_RX_CTL(pipe);
4260 temp = I915_READ(reg);
4261 if (HAS_PCH_CPT(dev_priv)) {
4262 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4263 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4265 temp &= ~FDI_LINK_TRAIN_NONE;
4266 temp |= FDI_LINK_TRAIN_PATTERN_1;
4268 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4273 for (i = 0; i < 4; i++) {
4274 reg = FDI_TX_CTL(pipe);
4275 temp = I915_READ(reg);
4276 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4277 temp |= snb_b_fdi_train_param[i];
4278 I915_WRITE(reg, temp);
4283 for (retry = 0; retry < 5; retry++) {
4284 reg = FDI_RX_IIR(pipe);
4285 temp = I915_READ(reg);
4286 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4287 if (temp & FDI_RX_BIT_LOCK) {
4288 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4289 DRM_DEBUG_KMS("FDI train 1 done.\n");
4298 DRM_ERROR("FDI train 1 fail!\n");
4301 reg = FDI_TX_CTL(pipe);
4302 temp = I915_READ(reg);
4303 temp &= ~FDI_LINK_TRAIN_NONE;
4304 temp |= FDI_LINK_TRAIN_PATTERN_2;
4305 if (IS_GEN(dev_priv, 6)) {
4306 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4308 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4310 I915_WRITE(reg, temp);
4312 reg = FDI_RX_CTL(pipe);
4313 temp = I915_READ(reg);
4314 if (HAS_PCH_CPT(dev_priv)) {
4315 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4316 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4318 temp &= ~FDI_LINK_TRAIN_NONE;
4319 temp |= FDI_LINK_TRAIN_PATTERN_2;
4321 I915_WRITE(reg, temp);
4326 for (i = 0; i < 4; i++) {
4327 reg = FDI_TX_CTL(pipe);
4328 temp = I915_READ(reg);
4329 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4330 temp |= snb_b_fdi_train_param[i];
4331 I915_WRITE(reg, temp);
4336 for (retry = 0; retry < 5; retry++) {
4337 reg = FDI_RX_IIR(pipe);
4338 temp = I915_READ(reg);
4339 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4340 if (temp & FDI_RX_SYMBOL_LOCK) {
4341 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4342 DRM_DEBUG_KMS("FDI train 2 done.\n");
4351 DRM_ERROR("FDI train 2 fail!\n");
4353 DRM_DEBUG_KMS("FDI train done.\n");
4356 /* Manual link training for Ivy Bridge A0 parts */
4357 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4358 const struct intel_crtc_state *crtc_state)
4360 struct drm_device *dev = crtc->base.dev;
4361 struct drm_i915_private *dev_priv = to_i915(dev);
4362 int pipe = crtc->pipe;
4366 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4368 reg = FDI_RX_IMR(pipe);
4369 temp = I915_READ(reg);
4370 temp &= ~FDI_RX_SYMBOL_LOCK;
4371 temp &= ~FDI_RX_BIT_LOCK;
4372 I915_WRITE(reg, temp);
4377 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4378 I915_READ(FDI_RX_IIR(pipe)));
4380 /* Try each vswing and preemphasis setting twice before moving on */
4381 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4382 /* disable first in case we need to retry */
4383 reg = FDI_TX_CTL(pipe);
4384 temp = I915_READ(reg);
4385 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4386 temp &= ~FDI_TX_ENABLE;
4387 I915_WRITE(reg, temp);
4389 reg = FDI_RX_CTL(pipe);
4390 temp = I915_READ(reg);
4391 temp &= ~FDI_LINK_TRAIN_AUTO;
4392 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4393 temp &= ~FDI_RX_ENABLE;
4394 I915_WRITE(reg, temp);
4396 /* enable CPU FDI TX and PCH FDI RX */
4397 reg = FDI_TX_CTL(pipe);
4398 temp = I915_READ(reg);
4399 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4400 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4401 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4402 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4403 temp |= snb_b_fdi_train_param[j/2];
4404 temp |= FDI_COMPOSITE_SYNC;
4405 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4407 I915_WRITE(FDI_RX_MISC(pipe),
4408 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4410 reg = FDI_RX_CTL(pipe);
4411 temp = I915_READ(reg);
4412 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4413 temp |= FDI_COMPOSITE_SYNC;
4414 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4417 udelay(1); /* should be 0.5us */
4419 for (i = 0; i < 4; i++) {
4420 reg = FDI_RX_IIR(pipe);
4421 temp = I915_READ(reg);
4422 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4424 if (temp & FDI_RX_BIT_LOCK ||
4425 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4426 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4427 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4431 udelay(1); /* should be 0.5us */
4434 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4439 reg = FDI_TX_CTL(pipe);
4440 temp = I915_READ(reg);
4441 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4442 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4443 I915_WRITE(reg, temp);
4445 reg = FDI_RX_CTL(pipe);
4446 temp = I915_READ(reg);
4447 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4448 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4449 I915_WRITE(reg, temp);
4452 udelay(2); /* should be 1.5us */
4454 for (i = 0; i < 4; i++) {
4455 reg = FDI_RX_IIR(pipe);
4456 temp = I915_READ(reg);
4457 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4459 if (temp & FDI_RX_SYMBOL_LOCK ||
4460 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4461 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4462 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4466 udelay(2); /* should be 1.5us */
4469 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4473 DRM_DEBUG_KMS("FDI train done.\n");
4476 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4478 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4479 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4480 int pipe = intel_crtc->pipe;
4484 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4485 reg = FDI_RX_CTL(pipe);
4486 temp = I915_READ(reg);
4487 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4488 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4489 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4490 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4495 /* Switch from Rawclk to PCDclk */
4496 temp = I915_READ(reg);
4497 I915_WRITE(reg, temp | FDI_PCDCLK);
4502 /* Enable CPU FDI TX PLL, always on for Ironlake */
4503 reg = FDI_TX_CTL(pipe);
4504 temp = I915_READ(reg);
4505 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4506 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4513 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4515 struct drm_device *dev = intel_crtc->base.dev;
4516 struct drm_i915_private *dev_priv = to_i915(dev);
4517 int pipe = intel_crtc->pipe;
4521 /* Switch from PCDclk to Rawclk */
4522 reg = FDI_RX_CTL(pipe);
4523 temp = I915_READ(reg);
4524 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4526 /* Disable CPU FDI TX PLL */
4527 reg = FDI_TX_CTL(pipe);
4528 temp = I915_READ(reg);
4529 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4534 reg = FDI_RX_CTL(pipe);
4535 temp = I915_READ(reg);
4536 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4538 /* Wait for the clocks to turn off. */
4543 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4545 struct drm_device *dev = crtc->dev;
4546 struct drm_i915_private *dev_priv = to_i915(dev);
4547 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4548 int pipe = intel_crtc->pipe;
4552 /* disable CPU FDI tx and PCH FDI rx */
4553 reg = FDI_TX_CTL(pipe);
4554 temp = I915_READ(reg);
4555 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4558 reg = FDI_RX_CTL(pipe);
4559 temp = I915_READ(reg);
4560 temp &= ~(0x7 << 16);
4561 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4562 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4567 /* Ironlake workaround, disable clock pointer after downing FDI */
4568 if (HAS_PCH_IBX(dev_priv))
4569 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4571 /* still set train pattern 1 */
4572 reg = FDI_TX_CTL(pipe);
4573 temp = I915_READ(reg);
4574 temp &= ~FDI_LINK_TRAIN_NONE;
4575 temp |= FDI_LINK_TRAIN_PATTERN_1;
4576 I915_WRITE(reg, temp);
4578 reg = FDI_RX_CTL(pipe);
4579 temp = I915_READ(reg);
4580 if (HAS_PCH_CPT(dev_priv)) {
4581 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4582 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4584 temp &= ~FDI_LINK_TRAIN_NONE;
4585 temp |= FDI_LINK_TRAIN_PATTERN_1;
4587 /* BPC in FDI rx is consistent with that in PIPECONF */
4588 temp &= ~(0x07 << 16);
4589 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4590 I915_WRITE(reg, temp);
4596 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4598 struct drm_crtc *crtc;
4601 drm_for_each_crtc(crtc, &dev_priv->drm) {
4602 struct drm_crtc_commit *commit;
4603 spin_lock(&crtc->commit_lock);
4604 commit = list_first_entry_or_null(&crtc->commit_list,
4605 struct drm_crtc_commit, commit_entry);
4606 cleanup_done = commit ?
4607 try_wait_for_completion(&commit->cleanup_done) : true;
4608 spin_unlock(&crtc->commit_lock);
4613 drm_crtc_wait_one_vblank(crtc);
4621 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4625 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4627 mutex_lock(&dev_priv->sb_lock);
4629 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4630 temp |= SBI_SSCCTL_DISABLE;
4631 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4633 mutex_unlock(&dev_priv->sb_lock);
4636 /* Program iCLKIP clock to the desired frequency */
4637 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
4639 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4640 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4641 int clock = crtc_state->base.adjusted_mode.crtc_clock;
4642 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4645 lpt_disable_iclkip(dev_priv);
4647 /* The iCLK virtual clock root frequency is in MHz,
4648 * but the adjusted_mode->crtc_clock in in KHz. To get the
4649 * divisors, it is necessary to divide one by another, so we
4650 * convert the virtual clock precision to KHz here for higher
4653 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4654 u32 iclk_virtual_root_freq = 172800 * 1000;
4655 u32 iclk_pi_range = 64;
4656 u32 desired_divisor;
4658 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4660 divsel = (desired_divisor / iclk_pi_range) - 2;
4661 phaseinc = desired_divisor % iclk_pi_range;
4664 * Near 20MHz is a corner case which is
4665 * out of range for the 7-bit divisor
4671 /* This should not happen with any sane values */
4672 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4673 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4674 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4675 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4677 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4684 mutex_lock(&dev_priv->sb_lock);
4686 /* Program SSCDIVINTPHASE6 */
4687 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4688 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4689 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4690 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4691 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4692 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4693 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4694 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4696 /* Program SSCAUXDIV */
4697 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4698 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4699 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4700 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4702 /* Enable modulator and associated divider */
4703 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4704 temp &= ~SBI_SSCCTL_DISABLE;
4705 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4707 mutex_unlock(&dev_priv->sb_lock);
4709 /* Wait for initialization time */
4712 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4715 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4717 u32 divsel, phaseinc, auxdiv;
4718 u32 iclk_virtual_root_freq = 172800 * 1000;
4719 u32 iclk_pi_range = 64;
4720 u32 desired_divisor;
4723 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4726 mutex_lock(&dev_priv->sb_lock);
4728 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4729 if (temp & SBI_SSCCTL_DISABLE) {
4730 mutex_unlock(&dev_priv->sb_lock);
4734 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4735 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4736 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4737 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4738 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4740 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4741 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4742 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4744 mutex_unlock(&dev_priv->sb_lock);
4746 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4748 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4749 desired_divisor << auxdiv);
4752 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
4753 enum pipe pch_transcoder)
4755 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4756 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4757 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4759 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4760 I915_READ(HTOTAL(cpu_transcoder)));
4761 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4762 I915_READ(HBLANK(cpu_transcoder)));
4763 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4764 I915_READ(HSYNC(cpu_transcoder)));
4766 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4767 I915_READ(VTOTAL(cpu_transcoder)));
4768 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4769 I915_READ(VBLANK(cpu_transcoder)));
4770 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4771 I915_READ(VSYNC(cpu_transcoder)));
4772 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4773 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4776 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
4780 temp = I915_READ(SOUTH_CHICKEN1);
4781 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4784 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4785 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4787 temp &= ~FDI_BC_BIFURCATION_SELECT;
4789 temp |= FDI_BC_BIFURCATION_SELECT;
4791 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4792 I915_WRITE(SOUTH_CHICKEN1, temp);
4793 POSTING_READ(SOUTH_CHICKEN1);
4796 static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
4798 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4799 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4801 switch (crtc->pipe) {
4805 if (crtc_state->fdi_lanes > 2)
4806 cpt_set_fdi_bc_bifurcation(dev_priv, false);
4808 cpt_set_fdi_bc_bifurcation(dev_priv, true);
4812 cpt_set_fdi_bc_bifurcation(dev_priv, true);
4821 * Finds the encoder associated with the given CRTC. This can only be
4822 * used when we know that the CRTC isn't feeding multiple encoders!
4824 static struct intel_encoder *
4825 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4826 const struct intel_crtc_state *crtc_state)
4828 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4829 const struct drm_connector_state *connector_state;
4830 const struct drm_connector *connector;
4831 struct intel_encoder *encoder = NULL;
4832 int num_encoders = 0;
4835 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4836 if (connector_state->crtc != &crtc->base)
4839 encoder = to_intel_encoder(connector_state->best_encoder);
4843 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4844 num_encoders, pipe_name(crtc->pipe));
4850 * Enable PCH resources required for PCH ports:
4852 * - FDI training & RX/TX
4853 * - update transcoder timings
4854 * - DP transcoding bits
4857 static void ironlake_pch_enable(const struct intel_atomic_state *state,
4858 const struct intel_crtc_state *crtc_state)
4860 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4861 struct drm_device *dev = crtc->base.dev;
4862 struct drm_i915_private *dev_priv = to_i915(dev);
4863 int pipe = crtc->pipe;
4866 assert_pch_transcoder_disabled(dev_priv, pipe);
4868 if (IS_IVYBRIDGE(dev_priv))
4869 ivybridge_update_fdi_bc_bifurcation(crtc_state);
4871 /* Write the TU size bits before fdi link training, so that error
4872 * detection works. */
4873 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4874 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4876 /* For PCH output, training FDI link */
4877 dev_priv->display.fdi_link_train(crtc, crtc_state);
4879 /* We need to program the right clock selection before writing the pixel
4880 * mutliplier into the DPLL. */
4881 if (HAS_PCH_CPT(dev_priv)) {
4884 temp = I915_READ(PCH_DPLL_SEL);
4885 temp |= TRANS_DPLL_ENABLE(pipe);
4886 sel = TRANS_DPLLB_SEL(pipe);
4887 if (crtc_state->shared_dpll ==
4888 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4892 I915_WRITE(PCH_DPLL_SEL, temp);
4895 /* XXX: pch pll's can be enabled any time before we enable the PCH
4896 * transcoder, and we actually should do this to not upset any PCH
4897 * transcoder that already use the clock when we share it.
4899 * Note that enable_shared_dpll tries to do the right thing, but
4900 * get_shared_dpll unconditionally resets the pll - we need that to have
4901 * the right LVDS enable sequence. */
4902 intel_enable_shared_dpll(crtc_state);
4904 /* set transcoder timing, panel must allow it */
4905 assert_panel_unlocked(dev_priv, pipe);
4906 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
4908 intel_fdi_normal_train(crtc);
4910 /* For PCH DP, enable TRANS_DP_CTL */
4911 if (HAS_PCH_CPT(dev_priv) &&
4912 intel_crtc_has_dp_encoder(crtc_state)) {
4913 const struct drm_display_mode *adjusted_mode =
4914 &crtc_state->base.adjusted_mode;
4915 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4916 i915_reg_t reg = TRANS_DP_CTL(pipe);
4919 temp = I915_READ(reg);
4920 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4921 TRANS_DP_SYNC_MASK |
4923 temp |= TRANS_DP_OUTPUT_ENABLE;
4924 temp |= bpc << 9; /* same format but at 11:9 */
4926 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4927 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4928 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4929 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4931 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
4932 WARN_ON(port < PORT_B || port > PORT_D);
4933 temp |= TRANS_DP_PORT_SEL(port);
4935 I915_WRITE(reg, temp);
4938 ironlake_enable_pch_transcoder(crtc_state);
4941 static void lpt_pch_enable(const struct intel_atomic_state *state,
4942 const struct intel_crtc_state *crtc_state)
4944 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4945 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4946 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4948 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4950 lpt_program_iclkip(crtc_state);
4952 /* Set transcoder timing. */
4953 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
4955 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4958 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4960 struct drm_i915_private *dev_priv = to_i915(dev);
4961 i915_reg_t dslreg = PIPEDSL(pipe);
4964 temp = I915_READ(dslreg);
4966 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4967 if (wait_for(I915_READ(dslreg) != temp, 5))
4968 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4973 * The hardware phase 0.0 refers to the center of the pixel.
4974 * We want to start from the top/left edge which is phase
4975 * -0.5. That matches how the hardware calculates the scaling
4976 * factors (from top-left of the first pixel to bottom-right
4977 * of the last pixel, as opposed to the pixel centers).
4979 * For 4:2:0 subsampled chroma planes we obviously have to
4980 * adjust that so that the chroma sample position lands in
4983 * Note that for packed YCbCr 4:2:2 formats there is no way to
4984 * control chroma siting. The hardware simply replicates the
4985 * chroma samples for both of the luma samples, and thus we don't
4986 * actually get the expected MPEG2 chroma siting convention :(
4987 * The same behaviour is observed on pre-SKL platforms as well.
4989 * Theory behind the formula (note that we ignore sub-pixel
4990 * source coordinates):
4991 * s = source sample position
4992 * d = destination sample position
4997 * | | 1.5 (initial phase)
5005 * | -0.375 (initial phase)
5012 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
5014 int phase = -0x8000;
5018 phase += (sub - 1) * 0x8000 / sub;
5020 phase += scale / (2 * sub);
5023 * Hardware initial phase limited to [-0.5:1.5].
5024 * Since the max hardware scale factor is 3.0, we
5025 * should never actually excdeed 1.0 here.
5027 WARN_ON(phase < -0x8000 || phase > 0x18000);
5030 phase = 0x10000 + phase;
5032 trip = PS_PHASE_TRIP;
5034 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5038 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5039 unsigned int scaler_user, int *scaler_id,
5040 int src_w, int src_h, int dst_w, int dst_h,
5041 const struct drm_format_info *format, bool need_scaler)
5043 struct intel_crtc_scaler_state *scaler_state =
5044 &crtc_state->scaler_state;
5045 struct intel_crtc *intel_crtc =
5046 to_intel_crtc(crtc_state->base.crtc);
5047 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5048 const struct drm_display_mode *adjusted_mode =
5049 &crtc_state->base.adjusted_mode;
5052 * Src coordinates are already rotated by 270 degrees for
5053 * the 90/270 degree plane rotation cases (to match the
5054 * GTT mapping), hence no need to account for rotation here.
5056 if (src_w != dst_w || src_h != dst_h)
5060 * Scaling/fitting not supported in IF-ID mode in GEN9+
5061 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5062 * Once NV12 is enabled, handle it here while allocating scaler
5065 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
5066 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5067 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5072 * if plane is being disabled or scaler is no more required or force detach
5073 * - free scaler binded to this plane/crtc
5074 * - in order to do this, update crtc->scaler_usage
5076 * Here scaler state in crtc_state is set free so that
5077 * scaler can be assigned to other user. Actual register
5078 * update to free the scaler is done in plane/panel-fit programming.
5079 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5081 if (force_detach || !need_scaler) {
5082 if (*scaler_id >= 0) {
5083 scaler_state->scaler_users &= ~(1 << scaler_user);
5084 scaler_state->scalers[*scaler_id].in_use = 0;
5086 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5087 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5088 intel_crtc->pipe, scaler_user, *scaler_id,
5089 scaler_state->scaler_users);
5095 if (format && is_planar_yuv_format(format->format) &&
5096 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5097 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
5102 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5103 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5104 (IS_GEN(dev_priv, 11) &&
5105 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5106 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5107 (!IS_GEN(dev_priv, 11) &&
5108 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5109 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5110 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
5111 "size is out of scaler range\n",
5112 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
5116 /* mark this plane as a scaler user in crtc_state */
5117 scaler_state->scaler_users |= (1 << scaler_user);
5118 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5119 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5120 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5121 scaler_state->scaler_users);
5127 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5129 * @state: crtc's scaler state
5132 * 0 - scaler_usage updated successfully
5133 * error - requested scaling cannot be supported or other error condition
5135 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5137 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
5138 bool need_scaler = false;
5140 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5143 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
5144 &state->scaler_state.scaler_id,
5145 state->pipe_src_w, state->pipe_src_h,
5146 adjusted_mode->crtc_hdisplay,
5147 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
5151 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5152 * @crtc_state: crtc's scaler state
5153 * @plane_state: atomic plane state to update
5156 * 0 - scaler_usage updated successfully
5157 * error - requested scaling cannot be supported or other error condition
5159 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5160 struct intel_plane_state *plane_state)
5162 struct intel_plane *intel_plane =
5163 to_intel_plane(plane_state->base.plane);
5164 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5165 struct drm_framebuffer *fb = plane_state->base.fb;
5167 bool force_detach = !fb || !plane_state->base.visible;
5168 bool need_scaler = false;
5170 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5171 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5172 fb && is_planar_yuv_format(fb->format->format))
5175 ret = skl_update_scaler(crtc_state, force_detach,
5176 drm_plane_index(&intel_plane->base),
5177 &plane_state->scaler_id,
5178 drm_rect_width(&plane_state->base.src) >> 16,
5179 drm_rect_height(&plane_state->base.src) >> 16,
5180 drm_rect_width(&plane_state->base.dst),
5181 drm_rect_height(&plane_state->base.dst),
5182 fb ? fb->format : NULL, need_scaler);
5184 if (ret || plane_state->scaler_id < 0)
5187 /* check colorkey */
5188 if (plane_state->ckey.flags) {
5189 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5190 intel_plane->base.base.id,
5191 intel_plane->base.name);
5195 /* Check src format */
5196 switch (fb->format->format) {
5197 case DRM_FORMAT_RGB565:
5198 case DRM_FORMAT_XBGR8888:
5199 case DRM_FORMAT_XRGB8888:
5200 case DRM_FORMAT_ABGR8888:
5201 case DRM_FORMAT_ARGB8888:
5202 case DRM_FORMAT_XRGB2101010:
5203 case DRM_FORMAT_XBGR2101010:
5204 case DRM_FORMAT_XBGR16161616F:
5205 case DRM_FORMAT_ABGR16161616F:
5206 case DRM_FORMAT_XRGB16161616F:
5207 case DRM_FORMAT_ARGB16161616F:
5208 case DRM_FORMAT_YUYV:
5209 case DRM_FORMAT_YVYU:
5210 case DRM_FORMAT_UYVY:
5211 case DRM_FORMAT_VYUY:
5212 case DRM_FORMAT_NV12:
5213 case DRM_FORMAT_P010:
5214 case DRM_FORMAT_P012:
5215 case DRM_FORMAT_P016:
5216 case DRM_FORMAT_Y210:
5217 case DRM_FORMAT_Y212:
5218 case DRM_FORMAT_Y216:
5219 case DRM_FORMAT_XVYU2101010:
5220 case DRM_FORMAT_XVYU12_16161616:
5221 case DRM_FORMAT_XVYU16161616:
5224 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5225 intel_plane->base.base.id, intel_plane->base.name,
5226 fb->base.id, fb->format->format);
5233 static void skylake_scaler_disable(struct intel_crtc *crtc)
5237 for (i = 0; i < crtc->num_scalers; i++)
5238 skl_detach_scaler(crtc, i);
5241 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
5243 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5244 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5245 enum pipe pipe = crtc->pipe;
5246 const struct intel_crtc_scaler_state *scaler_state =
5247 &crtc_state->scaler_state;
5249 if (crtc_state->pch_pfit.enabled) {
5250 u16 uv_rgb_hphase, uv_rgb_vphase;
5251 int pfit_w, pfit_h, hscale, vscale;
5254 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
5257 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5258 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5260 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5261 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5263 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5264 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5266 id = scaler_state->scaler_id;
5267 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5268 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5269 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5270 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5271 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5272 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5273 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5274 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
5278 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
5280 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5281 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5282 int pipe = crtc->pipe;
5284 if (crtc_state->pch_pfit.enabled) {
5285 /* Force use of hard-coded filter coefficients
5286 * as some pre-programmed values are broken,
5289 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5290 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5291 PF_PIPE_SEL_IVB(pipe));
5293 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5294 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5295 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
5299 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5301 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5302 struct drm_device *dev = crtc->base.dev;
5303 struct drm_i915_private *dev_priv = to_i915(dev);
5305 if (!crtc_state->ips_enabled)
5309 * We can only enable IPS after we enable a plane and wait for a vblank
5310 * This function is called from post_plane_update, which is run after
5313 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5315 if (IS_BROADWELL(dev_priv)) {
5316 mutex_lock(&dev_priv->pcu_lock);
5317 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5318 IPS_ENABLE | IPS_PCODE_CONTROL));
5319 mutex_unlock(&dev_priv->pcu_lock);
5320 /* Quoting Art Runyan: "its not safe to expect any particular
5321 * value in IPS_CTL bit 31 after enabling IPS through the
5322 * mailbox." Moreover, the mailbox may return a bogus state,
5323 * so we need to just enable it and continue on.
5326 I915_WRITE(IPS_CTL, IPS_ENABLE);
5327 /* The bit only becomes 1 in the next vblank, so this wait here
5328 * is essentially intel_wait_for_vblank. If we don't have this
5329 * and don't wait for vblanks until the end of crtc_enable, then
5330 * the HW state readout code will complain that the expected
5331 * IPS_CTL value is not the one we read. */
5332 if (intel_wait_for_register(dev_priv,
5333 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5335 DRM_ERROR("Timed out waiting for IPS enable\n");
5339 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5341 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5342 struct drm_device *dev = crtc->base.dev;
5343 struct drm_i915_private *dev_priv = to_i915(dev);
5345 if (!crtc_state->ips_enabled)
5348 if (IS_BROADWELL(dev_priv)) {
5349 mutex_lock(&dev_priv->pcu_lock);
5350 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5351 mutex_unlock(&dev_priv->pcu_lock);
5353 * Wait for PCODE to finish disabling IPS. The BSpec specified
5354 * 42ms timeout value leads to occasional timeouts so use 100ms
5357 if (intel_wait_for_register(dev_priv,
5358 IPS_CTL, IPS_ENABLE, 0,
5360 DRM_ERROR("Timed out waiting for IPS disable\n");
5362 I915_WRITE(IPS_CTL, 0);
5363 POSTING_READ(IPS_CTL);
5366 /* We need to wait for a vblank before we can disable the plane. */
5367 intel_wait_for_vblank(dev_priv, crtc->pipe);
5370 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5372 if (intel_crtc->overlay) {
5373 struct drm_device *dev = intel_crtc->base.dev;
5375 mutex_lock(&dev->struct_mutex);
5376 (void) intel_overlay_switch_off(intel_crtc->overlay);
5377 mutex_unlock(&dev->struct_mutex);
5380 /* Let userspace switch the overlay on again. In most cases userspace
5381 * has to recompute where to put it anyway.
5386 * intel_post_enable_primary - Perform operations after enabling primary plane
5387 * @crtc: the CRTC whose primary plane was just enabled
5388 * @new_crtc_state: the enabling state
5390 * Performs potentially sleeping operations that must be done after the primary
5391 * plane is enabled, such as updating FBC and IPS. Note that this may be
5392 * called due to an explicit primary plane update, or due to an implicit
5393 * re-enable that is caused when a sprite plane is updated to no longer
5394 * completely hide the primary plane.
5397 intel_post_enable_primary(struct drm_crtc *crtc,
5398 const struct intel_crtc_state *new_crtc_state)
5400 struct drm_device *dev = crtc->dev;
5401 struct drm_i915_private *dev_priv = to_i915(dev);
5402 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5403 int pipe = intel_crtc->pipe;
5406 * Gen2 reports pipe underruns whenever all planes are disabled.
5407 * So don't enable underrun reporting before at least some planes
5409 * FIXME: Need to fix the logic to work when we turn off all planes
5410 * but leave the pipe running.
5412 if (IS_GEN(dev_priv, 2))
5413 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5415 /* Underruns don't always raise interrupts, so check manually. */
5416 intel_check_cpu_fifo_underruns(dev_priv);
5417 intel_check_pch_fifo_underruns(dev_priv);
5420 /* FIXME get rid of this and use pre_plane_update */
5422 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5424 struct drm_device *dev = crtc->dev;
5425 struct drm_i915_private *dev_priv = to_i915(dev);
5426 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5427 int pipe = intel_crtc->pipe;
5430 * Gen2 reports pipe underruns whenever all planes are disabled.
5431 * So disable underrun reporting before all the planes get disabled.
5433 if (IS_GEN(dev_priv, 2))
5434 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5436 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5439 * Vblank time updates from the shadow to live plane control register
5440 * are blocked if the memory self-refresh mode is active at that
5441 * moment. So to make sure the plane gets truly disabled, disable
5442 * first the self-refresh mode. The self-refresh enable bit in turn
5443 * will be checked/applied by the HW only at the next frame start
5444 * event which is after the vblank start event, so we need to have a
5445 * wait-for-vblank between disabling the plane and the pipe.
5447 if (HAS_GMCH(dev_priv) &&
5448 intel_set_memory_cxsr(dev_priv, false))
5449 intel_wait_for_vblank(dev_priv, pipe);
5452 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5453 const struct intel_crtc_state *new_crtc_state)
5455 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5456 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5458 if (!old_crtc_state->ips_enabled)
5461 if (needs_modeset(&new_crtc_state->base))
5465 * Workaround : Do not read or write the pipe palette/gamma data while
5466 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5468 * Disable IPS before we program the LUT.
5470 if (IS_HASWELL(dev_priv) &&
5471 (new_crtc_state->base.color_mgmt_changed ||
5472 new_crtc_state->update_pipe) &&
5473 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5476 return !new_crtc_state->ips_enabled;
5479 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5480 const struct intel_crtc_state *new_crtc_state)
5482 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5483 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5485 if (!new_crtc_state->ips_enabled)
5488 if (needs_modeset(&new_crtc_state->base))
5492 * Workaround : Do not read or write the pipe palette/gamma data while
5493 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5495 * Re-enable IPS after the LUT has been programmed.
5497 if (IS_HASWELL(dev_priv) &&
5498 (new_crtc_state->base.color_mgmt_changed ||
5499 new_crtc_state->update_pipe) &&
5500 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5504 * We can't read out IPS on broadwell, assume the worst and
5505 * forcibly enable IPS on the first fastset.
5507 if (new_crtc_state->update_pipe &&
5508 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5511 return !old_crtc_state->ips_enabled;
5514 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5515 const struct intel_crtc_state *crtc_state)
5517 if (!crtc_state->nv12_planes)
5520 /* WA Display #0827: Gen9:all */
5521 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
5527 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5529 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5530 struct drm_device *dev = crtc->base.dev;
5531 struct drm_i915_private *dev_priv = to_i915(dev);
5532 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5533 struct intel_crtc_state *pipe_config =
5534 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5536 struct drm_plane *primary = crtc->base.primary;
5537 struct drm_plane_state *old_primary_state =
5538 drm_atomic_get_old_plane_state(old_state, primary);
5540 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5542 if (pipe_config->update_wm_post && pipe_config->base.active)
5543 intel_update_watermarks(crtc);
5545 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5546 hsw_enable_ips(pipe_config);
5548 if (old_primary_state) {
5549 struct drm_plane_state *new_primary_state =
5550 drm_atomic_get_new_plane_state(old_state, primary);
5552 intel_fbc_post_update(crtc);
5554 if (new_primary_state->visible &&
5555 (needs_modeset(&pipe_config->base) ||
5556 !old_primary_state->visible))
5557 intel_post_enable_primary(&crtc->base, pipe_config);
5560 /* Display WA 827 */
5561 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5562 !needs_nv12_wa(dev_priv, pipe_config)) {
5563 skl_wa_clkgate(dev_priv, crtc->pipe, false);
5567 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5568 struct intel_crtc_state *pipe_config)
5570 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5571 struct drm_device *dev = crtc->base.dev;
5572 struct drm_i915_private *dev_priv = to_i915(dev);
5573 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5574 struct drm_plane *primary = crtc->base.primary;
5575 struct drm_plane_state *old_primary_state =
5576 drm_atomic_get_old_plane_state(old_state, primary);
5577 bool modeset = needs_modeset(&pipe_config->base);
5578 struct intel_atomic_state *old_intel_state =
5579 to_intel_atomic_state(old_state);
5581 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5582 hsw_disable_ips(old_crtc_state);
5584 if (old_primary_state) {
5585 struct intel_plane_state *new_primary_state =
5586 intel_atomic_get_new_plane_state(old_intel_state,
5587 to_intel_plane(primary));
5589 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5591 * Gen2 reports pipe underruns whenever all planes are disabled.
5592 * So disable underrun reporting before all the planes get disabled.
5594 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
5595 (modeset || !new_primary_state->base.visible))
5596 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5599 /* Display WA 827 */
5600 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5601 needs_nv12_wa(dev_priv, pipe_config)) {
5602 skl_wa_clkgate(dev_priv, crtc->pipe, true);
5606 * Vblank time updates from the shadow to live plane control register
5607 * are blocked if the memory self-refresh mode is active at that
5608 * moment. So to make sure the plane gets truly disabled, disable
5609 * first the self-refresh mode. The self-refresh enable bit in turn
5610 * will be checked/applied by the HW only at the next frame start
5611 * event which is after the vblank start event, so we need to have a
5612 * wait-for-vblank between disabling the plane and the pipe.
5614 if (HAS_GMCH(dev_priv) && old_crtc_state->base.active &&
5615 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5616 intel_wait_for_vblank(dev_priv, crtc->pipe);
5619 * IVB workaround: must disable low power watermarks for at least
5620 * one frame before enabling scaling. LP watermarks can be re-enabled
5621 * when scaling is disabled.
5623 * WaCxSRDisabledForSpriteScaling:ivb
5625 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5626 old_crtc_state->base.active)
5627 intel_wait_for_vblank(dev_priv, crtc->pipe);
5630 * If we're doing a modeset, we're done. No need to do any pre-vblank
5631 * watermark programming here.
5633 if (needs_modeset(&pipe_config->base))
5637 * For platforms that support atomic watermarks, program the
5638 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5639 * will be the intermediate values that are safe for both pre- and
5640 * post- vblank; when vblank happens, the 'active' values will be set
5641 * to the final 'target' values and we'll do this again to get the
5642 * optimal watermarks. For gen9+ platforms, the values we program here
5643 * will be the final target values which will get automatically latched
5644 * at vblank time; no further programming will be necessary.
5646 * If a platform hasn't been transitioned to atomic watermarks yet,
5647 * we'll continue to update watermarks the old way, if flags tell
5650 if (dev_priv->display.initial_watermarks != NULL)
5651 dev_priv->display.initial_watermarks(old_intel_state,
5653 else if (pipe_config->update_wm_pre)
5654 intel_update_watermarks(crtc);
5657 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
5658 struct intel_crtc *crtc)
5660 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5661 const struct intel_crtc_state *new_crtc_state =
5662 intel_atomic_get_new_crtc_state(state, crtc);
5663 unsigned int update_mask = new_crtc_state->update_planes;
5664 const struct intel_plane_state *old_plane_state;
5665 struct intel_plane *plane;
5666 unsigned fb_bits = 0;
5669 intel_crtc_dpms_overlay_disable(crtc);
5671 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
5672 if (crtc->pipe != plane->pipe ||
5673 !(update_mask & BIT(plane->id)))
5676 plane->disable_plane(plane, new_crtc_state);
5678 if (old_plane_state->base.visible)
5679 fb_bits |= plane->frontbuffer_bit;
5682 intel_frontbuffer_flip(dev_priv, fb_bits);
5685 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5686 struct intel_crtc_state *crtc_state,
5687 struct drm_atomic_state *old_state)
5689 struct drm_connector_state *conn_state;
5690 struct drm_connector *conn;
5693 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5694 struct intel_encoder *encoder =
5695 to_intel_encoder(conn_state->best_encoder);
5697 if (conn_state->crtc != crtc)
5700 if (encoder->pre_pll_enable)
5701 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5705 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5706 struct intel_crtc_state *crtc_state,
5707 struct drm_atomic_state *old_state)
5709 struct drm_connector_state *conn_state;
5710 struct drm_connector *conn;
5713 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5714 struct intel_encoder *encoder =
5715 to_intel_encoder(conn_state->best_encoder);
5717 if (conn_state->crtc != crtc)
5720 if (encoder->pre_enable)
5721 encoder->pre_enable(encoder, crtc_state, conn_state);
5725 static void intel_encoders_enable(struct drm_crtc *crtc,
5726 struct intel_crtc_state *crtc_state,
5727 struct drm_atomic_state *old_state)
5729 struct drm_connector_state *conn_state;
5730 struct drm_connector *conn;
5733 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5734 struct intel_encoder *encoder =
5735 to_intel_encoder(conn_state->best_encoder);
5737 if (conn_state->crtc != crtc)
5740 if (encoder->enable)
5741 encoder->enable(encoder, crtc_state, conn_state);
5742 intel_opregion_notify_encoder(encoder, true);
5746 static void intel_encoders_disable(struct drm_crtc *crtc,
5747 struct intel_crtc_state *old_crtc_state,
5748 struct drm_atomic_state *old_state)
5750 struct drm_connector_state *old_conn_state;
5751 struct drm_connector *conn;
5754 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5755 struct intel_encoder *encoder =
5756 to_intel_encoder(old_conn_state->best_encoder);
5758 if (old_conn_state->crtc != crtc)
5761 intel_opregion_notify_encoder(encoder, false);
5762 if (encoder->disable)
5763 encoder->disable(encoder, old_crtc_state, old_conn_state);
5767 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5768 struct intel_crtc_state *old_crtc_state,
5769 struct drm_atomic_state *old_state)
5771 struct drm_connector_state *old_conn_state;
5772 struct drm_connector *conn;
5775 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5776 struct intel_encoder *encoder =
5777 to_intel_encoder(old_conn_state->best_encoder);
5779 if (old_conn_state->crtc != crtc)
5782 if (encoder->post_disable)
5783 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5787 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5788 struct intel_crtc_state *old_crtc_state,
5789 struct drm_atomic_state *old_state)
5791 struct drm_connector_state *old_conn_state;
5792 struct drm_connector *conn;
5795 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5796 struct intel_encoder *encoder =
5797 to_intel_encoder(old_conn_state->best_encoder);
5799 if (old_conn_state->crtc != crtc)
5802 if (encoder->post_pll_disable)
5803 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5807 static void intel_encoders_update_pipe(struct drm_crtc *crtc,
5808 struct intel_crtc_state *crtc_state,
5809 struct drm_atomic_state *old_state)
5811 struct drm_connector_state *conn_state;
5812 struct drm_connector *conn;
5815 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5816 struct intel_encoder *encoder =
5817 to_intel_encoder(conn_state->best_encoder);
5819 if (conn_state->crtc != crtc)
5822 if (encoder->update_pipe)
5823 encoder->update_pipe(encoder, crtc_state, conn_state);
5827 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5828 struct drm_atomic_state *old_state)
5830 struct drm_crtc *crtc = pipe_config->base.crtc;
5831 struct drm_device *dev = crtc->dev;
5832 struct drm_i915_private *dev_priv = to_i915(dev);
5833 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5834 int pipe = intel_crtc->pipe;
5835 struct intel_atomic_state *old_intel_state =
5836 to_intel_atomic_state(old_state);
5838 if (WARN_ON(intel_crtc->active))
5842 * Sometimes spurious CPU pipe underruns happen during FDI
5843 * training, at least with VGA+HDMI cloning. Suppress them.
5845 * On ILK we get an occasional spurious CPU pipe underruns
5846 * between eDP port A enable and vdd enable. Also PCH port
5847 * enable seems to result in the occasional CPU pipe underrun.
5849 * Spurious PCH underruns also occur during PCH enabling.
5851 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5852 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5854 if (pipe_config->has_pch_encoder)
5855 intel_prepare_shared_dpll(pipe_config);
5857 if (intel_crtc_has_dp_encoder(pipe_config))
5858 intel_dp_set_m_n(pipe_config, M1_N1);
5860 intel_set_pipe_timings(pipe_config);
5861 intel_set_pipe_src_size(pipe_config);
5863 if (pipe_config->has_pch_encoder) {
5864 intel_cpu_transcoder_set_m_n(pipe_config,
5865 &pipe_config->fdi_m_n, NULL);
5868 ironlake_set_pipeconf(pipe_config);
5870 intel_crtc->active = true;
5872 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5874 if (pipe_config->has_pch_encoder) {
5875 /* Note: FDI PLL enabling _must_ be done before we enable the
5876 * cpu pipes, hence this is separate from all the other fdi/pch
5878 ironlake_fdi_pll_enable(pipe_config);
5880 assert_fdi_tx_disabled(dev_priv, pipe);
5881 assert_fdi_rx_disabled(dev_priv, pipe);
5884 ironlake_pfit_enable(pipe_config);
5887 * On ILK+ LUT must be loaded before the pipe is running but with
5890 intel_color_load_luts(pipe_config);
5891 intel_color_commit(pipe_config);
5893 if (dev_priv->display.initial_watermarks != NULL)
5894 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5895 intel_enable_pipe(pipe_config);
5897 if (pipe_config->has_pch_encoder)
5898 ironlake_pch_enable(old_intel_state, pipe_config);
5900 assert_vblank_disabled(crtc);
5901 intel_crtc_vblank_on(pipe_config);
5903 intel_encoders_enable(crtc, pipe_config, old_state);
5905 if (HAS_PCH_CPT(dev_priv))
5906 cpt_verify_modeset(dev, intel_crtc->pipe);
5909 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5910 * And a second vblank wait is needed at least on ILK with
5911 * some interlaced HDMI modes. Let's do the double wait always
5912 * in case there are more corner cases we don't know about.
5914 if (pipe_config->has_pch_encoder) {
5915 intel_wait_for_vblank(dev_priv, pipe);
5916 intel_wait_for_vblank(dev_priv, pipe);
5918 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5919 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5922 /* IPS only exists on ULT machines and is tied to pipe A. */
5923 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5925 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5928 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5929 enum pipe pipe, bool apply)
5931 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5932 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5939 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5942 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5944 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5945 enum pipe pipe = crtc->pipe;
5948 val = MBUS_DBOX_A_CREDIT(2);
5949 val |= MBUS_DBOX_BW_CREDIT(1);
5950 val |= MBUS_DBOX_B_CREDIT(8);
5952 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5955 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5956 struct drm_atomic_state *old_state)
5958 struct drm_crtc *crtc = pipe_config->base.crtc;
5959 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5960 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5961 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5962 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
5963 struct intel_atomic_state *old_intel_state =
5964 to_intel_atomic_state(old_state);
5965 bool psl_clkgate_wa;
5967 if (WARN_ON(intel_crtc->active))
5970 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5972 if (pipe_config->shared_dpll)
5973 intel_enable_shared_dpll(pipe_config);
5975 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5977 if (intel_crtc_has_dp_encoder(pipe_config))
5978 intel_dp_set_m_n(pipe_config, M1_N1);
5980 if (!transcoder_is_dsi(cpu_transcoder))
5981 intel_set_pipe_timings(pipe_config);
5983 intel_set_pipe_src_size(pipe_config);
5985 if (cpu_transcoder != TRANSCODER_EDP &&
5986 !transcoder_is_dsi(cpu_transcoder)) {
5987 I915_WRITE(PIPE_MULT(cpu_transcoder),
5988 pipe_config->pixel_multiplier - 1);
5991 if (pipe_config->has_pch_encoder) {
5992 intel_cpu_transcoder_set_m_n(pipe_config,
5993 &pipe_config->fdi_m_n, NULL);
5996 if (!transcoder_is_dsi(cpu_transcoder))
5997 haswell_set_pipeconf(pipe_config);
5999 haswell_set_pipemisc(pipe_config);
6001 intel_crtc->active = true;
6003 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
6004 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
6005 pipe_config->pch_pfit.enabled;
6007 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
6009 if (INTEL_GEN(dev_priv) >= 9)
6010 skylake_pfit_enable(pipe_config);
6012 ironlake_pfit_enable(pipe_config);
6015 * On ILK+ LUT must be loaded before the pipe is running but with
6018 intel_color_load_luts(pipe_config);
6019 intel_color_commit(pipe_config);
6021 if (INTEL_GEN(dev_priv) >= 11)
6022 icl_set_pipe_chicken(intel_crtc);
6024 intel_ddi_set_pipe_settings(pipe_config);
6025 if (!transcoder_is_dsi(cpu_transcoder))
6026 intel_ddi_enable_transcoder_func(pipe_config);
6028 if (dev_priv->display.initial_watermarks != NULL)
6029 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
6031 if (INTEL_GEN(dev_priv) >= 11)
6032 icl_pipe_mbus_enable(intel_crtc);
6034 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6035 if (!transcoder_is_dsi(cpu_transcoder))
6036 intel_enable_pipe(pipe_config);
6038 if (pipe_config->has_pch_encoder)
6039 lpt_pch_enable(old_intel_state, pipe_config);
6041 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
6042 intel_ddi_set_vc_payload_alloc(pipe_config, true);
6044 assert_vblank_disabled(crtc);
6045 intel_crtc_vblank_on(pipe_config);
6047 intel_encoders_enable(crtc, pipe_config, old_state);
6049 if (psl_clkgate_wa) {
6050 intel_wait_for_vblank(dev_priv, pipe);
6051 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6054 /* If we change the relative order between pipe/planes enabling, we need
6055 * to change the workaround. */
6056 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
6057 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6058 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6059 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6063 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6065 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6066 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6067 enum pipe pipe = crtc->pipe;
6069 /* To avoid upsetting the power well on haswell only disable the pfit if
6070 * it's in use. The hw state code will make sure we get this right. */
6071 if (old_crtc_state->pch_pfit.enabled) {
6072 I915_WRITE(PF_CTL(pipe), 0);
6073 I915_WRITE(PF_WIN_POS(pipe), 0);
6074 I915_WRITE(PF_WIN_SZ(pipe), 0);
6078 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
6079 struct drm_atomic_state *old_state)
6081 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6082 struct drm_device *dev = crtc->dev;
6083 struct drm_i915_private *dev_priv = to_i915(dev);
6084 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6085 int pipe = intel_crtc->pipe;
6088 * Sometimes spurious CPU pipe underruns happen when the
6089 * pipe is already disabled, but FDI RX/TX is still enabled.
6090 * Happens at least with VGA+HDMI cloning. Suppress them.
6092 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6093 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6095 intel_encoders_disable(crtc, old_crtc_state, old_state);
6097 drm_crtc_vblank_off(crtc);
6098 assert_vblank_disabled(crtc);
6100 intel_disable_pipe(old_crtc_state);
6102 ironlake_pfit_disable(old_crtc_state);
6104 if (old_crtc_state->has_pch_encoder)
6105 ironlake_fdi_disable(crtc);
6107 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6109 if (old_crtc_state->has_pch_encoder) {
6110 ironlake_disable_pch_transcoder(dev_priv, pipe);
6112 if (HAS_PCH_CPT(dev_priv)) {
6116 /* disable TRANS_DP_CTL */
6117 reg = TRANS_DP_CTL(pipe);
6118 temp = I915_READ(reg);
6119 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6120 TRANS_DP_PORT_SEL_MASK);
6121 temp |= TRANS_DP_PORT_SEL_NONE;
6122 I915_WRITE(reg, temp);
6124 /* disable DPLL_SEL */
6125 temp = I915_READ(PCH_DPLL_SEL);
6126 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6127 I915_WRITE(PCH_DPLL_SEL, temp);
6130 ironlake_fdi_pll_disable(intel_crtc);
6133 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6134 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6137 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
6138 struct drm_atomic_state *old_state)
6140 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6141 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6142 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6143 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
6145 intel_encoders_disable(crtc, old_crtc_state, old_state);
6147 drm_crtc_vblank_off(crtc);
6148 assert_vblank_disabled(crtc);
6150 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6151 if (!transcoder_is_dsi(cpu_transcoder))
6152 intel_disable_pipe(old_crtc_state);
6154 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
6155 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
6157 if (!transcoder_is_dsi(cpu_transcoder))
6158 intel_ddi_disable_transcoder_func(old_crtc_state);
6160 intel_dsc_disable(old_crtc_state);
6162 if (INTEL_GEN(dev_priv) >= 9)
6163 skylake_scaler_disable(intel_crtc);
6165 ironlake_pfit_disable(old_crtc_state);
6167 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6169 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6172 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6174 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6175 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6177 if (!crtc_state->gmch_pfit.control)
6181 * The panel fitter should only be adjusted whilst the pipe is disabled,
6182 * according to register description and PRM.
6184 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6185 assert_pipe_disabled(dev_priv, crtc->pipe);
6187 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6188 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
6190 /* Border color in case we don't scale up to the full screen. Black by
6191 * default, change to something else for debugging. */
6192 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6195 bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
6197 if (port == PORT_NONE)
6200 if (IS_ICELAKE(dev_priv))
6201 return port <= PORT_B;
6206 bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
6208 if (IS_ICELAKE(dev_priv))
6209 return port >= PORT_C && port <= PORT_F;
6214 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6216 if (!intel_port_is_tc(dev_priv, port))
6217 return PORT_TC_NONE;
6219 return port - PORT_C;
6222 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
6226 return POWER_DOMAIN_PORT_DDI_A_LANES;
6228 return POWER_DOMAIN_PORT_DDI_B_LANES;
6230 return POWER_DOMAIN_PORT_DDI_C_LANES;
6232 return POWER_DOMAIN_PORT_DDI_D_LANES;
6234 return POWER_DOMAIN_PORT_DDI_E_LANES;
6236 return POWER_DOMAIN_PORT_DDI_F_LANES;
6239 return POWER_DOMAIN_PORT_OTHER;
6243 enum intel_display_power_domain
6244 intel_aux_power_domain(struct intel_digital_port *dig_port)
6246 switch (dig_port->aux_ch) {
6248 return POWER_DOMAIN_AUX_A;
6250 return POWER_DOMAIN_AUX_B;
6252 return POWER_DOMAIN_AUX_C;
6254 return POWER_DOMAIN_AUX_D;
6256 return POWER_DOMAIN_AUX_E;
6258 return POWER_DOMAIN_AUX_F;
6260 MISSING_CASE(dig_port->aux_ch);
6261 return POWER_DOMAIN_AUX_A;
6265 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
6266 struct intel_crtc_state *crtc_state)
6268 struct drm_device *dev = crtc->dev;
6269 struct drm_i915_private *dev_priv = to_i915(dev);
6270 struct drm_encoder *encoder;
6271 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6272 enum pipe pipe = intel_crtc->pipe;
6274 enum transcoder transcoder = crtc_state->cpu_transcoder;
6276 if (!crtc_state->base.active)
6279 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6280 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
6281 if (crtc_state->pch_pfit.enabled ||
6282 crtc_state->pch_pfit.force_thru)
6283 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
6285 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6286 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6288 mask |= BIT_ULL(intel_encoder->power_domain);
6291 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
6292 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
6294 if (crtc_state->shared_dpll)
6295 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
6301 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6302 struct intel_crtc_state *crtc_state)
6304 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6305 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6306 enum intel_display_power_domain domain;
6307 u64 domains, new_domains, old_domains;
6309 old_domains = intel_crtc->enabled_power_domains;
6310 intel_crtc->enabled_power_domains = new_domains =
6311 get_crtc_power_domains(crtc, crtc_state);
6313 domains = new_domains & ~old_domains;
6315 for_each_power_domain(domain, domains)
6316 intel_display_power_get(dev_priv, domain);
6318 return old_domains & ~new_domains;
6321 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6324 enum intel_display_power_domain domain;
6326 for_each_power_domain(domain, domains)
6327 intel_display_power_put_unchecked(dev_priv, domain);
6330 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6331 struct drm_atomic_state *old_state)
6333 struct intel_atomic_state *old_intel_state =
6334 to_intel_atomic_state(old_state);
6335 struct drm_crtc *crtc = pipe_config->base.crtc;
6336 struct drm_device *dev = crtc->dev;
6337 struct drm_i915_private *dev_priv = to_i915(dev);
6338 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6339 int pipe = intel_crtc->pipe;
6341 if (WARN_ON(intel_crtc->active))
6344 if (intel_crtc_has_dp_encoder(pipe_config))
6345 intel_dp_set_m_n(pipe_config, M1_N1);
6347 intel_set_pipe_timings(pipe_config);
6348 intel_set_pipe_src_size(pipe_config);
6350 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6351 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6352 I915_WRITE(CHV_CANVAS(pipe), 0);
6355 i9xx_set_pipeconf(pipe_config);
6357 intel_crtc->active = true;
6359 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6361 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
6363 if (IS_CHERRYVIEW(dev_priv)) {
6364 chv_prepare_pll(intel_crtc, pipe_config);
6365 chv_enable_pll(intel_crtc, pipe_config);
6367 vlv_prepare_pll(intel_crtc, pipe_config);
6368 vlv_enable_pll(intel_crtc, pipe_config);
6371 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6373 i9xx_pfit_enable(pipe_config);
6375 intel_color_load_luts(pipe_config);
6376 intel_color_commit(pipe_config);
6378 dev_priv->display.initial_watermarks(old_intel_state,
6380 intel_enable_pipe(pipe_config);
6382 assert_vblank_disabled(crtc);
6383 intel_crtc_vblank_on(pipe_config);
6385 intel_encoders_enable(crtc, pipe_config, old_state);
6388 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
6390 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6391 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6393 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6394 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
6397 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6398 struct drm_atomic_state *old_state)
6400 struct intel_atomic_state *old_intel_state =
6401 to_intel_atomic_state(old_state);
6402 struct drm_crtc *crtc = pipe_config->base.crtc;
6403 struct drm_device *dev = crtc->dev;
6404 struct drm_i915_private *dev_priv = to_i915(dev);
6405 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6406 enum pipe pipe = intel_crtc->pipe;
6408 if (WARN_ON(intel_crtc->active))
6411 i9xx_set_pll_dividers(pipe_config);
6413 if (intel_crtc_has_dp_encoder(pipe_config))
6414 intel_dp_set_m_n(pipe_config, M1_N1);
6416 intel_set_pipe_timings(pipe_config);
6417 intel_set_pipe_src_size(pipe_config);
6419 i9xx_set_pipeconf(pipe_config);
6421 intel_crtc->active = true;
6423 if (!IS_GEN(dev_priv, 2))
6424 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6426 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6428 i9xx_enable_pll(intel_crtc, pipe_config);
6430 i9xx_pfit_enable(pipe_config);
6432 intel_color_load_luts(pipe_config);
6433 intel_color_commit(pipe_config);
6435 if (dev_priv->display.initial_watermarks != NULL)
6436 dev_priv->display.initial_watermarks(old_intel_state,
6439 intel_update_watermarks(intel_crtc);
6440 intel_enable_pipe(pipe_config);
6442 assert_vblank_disabled(crtc);
6443 intel_crtc_vblank_on(pipe_config);
6445 intel_encoders_enable(crtc, pipe_config, old_state);
6448 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6450 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6451 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6453 if (!old_crtc_state->gmch_pfit.control)
6456 assert_pipe_disabled(dev_priv, crtc->pipe);
6458 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6459 I915_READ(PFIT_CONTROL));
6460 I915_WRITE(PFIT_CONTROL, 0);
6463 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6464 struct drm_atomic_state *old_state)
6466 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6467 struct drm_device *dev = crtc->dev;
6468 struct drm_i915_private *dev_priv = to_i915(dev);
6469 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6470 int pipe = intel_crtc->pipe;
6473 * On gen2 planes are double buffered but the pipe isn't, so we must
6474 * wait for planes to fully turn off before disabling the pipe.
6476 if (IS_GEN(dev_priv, 2))
6477 intel_wait_for_vblank(dev_priv, pipe);
6479 intel_encoders_disable(crtc, old_crtc_state, old_state);
6481 drm_crtc_vblank_off(crtc);
6482 assert_vblank_disabled(crtc);
6484 intel_disable_pipe(old_crtc_state);
6486 i9xx_pfit_disable(old_crtc_state);
6488 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6490 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
6491 if (IS_CHERRYVIEW(dev_priv))
6492 chv_disable_pll(dev_priv, pipe);
6493 else if (IS_VALLEYVIEW(dev_priv))
6494 vlv_disable_pll(dev_priv, pipe);
6496 i9xx_disable_pll(old_crtc_state);
6499 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6501 if (!IS_GEN(dev_priv, 2))
6502 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6504 if (!dev_priv->display.initial_watermarks)
6505 intel_update_watermarks(intel_crtc);
6507 /* clock the pipe down to 640x480@60 to potentially save power */
6508 if (IS_I830(dev_priv))
6509 i830_enable_pipe(dev_priv, pipe);
6512 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6513 struct drm_modeset_acquire_ctx *ctx)
6515 struct intel_encoder *encoder;
6516 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6517 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6518 enum intel_display_power_domain domain;
6519 struct intel_plane *plane;
6521 struct drm_atomic_state *state;
6522 struct intel_crtc_state *crtc_state;
6525 if (!intel_crtc->active)
6528 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6529 const struct intel_plane_state *plane_state =
6530 to_intel_plane_state(plane->base.state);
6532 if (plane_state->base.visible)
6533 intel_plane_disable_noatomic(intel_crtc, plane);
6536 state = drm_atomic_state_alloc(crtc->dev);
6538 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6539 crtc->base.id, crtc->name);
6543 state->acquire_ctx = ctx;
6545 /* Everything's already locked, -EDEADLK can't happen. */
6546 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6547 ret = drm_atomic_add_affected_connectors(state, crtc);
6549 WARN_ON(IS_ERR(crtc_state) || ret);
6551 dev_priv->display.crtc_disable(crtc_state, state);
6553 drm_atomic_state_put(state);
6555 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6556 crtc->base.id, crtc->name);
6558 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6559 crtc->state->active = false;
6560 intel_crtc->active = false;
6561 crtc->enabled = false;
6562 crtc->state->connector_mask = 0;
6563 crtc->state->encoder_mask = 0;
6565 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6566 encoder->base.crtc = NULL;
6568 intel_fbc_disable(intel_crtc);
6569 intel_update_watermarks(intel_crtc);
6570 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
6572 domains = intel_crtc->enabled_power_domains;
6573 for_each_power_domain(domain, domains)
6574 intel_display_power_put_unchecked(dev_priv, domain);
6575 intel_crtc->enabled_power_domains = 0;
6577 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6578 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6579 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6583 * turn all crtc's off, but do not adjust state
6584 * This has to be paired with a call to intel_modeset_setup_hw_state.
6586 int intel_display_suspend(struct drm_device *dev)
6588 struct drm_i915_private *dev_priv = to_i915(dev);
6589 struct drm_atomic_state *state;
6592 state = drm_atomic_helper_suspend(dev);
6593 ret = PTR_ERR_OR_ZERO(state);
6595 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6597 dev_priv->modeset_restore_state = state;
6601 void intel_encoder_destroy(struct drm_encoder *encoder)
6603 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6605 drm_encoder_cleanup(encoder);
6606 kfree(intel_encoder);
6609 /* Cross check the actual hw state with our own modeset state tracking (and it's
6610 * internal consistency). */
6611 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6612 struct drm_connector_state *conn_state)
6614 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6616 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6617 connector->base.base.id,
6618 connector->base.name);
6620 if (connector->get_hw_state(connector)) {
6621 struct intel_encoder *encoder = connector->encoder;
6623 I915_STATE_WARN(!crtc_state,
6624 "connector enabled without attached crtc\n");
6629 I915_STATE_WARN(!crtc_state->active,
6630 "connector is active, but attached crtc isn't\n");
6632 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6635 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6636 "atomic encoder doesn't match attached encoder\n");
6638 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6639 "attached encoder crtc differs from connector crtc\n");
6641 I915_STATE_WARN(crtc_state && crtc_state->active,
6642 "attached crtc is active, but connector isn't\n");
6643 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6644 "best encoder set without crtc!\n");
6648 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6650 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6651 return crtc_state->fdi_lanes;
6656 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6657 struct intel_crtc_state *pipe_config)
6659 struct drm_i915_private *dev_priv = to_i915(dev);
6660 struct drm_atomic_state *state = pipe_config->base.state;
6661 struct intel_crtc *other_crtc;
6662 struct intel_crtc_state *other_crtc_state;
6664 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6665 pipe_name(pipe), pipe_config->fdi_lanes);
6666 if (pipe_config->fdi_lanes > 4) {
6667 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6668 pipe_name(pipe), pipe_config->fdi_lanes);
6672 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6673 if (pipe_config->fdi_lanes > 2) {
6674 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6675 pipe_config->fdi_lanes);
6682 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6685 /* Ivybridge 3 pipe is really complicated */
6690 if (pipe_config->fdi_lanes <= 2)
6693 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6695 intel_atomic_get_crtc_state(state, other_crtc);
6696 if (IS_ERR(other_crtc_state))
6697 return PTR_ERR(other_crtc_state);
6699 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6700 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6701 pipe_name(pipe), pipe_config->fdi_lanes);
6706 if (pipe_config->fdi_lanes > 2) {
6707 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6708 pipe_name(pipe), pipe_config->fdi_lanes);
6712 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6714 intel_atomic_get_crtc_state(state, other_crtc);
6715 if (IS_ERR(other_crtc_state))
6716 return PTR_ERR(other_crtc_state);
6718 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6719 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6729 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6730 struct intel_crtc_state *pipe_config)
6732 struct drm_device *dev = intel_crtc->base.dev;
6733 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6734 int lane, link_bw, fdi_dotclock, ret;
6735 bool needs_recompute = false;
6738 /* FDI is a binary signal running at ~2.7GHz, encoding
6739 * each output octet as 10 bits. The actual frequency
6740 * is stored as a divider into a 100MHz clock, and the
6741 * mode pixel clock is stored in units of 1KHz.
6742 * Hence the bw of each lane in terms of the mode signal
6745 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6747 fdi_dotclock = adjusted_mode->crtc_clock;
6749 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6750 pipe_config->pipe_bpp);
6752 pipe_config->fdi_lanes = lane;
6754 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6755 link_bw, &pipe_config->fdi_m_n, false);
6757 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6758 if (ret == -EDEADLK)
6761 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6762 pipe_config->pipe_bpp -= 2*3;
6763 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6764 pipe_config->pipe_bpp);
6765 needs_recompute = true;
6766 pipe_config->bw_constrained = true;
6771 if (needs_recompute)
6777 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6779 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6780 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6782 /* IPS only exists on ULT machines and is tied to pipe A. */
6783 if (!hsw_crtc_supports_ips(crtc))
6786 if (!i915_modparams.enable_ips)
6789 if (crtc_state->pipe_bpp > 24)
6793 * We compare against max which means we must take
6794 * the increased cdclk requirement into account when
6795 * calculating the new cdclk.
6797 * Should measure whether using a lower cdclk w/o IPS
6799 if (IS_BROADWELL(dev_priv) &&
6800 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6806 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6808 struct drm_i915_private *dev_priv =
6809 to_i915(crtc_state->base.crtc->dev);
6810 struct intel_atomic_state *intel_state =
6811 to_intel_atomic_state(crtc_state->base.state);
6813 if (!hsw_crtc_state_ips_capable(crtc_state))
6816 if (crtc_state->ips_force_disable)
6819 /* IPS should be fine as long as at least one plane is enabled. */
6820 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6823 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6824 if (IS_BROADWELL(dev_priv) &&
6825 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6831 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6833 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6835 /* GDG double wide on either pipe, otherwise pipe A only */
6836 return INTEL_GEN(dev_priv) < 4 &&
6837 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6840 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6844 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6847 * We only use IF-ID interlacing. If we ever use
6848 * PF-ID we'll need to adjust the pixel_rate here.
6851 if (pipe_config->pch_pfit.enabled) {
6852 u64 pipe_w, pipe_h, pfit_w, pfit_h;
6853 u32 pfit_size = pipe_config->pch_pfit.size;
6855 pipe_w = pipe_config->pipe_src_w;
6856 pipe_h = pipe_config->pipe_src_h;
6858 pfit_w = (pfit_size >> 16) & 0xFFFF;
6859 pfit_h = pfit_size & 0xFFFF;
6860 if (pipe_w < pfit_w)
6862 if (pipe_h < pfit_h)
6865 if (WARN_ON(!pfit_w || !pfit_h))
6868 pixel_rate = div_u64((u64)pixel_rate * pipe_w * pipe_h,
6875 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6877 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6879 if (HAS_GMCH(dev_priv))
6880 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6881 crtc_state->pixel_rate =
6882 crtc_state->base.adjusted_mode.crtc_clock;
6884 crtc_state->pixel_rate =
6885 ilk_pipe_pixel_rate(crtc_state);
6888 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6889 struct intel_crtc_state *pipe_config)
6891 struct drm_device *dev = crtc->base.dev;
6892 struct drm_i915_private *dev_priv = to_i915(dev);
6893 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6894 int clock_limit = dev_priv->max_dotclk_freq;
6896 if (INTEL_GEN(dev_priv) < 4) {
6897 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6900 * Enable double wide mode when the dot clock
6901 * is > 90% of the (display) core speed.
6903 if (intel_crtc_supports_double_wide(crtc) &&
6904 adjusted_mode->crtc_clock > clock_limit) {
6905 clock_limit = dev_priv->max_dotclk_freq;
6906 pipe_config->double_wide = true;
6910 if (adjusted_mode->crtc_clock > clock_limit) {
6911 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6912 adjusted_mode->crtc_clock, clock_limit,
6913 yesno(pipe_config->double_wide));
6917 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6918 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6919 pipe_config->base.ctm) {
6921 * There is only one pipe CSC unit per pipe, and we need that
6922 * for output conversion from RGB->YCBCR. So if CTM is already
6923 * applied we can't support YCBCR420 output.
6925 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6930 * Pipe horizontal size must be even in:
6932 * - LVDS dual channel mode
6933 * - Double wide pipe
6935 if (pipe_config->pipe_src_w & 1) {
6936 if (pipe_config->double_wide) {
6937 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6941 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6942 intel_is_dual_link_lvds(dev)) {
6943 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6948 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6949 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6951 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6952 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6955 intel_crtc_compute_pixel_rate(pipe_config);
6957 if (pipe_config->has_pch_encoder)
6958 return ironlake_fdi_compute_config(crtc, pipe_config);
6964 intel_reduce_m_n_ratio(u32 *num, u32 *den)
6966 while (*num > DATA_LINK_M_N_MASK ||
6967 *den > DATA_LINK_M_N_MASK) {
6973 static void compute_m_n(unsigned int m, unsigned int n,
6974 u32 *ret_m, u32 *ret_n,
6978 * Several DP dongles in particular seem to be fussy about
6979 * too large link M/N values. Give N value as 0x8000 that
6980 * should be acceptable by specific devices. 0x8000 is the
6981 * specified fixed N value for asynchronous clock mode,
6982 * which the devices expect also in synchronous clock mode.
6987 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6989 *ret_m = div_u64((u64)m * *ret_n, n);
6990 intel_reduce_m_n_ratio(ret_m, ret_n);
6994 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
6995 int pixel_clock, int link_clock,
6996 struct intel_link_m_n *m_n,
7001 compute_m_n(bits_per_pixel * pixel_clock,
7002 link_clock * nlanes * 8,
7003 &m_n->gmch_m, &m_n->gmch_n,
7006 compute_m_n(pixel_clock, link_clock,
7007 &m_n->link_m, &m_n->link_n,
7011 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
7013 if (i915_modparams.panel_use_ssc >= 0)
7014 return i915_modparams.panel_use_ssc != 0;
7015 return dev_priv->vbt.lvds_use_ssc
7016 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
7019 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
7021 return (1 << dpll->n) << 16 | dpll->m2;
7024 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7026 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7029 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7030 struct intel_crtc_state *crtc_state,
7031 struct dpll *reduced_clock)
7033 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7036 if (IS_PINEVIEW(dev_priv)) {
7037 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7039 fp2 = pnv_dpll_compute_fp(reduced_clock);
7041 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7043 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7046 crtc_state->dpll_hw_state.fp0 = fp;
7048 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7050 crtc_state->dpll_hw_state.fp1 = fp2;
7052 crtc_state->dpll_hw_state.fp1 = fp;
7056 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7062 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7063 * and set it to a reasonable value instead.
7065 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7066 reg_val &= 0xffffff00;
7067 reg_val |= 0x00000030;
7068 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7070 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7071 reg_val &= 0x00ffffff;
7072 reg_val |= 0x8c000000;
7073 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7075 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7076 reg_val &= 0xffffff00;
7077 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7079 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7080 reg_val &= 0x00ffffff;
7081 reg_val |= 0xb0000000;
7082 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7085 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7086 const struct intel_link_m_n *m_n)
7088 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7089 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7090 enum pipe pipe = crtc->pipe;
7092 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7093 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7094 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7095 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7098 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7099 enum transcoder transcoder)
7101 if (IS_HASWELL(dev_priv))
7102 return transcoder == TRANSCODER_EDP;
7105 * Strictly speaking some registers are available before
7106 * gen7, but we only support DRRS on gen7+
7108 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
7111 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7112 const struct intel_link_m_n *m_n,
7113 const struct intel_link_m_n *m2_n2)
7115 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7116 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7117 enum pipe pipe = crtc->pipe;
7118 enum transcoder transcoder = crtc_state->cpu_transcoder;
7120 if (INTEL_GEN(dev_priv) >= 5) {
7121 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7122 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7123 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7124 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7126 * M2_N2 registers are set only if DRRS is supported
7127 * (to make sure the registers are not unnecessarily accessed).
7129 if (m2_n2 && crtc_state->has_drrs &&
7130 transcoder_has_m2_n2(dev_priv, transcoder)) {
7131 I915_WRITE(PIPE_DATA_M2(transcoder),
7132 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7133 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7134 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7135 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7138 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7139 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7140 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7141 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
7145 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
7147 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
7150 dp_m_n = &crtc_state->dp_m_n;
7151 dp_m2_n2 = &crtc_state->dp_m2_n2;
7152 } else if (m_n == M2_N2) {
7155 * M2_N2 registers are not supported. Hence m2_n2 divider value
7156 * needs to be programmed into M1_N1.
7158 dp_m_n = &crtc_state->dp_m2_n2;
7160 DRM_ERROR("Unsupported divider value\n");
7164 if (crtc_state->has_pch_encoder)
7165 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
7167 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
7170 static void vlv_compute_dpll(struct intel_crtc *crtc,
7171 struct intel_crtc_state *pipe_config)
7173 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
7174 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7175 if (crtc->pipe != PIPE_A)
7176 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7178 /* DPLL not used with DSI, but still need the rest set up */
7179 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7180 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7181 DPLL_EXT_BUFFER_ENABLE_VLV;
7183 pipe_config->dpll_hw_state.dpll_md =
7184 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7187 static void chv_compute_dpll(struct intel_crtc *crtc,
7188 struct intel_crtc_state *pipe_config)
7190 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
7191 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7192 if (crtc->pipe != PIPE_A)
7193 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7195 /* DPLL not used with DSI, but still need the rest set up */
7196 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7197 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
7199 pipe_config->dpll_hw_state.dpll_md =
7200 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7203 static void vlv_prepare_pll(struct intel_crtc *crtc,
7204 const struct intel_crtc_state *pipe_config)
7206 struct drm_device *dev = crtc->base.dev;
7207 struct drm_i915_private *dev_priv = to_i915(dev);
7208 enum pipe pipe = crtc->pipe;
7210 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7211 u32 coreclk, reg_val;
7214 I915_WRITE(DPLL(pipe),
7215 pipe_config->dpll_hw_state.dpll &
7216 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7218 /* No need to actually set up the DPLL with DSI */
7219 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7222 mutex_lock(&dev_priv->sb_lock);
7224 bestn = pipe_config->dpll.n;
7225 bestm1 = pipe_config->dpll.m1;
7226 bestm2 = pipe_config->dpll.m2;
7227 bestp1 = pipe_config->dpll.p1;
7228 bestp2 = pipe_config->dpll.p2;
7230 /* See eDP HDMI DPIO driver vbios notes doc */
7232 /* PLL B needs special handling */
7234 vlv_pllb_recal_opamp(dev_priv, pipe);
7236 /* Set up Tx target for periodic Rcomp update */
7237 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7239 /* Disable target IRef on PLL */
7240 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7241 reg_val &= 0x00ffffff;
7242 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7244 /* Disable fast lock */
7245 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7247 /* Set idtafcrecal before PLL is enabled */
7248 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7249 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7250 mdiv |= ((bestn << DPIO_N_SHIFT));
7251 mdiv |= (1 << DPIO_K_SHIFT);
7254 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7255 * but we don't support that).
7256 * Note: don't use the DAC post divider as it seems unstable.
7258 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7259 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7261 mdiv |= DPIO_ENABLE_CALIBRATION;
7262 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7264 /* Set HBR and RBR LPF coefficients */
7265 if (pipe_config->port_clock == 162000 ||
7266 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7267 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
7268 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7271 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7274 if (intel_crtc_has_dp_encoder(pipe_config)) {
7275 /* Use SSC source */
7277 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7280 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7282 } else { /* HDMI or VGA */
7283 /* Use bend source */
7285 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7288 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7292 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7293 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7294 if (intel_crtc_has_dp_encoder(pipe_config))
7295 coreclk |= 0x01000000;
7296 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7298 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7299 mutex_unlock(&dev_priv->sb_lock);
7302 static void chv_prepare_pll(struct intel_crtc *crtc,
7303 const struct intel_crtc_state *pipe_config)
7305 struct drm_device *dev = crtc->base.dev;
7306 struct drm_i915_private *dev_priv = to_i915(dev);
7307 enum pipe pipe = crtc->pipe;
7308 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7309 u32 loopfilter, tribuf_calcntr;
7310 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7314 /* Enable Refclk and SSC */
7315 I915_WRITE(DPLL(pipe),
7316 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7318 /* No need to actually set up the DPLL with DSI */
7319 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7322 bestn = pipe_config->dpll.n;
7323 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7324 bestm1 = pipe_config->dpll.m1;
7325 bestm2 = pipe_config->dpll.m2 >> 22;
7326 bestp1 = pipe_config->dpll.p1;
7327 bestp2 = pipe_config->dpll.p2;
7328 vco = pipe_config->dpll.vco;
7332 mutex_lock(&dev_priv->sb_lock);
7334 /* p1 and p2 divider */
7335 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7336 5 << DPIO_CHV_S1_DIV_SHIFT |
7337 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7338 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7339 1 << DPIO_CHV_K_DIV_SHIFT);
7341 /* Feedback post-divider - m2 */
7342 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7344 /* Feedback refclk divider - n and m1 */
7345 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7346 DPIO_CHV_M1_DIV_BY_2 |
7347 1 << DPIO_CHV_N_DIV_SHIFT);
7349 /* M2 fraction division */
7350 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7352 /* M2 fraction division enable */
7353 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7354 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7355 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7357 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7358 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7360 /* Program digital lock detect threshold */
7361 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7362 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7363 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7364 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7366 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7367 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7370 if (vco == 5400000) {
7371 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7372 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7373 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7374 tribuf_calcntr = 0x9;
7375 } else if (vco <= 6200000) {
7376 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7377 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7378 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7379 tribuf_calcntr = 0x9;
7380 } else if (vco <= 6480000) {
7381 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7382 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7383 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7384 tribuf_calcntr = 0x8;
7386 /* Not supported. Apply the same limits as in the max case */
7387 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7388 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7389 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7392 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7394 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7395 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7396 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7397 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7400 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7401 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7404 mutex_unlock(&dev_priv->sb_lock);
7408 * vlv_force_pll_on - forcibly enable just the PLL
7409 * @dev_priv: i915 private structure
7410 * @pipe: pipe PLL to enable
7411 * @dpll: PLL configuration
7413 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7414 * in cases where we need the PLL enabled even when @pipe is not going to
7417 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7418 const struct dpll *dpll)
7420 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7421 struct intel_crtc_state *pipe_config;
7423 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7427 pipe_config->base.crtc = &crtc->base;
7428 pipe_config->pixel_multiplier = 1;
7429 pipe_config->dpll = *dpll;
7431 if (IS_CHERRYVIEW(dev_priv)) {
7432 chv_compute_dpll(crtc, pipe_config);
7433 chv_prepare_pll(crtc, pipe_config);
7434 chv_enable_pll(crtc, pipe_config);
7436 vlv_compute_dpll(crtc, pipe_config);
7437 vlv_prepare_pll(crtc, pipe_config);
7438 vlv_enable_pll(crtc, pipe_config);
7447 * vlv_force_pll_off - forcibly disable just the PLL
7448 * @dev_priv: i915 private structure
7449 * @pipe: pipe PLL to disable
7451 * Disable the PLL for @pipe. To be used in cases where we need
7452 * the PLL enabled even when @pipe is not going to be enabled.
7454 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7456 if (IS_CHERRYVIEW(dev_priv))
7457 chv_disable_pll(dev_priv, pipe);
7459 vlv_disable_pll(dev_priv, pipe);
7462 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7463 struct intel_crtc_state *crtc_state,
7464 struct dpll *reduced_clock)
7466 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7468 struct dpll *clock = &crtc_state->dpll;
7470 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7472 dpll = DPLL_VGA_MODE_DIS;
7474 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7475 dpll |= DPLLB_MODE_LVDS;
7477 dpll |= DPLLB_MODE_DAC_SERIAL;
7479 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7480 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7481 dpll |= (crtc_state->pixel_multiplier - 1)
7482 << SDVO_MULTIPLIER_SHIFT_HIRES;
7485 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7486 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7487 dpll |= DPLL_SDVO_HIGH_SPEED;
7489 if (intel_crtc_has_dp_encoder(crtc_state))
7490 dpll |= DPLL_SDVO_HIGH_SPEED;
7492 /* compute bitmask from p1 value */
7493 if (IS_PINEVIEW(dev_priv))
7494 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7496 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7497 if (IS_G4X(dev_priv) && reduced_clock)
7498 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7500 switch (clock->p2) {
7502 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7505 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7508 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7511 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7514 if (INTEL_GEN(dev_priv) >= 4)
7515 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7517 if (crtc_state->sdvo_tv_clock)
7518 dpll |= PLL_REF_INPUT_TVCLKINBC;
7519 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7520 intel_panel_use_ssc(dev_priv))
7521 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7523 dpll |= PLL_REF_INPUT_DREFCLK;
7525 dpll |= DPLL_VCO_ENABLE;
7526 crtc_state->dpll_hw_state.dpll = dpll;
7528 if (INTEL_GEN(dev_priv) >= 4) {
7529 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7530 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7531 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7535 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7536 struct intel_crtc_state *crtc_state,
7537 struct dpll *reduced_clock)
7539 struct drm_device *dev = crtc->base.dev;
7540 struct drm_i915_private *dev_priv = to_i915(dev);
7542 struct dpll *clock = &crtc_state->dpll;
7544 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7546 dpll = DPLL_VGA_MODE_DIS;
7548 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7549 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7552 dpll |= PLL_P1_DIVIDE_BY_TWO;
7554 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7556 dpll |= PLL_P2_DIVIDE_BY_4;
7559 if (!IS_I830(dev_priv) &&
7560 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7561 dpll |= DPLL_DVO_2X_MODE;
7563 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7564 intel_panel_use_ssc(dev_priv))
7565 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7567 dpll |= PLL_REF_INPUT_DREFCLK;
7569 dpll |= DPLL_VCO_ENABLE;
7570 crtc_state->dpll_hw_state.dpll = dpll;
7573 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
7575 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7576 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7577 enum pipe pipe = crtc->pipe;
7578 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7579 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
7580 u32 crtc_vtotal, crtc_vblank_end;
7583 /* We need to be careful not to changed the adjusted mode, for otherwise
7584 * the hw state checker will get angry at the mismatch. */
7585 crtc_vtotal = adjusted_mode->crtc_vtotal;
7586 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7588 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7589 /* the chip adds 2 halflines automatically */
7591 crtc_vblank_end -= 1;
7593 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7594 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7596 vsyncshift = adjusted_mode->crtc_hsync_start -
7597 adjusted_mode->crtc_htotal / 2;
7599 vsyncshift += adjusted_mode->crtc_htotal;
7602 if (INTEL_GEN(dev_priv) > 3)
7603 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7605 I915_WRITE(HTOTAL(cpu_transcoder),
7606 (adjusted_mode->crtc_hdisplay - 1) |
7607 ((adjusted_mode->crtc_htotal - 1) << 16));
7608 I915_WRITE(HBLANK(cpu_transcoder),
7609 (adjusted_mode->crtc_hblank_start - 1) |
7610 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7611 I915_WRITE(HSYNC(cpu_transcoder),
7612 (adjusted_mode->crtc_hsync_start - 1) |
7613 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7615 I915_WRITE(VTOTAL(cpu_transcoder),
7616 (adjusted_mode->crtc_vdisplay - 1) |
7617 ((crtc_vtotal - 1) << 16));
7618 I915_WRITE(VBLANK(cpu_transcoder),
7619 (adjusted_mode->crtc_vblank_start - 1) |
7620 ((crtc_vblank_end - 1) << 16));
7621 I915_WRITE(VSYNC(cpu_transcoder),
7622 (adjusted_mode->crtc_vsync_start - 1) |
7623 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7625 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7626 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7627 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7629 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7630 (pipe == PIPE_B || pipe == PIPE_C))
7631 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7635 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
7637 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7638 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7639 enum pipe pipe = crtc->pipe;
7641 /* pipesrc controls the size that is scaled from, which should
7642 * always be the user's requested size.
7644 I915_WRITE(PIPESRC(pipe),
7645 ((crtc_state->pipe_src_w - 1) << 16) |
7646 (crtc_state->pipe_src_h - 1));
7649 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7650 struct intel_crtc_state *pipe_config)
7652 struct drm_device *dev = crtc->base.dev;
7653 struct drm_i915_private *dev_priv = to_i915(dev);
7654 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7657 tmp = I915_READ(HTOTAL(cpu_transcoder));
7658 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7659 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7660 tmp = I915_READ(HBLANK(cpu_transcoder));
7661 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7662 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7663 tmp = I915_READ(HSYNC(cpu_transcoder));
7664 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7665 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7667 tmp = I915_READ(VTOTAL(cpu_transcoder));
7668 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7669 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7670 tmp = I915_READ(VBLANK(cpu_transcoder));
7671 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7672 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7673 tmp = I915_READ(VSYNC(cpu_transcoder));
7674 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7675 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7677 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7678 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7679 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7680 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7684 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7685 struct intel_crtc_state *pipe_config)
7687 struct drm_device *dev = crtc->base.dev;
7688 struct drm_i915_private *dev_priv = to_i915(dev);
7691 tmp = I915_READ(PIPESRC(crtc->pipe));
7692 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7693 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7695 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7696 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7699 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7700 struct intel_crtc_state *pipe_config)
7702 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7703 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7704 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7705 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7707 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7708 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7709 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7710 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7712 mode->flags = pipe_config->base.adjusted_mode.flags;
7713 mode->type = DRM_MODE_TYPE_DRIVER;
7715 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7717 mode->hsync = drm_mode_hsync(mode);
7718 mode->vrefresh = drm_mode_vrefresh(mode);
7719 drm_mode_set_name(mode);
7722 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
7724 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7725 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7730 /* we keep both pipes enabled on 830 */
7731 if (IS_I830(dev_priv))
7732 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
7734 if (crtc_state->double_wide)
7735 pipeconf |= PIPECONF_DOUBLE_WIDE;
7737 /* only g4x and later have fancy bpc/dither controls */
7738 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7739 IS_CHERRYVIEW(dev_priv)) {
7740 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7741 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
7742 pipeconf |= PIPECONF_DITHER_EN |
7743 PIPECONF_DITHER_TYPE_SP;
7745 switch (crtc_state->pipe_bpp) {
7747 pipeconf |= PIPECONF_6BPC;
7750 pipeconf |= PIPECONF_8BPC;
7753 pipeconf |= PIPECONF_10BPC;
7756 /* Case prevented by intel_choose_pipe_bpp_dither. */
7761 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7762 if (INTEL_GEN(dev_priv) < 4 ||
7763 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7764 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7766 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7768 pipeconf |= PIPECONF_PROGRESSIVE;
7770 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7771 crtc_state->limited_color_range)
7772 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7774 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7775 POSTING_READ(PIPECONF(crtc->pipe));
7778 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7779 struct intel_crtc_state *crtc_state)
7781 struct drm_device *dev = crtc->base.dev;
7782 struct drm_i915_private *dev_priv = to_i915(dev);
7783 const struct intel_limit *limit;
7786 memset(&crtc_state->dpll_hw_state, 0,
7787 sizeof(crtc_state->dpll_hw_state));
7789 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7790 if (intel_panel_use_ssc(dev_priv)) {
7791 refclk = dev_priv->vbt.lvds_ssc_freq;
7792 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7795 limit = &intel_limits_i8xx_lvds;
7796 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7797 limit = &intel_limits_i8xx_dvo;
7799 limit = &intel_limits_i8xx_dac;
7802 if (!crtc_state->clock_set &&
7803 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7804 refclk, NULL, &crtc_state->dpll)) {
7805 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7809 i8xx_compute_dpll(crtc, crtc_state, NULL);
7814 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7815 struct intel_crtc_state *crtc_state)
7817 struct drm_device *dev = crtc->base.dev;
7818 struct drm_i915_private *dev_priv = to_i915(dev);
7819 const struct intel_limit *limit;
7822 memset(&crtc_state->dpll_hw_state, 0,
7823 sizeof(crtc_state->dpll_hw_state));
7825 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7826 if (intel_panel_use_ssc(dev_priv)) {
7827 refclk = dev_priv->vbt.lvds_ssc_freq;
7828 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7831 if (intel_is_dual_link_lvds(dev))
7832 limit = &intel_limits_g4x_dual_channel_lvds;
7834 limit = &intel_limits_g4x_single_channel_lvds;
7835 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7836 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7837 limit = &intel_limits_g4x_hdmi;
7838 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7839 limit = &intel_limits_g4x_sdvo;
7841 /* The option is for other outputs */
7842 limit = &intel_limits_i9xx_sdvo;
7845 if (!crtc_state->clock_set &&
7846 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7847 refclk, NULL, &crtc_state->dpll)) {
7848 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7852 i9xx_compute_dpll(crtc, crtc_state, NULL);
7857 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7858 struct intel_crtc_state *crtc_state)
7860 struct drm_device *dev = crtc->base.dev;
7861 struct drm_i915_private *dev_priv = to_i915(dev);
7862 const struct intel_limit *limit;
7865 memset(&crtc_state->dpll_hw_state, 0,
7866 sizeof(crtc_state->dpll_hw_state));
7868 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7869 if (intel_panel_use_ssc(dev_priv)) {
7870 refclk = dev_priv->vbt.lvds_ssc_freq;
7871 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7874 limit = &intel_limits_pineview_lvds;
7876 limit = &intel_limits_pineview_sdvo;
7879 if (!crtc_state->clock_set &&
7880 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7881 refclk, NULL, &crtc_state->dpll)) {
7882 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7886 i9xx_compute_dpll(crtc, crtc_state, NULL);
7891 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7892 struct intel_crtc_state *crtc_state)
7894 struct drm_device *dev = crtc->base.dev;
7895 struct drm_i915_private *dev_priv = to_i915(dev);
7896 const struct intel_limit *limit;
7899 memset(&crtc_state->dpll_hw_state, 0,
7900 sizeof(crtc_state->dpll_hw_state));
7902 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7903 if (intel_panel_use_ssc(dev_priv)) {
7904 refclk = dev_priv->vbt.lvds_ssc_freq;
7905 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7908 limit = &intel_limits_i9xx_lvds;
7910 limit = &intel_limits_i9xx_sdvo;
7913 if (!crtc_state->clock_set &&
7914 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7915 refclk, NULL, &crtc_state->dpll)) {
7916 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7920 i9xx_compute_dpll(crtc, crtc_state, NULL);
7925 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7926 struct intel_crtc_state *crtc_state)
7928 int refclk = 100000;
7929 const struct intel_limit *limit = &intel_limits_chv;
7931 memset(&crtc_state->dpll_hw_state, 0,
7932 sizeof(crtc_state->dpll_hw_state));
7934 if (!crtc_state->clock_set &&
7935 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7936 refclk, NULL, &crtc_state->dpll)) {
7937 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7941 chv_compute_dpll(crtc, crtc_state);
7946 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7947 struct intel_crtc_state *crtc_state)
7949 int refclk = 100000;
7950 const struct intel_limit *limit = &intel_limits_vlv;
7952 memset(&crtc_state->dpll_hw_state, 0,
7953 sizeof(crtc_state->dpll_hw_state));
7955 if (!crtc_state->clock_set &&
7956 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7957 refclk, NULL, &crtc_state->dpll)) {
7958 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7962 vlv_compute_dpll(crtc, crtc_state);
7967 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7968 struct intel_crtc_state *pipe_config)
7970 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7973 if (INTEL_GEN(dev_priv) <= 3 &&
7974 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7977 tmp = I915_READ(PFIT_CONTROL);
7978 if (!(tmp & PFIT_ENABLE))
7981 /* Check whether the pfit is attached to our pipe. */
7982 if (INTEL_GEN(dev_priv) < 4) {
7983 if (crtc->pipe != PIPE_B)
7986 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7990 pipe_config->gmch_pfit.control = tmp;
7991 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7994 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7995 struct intel_crtc_state *pipe_config)
7997 struct drm_device *dev = crtc->base.dev;
7998 struct drm_i915_private *dev_priv = to_i915(dev);
7999 int pipe = pipe_config->cpu_transcoder;
8002 int refclk = 100000;
8004 /* In case of DSI, DPLL will not be used */
8005 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8008 mutex_lock(&dev_priv->sb_lock);
8009 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
8010 mutex_unlock(&dev_priv->sb_lock);
8012 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
8013 clock.m2 = mdiv & DPIO_M2DIV_MASK;
8014 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
8015 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
8016 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
8018 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8022 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8023 struct intel_initial_plane_config *plane_config)
8025 struct drm_device *dev = crtc->base.dev;
8026 struct drm_i915_private *dev_priv = to_i915(dev);
8027 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8028 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8030 u32 val, base, offset;
8031 int fourcc, pixel_format;
8032 unsigned int aligned_height;
8033 struct drm_framebuffer *fb;
8034 struct intel_framebuffer *intel_fb;
8036 if (!plane->get_hw_state(plane, &pipe))
8039 WARN_ON(pipe != crtc->pipe);
8041 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8043 DRM_DEBUG_KMS("failed to alloc fb\n");
8047 fb = &intel_fb->base;
8051 val = I915_READ(DSPCNTR(i9xx_plane));
8053 if (INTEL_GEN(dev_priv) >= 4) {
8054 if (val & DISPPLANE_TILED) {
8055 plane_config->tiling = I915_TILING_X;
8056 fb->modifier = I915_FORMAT_MOD_X_TILED;
8059 if (val & DISPPLANE_ROTATE_180)
8060 plane_config->rotation = DRM_MODE_ROTATE_180;
8063 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8064 val & DISPPLANE_MIRROR)
8065 plane_config->rotation |= DRM_MODE_REFLECT_X;
8067 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8068 fourcc = i9xx_format_to_fourcc(pixel_format);
8069 fb->format = drm_format_info(fourcc);
8071 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8072 offset = I915_READ(DSPOFFSET(i9xx_plane));
8073 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8074 } else if (INTEL_GEN(dev_priv) >= 4) {
8075 if (plane_config->tiling)
8076 offset = I915_READ(DSPTILEOFF(i9xx_plane));
8078 offset = I915_READ(DSPLINOFF(i9xx_plane));
8079 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8081 base = I915_READ(DSPADDR(i9xx_plane));
8083 plane_config->base = base;
8085 val = I915_READ(PIPESRC(pipe));
8086 fb->width = ((val >> 16) & 0xfff) + 1;
8087 fb->height = ((val >> 0) & 0xfff) + 1;
8089 val = I915_READ(DSPSTRIDE(i9xx_plane));
8090 fb->pitches[0] = val & 0xffffffc0;
8092 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8094 plane_config->size = fb->pitches[0] * aligned_height;
8096 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8097 crtc->base.name, plane->base.name, fb->width, fb->height,
8098 fb->format->cpp[0] * 8, base, fb->pitches[0],
8099 plane_config->size);
8101 plane_config->fb = intel_fb;
8104 static void chv_crtc_clock_get(struct intel_crtc *crtc,
8105 struct intel_crtc_state *pipe_config)
8107 struct drm_device *dev = crtc->base.dev;
8108 struct drm_i915_private *dev_priv = to_i915(dev);
8109 int pipe = pipe_config->cpu_transcoder;
8110 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8112 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
8113 int refclk = 100000;
8115 /* In case of DSI, DPLL will not be used */
8116 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8119 mutex_lock(&dev_priv->sb_lock);
8120 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8121 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8122 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8123 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
8124 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8125 mutex_unlock(&dev_priv->sb_lock);
8127 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
8128 clock.m2 = (pll_dw0 & 0xff) << 22;
8129 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
8130 clock.m2 |= pll_dw2 & 0x3fffff;
8131 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8132 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8133 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8135 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
8138 static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
8139 struct intel_crtc_state *pipe_config)
8141 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8142 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
8144 pipe_config->lspcon_downsampling = false;
8146 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8147 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
8149 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
8150 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
8151 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
8153 if (ycbcr420_enabled) {
8154 /* We support 4:2:0 in full blend mode only */
8156 output = INTEL_OUTPUT_FORMAT_INVALID;
8157 else if (!(IS_GEMINILAKE(dev_priv) ||
8158 INTEL_GEN(dev_priv) >= 10))
8159 output = INTEL_OUTPUT_FORMAT_INVALID;
8161 output = INTEL_OUTPUT_FORMAT_YCBCR420;
8164 * Currently there is no interface defined to
8165 * check user preference between RGB/YCBCR444
8166 * or YCBCR420. So the only possible case for
8167 * YCBCR444 usage is driving YCBCR420 output
8168 * with LSPCON, when pipe is configured for
8169 * YCBCR444 output and LSPCON takes care of
8172 pipe_config->lspcon_downsampling = true;
8173 output = INTEL_OUTPUT_FORMAT_YCBCR444;
8178 pipe_config->output_format = output;
8181 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
8182 struct intel_crtc_state *pipe_config)
8184 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8185 enum intel_display_power_domain power_domain;
8186 intel_wakeref_t wakeref;
8190 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8191 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8195 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
8196 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8197 pipe_config->shared_dpll = NULL;
8201 tmp = I915_READ(PIPECONF(crtc->pipe));
8202 if (!(tmp & PIPECONF_ENABLE))
8205 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8206 IS_CHERRYVIEW(dev_priv)) {
8207 switch (tmp & PIPECONF_BPC_MASK) {
8209 pipe_config->pipe_bpp = 18;
8212 pipe_config->pipe_bpp = 24;
8214 case PIPECONF_10BPC:
8215 pipe_config->pipe_bpp = 30;
8222 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8223 (tmp & PIPECONF_COLOR_RANGE_SELECT))
8224 pipe_config->limited_color_range = true;
8226 if (INTEL_GEN(dev_priv) < 4)
8227 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8229 intel_get_pipe_timings(crtc, pipe_config);
8230 intel_get_pipe_src_size(crtc, pipe_config);
8232 i9xx_get_pfit_config(crtc, pipe_config);
8234 if (INTEL_GEN(dev_priv) >= 4) {
8235 /* No way to read it out on pipes B and C */
8236 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
8237 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8239 tmp = I915_READ(DPLL_MD(crtc->pipe));
8240 pipe_config->pixel_multiplier =
8241 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8242 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8243 pipe_config->dpll_hw_state.dpll_md = tmp;
8244 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8245 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8246 tmp = I915_READ(DPLL(crtc->pipe));
8247 pipe_config->pixel_multiplier =
8248 ((tmp & SDVO_MULTIPLIER_MASK)
8249 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8251 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8252 * port and will be fixed up in the encoder->get_config
8254 pipe_config->pixel_multiplier = 1;
8256 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8257 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
8259 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8260 * on 830. Filter it out here so that we don't
8261 * report errors due to that.
8263 if (IS_I830(dev_priv))
8264 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8266 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8267 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8269 /* Mask out read-only status bits. */
8270 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8271 DPLL_PORTC_READY_MASK |
8272 DPLL_PORTB_READY_MASK);
8275 if (IS_CHERRYVIEW(dev_priv))
8276 chv_crtc_clock_get(crtc, pipe_config);
8277 else if (IS_VALLEYVIEW(dev_priv))
8278 vlv_crtc_clock_get(crtc, pipe_config);
8280 i9xx_crtc_clock_get(crtc, pipe_config);
8283 * Normally the dotclock is filled in by the encoder .get_config()
8284 * but in case the pipe is enabled w/o any ports we need a sane
8287 pipe_config->base.adjusted_mode.crtc_clock =
8288 pipe_config->port_clock / pipe_config->pixel_multiplier;
8293 intel_display_power_put(dev_priv, power_domain, wakeref);
8298 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
8300 struct intel_encoder *encoder;
8303 bool has_lvds = false;
8304 bool has_cpu_edp = false;
8305 bool has_panel = false;
8306 bool has_ck505 = false;
8307 bool can_ssc = false;
8308 bool using_ssc_source = false;
8310 /* We need to take the global config into account */
8311 for_each_intel_encoder(&dev_priv->drm, encoder) {
8312 switch (encoder->type) {
8313 case INTEL_OUTPUT_LVDS:
8317 case INTEL_OUTPUT_EDP:
8319 if (encoder->port == PORT_A)
8327 if (HAS_PCH_IBX(dev_priv)) {
8328 has_ck505 = dev_priv->vbt.display_clock_mode;
8329 can_ssc = has_ck505;
8335 /* Check if any DPLLs are using the SSC source */
8336 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8337 u32 temp = I915_READ(PCH_DPLL(i));
8339 if (!(temp & DPLL_VCO_ENABLE))
8342 if ((temp & PLL_REF_INPUT_MASK) ==
8343 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8344 using_ssc_source = true;
8349 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8350 has_panel, has_lvds, has_ck505, using_ssc_source);
8352 /* Ironlake: try to setup display ref clock before DPLL
8353 * enabling. This is only under driver's control after
8354 * PCH B stepping, previous chipset stepping should be
8355 * ignoring this setting.
8357 val = I915_READ(PCH_DREF_CONTROL);
8359 /* As we must carefully and slowly disable/enable each source in turn,
8360 * compute the final state we want first and check if we need to
8361 * make any changes at all.
8364 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8366 final |= DREF_NONSPREAD_CK505_ENABLE;
8368 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8370 final &= ~DREF_SSC_SOURCE_MASK;
8371 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8372 final &= ~DREF_SSC1_ENABLE;
8375 final |= DREF_SSC_SOURCE_ENABLE;
8377 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8378 final |= DREF_SSC1_ENABLE;
8381 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8382 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8384 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8386 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8387 } else if (using_ssc_source) {
8388 final |= DREF_SSC_SOURCE_ENABLE;
8389 final |= DREF_SSC1_ENABLE;
8395 /* Always enable nonspread source */
8396 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8399 val |= DREF_NONSPREAD_CK505_ENABLE;
8401 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8404 val &= ~DREF_SSC_SOURCE_MASK;
8405 val |= DREF_SSC_SOURCE_ENABLE;
8407 /* SSC must be turned on before enabling the CPU output */
8408 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8409 DRM_DEBUG_KMS("Using SSC on panel\n");
8410 val |= DREF_SSC1_ENABLE;
8412 val &= ~DREF_SSC1_ENABLE;
8414 /* Get SSC going before enabling the outputs */
8415 I915_WRITE(PCH_DREF_CONTROL, val);
8416 POSTING_READ(PCH_DREF_CONTROL);
8419 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8421 /* Enable CPU source on CPU attached eDP */
8423 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8424 DRM_DEBUG_KMS("Using SSC on eDP\n");
8425 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8427 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8429 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8431 I915_WRITE(PCH_DREF_CONTROL, val);
8432 POSTING_READ(PCH_DREF_CONTROL);
8435 DRM_DEBUG_KMS("Disabling CPU source output\n");
8437 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8439 /* Turn off CPU output */
8440 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8442 I915_WRITE(PCH_DREF_CONTROL, val);
8443 POSTING_READ(PCH_DREF_CONTROL);
8446 if (!using_ssc_source) {
8447 DRM_DEBUG_KMS("Disabling SSC source\n");
8449 /* Turn off the SSC source */
8450 val &= ~DREF_SSC_SOURCE_MASK;
8451 val |= DREF_SSC_SOURCE_DISABLE;
8454 val &= ~DREF_SSC1_ENABLE;
8456 I915_WRITE(PCH_DREF_CONTROL, val);
8457 POSTING_READ(PCH_DREF_CONTROL);
8462 BUG_ON(val != final);
8465 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8469 tmp = I915_READ(SOUTH_CHICKEN2);
8470 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8471 I915_WRITE(SOUTH_CHICKEN2, tmp);
8473 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8474 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8475 DRM_ERROR("FDI mPHY reset assert timeout\n");
8477 tmp = I915_READ(SOUTH_CHICKEN2);
8478 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8479 I915_WRITE(SOUTH_CHICKEN2, tmp);
8481 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8482 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8483 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8486 /* WaMPhyProgramming:hsw */
8487 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8491 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8492 tmp &= ~(0xFF << 24);
8493 tmp |= (0x12 << 24);
8494 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8496 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8498 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8500 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8502 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8504 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8505 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8506 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8508 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8509 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8510 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8512 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8515 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8517 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8520 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8522 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8525 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8527 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8530 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8532 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8533 tmp &= ~(0xFF << 16);
8534 tmp |= (0x1C << 16);
8535 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8537 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8538 tmp &= ~(0xFF << 16);
8539 tmp |= (0x1C << 16);
8540 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8542 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8544 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8546 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8548 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8550 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8551 tmp &= ~(0xF << 28);
8553 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8555 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8556 tmp &= ~(0xF << 28);
8558 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8561 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8562 * Programming" based on the parameters passed:
8563 * - Sequence to enable CLKOUT_DP
8564 * - Sequence to enable CLKOUT_DP without spread
8565 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8567 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8568 bool with_spread, bool with_fdi)
8572 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8574 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8575 with_fdi, "LP PCH doesn't have FDI\n"))
8578 mutex_lock(&dev_priv->sb_lock);
8580 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8581 tmp &= ~SBI_SSCCTL_DISABLE;
8582 tmp |= SBI_SSCCTL_PATHALT;
8583 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8588 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8589 tmp &= ~SBI_SSCCTL_PATHALT;
8590 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8593 lpt_reset_fdi_mphy(dev_priv);
8594 lpt_program_fdi_mphy(dev_priv);
8598 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8599 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8600 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8601 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8603 mutex_unlock(&dev_priv->sb_lock);
8606 /* Sequence to disable CLKOUT_DP */
8607 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8611 mutex_lock(&dev_priv->sb_lock);
8613 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8614 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8615 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8616 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8618 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8619 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8620 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8621 tmp |= SBI_SSCCTL_PATHALT;
8622 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8625 tmp |= SBI_SSCCTL_DISABLE;
8626 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8629 mutex_unlock(&dev_priv->sb_lock);
8632 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8634 static const u16 sscdivintphase[] = {
8635 [BEND_IDX( 50)] = 0x3B23,
8636 [BEND_IDX( 45)] = 0x3B23,
8637 [BEND_IDX( 40)] = 0x3C23,
8638 [BEND_IDX( 35)] = 0x3C23,
8639 [BEND_IDX( 30)] = 0x3D23,
8640 [BEND_IDX( 25)] = 0x3D23,
8641 [BEND_IDX( 20)] = 0x3E23,
8642 [BEND_IDX( 15)] = 0x3E23,
8643 [BEND_IDX( 10)] = 0x3F23,
8644 [BEND_IDX( 5)] = 0x3F23,
8645 [BEND_IDX( 0)] = 0x0025,
8646 [BEND_IDX( -5)] = 0x0025,
8647 [BEND_IDX(-10)] = 0x0125,
8648 [BEND_IDX(-15)] = 0x0125,
8649 [BEND_IDX(-20)] = 0x0225,
8650 [BEND_IDX(-25)] = 0x0225,
8651 [BEND_IDX(-30)] = 0x0325,
8652 [BEND_IDX(-35)] = 0x0325,
8653 [BEND_IDX(-40)] = 0x0425,
8654 [BEND_IDX(-45)] = 0x0425,
8655 [BEND_IDX(-50)] = 0x0525,
8660 * steps -50 to 50 inclusive, in steps of 5
8661 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8662 * change in clock period = -(steps / 10) * 5.787 ps
8664 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8667 int idx = BEND_IDX(steps);
8669 if (WARN_ON(steps % 5 != 0))
8672 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8675 mutex_lock(&dev_priv->sb_lock);
8677 if (steps % 10 != 0)
8681 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8683 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8685 tmp |= sscdivintphase[idx];
8686 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8688 mutex_unlock(&dev_priv->sb_lock);
8693 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8695 struct intel_encoder *encoder;
8696 bool has_vga = false;
8698 for_each_intel_encoder(&dev_priv->drm, encoder) {
8699 switch (encoder->type) {
8700 case INTEL_OUTPUT_ANALOG:
8709 lpt_bend_clkout_dp(dev_priv, 0);
8710 lpt_enable_clkout_dp(dev_priv, true, true);
8712 lpt_disable_clkout_dp(dev_priv);
8717 * Initialize reference clocks when the driver loads
8719 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8721 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8722 ironlake_init_pch_refclk(dev_priv);
8723 else if (HAS_PCH_LPT(dev_priv))
8724 lpt_init_pch_refclk(dev_priv);
8727 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
8729 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8730 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8731 enum pipe pipe = crtc->pipe;
8736 switch (crtc_state->pipe_bpp) {
8738 val |= PIPECONF_6BPC;
8741 val |= PIPECONF_8BPC;
8744 val |= PIPECONF_10BPC;
8747 val |= PIPECONF_12BPC;
8750 /* Case prevented by intel_choose_pipe_bpp_dither. */
8754 if (crtc_state->dither)
8755 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8757 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8758 val |= PIPECONF_INTERLACED_ILK;
8760 val |= PIPECONF_PROGRESSIVE;
8762 if (crtc_state->limited_color_range)
8763 val |= PIPECONF_COLOR_RANGE_SELECT;
8765 I915_WRITE(PIPECONF(pipe), val);
8766 POSTING_READ(PIPECONF(pipe));
8769 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
8771 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8772 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8773 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8776 if (IS_HASWELL(dev_priv) && crtc_state->dither)
8777 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8779 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8780 val |= PIPECONF_INTERLACED_ILK;
8782 val |= PIPECONF_PROGRESSIVE;
8784 I915_WRITE(PIPECONF(cpu_transcoder), val);
8785 POSTING_READ(PIPECONF(cpu_transcoder));
8788 static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
8790 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8791 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
8793 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8796 switch (crtc_state->pipe_bpp) {
8798 val |= PIPEMISC_DITHER_6_BPC;
8801 val |= PIPEMISC_DITHER_8_BPC;
8804 val |= PIPEMISC_DITHER_10_BPC;
8807 val |= PIPEMISC_DITHER_12_BPC;
8810 /* Case prevented by pipe_config_set_bpp. */
8814 if (crtc_state->dither)
8815 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8817 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8818 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
8819 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
8821 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
8822 val |= PIPEMISC_YUV420_ENABLE |
8823 PIPEMISC_YUV420_MODE_FULL_BLEND;
8825 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8829 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8832 * Account for spread spectrum to avoid
8833 * oversubscribing the link. Max center spread
8834 * is 2.5%; use 5% for safety's sake.
8836 u32 bps = target_clock * bpp * 21 / 20;
8837 return DIV_ROUND_UP(bps, link_bw * 8);
8840 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8842 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8845 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8846 struct intel_crtc_state *crtc_state,
8847 struct dpll *reduced_clock)
8849 struct drm_crtc *crtc = &intel_crtc->base;
8850 struct drm_device *dev = crtc->dev;
8851 struct drm_i915_private *dev_priv = to_i915(dev);
8855 /* Enable autotuning of the PLL clock (if permissible) */
8857 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8858 if ((intel_panel_use_ssc(dev_priv) &&
8859 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8860 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8862 } else if (crtc_state->sdvo_tv_clock)
8865 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8867 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8870 if (reduced_clock) {
8871 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8873 if (reduced_clock->m < factor * reduced_clock->n)
8881 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8882 dpll |= DPLLB_MODE_LVDS;
8884 dpll |= DPLLB_MODE_DAC_SERIAL;
8886 dpll |= (crtc_state->pixel_multiplier - 1)
8887 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8889 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8890 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8891 dpll |= DPLL_SDVO_HIGH_SPEED;
8893 if (intel_crtc_has_dp_encoder(crtc_state))
8894 dpll |= DPLL_SDVO_HIGH_SPEED;
8897 * The high speed IO clock is only really required for
8898 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8899 * possible to share the DPLL between CRT and HDMI. Enabling
8900 * the clock needlessly does no real harm, except use up a
8901 * bit of power potentially.
8903 * We'll limit this to IVB with 3 pipes, since it has only two
8904 * DPLLs and so DPLL sharing is the only way to get three pipes
8905 * driving PCH ports at the same time. On SNB we could do this,
8906 * and potentially avoid enabling the second DPLL, but it's not
8907 * clear if it''s a win or loss power wise. No point in doing
8908 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8910 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8911 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8912 dpll |= DPLL_SDVO_HIGH_SPEED;
8914 /* compute bitmask from p1 value */
8915 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8917 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8919 switch (crtc_state->dpll.p2) {
8921 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8924 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8927 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8930 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8934 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8935 intel_panel_use_ssc(dev_priv))
8936 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8938 dpll |= PLL_REF_INPUT_DREFCLK;
8940 dpll |= DPLL_VCO_ENABLE;
8942 crtc_state->dpll_hw_state.dpll = dpll;
8943 crtc_state->dpll_hw_state.fp0 = fp;
8944 crtc_state->dpll_hw_state.fp1 = fp2;
8947 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8948 struct intel_crtc_state *crtc_state)
8950 struct drm_device *dev = crtc->base.dev;
8951 struct drm_i915_private *dev_priv = to_i915(dev);
8952 const struct intel_limit *limit;
8953 int refclk = 120000;
8955 memset(&crtc_state->dpll_hw_state, 0,
8956 sizeof(crtc_state->dpll_hw_state));
8958 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8959 if (!crtc_state->has_pch_encoder)
8962 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8963 if (intel_panel_use_ssc(dev_priv)) {
8964 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8965 dev_priv->vbt.lvds_ssc_freq);
8966 refclk = dev_priv->vbt.lvds_ssc_freq;
8969 if (intel_is_dual_link_lvds(dev)) {
8970 if (refclk == 100000)
8971 limit = &intel_limits_ironlake_dual_lvds_100m;
8973 limit = &intel_limits_ironlake_dual_lvds;
8975 if (refclk == 100000)
8976 limit = &intel_limits_ironlake_single_lvds_100m;
8978 limit = &intel_limits_ironlake_single_lvds;
8981 limit = &intel_limits_ironlake_dac;
8984 if (!crtc_state->clock_set &&
8985 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8986 refclk, NULL, &crtc_state->dpll)) {
8987 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8991 ironlake_compute_dpll(crtc, crtc_state, NULL);
8993 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8994 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8995 pipe_name(crtc->pipe));
9002 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
9003 struct intel_link_m_n *m_n)
9005 struct drm_device *dev = crtc->base.dev;
9006 struct drm_i915_private *dev_priv = to_i915(dev);
9007 enum pipe pipe = crtc->pipe;
9009 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
9010 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
9011 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
9013 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
9014 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
9015 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9018 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
9019 enum transcoder transcoder,
9020 struct intel_link_m_n *m_n,
9021 struct intel_link_m_n *m2_n2)
9023 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9024 enum pipe pipe = crtc->pipe;
9026 if (INTEL_GEN(dev_priv) >= 5) {
9027 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
9028 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
9029 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
9031 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
9032 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
9033 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9035 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
9036 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
9037 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
9038 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
9040 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
9041 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
9042 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9045 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
9046 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
9047 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
9049 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
9050 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
9051 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9055 void intel_dp_get_m_n(struct intel_crtc *crtc,
9056 struct intel_crtc_state *pipe_config)
9058 if (pipe_config->has_pch_encoder)
9059 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
9061 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9062 &pipe_config->dp_m_n,
9063 &pipe_config->dp_m2_n2);
9066 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
9067 struct intel_crtc_state *pipe_config)
9069 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9070 &pipe_config->fdi_m_n, NULL);
9073 static void skylake_get_pfit_config(struct intel_crtc *crtc,
9074 struct intel_crtc_state *pipe_config)
9076 struct drm_device *dev = crtc->base.dev;
9077 struct drm_i915_private *dev_priv = to_i915(dev);
9078 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
9083 /* find scaler attached to this pipe */
9084 for (i = 0; i < crtc->num_scalers; i++) {
9085 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9086 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9088 pipe_config->pch_pfit.enabled = true;
9089 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9090 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
9091 scaler_state->scalers[i].in_use = true;
9096 scaler_state->scaler_id = id;
9098 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9100 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
9105 skylake_get_initial_plane_config(struct intel_crtc *crtc,
9106 struct intel_initial_plane_config *plane_config)
9108 struct drm_device *dev = crtc->base.dev;
9109 struct drm_i915_private *dev_priv = to_i915(dev);
9110 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9111 enum plane_id plane_id = plane->id;
9113 u32 val, base, offset, stride_mult, tiling, alpha;
9114 int fourcc, pixel_format;
9115 unsigned int aligned_height;
9116 struct drm_framebuffer *fb;
9117 struct intel_framebuffer *intel_fb;
9119 if (!plane->get_hw_state(plane, &pipe))
9122 WARN_ON(pipe != crtc->pipe);
9124 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9126 DRM_DEBUG_KMS("failed to alloc fb\n");
9130 fb = &intel_fb->base;
9134 val = I915_READ(PLANE_CTL(pipe, plane_id));
9136 if (INTEL_GEN(dev_priv) >= 11)
9137 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
9139 pixel_format = val & PLANE_CTL_FORMAT_MASK;
9141 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
9142 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
9143 alpha &= PLANE_COLOR_ALPHA_MASK;
9145 alpha = val & PLANE_CTL_ALPHA_MASK;
9148 fourcc = skl_format_to_fourcc(pixel_format,
9149 val & PLANE_CTL_ORDER_RGBX, alpha);
9150 fb->format = drm_format_info(fourcc);
9152 tiling = val & PLANE_CTL_TILED_MASK;
9154 case PLANE_CTL_TILED_LINEAR:
9155 fb->modifier = DRM_FORMAT_MOD_LINEAR;
9157 case PLANE_CTL_TILED_X:
9158 plane_config->tiling = I915_TILING_X;
9159 fb->modifier = I915_FORMAT_MOD_X_TILED;
9161 case PLANE_CTL_TILED_Y:
9162 plane_config->tiling = I915_TILING_Y;
9163 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9164 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
9166 fb->modifier = I915_FORMAT_MOD_Y_TILED;
9168 case PLANE_CTL_TILED_YF:
9169 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9170 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
9172 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
9175 MISSING_CASE(tiling);
9180 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
9181 * while i915 HW rotation is clockwise, thats why this swapping.
9183 switch (val & PLANE_CTL_ROTATE_MASK) {
9184 case PLANE_CTL_ROTATE_0:
9185 plane_config->rotation = DRM_MODE_ROTATE_0;
9187 case PLANE_CTL_ROTATE_90:
9188 plane_config->rotation = DRM_MODE_ROTATE_270;
9190 case PLANE_CTL_ROTATE_180:
9191 plane_config->rotation = DRM_MODE_ROTATE_180;
9193 case PLANE_CTL_ROTATE_270:
9194 plane_config->rotation = DRM_MODE_ROTATE_90;
9198 if (INTEL_GEN(dev_priv) >= 10 &&
9199 val & PLANE_CTL_FLIP_HORIZONTAL)
9200 plane_config->rotation |= DRM_MODE_REFLECT_X;
9202 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
9203 plane_config->base = base;
9205 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
9207 val = I915_READ(PLANE_SIZE(pipe, plane_id));
9208 fb->height = ((val >> 16) & 0xfff) + 1;
9209 fb->width = ((val >> 0) & 0x1fff) + 1;
9211 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
9212 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
9213 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9215 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9217 plane_config->size = fb->pitches[0] * aligned_height;
9219 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9220 crtc->base.name, plane->base.name, fb->width, fb->height,
9221 fb->format->cpp[0] * 8, base, fb->pitches[0],
9222 plane_config->size);
9224 plane_config->fb = intel_fb;
9231 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
9232 struct intel_crtc_state *pipe_config)
9234 struct drm_device *dev = crtc->base.dev;
9235 struct drm_i915_private *dev_priv = to_i915(dev);
9238 tmp = I915_READ(PF_CTL(crtc->pipe));
9240 if (tmp & PF_ENABLE) {
9241 pipe_config->pch_pfit.enabled = true;
9242 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9243 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
9245 /* We currently do not free assignements of panel fitters on
9246 * ivb/hsw (since we don't use the higher upscaling modes which
9247 * differentiates them) so just WARN about this case for now. */
9248 if (IS_GEN(dev_priv, 7)) {
9249 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9250 PF_PIPE_SEL_IVB(crtc->pipe));
9255 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9256 struct intel_crtc_state *pipe_config)
9258 struct drm_device *dev = crtc->base.dev;
9259 struct drm_i915_private *dev_priv = to_i915(dev);
9260 enum intel_display_power_domain power_domain;
9261 intel_wakeref_t wakeref;
9265 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9266 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9270 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9271 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9272 pipe_config->shared_dpll = NULL;
9275 tmp = I915_READ(PIPECONF(crtc->pipe));
9276 if (!(tmp & PIPECONF_ENABLE))
9279 switch (tmp & PIPECONF_BPC_MASK) {
9281 pipe_config->pipe_bpp = 18;
9284 pipe_config->pipe_bpp = 24;
9286 case PIPECONF_10BPC:
9287 pipe_config->pipe_bpp = 30;
9289 case PIPECONF_12BPC:
9290 pipe_config->pipe_bpp = 36;
9296 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9297 pipe_config->limited_color_range = true;
9299 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9300 struct intel_shared_dpll *pll;
9301 enum intel_dpll_id pll_id;
9303 pipe_config->has_pch_encoder = true;
9305 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9306 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9307 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9309 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9311 if (HAS_PCH_IBX(dev_priv)) {
9313 * The pipe->pch transcoder and pch transcoder->pll
9316 pll_id = (enum intel_dpll_id) crtc->pipe;
9318 tmp = I915_READ(PCH_DPLL_SEL);
9319 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
9320 pll_id = DPLL_ID_PCH_PLL_B;
9322 pll_id= DPLL_ID_PCH_PLL_A;
9325 pipe_config->shared_dpll =
9326 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9327 pll = pipe_config->shared_dpll;
9329 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9330 &pipe_config->dpll_hw_state));
9332 tmp = pipe_config->dpll_hw_state.dpll;
9333 pipe_config->pixel_multiplier =
9334 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9335 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
9337 ironlake_pch_clock_get(crtc, pipe_config);
9339 pipe_config->pixel_multiplier = 1;
9342 intel_get_pipe_timings(crtc, pipe_config);
9343 intel_get_pipe_src_size(crtc, pipe_config);
9345 ironlake_get_pfit_config(crtc, pipe_config);
9350 intel_display_power_put(dev_priv, power_domain, wakeref);
9355 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9357 struct drm_device *dev = &dev_priv->drm;
9358 struct intel_crtc *crtc;
9360 for_each_intel_crtc(dev, crtc)
9361 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
9362 pipe_name(crtc->pipe));
9364 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
9365 "Display power well on\n");
9366 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
9367 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9368 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
9369 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
9370 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
9371 "CPU PWM1 enabled\n");
9372 if (IS_HASWELL(dev_priv))
9373 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
9374 "CPU PWM2 enabled\n");
9375 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
9376 "PCH PWM1 enabled\n");
9377 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
9378 "Utility pin enabled\n");
9379 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
9382 * In theory we can still leave IRQs enabled, as long as only the HPD
9383 * interrupts remain enabled. We used to check for that, but since it's
9384 * gen-specific and since we only disable LCPLL after we fully disable
9385 * the interrupts, the check below should be enough.
9387 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
9390 static u32 hsw_read_dcomp(struct drm_i915_private *dev_priv)
9392 if (IS_HASWELL(dev_priv))
9393 return I915_READ(D_COMP_HSW);
9395 return I915_READ(D_COMP_BDW);
9398 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, u32 val)
9400 if (IS_HASWELL(dev_priv)) {
9401 mutex_lock(&dev_priv->pcu_lock);
9402 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9404 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
9405 mutex_unlock(&dev_priv->pcu_lock);
9407 I915_WRITE(D_COMP_BDW, val);
9408 POSTING_READ(D_COMP_BDW);
9413 * This function implements pieces of two sequences from BSpec:
9414 * - Sequence for display software to disable LCPLL
9415 * - Sequence for display software to allow package C8+
9416 * The steps implemented here are just the steps that actually touch the LCPLL
9417 * register. Callers should take care of disabling all the display engine
9418 * functions, doing the mode unset, fixing interrupts, etc.
9420 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9421 bool switch_to_fclk, bool allow_power_down)
9425 assert_can_disable_lcpll(dev_priv);
9427 val = I915_READ(LCPLL_CTL);
9429 if (switch_to_fclk) {
9430 val |= LCPLL_CD_SOURCE_FCLK;
9431 I915_WRITE(LCPLL_CTL, val);
9433 if (wait_for_us(I915_READ(LCPLL_CTL) &
9434 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9435 DRM_ERROR("Switching to FCLK failed\n");
9437 val = I915_READ(LCPLL_CTL);
9440 val |= LCPLL_PLL_DISABLE;
9441 I915_WRITE(LCPLL_CTL, val);
9442 POSTING_READ(LCPLL_CTL);
9444 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
9445 DRM_ERROR("LCPLL still locked\n");
9447 val = hsw_read_dcomp(dev_priv);
9448 val |= D_COMP_COMP_DISABLE;
9449 hsw_write_dcomp(dev_priv, val);
9452 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9454 DRM_ERROR("D_COMP RCOMP still in progress\n");
9456 if (allow_power_down) {
9457 val = I915_READ(LCPLL_CTL);
9458 val |= LCPLL_POWER_DOWN_ALLOW;
9459 I915_WRITE(LCPLL_CTL, val);
9460 POSTING_READ(LCPLL_CTL);
9465 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9468 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9472 val = I915_READ(LCPLL_CTL);
9474 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9475 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9479 * Make sure we're not on PC8 state before disabling PC8, otherwise
9480 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9482 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9484 if (val & LCPLL_POWER_DOWN_ALLOW) {
9485 val &= ~LCPLL_POWER_DOWN_ALLOW;
9486 I915_WRITE(LCPLL_CTL, val);
9487 POSTING_READ(LCPLL_CTL);
9490 val = hsw_read_dcomp(dev_priv);
9491 val |= D_COMP_COMP_FORCE;
9492 val &= ~D_COMP_COMP_DISABLE;
9493 hsw_write_dcomp(dev_priv, val);
9495 val = I915_READ(LCPLL_CTL);
9496 val &= ~LCPLL_PLL_DISABLE;
9497 I915_WRITE(LCPLL_CTL, val);
9499 if (intel_wait_for_register(dev_priv,
9500 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9502 DRM_ERROR("LCPLL not locked yet\n");
9504 if (val & LCPLL_CD_SOURCE_FCLK) {
9505 val = I915_READ(LCPLL_CTL);
9506 val &= ~LCPLL_CD_SOURCE_FCLK;
9507 I915_WRITE(LCPLL_CTL, val);
9509 if (wait_for_us((I915_READ(LCPLL_CTL) &
9510 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9511 DRM_ERROR("Switching back to LCPLL failed\n");
9514 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9516 intel_update_cdclk(dev_priv);
9517 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
9521 * Package states C8 and deeper are really deep PC states that can only be
9522 * reached when all the devices on the system allow it, so even if the graphics
9523 * device allows PC8+, it doesn't mean the system will actually get to these
9524 * states. Our driver only allows PC8+ when going into runtime PM.
9526 * The requirements for PC8+ are that all the outputs are disabled, the power
9527 * well is disabled and most interrupts are disabled, and these are also
9528 * requirements for runtime PM. When these conditions are met, we manually do
9529 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9530 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9533 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9534 * the state of some registers, so when we come back from PC8+ we need to
9535 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9536 * need to take care of the registers kept by RC6. Notice that this happens even
9537 * if we don't put the device in PCI D3 state (which is what currently happens
9538 * because of the runtime PM support).
9540 * For more, read "Display Sequences for Package C8" on the hardware
9543 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9547 DRM_DEBUG_KMS("Enabling package C8+\n");
9549 if (HAS_PCH_LPT_LP(dev_priv)) {
9550 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9551 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9552 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9555 lpt_disable_clkout_dp(dev_priv);
9556 hsw_disable_lcpll(dev_priv, true, true);
9559 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9563 DRM_DEBUG_KMS("Disabling package C8+\n");
9565 hsw_restore_lcpll(dev_priv);
9566 lpt_init_pch_refclk(dev_priv);
9568 if (HAS_PCH_LPT_LP(dev_priv)) {
9569 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9570 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9571 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9575 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9576 struct intel_crtc_state *crtc_state)
9578 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9579 struct intel_atomic_state *state =
9580 to_intel_atomic_state(crtc_state->base.state);
9582 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
9583 IS_ICELAKE(dev_priv)) {
9584 struct intel_encoder *encoder =
9585 intel_get_crtc_new_encoder(state, crtc_state);
9587 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9588 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9589 pipe_name(crtc->pipe));
9597 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9599 struct intel_crtc_state *pipe_config)
9601 enum intel_dpll_id id;
9604 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9605 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9607 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9610 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9613 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9615 struct intel_crtc_state *pipe_config)
9617 enum intel_dpll_id id;
9620 /* TODO: TBT pll not implemented. */
9621 if (intel_port_is_combophy(dev_priv, port)) {
9622 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9623 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9624 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9626 if (WARN_ON(!intel_dpll_is_combophy(id)))
9628 } else if (intel_port_is_tc(dev_priv, port)) {
9629 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv, port));
9631 WARN(1, "Invalid port %x\n", port);
9635 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9638 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9640 struct intel_crtc_state *pipe_config)
9642 enum intel_dpll_id id;
9646 id = DPLL_ID_SKL_DPLL0;
9649 id = DPLL_ID_SKL_DPLL1;
9652 id = DPLL_ID_SKL_DPLL2;
9655 DRM_ERROR("Incorrect port type\n");
9659 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9662 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9664 struct intel_crtc_state *pipe_config)
9666 enum intel_dpll_id id;
9669 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9670 id = temp >> (port * 3 + 1);
9672 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9675 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9678 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9680 struct intel_crtc_state *pipe_config)
9682 enum intel_dpll_id id;
9683 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9685 switch (ddi_pll_sel) {
9686 case PORT_CLK_SEL_WRPLL1:
9687 id = DPLL_ID_WRPLL1;
9689 case PORT_CLK_SEL_WRPLL2:
9690 id = DPLL_ID_WRPLL2;
9692 case PORT_CLK_SEL_SPLL:
9695 case PORT_CLK_SEL_LCPLL_810:
9696 id = DPLL_ID_LCPLL_810;
9698 case PORT_CLK_SEL_LCPLL_1350:
9699 id = DPLL_ID_LCPLL_1350;
9701 case PORT_CLK_SEL_LCPLL_2700:
9702 id = DPLL_ID_LCPLL_2700;
9705 MISSING_CASE(ddi_pll_sel);
9707 case PORT_CLK_SEL_NONE:
9711 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9714 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9715 struct intel_crtc_state *pipe_config,
9716 u64 *power_domain_mask)
9718 struct drm_device *dev = crtc->base.dev;
9719 struct drm_i915_private *dev_priv = to_i915(dev);
9720 enum intel_display_power_domain power_domain;
9721 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
9722 unsigned long enabled_panel_transcoders = 0;
9723 enum transcoder panel_transcoder;
9726 if (IS_ICELAKE(dev_priv))
9727 panel_transcoder_mask |=
9728 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
9731 * The pipe->transcoder mapping is fixed with the exception of the eDP
9732 * and DSI transcoders handled below.
9734 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9737 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9738 * consistency and less surprising code; it's in always on power).
9740 for_each_set_bit(panel_transcoder,
9741 &panel_transcoder_mask,
9742 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
9743 enum pipe trans_pipe;
9745 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
9746 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
9750 * Log all enabled ones, only use the first one.
9752 * FIXME: This won't work for two separate DSI displays.
9754 enabled_panel_transcoders |= BIT(panel_transcoder);
9755 if (enabled_panel_transcoders != BIT(panel_transcoder))
9758 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9760 WARN(1, "unknown pipe linked to transcoder %s\n",
9761 transcoder_name(panel_transcoder));
9763 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9764 case TRANS_DDI_EDP_INPUT_A_ON:
9765 trans_pipe = PIPE_A;
9767 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9768 trans_pipe = PIPE_B;
9770 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9771 trans_pipe = PIPE_C;
9775 if (trans_pipe == crtc->pipe)
9776 pipe_config->cpu_transcoder = panel_transcoder;
9780 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
9782 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
9783 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
9785 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9786 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9789 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
9790 *power_domain_mask |= BIT_ULL(power_domain);
9792 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9794 return tmp & PIPECONF_ENABLE;
9797 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9798 struct intel_crtc_state *pipe_config,
9799 u64 *power_domain_mask)
9801 struct drm_device *dev = crtc->base.dev;
9802 struct drm_i915_private *dev_priv = to_i915(dev);
9803 enum intel_display_power_domain power_domain;
9805 enum transcoder cpu_transcoder;
9808 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9810 cpu_transcoder = TRANSCODER_DSI_A;
9812 cpu_transcoder = TRANSCODER_DSI_C;
9814 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9815 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9818 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
9819 *power_domain_mask |= BIT_ULL(power_domain);
9822 * The PLL needs to be enabled with a valid divider
9823 * configuration, otherwise accessing DSI registers will hang
9824 * the machine. See BSpec North Display Engine
9825 * registers/MIPI[BXT]. We can break out here early, since we
9826 * need the same DSI PLL to be enabled for both DSI ports.
9828 if (!bxt_dsi_pll_is_enabled(dev_priv))
9831 /* XXX: this works for video mode only */
9832 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9833 if (!(tmp & DPI_ENABLE))
9836 tmp = I915_READ(MIPI_CTRL(port));
9837 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9840 pipe_config->cpu_transcoder = cpu_transcoder;
9844 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9847 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9848 struct intel_crtc_state *pipe_config)
9850 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9851 struct intel_shared_dpll *pll;
9855 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9857 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9859 if (IS_ICELAKE(dev_priv))
9860 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9861 else if (IS_CANNONLAKE(dev_priv))
9862 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9863 else if (IS_GEN9_BC(dev_priv))
9864 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9865 else if (IS_GEN9_LP(dev_priv))
9866 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9868 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9870 pll = pipe_config->shared_dpll;
9872 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9873 &pipe_config->dpll_hw_state));
9877 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9878 * DDI E. So just check whether this pipe is wired to DDI E and whether
9879 * the PCH transcoder is on.
9881 if (INTEL_GEN(dev_priv) < 9 &&
9882 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9883 pipe_config->has_pch_encoder = true;
9885 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9886 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9887 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9889 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9893 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9894 struct intel_crtc_state *pipe_config)
9896 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9897 enum intel_display_power_domain power_domain;
9898 u64 power_domain_mask;
9901 intel_crtc_init_scalers(crtc, pipe_config);
9903 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9904 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9906 power_domain_mask = BIT_ULL(power_domain);
9908 pipe_config->shared_dpll = NULL;
9910 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9912 if (IS_GEN9_LP(dev_priv) &&
9913 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9921 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
9922 IS_ICELAKE(dev_priv)) {
9923 haswell_get_ddi_port_state(crtc, pipe_config);
9924 intel_get_pipe_timings(crtc, pipe_config);
9927 intel_get_pipe_src_size(crtc, pipe_config);
9928 intel_get_crtc_ycbcr_config(crtc, pipe_config);
9930 pipe_config->gamma_mode =
9931 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9933 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9934 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9935 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
9936 power_domain_mask |= BIT_ULL(power_domain);
9938 if (INTEL_GEN(dev_priv) >= 9)
9939 skylake_get_pfit_config(crtc, pipe_config);
9941 ironlake_get_pfit_config(crtc, pipe_config);
9944 if (hsw_crtc_supports_ips(crtc)) {
9945 if (IS_HASWELL(dev_priv))
9946 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9949 * We cannot readout IPS state on broadwell, set to
9950 * true so we can set it to a defined state on first
9953 pipe_config->ips_enabled = true;
9957 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9958 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9959 pipe_config->pixel_multiplier =
9960 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9962 pipe_config->pixel_multiplier = 1;
9966 for_each_power_domain(power_domain, power_domain_mask)
9967 intel_display_power_put_unchecked(dev_priv, power_domain);
9972 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9974 struct drm_i915_private *dev_priv =
9975 to_i915(plane_state->base.plane->dev);
9976 const struct drm_framebuffer *fb = plane_state->base.fb;
9977 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9980 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
9981 base = obj->phys_handle->busaddr;
9983 base = intel_plane_ggtt_offset(plane_state);
9985 base += plane_state->color_plane[0].offset;
9987 /* ILK+ do this automagically */
9988 if (HAS_GMCH(dev_priv) &&
9989 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9990 base += (plane_state->base.crtc_h *
9991 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9996 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9998 int x = plane_state->base.crtc_x;
9999 int y = plane_state->base.crtc_y;
10003 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
10006 pos |= x << CURSOR_X_SHIFT;
10009 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
10012 pos |= y << CURSOR_Y_SHIFT;
10017 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
10019 const struct drm_mode_config *config =
10020 &plane_state->base.plane->dev->mode_config;
10021 int width = plane_state->base.crtc_w;
10022 int height = plane_state->base.crtc_h;
10024 return width > 0 && width <= config->cursor_width &&
10025 height > 0 && height <= config->cursor_height;
10028 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
10030 const struct drm_framebuffer *fb = plane_state->base.fb;
10031 unsigned int rotation = plane_state->base.rotation;
10036 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
10037 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
10039 ret = intel_plane_check_stride(plane_state);
10043 src_x = plane_state->base.src_x >> 16;
10044 src_y = plane_state->base.src_y >> 16;
10046 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
10047 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
10050 if (src_x != 0 || src_y != 0) {
10051 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
10055 plane_state->color_plane[0].offset = offset;
10060 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
10061 struct intel_plane_state *plane_state)
10063 const struct drm_framebuffer *fb = plane_state->base.fb;
10066 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
10067 DRM_DEBUG_KMS("cursor cannot be tiled\n");
10071 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
10073 DRM_PLANE_HELPER_NO_SCALING,
10074 DRM_PLANE_HELPER_NO_SCALING,
10079 if (!plane_state->base.visible)
10082 ret = intel_plane_check_src_coordinates(plane_state);
10086 ret = intel_cursor_check_surface(plane_state);
10093 static unsigned int
10094 i845_cursor_max_stride(struct intel_plane *plane,
10095 u32 pixel_format, u64 modifier,
10096 unsigned int rotation)
10101 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10103 return CURSOR_GAMMA_ENABLE;
10106 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
10107 const struct intel_plane_state *plane_state)
10109 return CURSOR_ENABLE |
10110 CURSOR_FORMAT_ARGB |
10111 CURSOR_STRIDE(plane_state->color_plane[0].stride);
10114 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
10116 int width = plane_state->base.crtc_w;
10119 * 845g/865g are only limited by the width of their cursors,
10120 * the height is arbitrary up to the precision of the register.
10122 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
10125 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
10126 struct intel_plane_state *plane_state)
10128 const struct drm_framebuffer *fb = plane_state->base.fb;
10131 ret = intel_check_cursor(crtc_state, plane_state);
10135 /* if we want to turn off the cursor ignore width and height */
10139 /* Check for which cursor types we support */
10140 if (!i845_cursor_size_ok(plane_state)) {
10141 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10142 plane_state->base.crtc_w,
10143 plane_state->base.crtc_h);
10147 WARN_ON(plane_state->base.visible &&
10148 plane_state->color_plane[0].stride != fb->pitches[0]);
10150 switch (fb->pitches[0]) {
10157 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
10162 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
10167 static void i845_update_cursor(struct intel_plane *plane,
10168 const struct intel_crtc_state *crtc_state,
10169 const struct intel_plane_state *plane_state)
10171 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10172 u32 cntl = 0, base = 0, pos = 0, size = 0;
10173 unsigned long irqflags;
10175 if (plane_state && plane_state->base.visible) {
10176 unsigned int width = plane_state->base.crtc_w;
10177 unsigned int height = plane_state->base.crtc_h;
10179 cntl = plane_state->ctl |
10180 i845_cursor_ctl_crtc(crtc_state);
10182 size = (height << 12) | width;
10184 base = intel_cursor_base(plane_state);
10185 pos = intel_cursor_position(plane_state);
10188 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10190 /* On these chipsets we can only modify the base/size/stride
10191 * whilst the cursor is disabled.
10193 if (plane->cursor.base != base ||
10194 plane->cursor.size != size ||
10195 plane->cursor.cntl != cntl) {
10196 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
10197 I915_WRITE_FW(CURBASE(PIPE_A), base);
10198 I915_WRITE_FW(CURSIZE, size);
10199 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10200 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
10202 plane->cursor.base = base;
10203 plane->cursor.size = size;
10204 plane->cursor.cntl = cntl;
10206 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10209 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10212 static void i845_disable_cursor(struct intel_plane *plane,
10213 const struct intel_crtc_state *crtc_state)
10215 i845_update_cursor(plane, crtc_state, NULL);
10218 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
10221 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10222 enum intel_display_power_domain power_domain;
10223 intel_wakeref_t wakeref;
10226 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
10227 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10231 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
10235 intel_display_power_put(dev_priv, power_domain, wakeref);
10240 static unsigned int
10241 i9xx_cursor_max_stride(struct intel_plane *plane,
10242 u32 pixel_format, u64 modifier,
10243 unsigned int rotation)
10245 return plane->base.dev->mode_config.cursor_width * 4;
10248 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10250 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10251 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10254 if (INTEL_GEN(dev_priv) >= 11)
10257 cntl |= MCURSOR_GAMMA_ENABLE;
10259 if (HAS_DDI(dev_priv))
10260 cntl |= MCURSOR_PIPE_CSC_ENABLE;
10262 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10263 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
10268 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
10269 const struct intel_plane_state *plane_state)
10271 struct drm_i915_private *dev_priv =
10272 to_i915(plane_state->base.plane->dev);
10275 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
10276 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10278 switch (plane_state->base.crtc_w) {
10280 cntl |= MCURSOR_MODE_64_ARGB_AX;
10283 cntl |= MCURSOR_MODE_128_ARGB_AX;
10286 cntl |= MCURSOR_MODE_256_ARGB_AX;
10289 MISSING_CASE(plane_state->base.crtc_w);
10293 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
10294 cntl |= MCURSOR_ROTATE_180;
10299 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
10301 struct drm_i915_private *dev_priv =
10302 to_i915(plane_state->base.plane->dev);
10303 int width = plane_state->base.crtc_w;
10304 int height = plane_state->base.crtc_h;
10306 if (!intel_cursor_size_ok(plane_state))
10309 /* Cursor width is limited to a few power-of-two sizes */
10320 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10321 * height from 8 lines up to the cursor width, when the
10322 * cursor is not rotated. Everything else requires square
10325 if (HAS_CUR_FBC(dev_priv) &&
10326 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
10327 if (height < 8 || height > width)
10330 if (height != width)
10337 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
10338 struct intel_plane_state *plane_state)
10340 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
10341 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10342 const struct drm_framebuffer *fb = plane_state->base.fb;
10343 enum pipe pipe = plane->pipe;
10346 ret = intel_check_cursor(crtc_state, plane_state);
10350 /* if we want to turn off the cursor ignore width and height */
10354 /* Check for which cursor types we support */
10355 if (!i9xx_cursor_size_ok(plane_state)) {
10356 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10357 plane_state->base.crtc_w,
10358 plane_state->base.crtc_h);
10362 WARN_ON(plane_state->base.visible &&
10363 plane_state->color_plane[0].stride != fb->pitches[0]);
10365 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10366 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10367 fb->pitches[0], plane_state->base.crtc_w);
10372 * There's something wrong with the cursor on CHV pipe C.
10373 * If it straddles the left edge of the screen then
10374 * moving it away from the edge or disabling it often
10375 * results in a pipe underrun, and often that can lead to
10376 * dead pipe (constant underrun reported, and it scans
10377 * out just a solid color). To recover from that, the
10378 * display power well must be turned off and on again.
10379 * Refuse the put the cursor into that compromised position.
10381 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10382 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10383 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10387 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10392 static void i9xx_update_cursor(struct intel_plane *plane,
10393 const struct intel_crtc_state *crtc_state,
10394 const struct intel_plane_state *plane_state)
10396 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10397 enum pipe pipe = plane->pipe;
10398 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
10399 unsigned long irqflags;
10401 if (plane_state && plane_state->base.visible) {
10402 cntl = plane_state->ctl |
10403 i9xx_cursor_ctl_crtc(crtc_state);
10405 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10406 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10408 base = intel_cursor_base(plane_state);
10409 pos = intel_cursor_position(plane_state);
10412 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10415 * On some platforms writing CURCNTR first will also
10416 * cause CURPOS to be armed by the CURBASE write.
10417 * Without the CURCNTR write the CURPOS write would
10418 * arm itself. Thus we always update CURCNTR before
10421 * On other platforms CURPOS always requires the
10422 * CURBASE write to arm the update. Additonally
10423 * a write to any of the cursor register will cancel
10424 * an already armed cursor update. Thus leaving out
10425 * the CURBASE write after CURPOS could lead to a
10426 * cursor that doesn't appear to move, or even change
10427 * shape. Thus we always write CURBASE.
10429 * The other registers are armed by by the CURBASE write
10430 * except when the plane is getting enabled at which time
10431 * the CURCNTR write arms the update.
10434 if (INTEL_GEN(dev_priv) >= 9)
10435 skl_write_cursor_wm(plane, crtc_state);
10437 if (plane->cursor.base != base ||
10438 plane->cursor.size != fbc_ctl ||
10439 plane->cursor.cntl != cntl) {
10440 if (HAS_CUR_FBC(dev_priv))
10441 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
10442 I915_WRITE_FW(CURCNTR(pipe), cntl);
10443 I915_WRITE_FW(CURPOS(pipe), pos);
10444 I915_WRITE_FW(CURBASE(pipe), base);
10446 plane->cursor.base = base;
10447 plane->cursor.size = fbc_ctl;
10448 plane->cursor.cntl = cntl;
10450 I915_WRITE_FW(CURPOS(pipe), pos);
10451 I915_WRITE_FW(CURBASE(pipe), base);
10454 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10457 static void i9xx_disable_cursor(struct intel_plane *plane,
10458 const struct intel_crtc_state *crtc_state)
10460 i9xx_update_cursor(plane, crtc_state, NULL);
10463 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10466 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10467 enum intel_display_power_domain power_domain;
10468 intel_wakeref_t wakeref;
10473 * Not 100% correct for planes that can move between pipes,
10474 * but that's only the case for gen2-3 which don't have any
10475 * display power wells.
10477 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
10478 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10482 val = I915_READ(CURCNTR(plane->pipe));
10484 ret = val & MCURSOR_MODE;
10486 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10487 *pipe = plane->pipe;
10489 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10490 MCURSOR_PIPE_SELECT_SHIFT;
10492 intel_display_power_put(dev_priv, power_domain, wakeref);
10497 /* VESA 640x480x72Hz mode to set on the pipe */
10498 static const struct drm_display_mode load_detect_mode = {
10499 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10500 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10503 struct drm_framebuffer *
10504 intel_framebuffer_create(struct drm_i915_gem_object *obj,
10505 struct drm_mode_fb_cmd2 *mode_cmd)
10507 struct intel_framebuffer *intel_fb;
10510 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10512 return ERR_PTR(-ENOMEM);
10514 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
10518 return &intel_fb->base;
10522 return ERR_PTR(ret);
10525 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10526 struct drm_crtc *crtc)
10528 struct drm_plane *plane;
10529 struct drm_plane_state *plane_state;
10532 ret = drm_atomic_add_affected_planes(state, crtc);
10536 for_each_new_plane_in_state(state, plane, plane_state, i) {
10537 if (plane_state->crtc != crtc)
10540 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10544 drm_atomic_set_fb_for_plane(plane_state, NULL);
10550 int intel_get_load_detect_pipe(struct drm_connector *connector,
10551 const struct drm_display_mode *mode,
10552 struct intel_load_detect_pipe *old,
10553 struct drm_modeset_acquire_ctx *ctx)
10555 struct intel_crtc *intel_crtc;
10556 struct intel_encoder *intel_encoder =
10557 intel_attached_encoder(connector);
10558 struct drm_crtc *possible_crtc;
10559 struct drm_encoder *encoder = &intel_encoder->base;
10560 struct drm_crtc *crtc = NULL;
10561 struct drm_device *dev = encoder->dev;
10562 struct drm_i915_private *dev_priv = to_i915(dev);
10563 struct drm_mode_config *config = &dev->mode_config;
10564 struct drm_atomic_state *state = NULL, *restore_state = NULL;
10565 struct drm_connector_state *connector_state;
10566 struct intel_crtc_state *crtc_state;
10569 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10570 connector->base.id, connector->name,
10571 encoder->base.id, encoder->name);
10573 old->restore_state = NULL;
10575 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
10578 * Algorithm gets a little messy:
10580 * - if the connector already has an assigned crtc, use it (but make
10581 * sure it's on first)
10583 * - try to find the first unused crtc that can drive this connector,
10584 * and use that if we find one
10587 /* See if we already have a CRTC for this connector */
10588 if (connector->state->crtc) {
10589 crtc = connector->state->crtc;
10591 ret = drm_modeset_lock(&crtc->mutex, ctx);
10595 /* Make sure the crtc and connector are running */
10599 /* Find an unused one (if possible) */
10600 for_each_crtc(dev, possible_crtc) {
10602 if (!(encoder->possible_crtcs & (1 << i)))
10605 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10609 if (possible_crtc->state->enable) {
10610 drm_modeset_unlock(&possible_crtc->mutex);
10614 crtc = possible_crtc;
10619 * If we didn't find an unused CRTC, don't use any.
10622 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10628 intel_crtc = to_intel_crtc(crtc);
10630 state = drm_atomic_state_alloc(dev);
10631 restore_state = drm_atomic_state_alloc(dev);
10632 if (!state || !restore_state) {
10637 state->acquire_ctx = ctx;
10638 restore_state->acquire_ctx = ctx;
10640 connector_state = drm_atomic_get_connector_state(state, connector);
10641 if (IS_ERR(connector_state)) {
10642 ret = PTR_ERR(connector_state);
10646 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10650 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10651 if (IS_ERR(crtc_state)) {
10652 ret = PTR_ERR(crtc_state);
10656 crtc_state->base.active = crtc_state->base.enable = true;
10659 mode = &load_detect_mode;
10661 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
10665 ret = intel_modeset_disable_planes(state, crtc);
10669 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10671 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
10673 ret = drm_atomic_add_affected_planes(restore_state, crtc);
10675 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10679 ret = drm_atomic_commit(state);
10681 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10685 old->restore_state = restore_state;
10686 drm_atomic_state_put(state);
10688 /* let the connector get through one full cycle before testing */
10689 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
10694 drm_atomic_state_put(state);
10697 if (restore_state) {
10698 drm_atomic_state_put(restore_state);
10699 restore_state = NULL;
10702 if (ret == -EDEADLK)
10708 void intel_release_load_detect_pipe(struct drm_connector *connector,
10709 struct intel_load_detect_pipe *old,
10710 struct drm_modeset_acquire_ctx *ctx)
10712 struct intel_encoder *intel_encoder =
10713 intel_attached_encoder(connector);
10714 struct drm_encoder *encoder = &intel_encoder->base;
10715 struct drm_atomic_state *state = old->restore_state;
10718 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10719 connector->base.id, connector->name,
10720 encoder->base.id, encoder->name);
10725 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10727 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10728 drm_atomic_state_put(state);
10731 static int i9xx_pll_refclk(struct drm_device *dev,
10732 const struct intel_crtc_state *pipe_config)
10734 struct drm_i915_private *dev_priv = to_i915(dev);
10735 u32 dpll = pipe_config->dpll_hw_state.dpll;
10737 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10738 return dev_priv->vbt.lvds_ssc_freq;
10739 else if (HAS_PCH_SPLIT(dev_priv))
10741 else if (!IS_GEN(dev_priv, 2))
10747 /* Returns the clock of the currently programmed mode of the given pipe. */
10748 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10749 struct intel_crtc_state *pipe_config)
10751 struct drm_device *dev = crtc->base.dev;
10752 struct drm_i915_private *dev_priv = to_i915(dev);
10753 int pipe = pipe_config->cpu_transcoder;
10754 u32 dpll = pipe_config->dpll_hw_state.dpll;
10758 int refclk = i9xx_pll_refclk(dev, pipe_config);
10760 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10761 fp = pipe_config->dpll_hw_state.fp0;
10763 fp = pipe_config->dpll_hw_state.fp1;
10765 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10766 if (IS_PINEVIEW(dev_priv)) {
10767 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10768 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10770 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10771 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10774 if (!IS_GEN(dev_priv, 2)) {
10775 if (IS_PINEVIEW(dev_priv))
10776 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10777 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10779 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10780 DPLL_FPA01_P1_POST_DIV_SHIFT);
10782 switch (dpll & DPLL_MODE_MASK) {
10783 case DPLLB_MODE_DAC_SERIAL:
10784 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10787 case DPLLB_MODE_LVDS:
10788 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10792 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10793 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10797 if (IS_PINEVIEW(dev_priv))
10798 port_clock = pnv_calc_dpll_params(refclk, &clock);
10800 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10802 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10803 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10806 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10807 DPLL_FPA01_P1_POST_DIV_SHIFT);
10809 if (lvds & LVDS_CLKB_POWER_UP)
10814 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10817 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10818 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10820 if (dpll & PLL_P2_DIVIDE_BY_4)
10826 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10830 * This value includes pixel_multiplier. We will use
10831 * port_clock to compute adjusted_mode.crtc_clock in the
10832 * encoder's get_config() function.
10834 pipe_config->port_clock = port_clock;
10837 int intel_dotclock_calculate(int link_freq,
10838 const struct intel_link_m_n *m_n)
10841 * The calculation for the data clock is:
10842 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10843 * But we want to avoid losing precison if possible, so:
10844 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10846 * and the link clock is simpler:
10847 * link_clock = (m * link_clock) / n
10853 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10856 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10857 struct intel_crtc_state *pipe_config)
10859 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10861 /* read out port_clock from the DPLL */
10862 i9xx_crtc_clock_get(crtc, pipe_config);
10865 * In case there is an active pipe without active ports,
10866 * we may need some idea for the dotclock anyway.
10867 * Calculate one based on the FDI configuration.
10869 pipe_config->base.adjusted_mode.crtc_clock =
10870 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10871 &pipe_config->fdi_m_n);
10874 /* Returns the currently programmed mode of the given encoder. */
10875 struct drm_display_mode *
10876 intel_encoder_current_mode(struct intel_encoder *encoder)
10878 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10879 struct intel_crtc_state *crtc_state;
10880 struct drm_display_mode *mode;
10881 struct intel_crtc *crtc;
10884 if (!encoder->get_hw_state(encoder, &pipe))
10887 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10889 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10893 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10899 crtc_state->base.crtc = &crtc->base;
10901 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10907 encoder->get_config(encoder, crtc_state);
10909 intel_mode_from_pipe_config(mode, crtc_state);
10916 static void intel_crtc_destroy(struct drm_crtc *crtc)
10918 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10920 drm_crtc_cleanup(crtc);
10925 * intel_wm_need_update - Check whether watermarks need updating
10926 * @cur: current plane state
10927 * @new: new plane state
10929 * Check current plane state versus the new one to determine whether
10930 * watermarks need to be recalculated.
10932 * Returns true or false.
10934 static bool intel_wm_need_update(struct intel_plane_state *cur,
10935 struct intel_plane_state *new)
10937 /* Update watermarks on tiling or size changes. */
10938 if (new->base.visible != cur->base.visible)
10941 if (!cur->base.fb || !new->base.fb)
10944 if (cur->base.fb->modifier != new->base.fb->modifier ||
10945 cur->base.rotation != new->base.rotation ||
10946 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10947 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10948 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10949 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10955 static bool needs_scaling(const struct intel_plane_state *state)
10957 int src_w = drm_rect_width(&state->base.src) >> 16;
10958 int src_h = drm_rect_height(&state->base.src) >> 16;
10959 int dst_w = drm_rect_width(&state->base.dst);
10960 int dst_h = drm_rect_height(&state->base.dst);
10962 return (src_w != dst_w || src_h != dst_h);
10965 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10966 struct drm_crtc_state *crtc_state,
10967 const struct intel_plane_state *old_plane_state,
10968 struct drm_plane_state *plane_state)
10970 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10971 struct drm_crtc *crtc = crtc_state->crtc;
10972 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10973 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10974 struct drm_device *dev = crtc->dev;
10975 struct drm_i915_private *dev_priv = to_i915(dev);
10976 bool mode_changed = needs_modeset(crtc_state);
10977 bool was_crtc_enabled = old_crtc_state->base.active;
10978 bool is_crtc_enabled = crtc_state->active;
10979 bool turn_off, turn_on, visible, was_visible;
10980 struct drm_framebuffer *fb = plane_state->fb;
10983 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10984 ret = skl_update_scaler_plane(
10985 to_intel_crtc_state(crtc_state),
10986 to_intel_plane_state(plane_state));
10991 was_visible = old_plane_state->base.visible;
10992 visible = plane_state->visible;
10994 if (!was_crtc_enabled && WARN_ON(was_visible))
10995 was_visible = false;
10998 * Visibility is calculated as if the crtc was on, but
10999 * after scaler setup everything depends on it being off
11000 * when the crtc isn't active.
11002 * FIXME this is wrong for watermarks. Watermarks should also
11003 * be computed as if the pipe would be active. Perhaps move
11004 * per-plane wm computation to the .check_plane() hook, and
11005 * only combine the results from all planes in the current place?
11007 if (!is_crtc_enabled) {
11008 plane_state->visible = visible = false;
11009 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
11012 if (!was_visible && !visible)
11015 if (fb != old_plane_state->base.fb)
11016 pipe_config->fb_changed = true;
11018 turn_off = was_visible && (!visible || mode_changed);
11019 turn_on = visible && (!was_visible || mode_changed);
11021 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
11022 intel_crtc->base.base.id, intel_crtc->base.name,
11023 plane->base.base.id, plane->base.name,
11024 fb ? fb->base.id : -1);
11026 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
11027 plane->base.base.id, plane->base.name,
11028 was_visible, visible,
11029 turn_off, turn_on, mode_changed);
11032 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11033 pipe_config->update_wm_pre = true;
11035 /* must disable cxsr around plane enable/disable */
11036 if (plane->id != PLANE_CURSOR)
11037 pipe_config->disable_cxsr = true;
11038 } else if (turn_off) {
11039 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11040 pipe_config->update_wm_post = true;
11042 /* must disable cxsr around plane enable/disable */
11043 if (plane->id != PLANE_CURSOR)
11044 pipe_config->disable_cxsr = true;
11045 } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state),
11046 to_intel_plane_state(plane_state))) {
11047 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
11048 /* FIXME bollocks */
11049 pipe_config->update_wm_pre = true;
11050 pipe_config->update_wm_post = true;
11054 if (visible || was_visible)
11055 pipe_config->fb_bits |= plane->frontbuffer_bit;
11058 * ILK/SNB DVSACNTR/Sprite Enable
11059 * IVB SPR_CTL/Sprite Enable
11060 * "When in Self Refresh Big FIFO mode, a write to enable the
11061 * plane will be internally buffered and delayed while Big FIFO
11062 * mode is exiting."
11064 * Which means that enabling the sprite can take an extra frame
11065 * when we start in big FIFO mode (LP1+). Thus we need to drop
11066 * down to LP0 and wait for vblank in order to make sure the
11067 * sprite gets enabled on the next vblank after the register write.
11068 * Doing otherwise would risk enabling the sprite one frame after
11069 * we've already signalled flip completion. We can resume LP1+
11070 * once the sprite has been enabled.
11073 * WaCxSRDisabledForSpriteScaling:ivb
11074 * IVB SPR_SCALE/Scaling Enable
11075 * "Low Power watermarks must be disabled for at least one
11076 * frame before enabling sprite scaling, and kept disabled
11077 * until sprite scaling is disabled."
11079 * ILK/SNB DVSASCALE/Scaling Enable
11080 * "When in Self Refresh Big FIFO mode, scaling enable will be
11081 * masked off while Big FIFO mode is exiting."
11083 * Despite the w/a only being listed for IVB we assume that
11084 * the ILK/SNB note has similar ramifications, hence we apply
11085 * the w/a on all three platforms.
11087 * With experimental results seems this is needed also for primary
11088 * plane, not only sprite plane.
11090 if (plane->id != PLANE_CURSOR &&
11091 (IS_GEN_RANGE(dev_priv, 5, 6) ||
11092 IS_IVYBRIDGE(dev_priv)) &&
11093 (turn_on || (!needs_scaling(old_plane_state) &&
11094 needs_scaling(to_intel_plane_state(plane_state)))))
11095 pipe_config->disable_lp_wm = true;
11100 static bool encoders_cloneable(const struct intel_encoder *a,
11101 const struct intel_encoder *b)
11103 /* masks could be asymmetric, so check both ways */
11104 return a == b || (a->cloneable & (1 << b->type) &&
11105 b->cloneable & (1 << a->type));
11108 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11109 struct intel_crtc *crtc,
11110 struct intel_encoder *encoder)
11112 struct intel_encoder *source_encoder;
11113 struct drm_connector *connector;
11114 struct drm_connector_state *connector_state;
11117 for_each_new_connector_in_state(state, connector, connector_state, i) {
11118 if (connector_state->crtc != &crtc->base)
11122 to_intel_encoder(connector_state->best_encoder);
11123 if (!encoders_cloneable(encoder, source_encoder))
11130 static int icl_add_linked_planes(struct intel_atomic_state *state)
11132 struct intel_plane *plane, *linked;
11133 struct intel_plane_state *plane_state, *linked_plane_state;
11136 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11137 linked = plane_state->linked_plane;
11142 linked_plane_state = intel_atomic_get_plane_state(state, linked);
11143 if (IS_ERR(linked_plane_state))
11144 return PTR_ERR(linked_plane_state);
11146 WARN_ON(linked_plane_state->linked_plane != plane);
11147 WARN_ON(linked_plane_state->slave == plane_state->slave);
11153 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
11155 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11156 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11157 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
11158 struct intel_plane *plane, *linked;
11159 struct intel_plane_state *plane_state;
11162 if (INTEL_GEN(dev_priv) < 11)
11166 * Destroy all old plane links and make the slave plane invisible
11167 * in the crtc_state->active_planes mask.
11169 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11170 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
11173 plane_state->linked_plane = NULL;
11174 if (plane_state->slave && !plane_state->base.visible) {
11175 crtc_state->active_planes &= ~BIT(plane->id);
11176 crtc_state->update_planes |= BIT(plane->id);
11179 plane_state->slave = false;
11182 if (!crtc_state->nv12_planes)
11185 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11186 struct intel_plane_state *linked_state = NULL;
11188 if (plane->pipe != crtc->pipe ||
11189 !(crtc_state->nv12_planes & BIT(plane->id)))
11192 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
11193 if (!icl_is_nv12_y_plane(linked->id))
11196 if (crtc_state->active_planes & BIT(linked->id))
11199 linked_state = intel_atomic_get_plane_state(state, linked);
11200 if (IS_ERR(linked_state))
11201 return PTR_ERR(linked_state);
11206 if (!linked_state) {
11207 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
11208 hweight8(crtc_state->nv12_planes));
11213 plane_state->linked_plane = linked;
11215 linked_state->slave = true;
11216 linked_state->linked_plane = plane;
11217 crtc_state->active_planes |= BIT(linked->id);
11218 crtc_state->update_planes |= BIT(linked->id);
11219 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
11225 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
11226 struct drm_crtc_state *crtc_state)
11228 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11229 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11230 struct intel_crtc_state *pipe_config =
11231 to_intel_crtc_state(crtc_state);
11233 bool mode_changed = needs_modeset(crtc_state);
11235 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
11236 mode_changed && !crtc_state->active)
11237 pipe_config->update_wm_post = true;
11239 if (mode_changed && crtc_state->enable &&
11240 dev_priv->display.crtc_compute_clock &&
11241 !WARN_ON(pipe_config->shared_dpll)) {
11242 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
11248 if (mode_changed || crtc_state->color_mgmt_changed) {
11249 ret = intel_color_check(pipe_config);
11254 * Changing color management on Intel hardware is
11255 * handled as part of planes update.
11257 crtc_state->planes_changed = true;
11261 if (dev_priv->display.compute_pipe_wm) {
11262 ret = dev_priv->display.compute_pipe_wm(pipe_config);
11264 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
11269 if (dev_priv->display.compute_intermediate_wm) {
11270 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
11274 * Calculate 'intermediate' watermarks that satisfy both the
11275 * old state and the new state. We can program these
11278 ret = dev_priv->display.compute_intermediate_wm(pipe_config);
11280 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11285 if (INTEL_GEN(dev_priv) >= 9) {
11286 if (mode_changed || pipe_config->update_pipe)
11287 ret = skl_update_scaler_crtc(pipe_config);
11290 ret = icl_check_nv12_planes(pipe_config);
11292 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11295 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
11299 if (HAS_IPS(dev_priv))
11300 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11305 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
11306 .atomic_check = intel_crtc_atomic_check,
11309 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11311 struct intel_connector *connector;
11312 struct drm_connector_list_iter conn_iter;
11314 drm_connector_list_iter_begin(dev, &conn_iter);
11315 for_each_intel_connector_iter(connector, &conn_iter) {
11316 if (connector->base.state->crtc)
11317 drm_connector_put(&connector->base);
11319 if (connector->base.encoder) {
11320 connector->base.state->best_encoder =
11321 connector->base.encoder;
11322 connector->base.state->crtc =
11323 connector->base.encoder->crtc;
11325 drm_connector_get(&connector->base);
11327 connector->base.state->best_encoder = NULL;
11328 connector->base.state->crtc = NULL;
11331 drm_connector_list_iter_end(&conn_iter);
11335 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11336 struct intel_crtc_state *pipe_config)
11338 struct drm_connector *connector = conn_state->connector;
11339 const struct drm_display_info *info = &connector->display_info;
11342 switch (conn_state->max_bpc) {
11359 if (bpp < pipe_config->pipe_bpp) {
11360 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11361 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11362 connector->base.id, connector->name,
11363 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
11364 pipe_config->pipe_bpp);
11366 pipe_config->pipe_bpp = bpp;
11373 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
11374 struct intel_crtc_state *pipe_config)
11376 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11377 struct drm_atomic_state *state = pipe_config->base.state;
11378 struct drm_connector *connector;
11379 struct drm_connector_state *connector_state;
11382 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11383 IS_CHERRYVIEW(dev_priv)))
11385 else if (INTEL_GEN(dev_priv) >= 5)
11390 pipe_config->pipe_bpp = bpp;
11392 /* Clamp display bpp to connector max bpp */
11393 for_each_new_connector_in_state(state, connector, connector_state, i) {
11396 if (connector_state->crtc != &crtc->base)
11399 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11407 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11409 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11410 "type: 0x%x flags: 0x%x\n",
11412 mode->crtc_hdisplay, mode->crtc_hsync_start,
11413 mode->crtc_hsync_end, mode->crtc_htotal,
11414 mode->crtc_vdisplay, mode->crtc_vsync_start,
11415 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11419 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
11420 unsigned int lane_count, struct intel_link_m_n *m_n)
11422 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11424 m_n->gmch_m, m_n->gmch_n,
11425 m_n->link_m, m_n->link_n, m_n->tu);
11428 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11430 static const char * const output_type_str[] = {
11431 OUTPUT_TYPE(UNUSED),
11432 OUTPUT_TYPE(ANALOG),
11436 OUTPUT_TYPE(TVOUT),
11442 OUTPUT_TYPE(DP_MST),
11447 static void snprintf_output_types(char *buf, size_t len,
11448 unsigned int output_types)
11455 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11458 if ((output_types & BIT(i)) == 0)
11461 r = snprintf(str, len, "%s%s",
11462 str != buf ? "," : "", output_type_str[i]);
11468 output_types &= ~BIT(i);
11471 WARN_ON_ONCE(output_types != 0);
11474 static const char * const output_format_str[] = {
11475 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11476 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
11477 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
11478 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
11481 static const char *output_formats(enum intel_output_format format)
11483 if (format >= ARRAY_SIZE(output_format_str))
11484 format = INTEL_OUTPUT_FORMAT_INVALID;
11485 return output_format_str[format];
11488 static void intel_dump_pipe_config(struct intel_crtc *crtc,
11489 struct intel_crtc_state *pipe_config,
11490 const char *context)
11492 struct drm_device *dev = crtc->base.dev;
11493 struct drm_i915_private *dev_priv = to_i915(dev);
11494 struct drm_plane *plane;
11495 struct intel_plane *intel_plane;
11496 struct intel_plane_state *state;
11497 struct drm_framebuffer *fb;
11500 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11501 crtc->base.base.id, crtc->base.name, context);
11503 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11504 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11505 buf, pipe_config->output_types);
11507 DRM_DEBUG_KMS("output format: %s\n",
11508 output_formats(pipe_config->output_format));
11510 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11511 transcoder_name(pipe_config->cpu_transcoder),
11512 pipe_config->pipe_bpp, pipe_config->dither);
11514 if (pipe_config->has_pch_encoder)
11515 intel_dump_m_n_config(pipe_config, "fdi",
11516 pipe_config->fdi_lanes,
11517 &pipe_config->fdi_m_n);
11519 if (intel_crtc_has_dp_encoder(pipe_config)) {
11520 intel_dump_m_n_config(pipe_config, "dp m_n",
11521 pipe_config->lane_count, &pipe_config->dp_m_n);
11522 if (pipe_config->has_drrs)
11523 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11524 pipe_config->lane_count,
11525 &pipe_config->dp_m2_n2);
11528 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11529 pipe_config->has_audio, pipe_config->has_infoframe);
11531 DRM_DEBUG_KMS("requested mode:\n");
11532 drm_mode_debug_printmodeline(&pipe_config->base.mode);
11533 DRM_DEBUG_KMS("adjusted mode:\n");
11534 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11535 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
11536 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
11537 pipe_config->port_clock,
11538 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11539 pipe_config->pixel_rate);
11541 if (INTEL_GEN(dev_priv) >= 9)
11542 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11544 pipe_config->scaler_state.scaler_users,
11545 pipe_config->scaler_state.scaler_id);
11547 if (HAS_GMCH(dev_priv))
11548 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11549 pipe_config->gmch_pfit.control,
11550 pipe_config->gmch_pfit.pgm_ratios,
11551 pipe_config->gmch_pfit.lvds_border_bits);
11553 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11554 pipe_config->pch_pfit.pos,
11555 pipe_config->pch_pfit.size,
11556 enableddisabled(pipe_config->pch_pfit.enabled));
11558 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11559 pipe_config->ips_enabled, pipe_config->double_wide);
11561 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
11563 DRM_DEBUG_KMS("planes on this crtc\n");
11564 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
11565 struct drm_format_name_buf format_name;
11566 intel_plane = to_intel_plane(plane);
11567 if (intel_plane->pipe != crtc->pipe)
11570 state = to_intel_plane_state(plane->state);
11571 fb = state->base.fb;
11573 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11574 plane->base.id, plane->name, state->scaler_id);
11578 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11579 plane->base.id, plane->name,
11580 fb->base.id, fb->width, fb->height,
11581 drm_get_format_name(fb->format->format, &format_name));
11582 if (INTEL_GEN(dev_priv) >= 9)
11583 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11585 state->base.src.x1 >> 16,
11586 state->base.src.y1 >> 16,
11587 drm_rect_width(&state->base.src) >> 16,
11588 drm_rect_height(&state->base.src) >> 16,
11589 state->base.dst.x1, state->base.dst.y1,
11590 drm_rect_width(&state->base.dst),
11591 drm_rect_height(&state->base.dst));
11595 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
11597 struct drm_device *dev = state->dev;
11598 struct drm_connector *connector;
11599 struct drm_connector_list_iter conn_iter;
11600 unsigned int used_ports = 0;
11601 unsigned int used_mst_ports = 0;
11605 * Walk the connector list instead of the encoder
11606 * list to detect the problem on ddi platforms
11607 * where there's just one encoder per digital port.
11609 drm_connector_list_iter_begin(dev, &conn_iter);
11610 drm_for_each_connector_iter(connector, &conn_iter) {
11611 struct drm_connector_state *connector_state;
11612 struct intel_encoder *encoder;
11614 connector_state = drm_atomic_get_new_connector_state(state, connector);
11615 if (!connector_state)
11616 connector_state = connector->state;
11618 if (!connector_state->best_encoder)
11621 encoder = to_intel_encoder(connector_state->best_encoder);
11623 WARN_ON(!connector_state->crtc);
11625 switch (encoder->type) {
11626 unsigned int port_mask;
11627 case INTEL_OUTPUT_DDI:
11628 if (WARN_ON(!HAS_DDI(to_i915(dev))))
11630 /* else: fall through */
11631 case INTEL_OUTPUT_DP:
11632 case INTEL_OUTPUT_HDMI:
11633 case INTEL_OUTPUT_EDP:
11634 port_mask = 1 << encoder->port;
11636 /* the same port mustn't appear more than once */
11637 if (used_ports & port_mask)
11640 used_ports |= port_mask;
11642 case INTEL_OUTPUT_DP_MST:
11644 1 << encoder->port;
11650 drm_connector_list_iter_end(&conn_iter);
11652 /* can't mix MST and SST/HDMI on the same port */
11653 if (used_ports & used_mst_ports)
11660 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11662 struct drm_i915_private *dev_priv =
11663 to_i915(crtc_state->base.crtc->dev);
11664 struct intel_crtc_state *saved_state;
11666 saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL);
11670 /* FIXME: before the switch to atomic started, a new pipe_config was
11671 * kzalloc'd. Code that depends on any field being zero should be
11672 * fixed, so that the crtc_state can be safely duplicated. For now,
11673 * only fields that are know to not cause problems are preserved. */
11675 saved_state->scaler_state = crtc_state->scaler_state;
11676 saved_state->shared_dpll = crtc_state->shared_dpll;
11677 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
11678 saved_state->pch_pfit.force_thru = crtc_state->pch_pfit.force_thru;
11679 saved_state->ips_force_disable = crtc_state->ips_force_disable;
11680 if (IS_G4X(dev_priv) ||
11681 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11682 saved_state->wm = crtc_state->wm;
11684 /* Keep base drm_crtc_state intact, only clear our extended struct */
11685 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11686 memcpy(&crtc_state->base + 1, &saved_state->base + 1,
11687 sizeof(*crtc_state) - sizeof(crtc_state->base));
11689 kfree(saved_state);
11694 intel_modeset_pipe_config(struct drm_crtc *crtc,
11695 struct intel_crtc_state *pipe_config)
11697 struct drm_atomic_state *state = pipe_config->base.state;
11698 struct intel_encoder *encoder;
11699 struct drm_connector *connector;
11700 struct drm_connector_state *connector_state;
11705 ret = clear_intel_crtc_state(pipe_config);
11709 pipe_config->cpu_transcoder =
11710 (enum transcoder) to_intel_crtc(crtc)->pipe;
11713 * Sanitize sync polarity flags based on requested ones. If neither
11714 * positive or negative polarity is requested, treat this as meaning
11715 * negative polarity.
11717 if (!(pipe_config->base.adjusted_mode.flags &
11718 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
11719 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
11721 if (!(pipe_config->base.adjusted_mode.flags &
11722 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
11723 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
11725 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11730 base_bpp = pipe_config->pipe_bpp;
11733 * Determine the real pipe dimensions. Note that stereo modes can
11734 * increase the actual pipe size due to the frame doubling and
11735 * insertion of additional space for blanks between the frame. This
11736 * is stored in the crtc timings. We use the requested mode to do this
11737 * computation to clearly distinguish it from the adjusted mode, which
11738 * can be changed by the connectors in the below retry loop.
11740 drm_mode_get_hv_timing(&pipe_config->base.mode,
11741 &pipe_config->pipe_src_w,
11742 &pipe_config->pipe_src_h);
11744 for_each_new_connector_in_state(state, connector, connector_state, i) {
11745 if (connector_state->crtc != crtc)
11748 encoder = to_intel_encoder(connector_state->best_encoder);
11750 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11751 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11756 * Determine output_types before calling the .compute_config()
11757 * hooks so that the hooks can use this information safely.
11759 if (encoder->compute_output_type)
11760 pipe_config->output_types |=
11761 BIT(encoder->compute_output_type(encoder, pipe_config,
11764 pipe_config->output_types |= BIT(encoder->type);
11768 /* Ensure the port clock defaults are reset when retrying. */
11769 pipe_config->port_clock = 0;
11770 pipe_config->pixel_multiplier = 1;
11772 /* Fill in default crtc timings, allow encoders to overwrite them. */
11773 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11774 CRTC_STEREO_DOUBLE);
11776 /* Pass our mode to the connectors and the CRTC to give them a chance to
11777 * adjust it according to limitations or connector properties, and also
11778 * a chance to reject the mode entirely.
11780 for_each_new_connector_in_state(state, connector, connector_state, i) {
11781 if (connector_state->crtc != crtc)
11784 encoder = to_intel_encoder(connector_state->best_encoder);
11785 ret = encoder->compute_config(encoder, pipe_config,
11788 if (ret != -EDEADLK)
11789 DRM_DEBUG_KMS("Encoder config failure: %d\n",
11795 /* Set default port clock if not overwritten by the encoder. Needs to be
11796 * done afterwards in case the encoder adjusts the mode. */
11797 if (!pipe_config->port_clock)
11798 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
11799 * pipe_config->pixel_multiplier;
11801 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
11802 if (ret == -EDEADLK)
11805 DRM_DEBUG_KMS("CRTC fixup failed\n");
11809 if (ret == RETRY) {
11810 if (WARN(!retry, "loop in pipe configuration computation\n"))
11813 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11815 goto encoder_retry;
11818 /* Dithering seems to not pass-through bits correctly when it should, so
11819 * only enable it on 6bpc panels and when its not a compliance
11820 * test requesting 6bpc video pattern.
11822 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11823 !pipe_config->dither_force_disable;
11824 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11825 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
11830 static bool intel_fuzzy_clock_check(int clock1, int clock2)
11834 if (clock1 == clock2)
11837 if (!clock1 || !clock2)
11840 diff = abs(clock1 - clock2);
11842 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11849 intel_compare_m_n(unsigned int m, unsigned int n,
11850 unsigned int m2, unsigned int n2,
11853 if (m == m2 && n == n2)
11856 if (exact || !m || !n || !m2 || !n2)
11859 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11866 } else if (n < n2) {
11876 return intel_fuzzy_clock_check(m, m2);
11880 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11881 struct intel_link_m_n *m2_n2,
11884 if (m_n->tu == m2_n2->tu &&
11885 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11886 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11887 intel_compare_m_n(m_n->link_m, m_n->link_n,
11888 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11898 static void __printf(3, 4)
11899 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11901 struct va_format vaf;
11904 va_start(args, format);
11909 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11911 drm_err("mismatch in %s %pV", name, &vaf);
11916 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
11918 if (i915_modparams.fastboot != -1)
11919 return i915_modparams.fastboot;
11921 /* Enable fastboot by default on Skylake and newer */
11922 if (INTEL_GEN(dev_priv) >= 9)
11925 /* Enable fastboot by default on VLV and CHV */
11926 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11929 /* Disabled by default on all others */
11934 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11935 struct intel_crtc_state *current_config,
11936 struct intel_crtc_state *pipe_config,
11940 bool fixup_inherited = adjust &&
11941 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11942 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11944 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
11945 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
11949 #define PIPE_CONF_CHECK_X(name) do { \
11950 if (current_config->name != pipe_config->name) { \
11951 pipe_config_err(adjust, __stringify(name), \
11952 "(expected 0x%08x, found 0x%08x)\n", \
11953 current_config->name, \
11954 pipe_config->name); \
11959 #define PIPE_CONF_CHECK_I(name) do { \
11960 if (current_config->name != pipe_config->name) { \
11961 pipe_config_err(adjust, __stringify(name), \
11962 "(expected %i, found %i)\n", \
11963 current_config->name, \
11964 pipe_config->name); \
11969 #define PIPE_CONF_CHECK_BOOL(name) do { \
11970 if (current_config->name != pipe_config->name) { \
11971 pipe_config_err(adjust, __stringify(name), \
11972 "(expected %s, found %s)\n", \
11973 yesno(current_config->name), \
11974 yesno(pipe_config->name)); \
11980 * Checks state where we only read out the enabling, but not the entire
11981 * state itself (like full infoframes or ELD for audio). These states
11982 * require a full modeset on bootup to fix up.
11984 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11985 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11986 PIPE_CONF_CHECK_BOOL(name); \
11988 pipe_config_err(adjust, __stringify(name), \
11989 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11990 yesno(current_config->name), \
11991 yesno(pipe_config->name)); \
11996 #define PIPE_CONF_CHECK_P(name) do { \
11997 if (current_config->name != pipe_config->name) { \
11998 pipe_config_err(adjust, __stringify(name), \
11999 "(expected %p, found %p)\n", \
12000 current_config->name, \
12001 pipe_config->name); \
12006 #define PIPE_CONF_CHECK_M_N(name) do { \
12007 if (!intel_compare_link_m_n(¤t_config->name, \
12008 &pipe_config->name,\
12010 pipe_config_err(adjust, __stringify(name), \
12011 "(expected tu %i gmch %i/%i link %i/%i, " \
12012 "found tu %i, gmch %i/%i link %i/%i)\n", \
12013 current_config->name.tu, \
12014 current_config->name.gmch_m, \
12015 current_config->name.gmch_n, \
12016 current_config->name.link_m, \
12017 current_config->name.link_n, \
12018 pipe_config->name.tu, \
12019 pipe_config->name.gmch_m, \
12020 pipe_config->name.gmch_n, \
12021 pipe_config->name.link_m, \
12022 pipe_config->name.link_n); \
12027 /* This is required for BDW+ where there is only one set of registers for
12028 * switching between high and low RR.
12029 * This macro can be used whenever a comparison has to be made between one
12030 * hw state and multiple sw state variables.
12032 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
12033 if (!intel_compare_link_m_n(¤t_config->name, \
12034 &pipe_config->name, adjust) && \
12035 !intel_compare_link_m_n(¤t_config->alt_name, \
12036 &pipe_config->name, adjust)) { \
12037 pipe_config_err(adjust, __stringify(name), \
12038 "(expected tu %i gmch %i/%i link %i/%i, " \
12039 "or tu %i gmch %i/%i link %i/%i, " \
12040 "found tu %i, gmch %i/%i link %i/%i)\n", \
12041 current_config->name.tu, \
12042 current_config->name.gmch_m, \
12043 current_config->name.gmch_n, \
12044 current_config->name.link_m, \
12045 current_config->name.link_n, \
12046 current_config->alt_name.tu, \
12047 current_config->alt_name.gmch_m, \
12048 current_config->alt_name.gmch_n, \
12049 current_config->alt_name.link_m, \
12050 current_config->alt_name.link_n, \
12051 pipe_config->name.tu, \
12052 pipe_config->name.gmch_m, \
12053 pipe_config->name.gmch_n, \
12054 pipe_config->name.link_m, \
12055 pipe_config->name.link_n); \
12060 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
12061 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12062 pipe_config_err(adjust, __stringify(name), \
12063 "(%x) (expected %i, found %i)\n", \
12065 current_config->name & (mask), \
12066 pipe_config->name & (mask)); \
12071 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
12072 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12073 pipe_config_err(adjust, __stringify(name), \
12074 "(expected %i, found %i)\n", \
12075 current_config->name, \
12076 pipe_config->name); \
12081 #define PIPE_CONF_QUIRK(quirk) \
12082 ((current_config->quirks | pipe_config->quirks) & (quirk))
12084 PIPE_CONF_CHECK_I(cpu_transcoder);
12086 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
12087 PIPE_CONF_CHECK_I(fdi_lanes);
12088 PIPE_CONF_CHECK_M_N(fdi_m_n);
12090 PIPE_CONF_CHECK_I(lane_count);
12091 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
12093 if (INTEL_GEN(dev_priv) < 8) {
12094 PIPE_CONF_CHECK_M_N(dp_m_n);
12096 if (current_config->has_drrs)
12097 PIPE_CONF_CHECK_M_N(dp_m2_n2);
12099 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
12101 PIPE_CONF_CHECK_X(output_types);
12103 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
12104 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
12105 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
12106 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
12107 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
12108 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
12110 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
12111 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
12112 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
12113 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
12114 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
12115 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
12117 PIPE_CONF_CHECK_I(pixel_multiplier);
12118 PIPE_CONF_CHECK_I(output_format);
12119 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
12120 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
12121 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12122 PIPE_CONF_CHECK_BOOL(limited_color_range);
12124 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
12125 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
12126 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
12128 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
12130 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12131 DRM_MODE_FLAG_INTERLACE);
12133 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
12134 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12135 DRM_MODE_FLAG_PHSYNC);
12136 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12137 DRM_MODE_FLAG_NHSYNC);
12138 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12139 DRM_MODE_FLAG_PVSYNC);
12140 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12141 DRM_MODE_FLAG_NVSYNC);
12144 PIPE_CONF_CHECK_X(gmch_pfit.control);
12145 /* pfit ratios are autocomputed by the hw on gen4+ */
12146 if (INTEL_GEN(dev_priv) < 4)
12147 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
12148 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
12151 PIPE_CONF_CHECK_I(pipe_src_w);
12152 PIPE_CONF_CHECK_I(pipe_src_h);
12154 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
12155 if (current_config->pch_pfit.enabled) {
12156 PIPE_CONF_CHECK_X(pch_pfit.pos);
12157 PIPE_CONF_CHECK_X(pch_pfit.size);
12160 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
12161 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
12164 PIPE_CONF_CHECK_BOOL(double_wide);
12166 PIPE_CONF_CHECK_P(shared_dpll);
12167 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
12168 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
12169 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
12170 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
12171 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
12172 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
12173 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
12174 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
12175 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
12176 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
12177 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
12178 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
12179 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
12180 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
12181 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
12182 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
12183 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
12184 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
12185 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
12186 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
12187 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
12188 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
12189 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
12190 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
12191 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
12192 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
12193 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
12194 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
12195 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
12196 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
12197 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
12199 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
12200 PIPE_CONF_CHECK_X(dsi_pll.div);
12202 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
12203 PIPE_CONF_CHECK_I(pipe_bpp);
12205 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
12206 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
12208 PIPE_CONF_CHECK_I(min_voltage_level);
12210 #undef PIPE_CONF_CHECK_X
12211 #undef PIPE_CONF_CHECK_I
12212 #undef PIPE_CONF_CHECK_BOOL
12213 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
12214 #undef PIPE_CONF_CHECK_P
12215 #undef PIPE_CONF_CHECK_FLAGS
12216 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12217 #undef PIPE_CONF_QUIRK
12222 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
12223 const struct intel_crtc_state *pipe_config)
12225 if (pipe_config->has_pch_encoder) {
12226 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
12227 &pipe_config->fdi_m_n);
12228 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
12231 * FDI already provided one idea for the dotclock.
12232 * Yell if the encoder disagrees.
12234 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
12235 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12236 fdi_dotclock, dotclock);
12240 static void verify_wm_state(struct drm_crtc *crtc,
12241 struct drm_crtc_state *new_state)
12243 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
12244 struct skl_ddb_allocation hw_ddb, *sw_ddb;
12245 struct skl_pipe_wm hw_wm, *sw_wm;
12246 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
12247 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
12248 struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES];
12249 struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES];
12250 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12251 const enum pipe pipe = intel_crtc->pipe;
12252 int plane, level, max_level = ilk_wm_max_level(dev_priv);
12254 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
12257 skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm);
12258 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
12260 skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv);
12262 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
12263 sw_ddb = &dev_priv->wm.skl_hw.ddb;
12265 if (INTEL_GEN(dev_priv) >= 11)
12266 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
12267 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
12268 sw_ddb->enabled_slices,
12269 hw_ddb.enabled_slices);
12271 for_each_universal_plane(dev_priv, pipe, plane) {
12272 hw_plane_wm = &hw_wm.planes[plane];
12273 sw_plane_wm = &sw_wm->planes[plane];
12276 for (level = 0; level <= max_level; level++) {
12277 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12278 &sw_plane_wm->wm[level]))
12281 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",
12282 pipe_name(pipe), plane + 1, level,
12283 sw_plane_wm->wm[level].plane_en,
12284 sw_plane_wm->wm[level].plane_res_b,
12285 sw_plane_wm->wm[level].plane_res_l,
12286 hw_plane_wm->wm[level].plane_en,
12287 hw_plane_wm->wm[level].plane_res_b,
12288 hw_plane_wm->wm[level].plane_res_l);
12291 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12292 &sw_plane_wm->trans_wm)) {
12293 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",
12294 pipe_name(pipe), plane + 1,
12295 sw_plane_wm->trans_wm.plane_en,
12296 sw_plane_wm->trans_wm.plane_res_b,
12297 sw_plane_wm->trans_wm.plane_res_l,
12298 hw_plane_wm->trans_wm.plane_en,
12299 hw_plane_wm->trans_wm.plane_res_b,
12300 hw_plane_wm->trans_wm.plane_res_l);
12304 hw_ddb_entry = &hw_ddb_y[plane];
12305 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane];
12307 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12308 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
12309 pipe_name(pipe), plane + 1,
12310 sw_ddb_entry->start, sw_ddb_entry->end,
12311 hw_ddb_entry->start, hw_ddb_entry->end);
12317 * If the cursor plane isn't active, we may not have updated it's ddb
12318 * allocation. In that case since the ddb allocation will be updated
12319 * once the plane becomes visible, we can skip this check
12322 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
12323 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
12326 for (level = 0; level <= max_level; level++) {
12327 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12328 &sw_plane_wm->wm[level]))
12331 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",
12332 pipe_name(pipe), level,
12333 sw_plane_wm->wm[level].plane_en,
12334 sw_plane_wm->wm[level].plane_res_b,
12335 sw_plane_wm->wm[level].plane_res_l,
12336 hw_plane_wm->wm[level].plane_en,
12337 hw_plane_wm->wm[level].plane_res_b,
12338 hw_plane_wm->wm[level].plane_res_l);
12341 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12342 &sw_plane_wm->trans_wm)) {
12343 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12345 sw_plane_wm->trans_wm.plane_en,
12346 sw_plane_wm->trans_wm.plane_res_b,
12347 sw_plane_wm->trans_wm.plane_res_l,
12348 hw_plane_wm->trans_wm.plane_en,
12349 hw_plane_wm->trans_wm.plane_res_b,
12350 hw_plane_wm->trans_wm.plane_res_l);
12354 hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR];
12355 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR];
12357 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12358 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
12360 sw_ddb_entry->start, sw_ddb_entry->end,
12361 hw_ddb_entry->start, hw_ddb_entry->end);
12367 verify_connector_state(struct drm_device *dev,
12368 struct drm_atomic_state *state,
12369 struct drm_crtc *crtc)
12371 struct drm_connector *connector;
12372 struct drm_connector_state *new_conn_state;
12375 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
12376 struct drm_encoder *encoder = connector->encoder;
12377 struct drm_crtc_state *crtc_state = NULL;
12379 if (new_conn_state->crtc != crtc)
12383 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
12385 intel_connector_verify_state(crtc_state, new_conn_state);
12387 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
12388 "connector's atomic encoder doesn't match legacy encoder\n");
12393 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
12395 struct intel_encoder *encoder;
12396 struct drm_connector *connector;
12397 struct drm_connector_state *old_conn_state, *new_conn_state;
12400 for_each_intel_encoder(dev, encoder) {
12401 bool enabled = false, found = false;
12404 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12405 encoder->base.base.id,
12406 encoder->base.name);
12408 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
12409 new_conn_state, i) {
12410 if (old_conn_state->best_encoder == &encoder->base)
12413 if (new_conn_state->best_encoder != &encoder->base)
12415 found = enabled = true;
12417 I915_STATE_WARN(new_conn_state->crtc !=
12418 encoder->base.crtc,
12419 "connector's crtc doesn't match encoder crtc\n");
12425 I915_STATE_WARN(!!encoder->base.crtc != enabled,
12426 "encoder's enabled state mismatch "
12427 "(expected %i, found %i)\n",
12428 !!encoder->base.crtc, enabled);
12430 if (!encoder->base.crtc) {
12433 active = encoder->get_hw_state(encoder, &pipe);
12434 I915_STATE_WARN(active,
12435 "encoder detached but still enabled on pipe %c.\n",
12442 verify_crtc_state(struct drm_crtc *crtc,
12443 struct drm_crtc_state *old_crtc_state,
12444 struct drm_crtc_state *new_crtc_state)
12446 struct drm_device *dev = crtc->dev;
12447 struct drm_i915_private *dev_priv = to_i915(dev);
12448 struct intel_encoder *encoder;
12449 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12450 struct intel_crtc_state *pipe_config, *sw_config;
12451 struct drm_atomic_state *old_state;
12454 old_state = old_crtc_state->state;
12455 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
12456 pipe_config = to_intel_crtc_state(old_crtc_state);
12457 memset(pipe_config, 0, sizeof(*pipe_config));
12458 pipe_config->base.crtc = crtc;
12459 pipe_config->base.state = old_state;
12461 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
12463 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
12465 /* we keep both pipes enabled on 830 */
12466 if (IS_I830(dev_priv))
12467 active = new_crtc_state->active;
12469 I915_STATE_WARN(new_crtc_state->active != active,
12470 "crtc active state doesn't match with hw state "
12471 "(expected %i, found %i)\n", new_crtc_state->active, active);
12473 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12474 "transitional active state does not match atomic hw state "
12475 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
12477 for_each_encoder_on_crtc(dev, crtc, encoder) {
12480 active = encoder->get_hw_state(encoder, &pipe);
12481 I915_STATE_WARN(active != new_crtc_state->active,
12482 "[ENCODER:%i] active %i with crtc active %i\n",
12483 encoder->base.base.id, active, new_crtc_state->active);
12485 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12486 "Encoder connected to wrong pipe %c\n",
12490 encoder->get_config(encoder, pipe_config);
12493 intel_crtc_compute_pixel_rate(pipe_config);
12495 if (!new_crtc_state->active)
12498 intel_pipe_config_sanity_check(dev_priv, pipe_config);
12500 sw_config = to_intel_crtc_state(new_crtc_state);
12501 if (!intel_pipe_config_compare(dev_priv, sw_config,
12502 pipe_config, false)) {
12503 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12504 intel_dump_pipe_config(intel_crtc, pipe_config,
12506 intel_dump_pipe_config(intel_crtc, sw_config,
12512 intel_verify_planes(struct intel_atomic_state *state)
12514 struct intel_plane *plane;
12515 const struct intel_plane_state *plane_state;
12518 for_each_new_intel_plane_in_state(state, plane,
12520 assert_plane(plane, plane_state->base.visible);
12524 verify_single_dpll_state(struct drm_i915_private *dev_priv,
12525 struct intel_shared_dpll *pll,
12526 struct drm_crtc *crtc,
12527 struct drm_crtc_state *new_state)
12529 struct intel_dpll_hw_state dpll_hw_state;
12530 unsigned int crtc_mask;
12533 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12535 DRM_DEBUG_KMS("%s\n", pll->info->name);
12537 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
12539 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
12540 I915_STATE_WARN(!pll->on && pll->active_mask,
12541 "pll in active use but not on in sw tracking\n");
12542 I915_STATE_WARN(pll->on && !pll->active_mask,
12543 "pll is on but not used by any active crtc\n");
12544 I915_STATE_WARN(pll->on != active,
12545 "pll on state mismatch (expected %i, found %i)\n",
12550 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
12551 "more active pll users than references: %x vs %x\n",
12552 pll->active_mask, pll->state.crtc_mask);
12557 crtc_mask = drm_crtc_mask(crtc);
12559 if (new_state->active)
12560 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12561 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12562 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12564 I915_STATE_WARN(pll->active_mask & crtc_mask,
12565 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12566 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12568 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
12569 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
12570 crtc_mask, pll->state.crtc_mask);
12572 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
12574 sizeof(dpll_hw_state)),
12575 "pll hw state mismatch\n");
12579 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12580 struct drm_crtc_state *old_crtc_state,
12581 struct drm_crtc_state *new_crtc_state)
12583 struct drm_i915_private *dev_priv = to_i915(dev);
12584 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12585 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12587 if (new_state->shared_dpll)
12588 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
12590 if (old_state->shared_dpll &&
12591 old_state->shared_dpll != new_state->shared_dpll) {
12592 unsigned int crtc_mask = drm_crtc_mask(crtc);
12593 struct intel_shared_dpll *pll = old_state->shared_dpll;
12595 I915_STATE_WARN(pll->active_mask & crtc_mask,
12596 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12597 pipe_name(drm_crtc_index(crtc)));
12598 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
12599 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12600 pipe_name(drm_crtc_index(crtc)));
12605 intel_modeset_verify_crtc(struct drm_crtc *crtc,
12606 struct drm_atomic_state *state,
12607 struct drm_crtc_state *old_state,
12608 struct drm_crtc_state *new_state)
12610 if (!needs_modeset(new_state) &&
12611 !to_intel_crtc_state(new_state)->update_pipe)
12614 verify_wm_state(crtc, new_state);
12615 verify_connector_state(crtc->dev, state, crtc);
12616 verify_crtc_state(crtc, old_state, new_state);
12617 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
12621 verify_disabled_dpll_state(struct drm_device *dev)
12623 struct drm_i915_private *dev_priv = to_i915(dev);
12626 for (i = 0; i < dev_priv->num_shared_dpll; i++)
12627 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
12631 intel_modeset_verify_disabled(struct drm_device *dev,
12632 struct drm_atomic_state *state)
12634 verify_encoder_state(dev, state);
12635 verify_connector_state(dev, state, NULL);
12636 verify_disabled_dpll_state(dev);
12639 static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
12641 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
12642 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12645 * The scanline counter increments at the leading edge of hsync.
12647 * On most platforms it starts counting from vtotal-1 on the
12648 * first active line. That means the scanline counter value is
12649 * always one less than what we would expect. Ie. just after
12650 * start of vblank, which also occurs at start of hsync (on the
12651 * last active line), the scanline counter will read vblank_start-1.
12653 * On gen2 the scanline counter starts counting from 1 instead
12654 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12655 * to keep the value positive), instead of adding one.
12657 * On HSW+ the behaviour of the scanline counter depends on the output
12658 * type. For DP ports it behaves like most other platforms, but on HDMI
12659 * there's an extra 1 line difference. So we need to add two instead of
12660 * one to the value.
12662 * On VLV/CHV DSI the scanline counter would appear to increment
12663 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12664 * that means we can't tell whether we're in vblank or not while
12665 * we're on that particular line. We must still set scanline_offset
12666 * to 1 so that the vblank timestamps come out correct when we query
12667 * the scanline counter from within the vblank interrupt handler.
12668 * However if queried just before the start of vblank we'll get an
12669 * answer that's slightly in the future.
12671 if (IS_GEN(dev_priv, 2)) {
12672 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
12675 vtotal = adjusted_mode->crtc_vtotal;
12676 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
12679 crtc->scanline_offset = vtotal - 1;
12680 } else if (HAS_DDI(dev_priv) &&
12681 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
12682 crtc->scanline_offset = 2;
12684 crtc->scanline_offset = 1;
12687 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
12689 struct drm_device *dev = state->dev;
12690 struct drm_i915_private *dev_priv = to_i915(dev);
12691 struct drm_crtc *crtc;
12692 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12695 if (!dev_priv->display.crtc_compute_clock)
12698 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12699 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12700 struct intel_shared_dpll *old_dpll =
12701 to_intel_crtc_state(old_crtc_state)->shared_dpll;
12703 if (!needs_modeset(new_crtc_state))
12706 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
12711 intel_release_shared_dpll(old_dpll, intel_crtc, state);
12716 * This implements the workaround described in the "notes" section of the mode
12717 * set sequence documentation. When going from no pipes or single pipe to
12718 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12719 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12721 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12723 struct drm_crtc_state *crtc_state;
12724 struct intel_crtc *intel_crtc;
12725 struct drm_crtc *crtc;
12726 struct intel_crtc_state *first_crtc_state = NULL;
12727 struct intel_crtc_state *other_crtc_state = NULL;
12728 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12731 /* look at all crtc's that are going to be enabled in during modeset */
12732 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
12733 intel_crtc = to_intel_crtc(crtc);
12735 if (!crtc_state->active || !needs_modeset(crtc_state))
12738 if (first_crtc_state) {
12739 other_crtc_state = to_intel_crtc_state(crtc_state);
12742 first_crtc_state = to_intel_crtc_state(crtc_state);
12743 first_pipe = intel_crtc->pipe;
12747 /* No workaround needed? */
12748 if (!first_crtc_state)
12751 /* w/a possibly needed, check how many crtc's are already enabled. */
12752 for_each_intel_crtc(state->dev, intel_crtc) {
12753 struct intel_crtc_state *pipe_config;
12755 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12756 if (IS_ERR(pipe_config))
12757 return PTR_ERR(pipe_config);
12759 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12761 if (!pipe_config->base.active ||
12762 needs_modeset(&pipe_config->base))
12765 /* 2 or more enabled crtcs means no need for w/a */
12766 if (enabled_pipe != INVALID_PIPE)
12769 enabled_pipe = intel_crtc->pipe;
12772 if (enabled_pipe != INVALID_PIPE)
12773 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12774 else if (other_crtc_state)
12775 other_crtc_state->hsw_workaround_pipe = first_pipe;
12780 static int intel_lock_all_pipes(struct drm_atomic_state *state)
12782 struct drm_crtc *crtc;
12784 /* Add all pipes to the state */
12785 for_each_crtc(state->dev, crtc) {
12786 struct drm_crtc_state *crtc_state;
12788 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12789 if (IS_ERR(crtc_state))
12790 return PTR_ERR(crtc_state);
12796 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12798 struct drm_crtc *crtc;
12801 * Add all pipes to the state, and force
12802 * a modeset on all the active ones.
12804 for_each_crtc(state->dev, crtc) {
12805 struct drm_crtc_state *crtc_state;
12808 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12809 if (IS_ERR(crtc_state))
12810 return PTR_ERR(crtc_state);
12812 if (!crtc_state->active || needs_modeset(crtc_state))
12815 crtc_state->mode_changed = true;
12817 ret = drm_atomic_add_affected_connectors(state, crtc);
12821 ret = drm_atomic_add_affected_planes(state, crtc);
12829 static int intel_modeset_checks(struct drm_atomic_state *state)
12831 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12832 struct drm_i915_private *dev_priv = to_i915(state->dev);
12833 struct drm_crtc *crtc;
12834 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12837 if (!check_digital_port_conflicts(state)) {
12838 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12842 intel_state->modeset = true;
12843 intel_state->active_crtcs = dev_priv->active_crtcs;
12844 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12845 intel_state->cdclk.actual = dev_priv->cdclk.actual;
12847 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12848 if (new_crtc_state->active)
12849 intel_state->active_crtcs |= 1 << i;
12851 intel_state->active_crtcs &= ~(1 << i);
12853 if (old_crtc_state->active != new_crtc_state->active)
12854 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
12858 * See if the config requires any additional preparation, e.g.
12859 * to adjust global state with pipes off. We need to do this
12860 * here so we can get the modeset_pipe updated config for the new
12861 * mode set on this crtc. For other crtcs we need to use the
12862 * adjusted_mode bits in the crtc directly.
12864 if (dev_priv->display.modeset_calc_cdclk) {
12865 ret = dev_priv->display.modeset_calc_cdclk(state);
12870 * Writes to dev_priv->cdclk.logical must protected by
12871 * holding all the crtc locks, even if we don't end up
12872 * touching the hardware
12874 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12875 &intel_state->cdclk.logical)) {
12876 ret = intel_lock_all_pipes(state);
12881 /* All pipes must be switched off while we change the cdclk. */
12882 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12883 &intel_state->cdclk.actual)) {
12884 ret = intel_modeset_all_pipes(state);
12889 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12890 intel_state->cdclk.logical.cdclk,
12891 intel_state->cdclk.actual.cdclk);
12892 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12893 intel_state->cdclk.logical.voltage_level,
12894 intel_state->cdclk.actual.voltage_level);
12896 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12899 intel_modeset_clear_plls(state);
12901 if (IS_HASWELL(dev_priv))
12902 return haswell_mode_set_planes_workaround(state);
12908 * Handle calculation of various watermark data at the end of the atomic check
12909 * phase. The code here should be run after the per-crtc and per-plane 'check'
12910 * handlers to ensure that all derived state has been updated.
12912 static int calc_watermark_data(struct intel_atomic_state *state)
12914 struct drm_device *dev = state->base.dev;
12915 struct drm_i915_private *dev_priv = to_i915(dev);
12917 /* Is there platform-specific watermark information to calculate? */
12918 if (dev_priv->display.compute_global_watermarks)
12919 return dev_priv->display.compute_global_watermarks(state);
12925 * intel_atomic_check - validate state object
12927 * @state: state to validate
12929 static int intel_atomic_check(struct drm_device *dev,
12930 struct drm_atomic_state *state)
12932 struct drm_i915_private *dev_priv = to_i915(dev);
12933 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12934 struct drm_crtc *crtc;
12935 struct drm_crtc_state *old_crtc_state, *crtc_state;
12937 bool any_ms = false;
12939 /* Catch I915_MODE_FLAG_INHERITED */
12940 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12942 if (crtc_state->mode.private_flags !=
12943 old_crtc_state->mode.private_flags)
12944 crtc_state->mode_changed = true;
12947 ret = drm_atomic_helper_check_modeset(dev, state);
12951 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12952 struct intel_crtc_state *pipe_config =
12953 to_intel_crtc_state(crtc_state);
12955 if (!needs_modeset(crtc_state))
12958 if (!crtc_state->enable) {
12963 ret = intel_modeset_pipe_config(crtc, pipe_config);
12964 if (ret == -EDEADLK)
12967 intel_dump_pipe_config(to_intel_crtc(crtc),
12968 pipe_config, "[failed]");
12972 if (intel_pipe_config_compare(dev_priv,
12973 to_intel_crtc_state(old_crtc_state),
12974 pipe_config, true)) {
12975 crtc_state->mode_changed = false;
12976 pipe_config->update_pipe = true;
12979 if (needs_modeset(crtc_state))
12982 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12983 needs_modeset(crtc_state) ?
12984 "[modeset]" : "[fastset]");
12987 ret = drm_dp_mst_atomic_check(state);
12992 ret = intel_modeset_checks(state);
12997 intel_state->cdclk.logical = dev_priv->cdclk.logical;
13000 ret = icl_add_linked_planes(intel_state);
13004 ret = drm_atomic_helper_check_planes(dev, state);
13008 intel_fbc_choose_crtc(dev_priv, intel_state);
13009 return calc_watermark_data(intel_state);
13012 static int intel_atomic_prepare_commit(struct drm_device *dev,
13013 struct drm_atomic_state *state)
13015 return drm_atomic_helper_prepare_planes(dev, state);
13018 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
13020 struct drm_device *dev = crtc->base.dev;
13021 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
13023 if (!vblank->max_vblank_count)
13024 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
13026 return dev->driver->get_vblank_counter(dev, crtc->pipe);
13029 static void intel_update_crtc(struct drm_crtc *crtc,
13030 struct drm_atomic_state *state,
13031 struct drm_crtc_state *old_crtc_state,
13032 struct drm_crtc_state *new_crtc_state)
13034 struct drm_device *dev = crtc->dev;
13035 struct drm_i915_private *dev_priv = to_i915(dev);
13036 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13037 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
13038 bool modeset = needs_modeset(new_crtc_state);
13039 struct intel_plane_state *new_plane_state =
13040 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
13041 to_intel_plane(crtc->primary));
13044 update_scanline_offset(pipe_config);
13045 dev_priv->display.crtc_enable(pipe_config, state);
13047 /* vblanks work again, re-enable pipe CRC. */
13048 intel_crtc_enable_pipe_crc(intel_crtc);
13050 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
13053 if (pipe_config->update_pipe)
13054 intel_encoders_update_pipe(crtc, pipe_config, state);
13057 if (pipe_config->update_pipe && !pipe_config->enable_fbc)
13058 intel_fbc_disable(intel_crtc);
13059 else if (new_plane_state)
13060 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
13062 intel_begin_crtc_commit(crtc, old_crtc_state);
13064 if (INTEL_GEN(dev_priv) >= 9)
13065 skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
13067 i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
13069 intel_finish_crtc_commit(crtc, old_crtc_state);
13072 static void intel_update_crtcs(struct drm_atomic_state *state)
13074 struct drm_crtc *crtc;
13075 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
13078 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13079 if (!new_crtc_state->active)
13082 intel_update_crtc(crtc, state, old_crtc_state,
13087 static void skl_update_crtcs(struct drm_atomic_state *state)
13089 struct drm_i915_private *dev_priv = to_i915(state->dev);
13090 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13091 struct drm_crtc *crtc;
13092 struct intel_crtc *intel_crtc;
13093 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
13094 struct intel_crtc_state *cstate;
13095 unsigned int updated = 0;
13099 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
13100 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
13101 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
13103 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
13104 /* ignore allocations for crtc's that have been turned off. */
13105 if (new_crtc_state->active)
13106 entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
13108 /* If 2nd DBuf slice required, enable it here */
13109 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
13110 icl_dbuf_slices_update(dev_priv, required_slices);
13113 * Whenever the number of active pipes changes, we need to make sure we
13114 * update the pipes in the right order so that their ddb allocations
13115 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
13116 * cause pipe underruns and other bad stuff.
13121 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13122 bool vbl_wait = false;
13123 unsigned int cmask = drm_crtc_mask(crtc);
13125 intel_crtc = to_intel_crtc(crtc);
13126 cstate = to_intel_crtc_state(new_crtc_state);
13127 pipe = intel_crtc->pipe;
13129 if (updated & cmask || !cstate->base.active)
13132 if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb,
13134 INTEL_INFO(dev_priv)->num_pipes, i))
13138 entries[i] = cstate->wm.skl.ddb;
13141 * If this is an already active pipe, it's DDB changed,
13142 * and this isn't the last pipe that needs updating
13143 * then we need to wait for a vblank to pass for the
13144 * new ddb allocation to take effect.
13146 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
13147 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
13148 !new_crtc_state->active_changed &&
13149 intel_state->wm_results.dirty_pipes != updated)
13152 intel_update_crtc(crtc, state, old_crtc_state,
13156 intel_wait_for_vblank(dev_priv, pipe);
13160 } while (progress);
13162 /* If 2nd DBuf slice is no more required disable it */
13163 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
13164 icl_dbuf_slices_update(dev_priv, required_slices);
13167 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
13169 struct intel_atomic_state *state, *next;
13170 struct llist_node *freed;
13172 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
13173 llist_for_each_entry_safe(state, next, freed, freed)
13174 drm_atomic_state_put(&state->base);
13177 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
13179 struct drm_i915_private *dev_priv =
13180 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
13182 intel_atomic_helper_free_state(dev_priv);
13185 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
13187 struct wait_queue_entry wait_fence, wait_reset;
13188 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
13190 init_wait_entry(&wait_fence, 0);
13191 init_wait_entry(&wait_reset, 0);
13193 prepare_to_wait(&intel_state->commit_ready.wait,
13194 &wait_fence, TASK_UNINTERRUPTIBLE);
13195 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
13196 &wait_reset, TASK_UNINTERRUPTIBLE);
13199 if (i915_sw_fence_done(&intel_state->commit_ready)
13200 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
13205 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
13206 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
13209 static void intel_atomic_cleanup_work(struct work_struct *work)
13211 struct drm_atomic_state *state =
13212 container_of(work, struct drm_atomic_state, commit_work);
13213 struct drm_i915_private *i915 = to_i915(state->dev);
13215 drm_atomic_helper_cleanup_planes(&i915->drm, state);
13216 drm_atomic_helper_commit_cleanup_done(state);
13217 drm_atomic_state_put(state);
13219 intel_atomic_helper_free_state(i915);
13222 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
13224 struct drm_device *dev = state->dev;
13225 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13226 struct drm_i915_private *dev_priv = to_i915(dev);
13227 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
13228 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
13229 struct drm_crtc *crtc;
13230 struct intel_crtc *intel_crtc;
13231 u64 put_domains[I915_MAX_PIPES] = {};
13232 intel_wakeref_t wakeref = 0;
13235 intel_atomic_commit_fence_wait(intel_state);
13237 drm_atomic_helper_wait_for_dependencies(state);
13239 if (intel_state->modeset)
13240 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
13242 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13243 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
13244 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13245 intel_crtc = to_intel_crtc(crtc);
13247 if (needs_modeset(new_crtc_state) ||
13248 to_intel_crtc_state(new_crtc_state)->update_pipe) {
13250 put_domains[intel_crtc->pipe] =
13251 modeset_get_crtc_power_domains(crtc,
13252 new_intel_crtc_state);
13255 if (!needs_modeset(new_crtc_state))
13258 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
13260 if (old_crtc_state->active) {
13261 intel_crtc_disable_planes(intel_state, intel_crtc);
13264 * We need to disable pipe CRC before disabling the pipe,
13265 * or we race against vblank off.
13267 intel_crtc_disable_pipe_crc(intel_crtc);
13269 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
13270 intel_crtc->active = false;
13271 intel_fbc_disable(intel_crtc);
13272 intel_disable_shared_dpll(old_intel_crtc_state);
13275 * Underruns don't always raise
13276 * interrupts, so check manually.
13278 intel_check_cpu_fifo_underruns(dev_priv);
13279 intel_check_pch_fifo_underruns(dev_priv);
13281 /* FIXME unify this for all platforms */
13282 if (!new_crtc_state->active &&
13283 !HAS_GMCH(dev_priv) &&
13284 dev_priv->display.initial_watermarks)
13285 dev_priv->display.initial_watermarks(intel_state,
13286 new_intel_crtc_state);
13290 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
13291 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
13292 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
13294 if (intel_state->modeset) {
13295 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
13297 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
13300 * SKL workaround: bspec recommends we disable the SAGV when we
13301 * have more then one pipe enabled
13303 if (!intel_can_enable_sagv(state))
13304 intel_disable_sagv(dev_priv);
13306 intel_modeset_verify_disabled(dev, state);
13309 /* Complete the events for pipes that have now been disabled */
13310 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13311 bool modeset = needs_modeset(new_crtc_state);
13313 /* Complete events for now disable pipes here. */
13314 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
13315 spin_lock_irq(&dev->event_lock);
13316 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
13317 spin_unlock_irq(&dev->event_lock);
13319 new_crtc_state->event = NULL;
13323 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13324 dev_priv->display.update_crtcs(state);
13326 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13327 * already, but still need the state for the delayed optimization. To
13329 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13330 * - schedule that vblank worker _before_ calling hw_done
13331 * - at the start of commit_tail, cancel it _synchrously
13332 * - switch over to the vblank wait helper in the core after that since
13333 * we don't need out special handling any more.
13335 drm_atomic_helper_wait_for_flip_done(dev, state);
13337 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13338 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13340 if (new_crtc_state->active &&
13341 !needs_modeset(new_crtc_state) &&
13342 (new_intel_crtc_state->base.color_mgmt_changed ||
13343 new_intel_crtc_state->update_pipe))
13344 intel_color_load_luts(new_intel_crtc_state);
13348 * Now that the vblank has passed, we can go ahead and program the
13349 * optimal watermarks on platforms that need two-step watermark
13352 * TODO: Move this (and other cleanup) to an async worker eventually.
13354 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13355 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13357 if (dev_priv->display.optimize_watermarks)
13358 dev_priv->display.optimize_watermarks(intel_state,
13359 new_intel_crtc_state);
13362 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13363 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
13365 if (put_domains[i])
13366 modeset_put_power_domains(dev_priv, put_domains[i]);
13368 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
13371 if (intel_state->modeset)
13372 intel_verify_planes(intel_state);
13374 if (intel_state->modeset && intel_can_enable_sagv(state))
13375 intel_enable_sagv(dev_priv);
13377 drm_atomic_helper_commit_hw_done(state);
13379 if (intel_state->modeset) {
13380 /* As one of the primary mmio accessors, KMS has a high
13381 * likelihood of triggering bugs in unclaimed access. After we
13382 * finish modesetting, see if an error has been flagged, and if
13383 * so enable debugging for the next modeset - and hope we catch
13386 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
13387 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
13391 * Defer the cleanup of the old state to a separate worker to not
13392 * impede the current task (userspace for blocking modesets) that
13393 * are executed inline. For out-of-line asynchronous modesets/flips,
13394 * deferring to a new worker seems overkill, but we would place a
13395 * schedule point (cond_resched()) here anyway to keep latencies
13398 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
13399 queue_work(system_highpri_wq, &state->commit_work);
13402 static void intel_atomic_commit_work(struct work_struct *work)
13404 struct drm_atomic_state *state =
13405 container_of(work, struct drm_atomic_state, commit_work);
13407 intel_atomic_commit_tail(state);
13410 static int __i915_sw_fence_call
13411 intel_atomic_commit_ready(struct i915_sw_fence *fence,
13412 enum i915_sw_fence_notify notify)
13414 struct intel_atomic_state *state =
13415 container_of(fence, struct intel_atomic_state, commit_ready);
13418 case FENCE_COMPLETE:
13419 /* we do blocking waits in the worker, nothing to do here */
13423 struct intel_atomic_helper *helper =
13424 &to_i915(state->base.dev)->atomic_helper;
13426 if (llist_add(&state->freed, &helper->free_list))
13427 schedule_work(&helper->free_work);
13432 return NOTIFY_DONE;
13435 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
13437 struct drm_plane_state *old_plane_state, *new_plane_state;
13438 struct drm_plane *plane;
13441 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
13442 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
13443 intel_fb_obj(new_plane_state->fb),
13444 to_intel_plane(plane)->frontbuffer_bit);
13448 * intel_atomic_commit - commit validated state object
13450 * @state: the top-level driver state object
13451 * @nonblock: nonblocking commit
13453 * This function commits a top-level state object that has been validated
13454 * with drm_atomic_helper_check().
13457 * Zero for success or -errno.
13459 static int intel_atomic_commit(struct drm_device *dev,
13460 struct drm_atomic_state *state,
13463 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13464 struct drm_i915_private *dev_priv = to_i915(dev);
13467 drm_atomic_state_get(state);
13468 i915_sw_fence_init(&intel_state->commit_ready,
13469 intel_atomic_commit_ready);
13472 * The intel_legacy_cursor_update() fast path takes care
13473 * of avoiding the vblank waits for simple cursor
13474 * movement and flips. For cursor on/off and size changes,
13475 * we want to perform the vblank waits so that watermark
13476 * updates happen during the correct frames. Gen9+ have
13477 * double buffered watermarks and so shouldn't need this.
13479 * Unset state->legacy_cursor_update before the call to
13480 * drm_atomic_helper_setup_commit() because otherwise
13481 * drm_atomic_helper_wait_for_flip_done() is a noop and
13482 * we get FIFO underruns because we didn't wait
13485 * FIXME doing watermarks and fb cleanup from a vblank worker
13486 * (assuming we had any) would solve these problems.
13488 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13489 struct intel_crtc_state *new_crtc_state;
13490 struct intel_crtc *crtc;
13493 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13494 if (new_crtc_state->wm.need_postvbl_update ||
13495 new_crtc_state->update_wm_post)
13496 state->legacy_cursor_update = false;
13499 ret = intel_atomic_prepare_commit(dev, state);
13501 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13502 i915_sw_fence_commit(&intel_state->commit_ready);
13506 ret = drm_atomic_helper_setup_commit(state, nonblock);
13508 ret = drm_atomic_helper_swap_state(state, true);
13511 i915_sw_fence_commit(&intel_state->commit_ready);
13513 drm_atomic_helper_cleanup_planes(dev, state);
13516 dev_priv->wm.distrust_bios_wm = false;
13517 intel_shared_dpll_swap_state(state);
13518 intel_atomic_track_fbs(state);
13520 if (intel_state->modeset) {
13521 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13522 sizeof(intel_state->min_cdclk));
13523 memcpy(dev_priv->min_voltage_level,
13524 intel_state->min_voltage_level,
13525 sizeof(intel_state->min_voltage_level));
13526 dev_priv->active_crtcs = intel_state->active_crtcs;
13527 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13528 dev_priv->cdclk.actual = intel_state->cdclk.actual;
13531 drm_atomic_state_get(state);
13532 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
13534 i915_sw_fence_commit(&intel_state->commit_ready);
13535 if (nonblock && intel_state->modeset) {
13536 queue_work(dev_priv->modeset_wq, &state->commit_work);
13537 } else if (nonblock) {
13538 queue_work(system_unbound_wq, &state->commit_work);
13540 if (intel_state->modeset)
13541 flush_workqueue(dev_priv->modeset_wq);
13542 intel_atomic_commit_tail(state);
13548 static const struct drm_crtc_funcs intel_crtc_funcs = {
13549 .gamma_set = drm_atomic_helper_legacy_gamma_set,
13550 .set_config = drm_atomic_helper_set_config,
13551 .destroy = intel_crtc_destroy,
13552 .page_flip = drm_atomic_helper_page_flip,
13553 .atomic_duplicate_state = intel_crtc_duplicate_state,
13554 .atomic_destroy_state = intel_crtc_destroy_state,
13555 .set_crc_source = intel_crtc_set_crc_source,
13556 .verify_crc_source = intel_crtc_verify_crc_source,
13557 .get_crc_sources = intel_crtc_get_crc_sources,
13560 struct wait_rps_boost {
13561 struct wait_queue_entry wait;
13563 struct drm_crtc *crtc;
13564 struct i915_request *request;
13567 static int do_rps_boost(struct wait_queue_entry *_wait,
13568 unsigned mode, int sync, void *key)
13570 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
13571 struct i915_request *rq = wait->request;
13574 * If we missed the vblank, but the request is already running it
13575 * is reasonable to assume that it will complete before the next
13576 * vblank without our intervention, so leave RPS alone.
13578 if (!i915_request_started(rq))
13579 gen6_rps_boost(rq, NULL);
13580 i915_request_put(rq);
13582 drm_crtc_vblank_put(wait->crtc);
13584 list_del(&wait->wait.entry);
13589 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13590 struct dma_fence *fence)
13592 struct wait_rps_boost *wait;
13594 if (!dma_fence_is_i915(fence))
13597 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13600 if (drm_crtc_vblank_get(crtc))
13603 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13605 drm_crtc_vblank_put(crtc);
13609 wait->request = to_request(dma_fence_get(fence));
13612 wait->wait.func = do_rps_boost;
13613 wait->wait.flags = 0;
13615 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13618 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13620 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13621 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13622 struct drm_framebuffer *fb = plane_state->base.fb;
13623 struct i915_vma *vma;
13625 if (plane->id == PLANE_CURSOR &&
13626 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
13627 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13628 const int align = intel_cursor_alignment(dev_priv);
13631 err = i915_gem_object_attach_phys(obj, align);
13636 vma = intel_pin_and_fence_fb_obj(fb,
13637 &plane_state->view,
13638 intel_plane_uses_fence(plane_state),
13639 &plane_state->flags);
13641 return PTR_ERR(vma);
13643 plane_state->vma = vma;
13648 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13650 struct i915_vma *vma;
13652 vma = fetch_and_zero(&old_plane_state->vma);
13654 intel_unpin_fb_vma(vma, old_plane_state->flags);
13657 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13659 struct i915_sched_attr attr = {
13660 .priority = I915_PRIORITY_DISPLAY,
13663 i915_gem_object_wait_priority(obj, 0, &attr);
13667 * intel_prepare_plane_fb - Prepare fb for usage on plane
13668 * @plane: drm plane to prepare for
13669 * @new_state: the plane state being prepared
13671 * Prepares a framebuffer for usage on a display plane. Generally this
13672 * involves pinning the underlying object and updating the frontbuffer tracking
13673 * bits. Some older platforms need special physical address handling for
13676 * Must be called with struct_mutex held.
13678 * Returns 0 on success, negative error code on failure.
13681 intel_prepare_plane_fb(struct drm_plane *plane,
13682 struct drm_plane_state *new_state)
13684 struct intel_atomic_state *intel_state =
13685 to_intel_atomic_state(new_state->state);
13686 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13687 struct drm_framebuffer *fb = new_state->fb;
13688 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13689 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
13693 struct drm_crtc_state *crtc_state =
13694 drm_atomic_get_new_crtc_state(new_state->state,
13695 plane->state->crtc);
13697 /* Big Hammer, we also need to ensure that any pending
13698 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13699 * current scanout is retired before unpinning the old
13700 * framebuffer. Note that we rely on userspace rendering
13701 * into the buffer attached to the pipe they are waiting
13702 * on. If not, userspace generates a GPU hang with IPEHR
13703 * point to the MI_WAIT_FOR_EVENT.
13705 * This should only fail upon a hung GPU, in which case we
13706 * can safely continue.
13708 if (needs_modeset(crtc_state)) {
13709 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13710 old_obj->resv, NULL,
13718 if (new_state->fence) { /* explicit fencing */
13719 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13721 I915_FENCE_TIMEOUT,
13730 ret = i915_gem_object_pin_pages(obj);
13734 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13736 i915_gem_object_unpin_pages(obj);
13740 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
13742 mutex_unlock(&dev_priv->drm.struct_mutex);
13743 i915_gem_object_unpin_pages(obj);
13747 fb_obj_bump_render_priority(obj);
13748 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13750 if (!new_state->fence) { /* implicit fencing */
13751 struct dma_fence *fence;
13753 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13755 false, I915_FENCE_TIMEOUT,
13760 fence = reservation_object_get_excl_rcu(obj->resv);
13762 add_rps_boost_after_vblank(new_state->crtc, fence);
13763 dma_fence_put(fence);
13766 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
13770 * We declare pageflips to be interactive and so merit a small bias
13771 * towards upclocking to deliver the frame on time. By only changing
13772 * the RPS thresholds to sample more regularly and aim for higher
13773 * clocks we can hopefully deliver low power workloads (like kodi)
13774 * that are not quite steady state without resorting to forcing
13775 * maximum clocks following a vblank miss (see do_rps_boost()).
13777 if (!intel_state->rps_interactive) {
13778 intel_rps_mark_interactive(dev_priv, true);
13779 intel_state->rps_interactive = true;
13786 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13787 * @plane: drm plane to clean up for
13788 * @old_state: the state from the previous modeset
13790 * Cleans up a framebuffer that has just been removed from a plane.
13792 * Must be called with struct_mutex held.
13795 intel_cleanup_plane_fb(struct drm_plane *plane,
13796 struct drm_plane_state *old_state)
13798 struct intel_atomic_state *intel_state =
13799 to_intel_atomic_state(old_state->state);
13800 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13802 if (intel_state->rps_interactive) {
13803 intel_rps_mark_interactive(dev_priv, false);
13804 intel_state->rps_interactive = false;
13807 /* Should only be called after a successful intel_prepare_plane_fb()! */
13808 mutex_lock(&dev_priv->drm.struct_mutex);
13809 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13810 mutex_unlock(&dev_priv->drm.struct_mutex);
13814 skl_max_scale(const struct intel_crtc_state *crtc_state,
13817 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13818 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13819 int max_scale, mult;
13820 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
13822 if (!crtc_state->base.enable)
13823 return DRM_PLANE_HELPER_NO_SCALING;
13825 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13826 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13828 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
13831 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
13832 return DRM_PLANE_HELPER_NO_SCALING;
13835 * skl max scale is lower of:
13836 * close to 3 but not 3, -1 is for that purpose
13840 mult = is_planar_yuv_format(pixel_format) ? 2 : 3;
13841 tmpclk1 = (1 << 16) * mult - 1;
13842 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13843 max_scale = min(tmpclk1, tmpclk2);
13848 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13849 struct drm_crtc_state *old_crtc_state)
13851 struct drm_device *dev = crtc->dev;
13852 struct drm_i915_private *dev_priv = to_i915(dev);
13853 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13854 struct intel_crtc_state *old_intel_cstate =
13855 to_intel_crtc_state(old_crtc_state);
13856 struct intel_atomic_state *old_intel_state =
13857 to_intel_atomic_state(old_crtc_state->state);
13858 struct intel_crtc_state *intel_cstate =
13859 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13860 bool modeset = needs_modeset(&intel_cstate->base);
13862 /* Perform vblank evasion around commit operation */
13863 intel_pipe_update_start(intel_cstate);
13868 if (intel_cstate->base.color_mgmt_changed ||
13869 intel_cstate->update_pipe)
13870 intel_color_commit(intel_cstate);
13872 if (intel_cstate->update_pipe)
13873 intel_update_pipe_config(old_intel_cstate, intel_cstate);
13874 else if (INTEL_GEN(dev_priv) >= 9)
13875 skl_detach_scalers(intel_cstate);
13878 if (dev_priv->display.atomic_update_watermarks)
13879 dev_priv->display.atomic_update_watermarks(old_intel_state,
13883 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13884 struct intel_crtc_state *crtc_state)
13886 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13888 if (!IS_GEN(dev_priv, 2))
13889 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13891 if (crtc_state->has_pch_encoder) {
13892 enum pipe pch_transcoder =
13893 intel_crtc_pch_transcoder(crtc);
13895 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13899 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13900 struct drm_crtc_state *old_crtc_state)
13902 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13903 struct intel_atomic_state *old_intel_state =
13904 to_intel_atomic_state(old_crtc_state->state);
13905 struct intel_crtc_state *new_crtc_state =
13906 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13908 intel_pipe_update_end(new_crtc_state);
13910 if (new_crtc_state->update_pipe &&
13911 !needs_modeset(&new_crtc_state->base) &&
13912 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13913 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
13917 * intel_plane_destroy - destroy a plane
13918 * @plane: plane to destroy
13920 * Common destruction function for all types of planes (primary, cursor,
13923 void intel_plane_destroy(struct drm_plane *plane)
13925 drm_plane_cleanup(plane);
13926 kfree(to_intel_plane(plane));
13929 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13930 u32 format, u64 modifier)
13932 switch (modifier) {
13933 case DRM_FORMAT_MOD_LINEAR:
13934 case I915_FORMAT_MOD_X_TILED:
13941 case DRM_FORMAT_C8:
13942 case DRM_FORMAT_RGB565:
13943 case DRM_FORMAT_XRGB1555:
13944 case DRM_FORMAT_XRGB8888:
13945 return modifier == DRM_FORMAT_MOD_LINEAR ||
13946 modifier == I915_FORMAT_MOD_X_TILED;
13952 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13953 u32 format, u64 modifier)
13955 switch (modifier) {
13956 case DRM_FORMAT_MOD_LINEAR:
13957 case I915_FORMAT_MOD_X_TILED:
13964 case DRM_FORMAT_C8:
13965 case DRM_FORMAT_RGB565:
13966 case DRM_FORMAT_XRGB8888:
13967 case DRM_FORMAT_XBGR8888:
13968 case DRM_FORMAT_XRGB2101010:
13969 case DRM_FORMAT_XBGR2101010:
13970 return modifier == DRM_FORMAT_MOD_LINEAR ||
13971 modifier == I915_FORMAT_MOD_X_TILED;
13977 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13978 u32 format, u64 modifier)
13980 return modifier == DRM_FORMAT_MOD_LINEAR &&
13981 format == DRM_FORMAT_ARGB8888;
13984 static const struct drm_plane_funcs i965_plane_funcs = {
13985 .update_plane = drm_atomic_helper_update_plane,
13986 .disable_plane = drm_atomic_helper_disable_plane,
13987 .destroy = intel_plane_destroy,
13988 .atomic_get_property = intel_plane_atomic_get_property,
13989 .atomic_set_property = intel_plane_atomic_set_property,
13990 .atomic_duplicate_state = intel_plane_duplicate_state,
13991 .atomic_destroy_state = intel_plane_destroy_state,
13992 .format_mod_supported = i965_plane_format_mod_supported,
13995 static const struct drm_plane_funcs i8xx_plane_funcs = {
13996 .update_plane = drm_atomic_helper_update_plane,
13997 .disable_plane = drm_atomic_helper_disable_plane,
13998 .destroy = intel_plane_destroy,
13999 .atomic_get_property = intel_plane_atomic_get_property,
14000 .atomic_set_property = intel_plane_atomic_set_property,
14001 .atomic_duplicate_state = intel_plane_duplicate_state,
14002 .atomic_destroy_state = intel_plane_destroy_state,
14003 .format_mod_supported = i8xx_plane_format_mod_supported,
14007 intel_legacy_cursor_update(struct drm_plane *plane,
14008 struct drm_crtc *crtc,
14009 struct drm_framebuffer *fb,
14010 int crtc_x, int crtc_y,
14011 unsigned int crtc_w, unsigned int crtc_h,
14012 u32 src_x, u32 src_y,
14013 u32 src_w, u32 src_h,
14014 struct drm_modeset_acquire_ctx *ctx)
14016 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
14018 struct drm_plane_state *old_plane_state, *new_plane_state;
14019 struct intel_plane *intel_plane = to_intel_plane(plane);
14020 struct drm_framebuffer *old_fb;
14021 struct intel_crtc_state *crtc_state =
14022 to_intel_crtc_state(crtc->state);
14023 struct intel_crtc_state *new_crtc_state;
14026 * When crtc is inactive or there is a modeset pending,
14027 * wait for it to complete in the slowpath
14029 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
14030 crtc_state->update_pipe)
14033 old_plane_state = plane->state;
14035 * Don't do an async update if there is an outstanding commit modifying
14036 * the plane. This prevents our async update's changes from getting
14037 * overridden by a previous synchronous update's state.
14039 if (old_plane_state->commit &&
14040 !try_wait_for_completion(&old_plane_state->commit->hw_done))
14044 * If any parameters change that may affect watermarks,
14045 * take the slowpath. Only changing fb or position should be
14048 if (old_plane_state->crtc != crtc ||
14049 old_plane_state->src_w != src_w ||
14050 old_plane_state->src_h != src_h ||
14051 old_plane_state->crtc_w != crtc_w ||
14052 old_plane_state->crtc_h != crtc_h ||
14053 !old_plane_state->fb != !fb)
14056 new_plane_state = intel_plane_duplicate_state(plane);
14057 if (!new_plane_state)
14060 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
14061 if (!new_crtc_state) {
14066 drm_atomic_set_fb_for_plane(new_plane_state, fb);
14068 new_plane_state->src_x = src_x;
14069 new_plane_state->src_y = src_y;
14070 new_plane_state->src_w = src_w;
14071 new_plane_state->src_h = src_h;
14072 new_plane_state->crtc_x = crtc_x;
14073 new_plane_state->crtc_y = crtc_y;
14074 new_plane_state->crtc_w = crtc_w;
14075 new_plane_state->crtc_h = crtc_h;
14077 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
14078 to_intel_plane_state(old_plane_state),
14079 to_intel_plane_state(new_plane_state));
14083 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14087 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
14091 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
14093 old_fb = old_plane_state->fb;
14094 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
14095 intel_plane->frontbuffer_bit);
14097 /* Swap plane state */
14098 plane->state = new_plane_state;
14101 * We cannot swap crtc_state as it may be in use by an atomic commit or
14102 * page flip that's running simultaneously. If we swap crtc_state and
14103 * destroy the old state, we will cause a use-after-free there.
14105 * Only update active_planes, which is needed for our internal
14106 * bookkeeping. Either value will do the right thing when updating
14107 * planes atomically. If the cursor was part of the atomic update then
14108 * we would have taken the slowpath.
14110 crtc_state->active_planes = new_crtc_state->active_planes;
14112 if (plane->state->visible) {
14113 trace_intel_update_plane(plane, to_intel_crtc(crtc));
14114 intel_plane->update_plane(intel_plane, crtc_state,
14115 to_intel_plane_state(plane->state));
14117 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
14118 intel_plane->disable_plane(intel_plane, crtc_state);
14121 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
14124 mutex_unlock(&dev_priv->drm.struct_mutex);
14126 if (new_crtc_state)
14127 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
14129 intel_plane_destroy_state(plane, new_plane_state);
14131 intel_plane_destroy_state(plane, old_plane_state);
14135 return drm_atomic_helper_update_plane(plane, crtc, fb,
14136 crtc_x, crtc_y, crtc_w, crtc_h,
14137 src_x, src_y, src_w, src_h, ctx);
14140 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
14141 .update_plane = intel_legacy_cursor_update,
14142 .disable_plane = drm_atomic_helper_disable_plane,
14143 .destroy = intel_plane_destroy,
14144 .atomic_get_property = intel_plane_atomic_get_property,
14145 .atomic_set_property = intel_plane_atomic_set_property,
14146 .atomic_duplicate_state = intel_plane_duplicate_state,
14147 .atomic_destroy_state = intel_plane_destroy_state,
14148 .format_mod_supported = intel_cursor_format_mod_supported,
14151 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
14152 enum i9xx_plane_id i9xx_plane)
14154 if (!HAS_FBC(dev_priv))
14157 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14158 return i9xx_plane == PLANE_A; /* tied to pipe A */
14159 else if (IS_IVYBRIDGE(dev_priv))
14160 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
14161 i9xx_plane == PLANE_C;
14162 else if (INTEL_GEN(dev_priv) >= 4)
14163 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
14165 return i9xx_plane == PLANE_A;
14168 static struct intel_plane *
14169 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
14171 struct intel_plane *plane;
14172 const struct drm_plane_funcs *plane_funcs;
14173 unsigned int supported_rotations;
14174 unsigned int possible_crtcs;
14175 const u64 *modifiers;
14176 const u32 *formats;
14180 if (INTEL_GEN(dev_priv) >= 9)
14181 return skl_universal_plane_create(dev_priv, pipe,
14184 plane = intel_plane_alloc();
14188 plane->pipe = pipe;
14190 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
14191 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
14193 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
14194 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
14196 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
14197 plane->id = PLANE_PRIMARY;
14198 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
14200 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
14201 if (plane->has_fbc) {
14202 struct intel_fbc *fbc = &dev_priv->fbc;
14204 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
14207 if (INTEL_GEN(dev_priv) >= 4) {
14208 formats = i965_primary_formats;
14209 num_formats = ARRAY_SIZE(i965_primary_formats);
14210 modifiers = i9xx_format_modifiers;
14212 plane->max_stride = i9xx_plane_max_stride;
14213 plane->update_plane = i9xx_update_plane;
14214 plane->disable_plane = i9xx_disable_plane;
14215 plane->get_hw_state = i9xx_plane_get_hw_state;
14216 plane->check_plane = i9xx_plane_check;
14218 plane_funcs = &i965_plane_funcs;
14220 formats = i8xx_primary_formats;
14221 num_formats = ARRAY_SIZE(i8xx_primary_formats);
14222 modifiers = i9xx_format_modifiers;
14224 plane->max_stride = i9xx_plane_max_stride;
14225 plane->update_plane = i9xx_update_plane;
14226 plane->disable_plane = i9xx_disable_plane;
14227 plane->get_hw_state = i9xx_plane_get_hw_state;
14228 plane->check_plane = i9xx_plane_check;
14230 plane_funcs = &i8xx_plane_funcs;
14233 possible_crtcs = BIT(pipe);
14235 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
14236 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14237 possible_crtcs, plane_funcs,
14238 formats, num_formats, modifiers,
14239 DRM_PLANE_TYPE_PRIMARY,
14240 "primary %c", pipe_name(pipe));
14242 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14243 possible_crtcs, plane_funcs,
14244 formats, num_formats, modifiers,
14245 DRM_PLANE_TYPE_PRIMARY,
14247 plane_name(plane->i9xx_plane));
14251 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
14252 supported_rotations =
14253 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
14254 DRM_MODE_REFLECT_X;
14255 } else if (INTEL_GEN(dev_priv) >= 4) {
14256 supported_rotations =
14257 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
14259 supported_rotations = DRM_MODE_ROTATE_0;
14262 if (INTEL_GEN(dev_priv) >= 4)
14263 drm_plane_create_rotation_property(&plane->base,
14265 supported_rotations);
14267 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
14272 intel_plane_free(plane);
14274 return ERR_PTR(ret);
14277 static struct intel_plane *
14278 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
14281 unsigned int possible_crtcs;
14282 struct intel_plane *cursor;
14285 cursor = intel_plane_alloc();
14286 if (IS_ERR(cursor))
14289 cursor->pipe = pipe;
14290 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
14291 cursor->id = PLANE_CURSOR;
14292 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
14294 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14295 cursor->max_stride = i845_cursor_max_stride;
14296 cursor->update_plane = i845_update_cursor;
14297 cursor->disable_plane = i845_disable_cursor;
14298 cursor->get_hw_state = i845_cursor_get_hw_state;
14299 cursor->check_plane = i845_check_cursor;
14301 cursor->max_stride = i9xx_cursor_max_stride;
14302 cursor->update_plane = i9xx_update_cursor;
14303 cursor->disable_plane = i9xx_disable_cursor;
14304 cursor->get_hw_state = i9xx_cursor_get_hw_state;
14305 cursor->check_plane = i9xx_check_cursor;
14308 cursor->cursor.base = ~0;
14309 cursor->cursor.cntl = ~0;
14311 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14312 cursor->cursor.size = ~0;
14314 possible_crtcs = BIT(pipe);
14316 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
14317 possible_crtcs, &intel_cursor_plane_funcs,
14318 intel_cursor_formats,
14319 ARRAY_SIZE(intel_cursor_formats),
14320 cursor_format_modifiers,
14321 DRM_PLANE_TYPE_CURSOR,
14322 "cursor %c", pipe_name(pipe));
14326 if (INTEL_GEN(dev_priv) >= 4)
14327 drm_plane_create_rotation_property(&cursor->base,
14329 DRM_MODE_ROTATE_0 |
14330 DRM_MODE_ROTATE_180);
14332 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14337 intel_plane_free(cursor);
14339 return ERR_PTR(ret);
14342 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14343 struct intel_crtc_state *crtc_state)
14345 struct intel_crtc_scaler_state *scaler_state =
14346 &crtc_state->scaler_state;
14347 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14350 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
14351 if (!crtc->num_scalers)
14354 for (i = 0; i < crtc->num_scalers; i++) {
14355 struct intel_scaler *scaler = &scaler_state->scalers[i];
14357 scaler->in_use = 0;
14361 scaler_state->scaler_id = -1;
14364 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
14366 struct intel_crtc *intel_crtc;
14367 struct intel_crtc_state *crtc_state = NULL;
14368 struct intel_plane *primary = NULL;
14369 struct intel_plane *cursor = NULL;
14372 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
14376 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
14381 intel_crtc->config = crtc_state;
14382 intel_crtc->base.state = &crtc_state->base;
14383 crtc_state->base.crtc = &intel_crtc->base;
14385 primary = intel_primary_plane_create(dev_priv, pipe);
14386 if (IS_ERR(primary)) {
14387 ret = PTR_ERR(primary);
14390 intel_crtc->plane_ids_mask |= BIT(primary->id);
14392 for_each_sprite(dev_priv, pipe, sprite) {
14393 struct intel_plane *plane;
14395 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
14396 if (IS_ERR(plane)) {
14397 ret = PTR_ERR(plane);
14400 intel_crtc->plane_ids_mask |= BIT(plane->id);
14403 cursor = intel_cursor_plane_create(dev_priv, pipe);
14404 if (IS_ERR(cursor)) {
14405 ret = PTR_ERR(cursor);
14408 intel_crtc->plane_ids_mask |= BIT(cursor->id);
14410 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
14411 &primary->base, &cursor->base,
14413 "pipe %c", pipe_name(pipe));
14417 intel_crtc->pipe = pipe;
14419 /* initialize shared scalers */
14420 intel_crtc_init_scalers(intel_crtc, crtc_state);
14422 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14423 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14424 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14426 if (INTEL_GEN(dev_priv) < 9) {
14427 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14429 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14430 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14431 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14434 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
14436 intel_color_init(intel_crtc);
14438 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
14444 * drm_mode_config_cleanup() will free up any
14445 * crtcs/planes already initialized.
14453 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14454 struct drm_file *file)
14456 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
14457 struct drm_crtc *drmmode_crtc;
14458 struct intel_crtc *crtc;
14460 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
14464 crtc = to_intel_crtc(drmmode_crtc);
14465 pipe_from_crtc_id->pipe = crtc->pipe;
14470 static int intel_encoder_clones(struct intel_encoder *encoder)
14472 struct drm_device *dev = encoder->base.dev;
14473 struct intel_encoder *source_encoder;
14474 int index_mask = 0;
14477 for_each_intel_encoder(dev, source_encoder) {
14478 if (encoders_cloneable(encoder, source_encoder))
14479 index_mask |= (1 << entry);
14487 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
14489 if (!IS_MOBILE(dev_priv))
14492 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14495 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
14501 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
14503 if (INTEL_GEN(dev_priv) >= 9)
14506 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
14509 if (HAS_PCH_LPT_H(dev_priv) &&
14510 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
14513 /* DDI E can't be used if DDI A requires 4 lanes */
14514 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
14517 if (!dev_priv->vbt.int_crt_support)
14523 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14528 if (HAS_DDI(dev_priv))
14531 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14532 * everywhere where registers can be write protected.
14534 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14539 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14540 u32 val = I915_READ(PP_CONTROL(pps_idx));
14542 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14543 I915_WRITE(PP_CONTROL(pps_idx), val);
14547 static void intel_pps_init(struct drm_i915_private *dev_priv)
14549 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
14550 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14551 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14552 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14554 dev_priv->pps_mmio_base = PPS_BASE;
14556 intel_pps_unlock_regs_wa(dev_priv);
14559 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
14561 struct intel_encoder *encoder;
14562 bool dpd_is_edp = false;
14564 intel_pps_init(dev_priv);
14566 if (!HAS_DISPLAY(dev_priv))
14569 if (IS_ICELAKE(dev_priv)) {
14570 intel_ddi_init(dev_priv, PORT_A);
14571 intel_ddi_init(dev_priv, PORT_B);
14572 intel_ddi_init(dev_priv, PORT_C);
14573 intel_ddi_init(dev_priv, PORT_D);
14574 intel_ddi_init(dev_priv, PORT_E);
14576 * On some ICL SKUs port F is not present. No strap bits for
14577 * this, so rely on VBT.
14578 * Work around broken VBTs on SKUs known to have no port F.
14580 if (IS_ICL_WITH_PORT_F(dev_priv) &&
14581 intel_bios_is_port_present(dev_priv, PORT_F))
14582 intel_ddi_init(dev_priv, PORT_F);
14584 icl_dsi_init(dev_priv);
14585 } else if (IS_GEN9_LP(dev_priv)) {
14587 * FIXME: Broxton doesn't support port detection via the
14588 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14589 * detect the ports.
14591 intel_ddi_init(dev_priv, PORT_A);
14592 intel_ddi_init(dev_priv, PORT_B);
14593 intel_ddi_init(dev_priv, PORT_C);
14595 vlv_dsi_init(dev_priv);
14596 } else if (HAS_DDI(dev_priv)) {
14599 if (intel_ddi_crt_present(dev_priv))
14600 intel_crt_init(dev_priv);
14603 * Haswell uses DDI functions to detect digital outputs.
14604 * On SKL pre-D0 the strap isn't connected, so we assume
14607 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
14608 /* WaIgnoreDDIAStrap: skl */
14609 if (found || IS_GEN9_BC(dev_priv))
14610 intel_ddi_init(dev_priv, PORT_A);
14612 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
14614 found = I915_READ(SFUSE_STRAP);
14616 if (found & SFUSE_STRAP_DDIB_DETECTED)
14617 intel_ddi_init(dev_priv, PORT_B);
14618 if (found & SFUSE_STRAP_DDIC_DETECTED)
14619 intel_ddi_init(dev_priv, PORT_C);
14620 if (found & SFUSE_STRAP_DDID_DETECTED)
14621 intel_ddi_init(dev_priv, PORT_D);
14622 if (found & SFUSE_STRAP_DDIF_DETECTED)
14623 intel_ddi_init(dev_priv, PORT_F);
14625 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14627 if (IS_GEN9_BC(dev_priv) &&
14628 intel_bios_is_port_present(dev_priv, PORT_E))
14629 intel_ddi_init(dev_priv, PORT_E);
14631 } else if (HAS_PCH_SPLIT(dev_priv)) {
14635 * intel_edp_init_connector() depends on this completing first,
14636 * to prevent the registration of both eDP and LVDS and the
14637 * incorrect sharing of the PPS.
14639 intel_lvds_init(dev_priv);
14640 intel_crt_init(dev_priv);
14642 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
14644 if (ilk_has_edp_a(dev_priv))
14645 intel_dp_init(dev_priv, DP_A, PORT_A);
14647 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
14648 /* PCH SDVOB multiplex with HDMIB */
14649 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
14651 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
14652 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
14653 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
14656 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
14657 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
14659 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
14660 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
14662 if (I915_READ(PCH_DP_C) & DP_DETECTED)
14663 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
14665 if (I915_READ(PCH_DP_D) & DP_DETECTED)
14666 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
14667 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
14668 bool has_edp, has_port;
14670 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
14671 intel_crt_init(dev_priv);
14674 * The DP_DETECTED bit is the latched state of the DDC
14675 * SDA pin at boot. However since eDP doesn't require DDC
14676 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14677 * eDP ports may have been muxed to an alternate function.
14678 * Thus we can't rely on the DP_DETECTED bit alone to detect
14679 * eDP ports. Consult the VBT as well as DP_DETECTED to
14680 * detect eDP ports.
14682 * Sadly the straps seem to be missing sometimes even for HDMI
14683 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14684 * and VBT for the presence of the port. Additionally we can't
14685 * trust the port type the VBT declares as we've seen at least
14686 * HDMI ports that the VBT claim are DP or eDP.
14688 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
14689 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14690 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
14691 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
14692 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
14693 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
14695 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
14696 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14697 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
14698 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
14699 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
14700 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
14702 if (IS_CHERRYVIEW(dev_priv)) {
14704 * eDP not supported on port D,
14705 * so no need to worry about it
14707 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14708 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
14709 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
14710 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
14711 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
14714 vlv_dsi_init(dev_priv);
14715 } else if (IS_PINEVIEW(dev_priv)) {
14716 intel_lvds_init(dev_priv);
14717 intel_crt_init(dev_priv);
14718 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
14719 bool found = false;
14721 if (IS_MOBILE(dev_priv))
14722 intel_lvds_init(dev_priv);
14724 intel_crt_init(dev_priv);
14726 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14727 DRM_DEBUG_KMS("probing SDVOB\n");
14728 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
14729 if (!found && IS_G4X(dev_priv)) {
14730 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14731 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
14734 if (!found && IS_G4X(dev_priv))
14735 intel_dp_init(dev_priv, DP_B, PORT_B);
14738 /* Before G4X SDVOC doesn't have its own detect register */
14740 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14741 DRM_DEBUG_KMS("probing SDVOC\n");
14742 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
14745 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14747 if (IS_G4X(dev_priv)) {
14748 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14749 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
14751 if (IS_G4X(dev_priv))
14752 intel_dp_init(dev_priv, DP_C, PORT_C);
14755 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
14756 intel_dp_init(dev_priv, DP_D, PORT_D);
14758 if (SUPPORTS_TV(dev_priv))
14759 intel_tv_init(dev_priv);
14760 } else if (IS_GEN(dev_priv, 2)) {
14761 if (IS_I85X(dev_priv))
14762 intel_lvds_init(dev_priv);
14764 intel_crt_init(dev_priv);
14765 intel_dvo_init(dev_priv);
14768 intel_psr_init(dev_priv);
14770 for_each_intel_encoder(&dev_priv->drm, encoder) {
14771 encoder->base.possible_crtcs = encoder->crtc_mask;
14772 encoder->base.possible_clones =
14773 intel_encoder_clones(encoder);
14776 intel_init_pch_refclk(dev_priv);
14778 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14781 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14783 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14784 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14786 drm_framebuffer_cleanup(fb);
14788 i915_gem_object_lock(obj);
14789 WARN_ON(!obj->framebuffer_references--);
14790 i915_gem_object_unlock(obj);
14792 i915_gem_object_put(obj);
14797 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14798 struct drm_file *file,
14799 unsigned int *handle)
14801 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14803 if (obj->userptr.mm) {
14804 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14808 return drm_gem_handle_create(file, &obj->base, handle);
14811 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14812 struct drm_file *file,
14813 unsigned flags, unsigned color,
14814 struct drm_clip_rect *clips,
14815 unsigned num_clips)
14817 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14819 i915_gem_object_flush_if_display(obj);
14820 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14825 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14826 .destroy = intel_user_framebuffer_destroy,
14827 .create_handle = intel_user_framebuffer_create_handle,
14828 .dirty = intel_user_framebuffer_dirty,
14832 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14833 u32 pixel_format, u64 fb_modifier)
14835 struct intel_crtc *crtc;
14836 struct intel_plane *plane;
14839 * We assume the primary plane for pipe A has
14840 * the highest stride limits of them all.
14842 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14843 plane = to_intel_plane(crtc->base.primary);
14845 return plane->max_stride(plane, pixel_format, fb_modifier,
14846 DRM_MODE_ROTATE_0);
14849 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14850 struct drm_i915_gem_object *obj,
14851 struct drm_mode_fb_cmd2 *mode_cmd)
14853 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14854 struct drm_framebuffer *fb = &intel_fb->base;
14856 unsigned int tiling, stride;
14860 i915_gem_object_lock(obj);
14861 obj->framebuffer_references++;
14862 tiling = i915_gem_object_get_tiling(obj);
14863 stride = i915_gem_object_get_stride(obj);
14864 i915_gem_object_unlock(obj);
14866 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14868 * If there's a fence, enforce that
14869 * the fb modifier and tiling mode match.
14871 if (tiling != I915_TILING_NONE &&
14872 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14873 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14877 if (tiling == I915_TILING_X) {
14878 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14879 } else if (tiling == I915_TILING_Y) {
14880 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14885 if (!drm_any_plane_has_format(&dev_priv->drm,
14886 mode_cmd->pixel_format,
14887 mode_cmd->modifier[0])) {
14888 struct drm_format_name_buf format_name;
14890 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
14891 drm_get_format_name(mode_cmd->pixel_format,
14893 mode_cmd->modifier[0]);
14898 * gen2/3 display engine uses the fence if present,
14899 * so the tiling mode must match the fb modifier exactly.
14901 if (INTEL_GEN(dev_priv) < 4 &&
14902 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14903 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14907 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format,
14908 mode_cmd->modifier[0]);
14909 if (mode_cmd->pitches[0] > pitch_limit) {
14910 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14911 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14912 "tiled" : "linear",
14913 mode_cmd->pitches[0], pitch_limit);
14918 * If there's a fence, enforce that
14919 * the fb pitch and fence stride match.
14921 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14922 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14923 mode_cmd->pitches[0], stride);
14927 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14928 if (mode_cmd->offsets[0] != 0)
14931 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14933 for (i = 0; i < fb->format->num_planes; i++) {
14934 u32 stride_alignment;
14936 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14937 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14941 stride_alignment = intel_fb_stride_alignment(fb, i);
14944 * Display WA #0531: skl,bxt,kbl,glk
14946 * Render decompression and plane width > 3840
14947 * combined with horizontal panning requires the
14948 * plane stride to be a multiple of 4. We'll just
14949 * require the entire fb to accommodate that to avoid
14950 * potential runtime errors at plane configuration time.
14952 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
14953 is_ccs_modifier(fb->modifier))
14954 stride_alignment *= 4;
14956 if (fb->pitches[i] & (stride_alignment - 1)) {
14957 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14958 i, fb->pitches[i], stride_alignment);
14962 fb->obj[i] = &obj->base;
14965 ret = intel_fill_fb_info(dev_priv, fb);
14969 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14971 DRM_ERROR("framebuffer init failed %d\n", ret);
14978 i915_gem_object_lock(obj);
14979 obj->framebuffer_references--;
14980 i915_gem_object_unlock(obj);
14984 static struct drm_framebuffer *
14985 intel_user_framebuffer_create(struct drm_device *dev,
14986 struct drm_file *filp,
14987 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14989 struct drm_framebuffer *fb;
14990 struct drm_i915_gem_object *obj;
14991 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14993 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14995 return ERR_PTR(-ENOENT);
14997 fb = intel_framebuffer_create(obj, &mode_cmd);
14999 i915_gem_object_put(obj);
15004 static void intel_atomic_state_free(struct drm_atomic_state *state)
15006 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
15008 drm_atomic_state_default_release(state);
15010 i915_sw_fence_fini(&intel_state->commit_ready);
15015 static enum drm_mode_status
15016 intel_mode_valid(struct drm_device *dev,
15017 const struct drm_display_mode *mode)
15019 struct drm_i915_private *dev_priv = to_i915(dev);
15020 int hdisplay_max, htotal_max;
15021 int vdisplay_max, vtotal_max;
15024 * Can't reject DBLSCAN here because Xorg ddxen can add piles
15025 * of DBLSCAN modes to the output's mode list when they detect
15026 * the scaling mode property on the connector. And they don't
15027 * ask the kernel to validate those modes in any way until
15028 * modeset time at which point the client gets a protocol error.
15029 * So in order to not upset those clients we silently ignore the
15030 * DBLSCAN flag on such connectors. For other connectors we will
15031 * reject modes with the DBLSCAN flag in encoder->compute_config().
15032 * And we always reject DBLSCAN modes in connector->mode_valid()
15033 * as we never want such modes on the connector's mode list.
15036 if (mode->vscan > 1)
15037 return MODE_NO_VSCAN;
15039 if (mode->flags & DRM_MODE_FLAG_HSKEW)
15040 return MODE_H_ILLEGAL;
15042 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
15043 DRM_MODE_FLAG_NCSYNC |
15044 DRM_MODE_FLAG_PCSYNC))
15047 if (mode->flags & (DRM_MODE_FLAG_BCAST |
15048 DRM_MODE_FLAG_PIXMUX |
15049 DRM_MODE_FLAG_CLKDIV2))
15052 if (INTEL_GEN(dev_priv) >= 9 ||
15053 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
15054 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
15055 vdisplay_max = 4096;
15058 } else if (INTEL_GEN(dev_priv) >= 3) {
15059 hdisplay_max = 4096;
15060 vdisplay_max = 4096;
15064 hdisplay_max = 2048;
15065 vdisplay_max = 2048;
15070 if (mode->hdisplay > hdisplay_max ||
15071 mode->hsync_start > htotal_max ||
15072 mode->hsync_end > htotal_max ||
15073 mode->htotal > htotal_max)
15074 return MODE_H_ILLEGAL;
15076 if (mode->vdisplay > vdisplay_max ||
15077 mode->vsync_start > vtotal_max ||
15078 mode->vsync_end > vtotal_max ||
15079 mode->vtotal > vtotal_max)
15080 return MODE_V_ILLEGAL;
15085 static const struct drm_mode_config_funcs intel_mode_funcs = {
15086 .fb_create = intel_user_framebuffer_create,
15087 .get_format_info = intel_get_format_info,
15088 .output_poll_changed = intel_fbdev_output_poll_changed,
15089 .mode_valid = intel_mode_valid,
15090 .atomic_check = intel_atomic_check,
15091 .atomic_commit = intel_atomic_commit,
15092 .atomic_state_alloc = intel_atomic_state_alloc,
15093 .atomic_state_clear = intel_atomic_state_clear,
15094 .atomic_state_free = intel_atomic_state_free,
15098 * intel_init_display_hooks - initialize the display modesetting hooks
15099 * @dev_priv: device private
15101 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
15103 intel_init_cdclk_hooks(dev_priv);
15105 if (INTEL_GEN(dev_priv) >= 9) {
15106 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15107 dev_priv->display.get_initial_plane_config =
15108 skylake_get_initial_plane_config;
15109 dev_priv->display.crtc_compute_clock =
15110 haswell_crtc_compute_clock;
15111 dev_priv->display.crtc_enable = haswell_crtc_enable;
15112 dev_priv->display.crtc_disable = haswell_crtc_disable;
15113 } else if (HAS_DDI(dev_priv)) {
15114 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15115 dev_priv->display.get_initial_plane_config =
15116 i9xx_get_initial_plane_config;
15117 dev_priv->display.crtc_compute_clock =
15118 haswell_crtc_compute_clock;
15119 dev_priv->display.crtc_enable = haswell_crtc_enable;
15120 dev_priv->display.crtc_disable = haswell_crtc_disable;
15121 } else if (HAS_PCH_SPLIT(dev_priv)) {
15122 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
15123 dev_priv->display.get_initial_plane_config =
15124 i9xx_get_initial_plane_config;
15125 dev_priv->display.crtc_compute_clock =
15126 ironlake_crtc_compute_clock;
15127 dev_priv->display.crtc_enable = ironlake_crtc_enable;
15128 dev_priv->display.crtc_disable = ironlake_crtc_disable;
15129 } else if (IS_CHERRYVIEW(dev_priv)) {
15130 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15131 dev_priv->display.get_initial_plane_config =
15132 i9xx_get_initial_plane_config;
15133 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
15134 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15135 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15136 } else if (IS_VALLEYVIEW(dev_priv)) {
15137 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15138 dev_priv->display.get_initial_plane_config =
15139 i9xx_get_initial_plane_config;
15140 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
15141 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15142 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15143 } else if (IS_G4X(dev_priv)) {
15144 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15145 dev_priv->display.get_initial_plane_config =
15146 i9xx_get_initial_plane_config;
15147 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
15148 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15149 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15150 } else if (IS_PINEVIEW(dev_priv)) {
15151 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15152 dev_priv->display.get_initial_plane_config =
15153 i9xx_get_initial_plane_config;
15154 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
15155 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15156 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15157 } else if (!IS_GEN(dev_priv, 2)) {
15158 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15159 dev_priv->display.get_initial_plane_config =
15160 i9xx_get_initial_plane_config;
15161 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
15162 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15163 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15165 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15166 dev_priv->display.get_initial_plane_config =
15167 i9xx_get_initial_plane_config;
15168 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
15169 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15170 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15173 if (IS_GEN(dev_priv, 5)) {
15174 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
15175 } else if (IS_GEN(dev_priv, 6)) {
15176 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
15177 } else if (IS_IVYBRIDGE(dev_priv)) {
15178 /* FIXME: detect B0+ stepping and use auto training */
15179 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
15180 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
15181 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
15184 if (INTEL_GEN(dev_priv) >= 9)
15185 dev_priv->display.update_crtcs = skl_update_crtcs;
15187 dev_priv->display.update_crtcs = intel_update_crtcs;
15190 /* Disable the VGA plane that we never use */
15191 static void i915_disable_vga(struct drm_i915_private *dev_priv)
15193 struct pci_dev *pdev = dev_priv->drm.pdev;
15195 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15197 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15198 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
15199 outb(SR01, VGA_SR_INDEX);
15200 sr1 = inb(VGA_SR_DATA);
15201 outb(sr1 | 1<<5, VGA_SR_DATA);
15202 vga_put(pdev, VGA_RSRC_LEGACY_IO);
15205 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
15206 POSTING_READ(vga_reg);
15209 void intel_modeset_init_hw(struct drm_device *dev)
15211 struct drm_i915_private *dev_priv = to_i915(dev);
15213 intel_update_cdclk(dev_priv);
15214 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
15215 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
15219 * Calculate what we think the watermarks should be for the state we've read
15220 * out of the hardware and then immediately program those watermarks so that
15221 * we ensure the hardware settings match our internal state.
15223 * We can calculate what we think WM's should be by creating a duplicate of the
15224 * current state (which was constructed during hardware readout) and running it
15225 * through the atomic check code to calculate new watermark values in the
15228 static void sanitize_watermarks(struct drm_device *dev)
15230 struct drm_i915_private *dev_priv = to_i915(dev);
15231 struct drm_atomic_state *state;
15232 struct intel_atomic_state *intel_state;
15233 struct drm_crtc *crtc;
15234 struct drm_crtc_state *cstate;
15235 struct drm_modeset_acquire_ctx ctx;
15239 /* Only supported on platforms that use atomic watermark design */
15240 if (!dev_priv->display.optimize_watermarks)
15244 * We need to hold connection_mutex before calling duplicate_state so
15245 * that the connector loop is protected.
15247 drm_modeset_acquire_init(&ctx, 0);
15249 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15250 if (ret == -EDEADLK) {
15251 drm_modeset_backoff(&ctx);
15253 } else if (WARN_ON(ret)) {
15257 state = drm_atomic_helper_duplicate_state(dev, &ctx);
15258 if (WARN_ON(IS_ERR(state)))
15261 intel_state = to_intel_atomic_state(state);
15264 * Hardware readout is the only time we don't want to calculate
15265 * intermediate watermarks (since we don't trust the current
15268 if (!HAS_GMCH(dev_priv))
15269 intel_state->skip_intermediate_wm = true;
15271 ret = intel_atomic_check(dev, state);
15274 * If we fail here, it means that the hardware appears to be
15275 * programmed in a way that shouldn't be possible, given our
15276 * understanding of watermark requirements. This might mean a
15277 * mistake in the hardware readout code or a mistake in the
15278 * watermark calculations for a given platform. Raise a WARN
15279 * so that this is noticeable.
15281 * If this actually happens, we'll have to just leave the
15282 * BIOS-programmed watermarks untouched and hope for the best.
15284 WARN(true, "Could not determine valid watermarks for inherited state\n");
15288 /* Write calculated watermark values back */
15289 for_each_new_crtc_in_state(state, crtc, cstate, i) {
15290 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
15292 cs->wm.need_postvbl_update = true;
15293 dev_priv->display.optimize_watermarks(intel_state, cs);
15295 to_intel_crtc_state(crtc->state)->wm = cs->wm;
15299 drm_atomic_state_put(state);
15301 drm_modeset_drop_locks(&ctx);
15302 drm_modeset_acquire_fini(&ctx);
15305 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
15307 if (IS_GEN(dev_priv, 5)) {
15309 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
15311 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
15312 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
15313 dev_priv->fdi_pll_freq = 270000;
15318 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
15321 static int intel_initial_commit(struct drm_device *dev)
15323 struct drm_atomic_state *state = NULL;
15324 struct drm_modeset_acquire_ctx ctx;
15325 struct drm_crtc *crtc;
15326 struct drm_crtc_state *crtc_state;
15329 state = drm_atomic_state_alloc(dev);
15333 drm_modeset_acquire_init(&ctx, 0);
15336 state->acquire_ctx = &ctx;
15338 drm_for_each_crtc(crtc, dev) {
15339 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15340 if (IS_ERR(crtc_state)) {
15341 ret = PTR_ERR(crtc_state);
15345 if (crtc_state->active) {
15346 ret = drm_atomic_add_affected_planes(state, crtc);
15351 * FIXME hack to force a LUT update to avoid the
15352 * plane update forcing the pipe gamma on without
15353 * having a proper LUT loaded. Remove once we
15354 * have readout for pipe gamma enable.
15356 crtc_state->color_mgmt_changed = true;
15360 ret = drm_atomic_commit(state);
15363 if (ret == -EDEADLK) {
15364 drm_atomic_state_clear(state);
15365 drm_modeset_backoff(&ctx);
15369 drm_atomic_state_put(state);
15371 drm_modeset_drop_locks(&ctx);
15372 drm_modeset_acquire_fini(&ctx);
15377 int intel_modeset_init(struct drm_device *dev)
15379 struct drm_i915_private *dev_priv = to_i915(dev);
15380 struct i915_ggtt *ggtt = &dev_priv->ggtt;
15382 struct intel_crtc *crtc;
15385 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15387 drm_mode_config_init(dev);
15389 dev->mode_config.min_width = 0;
15390 dev->mode_config.min_height = 0;
15392 dev->mode_config.preferred_depth = 24;
15393 dev->mode_config.prefer_shadow = 1;
15395 dev->mode_config.allow_fb_modifiers = true;
15397 dev->mode_config.funcs = &intel_mode_funcs;
15399 init_llist_head(&dev_priv->atomic_helper.free_list);
15400 INIT_WORK(&dev_priv->atomic_helper.free_work,
15401 intel_atomic_helper_free_state_worker);
15403 intel_init_quirks(dev_priv);
15405 intel_fbc_init(dev_priv);
15407 intel_init_pm(dev_priv);
15410 * There may be no VBT; and if the BIOS enabled SSC we can
15411 * just keep using it to avoid unnecessary flicker. Whereas if the
15412 * BIOS isn't using it, don't assume it will work even if the VBT
15413 * indicates as much.
15415 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
15416 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15419 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15420 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15421 bios_lvds_use_ssc ? "en" : "dis",
15422 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15423 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15427 /* maximum framebuffer dimensions */
15428 if (IS_GEN(dev_priv, 2)) {
15429 dev->mode_config.max_width = 2048;
15430 dev->mode_config.max_height = 2048;
15431 } else if (IS_GEN(dev_priv, 3)) {
15432 dev->mode_config.max_width = 4096;
15433 dev->mode_config.max_height = 4096;
15435 dev->mode_config.max_width = 8192;
15436 dev->mode_config.max_height = 8192;
15439 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15440 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
15441 dev->mode_config.cursor_height = 1023;
15442 } else if (IS_GEN(dev_priv, 2)) {
15443 dev->mode_config.cursor_width = 64;
15444 dev->mode_config.cursor_height = 64;
15446 dev->mode_config.cursor_width = 256;
15447 dev->mode_config.cursor_height = 256;
15450 dev->mode_config.fb_base = ggtt->gmadr.start;
15452 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15453 INTEL_INFO(dev_priv)->num_pipes,
15454 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
15456 for_each_pipe(dev_priv, pipe) {
15457 ret = intel_crtc_init(dev_priv, pipe);
15459 drm_mode_config_cleanup(dev);
15464 intel_shared_dpll_init(dev);
15465 intel_update_fdi_pll_freq(dev_priv);
15467 intel_update_czclk(dev_priv);
15468 intel_modeset_init_hw(dev);
15470 if (dev_priv->max_cdclk_freq == 0)
15471 intel_update_max_cdclk(dev_priv);
15473 /* Just disable it once at startup */
15474 i915_disable_vga(dev_priv);
15475 intel_setup_outputs(dev_priv);
15477 drm_modeset_lock_all(dev);
15478 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
15479 drm_modeset_unlock_all(dev);
15481 for_each_intel_crtc(dev, crtc) {
15482 struct intel_initial_plane_config plane_config = {};
15488 * Note that reserving the BIOS fb up front prevents us
15489 * from stuffing other stolen allocations like the ring
15490 * on top. This prevents some ugliness at boot time, and
15491 * can even allow for smooth boot transitions if the BIOS
15492 * fb is large enough for the active pipe configuration.
15494 dev_priv->display.get_initial_plane_config(crtc,
15498 * If the fb is shared between multiple heads, we'll
15499 * just get the first one.
15501 intel_find_initial_plane_obj(crtc, &plane_config);
15505 * Make sure hardware watermarks really match the state we read out.
15506 * Note that we need to do this after reconstructing the BIOS fb's
15507 * since the watermark calculation done here will use pstate->fb.
15509 if (!HAS_GMCH(dev_priv))
15510 sanitize_watermarks(dev);
15513 * Force all active planes to recompute their states. So that on
15514 * mode_setcrtc after probe, all the intel_plane_state variables
15515 * are already calculated and there is no assert_plane warnings
15518 ret = intel_initial_commit(dev);
15520 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15525 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15527 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15528 /* 640x480@60Hz, ~25175 kHz */
15529 struct dpll clock = {
15539 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15541 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15542 pipe_name(pipe), clock.vco, clock.dot);
15544 fp = i9xx_dpll_compute_fp(&clock);
15545 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15546 DPLL_VGA_MODE_DIS |
15547 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15548 PLL_P2_DIVIDE_BY_4 |
15549 PLL_REF_INPUT_DREFCLK |
15552 I915_WRITE(FP0(pipe), fp);
15553 I915_WRITE(FP1(pipe), fp);
15555 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15556 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15557 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15558 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15559 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15560 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15561 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15564 * Apparently we need to have VGA mode enabled prior to changing
15565 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15566 * dividers, even though the register value does change.
15568 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15569 I915_WRITE(DPLL(pipe), dpll);
15571 /* Wait for the clocks to stabilize. */
15572 POSTING_READ(DPLL(pipe));
15575 /* The pixel multiplier can only be updated once the
15576 * DPLL is enabled and the clocks are stable.
15578 * So write it again.
15580 I915_WRITE(DPLL(pipe), dpll);
15582 /* We do this three times for luck */
15583 for (i = 0; i < 3 ; i++) {
15584 I915_WRITE(DPLL(pipe), dpll);
15585 POSTING_READ(DPLL(pipe));
15586 udelay(150); /* wait for warmup */
15589 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15590 POSTING_READ(PIPECONF(pipe));
15592 intel_wait_for_pipe_scanline_moving(crtc);
15595 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15597 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15599 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15602 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15603 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15604 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
15605 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15606 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
15608 I915_WRITE(PIPECONF(pipe), 0);
15609 POSTING_READ(PIPECONF(pipe));
15611 intel_wait_for_pipe_scanline_stopped(crtc);
15613 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15614 POSTING_READ(DPLL(pipe));
15618 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15620 struct intel_crtc *crtc;
15622 if (INTEL_GEN(dev_priv) >= 4)
15625 for_each_intel_crtc(&dev_priv->drm, crtc) {
15626 struct intel_plane *plane =
15627 to_intel_plane(crtc->base.primary);
15628 struct intel_crtc *plane_crtc;
15631 if (!plane->get_hw_state(plane, &pipe))
15634 if (pipe == crtc->pipe)
15637 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15638 plane->base.base.id, plane->base.name);
15640 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15641 intel_plane_disable_noatomic(plane_crtc, plane);
15645 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15647 struct drm_device *dev = crtc->base.dev;
15648 struct intel_encoder *encoder;
15650 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15656 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15658 struct drm_device *dev = encoder->base.dev;
15659 struct intel_connector *connector;
15661 for_each_connector_on_encoder(dev, &encoder->base, connector)
15667 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15668 enum pipe pch_transcoder)
15670 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15671 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15674 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15675 struct drm_modeset_acquire_ctx *ctx)
15677 struct drm_device *dev = crtc->base.dev;
15678 struct drm_i915_private *dev_priv = to_i915(dev);
15679 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15680 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
15682 /* Clear any frame start delays used for debugging left by the BIOS */
15683 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
15684 i915_reg_t reg = PIPECONF(cpu_transcoder);
15687 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15690 if (crtc_state->base.active) {
15691 struct intel_plane *plane;
15693 /* Disable everything but the primary plane */
15694 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15695 const struct intel_plane_state *plane_state =
15696 to_intel_plane_state(plane->base.state);
15698 if (plane_state->base.visible &&
15699 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15700 intel_plane_disable_noatomic(crtc, plane);
15704 * Disable any background color set by the BIOS, but enable the
15705 * gamma and CSC to match how we program our planes.
15707 if (INTEL_GEN(dev_priv) >= 9)
15708 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
15709 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
15710 SKL_BOTTOM_COLOR_CSC_ENABLE);
15713 /* Adjust the state of the output pipe according to whether we
15714 * have active connectors/encoders. */
15715 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
15716 intel_crtc_disable_noatomic(&crtc->base, ctx);
15718 if (crtc_state->base.active || HAS_GMCH(dev_priv)) {
15720 * We start out with underrun reporting disabled to avoid races.
15721 * For correct bookkeeping mark this on active crtcs.
15723 * Also on gmch platforms we dont have any hardware bits to
15724 * disable the underrun reporting. Which means we need to start
15725 * out with underrun reporting disabled also on inactive pipes,
15726 * since otherwise we'll complain about the garbage we read when
15727 * e.g. coming up after runtime pm.
15729 * No protection against concurrent access is required - at
15730 * worst a fifo underrun happens which also sets this to false.
15732 crtc->cpu_fifo_underrun_disabled = true;
15734 * We track the PCH trancoder underrun reporting state
15735 * within the crtc. With crtc for pipe A housing the underrun
15736 * reporting state for PCH transcoder A, crtc for pipe B housing
15737 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15738 * and marking underrun reporting as disabled for the non-existing
15739 * PCH transcoders B and C would prevent enabling the south
15740 * error interrupt (see cpt_can_enable_serr_int()).
15742 if (has_pch_trancoder(dev_priv, crtc->pipe))
15743 crtc->pch_fifo_underrun_disabled = true;
15747 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
15749 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
15752 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
15753 * the hardware when a high res displays plugged in. DPLL P
15754 * divider is zero, and the pipe timings are bonkers. We'll
15755 * try to disable everything in that case.
15757 * FIXME would be nice to be able to sanitize this state
15758 * without several WARNs, but for now let's take the easy
15761 return IS_GEN(dev_priv, 6) &&
15762 crtc_state->base.active &&
15763 crtc_state->shared_dpll &&
15764 crtc_state->port_clock == 0;
15767 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15769 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
15770 struct intel_connector *connector;
15771 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
15772 struct intel_crtc_state *crtc_state = crtc ?
15773 to_intel_crtc_state(crtc->base.state) : NULL;
15775 /* We need to check both for a crtc link (meaning that the
15776 * encoder is active and trying to read from a pipe) and the
15777 * pipe itself being active. */
15778 bool has_active_crtc = crtc_state &&
15779 crtc_state->base.active;
15781 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
15782 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
15783 pipe_name(crtc->pipe));
15784 has_active_crtc = false;
15787 connector = intel_encoder_find_connector(encoder);
15788 if (connector && !has_active_crtc) {
15789 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15790 encoder->base.base.id,
15791 encoder->base.name);
15793 /* Connector is active, but has no active pipe. This is
15794 * fallout from our resume register restoring. Disable
15795 * the encoder manually again. */
15797 struct drm_encoder *best_encoder;
15799 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15800 encoder->base.base.id,
15801 encoder->base.name);
15803 /* avoid oopsing in case the hooks consult best_encoder */
15804 best_encoder = connector->base.state->best_encoder;
15805 connector->base.state->best_encoder = &encoder->base;
15807 if (encoder->disable)
15808 encoder->disable(encoder, crtc_state,
15809 connector->base.state);
15810 if (encoder->post_disable)
15811 encoder->post_disable(encoder, crtc_state,
15812 connector->base.state);
15814 connector->base.state->best_encoder = best_encoder;
15816 encoder->base.crtc = NULL;
15818 /* Inconsistent output/port/pipe state happens presumably due to
15819 * a bug in one of the get_hw_state functions. Or someplace else
15820 * in our code, like the register restore mess on resume. Clamp
15821 * things to off as a safer default. */
15823 connector->base.dpms = DRM_MODE_DPMS_OFF;
15824 connector->base.encoder = NULL;
15827 /* notify opregion of the sanitized encoder state */
15828 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
15830 if (INTEL_GEN(dev_priv) >= 11)
15831 icl_sanitize_encoder_pll_mapping(encoder);
15834 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15836 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15838 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15839 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15840 i915_disable_vga(dev_priv);
15844 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15846 intel_wakeref_t wakeref;
15849 * This function can be called both from intel_modeset_setup_hw_state or
15850 * at a very early point in our resume sequence, where the power well
15851 * structures are not yet restored. Since this function is at a very
15852 * paranoid "someone might have enabled VGA while we were not looking"
15853 * level, just check if the power well is enabled instead of trying to
15854 * follow the "don't touch the power well if we don't need it" policy
15855 * the rest of the driver uses.
15857 wakeref = intel_display_power_get_if_enabled(dev_priv,
15862 i915_redisable_vga_power_on(dev_priv);
15864 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref);
15867 /* FIXME read out full plane state for all planes */
15868 static void readout_plane_state(struct drm_i915_private *dev_priv)
15870 struct intel_plane *plane;
15871 struct intel_crtc *crtc;
15873 for_each_intel_plane(&dev_priv->drm, plane) {
15874 struct intel_plane_state *plane_state =
15875 to_intel_plane_state(plane->base.state);
15876 struct intel_crtc_state *crtc_state;
15877 enum pipe pipe = PIPE_A;
15880 visible = plane->get_hw_state(plane, &pipe);
15882 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15883 crtc_state = to_intel_crtc_state(crtc->base.state);
15885 intel_set_plane_visible(crtc_state, plane_state, visible);
15887 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15888 plane->base.base.id, plane->base.name,
15889 enableddisabled(visible), pipe_name(pipe));
15892 for_each_intel_crtc(&dev_priv->drm, crtc) {
15893 struct intel_crtc_state *crtc_state =
15894 to_intel_crtc_state(crtc->base.state);
15896 fixup_active_planes(crtc_state);
15900 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15902 struct drm_i915_private *dev_priv = to_i915(dev);
15904 struct intel_crtc *crtc;
15905 struct intel_encoder *encoder;
15906 struct intel_connector *connector;
15907 struct drm_connector_list_iter conn_iter;
15910 dev_priv->active_crtcs = 0;
15912 for_each_intel_crtc(dev, crtc) {
15913 struct intel_crtc_state *crtc_state =
15914 to_intel_crtc_state(crtc->base.state);
15916 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15917 memset(crtc_state, 0, sizeof(*crtc_state));
15918 crtc_state->base.crtc = &crtc->base;
15920 crtc_state->base.active = crtc_state->base.enable =
15921 dev_priv->display.get_pipe_config(crtc, crtc_state);
15923 crtc->base.enabled = crtc_state->base.enable;
15924 crtc->active = crtc_state->base.active;
15926 if (crtc_state->base.active)
15927 dev_priv->active_crtcs |= 1 << crtc->pipe;
15929 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15930 crtc->base.base.id, crtc->base.name,
15931 enableddisabled(crtc_state->base.active));
15934 readout_plane_state(dev_priv);
15936 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15937 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15939 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15940 &pll->state.hw_state);
15941 pll->state.crtc_mask = 0;
15942 for_each_intel_crtc(dev, crtc) {
15943 struct intel_crtc_state *crtc_state =
15944 to_intel_crtc_state(crtc->base.state);
15946 if (crtc_state->base.active &&
15947 crtc_state->shared_dpll == pll)
15948 pll->state.crtc_mask |= 1 << crtc->pipe;
15950 pll->active_mask = pll->state.crtc_mask;
15952 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15953 pll->info->name, pll->state.crtc_mask, pll->on);
15956 for_each_intel_encoder(dev, encoder) {
15959 if (encoder->get_hw_state(encoder, &pipe)) {
15960 struct intel_crtc_state *crtc_state;
15962 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15963 crtc_state = to_intel_crtc_state(crtc->base.state);
15965 encoder->base.crtc = &crtc->base;
15966 encoder->get_config(encoder, crtc_state);
15968 encoder->base.crtc = NULL;
15971 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15972 encoder->base.base.id, encoder->base.name,
15973 enableddisabled(encoder->base.crtc),
15977 drm_connector_list_iter_begin(dev, &conn_iter);
15978 for_each_intel_connector_iter(connector, &conn_iter) {
15979 if (connector->get_hw_state(connector)) {
15980 connector->base.dpms = DRM_MODE_DPMS_ON;
15982 encoder = connector->encoder;
15983 connector->base.encoder = &encoder->base;
15985 if (encoder->base.crtc &&
15986 encoder->base.crtc->state->active) {
15988 * This has to be done during hardware readout
15989 * because anything calling .crtc_disable may
15990 * rely on the connector_mask being accurate.
15992 encoder->base.crtc->state->connector_mask |=
15993 drm_connector_mask(&connector->base);
15994 encoder->base.crtc->state->encoder_mask |=
15995 drm_encoder_mask(&encoder->base);
15999 connector->base.dpms = DRM_MODE_DPMS_OFF;
16000 connector->base.encoder = NULL;
16002 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
16003 connector->base.base.id, connector->base.name,
16004 enableddisabled(connector->base.encoder));
16006 drm_connector_list_iter_end(&conn_iter);
16008 for_each_intel_crtc(dev, crtc) {
16009 struct intel_crtc_state *crtc_state =
16010 to_intel_crtc_state(crtc->base.state);
16013 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
16014 if (crtc_state->base.active) {
16015 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
16016 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
16017 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
16018 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
16019 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
16022 * The initial mode needs to be set in order to keep
16023 * the atomic core happy. It wants a valid mode if the
16024 * crtc's enabled, so we do the above call.
16026 * But we don't set all the derived state fully, hence
16027 * set a flag to indicate that a full recalculation is
16028 * needed on the next commit.
16030 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
16032 intel_crtc_compute_pixel_rate(crtc_state);
16034 if (dev_priv->display.modeset_calc_cdclk) {
16035 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
16036 if (WARN_ON(min_cdclk < 0))
16040 drm_calc_timestamping_constants(&crtc->base,
16041 &crtc_state->base.adjusted_mode);
16042 update_scanline_offset(crtc_state);
16045 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
16046 dev_priv->min_voltage_level[crtc->pipe] =
16047 crtc_state->min_voltage_level;
16049 intel_pipe_config_sanity_check(dev_priv, crtc_state);
16054 get_encoder_power_domains(struct drm_i915_private *dev_priv)
16056 struct intel_encoder *encoder;
16058 for_each_intel_encoder(&dev_priv->drm, encoder) {
16060 enum intel_display_power_domain domain;
16061 struct intel_crtc_state *crtc_state;
16063 if (!encoder->get_power_domains)
16067 * MST-primary and inactive encoders don't have a crtc state
16068 * and neither of these require any power domain references.
16070 if (!encoder->base.crtc)
16073 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
16074 get_domains = encoder->get_power_domains(encoder, crtc_state);
16075 for_each_power_domain(domain, get_domains)
16076 intel_display_power_get(dev_priv, domain);
16080 static void intel_early_display_was(struct drm_i915_private *dev_priv)
16082 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
16083 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
16084 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
16087 if (IS_HASWELL(dev_priv)) {
16089 * WaRsPkgCStateDisplayPMReq:hsw
16090 * System hang if this isn't done before disabling all planes!
16092 I915_WRITE(CHICKEN_PAR1_1,
16093 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
16097 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
16098 enum port port, i915_reg_t hdmi_reg)
16100 u32 val = I915_READ(hdmi_reg);
16102 if (val & SDVO_ENABLE ||
16103 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
16106 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
16109 val &= ~SDVO_PIPE_SEL_MASK;
16110 val |= SDVO_PIPE_SEL(PIPE_A);
16112 I915_WRITE(hdmi_reg, val);
16115 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
16116 enum port port, i915_reg_t dp_reg)
16118 u32 val = I915_READ(dp_reg);
16120 if (val & DP_PORT_EN ||
16121 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
16124 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
16127 val &= ~DP_PIPE_SEL_MASK;
16128 val |= DP_PIPE_SEL(PIPE_A);
16130 I915_WRITE(dp_reg, val);
16133 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
16136 * The BIOS may select transcoder B on some of the PCH
16137 * ports even it doesn't enable the port. This would trip
16138 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
16139 * Sanitize the transcoder select bits to prevent that. We
16140 * assume that the BIOS never actually enabled the port,
16141 * because if it did we'd actually have to toggle the port
16142 * on and back off to make the transcoder A select stick
16143 * (see. intel_dp_link_down(), intel_disable_hdmi(),
16144 * intel_disable_sdvo()).
16146 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
16147 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
16148 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
16150 /* PCH SDVOB multiplex with HDMIB */
16151 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
16152 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
16153 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
16156 /* Scan out the current hw modeset state,
16157 * and sanitizes it to the current state
16160 intel_modeset_setup_hw_state(struct drm_device *dev,
16161 struct drm_modeset_acquire_ctx *ctx)
16163 struct drm_i915_private *dev_priv = to_i915(dev);
16164 struct intel_crtc_state *crtc_state;
16165 struct intel_encoder *encoder;
16166 struct intel_crtc *crtc;
16167 intel_wakeref_t wakeref;
16170 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
16172 intel_early_display_was(dev_priv);
16173 intel_modeset_readout_hw_state(dev);
16175 /* HW state is read out, now we need to sanitize this mess. */
16176 get_encoder_power_domains(dev_priv);
16178 if (HAS_PCH_IBX(dev_priv))
16179 ibx_sanitize_pch_ports(dev_priv);
16182 * intel_sanitize_plane_mapping() may need to do vblank
16183 * waits, so we need vblank interrupts restored beforehand.
16185 for_each_intel_crtc(&dev_priv->drm, crtc) {
16186 crtc_state = to_intel_crtc_state(crtc->base.state);
16188 drm_crtc_vblank_reset(&crtc->base);
16190 if (crtc_state->base.active)
16191 intel_crtc_vblank_on(crtc_state);
16194 intel_sanitize_plane_mapping(dev_priv);
16196 for_each_intel_encoder(dev, encoder)
16197 intel_sanitize_encoder(encoder);
16199 for_each_intel_crtc(&dev_priv->drm, crtc) {
16200 crtc_state = to_intel_crtc_state(crtc->base.state);
16201 intel_sanitize_crtc(crtc, ctx);
16202 intel_dump_pipe_config(crtc, crtc_state,
16203 "[setup_hw_state]");
16206 intel_modeset_update_connector_atomic_state(dev);
16208 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16209 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16211 if (!pll->on || pll->active_mask)
16214 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
16217 pll->info->funcs->disable(dev_priv, pll);
16221 if (IS_G4X(dev_priv)) {
16222 g4x_wm_get_hw_state(dev_priv);
16223 g4x_wm_sanitize(dev_priv);
16224 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16225 vlv_wm_get_hw_state(dev_priv);
16226 vlv_wm_sanitize(dev_priv);
16227 } else if (INTEL_GEN(dev_priv) >= 9) {
16228 skl_wm_get_hw_state(dev_priv);
16229 } else if (HAS_PCH_SPLIT(dev_priv)) {
16230 ilk_wm_get_hw_state(dev_priv);
16233 for_each_intel_crtc(dev, crtc) {
16236 crtc_state = to_intel_crtc_state(crtc->base.state);
16237 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
16238 if (WARN_ON(put_domains))
16239 modeset_put_power_domains(dev_priv, put_domains);
16242 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
16244 intel_fbc_init_pipe_state(dev_priv);
16247 void intel_display_resume(struct drm_device *dev)
16249 struct drm_i915_private *dev_priv = to_i915(dev);
16250 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
16251 struct drm_modeset_acquire_ctx ctx;
16254 dev_priv->modeset_restore_state = NULL;
16256 state->acquire_ctx = &ctx;
16258 drm_modeset_acquire_init(&ctx, 0);
16261 ret = drm_modeset_lock_all_ctx(dev, &ctx);
16262 if (ret != -EDEADLK)
16265 drm_modeset_backoff(&ctx);
16269 ret = __intel_display_resume(dev, state, &ctx);
16271 intel_enable_ipc(dev_priv);
16272 drm_modeset_drop_locks(&ctx);
16273 drm_modeset_acquire_fini(&ctx);
16276 DRM_ERROR("Restoring old state failed with %i\n", ret);
16278 drm_atomic_state_put(state);
16281 static void intel_hpd_poll_fini(struct drm_device *dev)
16283 struct intel_connector *connector;
16284 struct drm_connector_list_iter conn_iter;
16286 /* Kill all the work that may have been queued by hpd. */
16287 drm_connector_list_iter_begin(dev, &conn_iter);
16288 for_each_intel_connector_iter(connector, &conn_iter) {
16289 if (connector->modeset_retry_work.func)
16290 cancel_work_sync(&connector->modeset_retry_work);
16291 if (connector->hdcp.shim) {
16292 cancel_delayed_work_sync(&connector->hdcp.check_work);
16293 cancel_work_sync(&connector->hdcp.prop_work);
16296 drm_connector_list_iter_end(&conn_iter);
16299 void intel_modeset_cleanup(struct drm_device *dev)
16301 struct drm_i915_private *dev_priv = to_i915(dev);
16303 flush_workqueue(dev_priv->modeset_wq);
16305 flush_work(&dev_priv->atomic_helper.free_work);
16306 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
16309 * Interrupts and polling as the first thing to avoid creating havoc.
16310 * Too much stuff here (turning of connectors, ...) would
16311 * experience fancy races otherwise.
16313 intel_irq_uninstall(dev_priv);
16316 * Due to the hpd irq storm handling the hotplug work can re-arm the
16317 * poll handlers. Hence disable polling after hpd handling is shut down.
16319 intel_hpd_poll_fini(dev);
16321 /* poll work can call into fbdev, hence clean that up afterwards */
16322 intel_fbdev_fini(dev_priv);
16324 intel_unregister_dsm_handler();
16326 intel_fbc_global_disable(dev_priv);
16328 /* flush any delayed tasks or pending work */
16329 flush_scheduled_work();
16331 drm_mode_config_cleanup(dev);
16333 intel_overlay_cleanup(dev_priv);
16335 intel_teardown_gmbus(dev_priv);
16337 destroy_workqueue(dev_priv->modeset_wq);
16339 intel_fbc_cleanup_cfb(dev_priv);
16343 * set vga decode state - true == enable VGA decode
16345 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
16347 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
16350 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
16351 DRM_ERROR("failed to read control word\n");
16355 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
16359 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
16361 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
16363 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
16364 DRM_ERROR("failed to write control word\n");
16371 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
16373 struct intel_display_error_state {
16375 u32 power_well_driver;
16377 int num_transcoders;
16379 struct intel_cursor_error_state {
16384 } cursor[I915_MAX_PIPES];
16386 struct intel_pipe_error_state {
16387 bool power_domain_on;
16390 } pipe[I915_MAX_PIPES];
16392 struct intel_plane_error_state {
16400 } plane[I915_MAX_PIPES];
16402 struct intel_transcoder_error_state {
16403 bool power_domain_on;
16404 enum transcoder cpu_transcoder;
16417 struct intel_display_error_state *
16418 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
16420 struct intel_display_error_state *error;
16421 int transcoders[] = {
16429 if (!HAS_DISPLAY(dev_priv))
16432 error = kzalloc(sizeof(*error), GFP_ATOMIC);
16436 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16437 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
16439 for_each_pipe(dev_priv, i) {
16440 error->pipe[i].power_domain_on =
16441 __intel_display_power_is_enabled(dev_priv,
16442 POWER_DOMAIN_PIPE(i));
16443 if (!error->pipe[i].power_domain_on)
16446 error->cursor[i].control = I915_READ(CURCNTR(i));
16447 error->cursor[i].position = I915_READ(CURPOS(i));
16448 error->cursor[i].base = I915_READ(CURBASE(i));
16450 error->plane[i].control = I915_READ(DSPCNTR(i));
16451 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
16452 if (INTEL_GEN(dev_priv) <= 3) {
16453 error->plane[i].size = I915_READ(DSPSIZE(i));
16454 error->plane[i].pos = I915_READ(DSPPOS(i));
16456 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16457 error->plane[i].addr = I915_READ(DSPADDR(i));
16458 if (INTEL_GEN(dev_priv) >= 4) {
16459 error->plane[i].surface = I915_READ(DSPSURF(i));
16460 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16463 error->pipe[i].source = I915_READ(PIPESRC(i));
16465 if (HAS_GMCH(dev_priv))
16466 error->pipe[i].stat = I915_READ(PIPESTAT(i));
16469 /* Note: this does not include DSI transcoders. */
16470 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
16471 if (HAS_DDI(dev_priv))
16472 error->num_transcoders++; /* Account for eDP. */
16474 for (i = 0; i < error->num_transcoders; i++) {
16475 enum transcoder cpu_transcoder = transcoders[i];
16477 error->transcoder[i].power_domain_on =
16478 __intel_display_power_is_enabled(dev_priv,
16479 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
16480 if (!error->transcoder[i].power_domain_on)
16483 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16485 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16486 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16487 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16488 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16489 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16490 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16491 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
16497 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16500 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
16501 struct intel_display_error_state *error)
16503 struct drm_i915_private *dev_priv = m->i915;
16509 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
16510 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16511 err_printf(m, "PWR_WELL_CTL2: %08x\n",
16512 error->power_well_driver);
16513 for_each_pipe(dev_priv, i) {
16514 err_printf(m, "Pipe [%d]:\n", i);
16515 err_printf(m, " Power: %s\n",
16516 onoff(error->pipe[i].power_domain_on));
16517 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
16518 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
16520 err_printf(m, "Plane [%d]:\n", i);
16521 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16522 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
16523 if (INTEL_GEN(dev_priv) <= 3) {
16524 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16525 err_printf(m, " POS: %08x\n", error->plane[i].pos);
16527 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16528 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
16529 if (INTEL_GEN(dev_priv) >= 4) {
16530 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16531 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
16534 err_printf(m, "Cursor [%d]:\n", i);
16535 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16536 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16537 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
16540 for (i = 0; i < error->num_transcoders; i++) {
16541 err_printf(m, "CPU transcoder: %s\n",
16542 transcoder_name(error->transcoder[i].cpu_transcoder));
16543 err_printf(m, " Power: %s\n",
16544 onoff(error->transcoder[i].power_domain_on));
16545 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16546 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16547 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16548 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16549 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16550 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16551 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);