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_Y410;
2694 case PLANE_CTL_FORMAT_Y412:
2695 return DRM_FORMAT_Y412;
2696 case PLANE_CTL_FORMAT_Y416:
2697 return DRM_FORMAT_Y416;
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;
2720 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2721 struct intel_initial_plane_config *plane_config)
2723 struct drm_device *dev = crtc->base.dev;
2724 struct drm_i915_private *dev_priv = to_i915(dev);
2725 struct drm_i915_gem_object *obj = NULL;
2726 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2727 struct drm_framebuffer *fb = &plane_config->fb->base;
2728 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2729 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2732 size_aligned -= base_aligned;
2734 if (plane_config->size == 0)
2737 /* If the FB is too big, just don't use it since fbdev is not very
2738 * important and we should probably use that space with FBC or other
2740 if (size_aligned * 2 > dev_priv->stolen_usable_size)
2743 switch (fb->modifier) {
2744 case DRM_FORMAT_MOD_LINEAR:
2745 case I915_FORMAT_MOD_X_TILED:
2746 case I915_FORMAT_MOD_Y_TILED:
2749 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2754 mutex_lock(&dev->struct_mutex);
2755 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
2759 mutex_unlock(&dev->struct_mutex);
2763 switch (plane_config->tiling) {
2764 case I915_TILING_NONE:
2768 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2771 MISSING_CASE(plane_config->tiling);
2775 mode_cmd.pixel_format = fb->format->format;
2776 mode_cmd.width = fb->width;
2777 mode_cmd.height = fb->height;
2778 mode_cmd.pitches[0] = fb->pitches[0];
2779 mode_cmd.modifier[0] = fb->modifier;
2780 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2782 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
2783 DRM_DEBUG_KMS("intel fb init failed\n");
2788 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
2792 i915_gem_object_put(obj);
2797 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2798 struct intel_plane_state *plane_state,
2801 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2803 plane_state->base.visible = visible;
2806 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
2808 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
2811 static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2813 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2814 struct drm_plane *plane;
2817 * Active_planes aliases if multiple "primary" or cursor planes
2818 * have been used on the same (or wrong) pipe. plane_mask uses
2819 * unique ids, hence we can use that to reconstruct active_planes.
2821 crtc_state->active_planes = 0;
2823 drm_for_each_plane_mask(plane, &dev_priv->drm,
2824 crtc_state->base.plane_mask)
2825 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2828 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2829 struct intel_plane *plane)
2831 struct intel_crtc_state *crtc_state =
2832 to_intel_crtc_state(crtc->base.state);
2833 struct intel_plane_state *plane_state =
2834 to_intel_plane_state(plane->base.state);
2836 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2837 plane->base.base.id, plane->base.name,
2838 crtc->base.base.id, crtc->base.name);
2840 intel_set_plane_visible(crtc_state, plane_state, false);
2841 fixup_active_planes(crtc_state);
2843 if (plane->id == PLANE_PRIMARY)
2844 intel_pre_disable_primary_noatomic(&crtc->base);
2846 trace_intel_disable_plane(&plane->base, crtc);
2847 plane->disable_plane(plane, crtc_state);
2851 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2852 struct intel_initial_plane_config *plane_config)
2854 struct drm_device *dev = intel_crtc->base.dev;
2855 struct drm_i915_private *dev_priv = to_i915(dev);
2857 struct drm_i915_gem_object *obj;
2858 struct drm_plane *primary = intel_crtc->base.primary;
2859 struct drm_plane_state *plane_state = primary->state;
2860 struct intel_plane *intel_plane = to_intel_plane(primary);
2861 struct intel_plane_state *intel_state =
2862 to_intel_plane_state(plane_state);
2863 struct drm_framebuffer *fb;
2865 if (!plane_config->fb)
2868 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2869 fb = &plane_config->fb->base;
2873 kfree(plane_config->fb);
2876 * Failed to alloc the obj, check to see if we should share
2877 * an fb with another CRTC instead
2879 for_each_crtc(dev, c) {
2880 struct intel_plane_state *state;
2882 if (c == &intel_crtc->base)
2885 if (!to_intel_crtc(c)->active)
2888 state = to_intel_plane_state(c->primary->state);
2892 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2893 fb = state->base.fb;
2894 drm_framebuffer_get(fb);
2900 * We've failed to reconstruct the BIOS FB. Current display state
2901 * indicates that the primary plane is visible, but has a NULL FB,
2902 * which will lead to problems later if we don't fix it up. The
2903 * simplest solution is to just disable the primary plane now and
2904 * pretend the BIOS never had it enabled.
2906 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2911 intel_state->base.rotation = plane_config->rotation;
2912 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2913 intel_state->base.rotation);
2914 intel_state->color_plane[0].stride =
2915 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2917 mutex_lock(&dev->struct_mutex);
2919 intel_pin_and_fence_fb_obj(fb,
2921 intel_plane_uses_fence(intel_state),
2922 &intel_state->flags);
2923 mutex_unlock(&dev->struct_mutex);
2924 if (IS_ERR(intel_state->vma)) {
2925 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2926 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2928 intel_state->vma = NULL;
2929 drm_framebuffer_put(fb);
2933 obj = intel_fb_obj(fb);
2934 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2936 plane_state->src_x = 0;
2937 plane_state->src_y = 0;
2938 plane_state->src_w = fb->width << 16;
2939 plane_state->src_h = fb->height << 16;
2941 plane_state->crtc_x = 0;
2942 plane_state->crtc_y = 0;
2943 plane_state->crtc_w = fb->width;
2944 plane_state->crtc_h = fb->height;
2946 intel_state->base.src = drm_plane_state_src(plane_state);
2947 intel_state->base.dst = drm_plane_state_dest(plane_state);
2949 if (i915_gem_object_is_tiled(obj))
2950 dev_priv->preserve_bios_swizzle = true;
2952 plane_state->fb = fb;
2953 plane_state->crtc = &intel_crtc->base;
2955 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2956 &obj->frontbuffer_bits);
2959 static int skl_max_plane_width(const struct drm_framebuffer *fb,
2961 unsigned int rotation)
2963 int cpp = fb->format->cpp[color_plane];
2965 switch (fb->modifier) {
2966 case DRM_FORMAT_MOD_LINEAR:
2967 case I915_FORMAT_MOD_X_TILED:
2980 case I915_FORMAT_MOD_Y_TILED_CCS:
2981 case I915_FORMAT_MOD_Yf_TILED_CCS:
2982 /* FIXME AUX plane? */
2983 case I915_FORMAT_MOD_Y_TILED:
2984 case I915_FORMAT_MOD_Yf_TILED:
2999 MISSING_CASE(fb->modifier);
3005 static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3006 int main_x, int main_y, u32 main_offset)
3008 const struct drm_framebuffer *fb = plane_state->base.fb;
3009 int hsub = fb->format->hsub;
3010 int vsub = fb->format->vsub;
3011 int aux_x = plane_state->color_plane[1].x;
3012 int aux_y = plane_state->color_plane[1].y;
3013 u32 aux_offset = plane_state->color_plane[1].offset;
3014 u32 alignment = intel_surf_alignment(fb, 1);
3016 while (aux_offset >= main_offset && aux_y <= main_y) {
3019 if (aux_x == main_x && aux_y == main_y)
3022 if (aux_offset == 0)
3027 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3028 aux_offset, aux_offset - alignment);
3029 aux_x = x * hsub + aux_x % hsub;
3030 aux_y = y * vsub + aux_y % vsub;
3033 if (aux_x != main_x || aux_y != main_y)
3036 plane_state->color_plane[1].offset = aux_offset;
3037 plane_state->color_plane[1].x = aux_x;
3038 plane_state->color_plane[1].y = aux_y;
3043 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3045 const struct drm_framebuffer *fb = plane_state->base.fb;
3046 unsigned int rotation = plane_state->base.rotation;
3047 int x = plane_state->base.src.x1 >> 16;
3048 int y = plane_state->base.src.y1 >> 16;
3049 int w = drm_rect_width(&plane_state->base.src) >> 16;
3050 int h = drm_rect_height(&plane_state->base.src) >> 16;
3051 int max_width = skl_max_plane_width(fb, 0, rotation);
3052 int max_height = 4096;
3053 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
3055 if (w > max_width || h > max_height) {
3056 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3057 w, h, max_width, max_height);
3061 intel_add_fb_offsets(&x, &y, plane_state, 0);
3062 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
3063 alignment = intel_surf_alignment(fb, 0);
3066 * AUX surface offset is specified as the distance from the
3067 * main surface offset, and it must be non-negative. Make
3068 * sure that is what we will get.
3070 if (offset > aux_offset)
3071 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3072 offset, aux_offset & ~(alignment - 1));
3075 * When using an X-tiled surface, the plane blows up
3076 * if the x offset + width exceed the stride.
3078 * TODO: linear and Y-tiled seem fine, Yf untested,
3080 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3081 int cpp = fb->format->cpp[0];
3083 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
3085 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
3089 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3090 offset, offset - alignment);
3095 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3096 * they match with the main surface x/y offsets.
3098 if (is_ccs_modifier(fb->modifier)) {
3099 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3103 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3104 offset, offset - alignment);
3107 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
3108 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3113 plane_state->color_plane[0].offset = offset;
3114 plane_state->color_plane[0].x = x;
3115 plane_state->color_plane[0].y = y;
3120 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3122 const struct drm_framebuffer *fb = plane_state->base.fb;
3123 unsigned int rotation = plane_state->base.rotation;
3124 int max_width = skl_max_plane_width(fb, 1, rotation);
3125 int max_height = 4096;
3126 int x = plane_state->base.src.x1 >> 17;
3127 int y = plane_state->base.src.y1 >> 17;
3128 int w = drm_rect_width(&plane_state->base.src) >> 17;
3129 int h = drm_rect_height(&plane_state->base.src) >> 17;
3132 intel_add_fb_offsets(&x, &y, plane_state, 1);
3133 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3135 /* FIXME not quite sure how/if these apply to the chroma plane */
3136 if (w > max_width || h > max_height) {
3137 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3138 w, h, max_width, max_height);
3142 plane_state->color_plane[1].offset = offset;
3143 plane_state->color_plane[1].x = x;
3144 plane_state->color_plane[1].y = y;
3149 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3151 const struct drm_framebuffer *fb = plane_state->base.fb;
3152 int src_x = plane_state->base.src.x1 >> 16;
3153 int src_y = plane_state->base.src.y1 >> 16;
3154 int hsub = fb->format->hsub;
3155 int vsub = fb->format->vsub;
3156 int x = src_x / hsub;
3157 int y = src_y / vsub;
3160 intel_add_fb_offsets(&x, &y, plane_state, 1);
3161 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
3163 plane_state->color_plane[1].offset = offset;
3164 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3165 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
3170 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3172 const struct drm_framebuffer *fb = plane_state->base.fb;
3173 unsigned int rotation = plane_state->base.rotation;
3176 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3177 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3178 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3180 ret = intel_plane_check_stride(plane_state);
3184 if (!plane_state->base.visible)
3187 /* Rotate src coordinates to match rotated GTT view */
3188 if (drm_rotation_90_or_270(rotation))
3189 drm_rect_rotate(&plane_state->base.src,
3190 fb->width << 16, fb->height << 16,
3191 DRM_MODE_ROTATE_270);
3194 * Handle the AUX surface first since
3195 * the main surface setup depends on it.
3197 if (is_planar_yuv_format(fb->format->format)) {
3198 ret = skl_check_nv12_aux_surface(plane_state);
3201 } else if (is_ccs_modifier(fb->modifier)) {
3202 ret = skl_check_ccs_aux_surface(plane_state);
3206 plane_state->color_plane[1].offset = ~0xfff;
3207 plane_state->color_plane[1].x = 0;
3208 plane_state->color_plane[1].y = 0;
3211 ret = skl_check_main_surface(plane_state);
3219 i9xx_plane_max_stride(struct intel_plane *plane,
3220 u32 pixel_format, u64 modifier,
3221 unsigned int rotation)
3223 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3225 if (!HAS_GMCH(dev_priv)) {
3227 } else if (INTEL_GEN(dev_priv) >= 4) {
3228 if (modifier == I915_FORMAT_MOD_X_TILED)
3232 } else if (INTEL_GEN(dev_priv) >= 3) {
3233 if (modifier == I915_FORMAT_MOD_X_TILED)
3238 if (plane->i9xx_plane == PLANE_C)
3245 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3247 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3248 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3251 dspcntr |= DISPPLANE_GAMMA_ENABLE;
3253 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3254 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
3256 if (INTEL_GEN(dev_priv) < 5)
3257 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
3262 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3263 const struct intel_plane_state *plane_state)
3265 struct drm_i915_private *dev_priv =
3266 to_i915(plane_state->base.plane->dev);
3267 const struct drm_framebuffer *fb = plane_state->base.fb;
3268 unsigned int rotation = plane_state->base.rotation;
3271 dspcntr = DISPLAY_PLANE_ENABLE;
3273 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3274 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
3275 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3277 switch (fb->format->format) {
3279 dspcntr |= DISPPLANE_8BPP;
3281 case DRM_FORMAT_XRGB1555:
3282 dspcntr |= DISPPLANE_BGRX555;
3284 case DRM_FORMAT_RGB565:
3285 dspcntr |= DISPPLANE_BGRX565;
3287 case DRM_FORMAT_XRGB8888:
3288 dspcntr |= DISPPLANE_BGRX888;
3290 case DRM_FORMAT_XBGR8888:
3291 dspcntr |= DISPPLANE_RGBX888;
3293 case DRM_FORMAT_XRGB2101010:
3294 dspcntr |= DISPPLANE_BGRX101010;
3296 case DRM_FORMAT_XBGR2101010:
3297 dspcntr |= DISPPLANE_RGBX101010;
3300 MISSING_CASE(fb->format->format);
3304 if (INTEL_GEN(dev_priv) >= 4 &&
3305 fb->modifier == I915_FORMAT_MOD_X_TILED)
3306 dspcntr |= DISPPLANE_TILED;
3308 if (rotation & DRM_MODE_ROTATE_180)
3309 dspcntr |= DISPPLANE_ROTATE_180;
3311 if (rotation & DRM_MODE_REFLECT_X)
3312 dspcntr |= DISPPLANE_MIRROR;
3317 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
3319 struct drm_i915_private *dev_priv =
3320 to_i915(plane_state->base.plane->dev);
3321 const struct drm_framebuffer *fb = plane_state->base.fb;
3322 unsigned int rotation = plane_state->base.rotation;
3323 int src_x = plane_state->base.src.x1 >> 16;
3324 int src_y = plane_state->base.src.y1 >> 16;
3328 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
3329 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3331 ret = intel_plane_check_stride(plane_state);
3335 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
3337 if (INTEL_GEN(dev_priv) >= 4)
3338 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3343 /* HSW/BDW do this automagically in hardware */
3344 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
3345 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3346 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3348 if (rotation & DRM_MODE_ROTATE_180) {
3351 } else if (rotation & DRM_MODE_REFLECT_X) {
3356 plane_state->color_plane[0].offset = offset;
3357 plane_state->color_plane[0].x = src_x;
3358 plane_state->color_plane[0].y = src_y;
3364 i9xx_plane_check(struct intel_crtc_state *crtc_state,
3365 struct intel_plane_state *plane_state)
3369 ret = chv_plane_check_rotation(plane_state);
3373 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3375 DRM_PLANE_HELPER_NO_SCALING,
3376 DRM_PLANE_HELPER_NO_SCALING,
3381 if (!plane_state->base.visible)
3384 ret = intel_plane_check_src_coordinates(plane_state);
3388 ret = i9xx_check_plane_surface(plane_state);
3392 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3397 static void i9xx_update_plane(struct intel_plane *plane,
3398 const struct intel_crtc_state *crtc_state,
3399 const struct intel_plane_state *plane_state)
3401 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3402 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3404 int x = plane_state->color_plane[0].x;
3405 int y = plane_state->color_plane[0].y;
3406 unsigned long irqflags;
3410 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
3412 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
3414 if (INTEL_GEN(dev_priv) >= 4)
3415 dspaddr_offset = plane_state->color_plane[0].offset;
3417 dspaddr_offset = linear_offset;
3419 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3421 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3423 if (INTEL_GEN(dev_priv) < 4) {
3424 /* pipesrc and dspsize control the size that is scaled from,
3425 * which should always be the user's requested size.
3427 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
3428 I915_WRITE_FW(DSPSIZE(i9xx_plane),
3429 ((crtc_state->pipe_src_h - 1) << 16) |
3430 (crtc_state->pipe_src_w - 1));
3431 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
3432 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
3433 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
3434 ((crtc_state->pipe_src_h - 1) << 16) |
3435 (crtc_state->pipe_src_w - 1));
3436 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
3439 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3440 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
3441 } else if (INTEL_GEN(dev_priv) >= 4) {
3442 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3443 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3447 * The control register self-arms if the plane was previously
3448 * disabled. Try to make the plane enable atomic by writing
3449 * the control register just before the surface register.
3451 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3452 if (INTEL_GEN(dev_priv) >= 4)
3453 I915_WRITE_FW(DSPSURF(i9xx_plane),
3454 intel_plane_ggtt_offset(plane_state) +
3457 I915_WRITE_FW(DSPADDR(i9xx_plane),
3458 intel_plane_ggtt_offset(plane_state) +
3461 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3464 static void i9xx_disable_plane(struct intel_plane *plane,
3465 const struct intel_crtc_state *crtc_state)
3467 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3468 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3469 unsigned long irqflags;
3473 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
3474 * enable on ilk+ affect the pipe bottom color as
3475 * well, so we must configure them even if the plane
3478 * On pre-g4x there is no way to gamma correct the
3479 * pipe bottom color but we'll keep on doing this
3482 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
3484 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3486 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3487 if (INTEL_GEN(dev_priv) >= 4)
3488 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
3490 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
3492 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3495 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3498 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3499 enum intel_display_power_domain power_domain;
3500 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3501 intel_wakeref_t wakeref;
3506 * Not 100% correct for planes that can move between pipes,
3507 * but that's only the case for gen2-4 which don't have any
3508 * display power wells.
3510 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
3511 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3515 val = I915_READ(DSPCNTR(i9xx_plane));
3517 ret = val & DISPLAY_PLANE_ENABLE;
3519 if (INTEL_GEN(dev_priv) >= 5)
3520 *pipe = plane->pipe;
3522 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3523 DISPPLANE_SEL_PIPE_SHIFT;
3525 intel_display_power_put(dev_priv, power_domain, wakeref);
3531 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
3533 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3536 return intel_tile_width_bytes(fb, color_plane);
3539 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3541 struct drm_device *dev = intel_crtc->base.dev;
3542 struct drm_i915_private *dev_priv = to_i915(dev);
3544 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3545 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3546 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3550 * This function detaches (aka. unbinds) unused scalers in hardware
3552 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
3554 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3555 const struct intel_crtc_scaler_state *scaler_state =
3556 &crtc_state->scaler_state;
3559 /* loop through and disable scalers that aren't in use */
3560 for (i = 0; i < intel_crtc->num_scalers; i++) {
3561 if (!scaler_state->scalers[i].in_use)
3562 skl_detach_scaler(intel_crtc, i);
3566 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3567 int color_plane, unsigned int rotation)
3570 * The stride is either expressed as a multiple of 64 bytes chunks for
3571 * linear buffers or in number of tiles for tiled buffers.
3573 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3575 else if (drm_rotation_90_or_270(rotation))
3576 return intel_tile_height(fb, color_plane);
3578 return intel_tile_width_bytes(fb, color_plane);
3581 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3584 const struct drm_framebuffer *fb = plane_state->base.fb;
3585 unsigned int rotation = plane_state->base.rotation;
3586 u32 stride = plane_state->color_plane[color_plane].stride;
3588 if (color_plane >= fb->format->num_planes)
3591 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
3594 static u32 skl_plane_ctl_format(u32 pixel_format)
3596 switch (pixel_format) {
3598 return PLANE_CTL_FORMAT_INDEXED;
3599 case DRM_FORMAT_RGB565:
3600 return PLANE_CTL_FORMAT_RGB_565;
3601 case DRM_FORMAT_XBGR8888:
3602 case DRM_FORMAT_ABGR8888:
3603 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3604 case DRM_FORMAT_XRGB8888:
3605 case DRM_FORMAT_ARGB8888:
3606 return PLANE_CTL_FORMAT_XRGB_8888;
3607 case DRM_FORMAT_XRGB2101010:
3608 return PLANE_CTL_FORMAT_XRGB_2101010;
3609 case DRM_FORMAT_XBGR2101010:
3610 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
3611 case DRM_FORMAT_YUYV:
3612 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3613 case DRM_FORMAT_YVYU:
3614 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3615 case DRM_FORMAT_UYVY:
3616 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3617 case DRM_FORMAT_VYUY:
3618 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3619 case DRM_FORMAT_NV12:
3620 return PLANE_CTL_FORMAT_NV12;
3621 case DRM_FORMAT_P010:
3622 return PLANE_CTL_FORMAT_P010;
3623 case DRM_FORMAT_P012:
3624 return PLANE_CTL_FORMAT_P012;
3625 case DRM_FORMAT_P016:
3626 return PLANE_CTL_FORMAT_P016;
3627 case DRM_FORMAT_Y210:
3628 return PLANE_CTL_FORMAT_Y210;
3629 case DRM_FORMAT_Y212:
3630 return PLANE_CTL_FORMAT_Y212;
3631 case DRM_FORMAT_Y216:
3632 return PLANE_CTL_FORMAT_Y216;
3633 case DRM_FORMAT_Y410:
3634 return PLANE_CTL_FORMAT_Y410;
3635 case DRM_FORMAT_Y412:
3636 return PLANE_CTL_FORMAT_Y412;
3637 case DRM_FORMAT_Y416:
3638 return PLANE_CTL_FORMAT_Y416;
3640 MISSING_CASE(pixel_format);
3646 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
3648 if (!plane_state->base.fb->format->has_alpha)
3649 return PLANE_CTL_ALPHA_DISABLE;
3651 switch (plane_state->base.pixel_blend_mode) {
3652 case DRM_MODE_BLEND_PIXEL_NONE:
3653 return PLANE_CTL_ALPHA_DISABLE;
3654 case DRM_MODE_BLEND_PREMULTI:
3655 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3656 case DRM_MODE_BLEND_COVERAGE:
3657 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
3659 MISSING_CASE(plane_state->base.pixel_blend_mode);
3660 return PLANE_CTL_ALPHA_DISABLE;
3664 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
3666 if (!plane_state->base.fb->format->has_alpha)
3667 return PLANE_COLOR_ALPHA_DISABLE;
3669 switch (plane_state->base.pixel_blend_mode) {
3670 case DRM_MODE_BLEND_PIXEL_NONE:
3671 return PLANE_COLOR_ALPHA_DISABLE;
3672 case DRM_MODE_BLEND_PREMULTI:
3673 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3674 case DRM_MODE_BLEND_COVERAGE:
3675 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
3677 MISSING_CASE(plane_state->base.pixel_blend_mode);
3678 return PLANE_COLOR_ALPHA_DISABLE;
3682 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
3684 switch (fb_modifier) {
3685 case DRM_FORMAT_MOD_LINEAR:
3687 case I915_FORMAT_MOD_X_TILED:
3688 return PLANE_CTL_TILED_X;
3689 case I915_FORMAT_MOD_Y_TILED:
3690 return PLANE_CTL_TILED_Y;
3691 case I915_FORMAT_MOD_Y_TILED_CCS:
3692 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3693 case I915_FORMAT_MOD_Yf_TILED:
3694 return PLANE_CTL_TILED_YF;
3695 case I915_FORMAT_MOD_Yf_TILED_CCS:
3696 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3698 MISSING_CASE(fb_modifier);
3704 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3707 case DRM_MODE_ROTATE_0:
3710 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3711 * while i915 HW rotation is clockwise, thats why this swapping.
3713 case DRM_MODE_ROTATE_90:
3714 return PLANE_CTL_ROTATE_270;
3715 case DRM_MODE_ROTATE_180:
3716 return PLANE_CTL_ROTATE_180;
3717 case DRM_MODE_ROTATE_270:
3718 return PLANE_CTL_ROTATE_90;
3720 MISSING_CASE(rotate);
3726 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3731 case DRM_MODE_REFLECT_X:
3732 return PLANE_CTL_FLIP_HORIZONTAL;
3733 case DRM_MODE_REFLECT_Y:
3735 MISSING_CASE(reflect);
3741 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3743 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3746 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3749 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
3750 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
3755 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3756 const struct intel_plane_state *plane_state)
3758 struct drm_i915_private *dev_priv =
3759 to_i915(plane_state->base.plane->dev);
3760 const struct drm_framebuffer *fb = plane_state->base.fb;
3761 unsigned int rotation = plane_state->base.rotation;
3762 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3765 plane_ctl = PLANE_CTL_ENABLE;
3767 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3768 plane_ctl |= skl_plane_ctl_alpha(plane_state);
3769 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
3771 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3772 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3774 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3775 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3778 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3779 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3780 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3782 if (INTEL_GEN(dev_priv) >= 10)
3783 plane_ctl |= cnl_plane_ctl_flip(rotation &
3784 DRM_MODE_REFLECT_MASK);
3786 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3787 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3788 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3789 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3794 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
3796 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3797 u32 plane_color_ctl = 0;
3799 if (INTEL_GEN(dev_priv) >= 11)
3800 return plane_color_ctl;
3802 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3803 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3805 return plane_color_ctl;
3808 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3809 const struct intel_plane_state *plane_state)
3811 struct drm_i915_private *dev_priv =
3812 to_i915(plane_state->base.plane->dev);
3813 const struct drm_framebuffer *fb = plane_state->base.fb;
3814 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
3815 u32 plane_color_ctl = 0;
3817 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3818 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
3820 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
3821 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3822 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3824 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
3826 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3827 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3828 } else if (fb->format->is_yuv) {
3829 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
3832 return plane_color_ctl;
3836 __intel_display_resume(struct drm_device *dev,
3837 struct drm_atomic_state *state,
3838 struct drm_modeset_acquire_ctx *ctx)
3840 struct drm_crtc_state *crtc_state;
3841 struct drm_crtc *crtc;
3844 intel_modeset_setup_hw_state(dev, ctx);
3845 i915_redisable_vga(to_i915(dev));
3851 * We've duplicated the state, pointers to the old state are invalid.
3853 * Don't attempt to use the old state until we commit the duplicated state.
3855 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3857 * Force recalculation even if we restore
3858 * current state. With fast modeset this may not result
3859 * in a modeset when the state is compatible.
3861 crtc_state->mode_changed = true;
3864 /* ignore any reset values/BIOS leftovers in the WM registers */
3865 if (!HAS_GMCH(to_i915(dev)))
3866 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3868 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3870 WARN_ON(ret == -EDEADLK);
3874 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3876 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
3877 intel_has_gpu_reset(dev_priv));
3880 void intel_prepare_reset(struct drm_i915_private *dev_priv)
3882 struct drm_device *dev = &dev_priv->drm;
3883 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3884 struct drm_atomic_state *state;
3887 /* reset doesn't touch the display */
3888 if (!i915_modparams.force_reset_modeset_test &&
3889 !gpu_reset_clobbers_display(dev_priv))
3892 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3893 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3894 wake_up_all(&dev_priv->gpu_error.wait_queue);
3896 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3897 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3898 i915_gem_set_wedged(dev_priv);
3902 * Need mode_config.mutex so that we don't
3903 * trample ongoing ->detect() and whatnot.
3905 mutex_lock(&dev->mode_config.mutex);
3906 drm_modeset_acquire_init(ctx, 0);
3908 ret = drm_modeset_lock_all_ctx(dev, ctx);
3909 if (ret != -EDEADLK)
3912 drm_modeset_backoff(ctx);
3915 * Disabling the crtcs gracefully seems nicer. Also the
3916 * g33 docs say we should at least disable all the planes.
3918 state = drm_atomic_helper_duplicate_state(dev, ctx);
3919 if (IS_ERR(state)) {
3920 ret = PTR_ERR(state);
3921 DRM_ERROR("Duplicating state failed with %i\n", ret);
3925 ret = drm_atomic_helper_disable_all(dev, ctx);
3927 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3928 drm_atomic_state_put(state);
3932 dev_priv->modeset_restore_state = state;
3933 state->acquire_ctx = ctx;
3936 void intel_finish_reset(struct drm_i915_private *dev_priv)
3938 struct drm_device *dev = &dev_priv->drm;
3939 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3940 struct drm_atomic_state *state;
3943 /* reset doesn't touch the display */
3944 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
3947 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3951 /* reset doesn't touch the display */
3952 if (!gpu_reset_clobbers_display(dev_priv)) {
3953 /* for testing only restore the display */
3954 ret = __intel_display_resume(dev, state, ctx);
3956 DRM_ERROR("Restoring old state failed with %i\n", ret);
3959 * The display has been reset as well,
3960 * so need a full re-initialization.
3962 intel_runtime_pm_disable_interrupts(dev_priv);
3963 intel_runtime_pm_enable_interrupts(dev_priv);
3965 intel_pps_unlock_regs_wa(dev_priv);
3966 intel_modeset_init_hw(dev);
3967 intel_init_clock_gating(dev_priv);
3969 spin_lock_irq(&dev_priv->irq_lock);
3970 if (dev_priv->display.hpd_irq_setup)
3971 dev_priv->display.hpd_irq_setup(dev_priv);
3972 spin_unlock_irq(&dev_priv->irq_lock);
3974 ret = __intel_display_resume(dev, state, ctx);
3976 DRM_ERROR("Restoring old state failed with %i\n", ret);
3978 intel_hpd_init(dev_priv);
3981 drm_atomic_state_put(state);
3983 drm_modeset_drop_locks(ctx);
3984 drm_modeset_acquire_fini(ctx);
3985 mutex_unlock(&dev->mode_config.mutex);
3987 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3990 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
3992 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3993 enum pipe pipe = crtc->pipe;
3996 tmp = I915_READ(PIPE_CHICKEN(pipe));
3999 * Display WA #1153: icl
4000 * enable hardware to bypass the alpha math
4001 * and rounding for per-pixel values 00 and 0xff
4003 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4006 * W/A for underruns with linear/X-tiled with
4009 tmp |= PM_FILL_MAINTAIN_DBUF_FULLNESS;
4011 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4014 static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
4015 const struct intel_crtc_state *new_crtc_state)
4017 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
4018 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4020 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
4021 crtc->base.mode = new_crtc_state->base.mode;
4024 * Update pipe size and adjust fitter if needed: the reason for this is
4025 * that in compute_mode_changes we check the native mode (not the pfit
4026 * mode) to see if we can flip rather than do a full mode set. In the
4027 * fastboot case, we'll flip, but if we don't update the pipesrc and
4028 * pfit state, we'll end up with a big fb scanned out into the wrong
4032 I915_WRITE(PIPESRC(crtc->pipe),
4033 ((new_crtc_state->pipe_src_w - 1) << 16) |
4034 (new_crtc_state->pipe_src_h - 1));
4036 /* on skylake this is done by detaching scalers */
4037 if (INTEL_GEN(dev_priv) >= 9) {
4038 skl_detach_scalers(new_crtc_state);
4040 if (new_crtc_state->pch_pfit.enabled)
4041 skylake_pfit_enable(new_crtc_state);
4042 } else if (HAS_PCH_SPLIT(dev_priv)) {
4043 if (new_crtc_state->pch_pfit.enabled)
4044 ironlake_pfit_enable(new_crtc_state);
4045 else if (old_crtc_state->pch_pfit.enabled)
4046 ironlake_pfit_disable(old_crtc_state);
4050 * We don't (yet) allow userspace to control the pipe background color,
4051 * so force it to black, but apply pipe gamma and CSC so that its
4052 * handling will match how we program our planes.
4054 if (INTEL_GEN(dev_priv) >= 9)
4055 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
4056 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
4057 SKL_BOTTOM_COLOR_CSC_ENABLE);
4059 if (INTEL_GEN(dev_priv) >= 11)
4060 icl_set_pipe_chicken(crtc);
4063 static void intel_fdi_normal_train(struct intel_crtc *crtc)
4065 struct drm_device *dev = crtc->base.dev;
4066 struct drm_i915_private *dev_priv = to_i915(dev);
4067 int pipe = crtc->pipe;
4071 /* enable normal train */
4072 reg = FDI_TX_CTL(pipe);
4073 temp = I915_READ(reg);
4074 if (IS_IVYBRIDGE(dev_priv)) {
4075 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4076 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
4078 temp &= ~FDI_LINK_TRAIN_NONE;
4079 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
4081 I915_WRITE(reg, temp);
4083 reg = FDI_RX_CTL(pipe);
4084 temp = I915_READ(reg);
4085 if (HAS_PCH_CPT(dev_priv)) {
4086 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4087 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4089 temp &= ~FDI_LINK_TRAIN_NONE;
4090 temp |= FDI_LINK_TRAIN_NONE;
4092 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4094 /* wait one idle pattern time */
4098 /* IVB wants error correction enabled */
4099 if (IS_IVYBRIDGE(dev_priv))
4100 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4101 FDI_FE_ERRC_ENABLE);
4104 /* The FDI link training functions for ILK/Ibexpeak. */
4105 static void ironlake_fdi_link_train(struct intel_crtc *crtc,
4106 const struct intel_crtc_state *crtc_state)
4108 struct drm_device *dev = crtc->base.dev;
4109 struct drm_i915_private *dev_priv = to_i915(dev);
4110 int pipe = crtc->pipe;
4114 /* FDI needs bits from pipe first */
4115 assert_pipe_enabled(dev_priv, pipe);
4117 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4119 reg = FDI_RX_IMR(pipe);
4120 temp = I915_READ(reg);
4121 temp &= ~FDI_RX_SYMBOL_LOCK;
4122 temp &= ~FDI_RX_BIT_LOCK;
4123 I915_WRITE(reg, temp);
4127 /* enable CPU FDI TX and PCH FDI RX */
4128 reg = FDI_TX_CTL(pipe);
4129 temp = I915_READ(reg);
4130 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4131 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4132 temp &= ~FDI_LINK_TRAIN_NONE;
4133 temp |= FDI_LINK_TRAIN_PATTERN_1;
4134 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4136 reg = FDI_RX_CTL(pipe);
4137 temp = I915_READ(reg);
4138 temp &= ~FDI_LINK_TRAIN_NONE;
4139 temp |= FDI_LINK_TRAIN_PATTERN_1;
4140 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4145 /* Ironlake workaround, enable clock pointer after FDI enable*/
4146 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4147 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4148 FDI_RX_PHASE_SYNC_POINTER_EN);
4150 reg = FDI_RX_IIR(pipe);
4151 for (tries = 0; tries < 5; tries++) {
4152 temp = I915_READ(reg);
4153 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4155 if ((temp & FDI_RX_BIT_LOCK)) {
4156 DRM_DEBUG_KMS("FDI train 1 done.\n");
4157 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4162 DRM_ERROR("FDI train 1 fail!\n");
4165 reg = FDI_TX_CTL(pipe);
4166 temp = I915_READ(reg);
4167 temp &= ~FDI_LINK_TRAIN_NONE;
4168 temp |= FDI_LINK_TRAIN_PATTERN_2;
4169 I915_WRITE(reg, temp);
4171 reg = FDI_RX_CTL(pipe);
4172 temp = I915_READ(reg);
4173 temp &= ~FDI_LINK_TRAIN_NONE;
4174 temp |= FDI_LINK_TRAIN_PATTERN_2;
4175 I915_WRITE(reg, temp);
4180 reg = FDI_RX_IIR(pipe);
4181 for (tries = 0; tries < 5; tries++) {
4182 temp = I915_READ(reg);
4183 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4185 if (temp & FDI_RX_SYMBOL_LOCK) {
4186 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4187 DRM_DEBUG_KMS("FDI train 2 done.\n");
4192 DRM_ERROR("FDI train 2 fail!\n");
4194 DRM_DEBUG_KMS("FDI train done\n");
4198 static const int snb_b_fdi_train_param[] = {
4199 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4200 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4201 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4202 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4205 /* The FDI link training functions for SNB/Cougarpoint. */
4206 static void gen6_fdi_link_train(struct intel_crtc *crtc,
4207 const struct intel_crtc_state *crtc_state)
4209 struct drm_device *dev = crtc->base.dev;
4210 struct drm_i915_private *dev_priv = to_i915(dev);
4211 int pipe = crtc->pipe;
4215 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4217 reg = FDI_RX_IMR(pipe);
4218 temp = I915_READ(reg);
4219 temp &= ~FDI_RX_SYMBOL_LOCK;
4220 temp &= ~FDI_RX_BIT_LOCK;
4221 I915_WRITE(reg, temp);
4226 /* enable CPU FDI TX and PCH FDI RX */
4227 reg = FDI_TX_CTL(pipe);
4228 temp = I915_READ(reg);
4229 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4230 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4231 temp &= ~FDI_LINK_TRAIN_NONE;
4232 temp |= FDI_LINK_TRAIN_PATTERN_1;
4233 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4235 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4236 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4238 I915_WRITE(FDI_RX_MISC(pipe),
4239 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4241 reg = FDI_RX_CTL(pipe);
4242 temp = I915_READ(reg);
4243 if (HAS_PCH_CPT(dev_priv)) {
4244 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4245 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4247 temp &= ~FDI_LINK_TRAIN_NONE;
4248 temp |= FDI_LINK_TRAIN_PATTERN_1;
4250 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4255 for (i = 0; i < 4; i++) {
4256 reg = FDI_TX_CTL(pipe);
4257 temp = I915_READ(reg);
4258 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4259 temp |= snb_b_fdi_train_param[i];
4260 I915_WRITE(reg, temp);
4265 for (retry = 0; retry < 5; retry++) {
4266 reg = FDI_RX_IIR(pipe);
4267 temp = I915_READ(reg);
4268 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4269 if (temp & FDI_RX_BIT_LOCK) {
4270 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4271 DRM_DEBUG_KMS("FDI train 1 done.\n");
4280 DRM_ERROR("FDI train 1 fail!\n");
4283 reg = FDI_TX_CTL(pipe);
4284 temp = I915_READ(reg);
4285 temp &= ~FDI_LINK_TRAIN_NONE;
4286 temp |= FDI_LINK_TRAIN_PATTERN_2;
4287 if (IS_GEN(dev_priv, 6)) {
4288 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4290 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4292 I915_WRITE(reg, temp);
4294 reg = FDI_RX_CTL(pipe);
4295 temp = I915_READ(reg);
4296 if (HAS_PCH_CPT(dev_priv)) {
4297 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4298 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4300 temp &= ~FDI_LINK_TRAIN_NONE;
4301 temp |= FDI_LINK_TRAIN_PATTERN_2;
4303 I915_WRITE(reg, temp);
4308 for (i = 0; i < 4; i++) {
4309 reg = FDI_TX_CTL(pipe);
4310 temp = I915_READ(reg);
4311 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4312 temp |= snb_b_fdi_train_param[i];
4313 I915_WRITE(reg, temp);
4318 for (retry = 0; retry < 5; retry++) {
4319 reg = FDI_RX_IIR(pipe);
4320 temp = I915_READ(reg);
4321 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4322 if (temp & FDI_RX_SYMBOL_LOCK) {
4323 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4324 DRM_DEBUG_KMS("FDI train 2 done.\n");
4333 DRM_ERROR("FDI train 2 fail!\n");
4335 DRM_DEBUG_KMS("FDI train done.\n");
4338 /* Manual link training for Ivy Bridge A0 parts */
4339 static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4340 const struct intel_crtc_state *crtc_state)
4342 struct drm_device *dev = crtc->base.dev;
4343 struct drm_i915_private *dev_priv = to_i915(dev);
4344 int pipe = crtc->pipe;
4348 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4350 reg = FDI_RX_IMR(pipe);
4351 temp = I915_READ(reg);
4352 temp &= ~FDI_RX_SYMBOL_LOCK;
4353 temp &= ~FDI_RX_BIT_LOCK;
4354 I915_WRITE(reg, temp);
4359 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4360 I915_READ(FDI_RX_IIR(pipe)));
4362 /* Try each vswing and preemphasis setting twice before moving on */
4363 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4364 /* disable first in case we need to retry */
4365 reg = FDI_TX_CTL(pipe);
4366 temp = I915_READ(reg);
4367 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4368 temp &= ~FDI_TX_ENABLE;
4369 I915_WRITE(reg, temp);
4371 reg = FDI_RX_CTL(pipe);
4372 temp = I915_READ(reg);
4373 temp &= ~FDI_LINK_TRAIN_AUTO;
4374 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4375 temp &= ~FDI_RX_ENABLE;
4376 I915_WRITE(reg, temp);
4378 /* enable CPU FDI TX and PCH FDI RX */
4379 reg = FDI_TX_CTL(pipe);
4380 temp = I915_READ(reg);
4381 temp &= ~FDI_DP_PORT_WIDTH_MASK;
4382 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4383 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
4384 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4385 temp |= snb_b_fdi_train_param[j/2];
4386 temp |= FDI_COMPOSITE_SYNC;
4387 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4389 I915_WRITE(FDI_RX_MISC(pipe),
4390 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4392 reg = FDI_RX_CTL(pipe);
4393 temp = I915_READ(reg);
4394 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4395 temp |= FDI_COMPOSITE_SYNC;
4396 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4399 udelay(1); /* should be 0.5us */
4401 for (i = 0; i < 4; i++) {
4402 reg = FDI_RX_IIR(pipe);
4403 temp = I915_READ(reg);
4404 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4406 if (temp & FDI_RX_BIT_LOCK ||
4407 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4408 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4409 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4413 udelay(1); /* should be 0.5us */
4416 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4421 reg = FDI_TX_CTL(pipe);
4422 temp = I915_READ(reg);
4423 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4424 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4425 I915_WRITE(reg, temp);
4427 reg = FDI_RX_CTL(pipe);
4428 temp = I915_READ(reg);
4429 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4430 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4431 I915_WRITE(reg, temp);
4434 udelay(2); /* should be 1.5us */
4436 for (i = 0; i < 4; i++) {
4437 reg = FDI_RX_IIR(pipe);
4438 temp = I915_READ(reg);
4439 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4441 if (temp & FDI_RX_SYMBOL_LOCK ||
4442 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4443 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4444 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4448 udelay(2); /* should be 1.5us */
4451 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
4455 DRM_DEBUG_KMS("FDI train done.\n");
4458 static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
4460 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4461 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4462 int pipe = intel_crtc->pipe;
4466 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
4467 reg = FDI_RX_CTL(pipe);
4468 temp = I915_READ(reg);
4469 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
4470 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
4471 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4472 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4477 /* Switch from Rawclk to PCDclk */
4478 temp = I915_READ(reg);
4479 I915_WRITE(reg, temp | FDI_PCDCLK);
4484 /* Enable CPU FDI TX PLL, always on for Ironlake */
4485 reg = FDI_TX_CTL(pipe);
4486 temp = I915_READ(reg);
4487 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4488 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
4495 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4497 struct drm_device *dev = intel_crtc->base.dev;
4498 struct drm_i915_private *dev_priv = to_i915(dev);
4499 int pipe = intel_crtc->pipe;
4503 /* Switch from PCDclk to Rawclk */
4504 reg = FDI_RX_CTL(pipe);
4505 temp = I915_READ(reg);
4506 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4508 /* Disable CPU FDI TX PLL */
4509 reg = FDI_TX_CTL(pipe);
4510 temp = I915_READ(reg);
4511 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4516 reg = FDI_RX_CTL(pipe);
4517 temp = I915_READ(reg);
4518 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4520 /* Wait for the clocks to turn off. */
4525 static void ironlake_fdi_disable(struct drm_crtc *crtc)
4527 struct drm_device *dev = crtc->dev;
4528 struct drm_i915_private *dev_priv = to_i915(dev);
4529 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4530 int pipe = intel_crtc->pipe;
4534 /* disable CPU FDI tx and PCH FDI rx */
4535 reg = FDI_TX_CTL(pipe);
4536 temp = I915_READ(reg);
4537 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4540 reg = FDI_RX_CTL(pipe);
4541 temp = I915_READ(reg);
4542 temp &= ~(0x7 << 16);
4543 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4544 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4549 /* Ironlake workaround, disable clock pointer after downing FDI */
4550 if (HAS_PCH_IBX(dev_priv))
4551 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4553 /* still set train pattern 1 */
4554 reg = FDI_TX_CTL(pipe);
4555 temp = I915_READ(reg);
4556 temp &= ~FDI_LINK_TRAIN_NONE;
4557 temp |= FDI_LINK_TRAIN_PATTERN_1;
4558 I915_WRITE(reg, temp);
4560 reg = FDI_RX_CTL(pipe);
4561 temp = I915_READ(reg);
4562 if (HAS_PCH_CPT(dev_priv)) {
4563 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4564 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4566 temp &= ~FDI_LINK_TRAIN_NONE;
4567 temp |= FDI_LINK_TRAIN_PATTERN_1;
4569 /* BPC in FDI rx is consistent with that in PIPECONF */
4570 temp &= ~(0x07 << 16);
4571 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
4572 I915_WRITE(reg, temp);
4578 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
4580 struct drm_crtc *crtc;
4583 drm_for_each_crtc(crtc, &dev_priv->drm) {
4584 struct drm_crtc_commit *commit;
4585 spin_lock(&crtc->commit_lock);
4586 commit = list_first_entry_or_null(&crtc->commit_list,
4587 struct drm_crtc_commit, commit_entry);
4588 cleanup_done = commit ?
4589 try_wait_for_completion(&commit->cleanup_done) : true;
4590 spin_unlock(&crtc->commit_lock);
4595 drm_crtc_wait_one_vblank(crtc);
4603 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
4607 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4609 mutex_lock(&dev_priv->sb_lock);
4611 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4612 temp |= SBI_SSCCTL_DISABLE;
4613 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4615 mutex_unlock(&dev_priv->sb_lock);
4618 /* Program iCLKIP clock to the desired frequency */
4619 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
4621 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4622 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4623 int clock = crtc_state->base.adjusted_mode.crtc_clock;
4624 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4627 lpt_disable_iclkip(dev_priv);
4629 /* The iCLK virtual clock root frequency is in MHz,
4630 * but the adjusted_mode->crtc_clock in in KHz. To get the
4631 * divisors, it is necessary to divide one by another, so we
4632 * convert the virtual clock precision to KHz here for higher
4635 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
4636 u32 iclk_virtual_root_freq = 172800 * 1000;
4637 u32 iclk_pi_range = 64;
4638 u32 desired_divisor;
4640 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4642 divsel = (desired_divisor / iclk_pi_range) - 2;
4643 phaseinc = desired_divisor % iclk_pi_range;
4646 * Near 20MHz is a corner case which is
4647 * out of range for the 7-bit divisor
4653 /* This should not happen with any sane values */
4654 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4655 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4656 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4657 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4659 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
4666 mutex_lock(&dev_priv->sb_lock);
4668 /* Program SSCDIVINTPHASE6 */
4669 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4670 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4671 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4672 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4673 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4674 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4675 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
4676 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
4678 /* Program SSCAUXDIV */
4679 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4680 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4681 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
4682 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
4684 /* Enable modulator and associated divider */
4685 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4686 temp &= ~SBI_SSCCTL_DISABLE;
4687 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4689 mutex_unlock(&dev_priv->sb_lock);
4691 /* Wait for initialization time */
4694 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4697 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4699 u32 divsel, phaseinc, auxdiv;
4700 u32 iclk_virtual_root_freq = 172800 * 1000;
4701 u32 iclk_pi_range = 64;
4702 u32 desired_divisor;
4705 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4708 mutex_lock(&dev_priv->sb_lock);
4710 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4711 if (temp & SBI_SSCCTL_DISABLE) {
4712 mutex_unlock(&dev_priv->sb_lock);
4716 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4717 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4718 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4719 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4720 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4722 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4723 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4724 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4726 mutex_unlock(&dev_priv->sb_lock);
4728 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4730 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4731 desired_divisor << auxdiv);
4734 static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
4735 enum pipe pch_transcoder)
4737 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4738 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4739 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4741 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4742 I915_READ(HTOTAL(cpu_transcoder)));
4743 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4744 I915_READ(HBLANK(cpu_transcoder)));
4745 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4746 I915_READ(HSYNC(cpu_transcoder)));
4748 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4749 I915_READ(VTOTAL(cpu_transcoder)));
4750 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4751 I915_READ(VBLANK(cpu_transcoder)));
4752 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4753 I915_READ(VSYNC(cpu_transcoder)));
4754 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4755 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4758 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
4762 temp = I915_READ(SOUTH_CHICKEN1);
4763 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
4766 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4767 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4769 temp &= ~FDI_BC_BIFURCATION_SELECT;
4771 temp |= FDI_BC_BIFURCATION_SELECT;
4773 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
4774 I915_WRITE(SOUTH_CHICKEN1, temp);
4775 POSTING_READ(SOUTH_CHICKEN1);
4778 static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
4780 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4781 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4783 switch (crtc->pipe) {
4787 if (crtc_state->fdi_lanes > 2)
4788 cpt_set_fdi_bc_bifurcation(dev_priv, false);
4790 cpt_set_fdi_bc_bifurcation(dev_priv, true);
4794 cpt_set_fdi_bc_bifurcation(dev_priv, true);
4803 * Finds the encoder associated with the given CRTC. This can only be
4804 * used when we know that the CRTC isn't feeding multiple encoders!
4806 static struct intel_encoder *
4807 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4808 const struct intel_crtc_state *crtc_state)
4810 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4811 const struct drm_connector_state *connector_state;
4812 const struct drm_connector *connector;
4813 struct intel_encoder *encoder = NULL;
4814 int num_encoders = 0;
4817 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4818 if (connector_state->crtc != &crtc->base)
4821 encoder = to_intel_encoder(connector_state->best_encoder);
4825 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4826 num_encoders, pipe_name(crtc->pipe));
4832 * Enable PCH resources required for PCH ports:
4834 * - FDI training & RX/TX
4835 * - update transcoder timings
4836 * - DP transcoding bits
4839 static void ironlake_pch_enable(const struct intel_atomic_state *state,
4840 const struct intel_crtc_state *crtc_state)
4842 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4843 struct drm_device *dev = crtc->base.dev;
4844 struct drm_i915_private *dev_priv = to_i915(dev);
4845 int pipe = crtc->pipe;
4848 assert_pch_transcoder_disabled(dev_priv, pipe);
4850 if (IS_IVYBRIDGE(dev_priv))
4851 ivybridge_update_fdi_bc_bifurcation(crtc_state);
4853 /* Write the TU size bits before fdi link training, so that error
4854 * detection works. */
4855 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4856 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4858 /* For PCH output, training FDI link */
4859 dev_priv->display.fdi_link_train(crtc, crtc_state);
4861 /* We need to program the right clock selection before writing the pixel
4862 * mutliplier into the DPLL. */
4863 if (HAS_PCH_CPT(dev_priv)) {
4866 temp = I915_READ(PCH_DPLL_SEL);
4867 temp |= TRANS_DPLL_ENABLE(pipe);
4868 sel = TRANS_DPLLB_SEL(pipe);
4869 if (crtc_state->shared_dpll ==
4870 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4874 I915_WRITE(PCH_DPLL_SEL, temp);
4877 /* XXX: pch pll's can be enabled any time before we enable the PCH
4878 * transcoder, and we actually should do this to not upset any PCH
4879 * transcoder that already use the clock when we share it.
4881 * Note that enable_shared_dpll tries to do the right thing, but
4882 * get_shared_dpll unconditionally resets the pll - we need that to have
4883 * the right LVDS enable sequence. */
4884 intel_enable_shared_dpll(crtc_state);
4886 /* set transcoder timing, panel must allow it */
4887 assert_panel_unlocked(dev_priv, pipe);
4888 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
4890 intel_fdi_normal_train(crtc);
4892 /* For PCH DP, enable TRANS_DP_CTL */
4893 if (HAS_PCH_CPT(dev_priv) &&
4894 intel_crtc_has_dp_encoder(crtc_state)) {
4895 const struct drm_display_mode *adjusted_mode =
4896 &crtc_state->base.adjusted_mode;
4897 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4898 i915_reg_t reg = TRANS_DP_CTL(pipe);
4901 temp = I915_READ(reg);
4902 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4903 TRANS_DP_SYNC_MASK |
4905 temp |= TRANS_DP_OUTPUT_ENABLE;
4906 temp |= bpc << 9; /* same format but at 11:9 */
4908 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4909 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4910 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4911 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4913 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
4914 WARN_ON(port < PORT_B || port > PORT_D);
4915 temp |= TRANS_DP_PORT_SEL(port);
4917 I915_WRITE(reg, temp);
4920 ironlake_enable_pch_transcoder(crtc_state);
4923 static void lpt_pch_enable(const struct intel_atomic_state *state,
4924 const struct intel_crtc_state *crtc_state)
4926 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4927 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4928 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4930 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4932 lpt_program_iclkip(crtc_state);
4934 /* Set transcoder timing. */
4935 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
4937 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4940 static void cpt_verify_modeset(struct drm_device *dev, int pipe)
4942 struct drm_i915_private *dev_priv = to_i915(dev);
4943 i915_reg_t dslreg = PIPEDSL(pipe);
4946 temp = I915_READ(dslreg);
4948 if (wait_for(I915_READ(dslreg) != temp, 5)) {
4949 if (wait_for(I915_READ(dslreg) != temp, 5))
4950 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
4955 * The hardware phase 0.0 refers to the center of the pixel.
4956 * We want to start from the top/left edge which is phase
4957 * -0.5. That matches how the hardware calculates the scaling
4958 * factors (from top-left of the first pixel to bottom-right
4959 * of the last pixel, as opposed to the pixel centers).
4961 * For 4:2:0 subsampled chroma planes we obviously have to
4962 * adjust that so that the chroma sample position lands in
4965 * Note that for packed YCbCr 4:2:2 formats there is no way to
4966 * control chroma siting. The hardware simply replicates the
4967 * chroma samples for both of the luma samples, and thus we don't
4968 * actually get the expected MPEG2 chroma siting convention :(
4969 * The same behaviour is observed on pre-SKL platforms as well.
4971 * Theory behind the formula (note that we ignore sub-pixel
4972 * source coordinates):
4973 * s = source sample position
4974 * d = destination sample position
4979 * | | 1.5 (initial phase)
4987 * | -0.375 (initial phase)
4994 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
4996 int phase = -0x8000;
5000 phase += (sub - 1) * 0x8000 / sub;
5002 phase += scale / (2 * sub);
5005 * Hardware initial phase limited to [-0.5:1.5].
5006 * Since the max hardware scale factor is 3.0, we
5007 * should never actually excdeed 1.0 here.
5009 WARN_ON(phase < -0x8000 || phase > 0x18000);
5012 phase = 0x10000 + phase;
5014 trip = PS_PHASE_TRIP;
5016 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5020 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
5021 unsigned int scaler_user, int *scaler_id,
5022 int src_w, int src_h, int dst_w, int dst_h,
5023 const struct drm_format_info *format, bool need_scaler)
5025 struct intel_crtc_scaler_state *scaler_state =
5026 &crtc_state->scaler_state;
5027 struct intel_crtc *intel_crtc =
5028 to_intel_crtc(crtc_state->base.crtc);
5029 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5030 const struct drm_display_mode *adjusted_mode =
5031 &crtc_state->base.adjusted_mode;
5034 * Src coordinates are already rotated by 270 degrees for
5035 * the 90/270 degree plane rotation cases (to match the
5036 * GTT mapping), hence no need to account for rotation here.
5038 if (src_w != dst_w || src_h != dst_h)
5042 * Scaling/fitting not supported in IF-ID mode in GEN9+
5043 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5044 * Once NV12 is enabled, handle it here while allocating scaler
5047 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
5048 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5049 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5054 * if plane is being disabled or scaler is no more required or force detach
5055 * - free scaler binded to this plane/crtc
5056 * - in order to do this, update crtc->scaler_usage
5058 * Here scaler state in crtc_state is set free so that
5059 * scaler can be assigned to other user. Actual register
5060 * update to free the scaler is done in plane/panel-fit programming.
5061 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5063 if (force_detach || !need_scaler) {
5064 if (*scaler_id >= 0) {
5065 scaler_state->scaler_users &= ~(1 << scaler_user);
5066 scaler_state->scalers[*scaler_id].in_use = 0;
5068 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5069 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5070 intel_crtc->pipe, scaler_user, *scaler_id,
5071 scaler_state->scaler_users);
5077 if (format && is_planar_yuv_format(format->format) &&
5078 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
5079 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
5084 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
5085 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
5086 (IS_GEN(dev_priv, 11) &&
5087 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5088 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
5089 (!IS_GEN(dev_priv, 11) &&
5090 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5091 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
5092 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
5093 "size is out of scaler range\n",
5094 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
5098 /* mark this plane as a scaler user in crtc_state */
5099 scaler_state->scaler_users |= (1 << scaler_user);
5100 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5101 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5102 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5103 scaler_state->scaler_users);
5109 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5111 * @state: crtc's scaler state
5114 * 0 - scaler_usage updated successfully
5115 * error - requested scaling cannot be supported or other error condition
5117 int skl_update_scaler_crtc(struct intel_crtc_state *state)
5119 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
5120 bool need_scaler = false;
5122 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5125 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
5126 &state->scaler_state.scaler_id,
5127 state->pipe_src_w, state->pipe_src_h,
5128 adjusted_mode->crtc_hdisplay,
5129 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
5133 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
5134 * @crtc_state: crtc's scaler state
5135 * @plane_state: atomic plane state to update
5138 * 0 - scaler_usage updated successfully
5139 * error - requested scaling cannot be supported or other error condition
5141 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5142 struct intel_plane_state *plane_state)
5144 struct intel_plane *intel_plane =
5145 to_intel_plane(plane_state->base.plane);
5146 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
5147 struct drm_framebuffer *fb = plane_state->base.fb;
5149 bool force_detach = !fb || !plane_state->base.visible;
5150 bool need_scaler = false;
5152 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
5153 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
5154 fb && is_planar_yuv_format(fb->format->format))
5157 ret = skl_update_scaler(crtc_state, force_detach,
5158 drm_plane_index(&intel_plane->base),
5159 &plane_state->scaler_id,
5160 drm_rect_width(&plane_state->base.src) >> 16,
5161 drm_rect_height(&plane_state->base.src) >> 16,
5162 drm_rect_width(&plane_state->base.dst),
5163 drm_rect_height(&plane_state->base.dst),
5164 fb ? fb->format : NULL, need_scaler);
5166 if (ret || plane_state->scaler_id < 0)
5169 /* check colorkey */
5170 if (plane_state->ckey.flags) {
5171 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5172 intel_plane->base.base.id,
5173 intel_plane->base.name);
5177 /* Check src format */
5178 switch (fb->format->format) {
5179 case DRM_FORMAT_RGB565:
5180 case DRM_FORMAT_XBGR8888:
5181 case DRM_FORMAT_XRGB8888:
5182 case DRM_FORMAT_ABGR8888:
5183 case DRM_FORMAT_ARGB8888:
5184 case DRM_FORMAT_XRGB2101010:
5185 case DRM_FORMAT_XBGR2101010:
5186 case DRM_FORMAT_YUYV:
5187 case DRM_FORMAT_YVYU:
5188 case DRM_FORMAT_UYVY:
5189 case DRM_FORMAT_VYUY:
5190 case DRM_FORMAT_NV12:
5191 case DRM_FORMAT_P010:
5192 case DRM_FORMAT_P012:
5193 case DRM_FORMAT_P016:
5194 case DRM_FORMAT_Y210:
5195 case DRM_FORMAT_Y212:
5196 case DRM_FORMAT_Y216:
5197 case DRM_FORMAT_Y410:
5198 case DRM_FORMAT_Y412:
5199 case DRM_FORMAT_Y416:
5202 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5203 intel_plane->base.base.id, intel_plane->base.name,
5204 fb->base.id, fb->format->format);
5211 static void skylake_scaler_disable(struct intel_crtc *crtc)
5215 for (i = 0; i < crtc->num_scalers; i++)
5216 skl_detach_scaler(crtc, i);
5219 static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
5221 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5222 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5223 enum pipe pipe = crtc->pipe;
5224 const struct intel_crtc_scaler_state *scaler_state =
5225 &crtc_state->scaler_state;
5227 if (crtc_state->pch_pfit.enabled) {
5228 u16 uv_rgb_hphase, uv_rgb_vphase;
5229 int pfit_w, pfit_h, hscale, vscale;
5232 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
5235 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5236 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5238 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5239 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5241 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5242 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
5244 id = scaler_state->scaler_id;
5245 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5246 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
5247 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5248 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5249 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5250 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
5251 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5252 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
5256 static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
5258 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5259 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5260 int pipe = crtc->pipe;
5262 if (crtc_state->pch_pfit.enabled) {
5263 /* Force use of hard-coded filter coefficients
5264 * as some pre-programmed values are broken,
5267 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
5268 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5269 PF_PIPE_SEL_IVB(pipe));
5271 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
5272 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5273 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
5277 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
5279 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5280 struct drm_device *dev = crtc->base.dev;
5281 struct drm_i915_private *dev_priv = to_i915(dev);
5283 if (!crtc_state->ips_enabled)
5287 * We can only enable IPS after we enable a plane and wait for a vblank
5288 * This function is called from post_plane_update, which is run after
5291 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
5293 if (IS_BROADWELL(dev_priv)) {
5294 mutex_lock(&dev_priv->pcu_lock);
5295 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5296 IPS_ENABLE | IPS_PCODE_CONTROL));
5297 mutex_unlock(&dev_priv->pcu_lock);
5298 /* Quoting Art Runyan: "its not safe to expect any particular
5299 * value in IPS_CTL bit 31 after enabling IPS through the
5300 * mailbox." Moreover, the mailbox may return a bogus state,
5301 * so we need to just enable it and continue on.
5304 I915_WRITE(IPS_CTL, IPS_ENABLE);
5305 /* The bit only becomes 1 in the next vblank, so this wait here
5306 * is essentially intel_wait_for_vblank. If we don't have this
5307 * and don't wait for vblanks until the end of crtc_enable, then
5308 * the HW state readout code will complain that the expected
5309 * IPS_CTL value is not the one we read. */
5310 if (intel_wait_for_register(dev_priv,
5311 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5313 DRM_ERROR("Timed out waiting for IPS enable\n");
5317 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
5319 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5320 struct drm_device *dev = crtc->base.dev;
5321 struct drm_i915_private *dev_priv = to_i915(dev);
5323 if (!crtc_state->ips_enabled)
5326 if (IS_BROADWELL(dev_priv)) {
5327 mutex_lock(&dev_priv->pcu_lock);
5328 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
5329 mutex_unlock(&dev_priv->pcu_lock);
5331 * Wait for PCODE to finish disabling IPS. The BSpec specified
5332 * 42ms timeout value leads to occasional timeouts so use 100ms
5335 if (intel_wait_for_register(dev_priv,
5336 IPS_CTL, IPS_ENABLE, 0,
5338 DRM_ERROR("Timed out waiting for IPS disable\n");
5340 I915_WRITE(IPS_CTL, 0);
5341 POSTING_READ(IPS_CTL);
5344 /* We need to wait for a vblank before we can disable the plane. */
5345 intel_wait_for_vblank(dev_priv, crtc->pipe);
5348 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
5350 if (intel_crtc->overlay) {
5351 struct drm_device *dev = intel_crtc->base.dev;
5353 mutex_lock(&dev->struct_mutex);
5354 (void) intel_overlay_switch_off(intel_crtc->overlay);
5355 mutex_unlock(&dev->struct_mutex);
5358 /* Let userspace switch the overlay on again. In most cases userspace
5359 * has to recompute where to put it anyway.
5364 * intel_post_enable_primary - Perform operations after enabling primary plane
5365 * @crtc: the CRTC whose primary plane was just enabled
5366 * @new_crtc_state: the enabling state
5368 * Performs potentially sleeping operations that must be done after the primary
5369 * plane is enabled, such as updating FBC and IPS. Note that this may be
5370 * called due to an explicit primary plane update, or due to an implicit
5371 * re-enable that is caused when a sprite plane is updated to no longer
5372 * completely hide the primary plane.
5375 intel_post_enable_primary(struct drm_crtc *crtc,
5376 const struct intel_crtc_state *new_crtc_state)
5378 struct drm_device *dev = crtc->dev;
5379 struct drm_i915_private *dev_priv = to_i915(dev);
5380 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5381 int pipe = intel_crtc->pipe;
5384 * Gen2 reports pipe underruns whenever all planes are disabled.
5385 * So don't enable underrun reporting before at least some planes
5387 * FIXME: Need to fix the logic to work when we turn off all planes
5388 * but leave the pipe running.
5390 if (IS_GEN(dev_priv, 2))
5391 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5393 /* Underruns don't always raise interrupts, so check manually. */
5394 intel_check_cpu_fifo_underruns(dev_priv);
5395 intel_check_pch_fifo_underruns(dev_priv);
5398 /* FIXME get rid of this and use pre_plane_update */
5400 intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5402 struct drm_device *dev = crtc->dev;
5403 struct drm_i915_private *dev_priv = to_i915(dev);
5404 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5405 int pipe = intel_crtc->pipe;
5408 * Gen2 reports pipe underruns whenever all planes are disabled.
5409 * So disable underrun reporting before all the planes get disabled.
5411 if (IS_GEN(dev_priv, 2))
5412 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5414 hsw_disable_ips(to_intel_crtc_state(crtc->state));
5417 * Vblank time updates from the shadow to live plane control register
5418 * are blocked if the memory self-refresh mode is active at that
5419 * moment. So to make sure the plane gets truly disabled, disable
5420 * first the self-refresh mode. The self-refresh enable bit in turn
5421 * will be checked/applied by the HW only at the next frame start
5422 * event which is after the vblank start event, so we need to have a
5423 * wait-for-vblank between disabling the plane and the pipe.
5425 if (HAS_GMCH(dev_priv) &&
5426 intel_set_memory_cxsr(dev_priv, false))
5427 intel_wait_for_vblank(dev_priv, pipe);
5430 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5431 const struct intel_crtc_state *new_crtc_state)
5433 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5434 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5436 if (!old_crtc_state->ips_enabled)
5439 if (needs_modeset(&new_crtc_state->base))
5443 * Workaround : Do not read or write the pipe palette/gamma data while
5444 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5446 * Disable IPS before we program the LUT.
5448 if (IS_HASWELL(dev_priv) &&
5449 (new_crtc_state->base.color_mgmt_changed ||
5450 new_crtc_state->update_pipe) &&
5451 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5454 return !new_crtc_state->ips_enabled;
5457 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5458 const struct intel_crtc_state *new_crtc_state)
5460 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5461 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5463 if (!new_crtc_state->ips_enabled)
5466 if (needs_modeset(&new_crtc_state->base))
5470 * Workaround : Do not read or write the pipe palette/gamma data while
5471 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5473 * Re-enable IPS after the LUT has been programmed.
5475 if (IS_HASWELL(dev_priv) &&
5476 (new_crtc_state->base.color_mgmt_changed ||
5477 new_crtc_state->update_pipe) &&
5478 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5482 * We can't read out IPS on broadwell, assume the worst and
5483 * forcibly enable IPS on the first fastset.
5485 if (new_crtc_state->update_pipe &&
5486 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5489 return !old_crtc_state->ips_enabled;
5492 static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5493 const struct intel_crtc_state *crtc_state)
5495 if (!crtc_state->nv12_planes)
5498 /* WA Display #0827: Gen9:all */
5499 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
5505 static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5507 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5508 struct drm_device *dev = crtc->base.dev;
5509 struct drm_i915_private *dev_priv = to_i915(dev);
5510 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5511 struct intel_crtc_state *pipe_config =
5512 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5514 struct drm_plane *primary = crtc->base.primary;
5515 struct drm_plane_state *old_primary_state =
5516 drm_atomic_get_old_plane_state(old_state, primary);
5518 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
5520 if (pipe_config->update_wm_post && pipe_config->base.active)
5521 intel_update_watermarks(crtc);
5523 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5524 hsw_enable_ips(pipe_config);
5526 if (old_primary_state) {
5527 struct drm_plane_state *new_primary_state =
5528 drm_atomic_get_new_plane_state(old_state, primary);
5530 intel_fbc_post_update(crtc);
5532 if (new_primary_state->visible &&
5533 (needs_modeset(&pipe_config->base) ||
5534 !old_primary_state->visible))
5535 intel_post_enable_primary(&crtc->base, pipe_config);
5538 /* Display WA 827 */
5539 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
5540 !needs_nv12_wa(dev_priv, pipe_config)) {
5541 skl_wa_clkgate(dev_priv, crtc->pipe, false);
5545 static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5546 struct intel_crtc_state *pipe_config)
5548 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5549 struct drm_device *dev = crtc->base.dev;
5550 struct drm_i915_private *dev_priv = to_i915(dev);
5551 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5552 struct drm_plane *primary = crtc->base.primary;
5553 struct drm_plane_state *old_primary_state =
5554 drm_atomic_get_old_plane_state(old_state, primary);
5555 bool modeset = needs_modeset(&pipe_config->base);
5556 struct intel_atomic_state *old_intel_state =
5557 to_intel_atomic_state(old_state);
5559 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5560 hsw_disable_ips(old_crtc_state);
5562 if (old_primary_state) {
5563 struct intel_plane_state *new_primary_state =
5564 intel_atomic_get_new_plane_state(old_intel_state,
5565 to_intel_plane(primary));
5567 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
5569 * Gen2 reports pipe underruns whenever all planes are disabled.
5570 * So disable underrun reporting before all the planes get disabled.
5572 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
5573 (modeset || !new_primary_state->base.visible))
5574 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5577 /* Display WA 827 */
5578 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
5579 needs_nv12_wa(dev_priv, pipe_config)) {
5580 skl_wa_clkgate(dev_priv, crtc->pipe, true);
5584 * Vblank time updates from the shadow to live plane control register
5585 * are blocked if the memory self-refresh mode is active at that
5586 * moment. So to make sure the plane gets truly disabled, disable
5587 * first the self-refresh mode. The self-refresh enable bit in turn
5588 * will be checked/applied by the HW only at the next frame start
5589 * event which is after the vblank start event, so we need to have a
5590 * wait-for-vblank between disabling the plane and the pipe.
5592 if (HAS_GMCH(dev_priv) && old_crtc_state->base.active &&
5593 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5594 intel_wait_for_vblank(dev_priv, crtc->pipe);
5597 * IVB workaround: must disable low power watermarks for at least
5598 * one frame before enabling scaling. LP watermarks can be re-enabled
5599 * when scaling is disabled.
5601 * WaCxSRDisabledForSpriteScaling:ivb
5603 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5604 old_crtc_state->base.active)
5605 intel_wait_for_vblank(dev_priv, crtc->pipe);
5608 * If we're doing a modeset, we're done. No need to do any pre-vblank
5609 * watermark programming here.
5611 if (needs_modeset(&pipe_config->base))
5615 * For platforms that support atomic watermarks, program the
5616 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5617 * will be the intermediate values that are safe for both pre- and
5618 * post- vblank; when vblank happens, the 'active' values will be set
5619 * to the final 'target' values and we'll do this again to get the
5620 * optimal watermarks. For gen9+ platforms, the values we program here
5621 * will be the final target values which will get automatically latched
5622 * at vblank time; no further programming will be necessary.
5624 * If a platform hasn't been transitioned to atomic watermarks yet,
5625 * we'll continue to update watermarks the old way, if flags tell
5628 if (dev_priv->display.initial_watermarks != NULL)
5629 dev_priv->display.initial_watermarks(old_intel_state,
5631 else if (pipe_config->update_wm_pre)
5632 intel_update_watermarks(crtc);
5635 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
5636 struct intel_crtc *crtc)
5638 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5639 const struct intel_crtc_state *new_crtc_state =
5640 intel_atomic_get_new_crtc_state(state, crtc);
5641 unsigned int update_mask = new_crtc_state->update_planes;
5642 const struct intel_plane_state *old_plane_state;
5643 struct intel_plane *plane;
5644 unsigned fb_bits = 0;
5647 intel_crtc_dpms_overlay_disable(crtc);
5649 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
5650 if (crtc->pipe != plane->pipe ||
5651 !(update_mask & BIT(plane->id)))
5654 plane->disable_plane(plane, new_crtc_state);
5656 if (old_plane_state->base.visible)
5657 fb_bits |= plane->frontbuffer_bit;
5660 intel_frontbuffer_flip(dev_priv, fb_bits);
5663 static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
5664 struct intel_crtc_state *crtc_state,
5665 struct drm_atomic_state *old_state)
5667 struct drm_connector_state *conn_state;
5668 struct drm_connector *conn;
5671 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5672 struct intel_encoder *encoder =
5673 to_intel_encoder(conn_state->best_encoder);
5675 if (conn_state->crtc != crtc)
5678 if (encoder->pre_pll_enable)
5679 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
5683 static void intel_encoders_pre_enable(struct drm_crtc *crtc,
5684 struct intel_crtc_state *crtc_state,
5685 struct drm_atomic_state *old_state)
5687 struct drm_connector_state *conn_state;
5688 struct drm_connector *conn;
5691 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5692 struct intel_encoder *encoder =
5693 to_intel_encoder(conn_state->best_encoder);
5695 if (conn_state->crtc != crtc)
5698 if (encoder->pre_enable)
5699 encoder->pre_enable(encoder, crtc_state, conn_state);
5703 static void intel_encoders_enable(struct drm_crtc *crtc,
5704 struct intel_crtc_state *crtc_state,
5705 struct drm_atomic_state *old_state)
5707 struct drm_connector_state *conn_state;
5708 struct drm_connector *conn;
5711 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5712 struct intel_encoder *encoder =
5713 to_intel_encoder(conn_state->best_encoder);
5715 if (conn_state->crtc != crtc)
5718 if (encoder->enable)
5719 encoder->enable(encoder, crtc_state, conn_state);
5720 intel_opregion_notify_encoder(encoder, true);
5724 static void intel_encoders_disable(struct drm_crtc *crtc,
5725 struct intel_crtc_state *old_crtc_state,
5726 struct drm_atomic_state *old_state)
5728 struct drm_connector_state *old_conn_state;
5729 struct drm_connector *conn;
5732 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5733 struct intel_encoder *encoder =
5734 to_intel_encoder(old_conn_state->best_encoder);
5736 if (old_conn_state->crtc != crtc)
5739 intel_opregion_notify_encoder(encoder, false);
5740 if (encoder->disable)
5741 encoder->disable(encoder, old_crtc_state, old_conn_state);
5745 static void intel_encoders_post_disable(struct drm_crtc *crtc,
5746 struct intel_crtc_state *old_crtc_state,
5747 struct drm_atomic_state *old_state)
5749 struct drm_connector_state *old_conn_state;
5750 struct drm_connector *conn;
5753 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5754 struct intel_encoder *encoder =
5755 to_intel_encoder(old_conn_state->best_encoder);
5757 if (old_conn_state->crtc != crtc)
5760 if (encoder->post_disable)
5761 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
5765 static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
5766 struct intel_crtc_state *old_crtc_state,
5767 struct drm_atomic_state *old_state)
5769 struct drm_connector_state *old_conn_state;
5770 struct drm_connector *conn;
5773 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
5774 struct intel_encoder *encoder =
5775 to_intel_encoder(old_conn_state->best_encoder);
5777 if (old_conn_state->crtc != crtc)
5780 if (encoder->post_pll_disable)
5781 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
5785 static void intel_encoders_update_pipe(struct drm_crtc *crtc,
5786 struct intel_crtc_state *crtc_state,
5787 struct drm_atomic_state *old_state)
5789 struct drm_connector_state *conn_state;
5790 struct drm_connector *conn;
5793 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5794 struct intel_encoder *encoder =
5795 to_intel_encoder(conn_state->best_encoder);
5797 if (conn_state->crtc != crtc)
5800 if (encoder->update_pipe)
5801 encoder->update_pipe(encoder, crtc_state, conn_state);
5805 static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5806 struct drm_atomic_state *old_state)
5808 struct drm_crtc *crtc = pipe_config->base.crtc;
5809 struct drm_device *dev = crtc->dev;
5810 struct drm_i915_private *dev_priv = to_i915(dev);
5811 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5812 int pipe = intel_crtc->pipe;
5813 struct intel_atomic_state *old_intel_state =
5814 to_intel_atomic_state(old_state);
5816 if (WARN_ON(intel_crtc->active))
5820 * Sometimes spurious CPU pipe underruns happen during FDI
5821 * training, at least with VGA+HDMI cloning. Suppress them.
5823 * On ILK we get an occasional spurious CPU pipe underruns
5824 * between eDP port A enable and vdd enable. Also PCH port
5825 * enable seems to result in the occasional CPU pipe underrun.
5827 * Spurious PCH underruns also occur during PCH enabling.
5829 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5830 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5832 if (pipe_config->has_pch_encoder)
5833 intel_prepare_shared_dpll(pipe_config);
5835 if (intel_crtc_has_dp_encoder(pipe_config))
5836 intel_dp_set_m_n(pipe_config, M1_N1);
5838 intel_set_pipe_timings(pipe_config);
5839 intel_set_pipe_src_size(pipe_config);
5841 if (pipe_config->has_pch_encoder) {
5842 intel_cpu_transcoder_set_m_n(pipe_config,
5843 &pipe_config->fdi_m_n, NULL);
5846 ironlake_set_pipeconf(pipe_config);
5848 intel_crtc->active = true;
5850 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5852 if (pipe_config->has_pch_encoder) {
5853 /* Note: FDI PLL enabling _must_ be done before we enable the
5854 * cpu pipes, hence this is separate from all the other fdi/pch
5856 ironlake_fdi_pll_enable(pipe_config);
5858 assert_fdi_tx_disabled(dev_priv, pipe);
5859 assert_fdi_rx_disabled(dev_priv, pipe);
5862 ironlake_pfit_enable(pipe_config);
5865 * On ILK+ LUT must be loaded before the pipe is running but with
5868 intel_color_load_luts(pipe_config);
5869 intel_color_commit(pipe_config);
5871 if (dev_priv->display.initial_watermarks != NULL)
5872 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
5873 intel_enable_pipe(pipe_config);
5875 if (pipe_config->has_pch_encoder)
5876 ironlake_pch_enable(old_intel_state, pipe_config);
5878 assert_vblank_disabled(crtc);
5879 intel_crtc_vblank_on(pipe_config);
5881 intel_encoders_enable(crtc, pipe_config, old_state);
5883 if (HAS_PCH_CPT(dev_priv))
5884 cpt_verify_modeset(dev, intel_crtc->pipe);
5887 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5888 * And a second vblank wait is needed at least on ILK with
5889 * some interlaced HDMI modes. Let's do the double wait always
5890 * in case there are more corner cases we don't know about.
5892 if (pipe_config->has_pch_encoder) {
5893 intel_wait_for_vblank(dev_priv, pipe);
5894 intel_wait_for_vblank(dev_priv, pipe);
5896 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5897 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5900 /* IPS only exists on ULT machines and is tied to pipe A. */
5901 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5903 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5906 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5907 enum pipe pipe, bool apply)
5909 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5910 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5917 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5920 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5922 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5923 enum pipe pipe = crtc->pipe;
5926 val = MBUS_DBOX_A_CREDIT(2);
5927 val |= MBUS_DBOX_BW_CREDIT(1);
5928 val |= MBUS_DBOX_B_CREDIT(8);
5930 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5933 static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5934 struct drm_atomic_state *old_state)
5936 struct drm_crtc *crtc = pipe_config->base.crtc;
5937 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
5938 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5939 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
5940 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
5941 struct intel_atomic_state *old_intel_state =
5942 to_intel_atomic_state(old_state);
5943 bool psl_clkgate_wa;
5945 if (WARN_ON(intel_crtc->active))
5948 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
5950 if (pipe_config->shared_dpll)
5951 intel_enable_shared_dpll(pipe_config);
5953 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5955 if (intel_crtc_has_dp_encoder(pipe_config))
5956 intel_dp_set_m_n(pipe_config, M1_N1);
5958 if (!transcoder_is_dsi(cpu_transcoder))
5959 intel_set_pipe_timings(pipe_config);
5961 intel_set_pipe_src_size(pipe_config);
5963 if (cpu_transcoder != TRANSCODER_EDP &&
5964 !transcoder_is_dsi(cpu_transcoder)) {
5965 I915_WRITE(PIPE_MULT(cpu_transcoder),
5966 pipe_config->pixel_multiplier - 1);
5969 if (pipe_config->has_pch_encoder) {
5970 intel_cpu_transcoder_set_m_n(pipe_config,
5971 &pipe_config->fdi_m_n, NULL);
5974 if (!transcoder_is_dsi(cpu_transcoder))
5975 haswell_set_pipeconf(pipe_config);
5977 haswell_set_pipemisc(pipe_config);
5979 intel_crtc->active = true;
5981 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5982 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5983 pipe_config->pch_pfit.enabled;
5985 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5987 if (INTEL_GEN(dev_priv) >= 9)
5988 skylake_pfit_enable(pipe_config);
5990 ironlake_pfit_enable(pipe_config);
5993 * On ILK+ LUT must be loaded before the pipe is running but with
5996 intel_color_load_luts(pipe_config);
5997 intel_color_commit(pipe_config);
5999 if (INTEL_GEN(dev_priv) >= 11)
6000 icl_set_pipe_chicken(intel_crtc);
6002 intel_ddi_set_pipe_settings(pipe_config);
6003 if (!transcoder_is_dsi(cpu_transcoder))
6004 intel_ddi_enable_transcoder_func(pipe_config);
6006 if (dev_priv->display.initial_watermarks != NULL)
6007 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
6009 if (INTEL_GEN(dev_priv) >= 11)
6010 icl_pipe_mbus_enable(intel_crtc);
6012 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6013 if (!transcoder_is_dsi(cpu_transcoder))
6014 intel_enable_pipe(pipe_config);
6016 if (pipe_config->has_pch_encoder)
6017 lpt_pch_enable(old_intel_state, pipe_config);
6019 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
6020 intel_ddi_set_vc_payload_alloc(pipe_config, true);
6022 assert_vblank_disabled(crtc);
6023 intel_crtc_vblank_on(pipe_config);
6025 intel_encoders_enable(crtc, pipe_config, old_state);
6027 if (psl_clkgate_wa) {
6028 intel_wait_for_vblank(dev_priv, pipe);
6029 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6032 /* If we change the relative order between pipe/planes enabling, we need
6033 * to change the workaround. */
6034 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
6035 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
6036 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6037 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6041 static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6043 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6044 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6045 enum pipe pipe = crtc->pipe;
6047 /* To avoid upsetting the power well on haswell only disable the pfit if
6048 * it's in use. The hw state code will make sure we get this right. */
6049 if (old_crtc_state->pch_pfit.enabled) {
6050 I915_WRITE(PF_CTL(pipe), 0);
6051 I915_WRITE(PF_WIN_POS(pipe), 0);
6052 I915_WRITE(PF_WIN_SZ(pipe), 0);
6056 static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
6057 struct drm_atomic_state *old_state)
6059 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6060 struct drm_device *dev = crtc->dev;
6061 struct drm_i915_private *dev_priv = to_i915(dev);
6062 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6063 int pipe = intel_crtc->pipe;
6066 * Sometimes spurious CPU pipe underruns happen when the
6067 * pipe is already disabled, but FDI RX/TX is still enabled.
6068 * Happens at least with VGA+HDMI cloning. Suppress them.
6070 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6071 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
6073 intel_encoders_disable(crtc, old_crtc_state, old_state);
6075 drm_crtc_vblank_off(crtc);
6076 assert_vblank_disabled(crtc);
6078 intel_disable_pipe(old_crtc_state);
6080 ironlake_pfit_disable(old_crtc_state);
6082 if (old_crtc_state->has_pch_encoder)
6083 ironlake_fdi_disable(crtc);
6085 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6087 if (old_crtc_state->has_pch_encoder) {
6088 ironlake_disable_pch_transcoder(dev_priv, pipe);
6090 if (HAS_PCH_CPT(dev_priv)) {
6094 /* disable TRANS_DP_CTL */
6095 reg = TRANS_DP_CTL(pipe);
6096 temp = I915_READ(reg);
6097 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6098 TRANS_DP_PORT_SEL_MASK);
6099 temp |= TRANS_DP_PORT_SEL_NONE;
6100 I915_WRITE(reg, temp);
6102 /* disable DPLL_SEL */
6103 temp = I915_READ(PCH_DPLL_SEL);
6104 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
6105 I915_WRITE(PCH_DPLL_SEL, temp);
6108 ironlake_fdi_pll_disable(intel_crtc);
6111 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6112 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
6115 static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
6116 struct drm_atomic_state *old_state)
6118 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6119 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6120 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6121 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
6123 intel_encoders_disable(crtc, old_crtc_state, old_state);
6125 drm_crtc_vblank_off(crtc);
6126 assert_vblank_disabled(crtc);
6128 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
6129 if (!transcoder_is_dsi(cpu_transcoder))
6130 intel_disable_pipe(old_crtc_state);
6132 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
6133 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
6135 if (!transcoder_is_dsi(cpu_transcoder))
6136 intel_ddi_disable_transcoder_func(old_crtc_state);
6138 intel_dsc_disable(old_crtc_state);
6140 if (INTEL_GEN(dev_priv) >= 9)
6141 skylake_scaler_disable(intel_crtc);
6143 ironlake_pfit_disable(old_crtc_state);
6145 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6147 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6150 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
6152 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6153 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6155 if (!crtc_state->gmch_pfit.control)
6159 * The panel fitter should only be adjusted whilst the pipe is disabled,
6160 * according to register description and PRM.
6162 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6163 assert_pipe_disabled(dev_priv, crtc->pipe);
6165 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6166 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
6168 /* Border color in case we don't scale up to the full screen. Black by
6169 * default, change to something else for debugging. */
6170 I915_WRITE(BCLRPAT(crtc->pipe), 0);
6173 bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
6175 if (port == PORT_NONE)
6178 if (IS_ICELAKE(dev_priv))
6179 return port <= PORT_B;
6184 bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
6186 if (IS_ICELAKE(dev_priv))
6187 return port >= PORT_C && port <= PORT_F;
6192 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6194 if (!intel_port_is_tc(dev_priv, port))
6195 return PORT_TC_NONE;
6197 return port - PORT_C;
6200 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
6204 return POWER_DOMAIN_PORT_DDI_A_LANES;
6206 return POWER_DOMAIN_PORT_DDI_B_LANES;
6208 return POWER_DOMAIN_PORT_DDI_C_LANES;
6210 return POWER_DOMAIN_PORT_DDI_D_LANES;
6212 return POWER_DOMAIN_PORT_DDI_E_LANES;
6214 return POWER_DOMAIN_PORT_DDI_F_LANES;
6217 return POWER_DOMAIN_PORT_OTHER;
6221 enum intel_display_power_domain
6222 intel_aux_power_domain(struct intel_digital_port *dig_port)
6224 switch (dig_port->aux_ch) {
6226 return POWER_DOMAIN_AUX_A;
6228 return POWER_DOMAIN_AUX_B;
6230 return POWER_DOMAIN_AUX_C;
6232 return POWER_DOMAIN_AUX_D;
6234 return POWER_DOMAIN_AUX_E;
6236 return POWER_DOMAIN_AUX_F;
6238 MISSING_CASE(dig_port->aux_ch);
6239 return POWER_DOMAIN_AUX_A;
6243 static u64 get_crtc_power_domains(struct drm_crtc *crtc,
6244 struct intel_crtc_state *crtc_state)
6246 struct drm_device *dev = crtc->dev;
6247 struct drm_i915_private *dev_priv = to_i915(dev);
6248 struct drm_encoder *encoder;
6249 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6250 enum pipe pipe = intel_crtc->pipe;
6252 enum transcoder transcoder = crtc_state->cpu_transcoder;
6254 if (!crtc_state->base.active)
6257 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6258 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
6259 if (crtc_state->pch_pfit.enabled ||
6260 crtc_state->pch_pfit.force_thru)
6261 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
6263 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6264 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6266 mask |= BIT_ULL(intel_encoder->power_domain);
6269 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
6270 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
6272 if (crtc_state->shared_dpll)
6273 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
6279 modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6280 struct intel_crtc_state *crtc_state)
6282 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6283 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6284 enum intel_display_power_domain domain;
6285 u64 domains, new_domains, old_domains;
6287 old_domains = intel_crtc->enabled_power_domains;
6288 intel_crtc->enabled_power_domains = new_domains =
6289 get_crtc_power_domains(crtc, crtc_state);
6291 domains = new_domains & ~old_domains;
6293 for_each_power_domain(domain, domains)
6294 intel_display_power_get(dev_priv, domain);
6296 return old_domains & ~new_domains;
6299 static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
6302 enum intel_display_power_domain domain;
6304 for_each_power_domain(domain, domains)
6305 intel_display_power_put_unchecked(dev_priv, domain);
6308 static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6309 struct drm_atomic_state *old_state)
6311 struct intel_atomic_state *old_intel_state =
6312 to_intel_atomic_state(old_state);
6313 struct drm_crtc *crtc = pipe_config->base.crtc;
6314 struct drm_device *dev = crtc->dev;
6315 struct drm_i915_private *dev_priv = to_i915(dev);
6316 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6317 int pipe = intel_crtc->pipe;
6319 if (WARN_ON(intel_crtc->active))
6322 if (intel_crtc_has_dp_encoder(pipe_config))
6323 intel_dp_set_m_n(pipe_config, M1_N1);
6325 intel_set_pipe_timings(pipe_config);
6326 intel_set_pipe_src_size(pipe_config);
6328 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
6329 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6330 I915_WRITE(CHV_CANVAS(pipe), 0);
6333 i9xx_set_pipeconf(pipe_config);
6335 intel_crtc->active = true;
6337 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6339 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
6341 if (IS_CHERRYVIEW(dev_priv)) {
6342 chv_prepare_pll(intel_crtc, pipe_config);
6343 chv_enable_pll(intel_crtc, pipe_config);
6345 vlv_prepare_pll(intel_crtc, pipe_config);
6346 vlv_enable_pll(intel_crtc, pipe_config);
6349 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6351 i9xx_pfit_enable(pipe_config);
6353 intel_color_load_luts(pipe_config);
6354 intel_color_commit(pipe_config);
6356 dev_priv->display.initial_watermarks(old_intel_state,
6358 intel_enable_pipe(pipe_config);
6360 assert_vblank_disabled(crtc);
6361 intel_crtc_vblank_on(pipe_config);
6363 intel_encoders_enable(crtc, pipe_config, old_state);
6366 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
6368 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6369 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6371 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6372 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
6375 static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6376 struct drm_atomic_state *old_state)
6378 struct intel_atomic_state *old_intel_state =
6379 to_intel_atomic_state(old_state);
6380 struct drm_crtc *crtc = pipe_config->base.crtc;
6381 struct drm_device *dev = crtc->dev;
6382 struct drm_i915_private *dev_priv = to_i915(dev);
6383 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6384 enum pipe pipe = intel_crtc->pipe;
6386 if (WARN_ON(intel_crtc->active))
6389 i9xx_set_pll_dividers(pipe_config);
6391 if (intel_crtc_has_dp_encoder(pipe_config))
6392 intel_dp_set_m_n(pipe_config, M1_N1);
6394 intel_set_pipe_timings(pipe_config);
6395 intel_set_pipe_src_size(pipe_config);
6397 i9xx_set_pipeconf(pipe_config);
6399 intel_crtc->active = true;
6401 if (!IS_GEN(dev_priv, 2))
6402 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
6404 intel_encoders_pre_enable(crtc, pipe_config, old_state);
6406 i9xx_enable_pll(intel_crtc, pipe_config);
6408 i9xx_pfit_enable(pipe_config);
6410 intel_color_load_luts(pipe_config);
6411 intel_color_commit(pipe_config);
6413 if (dev_priv->display.initial_watermarks != NULL)
6414 dev_priv->display.initial_watermarks(old_intel_state,
6417 intel_update_watermarks(intel_crtc);
6418 intel_enable_pipe(pipe_config);
6420 assert_vblank_disabled(crtc);
6421 intel_crtc_vblank_on(pipe_config);
6423 intel_encoders_enable(crtc, pipe_config, old_state);
6426 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6428 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6429 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6431 if (!old_crtc_state->gmch_pfit.control)
6434 assert_pipe_disabled(dev_priv, crtc->pipe);
6436 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6437 I915_READ(PFIT_CONTROL));
6438 I915_WRITE(PFIT_CONTROL, 0);
6441 static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6442 struct drm_atomic_state *old_state)
6444 struct drm_crtc *crtc = old_crtc_state->base.crtc;
6445 struct drm_device *dev = crtc->dev;
6446 struct drm_i915_private *dev_priv = to_i915(dev);
6447 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6448 int pipe = intel_crtc->pipe;
6451 * On gen2 planes are double buffered but the pipe isn't, so we must
6452 * wait for planes to fully turn off before disabling the pipe.
6454 if (IS_GEN(dev_priv, 2))
6455 intel_wait_for_vblank(dev_priv, pipe);
6457 intel_encoders_disable(crtc, old_crtc_state, old_state);
6459 drm_crtc_vblank_off(crtc);
6460 assert_vblank_disabled(crtc);
6462 intel_disable_pipe(old_crtc_state);
6464 i9xx_pfit_disable(old_crtc_state);
6466 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
6468 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
6469 if (IS_CHERRYVIEW(dev_priv))
6470 chv_disable_pll(dev_priv, pipe);
6471 else if (IS_VALLEYVIEW(dev_priv))
6472 vlv_disable_pll(dev_priv, pipe);
6474 i9xx_disable_pll(old_crtc_state);
6477 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
6479 if (!IS_GEN(dev_priv, 2))
6480 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6482 if (!dev_priv->display.initial_watermarks)
6483 intel_update_watermarks(intel_crtc);
6485 /* clock the pipe down to 640x480@60 to potentially save power */
6486 if (IS_I830(dev_priv))
6487 i830_enable_pipe(dev_priv, pipe);
6490 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6491 struct drm_modeset_acquire_ctx *ctx)
6493 struct intel_encoder *encoder;
6494 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6495 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
6496 enum intel_display_power_domain domain;
6497 struct intel_plane *plane;
6499 struct drm_atomic_state *state;
6500 struct intel_crtc_state *crtc_state;
6503 if (!intel_crtc->active)
6506 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6507 const struct intel_plane_state *plane_state =
6508 to_intel_plane_state(plane->base.state);
6510 if (plane_state->base.visible)
6511 intel_plane_disable_noatomic(intel_crtc, plane);
6514 state = drm_atomic_state_alloc(crtc->dev);
6516 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6517 crtc->base.id, crtc->name);
6521 state->acquire_ctx = ctx;
6523 /* Everything's already locked, -EDEADLK can't happen. */
6524 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6525 ret = drm_atomic_add_affected_connectors(state, crtc);
6527 WARN_ON(IS_ERR(crtc_state) || ret);
6529 dev_priv->display.crtc_disable(crtc_state, state);
6531 drm_atomic_state_put(state);
6533 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6534 crtc->base.id, crtc->name);
6536 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6537 crtc->state->active = false;
6538 intel_crtc->active = false;
6539 crtc->enabled = false;
6540 crtc->state->connector_mask = 0;
6541 crtc->state->encoder_mask = 0;
6543 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6544 encoder->base.crtc = NULL;
6546 intel_fbc_disable(intel_crtc);
6547 intel_update_watermarks(intel_crtc);
6548 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
6550 domains = intel_crtc->enabled_power_domains;
6551 for_each_power_domain(domain, domains)
6552 intel_display_power_put_unchecked(dev_priv, domain);
6553 intel_crtc->enabled_power_domains = 0;
6555 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
6556 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
6557 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
6561 * turn all crtc's off, but do not adjust state
6562 * This has to be paired with a call to intel_modeset_setup_hw_state.
6564 int intel_display_suspend(struct drm_device *dev)
6566 struct drm_i915_private *dev_priv = to_i915(dev);
6567 struct drm_atomic_state *state;
6570 state = drm_atomic_helper_suspend(dev);
6571 ret = PTR_ERR_OR_ZERO(state);
6573 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
6575 dev_priv->modeset_restore_state = state;
6579 void intel_encoder_destroy(struct drm_encoder *encoder)
6581 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6583 drm_encoder_cleanup(encoder);
6584 kfree(intel_encoder);
6587 /* Cross check the actual hw state with our own modeset state tracking (and it's
6588 * internal consistency). */
6589 static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6590 struct drm_connector_state *conn_state)
6592 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6594 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6595 connector->base.base.id,
6596 connector->base.name);
6598 if (connector->get_hw_state(connector)) {
6599 struct intel_encoder *encoder = connector->encoder;
6601 I915_STATE_WARN(!crtc_state,
6602 "connector enabled without attached crtc\n");
6607 I915_STATE_WARN(!crtc_state->active,
6608 "connector is active, but attached crtc isn't\n");
6610 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6613 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6614 "atomic encoder doesn't match attached encoder\n");
6616 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6617 "attached encoder crtc differs from connector crtc\n");
6619 I915_STATE_WARN(crtc_state && crtc_state->active,
6620 "attached crtc is active, but connector isn't\n");
6621 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6622 "best encoder set without crtc!\n");
6626 static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
6628 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6629 return crtc_state->fdi_lanes;
6634 static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
6635 struct intel_crtc_state *pipe_config)
6637 struct drm_i915_private *dev_priv = to_i915(dev);
6638 struct drm_atomic_state *state = pipe_config->base.state;
6639 struct intel_crtc *other_crtc;
6640 struct intel_crtc_state *other_crtc_state;
6642 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6643 pipe_name(pipe), pipe_config->fdi_lanes);
6644 if (pipe_config->fdi_lanes > 4) {
6645 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6646 pipe_name(pipe), pipe_config->fdi_lanes);
6650 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
6651 if (pipe_config->fdi_lanes > 2) {
6652 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6653 pipe_config->fdi_lanes);
6660 if (INTEL_INFO(dev_priv)->num_pipes == 2)
6663 /* Ivybridge 3 pipe is really complicated */
6668 if (pipe_config->fdi_lanes <= 2)
6671 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
6673 intel_atomic_get_crtc_state(state, other_crtc);
6674 if (IS_ERR(other_crtc_state))
6675 return PTR_ERR(other_crtc_state);
6677 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
6678 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6679 pipe_name(pipe), pipe_config->fdi_lanes);
6684 if (pipe_config->fdi_lanes > 2) {
6685 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6686 pipe_name(pipe), pipe_config->fdi_lanes);
6690 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
6692 intel_atomic_get_crtc_state(state, other_crtc);
6693 if (IS_ERR(other_crtc_state))
6694 return PTR_ERR(other_crtc_state);
6696 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
6697 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
6707 static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
6708 struct intel_crtc_state *pipe_config)
6710 struct drm_device *dev = intel_crtc->base.dev;
6711 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6712 int lane, link_bw, fdi_dotclock, ret;
6713 bool needs_recompute = false;
6716 /* FDI is a binary signal running at ~2.7GHz, encoding
6717 * each output octet as 10 bits. The actual frequency
6718 * is stored as a divider into a 100MHz clock, and the
6719 * mode pixel clock is stored in units of 1KHz.
6720 * Hence the bw of each lane in terms of the mode signal
6723 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
6725 fdi_dotclock = adjusted_mode->crtc_clock;
6727 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
6728 pipe_config->pipe_bpp);
6730 pipe_config->fdi_lanes = lane;
6732 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
6733 link_bw, &pipe_config->fdi_m_n, false);
6735 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
6736 if (ret == -EDEADLK)
6739 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
6740 pipe_config->pipe_bpp -= 2*3;
6741 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6742 pipe_config->pipe_bpp);
6743 needs_recompute = true;
6744 pipe_config->bw_constrained = true;
6749 if (needs_recompute)
6755 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6757 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6758 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6760 /* IPS only exists on ULT machines and is tied to pipe A. */
6761 if (!hsw_crtc_supports_ips(crtc))
6764 if (!i915_modparams.enable_ips)
6767 if (crtc_state->pipe_bpp > 24)
6771 * We compare against max which means we must take
6772 * the increased cdclk requirement into account when
6773 * calculating the new cdclk.
6775 * Should measure whether using a lower cdclk w/o IPS
6777 if (IS_BROADWELL(dev_priv) &&
6778 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6784 static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6786 struct drm_i915_private *dev_priv =
6787 to_i915(crtc_state->base.crtc->dev);
6788 struct intel_atomic_state *intel_state =
6789 to_intel_atomic_state(crtc_state->base.state);
6791 if (!hsw_crtc_state_ips_capable(crtc_state))
6794 if (crtc_state->ips_force_disable)
6797 /* IPS should be fine as long as at least one plane is enabled. */
6798 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6801 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6802 if (IS_BROADWELL(dev_priv) &&
6803 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6809 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6811 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6813 /* GDG double wide on either pipe, otherwise pipe A only */
6814 return INTEL_GEN(dev_priv) < 4 &&
6815 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6818 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6822 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6825 * We only use IF-ID interlacing. If we ever use
6826 * PF-ID we'll need to adjust the pixel_rate here.
6829 if (pipe_config->pch_pfit.enabled) {
6830 u64 pipe_w, pipe_h, pfit_w, pfit_h;
6831 u32 pfit_size = pipe_config->pch_pfit.size;
6833 pipe_w = pipe_config->pipe_src_w;
6834 pipe_h = pipe_config->pipe_src_h;
6836 pfit_w = (pfit_size >> 16) & 0xFFFF;
6837 pfit_h = pfit_size & 0xFFFF;
6838 if (pipe_w < pfit_w)
6840 if (pipe_h < pfit_h)
6843 if (WARN_ON(!pfit_w || !pfit_h))
6846 pixel_rate = div_u64((u64)pixel_rate * pipe_w * pipe_h,
6853 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6855 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6857 if (HAS_GMCH(dev_priv))
6858 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6859 crtc_state->pixel_rate =
6860 crtc_state->base.adjusted_mode.crtc_clock;
6862 crtc_state->pixel_rate =
6863 ilk_pipe_pixel_rate(crtc_state);
6866 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6867 struct intel_crtc_state *pipe_config)
6869 struct drm_device *dev = crtc->base.dev;
6870 struct drm_i915_private *dev_priv = to_i915(dev);
6871 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
6872 int clock_limit = dev_priv->max_dotclk_freq;
6874 if (INTEL_GEN(dev_priv) < 4) {
6875 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6878 * Enable double wide mode when the dot clock
6879 * is > 90% of the (display) core speed.
6881 if (intel_crtc_supports_double_wide(crtc) &&
6882 adjusted_mode->crtc_clock > clock_limit) {
6883 clock_limit = dev_priv->max_dotclk_freq;
6884 pipe_config->double_wide = true;
6888 if (adjusted_mode->crtc_clock > clock_limit) {
6889 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6890 adjusted_mode->crtc_clock, clock_limit,
6891 yesno(pipe_config->double_wide));
6895 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6896 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6897 pipe_config->base.ctm) {
6899 * There is only one pipe CSC unit per pipe, and we need that
6900 * for output conversion from RGB->YCBCR. So if CTM is already
6901 * applied we can't support YCBCR420 output.
6903 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6908 * Pipe horizontal size must be even in:
6910 * - LVDS dual channel mode
6911 * - Double wide pipe
6913 if (pipe_config->pipe_src_w & 1) {
6914 if (pipe_config->double_wide) {
6915 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6919 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6920 intel_is_dual_link_lvds(dev)) {
6921 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6926 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6927 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6929 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6930 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
6933 intel_crtc_compute_pixel_rate(pipe_config);
6935 if (pipe_config->has_pch_encoder)
6936 return ironlake_fdi_compute_config(crtc, pipe_config);
6942 intel_reduce_m_n_ratio(u32 *num, u32 *den)
6944 while (*num > DATA_LINK_M_N_MASK ||
6945 *den > DATA_LINK_M_N_MASK) {
6951 static void compute_m_n(unsigned int m, unsigned int n,
6952 u32 *ret_m, u32 *ret_n,
6956 * Several DP dongles in particular seem to be fussy about
6957 * too large link M/N values. Give N value as 0x8000 that
6958 * should be acceptable by specific devices. 0x8000 is the
6959 * specified fixed N value for asynchronous clock mode,
6960 * which the devices expect also in synchronous clock mode.
6965 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6967 *ret_m = div_u64((u64)m * *ret_n, n);
6968 intel_reduce_m_n_ratio(ret_m, ret_n);
6972 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
6973 int pixel_clock, int link_clock,
6974 struct intel_link_m_n *m_n,
6979 compute_m_n(bits_per_pixel * pixel_clock,
6980 link_clock * nlanes * 8,
6981 &m_n->gmch_m, &m_n->gmch_n,
6984 compute_m_n(pixel_clock, link_clock,
6985 &m_n->link_m, &m_n->link_n,
6989 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6991 if (i915_modparams.panel_use_ssc >= 0)
6992 return i915_modparams.panel_use_ssc != 0;
6993 return dev_priv->vbt.lvds_use_ssc
6994 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
6997 static u32 pnv_dpll_compute_fp(struct dpll *dpll)
6999 return (1 << dpll->n) << 16 | dpll->m2;
7002 static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
7004 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
7007 static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
7008 struct intel_crtc_state *crtc_state,
7009 struct dpll *reduced_clock)
7011 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7014 if (IS_PINEVIEW(dev_priv)) {
7015 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
7017 fp2 = pnv_dpll_compute_fp(reduced_clock);
7019 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
7021 fp2 = i9xx_dpll_compute_fp(reduced_clock);
7024 crtc_state->dpll_hw_state.fp0 = fp;
7026 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7028 crtc_state->dpll_hw_state.fp1 = fp2;
7030 crtc_state->dpll_hw_state.fp1 = fp;
7034 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7040 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7041 * and set it to a reasonable value instead.
7043 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7044 reg_val &= 0xffffff00;
7045 reg_val |= 0x00000030;
7046 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7048 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7049 reg_val &= 0x00ffffff;
7050 reg_val |= 0x8c000000;
7051 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7053 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
7054 reg_val &= 0xffffff00;
7055 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
7057 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
7058 reg_val &= 0x00ffffff;
7059 reg_val |= 0xb0000000;
7060 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
7063 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7064 const struct intel_link_m_n *m_n)
7066 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7067 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7068 enum pipe pipe = crtc->pipe;
7070 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7071 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7072 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7073 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
7076 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7077 enum transcoder transcoder)
7079 if (IS_HASWELL(dev_priv))
7080 return transcoder == TRANSCODER_EDP;
7083 * Strictly speaking some registers are available before
7084 * gen7, but we only support DRRS on gen7+
7086 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
7089 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7090 const struct intel_link_m_n *m_n,
7091 const struct intel_link_m_n *m2_n2)
7093 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7094 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7095 enum pipe pipe = crtc->pipe;
7096 enum transcoder transcoder = crtc_state->cpu_transcoder;
7098 if (INTEL_GEN(dev_priv) >= 5) {
7099 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7100 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7101 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7102 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
7104 * M2_N2 registers are set only if DRRS is supported
7105 * (to make sure the registers are not unnecessarily accessed).
7107 if (m2_n2 && crtc_state->has_drrs &&
7108 transcoder_has_m2_n2(dev_priv, transcoder)) {
7109 I915_WRITE(PIPE_DATA_M2(transcoder),
7110 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7111 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7112 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7113 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7116 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7117 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7118 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7119 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
7123 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
7125 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
7128 dp_m_n = &crtc_state->dp_m_n;
7129 dp_m2_n2 = &crtc_state->dp_m2_n2;
7130 } else if (m_n == M2_N2) {
7133 * M2_N2 registers are not supported. Hence m2_n2 divider value
7134 * needs to be programmed into M1_N1.
7136 dp_m_n = &crtc_state->dp_m2_n2;
7138 DRM_ERROR("Unsupported divider value\n");
7142 if (crtc_state->has_pch_encoder)
7143 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
7145 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
7148 static void vlv_compute_dpll(struct intel_crtc *crtc,
7149 struct intel_crtc_state *pipe_config)
7151 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
7152 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7153 if (crtc->pipe != PIPE_A)
7154 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7156 /* DPLL not used with DSI, but still need the rest set up */
7157 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7158 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7159 DPLL_EXT_BUFFER_ENABLE_VLV;
7161 pipe_config->dpll_hw_state.dpll_md =
7162 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7165 static void chv_compute_dpll(struct intel_crtc *crtc,
7166 struct intel_crtc_state *pipe_config)
7168 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
7169 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
7170 if (crtc->pipe != PIPE_A)
7171 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7173 /* DPLL not used with DSI, but still need the rest set up */
7174 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
7175 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
7177 pipe_config->dpll_hw_state.dpll_md =
7178 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7181 static void vlv_prepare_pll(struct intel_crtc *crtc,
7182 const struct intel_crtc_state *pipe_config)
7184 struct drm_device *dev = crtc->base.dev;
7185 struct drm_i915_private *dev_priv = to_i915(dev);
7186 enum pipe pipe = crtc->pipe;
7188 u32 bestn, bestm1, bestm2, bestp1, bestp2;
7189 u32 coreclk, reg_val;
7192 I915_WRITE(DPLL(pipe),
7193 pipe_config->dpll_hw_state.dpll &
7194 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7196 /* No need to actually set up the DPLL with DSI */
7197 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7200 mutex_lock(&dev_priv->sb_lock);
7202 bestn = pipe_config->dpll.n;
7203 bestm1 = pipe_config->dpll.m1;
7204 bestm2 = pipe_config->dpll.m2;
7205 bestp1 = pipe_config->dpll.p1;
7206 bestp2 = pipe_config->dpll.p2;
7208 /* See eDP HDMI DPIO driver vbios notes doc */
7210 /* PLL B needs special handling */
7212 vlv_pllb_recal_opamp(dev_priv, pipe);
7214 /* Set up Tx target for periodic Rcomp update */
7215 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
7217 /* Disable target IRef on PLL */
7218 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
7219 reg_val &= 0x00ffffff;
7220 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
7222 /* Disable fast lock */
7223 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
7225 /* Set idtafcrecal before PLL is enabled */
7226 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7227 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7228 mdiv |= ((bestn << DPIO_N_SHIFT));
7229 mdiv |= (1 << DPIO_K_SHIFT);
7232 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7233 * but we don't support that).
7234 * Note: don't use the DAC post divider as it seems unstable.
7236 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
7237 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7239 mdiv |= DPIO_ENABLE_CALIBRATION;
7240 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
7242 /* Set HBR and RBR LPF coefficients */
7243 if (pipe_config->port_clock == 162000 ||
7244 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7245 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
7246 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7249 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
7252 if (intel_crtc_has_dp_encoder(pipe_config)) {
7253 /* Use SSC source */
7255 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7258 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7260 } else { /* HDMI or VGA */
7261 /* Use bend source */
7263 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7266 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
7270 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
7271 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
7272 if (intel_crtc_has_dp_encoder(pipe_config))
7273 coreclk |= 0x01000000;
7274 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
7276 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
7277 mutex_unlock(&dev_priv->sb_lock);
7280 static void chv_prepare_pll(struct intel_crtc *crtc,
7281 const struct intel_crtc_state *pipe_config)
7283 struct drm_device *dev = crtc->base.dev;
7284 struct drm_i915_private *dev_priv = to_i915(dev);
7285 enum pipe pipe = crtc->pipe;
7286 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7287 u32 loopfilter, tribuf_calcntr;
7288 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
7292 /* Enable Refclk and SSC */
7293 I915_WRITE(DPLL(pipe),
7294 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7296 /* No need to actually set up the DPLL with DSI */
7297 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7300 bestn = pipe_config->dpll.n;
7301 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7302 bestm1 = pipe_config->dpll.m1;
7303 bestm2 = pipe_config->dpll.m2 >> 22;
7304 bestp1 = pipe_config->dpll.p1;
7305 bestp2 = pipe_config->dpll.p2;
7306 vco = pipe_config->dpll.vco;
7310 mutex_lock(&dev_priv->sb_lock);
7312 /* p1 and p2 divider */
7313 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7314 5 << DPIO_CHV_S1_DIV_SHIFT |
7315 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7316 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7317 1 << DPIO_CHV_K_DIV_SHIFT);
7319 /* Feedback post-divider - m2 */
7320 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7322 /* Feedback refclk divider - n and m1 */
7323 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7324 DPIO_CHV_M1_DIV_BY_2 |
7325 1 << DPIO_CHV_N_DIV_SHIFT);
7327 /* M2 fraction division */
7328 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
7330 /* M2 fraction division enable */
7331 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7332 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7333 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7335 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7336 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
7338 /* Program digital lock detect threshold */
7339 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7340 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7341 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7342 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7344 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7345 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7348 if (vco == 5400000) {
7349 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7350 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7351 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7352 tribuf_calcntr = 0x9;
7353 } else if (vco <= 6200000) {
7354 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7355 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7356 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7357 tribuf_calcntr = 0x9;
7358 } else if (vco <= 6480000) {
7359 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7360 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7361 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7362 tribuf_calcntr = 0x8;
7364 /* Not supported. Apply the same limits as in the max case */
7365 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7366 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7367 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7370 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7372 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
7373 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7374 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7375 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7378 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7379 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7382 mutex_unlock(&dev_priv->sb_lock);
7386 * vlv_force_pll_on - forcibly enable just the PLL
7387 * @dev_priv: i915 private structure
7388 * @pipe: pipe PLL to enable
7389 * @dpll: PLL configuration
7391 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7392 * in cases where we need the PLL enabled even when @pipe is not going to
7395 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
7396 const struct dpll *dpll)
7398 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
7399 struct intel_crtc_state *pipe_config;
7401 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7405 pipe_config->base.crtc = &crtc->base;
7406 pipe_config->pixel_multiplier = 1;
7407 pipe_config->dpll = *dpll;
7409 if (IS_CHERRYVIEW(dev_priv)) {
7410 chv_compute_dpll(crtc, pipe_config);
7411 chv_prepare_pll(crtc, pipe_config);
7412 chv_enable_pll(crtc, pipe_config);
7414 vlv_compute_dpll(crtc, pipe_config);
7415 vlv_prepare_pll(crtc, pipe_config);
7416 vlv_enable_pll(crtc, pipe_config);
7425 * vlv_force_pll_off - forcibly disable just the PLL
7426 * @dev_priv: i915 private structure
7427 * @pipe: pipe PLL to disable
7429 * Disable the PLL for @pipe. To be used in cases where we need
7430 * the PLL enabled even when @pipe is not going to be enabled.
7432 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
7434 if (IS_CHERRYVIEW(dev_priv))
7435 chv_disable_pll(dev_priv, pipe);
7437 vlv_disable_pll(dev_priv, pipe);
7440 static void i9xx_compute_dpll(struct intel_crtc *crtc,
7441 struct intel_crtc_state *crtc_state,
7442 struct dpll *reduced_clock)
7444 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7446 struct dpll *clock = &crtc_state->dpll;
7448 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7450 dpll = DPLL_VGA_MODE_DIS;
7452 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
7453 dpll |= DPLLB_MODE_LVDS;
7455 dpll |= DPLLB_MODE_DAC_SERIAL;
7457 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7458 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7459 dpll |= (crtc_state->pixel_multiplier - 1)
7460 << SDVO_MULTIPLIER_SHIFT_HIRES;
7463 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7464 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
7465 dpll |= DPLL_SDVO_HIGH_SPEED;
7467 if (intel_crtc_has_dp_encoder(crtc_state))
7468 dpll |= DPLL_SDVO_HIGH_SPEED;
7470 /* compute bitmask from p1 value */
7471 if (IS_PINEVIEW(dev_priv))
7472 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7474 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7475 if (IS_G4X(dev_priv) && reduced_clock)
7476 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7478 switch (clock->p2) {
7480 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7483 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7486 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7489 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7492 if (INTEL_GEN(dev_priv) >= 4)
7493 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7495 if (crtc_state->sdvo_tv_clock)
7496 dpll |= PLL_REF_INPUT_TVCLKINBC;
7497 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7498 intel_panel_use_ssc(dev_priv))
7499 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7501 dpll |= PLL_REF_INPUT_DREFCLK;
7503 dpll |= DPLL_VCO_ENABLE;
7504 crtc_state->dpll_hw_state.dpll = dpll;
7506 if (INTEL_GEN(dev_priv) >= 4) {
7507 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
7508 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7509 crtc_state->dpll_hw_state.dpll_md = dpll_md;
7513 static void i8xx_compute_dpll(struct intel_crtc *crtc,
7514 struct intel_crtc_state *crtc_state,
7515 struct dpll *reduced_clock)
7517 struct drm_device *dev = crtc->base.dev;
7518 struct drm_i915_private *dev_priv = to_i915(dev);
7520 struct dpll *clock = &crtc_state->dpll;
7522 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
7524 dpll = DPLL_VGA_MODE_DIS;
7526 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7527 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7530 dpll |= PLL_P1_DIVIDE_BY_TWO;
7532 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7534 dpll |= PLL_P2_DIVIDE_BY_4;
7537 if (!IS_I830(dev_priv) &&
7538 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
7539 dpll |= DPLL_DVO_2X_MODE;
7541 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
7542 intel_panel_use_ssc(dev_priv))
7543 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7545 dpll |= PLL_REF_INPUT_DREFCLK;
7547 dpll |= DPLL_VCO_ENABLE;
7548 crtc_state->dpll_hw_state.dpll = dpll;
7551 static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
7553 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7554 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7555 enum pipe pipe = crtc->pipe;
7556 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7557 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
7558 u32 crtc_vtotal, crtc_vblank_end;
7561 /* We need to be careful not to changed the adjusted mode, for otherwise
7562 * the hw state checker will get angry at the mismatch. */
7563 crtc_vtotal = adjusted_mode->crtc_vtotal;
7564 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
7566 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
7567 /* the chip adds 2 halflines automatically */
7569 crtc_vblank_end -= 1;
7571 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7572 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7574 vsyncshift = adjusted_mode->crtc_hsync_start -
7575 adjusted_mode->crtc_htotal / 2;
7577 vsyncshift += adjusted_mode->crtc_htotal;
7580 if (INTEL_GEN(dev_priv) > 3)
7581 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
7583 I915_WRITE(HTOTAL(cpu_transcoder),
7584 (adjusted_mode->crtc_hdisplay - 1) |
7585 ((adjusted_mode->crtc_htotal - 1) << 16));
7586 I915_WRITE(HBLANK(cpu_transcoder),
7587 (adjusted_mode->crtc_hblank_start - 1) |
7588 ((adjusted_mode->crtc_hblank_end - 1) << 16));
7589 I915_WRITE(HSYNC(cpu_transcoder),
7590 (adjusted_mode->crtc_hsync_start - 1) |
7591 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7593 I915_WRITE(VTOTAL(cpu_transcoder),
7594 (adjusted_mode->crtc_vdisplay - 1) |
7595 ((crtc_vtotal - 1) << 16));
7596 I915_WRITE(VBLANK(cpu_transcoder),
7597 (adjusted_mode->crtc_vblank_start - 1) |
7598 ((crtc_vblank_end - 1) << 16));
7599 I915_WRITE(VSYNC(cpu_transcoder),
7600 (adjusted_mode->crtc_vsync_start - 1) |
7601 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7603 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7604 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7605 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7607 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
7608 (pipe == PIPE_B || pipe == PIPE_C))
7609 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7613 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
7615 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7616 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7617 enum pipe pipe = crtc->pipe;
7619 /* pipesrc controls the size that is scaled from, which should
7620 * always be the user's requested size.
7622 I915_WRITE(PIPESRC(pipe),
7623 ((crtc_state->pipe_src_w - 1) << 16) |
7624 (crtc_state->pipe_src_h - 1));
7627 static void intel_get_pipe_timings(struct intel_crtc *crtc,
7628 struct intel_crtc_state *pipe_config)
7630 struct drm_device *dev = crtc->base.dev;
7631 struct drm_i915_private *dev_priv = to_i915(dev);
7632 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7635 tmp = I915_READ(HTOTAL(cpu_transcoder));
7636 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7637 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7638 tmp = I915_READ(HBLANK(cpu_transcoder));
7639 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7640 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
7641 tmp = I915_READ(HSYNC(cpu_transcoder));
7642 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7643 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7645 tmp = I915_READ(VTOTAL(cpu_transcoder));
7646 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7647 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7648 tmp = I915_READ(VBLANK(cpu_transcoder));
7649 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7650 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
7651 tmp = I915_READ(VSYNC(cpu_transcoder));
7652 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7653 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7655 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
7656 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7657 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7658 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
7662 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7663 struct intel_crtc_state *pipe_config)
7665 struct drm_device *dev = crtc->base.dev;
7666 struct drm_i915_private *dev_priv = to_i915(dev);
7669 tmp = I915_READ(PIPESRC(crtc->pipe));
7670 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7671 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7673 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7674 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
7677 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
7678 struct intel_crtc_state *pipe_config)
7680 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7681 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7682 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7683 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
7685 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7686 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7687 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7688 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
7690 mode->flags = pipe_config->base.adjusted_mode.flags;
7691 mode->type = DRM_MODE_TYPE_DRIVER;
7693 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
7695 mode->hsync = drm_mode_hsync(mode);
7696 mode->vrefresh = drm_mode_vrefresh(mode);
7697 drm_mode_set_name(mode);
7700 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
7702 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7703 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7708 /* we keep both pipes enabled on 830 */
7709 if (IS_I830(dev_priv))
7710 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
7712 if (crtc_state->double_wide)
7713 pipeconf |= PIPECONF_DOUBLE_WIDE;
7715 /* only g4x and later have fancy bpc/dither controls */
7716 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7717 IS_CHERRYVIEW(dev_priv)) {
7718 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7719 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
7720 pipeconf |= PIPECONF_DITHER_EN |
7721 PIPECONF_DITHER_TYPE_SP;
7723 switch (crtc_state->pipe_bpp) {
7725 pipeconf |= PIPECONF_6BPC;
7728 pipeconf |= PIPECONF_8BPC;
7731 pipeconf |= PIPECONF_10BPC;
7734 /* Case prevented by intel_choose_pipe_bpp_dither. */
7739 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7740 if (INTEL_GEN(dev_priv) < 4 ||
7741 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7742 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7744 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7746 pipeconf |= PIPECONF_PROGRESSIVE;
7748 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7749 crtc_state->limited_color_range)
7750 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7752 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7753 POSTING_READ(PIPECONF(crtc->pipe));
7756 static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7757 struct intel_crtc_state *crtc_state)
7759 struct drm_device *dev = crtc->base.dev;
7760 struct drm_i915_private *dev_priv = to_i915(dev);
7761 const struct intel_limit *limit;
7764 memset(&crtc_state->dpll_hw_state, 0,
7765 sizeof(crtc_state->dpll_hw_state));
7767 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7768 if (intel_panel_use_ssc(dev_priv)) {
7769 refclk = dev_priv->vbt.lvds_ssc_freq;
7770 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7773 limit = &intel_limits_i8xx_lvds;
7774 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
7775 limit = &intel_limits_i8xx_dvo;
7777 limit = &intel_limits_i8xx_dac;
7780 if (!crtc_state->clock_set &&
7781 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7782 refclk, NULL, &crtc_state->dpll)) {
7783 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7787 i8xx_compute_dpll(crtc, crtc_state, NULL);
7792 static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7793 struct intel_crtc_state *crtc_state)
7795 struct drm_device *dev = crtc->base.dev;
7796 struct drm_i915_private *dev_priv = to_i915(dev);
7797 const struct intel_limit *limit;
7800 memset(&crtc_state->dpll_hw_state, 0,
7801 sizeof(crtc_state->dpll_hw_state));
7803 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7804 if (intel_panel_use_ssc(dev_priv)) {
7805 refclk = dev_priv->vbt.lvds_ssc_freq;
7806 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7809 if (intel_is_dual_link_lvds(dev))
7810 limit = &intel_limits_g4x_dual_channel_lvds;
7812 limit = &intel_limits_g4x_single_channel_lvds;
7813 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7814 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
7815 limit = &intel_limits_g4x_hdmi;
7816 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
7817 limit = &intel_limits_g4x_sdvo;
7819 /* The option is for other outputs */
7820 limit = &intel_limits_i9xx_sdvo;
7823 if (!crtc_state->clock_set &&
7824 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7825 refclk, NULL, &crtc_state->dpll)) {
7826 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7830 i9xx_compute_dpll(crtc, crtc_state, NULL);
7835 static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7836 struct intel_crtc_state *crtc_state)
7838 struct drm_device *dev = crtc->base.dev;
7839 struct drm_i915_private *dev_priv = to_i915(dev);
7840 const struct intel_limit *limit;
7843 memset(&crtc_state->dpll_hw_state, 0,
7844 sizeof(crtc_state->dpll_hw_state));
7846 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7847 if (intel_panel_use_ssc(dev_priv)) {
7848 refclk = dev_priv->vbt.lvds_ssc_freq;
7849 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7852 limit = &intel_limits_pineview_lvds;
7854 limit = &intel_limits_pineview_sdvo;
7857 if (!crtc_state->clock_set &&
7858 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7859 refclk, NULL, &crtc_state->dpll)) {
7860 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7864 i9xx_compute_dpll(crtc, crtc_state, NULL);
7869 static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7870 struct intel_crtc_state *crtc_state)
7872 struct drm_device *dev = crtc->base.dev;
7873 struct drm_i915_private *dev_priv = to_i915(dev);
7874 const struct intel_limit *limit;
7877 memset(&crtc_state->dpll_hw_state, 0,
7878 sizeof(crtc_state->dpll_hw_state));
7880 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
7881 if (intel_panel_use_ssc(dev_priv)) {
7882 refclk = dev_priv->vbt.lvds_ssc_freq;
7883 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7886 limit = &intel_limits_i9xx_lvds;
7888 limit = &intel_limits_i9xx_sdvo;
7891 if (!crtc_state->clock_set &&
7892 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7893 refclk, NULL, &crtc_state->dpll)) {
7894 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7898 i9xx_compute_dpll(crtc, crtc_state, NULL);
7903 static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7904 struct intel_crtc_state *crtc_state)
7906 int refclk = 100000;
7907 const struct intel_limit *limit = &intel_limits_chv;
7909 memset(&crtc_state->dpll_hw_state, 0,
7910 sizeof(crtc_state->dpll_hw_state));
7912 if (!crtc_state->clock_set &&
7913 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7914 refclk, NULL, &crtc_state->dpll)) {
7915 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7919 chv_compute_dpll(crtc, crtc_state);
7924 static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7925 struct intel_crtc_state *crtc_state)
7927 int refclk = 100000;
7928 const struct intel_limit *limit = &intel_limits_vlv;
7930 memset(&crtc_state->dpll_hw_state, 0,
7931 sizeof(crtc_state->dpll_hw_state));
7933 if (!crtc_state->clock_set &&
7934 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7935 refclk, NULL, &crtc_state->dpll)) {
7936 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7940 vlv_compute_dpll(crtc, crtc_state);
7945 static void i9xx_get_pfit_config(struct intel_crtc *crtc,
7946 struct intel_crtc_state *pipe_config)
7948 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7951 if (INTEL_GEN(dev_priv) <= 3 &&
7952 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
7955 tmp = I915_READ(PFIT_CONTROL);
7956 if (!(tmp & PFIT_ENABLE))
7959 /* Check whether the pfit is attached to our pipe. */
7960 if (INTEL_GEN(dev_priv) < 4) {
7961 if (crtc->pipe != PIPE_B)
7964 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7968 pipe_config->gmch_pfit.control = tmp;
7969 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
7972 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7973 struct intel_crtc_state *pipe_config)
7975 struct drm_device *dev = crtc->base.dev;
7976 struct drm_i915_private *dev_priv = to_i915(dev);
7977 int pipe = pipe_config->cpu_transcoder;
7980 int refclk = 100000;
7982 /* In case of DSI, DPLL will not be used */
7983 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7986 mutex_lock(&dev_priv->sb_lock);
7987 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7988 mutex_unlock(&dev_priv->sb_lock);
7990 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7991 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7992 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7993 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7994 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7996 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
8000 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8001 struct intel_initial_plane_config *plane_config)
8003 struct drm_device *dev = crtc->base.dev;
8004 struct drm_i915_private *dev_priv = to_i915(dev);
8005 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8006 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
8008 u32 val, base, offset;
8009 int fourcc, pixel_format;
8010 unsigned int aligned_height;
8011 struct drm_framebuffer *fb;
8012 struct intel_framebuffer *intel_fb;
8014 if (!plane->get_hw_state(plane, &pipe))
8017 WARN_ON(pipe != crtc->pipe);
8019 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8021 DRM_DEBUG_KMS("failed to alloc fb\n");
8025 fb = &intel_fb->base;
8029 val = I915_READ(DSPCNTR(i9xx_plane));
8031 if (INTEL_GEN(dev_priv) >= 4) {
8032 if (val & DISPPLANE_TILED) {
8033 plane_config->tiling = I915_TILING_X;
8034 fb->modifier = I915_FORMAT_MOD_X_TILED;
8037 if (val & DISPPLANE_ROTATE_180)
8038 plane_config->rotation = DRM_MODE_ROTATE_180;
8041 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8042 val & DISPPLANE_MIRROR)
8043 plane_config->rotation |= DRM_MODE_REFLECT_X;
8045 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
8046 fourcc = i9xx_format_to_fourcc(pixel_format);
8047 fb->format = drm_format_info(fourcc);
8049 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8050 offset = I915_READ(DSPOFFSET(i9xx_plane));
8051 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8052 } else if (INTEL_GEN(dev_priv) >= 4) {
8053 if (plane_config->tiling)
8054 offset = I915_READ(DSPTILEOFF(i9xx_plane));
8056 offset = I915_READ(DSPLINOFF(i9xx_plane));
8057 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8059 base = I915_READ(DSPADDR(i9xx_plane));
8061 plane_config->base = base;
8063 val = I915_READ(PIPESRC(pipe));
8064 fb->width = ((val >> 16) & 0xfff) + 1;
8065 fb->height = ((val >> 0) & 0xfff) + 1;
8067 val = I915_READ(DSPSTRIDE(i9xx_plane));
8068 fb->pitches[0] = val & 0xffffffc0;
8070 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8072 plane_config->size = fb->pitches[0] * aligned_height;
8074 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8075 crtc->base.name, plane->base.name, fb->width, fb->height,
8076 fb->format->cpp[0] * 8, base, fb->pitches[0],
8077 plane_config->size);
8079 plane_config->fb = intel_fb;
8082 static void chv_crtc_clock_get(struct intel_crtc *crtc,
8083 struct intel_crtc_state *pipe_config)
8085 struct drm_device *dev = crtc->base.dev;
8086 struct drm_i915_private *dev_priv = to_i915(dev);
8087 int pipe = pipe_config->cpu_transcoder;
8088 enum dpio_channel port = vlv_pipe_to_channel(pipe);
8090 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
8091 int refclk = 100000;
8093 /* In case of DSI, DPLL will not be used */
8094 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8097 mutex_lock(&dev_priv->sb_lock);
8098 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8099 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8100 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8101 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
8102 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
8103 mutex_unlock(&dev_priv->sb_lock);
8105 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
8106 clock.m2 = (pll_dw0 & 0xff) << 22;
8107 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
8108 clock.m2 |= pll_dw2 & 0x3fffff;
8109 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8110 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8111 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8113 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
8116 static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
8117 struct intel_crtc_state *pipe_config)
8119 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8120 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
8122 pipe_config->lspcon_downsampling = false;
8124 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8125 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
8127 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
8128 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
8129 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
8131 if (ycbcr420_enabled) {
8132 /* We support 4:2:0 in full blend mode only */
8134 output = INTEL_OUTPUT_FORMAT_INVALID;
8135 else if (!(IS_GEMINILAKE(dev_priv) ||
8136 INTEL_GEN(dev_priv) >= 10))
8137 output = INTEL_OUTPUT_FORMAT_INVALID;
8139 output = INTEL_OUTPUT_FORMAT_YCBCR420;
8142 * Currently there is no interface defined to
8143 * check user preference between RGB/YCBCR444
8144 * or YCBCR420. So the only possible case for
8145 * YCBCR444 usage is driving YCBCR420 output
8146 * with LSPCON, when pipe is configured for
8147 * YCBCR444 output and LSPCON takes care of
8150 pipe_config->lspcon_downsampling = true;
8151 output = INTEL_OUTPUT_FORMAT_YCBCR444;
8156 pipe_config->output_format = output;
8159 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
8160 struct intel_crtc_state *pipe_config)
8162 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8163 enum intel_display_power_domain power_domain;
8164 intel_wakeref_t wakeref;
8168 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8169 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8173 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
8174 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8175 pipe_config->shared_dpll = NULL;
8179 tmp = I915_READ(PIPECONF(crtc->pipe));
8180 if (!(tmp & PIPECONF_ENABLE))
8183 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8184 IS_CHERRYVIEW(dev_priv)) {
8185 switch (tmp & PIPECONF_BPC_MASK) {
8187 pipe_config->pipe_bpp = 18;
8190 pipe_config->pipe_bpp = 24;
8192 case PIPECONF_10BPC:
8193 pipe_config->pipe_bpp = 30;
8200 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
8201 (tmp & PIPECONF_COLOR_RANGE_SELECT))
8202 pipe_config->limited_color_range = true;
8204 if (INTEL_GEN(dev_priv) < 4)
8205 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8207 intel_get_pipe_timings(crtc, pipe_config);
8208 intel_get_pipe_src_size(crtc, pipe_config);
8210 i9xx_get_pfit_config(crtc, pipe_config);
8212 if (INTEL_GEN(dev_priv) >= 4) {
8213 /* No way to read it out on pipes B and C */
8214 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
8215 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8217 tmp = I915_READ(DPLL_MD(crtc->pipe));
8218 pipe_config->pixel_multiplier =
8219 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8220 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
8221 pipe_config->dpll_hw_state.dpll_md = tmp;
8222 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
8223 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
8224 tmp = I915_READ(DPLL(crtc->pipe));
8225 pipe_config->pixel_multiplier =
8226 ((tmp & SDVO_MULTIPLIER_MASK)
8227 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8229 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8230 * port and will be fixed up in the encoder->get_config
8232 pipe_config->pixel_multiplier = 1;
8234 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
8235 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
8237 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8238 * on 830. Filter it out here so that we don't
8239 * report errors due to that.
8241 if (IS_I830(dev_priv))
8242 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8244 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8245 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
8247 /* Mask out read-only status bits. */
8248 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8249 DPLL_PORTC_READY_MASK |
8250 DPLL_PORTB_READY_MASK);
8253 if (IS_CHERRYVIEW(dev_priv))
8254 chv_crtc_clock_get(crtc, pipe_config);
8255 else if (IS_VALLEYVIEW(dev_priv))
8256 vlv_crtc_clock_get(crtc, pipe_config);
8258 i9xx_crtc_clock_get(crtc, pipe_config);
8261 * Normally the dotclock is filled in by the encoder .get_config()
8262 * but in case the pipe is enabled w/o any ports we need a sane
8265 pipe_config->base.adjusted_mode.crtc_clock =
8266 pipe_config->port_clock / pipe_config->pixel_multiplier;
8271 intel_display_power_put(dev_priv, power_domain, wakeref);
8276 static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
8278 struct intel_encoder *encoder;
8281 bool has_lvds = false;
8282 bool has_cpu_edp = false;
8283 bool has_panel = false;
8284 bool has_ck505 = false;
8285 bool can_ssc = false;
8286 bool using_ssc_source = false;
8288 /* We need to take the global config into account */
8289 for_each_intel_encoder(&dev_priv->drm, encoder) {
8290 switch (encoder->type) {
8291 case INTEL_OUTPUT_LVDS:
8295 case INTEL_OUTPUT_EDP:
8297 if (encoder->port == PORT_A)
8305 if (HAS_PCH_IBX(dev_priv)) {
8306 has_ck505 = dev_priv->vbt.display_clock_mode;
8307 can_ssc = has_ck505;
8313 /* Check if any DPLLs are using the SSC source */
8314 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8315 u32 temp = I915_READ(PCH_DPLL(i));
8317 if (!(temp & DPLL_VCO_ENABLE))
8320 if ((temp & PLL_REF_INPUT_MASK) ==
8321 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8322 using_ssc_source = true;
8327 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8328 has_panel, has_lvds, has_ck505, using_ssc_source);
8330 /* Ironlake: try to setup display ref clock before DPLL
8331 * enabling. This is only under driver's control after
8332 * PCH B stepping, previous chipset stepping should be
8333 * ignoring this setting.
8335 val = I915_READ(PCH_DREF_CONTROL);
8337 /* As we must carefully and slowly disable/enable each source in turn,
8338 * compute the final state we want first and check if we need to
8339 * make any changes at all.
8342 final &= ~DREF_NONSPREAD_SOURCE_MASK;
8344 final |= DREF_NONSPREAD_CK505_ENABLE;
8346 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8348 final &= ~DREF_SSC_SOURCE_MASK;
8349 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8350 final &= ~DREF_SSC1_ENABLE;
8353 final |= DREF_SSC_SOURCE_ENABLE;
8355 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8356 final |= DREF_SSC1_ENABLE;
8359 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8360 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8362 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8364 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8365 } else if (using_ssc_source) {
8366 final |= DREF_SSC_SOURCE_ENABLE;
8367 final |= DREF_SSC1_ENABLE;
8373 /* Always enable nonspread source */
8374 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8377 val |= DREF_NONSPREAD_CK505_ENABLE;
8379 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8382 val &= ~DREF_SSC_SOURCE_MASK;
8383 val |= DREF_SSC_SOURCE_ENABLE;
8385 /* SSC must be turned on before enabling the CPU output */
8386 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8387 DRM_DEBUG_KMS("Using SSC on panel\n");
8388 val |= DREF_SSC1_ENABLE;
8390 val &= ~DREF_SSC1_ENABLE;
8392 /* Get SSC going before enabling the outputs */
8393 I915_WRITE(PCH_DREF_CONTROL, val);
8394 POSTING_READ(PCH_DREF_CONTROL);
8397 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8399 /* Enable CPU source on CPU attached eDP */
8401 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
8402 DRM_DEBUG_KMS("Using SSC on eDP\n");
8403 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8405 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8407 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8409 I915_WRITE(PCH_DREF_CONTROL, val);
8410 POSTING_READ(PCH_DREF_CONTROL);
8413 DRM_DEBUG_KMS("Disabling CPU source output\n");
8415 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
8417 /* Turn off CPU output */
8418 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
8420 I915_WRITE(PCH_DREF_CONTROL, val);
8421 POSTING_READ(PCH_DREF_CONTROL);
8424 if (!using_ssc_source) {
8425 DRM_DEBUG_KMS("Disabling SSC source\n");
8427 /* Turn off the SSC source */
8428 val &= ~DREF_SSC_SOURCE_MASK;
8429 val |= DREF_SSC_SOURCE_DISABLE;
8432 val &= ~DREF_SSC1_ENABLE;
8434 I915_WRITE(PCH_DREF_CONTROL, val);
8435 POSTING_READ(PCH_DREF_CONTROL);
8440 BUG_ON(val != final);
8443 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
8447 tmp = I915_READ(SOUTH_CHICKEN2);
8448 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8449 I915_WRITE(SOUTH_CHICKEN2, tmp);
8451 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8452 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
8453 DRM_ERROR("FDI mPHY reset assert timeout\n");
8455 tmp = I915_READ(SOUTH_CHICKEN2);
8456 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8457 I915_WRITE(SOUTH_CHICKEN2, tmp);
8459 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8460 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
8461 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
8464 /* WaMPhyProgramming:hsw */
8465 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8469 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8470 tmp &= ~(0xFF << 24);
8471 tmp |= (0x12 << 24);
8472 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8474 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8476 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8478 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8480 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8482 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8483 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8484 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8486 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8487 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8488 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8490 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8493 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
8495 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8498 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
8500 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8503 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8505 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8508 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8510 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8511 tmp &= ~(0xFF << 16);
8512 tmp |= (0x1C << 16);
8513 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8515 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8516 tmp &= ~(0xFF << 16);
8517 tmp |= (0x1C << 16);
8518 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8520 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8522 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
8524 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8526 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
8528 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8529 tmp &= ~(0xF << 28);
8531 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
8533 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8534 tmp &= ~(0xF << 28);
8536 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
8539 /* Implements 3 different sequences from BSpec chapter "Display iCLK
8540 * Programming" based on the parameters passed:
8541 * - Sequence to enable CLKOUT_DP
8542 * - Sequence to enable CLKOUT_DP without spread
8543 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8545 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8546 bool with_spread, bool with_fdi)
8550 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8552 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8553 with_fdi, "LP PCH doesn't have FDI\n"))
8556 mutex_lock(&dev_priv->sb_lock);
8558 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8559 tmp &= ~SBI_SSCCTL_DISABLE;
8560 tmp |= SBI_SSCCTL_PATHALT;
8561 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8566 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8567 tmp &= ~SBI_SSCCTL_PATHALT;
8568 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8571 lpt_reset_fdi_mphy(dev_priv);
8572 lpt_program_fdi_mphy(dev_priv);
8576 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8577 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8578 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8579 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8581 mutex_unlock(&dev_priv->sb_lock);
8584 /* Sequence to disable CLKOUT_DP */
8585 static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
8589 mutex_lock(&dev_priv->sb_lock);
8591 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
8592 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8593 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8594 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8596 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8597 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8598 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8599 tmp |= SBI_SSCCTL_PATHALT;
8600 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8603 tmp |= SBI_SSCCTL_DISABLE;
8604 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8607 mutex_unlock(&dev_priv->sb_lock);
8610 #define BEND_IDX(steps) ((50 + (steps)) / 5)
8612 static const u16 sscdivintphase[] = {
8613 [BEND_IDX( 50)] = 0x3B23,
8614 [BEND_IDX( 45)] = 0x3B23,
8615 [BEND_IDX( 40)] = 0x3C23,
8616 [BEND_IDX( 35)] = 0x3C23,
8617 [BEND_IDX( 30)] = 0x3D23,
8618 [BEND_IDX( 25)] = 0x3D23,
8619 [BEND_IDX( 20)] = 0x3E23,
8620 [BEND_IDX( 15)] = 0x3E23,
8621 [BEND_IDX( 10)] = 0x3F23,
8622 [BEND_IDX( 5)] = 0x3F23,
8623 [BEND_IDX( 0)] = 0x0025,
8624 [BEND_IDX( -5)] = 0x0025,
8625 [BEND_IDX(-10)] = 0x0125,
8626 [BEND_IDX(-15)] = 0x0125,
8627 [BEND_IDX(-20)] = 0x0225,
8628 [BEND_IDX(-25)] = 0x0225,
8629 [BEND_IDX(-30)] = 0x0325,
8630 [BEND_IDX(-35)] = 0x0325,
8631 [BEND_IDX(-40)] = 0x0425,
8632 [BEND_IDX(-45)] = 0x0425,
8633 [BEND_IDX(-50)] = 0x0525,
8638 * steps -50 to 50 inclusive, in steps of 5
8639 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8640 * change in clock period = -(steps / 10) * 5.787 ps
8642 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8645 int idx = BEND_IDX(steps);
8647 if (WARN_ON(steps % 5 != 0))
8650 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8653 mutex_lock(&dev_priv->sb_lock);
8655 if (steps % 10 != 0)
8659 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8661 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8663 tmp |= sscdivintphase[idx];
8664 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8666 mutex_unlock(&dev_priv->sb_lock);
8671 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
8673 struct intel_encoder *encoder;
8674 bool has_vga = false;
8676 for_each_intel_encoder(&dev_priv->drm, encoder) {
8677 switch (encoder->type) {
8678 case INTEL_OUTPUT_ANALOG:
8687 lpt_bend_clkout_dp(dev_priv, 0);
8688 lpt_enable_clkout_dp(dev_priv, true, true);
8690 lpt_disable_clkout_dp(dev_priv);
8695 * Initialize reference clocks when the driver loads
8697 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
8699 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
8700 ironlake_init_pch_refclk(dev_priv);
8701 else if (HAS_PCH_LPT(dev_priv))
8702 lpt_init_pch_refclk(dev_priv);
8705 static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
8707 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8708 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8709 enum pipe pipe = crtc->pipe;
8714 switch (crtc_state->pipe_bpp) {
8716 val |= PIPECONF_6BPC;
8719 val |= PIPECONF_8BPC;
8722 val |= PIPECONF_10BPC;
8725 val |= PIPECONF_12BPC;
8728 /* Case prevented by intel_choose_pipe_bpp_dither. */
8732 if (crtc_state->dither)
8733 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8735 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8736 val |= PIPECONF_INTERLACED_ILK;
8738 val |= PIPECONF_PROGRESSIVE;
8740 if (crtc_state->limited_color_range)
8741 val |= PIPECONF_COLOR_RANGE_SELECT;
8743 I915_WRITE(PIPECONF(pipe), val);
8744 POSTING_READ(PIPECONF(pipe));
8747 static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
8749 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8750 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8751 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8754 if (IS_HASWELL(dev_priv) && 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 I915_WRITE(PIPECONF(cpu_transcoder), val);
8763 POSTING_READ(PIPECONF(cpu_transcoder));
8766 static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
8768 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8769 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
8771 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8774 switch (crtc_state->pipe_bpp) {
8776 val |= PIPEMISC_DITHER_6_BPC;
8779 val |= PIPEMISC_DITHER_8_BPC;
8782 val |= PIPEMISC_DITHER_10_BPC;
8785 val |= PIPEMISC_DITHER_12_BPC;
8788 /* Case prevented by pipe_config_set_bpp. */
8792 if (crtc_state->dither)
8793 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8795 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8796 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
8797 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
8799 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
8800 val |= PIPEMISC_YUV420_ENABLE |
8801 PIPEMISC_YUV420_MODE_FULL_BLEND;
8803 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
8807 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8810 * Account for spread spectrum to avoid
8811 * oversubscribing the link. Max center spread
8812 * is 2.5%; use 5% for safety's sake.
8814 u32 bps = target_clock * bpp * 21 / 20;
8815 return DIV_ROUND_UP(bps, link_bw * 8);
8818 static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
8820 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
8823 static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8824 struct intel_crtc_state *crtc_state,
8825 struct dpll *reduced_clock)
8827 struct drm_crtc *crtc = &intel_crtc->base;
8828 struct drm_device *dev = crtc->dev;
8829 struct drm_i915_private *dev_priv = to_i915(dev);
8833 /* Enable autotuning of the PLL clock (if permissible) */
8835 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8836 if ((intel_panel_use_ssc(dev_priv) &&
8837 dev_priv->vbt.lvds_ssc_freq == 100000) ||
8838 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
8840 } else if (crtc_state->sdvo_tv_clock)
8843 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
8845 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8848 if (reduced_clock) {
8849 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8851 if (reduced_clock->m < factor * reduced_clock->n)
8859 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
8860 dpll |= DPLLB_MODE_LVDS;
8862 dpll |= DPLLB_MODE_DAC_SERIAL;
8864 dpll |= (crtc_state->pixel_multiplier - 1)
8865 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
8867 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8868 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
8869 dpll |= DPLL_SDVO_HIGH_SPEED;
8871 if (intel_crtc_has_dp_encoder(crtc_state))
8872 dpll |= DPLL_SDVO_HIGH_SPEED;
8875 * The high speed IO clock is only really required for
8876 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8877 * possible to share the DPLL between CRT and HDMI. Enabling
8878 * the clock needlessly does no real harm, except use up a
8879 * bit of power potentially.
8881 * We'll limit this to IVB with 3 pipes, since it has only two
8882 * DPLLs and so DPLL sharing is the only way to get three pipes
8883 * driving PCH ports at the same time. On SNB we could do this,
8884 * and potentially avoid enabling the second DPLL, but it's not
8885 * clear if it''s a win or loss power wise. No point in doing
8886 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8888 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8889 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8890 dpll |= DPLL_SDVO_HIGH_SPEED;
8892 /* compute bitmask from p1 value */
8893 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
8895 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
8897 switch (crtc_state->dpll.p2) {
8899 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8902 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8905 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8908 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8912 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8913 intel_panel_use_ssc(dev_priv))
8914 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
8916 dpll |= PLL_REF_INPUT_DREFCLK;
8918 dpll |= DPLL_VCO_ENABLE;
8920 crtc_state->dpll_hw_state.dpll = dpll;
8921 crtc_state->dpll_hw_state.fp0 = fp;
8922 crtc_state->dpll_hw_state.fp1 = fp2;
8925 static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8926 struct intel_crtc_state *crtc_state)
8928 struct drm_device *dev = crtc->base.dev;
8929 struct drm_i915_private *dev_priv = to_i915(dev);
8930 const struct intel_limit *limit;
8931 int refclk = 120000;
8933 memset(&crtc_state->dpll_hw_state, 0,
8934 sizeof(crtc_state->dpll_hw_state));
8936 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8937 if (!crtc_state->has_pch_encoder)
8940 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
8941 if (intel_panel_use_ssc(dev_priv)) {
8942 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8943 dev_priv->vbt.lvds_ssc_freq);
8944 refclk = dev_priv->vbt.lvds_ssc_freq;
8947 if (intel_is_dual_link_lvds(dev)) {
8948 if (refclk == 100000)
8949 limit = &intel_limits_ironlake_dual_lvds_100m;
8951 limit = &intel_limits_ironlake_dual_lvds;
8953 if (refclk == 100000)
8954 limit = &intel_limits_ironlake_single_lvds_100m;
8956 limit = &intel_limits_ironlake_single_lvds;
8959 limit = &intel_limits_ironlake_dac;
8962 if (!crtc_state->clock_set &&
8963 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8964 refclk, NULL, &crtc_state->dpll)) {
8965 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8969 ironlake_compute_dpll(crtc, crtc_state, NULL);
8971 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
8972 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8973 pipe_name(crtc->pipe));
8980 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8981 struct intel_link_m_n *m_n)
8983 struct drm_device *dev = crtc->base.dev;
8984 struct drm_i915_private *dev_priv = to_i915(dev);
8985 enum pipe pipe = crtc->pipe;
8987 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8988 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8989 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8991 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8992 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8993 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8996 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8997 enum transcoder transcoder,
8998 struct intel_link_m_n *m_n,
8999 struct intel_link_m_n *m2_n2)
9001 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9002 enum pipe pipe = crtc->pipe;
9004 if (INTEL_GEN(dev_priv) >= 5) {
9005 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
9006 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
9007 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
9009 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
9010 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
9011 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9013 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
9014 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
9015 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
9016 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
9018 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
9019 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
9020 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9023 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
9024 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
9025 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
9027 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
9028 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
9029 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9033 void intel_dp_get_m_n(struct intel_crtc *crtc,
9034 struct intel_crtc_state *pipe_config)
9036 if (pipe_config->has_pch_encoder)
9037 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
9039 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9040 &pipe_config->dp_m_n,
9041 &pipe_config->dp_m2_n2);
9044 static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
9045 struct intel_crtc_state *pipe_config)
9047 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
9048 &pipe_config->fdi_m_n, NULL);
9051 static void skylake_get_pfit_config(struct intel_crtc *crtc,
9052 struct intel_crtc_state *pipe_config)
9054 struct drm_device *dev = crtc->base.dev;
9055 struct drm_i915_private *dev_priv = to_i915(dev);
9056 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
9061 /* find scaler attached to this pipe */
9062 for (i = 0; i < crtc->num_scalers; i++) {
9063 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9064 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9066 pipe_config->pch_pfit.enabled = true;
9067 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9068 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
9069 scaler_state->scalers[i].in_use = true;
9074 scaler_state->scaler_id = id;
9076 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9078 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
9083 skylake_get_initial_plane_config(struct intel_crtc *crtc,
9084 struct intel_initial_plane_config *plane_config)
9086 struct drm_device *dev = crtc->base.dev;
9087 struct drm_i915_private *dev_priv = to_i915(dev);
9088 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9089 enum plane_id plane_id = plane->id;
9091 u32 val, base, offset, stride_mult, tiling, alpha;
9092 int fourcc, pixel_format;
9093 unsigned int aligned_height;
9094 struct drm_framebuffer *fb;
9095 struct intel_framebuffer *intel_fb;
9097 if (!plane->get_hw_state(plane, &pipe))
9100 WARN_ON(pipe != crtc->pipe);
9102 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9104 DRM_DEBUG_KMS("failed to alloc fb\n");
9108 fb = &intel_fb->base;
9112 val = I915_READ(PLANE_CTL(pipe, plane_id));
9114 if (INTEL_GEN(dev_priv) >= 11)
9115 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
9117 pixel_format = val & PLANE_CTL_FORMAT_MASK;
9119 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
9120 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
9121 alpha &= PLANE_COLOR_ALPHA_MASK;
9123 alpha = val & PLANE_CTL_ALPHA_MASK;
9126 fourcc = skl_format_to_fourcc(pixel_format,
9127 val & PLANE_CTL_ORDER_RGBX, alpha);
9128 fb->format = drm_format_info(fourcc);
9130 tiling = val & PLANE_CTL_TILED_MASK;
9132 case PLANE_CTL_TILED_LINEAR:
9133 fb->modifier = DRM_FORMAT_MOD_LINEAR;
9135 case PLANE_CTL_TILED_X:
9136 plane_config->tiling = I915_TILING_X;
9137 fb->modifier = I915_FORMAT_MOD_X_TILED;
9139 case PLANE_CTL_TILED_Y:
9140 plane_config->tiling = I915_TILING_Y;
9141 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9142 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
9144 fb->modifier = I915_FORMAT_MOD_Y_TILED;
9146 case PLANE_CTL_TILED_YF:
9147 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
9148 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
9150 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
9153 MISSING_CASE(tiling);
9158 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
9159 * while i915 HW rotation is clockwise, thats why this swapping.
9161 switch (val & PLANE_CTL_ROTATE_MASK) {
9162 case PLANE_CTL_ROTATE_0:
9163 plane_config->rotation = DRM_MODE_ROTATE_0;
9165 case PLANE_CTL_ROTATE_90:
9166 plane_config->rotation = DRM_MODE_ROTATE_270;
9168 case PLANE_CTL_ROTATE_180:
9169 plane_config->rotation = DRM_MODE_ROTATE_180;
9171 case PLANE_CTL_ROTATE_270:
9172 plane_config->rotation = DRM_MODE_ROTATE_90;
9176 if (INTEL_GEN(dev_priv) >= 10 &&
9177 val & PLANE_CTL_FLIP_HORIZONTAL)
9178 plane_config->rotation |= DRM_MODE_REFLECT_X;
9180 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
9181 plane_config->base = base;
9183 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
9185 val = I915_READ(PLANE_SIZE(pipe, plane_id));
9186 fb->height = ((val >> 16) & 0xfff) + 1;
9187 fb->width = ((val >> 0) & 0x1fff) + 1;
9189 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
9190 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
9191 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9193 aligned_height = intel_fb_align_height(fb, 0, fb->height);
9195 plane_config->size = fb->pitches[0] * aligned_height;
9197 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9198 crtc->base.name, plane->base.name, fb->width, fb->height,
9199 fb->format->cpp[0] * 8, base, fb->pitches[0],
9200 plane_config->size);
9202 plane_config->fb = intel_fb;
9209 static void ironlake_get_pfit_config(struct intel_crtc *crtc,
9210 struct intel_crtc_state *pipe_config)
9212 struct drm_device *dev = crtc->base.dev;
9213 struct drm_i915_private *dev_priv = to_i915(dev);
9216 tmp = I915_READ(PF_CTL(crtc->pipe));
9218 if (tmp & PF_ENABLE) {
9219 pipe_config->pch_pfit.enabled = true;
9220 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9221 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
9223 /* We currently do not free assignements of panel fitters on
9224 * ivb/hsw (since we don't use the higher upscaling modes which
9225 * differentiates them) so just WARN about this case for now. */
9226 if (IS_GEN(dev_priv, 7)) {
9227 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9228 PF_PIPE_SEL_IVB(crtc->pipe));
9233 static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
9234 struct intel_crtc_state *pipe_config)
9236 struct drm_device *dev = crtc->base.dev;
9237 struct drm_i915_private *dev_priv = to_i915(dev);
9238 enum intel_display_power_domain power_domain;
9239 intel_wakeref_t wakeref;
9243 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9244 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9248 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9249 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9250 pipe_config->shared_dpll = NULL;
9253 tmp = I915_READ(PIPECONF(crtc->pipe));
9254 if (!(tmp & PIPECONF_ENABLE))
9257 switch (tmp & PIPECONF_BPC_MASK) {
9259 pipe_config->pipe_bpp = 18;
9262 pipe_config->pipe_bpp = 24;
9264 case PIPECONF_10BPC:
9265 pipe_config->pipe_bpp = 30;
9267 case PIPECONF_12BPC:
9268 pipe_config->pipe_bpp = 36;
9274 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9275 pipe_config->limited_color_range = true;
9277 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
9278 struct intel_shared_dpll *pll;
9279 enum intel_dpll_id pll_id;
9281 pipe_config->has_pch_encoder = true;
9283 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9284 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9285 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9287 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9289 if (HAS_PCH_IBX(dev_priv)) {
9291 * The pipe->pch transcoder and pch transcoder->pll
9294 pll_id = (enum intel_dpll_id) crtc->pipe;
9296 tmp = I915_READ(PCH_DPLL_SEL);
9297 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
9298 pll_id = DPLL_ID_PCH_PLL_B;
9300 pll_id= DPLL_ID_PCH_PLL_A;
9303 pipe_config->shared_dpll =
9304 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9305 pll = pipe_config->shared_dpll;
9307 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9308 &pipe_config->dpll_hw_state));
9310 tmp = pipe_config->dpll_hw_state.dpll;
9311 pipe_config->pixel_multiplier =
9312 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9313 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
9315 ironlake_pch_clock_get(crtc, pipe_config);
9317 pipe_config->pixel_multiplier = 1;
9320 intel_get_pipe_timings(crtc, pipe_config);
9321 intel_get_pipe_src_size(crtc, pipe_config);
9323 ironlake_get_pfit_config(crtc, pipe_config);
9328 intel_display_power_put(dev_priv, power_domain, wakeref);
9333 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9335 struct drm_device *dev = &dev_priv->drm;
9336 struct intel_crtc *crtc;
9338 for_each_intel_crtc(dev, crtc)
9339 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
9340 pipe_name(crtc->pipe));
9342 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
9343 "Display power well on\n");
9344 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
9345 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9346 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
9347 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
9348 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
9349 "CPU PWM1 enabled\n");
9350 if (IS_HASWELL(dev_priv))
9351 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
9352 "CPU PWM2 enabled\n");
9353 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
9354 "PCH PWM1 enabled\n");
9355 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
9356 "Utility pin enabled\n");
9357 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
9360 * In theory we can still leave IRQs enabled, as long as only the HPD
9361 * interrupts remain enabled. We used to check for that, but since it's
9362 * gen-specific and since we only disable LCPLL after we fully disable
9363 * the interrupts, the check below should be enough.
9365 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
9368 static u32 hsw_read_dcomp(struct drm_i915_private *dev_priv)
9370 if (IS_HASWELL(dev_priv))
9371 return I915_READ(D_COMP_HSW);
9373 return I915_READ(D_COMP_BDW);
9376 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, u32 val)
9378 if (IS_HASWELL(dev_priv)) {
9379 mutex_lock(&dev_priv->pcu_lock);
9380 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9382 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
9383 mutex_unlock(&dev_priv->pcu_lock);
9385 I915_WRITE(D_COMP_BDW, val);
9386 POSTING_READ(D_COMP_BDW);
9391 * This function implements pieces of two sequences from BSpec:
9392 * - Sequence for display software to disable LCPLL
9393 * - Sequence for display software to allow package C8+
9394 * The steps implemented here are just the steps that actually touch the LCPLL
9395 * register. Callers should take care of disabling all the display engine
9396 * functions, doing the mode unset, fixing interrupts, etc.
9398 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9399 bool switch_to_fclk, bool allow_power_down)
9403 assert_can_disable_lcpll(dev_priv);
9405 val = I915_READ(LCPLL_CTL);
9407 if (switch_to_fclk) {
9408 val |= LCPLL_CD_SOURCE_FCLK;
9409 I915_WRITE(LCPLL_CTL, val);
9411 if (wait_for_us(I915_READ(LCPLL_CTL) &
9412 LCPLL_CD_SOURCE_FCLK_DONE, 1))
9413 DRM_ERROR("Switching to FCLK failed\n");
9415 val = I915_READ(LCPLL_CTL);
9418 val |= LCPLL_PLL_DISABLE;
9419 I915_WRITE(LCPLL_CTL, val);
9420 POSTING_READ(LCPLL_CTL);
9422 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
9423 DRM_ERROR("LCPLL still locked\n");
9425 val = hsw_read_dcomp(dev_priv);
9426 val |= D_COMP_COMP_DISABLE;
9427 hsw_write_dcomp(dev_priv, val);
9430 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9432 DRM_ERROR("D_COMP RCOMP still in progress\n");
9434 if (allow_power_down) {
9435 val = I915_READ(LCPLL_CTL);
9436 val |= LCPLL_POWER_DOWN_ALLOW;
9437 I915_WRITE(LCPLL_CTL, val);
9438 POSTING_READ(LCPLL_CTL);
9443 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9446 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
9450 val = I915_READ(LCPLL_CTL);
9452 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9453 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9457 * Make sure we're not on PC8 state before disabling PC8, otherwise
9458 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
9460 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
9462 if (val & LCPLL_POWER_DOWN_ALLOW) {
9463 val &= ~LCPLL_POWER_DOWN_ALLOW;
9464 I915_WRITE(LCPLL_CTL, val);
9465 POSTING_READ(LCPLL_CTL);
9468 val = hsw_read_dcomp(dev_priv);
9469 val |= D_COMP_COMP_FORCE;
9470 val &= ~D_COMP_COMP_DISABLE;
9471 hsw_write_dcomp(dev_priv, val);
9473 val = I915_READ(LCPLL_CTL);
9474 val &= ~LCPLL_PLL_DISABLE;
9475 I915_WRITE(LCPLL_CTL, val);
9477 if (intel_wait_for_register(dev_priv,
9478 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9480 DRM_ERROR("LCPLL not locked yet\n");
9482 if (val & LCPLL_CD_SOURCE_FCLK) {
9483 val = I915_READ(LCPLL_CTL);
9484 val &= ~LCPLL_CD_SOURCE_FCLK;
9485 I915_WRITE(LCPLL_CTL, val);
9487 if (wait_for_us((I915_READ(LCPLL_CTL) &
9488 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
9489 DRM_ERROR("Switching back to LCPLL failed\n");
9492 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
9494 intel_update_cdclk(dev_priv);
9495 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
9499 * Package states C8 and deeper are really deep PC states that can only be
9500 * reached when all the devices on the system allow it, so even if the graphics
9501 * device allows PC8+, it doesn't mean the system will actually get to these
9502 * states. Our driver only allows PC8+ when going into runtime PM.
9504 * The requirements for PC8+ are that all the outputs are disabled, the power
9505 * well is disabled and most interrupts are disabled, and these are also
9506 * requirements for runtime PM. When these conditions are met, we manually do
9507 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9508 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9511 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9512 * the state of some registers, so when we come back from PC8+ we need to
9513 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9514 * need to take care of the registers kept by RC6. Notice that this happens even
9515 * if we don't put the device in PCI D3 state (which is what currently happens
9516 * because of the runtime PM support).
9518 * For more, read "Display Sequences for Package C8" on the hardware
9521 void hsw_enable_pc8(struct drm_i915_private *dev_priv)
9525 DRM_DEBUG_KMS("Enabling package C8+\n");
9527 if (HAS_PCH_LPT_LP(dev_priv)) {
9528 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9529 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9530 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9533 lpt_disable_clkout_dp(dev_priv);
9534 hsw_disable_lcpll(dev_priv, true, true);
9537 void hsw_disable_pc8(struct drm_i915_private *dev_priv)
9541 DRM_DEBUG_KMS("Disabling package C8+\n");
9543 hsw_restore_lcpll(dev_priv);
9544 lpt_init_pch_refclk(dev_priv);
9546 if (HAS_PCH_LPT_LP(dev_priv)) {
9547 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9548 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9549 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9553 static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9554 struct intel_crtc_state *crtc_state)
9556 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9557 struct intel_atomic_state *state =
9558 to_intel_atomic_state(crtc_state->base.state);
9560 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
9561 IS_ICELAKE(dev_priv)) {
9562 struct intel_encoder *encoder =
9563 intel_get_crtc_new_encoder(state, crtc_state);
9565 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
9566 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9567 pipe_name(crtc->pipe));
9575 static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9577 struct intel_crtc_state *pipe_config)
9579 enum intel_dpll_id id;
9582 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9583 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9585 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9588 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9591 static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9593 struct intel_crtc_state *pipe_config)
9595 enum intel_dpll_id id;
9598 /* TODO: TBT pll not implemented. */
9599 if (intel_port_is_combophy(dev_priv, port)) {
9600 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9601 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9602 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9604 if (WARN_ON(!intel_dpll_is_combophy(id)))
9606 } else if (intel_port_is_tc(dev_priv, port)) {
9607 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv, port));
9609 WARN(1, "Invalid port %x\n", port);
9613 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9616 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9618 struct intel_crtc_state *pipe_config)
9620 enum intel_dpll_id id;
9624 id = DPLL_ID_SKL_DPLL0;
9627 id = DPLL_ID_SKL_DPLL1;
9630 id = DPLL_ID_SKL_DPLL2;
9633 DRM_ERROR("Incorrect port type\n");
9637 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9640 static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9642 struct intel_crtc_state *pipe_config)
9644 enum intel_dpll_id id;
9647 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
9648 id = temp >> (port * 3 + 1);
9650 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
9653 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9656 static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9658 struct intel_crtc_state *pipe_config)
9660 enum intel_dpll_id id;
9661 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
9663 switch (ddi_pll_sel) {
9664 case PORT_CLK_SEL_WRPLL1:
9665 id = DPLL_ID_WRPLL1;
9667 case PORT_CLK_SEL_WRPLL2:
9668 id = DPLL_ID_WRPLL2;
9670 case PORT_CLK_SEL_SPLL:
9673 case PORT_CLK_SEL_LCPLL_810:
9674 id = DPLL_ID_LCPLL_810;
9676 case PORT_CLK_SEL_LCPLL_1350:
9677 id = DPLL_ID_LCPLL_1350;
9679 case PORT_CLK_SEL_LCPLL_2700:
9680 id = DPLL_ID_LCPLL_2700;
9683 MISSING_CASE(ddi_pll_sel);
9685 case PORT_CLK_SEL_NONE:
9689 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9692 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9693 struct intel_crtc_state *pipe_config,
9694 u64 *power_domain_mask)
9696 struct drm_device *dev = crtc->base.dev;
9697 struct drm_i915_private *dev_priv = to_i915(dev);
9698 enum intel_display_power_domain power_domain;
9699 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
9700 unsigned long enabled_panel_transcoders = 0;
9701 enum transcoder panel_transcoder;
9704 if (IS_ICELAKE(dev_priv))
9705 panel_transcoder_mask |=
9706 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
9709 * The pipe->transcoder mapping is fixed with the exception of the eDP
9710 * and DSI transcoders handled below.
9712 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9715 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9716 * consistency and less surprising code; it's in always on power).
9718 for_each_set_bit(panel_transcoder,
9719 &panel_transcoder_mask,
9720 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
9721 enum pipe trans_pipe;
9723 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
9724 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
9728 * Log all enabled ones, only use the first one.
9730 * FIXME: This won't work for two separate DSI displays.
9732 enabled_panel_transcoders |= BIT(panel_transcoder);
9733 if (enabled_panel_transcoders != BIT(panel_transcoder))
9736 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9738 WARN(1, "unknown pipe linked to transcoder %s\n",
9739 transcoder_name(panel_transcoder));
9741 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9742 case TRANS_DDI_EDP_INPUT_A_ON:
9743 trans_pipe = PIPE_A;
9745 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9746 trans_pipe = PIPE_B;
9748 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9749 trans_pipe = PIPE_C;
9753 if (trans_pipe == crtc->pipe)
9754 pipe_config->cpu_transcoder = panel_transcoder;
9758 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
9760 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
9761 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
9763 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9764 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9767 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
9768 *power_domain_mask |= BIT_ULL(power_domain);
9770 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9772 return tmp & PIPECONF_ENABLE;
9775 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9776 struct intel_crtc_state *pipe_config,
9777 u64 *power_domain_mask)
9779 struct drm_device *dev = crtc->base.dev;
9780 struct drm_i915_private *dev_priv = to_i915(dev);
9781 enum intel_display_power_domain power_domain;
9783 enum transcoder cpu_transcoder;
9786 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9788 cpu_transcoder = TRANSCODER_DSI_A;
9790 cpu_transcoder = TRANSCODER_DSI_C;
9792 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9793 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9796 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
9797 *power_domain_mask |= BIT_ULL(power_domain);
9800 * The PLL needs to be enabled with a valid divider
9801 * configuration, otherwise accessing DSI registers will hang
9802 * the machine. See BSpec North Display Engine
9803 * registers/MIPI[BXT]. We can break out here early, since we
9804 * need the same DSI PLL to be enabled for both DSI ports.
9806 if (!bxt_dsi_pll_is_enabled(dev_priv))
9809 /* XXX: this works for video mode only */
9810 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9811 if (!(tmp & DPI_ENABLE))
9814 tmp = I915_READ(MIPI_CTRL(port));
9815 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9818 pipe_config->cpu_transcoder = cpu_transcoder;
9822 return transcoder_is_dsi(pipe_config->cpu_transcoder);
9825 static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
9826 struct intel_crtc_state *pipe_config)
9828 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9829 struct intel_shared_dpll *pll;
9833 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9835 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9837 if (IS_ICELAKE(dev_priv))
9838 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9839 else if (IS_CANNONLAKE(dev_priv))
9840 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9841 else if (IS_GEN9_BC(dev_priv))
9842 skylake_get_ddi_pll(dev_priv, port, pipe_config);
9843 else if (IS_GEN9_LP(dev_priv))
9844 bxt_get_ddi_pll(dev_priv, port, pipe_config);
9846 haswell_get_ddi_pll(dev_priv, port, pipe_config);
9848 pll = pipe_config->shared_dpll;
9850 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9851 &pipe_config->dpll_hw_state));
9855 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9856 * DDI E. So just check whether this pipe is wired to DDI E and whether
9857 * the PCH transcoder is on.
9859 if (INTEL_GEN(dev_priv) < 9 &&
9860 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
9861 pipe_config->has_pch_encoder = true;
9863 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9864 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9865 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9867 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9871 static bool haswell_get_pipe_config(struct intel_crtc *crtc,
9872 struct intel_crtc_state *pipe_config)
9874 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9875 enum intel_display_power_domain power_domain;
9876 u64 power_domain_mask;
9879 intel_crtc_init_scalers(crtc, pipe_config);
9881 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9882 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9884 power_domain_mask = BIT_ULL(power_domain);
9886 pipe_config->shared_dpll = NULL;
9888 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
9890 if (IS_GEN9_LP(dev_priv) &&
9891 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9899 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
9900 IS_ICELAKE(dev_priv)) {
9901 haswell_get_ddi_port_state(crtc, pipe_config);
9902 intel_get_pipe_timings(crtc, pipe_config);
9905 intel_get_pipe_src_size(crtc, pipe_config);
9906 intel_get_crtc_ycbcr_config(crtc, pipe_config);
9908 pipe_config->gamma_mode =
9909 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9911 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9912 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
9913 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
9914 power_domain_mask |= BIT_ULL(power_domain);
9916 if (INTEL_GEN(dev_priv) >= 9)
9917 skylake_get_pfit_config(crtc, pipe_config);
9919 ironlake_get_pfit_config(crtc, pipe_config);
9922 if (hsw_crtc_supports_ips(crtc)) {
9923 if (IS_HASWELL(dev_priv))
9924 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9927 * We cannot readout IPS state on broadwell, set to
9928 * true so we can set it to a defined state on first
9931 pipe_config->ips_enabled = true;
9935 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9936 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9937 pipe_config->pixel_multiplier =
9938 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9940 pipe_config->pixel_multiplier = 1;
9944 for_each_power_domain(power_domain, power_domain_mask)
9945 intel_display_power_put_unchecked(dev_priv, power_domain);
9950 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
9952 struct drm_i915_private *dev_priv =
9953 to_i915(plane_state->base.plane->dev);
9954 const struct drm_framebuffer *fb = plane_state->base.fb;
9955 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9958 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
9959 base = obj->phys_handle->busaddr;
9961 base = intel_plane_ggtt_offset(plane_state);
9963 base += plane_state->color_plane[0].offset;
9965 /* ILK+ do this automagically */
9966 if (HAS_GMCH(dev_priv) &&
9967 plane_state->base.rotation & DRM_MODE_ROTATE_180)
9968 base += (plane_state->base.crtc_h *
9969 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9974 static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9976 int x = plane_state->base.crtc_x;
9977 int y = plane_state->base.crtc_y;
9981 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9984 pos |= x << CURSOR_X_SHIFT;
9987 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9990 pos |= y << CURSOR_Y_SHIFT;
9995 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9997 const struct drm_mode_config *config =
9998 &plane_state->base.plane->dev->mode_config;
9999 int width = plane_state->base.crtc_w;
10000 int height = plane_state->base.crtc_h;
10002 return width > 0 && width <= config->cursor_width &&
10003 height > 0 && height <= config->cursor_height;
10006 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
10008 const struct drm_framebuffer *fb = plane_state->base.fb;
10009 unsigned int rotation = plane_state->base.rotation;
10014 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
10015 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
10017 ret = intel_plane_check_stride(plane_state);
10021 src_x = plane_state->base.src_x >> 16;
10022 src_y = plane_state->base.src_y >> 16;
10024 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
10025 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
10028 if (src_x != 0 || src_y != 0) {
10029 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
10033 plane_state->color_plane[0].offset = offset;
10038 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
10039 struct intel_plane_state *plane_state)
10041 const struct drm_framebuffer *fb = plane_state->base.fb;
10044 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
10045 DRM_DEBUG_KMS("cursor cannot be tiled\n");
10049 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
10051 DRM_PLANE_HELPER_NO_SCALING,
10052 DRM_PLANE_HELPER_NO_SCALING,
10057 if (!plane_state->base.visible)
10060 ret = intel_plane_check_src_coordinates(plane_state);
10064 ret = intel_cursor_check_surface(plane_state);
10071 static unsigned int
10072 i845_cursor_max_stride(struct intel_plane *plane,
10073 u32 pixel_format, u64 modifier,
10074 unsigned int rotation)
10079 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10081 return CURSOR_GAMMA_ENABLE;
10084 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
10085 const struct intel_plane_state *plane_state)
10087 return CURSOR_ENABLE |
10088 CURSOR_FORMAT_ARGB |
10089 CURSOR_STRIDE(plane_state->color_plane[0].stride);
10092 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
10094 int width = plane_state->base.crtc_w;
10097 * 845g/865g are only limited by the width of their cursors,
10098 * the height is arbitrary up to the precision of the register.
10100 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
10103 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
10104 struct intel_plane_state *plane_state)
10106 const struct drm_framebuffer *fb = plane_state->base.fb;
10109 ret = intel_check_cursor(crtc_state, plane_state);
10113 /* if we want to turn off the cursor ignore width and height */
10117 /* Check for which cursor types we support */
10118 if (!i845_cursor_size_ok(plane_state)) {
10119 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10120 plane_state->base.crtc_w,
10121 plane_state->base.crtc_h);
10125 WARN_ON(plane_state->base.visible &&
10126 plane_state->color_plane[0].stride != fb->pitches[0]);
10128 switch (fb->pitches[0]) {
10135 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
10140 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
10145 static void i845_update_cursor(struct intel_plane *plane,
10146 const struct intel_crtc_state *crtc_state,
10147 const struct intel_plane_state *plane_state)
10149 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10150 u32 cntl = 0, base = 0, pos = 0, size = 0;
10151 unsigned long irqflags;
10153 if (plane_state && plane_state->base.visible) {
10154 unsigned int width = plane_state->base.crtc_w;
10155 unsigned int height = plane_state->base.crtc_h;
10157 cntl = plane_state->ctl |
10158 i845_cursor_ctl_crtc(crtc_state);
10160 size = (height << 12) | width;
10162 base = intel_cursor_base(plane_state);
10163 pos = intel_cursor_position(plane_state);
10166 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10168 /* On these chipsets we can only modify the base/size/stride
10169 * whilst the cursor is disabled.
10171 if (plane->cursor.base != base ||
10172 plane->cursor.size != size ||
10173 plane->cursor.cntl != cntl) {
10174 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
10175 I915_WRITE_FW(CURBASE(PIPE_A), base);
10176 I915_WRITE_FW(CURSIZE, size);
10177 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10178 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
10180 plane->cursor.base = base;
10181 plane->cursor.size = size;
10182 plane->cursor.cntl = cntl;
10184 I915_WRITE_FW(CURPOS(PIPE_A), pos);
10187 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10190 static void i845_disable_cursor(struct intel_plane *plane,
10191 const struct intel_crtc_state *crtc_state)
10193 i845_update_cursor(plane, crtc_state, NULL);
10196 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
10199 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10200 enum intel_display_power_domain power_domain;
10201 intel_wakeref_t wakeref;
10204 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
10205 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10209 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
10213 intel_display_power_put(dev_priv, power_domain, wakeref);
10218 static unsigned int
10219 i9xx_cursor_max_stride(struct intel_plane *plane,
10220 u32 pixel_format, u64 modifier,
10221 unsigned int rotation)
10223 return plane->base.dev->mode_config.cursor_width * 4;
10226 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10228 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10229 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10232 if (INTEL_GEN(dev_priv) >= 11)
10235 cntl |= MCURSOR_GAMMA_ENABLE;
10237 if (HAS_DDI(dev_priv))
10238 cntl |= MCURSOR_PIPE_CSC_ENABLE;
10240 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10241 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
10246 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
10247 const struct intel_plane_state *plane_state)
10249 struct drm_i915_private *dev_priv =
10250 to_i915(plane_state->base.plane->dev);
10253 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
10254 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10256 switch (plane_state->base.crtc_w) {
10258 cntl |= MCURSOR_MODE_64_ARGB_AX;
10261 cntl |= MCURSOR_MODE_128_ARGB_AX;
10264 cntl |= MCURSOR_MODE_256_ARGB_AX;
10267 MISSING_CASE(plane_state->base.crtc_w);
10271 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
10272 cntl |= MCURSOR_ROTATE_180;
10277 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
10279 struct drm_i915_private *dev_priv =
10280 to_i915(plane_state->base.plane->dev);
10281 int width = plane_state->base.crtc_w;
10282 int height = plane_state->base.crtc_h;
10284 if (!intel_cursor_size_ok(plane_state))
10287 /* Cursor width is limited to a few power-of-two sizes */
10298 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10299 * height from 8 lines up to the cursor width, when the
10300 * cursor is not rotated. Everything else requires square
10303 if (HAS_CUR_FBC(dev_priv) &&
10304 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
10305 if (height < 8 || height > width)
10308 if (height != width)
10315 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
10316 struct intel_plane_state *plane_state)
10318 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
10319 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10320 const struct drm_framebuffer *fb = plane_state->base.fb;
10321 enum pipe pipe = plane->pipe;
10324 ret = intel_check_cursor(crtc_state, plane_state);
10328 /* if we want to turn off the cursor ignore width and height */
10332 /* Check for which cursor types we support */
10333 if (!i9xx_cursor_size_ok(plane_state)) {
10334 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10335 plane_state->base.crtc_w,
10336 plane_state->base.crtc_h);
10340 WARN_ON(plane_state->base.visible &&
10341 plane_state->color_plane[0].stride != fb->pitches[0]);
10343 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10344 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10345 fb->pitches[0], plane_state->base.crtc_w);
10350 * There's something wrong with the cursor on CHV pipe C.
10351 * If it straddles the left edge of the screen then
10352 * moving it away from the edge or disabling it often
10353 * results in a pipe underrun, and often that can lead to
10354 * dead pipe (constant underrun reported, and it scans
10355 * out just a solid color). To recover from that, the
10356 * display power well must be turned off and on again.
10357 * Refuse the put the cursor into that compromised position.
10359 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10360 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10361 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10365 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10370 static void i9xx_update_cursor(struct intel_plane *plane,
10371 const struct intel_crtc_state *crtc_state,
10372 const struct intel_plane_state *plane_state)
10374 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10375 enum pipe pipe = plane->pipe;
10376 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
10377 unsigned long irqflags;
10379 if (plane_state && plane_state->base.visible) {
10380 cntl = plane_state->ctl |
10381 i9xx_cursor_ctl_crtc(crtc_state);
10383 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10384 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10386 base = intel_cursor_base(plane_state);
10387 pos = intel_cursor_position(plane_state);
10390 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10393 * On some platforms writing CURCNTR first will also
10394 * cause CURPOS to be armed by the CURBASE write.
10395 * Without the CURCNTR write the CURPOS write would
10396 * arm itself. Thus we always update CURCNTR before
10399 * On other platforms CURPOS always requires the
10400 * CURBASE write to arm the update. Additonally
10401 * a write to any of the cursor register will cancel
10402 * an already armed cursor update. Thus leaving out
10403 * the CURBASE write after CURPOS could lead to a
10404 * cursor that doesn't appear to move, or even change
10405 * shape. Thus we always write CURBASE.
10407 * The other registers are armed by by the CURBASE write
10408 * except when the plane is getting enabled at which time
10409 * the CURCNTR write arms the update.
10412 if (INTEL_GEN(dev_priv) >= 9)
10413 skl_write_cursor_wm(plane, crtc_state);
10415 if (plane->cursor.base != base ||
10416 plane->cursor.size != fbc_ctl ||
10417 plane->cursor.cntl != cntl) {
10418 if (HAS_CUR_FBC(dev_priv))
10419 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
10420 I915_WRITE_FW(CURCNTR(pipe), cntl);
10421 I915_WRITE_FW(CURPOS(pipe), pos);
10422 I915_WRITE_FW(CURBASE(pipe), base);
10424 plane->cursor.base = base;
10425 plane->cursor.size = fbc_ctl;
10426 plane->cursor.cntl = cntl;
10428 I915_WRITE_FW(CURPOS(pipe), pos);
10429 I915_WRITE_FW(CURBASE(pipe), base);
10432 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10435 static void i9xx_disable_cursor(struct intel_plane *plane,
10436 const struct intel_crtc_state *crtc_state)
10438 i9xx_update_cursor(plane, crtc_state, NULL);
10441 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10444 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10445 enum intel_display_power_domain power_domain;
10446 intel_wakeref_t wakeref;
10451 * Not 100% correct for planes that can move between pipes,
10452 * but that's only the case for gen2-3 which don't have any
10453 * display power wells.
10455 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
10456 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10460 val = I915_READ(CURCNTR(plane->pipe));
10462 ret = val & MCURSOR_MODE;
10464 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10465 *pipe = plane->pipe;
10467 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10468 MCURSOR_PIPE_SELECT_SHIFT;
10470 intel_display_power_put(dev_priv, power_domain, wakeref);
10475 /* VESA 640x480x72Hz mode to set on the pipe */
10476 static const struct drm_display_mode load_detect_mode = {
10477 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10478 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10481 struct drm_framebuffer *
10482 intel_framebuffer_create(struct drm_i915_gem_object *obj,
10483 struct drm_mode_fb_cmd2 *mode_cmd)
10485 struct intel_framebuffer *intel_fb;
10488 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
10490 return ERR_PTR(-ENOMEM);
10492 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
10496 return &intel_fb->base;
10500 return ERR_PTR(ret);
10503 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10504 struct drm_crtc *crtc)
10506 struct drm_plane *plane;
10507 struct drm_plane_state *plane_state;
10510 ret = drm_atomic_add_affected_planes(state, crtc);
10514 for_each_new_plane_in_state(state, plane, plane_state, i) {
10515 if (plane_state->crtc != crtc)
10518 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10522 drm_atomic_set_fb_for_plane(plane_state, NULL);
10528 int intel_get_load_detect_pipe(struct drm_connector *connector,
10529 const struct drm_display_mode *mode,
10530 struct intel_load_detect_pipe *old,
10531 struct drm_modeset_acquire_ctx *ctx)
10533 struct intel_crtc *intel_crtc;
10534 struct intel_encoder *intel_encoder =
10535 intel_attached_encoder(connector);
10536 struct drm_crtc *possible_crtc;
10537 struct drm_encoder *encoder = &intel_encoder->base;
10538 struct drm_crtc *crtc = NULL;
10539 struct drm_device *dev = encoder->dev;
10540 struct drm_i915_private *dev_priv = to_i915(dev);
10541 struct drm_mode_config *config = &dev->mode_config;
10542 struct drm_atomic_state *state = NULL, *restore_state = NULL;
10543 struct drm_connector_state *connector_state;
10544 struct intel_crtc_state *crtc_state;
10547 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10548 connector->base.id, connector->name,
10549 encoder->base.id, encoder->name);
10551 old->restore_state = NULL;
10553 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
10556 * Algorithm gets a little messy:
10558 * - if the connector already has an assigned crtc, use it (but make
10559 * sure it's on first)
10561 * - try to find the first unused crtc that can drive this connector,
10562 * and use that if we find one
10565 /* See if we already have a CRTC for this connector */
10566 if (connector->state->crtc) {
10567 crtc = connector->state->crtc;
10569 ret = drm_modeset_lock(&crtc->mutex, ctx);
10573 /* Make sure the crtc and connector are running */
10577 /* Find an unused one (if possible) */
10578 for_each_crtc(dev, possible_crtc) {
10580 if (!(encoder->possible_crtcs & (1 << i)))
10583 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10587 if (possible_crtc->state->enable) {
10588 drm_modeset_unlock(&possible_crtc->mutex);
10592 crtc = possible_crtc;
10597 * If we didn't find an unused CRTC, don't use any.
10600 DRM_DEBUG_KMS("no pipe available for load-detect\n");
10606 intel_crtc = to_intel_crtc(crtc);
10608 state = drm_atomic_state_alloc(dev);
10609 restore_state = drm_atomic_state_alloc(dev);
10610 if (!state || !restore_state) {
10615 state->acquire_ctx = ctx;
10616 restore_state->acquire_ctx = ctx;
10618 connector_state = drm_atomic_get_connector_state(state, connector);
10619 if (IS_ERR(connector_state)) {
10620 ret = PTR_ERR(connector_state);
10624 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10628 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10629 if (IS_ERR(crtc_state)) {
10630 ret = PTR_ERR(crtc_state);
10634 crtc_state->base.active = crtc_state->base.enable = true;
10637 mode = &load_detect_mode;
10639 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
10643 ret = intel_modeset_disable_planes(state, crtc);
10647 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10649 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
10651 ret = drm_atomic_add_affected_planes(restore_state, crtc);
10653 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10657 ret = drm_atomic_commit(state);
10659 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
10663 old->restore_state = restore_state;
10664 drm_atomic_state_put(state);
10666 /* let the connector get through one full cycle before testing */
10667 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
10672 drm_atomic_state_put(state);
10675 if (restore_state) {
10676 drm_atomic_state_put(restore_state);
10677 restore_state = NULL;
10680 if (ret == -EDEADLK)
10686 void intel_release_load_detect_pipe(struct drm_connector *connector,
10687 struct intel_load_detect_pipe *old,
10688 struct drm_modeset_acquire_ctx *ctx)
10690 struct intel_encoder *intel_encoder =
10691 intel_attached_encoder(connector);
10692 struct drm_encoder *encoder = &intel_encoder->base;
10693 struct drm_atomic_state *state = old->restore_state;
10696 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
10697 connector->base.id, connector->name,
10698 encoder->base.id, encoder->name);
10703 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
10705 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
10706 drm_atomic_state_put(state);
10709 static int i9xx_pll_refclk(struct drm_device *dev,
10710 const struct intel_crtc_state *pipe_config)
10712 struct drm_i915_private *dev_priv = to_i915(dev);
10713 u32 dpll = pipe_config->dpll_hw_state.dpll;
10715 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
10716 return dev_priv->vbt.lvds_ssc_freq;
10717 else if (HAS_PCH_SPLIT(dev_priv))
10719 else if (!IS_GEN(dev_priv, 2))
10725 /* Returns the clock of the currently programmed mode of the given pipe. */
10726 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
10727 struct intel_crtc_state *pipe_config)
10729 struct drm_device *dev = crtc->base.dev;
10730 struct drm_i915_private *dev_priv = to_i915(dev);
10731 int pipe = pipe_config->cpu_transcoder;
10732 u32 dpll = pipe_config->dpll_hw_state.dpll;
10736 int refclk = i9xx_pll_refclk(dev, pipe_config);
10738 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
10739 fp = pipe_config->dpll_hw_state.fp0;
10741 fp = pipe_config->dpll_hw_state.fp1;
10743 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
10744 if (IS_PINEVIEW(dev_priv)) {
10745 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10746 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
10748 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10749 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10752 if (!IS_GEN(dev_priv, 2)) {
10753 if (IS_PINEVIEW(dev_priv))
10754 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10755 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
10757 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
10758 DPLL_FPA01_P1_POST_DIV_SHIFT);
10760 switch (dpll & DPLL_MODE_MASK) {
10761 case DPLLB_MODE_DAC_SERIAL:
10762 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10765 case DPLLB_MODE_LVDS:
10766 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10770 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
10771 "mode\n", (int)(dpll & DPLL_MODE_MASK));
10775 if (IS_PINEVIEW(dev_priv))
10776 port_clock = pnv_calc_dpll_params(refclk, &clock);
10778 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10780 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
10781 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
10784 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10785 DPLL_FPA01_P1_POST_DIV_SHIFT);
10787 if (lvds & LVDS_CLKB_POWER_UP)
10792 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10795 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10796 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10798 if (dpll & PLL_P2_DIVIDE_BY_4)
10804 port_clock = i9xx_calc_dpll_params(refclk, &clock);
10808 * This value includes pixel_multiplier. We will use
10809 * port_clock to compute adjusted_mode.crtc_clock in the
10810 * encoder's get_config() function.
10812 pipe_config->port_clock = port_clock;
10815 int intel_dotclock_calculate(int link_freq,
10816 const struct intel_link_m_n *m_n)
10819 * The calculation for the data clock is:
10820 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
10821 * But we want to avoid losing precison if possible, so:
10822 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
10824 * and the link clock is simpler:
10825 * link_clock = (m * link_clock) / n
10831 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
10834 static void ironlake_pch_clock_get(struct intel_crtc *crtc,
10835 struct intel_crtc_state *pipe_config)
10837 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10839 /* read out port_clock from the DPLL */
10840 i9xx_crtc_clock_get(crtc, pipe_config);
10843 * In case there is an active pipe without active ports,
10844 * we may need some idea for the dotclock anyway.
10845 * Calculate one based on the FDI configuration.
10847 pipe_config->base.adjusted_mode.crtc_clock =
10848 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
10849 &pipe_config->fdi_m_n);
10852 /* Returns the currently programmed mode of the given encoder. */
10853 struct drm_display_mode *
10854 intel_encoder_current_mode(struct intel_encoder *encoder)
10856 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10857 struct intel_crtc_state *crtc_state;
10858 struct drm_display_mode *mode;
10859 struct intel_crtc *crtc;
10862 if (!encoder->get_hw_state(encoder, &pipe))
10865 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
10867 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10871 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10877 crtc_state->base.crtc = &crtc->base;
10879 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10885 encoder->get_config(encoder, crtc_state);
10887 intel_mode_from_pipe_config(mode, crtc_state);
10894 static void intel_crtc_destroy(struct drm_crtc *crtc)
10896 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10898 drm_crtc_cleanup(crtc);
10903 * intel_wm_need_update - Check whether watermarks need updating
10904 * @cur: current plane state
10905 * @new: new plane state
10907 * Check current plane state versus the new one to determine whether
10908 * watermarks need to be recalculated.
10910 * Returns true or false.
10912 static bool intel_wm_need_update(struct intel_plane_state *cur,
10913 struct intel_plane_state *new)
10915 /* Update watermarks on tiling or size changes. */
10916 if (new->base.visible != cur->base.visible)
10919 if (!cur->base.fb || !new->base.fb)
10922 if (cur->base.fb->modifier != new->base.fb->modifier ||
10923 cur->base.rotation != new->base.rotation ||
10924 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10925 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10926 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10927 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
10933 static bool needs_scaling(const struct intel_plane_state *state)
10935 int src_w = drm_rect_width(&state->base.src) >> 16;
10936 int src_h = drm_rect_height(&state->base.src) >> 16;
10937 int dst_w = drm_rect_width(&state->base.dst);
10938 int dst_h = drm_rect_height(&state->base.dst);
10940 return (src_w != dst_w || src_h != dst_h);
10943 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10944 struct drm_crtc_state *crtc_state,
10945 const struct intel_plane_state *old_plane_state,
10946 struct drm_plane_state *plane_state)
10948 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
10949 struct drm_crtc *crtc = crtc_state->crtc;
10950 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10951 struct intel_plane *plane = to_intel_plane(plane_state->plane);
10952 struct drm_device *dev = crtc->dev;
10953 struct drm_i915_private *dev_priv = to_i915(dev);
10954 bool mode_changed = needs_modeset(crtc_state);
10955 bool was_crtc_enabled = old_crtc_state->base.active;
10956 bool is_crtc_enabled = crtc_state->active;
10957 bool turn_off, turn_on, visible, was_visible;
10958 struct drm_framebuffer *fb = plane_state->fb;
10961 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
10962 ret = skl_update_scaler_plane(
10963 to_intel_crtc_state(crtc_state),
10964 to_intel_plane_state(plane_state));
10969 was_visible = old_plane_state->base.visible;
10970 visible = plane_state->visible;
10972 if (!was_crtc_enabled && WARN_ON(was_visible))
10973 was_visible = false;
10976 * Visibility is calculated as if the crtc was on, but
10977 * after scaler setup everything depends on it being off
10978 * when the crtc isn't active.
10980 * FIXME this is wrong for watermarks. Watermarks should also
10981 * be computed as if the pipe would be active. Perhaps move
10982 * per-plane wm computation to the .check_plane() hook, and
10983 * only combine the results from all planes in the current place?
10985 if (!is_crtc_enabled) {
10986 plane_state->visible = visible = false;
10987 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10990 if (!was_visible && !visible)
10993 if (fb != old_plane_state->base.fb)
10994 pipe_config->fb_changed = true;
10996 turn_off = was_visible && (!visible || mode_changed);
10997 turn_on = visible && (!was_visible || mode_changed);
10999 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
11000 intel_crtc->base.base.id, intel_crtc->base.name,
11001 plane->base.base.id, plane->base.name,
11002 fb ? fb->base.id : -1);
11004 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
11005 plane->base.base.id, plane->base.name,
11006 was_visible, visible,
11007 turn_off, turn_on, mode_changed);
11010 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11011 pipe_config->update_wm_pre = true;
11013 /* must disable cxsr around plane enable/disable */
11014 if (plane->id != PLANE_CURSOR)
11015 pipe_config->disable_cxsr = true;
11016 } else if (turn_off) {
11017 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
11018 pipe_config->update_wm_post = true;
11020 /* must disable cxsr around plane enable/disable */
11021 if (plane->id != PLANE_CURSOR)
11022 pipe_config->disable_cxsr = true;
11023 } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state),
11024 to_intel_plane_state(plane_state))) {
11025 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
11026 /* FIXME bollocks */
11027 pipe_config->update_wm_pre = true;
11028 pipe_config->update_wm_post = true;
11032 if (visible || was_visible)
11033 pipe_config->fb_bits |= plane->frontbuffer_bit;
11036 * ILK/SNB DVSACNTR/Sprite Enable
11037 * IVB SPR_CTL/Sprite Enable
11038 * "When in Self Refresh Big FIFO mode, a write to enable the
11039 * plane will be internally buffered and delayed while Big FIFO
11040 * mode is exiting."
11042 * Which means that enabling the sprite can take an extra frame
11043 * when we start in big FIFO mode (LP1+). Thus we need to drop
11044 * down to LP0 and wait for vblank in order to make sure the
11045 * sprite gets enabled on the next vblank after the register write.
11046 * Doing otherwise would risk enabling the sprite one frame after
11047 * we've already signalled flip completion. We can resume LP1+
11048 * once the sprite has been enabled.
11051 * WaCxSRDisabledForSpriteScaling:ivb
11052 * IVB SPR_SCALE/Scaling Enable
11053 * "Low Power watermarks must be disabled for at least one
11054 * frame before enabling sprite scaling, and kept disabled
11055 * until sprite scaling is disabled."
11057 * ILK/SNB DVSASCALE/Scaling Enable
11058 * "When in Self Refresh Big FIFO mode, scaling enable will be
11059 * masked off while Big FIFO mode is exiting."
11061 * Despite the w/a only being listed for IVB we assume that
11062 * the ILK/SNB note has similar ramifications, hence we apply
11063 * the w/a on all three platforms.
11065 * With experimental results seems this is needed also for primary
11066 * plane, not only sprite plane.
11068 if (plane->id != PLANE_CURSOR &&
11069 (IS_GEN_RANGE(dev_priv, 5, 6) ||
11070 IS_IVYBRIDGE(dev_priv)) &&
11071 (turn_on || (!needs_scaling(old_plane_state) &&
11072 needs_scaling(to_intel_plane_state(plane_state)))))
11073 pipe_config->disable_lp_wm = true;
11078 static bool encoders_cloneable(const struct intel_encoder *a,
11079 const struct intel_encoder *b)
11081 /* masks could be asymmetric, so check both ways */
11082 return a == b || (a->cloneable & (1 << b->type) &&
11083 b->cloneable & (1 << a->type));
11086 static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11087 struct intel_crtc *crtc,
11088 struct intel_encoder *encoder)
11090 struct intel_encoder *source_encoder;
11091 struct drm_connector *connector;
11092 struct drm_connector_state *connector_state;
11095 for_each_new_connector_in_state(state, connector, connector_state, i) {
11096 if (connector_state->crtc != &crtc->base)
11100 to_intel_encoder(connector_state->best_encoder);
11101 if (!encoders_cloneable(encoder, source_encoder))
11108 static int icl_add_linked_planes(struct intel_atomic_state *state)
11110 struct intel_plane *plane, *linked;
11111 struct intel_plane_state *plane_state, *linked_plane_state;
11114 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11115 linked = plane_state->linked_plane;
11120 linked_plane_state = intel_atomic_get_plane_state(state, linked);
11121 if (IS_ERR(linked_plane_state))
11122 return PTR_ERR(linked_plane_state);
11124 WARN_ON(linked_plane_state->linked_plane != plane);
11125 WARN_ON(linked_plane_state->slave == plane_state->slave);
11131 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
11133 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11134 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11135 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
11136 struct intel_plane *plane, *linked;
11137 struct intel_plane_state *plane_state;
11140 if (INTEL_GEN(dev_priv) < 11)
11144 * Destroy all old plane links and make the slave plane invisible
11145 * in the crtc_state->active_planes mask.
11147 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11148 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
11151 plane_state->linked_plane = NULL;
11152 if (plane_state->slave && !plane_state->base.visible) {
11153 crtc_state->active_planes &= ~BIT(plane->id);
11154 crtc_state->update_planes |= BIT(plane->id);
11157 plane_state->slave = false;
11160 if (!crtc_state->nv12_planes)
11163 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11164 struct intel_plane_state *linked_state = NULL;
11166 if (plane->pipe != crtc->pipe ||
11167 !(crtc_state->nv12_planes & BIT(plane->id)))
11170 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
11171 if (!icl_is_nv12_y_plane(linked->id))
11174 if (crtc_state->active_planes & BIT(linked->id))
11177 linked_state = intel_atomic_get_plane_state(state, linked);
11178 if (IS_ERR(linked_state))
11179 return PTR_ERR(linked_state);
11184 if (!linked_state) {
11185 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
11186 hweight8(crtc_state->nv12_planes));
11191 plane_state->linked_plane = linked;
11193 linked_state->slave = true;
11194 linked_state->linked_plane = plane;
11195 crtc_state->active_planes |= BIT(linked->id);
11196 crtc_state->update_planes |= BIT(linked->id);
11197 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
11203 static int intel_crtc_atomic_check(struct drm_crtc *crtc,
11204 struct drm_crtc_state *crtc_state)
11206 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
11207 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11208 struct intel_crtc_state *pipe_config =
11209 to_intel_crtc_state(crtc_state);
11211 bool mode_changed = needs_modeset(crtc_state);
11213 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
11214 mode_changed && !crtc_state->active)
11215 pipe_config->update_wm_post = true;
11217 if (mode_changed && crtc_state->enable &&
11218 dev_priv->display.crtc_compute_clock &&
11219 !WARN_ON(pipe_config->shared_dpll)) {
11220 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
11226 if (mode_changed || crtc_state->color_mgmt_changed) {
11227 ret = intel_color_check(pipe_config);
11232 * Changing color management on Intel hardware is
11233 * handled as part of planes update.
11235 crtc_state->planes_changed = true;
11239 if (dev_priv->display.compute_pipe_wm) {
11240 ret = dev_priv->display.compute_pipe_wm(pipe_config);
11242 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
11247 if (dev_priv->display.compute_intermediate_wm) {
11248 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
11252 * Calculate 'intermediate' watermarks that satisfy both the
11253 * old state and the new state. We can program these
11256 ret = dev_priv->display.compute_intermediate_wm(pipe_config);
11258 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11263 if (INTEL_GEN(dev_priv) >= 9) {
11264 if (mode_changed || pipe_config->update_pipe)
11265 ret = skl_update_scaler_crtc(pipe_config);
11268 ret = icl_check_nv12_planes(pipe_config);
11270 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11273 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
11277 if (HAS_IPS(dev_priv))
11278 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11283 static const struct drm_crtc_helper_funcs intel_helper_funcs = {
11284 .atomic_check = intel_crtc_atomic_check,
11287 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11289 struct intel_connector *connector;
11290 struct drm_connector_list_iter conn_iter;
11292 drm_connector_list_iter_begin(dev, &conn_iter);
11293 for_each_intel_connector_iter(connector, &conn_iter) {
11294 if (connector->base.state->crtc)
11295 drm_connector_put(&connector->base);
11297 if (connector->base.encoder) {
11298 connector->base.state->best_encoder =
11299 connector->base.encoder;
11300 connector->base.state->crtc =
11301 connector->base.encoder->crtc;
11303 drm_connector_get(&connector->base);
11305 connector->base.state->best_encoder = NULL;
11306 connector->base.state->crtc = NULL;
11309 drm_connector_list_iter_end(&conn_iter);
11313 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11314 struct intel_crtc_state *pipe_config)
11316 struct drm_connector *connector = conn_state->connector;
11317 const struct drm_display_info *info = &connector->display_info;
11320 switch (conn_state->max_bpc) {
11337 if (bpp < pipe_config->pipe_bpp) {
11338 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11339 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11340 connector->base.id, connector->name,
11341 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
11342 pipe_config->pipe_bpp);
11344 pipe_config->pipe_bpp = bpp;
11351 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
11352 struct intel_crtc_state *pipe_config)
11354 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11355 struct drm_atomic_state *state = pipe_config->base.state;
11356 struct drm_connector *connector;
11357 struct drm_connector_state *connector_state;
11360 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11361 IS_CHERRYVIEW(dev_priv)))
11363 else if (INTEL_GEN(dev_priv) >= 5)
11368 pipe_config->pipe_bpp = bpp;
11370 /* Clamp display bpp to connector max bpp */
11371 for_each_new_connector_in_state(state, connector, connector_state, i) {
11374 if (connector_state->crtc != &crtc->base)
11377 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11385 static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11387 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11388 "type: 0x%x flags: 0x%x\n",
11390 mode->crtc_hdisplay, mode->crtc_hsync_start,
11391 mode->crtc_hsync_end, mode->crtc_htotal,
11392 mode->crtc_vdisplay, mode->crtc_vsync_start,
11393 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11397 intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
11398 unsigned int lane_count, struct intel_link_m_n *m_n)
11400 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11402 m_n->gmch_m, m_n->gmch_n,
11403 m_n->link_m, m_n->link_n, m_n->tu);
11406 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11408 static const char * const output_type_str[] = {
11409 OUTPUT_TYPE(UNUSED),
11410 OUTPUT_TYPE(ANALOG),
11414 OUTPUT_TYPE(TVOUT),
11420 OUTPUT_TYPE(DP_MST),
11425 static void snprintf_output_types(char *buf, size_t len,
11426 unsigned int output_types)
11433 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11436 if ((output_types & BIT(i)) == 0)
11439 r = snprintf(str, len, "%s%s",
11440 str != buf ? "," : "", output_type_str[i]);
11446 output_types &= ~BIT(i);
11449 WARN_ON_ONCE(output_types != 0);
11452 static const char * const output_format_str[] = {
11453 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11454 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
11455 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
11456 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
11459 static const char *output_formats(enum intel_output_format format)
11461 if (format >= ARRAY_SIZE(output_format_str))
11462 format = INTEL_OUTPUT_FORMAT_INVALID;
11463 return output_format_str[format];
11466 static void intel_dump_pipe_config(struct intel_crtc *crtc,
11467 struct intel_crtc_state *pipe_config,
11468 const char *context)
11470 struct drm_device *dev = crtc->base.dev;
11471 struct drm_i915_private *dev_priv = to_i915(dev);
11472 struct drm_plane *plane;
11473 struct intel_plane *intel_plane;
11474 struct intel_plane_state *state;
11475 struct drm_framebuffer *fb;
11478 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11479 crtc->base.base.id, crtc->base.name, context);
11481 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11482 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11483 buf, pipe_config->output_types);
11485 DRM_DEBUG_KMS("output format: %s\n",
11486 output_formats(pipe_config->output_format));
11488 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11489 transcoder_name(pipe_config->cpu_transcoder),
11490 pipe_config->pipe_bpp, pipe_config->dither);
11492 if (pipe_config->has_pch_encoder)
11493 intel_dump_m_n_config(pipe_config, "fdi",
11494 pipe_config->fdi_lanes,
11495 &pipe_config->fdi_m_n);
11497 if (intel_crtc_has_dp_encoder(pipe_config)) {
11498 intel_dump_m_n_config(pipe_config, "dp m_n",
11499 pipe_config->lane_count, &pipe_config->dp_m_n);
11500 if (pipe_config->has_drrs)
11501 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11502 pipe_config->lane_count,
11503 &pipe_config->dp_m2_n2);
11506 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
11507 pipe_config->has_audio, pipe_config->has_infoframe);
11509 DRM_DEBUG_KMS("requested mode:\n");
11510 drm_mode_debug_printmodeline(&pipe_config->base.mode);
11511 DRM_DEBUG_KMS("adjusted mode:\n");
11512 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11513 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
11514 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
11515 pipe_config->port_clock,
11516 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11517 pipe_config->pixel_rate);
11519 if (INTEL_GEN(dev_priv) >= 9)
11520 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11522 pipe_config->scaler_state.scaler_users,
11523 pipe_config->scaler_state.scaler_id);
11525 if (HAS_GMCH(dev_priv))
11526 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11527 pipe_config->gmch_pfit.control,
11528 pipe_config->gmch_pfit.pgm_ratios,
11529 pipe_config->gmch_pfit.lvds_border_bits);
11531 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11532 pipe_config->pch_pfit.pos,
11533 pipe_config->pch_pfit.size,
11534 enableddisabled(pipe_config->pch_pfit.enabled));
11536 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11537 pipe_config->ips_enabled, pipe_config->double_wide);
11539 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
11541 DRM_DEBUG_KMS("planes on this crtc\n");
11542 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
11543 struct drm_format_name_buf format_name;
11544 intel_plane = to_intel_plane(plane);
11545 if (intel_plane->pipe != crtc->pipe)
11548 state = to_intel_plane_state(plane->state);
11549 fb = state->base.fb;
11551 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11552 plane->base.id, plane->name, state->scaler_id);
11556 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11557 plane->base.id, plane->name,
11558 fb->base.id, fb->width, fb->height,
11559 drm_get_format_name(fb->format->format, &format_name));
11560 if (INTEL_GEN(dev_priv) >= 9)
11561 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11563 state->base.src.x1 >> 16,
11564 state->base.src.y1 >> 16,
11565 drm_rect_width(&state->base.src) >> 16,
11566 drm_rect_height(&state->base.src) >> 16,
11567 state->base.dst.x1, state->base.dst.y1,
11568 drm_rect_width(&state->base.dst),
11569 drm_rect_height(&state->base.dst));
11573 static bool check_digital_port_conflicts(struct drm_atomic_state *state)
11575 struct drm_device *dev = state->dev;
11576 struct drm_connector *connector;
11577 struct drm_connector_list_iter conn_iter;
11578 unsigned int used_ports = 0;
11579 unsigned int used_mst_ports = 0;
11583 * Walk the connector list instead of the encoder
11584 * list to detect the problem on ddi platforms
11585 * where there's just one encoder per digital port.
11587 drm_connector_list_iter_begin(dev, &conn_iter);
11588 drm_for_each_connector_iter(connector, &conn_iter) {
11589 struct drm_connector_state *connector_state;
11590 struct intel_encoder *encoder;
11592 connector_state = drm_atomic_get_new_connector_state(state, connector);
11593 if (!connector_state)
11594 connector_state = connector->state;
11596 if (!connector_state->best_encoder)
11599 encoder = to_intel_encoder(connector_state->best_encoder);
11601 WARN_ON(!connector_state->crtc);
11603 switch (encoder->type) {
11604 unsigned int port_mask;
11605 case INTEL_OUTPUT_DDI:
11606 if (WARN_ON(!HAS_DDI(to_i915(dev))))
11608 /* else: fall through */
11609 case INTEL_OUTPUT_DP:
11610 case INTEL_OUTPUT_HDMI:
11611 case INTEL_OUTPUT_EDP:
11612 port_mask = 1 << encoder->port;
11614 /* the same port mustn't appear more than once */
11615 if (used_ports & port_mask)
11618 used_ports |= port_mask;
11620 case INTEL_OUTPUT_DP_MST:
11622 1 << encoder->port;
11628 drm_connector_list_iter_end(&conn_iter);
11630 /* can't mix MST and SST/HDMI on the same port */
11631 if (used_ports & used_mst_ports)
11638 clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11640 struct drm_i915_private *dev_priv =
11641 to_i915(crtc_state->base.crtc->dev);
11642 struct intel_crtc_state *saved_state;
11644 saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL);
11648 /* FIXME: before the switch to atomic started, a new pipe_config was
11649 * kzalloc'd. Code that depends on any field being zero should be
11650 * fixed, so that the crtc_state can be safely duplicated. For now,
11651 * only fields that are know to not cause problems are preserved. */
11653 saved_state->scaler_state = crtc_state->scaler_state;
11654 saved_state->shared_dpll = crtc_state->shared_dpll;
11655 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
11656 saved_state->pch_pfit.force_thru = crtc_state->pch_pfit.force_thru;
11657 saved_state->ips_force_disable = crtc_state->ips_force_disable;
11658 if (IS_G4X(dev_priv) ||
11659 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11660 saved_state->wm = crtc_state->wm;
11662 /* Keep base drm_crtc_state intact, only clear our extended struct */
11663 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11664 memcpy(&crtc_state->base + 1, &saved_state->base + 1,
11665 sizeof(*crtc_state) - sizeof(crtc_state->base));
11667 kfree(saved_state);
11672 intel_modeset_pipe_config(struct drm_crtc *crtc,
11673 struct intel_crtc_state *pipe_config)
11675 struct drm_atomic_state *state = pipe_config->base.state;
11676 struct intel_encoder *encoder;
11677 struct drm_connector *connector;
11678 struct drm_connector_state *connector_state;
11683 ret = clear_intel_crtc_state(pipe_config);
11687 pipe_config->cpu_transcoder =
11688 (enum transcoder) to_intel_crtc(crtc)->pipe;
11691 * Sanitize sync polarity flags based on requested ones. If neither
11692 * positive or negative polarity is requested, treat this as meaning
11693 * negative polarity.
11695 if (!(pipe_config->base.adjusted_mode.flags &
11696 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
11697 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
11699 if (!(pipe_config->base.adjusted_mode.flags &
11700 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
11701 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
11703 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11708 base_bpp = pipe_config->pipe_bpp;
11711 * Determine the real pipe dimensions. Note that stereo modes can
11712 * increase the actual pipe size due to the frame doubling and
11713 * insertion of additional space for blanks between the frame. This
11714 * is stored in the crtc timings. We use the requested mode to do this
11715 * computation to clearly distinguish it from the adjusted mode, which
11716 * can be changed by the connectors in the below retry loop.
11718 drm_mode_get_hv_timing(&pipe_config->base.mode,
11719 &pipe_config->pipe_src_w,
11720 &pipe_config->pipe_src_h);
11722 for_each_new_connector_in_state(state, connector, connector_state, i) {
11723 if (connector_state->crtc != crtc)
11726 encoder = to_intel_encoder(connector_state->best_encoder);
11728 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11729 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
11734 * Determine output_types before calling the .compute_config()
11735 * hooks so that the hooks can use this information safely.
11737 if (encoder->compute_output_type)
11738 pipe_config->output_types |=
11739 BIT(encoder->compute_output_type(encoder, pipe_config,
11742 pipe_config->output_types |= BIT(encoder->type);
11746 /* Ensure the port clock defaults are reset when retrying. */
11747 pipe_config->port_clock = 0;
11748 pipe_config->pixel_multiplier = 1;
11750 /* Fill in default crtc timings, allow encoders to overwrite them. */
11751 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11752 CRTC_STEREO_DOUBLE);
11754 /* Pass our mode to the connectors and the CRTC to give them a chance to
11755 * adjust it according to limitations or connector properties, and also
11756 * a chance to reject the mode entirely.
11758 for_each_new_connector_in_state(state, connector, connector_state, i) {
11759 if (connector_state->crtc != crtc)
11762 encoder = to_intel_encoder(connector_state->best_encoder);
11763 ret = encoder->compute_config(encoder, pipe_config,
11766 if (ret != -EDEADLK)
11767 DRM_DEBUG_KMS("Encoder config failure: %d\n",
11773 /* Set default port clock if not overwritten by the encoder. Needs to be
11774 * done afterwards in case the encoder adjusts the mode. */
11775 if (!pipe_config->port_clock)
11776 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
11777 * pipe_config->pixel_multiplier;
11779 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
11780 if (ret == -EDEADLK)
11783 DRM_DEBUG_KMS("CRTC fixup failed\n");
11787 if (ret == RETRY) {
11788 if (WARN(!retry, "loop in pipe configuration computation\n"))
11791 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11793 goto encoder_retry;
11796 /* Dithering seems to not pass-through bits correctly when it should, so
11797 * only enable it on 6bpc panels and when its not a compliance
11798 * test requesting 6bpc video pattern.
11800 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11801 !pipe_config->dither_force_disable;
11802 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
11803 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
11808 static bool intel_fuzzy_clock_check(int clock1, int clock2)
11812 if (clock1 == clock2)
11815 if (!clock1 || !clock2)
11818 diff = abs(clock1 - clock2);
11820 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11827 intel_compare_m_n(unsigned int m, unsigned int n,
11828 unsigned int m2, unsigned int n2,
11831 if (m == m2 && n == n2)
11834 if (exact || !m || !n || !m2 || !n2)
11837 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11844 } else if (n < n2) {
11854 return intel_fuzzy_clock_check(m, m2);
11858 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11859 struct intel_link_m_n *m2_n2,
11862 if (m_n->tu == m2_n2->tu &&
11863 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11864 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11865 intel_compare_m_n(m_n->link_m, m_n->link_n,
11866 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11876 static void __printf(3, 4)
11877 pipe_config_err(bool adjust, const char *name, const char *format, ...)
11879 struct va_format vaf;
11882 va_start(args, format);
11887 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11889 drm_err("mismatch in %s %pV", name, &vaf);
11894 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
11896 if (i915_modparams.fastboot != -1)
11897 return i915_modparams.fastboot;
11899 /* Enable fastboot by default on Skylake and newer */
11900 if (INTEL_GEN(dev_priv) >= 9)
11903 /* Enable fastboot by default on VLV and CHV */
11904 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11907 /* Disabled by default on all others */
11912 intel_pipe_config_compare(struct drm_i915_private *dev_priv,
11913 struct intel_crtc_state *current_config,
11914 struct intel_crtc_state *pipe_config,
11918 bool fixup_inherited = adjust &&
11919 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11920 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
11922 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
11923 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
11927 #define PIPE_CONF_CHECK_X(name) do { \
11928 if (current_config->name != pipe_config->name) { \
11929 pipe_config_err(adjust, __stringify(name), \
11930 "(expected 0x%08x, found 0x%08x)\n", \
11931 current_config->name, \
11932 pipe_config->name); \
11937 #define PIPE_CONF_CHECK_I(name) do { \
11938 if (current_config->name != pipe_config->name) { \
11939 pipe_config_err(adjust, __stringify(name), \
11940 "(expected %i, found %i)\n", \
11941 current_config->name, \
11942 pipe_config->name); \
11947 #define PIPE_CONF_CHECK_BOOL(name) do { \
11948 if (current_config->name != pipe_config->name) { \
11949 pipe_config_err(adjust, __stringify(name), \
11950 "(expected %s, found %s)\n", \
11951 yesno(current_config->name), \
11952 yesno(pipe_config->name)); \
11958 * Checks state where we only read out the enabling, but not the entire
11959 * state itself (like full infoframes or ELD for audio). These states
11960 * require a full modeset on bootup to fix up.
11962 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11963 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11964 PIPE_CONF_CHECK_BOOL(name); \
11966 pipe_config_err(adjust, __stringify(name), \
11967 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11968 yesno(current_config->name), \
11969 yesno(pipe_config->name)); \
11974 #define PIPE_CONF_CHECK_P(name) do { \
11975 if (current_config->name != pipe_config->name) { \
11976 pipe_config_err(adjust, __stringify(name), \
11977 "(expected %p, found %p)\n", \
11978 current_config->name, \
11979 pipe_config->name); \
11984 #define PIPE_CONF_CHECK_M_N(name) do { \
11985 if (!intel_compare_link_m_n(¤t_config->name, \
11986 &pipe_config->name,\
11988 pipe_config_err(adjust, __stringify(name), \
11989 "(expected tu %i gmch %i/%i link %i/%i, " \
11990 "found tu %i, gmch %i/%i link %i/%i)\n", \
11991 current_config->name.tu, \
11992 current_config->name.gmch_m, \
11993 current_config->name.gmch_n, \
11994 current_config->name.link_m, \
11995 current_config->name.link_n, \
11996 pipe_config->name.tu, \
11997 pipe_config->name.gmch_m, \
11998 pipe_config->name.gmch_n, \
11999 pipe_config->name.link_m, \
12000 pipe_config->name.link_n); \
12005 /* This is required for BDW+ where there is only one set of registers for
12006 * switching between high and low RR.
12007 * This macro can be used whenever a comparison has to be made between one
12008 * hw state and multiple sw state variables.
12010 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
12011 if (!intel_compare_link_m_n(¤t_config->name, \
12012 &pipe_config->name, adjust) && \
12013 !intel_compare_link_m_n(¤t_config->alt_name, \
12014 &pipe_config->name, adjust)) { \
12015 pipe_config_err(adjust, __stringify(name), \
12016 "(expected tu %i gmch %i/%i link %i/%i, " \
12017 "or tu %i gmch %i/%i link %i/%i, " \
12018 "found tu %i, gmch %i/%i link %i/%i)\n", \
12019 current_config->name.tu, \
12020 current_config->name.gmch_m, \
12021 current_config->name.gmch_n, \
12022 current_config->name.link_m, \
12023 current_config->name.link_n, \
12024 current_config->alt_name.tu, \
12025 current_config->alt_name.gmch_m, \
12026 current_config->alt_name.gmch_n, \
12027 current_config->alt_name.link_m, \
12028 current_config->alt_name.link_n, \
12029 pipe_config->name.tu, \
12030 pipe_config->name.gmch_m, \
12031 pipe_config->name.gmch_n, \
12032 pipe_config->name.link_m, \
12033 pipe_config->name.link_n); \
12038 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
12039 if ((current_config->name ^ pipe_config->name) & (mask)) { \
12040 pipe_config_err(adjust, __stringify(name), \
12041 "(%x) (expected %i, found %i)\n", \
12043 current_config->name & (mask), \
12044 pipe_config->name & (mask)); \
12049 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
12050 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
12051 pipe_config_err(adjust, __stringify(name), \
12052 "(expected %i, found %i)\n", \
12053 current_config->name, \
12054 pipe_config->name); \
12059 #define PIPE_CONF_QUIRK(quirk) \
12060 ((current_config->quirks | pipe_config->quirks) & (quirk))
12062 PIPE_CONF_CHECK_I(cpu_transcoder);
12064 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
12065 PIPE_CONF_CHECK_I(fdi_lanes);
12066 PIPE_CONF_CHECK_M_N(fdi_m_n);
12068 PIPE_CONF_CHECK_I(lane_count);
12069 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
12071 if (INTEL_GEN(dev_priv) < 8) {
12072 PIPE_CONF_CHECK_M_N(dp_m_n);
12074 if (current_config->has_drrs)
12075 PIPE_CONF_CHECK_M_N(dp_m2_n2);
12077 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
12079 PIPE_CONF_CHECK_X(output_types);
12081 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
12082 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
12083 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
12084 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
12085 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
12086 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
12088 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
12089 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
12090 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
12091 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
12092 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
12093 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
12095 PIPE_CONF_CHECK_I(pixel_multiplier);
12096 PIPE_CONF_CHECK_I(output_format);
12097 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
12098 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
12099 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
12100 PIPE_CONF_CHECK_BOOL(limited_color_range);
12102 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
12103 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
12104 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
12106 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
12108 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12109 DRM_MODE_FLAG_INTERLACE);
12111 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
12112 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12113 DRM_MODE_FLAG_PHSYNC);
12114 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12115 DRM_MODE_FLAG_NHSYNC);
12116 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12117 DRM_MODE_FLAG_PVSYNC);
12118 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
12119 DRM_MODE_FLAG_NVSYNC);
12122 PIPE_CONF_CHECK_X(gmch_pfit.control);
12123 /* pfit ratios are autocomputed by the hw on gen4+ */
12124 if (INTEL_GEN(dev_priv) < 4)
12125 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
12126 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
12129 PIPE_CONF_CHECK_I(pipe_src_w);
12130 PIPE_CONF_CHECK_I(pipe_src_h);
12132 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
12133 if (current_config->pch_pfit.enabled) {
12134 PIPE_CONF_CHECK_X(pch_pfit.pos);
12135 PIPE_CONF_CHECK_X(pch_pfit.size);
12138 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
12139 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
12142 PIPE_CONF_CHECK_BOOL(double_wide);
12144 PIPE_CONF_CHECK_P(shared_dpll);
12145 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
12146 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
12147 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
12148 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
12149 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
12150 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
12151 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
12152 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
12153 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
12154 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
12155 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
12156 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
12157 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
12158 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
12159 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
12160 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
12161 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
12162 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
12163 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
12164 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
12165 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
12166 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
12167 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
12168 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
12169 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
12170 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
12171 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
12172 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
12173 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
12174 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
12175 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
12177 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
12178 PIPE_CONF_CHECK_X(dsi_pll.div);
12180 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
12181 PIPE_CONF_CHECK_I(pipe_bpp);
12183 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
12184 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
12186 PIPE_CONF_CHECK_I(min_voltage_level);
12188 #undef PIPE_CONF_CHECK_X
12189 #undef PIPE_CONF_CHECK_I
12190 #undef PIPE_CONF_CHECK_BOOL
12191 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
12192 #undef PIPE_CONF_CHECK_P
12193 #undef PIPE_CONF_CHECK_FLAGS
12194 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
12195 #undef PIPE_CONF_QUIRK
12200 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
12201 const struct intel_crtc_state *pipe_config)
12203 if (pipe_config->has_pch_encoder) {
12204 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
12205 &pipe_config->fdi_m_n);
12206 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
12209 * FDI already provided one idea for the dotclock.
12210 * Yell if the encoder disagrees.
12212 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
12213 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12214 fdi_dotclock, dotclock);
12218 static void verify_wm_state(struct drm_crtc *crtc,
12219 struct drm_crtc_state *new_state)
12221 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
12222 struct skl_ddb_allocation hw_ddb, *sw_ddb;
12223 struct skl_pipe_wm hw_wm, *sw_wm;
12224 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
12225 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
12226 struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES];
12227 struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES];
12228 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12229 const enum pipe pipe = intel_crtc->pipe;
12230 int plane, level, max_level = ilk_wm_max_level(dev_priv);
12232 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
12235 skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm);
12236 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
12238 skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv);
12240 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
12241 sw_ddb = &dev_priv->wm.skl_hw.ddb;
12243 if (INTEL_GEN(dev_priv) >= 11)
12244 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
12245 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
12246 sw_ddb->enabled_slices,
12247 hw_ddb.enabled_slices);
12249 for_each_universal_plane(dev_priv, pipe, plane) {
12250 hw_plane_wm = &hw_wm.planes[plane];
12251 sw_plane_wm = &sw_wm->planes[plane];
12254 for (level = 0; level <= max_level; level++) {
12255 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12256 &sw_plane_wm->wm[level]))
12259 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",
12260 pipe_name(pipe), plane + 1, level,
12261 sw_plane_wm->wm[level].plane_en,
12262 sw_plane_wm->wm[level].plane_res_b,
12263 sw_plane_wm->wm[level].plane_res_l,
12264 hw_plane_wm->wm[level].plane_en,
12265 hw_plane_wm->wm[level].plane_res_b,
12266 hw_plane_wm->wm[level].plane_res_l);
12269 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12270 &sw_plane_wm->trans_wm)) {
12271 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",
12272 pipe_name(pipe), plane + 1,
12273 sw_plane_wm->trans_wm.plane_en,
12274 sw_plane_wm->trans_wm.plane_res_b,
12275 sw_plane_wm->trans_wm.plane_res_l,
12276 hw_plane_wm->trans_wm.plane_en,
12277 hw_plane_wm->trans_wm.plane_res_b,
12278 hw_plane_wm->trans_wm.plane_res_l);
12282 hw_ddb_entry = &hw_ddb_y[plane];
12283 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane];
12285 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12286 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
12287 pipe_name(pipe), plane + 1,
12288 sw_ddb_entry->start, sw_ddb_entry->end,
12289 hw_ddb_entry->start, hw_ddb_entry->end);
12295 * If the cursor plane isn't active, we may not have updated it's ddb
12296 * allocation. In that case since the ddb allocation will be updated
12297 * once the plane becomes visible, we can skip this check
12300 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
12301 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
12304 for (level = 0; level <= max_level; level++) {
12305 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12306 &sw_plane_wm->wm[level]))
12309 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",
12310 pipe_name(pipe), level,
12311 sw_plane_wm->wm[level].plane_en,
12312 sw_plane_wm->wm[level].plane_res_b,
12313 sw_plane_wm->wm[level].plane_res_l,
12314 hw_plane_wm->wm[level].plane_en,
12315 hw_plane_wm->wm[level].plane_res_b,
12316 hw_plane_wm->wm[level].plane_res_l);
12319 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12320 &sw_plane_wm->trans_wm)) {
12321 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12323 sw_plane_wm->trans_wm.plane_en,
12324 sw_plane_wm->trans_wm.plane_res_b,
12325 sw_plane_wm->trans_wm.plane_res_l,
12326 hw_plane_wm->trans_wm.plane_en,
12327 hw_plane_wm->trans_wm.plane_res_b,
12328 hw_plane_wm->trans_wm.plane_res_l);
12332 hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR];
12333 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR];
12335 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
12336 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
12338 sw_ddb_entry->start, sw_ddb_entry->end,
12339 hw_ddb_entry->start, hw_ddb_entry->end);
12345 verify_connector_state(struct drm_device *dev,
12346 struct drm_atomic_state *state,
12347 struct drm_crtc *crtc)
12349 struct drm_connector *connector;
12350 struct drm_connector_state *new_conn_state;
12353 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
12354 struct drm_encoder *encoder = connector->encoder;
12355 struct drm_crtc_state *crtc_state = NULL;
12357 if (new_conn_state->crtc != crtc)
12361 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
12363 intel_connector_verify_state(crtc_state, new_conn_state);
12365 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
12366 "connector's atomic encoder doesn't match legacy encoder\n");
12371 verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
12373 struct intel_encoder *encoder;
12374 struct drm_connector *connector;
12375 struct drm_connector_state *old_conn_state, *new_conn_state;
12378 for_each_intel_encoder(dev, encoder) {
12379 bool enabled = false, found = false;
12382 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12383 encoder->base.base.id,
12384 encoder->base.name);
12386 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
12387 new_conn_state, i) {
12388 if (old_conn_state->best_encoder == &encoder->base)
12391 if (new_conn_state->best_encoder != &encoder->base)
12393 found = enabled = true;
12395 I915_STATE_WARN(new_conn_state->crtc !=
12396 encoder->base.crtc,
12397 "connector's crtc doesn't match encoder crtc\n");
12403 I915_STATE_WARN(!!encoder->base.crtc != enabled,
12404 "encoder's enabled state mismatch "
12405 "(expected %i, found %i)\n",
12406 !!encoder->base.crtc, enabled);
12408 if (!encoder->base.crtc) {
12411 active = encoder->get_hw_state(encoder, &pipe);
12412 I915_STATE_WARN(active,
12413 "encoder detached but still enabled on pipe %c.\n",
12420 verify_crtc_state(struct drm_crtc *crtc,
12421 struct drm_crtc_state *old_crtc_state,
12422 struct drm_crtc_state *new_crtc_state)
12424 struct drm_device *dev = crtc->dev;
12425 struct drm_i915_private *dev_priv = to_i915(dev);
12426 struct intel_encoder *encoder;
12427 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12428 struct intel_crtc_state *pipe_config, *sw_config;
12429 struct drm_atomic_state *old_state;
12432 old_state = old_crtc_state->state;
12433 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
12434 pipe_config = to_intel_crtc_state(old_crtc_state);
12435 memset(pipe_config, 0, sizeof(*pipe_config));
12436 pipe_config->base.crtc = crtc;
12437 pipe_config->base.state = old_state;
12439 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
12441 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
12443 /* we keep both pipes enabled on 830 */
12444 if (IS_I830(dev_priv))
12445 active = new_crtc_state->active;
12447 I915_STATE_WARN(new_crtc_state->active != active,
12448 "crtc active state doesn't match with hw state "
12449 "(expected %i, found %i)\n", new_crtc_state->active, active);
12451 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12452 "transitional active state does not match atomic hw state "
12453 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
12455 for_each_encoder_on_crtc(dev, crtc, encoder) {
12458 active = encoder->get_hw_state(encoder, &pipe);
12459 I915_STATE_WARN(active != new_crtc_state->active,
12460 "[ENCODER:%i] active %i with crtc active %i\n",
12461 encoder->base.base.id, active, new_crtc_state->active);
12463 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12464 "Encoder connected to wrong pipe %c\n",
12468 encoder->get_config(encoder, pipe_config);
12471 intel_crtc_compute_pixel_rate(pipe_config);
12473 if (!new_crtc_state->active)
12476 intel_pipe_config_sanity_check(dev_priv, pipe_config);
12478 sw_config = to_intel_crtc_state(new_crtc_state);
12479 if (!intel_pipe_config_compare(dev_priv, sw_config,
12480 pipe_config, false)) {
12481 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12482 intel_dump_pipe_config(intel_crtc, pipe_config,
12484 intel_dump_pipe_config(intel_crtc, sw_config,
12490 intel_verify_planes(struct intel_atomic_state *state)
12492 struct intel_plane *plane;
12493 const struct intel_plane_state *plane_state;
12496 for_each_new_intel_plane_in_state(state, plane,
12498 assert_plane(plane, plane_state->base.visible);
12502 verify_single_dpll_state(struct drm_i915_private *dev_priv,
12503 struct intel_shared_dpll *pll,
12504 struct drm_crtc *crtc,
12505 struct drm_crtc_state *new_state)
12507 struct intel_dpll_hw_state dpll_hw_state;
12508 unsigned int crtc_mask;
12511 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12513 DRM_DEBUG_KMS("%s\n", pll->info->name);
12515 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
12517 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
12518 I915_STATE_WARN(!pll->on && pll->active_mask,
12519 "pll in active use but not on in sw tracking\n");
12520 I915_STATE_WARN(pll->on && !pll->active_mask,
12521 "pll is on but not used by any active crtc\n");
12522 I915_STATE_WARN(pll->on != active,
12523 "pll on state mismatch (expected %i, found %i)\n",
12528 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
12529 "more active pll users than references: %x vs %x\n",
12530 pll->active_mask, pll->state.crtc_mask);
12535 crtc_mask = drm_crtc_mask(crtc);
12537 if (new_state->active)
12538 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12539 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12540 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12542 I915_STATE_WARN(pll->active_mask & crtc_mask,
12543 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12544 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12546 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
12547 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
12548 crtc_mask, pll->state.crtc_mask);
12550 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
12552 sizeof(dpll_hw_state)),
12553 "pll hw state mismatch\n");
12557 verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12558 struct drm_crtc_state *old_crtc_state,
12559 struct drm_crtc_state *new_crtc_state)
12561 struct drm_i915_private *dev_priv = to_i915(dev);
12562 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12563 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12565 if (new_state->shared_dpll)
12566 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
12568 if (old_state->shared_dpll &&
12569 old_state->shared_dpll != new_state->shared_dpll) {
12570 unsigned int crtc_mask = drm_crtc_mask(crtc);
12571 struct intel_shared_dpll *pll = old_state->shared_dpll;
12573 I915_STATE_WARN(pll->active_mask & crtc_mask,
12574 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12575 pipe_name(drm_crtc_index(crtc)));
12576 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
12577 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12578 pipe_name(drm_crtc_index(crtc)));
12583 intel_modeset_verify_crtc(struct drm_crtc *crtc,
12584 struct drm_atomic_state *state,
12585 struct drm_crtc_state *old_state,
12586 struct drm_crtc_state *new_state)
12588 if (!needs_modeset(new_state) &&
12589 !to_intel_crtc_state(new_state)->update_pipe)
12592 verify_wm_state(crtc, new_state);
12593 verify_connector_state(crtc->dev, state, crtc);
12594 verify_crtc_state(crtc, old_state, new_state);
12595 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
12599 verify_disabled_dpll_state(struct drm_device *dev)
12601 struct drm_i915_private *dev_priv = to_i915(dev);
12604 for (i = 0; i < dev_priv->num_shared_dpll; i++)
12605 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
12609 intel_modeset_verify_disabled(struct drm_device *dev,
12610 struct drm_atomic_state *state)
12612 verify_encoder_state(dev, state);
12613 verify_connector_state(dev, state, NULL);
12614 verify_disabled_dpll_state(dev);
12617 static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
12619 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
12620 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12623 * The scanline counter increments at the leading edge of hsync.
12625 * On most platforms it starts counting from vtotal-1 on the
12626 * first active line. That means the scanline counter value is
12627 * always one less than what we would expect. Ie. just after
12628 * start of vblank, which also occurs at start of hsync (on the
12629 * last active line), the scanline counter will read vblank_start-1.
12631 * On gen2 the scanline counter starts counting from 1 instead
12632 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12633 * to keep the value positive), instead of adding one.
12635 * On HSW+ the behaviour of the scanline counter depends on the output
12636 * type. For DP ports it behaves like most other platforms, but on HDMI
12637 * there's an extra 1 line difference. So we need to add two instead of
12638 * one to the value.
12640 * On VLV/CHV DSI the scanline counter would appear to increment
12641 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12642 * that means we can't tell whether we're in vblank or not while
12643 * we're on that particular line. We must still set scanline_offset
12644 * to 1 so that the vblank timestamps come out correct when we query
12645 * the scanline counter from within the vblank interrupt handler.
12646 * However if queried just before the start of vblank we'll get an
12647 * answer that's slightly in the future.
12649 if (IS_GEN(dev_priv, 2)) {
12650 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
12653 vtotal = adjusted_mode->crtc_vtotal;
12654 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
12657 crtc->scanline_offset = vtotal - 1;
12658 } else if (HAS_DDI(dev_priv) &&
12659 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
12660 crtc->scanline_offset = 2;
12662 crtc->scanline_offset = 1;
12665 static void intel_modeset_clear_plls(struct drm_atomic_state *state)
12667 struct drm_device *dev = state->dev;
12668 struct drm_i915_private *dev_priv = to_i915(dev);
12669 struct drm_crtc *crtc;
12670 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12673 if (!dev_priv->display.crtc_compute_clock)
12676 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12677 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12678 struct intel_shared_dpll *old_dpll =
12679 to_intel_crtc_state(old_crtc_state)->shared_dpll;
12681 if (!needs_modeset(new_crtc_state))
12684 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
12689 intel_release_shared_dpll(old_dpll, intel_crtc, state);
12694 * This implements the workaround described in the "notes" section of the mode
12695 * set sequence documentation. When going from no pipes or single pipe to
12696 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12697 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12699 static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12701 struct drm_crtc_state *crtc_state;
12702 struct intel_crtc *intel_crtc;
12703 struct drm_crtc *crtc;
12704 struct intel_crtc_state *first_crtc_state = NULL;
12705 struct intel_crtc_state *other_crtc_state = NULL;
12706 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12709 /* look at all crtc's that are going to be enabled in during modeset */
12710 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
12711 intel_crtc = to_intel_crtc(crtc);
12713 if (!crtc_state->active || !needs_modeset(crtc_state))
12716 if (first_crtc_state) {
12717 other_crtc_state = to_intel_crtc_state(crtc_state);
12720 first_crtc_state = to_intel_crtc_state(crtc_state);
12721 first_pipe = intel_crtc->pipe;
12725 /* No workaround needed? */
12726 if (!first_crtc_state)
12729 /* w/a possibly needed, check how many crtc's are already enabled. */
12730 for_each_intel_crtc(state->dev, intel_crtc) {
12731 struct intel_crtc_state *pipe_config;
12733 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12734 if (IS_ERR(pipe_config))
12735 return PTR_ERR(pipe_config);
12737 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12739 if (!pipe_config->base.active ||
12740 needs_modeset(&pipe_config->base))
12743 /* 2 or more enabled crtcs means no need for w/a */
12744 if (enabled_pipe != INVALID_PIPE)
12747 enabled_pipe = intel_crtc->pipe;
12750 if (enabled_pipe != INVALID_PIPE)
12751 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12752 else if (other_crtc_state)
12753 other_crtc_state->hsw_workaround_pipe = first_pipe;
12758 static int intel_lock_all_pipes(struct drm_atomic_state *state)
12760 struct drm_crtc *crtc;
12762 /* Add all pipes to the state */
12763 for_each_crtc(state->dev, crtc) {
12764 struct drm_crtc_state *crtc_state;
12766 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12767 if (IS_ERR(crtc_state))
12768 return PTR_ERR(crtc_state);
12774 static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12776 struct drm_crtc *crtc;
12779 * Add all pipes to the state, and force
12780 * a modeset on all the active ones.
12782 for_each_crtc(state->dev, crtc) {
12783 struct drm_crtc_state *crtc_state;
12786 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12787 if (IS_ERR(crtc_state))
12788 return PTR_ERR(crtc_state);
12790 if (!crtc_state->active || needs_modeset(crtc_state))
12793 crtc_state->mode_changed = true;
12795 ret = drm_atomic_add_affected_connectors(state, crtc);
12799 ret = drm_atomic_add_affected_planes(state, crtc);
12807 static int intel_modeset_checks(struct drm_atomic_state *state)
12809 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12810 struct drm_i915_private *dev_priv = to_i915(state->dev);
12811 struct drm_crtc *crtc;
12812 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
12815 if (!check_digital_port_conflicts(state)) {
12816 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12820 intel_state->modeset = true;
12821 intel_state->active_crtcs = dev_priv->active_crtcs;
12822 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12823 intel_state->cdclk.actual = dev_priv->cdclk.actual;
12825 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12826 if (new_crtc_state->active)
12827 intel_state->active_crtcs |= 1 << i;
12829 intel_state->active_crtcs &= ~(1 << i);
12831 if (old_crtc_state->active != new_crtc_state->active)
12832 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
12836 * See if the config requires any additional preparation, e.g.
12837 * to adjust global state with pipes off. We need to do this
12838 * here so we can get the modeset_pipe updated config for the new
12839 * mode set on this crtc. For other crtcs we need to use the
12840 * adjusted_mode bits in the crtc directly.
12842 if (dev_priv->display.modeset_calc_cdclk) {
12843 ret = dev_priv->display.modeset_calc_cdclk(state);
12848 * Writes to dev_priv->cdclk.logical must protected by
12849 * holding all the crtc locks, even if we don't end up
12850 * touching the hardware
12852 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12853 &intel_state->cdclk.logical)) {
12854 ret = intel_lock_all_pipes(state);
12859 /* All pipes must be switched off while we change the cdclk. */
12860 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12861 &intel_state->cdclk.actual)) {
12862 ret = intel_modeset_all_pipes(state);
12867 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12868 intel_state->cdclk.logical.cdclk,
12869 intel_state->cdclk.actual.cdclk);
12870 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12871 intel_state->cdclk.logical.voltage_level,
12872 intel_state->cdclk.actual.voltage_level);
12874 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
12877 intel_modeset_clear_plls(state);
12879 if (IS_HASWELL(dev_priv))
12880 return haswell_mode_set_planes_workaround(state);
12886 * Handle calculation of various watermark data at the end of the atomic check
12887 * phase. The code here should be run after the per-crtc and per-plane 'check'
12888 * handlers to ensure that all derived state has been updated.
12890 static int calc_watermark_data(struct intel_atomic_state *state)
12892 struct drm_device *dev = state->base.dev;
12893 struct drm_i915_private *dev_priv = to_i915(dev);
12895 /* Is there platform-specific watermark information to calculate? */
12896 if (dev_priv->display.compute_global_watermarks)
12897 return dev_priv->display.compute_global_watermarks(state);
12903 * intel_atomic_check - validate state object
12905 * @state: state to validate
12907 static int intel_atomic_check(struct drm_device *dev,
12908 struct drm_atomic_state *state)
12910 struct drm_i915_private *dev_priv = to_i915(dev);
12911 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12912 struct drm_crtc *crtc;
12913 struct drm_crtc_state *old_crtc_state, *crtc_state;
12915 bool any_ms = false;
12917 /* Catch I915_MODE_FLAG_INHERITED */
12918 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12920 if (crtc_state->mode.private_flags !=
12921 old_crtc_state->mode.private_flags)
12922 crtc_state->mode_changed = true;
12925 ret = drm_atomic_helper_check_modeset(dev, state);
12929 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
12930 struct intel_crtc_state *pipe_config =
12931 to_intel_crtc_state(crtc_state);
12933 if (!needs_modeset(crtc_state))
12936 if (!crtc_state->enable) {
12941 ret = intel_modeset_pipe_config(crtc, pipe_config);
12942 if (ret == -EDEADLK)
12945 intel_dump_pipe_config(to_intel_crtc(crtc),
12946 pipe_config, "[failed]");
12950 if (intel_pipe_config_compare(dev_priv,
12951 to_intel_crtc_state(old_crtc_state),
12952 pipe_config, true)) {
12953 crtc_state->mode_changed = false;
12954 pipe_config->update_pipe = true;
12957 if (needs_modeset(crtc_state))
12960 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12961 needs_modeset(crtc_state) ?
12962 "[modeset]" : "[fastset]");
12965 ret = drm_dp_mst_atomic_check(state);
12970 ret = intel_modeset_checks(state);
12975 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12978 ret = icl_add_linked_planes(intel_state);
12982 ret = drm_atomic_helper_check_planes(dev, state);
12986 intel_fbc_choose_crtc(dev_priv, intel_state);
12987 return calc_watermark_data(intel_state);
12990 static int intel_atomic_prepare_commit(struct drm_device *dev,
12991 struct drm_atomic_state *state)
12993 return drm_atomic_helper_prepare_planes(dev, state);
12996 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12998 struct drm_device *dev = crtc->base.dev;
12999 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
13001 if (!vblank->max_vblank_count)
13002 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
13004 return dev->driver->get_vblank_counter(dev, crtc->pipe);
13007 static void intel_update_crtc(struct drm_crtc *crtc,
13008 struct drm_atomic_state *state,
13009 struct drm_crtc_state *old_crtc_state,
13010 struct drm_crtc_state *new_crtc_state)
13012 struct drm_device *dev = crtc->dev;
13013 struct drm_i915_private *dev_priv = to_i915(dev);
13014 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13015 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
13016 bool modeset = needs_modeset(new_crtc_state);
13017 struct intel_plane_state *new_plane_state =
13018 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
13019 to_intel_plane(crtc->primary));
13022 update_scanline_offset(pipe_config);
13023 dev_priv->display.crtc_enable(pipe_config, state);
13025 /* vblanks work again, re-enable pipe CRC. */
13026 intel_crtc_enable_pipe_crc(intel_crtc);
13028 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
13031 if (pipe_config->update_pipe)
13032 intel_encoders_update_pipe(crtc, pipe_config, state);
13035 if (pipe_config->update_pipe && !pipe_config->enable_fbc)
13036 intel_fbc_disable(intel_crtc);
13037 else if (new_plane_state)
13038 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
13040 intel_begin_crtc_commit(crtc, old_crtc_state);
13042 if (INTEL_GEN(dev_priv) >= 9)
13043 skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
13045 i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
13047 intel_finish_crtc_commit(crtc, old_crtc_state);
13050 static void intel_update_crtcs(struct drm_atomic_state *state)
13052 struct drm_crtc *crtc;
13053 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
13056 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13057 if (!new_crtc_state->active)
13060 intel_update_crtc(crtc, state, old_crtc_state,
13065 static void skl_update_crtcs(struct drm_atomic_state *state)
13067 struct drm_i915_private *dev_priv = to_i915(state->dev);
13068 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13069 struct drm_crtc *crtc;
13070 struct intel_crtc *intel_crtc;
13071 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
13072 struct intel_crtc_state *cstate;
13073 unsigned int updated = 0;
13077 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
13078 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
13079 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
13081 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
13082 /* ignore allocations for crtc's that have been turned off. */
13083 if (new_crtc_state->active)
13084 entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
13086 /* If 2nd DBuf slice required, enable it here */
13087 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
13088 icl_dbuf_slices_update(dev_priv, required_slices);
13091 * Whenever the number of active pipes changes, we need to make sure we
13092 * update the pipes in the right order so that their ddb allocations
13093 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
13094 * cause pipe underruns and other bad stuff.
13099 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13100 bool vbl_wait = false;
13101 unsigned int cmask = drm_crtc_mask(crtc);
13103 intel_crtc = to_intel_crtc(crtc);
13104 cstate = to_intel_crtc_state(new_crtc_state);
13105 pipe = intel_crtc->pipe;
13107 if (updated & cmask || !cstate->base.active)
13110 if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb,
13112 INTEL_INFO(dev_priv)->num_pipes, i))
13116 entries[i] = cstate->wm.skl.ddb;
13119 * If this is an already active pipe, it's DDB changed,
13120 * and this isn't the last pipe that needs updating
13121 * then we need to wait for a vblank to pass for the
13122 * new ddb allocation to take effect.
13124 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
13125 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
13126 !new_crtc_state->active_changed &&
13127 intel_state->wm_results.dirty_pipes != updated)
13130 intel_update_crtc(crtc, state, old_crtc_state,
13134 intel_wait_for_vblank(dev_priv, pipe);
13138 } while (progress);
13140 /* If 2nd DBuf slice is no more required disable it */
13141 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
13142 icl_dbuf_slices_update(dev_priv, required_slices);
13145 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
13147 struct intel_atomic_state *state, *next;
13148 struct llist_node *freed;
13150 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
13151 llist_for_each_entry_safe(state, next, freed, freed)
13152 drm_atomic_state_put(&state->base);
13155 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
13157 struct drm_i915_private *dev_priv =
13158 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
13160 intel_atomic_helper_free_state(dev_priv);
13163 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
13165 struct wait_queue_entry wait_fence, wait_reset;
13166 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
13168 init_wait_entry(&wait_fence, 0);
13169 init_wait_entry(&wait_reset, 0);
13171 prepare_to_wait(&intel_state->commit_ready.wait,
13172 &wait_fence, TASK_UNINTERRUPTIBLE);
13173 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
13174 &wait_reset, TASK_UNINTERRUPTIBLE);
13177 if (i915_sw_fence_done(&intel_state->commit_ready)
13178 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
13183 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
13184 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
13187 static void intel_atomic_cleanup_work(struct work_struct *work)
13189 struct drm_atomic_state *state =
13190 container_of(work, struct drm_atomic_state, commit_work);
13191 struct drm_i915_private *i915 = to_i915(state->dev);
13193 drm_atomic_helper_cleanup_planes(&i915->drm, state);
13194 drm_atomic_helper_commit_cleanup_done(state);
13195 drm_atomic_state_put(state);
13197 intel_atomic_helper_free_state(i915);
13200 static void intel_atomic_commit_tail(struct drm_atomic_state *state)
13202 struct drm_device *dev = state->dev;
13203 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13204 struct drm_i915_private *dev_priv = to_i915(dev);
13205 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
13206 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
13207 struct drm_crtc *crtc;
13208 struct intel_crtc *intel_crtc;
13209 u64 put_domains[I915_MAX_PIPES] = {};
13210 intel_wakeref_t wakeref = 0;
13213 intel_atomic_commit_fence_wait(intel_state);
13215 drm_atomic_helper_wait_for_dependencies(state);
13217 if (intel_state->modeset)
13218 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
13220 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13221 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
13222 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13223 intel_crtc = to_intel_crtc(crtc);
13225 if (needs_modeset(new_crtc_state) ||
13226 to_intel_crtc_state(new_crtc_state)->update_pipe) {
13228 put_domains[intel_crtc->pipe] =
13229 modeset_get_crtc_power_domains(crtc,
13230 new_intel_crtc_state);
13233 if (!needs_modeset(new_crtc_state))
13236 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
13238 if (old_crtc_state->active) {
13239 intel_crtc_disable_planes(intel_state, intel_crtc);
13242 * We need to disable pipe CRC before disabling the pipe,
13243 * or we race against vblank off.
13245 intel_crtc_disable_pipe_crc(intel_crtc);
13247 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
13248 intel_crtc->active = false;
13249 intel_fbc_disable(intel_crtc);
13250 intel_disable_shared_dpll(old_intel_crtc_state);
13253 * Underruns don't always raise
13254 * interrupts, so check manually.
13256 intel_check_cpu_fifo_underruns(dev_priv);
13257 intel_check_pch_fifo_underruns(dev_priv);
13259 /* FIXME unify this for all platforms */
13260 if (!new_crtc_state->active &&
13261 !HAS_GMCH(dev_priv) &&
13262 dev_priv->display.initial_watermarks)
13263 dev_priv->display.initial_watermarks(intel_state,
13264 new_intel_crtc_state);
13268 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
13269 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
13270 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
13272 if (intel_state->modeset) {
13273 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
13275 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
13278 * SKL workaround: bspec recommends we disable the SAGV when we
13279 * have more then one pipe enabled
13281 if (!intel_can_enable_sagv(state))
13282 intel_disable_sagv(dev_priv);
13284 intel_modeset_verify_disabled(dev, state);
13287 /* Complete the events for pipes that have now been disabled */
13288 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13289 bool modeset = needs_modeset(new_crtc_state);
13291 /* Complete events for now disable pipes here. */
13292 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
13293 spin_lock_irq(&dev->event_lock);
13294 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
13295 spin_unlock_irq(&dev->event_lock);
13297 new_crtc_state->event = NULL;
13301 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13302 dev_priv->display.update_crtcs(state);
13304 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13305 * already, but still need the state for the delayed optimization. To
13307 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13308 * - schedule that vblank worker _before_ calling hw_done
13309 * - at the start of commit_tail, cancel it _synchrously
13310 * - switch over to the vblank wait helper in the core after that since
13311 * we don't need out special handling any more.
13313 drm_atomic_helper_wait_for_flip_done(dev, state);
13315 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13316 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13318 if (new_crtc_state->active &&
13319 !needs_modeset(new_crtc_state) &&
13320 (new_intel_crtc_state->base.color_mgmt_changed ||
13321 new_intel_crtc_state->update_pipe))
13322 intel_color_load_luts(new_intel_crtc_state);
13326 * Now that the vblank has passed, we can go ahead and program the
13327 * optimal watermarks on platforms that need two-step watermark
13330 * TODO: Move this (and other cleanup) to an async worker eventually.
13332 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13333 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13335 if (dev_priv->display.optimize_watermarks)
13336 dev_priv->display.optimize_watermarks(intel_state,
13337 new_intel_crtc_state);
13340 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13341 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
13343 if (put_domains[i])
13344 modeset_put_power_domains(dev_priv, put_domains[i]);
13346 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
13349 if (intel_state->modeset)
13350 intel_verify_planes(intel_state);
13352 if (intel_state->modeset && intel_can_enable_sagv(state))
13353 intel_enable_sagv(dev_priv);
13355 drm_atomic_helper_commit_hw_done(state);
13357 if (intel_state->modeset) {
13358 /* As one of the primary mmio accessors, KMS has a high
13359 * likelihood of triggering bugs in unclaimed access. After we
13360 * finish modesetting, see if an error has been flagged, and if
13361 * so enable debugging for the next modeset - and hope we catch
13364 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
13365 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
13369 * Defer the cleanup of the old state to a separate worker to not
13370 * impede the current task (userspace for blocking modesets) that
13371 * are executed inline. For out-of-line asynchronous modesets/flips,
13372 * deferring to a new worker seems overkill, but we would place a
13373 * schedule point (cond_resched()) here anyway to keep latencies
13376 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
13377 queue_work(system_highpri_wq, &state->commit_work);
13380 static void intel_atomic_commit_work(struct work_struct *work)
13382 struct drm_atomic_state *state =
13383 container_of(work, struct drm_atomic_state, commit_work);
13385 intel_atomic_commit_tail(state);
13388 static int __i915_sw_fence_call
13389 intel_atomic_commit_ready(struct i915_sw_fence *fence,
13390 enum i915_sw_fence_notify notify)
13392 struct intel_atomic_state *state =
13393 container_of(fence, struct intel_atomic_state, commit_ready);
13396 case FENCE_COMPLETE:
13397 /* we do blocking waits in the worker, nothing to do here */
13401 struct intel_atomic_helper *helper =
13402 &to_i915(state->base.dev)->atomic_helper;
13404 if (llist_add(&state->freed, &helper->free_list))
13405 schedule_work(&helper->free_work);
13410 return NOTIFY_DONE;
13413 static void intel_atomic_track_fbs(struct drm_atomic_state *state)
13415 struct drm_plane_state *old_plane_state, *new_plane_state;
13416 struct drm_plane *plane;
13419 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
13420 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
13421 intel_fb_obj(new_plane_state->fb),
13422 to_intel_plane(plane)->frontbuffer_bit);
13426 * intel_atomic_commit - commit validated state object
13428 * @state: the top-level driver state object
13429 * @nonblock: nonblocking commit
13431 * This function commits a top-level state object that has been validated
13432 * with drm_atomic_helper_check().
13435 * Zero for success or -errno.
13437 static int intel_atomic_commit(struct drm_device *dev,
13438 struct drm_atomic_state *state,
13441 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13442 struct drm_i915_private *dev_priv = to_i915(dev);
13445 drm_atomic_state_get(state);
13446 i915_sw_fence_init(&intel_state->commit_ready,
13447 intel_atomic_commit_ready);
13450 * The intel_legacy_cursor_update() fast path takes care
13451 * of avoiding the vblank waits for simple cursor
13452 * movement and flips. For cursor on/off and size changes,
13453 * we want to perform the vblank waits so that watermark
13454 * updates happen during the correct frames. Gen9+ have
13455 * double buffered watermarks and so shouldn't need this.
13457 * Unset state->legacy_cursor_update before the call to
13458 * drm_atomic_helper_setup_commit() because otherwise
13459 * drm_atomic_helper_wait_for_flip_done() is a noop and
13460 * we get FIFO underruns because we didn't wait
13463 * FIXME doing watermarks and fb cleanup from a vblank worker
13464 * (assuming we had any) would solve these problems.
13466 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13467 struct intel_crtc_state *new_crtc_state;
13468 struct intel_crtc *crtc;
13471 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13472 if (new_crtc_state->wm.need_postvbl_update ||
13473 new_crtc_state->update_wm_post)
13474 state->legacy_cursor_update = false;
13477 ret = intel_atomic_prepare_commit(dev, state);
13479 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13480 i915_sw_fence_commit(&intel_state->commit_ready);
13484 ret = drm_atomic_helper_setup_commit(state, nonblock);
13486 ret = drm_atomic_helper_swap_state(state, true);
13489 i915_sw_fence_commit(&intel_state->commit_ready);
13491 drm_atomic_helper_cleanup_planes(dev, state);
13494 dev_priv->wm.distrust_bios_wm = false;
13495 intel_shared_dpll_swap_state(state);
13496 intel_atomic_track_fbs(state);
13498 if (intel_state->modeset) {
13499 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13500 sizeof(intel_state->min_cdclk));
13501 memcpy(dev_priv->min_voltage_level,
13502 intel_state->min_voltage_level,
13503 sizeof(intel_state->min_voltage_level));
13504 dev_priv->active_crtcs = intel_state->active_crtcs;
13505 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13506 dev_priv->cdclk.actual = intel_state->cdclk.actual;
13509 drm_atomic_state_get(state);
13510 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
13512 i915_sw_fence_commit(&intel_state->commit_ready);
13513 if (nonblock && intel_state->modeset) {
13514 queue_work(dev_priv->modeset_wq, &state->commit_work);
13515 } else if (nonblock) {
13516 queue_work(system_unbound_wq, &state->commit_work);
13518 if (intel_state->modeset)
13519 flush_workqueue(dev_priv->modeset_wq);
13520 intel_atomic_commit_tail(state);
13526 static const struct drm_crtc_funcs intel_crtc_funcs = {
13527 .gamma_set = drm_atomic_helper_legacy_gamma_set,
13528 .set_config = drm_atomic_helper_set_config,
13529 .destroy = intel_crtc_destroy,
13530 .page_flip = drm_atomic_helper_page_flip,
13531 .atomic_duplicate_state = intel_crtc_duplicate_state,
13532 .atomic_destroy_state = intel_crtc_destroy_state,
13533 .set_crc_source = intel_crtc_set_crc_source,
13534 .verify_crc_source = intel_crtc_verify_crc_source,
13535 .get_crc_sources = intel_crtc_get_crc_sources,
13538 struct wait_rps_boost {
13539 struct wait_queue_entry wait;
13541 struct drm_crtc *crtc;
13542 struct i915_request *request;
13545 static int do_rps_boost(struct wait_queue_entry *_wait,
13546 unsigned mode, int sync, void *key)
13548 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
13549 struct i915_request *rq = wait->request;
13552 * If we missed the vblank, but the request is already running it
13553 * is reasonable to assume that it will complete before the next
13554 * vblank without our intervention, so leave RPS alone.
13556 if (!i915_request_started(rq))
13557 gen6_rps_boost(rq, NULL);
13558 i915_request_put(rq);
13560 drm_crtc_vblank_put(wait->crtc);
13562 list_del(&wait->wait.entry);
13567 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13568 struct dma_fence *fence)
13570 struct wait_rps_boost *wait;
13572 if (!dma_fence_is_i915(fence))
13575 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13578 if (drm_crtc_vblank_get(crtc))
13581 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13583 drm_crtc_vblank_put(crtc);
13587 wait->request = to_request(dma_fence_get(fence));
13590 wait->wait.func = do_rps_boost;
13591 wait->wait.flags = 0;
13593 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13596 static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13598 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13599 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13600 struct drm_framebuffer *fb = plane_state->base.fb;
13601 struct i915_vma *vma;
13603 if (plane->id == PLANE_CURSOR &&
13604 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
13605 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13606 const int align = intel_cursor_alignment(dev_priv);
13609 err = i915_gem_object_attach_phys(obj, align);
13614 vma = intel_pin_and_fence_fb_obj(fb,
13615 &plane_state->view,
13616 intel_plane_uses_fence(plane_state),
13617 &plane_state->flags);
13619 return PTR_ERR(vma);
13621 plane_state->vma = vma;
13626 static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13628 struct i915_vma *vma;
13630 vma = fetch_and_zero(&old_plane_state->vma);
13632 intel_unpin_fb_vma(vma, old_plane_state->flags);
13635 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13637 struct i915_sched_attr attr = {
13638 .priority = I915_PRIORITY_DISPLAY,
13641 i915_gem_object_wait_priority(obj, 0, &attr);
13645 * intel_prepare_plane_fb - Prepare fb for usage on plane
13646 * @plane: drm plane to prepare for
13647 * @new_state: the plane state being prepared
13649 * Prepares a framebuffer for usage on a display plane. Generally this
13650 * involves pinning the underlying object and updating the frontbuffer tracking
13651 * bits. Some older platforms need special physical address handling for
13654 * Must be called with struct_mutex held.
13656 * Returns 0 on success, negative error code on failure.
13659 intel_prepare_plane_fb(struct drm_plane *plane,
13660 struct drm_plane_state *new_state)
13662 struct intel_atomic_state *intel_state =
13663 to_intel_atomic_state(new_state->state);
13664 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13665 struct drm_framebuffer *fb = new_state->fb;
13666 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13667 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
13671 struct drm_crtc_state *crtc_state =
13672 drm_atomic_get_new_crtc_state(new_state->state,
13673 plane->state->crtc);
13675 /* Big Hammer, we also need to ensure that any pending
13676 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13677 * current scanout is retired before unpinning the old
13678 * framebuffer. Note that we rely on userspace rendering
13679 * into the buffer attached to the pipe they are waiting
13680 * on. If not, userspace generates a GPU hang with IPEHR
13681 * point to the MI_WAIT_FOR_EVENT.
13683 * This should only fail upon a hung GPU, in which case we
13684 * can safely continue.
13686 if (needs_modeset(crtc_state)) {
13687 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13688 old_obj->resv, NULL,
13696 if (new_state->fence) { /* explicit fencing */
13697 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13699 I915_FENCE_TIMEOUT,
13708 ret = i915_gem_object_pin_pages(obj);
13712 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13714 i915_gem_object_unpin_pages(obj);
13718 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
13720 mutex_unlock(&dev_priv->drm.struct_mutex);
13721 i915_gem_object_unpin_pages(obj);
13725 fb_obj_bump_render_priority(obj);
13726 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13728 if (!new_state->fence) { /* implicit fencing */
13729 struct dma_fence *fence;
13731 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13733 false, I915_FENCE_TIMEOUT,
13738 fence = reservation_object_get_excl_rcu(obj->resv);
13740 add_rps_boost_after_vblank(new_state->crtc, fence);
13741 dma_fence_put(fence);
13744 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
13748 * We declare pageflips to be interactive and so merit a small bias
13749 * towards upclocking to deliver the frame on time. By only changing
13750 * the RPS thresholds to sample more regularly and aim for higher
13751 * clocks we can hopefully deliver low power workloads (like kodi)
13752 * that are not quite steady state without resorting to forcing
13753 * maximum clocks following a vblank miss (see do_rps_boost()).
13755 if (!intel_state->rps_interactive) {
13756 intel_rps_mark_interactive(dev_priv, true);
13757 intel_state->rps_interactive = true;
13764 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13765 * @plane: drm plane to clean up for
13766 * @old_state: the state from the previous modeset
13768 * Cleans up a framebuffer that has just been removed from a plane.
13770 * Must be called with struct_mutex held.
13773 intel_cleanup_plane_fb(struct drm_plane *plane,
13774 struct drm_plane_state *old_state)
13776 struct intel_atomic_state *intel_state =
13777 to_intel_atomic_state(old_state->state);
13778 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13780 if (intel_state->rps_interactive) {
13781 intel_rps_mark_interactive(dev_priv, false);
13782 intel_state->rps_interactive = false;
13785 /* Should only be called after a successful intel_prepare_plane_fb()! */
13786 mutex_lock(&dev_priv->drm.struct_mutex);
13787 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13788 mutex_unlock(&dev_priv->drm.struct_mutex);
13792 skl_max_scale(const struct intel_crtc_state *crtc_state,
13795 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13797 int max_scale, mult;
13798 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
13800 if (!crtc_state->base.enable)
13801 return DRM_PLANE_HELPER_NO_SCALING;
13803 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13804 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13806 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
13809 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
13810 return DRM_PLANE_HELPER_NO_SCALING;
13813 * skl max scale is lower of:
13814 * close to 3 but not 3, -1 is for that purpose
13818 mult = is_planar_yuv_format(pixel_format) ? 2 : 3;
13819 tmpclk1 = (1 << 16) * mult - 1;
13820 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13821 max_scale = min(tmpclk1, tmpclk2);
13826 static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13827 struct drm_crtc_state *old_crtc_state)
13829 struct drm_device *dev = crtc->dev;
13830 struct drm_i915_private *dev_priv = to_i915(dev);
13831 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13832 struct intel_crtc_state *old_intel_cstate =
13833 to_intel_crtc_state(old_crtc_state);
13834 struct intel_atomic_state *old_intel_state =
13835 to_intel_atomic_state(old_crtc_state->state);
13836 struct intel_crtc_state *intel_cstate =
13837 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13838 bool modeset = needs_modeset(&intel_cstate->base);
13840 /* Perform vblank evasion around commit operation */
13841 intel_pipe_update_start(intel_cstate);
13846 if (intel_cstate->base.color_mgmt_changed ||
13847 intel_cstate->update_pipe)
13848 intel_color_commit(intel_cstate);
13850 if (intel_cstate->update_pipe)
13851 intel_update_pipe_config(old_intel_cstate, intel_cstate);
13852 else if (INTEL_GEN(dev_priv) >= 9)
13853 skl_detach_scalers(intel_cstate);
13856 if (dev_priv->display.atomic_update_watermarks)
13857 dev_priv->display.atomic_update_watermarks(old_intel_state,
13861 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13862 struct intel_crtc_state *crtc_state)
13864 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13866 if (!IS_GEN(dev_priv, 2))
13867 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13869 if (crtc_state->has_pch_encoder) {
13870 enum pipe pch_transcoder =
13871 intel_crtc_pch_transcoder(crtc);
13873 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13877 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13878 struct drm_crtc_state *old_crtc_state)
13880 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13881 struct intel_atomic_state *old_intel_state =
13882 to_intel_atomic_state(old_crtc_state->state);
13883 struct intel_crtc_state *new_crtc_state =
13884 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13886 intel_pipe_update_end(new_crtc_state);
13888 if (new_crtc_state->update_pipe &&
13889 !needs_modeset(&new_crtc_state->base) &&
13890 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13891 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
13895 * intel_plane_destroy - destroy a plane
13896 * @plane: plane to destroy
13898 * Common destruction function for all types of planes (primary, cursor,
13901 void intel_plane_destroy(struct drm_plane *plane)
13903 drm_plane_cleanup(plane);
13904 kfree(to_intel_plane(plane));
13907 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13908 u32 format, u64 modifier)
13910 switch (modifier) {
13911 case DRM_FORMAT_MOD_LINEAR:
13912 case I915_FORMAT_MOD_X_TILED:
13919 case DRM_FORMAT_C8:
13920 case DRM_FORMAT_RGB565:
13921 case DRM_FORMAT_XRGB1555:
13922 case DRM_FORMAT_XRGB8888:
13923 return modifier == DRM_FORMAT_MOD_LINEAR ||
13924 modifier == I915_FORMAT_MOD_X_TILED;
13930 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13931 u32 format, u64 modifier)
13933 switch (modifier) {
13934 case DRM_FORMAT_MOD_LINEAR:
13935 case I915_FORMAT_MOD_X_TILED:
13942 case DRM_FORMAT_C8:
13943 case DRM_FORMAT_RGB565:
13944 case DRM_FORMAT_XRGB8888:
13945 case DRM_FORMAT_XBGR8888:
13946 case DRM_FORMAT_XRGB2101010:
13947 case DRM_FORMAT_XBGR2101010:
13948 return modifier == DRM_FORMAT_MOD_LINEAR ||
13949 modifier == I915_FORMAT_MOD_X_TILED;
13955 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13956 u32 format, u64 modifier)
13958 return modifier == DRM_FORMAT_MOD_LINEAR &&
13959 format == DRM_FORMAT_ARGB8888;
13962 static const struct drm_plane_funcs i965_plane_funcs = {
13963 .update_plane = drm_atomic_helper_update_plane,
13964 .disable_plane = drm_atomic_helper_disable_plane,
13965 .destroy = intel_plane_destroy,
13966 .atomic_get_property = intel_plane_atomic_get_property,
13967 .atomic_set_property = intel_plane_atomic_set_property,
13968 .atomic_duplicate_state = intel_plane_duplicate_state,
13969 .atomic_destroy_state = intel_plane_destroy_state,
13970 .format_mod_supported = i965_plane_format_mod_supported,
13973 static const struct drm_plane_funcs i8xx_plane_funcs = {
13974 .update_plane = drm_atomic_helper_update_plane,
13975 .disable_plane = drm_atomic_helper_disable_plane,
13976 .destroy = intel_plane_destroy,
13977 .atomic_get_property = intel_plane_atomic_get_property,
13978 .atomic_set_property = intel_plane_atomic_set_property,
13979 .atomic_duplicate_state = intel_plane_duplicate_state,
13980 .atomic_destroy_state = intel_plane_destroy_state,
13981 .format_mod_supported = i8xx_plane_format_mod_supported,
13985 intel_legacy_cursor_update(struct drm_plane *plane,
13986 struct drm_crtc *crtc,
13987 struct drm_framebuffer *fb,
13988 int crtc_x, int crtc_y,
13989 unsigned int crtc_w, unsigned int crtc_h,
13990 u32 src_x, u32 src_y,
13991 u32 src_w, u32 src_h,
13992 struct drm_modeset_acquire_ctx *ctx)
13994 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13996 struct drm_plane_state *old_plane_state, *new_plane_state;
13997 struct intel_plane *intel_plane = to_intel_plane(plane);
13998 struct drm_framebuffer *old_fb;
13999 struct intel_crtc_state *crtc_state =
14000 to_intel_crtc_state(crtc->state);
14001 struct intel_crtc_state *new_crtc_state;
14004 * When crtc is inactive or there is a modeset pending,
14005 * wait for it to complete in the slowpath
14007 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
14008 crtc_state->update_pipe)
14011 old_plane_state = plane->state;
14013 * Don't do an async update if there is an outstanding commit modifying
14014 * the plane. This prevents our async update's changes from getting
14015 * overridden by a previous synchronous update's state.
14017 if (old_plane_state->commit &&
14018 !try_wait_for_completion(&old_plane_state->commit->hw_done))
14022 * If any parameters change that may affect watermarks,
14023 * take the slowpath. Only changing fb or position should be
14026 if (old_plane_state->crtc != crtc ||
14027 old_plane_state->src_w != src_w ||
14028 old_plane_state->src_h != src_h ||
14029 old_plane_state->crtc_w != crtc_w ||
14030 old_plane_state->crtc_h != crtc_h ||
14031 !old_plane_state->fb != !fb)
14034 new_plane_state = intel_plane_duplicate_state(plane);
14035 if (!new_plane_state)
14038 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
14039 if (!new_crtc_state) {
14044 drm_atomic_set_fb_for_plane(new_plane_state, fb);
14046 new_plane_state->src_x = src_x;
14047 new_plane_state->src_y = src_y;
14048 new_plane_state->src_w = src_w;
14049 new_plane_state->src_h = src_h;
14050 new_plane_state->crtc_x = crtc_x;
14051 new_plane_state->crtc_y = crtc_y;
14052 new_plane_state->crtc_w = crtc_w;
14053 new_plane_state->crtc_h = crtc_h;
14055 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
14056 to_intel_plane_state(old_plane_state),
14057 to_intel_plane_state(new_plane_state));
14061 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14065 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
14069 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
14071 old_fb = old_plane_state->fb;
14072 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
14073 intel_plane->frontbuffer_bit);
14075 /* Swap plane state */
14076 plane->state = new_plane_state;
14079 * We cannot swap crtc_state as it may be in use by an atomic commit or
14080 * page flip that's running simultaneously. If we swap crtc_state and
14081 * destroy the old state, we will cause a use-after-free there.
14083 * Only update active_planes, which is needed for our internal
14084 * bookkeeping. Either value will do the right thing when updating
14085 * planes atomically. If the cursor was part of the atomic update then
14086 * we would have taken the slowpath.
14088 crtc_state->active_planes = new_crtc_state->active_planes;
14090 if (plane->state->visible) {
14091 trace_intel_update_plane(plane, to_intel_crtc(crtc));
14092 intel_plane->update_plane(intel_plane, crtc_state,
14093 to_intel_plane_state(plane->state));
14095 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
14096 intel_plane->disable_plane(intel_plane, crtc_state);
14099 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
14102 mutex_unlock(&dev_priv->drm.struct_mutex);
14104 if (new_crtc_state)
14105 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
14107 intel_plane_destroy_state(plane, new_plane_state);
14109 intel_plane_destroy_state(plane, old_plane_state);
14113 return drm_atomic_helper_update_plane(plane, crtc, fb,
14114 crtc_x, crtc_y, crtc_w, crtc_h,
14115 src_x, src_y, src_w, src_h, ctx);
14118 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
14119 .update_plane = intel_legacy_cursor_update,
14120 .disable_plane = drm_atomic_helper_disable_plane,
14121 .destroy = intel_plane_destroy,
14122 .atomic_get_property = intel_plane_atomic_get_property,
14123 .atomic_set_property = intel_plane_atomic_set_property,
14124 .atomic_duplicate_state = intel_plane_duplicate_state,
14125 .atomic_destroy_state = intel_plane_destroy_state,
14126 .format_mod_supported = intel_cursor_format_mod_supported,
14129 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
14130 enum i9xx_plane_id i9xx_plane)
14132 if (!HAS_FBC(dev_priv))
14135 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14136 return i9xx_plane == PLANE_A; /* tied to pipe A */
14137 else if (IS_IVYBRIDGE(dev_priv))
14138 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
14139 i9xx_plane == PLANE_C;
14140 else if (INTEL_GEN(dev_priv) >= 4)
14141 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
14143 return i9xx_plane == PLANE_A;
14146 static struct intel_plane *
14147 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
14149 struct intel_plane *plane;
14150 const struct drm_plane_funcs *plane_funcs;
14151 unsigned int supported_rotations;
14152 unsigned int possible_crtcs;
14153 const u64 *modifiers;
14154 const u32 *formats;
14158 if (INTEL_GEN(dev_priv) >= 9)
14159 return skl_universal_plane_create(dev_priv, pipe,
14162 plane = intel_plane_alloc();
14166 plane->pipe = pipe;
14168 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
14169 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
14171 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
14172 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
14174 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
14175 plane->id = PLANE_PRIMARY;
14176 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
14178 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
14179 if (plane->has_fbc) {
14180 struct intel_fbc *fbc = &dev_priv->fbc;
14182 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
14185 if (INTEL_GEN(dev_priv) >= 4) {
14186 formats = i965_primary_formats;
14187 num_formats = ARRAY_SIZE(i965_primary_formats);
14188 modifiers = i9xx_format_modifiers;
14190 plane->max_stride = i9xx_plane_max_stride;
14191 plane->update_plane = i9xx_update_plane;
14192 plane->disable_plane = i9xx_disable_plane;
14193 plane->get_hw_state = i9xx_plane_get_hw_state;
14194 plane->check_plane = i9xx_plane_check;
14196 plane_funcs = &i965_plane_funcs;
14198 formats = i8xx_primary_formats;
14199 num_formats = ARRAY_SIZE(i8xx_primary_formats);
14200 modifiers = i9xx_format_modifiers;
14202 plane->max_stride = i9xx_plane_max_stride;
14203 plane->update_plane = i9xx_update_plane;
14204 plane->disable_plane = i9xx_disable_plane;
14205 plane->get_hw_state = i9xx_plane_get_hw_state;
14206 plane->check_plane = i9xx_plane_check;
14208 plane_funcs = &i8xx_plane_funcs;
14211 possible_crtcs = BIT(pipe);
14213 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
14214 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14215 possible_crtcs, plane_funcs,
14216 formats, num_formats, modifiers,
14217 DRM_PLANE_TYPE_PRIMARY,
14218 "primary %c", pipe_name(pipe));
14220 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
14221 possible_crtcs, plane_funcs,
14222 formats, num_formats, modifiers,
14223 DRM_PLANE_TYPE_PRIMARY,
14225 plane_name(plane->i9xx_plane));
14229 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
14230 supported_rotations =
14231 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
14232 DRM_MODE_REFLECT_X;
14233 } else if (INTEL_GEN(dev_priv) >= 4) {
14234 supported_rotations =
14235 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
14237 supported_rotations = DRM_MODE_ROTATE_0;
14240 if (INTEL_GEN(dev_priv) >= 4)
14241 drm_plane_create_rotation_property(&plane->base,
14243 supported_rotations);
14245 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
14250 intel_plane_free(plane);
14252 return ERR_PTR(ret);
14255 static struct intel_plane *
14256 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
14259 unsigned int possible_crtcs;
14260 struct intel_plane *cursor;
14263 cursor = intel_plane_alloc();
14264 if (IS_ERR(cursor))
14267 cursor->pipe = pipe;
14268 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
14269 cursor->id = PLANE_CURSOR;
14270 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
14272 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
14273 cursor->max_stride = i845_cursor_max_stride;
14274 cursor->update_plane = i845_update_cursor;
14275 cursor->disable_plane = i845_disable_cursor;
14276 cursor->get_hw_state = i845_cursor_get_hw_state;
14277 cursor->check_plane = i845_check_cursor;
14279 cursor->max_stride = i9xx_cursor_max_stride;
14280 cursor->update_plane = i9xx_update_cursor;
14281 cursor->disable_plane = i9xx_disable_cursor;
14282 cursor->get_hw_state = i9xx_cursor_get_hw_state;
14283 cursor->check_plane = i9xx_check_cursor;
14286 cursor->cursor.base = ~0;
14287 cursor->cursor.cntl = ~0;
14289 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14290 cursor->cursor.size = ~0;
14292 possible_crtcs = BIT(pipe);
14294 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
14295 possible_crtcs, &intel_cursor_plane_funcs,
14296 intel_cursor_formats,
14297 ARRAY_SIZE(intel_cursor_formats),
14298 cursor_format_modifiers,
14299 DRM_PLANE_TYPE_CURSOR,
14300 "cursor %c", pipe_name(pipe));
14304 if (INTEL_GEN(dev_priv) >= 4)
14305 drm_plane_create_rotation_property(&cursor->base,
14307 DRM_MODE_ROTATE_0 |
14308 DRM_MODE_ROTATE_180);
14310 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14315 intel_plane_free(cursor);
14317 return ERR_PTR(ret);
14320 static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14321 struct intel_crtc_state *crtc_state)
14323 struct intel_crtc_scaler_state *scaler_state =
14324 &crtc_state->scaler_state;
14325 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
14328 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
14329 if (!crtc->num_scalers)
14332 for (i = 0; i < crtc->num_scalers; i++) {
14333 struct intel_scaler *scaler = &scaler_state->scalers[i];
14335 scaler->in_use = 0;
14339 scaler_state->scaler_id = -1;
14342 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
14344 struct intel_crtc *intel_crtc;
14345 struct intel_crtc_state *crtc_state = NULL;
14346 struct intel_plane *primary = NULL;
14347 struct intel_plane *cursor = NULL;
14350 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
14354 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
14359 intel_crtc->config = crtc_state;
14360 intel_crtc->base.state = &crtc_state->base;
14361 crtc_state->base.crtc = &intel_crtc->base;
14363 primary = intel_primary_plane_create(dev_priv, pipe);
14364 if (IS_ERR(primary)) {
14365 ret = PTR_ERR(primary);
14368 intel_crtc->plane_ids_mask |= BIT(primary->id);
14370 for_each_sprite(dev_priv, pipe, sprite) {
14371 struct intel_plane *plane;
14373 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
14374 if (IS_ERR(plane)) {
14375 ret = PTR_ERR(plane);
14378 intel_crtc->plane_ids_mask |= BIT(plane->id);
14381 cursor = intel_cursor_plane_create(dev_priv, pipe);
14382 if (IS_ERR(cursor)) {
14383 ret = PTR_ERR(cursor);
14386 intel_crtc->plane_ids_mask |= BIT(cursor->id);
14388 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
14389 &primary->base, &cursor->base,
14391 "pipe %c", pipe_name(pipe));
14395 intel_crtc->pipe = pipe;
14397 /* initialize shared scalers */
14398 intel_crtc_init_scalers(intel_crtc, crtc_state);
14400 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14401 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14402 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14404 if (INTEL_GEN(dev_priv) < 9) {
14405 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14407 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14408 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14409 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14412 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
14414 intel_color_init(intel_crtc);
14416 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
14422 * drm_mode_config_cleanup() will free up any
14423 * crtcs/planes already initialized.
14431 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14432 struct drm_file *file)
14434 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
14435 struct drm_crtc *drmmode_crtc;
14436 struct intel_crtc *crtc;
14438 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
14442 crtc = to_intel_crtc(drmmode_crtc);
14443 pipe_from_crtc_id->pipe = crtc->pipe;
14448 static int intel_encoder_clones(struct intel_encoder *encoder)
14450 struct drm_device *dev = encoder->base.dev;
14451 struct intel_encoder *source_encoder;
14452 int index_mask = 0;
14455 for_each_intel_encoder(dev, source_encoder) {
14456 if (encoders_cloneable(encoder, source_encoder))
14457 index_mask |= (1 << entry);
14465 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
14467 if (!IS_MOBILE(dev_priv))
14470 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14473 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
14479 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
14481 if (INTEL_GEN(dev_priv) >= 9)
14484 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
14487 if (HAS_PCH_LPT_H(dev_priv) &&
14488 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
14491 /* DDI E can't be used if DDI A requires 4 lanes */
14492 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
14495 if (!dev_priv->vbt.int_crt_support)
14501 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14506 if (HAS_DDI(dev_priv))
14509 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14510 * everywhere where registers can be write protected.
14512 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14517 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14518 u32 val = I915_READ(PP_CONTROL(pps_idx));
14520 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14521 I915_WRITE(PP_CONTROL(pps_idx), val);
14525 static void intel_pps_init(struct drm_i915_private *dev_priv)
14527 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
14528 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14529 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14530 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14532 dev_priv->pps_mmio_base = PPS_BASE;
14534 intel_pps_unlock_regs_wa(dev_priv);
14537 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
14539 struct intel_encoder *encoder;
14540 bool dpd_is_edp = false;
14542 intel_pps_init(dev_priv);
14544 if (!HAS_DISPLAY(dev_priv))
14547 if (IS_ICELAKE(dev_priv)) {
14548 intel_ddi_init(dev_priv, PORT_A);
14549 intel_ddi_init(dev_priv, PORT_B);
14550 intel_ddi_init(dev_priv, PORT_C);
14551 intel_ddi_init(dev_priv, PORT_D);
14552 intel_ddi_init(dev_priv, PORT_E);
14554 * On some ICL SKUs port F is not present. No strap bits for
14555 * this, so rely on VBT.
14556 * Work around broken VBTs on SKUs known to have no port F.
14558 if (IS_ICL_WITH_PORT_F(dev_priv) &&
14559 intel_bios_is_port_present(dev_priv, PORT_F))
14560 intel_ddi_init(dev_priv, PORT_F);
14562 icl_dsi_init(dev_priv);
14563 } else if (IS_GEN9_LP(dev_priv)) {
14565 * FIXME: Broxton doesn't support port detection via the
14566 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14567 * detect the ports.
14569 intel_ddi_init(dev_priv, PORT_A);
14570 intel_ddi_init(dev_priv, PORT_B);
14571 intel_ddi_init(dev_priv, PORT_C);
14573 vlv_dsi_init(dev_priv);
14574 } else if (HAS_DDI(dev_priv)) {
14577 if (intel_ddi_crt_present(dev_priv))
14578 intel_crt_init(dev_priv);
14581 * Haswell uses DDI functions to detect digital outputs.
14582 * On SKL pre-D0 the strap isn't connected, so we assume
14585 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
14586 /* WaIgnoreDDIAStrap: skl */
14587 if (found || IS_GEN9_BC(dev_priv))
14588 intel_ddi_init(dev_priv, PORT_A);
14590 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
14592 found = I915_READ(SFUSE_STRAP);
14594 if (found & SFUSE_STRAP_DDIB_DETECTED)
14595 intel_ddi_init(dev_priv, PORT_B);
14596 if (found & SFUSE_STRAP_DDIC_DETECTED)
14597 intel_ddi_init(dev_priv, PORT_C);
14598 if (found & SFUSE_STRAP_DDID_DETECTED)
14599 intel_ddi_init(dev_priv, PORT_D);
14600 if (found & SFUSE_STRAP_DDIF_DETECTED)
14601 intel_ddi_init(dev_priv, PORT_F);
14603 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14605 if (IS_GEN9_BC(dev_priv) &&
14606 intel_bios_is_port_present(dev_priv, PORT_E))
14607 intel_ddi_init(dev_priv, PORT_E);
14609 } else if (HAS_PCH_SPLIT(dev_priv)) {
14613 * intel_edp_init_connector() depends on this completing first,
14614 * to prevent the registration of both eDP and LVDS and the
14615 * incorrect sharing of the PPS.
14617 intel_lvds_init(dev_priv);
14618 intel_crt_init(dev_priv);
14620 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
14622 if (ilk_has_edp_a(dev_priv))
14623 intel_dp_init(dev_priv, DP_A, PORT_A);
14625 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
14626 /* PCH SDVOB multiplex with HDMIB */
14627 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
14629 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
14630 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
14631 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
14634 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
14635 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
14637 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
14638 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
14640 if (I915_READ(PCH_DP_C) & DP_DETECTED)
14641 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
14643 if (I915_READ(PCH_DP_D) & DP_DETECTED)
14644 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
14645 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
14646 bool has_edp, has_port;
14648 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
14649 intel_crt_init(dev_priv);
14652 * The DP_DETECTED bit is the latched state of the DDC
14653 * SDA pin at boot. However since eDP doesn't require DDC
14654 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14655 * eDP ports may have been muxed to an alternate function.
14656 * Thus we can't rely on the DP_DETECTED bit alone to detect
14657 * eDP ports. Consult the VBT as well as DP_DETECTED to
14658 * detect eDP ports.
14660 * Sadly the straps seem to be missing sometimes even for HDMI
14661 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14662 * and VBT for the presence of the port. Additionally we can't
14663 * trust the port type the VBT declares as we've seen at least
14664 * HDMI ports that the VBT claim are DP or eDP.
14666 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
14667 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14668 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
14669 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
14670 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
14671 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
14673 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
14674 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14675 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
14676 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
14677 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
14678 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
14680 if (IS_CHERRYVIEW(dev_priv)) {
14682 * eDP not supported on port D,
14683 * so no need to worry about it
14685 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14686 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
14687 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
14688 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
14689 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
14692 vlv_dsi_init(dev_priv);
14693 } else if (IS_PINEVIEW(dev_priv)) {
14694 intel_lvds_init(dev_priv);
14695 intel_crt_init(dev_priv);
14696 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
14697 bool found = false;
14699 if (IS_MOBILE(dev_priv))
14700 intel_lvds_init(dev_priv);
14702 intel_crt_init(dev_priv);
14704 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14705 DRM_DEBUG_KMS("probing SDVOB\n");
14706 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
14707 if (!found && IS_G4X(dev_priv)) {
14708 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
14709 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
14712 if (!found && IS_G4X(dev_priv))
14713 intel_dp_init(dev_priv, DP_B, PORT_B);
14716 /* Before G4X SDVOC doesn't have its own detect register */
14718 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
14719 DRM_DEBUG_KMS("probing SDVOC\n");
14720 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
14723 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
14725 if (IS_G4X(dev_priv)) {
14726 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
14727 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
14729 if (IS_G4X(dev_priv))
14730 intel_dp_init(dev_priv, DP_C, PORT_C);
14733 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
14734 intel_dp_init(dev_priv, DP_D, PORT_D);
14736 if (SUPPORTS_TV(dev_priv))
14737 intel_tv_init(dev_priv);
14738 } else if (IS_GEN(dev_priv, 2)) {
14739 if (IS_I85X(dev_priv))
14740 intel_lvds_init(dev_priv);
14742 intel_crt_init(dev_priv);
14743 intel_dvo_init(dev_priv);
14746 intel_psr_init(dev_priv);
14748 for_each_intel_encoder(&dev_priv->drm, encoder) {
14749 encoder->base.possible_crtcs = encoder->crtc_mask;
14750 encoder->base.possible_clones =
14751 intel_encoder_clones(encoder);
14754 intel_init_pch_refclk(dev_priv);
14756 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14759 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14761 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14762 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14764 drm_framebuffer_cleanup(fb);
14766 i915_gem_object_lock(obj);
14767 WARN_ON(!obj->framebuffer_references--);
14768 i915_gem_object_unlock(obj);
14770 i915_gem_object_put(obj);
14775 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14776 struct drm_file *file,
14777 unsigned int *handle)
14779 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14781 if (obj->userptr.mm) {
14782 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14786 return drm_gem_handle_create(file, &obj->base, handle);
14789 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14790 struct drm_file *file,
14791 unsigned flags, unsigned color,
14792 struct drm_clip_rect *clips,
14793 unsigned num_clips)
14795 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14797 i915_gem_object_flush_if_display(obj);
14798 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
14803 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14804 .destroy = intel_user_framebuffer_destroy,
14805 .create_handle = intel_user_framebuffer_create_handle,
14806 .dirty = intel_user_framebuffer_dirty,
14810 u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
14811 u32 pixel_format, u64 fb_modifier)
14813 struct intel_crtc *crtc;
14814 struct intel_plane *plane;
14817 * We assume the primary plane for pipe A has
14818 * the highest stride limits of them all.
14820 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14821 plane = to_intel_plane(crtc->base.primary);
14823 return plane->max_stride(plane, pixel_format, fb_modifier,
14824 DRM_MODE_ROTATE_0);
14827 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14828 struct drm_i915_gem_object *obj,
14829 struct drm_mode_fb_cmd2 *mode_cmd)
14831 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14832 struct drm_framebuffer *fb = &intel_fb->base;
14834 unsigned int tiling, stride;
14838 i915_gem_object_lock(obj);
14839 obj->framebuffer_references++;
14840 tiling = i915_gem_object_get_tiling(obj);
14841 stride = i915_gem_object_get_stride(obj);
14842 i915_gem_object_unlock(obj);
14844 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14846 * If there's a fence, enforce that
14847 * the fb modifier and tiling mode match.
14849 if (tiling != I915_TILING_NONE &&
14850 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14851 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
14855 if (tiling == I915_TILING_X) {
14856 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14857 } else if (tiling == I915_TILING_Y) {
14858 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
14863 if (!drm_any_plane_has_format(&dev_priv->drm,
14864 mode_cmd->pixel_format,
14865 mode_cmd->modifier[0])) {
14866 struct drm_format_name_buf format_name;
14868 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
14869 drm_get_format_name(mode_cmd->pixel_format,
14871 mode_cmd->modifier[0]);
14876 * gen2/3 display engine uses the fence if present,
14877 * so the tiling mode must match the fb modifier exactly.
14879 if (INTEL_GEN(dev_priv) < 4 &&
14880 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14881 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
14885 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format,
14886 mode_cmd->modifier[0]);
14887 if (mode_cmd->pitches[0] > pitch_limit) {
14888 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
14889 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14890 "tiled" : "linear",
14891 mode_cmd->pitches[0], pitch_limit);
14896 * If there's a fence, enforce that
14897 * the fb pitch and fence stride match.
14899 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14900 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14901 mode_cmd->pitches[0], stride);
14905 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14906 if (mode_cmd->offsets[0] != 0)
14909 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14911 for (i = 0; i < fb->format->num_planes; i++) {
14912 u32 stride_alignment;
14914 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14915 DRM_DEBUG_KMS("bad plane %d handle\n", i);
14919 stride_alignment = intel_fb_stride_alignment(fb, i);
14922 * Display WA #0531: skl,bxt,kbl,glk
14924 * Render decompression and plane width > 3840
14925 * combined with horizontal panning requires the
14926 * plane stride to be a multiple of 4. We'll just
14927 * require the entire fb to accommodate that to avoid
14928 * potential runtime errors at plane configuration time.
14930 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
14931 is_ccs_modifier(fb->modifier))
14932 stride_alignment *= 4;
14934 if (fb->pitches[i] & (stride_alignment - 1)) {
14935 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14936 i, fb->pitches[i], stride_alignment);
14940 fb->obj[i] = &obj->base;
14943 ret = intel_fill_fb_info(dev_priv, fb);
14947 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14949 DRM_ERROR("framebuffer init failed %d\n", ret);
14956 i915_gem_object_lock(obj);
14957 obj->framebuffer_references--;
14958 i915_gem_object_unlock(obj);
14962 static struct drm_framebuffer *
14963 intel_user_framebuffer_create(struct drm_device *dev,
14964 struct drm_file *filp,
14965 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14967 struct drm_framebuffer *fb;
14968 struct drm_i915_gem_object *obj;
14969 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14971 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14973 return ERR_PTR(-ENOENT);
14975 fb = intel_framebuffer_create(obj, &mode_cmd);
14977 i915_gem_object_put(obj);
14982 static void intel_atomic_state_free(struct drm_atomic_state *state)
14984 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14986 drm_atomic_state_default_release(state);
14988 i915_sw_fence_fini(&intel_state->commit_ready);
14993 static enum drm_mode_status
14994 intel_mode_valid(struct drm_device *dev,
14995 const struct drm_display_mode *mode)
14997 struct drm_i915_private *dev_priv = to_i915(dev);
14998 int hdisplay_max, htotal_max;
14999 int vdisplay_max, vtotal_max;
15002 * Can't reject DBLSCAN here because Xorg ddxen can add piles
15003 * of DBLSCAN modes to the output's mode list when they detect
15004 * the scaling mode property on the connector. And they don't
15005 * ask the kernel to validate those modes in any way until
15006 * modeset time at which point the client gets a protocol error.
15007 * So in order to not upset those clients we silently ignore the
15008 * DBLSCAN flag on such connectors. For other connectors we will
15009 * reject modes with the DBLSCAN flag in encoder->compute_config().
15010 * And we always reject DBLSCAN modes in connector->mode_valid()
15011 * as we never want such modes on the connector's mode list.
15014 if (mode->vscan > 1)
15015 return MODE_NO_VSCAN;
15017 if (mode->flags & DRM_MODE_FLAG_HSKEW)
15018 return MODE_H_ILLEGAL;
15020 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
15021 DRM_MODE_FLAG_NCSYNC |
15022 DRM_MODE_FLAG_PCSYNC))
15025 if (mode->flags & (DRM_MODE_FLAG_BCAST |
15026 DRM_MODE_FLAG_PIXMUX |
15027 DRM_MODE_FLAG_CLKDIV2))
15030 if (INTEL_GEN(dev_priv) >= 9 ||
15031 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
15032 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
15033 vdisplay_max = 4096;
15036 } else if (INTEL_GEN(dev_priv) >= 3) {
15037 hdisplay_max = 4096;
15038 vdisplay_max = 4096;
15042 hdisplay_max = 2048;
15043 vdisplay_max = 2048;
15048 if (mode->hdisplay > hdisplay_max ||
15049 mode->hsync_start > htotal_max ||
15050 mode->hsync_end > htotal_max ||
15051 mode->htotal > htotal_max)
15052 return MODE_H_ILLEGAL;
15054 if (mode->vdisplay > vdisplay_max ||
15055 mode->vsync_start > vtotal_max ||
15056 mode->vsync_end > vtotal_max ||
15057 mode->vtotal > vtotal_max)
15058 return MODE_V_ILLEGAL;
15063 static const struct drm_mode_config_funcs intel_mode_funcs = {
15064 .fb_create = intel_user_framebuffer_create,
15065 .get_format_info = intel_get_format_info,
15066 .output_poll_changed = intel_fbdev_output_poll_changed,
15067 .mode_valid = intel_mode_valid,
15068 .atomic_check = intel_atomic_check,
15069 .atomic_commit = intel_atomic_commit,
15070 .atomic_state_alloc = intel_atomic_state_alloc,
15071 .atomic_state_clear = intel_atomic_state_clear,
15072 .atomic_state_free = intel_atomic_state_free,
15076 * intel_init_display_hooks - initialize the display modesetting hooks
15077 * @dev_priv: device private
15079 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
15081 intel_init_cdclk_hooks(dev_priv);
15083 if (INTEL_GEN(dev_priv) >= 9) {
15084 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15085 dev_priv->display.get_initial_plane_config =
15086 skylake_get_initial_plane_config;
15087 dev_priv->display.crtc_compute_clock =
15088 haswell_crtc_compute_clock;
15089 dev_priv->display.crtc_enable = haswell_crtc_enable;
15090 dev_priv->display.crtc_disable = haswell_crtc_disable;
15091 } else if (HAS_DDI(dev_priv)) {
15092 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
15093 dev_priv->display.get_initial_plane_config =
15094 i9xx_get_initial_plane_config;
15095 dev_priv->display.crtc_compute_clock =
15096 haswell_crtc_compute_clock;
15097 dev_priv->display.crtc_enable = haswell_crtc_enable;
15098 dev_priv->display.crtc_disable = haswell_crtc_disable;
15099 } else if (HAS_PCH_SPLIT(dev_priv)) {
15100 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
15101 dev_priv->display.get_initial_plane_config =
15102 i9xx_get_initial_plane_config;
15103 dev_priv->display.crtc_compute_clock =
15104 ironlake_crtc_compute_clock;
15105 dev_priv->display.crtc_enable = ironlake_crtc_enable;
15106 dev_priv->display.crtc_disable = ironlake_crtc_disable;
15107 } else if (IS_CHERRYVIEW(dev_priv)) {
15108 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15109 dev_priv->display.get_initial_plane_config =
15110 i9xx_get_initial_plane_config;
15111 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
15112 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15113 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15114 } else if (IS_VALLEYVIEW(dev_priv)) {
15115 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15116 dev_priv->display.get_initial_plane_config =
15117 i9xx_get_initial_plane_config;
15118 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
15119 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15120 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15121 } else if (IS_G4X(dev_priv)) {
15122 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15123 dev_priv->display.get_initial_plane_config =
15124 i9xx_get_initial_plane_config;
15125 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
15126 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15127 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15128 } else if (IS_PINEVIEW(dev_priv)) {
15129 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15130 dev_priv->display.get_initial_plane_config =
15131 i9xx_get_initial_plane_config;
15132 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
15133 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15134 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15135 } else if (!IS_GEN(dev_priv, 2)) {
15136 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15137 dev_priv->display.get_initial_plane_config =
15138 i9xx_get_initial_plane_config;
15139 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
15140 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15141 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15143 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15144 dev_priv->display.get_initial_plane_config =
15145 i9xx_get_initial_plane_config;
15146 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
15147 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15148 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15151 if (IS_GEN(dev_priv, 5)) {
15152 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
15153 } else if (IS_GEN(dev_priv, 6)) {
15154 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
15155 } else if (IS_IVYBRIDGE(dev_priv)) {
15156 /* FIXME: detect B0+ stepping and use auto training */
15157 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
15158 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
15159 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
15162 if (INTEL_GEN(dev_priv) >= 9)
15163 dev_priv->display.update_crtcs = skl_update_crtcs;
15165 dev_priv->display.update_crtcs = intel_update_crtcs;
15168 /* Disable the VGA plane that we never use */
15169 static void i915_disable_vga(struct drm_i915_private *dev_priv)
15171 struct pci_dev *pdev = dev_priv->drm.pdev;
15173 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15175 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
15176 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
15177 outb(SR01, VGA_SR_INDEX);
15178 sr1 = inb(VGA_SR_DATA);
15179 outb(sr1 | 1<<5, VGA_SR_DATA);
15180 vga_put(pdev, VGA_RSRC_LEGACY_IO);
15183 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
15184 POSTING_READ(vga_reg);
15187 void intel_modeset_init_hw(struct drm_device *dev)
15189 struct drm_i915_private *dev_priv = to_i915(dev);
15191 intel_update_cdclk(dev_priv);
15192 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
15193 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
15197 * Calculate what we think the watermarks should be for the state we've read
15198 * out of the hardware and then immediately program those watermarks so that
15199 * we ensure the hardware settings match our internal state.
15201 * We can calculate what we think WM's should be by creating a duplicate of the
15202 * current state (which was constructed during hardware readout) and running it
15203 * through the atomic check code to calculate new watermark values in the
15206 static void sanitize_watermarks(struct drm_device *dev)
15208 struct drm_i915_private *dev_priv = to_i915(dev);
15209 struct drm_atomic_state *state;
15210 struct intel_atomic_state *intel_state;
15211 struct drm_crtc *crtc;
15212 struct drm_crtc_state *cstate;
15213 struct drm_modeset_acquire_ctx ctx;
15217 /* Only supported on platforms that use atomic watermark design */
15218 if (!dev_priv->display.optimize_watermarks)
15222 * We need to hold connection_mutex before calling duplicate_state so
15223 * that the connector loop is protected.
15225 drm_modeset_acquire_init(&ctx, 0);
15227 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15228 if (ret == -EDEADLK) {
15229 drm_modeset_backoff(&ctx);
15231 } else if (WARN_ON(ret)) {
15235 state = drm_atomic_helper_duplicate_state(dev, &ctx);
15236 if (WARN_ON(IS_ERR(state)))
15239 intel_state = to_intel_atomic_state(state);
15242 * Hardware readout is the only time we don't want to calculate
15243 * intermediate watermarks (since we don't trust the current
15246 if (!HAS_GMCH(dev_priv))
15247 intel_state->skip_intermediate_wm = true;
15249 ret = intel_atomic_check(dev, state);
15252 * If we fail here, it means that the hardware appears to be
15253 * programmed in a way that shouldn't be possible, given our
15254 * understanding of watermark requirements. This might mean a
15255 * mistake in the hardware readout code or a mistake in the
15256 * watermark calculations for a given platform. Raise a WARN
15257 * so that this is noticeable.
15259 * If this actually happens, we'll have to just leave the
15260 * BIOS-programmed watermarks untouched and hope for the best.
15262 WARN(true, "Could not determine valid watermarks for inherited state\n");
15266 /* Write calculated watermark values back */
15267 for_each_new_crtc_in_state(state, crtc, cstate, i) {
15268 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
15270 cs->wm.need_postvbl_update = true;
15271 dev_priv->display.optimize_watermarks(intel_state, cs);
15273 to_intel_crtc_state(crtc->state)->wm = cs->wm;
15277 drm_atomic_state_put(state);
15279 drm_modeset_drop_locks(&ctx);
15280 drm_modeset_acquire_fini(&ctx);
15283 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
15285 if (IS_GEN(dev_priv, 5)) {
15287 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
15289 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
15290 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
15291 dev_priv->fdi_pll_freq = 270000;
15296 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
15299 static int intel_initial_commit(struct drm_device *dev)
15301 struct drm_atomic_state *state = NULL;
15302 struct drm_modeset_acquire_ctx ctx;
15303 struct drm_crtc *crtc;
15304 struct drm_crtc_state *crtc_state;
15307 state = drm_atomic_state_alloc(dev);
15311 drm_modeset_acquire_init(&ctx, 0);
15314 state->acquire_ctx = &ctx;
15316 drm_for_each_crtc(crtc, dev) {
15317 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15318 if (IS_ERR(crtc_state)) {
15319 ret = PTR_ERR(crtc_state);
15323 if (crtc_state->active) {
15324 ret = drm_atomic_add_affected_planes(state, crtc);
15329 * FIXME hack to force a LUT update to avoid the
15330 * plane update forcing the pipe gamma on without
15331 * having a proper LUT loaded. Remove once we
15332 * have readout for pipe gamma enable.
15334 crtc_state->color_mgmt_changed = true;
15338 ret = drm_atomic_commit(state);
15341 if (ret == -EDEADLK) {
15342 drm_atomic_state_clear(state);
15343 drm_modeset_backoff(&ctx);
15347 drm_atomic_state_put(state);
15349 drm_modeset_drop_locks(&ctx);
15350 drm_modeset_acquire_fini(&ctx);
15355 int intel_modeset_init(struct drm_device *dev)
15357 struct drm_i915_private *dev_priv = to_i915(dev);
15358 struct i915_ggtt *ggtt = &dev_priv->ggtt;
15360 struct intel_crtc *crtc;
15363 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15365 drm_mode_config_init(dev);
15367 dev->mode_config.min_width = 0;
15368 dev->mode_config.min_height = 0;
15370 dev->mode_config.preferred_depth = 24;
15371 dev->mode_config.prefer_shadow = 1;
15373 dev->mode_config.allow_fb_modifiers = true;
15375 dev->mode_config.funcs = &intel_mode_funcs;
15377 init_llist_head(&dev_priv->atomic_helper.free_list);
15378 INIT_WORK(&dev_priv->atomic_helper.free_work,
15379 intel_atomic_helper_free_state_worker);
15381 intel_init_quirks(dev_priv);
15383 intel_fbc_init(dev_priv);
15385 intel_init_pm(dev_priv);
15388 * There may be no VBT; and if the BIOS enabled SSC we can
15389 * just keep using it to avoid unnecessary flicker. Whereas if the
15390 * BIOS isn't using it, don't assume it will work even if the VBT
15391 * indicates as much.
15393 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
15394 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15397 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15398 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15399 bios_lvds_use_ssc ? "en" : "dis",
15400 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15401 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15405 /* maximum framebuffer dimensions */
15406 if (IS_GEN(dev_priv, 2)) {
15407 dev->mode_config.max_width = 2048;
15408 dev->mode_config.max_height = 2048;
15409 } else if (IS_GEN(dev_priv, 3)) {
15410 dev->mode_config.max_width = 4096;
15411 dev->mode_config.max_height = 4096;
15413 dev->mode_config.max_width = 8192;
15414 dev->mode_config.max_height = 8192;
15417 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15418 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
15419 dev->mode_config.cursor_height = 1023;
15420 } else if (IS_GEN(dev_priv, 2)) {
15421 dev->mode_config.cursor_width = 64;
15422 dev->mode_config.cursor_height = 64;
15424 dev->mode_config.cursor_width = 256;
15425 dev->mode_config.cursor_height = 256;
15428 dev->mode_config.fb_base = ggtt->gmadr.start;
15430 DRM_DEBUG_KMS("%d display pipe%s available.\n",
15431 INTEL_INFO(dev_priv)->num_pipes,
15432 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
15434 for_each_pipe(dev_priv, pipe) {
15435 ret = intel_crtc_init(dev_priv, pipe);
15437 drm_mode_config_cleanup(dev);
15442 intel_shared_dpll_init(dev);
15443 intel_update_fdi_pll_freq(dev_priv);
15445 intel_update_czclk(dev_priv);
15446 intel_modeset_init_hw(dev);
15448 if (dev_priv->max_cdclk_freq == 0)
15449 intel_update_max_cdclk(dev_priv);
15451 /* Just disable it once at startup */
15452 i915_disable_vga(dev_priv);
15453 intel_setup_outputs(dev_priv);
15455 drm_modeset_lock_all(dev);
15456 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
15457 drm_modeset_unlock_all(dev);
15459 for_each_intel_crtc(dev, crtc) {
15460 struct intel_initial_plane_config plane_config = {};
15466 * Note that reserving the BIOS fb up front prevents us
15467 * from stuffing other stolen allocations like the ring
15468 * on top. This prevents some ugliness at boot time, and
15469 * can even allow for smooth boot transitions if the BIOS
15470 * fb is large enough for the active pipe configuration.
15472 dev_priv->display.get_initial_plane_config(crtc,
15476 * If the fb is shared between multiple heads, we'll
15477 * just get the first one.
15479 intel_find_initial_plane_obj(crtc, &plane_config);
15483 * Make sure hardware watermarks really match the state we read out.
15484 * Note that we need to do this after reconstructing the BIOS fb's
15485 * since the watermark calculation done here will use pstate->fb.
15487 if (!HAS_GMCH(dev_priv))
15488 sanitize_watermarks(dev);
15491 * Force all active planes to recompute their states. So that on
15492 * mode_setcrtc after probe, all the intel_plane_state variables
15493 * are already calculated and there is no assert_plane warnings
15496 ret = intel_initial_commit(dev);
15498 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15503 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15505 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15506 /* 640x480@60Hz, ~25175 kHz */
15507 struct dpll clock = {
15517 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15519 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15520 pipe_name(pipe), clock.vco, clock.dot);
15522 fp = i9xx_dpll_compute_fp(&clock);
15523 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15524 DPLL_VGA_MODE_DIS |
15525 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15526 PLL_P2_DIVIDE_BY_4 |
15527 PLL_REF_INPUT_DREFCLK |
15530 I915_WRITE(FP0(pipe), fp);
15531 I915_WRITE(FP1(pipe), fp);
15533 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15534 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15535 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15536 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15537 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15538 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15539 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15542 * Apparently we need to have VGA mode enabled prior to changing
15543 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15544 * dividers, even though the register value does change.
15546 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15547 I915_WRITE(DPLL(pipe), dpll);
15549 /* Wait for the clocks to stabilize. */
15550 POSTING_READ(DPLL(pipe));
15553 /* The pixel multiplier can only be updated once the
15554 * DPLL is enabled and the clocks are stable.
15556 * So write it again.
15558 I915_WRITE(DPLL(pipe), dpll);
15560 /* We do this three times for luck */
15561 for (i = 0; i < 3 ; i++) {
15562 I915_WRITE(DPLL(pipe), dpll);
15563 POSTING_READ(DPLL(pipe));
15564 udelay(150); /* wait for warmup */
15567 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15568 POSTING_READ(PIPECONF(pipe));
15570 intel_wait_for_pipe_scanline_moving(crtc);
15573 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15575 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15577 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15580 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15581 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15582 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
15583 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15584 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
15586 I915_WRITE(PIPECONF(pipe), 0);
15587 POSTING_READ(PIPECONF(pipe));
15589 intel_wait_for_pipe_scanline_stopped(crtc);
15591 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15592 POSTING_READ(DPLL(pipe));
15596 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15598 struct intel_crtc *crtc;
15600 if (INTEL_GEN(dev_priv) >= 4)
15603 for_each_intel_crtc(&dev_priv->drm, crtc) {
15604 struct intel_plane *plane =
15605 to_intel_plane(crtc->base.primary);
15606 struct intel_crtc *plane_crtc;
15609 if (!plane->get_hw_state(plane, &pipe))
15612 if (pipe == crtc->pipe)
15615 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15616 plane->base.base.id, plane->base.name);
15618 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15619 intel_plane_disable_noatomic(plane_crtc, plane);
15623 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15625 struct drm_device *dev = crtc->base.dev;
15626 struct intel_encoder *encoder;
15628 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15634 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15636 struct drm_device *dev = encoder->base.dev;
15637 struct intel_connector *connector;
15639 for_each_connector_on_encoder(dev, &encoder->base, connector)
15645 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15646 enum pipe pch_transcoder)
15648 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15649 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15652 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15653 struct drm_modeset_acquire_ctx *ctx)
15655 struct drm_device *dev = crtc->base.dev;
15656 struct drm_i915_private *dev_priv = to_i915(dev);
15657 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15658 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
15660 /* Clear any frame start delays used for debugging left by the BIOS */
15661 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
15662 i915_reg_t reg = PIPECONF(cpu_transcoder);
15665 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15668 if (crtc_state->base.active) {
15669 struct intel_plane *plane;
15671 /* Disable everything but the primary plane */
15672 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15673 const struct intel_plane_state *plane_state =
15674 to_intel_plane_state(plane->base.state);
15676 if (plane_state->base.visible &&
15677 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15678 intel_plane_disable_noatomic(crtc, plane);
15682 * Disable any background color set by the BIOS, but enable the
15683 * gamma and CSC to match how we program our planes.
15685 if (INTEL_GEN(dev_priv) >= 9)
15686 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
15687 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
15688 SKL_BOTTOM_COLOR_CSC_ENABLE);
15691 /* Adjust the state of the output pipe according to whether we
15692 * have active connectors/encoders. */
15693 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
15694 intel_crtc_disable_noatomic(&crtc->base, ctx);
15696 if (crtc_state->base.active || HAS_GMCH(dev_priv)) {
15698 * We start out with underrun reporting disabled to avoid races.
15699 * For correct bookkeeping mark this on active crtcs.
15701 * Also on gmch platforms we dont have any hardware bits to
15702 * disable the underrun reporting. Which means we need to start
15703 * out with underrun reporting disabled also on inactive pipes,
15704 * since otherwise we'll complain about the garbage we read when
15705 * e.g. coming up after runtime pm.
15707 * No protection against concurrent access is required - at
15708 * worst a fifo underrun happens which also sets this to false.
15710 crtc->cpu_fifo_underrun_disabled = true;
15712 * We track the PCH trancoder underrun reporting state
15713 * within the crtc. With crtc for pipe A housing the underrun
15714 * reporting state for PCH transcoder A, crtc for pipe B housing
15715 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15716 * and marking underrun reporting as disabled for the non-existing
15717 * PCH transcoders B and C would prevent enabling the south
15718 * error interrupt (see cpt_can_enable_serr_int()).
15720 if (has_pch_trancoder(dev_priv, crtc->pipe))
15721 crtc->pch_fifo_underrun_disabled = true;
15725 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
15727 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
15730 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
15731 * the hardware when a high res displays plugged in. DPLL P
15732 * divider is zero, and the pipe timings are bonkers. We'll
15733 * try to disable everything in that case.
15735 * FIXME would be nice to be able to sanitize this state
15736 * without several WARNs, but for now let's take the easy
15739 return IS_GEN(dev_priv, 6) &&
15740 crtc_state->base.active &&
15741 crtc_state->shared_dpll &&
15742 crtc_state->port_clock == 0;
15745 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15747 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
15748 struct intel_connector *connector;
15749 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
15750 struct intel_crtc_state *crtc_state = crtc ?
15751 to_intel_crtc_state(crtc->base.state) : NULL;
15753 /* We need to check both for a crtc link (meaning that the
15754 * encoder is active and trying to read from a pipe) and the
15755 * pipe itself being active. */
15756 bool has_active_crtc = crtc_state &&
15757 crtc_state->base.active;
15759 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
15760 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
15761 pipe_name(crtc->pipe));
15762 has_active_crtc = false;
15765 connector = intel_encoder_find_connector(encoder);
15766 if (connector && !has_active_crtc) {
15767 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15768 encoder->base.base.id,
15769 encoder->base.name);
15771 /* Connector is active, but has no active pipe. This is
15772 * fallout from our resume register restoring. Disable
15773 * the encoder manually again. */
15775 struct drm_encoder *best_encoder;
15777 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15778 encoder->base.base.id,
15779 encoder->base.name);
15781 /* avoid oopsing in case the hooks consult best_encoder */
15782 best_encoder = connector->base.state->best_encoder;
15783 connector->base.state->best_encoder = &encoder->base;
15785 if (encoder->disable)
15786 encoder->disable(encoder, crtc_state,
15787 connector->base.state);
15788 if (encoder->post_disable)
15789 encoder->post_disable(encoder, crtc_state,
15790 connector->base.state);
15792 connector->base.state->best_encoder = best_encoder;
15794 encoder->base.crtc = NULL;
15796 /* Inconsistent output/port/pipe state happens presumably due to
15797 * a bug in one of the get_hw_state functions. Or someplace else
15798 * in our code, like the register restore mess on resume. Clamp
15799 * things to off as a safer default. */
15801 connector->base.dpms = DRM_MODE_DPMS_OFF;
15802 connector->base.encoder = NULL;
15805 /* notify opregion of the sanitized encoder state */
15806 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
15808 if (INTEL_GEN(dev_priv) >= 11)
15809 icl_sanitize_encoder_pll_mapping(encoder);
15812 void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
15814 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
15816 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15817 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
15818 i915_disable_vga(dev_priv);
15822 void i915_redisable_vga(struct drm_i915_private *dev_priv)
15824 intel_wakeref_t wakeref;
15827 * This function can be called both from intel_modeset_setup_hw_state or
15828 * at a very early point in our resume sequence, where the power well
15829 * structures are not yet restored. Since this function is at a very
15830 * paranoid "someone might have enabled VGA while we were not looking"
15831 * level, just check if the power well is enabled instead of trying to
15832 * follow the "don't touch the power well if we don't need it" policy
15833 * the rest of the driver uses.
15835 wakeref = intel_display_power_get_if_enabled(dev_priv,
15840 i915_redisable_vga_power_on(dev_priv);
15842 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref);
15845 /* FIXME read out full plane state for all planes */
15846 static void readout_plane_state(struct drm_i915_private *dev_priv)
15848 struct intel_plane *plane;
15849 struct intel_crtc *crtc;
15851 for_each_intel_plane(&dev_priv->drm, plane) {
15852 struct intel_plane_state *plane_state =
15853 to_intel_plane_state(plane->base.state);
15854 struct intel_crtc_state *crtc_state;
15855 enum pipe pipe = PIPE_A;
15858 visible = plane->get_hw_state(plane, &pipe);
15860 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15861 crtc_state = to_intel_crtc_state(crtc->base.state);
15863 intel_set_plane_visible(crtc_state, plane_state, visible);
15865 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15866 plane->base.base.id, plane->base.name,
15867 enableddisabled(visible), pipe_name(pipe));
15870 for_each_intel_crtc(&dev_priv->drm, crtc) {
15871 struct intel_crtc_state *crtc_state =
15872 to_intel_crtc_state(crtc->base.state);
15874 fixup_active_planes(crtc_state);
15878 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15880 struct drm_i915_private *dev_priv = to_i915(dev);
15882 struct intel_crtc *crtc;
15883 struct intel_encoder *encoder;
15884 struct intel_connector *connector;
15885 struct drm_connector_list_iter conn_iter;
15888 dev_priv->active_crtcs = 0;
15890 for_each_intel_crtc(dev, crtc) {
15891 struct intel_crtc_state *crtc_state =
15892 to_intel_crtc_state(crtc->base.state);
15894 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
15895 memset(crtc_state, 0, sizeof(*crtc_state));
15896 crtc_state->base.crtc = &crtc->base;
15898 crtc_state->base.active = crtc_state->base.enable =
15899 dev_priv->display.get_pipe_config(crtc, crtc_state);
15901 crtc->base.enabled = crtc_state->base.enable;
15902 crtc->active = crtc_state->base.active;
15904 if (crtc_state->base.active)
15905 dev_priv->active_crtcs |= 1 << crtc->pipe;
15907 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15908 crtc->base.base.id, crtc->base.name,
15909 enableddisabled(crtc_state->base.active));
15912 readout_plane_state(dev_priv);
15914 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15915 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15917 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15918 &pll->state.hw_state);
15919 pll->state.crtc_mask = 0;
15920 for_each_intel_crtc(dev, crtc) {
15921 struct intel_crtc_state *crtc_state =
15922 to_intel_crtc_state(crtc->base.state);
15924 if (crtc_state->base.active &&
15925 crtc_state->shared_dpll == pll)
15926 pll->state.crtc_mask |= 1 << crtc->pipe;
15928 pll->active_mask = pll->state.crtc_mask;
15930 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
15931 pll->info->name, pll->state.crtc_mask, pll->on);
15934 for_each_intel_encoder(dev, encoder) {
15937 if (encoder->get_hw_state(encoder, &pipe)) {
15938 struct intel_crtc_state *crtc_state;
15940 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15941 crtc_state = to_intel_crtc_state(crtc->base.state);
15943 encoder->base.crtc = &crtc->base;
15944 encoder->get_config(encoder, crtc_state);
15946 encoder->base.crtc = NULL;
15949 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15950 encoder->base.base.id, encoder->base.name,
15951 enableddisabled(encoder->base.crtc),
15955 drm_connector_list_iter_begin(dev, &conn_iter);
15956 for_each_intel_connector_iter(connector, &conn_iter) {
15957 if (connector->get_hw_state(connector)) {
15958 connector->base.dpms = DRM_MODE_DPMS_ON;
15960 encoder = connector->encoder;
15961 connector->base.encoder = &encoder->base;
15963 if (encoder->base.crtc &&
15964 encoder->base.crtc->state->active) {
15966 * This has to be done during hardware readout
15967 * because anything calling .crtc_disable may
15968 * rely on the connector_mask being accurate.
15970 encoder->base.crtc->state->connector_mask |=
15971 drm_connector_mask(&connector->base);
15972 encoder->base.crtc->state->encoder_mask |=
15973 drm_encoder_mask(&encoder->base);
15977 connector->base.dpms = DRM_MODE_DPMS_OFF;
15978 connector->base.encoder = NULL;
15980 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
15981 connector->base.base.id, connector->base.name,
15982 enableddisabled(connector->base.encoder));
15984 drm_connector_list_iter_end(&conn_iter);
15986 for_each_intel_crtc(dev, crtc) {
15987 struct intel_crtc_state *crtc_state =
15988 to_intel_crtc_state(crtc->base.state);
15991 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
15992 if (crtc_state->base.active) {
15993 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
15994 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15995 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
15996 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
15997 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
16000 * The initial mode needs to be set in order to keep
16001 * the atomic core happy. It wants a valid mode if the
16002 * crtc's enabled, so we do the above call.
16004 * But we don't set all the derived state fully, hence
16005 * set a flag to indicate that a full recalculation is
16006 * needed on the next commit.
16008 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
16010 intel_crtc_compute_pixel_rate(crtc_state);
16012 if (dev_priv->display.modeset_calc_cdclk) {
16013 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
16014 if (WARN_ON(min_cdclk < 0))
16018 drm_calc_timestamping_constants(&crtc->base,
16019 &crtc_state->base.adjusted_mode);
16020 update_scanline_offset(crtc_state);
16023 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
16024 dev_priv->min_voltage_level[crtc->pipe] =
16025 crtc_state->min_voltage_level;
16027 intel_pipe_config_sanity_check(dev_priv, crtc_state);
16032 get_encoder_power_domains(struct drm_i915_private *dev_priv)
16034 struct intel_encoder *encoder;
16036 for_each_intel_encoder(&dev_priv->drm, encoder) {
16038 enum intel_display_power_domain domain;
16039 struct intel_crtc_state *crtc_state;
16041 if (!encoder->get_power_domains)
16045 * MST-primary and inactive encoders don't have a crtc state
16046 * and neither of these require any power domain references.
16048 if (!encoder->base.crtc)
16051 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
16052 get_domains = encoder->get_power_domains(encoder, crtc_state);
16053 for_each_power_domain(domain, get_domains)
16054 intel_display_power_get(dev_priv, domain);
16058 static void intel_early_display_was(struct drm_i915_private *dev_priv)
16060 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
16061 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
16062 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
16065 if (IS_HASWELL(dev_priv)) {
16067 * WaRsPkgCStateDisplayPMReq:hsw
16068 * System hang if this isn't done before disabling all planes!
16070 I915_WRITE(CHICKEN_PAR1_1,
16071 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
16075 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
16076 enum port port, i915_reg_t hdmi_reg)
16078 u32 val = I915_READ(hdmi_reg);
16080 if (val & SDVO_ENABLE ||
16081 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
16084 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
16087 val &= ~SDVO_PIPE_SEL_MASK;
16088 val |= SDVO_PIPE_SEL(PIPE_A);
16090 I915_WRITE(hdmi_reg, val);
16093 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
16094 enum port port, i915_reg_t dp_reg)
16096 u32 val = I915_READ(dp_reg);
16098 if (val & DP_PORT_EN ||
16099 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
16102 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
16105 val &= ~DP_PIPE_SEL_MASK;
16106 val |= DP_PIPE_SEL(PIPE_A);
16108 I915_WRITE(dp_reg, val);
16111 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
16114 * The BIOS may select transcoder B on some of the PCH
16115 * ports even it doesn't enable the port. This would trip
16116 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
16117 * Sanitize the transcoder select bits to prevent that. We
16118 * assume that the BIOS never actually enabled the port,
16119 * because if it did we'd actually have to toggle the port
16120 * on and back off to make the transcoder A select stick
16121 * (see. intel_dp_link_down(), intel_disable_hdmi(),
16122 * intel_disable_sdvo()).
16124 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
16125 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
16126 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
16128 /* PCH SDVOB multiplex with HDMIB */
16129 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
16130 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
16131 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
16134 /* Scan out the current hw modeset state,
16135 * and sanitizes it to the current state
16138 intel_modeset_setup_hw_state(struct drm_device *dev,
16139 struct drm_modeset_acquire_ctx *ctx)
16141 struct drm_i915_private *dev_priv = to_i915(dev);
16142 struct intel_crtc_state *crtc_state;
16143 struct intel_encoder *encoder;
16144 struct intel_crtc *crtc;
16145 intel_wakeref_t wakeref;
16148 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
16150 intel_early_display_was(dev_priv);
16151 intel_modeset_readout_hw_state(dev);
16153 /* HW state is read out, now we need to sanitize this mess. */
16154 get_encoder_power_domains(dev_priv);
16156 if (HAS_PCH_IBX(dev_priv))
16157 ibx_sanitize_pch_ports(dev_priv);
16160 * intel_sanitize_plane_mapping() may need to do vblank
16161 * waits, so we need vblank interrupts restored beforehand.
16163 for_each_intel_crtc(&dev_priv->drm, crtc) {
16164 crtc_state = to_intel_crtc_state(crtc->base.state);
16166 drm_crtc_vblank_reset(&crtc->base);
16168 if (crtc_state->base.active)
16169 intel_crtc_vblank_on(crtc_state);
16172 intel_sanitize_plane_mapping(dev_priv);
16174 for_each_intel_encoder(dev, encoder)
16175 intel_sanitize_encoder(encoder);
16177 for_each_intel_crtc(&dev_priv->drm, crtc) {
16178 crtc_state = to_intel_crtc_state(crtc->base.state);
16179 intel_sanitize_crtc(crtc, ctx);
16180 intel_dump_pipe_config(crtc, crtc_state,
16181 "[setup_hw_state]");
16184 intel_modeset_update_connector_atomic_state(dev);
16186 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16187 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16189 if (!pll->on || pll->active_mask)
16192 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
16195 pll->info->funcs->disable(dev_priv, pll);
16199 if (IS_G4X(dev_priv)) {
16200 g4x_wm_get_hw_state(dev_priv);
16201 g4x_wm_sanitize(dev_priv);
16202 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
16203 vlv_wm_get_hw_state(dev_priv);
16204 vlv_wm_sanitize(dev_priv);
16205 } else if (INTEL_GEN(dev_priv) >= 9) {
16206 skl_wm_get_hw_state(dev_priv);
16207 } else if (HAS_PCH_SPLIT(dev_priv)) {
16208 ilk_wm_get_hw_state(dev_priv);
16211 for_each_intel_crtc(dev, crtc) {
16214 crtc_state = to_intel_crtc_state(crtc->base.state);
16215 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
16216 if (WARN_ON(put_domains))
16217 modeset_put_power_domains(dev_priv, put_domains);
16220 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
16222 intel_fbc_init_pipe_state(dev_priv);
16225 void intel_display_resume(struct drm_device *dev)
16227 struct drm_i915_private *dev_priv = to_i915(dev);
16228 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
16229 struct drm_modeset_acquire_ctx ctx;
16232 dev_priv->modeset_restore_state = NULL;
16234 state->acquire_ctx = &ctx;
16236 drm_modeset_acquire_init(&ctx, 0);
16239 ret = drm_modeset_lock_all_ctx(dev, &ctx);
16240 if (ret != -EDEADLK)
16243 drm_modeset_backoff(&ctx);
16247 ret = __intel_display_resume(dev, state, &ctx);
16249 intel_enable_ipc(dev_priv);
16250 drm_modeset_drop_locks(&ctx);
16251 drm_modeset_acquire_fini(&ctx);
16254 DRM_ERROR("Restoring old state failed with %i\n", ret);
16256 drm_atomic_state_put(state);
16259 static void intel_hpd_poll_fini(struct drm_device *dev)
16261 struct intel_connector *connector;
16262 struct drm_connector_list_iter conn_iter;
16264 /* Kill all the work that may have been queued by hpd. */
16265 drm_connector_list_iter_begin(dev, &conn_iter);
16266 for_each_intel_connector_iter(connector, &conn_iter) {
16267 if (connector->modeset_retry_work.func)
16268 cancel_work_sync(&connector->modeset_retry_work);
16269 if (connector->hdcp.shim) {
16270 cancel_delayed_work_sync(&connector->hdcp.check_work);
16271 cancel_work_sync(&connector->hdcp.prop_work);
16274 drm_connector_list_iter_end(&conn_iter);
16277 void intel_modeset_cleanup(struct drm_device *dev)
16279 struct drm_i915_private *dev_priv = to_i915(dev);
16281 flush_workqueue(dev_priv->modeset_wq);
16283 flush_work(&dev_priv->atomic_helper.free_work);
16284 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
16287 * Interrupts and polling as the first thing to avoid creating havoc.
16288 * Too much stuff here (turning of connectors, ...) would
16289 * experience fancy races otherwise.
16291 intel_irq_uninstall(dev_priv);
16294 * Due to the hpd irq storm handling the hotplug work can re-arm the
16295 * poll handlers. Hence disable polling after hpd handling is shut down.
16297 intel_hpd_poll_fini(dev);
16299 /* poll work can call into fbdev, hence clean that up afterwards */
16300 intel_fbdev_fini(dev_priv);
16302 intel_unregister_dsm_handler();
16304 intel_fbc_global_disable(dev_priv);
16306 /* flush any delayed tasks or pending work */
16307 flush_scheduled_work();
16309 drm_mode_config_cleanup(dev);
16311 intel_overlay_cleanup(dev_priv);
16313 intel_teardown_gmbus(dev_priv);
16315 destroy_workqueue(dev_priv->modeset_wq);
16317 intel_fbc_cleanup_cfb(dev_priv);
16321 * set vga decode state - true == enable VGA decode
16323 int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
16325 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
16328 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
16329 DRM_ERROR("failed to read control word\n");
16333 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
16337 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
16339 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
16341 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
16342 DRM_ERROR("failed to write control word\n");
16349 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
16351 struct intel_display_error_state {
16353 u32 power_well_driver;
16355 int num_transcoders;
16357 struct intel_cursor_error_state {
16362 } cursor[I915_MAX_PIPES];
16364 struct intel_pipe_error_state {
16365 bool power_domain_on;
16368 } pipe[I915_MAX_PIPES];
16370 struct intel_plane_error_state {
16378 } plane[I915_MAX_PIPES];
16380 struct intel_transcoder_error_state {
16381 bool power_domain_on;
16382 enum transcoder cpu_transcoder;
16395 struct intel_display_error_state *
16396 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
16398 struct intel_display_error_state *error;
16399 int transcoders[] = {
16407 if (!HAS_DISPLAY(dev_priv))
16410 error = kzalloc(sizeof(*error), GFP_ATOMIC);
16414 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16415 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
16417 for_each_pipe(dev_priv, i) {
16418 error->pipe[i].power_domain_on =
16419 __intel_display_power_is_enabled(dev_priv,
16420 POWER_DOMAIN_PIPE(i));
16421 if (!error->pipe[i].power_domain_on)
16424 error->cursor[i].control = I915_READ(CURCNTR(i));
16425 error->cursor[i].position = I915_READ(CURPOS(i));
16426 error->cursor[i].base = I915_READ(CURBASE(i));
16428 error->plane[i].control = I915_READ(DSPCNTR(i));
16429 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
16430 if (INTEL_GEN(dev_priv) <= 3) {
16431 error->plane[i].size = I915_READ(DSPSIZE(i));
16432 error->plane[i].pos = I915_READ(DSPPOS(i));
16434 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16435 error->plane[i].addr = I915_READ(DSPADDR(i));
16436 if (INTEL_GEN(dev_priv) >= 4) {
16437 error->plane[i].surface = I915_READ(DSPSURF(i));
16438 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16441 error->pipe[i].source = I915_READ(PIPESRC(i));
16443 if (HAS_GMCH(dev_priv))
16444 error->pipe[i].stat = I915_READ(PIPESTAT(i));
16447 /* Note: this does not include DSI transcoders. */
16448 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
16449 if (HAS_DDI(dev_priv))
16450 error->num_transcoders++; /* Account for eDP. */
16452 for (i = 0; i < error->num_transcoders; i++) {
16453 enum transcoder cpu_transcoder = transcoders[i];
16455 error->transcoder[i].power_domain_on =
16456 __intel_display_power_is_enabled(dev_priv,
16457 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
16458 if (!error->transcoder[i].power_domain_on)
16461 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16463 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16464 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16465 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16466 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16467 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16468 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16469 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
16475 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16478 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
16479 struct intel_display_error_state *error)
16481 struct drm_i915_private *dev_priv = m->i915;
16487 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
16488 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16489 err_printf(m, "PWR_WELL_CTL2: %08x\n",
16490 error->power_well_driver);
16491 for_each_pipe(dev_priv, i) {
16492 err_printf(m, "Pipe [%d]:\n", i);
16493 err_printf(m, " Power: %s\n",
16494 onoff(error->pipe[i].power_domain_on));
16495 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
16496 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
16498 err_printf(m, "Plane [%d]:\n", i);
16499 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16500 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
16501 if (INTEL_GEN(dev_priv) <= 3) {
16502 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16503 err_printf(m, " POS: %08x\n", error->plane[i].pos);
16505 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16506 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
16507 if (INTEL_GEN(dev_priv) >= 4) {
16508 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16509 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
16512 err_printf(m, "Cursor [%d]:\n", i);
16513 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16514 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16515 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
16518 for (i = 0; i < error->num_transcoders; i++) {
16519 err_printf(m, "CPU transcoder: %s\n",
16520 transcoder_name(error->transcoder[i].cpu_transcoder));
16521 err_printf(m, " Power: %s\n",
16522 onoff(error->transcoder[i].power_domain_on));
16523 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16524 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16525 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16526 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16527 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16528 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16529 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);